Address io16utd00edm350ajead4hcyke4rpvy88v84p5m05

Contract Overview

Balance:
0 IOTX

IOTX Value:
$ 0

Token:
Txn Hash
Block
From
To
Value [Txn Fee]
73582cccdb7a9b1a4f273b0ba3e5acb4dfe242cf445001fa277c41722b46abdd 27812962 2024-01-09 07:07:05 +0000 UTC 5 months ago io17j27pq9des2n272z8guxpqq6fc5zkfhjjt78p5  IN    Contract: SwapAndCloseTool 30.409025 IOTX 3.308286
726cf5d41ec5f1b36bb8b478c634f9c2ea9129669c6ce6b1407a370284e3443d 27715887 2024-01-03 16:15:35 +0000 UTC 5 months ago io1x5nk9q6w4jmrcqe0s7d9ksm920p9fqmaatvl5w  IN    Contract: SwapAndCloseTool 200.127240 IOTX 2.06278
2ac8433714b4dce8984b7af675600b4f13efea3babad2fa1ea67001273b7cde9 27688173 2024-01-02 00:59:05 +0000 UTC 5 months ago io17j27pq9des2n272z8guxpqq6fc5zkfhjjt78p5  IN    Contract: SwapAndCloseTool 35.208062 IOTX 2.06267
2ccff51cb6be774e18137f0e6596ce3247154ae5047be6af8411c03a7057ebe7 27645049 2023-12-30 13:05:05 +0000 UTC 5 months ago io1erm63nyuvgznkq67nteq47p6hlhs98c8uxav2q  IN    Contract: SwapAndCloseTool 10.423104 IOTX 2.049079
c37ee10add7e5997bdcf58aaca3df2f2e8bb67463362e0427096dff6009047ad 27642328 2023-12-30 09:18:20 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 9.475483 IOTX 2.04867
139c1de95460181bf89bdaf9ae577dfc7a229cf78ca36bf1af14a91969b1a28d 27594203 2023-12-27 14:26:50 +0000 UTC 5 months ago io17j27pq9des2n272z8guxpqq6fc5zkfhjjt78p5  IN    Contract: SwapAndCloseTool 11.827538 IOTX 2.02467
4f7f4b0b5ff2baa60315aa2463bdcf47403739e311d0c828899ebe7e49ff3c33 27593994 2023-12-27 14:09:25 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 9.273340 IOTX 2.00067
56c4135a16394ddf096232a5202d2228ffe7983457ac2d11fb386f42b42f441b 27593953 2023-12-27 14:06:00 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 9.191801 IOTX 2.00067
37eabce1629c60d2029bad7915f1eb85c9598a0e516231575816926875169549 27593875 2023-12-27 13:59:30 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 1.946484 IOTX 2.10417
a2367491666689fe151a6f73ab63b072023bb397de481453642b8dedef16baff 27593822 2023-12-27 13:55:05 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 1.946484 IOTX 0.397765
0dc1af0cd0c313cce844bc1610a596177d3528cedadd592eaa0c400ad82d08f2 27593538 2023-12-27 13:31:25 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 3.783312 IOTX 0.397765
9680bd875d5d9a69fbfb102b18b4f038965957261677308dfae8882642c56997 27593507 2023-12-27 13:28:50 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 1.946484 IOTX 0.397765
f01648074d6c87b26dbb0cfdbb0123f238dd602d5ca431115b46a12597dfcd5c 27593458 2023-12-27 13:24:45 +0000 UTC 5 months ago enterprise  IN    Contract: SwapAndCloseTool 1.946484 IOTX 0.104765
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SwapAndCloseTool

Compiler Version
v0.8.18+commit.87f61d96

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion, None license

Contract Source Code (Solidity)

// Sources flattened with hardhat v2.19.2 https://hardhat.org

// SPDX-License-Identifier: MIT

// File @openzeppelin/contracts/token/ERC20/extensions/[email protected]

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

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

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

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


// File @openzeppelin/contracts/token/ERC20/[email protected]

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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


// File @openzeppelin/contracts/utils/[email protected]

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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


// File @openzeppelin/contracts/token/ERC20/utils/[email protected]

// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;



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

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

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

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

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

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

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

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

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

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

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

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

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


// File contracts/Interfaces/IPriceFeed.sol

// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.9;

interface IPriceFeed {
    function fetchPrice() external returns (uint);
}


// File contracts/Interfaces/ITroveManager.sol

// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.9;

interface ITroveManager {
    function getEntireDebtAndColl(address _borrower) external view returns (
        uint debt, 
        uint coll, 
        uint pendingLUSDDebtReward, 
        uint pendingETHReward
    );

    function getTroveDebt(address _borrower) external view returns (uint);
}


// File contracts/Interfaces/IBorrowerOperations.sol

// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.9;


interface IBorrowerOperations {
    function closeTroveOnBehalf(address troveOwner) external;
    function troveManager() external view returns(ITroveManager);
    function LUSD_GAS_COMPENSATION() external view returns(uint);
    function lusdToken() external view returns(address);
    function priceFeed() external view returns(IPriceFeed);
}


// File contracts/Interfaces/IMimoV2Router02NoReferral.sol

// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.9;

interface IMimoV2Router02NoReferral {
    
    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactETHForTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (uint256[] memory amounts);

    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (uint256[] memory amounts);

    function getAmountsOut(uint256 amountIn, address[] memory path)
        external
        view
        returns (uint256[] memory amounts);

    function getAmountsIn(uint256 amountOut, address[] memory path)
        external
        view
        returns (uint256[] memory amounts);

    function WETH() external view returns(address);
}


// File contracts/SwapAndCloseTool.sol

// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.9;





