Skip to content

Commit 6dd9ee5

Browse files
committed
feat: wethToSignet
1 parent ebc5895 commit 6dd9ee5

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/interfaces/IWETH.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity >0.8.13;
3+
4+
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
5+
6+
interface IWETH is IERC20 {
7+
/// @notice Deposit ETH to get WETH
8+
function deposit() external payable;
9+
10+
/// @notice Withdraw WETH to get ETH
11+
function withdraw(uint256 amount) external;
12+
}

src/l1/Signet.sol

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.13;
44
import {HostOrders} from "zenith/src/orders/HostOrders.sol";
55
import {Passage} from "zenith/src/passage/Passage.sol";
66
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
7+
import {IWETH} from "../interfaces/IWETH.sol";
78

89
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
910
import {PecorinoConstants} from "../chains/Pecorino.sol";
@@ -18,7 +19,7 @@ abstract contract SignetL1 {
1819
HostOrders internal immutable ORDERS;
1920

2021
/// @notice The WETH token address.
21-
IERC20 internal immutable WETH;
22+
IWETH internal immutable WETH;
2223
/// @notice The WBTC token address.
2324
IERC20 internal immutable WBTC;
2425
/// @notice The USDC token address.
@@ -41,7 +42,7 @@ abstract contract SignetL1 {
4142
PASSAGE = PecorinoConstants.HOST_PASSAGE;
4243
ORDERS = PecorinoConstants.HOST_ORDERS;
4344

44-
WETH = IERC20(PecorinoConstants.HOST_WETH);
45+
WETH = IWETH(PecorinoConstants.HOST_WETH);
4546
WBTC = IERC20(PecorinoConstants.HOST_WBTC);
4647
USDC = IERC20(PecorinoConstants.HOST_USDC);
4748
USDT = IERC20(PecorinoConstants.HOST_USDT);
@@ -73,6 +74,7 @@ abstract contract SignetL1 {
7374
return AddressAliasHelper.applyL1ToL2Alias(address(this));
7475
}
7576

77+
/// @notice Helper to create an output struct.
7678
function makeOutput(address token, uint256 amount, address recipient)
7779
internal
7880
pure
@@ -84,36 +86,49 @@ abstract contract SignetL1 {
8486
output.chainId = PecorinoConstants.HOST_CHAIN_ID;
8587
}
8688

89+
/// @notice Helper to create an Output struct for usdc.
8790
function usdcOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) {
8891
return makeOutput(address(USDC), amount, recipient);
8992
}
9093

94+
/// @notice Helper to create an Output struct for usdt.
9195
function usdtOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) {
9296
return makeOutput(address(USDT), amount, recipient);
9397
}
9498

99+
/// @notice Helper to create an Output struct for wbtc.
95100
function wbtcOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) {
96101
return makeOutput(address(WBTC), amount, recipient);
97102
}
98103

104+
/// @notice Helper to create an Output struct for weth.
99105
function wethOutput(uint256 amount, address recipient) internal view returns (HostOrders.Output memory output) {
100106
return makeOutput(address(WETH), amount, recipient);
101107
}
102108

109+
/// @notice Helper to create an Output struct for eth.
103110
function ethOutput(uint256 amount, address recipient) internal pure returns (HostOrders.Output memory output) {
104111
return makeOutput(NATIVE_ASSET, amount, recipient);
105112
}
106113

107-
function enterSignetToken(address token, uint256 amount) internal {
114+
/// @notice Send tokens into Signet via the Passage contract.
115+
function tokensToSignet(address token, uint256 amount) internal {
108116
if (token == NATIVE_ASSET) {
109-
enterSignetEth(amount);
117+
ethToSignet(amount);
110118
return;
111119
}
112120
IERC20(token).approve(address(PASSAGE), amount);
113121
PASSAGE.enterToken(selfOnL2(), token, amount);
114122
}
115123

116-
function enterSignetEth(uint256 amount) internal {
124+
/// @notice Send ETH into Signet via the Passage contract.
125+
function ethToSignet(uint256 amount) internal {
117126
PASSAGE.enter{value: amount}(selfOnL2());
118127
}
128+
129+
/// @notice Send WETH into Signet via the Passage contract.
130+
function wethToSignet(uint256 amount) internal {
131+
WETH.withdraw(amount);
132+
ethToSignet(amount);
133+
}
119134
}

test/Tests.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4-
contract TestNop {
4+
import {Test} from "forge-std/Test.sol";
5+
6+
contract TestNop is Test {
57
/// @notice Prevents foundry from complaining about no tests in CI.
68
function test_nop() external pure returns (bool) {
79
return true;
810
}
911
}
12+

0 commit comments

Comments
 (0)