false
false
0

Contract Address Details

0xFa68ce20228aE14AC338Aedb95f0F55b4e8b2bbE

Contract Name
UpgradeableStakingLSTV2
Creator
0x454d79–a33fa0 at 0x1f1b23–6ed271
Balance
0 ACA
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
12287542
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
UpgradeableStakingLSTV2




Optimization enabled
true
Compiler version
v0.8.17+commit.8df45f5f




Optimization runs
200
EVM Version
default




Verified at
2024-01-05T05:30:18.747935Z

Contract source code

Sol2uml
new
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)

// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

/**
 * @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);
}

// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

/**
 * @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.
 */
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].
     */
    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);
}

// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

/**
 * @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);
        }
    }
}

/**
 * @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. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    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));
    }
}

/// @title Homa Predeploy Contract Interface
/// @author Acala Developers
/// @notice You can use this predeploy contract to call homa pallet
/// @dev The interface through which solidity contracts will interact with homa pallet
interface IHoma {
    /// @notice Minted liquid currency event.
    /// @param sender The sender of the transaction.
    /// @param amount The minted amount.
    event Minted(address indexed sender, uint256 amount);

    /// @notice Requested redeem event.
    /// @param sender The sender of the transaction.
    /// @param amount The requested amount.
    /// @param fastMatch Allow the request to be fast matched.
    event RequestedRedeem(
        address indexed sender,
        uint256 amount,
        bool fastMatch
    );

    /// @notice Mint liquid currency with staking currency.
    /// @dev It'll emit an {Minted} event.
    /// @param mintAmount The amount of staking currency used to mint liquid currency.
    /// @return Returns a boolean value indicating whether the operation succeeded.
    function mint(uint256 mintAmount) external returns (bool);

    /// @notice Request to redeem liquid curency for staking currency.
    /// @dev It'll emit an {RequestedRedeem} event.
    /// @param redeemAmount The amount of liquid currency to be requested  redeemed into Staking currency.
    /// @param fastMatch Allow the request to be fast matched, fast match will take a fixed rate as fee.
    /// @return Returns a boolean value indicating whether the operation succeeded.
    function requestRedeem(
        uint256 redeemAmount,
        bool fastMatch
    ) external returns (bool);

    /// @notice Get exchange rate.
    /// @return returns (exchange_rate), value is FixedU128 with a range of
    /// [0.000000000000000000, 340282366920938463463.374607431768211455]
    function getExchangeRate() external view returns (uint256);

    /// @notice Get estimated reward rate.
    /// @return returns (reward_rate), value is FixedU128 with a range of
    /// [0.000000000000000000, 340282366920938463463.374607431768211455].
    function getEstimatedRewardRate() external view returns (uint256);

    /// @notice Get commission rate.
    /// @return returns (commission_rate) is a FixedU128 representing a decimal.
    function getCommissionRate() external view returns (uint256);

    /// @notice Get fast match fee rate.
    /// @return returns (fast_match_fee) is a FixedU128 representing a decimal.
    function getFastMatchFee() external view returns (uint256);
}

/// @title StableAsset Predeploy Contract Interface
/// @author Acala Developers
/// @notice You can use this predeploy contract to call stable-asset pallet
/// @dev The interface through which solidity contracts will interact with stable-asset pallet
interface IStableAsset {
    /// @notice The stable asset swapped event.
    /// @param sender The sender of the transaction.
    /// @param poolId The ID of the pool.
    /// @param i The array index of the input token in stableAsset tokens.
    /// @param j The array index of the output token in stableAsset tokens.
    /// @param dx The amount of input token.
    /// @param minDY The minimum amount of output token received.
    /// @param assetLength The length of array in stableAsset tokens.
    event StableAssetSwapped(
        address indexed sender,
        uint32 indexed poolId,
        uint32 i,
        uint32 j,
        uint256 dx,
        uint256 minDY,
        uint32 assetLength
    );

    /// @notice The stable asset minted event.
    /// @param sender The sender of the transaction.
    /// @param poolId The ID of the pool.
    /// @param amounts amount of tokens to be put in the pool.
    /// @param minMintAmount amount of minimum pool token received.
    event StableAssetMinted(
        address indexed sender,
        uint32 indexed poolId,
        uint256[] amounts,
        uint256 minMintAmount
    );

    /// @notice The scheduled call event.
    /// @param sender The sender of the transaction.
    /// @param poolId The ID of the pool.
    /// @param redeemAmount The amount of pool token to be redeemed.
    /// @param amounts The minimum amounts of redeemed token received.
    event StableAssetRedeemed(
        address indexed sender,
        uint32 indexed poolId,
        uint256 redeemAmount,
        uint256[] amounts
    );

    /// @notice The scheduled call event.
    /// @param sender The sender of the transaction.
    /// @param poolId The ID of the pool.
    /// @param redeemAmount The amount of pool token to be redeemed.
    /// @param i The the array index of the input token in stable pool.
    /// @param minRedeemAmount The minimum amount of token recieved.
    /// @param assetLength The length of array of tokens in stable pool.
    event StableAssetRedeemedSingle(
        address indexed sender,
        uint32 indexed poolId,
        uint256 redeemAmount,
        uint32 i,
        uint256 minRedeemAmount,
        uint32 assetLength
    );

    /// @notice The scheduled call event.
    /// @param sender The sender of the transaction.
    /// @param poolId The ID of the pool.
    /// @param amounts The amount of underlying token to be recieved.
    /// @param maxRedeemAmount The maximum amount of pool token to be input.
    event StableAssetRedeemedMulti(
        address indexed sender,
        uint32 indexed poolId,
        uint256[] amounts,
        uint256 maxRedeemAmount
    );

    /// @notice Get stable asset pool tokens.
    /// @param poolId The ID of the pool.
    /// @return poolExists whether pool exists or not.
    /// @return tokens stabel asset pool tokens.
    function getStableAssetPoolTokens(
        uint32 poolId
    ) external view returns (bool, address[] memory);

    /// @notice Get stable asset pool total supply.
    /// @param poolId The ID of the pool.
    /// @return poolExists whether pool exists or not.
    /// @return totalSupply total supply value.
    function getStableAssetPoolTotalSupply(
        uint32 poolId
    ) external view returns (bool, uint256);

    /// @notice Get stable asset pool precision.
    /// @param poolId The ID of the pool.
    /// @return poolExists whether pool exists or not.
    /// @return precision precision value.
    function getStableAssetPoolPrecision(
        uint32 poolId
    ) external view returns (bool, uint256);

    /// @notice Get stable asset pool mint fee.
    /// @param poolId The ID of the pool.
    /// @return poolExists whether pool exists or not.
    /// @return mintFee mint fee value.
    function getStableAssetPoolMintFee(
        uint32 poolId
    ) external view returns (bool, uint256);

    /// @notice Get stable asset pool swap fee.
    /// @param poolId The ID of the pool.
    /// @return poolExists whether pool exists or not.
    /// @return swapFee swap fee value.
    function getStableAssetPoolSwapFee(
        uint32 poolId
    ) external view returns (bool, uint256);

    /// @notice Get stable asset pool redeem fee.
    /// @param poolId The ID of the pool.
    /// @return poolExists whether pool exists or not.
    /// @return redeemFee redeem fee value.
    function getStableAssetPoolRedeemFee(
        uint32 poolId
    ) external view returns (bool, uint256);

    /// @notice Stable asset swap tokens.
    /// @dev It'll emit an {StableAssetSwapped} event.
    /// @param poolId The ID of the pool.
    /// @param i The array index of the input token in stableAsset tokens.
    /// @param j The array index of the output token in stableAsset tokens.
    /// @param dx The amount of input token.
    /// @param minDY The minimum amount of output token received.
    /// @param assetLength The length of array in stableAsset tokens.
    /// @return Returns a boolean value indicating whether the operation succeeded.
    function stableAssetSwap(
        uint32 poolId,
        uint32 i,
        uint32 j,
        uint256 dx,
        uint256 minDY,
        uint32 assetLength
    ) external returns (bool);

    /// @notice Stable asset mint.
    /// @dev It'll emit an {StableAssetMinted} event.
    /// @param poolId The ID of the pool.
    /// @param amounts amount of tokens to be put in the pool.
    /// @param minMintAmount amount of minimum pool token received.
    /// @return Returns a boolean value indicating whether the operation succeeded.
    function stableAssetMint(
        uint32 poolId,
        uint256[] calldata amounts,
        uint256 minMintAmount
    ) external returns (bool);

    /// @notice Stable asset redeem, redeems the token proportionally.
    /// @dev It'll emit an {StableAssetRedeemed} event.
    /// @param poolId The ID of the pool.
    /// @param redeemAmount The amount of pool token to be redeemed.
    /// @param amounts The minimum amounts of redeemed token received.
    /// @return Returns a boolean value indicating whether the operation succeeded.
    function stableAssetRedeem(
        uint32 poolId,
        uint256 redeemAmount,
        uint256[] calldata amounts
    ) external returns (bool);

    /// @notice Stable asset redeem single, Redeems token into single token from pool.
    /// @dev It'll emit an {StableAssetRedeemedSingle} event.
    /// @param poolId The ID of the pool.
    /// @param redeemAmount The amount of pool token to be redeemed.
    /// @param i The the array index of the input token in stable pool.
    /// @param minRedeemAmount The minimum amount of token recieved.
    /// @param assetLength The length of array of tokens in stable pool.
    /// @return Returns a boolean value indicating whether the operation succeeded.
    function stableAssetRedeemSingle(
        uint32 poolId,
        uint256 redeemAmount,
        uint32 i,
        uint256 minRedeemAmount,
        uint32 assetLength
    ) external returns (bool);

    /// @notice Stable asset redeem multi, Redeems token into single token from pool.
    /// @dev It'll emit an {StableAssetRedeemedMulti} event.
    /// @param poolId The ID of the pool.
    /// @param amounts The amount of underlying token to be recieved.
    /// @param maxRedeemAmount The maximum amount of pool token to be input.
    /// @return Returns a boolean value indicating whether the operation succeeded.
    function stableAssetRedeemMulti(
        uint32 poolId,
        uint256[] calldata amounts,
        uint256 maxRedeemAmount
    ) external returns (bool);
}

/// @title Liquid Crowdloan Predeploy Contract Interface
/// @author Acala Developers
/// @notice You can use this predeploy contract to call liquid-crowdloan pallet
/// @dev The interface through which solidity contracts will interact with liquid-crowdloan pallet
interface ILiquidCrowdloan {
    /// @notice LCDOT is redeemed.
    /// @param sender The sender of the transaction.
    /// @param amount The redeem amount in LCDOT.
    /// @param redeemAmount The redeem amount in redeem token.
    event Redeemed(address indexed sender, uint256 amount, uint256 redeemAmount);

    /// @notice Redeem LCDOT.
    /// @dev It'll emit an {Redeemed} event. Use {getRedeemCurrency} to check the redeem currency.
    /// @param amount The amount of LCDOT to redeem.
    /// @return Returns how much redeem token is received.
    function redeem(uint256 amount) external returns (uint256);

    /// @notice Get the redeem currency address.
    /// @return Returns the redeem currency address.
    function getRedeemCurrency() external view returns (address);
}

// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @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);
        }
    }
}

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

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

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

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

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

/// @title PoolOperationPausable Contract
/// @author Acala Developers
/// @notice You can add modifier to functions to pause/unpause user operation for each pool by inherit this contract.
/// @dev This contract does not define access control for functions, you should override these define
/// in the derived contract.
abstract contract PoolOperationPausable {
    /// @notice The user operation pause status of `poolId` pool updated.
    /// @param poolId The index of staking pool.
    /// @param operation The user operation.
    /// @param paused True is paused, false is unpaused.
    event OperationPauseStatusSet(uint256 poolId, Operation operation, bool paused);

    enum Operation {
        Stake,
        Unstake,
        ClaimRewards
    }

    /// @dev The pause status for user operation of pool.
    /// (poolId => (operation => paused))
    mapping(uint256 => mapping(Operation => bool)) internal _pausedPoolOperations;

    /// @dev Modifier to be added to corresponding function, if it is checked that a user operation is paused,
    /// revert the transaction.
    modifier poolOperationNotPaused(uint256 poolId, Operation operation) {
        require(
            pausedPoolOperations(poolId, operation) == false, "PoolOperationPausable: operation is paused for this pool"
        );
        _;
    }

    /// @notice Get the pause status of `operation` for `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param operation The user operation.
    /// @return Returns True means paused.
    function pausedPoolOperations(uint256 poolId, Operation operation) public view virtual returns (bool) {
        return _pausedPoolOperations[poolId][operation];
    }

    /// @notice Set the `paused` status of `operation` for `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param operation The user operation.
    /// @param paused The pause status.
    /// @dev you should override this function to define access control in the derived contract.
    function setPoolOperationPause(uint256 poolId, Operation operation, bool paused) public virtual {
        _pausedPoolOperations[poolId][operation] = paused;
        emit OperationPauseStatusSet(poolId, operation, paused);
    }
}

/// @title IStaking Interface
/// @author Acala Developers
/// @notice You can use this integrate Acala LST staking into your contract.
interface IStaking {
    /// @notice Claim reward from staking pool.
    /// @param sender The sender of the transaction.
    /// @param poolId The index of staking pool.
    /// @param rewardType The reward token address.
    /// @param amount The claimed reward amount.
    event ClaimReward(address indexed sender, uint256 poolId, IERC20 indexed rewardType, uint256 amount);

    /// @notice Unstake share from staking pool.
    /// @param sender The sender of the transaction.
    /// @param poolId The index of staking pool.
    /// @param amount The share amount of unstake.
    event Unstake(address indexed sender, uint256 poolId, uint256 amount);

    /// @notice Stake share into staking pool.
    /// @param sender The sender of the transaction.
    /// @param poolId The index of staking pool.
    /// @param amount The share amount of stake.
    event Stake(address indexed sender, uint256 poolId, uint256 amount);

    /// @notice Get the share token address of the `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns (shareToken). If pool hasn't been initialized, return address(0x0).
    function shareTypes(uint256 poolId) external view returns (IERC20);

    /// @notice Get the total share amount of the `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns (totalShare).
    function totalShares(uint256 poolId) external view returns (uint256);

    /// @notice Get the all reward token types of the `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns (rewardTypesArr). Return all rewarded token types in this pool.
    function rewardTypes(uint256 poolId) external view returns (IERC20[] memory);

    /// @notice Get the share amount of `who` at `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param who The address of staker.
    /// @return Returns (shareAmount).
    function shares(uint256 poolId, address who) external view returns (uint256);

    /// @notice Get `who`'s unclaimed reward amount of specific `rewardType` at `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param who The address of staker.
    /// @param rewardType The reward token.
    /// @return Returns (rewardAmount).
    function earned(uint256 poolId, address who, IERC20 rewardType) external view returns (uint256);

    /// @notice Stake share into staking pool.
    /// @param poolId The index of staking pool.
    /// @param amount The share amount to stake.
    /// @return Returns (success).
    function stake(uint256 poolId, uint256 amount) external returns (bool);

    /// @notice Withdraw share from staking pool.
    /// @param poolId The index of staking pool.
    /// @return Returns (success).
    function unstake(uint256 poolId, uint256 amount) external returns (bool);

    /// @notice Claim all rewards from staking pool.
    /// @param poolId The index of staking pool.
    /// @return Returns (success).
    function claimRewards(uint256 poolId) external returns (bool);

    /// @notice Unstake all staked share and claim all unclaimed rewards from staking pool.
    /// @param poolId The index of staking pool.
    /// @return Returns (success).
    function exit(uint256 poolId) external returns (bool);
}

/// @title IStakingTo Interface
/// @author Acala Developers
/// @notice You can use this integrate Acala LST staking into your contract.
interface IStakingTo is IStaking {
    /// @notice Stake share to other.
    /// @param poolId The index of staking pool.
    /// @param amount The share amount to stake.
    /// @param receiver The share receiver.
    /// @return Returns (success).
    function stakeTo(uint256 poolId, uint256 amount, address receiver) external returns (bool);
}

/// @title Staking Abstract Contract
/// @author Acala Developers
/// @notice Staking supports multiple reward tokens and rewards claim deduction pubnishment.
/// Deduction rewards will be distributed to all stakers in the pool.
/// @dev This contract does not define access control for functions, you should override these define
/// in the derived contract.
abstract contract Staking is IStaking {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    /// @notice The rule for `rewardType` token at `poolId` pool updated.
    /// @param poolId The index of staking pool.
    /// @param rewardType The reward token.
    /// @param rewardRate The amount of `rewardType` token will accumulate per second.
    /// @param endTime The end time of this reward rule.
    event RewardRuleUpdate(uint256 poolId, IERC20 rewardType, uint256 rewardRate, uint256 endTime);

    /// @notice New staking pool.
    /// @param poolId The index of staking pool.
    /// @param shareType The share token of this staking pool.
    event NewPool(uint256 poolId, IERC20 shareType);

    /// @notice The deduction rate for all `rewardType` rewards of `poolId` pool updated.
    /// @param poolId The index of staking pool.
    /// @param rate The deduction rate.
    event RewardsDeductionRateSet(uint256 poolId, uint256 rate);

    struct RewardRule {
        // Reward amount per second.
        uint256 rewardRate;
        // The end time for reward accumulation.
        uint256 endTime;
        // Accumulated reward rate, this is used to calculate the reward amount of each staker.
        // It mul 1e18 to avoid loss of precision.
        uint256 rewardRateAccumulated;
        // The last time of this rule accumulates reward.
        uint256 lastAccumulatedTime;
    }

    /// @notice The maximum number of reward types for a staking pool. When distribute and receiving rewards,
    /// all reward types of a pool will be iterated. Limit the number of reward types to avoid out of huge gas.
    uint256 public constant MAX_REWARD_TYPES = 3;

    /// @dev The index of staking pools.
    uint256 internal _poolIndex = 0;

    /// @dev The share token of staking pool.
    /// (poolId => shareType)
    mapping(uint256 => IERC20) internal _shareTypes;

    /// @dev The share token of staking pool.
    /// (poolId => shareType)
    mapping(uint256 => uint256) internal _totalShares;

    /// @dev The deduction rate for all rewards of pool. 1e18 is 100%
    /// (poolId => rate)
    mapping(uint256 => uint256) internal _rewardsDeductionRates;

    /// @dev The reward token types of pool.
    /// (poolId => rewardTypeArr[])
    mapping(uint256 => IERC20[]) internal _rewardTypes;

    /// @dev The reward rule for reward type of pool.
    /// (poolId => (rewardType => rule))
    mapping(uint256 => mapping(IERC20 => RewardRule)) internal _rewardRules;

    /// @dev The share record for stakers of pool.
    /// (poolId => (staker => shareAmount))
    mapping(uint256 => mapping(address => uint256)) internal _shares;

    /// @dev The unclaimed reward amount for stakers of pool.
    /// (poolId => (staker => (rewardType => rewardAmount)))
    mapping(uint256 => mapping(address => mapping(IERC20 => uint256))) internal _rewards;

    /// @dev The reward accumulation rate for stakers of pool, this is used to calculate the reward amount of each staker.
    /// (poolId => (staker => (rewardType => rewardAmount)))
    mapping(uint256 => mapping(address => mapping(IERC20 => uint256))) internal _paidAccumulatedRates;

    /// @notice Get the index of next pool. It's equal to the current count of pools.
    /// @return Returns the next pool index.
    function poolIndex() public view virtual returns (uint256) {
        return _poolIndex;
    }

    /// @notice Get the share token of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns share token.
    function shareTypes(uint256 poolId) public view virtual override returns (IERC20) {
        return _shareTypes[poolId];
    }

    /// @notice Get the total share amount of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns total share amount.
    function totalShares(uint256 poolId) public view virtual override returns (uint256) {
        return _totalShares[poolId];
    }

    /// @notice Get the rewards decution rate of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns deduction rate.
    function rewardsDeductionRates(uint256 poolId) public view virtual returns (uint256) {
        return _rewardsDeductionRates[poolId];
    }

    /// @notice Get the reward token types of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns reward token array.
    function rewardTypes(uint256 poolId) public view virtual override returns (IERC20[] memory) {
        return _rewardTypes[poolId];
    }

    /// @notice Get the reward rule for `rewardType` reward of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param rewardType The reward token.
    /// @return Returns reward rule.
    function rewardRules(uint256 poolId, IERC20 rewardType) public view virtual returns (RewardRule memory) {
        return _rewardRules[poolId][rewardType];
    }

    /// @notice Get the share amount of `who` of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param who The staker.
    /// @return Returns share amount.
    function shares(uint256 poolId, address who) public view virtual override returns (uint256) {
        return _shares[poolId][who];
    }

    /// @notice Get the unclaimed paid `rewardType` reward amount for `who` of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param who The staker.
    /// @param rewardType The reward token.
    /// @return Returns reward amount.
    function rewards(uint256 poolId, address who, IERC20 rewardType) public view virtual returns (uint256) {
        return _rewards[poolId][who][rewardType];
    }

    /// @notice Get the paid accumulated rate of `rewardType` for `who` of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param who The staker.
    /// @param rewardType The reward token.
    /// @return Returns rate.
    function paidAccumulatedRates(uint256 poolId, address who, IERC20 rewardType)
        public
        view
        virtual
        returns (uint256)
    {
        return _paidAccumulatedRates[poolId][who][rewardType];
    }

    /// @notice Get lastest time that can be used to accumulate rewards for `rewardType` reward of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param rewardType The reward token.
    /// @return Returns timestamp.
    /// @dev If rule has ended, return the end time. Otherwise return the block time.
    function lastTimeRewardApplicable(uint256 poolId, IERC20 rewardType) public view virtual returns (uint256) {
        uint256 endTime = rewardRules(poolId, rewardType).endTime;
        return block.timestamp < endTime ? block.timestamp : endTime;
    }

    /// @notice Get the exchange rate for share to `rewardType` reward token of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param rewardType The reward token.
    /// @return Returns rate.
    /// @dev The reward part is accumulated rate adds pending to accumulate rate, it's used to calculate reward. 1e18 is 100%.
    function rewardPerShare(uint256 poolId, IERC20 rewardType) public view virtual returns (uint256) {
        RewardRule memory rewardRule = rewardRules(poolId, rewardType);
        uint256 totalShare = totalShares(poolId);

        if (totalShare == 0) {
            return rewardRule.rewardRateAccumulated;
        }

        uint256 pendingRewardRate = lastTimeRewardApplicable(poolId, rewardType).sub(rewardRule.lastAccumulatedTime).mul(
            rewardRule.rewardRate
        ).mul(1e18).div(totalShare); // mul 10**18 to avoid loss of precision

        return rewardRule.rewardRateAccumulated.add(pendingRewardRate);
    }

    /// @inheritdoc IStaking
    function earned(uint256 poolId, address who, IERC20 rewardType) public view virtual override returns (uint256) {
        uint256 share = shares(poolId, who);
        uint256 reward = rewards(poolId, who, rewardType);
        uint256 paidAccumulatedRate = paidAccumulatedRates(poolId, who, rewardType);
        uint256 pendingReward = share.mul(rewardPerShare(poolId, rewardType).sub(paidAccumulatedRate)).div(1e18); // div 10**18 that was mul in rewardPerShare

        return reward.add(pendingReward);
    }

    /// @dev Modifier to accumulate rewards for `poolId` pool, and distribute new accumulate rewards
    /// to `account`. If `account` is zero address, just accumulate rewards for pool.
    modifier updateRewards(uint256 poolId, address account) {
        IERC20[] memory types = rewardTypes(poolId);

        for (uint256 i = 0; i < types.length; i++) {
            RewardRule storage rewardRule = _rewardRules[poolId][types[i]];
            rewardRule.rewardRateAccumulated = rewardPerShare(poolId, types[i]);
            rewardRule.lastAccumulatedTime = lastTimeRewardApplicable(poolId, types[i]);

            // if account is not zero address, need accumulate reward and distribute
            if (account != address(0)) {
                _rewards[poolId][account][types[i]] = earned(poolId, account, types[i]);
                _paidAccumulatedRates[poolId][account][types[i]] = rewardRule.rewardRateAccumulated;
            }
        }

        _;
    }

    /// @notice Initialize a staking pool for `shareType`.
    /// @param shareType The share token.
    /// @dev you should override this function to define access control in the derived contract.
    function addPool(IERC20 shareType) public virtual {
        require(address(shareType) != address(0), "share token is zero address");

        uint256 poolId = poolIndex();
        _shareTypes[poolId] = shareType;
        _poolIndex = poolId.add(1);

        emit NewPool(poolId, shareType);
    }

    /// @notice Set deduction `rate` of claim rewards for `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param rate The deduction rate. 1e18 is 100%
    /// @dev you should override this function to define access control in the derived contract.
    function setRewardsDeductionRate(uint256 poolId, uint256 rate) public virtual {
        require(address(shareTypes(poolId)) != address(0), "invalid pool");
        require(rate <= 1e18, "invalid rate");

        _rewardsDeductionRates[poolId] = rate;
        emit RewardsDeductionRateSet(poolId, rate);
    }

    /// @notice Update the reward rule of `rewardType` for `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param rewardType The reward token.
    /// @param rewardRate The reward amount per second.
    /// @param endTime The end time of fule.
    /// @dev you should override this function to define access control in the derived contract.
    function updateRewardRule(uint256 poolId, IERC20 rewardType, uint256 rewardRate, uint256 endTime)
        public
        virtual
        updateRewards(poolId, address(0))
    {
        require(address(rewardType) != address(0), "reward token is zero address");
        require(address(shareTypes(poolId)) != address(0), "pool must be existed");

        IERC20[] memory types = rewardTypes(poolId);
        bool isNew = true;
        for (uint256 i = 0; i < types.length; i++) {
            if (types[i] == rewardType) {
                isNew = false;
                break;
            }
        }

        // if is a new reward type, need add to rewardTypes
        if (isNew) {
            _rewardTypes[poolId].push(rewardType);
        }
        require(_rewardTypes[poolId].length <= MAX_REWARD_TYPES, "too many reward types");

        RewardRule storage rewardRule = _rewardRules[poolId][rewardType];

        // rewards has accumulated to lastTimeRewardApplicable at previous updateRewards, so reset lastAccumulatedTime to now
        rewardRule.lastAccumulatedTime = block.timestamp;

        uint256 remainerReward;
        // If there are already rewards that have not yet ended, calculate the remainerReward that have not yet been accumulated.
        if (rewardRule.endTime > rewardRule.lastAccumulatedTime) {
            remainerReward = rewardRule.endTime.sub(rewardRule.lastAccumulatedTime).mul(rewardRule.rewardRate);
        }

        // reset endTime and rewardRate.
        if (block.timestamp > endTime) {
            rewardRule.endTime = block.timestamp;
        } else {
            rewardRule.endTime = endTime;
        }
        rewardRule.rewardRate = rewardRate;

        // calculate the newReward amount for the updated rewardRule.
        uint256 newReward = rewardRule.endTime.sub(rewardRule.lastAccumulatedTime).mul(rewardRule.rewardRate);

        if (remainerReward < newReward) {
            // if remainerReward is less than newReward, need transfer the gap from msg.sender to contract.
            rewardType.safeTransferFrom(msg.sender, address(this), newReward.sub(remainerReward));
        } else if (remainerReward > newReward) {
            // if remainerReward is greater than newReward, return the surplus part to msg.sender.
            rewardType.safeTransfer(msg.sender, remainerReward.sub(newReward));
        }

        emit RewardRuleUpdate(poolId, rewardType, rewardRule.rewardRate, rewardRule.endTime);
    }

    /// @inheritdoc IStaking
    function stake(uint256 poolId, uint256 amount)
        public
        virtual
        override
        updateRewards(poolId, msg.sender)
        returns (bool)
    {
        require(amount > 0, "cannot stake 0");
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");

        _totalShares[poolId] = _totalShares[poolId].add(amount);
        _shares[poolId][msg.sender] = _shares[poolId][msg.sender].add(amount);

        shareType.safeTransferFrom(msg.sender, address(this), amount);

        emit Stake(msg.sender, poolId, amount);

        return true;
    }

    /// @inheritdoc IStaking
    function unstake(uint256 poolId, uint256 amount)
        public
        virtual
        override
        updateRewards(poolId, msg.sender)
        returns (bool)
    {
        require(amount > 0, "cannot unstake 0");
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");
        require(shares(poolId, msg.sender) >= amount, "share not enough");

        _totalShares[poolId] = _totalShares[poolId].sub(amount);
        _shares[poolId][msg.sender] = _shares[poolId][msg.sender].sub(amount);

        shareType.safeTransfer(msg.sender, amount);

        emit Unstake(msg.sender, poolId, amount);

        return true;
    }

    /// @inheritdoc IStaking
    function claimRewards(uint256 poolId) public virtual override updateRewards(poolId, msg.sender) returns (bool) {
        IERC20[] memory types = rewardTypes(poolId);
        uint256 deductionRate = rewardsDeductionRates(poolId);

        for (uint256 i = 0; i < types.length; ++i) {
            uint256 rewardAmount = rewards(poolId, msg.sender, types[i]);
            if (rewardAmount > 0) {
                _rewards[poolId][msg.sender][types[i]] = 0;

                uint256 deduction = rewardAmount.mul(deductionRate).div(1e18);
                uint256 remainingReward = rewardAmount.sub(deduction);

                if (deduction > 0) {
                    RewardRule storage rewardRule = _rewardRules[poolId][types[i]];
                    uint256 totalShare = totalShares(poolId);

                    if (totalShare != 0) {
                        // redistribute the deduction to all stakers
                        uint256 addedAccumulatedRate = deduction.mul(1e18).div(totalShare);
                        rewardRule.rewardRateAccumulated = rewardRule.rewardRateAccumulated.add(addedAccumulatedRate);
                    }
                }

                types[i].safeTransfer(msg.sender, remainingReward);
                emit ClaimReward(msg.sender, poolId, types[i], remainingReward);
            }
        }

        return true;
    }

    /// @inheritdoc IStaking
    function exit(uint256 poolId) external virtual override returns (bool) {
        unstake(poolId, shares(poolId, msg.sender));
        claimRewards(poolId);
        return true;
    }
}

/// @title UpgradeableStakingCommon Contract
/// @author Acala Developers
/// @notice You can use this contract as a base contract for staking.
/// @dev This contract derived OwnableUpgradeable, PausableUpgradeable and PoolOperationPausable,
/// and overrides some functions to add access control for these.
/// This version conforms to the specification for upgradeable contracts.
contract UpgradeableStakingCommon is
    OwnableUpgradeable,
    PausableUpgradeable,
    Staking,
    PoolOperationPausable,
    ReentrancyGuardUpgradeable
{
    /// @notice The initialize function.
    /// @dev proxy contract will call this when firstly fetch this contract as the implementation contract.
    function initialize() public virtual initializer {
        __Pausable_init();
        __Ownable_init();
        __ReentrancyGuard_init();
    }

    /// @notice Puase the contract by Pausable.
    /// @dev Define the `onlyOwner` access.
    function pause() external onlyOwner {
        _pause();
    }

    /// @notice Unpuase the contract by Pausable.
    /// @dev Define the `onlyOwner` access.
    function unpause() external onlyOwner {
        _unpause();
    }

    /// @inheritdoc PoolOperationPausable
    /// @dev Override the inherited function to define `onlyOwner` and `whenNotPaused` access.
    function setPoolOperationPause(uint256 poolId, Operation operation, bool paused)
        public
        override
        onlyOwner
        whenNotPaused
    {
        super.setPoolOperationPause(poolId, operation, paused);
    }

    /// @inheritdoc Staking
    /// @dev Override the inherited function to define `onlyOwner` and `whenNotPaused` access.
    function addPool(IERC20 shareType) public override onlyOwner whenNotPaused {
        super.addPool(shareType);
    }

    /// @inheritdoc Staking
    /// @dev Override the inherited function to define `onlyOwner` and `whenNotPaused` access.
    function setRewardsDeductionRate(uint256 poolId, uint256 rate) public override onlyOwner whenNotPaused {
        super.setRewardsDeductionRate(poolId, rate);
    }

    /// @inheritdoc Staking
    /// @dev Override the inherited function to define `onlyOwner` and `whenNotPaused` access.
    function updateRewardRule(uint256 poolId, IERC20 rewardType, uint256 rewardRate, uint256 endTime)
        public
        override
        onlyOwner
        whenNotPaused
    {
        super.updateRewardRule(poolId, rewardType, rewardRate, endTime);
    }

    /// @inheritdoc Staking
    /// @dev Override the inherited function to define `whenNotPaused` and `poolOperationNotPaused(poolId, Operation.Stake)` access.
    function stake(uint256 poolId, uint256 amount)
        public
        virtual
        override
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.Stake)
        nonReentrant
        returns (bool)
    {
        return super.stake(poolId, amount);
    }

    /// @inheritdoc Staking
    /// @dev Override the inherited function to define `whenNotPaused` and `poolOperationNotPaused(poolId, Operation.Unstake)`.
    function unstake(uint256 poolId, uint256 amount)
        public
        virtual
        override
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.Unstake)
        nonReentrant
        returns (bool)
    {
        return super.unstake(poolId, amount);
    }

    /// @inheritdoc Staking
    /// @dev Override the inherited function to define `whenNotPaused` and `poolOperationNotPaused(poolId, Operation.ClaimRewards)`.
    function claimRewards(uint256 poolId)
        public
        override
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.ClaimRewards)
        nonReentrant
        returns (bool)
    {
        return super.claimRewards(poolId);
    }

    /// @inheritdoc Staking
    /// @dev Override the inherited function to define access.
    function exit(uint256 poolId) external override returns (bool) {
        unstake(poolId, shares(poolId, msg.sender));
        claimRewards(poolId);
        return true;
    }
}

// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(address indexed owner, address indexed spender, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                            METADATA STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    /*//////////////////////////////////////////////////////////////
                              ERC20 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    mapping(address => mapping(address => uint256)) public allowance;

    /*//////////////////////////////////////////////////////////////
                            EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

    /*//////////////////////////////////////////////////////////////
                               ERC20 LOGIC
    //////////////////////////////////////////////////////////////*/

    function approve(address spender, uint256 amount) public virtual returns (bool) {
        allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function transfer(address to, uint256 amount) public virtual returns (bool) {
        balanceOf[msg.sender] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }

    /*//////////////////////////////////////////////////////////////
                             EIP-2612 LOGIC
    //////////////////////////////////////////////////////////////*/

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                    keccak256(bytes(name)),
                    keccak256("1"),
                    block.chainid,
                    address(this)
                )
            );
    }

    /*//////////////////////////////////////////////////////////////
                        INTERNAL MINT/BURN LOGIC
    //////////////////////////////////////////////////////////////*/

    function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }
}

