ETH Price: $2,849.72 (-3.11%)
 

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Close Loan307177372025-05-26 2:00:21245 days ago1748224821IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.00000430.00557458
Close Loan301308602025-05-12 11:57:47258 days ago1747051067IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000074110.0192
Close Loan301308132025-05-12 11:56:13258 days ago1747050973IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000104620.0146
Close Loan301262772025-05-12 9:25:01258 days ago1747041901IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000031210.0376
Close Loan299700322025-05-08 18:36:51262 days ago1746729411IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000007370.0076
Close Loan299509892025-05-08 8:02:05262 days ago1746691325IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000067590.0351
Close Loan274491292025-03-11 10:06:45320 days ago1741687605IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000005770.00320317
Close Loan263000932025-02-12 19:45:33347 days ago1739389533IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000008640.00944163
Close Loan262842812025-02-12 10:58:29347 days ago1739357909IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000006750.00402963
Close Loan258823712025-02-03 3:41:29357 days ago1738554089IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000074540.04921116
Close Loan258820122025-02-03 3:29:31357 days ago1738553371IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000061130.05416747
Close Loan256744752025-01-29 8:11:37361 days ago1738138297IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000003870.00504682
Close Loan256693742025-01-29 5:21:35361 days ago1738128095IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.00000440.00379942
Close Loan256432022025-01-28 14:49:11362 days ago1738075751IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000023520.00894449
Create Loan255986592025-01-27 14:04:25363 days ago1737986665IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000029920.02213469
Close Loan255158122025-01-25 16:02:51365 days ago1737820971IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000006330.0085
Close Loan255156172025-01-25 15:56:21365 days ago1737820581IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000007740.0082
Close Loan255154872025-01-25 15:52:01365 days ago1737820321IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000000390.00746013
Close Loan255154872025-01-25 15:52:01365 days ago1737820321IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000000390.00746013
Close Loan255154712025-01-25 15:51:29365 days ago1737820289IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000000380.0075
Close Loan255154702025-01-25 15:51:27365 days ago1737820287IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000000380.0075
Close Loan255154692025-01-25 15:51:25365 days ago1737820285IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000005690.00741712
Close Loan255146192025-01-25 15:23:05365 days ago1737818585IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.00000490.0064
Close Loan255143532025-01-25 15:14:13365 days ago1737818053IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000001360.0059
Close Loan254854712025-01-24 23:11:29366 days ago1737760289IN
0xad7Fa0db...A0f48f1Ad
0 ETH0.000066150.00601355
View all transactions

Parent Transaction Hash Block From To
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
FlashLoanZap

Compiler Version
v0.8.25+commit.b61c2a91

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion, None license
// SPDX-License-Identifier: MIT

pragma solidity 0.8.25;

import { SafeERC20 } from "contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "contracts/token/ERC20/IERC20.sol";
import { IERC3156FlashBorrower } from "contracts/interfaces/IERC3156FlashBorrower.sol";
import { IMarketOperator } from "contracts/interfaces/IMarketOperator.sol";
import { OdosZapBase } from "contracts/periphery/zaps/dependencies/OdosZapBase.sol";

/**
    @title FlashLoan Zap using Odos V2 Router
    @author defidotmoney
    @notice Create, adjust, and close loans using flashloans and performing swaps via Odos
    @dev Used as a delegate for calls to `MainController`
 */
