Contract 0x3dc25F78b4Eaed2F3ac2C26b0f4Ae1DEBb08F6e5 2

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x25e348f0d91ec3e28a48468c01259ced38087b61952c00e5cf5a2d1338e85dd30x60806040213419602022-10-21 8:16:4536 days 18 hrs ago0xbcb909975715dc8fde643ee44b89e3fd6a35a259 IN  Create: HFunds0 AVAX0.03400032525
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
HFunds

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 11 : HFunds.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../../lib/LibFeeStorage.sol";
import "../HandlerBase.sol";

contract HFunds is HandlerBase {
    using SafeERC20 for IERC20;
    using LibFeeStorage for mapping(bytes32 => bytes32);

    event ChargeFee(address indexed tokenIn, uint256 feeAmount);

    function getContractName() public pure override returns (string memory) {
        return "HFunds";
    }

    function updateTokens(address[] calldata tokens)
        external
        payable
        returns (uint256[] memory)
    {
        uint256[] memory balances = new uint256[](tokens.length);
        for (uint256 i = 0; i < tokens.length; i++) {
            address token = tokens[i];
            if (token != address(0) && token != NATIVE_TOKEN_ADDRESS) {
                // Update involved token
                _updateToken(token);
            }
            balances[i] = _getBalance(token, type(uint256).max);
        }
        return balances;
    }

    function inject(address[] calldata tokens, uint256[] calldata amounts)
        external
        payable
        returns (uint256[] memory)
    {
        return _inject(tokens, amounts);
    }

    // Same as inject() and just to make another interface for different use case
    function addFunds(address[] calldata tokens, uint256[] calldata amounts)
        external
        payable
        returns (uint256[] memory)
    {
        return _inject(tokens, amounts);
    }

    function sendTokens(
        address[] calldata tokens,
        uint256[] calldata amounts,
        address payable receiver
    ) external payable {
        for (uint256 i = 0; i < tokens.length; i++) {
            uint256 amount = _getBalance(tokens[i], amounts[i]);
            if (amount > 0) {
                // ETH case
                if (
                    tokens[i] == address(0) || tokens[i] == NATIVE_TOKEN_ADDRESS
                ) {
                    receiver.transfer(amount);
                } else {
                    IERC20(tokens[i]).safeTransfer(receiver, amount);
                }
            }
        }
    }

    function send(uint256 amount, address payable receiver) external payable {
        amount = _getBalance(address(0), amount);
        if (amount > 0) {
            receiver.transfer(amount);
        }
    }

    function sendToken(
        address token,
        uint256 amount,
        address receiver
    ) external payable {
        amount = _getBalance(token, amount);
        if (amount > 0) {
            IERC20(token).safeTransfer(receiver, amount);
        }
    }

    /// @notice Send ether to block miner.
    /// @dev Transfer with built-in 2300 gas cap is safer and acceptable for most miners.
    /// @param amount The ether amount.
    function sendEtherToMiner(uint256 amount) external payable {
        if (amount > 0) {
            block.coinbase.transfer(amount);
        }
    }

    function checkSlippage(
        address[] calldata tokens,
        uint256[] calldata amounts
    ) external payable {
        _requireMsg(
            tokens.length == amounts.length,
            "checkSlippage",
            "token and amount do not match"
        );

        for (uint256 i = 0; i < tokens.length; i++) {
            if (tokens[i] == address(0)) {
                if (address(this).balance < amounts[i]) {
                    string memory errMsg =
                        string(
                            abi.encodePacked(
                                "error: ",
                                _uint2String(i),
                                "_",
                                _uint2String(address(this).balance)
                            )
                        );
                    _revertMsg("checkSlippage", errMsg);
                }
            } else if (
                IERC20(tokens[i]).balanceOf(address(this)) < amounts[i]
            ) {
                string memory errMsg =
                    string(
                        abi.encodePacked(
                            "error: ",
                            _uint2String(i),
                            "_",
                            _uint2String(
                                IERC20(tokens[i]).balanceOf(address(this))
                            )
                        )
                    );

                _revertMsg("checkSlippage", errMsg);
            }
        }
    }

    function getBalance(address token) external payable returns (uint256) {
        return _getBalance(token, type(uint256).max);
    }

    function _inject(address[] calldata tokens, uint256[] calldata amounts)
        internal
        returns (uint256[] memory)
    {
        _requireMsg(
            tokens.length == amounts.length,
            "inject",
            "token and amount does not match"
        );
        address sender = _getSender();
        uint256 feeRate = cache._getFeeRate();
        address collector = cache._getFeeCollector();
        uint256[] memory amountsInProxy = new uint256[](amounts.length);

        for (uint256 i = 0; i < tokens.length; i++) {
            IERC20(tokens[i]).safeTransferFrom(
                sender,
                address(this),
                amounts[i]
            );
            if (feeRate > 0) {
                uint256 fee = _calFee(amounts[i], feeRate);
                IERC20(tokens[i]).safeTransfer(collector, fee);
                amountsInProxy[i] = amounts[i] - fee;
                emit ChargeFee(tokens[i], fee);
            } else {
                amountsInProxy[i] = amounts[i];
            }

            // Update involved token
            _updateToken(tokens[i]);
        }
        return amountsInProxy;
    }

    function _calFee(uint256 amount, uint256 feeRate)
        internal
        pure
        returns (uint256)
    {
        return (amount * feeRate) / PERCENTAGE_BASE;
    }
}

