The aTokens are interest-bearing derivative tokens that are minted and burned upon deposit
(called from LendingPool
) and redeem
(called from the aToken contract
). The aTokens' value is pegged to the value of the corresponding deposited asset at a 1:1 ratio, and can be safely stored, transferred or traded. All interest collected by the aTokens reserves are distributed to aTokens holders directly by continuously increasing their wallet balance. Users can decide to redirect their stream of interest payments to any Ethereum public address.
redeem(uint256 _amount)
Non-standard ERC20 function to redeem an _amount
of aTokens for the underlying asset, burning the aTokens during the process.
redeem()
will fail if the aTokens to be redeemed are being used as collateral. Please refer to the transferAllowed()
function to understand how to check if a specific redeem/transfer action can be performed./// Instantiation of the aToken address
aToken aTokenInstance = AToken("/*aToken_address*/");
/// Input variables
uint256 amount = 1000 * 1e18;
/// redeem method call
aTokenInstance.redeem(amount)
// Import the ABIs, see: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
import ADaiTokenABI from "./ADaiToken.json"
//import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
//import LendingPoolABI from "./LendingPool.json"
//const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
//const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest LendingPoolCore address
//const lpCoreAddress = await lpAddressProviderContract.methods
// .getLendingPoolCore()
// .call()
// .catch((e) => {
// throw Error(`Error getting lendingPool address: ${e.message}`)
// })
const aDaiToken = '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d'
const aDaiContract = new web3.eth.Contract(ADaiTokenABI, aDaiToken)
// redeem 1000 DAI
const amountInWei = web3.utils.toWei("1000", "ether")
await aDaiContract.methods
.redeem(amountInWei)
.send()
.catch((e) => {
throw Error(`Error redeeming aDai: ${e.message}`)
})
transfer(address recipient, uint256 amount) public
Standard ERC20 function to transfer tokens from msg.sender
to a specified recipient
.
transfer()
will fail if the aTokens to be redeemed are being used as collateral. Please refer to the transferAllowed()
function to understand how to check if a specific redeem/transfer action can be performed.transfer()
will fail if an amount
of 0 is used, which is non-standard ERC20 behaviour./// Instantiation of the aToken address
aToken aTokenInstance = aToken("/*aToken_address*/");
/// Input variables
address recipient = /*transfer_recipient_address*/;
uint256 amount = 1000 * 1e18;
/// transfer method call
aTokenInstance.transfer(recipient, amount)
// Import the ABIs, see: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
import ADaiTokenABI from "./ADaiToken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest LendingPoolCore address
const lpCoreAddress = await lpAddressProviderContract.methods
.getLendingPoolCore()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
const aDaiToken = '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d'
const aDaiContract = new web3.eth.Contract(ADaiTokenABI, aDaiToken)
// transfer 1000 DAI
const amountInWei = web3.utils.toWei("1000", "ether")
await aDaiContract.methods
.transfer(amountInWei)
.send()
.catch((e) => {
throw Error(`Error transfering aDai: ${e.message}`)
})
transferFrom(address from, address to, uint256 amount) public
Standard ERC20 function to transfer tokens from an address to another.
transferFrom()
will fail if the aTokens to be redeemed are being used as collateral. Please refer to the transferAllowed()
function to understand how to check if a specific redeem/transfer action can be performed.transferFrom()
will fail if an amount
of 0 is used, which is non-standard ERC20 behaviour./// Instantiation of the AToken address
AToken aTokenInstance = AToken("/*aToken_address*/");
/// Input variables
address from = /*transfer_source_address*/
address to = /*transfer_recipient_address*/;
uint256 amount = 1000 * 1e18;
/// transferFrom method call
aTokenInstance.transferFrom(from, to, amount)
// Import the ABIs, see: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
import ADaiTokenABI from "./ADaiToken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest LendingPoolCore address
const lpCoreAddress = await lpAddressProviderContract.methods
.getLendingPoolCore()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
const aDaiToken = '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d'
const aDaiContract = new web3.eth.Contract(ADaiTokenABI, aDaiToken)
// transfer 1000 DAI between two addresses
const amountInWei = web3.utils.toWei("1000", "ether")
const from = "FROM_ADDRESS"
const to = "TO_ADDRESS"
await aDaiContract.methods
.transferFrom(from, to, amountInWei)
.send()
.catch((e) => {
throw Error(`Error transferFrom for aDai: ${e.message}`)
})
isTransferAllowed(address user, uint256 amount)
Non-standard ERC20 function that checks if a transfer or a redeem will fail. Specifically, a transfer/redeem will fail if the resulting Health Factor of the user performing the action will end up being below 1.
redirectInterestStream(address _to)
Redirects the interest generated to a target address.
/// Instantiation of the aToken address
aToken aTokenInstance = aToken("/*aToken_address*/");
/// Input variables
address receiver = /*receiver_public_address*/;
/// transfer method call
aTokenInstance.redirectInterestStream(receiver)
// Import the ABIs, see: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
import ADaiTokenABI from "./ADaiToken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest LendingPoolCore address
const lpCoreAddress = await lpAddressProviderContract.methods
.getLendingPoolCore()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
const aDaiToken = '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d'
const aDaiContract = new web3.eth.Contract(ADaiTokenABI, aDaiToken)
// redirect interest stream to a different address
const to = "TO_ADDRESS"
await aDaiContract.methods
.redirectInterestStream(to)
.send()
.catch((e) => {
throw Error(`Error redeeming Dai: ${e.message}`)
})
redirectInterestStreamOf(address _from, address _to)
Allows an allowed third-party to redirect the interest generated by a depositor to a target address. When the interest is redirected, the depositor balance is added to the receiver balance. The caller needs to have allowance on the interest redirection to be able to execute the function.
/// Instantiation of the aToken address
aToken aTokenInstance = aToken("/*aToken_address*/");
/// Input variables
address depositor = /*depositor_public_address*/;
address receiver = /*receiver_public_address*/;
/// transfer method call
aTokenInstance.redirectInterestStreamOf(depositor, receiver);
// Import the ABIs, see: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
import ADaiTokenABI from "./ADaiToken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest LendingPoolCore address
const lpCoreAddress = await lpAddressProviderContract.methods
.getLendingPoolCore()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
const aDaiToken = '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d'
const aDaiContract = new web3.eth.Contract(ADaiTokenABI, aDaiToken)
// redirect interest stream between two addresses
const from = "FROM_ADDRESS"
const to = "TO_ADDRESS"
await aDaiContract.methods
.redirectInterestStreamOf(from, to)
.send()
.catch((e) => {
throw Error(`Error redeeming Dai: ${e.message}`)
})
allowInterestRedirectionTo(address _to)
Gives allowance to an address to execute the interest redirection on behalf of the caller. This method allows third parties to setup interest stream redirections on behalf of the depositors.
/// Instantiation of the aToken address
aToken aTokenInstance = aToken("/*aToken_address*/");
/// Input variables
address receiver = /*receiver_public_address*/;
/// transfer method call
aTokenInstance.allowInterestRedirectionTo(receiver)
// Import the ABIs, see: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
import ADaiTokenABI from "./ADaiToken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest LendingPoolCore address
const lpCoreAddress = await lpAddressProviderContract.methods
.getLendingPoolCore()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
const aDaiToken = '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d'
const aDaiContract = new web3.eth.Contract(ADaiTokenABI, aDaiToken)
// allow `to` address to redirect interest stream
const to = "TO_ADDRESS"
await aDaiContract.methods
.allowInterestRedirectionTo(to)
.send()
.catch((e) => {
throw Error(`Error redeeming Dai: ${e.message}`)
})
_user
all interest collected included.user
current balance deposited to the Aave Protocol reserve contract, with interest collected amount removed.