Aave

Lend, borrow & interact with Aave's smart contact suite.

Overview

Currently, the FunWallet SDK supports the following Aave actions:

  • Withdraw a position from Aave on an EOA's behalf



In the future, the FunWallet SDK will support:

  • Withdraw a position from Aave

  • Open a position on Aave

  • Increase an Aave position's size

  • Decrease an Aave position's size



To learn more about Aave Module method headers, parameters & return values, visit the Aave Module API Reference.



Example Flow

It is highly recommended to test Aave on a fork of eth-mainnet. See how to test with forks here.

The following flow describes how to use the EoaAaveWithdrawal action to exit an Aave position on an EOA's behalf. For this flow to work, we require that the EOA give conditional spend approval over its aTokens to a FunWallet.

1

Import Requried Libraries

import { ethers } from "ethers";
import { FunWallet, FunWalletConfig, Modules } from "@fun-wallet/sdk";
const { EoaAaveWithdrawal } = Modules;
2

Create an ethers.Wallet EOA Instance

// An internal Fun RPC for customer testing
const rpc = "https://avalanche-fuji.infura.io/v3/4a1a0a67f6874be6bb6947a62792dab7";
const provider = new ethers.providers.JsonRpcProvider(rpc);
// Note that the key here will be exposed and should never be used in production
const eoa = new ethers.Wallet(PRIV_KEY, provider);
3

Create & Initialize a FunWallet

const chainID = "43113" // Fuji testnet
const prefundAmt = 0.3 // amount of native gas token to prefund our FunWallet with
const API_KEY = "" // Get your API key from app.fun.xyz/api-key
const config = new FunWalletConfig(eoa, chainID, prefundAmt)
const wallet = new FunWallet(config, API_KEY)
// init will perform the pre-funding of the FunWallet
await wallet.init()
4

Create & Add EoaAaveWithdrawal Module to a FunWallet

const eoaAaveWithdrawalModule = new EoaAaveWithdrawal();
await wallet.addModule(eoaAaveWithdrawalModule);
5

Deploy a FunWallet to a Blockchain with the EoaAaveWithdrawal Module Attached

const deployWalletReceipt = await wallet.deploy();
6

Generate & Deploy Required EoaAaveWithdrawal Module Pre-Execution Transactions

// Address of aDAI on mainnet
const TOKEN_ADDRESSS = "0x028171bCA77440897B824Ca71D1c56caC55b68A3";
// Use max int to withdraw the entire deposit
const WITHDRAW_AMOUNT = ethers.constants.MaxInt256
const moduleRequiredPreTxs = await eoaAaveWithdrawalModule.getPreExecTxs(TOKEN_ADDRESSS, WITHDRAW_AMOUNT);
const reqPreTxReceipt = await wallet.deployTxs(moduleRequiredPreTxs);
7

Generate & Deploy Transaction that Withdraws a Position From Aave

const aaveWithdrawTx = await eoaAaveWithdrawalModule.createWithdrawTx(TOKEN_ADDRESSS, await wallet.eoa.getAddress(), WITHDRAW_AMOUNT)
const aaveWithdrawalReceipt = await FunWallet.deployTx(aaveWithdrawTx);

Full example

,
aave-example.js
// Install necessary packages
// npm install @fun-wallet/sdk ethers
// Add Imports
import { ethers } from "ethers";
import { FunWallet, FunWalletConfig, Modules } from "@fun-wallet/sdk";
const { EoaAaveWithdrawal } = Modules;
// // An internal Fun RPC for customer testing
const rpc = "https://avalanche-fuji.infura.io/v3/4a1a0a67f6874be6bb6947a62792dab7";
const provider = new ethers.providers.JsonRpcProvider(rpc);
// Note that the key here will be exposed and should never be used in production
const eoa = new ethers.Wallet(PRIV_KEY, provider);
// Create a FunWallet
const chainID = "43113" // Fuji testnet
const prefundAmt = 0.3 // amount of native gas token to prefund our FunWallet with
const API_KEY = "" // Get your API key from app.fun.xyz/api-key
const config = new FunWalletConfig(eoa, chainID, prefundAmt)
const wallet = new FunWallet(config, API_KEY)
// init will perform the pre-funding of the FunWallet
await wallet.init()
// Address of aDAI on mainnet
const TOKEN_ADDRESSS = "0x028171bCA77440897B824Ca71D1c56caC55b68A3";
// Use max int to withdraw the entire deposit
const WITHDRAW_AMOUNT = ethers.constants.MaxInt256
const eoaAaveWithdrawalModule = new EoaAaveWithdrawal();
await wallet.addModule(eoaAaveWithdrawalModule);
const deployWalletReceipt = await wallet.deploy();
const moduleRequiredPreTxs = await eoaAaveWithdrawalModule.getPreExecTxs(TOKEN_ADDRESSS, WITHDRAW_AMOUNT);
const reqPreTxReceipt = await wallet.deployTxs(moduleRequiredPreTxs);
const aaveWithdrawTx = await eoaAaveWithdrawalModule.createWithdrawTx(TOKEN_ADDRESSS, await wallet.eoa.getAddress(), WITHDRAW_AMOUNT)
const aaveWithdrawalReceipt = await wallet.deployTx(aaveWithdrawTx);
console.log(aaveWithdrawalReceipt)
,
aave-example-output.json
{
userOpHash: '0xd7ea68043200a00db7bdf072842cb3669456525ab24db6032f910fe7aafd56cb',
txid: '0xb98e9c5cd9451a5b7335723f223738eaa0c16b3a60f47e9d3592ff5faef54fb4',
gasUsed: 173974,
gasUSD: 0.09142246713
}

Mentioned Classes