forked from OffchainLabs/nitro-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add XERC20Bridge POC #1
Open
lmcorbalan
wants to merge
1
commit into
develop
Choose a base branch
from
xer20-poc
base: develop
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.
Open
Conversation
This file contains 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
Comment on lines
+41
to
+126
contract XERC20Bridge is AbsBridge, IERC20Bridge { | ||
using SafeERC20 for IERC20; | ||
|
||
/// @inheritdoc IERC20Bridge | ||
address public nativeToken; | ||
|
||
/// @inheritdoc IERC20Bridge | ||
uint8 public nativeTokenDecimals; | ||
|
||
/// @inheritdoc IERC20Bridge | ||
function initialize(IOwnable rollup_, address nativeToken_) external initializer onlyDelegated { | ||
if (nativeToken_ == address(0)) revert InvalidTokenSet(nativeToken_); | ||
nativeToken = nativeToken_; | ||
_activeOutbox = EMPTY_ACTIVEOUTBOX; | ||
rollup = rollup_; | ||
|
||
// store number of decimals used by native token | ||
try ERC20(nativeToken_).decimals() returns (uint8 decimals) { | ||
if (decimals > MAX_ALLOWED_NATIVE_TOKEN_DECIMALS) { | ||
revert NativeTokenDecimalsTooLarge(decimals); | ||
} | ||
nativeTokenDecimals = decimals; | ||
} catch { | ||
// decimal is not part of the ERC20 spec | ||
// assume it have 0 decimals if it does not have decimals() method | ||
// we do this to align with the token bridge behavior | ||
nativeTokenDecimals = 0; | ||
} | ||
} | ||
|
||
/// @inheritdoc IERC20Bridge | ||
function enqueueDelayedMessage( | ||
uint8 kind, | ||
address sender, | ||
bytes32 messageDataHash, | ||
uint256 tokenFeeAmount | ||
) external returns (uint256) { | ||
return _enqueueDelayedMessage(kind, sender, messageDataHash, tokenFeeAmount); | ||
} | ||
|
||
function _transferFunds(uint256 amount) internal override { | ||
// fetch native token from Inbox | ||
// IERC20(nativeToken).safeTransferFrom(msg.sender, address(this), amount); | ||
IXERC20(nativeToken).burn(msg.sender, amount); | ||
} | ||
|
||
function _executeLowLevelCall( | ||
address to, | ||
uint256 value, | ||
bytes memory data | ||
) internal override returns (bool success, bytes memory returnData) { | ||
address _nativeToken = nativeToken; | ||
|
||
// we don't allow outgoing calls to native token contract because it could | ||
// result in loss of native tokens which are escrowed by ERC20Bridge | ||
if (to == _nativeToken) { | ||
revert CallTargetNotAllowed(_nativeToken); | ||
} | ||
|
||
// first release native token | ||
// IERC20(_nativeToken).safeTransfer(to, value); | ||
IXERC20(nativeToken).mint(to, value); | ||
success = true; | ||
|
||
// if there's data do additional contract call. Make sure that call is not used to | ||
// changing native token totalSupply | ||
if (data.length > 0) { | ||
uint256 totalSupplyBefore = IERC20(_nativeToken).totalSupply(); | ||
|
||
// solhint-disable-next-line avoid-low-level-calls | ||
(success, returnData) = to.call(data); | ||
|
||
uint256 totalSupplyAfter = IERC20(_nativeToken).totalSupply(); | ||
if (totalSupplyAfter != totalSupplyBefore) { | ||
revert CallNotAllowed(); | ||
} | ||
} | ||
} | ||
|
||
function _baseFeeToReport() internal pure override returns (uint256) { | ||
// ArbOs uses formula 'l1BaseFee * (1400 + 6 * calldataLengthInBytes)' to calculate retryable ticket's | ||
// submission fee. When custom ERC20 token is used to pay for fees, submission fee shall be 0. That's | ||
// why baseFee is reported as 0 here. | ||
return 0; | ||
} | ||
} |
Check warning
Code scanning / Slither
Contracts that lock Ether Medium
Contract locking ether found:
Contract XERC20Bridge has payable functions:
- AbsBridge.acceptFundsFromOldBridge()
But does not have a function to withdraw the ether
Contract XERC20Bridge has payable functions:
- AbsBridge.acceptFundsFromOldBridge()
But does not have a function to withdraw the ether
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem: To be able to use a XERC20 token (e.g. Magic token) from the parent chain as the gas token on an Orbit chain (e.g. Treasure chain).
Solution: A possible solution for using an XERC20 as the gas token could be upgrading the ERC20Bridge for burning and minting the XERC20 token (it could also involve a Lockbox if necessary).