File 2 of 11 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    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));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    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");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @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");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 3 of 11 : LibFeeStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./LibCache.sol";
import "../Storage.sol";

library LibFeeStorage {
    using LibCache for mapping(bytes32 => bytes32);

    // keccak256 hash of "furucombo.fee.rate"
    // prettier-ignore
    bytes32 public constant FEE_RATE_KEY = 0x142183525227cae0e4300fd0fc77d7f3b08ceb0fd9cb2a6c5488668fa0ea5ffa;

    // keccak256 hash of "furucombo.fee.collector"
    // prettier-ignore
    bytes32 public constant FEE_COLLECTOR_KEY = 0x60d7a7cc0a45d852bd613e4f527aaa2e4b81fff918a69a2aab88b6458751d614;

    function _setFeeRate(
        mapping(bytes32 => bytes32) storage _cache,
        uint256 _feeRate
    ) internal {
        require(_getFeeRate(_cache) == 0, "Fee rate not zero");
        _cache.setUint256(FEE_RATE_KEY, _feeRate);
    }

    function _resetFeeRate(mapping(bytes32 => bytes32) storage _cache)
        internal
    {
        _cache.setUint256(FEE_RATE_KEY, 0);
    }

    function _getFeeRate(mapping(bytes32 => bytes32) storage _cache)
        internal
        view
        returns (uint256)
    {
        return _cache.getUint256(FEE_RATE_KEY);
    }

    function _setFeeCollector(
        mapping(bytes32 => bytes32) storage _cache,
        address _collector
    ) internal {
        require(
            _getFeeCollector(_cache) == address(0),
            "Fee collector is initialized"
        );
        _cache.setAddress(FEE_COLLECTOR_KEY, _collector);
    }

    function _resetFeeCollector(mapping(bytes32 => bytes32) storage _cache)
        internal
    {
        _cache.setAddress(FEE_COLLECTOR_KEY, address(0));
    }

    function _getFeeCollector(mapping(bytes32 => bytes32) storage _cache)
        internal
        view
        returns (address)
    {
        return _cache.getAddress(FEE_COLLECTOR_KEY);
    }
}

File 4 of 11 : HandlerBase.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../interface/IERC20Usdt.sol";

import "../Config.sol";
import "../Storage.sol";

