Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove NFT protocols for V4 router #348

Merged
merged 6 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions contracts/UniversalRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ pragma solidity ^0.8.24;

// Command implementations
import {Dispatcher} from './base/Dispatcher.sol';
import {RewardsCollector} from './base/RewardsCollector.sol';
import {RouterParameters} from './base/RouterImmutables.sol';
import {PaymentsImmutables, PaymentsParameters} from './modules/PaymentsImmutables.sol';
import {NFTImmutables, NFTParameters} from './modules/NFTImmutables.sol';
import {UniswapImmutables, UniswapParameters} from './modules/uniswap/UniswapImmutables.sol';
import {Commands} from './libraries/Commands.sol';
import {IUniversalRouter} from './interfaces/IUniversalRouter.sol';

contract UniversalRouter is IUniversalRouter, Dispatcher, RewardsCollector {
contract UniversalRouter is IUniversalRouter, Dispatcher {
modifier checkDeadline(uint256 deadline) {
if (block.timestamp > deadline) revert TransactionDeadlinePassed();
_;
Expand All @@ -21,24 +19,7 @@ contract UniversalRouter is IUniversalRouter, Dispatcher, RewardsCollector {
UniswapImmutables(
UniswapParameters(params.v2Factory, params.v3Factory, params.pairInitCodeHash, params.poolInitCodeHash)
)
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
)
)
PaymentsImmutables(PaymentsParameters(params.permit2, params.weth9))
{}

/// @inheritdoc IUniversalRouter
Expand Down Expand Up @@ -79,6 +60,8 @@ contract UniversalRouter is IUniversalRouter, Dispatcher, RewardsCollector {
return command & Commands.FLAG_ALLOW_REVERT == 0;
}

/// @notice To receive ETH from WETH and NFT protocols
receive() external payable {}
/// @notice To receive ETH from WETH
receive() external payable {
if (msg.sender != address(WETH9)) revert InvalidEthSender();
}
}
23 changes: 2 additions & 21 deletions contracts/base/Callbacks.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;

import {IERC721Receiver} from '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import {IERC1155Receiver} from '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol';
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';

/// @title ERC Callback Support
/// @notice Implements various functions introduced by a variety of ERCs for security reasons.
/// All are called by external contracts to ensure that this contract safely supports the ERC in question.
contract Callbacks is IERC721Receiver, IERC1155Receiver {
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC721Received.selector;
}

function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC1155Received.selector;
}

function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
external
pure
returns (bytes4)
{
return this.onERC1155BatchReceived.selector;
}

contract Callbacks {
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || interfaceId == type(IERC721Receiver).interfaceId
|| interfaceId == type(IERC165).interfaceId;
return interfaceId == type(IERC165).interfaceId;
}
}
532 changes: 163 additions & 369 deletions contracts/base/Dispatcher.sol

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions contracts/base/RewardsCollector.sol

This file was deleted.

