Address

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/UnusPay.sol": {
      "content": "// Dependency file: C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\utils\Context.sol\r
\r
// SPDX-License-Identifier: MIT\r
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\r
\r
// pragma solidity ^0.8.0;\r
\r
/**\r
 * @dev Provides information about the current execution context, including the\r
 * sender of the transaction and its data. While these are generally available\r
 * via msg.sender and msg.data, they should not be accessed in such a direct\r
 * manner, since when dealing with meta-transactions the account sending and\r
 * paying for execution may not be the actual sender (as far as an application\r
 * is concerned).\r
 *\r
 * This contract is only required for intermediate, library-like contracts.\r
 */\r
abstract contract Context {\r
    function _msgSender() internal view virtual returns (address) {\r
        return msg.sender;\r
    }\r
\r
    function _msgData() internal view virtual returns (bytes calldata) {\r
        return msg.data;\r
    }\r
}\r
\r
\r
// Dependency file: C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\access\Ownable.sol\r
\r
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\r
\r
// pragma solidity ^0.8.0;\r
\r
// import "C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\utils\Context.sol";\r
\r
/**\r
 * @dev Contract module which provides a basic access control mechanism, where\r
 * there is an account (an owner) that can be granted exclusive access to\r
 * specific functions.\r
 *\r
 * By default, the owner account will be the one that deploys the contract. This\r
 * can later be changed with {transferOwnership}.\r
 *\r
 * This module is used through inheritance. It will make available the modifier\r
 * `onlyOwner`, which can be applied to your functions to restrict their use to\r
 * the owner.\r
 */\r
abstract contract Ownable is Context {\r
    address private _owner;\r
\r
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r
\r
    /**\r
     * @dev Initializes the contract setting the deployer as the initial owner.\r
     */\r
    constructor() {\r
        _transferOwnership(_msgSender());\r
    }\r
\r
    /**\r
     * @dev Throws if called by any account other than the owner.\r
     */\r
    modifier onlyOwner() {\r
        _checkOwner();\r
        _;\r
    }\r
\r
    /**\r
     * @dev Returns the address of the current owner.\r
     */\r
    function owner() public view virtual returns (address) {\r
        return _owner;\r
    }\r
\r
    /**\r
     * @dev Throws if the sender is not the owner.\r
     */\r
    function _checkOwner() internal view virtual {\r
        require(owner() == _msgSender(), "Ownable: caller is not the owner");\r
    }\r
\r
    /**\r
     * @dev Leaves the contract without owner. It will not be possible to call\r
     * `onlyOwner` functions. Can only be called by the current owner.\r
     *\r
     * NOTE: Renouncing ownership will leave the contract without an owner,\r
     * thereby disabling any functionality that is only available to the owner.\r
     */\r
    function renounceOwnership() public virtual onlyOwner {\r
        _transferOwnership(address(0));\r
    }\r
\r
    /**\r
     * @dev Transfers ownership of the contract to a new account (`newOwner`).\r
     * Can only be called by the current owner.\r
     */\r
    function transferOwnership(address newOwner) public virtual onlyOwner {\r
        require(newOwner != address(0), "Ownable: new owner is the zero address");\r
        _transferOwnership(newOwner);\r
    }\r
\r
    /**\r
     * @dev Transfers ownership of the contract to a new account (`newOwner`).\r
     * Internal function without access restriction.\r
     */\r
    function _transferOwnership(address newOwner) internal virtual {\r
        address oldOwner = _owner;\r
        _owner = newOwner;\r
        emit OwnershipTransferred(oldOwner, newOwner);\r
    }\r
}\r
\r
\r
// Dependency file: C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\access\Ownable2Step.sol\r
\r
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\r
\r
// pragma solidity ^0.8.0;\r
\r
// import "C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\access\Ownable.sol";\r
\r
/**\r
 * @dev Contract module which provides access control mechanism, where\r
 * there is an account (an owner) that can be granted exclusive access to\r
 * specific functions.\r
 *\r
 * By default, the owner account will be the one that deploys the contract. This\r
 * can later be changed with {transferOwnership} and {acceptOwnership}.\r
 *\r
 * This module is used through inheritance. It will make available all functions\r
 * from parent (Ownable).\r
 */\r
