How to deposit and redeem AAVE V3 in Solidity (Goerli)?

Hello friends.

Either I’m looking badly, or there is not a article on the Internet on how to add a deposit and withdraw it in the third version of aave.

I wrote this code, but it doesn’t work.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IPool } from "@aave/core-v3/contracts/interfaces/IPool.sol";
import { IPoolAddressesProvider } from "@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol";
import { IAToken } from "@aave/core-v3/contracts/interfaces/IAToken.sol";

contract Contract {

    function deposit(uint256 wallet_, address asset_, uint256 amount_) public {
        IPoolAddressesProvider provider = IPoolAddressesProvider(address(0xc4dCB5126a3AfEd129BC3668Ea19285A9f56D15D));
        IPool pool = IPool(provider.getPool());

        IERC20(asset_).transferFrom(msg.sender, address(this), amount_);

        if (IERC20(asset_).allowance(address(this), address(pool)) == 0) {
            IERC20(asset_).approve(address(pool), type(uint256).max);
        }

        pool.deposit(asset_, amount_, address(wallet_), 0);
    }
}

asset_ - LINK token 0x326C977E6efc84E512bB9C30f76E30c160eD06FB

Please, can someone have a working example of the code?

  1. Deploy contract using Remix
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import { IPool } from "@aave/core-v3/contracts/interfaces/IPool.sol";
import { IPoolAddressesProvider } from "@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol";
import { IAToken } from "@aave/core-v3/contracts/interfaces/IAToken.sol";

interface IERC20 {
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

contract Deposit {
    
    constructor() {} 
 
    function setDeposit() public returns(uint256) {
        IPoolAddressesProvider provider = IPoolAddressesProvider(address(0xc4dCB5126a3AfEd129BC3668Ea19285A9f56D15D));
        IPool pool = IPool(provider.getPool());
        IERC20(0x326C977E6efc84E512bB9C30f76E30c160eD06FB).transferFrom(msg.sender, address(this), 1*10**10);
        IERC20(0x326C977E6efc84E512bB9C30f76E30c160eD06FB).approve(address(pool), type(uint256).max);
        pool.deposit(0x326C977E6efc84E512bB9C30f76E30c160eD06FB, 1*10**10, 0x0Bf0Dc06F8F1b6AD19F63CE88066F693FaF18e2B, 0);
        return IERC20(0x326C977E6efc84E512bB9C30f76E30c160eD06FB).allowance(address(this), address(pool));
    }
} 
  1. Approve 10000000000 LINK token for contract address

  2. Run function setDeposit using Remix

ERROR

Oh my God.
You are using some other LINK token, which is simply impossible to get anywhere.

Faucet for Polygon Mainnet? I do not understand anything.

How to get test tokens for Goerli?

Hi @alexbakers the easiest way to get test tokens for Goerli is going to the interface https://app.aave.com/ enabled test mode in the top right corner, and then head to V3 Gorli market

Then in the header you can find the Faucet link.

if you have further dev queries I think its easier to get response from ecosystem developers in discord at Aave Community (I suggest you to disable DMs in privacy settings there only scammers/spammers would DM you there)

1 Like

You are the best.
Thank you.