From ad97943be70cfff608b47b9789b079a482628d2a Mon Sep 17 00:00:00 2001 From: Maayan Date: Thu, 18 May 2023 03:33:19 +0300 Subject: [PATCH] [TS SDK] Add TokenV2 Indexer queries (#8210) * add get account token query * add get account collection tokens * update changelog * add function comment * add function comment * fix lint * address feedback * update changelog * fix lint * typo * token ownership fields fragment --- ecosystem/typescript/sdk/CHANGELOG.md | 1 + .../sdk/src/indexer/generated/operations.ts | 30 + .../sdk/src/indexer/generated/queries.ts | 83 +++ .../sdk/src/indexer/generated/types.ts | 635 ++++++++++++++++++ ...urrentTokenOwnershipFieldsFragment.graphql | 37 + .../indexer/queries/getCollectionData.graphql | 11 + .../indexer/queries/getOwnedTokens.graphql | 10 + .../getTokenOwnedFromCollection.graphql | 14 + .../typescript/sdk/src/providers/indexer.ts | 147 +++- .../sdk/src/tests/e2e/indexer.test.ts | 91 ++- 10 files changed, 1053 insertions(+), 6 deletions(-) create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/getCollectionData.graphql create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql diff --git a/ecosystem/typescript/sdk/CHANGELOG.md b/ecosystem/typescript/sdk/CHANGELOG.md index 3a04c964fa8c1a..b38531f29d49db 100644 --- a/ecosystem/typescript/sdk/CHANGELOG.md +++ b/ecosystem/typescript/sdk/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to the Aptos Node SDK will be captured in this file. This ch - Fix get number of delegators Indexer query - Include static methods from `AptosClient` and `IndexerClient` classes in the `Provider` class +- Add Indexer queries for tokens - `getAccountTokens`, `getTokenOwnedFromCollectionAddress`, `getTokenOwnedFromCollectionNameAndCreatorAddress`, `getCollectionData`, `getCollectionAddress` ## 1.8.5 (2023-04-29) diff --git a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts index 862610156127c3..63fa1aeb5585eb 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts @@ -1,5 +1,7 @@ import * as Types from './types'; +export type CurrentTokenOwnershipFieldsFragment = { __typename?: 'current_token_ownerships_v2', token_standard: string, is_fungible_v2?: boolean | null, is_soulbound_v2?: boolean | null, property_version_v1: any, table_type_v1?: string | null, token_properties_mutated_v1?: any | null, amount: any, last_transaction_timestamp: any, last_transaction_version: any, storage_id: string, owner_address: string, current_token_data?: { __typename?: 'current_token_datas_v2', token_name: string, token_data_id: string, token_uri: string, token_properties: any, supply: any, maximum?: any | null, last_transaction_version: any, last_transaction_timestamp: any, largest_property_version_v1?: any | null, current_collection?: { __typename?: 'current_collections_v2', collection_name: string, creator_address: string, description: string, uri: string, collection_id: string, last_transaction_version: any, current_supply: any, mutable_description?: boolean | null, total_minted_v2?: any | null, table_handle_v1?: string | null, mutable_uri?: boolean | null } | null } | null }; + export type GetAccountCoinsDataQueryVariables = Types.Exact<{ owner_address?: Types.InputMaybe; offset?: Types.InputMaybe; @@ -45,6 +47,15 @@ export type GetAccountTransactionsDataQueryVariables = Types.Exact<{ export type GetAccountTransactionsDataQuery = { __typename?: 'query_root', move_resources: Array<{ __typename?: 'move_resources', transaction_version: any }> }; +export type GetCollectionDataQueryVariables = Types.Exact<{ + where_condition: Types.Current_Collections_V2_Bool_Exp; + offset?: Types.InputMaybe; + limit?: Types.InputMaybe; +}>; + + +export type GetCollectionDataQuery = { __typename?: 'query_root', current_collections_v2: Array<{ __typename?: 'current_collections_v2', collection_id: string, token_standard: string, collection_name: string, creator_address: string, current_supply: any, description: string, uri: string }> }; + export type GetDelegatedStakingActivitiesQueryVariables = Types.Exact<{ delegatorAddress?: Types.InputMaybe; poolAddress?: Types.InputMaybe; @@ -65,6 +76,15 @@ export type GetNumberOfDelegatorsQueryVariables = Types.Exact<{ export type GetNumberOfDelegatorsQuery = { __typename?: 'query_root', num_active_delegator_per_pool: Array<{ __typename?: 'num_active_delegator_per_pool', num_active_delegator?: any | null }> }; +export type GetOwnedTokensQueryVariables = Types.Exact<{ + address: Types.Scalars['String']; + offset?: Types.InputMaybe; + limit?: Types.InputMaybe; +}>; + + +export type GetOwnedTokensQuery = { __typename?: 'query_root', current_token_ownerships_v2: Array<{ __typename?: 'current_token_ownerships_v2', token_standard: string, is_fungible_v2?: boolean | null, is_soulbound_v2?: boolean | null, property_version_v1: any, table_type_v1?: string | null, token_properties_mutated_v1?: any | null, amount: any, last_transaction_timestamp: any, last_transaction_version: any, storage_id: string, owner_address: string, current_token_data?: { __typename?: 'current_token_datas_v2', token_name: string, token_data_id: string, token_uri: string, token_properties: any, supply: any, maximum?: any | null, last_transaction_version: any, last_transaction_timestamp: any, largest_property_version_v1?: any | null, current_collection?: { __typename?: 'current_collections_v2', collection_name: string, creator_address: string, description: string, uri: string, collection_id: string, last_transaction_version: any, current_supply: any, mutable_description?: boolean | null, total_minted_v2?: any | null, table_handle_v1?: string | null, mutable_uri?: boolean | null } | null } | null }> }; + export type GetTokenActivitiesQueryVariables = Types.Exact<{ idHash: Types.Scalars['String']; offset?: Types.InputMaybe; @@ -88,6 +108,16 @@ export type GetTokenDataQueryVariables = Types.Exact<{ export type GetTokenDataQuery = { __typename?: 'query_root', current_token_datas: Array<{ __typename?: 'current_token_datas', token_data_id_hash: string, name: string, collection_name: string, creator_address: string, default_properties: any, largest_property_version: any, maximum: any, metadata_uri: string, payee_address: string, royalty_points_denominator: any, royalty_points_numerator: any, supply: any }> }; +export type GetTokenOwnedFromCollectionQueryVariables = Types.Exact<{ + collection_id: Types.Scalars['String']; + owner_address: Types.Scalars['String']; + offset?: Types.InputMaybe; + limit?: Types.InputMaybe; +}>; + + +export type GetTokenOwnedFromCollectionQuery = { __typename?: 'query_root', current_token_ownerships_v2: Array<{ __typename?: 'current_token_ownerships_v2', token_standard: string, is_fungible_v2?: boolean | null, is_soulbound_v2?: boolean | null, property_version_v1: any, table_type_v1?: string | null, token_properties_mutated_v1?: any | null, amount: any, last_transaction_timestamp: any, last_transaction_version: any, storage_id: string, owner_address: string, current_token_data?: { __typename?: 'current_token_datas_v2', token_name: string, token_data_id: string, token_uri: string, token_properties: any, supply: any, maximum?: any | null, last_transaction_version: any, last_transaction_timestamp: any, largest_property_version_v1?: any | null, current_collection?: { __typename?: 'current_collections_v2', collection_name: string, creator_address: string, description: string, uri: string, collection_id: string, last_transaction_version: any, current_supply: any, mutable_description?: boolean | null, total_minted_v2?: any | null, table_handle_v1?: string | null, mutable_uri?: boolean | null } | null } | null }> }; + export type GetTokenOwnersDataQueryVariables = Types.Exact<{ token_id?: Types.InputMaybe; property_version?: Types.InputMaybe; diff --git a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts index 712d8514e81ea1..33d71de4a51848 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts @@ -2,6 +2,45 @@ import * as Types from './operations'; import { GraphQLClient } from 'graphql-request'; import * as Dom from 'graphql-request/dist/types.dom'; +export const CurrentTokenOwnershipFieldsFragmentDoc = ` + fragment CurrentTokenOwnershipFields on current_token_ownerships_v2 { + token_standard + is_fungible_v2 + is_soulbound_v2 + property_version_v1 + table_type_v1 + token_properties_mutated_v1 + amount + last_transaction_timestamp + last_transaction_version + storage_id + owner_address + current_token_data { + token_name + token_data_id + token_uri + token_properties + supply + maximum + last_transaction_version + last_transaction_timestamp + largest_property_version_v1 + current_collection { + collection_name + creator_address + description + uri + collection_id + last_transaction_version + current_supply + mutable_description + total_minted_v2 + table_handle_v1 + mutable_uri + } + } +} + `; export const TokenDataFieldsFragmentDoc = ` fragment TokenDataFields on current_token_datas { creator_address @@ -98,6 +137,19 @@ export const GetAccountTransactionsData = ` } } `; +export const GetCollectionData = ` + query getCollectionData($where_condition: current_collections_v2_bool_exp!, $offset: Int, $limit: Int) { + current_collections_v2(where: $where_condition, offset: $offset, limit: $limit) { + collection_id + token_standard + collection_name + creator_address + current_supply + description + uri + } +} + `; export const GetDelegatedStakingActivities = ` query getDelegatedStakingActivities($delegatorAddress: String, $poolAddress: String) { delegated_staking_activities( @@ -129,6 +181,17 @@ export const GetNumberOfDelegators = ` } } `; +export const GetOwnedTokens = ` + query getOwnedTokens($address: String!, $offset: Int, $limit: Int) { + current_token_ownerships_v2( + where: {owner_address: {_eq: $address}, amount: {_gt: 0}} + offset: $offset + limit: $limit + ) { + ...CurrentTokenOwnershipFields + } +} + ${CurrentTokenOwnershipFieldsFragmentDoc}`; export const GetTokenActivities = ` query getTokenActivities($idHash: String!, $offset: Int, $limit: Int) { token_activities( @@ -180,6 +243,17 @@ export const GetTokenData = ` } } `; +export const GetTokenOwnedFromCollection = ` + query getTokenOwnedFromCollection($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) { + current_token_ownerships_v2( + where: {owner_address: {_eq: $owner_address}, current_token_data: {collection_id: {_eq: $collection_id}}, amount: {_gt: 0}} + offset: $offset + limit: $limit + ) { + ...CurrentTokenOwnershipFields + } +} + ${CurrentTokenOwnershipFieldsFragmentDoc}`; export const GetTokenOwnersData = ` query getTokenOwnersData($token_id: String, $property_version: numeric) { current_token_ownerships( @@ -231,6 +305,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = getAccountTransactionsData(variables?: Types.GetAccountTransactionsDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountTransactionsData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountTransactionsData', 'query'); }, + getCollectionData(variables: Types.GetCollectionDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { + return withWrapper((wrappedRequestHeaders) => client.request(GetCollectionData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getCollectionData', 'query'); + }, getDelegatedStakingActivities(variables?: Types.GetDelegatedStakingActivitiesQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetDelegatedStakingActivities, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getDelegatedStakingActivities', 'query'); }, @@ -240,6 +317,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = getNumberOfDelegators(variables?: Types.GetNumberOfDelegatorsQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetNumberOfDelegators, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getNumberOfDelegators', 'query'); }, + getOwnedTokens(variables: Types.GetOwnedTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { + return withWrapper((wrappedRequestHeaders) => client.request(GetOwnedTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getOwnedTokens', 'query'); + }, getTokenActivities(variables: Types.GetTokenActivitiesQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetTokenActivities, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenActivities', 'query'); }, @@ -249,6 +329,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = getTokenData(variables?: Types.GetTokenDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetTokenData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenData', 'query'); }, + getTokenOwnedFromCollection(variables: Types.GetTokenOwnedFromCollectionQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { + return withWrapper((wrappedRequestHeaders) => client.request(GetTokenOwnedFromCollection, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenOwnedFromCollection', 'query'); + }, getTokenOwnersData(variables?: Types.GetTokenOwnersDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetTokenOwnersData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenOwnersData', 'query'); }, diff --git a/ecosystem/typescript/sdk/src/indexer/generated/types.ts b/ecosystem/typescript/sdk/src/indexer/generated/types.ts index 139263b3a709ac..dea693afaa9fc5 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/types.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/types.ts @@ -1092,6 +1092,122 @@ export type Current_Collection_Ownership_View_Stream_Cursor_Value_Input = { owner_address?: InputMaybe; }; +/** columns and relationships of "current_collections_v2" */ +export type Current_Collections_V2 = { + __typename?: 'current_collections_v2'; + collection_id: Scalars['String']; + collection_name: Scalars['String']; + creator_address: Scalars['String']; + current_supply: Scalars['numeric']; + description: Scalars['String']; + last_transaction_timestamp: Scalars['timestamp']; + last_transaction_version: Scalars['bigint']; + max_supply?: Maybe; + mutable_description?: Maybe; + mutable_uri?: Maybe; + table_handle_v1?: Maybe; + token_standard: Scalars['String']; + total_minted_v2?: Maybe; + uri: Scalars['String']; +}; + +/** Boolean expression to filter rows from the table "current_collections_v2". All fields are combined with a logical 'AND'. */ +export type Current_Collections_V2_Bool_Exp = { + _and?: InputMaybe>; + _not?: InputMaybe; + _or?: InputMaybe>; + collection_id?: InputMaybe; + collection_name?: InputMaybe; + creator_address?: InputMaybe; + current_supply?: InputMaybe; + description?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + max_supply?: InputMaybe; + mutable_description?: InputMaybe; + mutable_uri?: InputMaybe; + table_handle_v1?: InputMaybe; + token_standard?: InputMaybe; + total_minted_v2?: InputMaybe; + uri?: InputMaybe; +}; + +/** Ordering options when selecting data from "current_collections_v2". */ +export type Current_Collections_V2_Order_By = { + collection_id?: InputMaybe; + collection_name?: InputMaybe; + creator_address?: InputMaybe; + current_supply?: InputMaybe; + description?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + max_supply?: InputMaybe; + mutable_description?: InputMaybe; + mutable_uri?: InputMaybe; + table_handle_v1?: InputMaybe; + token_standard?: InputMaybe; + total_minted_v2?: InputMaybe; + uri?: InputMaybe; +}; + +/** select columns of table "current_collections_v2" */ +export enum Current_Collections_V2_Select_Column { + /** column name */ + CollectionId = 'collection_id', + /** column name */ + CollectionName = 'collection_name', + /** column name */ + CreatorAddress = 'creator_address', + /** column name */ + CurrentSupply = 'current_supply', + /** column name */ + Description = 'description', + /** column name */ + LastTransactionTimestamp = 'last_transaction_timestamp', + /** column name */ + LastTransactionVersion = 'last_transaction_version', + /** column name */ + MaxSupply = 'max_supply', + /** column name */ + MutableDescription = 'mutable_description', + /** column name */ + MutableUri = 'mutable_uri', + /** column name */ + TableHandleV1 = 'table_handle_v1', + /** column name */ + TokenStandard = 'token_standard', + /** column name */ + TotalMintedV2 = 'total_minted_v2', + /** column name */ + Uri = 'uri' +} + +/** Streaming cursor of the table "current_collections_v2" */ +export type Current_Collections_V2_Stream_Cursor_Input = { + /** Stream column input with initial value */ + initial_value: Current_Collections_V2_Stream_Cursor_Value_Input; + /** cursor ordering */ + ordering?: InputMaybe; +}; + +/** Initial value of the column from where the streaming should start */ +export type Current_Collections_V2_Stream_Cursor_Value_Input = { + collection_id?: InputMaybe; + collection_name?: InputMaybe; + creator_address?: InputMaybe; + current_supply?: InputMaybe; + description?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + max_supply?: InputMaybe; + mutable_description?: InputMaybe; + mutable_uri?: InputMaybe; + table_handle_v1?: InputMaybe; + token_standard?: InputMaybe; + total_minted_v2?: InputMaybe; + uri?: InputMaybe; +}; + /** columns and relationships of "current_delegator_balances" */ export type Current_Delegator_Balances = { __typename?: 'current_delegator_balances'; @@ -1470,6 +1586,126 @@ export type Current_Token_Datas_Stream_Cursor_Value_Input = { uri_mutable?: InputMaybe; }; +/** columns and relationships of "current_token_datas_v2" */ +export type Current_Token_Datas_V2 = { + __typename?: 'current_token_datas_v2'; + collection_id: Scalars['String']; + /** An object relationship */ + current_collection?: Maybe; + description: Scalars['String']; + is_fungible_v2?: Maybe; + largest_property_version_v1?: Maybe; + last_transaction_timestamp: Scalars['timestamp']; + last_transaction_version: Scalars['bigint']; + maximum?: Maybe; + supply: Scalars['numeric']; + token_data_id: Scalars['String']; + token_name: Scalars['String']; + token_properties: Scalars['jsonb']; + token_standard: Scalars['String']; + token_uri: Scalars['String']; +}; + + +/** columns and relationships of "current_token_datas_v2" */ +export type Current_Token_Datas_V2Token_PropertiesArgs = { + path?: InputMaybe; +}; + +/** Boolean expression to filter rows from the table "current_token_datas_v2". All fields are combined with a logical 'AND'. */ +export type Current_Token_Datas_V2_Bool_Exp = { + _and?: InputMaybe>; + _not?: InputMaybe; + _or?: InputMaybe>; + collection_id?: InputMaybe; + current_collection?: InputMaybe; + description?: InputMaybe; + is_fungible_v2?: InputMaybe; + largest_property_version_v1?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + maximum?: InputMaybe; + supply?: InputMaybe; + token_data_id?: InputMaybe; + token_name?: InputMaybe; + token_properties?: InputMaybe; + token_standard?: InputMaybe; + token_uri?: InputMaybe; +}; + +/** Ordering options when selecting data from "current_token_datas_v2". */ +export type Current_Token_Datas_V2_Order_By = { + collection_id?: InputMaybe; + current_collection?: InputMaybe; + description?: InputMaybe; + is_fungible_v2?: InputMaybe; + largest_property_version_v1?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + maximum?: InputMaybe; + supply?: InputMaybe; + token_data_id?: InputMaybe; + token_name?: InputMaybe; + token_properties?: InputMaybe; + token_standard?: InputMaybe; + token_uri?: InputMaybe; +}; + +/** select columns of table "current_token_datas_v2" */ +export enum Current_Token_Datas_V2_Select_Column { + /** column name */ + CollectionId = 'collection_id', + /** column name */ + Description = 'description', + /** column name */ + IsFungibleV2 = 'is_fungible_v2', + /** column name */ + LargestPropertyVersionV1 = 'largest_property_version_v1', + /** column name */ + LastTransactionTimestamp = 'last_transaction_timestamp', + /** column name */ + LastTransactionVersion = 'last_transaction_version', + /** column name */ + Maximum = 'maximum', + /** column name */ + Supply = 'supply', + /** column name */ + TokenDataId = 'token_data_id', + /** column name */ + TokenName = 'token_name', + /** column name */ + TokenProperties = 'token_properties', + /** column name */ + TokenStandard = 'token_standard', + /** column name */ + TokenUri = 'token_uri' +} + +/** Streaming cursor of the table "current_token_datas_v2" */ +export type Current_Token_Datas_V2_Stream_Cursor_Input = { + /** Stream column input with initial value */ + initial_value: Current_Token_Datas_V2_Stream_Cursor_Value_Input; + /** cursor ordering */ + ordering?: InputMaybe; +}; + +/** Initial value of the column from where the streaming should start */ +export type Current_Token_Datas_V2_Stream_Cursor_Value_Input = { + collection_id?: InputMaybe; + description?: InputMaybe; + is_fungible_v2?: InputMaybe; + largest_property_version_v1?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + maximum?: InputMaybe; + supply?: InputMaybe; + token_data_id?: InputMaybe; + token_name?: InputMaybe; + token_properties?: InputMaybe; + token_standard?: InputMaybe; + token_uri?: InputMaybe; +}; + /** columns and relationships of "current_token_ownerships" */ export type Current_Token_Ownerships = { __typename?: 'current_token_ownerships'; @@ -1774,6 +2010,242 @@ export type Current_Token_Ownerships_Sum_Order_By = { property_version?: InputMaybe; }; +/** columns and relationships of "current_token_ownerships_v2" */ +export type Current_Token_Ownerships_V2 = { + __typename?: 'current_token_ownerships_v2'; + amount: Scalars['numeric']; + /** An object relationship */ + current_token_data?: Maybe; + is_fungible_v2?: Maybe; + is_soulbound_v2?: Maybe; + last_transaction_timestamp: Scalars['timestamp']; + last_transaction_version: Scalars['bigint']; + owner_address: Scalars['String']; + property_version_v1: Scalars['numeric']; + storage_id: Scalars['String']; + table_type_v1?: Maybe; + token_data_id: Scalars['String']; + token_properties_mutated_v1?: Maybe; + token_standard: Scalars['String']; +}; + + +/** columns and relationships of "current_token_ownerships_v2" */ +export type Current_Token_Ownerships_V2Token_Properties_Mutated_V1Args = { + path?: InputMaybe; +}; + +/** aggregated selection of "current_token_ownerships_v2" */ +export type Current_Token_Ownerships_V2_Aggregate = { + __typename?: 'current_token_ownerships_v2_aggregate'; + aggregate?: Maybe; + nodes: Array; +}; + +/** aggregate fields of "current_token_ownerships_v2" */ +export type Current_Token_Ownerships_V2_Aggregate_Fields = { + __typename?: 'current_token_ownerships_v2_aggregate_fields'; + avg?: Maybe; + count: Scalars['Int']; + max?: Maybe; + min?: Maybe; + stddev?: Maybe; + stddev_pop?: Maybe; + stddev_samp?: Maybe; + sum?: Maybe; + var_pop?: Maybe; + var_samp?: Maybe; + variance?: Maybe; +}; + + +/** aggregate fields of "current_token_ownerships_v2" */ +export type Current_Token_Ownerships_V2_Aggregate_FieldsCountArgs = { + columns?: InputMaybe>; + distinct?: InputMaybe; +}; + +/** aggregate avg on columns */ +export type Current_Token_Ownerships_V2_Avg_Fields = { + __typename?: 'current_token_ownerships_v2_avg_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + +/** Boolean expression to filter rows from the table "current_token_ownerships_v2". All fields are combined with a logical 'AND'. */ +export type Current_Token_Ownerships_V2_Bool_Exp = { + _and?: InputMaybe>; + _not?: InputMaybe; + _or?: InputMaybe>; + amount?: InputMaybe; + current_token_data?: InputMaybe; + is_fungible_v2?: InputMaybe; + is_soulbound_v2?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + owner_address?: InputMaybe; + property_version_v1?: InputMaybe; + storage_id?: InputMaybe; + table_type_v1?: InputMaybe; + token_data_id?: InputMaybe; + token_properties_mutated_v1?: InputMaybe; + token_standard?: InputMaybe; +}; + +/** aggregate max on columns */ +export type Current_Token_Ownerships_V2_Max_Fields = { + __typename?: 'current_token_ownerships_v2_max_fields'; + amount?: Maybe; + last_transaction_timestamp?: Maybe; + last_transaction_version?: Maybe; + owner_address?: Maybe; + property_version_v1?: Maybe; + storage_id?: Maybe; + table_type_v1?: Maybe; + token_data_id?: Maybe; + token_standard?: Maybe; +}; + +/** aggregate min on columns */ +export type Current_Token_Ownerships_V2_Min_Fields = { + __typename?: 'current_token_ownerships_v2_min_fields'; + amount?: Maybe; + last_transaction_timestamp?: Maybe; + last_transaction_version?: Maybe; + owner_address?: Maybe; + property_version_v1?: Maybe; + storage_id?: Maybe; + table_type_v1?: Maybe; + token_data_id?: Maybe; + token_standard?: Maybe; +}; + +/** Ordering options when selecting data from "current_token_ownerships_v2". */ +export type Current_Token_Ownerships_V2_Order_By = { + amount?: InputMaybe; + current_token_data?: InputMaybe; + is_fungible_v2?: InputMaybe; + is_soulbound_v2?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + owner_address?: InputMaybe; + property_version_v1?: InputMaybe; + storage_id?: InputMaybe; + table_type_v1?: InputMaybe; + token_data_id?: InputMaybe; + token_properties_mutated_v1?: InputMaybe; + token_standard?: InputMaybe; +}; + +/** select columns of table "current_token_ownerships_v2" */ +export enum Current_Token_Ownerships_V2_Select_Column { + /** column name */ + Amount = 'amount', + /** column name */ + IsFungibleV2 = 'is_fungible_v2', + /** column name */ + IsSoulboundV2 = 'is_soulbound_v2', + /** column name */ + LastTransactionTimestamp = 'last_transaction_timestamp', + /** column name */ + LastTransactionVersion = 'last_transaction_version', + /** column name */ + OwnerAddress = 'owner_address', + /** column name */ + PropertyVersionV1 = 'property_version_v1', + /** column name */ + StorageId = 'storage_id', + /** column name */ + TableTypeV1 = 'table_type_v1', + /** column name */ + TokenDataId = 'token_data_id', + /** column name */ + TokenPropertiesMutatedV1 = 'token_properties_mutated_v1', + /** column name */ + TokenStandard = 'token_standard' +} + +/** aggregate stddev on columns */ +export type Current_Token_Ownerships_V2_Stddev_Fields = { + __typename?: 'current_token_ownerships_v2_stddev_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + +/** aggregate stddev_pop on columns */ +export type Current_Token_Ownerships_V2_Stddev_Pop_Fields = { + __typename?: 'current_token_ownerships_v2_stddev_pop_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + +/** aggregate stddev_samp on columns */ +export type Current_Token_Ownerships_V2_Stddev_Samp_Fields = { + __typename?: 'current_token_ownerships_v2_stddev_samp_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + +/** Streaming cursor of the table "current_token_ownerships_v2" */ +export type Current_Token_Ownerships_V2_Stream_Cursor_Input = { + /** Stream column input with initial value */ + initial_value: Current_Token_Ownerships_V2_Stream_Cursor_Value_Input; + /** cursor ordering */ + ordering?: InputMaybe; +}; + +/** Initial value of the column from where the streaming should start */ +export type Current_Token_Ownerships_V2_Stream_Cursor_Value_Input = { + amount?: InputMaybe; + is_fungible_v2?: InputMaybe; + is_soulbound_v2?: InputMaybe; + last_transaction_timestamp?: InputMaybe; + last_transaction_version?: InputMaybe; + owner_address?: InputMaybe; + property_version_v1?: InputMaybe; + storage_id?: InputMaybe; + table_type_v1?: InputMaybe; + token_data_id?: InputMaybe; + token_properties_mutated_v1?: InputMaybe; + token_standard?: InputMaybe; +}; + +/** aggregate sum on columns */ +export type Current_Token_Ownerships_V2_Sum_Fields = { + __typename?: 'current_token_ownerships_v2_sum_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + +/** aggregate var_pop on columns */ +export type Current_Token_Ownerships_V2_Var_Pop_Fields = { + __typename?: 'current_token_ownerships_v2_var_pop_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + +/** aggregate var_samp on columns */ +export type Current_Token_Ownerships_V2_Var_Samp_Fields = { + __typename?: 'current_token_ownerships_v2_var_samp_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + +/** aggregate variance on columns */ +export type Current_Token_Ownerships_V2_Variance_Fields = { + __typename?: 'current_token_ownerships_v2_variance_fields'; + amount?: Maybe; + last_transaction_version?: Maybe; + property_version_v1?: Maybe; +}; + /** aggregate var_pop on columns */ export type Current_Token_Ownerships_Var_Pop_Fields = { __typename?: 'current_token_ownerships_var_pop_fields'; @@ -2737,6 +3209,10 @@ export type Query_Root = { current_collection_datas_by_pk?: Maybe; /** fetch data from the table: "current_collection_ownership_view" */ current_collection_ownership_view: Array; + /** fetch data from the table: "current_collections_v2" */ + current_collections_v2: Array; + /** fetch data from the table: "current_collections_v2" using primary key columns */ + current_collections_v2_by_pk?: Maybe; /** fetch data from the table: "current_delegator_balances" */ current_delegator_balances: Array; /** fetch data from the table: "current_delegator_balances" using primary key columns */ @@ -2753,12 +3229,22 @@ export type Query_Root = { current_token_datas: Array; /** fetch data from the table: "current_token_datas" using primary key columns */ current_token_datas_by_pk?: Maybe; + /** fetch data from the table: "current_token_datas_v2" */ + current_token_datas_v2: Array; + /** fetch data from the table: "current_token_datas_v2" using primary key columns */ + current_token_datas_v2_by_pk?: Maybe; /** fetch data from the table: "current_token_ownerships" */ current_token_ownerships: Array; /** fetch aggregated fields from the table: "current_token_ownerships" */ current_token_ownerships_aggregate: Current_Token_Ownerships_Aggregate; /** fetch data from the table: "current_token_ownerships" using primary key columns */ current_token_ownerships_by_pk?: Maybe; + /** fetch data from the table: "current_token_ownerships_v2" */ + current_token_ownerships_v2: Array; + /** fetch aggregated fields from the table: "current_token_ownerships_v2" */ + current_token_ownerships_v2_aggregate: Current_Token_Ownerships_V2_Aggregate; + /** fetch data from the table: "current_token_ownerships_v2" using primary key columns */ + current_token_ownerships_v2_by_pk?: Maybe; /** fetch data from the table: "current_token_pending_claims" */ current_token_pending_claims: Array; /** fetch data from the table: "current_token_pending_claims" using primary key columns */ @@ -2978,6 +3464,20 @@ export type Query_RootCurrent_Collection_Ownership_ViewArgs = { }; +export type Query_RootCurrent_Collections_V2Args = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Query_RootCurrent_Collections_V2_By_PkArgs = { + collection_id: Scalars['String']; +}; + + export type Query_RootCurrent_Delegator_BalancesArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -3037,6 +3537,20 @@ export type Query_RootCurrent_Token_Datas_By_PkArgs = { }; +export type Query_RootCurrent_Token_Datas_V2Args = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Query_RootCurrent_Token_Datas_V2_By_PkArgs = { + token_data_id: Scalars['String']; +}; + + export type Query_RootCurrent_Token_OwnershipsArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -3062,6 +3576,32 @@ export type Query_RootCurrent_Token_Ownerships_By_PkArgs = { }; +export type Query_RootCurrent_Token_Ownerships_V2Args = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Query_RootCurrent_Token_Ownerships_V2_AggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Query_RootCurrent_Token_Ownerships_V2_By_PkArgs = { + owner_address: Scalars['String']; + property_version_v1: Scalars['numeric']; + storage_id: Scalars['String']; + token_data_id: Scalars['String']; +}; + + export type Query_RootCurrent_Token_Pending_ClaimsArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -3395,6 +3935,12 @@ export type Subscription_Root = { current_collection_ownership_view: Array; /** fetch data from the table in a streaming manner : "current_collection_ownership_view" */ current_collection_ownership_view_stream: Array; + /** fetch data from the table: "current_collections_v2" */ + current_collections_v2: Array; + /** fetch data from the table: "current_collections_v2" using primary key columns */ + current_collections_v2_by_pk?: Maybe; + /** fetch data from the table in a streaming manner : "current_collections_v2" */ + current_collections_v2_stream: Array; /** fetch data from the table: "current_delegator_balances" */ current_delegator_balances: Array; /** fetch data from the table: "current_delegator_balances" using primary key columns */ @@ -3419,6 +3965,12 @@ export type Subscription_Root = { current_token_datas_by_pk?: Maybe; /** fetch data from the table in a streaming manner : "current_token_datas" */ current_token_datas_stream: Array; + /** fetch data from the table: "current_token_datas_v2" */ + current_token_datas_v2: Array; + /** fetch data from the table: "current_token_datas_v2" using primary key columns */ + current_token_datas_v2_by_pk?: Maybe; + /** fetch data from the table in a streaming manner : "current_token_datas_v2" */ + current_token_datas_v2_stream: Array; /** fetch data from the table: "current_token_ownerships" */ current_token_ownerships: Array; /** fetch aggregated fields from the table: "current_token_ownerships" */ @@ -3427,6 +3979,14 @@ export type Subscription_Root = { current_token_ownerships_by_pk?: Maybe; /** fetch data from the table in a streaming manner : "current_token_ownerships" */ current_token_ownerships_stream: Array; + /** fetch data from the table: "current_token_ownerships_v2" */ + current_token_ownerships_v2: Array; + /** fetch aggregated fields from the table: "current_token_ownerships_v2" */ + current_token_ownerships_v2_aggregate: Current_Token_Ownerships_V2_Aggregate; + /** fetch data from the table: "current_token_ownerships_v2" using primary key columns */ + current_token_ownerships_v2_by_pk?: Maybe; + /** fetch data from the table in a streaming manner : "current_token_ownerships_v2" */ + current_token_ownerships_v2_stream: Array; /** fetch data from the table: "current_token_pending_claims" */ current_token_pending_claims: Array; /** fetch data from the table: "current_token_pending_claims" using primary key columns */ @@ -3757,6 +4317,27 @@ export type Subscription_RootCurrent_Collection_Ownership_View_StreamArgs = { }; +export type Subscription_RootCurrent_Collections_V2Args = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Subscription_RootCurrent_Collections_V2_By_PkArgs = { + collection_id: Scalars['String']; +}; + + +export type Subscription_RootCurrent_Collections_V2_StreamArgs = { + batch_size: Scalars['Int']; + cursor: Array>; + where?: InputMaybe; +}; + + export type Subscription_RootCurrent_Delegator_BalancesArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -3844,6 +4425,27 @@ export type Subscription_RootCurrent_Token_Datas_StreamArgs = { }; +export type Subscription_RootCurrent_Token_Datas_V2Args = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Subscription_RootCurrent_Token_Datas_V2_By_PkArgs = { + token_data_id: Scalars['String']; +}; + + +export type Subscription_RootCurrent_Token_Datas_V2_StreamArgs = { + batch_size: Scalars['Int']; + cursor: Array>; + where?: InputMaybe; +}; + + export type Subscription_RootCurrent_Token_OwnershipsArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -3876,6 +4478,39 @@ export type Subscription_RootCurrent_Token_Ownerships_StreamArgs = { }; +export type Subscription_RootCurrent_Token_Ownerships_V2Args = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Subscription_RootCurrent_Token_Ownerships_V2_AggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +export type Subscription_RootCurrent_Token_Ownerships_V2_By_PkArgs = { + owner_address: Scalars['String']; + property_version_v1: Scalars['numeric']; + storage_id: Scalars['String']; + token_data_id: Scalars['String']; +}; + + +export type Subscription_RootCurrent_Token_Ownerships_V2_StreamArgs = { + batch_size: Scalars['Int']; + cursor: Array>; + where?: InputMaybe; +}; + + export type Subscription_RootCurrent_Token_Pending_ClaimsArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; diff --git a/ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql b/ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql new file mode 100644 index 00000000000000..07f6651851250f --- /dev/null +++ b/ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql @@ -0,0 +1,37 @@ +fragment CurrentTokenOwnershipFields on current_token_ownerships_v2 { + token_standard + is_fungible_v2 + is_soulbound_v2 + property_version_v1 + table_type_v1 + token_properties_mutated_v1 + amount + last_transaction_timestamp + last_transaction_version + storage_id + owner_address + current_token_data { + token_name + token_data_id + token_uri + token_properties + supply + maximum + last_transaction_version + last_transaction_timestamp + largest_property_version_v1 + current_collection { + collection_name + creator_address + description + uri + collection_id + last_transaction_version + current_supply + mutable_description + total_minted_v2 + table_handle_v1 + mutable_uri + } + } +} diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getCollectionData.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getCollectionData.graphql new file mode 100644 index 00000000000000..066f5871e75156 --- /dev/null +++ b/ecosystem/typescript/sdk/src/indexer/queries/getCollectionData.graphql @@ -0,0 +1,11 @@ +query getCollectionData($where_condition: current_collections_v2_bool_exp!, $offset: Int, $limit: Int) { + current_collections_v2(where: $where_condition, offset: $offset, limit: $limit) { + collection_id + token_standard + collection_name + creator_address + current_supply + description + uri + } +} diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql new file mode 100644 index 00000000000000..1920e431db6bc8 --- /dev/null +++ b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql @@ -0,0 +1,10 @@ +#import "./CurrentTokenOwnershipFieldsFragment"; +query getOwnedTokens($address: String!, $offset: Int, $limit: Int) { + current_token_ownerships_v2( + where: { owner_address: { _eq: $address }, amount: { _gt: 0 } } + offset: $offset + limit: $limit + ) { + ...CurrentTokenOwnershipFields + } +} diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql new file mode 100644 index 00000000000000..978fa420c16ddd --- /dev/null +++ b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql @@ -0,0 +1,14 @@ +#import "./CurrentTokenOwnershipFieldsFragment"; +query getTokenOwnedFromCollection($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) { + current_token_ownerships_v2( + where: { + owner_address: { _eq: $owner_address } + current_token_data: { collection_id: { _eq: $collection_id } } + amount: { _gt: 0 } + } + offset: $offset + limit: $limit + ) { + ...CurrentTokenOwnershipFields + } +} diff --git a/ecosystem/typescript/sdk/src/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index 212dac80bb8960..6f7d3a21468de9 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -17,6 +17,9 @@ import { GetTokenOwnersDataQuery, GetTopUserTransactionsQuery, GetUserTransactionsQuery, + GetOwnedTokensQuery, + GetTokenOwnedFromCollectionQuery, + GetCollectionDataQuery, } from "../indexer/generated/operations"; import { GetAccountTokensCount, @@ -33,6 +36,9 @@ import { GetTokenOwnersData, GetTopUserTransactions, GetUserTransactions, + GetOwnedTokens, + GetTokenOwnedFromCollection, + GetCollectionData, } from "../indexer/generated/queries"; /** @@ -48,6 +54,8 @@ interface PaginationArgs { limit?: number; } +type TokenStandard = "v1" | "v2"; + type GraphqlQuery = { query: string; variables?: {}; @@ -74,7 +82,7 @@ export class IndexerClient { */ static validateAddress(address: string): void { if (address.length < 66) { - throw new Error("Address needs to be 66 chars long."); + throw new Error(`${address} is less than 66 chars long.`); } } @@ -310,4 +318,141 @@ export class IndexerClient { }; return this.queryIndexer(graphqlQuery); } + + /** + * Queries account's current owned tokens. + * This query returns all tokens (v1 and v2 standards) an account owns, including NFTs, fungible, soulbound, etc. + * + * @param ownerAddress The token owner address we want to get the tokens for + * @returns GetOwnedTokensQuery response type + */ + async getOwnedTokens( + ownerAddress: MaybeHexString, + extraArgs?: { + options?: PaginationArgs; + }, + ): Promise { + const address = HexString.ensure(ownerAddress).hex(); + IndexerClient.validateAddress(address); + const graphqlQuery = { + query: GetOwnedTokens, + variables: { address, offset: extraArgs?.options?.offset, limit: extraArgs?.options?.limit }, + }; + return this.queryIndexer(graphqlQuery); + } + + /** + * Queries all tokens of a specific collection that an account owns by the collection address + * + * @param ownerAddress owner address that owns the tokens + * @param collectionAddress the collection address + * @returns GetTokenOwnedFromCollectionQuery response type + */ + async getTokenOwnedFromCollectionAddress( + ownerAddress: MaybeHexString, + collectionAddress: string, + extraArgs?: { + tokenStandard?: TokenStandard; + options?: PaginationArgs; + }, + ): Promise { + const ownerHexAddress = HexString.ensure(ownerAddress).hex(); + IndexerClient.validateAddress(ownerHexAddress); + + const collectionHexAddress = HexString.ensure(collectionAddress).hex(); + IndexerClient.validateAddress(collectionHexAddress); + + const graphqlQuery = { + query: GetTokenOwnedFromCollection, + variables: { + collection_id: collectionHexAddress, + owner_address: ownerHexAddress, + offset: extraArgs?.options?.offset, + limit: extraArgs?.options?.limit, + }, + }; + return this.queryIndexer(graphqlQuery); + } + + /** + * Queries all tokens of a specific collection that an account owns by the collection name and collection + * creator address + * + * @param ownerAddress owner address that owns the tokens + * @param collectionName the collection name + * @param creatorAddress the collection creator address + * @returns GetTokenOwnedFromCollectionQuery response type + */ + async getTokenOwnedFromCollectionNameAndCreatorAddress( + ownerAddress: MaybeHexString, + collectionName: string, + creatorAddress: MaybeHexString, + extraArgs?: { + tokenStandard?: TokenStandard; + options?: PaginationArgs; + }, + ): Promise { + const collectionAddress = await this.getCollectionAddress(creatorAddress, collectionName, extraArgs); + const tokens = await this.getTokenOwnedFromCollectionAddress(ownerAddress, collectionAddress, extraArgs); + return tokens; + } + + /** + * Queries data of a specific collection by the collection creator address and the collection name. + * + * if, for some reason, a creator account has 2 collections with the same name in v1 and v2, + * can pass an optional `tokenStandard` parameter to query a specific standard + * + * @param creatorAddress the collection creator address + * @param collectionName the collection name + * @returns GetCollectionDataQuery response type + */ + async getCollectionData( + creatorAddress: MaybeHexString, + collectionName: string, + extraArgs?: { + tokenStandard?: TokenStandard; + options?: PaginationArgs; + }, + ): Promise { + const address = HexString.ensure(creatorAddress).hex(); + IndexerClient.validateAddress(address); + + const whereCondition: any = { + collection_name: { _eq: collectionName }, + creator_address: { _eq: address }, + }; + + if (extraArgs?.tokenStandard) { + whereCondition.token_standard = { _eq: extraArgs?.tokenStandard }; + } + + const graphqlQuery = { + query: GetCollectionData, + variables: { + where_condition: whereCondition, + offset: extraArgs?.options?.offset, + limit: extraArgs?.options?.limit, + }, + }; + return this.queryIndexer(graphqlQuery); + } + + /** + * Queries a collection address. + * + * @param creatorAddress the collection creator address + * @param collectionName the collection name + * @returns the collection address + */ + async getCollectionAddress( + creatorAddress: MaybeHexString, + collectionName: string, + extraArgs?: { + tokenStandard?: TokenStandard; + }, + ): Promise { + return (await this.getCollectionData(creatorAddress, collectionName, extraArgs)).current_collections_v2[0] + .collection_id; + } } diff --git a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts index c2a5ade15faf85..a448492f8f94a6 100644 --- a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts +++ b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts @@ -6,16 +6,20 @@ import { IndexerClient } from "../../providers/indexer"; import { TokenClient } from "../../plugins/token_client"; import { FAUCET_AUTH_TOKEN, longTestTimeout } from "../unit/test_helper.test"; import { Network, NetworkToIndexerAPI, NetworkToNodeAPI, sleep } from "../../utils"; +import { Provider } from "../../providers"; +import { AptosToken } from "../../plugins"; -const aptosClient = new AptosClient(NetworkToNodeAPI[Network.TESTNET]); +const provider = new Provider(Network.TESTNET); +const aptosToken = new AptosToken(provider); const faucetClient = new FaucetClient( "https://fullnode.testnet.aptoslabs.com", "https://faucet.testnet.aptoslabs.com", { TOKEN: FAUCET_AUTH_TOKEN }, ); -const tokenClient = new TokenClient(aptosClient); +const tokenClient = new TokenClient(provider.aptosClient); const alice = new AptosAccount(); const collectionName = "AliceCollection"; +const collectionNameV2 = "AliceCollection2"; const tokenName = "Alice Token"; const indexerClient = new IndexerClient(NetworkToIndexerAPI[Network.TESTNET]); @@ -39,11 +43,11 @@ describe("Indexer", () => { beforeAll(async () => { await faucetClient.fundAccount(alice.address(), 100000000); // Create collection and token on Alice's account - await aptosClient.waitForTransaction( + await provider.waitForTransaction( await tokenClient.createCollection(alice, collectionName, "Alice's simple collection", "https://aptos.dev"), { checkSuccess: true }, ); - await aptosClient.waitForTransaction( + await provider.waitForTransaction( await tokenClient.createTokenWithMutabilityConfig( alice, collectionName, @@ -62,6 +66,28 @@ describe("Indexer", () => { ), { checkSuccess: true }, ); + + await provider.waitForTransaction( + await aptosToken.createCollection(alice, "Alice's simple collection", collectionNameV2, "https://aptos.dev", 5, { + royaltyNumerator: 10, + royaltyDenominator: 10, + }), + { checkSuccess: true }, + ); + + await provider.waitForTransactionWithResult( + await aptosToken.mint( + alice, + collectionNameV2, + "Alice's simple token", + tokenName, + "https://aptos.dev/img/nyan.jpeg", + ["key"], + ["bool"], + ["true"], + ), + { checkSuccess: true }, + ); }, longTestTimeout); describe("get data", () => { @@ -117,7 +143,7 @@ describe("Indexer", () => { "gets account transactions count", async () => { const accountTransactionsCount = await indexerClient.getAccountTransactionsCount(alice.address().hex()); - expect(accountTransactionsCount.move_resources_aggregate.aggregate?.count).toEqual(3); + expect(accountTransactionsCount.move_resources_aggregate.aggregate?.count).toEqual(5); }, longTestTimeout, ); @@ -200,5 +226,60 @@ describe("Indexer", () => { const ledgerInfo = await indexerClient.getIndexerLedgerInfo(); expect(ledgerInfo.ledger_infos[0].chain_id).toBeGreaterThan(1); }); + + it("gets account current tokens", async () => { + const tokens = await indexerClient.getOwnedTokens(alice.address().hex()); + expect(tokens.current_token_ownerships_v2).toHaveLength(2); + }); + + it("gets the collection data", async () => { + const collectionData = await indexerClient.getCollectionData(alice.address().hex(), collectionName); + expect(collectionData.current_collections_v2).toHaveLength(1); + expect(collectionData.current_collections_v2[0].collection_name).toEqual(collectionName); + }); + + it("gets the currect collection address", async () => { + const collectionData = await indexerClient.getCollectionData(alice.address().hex(), collectionNameV2); + const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionNameV2); + expect(collectionData.current_collections_v2[0].collection_id).toEqual(collectionAddress); + }); + + it( + "gets account current tokens of a specific collection by the collection address with token standard specified", + async () => { + const tokens = await indexerClient.getTokenOwnedFromCollectionNameAndCreatorAddress( + alice.address().hex(), + collectionNameV2, + alice.address().hex(), + { + tokenStandard: "v2", + }, + ); + expect(tokens.current_token_ownerships_v2).toHaveLength(1); + expect(tokens.current_token_ownerships_v2[0].token_standard).toEqual("v2"); + }, + longTestTimeout, + ); + + it( + "returns same result for getTokenOwnedFromCollectionNameAndCreatorAddress and getTokenOwnedFromCollectionAddress", + async () => { + const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionNameV2); + const tokensFromCollectionAddress = await indexerClient.getTokenOwnedFromCollectionAddress( + alice.address().hex(), + collectionAddress, + ); + const tokensFromNameAndCreatorAddress = await indexerClient.getTokenOwnedFromCollectionNameAndCreatorAddress( + alice.address().hex(), + collectionNameV2, + alice.address().hex(), + ); + + expect(tokensFromCollectionAddress.current_token_ownerships_v2).toEqual( + tokensFromNameAndCreatorAddress.current_token_ownerships_v2, + ); + }, + longTestTimeout, + ); }); });