abstract contract Ownable2Step is Ownable {\r
    address private _pendingOwner;\r
\r
    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\r
\r
    /**\r
     * @dev Returns the address of the pending owner.\r
     */\r
    function pendingOwner() public view virtual returns (address) {\r
        return _pendingOwner;\r
    }\r
\r
    /**\r
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\r
     * Can only be called by the current owner.\r
     */\r
    function transferOwnership(address newOwner) public virtual override onlyOwner {\r
        _pendingOwner = newOwner;\r
        emit OwnershipTransferStarted(owner(), newOwner);\r
    }\r
\r
    /**\r
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\r
     * Internal function without access restriction.\r
     */\r
    function _transferOwnership(address newOwner) internal virtual override {\r
        delete _pendingOwner;\r
        super._transferOwnership(newOwner);\r
    }\r
\r
    /**\r
     * @dev The new owner accepts the ownership transfer.\r
     */\r
    function acceptOwnership() public virtual {\r
        address sender = _msgSender();\r
        require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");\r
        _transferOwnership(sender);\r
    }\r
}\r
\r
\r
// Dependency file: C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\	oken\ERC20\IERC20.sol\r
\r
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\r
\r
// pragma solidity ^0.8.0;\r
\r
/**\r
 * @dev Interface of the ERC20 standard as defined in the EIP.\r
 */\r
interface IERC20 {\r
    /**\r
     * @dev Emitted when `value` tokens are moved from one account (`from`) to\r
     * another (`to`).\r
     *\r
     * Note that `value` may be zero.\r
     */\r
    event Transfer(address indexed from, address indexed to, uint256 value);\r
\r
    /**\r
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\r
     * a call to {approve}. `value` is the new allowance.\r
     */\r
    event Approval(address indexed owner, address indexed spender, uint256 value);\r
\r
    /**\r
     * @dev Returns the amount of tokens in existence.\r
     */\r
    function totalSupply() external view returns (uint256);\r
\r
    /**\r
     * @dev Returns the amount of tokens owned by `account`.\r
     */\r
    function balanceOf(address account) external view returns (uint256);\r
\r
    /**\r
     * @dev Moves `amount` tokens from the caller's account to `to`.\r
     *\r
     * Returns a boolean value indicating whether the operation succeeded.\r
     *\r
     * Emits a {Transfer} event.\r
     */\r
    function transfer(address to, uint256 amount) external returns (bool);\r
\r
    /**\r
     * @dev Returns the remaining number of tokens that `spender` will be\r
     * allowed to spend on behalf of `owner` through {transferFrom}. This is\r
     * zero by default.\r
     *\r
     * This value changes when {approve} or {transferFrom} are called.\r
     */\r
    function allowance(address owner, address spender) external view returns (uint256);\r
\r
    /**\r
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\r
     *\r
     * Returns a boolean value indicating whether the operation succeeded.\r
     *\r
     * IMPORTANT: Beware that changing an allowance with this method brings the risk\r
     * that someone may use both the old and the new allowance by unfortunate\r
     * transaction ordering. One possible solution to mitigate this race\r
     * condition is to first reduce the spender's allowance to 0 and set the\r
     * desired value afterwards:\r
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\r
     *\r
     * Emits an {Approval} event.\r
     */\r
    function approve(address spender, uint256 amount) external returns (bool);\r
\r
    /**\r
     * @dev Moves `amount` tokens from `from` to `to` using the\r
     * allowance mechanism. `amount` is then deducted from the caller's\r
     * allowance.\r
     *\r
     * Returns a boolean value indicating whether the operation succeeded.\r
     *\r
     * Emits a {Transfer} event.\r
     */\r
    function transferFrom(address from, address to, uint256 amount) external returns (bool);\r
}\r
\r
\r
// Dependency file: C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\	oken\ERC20\extensions\IERC20Permit.sol\r
\r
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)\r
\r
// pragma solidity ^0.8.0;\r
\r
/**\r
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\r
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\r
 *\r
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\r
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\r
 * need to send a transaction, and thus is not required to hold Ether at all.\r
 */\r