contract FlashLoanZap is OdosZapBase, IERC3156FlashBorrower {
    using SafeERC20 for IERC20;

    bytes32 private constant _RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");

    enum Action {
        CreateLoan,
        IncreaseLoan,
        DecreaseLoan,
        CloseLoan,
        CloseAndCreateLoan
    }

    /**
        @notice Contract constructor
        @param _mainController MainController contract address
        @param _stable Stablecoin token address
        @param _router Odos router address (available at https://github.com/odos-xyz/odos-router-v2)
     */
    constructor(
        address _mainController,
        address _stable,
        address _router
    ) OdosZapBase(_mainController, _stable, _router) {
        IERC20(_stable).approve(_mainController, type(uint256).max);
        IERC20(_stable).approve(_stable, type(uint256).max);
    }

    /**
        @notice Use a flashloan to create a new loan
        @dev The router swap should convert exactly `debtAmount` of stablecoin into the collateral
             for the given market. The entire received collateral balance is used to create the new
             loan. No stablecoins or collateral are returned.
        @param market Address of the market to create a new loan in
        @param collAmount Collateral amount provided by the caller
        @param debtAmount Amount of stablecoins to open a loan for
        @param numBands Number of bands to use for the loan
        @param routingData Odos router swap calldata
     */
    function createLoan(
        address market,
        uint256 collAmount,
        uint256 debtAmount,
        uint256 numBands,
        bytes calldata routingData
    ) external nonReentrant {
        IERC20 collateral = getCollateralOrRevert(market);
        if (collAmount > 0) collateral.safeTransferFrom(msg.sender, address(this), collAmount);

        bytes memory data = abi.encode(Action.CreateLoan, msg.sender, market, collateral, numBands, routingData);
        stableCoin.flashLoan(this, address(stableCoin), debtAmount, data);
    }

    /**
        @notice Use a flashloan to increase the debt and collateral of an existing loan
        @dev The router swap should convert `debtAmount` of stablecoin into the collateral for the
             given market. The loan adjustment adds the entire collateral balance and mints the
             required stablecoins to repay the flashloan. No stablecoins or collateral are returned.
        @param market Address of the market where the loan is being adjusted
        @param collAmount Collateral amount provided by the caller
        @param debtAmount Stablecoin amount to flashloan
        @param routingData Odos router swap calldata
     */
    function increaseLoan(
        address market,
        uint256 collAmount,
        uint256 debtAmount,
        bytes calldata routingData
    ) external nonReentrant {
        IERC20 collateral = getCollateralOrRevert(market);
        if (collAmount > 0) collateral.safeTransferFrom(msg.sender, address(this), collAmount);

        bytes memory data = abi.encode(Action.IncreaseLoan, msg.sender, market, collateral, routingData);
        stableCoin.flashLoan(this, address(stableCoin), debtAmount, data);
    }

    /**
        @notice Decrease the debt of an existing loan by selling collateral
        @dev The router swap must convert up to `collAmount` of collateral into at least `debtAmount`
             of stablecoin. Any remaining stablecoin or collateral balances are transferred to the caller.
        @param market Address of the market to close the loan in
        @param collAmount Amount of collateral to withdraw from the loan
        @param debtAmount Amount of debt to reduce the loan by
        @param routingData Odos router swap calldata
     */
    function decreaseLoan(
        address market,
        uint256 collAmount,
        uint256 debtAmount,
        bytes calldata routingData
    ) external nonReentrant {
        IERC20 collateral = getCollateralOrRevert(market);

        bytes memory data = abi.encode(Action.DecreaseLoan, msg.sender, market, collateral, collAmount, routingData);
        stableCoin.flashLoan(this, address(stableCoin), debtAmount, data);

        _transferTokensToCaller(collateral);
    }

    /**
        @notice Close a loan by selling collateral to cover a portion of the debt
        @dev The router swap should convert enough collateral into stablecoin to cover the debt
             shortfall. Remaining stablecoin and collateral balances are transferred to the caller.
        @param market Address of the market to close the loan in
        @param debtAmount Stablecoin amount provided by the caller
        @param routingData Odos router swap calldata
     */
    function closeLoan(address market, uint256 debtAmount, bytes calldata routingData) external nonReentrant {
        IERC20 collateral = getCollateralOrRevert(market);
        if (debtAmount > 0) stableCoin.transferFrom(msg.sender, address(this), debtAmount);

        (int256 debtChange, uint256 collReceived) = mainController.get_close_loan_amounts(msg.sender, market);
        require(debtChange < 0, "DFM: No debt owed");
        require(collReceived > 0, "DFM: No coll received");

        uint256 debtShortfall = uint256(-debtChange) - debtAmount;

        bytes memory data = abi.encode(Action.CloseLoan, msg.sender, market, collateral, routingData);
        stableCoin.flashLoan(this, address(stableCoin), debtShortfall, data);

        _transferTokensToCaller(collateral);
    }

    /**
        @notice Use a flashloan to close and recreate a loan
        @dev * The router swap can trade between collateral and stablecoins in either direction.
             * The swap executes after closing the existing loan and before opening a new one.
             * The amounts available to swap are equal to the loan's AMM balances plus any added
               collateral or minted debt.
             * The final amounts for the new loan are equal to the zap's balances after the swap,
               less any withdrawn collateral or repaid debt.
        @param market Address of the market to adjust the loan in
        @param collChange Collateral adjustment amount. A positive value transfers collateral from
            the caller to add to the loan. A negative value withdraws collateral from the loan and
            sends to the caller.
        @param debtChange Debt adjustment amount. A positive value mints additional debt and sends
            it to the caller. A negative value transfers debt from the caller and uses it to repay
            the loan.
        @param numBands Number of bands to set the loan to.
        @param routingData Optional odos router swap calldata. Leave empty if no swap is required.
     */
    function closeAndCreateLoan(
        address market,
        int256 collChange,
        int256 debtChange,
        uint256 numBands,
        bytes calldata routingData
    ) external {
        IERC20 collateral = getCollateralOrRevert(market);

        if (collChange > 0) {
            collateral.safeTransferFrom(msg.sender, address(this), uint256(collChange));
            collChange = 0;
        }

        uint256 flashloanAmount = IMarketOperator(market).debt(msg.sender);

        if (debtChange < 0) {
            uint256 debtReduction = uint256(-debtChange);
            require(flashloanAmount > debtReduction, "DFM: -debtChange > debt");
            flashloanAmount -= debtReduction;
            stableCoin.transferFrom(msg.sender, address(this), debtReduction);
            debtChange = 0;
        } else {
            // increase flashloan amount so newly minted debt is available during the router swap
            flashloanAmount += uint256(debtChange);
        }

        bytes memory data = abi.encode(
            Action.CloseAndCreateLoan,
            msg.sender,
            market,
            collateral,
            -collChange,
            debtChange,
            numBands,
            routingData
        );
        stableCoin.flashLoan(this, address(stableCoin), flashloanAmount, data);

        _transferTokensToCaller(collateral);
    }

    /**
        @dev This contract assumes that `stableCoin` only ever performs flashloans of itself and
             that the fee charged will always be zero. If you are modifying this contract for use
             with a different flashlender, consider if whether implementation requires validation
             checks for the `fee` and `token` parameters.
     */
    function onFlashLoan(
        address initiator,
        address /* token */,
        uint256 amount,
        uint /* fee */,
        bytes calldata data
    ) external returns (bytes32) {
        require(msg.sender == address(stableCoin), "DFM: Invalid caller");
        require(initiator == address(this), "DFM: Invalid initiator");

        Action action = abi.decode(data, (Action));
        if (action == Action.CreateLoan) _flashCreate(amount, data);
        else if (action == Action.IncreaseLoan) _flashIncrease(amount, data);
        else if (action == Action.DecreaseLoan) _flashDecrease(amount, data);
        else if (action == Action.CloseLoan) _flashClose(data);
        else if (action == Action.CloseAndCreateLoan) _flashCloseAndCreate(amount, data);
        else revert("DFM: Invalid flashloan action");

        return _RETURN_VALUE;
    }

    /**
        @dev 1. Swaps the flashloaned stablecoins for collateral.
             2. Uses the collateral to create a new loan and mint stablecoins to repay the flashloan.
     */
    function _flashCreate(uint256 flashloanAmount, bytes calldata data) internal {
        (, address account, address market, IERC20 collateral, uint256 numBands, bytes memory routingData) = abi.decode(
            data,
            (uint256, address, address, IERC20, uint256, bytes)
        );

        callRouter(routingData, 0);
        uint256 collAmount = collateral.balanceOf(address(this));
        uint256 debtAmount = _calculateDebtAmount(flashloanAmount, 1);
        mainController.create_loan(account, market, collAmount, debtAmount, numBands);
    }

    /**
        @dev 1. Swaps the flashloaned stablecoins for collateral.
             2. Adds the collateral to an existing loan and mints stablecoins to repay the flashloan.
     */
    function _flashIncrease(uint256 flashloanAmount, bytes calldata data) internal {
        (, address account, address market, IERC20 collateral, bytes memory routingData) = abi.decode(
            data,
            (uint256, address, address, IERC20, bytes)
        );

        callRouter(routingData, 0);
        int256 collAmount = int256(collateral.balanceOf(address(this)));
        int256 debtAmount = int256(_calculateDebtAmount(flashloanAmount, 0));
        mainController.adjust_loan(account, market, collAmount, debtAmount);
    }

    /**
        @dev 1. Uses the flashloaned stablecoin to repay an existing loan, and withdraws a portion of the collateral.
             2. Swaps the withdrawn collateral for the stablecoins required repay the flashloan.
     */
    function _flashDecrease(uint256 flashloanAmount, bytes calldata data) internal {
        (, address account, address market, IERC20 collateral, uint256 collAmount, bytes memory routingData) = abi
            .decode(data, (uint256, address, address, IERC20, uint256, bytes));

        mainController.adjust_loan(account, market, -int256(collAmount), -int256(flashloanAmount));
        callRouter(routingData, 0);
    }

    /**
        @dev 1. Uses the available stablecoin balance (flashloaned and received from the caller) to
                close an existing loan, and receive the collateral from the loan.
             2. Swaps the withdrawn collateral for the stablecoins required repay the flashloan.
     */
    function _flashClose(bytes calldata data) internal {
        (, address account, address market, IERC20 collateral, bytes memory routingData) = abi.decode(
            data,
            (uint256, address, address, IERC20, bytes)
        );

        (, uint256 collReceived) = mainController.close_loan(account, market);
        callRouter(routingData, 0);
    }

    /**
        @dev 1. Uses the available stablecoin balance to close an existing loan.
             2. Optionally performs a swap between collateral and stablecoins (in either direction).
             3. Uses available collateral balance to create a new loan, and mints the stablecoin
                balance required to repay the flashloan.
     */
    function _flashCloseAndCreate(uint256 flashloanAmount, bytes calldata data) internal {
        (
            ,
            address account,
            address market,
            IERC20 collateral,
            uint256 collateralOut,
            uint256 debtOut,
            uint256 numBands,
            bytes memory routingData
        ) = abi.decode(data, (uint256, address, address, IERC20, uint256, uint256, uint256, bytes));

        mainController.close_loan(account, market);

        // router swap is optional
        if (routingData.length > 0) callRouter(routingData, 0);

        uint256 collAmount = collateral.balanceOf(address(this));
        if (collateralOut > 0) {
            require(collAmount > collateralOut, "DFM: No collateral");
            collAmount -= collateralOut;
        }
        uint256 debtAmount = _calculateDebtAmount(flashloanAmount + debtOut, 1);
        mainController.create_loan(account, market, collAmount, debtAmount, numBands);
    }

    function _transferTokensToCaller(IERC20 collateral) internal {
        uint256 amount = collateral.balanceOf(address(this));
        if (amount > 0) collateral.safeTransfer(msg.sender, amount);

        amount = stableCoin.balanceOf(address(this));
        if (amount > 0) stableCoin.transfer(msg.sender, amount);
    }

    function _calculateDebtAmount(uint256 flashloanAmount, uint256 minAmount) internal view returns (uint256) {
        uint256 balance = stableCoin.balanceOf(address(this));
        if (flashloanAmount > balance) {
            return flashloanAmount - balance;
        } else {
            return minAmount;
        }
    }
}

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

pragma solidity ^0.8.0;

import "contracts/token/ERC20/IERC20.sol";
import "contracts/token/ERC20/extensions/IERC20Permit.sol";
import "contracts/utils/Address.sol";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// 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 6 of 25 : IERC3156FlashBorrower.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC3156FlashBorrower.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC3156 FlashBorrower, as defined in
 * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
 *
 * _Available since v4.1._
 */
