-
Notifications
You must be signed in to change notification settings - Fork 304
Add support for custom gas token chains #141
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 2 commits
Commits
Show all changes
4 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
72 changes: 72 additions & 0 deletions
72
packages/contract-deposit/contracts/CustomGasTokenDeposit.sol
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,72 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@arbitrum/nitro-contracts/src/bridge/IERC20Inbox.sol"; | ||
import "@arbitrum/nitro-contracts/src/bridge/IERC20Bridge.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
contract CustomGasTokenDeposit { | ||
using SafeERC20 for IERC20; | ||
|
||
IERC20Inbox public inbox; | ||
|
||
event CustomGasTokenDeposited(uint256 indexed ticketId); | ||
event RetryableTicketCreated(uint256 indexed ticketId); | ||
|
||
constructor(address _inbox) { | ||
inbox = IERC20Inbox(_inbox); | ||
} | ||
|
||
function depositToChildChain(uint256 amount) public returns (uint256) { | ||
// Transfer the native token to this contract | ||
// and allow Inbox to transfer those tokens | ||
address bridge = address(inbox.bridge()); | ||
address nativeToken = IERC20Bridge(bridge).nativeToken(); | ||
|
||
IERC20(nativeToken).safeTransferFrom(msg.sender, address(this), amount); | ||
IERC20(nativeToken).approve(address(inbox), amount); | ||
|
||
uint256 ticketID = inbox.depositERC20(amount); | ||
|
||
emit CustomGasTokenDeposited(ticketID); | ||
return ticketID; | ||
} | ||
|
||
function moveFundsFromChildChainAliasToAnotherAddress( | ||
address to, | ||
uint256 l2callvalue, | ||
uint256 maxSubmissionCost, | ||
uint256 maxGas, | ||
uint256 gasPriceBid, | ||
uint256 tokenAmount | ||
) public returns (uint256) { | ||
// Transfer the native token to this contract | ||
// and allow Inbox to transfer those tokens | ||
address bridge = address(inbox.bridge()); | ||
address nativeToken = IERC20Bridge(bridge).nativeToken(); | ||
|
||
IERC20(nativeToken).safeTransferFrom(msg.sender, address(this), tokenAmount); | ||
IERC20(nativeToken).approve(address(inbox), tokenAmount); | ||
|
||
/** | ||
* We are using unsafeCreateRetryableTicket because the safe one will check if | ||
* the parent chain's msg.value can be used to pay for the child chain's callvalue, while in this case | ||
* we'll use child chain's balance to pay for the callvalue rather than parent chain's msg.value | ||
*/ | ||
uint256 ticketID = inbox.unsafeCreateRetryableTicket( | ||
to, | ||
l2callvalue, | ||
maxSubmissionCost, | ||
msg.sender, | ||
msg.sender, | ||
maxGas, | ||
gasPriceBid, | ||
tokenAmount, | ||
"" | ||
); | ||
|
||
emit RetryableTicketCreated(ticketID); | ||
return ticketID; | ||
} | ||
} |
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
18 changes: 9 additions & 9 deletions
18
packages/custom-gateway-bridging/contracts/ChildChainToken.sol
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.
Uh oh!
There was an error while loading. Please reload this page.