Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xe503f9a8653CDeb807C41aEeaccB9C0dE3C9AAC1
Balance 0 ETH
Nonce 1
Code Size 5965 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

5965 bytes
0x608060405234801561001057600080fd5b50600436106101425760003560e01c8063b646c194116100b8578063f2fde38b1161007c578063f2fde38b146102d0578063f4cb33cc146102e3578063f5e90f94146102f6578063f6708f9614610309578063fc0c546a1461031c578063fddaa0651461032f57600080fd5b8063b646c1941461024b578063b6b55f251461025e578063c9b5ef8e14610271578063d845a4b31461029d578063dd39f00d146102bd57600080fd5b806360f0a5ac1161010a57806360f0a5ac146101e65780636a882d51146101f95780636cf4c88f1461020c578063715018a61461021f5780637569d66f146102275780638da5cb5b1461023a57600080fd5b80631d3d89b6146101475780633ccfd60b146101775780633f131d9f1461018157806358d937ce146101bd57806360659a92146101d0575b600080fd5b61015a610155366004611387565b610352565b6040516001600160a01b0390911681526020015b60405180910390f35b61017f610376565b005b6101ad61018f366004611485565b6001600160a01b031660009081526002602052604090205460ff1690565b604051901515815260200161016e565b61017f6101cb366004611387565b610442565b6101d86108da565b60405190815260200161016e565b61017f6101f4366004611485565b61095b565b61017f6102073660046114a0565b6109aa565b61017f61021a366004611485565b6109f2565b61017f610a41565b61017f6102353660046114a0565b610a55565b6000546001600160a01b031661015a565b61017f610259366004611485565b610a9d565b61017f61026c3660046114d5565b610aef565b6101ad61027f366004611485565b6001600160a01b031660009081526001602052604090205460ff1690565b6101d86102ab3660046114d5565b60009081526005602052604090205490565b61017f6102cb366004611485565b610b44565b61017f6102de366004611485565b610b99565b61017f6102f13660046114a0565b610c12565b61017f6103043660046114a0565b610c5a565b6101d86103173660046114ee565b610ca2565b60035461015a906001600160a01b031681565b6101ad61033d3660046114d5565b60009081526004602052604090205460ff1690565b600080610360868686610ca2565b905061036c8184610d7f565b9695505050505050565b61037e610d92565b60006103886108da565b90506000811161039a5761039a611576565b6003546001600160a01b031663a9059cbb6103bd6000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044015b602060405180830381600087803b15801561040657600080fd5b505af115801561041a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043e919061158c565b5050565b61044b3361027f565b6104a75760405162461bcd60e51b815260206004820152602260248201527f52656c617965723a2063616c6c6572206973206e6f74207468652072656c617960448201526132b960f11b60648201526084015b60405180910390fd5b600084511180156104b9575060008351115b80156104c6575060008251115b61051d5760405162461bcd60e51b815260206004820152602260248201527f537761703a206f6e65206f72206d6f726520696e707574732061726520656d70604482015261747960f01b606482015260840161049e565b8151835114801561052f575082518451145b6105875760405162461bcd60e51b8152602060048201526024808201527f537761703a2074686520696e707574206c656e6774687320646f206e6f74206d6044820152630c2e8c6d60e31b606482015260840161049e565b6000610594858585610ca2565b60008181526004602052604090205490915060ff16156105f65760405162461bcd60e51b815260206004820152601a60248201527f537761703a20626174636820616c726561647920657869737473000000000000604482015260640161049e565b60006106028284610d7f565b90506001600160a01b03811661065a5760405162461bcd60e51b815260206004820152601d60248201527f45434453413a207369676e6174757265206973206e6f742076616c6964000000604482015260640161049e565b6001600160a01b03811660009081526002602052604090205460ff1615156001146106d35760405162461bcd60e51b815260206004820152602360248201527f537761703a20746865207369676e6572206973206e6f7420616e20617070726f6044820152623b32b960e91b606482015260840161049e565b6000828152600460205260408120805460ff191660011790555b8551811015610893576005600088838151811061070c5761070c6115ae565b60200260200101518152602001908152602001600020546000801b146107745760405162461bcd60e51b815260206004820152601c60248201527f537761703a207265717565737420616c72656164792065786973747300000000604482015260640161049e565b826005600089848151811061078b5761078b6115ae565b6020026020010151815260200190815260200160002081905550600360009054906101000a90046001600160a01b03166001600160a01b031663a9059cbb8783815181106107db576107db6115ae565b60200260200101518784815181106107f5576107f56115ae565b60200260200101516040518363ffffffff1660e01b815260040161082e9291906001600160a01b03929092168252602082015260400190565b602060405180830381600087803b15801561084857600080fd5b505af115801561085c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610880919061158c565b508061088b816115c4565b9150506106ed565b50856040516108a291906115ed565b604051908190038120907f796a6fb73c9c09afe863a5d1bc7040da846e5aeb2ad3cb42ee36e08a0c0a3e7190600090a2505050505050565b6003546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561091e57600080fd5b505afa158015610932573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109569190611623565b905090565b610963610d92565b6001600160a01b0381166109895760405162461bcd60e51b815260040161049e9061163c565b6001600160a01b03166000908152600160205260409020805460ff19169055565b6109b2610d92565b60005b815181101561043e576109e08282815181106109d3576109d36115ae565b6020026020010151610a9d565b806109ea816115c4565b9150506109b5565b6109fa610d92565b6001600160a01b038116610a205760405162461bcd60e51b815260040161049e90611684565b6001600160a01b03166000908152600260205260409020805460ff19169055565b610a49610d92565b610a536000610dec565b565b610a5d610d92565b60005b815181101561043e57610a8b828281518110610a7e57610a7e6115ae565b60200260200101516109f2565b80610a95816115c4565b915050610a60565b610aa5610d92565b6001600160a01b038116610acb5760405162461bcd60e51b815260040161049e90611684565b6001600160a01b03166000908152600260205260409020805460ff19166001179055565b610af7610d92565b60008111610b0757610b07611576565b6003546040516323b872dd60e01b8152336004820152306024820152604481018390526001600160a01b03909116906323b872dd906064016103ec565b610b4c610d92565b6001600160a01b038116610b725760405162461bcd60e51b815260040161049e9061163c565b6001600160a01b03166000908152600160208190526040909120805460ff19169091179055565b610ba1610d92565b6001600160a01b038116610c065760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161049e565b610c0f81610dec565b50565b610c1a610d92565b60005b815181101561043e57610c48828281518110610c3b57610c3b6115ae565b6020026020010151610b44565b80610c52816115c4565b915050610c1d565b610c62610d92565b60005b815181101561043e57610c90828281518110610c8357610c836115ae565b602002602001015161095b565b80610c9a816115c4565b915050610c65565b6000610d777f09b8a08b090eeab5363e11767a7aa5068ad8ad0003d8600d51b47998093fdae685604051602001610cd991906115ed565b6040516020818303038152906040528051906020012085604051602001610d0091906116ce565b6040516020818303038152906040528051906020012085604051602001610d2791906115ed565b60408051601f198184030181528282528051602091820120908301959095528101929092526060820152608081019190915260a00160405160208183030381529060405280519060200120610e3c565b949350505050565b6000610d8b8383610e90565b9392505050565b6000546001600160a01b03163314610a535760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161049e565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000610e8a610e49610eb4565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b92915050565b6000806000610e9f8585610fdb565b91509150610eac81611021565b509392505050565b6000306001600160a01b037f000000000000000000000000e503f9a8653cdeb807c41aeeaccb9c0de3c9aac116148015610f0d57507f000000000000000000000000000000000000000000000000000000000000000146145b15610f3757507f1d38bab1dd311b33a39c5d7e9f1b727d40bac3ce52b70173cf94c2edebd5ea1490565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527f1d6ce926126a7a404be012b8bac2f9eaa7e344eec3c8586dccda9cca6a5c0090828401527f88f72b566ae0c96f6fffac4bc8ac74909f61512ac0c06a8124d5ed420d306f9060608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6000808251604114156110125760208301516040840151606085015160001a6110068782858561116f565b9450945050505061101a565b506000905060025b9250929050565b600081600481111561103557611035611701565b141561103e5750565b600181600481111561105257611052611701565b14156110a05760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161049e565b60028160048111156110b4576110b4611701565b14156111025760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161049e565b600381600481111561111657611116611701565b1415610c0f5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b606482015260840161049e565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156111a6575060009050600361122a565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156111fa573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166112235760006001925092505061122a565b9150600090505b94509492505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561127257611272611233565b604052919050565b600067ffffffffffffffff82111561129457611294611233565b5060051b60200190565b600082601f8301126112af57600080fd5b813560206112c46112bf8361127a565b611249565b82815260059290921b840181019181810190868411156112e357600080fd5b8286015b848110156112fe57803583529183019183016112e7565b509695505050505050565b80356001600160a01b038116811461132057600080fd5b919050565b600082601f83011261133657600080fd5b813560206113466112bf8361127a565b82815260059290921b8401810191818101908684111561136557600080fd5b8286015b848110156112fe5761137a81611309565b8352918301918301611369565b6000806000806080858703121561139d57600080fd5b843567ffffffffffffffff808211156113b557600080fd5b6113c18883890161129e565b95506020915081870135818111156113d857600080fd5b6113e489828a01611325565b9550506040870135818111156113f957600080fd5b61140589828a0161129e565b94505060608701358181111561141a57600080fd5b8701601f8101891361142b57600080fd5b80358281111561143d5761143d611233565b61144f601f8201601f19168501611249565b9250808352898482840101111561146557600080fd5b808483018585013760008482850101525050809250505092959194509250565b60006020828403121561149757600080fd5b610d8b82611309565b6000602082840312156114b257600080fd5b813567ffffffffffffffff8111156114c957600080fd5b610d7784828501611325565b6000602082840312156114e757600080fd5b5035919050565b60008060006060848603121561150357600080fd5b833567ffffffffffffffff8082111561151b57600080fd5b6115278783880161129e565b9450602086013591508082111561153d57600080fd5b61154987838801611325565b9350604086013591508082111561155f57600080fd5b5061156c8682870161129e565b9150509250925092565b634e487b7160e01b600052600160045260246000fd5b60006020828403121561159e57600080fd5b81518015158114610d8b57600080fd5b634e487b7160e01b600052603260045260246000fd5b60006000198214156115e657634e487b7160e01b600052601160045260246000fd5b5060010190565b815160009082906020808601845b83811015611617578151855293820193908201906001016115fb565b50929695505050505050565b60006020828403121561163557600080fd5b5051919050565b60208082526028908201527f52656c617965723a207468652072656c6179657220697320746865207a65726f604082015267206164647265737360c01b606082015260800190565b6020808252602a908201527f417070726f7665723a2074686520617070726f76657220697320746865207a65604082015269726f206164647265737360b01b606082015260800190565b815160009082906020808601845b838110156116175781516001600160a01b0316855293820193908201906001016116dc565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220fc19831561e43f9280af332d707263d651bbd7a68eacb54e3b604e8f508eb26b64736f6c63430008090033