interface IERC20Permit {\r
    /**\r
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\r
     * given ``owner``'s signed approval.\r
     *\r
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\r
     * ordering also apply here.\r
     *\r
     * Emits an {Approval} event.\r
     *\r
     * Requirements:\r
     *\r
     * - `spender` cannot be the zero address.\r
     * - `deadline` must be a timestamp in the future.\r
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\r
     * over the EIP712-formatted function arguments.\r
     * - the signature must use ``owner``'s current nonce (see {nonces}).\r
     *\r
     * For more information on the signature format, see the\r
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\r
     * section].\r
     */\r
    function permit(\r
        address owner,\r
        address spender,\r
        uint256 value,\r
        uint256 deadline,\r
        uint8 v,\r
        bytes32 r,\r
        bytes32 s\r
    ) external;\r
\r
    /**\r
     * @dev Returns the current nonce for `owner`. This value must be\r
     * included whenever a signature is generated for {permit}.\r
     *\r
     * Every successful call to {permit} increases ``owner``'s nonce by one. This\r
     * prevents a signature from being used multiple times.\r
     */\r
    function nonces(address owner) external view returns (uint256);\r
\r
    /**\r
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\r
     */\r
    // solhint-disable-next-line func-name-mixedcase\r
    function DOMAIN_SEPARATOR() external view returns (bytes32);\r
}\r
\r
\r
// Dependency file: C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\utils\Address.sol\r
\r
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\r
\r
// pragma solidity ^0.8.1;\r
\r
/**\r
 * @dev Collection of functions related to the address type\r
 */\r
