10grans-ng/contracts/TenGransEthToken.sol

84 lines
2.7 KiB
Solidity

// 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 gateway;
address public router;
bool private shouldRegisterGateway;
constructor() AbstractGrans() {
_mint(msg.sender, 15000 * 10 ** decimals());
}
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 {
// 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;
}
}