Verified Source Code Full Match

Compiler: v0.8.9+commit.e5eed63a EVM: london Optimization: Yes (200 runs)
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}
Swap.sol 226 lines
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";

abstract contract Relayer is Ownable {
  mapping(address => bool) private _relayers;

  function relayer(address _address) public view virtual returns (bool) {
    return _relayers[_address];
  }
  
  /**
   * @dev Throws if called by any account other than the relayer.
   */
  modifier onlyRelayer() {
    require(relayer(_msgSender()), "Relayer: caller is not the relayer");
    _;
  }

  /**
   * @dev Adds a relayer.
   */
  function addRelayer(address _address) public virtual onlyOwner {
    require(_address != address(0), "Relayer: the relayer is the zero address");   
    _relayers[_address] = true;
  }

  /**
   * @dev Adds one or more relayers.
   */
  function addRelayers(address[] memory _addresses) public virtual onlyOwner {
    for (uint256 i = 0; i < _addresses.length; i++) {
      addRelayer(_addresses[i]);
    }
  }

  /**
   * @dev Removes a relayer.
   */
  function removeRelayer(address _address) public virtual onlyOwner {
    require(_address != address(0), "Relayer: the relayer is the zero address");   
    _relayers[_address] = false;
  }

  /**
   * @dev Removes one or more approvers.
   */
  function removeRelayers(address[] memory _addresses) public virtual onlyOwner {
    for (uint256 i = 0; i < _addresses.length; i++) {
      removeRelayer(_addresses[i]);
    }
  }
}