library Address {\r
    /**\r
     * @dev Returns true if `account` is a contract.\r
     *\r
     * [IMPORTANT]\r
     * ====\r
     * It is unsafe to assume that an address for which this function returns\r
     * false is an externally-owned account (EOA) and not a contract.\r
     *\r
     * Among others, `isContract` will return false for the following\r
     * types of addresses:\r
     *\r
     *  - an externally-owned account\r
     *  - a contract in construction\r
     *  - an address where a contract will be created\r
     *  - an address where a contract lived, but was destroyed\r
     *\r
     * Furthermore, `isContract` will also return true if the target contract within\r
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\r
     * which only has an effect at the end of a transaction.\r
     * ====\r
     *\r
     * [IMPORTANT]\r
     * ====\r
     * You shouldn't rely on `isContract` to protect against flash loan attacks!\r
     *\r
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\r
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\r
     * constructor.\r
     * ====\r
     */\r
    function isContract(address account) internal view returns (bool) {\r
        // This method relies on extcodesize/address.code.length, which returns 0\r
        // for contracts in construction, since the code is only stored at the end\r
        // of the constructor execution.\r
\r
        return account.code.length > 0;\r
    }\r
\r
    /**\r
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r
     * `recipient`, forwarding all available gas and reverting on errors.\r
     *\r
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r
     * of certain opcodes, possibly making contracts go over the 2300 gas limit\r
     * imposed by `transfer`, making them unable to receive funds via\r
     * `transfer`. {sendValue} removes this limitation.\r
     *\r
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r
     *\r
     * IMPORTANT: because control is transferred to `recipient`, care must be\r
     * taken to not create reentrancy vulnerabilities. Consider using\r
     * {ReentrancyGuard} or the\r
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r
     */\r
    function sendValue(address payable recipient, uint256 amount) internal {\r
        require(address(this).balance >= amount, "Address: insufficient balance");\r
\r
        (bool success, ) = recipient.call{value: amount}("");\r
        require(success, "Address: unable to send value, recipient may have reverted");\r
    }\r
\r
    /**\r
     * @dev Performs a Solidity function call using a low level `call`. A\r
     * plain `call` is an unsafe replacement for a function call: use this\r
     * function instead.\r
     *\r
     * If `target` reverts with a revert reason, it is bubbled up by this\r
     * function (like regular Solidity function calls).\r
     *\r
     * Returns the raw returned data. To convert to the expected return value,\r
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r
     *\r
     * Requirements:\r
     *\r
     * - `target` must be a contract.\r
     * - calling `target` with `data` must not revert.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r
     * `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, 0, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but also transferring `value` wei to `target`.\r
     *\r
     * Requirements:\r
     *\r
     * - the calling contract must have an ETH balance of at least `value`.\r
     * - the called Solidity function must be `payable`.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r
     * with `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(\r
        address target,\r
        bytes memory data,\r
        uint256 value,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        require(address(this).balance >= value, "Address: insufficient balance for call");\r
        (bool success, bytes memory returndata) = target.call{value: value}(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but performing a static call.\r
     *\r
     * _Available since v3.3._\r
     */\r
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\r
        return functionStaticCall(target, data, "Address: low-level static call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
     * but performing a static call.\r
     *\r
     * _Available since v3.3._\r
     */\r
    function functionStaticCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal view returns (bytes memory) {\r
        (bool success, bytes memory returndata) = target.staticcall(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but performing a delegate call.\r
     *\r
     * _Available since v3.4._\r
     */\r
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\r
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
     * but performing a delegate call.\r
     *\r
     * _Available since v3.4._\r
     */\r
    function functionDelegateCall(\r
        address target,\r
        bytes memory data,\r
        string memory errorMessage\r
    ) internal returns (bytes memory) {\r
        (bool success, bytes memory returndata) = target.delegatecall(data);\r
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\r
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\r
     *\r
     * _Available since v4.8._\r
     */\r
    function verifyCallResultFromTarget(\r
        address target,\r
        bool success,\r
        bytes memory returndata,\r
        string memory errorMessage\r
    ) internal view returns (bytes memory) {\r
        if (success) {\r
            if (returndata.length == 0) {\r
                // only check isContract if the call was successful and the return data is empty\r
                // otherwise we already know that it was a contract\r
                require(isContract(target), "Address: call to non-contract");\r
            }\r
            return returndata;\r
        } else {\r
            _revert(returndata, errorMessage);\r
        }\r
    }\r
\r
    /**\r
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\r
     * revert reason or using the provided one.\r
     *\r
     * _Available since v4.3._\r
     */\r
    function verifyCallResult(\r
        bool success,\r
        bytes memory returndata,\r
        string memory errorMessage\r
    ) internal pure returns (bytes memory) {\r
        if (success) {\r
            return returndata;\r
        } else {\r
            _revert(returndata, errorMessage);\r
        }\r
    }\r
\r
    function _revert(bytes memory returndata, string memory errorMessage) private pure {\r
        // Look for revert reason and bubble it up if present\r
        if (returndata.length > 0) {\r
            // The easiest way to bubble the revert reason is using memory via assembly\r
            /// @solidity memory-safe-assembly\r
            assembly {\r
                let returndata_size := mload(returndata)\r
                revert(add(32, returndata), returndata_size)\r
            }\r
        } else {\r
            revert(errorMessage);\r
        }\r
    }\r
}\r
\r
\r
// Dependency file: C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\	oken\ERC20\utils\SafeERC20.sol\r
\r
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)\r
\r
// pragma solidity ^0.8.0;\r
\r
// import "C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\	oken\ERC20\IERC20.sol";\r
// import "C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\	oken\ERC20\extensions\IERC20Permit.sol";\r
// import "C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\utils\Address.sol";\r
\r
/**\r
 * @title SafeERC20\r
 * @dev Wrappers around ERC20 operations that throw on failure (when the token\r
 * contract returns false). Tokens that return no value (and instead revert or\r
 * throw on failure) are also supported, non-reverting calls are assumed to be\r
 * successful.\r
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\r
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\r
 */\r
library SafeERC20 {\r
    using Address for address;\r
\r
    /**\r
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\r
     * non-reverting calls are assumed to be successful.\r
     */\r
    function safeTransfer(IERC20 token, address to, uint256 value) internal {\r
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\r
    }\r
\r
    /**\r
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\r
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\r
     */\r
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\r
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\r
    }\r
\r
    /**\r
     * @dev Deprecated. This function has issues similar to the ones found in\r
     * {IERC20-approve}, and its usage is discouraged.\r
     *\r
     * Whenever possible, use {safeIncreaseAllowance} and\r
     * {safeDecreaseAllowance} instead.\r
     */\r
    function safeApprove(IERC20 token, address spender, uint256 value) internal {\r
        // safeApprove should only be called when setting an initial allowance,\r
        // or when resetting it to zero. To increase and decrease it, use\r
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\r
        require(\r
            (value == 0) || (token.allowance(address(this), spender) == 0),\r
            "SafeERC20: approve from non-zero to non-zero allowance"\r
        );\r
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\r
    }\r
\r
    /**\r
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\r
     * non-reverting calls are assumed to be successful.\r
     */\r
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\r
        uint256 oldAllowance = token.allowance(address(this), spender);\r
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));\r
    }\r
