Contract 0x6DDeb613b3f8977497883d96d9eD551F644B44b2 2

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x795529b019685dad7814b013506e8b11f7c523bedb0f02dcc877ee4548aefbbd0x61010060217962192021-11-25 20:04:327 days 57 mins ago0xb46693c062b49689cc4f624aab24a7ea90275890 IN  Contract Creation0 MATIC0.12373122
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
InteropAaveResolver

Compiler Version
v0.8.6+commit.11564f7e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 9 : main.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./helpers.sol";
import {
    AaveLendingPoolProviderInterface,
    AaveDataProviderInterface,
    AaveOracleInterface,
    IndexInterface
} from "./interfaces.sol";

contract InteropAaveResolver is Helpers {
    function checkAavePosition(
        address userAddress,
        Position memory position,
        uint256 safeRatioPercentage,
        bool isTarget
    ) public view returns(PositionData memory p) {
        (
            p.isOk,
            p.ltv,
            p.currentLiquidationThreshold
        ) = isPositionSafe(userAddress, safeRatioPercentage);
        p.isOk = isTarget ? true : p.isOk;
        if (!p.isOk) return p;

        p = _checkRatio(userAddress, position, safeRatioPercentage, isTarget);
        if (!p.isOk) return p;
    }

    function checkLiquidity(
        address liquidityAddress,
        address[] memory tokens,
        uint256 totalSupply,
        uint256 totalBorrow,
        uint256 safeLiquidityRatioPercentage,
        bool isTarget
    )
    public view returns(PositionData memory p) {
         (
            p.isOk,
            p.ltv,
            p.currentLiquidationThreshold
        ) = isPositionSafe(liquidityAddress, safeLiquidityRatioPercentage);
        if (!p.isOk) return p;

        p = _checkLiquidityRatio(
            liquidityAddress,
            tokens,
            safeLiquidityRatioPercentage,
            isTarget ? totalSupply :  totalBorrow
        );
        if (!p.isOk) return p;
    }

    constructor (
        address _aaveLendingPoolAddressesProvider,
        address _aaveProtocolDataProvider,
        address _instaIndex,
        address _wnativeToken
    ) Helpers (
        _aaveLendingPoolAddressesProvider,
        _aaveProtocolDataProvider,
        _instaIndex,
        _wnativeToken
    ){}
}

File 2 of 9 : helpers.sol
pragma solidity ^0.8.6;
pragma experimental ABIEncoderV2;

import { DSMath } from "./math.sol";
import { Variables } from "./variables.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { 
    AaveLendingPoolProviderInterface,
    AaveDataProviderInterface,
    AaveInterface,
    ATokenInterface,
    AavePriceOracle,
    ChainLinkInterface
} from "./interfaces.sol";

