Transaction Hash:
Block:
10419107 at Jul-08-2020 01:19:53 PM +UTC
Transaction Fee:
0.040383414839825443 ETH
$87.95
Gas Used:
747,841 Gas / 54.000001123 Gwei
Emitted Events:
| 159 |
ERC777_StandardToken.Sent( operator=[Receiver] 0x899cc5f7e0dccec1565a6c39320f6716076d314c, from=[Sender] 0x5853a21950dde5a1b68580b3400f3f4076ad87f0, to=[Receiver] 0x899cc5f7e0dccec1565a6c39320f6716076d314c, amount=124475535000000000000, data=0x, operatorData=0x )
|
| 160 |
ERC777_StandardToken.Transfer( from=[Sender] 0x5853a21950dde5a1b68580b3400f3f4076ad87f0, to=[Receiver] 0x899cc5f7e0dccec1565a6c39320f6716076d314c, value=124475535000000000000 )
|
| 161 |
ERC777_StandardToken.Approval( owner=[Sender] 0x5853a21950dde5a1b68580b3400f3f4076ad87f0, spender=[Receiver] 0x899cc5f7e0dccec1565a6c39320f6716076d314c, value=0 )
|
Account State Difference:
| Address | Before | After | State Difference | ||
|---|---|---|---|---|---|
|
0x04668Ec2...D451c8F7F
Miner
| (zhizhu.top) | 3,231.789265806527407816 Eth | 3,231.829649221367233259 Eth | 0.040383414839825443 | |
| 0x5853a219...076ad87f0 |
0.064234684891371965 Eth
Nonce: 36
|
0.023851270051546522 Eth
Nonce: 37
| 0.040383414839825443 | ||
| 0x899CC5f7...6076d314c | |||||
| 0xF24A6d03...8760c6099 |
Execution Trace
0x899cc5f7e0dccec1565a6c39320f6716076d314c.CALL( )
-
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.ec8bc845( ) -
0xf3ee1c3cafddbe4a2e894a0a5df31b6f2c38c465.6386c1c7( )
ERC777_StandardToken.transferFrom( holder=0x5853a21950dDe5a1b68580B3400F3f4076ad87f0, recipient=0x899CC5f7e0dCCEC1565A6C39320f6716076d314c, amount=124475535000000000000 ) => ( True )
-
ERC1820Registry.getInterfaceImplementer( _addr=0x5853a21950dDe5a1b68580B3400F3f4076ad87f0, _interfaceHash=29DDB589B1FB5FC7CF394961C1ADF5F8C6454761ADF795E67FE149F658ABE895 ) => ( 0x0000000000000000000000000000000000000000 ) -
ERC1820Registry.getInterfaceImplementer( _addr=0x899CC5f7e0dCCEC1565A6C39320f6716076d314c, _interfaceHash=B281FC8C12954D22544DB45DE3159A39272895B169A852B314F9CC762E44C53B ) => ( 0x0000000000000000000000000000000000000000 )
-
File 1 of 2: ERC777_StandardToken
File 2 of 2: ERC1820Registry
{"Address.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\n/**\r\n * @dev Collection of functions related to the address type\r\n */\r\nlibrary Address {\r\n /**\r\n * @dev Returns true if `account` is a contract.\r\n *\r\n * This test is non-exhaustive, and there may be false-negatives: during the\r\n * execution of a contract\u0027s constructor, its address will be reported as\r\n * not containing a contract.\r\n *\r\n * IMPORTANT: It is unsafe to assume that an address for which this\r\n * function returns false is an externally-owned account (EOA) and not a\r\n * contract.\r\n */\r\n function isContract(address account) internal view returns (bool) {\r\n // This method relies in extcodesize, which returns 0 for contracts in\r\n // construction, since the code is only stored at the end of the\r\n // constructor execution.\r\n\r\n // According to EIP-1052, 0x0 is the value returned for not-yet created accounts\r\n // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned\r\n // for accounts without code, i.e. `keccak256(\u0027\u0027)`\r\n bytes32 codehash;\r\n bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;\r\n // solhint-disable-next-line no-inline-assembly\r\n assembly { codehash := extcodehash(account) }\r\n return (codehash != 0x0 \u0026\u0026 codehash != accountHash);\r\n }\r\n\r\n /**\r\n * @dev Converts an `address` into `address payable`. Note that this is\r\n * simply a type cast: the actual underlying value is not changed.\r\n *\r\n * _Available since v2.4.0._\r\n */\r\n function toPayable(address account) internal pure returns (address payable) {\r\n return address(uint160(account));\r\n }\r\n}\r\n"},"Context.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\n/*\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with GSN meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\ncontract Context {\r\n\t// Empty internal constructor, to prevent people from mistakenly deploying\r\n\t// an instance of this contract, which should be used via inheritance.\r\n\tconstructor () internal { }\r\n\t// solhint-disable-previous-line no-empty-blocks\r\n\r\n /**\r\n * @dev return msg.sender\r\n * @return msg.sender\r\n */\r\n\tfunction _msgSender()\r\n internal\r\n view\r\n returns (address payable)\r\n {\r\n\t\treturn msg.sender;\r\n\t}\r\n\r\n /**\r\n * @dev return msg.value\r\n * @return msg.value\r\n */\r\n\tfunction _msgValue()\r\n internal\r\n view\r\n returns (uint)\r\n {\r\n\t\treturn msg.value;\r\n\t}\r\n\r\n /**\r\n * @dev return tx.origin\r\n * @return tx.origin\r\n */\r\n\tfunction _txOrigin()\r\n internal\r\n view\r\n returns (address)\r\n {\r\n\t\treturn tx.origin;\r\n\t}\r\n}"},"ERC777.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\nimport \"./Context.sol\";\r\nimport \"./IERC777.sol\";\r\nimport \"./IERC777Recipient.sol\";\r\nimport \"./IERC777Sender.sol\";\r\nimport \"./IERC20.sol\";\r\nimport \"./SafeMath.sol\";\r\nimport \"./Address.sol\";\r\nimport \"./IERC1820Registry.sol\";\r\n\r\n/**\r\n * @dev Implementation of the {IERC777} interface.\r\n *\r\n * This implementation is agnostic to the way tokens are created. This means\r\n * that a supply mechanism has to be added in a derived contract using {_mint}.\r\n *\r\n * Support for ERC20 is included in this contract, as specified by the EIP: both\r\n * the ERC777 and ERC20 interfaces can be safely used when interacting with it.\r\n * Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token\r\n * movements.\r\n *\r\n * Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there\r\n * are no special restrictions in the amount of tokens that created, moved, or\r\n * destroyed. This makes integration with ERC20 applications seamless.\r\n */\r\ncontract ERC777 is Context, IERC777, IERC20 {\r\n using SafeMath for uint256;\r\n using Address for address;\r\n\r\n IERC1820Registry constant private ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);\r\n\r\n mapping(address =\u003e uint256) private _balances;\r\n\r\n uint256 private _totalSupply;\r\n\r\n string private _name;\r\n string private _symbol;\r\n\r\n // We inline the result of the following hashes because Solidity doesn\u0027t resolve them at compile time.\r\n // See https://github.com/ethereum/solidity/issues/4024.\r\n\r\n // keccak256(\"ERC777TokensSender\")\r\n bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =\r\n 0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;\r\n\r\n // keccak256(\"ERC777TokensRecipient\")\r\n bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =\r\n 0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;\r\n\r\n // This isn\u0027t ever read from - it\u0027s only used to respond to the defaultOperators query.\r\n address[] private _defaultOperatorsArray;\r\n\r\n // Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).\r\n mapping(address =\u003e bool) private _defaultOperators;\r\n\r\n // For each account, a mapping of its operators and revoked default operators.\r\n mapping(address =\u003e mapping(address =\u003e bool)) private _operators;\r\n mapping(address =\u003e mapping(address =\u003e bool)) private _revokedDefaultOperators;\r\n\r\n // ERC20-allowances\r\n mapping (address =\u003e mapping (address =\u003e uint256)) private _allowances;\r\n\r\n /**\r\n * @dev `defaultOperators` may be an empty array.\r\n */\r\n constructor(\r\n string memory name,\r\n string memory symbol,\r\n address[] memory defaultOperators\r\n ) public {\r\n _name = name;\r\n _symbol = symbol;\r\n\r\n _defaultOperatorsArray = defaultOperators;\r\n for (uint256 i = 0; i \u003c _defaultOperatorsArray.length; i++) {\r\n _defaultOperators[_defaultOperatorsArray[i]] = true;\r\n }\r\n\r\n // register interfaces\r\n ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256(\"ERC777Token\"), address(this));\r\n ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256(\"ERC20Token\"), address(this));\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-name}.\r\n */\r\n function name() public view returns (string memory) {\r\n return _name;\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-symbol}.\r\n */\r\n function symbol() public view returns (string memory) {\r\n return _symbol;\r\n }\r\n\r\n /**\r\n * @dev See {ERC20Detailed-decimals}.\r\n *\r\n * Always returns 18, as per the\r\n * [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).\r\n */\r\n function decimals() public pure returns (uint8) {\r\n return 18;\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-granularity}.\r\n *\r\n * This implementation always returns `1`.\r\n */\r\n function granularity() public view returns (uint256) {\r\n return 1;\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-totalSupply}.\r\n */\r\n function totalSupply() public view returns (uint256) {\r\n return _totalSupply;\r\n }\r\n\r\n /**\r\n * @dev Returns the amount of tokens owned by an account (`tokenHolder`).\r\n */\r\n function balanceOf(address tokenHolder) public view returns (uint256) {\r\n return _balances[tokenHolder];\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-send}.\r\n *\r\n * Also emits a {IERC20-Transfer} event for ERC20 compatibility.\r\n */\r\n function send(address recipient, uint256 amount, bytes memory data) public {\r\n _send(_msgSender(), _msgSender(), recipient, amount, data, \"\", true);\r\n }\r\n\r\n /**\r\n * @dev See {IERC20-transfer}.\r\n *\r\n * Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}\r\n * interface if it is a contract.\r\n *\r\n * Also emits a {Sent} event.\r\n */\r\n function transfer(address recipient, uint256 amount) public returns (bool) {\r\n require(recipient != address(0), \"ERC777: transfer to the zero address\");\r\n\r\n address from = _msgSender();\r\n\r\n _callTokensToSend(from, from, recipient, amount, \"\", \"\");\r\n\r\n _move(from, from, recipient, amount, \"\", \"\");\r\n\r\n _callTokensReceived(from, from, recipient, amount, \"\", \"\", false);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-burn}.\r\n *\r\n * Also emits a {IERC20-Transfer} event for ERC20 compatibility.\r\n */\r\n function burn(uint256 amount, bytes memory data) public {\r\n _burn(_msgSender(), _msgSender(), amount, data, \"\");\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-isOperatorFor}.\r\n */\r\n function isOperatorFor(\r\n address operator,\r\n address tokenHolder\r\n ) public view returns (bool) {\r\n return operator == tokenHolder ||\r\n (_defaultOperators[operator] \u0026\u0026 !_revokedDefaultOperators[tokenHolder][operator]) ||\r\n _operators[tokenHolder][operator];\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-authorizeOperator}.\r\n */\r\n function authorizeOperator(address operator) public {\r\n require(_msgSender() != operator, \"ERC777: authorizing self as operator\");\r\n\r\n if (_defaultOperators[operator]) {\r\n delete _revokedDefaultOperators[_msgSender()][operator];\r\n } else {\r\n _operators[_msgSender()][operator] = true;\r\n }\r\n\r\n emit AuthorizedOperator(operator, _msgSender());\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-revokeOperator}.\r\n */\r\n function revokeOperator(address operator) public {\r\n require(operator != _msgSender(), \"ERC777: revoking self as operator\");\r\n\r\n if (_defaultOperators[operator]) {\r\n _revokedDefaultOperators[_msgSender()][operator] = true;\r\n } else {\r\n delete _operators[_msgSender()][operator];\r\n }\r\n\r\n emit RevokedOperator(operator, _msgSender());\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-defaultOperators}.\r\n */\r\n function defaultOperators() public view returns (address[] memory) {\r\n return _defaultOperatorsArray;\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-operatorSend}.\r\n *\r\n * Emits {Sent} and {IERC20-Transfer} events.\r\n */\r\n function operatorSend(\r\n address sender,\r\n address recipient,\r\n uint256 amount,\r\n bytes memory data,\r\n bytes memory operatorData\r\n )\r\n public\r\n {\r\n require(isOperatorFor(_msgSender(), sender), \"ERC777: caller is not an operator for holder\");\r\n _send(_msgSender(), sender, recipient, amount, data, operatorData, true);\r\n }\r\n\r\n /**\r\n * @dev See {IERC777-operatorBurn}.\r\n *\r\n * Emits {Burned} and {IERC20-Transfer} events.\r\n */\r\n function operatorBurn(address account, uint256 amount, bytes memory data, bytes memory operatorData) public {\r\n require(isOperatorFor(_msgSender(), account), \"ERC777: caller is not an operator for holder\");\r\n _burn(_msgSender(), account, amount, data, operatorData);\r\n }\r\n\r\n /**\r\n * @dev See {IERC20-allowance}.\r\n *\r\n * Note that operator and allowance concepts are orthogonal: operators may\r\n * not have allowance, and accounts with allowance may not be operators\r\n * themselves.\r\n */\r\n function allowance(address holder, address spender) public view returns (uint256) {\r\n return _allowances[holder][spender];\r\n }\r\n\r\n /**\r\n * @dev See {IERC20-approve}.\r\n *\r\n * Note that accounts cannot have allowance issued by their operators.\r\n */\r\n function approve(address spender, uint256 value) public returns (bool) {\r\n address holder = _msgSender();\r\n _approve(holder, spender, value);\r\n return true;\r\n }\r\n\r\n /**\r\n * @dev See {IERC20-transferFrom}.\r\n *\r\n * Note that operator and allowance concepts are orthogonal: operators cannot\r\n * call `transferFrom` (unless they have allowance), and accounts with\r\n * allowance cannot call `operatorSend` (unless they are operators).\r\n *\r\n * Emits {Sent}, {IERC20-Transfer} and {IERC20-Approval} events.\r\n */\r\n function transferFrom(address holder, address recipient, uint256 amount) public returns (bool) {\r\n require(recipient != address(0), \"ERC777: transfer to the zero address\");\r\n require(holder != address(0), \"ERC777: transfer from the zero address\");\r\n\r\n address spender = _msgSender();\r\n\r\n _callTokensToSend(spender, holder, recipient, amount, \"\", \"\");\r\n\r\n _move(spender, holder, recipient, amount, \"\", \"\");\r\n _approve(holder, spender, _allowances[holder][spender].sub(amount, \"ERC777: transfer amount exceeds allowance\"));\r\n\r\n _callTokensReceived(spender, holder, recipient, amount, \"\", \"\", false);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @dev Creates `amount` tokens and assigns them to `account`, increasing\r\n * the total supply.\r\n *\r\n * If a send hook is registered for `account`, the corresponding function\r\n * will be called with `operator`, `data` and `operatorData`.\r\n *\r\n * See {IERC777Sender} and {IERC777Recipient}.\r\n *\r\n * Emits {Minted} and {IERC20-Transfer} events.\r\n *\r\n * Requirements\r\n *\r\n * - `account` cannot be the zero address.\r\n * - if `account` is a contract, it must implement the {IERC777Recipient}\r\n * interface.\r\n */\r\n function _mint(\r\n address operator,\r\n address account,\r\n uint256 amount,\r\n bytes memory userData,\r\n bytes memory operatorData\r\n )\r\n internal\r\n {\r\n require(account != address(0), \"ERC777: mint to the zero address\");\r\n\r\n // Update state variables\r\n _totalSupply = _totalSupply.add(amount);\r\n _balances[account] = _balances[account].add(amount);\r\n\r\n _callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);\r\n\r\n emit Minted(operator, account, amount, userData, operatorData);\r\n emit Transfer(address(0), account, amount);\r\n }\r\n\r\n /**\r\n * @dev Send tokens\r\n * @param operator address operator requesting the transfer\r\n * @param from address token holder address\r\n * @param to address recipient address\r\n * @param amount uint256 amount of tokens to transfer\r\n * @param userData bytes extra information provided by the token holder (if any)\r\n * @param operatorData bytes extra information provided by the operator (if any)\r\n * @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient\r\n */\r\n function _send(\r\n address operator,\r\n address from,\r\n address to,\r\n uint256 amount,\r\n bytes memory userData,\r\n bytes memory operatorData,\r\n bool requireReceptionAck\r\n )\r\n private\r\n {\r\n require(from != address(0), \"ERC777: send from the zero address\");\r\n require(to != address(0), \"ERC777: send to the zero address\");\r\n\r\n _callTokensToSend(operator, from, to, amount, userData, operatorData);\r\n\r\n _move(operator, from, to, amount, userData, operatorData);\r\n\r\n _callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);\r\n }\r\n\r\n /**\r\n * @dev Burn tokens\r\n * @param operator address operator requesting the operation\r\n * @param from address token holder address\r\n * @param amount uint256 amount of tokens to burn\r\n * @param data bytes extra information provided by the token holder\r\n * @param operatorData bytes extra information provided by the operator (if any)\r\n */\r\n function _burn(\r\n address operator,\r\n address from,\r\n uint256 amount,\r\n bytes memory data,\r\n bytes memory operatorData\r\n )\r\n internal\r\n {\r\n require(from != address(0), \"ERC777: burn from the zero address\");\r\n\r\n _callTokensToSend(operator, from, address(0), amount, data, operatorData);\r\n\r\n // Update state variables\r\n _balances[from] = _balances[from].sub(amount, \"ERC777: burn amount exceeds balance\");\r\n _totalSupply = _totalSupply.sub(amount);\r\n\r\n emit Burned(operator, from, amount, data, operatorData);\r\n emit Transfer(from, address(0), amount);\r\n }\r\n\r\n function _move(\r\n address operator,\r\n address from,\r\n address to,\r\n uint256 amount,\r\n bytes memory userData,\r\n bytes memory operatorData\r\n )\r\n private\r\n {\r\n _balances[from] = _balances[from].sub(amount, \"ERC777: transfer amount exceeds balance\");\r\n _balances[to] = _balances[to].add(amount);\r\n\r\n emit Sent(operator, from, to, amount, userData, operatorData);\r\n emit Transfer(from, to, amount);\r\n }\r\n\r\n function _approve(address holder, address spender, uint256 value) private {\r\n // TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is\r\n // currently unnecessary.\r\n //require(holder != address(0), \"ERC777: approve from the zero address\");\r\n require(spender != address(0), \"ERC777: approve to the zero address\");\r\n\r\n _allowances[holder][spender] = value;\r\n emit Approval(holder, spender, value);\r\n }\r\n\r\n /**\r\n * @dev Call from.tokensToSend() if the interface is registered\r\n * @param operator address operator requesting the transfer\r\n * @param from address token holder address\r\n * @param to address recipient address\r\n * @param amount uint256 amount of tokens to transfer\r\n * @param userData bytes extra information provided by the token holder (if any)\r\n * @param operatorData bytes extra information provided by the operator (if any)\r\n */\r\n function _callTokensToSend(\r\n address operator,\r\n address from,\r\n address to,\r\n uint256 amount,\r\n bytes memory userData,\r\n bytes memory operatorData\r\n )\r\n private\r\n {\r\n address implementer = ERC1820_REGISTRY.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);\r\n if (implementer != address(0)) {\r\n IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but\r\n * tokensReceived() was not registered for the recipient\r\n * @param operator address operator requesting the transfer\r\n * @param from address token holder address\r\n * @param to address recipient address\r\n * @param amount uint256 amount of tokens to transfer\r\n * @param userData bytes extra information provided by the token holder (if any)\r\n * @param operatorData bytes extra information provided by the operator (if any)\r\n * @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient\r\n */\r\n function _callTokensReceived(\r\n address operator,\r\n address from,\r\n address to,\r\n uint256 amount,\r\n bytes memory userData,\r\n bytes memory operatorData,\r\n bool requireReceptionAck\r\n )\r\n private\r\n {\r\n address implementer = ERC1820_REGISTRY.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);\r\n if (implementer != address(0)) {\r\n IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);\r\n } else if (requireReceptionAck) {\r\n require(!to.isContract(), \"ERC777: token recipient contract has no implementer for ERC777TokensRecipient\");\r\n }\r\n }\r\n}\r\n"},"ERC777_StandardToken.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\nimport \u0027./SafeMath.sol\u0027;\r\nimport \"./ERC777.sol\";\r\n\r\n\r\n/**\r\n * @dev Optional functions from the ERC777 standard.\r\n */\r\ncontract ERC777_StandardToken is ERC777 {\r\n\r\n /**\r\n * @dev `defaultOperators` may be an empty array.\r\n */\r\n constructor(\r\n string memory name,\r\n string memory symbol,\r\n address[] memory defaultOperators,\r\n uint256 claimAmount\r\n ) ERC777(name, symbol, defaultOperators)\r\n public\r\n {\r\n uint256 mintAmount = claimAmount.mul(10 ** uint256(18));\r\n _mint(address(0), _msgSender(), mintAmount, \"\", \"\");\r\n }\r\n\r\n}\r\n"},"IERC1820Registry.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\n/**\r\n * @dev Interface of the global ERC1820 Registry, as defined in the\r\n * https://eips.ethereum.org/EIPS/eip-1820[EIP]. Accounts may register\r\n * implementers for interfaces in this registry, as well as query support.\r\n *\r\n * Implementers may be shared by multiple accounts, and can also implement more\r\n * than a single interface for each account. Contracts can implement interfaces\r\n * for themselves, but externally-owned accounts (EOA) must delegate this to a\r\n * contract.\r\n *\r\n * {IERC165} interfaces can also be queried via the registry.\r\n *\r\n * For an in-depth explanation and source code analysis, see the EIP text.\r\n */\r\ninterface IERC1820Registry {\r\n /**\r\n * @dev Sets `newManager` as the manager for `account`. A manager of an\r\n * account is able to set interface implementers for it.\r\n *\r\n * By default, each account is its own manager. Passing a value of `0x0` in\r\n * `newManager` will reset the manager to this initial state.\r\n *\r\n * Emits a {ManagerChanged} event.\r\n *\r\n * Requirements:\r\n *\r\n * - the caller must be the current manager for `account`.\r\n */\r\n function setManager(address account, address newManager) external;\r\n\r\n /**\r\n * @dev Returns the manager for `account`.\r\n *\r\n * See {setManager}.\r\n */\r\n function getManager(address account) external view returns (address);\r\n\r\n /**\r\n * @dev Sets the `implementer` contract as `account`\u0027s implementer for\r\n * `interfaceHash`.\r\n *\r\n * `account` being the zero address is an alias for the caller\u0027s address.\r\n * The zero address can also be used in `implementer` to remove an old one.\r\n *\r\n * See {interfaceHash} to learn how these are created.\r\n *\r\n * Emits an {InterfaceImplementerSet} event.\r\n *\r\n * Requirements:\r\n *\r\n * - the caller must be the current manager for `account`.\r\n * - `interfaceHash` must not be an {IERC165} interface id (i.e. it must not\r\n * end in 28 zeroes).\r\n * - `implementer` must implement {IERC1820Implementer} and return true when\r\n * queried for support, unless `implementer` is the caller. See\r\n * {IERC1820Implementer-canImplementInterfaceForAddress}.\r\n */\r\n function setInterfaceImplementer(address account, bytes32 interfaceHash, address implementer) external;\r\n\r\n /**\r\n * @dev Returns the implementer of `interfaceHash` for `account`. If no such\r\n * implementer is registered, returns the zero address.\r\n *\r\n * If `interfaceHash` is an {IERC165} interface id (i.e. it ends with 28\r\n * zeroes), `account` will be queried for support of it.\r\n *\r\n * `account` being the zero address is an alias for the caller\u0027s address.\r\n */\r\n function getInterfaceImplementer(address account, bytes32 interfaceHash) external view returns (address);\r\n\r\n /**\r\n * @dev Returns the interface hash for an `interfaceName`, as defined in the\r\n * corresponding\r\n * https://eips.ethereum.org/EIPS/eip-1820#interface-name[section of the EIP].\r\n */\r\n function interfaceHash(string calldata interfaceName) external pure returns (bytes32);\r\n\r\n /**\r\n * @notice Updates the cache with whether the contract implements an ERC165 interface or not.\r\n * @param account Address of the contract for which to update the cache.\r\n * @param interfaceId ERC165 interface for which to update the cache.\r\n */\r\n function updateERC165Cache(address account, bytes4 interfaceId) external;\r\n\r\n /**\r\n * @notice Checks whether a contract implements an ERC165 interface or not.\r\n * If the result is not cached a direct lookup on the contract address is performed.\r\n * If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling\r\n * {updateERC165Cache} with the contract address.\r\n * @param account Address of the contract to check.\r\n * @param interfaceId ERC165 interface to check.\r\n * @return True if `account` implements `interfaceId`, false otherwise.\r\n */\r\n function implementsERC165Interface(address account, bytes4 interfaceId) external view returns (bool);\r\n\r\n /**\r\n * @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache.\r\n * @param account Address of the contract to check.\r\n * @param interfaceId ERC165 interface to check.\r\n * @return True if `account` implements `interfaceId`, false otherwise.\r\n */\r\n function implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) external view returns (bool);\r\n\r\n event InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer);\r\n\r\n event ManagerChanged(address indexed account, address indexed newManager);\r\n}\r\n"},"IERC20.sol":{"content":"pragma solidity \u003e=0.4.22 \u003c 0.6.0;\r\n\r\n/**\r\n * @dev Interface of the ERC20 standard as defined in the EIP. Does not include\r\n * the optional functions; to access them see {ERC20Detailed}.\r\n */\r\ninterface IERC20 {\r\n /**\r\n * @dev Returns the amount of tokens in existence.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n /**\r\n * @dev Returns the amount of tokens owned by `account`.\r\n */\r\n function balanceOf(address account) external view returns (uint256);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from the caller\u0027s account to `recipient`.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transfer(address recipient, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Returns the remaining number of tokens that `spender` will be\r\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\r\n * zero by default.\r\n *\r\n * This value changes when {approve} or {transferFrom} are called.\r\n */\r\n function allowance(address owner, address spender) external view returns (uint256);\r\n\r\n /**\r\n * @dev Sets `amount` as the allowance of `spender` over the caller\u0027s tokens.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\r\n * that someone may use both the old and the new allowance by unfortunate\r\n * transaction ordering. One possible solution to mitigate this race\r\n * condition is to first reduce the spender\u0027s allowance to 0 and set the\r\n * desired value afterwards:\r\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address spender, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\r\n * allowance mechanism. `amount` is then deducted from the caller\u0027s\r\n * allowance.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\r\n * another (`to`).\r\n *\r\n * Note that `value` may be zero.\r\n */\r\n event Transfer(address indexed from, address indexed to, uint256 value);\r\n\r\n /**\r\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\r\n * a call to {approve}. `value` is the new allowance.\r\n */\r\n event Approval(address indexed owner, address indexed spender, uint256 value);\r\n}\r\n"},"IERC777.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\n/**\r\n * @dev Interface of the ERC777Token standard as defined in the EIP.\r\n *\r\n * This contract uses the\r\n * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 registry standard] to let\r\n * token holders and recipients react to token movements by using setting implementers\r\n * for the associated interfaces in said registry. See {IERC1820Registry} and\r\n * {ERC1820Implementer}.\r\n */\r\ninterface IERC777 {\r\n /**\r\n * @dev Returns the name of the token.\r\n */\r\n function name() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the symbol of the token, usually a shorter version of the\r\n * name.\r\n */\r\n function symbol() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the smallest part of the token that is not divisible. This\r\n * means all token operations (creation, movement and destruction) must have\r\n * amounts that are a multiple of this number.\r\n *\r\n * For most token contracts, this value will equal 1.\r\n */\r\n function granularity() external view returns (uint256);\r\n\r\n /**\r\n * @dev Returns the amount of tokens in existence.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n /**\r\n * @dev Returns the amount of tokens owned by an account (`owner`).\r\n */\r\n function balanceOf(address owner) external view returns (uint256);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from the caller\u0027s account to `recipient`.\r\n *\r\n * If send or receive hooks are registered for the caller and `recipient`,\r\n * the corresponding functions will be called with `data` and empty\r\n * `operatorData`. See {IERC777Sender} and {IERC777Recipient}.\r\n *\r\n * Emits a {Sent} event.\r\n *\r\n * Requirements\r\n *\r\n * - the caller must have at least `amount` tokens.\r\n * - `recipient` cannot be the zero address.\r\n * - if `recipient` is a contract, it must implement the {IERC777Recipient}\r\n * interface.\r\n */\r\n function send(address recipient, uint256 amount, bytes calldata data) external;\r\n\r\n /**\r\n * @dev Destroys `amount` tokens from the caller\u0027s account, reducing the\r\n * total supply.\r\n *\r\n * If a send hook is registered for the caller, the corresponding function\r\n * will be called with `data` and empty `operatorData`. See {IERC777Sender}.\r\n *\r\n * Emits a {Burned} event.\r\n *\r\n * Requirements\r\n *\r\n * - the caller must have at least `amount` tokens.\r\n */\r\n function burn(uint256 amount, bytes calldata data) external;\r\n\r\n /**\r\n * @dev Returns true if an account is an operator of `tokenHolder`.\r\n * Operators can send and burn tokens on behalf of their owners. All\r\n * accounts are their own operator.\r\n *\r\n * See {operatorSend} and {operatorBurn}.\r\n */\r\n function isOperatorFor(address operator, address tokenHolder) external view returns (bool);\r\n\r\n /**\r\n * @dev Make an account an operator of the caller.\r\n *\r\n * See {isOperatorFor}.\r\n *\r\n * Emits an {AuthorizedOperator} event.\r\n *\r\n * Requirements\r\n *\r\n * - `operator` cannot be calling address.\r\n */\r\n function authorizeOperator(address operator) external;\r\n\r\n /**\r\n * @dev Make an account an operator of the caller.\r\n *\r\n * See {isOperatorFor} and {defaultOperators}.\r\n *\r\n * Emits a {RevokedOperator} event.\r\n *\r\n * Requirements\r\n *\r\n * - `operator` cannot be calling address.\r\n */\r\n function revokeOperator(address operator) external;\r\n\r\n /**\r\n * @dev Returns the list of default operators. These accounts are operators\r\n * for all token holders, even if {authorizeOperator} was never called on\r\n * them.\r\n *\r\n * This list is immutable, but individual holders may revoke these via\r\n * {revokeOperator}, in which case {isOperatorFor} will return false.\r\n */\r\n function defaultOperators() external view returns (address[] memory);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from `sender` to `recipient`. The caller must\r\n * be an operator of `sender`.\r\n *\r\n * If send or receive hooks are registered for `sender` and `recipient`,\r\n * the corresponding functions will be called with `data` and\r\n * `operatorData`. See {IERC777Sender} and {IERC777Recipient}.\r\n *\r\n * Emits a {Sent} event.\r\n *\r\n * Requirements\r\n *\r\n * - `sender` cannot be the zero address.\r\n * - `sender` must have at least `amount` tokens.\r\n * - the caller must be an operator for `sender`.\r\n * - `recipient` cannot be the zero address.\r\n * - if `recipient` is a contract, it must implement the {IERC777Recipient}\r\n * interface.\r\n */\r\n function operatorSend(\r\n address sender,\r\n address recipient,\r\n uint256 amount,\r\n bytes calldata data,\r\n bytes calldata operatorData\r\n ) external;\r\n\r\n /**\r\n * @dev Destoys `amount` tokens from `account`, reducing the total supply.\r\n * The caller must be an operator of `account`.\r\n *\r\n * If a send hook is registered for `account`, the corresponding function\r\n * will be called with `data` and `operatorData`. See {IERC777Sender}.\r\n *\r\n * Emits a {Burned} event.\r\n *\r\n * Requirements\r\n *\r\n * - `account` cannot be the zero address.\r\n * - `account` must have at least `amount` tokens.\r\n * - the caller must be an operator for `account`.\r\n */\r\n function operatorBurn(\r\n address account,\r\n uint256 amount,\r\n bytes calldata data,\r\n bytes calldata operatorData\r\n ) external;\r\n\r\n event Sent(\r\n address indexed operator,\r\n address indexed from,\r\n address indexed to,\r\n uint256 amount,\r\n bytes data,\r\n bytes operatorData\r\n );\r\n\r\n event Minted(address indexed operator, address indexed to, uint256 amount, bytes data, bytes operatorData);\r\n\r\n event Burned(address indexed operator, address indexed from, uint256 amount, bytes data, bytes operatorData);\r\n\r\n event AuthorizedOperator(address indexed operator, address indexed tokenHolder);\r\n\r\n event RevokedOperator(address indexed operator, address indexed tokenHolder);\r\n}\r\n"},"IERC777Recipient.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\n/**\r\n * @dev Interface of the ERC777TokensRecipient standard as defined in the EIP.\r\n *\r\n * Accounts can be notified of {IERC777} tokens being sent to them by having a\r\n * contract implement this interface (contract holders can be their own\r\n * implementer) and registering it on the\r\n * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].\r\n *\r\n * See {IERC1820Registry} and {ERC1820Implementer}.\r\n */\r\ninterface IERC777Recipient {\r\n /**\r\n * @dev Called by an {IERC777} token contract whenever tokens are being\r\n * moved or created into a registered account (`to`). The type of operation\r\n * is conveyed by `from` being the zero address or not.\r\n *\r\n * This call occurs _after_ the token contract\u0027s state is updated, so\r\n * {IERC777-balanceOf}, etc., can be used to query the post-operation state.\r\n *\r\n * This function may revert to prevent the operation from being executed.\r\n */\r\n function tokensReceived(\r\n address operator,\r\n address from,\r\n address to,\r\n uint256 amount,\r\n bytes calldata userData,\r\n bytes calldata operatorData\r\n ) external;\r\n}\r\n"},"IERC777Sender.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\n/**\r\n * @dev Interface of the ERC777TokensSender standard as defined in the EIP.\r\n *\r\n * {IERC777} Token holders can be notified of operations performed on their\r\n * tokens by having a contract implement this interface (contract holders can be\r\n * their own implementer) and registering it on the\r\n * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].\r\n *\r\n * See {IERC1820Registry} and {ERC1820Implementer}.\r\n */\r\ninterface IERC777Sender {\r\n /**\r\n * @dev Called by an {IERC777} token contract whenever a registered holder\u0027s\r\n * (`from`) tokens are about to be moved or destroyed. The type of operation\r\n * is conveyed by `to` being the zero address or not.\r\n *\r\n * This call occurs _before_ the token contract\u0027s state is updated, so\r\n * {IERC777-balanceOf}, etc., can be used to query the pre-operation state.\r\n *\r\n * This function may revert to prevent the operation from being executed.\r\n */\r\n function tokensToSend(\r\n address operator,\r\n address from,\r\n address to,\r\n uint256 amount,\r\n bytes calldata userData,\r\n bytes calldata operatorData\r\n ) external;\r\n}\r\n"},"SafeMath.sol":{"content":"pragma solidity ^0.5.0;\r\n\r\n/**\r\n * @dev Wrappers over Solidity\u0027s arithmetic operations with added overflow\r\n * checks.\r\n *\r\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\r\n * in bugs, because programmers usually assume that an overflow raises an\r\n * error, which is the standard behavior in high level programming languages.\r\n * `SafeMath` restores this intuition by reverting the transaction when an\r\n * operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it\u0027s recommended to use it always.\r\n */\r\nlibrary SafeMath {\r\n /**\r\n * @dev Returns the addition of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity\u0027s `+` operator.\r\n *\r\n * Requirements:\r\n * - Addition cannot overflow.\r\n */\r\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\r\n uint256 c = a + b;\r\n require(c \u003e= a, \"SafeMath: addition overflow\");\r\n\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting on\r\n * overflow (when the result is negative).\r\n *\r\n * Counterpart to Solidity\u0027s `-` operator.\r\n *\r\n * Requirements:\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return sub(a, b, \"SafeMath: subtraction overflow\");\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r\n * overflow (when the result is negative).\r\n *\r\n * Counterpart to Solidity\u0027s `-` operator.\r\n *\r\n * Requirements:\r\n * - Subtraction cannot overflow.\r\n *\r\n * _Available since v2.4.0._\r\n */\r\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b \u003c= a, errorMessage);\r\n uint256 c = a - b;\r\n\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity\u0027s `*` operator.\r\n *\r\n * Requirements:\r\n * - Multiplication cannot overflow.\r\n */\r\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r\n // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\r\n // benefit is lost if \u0027b\u0027 is also tested.\r\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n if (a == 0) {\r\n return 0;\r\n }\r\n\r\n uint256 c = a * b;\r\n require(c / a == b, \"SafeMath: multiplication overflow\");\r\n\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers. Reverts on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return div(a, b, \"SafeMath: division by zero\");\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n * - The divisor cannot be zero.\r\n *\r\n * _Available since v2.4.0._\r\n */\r\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n // Solidity only automatically asserts when dividing by 0\r\n require(b \u003e 0, errorMessage);\r\n uint256 c = a / b;\r\n // assert(a == b * c + a % b); // There is no case in which this doesn\u0027t hold\r\n\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * Reverts when dividing by zero.\r\n *\r\n * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return mod(a, b, \"SafeMath: modulo by zero\");\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * Reverts with custom message when dividing by zero.\r\n *\r\n * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n * - The divisor cannot be zero.\r\n *\r\n * _Available since v2.4.0._\r\n */\r\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b != 0, errorMessage);\r\n return a % b;\r\n }\r\n}\r\n"}}File 2 of 2: ERC1820Registry
/* ERC1820 Pseudo-introspection Registry Contract
* This standard defines a universal registry smart contract where any address (contract or regular account) can
* register which interface it supports and which smart contract is responsible for its implementation.
*
* Written in 2019 by Jordi Baylina and Jacques Dafflon
*
* To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to
* this software to the public domain worldwide. This software is distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*
* ███████╗██████╗ ██████╗ ██╗ █████╗ ██████╗ ██████╗
* ██╔════╝██╔══██╗██╔════╝███║██╔══██╗╚════██╗██╔═████╗
* █████╗ ██████╔╝██║ ╚██║╚█████╔╝ █████╔╝██║██╔██║
* ██╔══╝ ██╔══██╗██║ ██║██╔══██╗██╔═══╝ ████╔╝██║
* ███████╗██║ ██║╚██████╗ ██║╚█████╔╝███████╗╚██████╔╝
* ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚════╝ ╚══════╝ ╚═════╝
*
* ██████╗ ███████╗ ██████╗ ██╗███████╗████████╗██████╗ ██╗ ██╗
* ██╔══██╗██╔════╝██╔════╝ ██║██╔════╝╚══██╔══╝██╔══██╗╚██╗ ██╔╝
* ██████╔╝█████╗ ██║ ███╗██║███████╗ ██║ ██████╔╝ ╚████╔╝
* ██╔══██╗██╔══╝ ██║ ██║██║╚════██║ ██║ ██╔══██╗ ╚██╔╝
* ██║ ██║███████╗╚██████╔╝██║███████║ ██║ ██║ ██║ ██║
* ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
*
*/
pragma solidity 0.5.3;
// IV is value needed to have a vanity address starting with '0x1820'.
// IV: 53759
/// @dev The interface a contract MUST implement if it is the implementer of
/// some (other) interface for any address other than itself.
interface ERC1820ImplementerInterface {
/// @notice Indicates whether the contract implements the interface 'interfaceHash' for the address 'addr' or not.
/// @param interfaceHash keccak256 hash of the name of the interface
/// @param addr Address for which the contract will implement the interface
/// @return ERC1820_ACCEPT_MAGIC only if the contract implements 'interfaceHash' for the address 'addr'.
function canImplementInterfaceForAddress(bytes32 interfaceHash, address addr) external view returns(bytes32);
}
/// @title ERC1820 Pseudo-introspection Registry Contract
/// @author Jordi Baylina and Jacques Dafflon
/// @notice This contract is the official implementation of the ERC1820 Registry.
/// @notice For more details, see https://eips.ethereum.org/EIPS/eip-1820
contract ERC1820Registry {
/// @notice ERC165 Invalid ID.
bytes4 constant internal INVALID_ID = 0xffffffff;
/// @notice Method ID for the ERC165 supportsInterface method (= `bytes4(keccak256('supportsInterface(bytes4)'))`).
bytes4 constant internal ERC165ID = 0x01ffc9a7;
/// @notice Magic value which is returned if a contract implements an interface on behalf of some other address.
bytes32 constant internal ERC1820_ACCEPT_MAGIC = keccak256(abi.encodePacked("ERC1820_ACCEPT_MAGIC"));
/// @notice mapping from addresses and interface hashes to their implementers.
mapping(address => mapping(bytes32 => address)) internal interfaces;
/// @notice mapping from addresses to their manager.
mapping(address => address) internal managers;
/// @notice flag for each address and erc165 interface to indicate if it is cached.
mapping(address => mapping(bytes4 => bool)) internal erc165Cached;
/// @notice Indicates a contract is the 'implementer' of 'interfaceHash' for 'addr'.
event InterfaceImplementerSet(address indexed addr, bytes32 indexed interfaceHash, address indexed implementer);
/// @notice Indicates 'newManager' is the address of the new manager for 'addr'.
event ManagerChanged(address indexed addr, address indexed newManager);
/// @notice Query if an address implements an interface and through which contract.
/// @param _addr Address being queried for the implementer of an interface.
/// (If '_addr' is the zero address then 'msg.sender' is assumed.)
/// @param _interfaceHash Keccak256 hash of the name of the interface as a string.
/// E.g., 'web3.utils.keccak256("ERC777TokensRecipient")' for the 'ERC777TokensRecipient' interface.
/// @return The address of the contract which implements the interface '_interfaceHash' for '_addr'
/// or '0' if '_addr' did not register an implementer for this interface.
function getInterfaceImplementer(address _addr, bytes32 _interfaceHash) external view returns (address) {
address addr = _addr == address(0) ? msg.sender : _addr;
if (isERC165Interface(_interfaceHash)) {
bytes4 erc165InterfaceHash = bytes4(_interfaceHash);
return implementsERC165Interface(addr, erc165InterfaceHash) ? addr : address(0);
}
return interfaces[addr][_interfaceHash];
}
/// @notice Sets the contract which implements a specific interface for an address.
/// Only the manager defined for that address can set it.
/// (Each address is the manager for itself until it sets a new manager.)
/// @param _addr Address for which to set the interface.
/// (If '_addr' is the zero address then 'msg.sender' is assumed.)
/// @param _interfaceHash Keccak256 hash of the name of the interface as a string.
/// E.g., 'web3.utils.keccak256("ERC777TokensRecipient")' for the 'ERC777TokensRecipient' interface.
/// @param _implementer Contract address implementing '_interfaceHash' for '_addr'.
function setInterfaceImplementer(address _addr, bytes32 _interfaceHash, address _implementer) external {
address addr = _addr == address(0) ? msg.sender : _addr;
require(getManager(addr) == msg.sender, "Not the manager");
require(!isERC165Interface(_interfaceHash), "Must not be an ERC165 hash");
if (_implementer != address(0) && _implementer != msg.sender) {
require(
ERC1820ImplementerInterface(_implementer)
.canImplementInterfaceForAddress(_interfaceHash, addr) == ERC1820_ACCEPT_MAGIC,
"Does not implement the interface"
);
}
interfaces[addr][_interfaceHash] = _implementer;
emit InterfaceImplementerSet(addr, _interfaceHash, _implementer);
}
/// @notice Sets '_newManager' as manager for '_addr'.
/// The new manager will be able to call 'setInterfaceImplementer' for '_addr'.
/// @param _addr Address for which to set the new manager.
/// @param _newManager Address of the new manager for 'addr'. (Pass '0x0' to reset the manager to '_addr'.)
function setManager(address _addr, address _newManager) external {
require(getManager(_addr) == msg.sender, "Not the manager");
managers[_addr] = _newManager == _addr ? address(0) : _newManager;
emit ManagerChanged(_addr, _newManager);
}
/// @notice Get the manager of an address.
/// @param _addr Address for which to return the manager.
/// @return Address of the manager for a given address.
function getManager(address _addr) public view returns(address) {
// By default the manager of an address is the same address
if (managers[_addr] == address(0)) {
return _addr;
} else {
return managers[_addr];
}
}
/// @notice Compute the keccak256 hash of an interface given its name.
/// @param _interfaceName Name of the interface.
/// @return The keccak256 hash of an interface name.
function interfaceHash(string calldata _interfaceName) external pure returns(bytes32) {
return keccak256(abi.encodePacked(_interfaceName));
}
/* --- ERC165 Related Functions --- */
/* --- Developed in collaboration with William Entriken. --- */
/// @notice Updates the cache with whether the contract implements an ERC165 interface or not.
/// @param _contract Address of the contract for which to update the cache.
/// @param _interfaceId ERC165 interface for which to update the cache.
function updateERC165Cache(address _contract, bytes4 _interfaceId) external {
interfaces[_contract][_interfaceId] = implementsERC165InterfaceNoCache(
_contract, _interfaceId) ? _contract : address(0);
erc165Cached[_contract][_interfaceId] = true;
}
/// @notice Checks whether a contract implements an ERC165 interface or not.
// If the result is not cached a direct lookup on the contract address is performed.
// If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling
// 'updateERC165Cache' with the contract address.
/// @param _contract Address of the contract to check.
/// @param _interfaceId ERC165 interface to check.
/// @return True if '_contract' implements '_interfaceId', false otherwise.
function implementsERC165Interface(address _contract, bytes4 _interfaceId) public view returns (bool) {
if (!erc165Cached[_contract][_interfaceId]) {
return implementsERC165InterfaceNoCache(_contract, _interfaceId);
}
return interfaces[_contract][_interfaceId] == _contract;
}
/// @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache.
/// @param _contract Address of the contract to check.
/// @param _interfaceId ERC165 interface to check.
/// @return True if '_contract' implements '_interfaceId', false otherwise.
function implementsERC165InterfaceNoCache(address _contract, bytes4 _interfaceId) public view returns (bool) {
uint256 success;
uint256 result;
(success, result) = noThrowCall(_contract, ERC165ID);
if (success == 0 || result == 0) {
return false;
}
(success, result) = noThrowCall(_contract, INVALID_ID);
if (success == 0 || result != 0) {
return false;
}
(success, result) = noThrowCall(_contract, _interfaceId);
if (success == 1 && result == 1) {
return true;
}
return false;
}
/// @notice Checks whether the hash is a ERC165 interface (ending with 28 zeroes) or not.
/// @param _interfaceHash The hash to check.
/// @return True if '_interfaceHash' is an ERC165 interface (ending with 28 zeroes), false otherwise.
function isERC165Interface(bytes32 _interfaceHash) internal pure returns (bool) {
return _interfaceHash & 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0;
}
/// @dev Make a call on a contract without throwing if the function does not exist.
function noThrowCall(address _contract, bytes4 _interfaceId)
internal view returns (uint256 success, uint256 result)
{
bytes4 erc165ID = ERC165ID;
assembly {
let x := mload(0x40) // Find empty storage location using "free memory pointer"
mstore(x, erc165ID) // Place signature at beginning of empty storage
mstore(add(x, 0x04), _interfaceId) // Place first argument directly next to signature
success := staticcall(
30000, // 30k gas
_contract, // To addr
x, // Inputs are stored at location x
0x24, // Inputs are 36 (4 + 32) bytes long
x, // Store output over input (saves space)
0x20 // Outputs are 32 bytes long
)
result := mload(x) // Load the result
}
}
}