ETH Price: $3,623.22 (-0.09%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ConnectAaveV2Import

Compiler Version
v0.6.0+commit.26b70077

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2020-12-27
*/

pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;

interface MemoryInterface {
    function getUint(uint _id) external returns (uint _num);
    function setUint(uint _id, uint _val) external;
}

interface TokenInterface {
    function approve(address, uint256) external;
    function transfer(address, uint) external;
    function transferFrom(address, address, uint) external;
    function deposit() external payable;
    function withdraw(uint) external;
    function balanceOf(address) external view returns (uint);
    function decimals() external view returns (uint);
}

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

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

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

interface DSAInterface {
    function isAuth(address) external view returns(bool);
}

contract DSMath {

    function add(uint x, uint y) internal pure returns (uint z) {
        require((z = x + y) >= x, "math-not-safe");
    }

    function mul(uint x, uint y) internal pure returns (uint z) {
        require(y == 0 || (z = x * y) / y == x, "math-not-safe");
    }

    uint constant WAD = 10 ** 18;

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

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

}

contract Helpers is DSMath {
    /**
     * @dev Return ethereum address
     */
    function getEthAddr() internal pure returns (address) {
        return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address
    }

    /**
     * @dev Return Weth address
    */
    function getWethAddr() internal pure returns (address) {
        return 0xd0A1E359811322d97991E03f863a0C30C2cF029C; // Kovan WETH Address
    }

    /**
     * @dev Return Memory Variable Address
     */
    function getMemoryAddr() internal pure returns (address) {
        return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
    }

    /**
     * @dev Get Uint value from InstaMemory Contract.
    */
    function getUint(uint getId, uint val) internal returns (uint returnVal) {
        returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId);
    }

    /**
     * @dev Set Uint value in InstaMemory Contract.
    */
    function setUint(uint setId, uint val) internal {
        if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val);
    }

     /**
     * @dev Connector Details.
     */
    function connectorID() public pure returns(uint model, uint id) {
        (model, id) = (1, 69);
    }
}

contract AaveImportHelpers is Helpers {

    /**
     * @dev get Aave Lending Pool Provider
    */
    function getAaveProvider() internal pure returns (AaveLendingPoolProviderInterface) {
        return AaveLendingPoolProviderInterface(0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5); //mainnet
        // return AaveLendingPoolProviderInterface(0x652B2937Efd0B5beA1c8d54293FC1289672AFC6b); //kovan
    }

    /**
     * @dev get Aave Protocol Data Provider
    */
    function getAaveDataProvider() internal pure returns (AaveDataProviderInterface) {
        return AaveDataProviderInterface(0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d); //mainnet
        // return AaveDataProviderInterface(0x744C1aaA95232EeF8A9994C4E0b3a89659D9AB79); //kovan
    }

    /**
     * @dev get Referral Code V2
    */
    function getReferralCode() internal pure returns (uint16) {
        return 3228;
        // return 0;
    }

    function getIsColl(AaveDataProviderInterface aaveData, address token, address user) internal view returns (bool isCol) {
        (, , , , , , , , isCol) = aaveData.getUserReserveData(token, user);
    }

    function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal {
        if(isEth) token.deposit.value(amount)();
    }

    function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal {
       if(isEth) {
            token.approve(address(token), amount);
            token.withdraw(amount);
        }
    }
}