abstract contract Helpers is DSMath, Variables {
    using SafeERC20 for IERC20;

    constructor (
        address _aaveLendingPoolAddressesProvider,
        address _aaveProtocolDataProvider,
        address _instaIndex,
        address _wnativeToken
    ) Variables (
        _aaveLendingPoolAddressesProvider,
        _aaveProtocolDataProvider,
        _instaIndex,
        _wnativeToken
    ){}
    function convertTo18(uint amount, uint decimal) internal pure returns (uint) {
        return amount * (10 ** (18 - decimal));
    }

    function getTokensPrices(address[] memory tokens) public view returns(uint[] memory tokenPricesInEth) {
        tokenPricesInEth = AavePriceOracle(aaveLendingPoolAddressesProvider.getPriceOracle()).getAssetsPrices(tokens);
    }

    struct ReserveConfigData {
        uint256 decimals; // token decimals
        uint256 ltv; // loan to value
        uint256 tl; // liquidationThreshold
        bool enabledAsCollateral;
        bool borrowingEnabled;
        bool isActive;
        bool isFrozen;
        uint256 availableLiquidity;
        uint256 totalOverallDebt;
    }

    function getTokenInfos(address[] memory tokens) public view returns (ReserveConfigData[] memory reserveConfigData) {
        uint _len = tokens.length;
        reserveConfigData = new ReserveConfigData[](_len);
        for (uint i = 0; i < _len; i++) {
            (
                reserveConfigData[i].decimals,
                reserveConfigData[i].ltv,
                reserveConfigData[i].tl,
                ,
                ,
                reserveConfigData[i].enabledAsCollateral,
                reserveConfigData[i].borrowingEnabled,
                ,
                reserveConfigData[i].isActive,
                reserveConfigData[i].isFrozen
            ) = aaveProtocolDataProvider.getReserveConfigurationData(tokens[i]);

            uint256 totalStableDebt;
            uint256 totalVariableDebt;

            (
                reserveConfigData[i].availableLiquidity,
                totalStableDebt,
                totalVariableDebt,
                ,
                ,
                ,
                ,
                ,
                ,
            ) = aaveProtocolDataProvider.getReserveData(tokens[i]);

            reserveConfigData[i].totalOverallDebt = add(totalStableDebt, totalVariableDebt);
        }
    }

    function sortData(Position memory position, bool isTarget) public view returns (AaveData memory aaveData) {
        uint256 supplyLen = position.supply.length;
        uint256 borrowLen = position.withdraw.length;
        aaveData.supplyAmts = new uint256[](supplyLen);
        aaveData.borrowAmts = new uint256[](borrowLen);
        aaveData.supplyTokens = new address[](supplyLen);
        aaveData.borrowTokens = new address[](borrowLen);

        for (uint256 i = 0; i < supplyLen; i++) {
            uint256 amount = position.supply[i].amount;
            address token = !isTarget ? position.supply[i].sourceToken : position.supply[i].targetToken;
            token = token == nativeToken ? wnativeToken : token;
            aaveData.supplyTokens[i] = token;
            aaveData.supplyAmts[i] = amount;
        }

        for (uint256 i = 0; i < borrowLen; i++) {
            uint256 amount = position.withdraw[i].amount;
            address token = !isTarget ? position.withdraw[i].sourceToken : position.withdraw[i].targetToken;
            token = token == nativeToken ? wnativeToken : token;
            aaveData.borrowTokens[i] = token;
            aaveData.borrowAmts[i] = amount;
        }
    }

    function checkSupplyToken(
        address userAddress,
        AaveData memory data,
        bool isTarget
    ) public view returns (
        uint256 totalSupply,
        uint256 totalMaxBorrow,
        uint256 totalMaxLiquidation,
        bool isOk
    ) {
        
        uint256[] memory supplyTokenPrices = getTokensPrices(data.supplyTokens);
        ReserveConfigData[] memory supplyReserveConfigData = getTokenInfos(data.supplyTokens);
        isOk = true;
        for (uint256 i = 0; i < data.supplyTokens.length; i++) {

            if (!isTarget) {
                (
                    uint256 supply,
                    ,
                    ,
                    ,,,,,
                ) = aaveProtocolDataProvider.getUserReserveData(data.supplyTokens[i], userAddress);

                if (supply < data.supplyAmts[i]) {
                    isOk = false;
                }
            }

            uint256 _amt = wmul(
                convertTo18(data.supplyAmts[i], supplyReserveConfigData[i].decimals),
                supplyTokenPrices[i]
            );

            totalSupply += _amt;
            totalMaxLiquidation += (_amt * supplyReserveConfigData[i].tl) / 10000; // convert the number 8000 to 0.8
            totalMaxBorrow += (_amt * supplyReserveConfigData[i].ltv) / 10000; // convert the number 8000 to 0.8
        }
    }

    function checkLiquidityToken(
        address user,
        address[] memory tokens
    ) public view returns (
        uint256 totalSupply,
        uint256 totalBorrow,
        uint256 totalMaxBorrow,
        uint256 totalMaxLiquidation
    ) {
        uint256[] memory tokensPrices = getTokensPrices(tokens);
        ReserveConfigData[] memory reserveConfigData = getTokenInfos(tokens);
        for (uint256 i = 0; i < tokens.length; i++) {
             (
                uint256 supply,
                uint stableDebt,
                uint variableDebt,
                ,,,,,
            ) = aaveProtocolDataProvider.getUserReserveData(tokens[i], user);

            uint256 supplyAmtInUnderlying = wmul(
                convertTo18(supply, reserveConfigData[i].decimals),
                tokensPrices[i]
            );

            uint256 borrowAmtInUnderlying = wmul(
                convertTo18(
                    add(stableDebt, variableDebt),
                    reserveConfigData[i].decimals
                ),
                tokensPrices[i]
            );

            totalSupply += supplyAmtInUnderlying;
            totalBorrow += borrowAmtInUnderlying;
            totalMaxLiquidation += (supplyAmtInUnderlying * reserveConfigData[i].tl) / 10000; // convert the number 8000 to 0.8
            totalMaxBorrow += (supplyAmtInUnderlying * reserveConfigData[i].ltv) / 10000; // convert the number 8000 to 0.8
        }
    }


    function checkBorrowToken(
        address userAddress,
        AaveData memory data,
        bool isTarget
    ) public view returns (
        uint256 totalBorrow,
        bool isOk
    ) {
        
        uint256[] memory borrowTokenPrices = getTokensPrices(data.borrowTokens);
        ReserveConfigData[] memory borrowReserveConfigData = getTokenInfos(data.borrowTokens);
        isOk = true;
        for (uint256 i = 0; i < data.borrowTokens.length; i++) {

            if (!isTarget) {
                (
                    ,
                    uint stableDebt,
                    uint variableDebt,
                    ,,,,,
                ) = aaveProtocolDataProvider.getUserReserveData(data.borrowTokens[i], userAddress);

                uint256 borrow = stableDebt + variableDebt;

                if (borrow < data.borrowAmts[i]) {
                    isOk = false;
                }
            }

            uint256 _amt = wmul(
                convertTo18(data.borrowAmts[i], borrowReserveConfigData[i].decimals),
                borrowTokenPrices[i]
            );
            totalBorrow += _amt;
        }
    }

    struct PositionData {
        bool isOk;
        uint256 ratio;
        uint256 maxRatio;
        uint256 maxLiquidationRatio;
        uint256 ltv; // loan to value
        uint256 currentLiquidationThreshold; // liquidationThreshold
        uint256 totalSupply;
        uint256 totalBorrow;
        uint256 price;
    }

    /*
     * Checks the position to migrate should have a safe gap from liquidation 
    */
    function _checkRatio(
        address userAddress,
        Position memory position,
        uint256 safeRatioPercentage, 
        bool isTarget
    ) public view returns (
        PositionData memory positionData
    ) {
        AaveData memory data = sortData(position, isTarget);
        bool isSupplyOk;
        bool isBorrowOk;
        uint256 totalMaxBorrow;
        uint256 totalMaxLiquidation;

        (positionData.totalSupply, totalMaxBorrow, totalMaxLiquidation, isSupplyOk) = 
            checkSupplyToken(userAddress, data, isTarget);
        (positionData.totalBorrow, isBorrowOk) =
            checkBorrowToken(userAddress, data, isTarget);

        if (positionData.totalSupply > 0) {
            positionData.maxRatio = (totalMaxBorrow * 10000) / positionData.totalSupply;
            positionData.maxLiquidationRatio = (totalMaxLiquidation * 10000) / positionData.totalSupply;
            positionData.ratio = (positionData.totalBorrow * 10000) / positionData.totalSupply;
        }

        if (!isSupplyOk || !isBorrowOk) {
            positionData.isOk = false;
            return (positionData);
        }

        // require(positionData.totalBorrow < sub(liquidation, _dif), "position-is-risky-to-migrate");
        uint256 _dif = wmul(totalMaxLiquidation, sub(1e18, safeRatioPercentage));
        positionData.isOk = positionData.totalBorrow < sub(totalMaxLiquidation, _dif);
    }

    /*
     * Checks the position to migrate should have a safe gap from liquidation 
    */
    function _checkLiquidityRatio(
        address liquidity,
        address[] memory tokens,
        uint256 safeRatioPercentage,
        uint256 userTotalBorrow
    ) public view returns (
        PositionData memory positionData
    ) {
        uint256 totalMaxBorrow;
        uint256 totalMaxLiquidation;

        (
            positionData.totalSupply,
            positionData.totalBorrow,
            totalMaxBorrow,
            totalMaxLiquidation
        ) = checkLiquidityToken(liquidity, tokens);
        positionData.totalBorrow = add(positionData.totalBorrow, userTotalBorrow);

        if (positionData.totalSupply > 0) {
            positionData.maxRatio = (totalMaxBorrow * 10000) / positionData.totalSupply;
            positionData.maxLiquidationRatio = (totalMaxLiquidation * 10000) / positionData.totalSupply;
            positionData.ratio = (positionData.totalBorrow * 10000) / positionData.totalSupply;
        }

        uint256 _dif = wmul(positionData.totalSupply, sub(1e18, safeRatioPercentage));
        positionData.isOk = positionData.totalBorrow < sub(totalMaxLiquidation, _dif);
    }

    function isPositionSafe(
        address user,
        uint256 safeRatioPercentage
    ) public view returns (
        bool isOk,
        uint256 userTl,
        uint256 userLtv
    ) {
        AaveInterface aave = AaveInterface(aaveLendingPoolAddressesProvider.getLendingPool());
        uint healthFactor;
        (,,, userTl, userLtv, healthFactor) = aave.getUserAccountData(user);
        uint minLimit = wdiv(1e18, safeRatioPercentage);
        isOk = healthFactor > minLimit;
    }
}