\r
    /**\r
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\r
     * non-reverting calls are assumed to be successful.\r
     */\r
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\r
        unchecked {\r
            uint256 oldAllowance = token.allowance(address(this), spender);\r
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");\r
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));\r
        }\r
    }\r
\r
    /**\r
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\r
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\r
     * to be set to zero before setting it to a non-zero value, such as USDT.\r
     */\r
    function forceApprove(IERC20 token, address spender, uint256 value) internal {\r
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);\r
\r
        if (!_callOptionalReturnBool(token, approvalCall)) {\r
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\r
            _callOptionalReturn(token, approvalCall);\r
        }\r
    }\r
\r
    /**\r
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.\r
     * Revert on invalid signature.\r
     */\r
    function safePermit(\r
        IERC20Permit token,\r
        address owner,\r
        address spender,\r
        uint256 value,\r
        uint256 deadline,\r
        uint8 v,\r
        bytes32 r,\r
        bytes32 s\r
    ) internal {\r
        uint256 nonceBefore = token.nonces(owner);\r
        token.permit(owner, spender, value, deadline, v, r, s);\r
        uint256 nonceAfter = token.nonces(owner);\r
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");\r
    }\r
\r
    /**\r
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\r
     * on the return value: the return value is optional (but if data is returned, it must not be false).\r
     * @param token The token targeted by the call.\r
     * @param data The call data (encoded using abi.encode or one of its variants).\r
     */\r
    function _callOptionalReturn(IERC20 token, bytes memory data) private {\r
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\r
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\r
        // the target address contains contract code and also asserts for success in the low-level call.\r
\r
        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");\r
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");\r
    }\r
\r
    /**\r
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\r
     * on the return value: the return value is optional (but if data is returned, it must not be false).\r
     * @param token The token targeted by the call.\r
     * @param data The call data (encoded using abi.encode or one of its variants).\r
     *\r
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\r
     */\r
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\r
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\r
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false\r
        // and not revert is the subcall reverts.\r