/// @title IWTDOT Interface
/// @author Acala Developers
/// @notice You can use this integrate with WrappedTDOT.
interface IWTDOT {
    /// @notice Deposit TDOT to mint WTDOT.
    /// @param who The sender of the transaction.
    /// @param tdotAmount The TDOT amount to deposit.
    /// @param wtdotAmount The WTDOT amount received.
    event Deposit(address indexed who, uint256 tdotAmount, uint256 wtdotAmount);

    /// @notice Withdraw TDOT by burn WTDOT.
    /// @param who The sender of the transaction.
    /// @param wtdotAmount The WTDOT amount to burn.
    /// @param tdotAmount The TDOT amount received.
    event Withdraw(address indexed who, uint256 wtdotAmount, uint256 tdotAmount);

    /// @notice Get the deposit rate(the exchange rate for TDOT to WTDOT).
    /// @return Returns (exchangeRate). Deposit rate, 1e18 is 100%
    function depositRate() external view returns (uint256);

    /// @notice Get the withdraw rate(the exchange rate for WTDOT to TDOT).
    /// @return Returns (exchangeRate). Withdraw rate, 1e18 is 100%
    function withdrawRate() external view returns (uint256);

    /// @notice Deposit `tdotAmount` TDOT to mint WTDOT.
    /// @param tdotAmount The TDOT amount to deposit.
    /// @return Returns (wtdotAmount). The WTDOT amount received.
    function deposit(uint256 tdotAmount) external returns (uint256);

