S Price: $0.455512 (+0.99%)

Contract

0xC75C1b7e061e703D4c7dB531B8451B85509af12d

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
OrderbookImplementation

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 15 : OrderbookImplementation.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./interface/IGateway.sol";
import "./OrderbookStorage.sol";
import './interface/IDToken.sol';
import './library/SafeMath.sol';
import "./library/ETHAndERC20.sol";
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';

contract OrderbookImplementation is OrderbookStorage, IERC721Receiver {
    using SafeMath for int256;
    using SafeMath for uint256;
    using ETHAndERC20 for address;

    error InsufficientExecutionFee();
    error InsufficientBAmount();
    error NonExistedOrder();
    error ExecutorOnly();
    error NotOrderOwner();

    address constant tokenETH = address(1);
    IDToken internal immutable pToken;
    IGateway internal immutable gateway;

    event CreateOrder(
        uint256 indexed orderIndex,
        bool isLite,
        address account,
        uint256 pTokenId,
        bytes32 symbolId,
        address bToken,
        int256 bAmount,
        int256[] orderParams,
        int256[] tradeParams,
        uint256 executionFee
    );
    event ExecuteOrder(
        uint256 indexed orderIndex,
        bool isLite,
        address account,
        uint256 pTokenId,
        bytes32 symbolId,
        address bToken,
        int256 bAmount,
        int256[] orderParams,
        int256[] tradeParams,
        uint256 executionFee
    );
    event CancelOrder(
        uint256 indexed orderIndex,
        bool isLite,
        address account,
        uint256 pTokenId,
        bytes32 symbolId,
        address bToken,
        int256 bAmount,
        int256[] orderParams,
        int256[] tradeParams
    );

    constructor (
        address pToken_,
        address gateway_
    ) {
        pToken = IDToken(pToken_);
        gateway = IGateway(gateway_);
    }

    function setExecutor(address executor_) external _onlyAdmin_ {
        executor = executor_;
    }

    function approveBToken(address bToken) external _onlyAdmin_ {
        bToken.approveMax(address(gateway));
    }

    function createOrder(Order calldata order) external payable {
        uint256[] memory fees = gateway.getExecutionFees();
        uint256 executionFee;
        if (order.isLite && order.bAmount < 0) {
            executionFee = fees[4];
        } else {
            executionFee = fees[3];
        }
        if (msg.value < executionFee) {
            revert InsufficientExecutionFee();
        }
        if (order.bToken == tokenETH && order.bAmount > 0) {
            if (msg.value < executionFee + order.bAmount.itou()) {
                revert InsufficientBAmount();
            }
        } else if (order.bAmount > 0) {
            order.bToken.transferIn(msg.sender, order.bAmount.itou());
        }
        

        uint256 orderIndex = ++ordersIndex[order.account];
        orders[order.account][orderIndex] = order;
        executionFees[order.account][orderIndex] = executionFee;
    
        emit CreateOrder(
            orderIndex,
            order.isLite,
            order.account,
            order.pTokenId,
            order.symbolId,
            order.bToken,
            order.bAmount,
            order.orderParams,
            order.tradeParams,
            executionFee
            );
    }


    function executeOrder(address account, uint256 orderIndex) external payable {
        if (msg.sender != executor) {
            revert ExecutorOnly();
        }
        Order memory order = orders[account][orderIndex];
        if (order.account == address(0)) {
            revert NonExistedOrder();
        }

        uint256[] memory fees = gateway.getExecutionFees();
        uint256 executionFee;
        if (order.isLite && order.bAmount < 0) {
            executionFee = fees[4];
        } else {
            executionFee = fees[3];
        }

        if (order.isLite) { // lite mode
            if (order.bAmount > 0) {
                if (order.pTokenId != 0) {
                    pToken.safeTransferFrom(order.account, address(this), order.pTokenId);
                }
                uint256 pTokenId = gateway.requestAddMargin{value: order.bToken == tokenETH? order.bAmount.itou() : 0}(
                    order.pTokenId,
                    order.bToken,
                    order.bAmount.itou(),
                    true
                );
                gateway.requestTrade{value: executionFee}(pTokenId, order.symbolId, order.tradeParams);
                pToken.safeTransferFrom(address(this), order.account, pTokenId);
            } else {
                pToken.safeTransferFrom(order.account, address(this), order.pTokenId);
                gateway.requestTradeAndRemoveMargin{value: executionFee}(
                    order.pTokenId,
                    order.bToken,
                    (-order.bAmount).itou(),
                    order.symbolId,
                    order.tradeParams
                );
                pToken.safeTransferFrom(address(this), order.account, order.pTokenId);
            }
        } else { // pro mode
            pToken.safeTransferFrom(order.account, address(this), order.pTokenId);
            gateway.requestTrade{value: executionFee}(
                order.pTokenId,
                order.symbolId,
                order.tradeParams
                );
            pToken.safeTransferFrom(address(this), order.account, order.pTokenId);
        }

        delete orders[account][orderIndex];
        emit ExecuteOrder(
            orderIndex,
            order.isLite,
            order.account,
            order.pTokenId,
            order.symbolId,
            order.bToken,
            order.bAmount,
            order.orderParams,
            order.tradeParams,
            executionFee
            );
    }


    function cancelOrder(address account, uint256 orderIndex) external _reentryLock_ {
        if (msg.sender != account) {
            revert NotOrderOwner();
        }
        Order memory order = orders[account][orderIndex];
        if (order.account == address(0)) {
            revert NonExistedOrder();
        }

        uint256 executionFee = executionFees[order.account][orderIndex];
        if (order.bAmount > 0 && order.bToken == tokenETH) {
            tokenETH.transferOut(account, order.bAmount.itou() + executionFee);
        } else if (order.bAmount > 0) {
            order.bToken.transferOut(account, order.bAmount.itou());
            tokenETH.transferOut(account, executionFee);
        } else {
            tokenETH.transferOut(account, executionFee);
        }

        delete orders[account][orderIndex];
        emit CancelOrder(
            orderIndex,
            order.isLite,
            order.account,
            order.pTokenId,
            order.symbolId,
            order.bToken,
            order.bAmount,
            order.orderParams,
            order.tradeParams
            );
    }

    function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external view returns (bytes4) {
        return IERC721Receiver.onERC721Received.selector;
    }

}

File 2 of 15 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 3 of 15 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 4 of 15 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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);
}

File 5 of 15 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 6 of 15 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 7 of 15 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 8 of 15 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 9 of 15 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 10 of 15 : IDToken.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import '@openzeppelin/contracts/token/ERC721/IERC721.sol';

interface IDToken is IERC721 {

    function ownerOf(uint256) external view returns (address);

    function totalMinted() external view returns (uint160);

    function mint(address owner) external returns (uint256 tokenId);

    function burn(uint256 tokenId) external;

}

File 11 of 15 : IGateway.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

interface IGateway {