File 3 of 9 : interfaces.sol
pragma solidity ^0.8.6;
pragma experimental ABIEncoderV2;

interface AaveInterface {
    function deposit(address _asset, uint256 _amount, address _onBehalfOf, uint16 _referralCode) external;
    function withdraw(address _asset, uint256 _amount, address _to) external;
    function borrow(
        address _asset,
        uint256 _amount,
        uint256 _interestRateMode,
        uint16 _referralCode,
        address _onBehalfOf
    ) external;
    function repay(address _asset, uint256 _amount, uint256 _rateMode, address _onBehalfOf) external;
    function setUserUseReserveAsCollateral(address _asset, bool _useAsCollateral) external;
    function getUserAccountData(address user) external view returns (
        uint256 totalCollateralETH,
        uint256 totalDebtETH,
        uint256 availableBorrowsETH,
        uint256 currentLiquidationThreshold,
        uint256 ltv,
        uint256 healthFactor
    );
}

interface AaveLendingPoolProviderInterface {
    function getLendingPool() external view returns (address);
    function getPriceOracle() external view returns (address);
}

// Aave Protocol Data Provider
interface AaveDataProviderInterface {
    function getReserveTokensAddresses(address _asset) external view returns (
        address aTokenAddress,
        address stableDebtTokenAddress,
        address variableDebtTokenAddress
    );
    function getUserReserveData(address _asset, address _user) external view returns (
        uint256 currentATokenBalance,
        uint256 currentStableDebt,
        uint256 currentVariableDebt,
        uint256 principalStableDebt,
        uint256 scaledVariableDebt,
        uint256 stableBorrowRate,
        uint256 liquidityRate,
        uint40 stableRateLastUpdated,
        bool usageAsCollateralEnabled
    );
    function getReserveConfigurationData(address asset) external view returns (
        uint256 decimals,
        uint256 ltv,
        uint256 liquidationThreshold,
        uint256 liquidationBonus,
        uint256 reserveFactor,
        bool usageAsCollateralEnabled,
        bool borrowingEnabled,
        bool stableBorrowRateEnabled,
        bool isActive,
        bool isFrozen
    );
    function getReserveData(address asset) external view returns (uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp);
}

interface AaveAddressProviderRegistryInterface {
    function getAddressesProvidersList() external view returns (address[] memory);
}

interface ATokenInterface {
    function scaledBalanceOf(address _user) external view returns (uint256);
    function isTransferAllowed(address _user, uint256 _amount) external view returns (bool);
    function balanceOf(address _user) external view returns(uint256);
    function transferFrom(address, address, uint) external returns (bool);
    function approve(address, uint256) external;
}

interface AaveOracleInterface {
    function getAssetPrice(address _asset) external view returns (uint256);
    function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
    function getSourceOfAsset(address _asset) external view returns(address);
    function getFallbackOracle() external view returns(address);
}

interface IndexInterface {
    function master() external view returns (address);
}

interface FlashloanInterface {
    function initiateFlashLoan(bytes memory data, uint ethAmt) external;
}

interface AavePriceOracle {
    function getAssetPrice(address _asset) external view returns(uint256);
    function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
    function getSourceOfAsset(address _asset) external view returns(uint256);
    function getFallbackOracle() external view returns(uint256);
}

interface ChainLinkInterface {
    function latestAnswer() external view returns (int256);
    function decimals() external view returns (uint256);
}

File 4 of 9 : math.sol
pragma solidity ^0.8.6;

import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract DSMath {
  uint constant WAD = 10 ** 18;
  uint constant RAY = 10 ** 27;

  function add(uint x, uint y) internal pure returns (uint z) {
    z = SafeMath.add(x, y);
  }

  function sub(uint x, uint y) internal virtual pure returns (uint z) {
    z = SafeMath.sub(x, y);
  }

  function mul(uint x, uint y) internal pure returns (uint z) {
    z = SafeMath.mul(x, y);
  }

  function div(uint x, uint y) internal pure returns (uint z) {
    z = SafeMath.div(x, y);
  }

  function wmul(uint x, uint y) internal pure returns (uint z) {
    z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD;
  }

  function wdiv(uint x, uint y) internal pure returns (uint z) {
    z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y;
  }

  function rdiv(uint x, uint y) internal pure returns (uint z) {
    z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y;
  }

  function rmul(uint x, uint y) internal pure returns (uint z) {
    z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY;
  }

  function toInt(uint x) internal pure returns (int y) {
    y = int(x);
    require(y >= 0, "int-overflow");
  }

  function toRad(uint wad) internal pure returns (uint rad) {
    rad = mul(wad, 10 ** 27);
  }

}

