UNPKG

@layerzerolabs/lz-aptos-sdk-v2

Version:

290 lines (285 loc) 11.3 kB
import { Aptos, Ed25519Account, SimpleTransaction, AccountAuthenticator, CommittedTransactionResponse, InputGenerateTransactionPayloadData, AccountAddressInput, MoveStructId, LedgerVersionArg, TableItemRequest } from '@aptos-labs/ts-sdk'; import { Provider } from '@layerzerolabs/lz-core'; import { Network, Chain, Stage } from '@layerzerolabs/lz-definitions'; import { AccountsOption, MoveSdkImpl, LayerZeroModulesSdk } from '@layerzerolabs/lz-movevm-sdk-v2'; import { MoveFunction, EntryFunctionArgumentTypes, MoveValue, PrivateKey, MnemonicAndPath, ByteCode, GasOptions, TransactionResponse } from '@layerzerolabs/move-definitions'; /** * The basis points (BPS) used to apply a safety margin to the gas limit. * * 1 BPS = 0.01%, so 2000 BPS = 20%. */ declare const GAS_LIMIT_SAFETY_BPS = 2000; /** * Applies a safety margin to the gas limit. * * @param {string} gasUsed - The amount of gas used. * @returns {bigint} The gas limit with the safety margin applied. */ declare function applyGasLimitSafety(gasUsed: string): bigint; declare const ENDPOINT_V2_ADDRESS: { [network in Network]?: string; }; declare const SIMPLE_MESSAGE_LIB_ADDRESS: { [network in Network]?: string; }; declare const ULN_MESSAGE_LIB_ADDRESS: { [network in Network]?: string; }; declare const COUNTER_V2_ADDRESS: { [network in Network]?: string; }; declare const OFT_ADDRESS: { [network in Network]?: string; }; declare const LAYERZERO_VIEWS_ADDRESS: { [network in Network]?: string; }; declare const EXECUTOR_ADDRESS: { [network in Network]?: string; }; declare const EXECUTOR_ULN301_ADDRESS: { [network in Network]?: string; }; declare const DVN_ADDRESS: { [network in Network]?: string; }; declare const DVN_301_ADDRESS: { [network in Network]?: string; }; declare const DVN_UPGRADER_ADDRESS: { [network in Network]?: string; }; declare const WORKER_COMMON: { [network in Network]?: string; }; declare const PRICE_FEED: { [network in Network]?: string; }; declare const TREASURY_ADDRESS: { [network in Network]?: string; }; declare const ENDPOINT_V2_COMMON: { [network in Network]?: string; }; declare const DVN_FEE_LIB: { [network in Network]?: string; }; declare const EXECUTOR_FEE_LIB: { [network in Network]?: string; }; declare const DEPLOY_TO_OBJECT: { [network in Network]?: string; }; /** * Options for initializing the SDK. */ interface SdkOptions { /** * The chain for the SDK (optional). * default value is Chain.APTOS */ chain?: Chain; /** * The provider for the SDK. */ provider: Aptos; /** * The stage of the SDK (optional). * default value is Stage.SANDBOX */ stage?: Stage; /** * The accounts option (optional). * default value is read from generated/addresses.ts */ accounts?: AccountsOption; } /** * Creates an instance of the SDK from the given provider. * * @param {Provider} provider - The provider of the current chain. {@link AptosProvider} * @param {Stage} [stage] - The stage of the SDK. {@link Stage} * @returns {SDK} The initialized SDK instance. */ declare function getSDKFromProvider(provider: Provider, stage?: Stage): SDK; /** * The SDK class provides methods to interact with the Aptos. * For usage, please check [README.md](../README.md). * * @implements {MoveSdkImpl<Ed25519Account>} */ declare class SDK implements MoveSdkImpl<Ed25519Account> { chain: Chain; stage: Stage; client: Aptos; LayerzeroModule: LayerZeroModulesSdk<Ed25519Account>; accounts: AccountsOption; /** * Creates an instance of the SDK. * * @param {SdkOptions} options - The SDK options. */ constructor(options: SdkOptions); /** * Gets the Aptos client. * * @returns {Aptos} The Aptos client. */ getAptosClient(): Aptos; /** * Sends and confirms an authenticated transaction. * * @param {Object} args - The arguments for the transaction. * @param {SimpleTransaction} args.txn - The transaction to send. * @param {AccountAuthenticator} args.auth - The authenticator for the transaction. * @returns {Promise<CommittedTransactionResponse>} The response of the committed transaction. */ sendAndConfirmAuthTransaction(args: { txn: SimpleTransaction; auth: AccountAuthenticator; }): Promise<CommittedTransactionResponse>; isMoveFunctionId(name: string): boolean; /** * Sends and confirms a transaction with the given signer and payload. * * @param {Ed25519Account} signer - The signer of the transaction. * @param {InputEntryFunctionData} payload - The payload of the transaction. * @param {GasOptions} [gasOptions] - The gas options for the transaction. * @returns {Promise<CommittedTransactionResponse>} The response of the committed transaction. * @private */ private sendAndConfirmTransaction_; /** * Handles errors and returns appropriate error instances based on the error type. * * @param {unknown} e - The error to handle. * @returns {unknown} The handled error, which could be an instance of MoveAbortError, MoveResourceNotFoundError, MoveTableItemNotFoundError, UnclassifiedError, or the original error. */ handleError(e: unknown): unknown; /** * Executes a view function and returns the result. * @implements {MoveSdkImpl<Ed25519Account>} * * @param {Object} args - The arguments for the view function. * @param {MoveFunction} args.functionName - The name of the function. * @param {EntryFunctionArgumentTypes[]} args.functionArgs - The arguments for the function. * @param {string[]} [args.typeArgs] - The type arguments for the function. * @returns {Promise<MoveValue[]>} The result of the view function. */ viewFunction(args: { functionName: MoveFunction; functionArgs: EntryFunctionArgumentTypes[]; typeArgs?: string[]; }): Promise<MoveValue[]>; /** * Normalizes the signer to an Ed25519Account. * @implements {MoveSdkImpl<Ed25519Account>} * * @param {Ed25519Account | PrivateKey | MnemonicAndPath} signer - The signer to normalize. * @returns {Ed25519Account} The normalized signer. * @throws {Error} If the signer is invalid. */ normalizeSigner(signer: Ed25519Account | PrivateKey | MnemonicAndPath): Ed25519Account; /** * Converts an account to an address string. * @implements {MoveSdkImpl<Ed25519Account>} * * @param {Ed25519Account} account - The account to convert. * @returns {string} The address of the account. */ accountToAddress(account: Ed25519Account): string; /** * Sends a transaction and waits for confirmation. * @implements {MoveSdkImpl<Ed25519Account>} * * @param {Ed25519Account | PrivateKey | MnemonicAndPath} signer - The signer of the transaction. * @param {MoveFunction} func - The function to call. * @param {EntryFunctionArgumentTypes[] | SimpleEntryFunctionArgumentTypes[]} args - The arguments for the function. * @param {string[]} [_] - Unused parameter. * @param {GasOptions} [gasOptions] - The gas options. * @param {string[]} [typeArguments] - The type arguments. * @returns {Promise<TransactionResponse>} The transaction response. */ sendAndConfirmTransaction(signer: Ed25519Account | PrivateKey | MnemonicAndPath, func: MoveFunction | ByteCode, args: EntryFunctionArgumentTypes[], _?: string[], gasOptions?: GasOptions, typeArguments?: string[]): Promise<TransactionResponse>; /** * Asserts that the given gas options are valid. * * @param {GasOptions} [gasOptions] - The gas options to validate. * @throws {Error} If the gas options are invalid. */ assertValidGasOptions(gasOptions?: GasOptions): void; /** * Estimates the gas required for a transaction. * * @param {Ed25519Account} signer - The signer of the transaction. * @param {InputGenerateTransactionPayloadData} payload - The payload of the transaction. * @returns {Promise<{ max_gas_amount: string; gas_unit_price: string }>} The estimated gas amount and gas unit price. */ estimateGas(signer: Ed25519Account, payload: InputGenerateTransactionPayloadData): Promise<{ max_gas_amount: string; gas_unit_price: string; }>; /** * Gets an account resource. * @implements {MoveSdkImpl<Ed25519Account>} * * @param {Object} args - The arguments for getting the account resource. * @param {AccountAddressInput} args.accountAddress - The account address. * @param {MoveStructId} args.resourceType - The type of the resource. * @param {LedgerVersionArg} [args.options] - The options for getting the resource. * @returns {Promise<T>} The account resource. * @template T - The type of the resource. * @throws {Error} If the request fails. */ getAccountResource<T extends NonNullable<unknown> = any>(args: { accountAddress: AccountAddressInput; resourceType: MoveStructId; options?: LedgerVersionArg; }): Promise<T>; /** * Gets a table item. * * @param {Object} args - The arguments for getting the table item. * @param {string} args.handle - The table handle. * @param {TableItemRequest} args.data - The key of the item. * @param {LedgerVersionArg} [args.options] - The options for getting the item. * @returns {Promise<T>} The table item. * @template T - The type of the item. * @throws {Error} If the request fails. */ getTableItem<T>(args: { handle: string; data: TableItemRequest; options?: LedgerVersionArg; }): Promise<T>; /** * Waits for a transaction to be confirmed and returns the transaction response. * * @param {string} txnHash - The hash of the transaction. * @returns {Promise<CommittedTransactionResponse>} The response of the committed transaction. * @throws {Error} If the transaction fails. * @private */ private waitAndGetTransaction; /** * Normalizes an address to a string. * @implements {MoveSdkImpl<Ed25519Account>} * * @param {string} address - The address to normalize. * @returns {string} The normalized address. */ normalizeAddress(address: string): string; /** * Checks if the SDK supports coins. * @implements {MoveSdkImpl<Ed25519Account>} * * @returns {boolean} True if the SDK supports coins, false otherwise. */ supportsCoin(): boolean; /** * Checks if the given address is a valid object address. * @param address */ isObjectAddress(address: string): Promise<boolean>; } export { COUNTER_V2_ADDRESS, DEPLOY_TO_OBJECT, DVN_301_ADDRESS, DVN_ADDRESS, DVN_FEE_LIB, DVN_UPGRADER_ADDRESS, ENDPOINT_V2_ADDRESS, ENDPOINT_V2_COMMON, EXECUTOR_ADDRESS, EXECUTOR_FEE_LIB, EXECUTOR_ULN301_ADDRESS, GAS_LIMIT_SAFETY_BPS, LAYERZERO_VIEWS_ADDRESS, OFT_ADDRESS, PRICE_FEED, SDK, SIMPLE_MESSAGE_LIB_ADDRESS, type SdkOptions, TREASURY_ADDRESS, ULN_MESSAGE_LIB_ADDRESS, WORKER_COMMON, applyGasLimitSafety, getSDKFromProvider };