-
Notifications
You must be signed in to change notification settings - Fork 1
feat: SignetL1 #4
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
Open
prestwich
wants to merge
5
commits into
prestwich/clean-up
Choose a base branch
from
prestwich/l1-lib
base: prestwich/clean-up
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+218
−5
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
| pragma solidity >0.8.13; | ||
|
|
||
| import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
|
|
||
| interface IWETH is IERC20 { | ||
| /// @notice Deposit ETH to get WETH | ||
| function deposit() external payable; | ||
|
|
||
| /// @notice Withdraw WETH to get ETH | ||
| function withdraw(uint256 amount) external; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {HostOrders} from "zenith/src/orders/HostOrders.sol"; | ||
| import {Passage} from "zenith/src/passage/Passage.sol"; | ||
| import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
| import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
| import {IWETH} from "../interfaces/IWETH.sol"; | ||
|
|
||
| import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol"; | ||
| import {PecorinoConstants} from "../chains/Pecorino.sol"; | ||
|
|
||
| abstract contract SignetL1 { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| /// @notice Sentinel value for the native asset in order inputs/outputs | ||
| address constant NATIVE_ASSET = address(0); | ||
|
|
||
| /// @notice The Passage address | ||
| Passage internal immutable PASSAGE; | ||
| /// @notice The Host Orders address | ||
| HostOrders internal immutable ORDERS; | ||
|
|
||
| /// @notice The WETH token address. | ||
| IWETH internal immutable WETH; | ||
| /// @notice The WBTC token address. | ||
| IERC20 internal immutable WBTC; | ||
| /// @notice The USDC token address. | ||
| IERC20 internal immutable USDC; | ||
| /// @notice The USDT token address. | ||
| IERC20 internal immutable USDT; | ||
|
|
||
| /// @notice The Rollup WUSD token address. | ||
| address internal immutable RU_WUSD; | ||
| /// @notice The Rollup WBTC token address. | ||
| address internal immutable RU_WBTC; | ||
| /// @notice The Rollup WETH token address. | ||
| address internal immutable RU_WETH; | ||
|
|
||
| /// @notice Error for unsupported chain IDs. | ||
| error UnsupportedChain(uint256); | ||
|
|
||
| constructor() { | ||
| if (block.chainid == PecorinoConstants.HOST_CHAIN_ID) { | ||
| PASSAGE = PecorinoConstants.HOST_PASSAGE; | ||
| ORDERS = PecorinoConstants.HOST_ORDERS; | ||
|
|
||
| WETH = IWETH(PecorinoConstants.HOST_WETH); | ||
| WBTC = IERC20(PecorinoConstants.HOST_WBTC); | ||
| USDC = IERC20(PecorinoConstants.HOST_USDC); | ||
| USDT = IERC20(PecorinoConstants.HOST_USDT); | ||
|
|
||
| RU_WUSD = address(PecorinoConstants.WUSD); | ||
| RU_WBTC = address(PecorinoConstants.WBTC); | ||
| RU_WETH = address(PecorinoConstants.WETH); | ||
| } else { | ||
| revert UnsupportedChain(block.chainid); | ||
| } | ||
| } | ||
|
|
||
| /// @notice Returns the address of this contract on L2, applying an | ||
| /// address alias. | ||
| function selfOnL2() internal view virtual returns (address) { | ||
| if (address(this).code.length == 23) { | ||
| bool is7702; | ||
| assembly { | ||
| let ptr := mload(0x40) | ||
| codecopy(ptr, 0, 0x20) | ||
| is7702 := eq(shr(232, mload(ptr)), 0xEF0100) | ||
| // clean the memory we used. Unnecessary, but good hygiene | ||
| mstore(ptr, 0x0) | ||
| } | ||
| if (is7702) { | ||
| return address(this); | ||
| } | ||
| } | ||
| return AddressAliasHelper.applyL1ToL2Alias(address(this)); | ||
| } | ||
|
|
||
| /// @notice Helper to create an output struct. | ||
| function makeOutput(address token, uint256 amount, address recipient) | ||
| internal | ||
| pure | ||
| returns (HostOrders.Output memory output) | ||
| { | ||
| output.token = token; | ||
| output.amount = amount; | ||
| output.recipient = recipient; | ||
| output.chainId = PecorinoConstants.HOST_CHAIN_ID; | ||
| } | ||
|
|
||
| /// @notice Helper to create an Output struct for usdc. | ||
| function usdcOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) { | ||
| return makeOutput(address(USDC), amount, recipient); | ||
| } | ||
|
|
||
| /// @notice Helper to create an Output struct for usdt. | ||
| function usdtOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) { | ||
| return makeOutput(address(USDT), amount, recipient); | ||
| } | ||
|
|
||
| /// @notice Helper to create an Output struct for wbtc. | ||
| function wbtcOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) { | ||
| return makeOutput(address(WBTC), amount, recipient); | ||
| } | ||
|
|
||
| /// @notice Helper to create an Output struct for weth. | ||
| function wethOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) { | ||
| return makeOutput(address(WETH), amount, recipient); | ||
| } | ||
|
|
||
| /// @notice Helper to create an Output struct for eth. | ||
| function ethOutput(uint256 amount, address recipient) internal pure returns (HostOrders.Output memory output) { | ||
| return makeOutput(NATIVE_ASSET, amount, recipient); | ||
| } | ||
|
|
||
| /// @notice Send tokens into Signet via the Passage contract. | ||
| function tokensToSignet(address token, uint256 amount) internal { | ||
| if (token == NATIVE_ASSET) { | ||
| ethToSignet(amount); | ||
| return; | ||
| } | ||
| IERC20(token).forceApprove(address(PASSAGE), amount); | ||
| PASSAGE.enterToken(selfOnL2(), token, amount); | ||
| } | ||
|
|
||
| /// @notice Send ETH into Signet via the Passage contract. | ||
| function ethToSignet(uint256 amount) internal { | ||
| PASSAGE.enter{value: amount}(selfOnL2()); | ||
| } | ||
|
|
||
| /// @notice Send WETH into Signet via the Passage contract. | ||
| function wethToSignet(uint256 amount) internal { | ||
| WETH.withdraw(amount); | ||
| ethToSignet(amount); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {SignetL1} from "./Signet.sol"; | ||
|
|
||
| abstract contract SignetL1Ephemeral is SignetL1 { | ||
| function selfOnL2() internal view override returns (address) { | ||
| return address(this); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /* | ||
| * Copyright 2019-2021, Offchain Labs, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| library AddressAliasHelper { | ||
| uint160 constant offset = uint160(0x1111000000000000000000000000000000001111); | ||
|
|
||
| /// @notice Utility function that converts the address in the L1 that submitted a tx to | ||
| /// the inbox to the msg.sender viewed in the L2 | ||
| /// @param l1Address the address in the L1 that triggered the tx to L2 | ||
| /// @return l2Address L2 address as viewed in msg.sender | ||
| function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) { | ||
| unchecked { | ||
| l2Address = address(uint160(l1Address) + offset); | ||
| } | ||
| } | ||
|
|
||
| /// @notice Utility function that converts the msg.sender viewed in the L2 to the | ||
| /// address in the L1 that submitted a tx to the inbox | ||
| /// @param l2Address L2 address as viewed in msg.sender | ||
| /// @return l1Address the address in the L1 that triggered the tx to L2 | ||
| function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) { | ||
| unchecked { | ||
| l1Address = address(uint160(l2Address) - offset); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| contract TestNop { | ||
| import {Test} from "forge-std/Test.sol"; | ||
|
|
||
| contract TestNop is Test { | ||
| /// @notice Prevents foundry from complaining about no tests in CI. | ||
| function test_nop() external pure returns (bool) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i actually still think this is wrong. won't this just copy the actual
SignetL1(the delegation target) code instead of the EOA's code?