implementation

This commit is contained in:
User 1 2023-08-13 11:15:29 -04:00
parent 9548409ca9
commit c5f91b6305
5 changed files with 1799 additions and 136 deletions

View File

@ -0,0 +1,50 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol";
abstract contract AbstractGrans is ERC20, ERC20Burnable, Pausable, Ownable, ERC20Permit, ERC20Votes, ERC20FlashMint {
constructor() ERC20("10Grans", "GRANS") ERC20Permit("10Grans") {
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal override whenNotPaused {
super._beforeTokenTransfer(from, to, amount);
}
// The following functions are overrides required by Solidity.
function _afterTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Votes) {
super._afterTokenTransfer(from, to, amount);
}
function _mint(address to, uint256 amount) internal override(ERC20, ERC20Votes) {
super._mint(to, amount);
}
function _burn(address account, uint256 amount) internal override(ERC20, ERC20Votes) {
super._burn(account, amount);
}
function balanceOf(address account) public view virtual override(ERC20) returns (uint256) {
return ERC20.balanceOf(account);
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override(ERC20) returns (bool) {
return ERC20.transferFrom(sender, recipient, amount);
}
}

View File

@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "./TenGransAbstractToken.sol";
import "@arbitrum/token-bridge-contracts/contracts/tokenbridge/arbitrum/IArbToken.sol";
contract TenGransArbToken is AbstractGrans, IArbToken {
address public l2Gateway;
address public override l1Address;
modifier onlyGateway() {
require(msg.sender == l2Gateway, "ONLY_l2GATEWAY");
_;
}
constructor(address _l2Gateway, address _l1Address) AbstractGrans() {
l2Gateway = _l2Gateway;
l1Address = _l1Address;
}
function bridgeMint(address account, uint256 amount) external virtual override onlyGateway {
_mint(account, amount);
}
function bridgeBurn(address account, uint256 amount) external virtual override onlyGateway {
_burn(account, amount);
}
}

View File

@ -0,0 +1,83 @@
// 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;
}
}

1773
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@
"prettier-plugin-solidity": "^1.1.3" "prettier-plugin-solidity": "^1.1.3"
}, },
"dependencies": { "dependencies": {
"@arbitrum/token-bridge-contracts": "^1.0.0-beta.0",
"@openzeppelin/contracts": "^4.9.3" "@openzeppelin/contracts": "^4.9.3"
} }
} }