\r
        (bool success, bytes memory returndata) = address(token).call(data);\r
        return\r
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));\r
    }\r
}\r
\r
\r
// Dependency file: contracts\interfaces\IUnusPay.sol\r
\r
// pragma solidity 0.8.28;\r
\r
interface IUnusPay {\r
  error PaymentTimeout();\r
  error WrongNativeAmountIn();\r
  error InvalidPlan();\r
  error NotSubscribed();\r
  error NotTimeYet();\r
  error WrongNextPayTime();\r
  error ExchangeDisabled();\r
  error InvalidExchangeData();\r
  error ExchangeCallFailed();\r
  error NativePayFailed();\r
  error InvalidToAddress();\r
  error InsufficientBalanceAfterPay(address token);\r
  error WrongNativeCount();\r
\r
  struct From {\r
    uint8 exchangeType;\r
    address tokenAddress;\r
    address toTokenAddress;\r
    address exchangeAddress;\r
    uint256 amount;\r
    bytes exchangeData;\r
  }\r
\r
  struct To {\r
    address tokenAddress;\r
    uint256 amount;\r
    uint256 feeAmount;\r
  }\r
\r
  struct PayData {\r
    address toAddress;\r
    address feeAddress;\r
    uint256 deadline;\r
    From[] fromTokens;\r
    To[] toTokens;\r
  }\r
\r
  function pay(PayData calldata payData) external payable returns (bool);\r
\r
  function exchangeToken(IUnusPay.From[] calldata fromTokens) external payable returns (bool);\r
\r
/*   event exchangeStatus(address indexed exchange, bool status);\r
\r
  function toggleExchange(address exchange, bool status) external returns (bool);\r
\r
  function withdraw(address[] calldata tokens, uint amount) external returns (bool); */\r
}\r
\r
\r
// Root file: contracts\UnusPay.sol\r
\r
pragma solidity 0.8.28;\r
\r
// import 'C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\access\Ownable2Step.sol';\r
// import 'C:\Users\xiecan\dev\depay\unuspay-evm-router\
ode_modules\@openzeppelin\contracts\	oken\ERC20\utils\SafeERC20.sol';\r
// import 'contracts\interfaces\IUnusPay.sol';\r
\r
contract UnusPay is Ownable2Step {\r
  using SafeERC20 for IERC20;\r
\r
  address private constant NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\r
\r
  mapping(address => bool) public exchanges;\r
\r
  constructor() {}\r
\r
  receive() external payable {}\r
\r
  event Payment(\r
    address indexed from,\r
    address indexed to,\r
    address token,\r
    uint256 value,\r
    address feeAddress,\r
    uint256 fee\r
  );\r
\r
  event exchangeStatus(address indexed exchange, bool status);\r
\r
  function pay(IUnusPay.PayData calldata payData) external payable returns (bool) {\r
    if (payData.deadline < block.timestamp) {\r
      revert IUnusPay.PaymentTimeout();\r
    }\r
    return _pay(payData);\r
  }\r
  function exchangeToken(IUnusPay.From[] calldata payData) external payable {\r
    _exchangeToken(payData);\r
  }\r
\r
  function _pay(IUnusPay.PayData calldata payData) internal returns (bool) {\r
    uint256[] memory originBalanceIn = new uint256[](payData.fromTokens.length);\r
    uint256[] memory originBalanceOut = new uint256[](payData.toTokens.length);\r
    _getOriginBalanceIn(payData, originBalanceIn);\r
    _getOriginBalanceOut(payData, originBalanceOut);\r
    _payIn(payData);\r
    _executePay(payData);\r
    _validateBalanceAfterPay(payData, originBalanceIn, originBalanceOut);\r
    return true;\r
  }\r
\r
  function _getOriginBalanceIn(IUnusPay.PayData calldata payData, uint256[] memory originBalanceIn) internal {\r
    bool HAS_NATIVE;\r
    for (uint i = 0; i < payData.fromTokens.length; i++) {\r
      IUnusPay.From memory fromToken = payData.fromTokens[i];\r
      if (fromToken.tokenAddress == NATIVE) {\r
        if (!HAS_NATIVE) {\r
          HAS_NATIVE = true;\r
        } else {\r
          revert IUnusPay.WrongNativeCount();\r
        }\r
        originBalanceIn[i] = address(this).balance - msg.value;\r
      } else {\r
        originBalanceIn[i] = IERC20(fromToken.tokenAddress).balanceOf(address(this));\r
      }\r
    }\r
  }\r
\r
  function _getOriginBalanceOut(IUnusPay.PayData calldata payData, uint256[] memory originBalanceOut) internal {\r
    bool HAS_NATIVE;\r
    for (uint i = 0; i < payData.toTokens.length; i++) {\r
      IUnusPay.To memory toToken = payData.toTokens[i];\r
      if (toToken.tokenAddress == NATIVE) {\r
        if (!HAS_NATIVE) {\r
          HAS_NATIVE = true;\r
        } else {\r
          revert IUnusPay.WrongNativeCount();\r
        }\r
        originBalanceOut[i] = address(this).balance - msg.value;\r
      } else {\r
        originBalanceOut[i] = IERC20(toToken.tokenAddress).balanceOf(address(this));\r
      }\r
    }\r
  }\r
\r
  function _payIn(IUnusPay.PayData calldata payData) internal {\r
    for (uint i = 0; i < payData.fromTokens.length; i++) {\r
      IUnusPay.From memory fromToken = payData.fromTokens[i];\r
      if (fromToken.tokenAddress == NATIVE) {\r
        if (msg.value != fromToken.amount) {\r
          revert IUnusPay.WrongNativeAmountIn();\r
        }\r
      } else {\r
        IERC20(fromToken.tokenAddress).safeTransferFrom(msg.sender, address(this), fromToken.amount);\r
      }\r
    }\r
  }\r
\r
  function _executePay(IUnusPay.PayData calldata payData) internal {\r
    _exchangeToken(payData.fromTokens);\r
    if (payData.feeAddress != address(0)) {\r
      _payOutWithFee(payData);\r
    } else {\r
      _payOut(payData);\r
    }\r
  }\r
\r
  function _validateBalanceAfterPay(\r
    IUnusPay.PayData calldata payData,\r
    uint256[] memory originBalanceIn,\r
    uint256[] memory originBalanceOut\r
  ) internal view {\r
    for (uint i = 0; i < payData.fromTokens.length; i++) {\r
      IUnusPay.From memory fromToken = payData.fromTokens[i];\r
      uint256 balance = originBalanceIn[i];\r
      if (fromToken.tokenAddress == NATIVE) {\r
        if (address(this).balance < balance) {\r
          revert IUnusPay.InsufficientBalanceAfterPay(NATIVE);\r
        }\r
      } else {\r
        if (IERC20(fromToken.tokenAddress).balanceOf(address(this)) < balance) {\r
          revert IUnusPay.InsufficientBalanceAfterPay(fromToken.tokenAddress);\r
        }\r
      }\r
    }\r
    for (uint i = 0; i < payData.toTokens.length; i++) {\r
      IUnusPay.To memory toToken = payData.toTokens[i];\r
      uint256 balance = originBalanceOut[i];\r
      if (toToken.tokenAddress == NATIVE) {\r
        if (address(this).balance < balance) {\r
          revert IUnusPay.InsufficientBalanceAfterPay(NATIVE);\r
        }\r
      } else {\r
        if (IERC20(toToken.tokenAddress).balanceOf(address(this)) < balance) {\r
          revert IUnusPay.InsufficientBalanceAfterPay(toToken.tokenAddress);\r
        }\r
      }\r
    }\r
  }\r
\r
  function _exchangeToken(IUnusPay.From[] calldata fromTokens) internal {\r
    for (uint i = 0; i < fromTokens.length; i++) {\r
      IUnusPay.From memory fromToken = fromTokens[i];\r
      if (fromToken.exchangeAddress != address(0)) {\r
        if (!exchanges[fromToken.exchangeAddress]) {\r
          revert IUnusPay.ExchangeDisabled();\r
        }\r
        bool success;\r
        if (fromToken.tokenAddress == NATIVE) {\r
          if (fromToken.exchangeData.length == 0) {\r
            revert IUnusPay.InvalidExchangeData();\r
          }\r
          (success, ) = fromToken.exchangeAddress.call{value: msg.value}(fromToken.exchangeData);\r
        } else {\r
          if (fromToken.exchangeType == 1) {\r
            // pull\r
            IERC20(fromToken.tokenAddress).safeApprove(fromToken.exchangeAddress, fromToken.amount);\r
          } else if (fromToken.exchangeType == 2) {\r
            // push\r
            IERC20(fromToken.tokenAddress).safeTransfer(fromToken.exchangeAddress, fromToken.amount);\r
          }\r
          (success, ) = fromToken.exchangeAddress.call(fromToken.exchangeData);\r
          if (fromToken.exchangeType == 1) {\r
            // pull\r
            IERC20(fromToken.tokenAddress).safeApprove(fromToken.exchangeAddress, 0);\r
          }\r
        }\r
        if (!success) {\r
          revert IUnusPay.ExchangeCallFailed();\r
        }\r
      }\r
    }\r
  }\r
\r
  function _payOut(IUnusPay.PayData calldata payData) internal {\r
    for (uint i = 0; i < payData.toTokens.length; i++) {\r
      IUnusPay.To memory toToken = payData.toTokens[i];\r
      if (toToken.tokenAddress == NATIVE) {\r
        if (payData.toAddress == address(0)) {\r
          revert IUnusPay.InvalidToAddress();\r
        }\r
        (bool success, ) = payData.toAddress.call{value: toToken.amount}(new bytes(0));\r
        if (!success) {\r
          revert IUnusPay.NativePayFailed();\r
        }\r
      } else {\r
        IERC20(toToken.tokenAddress).safeTransfer(payData.toAddress, toToken.amount);\r
      }\r
      emit Payment(msg.sender, payData.toAddress, toToken.tokenAddress, toToken.amount, address(0), 0);\r
    }\r
  }\r
  function _payOutWithFee(IUnusPay.PayData calldata payData) internal {\r
    for (uint i = 0; i < payData.toTokens.length; i++) {\r
      IUnusPay.To memory toToken = payData.toTokens[i];\r
      if (toToken.tokenAddress == NATIVE) {\r
        if (payData.toAddress == address(0)) {\r
          revert IUnusPay.InvalidToAddress();\r
        }\r
        (bool success, ) = payData.toAddress.call{value: toToken.amount}(new bytes(0));\r
        if (!success) {\r
          revert IUnusPay.NativePayFailed();\r
        }\r
        (bool feeSuccess, ) = payData.feeAddress.call{value: toToken.feeAmount}(new bytes(0));\r
        if (!feeSuccess) {\r
          revert IUnusPay.NativePayFailed();\r
        }\r
      } else {\r
        IERC20(toToken.tokenAddress).safeTransfer(payData.toAddress, toToken.amount);\r
        IERC20(toToken.tokenAddress).safeTransfer(payData.feeAddress, toToken.feeAmount);\r
      }\r
      emit Payment(\r
        msg.sender,\r
        payData.toAddress,\r
        toToken.tokenAddress,\r
        toToken.amount,\r
        payData.feeAddress,\r
        toToken.feeAmount\r
      );\r
    }\r
  }\r
\r
  function toggleExchange(address exchange, bool status) external onlyOwner returns (bool) {\r
    exchanges[exchange] = status;\r
    emit exchangeStatus(exchange, status);\r
    return true;\r
  }\r
\r
  function withdraw(address[] calldata tokens, uint amount) external onlyOwner returns (bool) {\r
    for (uint i = 0; i < tokens.length; i++) {\r
      if (tokens[i] == NATIVE) {\r
        (bool success, ) = address(msg.sender).call{value: amount}(new bytes(0));\r
        require(success, 'withdraw failed!');\r
      } else {\r
        IERC20(tokens[i]).safeTransfer(msg.sender, amount);\r
      }\r
    }\r
    return true;\r
  }\r
}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": false,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": [],
    "evmVersion": "cancun"
  }
}}

Tags:
ERC20, Multisig, Upgradeable, Multi-Signature, Factory|addr:0x33aa3250bc09c672fb507fe2c6a04118cb9b6a1a|verified:true|block:23738733|tx:0xbf8db48debe5793d368c06dcff93fd37ce4bed2a72f72db0cdee9c1b772f505a|first_check:1762427708

Submitted on: 2025-11-06 12:15:08

Comments

Log in to comment.

No comments yet.