contract AaveResolver is AaveImportHelpers {
    function _TransferAtokens(
        uint _length,
        AaveInterface aave,
        AaveDataProviderInterface aaveData,
        ATokenInterface[] memory atokenContracts,
        uint[] memory amts,
        address[] memory tokens,
        address userAccount
    ) internal {
        for (uint i = 0; i < _length; i++) {
            if (amts[i] > 0) {
                require(atokenContracts[i].transferFrom(userAccount, address(this), amts[i]), "allowance?");
                
                if (!getIsColl(aaveData, tokens[i], address(this))) {
                    aave.setUserUseReserveAsCollateral(tokens[i], true);
                }
            }
        }
    }

    function _borrowOne(AaveInterface aave, address token, uint amt, uint rateMode) private {
        bool isEth = token == getEthAddr();
        address _token = isEth ? getWethAddr() : token;

        aave.borrow(_token, amt, rateMode, getReferralCode(), address(this));
    }

    function _paybackBehalfOne(AaveInterface aave, address token, uint amt, uint rateMode, address user) private {
        bool isEth = token == getEthAddr();
        address _token = isEth ? getWethAddr() : token;

        aave.repay(_token, amt, rateMode, user);
    }

    function _BorrowStable(
        uint _length,
        AaveInterface aave,
        address[] memory tokens,
        uint256[] memory amts
    ) internal {
        for (uint i = 0; i < _length; i++) {
            if (amts[i] > 0) {
                _borrowOne(aave, tokens[i], amts[i], 1);
            }
        }
    }

    function _BorrowVariable(
        uint _length,
        AaveInterface aave,
        address[] memory tokens,
        uint256[] memory amts
    ) internal {
        for (uint i = 0; i < _length; i++) {
            if (amts[i] > 0) {
                _borrowOne(aave, tokens[i], amts[i], 2);
            }
        }
    }

    function _PaybackStable(
        uint _length,
        AaveInterface aave,
        address[] memory tokens,
        uint256[] memory amts,
        address user
    ) internal {
        for (uint i = 0; i < _length; i++) {
            if (amts[i] > 0) {
                _paybackBehalfOne(aave, tokens[i], amts[i], 1, user);
            }
        }
    }

    function _PaybackVariable(
        uint _length,
        AaveInterface aave,
        address[] memory tokens,
        uint256[] memory amts,
        address user
    ) internal {
        for (uint i = 0; i < _length; i++) {
            if (amts[i] > 0) {
                _paybackBehalfOne(aave, tokens[i], amts[i], 2, user);
            }
        }
    }
}

contract AaveImportResolver is AaveResolver {

    struct AaveData {
        address[] tokens;
        address[] atokens;
        uint[] stableBorrowAmts;
        uint[] variableBorrowAmts;
        uint[] totalBorrowAmts;
        uint[] atokensBal;
        ATokenInterface[] atokenContracts;
    }

    function importAave(address userAccount, address[] calldata tokens, bool converStable) external payable {
        require(DSAInterface(address(this)).isAuth(userAccount), "user-account-not-auth");

        uint _length = tokens.length;
        require(_length > 0, "0-tokens-not-allowed");

        AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool());
        AaveDataProviderInterface aaveData = getAaveDataProvider();

        AaveData memory _aaveData = AaveData({
            tokens: tokens,
            atokens: new address[](_length),
            stableBorrowAmts: new uint[](_length),
            variableBorrowAmts: new uint[](_length),
            totalBorrowAmts: new uint[](_length),
            atokensBal: new uint[](_length),
            atokenContracts: new ATokenInterface[](_length)
        });

        for (uint i = 0; i < _length; i++) {
            (_aaveData.atokens[i], ,) = aaveData.getReserveTokensAddresses(tokens[i]);
            (
                _aaveData.atokensBal[i],
                _aaveData.stableBorrowAmts[i],
                _aaveData.variableBorrowAmts[i],
                ,,,,,
            ) = aaveData.getUserReserveData(userAccount, tokens[i]);
            _aaveData.totalBorrowAmts[i] = _aaveData.stableBorrowAmts[i] + _aaveData.variableBorrowAmts[i];

            bool isEth = tokens[i] == getEthAddr();
            address _token = isEth ? getWethAddr() : tokens[i];
            _aaveData.atokenContracts[i] = ATokenInterface(_token);
            TokenInterface(_token).approve(address(aave), _aaveData.totalBorrowAmts[i]);
        }

        if (converStable) {
            _BorrowVariable(_length, aave, _aaveData.tokens, _aaveData.totalBorrowAmts);
        } else {
            _BorrowStable(_length, aave, _aaveData.tokens, _aaveData.stableBorrowAmts);
            _BorrowVariable(_length, aave, _aaveData.tokens, _aaveData.variableBorrowAmts);
        }
        _PaybackStable(_length, aave, _aaveData.tokens, _aaveData.stableBorrowAmts, userAccount);
        _PaybackVariable(_length, aave, _aaveData.tokens, _aaveData.variableBorrowAmts, userAccount);
        _TransferAtokens(_length, aave, aaveData, _aaveData.atokenContracts, _aaveData.atokensBal, _aaveData.tokens, userAccount);
    }
}


contract ConnectAaveV2Import is AaveResolver {
    string public name = "AaveV2-Import-v1.0";
}

Contract Security Audit

Contract ABI

