The OracleClient class provides methods to interact with the oracle contract on the Aptos blockchain. It extends the AptosContractWrapperBaseClass and includes functionalities to retrieve and set asset prices, manage feed IDs, and obtain oracle-related addresses.

This client is designed to work with the oracle contracts and provides a high-level API for price feed 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 oracle profile account
// Using buildWithDefaultSigner
const provider = new AptosProvider();
const client = OracleClient.buildWithDefaultSigner(provider);

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

// Get asset price
const price = await client.getAssetPrice(assetAddress);

The AptosProvider instance used to interact with the Aptos blockchain.

Optional Ed25519Account signer for transaction signing.

Hierarchy (View Summary)

Constructors

Properties

oracleContract: OracleContract

Methods

  • Removes the custom prices for a batch of assets from the oracle contract.

    Parameters

    • assets: AccountAddress[]

      An array of account addresses representing the assets whose custom prices are to be removed.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse indicating the result of the transaction.

  • Removes the feed IDs for a batch of assets from the oracle contract.

    Parameters

    • assets: AccountAddress[]

      An array of account addresses representing the assets whose feed IDs are to be removed.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse indicating the result of the transaction.

  • Sets the custom prices for a batch of assets in the oracle contract.

    Parameters

    • assets: AccountAddress[]

      An array of account addresses representing the assets.

    • customPrices: bigint[]

      An array of bigints representing the custom prices of the assets.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • Sets the feed IDs for a batch of assets in the oracle contract.

    Parameters

    • assets: AccountAddress[]

      An array of account addresses representing the assets.

    • feedIds: Uint8Array<ArrayBufferLike>[]

      An array of Uint8Array representing the feed IDs for the assets.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to a CommittedTransactionResponse.

  • 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 the price of a specified asset.

    Parameters

    • asset: AccountAddress

      The address of the asset for which the price is being requested.

    Returns Promise<bigint>

    A promise that resolves to the price of the asset as a bigint.

  • Retrieves the oracle asset price decimals.

    Returns Promise<number>

    A promise that resolves to the asset price decimals of the oracle.

  • Retrieves the prices of the specified assets.

    Parameters

    • assets: AccountAddress[]

      An array of account addresses representing the assets.

    Returns Promise<bigint[]>

    A promise that resolves to an array of bigints, each representing the price of an asset.

  • 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 oracle address from the oracle contract.

    Returns Promise<AccountAddress>

    A promise that resolves to the oracle address.

  • Retrieves the price cap of a specified asset.

    Parameters

    • asset: AccountAddress

      The address of the asset for which the price cap is being requested.

    Returns Promise<MoveOptionType>

    A promise that resolves to the price cap of the asset as a bigint.

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

  • Returns if an asset price is capped or not.

    Parameters

    • asset: AccountAddress

      The address of the asset for which we are checking if there is a cap.

    Returns Promise<boolean>

    A promise that resolves to a boolean.

  • Removes the custom price associated with a given asset.

    Parameters

    • asset: AccountAddress

      The address of the asset for which the custom price should be removed.

    Returns Promise<CommittedTransactionResponse>

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

  • Removes the feed ID associated with a given asset.

    Parameters

    • asset: AccountAddress

      The address of the asset for which the feed ID should be removed.

    Returns Promise<CommittedTransactionResponse>

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

  • Removes a price cap stable adapter for a given asset.

    Parameters

    • asset: AccountAddress

      The account address of the asset for which the stable price adapter is being remved.

    Returns Promise<CommittedTransactionResponse>

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

  • 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 a custom price for a given asset.

    Parameters

    • asset: AccountAddress

      The account address of the asset for which the feed ID is being set.

    • customPrice: bigint

      The custom price of the asset.

    Returns Promise<CommittedTransactionResponse>

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

  • Sets the feed ID for a given asset in the oracle contract.

    Parameters

    • asset: AccountAddress

      The account address of the asset for which the feed ID is being set.

    • feedId: Uint8Array

      The feed ID to be associated with the asset, represented as a Uint8Array.

    Returns Promise<CommittedTransactionResponse>

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

  • Sets a price cap stable adapter for a given asset.

    Parameters

    • asset: AccountAddress

      The account address of the asset for which the stable price adapter is being set.

    • priceCap: bigint

      The price cap.

    Returns Promise<CommittedTransactionResponse>

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