abstract contract HandlerBase is Storage, Config {
    using SafeERC20 for IERC20;
    using LibStack for bytes32[];

    address public constant NATIVE_TOKEN_ADDRESS =
        0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    function postProcess() external payable virtual {
        revert("Invalid post process");
        /* Implementation template
        bytes4 sig = stack.getSig();
        if (sig == bytes4(keccak256(bytes("handlerFunction_1()")))) {
            // Do something
        } else if (sig == bytes4(keccak256(bytes("handlerFunction_2()")))) {
            bytes32 temp = stack.get();
            // Do something
        } else revert("Invalid post process");
        */
    }

    function _updateToken(address token) internal {
        stack.setAddress(token);
        // Ignore token type to fit old handlers
        // stack.setHandlerType(uint256(HandlerType.Token));
    }

    function _updatePostProcess(bytes32[] memory params) internal {
        for (uint256 i = params.length; i > 0; i--) {
            stack.set(params[i - 1]);
        }
        stack.set(msg.sig);
        stack.setHandlerType(HandlerType.Custom);
    }

    function getContractName() public pure virtual returns (string memory);

    function _revertMsg(string memory functionName, string memory reason)
        internal
        pure
    {
        revert(
            string(
                abi.encodePacked(
                    getContractName(),
                    "_",
                    functionName,
                    ": ",
                    reason
                )
            )
        );
    }

    function _revertMsg(string memory functionName) internal pure {
        _revertMsg(functionName, "Unspecified");
    }

    function _requireMsg(
        bool condition,
        string memory functionName,
        string memory reason
    ) internal pure {
        if (!condition) _revertMsg(functionName, reason);
    }

    function _uint2String(uint256 n) internal pure returns (string memory) {
        if (n == 0) {
            return "0";
        } else {
            uint256 len = 0;
            for (uint256 temp = n; temp > 0; temp /= 10) {
                len++;
            }
            bytes memory str = new bytes(len);
            for (uint256 i = len; i > 0; i--) {
                str[i - 1] = bytes1(uint8(48 + (n % 10)));
                n /= 10;
            }
            return string(str);
        }
    }

    function _getBalance(address token, uint256 amount)
        internal
        view
        returns (uint256)
    {
        if (amount != type(uint256).max) {
            return amount;
        }

        // ETH case
        if (token == address(0) || token == NATIVE_TOKEN_ADDRESS) {
            return address(this).balance;
        }
        // ERC20 token case
        return IERC20(token).balanceOf(address(this));
    }

    function _tokenApprove(
        address token,
        address spender,
        uint256 amount
    ) internal {
        try IERC20Usdt(token).approve(spender, amount) {} catch {
            IERC20(token).safeApprove(spender, 0);
            IERC20(token).safeApprove(spender, amount);
        }
    }

    function _tokenApproveZero(address token, address spender) internal {
        if (IERC20Usdt(token).allowance(address(this), spender) > 0) {
            try IERC20Usdt(token).approve(spender, 0) {} catch {
                IERC20Usdt(token).approve(spender, 1);
            }
        }
    }

    function _isNotNativeToken(address token) internal pure returns (bool) {
        return (token != address(0) && token != NATIVE_TOKEN_ADDRESS);
    }
}

File 5 of 11 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

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

File 6 of 11 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 7 of 11 : LibCache.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

library LibCache {
    function set(
        mapping(bytes32 => bytes32) storage _cache,
        bytes32 _key,
        bytes32 _value
    ) internal {
        _cache[_key] = _value;
    }

    function setAddress(
        mapping(bytes32 => bytes32) storage _cache,
        bytes32 _key,
        address _value
    ) internal {
        _cache[_key] = bytes32(uint256(uint160(_value)));
    }

    function setUint256(
        mapping(bytes32 => bytes32) storage _cache,
        bytes32 _key,
        uint256 _value
    ) internal {
        _cache[_key] = bytes32(_value);
    }

    function getAddress(
        mapping(bytes32 => bytes32) storage _cache,
        bytes32 _key
    ) internal view returns (address ret) {
        ret = address(uint160(uint256(_cache[_key])));
    }

    function getUint256(
        mapping(bytes32 => bytes32) storage _cache,
        bytes32 _key
    ) internal view returns (uint256 ret) {
        ret = uint256(_cache[_key]);
    }

    function get(mapping(bytes32 => bytes32) storage _cache, bytes32 _key)
        internal
        view
        returns (bytes32 ret)
    {
        ret = _cache[_key];
    }
}