    /// @notice Withdraw TDOT by burn `wtdotAmount` WTDOT.
    /// @param wtdotAmount The WTDOT amount to burn.
    /// @return Returns (tdotAmount). The TDOT amount received.
    function withdraw(uint256 wtdotAmount) external returns (uint256);
}

/// @title WrappedTDOT Contract
/// @author Acala Developers
/// @notice To wrap TDOT, TDOT is the LP token of Taiga's StableAsset(DOT-LDOT) pool on Acala. The TDOT holders
/// can receive TDOT as the LP fee by claim. So WTDOT and DOT do not maintain a 1:1 ratio.
contract WrappedTDOT is IWTDOT, ERC20, ReentrancyGuard {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    /// @notice The token address of TDOT.
    address public immutable tdot;

    /// @notice Deploys WTDOT token.
    /// @param tdotAddr The token address of TDOT.
    constructor(address tdotAddr) ERC20("Wrapped TDOT", "WTDOT", 10) {
        tdot = tdotAddr;
    }

    /// @inheritdoc IWTDOT
    function depositRate() public view returns (uint256) {
        uint256 tdotAmount = IERC20(tdot).balanceOf(address(this));
        uint256 wtdotAmount = totalSupply;

        if (wtdotAmount == 0 || tdotAmount == 0) {
            return 1e18;
        } else {
            return wtdotAmount.mul(1e18).div(tdotAmount);
        }
    }

    /// @inheritdoc IWTDOT
    function withdrawRate() public view returns (uint256) {
        uint256 tdotAmount = IERC20(tdot).balanceOf(address(this));
        uint256 wtdotAmount = totalSupply;

        if (wtdotAmount == 0) {
            return 0;
        } else {
            return tdotAmount.mul(1e18).div(wtdotAmount);
        }
    }

    /// @inheritdoc IWTDOT
    function deposit(uint256 tdotAmount) public returns (uint256) {
        uint256 wtdotAmount = tdotAmount.mul(depositRate()).div(1e18);
        require(wtdotAmount != 0, "WTDOT: invalid WTDOT amount");

        IERC20(tdot).safeTransferFrom(msg.sender, address(this), tdotAmount);
        _mint(msg.sender, wtdotAmount);

        emit Deposit(msg.sender, tdotAmount, wtdotAmount);
        return wtdotAmount;
    }

    /// @inheritdoc IWTDOT
    function withdraw(uint256 wtdotAmount) public returns (uint256) {
        require(balanceOf[msg.sender] >= wtdotAmount, "WTDOT: WTDOT not enough");
        uint256 tdotAmount = wtdotAmount.mul(withdrawRate()).div(1e18);
        require(tdotAmount != 0, "WTDOT: invalid TDOT amount");

        _burn(msg.sender, wtdotAmount);
        IERC20(tdot).safeTransfer(msg.sender, tdotAmount);

        emit Withdraw(msg.sender, wtdotAmount, tdotAmount);
        return tdotAmount;
    }
}