contract SwapAndCloseTool {
    using Address for address;
    using SafeERC20 for IERC20;

    IBorrowerOperations public borrowerOperations;
    ITroveManager public troveManager;
    IMimoV2Router02NoReferral public mimoRouter;
    IERC20 public WEN;
    address public WETH;

    constructor(address _borrowerOperations, address _mimoRouter) {
        require(_borrowerOperations.isContract(), "SwapAndCloseTool: borrowerOperations is not contract");
        require(_mimoRouter.isContract(), "SwapAndCloseTool: mimoRouter is not contract");

        borrowerOperations = IBorrowerOperations(_borrowerOperations);
        troveManager = borrowerOperations.troveManager();
        mimoRouter = IMimoV2Router02NoReferral(_mimoRouter);
        WEN = IERC20(borrowerOperations.lusdToken());
        WETH = mimoRouter.WETH();

        WEN.approve(address(borrowerOperations), type(uint256).max);
    }

    function swapAndCloseTrove() payable external {
        uint debt = troveManager.getTroveDebt(msg.sender);
        require(debt > 0, "SwapAndCloseTool: debt is 0");
        debt = debt - borrowerOperations.LUSD_GAS_COMPENSATION();

        uint256 balance = WEN.balanceOf(msg.sender);
        uint256 transferIn = balance >= debt ? debt : balance;
        if (transferIn > 0) {
            WEN.safeTransferFrom(msg.sender, address(this), transferIn);
        }

        if (WEN.balanceOf(address(this)) < debt) {
            uint256 amountOut = debt - WEN.balanceOf(address(this));
            // swap
            address[] memory path = new address[](2);
            path[0] = WETH;
            path[1] = address(WEN);
            uint256[] memory amounts = mimoRouter.getAmountsIn(amountOut, path);
            require(msg.value >= amounts[0], "SwapAndCloseTool: ETH is not enough");

            mimoRouter.swapETHForExactTokens{value: amounts[0]}(amountOut, path, address(this), block.timestamp + 10);
        }

        // close trove
        borrowerOperations.closeTroveOnBehalf(msg.sender);
        if(address(this).balance > 0) {
            (bool success, ) = msg.sender.call{ value: address(this).balance }("");
            require(success, "SwapAndCloseTool: sending ETH failed");
        }
    }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_borrowerOperations","type":"address"},{"internalType":"address","name":"_mimoRouter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WEN","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowerOperations","outputs":[{"internalType":"contract IBorrowerOperations","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mimoRouter","outputs":[{"internalType":"contract IMimoV2Router02NoReferral","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapAndCloseTrove","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"troveManager","outputs":[{"internalType":"contract ITroveManager","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

Contract Creation Code

6080604052600436106100555760003560e01c8063341a87731461005a5780633d83908a1461006457806352c70ad01461008f57806377553ad4146100ba5780637f477738146100e5578063ad5c464814610110575b600080fd5b61006261013b565b005b34801561007057600080fd5b50610079610967565b6040516100869190610dc0565b60405180910390f35b34801561009b57600080fd5b506100a461098d565b6040516100b19190610dfc565b60405180910390f35b3480156100c657600080fd5b506100cf6109b3565b6040516100dc9190610e38565b60405180910390f35b3480156100f157600080fd5b506100fa6109d7565b6040516101079190610e74565b60405180910390f35b34801561011c57600080fd5b506101256109fd565b6040516101329190610eb0565b60405180910390f35b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d66a2553336040518263ffffffff1660e01b81526004016101989190610eb0565b602060405180830381865afa1580156101b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d99190610f15565b90506000811161021e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161021590610f9f565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e86bbd86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610289573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102ad9190610f15565b816102b89190610fee565b90506000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231336040518263ffffffff1660e01b81526004016103179190610eb0565b602060405180830381865afa158015610334573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103589190610f15565b905060008282101561036a578161036c565b825b905060008111156103c7576103c6333083600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610a46909392919063ffffffff16565b5b82600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016104239190610eb0565b602060405180830381865afa158015610440573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104649190610f15565b1015610820576000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016104c79190610eb0565b602060405180830381865afa1580156104e4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105089190610f15565b846105139190610fee565b90506000600267ffffffffffffffff81111561053257610531611022565b5b6040519080825280602002602001820160405280156105605781602001602082028036833780820191505090505b509050600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160008151811061059a57610599611051565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160018151811061060b5761060a611051565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250506000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631f00ca7484846040518363ffffffff1660e01b81526004016106a492919061114d565b600060405180830381865afa1580156106c1573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906106ea91906112a7565b905080600081518110610700576106ff611051565b5b602002602001015134101561074a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161074190611362565b60405180910390fd5b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fb3bdb418260008151811061079c5761079b611051565b5b6020026020010151858530600a426107b49190611382565b6040518663ffffffff1660e01b81526004016107d394939291906113b6565b60006040518083038185885af11580156107f1573d6000803e3d6000fd5b50505050506040513d6000823e3d601f19601f8201168201806040525081019061081b91906112a7565b505050505b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663c345960c336040518263ffffffff1660e01b81526004016108799190610eb0565b600060405180830381600087803b15801561089357600080fd5b505af11580156108a7573d6000803e3d6000fd5b5050505060004711156109625760003373ffffffffffffffffffffffffffffffffffffffff16476040516108da90611433565b60006040518083038185875af1925050503d8060008114610917576040519150601f19603f3d011682016040523d82523d6000602084013e61091c565b606091505b5050905080610960576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610957906114ba565b60405180910390fd5b505b505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b610ac9846323b872dd60e01b858585604051602401610a67939291906114da565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610acf565b50505050565b6000610b31826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610b979092919063ffffffff16565b9050600081511480610b53575080806020019051810190610b529190611549565b5b610b92576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b89906115e8565b60405180910390fd5b505050565b6060610ba68484600085610baf565b90509392505050565b606082471015610bf4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610beb9061167a565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051610c1d9190611700565b60006040518083038185875af1925050503d8060008114610c5a576040519150601f19603f3d011682016040523d82523d6000602084013e610c5f565b606091505b5091509150610c7087838387610c7c565b92505050949350505050565b60608315610cde576000835103610cd657610c9685610a23565b610cd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ccc90611763565b60405180910390fd5b5b829050610ce9565b610ce88383610cf1565b5b949350505050565b600082511115610d045781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d3891906117c7565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000610d86610d81610d7c84610d41565b610d61565b610d41565b9050919050565b6000610d9882610d6b565b9050919050565b6000610daa82610d8d565b9050919050565b610dba81610d9f565b82525050565b6000602082019050610dd56000830184610db1565b92915050565b6000610de682610d8d565b9050919050565b610df681610ddb565b82525050565b6000602082019050610e116000830184610ded565b92915050565b6000610e2282610d8d565b9050919050565b610e3281610e17565b82525050565b6000602082019050610e4d6000830184610e29565b92915050565b6000610e5e82610d8d565b9050919050565b610e6e81610e53565b82525050565b6000602082019050610e896000830184610e65565b92915050565b6000610e9a82610d41565b9050919050565b610eaa81610e8f565b82525050565b6000602082019050610ec56000830184610ea1565b92915050565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b610ef281610edf565b8114610efd57600080fd5b50565b600081519050610f0f81610ee9565b92915050565b600060208284031215610f2b57610f2a610ed5565b5b6000610f3984828501610f00565b91505092915050565b600082825260208201905092915050565b7f53776170416e64436c6f7365546f6f6c3a206465627420697320300000000000600082015250565b6000610f89601b83610f42565b9150610f9482610f53565b602082019050919050565b60006020820190508181036000830152610fb881610f7c565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610ff982610edf565b915061100483610edf565b925082820390508181111561101c5761101b610fbf565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b61108981610edf565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6110c481610e8f565b82525050565b60006110d683836110bb565b60208301905092915050565b6000602082019050919050565b60006110fa8261108f565b611104818561109a565b935061110f836110ab565b8060005b8381101561114057815161112788826110ca565b9750611132836110e2565b925050600181019050611113565b5085935050505092915050565b60006040820190506111626000830185611080565b818103602083015261117481846110ef565b90509392505050565b600080fd5b6000601f19601f8301169050919050565b61119c82611182565b810181811067ffffffffffffffff821117156111bb576111ba611022565b5b80604052505050565b60006111ce610ecb565b90506111da8282611193565b919050565b600067ffffffffffffffff8211156111fa576111f9611022565b5b602082029050602081019050919050565b600080fd5b600061122361121e846111df565b6111c4565b905080838252602082019050602084028301858111156112465761124561120b565b5b835b8181101561126f578061125b8882610f00565b845260208401935050602081019050611248565b5050509392505050565b600082601f83011261128e5761128d61117d565b5b815161129e848260208601611210565b91505092915050565b6000602082840312156112bd576112bc610ed5565b5b600082015167ffffffffffffffff8111156112db576112da610eda565b5b6112e784828501611279565b91505092915050565b7f53776170416e64436c6f7365546f6f6c3a20455448206973206e6f7420656e6f60008201527f7567680000000000000000000000000000000000000000000000000000000000602082015250565b600061134c602383610f42565b9150611357826112f0565b604082019050919050565b6000602082019050818103600083015261137b8161133f565b9050919050565b600061138d82610edf565b915061139883610edf565b92508282019050808211156113b0576113af610fbf565b5b92915050565b60006080820190506113cb6000830187611080565b81810360208301526113dd81866110ef565b90506113ec6040830185610ea1565b6113f96060830184611080565b95945050505050565b600081905092915050565b50565b600061141d600083611402565b91506114288261140d565b600082019050919050565b600061143e82611410565b9150819050919050565b7f53776170416e64436c6f7365546f6f6c3a2073656e64696e672045544820666160008201527f696c656400000000000000000000000000000000000000000000000000000000602082015250565b60006114a4602483610f42565b91506114af82611448565b604082019050919050565b600060208201905081810360008301526114d381611497565b9050919050565b60006060820190506114ef6000830186610ea1565b6114fc6020830185610ea1565b6115096040830184611080565b949350505050565b60008115159050919050565b61152681611511565b811461153157600080fd5b50565b6000815190506115438161151d565b92915050565b60006020828403121561155f5761155e610ed5565b5b600061156d84828501611534565b91505092915050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b60006115d2602a83610f42565b91506115dd82611576565b604082019050919050565b60006020820190508181036000830152611601816115c5565b9050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b6000611664602683610f42565b915061166f82611608565b604082019050919050565b6000602082019050818103600083015261169381611657565b9050919050565b600081519050919050565b60005b838110156116c35780820151818401526020810190506116a8565b60008484015250505050565b60006116da8261169a565b6116e48185611402565b93506116f48185602086016116a5565b80840191505092915050565b600061170c82846116cf565b915081905092915050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b600061174d601d83610f42565b915061175882611717565b602082019050919050565b6000602082019050818103600083015261177c81611740565b9050919050565b600081519050919050565b600061179982611783565b6117a38185610f42565b93506117b38185602086016116a5565b6117bc81611182565b840191505092915050565b600060208201905081810360008301526117e1818461178e565b90509291505056fea264697066735822122005c9fa74f91d2395bb2f2cc230be572c6fceb67030a2e497bfb61fb3406739b864736f6c63430008120033

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