文件 1 的 15:AdminMultisigBase.sol
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
pragma solidity >=0.8.0 <0.9.0;
contract AdminMultisigBase is EternalStorage {
bytes32 internal constant KEY_ADMIN_EPOCH = keccak256('admin-epoch');
bytes32 internal constant PREFIX_ADMIN = keccak256('admin');
bytes32 internal constant PREFIX_ADMIN_COUNT = keccak256('admin-count');
bytes32 internal constant PREFIX_ADMIN_THRESHOLD = keccak256('admin-threshold');
bytes32 internal constant PREFIX_ADMIN_VOTE_COUNTS = keccak256('admin-vote-counts');
bytes32 internal constant PREFIX_ADMIN_VOTED = keccak256('admin-voted');
bytes32 internal constant PREFIX_IS_ADMIN = keccak256('is-admin');
modifier onlyAdmin() {
uint256 adminEpoch = _adminEpoch();
require(_isAdmin(adminEpoch, msg.sender), 'NOT_ADMIN');
bytes32 topic = keccak256(msg.data);
require(!_hasVoted(adminEpoch, topic, msg.sender), 'VOTED');
_setHasVoted(adminEpoch, topic, msg.sender, true);
uint256 adminVoteCount = _getVoteCount(adminEpoch, topic) + uint256(1);
_setVoteCount(adminEpoch, topic, adminVoteCount);
if (adminVoteCount < _getAdminThreshold(adminEpoch)) return;
_;
_setVoteCount(adminEpoch, topic, uint256(0));
uint256 adminCount = _getAdminCount(adminEpoch);
for (uint256 i; i < adminCount; i++) {
_setHasVoted(adminEpoch, topic, _getAdmin(adminEpoch, i), false);
}
}
function _getAdminKey(uint256 adminEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN, adminEpoch, index));
}
function _getAdminCountKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_COUNT, adminEpoch));
}
function _getAdminThresholdKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_THRESHOLD, adminEpoch));
}
function _getAdminVoteCountsKey(uint256 adminEpoch, bytes32 topic) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTE_COUNTS, adminEpoch, topic));
}
function _getAdminVotedKey(
uint256 adminEpoch,
bytes32 topic,
address account
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTED, adminEpoch, topic, account));
}
function _getIsAdminKey(uint256 adminEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_ADMIN, adminEpoch, account));
}
function _adminEpoch() internal view returns (uint256) {
return getUint(KEY_ADMIN_EPOCH);
}
function _getAdmin(uint256 adminEpoch, uint256 index) internal view returns (address) {
return getAddress(_getAdminKey(adminEpoch, index));
}
function _getAdminCount(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminCountKey(adminEpoch));
}
function _getAdminThreshold(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminThresholdKey(adminEpoch));
}
function _getVoteCount(uint256 adminEpoch, bytes32 topic) internal view returns (uint256) {
return getUint(_getAdminVoteCountsKey(adminEpoch, topic));
}
function _hasVoted(
uint256 adminEpoch,
bytes32 topic,
address account
) internal view returns (bool) {
return getBool(_getAdminVotedKey(adminEpoch, topic, account));
}
function _isAdmin(uint256 adminEpoch, address account) internal view returns (bool) {
return getBool(_getIsAdminKey(adminEpoch, account));
}
function _setAdminEpoch(uint256 adminEpoch) internal {
_setUint(KEY_ADMIN_EPOCH, adminEpoch);
}
function _setAdmin(
uint256 adminEpoch,
uint256 index,
address account
) internal {
_setAddress(_getAdminKey(adminEpoch, index), account);
}
function _setAdminCount(uint256 adminEpoch, uint256 adminCount) internal {
_setUint(_getAdminCountKey(adminEpoch), adminCount);
}
function _setAdmins(
uint256 adminEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 adminLength = accounts.length;
require(adminLength >= threshold, 'INV_ADMINS');
require(threshold > uint256(0), 'INV_ADMIN_THLD');
_setAdminThreshold(adminEpoch, threshold);
_setAdminCount(adminEpoch, adminLength);
for (uint256 i; i < adminLength; i++) {
address account = accounts[i];
require(!_isAdmin(adminEpoch, account), 'DUP_ADMIN');
_setAdmin(adminEpoch, i, account);
_setIsAdmin(adminEpoch, account, true);
}
}
function _setAdminThreshold(uint256 adminEpoch, uint256 adminThreshold) internal {
_setUint(_getAdminThresholdKey(adminEpoch), adminThreshold);
}
function _setVoteCount(
uint256 adminEpoch,
bytes32 topic,
uint256 voteCount
) internal {
_setUint(_getAdminVoteCountsKey(adminEpoch, topic), voteCount);
}
function _setHasVoted(
uint256 adminEpoch,
bytes32 topic,
address account,
bool voted
) internal {
_setBool(_getAdminVotedKey(adminEpoch, topic, account), voted);
}
function _setIsAdmin(
uint256 adminEpoch,
address account,
bool isAdmin
) internal {
_setBool(_getIsAdminKey(adminEpoch, account), isAdmin);
}
}
文件 2 的 15:AxelarGateway.sol
interface IAxelarGateway {
event Executed(bytes32 indexed commandId);
event TokenDeployed(string symbol, address tokenAddresses);
event TokenFrozen(string indexed symbol);
event TokenUnfrozen(string indexed symbol);
event AllTokensFrozen();
event AllTokensUnfrozen();
event AccountBlacklisted(address indexed account);
event AccountWhitelisted(address indexed account);
event Upgraded(address indexed implementation);
function allTokensFrozen() external view returns (bool);
function implementation() external view returns (address);
function tokenAddresses(string memory symbol) external view returns (address);
function tokenFrozen(string memory symbol) external view returns (bool);
function isCommandExecuted(bytes32 commandId) external view returns (bool);
function freezeToken(string memory symbol) external;
function unfreezeToken(string memory symbol) external;
function freezeAllTokens() external;
function unfreezeAllTokens() external;
function upgrade(address newImplementation, bytes calldata setupParams) external;
function setup(bytes calldata params) external;
function execute(bytes calldata input) external;
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
contract ERC20 is Context, IERC20 {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
uint256 public override totalSupply;
string public name;
string public symbol;
uint8 public immutable decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), 'ZERO_ADDR');
require(recipient != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(sender, recipient, amount);
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), 'ZERO_ADDR');
require(spender != address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
abstract contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
require(owner == msg.sender, 'NOT_OWNER');
_;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Burner {
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
contract BurnableMintableCappedERC20 is ERC20, Ownable {
uint256 public cap;
bytes32 private constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 private constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
event Frozen(address indexed owner);
event Unfrozen(address indexed owner);
constructor(
string memory name,
string memory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
function depositAddress(bytes32 salt) public view returns (address) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
function mint(address account, uint256 amount) public onlyOwner {
uint256 capacity = cap;
require(capacity == 0 || totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
function burn(bytes32 salt) public onlyOwner {
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function _beforeTokenTransfer(
address,
address,
uint256
) internal view override {
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
contract AdminMultisigBase is EternalStorage {
bytes32 internal constant KEY_ADMIN_EPOCH = keccak256('admin-epoch');
bytes32 internal constant PREFIX_ADMIN = keccak256('admin');
bytes32 internal constant PREFIX_ADMIN_COUNT = keccak256('admin-count');
bytes32 internal constant PREFIX_ADMIN_THRESHOLD = keccak256('admin-threshold');
bytes32 internal constant PREFIX_ADMIN_VOTE_COUNTS = keccak256('admin-vote-counts');
bytes32 internal constant PREFIX_ADMIN_VOTED = keccak256('admin-voted');
bytes32 internal constant PREFIX_IS_ADMIN = keccak256('is-admin');
modifier onlyAdmin() {
uint256 adminEpoch = _adminEpoch();
require(_isAdmin(adminEpoch, msg.sender), 'NOT_ADMIN');
bytes32 topic = keccak256(msg.data);
require(!_hasVoted(adminEpoch, topic, msg.sender), 'VOTED');
_setHasVoted(adminEpoch, topic, msg.sender, true);
uint256 adminVoteCount = _getVoteCount(adminEpoch, topic) + uint256(1);
_setVoteCount(adminEpoch, topic, adminVoteCount);
if (adminVoteCount < _getAdminThreshold(adminEpoch)) return;
_;
_setVoteCount(adminEpoch, topic, uint256(0));
uint256 adminCount = _getAdminCount(adminEpoch);
for (uint256 i; i < adminCount; i++) {
_setHasVoted(adminEpoch, topic, _getAdmin(adminEpoch, i), false);
}
}
function _getAdminKey(uint256 adminEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN, adminEpoch, index));
}
function _getAdminCountKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_COUNT, adminEpoch));
}
function _getAdminThresholdKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_THRESHOLD, adminEpoch));
}
function _getAdminVoteCountsKey(uint256 adminEpoch, bytes32 topic) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTE_COUNTS, adminEpoch, topic));
}
function _getAdminVotedKey(
uint256 adminEpoch,
bytes32 topic,
address account
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTED, adminEpoch, topic, account));
}
function _getIsAdminKey(uint256 adminEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_ADMIN, adminEpoch, account));
}
function _adminEpoch() internal view returns (uint256) {
return getUint(KEY_ADMIN_EPOCH);
}
function _getAdmin(uint256 adminEpoch, uint256 index) internal view returns (address) {
return getAddress(_getAdminKey(adminEpoch, index));
}
function _getAdminCount(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminCountKey(adminEpoch));
}
function _getAdminThreshold(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminThresholdKey(adminEpoch));
}
function _getVoteCount(uint256 adminEpoch, bytes32 topic) internal view returns (uint256) {
return getUint(_getAdminVoteCountsKey(adminEpoch, topic));
}
function _hasVoted(
uint256 adminEpoch,
bytes32 topic,
address account
) internal view returns (bool) {
return getBool(_getAdminVotedKey(adminEpoch, topic, account));
}
function _isAdmin(uint256 adminEpoch, address account) internal view returns (bool) {
return getBool(_getIsAdminKey(adminEpoch, account));
}
function _setAdminEpoch(uint256 adminEpoch) internal {
_setUint(KEY_ADMIN_EPOCH, adminEpoch);
}
function _setAdmin(
uint256 adminEpoch,
uint256 index,
address account
) internal {
_setAddress(_getAdminKey(adminEpoch, index), account);
}
function _setAdminCount(uint256 adminEpoch, uint256 adminCount) internal {
_setUint(_getAdminCountKey(adminEpoch), adminCount);
}
function _setAdmins(
uint256 adminEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 adminLength = accounts.length;
require(adminLength >= threshold, 'INV_ADMINS');
require(threshold > uint256(0), 'INV_ADMIN_THLD');
_setAdminThreshold(adminEpoch, threshold);
_setAdminCount(adminEpoch, adminLength);
for (uint256 i; i < adminLength; i++) {
address account = accounts[i];
require(!_isAdmin(adminEpoch, account), 'DUP_ADMIN');
_setAdmin(adminEpoch, i, account);
_setIsAdmin(adminEpoch, account, true);
}
}
function _setAdminThreshold(uint256 adminEpoch, uint256 adminThreshold) internal {
_setUint(_getAdminThresholdKey(adminEpoch), adminThreshold);
}
function _setVoteCount(
uint256 adminEpoch,
bytes32 topic,
uint256 voteCount
) internal {
_setUint(_getAdminVoteCountsKey(adminEpoch, topic), voteCount);
}
function _setHasVoted(
uint256 adminEpoch,
bytes32 topic,
address account,
bool voted
) internal {
_setBool(_getAdminVotedKey(adminEpoch, topic, account), voted);
}
function _setIsAdmin(
uint256 adminEpoch,
address account,
bool isAdmin
) internal {
_setBool(_getIsAdminKey(adminEpoch, account), isAdmin);
}
}
pragma solidity >=0.8.0 <0.9.0;
abstract contract AxelarGateway is IAxelarGateway, AdminMultisigBase {
bytes32 internal constant KEY_IMPLEMENTATION =
bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
bytes32 internal constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
bytes32 internal constant PREFIX_COMMAND_EXECUTED = keccak256('command-executed');
bytes32 internal constant PREFIX_TOKEN_ADDRESS = keccak256('token-address');
bytes32 internal constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 internal constant SELECTOR_BURN_TOKEN = keccak256('burnToken');
bytes32 internal constant SELECTOR_DEPLOY_TOKEN = keccak256('deployToken');
bytes32 internal constant SELECTOR_MINT_TOKEN = keccak256('mintToken');
bytes32 internal constant SELECTOR_TRANSFER_OPERATORSHIP = keccak256('transferOperatorship');
bytes32 internal constant SELECTOR_TRANSFER_OWNERSHIP = keccak256('transferOwnership');
uint8 internal constant OLD_KEY_RETENTION = 16;
modifier onlySelf() {
require(msg.sender == address(this), 'NOT_SELF');
_;
}
function allTokensFrozen() public view override returns (bool) {
return getBool(KEY_ALL_TOKENS_FROZEN);
}
function implementation() public view override returns (address) {
return getAddress(KEY_IMPLEMENTATION);
}
function tokenAddresses(string memory symbol) public view override returns (address) {
return getAddress(_getTokenAddressKey(symbol));
}
function tokenFrozen(string memory symbol) public view override returns (bool) {
return getBool(_getFreezeTokenKey(symbol));
}
function isCommandExecuted(bytes32 commandId) public view override returns (bool) {
return getBool(_getIsCommandExecutedKey(commandId));
}
function freezeToken(string memory symbol) external override onlyAdmin {
_setBool(_getFreezeTokenKey(symbol), true);
emit TokenFrozen(symbol);
}
function unfreezeToken(string memory symbol) external override onlyAdmin {
_setBool(_getFreezeTokenKey(symbol), false);
emit TokenUnfrozen(symbol);
}
function freezeAllTokens() external override onlyAdmin {
_setBool(KEY_ALL_TOKENS_FROZEN, true);
emit AllTokensFrozen();
}
function unfreezeAllTokens() external override onlyAdmin {
_setBool(KEY_ALL_TOKENS_FROZEN, false);
emit AllTokensUnfrozen();
}
function upgrade(address newImplementation, bytes calldata setupParams) external override onlyAdmin {
emit Upgraded(newImplementation);
(bool success, ) = newImplementation.delegatecall(
abi.encodeWithSelector(IAxelarGateway.setup.selector, setupParams)
);
require(success, 'SETUP_FAILED');
_setImplementation(newImplementation);
}
function _deployToken(
string memory name,
string memory symbol,
uint8 decimals,
uint256 cap
) internal {
require(tokenAddresses(symbol) == address(0), 'TOKEN_EXIST');
bytes32 salt = keccak256(abi.encodePacked(symbol));
address token = address(new BurnableMintableCappedERC20{ salt: salt }(name, symbol, decimals, cap));
_setTokenAddress(symbol, token);
emit TokenDeployed(symbol, token);
}
function _mintToken(
string memory symbol,
address account,
uint256 amount
) internal {
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress != address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).mint(account, amount);
}
function _burnToken(string memory symbol, bytes32 salt) internal {
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress != address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).burn(salt);
}
function _getFreezeTokenKey(string memory symbol) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol));
}
function _getTokenAddressKey(string memory symbol) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_TOKEN_ADDRESS, symbol));
}
function _getIsCommandExecutedKey(bytes32 commandId) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_COMMAND_EXECUTED, commandId));
}
function _getChainID() internal view returns (uint256 id) {
assembly {
id := chainid()
}
}
function _setTokenAddress(string memory symbol, address tokenAddr) internal {
_setAddress(_getTokenAddressKey(symbol), tokenAddr);
}
function _setCommandExecuted(bytes32 commandId, bool executed) internal {
_setBool(_getIsCommandExecutedKey(commandId), executed);
}
function _setImplementation(address newImplementation) internal {
_setAddress(KEY_IMPLEMENTATION, newImplementation);
}
}
文件 3 的 15:AxelarGatewayMultisig.sol
interface IAxelarGateway {
event Executed(bytes32 indexed commandId);
event TokenDeployed(string symbol, address tokenAddresses);
event TokenFrozen(string indexed symbol);
event TokenUnfrozen(string indexed symbol);
event AllTokensFrozen();
event AllTokensUnfrozen();
event AccountBlacklisted(address indexed account);
event AccountWhitelisted(address indexed account);
event Upgraded(address indexed implementation);
function allTokensFrozen() external view returns (bool);
function implementation() external view returns (address);
function tokenAddresses(string memory symbol) external view returns (address);
function tokenFrozen(string memory symbol) external view returns (bool);
function isCommandExecuted(bytes32 commandId) external view returns (bool);
function freezeToken(string memory symbol) external;
function unfreezeToken(string memory symbol) external;
function freezeAllTokens() external;
function unfreezeAllTokens() external;
function upgrade(address newImplementation, bytes calldata setupParams) external;
function setup(bytes calldata params) external;
function execute(bytes calldata input) external;
}
interface IAxelarGatewayMultisig is IAxelarGateway {
event OwnershipTransferred(address[] preOwners, uint256 prevThreshold, address[] newOwners, uint256 newThreshold);
event OperatorshipTransferred(address[] preOperators, uint256 prevThreshold, address[] newOperators, uint256 newThreshold);
function owners() external view returns (address[] memory);
function operators() external view returns (address[] memory);
}
library ECDSA {
function recover(bytes32 hash, bytes memory signature) internal pure returns (address signer) {
require(signature.length == 65, 'INV_LEN');
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, 'INV_S');
require(v == 27 || v == 28, 'INV_V');
require((signer = ecrecover(hash, v, r, s)) != address(0), 'INV_SIG');
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked('\x19Ethereum Signed Message:\n32', hash));
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
contract ERC20 is Context, IERC20 {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
uint256 public override totalSupply;
string public name;
string public symbol;
uint8 public immutable decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), 'ZERO_ADDR');
require(recipient != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(sender, recipient, amount);
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), 'ZERO_ADDR');
require(spender != address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
abstract contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
require(owner == msg.sender, 'NOT_OWNER');
_;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Burner {
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
contract BurnableMintableCappedERC20 is ERC20, Ownable {
uint256 public cap;
bytes32 private constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 private constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
event Frozen(address indexed owner);
event Unfrozen(address indexed owner);
constructor(
string memory name,
string memory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
function depositAddress(bytes32 salt) public view returns (address) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
function mint(address account, uint256 amount) public onlyOwner {
uint256 capacity = cap;
require(capacity == 0 || totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
function burn(bytes32 salt) public onlyOwner {
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function _beforeTokenTransfer(
address,
address,
uint256
) internal view override {
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
contract AdminMultisigBase is EternalStorage {
bytes32 internal constant KEY_ADMIN_EPOCH = keccak256('admin-epoch');
bytes32 internal constant PREFIX_ADMIN = keccak256('admin');
bytes32 internal constant PREFIX_ADMIN_COUNT = keccak256('admin-count');
bytes32 internal constant PREFIX_ADMIN_THRESHOLD = keccak256('admin-threshold');
bytes32 internal constant PREFIX_ADMIN_VOTE_COUNTS = keccak256('admin-vote-counts');
bytes32 internal constant PREFIX_ADMIN_VOTED = keccak256('admin-voted');
bytes32 internal constant PREFIX_IS_ADMIN = keccak256('is-admin');
modifier onlyAdmin() {
uint256 adminEpoch = _adminEpoch();
require(_isAdmin(adminEpoch, msg.sender), 'NOT_ADMIN');
bytes32 topic = keccak256(msg.data);
require(!_hasVoted(adminEpoch, topic, msg.sender), 'VOTED');
_setHasVoted(adminEpoch, topic, msg.sender, true);
uint256 adminVoteCount = _getVoteCount(adminEpoch, topic) + uint256(1);
_setVoteCount(adminEpoch, topic, adminVoteCount);
if (adminVoteCount < _getAdminThreshold(adminEpoch)) return;
_;
_setVoteCount(adminEpoch, topic, uint256(0));
uint256 adminCount = _getAdminCount(adminEpoch);
for (uint256 i; i < adminCount; i++) {
_setHasVoted(adminEpoch, topic, _getAdmin(adminEpoch, i), false);
}
}
function _getAdminKey(uint256 adminEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN, adminEpoch, index));
}
function _getAdminCountKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_COUNT, adminEpoch));
}
function _getAdminThresholdKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_THRESHOLD, adminEpoch));
}
function _getAdminVoteCountsKey(uint256 adminEpoch, bytes32 topic) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTE_COUNTS, adminEpoch, topic));
}
function _getAdminVotedKey(
uint256 adminEpoch,
bytes32 topic,
address account
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTED, adminEpoch, topic, account));
}
function _getIsAdminKey(uint256 adminEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_ADMIN, adminEpoch, account));
}
function _adminEpoch() internal view returns (uint256) {
return getUint(KEY_ADMIN_EPOCH);
}
function _getAdmin(uint256 adminEpoch, uint256 index) internal view returns (address) {
return getAddress(_getAdminKey(adminEpoch, index));
}
function _getAdminCount(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminCountKey(adminEpoch));
}
function _getAdminThreshold(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminThresholdKey(adminEpoch));
}
function _getVoteCount(uint256 adminEpoch, bytes32 topic) internal view returns (uint256) {
return getUint(_getAdminVoteCountsKey(adminEpoch, topic));
}
function _hasVoted(
uint256 adminEpoch,
bytes32 topic,
address account
) internal view returns (bool) {
return getBool(_getAdminVotedKey(adminEpoch, topic, account));
}
function _isAdmin(uint256 adminEpoch, address account) internal view returns (bool) {
return getBool(_getIsAdminKey(adminEpoch, account));
}
function _setAdminEpoch(uint256 adminEpoch) internal {
_setUint(KEY_ADMIN_EPOCH, adminEpoch);
}
function _setAdmin(
uint256 adminEpoch,
uint256 index,
address account
) internal {
_setAddress(_getAdminKey(adminEpoch, index), account);
}
function _setAdminCount(uint256 adminEpoch, uint256 adminCount) internal {
_setUint(_getAdminCountKey(adminEpoch), adminCount);
}
function _setAdmins(
uint256 adminEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 adminLength = accounts.length;
require(adminLength >= threshold, 'INV_ADMINS');
require(threshold > uint256(0), 'INV_ADMIN_THLD');
_setAdminThreshold(adminEpoch, threshold);
_setAdminCount(adminEpoch, adminLength);
for (uint256 i; i < adminLength; i++) {
address account = accounts[i];
require(!_isAdmin(adminEpoch, account), 'DUP_ADMIN');
_setAdmin(adminEpoch, i, account);
_setIsAdmin(adminEpoch, account, true);
}
}
function _setAdminThreshold(uint256 adminEpoch, uint256 adminThreshold) internal {
_setUint(_getAdminThresholdKey(adminEpoch), adminThreshold);
}
function _setVoteCount(
uint256 adminEpoch,
bytes32 topic,
uint256 voteCount
) internal {
_setUint(_getAdminVoteCountsKey(adminEpoch, topic), voteCount);
}
function _setHasVoted(
uint256 adminEpoch,
bytes32 topic,
address account,
bool voted
) internal {
_setBool(_getAdminVotedKey(adminEpoch, topic, account), voted);
}
function _setIsAdmin(
uint256 adminEpoch,
address account,
bool isAdmin
) internal {
_setBool(_getIsAdminKey(adminEpoch, account), isAdmin);
}
}
abstract contract AxelarGateway is IAxelarGateway, AdminMultisigBase {
bytes32 internal constant KEY_IMPLEMENTATION =
bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
bytes32 internal constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
bytes32 internal constant PREFIX_COMMAND_EXECUTED = keccak256('command-executed');
bytes32 internal constant PREFIX_TOKEN_ADDRESS = keccak256('token-address');
bytes32 internal constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 internal constant SELECTOR_BURN_TOKEN = keccak256('burnToken');
bytes32 internal constant SELECTOR_DEPLOY_TOKEN = keccak256('deployToken');
bytes32 internal constant SELECTOR_MINT_TOKEN = keccak256('mintToken');
bytes32 internal constant SELECTOR_TRANSFER_OPERATORSHIP = keccak256('transferOperatorship');
bytes32 internal constant SELECTOR_TRANSFER_OWNERSHIP = keccak256('transferOwnership');
uint8 internal constant OLD_KEY_RETENTION = 16;
modifier onlySelf() {
require(msg.sender == address(this), 'NOT_SELF');
_;
}
function allTokensFrozen() public view override returns (bool) {
return getBool(KEY_ALL_TOKENS_FROZEN);
}
function implementation() public view override returns (address) {
return getAddress(KEY_IMPLEMENTATION);
}
function tokenAddresses(string memory symbol) public view override returns (address) {
return getAddress(_getTokenAddressKey(symbol));
}
function tokenFrozen(string memory symbol) public view override returns (bool) {
return getBool(_getFreezeTokenKey(symbol));
}
function isCommandExecuted(bytes32 commandId) public view override returns (bool) {
return getBool(_getIsCommandExecutedKey(commandId));
}
function freezeToken(string memory symbol) external override onlyAdmin {
_setBool(_getFreezeTokenKey(symbol), true);
emit TokenFrozen(symbol);
}
function unfreezeToken(string memory symbol) external override onlyAdmin {
_setBool(_getFreezeTokenKey(symbol), false);
emit TokenUnfrozen(symbol);
}
function freezeAllTokens() external override onlyAdmin {
_setBool(KEY_ALL_TOKENS_FROZEN, true);
emit AllTokensFrozen();
}
function unfreezeAllTokens() external override onlyAdmin {
_setBool(KEY_ALL_TOKENS_FROZEN, false);
emit AllTokensUnfrozen();
}
function upgrade(address newImplementation, bytes calldata setupParams) external override onlyAdmin {
emit Upgraded(newImplementation);
(bool success, ) = newImplementation.delegatecall(
abi.encodeWithSelector(IAxelarGateway.setup.selector, setupParams)
);
require(success, 'SETUP_FAILED');
_setImplementation(newImplementation);
}
function _deployToken(
string memory name,
string memory symbol,
uint8 decimals,
uint256 cap
) internal {
require(tokenAddresses(symbol) == address(0), 'TOKEN_EXIST');
bytes32 salt = keccak256(abi.encodePacked(symbol));
address token = address(new BurnableMintableCappedERC20{ salt: salt }(name, symbol, decimals, cap));
_setTokenAddress(symbol, token);
emit TokenDeployed(symbol, token);
}
function _mintToken(
string memory symbol,
address account,
uint256 amount
) internal {
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress != address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).mint(account, amount);
}
function _burnToken(string memory symbol, bytes32 salt) internal {
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress != address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).burn(salt);
}
function _getFreezeTokenKey(string memory symbol) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol));
}
function _getTokenAddressKey(string memory symbol) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_TOKEN_ADDRESS, symbol));
}
function _getIsCommandExecutedKey(bytes32 commandId) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_COMMAND_EXECUTED, commandId));
}
function _getChainID() internal view returns (uint256 id) {
assembly {
id := chainid()
}
}
function _setTokenAddress(string memory symbol, address tokenAddr) internal {
_setAddress(_getTokenAddressKey(symbol), tokenAddr);
}
function _setCommandExecuted(bytes32 commandId, bool executed) internal {
_setBool(_getIsCommandExecutedKey(commandId), executed);
}
function _setImplementation(address newImplementation) internal {
_setAddress(KEY_IMPLEMENTATION, newImplementation);
}
}
pragma solidity >=0.8.0 <0.9.0;
contract AxelarGatewayMultisig is IAxelarGatewayMultisig, AxelarGateway {
bytes32 internal constant KEY_OWNER_EPOCH = keccak256('owner-epoch');
bytes32 internal constant PREFIX_OWNER = keccak256('owner');
bytes32 internal constant PREFIX_OWNER_COUNT = keccak256('owner-count');
bytes32 internal constant PREFIX_OWNER_THRESHOLD = keccak256('owner-threshold');
bytes32 internal constant PREFIX_IS_OWNER = keccak256('is-owner');
bytes32 internal constant KEY_OPERATOR_EPOCH = keccak256('operator-epoch');
bytes32 internal constant PREFIX_OPERATOR = keccak256('operator');
bytes32 internal constant PREFIX_OPERATOR_COUNT = keccak256('operator-count');
bytes32 internal constant PREFIX_OPERATOR_THRESHOLD = keccak256('operator-threshold');
bytes32 internal constant PREFIX_IS_OPERATOR = keccak256('is-operator');
function _containsDuplicates(address[] memory accounts) internal pure returns (bool) {
uint256 count = accounts.length;
for (uint256 i; i < count; ++i) {
for (uint256 j = i + 1; j < count; ++j) {
if (accounts[i] == accounts[j]) return true;
}
}
return false;
}
function _getOwnerKey(uint256 ownerEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OWNER, ownerEpoch, index));
}
function _getOwnerCountKey(uint256 ownerEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OWNER_COUNT, ownerEpoch));
}
function _getOwnerThresholdKey(uint256 ownerEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OWNER_THRESHOLD, ownerEpoch));
}
function _getIsOwnerKey(uint256 ownerEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_OWNER, ownerEpoch, account));
}
function _ownerEpoch() internal view returns (uint256) {
return getUint(KEY_OWNER_EPOCH);
}
function _getOwner(uint256 ownerEpoch, uint256 index) internal view returns (address) {
return getAddress(_getOwnerKey(ownerEpoch, index));
}
function _getOwnerCount(uint256 ownerEpoch) internal view returns (uint256) {
return getUint(_getOwnerCountKey(ownerEpoch));
}
function _getOwnerThreshold(uint256 ownerEpoch) internal view returns (uint256) {
return getUint(_getOwnerThresholdKey(ownerEpoch));
}
function _isOwner(uint256 ownerEpoch, address account) internal view returns (bool) {
return getBool(_getIsOwnerKey(ownerEpoch, account));
}
function _areValidRecentOwners(address[] memory accounts) internal view returns (bool) {
uint256 ownerEpoch = _ownerEpoch();
uint256 recentEpochs = OLD_KEY_RETENTION + uint256(1);
uint256 lowerBoundOwnerEpoch = ownerEpoch > recentEpochs ? ownerEpoch - recentEpochs : uint256(0);
while (ownerEpoch > lowerBoundOwnerEpoch) {
if (_areValidOwnersInEpoch(ownerEpoch--, accounts)) return true;
}
return false;
}
function _areValidOwnersInEpoch(uint256 ownerEpoch, address[] memory accounts) internal view returns (bool) {
if (_containsDuplicates(accounts)) return false;
uint256 threshold = _getOwnerThreshold(ownerEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOwner(ownerEpoch, accounts[i]) && ++validSignerCount >= threshold) return true;
}
return false;
}
function owners() public view override returns (address[] memory results) {
uint256 ownerEpoch = _ownerEpoch();
uint256 ownerCount = _getOwnerCount(ownerEpoch);
results = new address[](ownerCount);
for (uint256 i; i < ownerCount; i++) {
results[i] = _getOwner(ownerEpoch, i);
}
}
function _setOwnerEpoch(uint256 ownerEpoch) internal {
_setUint(KEY_OWNER_EPOCH, ownerEpoch);
}
function _setOwner(
uint256 ownerEpoch,
uint256 index,
address account
) internal {
require(account != address(0), 'ZERO_ADDR');
_setAddress(_getOwnerKey(ownerEpoch, index), account);
}
function _setOwnerCount(uint256 ownerEpoch, uint256 ownerCount) internal {
_setUint(_getOwnerCountKey(ownerEpoch), ownerCount);
}
function _setOwners(
uint256 ownerEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 accountLength = accounts.length;
require(accountLength >= threshold, 'INV_OWNERS');
require(threshold > uint256(0), 'INV_OWNER_THLD');
_setOwnerThreshold(ownerEpoch, threshold);
_setOwnerCount(ownerEpoch, accountLength);
for (uint256 i; i < accountLength; i++) {
address account = accounts[i];
require(!_isOwner(ownerEpoch, account), 'DUP_OWNER');
_setOwner(ownerEpoch, i, account);
_setIsOwner(ownerEpoch, account, true);
}
}
function _setOwnerThreshold(uint256 ownerEpoch, uint256 ownerThreshold) internal {
_setUint(_getOwnerThresholdKey(ownerEpoch), ownerThreshold);
}
function _setIsOwner(
uint256 ownerEpoch,
address account,
bool isOwner
) internal {
_setBool(_getIsOwnerKey(ownerEpoch, account), isOwner);
}
function _getOperatorKey(uint256 operatorEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OPERATOR, operatorEpoch, index));
}
function _getOperatorCountKey(uint256 operatorEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OPERATOR_COUNT, operatorEpoch));
}
function _getOperatorThresholdKey(uint256 operatorEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OPERATOR_THRESHOLD, operatorEpoch));
}
function _getIsOperatorKey(uint256 operatorEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_OPERATOR, operatorEpoch, account));
}
function _operatorEpoch() internal view returns (uint256) {
return getUint(KEY_OPERATOR_EPOCH);
}
function _getOperator(uint256 operatorEpoch, uint256 index) internal view returns (address) {
return getAddress(_getOperatorKey(operatorEpoch, index));
}
function _getOperatorCount(uint256 operatorEpoch) internal view returns (uint256) {
return getUint(_getOperatorCountKey(operatorEpoch));
}
function _getOperatorThreshold(uint256 operatorEpoch) internal view returns (uint256) {
return getUint(_getOperatorThresholdKey(operatorEpoch));
}
function _isOperator(uint256 operatorEpoch, address account) internal view returns (bool) {
return getBool(_getIsOperatorKey(operatorEpoch, account));
}
function _areValidRecentOperators(address[] memory accounts) internal view returns (bool) {
uint256 operatorEpoch = _operatorEpoch();
uint256 recentEpochs = OLD_KEY_RETENTION + uint256(1);
uint256 lowerBoundOperatorEpoch = operatorEpoch > recentEpochs ? operatorEpoch - recentEpochs : uint256(0);
while (operatorEpoch > lowerBoundOperatorEpoch) {
if (_areValidOperatorsInEpoch(operatorEpoch--, accounts)) return true;
}
return false;
}
function _areValidOperatorsInEpoch(uint256 operatorEpoch, address[] memory accounts) internal view returns (bool) {
if (_containsDuplicates(accounts)) return false;
uint256 threshold = _getOperatorThreshold(operatorEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOperator(operatorEpoch, accounts[i]) && ++validSignerCount >= threshold) return true;
}
return false;
}
function operators() public view override returns (address[] memory results) {
uint256 operatorEpoch = _operatorEpoch();
uint256 operatorCount = _getOperatorCount(operatorEpoch);
results = new address[](operatorCount);
for (uint256 i; i < operatorCount; i++) {
results[i] = _getOperator(operatorEpoch, i);
}
}
function _setOperatorEpoch(uint256 operatorEpoch) internal {
_setUint(KEY_OPERATOR_EPOCH, operatorEpoch);
}
function _setOperator(
uint256 operatorEpoch,
uint256 index,
address account
) internal {
_setAddress(_getOperatorKey(operatorEpoch, index), account);
}
function _setOperatorCount(uint256 operatorEpoch, uint256 operatorCount) internal {
_setUint(_getOperatorCountKey(operatorEpoch), operatorCount);
}
function _setOperators(
uint256 operatorEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 accountLength = accounts.length;
require(accountLength >= threshold, 'INV_OPERATORS');
require(threshold > uint256(0), 'INV_OPERATOR_THLD');
_setOperatorThreshold(operatorEpoch, threshold);
_setOperatorCount(operatorEpoch, accountLength);
for (uint256 i; i < accountLength; i++) {
address account = accounts[i];
require(!_isOperator(operatorEpoch, account), 'DUP_OPERATOR');
_setOperator(operatorEpoch, i, account);
_setIsOperator(operatorEpoch, account, true);
}
}
function _setOperatorThreshold(uint256 operatorEpoch, uint256 operatorThreshold) internal {
_setUint(_getOperatorThresholdKey(operatorEpoch), operatorThreshold);
}
function _setIsOperator(
uint256 operatorEpoch,
address account,
bool isOperator
) internal {
_setBool(_getIsOperatorKey(operatorEpoch, account), isOperator);
}
function deployToken(bytes calldata params) external onlySelf {
(string memory name, string memory symbol, uint8 decimals, uint256 cap) = abi.decode(
params,
(string, string, uint8, uint256)
);
_deployToken(name, symbol, decimals, cap);
}
function mintToken(bytes calldata params) external onlySelf {
(string memory symbol, address account, uint256 amount) = abi.decode(params, (string, address, uint256));
_mintToken(symbol, account, amount);
}
function burnToken(bytes calldata params) external onlySelf {
(string memory symbol, bytes32 salt) = abi.decode(params, (string, bytes32));
_burnToken(symbol, salt);
}
function transferOwnership(bytes calldata params) external onlySelf {
(address[] memory newOwners, uint256 newThreshold) = abi.decode(params, (address[], uint256));
uint256 ownerEpoch = _ownerEpoch();
emit OwnershipTransferred(owners(), _getOwnerThreshold(ownerEpoch), newOwners, newThreshold);
_setOwnerEpoch(++ownerEpoch);
_setOwners(ownerEpoch, newOwners, newThreshold);
}
function transferOperatorship(bytes calldata params) external onlySelf {
(address[] memory newOperators, uint256 newThreshold) = abi.decode(params, (address[], uint256));
uint256 ownerEpoch = _ownerEpoch();
emit OperatorshipTransferred(operators(), _getOperatorThreshold(ownerEpoch), newOperators, newThreshold);
uint256 operatorEpoch = _operatorEpoch();
_setOperatorEpoch(++operatorEpoch);
_setOperators(operatorEpoch, newOperators, newThreshold);
}
function setup(bytes calldata params) external override {
require(implementation() != address(0), 'NOT_PROXY');
(
address[] memory adminAddresses,
uint256 adminThreshold,
address[] memory ownerAddresses,
uint256 ownerThreshold,
address[] memory operatorAddresses,
uint256 operatorThreshold
) = abi.decode(params, (address[], uint256, address[], uint256, address[], uint256));
uint256 adminEpoch = _adminEpoch() + uint256(1);
_setAdminEpoch(adminEpoch);
_setAdmins(adminEpoch, adminAddresses, adminThreshold);
uint256 ownerEpoch = _ownerEpoch() + uint256(1);
_setOwnerEpoch(ownerEpoch);
_setOwners(ownerEpoch, ownerAddresses, ownerThreshold);
uint256 operatorEpoch = _operatorEpoch() + uint256(1);
_setOperatorEpoch(operatorEpoch);
_setOperators(operatorEpoch, operatorAddresses, operatorThreshold);
emit OwnershipTransferred(new address[](uint256(0)), uint256(0), ownerAddresses, ownerThreshold);
emit OperatorshipTransferred(new address[](uint256(0)), uint256(0), operatorAddresses, operatorThreshold);
}
function execute(bytes calldata input) external override {
(bytes memory data, bytes[] memory signatures) = abi.decode(input, (bytes, bytes[]));
_execute(data, signatures);
}
function _execute(bytes memory data, bytes[] memory signatures) internal {
uint256 signatureCount = signatures.length;
address[] memory signers = new address[](signatureCount);
for (uint256 i; i < signatureCount; i++) {
signers[i] = ECDSA.recover(ECDSA.toEthSignedMessageHash(keccak256(data)), signatures[i]);
}
(uint256 chainId, bytes32[] memory commandIds, string[] memory commands, bytes[] memory params) = abi.decode(
data,
(uint256, bytes32[], string[], bytes[])
);
require(chainId == _getChainID(), 'INV_CHAIN');
uint256 commandsLength = commandIds.length;
require(commandsLength == commands.length && commandsLength == params.length, 'INV_CMDS');
bool areValidCurrentOwners = _areValidOwnersInEpoch(_ownerEpoch(), signers);
bool areValidRecentOwners = areValidCurrentOwners || _areValidRecentOwners(signers);
bool areValidRecentOperators = _areValidRecentOperators(signers);
for (uint256 i; i < commandsLength; i++) {
bytes32 commandId = commandIds[i];
if (isCommandExecuted(commandId)) continue;
bytes4 commandSelector;
bytes32 commandHash = keccak256(abi.encodePacked(commands[i]));
if (commandHash == SELECTOR_DEPLOY_TOKEN) {
if (!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.deployToken.selector;
} else if (commandHash == SELECTOR_MINT_TOKEN) {
if (!areValidRecentOperators && !areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.mintToken.selector;
} else if (commandHash == SELECTOR_BURN_TOKEN) {
if (!areValidRecentOperators && !areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.burnToken.selector;
} else if (commandHash == SELECTOR_TRANSFER_OWNERSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOwnership.selector;
} else if (commandHash == SELECTOR_TRANSFER_OPERATORSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOperatorship.selector;
} else {
continue;
}
_setCommandExecuted(commandId, true);
(bool success, ) = address(this).call(abi.encodeWithSelector(commandSelector, params[i]));
_setCommandExecuted(commandId, success);
if (success) {
emit Executed(commandId);
}
}
}
}
文件 4 的 15:AxelarGatewayProxy.sol
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
pragma solidity >=0.8.0 <0.9.0;
contract AxelarGatewayProxy is EternalStorage {
bytes32 internal constant KEY_IMPLEMENTATION =
bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
fallback() external payable {
address implementation = getAddress(KEY_IMPLEMENTATION);
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable {
revert('NO_ETHER');
}
}
文件 5 的 15:AxelarGatewayProxyMultisig.sol
interface IAxelarGateway {
event Executed(bytes32 indexed commandId);
event TokenDeployed(string symbol, address tokenAddresses);
event TokenFrozen(string indexed symbol);
event TokenUnfrozen(string indexed symbol);
event AllTokensFrozen();
event AllTokensUnfrozen();
event AccountBlacklisted(address indexed account);
event AccountWhitelisted(address indexed account);
event Upgraded(address indexed implementation);
function allTokensFrozen() external view returns (bool);
function implementation() external view returns (address);
function tokenAddresses(string memory symbol) external view returns (address);
function tokenFrozen(string memory symbol) external view returns (bool);
function isCommandExecuted(bytes32 commandId) external view returns (bool);
function freezeToken(string memory symbol) external;
function unfreezeToken(string memory symbol) external;
function freezeAllTokens() external;
function unfreezeAllTokens() external;
function upgrade(address newImplementation, bytes calldata setupParams) external;
function setup(bytes calldata params) external;
function execute(bytes calldata input) external;
}
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
contract AxelarGatewayProxy is EternalStorage {
bytes32 internal constant KEY_IMPLEMENTATION =
bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
fallback() external payable {
address implementation = getAddress(KEY_IMPLEMENTATION);
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable {
revert('NO_ETHER');
}
}
interface IAxelarGatewayMultisig is IAxelarGateway {
event OwnershipTransferred(address[] preOwners, uint256 prevThreshold, address[] newOwners, uint256 newThreshold);
event OperatorshipTransferred(address[] preOperators, uint256 prevThreshold, address[] newOperators, uint256 newThreshold);
function owners() external view returns (address[] memory);
function operators() external view returns (address[] memory);
}
library ECDSA {
function recover(bytes32 hash, bytes memory signature) internal pure returns (address signer) {
require(signature.length == 65, 'INV_LEN');
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, 'INV_S');
require(v == 27 || v == 28, 'INV_V');
require((signer = ecrecover(hash, v, r, s)) != address(0), 'INV_SIG');
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked('\x19Ethereum Signed Message:\n32', hash));
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
contract ERC20 is Context, IERC20 {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
uint256 public override totalSupply;
string public name;
string public symbol;
uint8 public immutable decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), 'ZERO_ADDR');
require(recipient != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(sender, recipient, amount);
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), 'ZERO_ADDR');
require(spender != address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
abstract contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
require(owner == msg.sender, 'NOT_OWNER');
_;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Burner {
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
contract BurnableMintableCappedERC20 is ERC20, Ownable {
uint256 public cap;
bytes32 private constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 private constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
event Frozen(address indexed owner);
event Unfrozen(address indexed owner);
constructor(
string memory name,
string memory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
function depositAddress(bytes32 salt) public view returns (address) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
function mint(address account, uint256 amount) public onlyOwner {
uint256 capacity = cap;
require(capacity == 0 || totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
function burn(bytes32 salt) public onlyOwner {
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function _beforeTokenTransfer(
address,
address,
uint256
) internal view override {
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
contract AdminMultisigBase is EternalStorage {
bytes32 internal constant KEY_ADMIN_EPOCH = keccak256('admin-epoch');
bytes32 internal constant PREFIX_ADMIN = keccak256('admin');
bytes32 internal constant PREFIX_ADMIN_COUNT = keccak256('admin-count');
bytes32 internal constant PREFIX_ADMIN_THRESHOLD = keccak256('admin-threshold');
bytes32 internal constant PREFIX_ADMIN_VOTE_COUNTS = keccak256('admin-vote-counts');
bytes32 internal constant PREFIX_ADMIN_VOTED = keccak256('admin-voted');
bytes32 internal constant PREFIX_IS_ADMIN = keccak256('is-admin');
modifier onlyAdmin() {
uint256 adminEpoch = _adminEpoch();
require(_isAdmin(adminEpoch, msg.sender), 'NOT_ADMIN');
bytes32 topic = keccak256(msg.data);
require(!_hasVoted(adminEpoch, topic, msg.sender), 'VOTED');
_setHasVoted(adminEpoch, topic, msg.sender, true);
uint256 adminVoteCount = _getVoteCount(adminEpoch, topic) + uint256(1);
_setVoteCount(adminEpoch, topic, adminVoteCount);
if (adminVoteCount < _getAdminThreshold(adminEpoch)) return;
_;
_setVoteCount(adminEpoch, topic, uint256(0));
uint256 adminCount = _getAdminCount(adminEpoch);
for (uint256 i; i < adminCount; i++) {
_setHasVoted(adminEpoch, topic, _getAdmin(adminEpoch, i), false);
}
}
function _getAdminKey(uint256 adminEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN, adminEpoch, index));
}
function _getAdminCountKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_COUNT, adminEpoch));
}
function _getAdminThresholdKey(uint256 adminEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_THRESHOLD, adminEpoch));
}
function _getAdminVoteCountsKey(uint256 adminEpoch, bytes32 topic) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTE_COUNTS, adminEpoch, topic));
}
function _getAdminVotedKey(
uint256 adminEpoch,
bytes32 topic,
address account
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_ADMIN_VOTED, adminEpoch, topic, account));
}
function _getIsAdminKey(uint256 adminEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_ADMIN, adminEpoch, account));
}
function _adminEpoch() internal view returns (uint256) {
return getUint(KEY_ADMIN_EPOCH);
}
function _getAdmin(uint256 adminEpoch, uint256 index) internal view returns (address) {
return getAddress(_getAdminKey(adminEpoch, index));
}
function _getAdminCount(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminCountKey(adminEpoch));
}
function _getAdminThreshold(uint256 adminEpoch) internal view returns (uint256) {
return getUint(_getAdminThresholdKey(adminEpoch));
}
function _getVoteCount(uint256 adminEpoch, bytes32 topic) internal view returns (uint256) {
return getUint(_getAdminVoteCountsKey(adminEpoch, topic));
}
function _hasVoted(
uint256 adminEpoch,
bytes32 topic,
address account
) internal view returns (bool) {
return getBool(_getAdminVotedKey(adminEpoch, topic, account));
}
function _isAdmin(uint256 adminEpoch, address account) internal view returns (bool) {
return getBool(_getIsAdminKey(adminEpoch, account));
}
function _setAdminEpoch(uint256 adminEpoch) internal {
_setUint(KEY_ADMIN_EPOCH, adminEpoch);
}
function _setAdmin(
uint256 adminEpoch,
uint256 index,
address account
) internal {
_setAddress(_getAdminKey(adminEpoch, index), account);
}
function _setAdminCount(uint256 adminEpoch, uint256 adminCount) internal {
_setUint(_getAdminCountKey(adminEpoch), adminCount);
}
function _setAdmins(
uint256 adminEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 adminLength = accounts.length;
require(adminLength >= threshold, 'INV_ADMINS');
require(threshold > uint256(0), 'INV_ADMIN_THLD');
_setAdminThreshold(adminEpoch, threshold);
_setAdminCount(adminEpoch, adminLength);
for (uint256 i; i < adminLength; i++) {
address account = accounts[i];
require(!_isAdmin(adminEpoch, account), 'DUP_ADMIN');
_setAdmin(adminEpoch, i, account);
_setIsAdmin(adminEpoch, account, true);
}
}
function _setAdminThreshold(uint256 adminEpoch, uint256 adminThreshold) internal {
_setUint(_getAdminThresholdKey(adminEpoch), adminThreshold);
}
function _setVoteCount(
uint256 adminEpoch,
bytes32 topic,
uint256 voteCount
) internal {
_setUint(_getAdminVoteCountsKey(adminEpoch, topic), voteCount);
}
function _setHasVoted(
uint256 adminEpoch,
bytes32 topic,
address account,
bool voted
) internal {
_setBool(_getAdminVotedKey(adminEpoch, topic, account), voted);
}
function _setIsAdmin(
uint256 adminEpoch,
address account,
bool isAdmin
) internal {
_setBool(_getIsAdminKey(adminEpoch, account), isAdmin);
}
}
abstract contract AxelarGateway is IAxelarGateway, AdminMultisigBase {
bytes32 internal constant KEY_IMPLEMENTATION =
bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
bytes32 internal constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
bytes32 internal constant PREFIX_COMMAND_EXECUTED = keccak256('command-executed');
bytes32 internal constant PREFIX_TOKEN_ADDRESS = keccak256('token-address');
bytes32 internal constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 internal constant SELECTOR_BURN_TOKEN = keccak256('burnToken');
bytes32 internal constant SELECTOR_DEPLOY_TOKEN = keccak256('deployToken');
bytes32 internal constant SELECTOR_MINT_TOKEN = keccak256('mintToken');
bytes32 internal constant SELECTOR_TRANSFER_OPERATORSHIP = keccak256('transferOperatorship');
bytes32 internal constant SELECTOR_TRANSFER_OWNERSHIP = keccak256('transferOwnership');
uint8 internal constant OLD_KEY_RETENTION = 16;
modifier onlySelf() {
require(msg.sender == address(this), 'NOT_SELF');
_;
}
function allTokensFrozen() public view override returns (bool) {
return getBool(KEY_ALL_TOKENS_FROZEN);
}
function implementation() public view override returns (address) {
return getAddress(KEY_IMPLEMENTATION);
}
function tokenAddresses(string memory symbol) public view override returns (address) {
return getAddress(_getTokenAddressKey(symbol));
}
function tokenFrozen(string memory symbol) public view override returns (bool) {
return getBool(_getFreezeTokenKey(symbol));
}
function isCommandExecuted(bytes32 commandId) public view override returns (bool) {
return getBool(_getIsCommandExecutedKey(commandId));
}
function freezeToken(string memory symbol) external override onlyAdmin {
_setBool(_getFreezeTokenKey(symbol), true);
emit TokenFrozen(symbol);
}
function unfreezeToken(string memory symbol) external override onlyAdmin {
_setBool(_getFreezeTokenKey(symbol), false);
emit TokenUnfrozen(symbol);
}
function freezeAllTokens() external override onlyAdmin {
_setBool(KEY_ALL_TOKENS_FROZEN, true);
emit AllTokensFrozen();
}
function unfreezeAllTokens() external override onlyAdmin {
_setBool(KEY_ALL_TOKENS_FROZEN, false);
emit AllTokensUnfrozen();
}
function upgrade(address newImplementation, bytes calldata setupParams) external override onlyAdmin {
emit Upgraded(newImplementation);
(bool success, ) = newImplementation.delegatecall(
abi.encodeWithSelector(IAxelarGateway.setup.selector, setupParams)
);
require(success, 'SETUP_FAILED');
_setImplementation(newImplementation);
}
function _deployToken(
string memory name,
string memory symbol,
uint8 decimals,
uint256 cap
) internal {
require(tokenAddresses(symbol) == address(0), 'TOKEN_EXIST');
bytes32 salt = keccak256(abi.encodePacked(symbol));
address token = address(new BurnableMintableCappedERC20{ salt: salt }(name, symbol, decimals, cap));
_setTokenAddress(symbol, token);
emit TokenDeployed(symbol, token);
}
function _mintToken(
string memory symbol,
address account,
uint256 amount
) internal {
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress != address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).mint(account, amount);
}
function _burnToken(string memory symbol, bytes32 salt) internal {
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress != address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).burn(salt);
}
function _getFreezeTokenKey(string memory symbol) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol));
}
function _getTokenAddressKey(string memory symbol) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_TOKEN_ADDRESS, symbol));
}
function _getIsCommandExecutedKey(bytes32 commandId) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_COMMAND_EXECUTED, commandId));
}
function _getChainID() internal view returns (uint256 id) {
assembly {
id := chainid()
}
}
function _setTokenAddress(string memory symbol, address tokenAddr) internal {
_setAddress(_getTokenAddressKey(symbol), tokenAddr);
}
function _setCommandExecuted(bytes32 commandId, bool executed) internal {
_setBool(_getIsCommandExecutedKey(commandId), executed);
}
function _setImplementation(address newImplementation) internal {
_setAddress(KEY_IMPLEMENTATION, newImplementation);
}
}
contract AxelarGatewayMultisig is IAxelarGatewayMultisig, AxelarGateway {
bytes32 internal constant KEY_OWNER_EPOCH = keccak256('owner-epoch');
bytes32 internal constant PREFIX_OWNER = keccak256('owner');
bytes32 internal constant PREFIX_OWNER_COUNT = keccak256('owner-count');
bytes32 internal constant PREFIX_OWNER_THRESHOLD = keccak256('owner-threshold');
bytes32 internal constant PREFIX_IS_OWNER = keccak256('is-owner');
bytes32 internal constant KEY_OPERATOR_EPOCH = keccak256('operator-epoch');
bytes32 internal constant PREFIX_OPERATOR = keccak256('operator');
bytes32 internal constant PREFIX_OPERATOR_COUNT = keccak256('operator-count');
bytes32 internal constant PREFIX_OPERATOR_THRESHOLD = keccak256('operator-threshold');
bytes32 internal constant PREFIX_IS_OPERATOR = keccak256('is-operator');
function _containsDuplicates(address[] memory accounts) internal pure returns (bool) {
uint256 count = accounts.length;
for (uint256 i; i < count; ++i) {
for (uint256 j = i + 1; j < count; ++j) {
if (accounts[i] == accounts[j]) return true;
}
}
return false;
}
function _getOwnerKey(uint256 ownerEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OWNER, ownerEpoch, index));
}
function _getOwnerCountKey(uint256 ownerEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OWNER_COUNT, ownerEpoch));
}
function _getOwnerThresholdKey(uint256 ownerEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OWNER_THRESHOLD, ownerEpoch));
}
function _getIsOwnerKey(uint256 ownerEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_OWNER, ownerEpoch, account));
}
function _ownerEpoch() internal view returns (uint256) {
return getUint(KEY_OWNER_EPOCH);
}
function _getOwner(uint256 ownerEpoch, uint256 index) internal view returns (address) {
return getAddress(_getOwnerKey(ownerEpoch, index));
}
function _getOwnerCount(uint256 ownerEpoch) internal view returns (uint256) {
return getUint(_getOwnerCountKey(ownerEpoch));
}
function _getOwnerThreshold(uint256 ownerEpoch) internal view returns (uint256) {
return getUint(_getOwnerThresholdKey(ownerEpoch));
}
function _isOwner(uint256 ownerEpoch, address account) internal view returns (bool) {
return getBool(_getIsOwnerKey(ownerEpoch, account));
}
function _areValidRecentOwners(address[] memory accounts) internal view returns (bool) {
uint256 ownerEpoch = _ownerEpoch();
uint256 recentEpochs = OLD_KEY_RETENTION + uint256(1);
uint256 lowerBoundOwnerEpoch = ownerEpoch > recentEpochs ? ownerEpoch - recentEpochs : uint256(0);
while (ownerEpoch > lowerBoundOwnerEpoch) {
if (_areValidOwnersInEpoch(ownerEpoch--, accounts)) return true;
}
return false;
}
function _areValidOwnersInEpoch(uint256 ownerEpoch, address[] memory accounts) internal view returns (bool) {
if (_containsDuplicates(accounts)) return false;
uint256 threshold = _getOwnerThreshold(ownerEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOwner(ownerEpoch, accounts[i]) && ++validSignerCount >= threshold) return true;
}
return false;
}
function owners() public view override returns (address[] memory results) {
uint256 ownerEpoch = _ownerEpoch();
uint256 ownerCount = _getOwnerCount(ownerEpoch);
results = new address[](ownerCount);
for (uint256 i; i < ownerCount; i++) {
results[i] = _getOwner(ownerEpoch, i);
}
}
function _setOwnerEpoch(uint256 ownerEpoch) internal {
_setUint(KEY_OWNER_EPOCH, ownerEpoch);
}
function _setOwner(
uint256 ownerEpoch,
uint256 index,
address account
) internal {
require(account != address(0), 'ZERO_ADDR');
_setAddress(_getOwnerKey(ownerEpoch, index), account);
}
function _setOwnerCount(uint256 ownerEpoch, uint256 ownerCount) internal {
_setUint(_getOwnerCountKey(ownerEpoch), ownerCount);
}
function _setOwners(
uint256 ownerEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 accountLength = accounts.length;
require(accountLength >= threshold, 'INV_OWNERS');
require(threshold > uint256(0), 'INV_OWNER_THLD');
_setOwnerThreshold(ownerEpoch, threshold);
_setOwnerCount(ownerEpoch, accountLength);
for (uint256 i; i < accountLength; i++) {
address account = accounts[i];
require(!_isOwner(ownerEpoch, account), 'DUP_OWNER');
_setOwner(ownerEpoch, i, account);
_setIsOwner(ownerEpoch, account, true);
}
}
function _setOwnerThreshold(uint256 ownerEpoch, uint256 ownerThreshold) internal {
_setUint(_getOwnerThresholdKey(ownerEpoch), ownerThreshold);
}
function _setIsOwner(
uint256 ownerEpoch,
address account,
bool isOwner
) internal {
_setBool(_getIsOwnerKey(ownerEpoch, account), isOwner);
}
function _getOperatorKey(uint256 operatorEpoch, uint256 index) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OPERATOR, operatorEpoch, index));
}
function _getOperatorCountKey(uint256 operatorEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OPERATOR_COUNT, operatorEpoch));
}
function _getOperatorThresholdKey(uint256 operatorEpoch) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_OPERATOR_THRESHOLD, operatorEpoch));
}
function _getIsOperatorKey(uint256 operatorEpoch, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PREFIX_IS_OPERATOR, operatorEpoch, account));
}
function _operatorEpoch() internal view returns (uint256) {
return getUint(KEY_OPERATOR_EPOCH);
}
function _getOperator(uint256 operatorEpoch, uint256 index) internal view returns (address) {
return getAddress(_getOperatorKey(operatorEpoch, index));
}
function _getOperatorCount(uint256 operatorEpoch) internal view returns (uint256) {
return getUint(_getOperatorCountKey(operatorEpoch));
}
function _getOperatorThreshold(uint256 operatorEpoch) internal view returns (uint256) {
return getUint(_getOperatorThresholdKey(operatorEpoch));
}
function _isOperator(uint256 operatorEpoch, address account) internal view returns (bool) {
return getBool(_getIsOperatorKey(operatorEpoch, account));
}
function _areValidRecentOperators(address[] memory accounts) internal view returns (bool) {
uint256 operatorEpoch = _operatorEpoch();
uint256 recentEpochs = OLD_KEY_RETENTION + uint256(1);
uint256 lowerBoundOperatorEpoch = operatorEpoch > recentEpochs ? operatorEpoch - recentEpochs : uint256(0);
while (operatorEpoch > lowerBoundOperatorEpoch) {
if (_areValidOperatorsInEpoch(operatorEpoch--, accounts)) return true;
}
return false;
}
function _areValidOperatorsInEpoch(uint256 operatorEpoch, address[] memory accounts) internal view returns (bool) {
if (_containsDuplicates(accounts)) return false;
uint256 threshold = _getOperatorThreshold(operatorEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOperator(operatorEpoch, accounts[i]) && ++validSignerCount >= threshold) return true;
}
return false;
}
function operators() public view override returns (address[] memory results) {
uint256 operatorEpoch = _operatorEpoch();
uint256 operatorCount = _getOperatorCount(operatorEpoch);
results = new address[](operatorCount);
for (uint256 i; i < operatorCount; i++) {
results[i] = _getOperator(operatorEpoch, i);
}
}
function _setOperatorEpoch(uint256 operatorEpoch) internal {
_setUint(KEY_OPERATOR_EPOCH, operatorEpoch);
}
function _setOperator(
uint256 operatorEpoch,
uint256 index,
address account
) internal {
_setAddress(_getOperatorKey(operatorEpoch, index), account);
}
function _setOperatorCount(uint256 operatorEpoch, uint256 operatorCount) internal {
_setUint(_getOperatorCountKey(operatorEpoch), operatorCount);
}
function _setOperators(
uint256 operatorEpoch,
address[] memory accounts,
uint256 threshold
) internal {
uint256 accountLength = accounts.length;
require(accountLength >= threshold, 'INV_OPERATORS');
require(threshold > uint256(0), 'INV_OPERATOR_THLD');
_setOperatorThreshold(operatorEpoch, threshold);
_setOperatorCount(operatorEpoch, accountLength);
for (uint256 i; i < accountLength; i++) {
address account = accounts[i];
require(!_isOperator(operatorEpoch, account), 'DUP_OPERATOR');
_setOperator(operatorEpoch, i, account);
_setIsOperator(operatorEpoch, account, true);
}
}
function _setOperatorThreshold(uint256 operatorEpoch, uint256 operatorThreshold) internal {
_setUint(_getOperatorThresholdKey(operatorEpoch), operatorThreshold);
}
function _setIsOperator(
uint256 operatorEpoch,
address account,
bool isOperator
) internal {
_setBool(_getIsOperatorKey(operatorEpoch, account), isOperator);
}
function deployToken(bytes calldata params) external onlySelf {
(string memory name, string memory symbol, uint8 decimals, uint256 cap) = abi.decode(
params,
(string, string, uint8, uint256)
);
_deployToken(name, symbol, decimals, cap);
}
function mintToken(bytes calldata params) external onlySelf {
(string memory symbol, address account, uint256 amount) = abi.decode(params, (string, address, uint256));
_mintToken(symbol, account, amount);
}
function burnToken(bytes calldata params) external onlySelf {
(string memory symbol, bytes32 salt) = abi.decode(params, (string, bytes32));
_burnToken(symbol, salt);
}
function transferOwnership(bytes calldata params) external onlySelf {
(address[] memory newOwners, uint256 newThreshold) = abi.decode(params, (address[], uint256));
uint256 ownerEpoch = _ownerEpoch();
emit OwnershipTransferred(owners(), _getOwnerThreshold(ownerEpoch), newOwners, newThreshold);
_setOwnerEpoch(++ownerEpoch);
_setOwners(ownerEpoch, newOwners, newThreshold);
}
function transferOperatorship(bytes calldata params) external onlySelf {
(address[] memory newOperators, uint256 newThreshold) = abi.decode(params, (address[], uint256));
uint256 ownerEpoch = _ownerEpoch();
emit OperatorshipTransferred(operators(), _getOperatorThreshold(ownerEpoch), newOperators, newThreshold);
uint256 operatorEpoch = _operatorEpoch();
_setOperatorEpoch(++operatorEpoch);
_setOperators(operatorEpoch, newOperators, newThreshold);
}
function setup(bytes calldata params) external override {
require(implementation() != address(0), 'NOT_PROXY');
(
address[] memory adminAddresses,
uint256 adminThreshold,
address[] memory ownerAddresses,
uint256 ownerThreshold,
address[] memory operatorAddresses,
uint256 operatorThreshold
) = abi.decode(params, (address[], uint256, address[], uint256, address[], uint256));
uint256 adminEpoch = _adminEpoch() + uint256(1);
_setAdminEpoch(adminEpoch);
_setAdmins(adminEpoch, adminAddresses, adminThreshold);
uint256 ownerEpoch = _ownerEpoch() + uint256(1);
_setOwnerEpoch(ownerEpoch);
_setOwners(ownerEpoch, ownerAddresses, ownerThreshold);
uint256 operatorEpoch = _operatorEpoch() + uint256(1);
_setOperatorEpoch(operatorEpoch);
_setOperators(operatorEpoch, operatorAddresses, operatorThreshold);
emit OwnershipTransferred(new address[](uint256(0)), uint256(0), ownerAddresses, ownerThreshold);
emit OperatorshipTransferred(new address[](uint256(0)), uint256(0), operatorAddresses, operatorThreshold);
}
function execute(bytes calldata input) external override {
(bytes memory data, bytes[] memory signatures) = abi.decode(input, (bytes, bytes[]));
_execute(data, signatures);
}
function _execute(bytes memory data, bytes[] memory signatures) internal {
uint256 signatureCount = signatures.length;
address[] memory signers = new address[](signatureCount);
for (uint256 i; i < signatureCount; i++) {
signers[i] = ECDSA.recover(ECDSA.toEthSignedMessageHash(keccak256(data)), signatures[i]);
}
(uint256 chainId, bytes32[] memory commandIds, string[] memory commands, bytes[] memory params) = abi.decode(
data,
(uint256, bytes32[], string[], bytes[])
);
require(chainId == _getChainID(), 'INV_CHAIN');
uint256 commandsLength = commandIds.length;
require(commandsLength == commands.length && commandsLength == params.length, 'INV_CMDS');
bool areValidCurrentOwners = _areValidOwnersInEpoch(_ownerEpoch(), signers);
bool areValidRecentOwners = areValidCurrentOwners || _areValidRecentOwners(signers);
bool areValidRecentOperators = _areValidRecentOperators(signers);
for (uint256 i; i < commandsLength; i++) {
bytes32 commandId = commandIds[i];
if (isCommandExecuted(commandId)) continue;
bytes4 commandSelector;
bytes32 commandHash = keccak256(abi.encodePacked(commands[i]));
if (commandHash == SELECTOR_DEPLOY_TOKEN) {
if (!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.deployToken.selector;
} else if (commandHash == SELECTOR_MINT_TOKEN) {
if (!areValidRecentOperators && !areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.mintToken.selector;
} else if (commandHash == SELECTOR_BURN_TOKEN) {
if (!areValidRecentOperators && !areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.burnToken.selector;
} else if (commandHash == SELECTOR_TRANSFER_OWNERSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOwnership.selector;
} else if (commandHash == SELECTOR_TRANSFER_OPERATORSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOperatorship.selector;
} else {
continue;
}
_setCommandExecuted(commandId, true);
(bool success, ) = address(this).call(abi.encodeWithSelector(commandSelector, params[i]));
_setCommandExecuted(commandId, success);
if (success) {
emit Executed(commandId);
}
}
}
}
pragma solidity >=0.8.0 <0.9.0;
contract AxelarGatewayProxyMultisig is AxelarGatewayProxy {
constructor(bytes memory params) {
address gateway = address(new AxelarGatewayMultisig());
_setAddress(KEY_IMPLEMENTATION, gateway);
(bool success, ) = gateway.delegatecall(abi.encodeWithSelector(IAxelarGateway.setup.selector, params));
require(success, 'SETUP_FAILED');
}
function setup(bytes calldata params) external {}
}
文件 6 的 15:BurnableMintableCappedERC20.sol
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
contract ERC20 is Context, IERC20 {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
uint256 public override totalSupply;
string public name;
string public symbol;
uint8 public immutable decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), 'ZERO_ADDR');
require(recipient != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(sender, recipient, amount);
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), 'ZERO_ADDR');
require(spender != address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
abstract contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
require(owner == msg.sender, 'NOT_OWNER');
_;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Burner {
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
pragma solidity >=0.8.0 <0.9.0;
contract BurnableMintableCappedERC20 is ERC20, Ownable {
uint256 public cap;
bytes32 private constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 private constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
event Frozen(address indexed owner);
event Unfrozen(address indexed owner);
constructor(
string memory name,
string memory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
function depositAddress(bytes32 salt) public view returns (address) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
function mint(address account, uint256 amount) public onlyOwner {
uint256 capacity = cap;
require(capacity == 0 || totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
function burn(bytes32 salt) public onlyOwner {
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function _beforeTokenTransfer(
address,
address,
uint256
) internal view override {
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
文件 7 的 15:Burner.sol
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
contract ERC20 is Context, IERC20 {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
uint256 public override totalSupply;
string public name;
string public symbol;
uint8 public immutable decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), 'ZERO_ADDR');
require(recipient != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(sender, recipient, amount);
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), 'ZERO_ADDR');
require(spender != address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
abstract contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
require(owner == msg.sender, 'NOT_OWNER');
_;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
contract BurnableMintableCappedERC20 is ERC20, Ownable {
uint256 public cap;
bytes32 private constant PREFIX_TOKEN_FROZEN = keccak256('token-frozen');
bytes32 private constant KEY_ALL_TOKENS_FROZEN = keccak256('all-tokens-frozen');
event Frozen(address indexed owner);
event Unfrozen(address indexed owner);
constructor(
string memory name,
string memory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
function depositAddress(bytes32 salt) public view returns (address) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
function mint(address account, uint256 amount) public onlyOwner {
uint256 capacity = cap;
require(capacity == 0 || totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
function burn(bytes32 salt) public onlyOwner {
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function _beforeTokenTransfer(
address,
address,
uint256
) internal view override {
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
pragma solidity >=0.8.0 <0.9.0;
contract Burner {
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
文件 8 的 15:Context.sol
pragma solidity >=0.8.0 <0.9.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 9 的 15:ECDSA.sol
pragma solidity >=0.8.0 <0.9.0;
library ECDSA {
function recover(bytes32 hash, bytes memory signature) internal pure returns (address signer) {
require(signature.length == 65, 'INV_LEN');
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, 'INV_S');
require(v == 27 || v == 28, 'INV_V');
require((signer = ecrecover(hash, v, r, s)) != address(0), 'INV_SIG');
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked('\x19Ethereum Signed Message:\n32', hash));
}
}
文件 10 的 15:ERC20.sol
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
pragma solidity >=0.8.0 <0.9.0;
contract ERC20 is Context, IERC20 {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
uint256 public override totalSupply;
string public name;
string public symbol;
uint8 public immutable decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), 'ZERO_ADDR');
require(recipient != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(sender, recipient, amount);
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), 'ZERO_ADDR');
require(spender != address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
文件 11 的 15:EternalStorage.sol
pragma solidity >=0.8.0 <0.9.0;
contract EternalStorage {
mapping(bytes32 => uint256) private _uintStorage;
mapping(bytes32 => string) private _stringStorage;
mapping(bytes32 => address) private _addressStorage;
mapping(bytes32 => bytes) private _bytesStorage;
mapping(bytes32 => bool) private _boolStorage;
mapping(bytes32 => int256) private _intStorage;
function getUint(bytes32 key) public view returns (uint256) {
return _uintStorage[key];
}
function getString(bytes32 key) public view returns (string memory) {
return _stringStorage[key];
}
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[key];
}
function getBytes(bytes32 key) public view returns (bytes memory) {
return _bytesStorage[key];
}
function getBool(bytes32 key) public view returns (bool) {
return _boolStorage[key];
}
function getInt(bytes32 key) public view returns (int256) {
return _intStorage[key];
}
function _setUint(bytes32 key, uint256 value) internal {
_uintStorage[key] = value;
}
function _setString(bytes32 key, string memory value) internal {
_stringStorage[key] = value;
}
function _setAddress(bytes32 key, address value) internal {
_addressStorage[key] = value;
}
function _setBytes(bytes32 key, bytes memory value) internal {
_bytesStorage[key] = value;
}
function _setBool(bytes32 key, bool value) internal {
_boolStorage[key] = value;
}
function _setInt(bytes32 key, int256 value) internal {
_intStorage[key] = value;
}
function _deleteUint(bytes32 key) internal {
delete _uintStorage[key];
}
function _deleteString(bytes32 key) internal {
delete _stringStorage[key];
}
function _deleteAddress(bytes32 key) internal {
delete _addressStorage[key];
}
function _deleteBytes(bytes32 key) internal {
delete _bytesStorage[key];
}
function _deleteBool(bytes32 key) internal {
delete _boolStorage[key];
}
function _deleteInt(bytes32 key) internal {
delete _intStorage[key];
}
}
文件 12 的 15:IAxelarGateway.sol
pragma solidity >=0.8.0 <0.9.0;
interface IAxelarGateway {
event Executed(bytes32 indexed commandId);
event TokenDeployed(string symbol, address tokenAddresses);
event TokenFrozen(string indexed symbol);
event TokenUnfrozen(string indexed symbol);
event AllTokensFrozen();
event AllTokensUnfrozen();
event AccountBlacklisted(address indexed account);
event AccountWhitelisted(address indexed account);
event Upgraded(address indexed implementation);
function allTokensFrozen() external view returns (bool);
function implementation() external view returns (address);
function tokenAddresses(string memory symbol) external view returns (address);
function tokenFrozen(string memory symbol) external view returns (bool);
function isCommandExecuted(bytes32 commandId) external view returns (bool);
function freezeToken(string memory symbol) external;
function unfreezeToken(string memory symbol) external;
function freezeAllTokens() external;
function unfreezeAllTokens() external;
function upgrade(address newImplementation, bytes calldata setupParams) external;
function setup(bytes calldata params) external;
function execute(bytes calldata input) external;
}
文件 13 的 15:IAxelarGatewayMultisig.sol
interface IAxelarGateway {
event Executed(bytes32 indexed commandId);
event TokenDeployed(string symbol, address tokenAddresses);
event TokenFrozen(string indexed symbol);
event TokenUnfrozen(string indexed symbol);
event AllTokensFrozen();
event AllTokensUnfrozen();
event AccountBlacklisted(address indexed account);
event AccountWhitelisted(address indexed account);
event Upgraded(address indexed implementation);
function allTokensFrozen() external view returns (bool);
function implementation() external view returns (address);
function tokenAddresses(string memory symbol) external view returns (address);
function tokenFrozen(string memory symbol) external view returns (bool);
function isCommandExecuted(bytes32 commandId) external view returns (bool);
function freezeToken(string memory symbol) external;
function unfreezeToken(string memory symbol) external;
function freezeAllTokens() external;
function unfreezeAllTokens() external;
function upgrade(address newImplementation, bytes calldata setupParams) external;
function setup(bytes calldata params) external;
function execute(bytes calldata input) external;
}
pragma solidity >=0.8.0 <0.9.0;
interface IAxelarGatewayMultisig is IAxelarGateway {
event OwnershipTransferred(address[] preOwners, uint256 prevThreshold, address[] newOwners, uint256 newThreshold);
event OperatorshipTransferred(address[] preOperators, uint256 prevThreshold, address[] newOperators, uint256 newThreshold);
function owners() external view returns (address[] memory);
function operators() external view returns (address[] memory);
}
文件 14 的 15:IERC20.sol
pragma solidity >=0.8.0 <0.9.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 15 的 15:Ownable.sol
pragma solidity >=0.8.0 <0.9.0;
abstract contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifier onlyOwner() {
require(owner == msg.sender, 'NOT_OWNER');
_;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
{
"compilationTarget": {
"AxelarGatewayProxyMultisig.sol": "AxelarGatewayProxyMultisig"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"bytes","name":"params","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getBool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getBytes","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getInt","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getString","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getUint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"params","type":"bytes"}],"name":"setup","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]