aave-tokens on Aptos

This documentation covers the tokenization modules in the Aave protocol implementation on Aptos. Similar to Aave on EVM chains, the Aptos implementation uses specialized tokens to represent user positions in the protocol.

a_token_factory Module

The a_token_factory module manages the creation and operations of aTokens, which represent user supply positions in the Aave protocol. aTokens are interest-bearing tokens that automatically accrue interest to their holders.

Write Methods

create_token

public(friend) fun create_token(    signer: &signer,    name: String,    symbol: String,    decimals: u8,    icon_uri: String,    project_uri: String,    incentives_controller: Option<address>,    underlying_asset: address,    treasury: address): address

Creates a new aToken for a specific underlying asset.

Input Parameters:

NameTypeDescription
signer&signerThe signer of the caller
nameStringThe name of the aToken
symbolStringThe symbol of the aToken
decimalsu8The decimals of the aToken
icon_uriStringThe icon URI of the aToken
project_uriStringThe project URI of the aToken
incentives_controllerOption<address>The address of the incentives controller for this aToken
underlying_assetaddressThe address of the underlying asset
treasuryaddressThe address of the treasury

Return Values:

TypeDescription
addressThe address of the created aToken

Emits:

  • Initialized event with details about the created aToken

mint

public(friend) fun mint(    caller: address,    on_behalf_of: address,    amount: u256,    index: u256,    metadata_address: address): bool

Mints aTokens to a user.

Input Parameters:

NameTypeDescription
calleraddressThe address performing the mint
on_behalf_ofaddressThe address that will receive the minted aTokens
amountu256The amount of tokens getting minted
indexu256The next liquidity index of the reserve
metadata_addressaddressThe address of the aToken

Return Values:

TypeDescription
booltrue if the previous balance of the user was 0

burn

public(friend) fun burn(    from: address,    receiver_of_underlying: address,    amount: u256,    index: u256,    metadata_address: address)

Burns aTokens from a user and sends the equivalent amount of underlying to the receiver.

In some instances, a mint event could be emitted from a burn transaction if the amount to burn is less than the interest that the user accrued.

mint_to_treasury

public(friend) fun mint_to_treasury(    amount: u256,    index: u256,    metadata_address: address)

Mints aTokens to the reserve treasury.

Input Parameters:

NameTypeDescription
amountu256The amount of tokens getting minted
indexu256The next liquidity index of the reserve
metadata_addressaddressThe address of the aToken

transfer_on_liquidation

public(friend) fun transfer_on_liquidation(    from: address,    to: address,    amount: u256,    index: u256,    metadata_address: address)

Transfers aTokens in the event of a borrow being liquidated, in case the liquidator reclaims the aToken.

Input Parameters:

NameTypeDescription
fromaddressThe address getting liquidated, current owner of the aTokens
toaddressThe recipient of aTokens
amountu256The amount of tokens getting transferred
indexu256The next liquidity index of the reserve
metadata_addressaddressThe address of the aToken

Emits:

  • Balance transfer event with the scaled amount and index

handle_repayment

public fun handle_repayment(    _user: address,    _on_behalf_of: address,    _amount: u256,    _metadata_address: address)

Handles the underlying received by the aToken after the transfer has been completed.

The default implementation is empty as with standard tokens, nothing needs to be done after the transfer is concluded. However, in the future there may be aTokens that allow for example to stake the underlying to receive LM rewards. In that case, handle_repayment() would perform the staking of the underlying asset.

Input Parameters:

NameTypeDescription
_useraddressThe user executing the repayment
_on_behalf_ofaddressThe address for which the borrow position is repaid
_amountu256The amount getting repaid
_metadata_addressaddressThe address of the aToken

drop_token

public(friend) fun drop_token(metadata_address: address)

Drops the aToken associated data.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the metadata object

View Methods

get_underlying_asset_address

public fun get_underlying_asset_address(    metadata_address: address): address

Returns the address of the underlying asset of this aToken.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the aToken

Return Values:

TypeDescription
addressThe address of the underlying asset

get_previous_index

public fun get_previous_index(    user: address,    metadata_address: address): u256

Returns the last index interest was accrued to the user's balance.

Input Parameters:

NameTypeDescription
useraddressThe address of the user
metadata_addressaddressThe address of the aToken

Return Values:

TypeDescription
u256The last index interest was accrued to the user's balance, expressed in ray

get_scaled_user_balance_and_supply

public fun get_scaled_user_balance_and_supply(    owner: address,    metadata_address: address): (u256, u256)

Returns the scaled balance of the user and the scaled total supply.

Input Parameters:

NameTypeDescription
owneraddressThe address of the user
metadata_addressaddressThe address of the aToken

Return Values:

TypeDescription
u256The scaled balance of the user
u256The scaled total supply

scaled_balance_of

public fun scaled_balance_of(    owner: address,    metadata_address: address): u256

Returns the scaled balance of the 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.

Input Parameters:

NameTypeDescription
owneraddressThe address of the user
metadata_addressaddressThe address of the aToken

Return Values:

TypeDescription
u256The scaled balance of the user

scaled_total_supply

public fun scaled_total_supply(    metadata_address: address): u256

Returns the scaled total supply of the aToken.

The scaled total supply is the sum of all scaled balances of the users.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the aToken

Return Values:

TypeDescription
u256The scaled total supply

decimals

public fun decimals(metadata_address: address): u8

Returns the decimals of the aToken.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the aToken

