The UnderlyingTokensClient class provides methods to interact with underlying tokens on the Aptos blockchain. It extends the AptosContractWrapperBaseClass and includes functionalities for creating, minting, burning, and managing underlying tokens within the AAVE protocol.

This client is designed to work with the underlying token contracts and provides a high-level API for token operations. The client can be instantiated in two ways:

  1. Using the constructor directly with a provider and optional signer
  2. Using the static buildWithDefaultSigner method which automatically configures the client with the provider's pool profile account
// Using buildWithDefaultSigner
const provider = new AptosProvider();
const client = UnderlyingTokensClient.buildWithDefaultSigner(provider);

// Using constructor directly
const provider = new AptosProvider();
const signer = provider.getPoolProfileAccount();
const client = new UnderlyingTokensClient(provider, signer);

// Create a new token
const tx = await client.createToken(
1000000n, // maximumSupply
"My Token", // name
"MTK", // symbol
8, // decimals
"https://example.com/icon.png", // iconUri
"https://example.com" // projectUri
);

// Mint tokens to an address
const metadataAddress = await client.getMetadataBySymbol("MTK");
const tx = await client.mint(userAddress, 1000n, metadataAddress);

The AptosProvider instance used to interact with the Aptos blockchain.

Optional Ed25519Account signer for transaction signing.

Hierarchy (View Summary)

Constructors

Properties

tokensContract: TokensContract

Methods

  • Retrieves the balance of underlying tokens for a given owner and metadata address.

    Parameters

    • owner: AccountAddress

      The account address of the token owner.

    • metadataAddress: AccountAddress

      The account address of the token metadata.

    Returns Promise<bigint>

    A promise that resolves to the balance of underlying tokens as a bigint.

  • Builds a transaction for the specified user, function, and arguments.

    Parameters

    • user: AccountAddress

      The account address of the user initiating the transaction.

    • functionId: `${string}::${string}::${string}`

      The identifier of the Move function to be called.

    • funcArgs: (EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes)[]

      An array of arguments for the entry function.

    • typeArgs: string[] = []

    Returns Promise<SimpleTransaction>

    A promise that resolves to a SimpleTransaction object.

  • Burns a specified amount of tokens to a given account address.

    Parameters

    • from: AccountAddress

      The account address to which the tokens will be burned.

    • amount: bigint

      The amount of tokens to burn, represented as a bigint.

    • metadataAddress: AccountAddress

      The account address of the metadata.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Calls a view method on the Aptos blockchain.

    Type Parameters

    • T extends MoveValue[]

      The type of the return value, which extends an array of MoveValue.

    Parameters

    • functionId: `${string}::${string}::${string}`

      The identifier of the function to call.

    • funcArgs: (EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes)[]

      The arguments to pass to the function.

    • typeArgs: string[] = []

      Optional generic type arguments for the function (e.g. ["0x1::aptos_coin::AptosCoin"]).

    Returns Promise<T>

    • A promise that resolves to the result of the view method call.
  • Creates a new token with the specified parameters.

    Parameters

    • maximumSupply: bigint

      The maximum supply of the token as a bigint.

    • name: string

      The name of the token.

    • symbol: string

      The symbol of the token.

    • decimals: number

      The number of decimal places for the token.

    • iconUri: string

      The URI of the token's icon.

    • projectUri: string

      The URI of the project's website or information page.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Retrieves the number of decimals for a given token's metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the token's metadata.

    Returns Promise<bigint>

    A promise that resolves to the number of decimals as a bigint.

  • Funds an account with a specified amount.

    Parameters

    • account: AccountAddress

      The address of the account to be funded.

    • amount: bigint

      The amount to fund the account with, in bigint.

    Returns Promise<UserTransactionResponse>

    A promise that resolves to a UserTransactionResponse.

  • Retrieves the Aptos balance of a specified account.

    Parameters

    • account: Ed25519Account

      The Ed25519 account object.

    • accountAddress: AccountAddress

      The address of the account to retrieve the balance for.

    • OptionalversionToWaitFor: bigint

      (Optional) The specific version to wait for before retrieving the balance.

    Returns Promise<bigint>

    A promise that resolves to the balance of the account in bigint.

  • Retrieves events associated with a specific account.

    Parameters

    • account: AccountAddress

      The address of the account to retrieve events for.

    • limit: number

      The maximum number of events to retrieve.

    Returns Promise<
        {
            account_address: string;
            creation_number: any;
            data: any;
            event_index: any;
            indexed_type: string;
            sequence_number: any;
            transaction_block_height: any;
            transaction_version: any;
            type: string;
        }[],
    >

    A promise that resolves to an array of event objects, each containing:

    • account_address: The address of the account.
    • creation_number: The creation number of the event.
    • data: The data associated with the event.
    • event_index: The index of the event.
    • sequence_number: The sequence number of the event.
    • transaction_block_height: The block height of the transaction.
    • transaction_version: The version of the transaction.
    • type: The type of the event.
    • indexed_type: The indexed type of the event.
  • Retrieves the metadata for a given token symbol.

    Parameters

    • symbol: string

      The symbol of the token for which metadata is being requested.

    Returns Promise<AccountAddress>

    A promise that resolves to an AccountAddress object containing the metadata.

    Will throw an error if the view method call fails or if the response cannot be parsed.

  • Retrieves the token account address.

    This method calls the UnderlyingGetTokenAccountAddressFuncAddr function of the tokensContract to get the token account address.

    Returns Promise<AccountAddress>

    A promise that resolves to an AccountAddress object.

  • Retrieves the events associated with a given transaction hash.

    Parameters

    • txHash: HexInput

      The hash of the transaction to retrieve events for.

    Returns Promise<{ data: unknown }[]>

    A promise that resolves to an array of objects containing the event data.

    This method fetches the transaction details using the provided Aptos provider. It then checks if the transaction response is of type BlockMetadataTransactionResponse or UserTransactionResponse to extract the events. The event data is parsed from JSON and returned in an array.

  • Retrieves the maximum value associated with a given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the account metadata.

    Returns Promise<bigint>

    A promise that resolves to a bigint representing the maximum value, or undefined if not available.

  • Mints a specified amount of tokens to a given account address.

    Parameters

    • to: AccountAddress

      The account address to which the tokens will be minted.

    • amount: bigint

      The amount of tokens to mint, represented as a bigint.

    • metadataAddress: AccountAddress

      The account address of the metadata.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Retrieves the name of the underlying token associated with the given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the account metadata.

    Returns Promise<string>

    A promise that resolves to the name of the underlying token as a string.

  • Sends a transaction and awaits the response.

    Parameters

    • functionId: `${string}::${string}::${string}`

      The ID of the Move function to be called.

    • funcArgs: (EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes)[]

      An array of arguments for the entry function.

    • typeArgs: string[] = []

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to the committed transaction response.

  • Supplies the underlying tokens for a given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the metadata to supply tokens for.

    Returns Promise<bigint>

    A promise that resolves to the amount of tokens supplied as a bigint.

  • Retrieves the symbol of the underlying token associated with the given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the account metadata.

    Returns Promise<string>

    A promise that resolves to the symbol of the underlying token as a string.

  • Retrieves the token address for a given symbol.

    Parameters

    • symbol: string

      The symbol of the token whose address is to be retrieved.

    Returns Promise<AccountAddress>

    A promise that resolves to the account address of the token.