File 5 of 9 : variables.sol
pragma solidity ^0.8.6;

import {
    AaveLendingPoolProviderInterface,
    AaveDataProviderInterface,
    AaveOracleInterface,
    IndexInterface
} from "./interfaces.sol";

contract Variables {
    struct TokenInfo {
        address sourceToken;
        address targetToken;
        uint256 amount;
    }
    
    struct Position {
        TokenInfo[] supply;
        TokenInfo[] withdraw;
    }

    // Structs
    struct AaveDataRaw {
        address targetDsa;
        uint256[] supplyAmts;
        uint256[] variableBorrowAmts;
        uint256[] stableBorrowAmts;
        address[] supplyTokens;
        address[] borrowTokens;
    }

    struct AaveData {
        address targetDsa;
        uint256[] supplyAmts;
        uint256[] borrowAmts;
        address[] supplyTokens;
        address[] borrowTokens;
    }

    // Constant Addresses //

    /**
    * @dev Aave referal code
    */
    uint16 constant internal referralCode = 3228;
    address public constant nativeToken = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
    
    /**
     * @dev Aave Provider
     */
    AaveLendingPoolProviderInterface public immutable aaveLendingPoolAddressesProvider;

    /**
     * @dev Aave Data Provider
     */
    AaveDataProviderInterface public immutable aaveProtocolDataProvider;

    /**
     * @dev Aave Price Oracle
     */
    // AaveOracleInterface public aaveOracle = AaveOracleInterface(0xA50ba011c48153De246E5192C8f9258A2ba79Ca9);

    /**
     * @dev InstaIndex Address.
     */
    IndexInterface public immutable instaIndex;
    address public immutable wnativeToken;

    constructor (
        address _aaveLendingPoolAddressesProvider,
        address _aaveProtocolDataProvider,
        address _instaIndex,
        address _wnativeToken
    ) {
        aaveLendingPoolAddressesProvider = AaveLendingPoolProviderInterface(_aaveLendingPoolAddressesProvider);
        aaveProtocolDataProvider = AaveDataProviderInterface(_aaveProtocolDataProvider);
        instaIndex = IndexInterface(_instaIndex);
        wnativeToken = _wnativeToken;
    }
}

File 6 of 9 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

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

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

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

File 7 of 9 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

