Skip to content

Commit

Permalink
Add NFT immutables but can't compile
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongeric committed Sep 8, 2023
1 parent 7c9c393 commit a4d9c99
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 85 deletions.
2 changes: 1 addition & 1 deletion contracts/UniversalRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {RouterParameters, RouterImmutables} from './base/RouterImmutables.sol';
import {Commands} from './libraries/Commands.sol';
import {IUniversalRouter} from './interfaces/IUniversalRouter.sol';

contract UniversalRouter is RouterImmutables, IUniversalRouter, Dispatcher, RewardsCollector {
contract UniversalRouter is Dispatcher, RouterImmutables, RewardsCollector, IUniversalRouter {
modifier checkDeadline(uint256 deadline) {
if (block.timestamp > deadline) revert TransactionDeadlinePassed();
_;
Expand Down
7 changes: 4 additions & 3 deletions contracts/base/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {V2SwapRouter} from '../modules/uniswap/v2/V2SwapRouter.sol';
import {V3SwapRouter} from '../modules/uniswap/v3/V3SwapRouter.sol';
import {BytesLib} from '../modules/uniswap/v3/BytesLib.sol';
import {Payments} from '../modules/Payments.sol';
import {RouterImmutables} from '../base/RouterImmutables.sol';
import {PaymentsImmutables} from '../modules/PaymentsImmutables.sol';
import {NFTImmutables} from '../modules/NFTImmutables.sol';
import {Callbacks} from '../base/Callbacks.sol';
import {Commands} from '../libraries/Commands.sol';
import {LockAndMsgSender} from './LockAndMsgSender.sol';
Expand All @@ -17,7 +18,7 @@ import {ICryptoPunksMarket} from '../interfaces/external/ICryptoPunksMarket.sol'

/// @title Decodes and Executes Commands
/// @notice Called by the UniversalRouter contract to efficiently decode and execute a singular command
abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, Callbacks, LockAndMsgSender {
abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, NFTImmutables, Callbacks, LockAndMsgSender {
using BytesLib for bytes;

error InvalidCommandType(uint256 commandType);
Expand Down Expand Up @@ -344,7 +345,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, Callbacks,
(address(this)).call(abi.encodeWithSelector(Dispatcher.execute.selector, _commands, _inputs));
} else if (command == Commands.APPROVE_ERC20) {
ERC20 token;
RouterImmutables.Spenders spender;
PaymentsImmutables.Spenders spender;
assembly {
token := calldataload(inputs.offset)
spender := calldataload(add(inputs.offset, 0x20))
Expand Down
4 changes: 2 additions & 2 deletions contracts/base/RewardsCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pragma solidity ^0.8.15;

import {ERC20} from 'solmate/src/tokens/ERC20.sol';
import {SafeTransferLib} from 'solmate/src/utils/SafeTransferLib.sol';
import {RouterImmutables} from './RouterImmutables.sol';
import {NFTImmutables} from '../modules/NFTImmutables.sol';
import {IRewardsCollector} from '../interfaces/IRewardsCollector.sol';

abstract contract RewardsCollector is IRewardsCollector, RouterImmutables {
abstract contract RewardsCollector is IRewardsCollector, NFTImmutables {
using SafeTransferLib for ERC20;

event RewardsSent(uint256 amount);
Expand Down
99 changes: 24 additions & 75 deletions contracts/base/RouterImmutables.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import {IAllowanceTransfer} from 'permit2/src/interfaces/IAllowanceTransfer.sol';
import {ERC20} from 'solmate/src/tokens/ERC20.sol';
import {IWETH9} from '../interfaces/external/IWETH9.sol';
import {UniswapParameters, UniswapImmutables} from '../modules/uniswap/UniswapImmutables.sol';
import {PaymentsParameters, PaymentsImmutables} from '../modules/PaymentsImmutables.sol';
import {NFTParameters, NFTImmutables} from '../modules/NFTImmutables.sol';

struct RouterParameters {
address permit2;
Expand All @@ -31,80 +30,30 @@ struct RouterParameters {

/// @title Router Immutable Storage contract
/// @notice Used along with the `RouterParameters` struct for ease of cross-chain deployment
contract RouterImmutables is UniswapImmutables {
/// @dev WETH9 address
IWETH9 internal immutable WETH9;

/// @dev Permit2 address
IAllowanceTransfer internal immutable PERMIT2;

/// @dev Seaport 1.5 address
address internal immutable SEAPORT_V1_5;

/// @dev Seaport 1.4 address
address internal immutable SEAPORT_V1_4;

/// @dev The address of OpenSea's conduit used in both Seaport 1.4 and Seaport 1.5
address internal immutable OPENSEA_CONDUIT;

/// @dev The address of NFTX zap contract for interfacing with vaults
address internal immutable NFTX_ZAP;

/// @dev The address of X2Y2
address internal immutable X2Y2;

// @dev The address of Foundation
address internal immutable FOUNDATION;

// @dev The address of Sudoswap's router
address internal immutable SUDOSWAP;

// @dev The address of Element Market
address internal immutable ELEMENT_MARKET;

// @dev the address of NFT20's zap contract
address internal immutable NFT20_ZAP;

// @dev the address of Larva Lab's cryptopunks marketplace
address internal immutable CRYPTOPUNKS;

/// @dev The address of LooksRareV2
address internal immutable LOOKS_RARE_V2;

/// @dev The address of LooksRare token
ERC20 internal immutable LOOKS_RARE_TOKEN;

/// @dev The address of LooksRare rewards distributor
address internal immutable LOOKS_RARE_REWARDS_DISTRIBUTOR;

/// @dev The address of router rewards distributor
address internal immutable ROUTER_REWARDS_DISTRIBUTOR;

enum Spenders {
OSConduit,
Sudoswap
}

contract RouterImmutables is PaymentsImmutables, UniswapImmutables, NFTImmutables {
constructor(RouterParameters memory params)
UniswapImmutables(
UniswapParameters(params.v2Factory, params.v3Factory, params.pairInitCodeHash, params.poolInitCodeHash)
)
{
PERMIT2 = IAllowanceTransfer(params.permit2);
WETH9 = IWETH9(params.weth9);
SEAPORT_V1_5 = params.seaportV1_5;
SEAPORT_V1_4 = params.seaportV1_4;
OPENSEA_CONDUIT = params.openseaConduit;
NFTX_ZAP = params.nftxZap;
X2Y2 = params.x2y2;
FOUNDATION = params.foundation;
SUDOSWAP = params.sudoswap;
ELEMENT_MARKET = params.elementMarket;
NFT20_ZAP = params.nft20Zap;
CRYPTOPUNKS = params.cryptopunks;
LOOKS_RARE_V2 = params.looksRareV2;
LOOKS_RARE_TOKEN = ERC20(params.looksRareToken);
LOOKS_RARE_REWARDS_DISTRIBUTOR = params.looksRareRewardsDistributor;
ROUTER_REWARDS_DISTRIBUTOR = params.routerRewardsDistributor;
}
PaymentsImmutables(
PaymentsParameters(params.permit2, params.weth9, params.openseaConduit, params.sudoswap)
)
NFTImmutables(
NFTParameters(
params.seaportV1_5,
params.seaportV1_4,
params.nftxZap,
params.x2y2,
params.foundation,
params.sudoswap,
params.elementMarket,
params.nft20Zap,
params.cryptopunks,
params.looksRareV2,
params.routerRewardsDistributor,
params.looksRareRewardsDistributor,
params.looksRareToken
)
)
{}
}
73 changes: 73 additions & 0 deletions contracts/modules/NFTImmutables.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import {ERC20} from 'solmate/src/tokens/ERC20.sol';

struct NFTParameters {
address seaportV1_5;
address seaportV1_4;
address nftxZap;
address x2y2;
address foundation;
address sudoswap;
address elementMarket;
address nft20Zap;
address cryptopunks;
address looksRareV2;
address routerRewardsDistributor;
address looksRareRewardsDistributor;
address looksRareToken;
}

contract NFTImmutables {
/// @dev Seaport 1.5 address
address internal immutable SEAPORT_V1_5;

/// @dev Seaport 1.4 address
address internal immutable SEAPORT_V1_4;

/// @dev The address of NFTX zap contract for interfacing with vaults
address internal immutable NFTX_ZAP;

/// @dev The address of X2Y2
address internal immutable X2Y2;

// @dev The address of Foundation
address internal immutable FOUNDATION;

// @dev The address of Element Market
address internal immutable ELEMENT_MARKET;

// @dev the address of NFT20's zap contract
address internal immutable NFT20_ZAP;

// @dev the address of Larva Lab's cryptopunks marketplace
address internal immutable CRYPTOPUNKS;

/// @dev The address of LooksRareV2
address internal immutable LOOKS_RARE_V2;

/// @dev The address of LooksRare token
ERC20 internal immutable LOOKS_RARE_TOKEN;

/// @dev The address of LooksRare rewards distributor
address internal immutable LOOKS_RARE_REWARDS_DISTRIBUTOR;

/// @dev The address of router rewards distributor
address internal immutable ROUTER_REWARDS_DISTRIBUTOR;

constructor(NFTParameters memory params) {
SEAPORT_V1_5 = params.seaportV1_5;
SEAPORT_V1_4 = params.seaportV1_4;
NFTX_ZAP = params.nftxZap;
X2Y2 = params.x2y2;
FOUNDATION = params.foundation;
ELEMENT_MARKET = params.elementMarket;
NFT20_ZAP = params.nft20Zap;
CRYPTOPUNKS = params.cryptopunks;
LOOKS_RARE_V2 = params.looksRareV2;
LOOKS_RARE_TOKEN = ERC20(params.looksRareToken);
LOOKS_RARE_REWARDS_DISTRIBUTOR = params.looksRareRewardsDistributor;
ROUTER_REWARDS_DISTRIBUTOR = params.routerRewardsDistributor;
}
}
4 changes: 2 additions & 2 deletions contracts/modules/Payments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
pragma solidity ^0.8.17;

import {Constants} from '../libraries/Constants.sol';
import {RouterImmutables} from '../base/RouterImmutables.sol';
import {PaymentsImmutables} from '../modules/PaymentsImmutables.sol';
import {SafeTransferLib} from 'solmate/src/utils/SafeTransferLib.sol';
import {ERC20} from 'solmate/src/tokens/ERC20.sol';
import {ERC721} from 'solmate/src/tokens/ERC721.sol';
import {ERC1155} from 'solmate/src/tokens/ERC1155.sol';

/// @title Payments contract
/// @notice Performs various operations around the payment of ETH and tokens
abstract contract Payments is RouterImmutables {
abstract contract Payments is PaymentsImmutables {
using SafeTransferLib for ERC20;
using SafeTransferLib for address;

Expand Down
37 changes: 37 additions & 0 deletions contracts/modules/PaymentsImmutables.sol
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import {IWETH9} from '../interfaces/external/IWETH9.sol';
import {IAllowanceTransfer} from 'permit2/src/interfaces/IAllowanceTransfer.sol';

struct PaymentsParameters {
address permit2;
address weth9;
address openseaConduit;
address sudoswap;
}

contract PaymentsImmutables {
/// @dev WETH9 address
IWETH9 internal immutable WETH9;

/// @dev Permit2 address
IAllowanceTransfer internal immutable PERMIT2;

/// @dev The address of OpenSea's conduit used in both Seaport 1.4 and Seaport 1.5
address internal immutable OPENSEA_CONDUIT;

// @dev The address of Sudoswap's router
address internal immutable SUDOSWAP;

enum Spenders {
OSConduit,
Sudoswap
}

constructor(PaymentsParameters memory params) {
WETH9 = IWETH9(params.weth9);
PERMIT2 = IAllowanceTransfer(params.permit2);
OPENSEA_CONDUIT = params.openseaConduit;
SUDOSWAP = params.sudoswap;
}
}
4 changes: 2 additions & 2 deletions contracts/modules/uniswap/v2/V2SwapRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ pragma solidity ^0.8.17;

import {IUniswapV2Pair} from '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import {UniswapV2Library} from './UniswapV2Library.sol';
import {RouterImmutables} from '../../../base/RouterImmutables.sol';
import {UniswapImmutables} from '../UniswapImmutables.sol';
import {Payments} from '../../Payments.sol';
import {Permit2Payments} from '../../Permit2Payments.sol';
import {Constants} from '../../../libraries/Constants.sol';
import {ERC20} from 'solmate/src/tokens/ERC20.sol';

/// @title Router for Uniswap v2 Trades
abstract contract V2SwapRouter is RouterImmutables, Permit2Payments {
abstract contract V2SwapRouter is UniswapImmutables, Permit2Payments {
error V2TooLittleReceived();
error V2TooMuchRequested();
error V2InvalidPath();
Expand Down

0 comments on commit a4d9c99

Please sign in to comment.