abstract contract Approver is Ownable {
  mapping(address => bool) private _approvers;

  function approver(address _address) public view virtual returns (bool) {
    return _approvers[_address];
  }

  /**
   * @dev Adds an approver.
   */
  function addApprover(address _address) public virtual onlyOwner {
    require(_address != address(0), "Approver: the approver is the zero address");   
    _approvers[_address] = true;
  }

  /**
   * @dev Adds one or more approvers.
   */
  function addApprovers(address[] memory _addresses) public virtual onlyOwner {
    for (uint256 i = 0; i < _addresses.length; i++) {
      addApprover(_addresses[i]);
    }
  }

  /**
   * @dev Removes an approver.
   */
  function removeApprover(address _address) public virtual onlyOwner {
    require(_address != address(0), "Approver: the approver is the zero address");   
    _approvers[_address] = false;
  }

  /**
   * @dev Removes one or more approvers.
   */
  function removeApprovers(address[] memory _addresses) public virtual onlyOwner {
    for (uint256 i = 0; i < _addresses.length; i++) {
      removeApprover(_addresses[i]);
    }
  }
}

contract Swap is Relayer, Approver, EIP712 {
  using ECDSA for bytes32;

  IERC20 public token;
  mapping(bytes32 => bool) private _batches;
  mapping(uint256 => bytes32) private _requests;
  
  constructor(address _token, address _relayer, address _approver) EIP712("ShareRingSwap", "2.0") {
    require(_token != address(0), "Swap: the token is the zero address");
    token = IERC20(_token);
    require(token.balanceOf(address(this)) == 0, "Swap: the token must be an ERC20 contract");
    addRelayer(_relayer);
    addApprover(_approver);
  }

  event SwapCompleted(uint256[] indexed ids);

  /**
   * @dev Returns the token balance of the contract.
   */
  function tokensAvailable() public view returns (uint256) {
    return token.balanceOf(address(this));
  }

  /**
   * @dev Withdraws all remaining balance to owner's account.
   *
   * Currently it transfers ALL balance.
   * TBC: support partial withdraw?
   */
  function withdraw() public onlyOwner {
    uint256 balance = tokensAvailable();
    assert(balance > 0);
    token.transfer(owner(), balance);
  }

  /**
   * @dev Deposits token into the contract address.
   *
   * There are two options for transferring tokens into the contract:
   * - By transfer from address to contract address
   * - By approve allowance for this contract to transfer with this function 
   *
   * NOTE: The function only works when the allowance is approved.
   */
  function deposit(uint256 _amount) public onlyOwner {
    assert(_amount > 0);
    token.transferFrom(msg.sender, address(this), _amount);
  }

  /**
   * @dev Get a specified batch.
   */
  function batch(bytes32 _digest) external view returns (bool) {
    return _batches[_digest];
  }

  /**
   * @dev Get a specified request.
   */
  function request(uint256 _id) external view returns (bytes32) {
    return _requests[_id];
  }

  /**
   * @dev Returns the digest.
   *
   * NOTE: This function does not actually do any state change.
   *       It is just there for generating the approval digest.
   *
   * TBC: make it internal
   */
  function digest(uint256[] memory _ids, address[] memory _tos, uint256[] memory _amounts) public view returns(bytes32) {
    return _hashTypedDataV4(
      keccak256(
        abi.encode(
          keccak256("Swap(uint256[] ids,address[] tos,uint256[] amounts)"),
          keccak256(abi.encodePacked(_ids)),
          keccak256(abi.encodePacked(_tos)),
          keccak256(abi.encodePacked(_amounts))
        )
      )
    );
  }

  /**
   * @dev Returns the signer's address if signature is valid, otherwise a strange address (or 0x0).
   *
   * NOTE: This function does not actually do any state change.
   *       It is just there for verifying the approval signature.
   *
   * TBC: make it internal
   */
  function verify(uint256[] memory _ids, address[] memory _tos, uint256[] memory _amounts, bytes memory signature) public view returns(address) {
    bytes32 hash = digest(_ids, _tos, _amounts);
    return verify(hash, signature);
  }

  function verify(bytes32 _digest, bytes memory signature) internal pure returns(address) {
    return _digest.recover(signature);
  }

  /**
   * @dev Proceeds the swaps and transfer tokens.
   */
  function swap(uint256[] memory _ids, address[] memory _tos, uint256[] memory _amounts, bytes memory _signature) public onlyRelayer {
    // 1. validate inputs
    require(_ids.length > 0 && _tos.length > 0 && _amounts.length > 0, "Swap: one or more inputs are empty");
    require(_tos.length == _amounts.length && _ids.length == _tos.length, "Swap: the input lengths do not match");
    bytes32 _digest = digest(_ids, _tos, _amounts);
    require(_batches[_digest] == false, "Swap: batch already exists");
    // 2. validate signature
    address signer = verify(_digest, _signature);
    require(signer != address(0), "ECDSA: signature is not valid");
    require(approver(signer) == true, "Swap: the signer is not an approver");
    _batches[_digest] = true;
    // 3. proceed with sending tokens
    for (uint256 i = 0; i < _tos.length; i++) {
      // additional check if request already proceeded
      require(_requests[_ids[i]] == 0, "Swap: request already exists");
      _requests[_ids[i]] = _digest;
      token.transfer(_tos[i], _amounts[i]);
    }
    emit SwapCompleted(_ids);
  }
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}
ECDSA.sol 213 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV // Deprecated in v4.8
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}
EIP712.sol 104 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;
    address private immutable _CACHED_THIS;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;

    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _CACHED_THIS = address(this);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

Read Contract

approver 0x3f131d9f → bool
batch 0xfddaa065 → bool
digest 0xf6708f96 → bytes32
owner 0x8da5cb5b → address
relayer 0xc9b5ef8e → bool
request 0xd845a4b3 → bytes32
token 0xfc0c546a → address
tokensAvailable 0x60659a92 → uint256
verify 0x1d3d89b6 → address

Write Contract 13 functions

These functions modify contract state and require a wallet transaction to execute.

addApprover 0xb646c194
address _address
addApprovers 0x6a882d51
address[] _addresses
addRelayer 0xdd39f00d
address _address
addRelayers 0xf4cb33cc
address[] _addresses
deposit 0xb6b55f25
uint256 _amount
removeApprover 0x6cf4c88f
address _address
removeApprovers 0x7569d66f
address[] _addresses
removeRelayer 0x60f0a5ac
address _address
removeRelayers 0xf5e90f94
address[] _addresses
renounceOwnership 0x715018a6
No parameters
swap 0x58d937ce
uint256[] _ids
address[] _tos
uint256[] _amounts
bytes _signature
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x3ccfd60b
No parameters

Recent Transactions

No transactions found for this address