/// @title UpgradeableStakingLST Contract
/// @author Acala Developers
/// @notice This staking contract can convert the share token to it's LST. It just support LcDOT token on Acala.
/// @dev After pool's share is converted into its LST token, this pool can be staked with LST token and before token both.
/// This version conforms to the specification for upgradeable contracts.
contract UpgradeableStakingLST is UpgradeableStakingCommon {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    /// @notice The pool's share token is converted into its LST token.
    /// @param poolId The pool id.
    /// @param beforeShareType The share token before converted.
    /// @param afterShareType The share token after converted.
    /// @param beforeShareTokenAmount The share token amount before converted.
    /// @param afterShareTokenAmount The share token amount after converted.
    event LSTPoolConverted(
        uint256 poolId,
        IERC20 beforeShareType,
        IERC20 afterShareType,
        uint256 beforeShareTokenAmount,
        uint256 afterShareTokenAmount
    );

    struct ConvertInfo {
        // The converted LST token.
        IERC20 convertedShareType;
        // This is a snapshot of the ratio between share amount to new share token amount at the moment of conversion. 1e18 is 1:1
        uint256 convertedExchangeRate;
    }

    enum ConvertType {
        LCDOT2LDOT,
        LCDOT2WTDOT,
        DOT2LDOT,
        DOT2WTDOT
    }

    /// @notice The DOT token address.
    address public DOT;

    /// @notice The LcDOT token address.
    address public LCDOT;

    /// @notice The LDOT token address.
    address public LDOT;

    /// @notice The tDOT token address.
    address public TDOT;

    /// @notice The Homa predeploy contract address.
    address public HOMA;

    /// @notice The StableAsset predeploy contract address.
    address public STABLE_ASSET;

    /// @notice The LiquidCrowdloan predeploy contract address.
    address public LIQUID_CROWDLOAN;

    /// @notice The Wrapped TDOT (WTDOT) token address.
    address public WTDOT;

    /// @notice The threshold amount of DOT to mint by HOMA.
    uint256 public constant HOMA_MINT_THRESHOLD = 50_000_000_000; // 5 DOT

    /// @notice The LST convert info info of pool.
    /// (poolId => convertInfo)
    mapping(uint256 => ConvertInfo) internal _convertInfos;

    /// @dev overwrite initialize() to mute initializer of UpgradeableStakingCommon
    function initialize() public override {}

    /// @notice The initialize function.
    /// @dev proxy contract will call this when firstly fetch this contract as the implementation contract.
    function initialize(
        address dot,
        address lcdot,
        address ldot,
        address tdot,
        address homa,
        address stableAsset,
        address liquidCrowdloan,
        address wtdot
    ) public initializer {
        require(dot != address(0), "DOT address is zero");
        require(lcdot != address(0), "lCDOT address is zero");
        require(ldot != address(0), "LDOT address is zero");
        require(tdot != address(0), "TDOT address is zero");
        require(homa != address(0), "HOMA address is zero");
        require(stableAsset != address(0), "STABLE_ASSET address is zero");
        require(liquidCrowdloan != address(0), "LIQUID_CROWDLOAN address is zero");
        require(wtdot != address(0), "WTDOT address is zero");
        DOT = dot;
        LCDOT = lcdot;
        LDOT = ldot;
        TDOT = tdot;
        HOMA = homa;
        STABLE_ASSET = stableAsset;
        LIQUID_CROWDLOAN = liquidCrowdloan;
        WTDOT = wtdot;

        __Pausable_init();
        __Ownable_init();
        __ReentrancyGuard_init();
    }

    /// @notice Get the LST convertion info of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns convert info.
    function convertInfos(uint256 poolId) public view returns (ConvertInfo memory) {
        return _convertInfos[poolId];
    }

    /// @dev redeem `amount` LcDOT token on LiquidCrowdloan contract.
    /// @param amount The amount of LcDOT to redeem.
    /// @return redeemCurrency The token address of redeemed currency.
    /// @return redeemedAmount The amount of redeemed token.
    function _redeemLCDOT(uint256 amount) internal returns (address redeemCurrency, uint256 redeemedAmount) {
        require(amount > 0, "amount shouldn't be zero");
        redeemCurrency = ILiquidCrowdloan(LIQUID_CROWDLOAN).getRedeemCurrency();
        redeemedAmount = ILiquidCrowdloan(LIQUID_CROWDLOAN).redeem(amount);
    }

    /// @dev convert `amount` DOT token of this contract to LDOT token.
    /// @param amount The amount of DOT to convert.
    /// @return convertAmount The amount of converted LDOT.
    function _convertDOT2LDOT(uint256 amount) internal returns (uint256 convertAmount) {
        require(amount > 0, "amount shouldn't be zero");

        uint256 beforeLdotAmount = IERC20(LDOT).balanceOf(address(this));
        bool success = IHoma(HOMA).mint(amount);
        require(success, "homa mint failed");

        uint256 afterLdotAmount = IERC20(LDOT).balanceOf(address(this));
        convertAmount = afterLdotAmount.sub(beforeLdotAmount);
    }

    /// @dev convert `amount` DOT token of this contract to TDOT token.
    /// @param amount The amount of DOT to convert.
    /// @return convertAmount The amount of converted TDOT.
    function _convertDOT2TDOT(uint256 amount) internal returns (uint256 convertAmount) {
        require(amount > 0, "amount shouldn't be zero");

        // params for tDOT pool fo StableAsset on Acala:
        // tDOT pool id: 0
        // assets length: 2
        // asset index of DOT: 0
        // asset index of LDOT: 1
        // here deadcode these params
        (bool valid, address[] memory assets) = IStableAsset(STABLE_ASSET).getStableAssetPoolTokens(0);
        require(valid && assets[0] == DOT && assets[1] == LDOT, "invalid stable asset pool");
        uint256[] memory paramAmounts = new uint256[](2);

        if (amount.div(2) >= HOMA_MINT_THRESHOLD) {
            uint256 ldotAmount = _convertDOT2LDOT(amount.div(2));

            // convert LDOT amount to rebased LDOT amount as the param
            // NOTE: the precision of Homa.getExchangeRate is 1e18
            uint256 ldotParamAmount = ldotAmount.mul(IHoma(HOMA).getExchangeRate()).div(1e18);
            paramAmounts[0] = amount.sub(amount.div(2));
            paramAmounts[1] = ldotParamAmount;
        } else {
            paramAmounts[0] = amount;
            paramAmounts[1] = 0;
        }

        uint256 beforeTdotAmount = IERC20(TDOT).balanceOf(address(this));
        // NOTE: allow max slippage here
        bool success = IStableAsset(STABLE_ASSET).stableAssetMint(0, paramAmounts, 0);
        require(success, "stable-asset mint failed");

        uint256 afterTdotAmount = IERC20(TDOT).balanceOf(address(this));
        convertAmount = afterTdotAmount.sub(beforeTdotAmount);
    }

    /// @dev convert `amount` LDOT token of this contract to TDOT token.
    /// @param amount The amount of LDOT to convert.
    /// @return convertAmount The amount of converted TDOT.
    function _convertLDOT2TDOT(uint256 amount) internal returns (uint256 convertAmount) {
        require(amount > 0, "amount shouldn't be zero");

        // params for tDOT pool fo StableAsset on Acala:
        // tDOT pool id: 0
        // assets length: 2
        // asset index of LDOT: 1
        // here deadcode these params
        (bool valid, address[] memory assets) = IStableAsset(STABLE_ASSET).getStableAssetPoolTokens(0);
        require(valid && assets[1] == LDOT, "invalid stable asset pool");

        // convert LDOT amount to rebased LDOT amount as the param
        // NOTE: the precision of Homa.getExchangeRate is 1e18
        uint256 ldotParamAmount = amount.mul(IHoma(HOMA).getExchangeRate()).div(1e18);

        uint256[] memory paramAmounts = new uint256[](2);
        paramAmounts[0] = 0;
        paramAmounts[1] = ldotParamAmount;

        uint256 beforeTdotAmount = IERC20(TDOT).balanceOf(address(this));
        // NOTE: allow max slippage here
        bool success = IStableAsset(STABLE_ASSET).stableAssetMint(0, paramAmounts, 0);
        require(success, "stable-asset mint failed");

        uint256 afterTdotAmount = IERC20(TDOT).balanceOf(address(this));
        convertAmount = afterTdotAmount.sub(beforeTdotAmount);
    }

    /// @dev convert `amount` LcDOT token of this contract to LDOT token.
    /// @param amount The amount of LcDOT to convert.
    /// @return convertAmount The amount of converted LDOT.
    function _convertLCDOT2LDOT(uint256 amount) internal returns (uint256 convertAmount) {
        require(amount > 0, "amount shouldn't be zero");

        // redeem LcDOT by LiquidCrowdloan.
        (address redeemCurrency, uint256 redeemedAmount) = _redeemLCDOT(amount);

        if (redeemCurrency == LDOT) {
            convertAmount = redeemedAmount;
        } else if (redeemCurrency == DOT) {
            convertAmount = _convertDOT2LDOT(redeemedAmount);
        } else {
            revert("unsupported convert");
        }
    }

    /// @dev convert `amount` LcDOT token of this contract to TDOT token.
    /// @param amount The amount of LcDOT to convert.
    /// @return convertAmount The amount of converted TDOT.
    function _convertLCDOT2TDOT(uint256 amount) internal returns (uint256 convertAmount) {
        require(amount != 0, "amount shouldn't be zero");

        // redeem LcDOT by LiquidCrowdloan.
        (address redeemCurrency, uint256 redeemedAmount) = _redeemLCDOT(amount);

        if (redeemCurrency == TDOT) {
            convertAmount = redeemedAmount;
        } else if (redeemCurrency == DOT) {
            convertAmount = _convertDOT2TDOT(redeemedAmount);
        } else if (redeemCurrency == LDOT) {
            convertAmount = _convertLDOT2TDOT(redeemedAmount);
        } else {
            revert("unsupported convert");
        }
    }

    /// @dev convert `amount` WTDOT token of this contract to TDOT token.
    /// @param amount The amount of WTDOT to convert.
    /// @return convertAmount The amount of converted TDOT.
    function _convertWTDOT2TDOT(uint256 amount) internal returns (uint256 convertAmount) {
        require(amount != 0, "amount shouldn't be zero");
        return IWTDOT(WTDOT).withdraw(amount);
    }

    /// @dev convert `amount` TDOT token of this contract to WTDOT token.
    /// @param amount The amount of TDOT to convert.
    /// @return convertAmount The amount of converted WTDOT.
    function _convertTDOT2WTDOT(uint256 amount) internal returns (uint256 convertAmount) {
        require(amount != 0, "amount shouldn't be zero");
        IERC20(TDOT).safeApprove(WTDOT, amount);
        return IWTDOT(WTDOT).deposit(amount);
    }

    /// @notice convert the share token of ‘poolId’ pool to LST token by `convertType`.
    /// @param poolId The index of staking pool.
    /// @param convertType The convert type.
    function convertLSTPool(uint256 poolId, ConvertType convertType) external virtual onlyOwner whenNotPaused {
        IERC20 shareType = shareTypes(poolId);
        ConvertInfo storage convert = _convertInfos[poolId];
        require(address(convert.convertedShareType) == address(0), "already converted");

        uint256 amount = totalShares(poolId);
        require(amount > 0, "pool is empty");

        uint256 convertAmount;

        if (convertType == ConvertType.LCDOT2LDOT) {
            require(address(shareType) == LCDOT, "share token must be LcDOT");

            convertAmount = _convertLCDOT2LDOT(amount);
            convert.convertedShareType = IERC20(LDOT);
        } else if (convertType == ConvertType.DOT2LDOT) {
            require(address(shareType) == DOT, "share token must be DOT");

            convertAmount = _convertDOT2LDOT(amount);
            convert.convertedShareType = IERC20(LDOT);
        } else if (convertType == ConvertType.LCDOT2WTDOT) {
            require(address(shareType) == LCDOT, "share token must be LcDOT");

            uint256 tdotAmount = _convertLCDOT2TDOT(amount);
            convertAmount = _convertTDOT2WTDOT(tdotAmount);
            convert.convertedShareType = IERC20(WTDOT);
        } else if (convertType == ConvertType.DOT2WTDOT) {
            require(address(shareType) == DOT, "share token must be DOT");

            uint256 tdotAmount = _convertDOT2TDOT(amount);
            convertAmount = _convertTDOT2WTDOT(tdotAmount);
            convert.convertedShareType = IERC20(WTDOT);
        } else {
            revert("unsupported convert");
        }

        uint256 exchangeRate = convertAmount.mul(1e18).div(amount);
        require(exchangeRate != 0, "exchange rate shouldn't be zero");
        convert.convertedExchangeRate = exchangeRate;
        emit LSTPoolConverted(poolId, shareType, convert.convertedShareType, amount, convertAmount);
    }

    /// @notice Stake `amount` share token to `poolId` pool. If pool has been converted, still stake before share token.
    /// @param poolId The index of staking pool.
    /// @param amount The amount of share token to stake.
    function stake(uint256 poolId, uint256 amount)
        public
        virtual
        override
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.Stake)
        updateRewards(poolId, msg.sender)
        nonReentrant
        returns (bool)
    {
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");

        uint256 addedShare;
        ConvertInfo memory convertInfo = convertInfos(poolId);
        if (address(convertInfo.convertedShareType) != address(0)) {
            // if pool has converted, transfer the before share token to this firstly
            shareType.safeTransferFrom(msg.sender, address(this), amount);

            uint256 convertedAmount;
            if (address(shareType) == LCDOT && address(convertInfo.convertedShareType) == LDOT) {
                convertedAmount = _convertLCDOT2LDOT(amount);
            } else if (address(shareType) == LCDOT && address(convertInfo.convertedShareType) == TDOT) {
                convertedAmount = _convertLCDOT2TDOT(amount);
            } else if (address(shareType) == DOT && address(convertInfo.convertedShareType) == LDOT) {
                convertedAmount = _convertDOT2LDOT(amount);
            } else if (address(shareType) == DOT && address(convertInfo.convertedShareType) == TDOT) {
                convertedAmount = _convertDOT2TDOT(amount);
            } else if (address(shareType) == LCDOT && address(convertInfo.convertedShareType) == WTDOT) {
                uint256 tdotAmount = _convertLCDOT2TDOT(amount);
                convertedAmount = _convertTDOT2WTDOT(tdotAmount);
            } else if (address(shareType) == DOT && address(convertInfo.convertedShareType) == WTDOT) {
                uint256 tdotAmount = _convertDOT2TDOT(amount);
                convertedAmount = _convertTDOT2WTDOT(tdotAmount);
            } else {
                revert("unsupported converted share token");
            }

            // must convert the share amount according to the exchange rate of converted pool
            addedShare = convertedAmount.mul(1e18).div(convertInfo.convertedExchangeRate);
        } else if (address(shareType) == WTDOT) {
            // transfer TDOT to this, convert it to WTDOT and stake it
            IERC20(TDOT).safeTransferFrom(msg.sender, address(this), amount);
            addedShare = _convertTDOT2WTDOT(amount);
        } else {
            // if pool hasn't converted, stake it directly
            shareType.safeTransferFrom(msg.sender, address(this), amount);
            addedShare = amount;
        }

        require(addedShare > 0, "cannot stake 0");
        _totalShares[poolId] = _totalShares[poolId].add(addedShare);
        _shares[poolId][msg.sender] = _shares[poolId][msg.sender].add(addedShare);

        emit Stake(msg.sender, poolId, addedShare);

        return true;
    }

    /// @notice Unstake `amount` share token from `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param amount The share token amount to unstake. If pool has been converted, it's converted share token amount, not the share amount.
    /// @return Returns (success).
    function unstake(uint256 poolId, uint256 amount)
        public
        virtual
        override
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.Unstake)
        updateRewards(poolId, msg.sender)
        nonReentrant
        returns (bool)
    {
        require(amount > 0, "cannot unstake 0");
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");
        require(_shares[poolId][msg.sender] >= amount, "share not enough");

        _totalShares[poolId] = _totalShares[poolId].sub(amount);
        _shares[poolId][msg.sender] = _shares[poolId][msg.sender].sub(amount);

        ConvertInfo memory convertInfo = convertInfos(poolId);
        if (address(convertInfo.convertedShareType) != address(0)) {
            uint256 convertedAmount = amount.mul(convertInfo.convertedExchangeRate).div(1e18);
            require(convertedAmount != 0, "shouldn't be zero");

            if (address(convertInfo.convertedShareType) == WTDOT) {
                uint256 tdotAmount = _convertWTDOT2TDOT(convertedAmount);
                IERC20(TDOT).safeTransfer(msg.sender, tdotAmount);
            } else {
                convertInfo.convertedShareType.safeTransfer(msg.sender, convertedAmount);
            }
        } else if (address(shareType) == WTDOT) {
            uint256 tdotAmount = _convertWTDOT2TDOT(amount);
            IERC20(TDOT).safeTransfer(msg.sender, tdotAmount);
        } else {
            shareType.safeTransfer(msg.sender, amount);
        }

        emit Unstake(msg.sender, poolId, amount);

        return true;
    }
}

/// @title ILSTConvert Interface
/// @author Acala Developers
/// @notice You can use this convertor to convert token into LST.
interface ILSTConvert {
    /// @notice Get the input token type of this convertor.
    /// @return Returns (inputToken).
    function inputToken() external view returns (address);

    /// @notice Get the output token type of this convertor.
    /// @return Returns (outputToken).
    function outputToken() external view returns (address);

    /// @notice Convert `inputAmount` token.
    /// @param inputAmount The input token amount to convert.
    /// @return Returns (outputTokenAmount).
    function convert(uint256 inputAmount) external returns (uint256);

    /// @notice Convert `inputAmount` token and send output token to `receiver`.
    /// @param inputAmount The input token amount to convert.
    /// @param receiver The receiver for the converted output token.
    /// @return Returns Output token amount.
    function convertTo(
        uint256 inputAmount,
        address receiver
    ) external returns (uint256);
}