[{"inputs":[],"name":"connectorID","outputs":[{"internalType":"uint256","name":"model","type":"uint256"},{"internalType":"uint256","name":"id","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]

60806040526040518060400160405280601281526020017f4161766556322d496d706f72742d76312e3000000000000000000000000000008152506000908051906020019061004f929190610062565b5034801561005c57600080fd5b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610262806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806306fdde031461003b578063eb15f78114610059575b600080fd5b610043610078565b6040516100509190610177565b60405180910390f35b610061610116565b60405161006f929190610199565b60405180910390f35b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561010e5780601f106100e35761010080835404028352916020019161010e565b820191906000526020600020905b8154815290600101906020018083116100f157829003601f168201915b505050505081565b6000806001604581915080905080925081935050509091565b600061013a826101c2565b61014481856101cd565b93506101548185602086016101e8565b61015d8161021b565b840191505092915050565b610171816101de565b82525050565b60006020820190508181036000830152610191818461012f565b905092915050565b60006040820190506101ae6000830185610168565b6101bb6020830184610168565b9392505050565b600081519050919050565b600082825260208201905092915050565b6000819050919050565b60005b838110156102065780820151818401526020810190506101eb565b83811115610215576000848401525b50505050565b6000601f19601f830116905091905056fea26469706673582212204afe74c035aafbeafe6df2999db697b85e89a612a768c2cf7e60cd1926015ae764736f6c63430006000033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100365760003560e01c806306fdde031461003b578063eb15f78114610059575b600080fd5b610043610078565b6040516100509190610177565b60405180910390f35b610061610116565b60405161006f929190610199565b60405180910390f35b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561010e5780601f106100e35761010080835404028352916020019161010e565b820191906000526020600020905b8154815290600101906020018083116100f157829003601f168201915b505050505081565b6000806001604581915080905080925081935050509091565b600061013a826101c2565b61014481856101cd565b93506101548185602086016101e8565b61015d8161021b565b840191505092915050565b610171816101de565b82525050565b60006020820190508181036000830152610191818461012f565b905092915050565b60006040820190506101ae6000830185610168565b6101bb6020830184610168565b9392505050565b600081519050919050565b600082825260208201905092915050565b6000819050919050565b60005b838110156102065780820151818401526020810190506101eb565b83811115610215576000848401525b50505050565b6000601f19601f830116905091905056fea26469706673582212204afe74c035aafbeafe6df2999db697b85e89a612a768c2cf7e60cd1926015ae764736f6c63430006000033

Deployed Bytecode Sourcemap

12020:97:0:-:0;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;12020:97:0;;;;;;;;;;;;;;;;;;;;;;;;12072:41;;;:::i;:::-;;;;;;;;;;;;;;;;5037:104;;;:::i;:::-;;;;;;;;;;;;;;;;;12072:41;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;5037:104::-;5080:10;5092:7;5127:1;5130:2;5112:21;;;;;;;;;;;;;;5037:104;;:::o;5:339:-1:-;;113:35;142:5;113:35;;;160:71;224:6;219:3;160:71;;;153:78;;236:52;281:6;276:3;269:4;262:5;258:16;236:52;;;309:29;331:6;309:29;;;304:3;300:39;293:46;;93:251;;;;;;351:113;434:24;452:5;434:24;;;429:3;422:37;416:48;;;471:293;;605:2;594:9;590:18;582:26;;655:9;649:4;645:20;641:1;630:9;626:17;619:47;680:74;749:4;740:6;680:74;;;672:82;;576:188;;;;;771:324;;917:2;906:9;902:18;894:26;;931:71;999:1;988:9;984:17;975:6;931:71;;;1013:72;1081:2;1070:9;1066:18;1057:6;1013:72;;;888:207;;;;;;1102:118;;1192:5;1186:12;1176:22;;1157:63;;;;1228:163;;1343:6;1338:3;1331:19;1380:4;1375:3;1371:14;1356:29;;1324:67;;;;;1399:72;;1461:5;1450:16;;1444:27;;;;1479:268;1544:1;1551:101;1565:6;1562:1;1559:13;1551:101;;;1641:1;1636:3;1632:11;1626:18;1622:1;1617:3;1613:11;1606:39;1587:2;1584:1;1580:10;1575:15;;1551:101;;;1667:6;1664:1;1661:13;1658:2;;;1732:1;1723:6;1718:3;1714:16;1707:27;1658:2;1528:219;;;;;1755:97;;1843:2;1839:7;1834:2;1827:5;1823:14;1819:28;1809:38;;1803:49;;;

Swarm Source

ipfs://4afe74c035aafbeafe6df2999db697b85e89a612a768c2cf7e60cd1926015ae7

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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.