14 changes: 0 additions & 14 deletions contracts/base/RouterImmutables.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ pragma solidity ^0.8.24;
struct RouterParameters {
address permit2;
address weth9;
address seaportV1_5;
address seaportV1_4;
address openseaConduit;
address nftxZap;
address x2y2;
address foundation;
address sudoswap;
address elementMarket;
address nft20Zap;
address cryptopunks;
address looksRareV2;
address routerRewardsDistributor;
address looksRareRewardsDistributor;
address looksRareToken;
address v2Factory;
address v3Factory;
bytes32 pairInitCodeHash;
Expand Down
13 changes: 0 additions & 13 deletions contracts/interfaces/IRewardsCollector.sol

This file was deleted.

9 changes: 4 additions & 5 deletions contracts/interfaces/IUniversalRouter.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;

import {IERC721Receiver} from '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import {IERC1155Receiver} from '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol';
import {IRewardsCollector} from './IRewardsCollector.sol';

interface IUniversalRouter is IRewardsCollector, IERC721Receiver, IERC1155Receiver {
interface IUniversalRouter {
/// @notice Thrown when a required command has failed
error ExecutionFailed(uint256 commandIndex, bytes message);

Expand All @@ -18,6 +14,9 @@ interface IUniversalRouter is IRewardsCollector, IERC721Receiver, IERC1155Receiv
/// @notice Thrown when attempting to execute commands and an incorrect number of inputs are provided
error LengthMismatch();

// @notice Thrown when an address that isnt WETH tries to send ETH to the router without calldata
error InvalidEthSender();

/// @notice Executes encoded commands along with provided inputs. Reverts if deadline has expired.
/// @param commands A set of concatenated commands, each 1 byte in length
/// @param inputs An array of byte strings containing abi encoded inputs for each command
Expand Down
11 changes: 0 additions & 11 deletions contracts/interfaces/external/ICryptoPunksMarket.sol

This file was deleted.

22 changes: 0 additions & 22 deletions contracts/libraries/Commands.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,15 @@ library Commands {
// The following constant defines one of the boundaries where the if blocks split commands
uint256 constant SECOND_IF_BOUNDARY = 0x10;

// Command Types where 0x10<=value<0x18, executed in the third nested-if block
uint256 constant SEAPORT_V1_5 = 0x10;
uint256 constant LOOKS_RARE_V2 = 0x11;
uint256 constant NFTX = 0x12;
uint256 constant CRYPTOPUNKS = 0x13;
// 0x14;
uint256 constant OWNER_CHECK_721 = 0x15;
uint256 constant OWNER_CHECK_1155 = 0x16;
uint256 constant SWEEP_ERC721 = 0x17;

// The commands are executed in nested if blocks to minimise gas consumption
// The following constant defines one of the boundaries where the if blocks split commands
uint256 constant THIRD_IF_BOUNDARY = 0x18;

// Command Types where 0x18<=value<=0x1f, executed in the final nested-if block
uint256 constant X2Y2_721 = 0x18;
uint256 constant SUDOSWAP = 0x19;
uint256 constant NFT20 = 0x1a;
uint256 constant X2Y2_1155 = 0x1b;
uint256 constant FOUNDATION = 0x1c;
uint256 constant SWEEP_ERC1155 = 0x1d;
uint256 constant ELEMENT_MARKET = 0x1e;
// COMMAND_PLACEHOLDER = 0x1f;

// The commands are executed in nested if blocks to minimise gas consumption
// The following constant defines one of the boundaries where the if blocks split commands
uint256 constant FOURTH_IF_BOUNDARY = 0x20;

// Command Types where 0x20<=value
uint256 constant SEAPORT_V1_4 = 0x20;
uint256 constant EXECUTE_SUB_PLAN = 0x21;
uint256 constant APPROVE_ERC20 = 0x22;
// COMMAND_PLACEHOLDER for 0x23 to 0x3f (all unused)
}
73 changes: 0 additions & 73 deletions contracts/modules/NFTImmutables.sol

This file was deleted.

36 changes: 0 additions & 36 deletions contracts/modules/Payments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {Constants} from '../libraries/Constants.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
Expand Down Expand Up @@ -37,21 +35,6 @@ abstract contract Payments is PaymentsImmutables {
}
}

/// @notice Approves a protocol to spend ERC20s in the router
/// @param token The token to approve
/// @param spender Which protocol to approve
function approveERC20(ERC20 token, Spenders spender) internal {
hensha256 marked this conversation as resolved.
Show resolved Hide resolved
// check spender is one of our approved spenders
address spenderAddress;
/// @dev use 0 = Opensea Conduit for both Seaport v1.4 and v1.5
if (spender == Spenders.OSConduit) spenderAddress = OPENSEA_CONDUIT;
else if (spender == Spenders.Sudoswap) spenderAddress = SUDOSWAP;
else revert InvalidSpender();

// set approval
token.safeApprove(spenderAddress, type(uint256).max);
}

/// @notice Pays a proportion of the contract's ETH or ERC20 to a recipient
/// @param token The token to pay (can be ETH using Constants.ETH)
/// @param recipient The address that will receive payment
Expand Down Expand Up @@ -86,25 +69,6 @@ abstract contract Payments is PaymentsImmutables {
}
}

/// @notice Sweeps an ERC721 to a recipient from the contract
/// @param token The ERC721 token to sweep
/// @param recipient The address that will receive payment
/// @param id The ID of the ERC721 to sweep
function sweepERC721(address token, address recipient, uint256 id) internal {
ERC721(token).safeTransferFrom(address(this), recipient, id);
}

/// @notice Sweeps all of the contract's ERC1155 to an address
/// @param token The ERC1155 token to sweep
/// @param recipient The address that will receive payment
/// @param id The ID of the ERC1155 to sweep
/// @param amountMinimum The minimum desired amount
function sweepERC1155(address token, address recipient, uint256 id, uint256 amountMinimum) internal {
uint256 balance = ERC1155(token).balanceOf(address(this), id);
if (balance < amountMinimum) revert InsufficientToken();
ERC1155(token).safeTransferFrom(address(this), recipient, id, balance, bytes(''));
}

/// @notice Wraps an amount of ETH into WETH
/// @param recipient The recipient of the WETH
/// @param amount The amount to wrap (can be CONTRACT_BALANCE)
Expand Down
10 changes: 0 additions & 10 deletions contracts/modules/PaymentsImmutables.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {IPermit2} from 'permit2/src/interfaces/IPermit2.sol';
struct PaymentsParameters {
address permit2;
address weth9;
address openseaConduit;
address sudoswap;
}

contract PaymentsImmutables {
Expand All @@ -18,12 +16,6 @@ contract PaymentsImmutables {
/// @dev Permit2 address
IPermit2 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
Expand All @@ -32,7 +24,5 @@ contract PaymentsImmutables {
constructor(PaymentsParameters memory params) {
WETH9 = IWETH9(params.weth9);
PERMIT2 = IPermit2(params.permit2);
OPENSEA_CONDUIT = params.openseaConduit;
SUDOSWAP = params.sudoswap;
}
}
8 changes: 0 additions & 8 deletions contracts/test/ImportsForTypechain.sol

This file was deleted.

Loading
Loading