File 8 of 9 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

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

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_aaveLendingPoolAddressesProvider","type":"address"},{"internalType":"address","name":"_aaveProtocolDataProvider","type":"address"},{"internalType":"address","name":"_instaIndex","type":"address"},{"internalType":"address","name":"_wnativeToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"liquidity","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"safeRatioPercentage","type":"uint256"},{"internalType":"uint256","name":"userTotalBorrow","type":"uint256"}],"name":"_checkLiquidityRatio","outputs":[{"components":[{"internalType":"bool","name":"isOk","type":"bool"},{"internalType":"uint256","name":"ratio","type":"uint256"},{"internalType":"uint256","name":"maxRatio","type":"uint256"},{"internalType":"uint256","name":"maxLiquidationRatio","type":"uint256"},{"internalType":"uint256","name":"ltv","type":"uint256"},{"internalType":"uint256","name":"currentLiquidationThreshold","type":"uint256"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalBorrow","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"internalType":"struct Helpers.PositionData","name":"positionData","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"components":[{"components":[{"internalType":"address","name":"sourceToken","type":"address"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Variables.TokenInfo[]","name":"supply","type":"tuple[]"},{"components":[{"internalType":"address","name":"sourceToken","type":"address"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Variables.TokenInfo[]","name":"withdraw","type":"tuple[]"}],"internalType":"struct Variables.Position","name":"position","type":"tuple"},{"internalType":"uint256","name":"safeRatioPercentage","type":"uint256"},{"internalType":"bool","name":"isTarget","type":"bool"}],"name":"_checkRatio","outputs":[{"components":[{"internalType":"bool","name":"isOk","type":"bool"},{"internalType":"uint256","name":"ratio","type":"uint256"},{"internalType":"uint256","name":"maxRatio","type":"uint256"},{"internalType":"uint256","name":"maxLiquidationRatio","type":"uint256"},{"internalType":"uint256","name":"ltv","type":"uint256"},{"internalType":"uint256","name":"currentLiquidationThreshold","type":"uint256"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalBorrow","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"internalType":"struct Helpers.PositionData","name":"positionData","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aaveLendingPoolAddressesProvider","outputs":[{"internalType":"contract AaveLendingPoolProviderInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aaveProtocolDataProvider","outputs":[{"internalType":"contract AaveDataProviderInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"components":[{"components":[{"internalType":"address","name":"sourceToken","type":"address"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Variables.TokenInfo[]","name":"supply","type":"tuple[]"},{"components":[{"internalType":"address","name":"sourceToken","type":"address"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Variables.TokenInfo[]","name":"withdraw","type":"tuple[]"}],"internalType":"struct Variables.Position","name":"position","type":"tuple"},{"internalType":"uint256","name":"safeRatioPercentage","type":"uint256"},{"internalType":"bool","name":"isTarget","type":"bool"}],"name":"checkAavePosition","outputs":[{"components":[{"internalType":"bool","name":"isOk","type":"bool"},{"internalType":"uint256","name":"ratio","type":"uint256"},{"internalType":"uint256","name":"maxRatio","type":"uint256"},{"internalType":"uint256","name":"maxLiquidationRatio","type":"uint256"},{"internalType":"uint256","name":"ltv","type":"uint256"},{"internalType":"uint256","name":"currentLiquidationThreshold","type":"uint256"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalBorrow","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"internalType":"struct Helpers.PositionData","name":"p","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"components":[{"internalType":"address","name":"targetDsa","type":"address"},{"internalType":"uint256[]","name":"supplyAmts","type":"uint256[]"},{"internalType":"uint256[]","name":"borrowAmts","type":"uint256[]"},{"internalType":"address[]","name":"supplyTokens","type":"address[]"},{"internalType":"address[]","name":"borrowTokens","type":"address[]"}],"internalType":"struct Variables.AaveData","name":"data","type":"tuple"},{"internalType":"bool","name":"isTarget","type":"bool"}],"name":"checkBorrowToken","outputs":[{"internalType":"uint256","name":"totalBorrow","type":"uint256"},{"internalType":"bool","name":"isOk","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"liquidityAddress","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalBorrow","type":"uint256"},{"internalType":"uint256","name":"safeLiquidityRatioPercentage","type":"uint256"},{"internalType":"bool","name":"isTarget","type":"bool"}],"name":"checkLiquidity","outputs":[{"components":[{"internalType":"bool","name":"isOk","type":"bool"},{"internalType":"uint256","name":"ratio","type":"uint256"},{"internalType":"uint256","name":"maxRatio","type":"uint256"},{"internalType":"uint256","name":"maxLiquidationRatio","type":"uint256"},{"internalType":"uint256","name":"ltv","type":"uint256"},{"internalType":"uint256","name":"currentLiquidationThreshold","type":"uint256"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalBorrow","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"internalType":"struct Helpers.PositionData","name":"p","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"checkLiquidityToken","outputs":[{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalBorrow","type":"uint256"},{"internalType":"uint256","name":"totalMaxBorrow","type":"uint256"},{"internalType":"uint256","name":"totalMaxLiquidation","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"components":[{"internalType":"address","name":"targetDsa","type":"address"},{"internalType":"uint256[]","name":"supplyAmts","type":"uint256[]"},{"internalType":"uint256[]","name":"borrowAmts","type":"uint256[]"},{"internalType":"address[]","name":"supplyTokens","type":"address[]"},{"internalType":"address[]","name":"borrowTokens","type":"address[]"}],"internalType":"struct Variables.AaveData","name":"data","type":"tuple"},{"internalType":"bool","name":"isTarget","type":"bool"}],"name":"checkSupplyToken","outputs":[{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalMaxBorrow","type":"uint256"},{"internalType":"uint256","name":"totalMaxLiquidation","type":"uint256"},{"internalType":"bool","name":"isOk","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"getTokenInfos","outputs":[{"components":[{"internalType":"uint256","name":"decimals","type":"uint256"},{"internalType":"uint256","name":"ltv","type":"uint256"},{"internalType":"uint256","name":"tl","type":"uint256"},{"internalType":"bool","name":"enabledAsCollateral","type":"bool"},{"internalType":"bool","name":"borrowingEnabled","type":"bool"},{"internalType":"bool","name":"isActive","type":"bool"},{"internalType":"bool","name":"isFrozen","type":"bool"},{"internalType":"uint256","name":"availableLiquidity","type":"uint256"},{"internalType":"uint256","name":"totalOverallDebt","type":"uint256"}],"internalType":"struct Helpers.ReserveConfigData[]","name":"reserveConfigData","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"getTokensPrices","outputs":[{"internalType":"uint256[]","name":"tokenPricesInEth","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"instaIndex","outputs":[{"internalType":"contract IndexInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"safeRatioPercentage","type":"uint256"}],"name":"isPositionSafe","outputs":[{"internalType":"bool","name":"isOk","type":"bool"},{"internalType":"uint256","name":"userTl","type":"uint256"},{"internalType":"uint256","name":"userLtv","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nativeToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"sourceToken","type":"address"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Variables.TokenInfo[]","name":"supply","type":"tuple[]"},{"components":[{"internalType":"address","name":"sourceToken","type":"address"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Variables.TokenInfo[]","name":"withdraw","type":"tuple[]"}],"internalType":"struct Variables.Position","name":"position","type":"tuple"},{"internalType":"bool","name":"isTarget","type":"bool"}],"name":"sortData","outputs":[{"components":[{"internalType":"address","name":"targetDsa","type":"address"},{"internalType":"uint256[]","name":"supplyAmts","type":"uint256[]"},{"internalType":"uint256[]","name":"borrowAmts","type":"uint256[]"},{"internalType":"address[]","name":"supplyTokens","type":"address[]"},{"internalType":"address[]","name":"borrowTokens","type":"address[]"}],"internalType":"struct Variables.AaveData","name":"aaveData","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wnativeToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

6101006040523480156200001257600080fd5b50604051620025b3380380620025b3833981016040819052620000359162000082565b6001600160601b0319606094851b811660805292841b831660a05290831b821660c05290911b1660e052620000df565b80516001600160a01b03811681146200007d57600080fd5b919050565b600080600080608085870312156200009957600080fd5b620000a48562000065565b9350620000b46020860162000065565b9250620000c46040860162000065565b9150620000d46060860162000065565b905092959194509250565b60805160601c60a05160601c60c05160601c60e05160601c61244f62000164600039600081816102fc015281816108f90152610a3c015260006102c2015260008181610248015281816103f701528181610b5701528181610f760152818161114301526113aa015260008181610167015281816105ac0152610d59015261244f6000f3fe608060405234801561001057600080fd5b50600436106101005760003560e01c8063a41098bf11610097578063d4c40c0d11610066578063d4c40c0d1461033e578063da04d54a14610351578063e1758bd814610386578063eaf44ae2146103a157600080fd5b8063a41098bf146102bd578063acfbe3c9146102e4578063b729cbeb146102f7578063bb17e4441461031e57600080fd5b80634b07e4d7116100d35780634b07e4d7146101c15780635f9d4d2e14610243578063833826531461026a578063899149ef1461029d57600080fd5b80631673493114610105578063222641c014610132578063238f9b7a14610162578063493ebfec146101a1575b600080fd5b610118610113366004611b2d565b6103b4565b604080519283529015156020830152015b60405180910390f35b610145610140366004611ca5565b6105a4565b604080519315158452602084019290925290820152606001610129565b6101897f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610129565b6101b46101af366004611d9c565b6106ec565b604051610129919061210e565b6101d46101cf366004611aae565b610ad6565b60405161012991906000610120820190508251151582526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525092915050565b6101897f000000000000000000000000000000000000000000000000000000000000000081565b61027d610278366004611a00565b610b24565b604080519485526020850193909352918301526060820152608001610129565b6102b06102ab366004611cd1565b610d55565b60405161012991906120fb565b6101897f000000000000000000000000000000000000000000000000000000000000000081565b6101d46102f2366004611c3a565b610e6d565b6101897f000000000000000000000000000000000000000000000000000000000000000081565b61033161032c366004611cd1565b610ec1565b604051610129919061205b565b6101d461034c366004611a4f565b61127c565b61036461035f366004611b2d565b611365565b6040805194855260208501939093529183015215156060820152608001610129565b61018973eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b6101d46103af366004611c3a565b61157f565b60008060006103c68560800151610d55565b905060006103d78660800151610ec1565b90506001925060005b866080015151811015610599578561050f576000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166328dd2d018a60800151858151811061043a5761043a6123c7565b60200260200101518c6040518363ffffffff1660e01b81526004016104759291906001600160a01b0392831681529116602082015260400190565b6101206040518083038186803b15801561048e57600080fd5b505afa1580156104a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104c69190611f59565b5050505050509250925050600081836104df919061223b565b9050896040015184815181106104f7576104f76123c7565b602002602001015181101561050b57600096505b5050505b60006105776105588960400151848151811061052d5761052d6123c7565b6020026020010151858581518110610547576105476123c7565b602002602001015160000151611694565b85848151811061056a5761056a6123c7565b60200260200101516116bd565b9050610583818761223b565b955050808061059190612396565b9150506103e0565b505050935093915050565b6000806000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630261bf8b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561060357600080fd5b505afa158015610617573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063b91906119e3565b604051632fe4a15f60e21b81526001600160a01b03888116600483015291925060009183169063bf92857c9060240160c06040518083038186803b15801561068257600080fd5b505afa158015610696573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ba9190611e94565b91985096509350600092506106db9150670de0b6b3a76400009050886116f7565b905080821195505050509250925092565b6107276040518060a0016040528060006001600160a01b03168152602001606081526020016060815260200160608152602001606081525090565b825151602084015151816001600160401b03811115610748576107486123dd565b604051908082528060200260200182016040528015610771578160200160208202803683370190505b506020840152806001600160401b0381111561078f5761078f6123dd565b6040519080825280602002602001820160405280156107b8578160200160208202803683370190505b506040840152816001600160401b038111156107d6576107d66123dd565b6040519080825280602002602001820160405280156107ff578160200160208202803683370190505b506060840152806001600160401b0381111561081d5761081d6123dd565b604051908082528060200260200182016040528015610846578160200160208202803683370190505b50608084015260005b8281101561098a5760008660000151828151811061086f5761086f6123c7565b6020026020010151604001519050600086156108aa578751805184908110610899576108996123c7565b6020026020010151602001516108cb565b87518051849081106108be576108be6123c7565b6020026020010151600001515b90506001600160a01b03811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee146108f75780610919565b7f00000000000000000000000000000000000000000000000000000000000000005b90508086606001518481518110610932576109326123c7565b60200260200101906001600160a01b031690816001600160a01b0316815250508186602001518481518110610969576109696123c7565b6020026020010181815250505050808061098290612396565b91505061084f565b5060005b81811015610acd576000866020015182815181106109ae576109ae6123c7565b6020026020010151604001519050600086156109eb57876020015183815181106109da576109da6123c7565b602002602001015160200151610a0e565b87602001518381518110610a0157610a016123c7565b6020026020010151600001515b90506001600160a01b03811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14610a3a5780610a5c565b7f00000000000000000000000000000000000000000000000000000000000000005b90508086608001518481518110610a7557610a756123c7565b60200260200101906001600160a01b031690816001600160a01b0316815250508186604001518481518110610aac57610aac6123c7565b60200260200101818152505050508080610ac590612396565b91505061098e565b50505092915050565b610ade611756565b610ae887846105a4565b60a084015260808301521515808252610b0057610b1a565b610b1787878585610b11578761127c565b8861127c565b90505b9695505050505050565b6000806000806000610b3586610d55565b90506000610b4287610ec1565b905060005b8751811015610d495760008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166328dd2d018c8681518110610b9657610b966123c7565b60200260200101518e6040518363ffffffff1660e01b8152600401610bd19291906001600160a01b0392831681529116602082015260400190565b6101206040518083038186803b158015610bea57600080fd5b505afa158015610bfe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c229190611f59565b5050505050509250925092506000610c5b610c4985888881518110610547576105476123c7565b88878151811061056a5761056a6123c7565b90506000610c93610c81610c6f868661171a565b898981518110610547576105476123c7565b89888151811061056a5761056a6123c7565b9050610c9f828d61223b565b9b50610cab818c61223b565b9a50612710878781518110610cc257610cc26123c7565b60200260200101516040015183610cd99190612360565b610ce39190612253565b610ced908a61223b565b9850612710878781518110610d0457610d046123c7565b60200260200101516020015183610d1b9190612360565b610d259190612253565b610d2f908b61223b565b995050505050508080610d4190612396565b915050610b47565b50505092959194509250565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fca513a86040518163ffffffff1660e01b815260040160206040518083038186803b158015610db057600080fd5b505afa158015610dc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de891906119e3565b6001600160a01b0316639d23d9f2836040518263ffffffff1660e01b8152600401610e139190612048565b60006040518083038186803b158015610e2b57600080fd5b505afa158015610e3f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e679190810190611d05565b92915050565b610e75611756565b610e7f85846105a4565b60a084015260808301521515815281610e99578051610e9c565b60015b1515808252610eaa57610eb9565b610eb68585858561157f565b90505b949350505050565b8051606090806001600160401b03811115610ede57610ede6123dd565b604051908082528060200260200182016040528015610f6657816020015b610f5360405180610120016040528060008152602001600081526020016000815260200160001515815260200160001515815260200160001515815260200160001515815260200160008152602001600081525090565b815260200190600190039081610efc5790505b50915060005b81811015611275577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633e150141858381518110610fb557610fb56123c7565b60200260200101516040518263ffffffff1660e01b8152600401610fe891906001600160a01b0391909116815260200190565b6101406040518083038186803b15801561100157600080fd5b505afa158015611015573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110399190611ded565b8c51949650929450928b915089908110611055576110556123c7565b60200260200101516000018a8981518110611072576110726123c7565b60200260200101516020018b8a8151811061108f5761108f6123c7565b60200260200101516040018c8b815181106110ac576110ac6123c7565b60200260200101516060018d8c815181106110c9576110c96123c7565b60200260200101516080018e8d815181106110e6576110e66123c7565b602002602001015160a0018f8e81518110611103576111036123c7565b602090810291909101015196151560c090970196909652951515909452941515909352931515905292905291905252835160009081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906335ea6a759088908690811061117c5761117c6123c7565b60200260200101516040518263ffffffff1660e01b81526004016111af91906001600160a01b0391909116815260200190565b6101406040518083038186803b1580156111c857600080fd5b505afa1580156111dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112009190611ede565b50508c518d95508b94508410925061121d9150505761121d6123c7565b602090810291909101015160e001929092529250905061123d828261171a565b85848151811061124f5761124f6123c7565b60200260200101516101000181815250505050808061126d90612396565b915050610f6c565b5050919050565b611284611756565b6000806112918787610b24565b60e0870183905260c087019390935293509091506112af908561171a565b60e084015260c0830151156113245760c08301516112cf83612710612360565b6112d99190612253565b604084015260c08301516112ef82612710612360565b6112f99190612253565b606084015260c083015160e084015161131490612710612360565b61131e9190612253565b60208401525b60006113458460c00151611340670de0b6b3a764000089611726565b6116bd565b90506113518282611726565b60e085015110845250919695505050505050565b600080600080600061137a8760600151610d55565b9050600061138b8860600151610ec1565b90506001925060005b88606001515181101561157357876114af5760007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166328dd2d018b6060015184815181106113ed576113ed6123c7565b60200260200101518d6040518363ffffffff1660e01b81526004016114289291906001600160a01b0392831681529116602082015260400190565b6101206040518083038186803b15801561144157600080fd5b505afa158015611455573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114799190611f59565b5050505050505050905089602001518281518110611499576114996123c7565b60200260200101518110156114ad57600094505b505b60006114cd6105588b60200151848151811061052d5761052d6123c7565b90506114d9818961223b565b97506127108383815181106114f0576114f06123c7565b602002602001015160400151826115079190612360565b6115119190612253565b61151b908761223b565b9550612710838381518110611532576115326123c7565b602002602001015160200151826115499190612360565b6115539190612253565b61155d908861223b565b965050808061156b90612396565b915050611394565b50505093509350935093565b611587611756565b600061159385846106ec565b90506000806000806115a68a8689611365565b60c08a0193909352919550925090506115c08a86896103b4565b60e088019190915260c08701519093501561163b5760c08601516115e683612710612360565b6115f09190612253565b604087015260c086015161160682612710612360565b6116109190612253565b606087015260c086015160e087015161162b90612710612360565b6116359190612253565b60208701525b831580611646575082155b1561165a5750506000845250610eb9915050565b600061167282611340670de0b6b3a76400008c611726565b905061167e8282611726565b60e0880151108752505050505050949350505050565b60006116a182601261237f565b6116ac90600a6122b8565b6116b69084612360565b9392505050565b6000670de0b6b3a76400006116ed6116d58585611732565b6116e86002670de0b6b3a7640000612253565b61173e565b6116b69190612253565b6000816116ed61170f85670de0b6b3a7640000611732565b6116e8600286612253565b60006116b6838361173e565b60006116b6838361174a565b60006116b68284612360565b60006116b6828461223b565b60006116b6828461237f565b60405180610120016040528060001515815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b80356117af816123f3565b919050565b600082601f8301126117c557600080fd5b813560206117da6117d583612218565b6121e8565b80838252828201915082860187848660051b89010111156117fa57600080fd5b60005b85811015611822578135611810816123f3565b845292840192908401906001016117fd565b5090979650505050505050565b600082601f83011261184057600080fd5b813560206118506117d583612218565b8281528181019085830160608086028801850189101561186f57600080fd5b6000805b878110156118cb5782848c031215611889578182fd5b61189161219e565b843561189c816123f3565b8152848801356118ab816123f3565b818901526040858101359082015286529486019492820192600101611873565b50929998505050505050505050565b600082601f8301126118eb57600080fd5b813560206118fb6117d583612218565b80838252828201915082860187848660051b890101111561191b57600080fd5b60005b858110156118225781358452928401929084019060010161191e565b80356117af8161240b565b60006040828403121561195757600080fd5b604051604081016001600160401b03828210818311171561197a5761197a6123dd565b81604052829350843591508082111561199257600080fd5b61199e8683870161182f565b835260208501359150808211156119b457600080fd5b506119c18582860161182f565b6020830152505092915050565b805164ffffffffff811681146117af57600080fd5b6000602082840312156119f557600080fd5b81516116b6816123f3565b60008060408385031215611a1357600080fd5b8235611a1e816123f3565b915060208301356001600160401b03811115611a3957600080fd5b611a45858286016117b4565b9150509250929050565b60008060008060808587031215611a6557600080fd5b8435611a70816123f3565b935060208501356001600160401b03811115611a8b57600080fd5b611a97878288016117b4565b949794965050505060408301359260600135919050565b60008060008060008060c08789031215611ac757600080fd5b8635611ad2816123f3565b955060208701356001600160401b03811115611aed57600080fd5b611af989828a016117b4565b95505060408701359350606087013592506080870135915060a0870135611b1f8161240b565b809150509295509295509295565b600080600060608486031215611b4257600080fd5b8335611b4d816123f3565b925060208401356001600160401b0380821115611b6957600080fd5b9085019060a08288031215611b7d57600080fd5b611b856121c6565b611b8e836117a4565b8152602083013582811115611ba257600080fd5b611bae898286016118da565b602083015250604083013582811115611bc657600080fd5b611bd2898286016118da565b604083015250606083013582811115611bea57600080fd5b611bf6898286016117b4565b606083015250608083013582811115611c0e57600080fd5b611c1a898286016117b4565b6080830152509350611c319150506040850161193a565b90509250925092565b60008060008060808587031215611c5057600080fd5b8435611c5b816123f3565b935060208501356001600160401b03811115611c7657600080fd5b611c8287828801611945565b935050604085013591506060850135611c9a8161240b565b939692955090935050565b60008060408385031215611cb857600080fd5b8235611cc3816123f3565b946020939093013593505050565b600060208284031215611ce357600080fd5b81356001600160401b03811115611cf957600080fd5b610eb9848285016117b4565b60006020808385031215611d1857600080fd5b82516001600160401b03811115611d2e57600080fd5b8301601f81018513611d3f57600080fd5b8051611d4d6117d582612218565b80828252848201915084840188868560051b8701011115611d6d57600080fd5b600094505b83851015611d90578051835260019490940193918501918501611d72565b50979650505050505050565b60008060408385031215611daf57600080fd5b82356001600160401b03811115611dc557600080fd5b611dd185828601611945565b9250506020830135611de28161240b565b809150509250929050565b6000806000806000806000806000806101408b8d031215611e0d57600080fd5b8a51995060208b0151985060408b0151975060608b0151965060808b0151955060a08b0151611e3b8161240b565b60c08c0151909550611e4c8161240b565b60e08c0151909450611e5d8161240b565b6101008c0151909350611e6f8161240b565b6101208c0151909250611e818161240b565b809150509295989b9194979a5092959850565b60008060008060008060c08789031215611ead57600080fd5b865195506020870151945060408701519350606087015192506080870151915060a087015190509295509295509295565b6000806000806000806000806000806101408b8d031215611efe57600080fd5b8a51995060208b0151985060408b0151975060608b0151965060808b0151955060a08b0151945060c08b0151935060e08b015192506101008b01519150611f486101208c016119ce565b90509295989b9194979a5092959850565b60008060008060008060008060006101208a8c031215611f7857600080fd5b8951985060208a0151975060408a0151965060608a0151955060808a0151945060a08a0151935060c08a01519250611fb260e08b016119ce565b91506101008a0151611fc38161240b565b809150509295985092959850929598565b600081518084526020808501945080840160005b8381101561200d5781516001600160a01b031687529582019590820190600101611fe8565b509495945050505050565b600081518084526020808501945080840160005b8381101561200d5781518752958201959082019060010161202c565b6020815260006116b66020830184611fd4565b602080825282518282018190526000919060409081850190868401855b828110156120ee578151805185528681015187860152858101518686015260608082015115159086015260808082015115159086015260a08082015115159086015260c08082015115159086015260e0808201519086015261010090810151908501526101209093019290850190600101612078565b5091979650505050505050565b6020815260006116b66020830184612018565b602080825282516001600160a01b03168282015282015160a0604083015260009061213c60c0840182612018565b90506040840151601f198085840301606086015261215a8383612018565b925060608601519150808584030160808601526121778383611fd4565b925060808601519150808584030160a0860152506121958282611fd4565b95945050505050565b604051606081016001600160401b03811182821017156121c0576121c06123dd565b60405290565b60405160a081016001600160401b03811182821017156121c0576121c06123dd565b604051601f8201601f191681016001600160401b0381118282101715612210576122106123dd565b604052919050565b60006001600160401b03821115612231576122316123dd565b5060051b60200190565b6000821982111561224e5761224e6123b1565b500190565b60008261227057634e487b7160e01b600052601260045260246000fd5b500490565b600181815b808511156122b0578160001904821115612296576122966123b1565b808516156122a357918102915b93841c939080029061227a565b509250929050565b60006116b683836000826122ce57506001610e67565b816122db57506000610e67565b81600181146122f157600281146122fb57612317565b6001915050610e67565b60ff84111561230c5761230c6123b1565b50506001821b610e67565b5060208310610133831016604e8410600b841016171561233a575081810a610e67565b6123448383612275565b8060001904821115612358576123586123b1565b029392505050565b600081600019048311821515161561237a5761237a6123b1565b500290565b600082821015612391576123916123b1565b500390565b60006000198214156123aa576123aa6123b1565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461240857600080fd5b50565b801515811461240857600080fdfea2646970667358221220d1c7bba106ca90b995b7ee73259d185e827f67e53f1669f19591abed6082294b64736f6c63430008060033000000000000000000000000d05e3e715d945b59290df0ae8ef85c1bdb6847440000000000000000000000007551b5d2763519d4e37e8b81929d336de671d46d000000000000000000000000a9b99766e6c676cf1975c0d3166f96c0848ff5ad0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf1270

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

000000000000000000000000d05e3e715d945b59290df0ae8ef85c1bdb6847440000000000000000000000007551b5d2763519d4e37e8b81929d336de671d46d000000000000000000000000a9b99766e6c676cf1975c0d3166f96c0848ff5ad0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf1270

-----Decoded View---------------
Arg [0] : _aaveLendingPoolAddressesProvider (address): 0xd05e3e715d945b59290df0ae8ef85c1bdb684744
Arg [1] : _aaveProtocolDataProvider (address): 0x7551b5d2763519d4e37e8b81929d336de671d46d
Arg [2] : _instaIndex (address): 0xa9b99766e6c676cf1975c0d3166f96c0848ff5ad
Arg [3] : _wnativeToken (address): 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000d05e3e715d945b59290df0ae8ef85c1bdb684744
Arg [1] : 0000000000000000000000007551b5d2763519d4e37e8b81929d336de671d46d
Arg [2] : 000000000000000000000000a9b99766e6c676cf1975c0d3166f96c0848ff5ad
Arg [3] : 0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf1270


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