Module 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::a_token_factory
@title a_token_factory Module @author Aave @notice Factory module for creating and managing aTokens in the Aave protocol @dev This module manages the creation, minting, burning, and various operations of aTokens
- Struct
Initialized
- Struct
TokenRescued
- Resource
TokenData
- Resource
TokenMap
- Function
is_atoken
- Function
get_token_account_address
- Function
get_reserve_treasury_address
- Function
get_underlying_asset_address
- Function
get_previous_index
- Function
get_scaled_user_balance_and_supply
- Function
scaled_balance_of
- Function
balance_of
- Function
scaled_total_supply
- Function
total_supply
- Function
name
- Function
symbol
- Function
decimals
- Function
token_address
- Function
asset_metadata
- Function
rescue_tokens
- Function
handle_repayment
- Function
create_token
- Function
mint
- Function
burn
- Function
mint_to_treasury
- Function
set_incentives_controller
- Function
transfer_underlying_to
- Function
transfer_on_liquidation
- Function
drop_token
use 0x1::account;
use 0x1::event;
use 0x1::fungible_asset;
use 0x1::object;
use 0x1::option;
use 0x1::signer;
use 0x1::smart_table;
use 0x1::string;
use 0x1::table_with_length;
use 0x24e01fa503119e76bf9eea69eec59884fc3da82f5ea23bf5f20f8ce358a4606::acl_manage;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::error_config;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::events;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::fungible_asset_manager;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::pool;
use 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::token_base;
use 0xd63343bff7977cb364b17dcdcdeb64e77b7bc9b4ec252f481ace51b6de3bbd96::wad_ray_math;
Struct Initialized
@notice Emitted when an aToken is initialized @param underlying_asset The address of the underlying asset @param treasury The address of the treasury @param incentives_controller The address of the incentives controller @param a_token_decimals The decimals of the underlying @param a_token_name The name of the aToken @param a_token_symbol The symbol of the aToken
#[event]
struct Initialized has drop, store
Struct TokenRescued
@notice Emitted when a token is being rescued @dev Emitted during the the rescue tokens method @param from The account from which the token is being transferred/rescued @param to The receiver of the rescued tokens @param amount The amount being transferred during rescue @param a_token_address The address of the aToken
#[event]
struct TokenRescued has drop, store
Resource TokenData
@notice Data structure that stores aToken-specific information @param underlying_asset The address of the underlying asset @param treasury The address of the treasury @param signer_cap The signer capability for the resource account
#[resource_group_member(#[group = 0x1::object::ObjectGroup])]
struct TokenData has drop, key
Resource TokenMap
@notice Bi-directional mapping between underlying tokens and aTokens @dev This serves two purposes: 1. Ensures the same underlying token has only one aToken (underlying_to_token) 2. Provides quick lookup to check if an address is an aToken (token_to_underlying) @param underlying_to_token Maps underlying token address to aToken address @param token_to_underlying Maps aToken address to underlying token address
struct TokenMap has key
Function is_atoken
@notice Checks if the given address represents an aToken @param metadata_address The address to check @return True if the address is an aToken, false otherwise
#[view]
public fun is_atoken(metadata_address: address): bool
Function get_token_account_address
@notice Retrieves the account address of the managed fungible asset for a specific aToken @dev Creates a signer capability for the resource account managing the fungible asset @param metadata_address The address of the aToken @return The address of the managed fungible asset account
#[view]
public fun get_token_account_address(metadata_address: address): address
Function get_reserve_treasury_address
@notice Returns the address of the Aave treasury that receives fees on this aToken @param metadata_address The address of the aToken @return Address of the Aave treasury
#[view]
public fun get_reserve_treasury_address(metadata_address: address): address
Function get_underlying_asset_address
@notice Returns the address of the underlying asset of this aToken @param metadata_address The address of the aToken @return The address of the underlying asset
#[view]
public fun get_underlying_asset_address(metadata_address: address): address
Function get_previous_index
@notice Returns last index interest was accrued to the user's balance @param user The address of the user @param metadata_address The address of the aToken @return The last index interest was accrued to the user's balance, expressed in ray
#[view]
public fun get_previous_index(user: address, metadata_address: address): u256
Function get_scaled_user_balance_and_supply
@notice Returns the scaled balance of the user and the scaled total supply @param owner The address of the user @param metadata_address The address of the aToken @return The scaled balance of the user @return The scaled total supply
#[view]
public fun get_scaled_user_balance_and_supply(owner: address, metadata_address: address): (u256, u256)
Function scaled_balance_of
@notice Returns the scaled balance of the user @dev 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 @param owner The user whose balance is calculated @param metadata_address The address of the aToken @return The scaled balance of the user
#[view]
public fun scaled_balance_of(owner: address, metadata_address: address): u256
Function balance_of
@notice Returns the amount of tokens owned by the owner @param owner The address of the token owner @param metadata_address The address of the aToken @return The balance of tokens for the owner
#[view]
public fun balance_of(owner: address, metadata_address: address): u256
Function scaled_total_supply
@notice Returns the scaled total supply of the scaled balance token @dev Represents sum(debt/index) @param metadata_address The address of the aToken @return The scaled total supply
#[view]
public fun scaled_total_supply(metadata_address: address): u256
Function total_supply
@notice Returns the amount of tokens in existence @param metadata_address The address of the aToken @return The total supply of tokens
#[view]
public fun total_supply(metadata_address: address): u256
Function name
@notice Returns the name of the token @param metadata_address The address of the aToken @return The name of the token
#[view]
public fun name(metadata_address: address): string::String
Function symbol
@notice Returns the symbol of the token @param metadata_address The address of the aToken @return The symbol of the token
#[view]
public fun symbol(metadata_address: address): string::String
Function decimals
@notice Returns the number of decimals of the token @param metadata_address The address of the aToken @return The number of decimals
#[view]
public fun decimals(metadata_address: address): u8
Function token_address
@notice Returns the address of an aToken by its symbol @param symbol The symbol of the aToken to find @return The address of the aToken
#[view]
public fun token_address(symbol: string::String): address
Function asset_metadata
@notice Returns the metadata object of an aToken by its symbol @param symbol The symbol of the aToken to find @return The metadata object of the aToken
#[view]
public fun asset_metadata(symbol: string::String): object::Object<fungible_asset::Metadata>
Function rescue_tokens
@notice Transfers out any token that is not the underlying token from an aToken's resource account @param account The account signer of the caller @param token The address of the token to transfer @param to The address of the recipient @param amount The amount of token to transfer @param metadata_address The address of the aToken
public entry fun rescue_tokens(account: &signer, token: address, to: address, amount: u256, metadata_address: address)
Function handle_repayment
@notice Handles repayment by potentially performing actions with the underlying asset @dev The default implementation is empty, but subclasses may override to stake or use the asset @param _user The user executing the repayment @param _on_behalf_of The address of the user who will get his debt reduced/removed @param _amount The amount getting repaid @param _metadata_address The address of the aToken
public fun handle_repayment(_user: address, _on_behalf_of: address, _amount: u256, _metadata_address: address)
Function create_token
@notice Creates a new aToken @dev Only callable by the pool_token_logic module @param signer The signer of the caller @param name The name of the aToken @param symbol The symbol of the aToken @param decimals The decimals of the aToken @param icon_uri The icon URI of the aToken @param project_uri The project URI of the aToken @param incentives_controller The incentive controller address, if any, of the Token @param underlying_asset The address of the underlying asset @param treasury The address of the treasury @return The address of the aToken
public(friend) fun create_token(signer: &signer, name: string::String, symbol: string::String, decimals: u8, icon_uri: string::String, project_uri: string::String, incentives_controller: option::Option<address>, underlying_asset: address, treasury: address): address
Function mint
@notice Mints amount
aTokens to on_behalf_of
@dev Only callable by the supply_logic module
@param caller The address performing the mint
@param on_behalf_of The address of the user that will receive the minted aTokens
@param amount The amount of tokens getting minted
@param index The next liquidity index of the reserve
@param metadata_address The address of the aToken
@return whether this is the first time we mint aTokens to on_behalf_of
public(friend) fun mint(caller: address, on_behalf_of: address, amount: u256, index: u256, metadata_address: address): bool
Function burn
@notice Burns aTokens from from
and sends the equivalent amount of underlying to receiver_of_underlying
@dev Only callable by the supply_logic, borrow_logic and liquidation_logic module
@dev In some instances, the mint event could be emitted from a burn transaction
if the amount to burn is less than the interest that the user accrued
@param from The address from which the aTokens will be burned
@param receiver_of_underlying The address that will receive the underlying
@param amount The amount being burned
@param index The next liquidity index of the reserve
@param metadata_address The address of the aToken
public(friend) fun burn(from: address, receiver_of_underlying: address, amount: u256, index: u256, metadata_address: address)
Function mint_to_treasury
@notice Mints aTokens to the reserve treasury @dev Only callable by the pool_token_logic module @param amount The amount of tokens getting minted @param index The next liquidity index of the reserve @param metadata_address The address of the aToken
public(friend) fun mint_to_treasury(amount: u256, index: u256, metadata_address: address)
Function set_incentives_controller
@notice Sets an incentives controller for the aToken @dev Only callable by the pool_token_logic module @param admin The address of the admin calling the method @param metadata_address The address of the aToken @param incentives_controller The address of the incentives controller
public(friend) fun set_incentives_controller(admin: &signer, metadata_address: address, incentives_controller: option::Option<address>)
Function transfer_underlying_to
@notice Transfers the underlying asset to to
@dev Only callable by the borrow_logic and flashloan_logic module
@param to The recipient of the underlying
@param amount The amount getting transferred
@param metadata_address The address of the aToken
public(friend) fun transfer_underlying_to(to: address, amount: u256, metadata_address: address)
Function transfer_on_liquidation
@notice Transfers aTokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken @dev Only callable by the liquidation_logic module @param from The address getting liquidated, current owner of the aTokens @param to The recipient @param amount The amount of tokens getting transferred @param index The next liquidity index of the reserve @param metadata_address The address of the aToken
public(friend) fun transfer_on_liquidation(from: address, to: address, amount: u256, index: u256, metadata_address: address)
Function drop_token
@notice Drops the a token associated data @dev Only callable by the pool_token_logic module @param metadata_address The address of the metadata object
public(friend) fun drop_token(metadata_address: address)