AToken

AToken

aTokens are tokens minted and burnt upon supply and withdraw of assets to an Aave market, which denote the amount of crypto assets supplied and the yield earned on those assets. The aTokens’ value is pegged to the value of the corresponding supplied asset at a 1:1 ratio and can be safely stored, transferred or traded. All yield collected by the aTokens' reserves are distributed to aToken holders directly by continuously increasing their wallet balance.

EIP20 Methods

All standard EIP20 methods are implemented for aTokens, such as balanceOf, transfer, transferFrom, approve, totalSupply etc.
💡 `balanceOf` will always return the most up to date balance of the user, which includes their principal balance + the yield generated by the principal balance.

EIP712 Methods

DOMAIN_SEPARATOR

function DOMAIN_SEPARATOR()
Get the domain separator for the token at current chain.

nonces

function nonces(address owner)
Returns the nonce value for address specified as parameter. This is the nonce used when calling permit()
1
const token = new Contract(aTokenAddres, aToken.abi, provider);
2
await token.nonces(user);
Copied!

Aave Protocol View Methods

scaledBalanceOf

function scaledBalanceOf(address user)
Returns the scaled supply balance of user. The scaled balance is the sum of all the updated stored balance divided by the reserve's liquidity index at the moment of the update.

getScaledUserBalanceAndSupply

function getScaledUserBalanceAndSupply(address user)
Returns the scaled balance of the user and the scaled total supply.

scaledTotalSupply

function scaledTotalSupply()
Returns the scaled total supply of the aToken.

getPreviousIndex

function getPreviousIndex(address user)
Returns last index interest that was accrued to the user's balance (expressed in ray).

getIncentivesController

function getIncentivesController()
Returns the address of the Incentives Controller contract

POOL

function POOL()
Returns the address of the associated Pool for the aToken.

UNDERLYING_ASSET_ADDRESS

function UNDERLYING_ASSET_ADDRESS()
Returns address of the underlying reserve asset.

RESERVE_TREASURY_ADDRESS

function RESERVE_TREASURY_ADDRESS()
Returns address of the Aave Treasury, controlled by governance, receiving the fee on this aToken.

Aave Protocol Write Methods

setIncentivesController

function setIncentivesController(IAaveIncentivesController controller)
Sets a new Incentives Controller.
Only Pool Admin can call this methods. To update Incentives Controller on main Aave market, Governance Proposal must be submitted.

permit

Allows a user to permit another account (or contract) to use their funds using a signed message. This enables gas-less transactions and single approval/transfer transactions.
Parameter
Type
Description
owner
address
The owner of the funds
spender
address
The spender for the funds
value
uint256
The amount the spender is permitted to use
deadline
uint256
The deadline timestamp that the permit is valid. Use type(uint).max for no deadline.
v
uint8
Signature parameter
r
bytes32
Signature parameter
s
bytes32
Signature parameter
1
import { signTypedData_v4 } from 'eth-sig-util'
2
import { fromRpcSig } from 'ethereumjs-util'
3
// ... other imports
4
import aTokenAbi from "./aTokenAbi.json"
5
// ... setup your web3 provider
6
const aTokenAddress = "ATOKEN_ADDRESS"
7
const aTokenContract = new web3.eth.Contract(aTokenAbi, aTokenAddress)
8
const privateKey = "YOUR_PRIVATE_KEY_WITHOUT_0x"
9
const chainId = 1
10
const owner = "OWNER_ADDRESS"
11
const spender = "SPENDER_ADDRESS"
12
const value = 100 // Amount the spender is permitted
13
const nonce = 1 // The next valid nonce, use `_nonces()`
14
const deadline = 1600093162
15
const permitParams = {
16
types: {
17
EIP712Domain: [
18
{ name: "name", type: "string" },
19
{ name: "version", type: "string" },
20
{ name: "chainId", type: "uint256" },
21
{ name: "verifyingContract", type: "address" },
22
],
23
Permit: [
24
{ name: "owner", type: "address" },
25
{ name: "spender", type: "address" },
26
{ name: "value", type: "uint256" },
27
{ name: "nonce", type: "uint256" },
28
{ name: "deadline", type: "uint256" },
29
],
30
},
31
primaryType: "Permit",
32
domain: {
33
name: "aTOKEN_NAME",
34
version: "1",
35
chainId: chainId,
36
verifyingContract: aTokenAddress,
37
},
38
message: {
39
owner,
40
spender,
41
value,
42
nonce,
43
deadline,
44
},
45
}
46
const signature = signTypedData_v4(
47
Buffer.from(privateKey, "hex"),
48
{ data: permitParams }
49
)
50
// The signature can now be used to execute the transaction
51
const { v, r, s } = fromRpcSig(signature)
52
await aTokenContract.methods
53
.permit({
54
owner,
55
spender,
56
value,
57
deadline,
58
v,
59
r,
60
s
61
})
62
.send()
63
.catch((e) => {
64
throw Error(`Error permitting: ${e.message}`)
65
})
Copied!

FAQ

  • How aToken earn interest? / How aToken balance increases?
    LendingPool methods (deposit, withdraw, borrow, repay, liquidationCall) updates the state and cumulated liquidity index of the reserve once every block. AToken's balanceOf method returns the balance computed based on block.timestamp and liquidityIndex of the underlying reserve and hence, returns the most up to date balance of account, which includes principal + interest.
  • LiquidityRate vs LiquidityIndex
  • Can I transfer aTokens?
    Yes! with few caveat to keep in mind
    • By transferring aTokens, you’re transferring your balance of the underlying asset. Only the account holding the aTokens can withdraw the deposited asset.
    • AToken transfer will fail if the resulting Health Factor of user will end up being below 1.
  • If I transfer aToken does my pending liquidity rewards get transferred?
    No, liquidity rewards earned prior to the transfer of aToken are accrued by the user/address holding the aTokens originally. Though, all future liquidity rewards will be earned by the new recepient.
  • What is the difference between ScaledBalance and Balance?
  • Example please!
    Let’s say you supply 1,000 DAI to the Aave LendingPool, you will receive 1,000 aDAI (at 1:1 exchange rate).
    You can see your aDAI balance increasing right away.
    Now, say a month later your aDAI balance is 1,050. You could withdraw 1,050 DAI from LendingPool by burning 1050 aDAI.