Return Values:

TypeDescription
u8The decimals of the aToken

Variable Debt Token Factory

The variable_debt_token_factory module manages the creation and operations of variable debt tokens in the Aave protocol on Aptos. Variable debt tokens represent user borrowing positions with a variable interest rate.

Write Methods

create_token

public(friend) fun create_token(    signer: &signer,    name: String,    symbol: String,    decimals: u8,    icon_uri: String,    project_uri: String,    incentives_controller: Option<address>,    underlying_asset: address): address

Creates a new variable debt token for a specific underlying asset.

Input Parameters:

NameTypeDescription
signer&signerThe signer of the caller
nameStringThe name of the variable debt token
symbolStringThe symbol of the variable debt token
decimalsu8The decimals of the variable debt token
icon_uriStringThe icon URI of the variable debt token
project_uriStringThe project URI of the variable debt token
incentives_controllerOption<address>The address of the incentives controller for this debt token
underlying_assetaddressThe address of the underlying asset

Return Values:

TypeDescription
addressThe address of the created debt token

Emits:

  • Initialized event with details about the created variable debt token

mint

public(friend) fun mint(    caller: address,    on_behalf_of: address,    amount: u256,    index: u256,    metadata_address: address): bool

Mints debt tokens to the on_behalf_of address.

Input Parameters:

NameTypeDescription
calleraddressThe address receiving the borrowed underlying, being the delegatee in case of credit delegate, or same as on_behalf_of otherwise
on_behalf_ofaddressThe address receiving the debt tokens
amountu256The amount of debt being minted
indexu256The variable debt index of the reserve
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
boolWhether this is the first time we mint the variable debt token to the user

Emits:

  • Transfer event from zero address to recipient

  • Mint event with details about the mint operation

burn

public(friend) fun burn(    from: address,    amount: u256,    index: u256,    metadata_address: address)

Burns debt tokens from a user.

Input Parameters:

NameTypeDescription
fromaddressThe address from which the debt tokens will be burned
amountu256The amount of debt tokens that will be burned
indexu256The variable debt index of the reserve
metadata_addressaddressThe address of the variable debt token

Emits:

  • Transfer event to zero address

  • Burn event with details about the burn operation

  • If the balance increase is greater than the amount, also emits Transfer and Mint events

drop_token

public(friend) fun drop_token(metadata_address: address)

Drops the variable debt token associated data.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the metadata object

View Methods

get_underlying_asset_address

public fun get_underlying_asset_address(    metadata_address: address): address

Returns the address of the underlying asset of this variable debt token.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
addressThe address of the underlying asset

get_previous_index

public fun get_previous_index(    user: address,    metadata_address: address): u256

Returns the last index interest was accrued to the user's balance.

Input Parameters:

NameTypeDescription
useraddressThe address of the user
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
u256The last index interest was accrued to the user's balance, expressed in ray

get_scaled_user_balance_and_supply

public fun get_scaled_user_balance_and_supply(    owner: address,    metadata_address: address): (u256, u256)

Returns the scaled balance of the user and the scaled total supply.

Input Parameters:

NameTypeDescription
owneraddressThe address of the user
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
u256The scaled balance of the user
u256The scaled total supply

scaled_balance_of

public fun scaled_balance_of(    owner: address,    metadata_address: address): u256

Returns the scaled balance of the user.

The scaled balance is the sum of all the updated stored balance divided by the reserve's variable debt index at the moment of the update.

Input Parameters:

NameTypeDescription
owneraddressThe address of the user
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
u256The scaled balance of the user

scaled_total_supply

public fun scaled_total_supply(    metadata_address: address): u256

Returns the scaled total supply of the variable debt token.

The scaled total supply is the sum of all scaled balances of the users with debt.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
u256The scaled total supply

name

public fun name(metadata_address: address): String

Returns the name of the variable debt token.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
StringThe name of the variable debt token

symbol

public fun symbol(metadata_address: address): String

Returns the symbol of the variable debt token.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
StringThe symbol of the variable debt token

decimals

public fun decimals(metadata_address: address): u8

Returns the decimals of the variable debt token.

Input Parameters:

NameTypeDescription
metadata_addressaddressThe address of the variable debt token

Return Values:

TypeDescription
u8The decimals of the variable debt token

Comparison with Ethereum Implementation

The variable debt token implementation in Aptos follows similar principles to the Ethereum implementation but is adapted to the Move language and Aptos blockchain architecture:

  1. Object-based Model: Instead of ERC20 contracts, Aptos uses an object-based model for fungible assets.

  2. Scaled Balances: Like in Ethereum, the variable debt tokens use scaled balances to track user debt positions, which automatically accrue interest over time.

  3. Index-based Interest Accrual: Interest accrual is handled through index-based calculations, similar to the Ethereum implementation.

  4. No Transfers: Variable debt tokens cannot be transferred between users, as they represent a specific user's debt position.

The variable debt tokens in Aave on Aptos serve the same purpose as in the Ethereum implementation: they represent a user's variable-rate debt position in the protocol and automatically accrue interest over time based on the variable interest rate of the corresponding reserve.

Aave.com provides information and resources about the fundamentals of the decentralised non-custodial liquidity protocol called the Aave Protocol, comprised of open-source self-executing smart contracts that are deployed on various permissionless public blockchains, such as Ethereum (the "Aave Protocol" or the "Protocol"). Aave Labs does not control or operate any version of the Aave Protocol on any blockchain network.