Contract 0x134A48F02bB8d160e4A75fc2A13DE721f28A8F41 2

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xd0b0244ada4729d7f5b40c89a45e3ca9514c50ca912bd0e53eb9216a9e2a948d0x60806040183497552022-07-23 7:27:3173 days 3 hrs ago0x2702d89c1c8658b49c45dd460deebcc45faec03c IN  Create: RangoV10 ETH0.008186968536 ETH
[ Download CSV Export 
Latest 7 internal transactions
Parent Txn Hash Block From To Value
0x5a898c820e1ca410e8cfc0f725f0fe9ccf5a89b6e89c2b850a5e64560e02e88f184331172022-07-24 10:16:2672 days 55 mins ago 0x2333722ba53d11cd76899b1c04a26949617f2254 0x134a48f02bb8d160e4a75fc2a13de721f28a8f410.01 ETH
0x85150649895542d861447564bdb943a893e0f443c106e26512fc4c6ab44e752e183498242022-07-23 7:27:3173 days 3 hrs ago 0x2333722ba53d11cd76899b1c04a26949617f2254 0x134a48f02bb8d160e4a75fc2a13de721f28a8f410 ETH
0xe38710acc7ca393edf59f6777674a498c56a626412ef3dbe81120743675b6e6b183498082022-07-23 7:27:3173 days 3 hrs ago 0x2333722ba53d11cd76899b1c04a26949617f2254 0x134a48f02bb8d160e4a75fc2a13de721f28a8f410 ETH
0x4c61efa7c79fb81b1d2a00c09ff705d6193e5fc9f92852ae64ce3a7f5484f0ee183497942022-07-23 7:27:3173 days 3 hrs ago 0x2333722ba53d11cd76899b1c04a26949617f2254 0x134a48f02bb8d160e4a75fc2a13de721f28a8f410 ETH
0xf7b925fc7d54626b572cf3b8779a704c99106351101aac9bb0df06d52eb4abcb183497772022-07-23 7:27:3173 days 3 hrs ago 0x2333722ba53d11cd76899b1c04a26949617f2254 0x134a48f02bb8d160e4a75fc2a13de721f28a8f410 ETH
0x5caf7559178119a7446dfff7a7e1c50265be1761b86722a71881a8b8f40ad4d7183497752022-07-23 7:27:3173 days 3 hrs ago 0x2333722ba53d11cd76899b1c04a26949617f2254 0x134a48f02bb8d160e4a75fc2a13de721f28a8f410 ETH
0xb227460f8e037d57848ba38384b5e00598444708bf6246024c68a98be45c773f183497712022-07-23 7:27:3173 days 3 hrs ago 0x2333722ba53d11cd76899b1c04a26949617f2254 0x134a48f02bb8d160e4a75fc2a13de721f28a8f410 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
RangoV1

Compiler Version
v0.8.13+commit.abaa5c0e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Unlicense license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 31 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract 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 Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

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

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

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

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

File 2 of 31 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @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]
 * ```
 * 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. Equivalent to `reinitializer(1)`.
     */
    modifier initializer() {
        bool isTopLevelCall = _setInitializedVersion(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.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so 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.
     *
     * 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.
     */
    modifier reinitializer(uint8 version) {
        bool isTopLevelCall = _setInitializedVersion(version);
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _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.
     */
    function _disableInitializers() internal virtual {
        _setInitializedVersion(type(uint8).max);
    }

    function _setInitializedVersion(uint8 version) private returns (bool) {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
        // of initializers, because in other contexts the contract may have been reentered.
        if (_initializing) {
            require(
                version == 1 && !AddressUpgradeable.isContract(address(this)),
                "Initializable: contract is already initialized"
            );
            return false;
        } else {
            require(_initialized < version, "Initializable: contract is already initialized");
            _initialized = version;
            return true;
        }
    }
}

File 3 of 31 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

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

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        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;
}

File 4 of 31 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.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() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_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;
}

File 5 of 31 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 6 of 31 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

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

    function safeTransferFrom(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(IERC20Upgradeable 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 7 of 31 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [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://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 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 8 of 31 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

File 9 of 31 : SafeMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

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

File 10 of 31 : RangoCBridgeModels.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

library RangoCBridgeModels {
    struct RangoCBridgeInterChainMessage {
        uint64 dstChainId;
        bool bridgeNativeOut;
        address dexAddress;
        address fromToken;
        address toToken;
        uint amountOutMin;
        address[] path;
        uint deadline;
        bool nativeOut;
        address originalSender;
        address recipient;

        // Extra message
        bytes dAppMessage;
        address dAppSourceContract;
        address dAppDestContract;
    }
}

File 11 of 31 : RangoHopModels.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

library RangoHopModels {
    enum ActionType { SWAP_AND_SEND, SEND_TO_L2 }

    struct HopRequest {
        ActionType actionType;
        address bridgeAddress;
        uint256 chainId;
        address recipient;
        uint256 bonderFee;
        uint256 amountOutMin;
        uint256 deadline;
        uint256 destinationAmountOutMin;
        uint256 destinationDeadline;
        address relayer;
        uint256 relayerFee;
    }

}

File 12 of 31 : RangoMultichainModels.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

library RangoMultichainModels {
    enum MultichainBridgeType { OUT, OUT_UNDERLYING, OUT_NATIVE }
}

File 13 of 31 : RangoSynapseModels.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

library RangoSynapseModels {
    enum SynapseBridgeType {
        SWAP_AND_REDEEM,
        SWAP_ETH_AND_REDEEM,
        SWAP_AND_REDEEM_AND_SWAP,
        SWAP_AND_REDEEM_AND_REMOVE,
        REDEEM,
        REDEEM_AND_SWAP,
        REDEEM_AND_REMOVE,
        DEPOSIT,
        DEPOSIT_ETH,
        DEPOSIT_AND_SWAP,
        DEPOSIT_ETH_AND_SWAP,
        ZAP_AND_DEPOSIT,
        ZAP_AND_DEPOSIT_AND_SWAP
    }

    /// @notice The request object for Synapse bridge call
    struct SynapseBridgeRequest {
        RangoSynapseModels.SynapseBridgeType bridgeType;
        address router;
        address to;
        uint256 chainId;
        address token;
        uint8 tokenIndexFrom;
        uint8 tokenIndexTo;
        uint256 minDy;
        uint256 deadline;
        uint8 swapTokenIndexFrom;
        uint8 swapTokenIndexTo;
        uint256 swapMinDy;
        uint256 swapDeadline;
        uint256[] liquidityAmounts;
    }

    event SynapseBridgeEvent(
        address inputToken,
        uint inputAmount,
        SynapseBridgeType bridgeType,
        address to,
        uint256 chainId,
        address token
    );

    event SynapseBridgeDetailEvent(
        uint8 tokenIndexFrom,
        uint8 tokenIndexTo,
        uint256 minDy,
        uint256 deadline,
        uint8 swapTokenIndexFrom,
        uint8 swapTokenIndexTo,
        uint256 swapMinDy,
        uint256 swapDeadline
    );
}

File 14 of 31 : BaseProxyContract.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../../interfaces/IWETH.sol";
import "../../interfaces/IThorchainRouter.sol";

/// @title The base contract that RangoV1 and all its parents inherit to support refund, on-chain swap, and DEX whitelisting
/// @author Uchiha Sasuke
/// @notice It contains storage for whitelisted contracts, refund ERC20 and native tokens and on-chain swap
contract BaseProxyContract is PausableUpgradeable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
    address payable constant NULL_ADDRESS = payable(0x0000000000000000000000000000000000000000);

    /// @notice The maximum possible percent of fee that Rango will receive from user times 10,000, so 300 = 3%
    /// @dev The real fee is calculated by smart routing off-chain, this field only limits the value to prevent mis-calculations
    uint constant MAX_FEE_PERCENT_x_10000 = 300;

    /// @notice The maximum possible percent of fee that third-party dApp will receive from user times 10,000, so 300 = 3%
    /// @dev The real fee is calculated by smart routing off-chain, this field only limits the value to prevent mis-calculations
    uint constant MAX_AFFILIATE_PERCENT_x_10000 = 300;

    using SafeMathUpgradeable for uint;

    /// @dev keccak256("exchange.rango.baseproxycontract")
    bytes32 internal constant BASE_PROXY_CONTRACT_NAMESPACE = hex"c23df90b6466cfd0cbf4f6a578f167d2f60ed56371b4746a3c5973c8543f4fd9";

    struct BaseProxyStorage {
        address payable feeContractAddress;
        address nativeWrappedAddress;
        mapping (address => bool) whitelistContracts;
    }

    /// @notice Rango received a fee reward
    /// @param token The address of received token, ZERO address for native
    /// @param wallet The address of receiver wallet
    /// @param amount The amount received as fee
    event FeeReward(address token, address wallet, uint amount);

    /// @notice Some money is sent to dApp wallet as affiliate reward
    /// @param token The address of received token, ZERO address for native
    /// @param wallet The address of receiver wallet
    /// @param amount The amount received as fee
    event AffiliateReward(address token, address wallet, uint amount);

    /// @notice A call to another dex or contract done and here is the result
    /// @param target The address of dex or contract that is called
    /// @param success A boolean indicating that the call was success or not
    /// @param returnData The response of function call
    event CallResult(address target, bool success, bytes returnData);

    /// @notice Output amount of a dex calls is logged
    /// @param _token The address of output token, ZERO address for native
    /// @param amount The amount of output
    event DexOutput(address _token, uint amount);

    /// @notice The output money (ERC20/Native) is sent to a wallet
    /// @param _token The token that is sent to a wallet, ZERO address for native
    /// @param _amount The sent amount
    /// @param _receiver The receiver wallet address
    /// @param _nativeOut means the output was native token
    /// @param _withdraw If true, indicates that we swapped WETH to ETH before sending the money and _nativeOut is also true
    event SendToken(address _token, uint256 _amount, address _receiver, bool _nativeOut, bool _withdraw);

    /// @notice Notifies that a new contract is whitelisted
    /// @param _factory The address of the contract
    event ContractWhitelisted(address _factory);

    /// @notice Notifies that a new contract is blacklisted
    /// @param _factory The address of the contract
    event ContractBlacklisted(address _factory);

    /// @notice Notifies that Rango's fee receiver address updated
    /// @param _oldAddress The previous fee wallet address
    /// @param _newAddress The new fee wallet address
    event FeeContractAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice Notifies that admin manually refunded some money
    /// @param _token The address of refunded token, 0x000..00 address for native token
    /// @param _amount The amount that is refunded
    event Refunded(address _token, uint _amount);

    /// @notice The requested call data which is computed off-chain and passed to the contract
    /// @param target The dex contract address that should be called
    /// @param callData The required data field that should be give to the dex contract to perform swap
    struct Call { address payable target; bytes callData; }

    /// @notice General swap request which is given to us in all relevant functions
    /// @param fromToken The source token that is going to be swapped (in case of simple swap or swap + bridge) or the briding token (in case of solo bridge)
    /// @param toToken The output token of swapping. This is the output of DEX step and is also input of bridging step
    /// @param amountIn The amount of input token to be swapped
    /// @param feeIn The amount of fee charged by Rango
    /// @param affiliateIn The amount of fee charged by affiliator dApp
    /// @param affiliatorAddress The wallet address that the affiliator fee should be sent to
    struct SwapRequest {
        address fromToken;
        address toToken;
        uint amountIn;
        uint feeIn;
        uint affiliateIn;
        address payable affiliatorAddress;
    }

    /// @notice Adds a contract to the whitelisted DEXes that can be called
    /// @param _factory The address of the DEX
    function addWhitelist(address _factory) external onlyOwner {
        BaseProxyStorage storage baseProxyStorage = getBaseProxyContractStorage();
        baseProxyStorage.whitelistContracts[_factory] = true;

        emit ContractWhitelisted(_factory);
    }

    /// @notice Removes a contract from the whitelisted DEXes that can be called
    /// @param _factory The address of the DEX
    function removeWhitelist(address _factory) external onlyOwner {
        BaseProxyStorage storage baseProxyStorage = getBaseProxyContractStorage();
        require(baseProxyStorage.whitelistContracts[_factory], 'Factory not found');
        delete baseProxyStorage.whitelistContracts[_factory];

        emit ContractBlacklisted(_factory);
    }

    /// @notice Sets the wallet that receives Rango's fees from now on
    /// @param _address The receiver wallet address
    function updateFeeContractAddress(address payable _address) external onlyOwner {
        BaseProxyStorage storage baseProxyStorage = getBaseProxyContractStorage();

        address oldAddress = baseProxyStorage.feeContractAddress;
        baseProxyStorage.feeContractAddress = _address;

        emit FeeContractAddressUpdated(oldAddress, _address);
    }

    /// @notice Transfers an ERC20 token from this contract to msg.sender
    /// @dev This endpoint is to return money to a user if we didn't handle failure correctly and the money is still in the contract
    /// @dev Currently the money goes to admin and they should manually transfer it to a wallet later
    /// @param _tokenAddress The address of ERC20 token to be transferred
    /// @param _amount The amount of money that should be transfered
    function refund(address _tokenAddress, uint256 _amount) external onlyOwner {
        IERC20Upgradeable ercToken = IERC20Upgradeable(_tokenAddress);
        uint balance = ercToken.balanceOf(address(this));
        require(balance >= _amount, 'Insufficient balance');

        SafeERC20Upgradeable.safeTransfer(ercToken, msg.sender, _amount);

        emit Refunded(_tokenAddress, _amount);
    }

    /// @notice Transfers the native token from this contract to msg.sender
    /// @dev This endpoint is to return money to a user if we didn't handle failure correctly and the money is still in the contract
    /// @dev Currently the money goes to admin and they should manually transfer it to a wallet later
    /// @param _amount The amount of native token that should be transfered
    function refundNative(uint256 _amount) external onlyOwner {
        uint balance = address(this).balance;
        require(balance >= _amount, 'Insufficient balance');

        _sendToken(NULL_ADDRESS, _amount, msg.sender, true, false);

        emit Refunded(NULL_ADDRESS, _amount);
    }

    /// @notice Does a simple on-chain swap
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls
    /// @param nativeOut indicates that the output of swaps must be a native token
    /// @return The byte array result of all DEX calls
    function onChainSwaps(
        SwapRequest memory request,
        Call[] calldata calls,
        bool nativeOut
    ) external payable whenNotPaused nonReentrant returns (bytes[] memory) {
        (bytes[] memory result, uint outputAmount) = onChainSwapsInternal(request, calls);

        _sendToken(request.toToken, outputAmount, msg.sender, nativeOut, false);
        return result;
    }

    /// @notice Internal function to compute output amount of DEXes
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls
    /// @return The response of all DEX calls and the output amount of the whole process
    function onChainSwapsInternal(SwapRequest memory request, Call[] calldata calls) internal returns (bytes[] memory, uint) {

        uint toBalanceBefore = getBalanceOf(request.toToken);
        uint fromBalanceBefore = getBalanceOf(request.fromToken);

        bytes[] memory result = callSwapsAndFees(request, calls);

        uint toBalanceAfter = getBalanceOf(request.toToken);
        uint fromBalanceAfter = getBalanceOf(request.fromToken);

        if (request.fromToken != NULL_ADDRESS)
            require(fromBalanceAfter >= fromBalanceBefore, 'Source token balance on contract must not decrease after swap');
        else
            require(fromBalanceAfter >= fromBalanceBefore - msg.value, 'Source token balance on contract must not decrease after swap');

        uint secondaryBalance;
        if (calls.length > 0) {
            require(toBalanceAfter - toBalanceBefore > 0, "No balance found after swaps");

            secondaryBalance = toBalanceAfter - toBalanceBefore;
            emit DexOutput(request.toToken, secondaryBalance);
        } else {
            secondaryBalance = toBalanceAfter > toBalanceBefore ? toBalanceAfter - toBalanceBefore : request.amountIn;
        }

        return (result, secondaryBalance);
    }

    /// @notice Private function to handle fetching money from wallet to contract, reduce fee/affiliate, perform DEX calls
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls
    /// @dev It checks the whitelisting of all DEX addresses + having enough msg.value as input
    /// @dev It checks the max threshold for fee/affiliate
    /// @return The bytes of all DEX calls response
    function callSwapsAndFees(SwapRequest memory request, Call[] calldata calls) private returns (bytes[] memory) {
        bool isSourceNative = request.fromToken == NULL_ADDRESS;
        BaseProxyStorage storage baseProxyStorage = getBaseProxyContractStorage();
        
        // validate
        require(baseProxyStorage.feeContractAddress != NULL_ADDRESS, "Fee contract address not set");

        for(uint256 i = 0; i < calls.length; i++) {
            require(baseProxyStorage.whitelistContracts[calls[i].target], "Contract not whitelisted");
        }

        // Get all the money from user
        uint totalInputAmount = request.feeIn + request.affiliateIn + request.amountIn;
        if (isSourceNative)
            require(msg.value >= totalInputAmount, "Not enough ETH provided to contract");

        // Check max fee/affiliate is respected
        uint maxFee = totalInputAmount * MAX_FEE_PERCENT_x_10000 / 10000;
        uint maxAffiliate = totalInputAmount * MAX_AFFILIATE_PERCENT_x_10000 / 10000;
        require(request.feeIn <= maxFee, 'Requested fee exceeded max threshold');
        require(request.affiliateIn <= maxAffiliate, 'Requested affiliate reward exceeded max threshold');

        // Transfer from wallet to contract
        if (!isSourceNative) {
            for(uint256 i = 0; i < calls.length; i++) {
                approve(request.fromToken, calls[i].target, totalInputAmount);
            }

            uint balanceBefore = getBalanceOf(request.fromToken);
            SafeERC20Upgradeable.safeTransferFrom(IERC20Upgradeable(request.fromToken), msg.sender, address(this), totalInputAmount);
            uint balanceAfter = getBalanceOf(request.fromToken);

            if(balanceAfter > balanceBefore && balanceAfter - balanceBefore < totalInputAmount)
                revert("Deflationary tokens are not supported by Rango contract");
        }

        // Get Platform fee
        if (request.feeIn > 0) {
            _sendToken(request.fromToken, request.feeIn, baseProxyStorage.feeContractAddress, isSourceNative, false);
            emit FeeReward(request.fromToken, baseProxyStorage.feeContractAddress, request.feeIn);
        }

        // Get affiliator fee
        if (request.affiliateIn > 0) {
            require(request.affiliatorAddress != NULL_ADDRESS, "Invalid affiliatorAddress");
            _sendToken(request.fromToken, request.affiliateIn, request.affiliatorAddress, isSourceNative, false);
            emit AffiliateReward(request.fromToken, request.affiliatorAddress, request.affiliateIn);
        }

        bytes[] memory returnData = new bytes[](calls.length);
        for (uint256 i = 0; i < calls.length; i++) {
            (bool success, bytes memory ret) = isSourceNative
                ? calls[i].target.call{value: request.amountIn}(calls[i].callData)
                : calls[i].target.call(calls[i].callData);

            emit CallResult(calls[i].target, success, ret);
            if (!success)
                revert(_getRevertMsg(ret));
            returnData[i] = ret;
        }

        return returnData;
    }

    /// @notice Approves an ERC20 token to a contract to transfer from the current contract
    /// @param token The address of an ERC20 token
    /// @param to The contract address that should be approved
    /// @param value The amount that should be approved
    function approve(address token, address to, uint value) internal {
        SafeERC20Upgradeable.safeApprove(IERC20Upgradeable(token), to, 0);
        SafeERC20Upgradeable.safeIncreaseAllowance(IERC20Upgradeable(token), to, value);
    }

    /// @notice An internal function to send a token from the current contract to another contract or wallet
    /// @dev This function also can convert WETH to ETH before sending if _withdraw flat is set to true
    /// @dev To send native token _nativeOut param should be set to true, otherwise we assume it's an ERC20 transfer
    /// @param _token The token that is going to be sent to a wallet, ZERO address for native
    /// @param _amount The sent amount
    /// @param _receiver The receiver wallet address or contract
    /// @param _nativeOut means the output is native token
    /// @param _withdraw If true, indicates that we should swap WETH to ETH before sending the money and _nativeOut must also be true
    function _sendToken(
        address _token,
        uint256 _amount,
        address _receiver,
        bool _nativeOut,
        bool _withdraw
    ) internal {
        BaseProxyStorage storage baseProxyStorage = getBaseProxyContractStorage();
        emit SendToken(_token, _amount, _receiver, _nativeOut, _withdraw);

        if (_nativeOut) {
            if (_withdraw) {
                require(_token == baseProxyStorage.nativeWrappedAddress, "token mismatch");
                IWETH(baseProxyStorage.nativeWrappedAddress).withdraw(_amount);
            } else {
                require(_token == NULL_ADDRESS, 'Token address must be 0x00...0 for native out');
            }
            _sendNative(_receiver, _amount);
        } else {
            SafeERC20Upgradeable.safeTransfer(IERC20Upgradeable(_token), _receiver, _amount);
        }
    }

    /// @notice An internal function to send native token to a contract or wallet
    /// @param _receiver The address that will receive the native token
    /// @param _amount The amount of the native token that should be sent
    function _sendNative(address _receiver, uint _amount) internal {
        (bool sent, ) = _receiver.call{value: _amount}("");
        require(sent, "failed to send native");
    }


    /// @notice A utility function to fetch storage from a predefined random slot using assembly
    /// @return s The storage object
    function getBaseProxyContractStorage() internal pure returns (BaseProxyStorage storage s) {
        bytes32 namespace = BASE_PROXY_CONTRACT_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }

    /// @notice To extract revert message from a DEX/contract call to represent to the end-user in the blockchain
    /// @param _returnData The resulting bytes of a failed call to a DEX or contract
    /// @return A string that describes what was the error
    function _getRevertMsg(bytes memory _returnData) internal pure returns (string memory) {
        // If the _res length is less than 68, then the transaction failed silently (without a revert message)
        if (_returnData.length < 68) return 'Transaction reverted silently';

        assembly {
            // Slice the sighash.
            _returnData := add(_returnData, 0x04)
        }
        return abi.decode(_returnData, (string)); // All that remains is the revert string
    }

    function getBalanceOf(address token) internal view returns (uint) {
        IERC20Upgradeable ercToken = IERC20Upgradeable(token);
        return token == NULL_ADDRESS ? address(this).balance : ercToken.balanceOf(address(this));
    }
}

File 15 of 31 : RangoV1.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../libs/BaseProxyContract.sol";
import "./bridges/cbridge/RangoCBridgeProxy.sol";
import "./bridges/thorchain/RangoThorchainProxy.sol";
import "./bridges/multichain/RangoMultichainProxy.sol";
import "./bridges/hyphen/RangoHyphenProxy.sol";
import "./bridges/across/RangoAcrossProxy.sol";
import "./bridges/hop/RangoHopProxy.sol";
import "./bridges/synapse/RangoSynapseProxy.sol";

/// @title The main contract that users interact with in the source chain
/// @author Uchiha Sasuke
/// @notice It contains all the required functions to swap on-chain or swap + bridge or swap + bridge + swap initiation in a single step
/// @dev To support a new bridge, it inherits from a proxy with the name of that bridge which adds extra function for that specific bridge
/// @dev There are some extra refund functions for admin to get the money back in case of any unwanted problem
/// @dev This contract is being seen via a transparent proxy from openzeppelin
contract RangoV1 is BaseProxyContract, RangoCBridgeProxy, RangoThorchainProxy, RangoMultichainProxy, RangoSynapseProxy, RangoHopProxy, RangoAcrossProxy, RangoHyphenProxy {

    /// @notice Initializes the state of all sub bridges contracts that RangoV1 inherited from
    /// @param _nativeWrappedAddress Address of wrapped token (WETH, WBNB, etc.) on the current chain
    /// @dev It is the initializer function of proxy pattern, and is equivalent to constructor for normal contracts
    function initialize(address _nativeWrappedAddress) public initializer {
        BaseProxyStorage storage baseProxyStorage = getBaseProxyContractStorage();
        CBridgeProxyStorage storage cbridgeProxyStorage = getCBridgeProxyStorage();
        ThorchainProxyStorage storage thorchainProxyStorage = getThorchainProxyStorage();
        MultichainProxyStorage storage multichainProxyStorage = getMultichainProxyStorage();
        HyphenProxyStorage storage hyphenProxyStorage = getHyphenProxyStorage();
        AcrossProxyStorage storage acrossProxyStorage = getAcrossProxyStorage();
        HopProxyStorage storage hopProxyStorage = getHopProxyStorage();
        SynapseProxyStorage storage synapseProxyStorage = getSynapseProxyStorage();
        
        baseProxyStorage.nativeWrappedAddress = _nativeWrappedAddress;
        baseProxyStorage.feeContractAddress = NULL_ADDRESS;
        cbridgeProxyStorage.rangoCBridgeAddress = NULL_ADDRESS;
        thorchainProxyStorage.rangoThorchainAddress = NULL_ADDRESS;
        multichainProxyStorage.rangoMultichainAddress = NULL_ADDRESS;
        hyphenProxyStorage.rangoHyphenAddress = NULL_ADDRESS;
        acrossProxyStorage.rangoAcrossAddress = NULL_ADDRESS;
        hopProxyStorage.rangoHopAddress = NULL_ADDRESS;
        synapseProxyStorage.rangoSynapseAddress = NULL_ADDRESS;

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

    /// @notice Enables the contract to receive native ETH token from other contracts including WETH contract
    receive() external payable { }

    /// @notice Returns the list of valid Rango contracts that can call other contracts for the security purpose
    /// @dev This contains the contracts that can call others via messaging protocols, and excludes DEX-only contracts such as Thorchain
    /// @return List of addresses of Rango contracts that can call other contracts
    function getValidRangoContracts() external view returns (address[] memory) {
        CBridgeProxyStorage storage cbridgeProxyStorage = getCBridgeProxyStorage();
        MultichainProxyStorage storage multichainProxyStorage = getMultichainProxyStorage();
        ThorchainProxyStorage storage thorchainProxyStorage = getThorchainProxyStorage();
        SynapseProxyStorage storage synapseProxyStorage = getSynapseProxyStorage();
        AcrossProxyStorage storage acrossProxyStorage = getAcrossProxyStorage();
        HopProxyStorage storage hopProxyStorage = getHopProxyStorage();
        HyphenProxyStorage storage hyphenProxyStorage = getHyphenProxyStorage();

        address[] memory whitelist = new address[](8);
        whitelist[0] = address(this);
        whitelist[1] = cbridgeProxyStorage.rangoCBridgeAddress;
        whitelist[2] = multichainProxyStorage.rangoMultichainAddress;
        whitelist[3] = synapseProxyStorage.rangoSynapseAddress;
        whitelist[4] = acrossProxyStorage.rangoAcrossAddress;
        whitelist[5] = hopProxyStorage.rangoHopAddress;
        whitelist[6] = thorchainProxyStorage.rangoThorchainAddress;
        whitelist[7] = hyphenProxyStorage.rangoHyphenAddress;

        return whitelist;
    }
}

File 16 of 31 : IRangoAcross.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../bridges/multichain/RangoMultichainModels.sol";

/// @title An interface to RangoAcross.sol contract to improve type hinting
/// @author Uchiha Sasuke
interface IRangoAcross {

    /// @notice Executes an Across bridge call
    /// @param spokePoolAddress The address of Across spoke pool that deposit should be done to
    /// @param fromToken The erc20 address of the input token, 0x000...00 for native token
    /// @param recipient Address to receive funds at on destination chain.
    /// @param originToken Token to lock into this contract to initiate deposit.
    /// @param amount Amount of tokens to deposit. Will be amount of tokens to receive less fees.
    /// @param destinationChainId Denotes network where user will receive funds from SpokePool by a relayer.
    /// @param relayerFeePct % of deposit amount taken out to incentivize a fast relayer.
    /// @param quoteTimestamp Timestamp used by relayers to compute this deposit's realizedLPFeePct which is paid to LP pool on HubPool.
    function acrossBridge(
        address spokePoolAddress,
        address fromToken,
        address recipient,
        address originToken,
        uint256 amount,
        uint256 destinationChainId,
        uint64 relayerFeePct,
        uint32 quoteTimestamp
    ) external payable;
}

File 17 of 31 : RangoAcrossProxy.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../libs/BaseProxyContract.sol";
import "./IRangoAcross.sol";

/// @title The functions that allow users to perform an Across call with or without some arbitrary DEX calls
/// @author Uchiha Sasuke
/// @notice It contains functions to call Across bridge
/// @dev This contract only handles the DEX part and calls RangoAcross.sol functions via contact call to perform the bridiging step
contract RangoAcrossProxy is BaseProxyContract {

    /// @dev keccak256("exchange.rango.across.proxy")
    bytes32 internal constant RANGO_ACROSS_PROXY_NAMESPACE = hex"677e79f0e4009f1792a10267078e7120af47266c8ce03085f21aef7ba016b06f";

    struct AcrossProxyStorage {
        address rangoAcrossAddress;
    }

    /// @notice Notifies that the RangoAcross.sol contract address is updated
    /// @param _oldAddress The previous deployed address
    /// @param _newAddress The new deployed address
    event RangoAcrossAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice The request object for Across bridge call
    /// @param spokePoolAddress The address of Across spoke pool that deposit should be done to
    /// @param recipient Address to receive funds at on destination chain.
    /// @param originToken Token to lock into this contract to initiate deposit.
    /// @param destinationChainId Denotes network where user will receive funds from SpokePool by a relayer.
    /// @param relayerFeePct % of deposit amount taken out to incentivize a fast relayer.
    /// @param quoteTimestamp Timestamp used by relayers to compute this deposit's realizedLPFeePct which is paid to LP pool on HubPool.
    struct AcrossBridgeRequest {
        address spokePoolAddress;
        address recipient;
        address originToken;
        uint256 destinationChainId;
        uint64 relayerFeePct;
        uint32 quoteTimestamp;
    }

    /// @notice Updates the address of deployed RangoAcross.sol contract
    /// @param _address The address
    function updateRangoAcrossAddress(address _address) external onlyOwner {
        AcrossProxyStorage storage acrossProxyStorage = getAcrossProxyStorage();

        address oldAddress = acrossProxyStorage.rangoAcrossAddress;
        acrossProxyStorage.rangoAcrossAddress = _address;

        emit RangoAcrossAddressUpdated(oldAddress, _address);
    }

    /// @notice Executes a DEX (arbitrary) call + a Across bridge call
    /// @dev The bridge part is handled in the RangoAcross.sol contract
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
    /// @param bridgeRequest required data for the bridging step, including the destination chain and recipient wallet address
    function acrossBridge(
        SwapRequest memory request,
        Call[] calldata calls,
        AcrossBridgeRequest memory bridgeRequest
    ) external payable whenNotPaused nonReentrant {
        AcrossProxyStorage storage proxyStorage = getAcrossProxyStorage();
        require(proxyStorage.rangoAcrossAddress != NULL_ADDRESS, 'Across address in Rango contract not set');

        bool isNative = request.fromToken == NULL_ADDRESS;
        uint minimumRequiredValue = isNative ? request.feeIn + request.affiliateIn + request.amountIn : 0;
        require(msg.value >= minimumRequiredValue, 'Send more ETH to cover input amount + fee');

        (, uint out) = onChainSwapsInternal(request, calls);
        if (request.toToken != NULL_ADDRESS)
            approve(request.toToken, proxyStorage.rangoAcrossAddress, out);

        uint value = request.toToken == NULL_ADDRESS ? (out > 0 ? out : request.amountIn) : 0;

        IRangoAcross(proxyStorage.rangoAcrossAddress).acrossBridge{value: value}(
            bridgeRequest.spokePoolAddress,
            request.toToken,
            bridgeRequest.recipient,
            bridgeRequest.originToken,
            out,
            bridgeRequest.destinationChainId,
            bridgeRequest.relayerFeePct,
            bridgeRequest.quoteTimestamp
        );
    }

    /// @notice A utility function to fetch storage from a predefined random slot using assembly
    /// @return s The storage object
    function getAcrossProxyStorage() internal pure returns (AcrossProxyStorage storage s) {
        bytes32 namespace = RANGO_ACROSS_PROXY_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }
}

File 18 of 31 : IRangoCBridge.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../bridges/cbridge/RangoCBridgeModels.sol";

/// @title An interface to RangoCBridge.sol contract to improve type hinting
/// @author Uchiha Sasuke
interface IRangoCBridge {

    /// @notice Executes a cBridgeIM call
    /// @param _fromToken The address of source token to bridge
    /// @param _inputAmount The amount of input to be bridged
    /// @param _receiverContract Our RangoCbridge.sol contract in the destination chain that will handle the destination logic
    /// @param _dstChainId The network id of destination chain, ex: 10 for optimism
    /// @param _nonce A nonce mechanism used by cBridge that is generated off-chain, it normally is the time.now()
    /// @param _maxSlippage The maximum tolerable slippage by user on cBridge side (The bridge is not 1-1 and may have slippage in big swaps)
    /// @param _sgnFee The fee amount (in native token) that cBridge IM charges for delivering the message
    /// @param imMessage Our custom interchain message that contains all the required info for the RangoCBridge.sol on the destination
    function cBridgeIM(
        address _fromToken,
        uint _inputAmount,
        address _receiverContract, // The receiver app contract address, not recipient
        uint64 _dstChainId,
        uint64 _nonce,
        uint32 _maxSlippage,
        uint _sgnFee,

        RangoCBridgeModels.RangoCBridgeInterChainMessage memory imMessage
    ) external payable;

    /// @notice Executes a bridging via cBridge
    /// @param _receiver The receiver address in the destination chain
    /// @param _token The token address to be bridged
    /// @param _amount The amount of the token to be bridged
    /// @param _dstChainId The network id of destination chain, ex: 10 for optimism
    /// @param _nonce A nonce mechanism used by cBridge that is generated off-chain, it normally is the time.now()
    /// @param _maxSlippage The maximum tolerable slippage by user on cBridge side (The bridge is not 1-1 and may have slippage in big swaps)
    function send(
        address _receiver,
        address _token,
        uint256 _amount,
        uint64 _dstChainId,
        uint64 _nonce,
        uint32 _maxSlippage
    ) external;

}

File 19 of 31 : RangoCBridgeProxy.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../libs/BaseProxyContract.sol";
import "./IRangoCBridge.sol";

/// @title The functions that allow users to perform a cbridge call with or without some arbitrary DEX calls
/// @author Uchiha Sasuke
/// @notice It contains functions to call cbridge.send for simple transfers or Celer IM for cross-chain messaging
/// @dev This contract only handles the DEX part and calls RangoCBridge.sol functions via contact call to perform the bridiging step
contract RangoCBridgeProxy is BaseProxyContract {

    /// @dev keccak256("exchange.rango.cbridge.proxy")
    bytes32 internal constant RANGO_CBRIDGE_PROXY_NAMESPACE = hex"e9cf4febccbfad5ef15964f91cb6c48fe594747e386f28fc2b067ddf16f1ed5d";

    struct CBridgeProxyStorage {
        address rangoCBridgeAddress;
    }

    /// @notice Notifies that the RangoCBridge.sol contract address is updated
    /// @param _oldAddress The previous deployed address
    /// @param _newAddress The new deployed address
    event RangoCBridgeAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice Updates the address of deployed RangoCBridge.sol contract
    /// @param _address The address
    function updateRangoCBridgeAddress(address _address) external onlyOwner {
        CBridgeProxyStorage storage cbridgeProxyStorage = getCBridgeProxyStorage();

        address oldAddress = cbridgeProxyStorage.rangoCBridgeAddress;
        cbridgeProxyStorage.rangoCBridgeAddress = _address;

        emit RangoCBridgeAddressUpdated(oldAddress, _address);
    }

    /// @notice Executes a DEX (arbitrary) call + a cBridge send function
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
    /// @param _receiver The receiver address in the destination chain
    /// @param _dstChainId The network id of destination chain, ex: 10 for optimism
    /// @param _nonce A nonce mechanism used by cBridge that is generated off-chain, it normally is the time.now()
    /// @param _maxSlippage The maximum tolerable slippage by user on cBridge side (The bridge is not 1-1 and may have slippage in big swaps)
    /// @dev The cbridge part is handled in the RangoCBridge.sol contract
    /// @dev If this function is success, user will automatically receive the fund in the destination in his/her wallet (_receiver)
    /// @dev If bridge is out of liquidity somehow after submiting this transaction and success, user must sign a refund transaction which is not currently present here, will be supported soon
    function cBridgeSend(
        SwapRequest memory request,
        Call[] calldata calls,

        // cbridge params
        address _receiver,
        uint64 _dstChainId,
        uint64 _nonce,
        uint32 _maxSlippage
    ) external payable whenNotPaused nonReentrant {
        CBridgeProxyStorage storage cbridgeProxyStorage = getCBridgeProxyStorage();
        require(cbridgeProxyStorage.rangoCBridgeAddress != NULL_ADDRESS, 'cBridge address in Rango contract not set');

        bool isNative = request.fromToken == NULL_ADDRESS;
        uint minimumRequiredValue = isNative ? request.feeIn + request.affiliateIn + request.amountIn : 0;
        require(msg.value >= minimumRequiredValue, 'Send more ETH to cover input amount');

        (, uint out) = onChainSwapsInternal(request, calls);
        approve(request.toToken, cbridgeProxyStorage.rangoCBridgeAddress, out);

        IRangoCBridge(cbridgeProxyStorage.rangoCBridgeAddress)
            .send(_receiver, request.toToken, out, _dstChainId, _nonce, _maxSlippage);
    }

    /// @notice Executes a DEX (arbitrary) call + a cBridge IM function
    /// @dev The cbridge part is handled in the RangoCBridge.sol contract
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
    /// @param _receiverContract Our RangoCbridge.sol contract in the destination chain that will handle the destination logic
    /// @param _dstChainId The network id of destination chain, ex: 10 for optimism
    /// @param _nonce A nonce mechanism used by cBridge that is generated off-chain, it normally is the time.now()
    /// @param _maxSlippage The maximum tolerable slippage by user on cBridge side (The bridge is not 1-1 and may have slippage in big swaps)
    /// @param _sgnFee The fee amount (in native token) that cBridge IM charges for delivering the message
    /// @param imMessage Our custom interchain message that contains all the required info for the RangoCBridge.sol on the destination
    /// @dev The msg.value should at least be _sgnFee + (input + fee + affiliate) if input is native token
    /**
     * @dev Here is the overall flow for a cross-chain dApp that integrates Rango + cBridgeIM:
     * Example case: RangoSea is an imaginary cross-chain OpenSea that users can lock their NFT on BSC to get 100 BNB
     * and convert it to FTM to buy another NFT there, all in one TX.
     * RangoSea contract = RS
     * Rango contract = R
     *
     * 1. RangoSea server asks Rango for a quote of 100 BSC.BNB to Fantom.FTM and embeds the message (imMessage.dAppMessage) that should be received by RS on destination
     * 2. User signs sellNFTandBuyCrosschain on RS
     * 3. RS executes their own logic and locks the NFT, gets 100 BNB and calls R with the hex from step 1 (which is cBridgeIM function call)
     * 4. R on source chain does the required swap/bridge
     * 5. R on destination receives the message via Celer network (by calling RangoCBridge.executeMessageWithTransfer on dest) and does other Rango internal stuff on destination to have the final FTM
     * 6. R on dest sends fund to RS on dest and calls their handler function for message handling and passes imMessage.dAppMessage to it
     * 7. RS on destination has the money and the message it needs to buy the NFT on destination and if it is still available it will be purchased
     *
     * Failure scenarios:
     * If cBridge does not have enough liquidity later:
     * 1. Celer network will call (RangoCBridge on source chain).executeMessageWithTransferRefund function
     * 2. RangoCbridge will refund money to the RS contract on source and ask it to handle refund to their own users
     *
     * If something on the destination fails:
     * 1. Celer network will call (RangoCBridge on dest chain).executeMessageWithTransferFallback function
     * 2. R on dest sends fund to RS on dest with refund reason, again RS should send it to your user if you like
     *
     * Hint: The dAppMessage part is arbitrary, if it's not set. The scenario is the same as above but without RS being in. In this case Rango will refund to the end-user.
     * Here is the celer IM docs: https://im-docs.celer.network/
     */
    function cBridgeIM(
        SwapRequest memory request,
        Call[] calldata calls,

        address _receiverContract, // The receiver app contract address, not recipient
        uint64 _dstChainId,
        uint64 _nonce,
        uint32 _maxSlippage,
        uint _sgnFee,

        RangoCBridgeModels.RangoCBridgeInterChainMessage memory imMessage
    ) external payable whenNotPaused nonReentrant {
        CBridgeProxyStorage storage cbridgeProxyStorage = getCBridgeProxyStorage();
        require(cbridgeProxyStorage.rangoCBridgeAddress != NULL_ADDRESS, 'cBridge address in Rango contract not set');

        bool isNative = request.fromToken == NULL_ADDRESS;
        uint minimumRequiredValue = (isNative ? request.feeIn + request.affiliateIn + request.amountIn : 0) + _sgnFee;
        require(msg.value >= minimumRequiredValue, 'Send more ETH to cover sgnFee + input amount');

        (, uint out) = onChainSwapsInternal(request, calls);
        approve(request.toToken, cbridgeProxyStorage.rangoCBridgeAddress, out);

        IRangoCBridge(cbridgeProxyStorage.rangoCBridgeAddress).cBridgeIM{value: _sgnFee}(
            request.toToken,
            out,
            _receiverContract,
            _dstChainId,
            _nonce,
            _maxSlippage,
            _sgnFee,
            imMessage
        );
    }


    /// @notice A utility function to fetch storage from a predefined random slot using assembly
    /// @return s The storage object
    function getCBridgeProxyStorage() internal pure returns (CBridgeProxyStorage storage s) {
        bytes32 namespace = RANGO_CBRIDGE_PROXY_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }
}

File 20 of 31 : IRangoHop.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../bridges/hop/RangoHopModels.sol";

/// @title An interface to RangoHop.sol contract to improve type hinting
/// @author Uchiha Sasuke
interface IRangoHop {
    /// @notice Executes a Hop bridge call
    /// @param _request The request object containing required field by hop bridge
    /// @param _amount The amount to be bridged
    function hopBridge(
        RangoHopModels.HopRequest memory _request,
        address fromToken,
        uint _amount
    ) external payable;
}

File 21 of 31 : RangoHopProxy.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../libs/BaseProxyContract.sol";
import "./IRangoHop.sol";
import "../../../bridges/hop/RangoHopModels.sol";

/// @title The functions that allow users to perform a Hop call with or without some arbitrary DEX calls
/// @author Uchiha Sasuke
/// @notice It contains functions to call Hop bridge
/// @dev This contract only handles the DEX part and calls RangoHop.sol functions via contact call to perform the bridiging step
contract RangoHopProxy is BaseProxyContract {

    /// @dev keccak256("exchange.rango.hop.proxy")
    bytes32 internal constant RANGO_HOP_PROXY_NAMESPACE = hex"15410819d7d6216709939083a650939157bf8023516c3537a5272f9c42b704a2";

    struct HopProxyStorage {
        address rangoHopAddress;
    }

    /// @notice Notifies that the RangoHop.sol contract address is updated
    /// @param _oldAddress The previous deployed address
    /// @param _newAddress The new deployed address
    event RangoHopAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice Updates the address of deployed RangoHop.sol contract
    /// @param _address The address
    function updateRangoHopAddress(address _address) external onlyOwner {
        HopProxyStorage storage proxyStorage = getHopProxyStorage();

        address oldAddress = proxyStorage.rangoHopAddress;
        proxyStorage.rangoHopAddress = _address;

        emit RangoHopAddressUpdated(oldAddress, _address);
    }

    /// @notice Executes a DEX (arbitrary) call + a Hop bridge call
    /// @dev The bridge part is handled in the RangoHop.sol contract
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
    /// @param bridgeRequest required data for the bridging step, including the destination chain and recipient wallet address
    function hopBridge(
        SwapRequest memory request,
        Call[] calldata calls,
        RangoHopModels.HopRequest memory bridgeRequest
    ) external payable whenNotPaused nonReentrant {
        HopProxyStorage storage proxyStorage = getHopProxyStorage();
        require(proxyStorage.rangoHopAddress != NULL_ADDRESS, 'Hop address in Rango contract not set');

        bool isNative = request.fromToken == NULL_ADDRESS;
        uint minimumRequiredValue = isNative ? request.feeIn + request.affiliateIn + request.amountIn : 0;
        require(msg.value >= minimumRequiredValue, 'Send more ETH to cover input amount + fee');

        (, uint out) = onChainSwapsInternal(request, calls);
        if (request.toToken != NULL_ADDRESS)
            approve(request.toToken, proxyStorage.rangoHopAddress, out);

        uint value = request.toToken == NULL_ADDRESS ? (out > 0 ? out : request.amountIn) : 0;

        IRangoHop(proxyStorage.rangoHopAddress).hopBridge{value: value}(bridgeRequest, request.toToken, out);
    }

    /// @notice A utility function to fetch storage from a predefined random slot using assembly
    /// @return s The storage object
    function getHopProxyStorage() internal pure returns (HopProxyStorage storage s) {
        bytes32 namespace = RANGO_HOP_PROXY_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }
}

File 22 of 31 : IRangoHyphen.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

/// @title An interface to RangoHyphen.sol contract to improve type hinting
/// @author Hellboy
interface IRangoHyphen {

    /// @notice Executes a bridging via hyphen
    /// @param _receiver The receiver address in the destination chain
    /// @param _token The requested token to bridge
    /// @param _amount The requested amount to bridge
    /// @param _dstChainId The network id of destination chain, ex: 56 for BSC
    function hyphenBridge(
        address _receiver,
        address _token,
        uint256 _amount,
        uint256 _dstChainId
    ) external;
}

File 23 of 31 : RangoHyphenProxy.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../libs/BaseProxyContract.sol";
import "./IRangoHyphen.sol";

/// @title The functions that allow users to perform a hyphen call
/// @author Hellboy
/// @notice It contains functions to call hyphenBridge for bridging funds between chains
/// @dev This contract only handles the DEX part and calls RangoHyphen.sol functions via contact call to perform the bridging step
contract RangoHyphenProxy is BaseProxyContract {

    //keccak256("exchange.rango.hyphen.proxy")
    bytes32 internal constant RANGO_HYPHEN_PROXY_NAMESPACE = hex"a2cc4f41cf11b520eef4f1381031d11e095bbe59b53dc2a554b45e899a0f9f81";

    struct HyphenProxyStorage {
        address rangoHyphenAddress;
    }

    /// @notice Notifies that the RangoHyphen.sol contract address is updated
    /// @param _oldAddress The previous deployed address
    /// @param _newAddress The new deployed address
    event RangoHyphenAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice Updates the address of deployed RangoHyphen.sol contract
    /// @param _address The address of rangoHyphen contract
    function updateRangoHyphenAddress(address _address) external onlyOwner {
        HyphenProxyStorage storage hyphenProxyStorage = getHyphenProxyStorage();
        address oldAddress = hyphenProxyStorage.rangoHyphenAddress;
        hyphenProxyStorage.rangoHyphenAddress = _address;

        emit RangoHyphenAddressUpdated(oldAddress, _address);
    }

    /// @param receiver The receiver address in the destination chain
    /// @param toChainId The network id of destination chain, ex: 56 for BSC
    struct HyphenBridgeRequest {
        address receiver;
        uint256 toChainId;
    }

    /// @notice Executes a DEX (arbitrary) call + a hyphen bridge function
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
    /// @param bridgeRequest data related to hyphen bridge
    /// @dev The hyphen bridge part is handled in the RangoHyphen.sol contract
    /// @dev If this function is a success, user will automatically receive the fund in the destination in their wallet (_receiver)
    function hyphenBridge(
        SwapRequest memory request,
        Call[] calldata calls,
        HyphenBridgeRequest memory bridgeRequest
    ) external payable whenNotPaused nonReentrant {
        HyphenProxyStorage storage hyphenProxyStorage = getHyphenProxyStorage();
        require(hyphenProxyStorage.rangoHyphenAddress != NULL_ADDRESS, 'hyphen address in Rango contract not set');
        bool isNative = request.fromToken == NULL_ADDRESS;
        uint minimumRequiredValue = isNative ? request.feeIn + request.affiliateIn + request.amountIn : 0;
        require(msg.value >= minimumRequiredValue, 'Send more ETH to cover input amount');

        (, uint out) = onChainSwapsInternal(request, calls);

        if (request.toToken != NULL_ADDRESS)
            approve(request.toToken, hyphenProxyStorage.rangoHyphenAddress, out);

        IRangoHyphen(hyphenProxyStorage.rangoHyphenAddress).hyphenBridge(bridgeRequest.receiver, request.toToken, out, bridgeRequest.toChainId);
    }

    /// @notice A utility function to fetch storage from a predefined random slot using assembly
    /// @return s The storage object
    function getHyphenProxyStorage() internal pure returns (HyphenProxyStorage storage s) {
        bytes32 namespace = RANGO_HYPHEN_PROXY_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }
}

File 24 of 31 : IRangoMultichain.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../bridges/multichain/RangoMultichainModels.sol";

/// @title An interface to RangoMultichain.sol contract to improve type hinting
/// @author Uchiha Sasuke
interface IRangoMultichain {

    /// @notice Executes a MultichainOrg bridge call
    /// @param _actionType The type of bridge action which indicates the name of the function of MultichainOrg contract to be called
    /// @param _fromToken The address of bridging token
    /// @param _underlyingToken For _actionType = OUT_UNDERLYING, it's the address of the underlying token
    /// @param _inputAmount The amount of the token to be bridged
    /// @param multichainRouter Address of MultichainOrg contract on the current chain
    /// @param _receiverAddress The address of end-user on the destination
    /// @param _receiverChainID The network id of destination chain
    function multichainBridge(
        RangoMultichainModels.MultichainBridgeType _actionType,
        address _fromToken,
        address _underlyingToken,
        uint _inputAmount,
        address multichainRouter,
        address _receiverAddress,
        uint _receiverChainID
    ) external payable;

}

File 25 of 31 : RangoMultichainProxy.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../libs/BaseProxyContract.sol";
import "./IRangoMultichain.sol";

/// @title The functions that allow users to perform a MultichainOrg call with or without some arbitrary DEX calls
/// @author Uchiha Sasuke
/// @notice It contains functions to call MultichainOrg bridge
/// @dev This contract only handles the DEX part and calls RangoMultichain.sol functions via contact call to perform the bridiging step
contract RangoMultichainProxy is BaseProxyContract {

    /// @dev keccak256("exchange.rango.multichain.proxy")
    bytes32 internal constant RANGO_MULTICHAIN_PROXY_NAMESPACE = hex"ed7d91da7fb046892c2413e11ecc409c17b784b916ff0fd3fa2d512c567da864";

    struct MultichainProxyStorage {
        address rangoMultichainAddress;
    }

    /// @notice Notifies that the RangoMultichain.sol contract address is updated
    /// @param _oldAddress The previous deployed address
    /// @param _newAddress The new deployed address
    event RangoMultichainAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice The request object for MultichainOrg bridge call
    /// @param _actionType The type of bridge action which indicates the name of the function of MultichainOrg contract to be called
    /// @param _underlyingToken For _actionType = OUT_UNDERLYING, it's the address of the underlying token
    /// @param _multichainRouter Address of MultichainOrg contract on the current chain
    /// @param _receiverAddress The address of end-user on the destination
    /// @param _receiverChainID The network id of destination chain
    struct MultichainBridgeRequest {
        RangoMultichainModels.MultichainBridgeType _actionType;
        address _underlyingToken;
        address _multichainRouter;
        address _receiverAddress;
        uint _receiverChainID;
    }

    /// @notice Updates the address of deployed RangoMultichain.sol contract
    /// @param _address The address
    function updateRangoMultichainAddress(address _address) external onlyOwner {
        MultichainProxyStorage storage multichainProxyStorage = getMultichainProxyStorage();

        address oldAddress = multichainProxyStorage.rangoMultichainAddress;
        multichainProxyStorage.rangoMultichainAddress = _address;

        emit RangoMultichainAddressUpdated(oldAddress, _address);
    }

    /// @notice Executes a DEX (arbitrary) call + a MultichainOrg bridge call
    /// @dev The cbridge part is handled in the RangoMultichain.sol contract
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
    /// @param bridgeRequest required data for the bridging step, including the destination chain and recipient wallet address
    function multichainBridge(
        SwapRequest memory request,
        Call[] calldata calls,
        MultichainBridgeRequest memory bridgeRequest
    ) external payable whenNotPaused nonReentrant {
        MultichainProxyStorage storage multichainProxyStorage = getMultichainProxyStorage();
        require(multichainProxyStorage.rangoMultichainAddress != NULL_ADDRESS, 'Multichain address in Rango contract not set');

        bool isNative = request.fromToken == NULL_ADDRESS;
        uint minimumRequiredValue = isNative ? request.feeIn + request.affiliateIn + request.amountIn : 0;
        require(msg.value >= minimumRequiredValue, 'Send more ETH to cover input amount + fee');

        (, uint out) = onChainSwapsInternal(request, calls);
        if (request.toToken != NULL_ADDRESS)
            approve(request.toToken, multichainProxyStorage.rangoMultichainAddress, out);

        uint value = request.toToken == NULL_ADDRESS ? (out > 0 ? out : request.amountIn) : 0;

        IRangoMultichain(multichainProxyStorage.rangoMultichainAddress).multichainBridge{value: value}(
            bridgeRequest._actionType,
            request.toToken,
            bridgeRequest._underlyingToken,
            out,
            bridgeRequest._multichainRouter,
            bridgeRequest._receiverAddress,
            bridgeRequest._receiverChainID
        );
    }

    /// @notice A utility function to fetch storage from a predefined random slot using assembly
    /// @return s The storage object
    function getMultichainProxyStorage() internal pure returns (MultichainProxyStorage storage s) {
        bytes32 namespace = RANGO_MULTICHAIN_PROXY_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }
}

File 26 of 31 : IRangoSynapse.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../bridges/synapse/RangoSynapseModels.sol";


/// @title An interface to RangoSynapse.sol contract to improve type hinting
/// @author Rango DeXter
interface IRangoSynapse {

    /// @notice Executes a Synapse bridge call
    /// @param inputToken The address of bridging token
    /// @param inputAmount The amount of the token to be bridged
    /// @param request required data for bridge
    function synapseBridge(
        address inputToken,
        uint inputAmount,
        RangoSynapseModels.SynapseBridgeRequest memory request
    ) external payable;

}

File 27 of 31 : RangoSynapseProxy.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "./IRangoSynapse.sol";
import "../../../libs/BaseProxyContract.sol";
import "../../../bridges/synapse/RangoSynapseModels.sol";

/// @title The functions that allow users to perform a Synapse Bridge call with or without some arbitrary DEX calls
/// @author Rango DeXter
/// @notice It contains functions to call Synapse Bridge
/// @dev This contract only handles the DEX part and calls RangoSynapse.sol functions via contact call to perform the bridging step
contract RangoSynapseProxy is BaseProxyContract {

    /// @dev keccak256("exchange.rango.synapse.proxy")
    bytes32 internal constant RANGO_SYNAPSE_PROXY_NAMESPACE = hex"f8ff8b28c44d8cca223cd9f986a0465240ed11ac179f68af36410e3725a13ab6";

    struct SynapseProxyStorage {
        address rangoSynapseAddress;
    }

    /// @notice Notifies that the RangoSynapse.sol contract address is updated
    /// @param _oldAddress The previous deployed address
    /// @param _newAddress The new deployed address
    event RangoSynapseAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice Updates the address of deployed RangoSynapse.sol contract
    /// @param _address The address
    function updateRangoSynapseAddress(address _address) external onlyOwner {
        SynapseProxyStorage storage proxyStorage = getSynapseProxyStorage();
        address oldAddress = proxyStorage.rangoSynapseAddress;
        proxyStorage.rangoSynapseAddress = _address;

        emit RangoSynapseAddressUpdated(oldAddress, _address);
    }

    /// @notice Executes a DEX (arbitrary) call + a Synapse bridge call
    /// @dev The Synapse part is handled in the RangoSynapse.sol contract
    /// @param request The general swap request containing from/to token and fee/affiliate rewards
    /// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
    /// @param bridgeRequest required data for the bridging step, including the destination chain and recipient wallet address
    function synapseBridge(
        SwapRequest memory request,
        Call[] calldata calls,
        RangoSynapseModels.SynapseBridgeRequest memory bridgeRequest
    ) external payable whenNotPaused nonReentrant {
        SynapseProxyStorage storage synapseStorage = getSynapseProxyStorage();
        require(synapseStorage.rangoSynapseAddress != NULL_ADDRESS, 'Synapse address in Rango contract not set');

        bool isNative = request.fromToken == NULL_ADDRESS;
        uint minimumRequiredValue = isNative ? request.feeIn + request.affiliateIn + request.amountIn : 0;
        require(msg.value >= minimumRequiredValue, 'Send more ETH to cover input amount + fee');

        (, uint out) = onChainSwapsInternal(request, calls);
        if (request.toToken != NULL_ADDRESS)
            approve(request.toToken, synapseStorage.rangoSynapseAddress, out);

        uint value = request.toToken == NULL_ADDRESS ? (out > 0 ? out : request.amountIn) : 0;

        IRangoSynapse(synapseStorage.rangoSynapseAddress).synapseBridge{value : value}(
            request.toToken,
            out,
            bridgeRequest
        );
    }

    /// @notice A utility function to fetch storage from a predefined random slot using assembly
    /// @return s The storage object
    function getSynapseProxyStorage() internal pure returns (SynapseProxyStorage storage s) {
        bytes32 namespace = RANGO_SYNAPSE_PROXY_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }
}

File 28 of 31 : IRangoThorchain.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

/// @title Interface to interact with RangoThorchain contract.
/// @author Thinking Particle
interface IRangoThorchain {
    /// @notice Defines parameters used for swapIn functionality on thorchain router.
    /// @param token The token contract address (if token is native, should be 0x0000000000000000000000000000000000000000)
    /// @param amount The amount of token to be swapped. It should be positive and if token is native, msg.value should be bigger than amount.
    /// @param tcRouter The router contract address of Thorchain. This cannot be hardcoded because Thorchain can upgrade its router and the address might change.
    /// @param tcVault The vault address of Thorchain. This cannot be hardcoded because Thorchain rotates vaults.
    /// @param thorchainMemo The transaction memo used by Thorchain which contains the thorchain swap data. More info: https://dev.thorchain.org/thorchain-dev/memos
    /// @param expiration The expiration block number. If the tx is included after this block, it will be reverted.
    function swapInToThorchain(
        address token,
        uint amount,
        address tcRouter,
        address tcVault,
        string calldata thorchainMemo,
        uint expiration
    ) external payable;

}

File 29 of 31 : RangoThorchainProxy.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "../../../libs/BaseProxyContract.sol";
import "./IRangoThorchain.sol";

/// @title thorchain proxy logic
/// @author Thinking Particle
/// @dev This contract stores the address of the RangoThorchain contract and implements the logic for interacting with it. This contract can swap the given input token to another token and then pass the output to the RangoThorchain contract.
/// @notice This contract can swap the token to another token before passing it to thorchain for another swap.
contract RangoThorchainProxy is BaseProxyContract {

    // @dev keccak256("exchange.rango.thorchain.proxy")
    bytes32 internal constant RANGO_THORCHAIN_PROXY_NAMESPACE = hex"2d408556142e9c30601bb067c0631f1a23ffac1d1598afa3da595c26103e4966";

    /// @notice stores the address of RangoThorchain contract
    struct ThorchainProxyStorage {
        address rangoThorchainAddress;
    }

    /// @notice Notifies that the RangoThorchain.sol contract address is updated
    /// @param _oldAddress The previous deployed address
    /// @param _newAddress The new deployed address
    event RangoThorchainAddressUpdated(address _oldAddress, address _newAddress);

    /// @notice updates RangoThorchain contract address, only callable by the owner.
    function updateRangoThorchainAddress(address _address) external onlyOwner {
        ThorchainProxyStorage storage thorchainProxyStorage = getThorchainProxyStorage();

        address oldAddress = thorchainProxyStorage.rangoThorchainAddress;
        thorchainProxyStorage.rangoThorchainAddress = _address;

        emit RangoThorchainAddressUpdated(oldAddress, _address);
    }

    /// @notice Swap tokens if necessary, then pass it to RangoThorchain
    /// @dev Swap tokens if necessary, then pass it to RangoThorchain. If no swap is required (calls.length==0) the provided token is passed to RangoThorchain without change.
    /// @param request The swap information used to check input and output token addresses and balances, as well as the fees if any. Together with calls param, determines the swap logic before passing to Thorchain.
    /// @param calls The contract call data that is used to swap (can be empty if no swap is needed). Together with request param, determines the swap logic before passing to Thorchain.
    /// @param tcRouter The router contract address of Thorchain. This cannot be hardcoded because Thorchain can upgrade its router and the address might change.
    /// @param tcVault The vault address of Thorchain. This cannot be hardcoded because Thorchain rotates vaults.
    /// @param thorchainMemo The transaction memo used by Thorchain which contains the thorchain swap data. More info: https://dev.thorchain.org/thorchain-dev/memos
    /// @param expiration The expiration block number. If the tx is included after this block, it will be reverted.
    function swapInToThorchain(
        SwapRequest memory request,
        Call[] calldata calls,

        address tcRouter,
        address tcVault,
        string calldata thorchainMemo,
        uint expiration
    ) external payable whenNotPaused nonReentrant {
        ThorchainProxyStorage storage thorchainProxyStorage = getThorchainProxyStorage();
        require(thorchainProxyStorage.rangoThorchainAddress != NULL_ADDRESS, 'Thorchain wrapper address in Rango contract not set');

        (, uint out) = onChainSwapsInternal(request, calls);
        uint value = 0;
        if (request.toToken != NULL_ADDRESS) {
            approve(request.toToken, thorchainProxyStorage.rangoThorchainAddress, out);
        } else {
            value = out;
        }

        IRangoThorchain(thorchainProxyStorage.rangoThorchainAddress).swapInToThorchain{value : value}(
            request.toToken,
            out,
            tcRouter,
            tcVault,
            thorchainMemo,
            expiration
        );
    }

    /// @notice reads the storage using namespace
    /// @return s the stored value for ThorchainProxyStorage using the namespace
    function getThorchainProxyStorage() internal pure returns (ThorchainProxyStorage storage s) {
        bytes32 namespace = RANGO_THORCHAIN_PROXY_NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            s.slot := namespace
        }
    }
}

File 30 of 31 : IThorchainRouter.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

/// @dev based on thorchain router https://gitlab.com/thorchain/ethereum/eth-router/-/blob/29b59c2d6c6fc7a65d6bbc0f80d90694ac4122f8/contracts/THORChain_Aggregator.sol#L12
interface IThorchainRouter {
    /// @param vault The vault address of Thorchain. This cannot be hardcoded because Thorchain rotates vaults.
    /// @param asset The token contract address (if token is native, should be 0x0000000000000000000000000000000000000000)
    /// @param amount The amount of token to be swapped. It should be positive and if token is native, msg.value should be bigger than amount.
    /// @param memo The transaction memo used by Thorchain which contains the thorchain swap data. More info: https://dev.thorchain.org/thorchain-dev/memos
    /// @param expiration The expiration block number. If the tx is included after this block, it will be reverted.
    function depositWithExpiry(
        address payable vault,
        address asset,
        uint amount,
        string calldata memo,
        uint expiration
    ) external payable;
}

File 31 of 31 : IWETH.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity 0.8.13;

interface IWETH {
    function deposit() external payable;

    function withdraw(uint256) external;
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AffiliateReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"bytes","name":"returnData","type":"bytes"}],"name":"CallResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_factory","type":"address"}],"name":"ContractBlacklisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_factory","type":"address"}],"name":"ContractWhitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DexOutput","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"FeeContractAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FeeReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"RangoAcrossAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"RangoCBridgeAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"RangoHopAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"RangoHyphenAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"RangoMultichainAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"RangoSynapseAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"RangoThorchainAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Refunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_receiver","type":"address"},{"indexed":false,"internalType":"bool","name":"_nativeOut","type":"bool"},{"indexed":false,"internalType":"bool","name":"_withdraw","type":"bool"}],"name":"SendToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"components":[{"internalType":"address","name":"spokePoolAddress","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"originToken","type":"address"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"uint64","name":"relayerFeePct","type":"uint64"},{"internalType":"uint32","name":"quoteTimestamp","type":"uint32"}],"internalType":"struct RangoAcrossProxy.AcrossBridgeRequest","name":"bridgeRequest","type":"tuple"}],"name":"acrossBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_factory","type":"address"}],"name":"addWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"internalType":"address","name":"_receiverContract","type":"address"},{"internalType":"uint64","name":"_dstChainId","type":"uint64"},{"internalType":"uint64","name":"_nonce","type":"uint64"},{"internalType":"uint32","name":"_maxSlippage","type":"uint32"},{"internalType":"uint256","name":"_sgnFee","type":"uint256"},{"components":[{"internalType":"uint64","name":"dstChainId","type":"uint64"},{"internalType":"bool","name":"bridgeNativeOut","type":"bool"},{"internalType":"address","name":"dexAddress","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"nativeOut","type":"bool"},{"internalType":"address","name":"originalSender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bytes","name":"dAppMessage","type":"bytes"},{"internalType":"address","name":"dAppSourceContract","type":"address"},{"internalType":"address","name":"dAppDestContract","type":"address"}],"internalType":"struct RangoCBridgeModels.RangoCBridgeInterChainMessage","name":"imMessage","type":"tuple"}],"name":"cBridgeIM","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint64","name":"_dstChainId","type":"uint64"},{"internalType":"uint64","name":"_nonce","type":"uint64"},{"internalType":"uint32","name":"_maxSlippage","type":"uint32"}],"name":"cBridgeSend","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getValidRangoContracts","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"components":[{"internalType":"enum RangoHopModels.ActionType","name":"actionType","type":"uint8"},{"internalType":"address","name":"bridgeAddress","type":"address"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"bonderFee","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"destinationAmountOutMin","type":"uint256"},{"internalType":"uint256","name":"destinationDeadline","type":"uint256"},{"internalType":"address","name":"relayer","type":"address"},{"internalType":"uint256","name":"relayerFee","type":"uint256"}],"internalType":"struct RangoHopModels.HopRequest","name":"bridgeRequest","type":"tuple"}],"name":"hopBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"components":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"toChainId","type":"uint256"}],"internalType":"struct RangoHyphenProxy.HyphenBridgeRequest","name":"bridgeRequest","type":"tuple"}],"name":"hyphenBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_nativeWrappedAddress","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"components":[{"internalType":"enum RangoMultichainModels.MultichainBridgeType","name":"_actionType","type":"uint8"},{"internalType":"address","name":"_underlyingToken","type":"address"},{"internalType":"address","name":"_multichainRouter","type":"address"},{"internalType":"address","name":"_receiverAddress","type":"address"},{"internalType":"uint256","name":"_receiverChainID","type":"uint256"}],"internalType":"struct RangoMultichainProxy.MultichainBridgeRequest","name":"bridgeRequest","type":"tuple"}],"name":"multichainBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"internalType":"bool","name":"nativeOut","type":"bool"}],"name":"onChainSwaps","outputs":[{"internalType":"bytes[]","name":"","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"refund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"refundNative","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_factory","type":"address"}],"name":"removeWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"internalType":"address","name":"tcRouter","type":"address"},{"internalType":"address","name":"tcVault","type":"address"},{"internalType":"string","name":"thorchainMemo","type":"string"},{"internalType":"uint256","name":"expiration","type":"uint256"}],"name":"swapInToThorchain","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"feeIn","type":"uint256"},{"internalType":"uint256","name":"affiliateIn","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"}],"internalType":"struct BaseProxyContract.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address payable","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct BaseProxyContract.Call[]","name":"calls","type":"tuple[]"},{"components":[{"internalType":"enum RangoSynapseModels.SynapseBridgeType","name":"bridgeType","type":"uint8"},{"internalType":"address","name":"router","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint8","name":"tokenIndexFrom","type":"uint8"},{"internalType":"uint8","name":"tokenIndexTo","type":"uint8"},{"internalType":"uint256","name":"minDy","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"swapTokenIndexFrom","type":"uint8"},{"internalType":"uint8","name":"swapTokenIndexTo","type":"uint8"},{"internalType":"uint256","name":"swapMinDy","type":"uint256"},{"internalType":"uint256","name":"swapDeadline","type":"uint256"},{"internalType":"uint256[]","name":"liquidityAmounts","type":"uint256[]"}],"internalType":"struct RangoSynapseModels.SynapseBridgeRequest","name":"bridgeRequest","type":"tuple"}],"name":"synapseBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_address","type":"address"}],"name":"updateFeeContractAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateRangoAcrossAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateRangoCBridgeAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateRangoHopAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateRangoHyphenAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateRangoMultichainAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateRangoSynapseAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateRangoThorchainAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

608060405234801561001057600080fd5b50614d29806100206000396000f3fe6080604052600436106101a05760003560e01c80638da5cb5b116100ec578063e171b2ff1161008a578063ed9656f711610064578063ed9656f714610447578063f2fde38b1461045a578063f68ee4ea1461047a578063f80f5dd51461048d57600080fd5b8063e171b2ff1461040e578063e8b98cdc14610421578063eb74d1851461043457600080fd5b80639fae52e6116100c65780639fae52e61461038e578063a60fdfb6146103ae578063c4d66de8146103ce578063ceeb5489146103ee57600080fd5b80638da5cb5b1461032457806397baa26f1461034c578063984accae1461036c57600080fd5b80635c975abb11610159578063797ecf3a11610133578063797ecf3a146102b15780637fc7a6ba146102d15780638577c426146102e45780638c27630d1461030457600080fd5b80635c975abb14610254578063715018a61461027c57806378c8cda71461029157600080fd5b80630b320d95146101ac57806315f560db146101c15780631a347f5d146101d4578063264e037a146101f4578063306f4a9214610214578063410085df1461023457600080fd5b366101a757005b600080fd5b6101bf6101ba3660046137b3565b6104ad565b005b6101bf6101cf3660046139a2565b6106ad565b3480156101e057600080fd5b506101bf6101ef366004613a51565b610899565b34801561020057600080fd5b506101bf61020f366004613a51565b610933565b34801561022057600080fd5b506101bf61022f366004613a51565b6109c0565b34801561024057600080fd5b506101bf61024f366004613a6e565b610a4d565b34801561026057600080fd5b5060335460ff1660405190151581526020015b60405180910390f35b34801561028857600080fd5b506101bf610b80565b34801561029d57600080fd5b506101bf6102ac366004613a51565b610bb6565b3480156102bd57600080fd5b506101bf6102cc366004613a51565b610cc6565b6101bf6102df366004613aa9565b610d53565b3480156102f057600080fd5b506101bf6102ff366004613a51565b610f5e565b34801561031057600080fd5b506101bf61031f366004613a51565b610feb565b34801561033057600080fd5b506065546040516001600160a01b039091168152602001610273565b34801561035857600080fd5b506101bf610367366004613a51565b611078565b34801561037857600080fd5b50610381611105565b6040516102739190613bb7565b34801561039a57600080fd5b506101bf6103a9366004613c04565b611325565b6103c16103bc366004613c1d565b6113de565b6040516102739190613cdc565b3480156103da57600080fd5b506101bf6103e9366004613a51565b611463565b3480156103fa57600080fd5b506101bf610409366004613a51565b6115e0565b6101bf61041c366004613db9565b61166d565b6101bf61042f366004613f2c565b61183b565b6101bf610442366004613ffe565b611a29565b6101bf6104553660046140e2565b611bc4565b34801561046657600080fd5b506101bf610475366004613a51565b611d75565b6101bf61048836600461417e565b611e10565b34801561049957600080fd5b506101bf6104a8366004613a51565b612035565b60335460ff16156104d95760405162461bcd60e51b81526004016104d09061425a565b60405180910390fd5b6002609754036104fb5760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614c5483398151915280546001600160a01b03166105365760405162461bcd60e51b81526004016104d0906142bb565b89516001600160a01b03161560008482610551576000610574565b8c604001518d608001518e6060015161056a919061431a565b610574919061431a565b61057e919061431a565b9050803410156105e55760405162461bcd60e51b815260206004820152602c60248201527f53656e64206d6f72652045544820746f20636f7665722073676e466565202b2060448201526b1a5b9c1d5d08185b5bdd5b9d60a21b60648201526084016104d0565b60006105f28d8d8d6120e2565b60208f015186549193506106119250906001600160a01b031683612281565b8360000160009054906101000a90046001600160a01b03166001600160a01b0316635465f9f5878f60200151848e8e8e8e8e8e6040518a63ffffffff1660e01b8152600401610667989796959493929190614376565b6000604051808303818588803b15801561068057600080fd5b505af1158015610694573d6000803e3d6000fd5b5050600160975550505050505050505050505050505050565b60335460ff16156106d05760405162461bcd60e51b81526004016104d09061425a565b6002609754036106f25760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614c3483398151915280546001600160a01b031661076e5760405162461bcd60e51b815260206004820152602860248201527f68797068656e206164647265737320696e2052616e676f20636f6e7472616374604482015267081b9bdd081cd95d60c21b60648201526084016104d0565b84516001600160a01b0316156000816107885760006107ab565b8660400151876080015188606001516107a1919061431a565b6107ab919061431a565b9050803410156107cd5760405162461bcd60e51b81526004016104d09061450d565b60006107da8888886120e2565b60208a01519092506001600160a01b031615905061080d576020880151845461080d91906001600160a01b031683612281565b8354855160208a8101519088015160405163779cb16760e01b81526001600160a01b039384166004820152918316602483015260448201859052606482015291169063779cb16790608401600060405180830381600087803b15801561087257600080fd5b505af1158015610886573d6000803e3d6000fd5b5050600160975550505050505050505050565b6065546001600160a01b031633146108c35760405162461bcd60e51b81526004016104d090614550565b6000600080516020614bf483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907f1c7cb0cdc9ba781f9745f3e24b6de0c45db97bf81b2091dfbcc45e9fdd1c1d13906109269083908690614585565b60405180910390a1505050565b6065546001600160a01b0316331461095d5760405162461bcd60e51b81526004016104d090614550565b6000600080516020614c5483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907f68893781f5159598b8f9249a447a49f9817d59d48444fdc01f6bc00418c035d7906109269083908690614585565b6065546001600160a01b031633146109ea5760405162461bcd60e51b81526004016104d090614550565b6000600080516020614cb483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907f773c28395b522e477efe15598600eafb335fafed4fde290f8fb0fcf60d5189f0906109269083908690614585565b6065546001600160a01b03163314610a775760405162461bcd60e51b81526004016104d090614550565b6040516370a0823160e01b815230600482015282906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610ac0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae4919061459f565b905082811015610b2d5760405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b60448201526064016104d0565b610b3882338561229d565b604080516001600160a01b0386168152602081018590527fd7dee2702d63ad89917b6a4da9981c90c4d24f8c2bdfd64c604ecae57d8d0651910160405180910390a150505050565b6065546001600160a01b03163314610baa5760405162461bcd60e51b81526004016104d090614550565b610bb46000612300565b565b6065546001600160a01b03163314610be05760405162461bcd60e51b81526004016104d090614550565b6001600160a01b03811660009081527fc23df90b6466cfd0cbf4f6a578f167d2f60ed56371b4746a3c5973c8543f4fdb6020526040902054600080516020614bf48339815191529060ff16610c6b5760405162461bcd60e51b8152602060048201526011602482015270119858dd1bdc9e481b9bdd08199bdd5b99607a1b60448201526064016104d0565b6001600160a01b0382166000818152600283016020908152604091829020805460ff1916905590519182527ffb00f7adc91459b5048ecdc60b783959a583bafb1e3041f3e1f017540a0e47d391015b60405180910390a15050565b6065546001600160a01b03163314610cf05760405162461bcd60e51b81526004016104d090614550565b6000600080516020614c7483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907f0b481302a73f292d20517d616c186d80d59578133e50a400770993f300aa412d906109269083908690614585565b60335460ff1615610d765760405162461bcd60e51b81526004016104d09061425a565b600260975403610d985760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614c7483398151915280546001600160a01b0316610e115760405162461bcd60e51b815260206004820152602560248201527f486f70206164647265737320696e2052616e676f20636f6e7472616374206e6f6044820152641d081cd95d60da1b60648201526084016104d0565b84516001600160a01b031615600081610e2b576000610e4e565b866040015187608001518860600151610e44919061431a565b610e4e919061431a565b905080341015610e705760405162461bcd60e51b81526004016104d0906145b8565b6000610e7d8888886120e2565b60208a01519092506001600160a01b0316159050610eb05760208801518454610eb091906001600160a01b031683612281565b60208801516000906001600160a01b031615610ecd576000610ee1565b60008211610edf578860400151610ee1565b815b855460208b0151604051632d0fbddf60e11b81529293506001600160a01b0390911691635a1f7bbe918491610f1c918b91889060040161462b565b6000604051808303818588803b158015610f3557600080fd5b505af1158015610f49573d6000803e3d6000fd5b50506001609755505050505050505050505050565b6065546001600160a01b03163314610f885760405162461bcd60e51b81526004016104d090614550565b6000600080516020614c3483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907fd5679d64209e390c04cdeeda4788f40ba458416510930b642192f9dfdf001dfc906109269083908690614585565b6065546001600160a01b031633146110155760405162461bcd60e51b81526004016104d090614550565b6000600080516020614cd483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907faa779eacfbe610fe15a952f7c7dd2a74fd25a1725720e506d0b73d66af2fca0a906109269083908690614585565b6065546001600160a01b031633146110a25760405162461bcd60e51b81526004016104d090614550565b6000600080516020614c1483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907f9ddbfb5940e42674919ab5489576289df714b22e99c3ebd644e749728aa34a3b906109269083908690614585565b6040805160088082526101208201909252606091600080516020614c5483398151915291600080516020614cd483398151915291600080516020614c9483398151915291600080516020614cb483398151915291600080516020614c1483398151915291600080516020614c7483398151915291600080516020614c3483398151915291600091602082016101008036833701905050905030816000815181106111b1576111b16146fa565b6001600160a01b03928316602091820292909201015288548251911690829060019081106111e1576111e16146fa565b6001600160a01b0392831660209182029290920101528754825191169082906002908110611211576112116146fa565b6001600160a01b0392831660209182029290920101528554825191169082906003908110611241576112416146fa565b6001600160a01b0392831660209182029290920101528454825191169082906004908110611271576112716146fa565b6001600160a01b03928316602091820292909201015283548251911690829060059081106112a1576112a16146fa565b6001600160a01b03928316602091820292909201015286548251911690829060069081106112d1576112d16146fa565b6001600160a01b0392831660209182029290920101528254825191169082906007908110611301576113016146fa565b6001600160a01b039092166020928302919091019091015298975050505050505050565b6065546001600160a01b0316331461134f5760405162461bcd60e51b81526004016104d090614550565b47818110156113975760405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b60448201526064016104d0565b6113a76000833360016000612352565b6040805160008152602081018490527fd7dee2702d63ad89917b6a4da9981c90c4d24f8c2bdfd64c604ecae57d8d06519101610cba565b60606113ec60335460ff1690565b156114095760405162461bcd60e51b81526004016104d09061425a565b60026097540361142b5760405162461bcd60e51b81526004016104d090614284565b600260975560008061143e8787876120e2565b9150915061145487602001518233876000612352565b50600160975595945050505050565b600061146f600161250d565b90508015611487576000805461ff0019166101001790555b7fc23df90b6466cfd0cbf4f6a578f167d2f60ed56371b4746a3c5973c8543f4fda80546001600160a01b03199081166001600160a01b03851617909155600080516020614bf4833981519152805482168155600080516020614c54833981519152805483168155600080516020614c94833981519152805484168155600080516020614cd4833981519152805485168155600080516020614c34833981519152805486168155600080516020614c14833981519152805487168155600080516020614c74833981519152805488168155600080516020614cb4833981519152805490981688559596949593949293919290919061158261259a565b61158a6125c9565b6115926125f8565b505050505050505080156115dc576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610cba565b5050565b6065546001600160a01b0316331461160a5760405162461bcd60e51b81526004016104d090614550565b6000600080516020614c9483398151915280546001600160a01b038481166001600160a01b0319831617835560405192935016907fa0ac4525a841c5df5b487fe49e87dc64d2349ab7136d92edc097ea2c66a4385f906109269083908690614585565b60335460ff16156116905760405162461bcd60e51b81526004016104d09061425a565b6002609754036116b25760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614cb483398151915280546001600160a01b031661172f5760405162461bcd60e51b815260206004820152602960248201527f53796e61707365206164647265737320696e2052616e676f20636f6e747261636044820152681d081b9bdd081cd95d60ba1b60648201526084016104d0565b84516001600160a01b03161560008161174957600061176c565b866040015187608001518860600151611762919061431a565b61176c919061431a565b90508034101561178e5760405162461bcd60e51b81526004016104d0906145b8565b600061179b8888886120e2565b60208a01519092506001600160a01b03161590506117ce57602088015184546117ce91906001600160a01b031683612281565b60208801516000906001600160a01b0316156117eb5760006117ff565b600082116117fd5788604001516117ff565b815b855460208b01516040516322f772a560e21b81529293506001600160a01b0390911691638bddca94918491610f1c919087908c90600401614750565b60335460ff161561185e5760405162461bcd60e51b81526004016104d09061425a565b6002609754036118805760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614cd483398151915280546001600160a01b03166119005760405162461bcd60e51b815260206004820152602c60248201527f4d756c7469636861696e206164647265737320696e2052616e676f20636f6e7460448201526b1c9858dd081b9bdd081cd95d60a21b60648201526084016104d0565b84516001600160a01b03161560008161191a57600061193d565b866040015187608001518860600151611933919061431a565b61193d919061431a565b90508034101561195f5760405162461bcd60e51b81526004016104d0906145b8565b600061196c8888886120e2565b60208a01519092506001600160a01b031615905061199f576020880151845461199f91906001600160a01b031683612281565b60208801516000906001600160a01b0316156119bc5760006119d0565b600082116119ce5788604001516119d0565b815b855487516020808d0151908a01516040808c015160608d015160808e01519251637af49a4560e11b81529798506001600160a01b039096169663f5e9348a968996610f1c969095909490938c9390929190600401614880565b60335460ff1615611a4c5760405162461bcd60e51b81526004016104d09061425a565b600260975403611a6e5760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614c9483398151915280546001600160a01b0316611af55760405162461bcd60e51b815260206004820152603360248201527f54686f72636861696e2077726170706572206164647265737320696e2052616e60448201527219dbc818dbdb9d1c9858dd081b9bdd081cd95d606a1b60648201526084016104d0565b6000611b028a8a8a6120e2565b60208c0151909250600091506001600160a01b031615611b3c5760208b01518354611b3791906001600160a01b031684612281565b611b3f565b50805b825460208c0151604051632d3cfc3360e01b81526001600160a01b0390921691632d3cfc33918491611b80919087908e908e908e908e908e906004016148ce565b6000604051808303818588803b158015611b9957600080fd5b505af1158015611bad573d6000803e3d6000fd5b505060016097555050505050505050505050505050565b60335460ff1615611be75760405162461bcd60e51b81526004016104d09061425a565b600260975403611c095760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614c5483398151915280546001600160a01b0316611c445760405162461bcd60e51b81526004016104d0906142bb565b87516001600160a01b031615600081611c5e576000611c81565b89604001518a608001518b60600151611c77919061431a565b611c81919061431a565b905080341015611ca35760405162461bcd60e51b81526004016104d09061450d565b6000611cb08b8b8b6120e2565b60208d01518654919350611ccf9250906001600160a01b031683612281565b835460208c015160405163a5977fbb60e01b81526001600160a01b038b811660048301529182166024820152604481018490526001600160401b03808b1660648301528916608482015263ffffffff881660a482015291169063a5977fbb9060c401600060405180830381600087803b158015611d4b57600080fd5b505af1158015611d5f573d6000803e3d6000fd5b5050600160975550505050505050505050505050565b6065546001600160a01b03163314611d9f5760405162461bcd60e51b81526004016104d090614550565b6001600160a01b038116611e045760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016104d0565b611e0d81612300565b50565b60335460ff1615611e335760405162461bcd60e51b81526004016104d09061425a565b600260975403611e555760405162461bcd60e51b81526004016104d090614284565b6002609755600080516020614c1483398151915280546001600160a01b0316611ed15760405162461bcd60e51b815260206004820152602860248201527f4163726f7373206164647265737320696e2052616e676f20636f6e7472616374604482015267081b9bdd081cd95d60c21b60648201526084016104d0565b84516001600160a01b031615600081611eeb576000611f0e565b866040015187608001518860600151611f04919061431a565b611f0e919061431a565b905080341015611f305760405162461bcd60e51b81526004016104d0906145b8565b6000611f3d8888886120e2565b60208a01519092506001600160a01b0316159050611f705760208801518454611f7091906001600160a01b031683612281565b60208801516000906001600160a01b031615611f8d576000611fa1565b60008211611f9f578860400151611fa1565b815b8554875160208c810151908a01516040808c015160608d015160808e015160a08f01519351636da1915760e11b81526001600160a01b0397881660048201529587166024870152938616604486015290851660648501526084840189905260a48401526001600160401b0390911660c483015263ffffffff1660e4820152929350169063db4322ae90839061010401610f1c565b6065546001600160a01b0316331461205f5760405162461bcd60e51b81526004016104d090614550565b6001600160a01b03811660008181527fc23df90b6466cfd0cbf4f6a578f167d2f60ed56371b4746a3c5973c8543f4fdb6020908152604091829020805460ff191660011790559051918252600080516020614bf4833981519152917fb7269578552456138d47dc37471d94886205143f138387446eff0148047965f69101610cba565b60606000806120f48660200151612627565b905060006121058760000151612627565b905060006121148888886126af565b905060006121258960200151612627565b905060006121368a60000151612627565b8a519091506001600160a01b03161561216e57838110156121695760405162461bcd60e51b81526004016104d090614932565b612197565b612178348561498f565b8110156121975760405162461bcd60e51b81526004016104d090614932565b600088156122525760006121ab878561498f565b116121f85760405162461bcd60e51b815260206004820152601c60248201527f4e6f2062616c616e636520666f756e642061667465722073776170730000000060448201526064016104d0565b612202868461498f565b6020808d0151604080516001600160a01b0390921682529181018390529192507f2f2a0be2ceea0e98188f8c78d4b07b127323c860cd38aa66270036b4792171e6910160405180910390a1612270565b858311612263578a6040015161226d565b61226d868461498f565b90505b929a92995091975050505050505050565b61228d83836000612ea5565b612298838383612fb9565b505050565b6040516001600160a01b03831660248201526044810182905261229890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261306e565b606580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b604080516001600160a01b03878116825260208201879052851681830152831515606082015282151560808201529051600080516020614bf4833981519152917fbc5ba848d4a4b8ebad0f5104ceb00e5ef597fe76fecfc967fb39801515271fa7919081900360a00190a182156124fa57811561247e5760018101546001600160a01b038781169116146124195760405162461bcd60e51b815260206004820152600e60248201526d0e8ded6cadc40dad2e6dac2e8c6d60931b60448201526064016104d0565b6001810154604051632e1a7d4d60e01b8152600481018790526001600160a01b0390911690632e1a7d4d90602401600060405180830381600087803b15801561246157600080fd5b505af1158015612475573d6000803e3d6000fd5b505050506124eb565b6001600160a01b038616156124eb5760405162461bcd60e51b815260206004820152602d60248201527f546f6b656e2061646472657373206d75737420626520307830302e2e2e30206660448201526c1bdc881b985d1a5d99481bdd5d609a1b60648201526084016104d0565b6124f58486613140565b612505565b61250586858761229d565b505050505050565b60008054610100900460ff1615612554578160ff1660011480156125305750303b155b61254c5760405162461bcd60e51b81526004016104d0906149a6565b506000919050565b60005460ff80841691161061257b5760405162461bcd60e51b81526004016104d0906149a6565b506000805460ff191660ff92909216919091179055600190565b919050565b600054610100900460ff166125c15760405162461bcd60e51b81526004016104d0906149f4565b610bb46131db565b600054610100900460ff166125f05760405162461bcd60e51b81526004016104d0906149f4565b610bb461320b565b600054610100900460ff1661261f5760405162461bcd60e51b81526004016104d0906149f4565b610bb461323e565b6000816001600160a01b038116156126a6576040516370a0823160e01b81523060048201526001600160a01b038216906370a0823190602401602060405180830381865afa15801561267d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a1919061459f565b6126a8565b475b9392505050565b8251600080516020614bf483398151915280546060926001600160a01b03908116159291166127205760405162461bcd60e51b815260206004820152601c60248201527f46656520636f6e74726163742061646472657373206e6f74207365740000000060448201526064016104d0565b60005b848110156127de57816002016000878784818110612743576127436146fa565b90506020028101906127559190614a3f565b612763906020810190613a51565b6001600160a01b0316815260208101919091526040016000205460ff166127cc5760405162461bcd60e51b815260206004820152601860248201527f436f6e7472616374206e6f742077686974656c6973746564000000000000000060448201526064016104d0565b806127d681614a5f565b915050612723565b5060008660400151876080015188606001516127fa919061431a565b612804919061431a565b9050821561286857803410156128685760405162461bcd60e51b815260206004820152602360248201527f4e6f7420656e6f756768204554482070726f766964656420746f20636f6e74726044820152621858dd60ea1b60648201526084016104d0565b600061271061287961012c84614a78565b6128839190614a97565b9050600061271061289661012c85614a78565b6128a09190614a97565b905081896060015111156129025760405162461bcd60e51b8152602060048201526024808201527f52657175657374656420666565206578636565646564206d61782074687265736044820152631a1bdb1960e21b60648201526084016104d0565b80896080015111156129705760405162461bcd60e51b815260206004820152603160248201527f52657175657374656420616666696c6961746520726577617264206578636565604482015270191959081b585e081d1a1c995cda1bdb19607a1b60648201526084016104d0565b84612a905760005b878110156129d05789516129be908a8a84818110612998576129986146fa565b90506020028101906129aa9190614a3f565b6129b8906020810190613a51565b86612281565b806129c881614a5f565b915050612978565b5060006129e08a60000151612627565b90506129f28a6000015133308761326c565b6000612a018b60000151612627565b90508181118015612a1a575084612a18838361498f565b105b15612a8d5760405162461bcd60e51b815260206004820152603760248201527f4465666c6174696f6e61727920746f6b656e7320617265206e6f74207375707060448201527f6f727465642062792052616e676f20636f6e747261637400000000000000000060648201526084016104d0565b50505b606089015115612b0f57885160608a01518554612aba9291906001600160a01b0316886000612352565b885184546060808c0151604080516001600160a01b0395861681529490931660208501528383015290517f715e76729ba81a946e254c4ba6488670b429b63e79b2b4cd7f0a969dd7ecbd819281900390910190a15b608089015115612be35760a08901516001600160a01b0316612b735760405162461bcd60e51b815260206004820152601960248201527f496e76616c696420616666696c6961746f72416464726573730000000000000060448201526064016104d0565b612b8d89600001518a608001518b60a00151886000612352565b885160a08a015160808b0151604080516001600160a01b03948516815293909216602084015282820152517fbd8658de9f5922c925df42ff357f621af85a2047dff46d23443decd2cdc74b429181900360600190a15b6000876001600160401b03811115612bfd57612bfd61348a565b604051908082528060200260200182016040528015612c3057816020015b6060815260200190600190039081612c1b5790505b50905060005b88811015612e975760008088612d09578b8b84818110612c5857612c586146fa565b9050602002810190612c6a9190614a3f565b612c78906020810190613a51565b6001600160a01b03168c8c85818110612c9357612c936146fa565b9050602002810190612ca59190614a3f565b612cb3906020810190614ab9565b604051612cc1929190614aff565b6000604051808303816000865af19150503d8060008114612cfe576040519150601f19603f3d011682016040523d82523d6000602084013e612d03565b606091505b50612dcd565b8b8b84818110612d1b57612d1b6146fa565b9050602002810190612d2d9190614a3f565b612d3b906020810190613a51565b6001600160a01b03168d604001518d8d86818110612d5b57612d5b6146fa565b9050602002810190612d6d9190614a3f565b612d7b906020810190614ab9565b604051612d89929190614aff565b60006040518083038185875af1925050503d8060008114612dc6576040519150601f19603f3d011682016040523d82523d6000602084013e612dcb565b606091505b505b915091507f2fc0d44e6ef6b3e7707cacd3cc326511198c3d1598c65dd54be5a9e37ce02f128c8c85818110612e0457612e046146fa565b9050602002810190612e169190614a3f565b612e24906020810190613a51565b8383604051612e3593929190614b0f565b60405180910390a181612e6457612e4b816132a4565b60405162461bcd60e51b81526004016104d09190614b44565b80848481518110612e7757612e776146fa565b602002602001018190525050508080612e8f90614a5f565b915050612c36565b509998505050505050505050565b801580612f1e5750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612edb9030908690600401614585565b602060405180830381865afa158015612ef8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f1c919061459f565b155b612f895760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016104d0565b6040516001600160a01b03831660248201526044810182905261229890849063095ea7b360e01b906064016122c9565b600081846001600160a01b031663dd62ed3e30866040518363ffffffff1660e01b8152600401612fea929190614585565b602060405180830381865afa158015613007573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061302b919061459f565b613035919061431a565b6040516001600160a01b03851660248201526044810182905290915061306890859063095ea7b360e01b906064016122c9565b50505050565b60006130c3826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166133099092919063ffffffff16565b80519091501561229857808060200190518101906130e19190614b57565b6122985760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016104d0565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461318d576040519150601f19603f3d011682016040523d82523d6000602084013e613192565b606091505b50509050806122985760405162461bcd60e51b81526020600482015260156024820152746661696c656420746f2073656e64206e617469766560581b60448201526064016104d0565b600054610100900460ff166132025760405162461bcd60e51b81526004016104d0906149f4565b610bb433612300565b600054610100900460ff166132325760405162461bcd60e51b81526004016104d0906149f4565b6033805460ff19169055565b600054610100900460ff166132655760405162461bcd60e51b81526004016104d0906149f4565b6001609755565b6040516001600160a01b03808516602483015283166044820152606481018290526130689085906323b872dd60e01b906084016122c9565b60606044825110156132e957505060408051808201909152601d81527f5472616e73616374696f6e2072657665727465642073696c656e746c79000000602082015290565b600482019150818060200190518101906133039190614b74565b92915050565b60606133188484600085613320565b949350505050565b6060824710156133815760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016104d0565b6001600160a01b0385163b6133d85760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016104d0565b600080866001600160a01b031685876040516133f49190614be1565b60006040518083038185875af1925050503d8060008114613431576040519150601f19603f3d011682016040523d82523d6000602084013e613436565b606091505b5091509150613446828286613451565b979650505050505050565b606083156134605750816126a8565b8251156134705782518084602001fd5b8160405162461bcd60e51b81526004016104d09190614b44565b634e487b7160e01b600052604160045260246000fd5b6040516101c081016001600160401b03811182821017156134c3576134c361348a565b60405290565b60405161016081016001600160401b03811182821017156134c3576134c361348a565b60405160a081016001600160401b03811182821017156134c3576134c361348a565b60405160c081016001600160401b03811182821017156134c3576134c361348a565b604051601f8201601f191681016001600160401b03811182821017156135585761355861348a565b604052919050565b6001600160a01b0381168114611e0d57600080fd5b803561259581613560565b600060c0828403121561359257600080fd5b60405160c081018181106001600160401b03821117156135b4576135b461348a565b60405290508082356135c581613560565b815260208301356135d581613560565b8060208301525060408301356040820152606083013560608201526080830135608082015260a083013561360881613560565b60a0919091015292915050565b60008083601f84011261362757600080fd5b5081356001600160401b0381111561363e57600080fd5b6020830191508360208260051b850101111561365957600080fd5b9250929050565b80356001600160401b038116811461259557600080fd5b803563ffffffff8116811461259557600080fd5b8015158114611e0d57600080fd5b80356125958161368b565b60006001600160401b038211156136bd576136bd61348a565b5060051b60200190565b600082601f8301126136d857600080fd5b813560206136ed6136e8836136a4565b613530565b82815260059290921b8401810191818101908684111561370c57600080fd5b8286015b8481101561373057803561372381613560565b8352918301918301613710565b509695505050505050565b60006001600160401b038211156137545761375461348a565b50601f01601f191660200190565b600082601f83011261377357600080fd5b81356137816136e88261373b565b81815284602083860101111561379657600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060008060008060006101a08a8c0312156137d257600080fd5b6137dc8b8b613580565b985060c08a01356001600160401b03808211156137f857600080fd5b6138048d838e01613615565b909a50985060e08c0135915061381982613560565b8197506138296101008d01613660565b96506138386101208d01613660565b95506138476101408d01613677565b94506101608c013593506101808c013591508082111561386657600080fd5b908b01906101c0828e03121561387b57600080fd5b6138836134a0565b61388c83613660565b815261389a60208401613699565b60208201526138ab60408401613575565b60408201526138bc60608401613575565b60608201526138cd60808401613575565b608082015260a083013560a082015260c0830135828111156138ee57600080fd5b6138fa8f8286016136c7565b60c08301525060e083013560e08201526139176101008401613699565b61010082015261392a6101208401613575565b61012082015261393d6101408401613575565b6101408201526101608301358281111561395657600080fd5b6139628f828601613762565b610160830152506139766101808401613575565b6101808201526139896101a08401613575565b6101a08201528093505050509295985092959850929598565b6000806000808486036101208112156139ba57600080fd5b6139c48787613580565b945060c08601356001600160401b03808211156139e057600080fd5b6139ec89838a01613615565b9096509450849150604060df1984011215613a0657600080fd5b60405192506040830191508282108183111715613a2557613a2561348a565b5060405260e0860135613a3781613560565b815261010095909501356020860152509194909350909190565b600060208284031215613a6357600080fd5b81356126a881613560565b60008060408385031215613a8157600080fd5b8235613a8c81613560565b946020939093013593505050565b80356002811061259557600080fd5b600080600080848603610240811215613ac157600080fd5b613acb8787613580565b945060c08601356001600160401b03811115613ae657600080fd5b613af288828901613615565b9095509350610160905060df198201811315613b0d57600080fd5b613b156134c9565b9150613b2360e08801613a9a565b8252610100613b33818901613575565b6020840152610120808901356040850152610140613b52818b01613575565b6060860152838a013560808601526101808a013560a08601526101a08a013560c08601526101c08a013560e08601526101e08a013583860152613b986102008b01613575565b828601526102208a013581860152505050508091505092959194509250565b6020808252825182820181905260009190848201906040850190845b81811015613bf85783516001600160a01b031683529284019291840191600101613bd3565b50909695505050505050565b600060208284031215613c1657600080fd5b5035919050565b6000806000806101008587031215613c3457600080fd5b613c3e8686613580565b935060c08501356001600160401b03811115613c5957600080fd5b613c6587828801613615565b90945092505060e0850135613c798161368b565b939692955090935050565b60005b83811015613c9f578181015183820152602001613c87565b838111156130685750506000910152565b60008151808452613cc8816020860160208601613c84565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015613d3157603f19888603018452613d1f858351613cb0565b94509285019290850190600101613d03565b5092979650505050505050565b8035600d811061259557600080fd5b803560ff8116811461259557600080fd5b600082601f830112613d6f57600080fd5b81356020613d7f6136e8836136a4565b82815260059290921b84018101918181019086841115613d9e57600080fd5b8286015b848110156137305780358352918301918301613da2565b600080600080610100808688031215613dd157600080fd5b613ddb8787613580565b945060c08601356001600160401b0380821115613df757600080fd5b613e0389838a01613615565b909650945060e0880135915080821115613e1c57600080fd5b908701906101c0828a031215613e3157600080fd5b613e396134a0565b613e4283613d3e565b8152613e5060208401613575565b6020820152613e6160408401613575565b604082015260608301356060820152613e7c60808401613575565b6080820152613e8d60a08401613d4d565b60a0820152613e9e60c08401613d4d565b60c082015260e083013560e082015283830135848201526101209350613ec5848401613d4d565b848201526101409350613ed9848401613d4d565b93810193909352610160828101359084015261018080830135908401526101a0928383013582811115613f0b57600080fd5b613f178b828601613d5e565b85830152508094505050505092959194509250565b600080600080848603610180811215613f4457600080fd5b613f4e8787613580565b945060c08601356001600160401b03811115613f6957600080fd5b613f7588828901613615565b90955093505060a060df1982011215613f8d57600080fd5b50613f966134ec565b60e086013560038110613fa857600080fd5b8152610100860135613fb981613560565b6020820152610120860135613fcd81613560565b6040820152610140860135613fe181613560565b606082015261016095909501356080860152509194909350909190565b600080600080600080600080610160898b03121561401b57600080fd5b6140258a8a613580565b975060c08901356001600160401b038082111561404157600080fd5b61404d8c838d01613615565b909950975060e08b0135915061406282613560565b9095506101008a01359061407582613560565b9094506101208a0135908082111561408c57600080fd5b818b0191508b601f8301126140a057600080fd5b8135818111156140af57600080fd5b8c60208285010111156140c157600080fd5b60208301955080945050505061014089013590509295985092959890939650565b6000806000806000806000610160888a0312156140fe57600080fd5b6141088989613580565b965060c08801356001600160401b0381111561412357600080fd5b61412f8a828b01613615565b90975095505060e088013561414381613560565b93506141526101008901613660565b92506141616101208901613660565b91506141706101408901613677565b905092959891949750929550565b6000806000808486036101a081121561419657600080fd5b6141a08787613580565b945060c08601356001600160401b038111156141bb57600080fd5b6141c788828901613615565b90955093505060c060df19820112156141df57600080fd5b506141e861350e565b60e08601356141f681613560565b815261010086013561420781613560565b602082015261012086013561421b81613560565b604082015261014086013560608201526142386101608701613660565b608082015261424a6101808701613677565b60a0820152939692955090935050565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526029908201527f63427269646765206164647265737320696e2052616e676f20636f6e747261636040820152681d081b9bdd081cd95d60ba1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b6000821982111561432d5761432d614304565b500190565b600081518084526020808501945080840160005b8381101561436b5781516001600160a01b031687529582019590820190600101614346565b509495945050505050565b6001600160a01b03898116825260208201899052871660408201526001600160401b038681166060830152858116608083015263ffffffff851660a083015260c0820184905261010060e0830181905283519091168183015260009060208401516101206143e78186018315159052565b60408601519150610140614405818701846001600160a01b03169052565b60608701519250610160614423818801856001600160a01b03169052565b60808801519350610180614441818901866001600160a01b03169052565b60a08901516101a08981019190915260c08a01516101c0808b0152955061446c6102c08a0187614332565b60e08b01516101e08b0152968a015115156102008a0152848a01516001600160a01b039081166102208b0152848b0151166102408a0152828a015189880360ff19016102608b01529695506144c18688613cb0565b9650818a015195506144df6102808a01876001600160a01b03169052565b8901516001600160a01b0381166102a08a015294506144fe9350505050565b509a9950505050505050505050565b60208082526023908201527f53656e64206d6f72652045544820746f20636f76657220696e70757420616d6f6040820152621d5b9d60ea1b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6001600160a01b0392831681529116602082015260400190565b6000602082840312156145b157600080fd5b5051919050565b60208082526029908201527f53656e64206d6f72652045544820746f20636f76657220696e70757420616d6f604082015268756e74202b2066656560b81b606082015260800190565b634e487b7160e01b600052602160045260246000fd5b6002811061462757614627614601565b9052565b60006101a08201905061463f828651614617565b602085015161465960208401826001600160a01b03169052565b5060408501516040830152606085015161467e60608401826001600160a01b03169052565b506080850151608083015260a085015160a083015260c085015160c083015260e085015160e0830152610100808601518184015250610120808601516146ce828501826001600160a01b03169052565b505061014085810151908301526001600160a01b03841661016083015282610180830152949350505050565b634e487b7160e01b600052603260045260246000fd5b600d811061462757614627614601565b600081518084526020808501945080840160005b8381101561436b57815187529582019590820190600101614734565b60018060a01b038416815282602082015260606040820152614776606082018351614710565b6000602083015161479260808401826001600160a01b03169052565b5060408301516001600160a01b03811660a084015250606083015160c083015260808301516001600160a01b03811660e08401525060a08301516101006147dd8185018360ff169052565b60c085015191506101206147f58186018460ff169052565b60e0860151610140868101919091529186015161016080870191909152908601519250906101809061482b8287018560ff169052565b86015192506101a06148418682018560ff169052565b918601516101c086810191909152908601516101e0860152908501516102008501919091529050614876610220840182614720565b9695505050505050565b60e081016003891061489457614894614601565b9781526001600160a01b03968716602082015294861660408601526060850193909352908416608084015290921660a082015260c0015290565b6001600160a01b0388811682526020820188905286811660408301528516606082015260c06080820181905281018390526000838560e0840137600060e0858401015260e0601f19601f86011683010190508260a083015298975050505050505050565b6020808252603d908201527f536f7572636520746f6b656e2062616c616e6365206f6e20636f6e747261637460408201527f206d757374206e6f742064656372656173652061667465722073776170000000606082015260800190565b6000828210156149a1576149a1614304565b500390565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60008235603e19833603018112614a5557600080fd5b9190910192915050565b600060018201614a7157614a71614304565b5060010190565b6000816000190483118215151615614a9257614a92614304565b500290565b600082614ab457634e487b7160e01b600052601260045260246000fd5b500490565b6000808335601e19843603018112614ad057600080fd5b8301803591506001600160401b03821115614aea57600080fd5b60200191503681900382131561365957600080fd5b8183823760009101908152919050565b6001600160a01b03841681528215156020820152606060408201819052600090614b3b90830184613cb0565b95945050505050565b6020815260006126a86020830184613cb0565b600060208284031215614b6957600080fd5b81516126a88161368b565b600060208284031215614b8657600080fd5b81516001600160401b03811115614b9c57600080fd5b8201601f81018413614bad57600080fd5b8051614bbb6136e88261373b565b818152856020838501011115614bd057600080fd5b614b3b826020830160208601613c84565b60008251614a55818460208701613c8456fec23df90b6466cfd0cbf4f6a578f167d2f60ed56371b4746a3c5973c8543f4fd9677e79f0e4009f1792a10267078e7120af47266c8ce03085f21aef7ba016b06fa2cc4f41cf11b520eef4f1381031d11e095bbe59b53dc2a554b45e899a0f9f81e9cf4febccbfad5ef15964f91cb6c48fe594747e386f28fc2b067ddf16f1ed5d15410819d7d6216709939083a650939157bf8023516c3537a5272f9c42b704a22d408556142e9c30601bb067c0631f1a23ffac1d1598afa3da595c26103e4966f8ff8b28c44d8cca223cd9f986a0465240ed11ac179f68af36410e3725a13ab6ed7d91da7fb046892c2413e11ecc409c17b784b916ff0fd3fa2d512c567da864a2646970667358221220c0e981ee42058ec63f441d7b75679b03694a7b16267424b5530106c72e4eaf3764736f6c634300080d0033

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.