-
Notifications
You must be signed in to change notification settings - Fork 1
feat: basic third-party bridge app #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
298f3d8
feat: basic third-party bridge app
prestwich eb9d584
lint: fmt
prestwich bbe5648
refactor: move down
prestwich bde89cd
chore: add some natspec
prestwich 97e0668
lint: fmt
prestwich 684e8eb
chore: add natspec
prestwich 9af82ed
refactor: use BurnMintErc20 everywhere
prestwich 8dce57e
fix: ownable constructor invocation
prestwich 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {RollupOrders} from "zenith/src/orders/RollupOrders.sol"; | ||
| import {BurnMintERC20} from "../vendor/BurnMintERC20.sol"; | ||
|
|
||
| import {SignetL2} from "../l2/Signet.sol"; | ||
|
|
||
| abstract contract BridgeL2 is SignetL2, BurnMintERC20 { | ||
| /// @notice The address of the asset on the host chain. | ||
| address immutable HOST_ASSET; | ||
| /// @notice The address of the bank on the host chain. The bank holds the | ||
| /// asset while tokens are bridged into the rollup. | ||
| address immutable HOST_BANK; | ||
|
|
||
| constructor(address _hostAsset, address _hostBank, string memory _name, string memory _symbol, uint8 _decimals) | ||
| BurnMintERC20(_name, _symbol, _decimals, 0, 0) | ||
| { | ||
| HOST_ASSET = _hostAsset; | ||
| HOST_BANK = _hostBank; | ||
| } | ||
|
|
||
| /// @notice Bridges assets into the rollup for a given recipient. | ||
| function _bridgeIn(address recipient, uint256 amount, RollupOrders.Input[] memory inputs) internal virtual { | ||
| _mint(recipient, amount); | ||
|
|
||
| RollupOrders.Output[] memory outputs = new RollupOrders.Output[](1); | ||
| outputs[0] = makeHostOutput(HOST_ASSET, amount, HOST_BANK); | ||
|
|
||
| ORDERS.initiate(block.timestamp, inputs, outputs); | ||
| } | ||
|
|
||
| /// @notice Bridges assets into the rollup for a given recipient. | ||
| function bridgeIn(address recipient, uint256 amount) public virtual { | ||
| _bridgeIn(recipient, amount, new RollupOrders.Input[](0)); | ||
| } | ||
|
|
||
| /// @notice Burn asset on L2, and create an order to bridge out asset to | ||
| /// L1. If the order is not filled, the asset will not be burned. | ||
| /// | ||
| /// This transaction should be paired with some off-chain logic that fills | ||
| /// orders from the L1 bank. | ||
| function _bridgeOut(address sender, address recipient, uint256 amount, RollupOrders.Input[] memory inputs) | ||
| internal | ||
| virtual | ||
| { | ||
| if (_msgSender() != sender) { | ||
| _spendAllowance(sender, _msgSender(), amount); | ||
| } | ||
|
|
||
| _burn(msg.sender, amount); | ||
|
|
||
| RollupOrders.Output[] memory outputs = new RollupOrders.Output[](1); | ||
| outputs[0] = makeHostOutput(HOST_ASSET, amount, recipient); | ||
|
|
||
| ORDERS.initiate(block.timestamp, inputs, outputs); | ||
| } | ||
|
|
||
| /// @notice Burn asset on L2, and create an order to bridge out assets to | ||
| /// L1. If the order is not filled, the asset will not be burned. | ||
| /// | ||
| /// This transaction should be paired with some off-chain logic that fills | ||
| /// orders from the L1 bank. | ||
| function bridgeOut(address recipient, uint256 amount) public virtual { | ||
| _bridgeOut(msg.sender, recipient, amount, new RollupOrders.Input[](0)); | ||
| } | ||
|
|
||
| /// @notice Burn asset on L2 from `sender`, and create an order to bridge | ||
| /// out assets to L1. If the order is not filled, the asset will not be | ||
| /// burned. Used when the caller is not the sender. | ||
| /// | ||
| /// This transaction should be paired with some off-chain logic that fills | ||
| /// orders from the L1 bank. | ||
| function bridgeOutFrom(address sender, address recipient, uint256 amount) public virtual { | ||
| _bridgeOut(sender, recipient, amount, new RollupOrders.Input[](0)); | ||
| } | ||
| } |
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,46 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {RollupOrders} from "zenith/src/orders/RollupOrders.sol"; | ||
| import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
| import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
|
|
||
| import {BridgeL2} from "./Bridge.sol"; | ||
|
|
||
| /// @notice An example contract, implementing LIDO staking from Signet L2, with | ||
| /// support for CCIP teleporting. | ||
| /// Allows bridging two ways: | ||
| /// - Signet native bridging with Orders. | ||
| /// - CCIP Teleporting via support for the CCT standard. | ||
| /// | ||
| /// Bridging with Signet: | ||
| /// - bridgeIn: Creates an order that delilvers wstETH to `HOST_PASSAGE` on L1. | ||
| /// If the order is filled, mints stETH on L2 to `recipient`. | ||
| /// - bridgeOut: Burns stETH on L2 from `msg.sender`, and creates an order | ||
| /// that delivers wstETH to `recipient` on L1. | ||
| /// - enter: Transfers WETH from `funder`, creates an order that converts | ||
| /// WETH to wstETH on L1 and delivers it to `HOST_PASSAGE`, and mints stETH | ||
| /// on L2 to `recipient`. | ||
| /// | ||
| contract LidoL2 is BridgeL2 { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| /// @notice The WstETH token on the host. | ||
| address public immutable HOST_WSTETH; | ||
|
|
||
| constructor(address _hostWsteth) BridgeL2(_hostWsteth, HOST_PASSAGE, "Lido Staked Ether", "stETH", 18) { | ||
| HOST_WSTETH = _hostWsteth; | ||
| WETH.forceApprove(address(ORDERS), type(uint256).max); | ||
| } | ||
|
|
||
| /// @notice Transfer WETH from `funder`, create an order to convert it to | ||
| /// wstETH on L1 and bridge it to L2, and mint stETH to `recipient`. | ||
| function enter(uint256 amountIn, address recipient, uint256 amountOut) external { | ||
| WETH.safeTransferFrom(msg.sender, address(this), amountIn); | ||
|
|
||
| RollupOrders.Input[] memory inputs = new RollupOrders.Input[](1); | ||
| inputs[0] = makeWethInput(amountIn); | ||
|
|
||
| _bridgeIn(recipient, amountOut, inputs); | ||
| } | ||
| } | ||
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,18 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {BridgeL2} from "./Bridge.sol"; | ||
|
|
||
| contract SignetCoreAsset is BridgeL2 { | ||
| constructor( | ||
| address _hostAsset, | ||
| address _hostPassageAdmin, | ||
| string memory _name, | ||
| string memory _symbol, | ||
| uint8 _decimals | ||
| ) BridgeL2(_hostAsset, HOST_PASSAGE, _name, _symbol, _decimals) { | ||
| _revokeRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
| _grantRole(DEFAULT_ADMIN_ROLE, _hostPassageAdmin); | ||
| _grantRole(MINTER_ROLE, TOKEN_MINTER); | ||
| } | ||
| } |
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,10 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol"; | ||
|
|
||
| import {SignetL2} from "./Signet.sol"; | ||
|
|
||
| abstract contract SelfOwned is SignetL2, Ownable { | ||
| constructor() Ownable(aliasedSelf()) {} | ||
| } |
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
Oops, something went wrong.
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.