/// @title UpgradeableStakingLSTV2 Contract
/// @author Acala Developers
/// @notice This staking contract can convert the share token to it's LST. It just support LcDOT token on Acala.
/// @dev After pool's share is converted into its LST token, this pool can be staked with LST token and before token both.
/// This version conforms to the specification for upgradeable contracts.
contract UpgradeableStakingLSTV2 is UpgradeableStakingLST, IStakingTo {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    /// @dev The LST convertor of pool.
    /// (poolId => ILSTConvert)
    mapping(uint256 => ILSTConvert) private _poolConvertors;

    /// @notice Get the LST convertor of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @return Returns convertor address.
    function poolConvertors(uint256 poolId) public view returns (ILSTConvert) {
        return _poolConvertors[poolId];
    }

    /// @notice Reset the `convertor` as the convertor of `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param convertor The LST convertor.
    function resetPoolConvertor(uint256 poolId, ILSTConvert convertor) public onlyOwner whenNotPaused {
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");
        IERC20 convertedShareTypes = convertInfos(poolId).convertedShareType;
        require(address(convertedShareTypes) != address(0), "pool must be already converted");

        require(
            convertor.inputToken() == address(shareType) && convertor.outputToken() == address(convertedShareTypes),
            "convertor is not matched"
        );

        _poolConvertors[poolId] = convertor;
    }

    /// @notice convert the share token of ‘poolId’ pool to LST token by `convertType`.
    /// @param poolId The index of staking pool.
    /// @param convertType The convert type.
    /// @dev override to depracate it.
    function convertLSTPool(uint256 poolId, ConvertType convertType)
        external
        virtual
        override
        onlyOwner
        whenNotPaused
    {
        revert("deprecated");
    }

    /// @notice convert the share token of ‘poolId’ pool to LST token by `convertor`.
    /// @param poolId The index of staking pool.
    /// @param convertor The convert contract address.
    function convertLSTPool(uint256 poolId, ILSTConvert convertor) external virtual onlyOwner whenNotPaused {
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");
        ConvertInfo storage convert = _convertInfos[poolId];
        require(address(convert.convertedShareType) == address(0), "already converted");

        uint256 amount = totalShares(poolId);
        require(amount > 0, "pool is empty");

        require(convertor.inputToken() == address(shareType), "convertor is not matched");

        shareType.safeApprove(address(convertor), amount);
        uint256 convertAmount = convertor.convert(amount);

        uint256 exchangeRate = convertAmount.mul(1e18).div(amount);
        require(exchangeRate != 0, "exchange rate shouldn't be zero");

        convert.convertedExchangeRate = exchangeRate;
        convert.convertedShareType = IERC20(convertor.outputToken());
        _poolConvertors[poolId] = convertor;

        emit LSTPoolConverted(poolId, shareType, convert.convertedShareType, amount, convertAmount);
    }

    function _stakeTo(uint256 poolId, uint256 amount, address receiver) internal returns (bool) {
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");
        uint256 addedShare;
        ConvertInfo memory convertInfo = convertInfos(poolId);
        if (address(convertInfo.convertedShareType) != address(0)) {
            ILSTConvert convertor = poolConvertors(poolId);
            require(address(convertor) != address(0), "pool convertor is not set");

            // if pool has converted, transfer the before share token to this firstly
            shareType.safeTransferFrom(msg.sender, address(this), amount);

            // convert share
            shareType.safeApprove(address(convertor), amount);
            uint256 convertedAmount = convertor.convert(amount);

            // must convert the share amount according to the exchange rate of converted pool
            addedShare = convertedAmount.mul(1e18).div(convertInfo.convertedExchangeRate);
        } else {
            // if pool hasn't converted, stake it directly
            shareType.safeTransferFrom(msg.sender, address(this), amount);
            addedShare = amount;
        }

        require(addedShare > 0, "cannot stake 0");
        _totalShares[poolId] = _totalShares[poolId].add(addedShare);
        _shares[poolId][receiver] = _shares[poolId][receiver].add(addedShare);

        emit Stake(receiver, poolId, addedShare);

        return true;
    }

    /// @notice Stake `amount` share token to `poolId` pool. If pool has been converted, still stake before share token.
    /// @param poolId The index of staking pool.
    /// @param amount The amount of share token to stake.
    function stake(uint256 poolId, uint256 amount)
        public
        virtual
        override(IStaking, UpgradeableStakingLST)
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.Stake)
        updateRewards(poolId, msg.sender)
        nonReentrant
        returns (bool)
    {
        return _stakeTo(poolId, amount, msg.sender);
    }

    /// @inheritdoc IStakingTo
    function stakeTo(uint256 poolId, uint256 amount, address receiver)
        public
        virtual
        override
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.Stake)
        updateRewards(poolId, receiver)
        nonReentrant
        returns (bool)
    {
        require(receiver != address(0), "invalid receiver");
        return _stakeTo(poolId, amount, receiver);
    }

    /// @notice Unstake `amount` share token from `poolId` pool.
    /// @param poolId The index of staking pool.
    /// @param amount The share token amount to unstake. If pool has been converted, it's converted share token amount, not the share amount.
    /// @return Returns (success).
    function unstake(uint256 poolId, uint256 amount)
        public
        virtual
        override(IStaking, UpgradeableStakingLST)
        whenNotPaused
        poolOperationNotPaused(poolId, Operation.Unstake)
        updateRewards(poolId, msg.sender)
        nonReentrant
        returns (bool)
    {
        require(amount > 0, "cannot unstake 0");
        IERC20 shareType = shareTypes(poolId);
        require(address(shareType) != address(0), "invalid pool");
        require(_shares[poolId][msg.sender] >= amount, "share not enough");

        _totalShares[poolId] = _totalShares[poolId].sub(amount);
        _shares[poolId][msg.sender] = _shares[poolId][msg.sender].sub(amount);

        ConvertInfo memory convertInfo = convertInfos(poolId);
        if (address(convertInfo.convertedShareType) != address(0)) {
            uint256 convertedAmount = amount.mul(convertInfo.convertedExchangeRate).div(1e18);
            require(convertedAmount != 0, "shouldn't be zero");

            convertInfo.convertedShareType.safeTransfer(msg.sender, convertedAmount);
        } else {
            shareType.safeTransfer(msg.sender, amount);
        }

        emit Unstake(msg.sender, poolId, amount);

        return true;
    }
}
        

Contract ABI