File 8 of 11 : Storage.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./lib/LibCache.sol";
import "./lib/LibStack.sol";

/// @notice A cache structure composed by a bytes32 array
contract Storage {
    using LibCache for mapping(bytes32 => bytes32);
    using LibStack for bytes32[];

    bytes32[] public stack;
    mapping(bytes32 => bytes32) public cache;

    // keccak256 hash of "msg.sender"
    // prettier-ignore
    bytes32 public constant MSG_SENDER_KEY = 0xb2f2618cecbbb6e7468cc0f2aa43858ad8d153e0280b22285e28e853bb9d453a;

    modifier isStackEmpty() {
        require(stack.length == 0, "Stack not empty");
        _;
    }

    modifier isInitialized() {
        require(_getSender() != address(0), "Sender is not initialized");
        _;
    }

    modifier isNotInitialized() {
        require(_getSender() == address(0), "Sender is initialized");
        _;
    }

    function _setSender() internal isNotInitialized {
        cache.setAddress(MSG_SENDER_KEY, msg.sender);
    }

    function _resetSender() internal {
        cache.setAddress(MSG_SENDER_KEY, address(0));
    }

    function _getSender() internal view returns (address) {
        return cache.getAddress(MSG_SENDER_KEY);
    }
}

File 9 of 11 : LibStack.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../Config.sol";

library LibStack {
    function setAddress(bytes32[] storage _stack, address _input) internal {
        _stack.push(bytes32(uint256(uint160(_input))));
    }

    function set(bytes32[] storage _stack, bytes32 _input) internal {
        _stack.push(_input);
    }

    function setHandlerType(bytes32[] storage _stack, Config.HandlerType _input)
        internal
    {
        _stack.push(bytes12(uint96(_input)));
    }

    function getAddress(bytes32[] storage _stack)
        internal
        returns (address ret)
    {
        ret = address(uint160(uint256(peek(_stack))));
        _stack.pop();
    }

    function getSig(bytes32[] storage _stack) internal returns (bytes4 ret) {
        ret = bytes4(peek(_stack));
        _stack.pop();
    }

    function get(bytes32[] storage _stack) internal returns (bytes32 ret) {
        ret = peek(_stack);
        _stack.pop();
    }

    function peek(bytes32[] storage _stack)
        internal
        view
        returns (bytes32 ret)
    {
        uint256 length = _stack.length;
        require(length > 0, "stack empty");
        ret = _stack[length - 1];
    }

    function peek(bytes32[] storage _stack, uint256 _index)
        internal
        view
        returns (bytes32 ret)
    {
        uint256 length = _stack.length;
        require(length > 0, "stack empty");
        require(length > _index, "not enough elements in stack");
        ret = _stack[length - _index - 1];
    }
}

File 10 of 11 : Config.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract Config {
    // function signature of "postProcess()"
    bytes4 public constant POSTPROCESS_SIG = 0xc2722916;

    // The base amount of percentage function
    uint256 public constant PERCENTAGE_BASE = 1 ether;

    // Handler post-process type. Others should not happen now.
    enum HandlerType {Token, Custom, Others}
}

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

pragma solidity ^0.8.0;

interface IERC20Usdt {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address recipient, uint256 amount) external;

    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 amount) external;

    function transferFrom(address sender, address recipient, uint256 amount) external;

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

    event Approval(address indexed owner, address indexed spender, uint256 value);
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"}],"name":"ChargeFee","type":"event"},{"inputs":[],"name":"MSG_SENDER_KEY","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NATIVE_TOKEN_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERCENTAGE_BASE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POSTPROCESS_SIG","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"addFunds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"cache","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"checkSlippage","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getContractName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"inject","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"postProcess","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address payable","name":"receiver","type":"address"}],"name":"send","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sendEtherToMiner","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"sendToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address payable","name":"receiver","type":"address"}],"name":"sendTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"stack","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"updateTokens","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"payable","type":"function"}]

