The CoreClient class provides methods to interact with the Aave protocol on the Aptos blockchain. It extends the AptosContractWrapperBaseClass and includes functionalities for supplying, borrowing, repaying, and managing assets within the Aave protocol.

This client is designed to work with the core Aave protocol contracts and provides a high-level API for supply, borrow, and liquidation 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 = CoreClient.buildWithDefaultSigner(provider);

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

// Supply assets to the protocol
const tx = await client.supply(assetAddress, 1000n, userAddress, 0);

Hierarchy (View Summary)

Constructors

Properties

supplyBorrowContract: SupplyBorrowContract

Methods

  • Borrows a specified amount of an asset on behalf of a user.

    Parameters

    • asset: AccountAddress

      The address of the asset to borrow.

    • amount: bigint

      The amount of the asset to borrow.

    • interestRateMode: number

      The interest rate mode (e.g., stable or variable).

    • referralCode: number

      The referral code for the transaction.

    • onBehalfOf: AccountAddress

      The address of the user on whose behalf the asset is borrowed.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to the response of the committed transaction.

  • 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.

  • 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.
  • 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 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 account data for a specific user.

    Parameters

    • user: AccountAddress

      The address of the user's account.

    Returns Promise<
        {
            availableBorrowsBase: bigint;
            currentLiquidationThreshold: bigint;
            healthFactor: bigint;
            ltv: bigint;
            totalCollateralBase: bigint;
            totalDebtBase: bigint;
        },
    >

    A promise that resolves to an object containing the user's account data:

    • totalCollateralBase: The total collateral in base units.
    • totalDebtBase: The total debt in base units.
    • availableBorrowsBase: The available amount for borrowing in base units.
    • currentLiquidationThreshold: The current liquidation threshold in base units.
    • ltv: The loan-to-value ratio in base units.
    • healthFactor: The health factor in base units.
  • Executes a liquidation call on the Aave protocol.

    Parameters

    • collateralAsset: AccountAddress

      The address of the collateral asset.

    • debtAsset: AccountAddress

      The address of the debt asset.

    • user: AccountAddress

      The address of the user whose position is being liquidated.

    • debtToCover: bigint

      The amount of debt to cover in the liquidation.

    • receiveAToken: boolean

      A boolean indicating whether to receive aTokens as collateral.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse object.

  • Repays a borrowed amount for a specific asset.

    Parameters

    • asset: AccountAddress

      The address of the asset to repay.

    • amount: bigint

      The amount to repay, specified as a bigint.

    • interestRateMode: number

      The interest rate mode (e.g., stable or variable).

    • onBehalfOf: AccountAddress

      The address of the account on whose behalf the repayment is made.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Repays a loan using aTokens.

    Parameters

    • asset: AccountAddress

      The address of the asset to repay.

    • amount: bigint

      The amount of the asset to repay, in bigint.

    • interestRateMode: number

      The interest rate mode (e.g., stable or variable).

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • 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.

  • Sets whether a user should use a specific reserve as collateral.

    Parameters

    • asset: AccountAddress

      The address of the asset to be used as collateral.

    • useAsCollateral: boolean

      A boolean indicating whether to use the asset as collateral.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Supplies a specified amount of an asset on behalf of a given account.

    Parameters

    • asset: AccountAddress

      The address of the fungible asset to supply.

    • amount: bigint

      The amount of the fungible asset to supply, represented as a bigint.

    • onBehalfOf: AccountAddress

      The address of the account on whose behalf the asset is being supplied.

    • referralCode: number

      A referral code for tracking referrals.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Supplies a specified amount of a coin on behalf of a given account.

    Parameters

    • coinType: string

      The type of the coin to supply.

    • amount: bigint

      The amount of the coin to supply, represented as a bigint.

    • onBehalfOf: AccountAddress

      The address of the account on whose behalf the asset is being supplied.

    • referralCode: number

      A referral code for tracking referrals.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Withdraws a specified amount of an asset to a given account address.

    Parameters

    • asset: AccountAddress

      The address of the asset to withdraw.

    • amount: bigint

      The amount of the asset to withdraw, represented as a bigint.

    • to: AccountAddress

      The account address to which the asset will be withdrawn.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse once the transaction is committed.