POL Price: $0.620546 (-0.60%)
 

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:
AutofarmDepositBridge

Compiler Version
v0.8.6+commit.11564f7e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 4 : AutofarmDepositBridge.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.6;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./interfaces/IAutofarmV2_CrossChain.sol";
import "../../interfaces/IAutofarmDeposit.sol";

/**
 * @title AutofarmDepositBridge
 * @author DeFi Basket
 *
 * @notice Deposits, withdraws and harvest rewards from AutofarmV2_CrossChain contract in Polygon.
 *
 * @dev This contract has 2 main functions:
 *
 * 1. Deposit in AutofarmV2_CrossChain (example: QUICK/ETH -> autofarm doesn't return a deposit token)
 * 2. Withdraw from AutofarmV2_CrossChain
 *
 */

contract AutofarmDepositBridge is IAutofarmDeposit {
    // Hardcoded to make less variables needed for the user to check (UI will help explain/debug it)
    address constant autofarmAddress = 0x89d065572136814230A55DdEeDDEC9DF34EB0B76;
    address constant wMaticAddress = 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270;
    address constant pAutoAddress = 0x7f426F6Dc648e50464a0392E60E1BB465a67E9cf;

    /**
      * @notice Deposits into the Autofarm protocol.
      *
      * @dev Wraps the Autofarm deposit and generate the necessary events to communicate with DeFi Basket's UI and back-end.
      *
      * @param percentageIn Percentage of the balance of the asset that will be deposited
      */
    function deposit(uint256 poolId, uint256 percentageIn) external override {
        IAutofarmV2_CrossChain autofarm = IAutofarmV2_CrossChain(autofarmAddress);
        (IERC20 assetIn, , , , address vaultAddress) = autofarm.poolInfo(poolId);

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

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

        autofarm.deposit(poolId, amountIn);

        emit DEFIBASKET_AUTOFARM_DEPOSIT(vaultAddress, address(assetIn), amountIn);
    }

    /**
      * @notice Withdraws from the Autofarm protocol.
      *
      * @dev Wraps the Autofarm withdraw and generate the necessary events to communicate with DeFi Basket's UI and
      * back-end. A harvest is withdraw where percentageOut == 0.
      *
      * @param poolId Autofarm pool id
      * @param percentageOut Percentage of the balance of the asset that will be withdrawn
      */
    function withdraw(uint256 poolId, uint256 percentageOut) external override {
        IAutofarmV2_CrossChain autofarm = IAutofarmV2_CrossChain(autofarmAddress);
        (IERC20 assetOut, , , , address vaultAddress) = autofarm.poolInfo(poolId);

        uint256 wMaticBalance = IERC20(wMaticAddress).balanceOf(address(this));
        uint256 pAutoBalance = IERC20(pAutoAddress).balanceOf(address(this));

        uint256 amountOut = autofarm.stakedWantTokens(poolId, address(this)) * percentageOut / 100000;
        autofarm.withdraw(poolId, amountOut);

        uint256 wMaticReward = IERC20(wMaticAddress).balanceOf(address(this)) - wMaticBalance;
        uint256 pAutoReward = IERC20(pAutoAddress).balanceOf(address(this)) - pAutoBalance;

        emit DEFIBASKET_AUTOFARM_WITHDRAW(vaultAddress, address(assetOut), amountOut, wMaticReward, pAutoReward);
    }
}

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

pragma solidity ^0.8.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IAutofarmV2_CrossChain {
    struct PoolInfo {
        IERC20 want; // Address of the want token.
        uint256 allocPoint; // How many allocation points assigned to this pool. AUTO to distribute per block.
        uint256 lastRewardBlock; // Last block number that AUTO distribution occurs.
        uint256 accAUTOPerShare; // Accumulated AUTO per share, times 1e12. See below.
        address strat; // Strategy address that will auto compound want tokens
    }

    function poolInfo(uint i) external returns (IERC20, uint256, uint256, uint256, address);

    function deposit(uint256 _pid, uint256 _wantAmt) external;

    function withdraw(uint256 _pid, uint256 _wantAmt) external;

    function stakedWantTokens(uint256 _pid, address _user) external view returns (uint256);

    function poolLength() external view returns (uint256);
}

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

pragma solidity ^0.8.6;

interface IAutofarmDeposit {
    event DEFIBASKET_AUTOFARM_DEPOSIT (
        address vaultAddress,
        address assetIn,
        uint256 amount
    );

    event DEFIBASKET_AUTOFARM_WITHDRAW (
        address vaultAddress,
        address assetOut,
        uint256 amount,
        uint256 wMaticReward,
        uint256 pAutoReward
    );