[{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"DOT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"HOMA","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"HOMA_MINT_THRESHOLD","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"LCDOT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"LDOT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"LIQUID_CROWDLOAN","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAX_REWARD_TYPES","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"STABLE_ASSET","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"TDOT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"WTDOT","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addPool","inputs":[{"type":"address","name":"shareType","internalType":"contract IERC20"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"claimRewards","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct UpgradeableStakingLST.ConvertInfo","components":[{"type":"address"},{"type":"uint256"}]}],"name":"convertInfos","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"convertLSTPool","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"uint8","name":"convertType","internalType":"enum UpgradeableStakingLST.ConvertType"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"convertLSTPool","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"convertor","internalType":"contract ILSTConvert"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"earned","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"who","internalType":"address"},{"type":"address","name":"rewardType","internalType":"contract IERC20"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"exit","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"dot","internalType":"address"},{"type":"address","name":"lcdot","internalType":"address"},{"type":"address","name":"ldot","internalType":"address"},{"type":"address","name":"tdot","internalType":"address"},{"type":"address","name":"homa","internalType":"address"},{"type":"address","name":"stableAsset","internalType":"address"},{"type":"address","name":"liquidCrowdloan","internalType":"address"},{"type":"address","name":"wtdot","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastTimeRewardApplicable","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"rewardType","internalType":"contract IERC20"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"paidAccumulatedRates","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"who","internalType":"address"},{"type":"address","name":"rewardType","internalType":"contract IERC20"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"pausedPoolOperations","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"uint8","name":"operation","internalType":"enum PoolOperationPausable.Operation"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ILSTConvert"}],"name":"poolConvertors","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"poolIndex","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"resetPoolConvertor","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"convertor","internalType":"contract ILSTConvert"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rewardPerShare","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"rewardType","internalType":"contract IERC20"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct Staking.RewardRule","components":[{"type":"uint256"},{"type":"uint256"},{"type":"uint256"},{"type":"uint256"}]}],"name":"rewardRules","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"rewardType","internalType":"contract IERC20"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"","internalType":"contract IERC20[]"}],"name":"rewardTypes","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rewards","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"who","internalType":"address"},{"type":"address","name":"rewardType","internalType":"contract IERC20"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rewardsDeductionRates","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPoolOperationPause","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"uint8","name":"operation","internalType":"enum PoolOperationPausable.Operation"},{"type":"bool","name":"paused","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setRewardsDeductionRate","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"uint256","name":"rate","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC20"}],"name":"shareTypes","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"shares","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"who","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"stake","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"stakeTo","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"receiver","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalShares","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"unstake","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateRewardRule","inputs":[{"type":"uint256","name":"poolId","internalType":"uint256"},{"type":"address","name":"rewardType","internalType":"contract IERC20"},{"type":"uint256","name":"rewardRate","internalType":"uint256"},{"type":"uint256","name":"endTime","internalType":"uint256"}]},{"type":"event","name":"ClaimReward","inputs":[{"type":"address","name":"sender","indexed":true},{"type":"uint256","name":"poolId","indexed":false},{"type":"address","name":"rewardType","indexed":true},{"type":"uint256","name":"amount","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","indexed":false}],"anonymous":false},{"type":"event","name":"LSTPoolConverted","inputs":[{"type":"uint256","name":"poolId","indexed":false},{"type":"address","name":"beforeShareType","indexed":false},{"type":"address","name":"afterShareType","indexed":false},{"type":"uint256","name":"beforeShareTokenAmount","indexed":false},{"type":"uint256","name":"afterShareTokenAmount","indexed":false}],"anonymous":false},{"type":"event","name":"NewPool","inputs":[{"type":"uint256","name":"poolId","indexed":false},{"type":"address","name":"shareType","indexed":false}],"anonymous":false},{"type":"event","name":"OperationPauseStatusSet","inputs":[{"type":"uint256","name":"poolId","indexed":false},{"type":"uint8","name":"operation","indexed":false},{"type":"bool","name":"paused","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","indexed":true},{"type":"address","name":"newOwner","indexed":true}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","indexed":false}],"anonymous":false},{"type":"event","name":"RewardRuleUpdate","inputs":[{"type":"uint256","name":"poolId","indexed":false},{"type":"address","name":"rewardType","indexed":false},{"type":"uint256","name":"rewardRate","indexed":false},{"type":"uint256","name":"endTime","indexed":false}],"anonymous":false},{"type":"event","name":"RewardsDeductionRateSet","inputs":[{"type":"uint256","name":"poolId","indexed":false},{"type":"uint256","name":"rate","indexed":false}],"anonymous":false},{"type":"event","name":"Stake","inputs":[{"type":"address","name":"sender","indexed":true},{"type":"uint256","name":"poolId","indexed":false},{"type":"uint256","name":"amount","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","indexed":false}],"anonymous":false},{"type":"event","name":"Unstake","inputs":[{"type":"address","name":"sender","indexed":true},{"type":"uint256","name":"poolId","indexed":false},{"type":"uint256","name":"amount","indexed":false}],"anonymous":false}]
              

Contract Creation Code

Verify & Publish
0x6080604052600060975534801561001557600080fd5b50613891806100256000396000f3fe608060405234801561001057600080fd5b506004361061027f5760003560e01c80637f8661a11161015c578063abdd0517116100ce578063d914cd4b11610087578063d914cd4b14610615578063e61dd13314610628578063ebf4168714610630578063ef1280a214610643578063f2fde38b14610656578063f924d3ef1461066957600080fd5b8063abdd051714610596578063c45c08ed146105a9578063c5a8f021146105bc578063c643365f146105cf578063cfe68703146105e2578063d58df9b6146105f557600080fd5b806388b494091161012057806388b49409146105265780638a29e2de146105395780638da5cb5b1461054c5780639248519f1461055d5780639e2c8a5b14610570578063a355569d1461058357600080fd5b80637f8661a1146104e55780638129fc1c1461042757806382481d49146104f857806382b87a191461050b5780638456cb591461051e57600080fd5b80633f4ba83a116101f55780635c975abb116101b95780635c975abb146104795780636022c7ab14610484578063715018a61461049757806373ddc5eb1461049f578063782ed591146104bf5780637b0472f0146104d257600080fd5b80633f4ba83a1461041f578063430855b5146104295780634665f3ee146104525780634ce272ee146104655780635091d96c1461046d57600080fd5b80631408cdf4116102475780631408cdf41461032b5780631c1b99581461033e578063271283cb14610351578063307a8c30146103885780633406962f146103ce57806336e029501461040c57600080fd5b80630962ef79146102845780630bea593a146102ac5780630ded29eb146102d757806311b74f94146102f857806313f2dad01461030b575b600080fd5b6102976102923660046132e6565b61067c565b60405190151581526020015b60405180910390f35b60d4546102bf906001600160a01b031681565b6040516001600160a01b0390911681526020016102a3565b6102ea6102e5366004613314565b6106dd565b6040519081526020016102a3565b6102ea610306366004613356565b610773565b6102ea6103193660046132e6565b60009081526099602052604090205490565b60da546102bf906001600160a01b031681565b60d6546102bf906001600160a01b031681565b61036461035f3660046132e6565b6107f5565b6040805182516001600160a01b0316815260209283015192810192909252016102a3565b61039b610396366004613356565b61083c565b6040516102a391908151815260208083015190820152604080830151908201526060918201519181019190915260800190565b6102ea6103dc366004613314565b6000928352609f602090815260408085206001600160a01b03948516865282528085209290931684525290205490565b60d3546102bf906001600160a01b031681565b6104276108be565b005b6102bf6104373660046132e6565b600090815260dc60205260409020546001600160a01b031690565b60d7546102bf906001600160a01b031681565b6097546102ea565b6102ea640ba43b740081565b60655460ff16610297565b60d5546102bf906001600160a01b031681565b6104276108d0565b6104b26104ad3660046132e6565b6108e2565b6040516102a39190613386565b6104276104cd3660046133d3565b61094e565b6102976104e03660046133d3565b61096c565b6102976104f33660046132e6565b610bae565b6102ea610506366004613356565b610bd1565b610427610519366004613417565b610bf9565b610427610c19565b6102ea610534366004613314565b610c29565b61042761054736600461344c565b610c59565b6033546001600160a01b03166102bf565b61042761056b3660046134f5565b611077565b61029761057e3660046133d3565b611099565b610297610591366004613532565b6114c9565b6102ea6105a4366004613356565b611516565b60d9546102bf906001600160a01b031681565b6104276105ca36600461355e565b611540565b6104276105dd366004613356565b611585565b6102bf6105f03660046132e6565b61191a565b6102ea6106033660046132e6565b6000908152609a602052604090205490565b610427610623366004613587565b611935565b6102ea600381565b61029761063e3660046135a4565b611951565b60d8546102bf906001600160a01b031681565b610427610664366004613587565b611bb6565b610427610677366004613356565b611c2c565b6000610686611e3e565b81600261069382826114c9565b156106b95760405162461bcd60e51b81526004016106b0906135d2565b60405180910390fd5b6106c1611e84565b6106ca84611edd565b92506106d6600160a155565b5050919050565b6000806106ea8585610bd1565b905060006106f9868686610c29565b6000878152609f602090815260408083206001600160a01b038a81168552908352818420908916845290915281205491925061075b670de0b6b3a764000061075561074e856107488d8c610773565b906122f4565b8790612307565b90612313565b9050610767838261231f565b98975050505050505050565b600080610780848461083c565b6000858152609960205260408120549192508190036107a557506040015190506107ef565b60006107d782610755670de0b6b3a76400006107d187600001516107d189606001516107488e8e611516565b90612307565b60408401519091506107e9908261231f565b93505050505b92915050565b604080518082019091526000808252602082015250600090815260db6020908152604091829020825180840190935280546001600160a01b03168352600101549082015290565b6108676040518060800160405280600081526020016000815260200160008152602001600081525090565b506000918252609c602090815260408084206001600160a01b039390931684529181529181902081516080810183528154815260018201549381019390935260028101549183019190915260030154606082015290565b6108c661232b565b6108ce612385565b565b6108d861232b565b6108ce60006123d7565b6000818152609b602090815260409182902080548351818402810184019094528084526060939283018282801561094257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610924575b50505050509050919050565b61095661232b565b61095e611e3e565b6109688282612429565b5050565b6000610976611e3e565b82600061098382826114c9565b156109a05760405162461bcd60e51b81526004016106b0906135d2565b843360006109ad836108e2565b905060005b8151811015610b83576000848152609c60205260408120835182908590859081106109df576109df61362f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050610a2c85848481518110610a1f57610a1f61362f565b6020026020010151610773565b8160020181905550610a5785848481518110610a4a57610a4a61362f565b6020026020010151611516565b60038201556001600160a01b03841615610b7057610a8f8585858581518110610a8257610a8261362f565b60200260200101516106dd565b6000868152609e602090815260408083206001600160a01b038916845290915281208551909190869086908110610ac857610ac861362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b031681526020019081526020016000206000858581518110610b4357610b4361362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b5080610b7b8161365b565b9150506109b2565b50610b8c611e84565b610b978888336124f1565b9550610ba3600160a155565b505050505092915050565b6000610bbe8261057e8433610bd1565b50610bc88261067c565b50600192915050565b6000918252609d602090815260408084206001600160a01b0393909316845291905290205490565b610c0161232b565b610c09611e3e565b610c1483838361277e565b505050565b610c2161232b565b6108ce612816565b6000928352609e602090815260408085206001600160a01b03948516865282528085209290931684525290205490565b600054610100900460ff1615808015610c795750600054600160ff909116105b80610c935750303b158015610c93575060005460ff166001145b610cf65760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016106b0565b6000805460ff191660011790558015610d19576000805461ff0019166101001790555b6001600160a01b038916610d655760405162461bcd60e51b8152602060048201526013602482015272444f542061646472657373206973207a65726f60681b60448201526064016106b0565b6001600160a01b038816610db35760405162461bcd60e51b81526020600482015260156024820152746c43444f542061646472657373206973207a65726f60581b60448201526064016106b0565b6001600160a01b038716610e005760405162461bcd60e51b81526020600482015260146024820152734c444f542061646472657373206973207a65726f60601b60448201526064016106b0565b6001600160a01b038616610e4d5760405162461bcd60e51b815260206004820152601460248201527354444f542061646472657373206973207a65726f60601b60448201526064016106b0565b6001600160a01b038516610e9a5760405162461bcd60e51b8152602060048201526014602482015273484f4d412061646472657373206973207a65726f60601b60448201526064016106b0565b6001600160a01b038416610ef05760405162461bcd60e51b815260206004820152601c60248201527f535441424c455f41535345542061646472657373206973207a65726f0000000060448201526064016106b0565b6001600160a01b038316610f465760405162461bcd60e51b815260206004820181905260248201527f4c49515549445f43524f57444c4f414e2061646472657373206973207a65726f60448201526064016106b0565b6001600160a01b038216610f945760405162461bcd60e51b81526020600482015260156024820152745754444f542061646472657373206973207a65726f60581b60448201526064016106b0565b60d380546001600160a01b03199081166001600160a01b038c81169190911790925560d4805482168b841617905560d5805482168a841617905560d68054821689841617905560d78054821688841617905560d88054821687841617905560d98054821686841617905560da8054909116918416919091179055611016612853565b61101e612882565b6110266128b1565b801561106c576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050505050565b61107f61232b565b611087611e3e565b611093848484846128e0565b50505050565b60006110a3611e3e565b8260016110b082826114c9565b156110cd5760405162461bcd60e51b81526004016106b0906135d2565b843360006110da836108e2565b905060005b8151811015611289576000848152609c602052604081208351829085908590811061110c5761110c61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020905061114c85848481518110610a1f57610a1f61362f565b816002018190555061116a85848481518110610a4a57610a4a61362f565b60038201556001600160a01b03841615611276576111958585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b0389168452909152812085519091908690869081106111ce576111ce61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b0316815260200190815260200160002060008585815181106112495761124961362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b50806112818161365b565b9150506110df565b50611292611e84565b600087116112d55760405162461bcd60e51b815260206004820152601060248201526f063616e6e6f7420756e7374616b6520360841b60448201526064016106b0565b60006112e08961191a565b90506001600160a01b0381166113085760405162461bcd60e51b81526004016106b090613674565b6000898152609d602090815260408083203384529091529020548811156113645760405162461bcd60e51b815260206004820152601060248201526f0e6d0c2e4ca40dcdee840cadcdeeaced60831b60448201526064016106b0565b60008981526099602052604090205461137d90896122f4565b60008a815260996020908152604080832093909355609d8152828220338352905220546113aa90896122f4565b60008a8152609d602090815260408083203384529091528120919091556113d08a6107f5565b80519091506001600160a01b03161561146a576000611408670de0b6b3a764000061075584602001518d61230790919063ffffffff16565b90508060000361144e5760405162461bcd60e51b815260206004820152601160248201527073686f756c646e2774206265207a65726f60781b60448201526064016106b0565b8151611464906001600160a01b03163383612d95565b5061147e565b61147e6001600160a01b038316338b612d95565b604080518b8152602081018b905233917ff960dbf9e5d0682f7a298ed974e33a28b4464914b7a2bfac12ae419a9afeb280910160405180910390a2600197505050610ba3600160a155565b600082815260a060205260408120818360028111156114ea576114ea61369a565b60028111156114fb576114fb61369a565b815260208101919091526040016000205460ff169392505050565b600080611523848461083c565b6020015190508042106115365780611538565b425b949350505050565b61154861232b565b611550611e3e565b60405162461bcd60e51b815260206004820152600a60248201526919195c1c9958d85d195960b21b60448201526064016106b0565b61158d61232b565b611595611e3e565b60006115a08361191a565b90506001600160a01b0381166115c85760405162461bcd60e51b81526004016106b090613674565b600083815260db6020526040902080546001600160a01b0316156116225760405162461bcd60e51b8152602060048201526011602482015270185b1c9958591e4818dbdb9d995c9d1959607a1b60448201526064016106b0565b6000848152609960205260409020548061166e5760405162461bcd60e51b815260206004820152600d60248201526c706f6f6c20697320656d70747960981b60448201526064016106b0565b826001600160a01b0316846001600160a01b03166301b60ef26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116da91906136b0565b6001600160a01b03161461172b5760405162461bcd60e51b815260206004820152601860248201527718dbdb9d995c9d1bdc881a5cc81b9bdd081b585d18da195960421b60448201526064016106b0565b61173f6001600160a01b0384168583612df8565b60405163a3908e1b60e01b8152600481018290526000906001600160a01b0386169063a3908e1b906024016020604051808303816000875af1158015611789573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117ad91906136cd565b905060006117c78361075584670de0b6b3a7640000612307565b9050806000036118195760405162461bcd60e51b815260206004820152601f60248201527f65786368616e676520726174652073686f756c646e2774206265207a65726f0060448201526064016106b0565b808460010181905550856001600160a01b031663c1d8d1d96040518163ffffffff1660e01b8152600401602060405180830381865afa158015611860573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188491906136b0565b84546001600160a01b03199081166001600160a01b03928316178655600089815260dc602090815260409182902080549093168a851617909255865481518b81528985169381019390935290921681830152606081018590526080810184905290517f7357bdf6439eb71d76705f65b579405009821f85cd9c27520fe6bca4d2707bae9160a0908290030190a150505050505050565b6000908152609860205260409020546001600160a01b031690565b61193d61232b565b611945611e3e565b61194e81612f0d565b50565b600061195b611e3e565b83600061196882826114c9565b156119855760405162461bcd60e51b81526004016106b0906135d2565b85846000611992836108e2565b905060005b8151811015611b41576000848152609c60205260408120835182908590859081106119c4576119c461362f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050611a0485848481518110610a1f57610a1f61362f565b8160020181905550611a2285848481518110610a4a57610a4a61362f565b60038201556001600160a01b03841615611b2e57611a4d8585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b038916845290915281208551909190869086908110611a8657611a8661362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b031681526020019081526020016000206000858581518110611b0157611b0161362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b5080611b398161365b565b915050611997565b50611b4a611e84565b6001600160a01b038716611b935760405162461bcd60e51b815260206004820152601060248201526f34b73b30b634b2103932b1b2b4bb32b960811b60448201526064016106b0565b611b9e8989896124f1565b9550611baa600160a155565b50505050509392505050565b611bbe61232b565b6001600160a01b038116611c235760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016106b0565b61194e816123d7565b611c3461232b565b611c3c611e3e565b6000611c478361191a565b90506001600160a01b038116611c6f5760405162461bcd60e51b81526004016106b090613674565b6000611c7a846107f5565b5190506001600160a01b038116611cd35760405162461bcd60e51b815260206004820152601e60248201527f706f6f6c206d75737420626520616c726561647920636f6e766572746564000060448201526064016106b0565b816001600160a01b0316836001600160a01b03166301b60ef26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3f91906136b0565b6001600160a01b0316148015611dc75750806001600160a01b0316836001600160a01b031663c1d8d1d96040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dbc91906136b0565b6001600160a01b0316145b611e0e5760405162461bcd60e51b815260206004820152601860248201527718dbdb9d995c9d1bdc881a5cc81b9bdd081b585d18da195960421b60448201526064016106b0565b5050600091825260dc602052604090912080546001600160a01b0319166001600160a01b03909216919091179055565b60655460ff16156108ce5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016106b0565b600260a15403611ed65760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016106b0565b600260a155565b600081336000611eec836108e2565b905060005b815181101561209b576000848152609c6020526040812083518290859085908110611f1e57611f1e61362f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050611f5e85848481518110610a1f57610a1f61362f565b8160020181905550611f7c85848481518110610a4a57610a4a61362f565b60038201556001600160a01b0384161561208857611fa78585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b038916845290915281208551909190869086908110611fe057611fe061362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b03168152602001908152602001600020600085858151811061205b5761205b61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b50806120938161365b565b915050611ef1565b5060006120a7866108e2565b6000878152609a60205260408120549192505b82518110156122df5760006120e989338685815181106120dc576120dc61362f565b6020026020010151610c29565b905080156122ce576000898152609e602090815260408083203384529091528120855182908790869081106121205761212061362f565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002081905550600061216d670de0b6b3a7640000610755868561230790919063ffffffff16565b9050600061217b83836122f4565b905081156122255760008b8152609c60205260408120875182908990889081106121a7576121a761362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020905060006121e98d60009081526099602052604090205490565b905080156122225760006122098261075587670de0b6b3a7640000612307565b600284015490915061221b908261231f565b6002840155505b50505b61225c338288878151811061223c5761223c61362f565b60200260200101516001600160a01b0316612d959092919063ffffffff16565b85848151811061226e5761226e61362f565b60200260200101516001600160a01b0316336001600160a01b03167f3ca11272227262090da5effe1aab9b06d2418af179ea41c876a68b186c73cc208d846040516122c3929190918252602082015260400190565b60405180910390a350505b506122d88161365b565b90506120ba565b506001979650505050505050565b600160a155565b600061230082846136e6565b9392505050565b600061230082846136f9565b60006123008284613710565b60006123008284613732565b6033546001600160a01b031633146108ce5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016106b0565b61238d612fe3565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006124348361191a565b6001600160a01b03160361245a5760405162461bcd60e51b81526004016106b090613674565b670de0b6b3a76400008111156124a15760405162461bcd60e51b815260206004820152600c60248201526b696e76616c6964207261746560a01b60448201526064016106b0565b6000828152609a602090815260409182902083905581518481529081018390527fb7232ad8c7b793eeaae7f80539cf2d5bb40ae19b3afaa25ea24fa3e4279a369e91015b60405180910390a15050565b6000806124fd8561191a565b90506001600160a01b0381166125255760405162461bcd60e51b81526004016106b090613674565b600080612531876107f5565b80519091506001600160a01b03161561266757600087815260dc60205260409020546001600160a01b0316806125a95760405162461bcd60e51b815260206004820152601960248201527f706f6f6c20636f6e766572746f72206973206e6f74207365740000000000000060448201526064016106b0565b6125be6001600160a01b03851633308a61302c565b6125d26001600160a01b0385168289612df8565b60405163a3908e1b60e01b8152600481018890526000906001600160a01b0383169063a3908e1b906024016020604051808303816000875af115801561261c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061264091906136cd565b602084015190915061265e9061075583670de0b6b3a7640000612307565b93505050612680565b61267c6001600160a01b03841633308961302c565b8591505b600082116126c15760405162461bcd60e51b815260206004820152600e60248201526d063616e6e6f74207374616b6520360941b60448201526064016106b0565b6000878152609960205260409020546126da908361231f565b600088815260996020908152604080832093909355609d81528282206001600160a01b038916835290522054612710908361231f565b6000888152609d602090815260408083206001600160a01b038a16808552908352928190209390935582518a815290810185905290917f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b6910160405180910390a25060019695505050505050565b600083815260a06020526040812082918460028111156127a0576127a061369a565b60028111156127b1576127b161369a565b815260200190815260200160002060006101000a81548160ff0219169083151502179055507f72456f11997c4141186829babc53f5f329ed7d5166fd80affcebd3114dcaf90383838360405161280993929190613745565b60405180910390a1505050565b61281e611e3e565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586123ba3390565b600054610100900460ff1661287a5760405162461bcd60e51b81526004016106b090613780565b6108ce613064565b600054610100900460ff166128a95760405162461bcd60e51b81526004016106b090613780565b6108ce613097565b600054610100900460ff166128d85760405162461bcd60e51b81526004016106b090613780565b6108ce6130c7565b836000806128ed836108e2565b905060005b8151811015612a9c576000848152609c602052604081208351829085908590811061291f5761291f61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020905061295f85848481518110610a1f57610a1f61362f565b816002018190555061297d85848481518110610a4a57610a4a61362f565b60038201556001600160a01b03841615612a89576129a88585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b0389168452909152812085519091908690869081106129e1576129e161362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b031681526020019081526020016000206000858581518110612a5c57612a5c61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b5080612a948161365b565b9150506128f2565b506001600160a01b038616612af35760405162461bcd60e51b815260206004820152601c60248201527f72657761726420746f6b656e206973207a65726f20616464726573730000000060448201526064016106b0565b6000612afe8861191a565b6001600160a01b031603612b4b5760405162461bcd60e51b81526020600482015260146024820152731c1bdbdb081b5d5cdd08189948195e1a5cdd195960621b60448201526064016106b0565b6000612b56886108e2565b9050600160005b8251811015612bb357886001600160a01b0316838281518110612b8257612b8261362f565b60200260200101516001600160a01b031603612ba15760009150612bb3565b80612bab8161365b565b915050612b5d565b508015612bf2576000898152609b602090815260408220805460018101825590835291200180546001600160a01b0319166001600160a01b038a161790555b6000898152609b602052604090205460031015612c495760405162461bcd60e51b8152602060048201526015602482015274746f6f206d616e792072657761726420747970657360581b60448201526064016106b0565b6000898152609c602090815260408083206001600160a01b038c1684529091528120426003820181905560018201549192911115612c9f57815460038301546001840154612c9c92916107d191906122f4565b90505b87421115612cb257426001830155612cba565b600182018890555b88825560038201546001830154600091612cda918c916107d191906122f4565b905080821015612d0a57612d053330612cf384866122f4565b6001600160a01b038f1692919061302c565b612d31565b80821115612d3157612d3133612d2084846122f4565b6001600160a01b038e169190612d95565b82546001840154604080518f81526001600160a01b038f1660208201529081019290925260608201527f560be8033bbe7cd2b35cc61f8150821a44ced377dc74a650a0dea24d49693c9a9060800160405180910390a1505050505050505050505050565b6040516001600160a01b038316602482015260448101829052610c1490849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526130ee565b801580612e725750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015612e4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7091906136cd565b155b612edd5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016106b0565b6040516001600160a01b038316602482015260448101829052610c1490849063095ea7b360e01b90606401612dc1565b6001600160a01b038116612f635760405162461bcd60e51b815260206004820152601b60248201527f736861726520746f6b656e206973207a65726f2061646472657373000000000060448201526064016106b0565b6000612f6e60975490565b600081815260986020526040902080546001600160a01b0319166001600160a01b0385161790559050612fa281600161231f565b609755604080518281526001600160a01b03841660208201527fcfdb757a17c7073437a01260a6760f5026efd70c96fb9a3f54d03c6ed2c372c391016124e5565b60655460ff166108ce5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016106b0565b6040516001600160a01b03808516602483015283166044820152606481018290526110939085906323b872dd60e01b90608401612dc1565b600054610100900460ff1661308b5760405162461bcd60e51b81526004016106b090613780565b6065805460ff19169055565b600054610100900460ff166130be5760405162461bcd60e51b81526004016106b090613780565b6108ce336123d7565b600054610100900460ff166122ed5760405162461bcd60e51b81526004016106b090613780565b6000613143826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166131c39092919063ffffffff16565b905080516000148061316457508080602001905181019061316491906137cb565b610c145760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016106b0565b6060611538848460008585600080866001600160a01b031685876040516131ea919061380c565b60006040518083038185875af1925050503d8060008114613227576040519150601f19603f3d011682016040523d82523d6000602084013e61322c565b606091505b509150915061323d87838387613248565b979650505050505050565b606083156132b75782516000036132b0576001600160a01b0385163b6132b05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016106b0565b5081611538565b61153883838151156132cc5781518083602001fd5b8060405162461bcd60e51b81526004016106b09190613828565b6000602082840312156132f857600080fd5b5035919050565b6001600160a01b038116811461194e57600080fd5b60008060006060848603121561332957600080fd5b83359250602084013561333b816132ff565b9150604084013561334b816132ff565b809150509250925092565b6000806040838503121561336957600080fd5b82359150602083013561337b816132ff565b809150509250929050565b6020808252825182820181905260009190848201906040850190845b818110156133c75783516001600160a01b0316835292840192918401916001016133a2565b50909695505050505050565b600080604083850312156133e657600080fd5b50508035926020909101359150565b80356003811061340457600080fd5b919050565b801515811461194e57600080fd5b60008060006060848603121561342c57600080fd5b8335925061343c602085016133f5565b9150604084013561334b81613409565b600080600080600080600080610100898b03121561346957600080fd5b8835613474816132ff565b97506020890135613484816132ff565b96506040890135613494816132ff565b955060608901356134a4816132ff565b945060808901356134b4816132ff565b935060a08901356134c4816132ff565b925060c08901356134d4816132ff565b915060e08901356134e4816132ff565b809150509295985092959890939650565b6000806000806080858703121561350b57600080fd5b84359350602085013561351d816132ff565b93969395505050506040820135916060013590565b6000806040838503121561354557600080fd5b82359150613555602084016133f5565b90509250929050565b6000806040838503121561357157600080fd5b8235915060208301356004811061337b57600080fd5b60006020828403121561359957600080fd5b8135612300816132ff565b6000806000606084860312156135b957600080fd5b8335925060208401359150604084013561334b816132ff565b60208082526038908201527f506f6f6c4f7065726174696f6e5061757361626c653a206f7065726174696f6e60408201527f2069732070617573656420666f72207468697320706f6f6c0000000000000000606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161366d5761366d613645565b5060010190565b6020808252600c908201526b1a5b9d985b1a59081c1bdbdb60a21b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b6000602082840312156136c257600080fd5b8151612300816132ff565b6000602082840312156136df57600080fd5b5051919050565b818103818111156107ef576107ef613645565b80820281158282048414176107ef576107ef613645565b60008261372d57634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156107ef576107ef613645565b838152606081016003841061376a57634e487b7160e01b600052602160045260246000fd5b8360208301528215156040830152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156137dd57600080fd5b815161230081613409565b60005b838110156138035781810151838201526020016137eb565b50506000910152565b6000825161381e8184602087016137e8565b9190910192915050565b60208152600082518060208401526138478160408501602087016137e8565b601f01601f1916919091016040019291505056fea2646970667358221220e7fede1b2d4d4ab3817d5ca353e049be2c0616b0cd0e004e4b54ecff1ea191d164736f6c63430008110033

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061027f5760003560e01c80637f8661a11161015c578063abdd0517116100ce578063d914cd4b11610087578063d914cd4b14610615578063e61dd13314610628578063ebf4168714610630578063ef1280a214610643578063f2fde38b14610656578063f924d3ef1461066957600080fd5b8063abdd051714610596578063c45c08ed146105a9578063c5a8f021146105bc578063c643365f146105cf578063cfe68703146105e2578063d58df9b6146105f557600080fd5b806388b494091161012057806388b49409146105265780638a29e2de146105395780638da5cb5b1461054c5780639248519f1461055d5780639e2c8a5b14610570578063a355569d1461058357600080fd5b80637f8661a1146104e55780638129fc1c1461042757806382481d49146104f857806382b87a191461050b5780638456cb591461051e57600080fd5b80633f4ba83a116101f55780635c975abb116101b95780635c975abb146104795780636022c7ab14610484578063715018a61461049757806373ddc5eb1461049f578063782ed591146104bf5780637b0472f0146104d257600080fd5b80633f4ba83a1461041f578063430855b5146104295780634665f3ee146104525780634ce272ee146104655780635091d96c1461046d57600080fd5b80631408cdf4116102475780631408cdf41461032b5780631c1b99581461033e578063271283cb14610351578063307a8c30146103885780633406962f146103ce57806336e029501461040c57600080fd5b80630962ef79146102845780630bea593a146102ac5780630ded29eb146102d757806311b74f94146102f857806313f2dad01461030b575b600080fd5b6102976102923660046132e6565b61067c565b60405190151581526020015b60405180910390f35b60d4546102bf906001600160a01b031681565b6040516001600160a01b0390911681526020016102a3565b6102ea6102e5366004613314565b6106dd565b6040519081526020016102a3565b6102ea610306366004613356565b610773565b6102ea6103193660046132e6565b60009081526099602052604090205490565b60da546102bf906001600160a01b031681565b60d6546102bf906001600160a01b031681565b61036461035f3660046132e6565b6107f5565b6040805182516001600160a01b0316815260209283015192810192909252016102a3565b61039b610396366004613356565b61083c565b6040516102a391908151815260208083015190820152604080830151908201526060918201519181019190915260800190565b6102ea6103dc366004613314565b6000928352609f602090815260408085206001600160a01b03948516865282528085209290931684525290205490565b60d3546102bf906001600160a01b031681565b6104276108be565b005b6102bf6104373660046132e6565b600090815260dc60205260409020546001600160a01b031690565b60d7546102bf906001600160a01b031681565b6097546102ea565b6102ea640ba43b740081565b60655460ff16610297565b60d5546102bf906001600160a01b031681565b6104276108d0565b6104b26104ad3660046132e6565b6108e2565b6040516102a39190613386565b6104276104cd3660046133d3565b61094e565b6102976104e03660046133d3565b61096c565b6102976104f33660046132e6565b610bae565b6102ea610506366004613356565b610bd1565b610427610519366004613417565b610bf9565b610427610c19565b6102ea610534366004613314565b610c29565b61042761054736600461344c565b610c59565b6033546001600160a01b03166102bf565b61042761056b3660046134f5565b611077565b61029761057e3660046133d3565b611099565b610297610591366004613532565b6114c9565b6102ea6105a4366004613356565b611516565b60d9546102bf906001600160a01b031681565b6104276105ca36600461355e565b611540565b6104276105dd366004613356565b611585565b6102bf6105f03660046132e6565b61191a565b6102ea6106033660046132e6565b6000908152609a602052604090205490565b610427610623366004613587565b611935565b6102ea600381565b61029761063e3660046135a4565b611951565b60d8546102bf906001600160a01b031681565b610427610664366004613587565b611bb6565b610427610677366004613356565b611c2c565b6000610686611e3e565b81600261069382826114c9565b156106b95760405162461bcd60e51b81526004016106b0906135d2565b60405180910390fd5b6106c1611e84565b6106ca84611edd565b92506106d6600160a155565b5050919050565b6000806106ea8585610bd1565b905060006106f9868686610c29565b6000878152609f602090815260408083206001600160a01b038a81168552908352818420908916845290915281205491925061075b670de0b6b3a764000061075561074e856107488d8c610773565b906122f4565b8790612307565b90612313565b9050610767838261231f565b98975050505050505050565b600080610780848461083c565b6000858152609960205260408120549192508190036107a557506040015190506107ef565b60006107d782610755670de0b6b3a76400006107d187600001516107d189606001516107488e8e611516565b90612307565b60408401519091506107e9908261231f565b93505050505b92915050565b604080518082019091526000808252602082015250600090815260db6020908152604091829020825180840190935280546001600160a01b03168352600101549082015290565b6108676040518060800160405280600081526020016000815260200160008152602001600081525090565b506000918252609c602090815260408084206001600160a01b039390931684529181529181902081516080810183528154815260018201549381019390935260028101549183019190915260030154606082015290565b6108c661232b565b6108ce612385565b565b6108d861232b565b6108ce60006123d7565b6000818152609b602090815260409182902080548351818402810184019094528084526060939283018282801561094257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610924575b50505050509050919050565b61095661232b565b61095e611e3e565b6109688282612429565b5050565b6000610976611e3e565b82600061098382826114c9565b156109a05760405162461bcd60e51b81526004016106b0906135d2565b843360006109ad836108e2565b905060005b8151811015610b83576000848152609c60205260408120835182908590859081106109df576109df61362f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050610a2c85848481518110610a1f57610a1f61362f565b6020026020010151610773565b8160020181905550610a5785848481518110610a4a57610a4a61362f565b6020026020010151611516565b60038201556001600160a01b03841615610b7057610a8f8585858581518110610a8257610a8261362f565b60200260200101516106dd565b6000868152609e602090815260408083206001600160a01b038916845290915281208551909190869086908110610ac857610ac861362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b031681526020019081526020016000206000858581518110610b4357610b4361362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b5080610b7b8161365b565b9150506109b2565b50610b8c611e84565b610b978888336124f1565b9550610ba3600160a155565b505050505092915050565b6000610bbe8261057e8433610bd1565b50610bc88261067c565b50600192915050565b6000918252609d602090815260408084206001600160a01b0393909316845291905290205490565b610c0161232b565b610c09611e3e565b610c1483838361277e565b505050565b610c2161232b565b6108ce612816565b6000928352609e602090815260408085206001600160a01b03948516865282528085209290931684525290205490565b600054610100900460ff1615808015610c795750600054600160ff909116105b80610c935750303b158015610c93575060005460ff166001145b610cf65760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016106b0565b6000805460ff191660011790558015610d19576000805461ff0019166101001790555b6001600160a01b038916610d655760405162461bcd60e51b8152602060048201526013602482015272444f542061646472657373206973207a65726f60681b60448201526064016106b0565b6001600160a01b038816610db35760405162461bcd60e51b81526020600482015260156024820152746c43444f542061646472657373206973207a65726f60581b60448201526064016106b0565b6001600160a01b038716610e005760405162461bcd60e51b81526020600482015260146024820152734c444f542061646472657373206973207a65726f60601b60448201526064016106b0565b6001600160a01b038616610e4d5760405162461bcd60e51b815260206004820152601460248201527354444f542061646472657373206973207a65726f60601b60448201526064016106b0565b6001600160a01b038516610e9a5760405162461bcd60e51b8152602060048201526014602482015273484f4d412061646472657373206973207a65726f60601b60448201526064016106b0565b6001600160a01b038416610ef05760405162461bcd60e51b815260206004820152601c60248201527f535441424c455f41535345542061646472657373206973207a65726f0000000060448201526064016106b0565b6001600160a01b038316610f465760405162461bcd60e51b815260206004820181905260248201527f4c49515549445f43524f57444c4f414e2061646472657373206973207a65726f60448201526064016106b0565b6001600160a01b038216610f945760405162461bcd60e51b81526020600482015260156024820152745754444f542061646472657373206973207a65726f60581b60448201526064016106b0565b60d380546001600160a01b03199081166001600160a01b038c81169190911790925560d4805482168b841617905560d5805482168a841617905560d68054821689841617905560d78054821688841617905560d88054821687841617905560d98054821686841617905560da8054909116918416919091179055611016612853565b61101e612882565b6110266128b1565b801561106c576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050505050565b61107f61232b565b611087611e3e565b611093848484846128e0565b50505050565b60006110a3611e3e565b8260016110b082826114c9565b156110cd5760405162461bcd60e51b81526004016106b0906135d2565b843360006110da836108e2565b905060005b8151811015611289576000848152609c602052604081208351829085908590811061110c5761110c61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020905061114c85848481518110610a1f57610a1f61362f565b816002018190555061116a85848481518110610a4a57610a4a61362f565b60038201556001600160a01b03841615611276576111958585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b0389168452909152812085519091908690869081106111ce576111ce61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b0316815260200190815260200160002060008585815181106112495761124961362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b50806112818161365b565b9150506110df565b50611292611e84565b600087116112d55760405162461bcd60e51b815260206004820152601060248201526f063616e6e6f7420756e7374616b6520360841b60448201526064016106b0565b60006112e08961191a565b90506001600160a01b0381166113085760405162461bcd60e51b81526004016106b090613674565b6000898152609d602090815260408083203384529091529020548811156113645760405162461bcd60e51b815260206004820152601060248201526f0e6d0c2e4ca40dcdee840cadcdeeaced60831b60448201526064016106b0565b60008981526099602052604090205461137d90896122f4565b60008a815260996020908152604080832093909355609d8152828220338352905220546113aa90896122f4565b60008a8152609d602090815260408083203384529091528120919091556113d08a6107f5565b80519091506001600160a01b03161561146a576000611408670de0b6b3a764000061075584602001518d61230790919063ffffffff16565b90508060000361144e5760405162461bcd60e51b815260206004820152601160248201527073686f756c646e2774206265207a65726f60781b60448201526064016106b0565b8151611464906001600160a01b03163383612d95565b5061147e565b61147e6001600160a01b038316338b612d95565b604080518b8152602081018b905233917ff960dbf9e5d0682f7a298ed974e33a28b4464914b7a2bfac12ae419a9afeb280910160405180910390a2600197505050610ba3600160a155565b600082815260a060205260408120818360028111156114ea576114ea61369a565b60028111156114fb576114fb61369a565b815260208101919091526040016000205460ff169392505050565b600080611523848461083c565b6020015190508042106115365780611538565b425b949350505050565b61154861232b565b611550611e3e565b60405162461bcd60e51b815260206004820152600a60248201526919195c1c9958d85d195960b21b60448201526064016106b0565b61158d61232b565b611595611e3e565b60006115a08361191a565b90506001600160a01b0381166115c85760405162461bcd60e51b81526004016106b090613674565b600083815260db6020526040902080546001600160a01b0316156116225760405162461bcd60e51b8152602060048201526011602482015270185b1c9958591e4818dbdb9d995c9d1959607a1b60448201526064016106b0565b6000848152609960205260409020548061166e5760405162461bcd60e51b815260206004820152600d60248201526c706f6f6c20697320656d70747960981b60448201526064016106b0565b826001600160a01b0316846001600160a01b03166301b60ef26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116da91906136b0565b6001600160a01b03161461172b5760405162461bcd60e51b815260206004820152601860248201527718dbdb9d995c9d1bdc881a5cc81b9bdd081b585d18da195960421b60448201526064016106b0565b61173f6001600160a01b0384168583612df8565b60405163a3908e1b60e01b8152600481018290526000906001600160a01b0386169063a3908e1b906024016020604051808303816000875af1158015611789573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117ad91906136cd565b905060006117c78361075584670de0b6b3a7640000612307565b9050806000036118195760405162461bcd60e51b815260206004820152601f60248201527f65786368616e676520726174652073686f756c646e2774206265207a65726f0060448201526064016106b0565b808460010181905550856001600160a01b031663c1d8d1d96040518163ffffffff1660e01b8152600401602060405180830381865afa158015611860573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188491906136b0565b84546001600160a01b03199081166001600160a01b03928316178655600089815260dc602090815260409182902080549093168a851617909255865481518b81528985169381019390935290921681830152606081018590526080810184905290517f7357bdf6439eb71d76705f65b579405009821f85cd9c27520fe6bca4d2707bae9160a0908290030190a150505050505050565b6000908152609860205260409020546001600160a01b031690565b61193d61232b565b611945611e3e565b61194e81612f0d565b50565b600061195b611e3e565b83600061196882826114c9565b156119855760405162461bcd60e51b81526004016106b0906135d2565b85846000611992836108e2565b905060005b8151811015611b41576000848152609c60205260408120835182908590859081106119c4576119c461362f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050611a0485848481518110610a1f57610a1f61362f565b8160020181905550611a2285848481518110610a4a57610a4a61362f565b60038201556001600160a01b03841615611b2e57611a4d8585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b038916845290915281208551909190869086908110611a8657611a8661362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b031681526020019081526020016000206000858581518110611b0157611b0161362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b5080611b398161365b565b915050611997565b50611b4a611e84565b6001600160a01b038716611b935760405162461bcd60e51b815260206004820152601060248201526f34b73b30b634b2103932b1b2b4bb32b960811b60448201526064016106b0565b611b9e8989896124f1565b9550611baa600160a155565b50505050509392505050565b611bbe61232b565b6001600160a01b038116611c235760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016106b0565b61194e816123d7565b611c3461232b565b611c3c611e3e565b6000611c478361191a565b90506001600160a01b038116611c6f5760405162461bcd60e51b81526004016106b090613674565b6000611c7a846107f5565b5190506001600160a01b038116611cd35760405162461bcd60e51b815260206004820152601e60248201527f706f6f6c206d75737420626520616c726561647920636f6e766572746564000060448201526064016106b0565b816001600160a01b0316836001600160a01b03166301b60ef26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3f91906136b0565b6001600160a01b0316148015611dc75750806001600160a01b0316836001600160a01b031663c1d8d1d96040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dbc91906136b0565b6001600160a01b0316145b611e0e5760405162461bcd60e51b815260206004820152601860248201527718dbdb9d995c9d1bdc881a5cc81b9bdd081b585d18da195960421b60448201526064016106b0565b5050600091825260dc602052604090912080546001600160a01b0319166001600160a01b03909216919091179055565b60655460ff16156108ce5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016106b0565b600260a15403611ed65760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016106b0565b600260a155565b600081336000611eec836108e2565b905060005b815181101561209b576000848152609c6020526040812083518290859085908110611f1e57611f1e61362f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050611f5e85848481518110610a1f57610a1f61362f565b8160020181905550611f7c85848481518110610a4a57610a4a61362f565b60038201556001600160a01b0384161561208857611fa78585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b038916845290915281208551909190869086908110611fe057611fe061362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b03168152602001908152602001600020600085858151811061205b5761205b61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b50806120938161365b565b915050611ef1565b5060006120a7866108e2565b6000878152609a60205260408120549192505b82518110156122df5760006120e989338685815181106120dc576120dc61362f565b6020026020010151610c29565b905080156122ce576000898152609e602090815260408083203384529091528120855182908790869081106121205761212061362f565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002081905550600061216d670de0b6b3a7640000610755868561230790919063ffffffff16565b9050600061217b83836122f4565b905081156122255760008b8152609c60205260408120875182908990889081106121a7576121a761362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020905060006121e98d60009081526099602052604090205490565b905080156122225760006122098261075587670de0b6b3a7640000612307565b600284015490915061221b908261231f565b6002840155505b50505b61225c338288878151811061223c5761223c61362f565b60200260200101516001600160a01b0316612d959092919063ffffffff16565b85848151811061226e5761226e61362f565b60200260200101516001600160a01b0316336001600160a01b03167f3ca11272227262090da5effe1aab9b06d2418af179ea41c876a68b186c73cc208d846040516122c3929190918252602082015260400190565b60405180910390a350505b506122d88161365b565b90506120ba565b506001979650505050505050565b600160a155565b600061230082846136e6565b9392505050565b600061230082846136f9565b60006123008284613710565b60006123008284613732565b6033546001600160a01b031633146108ce5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016106b0565b61238d612fe3565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006124348361191a565b6001600160a01b03160361245a5760405162461bcd60e51b81526004016106b090613674565b670de0b6b3a76400008111156124a15760405162461bcd60e51b815260206004820152600c60248201526b696e76616c6964207261746560a01b60448201526064016106b0565b6000828152609a602090815260409182902083905581518481529081018390527fb7232ad8c7b793eeaae7f80539cf2d5bb40ae19b3afaa25ea24fa3e4279a369e91015b60405180910390a15050565b6000806124fd8561191a565b90506001600160a01b0381166125255760405162461bcd60e51b81526004016106b090613674565b600080612531876107f5565b80519091506001600160a01b03161561266757600087815260dc60205260409020546001600160a01b0316806125a95760405162461bcd60e51b815260206004820152601960248201527f706f6f6c20636f6e766572746f72206973206e6f74207365740000000000000060448201526064016106b0565b6125be6001600160a01b03851633308a61302c565b6125d26001600160a01b0385168289612df8565b60405163a3908e1b60e01b8152600481018890526000906001600160a01b0383169063a3908e1b906024016020604051808303816000875af115801561261c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061264091906136cd565b602084015190915061265e9061075583670de0b6b3a7640000612307565b93505050612680565b61267c6001600160a01b03841633308961302c565b8591505b600082116126c15760405162461bcd60e51b815260206004820152600e60248201526d063616e6e6f74207374616b6520360941b60448201526064016106b0565b6000878152609960205260409020546126da908361231f565b600088815260996020908152604080832093909355609d81528282206001600160a01b038916835290522054612710908361231f565b6000888152609d602090815260408083206001600160a01b038a16808552908352928190209390935582518a815290810185905290917f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b6910160405180910390a25060019695505050505050565b600083815260a06020526040812082918460028111156127a0576127a061369a565b60028111156127b1576127b161369a565b815260200190815260200160002060006101000a81548160ff0219169083151502179055507f72456f11997c4141186829babc53f5f329ed7d5166fd80affcebd3114dcaf90383838360405161280993929190613745565b60405180910390a1505050565b61281e611e3e565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586123ba3390565b600054610100900460ff1661287a5760405162461bcd60e51b81526004016106b090613780565b6108ce613064565b600054610100900460ff166128a95760405162461bcd60e51b81526004016106b090613780565b6108ce613097565b600054610100900460ff166128d85760405162461bcd60e51b81526004016106b090613780565b6108ce6130c7565b836000806128ed836108e2565b905060005b8151811015612a9c576000848152609c602052604081208351829085908590811061291f5761291f61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020905061295f85848481518110610a1f57610a1f61362f565b816002018190555061297d85848481518110610a4a57610a4a61362f565b60038201556001600160a01b03841615612a89576129a88585858581518110610a8257610a8261362f565b6000868152609e602090815260408083206001600160a01b0389168452909152812085519091908690869081106129e1576129e161362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055508060020154609f60008781526020019081526020016000206000866001600160a01b03166001600160a01b031681526020019081526020016000206000858581518110612a5c57612a5c61362f565b60200260200101516001600160a01b03166001600160a01b03168152602001908152602001600020819055505b5080612a948161365b565b9150506128f2565b506001600160a01b038616612af35760405162461bcd60e51b815260206004820152601c60248201527f72657761726420746f6b656e206973207a65726f20616464726573730000000060448201526064016106b0565b6000612afe8861191a565b6001600160a01b031603612b4b5760405162461bcd60e51b81526020600482015260146024820152731c1bdbdb081b5d5cdd08189948195e1a5cdd195960621b60448201526064016106b0565b6000612b56886108e2565b9050600160005b8251811015612bb357886001600160a01b0316838281518110612b8257612b8261362f565b60200260200101516001600160a01b031603612ba15760009150612bb3565b80612bab8161365b565b915050612b5d565b508015612bf2576000898152609b602090815260408220805460018101825590835291200180546001600160a01b0319166001600160a01b038a161790555b6000898152609b602052604090205460031015612c495760405162461bcd60e51b8152602060048201526015602482015274746f6f206d616e792072657761726420747970657360581b60448201526064016106b0565b6000898152609c602090815260408083206001600160a01b038c1684529091528120426003820181905560018201549192911115612c9f57815460038301546001840154612c9c92916107d191906122f4565b90505b87421115612cb257426001830155612cba565b600182018890555b88825560038201546001830154600091612cda918c916107d191906122f4565b905080821015612d0a57612d053330612cf384866122f4565b6001600160a01b038f1692919061302c565b612d31565b80821115612d3157612d3133612d2084846122f4565b6001600160a01b038e169190612d95565b82546001840154604080518f81526001600160a01b038f1660208201529081019290925260608201527f560be8033bbe7cd2b35cc61f8150821a44ced377dc74a650a0dea24d49693c9a9060800160405180910390a1505050505050505050505050565b6040516001600160a01b038316602482015260448101829052610c1490849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526130ee565b801580612e725750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015612e4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7091906136cd565b155b612edd5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016106b0565b6040516001600160a01b038316602482015260448101829052610c1490849063095ea7b360e01b90606401612dc1565b6001600160a01b038116612f635760405162461bcd60e51b815260206004820152601b60248201527f736861726520746f6b656e206973207a65726f2061646472657373000000000060448201526064016106b0565b6000612f6e60975490565b600081815260986020526040902080546001600160a01b0319166001600160a01b0385161790559050612fa281600161231f565b609755604080518281526001600160a01b03841660208201527fcfdb757a17c7073437a01260a6760f5026efd70c96fb9a3f54d03c6ed2c372c391016124e5565b60655460ff166108ce5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016106b0565b6040516001600160a01b03808516602483015283166044820152606481018290526110939085906323b872dd60e01b90608401612dc1565b600054610100900460ff1661308b5760405162461bcd60e51b81526004016106b090613780565b6065805460ff19169055565b600054610100900460ff166130be5760405162461bcd60e51b81526004016106b090613780565b6108ce336123d7565b600054610100900460ff166122ed5760405162461bcd60e51b81526004016106b090613780565b6000613143826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166131c39092919063ffffffff16565b905080516000148061316457508080602001905181019061316491906137cb565b610c145760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016106b0565b6060611538848460008585600080866001600160a01b031685876040516131ea919061380c565b60006040518083038185875af1925050503d8060008114613227576040519150601f19603f3d011682016040523d82523d6000602084013e61322c565b606091505b509150915061323d87838387613248565b979650505050505050565b606083156132b75782516000036132b0576001600160a01b0385163b6132b05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016106b0565b5081611538565b61153883838151156132cc5781518083602001fd5b8060405162461bcd60e51b81526004016106b09190613828565b6000602082840312156132f857600080fd5b5035919050565b6001600160a01b038116811461194e57600080fd5b60008060006060848603121561332957600080fd5b83359250602084013561333b816132ff565b9150604084013561334b816132ff565b809150509250925092565b6000806040838503121561336957600080fd5b82359150602083013561337b816132ff565b809150509250929050565b6020808252825182820181905260009190848201906040850190845b818110156133c75783516001600160a01b0316835292840192918401916001016133a2565b50909695505050505050565b600080604083850312156133e657600080fd5b50508035926020909101359150565b80356003811061340457600080fd5b919050565b801515811461194e57600080fd5b60008060006060848603121561342c57600080fd5b8335925061343c602085016133f5565b9150604084013561334b81613409565b600080600080600080600080610100898b03121561346957600080fd5b8835613474816132ff565b97506020890135613484816132ff565b96506040890135613494816132ff565b955060608901356134a4816132ff565b945060808901356134b4816132ff565b935060a08901356134c4816132ff565b925060c08901356134d4816132ff565b915060e08901356134e4816132ff565b809150509295985092959890939650565b6000806000806080858703121561350b57600080fd5b84359350602085013561351d816132ff565b93969395505050506040820135916060013590565b6000806040838503121561354557600080fd5b82359150613555602084016133f5565b90509250929050565b6000806040838503121561357157600080fd5b8235915060208301356004811061337b57600080fd5b60006020828403121561359957600080fd5b8135612300816132ff565b6000806000606084860312156135b957600080fd5b8335925060208401359150604084013561334b816132ff565b60208082526038908201527f506f6f6c4f7065726174696f6e5061757361626c653a206f7065726174696f6e60408201527f2069732070617573656420666f72207468697320706f6f6c0000000000000000606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161366d5761366d613645565b5060010190565b6020808252600c908201526b1a5b9d985b1a59081c1bdbdb60a21b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b6000602082840312156136c257600080fd5b8151612300816132ff565b6000602082840312156136df57600080fd5b5051919050565b818103818111156107ef576107ef613645565b80820281158282048414176107ef576107ef613645565b60008261372d57634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156107ef576107ef613645565b838152606081016003841061376a57634e487b7160e01b600052602160045260246000fd5b8360208301528215156040830152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156137dd57600080fd5b815161230081613409565b60005b838110156138035781810151838201526020016137eb565b50506000910152565b6000825161381e8184602087016137e8565b9190910192915050565b60208152600082518060208401526138478160408501602087016137e8565b601f01601f1916919091016040019291505056fea2646970667358221220e7fede1b2d4d4ab3817d5ca353e049be2c0616b0cd0e004e4b54ecff1ea191d164736f6c63430008110033