Contract is not verified. However, we found a verified contract with the same bytecode in Blockscout DB 0xfd94eab45b98fe5ae749405f92aadfb293e9e462.
All metadata displayed below is from that contract. In order to verify current contract, click Verify & Publish button
Verify & Publish
All metadata displayed below is from that contract. In order to verify current contract, click Verify & Publish button
- Contract name:
- TokenExchanger
- Optimization enabled
- true
- Compiler version
- v0.5.4+commit.9549d8ff
- Optimization runs
- 200
- Verified at
- 2023-01-03T08:54:19.594934Z
Contract source code
pragma solidity ^0.5.4; /** * @title Module * @dev Interface for a module. * A module MUST implement the addModule() method to ensure that a wallet with at least one module * can never end up in a "frozen" state. * @author Julien Niset - <julien@argent.xyz> */ interface Module { /** * @dev Inits a module for a wallet by e.g. setting some wallet specific parameters in storage. * @param _wallet The wallet. */ function init(BaseWallet _wallet) external; /** * @dev Adds a module to a wallet. * @param _wallet The target wallet. * @param _module The modules to authorise. */ function addModule(BaseWallet _wallet, Module _module) external; /** * @dev Utility method to recover any ERC20 token that was sent to the * module by mistake. * @param _token The token to recover. */ function recoverToken(address _token) external; } /** * @title BaseWallet * @dev Simple modular wallet that authorises modules to call its invoke() method. * Based on https://gist.github.com/Arachnid/a619d31f6d32757a4328a428286da186 by * @author Julien Niset - <julien@argent.im> */ contract BaseWallet { // The implementation of the proxy address public implementation; // The owner address public owner; // The authorised modules mapping (address => bool) public authorised; // The enabled static calls mapping (bytes4 => address) public enabled; // The number of modules uint public modules; event AuthorisedModule(address indexed module, bool value); event EnabledStaticCall(address indexed module, bytes4 indexed method); event Invoked(address indexed module, address indexed target, uint indexed value, bytes data); event Received(uint indexed value, address indexed sender, bytes data); event OwnerChanged(address owner); /** * @dev Throws if the sender is not an authorised module. */ modifier moduleOnly { require(authorised[msg.sender], "BW: msg.sender not an authorized module"); _; } /** * @dev Inits the wallet by setting the owner and authorising a list of modules. * @param _owner The owner. * @param _modules The modules to authorise. */ function init(address _owner, address[] calldata _modules) external { require(owner == address(0) && modules == 0, "BW: wallet already initialised"); require(_modules.length > 0, "BW: construction requires at least 1 module"); owner = _owner; modules = _modules.length; for(uint256 i = 0; i < _modules.length; i++) { require(authorised[_modules[i]] == false, "BW: module is already added"); authorised[_modules[i]] = true; Module(_modules[i]).init(this); emit AuthorisedModule(_modules[i], true); } if (address(this).balance > 0) { emit Received(address(this).balance, address(0), ""); } } /** * @dev Enables/Disables a module. * @param _module The target module. * @param _value Set to true to authorise the module. */ function authoriseModule(address _module, bool _value) external moduleOnly { if (authorised[_module] != _value) { emit AuthorisedModule(_module, _value); if(_value == true) { modules += 1; authorised[_module] = true; Module(_module).init(this); } else { modules -= 1; require(modules > 0, "BW: wallet must have at least one module"); delete authorised[_module]; } } } /** * @dev Enables a static method by specifying the target module to which the call * must be delegated. * @param _module The target module. * @param _method The static method signature. */ function enableStaticCall(address _module, bytes4 _method) external moduleOnly { require(authorised[_module], "BW: must be an authorised module for static call"); enabled[_method] = _module; emit EnabledStaticCall(_module, _method); } /** * @dev Sets a new owner for the wallet. * @param _newOwner The new owner. */ function setOwner(address _newOwner) external moduleOnly { require(_newOwner != address(0), "BW: address cannot be null"); owner = _newOwner; emit OwnerChanged(_newOwner); } /** * @dev Performs a generic transaction. * @param _target The address for the transaction. * @param _value The value of the transaction. * @param _data The data of the transaction. */ function invoke(address _target, uint _value, bytes calldata _data) external moduleOnly returns (bytes memory _result) { bool success; // solium-disable-next-line security/no-call-value (success, _result) = _target.call.value(_value)(_data); if(!success) { // solium-disable-next-line security/no-inline-assembly assembly { returndatacopy(0, 0, returndatasize) revert(0, returndatasize) } } emit Invoked(msg.sender, _target, _value, _data); } /** * @dev This method makes it possible for the wallet to comply to interfaces expecting the wallet to * implement specific static methods. It delegates the static call to a target contract if the data corresponds * to an enabled method, or logs the call otherwise. */ function() external payable { if(msg.data.length > 0) { address module = enabled[msg.sig]; if(module == address(0)) { emit Received(msg.value, msg.sender, msg.data); } else { require(authorised[module], "BW: must be an authorised module for static call"); // solium-disable-next-line security/no-inline-assembly assembly { calldatacopy(0, 0, calldatasize()) let result := staticcall(gas, module, 0, calldatasize(), 0, 0) returndatacopy(0, 0, returndatasize()) switch result case 0 {revert(0, returndatasize())} default {return (0, returndatasize())} } } } } } /** * @title Owned * @dev Basic contract to define an owner. * @author Julien Niset - <julien@argent.im> */ contract Owned { // The owner address public owner; event OwnerChanged(address indexed _newOwner); /** * @dev Throws if the sender is not the owner. */ modifier onlyOwner { require(msg.sender == owner, "Must be owner"); _; } constructor() public { owner = msg.sender; } /** * @dev Lets the owner transfer ownership of the contract to a new owner. * @param _newOwner The new owner. */ function changeOwner(address _newOwner) external onlyOwner { require(_newOwner != address(0), "Address must not be null"); owner = _newOwner; emit OwnerChanged(_newOwner); } } /** * ERC20 contract interface. */ contract ERC20 { function totalSupply() public view returns (uint); function decimals() public view returns (uint); function balanceOf(address tokenOwner) public view returns (uint balance); function allowance(address tokenOwner, address spender) public view returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); } /** * @title ModuleRegistry * @dev Registry of authorised modules. * Modules must be registered before they can be authorised on a wallet. * @author Julien Niset - <julien@argent.im> */ contract ModuleRegistry is Owned { mapping (address => Info) internal modules; mapping (address => Info) internal upgraders; event ModuleRegistered(address indexed module, bytes32 name); event ModuleDeRegistered(address module); event UpgraderRegistered(address indexed upgrader, bytes32 name); event UpgraderDeRegistered(address upgrader); struct Info { bool exists; bytes32 name; } /** * @dev Registers a module. * @param _module The module. * @param _name The unique name of the module. */ function registerModule(address _module, bytes32 _name) external onlyOwner { require(!modules[_module].exists, "MR: module already exists"); modules[_module] = Info({exists: true, name: _name}); emit ModuleRegistered(_module, _name); } /** * @dev Deregisters a module. * @param _module The module. */ function deregisterModule(address _module) external onlyOwner { require(modules[_module].exists, "MR: module does not exist"); delete modules[_module]; emit ModuleDeRegistered(_module); } /** * @dev Registers an upgrader. * @param _upgrader The upgrader. * @param _name The unique name of the upgrader. */ function registerUpgrader(address _upgrader, bytes32 _name) external onlyOwner { require(!upgraders[_upgrader].exists, "MR: upgrader already exists"); upgraders[_upgrader] = Info({exists: true, name: _name}); emit UpgraderRegistered(_upgrader, _name); } /** * @dev Deregisters an upgrader. * @param _upgrader The _upgrader. */ function deregisterUpgrader(address _upgrader) external onlyOwner { require(upgraders[_upgrader].exists, "MR: upgrader does not exist"); delete upgraders[_upgrader]; emit UpgraderDeRegistered(_upgrader); } /** * @dev Utility method enbaling the owner of the registry to claim any ERC20 token that was sent to the * registry. * @param _token The token to recover. */ function recoverToken(address _token) external onlyOwner { uint total = ERC20(_token).balanceOf(address(this)); ERC20(_token).transfer(msg.sender, total); } /** * @dev Gets the name of a module from its address. * @param _module The module address. * @return the name. */ function moduleInfo(address _module) external view returns (bytes32) { return modules[_module].name; } /** * @dev Gets the name of an upgrader from its address. * @param _upgrader The upgrader address. * @return the name. */ function upgraderInfo(address _upgrader) external view returns (bytes32) { return upgraders[_upgrader].name; } /** * @dev Checks if a module is registered. * @param _module The module address. * @return true if the module is registered. */ function isRegisteredModule(address _module) external view returns (bool) { return modules[_module].exists; } /** * @dev Checks if a list of modules are registered. * @param _modules The list of modules address. * @return true if all the modules are registered. */ function isRegisteredModule(address[] calldata _modules) external view returns (bool) { for(uint i = 0; i < _modules.length; i++) { if (!modules[_modules[i]].exists) { return false; } } return true; } /** * @dev Checks if an upgrader is registered. * @param _upgrader The upgrader address. * @return true if the upgrader is registered. */ function isRegisteredUpgrader(address _upgrader) external view returns (bool) { return upgraders[_upgrader].exists; } } /** * @title BaseModule * @dev Basic module that contains some methods common to all modules. * @author Julien Niset - <julien@argent.im> */ contract BaseModule is Module { // The adddress of the module registry. ModuleRegistry internal registry; event ModuleCreated(bytes32 name); event ModuleInitialised(address wallet); constructor(ModuleRegistry _registry, bytes32 _name) public { registry = _registry; emit ModuleCreated(_name); } /** * @dev Throws if the sender is not the target wallet of the call. */ modifier onlyWallet(BaseWallet _wallet) { require(msg.sender == address(_wallet), "BM: caller must be wallet"); _; } /** * @dev Throws if the sender is not the owner of the target wallet or the module itself. */ modifier onlyWalletOwner(BaseWallet _wallet) { require(msg.sender == address(this) || isOwner(_wallet, msg.sender), "BM: must be an owner for the wallet"); _; } /** * @dev Throws if the sender is not the owner of the target wallet. */ modifier strictOnlyWalletOwner(BaseWallet _wallet) { require(isOwner(_wallet, msg.sender), "BM: msg.sender must be an owner for the wallet"); _; } /** * @dev Inits the module for a wallet by logging an event. * The method can only be called by the wallet itself. * @param _wallet The wallet. */ function init(BaseWallet _wallet) public onlyWallet(_wallet) { emit ModuleInitialised(address(_wallet)); } /** * @dev Adds a module to a wallet. First checks that the module is registered. * @param _wallet The target wallet. * @param _module The modules to authorise. */ function addModule(BaseWallet _wallet, Module _module) external strictOnlyWalletOwner(_wallet) { require(registry.isRegisteredModule(address(_module)), "BM: module is not registered"); _wallet.authoriseModule(address(_module), true); } /** * @dev Utility method enbaling anyone to recover ERC20 token sent to the * module by mistake and transfer them to the Module Registry. * @param _token The token to recover. */ function recoverToken(address _token) external { uint total = ERC20(_token).balanceOf(address(this)); ERC20(_token).transfer(address(registry), total); } /** * @dev Helper method to check if an address is the owner of a target wallet. * @param _wallet The target wallet. * @param _addr The address. */ function isOwner(BaseWallet _wallet, address _addr) internal view returns (bool) { return _wallet.owner() == _addr; } /** * @dev Helper method to invoke a wallet. * @param _wallet The target wallet. * @param _to The target address for the transaction. * @param _value The value of the transaction. * @param _data The data of the transaction. */ function invokeWallet(address _wallet, address _to, uint256 _value, bytes memory _data) internal returns (bytes memory _res) { bool success; // solium-disable-next-line security/no-call-value (success, _res) = _wallet.call(abi.encodeWithSignature("invoke(address,uint256,bytes)", _to, _value, _data)); if(success && _res.length > 0) { //_res is empty if _wallet is an "old" BaseWallet that can't return output values (_res) = abi.decode(_res, (bytes)); } else if (_res.length > 0) { // solium-disable-next-line security/no-inline-assembly assembly { returndatacopy(0, 0, returndatasize) revert(0, returndatasize) } } else if(!success) { revert("BM: wallet invoke reverted"); } } } /** * @title RelayerModule * @dev Base module containing logic to execute transactions signed by eth-less accounts and sent by a relayer. * @author Julien Niset - <julien@argent.im> */ contract RelayerModule is Module { uint256 constant internal BLOCKBOUND = 10000; mapping (address => RelayerConfig) public relayer; struct RelayerConfig { uint256 nonce; mapping (bytes32 => bool) executedTx; } event TransactionExecuted(address indexed wallet, bool indexed success, bytes32 signedHash); /** * @dev Throws if the call did not go through the execute() method. */ modifier onlyExecute { require(msg.sender == address(this), "RM: must be called via execute()"); _; } /* ***************** Abstract method ************************* */ /** * @dev Gets the number of valid signatures that must be provided to execute a * specific relayed transaction. * @param _wallet The target wallet. * @param _data The data of the relayed transaction. * @return The number of required signatures. */ function getRequiredSignatures(BaseWallet _wallet, bytes memory _data) internal view returns (uint256); /** * @dev Validates the signatures provided with a relayed transaction. * The method MUST throw if one or more signatures are not valid. * @param _wallet The target wallet. * @param _data The data of the relayed transaction. * @param _signHash The signed hash representing the relayed transaction. * @param _signatures The signatures as a concatenated byte array. */ function validateSignatures(BaseWallet _wallet, bytes memory _data, bytes32 _signHash, bytes memory _signatures) internal view returns (bool); /* ************************************************************ */ /** * @dev Executes a relayed transaction. * @param _wallet The target wallet. * @param _data The data for the relayed transaction * @param _nonce The nonce used to prevent replay attacks. * @param _signatures The signatures as a concatenated byte array. * @param _gasPrice The gas price to use for the gas refund. * @param _gasLimit The gas limit to use for the gas refund. */ function execute( BaseWallet _wallet, bytes calldata _data, uint256 _nonce, bytes calldata _signatures, uint256 _gasPrice, uint256 _gasLimit ) external returns (bool success) { uint startGas = gasleft(); bytes32 signHash = getSignHash(address(this), address(_wallet), 0, _data, _nonce, _gasPrice, _gasLimit); require(checkAndUpdateUniqueness(_wallet, _nonce, signHash), "RM: Duplicate request"); require(verifyData(address(_wallet), _data), "RM: the wallet authorized is different then the target of the relayed data"); uint256 requiredSignatures = getRequiredSignatures(_wallet, _data); if((requiredSignatures * 65) == _signatures.length) { if(verifyRefund(_wallet, _gasLimit, _gasPrice, requiredSignatures)) { if(requiredSignatures == 0 || validateSignatures(_wallet, _data, signHash, _signatures)) { // solium-disable-next-line security/no-call-value (success,) = address(this).call(_data); refund(_wallet, startGas - gasleft(), _gasPrice, _gasLimit, requiredSignatures, msg.sender); } } } emit TransactionExecuted(address(_wallet), success, signHash); } /** * @dev Gets the current nonce for a wallet. * @param _wallet The target wallet. */ function getNonce(BaseWallet _wallet) external view returns (uint256 nonce) { return relayer[address(_wallet)].nonce; } /** * @dev Generates the signed hash of a relayed transaction according to ERC 1077. * @param _from The starting address for the relayed transaction (should be the module) * @param _to The destination address for the relayed transaction (should be the wallet) * @param _value The value for the relayed transaction * @param _data The data for the relayed transaction * @param _nonce The nonce used to prevent replay attacks. * @param _gasPrice The gas price to use for the gas refund. * @param _gasLimit The gas limit to use for the gas refund. */ function getSignHash( address _from, address _to, uint256 _value, bytes memory _data, uint256 _nonce, uint256 _gasPrice, uint256 _gasLimit ) internal pure returns (bytes32) { return keccak256( abi.encodePacked( "\x19Ethereum Signed Message:\n32", keccak256(abi.encodePacked(byte(0x19), byte(0), _from, _to, _value, _data, _nonce, _gasPrice, _gasLimit)) )); } /** * @dev Checks if the relayed transaction is unique. * @param _wallet The target wallet. * @param _nonce The nonce * @param _signHash The signed hash of the transaction */ function checkAndUpdateUniqueness(BaseWallet _wallet, uint256 _nonce, bytes32 _signHash) internal returns (bool) { if(relayer[address(_wallet)].executedTx[_signHash] == true) { return false; } relayer[address(_wallet)].executedTx[_signHash] = true; return true; } /** * @dev Checks that a nonce has the correct format and is valid. * It must be constructed as nonce = {block number}{timestamp} where each component is 16 bytes. * @param _wallet The target wallet. * @param _nonce The nonce */ function checkAndUpdateNonce(BaseWallet _wallet, uint256 _nonce) internal returns (bool) { if(_nonce <= relayer[address(_wallet)].nonce) { return false; } uint256 nonceBlock = (_nonce & 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000) >> 128; if(nonceBlock > block.number + BLOCKBOUND) { return false; } relayer[address(_wallet)].nonce = _nonce; return true; } /** * @dev Recovers the signer at a given position from a list of concatenated signatures. * @param _signedHash The signed hash * @param _signatures The concatenated signatures. * @param _index The index of the signature to recover. */ function recoverSigner(bytes32 _signedHash, bytes memory _signatures, uint _index) internal pure returns (address) { uint8 v; bytes32 r; bytes32 s; // we jump 32 (0x20) as the first slot of bytes contains the length // we jump 65 (0x41) per signature // for v we load 32 bytes ending with v (the first 31 come from s) then apply a mask // solium-disable-next-line security/no-inline-assembly assembly { r := mload(add(_signatures, add(0x20,mul(0x41,_index)))) s := mload(add(_signatures, add(0x40,mul(0x41,_index)))) v := and(mload(add(_signatures, add(0x41,mul(0x41,_index)))), 0xff) } require(v == 27 || v == 28); return ecrecover(_signedHash, v, r, s); } /** * @dev Refunds the gas used to the Relayer. * For security reasons the default behavior is to not refund calls with 0 or 1 signatures. * @param _wallet The target wallet. * @param _gasUsed The gas used. * @param _gasPrice The gas price for the refund. * @param _gasLimit The gas limit for the refund. * @param _signatures The number of signatures used in the call. * @param _relayer The address of the Relayer. */ function refund(BaseWallet _wallet, uint _gasUsed, uint _gasPrice, uint _gasLimit, uint _signatures, address _relayer) internal { uint256 amount = 29292 + _gasUsed; // 21000 (transaction) + 7620 (execution of refund) + 672 to log the event + _gasUsed // only refund if gas price not null, more than 1 signatures, gas less than gasLimit if(_gasPrice > 0 && _signatures > 1 && amount <= _gasLimit) { if(_gasPrice > tx.gasprice) { amount = amount * tx.gasprice; } else { amount = amount * _gasPrice; } _wallet.invoke(_relayer, amount, ""); } } /** * @dev Returns false if the refund is expected to fail. * @param _wallet The target wallet. * @param _gasUsed The expected gas used. * @param _gasPrice The expected gas price for the refund. */ function verifyRefund(BaseWallet _wallet, uint _gasUsed, uint _gasPrice, uint _signatures) internal view returns (bool) { if(_gasPrice > 0 && _signatures > 1 && (address(_wallet).balance < _gasUsed * _gasPrice || _wallet.authorised(address(this)) == false)) { return false; } return true; } /** * @dev Checks that the wallet address provided as the first parameter of the relayed data is the same * as the wallet passed as the input of the execute() method. @return false if the addresses are different. */ function verifyData(address _wallet, bytes memory _data) private pure returns (bool) { require(_data.length >= 36, "RM: Invalid dataWallet"); address dataWallet; // solium-disable-next-line security/no-inline-assembly assembly { //_data = {length:32}{sig:4}{_wallet:32}{...} dataWallet := mload(add(_data, 0x24)) } return dataWallet == _wallet; } /** * @dev Parses the data to extract the method signature. */ function functionPrefix(bytes memory _data) internal pure returns (bytes4 prefix) { require(_data.length >= 4, "RM: Invalid functionPrefix"); // solium-disable-next-line security/no-inline-assembly assembly { prefix := mload(add(_data, 0x20)) } } } /** * @title OnlyOwnerModule * @dev Module that extends BaseModule and RelayerModule for modules where the execute() method * must be called with one signature frm the owner. * @author Julien Niset - <julien@argent.im> */ contract OnlyOwnerModule is BaseModule, RelayerModule { // bytes4 private constant IS_ONLY_OWNER_MODULE = bytes4(keccak256("isOnlyOwnerModule()")); /** * @dev Returns a constant that indicates that the module is an OnlyOwnerModule. * @return The constant bytes4(keccak256("isOnlyOwnerModule()")) */ function isOnlyOwnerModule() external pure returns (bytes4) { // return IS_ONLY_OWNER_MODULE; return this.isOnlyOwnerModule.selector; } /** * @dev Adds a module to a wallet. First checks that the module is registered. * Unlike its overrided parent, this method can be called via the RelayerModule's execute() * @param _wallet The target wallet. * @param _module The modules to authorise. */ function addModule(BaseWallet _wallet, Module _module) external onlyWalletOwner(_wallet) { require(registry.isRegisteredModule(address(_module)), "BM: module is not registered"); _wallet.authoriseModule(address(_module), true); } // *************** Implementation of RelayerModule methods ********************* // // Overrides to use the incremental nonce and save some gas function checkAndUpdateUniqueness(BaseWallet _wallet, uint256 _nonce, bytes32 /* _signHash */) internal returns (bool) { return checkAndUpdateNonce(_wallet, _nonce); } function validateSignatures( BaseWallet _wallet, bytes memory /* _data */, bytes32 _signHash, bytes memory _signatures ) internal view returns (bool) { address signer = recoverSigner(_signHash, _signatures, 0); return isOwner(_wallet, signer); // "OOM: signer must be owner" } function getRequiredSignatures(BaseWallet /* _wallet */, bytes memory /* _data */) internal view returns (uint256) { return 1; } } /* The MIT License (MIT) Copyright (c) 2016 Smart Contract Solutions, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, reverts on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b); return c; } /** * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0); // Solidity only automatically asserts when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a); uint256 c = a - b; return c; } /** * @dev Adds two numbers, reverts on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a); return c; } /** * @dev Divides two numbers and returns the remainder (unsigned integer modulo), * reverts when dividing by zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0); return a % b; } /** * @dev Returns ceil(a / b). */ function ceil(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a / b; if(a % b == 0) { return c; } else { return c + 1; } } // from DSMath - operations on fixed precision floats uint256 constant WAD = 10 ** 18; uint256 constant RAY = 10 ** 27; function wmul(uint256 x, uint256 y) internal pure returns (uint256 z) { z = add(mul(x, y), WAD / 2) / WAD; } function rmul(uint256 x, uint256 y) internal pure returns (uint256 z) { z = add(mul(x, y), RAY / 2) / RAY; } function wdiv(uint256 x, uint256 y) internal pure returns (uint256 z) { z = add(mul(x, WAD), y / 2) / y; } function rdiv(uint256 x, uint256 y) internal pure returns (uint256 z) { z = add(mul(x, RAY), y / 2) / y; } } contract KyberNetwork { function getExpectedRate( ERC20 src, ERC20 dest, uint srcQty ) public view returns (uint expectedRate, uint slippageRate); function trade( ERC20 src, uint srcAmount, ERC20 dest, address payable destAddress, uint maxDestAmount, uint minConversionRate, address walletId ) public payable returns(uint); } /** * @title Storage * @dev Base contract for the storage of a wallet. * @author Julien Niset - <julien@argent.im> */ contract Storage { /** * @dev Throws if the caller is not an authorised module. */ modifier onlyModule(BaseWallet _wallet) { require(_wallet.authorised(msg.sender), "TS: must be an authorized module to call this method"); _; } } /** * @title GuardianStorage * @dev Contract storing the state of wallets related to guardians and lock. * The contract only defines basic setters and getters with no logic. Only modules authorised * for a wallet can modify its state. * @author Julien Niset - <julien@argent.im> * @author Olivier Van Den Biggelaar - <olivier@argent.im> */ contract GuardianStorage is Storage { struct GuardianStorageConfig { // the list of guardians address[] guardians; // the info about guardians mapping (address => GuardianInfo) info; // the lock's release timestamp uint256 lock; // the module that set the last lock address locker; } struct GuardianInfo { bool exists; uint128 index; } // wallet specific storage mapping (address => GuardianStorageConfig) internal configs; // *************** External Functions ********************* // /** * @dev Lets an authorised module add a guardian to a wallet. * @param _wallet The target wallet. * @param _guardian The guardian to add. */ function addGuardian(BaseWallet _wallet, address _guardian) external onlyModule(_wallet) { GuardianStorageConfig storage config = configs[address(_wallet)]; config.info[_guardian].exists = true; config.info[_guardian].index = uint128(config.guardians.push(_guardian) - 1); } /** * @dev Lets an authorised module revoke a guardian from a wallet. * @param _wallet The target wallet. * @param _guardian The guardian to revoke. */ function revokeGuardian(BaseWallet _wallet, address _guardian) external onlyModule(_wallet) { GuardianStorageConfig storage config = configs[address(_wallet)]; address lastGuardian = config.guardians[config.guardians.length - 1]; if (_guardian != lastGuardian) { uint128 targetIndex = config.info[_guardian].index; config.guardians[targetIndex] = lastGuardian; config.info[lastGuardian].index = targetIndex; } config.guardians.length--; delete config.info[_guardian]; } /** * @dev Returns the number of guardians for a wallet. * @param _wallet The target wallet. * @return the number of guardians. */ function guardianCount(BaseWallet _wallet) external view returns (uint256) { return configs[address(_wallet)].guardians.length; } /** * @dev Gets the list of guaridans for a wallet. * @param _wallet The target wallet. * @return the list of guardians. */ function getGuardians(BaseWallet _wallet) external view returns (address[] memory) { GuardianStorageConfig storage config = configs[address(_wallet)]; address[] memory guardians = new address[](config.guardians.length); for (uint256 i = 0; i < config.guardians.length; i++) { guardians[i] = config.guardians[i]; } return guardians; } /** * @dev Checks if an account is a guardian for a wallet. * @param _wallet The target wallet. * @param _guardian The account. * @return true if the account is a guardian for a wallet. */ function isGuardian(BaseWallet _wallet, address _guardian) external view returns (bool) { return configs[address(_wallet)].info[_guardian].exists; } /** * @dev Lets an authorised module set the lock for a wallet. * @param _wallet The target wallet. * @param _releaseAfter The epoch time at which the lock should automatically release. */ function setLock(BaseWallet _wallet, uint256 _releaseAfter) external onlyModule(_wallet) { configs[address(_wallet)].lock = _releaseAfter; if(_releaseAfter != 0 && msg.sender != configs[address(_wallet)].locker) { configs[address(_wallet)].locker = msg.sender; } } /** * @dev Checks if the lock is set for a wallet. * @param _wallet The target wallet. * @return true if the lock is set for the wallet. */ function isLocked(BaseWallet _wallet) external view returns (bool) { return configs[address(_wallet)].lock > now; } /** * @dev Gets the time at which the lock of a wallet will release. * @param _wallet The target wallet. * @return the time at which the lock of a wallet will release, or zero if there is no lock set. */ function getLock(BaseWallet _wallet) external view returns (uint256) { return configs[address(_wallet)].lock; } /** * @dev Gets the address of the last module that modified the lock for a wallet. * @param _wallet The target wallet. * @return the address of the last module that modified the lock for a wallet. */ function getLocker(BaseWallet _wallet) external view returns (address) { return configs[address(_wallet)].locker; } } /** * @title TokenExchanger * @dev Module to trade tokens (ETH or ERC20) using KyberNetworks. * @author Julien Niset - <julien@argent.im> */ contract TokenExchanger is BaseModule, RelayerModule, OnlyOwnerModule { bytes32 constant NAME = "TokenExchanger"; using SafeMath for uint256; // Mock token address for ETH address constant internal ETH_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // The address of the KyberNetwork proxy contract address public kyber; // The address of the contract collecting fees for Argent. address public feeCollector; // The Argent fee in 1-per-10000. uint256 public feeRatio; // The Guardian storage GuardianStorage public guardianStorage; event TokenExchanged(address indexed wallet, address srcToken, uint srcAmount, address destToken, uint destAmount); /** * @dev Throws if the wallet is locked. */ modifier onlyWhenUnlocked(BaseWallet _wallet) { // solium-disable-next-line security/no-block-members require(!guardianStorage.isLocked(_wallet), "TT: wallet must be unlocked"); _; } constructor( ModuleRegistry _registry, GuardianStorage _guardianStorage, address _kyber, address _feeCollector, uint _feeRatio ) BaseModule(_registry, NAME) public { kyber = _kyber; feeCollector = _feeCollector; feeRatio = _feeRatio; guardianStorage = _guardianStorage; } /** * @dev Lets the owner of the wallet execute a trade. * @param _wallet The target wallet * @param _srcToken The address of the source token. * @param _srcAmount The amoutn of source token to trade. * @param _destToken The address of the destination token. * @param _maxDestAmount The maximum amount of destination token accepted for the trade. * @param _minConversionRate The minimum accepted rate for the trade. * @return The amount of destination tokens that have been received. */ function trade( BaseWallet _wallet, address _srcToken, uint256 _srcAmount, address _destToken, uint256 _maxDestAmount, uint256 _minConversionRate ) external onlyWalletOwner(_wallet) onlyWhenUnlocked(_wallet) returns(uint256) { bytes memory methodData; require(_srcToken == ETH_TOKEN_ADDRESS || _destToken == ETH_TOKEN_ADDRESS, "TE: source or destination must be ETH"); (uint256 destAmount, uint256 fee, ) = getExpectedTrade(_srcToken, _destToken, _srcAmount); if(destAmount > _maxDestAmount) { fee = fee.mul(_maxDestAmount).div(destAmount); destAmount = _maxDestAmount; } if(_srcToken == ETH_TOKEN_ADDRESS) { uint256 srcTradable = _srcAmount.sub(fee); methodData = abi.encodeWithSignature( "trade(address,uint256,address,address,uint256,uint256,address)", _srcToken, srcTradable, _destToken, address(_wallet), _maxDestAmount, _minConversionRate, feeCollector ); _wallet.invoke(kyber, srcTradable, methodData); } else { // approve kyber on erc20 methodData = abi.encodeWithSignature("approve(address,uint256)", kyber, _srcAmount); _wallet.invoke(_srcToken, 0, methodData); // transfer erc20 methodData = abi.encodeWithSignature( "trade(address,uint256,address,address,uint256,uint256,address)", _srcToken, _srcAmount, _destToken, address(_wallet), _maxDestAmount, _minConversionRate, feeCollector ); _wallet.invoke(kyber, 0, methodData); } if (fee > 0) { _wallet.invoke(feeCollector, fee, ""); } emit TokenExchanged(address(_wallet), _srcToken, _srcAmount, _destToken, destAmount); return destAmount; } /** * @dev Gets the expected terms of a trade. * @param _srcToken The address of the source token. * @param _destToken The address of the destination token. * @param _srcAmount The amount of source token to trade. * @return the amount of destination tokens to be received and the amount of ETH paid to Argent as fee. */ function getExpectedTrade( address _srcToken, address _destToken, uint256 _srcAmount ) public view returns(uint256 _destAmount, uint256 _fee, uint256 _expectedRate) { if(_srcToken == ETH_TOKEN_ADDRESS) { _fee = computeFee(_srcAmount); (_expectedRate,) = KyberNetwork(kyber).getExpectedRate(ERC20(_srcToken), ERC20(_destToken), _srcAmount.sub(_fee)); uint256 destDecimals = ERC20(_destToken).decimals(); // destAmount = expectedRate * (_srcAmount - fee) / ETH_PRECISION * (DEST_PRECISION / SRC_PRECISION) _destAmount = _expectedRate.mul(_srcAmount.sub(_fee)).div(10 ** (36-destDecimals)); } else { (_expectedRate,) = KyberNetwork(kyber).getExpectedRate(ERC20(_srcToken), ERC20(_destToken), _srcAmount); uint256 srcDecimals = ERC20(_srcToken).decimals(); // destAmount = expectedRate * _srcAmount / ETH_PRECISION * (DEST_PRECISION / SRC_PRECISION) - fee _destAmount = _expectedRate.mul(_srcAmount).div(10 ** srcDecimals); _fee = computeFee(_destAmount); _destAmount -= _fee; } } /** * @dev Computes the Argent fee based on the amount of source tokens in ETH. * @param _srcAmount The amount of source token to trade in ETH. * @return the fee paid to Argent. */ function computeFee(uint256 _srcAmount) internal view returns (uint256 fee) { fee = (_srcAmount * feeRatio) / 10000; } }
Contract ABI
[{"type":"constructor","inputs":[{"type":"address","name":"_registry"},{"type":"address","name":"_guardianStorage"},{"type":"address","name":"_kyber"},{"type":"address","name":"_feeCollector"},{"type":"uint256","name":"_feeRatio"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addModule","inputs":[{"type":"address","name":"_wallet"},{"type":"address","name":"_module"}],"constant":false},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"success"}],"name":"execute","inputs":[{"type":"address","name":"_wallet"},{"type":"bytes","name":"_data"},{"type":"uint256","name":"_nonce"},{"type":"bytes","name":"_signatures"},{"type":"uint256","name":"_gasPrice"},{"type":"uint256","name":"_gasLimit"}],"constant":false},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":""}],"name":"feeCollector","inputs":[],"constant":true},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":""}],"name":"feeRatio","inputs":[],"constant":true},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"_destAmount"},{"type":"uint256","name":"_fee"},{"type":"uint256","name":"_expectedRate"}],"name":"getExpectedTrade","inputs":[{"type":"address","name":"_srcToken"},{"type":"address","name":"_destToken"},{"type":"uint256","name":"_srcAmount"}],"constant":true},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"nonce"}],"name":"getNonce","inputs":[{"type":"address","name":"_wallet"}],"constant":true},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":""}],"name":"guardianStorage","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"init","inputs":[{"type":"address","name":"_wallet"}],"constant":false},{"type":"function","stateMutability":"pure","outputs":[{"type":"bytes4","name":""}],"name":"isOnlyOwnerModule","inputs":[],"constant":true},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":""}],"name":"kyber","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"recoverToken","inputs":[{"type":"address","name":"_token"}],"constant":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"nonce"}],"name":"relayer","inputs":[{"type":"address","name":""}],"constant":true},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":""}],"name":"trade","inputs":[{"type":"address","name":"_wallet"},{"type":"address","name":"_srcToken"},{"type":"uint256","name":"_srcAmount"},{"type":"address","name":"_destToken"},{"type":"uint256","name":"_maxDestAmount"},{"type":"uint256","name":"_minConversionRate"}],"constant":false},{"type":"event","name":"ModuleCreated","inputs":[{"type":"bytes32","name":"name","indexed":false}],"anonymous":false},{"type":"event","name":"ModuleInitialised","inputs":[{"type":"address","name":"wallet","indexed":false}],"anonymous":false},{"type":"event","name":"TokenExchanged","inputs":[{"type":"address","name":"wallet","indexed":true},{"type":"address","name":"srcToken","indexed":false},{"type":"uint256","name":"srcAmount","indexed":false},{"type":"address","name":"destToken","indexed":false},{"type":"uint256","name":"destAmount","indexed":false}],"anonymous":false},{"type":"event","name":"TransactionExecuted","inputs":[{"type":"address","name":"wallet","indexed":true},{"type":"bool","name":"success","indexed":true},{"type":"bytes32","name":"signedHash","indexed":false}],"anonymous":false}]
Contract Creation Code
0x608060405234801561001057600080fd5b5060405160a080612019833981018060405260a081101561003057600080fd5b508051602080830151604080850151606086015160809096015160008054600160a060020a031916600160a060020a03881617905582517f546f6b656e45786368616e67657200000000000000000000000000000000000080825293519697949692959193889390927f3019c8fc80239e3dff8f781212ae2004839c2cb61d6c70acd279ac65392145df928290030190a1505060028054600160a060020a03948516600160a060020a03199182161790915560038054938516938216939093179092556004556005805493909216921691909117905550611f03806101166000396000f3fe608060405234801561001057600080fd5b50600436106100d35760003560e060020a900480639be65a6011610090578063c415b95c1161006a578063c415b95c14610346578063c9b5ef8e1461034e578063d490da4d14610374578063d89784fc146103b1576100d3565b80639be65a601461020c578063a2d10ba514610232578063aacaaf8814610256576100d3565b806319ab453c146100d85780632d0335ab146101005780632d8da11a1461013857806341744dd4146101825780635a1db8c41461018a5780636b5ad723146101b8575b600080fd5b6100fe600480360360208110156100ee57600080fd5b5035600160a060020a03166103b9565b005b6101266004803603602081101561011657600080fd5b5035600160a060020a031661045a565b60408051918252519081900360200190f35b610126600480360360c081101561014e57600080fd5b50600160a060020a038135811691602081013582169160408201359160608101359091169060808101359060a00135610475565b610126610edb565b6100fe600480360360408110156101a057600080fd5b50600160a060020a0381358116916020013516610ee1565b6101ee600480360360608110156101ce57600080fd5b50600160a060020a038135811691602081013590911690604001356110a5565b60408051938452602084019290925282820152519081900360600190f35b6100fe6004803603602081101561022257600080fd5b5035600160a060020a0316611396565b61023a6114c9565b60408051600160a060020a039092168252519081900360200190f35b610332600480360360c081101561026c57600080fd5b600160a060020a03823516919081019060408101602082013564010000000081111561029757600080fd5b8201836020820111156102a957600080fd5b803590602001918460018302840111640100000000831117156102cb57600080fd5b919390928235926040810190602001356401000000008111156102ed57600080fd5b8201836020820111156102ff57600080fd5b8035906020019184600183028401116401000000008311171561032157600080fd5b9193509150803590602001356114d8565b604080519115158252519081900360200190f35b61023a6117b6565b6101266004803603602081101561036457600080fd5b5035600160a060020a03166117c5565b61037c6117d7565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b61023a6117fb565b8033600160a060020a0382161461041a576040805160e560020a62461bcd02815260206004820152601960248201527f424d3a2063616c6c6572206d7573742062652077616c6c657400000000000000604482015290519081900360640190fd5b60408051600160a060020a038416815290517f9fcca3f73f85397e2bf03647abf243c20b753bd54463ff3cae74de2971c112fa9181900360200190a15050565b600160a060020a031660009081526001602052604090205490565b6000863330148061048b575061048b813361180a565b15156104cb5760405160e560020a62461bcd028152600401808060200182810382526023815260200180611eb56023913960400191505060405180910390fd5b600554604080517f4a4fbeec000000000000000000000000000000000000000000000000000000008152600160a060020a03808c16600483015291518b939290921691634a4fbeec91602480820192602092909190829003018186803b15801561053457600080fd5b505afa158015610548573d6000803e3d6000fd5b505050506040513d602081101561055e57600080fd5b5051156105b5576040805160e560020a62461bcd02815260206004820152601b60248201527f54543a2077616c6c6574206d75737420626520756e6c6f636b65640000000000604482015290519081900360640190fd5b6060600160a060020a03891673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14806105fe5750600160a060020a03871673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee145b151561063e5760405160e560020a62461bcd028152600401808060200182810382526025815260200180611e906025913960400191505060405180910390fd5b60008061064c8b8a8c6110a5565b50915091508782111561067f576106798261066d838b63ffffffff61189116565b9063ffffffff6118c316565b90508791505b600160a060020a038b1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561091c5760006106b68b8363ffffffff6118e716565b90508b818b8f8c8c600360009054906101000a9004600160a060020a03166040516024018088600160a060020a0316600160a060020a0316815260200187815260200186600160a060020a0316600160a060020a0316815260200185600160a060020a0316600160a060020a0316815260200184815260200183815260200182600160a060020a0316600160a060020a031681526020019750505050505050506040516020818303038152906040527fcb3c28c700000000000000000000000000000000000000000000000000000000600160e060020a031916602082018051600160e060020a03838183161783525050505093508c600160a060020a0316638f6f0332600260009054906101000a9004600160a060020a031683876040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561083f578181015183820152602001610827565b50505050905090810190601f16801561086c5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561088d57600080fd5b505af11580156108a1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405260208110156108ca57600080fd5b8101908080516401000000008111156108e257600080fd5b820160208101848111156108f557600080fd5b815164010000000081118282018710171561090f57600080fd5b50610d6995505050505050565b600260009054906101000a9004600160a060020a03168a6040516024018083600160a060020a0316600160a060020a03168152602001828152602001925050506040516020818303038152906040527f095ea7b300000000000000000000000000000000000000000000000000000000600160e060020a031916602082018051600160e060020a03838183161783525050505092508b600160a060020a0316638f6f03328c6000866040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610a31578181015183820152602001610a19565b50505050905090810190601f168015610a5e5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015610a7f57600080fd5b505af1158015610a93573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610abc57600080fd5b810190808051640100000000811115610ad457600080fd5b82016020810184811115610ae757600080fd5b8151640100000000811182820187101715610b0157600080fd5b5050929190505050508a8a8a8e8b8b600360009054906101000a9004600160a060020a03166040516024018088600160a060020a0316600160a060020a0316815260200187815260200186600160a060020a0316600160a060020a0316815260200185600160a060020a0316600160a060020a0316815260200184815260200183815260200182600160a060020a0316600160a060020a031681526020019750505050505050506040516020818303038152906040527fcb3c28c700000000000000000000000000000000000000000000000000000000600160e060020a031916602082018051600160e060020a03838183161783525050505092508b600160a060020a0316638f6f0332600260009054906101000a9004600160a060020a03166000866040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610c92578181015183820152602001610c7a565b50505050905090810190601f168015610cbf5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015610ce057600080fd5b505af1158015610cf4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610d1d57600080fd5b810190808051640100000000811115610d3557600080fd5b82016020810184811115610d4857600080fd5b8151640100000000811182820187101715610d6257600080fd5b5050505050505b6000811115610e7657600354604080517f8f6f0332000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101849052606060448201526000606482018190529151928f1692638f6f03329260a48084019391929182900301818387803b158015610ded57600080fd5b505af1158015610e01573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610e2a57600080fd5b810190808051640100000000811115610e4257600080fd5b82016020810184811115610e5557600080fd5b8151640100000000811182820187101715610e6f57600080fd5b5050505050505b60408051600160a060020a038d81168252602082018d90528b811682840152606082018590529151918e16917fc8082d818d67bbb0b463bdaa897d7363157a1425f6b077691285ac6ca82b60b19181900360800190a2509a9950505050505050505050565b60045481565b8133301480610ef55750610ef5813361180a565b1515610f355760405160e560020a62461bcd028152600401808060200182810382526023815260200180611eb56023913960400191505060405180910390fd5b600054604080517f0bcd4ebb000000000000000000000000000000000000000000000000000000008152600160a060020a03858116600483015291519190921691630bcd4ebb916024808301926020929190829003018186803b158015610f9b57600080fd5b505afa158015610faf573d6000803e3d6000fd5b505050506040513d6020811015610fc557600080fd5b5051151561101d576040805160e560020a62461bcd02815260206004820152601c60248201527f424d3a206d6f64756c65206973206e6f74207265676973746572656400000000604482015290519081900360640190fd5b604080517f1f17732d000000000000000000000000000000000000000000000000000000008152600160a060020a03848116600483015260016024830152915191851691631f17732d9160448082019260009290919082900301818387803b15801561108857600080fd5b505af115801561109c573d6000803e3d6000fd5b50505050505050565b60008080600160a060020a03861673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415611237576110d7846118fc565b600254909250600160a060020a031663809a9e5587876110fd888763ffffffff6118e716565b6040805160e060020a63ffffffff8716028152600160a060020a0394851660048201529290931660248301526044820152815160648083019392829003018186803b15801561114b57600080fd5b505afa15801561115f573d6000803e3d6000fd5b505050506040513d604081101561117557600080fd5b5051604080517f313ce5670000000000000000000000000000000000000000000000000000000081529051919250600091600160a060020a0388169163313ce567916004808301926020929190829003018186803b1580156111d657600080fd5b505afa1580156111ea573d6000803e3d6000fd5b505050506040513d602081101561120057600080fd5b5051905061122f6024829003600a0a61066d611222888763ffffffff6118e716565b859063ffffffff61189116565b93505061138d565b600254604080517f809a9e55000000000000000000000000000000000000000000000000000000008152600160a060020a038981166004830152888116602483015260448201889052825193169263809a9e5592606480840193919291829003018186803b1580156112a857600080fd5b505afa1580156112bc573d6000803e3d6000fd5b505050506040513d60408110156112d257600080fd5b5051604080517f313ce5670000000000000000000000000000000000000000000000000000000081529051919250600091600160a060020a0389169163313ce567916004808301926020929190829003018186803b15801561133357600080fd5b505afa158015611347573d6000803e3d6000fd5b505050506040513d602081101561135d57600080fd5b50519050611379600a82900a61066d848863ffffffff61189116565b9350611384846118fc565b92508284039350505b93509350939050565b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600091600160a060020a038416916370a0823191602480820192602092909190829003018186803b1580156113f957600080fd5b505afa15801561140d573d6000803e3d6000fd5b505050506040513d602081101561142357600080fd5b505160008054604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a0392831660048201526024810185905290519394509085169263a9059cbb92604480840193602093929083900390910190829087803b15801561149957600080fd5b505af11580156114ad573d6000803e3d6000fd5b505050506040513d60208110156114c357600080fd5b50505050565b600254600160a060020a031681565b6000805a90506000611528308c60008d8d8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508f92508c91508b9050611908565b90506115358b8983611a4b565b151561158b576040805160e560020a62461bcd02815260206004820152601560248201527f524d3a204475706c696361746520726571756573740000000000000000000000604482015290519081900360640190fd5b6115cb8b8b8b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611a5f92505050565b151561160b5760405160e560020a62461bcd02815260040180806020018281038252604a815260200180611e46604a913960600191505060405180910390fd5b600061164d8c8c8c8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611ad392505050565b905060418102871415611765576116668c868884611adb565b15611765578015806116e957506116e98c8c8c8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8f018190048102820181019092528d815288935091508d908d9081908401838280828437600092019190915250611bad92505050565b156117655730600160a060020a03168b8b604051808383808284376040519201945060009350909150508083038183865af19150503d806000811461174a576040519150601f19603f3d011682016040523d82523d6000602084013e61174f565b606091505b5050809450506117658c5a850388888533611bd2565b60408051838152905185151591600160a060020a038f16917f6bb0b384ce772133df63560651bc8c727c53306cec1d51e2cbf8ea35fb8f2ec19181900360200190a350505098975050505050505050565b600354600160a060020a031681565b60016020526000908152604090205481565b7fd490da4d0000000000000000000000000000000000000000000000000000000090565b600554600160a060020a031681565b600081600160a060020a031683600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b15801561185257600080fd5b505afa158015611866573d6000803e3d6000fd5b505050506040513d602081101561187c57600080fd5b5051600160a060020a03161490505b92915050565b60008215156118a25750600061188b565b8282028284828115156118b157fe5b04146118bc57600080fd5b9392505050565b60008082116118d157600080fd5b600082848115156118de57fe5b04949350505050565b6000828211156118f657600080fd5b50900390565b60045461271091020490565b6040517f190000000000000000000000000000000000000000000000000000000000000060208083018281526000602185018190526c01000000000000000000000000600160a060020a03808e16820260228801528c16026036860152604a85018a90528851909485938d938d938d938d938d938d938d939192606a909201918701908083835b602083106119ae5780518252601f19909201916020918201910161198f565b51815160209384036101000a600019018019909216911617905292019586525084810193909352506040808401919091528051808403820181526060840182528051908301207f19457468657265756d205369676e6564204d6573736167653a0a3332000000006080850152609c808501919091528151808503909101815260bc909301905281519101209e9d5050505050505050505050505050565b6000611a578484611d11565b949350505050565b60006024825110151515611abd576040805160e560020a62461bcd02815260206004820152601660248201527f524d3a20496e76616c6964206461746157616c6c657400000000000000000000604482015290519081900360640190fd5b5060240151600160a060020a0391821691161490565b600192915050565b60008083118015611aec5750600182115b8015611b95575082840285600160a060020a0316311080611b955750604080517fd6eb1bbf0000000000000000000000000000000000000000000000000000000081523060048201529051600160a060020a0387169163d6eb1bbf916024808301926020929190829003018186803b158015611b6757600080fd5b505afa158015611b7b573d6000803e3d6000fd5b505050506040513d6020811015611b9157600080fd5b5051155b15611ba257506000611a57565b506001949350505050565b600080611bbc84846000611d9b565b9050611bc8868261180a565b9695505050505050565b61726c8501600085118015611be75750600183115b8015611bf35750838111155b1561109c573a851115611c07573a02611c0a565b84025b604080517f8f6f0332000000000000000000000000000000000000000000000000000000008152600160a060020a03848116600483015260248201849052606060448301526000606483018190529251908a1692638f6f03329260a4808201939182900301818387803b158015611c8057600080fd5b505af1158015611c94573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015611cbd57600080fd5b810190808051640100000000811115611cd557600080fd5b82016020810184811115611ce857600080fd5b8151640100000000811182820187101715611d0257600080fd5b50505050505050505050505050565b600160a060020a0382166000908152600160205260408120548211611d385750600061188b565b7001000000000000000000000000000000006fffffffffffffffffffffffffffffffff198316044361271001811115611d7557600091505061188b565b5050600160a060020a038216600090815260016020819052604090912082905592915050565b6041808202830160208101516040820151919092015160009260ff9190911691601b831480611dcd57508260ff16601c145b1515611dd857600080fd5b604080516000815260208082018084528a905260ff8616828401526060820185905260808201849052915160019260a0808401939192601f1981019281900390910190855afa158015611e2f573d6000803e3d6000fd5b5050604051601f1901519897505050505050505056fe524d3a207468652077616c6c657420617574686f72697a656420697320646966666572656e74207468656e2074686520746172676574206f66207468652072656c61796564206461746154453a20736f75726365206f722064657374696e6174696f6e206d75737420626520455448424d3a206d75737420626520616e206f776e657220666f72207468652077616c6c6574a165627a7a72305820a0dffc345b1db41072718ccaa3e30aed2777b1e1bd7ec1df3a8e18a91afc8aa4002900000000000000000000000048fbf8d51f389d0c18691a1c9ea4c2794735bf82000000000000000000000000addc501564740bf4bdbfcd7c8235b63b71a4d28e00000000000000000000000000476fa07c69447a2011a59b02afa24592ac0edb000000000000000000000000c591e1194056166812049743daaa714159e6c3c8000000000000000000000000000000000000000000000000000000000000000f
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106100d35760003560e060020a900480639be65a6011610090578063c415b95c1161006a578063c415b95c14610346578063c9b5ef8e1461034e578063d490da4d14610374578063d89784fc146103b1576100d3565b80639be65a601461020c578063a2d10ba514610232578063aacaaf8814610256576100d3565b806319ab453c146100d85780632d0335ab146101005780632d8da11a1461013857806341744dd4146101825780635a1db8c41461018a5780636b5ad723146101b8575b600080fd5b6100fe600480360360208110156100ee57600080fd5b5035600160a060020a03166103b9565b005b6101266004803603602081101561011657600080fd5b5035600160a060020a031661045a565b60408051918252519081900360200190f35b610126600480360360c081101561014e57600080fd5b50600160a060020a038135811691602081013582169160408201359160608101359091169060808101359060a00135610475565b610126610edb565b6100fe600480360360408110156101a057600080fd5b50600160a060020a0381358116916020013516610ee1565b6101ee600480360360608110156101ce57600080fd5b50600160a060020a038135811691602081013590911690604001356110a5565b60408051938452602084019290925282820152519081900360600190f35b6100fe6004803603602081101561022257600080fd5b5035600160a060020a0316611396565b61023a6114c9565b60408051600160a060020a039092168252519081900360200190f35b610332600480360360c081101561026c57600080fd5b600160a060020a03823516919081019060408101602082013564010000000081111561029757600080fd5b8201836020820111156102a957600080fd5b803590602001918460018302840111640100000000831117156102cb57600080fd5b919390928235926040810190602001356401000000008111156102ed57600080fd5b8201836020820111156102ff57600080fd5b8035906020019184600183028401116401000000008311171561032157600080fd5b9193509150803590602001356114d8565b604080519115158252519081900360200190f35b61023a6117b6565b6101266004803603602081101561036457600080fd5b5035600160a060020a03166117c5565b61037c6117d7565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b61023a6117fb565b8033600160a060020a0382161461041a576040805160e560020a62461bcd02815260206004820152601960248201527f424d3a2063616c6c6572206d7573742062652077616c6c657400000000000000604482015290519081900360640190fd5b60408051600160a060020a038416815290517f9fcca3f73f85397e2bf03647abf243c20b753bd54463ff3cae74de2971c112fa9181900360200190a15050565b600160a060020a031660009081526001602052604090205490565b6000863330148061048b575061048b813361180a565b15156104cb5760405160e560020a62461bcd028152600401808060200182810382526023815260200180611eb56023913960400191505060405180910390fd5b600554604080517f4a4fbeec000000000000000000000000000000000000000000000000000000008152600160a060020a03808c16600483015291518b939290921691634a4fbeec91602480820192602092909190829003018186803b15801561053457600080fd5b505afa158015610548573d6000803e3d6000fd5b505050506040513d602081101561055e57600080fd5b5051156105b5576040805160e560020a62461bcd02815260206004820152601b60248201527f54543a2077616c6c6574206d75737420626520756e6c6f636b65640000000000604482015290519081900360640190fd5b6060600160a060020a03891673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14806105fe5750600160a060020a03871673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee145b151561063e5760405160e560020a62461bcd028152600401808060200182810382526025815260200180611e906025913960400191505060405180910390fd5b60008061064c8b8a8c6110a5565b50915091508782111561067f576106798261066d838b63ffffffff61189116565b9063ffffffff6118c316565b90508791505b600160a060020a038b1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561091c5760006106b68b8363ffffffff6118e716565b90508b818b8f8c8c600360009054906101000a9004600160a060020a03166040516024018088600160a060020a0316600160a060020a0316815260200187815260200186600160a060020a0316600160a060020a0316815260200185600160a060020a0316600160a060020a0316815260200184815260200183815260200182600160a060020a0316600160a060020a031681526020019750505050505050506040516020818303038152906040527fcb3c28c700000000000000000000000000000000000000000000000000000000600160e060020a031916602082018051600160e060020a03838183161783525050505093508c600160a060020a0316638f6f0332600260009054906101000a9004600160a060020a031683876040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561083f578181015183820152602001610827565b50505050905090810190601f16801561086c5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801561088d57600080fd5b505af11580156108a1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405260208110156108ca57600080fd5b8101908080516401000000008111156108e257600080fd5b820160208101848111156108f557600080fd5b815164010000000081118282018710171561090f57600080fd5b50610d6995505050505050565b600260009054906101000a9004600160a060020a03168a6040516024018083600160a060020a0316600160a060020a03168152602001828152602001925050506040516020818303038152906040527f095ea7b300000000000000000000000000000000000000000000000000000000600160e060020a031916602082018051600160e060020a03838183161783525050505092508b600160a060020a0316638f6f03328c6000866040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610a31578181015183820152602001610a19565b50505050905090810190601f168015610a5e5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015610a7f57600080fd5b505af1158015610a93573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610abc57600080fd5b810190808051640100000000811115610ad457600080fd5b82016020810184811115610ae757600080fd5b8151640100000000811182820187101715610b0157600080fd5b5050929190505050508a8a8a8e8b8b600360009054906101000a9004600160a060020a03166040516024018088600160a060020a0316600160a060020a0316815260200187815260200186600160a060020a0316600160a060020a0316815260200185600160a060020a0316600160a060020a0316815260200184815260200183815260200182600160a060020a0316600160a060020a031681526020019750505050505050506040516020818303038152906040527fcb3c28c700000000000000000000000000000000000000000000000000000000600160e060020a031916602082018051600160e060020a03838183161783525050505092508b600160a060020a0316638f6f0332600260009054906101000a9004600160a060020a03166000866040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610c92578181015183820152602001610c7a565b50505050905090810190601f168015610cbf5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015610ce057600080fd5b505af1158015610cf4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610d1d57600080fd5b810190808051640100000000811115610d3557600080fd5b82016020810184811115610d4857600080fd5b8151640100000000811182820187101715610d6257600080fd5b5050505050505b6000811115610e7657600354604080517f8f6f0332000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101849052606060448201526000606482018190529151928f1692638f6f03329260a48084019391929182900301818387803b158015610ded57600080fd5b505af1158015610e01573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610e2a57600080fd5b810190808051640100000000811115610e4257600080fd5b82016020810184811115610e5557600080fd5b8151640100000000811182820187101715610e6f57600080fd5b5050505050505b60408051600160a060020a038d81168252602082018d90528b811682840152606082018590529151918e16917fc8082d818d67bbb0b463bdaa897d7363157a1425f6b077691285ac6ca82b60b19181900360800190a2509a9950505050505050505050565b60045481565b8133301480610ef55750610ef5813361180a565b1515610f355760405160e560020a62461bcd028152600401808060200182810382526023815260200180611eb56023913960400191505060405180910390fd5b600054604080517f0bcd4ebb000000000000000000000000000000000000000000000000000000008152600160a060020a03858116600483015291519190921691630bcd4ebb916024808301926020929190829003018186803b158015610f9b57600080fd5b505afa158015610faf573d6000803e3d6000fd5b505050506040513d6020811015610fc557600080fd5b5051151561101d576040805160e560020a62461bcd02815260206004820152601c60248201527f424d3a206d6f64756c65206973206e6f74207265676973746572656400000000604482015290519081900360640190fd5b604080517f1f17732d000000000000000000000000000000000000000000000000000000008152600160a060020a03848116600483015260016024830152915191851691631f17732d9160448082019260009290919082900301818387803b15801561108857600080fd5b505af115801561109c573d6000803e3d6000fd5b50505050505050565b60008080600160a060020a03861673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415611237576110d7846118fc565b600254909250600160a060020a031663809a9e5587876110fd888763ffffffff6118e716565b6040805160e060020a63ffffffff8716028152600160a060020a0394851660048201529290931660248301526044820152815160648083019392829003018186803b15801561114b57600080fd5b505afa15801561115f573d6000803e3d6000fd5b505050506040513d604081101561117557600080fd5b5051604080517f313ce5670000000000000000000000000000000000000000000000000000000081529051919250600091600160a060020a0388169163313ce567916004808301926020929190829003018186803b1580156111d657600080fd5b505afa1580156111ea573d6000803e3d6000fd5b505050506040513d602081101561120057600080fd5b5051905061122f6024829003600a0a61066d611222888763ffffffff6118e716565b859063ffffffff61189116565b93505061138d565b600254604080517f809a9e55000000000000000000000000000000000000000000000000000000008152600160a060020a038981166004830152888116602483015260448201889052825193169263809a9e5592606480840193919291829003018186803b1580156112a857600080fd5b505afa1580156112bc573d6000803e3d6000fd5b505050506040513d60408110156112d257600080fd5b5051604080517f313ce5670000000000000000000000000000000000000000000000000000000081529051919250600091600160a060020a0389169163313ce567916004808301926020929190829003018186803b15801561133357600080fd5b505afa158015611347573d6000803e3d6000fd5b505050506040513d602081101561135d57600080fd5b50519050611379600a82900a61066d848863ffffffff61189116565b9350611384846118fc565b92508284039350505b93509350939050565b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600091600160a060020a038416916370a0823191602480820192602092909190829003018186803b1580156113f957600080fd5b505afa15801561140d573d6000803e3d6000fd5b505050506040513d602081101561142357600080fd5b505160008054604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a0392831660048201526024810185905290519394509085169263a9059cbb92604480840193602093929083900390910190829087803b15801561149957600080fd5b505af11580156114ad573d6000803e3d6000fd5b505050506040513d60208110156114c357600080fd5b50505050565b600254600160a060020a031681565b6000805a90506000611528308c60008d8d8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508f92508c91508b9050611908565b90506115358b8983611a4b565b151561158b576040805160e560020a62461bcd02815260206004820152601560248201527f524d3a204475706c696361746520726571756573740000000000000000000000604482015290519081900360640190fd5b6115cb8b8b8b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611a5f92505050565b151561160b5760405160e560020a62461bcd02815260040180806020018281038252604a815260200180611e46604a913960600191505060405180910390fd5b600061164d8c8c8c8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611ad392505050565b905060418102871415611765576116668c868884611adb565b15611765578015806116e957506116e98c8c8c8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8f018190048102820181019092528d815288935091508d908d9081908401838280828437600092019190915250611bad92505050565b156117655730600160a060020a03168b8b604051808383808284376040519201945060009350909150508083038183865af19150503d806000811461174a576040519150601f19603f3d011682016040523d82523d6000602084013e61174f565b606091505b5050809450506117658c5a850388888533611bd2565b60408051838152905185151591600160a060020a038f16917f6bb0b384ce772133df63560651bc8c727c53306cec1d51e2cbf8ea35fb8f2ec19181900360200190a350505098975050505050505050565b600354600160a060020a031681565b60016020526000908152604090205481565b7fd490da4d0000000000000000000000000000000000000000000000000000000090565b600554600160a060020a031681565b600081600160a060020a031683600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b15801561185257600080fd5b505afa158015611866573d6000803e3d6000fd5b505050506040513d602081101561187c57600080fd5b5051600160a060020a03161490505b92915050565b60008215156118a25750600061188b565b8282028284828115156118b157fe5b04146118bc57600080fd5b9392505050565b60008082116118d157600080fd5b600082848115156118de57fe5b04949350505050565b6000828211156118f657600080fd5b50900390565b60045461271091020490565b6040517f190000000000000000000000000000000000000000000000000000000000000060208083018281526000602185018190526c01000000000000000000000000600160a060020a03808e16820260228801528c16026036860152604a85018a90528851909485938d938d938d938d938d938d938d939192606a909201918701908083835b602083106119ae5780518252601f19909201916020918201910161198f565b51815160209384036101000a600019018019909216911617905292019586525084810193909352506040808401919091528051808403820181526060840182528051908301207f19457468657265756d205369676e6564204d6573736167653a0a3332000000006080850152609c808501919091528151808503909101815260bc909301905281519101209e9d5050505050505050505050505050565b6000611a578484611d11565b949350505050565b60006024825110151515611abd576040805160e560020a62461bcd02815260206004820152601660248201527f524d3a20496e76616c6964206461746157616c6c657400000000000000000000604482015290519081900360640190fd5b5060240151600160a060020a0391821691161490565b600192915050565b60008083118015611aec5750600182115b8015611b95575082840285600160a060020a0316311080611b955750604080517fd6eb1bbf0000000000000000000000000000000000000000000000000000000081523060048201529051600160a060020a0387169163d6eb1bbf916024808301926020929190829003018186803b158015611b6757600080fd5b505afa158015611b7b573d6000803e3d6000fd5b505050506040513d6020811015611b9157600080fd5b5051155b15611ba257506000611a57565b506001949350505050565b600080611bbc84846000611d9b565b9050611bc8868261180a565b9695505050505050565b61726c8501600085118015611be75750600183115b8015611bf35750838111155b1561109c573a851115611c07573a02611c0a565b84025b604080517f8f6f0332000000000000000000000000000000000000000000000000000000008152600160a060020a03848116600483015260248201849052606060448301526000606483018190529251908a1692638f6f03329260a4808201939182900301818387803b158015611c8057600080fd5b505af1158015611c94573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015611cbd57600080fd5b810190808051640100000000811115611cd557600080fd5b82016020810184811115611ce857600080fd5b8151640100000000811182820187101715611d0257600080fd5b50505050505050505050505050565b600160a060020a0382166000908152600160205260408120548211611d385750600061188b565b7001000000000000000000000000000000006fffffffffffffffffffffffffffffffff198316044361271001811115611d7557600091505061188b565b5050600160a060020a038216600090815260016020819052604090912082905592915050565b6041808202830160208101516040820151919092015160009260ff9190911691601b831480611dcd57508260ff16601c145b1515611dd857600080fd5b604080516000815260208082018084528a905260ff8616828401526060820185905260808201849052915160019260a0808401939192601f1981019281900390910190855afa158015611e2f573d6000803e3d6000fd5b5050604051601f1901519897505050505050505056fe524d3a207468652077616c6c657420617574686f72697a656420697320646966666572656e74207468656e2074686520746172676574206f66207468652072656c61796564206461746154453a20736f75726365206f722064657374696e6174696f6e206d75737420626520455448424d3a206d75737420626520616e206f776e657220666f72207468652077616c6c6574a165627a7a72305820a0dffc345b1db41072718ccaa3e30aed2777b1e1bd7ec1df3a8e18a91afc8aa40029