POL Price: $0.439536 (-3.84%)
 

Overview

POL Balance

Polygon PoS Chain LogoPolygon PoS Chain LogoPolygon PoS Chain Logo0 POL

POL Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AaveV2DepositBridge

Compiler Version
v0.8.6+commit.11564f7e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Audited
File 1 of 6 : AaveV2DepositBridge.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.6;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./interfaces/ILendingPool.sol";
import "./interfaces/IAaveIncentivesController.sol";
import "../../interfaces/IAaveV2Deposit.sol";

/**
 * @title AaveV2DepositBridge
 * @author DeFi Basket
 *
 * @notice Deposits, withdraws and harvest rewards from Aave's LendingPool contract in Polygon.
 *
 * @dev This contract has 2 main functions:
 *
 * 1. Deposit in Aave's LendingPool (example: DAI -> amDAI)
 * 2. Withdraw from Aave's LendingPool (example: amDAI -> DAI)
 *
 * Notice that we haven't implemented any kind of borrowing mechanisms, mostly because that would be nice to have
 * control mechanics to go along with it.
 *
 */

contract AaveV2DepositBridge is IAaveV2Deposit {

    address constant aaveLendingPoolAddress = 0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf;
    address constant incentivesControllerAddress = 0x357D51124f59836DeD84c8a1730D72B749d8BC23;

    /**
      * @notice Deposits into the Aave protocol.
      *
      * @dev Wraps the Aave deposit and generate the necessary events to communicate with DeFi Basket's UI and back-end.
      *
      * @param assetIn Address of the asset to be deposited into the Aave protocol
      * @param percentageIn Percentage of the balance of the asset that will be deposited
      */
    function deposit(address assetIn, uint256 percentageIn) external override {
        ILendingPool _aaveLendingPool = ILendingPool(aaveLendingPoolAddress);

        uint256 amount = IERC20(assetIn).balanceOf(address(this)) * percentageIn / 100000;

        // Approve 0 first as a few ERC20 tokens are requiring this pattern.
        IERC20(assetIn).approve(aaveLendingPoolAddress, 0);
        IERC20(assetIn).approve(aaveLendingPoolAddress, amount);

        _aaveLendingPool.deposit(assetIn, amount, address(this), 0);

        address assetOut = _aaveLendingPool.getReserveData(assetIn).aTokenAddress;

        emit DEFIBASKET_AAVEV2_DEPOSIT(assetOut, amount);
    }

    /**
      * @notice Withdraws from the Aave protocol.
      *
      * @dev Wraps the Aave withdrawal and generates the necessary events to communicate with DeFi Basket's UI and back-end.
      * To perform a harvest invoke withdraw with percentageOut set to 0.
      *
      * @param assetOut Address of the asset to be withdrawn from the Aave protocol
      * @param percentageOut Percentage of the balance of the asset that will be withdrawn
      */
    function withdraw(address assetOut, uint256 percentageOut) external override {
        IAaveIncentivesController distributor = IAaveIncentivesController(incentivesControllerAddress);
        ILendingPool _aaveLendingPool = ILendingPool(aaveLendingPoolAddress);

        address assetIn = _aaveLendingPool.getReserveData(assetOut).aTokenAddress;
        uint256 amount = 0;

        if (percentageOut > 0) {
            amount = IERC20(assetIn).balanceOf(address(this)) * percentageOut / 100000;
            _aaveLendingPool.withdraw(assetOut, amount, address(this));
        }

        address[] memory assets = new address[](1);
        assets[0] = assetIn;

        uint256 amountToClaim = distributor.getRewardsBalance(assets, address(this));
        uint256 claimedReward = distributor.claimRewards(assets, amountToClaim, address(this));
        address claimedAsset = distributor.REWARD_TOKEN();

        emit DEFIBASKET_AAVEV2_WITHDRAW(assetIn, amount, claimedAsset, claimedReward);
    }
}

File 2 of 6 : 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 3 of 6 : ILendingPool.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.6;

import {DataTypes} from '../libraries/DataTypes.sol';

interface ILendingPool {
    function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external;

    function withdraw(address asset, uint256 amount, address to) external returns (uint256);

    function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);
}

File 4 of 6 : IAaveIncentivesController.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.6;

interface IAaveIncentivesController {
    function getRewardsBalance(address[] calldata assets, address user) external view returns (uint256);