interface IERC3156FlashBorrower {
    /**
     * @dev Receive a flash loan.
     * @param initiator The initiator of the loan.
     * @param token The loan currency.
     * @param amount The amount of tokens lent.
     * @param fee The additional amount of tokens to repay.
     * @param data Arbitrary data structure, intended to contain user-defined parameters.
     * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
     */
    function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external returns (bytes32);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IMarketOperator {
    function debt(address account) external view returns (uint256);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.25;

import { SafeERC20 } from "contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuard } from "contracts/security/ReentrancyGuard.sol";
import { IERC20 } from "contracts/token/ERC20/IERC20.sol";
import { IMainController } from "contracts/interfaces/IMainController.sol";
import { IBridgeToken } from "contracts/interfaces/IBridgeToken.sol";

/**
    @title Odos Zap abstract base
    @author defidotmoney
    @notice Base logic for performing token swaps via Odos' V2 router
    @dev Used as a delegate for calls to `MainController`
 */
abstract contract OdosZapBase is ReentrancyGuard {
    using SafeERC20 for IERC20;

    IMainController public immutable mainController;
    IBridgeToken public immutable stableCoin;
    address public immutable router;

    mapping(address market => IERC20 collateral) internal _marketCollaterals;
    mapping(IERC20 token => bool isRouterApproved) internal _routerApprovals;

    /**
        @notice Contract constructor
        @param _mainController MainController contract address
        @param _stable Stablecoin token address
        @param _router Odos router address (available at https://github.com/odos-xyz/odos-router-v2)
     */
    constructor(address _mainController, address _stable, address _router) {
        mainController = IMainController(_mainController);
        stableCoin = IBridgeToken(_stable);
        router = _router;
        approveRouter(IERC20(_stable));
    }

    function approveRouter(IERC20 token) internal {
        if (!_routerApprovals[token]) {
            token.forceApprove(router, type(uint256).max);
            _routerApprovals[token] = true;
        }
    }

    function getCollateralOrRevert(address market) internal returns (IERC20) {
        IERC20 collateral = _marketCollaterals[market];
        if (address(collateral) == address(0)) {
            collateral = IERC20(mainController.get_collateral(market));
            require(address(collateral) != address(0), "DFM: Market does not exist");
            collateral.forceApprove(address(mainController), type(uint256).max);
            approveRouter(collateral);
            _marketCollaterals[market] = collateral;
        }
        return collateral;
    }

    function callRouter(bytes memory routingData, uint256 nativeAmount) internal {
        (bool success, ) = router.call{ value: nativeAmount }(routingData);
        require(success, "DFM: Odos router call failed");
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

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

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

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

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

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

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IMainController {
    function get_collateral(address market) external view returns (address);

    function get_oracle_price(address collateral) external view returns (uint256);

    function get_close_loan_amounts(
        address account,
        address market
    ) external view returns (int256 callerDebtBalanceChange, uint256 collReceived);

    function create_loan(
        address account,
        address market,
        uint256 collAmount,
        uint256 debtAmount,
        uint256 numBands
    ) external;

    function adjust_loan(address account, address market, int256 collChange, int256 debtChange) external;

    function close_loan(
        address account,
        address market
    ) external returns (int256 callerDebtBalanceChange, uint256 collReceived);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { IERC3156FlashLender } from "contracts/interfaces/IERC3156FlashLender.sol";
import { IBridgeTokenBase } from "contracts/interfaces/IBridgeTokenBase.sol";

interface IBridgeToken is IBridgeTokenBase, IERC3156FlashLender {
    function setMinter(address minter, bool isApproved) external returns (bool);

    function mint(address _account, uint256 _amount) external returns (bool);

    function burn(address _account, uint256 _amount) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156FlashLender.sol)

pragma solidity ^0.8.0;

import "contracts/interfaces/IERC3156FlashBorrower.sol";

/**
 * @dev Interface of the ERC3156 FlashLender, as defined in
 * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
 *
 * _Available since v4.1._
 */
interface IERC3156FlashLender {
    /**
     * @dev The amount of currency available to be lended.
     * @param token The loan currency.
     * @return The amount of `token` that can be borrowed.
     */
    function maxFlashLoan(address token) external view returns (uint256);

    /**
     * @dev The fee to be charged for a given loan.
     * @param token The loan currency.
     * @param amount The amount of tokens lent.
     * @return The amount of `token` to be charged for the loan, on top of the returned principal.
     */
    function flashFee(address token, uint256 amount) external view returns (uint256);

    /**
     * @dev Initiate a flash loan.
     * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
     * @param token The loan currency.
     * @param amount The amount of tokens lent.
     * @param data Arbitrary data structure, intended to contain user-defined parameters.
     */
    function flashLoan(
        IERC3156FlashBorrower receiver,
        address token,
        uint256 amount,
        bytes calldata data
    ) external returns (bool);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { IOFT } from "contracts/oft/interfaces/IOFT.sol";
import { IOAppCore } from "contracts/oapp/interfaces/IOAppCore.sol";
import { IERC20Metadata } from "contracts/token/ERC20/extensions/IERC20Metadata.sol";

interface IBridgeTokenBase is IOFT, IOAppCore, IERC20Metadata {
    function quoteSimple(uint32 _eid, address _target, uint256 _amount) external view returns (uint256);

    function sendSimple(uint32 _eid, address _target, uint256 _amount) external payable returns (uint256);

    function globalPeerCount() external view returns (uint256);

    function setPeer(uint32 _eid, bytes32 _peer) external;

    function thisId() external view returns (uint32);

    function defaultOptions() external view returns (bytes memory);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { MessagingReceipt, MessagingFee } from "contracts/oapp/OAppSender.sol";

/**
 * @dev Struct representing token parameters for the OFT send() operation.
 */
struct SendParam {
    uint32 dstEid; // Destination endpoint ID.
    bytes32 to; // Recipient address.
    uint256 amountLD; // Amount to send in local decimals.
    uint256 minAmountLD; // Minimum amount to send in local decimals.
    bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
    bytes composeMsg; // The composed message for the send() operation.
    bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations.
}

/**
 * @dev Struct representing OFT limit information.
 * @dev These amounts can change dynamically and are up the the specific oft implementation.
 */
struct OFTLimit {
    uint256 minAmountLD; // Minimum amount in local decimals that can be sent to the recipient.
    uint256 maxAmountLD; // Maximum amount in local decimals that can be sent to the recipient.
}

/**
 * @dev Struct representing OFT receipt information.
 */
struct OFTReceipt {
    uint256 amountSentLD; // Amount of tokens ACTUALLY debited from the sender in local decimals.
    // @dev In non-default implementations, the amountReceivedLD COULD differ from this value.
    uint256 amountReceivedLD; // Amount of tokens to be received on the remote side.
}

/**
 * @dev Struct representing OFT fee details.
 * @dev Future proof mechanism to provide a standardized way to communicate fees to things like a UI.
 */
struct OFTFeeDetail {
    int256 feeAmountLD; // Amount of the fee in local decimals.
    string description; // Description of the fee.
}

/**
 * @title IOFT
 * @dev Interface for the OftChain (OFT) token.
 * @dev Does not inherit ERC20 to accommodate usage by OFTAdapter as well.
 * @dev This specific interface ID is '0x02e49c2c'.
 */
interface IOFT {
    // Custom error messages
    error InvalidLocalDecimals();
    error SlippageExceeded(uint256 amountLD, uint256 minAmountLD);

    // Events
    event OFTSent(
        bytes32 indexed guid, // GUID of the OFT message.
        uint32 dstEid, // Destination Endpoint ID.
        address indexed fromAddress, // Address of the sender on the src chain.
        uint256 amountSentLD, // Amount of tokens sent in local decimals.
        uint256 amountReceivedLD // Amount of tokens received in local decimals.
    );
    event OFTReceived(
        bytes32 indexed guid, // GUID of the OFT message.
        uint32 srcEid, // Source Endpoint ID.
        address indexed toAddress, // Address of the recipient on the dst chain.
        uint256 amountReceivedLD // Amount of tokens received in local decimals.
    );

    /**
     * @notice Retrieves interfaceID and the version of the OFT.
     * @return interfaceId The interface ID.
     * @return version The version.
     *
     * @dev interfaceId: This specific interface ID is '0x02e49c2c'.
     * @dev version: Indicates a cross-chain compatible msg encoding with other OFTs.
     * @dev If a new feature is added to the OFT cross-chain msg encoding, the version will be incremented.
     * ie. localOFT version(x,1) CAN send messages to remoteOFT version(x,1)
     */
    function oftVersion() external view returns (bytes4 interfaceId, uint64 version);

    /**
     * @notice Retrieves the address of the token associated with the OFT.
     * @return token The address of the ERC20 token implementation.
     */
    function token() external view returns (address);

    /**
     * @notice Indicates whether the OFT contract requires approval of the 'token()' to send.
     * @return requiresApproval Needs approval of the underlying token implementation.
     *
     * @dev Allows things like wallet implementers to determine integration requirements,
     * without understanding the underlying token implementation.
     */
    function approvalRequired() external view returns (bool);

    /**
     * @notice Retrieves the shared decimals of the OFT.
     * @return sharedDecimals The shared decimals of the OFT.
     */
    function sharedDecimals() external view returns (uint8);

    /**
     * @notice Provides a quote for OFT-related operations.
     * @param _sendParam The parameters for the send operation.
     * @return limit The OFT limit information.
     * @return oftFeeDetails The details of OFT fees.
     * @return receipt The OFT receipt information.
     */
    function quoteOFT(
        SendParam calldata _sendParam
    ) external view returns (OFTLimit memory, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory);

    /**
     * @notice Provides a quote for the send() operation.
     * @param _sendParam The parameters for the send() operation.
     * @param _payInLzToken Flag indicating whether the caller is paying in the LZ token.
     * @return fee The calculated LayerZero messaging fee from the send() operation.
     *
     * @dev MessagingFee: LayerZero msg fee
     *  - nativeFee: The native fee.
     *  - lzTokenFee: The lzToken fee.
     */
    function quoteSend(SendParam calldata _sendParam, bool _payInLzToken) external view returns (MessagingFee memory);

    /**
     * @notice Executes the send() operation.
     * @param _sendParam The parameters for the send operation.
     * @param _fee The fee information supplied by the caller.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess funds from fees etc. on the src.
     * @return receipt The LayerZero messaging receipt from the send() operation.
     * @return oftReceipt The OFT receipt information.
     *
     * @dev MessagingReceipt: LayerZero msg receipt
     *  - guid: The unique identifier for the sent message.
     *  - nonce: The nonce of the sent message.
     *  - fee: The LayerZero fee incurred for the message.
     */
    function send(
        SendParam calldata _sendParam,
        MessagingFee calldata _fee,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory, OFTReceipt memory);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { SafeERC20, IERC20 } from "contracts/token/ERC20/utils/SafeERC20.sol";
import { MessagingParams, MessagingFee, MessagingReceipt } from "contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppCore } from "contracts/oapp/OAppCore.sol";

/**
 * @title OAppSender
 * @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
 */
abstract contract OAppSender is OAppCore {
    using SafeERC20 for IERC20;

    // Custom error messages
    error NotEnoughNative(uint256 msgValue);
    error LzTokenUnavailable();

    // @dev The version of the OAppSender implementation.
    // @dev Version is bumped when changes are made to this contract.
    uint64 internal constant SENDER_VERSION = 1;

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     *
     * @dev Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented.
     * ie. this is a SEND only OApp.
     * @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions
     */
    function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
        return (SENDER_VERSION, 0);
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _payInLzToken Flag indicating whether to pay the fee in LZ tokens.
     * @return fee The calculated MessagingFee for the message.
     *      - nativeFee: The native fee for the message.
     *      - lzTokenFee: The LZ token fee for the message.
     */
    function _quote(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        bool _payInLzToken
    ) internal view virtual returns (MessagingFee memory fee) {
        return
            endpoint.quote(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken),
                address(this)
            );
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.send() for sending a message.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _fee The calculated LayerZero fee for the message.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess fee values sent to the endpoint.
     * @return receipt The receipt for the sent message.
     *      - guid: The unique identifier for the sent message.
     *      - nonce: The nonce of the sent message.
     *      - fee: The LayerZero fee incurred for the message.
     */
    function _lzSend(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        MessagingFee memory _fee,
        address _refundAddress
    ) internal virtual returns (MessagingReceipt memory receipt) {
        // @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the endpoint.
        uint256 messageValue = _payNative(_fee.nativeFee);
        if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);

        return
            // solhint-disable-next-line check-send-result
            endpoint.send{ value: messageValue }(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0),
                _refundAddress
            );
    }

    /**
     * @dev Internal function to pay the native fee associated with the message.
     * @param _nativeFee The native fee to be paid.
     * @return nativeFee The amount of native currency paid.
     *
     * @dev If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction,
     * this will need to be overridden because msg.value would contain multiple lzFees.
     * @dev Should be overridden in the event the LayerZero endpoint requires a different native currency.
     * @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
     * @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
     */
    function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee) {
        if (msg.value != _nativeFee) revert NotEnoughNative(msg.value);
        return _nativeFee;
    }

    /**
     * @dev Internal function to pay the LZ token fee associated with the message.
     * @param _lzTokenFee The LZ token fee to be paid.
     *
     * @dev If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.
     * @dev Any excess sent, is passed back to the specified _refundAddress in the _lzSend().
     */
    function _payLzToken(uint256 _lzTokenFee) internal virtual {
        // @dev Cannot cache the token because it is not immutable in the endpoint.
        address lzToken = endpoint.lzToken();
        if (lzToken == address(0)) revert LzTokenUnavailable();

        // Pay LZ token fee by sending tokens to the endpoint.
        IERC20(lzToken).safeTransferFrom(msg.sender, address(endpoint), _lzTokenFee);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { IMessageLibManager } from "contracts/interfaces/IMessageLibManager.sol";
import { IMessagingComposer } from "contracts/interfaces/IMessagingComposer.sol";
import { IMessagingChannel } from "contracts/interfaces/IMessagingChannel.sol";
import { IMessagingContext } from "contracts/interfaces/IMessagingContext.sol";

struct MessagingParams {
    uint32 dstEid;
    bytes32 receiver;
    bytes message;
    bytes options;
    bool payInLzToken;
}

struct MessagingReceipt {
    bytes32 guid;
    uint64 nonce;
    MessagingFee fee;
}

struct MessagingFee {
    uint256 nativeFee;
    uint256 lzTokenFee;
}

struct Origin {
    uint32 srcEid;
    bytes32 sender;
    uint64 nonce;
}

interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
    event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);

    event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);

    event PacketDelivered(Origin origin, address receiver);

    event LzReceiveAlert(
        address indexed receiver,
        address indexed executor,
        Origin origin,
        bytes32 guid,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    event LzTokenSet(address token);

    event DelegateSet(address sender, address delegate);

    function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);

    function send(
        MessagingParams calldata _params,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory);

    function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;

    function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);

    function initializable(Origin calldata _origin, address _receiver) external view returns (bool);

    function lzReceive(
        Origin calldata _origin,
        address _receiver,
        bytes32 _guid,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;

    // oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
    function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;

    function setLzToken(address _lzToken) external;

    function lzToken() external view returns (address);

    function nativeToken() external view returns (address);

    function setDelegate(address _delegate) external;
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

struct SetConfigParam {
    uint32 eid;
    uint32 configType;
    bytes config;
}

interface IMessageLibManager {
    struct Timeout {
        address lib;
        uint256 expiry;
    }

    event LibraryRegistered(address newLib);
    event DefaultSendLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
    event SendLibrarySet(address sender, uint32 eid, address newLib);
    event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
    event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);

    function registerLibrary(address _lib) external;

    function isRegisteredLibrary(address _lib) external view returns (bool);

    function getRegisteredLibraries() external view returns (address[] memory);

    function setDefaultSendLibrary(uint32 _eid, address _newLib) external;

    function defaultSendLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function defaultReceiveLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;

    function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);

    function isSupportedEid(uint32 _eid) external view returns (bool);

    function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);

    /// ------------------- OApp interfaces -------------------
    function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;

    function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);

    function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);

