// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; import "./TenGransAbstractToken.sol"; import "@arbitrum/token-bridge-contracts/contracts/tokenbridge/ethereum/ICustomToken.sol"; interface IL1CustomGateway { function registerTokenToL2( address _l2Address, uint256 _maxGas, uint256 _gasPriceBid, uint256 _maxSubmissionCost, address _creditBackAddress ) external payable returns (uint256); } interface IGatewayRouter2 { function setGateway( address _gateway, uint256 _maxGas, uint256 _gasPriceBid, uint256 _maxSubmissionCost, address _creditBackAddress ) external payable returns (uint256); } contract TenGransEthToken is AbstractGrans, ICustomToken { address public immutable gateway; address public immutable router; bool private shouldRegisterGateway; constructor(address _gateway, address _router) AbstractGrans() { gateway = _gateway; router = _router; _mint(msg.sender, 15_000 * 10 ** 18); } function balanceOf(address account) public view virtual override(AbstractGrans, ICustomToken) returns (uint256) { return AbstractGrans.balanceOf(account); } function transferFrom(address sender, address recipient, uint256 amount) public virtual override(AbstractGrans, ICustomToken) returns (bool) { return AbstractGrans.transferFrom(sender, recipient, amount); } /// @dev we only set shouldRegisterGateway to true when in `registerTokenOnL2` function isArbitrumEnabled() external view override returns (uint8) { require(shouldRegisterGateway, "NOT_EXPECTED_CALL"); return uint8(uint16(uint32(uint64(uint128(0xa4b1))))); } function registerTokenOnL2( address l2CustomTokenAddress, uint256 maxSubmissionCostForCustomGateway, uint256 maxSubmissionCostForRouter, uint256 maxGasForCustomGateway, uint256 maxGasForRouter, uint256 gasPriceBid, uint256 valueForGateway, uint256 valueForRouter, address creditBackAddress ) public payable override onlyOwner { // we temporarily set `shouldRegisterGateway` to true for the callback in registerTokenToL2 to succeed bool prev = shouldRegisterGateway; shouldRegisterGateway = true; IL1CustomGateway(gateway).registerTokenToL2{value: valueForGateway}( l2CustomTokenAddress, maxGasForCustomGateway, gasPriceBid, maxSubmissionCostForCustomGateway, creditBackAddress ); IGatewayRouter2(router).setGateway{value: valueForRouter}( gateway, maxGasForRouter, gasPriceBid, maxSubmissionCostForRouter, creditBackAddress ); shouldRegisterGateway = prev; } }