#StackBounty: #contract-development #truffle-contract #aave Simple Contract to supply eth to aave

Bounty: 100

I’m working on a simple contract which will supply eth (and other tokens to aave).

// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 < 0.8.7;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";


import "./libs/IAaveStake.sol";


contract SafeYieldAggregator is Ownable, ReentrancyGuard, Pausable {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    address public constant aaveDepositAddress = 0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf;
    address public constant aaveMockETHAddress = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
    address public wantAddress;
    uint16 public referralCode = 0;
    address public govAddress;

    constructor() {
        govAddress = msg.sender;        
        wantAddress = aaveMockETHAddress;
    }

    function supply(uint256 _amount) public payable {
        IAaveStake(aaveDepositAddress).deposit(wantAddress, _amount, address(this), referralCode);
    }
    
    function removeSupply(uint256 _amount) public {
        IAaveStake(aaveDepositAddress).withdraw(wantAddress, _amount, address(this));
    }
}

interface IAaveStake {

    function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external payable;
    
    function withdraw(address asset, uint256 amount, address to) external;

}

I have code which consumes this like so:

handleDeposit: function(event) {
  event.preventDefault();
  web3.eth.getAccounts(function(error, accounts) {
    if (error) {
      console.log(error);
    }
  
    var account = accounts[0];
  
    App.contracts.SafeYieldAggregator.deployed().then(function(instance) {
      yieldAggregatorInstance = instance;
  
      // Execute adopt as a transaction by sending account
      return yieldAggregatorInstance.supply(1, {from: account});
    }).then(function(result) {
      //return App.markAdopted();
    }).catch(function(err) {
      console.log(err.message);
    });
  });
},

When attempting to supply, Metamask displays an error:

ALERT: Transaction Error. Exception thrown in contract code.

I’m running ganache

ganache-cli --fork https://mainnet.infura.io/v3/{{MyProjectId}}

The only error I see in the console is:

Transaction: 0x9961f8a187c09fd7c9ebf803771fa161c9939268bb01552a1598807bcfdc13ff
Gas usage: 24813
Block Number: 12905002
Block Time: Mon Jul 26 2021 20:38:30 GMT-0400 (Eastern Daylight Time)
Runtime Error: revert

How can I write a simple contract which supplies Eth (Or any other token) to aave?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.