{"sources":{"contracts/ERC20Impl.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\nimport \"./CustodianUpgradeableV1dot1.sol\";\nimport \"./ERC20Proxy.sol\";\nimport \"./ERC20Store.sol\";\n\n/** @title  ERC20 compliant token intermediary contract holding core logic.\n  *\n  * @notice  This contract serves as an intermediary between the exposed ERC20\n  * interface in ERC20Proxy and the store of balances in ERC20Store. This\n  * contract contains core logic that the proxy can delegate to\n  * and that the store is called by.\n  *\n  * @dev  This contract contains the core logic to implement the\n  * ERC20 specification as well as several extensions.\n  * 1. Changes to the token supply.\n  * 2. Batched transfers.\n  * 3. Relative changes to spending approvals.\n  * 4. Delegated transfer control ('sweeping').\n  *\n  * @author  Gemini Trust Company, LLC\n  */\ncontract ERC20Impl is CustodianUpgradeableV1dot1 {\n\n    // TYPES\n    /// @dev  The struct type for pending increases to the token supply (print).\n    struct PendingPrint {\n        address receiver;\n        uint256 value;\n    }\n\n    // MEMBERS\n    /// @dev  The reference to the proxy.\n    ERC20Proxy immutable public erc20Proxy;\n\n    /// @dev  The reference to the store.\n    ERC20Store immutable public erc20Store;\n\n    /// @dev  The map of lock ids to pending token increases.\n    mapping (bytes32 => PendingPrint) public pendingPrintMap;\n\n    // CONSTRUCTOR\n    constructor(\n          address _erc20Proxy,\n          address _erc20Store,\n          address _custodian\n    )\n        CustodianUpgradeableV1dot1(_custodian)\n    {\n        erc20Proxy = ERC20Proxy(_erc20Proxy);\n        erc20Store = ERC20Store(_erc20Store);\n    }\n\n    // MODIFIERS\n    modifier onlyProxy {\n        require(msg.sender == address(erc20Proxy), \"unauthorized\");\n        _;\n    }\n\n\n    /** @notice  Core logic of the ERC20 `approve` function.\n      *\n      * @dev  This function can only be called by the referenced proxy,\n      * which has an `approve` function.\n      * Every argument passed to that function as well as the original\n      * `msg.sender` gets passed to this function.\n      * NOTE: approvals for the zero address (unspendable) are disallowed.\n      *\n      * @param  _sender  The address initiating the approval in proxy.\n      */\n    function approveWithSender(\n        address _sender,\n        address _spender,\n        uint256 _value\n    )\n        external\n        onlyProxy\n        returns (bool success)\n    {\n        require(_spender != address(0), \"zero address\"); // disallow unspendable approvals\n        erc20Store.setAllowance(_sender, _spender, _value);\n        erc20Proxy.emitApproval(_sender, _spender, _value);\n        return true;\n    }\n\n    /** @notice  Core logic of the `increaseApproval` function.\n      *\n      * @dev  This function can only be called by the referenced proxy,\n      * which has an `increaseApproval` function.\n      * Every argument passed to that function as well as the original\n      * `msg.sender` gets passed to this function.\n      * NOTE: approvals for the zero address (unspendable) are disallowed.\n      *\n      * @param  _sender  The address initiating the approval.\n      */\n    function increaseApprovalWithSender(\n        address _sender,\n        address _spender,\n        uint256 _addedValue\n    )\n        external\n        onlyProxy\n        returns (bool success)\n    {\n        require(_spender != address(0), \"zero address\"); // disallow unspendable approvals\n        uint256 currentAllowance = erc20Store.allowed(_sender, _spender);\n\n        unchecked {\n            // unchecked `+` is safe as overflow check follows\n            uint256 newAllowance = currentAllowance + _addedValue;\n            require(newAllowance >= currentAllowance, \"overflow\");\n\n            erc20Store.setAllowance(_sender, _spender, newAllowance);\n            erc20Proxy.emitApproval(_sender, _spender, newAllowance);\n            return true;\n        }\n    }\n\n    /** @notice  Core logic of the `decreaseApproval` function.\n      *\n      * @dev  This function can only be called by the referenced proxy,\n      * which has a `decreaseApproval` function.\n      * Every argument passed to that function as well as the original\n      * `msg.sender` gets passed to this function.\n      * NOTE: approvals for the zero address (unspendable) are disallowed.\n      *\n      * @param  _sender  The address initiating the approval.\n      */\n    function decreaseApprovalWithSender(\n        address _sender,\n        address _spender,\n        uint256 _subtractedValue\n    )\n        external\n        onlyProxy\n        returns (bool success)\n    {\n        require(_spender != address(0), \"zero address\"); // disallow unspendable approvals\n        uint256 currentAllowance = erc20Store.allowed(_sender, _spender);\n\n        unchecked {\n            // unchecked `-` is safe as overflow check follows\n            uint256 newAllowance = currentAllowance - _subtractedValue;\n            require(newAllowance <= currentAllowance, \"overflow\");\n\n            erc20Store.setAllowance(_sender, _spender, newAllowance);\n            erc20Proxy.emitApproval(_sender, _spender, newAllowance);\n        }\n\n        return true;\n    }\n\n    /** @notice  Requests an increase in the token supply, with the newly created\n      * tokens to be added to the balance of the specified account.\n      *\n      * @dev  Returns a unique lock id associated with the request.\n      * Anyone can call this function, but confirming the request is authorized\n      * by the custodian.\n      * NOTE: printing to the zero address is disallowed.\n      *\n      * @param  _receiver  The receiving address of the print, if confirmed.\n      * @param  _value  The number of tokens to add to the total supply and the\n      * balance of the receiving address, if confirmed.\n      *\n      * @return  lockId  A unique identifier for this request.\n      */\n    function requestPrint(address _receiver, uint256 _value) external returns (bytes32 lockId) {\n        require(_receiver != address(0), \"zero address\");\n\n        (bytes32 preLockId, uint256 lockRequestIdx) = generatePreLockId();\n        lockId = keccak256(\n            abi.encodePacked(\n                preLockId,\n                this.requestPrint.selector,\n                _receiver,\n                _value\n            )\n        );\n\n        pendingPrintMap[lockId] = PendingPrint({\n            receiver: _receiver,\n            value: _value\n        });\n\n        emit PrintingLocked(lockId, _receiver, _value, lockRequestIdx);\n    }\n\n    function _executePrint(address _receiver, uint256 _value) private returns (bool success) {\n        uint256 supply = erc20Store.totalSupply();\n\n        unchecked {\n            // unchecked `+` is safe as overflow check follows\n            uint256 newSupply = supply + _value;\n            if (newSupply >= supply) {\n                erc20Store.setTotalSupply(newSupply);\n                erc20Store.addBalance(_receiver, _value);\n\n                erc20Proxy.emitTransfer(address(0), _receiver, _value);\n                return true;\n            }\n        }\n    }\n\n    function executePrint(address _receiver, uint256 _value) external onlyCustodian {\n        require(_receiver != address(0), \"zero address\");\n        _executePrint(_receiver, _value);\n    }\n\n    /** @notice  Confirms a pending increase in the token supply.\n      *\n      * @dev  When called by the custodian with a lock id associated with a\n      * pending increase, the amount requested to be printed in the print request\n      * is printed to the receiving address specified in that same request.\n      * NOTE: this function will not execute any print that would overflow the\n      * total supply, but it will not revert either.\n      *\n      * @param  _lockId  The identifier of a pending print request.\n      */\n    function confirmPrint(bytes32 _lockId) external onlyCustodian {\n        PendingPrint storage print = pendingPrintMap[_lockId];\n\n        // reject ‘null’ results from the map lookup\n        // this can only be the case if an unknown `_lockId` is received\n        address receiver = print.receiver;\n        require (receiver != address(0), \"no such lockId\");\n        uint256 value = print.value;\n\n        delete pendingPrintMap[_lockId];\n\n        if (_executePrint(receiver, value)) {\n            emit PrintingConfirmed(_lockId, receiver, value);\n        }\n    }\n\n    function _executeBurn(address _owner, uint256 _value) private returns (bool success) {\n        uint256 balanceOfSender = erc20Store.balances(_owner);\n        require(_value <= balanceOfSender, \"insufficient balance\");\n\n        unchecked {\n            // unchecked `-` is safe as `_value <= balanceOfSender`\n            erc20Store.setBalance(_owner, balanceOfSender - _value);\n            // unchecked `-` is safe as the global invariants is that\n            // the sum of all balances equals the total supply, therefore\n            // as `_value <= balanceOfSender`, then `_value <= totalSupply`\n            erc20Store.setTotalSupply(erc20Store.totalSupply() - _value);\n        }\n\n        erc20Proxy.emitTransfer(_owner, address(0), _value);\n\n        return true;\n    }\n\n    /** @notice  Burns the specified value from the sender's balance.\n      *\n      * @dev  Sender's balanced is subtracted by the amount they wish to burn.\n      *\n      * @param  _value  The amount to burn.\n      *\n      * @return  success  true if the burn succeeded.\n      */\n    function burn(uint256 _value) external returns (bool success) {\n        return _executeBurn(msg.sender, _value);\n    }\n\n    /** @notice  Burns the specified value from the owner's balance.\n      *\n      * @dev  Owner's balance is subtracted by the amount the custodian wishes to burn.\n      *\n      * @param  _owner  The owner of the tokens.\n      * @param  _value  The amount to burn.\n      */\n    function burn(address _owner, uint256 _value) external onlyCustodian {\n        _executeBurn(_owner, _value);\n    }\n\n    /** @notice  A function for a sender to issue multiple transfers to multiple\n      * different addresses at once. This function is implemented for gas\n      * considerations when someone wishes to transfer, as one transaction is\n      * cheaper than issuing several distinct individual `transfer` transactions.\n      *\n      * @dev  By specifying a set of destination addresses and values, the\n      * sender can issue one transaction to transfer multiple amounts to\n      * distinct addresses, rather than issuing each as a separate\n      * transaction. The `_tos` and `_values` arrays must be equal length, and\n      * an index in one array corresponds to the same index in the other array\n      * (e.g. `_tos[0]` will receive `_values[0]`, `_tos[1]` will receive\n      * `_values[1]`, and so on.)\n      * NOTE: transfers to the zero address are disallowed.\n      *\n      * @param  _tos  The destination addresses to receive the transfers.\n      * @param  _values  The values for each destination address.\n      * @return  success  If transfers succeeded.\n      */\n    function batchTransfer(address[] calldata _tos, uint256[] calldata _values) external returns (bool success) {\n        require(_tos.length == _values.length, \"inconsistent length\");\n\n        uint256 numTransfers = _tos.length;\n        uint256 senderBalance = erc20Store.balances(msg.sender);\n\n        for (uint256 i = 0; i < numTransfers; i++) {\n          address to = _tos[i];\n          require(to != address(0), \"zero address\");\n          uint256 v = _values[i];\n          require(senderBalance >= v, \"insufficient balance\");\n\n          if (msg.sender != to) {\n            senderBalance -= v;\n            erc20Store.addBalance(to, v);\n          }\n          erc20Proxy.emitTransfer(msg.sender, to, v);\n        }\n\n        erc20Store.setBalance(msg.sender, senderBalance);\n\n        return true;\n    }\n\n    /** @notice  Core logic of the ERC20 `transferFrom` function.\n      *\n      * @dev  This function can only be called by the referenced proxy,\n      * which has a `transferFrom` function.\n      * Every argument passed to that function as well as the original\n      * `msg.sender` gets passed to this function.\n      * NOTE: transfers to the zero address are disallowed.\n      *\n      * @param  _sender  The address initiating the transfer in proxy.\n      */\n    function transferFromWithSender(\n        address _sender,\n        address _from,\n        address _to,\n        uint256 _value\n    )\n        external\n        onlyProxy\n        returns (bool success)\n    {\n        require(_to != address(0), \"zero address\"); // ensure burn is the cannonical transfer to 0x0\n\n        uint256 balanceOfFrom = erc20Store.balances(_from);\n        require(_value <= balanceOfFrom, \"insufficient balance\");\n\n        uint256 senderAllowance = erc20Store.allowed(_from, _sender);\n        require(_value <= senderAllowance, \"insufficient allowance\");\n\n        unchecked {\n            // unchecked `-` is safe as `_value <= balanceOfFrom`\n            erc20Store.setBalance(_from, balanceOfFrom - _value);\n        }\n        erc20Store.addBalance(_to, _value);\n\n        unchecked {\n            // unchecked `-` is safe as `_value <= senderAllowance`\n            erc20Store.setAllowance(_from, _sender, senderAllowance - _value);\n        }\n\n        erc20Proxy.emitTransfer(_from, _to, _value);\n\n        return true;\n    }\n\n    /** @notice  Core logic of the ERC20 `transfer` function.\n      *\n      * @dev  This function can only be called by the referenced proxy,\n      * which has a `transfer` function.\n      * Every argument passed to that function as well as the original\n      * `msg.sender` gets passed to this function.\n      * NOTE: transfers to the zero address are disallowed.\n      *\n      * @param  _sender  The address initiating the transfer in proxy.\n      */\n    function transferWithSender(\n        address _sender,\n        address _to,\n        uint256 _value\n    )\n        external\n        onlyProxy\n        returns (bool success)\n    {\n        require(_to != address(0), \"zero address\"); // ensure burn is the cannonical transfer to 0x0\n\n        uint256 balanceOfSender = erc20Store.balances(_sender);\n        require(_value <= balanceOfSender, \"insufficient balance\");\n\n        unchecked {\n            // unchecked `-` is safe as `_value <= balanceOfSender`\n            erc20Store.setBalance(_sender, balanceOfSender - _value);\n        }\n        erc20Store.addBalance(_to, _value);\n\n        erc20Proxy.emitTransfer(_sender, _to, _value);\n\n        return true;\n    }\n\n    // METHODS (ERC20 sub interface impl.)\n    /// @notice  Core logic of the ERC20 `totalSupply` function.\n    function totalSupply() external view returns (uint256) {\n        return erc20Store.totalSupply();\n    }\n\n    /// @notice  Core logic of the ERC20 `balanceOf` function.\n    function balanceOf(address _owner) external view returns (uint256 balance) {\n        return erc20Store.balances(_owner);\n    }\n\n    /// @notice  Core logic of the ERC20 `allowance` function.\n    function allowance(address _owner, address _spender) external view returns (uint256 remaining) {\n        return erc20Store.allowed(_owner, _spender);\n    }\n\n    // EVENTS\n    /// @dev  Emitted by successful `requestPrint` calls.\n    event PrintingLocked(bytes32 _lockId, address _receiver, uint256 _value, uint256 _lockRequestIdx);\n    /// @dev Emitted by successful `confirmPrint` calls.\n    event PrintingConfirmed(bytes32 _lockId, address _receiver, uint256 _value);\n}\n"},"contracts/CustodianUpgradeableV1dot1.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\nimport \"./LockRequestableV1dot1.sol\";\n\n/** @title  A contract to inherit upgradeable custodianship.\n  *\n  * @notice  A contract that provides re-usable code for upgradeable\n  * custodianship. That custodian may be an account or another contract.\n  *\n  * @dev  This contract is intended to be inherited by any contract\n  * requiring a custodian to control some aspect of its functionality.\n  * This contract provides the mechanism for that custodianship to be\n  * passed from one custodian to the next.\n  *\n  * @author  Gemini Trust Company, LLC\n  */\nabstract contract CustodianUpgradeableV1dot1 is LockRequestableV1dot1 {\n\n    // TYPES\n    /// @dev  The struct type for pending custodian changes.\n    struct CustodianChangeRequest {\n        address proposedNew;\n    }\n\n    // MEMBERS\n    /// @dev  The address of the account or contract that acts as the custodian.\n    address public custodian;\n\n    /// @dev  The map of lock ids to pending custodian changes.\n    mapping (bytes32 => CustodianChangeRequest) public custodianChangeReqs;\n\n    // CONSTRUCTOR\n    constructor(\n        address _custodian\n    )\n      LockRequestableV1dot1()\n    {\n        custodian = _custodian;\n    }\n\n    // MODIFIERS\n    modifier onlyCustodian {\n        require(msg.sender == custodian, \"unauthorized\");\n        _;\n    }\n\n    // PUBLIC FUNCTIONS\n    // (UPGRADE)\n\n    /** @notice  Requests a change of the custodian associated with this contract.\n      *\n      * @dev  Returns a unique lock id associated with the request.\n      * Anyone can call this function, but confirming the request is authorized\n      * by the custodian.\n      *\n      * @param  _proposedCustodian  The address of the new custodian.\n      * @return  lockId  A unique identifier for this request.\n      */\n    function requestCustodianChange(address _proposedCustodian) external returns (bytes32 lockId) {\n        require(_proposedCustodian != address(0), \"zero address\");\n\n        (bytes32 preLockId, uint256 lockRequestIdx) = generatePreLockId();\n        lockId = keccak256(\n            abi.encodePacked(\n                preLockId,\n                this.requestCustodianChange.selector,\n                _proposedCustodian\n            )\n        );\n\n        custodianChangeReqs[lockId] = CustodianChangeRequest({\n            proposedNew: _proposedCustodian\n        });\n\n        emit CustodianChangeRequested(lockId, msg.sender, _proposedCustodian, lockRequestIdx);\n    }\n\n    /** @notice  Confirms a pending change of the custodian associated with this contract.\n      *\n      * @dev  When called by the current custodian with a lock id associated with a\n      * pending custodian change, the `address custodian` member will be updated with the\n      * requested address.\n      *\n      * @param  _lockId  The identifier of a pending change request.\n      */\n    function confirmCustodianChange(bytes32 _lockId) external onlyCustodian {\n        custodian = getCustodianChangeReq(_lockId);\n\n        delete custodianChangeReqs[_lockId];\n\n        emit CustodianChangeConfirmed(_lockId, custodian);\n    }\n\n    // PRIVATE FUNCTIONS\n    function getCustodianChangeReq(bytes32 _lockId) private view returns (address _proposedNew) {\n        CustodianChangeRequest storage changeRequest = custodianChangeReqs[_lockId];\n\n        // reject ‘null’ results from the map lookup\n        // this can only be the case if an unknown `_lockId` is received\n        require(changeRequest.proposedNew != address(0), \"no such lockId\");\n\n        return changeRequest.proposedNew;\n    }\n\n    /// @dev  Emitted by successful `requestCustodianChange` calls.\n    event CustodianChangeRequested(\n        bytes32 _lockId,\n        address _msgSender,\n        address _proposedCustodian,\n        uint256 _lockRequestIdx\n    );\n\n    /// @dev Emitted by successful `confirmCustodianChange` calls.\n    event CustodianChangeConfirmed(bytes32 _lockId, address _newCustodian);\n}\n"},"contracts/ERC20Proxy.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\nimport \"./ERC20Interface.sol\";\nimport \"./ERC20ImplUpgradeable.sol\";\n\n/** @title  Public interface to ERC20 compliant token.\n  *\n  * @notice  This contract is a permanent entry point to an ERC20 compliant\n  * system of contracts.\n  *\n  * @dev  This contract contains no business logic and instead\n  * delegates to an instance of ERC20Impl. This contract also has no storage\n  * that constitutes the operational state of the token. This contract is\n  * upgradeable in the sense that the `custodian` can update the\n  * `erc20Impl` address, thus redirecting the delegation of business logic.\n  * The `custodian` is also authorized to pass custodianship.\n  *\n  * @author  Gemini Trust Company, LLC\n  */\ncontract ERC20Proxy is ERC20Interface, ERC20ImplUpgradeable {\n\n    // MEMBERS\n    /// @notice  Returns the name of the token.\n    string public name;\n\n    /// @notice  Returns the symbol of the token.\n    string public symbol;\n\n    /// @notice  Returns the number of decimals the token uses.\n    uint8 public decimals;\n\n    // CONSTRUCTOR\n    constructor(\n        string memory _name,\n        string memory _symbol,\n        uint8 _decimals,\n        address _custodian\n    )\n        ERC20ImplUpgradeable(_custodian)\n    {\n        name = _name;\n        symbol = _symbol;\n        decimals = _decimals;\n    }\n\n    // PUBLIC FUNCTIONS\n    // (ERC20Interface)\n    /** @notice  Returns the total token supply.\n      *\n      * @return  the total token supply.\n      */\n    function totalSupply() public override view returns (uint256) {\n        return erc20Impl.totalSupply();\n    }\n\n    /** @notice  Returns the account balance of another account with address\n      * `_owner`.\n      *\n      * @return  balance  the balance of account with address `_owner`.\n      */\n    function balanceOf(address _owner) public override view returns (uint256 balance) {\n        return erc20Impl.balanceOf(_owner);\n    }\n\n    /** @dev Internal use only.\n      */\n    function emitTransfer(address _from, address _to, uint256 _value) public onlyImpl {\n        emit Transfer(_from, _to, _value);\n    }\n\n    /** @notice  Transfers `_value` amount of tokens to address `_to`.\n      *\n      * @dev Will fire the `Transfer` event. Will revert if the `_from`\n      * account balance does not have enough tokens to spend.\n      *\n      * @return  success  true if transfer completes.\n      */\n    function transfer(address _to, uint256 _value) public override returns (bool success) {\n        return erc20Impl.transferWithSender(msg.sender, _to, _value);\n    }\n\n    /** @notice  Transfers `_value` amount of tokens from address `_from`\n      * to address `_to`.\n      *\n      * @dev  Will fire the `Transfer` event. Will revert unless the `_from`\n      * account has deliberately authorized the sender of the message\n      * via some mechanism.\n      *\n      * @return  success  true if transfer completes.\n      */\n    function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) {\n        return erc20Impl.transferFromWithSender(msg.sender, _from, _to, _value);\n    }\n\n    /** @dev Internal use only.\n      */\n    function emitApproval(address _owner, address _spender, uint256 _value) public onlyImpl {\n        emit Approval(_owner, _spender, _value);\n    }\n\n    /** @notice  Allows `_spender` to withdraw from your account multiple times,\n      * up to the `_value` amount. If this function is called again it\n      * overwrites the current allowance with _value.\n      *\n      * @dev  Will fire the `Approval` event.\n      *\n      * @return  success  true if approval completes.\n      */\n    function approve(address _spender, uint256 _value) public override returns (bool success) {\n        return erc20Impl.approveWithSender(msg.sender, _spender, _value);\n    }\n\n    /** @notice Increases the amount `_spender` is allowed to withdraw from\n      * your account.\n      * This function is implemented to avoid the race condition in standard\n      * ERC20 contracts surrounding the `approve` method.\n      *\n      * @dev  Will fire the `Approval` event. This function should be used instead of\n      * `approve`.\n      *\n      * @return  success  true if approval completes.\n      */\n    function increaseApproval(address _spender, uint256 _addedValue) public returns (bool success) {\n        return erc20Impl.increaseApprovalWithSender(msg.sender, _spender, _addedValue);\n    }\n\n    /** @notice  Decreases the amount `_spender` is allowed to withdraw from\n      * your account. This function is implemented to avoid the race\n      * condition in standard ERC20 contracts surrounding the `approve` method.\n      *\n      * @dev  Will fire the `Approval` event. This function should be used\n      * instead of `approve`.\n      *\n      * @return  success  true if approval completes.\n      */\n    function decreaseApproval(address _spender, uint256 _subtractedValue) public returns (bool success) {\n        return erc20Impl.decreaseApprovalWithSender(msg.sender, _spender, _subtractedValue);\n    }\n\n    /** @notice  Returns how much `_spender` is currently allowed to spend from\n      * `_owner`'s balance.\n      *\n      * @return  remaining  the remaining allowance.\n      */\n    function allowance(address _owner, address _spender) public override view returns (uint256 remaining) {\n        return erc20Impl.allowance(_owner, _spender);\n    }\n}\n"},"contracts/ERC20Store.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\nimport \"./ERC20ImplUpgradeable.sol\";\n\n/** @title  ERC20 compliant token balance store.\n  *\n  * @notice  This contract serves as the store of balances, allowances, and\n  * supply for the ERC20 compliant token. No business logic exists here.\n  *\n  * @dev  This contract contains no business logic and instead\n  * is the final destination for any change in balances, allowances, or token\n  * supply. This contract is upgradeable in the sense that its custodian can\n  * update the `erc20Impl` address, thus redirecting the source of logic that\n  * determines how the balances will be updated.\n  *\n  * @author  Gemini Trust Company, LLC\n  */\ncontract ERC20Store is ERC20ImplUpgradeable {\n\n    // MEMBERS\n    /// @dev  The total token supply.\n    uint256 public totalSupply;\n\n    /// @dev  The mapping of balances.\n    mapping (address => uint256) public balances;\n\n    /// @dev  The mapping of allowances.\n    mapping (address => mapping (address => uint256)) public allowed;\n\n    // CONSTRUCTOR\n    constructor(address _custodian) ERC20ImplUpgradeable(_custodian) {\n        totalSupply = 0;\n    }\n\n\n    // PUBLIC FUNCTIONS\n    // (ERC20 Ledger)\n\n    /** @notice  The function to set the total supply of tokens.\n      *\n      * @dev  Intended for use by token implementation functions\n      * that update the total supply. The only authorized caller\n      * is the active implementation.\n      *\n      * @param _newTotalSupply the value to set as the new total supply\n      */\n    function setTotalSupply(\n        uint256 _newTotalSupply\n    )\n        public\n        onlyImpl\n    {\n        totalSupply = _newTotalSupply;\n    }\n\n    /** @notice  Sets how much `_owner` allows `_spender` to transfer on behalf\n      * of `_owner`.\n      *\n      * @dev  Intended for use by token implementation functions\n      * that update spending allowances. The only authorized caller\n      * is the active implementation.\n      *\n      * @param  _owner  The account that will allow an on-behalf-of spend.\n      * @param  _spender  The account that will spend on behalf of the owner.\n      * @param  _value  The limit of what can be spent.\n      */\n    function setAllowance(\n        address _owner,\n        address _spender,\n        uint256 _value\n    )\n        public\n        onlyImpl\n    {\n        allowed[_owner][_spender] = _value;\n    }\n\n    /** @notice  Sets the balance of `_owner` to `_newBalance`.\n      *\n      * @dev  Intended for use by token implementation functions\n      * that update balances. The only authorized caller\n      * is the active implementation.\n      *\n      * @param  _owner  The account that will hold a new balance.\n      * @param  _newBalance  The balance to set.\n      */\n    function setBalance(\n        address _owner,\n        uint256 _newBalance\n    )\n        public\n        onlyImpl\n    {\n        balances[_owner] = _newBalance;\n    }\n\n    /** @notice Adds `_balanceIncrease` to `_owner`'s balance.\n      *\n      * @dev  Intended for use by token implementation functions\n      * that update balances. The only authorized caller\n      * is the active implementation.\n      * WARNING: the caller is responsible for preventing overflow.\n      *\n      * @param  _owner  The account that will hold a new balance.\n      * @param  _balanceIncrease  The balance to add.\n      */\n    function addBalance(\n        address _owner,\n        uint256 _balanceIncrease\n    )\n        public\n        onlyImpl\n    {\n        unchecked {\n            // unchecked `+` as caller is responsible\n            // see occurrences of `.addBalance` in `ERC20Impl`\n            balances[_owner] = balances[_owner] + _balanceIncrease;\n        }\n    }\n}\n"},"contracts/LockRequestableV1dot1.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\n/** @title  A contract for generating unique identifiers\n  *\n  * @notice  A contract that provides a identifier generation scheme,\n  * guaranteeing uniqueness across all contracts that inherit from it,\n  * as well as unpredictability of future identifiers.\n  *\n  * @dev  This contract is intended to be inherited by any contract that\n  * implements the callback software pattern for cooperative custodianship.\n  *\n  * @author  Gemini Trust Company, LLC\n  */\nabstract contract LockRequestableV1dot1 {\n\n    // MEMBERS\n    /// @notice  the count of all invocations of `generatePreLockId`.\n    uint256 public lockRequestCount;\n\n    // CONSTRUCTOR\n    constructor() {\n        lockRequestCount = 0;\n    }\n\n    // FUNCTIONS\n    /** @notice  Returns a fresh unique identifier.\n      *\n      * @dev the generation scheme uses three components.\n      * First, the blockhash of the previous block.\n      * Second, the deployed address.\n      * Third, the next value of the counter.\n      * This ensure that identifiers are unique across all contracts\n      * following this scheme, and that future identifiers are\n      * unpredictable.\n      *\n      * @return preLockId a 32-byte unique identifier.\n      * @return lockRequestIdx index of lock request\n\n      */\n    function generatePreLockId() internal returns (bytes32 preLockId, uint256 lockRequestIdx) {\n        unchecked {\n            // unchecked `-` is safe as this can never be evaluated in the genesis (0) block\n            // unchecked `++` is safe as it is infeasible to exhaust 256-bit integer counter\n            lockRequestIdx = ++lockRequestCount;\n            preLockId = keccak256(\n                abi.encodePacked(\n                    blockhash(block.number - 1),\n                    address(this),\n                    lockRequestIdx\n                )\n            );\n        }\n    }\n}\n"},"contracts/ERC20Interface.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\ninterface ERC20Interface {\n  // METHODS\n\n  // NOTE:\n  //   public getter functions are not currently recognised as an\n  //   implementation of the matching abstract function by the compiler.\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#name\n  // function name() public view returns (string);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#symbol\n  // function symbol() public view returns (string);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#totalsupply\n  // function decimals() public view returns (uint8);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#totalsupply\n  function totalSupply() external view returns (uint256);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#balanceof\n  function balanceOf(address _owner) external view returns (uint256 balance);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer\n  function transfer(address _to, uint256 _value) external returns (bool success);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transferfrom\n  function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#approve\n  function approve(address _spender, uint256 _value) external returns (bool success);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#allowance\n  function allowance(address _owner, address _spender) external view returns (uint256 remaining);\n\n  // EVENTS\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1\n  event Transfer(address indexed _from, address indexed _to, uint256 _value);\n\n  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#approval\n  event Approval(address indexed _owner, address indexed _spender, uint256 _value);\n}\n"},"contracts/ERC20ImplUpgradeable.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\nimport \"./CustodianUpgradeable.sol\";\nimport \"./ERC20Impl.sol\";\n\n/** @title  A contract to inherit upgradeable token implementations.\n  *\n  * @notice  A contract that provides re-usable code for upgradeable\n  * token implementations. It itself inherits from `CustodianUpgradable`\n  * as the upgrade process is controlled by the custodian.\n  *\n  * @dev  This contract is intended to be inherited by any contract\n  * requiring a reference to the active token implementation, either\n  * to delegate calls to it, or authorize calls from it. This contract\n  * provides the mechanism for that implementation to be be replaced,\n  * which constitutes an implementation upgrade.\n  *\n  * @author Gemini Trust Company, LLC\n  */\nabstract contract ERC20ImplUpgradeable is CustodianUpgradeable {\n\n    // TYPES\n    /// @dev  The struct type for pending implementation changes.\n    struct ImplChangeRequest {\n        address proposedNew;\n    }\n\n    // MEMBERS\n    // @dev  The reference to the active token implementation.\n    ERC20Impl public erc20Impl;\n\n    /// @dev  The map of lock ids to pending implementation changes.\n    mapping (bytes32 => ImplChangeRequest) public implChangeReqs;\n\n    // CONSTRUCTOR\n    constructor(address _custodian) CustodianUpgradeable(_custodian) {\n        erc20Impl = ERC20Impl(address(0));\n    }\n\n    // MODIFIERS\n    modifier onlyImpl {\n        require(msg.sender == address(erc20Impl));\n        _;\n    }\n\n    // PUBLIC FUNCTIONS\n    // (UPGRADE)\n    /** @notice  Requests a change of the active implementation associated\n      * with this contract.\n      *\n      * @dev  Returns a unique lock id associated with the request.\n      * Anyone can call this function, but confirming the request is authorized\n      * by the custodian.\n      *\n      * @param  _proposedImpl  The address of the new active implementation.\n      * @return  lockId  A unique identifier for this request.\n      */\n    function requestImplChange(address _proposedImpl) public returns (bytes32 lockId) {\n        require(_proposedImpl != address(0));\n\n        lockId = generateLockId();\n\n        implChangeReqs[lockId] = ImplChangeRequest({\n            proposedNew: _proposedImpl\n        });\n\n        emit ImplChangeRequested(lockId, msg.sender, _proposedImpl);\n    }\n\n    /** @notice  Confirms a pending change of the active implementation\n      * associated with this contract.\n      *\n      * @dev  When called by the custodian with a lock id associated with a\n      * pending change, the `ERC20Impl erc20Impl` member will be updated\n      * with the requested address.\n      *\n      * @param  _lockId  The identifier of a pending change request.\n      */\n    function confirmImplChange(bytes32 _lockId) public onlyCustodian {\n        erc20Impl = getImplChangeReq(_lockId);\n\n        delete implChangeReqs[_lockId];\n\n        emit ImplChangeConfirmed(_lockId, address(erc20Impl));\n    }\n\n    // PRIVATE FUNCTIONS\n    function getImplChangeReq(bytes32 _lockId) private view returns (ERC20Impl _proposedNew) {\n        ImplChangeRequest storage changeRequest = implChangeReqs[_lockId];\n\n        // reject ‘null’ results from the map lookup\n        // this can only be the case if an unknown `_lockId` is received\n        require(changeRequest.proposedNew != address(0));\n\n        return ERC20Impl(changeRequest.proposedNew);\n    }\n\n    /// @dev  Emitted by successful `requestImplChange` calls.\n    event ImplChangeRequested(\n        bytes32 _lockId,\n        address _msgSender,\n        address _proposedImpl\n    );\n\n    /// @dev Emitted by successful `confirmImplChange` calls.\n    event ImplChangeConfirmed(bytes32 _lockId, address _newImpl);\n}\n"},"contracts/CustodianUpgradeable.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\nimport \"./LockRequestable.sol\";\n\n/** @title  A contract to inherit upgradeable custodianship.\n  *\n  * @notice  A contract that provides re-usable code for upgradeable\n  * custodianship. That custodian may be an account or another contract.\n  *\n  * @dev  This contract is intended to be inherited by any contract\n  * requiring a custodian to control some aspect of its functionality.\n  * This contract provides the mechanism for that custodianship to be\n  * passed from one custodian to the next.\n  *\n  * @author  Gemini Trust Company, LLC\n  */\nabstract contract CustodianUpgradeable is LockRequestable {\n\n    // TYPES\n    /// @dev  The struct type for pending custodian changes.\n    struct CustodianChangeRequest {\n        address proposedNew;\n    }\n\n    // MEMBERS\n    /// @dev  The address of the account or contract that acts as the custodian.\n    address public custodian;\n\n    /// @dev  The map of lock ids to pending custodian changes.\n    mapping (bytes32 => CustodianChangeRequest) public custodianChangeReqs;\n\n    // CONSTRUCTOR\n    constructor(\n        address _custodian\n    )\n      LockRequestable()\n    {\n        custodian = _custodian;\n    }\n\n    // MODIFIERS\n    modifier onlyCustodian {\n        require(msg.sender == custodian);\n        _;\n    }\n\n    // PUBLIC FUNCTIONS\n    // (UPGRADE)\n\n    /** @notice  Requests a change of the custodian associated with this contract.\n      *\n      * @dev  Returns a unique lock id associated with the request.\n      * Anyone can call this function, but confirming the request is authorized\n      * by the custodian.\n      *\n      * @param  _proposedCustodian  The address of the new custodian.\n      * @return  lockId  A unique identifier for this request.\n      */\n    function requestCustodianChange(address _proposedCustodian) public returns (bytes32 lockId) {\n        require(_proposedCustodian != address(0));\n\n        lockId = generateLockId();\n\n        custodianChangeReqs[lockId] = CustodianChangeRequest({\n            proposedNew: _proposedCustodian\n        });\n\n        emit CustodianChangeRequested(lockId, msg.sender, _proposedCustodian);\n    }\n\n    /** @notice  Confirms a pending change of the custodian associated with this contract.\n      *\n      * @dev  When called by the current custodian with a lock id associated with a\n      * pending custodian change, the `address custodian` member will be updated with the\n      * requested address.\n      *\n      * @param  _lockId  The identifier of a pending change request.\n      */\n    function confirmCustodianChange(bytes32 _lockId) public onlyCustodian {\n        custodian = getCustodianChangeReq(_lockId);\n\n        delete custodianChangeReqs[_lockId];\n\n        emit CustodianChangeConfirmed(_lockId, custodian);\n    }\n\n    // PRIVATE FUNCTIONS\n    function getCustodianChangeReq(bytes32 _lockId) private view returns (address _proposedNew) {\n        CustodianChangeRequest storage changeRequest = custodianChangeReqs[_lockId];\n\n        // reject ‘null’ results from the map lookup\n        // this can only be the case if an unknown `_lockId` is received\n        require(changeRequest.proposedNew != address(0));\n\n        return changeRequest.proposedNew;\n    }\n\n    /// @dev  Emitted by successful `requestCustodianChange` calls.\n    event CustodianChangeRequested(\n        bytes32 _lockId,\n        address _msgSender,\n        address _proposedCustodian\n    );\n\n    /// @dev Emitted by successful `confirmCustodianChange` calls.\n    event CustodianChangeConfirmed(bytes32 _lockId, address _newCustodian);\n}\n"},"contracts/LockRequestable.sol":{"content":"// SPDX-License-Identifier: UNLICENSED\n// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved\npragma solidity ^0.8.0;\n\n/** @title  A contract for generating unique identifiers\n  *\n  * @notice  A contract that provides a identifier generation scheme,\n  * guaranteeing uniqueness across all contracts that inherit from it,\n  * as well as unpredictability of future identifiers.\n  *\n  * @dev  This contract is intended to be inherited by any contract that\n  * implements the callback software pattern for cooperative custodianship.\n  *\n  * @author  Gemini Trust Company, LLC\n  */\nabstract contract LockRequestable {\n\n    // MEMBERS\n    /// @notice  the count of all invocations of `generateLockId`.\n    uint256 public lockRequestCount;\n\n    // CONSTRUCTOR\n    constructor() {\n        lockRequestCount = 0;\n    }\n\n    // FUNCTIONS\n    /** @notice  Returns a fresh unique identifier.\n      *\n      * @dev the generation scheme uses three components.\n      * First, the blockhash of the previous block.\n      * Second, the deployed address.\n      * Third, the next value of the counter.\n      * This ensure that identifiers are unique across all contracts\n      * following this scheme, and that future identifiers are\n      * unpredictable.\n      *\n      * @return lockId a 32-byte unique identifier.\n      */\n    function generateLockId() internal returns (bytes32 lockId) {\n        unchecked {\n            // unchecked `-` is safe as this can never be evaluated in the genesis (0) block\n            // unchecked `++` is safe as it is infeasible to exhaust 256-bit integer counter\n            return keccak256(\n                abi.encodePacked(\n                    blockhash(block.number - 1),\n                    address(this),\n                    ++lockRequestCount\n                )\n            );\n        }\n    }\n}\n"}},"matchId":"56237078","creationMatch":"exact_match","runtimeMatch":"exact_match","verifiedAt":"2026-10-16T17:09:05Z","match":"exact_match","chainId":"1","address":"0x483A1E7F16F46266400f1bAF7abdF445c8D140A2"}