-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate token with arbitrum bridge
- Loading branch information
1 parent
3a3363d
commit f48a8fa
Showing
5 changed files
with
130 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
|
||
import "./HATToken.sol"; | ||
import "@arbitrum/token-bridge-contracts/contracts/tokenbridge/ethereum/ICustomToken.sol"; | ||
|
||
/** | ||
* @title Interface needed to call function registerTokenToL2 of the L1CustomGateway | ||
*/ | ||
interface IL1CustomGateway { | ||
function registerTokenToL2( | ||
address _l2Address, | ||
uint256 _maxGas, | ||
uint256 _gasPriceBid, | ||
uint256 _maxSubmissionCost, | ||
address _creditBackAddress | ||
) external payable returns (uint256); | ||
} | ||
|
||
/** | ||
* @title Interface needed to call function setGateway of the L2GatewayRouter | ||
*/ | ||
interface IL2GatewayRouter { | ||
function setGateway( | ||
address _gateway, | ||
uint256 _maxGas, | ||
uint256 _gasPriceBid, | ||
uint256 _maxSubmissionCost, | ||
address _creditBackAddress | ||
) external payable returns (uint256); | ||
} | ||
|
||
contract HATTokenArbitrumBridgeL1 is ICustomToken, HATToken { | ||
address private customGatewayAddress; | ||
address private routerAddress; | ||
bool private shouldRegisterGateway; | ||
|
||
constructor (address _customGatewayAddress, address _routerAddress, address _governance) HATToken(_governance) { | ||
customGatewayAddress = _customGatewayAddress; | ||
routerAddress = _routerAddress; | ||
} | ||
|
||
function isArbitrumEnabled() external view override returns (uint8) { | ||
require(shouldRegisterGateway, "NOT_EXPECTED_CALL"); | ||
return uint8(0xb1); | ||
} | ||
|
||
function registerTokenOnL2( | ||
address l2CustomTokenAddress, | ||
uint256 maxSubmissionCostForCustomGateway, | ||
uint256 maxSubmissionCostForRouter, | ||
uint256 maxGasForCustomGateway, | ||
uint256 maxGasForRouter, | ||
uint256 gasPriceBid, | ||
uint256 valueForGateway, | ||
uint256 valueForRouter, | ||
address creditBackAddress | ||
) public override payable onlyOwner { | ||
// we temporarily set `shouldRegisterGateway` to true for the callback in registerTokenToL2 to succeed | ||
bool prev = shouldRegisterGateway; | ||
shouldRegisterGateway = true; | ||
|
||
IL1CustomGateway(customGatewayAddress).registerTokenToL2{ value: valueForGateway }( | ||
l2CustomTokenAddress, | ||
maxGasForCustomGateway, | ||
gasPriceBid, | ||
maxSubmissionCostForCustomGateway, | ||
creditBackAddress | ||
); | ||
|
||
IL2GatewayRouter(routerAddress).setGateway{ value: valueForRouter }( | ||
customGatewayAddress, | ||
maxGasForRouter, | ||
gasPriceBid, | ||
maxSubmissionCostForRouter, | ||
creditBackAddress | ||
); | ||
|
||
shouldRegisterGateway = prev; | ||
} | ||
|
||
function transferFrom( | ||
address sender, | ||
address recipient, | ||
uint256 amount | ||
) public override(ICustomToken, ERC20) returns (bool) { | ||
return super.transferFrom(sender, recipient, amount); | ||
} | ||
|
||
function balanceOf(address account) public view override(ICustomToken, ERC20) returns (uint256) { | ||
return super.balanceOf(account); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
|
||
import "./HATToken.sol"; | ||
import "@arbitrum/token-bridge-contracts/contracts/tokenbridge/arbitrum/IArbToken.sol"; | ||
|
||
contract HATTokenArbitrumBridgeL2 is HATToken, IArbToken { | ||
address public l2Gateway; | ||
address public override l1Address; | ||
|
||
modifier onlyL2Gateway() { | ||
require(msg.sender == l2Gateway, "NOT_GATEWAY"); | ||
_; | ||
} | ||
|
||
constructor(address _l2Gateway, address _l1TokenAddress) HATToken(address(0)) { | ||
l2Gateway = _l2Gateway; | ||
l1Address = _l1TokenAddress; | ||
transferable = true; | ||
emit TransferableSet(); | ||
} | ||
|
||
/** | ||
* @notice should increase token supply by amount, and should only be callable by the L2Gateway. | ||
*/ | ||
function bridgeMint(address account, uint256 amount) external override onlyL2Gateway { | ||
_mint(account, amount); | ||
} | ||
|
||
/** | ||
* @notice should decrease token supply by amount, and should only be callable by the L2Gateway. | ||
*/ | ||
function bridgeBurn(address account, uint256 amount) external override onlyL2Gateway { | ||
_burn(account, amount); | ||
} | ||
} |