{"version":3,"sources":["../../src/api/fungibleAsset.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n  AnyNumber,\n  GetCurrentFungibleAssetBalancesResponse,\n  GetFungibleAssetActivitiesResponse,\n  GetFungibleAssetMetadataResponse,\n  PaginationArgs,\n  WhereArg,\n} from \"../types\";\nimport {\n  getCurrentFungibleAssetBalances,\n  getFungibleAssetActivities,\n  getFungibleAssetMetadata,\n  transferFungibleAsset,\n} from \"../internal/fungibleAsset\";\nimport {\n  CurrentFungibleAssetBalancesBoolExp,\n  FungibleAssetActivitiesBoolExp,\n  FungibleAssetMetadataBoolExp,\n} from \"../types/generated/types\";\nimport { ProcessorType } from \"../utils/const\";\nimport { AptosConfig } from \"./aptosConfig\";\nimport { waitForIndexerOnVersion } from \"./utils\";\nimport { Account } from \"../account\";\nimport { AccountAddressInput } from \"../core\";\nimport { InputGenerateTransactionOptions } from \"../transactions\";\nimport { SimpleTransaction } from \"../transactions/instances/simpleTransaction\";\n\n/**\n * A class to query all `FungibleAsset` related queries on Aptos.\n */\nexport class FungibleAsset {\n  constructor(readonly config: AptosConfig) {}\n\n  /**\n   * Queries all fungible asset metadata.\n   *\n   * @example\n   * const fungibleAsset = await aptos.getFungibleAssetMetadata()\n   *\n   * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n   * @param args.options Optional configuration for pagination and filtering\n   *\n   * @returns A list of fungible asset metadata\n   */\n  async getFungibleAssetMetadata(args?: {\n    minimumLedgerVersion?: AnyNumber;\n    options?: PaginationArgs & WhereArg<FungibleAssetMetadataBoolExp>;\n  }): Promise<GetFungibleAssetMetadataResponse> {\n    await waitForIndexerOnVersion({\n      config: this.config,\n      minimumLedgerVersion: args?.minimumLedgerVersion,\n      processorType: ProcessorType.FUNGIBLE_ASSET_PROCESSOR,\n    });\n    return getFungibleAssetMetadata({ aptosConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries a fungible asset metadata\n   *\n   * This query returns the fungible asset metadata for a specific fungible asset.\n   *\n   * @example\n   * const fungibleAsset = await aptos.getFungibleAssetMetadataByAssetType({assetType:\"0x123::test_coin::TestCoin\"})\n   *\n   * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n   * @param args.assetType The asset type of the fungible asset.\n   * e.g\n   * \"0x1::aptos_coin::AptosCoin\" for Aptos Coin\n   * \"0xc2948283c2ce03aafbb294821de7ee684b06116bb378ab614fa2de07a99355a8\" - address format if this is fungible asset\n   *\n   * @returns A fungible asset metadata item\n   */\n  async getFungibleAssetMetadataByAssetType(args: {\n    assetType: string;\n    minimumLedgerVersion?: AnyNumber;\n  }): Promise<GetFungibleAssetMetadataResponse[0]> {\n    await waitForIndexerOnVersion({\n      config: this.config,\n      minimumLedgerVersion: args?.minimumLedgerVersion,\n      processorType: ProcessorType.FUNGIBLE_ASSET_PROCESSOR,\n    });\n    const data = await getFungibleAssetMetadata({\n      aptosConfig: this.config,\n      options: {\n        where: {\n          asset_type: { _eq: args.assetType },\n        },\n      },\n    });\n\n    return data[0];\n  }\n\n  /**\n   * Queries all fungible asset activities\n   *\n   * @example\n   * const fungibleAssetActivities = await aptos.getFungibleAssetActivities()\n   *\n   * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n   * @param args.options Optional configuration for pagination and filtering\n   *\n   * @returns A list of fungible asset metadata\n   */\n  async getFungibleAssetActivities(args?: {\n    minimumLedgerVersion?: AnyNumber;\n    options?: PaginationArgs & WhereArg<FungibleAssetActivitiesBoolExp>;\n  }): Promise<GetFungibleAssetActivitiesResponse> {\n    await waitForIndexerOnVersion({\n      config: this.config,\n      minimumLedgerVersion: args?.minimumLedgerVersion,\n      processorType: ProcessorType.FUNGIBLE_ASSET_PROCESSOR,\n    });\n    return getFungibleAssetActivities({ aptosConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries all fungible asset balances\n   *\n   * @example\n   * const fungibleAssetBalances = await aptos.getCurrentFungibleAssetBalances()\n   *\n   * @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying\n   * @param args.options Optional configuration for pagination and filtering\n   *\n   * @returns A list of fungible asset metadata\n   */\n  async getCurrentFungibleAssetBalances(args?: {\n    minimumLedgerVersion?: AnyNumber;\n    options?: PaginationArgs & WhereArg<CurrentFungibleAssetBalancesBoolExp>;\n  }): Promise<GetCurrentFungibleAssetBalancesResponse> {\n    await waitForIndexerOnVersion({\n      config: this.config,\n      minimumLedgerVersion: args?.minimumLedgerVersion,\n      processorType: ProcessorType.FUNGIBLE_ASSET_PROCESSOR,\n    });\n    return getCurrentFungibleAssetBalances({ aptosConfig: this.config, ...args });\n  }\n\n  /**\n   * Transfer `amount` of fungible asset from sender's primary store to recipient's primary store.\n   *\n   * Use this method to transfer any fungible asset including fungible token.\n   *\n   * @example\n   * const transaction = await aptos.transferFungibleAsset({\n   *  sender: alice,\n   *  fungibleAssetMetadataAddress: \"0x123\",\n   *  recipient: \"0x456\",\n   *  amount: 5\n   * })\n   *\n   * @param sender The sender account\n   * @param fungibleAssetMetadataAddress The fungible asset account address.\n   * For example if you’re transferring USDT this would be the USDT address\n   * @param recipient The recipient account address\n   * @param amount Number of assets to transfer\n   *\n   * @returns A SimpleTransaction that can be simulated or submitted to chain.\n   */\n  async transferFungibleAsset(args: {\n    sender: Account;\n    fungibleAssetMetadataAddress: AccountAddressInput;\n    recipient: AccountAddressInput;\n    amount: AnyNumber;\n    options?: InputGenerateTransactionOptions;\n  }): Promise<SimpleTransaction> {\n    return transferFungibleAsset({ aptosConfig: this.config, ...args });\n  }\n}\n"],"mappings":"uGAiCO,IAAMA,EAAN,KAAoB,CACzB,YAAqBC,EAAqB,CAArB,YAAAA,CAAsB,CAa3C,MAAM,yBAAyBC,EAGe,CAC5C,aAAMC,EAAwB,CAC5B,OAAQ,KAAK,OACb,qBAAsBD,GAAM,qBAC5B,wCACF,CAAC,EACME,EAAyB,CAAE,YAAa,KAAK,OAAQ,GAAGF,CAAK,CAAC,CACvE,CAkBA,MAAM,oCAAoCA,EAGO,CAC/C,aAAMC,EAAwB,CAC5B,OAAQ,KAAK,OACb,qBAAsBD,GAAM,qBAC5B,wCACF,CAAC,GACY,MAAME,EAAyB,CAC1C,YAAa,KAAK,OAClB,QAAS,CACP,MAAO,CACL,WAAY,CAAE,IAAKF,EAAK,SAAU,CACpC,CACF,CACF,CAAC,GAEW,CAAC,CACf,CAaA,MAAM,2BAA2BA,EAGe,CAC9C,aAAMC,EAAwB,CAC5B,OAAQ,KAAK,OACb,qBAAsBD,GAAM,qBAC5B,wCACF,CAAC,EACMG,EAA2B,CAAE,YAAa,KAAK,OAAQ,GAAGH,CAAK,CAAC,CACzE,CAaA,MAAM,gCAAgCA,EAGe,CACnD,aAAMC,EAAwB,CAC5B,OAAQ,KAAK,OACb,qBAAsBD,GAAM,qBAC5B,wCACF,CAAC,EACMI,EAAgC,CAAE,YAAa,KAAK,OAAQ,GAAGJ,CAAK,CAAC,CAC9E,CAuBA,MAAM,sBAAsBA,EAMG,CAC7B,OAAOK,EAAsB,CAAE,YAAa,KAAK,OAAQ,GAAGL,CAAK,CAAC,CACpE,CACF","names":["FungibleAsset","config","args","waitForIndexerOnVersion","getFungibleAssetMetadata","getFungibleAssetActivities","getCurrentFungibleAssetBalances","transferFungibleAsset"]}