diff --git a/README.md b/README.md index 5f21e0c0..465d524b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ users can participate as suppliers or borrowers. Aave Utilities is a JavaScript SDK extending [ethers.js](https://docs.ethers.org/v5/) for interacting with V2 and V3 of the Aave Protocol, an upgrade to the existing -[aave-js](https://github.com/aave/aave-js) library. +[aave-js](https://github.com/aave/aave-js) library. It may be useful to also have +[aave-concepts](https://aave.com/docs/concepts) and [aave-developer-docs](https://aave.com/docs/developers/smart-contracts).
@@ -258,7 +259,7 @@ const currentTimestamp = dayjs().unix(); - @param `marketReferencePriceInUsd` Input from [Fetching Protocol Data](#fetching-protocol-data), `reserves.baseCurrencyData.marketReferencePriceInUsd` - @param `marketReferenceCurrencyDecimals` Input from [Fetching Protocol Data](#fetching-protocol-data), `reserves.baseCurrencyData.marketReferenceCurrencyDecimals` */ -const formattedPoolReserves = formatReserves({ +const formattedReserves = formatReserves({ reserves: reservesArray, currentTimestamp, marketReferenceCurrencyDecimals: @@ -298,7 +299,7 @@ const currentTimestamp = dayjs().unix(); - @param `marketReferenceCurrencyDecimals` Input from [Fetching Protocol Data](#fetching-protocol-data), `reserves.baseCurrencyData.marketReferenceCurrencyDecimals` - @param `reserveIncentives` Input from [Fetching Protocol Data](#fetching-protocol-data), `reserveIncentives` */ -const formattedPoolReserves = formatReservesAndIncentives({ +const formattedReservesAndIncentives = formatReservesAndIncentives({ reserves: reservesArray, currentTimestamp, marketReferenceCurrencyDecimals: @@ -347,7 +348,7 @@ const userReservesArray = userReserves.userReserves; const currentTimestamp = dayjs().unix(); -const formattedPoolReserves = formatReserves({ +const formattedReserves = formatReserves({ reserves: reservesArray, currentTimestamp, marketReferenceCurrencyDecimals: @@ -362,7 +363,7 @@ const formattedPoolReserves = formatReserves({ - @param `userReserves` Input from [Fetching Protocol Data](#fetching-protocol-data), combination of `userReserves.userReserves` and `reserves.reservesArray` - @param `userEmodeCategoryId` Input from [Fetching Protocol Data](#fetching-protocol-data), `userReserves.userEmodeCategoryId` */ -const userSummary = formatUserSummary({ +const formattedUserSummary = formatUserSummary({ currentTimestamp, marketReferencePriceInUsd: baseCurrencyData.marketReferenceCurrencyPriceInUsd, marketReferenceCurrencyDecimals: @@ -398,7 +399,7 @@ const userReservesArray = userReserves.userReserves; const currentTimestamp = dayjs().unix(); -const formattedPoolReserves = formatReserves({ +const formattedReserves = formatReserves({ reserves: reservesArray, currentTimestamp, marketReferenceCurrencyDecimals: @@ -415,7 +416,7 @@ const formattedPoolReserves = formatReserves({ - @param `reserveIncentives` Input from [Fetching Protocol Data](#fetching-protocol-data), `reserveIncentives` - @param `userIncentives` Input from [Fetching Protocol Data](#fetching-protocol-data), `userIncentives` */ -const userSummary = formatUserSummaryAndIncentives({ +const formattedUserSummaryAndIncentives = formatUserSummaryAndIncentives({ currentTimestamp, marketReferencePriceInUsd: baseCurrencyData.marketReferenceCurrencyPriceInUsd, marketReferenceCurrencyDecimals: @@ -515,7 +516,7 @@ corresponding amount of aTokens is minted. The bundle method provides the transaction for the action, approval if required (txn or signature request), and callback to generate signed supplyWithPermit -txn. +txn. You can fetch the `poolAddress` and `WETH_GATEWAY` from [Aave Address Book](https://github.com/bgd-labs/aave-address-book#usage-with-node).
Sample Code @@ -611,9 +612,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `deadline` Expiration of signature in seconds, for example, 1 hour = Math.floor(Date.now() / 1000 + 3600).toString() */ const dataToSign: string = await pool.signERC20Approval({ @@ -652,9 +653,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `signature` Signature approving Pool to spend user funds, received from signing output data of signERC20Approval() - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -691,7 +692,7 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that repays +- @param `user` The ethereum address that repays - @param `reserve` The ethereum address of the reserve on which the user borrowed - @param `amount` The amount to repay, or (-1) if the user wants to repay everything - @param `interestRateMode` // Whether the borrow will incur a stable (InterestRate.Stable) or variable (InterestRate.Variable) interest rate @@ -734,9 +735,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `interestRateMode` // Whether stable (InterestRate.Stable) or variable (InterestRate.Variable) debt will be repaid - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -776,9 +777,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `signature` Signature approving Pool to spend user funds, from signERC20Approval() - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -818,9 +819,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit +- @param `user` The ethereum address that will make the deposit - @param `amount` The amount to be deposited, -1 to repay max aToken balance or max debt balance without dust (whichever is lowest) -- @param `reserve` The ethereum address of the reserve +- @param `reserve` The ethereum address of the reserve - @param `rateMode` The debt type to repay, stable (InterestRate.Stable) or variable (InterestRate.Variable) */ const txs: EthereumTransactionTypeExtended[] = await pool.repayWithATokens({ @@ -853,9 +854,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `aTokenAddress` The aToken to redeem for underlying asset - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -891,9 +892,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `interestRateMode` The rate mode to swap to, stable (InterestRate.Stable) or variable (InterestRate.Variable) +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `interestRateMode` The rate mode to swap to, stable (InterestRate.Stable) or variable (InterestRate.Variable) */ const txs: EthereumTransactionTypeExtended[] = await pool.swapBorrowRateMode({ user, @@ -925,8 +926,8 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve - @param `usageAsCollateral` Boolean, true if the user wants to use the deposit as collateral, false otherwise */ const txs: EthereumTransactionTypeExtended[] = await pool.setUsageAsCollateral({ @@ -958,11 +959,11 @@ const pool = new Pool(provider, { }); /* -- @param `liquidator` The ethereum address that will liquidate the position -- @param `liquidatedUser` The address of the borrower -- @param `debtReserve` The ethereum address of the principal reserve -- @param `collateralReserve` The address of the collateral to liquidated -- @param `purchaseAmount` The amount of principal that the liquidator wants to repay +- @param `liquidator` The ethereum address that will liquidate the position +- @param `liquidatedUser` The address of the borrower +- @param `debtReserve` The ethereum address of the principal reserve +- @param `collateralReserve` The address of the collateral to liquidated +- @param `purchaseAmount` The amount of principal that the liquidator wants to repay - @param @optional `getAToken` Boolean to indicate if the user wants to receive the aToken instead of the asset. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = lendingPool.liquidationCall({ @@ -998,18 +999,18 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position -- @param @optional `flash` If the transaction will be executed through a flashloan(true) or will be done directly through the adapters(false). Defaults to false -- @param `fromAsset` The ethereum address of the asset you want to swap -- @param `fromAToken` The ethereum address of the aToken of the asset you want to swap -- @param `toAsset` The ethereum address of the asset you want to swap to (get) -- @param `fromAmount` The amount you want to swap -- @param `toAmount` The amount you want to get after the swap -- @param `maxSlippage` The max slippage that the user accepts in the swap -- @param @optional `permitSignature` A permit signature of the tx. Only needed when previously signed (Not needed at the moment). -- @param `swapAll` Bool indicating if the user wants to swap all the current collateral -- @param @optional `onBehalfOf` The ethereum address for which user is swapping. It will default to the user address -- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) +- @param `user` The ethereum address that will liquidate the position +- @param @optional `flash` If the transaction will be executed through a flashloan(true) or will be done directly through the adapters(false). Defaults to false +- @param `fromAsset` The ethereum address of the asset you want to swap +- @param `fromAToken` The ethereum address of the aToken of the asset you want to swap +- @param `toAsset` The ethereum address of the asset you want to swap to (get) +- @param `fromAmount` The amount you want to swap +- @param `toAmount` The amount you want to get after the swap +- @param `maxSlippage` The max slippage that the user accepts in the swap +- @param @optional `permitSignature` A permit signature of the tx. Only needed when previously signed (Not needed at the moment). +- @param `swapAll` Bool indicating if the user wants to swap all the current collateral +- @param @optional `onBehalfOf` The ethereum address for which user is swapping. It will default to the user address +- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) - @param @optional `useEthPath` Boolean to indicate if the swap will use an ETH path. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = await lendingPool.swapCollateral( @@ -1054,18 +1055,18 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position -- @param `fromAsset` The ethereum address of the asset you want to repay with (collateral) -- @param `fromAToken` The ethereum address of the aToken of the asset you want to repay with (collateral) -- @param `assetToRepay` The ethereum address of the asset you want to repay +- @param `user` The ethereum address that will liquidate the position +- @param `fromAsset` The ethereum address of the asset you want to repay with (collateral) +- @param `fromAToken` The ethereum address of the aToken of the asset you want to repay with (collateral) +- @param `assetToRepay` The ethereum address of the asset you want to repay - @param `repayWithAmount` The amount of collateral you want to repay the debt with -- @param `repayAmount` The amount of debt you want to repay +- @param `repayAmount` The amount of debt you want to repay - @param `permitSignature` A permit signature of the tx. Optional -- @param @optional `repayAllDebt` Bool indicating if the user wants to repay all current debt. Defaults to false +- @param @optional `repayAllDebt` Bool indicating if the user wants to repay all current debt. Defaults to false - @param `rateMode` //Enum indicating the type of the interest rate of the collateral -- @param @optional `onBehalfOf` The ethereum address for which user is swapping. It will default to the user address -- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) -- @param @optional `flash` If the transaction will be executed through a flashloan(true) or will be done directly through the adapters(false). Defaults to false +- @param @optional `onBehalfOf` The ethereum address for which user is swapping. It will default to the user address +- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) +- @param @optional `flash` If the transaction will be executed through a flashloan(true) or will be done directly through the adapters(false). Defaults to false - @param @optional `useEthPath` Boolean to indicate if the swap will use an ETH path. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = @@ -1113,7 +1114,7 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit +- @param `user` The ethereum address that will make the deposit - @param `categoryId` number representing the eMode to switch to, 0 = disable, 1 = stablecoins */ const txs: EthereumTransactionTypeExtended[] = await pool.setUserEMode({ @@ -1228,12 +1229,12 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will receive the borrowed amount -- @param `reserve` The ethereum address of the reserve asset +- @param `user` The ethereum address that will receive the borrowed amount +- @param `reserve` The ethereum address of the reserve asset - @param `amount` The amount to be borrowed, in human readable units (e.g. 2.5 ETH) - @param `interestRateMode`//Whether the borrow will incur a stable (InterestRate.Stable) or variable (InterestRate.Variable) interest rate -- @param @optional `debtTokenAddress` The ethereum address of the debt token of the asset you want to borrow. Only needed if the reserve is ETH mock address -- @param @optional `onBehalfOf` The ethereum address for which user is borrowing. It will default to the user address +- @param @optional `debtTokenAddress` The ethereum address of the debt token of the asset you want to borrow. Only needed if the reserve is ETH mock address +- @param @optional `onBehalfOf` The ethereum address for which user is borrowing. It will default to the user address */ const txs: EthereumTransactionTypeExtended[] = await lendingPool.borrow({ user, @@ -1273,7 +1274,7 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that repays +- @param `user` The ethereum address that repays - @param `reserve` The ethereum address of the reserve on which the user borrowed - @param `amount` The amount to repay, or (-1) if the user wants to repay everything - @param `interestRateMode` // Whether stable (InterestRate.Stable) or variable (InterestRate.Variable) debt will be repaid @@ -1310,10 +1311,10 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will receive the aTokens -- @param `reserve` The ethereum address of the reserve asset -- @param `amount` The amount of aToken being redeemed -- @param @optional `aTokenAddress` The ethereum address of the aToken. Only needed if the reserve is ETH mock address +- @param `user` The ethereum address that will receive the aTokens +- @param `reserve` The ethereum address of the reserve asset +- @param `amount` The amount of aToken being redeemed +- @param @optional `aTokenAddress` The ethereum address of the aToken. Only needed if the reserve is ETH mock address - @param @optional `onBehalfOf` The amount of aToken being redeemed. It will default to the user address */ const txs: EthereumTransactionTypeExtended[] = lendingPool.withdraw({ @@ -1347,8 +1348,8 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that wants to swap rate modes -- @param `reserve` The address of the reserve on which the user borrowed +- @param `user` The ethereum address that wants to swap rate modes +- @param `reserve` The address of the reserve on which the user borrowed - @param `interestRateMode` //Whether the borrow will incur a stable (InterestRate.Stable) or variable (InterestRate.Variable) interest rate */ const txs: EthereumTransactionTypeExtended[] = lendingPool.swapBorrowRateMode({ @@ -1380,7 +1381,7 @@ const lendingPool = new LendingPool(provider, { /* - @param `user` The ethereum address that enables or disables the deposit as collateral -- @param `reserve` The ethereum address of the reserve +- @param `reserve` The ethereum address of the reserve - @param `useAsCollateral` Boolean, true if the user wants to use the deposit as collateral, false otherwise */ const txs: EthereumTransactionTypeExtended[] = lendingPool.setUsageAsCollateral( @@ -1416,10 +1417,10 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `liquidator` The ethereum address that will liquidate the position -- @param `liquidatedUser` The address of the borrower -- @param `debtReserve` The ethereum address of the principal reserve -- @param `collateralReserve` The address of the collateral to liquidated +- @param `liquidator` The ethereum address that will liquidate the position +- @param `liquidatedUser` The address of the borrower +- @param `debtReserve` The ethereum address of the principal reserve +- @param `collateralReserve` The address of the collateral to liquidated - @param `purchaseAmount` The amount of principal that the liquidator wants to repay - @param @optional `getAToken` Boolean to indicate if the user wants to receive the aToken instead of the asset. Defaults to false */ @@ -1460,14 +1461,14 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position -- @param @optional `flash` If the transaction will be executed through a flashloan(true) or will be done directly through the adapters(false). Defaults to false -- @param `fromAsset` The ethereum address of the asset you want to swap +- @param `user` The ethereum address that will liquidate the position +- @param @optional `flash` If the transaction will be executed through a flashloan(true) or will be done directly through the adapters(false). Defaults to false +- @param `fromAsset` The ethereum address of the asset you want to swap - @param `fromAToken` The ethereum address of the aToken of the asset you want to swap -- @param `toAsset` The ethereum address of the asset you want to swap to (get) -- @param `fromAmount` The amount you want to swap -- @param `toAmount` The amount you want to get after the swap -- @param `maxSlippage` The max slippage that the user accepts in the swap +- @param `toAsset` The ethereum address of the asset you want to swap to (get) +- @param `fromAmount` The amount you want to swap +- @param `toAmount` The amount you want to get after the swap +- @param `maxSlippage` The max slippage that the user accepts in the swap - @param @optional `permitSignature` A permit signature of the tx. Only needed when previously signed (Not needed at the moment). - @param `swapAll` Bool indicating if the user wants to swap all the current collateral - @param @optional `onBehalfOf` The ethereum address for which user is swapping. It will default to the user address @@ -1520,12 +1521,12 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position +- @param `user` The ethereum address that will liquidate the position - @param `fromAsset` The ethereum address of the asset you want to repay with (collateral) - @param `fromAToken` The ethereum address of the aToken of the asset you want to repay with (collateral) -- @param `assetToRepay` The ethereum address of the asset you want to repay +- @param `assetToRepay` The ethereum address of the asset you want to repay - @param `repayWithAmount` The amount of collateral you want to repay the debt with -- @param `repayAmount` The amount of debt you want to repay +- @param `repayAmount` The amount of debt you want to repay - @param `permitSignature` A permit signature of the tx. Optional - @param @optional `repayAllDebt` Bool indicating if the user wants to repay all current debt. Defaults to false - @param `rateMode` //Enum indicating the type of the interest rate of the collateral @@ -1724,8 +1725,8 @@ const governanceService = new AaveGovernanceService(rpcProvider, { }); /* -- @param `user` The ethereum address that will create the proposal -- @param `proposalId` Id of the proposal we want to vote +- @param `user` The ethereum address that will create the proposal +- @param `proposalId` Id of the proposal we want to vote - @param `support` Bool indicating if you are voting in favor (true) or against (false) */ const tx = governanceService.submitVote({ user, proposalId, support }); @@ -1751,7 +1752,7 @@ import { GovernancePowerDelegationTokenService } from '@aave/contract-helpers'; const powerDelegation = new GovernancePowerDelegationTokenService(rpcProvider); /* -- @param `user` The ethereum address that will create the proposal +- @param `user` The ethereum address that will create the proposal - @param `delegatee` The ethereum address to which the user wants to delegate proposition power and voting power - @param `governanceToken` The ethereum address of the governance token */ @@ -1778,7 +1779,7 @@ import { GovernancePowerDelegationTokenService } from '@aave/contract-helpers'; const powerDelegation = new GovernancePowerDelegationTokenService(rpcProvider); /* -- @param `user` The ethereum address that will create the proposal +- @param `user` The ethereum address that will create the proposal - @param `delegatee` The ethereum address to which the user wants to delegate proposition power and voting power - @param `delegationType` The type of the delegation the user wants to do: voting power ('0') or proposition power ('1') - @param `governanceToken` The ethereum address of the governance token @@ -1816,7 +1817,7 @@ const faucetService = new FaucetService(provider, faucetAddress); /* - @param `userAddress` The ethereum address of the wallet the minted tokens will go -- @param `reserve` The ethereum address of the token you want to mint +- @param `reserve` The ethereum address of the token you want to mint - @param `tokenSymbol` The symbol of the token you want to mint */ const tx = faucet.mint({ userAddress, reserve, tokenSymbol });