    struct GatewayParam {
        address lToken;
        address pToken;
        address oracle;
        address swapper;
        address vault0;
        address iou;
        address tokenB0;
        address dChainEventSigner;
        uint256 b0ReserveRatio;
        int256  liquidationRewardCutRatio;
        int256  minLiquidationReward;
        int256  maxLiquidationReward;
    }

    struct GatewayState {
        int256  cumulativePnlOnGateway;
        uint256 liquidityTime;
        uint256 totalLiquidity;
        int256  cumulativeTimePerLiquidity;
        uint256 gatewayRequestId;
        uint256 dChainExecutionFeePerRequest;
        uint256 totalIChainExecutionFee;
    }

    struct BTokenState {
        address vault;
        bytes32 oracleId;
        uint256 collateralFactor;
    }

    struct LpState {
        uint256 requestId;
        address bToken;
        uint256 bAmount;
        int256  b0Amount;
        int256  lastCumulativePnlOnEngine;
        uint256 liquidity;
        uint256 cumulativeTime;
        uint256 lastCumulativeTimePerLiquidity;
        uint256 lastRequestIChainExecutionFee;
        uint256 cumulativeUnusedIChainExecutionFee;
    }

    struct TdState {
        uint256 requestId;
        address bToken;
        uint256 bAmount;
        int256  b0Amount;
        int256  lastCumulativePnlOnEngine;
        bool    singlePosition;
        uint256 lastRequestIChainExecutionFee;
        uint256 cumulativeUnusedIChainExecutionFee;
    }

    struct VarOnExecuteUpdateLiquidity {
        uint256 requestId;
        uint256 lTokenId;
        uint256 liquidity;
        uint256 totalLiquidity;
        int256  cumulativePnlOnEngine;
        uint256 bAmountToRemove;
    }

    struct VarOnExecuteRemoveMargin {
        uint256 requestId;
        uint256 pTokenId;
        uint256 requiredMargin;
        int256  cumulativePnlOnEngine;
        uint256 bAmountToRemove;
    }

    struct VarOnExecuteLiquidate {
        uint256 requestId;
        uint256 pTokenId;
        int256  cumulativePnlOnEngine;
    }

    function getGatewayState() external view returns (GatewayState memory s);

    function getBTokenState(address bToken) external view returns (BTokenState memory s);

    function getLpState(uint256 lTokenId) external view returns (LpState memory s);

    function getTdState(uint256 pTokenId) external view returns (TdState memory s);

    function getExecutionFees() external view returns (uint256[] memory fees);

    function requestTrade(uint256 pTokenId, bytes32 symbolId, int256[] calldata tradeParams) external payable;

    function requestAddMarginAndTrade(
        uint256 pTokenId,
        address bToken,
        uint256 bAmount,
        bytes32 symbolId,
        int256[] calldata tradeParams,
        bool singlePosition
    ) external payable;

    function requestTradeAndRemoveMargin(
        uint256 pTokenId,
        address bToken,
        uint256 bAmount,
        bytes32 symbolId,
        int256[] calldata tradeParams
    ) external payable;


    function requestAddMargin(uint256 pTokenId, address bToken, uint256 bAmount, bool singlePosition) external payable returns (uint256);


}

File 12 of 15 : ETHAndERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

/// Library for operating ERC20 and ETH in one logic
/// ETH is represented by address: 0x0000000000000000000000000000000000000001

library ETHAndERC20 {

    using SafeERC20 for IERC20;

    error SendEthFail();
    error WrongTokenInAmount();
    error WrongTokenOutAmount();

    function decimals(address token) internal view returns (uint8) {
        return token == address(1) ? 18 : IERC20Metadata(token).decimals();
    }

    // @notice Get the balance of ERC20 tokens or Ether held by this contract
    function balanceOfThis(address token) internal view returns (uint256) {
        return token == address(1)
            ? address(this).balance
            : IERC20(token).balanceOf(address(this));
    }

    function approveMax(address token, address spender) internal {
        if (token != address(1)) {
            uint256 allowance = IERC20(token).allowance(address(this), spender);
            if (allowance != type(uint256).max) {
                if (allowance != 0) {
                    IERC20(token).safeApprove(spender, 0);
                }
                IERC20(token).safeApprove(spender, type(uint256).max);
            }
        }
    }

    function unapprove(address token, address spender) internal {
        if (token != address(1)) {
            uint256 allowance = IERC20(token).allowance(address(this), spender);
            if (allowance != 0) {
                IERC20(token).safeApprove(spender, 0);
            }
        }
    }

    // @notice Transfer ERC20 tokens or Ether from 'from' to this contract
    function transferIn(address token, address from, uint256 amount) internal {
        if (token == address(1)) {
            if (amount != msg.value) {
                revert WrongTokenInAmount();
            }
        } else {
            uint256 balance1 = balanceOfThis(token);
            IERC20(token).safeTransferFrom(from, address(this), amount);
            uint256 balance2 = balanceOfThis(token);
            if (balance2 != balance1 + amount) {
                revert WrongTokenInAmount();
            }
        }
    }

    // @notice Transfer ERC20 tokens or Ether from this contract to 'to'
    function transferOut(address token, address to, uint256 amount) internal {
        uint256 balance1 = balanceOfThis(token);
        if (token == address(1)) {
            (bool success, ) = payable(to).call{value: amount}('');
            if (!success) {
                revert SendEthFail();
            }
        } else {
            IERC20(token).safeTransfer(to, amount);
        }
        uint256 balance2 = balanceOfThis(token);
        if (balance1 != balance2 + amount) {
            revert WrongTokenOutAmount();
        }
    }

}

File 13 of 15 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

