// Dependency file: src/interfaces/IAxelarGateway.sol// SPDX-License-Identifier: MIT// pragma solidity >=0.8.0 <0.9.0;interfaceIAxelarGateway{
/**********\
|* Events *|
\**********/eventExecuted(bytes32indexed commandId);
eventTokenDeployed(string symbol, address tokenAddresses);
eventTokenFrozen(stringindexed symbol);
eventTokenUnfrozen(stringindexed symbol);
eventAllTokensFrozen();
eventAllTokensUnfrozen();
eventAccountBlacklisted(addressindexed account);
eventAccountWhitelisted(addressindexed account);
eventUpgraded(addressindexed implementation);
/***********\
|* Getters *|
\***********/functionallTokensFrozen() externalviewreturns (bool);
functionimplementation() externalviewreturns (address);
functiontokenAddresses(stringmemory symbol) externalviewreturns (address);
functiontokenFrozen(stringmemory symbol) externalviewreturns (bool);
functionisCommandExecuted(bytes32 commandId) externalviewreturns (bool);
/*******************\
|* Admin Functions *|
\*******************/functionfreezeToken(stringmemory symbol) external;
functionunfreezeToken(stringmemory symbol) external;
functionfreezeAllTokens() external;
functionunfreezeAllTokens() external;
functionupgrade(address newImplementation, bytescalldata setupParams) external;
/**********************\
|* External Functions *|
\**********************/functionsetup(bytescalldata params) external;
functionexecute(bytescalldata input) external;
}
// Dependency file: src/interfaces/IERC20.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
// Dependency file: src/Context.sol// pragma solidity >=0.8.0 <0.9.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnpayable(msg.sender);
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
// Dependency file: src/ERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { IERC20 } from 'src/interfaces/IERC20.sol';// import { Context } from 'src/Context.sol';/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20{
mapping(address=>uint256) publicoverride balanceOf;
mapping(address=>mapping(address=>uint256)) publicoverride allowance;
uint256publicoverride totalSupply;
stringpublic name;
stringpublic symbol;
uint8publicimmutable decimals;
/**
* @dev Sets the values for {name}, {symbol}, and {decimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_,
stringmemory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtual{
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner,
address spender,
uint256 amount
) internalvirtual{
require(owner !=address(0), 'ZERO_ADDR');
require(spender !=address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
// Dependency file: src/Ownable.sol// pragma solidity >=0.8.0 <0.9.0;abstractcontractOwnable{
addresspublic owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
constructor() {
owner =msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifieronlyOwner() {
require(owner ==msg.sender, 'NOT_OWNER');
_;
}
functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// Dependency file: src/Burner.sol// pragma solidity >=0.8.0 <0.9.0;// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';contractBurner{
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
// Dependency file: src/EternalStorage.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @title EternalStorage
* @dev This contract holds all the necessary state variables to carry out the storage of any contract.
*/contractEternalStorage{
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;
// *** Getter Methods ***functiongetUint(bytes32 key) publicviewreturns (uint256) {
return _uintStorage[key];
}
functiongetString(bytes32 key) publicviewreturns (stringmemory) {
return _stringStorage[key];
}
functiongetAddress(bytes32 key) publicviewreturns (address) {
return _addressStorage[key];
}
functiongetBytes(bytes32 key) publicviewreturns (bytesmemory) {
return _bytesStorage[key];
}
functiongetBool(bytes32 key) publicviewreturns (bool) {
return _boolStorage[key];
}
functiongetInt(bytes32 key) publicviewreturns (int256) {
return _intStorage[key];
}
// *** Setter Methods ***function_setUint(bytes32 key, uint256 value) internal{
_uintStorage[key] = value;
}
function_setString(bytes32 key, stringmemory value) internal{
_stringStorage[key] = value;
}
function_setAddress(bytes32 key, address value) internal{
_addressStorage[key] = value;
}
function_setBytes(bytes32 key, bytesmemory 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;
}
// *** Delete Methods ***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];
}
}
// Dependency file: src/BurnableMintableCappedERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { ERC20 } from 'src/ERC20.sol';// import { Ownable } from 'src/Ownable.sol';// import { Burner } from 'src/Burner.sol';// import { EternalStorage } from 'src/EternalStorage.sol';contractBurnableMintableCappedERC20isERC20, Ownable{
uint256public cap;
bytes32privateconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32privateconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
eventFrozen(addressindexed owner);
eventUnfrozen(addressindexed owner);
constructor(stringmemory name,
stringmemory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
functiondepositAddress(bytes32 salt) publicviewreturns (address) {
// This would be easier, cheaper, simpler, and result in globally consistent deposit addresses for any salt (all chains, all tokens).// return address(uint160(uint256(keccak256(abi.encodePacked(bytes32(0x000000000000000000000000000000000000000000000000000000000000dead), salt)))));/* Convert a hash which is bytes32 to an address which is 20-byte long
according to https://docs.soliditylang.org/en/v0.8.1/control-structures.html?highlight=create2#salted-contract-creations-create2 */returnaddress(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
functionmint(address account, uint256 amount) publiconlyOwner{
uint256 capacity = cap;
require(capacity ==0|| totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
functionburn(bytes32 salt) publiconlyOwner{
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function_beforeTokenTransfer(address,
address,
uint256) internalviewoverride{
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
// Dependency file: src/AdminMultisigBase.sol// pragma solidity >=0.8.0 <0.9.0;// import { EternalStorage } from 'src/EternalStorage.sol';contractAdminMultisigBaseisEternalStorage{
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_ADMIN_EPOCH =keccak256('admin-epoch');
bytes32internalconstant PREFIX_ADMIN =keccak256('admin');
bytes32internalconstant PREFIX_ADMIN_COUNT =keccak256('admin-count');
bytes32internalconstant PREFIX_ADMIN_THRESHOLD =keccak256('admin-threshold');
bytes32internalconstant PREFIX_ADMIN_VOTE_COUNTS =keccak256('admin-vote-counts');
bytes32internalconstant PREFIX_ADMIN_VOTED =keccak256('admin-voted');
bytes32internalconstant PREFIX_IS_ADMIN =keccak256('is-admin');
modifieronlyAdmin() {
uint256 adminEpoch = _adminEpoch();
require(_isAdmin(adminEpoch, msg.sender), 'NOT_ADMIN');
bytes32 topic =keccak256(msg.data);
// Check that admin has not voted, then record that they have voted.require(!_hasVoted(adminEpoch, topic, msg.sender), 'VOTED');
_setHasVoted(adminEpoch, topic, msg.sender, true);
// Determine the new vote count and update it.uint256 adminVoteCount = _getVoteCount(adminEpoch, topic) +uint256(1);
_setVoteCount(adminEpoch, topic, adminVoteCount);
// Do not proceed with operation execution if insufficient votes.if (adminVoteCount < _getAdminThreshold(adminEpoch)) return;
_;
// Clear vote count and voted booleans.
_setVoteCount(adminEpoch, topic, uint256(0));
uint256 adminCount = _getAdminCount(adminEpoch);
for (uint256 i; i < adminCount; i++) {
_setHasVoted(adminEpoch, topic, _getAdmin(adminEpoch, i), false);
}
}
/********************\
|* Pure Key Getters *|
\********************/function_getAdminKey(uint256 adminEpoch, uint256 index) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN, adminEpoch, index));
}
function_getAdminCountKey(uint256 adminEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_COUNT, adminEpoch));
}
function_getAdminThresholdKey(uint256 adminEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_THRESHOLD, adminEpoch));
}
function_getAdminVoteCountsKey(uint256 adminEpoch, bytes32 topic) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_VOTE_COUNTS, adminEpoch, topic));
}
function_getAdminVotedKey(uint256 adminEpoch,
bytes32 topic,
address account
) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_VOTED, adminEpoch, topic, account));
}
function_getIsAdminKey(uint256 adminEpoch, address account) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_IS_ADMIN, adminEpoch, account));
}
/***********\
|* Getters *|
\***********/function_adminEpoch() internalviewreturns (uint256) {
return getUint(KEY_ADMIN_EPOCH);
}
function_getAdmin(uint256 adminEpoch, uint256 index) internalviewreturns (address) {
return getAddress(_getAdminKey(adminEpoch, index));
}
function_getAdminCount(uint256 adminEpoch) internalviewreturns (uint256) {
return getUint(_getAdminCountKey(adminEpoch));
}
function_getAdminThreshold(uint256 adminEpoch) internalviewreturns (uint256) {
return getUint(_getAdminThresholdKey(adminEpoch));
}
function_getVoteCount(uint256 adminEpoch, bytes32 topic) internalviewreturns (uint256) {
return getUint(_getAdminVoteCountsKey(adminEpoch, topic));
}
function_hasVoted(uint256 adminEpoch,
bytes32 topic,
address account
) internalviewreturns (bool) {
return getBool(_getAdminVotedKey(adminEpoch, topic, account));
}
function_isAdmin(uint256 adminEpoch, address account) internalviewreturns (bool) {
return getBool(_getIsAdminKey(adminEpoch, account));
}
/***********\
|* Setters *|
\***********/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];
// Check that the account wasn't already set as an admin for this epoch.require(!_isAdmin(adminEpoch, account), 'DUP_ADMIN');
// Set this account as the i-th admin in this epoch (needed to we can clear topic votes in `onlyAdmin`).
_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);
}
}
// Root file: src/AxelarGateway.solpragmasolidity >=0.8.0 <0.9.0;// import { IAxelarGateway } from 'src/interfaces/IAxelarGateway.sol';// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';// import { AdminMultisigBase } from 'src/AdminMultisigBase.sol';abstractcontractAxelarGatewayisIAxelarGateway, AdminMultisigBase{
/// @dev Storage slot with the address of the current factory. `keccak256('eip1967.proxy.implementation') - 1`.bytes32internalconstant KEY_IMPLEMENTATION =bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
bytes32internalconstant PREFIX_COMMAND_EXECUTED =keccak256('command-executed');
bytes32internalconstant PREFIX_TOKEN_ADDRESS =keccak256('token-address');
bytes32internalconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32internalconstant SELECTOR_BURN_TOKEN =keccak256('burnToken');
bytes32internalconstant SELECTOR_DEPLOY_TOKEN =keccak256('deployToken');
bytes32internalconstant SELECTOR_MINT_TOKEN =keccak256('mintToken');
bytes32internalconstant SELECTOR_TRANSFER_OPERATORSHIP =keccak256('transferOperatorship');
bytes32internalconstant SELECTOR_TRANSFER_OWNERSHIP =keccak256('transferOwnership');
uint8internalconstant OLD_KEY_RETENTION =16;
modifieronlySelf() {
require(msg.sender==address(this), 'NOT_SELF');
_;
}
/***********\
|* Getters *|
\***********/functionallTokensFrozen() publicviewoverridereturns (bool) {
return getBool(KEY_ALL_TOKENS_FROZEN);
}
functionimplementation() publicviewoverridereturns (address) {
return getAddress(KEY_IMPLEMENTATION);
}
functiontokenAddresses(stringmemory symbol) publicviewoverridereturns (address) {
return getAddress(_getTokenAddressKey(symbol));
}
functiontokenFrozen(stringmemory symbol) publicviewoverridereturns (bool) {
return getBool(_getFreezeTokenKey(symbol));
}
functionisCommandExecuted(bytes32 commandId) publicviewoverridereturns (bool) {
return getBool(_getIsCommandExecutedKey(commandId));
}
/*******************\
|* Admin Functions *|
\*******************/functionfreezeToken(stringmemory symbol) externaloverrideonlyAdmin{
_setBool(_getFreezeTokenKey(symbol), true);
emit TokenFrozen(symbol);
}
functionunfreezeToken(stringmemory symbol) externaloverrideonlyAdmin{
_setBool(_getFreezeTokenKey(symbol), false);
emit TokenUnfrozen(symbol);
}
functionfreezeAllTokens() externaloverrideonlyAdmin{
_setBool(KEY_ALL_TOKENS_FROZEN, true);
emit AllTokensFrozen();
}
functionunfreezeAllTokens() externaloverrideonlyAdmin{
_setBool(KEY_ALL_TOKENS_FROZEN, false);
emit AllTokensUnfrozen();
}
functionupgrade(address newImplementation, bytescalldata setupParams) externaloverrideonlyAdmin{
emit Upgraded(newImplementation);
// AUDIT: If `newImplementation.setup` performs `selfdestruct`, it will result in the loss of _this_ implementation (thereby losing the gateway)// if `upgrade` is entered within the context of _this_ implementation itself.
(bool success, ) = newImplementation.delegatecall(
abi.encodeWithSelector(IAxelarGateway.setup.selector, setupParams)
);
require(success, 'SETUP_FAILED');
_setImplementation(newImplementation);
}
/**********************\
|* Internal Functions *|
\**********************/function_deployToken(stringmemory name,
stringmemory 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(stringmemory symbol,
address account,
uint256 amount
) internal{
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress !=address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).mint(account, amount);
}
function_burnToken(stringmemory symbol, bytes32 salt) internal{
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress !=address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).burn(salt);
}
/********************\
|* Pure Key Getters *|
\********************/function_getFreezeTokenKey(stringmemory symbol) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol));
}
function_getTokenAddressKey(stringmemory symbol) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_TOKEN_ADDRESS, symbol));
}
function_getIsCommandExecutedKey(bytes32 commandId) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_COMMAND_EXECUTED, commandId));
}
/********************\
|* Internal Getters *|
\********************/function_getChainID() internalviewreturns (uint256 id) {
assembly {
id :=chainid()
}
}
/********************\
|* Internal Setters *|
\********************/function_setTokenAddress(stringmemory 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 Source Code
File 3 of 15: AxelarGatewayMultisig.sol
// Dependency file: src/interfaces/IAxelarGateway.sol// SPDX-License-Identifier: MIT// pragma solidity >=0.8.0 <0.9.0;interfaceIAxelarGateway{
/**********\
|* Events *|
\**********/eventExecuted(bytes32indexed commandId);
eventTokenDeployed(string symbol, address tokenAddresses);
eventTokenFrozen(stringindexed symbol);
eventTokenUnfrozen(stringindexed symbol);
eventAllTokensFrozen();
eventAllTokensUnfrozen();
eventAccountBlacklisted(addressindexed account);
eventAccountWhitelisted(addressindexed account);
eventUpgraded(addressindexed implementation);
/***********\
|* Getters *|
\***********/functionallTokensFrozen() externalviewreturns (bool);
functionimplementation() externalviewreturns (address);
functiontokenAddresses(stringmemory symbol) externalviewreturns (address);
functiontokenFrozen(stringmemory symbol) externalviewreturns (bool);
functionisCommandExecuted(bytes32 commandId) externalviewreturns (bool);
/*******************\
|* Admin Functions *|
\*******************/functionfreezeToken(stringmemory symbol) external;
functionunfreezeToken(stringmemory symbol) external;
functionfreezeAllTokens() external;
functionunfreezeAllTokens() external;
functionupgrade(address newImplementation, bytescalldata setupParams) external;
/**********************\
|* External Functions *|
\**********************/functionsetup(bytescalldata params) external;
functionexecute(bytescalldata input) external;
}
// Dependency file: src/interfaces/IAxelarGatewayMultisig.sol// pragma solidity >=0.8.0 <0.9.0;// import { IAxelarGateway } from 'src/interfaces/IAxelarGateway.sol';interfaceIAxelarGatewayMultisigisIAxelarGateway{
eventOwnershipTransferred(address[] preOwners, uint256 prevThreshold, address[] newOwners, uint256 newThreshold);
eventOperatorshipTransferred(address[] preOperators, uint256 prevThreshold, address[] newOperators, uint256 newThreshold);
functionowners() externalviewreturns (address[] memory);
functionoperators() externalviewreturns (address[] memory);
}
// Dependency file: src/ECDSA.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/libraryECDSA{
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/functionrecover(bytes32 hash, bytesmemory signature) internalpurereturns (address signer) {
// Check the signature lengthrequire(signature.length==65, 'INV_LEN');
// Divide the signature in r, s and v variablesbytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them// currently is to use assembly.// solhint-disable-next-line no-inline-assemblyassembly {
r :=mload(add(signature, 0x20))
s :=mload(add(signature, 0x40))
v :=byte(0, mload(add(signature, 0x60)))
}
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most// signatures from current libraries generate a unique signature with an s-value in the lower half order.//// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept// these malleable signatures as well.require(uint256(s) <=0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, 'INV_S');
require(v ==27|| v ==28, 'INV_V');
// If the signature is valid (and not malleable), return the signer addressrequire((signer =ecrecover(hash, v, r, s)) !=address(0), 'INV_SIG');
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* replicates the behavior of the
* https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
* JSON-RPC method.
*
* See {recover}.
*/functiontoEthSignedMessageHash(bytes32 hash) internalpurereturns (bytes32) {
// 32 is the length in bytes of hash,// enforced by the type signature abovereturnkeccak256(abi.encodePacked('\x19Ethereum Signed Message:\n32', hash));
}
}
// Dependency file: src/interfaces/IERC20.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
// Dependency file: src/Context.sol// pragma solidity >=0.8.0 <0.9.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnpayable(msg.sender);
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
// Dependency file: src/ERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { IERC20 } from 'src/interfaces/IERC20.sol';// import { Context } from 'src/Context.sol';/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20{
mapping(address=>uint256) publicoverride balanceOf;
mapping(address=>mapping(address=>uint256)) publicoverride allowance;
uint256publicoverride totalSupply;
stringpublic name;
stringpublic symbol;
uint8publicimmutable decimals;
/**
* @dev Sets the values for {name}, {symbol}, and {decimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_,
stringmemory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtual{
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner,
address spender,
uint256 amount
) internalvirtual{
require(owner !=address(0), 'ZERO_ADDR');
require(spender !=address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
// Dependency file: src/Ownable.sol// pragma solidity >=0.8.0 <0.9.0;abstractcontractOwnable{
addresspublic owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
constructor() {
owner =msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifieronlyOwner() {
require(owner ==msg.sender, 'NOT_OWNER');
_;
}
functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// Dependency file: src/Burner.sol// pragma solidity >=0.8.0 <0.9.0;// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';contractBurner{
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
// Dependency file: src/EternalStorage.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @title EternalStorage
* @dev This contract holds all the necessary state variables to carry out the storage of any contract.
*/contractEternalStorage{
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;
// *** Getter Methods ***functiongetUint(bytes32 key) publicviewreturns (uint256) {
return _uintStorage[key];
}
functiongetString(bytes32 key) publicviewreturns (stringmemory) {
return _stringStorage[key];
}
functiongetAddress(bytes32 key) publicviewreturns (address) {
return _addressStorage[key];
}
functiongetBytes(bytes32 key) publicviewreturns (bytesmemory) {
return _bytesStorage[key];
}
functiongetBool(bytes32 key) publicviewreturns (bool) {
return _boolStorage[key];
}
functiongetInt(bytes32 key) publicviewreturns (int256) {
return _intStorage[key];
}
// *** Setter Methods ***function_setUint(bytes32 key, uint256 value) internal{
_uintStorage[key] = value;
}
function_setString(bytes32 key, stringmemory value) internal{
_stringStorage[key] = value;
}
function_setAddress(bytes32 key, address value) internal{
_addressStorage[key] = value;
}
function_setBytes(bytes32 key, bytesmemory 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;
}
// *** Delete Methods ***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];
}
}
// Dependency file: src/BurnableMintableCappedERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { ERC20 } from 'src/ERC20.sol';// import { Ownable } from 'src/Ownable.sol';// import { Burner } from 'src/Burner.sol';// import { EternalStorage } from 'src/EternalStorage.sol';contractBurnableMintableCappedERC20isERC20, Ownable{
uint256public cap;
bytes32privateconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32privateconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
eventFrozen(addressindexed owner);
eventUnfrozen(addressindexed owner);
constructor(stringmemory name,
stringmemory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
functiondepositAddress(bytes32 salt) publicviewreturns (address) {
// This would be easier, cheaper, simpler, and result in globally consistent deposit addresses for any salt (all chains, all tokens).// return address(uint160(uint256(keccak256(abi.encodePacked(bytes32(0x000000000000000000000000000000000000000000000000000000000000dead), salt)))));/* Convert a hash which is bytes32 to an address which is 20-byte long
according to https://docs.soliditylang.org/en/v0.8.1/control-structures.html?highlight=create2#salted-contract-creations-create2 */returnaddress(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
functionmint(address account, uint256 amount) publiconlyOwner{
uint256 capacity = cap;
require(capacity ==0|| totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
functionburn(bytes32 salt) publiconlyOwner{
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function_beforeTokenTransfer(address,
address,
uint256) internalviewoverride{
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
// Dependency file: src/AdminMultisigBase.sol// pragma solidity >=0.8.0 <0.9.0;// import { EternalStorage } from 'src/EternalStorage.sol';contractAdminMultisigBaseisEternalStorage{
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_ADMIN_EPOCH =keccak256('admin-epoch');
bytes32internalconstant PREFIX_ADMIN =keccak256('admin');
bytes32internalconstant PREFIX_ADMIN_COUNT =keccak256('admin-count');
bytes32internalconstant PREFIX_ADMIN_THRESHOLD =keccak256('admin-threshold');
bytes32internalconstant PREFIX_ADMIN_VOTE_COUNTS =keccak256('admin-vote-counts');
bytes32internalconstant PREFIX_ADMIN_VOTED =keccak256('admin-voted');
bytes32internalconstant PREFIX_IS_ADMIN =keccak256('is-admin');
modifieronlyAdmin() {
uint256 adminEpoch = _adminEpoch();
require(_isAdmin(adminEpoch, msg.sender), 'NOT_ADMIN');
bytes32 topic =keccak256(msg.data);
// Check that admin has not voted, then record that they have voted.require(!_hasVoted(adminEpoch, topic, msg.sender), 'VOTED');
_setHasVoted(adminEpoch, topic, msg.sender, true);
// Determine the new vote count and update it.uint256 adminVoteCount = _getVoteCount(adminEpoch, topic) +uint256(1);
_setVoteCount(adminEpoch, topic, adminVoteCount);
// Do not proceed with operation execution if insufficient votes.if (adminVoteCount < _getAdminThreshold(adminEpoch)) return;
_;
// Clear vote count and voted booleans.
_setVoteCount(adminEpoch, topic, uint256(0));
uint256 adminCount = _getAdminCount(adminEpoch);
for (uint256 i; i < adminCount; i++) {
_setHasVoted(adminEpoch, topic, _getAdmin(adminEpoch, i), false);
}
}
/********************\
|* Pure Key Getters *|
\********************/function_getAdminKey(uint256 adminEpoch, uint256 index) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN, adminEpoch, index));
}
function_getAdminCountKey(uint256 adminEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_COUNT, adminEpoch));
}
function_getAdminThresholdKey(uint256 adminEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_THRESHOLD, adminEpoch));
}
function_getAdminVoteCountsKey(uint256 adminEpoch, bytes32 topic) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_VOTE_COUNTS, adminEpoch, topic));
}
function_getAdminVotedKey(uint256 adminEpoch,
bytes32 topic,
address account
) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_VOTED, adminEpoch, topic, account));
}
function_getIsAdminKey(uint256 adminEpoch, address account) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_IS_ADMIN, adminEpoch, account));
}
/***********\
|* Getters *|
\***********/function_adminEpoch() internalviewreturns (uint256) {
return getUint(KEY_ADMIN_EPOCH);
}
function_getAdmin(uint256 adminEpoch, uint256 index) internalviewreturns (address) {
return getAddress(_getAdminKey(adminEpoch, index));
}
function_getAdminCount(uint256 adminEpoch) internalviewreturns (uint256) {
return getUint(_getAdminCountKey(adminEpoch));
}
function_getAdminThreshold(uint256 adminEpoch) internalviewreturns (uint256) {
return getUint(_getAdminThresholdKey(adminEpoch));
}
function_getVoteCount(uint256 adminEpoch, bytes32 topic) internalviewreturns (uint256) {
return getUint(_getAdminVoteCountsKey(adminEpoch, topic));
}
function_hasVoted(uint256 adminEpoch,
bytes32 topic,
address account
) internalviewreturns (bool) {
return getBool(_getAdminVotedKey(adminEpoch, topic, account));
}
function_isAdmin(uint256 adminEpoch, address account) internalviewreturns (bool) {
return getBool(_getIsAdminKey(adminEpoch, account));
}
/***********\
|* Setters *|
\***********/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];
// Check that the account wasn't already set as an admin for this epoch.require(!_isAdmin(adminEpoch, account), 'DUP_ADMIN');
// Set this account as the i-th admin in this epoch (needed to we can clear topic votes in `onlyAdmin`).
_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);
}
}
// Dependency file: src/AxelarGateway.sol// pragma solidity >=0.8.0 <0.9.0;// import { IAxelarGateway } from 'src/interfaces/IAxelarGateway.sol';// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';// import { AdminMultisigBase } from 'src/AdminMultisigBase.sol';abstractcontractAxelarGatewayisIAxelarGateway, AdminMultisigBase{
/// @dev Storage slot with the address of the current factory. `keccak256('eip1967.proxy.implementation') - 1`.bytes32internalconstant KEY_IMPLEMENTATION =bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
bytes32internalconstant PREFIX_COMMAND_EXECUTED =keccak256('command-executed');
bytes32internalconstant PREFIX_TOKEN_ADDRESS =keccak256('token-address');
bytes32internalconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32internalconstant SELECTOR_BURN_TOKEN =keccak256('burnToken');
bytes32internalconstant SELECTOR_DEPLOY_TOKEN =keccak256('deployToken');
bytes32internalconstant SELECTOR_MINT_TOKEN =keccak256('mintToken');
bytes32internalconstant SELECTOR_TRANSFER_OPERATORSHIP =keccak256('transferOperatorship');
bytes32internalconstant SELECTOR_TRANSFER_OWNERSHIP =keccak256('transferOwnership');
uint8internalconstant OLD_KEY_RETENTION =16;
modifieronlySelf() {
require(msg.sender==address(this), 'NOT_SELF');
_;
}
/***********\
|* Getters *|
\***********/functionallTokensFrozen() publicviewoverridereturns (bool) {
return getBool(KEY_ALL_TOKENS_FROZEN);
}
functionimplementation() publicviewoverridereturns (address) {
return getAddress(KEY_IMPLEMENTATION);
}
functiontokenAddresses(stringmemory symbol) publicviewoverridereturns (address) {
return getAddress(_getTokenAddressKey(symbol));
}
functiontokenFrozen(stringmemory symbol) publicviewoverridereturns (bool) {
return getBool(_getFreezeTokenKey(symbol));
}
functionisCommandExecuted(bytes32 commandId) publicviewoverridereturns (bool) {
return getBool(_getIsCommandExecutedKey(commandId));
}
/*******************\
|* Admin Functions *|
\*******************/functionfreezeToken(stringmemory symbol) externaloverrideonlyAdmin{
_setBool(_getFreezeTokenKey(symbol), true);
emit TokenFrozen(symbol);
}
functionunfreezeToken(stringmemory symbol) externaloverrideonlyAdmin{
_setBool(_getFreezeTokenKey(symbol), false);
emit TokenUnfrozen(symbol);
}
functionfreezeAllTokens() externaloverrideonlyAdmin{
_setBool(KEY_ALL_TOKENS_FROZEN, true);
emit AllTokensFrozen();
}
functionunfreezeAllTokens() externaloverrideonlyAdmin{
_setBool(KEY_ALL_TOKENS_FROZEN, false);
emit AllTokensUnfrozen();
}
functionupgrade(address newImplementation, bytescalldata setupParams) externaloverrideonlyAdmin{
emit Upgraded(newImplementation);
// AUDIT: If `newImplementation.setup` performs `selfdestruct`, it will result in the loss of _this_ implementation (thereby losing the gateway)// if `upgrade` is entered within the context of _this_ implementation itself.
(bool success, ) = newImplementation.delegatecall(
abi.encodeWithSelector(IAxelarGateway.setup.selector, setupParams)
);
require(success, 'SETUP_FAILED');
_setImplementation(newImplementation);
}
/**********************\
|* Internal Functions *|
\**********************/function_deployToken(stringmemory name,
stringmemory 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(stringmemory symbol,
address account,
uint256 amount
) internal{
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress !=address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).mint(account, amount);
}
function_burnToken(stringmemory symbol, bytes32 salt) internal{
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress !=address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).burn(salt);
}
/********************\
|* Pure Key Getters *|
\********************/function_getFreezeTokenKey(stringmemory symbol) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol));
}
function_getTokenAddressKey(stringmemory symbol) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_TOKEN_ADDRESS, symbol));
}
function_getIsCommandExecutedKey(bytes32 commandId) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_COMMAND_EXECUTED, commandId));
}
/********************\
|* Internal Getters *|
\********************/function_getChainID() internalviewreturns (uint256 id) {
assembly {
id :=chainid()
}
}
/********************\
|* Internal Setters *|
\********************/function_setTokenAddress(stringmemory 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);
}
}
// Root file: src/AxelarGatewayMultisig.solpragmasolidity >=0.8.0 <0.9.0;// import { IAxelarGatewayMultisig } from 'src/interfaces/IAxelarGatewayMultisig.sol';// import { ECDSA } from 'src/ECDSA.sol';// import { AxelarGateway } from 'src/AxelarGateway.sol';contractAxelarGatewayMultisigisIAxelarGatewayMultisig, AxelarGateway{
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_OWNER_EPOCH =keccak256('owner-epoch');
bytes32internalconstant PREFIX_OWNER =keccak256('owner');
bytes32internalconstant PREFIX_OWNER_COUNT =keccak256('owner-count');
bytes32internalconstant PREFIX_OWNER_THRESHOLD =keccak256('owner-threshold');
bytes32internalconstant PREFIX_IS_OWNER =keccak256('is-owner');
bytes32internalconstant KEY_OPERATOR_EPOCH =keccak256('operator-epoch');
bytes32internalconstant PREFIX_OPERATOR =keccak256('operator');
bytes32internalconstant PREFIX_OPERATOR_COUNT =keccak256('operator-count');
bytes32internalconstant PREFIX_OPERATOR_THRESHOLD =keccak256('operator-threshold');
bytes32internalconstant PREFIX_IS_OPERATOR =keccak256('is-operator');
function_containsDuplicates(address[] memory accounts) internalpurereturns (bool) {
uint256 count = accounts.length;
for (uint256 i; i < count; ++i) {
for (uint256 j = i +1; j < count; ++j) {
if (accounts[i] == accounts[j]) returntrue;
}
}
returnfalse;
}
/************************\
|* Owners Functionality *|
\************************//********************\
|* Pure Key Getters *|
\********************/function_getOwnerKey(uint256 ownerEpoch, uint256 index) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OWNER, ownerEpoch, index));
}
function_getOwnerCountKey(uint256 ownerEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OWNER_COUNT, ownerEpoch));
}
function_getOwnerThresholdKey(uint256 ownerEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OWNER_THRESHOLD, ownerEpoch));
}
function_getIsOwnerKey(uint256 ownerEpoch, address account) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_IS_OWNER, ownerEpoch, account));
}
/***********\
|* Getters *|
\***********/function_ownerEpoch() internalviewreturns (uint256) {
return getUint(KEY_OWNER_EPOCH);
}
function_getOwner(uint256 ownerEpoch, uint256 index) internalviewreturns (address) {
return getAddress(_getOwnerKey(ownerEpoch, index));
}
function_getOwnerCount(uint256 ownerEpoch) internalviewreturns (uint256) {
return getUint(_getOwnerCountKey(ownerEpoch));
}
function_getOwnerThreshold(uint256 ownerEpoch) internalviewreturns (uint256) {
return getUint(_getOwnerThresholdKey(ownerEpoch));
}
function_isOwner(uint256 ownerEpoch, address account) internalviewreturns (bool) {
return getBool(_getIsOwnerKey(ownerEpoch, account));
}
/// @dev Returns true if a sufficient quantity of `accounts` are owners in the same `ownerEpoch`, within the last `OLD_KEY_RETENTION + 1` owner epochs.function_areValidRecentOwners(address[] memory accounts) internalviewreturns (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)) returntrue;
}
returnfalse;
}
/// @dev Returns true if a sufficient quantity of `accounts` are owners in the `ownerEpoch`.function_areValidOwnersInEpoch(uint256 ownerEpoch, address[] memory accounts) internalviewreturns (bool) {
if (_containsDuplicates(accounts)) returnfalse;
uint256 threshold = _getOwnerThreshold(ownerEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOwner(ownerEpoch, accounts[i]) &&++validSignerCount >= threshold) returntrue;
}
returnfalse;
}
/// @dev Returns the array of owners within the current `ownerEpoch`.functionowners() publicviewoverridereturns (address[] memory results) {
uint256 ownerEpoch = _ownerEpoch();
uint256 ownerCount = _getOwnerCount(ownerEpoch);
results =newaddress[](ownerCount);
for (uint256 i; i < ownerCount; i++) {
results[i] = _getOwner(ownerEpoch, i);
}
}
/***********\
|* Setters *|
\***********/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];
// Check that the account wasn't already set as an owner for this ownerEpoch.require(!_isOwner(ownerEpoch, account), 'DUP_OWNER');
// Set this account as the i-th owner in this ownerEpoch (needed to we can get all the owners for `owners`).
_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);
}
/**************************\
|* Operator Functionality *|
\**************************//********************\
|* Pure Key Getters *|
\********************/function_getOperatorKey(uint256 operatorEpoch, uint256 index) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OPERATOR, operatorEpoch, index));
}
function_getOperatorCountKey(uint256 operatorEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OPERATOR_COUNT, operatorEpoch));
}
function_getOperatorThresholdKey(uint256 operatorEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OPERATOR_THRESHOLD, operatorEpoch));
}
function_getIsOperatorKey(uint256 operatorEpoch, address account) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_IS_OPERATOR, operatorEpoch, account));
}
/***********\
|* Getters *|
\***********/function_operatorEpoch() internalviewreturns (uint256) {
return getUint(KEY_OPERATOR_EPOCH);
}
function_getOperator(uint256 operatorEpoch, uint256 index) internalviewreturns (address) {
return getAddress(_getOperatorKey(operatorEpoch, index));
}
function_getOperatorCount(uint256 operatorEpoch) internalviewreturns (uint256) {
return getUint(_getOperatorCountKey(operatorEpoch));
}
function_getOperatorThreshold(uint256 operatorEpoch) internalviewreturns (uint256) {
return getUint(_getOperatorThresholdKey(operatorEpoch));
}
function_isOperator(uint256 operatorEpoch, address account) internalviewreturns (bool) {
return getBool(_getIsOperatorKey(operatorEpoch, account));
}
/// @dev Returns true if a sufficient quantity of `accounts` are operator in the same `operatorEpoch`, within the last `OLD_KEY_RETENTION + 1` operator epochs.function_areValidRecentOperators(address[] memory accounts) internalviewreturns (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)) returntrue;
}
returnfalse;
}
/// @dev Returns true if a sufficient quantity of `accounts` are operator in the `operatorEpoch`.function_areValidOperatorsInEpoch(uint256 operatorEpoch, address[] memory accounts) internalviewreturns (bool) {
if (_containsDuplicates(accounts)) returnfalse;
uint256 threshold = _getOperatorThreshold(operatorEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOperator(operatorEpoch, accounts[i]) &&++validSignerCount >= threshold) returntrue;
}
returnfalse;
}
/// @dev Returns the array of operators within the current `operatorEpoch`.functionoperators() publicviewoverridereturns (address[] memory results) {
uint256 operatorEpoch = _operatorEpoch();
uint256 operatorCount = _getOperatorCount(operatorEpoch);
results =newaddress[](operatorCount);
for (uint256 i; i < operatorCount; i++) {
results[i] = _getOperator(operatorEpoch, i);
}
}
/***********\
|* Setters *|
\***********/function_setOperatorEpoch(uint256 operatorEpoch) internal{
_setUint(KEY_OPERATOR_EPOCH, operatorEpoch);
}
function_setOperator(uint256 operatorEpoch,
uint256 index,
address account
) internal{
// AUDIT: Should have `require(account != address(0), 'ZERO_ADDR');` like Singlesig?
_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];
// Check that the account wasn't already set as an operator for this operatorEpoch.require(!_isOperator(operatorEpoch, account), 'DUP_OPERATOR');
// Set this account as the i-th operator in this operatorEpoch (needed to we can get all the operators for `operators`).
_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);
}
/**********************\
|* Self Functionality *|
\**********************/functiondeployToken(bytescalldata params) externalonlySelf{
(stringmemory name, stringmemory symbol, uint8 decimals, uint256 cap) =abi.decode(
params,
(string, string, uint8, uint256)
);
_deployToken(name, symbol, decimals, cap);
}
functionmintToken(bytescalldata params) externalonlySelf{
(stringmemory symbol, address account, uint256 amount) =abi.decode(params, (string, address, uint256));
_mintToken(symbol, account, amount);
}
functionburnToken(bytescalldata params) externalonlySelf{
(stringmemory symbol, bytes32 salt) =abi.decode(params, (string, bytes32));
_burnToken(symbol, salt);
}
functiontransferOwnership(bytescalldata params) externalonlySelf{
(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);
}
functiontransferOperatorship(bytescalldata params) externalonlySelf{
(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);
}
/**************************\
|* External Functionality *|
\**************************/functionsetup(bytescalldata params) externaloverride{
// Prevent setup from being called on a non-proxy (the implementation).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(newaddress[](uint256(0)), uint256(0), ownerAddresses, ownerThreshold);
emit OperatorshipTransferred(newaddress[](uint256(0)), uint256(0), operatorAddresses, operatorThreshold);
}
functionexecute(bytescalldata input) externaloverride{
(bytesmemory data, bytes[] memory signatures) =abi.decode(input, (bytes, bytes[]));
_execute(data, signatures);
}
function_execute(bytesmemory data, bytes[] memory signatures) internal{
uint256 signatureCount = signatures.length;
address[] memory signers =newaddress[](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; /* Ignore if duplicate commandId received */bytes4 commandSelector;
bytes32 commandHash =keccak256(abi.encodePacked(commands[i]));
if (commandHash == SELECTOR_DEPLOY_TOKEN) {
if (!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.deployToken.selector;
} elseif (commandHash == SELECTOR_MINT_TOKEN) {
if (!areValidRecentOperators &&!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.mintToken.selector;
} elseif (commandHash == SELECTOR_BURN_TOKEN) {
if (!areValidRecentOperators &&!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.burnToken.selector;
} elseif (commandHash == SELECTOR_TRANSFER_OWNERSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOwnership.selector;
} elseif (commandHash == SELECTOR_TRANSFER_OPERATORSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOperatorship.selector;
} else {
continue; /* Ignore if unknown command received */
}
// Prevent a re-entrancy from executing this command before it can be marked as successful.
_setCommandExecuted(commandId, true);
(bool success, ) =address(this).call(abi.encodeWithSelector(commandSelector, params[i]));
_setCommandExecuted(commandId, success);
if (success) {
emit Executed(commandId);
}
}
}
}
// Dependency file: src/interfaces/IAxelarGateway.sol// SPDX-License-Identifier: MIT// pragma solidity >=0.8.0 <0.9.0;interfaceIAxelarGateway{
/**********\
|* Events *|
\**********/eventExecuted(bytes32indexed commandId);
eventTokenDeployed(string symbol, address tokenAddresses);
eventTokenFrozen(stringindexed symbol);
eventTokenUnfrozen(stringindexed symbol);
eventAllTokensFrozen();
eventAllTokensUnfrozen();
eventAccountBlacklisted(addressindexed account);
eventAccountWhitelisted(addressindexed account);
eventUpgraded(addressindexed implementation);
/***********\
|* Getters *|
\***********/functionallTokensFrozen() externalviewreturns (bool);
functionimplementation() externalviewreturns (address);
functiontokenAddresses(stringmemory symbol) externalviewreturns (address);
functiontokenFrozen(stringmemory symbol) externalviewreturns (bool);
functionisCommandExecuted(bytes32 commandId) externalviewreturns (bool);
/*******************\
|* Admin Functions *|
\*******************/functionfreezeToken(stringmemory symbol) external;
functionunfreezeToken(stringmemory symbol) external;
functionfreezeAllTokens() external;
functionunfreezeAllTokens() external;
functionupgrade(address newImplementation, bytescalldata setupParams) external;
/**********************\
|* External Functions *|
\**********************/functionsetup(bytescalldata params) external;
functionexecute(bytescalldata input) external;
}
// Dependency file: src/EternalStorage.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @title EternalStorage
* @dev This contract holds all the necessary state variables to carry out the storage of any contract.
*/contractEternalStorage{
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;
// *** Getter Methods ***functiongetUint(bytes32 key) publicviewreturns (uint256) {
return _uintStorage[key];
}
functiongetString(bytes32 key) publicviewreturns (stringmemory) {
return _stringStorage[key];
}
functiongetAddress(bytes32 key) publicviewreturns (address) {
return _addressStorage[key];
}
functiongetBytes(bytes32 key) publicviewreturns (bytesmemory) {
return _bytesStorage[key];
}
functiongetBool(bytes32 key) publicviewreturns (bool) {
return _boolStorage[key];
}
functiongetInt(bytes32 key) publicviewreturns (int256) {
return _intStorage[key];
}
// *** Setter Methods ***function_setUint(bytes32 key, uint256 value) internal{
_uintStorage[key] = value;
}
function_setString(bytes32 key, stringmemory value) internal{
_stringStorage[key] = value;
}
function_setAddress(bytes32 key, address value) internal{
_addressStorage[key] = value;
}
function_setBytes(bytes32 key, bytesmemory 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;
}
// *** Delete Methods ***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];
}
}
// Dependency file: src/AxelarGatewayProxy.sol// pragma solidity >=0.8.0 <0.9.0;// import { EternalStorage } from 'src/EternalStorage.sol';contractAxelarGatewayProxyisEternalStorage{
/// @dev Storage slot with the address of the current factory. `keccak256('eip1967.proxy.implementation') - 1`.bytes32internalconstant KEY_IMPLEMENTATION =bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
fallback() externalpayable{
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
case0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() externalpayable{
revert('NO_ETHER');
}
}
// Dependency file: src/interfaces/IAxelarGatewayMultisig.sol// pragma solidity >=0.8.0 <0.9.0;// import { IAxelarGateway } from 'src/interfaces/IAxelarGateway.sol';interfaceIAxelarGatewayMultisigisIAxelarGateway{
eventOwnershipTransferred(address[] preOwners, uint256 prevThreshold, address[] newOwners, uint256 newThreshold);
eventOperatorshipTransferred(address[] preOperators, uint256 prevThreshold, address[] newOperators, uint256 newThreshold);
functionowners() externalviewreturns (address[] memory);
functionoperators() externalviewreturns (address[] memory);
}
// Dependency file: src/ECDSA.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/libraryECDSA{
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/functionrecover(bytes32 hash, bytesmemory signature) internalpurereturns (address signer) {
// Check the signature lengthrequire(signature.length==65, 'INV_LEN');
// Divide the signature in r, s and v variablesbytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them// currently is to use assembly.// solhint-disable-next-line no-inline-assemblyassembly {
r :=mload(add(signature, 0x20))
s :=mload(add(signature, 0x40))
v :=byte(0, mload(add(signature, 0x60)))
}
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most// signatures from current libraries generate a unique signature with an s-value in the lower half order.//// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept// these malleable signatures as well.require(uint256(s) <=0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, 'INV_S');
require(v ==27|| v ==28, 'INV_V');
// If the signature is valid (and not malleable), return the signer addressrequire((signer =ecrecover(hash, v, r, s)) !=address(0), 'INV_SIG');
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* replicates the behavior of the
* https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
* JSON-RPC method.
*
* See {recover}.
*/functiontoEthSignedMessageHash(bytes32 hash) internalpurereturns (bytes32) {
// 32 is the length in bytes of hash,// enforced by the type signature abovereturnkeccak256(abi.encodePacked('\x19Ethereum Signed Message:\n32', hash));
}
}
// Dependency file: src/interfaces/IERC20.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
// Dependency file: src/Context.sol// pragma solidity >=0.8.0 <0.9.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnpayable(msg.sender);
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
// Dependency file: src/ERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { IERC20 } from 'src/interfaces/IERC20.sol';// import { Context } from 'src/Context.sol';/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20{
mapping(address=>uint256) publicoverride balanceOf;
mapping(address=>mapping(address=>uint256)) publicoverride allowance;
uint256publicoverride totalSupply;
stringpublic name;
stringpublic symbol;
uint8publicimmutable decimals;
/**
* @dev Sets the values for {name}, {symbol}, and {decimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_,
stringmemory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtual{
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner,
address spender,
uint256 amount
) internalvirtual{
require(owner !=address(0), 'ZERO_ADDR');
require(spender !=address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
// Dependency file: src/Ownable.sol// pragma solidity >=0.8.0 <0.9.0;abstractcontractOwnable{
addresspublic owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
constructor() {
owner =msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifieronlyOwner() {
require(owner ==msg.sender, 'NOT_OWNER');
_;
}
functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// Dependency file: src/Burner.sol// pragma solidity >=0.8.0 <0.9.0;// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';contractBurner{
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
// Dependency file: src/BurnableMintableCappedERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { ERC20 } from 'src/ERC20.sol';// import { Ownable } from 'src/Ownable.sol';// import { Burner } from 'src/Burner.sol';// import { EternalStorage } from 'src/EternalStorage.sol';contractBurnableMintableCappedERC20isERC20, Ownable{
uint256public cap;
bytes32privateconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32privateconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
eventFrozen(addressindexed owner);
eventUnfrozen(addressindexed owner);
constructor(stringmemory name,
stringmemory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
functiondepositAddress(bytes32 salt) publicviewreturns (address) {
// This would be easier, cheaper, simpler, and result in globally consistent deposit addresses for any salt (all chains, all tokens).// return address(uint160(uint256(keccak256(abi.encodePacked(bytes32(0x000000000000000000000000000000000000000000000000000000000000dead), salt)))));/* Convert a hash which is bytes32 to an address which is 20-byte long
according to https://docs.soliditylang.org/en/v0.8.1/control-structures.html?highlight=create2#salted-contract-creations-create2 */returnaddress(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
functionmint(address account, uint256 amount) publiconlyOwner{
uint256 capacity = cap;
require(capacity ==0|| totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
functionburn(bytes32 salt) publiconlyOwner{
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function_beforeTokenTransfer(address,
address,
uint256) internalviewoverride{
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
// Dependency file: src/AdminMultisigBase.sol// pragma solidity >=0.8.0 <0.9.0;// import { EternalStorage } from 'src/EternalStorage.sol';contractAdminMultisigBaseisEternalStorage{
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_ADMIN_EPOCH =keccak256('admin-epoch');
bytes32internalconstant PREFIX_ADMIN =keccak256('admin');
bytes32internalconstant PREFIX_ADMIN_COUNT =keccak256('admin-count');
bytes32internalconstant PREFIX_ADMIN_THRESHOLD =keccak256('admin-threshold');
bytes32internalconstant PREFIX_ADMIN_VOTE_COUNTS =keccak256('admin-vote-counts');
bytes32internalconstant PREFIX_ADMIN_VOTED =keccak256('admin-voted');
bytes32internalconstant PREFIX_IS_ADMIN =keccak256('is-admin');
modifieronlyAdmin() {
uint256 adminEpoch = _adminEpoch();
require(_isAdmin(adminEpoch, msg.sender), 'NOT_ADMIN');
bytes32 topic =keccak256(msg.data);
// Check that admin has not voted, then record that they have voted.require(!_hasVoted(adminEpoch, topic, msg.sender), 'VOTED');
_setHasVoted(adminEpoch, topic, msg.sender, true);
// Determine the new vote count and update it.uint256 adminVoteCount = _getVoteCount(adminEpoch, topic) +uint256(1);
_setVoteCount(adminEpoch, topic, adminVoteCount);
// Do not proceed with operation execution if insufficient votes.if (adminVoteCount < _getAdminThreshold(adminEpoch)) return;
_;
// Clear vote count and voted booleans.
_setVoteCount(adminEpoch, topic, uint256(0));
uint256 adminCount = _getAdminCount(adminEpoch);
for (uint256 i; i < adminCount; i++) {
_setHasVoted(adminEpoch, topic, _getAdmin(adminEpoch, i), false);
}
}
/********************\
|* Pure Key Getters *|
\********************/function_getAdminKey(uint256 adminEpoch, uint256 index) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN, adminEpoch, index));
}
function_getAdminCountKey(uint256 adminEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_COUNT, adminEpoch));
}
function_getAdminThresholdKey(uint256 adminEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_THRESHOLD, adminEpoch));
}
function_getAdminVoteCountsKey(uint256 adminEpoch, bytes32 topic) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_VOTE_COUNTS, adminEpoch, topic));
}
function_getAdminVotedKey(uint256 adminEpoch,
bytes32 topic,
address account
) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_ADMIN_VOTED, adminEpoch, topic, account));
}
function_getIsAdminKey(uint256 adminEpoch, address account) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_IS_ADMIN, adminEpoch, account));
}
/***********\
|* Getters *|
\***********/function_adminEpoch() internalviewreturns (uint256) {
return getUint(KEY_ADMIN_EPOCH);
}
function_getAdmin(uint256 adminEpoch, uint256 index) internalviewreturns (address) {
return getAddress(_getAdminKey(adminEpoch, index));
}
function_getAdminCount(uint256 adminEpoch) internalviewreturns (uint256) {
return getUint(_getAdminCountKey(adminEpoch));
}
function_getAdminThreshold(uint256 adminEpoch) internalviewreturns (uint256) {
return getUint(_getAdminThresholdKey(adminEpoch));
}
function_getVoteCount(uint256 adminEpoch, bytes32 topic) internalviewreturns (uint256) {
return getUint(_getAdminVoteCountsKey(adminEpoch, topic));
}
function_hasVoted(uint256 adminEpoch,
bytes32 topic,
address account
) internalviewreturns (bool) {
return getBool(_getAdminVotedKey(adminEpoch, topic, account));
}
function_isAdmin(uint256 adminEpoch, address account) internalviewreturns (bool) {
return getBool(_getIsAdminKey(adminEpoch, account));
}
/***********\
|* Setters *|
\***********/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];
// Check that the account wasn't already set as an admin for this epoch.require(!_isAdmin(adminEpoch, account), 'DUP_ADMIN');
// Set this account as the i-th admin in this epoch (needed to we can clear topic votes in `onlyAdmin`).
_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);
}
}
// Dependency file: src/AxelarGateway.sol// pragma solidity >=0.8.0 <0.9.0;// import { IAxelarGateway } from 'src/interfaces/IAxelarGateway.sol';// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';// import { AdminMultisigBase } from 'src/AdminMultisigBase.sol';abstractcontractAxelarGatewayisIAxelarGateway, AdminMultisigBase{
/// @dev Storage slot with the address of the current factory. `keccak256('eip1967.proxy.implementation') - 1`.bytes32internalconstant KEY_IMPLEMENTATION =bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
bytes32internalconstant PREFIX_COMMAND_EXECUTED =keccak256('command-executed');
bytes32internalconstant PREFIX_TOKEN_ADDRESS =keccak256('token-address');
bytes32internalconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32internalconstant SELECTOR_BURN_TOKEN =keccak256('burnToken');
bytes32internalconstant SELECTOR_DEPLOY_TOKEN =keccak256('deployToken');
bytes32internalconstant SELECTOR_MINT_TOKEN =keccak256('mintToken');
bytes32internalconstant SELECTOR_TRANSFER_OPERATORSHIP =keccak256('transferOperatorship');
bytes32internalconstant SELECTOR_TRANSFER_OWNERSHIP =keccak256('transferOwnership');
uint8internalconstant OLD_KEY_RETENTION =16;
modifieronlySelf() {
require(msg.sender==address(this), 'NOT_SELF');
_;
}
/***********\
|* Getters *|
\***********/functionallTokensFrozen() publicviewoverridereturns (bool) {
return getBool(KEY_ALL_TOKENS_FROZEN);
}
functionimplementation() publicviewoverridereturns (address) {
return getAddress(KEY_IMPLEMENTATION);
}
functiontokenAddresses(stringmemory symbol) publicviewoverridereturns (address) {
return getAddress(_getTokenAddressKey(symbol));
}
functiontokenFrozen(stringmemory symbol) publicviewoverridereturns (bool) {
return getBool(_getFreezeTokenKey(symbol));
}
functionisCommandExecuted(bytes32 commandId) publicviewoverridereturns (bool) {
return getBool(_getIsCommandExecutedKey(commandId));
}
/*******************\
|* Admin Functions *|
\*******************/functionfreezeToken(stringmemory symbol) externaloverrideonlyAdmin{
_setBool(_getFreezeTokenKey(symbol), true);
emit TokenFrozen(symbol);
}
functionunfreezeToken(stringmemory symbol) externaloverrideonlyAdmin{
_setBool(_getFreezeTokenKey(symbol), false);
emit TokenUnfrozen(symbol);
}
functionfreezeAllTokens() externaloverrideonlyAdmin{
_setBool(KEY_ALL_TOKENS_FROZEN, true);
emit AllTokensFrozen();
}
functionunfreezeAllTokens() externaloverrideonlyAdmin{
_setBool(KEY_ALL_TOKENS_FROZEN, false);
emit AllTokensUnfrozen();
}
functionupgrade(address newImplementation, bytescalldata setupParams) externaloverrideonlyAdmin{
emit Upgraded(newImplementation);
// AUDIT: If `newImplementation.setup` performs `selfdestruct`, it will result in the loss of _this_ implementation (thereby losing the gateway)// if `upgrade` is entered within the context of _this_ implementation itself.
(bool success, ) = newImplementation.delegatecall(
abi.encodeWithSelector(IAxelarGateway.setup.selector, setupParams)
);
require(success, 'SETUP_FAILED');
_setImplementation(newImplementation);
}
/**********************\
|* Internal Functions *|
\**********************/function_deployToken(stringmemory name,
stringmemory 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(stringmemory symbol,
address account,
uint256 amount
) internal{
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress !=address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).mint(account, amount);
}
function_burnToken(stringmemory symbol, bytes32 salt) internal{
address tokenAddress = tokenAddresses(symbol);
require(tokenAddress !=address(0), 'TOKEN_NOT_EXIST');
BurnableMintableCappedERC20(tokenAddress).burn(salt);
}
/********************\
|* Pure Key Getters *|
\********************/function_getFreezeTokenKey(stringmemory symbol) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol));
}
function_getTokenAddressKey(stringmemory symbol) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_TOKEN_ADDRESS, symbol));
}
function_getIsCommandExecutedKey(bytes32 commandId) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_COMMAND_EXECUTED, commandId));
}
/********************\
|* Internal Getters *|
\********************/function_getChainID() internalviewreturns (uint256 id) {
assembly {
id :=chainid()
}
}
/********************\
|* Internal Setters *|
\********************/function_setTokenAddress(stringmemory 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);
}
}
// Dependency file: src/AxelarGatewayMultisig.sol// pragma solidity >=0.8.0 <0.9.0;// import { IAxelarGatewayMultisig } from 'src/interfaces/IAxelarGatewayMultisig.sol';// import { ECDSA } from 'src/ECDSA.sol';// import { AxelarGateway } from 'src/AxelarGateway.sol';contractAxelarGatewayMultisigisIAxelarGatewayMultisig, AxelarGateway{
// AUDIT: slot names should be prefixed with some standard string// AUDIT: constants should be literal and their derivation should be in commentsbytes32internalconstant KEY_OWNER_EPOCH =keccak256('owner-epoch');
bytes32internalconstant PREFIX_OWNER =keccak256('owner');
bytes32internalconstant PREFIX_OWNER_COUNT =keccak256('owner-count');
bytes32internalconstant PREFIX_OWNER_THRESHOLD =keccak256('owner-threshold');
bytes32internalconstant PREFIX_IS_OWNER =keccak256('is-owner');
bytes32internalconstant KEY_OPERATOR_EPOCH =keccak256('operator-epoch');
bytes32internalconstant PREFIX_OPERATOR =keccak256('operator');
bytes32internalconstant PREFIX_OPERATOR_COUNT =keccak256('operator-count');
bytes32internalconstant PREFIX_OPERATOR_THRESHOLD =keccak256('operator-threshold');
bytes32internalconstant PREFIX_IS_OPERATOR =keccak256('is-operator');
function_containsDuplicates(address[] memory accounts) internalpurereturns (bool) {
uint256 count = accounts.length;
for (uint256 i; i < count; ++i) {
for (uint256 j = i +1; j < count; ++j) {
if (accounts[i] == accounts[j]) returntrue;
}
}
returnfalse;
}
/************************\
|* Owners Functionality *|
\************************//********************\
|* Pure Key Getters *|
\********************/function_getOwnerKey(uint256 ownerEpoch, uint256 index) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OWNER, ownerEpoch, index));
}
function_getOwnerCountKey(uint256 ownerEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OWNER_COUNT, ownerEpoch));
}
function_getOwnerThresholdKey(uint256 ownerEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OWNER_THRESHOLD, ownerEpoch));
}
function_getIsOwnerKey(uint256 ownerEpoch, address account) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_IS_OWNER, ownerEpoch, account));
}
/***********\
|* Getters *|
\***********/function_ownerEpoch() internalviewreturns (uint256) {
return getUint(KEY_OWNER_EPOCH);
}
function_getOwner(uint256 ownerEpoch, uint256 index) internalviewreturns (address) {
return getAddress(_getOwnerKey(ownerEpoch, index));
}
function_getOwnerCount(uint256 ownerEpoch) internalviewreturns (uint256) {
return getUint(_getOwnerCountKey(ownerEpoch));
}
function_getOwnerThreshold(uint256 ownerEpoch) internalviewreturns (uint256) {
return getUint(_getOwnerThresholdKey(ownerEpoch));
}
function_isOwner(uint256 ownerEpoch, address account) internalviewreturns (bool) {
return getBool(_getIsOwnerKey(ownerEpoch, account));
}
/// @dev Returns true if a sufficient quantity of `accounts` are owners in the same `ownerEpoch`, within the last `OLD_KEY_RETENTION + 1` owner epochs.function_areValidRecentOwners(address[] memory accounts) internalviewreturns (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)) returntrue;
}
returnfalse;
}
/// @dev Returns true if a sufficient quantity of `accounts` are owners in the `ownerEpoch`.function_areValidOwnersInEpoch(uint256 ownerEpoch, address[] memory accounts) internalviewreturns (bool) {
if (_containsDuplicates(accounts)) returnfalse;
uint256 threshold = _getOwnerThreshold(ownerEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOwner(ownerEpoch, accounts[i]) &&++validSignerCount >= threshold) returntrue;
}
returnfalse;
}
/// @dev Returns the array of owners within the current `ownerEpoch`.functionowners() publicviewoverridereturns (address[] memory results) {
uint256 ownerEpoch = _ownerEpoch();
uint256 ownerCount = _getOwnerCount(ownerEpoch);
results =newaddress[](ownerCount);
for (uint256 i; i < ownerCount; i++) {
results[i] = _getOwner(ownerEpoch, i);
}
}
/***********\
|* Setters *|
\***********/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];
// Check that the account wasn't already set as an owner for this ownerEpoch.require(!_isOwner(ownerEpoch, account), 'DUP_OWNER');
// Set this account as the i-th owner in this ownerEpoch (needed to we can get all the owners for `owners`).
_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);
}
/**************************\
|* Operator Functionality *|
\**************************//********************\
|* Pure Key Getters *|
\********************/function_getOperatorKey(uint256 operatorEpoch, uint256 index) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OPERATOR, operatorEpoch, index));
}
function_getOperatorCountKey(uint256 operatorEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OPERATOR_COUNT, operatorEpoch));
}
function_getOperatorThresholdKey(uint256 operatorEpoch) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_OPERATOR_THRESHOLD, operatorEpoch));
}
function_getIsOperatorKey(uint256 operatorEpoch, address account) internalpurereturns (bytes32) {
returnkeccak256(abi.encodePacked(PREFIX_IS_OPERATOR, operatorEpoch, account));
}
/***********\
|* Getters *|
\***********/function_operatorEpoch() internalviewreturns (uint256) {
return getUint(KEY_OPERATOR_EPOCH);
}
function_getOperator(uint256 operatorEpoch, uint256 index) internalviewreturns (address) {
return getAddress(_getOperatorKey(operatorEpoch, index));
}
function_getOperatorCount(uint256 operatorEpoch) internalviewreturns (uint256) {
return getUint(_getOperatorCountKey(operatorEpoch));
}
function_getOperatorThreshold(uint256 operatorEpoch) internalviewreturns (uint256) {
return getUint(_getOperatorThresholdKey(operatorEpoch));
}
function_isOperator(uint256 operatorEpoch, address account) internalviewreturns (bool) {
return getBool(_getIsOperatorKey(operatorEpoch, account));
}
/// @dev Returns true if a sufficient quantity of `accounts` are operator in the same `operatorEpoch`, within the last `OLD_KEY_RETENTION + 1` operator epochs.function_areValidRecentOperators(address[] memory accounts) internalviewreturns (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)) returntrue;
}
returnfalse;
}
/// @dev Returns true if a sufficient quantity of `accounts` are operator in the `operatorEpoch`.function_areValidOperatorsInEpoch(uint256 operatorEpoch, address[] memory accounts) internalviewreturns (bool) {
if (_containsDuplicates(accounts)) returnfalse;
uint256 threshold = _getOperatorThreshold(operatorEpoch);
uint256 validSignerCount;
for (uint256 i; i < accounts.length; i++) {
if (_isOperator(operatorEpoch, accounts[i]) &&++validSignerCount >= threshold) returntrue;
}
returnfalse;
}
/// @dev Returns the array of operators within the current `operatorEpoch`.functionoperators() publicviewoverridereturns (address[] memory results) {
uint256 operatorEpoch = _operatorEpoch();
uint256 operatorCount = _getOperatorCount(operatorEpoch);
results =newaddress[](operatorCount);
for (uint256 i; i < operatorCount; i++) {
results[i] = _getOperator(operatorEpoch, i);
}
}
/***********\
|* Setters *|
\***********/function_setOperatorEpoch(uint256 operatorEpoch) internal{
_setUint(KEY_OPERATOR_EPOCH, operatorEpoch);
}
function_setOperator(uint256 operatorEpoch,
uint256 index,
address account
) internal{
// AUDIT: Should have `require(account != address(0), 'ZERO_ADDR');` like Singlesig?
_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];
// Check that the account wasn't already set as an operator for this operatorEpoch.require(!_isOperator(operatorEpoch, account), 'DUP_OPERATOR');
// Set this account as the i-th operator in this operatorEpoch (needed to we can get all the operators for `operators`).
_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);
}
/**********************\
|* Self Functionality *|
\**********************/functiondeployToken(bytescalldata params) externalonlySelf{
(stringmemory name, stringmemory symbol, uint8 decimals, uint256 cap) =abi.decode(
params,
(string, string, uint8, uint256)
);
_deployToken(name, symbol, decimals, cap);
}
functionmintToken(bytescalldata params) externalonlySelf{
(stringmemory symbol, address account, uint256 amount) =abi.decode(params, (string, address, uint256));
_mintToken(symbol, account, amount);
}
functionburnToken(bytescalldata params) externalonlySelf{
(stringmemory symbol, bytes32 salt) =abi.decode(params, (string, bytes32));
_burnToken(symbol, salt);
}
functiontransferOwnership(bytescalldata params) externalonlySelf{
(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);
}
functiontransferOperatorship(bytescalldata params) externalonlySelf{
(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);
}
/**************************\
|* External Functionality *|
\**************************/functionsetup(bytescalldata params) externaloverride{
// Prevent setup from being called on a non-proxy (the implementation).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(newaddress[](uint256(0)), uint256(0), ownerAddresses, ownerThreshold);
emit OperatorshipTransferred(newaddress[](uint256(0)), uint256(0), operatorAddresses, operatorThreshold);
}
functionexecute(bytescalldata input) externaloverride{
(bytesmemory data, bytes[] memory signatures) =abi.decode(input, (bytes, bytes[]));
_execute(data, signatures);
}
function_execute(bytesmemory data, bytes[] memory signatures) internal{
uint256 signatureCount = signatures.length;
address[] memory signers =newaddress[](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; /* Ignore if duplicate commandId received */bytes4 commandSelector;
bytes32 commandHash =keccak256(abi.encodePacked(commands[i]));
if (commandHash == SELECTOR_DEPLOY_TOKEN) {
if (!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.deployToken.selector;
} elseif (commandHash == SELECTOR_MINT_TOKEN) {
if (!areValidRecentOperators &&!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.mintToken.selector;
} elseif (commandHash == SELECTOR_BURN_TOKEN) {
if (!areValidRecentOperators &&!areValidRecentOwners) continue;
commandSelector = AxelarGatewayMultisig.burnToken.selector;
} elseif (commandHash == SELECTOR_TRANSFER_OWNERSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOwnership.selector;
} elseif (commandHash == SELECTOR_TRANSFER_OPERATORSHIP) {
if (!areValidCurrentOwners) continue;
commandSelector = AxelarGatewayMultisig.transferOperatorship.selector;
} else {
continue; /* Ignore if unknown command received */
}
// Prevent a re-entrancy from executing this command before it can be marked as successful.
_setCommandExecuted(commandId, true);
(bool success, ) =address(this).call(abi.encodeWithSelector(commandSelector, params[i]));
_setCommandExecuted(commandId, success);
if (success) {
emit Executed(commandId);
}
}
}
}
// Root file: src/AxelarGatewayProxyMultisig.solpragmasolidity >=0.8.0 <0.9.0;// import { IAxelarGateway } from 'src/interfaces/IAxelarGateway.sol';// import { AxelarGatewayProxy } from 'src/AxelarGatewayProxy.sol';// import { AxelarGatewayMultisig } from 'src/AxelarGatewayMultisig.sol';contractAxelarGatewayProxyMultisigisAxelarGatewayProxy{
constructor(bytesmemory params) {
// AUDIT: constructor contains entire AxelarGatewayMultisig bytecode. Consider passing in an AxelarGatewayMultisig address.address gateway =address(new AxelarGatewayMultisig());
_setAddress(KEY_IMPLEMENTATION, gateway);
(bool success, ) = gateway.delegatecall(abi.encodeWithSelector(IAxelarGateway.setup.selector, params));
require(success, 'SETUP_FAILED');
}
functionsetup(bytescalldata params) external{}
}
Contract Source Code
File 6 of 15: BurnableMintableCappedERC20.sol
// Dependency file: src/interfaces/IERC20.sol// SPDX-License-Identifier: MIT// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
// Dependency file: src/Context.sol// pragma solidity >=0.8.0 <0.9.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnpayable(msg.sender);
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
// Dependency file: src/ERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { IERC20 } from 'src/interfaces/IERC20.sol';// import { Context } from 'src/Context.sol';/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20{
mapping(address=>uint256) publicoverride balanceOf;
mapping(address=>mapping(address=>uint256)) publicoverride allowance;
uint256publicoverride totalSupply;
stringpublic name;
stringpublic symbol;
uint8publicimmutable decimals;
/**
* @dev Sets the values for {name}, {symbol}, and {decimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_,
stringmemory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtual{
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner,
address spender,
uint256 amount
) internalvirtual{
require(owner !=address(0), 'ZERO_ADDR');
require(spender !=address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
// Dependency file: src/Ownable.sol// pragma solidity >=0.8.0 <0.9.0;abstractcontractOwnable{
addresspublic owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
constructor() {
owner =msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifieronlyOwner() {
require(owner ==msg.sender, 'NOT_OWNER');
_;
}
functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// Dependency file: src/Burner.sol// pragma solidity >=0.8.0 <0.9.0;// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';contractBurner{
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
// Dependency file: src/EternalStorage.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @title EternalStorage
* @dev This contract holds all the necessary state variables to carry out the storage of any contract.
*/contractEternalStorage{
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;
// *** Getter Methods ***functiongetUint(bytes32 key) publicviewreturns (uint256) {
return _uintStorage[key];
}
functiongetString(bytes32 key) publicviewreturns (stringmemory) {
return _stringStorage[key];
}
functiongetAddress(bytes32 key) publicviewreturns (address) {
return _addressStorage[key];
}
functiongetBytes(bytes32 key) publicviewreturns (bytesmemory) {
return _bytesStorage[key];
}
functiongetBool(bytes32 key) publicviewreturns (bool) {
return _boolStorage[key];
}
functiongetInt(bytes32 key) publicviewreturns (int256) {
return _intStorage[key];
}
// *** Setter Methods ***function_setUint(bytes32 key, uint256 value) internal{
_uintStorage[key] = value;
}
function_setString(bytes32 key, stringmemory value) internal{
_stringStorage[key] = value;
}
function_setAddress(bytes32 key, address value) internal{
_addressStorage[key] = value;
}
function_setBytes(bytes32 key, bytesmemory 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;
}
// *** Delete Methods ***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];
}
}
// Root file: src/BurnableMintableCappedERC20.solpragmasolidity >=0.8.0 <0.9.0;// import { ERC20 } from 'src/ERC20.sol';// import { Ownable } from 'src/Ownable.sol';// import { Burner } from 'src/Burner.sol';// import { EternalStorage } from 'src/EternalStorage.sol';contractBurnableMintableCappedERC20isERC20, Ownable{
uint256public cap;
bytes32privateconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32privateconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
eventFrozen(addressindexed owner);
eventUnfrozen(addressindexed owner);
constructor(stringmemory name,
stringmemory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
functiondepositAddress(bytes32 salt) publicviewreturns (address) {
// This would be easier, cheaper, simpler, and result in globally consistent deposit addresses for any salt (all chains, all tokens).// return address(uint160(uint256(keccak256(abi.encodePacked(bytes32(0x000000000000000000000000000000000000000000000000000000000000dead), salt)))));/* Convert a hash which is bytes32 to an address which is 20-byte long
according to https://docs.soliditylang.org/en/v0.8.1/control-structures.html?highlight=create2#salted-contract-creations-create2 */returnaddress(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
functionmint(address account, uint256 amount) publiconlyOwner{
uint256 capacity = cap;
require(capacity ==0|| totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
functionburn(bytes32 salt) publiconlyOwner{
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function_beforeTokenTransfer(address,
address,
uint256) internalviewoverride{
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
Contract Source Code
File 7 of 15: Burner.sol
// Dependency file: src/interfaces/IERC20.sol// SPDX-License-Identifier: MIT// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
// Dependency file: src/Context.sol// pragma solidity >=0.8.0 <0.9.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnpayable(msg.sender);
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
// Dependency file: src/ERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { IERC20 } from 'src/interfaces/IERC20.sol';// import { Context } from 'src/Context.sol';/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20{
mapping(address=>uint256) publicoverride balanceOf;
mapping(address=>mapping(address=>uint256)) publicoverride allowance;
uint256publicoverride totalSupply;
stringpublic name;
stringpublic symbol;
uint8publicimmutable decimals;
/**
* @dev Sets the values for {name}, {symbol}, and {decimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_,
stringmemory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtual{
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner,
address spender,
uint256 amount
) internalvirtual{
require(owner !=address(0), 'ZERO_ADDR');
require(spender !=address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
// Dependency file: src/Ownable.sol// pragma solidity >=0.8.0 <0.9.0;abstractcontractOwnable{
addresspublic owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
constructor() {
owner =msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
modifieronlyOwner() {
require(owner ==msg.sender, 'NOT_OWNER');
_;
}
functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), 'ZERO_ADDR');
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// Dependency file: src/EternalStorage.sol// pragma solidity >=0.8.0 <0.9.0;/**
* @title EternalStorage
* @dev This contract holds all the necessary state variables to carry out the storage of any contract.
*/contractEternalStorage{
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;
// *** Getter Methods ***functiongetUint(bytes32 key) publicviewreturns (uint256) {
return _uintStorage[key];
}
functiongetString(bytes32 key) publicviewreturns (stringmemory) {
return _stringStorage[key];
}
functiongetAddress(bytes32 key) publicviewreturns (address) {
return _addressStorage[key];
}
functiongetBytes(bytes32 key) publicviewreturns (bytesmemory) {
return _bytesStorage[key];
}
functiongetBool(bytes32 key) publicviewreturns (bool) {
return _boolStorage[key];
}
functiongetInt(bytes32 key) publicviewreturns (int256) {
return _intStorage[key];
}
// *** Setter Methods ***function_setUint(bytes32 key, uint256 value) internal{
_uintStorage[key] = value;
}
function_setString(bytes32 key, stringmemory value) internal{
_stringStorage[key] = value;
}
function_setAddress(bytes32 key, address value) internal{
_addressStorage[key] = value;
}
function_setBytes(bytes32 key, bytesmemory 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;
}
// *** Delete Methods ***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];
}
}
// Dependency file: src/BurnableMintableCappedERC20.sol// pragma solidity >=0.8.0 <0.9.0;// import { ERC20 } from 'src/ERC20.sol';// import { Ownable } from 'src/Ownable.sol';// import { Burner } from 'src/Burner.sol';// import { EternalStorage } from 'src/EternalStorage.sol';contractBurnableMintableCappedERC20isERC20, Ownable{
uint256public cap;
bytes32privateconstant PREFIX_TOKEN_FROZEN =keccak256('token-frozen');
bytes32privateconstant KEY_ALL_TOKENS_FROZEN =keccak256('all-tokens-frozen');
eventFrozen(addressindexed owner);
eventUnfrozen(addressindexed owner);
constructor(stringmemory name,
stringmemory symbol,
uint8 decimals,
uint256 capacity
) ERC20(name, symbol, decimals) Ownable() {
cap = capacity;
}
functiondepositAddress(bytes32 salt) publicviewreturns (address) {
// This would be easier, cheaper, simpler, and result in globally consistent deposit addresses for any salt (all chains, all tokens).// return address(uint160(uint256(keccak256(abi.encodePacked(bytes32(0x000000000000000000000000000000000000000000000000000000000000dead), salt)))));/* Convert a hash which is bytes32 to an address which is 20-byte long
according to https://docs.soliditylang.org/en/v0.8.1/control-structures.html?highlight=create2#salted-contract-creations-create2 */returnaddress(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
owner,
salt,
keccak256(abi.encodePacked(type(Burner).creationCode, abi.encode(address(this)), salt))
)
)
)
)
);
}
functionmint(address account, uint256 amount) publiconlyOwner{
uint256 capacity = cap;
require(capacity ==0|| totalSupply + amount <= capacity, 'CAP_EXCEEDED');
_mint(account, amount);
}
functionburn(bytes32 salt) publiconlyOwner{
address account = depositAddress(salt);
_burn(account, balanceOf[account]);
}
function_beforeTokenTransfer(address,
address,
uint256) internalviewoverride{
require(!EternalStorage(owner).getBool(KEY_ALL_TOKENS_FROZEN), 'IS_FROZEN');
require(!EternalStorage(owner).getBool(keccak256(abi.encodePacked(PREFIX_TOKEN_FROZEN, symbol))), 'IS_FROZEN');
}
}
// Root file: src/Burner.solpragmasolidity >=0.8.0 <0.9.0;// import { BurnableMintableCappedERC20 } from 'src/BurnableMintableCappedERC20.sol';contractBurner{
constructor(address tokenAddress, bytes32 salt) {
BurnableMintableCappedERC20(tokenAddress).burn(salt);
selfdestruct(payable(address(0)));
}
}
Contract Source Code
File 8 of 15: Context.sol
// Root file: src/Context.sol// SPDX-License-Identifier: MITpragmasolidity >=0.8.0 <0.9.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnpayable(msg.sender);
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
Contract Source Code
File 9 of 15: ECDSA.sol
// Root file: src/ECDSA.sol// SPDX-License-Identifier: MITpragmasolidity >=0.8.0 <0.9.0;/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/libraryECDSA{
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/functionrecover(bytes32 hash, bytesmemory signature) internalpurereturns (address signer) {
// Check the signature lengthrequire(signature.length==65, 'INV_LEN');
// Divide the signature in r, s and v variablesbytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them// currently is to use assembly.// solhint-disable-next-line no-inline-assemblyassembly {
r :=mload(add(signature, 0x20))
s :=mload(add(signature, 0x40))
v :=byte(0, mload(add(signature, 0x60)))
}
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most// signatures from current libraries generate a unique signature with an s-value in the lower half order.//// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept// these malleable signatures as well.require(uint256(s) <=0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, 'INV_S');
require(v ==27|| v ==28, 'INV_V');
// If the signature is valid (and not malleable), return the signer addressrequire((signer =ecrecover(hash, v, r, s)) !=address(0), 'INV_SIG');
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* replicates the behavior of the
* https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
* JSON-RPC method.
*
* See {recover}.
*/functiontoEthSignedMessageHash(bytes32 hash) internalpurereturns (bytes32) {
// 32 is the length in bytes of hash,// enforced by the type signature abovereturnkeccak256(abi.encodePacked('\x19Ethereum Signed Message:\n32', hash));
}
}
Contract Source Code
File 10 of 15: ERC20.sol
// Dependency file: src/interfaces/IERC20.sol// SPDX-License-Identifier: MIT// pragma solidity >=0.8.0 <0.9.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
// Dependency file: src/Context.sol// pragma solidity >=0.8.0 <0.9.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnpayable(msg.sender);
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
// Root file: src/ERC20.solpragmasolidity >=0.8.0 <0.9.0;// import { IERC20 } from 'src/interfaces/IERC20.sol';// import { Context } from 'src/Context.sol';/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20{
mapping(address=>uint256) publicoverride balanceOf;
mapping(address=>mapping(address=>uint256)) publicoverride allowance;
uint256publicoverride totalSupply;
stringpublic name;
stringpublic symbol;
uint8publicimmutable decimals;
/**
* @dev Sets the values for {name}, {symbol}, and {decimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_,
stringmemory symbol_,
uint8 decimals_
) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance[sender][_msgSender()] - amount);
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] + addedValue);
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, allowance[_msgSender()][spender] - subtractedValue);
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtual{
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);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(address(0), account, amount);
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), 'ZERO_ADDR');
_beforeTokenTransfer(account, address(0), amount);
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner,
address spender,
uint256 amount
) internalvirtual{
require(owner !=address(0), 'ZERO_ADDR');
require(spender !=address(0), 'ZERO_ADDR');
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
// Root file: src/interfaces/IERC20.sol// SPDX-License-Identifier: MITpragmasolidity >=0.8.0 <0.9.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}