    function claimRewards(
        address[] calldata assets,
        uint256 amount,
        address to
    ) external returns (uint256);

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

File 5 of 6 : IAaveV2Deposit.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.6;

interface IAaveV2Deposit {
    event DEFIBASKET_AAVEV2_DEPOSIT (
        address assetOut,
        uint256 amount
    );

    event DEFIBASKET_AAVEV2_WITHDRAW (
        address assetIn,
        uint256 amount,
        address rewardAsset,
        uint256 rewardAmount
    );

    function deposit(address assetIn, uint256 percentageIn) external;

    function withdraw(address assetOut, uint256 percentageOut) external;
}

File 6 of 6 : DataTypes.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.6;

library DataTypes {
    // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties.
    struct ReserveData {
        //stores the reserve configuration
        ReserveConfigurationMap configuration;
        //the liquidity index. Expressed in ray
        uint128 liquidityIndex;
        //variable borrow index. Expressed in ray
        uint128 variableBorrowIndex;
        //the current supply rate. Expressed in ray
        uint128 currentLiquidityRate;
        //the current variable borrow rate. Expressed in ray
        uint128 currentVariableBorrowRate;
        //the current stable borrow rate. Expressed in ray
        uint128 currentStableBorrowRate;
        uint40 lastUpdateTimestamp;
        //tokens addresses
        address aTokenAddress;
        address stableDebtTokenAddress;
        address variableDebtTokenAddress;
        //address of the interest rate strategy
        address interestRateStrategyAddress;
        //the id of the reserve. Represents the position in the list of the active reserves
        uint8 id;
    }

    struct ReserveConfigurationMap {
        //bit 0-15: LTV
        //bit 16-31: Liq. threshold
        //bit 32-47: Liq. bonus
        //bit 48-55: Decimals
        //bit 56: Reserve is active
        //bit 57: reserve is frozen
        //bit 58: borrowing is enabled
        //bit 59: stable rate borrowing enabled
        //bit 60-63: reserved
        //bit 64-79: reserve factor
        uint256 data;
    }

    struct UserConfigurationMap {
        uint256 data;
    }

    enum InterestRateMode {NONE, STABLE, VARIABLE}
}

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

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"assetOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DEFIBASKET_AAVEV2_DEPOSIT","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"assetIn","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"rewardAsset","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"name":"DEFIBASKET_AAVEV2_WITHDRAW","type":"event"},{"inputs":[{"internalType":"address","name":"assetIn","type":"address"},{"internalType":"uint256","name":"percentageIn","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint256","name":"percentageOut","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50610b17806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806347e7ef241461003b578063f3fef3a314610050575b600080fd5b61004e610049366004610837565b610063565b005b61004e61005e366004610837565b610377565b6040516370a0823160e01b8152306004820152738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf90600090620186a09084906001600160a01b038716906370a082319060240160206040518083038186803b1580156100c257600080fd5b505afa1580156100d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100fa9190610972565b6101049190610a86565b61010e9190610a64565b60405163095ea7b360e01b8152738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf6004820152600060248201529091506001600160a01b0385169063095ea7b390604401602060405180830381600087803b15801561016d57600080fd5b505af1158015610181573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101a59190610863565b5060405163095ea7b360e01b8152738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf6004820152602481018290526001600160a01b0385169063095ea7b390604401602060405180830381600087803b15801561020257600080fd5b505af1158015610216573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061023a9190610863565b5060405163e8eda9df60e01b81526001600160a01b038581166004830152602482018390523060448301526000606483015283169063e8eda9df90608401600060405180830381600087803b15801561029257600080fd5b505af11580156102a6573d6000803e3d6000fd5b50506040516335ea6a7560e01b81526001600160a01b03878116600483015260009350851691506335ea6a75906024016101806040518083038186803b1580156102ef57600080fd5b505afa158015610303573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103279190610885565b60e00151604080516001600160a01b0383168152602081018590529192507fc3d4f43b9c681a913d26fd72f769c90974df25af68cc11234fb2f89be84e1e4e910160405180910390a15050505050565b6040516335ea6a7560e01b81526001600160a01b038316600482015273357d51124f59836ded84c8a1730d72b749d8bc2390738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf9060009082906335ea6a75906024016101806040518083038186803b1580156103e657600080fd5b505afa1580156103fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061041e9190610885565b60e0015190506000841561054c576040516370a0823160e01b8152306004820152620186a09086906001600160a01b038516906370a082319060240160206040518083038186803b15801561047257600080fd5b505afa158015610486573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104aa9190610972565b6104b49190610a86565b6104be9190610a64565b604051631a4ca37b60e21b81526001600160a01b03888116600483015260248201839052306044830152919250908416906369328dec90606401602060405180830381600087803b15801561051257600080fd5b505af1158015610526573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061054a9190610972565b505b60408051600180825281830190925260009160208083019080368337019050509050828160008151811061058257610582610ab3565b6001600160a01b0392831660209182029290920101526040516345accf9360e11b8152600091871690638b599f26906105c190859030906004016109cf565b60206040518083038186803b1580156105d957600080fd5b505afa1580156105ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106119190610972565b90506000866001600160a01b0316633111e7b38484306040518463ffffffff1660e01b8152600401610645939291906109f9565b602060405180830381600087803b15801561065f57600080fd5b505af1158015610673573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106979190610972565b90506000876001600160a01b03166399248ea76040518163ffffffff1660e01b815260040160206040518083038186803b1580156106d457600080fd5b505afa1580156106e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061070c9190610813565b604080516001600160a01b038981168252602082018990528316818301526060810185905290519192507ff50b60b313187102f7986d260327872cbcf7c18def9179e9bb8f52a873abc8e6919081900360800190a150505050505050505050565b805161077881610ac9565b919050565b60006020828403121561078f57600080fd5b6040516020810181811067ffffffffffffffff821117156107c057634e487b7160e01b600052604160045260246000fd5b6040529151825250919050565b80516fffffffffffffffffffffffffffffffff8116811461077857600080fd5b805164ffffffffff8116811461077857600080fd5b805160ff8116811461077857600080fd5b60006020828403121561082557600080fd5b815161083081610ac9565b9392505050565b6000806040838503121561084a57600080fd5b823561085581610ac9565b946020939093013593505050565b60006020828403121561087557600080fd5b8151801515811461083057600080fd5b6000610180828403121561089857600080fd5b6108a0610a2c565b6108aa848461077d565b81526108b8602084016107cd565b60208201526108c9604084016107cd565b60408201526108da606084016107cd565b60608201526108eb608084016107cd565b60808201526108fc60a084016107cd565b60a082015261090d60c084016107ed565b60c082015261091e60e0840161076d565b60e082015261010061093181850161076d565b9082015261012061094384820161076d565b9082015261014061095584820161076d565b90820152610160610967848201610802565b908201529392505050565b60006020828403121561098457600080fd5b5051919050565b600081518084526020808501945080840160005b838110156109c45781516001600160a01b03168752958201959082019060010161099f565b509495945050505050565b6040815260006109e2604083018561098b565b905060018060a01b03831660208301529392505050565b606081526000610a0c606083018661098b565b6020830194909452506001600160a01b0391909116604090910152919050565b604051610180810167ffffffffffffffff81118282101715610a5e57634e487b7160e01b600052604160045260246000fd5b60405290565b600082610a8157634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615610aae57634e487b7160e01b600052601160045260246000fd5b500290565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0381168114610ade57600080fd5b5056fea2646970667358221220b85d8036cfaf1dd73ff5dabdbbdda0b8d350d0b6dd9e874ccfe0f436a2a213a164736f6c63430008060033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100365760003560e01c806347e7ef241461003b578063f3fef3a314610050575b600080fd5b61004e610049366004610837565b610063565b005b61004e61005e366004610837565b610377565b6040516370a0823160e01b8152306004820152738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf90600090620186a09084906001600160a01b038716906370a082319060240160206040518083038186803b1580156100c257600080fd5b505afa1580156100d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100fa9190610972565b6101049190610a86565b61010e9190610a64565b60405163095ea7b360e01b8152738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf6004820152600060248201529091506001600160a01b0385169063095ea7b390604401602060405180830381600087803b15801561016d57600080fd5b505af1158015610181573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101a59190610863565b5060405163095ea7b360e01b8152738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf6004820152602481018290526001600160a01b0385169063095ea7b390604401602060405180830381600087803b15801561020257600080fd5b505af1158015610216573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061023a9190610863565b5060405163e8eda9df60e01b81526001600160a01b038581166004830152602482018390523060448301526000606483015283169063e8eda9df90608401600060405180830381600087803b15801561029257600080fd5b505af11580156102a6573d6000803e3d6000fd5b50506040516335ea6a7560e01b81526001600160a01b03878116600483015260009350851691506335ea6a75906024016101806040518083038186803b1580156102ef57600080fd5b505afa158015610303573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103279190610885565b60e00151604080516001600160a01b0383168152602081018590529192507fc3d4f43b9c681a913d26fd72f769c90974df25af68cc11234fb2f89be84e1e4e910160405180910390a15050505050565b6040516335ea6a7560e01b81526001600160a01b038316600482015273357d51124f59836ded84c8a1730d72b749d8bc2390738dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf9060009082906335ea6a75906024016101806040518083038186803b1580156103e657600080fd5b505afa1580156103fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061041e9190610885565b60e0015190506000841561054c576040516370a0823160e01b8152306004820152620186a09086906001600160a01b038516906370a082319060240160206040518083038186803b15801561047257600080fd5b505afa158015610486573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104aa9190610972565b6104b49190610a86565b6104be9190610a64565b604051631a4ca37b60e21b81526001600160a01b03888116600483015260248201839052306044830152919250908416906369328dec90606401602060405180830381600087803b15801561051257600080fd5b505af1158015610526573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061054a9190610972565b505b60408051600180825281830190925260009160208083019080368337019050509050828160008151811061058257610582610ab3565b6001600160a01b0392831660209182029290920101526040516345accf9360e11b8152600091871690638b599f26906105c190859030906004016109cf565b60206040518083038186803b1580156105d957600080fd5b505afa1580156105ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106119190610972565b90506000866001600160a01b0316633111e7b38484306040518463ffffffff1660e01b8152600401610645939291906109f9565b602060405180830381600087803b15801561065f57600080fd5b505af1158015610673573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106979190610972565b90506000876001600160a01b03166399248ea76040518163ffffffff1660e01b815260040160206040518083038186803b1580156106d457600080fd5b505afa1580156106e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061070c9190610813565b604080516001600160a01b038981168252602082018990528316818301526060810185905290519192507ff50b60b313187102f7986d260327872cbcf7c18def9179e9bb8f52a873abc8e6919081900360800190a150505050505050505050565b805161077881610ac9565b919050565b60006020828403121561078f57600080fd5b6040516020810181811067ffffffffffffffff821117156107c057634e487b7160e01b600052604160045260246000fd5b6040529151825250919050565b80516fffffffffffffffffffffffffffffffff8116811461077857600080fd5b805164ffffffffff8116811461077857600080fd5b805160ff8116811461077857600080fd5b60006020828403121561082557600080fd5b815161083081610ac9565b9392505050565b6000806040838503121561084a57600080fd5b823561085581610ac9565b946020939093013593505050565b60006020828403121561087557600080fd5b8151801515811461083057600080fd5b6000610180828403121561089857600080fd5b6108a0610a2c565b6108aa848461077d565b81526108b8602084016107cd565b60208201526108c9604084016107cd565b60408201526108da606084016107cd565b60608201526108eb608084016107cd565b60808201526108fc60a084016107cd565b60a082015261090d60c084016107ed565b60c082015261091e60e0840161076d565b60e082015261010061093181850161076d565b9082015261012061094384820161076d565b9082015261014061095584820161076d565b90820152610160610967848201610802565b908201529392505050565b60006020828403121561098457600080fd5b5051919050565b600081518084526020808501945080840160005b838110156109c45781516001600160a01b03168752958201959082019060010161099f565b509495945050505050565b6040815260006109e2604083018561098b565b905060018060a01b03831660208301529392505050565b606081526000610a0c606083018661098b565b6020830194909452506001600160a01b0391909116604090910152919050565b604051610180810167ffffffffffffffff81118282101715610a5e57634e487b7160e01b600052604160045260246000fd5b60405290565b600082610a8157634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615610aae57634e487b7160e01b600052601160045260246000fd5b500290565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0381168114610ade57600080fd5b5056fea2646970667358221220b85d8036cfaf1dd73ff5dabdbbdda0b8d350d0b6dd9e874ccfe0f436a2a213a164736f6c63430008060033

Block Transaction Gas Used Reward
view all blocks produced

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

OVERVIEW

DeFi Basket's auxiliar contract for communication with AaveV2

Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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.