@aptos-labs/ts-sdk
Version:
Aptos TypeScript SDK
155 lines • 7.01 kB
JavaScript
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0
import { queryIndexer } from "./general.js";
import { GetCurrentFungibleAssetBalances, GetFungibleAssetActivities, GetFungibleAssetMetadata, } from "../types/generated/queries.js";
import { parseTypeTag, TypeTagAddress, TypeTagU64, } from "../transactions/index.js";
import { generateTransaction } from "./transactionSubmission.js";
/**
* Retrieves metadata for fungible assets based on specified criteria.
* This function allows you to filter and paginate through fungible asset metadata.
*
* @param args - The arguments for the function.
* @param args.aptosConfig - The configuration for Aptos.
* @param [args.options] - Optional parameters for pagination and filtering.
* @param [args.options.limit] - The maximum number of results to return.
* @param [args.options.offset] - The number of results to skip before starting to collect the result set.
* @param [args.options.where] - Conditions to filter the results.
* @group Implementation
*/
export async function getFungibleAssetMetadata(args) {
const { aptosConfig, options } = args;
const graphqlQuery = {
query: GetFungibleAssetMetadata,
variables: {
where_condition: options?.where,
limit: options?.limit,
offset: options?.offset,
},
};
const data = await queryIndexer({
aptosConfig,
query: graphqlQuery,
originMethod: "getFungibleAssetMetadata",
});
return data.fungible_asset_metadata;
}
/**
* Retrieves the activities associated with fungible assets.
* This function allows you to filter and paginate through the activities based on specified conditions.
*
* @param args - The arguments for retrieving fungible asset activities.
* @param args.aptosConfig - The configuration settings for Aptos.
* @param [args.options] - Optional parameters for pagination and filtering.
* @param [args.options.limit] - The maximum number of activities to retrieve.
* @param [args.options.offset] - The number of activities to skip before starting to collect the result set.
* @param [args.options.where] - Conditions to filter the activities.
* @returns A promise that resolves to an array of fungible asset activities.
* @group Implementation
*/
export async function getFungibleAssetActivities(args) {
const { aptosConfig, options } = args;
const graphqlQuery = {
query: GetFungibleAssetActivities,
variables: {
where_condition: options?.where,
limit: options?.limit,
offset: options?.offset,
},
};
const data = await queryIndexer({
aptosConfig,
query: graphqlQuery,
originMethod: "getFungibleAssetActivities",
});
return data.fungible_asset_activities;
}
/**
* Retrieves the current balances of fungible assets for a specified configuration.
*
* @param args - The arguments for retrieving fungible asset balances.
* @param args.aptosConfig - The configuration settings for Aptos.
* @param args.options - Optional parameters for pagination and filtering.
* @param args.options.limit - The maximum number of results to return.
* @param args.options.offset - The number of results to skip before starting to collect the results.
* @param args.options.where - Conditions to filter the results based on specific criteria.
* @returns The current balances of fungible assets.
* @group Implementation
*/
export async function getCurrentFungibleAssetBalances(args) {
const { aptosConfig, options } = args;
const graphqlQuery = {
query: GetCurrentFungibleAssetBalances,
variables: {
where_condition: options?.where,
limit: options?.limit,
offset: options?.offset,
},
};
const data = await queryIndexer({
aptosConfig,
query: graphqlQuery,
originMethod: "getCurrentFungibleAssetBalances",
});
return data.current_fungible_asset_balances;
}
const faTransferAbi = {
typeParameters: [{ constraints: [] }],
parameters: [parseTypeTag("0x1::object::Object"), new TypeTagAddress(), new TypeTagU64()],
};
/**
* Transfers a specified amount of a fungible asset from the sender to the recipient.
* This function helps facilitate the transfer of digital assets between accounts on the Aptos blockchain.
*
* @param args - The parameters for the transfer operation.
* @param args.aptosConfig - The configuration settings for the Aptos network.
* @param args.sender - The account initiating the transfer.
* @param args.fungibleAssetMetadataAddress - The address of the fungible asset's metadata.
* @param args.recipient - The address of the account receiving the asset.
* @param args.amount - The amount of the fungible asset to transfer.
* @param args.options - Optional settings for generating the transaction.
* @group Implementation
*/
export async function transferFungibleAsset(args) {
const { aptosConfig, sender, fungibleAssetMetadataAddress, recipient, amount, options } = args;
return generateTransaction({
aptosConfig,
sender: sender.accountAddress,
data: {
function: "0x1::primary_fungible_store::transfer",
typeArguments: ["0x1::fungible_asset::Metadata"],
functionArguments: [fungibleAssetMetadataAddress, recipient, amount],
abi: faTransferAbi,
},
options,
});
}
/**
* Transfers a specified amount of a fungible asset from any (primary or secondary) fungible store to any (primary or secondary) fungible store.
* This function helps facilitate the transfer of digital assets between fungible stores on the Aptos blockchain.
*
* @param args - The parameters for the transfer operation.
* @param args.aptosConfig - The configuration settings for the Aptos network.
* @param args.sender - The account initiating the transfer.
* @param args.fromStore - The address of the fungible store initiating the transfer.
* @param args.toStore - The address of the fungible store receiving the asset.
* @param args.amount - The amount of the fungible asset to transfer. Must be a positive number.
* @param args.options - Optional settings for generating the transaction.
* @returns A SimpleTransaction that can be submitted to the blockchain.
* @throws Error if the transaction generation fails or if the input parameters are invalid.
* @group Implementation
*/
export async function transferFungibleAssetBetweenStores(args) {
const { aptosConfig, sender, fromStore, toStore, amount, options } = args;
return generateTransaction({
aptosConfig,
sender: sender.accountAddress,
data: {
function: "0x1::dispatchable_fungible_asset::transfer",
typeArguments: ["0x1::fungible_asset::FungibleStore"],
functionArguments: [fromStore, toStore, amount],
abi: faTransferAbi,
},
options,
});
}
//# sourceMappingURL=fungibleAsset.js.map