library SafeMath {

    error UtoIOverflow(uint256);
    error IToUOverflow(int256);
    error AbsOverflow(int256);

    uint256 constant IMAX = 2**255 - 1;
    int256  constant IMIN = -2**255;

    function utoi(uint256 a) internal pure returns (int256) {
        if (a > IMAX) {
            revert UtoIOverflow(a);
        }
        return int256(a);
    }

    function itou(int256 a) internal pure returns (uint256) {
        if (a < 0) {
            revert IToUOverflow(a);
        }
        return uint256(a);
    }

    function abs(int256 a) internal pure returns (int256) {
        if (a == IMIN) {
            revert AbsOverflow(a);
        }
        return a >= 0 ? a : -a;
    }

    function add(uint256 a, int256 b) internal pure returns (uint256) {
        if (b >= 0) {
            return a + uint256(b);
        } else {
            return a - uint256(-b);
        }
    }

    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    function max(int256 a, int256 b) internal pure returns (int256) {
        return a >= b ? a : b;
    }

    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a <= b ? a : b;
    }

    function min(int256 a, int256 b) internal pure returns (int256) {
        return a <= b ? a : b;
    }

    function divRoundingUp(uint256 a, uint256 b) internal pure returns (uint256 c) {
        c = a / b;
        if (b * c != a) {
            c += 1;
        }
    }

    // @notice Rescale a uint256 value from a base of 10^decimals1 to 10^decimals2
    function rescale(uint256 value, uint256 decimals1, uint256 decimals2) internal pure returns (uint256) {
        return decimals1 == decimals2 ? value : value * 10**decimals2 / 10**decimals1;
    }

    // @notice Rescale value with rounding down
    function rescaleDown(uint256 value, uint256 decimals1, uint256 decimals2) internal pure returns (uint256) {
        return rescale(value, decimals1, decimals2);
    }

    // @notice Rescale value with rounding up
    function rescaleUp(uint256 value, uint256 decimals1, uint256 decimals2) internal pure returns (uint256) {
        uint256 rescaled = rescale(value, decimals1, decimals2);
        if (rescale(rescaled, decimals2, decimals1) != value) {
            rescaled += 1;
        }
        return rescaled;
    }

    function rescale(int256 value, uint256 decimals1, uint256 decimals2) internal pure returns (int256) {
        return decimals1 == decimals2 ? value : value * int256(10**decimals2) / int256(10**decimals1);
    }

    function rescaleDown(int256 value, uint256 decimals1, uint256 decimals2) internal pure returns (int256) {
        int256 rescaled = rescale(value, decimals1, decimals2);
        if (value < 0 && rescale(rescaled, decimals2, decimals1) != value) {
            rescaled -= 1;
        }
        return rescaled;
    }

    function rescaleUp(int256 value, uint256 decimals1, uint256 decimals2) internal pure returns (int256) {
        int256 rescaled = rescale(value, decimals1, decimals2);
        if (value > 0 && rescale(rescaled, decimals2, decimals1) != value) {
            rescaled += 1;
        }
        return rescaled;
    }

    // @notice Calculate a + b with overflow allowed
    function addUnchecked(int256 a, int256 b) internal pure returns (int256 c) {
        unchecked { c = a + b; }
    }

    // @notice Calculate a - b with overflow allowed
    function minusUnchecked(int256 a, int256 b) internal pure returns (int256 c) {
        unchecked { c = a - b; }
    }

}

File 14 of 15 : OrderbookStorage.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./utils/Admin.sol";

abstract contract OrderbookStorage is Admin {
    address public implementation;

    bool internal _mutex;

    modifier _reentryLock_() {
        require(!_mutex, "Router: reentry");
        _mutex = true;
        _;
        _mutex = false;
    }

    address public executor;
    
    struct Order {
        bool isLite;
        address account;
        uint256 pTokenId;
        bytes32 symbolId;
        address bToken;
        int256 bAmount;
        int256[] orderParams; // 0:trigerPrice, 1:isAboveTrigerPrice, 2: isIndexPrice
        int256[] tradeParams; // 0:volume, 1: priceLimit
    }

    // account -> index -> Order
	mapping (address => mapping(uint256 => Order)) public orders;
    // account -> index -> executionFee
    mapping (address => mapping(uint256 => uint256)) public executionFees;
    mapping (address => uint256) public ordersIndex;

}

File 15 of 15 : Admin.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

