- Contract name:
- TokenCtrl
- Optimization enabled
- true
- Compiler version
- v0.8.9+commit.e5eed63a
- Optimization runs
- 1000
- Verified at
- 2023-04-10T02:06:15.284768Z
Constructor Arguments
000000000000000000000000111b0fba4e94ff9a312b517d5f817f4a8957375f000000000000000000000000b90a713d8dac53686eb482a66adc205532ead9f8
Arg [0] (address) : 0x111b0fba4e94ff9a312b517d5f817f4a8957375f
Arg [1] (address) : 0xb90a713d8dac53686eb482a66adc205532ead9f8
contracts/TokenCtrl.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "@openzeppelin/contracts/access/Ownable2Step.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/proxy/Clones.sol"; import "./utils/EIP712Custom.sol"; import "./utils/DeployTokenHasher.sol"; import "./utils/MintTokenHasher.sol"; import "./IToken.sol"; /// @title Token Controller, mint and manage Token contract TokenCtrl is Ownable2Step, EIP712Custom, DeployTokenHasher, MintTokenHasher { using Counters for Counters.Counter; // properties // token symbol to address mapping mapping(bytes32 => address) public tokens; // token nonces mapping(bytes32 => Counters.Counter) private _nonces; // token lists bytes32[] public tokenLists; // authorities mapping(address => bool) public authorities; // token template address public tokenTemplate; // events event DeployToken( address indexed tokenAddress, address indexed authority, address sender, bytes32 symbol ); event MintToken( address indexed tokenAddress, address indexed authority, address indexed destination, uint256 amount, address sender, bytes32 symbol ); event ChangeTokenAuthority( address indexed tokenAddress, address indexed newAuthority, address sender, bytes32 symbol ); event EnlistToken( address indexed tokenAddress, address sender, bytes32 symbol ); event DelistToken( address indexed tokenAddress, address sender, bytes32 symbol ); event SetAuthority( address indexed authority, address sender, bool isAuthority ); event SetTokenTemplate( address indexed tokenTemplate, address indexed previousTokenTemplate, address sender ); constructor( address authority_, address tokenTemplate_ ) EIP712Custom("TokenCtrl", "1") { // set authority _setAuthority(authority_); // set token Template address _setTokenTemplate(tokenTemplate_); } // external functions /// Deploy new Token with EIP-712 signature, signer must be **authority** /// @param params_ DeployTokenParams of token to be deployed /// @param v_ V value of a signature /// @param r_ R value of a signature /// @param s_ S value of a signature function deployToken( DeployTokenParam calldata params_, uint8 v_, bytes32 r_, bytes32 s_ ) external { // verify deadline require( block.timestamp <= params_.deadline, "DEPLOY_TOKEN: expired deadline" ); bytes32 symbol32 = _stringToBytes32(params_.symbol); // token must not be already deployed require( _getTokenAddress(symbol32) == address(0), "DEPLOY_TOKEN: token already deployed" ); // find parameters by chainId EvmDeployToken memory dt; for (uint256 i = 0; i < params_.deployTokens.length; i++) { if (params_.deployTokens[i].chainId == block.chainid) { dt = params_.deployTokens[i]; } } require(dt.chainId != 0, "DEPLOY_TOKEN: chain id not match"); // verify contract address require( dt.contractAddress == address(this), "DEPLOY_TOKEN: mismatch contract address" ); // check nonce, to prevent replay attack require( dt.nonce == _useNonces(symbol32), "DEPLOY_TOKEN: invalid nonce" ); // verify signer of the signature bytes32 structHash = _hashDeployTokenStruct(params_); address signer = _recoverSigner(structHash, v_, r_, s_); require(authorities[signer], "DEPLOY_TOKEN: unauthorized"); // deploy token address tokenAddress = _doDeployToken(params_.name, params_.symbol); _registerToken(symbol32, tokenAddress); // emit event emit DeployToken(tokenAddress, signer, _msgSender(), symbol32); } /// Mint Tokens with EIP-712 signature, signer must be **authority** /// @param params_ MintTokenParams of token to be minted /// @param v_ V value of a signature /// @param r_ R value of a signature /// @param s_ S value of a signature function mintToken( MintTokenParams calldata params_, uint8 v_, bytes32 r_, bytes32 s_ ) external { // verify deadline require( block.timestamp <= params_.deadline, "MINT_TOKEN: expired deadline" ); bytes32 symbol32 = _stringToBytes32(params_.symbol); require( _getTokenAddress(symbol32) != address(0), "MINT_TOKEN: token not found" ); // find parameters by chainId EvmMintDestination memory dt; for (uint256 i = 0; i < params_.destinations.length; i++) { if (params_.destinations[i].chainId == block.chainid) { dt = params_.destinations[i]; } } require(dt.chainId != 0, "MINT_TOKEN: chain id not match"); // verify contract address require( dt.contractAddress == address(this), "MINT_TOKEN: mismatch contract address" ); // verify token nonce, to prevent replay attack require(dt.nonce == _useNonces(symbol32), "MINT_TOKEN: invalid nonce"); // verify signer of the signature bytes32 structHash = _hashMintTokenStruct(params_); address signer = _recoverSigner(structHash, v_, r_, s_); require(authorities[signer], "MINT_TOKEN: unauthorized"); // mint token address tokenAddress = _doMintToken( params_.symbol, signer, params_.amount ); // emit event emit MintToken( tokenAddress, signer, signer, params_.amount, _msgSender(), symbol32 ); } /// Change token authority, caller must be **owner** /// @param symbol_ Symbol of the token /// @param newAuthority_ New authority to be assgined to function changeTokenAuthority( string calldata symbol_, address newAuthority_ ) external onlyOwner { // authoriy address must not empty require( newAuthority_ != address(0), "CHANGE_TOKEN_AUTHORITY: authority is empty" ); bytes32 symbol32 = _stringToBytes32(symbol_); address tokenAddress = _getTokenAddress(symbol32); // verify token symbol exists require( tokenAddress != address(0), "CHANGE_TOKEN_AUTHORITY: token not found" ); // bump token nonce _useNonces(symbol32); // change token authority _doChangeTokenAuthority(tokenAddress, newAuthority_); // emit event emit ChangeTokenAuthority( tokenAddress, newAuthority_, _msgSender(), symbol32 ); } /// Enlist token deployed from other controller, caller must be **owner* /// @param symbol_ Symbol of the token /// @param tokenAddress_ Token address to be added /// @dev token's ownership must be transfered before enlisting the token function enlistToken( string calldata symbol_, address tokenAddress_ ) external onlyOwner { bytes32 symbol32 = _stringToBytes32(symbol_); // verify token symbol exists require( tokens[symbol32] == address(0), "ENLIST_TOKEN: token already exists" ); // token address must not be empty require(tokenAddress_ != address(0), "ENLIST_TOKEN: address is empty"); // token owner must be this controller require( Ownable(tokenAddress_).owner() == address(this), "ENLIST_TOKEN: token is not owned by the controller" ); // bump token nonce _useNonces(symbol32); // register token _registerToken(symbol32, tokenAddress_); emit EnlistToken(tokenAddress_, _msgSender(), symbol32); } /// Delist token from the controller, caller must be **owner* /// @param symbol_ Symbol of the token function delistToken(string calldata symbol_) external onlyOwner { bytes32 symbol32 = _stringToBytes32(symbol_); address tokenAddress = tokens[symbol32]; require(tokenAddress != address(0), "DELIST_TOKEN: token not found"); // bump token nonce _useNonces(symbol32); // unregister token _unregisterToken(symbol32); emit DelistToken(tokenAddress, _msgSender(), symbol32); } /// Set authority address of this controller, caller must be **owner** /// @param authority_ New authority function setAuthority(address authority_) external onlyOwner { _setAuthority(authority_); } /// Remove authority address from this controller, caller must be **owner** /// @param authority_ Authority to be removed function removeAuthority(address authority_) external onlyOwner { require(authorities[authority_], "REMOVE_AUTHORITY: not authority"); authorities[authority_] = false; emit SetAuthority(authority_, _msgSender(), false); } /// Set token token template, caller must be **owner** /// @param tokenTemplate_ Address of token template function setTokenTemplate(address tokenTemplate_) external onlyOwner { _setTokenTemplate(tokenTemplate_); } /// Get token address by symbol /// @param symbol_ Symbol of the token function getTokenAddress( string memory symbol_ ) external view returns (address) { bytes32 symbol32 = _stringToBytes32(symbol_); return _getTokenAddress(symbol32); } /// Get current token nonce by symbol /// @param symbol_ Symbol of the token function getNonces(string memory symbol_) external view returns (uint256) { bytes32 symbol32 = _stringToBytes32(symbol_); return _nonces[symbol32].current(); } /// Get symbol of token registered with this controller function getTokenLists() external view returns (bytes32[] memory) { return tokenLists; } // private functions function _getTokenAddress( bytes32 symbol32_ ) private view returns (address) { return tokens[symbol32_]; } function _doDeployToken( string memory name_, string memory symbol_ ) private returns (address) { IToken token = IToken(Clones.clone(tokenTemplate)); token.initialize(name_, symbol_); return address(token); } function _registerToken(bytes32 symbol32_, address tokenAddress_) private { tokens[symbol32_] = tokenAddress_; tokenLists.push(symbol32_); } function _unregisterToken(bytes32 symbol32_) private { delete tokens[symbol32_]; // intentional not to clear nonce, as it may lead to replay attack uint256 len = tokenLists.length; if ( (len == 1 && tokenLists[0] == symbol32_) || tokenLists[len - 1] == symbol32_ ) { // one item and matches // or being last item tokenLists.pop(); } else { // find item index for (uint i = 0; i < len - 1; i++) { if (tokenLists[i] == symbol32_) { // swap item from last index tokenLists[i] = tokenLists[len - 1]; break; } } tokenLists.pop(); } } function _doMintToken( string memory symbol_, address destination_, uint256 amount_ ) private returns (address _token) { _token = this.getTokenAddress(symbol_); IToken(_token).mint(destination_, amount_); } function _doChangeTokenAuthority( address tokenAddress_, address authority_ ) private { Ownable(tokenAddress_).transferOwnership(authority_); } function _useNonces(bytes32 symbol32_) private returns (uint256 _current) { Counters.Counter storage nonce = _nonces[symbol32_]; _current = nonce.current(); nonce.increment(); } function _setAuthority(address authority_) private { require(authority_ != address(0), "SET_AUTHORITY: authority is empty"); require( !authorities[authority_], "SET_AUTHORITY: already be authority" ); authorities[authority_] = true; emit SetAuthority(authority_, _msgSender(), true); } function _setTokenTemplate(address tokenTemplate_) private { require( tokenTemplate_ != address(0), "SET_TOKEN_TEMPLATE: token template is zero" ); address previousTokenTemplate = tokenTemplate; tokenTemplate = tokenTemplate_; emit SetTokenTemplate( tokenTemplate_, previousTokenTemplate, _msgSender() ); } // utilities funcitons function _stringToBytes32( string memory source_ ) private pure returns (bytes32 result_) { bytes memory tempEmptyStringTest = bytes(source_); if (tempEmptyStringTest.length == 0) { return 0x0; } assembly { result_ := mload(add(source_, 32)) } } }
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
@openzeppelin/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (access/Ownable2Step.sol) pragma solidity ^0.8.0; import "./Ownable.sol"; /** * @dev Contract module which provides access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership} and {acceptOwnership}. * * This module is used through inheritance. It will make available all functions * from parent (Ownable). */ abstract contract Ownable2Step is Ownable { address private _pendingOwner; event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner); /** * @dev Returns the address of the pending owner. */ function pendingOwner() public view virtual returns (address) { return _pendingOwner; } /** * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual override onlyOwner { _pendingOwner = newOwner; emit OwnershipTransferStarted(owner(), newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner. * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual override { delete _pendingOwner; super._transferOwnership(newOwner); } /** * @dev The new owner accepts the ownership transfer. */ function acceptOwnership() external { address sender = _msgSender(); require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner"); _transferOwnership(sender); } }
@openzeppelin/contracts/proxy/Clones.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (proxy/Clones.sol) pragma solidity ^0.8.0; /** * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for * deploying minimal proxy contracts, also known as "clones". * * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies * > a minimal bytecode implementation that delegates all calls to a known, fixed address. * * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the * deterministic method. * * _Available since v3.4._ */ library Clones { /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create opcode, which should never revert. */ function clone(address implementation) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes // of the `implementation` address with the bytecode before the address. mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000)) // Packs the remaining 17 bytes of `implementation` with the bytecode after the address. mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)) instance := create(0, 0x09, 0x37) } require(instance != address(0), "ERC1167: create failed"); } /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create2 opcode and a `salt` to deterministically deploy * the clone. Using the same `implementation` and `salt` multiple time will revert, since * the clones cannot be deployed twice at the same address. */ function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes // of the `implementation` address with the bytecode before the address. mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000)) // Packs the remaining 17 bytes of `implementation` with the bytecode after the address. mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)) instance := create2(0, 0x09, 0x37, salt) } require(instance != address(0), "ERC1167: create2 failed"); } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress( address implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(add(ptr, 0x38), deployer) mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff) mstore(add(ptr, 0x14), implementation) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73) mstore(add(ptr, 0x58), salt) mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37)) predicted := keccak256(add(ptr, 0x43), 0x55) } } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress(address implementation, bytes32 salt) internal view returns (address predicted) { return predictDeterministicAddress(implementation, salt, address(this)); } }
@openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/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.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead 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}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @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}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @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. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @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`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This 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: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, 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: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _balances[account] += amount; } emit Transfer(address(0), account, amount); _afterTokenTransfer(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) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } emit Transfer(account, address(0), amount); _afterTokenTransfer(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 ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - 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 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( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed 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. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (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. */ function allowance(address owner, address spender) external view returns (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. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` 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. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol) pragma solidity ^0.8.0; import "../ERC20.sol"; import "../../../utils/Context.sol"; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ abstract contract ERC20Burnable is Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { _spendAllowance(account, _msgSender(), amount); _burn(account, amount); } }
@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.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 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. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
@openzeppelin/contracts/utils/Counters.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } }
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
@openzeppelin/contracts/utils/cryptography/ECDSA.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @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. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. 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. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @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. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // 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 (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): 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. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
@openzeppelin/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
contracts/IToken.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IToken is IERC20 { function initialize(string memory name_, string memory symbol_) external; function mint(address to_, uint256 amount_) external; }
contracts/Token.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "./IToken.sol"; /// @title Token template /// @notice This contract is an ERC20 template, have to call initialize to setup name and symbol contract Token is IToken, ERC20, ERC20Burnable, Ownable { string private _name; string private _symbol; bool private _initialized; constructor() ERC20("", "") {} /// Initialize the token /// @param name_ Name of the token /// @param symbol_ Symbol of the token function initialize(string memory name_, string memory symbol_) external { require(!_initialized, "token: Already initialized"); // set as initialized _initialized = true; // set parameters _name = name_; _symbol = symbol_; // transfer token ownership _transferOwnership(msg.sender); } /// Mint tokens to target address, caller must be **owner** /// @param to_ Target address /// @param amount_ Amount of token to be minted function mint(address to_, uint256 amount_) public onlyOwner { _mint(to_, amount_); } /// Return name of the token function name() public view override returns (string memory) { return _name; } /// Return symbol of the token function symbol() public view override returns (string memory) { return _symbol; } }
contracts/utils/DeployTokenHasher.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; /// @title Deploy Token Hasher abstract contract DeployTokenHasher { // keccak256("DeployToken(string name,string symbol,EvmDeployToken[] deployTokens,StellarDeployToken stellarDeployToken,uint256 deadline)EvmDeployToken(address contractAddress,uint256 chainId,uint256 nonce)StellarDeployToken(string asset,string authority,uint256 sequenceNo)"); bytes32 private constant _DEPLOY_TOKEN_TYPEHASH = 0xb0d684284bab62fd5887a7ff9bf55a567a90e78b8a82f543d2d7aad12f721eb7; // keccak256("EvmDeployToken(address contractAddress,uint256 chainId,uint256 nonce)"); bytes32 private constant _EVM_DEPLOY_TOKEN_TYPEHASH = 0x16be7e703a5ec19023dc1f99e6b1b464b2e71aefd0c9b6e791b34f20755bdd6f; // keccak256("StellarDeployToken(string asset,string authority,uint256 sequenceNo)"); bytes32 private constant _STELLAR_DEPLOY_TOKEN_TYPEHASH = 0xc7036020acece1e4e42197d1db5470d4a8c7b7c4071b1b01e6c2e3a007fde9d5; struct EvmDeployToken { address contractAddress; uint256 chainId; uint256 nonce; } struct StellarDeployToken { string asset; string authority; uint256 sequenceNo; } struct DeployTokenParam { string name; string symbol; EvmDeployToken[] deployTokens; StellarDeployToken stellarDeployToken; uint256 deadline; } /// Hash `DeployTokenParams` for ERC-712 signature validation function _hashDeployTokenStruct( DeployTokenParam memory _params ) internal pure returns (bytes32) { bytes32[] memory deployTokensHashes = new bytes32[]( _params.deployTokens.length ); // hash each EvmDeployToken for (uint256 i = 0; i < _params.deployTokens.length; i++) { deployTokensHashes[i] = _hashEvmDeployTokenStruct( _params.deployTokens[i] ); } // hash StellarDeployToken bytes32 stellarDeployTokenHash = _hashStellarDeployTokenStruct( _params.stellarDeployToken ); // hash DeployTokenParam bytes32 structHash = keccak256( abi.encode( _DEPLOY_TOKEN_TYPEHASH, keccak256(bytes(_params.name)), keccak256(bytes(_params.symbol)), keccak256(abi.encodePacked(deployTokensHashes)), stellarDeployTokenHash, _params.deadline ) ); return structHash; } /// Hash `EvmDeployToken` for ERC-712 signature validation function _hashEvmDeployTokenStruct( EvmDeployToken memory _params ) private pure returns (bytes32 _encodedStruct) { // hash EvmDeployToken _encodedStruct = keccak256( abi.encode( _EVM_DEPLOY_TOKEN_TYPEHASH, _params.contractAddress, _params.chainId, _params.nonce ) ); } /// Hash `StellarDeployToken` for ERC-712 signature validation function _hashStellarDeployTokenStruct( StellarDeployToken memory _params ) private pure returns (bytes32 _encodedStruct) { // hash StellarDeployToken _encodedStruct = keccak256( abi.encode( _STELLAR_DEPLOY_TOKEN_TYPEHASH, keccak256(bytes(_params.asset)), keccak256(bytes(_params.authority)), _params.sequenceNo ) ); } }
contracts/utils/EIP712Custom.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol) pragma solidity 0.8.9; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; /** * Modified from openzeppelin/contracts/utils/cryptography/EIP712.sol * This fixed verifying contract address to 0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC and chain_id to 56789 */ abstract contract EIP712Custom { /* solhint-disable var-name-mixedcase */ // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _CACHED_DOMAIN_SEPARATOR; /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory _name, string memory _version) { bytes32 hashedName = keccak256(bytes(_name)); bytes32 hashedVersion = keccak256(bytes(_version)); // keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); bytes32 typeHash = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f; // verifyingContract: 0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC // chain_id: 56789 _CACHED_DOMAIN_SEPARATOR = keccak256( abi.encode( typeHash, hashedName, hashedVersion, 56789, address(0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC) ) ); } function _hashTypedDataV4( bytes32 _structHash ) private view returns (bytes32) { return ECDSA.toTypedDataHash(_CACHED_DOMAIN_SEPARATOR, _structHash); } /// Recover signature function _recoverSigner( bytes32 _structHash, uint8 _v, bytes32 _r, bytes32 _s ) internal view returns (address _signer) { bytes32 hash = _hashTypedDataV4(_structHash); _signer = ECDSA.recover(hash, _v, _r, _s); } }
contracts/utils/MintTokenHasher.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; /// @title Mint Token Hasher abstract contract MintTokenHasher { // keccak256("MintToken(string symbol,uint256 amount,EvmMintDestination[] destinations,StellarMintDestination stellarDestination,uint256 deadline)EvmMintDestination(address contractAddress,uint256 chainId,uint256 nonce)StellarMintDestination(string asset,string authority,uint256 sequenceNo)"); bytes32 private constant _MINT_TOKEN_TYPEHASH = 0x7768cc1a3091453e40ae794b95130b9a7ecd0497b18984c57c52995e34d884fd; // keccak256("EvmMintDestination(address contractAddress,uint256 chainId,uint256 nonce)"); bytes32 private constant _EVM_MINT_DESTINATION_TYPEHASH = 0xf926565b58497271466ade9f996776ec81486c663ec41ce3bea33da7e1f9c031; // keccak256("StellarMintDestination(string asset,string authority,uint256 sequenceNo)"); bytes32 private constant _STELLAR_MINT_DESTINATION_TYPEHASH = 0x1169d81a1d4f5d9bdd3142477ed3d12d102799cac7ce46e17f2a3ba127f70c55; struct EvmMintDestination { address contractAddress; uint256 chainId; uint256 nonce; } struct StellarMintDestination { string asset; string authority; uint256 sequenceNo; } struct MintTokenParams { string symbol; uint256 amount; EvmMintDestination[] destinations; StellarMintDestination stellarDestination; uint256 deadline; } /// Hash `MintTokenParams` for ERC-712 signature validation function _hashMintTokenStruct( MintTokenParams memory _params ) internal pure returns (bytes32) { bytes32[] memory destinations = new bytes32[]( _params.destinations.length ); // hash each EvmMintDestination for (uint256 i = 0; i < _params.destinations.length; i++) { destinations[i] = _hashEvmMintDestinationStruct( _params.destinations[i] ); } // hash StellarMintDestination bytes32 stellarDestination = _hashStellarMintDestinationStruct( _params.stellarDestination ); // hash MintTokenParams bytes32 structHash = keccak256( abi.encode( _MINT_TOKEN_TYPEHASH, keccak256(bytes(_params.symbol)), _params.amount, keccak256(abi.encodePacked(destinations)), stellarDestination, _params.deadline ) ); return structHash; } /// Hash `EvmMintDestination` for ERC-712 signature validation function _hashEvmMintDestinationStruct( EvmMintDestination memory _params ) private pure returns (bytes32 _encodedStruct) { _encodedStruct = keccak256( abi.encode( _EVM_MINT_DESTINATION_TYPEHASH, _params.contractAddress, _params.chainId, _params.nonce ) ); } /// Hash `StellarMintDestination` for ERC-712 signature validation function _hashStellarMintDestinationStruct( StellarMintDestination memory _params ) private pure returns (bytes32 _encodedStruct) { _encodedStruct = keccak256( abi.encode( _STELLAR_MINT_DESTINATION_TYPEHASH, keccak256(bytes(_params.asset)), keccak256(bytes(_params.authority)), _params.sequenceNo ) ); } }
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"authority_","internalType":"address"},{"type":"address","name":"tokenTemplate_","internalType":"address"}]},{"type":"event","name":"ChangeTokenAuthority","inputs":[{"type":"address","name":"tokenAddress","internalType":"address","indexed":true},{"type":"address","name":"newAuthority","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":false},{"type":"bytes32","name":"symbol","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"DelistToken","inputs":[{"type":"address","name":"tokenAddress","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":false},{"type":"bytes32","name":"symbol","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"DeployToken","inputs":[{"type":"address","name":"tokenAddress","internalType":"address","indexed":true},{"type":"address","name":"authority","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":false},{"type":"bytes32","name":"symbol","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"EnlistToken","inputs":[{"type":"address","name":"tokenAddress","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":false},{"type":"bytes32","name":"symbol","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"MintToken","inputs":[{"type":"address","name":"tokenAddress","internalType":"address","indexed":true},{"type":"address","name":"authority","internalType":"address","indexed":true},{"type":"address","name":"destination","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"address","name":"sender","internalType":"address","indexed":false},{"type":"bytes32","name":"symbol","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferStarted","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"SetAuthority","inputs":[{"type":"address","name":"authority","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":false},{"type":"bool","name":"isAuthority","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"SetTokenTemplate","inputs":[{"type":"address","name":"tokenTemplate","internalType":"address","indexed":true},{"type":"address","name":"previousTokenTemplate","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"acceptOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"authorities","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"changeTokenAuthority","inputs":[{"type":"string","name":"symbol_","internalType":"string"},{"type":"address","name":"newAuthority_","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"delistToken","inputs":[{"type":"string","name":"symbol_","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deployToken","inputs":[{"type":"tuple","name":"params_","internalType":"struct DeployTokenHasher.DeployTokenParam","components":[{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"symbol","internalType":"string"},{"type":"tuple[]","name":"deployTokens","internalType":"struct DeployTokenHasher.EvmDeployToken[]","components":[{"type":"address","name":"contractAddress","internalType":"address"},{"type":"uint256","name":"chainId","internalType":"uint256"},{"type":"uint256","name":"nonce","internalType":"uint256"}]},{"type":"tuple","name":"stellarDeployToken","internalType":"struct DeployTokenHasher.StellarDeployToken","components":[{"type":"string","name":"asset","internalType":"string"},{"type":"string","name":"authority","internalType":"string"},{"type":"uint256","name":"sequenceNo","internalType":"uint256"}]},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"uint8","name":"v_","internalType":"uint8"},{"type":"bytes32","name":"r_","internalType":"bytes32"},{"type":"bytes32","name":"s_","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"enlistToken","inputs":[{"type":"string","name":"symbol_","internalType":"string"},{"type":"address","name":"tokenAddress_","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getNonces","inputs":[{"type":"string","name":"symbol_","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getTokenAddress","inputs":[{"type":"string","name":"symbol_","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32[]","name":"","internalType":"bytes32[]"}],"name":"getTokenLists","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"mintToken","inputs":[{"type":"tuple","name":"params_","internalType":"struct MintTokenHasher.MintTokenParams","components":[{"type":"string","name":"symbol","internalType":"string"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"tuple[]","name":"destinations","internalType":"struct MintTokenHasher.EvmMintDestination[]","components":[{"type":"address","name":"contractAddress","internalType":"address"},{"type":"uint256","name":"chainId","internalType":"uint256"},{"type":"uint256","name":"nonce","internalType":"uint256"}]},{"type":"tuple","name":"stellarDestination","internalType":"struct MintTokenHasher.StellarMintDestination","components":[{"type":"string","name":"asset","internalType":"string"},{"type":"string","name":"authority","internalType":"string"},{"type":"uint256","name":"sequenceNo","internalType":"uint256"}]},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"uint8","name":"v_","internalType":"uint8"},{"type":"bytes32","name":"r_","internalType":"bytes32"},{"type":"bytes32","name":"s_","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pendingOwner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeAuthority","inputs":[{"type":"address","name":"authority_","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setAuthority","inputs":[{"type":"address","name":"authority_","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTokenTemplate","inputs":[{"type":"address","name":"tokenTemplate_","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"tokenLists","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"tokenTemplate","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"tokens","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
Deployed ByteCode
0x608060405234801561001057600080fd5b506004361061016c5760003560e01c8063904194a3116100cd578063d544e01011610081578063e30c397811610066578063e30c397814610301578063f2fde38b14610312578063fa69a0b31461032557600080fd5b8063d544e010146102d9578063d5e19157146102ec57600080fd5b806397c6002d116100b257806397c6002d146102a0578063b01b96c3146102b3578063c4091236146102c657600080fd5b8063904194a31461024457806391223d691461026d57600080fd5b80634426dad11161012457806379ba50971161010957806379ba5097146102185780637a9e5e4b146102205780638da5cb5b1461023357600080fd5b80634426dad1146101fd578063715018a61461021057600080fd5b806319d50fcb1161015557806319d50fcb146101b65780631cb928a9146101c9578063379659fc146101ea57600080fd5b80630814d3dd1461017157806312111aa6146101a1575b600080fd5b600654610184906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6101b46101af36600461232c565b610338565b005b6101b46101c436600461236c565b61034c565b6101dc6101d73660046123c9565b610841565b604051908152602001610198565b6101b46101f836600461236c565b610862565b6101dc61020b3660046124e5565b610c5c565b6101b4610c82565b6101b4610c96565b6101b461022e36600461232c565b610d21565b6000546001600160a01b0316610184565b6101846102523660046123c9565b6002602052600090815260409020546001600160a01b031681565b61029061027b36600461232c565b60056020526000908152604090205460ff1681565b6040519015158152602001610198565b6101b46102ae36600461256b565b610d32565b6101b46102c13660046125c2565b61100c565b6101846102d43660046124e5565b611111565b6101b46102e736600461232c565b61113d565b6102f4611214565b6040516101989190612604565b6001546001600160a01b0316610184565b6101b461032036600461232c565b61126c565b6101b461033336600461256b565b6112dd565b6103406114f8565b61034981611552565b50565b83608001354211156103a55760405162461bcd60e51b815260206004820152601e60248201527f4445504c4f595f544f4b454e3a206578706972656420646561646c696e65000060448201526064015b60405180910390fd5b60006103f16103b76020870187612648565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061163892505050565b6000818152600260205260409020549091506001600160a01b03161561047e5760405162461bcd60e51b8152602060048201526024808201527f4445504c4f595f544f4b454e3a20746f6b656e20616c7265616479206465706c60448201527f6f79656400000000000000000000000000000000000000000000000000000000606482015260840161039c565b6104ab604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b60005b6104bb604088018861268f565b905081101561053a57466104d2604089018961268f565b838181106104e2576104e26126d8565b905060600201602001351415610528576104ff604088018861268f565b8281811061050f5761050f6126d8565b9050606002018036038101906105259190612733565b91505b8061053281612765565b9150506104ae565b50602081015161058c5760405162461bcd60e51b815260206004820181905260248201527f4445504c4f595f544f4b454e3a20636861696e206964206e6f74206d61746368604482015260640161039c565b80516001600160a01b0316301461060b5760405162461bcd60e51b815260206004820152602760248201527f4445504c4f595f544f4b454e3a206d69736d6174636820636f6e74726163742060448201527f6164647265737300000000000000000000000000000000000000000000000000606482015260840161039c565b61061482611655565b8160400151146106665760405162461bcd60e51b815260206004820152601b60248201527f4445504c4f595f544f4b454e3a20696e76616c6964206e6f6e63650000000000604482015260640161039c565b600061067961067488612883565b611673565b90506000610689828888886117e8565b6001600160a01b03811660009081526005602052604090205490915060ff166106f45760405162461bcd60e51b815260206004820152601a60248201527f4445504c4f595f544f4b454e3a20756e617574686f72697a6564000000000000604482015260640161039c565b600061077f6107038a80612648565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506107459250505060208c018c612648565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061187492505050565b600086815260026020526040812080546001600160a01b0319166001600160a01b0384161790556004805460018101825591527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b018690559050816001600160a01b0316816001600160a01b03167f82e38afdf01aafc35d5271ed0e16dd76425458f061746bd86f1120e4c32a15a56108153390565b604080516001600160a01b039092168252602082018a90520160405180910390a3505050505050505050565b6004818154811061085157600080fd5b600091825260209091200154905081565b83608001354211156108b65760405162461bcd60e51b815260206004820152601c60248201527f4d494e545f544f4b454e3a206578706972656420646561646c696e6500000000604482015260640161039c565b60006108c56103b78680612648565b6000818152600260205260409020549091506001600160a01b031661092c5760405162461bcd60e51b815260206004820152601b60248201527f4d494e545f544f4b454e3a20746f6b656e206e6f7420666f756e640000000000604482015260640161039c565b610959604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b60005b610969604088018861268f565b90508110156109e85746610980604089018961268f565b83818110610990576109906126d8565b9050606002016020013514156109d6576109ad604088018861268f565b828181106109bd576109bd6126d8565b9050606002018036038101906109d39190612733565b91505b806109e081612765565b91505061095c565b506020810151610a3a5760405162461bcd60e51b815260206004820152601e60248201527f4d494e545f544f4b454e3a20636861696e206964206e6f74206d617463680000604482015260640161039c565b80516001600160a01b03163014610ab95760405162461bcd60e51b815260206004820152602560248201527f4d494e545f544f4b454e3a206d69736d6174636820636f6e747261637420616460448201527f6472657373000000000000000000000000000000000000000000000000000000606482015260840161039c565b610ac282611655565b816040015114610b145760405162461bcd60e51b815260206004820152601960248201527f4d494e545f544f4b454e3a20696e76616c6964206e6f6e636500000000000000604482015260640161039c565b6000610b27610b2288612945565b611912565b90506000610b37828888886117e8565b6001600160a01b03811660009081526005602052604090205490915060ff16610ba25760405162461bcd60e51b815260206004820152601860248201527f4d494e545f544f4b454e3a20756e617574686f72697a65640000000000000000604482015260640161039c565b6000610bf1610bb18a80612648565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250869250505060208c0135611a19565b90506001600160a01b0380831690819083167f2f19f93249fd1e3cb829be5753f476a5bca0e8fd9fe080a327974dc3da2cee3060208d013533604080519283526001600160a01b03909116602083015281018a905260600160405180910390a4505050505050505050565b600080610c6883611638565b6000818152600360205260409020549091505b9392505050565b610c8a6114f8565b610c946000611b2e565b565b60015433906001600160a01b03168114610d185760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f74207468652060448201527f6e6577206f776e65720000000000000000000000000000000000000000000000606482015260840161039c565b61034981611b2e565b610d296114f8565b61034981611b47565b610d3a6114f8565b6000610d7b84848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061163892505050565b6000818152600260205260409020549091506001600160a01b031615610e095760405162461bcd60e51b815260206004820152602260248201527f454e4c4953545f544f4b454e3a20746f6b656e20616c7265616479206578697360448201527f7473000000000000000000000000000000000000000000000000000000000000606482015260840161039c565b6001600160a01b038216610e5f5760405162461bcd60e51b815260206004820152601e60248201527f454e4c4953545f544f4b454e3a206164647265737320697320656d7074790000604482015260640161039c565b306001600160a01b0316826001600160a01b0316638da5cb5b6040518163ffffffff1660e01b815260040160206040518083038186803b158015610ea257600080fd5b505afa158015610eb6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eda91906129a3565b6001600160a01b031614610f565760405162461bcd60e51b815260206004820152603260248201527f454e4c4953545f544f4b454e3a20746f6b656e206973206e6f74206f776e656460448201527f2062792074686520636f6e74726f6c6c65720000000000000000000000000000606482015260840161039c565b610f5f81611655565b50600081815260026020526040812080546001600160a01b0319166001600160a01b0385161790556004805460018101825591527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b018190556001600160a01b0382167f9a6979990408ddc19353e09e9e01b0f9908901ecaa38bc1573e0423639f8454833604080516001600160a01b03909216825260208201859052015b60405180910390a250505050565b6110146114f8565b600061105583838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061163892505050565b6000818152600260205260409020549091506001600160a01b0316806110bd5760405162461bcd60e51b815260206004820152601d60248201527f44454c4953545f544f4b454e3a20746f6b656e206e6f7420666f756e64000000604482015260640161039c565b6110c682611655565b506110d082611cbb565b60408051338152602081018490526001600160a01b038316917f66144e864f2e951c4e7a75fdba76e28c13ec4cdd34e306c23906ad5b471c7ab79101610ffe565b60008061111d83611638565b6000818152600260205260409020549091506001600160a01b0316610c7b565b6111456114f8565b6001600160a01b03811660009081526005602052604090205460ff166111ad5760405162461bcd60e51b815260206004820152601f60248201527f52454d4f56455f415554484f524954593a206e6f7420617574686f7269747900604482015260640161039c565b6001600160a01b0381166000818152600560205260409020805460ff191690557f7cae0cbb9f9c3320f87d8610dd7c2b37098c0fe5c4f9246df36371ccf628ed7d33604080516001600160a01b03909216825260006020830152015b60405180910390a250565b6060600480548060200260200160405190810160405280929190818152602001828054801561126257602002820191906000526020600020905b81548152602001906001019080831161124e575b5050505050905090565b6112746114f8565b600180546001600160a01b0383166001600160a01b031990911681179091556112a56000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6112e56114f8565b6001600160a01b0381166113615760405162461bcd60e51b815260206004820152602a60248201527f4348414e47455f544f4b454e5f415554484f524954593a20617574686f72697460448201527f7920697320656d70747900000000000000000000000000000000000000000000606482015260840161039c565b60006113a284848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061163892505050565b6000818152600260205260409020549091506001600160a01b0316806114305760405162461bcd60e51b815260206004820152602760248201527f4348414e47455f544f4b454e5f415554484f524954593a20746f6b656e206e6f60448201527f7420666f756e6400000000000000000000000000000000000000000000000000606482015260840161039c565b61143982611655565b506114448184611e12565b826001600160a01b0316816001600160a01b03167feb67cd69ed27dcad854aa1e430ae6818242c056575019bbfffefc1327670b1366114803390565b604080516001600160a01b039092168252602082018790520160405180910390a35050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000546001600160a01b03163314610c945760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161039c565b6001600160a01b0381166115ce5760405162461bcd60e51b815260206004820152602a60248201527f5345545f544f4b454e5f54454d504c4154453a20746f6b656e2074656d706c6160448201527f7465206973207a65726f00000000000000000000000000000000000000000000606482015260840161039c565b600680546001600160a01b038381166001600160a01b031983168117909355169081907f63bf103ef2add6b7dc9bdcb352e986fc4b609f0d6cf5c4e17aead7401c30d4ed6116193390565b6040516001600160a01b03909116815260200160405180910390a35050565b8051600090829061164c5750600092915050565b50506020015190565b60008181526003602052604090208054600181018255905b50919050565b60008082604001515167ffffffffffffffff811115611694576116946123e2565b6040519080825280602002602001820160405280156116bd578160200160208202803683370190505b50905060005b836040015151811015611725576116f6846040015182815181106116e9576116e96126d8565b6020026020010151611e8a565b828281518110611708576117086126d8565b60209081029190910101528061171d81612765565b9150506116c3565b5060006117358460600151611f02565b84518051602091820120818701518051908301206040519394506000937fb0d684284bab62fd5887a7ff9bf55a567a90e78b8a82f543d2d7aad12f721eb793611780918891016129c0565b60408051601f1981840301815282825280516020918201206080808d0151928501979097529183019490945260608201929092529283015260a0820184905260c082015260e00160408051601f19818403018152919052805160209091012095945050505050565b604080517f19010000000000000000000000000000000000000000000000000000000000006020808301919091527fd2317b745b025da89e9c9d067662ad1ed75eec0394e1c06e8b1f26f998d1fe4d60228301526042808301889052835180840390910181526062909201909252805191012060009061186a81868686611f62565b9695505050505050565b600654600090819061188e906001600160a01b0316611f8a565b6040517f4cd88b760000000000000000000000000000000000000000000000000000000081529091506001600160a01b03821690634cd88b76906118d89087908790600401612a37565b600060405180830381600087803b1580156118f257600080fd5b505af1158015611906573d6000803e3d6000fd5b50929695505050505050565b60008082604001515167ffffffffffffffff811115611933576119336123e2565b60405190808252806020026020018201604052801561195c578160200160208202803683370190505b50905060005b8360400151518110156119c45761199584604001518281518110611988576119886126d8565b602002602001015161202b565b8282815181106119a7576119a76126d8565b6020908102919091010152806119bc81612765565b915050611962565b5060006119d4846060015161208a565b84518051602091820120818701516040519394506000937f7768cc1a3091453e40ae794b95130b9a7ecd0497b18984c57c52995e34d884fd93611780918891016129c0565b6040517fc4091236000000000000000000000000000000000000000000000000000000008152600090309063c409123690611a58908790600401612a65565b60206040518083038186803b158015611a7057600080fd5b505afa158015611a84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611aa891906129a3565b6040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03858116600483015260248201859052919250908216906340c10f1990604401600060405180830381600087803b158015611b0f57600080fd5b505af1158015611b23573d6000803e3d6000fd5b505050509392505050565b600180546001600160a01b0319169055610349816114a8565b6001600160a01b038116611bc35760405162461bcd60e51b815260206004820152602160248201527f5345545f415554484f524954593a20617574686f7269747920697320656d707460448201527f7900000000000000000000000000000000000000000000000000000000000000606482015260840161039c565b6001600160a01b03811660009081526005602052604090205460ff1615611c525760405162461bcd60e51b815260206004820152602360248201527f5345545f415554484f524954593a20616c726561647920626520617574686f7260448201527f6974790000000000000000000000000000000000000000000000000000000000606482015260840161039c565b6001600160a01b0381166000818152600560205260409020805460ff191660011790557f7cae0cbb9f9c3320f87d8610dd7c2b37098c0fe5c4f9246df36371ccf628ed7d611c9d3390565b604080516001600160a01b0390921682526001602083015201611209565b600081815260026020526040902080546001600160a01b0319169055600454600181148015611d075750816004600081548110611cfa57611cfa6126d8565b9060005260206000200154145b80611d385750816004611d1b600184612a78565b81548110611d2b57611d2b6126d8565b9060005260206000200154145b15611d68576004805480611d4e57611d4e612a8f565b600190038181906000526020600020016000905590555050565b60005b611d76600183612a78565b811015611e00578260048281548110611d9157611d916126d8565b90600052602060002001541415611dee576004611daf600184612a78565b81548110611dbf57611dbf6126d8565b906000526020600020015460048281548110611ddd57611ddd6126d8565b600091825260209091200155611e00565b80611df881612765565b915050611d6b565b506004805480611d4e57611d4e612a8f565b6040517ff2fde38b0000000000000000000000000000000000000000000000000000000081526001600160a01b03828116600483015283169063f2fde38b90602401600060405180830381600087803b158015611e6e57600080fd5b505af1158015611e82573d6000803e3d6000fd5b505050505050565b805160208083015160408085015181517f16be7e703a5ec19023dc1f99e6b1b464b2e71aefd0c9b6e791b34f20755bdd6f948101949094526001600160a01b03909416908301526060820152608081019190915260009060a0015b604051602081830303815290604052805190602001209050919050565b805180516020918201208183015180519083012060408085015181517fc7036020acece1e4e42197d1db5470d4a8c7b7c4071b1b01e6c2e3a007fde9d595810195909552908401929092526060830152608082015260009060a001611ee5565b6000806000611f73878787876120ea565b91509150611f80816121ae565b5095945050505050565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008260601b60e81c176000526e5af43d82803e903d91602b57fd5bf38260781b17602052603760096000f090506001600160a01b0381166120265760405162461bcd60e51b815260206004820152601660248201527f455243313136373a20637265617465206661696c656400000000000000000000604482015260640161039c565b919050565b805160208083015160408085015181517ff926565b58497271466ade9f996776ec81486c663ec41ce3bea33da7e1f9c031948101949094526001600160a01b03909416908301526060820152608081019190915260009060a001611ee5565b805180516020918201208183015180519083012060408085015181517f1169d81a1d4f5d9bdd3142477ed3d12d102799cac7ce46e17f2a3ba127f70c5595810195909552908401929092526060830152608082015260009060a001611ee5565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561212157506000905060036121a5565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612175573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661219e576000600192509250506121a5565b9150600090505b94509492505050565b60008160048111156121c2576121c2612aa5565b14156121cb5750565b60018160048111156121df576121df612aa5565b141561222d5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161039c565b600281600481111561224157612241612aa5565b141561228f5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161039c565b60038160048111156122a3576122a3612aa5565b14156103495760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f7565000000000000000000000000000000000000000000000000000000000000606482015260840161039c565b6001600160a01b038116811461034957600080fd5b60006020828403121561233e57600080fd5b8135610c7b81612317565b600060a0828403121561166d57600080fd5b803560ff8116811461202657600080fd5b6000806000806080858703121561238257600080fd5b843567ffffffffffffffff81111561239957600080fd5b6123a587828801612349565b9450506123b46020860161235b565b93969395505050506040820135916060013590565b6000602082840312156123db57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561241b5761241b6123e2565b60405290565b60405160a0810167ffffffffffffffff8111828210171561241b5761241b6123e2565b604051601f8201601f1916810167ffffffffffffffff8111828210171561246d5761246d6123e2565b604052919050565b600082601f83011261248657600080fd5b813567ffffffffffffffff8111156124a0576124a06123e2565b6124b3601f8201601f1916602001612444565b8181528460208386010111156124c857600080fd5b816020850160208301376000918101602001919091529392505050565b6000602082840312156124f757600080fd5b813567ffffffffffffffff81111561250e57600080fd5b61251a84828501612475565b949350505050565b60008083601f84011261253457600080fd5b50813567ffffffffffffffff81111561254c57600080fd5b60208301915083602082850101111561256457600080fd5b9250929050565b60008060006040848603121561258057600080fd5b833567ffffffffffffffff81111561259757600080fd5b6125a386828701612522565b90945092505060208401356125b781612317565b809150509250925092565b600080602083850312156125d557600080fd5b823567ffffffffffffffff8111156125ec57600080fd5b6125f885828601612522565b90969095509350505050565b6020808252825182820181905260009190848201906040850190845b8181101561263c57835183529284019291840191600101612620565b50909695505050505050565b6000808335601e1984360301811261265f57600080fd5b83018035915067ffffffffffffffff82111561267a57600080fd5b60200191503681900382131561256457600080fd5b6000808335601e198436030181126126a657600080fd5b83018035915067ffffffffffffffff8211156126c157600080fd5b602001915060608102360382131561256457600080fd5b634e487b7160e01b600052603260045260246000fd5b60006060828403121561270057600080fd5b6127086123f8565b9050813561271581612317565b80825250602082013560208201526040820135604082015292915050565b60006060828403121561274557600080fd5b610c7b83836126ee565b634e487b7160e01b600052601160045260246000fd5b60006000198214156127795761277961274f565b5060010190565b600082601f83011261279157600080fd5b8135602067ffffffffffffffff8211156127ad576127ad6123e2565b6127bb818360051b01612444565b828152606092830285018201928282019190878511156127da57600080fd5b8387015b858110156127fd576127f089826126ee565b84529284019281016127de565b5090979650505050505050565b60006060828403121561281c57600080fd5b6128246123f8565b9050813567ffffffffffffffff8082111561283e57600080fd5b61284a85838601612475565b8352602084013591508082111561286057600080fd5b5061286d84828501612475565b6020830152506040820135604082015292915050565b600060a0823603121561289557600080fd5b61289d612421565b823567ffffffffffffffff808211156128b557600080fd5b6128c136838701612475565b835260208501359150808211156128d757600080fd5b6128e336838701612475565b602084015260408501359150808211156128fc57600080fd5b61290836838701612780565b6040840152606085013591508082111561292157600080fd5b5061292e3682860161280a565b606083015250608092830135928101929092525090565b600060a0823603121561295757600080fd5b61295f612421565b823567ffffffffffffffff8082111561297757600080fd5b61298336838701612475565b83526020850135602084015260408501359150808211156128fc57600080fd5b6000602082840312156129b557600080fd5b8151610c7b81612317565b815160009082906020808601845b83811015611906578151855293820193908201906001016129ce565b6000815180845260005b81811015612a10576020818501810151868301820152016129f4565b81811115612a22576000602083870101525b50601f01601f19169290920160200192915050565b604081526000612a4a60408301856129ea565b8281036020840152612a5c81856129ea565b95945050505050565b602081526000610c7b60208301846129ea565b600082821015612a8a57612a8a61274f565b500390565b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052602160045260246000fdfea2646970667358221220965ca6900cc117bbe586919f91efd3c0989bb9e8dea7e0ffcc25a8896d9340df64736f6c63430008090033