    function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);

    function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;

    function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);

    function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;

    function getConfig(
        address _oapp,
        address _lib,
        uint32 _eid,
        uint32 _configType
    ) external view returns (bytes memory config);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingComposer {
    event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
    event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
    event LzComposeAlert(
        address indexed from,
        address indexed to,
        address indexed executor,
        bytes32 guid,
        uint16 index,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    function composeQueue(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index
    ) external view returns (bytes32 messageHash);

    function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;

    function lzCompose(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingChannel {
    event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
    event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
    event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);

    function eid() external view returns (uint32);

    // this is an emergency function if a message cannot be verified for some reasons
    // required to provide _nextNonce to avoid race condition
    function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;

    function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);

    function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);

    function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);

    function inboundPayloadHash(
        address _receiver,
        uint32 _srcEid,
        bytes32 _sender,
        uint64 _nonce
    ) external view returns (bytes32);

    function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingContext {
    function isSendingMessage() external view returns (bool);

    function getSendContext() external view returns (uint32 dstEid, address sender);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { Ownable } from "contracts/access/Ownable.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "contracts/oapp/interfaces/IOAppCore.sol";

/**
 * @title OAppCore
 * @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
 */
abstract contract OAppCore is IOAppCore, Ownable {
    // The LayerZero endpoint associated with the given OApp
    ILayerZeroEndpointV2 public immutable endpoint;

    // Mapping to store peers associated with corresponding endpoints
    mapping(uint32 eid => bytes32 peer) public peers;

    /**
     * @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
     * @param _endpoint The address of the LOCAL Layer Zero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     *
     * @dev The delegate typically should be set as the owner of the contract.
     */
    constructor(address _endpoint, address _delegate) {
        endpoint = ILayerZeroEndpointV2(_endpoint);

        if (_delegate == address(0)) revert InvalidDelegate();
        endpoint.setDelegate(_delegate);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function setPeer(uint32 _eid, bytes32 _peer) public virtual onlyOwner {
        _setPeer(_eid, _peer);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function _setPeer(uint32 _eid, bytes32 _peer) internal virtual {
        peers[_eid] = _peer;
        emit PeerSet(_eid, _peer);
    }

    /**
     * @notice Internal function to get the peer address associated with a specific endpoint; reverts if NOT set.
     * ie. the peer is set to bytes32(0).
     * @param _eid The endpoint ID.
     * @return peer The address of the peer associated with the specified endpoint.
     */
    function _getPeerOrRevert(uint32 _eid) internal view virtual returns (bytes32) {
        bytes32 peer = peers[_eid];
        if (peer == bytes32(0)) revert NoPeer(_eid);
        return peer;
    }

    /**
     * @notice Sets the delegate address for the OApp.
     * @param _delegate The address of the delegate to be set.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Provides the ability for a delegate to set configs, on behalf of the OApp, directly on the Endpoint contract.
     */
    function setDelegate(address _delegate) public onlyOwner {
        endpoint.setDelegate(_delegate);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "contracts/utils/Context.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 Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @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 Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { ILayerZeroEndpointV2 } from "contracts/interfaces/ILayerZeroEndpointV2.sol";

/**
 * @title IOAppCore
 */
interface IOAppCore {
    // Custom error messages
    error OnlyPeer(uint32 eid, bytes32 sender);
    error NoPeer(uint32 eid);
    error InvalidEndpointCall();
    error InvalidDelegate();

    // Event emitted when a peer (OApp) is set for a corresponding endpoint
    event PeerSet(uint32 eid, bytes32 peer);

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     */
    function oAppVersion() external view returns (uint64 senderVersion, uint64 receiverVersion);

    /**
     * @notice Retrieves the LayerZero endpoint associated with the OApp.
     * @return iEndpoint The LayerZero endpoint as an interface.
     */
    function endpoint() external view returns (ILayerZeroEndpointV2 iEndpoint);

    /**
     * @notice Retrieves the peer (OApp) associated with a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @return peer The peer address (OApp instance) associated with the corresponding endpoint.
     */
    function peers(uint32 _eid) external view returns (bytes32 peer);

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     */
    function setPeer(uint32 _eid, bytes32 _peer) external;

    /**
     * @notice Sets the delegate address for the OApp Core.
     * @param _delegate The address of the delegate to be set.
     */
    function setDelegate(address _delegate) external;
}

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

pragma solidity ^0.8.0;

import "contracts/token/ERC20/IERC20.sol";

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

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

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

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

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_mainController","type":"address"},{"internalType":"address","name":"_stable","type":"address"},{"internalType":"address","name":"_router","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"int256","name":"collChange","type":"int256"},{"internalType":"int256","name":"debtChange","type":"int256"},{"internalType":"uint256","name":"numBands","type":"uint256"},{"internalType":"bytes","name":"routingData","type":"bytes"}],"name":"closeAndCreateLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"debtAmount","type":"uint256"},{"internalType":"bytes","name":"routingData","type":"bytes"}],"name":"closeLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"collAmount","type":"uint256"},{"internalType":"uint256","name":"debtAmount","type":"uint256"},{"internalType":"uint256","name":"numBands","type":"uint256"},{"internalType":"bytes","name":"routingData","type":"bytes"}],"name":"createLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"collAmount","type":"uint256"},{"internalType":"uint256","name":"debtAmount","type":"uint256"},{"internalType":"bytes","name":"routingData","type":"bytes"}],"name":"decreaseLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"collAmount","type":"uint256"},{"internalType":"uint256","name":"debtAmount","type":"uint256"},{"internalType":"bytes","name":"routingData","type":"bytes"}],"name":"increaseLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mainController","outputs":[{"internalType":"contract IMainController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"initiator","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onFlashLoan","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stableCoin","outputs":[{"internalType":"contract IBridgeToken","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60e060405234801561001057600080fd5b50604051612b47380380612b4783398101604081905261002f916105a8565b60016000556001600160a01b0380841660805280831660a052811660c0528282826100598261014d565b505060405163095ea7b360e01b81526001600160a01b03858116600483015260001960248301528416915063095ea7b3906044016020604051808303816000875af11580156100ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d091906105eb565b5060405163095ea7b360e01b81526001600160a01b0383166004820181905260001960248301529063095ea7b3906044016020604051808303816000875af1158015610120573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061014491906105eb565b50505050610687565b6001600160a01b03811660009081526002602052604090205460ff166101ab5760c051610187906001600160a01b038316906000196101ae565b6001600160a01b0381166000908152600260205260409020805460ff191660011790555b50565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b0390811663095ea7b360e01b17909152610206908590839061027d16565b610277576040516001600160a01b03841660248201526000604482015261026d90859063095ea7b360e01b9060640160408051808303601f190181529190526020810180516001600160e01b0319939093166001600160e01b039384161790529061032416565b6102778482610324565b50505050565b6000806000846001600160a01b03168460405161029a9190610638565b6000604051808303816000865af19150503d80600081146102d7576040519150601f19603f3d011682016040523d82523d6000602084013e6102dc565b606091505b509150915081801561030657508051158061030657508080602001905181019061030691906105eb565b801561031b57506001600160a01b0385163b15155b95945050505050565b6040805180820190915260208082527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656490820152600090610371906001600160a01b0385169084906103fb565b905080516000148061039257508080602001905181019061039291906105eb565b6103f65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b505050565b606061040a8484600085610412565b949350505050565b6060824710156104735760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016103ed565b600080866001600160a01b0316858760405161048f9190610638565b60006040518083038185875af1925050503d80600081146104cc576040519150601f19603f3d011682016040523d82523d6000602084013e6104d1565b606091505b5090925090506104e3878383876104ee565b979650505050505050565b6060831561055d578251600003610556576001600160a01b0385163b6105565760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103ed565b508161040a565b61040a83838151156105725781518083602001fd5b8060405162461bcd60e51b81526004016103ed9190610654565b80516001600160a01b03811681146105a357600080fd5b919050565b6000806000606084860312156105bd57600080fd5b6105c68461058c565b92506105d46020850161058c565b91506105e26040850161058c565b90509250925092565b6000602082840312156105fd57600080fd5b8151801515811461060d57600080fd5b9392505050565b60005b8381101561062f578181015183820152602001610617565b50506000910152565b6000825161064a818460208701610614565b9190910192915050565b6020815260008251806020840152610673816040850160208701610614565b601f01601f19169190910160400192915050565b60805160a05160c0516123f861074f6000396000818161018a015281816116a101526118da015260008181610150015281816101b901528181610403015281816104e3015281816106d3015281816108a90152818161098101528181610a8a01528181610b9201528181611520015281816115b7015261178d01526000818160eb0152818161058401528181610d0601528181610e4701528181610ecf01528181610fd9015281816110ab015281816112470152818161134d015261141f01526123f86000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c806340c331601161006657806340c331601461012557806364e7ba5214610138578063992642e51461014b578063c1c0f82614610172578063f887ea401461018557600080fd5b806323e30c8b1461009857806329f4d3d9146100be5780632a8bba26146100d35780633c43b87c146100e6575b600080fd5b6100ab6100a6366004611cc2565b6101ac565b6040519081526020015b60405180910390f35b6100d16100cc366004611d3e565b6103af565b005b6100d16100e1366004611da8565b6104a6565b61010d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016100b5565b6100d1610133366004611e04565b610778565b6100d1610146366004611e04565b610a1c565b61010d7f000000000000000000000000000000000000000000000000000000000000000081565b6100d1610180366004611d3e565b610b25565b61010d7f000000000000000000000000000000000000000000000000000000000000000081565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146102215760405162461bcd60e51b81526020600482015260136024820152722223269d1024b73b30b634b21031b0b63632b960691b60448201526064015b60405180910390fd5b6001600160a01b03871630146102725760405162461bcd60e51b81526020600482015260166024820152752223269d1024b73b30b634b21034b734ba34b0ba37b960511b6044820152606401610218565b600061028083850185611e59565b9050600081600481111561029657610296611e81565b036102ab576102a6868585610c25565b610382565b60018160048111156102bf576102bf611e81565b036102cf576102a6868585610d70565b60028160048111156102e3576102e3611e81565b036102f3576102a6868585610eb0565b600381600481111561030757610307611e81565b03610316576102a68484610f92565b600481600481111561032a5761032a611e81565b0361033a576102a686858561105e565b60405162461bcd60e51b815260206004820152601d60248201527f44464d3a20496e76616c696420666c6173686c6f616e20616374696f6e0000006044820152606401610218565b507f439148f0bbc682ca079e46d6e2c2f0c1e3b820f1a291b069d8882abf8cf18dd9979650505050505050565b6103b76112b3565b60006103c28661130c565b9050600060023388848988886040516020016103e49796959493929190611ee2565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03811691635cffe9de91610446913091908a908790600401611f88565b6020604051808303816000875af1158015610465573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104899190611fc5565b5061049382611484565b505061049f6001600055565b5050505050565b6104ae6112b3565b60006104b98561130c565b9050831561055a576040516323b872dd60e01b8152336004820152306024820152604481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610534573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105589190611fc5565b505b604051635b7aaef160e01b81523360048201526001600160a01b03868116602483015260009182917f00000000000000000000000000000000000000000000000000000000000000001690635b7aaef1906044016040805180830381865afa1580156105ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ee9190611fe7565b91509150600082126106365760405162461bcd60e51b81526020600482015260116024820152701111934e88139bc81919589d081bddd959607a1b6044820152606401610218565b6000811161067e5760405162461bcd60e51b81526020600482015260156024820152741111934e88139bc818dbdb1b081c9958d95a5d9959605a1b6044820152606401610218565b60008661068a84612021565b610694919061203d565b905060006003338a878a8a6040516020016106b496959493929190612050565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03811691635cffe9de916107169130919087908790600401611f88565b6020604051808303816000875af1158015610735573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107599190611fc5565b5061076385611484565b50505050506107726001600055565b50505050565b60006107838761130c565b905060008613156107a8576107a36001600160a01b038216333089611632565b600095505b6040516326db15bb60e21b81523360048201526000906001600160a01b03891690639b6c56ec90602401602060405180830381865afa1580156107ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610813919061209e565b9050600086121561092957600061082987612021565b905080821161087a5760405162461bcd60e51b815260206004820152601760248201527f44464d3a202d646562744368616e6765203e20646562740000000000000000006044820152606401610218565b610884818361203d565b6040516323b872dd60e01b8152336004820152306024820152604481018390529092507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af11580156108fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091e9190611fc5565b506000965050610936565b61093386826120b7565b90505b60006004338a856109468c612021565b8b8b8b8b604051602001610962999897969594939291906120ca565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03811691635cffe9de916109c49130919087908790600401611f88565b6020604051808303816000875af11580156109e3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a079190611fc5565b50610a1183611484565b505050505050505050565b610a246112b3565b6000610a2f8761130c565b90508515610a4c57610a4c6001600160a01b038216333089611632565b600080338984888888604051602001610a6b9796959493929190611ee2565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03811691635cffe9de91610acd913091908b908790600401611f88565b6020604051808303816000875af1158015610aec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b109190611fc5565b505050610b1d6001600055565b505050505050565b610b2d6112b3565b6000610b388661130c565b90508415610b5557610b556001600160a01b038216333088611632565b600060013388848787604051602001610b7396959493929190612050565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03811691635cffe9de91610bd5913091908a908790600401611f88565b6020604051808303816000875af1158015610bf4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c189190611fc5565b50505061049f6001600055565b600080808080610c37868801886121d4565b9550955095509550955050610c4d81600061169d565b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015610c94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb8919061209e565b90506000610cc78a600161176b565b604051638930995f60e01b81526001600160a01b03898116600483015288811660248301526044820185905260648201839052608482018790529192507f000000000000000000000000000000000000000000000000000000000000000090911690638930995f9060a401600060405180830381600087803b158015610d4c57600080fd5b505af1158015610d60573d6000803e3d6000fd5b5050505050505050505050505050565b6000808080610d818587018761225b565b945094509450945050610d9581600061169d565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610ddc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e00919061209e565b90506000610e0f89600061176b565b604051632ba0840f60e01b81526001600160a01b038881166004830152878116602483015260448201859052606482018390529192507f000000000000000000000000000000000000000000000000000000000000000090911690632ba0840f90608401600060405180830381600087803b158015610e8d57600080fd5b505af1158015610ea1573d6000803e3d6000fd5b50505050505050505050505050565b600080808080610ec2868801886121d4565b95509550955095509550507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632ba0840f868685610f0890612021565b610f118d612021565b6040516001600160e01b031960e087901b1681526001600160a01b03948516600482015293909216602484015260448301526064820152608401600060405180830381600087803b158015610f6557600080fd5b505af1158015610f79573d6000803e3d6000fd5b50505050610f8881600061169d565b5050505050505050565b6000808080610fa38587018761225b565b60405163099c828f60e11b81526001600160a01b03858116600483015284811660248301529499509297509095509350600092507f000000000000000000000000000000000000000000000000000000000000000090911690631339051e9060440160408051808303816000875af1158015611023573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110479190611fe7565b91505061105582600061169d565b50505050505050565b6000808080808080611072888a018a6122da565b60405163099c828f60e11b81526001600160a01b0388811660048301528781166024830152979f50959d50939b509199509750955093507f00000000000000000000000000000000000000000000000000000000000000009091169150631339051e9060440160408051808303816000875af11580156110f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111a9190611fe7565b505080511561112e5761112e81600061169d565b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa158015611175573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611199919061209e565b905084156111f2578481116111e55760405162461bcd60e51b81526020600482015260126024820152711111934e88139bc818dbdb1b185d195c985b60721b6044820152606401610218565b6111ef858261203d565b90505b6000611208611201868e6120b7565b600161176b565b604051638930995f60e01b81526001600160a01b038b811660048301528a811660248301526044820185905260648201839052608482018790529192507f000000000000000000000000000000000000000000000000000000000000000090911690638930995f9060a401600060405180830381600087803b15801561128d57600080fd5b505af11580156112a1573d6000803e3d6000fd5b50505050505050505050505050505050565b6002600054036113055760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610218565b6002600055565b6001600160a01b038082166000908152600160205260408120549091168061147e5760405163359a9a0560e11b81526001600160a01b0384811660048301527f00000000000000000000000000000000000000000000000000000000000000001690636b35340a90602401602060405180830381865afa158015611394573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b89190612376565b90506001600160a01b0381166114105760405162461bcd60e51b815260206004820152601a60248201527f44464d3a204d61726b657420646f6573206e6f742065786973740000000000006044820152606401610218565b6114466001600160a01b0382167f000000000000000000000000000000000000000000000000000000000000000060001961181c565b61144f816118ab565b6001600160a01b03838116600090815260016020526040902080546001600160a01b0319169183169190911790555b92915050565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156114cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ef919061209e565b9050801561150b5761150b6001600160a01b0383163383611928565b6040516370a0823160e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa15801561156f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611593919061209e565b9050801561162e5760405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015611608573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061162c9190611fc5565b505b5050565b6040516001600160a01b03808516602483015283166044820152606481018290526107729085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611958565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031682846040516116d89190612393565b60006040518083038185875af1925050503d8060008114611715576040519150601f19603f3d011682016040523d82523d6000602084013e61171a565b606091505b505090508061162c5760405162461bcd60e51b815260206004820152601c60248201527f44464d3a204f646f7320726f757465722063616c6c206661696c6564000000006044820152606401610218565b6040516370a0823160e01b815230600482015260009081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381865afa1580156117d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f8919061209e565b9050808411156118145761180c818561203d565b91505061147e565b509092915050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261186d8482611a2d565b610772576040516001600160a01b0384166024820152600060448201526118a190859063095ea7b360e01b90606401611666565b6107728482611958565b6001600160a01b03811660009081526002602052604090205460ff16611925576119016001600160a01b0382167f000000000000000000000000000000000000000000000000000000000000000060001961181c565b6001600160a01b0381166000908152600260205260409020805460ff191660011790555b50565b6040516001600160a01b03831660248201526044810182905261162c90849063a9059cbb60e01b90606401611666565b60006119ad826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611ad49092919063ffffffff16565b90508051600014806119ce5750808060200190518101906119ce9190611fc5565b61162c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610218565b6000806000846001600160a01b031684604051611a4a9190612393565b6000604051808303816000865af19150503d8060008114611a87576040519150601f19603f3d011682016040523d82523d6000602084013e611a8c565b606091505b5091509150818015611ab6575080511580611ab6575080806020019051810190611ab69190611fc5565b8015611acb57506001600160a01b0385163b15155b95945050505050565b6060611ae38484600085611aeb565b949350505050565b606082471015611b4c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610218565b600080866001600160a01b03168587604051611b689190612393565b60006040518083038185875af1925050503d8060008114611ba5576040519150601f19603f3d011682016040523d82523d6000602084013e611baa565b606091505b5091509150611bbb87838387611bc6565b979650505050505050565b60608315611c35578251600003611c2e576001600160a01b0385163b611c2e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610218565b5081611ae3565b611ae38383815115611c4a5781518083602001fd5b8060405162461bcd60e51b815260040161021891906123af565b6001600160a01b038116811461192557600080fd5b60008083601f840112611c8b57600080fd5b50813567ffffffffffffffff811115611ca357600080fd5b602083019150836020828501011115611cbb57600080fd5b9250929050565b60008060008060008060a08789031215611cdb57600080fd5b8635611ce681611c64565b95506020870135611cf681611c64565b94506040870135935060608701359250608087013567ffffffffffffffff811115611d2057600080fd5b611d2c89828a01611c79565b979a9699509497509295939492505050565b600080600080600060808688031215611d5657600080fd5b8535611d6181611c64565b94506020860135935060408601359250606086013567ffffffffffffffff811115611d8b57600080fd5b611d9788828901611c79565b969995985093965092949392505050565b60008060008060608587031215611dbe57600080fd5b8435611dc981611c64565b935060208501359250604085013567ffffffffffffffff811115611dec57600080fd5b611df887828801611c79565b95989497509550505050565b60008060008060008060a08789031215611e1d57600080fd5b8635611e2881611c64565b9550602087013594506040870135935060608701359250608087013567ffffffffffffffff811115611d2057600080fd5b600060208284031215611e6b57600080fd5b813560058110611e7a57600080fd5b9392505050565b634e487b7160e01b600052602160045260246000fd5b60058110611eb557634e487b7160e01b600052602160045260246000fd5b9052565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b611eec8189611e97565b6001600160a01b0387811660208301528681166040830152851660608201526080810184905260c060a08201819052600090611f2b9083018486611eb9565b9998505050505050505050565b60005b83811015611f53578181015183820152602001611f3b565b50506000910152565b60008151808452611f74816020860160208601611f38565b601f01601f19169290920160200192915050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611fbb90830184611f5c565b9695505050505050565b600060208284031215611fd757600080fd5b81518015158114611e7a57600080fd5b60008060408385031215611ffa57600080fd5b505080516020909101519092909150565b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b82016120365761203661200b565b5060000390565b8181038181111561147e5761147e61200b565b61205a8188611e97565b6001600160a01b03868116602083015285811660408301528416606082015260a0608082018190526000906120929083018486611eb9565b98975050505050505050565b6000602082840312156120b057600080fd5b5051919050565b8082018082111561147e5761147e61200b565b60006101006120d9838d611e97565b6001600160a01b038b811660208501528a81166040850152891660608401526080830188905260a0830187905260c0830186905260e083018190526121218184018587611eb9565b9c9b505050505050505050505050565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261215857600080fd5b813567ffffffffffffffff8082111561217357612173612131565b604051601f8301601f19908116603f0116810190828211818310171561219b5761219b612131565b816040528381528660208588010111156121b457600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060008060008060c087890312156121ed57600080fd5b8635955060208701356121ff81611c64565b9450604087013561220f81611c64565b9350606087013561221f81611c64565b92506080870135915060a087013567ffffffffffffffff81111561224257600080fd5b61224e89828a01612147565b9150509295509295509295565b600080600080600060a0868803121561227357600080fd5b85359450602086013561228581611c64565b9350604086013561229581611c64565b925060608601356122a581611c64565b9150608086013567ffffffffffffffff8111156122c157600080fd5b6122cd88828901612147565b9150509295509295909350565b600080600080600080600080610100898b0312156122f757600080fd5b88359750602089013561230981611c64565b9650604089013561231981611c64565b9550606089013561232981611c64565b94506080890135935060a0890135925060c0890135915060e089013567ffffffffffffffff81111561235a57600080fd5b6123668b828c01612147565b9150509295985092959890939650565b60006020828403121561238857600080fd5b8151611e7a81611c64565b600082516123a5818460208701611f38565b9190910192915050565b602081526000611e7a6020830184611f5c56fea26469706673582212203be5e0d1cf96ed34aa4e0b1693235efee2567f2da1a7e8f060ecde7eb5e02e9864736f6c634300081900330000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd00000000000000000000000069420f9e38a4e60a62224c489be4bf7a9440249600000000000000000000000019ceead7105607cd444f5ad10dd51356436095a1

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100935760003560e01c806340c331601161006657806340c331601461012557806364e7ba5214610138578063992642e51461014b578063c1c0f82614610172578063f887ea401461018557600080fd5b806323e30c8b1461009857806329f4d3d9146100be5780632a8bba26146100d35780633c43b87c146100e6575b600080fd5b6100ab6100a6366004611cc2565b6101ac565b6040519081526020015b60405180910390f35b6100d16100cc366004611d3e565b6103af565b005b6100d16100e1366004611da8565b6104a6565b61010d7f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd81565b6040516001600160a01b0390911681526020016100b5565b6100d1610133366004611e04565b610778565b6100d1610146366004611e04565b610a1c565b61010d7f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a9440249681565b6100d1610180366004611d3e565b610b25565b61010d7f00000000000000000000000019ceead7105607cd444f5ad10dd51356436095a181565b6000336001600160a01b037f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a9440249616146102215760405162461bcd60e51b81526020600482015260136024820152722223269d1024b73b30b634b21031b0b63632b960691b60448201526064015b60405180910390fd5b6001600160a01b03871630146102725760405162461bcd60e51b81526020600482015260166024820152752223269d1024b73b30b634b21034b734ba34b0ba37b960511b6044820152606401610218565b600061028083850185611e59565b9050600081600481111561029657610296611e81565b036102ab576102a6868585610c25565b610382565b60018160048111156102bf576102bf611e81565b036102cf576102a6868585610d70565b60028160048111156102e3576102e3611e81565b036102f3576102a6868585610eb0565b600381600481111561030757610307611e81565b03610316576102a68484610f92565b600481600481111561032a5761032a611e81565b0361033a576102a686858561105e565b60405162461bcd60e51b815260206004820152601d60248201527f44464d3a20496e76616c696420666c6173686c6f616e20616374696f6e0000006044820152606401610218565b507f439148f0bbc682ca079e46d6e2c2f0c1e3b820f1a291b069d8882abf8cf18dd9979650505050505050565b6103b76112b3565b60006103c28661130c565b9050600060023388848988886040516020016103e49796959493929190611ee2565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b03811691635cffe9de91610446913091908a908790600401611f88565b6020604051808303816000875af1158015610465573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104899190611fc5565b5061049382611484565b505061049f6001600055565b5050505050565b6104ae6112b3565b60006104b98561130c565b9050831561055a576040516323b872dd60e01b8152336004820152306024820152604481018590527f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610534573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105589190611fc5565b505b604051635b7aaef160e01b81523360048201526001600160a01b03868116602483015260009182917f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd1690635b7aaef1906044016040805180830381865afa1580156105ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ee9190611fe7565b91509150600082126106365760405162461bcd60e51b81526020600482015260116024820152701111934e88139bc81919589d081bddd959607a1b6044820152606401610218565b6000811161067e5760405162461bcd60e51b81526020600482015260156024820152741111934e88139bc818dbdb1b081c9958d95a5d9959605a1b6044820152606401610218565b60008661068a84612021565b610694919061203d565b905060006003338a878a8a6040516020016106b496959493929190612050565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b03811691635cffe9de916107169130919087908790600401611f88565b6020604051808303816000875af1158015610735573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107599190611fc5565b5061076385611484565b50505050506107726001600055565b50505050565b60006107838761130c565b905060008613156107a8576107a36001600160a01b038216333089611632565b600095505b6040516326db15bb60e21b81523360048201526000906001600160a01b03891690639b6c56ec90602401602060405180830381865afa1580156107ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610813919061209e565b9050600086121561092957600061082987612021565b905080821161087a5760405162461bcd60e51b815260206004820152601760248201527f44464d3a202d646562744368616e6765203e20646562740000000000000000006044820152606401610218565b610884818361203d565b6040516323b872dd60e01b8152336004820152306024820152604481018390529092507f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b0316906323b872dd906064016020604051808303816000875af11580156108fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091e9190611fc5565b506000965050610936565b61093386826120b7565b90505b60006004338a856109468c612021565b8b8b8b8b604051602001610962999897969594939291906120ca565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b03811691635cffe9de916109c49130919087908790600401611f88565b6020604051808303816000875af11580156109e3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a079190611fc5565b50610a1183611484565b505050505050505050565b610a246112b3565b6000610a2f8761130c565b90508515610a4c57610a4c6001600160a01b038216333089611632565b600080338984888888604051602001610a6b9796959493929190611ee2565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b03811691635cffe9de91610acd913091908b908790600401611f88565b6020604051808303816000875af1158015610aec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b109190611fc5565b505050610b1d6001600055565b505050505050565b610b2d6112b3565b6000610b388661130c565b90508415610b5557610b556001600160a01b038216333088611632565b600060013388848787604051602001610b7396959493929190612050565b60408051808303601f1901815290829052632e7ff4ef60e11b825291507f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b03811691635cffe9de91610bd5913091908a908790600401611f88565b6020604051808303816000875af1158015610bf4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c189190611fc5565b50505061049f6001600055565b600080808080610c37868801886121d4565b9550955095509550955050610c4d81600061169d565b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015610c94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb8919061209e565b90506000610cc78a600161176b565b604051638930995f60e01b81526001600160a01b03898116600483015288811660248301526044820185905260648201839052608482018790529192507f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd90911690638930995f9060a401600060405180830381600087803b158015610d4c57600080fd5b505af1158015610d60573d6000803e3d6000fd5b5050505050505050505050505050565b6000808080610d818587018761225b565b945094509450945050610d9581600061169d565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610ddc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e00919061209e565b90506000610e0f89600061176b565b604051632ba0840f60e01b81526001600160a01b038881166004830152878116602483015260448201859052606482018390529192507f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd90911690632ba0840f90608401600060405180830381600087803b158015610e8d57600080fd5b505af1158015610ea1573d6000803e3d6000fd5b50505050505050505050505050565b600080808080610ec2868801886121d4565b95509550955095509550507f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd6001600160a01b0316632ba0840f868685610f0890612021565b610f118d612021565b6040516001600160e01b031960e087901b1681526001600160a01b03948516600482015293909216602484015260448301526064820152608401600060405180830381600087803b158015610f6557600080fd5b505af1158015610f79573d6000803e3d6000fd5b50505050610f8881600061169d565b5050505050505050565b6000808080610fa38587018761225b565b60405163099c828f60e11b81526001600160a01b03858116600483015284811660248301529499509297509095509350600092507f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd90911690631339051e9060440160408051808303816000875af1158015611023573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110479190611fe7565b91505061105582600061169d565b50505050505050565b6000808080808080611072888a018a6122da565b60405163099c828f60e11b81526001600160a01b0388811660048301528781166024830152979f50959d50939b509199509750955093507f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd9091169150631339051e9060440160408051808303816000875af11580156110f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111a9190611fe7565b505080511561112e5761112e81600061169d565b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa158015611175573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611199919061209e565b905084156111f2578481116111e55760405162461bcd60e51b81526020600482015260126024820152711111934e88139bc818dbdb1b185d195c985b60721b6044820152606401610218565b6111ef858261203d565b90505b6000611208611201868e6120b7565b600161176b565b604051638930995f60e01b81526001600160a01b038b811660048301528a811660248301526044820185905260648201839052608482018790529192507f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd90911690638930995f9060a401600060405180830381600087803b15801561128d57600080fd5b505af11580156112a1573d6000803e3d6000fd5b50505050505050505050505050505050565b6002600054036113055760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610218565b6002600055565b6001600160a01b038082166000908152600160205260408120549091168061147e5760405163359a9a0560e11b81526001600160a01b0384811660048301527f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd1690636b35340a90602401602060405180830381865afa158015611394573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b89190612376565b90506001600160a01b0381166114105760405162461bcd60e51b815260206004820152601a60248201527f44464d3a204d61726b657420646f6573206e6f742065786973740000000000006044820152606401610218565b6114466001600160a01b0382167f0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd60001961181c565b61144f816118ab565b6001600160a01b03838116600090815260016020526040902080546001600160a01b0319169183169190911790555b92915050565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156114cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ef919061209e565b9050801561150b5761150b6001600160a01b0383163383611928565b6040516370a0823160e01b81523060048201527f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b0316906370a0823190602401602060405180830381865afa15801561156f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611593919061209e565b9050801561162e5760405163a9059cbb60e01b8152336004820152602481018290527f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a944024966001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015611608573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061162c9190611fc5565b505b5050565b6040516001600160a01b03808516602483015283166044820152606481018290526107729085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611958565b60007f00000000000000000000000019ceead7105607cd444f5ad10dd51356436095a16001600160a01b031682846040516116d89190612393565b60006040518083038185875af1925050503d8060008114611715576040519150601f19603f3d011682016040523d82523d6000602084013e61171a565b606091505b505090508061162c5760405162461bcd60e51b815260206004820152601c60248201527f44464d3a204f646f7320726f757465722063616c6c206661696c6564000000006044820152606401610218565b6040516370a0823160e01b815230600482015260009081906001600160a01b037f00000000000000000000000069420f9e38a4e60a62224c489be4bf7a9440249616906370a0823190602401602060405180830381865afa1580156117d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f8919061209e565b9050808411156118145761180c818561203d565b91505061147e565b509092915050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261186d8482611a2d565b610772576040516001600160a01b0384166024820152600060448201526118a190859063095ea7b360e01b90606401611666565b6107728482611958565b6001600160a01b03811660009081526002602052604090205460ff16611925576119016001600160a01b0382167f00000000000000000000000019ceead7105607cd444f5ad10dd51356436095a160001961181c565b6001600160a01b0381166000908152600260205260409020805460ff191660011790555b50565b6040516001600160a01b03831660248201526044810182905261162c90849063a9059cbb60e01b90606401611666565b60006119ad826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611ad49092919063ffffffff16565b90508051600014806119ce5750808060200190518101906119ce9190611fc5565b61162c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610218565b6000806000846001600160a01b031684604051611a4a9190612393565b6000604051808303816000865af19150503d8060008114611a87576040519150601f19603f3d011682016040523d82523d6000602084013e611a8c565b606091505b5091509150818015611ab6575080511580611ab6575080806020019051810190611ab69190611fc5565b8015611acb57506001600160a01b0385163b15155b95945050505050565b6060611ae38484600085611aeb565b949350505050565b606082471015611b4c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610218565b600080866001600160a01b03168587604051611b689190612393565b60006040518083038185875af1925050503d8060008114611ba5576040519150601f19603f3d011682016040523d82523d6000602084013e611baa565b606091505b5091509150611bbb87838387611bc6565b979650505050505050565b60608315611c35578251600003611c2e576001600160a01b0385163b611c2e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610218565b5081611ae3565b611ae38383815115611c4a5781518083602001fd5b8060405162461bcd60e51b815260040161021891906123af565b6001600160a01b038116811461192557600080fd5b60008083601f840112611c8b57600080fd5b50813567ffffffffffffffff811115611ca357600080fd5b602083019150836020828501011115611cbb57600080fd5b9250929050565b60008060008060008060a08789031215611cdb57600080fd5b8635611ce681611c64565b95506020870135611cf681611c64565b94506040870135935060608701359250608087013567ffffffffffffffff811115611d2057600080fd5b611d2c89828a01611c79565b979a9699509497509295939492505050565b600080600080600060808688031215611d5657600080fd5b8535611d6181611c64565b94506020860135935060408601359250606086013567ffffffffffffffff811115611d8b57600080fd5b611d9788828901611c79565b969995985093965092949392505050565b60008060008060608587031215611dbe57600080fd5b8435611dc981611c64565b935060208501359250604085013567ffffffffffffffff811115611dec57600080fd5b611df887828801611c79565b95989497509550505050565b60008060008060008060a08789031215611e1d57600080fd5b8635611e2881611c64565b9550602087013594506040870135935060608701359250608087013567ffffffffffffffff811115611d2057600080fd5b600060208284031215611e6b57600080fd5b813560058110611e7a57600080fd5b9392505050565b634e487b7160e01b600052602160045260246000fd5b60058110611eb557634e487b7160e01b600052602160045260246000fd5b9052565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b611eec8189611e97565b6001600160a01b0387811660208301528681166040830152851660608201526080810184905260c060a08201819052600090611f2b9083018486611eb9565b9998505050505050505050565b60005b83811015611f53578181015183820152602001611f3b565b50506000910152565b60008151808452611f74816020860160208601611f38565b601f01601f19169290920160200192915050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611fbb90830184611f5c565b9695505050505050565b600060208284031215611fd757600080fd5b81518015158114611e7a57600080fd5b60008060408385031215611ffa57600080fd5b505080516020909101519092909150565b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b82016120365761203661200b565b5060000390565b8181038181111561147e5761147e61200b565b61205a8188611e97565b6001600160a01b03868116602083015285811660408301528416606082015260a0608082018190526000906120929083018486611eb9565b98975050505050505050565b6000602082840312156120b057600080fd5b5051919050565b8082018082111561147e5761147e61200b565b60006101006120d9838d611e97565b6001600160a01b038b811660208501528a81166040850152891660608401526080830188905260a0830187905260c0830186905260e083018190526121218184018587611eb9565b9c9b505050505050505050505050565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261215857600080fd5b813567ffffffffffffffff8082111561217357612173612131565b604051601f8301601f19908116603f0116810190828211818310171561219b5761219b612131565b816040528381528660208588010111156121b457600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060008060008060c087890312156121ed57600080fd5b8635955060208701356121ff81611c64565b9450604087013561220f81611c64565b9350606087013561221f81611c64565b92506080870135915060a087013567ffffffffffffffff81111561224257600080fd5b61224e89828a01612147565b9150509295509295509295565b600080600080600060a0868803121561227357600080fd5b85359450602086013561228581611c64565b9350604086013561229581611c64565b925060608601356122a581611c64565b9150608086013567ffffffffffffffff8111156122c157600080fd5b6122cd88828901612147565b9150509295509295909350565b600080600080600080600080610100898b0312156122f757600080fd5b88359750602089013561230981611c64565b9650604089013561231981611c64565b9550606089013561232981611c64565b94506080890135935060a0890135925060c0890135915060e089013567ffffffffffffffff81111561235a57600080fd5b6123668b828c01612147565b9150509295985092959890939650565b60006020828403121561238857600080fd5b8151611e7a81611c64565b600082516123a5818460208701611f38565b9190910192915050565b602081526000611e7a6020830184611f5c56fea26469706673582212203be5e0d1cf96ed34aa4e0b1693235efee2567f2da1a7e8f060ecde7eb5e02e9864736f6c63430008190033

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

0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd00000000000000000000000069420f9e38a4e60a62224c489be4bf7a9440249600000000000000000000000019ceead7105607cd444f5ad10dd51356436095a1

-----Decoded View---------------
Arg [0] : _mainController (address): 0x1337F001E280420EcCe9E7B934Fa07D67fdb62CD
Arg [1] : _stable (address): 0x69420f9E38a4e60a62224C489be4BF7a94402496
Arg [2] : _router (address): 0x19cEeAd7105607Cd444F5ad10dd51356436095a1

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000001337f001e280420ecce9e7b934fa07d67fdb62cd
Arg [1] : 00000000000000000000000069420f9e38a4e60a62224c489be4bf7a94402496
Arg [2] : 00000000000000000000000019ceead7105607cd444f5ad10dd51356436095a1


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

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