Skip to content

Commit

Permalink
[TS SDK] Add TokenV2 Indexer queries (#8210)
Browse files Browse the repository at this point in the history
* add get account token query

* add get account collection tokens

* update changelog

* add function comment

* add function comment

* fix lint

* address feedback

* update changelog

* fix lint

* typo

* token ownership fields fragment
  • Loading branch information
0xmaayan authored and gedigi committed Jun 6, 2023
1 parent 9b375f5 commit ad97943
Show file tree
Hide file tree
Showing 10 changed files with 1,053 additions and 6 deletions.
1 change: 1 addition & 0 deletions ecosystem/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to the Aptos Node SDK will be captured in this file. This ch

- Fix get number of delegators Indexer query
- Include static methods from `AptosClient` and `IndexerClient` classes in the `Provider` class
- Add Indexer queries for tokens - `getAccountTokens`, `getTokenOwnedFromCollectionAddress`, `getTokenOwnedFromCollectionNameAndCreatorAddress`, `getCollectionData`, `getCollectionAddress`

## 1.8.5 (2023-04-29)

Expand Down
30 changes: 30 additions & 0 deletions ecosystem/typescript/sdk/src/indexer/generated/operations.ts
Original file line number Diff line number Diff line change
@@ -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<Types.Scalars['String']>;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
Expand Down Expand Up @@ -45,6 +47,15 @@ export type GetAccountTransactionsDataQueryVariables = Types.Exact<{

export type GetAccountTransactionsDataQuery = { __typename?: 'query_root', move_resources: Array<{ __typename?: 'move_resources', transaction_version: any }> };

export type GetCollectionDataQueryVariables = Types.Exact<{
where_condition: Types.Current_Collections_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
}>;


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<Types.Scalars['String']>;
poolAddress?: Types.InputMaybe<Types.Scalars['String']>;
Expand All @@ -65,6 +76,15 @@ export type GetNumberOfDelegatorsQueryVariables = Types.Exact<{

export type GetNumberOfDelegatorsQuery = { __typename?: 'query_root', num_active_delegator_per_pool: Array<{ __typename?: 'num_active_delegator_per_pool', num_active_delegator?: any | null }> };

export type GetOwnedTokensQueryVariables = Types.Exact<{
address: Types.Scalars['String'];
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
}>;


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<Types.Scalars['Int']>;
Expand All @@ -88,6 +108,16 @@ export type GetTokenDataQueryVariables = Types.Exact<{

export type GetTokenDataQuery = { __typename?: 'query_root', current_token_datas: Array<{ __typename?: 'current_token_datas', token_data_id_hash: string, name: string, collection_name: string, creator_address: string, default_properties: any, largest_property_version: any, maximum: any, metadata_uri: string, payee_address: string, royalty_points_denominator: any, royalty_points_numerator: any, supply: any }> };

export type GetTokenOwnedFromCollectionQueryVariables = Types.Exact<{
collection_id: Types.Scalars['String'];
owner_address: Types.Scalars['String'];
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
}>;


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<Types.Scalars['String']>;
property_version?: Types.InputMaybe<Types.Scalars['numeric']>;
Expand Down
83 changes: 83 additions & 0 deletions ecosystem/typescript/sdk/src/indexer/generated/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +137,19 @@ export const GetAccountTransactionsData = `
}
}
`;
export const GetCollectionData = `
query getCollectionData($where_condition: current_collections_v2_bool_exp!, $offset: Int, $limit: Int) {
current_collections_v2(where: $where_condition, offset: $offset, limit: $limit) {
collection_id
token_standard
collection_name
creator_address
current_supply
description
uri
}
}
`;
export const GetDelegatedStakingActivities = `
query getDelegatedStakingActivities($delegatorAddress: String, $poolAddress: String) {
delegated_staking_activities(
Expand Down Expand Up @@ -129,6 +181,17 @@ export const GetNumberOfDelegators = `
}
}
`;
export const GetOwnedTokens = `
query getOwnedTokens($address: String!, $offset: Int, $limit: Int) {
current_token_ownerships_v2(
where: {owner_address: {_eq: $address}, amount: {_gt: 0}}
offset: $offset
limit: $limit
) {
...CurrentTokenOwnershipFields
}
}
${CurrentTokenOwnershipFieldsFragmentDoc}`;
export const GetTokenActivities = `
query getTokenActivities($idHash: String!, $offset: Int, $limit: Int) {
token_activities(
Expand Down Expand Up @@ -180,6 +243,17 @@ export const GetTokenData = `
}
}
`;
export const GetTokenOwnedFromCollection = `
query getTokenOwnedFromCollection($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) {
current_token_ownerships_v2(
where: {owner_address: {_eq: $owner_address}, current_token_data: {collection_id: {_eq: $collection_id}}, amount: {_gt: 0}}
offset: $offset
limit: $limit
) {
...CurrentTokenOwnershipFields
}
}
${CurrentTokenOwnershipFieldsFragmentDoc}`;
export const GetTokenOwnersData = `
query getTokenOwnersData($token_id: String, $property_version: numeric) {
current_token_ownerships(
Expand Down Expand Up @@ -231,6 +305,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
getAccountTransactionsData(variables?: Types.GetAccountTransactionsDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetAccountTransactionsDataQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetAccountTransactionsDataQuery>(GetAccountTransactionsData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getAccountTransactionsData', 'query');
},
getCollectionData(variables: Types.GetCollectionDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetCollectionDataQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetCollectionDataQuery>(GetCollectionData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getCollectionData', 'query');
},
getDelegatedStakingActivities(variables?: Types.GetDelegatedStakingActivitiesQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetDelegatedStakingActivitiesQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetDelegatedStakingActivitiesQuery>(GetDelegatedStakingActivities, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getDelegatedStakingActivities', 'query');
},
Expand All @@ -240,6 +317,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
getNumberOfDelegators(variables?: Types.GetNumberOfDelegatorsQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetNumberOfDelegatorsQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetNumberOfDelegatorsQuery>(GetNumberOfDelegators, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getNumberOfDelegators', 'query');
},
getOwnedTokens(variables: Types.GetOwnedTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetOwnedTokensQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetOwnedTokensQuery>(GetOwnedTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getOwnedTokens', 'query');
},
getTokenActivities(variables: Types.GetTokenActivitiesQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetTokenActivitiesQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetTokenActivitiesQuery>(GetTokenActivities, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenActivities', 'query');
},
Expand All @@ -249,6 +329,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
getTokenData(variables?: Types.GetTokenDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetTokenDataQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetTokenDataQuery>(GetTokenData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenData', 'query');
},
getTokenOwnedFromCollection(variables: Types.GetTokenOwnedFromCollectionQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetTokenOwnedFromCollectionQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetTokenOwnedFromCollectionQuery>(GetTokenOwnedFromCollection, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenOwnedFromCollection', 'query');
},
getTokenOwnersData(variables?: Types.GetTokenOwnersDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetTokenOwnersDataQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetTokenOwnersDataQuery>(GetTokenOwnersData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenOwnersData', 'query');
},
Expand Down
Loading

0 comments on commit ad97943

Please sign in to comment.