abstract contract Admin {

    error OnlyAdmin();

    event NewAdmin(address newAdmin);

    address public admin;

    modifier _onlyAdmin_() {
        if (msg.sender != admin) {
            revert OnlyAdmin();
        }
        _;
    }

    constructor () {
        admin = msg.sender;
        emit NewAdmin(admin);
    }

    /**
     * @notice Set a new admin for the contract.
     * @dev This function allows the current admin to assign a new admin address without performing any explicit verification.
     *      It's the current admin's responsibility to ensure that the 'newAdmin' address is correct and secure.
     * @param newAdmin The address of the new admin.
     */
    function setAdmin(address newAdmin) external _onlyAdmin_ {
        admin = newAdmin;
        emit NewAdmin(newAdmin);
    }

}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"pToken_","type":"address"},{"internalType":"address","name":"gateway_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ExecutorOnly","type":"error"},{"inputs":[{"internalType":"int256","name":"","type":"int256"}],"name":"IToUOverflow","type":"error"},{"inputs":[],"name":"InsufficientBAmount","type":"error"},{"inputs":[],"name":"InsufficientExecutionFee","type":"error"},{"inputs":[],"name":"NonExistedOrder","type":"error"},{"inputs":[],"name":"NotOrderOwner","type":"error"},{"inputs":[],"name":"OnlyAdmin","type":"error"},{"inputs":[],"name":"SendEthFail","type":"error"},{"inputs":[],"name":"WrongTokenInAmount","type":"error"},{"inputs":[],"name":"WrongTokenOutAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"orderIndex","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isLite","type":"bool"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"pTokenId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"symbolId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"bToken","type":"address"},{"indexed":false,"internalType":"int256","name":"bAmount","type":"int256"},{"indexed":false,"internalType":"int256[]","name":"orderParams","type":"int256[]"},{"indexed":false,"internalType":"int256[]","name":"tradeParams","type":"int256[]"}],"name":"CancelOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"orderIndex","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isLite","type":"bool"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"pTokenId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"symbolId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"bToken","type":"address"},{"indexed":false,"internalType":"int256","name":"bAmount","type":"int256"},{"indexed":false,"internalType":"int256[]","name":"orderParams","type":"int256[]"},{"indexed":false,"internalType":"int256[]","name":"tradeParams","type":"int256[]"},{"indexed":false,"internalType":"uint256","name":"executionFee","type":"uint256"}],"name":"CreateOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"orderIndex","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isLite","type":"bool"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"pTokenId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"symbolId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"bToken","type":"address"},{"indexed":false,"internalType":"int256","name":"bAmount","type":"int256"},{"indexed":false,"internalType":"int256[]","name":"orderParams","type":"int256[]"},{"indexed":false,"internalType":"int256[]","name":"tradeParams","type":"int256[]"},{"indexed":false,"internalType":"uint256","name":"executionFee","type":"uint256"}],"name":"ExecuteOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"NewAdmin","type":"event"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"bToken","type":"address"}],"name":"approveBToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"orderIndex","type":"uint256"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"isLite","type":"bool"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pTokenId","type":"uint256"},{"internalType":"bytes32","name":"symbolId","type":"bytes32"},{"internalType":"address","name":"bToken","type":"address"},{"internalType":"int256","name":"bAmount","type":"int256"},{"internalType":"int256[]","name":"orderParams","type":"int256[]"},{"internalType":"int256[]","name":"tradeParams","type":"int256[]"}],"internalType":"struct OrderbookStorage.Order","name":"order","type":"tuple"}],"name":"createOrder","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"orderIndex","type":"uint256"}],"name":"executeOrder","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"executionFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"executor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"orders","outputs":[{"internalType":"bool","name":"isLite","type":"bool"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pTokenId","type":"uint256"},{"internalType":"bytes32","name":"symbolId","type":"bytes32"},{"internalType":"address","name":"bToken","type":"address"},{"internalType":"int256","name":"bAmount","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"ordersIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"executor_","type":"address"}],"name":"setExecutor","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60c06040523480156200001157600080fd5b506040516200249d3803806200249d8339810160408190526200003491620000b1565b600080546001600160a01b031916339081179091556040519081527f71614071b88dee5e0b2ae578a9dd7b2ebbe9ae832ba419dc0242cd065a290b6c9060200160405180910390a16001600160a01b039182166080521660a052620000e9565b80516001600160a01b0381168114620000ac57600080fd5b919050565b60008060408385031215620000c557600080fd5b620000d08362000094565b9150620000e06020840162000094565b90509250929050565b60805160a0516123416200015c6000396000818161039a01528181610af801528181610c9301528181610e2101528181610f19015281816110b8015261127a015260008181610db401528181610fbc0152818161104e0152818161117a01528181611210015261131f01526123416000f3fe6080604052600436106100c25760003560e01c80636a2061371161007f578063bc3c782d11610059578063bc3c782d146102d6578063c34c08e5146102f6578063dc3528d614610316578063f851a4401461032957600080fd5b80636a206137146101f1578063704b6c0214610211578063793b8c6d1461023157600080fd5b80630a5cfdf1146100c7578063150b7a02146101125780631c3c0ea8146101575780632895e23f146101795780635b8d97751461018c5780635c60da1b146101b9575b600080fd5b3480156100d357600080fd5b506100ff6100e2366004611baf565b600460209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b34801561011e57600080fd5b5061013e61012d366004611bdb565b630a85bd0160e11b95945050505050565b6040516001600160e01b03199091168152602001610109565b34801561016357600080fd5b50610177610172366004611c7a565b610349565b005b610177610187366004611c9e565b610396565b34801561019857600080fd5b506100ff6101a7366004611c7a565b60056020526000908152604090205481565b3480156101c557600080fd5b506001546101d9906001600160a01b031681565b6040516001600160a01b039091168152602001610109565b3480156101fd57600080fd5b5061017761020c366004611baf565b6106bd565b34801561021d57600080fd5b5061017761022c366004611c7a565b610a3f565b34801561023d57600080fd5b5061029a61024c366004611baf565b600360208181526000938452604080852090915291835291208054600182015460028301549383015460049093015460ff8316946001600160a01b0361010090940484169492939092169086565b6040805196151587526001600160a01b0395861660208801528601939093526060850191909152909116608083015260a082015260c001610109565b3480156102e257600080fd5b506101776102f1366004611c7a565b610abe565b34801561030257600080fd5b506002546101d9906001600160a01b031681565b610177610324366004611baf565b610b1f565b34801561033557600080fd5b506000546101d9906001600160a01b031681565b6000546001600160a01b0316331461037457604051634755657960e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e926bc9d6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156103f6573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261041e9190810190611cf0565b9050600061042f6020840184611dbc565b801561043f575060008360a00135125b15610466578160048151811061045757610457611dd9565b60200260200101519050610484565b8160038151811061047957610479611dd9565b602002602001015190505b803410156104a557604051639413602360e01b815260040160405180910390fd5b60016104b760a0850160808601611c7a565b6001600160a01b03161480156104d1575060008360a00135135b15610512576104e38360a00135611474565b6104ed9082611e05565b34101561050d5760405163ef71d09160e01b815260040160405180910390fd5b610550565b60008360a00135131561055057610550336105308560a00135611474565b61054060a0870160808801611c7a565b6001600160a01b0316919061149e565b60006005816105656040870160208801611c7a565b6001600160a01b03166001600160a01b031681526020019081526020016000206000815461059290611e18565b9182905550905083600360006105ae6040840160208501611c7a565b6001600160a01b031681526020808201929092526040908101600090812085825290925290206105de8282611f28565b50829050600460006105f66040880160208901611c7a565b6001600160a01b03168152602080820192909252604090810160009081208582528352209190915581907f5249cb945bff4620fe48667c10e907c054f6ac72472924aac434b671d570db289061064e90870187611dbc565b61065e6040880160208901611c7a565b6040880135606089013561067860a08b0160808c01611c7a565b60a08b013561068a60c08d018d611e3e565b61069760e08f018f611e3e565b8d6040516106af9b9a9998979695949392919061203a565b60405180910390a250505050565b600154600160a01b900460ff161561070e5760405162461bcd60e51b815260206004820152600f60248201526e526f757465723a207265656e74727960881b60448201526064015b60405180910390fd5b6001805460ff60a01b1916600160a01b179055336001600160a01b0383161461074a57604051637b2095ad60e11b815260040160405180910390fd5b6001600160a01b038083166000908152600360208181526040808420868552825280842081516101008082018452825460ff8116151583520487168185015260018201548184015260028201546060820152938101549095166080840152600485015460a08401526005850180548251818502810185019093528083529495939460c08601938301828280156107ff57602002820191906000526020600020905b8154815260200190600101908083116107eb575b505050505081526020016006820180548060200260200160405190810160405280929190818152602001828054801561085757602002820191906000526020600020905b815481526020019060010190808311610843575b5050509190925250505060208101519091506001600160a01b031661088f5760405163319ca3c560e01b815260040160405180910390fd5b6020808201516001600160a01b031660009081526004825260408082208583529092529081205460a083015190911280156108d7575060808201516001600160a01b03166001145b156109065761090184826108ee8560a00151611474565b6108f89190611e05565b60019190611534565b610951565b60008260a00151131561094557610939846109248460a00151611474565b60808501516001600160a01b03169190611534565b61090160018583611534565b61095160018583611534565b6001600160a01b0384166000908152600360208181526040808420878552909152822080546001600160a81b0319168155600181018390556002810183905590810180546001600160a01b031916905560048101829055906109b66005830182611b6c565b6109c4600683016000611b6c565b5050827f968e14396d626913d1539a04838910a8d02042a9ad2c800b6f37752b65acf6b4836000015184602001518560400151866060015187608001518860a001518960c001518a60e00151604051610a249897969594939291906120e4565b60405180910390a250506001805460ff60a01b191690555050565b6000546001600160a01b03163314610a6a57604051634755657960e01b815260040160405180910390fd5b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527f71614071b88dee5e0b2ae578a9dd7b2ebbe9ae832ba419dc0242cd065a290b6c9060200160405180910390a150565b6000546001600160a01b03163314610ae957604051634755657960e01b815260040160405180910390fd5b610b1c6001600160a01b0382167f0000000000000000000000000000000000000000000000000000000000000000611617565b50565b6002546001600160a01b03163314610b4a5760405163605551bd60e11b815260040160405180910390fd5b6001600160a01b038083166000908152600360208181526040808420868552825280842081516101008082018452825460ff8116151583520487168185015260018201548184015260028201546060820152938101549095166080840152600485015460a08401526005850180548251818502810185019093528083529495939460c0860193830182828015610bff57602002820191906000526020600020905b815481526020019060010190808311610beb575b5050505050815260200160068201805480602002602001604051908101604052809291908181526020018280548015610c5757602002820191906000526020600020905b815481526020019060010190808311610c43575b5050509190925250505060208101519091506001600160a01b0316610c8f5760405163319ca3c560e01b815260040160405180910390fd5b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e926bc9d6040518163ffffffff1660e01b8152600401600060405180830381865afa158015610cef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d179190810190611cf0565b9050600082600001518015610d30575060008360a00151125b15610d575781600481518110610d4857610d48611dd9565b60200260200101519050610d75565b81600381518110610d6a57610d6a611dd9565b602002602001015190505b8251156111ef5760008360a00151131561102d57604083015115610e1d5760208301516040808501519051632142170760e11b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926342842e0e92610dea92309190600401612151565b600060405180830381600087803b158015610e0457600080fd5b505af1158015610e18573d6000803e3d6000fd5b505050505b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637e9459ba60016001600160a01b031686608001516001600160a01b031614610e73576000610e80565b610e808660a00151611474565b86604001518760800151610e978960a00151611474565b6040516001600160e01b031960e087901b16815260048101939093526001600160a01b03909116602483015260448201526001606482015260840160206040518083038185885af1158015610ef0573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f159190612175565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fa321c26838387606001518860e001516040518563ffffffff1660e01b8152600401610f709392919061218e565b6000604051808303818588803b158015610f8957600080fd5b505af1158015610f9d573d6000803e3d6000fd5b5050506020860151604051632142170760e11b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001693506342842e0e9250610ff59130918690600401612151565b600060405180830381600087803b15801561100f57600080fd5b505af1158015611023573d6000803e3d6000fd5b5050505050611390565b60208301516040808501519051632142170760e11b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926342842e0e9261108492309190600401612151565b600060405180830381600087803b15801561109e57600080fd5b505af11580156110b2573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e1faff5682856040015186608001516111068860a00151611101906121b6565b611474565b88606001518960e001516040518763ffffffff1660e01b81526004016111309594939291906121d2565b6000604051808303818588803b15801561114957600080fd5b505af115801561115d573d6000803e3d6000fd5b5050505060208401516040808601519051632142170760e11b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031693506342842e0e926111b8923092600401612151565b600060405180830381600087803b1580156111d257600080fd5b505af11580156111e6573d6000803e3d6000fd5b50505050611390565b60208301516040808501519051632142170760e11b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926342842e0e9261124692309190600401612151565b600060405180830381600087803b15801561126057600080fd5b505af1158015611274573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fa321c2682856040015186606001518760e001516040518563ffffffff1660e01b81526004016112d59392919061218e565b6000604051808303818588803b1580156112ee57600080fd5b505af1158015611302573d6000803e3d6000fd5b5050505060208401516040808601519051632142170760e11b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031693506342842e0e9261135d923092600401612151565b600060405180830381600087803b15801561137757600080fd5b505af115801561138b573d6000803e3d6000fd5b505050505b6001600160a01b0385166000908152600360208181526040808420888552909152822080546001600160a81b0319168155600181018390556002810183905590810180546001600160a01b031916905560048101829055906113f56005830182611b6c565b611403600683016000611b6c565b5050837f9857d267bdf80f55c6be7439521cb7341d623e75fae1a179114d3af2db2afb6d846000015185602001518660400151876060015188608001518960a001518a60c001518b60e001518a60405161146599989796959493929190612205565b60405180910390a25050505050565b60008082121561149a57604051632a33bb3160e01b815260048101839052602401610705565b5090565b6000196001600160a01b038416016114d5573481146114d057604051630fc9bd0f60e11b815260040160405180910390fd5b505050565b60006114e0846116dc565b90506114f76001600160a01b038516843085611764565b6000611502856116dc565b905061150e8383611e05565b811461152d57604051630fc9bd0f60e11b815260040160405180910390fd5b5050505050565b600061153f846116dc565b90506000196001600160a01b038516016115cd576000836001600160a01b03168360405160006040518083038185875af1925050503d80600081146115a0576040519150601f19603f3d011682016040523d82523d6000602084013e6115a5565b606091505b50509050806115c75760405163e277d13760e01b815260040160405180910390fd5b506115e1565b6115e16001600160a01b03851684846117c2565b60006115ec856116dc565b90506115f88382611e05565b821461152d5760405163f4d4667360e01b815260040160405180910390fd5b6001600160a01b0382166001146116d857604051636eb1769f60e11b81523060048201526001600160a01b0382811660248301526000919084169063dd62ed3e90604401602060405180830381865afa158015611678573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169c9190612175565b905060001981146114d05780156116c2576116c26001600160a01b0384168360006117f2565b6114d06001600160a01b038416836000196117f2565b5050565b60006001600160a01b03821660011461175c576040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015611733573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117579190612175565b61175e565b475b92915050565b6117bc846323b872dd60e01b85858560405160240161178593929190612151565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611907565b50505050565b6040516001600160a01b0383166024820152604481018290526114d090849063a9059cbb60e01b90606401611785565b80158061186c5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015611846573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061186a9190612175565b155b6118d75760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610705565b6040516001600160a01b0383166024820152604481018290526114d090849063095ea7b360e01b90606401611785565b600061195c826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166119dc9092919063ffffffff16565b905080516000148061197d57508080602001905181019061197d919061227b565b6114d05760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610705565b60606119eb84846000856119f3565b949350505050565b606082471015611a545760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610705565b600080866001600160a01b03168587604051611a7091906122bc565b60006040518083038185875af1925050503d8060008114611aad576040519150601f19603f3d011682016040523d82523d6000602084013e611ab2565b606091505b5091509150611ac387838387611ace565b979650505050505050565b60608315611b3d578251600003611b36576001600160a01b0385163b611b365760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610705565b50816119eb565b6119eb8383815115611b525781518083602001fd5b8060405162461bcd60e51b815260040161070591906122d8565b5080546000825590600052602060002090810190610b1c91905b8082111561149a5760008155600101611b86565b6001600160a01b0381168114610b1c57600080fd5b60008060408385031215611bc257600080fd5b8235611bcd81611b9a565b946020939093013593505050565b600080600080600060808688031215611bf357600080fd5b8535611bfe81611b9a565b94506020860135611c0e81611b9a565b935060408601359250606086013567ffffffffffffffff80821115611c3257600080fd5b818801915088601f830112611c4657600080fd5b813581811115611c5557600080fd5b896020828501011115611c6757600080fd5b9699959850939650602001949392505050565b600060208284031215611c8c57600080fd5b8135611c9781611b9a565b9392505050565b600060208284031215611cb057600080fd5b813567ffffffffffffffff811115611cc757600080fd5b82016101008185031215611c9757600080fd5b634e487b7160e01b600052604160045260246000fd5b60006020808385031215611d0357600080fd5b825167ffffffffffffffff80821115611d1b57600080fd5b818501915085601f830112611d2f57600080fd5b815181811115611d4157611d41611cda565b8060051b604051601f19603f83011681018181108582111715611d6657611d66611cda565b604052918252848201925083810185019188831115611d8457600080fd5b938501935b82851015611da257845184529385019392850192611d89565b98975050505050505050565b8015158114610b1c57600080fd5b600060208284031215611dce57600080fd5b8135611c9781611dae565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8082018082111561175e5761175e611def565b600060018201611e2a57611e2a611def565b5060010190565b6000813561175e81611b9a565b6000808335601e19843603018112611e5557600080fd5b83018035915067ffffffffffffffff821115611e7057600080fd5b6020019150600581901b3603821315611e8857600080fd5b9250929050565b67ffffffffffffffff831115611ea757611ea7611cda565b68010000000000000000831115611ec057611ec0611cda565b805483825580841015611ef7576000828152602081208581019083015b80821015611ef357828255600182019150611edd565b5050505b5060008181526020812083915b85811015611f2057823582820155602090920191600101611f04565b505050505050565b8135611f3381611dae565b815490151560ff1660ff1991909116178155611f7a611f5460208401611e31565b828054610100600160a81b03191660089290921b610100600160a81b0316919091179055565b6040820135600182015560608201356002820155611fc1611f9d60808401611e31565b6003830180546001600160a01b0319166001600160a01b0392909216919091179055565b60a08201356004820155611fd860c0830183611e3e565b611fe6818360058601611e8f565b5050611ff560e0830183611e3e565b6117bc818360068601611e8f565b8183526000602080850194508260005b8581101561202f57813587529582019590820190600101612013565b509495945050505050565b8b151581526001600160a01b038b81166020830152604082018b9052606082018a90528816608082015260a0810187905261012060c08201819052600090612085838201888a612003565b905082810360e084015261209a818688612003565b915050826101008301529c9b505050505050505050505050565b600081518084526020808501945080840160005b8381101561202f578151875295820195908201906001016120c8565b88151581526001600160a01b03888116602083015260408201889052606082018790528516608082015260a0810184905261010060c0820181905260009061212e838201866120b4565b905082810360e084015261214281856120b4565b9b9a5050505050505050505050565b6001600160a01b039384168152919092166020820152604081019190915260600190565b60006020828403121561218757600080fd5b5051919050565b8381528260208201526060604082015260006121ad60608301846120b4565b95945050505050565b6000600160ff1b82016121cb576121cb611def565b5060000390565b85815260018060a01b038516602082015283604082015282606082015260a060808201526000611ac360a08301846120b4565b89151581526001600160a01b03898116602083015260408201899052606082018890528616608082015260a0810185905261012060c0820181905260009061224f838201876120b4565b905082810360e084015261226381866120b4565b915050826101008301529a9950505050505050505050565b60006020828403121561228d57600080fd5b8151611c9781611dae565b60005b838110156122b357818101518382015260200161229b565b50506000910152565b600082516122ce818460208701612298565b9190910192915050565b60208152600082518060208401526122f7816040850160208701612298565b601f01601f1916919091016040019291505056fea2646970667358221220d696ad5708d72ee9667b8585517585eb0a4a1cddee4e36a0611f4d5490b7abe064736f6c6343000814003300000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f82800000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d1

Deployed Bytecode

0x6080604052600436106100c25760003560e01c80636a2061371161007f578063bc3c782d11610059578063bc3c782d146102d6578063c34c08e5146102f6578063dc3528d614610316578063f851a4401461032957600080fd5b80636a206137146101f1578063704b6c0214610211578063793b8c6d1461023157600080fd5b80630a5cfdf1146100c7578063150b7a02146101125780631c3c0ea8146101575780632895e23f146101795780635b8d97751461018c5780635c60da1b146101b9575b600080fd5b3480156100d357600080fd5b506100ff6100e2366004611baf565b600460209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b34801561011e57600080fd5b5061013e61012d366004611bdb565b630a85bd0160e11b95945050505050565b6040516001600160e01b03199091168152602001610109565b34801561016357600080fd5b50610177610172366004611c7a565b610349565b005b610177610187366004611c9e565b610396565b34801561019857600080fd5b506100ff6101a7366004611c7a565b60056020526000908152604090205481565b3480156101c557600080fd5b506001546101d9906001600160a01b031681565b6040516001600160a01b039091168152602001610109565b3480156101fd57600080fd5b5061017761020c366004611baf565b6106bd565b34801561021d57600080fd5b5061017761022c366004611c7a565b610a3f565b34801561023d57600080fd5b5061029a61024c366004611baf565b600360208181526000938452604080852090915291835291208054600182015460028301549383015460049093015460ff8316946001600160a01b0361010090940484169492939092169086565b6040805196151587526001600160a01b0395861660208801528601939093526060850191909152909116608083015260a082015260c001610109565b3480156102e257600080fd5b506101776102f1366004611c7a565b610abe565b34801561030257600080fd5b506002546101d9906001600160a01b031681565b610177610324366004611baf565b610b1f565b34801561033557600080fd5b506000546101d9906001600160a01b031681565b6000546001600160a01b0316331461037457604051634755657960e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b60007f00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d16001600160a01b031663e926bc9d6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156103f6573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261041e9190810190611cf0565b9050600061042f6020840184611dbc565b801561043f575060008360a00135125b15610466578160048151811061045757610457611dd9565b60200260200101519050610484565b8160038151811061047957610479611dd9565b602002602001015190505b803410156104a557604051639413602360e01b815260040160405180910390fd5b60016104b760a0850160808601611c7a565b6001600160a01b03161480156104d1575060008360a00135135b15610512576104e38360a00135611474565b6104ed9082611e05565b34101561050d5760405163ef71d09160e01b815260040160405180910390fd5b610550565b60008360a00135131561055057610550336105308560a00135611474565b61054060a0870160808801611c7a565b6001600160a01b0316919061149e565b60006005816105656040870160208801611c7a565b6001600160a01b03166001600160a01b031681526020019081526020016000206000815461059290611e18565b9182905550905083600360006105ae6040840160208501611c7a565b6001600160a01b031681526020808201929092526040908101600090812085825290925290206105de8282611f28565b50829050600460006105f66040880160208901611c7a565b6001600160a01b03168152602080820192909252604090810160009081208582528352209190915581907f5249cb945bff4620fe48667c10e907c054f6ac72472924aac434b671d570db289061064e90870187611dbc565b61065e6040880160208901611c7a565b6040880135606089013561067860a08b0160808c01611c7a565b60a08b013561068a60c08d018d611e3e565b61069760e08f018f611e3e565b8d6040516106af9b9a9998979695949392919061203a565b60405180910390a250505050565b600154600160a01b900460ff161561070e5760405162461bcd60e51b815260206004820152600f60248201526e526f757465723a207265656e74727960881b60448201526064015b60405180910390fd5b6001805460ff60a01b1916600160a01b179055336001600160a01b0383161461074a57604051637b2095ad60e11b815260040160405180910390fd5b6001600160a01b038083166000908152600360208181526040808420868552825280842081516101008082018452825460ff8116151583520487168185015260018201548184015260028201546060820152938101549095166080840152600485015460a08401526005850180548251818502810185019093528083529495939460c08601938301828280156107ff57602002820191906000526020600020905b8154815260200190600101908083116107eb575b505050505081526020016006820180548060200260200160405190810160405280929190818152602001828054801561085757602002820191906000526020600020905b815481526020019060010190808311610843575b5050509190925250505060208101519091506001600160a01b031661088f5760405163319ca3c560e01b815260040160405180910390fd5b6020808201516001600160a01b031660009081526004825260408082208583529092529081205460a083015190911280156108d7575060808201516001600160a01b03166001145b156109065761090184826108ee8560a00151611474565b6108f89190611e05565b60019190611534565b610951565b60008260a00151131561094557610939846109248460a00151611474565b60808501516001600160a01b03169190611534565b61090160018583611534565b61095160018583611534565b6001600160a01b0384166000908152600360208181526040808420878552909152822080546001600160a81b0319168155600181018390556002810183905590810180546001600160a01b031916905560048101829055906109b66005830182611b6c565b6109c4600683016000611b6c565b5050827f968e14396d626913d1539a04838910a8d02042a9ad2c800b6f37752b65acf6b4836000015184602001518560400151866060015187608001518860a001518960c001518a60e00151604051610a249897969594939291906120e4565b60405180910390a250506001805460ff60a01b191690555050565b6000546001600160a01b03163314610a6a57604051634755657960e01b815260040160405180910390fd5b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527f71614071b88dee5e0b2ae578a9dd7b2ebbe9ae832ba419dc0242cd065a290b6c9060200160405180910390a150565b6000546001600160a01b03163314610ae957604051634755657960e01b815260040160405180910390fd5b610b1c6001600160a01b0382167f00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d1611617565b50565b6002546001600160a01b03163314610b4a5760405163605551bd60e11b815260040160405180910390fd5b6001600160a01b038083166000908152600360208181526040808420868552825280842081516101008082018452825460ff8116151583520487168185015260018201548184015260028201546060820152938101549095166080840152600485015460a08401526005850180548251818502810185019093528083529495939460c0860193830182828015610bff57602002820191906000526020600020905b815481526020019060010190808311610beb575b5050505050815260200160068201805480602002602001604051908101604052809291908181526020018280548015610c5757602002820191906000526020600020905b815481526020019060010190808311610c43575b5050509190925250505060208101519091506001600160a01b0316610c8f5760405163319ca3c560e01b815260040160405180910390fd5b60007f00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d16001600160a01b031663e926bc9d6040518163ffffffff1660e01b8152600401600060405180830381865afa158015610cef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d179190810190611cf0565b9050600082600001518015610d30575060008360a00151125b15610d575781600481518110610d4857610d48611dd9565b60200260200101519050610d75565b81600381518110610d6a57610d6a611dd9565b602002602001015190505b8251156111ef5760008360a00151131561102d57604083015115610e1d5760208301516040808501519051632142170760e11b81526001600160a01b037f00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f82816926342842e0e92610dea92309190600401612151565b600060405180830381600087803b158015610e0457600080fd5b505af1158015610e18573d6000803e3d6000fd5b505050505b60007f00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d16001600160a01b0316637e9459ba60016001600160a01b031686608001516001600160a01b031614610e73576000610e80565b610e808660a00151611474565b86604001518760800151610e978960a00151611474565b6040516001600160e01b031960e087901b16815260048101939093526001600160a01b03909116602483015260448201526001606482015260840160206040518083038185885af1158015610ef0573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f159190612175565b90507f00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d16001600160a01b031663fa321c26838387606001518860e001516040518563ffffffff1660e01b8152600401610f709392919061218e565b6000604051808303818588803b158015610f8957600080fd5b505af1158015610f9d573d6000803e3d6000fd5b5050506020860151604051632142170760e11b81526001600160a01b037f00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f8281693506342842e0e9250610ff59130918690600401612151565b600060405180830381600087803b15801561100f57600080fd5b505af1158015611023573d6000803e3d6000fd5b5050505050611390565b60208301516040808501519051632142170760e11b81526001600160a01b037f00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f82816926342842e0e9261108492309190600401612151565b600060405180830381600087803b15801561109e57600080fd5b505af11580156110b2573d6000803e3d6000fd5b505050507f00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d16001600160a01b031663e1faff5682856040015186608001516111068860a00151611101906121b6565b611474565b88606001518960e001516040518763ffffffff1660e01b81526004016111309594939291906121d2565b6000604051808303818588803b15801561114957600080fd5b505af115801561115d573d6000803e3d6000fd5b5050505060208401516040808601519051632142170760e11b81527f00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f8286001600160a01b031693506342842e0e926111b8923092600401612151565b600060405180830381600087803b1580156111d257600080fd5b505af11580156111e6573d6000803e3d6000fd5b50505050611390565b60208301516040808501519051632142170760e11b81526001600160a01b037f00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f82816926342842e0e9261124692309190600401612151565b600060405180830381600087803b15801561126057600080fd5b505af1158015611274573d6000803e3d6000fd5b505050507f00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d16001600160a01b031663fa321c2682856040015186606001518760e001516040518563ffffffff1660e01b81526004016112d59392919061218e565b6000604051808303818588803b1580156112ee57600080fd5b505af1158015611302573d6000803e3d6000fd5b5050505060208401516040808601519051632142170760e11b81527f00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f8286001600160a01b031693506342842e0e9261135d923092600401612151565b600060405180830381600087803b15801561137757600080fd5b505af115801561138b573d6000803e3d6000fd5b505050505b6001600160a01b0385166000908152600360208181526040808420888552909152822080546001600160a81b0319168155600181018390556002810183905590810180546001600160a01b031916905560048101829055906113f56005830182611b6c565b611403600683016000611b6c565b5050837f9857d267bdf80f55c6be7439521cb7341d623e75fae1a179114d3af2db2afb6d846000015185602001518660400151876060015188608001518960a001518a60c001518b60e001518a60405161146599989796959493929190612205565b60405180910390a25050505050565b60008082121561149a57604051632a33bb3160e01b815260048101839052602401610705565b5090565b6000196001600160a01b038416016114d5573481146114d057604051630fc9bd0f60e11b815260040160405180910390fd5b505050565b60006114e0846116dc565b90506114f76001600160a01b038516843085611764565b6000611502856116dc565b905061150e8383611e05565b811461152d57604051630fc9bd0f60e11b815260040160405180910390fd5b5050505050565b600061153f846116dc565b90506000196001600160a01b038516016115cd576000836001600160a01b03168360405160006040518083038185875af1925050503d80600081146115a0576040519150601f19603f3d011682016040523d82523d6000602084013e6115a5565b606091505b50509050806115c75760405163e277d13760e01b815260040160405180910390fd5b506115e1565b6115e16001600160a01b03851684846117c2565b60006115ec856116dc565b90506115f88382611e05565b821461152d5760405163f4d4667360e01b815260040160405180910390fd5b6001600160a01b0382166001146116d857604051636eb1769f60e11b81523060048201526001600160a01b0382811660248301526000919084169063dd62ed3e90604401602060405180830381865afa158015611678573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169c9190612175565b905060001981146114d05780156116c2576116c26001600160a01b0384168360006117f2565b6114d06001600160a01b038416836000196117f2565b5050565b60006001600160a01b03821660011461175c576040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015611733573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117579190612175565b61175e565b475b92915050565b6117bc846323b872dd60e01b85858560405160240161178593929190612151565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611907565b50505050565b6040516001600160a01b0383166024820152604481018290526114d090849063a9059cbb60e01b90606401611785565b80158061186c5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015611846573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061186a9190612175565b155b6118d75760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610705565b6040516001600160a01b0383166024820152604481018290526114d090849063095ea7b360e01b90606401611785565b600061195c826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166119dc9092919063ffffffff16565b905080516000148061197d57508080602001905181019061197d919061227b565b6114d05760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610705565b60606119eb84846000856119f3565b949350505050565b606082471015611a545760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610705565b600080866001600160a01b03168587604051611a7091906122bc565b60006040518083038185875af1925050503d8060008114611aad576040519150601f19603f3d011682016040523d82523d6000602084013e611ab2565b606091505b5091509150611ac387838387611ace565b979650505050505050565b60608315611b3d578251600003611b36576001600160a01b0385163b611b365760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610705565b50816119eb565b6119eb8383815115611b525781518083602001fd5b8060405162461bcd60e51b815260040161070591906122d8565b5080546000825590600052602060002090810190610b1c91905b8082111561149a5760008155600101611b86565b6001600160a01b0381168114610b1c57600080fd5b60008060408385031215611bc257600080fd5b8235611bcd81611b9a565b946020939093013593505050565b600080600080600060808688031215611bf357600080fd5b8535611bfe81611b9a565b94506020860135611c0e81611b9a565b935060408601359250606086013567ffffffffffffffff80821115611c3257600080fd5b818801915088601f830112611c4657600080fd5b813581811115611c5557600080fd5b896020828501011115611c6757600080fd5b9699959850939650602001949392505050565b600060208284031215611c8c57600080fd5b8135611c9781611b9a565b9392505050565b600060208284031215611cb057600080fd5b813567ffffffffffffffff811115611cc757600080fd5b82016101008185031215611c9757600080fd5b634e487b7160e01b600052604160045260246000fd5b60006020808385031215611d0357600080fd5b825167ffffffffffffffff80821115611d1b57600080fd5b818501915085601f830112611d2f57600080fd5b815181811115611d4157611d41611cda565b8060051b604051601f19603f83011681018181108582111715611d6657611d66611cda565b604052918252848201925083810185019188831115611d8457600080fd5b938501935b82851015611da257845184529385019392850192611d89565b98975050505050505050565b8015158114610b1c57600080fd5b600060208284031215611dce57600080fd5b8135611c9781611dae565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8082018082111561175e5761175e611def565b600060018201611e2a57611e2a611def565b5060010190565b6000813561175e81611b9a565b6000808335601e19843603018112611e5557600080fd5b83018035915067ffffffffffffffff821115611e7057600080fd5b6020019150600581901b3603821315611e8857600080fd5b9250929050565b67ffffffffffffffff831115611ea757611ea7611cda565b68010000000000000000831115611ec057611ec0611cda565b805483825580841015611ef7576000828152602081208581019083015b80821015611ef357828255600182019150611edd565b5050505b5060008181526020812083915b85811015611f2057823582820155602090920191600101611f04565b505050505050565b8135611f3381611dae565b815490151560ff1660ff1991909116178155611f7a611f5460208401611e31565b828054610100600160a81b03191660089290921b610100600160a81b0316919091179055565b6040820135600182015560608201356002820155611fc1611f9d60808401611e31565b6003830180546001600160a01b0319166001600160a01b0392909216919091179055565b60a08201356004820155611fd860c0830183611e3e565b611fe6818360058601611e8f565b5050611ff560e0830183611e3e565b6117bc818360068601611e8f565b8183526000602080850194508260005b8581101561202f57813587529582019590820190600101612013565b509495945050505050565b8b151581526001600160a01b038b81166020830152604082018b9052606082018a90528816608082015260a0810187905261012060c08201819052600090612085838201888a612003565b905082810360e084015261209a818688612003565b915050826101008301529c9b505050505050505050505050565b600081518084526020808501945080840160005b8381101561202f578151875295820195908201906001016120c8565b88151581526001600160a01b03888116602083015260408201889052606082018790528516608082015260a0810184905261010060c0820181905260009061212e838201866120b4565b905082810360e084015261214281856120b4565b9b9a5050505050505050505050565b6001600160a01b039384168152919092166020820152604081019190915260600190565b60006020828403121561218757600080fd5b5051919050565b8381528260208201526060604082015260006121ad60608301846120b4565b95945050505050565b6000600160ff1b82016121cb576121cb611def565b5060000390565b85815260018060a01b038516602082015283604082015282606082015260a060808201526000611ac360a08301846120b4565b89151581526001600160a01b03898116602083015260408201899052606082018890528616608082015260a0810185905261012060c0820181905260009061224f838201876120b4565b905082810360e084015261226381866120b4565b915050826101008301529a9950505050505050505050565b60006020828403121561228d57600080fd5b8151611c9781611dae565b60005b838110156122b357818101518382015260200161229b565b50506000910152565b600082516122ce818460208701612298565b9190910192915050565b60208152600082518060208401526122f7816040850160208701612298565b601f01601f1916919091016040019291505056fea2646970667358221220d696ad5708d72ee9667b8585517585eb0a4a1cddee4e36a0611f4d5490b7abe064736f6c63430008140033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f82800000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d1

-----Decoded View---------------
Arg [0] : pToken_ (address): 0x67BDD68f20a1BB06f487d29b26ad63e162A2f828
Arg [1] : gateway_ (address): 0x35EE168B4d0EA31974E9B184480b758F3E9940D1

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 00000000000000000000000067bdd68f20a1bb06f487d29b26ad63e162a2f828
Arg [1] : 00000000000000000000000035ee168b4d0ea31974e9b184480b758f3e9940d1


Block Transaction Gas Used Reward
view all blocks ##produced##

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.