Skip to content

Commit 9af82ed

Browse files
committed
refactor: use BurnMintErc20 everywhere
1 parent 684e8eb commit 9af82ed

File tree

4 files changed

+29
-44
lines changed

4 files changed

+29
-44
lines changed

src/apps/Bridge.sol

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22
pragma solidity ^0.8.13;
33

44
import {RollupOrders} from "zenith/src/orders/RollupOrders.sol";
5-
import {SimpleERC20} from "simple-erc20/SimpleERC20.sol";
5+
import {BurnMintERC20} from "../vendor/BurnMintERC20.sol";
66

77
import {SignetL2} from "../l2/Signet.sol";
88

9-
abstract contract BridgeL2 is SignetL2, SimpleERC20 {
9+
abstract contract BridgeL2 is SignetL2, BurnMintERC20 {
1010
/// @notice The address of the asset on the host chain.
1111
address immutable HOST_ASSET;
1212
/// @notice The address of the bank on the host chain. The bank holds the
1313
/// asset while tokens are bridged into the rollup.
1414
address immutable HOST_BANK;
1515

16-
constructor(
17-
address _hostAsset,
18-
address _hostBank,
19-
address _initialOwner,
20-
string memory _name,
21-
string memory _symbol,
22-
uint8 _decimals
23-
) SimpleERC20(_initialOwner, _name, _symbol, _decimals) {
16+
constructor(address _hostAsset, address _hostBank, string memory _name, string memory _symbol, uint8 _decimals)
17+
BurnMintERC20(_name, _symbol, _decimals, 0, 0)
18+
{
2419
HOST_ASSET = _hostAsset;
2520
HOST_BANK = _hostBank;
2621
}

src/apps/Lido.sol

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {RollupOrders} from "zenith/src/orders/RollupOrders.sol";
55
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
66
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
77

8-
import {SignetL2} from "../l2/Signet.sol";
9-
import {BurnMintERC20} from "../vendor/BurnMintERC20.sol";
8+
import {BridgeL2} from "./Bridge.sol";
109

1110
/// @notice An example contract, implementing LIDO staking from Signet L2, with
1211
/// support for CCIP teleporting.
@@ -23,47 +22,17 @@ import {BurnMintERC20} from "../vendor/BurnMintERC20.sol";
2322
/// WETH to wstETH on L1 and delivers it to `HOST_PASSAGE`, and mints stETH
2423
/// on L2 to `recipient`.
2524
///
26-
contract LidoL2 is SignetL2, BurnMintERC20 {
25+
contract LidoL2 is BridgeL2 {
2726
using SafeERC20 for IERC20;
2827

2928
/// @notice The WstETH token on the host.
3029
address public immutable HOST_WSTETH;
3130

32-
constructor(address _hostWsteth) BurnMintERC20("Signet Lido Staked Ether", "stETH", 18, 0, 0) {
31+
constructor(address _hostWsteth) BridgeL2(_hostWsteth, HOST_PASSAGE, "Lido Staked Ether", "stETH", 18) {
3332
HOST_WSTETH = _hostWsteth;
3433
WETH.forceApprove(address(ORDERS), type(uint256).max);
3534
}
3635

37-
/// @notice Create an order to bridge in wstETH from L1, and mint stETH on
38-
/// L2.
39-
function _bridgeIn(address recipient, uint256 amount, RollupOrders.Input[] memory inputs) internal {
40-
RollupOrders.Output[] memory outputs = new RollupOrders.Output[](1);
41-
outputs[0] = makeHostOutput(HOST_WSTETH, amount, address(HOST_PASSAGE));
42-
43-
ORDERS.initiate(block.timestamp, inputs, outputs);
44-
45-
_mint(recipient, amount);
46-
}
47-
48-
/// @notice Bridge in wstETH from L1, and mint stETH on L2.
49-
function bridgeIn(address recipient, uint256 amount) external {
50-
_bridgeIn(recipient, amount, new RollupOrders.Input[](0));
51-
}
52-
53-
/// @notice Burn stETH on L2, and create an order to bridge out wstETH to
54-
/// L1. If the order is not filled, the stETH will not be burned.
55-
///
56-
/// This transaction should be paired with some off-chain logic that fills
57-
/// orders from the L1 bank.
58-
function bridgeOut(address recipient, uint256 amount) public {
59-
_burn(msg.sender, amount);
60-
61-
RollupOrders.Output[] memory outputs = new RollupOrders.Output[](1);
62-
outputs[0] = makeHostOutput(HOST_WSTETH, amount, recipient);
63-
64-
ORDERS.initiate(block.timestamp, new RollupOrders.Input[](0), outputs);
65-
}
66-
6736
/// @notice Transfer WETH from `funder`, create an order to convert it to
6837
/// wstETH on L1 and bridge it to L2, and mint stETH to `recipient`.
6938
function enter(address funder, uint256 amountIn, address recipient, uint256 amountOut) external {

src/apps/SignetCoreAsset.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import {BridgeL2} from "./Bridge.sol";
5+
6+
contract SignetCoreAsset is BridgeL2 {
7+
constructor(
8+
address _hostAsset,
9+
address _hostPassageAdmin,
10+
string memory _name,
11+
string memory _symbol,
12+
uint8 _decimals
13+
) BridgeL2(_hostAsset, HOST_PASSAGE, _name, _symbol, _decimals) {
14+
_revokeRole(DEFAULT_ADMIN_ROLE, msg.sender);
15+
_grantRole(DEFAULT_ADMIN_ROLE, _hostPassageAdmin);
16+
_grantRole(MINTER_ROLE, TOKEN_MINTER);
17+
}
18+
}

src/l2/Signet.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ contract SignetL2 {
1212
/// @notice Sentinal value for the native asset in order inputs/outputs
1313
address constant NATIVE_ASSET = address(0);
1414

15+
/// @notice System address that produces System minted tokens.
16+
address constant TOKEN_MINTER = 0x00000000000000000000746f6b656E61646d696E;
17+
1518
/// @notice The chain ID of the host network.
1619
uint32 internal immutable HOST_CHAIN_ID;
1720

0 commit comments

Comments
 (0)