Skip to content

Commit

Permalink
[TS SDK] Add query to fetch all collections that an account has token…
Browse files Browse the repository at this point in the history
…s for (#8498)

* add query to get all collections that an account has tokens for

* use token standard param in query condition

* update changelog

* address feedback
  • Loading branch information
0xmaayan authored and banool committed Jul 7, 2023
1 parent 9249d77 commit 78ae6a2
Show file tree
Hide file tree
Showing 9 changed files with 1,172 additions and 43 deletions.
2 changes: 2 additions & 0 deletions ecosystem/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to the Aptos Node SDK will be captured in this file. This ch
- Add `x-aptos-client` header to `IndexerClient` requests
- Add `standardizeAddress` static function to `AccountAddress` class to standardizes an address to the format "0x" followed by 64 lowercase hexadecimal digits.
- Change `indexerUrl` param on `Provider` class to an optional parameter
- Add `getCollectionsWithOwnedTokens` query to fetch all collections that an account has tokens for
- Support `tokenStandard` param in `getOwnedTokens` and `getTokenOwnedFromCollectionAddress` queries

## 1.9.1 (2023-05-24)

Expand Down
14 changes: 11 additions & 3 deletions ecosystem/typescript/sdk/src/indexer/generated/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export type GetCollectionDataQueryVariables = Types.Exact<{

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 GetCollectionsWithOwnedTokensQueryVariables = Types.Exact<{
where_condition: Types.Current_Collection_Ownership_V2_View_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
}>;


export type GetCollectionsWithOwnedTokensQuery = { __typename?: 'query_root', current_collection_ownership_v2_view: Array<{ __typename?: 'current_collection_ownership_v2_view', distinct_tokens?: any | null, last_transaction_version?: any | null, current_collection?: { __typename?: 'current_collections_v2', creator_address: string, collection_name: string, token_standard: string, collection_id: string, description: string, table_handle_v1?: string | null, uri: string, total_minted_v2?: any | null, max_supply?: any | null } | null }> };

export type GetDelegatedStakingActivitiesQueryVariables = Types.Exact<{
delegatorAddress?: Types.InputMaybe<Types.Scalars['String']>;
poolAddress?: Types.InputMaybe<Types.Scalars['String']>;
Expand All @@ -77,7 +86,7 @@ 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'];
where_condition: Types.Current_Token_Ownerships_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
}>;
Expand Down Expand Up @@ -109,8 +118,7 @@ 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'];
where_condition: Types.Current_Token_Ownerships_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
}>;
Expand Down
35 changes: 31 additions & 4 deletions ecosystem/typescript/sdk/src/indexer/generated/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ export const GetCollectionData = `
}
}
`;
export const GetCollectionsWithOwnedTokens = `
query getCollectionsWithOwnedTokens($where_condition: current_collection_ownership_v2_view_bool_exp!, $offset: Int, $limit: Int) {
current_collection_ownership_v2_view(
where: $where_condition
order_by: {last_transaction_version: desc}
offset: $offset
limit: $limit
) {
current_collection {
creator_address
collection_name
token_standard
collection_id
description
table_handle_v1
uri
total_minted_v2
max_supply
}
distinct_tokens
last_transaction_version
}
}
`;
export const GetDelegatedStakingActivities = `
query getDelegatedStakingActivities($delegatorAddress: String, $poolAddress: String) {
delegated_staking_activities(
Expand Down Expand Up @@ -182,9 +206,9 @@ export const GetNumberOfDelegators = `
}
`;
export const GetOwnedTokens = `
query getOwnedTokens($address: String!, $offset: Int, $limit: Int) {
query getOwnedTokens($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int) {
current_token_ownerships_v2(
where: {owner_address: {_eq: $address}, amount: {_gt: 0}}
where: $where_condition
offset: $offset
limit: $limit
) {
Expand Down Expand Up @@ -244,9 +268,9 @@ export const GetTokenData = `
}
`;
export const GetTokenOwnedFromCollection = `
query getTokenOwnedFromCollection($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) {
query getTokenOwnedFromCollection($where_condition: current_token_ownerships_v2_bool_exp!, $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}}
where: $where_condition
offset: $offset
limit: $limit
) {
Expand Down Expand Up @@ -308,6 +332,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
getCollectionData(variables: Types.GetCollectionDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetCollectionDataQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetCollectionDataQuery>(GetCollectionData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getCollectionData', 'query');
},
getCollectionsWithOwnedTokens(variables: Types.GetCollectionsWithOwnedTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetCollectionsWithOwnedTokensQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetCollectionsWithOwnedTokensQuery>(GetCollectionsWithOwnedTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getCollectionsWithOwnedTokens', '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 Down
Loading

0 comments on commit 78ae6a2

Please sign in to comment.