608060405234801561001057600080fd5b506117a3806100206000396000f3fe6080604052600436106100fe5760003560e01c8063d0797f8411610095578063df2ebdbb11610064578063df2ebdbb14610240578063e64154d314610280578063f5f5ba7214610293578063f8b2cb4f146102c8578063fa2901a5146102db57600080fd5b8063d0797f8414610103578063db71410e146101fa578063dc9031c41461020d578063de41691c1461022d57600080fd5b806381baf3ab116100d157806381baf3ab1461019657806387c13943146101a957806399eb59b9146101c5578063c2722916146101f257600080fd5b80630ce7df36146101035780630f532d181461012c57806318248f2a1461016e578063785d04f514610183575b600080fd5b6101166101113660046112d5565b61030f565b6040516101239190611341565b60405180910390f35b34801561013857600080fd5b506101607fb2f2618cecbbb6e7468cc0f2aa43858ad8d153e0280b22285e28e853bb9d453a81565b604051908152602001610123565b61018161017c36600461139a565b610326565b005b6101816101913660046113dc565b610351565b6101816101a436600461140c565b61039e565b3480156101b557600080fd5b50610160670de0b6b3a764000081565b3480156101d157600080fd5b506101606101e0366004611490565b60016020526000908152604090205481565b610181610513565b6101816102083660046112d5565b610557565b34801561021957600080fd5b50610160610228366004611490565b61083e565b61011661023b3660046114a9565b61085f565b34801561024c57600080fd5b5061026873eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b6040516001600160a01b039091168152602001610123565b61018161028e366004611490565b610967565b34801561029f57600080fd5b5060408051808201825260068152654846756e647360d01b602082015290516101239190611517565b6101606102d636600461154a565b61099d565b3480156102e757600080fd5b506102f6636139148b60e11b81565b6040516001600160e01b03199091168152602001610123565b606061031d858585856109ab565b95945050505050565b6103308383610c9f565b9150811561034c5761034c6001600160a01b0384168284610d5e565b505050565b61035c600083610c9f565b9150811561039a576040516001600160a01b0382169083156108fc029084906000818181858888f1935050505015801561034c573d6000803e3d6000fd5b5050565b60005b8481101561050b5760006103f38787848181106103c0576103c0611567565b90506020020160208101906103d5919061154a565b8686858181106103e7576103e7611567565b90506020020135610c9f565b905080156104f857600087878481811061040f5761040f611567565b9050602002016020810190610424919061154a565b6001600160a01b0316148061047b575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee87878481811061045b5761045b611567565b9050602002016020810190610470919061154a565b6001600160a01b0316145b156104bc576040516001600160a01b0384169082156108fc029083906000818181858888f193505050501580156104b6573d6000803e3d6000fd5b506104f8565b6104f883828989868181106104d3576104d3611567565b90506020020160208101906104e8919061154a565b6001600160a01b03169190610d5e565b508061050381611593565b9150506103a1565b505050505050565b60405162461bcd60e51b8152602060048201526014602482015273496e76616c696420706f73742070726f6365737360601b60448201526064015b60405180910390fd5b604080518082018252600d81526c636865636b536c69707061676560981b6020808301919091528251808401909352601d83527f746f6b656e20616e6420616d6f756e7420646f206e6f74206d61746368000000908301526105bd918584149190610dc1565b60005b838110156108375760008585838181106105dc576105dc611567565b90506020020160208101906105f1919061154a565b6001600160a01b031614156106855782828281811061061257610612611567565b9050602002013547101561068057600061062b82610dd0565b61063447610dd0565b6040516020016106459291906115ae565b60408051601f19818403018152828201909152600d82526c636865636b536c69707061676560981b6020830152915061067e9082610ee2565b505b610825565b82828281811061069757610697611567565b905060200201358585838181106106b0576106b0611567565b90506020020160208101906106c5919061154a565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa15801561070b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072f91906115fd565b101561082557600061074082610dd0565b6107d987878581811061075557610755611567565b905060200201602081019061076a919061154a565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156107b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107d491906115fd565b610dd0565b6040516020016107ea9291906115ae565b60408051601f19818403018152828201909152600d82526c636865636b536c69707061676560981b602083015291506108239082610ee2565b505b8061082f81611593565b9150506105c0565b5050505050565b6000818154811061084e57600080fd5b600091825260209091200154905081565b606060008267ffffffffffffffff81111561087c5761087c611616565b6040519080825280602002602001820160405280156108a5578160200160208202803683370190505b50905060005b8381101561095d5760008585838181106108c7576108c7611567565b90506020020160208101906108dc919061154a565b90506001600160a01b0381161580159061091357506001600160a01b03811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14155b156109215761092181610f39565b61092d81600019610c9f565b83838151811061093f5761093f611567565b6020908102919091010152508061095581611593565b9150506108ab565b5090505b92915050565b801561099a57604051419082156108fc029083906000818181858888f1935050505015801561039a573d6000803e3d6000fd5b50565b600061096182600019610c9f565b60408051808201825260068152651a5b9a9958dd60d21b6020808301919091528251808401909352601f83527f746f6b656e20616e6420616d6f756e7420646f6573206e6f74206d617463680090830152606091610a0c9186851491610dc1565b6000610a5f7fb2f2618cecbbb6e7468cc0f2aa43858ad8d153e0280b22285e28e853bb9d453a60005260016020527fe066822ceb6294079ebca45035319f95ccb12306128dbdf5a257f0d1235733c95490565b90506000610a6d6001610f78565b90506000610a7b6001610fad565b905060008567ffffffffffffffff811115610a9857610a98611616565b604051908082528060200260200182016040528015610ac1578160200160208202803683370190505b50905060005b88811015610c9257610b2585308a8a85818110610ae657610ae6611567565b905060200201358d8d86818110610aff57610aff611567565b9050602002016020810190610b14919061154a565b6001600160a01b0316929190610fe2565b8315610c19576000610b4f898984818110610b4257610b42611567565b9050602002013586611020565b9050610b6884828d8d868181106104d3576104d3611567565b80898984818110610b7b57610b7b611567565b90506020020135610b8c919061162c565b838381518110610b9e57610b9e611567565b6020026020010181815250508a8a83818110610bbc57610bbc611567565b9050602002016020810190610bd1919061154a565b6001600160a01b03167ff842076a30ec58e71f31f5ded044f2790b403c5a75bdbfddea03130ee65e1a5882604051610c0b91815260200190565b60405180910390a250610c51565b878782818110610c2b57610c2b611567565b90506020020135828281518110610c4457610c44611567565b6020026020010181815250505b610c808a8a83818110610c6657610c66611567565b9050602002016020810190610c7b919061154a565b610f39565b80610c8a81611593565b915050610ac7565b5098975050505050505050565b60006000198214610cb1575080610961565b6001600160a01b0383161580610ce357506001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee145b15610cef575047610961565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa158015610d33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d5791906115fd565b9392505050565b6040516001600160a01b03831660248201526044810182905261034c90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261103f565b8261034c5761034c8282610ee2565b606081610df45750506040805180820190915260018152600360fc1b602082015290565b6000825b8015610e1e5781610e0881611593565b9250610e179050600a82611659565b9050610df8565b5060008167ffffffffffffffff811115610e3a57610e3a611616565b6040519080825280601f01601f191660200182016040528015610e64576020820181803683370190505b509050815b8015610eda57610e7a600a8661166d565b610e85906030611681565b60f81b82610e9460018461162c565b81518110610ea457610ea4611567565b60200101906001600160f81b031916908160001a905350610ec6600a86611659565b945080610ed281611699565b915050610e69565b509392505050565b6040805180820190915260068152654846756e647360d01b60208201528282604051602001610f13939291906116b0565b60408051601f198184030181529082905262461bcd60e51b825261054e91600401611517565b600080546001810182559080526001600160a01b0382167f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639091015550565b7f142183525227cae0e4300fd0fc77d7f3b08ceb0fd9cb2a6c5488668fa0ea5ffa600090815260208290526040812054610961565b7f60d7a7cc0a45d852bd613e4f527aaa2e4b81fff918a69a2aab88b6458751d614600090815260208290526040812054610961565b6040516001600160a01b038085166024830152831660448201526064810182905261101a9085906323b872dd60e01b90608401610d8a565b50505050565b6000670de0b6b3a76400006110358385611710565b610d579190611659565b6000611094826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166111119092919063ffffffff16565b80519091501561034c57808060200190518101906110b2919061172f565b61034c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161054e565b60606111208484600085611128565b949350505050565b6060824710156111895760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161054e565b843b6111d75760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161054e565b600080866001600160a01b031685876040516111f39190611751565b60006040518083038185875af1925050503d8060008114611230576040519150601f19603f3d011682016040523d82523d6000602084013e611235565b606091505b5091509150611245828286611250565b979650505050505050565b6060831561125f575081610d57565b82511561126f5782518084602001fd5b8160405162461bcd60e51b815260040161054e9190611517565b60008083601f84011261129b57600080fd5b50813567ffffffffffffffff8111156112b357600080fd5b6020830191508360208260051b85010111156112ce57600080fd5b9250929050565b600080600080604085870312156112eb57600080fd5b843567ffffffffffffffff8082111561130357600080fd5b61130f88838901611289565b9096509450602087013591508082111561132857600080fd5b5061133587828801611289565b95989497509550505050565b6020808252825182820181905260009190848201906040850190845b818110156113795783518352928401929184019160010161135d565b50909695505050505050565b6001600160a01b038116811461099a57600080fd5b6000806000606084860312156113af57600080fd5b83356113ba81611385565b92506020840135915060408401356113d181611385565b809150509250925092565b600080604083850312156113ef57600080fd5b82359150602083013561140181611385565b809150509250929050565b60008060008060006060868803121561142457600080fd5b853567ffffffffffffffff8082111561143c57600080fd5b61144889838a01611289565b9097509550602088013591508082111561146157600080fd5b5061146e88828901611289565b909450925050604086013561148281611385565b809150509295509295909350565b6000602082840312156114a257600080fd5b5035919050565b600080602083850312156114bc57600080fd5b823567ffffffffffffffff8111156114d357600080fd5b6114df85828601611289565b90969095509350505050565b60005b838110156115065781810151838201526020016114ee565b8381111561101a5750506000910152565b60208152600082518060208401526115368160408501602087016114eb565b601f01601f19169190910160400192915050565b60006020828403121561155c57600080fd5b8135610d5781611385565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006000198214156115a7576115a761157d565b5060010190565b66032b93937b91d160cd1b8152600083516115d08160078501602088016114eb565b605f60f81b60079184019182015283516115f18160088401602088016114eb565b01600801949350505050565b60006020828403121561160f57600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b60008282101561163e5761163e61157d565b500390565b634e487b7160e01b600052601260045260246000fd5b60008261166857611668611643565b500490565b60008261167c5761167c611643565b500690565b600082198211156116945761169461157d565b500190565b6000816116a8576116a861157d565b506000190190565b600084516116c28184602089016114eb565b605f60f81b90830190815284516116e08160018401602089016114eb565b6101d160f51b6001929091019182015283516117038160038401602088016114eb565b0160030195945050505050565b600081600019048311821515161561172a5761172a61157d565b500290565b60006020828403121561174157600080fd5b81518015158114610d5757600080fd5b600082516117638184602087016114eb565b919091019291505056fea2646970667358221220867d36b53acb7d7e39931ad5a58c415fdf2fdce70f579198ac4d3d091569f5af64736f6c634300080a0033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.