Skip to content

Commit

Permalink
Prepare for v4 work (#346)
Browse files Browse the repository at this point in the history
* update hardhat

* remove symlinks by using hardhat-foundry

use hardhat-foundry package to use foundry remappings to compile. Symlinks are no longer necessary
After upgrade HH412 error was thrown caused by the existing symlinks
ref:
https://hardhat.org/hardhat-runner/docs/errors#HH412
NomicFoundation/hardhat#3623

* update compiler version to ^0.8.24 supporting the cancun upgrades

* fix ci

* fix lock file

* Update yarn.lock

* regenerate gas snapshots

* install foundry in ci

* Use mainnet permit2 (#347)

* solc upgrade to 0.8.26

* use mainnet permit2 work started

* fix uniswap tests

* Remove block from resetFork

* Refactor to fetch fee tiers

* remove NFT protocols for V4 router (#348)

* first pass

* fix forge builds

* fix reentrancy test

* Add check to receive

* remove .only rip

* add todo for tests that need wrtiting

* update readme and planner

---------

Co-authored-by: Alice <34962750+hensha256@users.noreply.github.com>
Co-authored-by: Alice Henshaw <henshawalice@gmail.com>
  • Loading branch information
3 people committed Jun 14, 2024
1 parent 228f2d1 commit 6cf84c8
Show file tree
Hide file tree
Showing 126 changed files with 613 additions and 13,000 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ jobs:
# Must Insall node modules for forge to reference in remappings
- uses: actions/setup-node@v1
with:
node-version: 16.x
node-version: 18.x
registry-url: https://registry.npmjs.org

- name: Install Yarn
run: npm install -g yarn

- id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ jobs:
- name: Set up node
uses: actions/setup-node@v1
with:
node-version: 16.x
node-version: 18.x
registry-url: https://registry.npmjs.org

- name: Install Yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ jobs:

- uses: actions/setup-node@v1
with:
node-version: 16.x
node-version: 18.x
registry-url: https://registry.npmjs.org

- name: Install Yarn
run: npm install -g yarn

- id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

Expand All @@ -34,6 +37,11 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

# This is required separately from yarn test because it generates the typechain definitions
- name: Compile
run: yarn compile
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Compiler files
cache/
cache_hardhat/
out/

# Ignores development broadcast logs
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ out
openzeppelin-contracts
permit2
solmate
cache_hardhat
44 changes: 3 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,49 +84,12 @@ Each command is a `bytes1` containing the following 8 bits:
├──────┼───────────────────────────────┤
│ 0x0d │ PERMIT2_TRANSFER_FROM_BATCH │
├──────┼───────────────────────────────┤
│ 0x0e │ ------- │
├──────┼───────────────────────────────┤
│ 0x0f │ ------- │
├──────┼───────────────────────────────┤
│ 0x10 │ SEAPORT_V1_5 │
├──────┼───────────────────────────────┤
│ 0x11 │ LOOKS_RARE_721 │
├──────┼───────────────────────────────┤
│ 0x12 │ NFTX │
├──────┼───────────────────────────────┤
│ 0x13 │ CRYPTOPUNKS │
├──────┼───────────────────────────────┤
│ 0x14 │ LOOKS_RARE_1155 │
├──────┼───────────────────────────────┤
│ 0x15 │ OWNER_CHECK_721 │
├──────┼───────────────────────────────┤
│ 0x16 │ OWNER_CHECK_1155 │
├──────┼───────────────────────────────┤
│ 0x17 │ SWEEP_ERC721 │
├──────┼───────────────────────────────┤
│ 0x18 │ X2Y2_721 │
├──────┼───────────────────────────────┤
│ 0x19 │ SUDOSWAP │
├──────┼───────────────────────────────┤
│ 0x1a │ NFT20 │
├──────┼───────────────────────────────┤
│ 0x1b │ X2Y2_1155 │
├──────┼───────────────────────────────┤
│ 0x1c │ FOUNDATION │
├──────┼───────────────────────────────┤
│ 0x1d │ SWEEP_ERC1155 │
├──────┼───────────────────────────────┤
│ 0x1e │ ELEMENT_MARKET │
├──────┼───────────────────────────────┤
│ 0x1f │ ------- │
├──────┼───────────────────────────────┤
│ 0x20 │ SEAPORT_V1_4 │
│ 0x0e-│ ------- │
│ 0x20 │ │
├──────┼───────────────────────────────┤
│ 0x21 │ EXECUTE_SUB_PLAN │
├──────┼───────────────────────────────┤
│ 0x22 │ APPROVE_ERC20 │
├──────┼───────────────────────────────┤
│ 0x23-│ ------- │
│ 0x22-│ ------- │
│ 0x3f │ │
└──────┴───────────────────────────────┘
```
Expand Down Expand Up @@ -180,7 +143,6 @@ INFURA_API_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

```console
yarn install
yarn symlink
yarn compile
yarn test
```
Expand Down
31 changes: 7 additions & 24 deletions contracts/UniversalRouter.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
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();
}
}
25 changes: 3 additions & 22 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.17;
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;
}
}
Loading

0 comments on commit 6cf84c8

Please sign in to comment.