    function deposit(uint256 percentageIn, uint256 poolId) external;

    function withdraw(uint256 percentageOut, uint256 poolId) external;
}

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":"vaultAddress","type":"address"},{"indexed":false,"internalType":"address","name":"assetIn","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DEFIBASKET_AUTOFARM_DEPOSIT","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"vaultAddress","type":"address"},{"indexed":false,"internalType":"address","name":"assetOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wMaticReward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pAutoReward","type":"uint256"}],"name":"DEFIBASKET_AUTOFARM_WITHDRAW","type":"event"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"percentageIn","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"percentageOut","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50610918806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063441a3e701461003b578063e2bbb15814610050575b600080fd5b61004e61004936600461083a565b610063565b005b61004e61005e36600461083a565b610495565b604051631526fe2760e01b8152600481018390527389d065572136814230a55ddeeddec9df34eb0b769060009081908390631526fe279060240160a060405180830381600087803b1580156100b757600080fd5b505af11580156100cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100ef91906107c9565b6040516370a0823160e01b81523060048201529496509450600093730d500b1d8e8ef31e21c99d1db9a6444d3adf127093506370a082319250602401905060206040518083038186803b15801561014557600080fd5b505afa158015610159573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017d9190610821565b6040516370a0823160e01b8152306004820152909150600090737f426f6dc648e50464a0392e60e1bb465a67e9cf906370a082319060240160206040518083038186803b1580156101cd57600080fd5b505afa1580156101e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102059190610821565b604051631ee136bb60e21b815260048101899052306024820152909150600090620186a09088906001600160a01b03891690637b84daec9060440160206040518083038186803b15801561025857600080fd5b505afa15801561026c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102909190610821565b61029a919061087e565b6102a4919061085c565b604051630441a3e760e41b8152600481018a9052602481018290529091506001600160a01b0387169063441a3e7090604401600060405180830381600087803b1580156102f057600080fd5b505af1158015610304573d6000803e3d6000fd5b50506040516370a0823160e01b815230600482015260009250859150730d500b1d8e8ef31e21c99d1db9a6444d3adf1270906370a082319060240160206040518083038186803b15801561035757600080fd5b505afa15801561036b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061038f9190610821565b610399919061089d565b6040516370a0823160e01b81523060048201529091506000908490737f426f6dc648e50464a0392e60e1bb465a67e9cf906370a082319060240160206040518083038186803b1580156103eb57600080fd5b505afa1580156103ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104239190610821565b61042d919061089d565b604080516001600160a01b03808a1682528a16602082015290810185905260608101849052608081018290529091507fe375b7683f29025c0d635a23d52724c8e0eb095cc78e38d917862d0014475b9f9060a00160405180910390a150505050505050505050565b604051631526fe2760e01b8152600481018390527389d065572136814230a55ddeeddec9df34eb0b769060009081908390631526fe279060240160a060405180830381600087803b1580156104e957600080fd5b505af11580156104fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052191906107c9565b6040516370a0823160e01b81523060048201529496509450600093620186a093508892506001600160a01b03871691506370a082319060240160206040518083038186803b15801561057257600080fd5b505afa158015610586573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105aa9190610821565b6105b4919061087e565b6105be919061085c565b60405163095ea7b360e01b81527389d065572136814230a55ddeeddec9df34eb0b766004820152600060248201529091506001600160a01b0384169063095ea7b390604401602060405180830381600087803b15801561061d57600080fd5b505af1158015610631573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065591906107a0565b5060405163095ea7b360e01b81527389d065572136814230a55ddeeddec9df34eb0b766004820152602481018290526001600160a01b0384169063095ea7b390604401602060405180830381600087803b1580156106b257600080fd5b505af11580156106c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ea91906107a0565b50604051631c57762b60e31b815260048101879052602481018290526001600160a01b0385169063e2bbb15890604401600060405180830381600087803b15801561073457600080fd5b505af1158015610748573d6000803e3d6000fd5b5050604080516001600160a01b038087168252871660208201529081018490527f7359c7ba7b650e10846147c1056a541fbe983598b21ea457aea7ad22cafdc26b9250606001905060405180910390a1505050505050565b6000602082840312156107b257600080fd5b815180151581146107c257600080fd5b9392505050565b600080600080600060a086880312156107e157600080fd5b85516107ec816108ca565b809550506020860151935060408601519250606086015191506080860151610813816108ca565b809150509295509295909350565b60006020828403121561083357600080fd5b5051919050565b6000806040838503121561084d57600080fd5b50508035926020909101359150565b60008261087957634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615610898576108986108b4565b500290565b6000828210156108af576108af6108b4565b500390565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146108df57600080fd5b5056fea2646970667358221220c87e1f15100c75903a1bb952ffbacd5ad9facfc853a26865037b73c041e3931e64736f6c63430008060033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063441a3e701461003b578063e2bbb15814610050575b600080fd5b61004e61004936600461083a565b610063565b005b61004e61005e36600461083a565b610495565b604051631526fe2760e01b8152600481018390527389d065572136814230a55ddeeddec9df34eb0b769060009081908390631526fe279060240160a060405180830381600087803b1580156100b757600080fd5b505af11580156100cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100ef91906107c9565b6040516370a0823160e01b81523060048201529496509450600093730d500b1d8e8ef31e21c99d1db9a6444d3adf127093506370a082319250602401905060206040518083038186803b15801561014557600080fd5b505afa158015610159573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017d9190610821565b6040516370a0823160e01b8152306004820152909150600090737f426f6dc648e50464a0392e60e1bb465a67e9cf906370a082319060240160206040518083038186803b1580156101cd57600080fd5b505afa1580156101e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102059190610821565b604051631ee136bb60e21b815260048101899052306024820152909150600090620186a09088906001600160a01b03891690637b84daec9060440160206040518083038186803b15801561025857600080fd5b505afa15801561026c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102909190610821565b61029a919061087e565b6102a4919061085c565b604051630441a3e760e41b8152600481018a9052602481018290529091506001600160a01b0387169063441a3e7090604401600060405180830381600087803b1580156102f057600080fd5b505af1158015610304573d6000803e3d6000fd5b50506040516370a0823160e01b815230600482015260009250859150730d500b1d8e8ef31e21c99d1db9a6444d3adf1270906370a082319060240160206040518083038186803b15801561035757600080fd5b505afa15801561036b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061038f9190610821565b610399919061089d565b6040516370a0823160e01b81523060048201529091506000908490737f426f6dc648e50464a0392e60e1bb465a67e9cf906370a082319060240160206040518083038186803b1580156103eb57600080fd5b505afa1580156103ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104239190610821565b61042d919061089d565b604080516001600160a01b03808a1682528a16602082015290810185905260608101849052608081018290529091507fe375b7683f29025c0d635a23d52724c8e0eb095cc78e38d917862d0014475b9f9060a00160405180910390a150505050505050505050565b604051631526fe2760e01b8152600481018390527389d065572136814230a55ddeeddec9df34eb0b769060009081908390631526fe279060240160a060405180830381600087803b1580156104e957600080fd5b505af11580156104fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052191906107c9565b6040516370a0823160e01b81523060048201529496509450600093620186a093508892506001600160a01b03871691506370a082319060240160206040518083038186803b15801561057257600080fd5b505afa158015610586573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105aa9190610821565b6105b4919061087e565b6105be919061085c565b60405163095ea7b360e01b81527389d065572136814230a55ddeeddec9df34eb0b766004820152600060248201529091506001600160a01b0384169063095ea7b390604401602060405180830381600087803b15801561061d57600080fd5b505af1158015610631573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065591906107a0565b5060405163095ea7b360e01b81527389d065572136814230a55ddeeddec9df34eb0b766004820152602481018290526001600160a01b0384169063095ea7b390604401602060405180830381600087803b1580156106b257600080fd5b505af11580156106c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ea91906107a0565b50604051631c57762b60e31b815260048101879052602481018290526001600160a01b0385169063e2bbb15890604401600060405180830381600087803b15801561073457600080fd5b505af1158015610748573d6000803e3d6000fd5b5050604080516001600160a01b038087168252871660208201529081018490527f7359c7ba7b650e10846147c1056a541fbe983598b21ea457aea7ad22cafdc26b9250606001905060405180910390a1505050505050565b6000602082840312156107b257600080fd5b815180151581146107c257600080fd5b9392505050565b600080600080600060a086880312156107e157600080fd5b85516107ec816108ca565b809550506020860151935060408601519250606086015191506080860151610813816108ca565b809150509295509295909350565b60006020828403121561083357600080fd5b5051919050565b6000806040838503121561084d57600080fd5b50508035926020909101359150565b60008261087957634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615610898576108986108b4565b500290565b6000828210156108af576108af6108b4565b500390565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146108df57600080fd5b5056fea2646970667358221220c87e1f15100c75903a1bb952ffbacd5ad9facfc853a26865037b73c041e3931e64736f6c63430008060033

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 Autofarm.

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.