From 1bf7cdfa2f9f3e963856b3cb16a660eefd18de1d Mon Sep 17 00:00:00 2001 From: maayan Date: Fri, 12 May 2023 10:45:21 -0700 Subject: [PATCH 01/11] add get account token query --- .../sdk/src/indexer/generated/operations.ts | 9 + .../sdk/src/indexer/generated/queries.ts | 49 ++ .../sdk/src/indexer/generated/types.ts | 635 ++++++++++++++++++ .../queries/getAccountCurrentTokensv2.graphql | 44 ++ .../typescript/sdk/src/providers/indexer.ts | 18 + 5 files changed, 755 insertions(+) create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/getAccountCurrentTokensv2.graphql diff --git a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts index 862610156127c..8f758f561e5c4 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts @@ -22,6 +22,15 @@ export type TokenDataFieldsFragment = { __typename?: 'current_token_datas', crea export type CollectionDataFieldsFragment = { __typename?: 'current_collection_datas', metadata_uri: string, supply: any, description: string, collection_name: string, collection_data_id_hash: string, table_handle: string, creator_address: string }; +export type GetAccountTokensQueryVariables = Types.Exact<{ + address: Types.Scalars['String']; + offset?: Types.InputMaybe; + limit?: Types.InputMaybe; +}>; + + +export type GetAccountTokensQuery = { __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 GetAccountTokensCountQueryVariables = Types.Exact<{ owner_address?: Types.InputMaybe; }>; diff --git a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts index 712d8514e81ea..7f1fe8bdb2aa4 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts @@ -62,6 +62,52 @@ export const GetAccountCurrentTokens = ` } ${TokenDataFieldsFragmentDoc} ${CollectionDataFieldsFragmentDoc}`; +export const GetAccountTokens = ` + query getAccountTokens($address: String!, $offset: Int, $limit: Int) { + current_token_ownerships_v2( + where: {owner_address: {_eq: $address}, amount: {_gt: 0}} + offset: $offset + limit: $limit + ) { + token_standard + is_fungible_v2 + is_soulbound_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 GetAccountTokensCount = ` query getAccountTokensCount($owner_address: String) { current_token_ownerships_aggregate( @@ -222,6 +268,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = getAccountCurrentTokens(variables: Types.GetAccountCurrentTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCurrentTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCurrentTokens', 'query'); }, + getAccountTokens(variables: Types.GetAccountTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { + return withWrapper((wrappedRequestHeaders) => client.request(GetAccountTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountTokens', 'query'); + }, getAccountTokensCount(variables?: Types.GetAccountTokensCountQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountTokensCount, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountTokensCount', 'query'); }, diff --git a/ecosystem/typescript/sdk/src/indexer/generated/types.ts b/ecosystem/typescript/sdk/src/indexer/generated/types.ts index 139263b3a709a..dea693afaa9fc 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/getAccountCurrentTokensv2.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getAccountCurrentTokensv2.graphql new file mode 100644 index 0000000000000..82677f82ab1ea --- /dev/null +++ b/ecosystem/typescript/sdk/src/indexer/queries/getAccountCurrentTokensv2.graphql @@ -0,0 +1,44 @@ +query getAccountTokens($address: String!, $offset: Int, $limit: Int) { + current_token_ownerships_v2( + where: { owner_address: { _eq: $address }, amount: { _gt: 0 } } + offset: $offset + limit: $limit + ) { + token_standard + is_fungible_v2 + is_soulbound_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/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index 212dac80bb896..d373b494d1652 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -17,6 +17,7 @@ import { GetTokenOwnersDataQuery, GetTopUserTransactionsQuery, GetUserTransactionsQuery, + GetAccountTokensQuery, } from "../indexer/generated/operations"; import { GetAccountTokensCount, @@ -33,6 +34,7 @@ import { GetTokenOwnersData, GetTopUserTransactions, GetUserTransactions, + GetAccountTokens, } from "../indexer/generated/queries"; /** @@ -310,4 +312,20 @@ export class IndexerClient { }; return this.queryIndexer(graphqlQuery); } + + /** + * Queries account's current tokens. + * This query queries for any type of tokens (i.e NFT, Fungiable, soul bound, etc). + * + * @returns GetAccountTokensQuery response type + */ + async getAccountTokens(accountAddress: MaybeHexString, options?: PaginationArgs): Promise { + const address = HexString.ensure(accountAddress).hex(); + IndexerClient.validateAddress(address); + const graphqlQuery = { + query: GetAccountTokens, + variables: { accountAddress: address, offset: options?.offset, limit: options?.limit }, + }; + return this.queryIndexer(graphqlQuery); + } } From 176c445cbb52f7fdb9803cca514f5ad0ba55e7ab Mon Sep 17 00:00:00 2001 From: maayan Date: Mon, 15 May 2023 16:24:37 -0700 Subject: [PATCH 02/11] add get account collection tokens --- .../sdk/src/indexer/generated/operations.ts | 19 ++++ .../sdk/src/indexer/generated/queries.ts | 65 +++++++++++++ .../getAccountCollectionTokens.graphql | 48 ++++++++++ .../indexer/queries/getCollectionData.graphql | 11 +++ .../typescript/sdk/src/providers/indexer.ts | 91 ++++++++++++++++++- .../sdk/src/tests/e2e/indexer.test.ts | 77 +++++++++++++++- 6 files changed, 303 insertions(+), 8 deletions(-) create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/getAccountCollectionTokens.graphql create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/getCollectionData.graphql diff --git a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts index 8f758f561e5c4..2c9999ae74905 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts @@ -9,6 +9,16 @@ export type GetAccountCoinsDataQueryVariables = Types.Exact<{ export type GetAccountCoinsDataQuery = { __typename?: 'query_root', current_coin_balances: Array<{ __typename?: 'current_coin_balances', amount: any, coin_type: string, coin_info?: { __typename?: 'coin_infos', name: string, decimals: number, symbol: string } | null }> }; +export type GetAccountCollectionTokensQueryVariables = Types.Exact<{ + collection_id: Types.Scalars['String']; + owner_address: Types.Scalars['String']; + offset?: Types.InputMaybe; + limit?: Types.InputMaybe; +}>; + + +export type GetAccountCollectionTokensQuery = { __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 GetAccountCurrentTokensQueryVariables = Types.Exact<{ address: Types.Scalars['String']; offset?: Types.InputMaybe; @@ -54,6 +64,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; diff --git a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts index 7f1fe8bdb2aa4..345b3437c2927 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts @@ -41,6 +41,52 @@ export const GetAccountCoinsData = ` } } `; +export const GetAccountCollectionTokens = ` + query getAccountCollectionTokens($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 + ) { + token_standard + is_fungible_v2 + is_soulbound_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 GetAccountCurrentTokens = ` query getAccountCurrentTokens($address: String!, $offset: Int, $limit: Int) { current_token_ownerships( @@ -144,6 +190,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( @@ -265,6 +324,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = getAccountCoinsData(variables?: Types.GetAccountCoinsDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCoinsData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCoinsData', 'query'); }, + getAccountCollectionTokens(variables: Types.GetAccountCollectionTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { + return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCollectionTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCollectionTokens', 'query'); + }, getAccountCurrentTokens(variables: Types.GetAccountCurrentTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCurrentTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCurrentTokens', 'query'); }, @@ -280,6 +342,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'); }, diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getAccountCollectionTokens.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getAccountCollectionTokens.graphql new file mode 100644 index 0000000000000..d4149963c2db2 --- /dev/null +++ b/ecosystem/typescript/sdk/src/indexer/queries/getAccountCollectionTokens.graphql @@ -0,0 +1,48 @@ +query getAccountCollectionTokens($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 + ) { + token_standard + is_fungible_v2 + is_soulbound_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 0000000000000..066f5871e7515 --- /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/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index d373b494d1652..d082a35a5f783 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -1,4 +1,5 @@ import axios from "axios"; +import { sha3_256 as sha3Hash } from "@noble/hashes/sha3"; import { AnyNumber } from "../bcs/types"; import { HexString, MaybeHexString } from "../utils"; @@ -18,6 +19,8 @@ import { GetTopUserTransactionsQuery, GetUserTransactionsQuery, GetAccountTokensQuery, + GetAccountCollectionTokensQuery, + GetCollectionDataQuery, } from "../indexer/generated/operations"; import { GetAccountTokensCount, @@ -35,7 +38,11 @@ import { GetTopUserTransactions, GetUserTransactions, GetAccountTokens, + GetAccountCollectionTokens, + GetCollectionData, } from "../indexer/generated/queries"; +import { AccountAddress } from "../aptos_types"; +import { bcsToBytes } from "../bcs"; /** * Controls the number of results that are returned and the starting position of those results. @@ -50,6 +57,8 @@ interface PaginationArgs { limit?: number; } +type TokenStandard = "v1" | "v2"; + type GraphqlQuery = { query: string; variables?: {}; @@ -319,13 +328,89 @@ export class IndexerClient { * * @returns GetAccountTokensQuery response type */ - async getAccountTokens(accountAddress: MaybeHexString, options?: PaginationArgs): Promise { - const address = HexString.ensure(accountAddress).hex(); + async getAccountTokens(ownerAddress: MaybeHexString, options?: PaginationArgs): Promise { + const address = HexString.ensure(ownerAddress).hex(); IndexerClient.validateAddress(address); const graphqlQuery = { query: GetAccountTokens, - variables: { accountAddress: address, offset: options?.offset, limit: options?.limit }, + variables: { address, offset: options?.offset, limit: options?.limit }, + }; + return this.queryIndexer(graphqlQuery); + } + + /** + * Queries all tokens of a specific collection that an account owns + * + * @param ownerAddress owner address + * @param collectionAddress the collection address + * @returns GetAccountCollectionTokensQuery response type + */ + async getAccountCollectionTokensByCollectionAddress( + ownerAddress: MaybeHexString, + collectionAddress: MaybeHexString, + options?: PaginationArgs, + ): Promise { + const address = HexString.ensure(ownerAddress).hex(); + IndexerClient.validateAddress(address); + + const graphqlQuery = { + query: GetAccountCollectionTokens, + variables: { + collection_id: collectionAddress, + owner_address: address, + offset: options?.offset, + limit: options?.limit, + }, }; return this.queryIndexer(graphqlQuery); } + + /** + * Queries a collection data + * + * @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); + + let 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); + } + + 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 c2a5ade15faf8..218defbeeb23b 100644 --- a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts +++ b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts @@ -6,14 +6,17 @@ 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 tokenName = "Alice Token"; @@ -39,11 +42,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 +65,28 @@ describe("Indexer", () => { ), { checkSuccess: true }, ); + + await provider.waitForTransaction( + await aptosToken.createCollection(alice, "Alice's simple collection", collectionName, "https://aptos.dev", 5, { + royaltyNumerator: 10, + royaltyDenominator: 10, + }), + { checkSuccess: true }, + ); + + await provider.waitForTransactionWithResult( + await aptosToken.mint( + alice, + collectionName, + "Alice's simple token", + tokenName, + "https://aptos.dev/img/nyan.jpeg", + ["key"], + ["bool"], + ["true"], + ), + { checkSuccess: true }, + ); }, longTestTimeout); describe("get data", () => { @@ -117,7 +142,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 +225,47 @@ 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.getAccountTokens(alice.address().hex()); + expect(tokens.current_token_ownerships_v2).toHaveLength(2); + }); + + it("gets the account collection data", async () => { + const collectionData = await indexerClient.getCollectionData(alice.address().hex(), collectionName); + expect(collectionData.current_collections_v2).toHaveLength(2); + }); + + it( + "gets account current tokens of a specific collection by the collection address", + async () => { + const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionName, { + tokenStandard: "v2", + }); + const tokens = await indexerClient.getAccountCollectionTokensByCollectionAddress( + alice.address().hex(), + collectionAddress, + ); + expect(tokens.current_token_ownerships_v2).toHaveLength(1); + expect(tokens.current_token_ownerships_v2[0].token_standard).toEqual("v2"); + }, + longTestTimeout, + ); + + it( + "gets account current tokens of a specific collection by the collection address", + async () => { + const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionName, { + tokenStandard: "v1", + }); + const tokens = await indexerClient.getAccountCollectionTokensByCollectionAddress( + alice.address().hex(), + collectionAddress, + ); + expect(tokens.current_token_ownerships_v2).toHaveLength(1); + expect(tokens.current_token_ownerships_v2[0].token_standard).toEqual("v1"); + }, + longTestTimeout, + ); }); }); From 1fb90ee1fcf077d0cb1af3b61a6449895a13b6e7 Mon Sep 17 00:00:00 2001 From: maayan Date: Mon, 15 May 2023 16:26:00 -0700 Subject: [PATCH 03/11] update changelog --- ecosystem/typescript/sdk/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ecosystem/typescript/sdk/CHANGELOG.md b/ecosystem/typescript/sdk/CHANGELOG.md index 3a04c964fa8c1..000dd925eaa41 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`, `getAccountCollectionTokensByCollectionAddress`, `getCollectionData`, `getCollectionAddress` ## 1.8.5 (2023-04-29) From b84dddc428837bdf8168eaba8bb3f391d9713b6b Mon Sep 17 00:00:00 2001 From: maayan Date: Mon, 15 May 2023 16:31:15 -0700 Subject: [PATCH 04/11] add function comment --- ecosystem/typescript/sdk/src/providers/indexer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ecosystem/typescript/sdk/src/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index d082a35a5f783..d9715de8bc9c3 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -367,6 +367,7 @@ export class IndexerClient { /** * Queries a collection data + * 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 From f18a779cd62217a7b130a4c94dd06aabdbded2bd Mon Sep 17 00:00:00 2001 From: maayan Date: Mon, 15 May 2023 16:32:49 -0700 Subject: [PATCH 05/11] add function comment --- ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts index 218defbeeb23b..539d5834d444a 100644 --- a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts +++ b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts @@ -231,7 +231,7 @@ describe("Indexer", () => { expect(tokens.current_token_ownerships_v2).toHaveLength(2); }); - it("gets the account collection data", async () => { + it("gets the collection data", async () => { const collectionData = await indexerClient.getCollectionData(alice.address().hex(), collectionName); expect(collectionData.current_collections_v2).toHaveLength(2); }); From 9e0760598b0a3b2cd6e387640833f9bd9a6f0893 Mon Sep 17 00:00:00 2001 From: maayan Date: Mon, 15 May 2023 16:43:38 -0700 Subject: [PATCH 06/11] fix lint --- ecosystem/typescript/sdk/src/providers/indexer.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ecosystem/typescript/sdk/src/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index d9715de8bc9c3..ff7c6a6661c6c 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -1,5 +1,4 @@ import axios from "axios"; -import { sha3_256 as sha3Hash } from "@noble/hashes/sha3"; import { AnyNumber } from "../bcs/types"; import { HexString, MaybeHexString } from "../utils"; @@ -41,8 +40,6 @@ import { GetAccountCollectionTokens, GetCollectionData, } from "../indexer/generated/queries"; -import { AccountAddress } from "../aptos_types"; -import { bcsToBytes } from "../bcs"; /** * Controls the number of results that are returned and the starting position of those results. @@ -367,7 +364,8 @@ export class IndexerClient { /** * Queries a collection data - * 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 + * 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 @@ -384,7 +382,7 @@ export class IndexerClient { const address = HexString.ensure(creatorAddress).hex(); IndexerClient.validateAddress(address); - let whereCondition: any = { + const whereCondition: any = { collection_name: { _eq: collectionName }, creator_address: { _eq: address }, }; From 424201055dc451997c65e3a0f44a9c242713ad6a Mon Sep 17 00:00:00 2001 From: maayan Date: Tue, 16 May 2023 15:34:36 -0700 Subject: [PATCH 07/11] address feedback --- .../sdk/src/indexer/generated/operations.ts | 20 ++-- .../sdk/src/indexer/generated/queries.ts | 98 +++++++++---------- ...ql => getTokenOwnedFromCollection.graphql} | 2 +- .../typescript/sdk/src/providers/indexer.ts | 84 ++++++++++++---- .../sdk/src/tests/e2e/indexer.test.ts | 47 ++++++--- 5 files changed, 154 insertions(+), 97 deletions(-) rename ecosystem/typescript/sdk/src/indexer/queries/{getAccountCollectionTokens.graphql => getTokenOwnedFromCollection.graphql} (89%) diff --git a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts index 2c9999ae74905..fa5b31bebb2ac 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts @@ -9,16 +9,6 @@ export type GetAccountCoinsDataQueryVariables = Types.Exact<{ export type GetAccountCoinsDataQuery = { __typename?: 'query_root', current_coin_balances: Array<{ __typename?: 'current_coin_balances', amount: any, coin_type: string, coin_info?: { __typename?: 'coin_infos', name: string, decimals: number, symbol: string } | null }> }; -export type GetAccountCollectionTokensQueryVariables = Types.Exact<{ - collection_id: Types.Scalars['String']; - owner_address: Types.Scalars['String']; - offset?: Types.InputMaybe; - limit?: Types.InputMaybe; -}>; - - -export type GetAccountCollectionTokensQuery = { __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 GetAccountCurrentTokensQueryVariables = Types.Exact<{ address: Types.Scalars['String']; offset?: Types.InputMaybe; @@ -116,6 +106,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 345b3437c2927..99513ebb070a4 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts @@ -41,52 +41,6 @@ export const GetAccountCoinsData = ` } } `; -export const GetAccountCollectionTokens = ` - query getAccountCollectionTokens($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 - ) { - token_standard - is_fungible_v2 - is_soulbound_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 GetAccountCurrentTokens = ` query getAccountCurrentTokens($address: String!, $offset: Int, $limit: Int) { current_token_ownerships( @@ -285,6 +239,52 @@ 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 + ) { + token_standard + is_fungible_v2 + is_soulbound_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 GetTokenOwnersData = ` query getTokenOwnersData($token_id: String, $property_version: numeric) { current_token_ownerships( @@ -324,9 +324,6 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = getAccountCoinsData(variables?: Types.GetAccountCoinsDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCoinsData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCoinsData', 'query'); }, - getAccountCollectionTokens(variables: Types.GetAccountCollectionTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { - return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCollectionTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCollectionTokens', 'query'); - }, getAccountCurrentTokens(variables: Types.GetAccountCurrentTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCurrentTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCurrentTokens', 'query'); }, @@ -363,6 +360,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/queries/getAccountCollectionTokens.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql similarity index 89% rename from ecosystem/typescript/sdk/src/indexer/queries/getAccountCollectionTokens.graphql rename to ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql index d4149963c2db2..3505927224ba8 100644 --- a/ecosystem/typescript/sdk/src/indexer/queries/getAccountCollectionTokens.graphql +++ b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql @@ -1,4 +1,4 @@ -query getAccountCollectionTokens($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) { +query getTokenOwnedFromCollection($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) { current_token_ownerships_v2( where: { owner_address: { _eq: $owner_address } diff --git a/ecosystem/typescript/sdk/src/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index ff7c6a6661c6c..4c841d1151658 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -18,7 +18,7 @@ import { GetTopUserTransactionsQuery, GetUserTransactionsQuery, GetAccountTokensQuery, - GetAccountCollectionTokensQuery, + GetTokenOwnedFromCollectionQuery, GetCollectionDataQuery, } from "../indexer/generated/operations"; import { @@ -37,7 +37,7 @@ import { GetTopUserTransactions, GetUserTransactions, GetAccountTokens, - GetAccountCollectionTokens, + GetTokenOwnedFromCollection, GetCollectionData, } from "../indexer/generated/queries"; @@ -82,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.`); } } @@ -321,49 +321,84 @@ export class IndexerClient { /** * Queries account's current tokens. - * This query queries for any type of tokens (i.e NFT, Fungiable, soul bound, etc). + * 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 GetAccountTokensQuery response type */ - async getAccountTokens(ownerAddress: MaybeHexString, options?: PaginationArgs): Promise { + async getAccountTokens( + ownerAddress: MaybeHexString, + extraArgs?: { + options?: PaginationArgs; + }, + ): Promise { const address = HexString.ensure(ownerAddress).hex(); IndexerClient.validateAddress(address); const graphqlQuery = { query: GetAccountTokens, - variables: { address, offset: options?.offset, limit: options?.limit }, + 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 + * Queries all tokens of a specific collection that an account owns by the collection address * - * @param ownerAddress owner address + * @param ownerAddress owner address that owns the tokens * @param collectionAddress the collection address - * @returns GetAccountCollectionTokensQuery response type + * @returns GetTokenOwnedFromCollectionQuery response type */ - async getAccountCollectionTokensByCollectionAddress( + async getTokenOwnedFromCollectionAddress( ownerAddress: MaybeHexString, - collectionAddress: MaybeHexString, - options?: PaginationArgs, - ): Promise { - const address = HexString.ensure(ownerAddress).hex(); - IndexerClient.validateAddress(address); + 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: GetAccountCollectionTokens, + query: GetTokenOwnedFromCollection, variables: { - collection_id: collectionAddress, - owner_address: address, - offset: options?.offset, - limit: options?.limit, + collection_id: collectionHexAddress, + owner_address: ownerHexAddress, + offset: extraArgs?.options?.offset, + limit: extraArgs?.options?.limit, }, }; return this.queryIndexer(graphqlQuery); } /** - * Queries a collection data + * 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); + return await this.getTokenOwnedFromCollectionAddress(ownerAddress, collectionAddress, extraArgs); + } + + /** + * 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 * @@ -402,6 +437,13 @@ export class IndexerClient { 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, diff --git a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts index 539d5834d444a..90f3b72b35a96 100644 --- a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts +++ b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts @@ -19,6 +19,7 @@ const faucetClient = new FaucetClient( 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]); @@ -67,7 +68,7 @@ describe("Indexer", () => { ); await provider.waitForTransaction( - await aptosToken.createCollection(alice, "Alice's simple collection", collectionName, "https://aptos.dev", 5, { + await aptosToken.createCollection(alice, "Alice's simple collection", collectionNameV2, "https://aptos.dev", 5, { royaltyNumerator: 10, royaltyDenominator: 10, }), @@ -77,7 +78,7 @@ describe("Indexer", () => { await provider.waitForTransactionWithResult( await aptosToken.mint( alice, - collectionName, + collectionNameV2, "Alice's simple token", tokenName, "https://aptos.dev/img/nyan.jpeg", @@ -233,18 +234,26 @@ describe("Indexer", () => { it("gets the collection data", async () => { const collectionData = await indexerClient.getCollectionData(alice.address().hex(), collectionName); - expect(collectionData.current_collections_v2).toHaveLength(2); + 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", + "gets account current tokens of a specific collection by the collection address with token standard specified", async () => { - const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionName, { - tokenStandard: "v2", - }); - const tokens = await indexerClient.getAccountCollectionTokensByCollectionAddress( + const tokens = await indexerClient.getTokenOwnedFromCollectionNameAndCreatorAddress( alice.address().hex(), - collectionAddress, + 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"); @@ -253,17 +262,23 @@ describe("Indexer", () => { ); it( - "gets account current tokens of a specific collection by the collection address", + "returns same result for getTokenOwnedFromCollectionNameAndCreatorAddress and getTokenOwnedFromCollectionAddress", async () => { - const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionName, { - tokenStandard: "v1", - }); - const tokens = await indexerClient.getAccountCollectionTokensByCollectionAddress( + console.log(alice.address().hex()); + const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionNameV2); + const tokensFromCollectionAddress = await indexerClient.getTokenOwnedFromCollectionAddress( alice.address().hex(), collectionAddress, ); - expect(tokens.current_token_ownerships_v2).toHaveLength(1); - expect(tokens.current_token_ownerships_v2[0].token_standard).toEqual("v1"); + 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, ); From a6635424999d0214c09d8ed94113f13d95354a5d Mon Sep 17 00:00:00 2001 From: maayan Date: Tue, 16 May 2023 15:35:44 -0700 Subject: [PATCH 08/11] update changelog --- ecosystem/typescript/sdk/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecosystem/typescript/sdk/CHANGELOG.md b/ecosystem/typescript/sdk/CHANGELOG.md index 000dd925eaa41..b38531f29d49d 100644 --- a/ecosystem/typescript/sdk/CHANGELOG.md +++ b/ecosystem/typescript/sdk/CHANGELOG.md @@ -8,7 +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`, `getAccountCollectionTokensByCollectionAddress`, `getCollectionData`, `getCollectionAddress` +- Add Indexer queries for tokens - `getAccountTokens`, `getTokenOwnedFromCollectionAddress`, `getTokenOwnedFromCollectionNameAndCreatorAddress`, `getCollectionData`, `getCollectionAddress` ## 1.8.5 (2023-04-29) From abbea237630181acb486661b74ff0c4ad6fb565e Mon Sep 17 00:00:00 2001 From: maayan Date: Tue, 16 May 2023 16:24:32 -0700 Subject: [PATCH 09/11] fix lint --- ecosystem/typescript/sdk/src/providers/indexer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ecosystem/typescript/sdk/src/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index 4c841d1151658..c1739375a8fce 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -393,7 +393,8 @@ export class IndexerClient { }, ): Promise { const collectionAddress = await this.getCollectionAddress(creatorAddress, collectionName, extraArgs); - return await this.getTokenOwnedFromCollectionAddress(ownerAddress, collectionAddress, extraArgs); + const tokens = await this.getTokenOwnedFromCollectionAddress(ownerAddress, collectionAddress, extraArgs); + return tokens; } /** From 118e39aa43cf122da5f7a6c06c7fca9cfb958f17 Mon Sep 17 00:00:00 2001 From: maayan Date: Wed, 17 May 2023 09:59:58 -0700 Subject: [PATCH 10/11] typo --- .../sdk/src/indexer/generated/operations.ts | 18 ++-- .../sdk/src/indexer/generated/queries.ts | 98 +++++++++---------- ...okensv2.graphql => getOwnedTokens.graphql} | 3 +- .../getTokenOwnedFromCollection.graphql | 1 - .../typescript/sdk/src/providers/indexer.ts | 14 +-- .../sdk/src/tests/e2e/indexer.test.ts | 2 +- 6 files changed, 66 insertions(+), 70 deletions(-) rename ecosystem/typescript/sdk/src/indexer/queries/{getAccountCurrentTokensv2.graphql => getOwnedTokens.graphql} (90%) diff --git a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts index fa5b31bebb2ac..d0e1f16f88f41 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts @@ -22,15 +22,6 @@ export type TokenDataFieldsFragment = { __typename?: 'current_token_datas', crea export type CollectionDataFieldsFragment = { __typename?: 'current_collection_datas', metadata_uri: string, supply: any, description: string, collection_name: string, collection_data_id_hash: string, table_handle: string, creator_address: string }; -export type GetAccountTokensQueryVariables = Types.Exact<{ - address: Types.Scalars['String']; - offset?: Types.InputMaybe; - limit?: Types.InputMaybe; -}>; - - -export type GetAccountTokensQuery = { __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 GetAccountTokensCountQueryVariables = Types.Exact<{ owner_address?: Types.InputMaybe; }>; @@ -83,6 +74,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; diff --git a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts index 99513ebb070a4..47a8ce608d5b2 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts @@ -62,52 +62,6 @@ export const GetAccountCurrentTokens = ` } ${TokenDataFieldsFragmentDoc} ${CollectionDataFieldsFragmentDoc}`; -export const GetAccountTokens = ` - query getAccountTokens($address: String!, $offset: Int, $limit: Int) { - current_token_ownerships_v2( - where: {owner_address: {_eq: $address}, amount: {_gt: 0}} - offset: $offset - limit: $limit - ) { - token_standard - is_fungible_v2 - is_soulbound_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 GetAccountTokensCount = ` query getAccountTokensCount($owner_address: String) { current_token_ownerships_aggregate( @@ -188,6 +142,51 @@ 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 + ) { + 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 GetTokenActivities = ` query getTokenActivities($idHash: String!, $offset: Int, $limit: Int) { token_activities( @@ -249,7 +248,6 @@ export const GetTokenOwnedFromCollection = ` token_standard is_fungible_v2 is_soulbound_v2 - is_soulbound_v2 property_version_v1 table_type_v1 token_properties_mutated_v1 @@ -327,9 +325,6 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = getAccountCurrentTokens(variables: Types.GetAccountCurrentTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountCurrentTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountCurrentTokens', 'query'); }, - getAccountTokens(variables: Types.GetAccountTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { - return withWrapper((wrappedRequestHeaders) => client.request(GetAccountTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountTokens', 'query'); - }, getAccountTokensCount(variables?: Types.GetAccountTokensCountQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { return withWrapper((wrappedRequestHeaders) => client.request(GetAccountTokensCount, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountTokensCount', 'query'); }, @@ -351,6 +346,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'); }, diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getAccountCurrentTokensv2.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql similarity index 90% rename from ecosystem/typescript/sdk/src/indexer/queries/getAccountCurrentTokensv2.graphql rename to ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql index 82677f82ab1ea..7387ec09a44da 100644 --- a/ecosystem/typescript/sdk/src/indexer/queries/getAccountCurrentTokensv2.graphql +++ b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql @@ -1,4 +1,4 @@ -query getAccountTokens($address: String!, $offset: Int, $limit: Int) { +query getOwnedTokens($address: String!, $offset: Int, $limit: Int) { current_token_ownerships_v2( where: { owner_address: { _eq: $address }, amount: { _gt: 0 } } offset: $offset @@ -7,7 +7,6 @@ query getAccountTokens($address: String!, $offset: Int, $limit: Int) { token_standard is_fungible_v2 is_soulbound_v2 - is_soulbound_v2 property_version_v1 table_type_v1 token_properties_mutated_v1 diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql index 3505927224ba8..39974c95e8371 100644 --- a/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql +++ b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql @@ -11,7 +11,6 @@ query getTokenOwnedFromCollection($collection_id: String!, $owner_address: Strin token_standard is_fungible_v2 is_soulbound_v2 - is_soulbound_v2 property_version_v1 table_type_v1 token_properties_mutated_v1 diff --git a/ecosystem/typescript/sdk/src/providers/indexer.ts b/ecosystem/typescript/sdk/src/providers/indexer.ts index c1739375a8fce..6f7d3a21468de 100644 --- a/ecosystem/typescript/sdk/src/providers/indexer.ts +++ b/ecosystem/typescript/sdk/src/providers/indexer.ts @@ -17,7 +17,7 @@ import { GetTokenOwnersDataQuery, GetTopUserTransactionsQuery, GetUserTransactionsQuery, - GetAccountTokensQuery, + GetOwnedTokensQuery, GetTokenOwnedFromCollectionQuery, GetCollectionDataQuery, } from "../indexer/generated/operations"; @@ -36,7 +36,7 @@ import { GetTokenOwnersData, GetTopUserTransactions, GetUserTransactions, - GetAccountTokens, + GetOwnedTokens, GetTokenOwnedFromCollection, GetCollectionData, } from "../indexer/generated/queries"; @@ -320,22 +320,22 @@ export class IndexerClient { } /** - * Queries account's current tokens. + * 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 GetAccountTokensQuery response type + * @returns GetOwnedTokensQuery response type */ - async getAccountTokens( + async getOwnedTokens( ownerAddress: MaybeHexString, extraArgs?: { options?: PaginationArgs; }, - ): Promise { + ): Promise { const address = HexString.ensure(ownerAddress).hex(); IndexerClient.validateAddress(address); const graphqlQuery = { - query: GetAccountTokens, + query: GetOwnedTokens, variables: { address, offset: extraArgs?.options?.offset, limit: extraArgs?.options?.limit }, }; return this.queryIndexer(graphqlQuery); diff --git a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts index 90f3b72b35a96..5063130404b28 100644 --- a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts +++ b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts @@ -228,7 +228,7 @@ describe("Indexer", () => { }); it("gets account current tokens", async () => { - const tokens = await indexerClient.getAccountTokens(alice.address().hex()); + const tokens = await indexerClient.getOwnedTokens(alice.address().hex()); expect(tokens.current_token_ownerships_v2).toHaveLength(2); }); From 7a27ab4be8c62adfa350004713df9968b7b89202 Mon Sep 17 00:00:00 2001 From: maayan Date: Wed, 17 May 2023 10:43:38 -0700 Subject: [PATCH 11/11] token ownership fields fragment --- .../sdk/src/indexer/generated/operations.ts | 2 + .../sdk/src/indexer/generated/queries.ts | 115 +++++++----------- ...urrentTokenOwnershipFieldsFragment.graphql | 37 ++++++ .../indexer/queries/getOwnedTokens.graphql | 37 +----- .../getTokenOwnedFromCollection.graphql | 37 +----- .../sdk/src/tests/e2e/indexer.test.ts | 1 - 6 files changed, 86 insertions(+), 143 deletions(-) create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql diff --git a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts index d0e1f16f88f41..63fa1aeb5585e 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; diff --git a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts index 47a8ce608d5b2..33d71de4a5184 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 @@ -149,44 +188,10 @@ export const GetOwnedTokens = ` offset: $offset limit: $limit ) { - 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 - } - } + ...CurrentTokenOwnershipFields } } - `; + ${CurrentTokenOwnershipFieldsFragmentDoc}`; export const GetTokenActivities = ` query getTokenActivities($idHash: String!, $offset: Int, $limit: Int) { token_activities( @@ -245,44 +250,10 @@ export const GetTokenOwnedFromCollection = ` offset: $offset limit: $limit ) { - 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 - } - } + ...CurrentTokenOwnershipFields } } - `; + ${CurrentTokenOwnershipFieldsFragmentDoc}`; export const GetTokenOwnersData = ` query getTokenOwnersData($token_id: String, $property_version: numeric) { current_token_ownerships( 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 0000000000000..07f6651851250 --- /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/getOwnedTokens.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql index 7387ec09a44da..1920e431db6bc 100644 --- a/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql +++ b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql @@ -1,43 +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 ) { - 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 - } - } + ...CurrentTokenOwnershipFields } } diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql index 39974c95e8371..978fa420c16dd 100644 --- a/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql +++ b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql @@ -1,3 +1,4 @@ +#import "./CurrentTokenOwnershipFieldsFragment"; query getTokenOwnedFromCollection($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) { current_token_ownerships_v2( where: { @@ -8,40 +9,6 @@ query getTokenOwnedFromCollection($collection_id: String!, $owner_address: Strin offset: $offset limit: $limit ) { - 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 - } - } + ...CurrentTokenOwnershipFields } } diff --git a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts index 5063130404b28..a448492f8f94a 100644 --- a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts +++ b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts @@ -264,7 +264,6 @@ describe("Indexer", () => { it( "returns same result for getTokenOwnedFromCollectionNameAndCreatorAddress and getTokenOwnedFromCollectionAddress", async () => { - console.log(alice.address().hex()); const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionNameV2); const tokensFromCollectionAddress = await indexerClient.getTokenOwnedFromCollectionAddress( alice.address().hex(),