@aptos-labs/ts-sdk 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/browser/index.global.js +410 -0
- package/dist/browser/index.global.js.map +1 -0
- package/dist/cjs/index.d.ts +4965 -0
- package/dist/cjs/index.js +4762 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.ts +4965 -0
- package/dist/esm/index.mjs +4645 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +1247 -0
- package/dist/types/index.js +151 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +79 -0
- package/src/api/account.ts +360 -0
- package/src/api/aptos.ts +103 -0
- package/src/api/aptosConfig.ts +77 -0
- package/src/api/coin.ts +39 -0
- package/src/api/digitalAsset.ts +192 -0
- package/src/api/event.ts +78 -0
- package/src/api/faucet.ts +30 -0
- package/src/api/fungibleAsset.ts +82 -0
- package/src/api/general.ts +188 -0
- package/src/api/index.ts +5 -0
- package/src/api/staking.ts +58 -0
- package/src/api/transaction.ts +135 -0
- package/src/api/transactionSubmission.ts +168 -0
- package/src/bcs/consts.ts +12 -0
- package/src/bcs/deserializer.ts +248 -0
- package/src/bcs/index.ts +9 -0
- package/src/bcs/serializable/entryFunctionBytes.ts +61 -0
- package/src/bcs/serializable/fixedBytes.ts +65 -0
- package/src/bcs/serializable/movePrimitives.ts +211 -0
- package/src/bcs/serializable/moveStructs.ts +462 -0
- package/src/bcs/serializer.ts +353 -0
- package/src/client/core.ts +106 -0
- package/src/client/get.ts +109 -0
- package/src/client/index.ts +7 -0
- package/src/client/post.ts +90 -0
- package/src/client/types.ts +58 -0
- package/src/core/account.ts +180 -0
- package/src/core/accountAddress.ts +407 -0
- package/src/core/authenticationKey.ts +102 -0
- package/src/core/common.ts +40 -0
- package/src/core/crypto/asymmetricCrypto.ts +77 -0
- package/src/core/crypto/ed25519.ts +224 -0
- package/src/core/crypto/index.ts +7 -0
- package/src/core/crypto/multiEd25519.ts +251 -0
- package/src/core/crypto/secp256k1.ts +227 -0
- package/src/core/hex.ts +177 -0
- package/src/core/index.ts +9 -0
- package/src/index.ts +12 -0
- package/src/internal/account.ts +484 -0
- package/src/internal/coin.ts +32 -0
- package/src/internal/digitalAsset.ts +302 -0
- package/src/internal/event.ts +88 -0
- package/src/internal/faucet.ts +41 -0
- package/src/internal/fungibleAsset.ts +114 -0
- package/src/internal/general.ts +160 -0
- package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
- package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +45 -0
- package/src/internal/queries/getAccountCoinCount.graphql +7 -0
- package/src/internal/queries/getAccountCoinsData.graphql +32 -0
- package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
- package/src/internal/queries/getAccountOwnedObjects.graphql +16 -0
- package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
- package/src/internal/queries/getAccountTokensCount.graphql +7 -0
- package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
- package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
- package/src/internal/queries/getCollectionData.graphql +20 -0
- package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
- package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
- package/src/internal/queries/getEvents.graphql +12 -0
- package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
- package/src/internal/queries/getFungibleAssetMetadata.graphql +16 -0
- package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
- package/src/internal/queries/getProcessorStatus.graphql +7 -0
- package/src/internal/queries/getTokenActivity.graphql +11 -0
- package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
- package/src/internal/queries/getTokenData.graphql +38 -0
- package/src/internal/staking.ts +68 -0
- package/src/internal/transaction.ts +245 -0
- package/src/internal/transactionSubmission.ts +162 -0
- package/src/transactions/authenticator/account.ts +121 -0
- package/src/transactions/authenticator/transaction.ts +222 -0
- package/src/transactions/instances/chainId.ts +26 -0
- package/src/transactions/instances/identifier.ts +28 -0
- package/src/transactions/instances/index.ts +9 -0
- package/src/transactions/instances/moduleId.ts +53 -0
- package/src/transactions/instances/rawTransaction.ts +199 -0
- package/src/transactions/instances/signedTransaction.ts +43 -0
- package/src/transactions/instances/transactionArgument.ts +37 -0
- package/src/transactions/instances/transactionPayload.ts +407 -0
- package/src/transactions/transaction_builder/transaction_builder.ts +541 -0
- package/src/transactions/typeTag/typeTag.ts +487 -0
- package/src/transactions/types.ts +262 -0
- package/src/types/codegen.yaml +33 -0
- package/src/types/generated/operations.ts +623 -0
- package/src/types/generated/queries.ts +737 -0
- package/src/types/generated/types.ts +10387 -0
- package/src/types/index.ts +944 -0
- package/src/types/indexer.ts +93 -0
- package/src/utils/apiEndpoints.ts +36 -0
- package/src/utils/const.ts +51 -0
- package/src/utils/hdKey.ts +113 -0
- package/src/utils/helpers.ts +12 -0
- package/src/utils/memoize.ts +68 -0
- package/src/version.ts +9 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This file contains the underlying implementations for exposed API surface in
|
|
6
|
+
* the {@link api/account}. By moving the methods out into a separate file,
|
|
7
|
+
* other namespaces and processes can access these methods without depending on the entire
|
|
8
|
+
* account namespace and without having a dependency cycle error.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { AptosConfig } from "../api/aptosConfig";
|
|
12
|
+
import { AptosApiError, getAptosFullNode, paginateWithCursor } from "../client";
|
|
13
|
+
import { AccountAddress, Hex } from "../core";
|
|
14
|
+
import { getTableItem, queryIndexer } from "./general";
|
|
15
|
+
import {
|
|
16
|
+
AccountData,
|
|
17
|
+
GetAccountCoinsDataResponse,
|
|
18
|
+
GetAccountCollectionsWithOwnedTokenResponse,
|
|
19
|
+
GetAccountOwnedObjectsResponse,
|
|
20
|
+
GetAccountOwnedTokensFromCollectionResponse,
|
|
21
|
+
GetAccountOwnedTokensQueryResponse,
|
|
22
|
+
HexInput,
|
|
23
|
+
LedgerVersion,
|
|
24
|
+
MoveModuleBytecode,
|
|
25
|
+
MoveResource,
|
|
26
|
+
MoveResourceType,
|
|
27
|
+
OrderBy,
|
|
28
|
+
PaginationArgs,
|
|
29
|
+
TokenStandard,
|
|
30
|
+
TransactionResponse,
|
|
31
|
+
} from "../types";
|
|
32
|
+
import {
|
|
33
|
+
GetAccountCoinsCountQuery,
|
|
34
|
+
GetAccountCoinsDataQuery,
|
|
35
|
+
GetAccountCollectionsWithOwnedTokensQuery,
|
|
36
|
+
GetAccountOwnedObjectsQuery,
|
|
37
|
+
GetAccountOwnedTokensFromCollectionQuery,
|
|
38
|
+
GetAccountOwnedTokensQuery,
|
|
39
|
+
GetAccountTokensCountQuery,
|
|
40
|
+
GetAccountTransactionsCountQuery,
|
|
41
|
+
} from "../types/generated/operations";
|
|
42
|
+
import {
|
|
43
|
+
GetAccountCoinsCount,
|
|
44
|
+
GetAccountCoinsData,
|
|
45
|
+
GetAccountCollectionsWithOwnedTokens,
|
|
46
|
+
GetAccountOwnedObjects,
|
|
47
|
+
GetAccountOwnedTokens,
|
|
48
|
+
GetAccountOwnedTokensFromCollection,
|
|
49
|
+
GetAccountTokensCount,
|
|
50
|
+
GetAccountTransactionsCount,
|
|
51
|
+
} from "../types/generated/queries";
|
|
52
|
+
import { memoizeAsync } from "../utils/memoize";
|
|
53
|
+
|
|
54
|
+
export async function getInfo(args: { aptosConfig: AptosConfig; accountAddress: HexInput }): Promise<AccountData> {
|
|
55
|
+
const { aptosConfig, accountAddress } = args;
|
|
56
|
+
const { data } = await getAptosFullNode<{}, AccountData>({
|
|
57
|
+
aptosConfig,
|
|
58
|
+
originMethod: "getInfo",
|
|
59
|
+
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}`,
|
|
60
|
+
});
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function getModules(args: {
|
|
65
|
+
aptosConfig: AptosConfig;
|
|
66
|
+
accountAddress: HexInput;
|
|
67
|
+
options?: PaginationArgs & LedgerVersion;
|
|
68
|
+
}): Promise<MoveModuleBytecode[]> {
|
|
69
|
+
const { aptosConfig, accountAddress, options } = args;
|
|
70
|
+
return paginateWithCursor<{}, MoveModuleBytecode[]>({
|
|
71
|
+
aptosConfig,
|
|
72
|
+
originMethod: "getModules",
|
|
73
|
+
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/modules`,
|
|
74
|
+
params: {
|
|
75
|
+
ledger_version: options?.ledgerVersion,
|
|
76
|
+
start: options?.offset,
|
|
77
|
+
limit: options?.limit ?? 1000,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Queries for a move module given account address and module name
|
|
84
|
+
*
|
|
85
|
+
* @param args.accountAddress Hex-encoded 32 byte Aptos account address
|
|
86
|
+
* @param args.moduleName The name of the module
|
|
87
|
+
* @param args.query.ledgerVersion Specifies ledger version of transactions. By default, latest version will be used
|
|
88
|
+
* @returns The move module.
|
|
89
|
+
*/
|
|
90
|
+
export async function getModule(args: {
|
|
91
|
+
aptosConfig: AptosConfig;
|
|
92
|
+
accountAddress: HexInput;
|
|
93
|
+
moduleName: string;
|
|
94
|
+
options?: LedgerVersion;
|
|
95
|
+
}): Promise<MoveModuleBytecode> {
|
|
96
|
+
// We don't memoize the account module by ledger version, as it's not a common use case, this would be handled
|
|
97
|
+
// by the developer directly
|
|
98
|
+
if (args.options?.ledgerVersion !== undefined) {
|
|
99
|
+
return getModuleInner(args);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return memoizeAsync(
|
|
103
|
+
async () => getModuleInner(args),
|
|
104
|
+
`module-${args.accountAddress}-${args.moduleName}`,
|
|
105
|
+
1000 * 60 * 5, // 5 minutes
|
|
106
|
+
)();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function getModuleInner(args: {
|
|
110
|
+
aptosConfig: AptosConfig;
|
|
111
|
+
accountAddress: HexInput;
|
|
112
|
+
moduleName: string;
|
|
113
|
+
options?: LedgerVersion;
|
|
114
|
+
}): Promise<MoveModuleBytecode> {
|
|
115
|
+
const { aptosConfig, accountAddress, moduleName, options } = args;
|
|
116
|
+
|
|
117
|
+
const { data } = await getAptosFullNode<{}, MoveModuleBytecode>({
|
|
118
|
+
aptosConfig,
|
|
119
|
+
originMethod: "getModule",
|
|
120
|
+
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/module/${moduleName}`,
|
|
121
|
+
params: { ledger_version: options?.ledgerVersion },
|
|
122
|
+
});
|
|
123
|
+
return data;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function getTransactions(args: {
|
|
127
|
+
aptosConfig: AptosConfig;
|
|
128
|
+
accountAddress: HexInput;
|
|
129
|
+
options?: PaginationArgs;
|
|
130
|
+
}): Promise<TransactionResponse[]> {
|
|
131
|
+
const { aptosConfig, accountAddress, options } = args;
|
|
132
|
+
return paginateWithCursor<{}, TransactionResponse[]>({
|
|
133
|
+
aptosConfig,
|
|
134
|
+
originMethod: "getTransactions",
|
|
135
|
+
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/transactions`,
|
|
136
|
+
params: { start: options?.offset, limit: options?.limit },
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function getResources(args: {
|
|
141
|
+
aptosConfig: AptosConfig;
|
|
142
|
+
accountAddress: HexInput;
|
|
143
|
+
options?: PaginationArgs & LedgerVersion;
|
|
144
|
+
}): Promise<MoveResource[]> {
|
|
145
|
+
const { aptosConfig, accountAddress, options } = args;
|
|
146
|
+
return paginateWithCursor<{}, MoveResource[]>({
|
|
147
|
+
aptosConfig,
|
|
148
|
+
originMethod: "getResources",
|
|
149
|
+
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/resources`,
|
|
150
|
+
params: {
|
|
151
|
+
ledger_version: options?.ledgerVersion,
|
|
152
|
+
start: options?.offset,
|
|
153
|
+
limit: options?.limit ?? 999,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export async function getResource(args: {
|
|
159
|
+
aptosConfig: AptosConfig;
|
|
160
|
+
accountAddress: HexInput;
|
|
161
|
+
resourceType: MoveResourceType;
|
|
162
|
+
options?: LedgerVersion;
|
|
163
|
+
}): Promise<MoveResource> {
|
|
164
|
+
const { aptosConfig, accountAddress, resourceType, options } = args;
|
|
165
|
+
const { data } = await getAptosFullNode<{}, MoveResource>({
|
|
166
|
+
aptosConfig,
|
|
167
|
+
originMethod: "getResource",
|
|
168
|
+
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/resource/${resourceType}`,
|
|
169
|
+
params: { ledger_version: options?.ledgerVersion },
|
|
170
|
+
});
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function lookupOriginalAccountAddress(args: {
|
|
175
|
+
aptosConfig: AptosConfig;
|
|
176
|
+
authenticationKey: HexInput;
|
|
177
|
+
options?: LedgerVersion;
|
|
178
|
+
}): Promise<AccountAddress> {
|
|
179
|
+
const { aptosConfig, authenticationKey, options } = args;
|
|
180
|
+
const resource = await getResource({
|
|
181
|
+
aptosConfig,
|
|
182
|
+
accountAddress: "0x1",
|
|
183
|
+
resourceType: "0x1::account::OriginatingAddress",
|
|
184
|
+
options,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const {
|
|
188
|
+
address_map: { handle },
|
|
189
|
+
} = resource.data as any;
|
|
190
|
+
|
|
191
|
+
// If the address is not found in the address map, which means its not rotated
|
|
192
|
+
// then return the address as is
|
|
193
|
+
try {
|
|
194
|
+
const originalAddress = await getTableItem({
|
|
195
|
+
aptosConfig,
|
|
196
|
+
handle,
|
|
197
|
+
data: {
|
|
198
|
+
key: Hex.fromHexInput(authenticationKey).toString(),
|
|
199
|
+
key_type: "address",
|
|
200
|
+
value_type: "address",
|
|
201
|
+
},
|
|
202
|
+
options,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return AccountAddress.fromHexInput(originalAddress);
|
|
206
|
+
} catch (err) {
|
|
207
|
+
if (err instanceof AptosApiError && err.data.error_code === "table_item_not_found") {
|
|
208
|
+
return AccountAddress.fromHexInput(authenticationKey);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export async function getAccountTokensCount(args: {
|
|
216
|
+
aptosConfig: AptosConfig;
|
|
217
|
+
accountAddress: HexInput;
|
|
218
|
+
}): Promise<number> {
|
|
219
|
+
const { aptosConfig, accountAddress } = args;
|
|
220
|
+
|
|
221
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
222
|
+
|
|
223
|
+
const whereCondition: any = {
|
|
224
|
+
owner_address: { _eq: address },
|
|
225
|
+
amount: { _gt: "0" },
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const graphqlQuery = {
|
|
229
|
+
query: GetAccountTokensCount,
|
|
230
|
+
variables: { where_condition: whereCondition },
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const data = await queryIndexer<GetAccountTokensCountQuery>({
|
|
234
|
+
aptosConfig,
|
|
235
|
+
query: graphqlQuery,
|
|
236
|
+
originMethod: "getAccountTokensCount",
|
|
237
|
+
});
|
|
238
|
+
if (!data.current_token_ownerships_v2_aggregate.aggregate) {
|
|
239
|
+
throw Error("Failed to get the count of account tokens");
|
|
240
|
+
}
|
|
241
|
+
return data.current_token_ownerships_v2_aggregate.aggregate.count;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export async function getAccountOwnedTokens(args: {
|
|
245
|
+
aptosConfig: AptosConfig;
|
|
246
|
+
accountAddress: HexInput;
|
|
247
|
+
options?: {
|
|
248
|
+
tokenStandard?: TokenStandard;
|
|
249
|
+
pagination?: PaginationArgs;
|
|
250
|
+
orderBy?: OrderBy<GetAccountOwnedTokensQueryResponse[0]>;
|
|
251
|
+
};
|
|
252
|
+
}): Promise<GetAccountOwnedTokensQueryResponse> {
|
|
253
|
+
const { aptosConfig, accountAddress, options } = args;
|
|
254
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
255
|
+
|
|
256
|
+
const whereCondition: any = {
|
|
257
|
+
owner_address: { _eq: address },
|
|
258
|
+
amount: { _gt: 0 },
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
if (options?.tokenStandard) {
|
|
262
|
+
whereCondition.token_standard = { _eq: options?.tokenStandard };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const graphqlQuery = {
|
|
266
|
+
query: GetAccountOwnedTokens,
|
|
267
|
+
variables: {
|
|
268
|
+
where_condition: whereCondition,
|
|
269
|
+
offset: options?.pagination?.offset,
|
|
270
|
+
limit: options?.pagination?.limit,
|
|
271
|
+
order_by: options?.orderBy,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const data = await queryIndexer<GetAccountOwnedTokensQuery>({
|
|
276
|
+
aptosConfig,
|
|
277
|
+
query: graphqlQuery,
|
|
278
|
+
originMethod: "getAccountOwnedTokens",
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
return data.current_token_ownerships_v2;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export async function getAccountOwnedTokensFromCollectionAddress(args: {
|
|
285
|
+
aptosConfig: AptosConfig;
|
|
286
|
+
accountAddress: HexInput;
|
|
287
|
+
collectionAddress: HexInput;
|
|
288
|
+
options?: {
|
|
289
|
+
tokenStandard?: TokenStandard;
|
|
290
|
+
pagination?: PaginationArgs;
|
|
291
|
+
orderBy?: OrderBy<GetAccountOwnedTokensFromCollectionResponse[0]>;
|
|
292
|
+
};
|
|
293
|
+
}): Promise<GetAccountOwnedTokensFromCollectionResponse> {
|
|
294
|
+
const { aptosConfig, accountAddress, collectionAddress, options } = args;
|
|
295
|
+
const ownerAddress = AccountAddress.fromHexInput(accountAddress).toString();
|
|
296
|
+
const collAddress = Hex.fromHexInput(collectionAddress).toString();
|
|
297
|
+
|
|
298
|
+
const whereCondition: any = {
|
|
299
|
+
owner_address: { _eq: ownerAddress },
|
|
300
|
+
current_token_data: { collection_id: { _eq: collAddress } },
|
|
301
|
+
amount: { _gt: 0 },
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
if (options?.tokenStandard) {
|
|
305
|
+
whereCondition.token_standard = { _eq: options?.tokenStandard };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const graphqlQuery = {
|
|
309
|
+
query: GetAccountOwnedTokensFromCollection,
|
|
310
|
+
variables: {
|
|
311
|
+
where_condition: whereCondition,
|
|
312
|
+
offset: options?.pagination?.offset,
|
|
313
|
+
limit: options?.pagination?.limit,
|
|
314
|
+
order_by: options?.orderBy,
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const data = await queryIndexer<GetAccountOwnedTokensFromCollectionQuery>({
|
|
319
|
+
aptosConfig,
|
|
320
|
+
query: graphqlQuery,
|
|
321
|
+
originMethod: "getAccountOwnedTokensFromCollectionAddress",
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
return data.current_token_ownerships_v2;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export async function getAccountCollectionsWithOwnedTokens(args: {
|
|
328
|
+
aptosConfig: AptosConfig;
|
|
329
|
+
accountAddress: HexInput;
|
|
330
|
+
options?: {
|
|
331
|
+
tokenStandard?: TokenStandard;
|
|
332
|
+
pagination?: PaginationArgs;
|
|
333
|
+
orderBy?: OrderBy<GetAccountCollectionsWithOwnedTokenResponse[0]>;
|
|
334
|
+
};
|
|
335
|
+
}): Promise<GetAccountCollectionsWithOwnedTokenResponse> {
|
|
336
|
+
const { aptosConfig, accountAddress, options } = args;
|
|
337
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
338
|
+
|
|
339
|
+
const whereCondition: any = {
|
|
340
|
+
owner_address: { _eq: address },
|
|
341
|
+
amount: { _gt: 0 },
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
if (options?.tokenStandard) {
|
|
345
|
+
whereCondition.current_collection = {
|
|
346
|
+
token_standard: { _eq: options?.tokenStandard },
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const graphqlQuery = {
|
|
351
|
+
query: GetAccountCollectionsWithOwnedTokens,
|
|
352
|
+
variables: {
|
|
353
|
+
where_condition: whereCondition,
|
|
354
|
+
offset: options?.pagination?.offset,
|
|
355
|
+
limit: options?.pagination?.limit,
|
|
356
|
+
order_by: options?.orderBy,
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const data = await queryIndexer<GetAccountCollectionsWithOwnedTokensQuery>({
|
|
361
|
+
aptosConfig,
|
|
362
|
+
query: graphqlQuery,
|
|
363
|
+
originMethod: "getAccountCollectionsWithOwnedTokens",
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
return data.current_collection_ownership_v2_view;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export async function getAccountTransactionsCount(args: {
|
|
370
|
+
aptosConfig: AptosConfig;
|
|
371
|
+
accountAddress: HexInput;
|
|
372
|
+
}): Promise<number> {
|
|
373
|
+
const { aptosConfig, accountAddress } = args;
|
|
374
|
+
|
|
375
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
376
|
+
|
|
377
|
+
const graphqlQuery = {
|
|
378
|
+
query: GetAccountTransactionsCount,
|
|
379
|
+
variables: { address },
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
const data = await queryIndexer<GetAccountTransactionsCountQuery>({
|
|
383
|
+
aptosConfig,
|
|
384
|
+
query: graphqlQuery,
|
|
385
|
+
originMethod: "getAccountTransactionsCount",
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
if (!data.account_transactions_aggregate.aggregate) {
|
|
389
|
+
throw Error("Failed to get the count of account transactions");
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return data.account_transactions_aggregate.aggregate.count;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export async function getAccountCoinsData(args: {
|
|
396
|
+
aptosConfig: AptosConfig;
|
|
397
|
+
accountAddress: HexInput;
|
|
398
|
+
options?: {
|
|
399
|
+
pagination?: PaginationArgs;
|
|
400
|
+
orderBy?: OrderBy<GetAccountCoinsDataResponse[0]>;
|
|
401
|
+
};
|
|
402
|
+
}): Promise<GetAccountCoinsDataResponse> {
|
|
403
|
+
const { aptosConfig, accountAddress, options } = args;
|
|
404
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
405
|
+
|
|
406
|
+
const whereCondition: any = {
|
|
407
|
+
owner_address: { _eq: address },
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const graphqlQuery = {
|
|
411
|
+
query: GetAccountCoinsData,
|
|
412
|
+
variables: {
|
|
413
|
+
where_condition: whereCondition,
|
|
414
|
+
offset: options?.pagination?.offset,
|
|
415
|
+
limit: options?.pagination?.limit,
|
|
416
|
+
order_by: options?.orderBy,
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const data = await queryIndexer<GetAccountCoinsDataQuery>({
|
|
421
|
+
aptosConfig,
|
|
422
|
+
query: graphqlQuery,
|
|
423
|
+
originMethod: "getAccountCoinsData",
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
return data.current_fungible_asset_balances;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export async function getAccountCoinsCount(args: {
|
|
430
|
+
aptosConfig: AptosConfig;
|
|
431
|
+
accountAddress: HexInput;
|
|
432
|
+
}): Promise<number> {
|
|
433
|
+
const { aptosConfig, accountAddress } = args;
|
|
434
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
435
|
+
|
|
436
|
+
const graphqlQuery = {
|
|
437
|
+
query: GetAccountCoinsCount,
|
|
438
|
+
variables: { address },
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const data = await queryIndexer<GetAccountCoinsCountQuery>({
|
|
442
|
+
aptosConfig,
|
|
443
|
+
query: graphqlQuery,
|
|
444
|
+
originMethod: "getAccountCoinsCount",
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
if (!data.current_fungible_asset_balances_aggregate.aggregate) {
|
|
448
|
+
throw Error("Failed to get the count of account coins");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return data.current_fungible_asset_balances_aggregate.aggregate.count;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export async function getAccountOwnedObjects(args: {
|
|
455
|
+
aptosConfig: AptosConfig;
|
|
456
|
+
accountAddress: HexInput;
|
|
457
|
+
options?: {
|
|
458
|
+
pagination?: PaginationArgs;
|
|
459
|
+
orderBy?: OrderBy<GetAccountOwnedObjectsResponse[0]>;
|
|
460
|
+
};
|
|
461
|
+
}): Promise<GetAccountOwnedObjectsResponse> {
|
|
462
|
+
const { aptosConfig, accountAddress, options } = args;
|
|
463
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
464
|
+
|
|
465
|
+
const whereCondition: any = {
|
|
466
|
+
owner_address: { _eq: address },
|
|
467
|
+
};
|
|
468
|
+
const graphqlQuery = {
|
|
469
|
+
query: GetAccountOwnedObjects,
|
|
470
|
+
variables: {
|
|
471
|
+
where_condition: whereCondition,
|
|
472
|
+
offset: options?.pagination?.offset,
|
|
473
|
+
limit: options?.pagination?.limit,
|
|
474
|
+
order_by: options?.orderBy,
|
|
475
|
+
},
|
|
476
|
+
};
|
|
477
|
+
const data = await queryIndexer<GetAccountOwnedObjectsQuery>({
|
|
478
|
+
aptosConfig,
|
|
479
|
+
query: graphqlQuery,
|
|
480
|
+
originMethod: "getAccountOwnedObjects",
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
return data.current_objects;
|
|
484
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AptosConfig } from "../api/aptosConfig";
|
|
2
|
+
import { U64 } from "../bcs/serializable/movePrimitives";
|
|
3
|
+
import { Account, AccountAddress } from "../core";
|
|
4
|
+
import { GenerateTransactionOptions, SingleSignerTransaction } from "../transactions/types";
|
|
5
|
+
import { StructTag, TypeTagStruct } from "../transactions/typeTag/typeTag";
|
|
6
|
+
import { HexInput, AnyNumber, MoveResourceType } from "../types";
|
|
7
|
+
import { APTOS_COIN } from "../utils/const";
|
|
8
|
+
import { generateTransaction } from "./transactionSubmission";
|
|
9
|
+
|
|
10
|
+
export async function transferCoinTransaction(args: {
|
|
11
|
+
aptosConfig: AptosConfig;
|
|
12
|
+
sender: Account;
|
|
13
|
+
recipient: HexInput;
|
|
14
|
+
amount: AnyNumber;
|
|
15
|
+
coinType?: MoveResourceType;
|
|
16
|
+
options?: GenerateTransactionOptions;
|
|
17
|
+
}): Promise<SingleSignerTransaction> {
|
|
18
|
+
const { aptosConfig, sender, recipient, amount, coinType, options } = args;
|
|
19
|
+
const coinStructType = coinType ?? APTOS_COIN;
|
|
20
|
+
const transaction = await generateTransaction({
|
|
21
|
+
aptosConfig,
|
|
22
|
+
sender: sender.accountAddress.toString(),
|
|
23
|
+
data: {
|
|
24
|
+
function: "0x1::aptos_account::transfer_coins",
|
|
25
|
+
typeArguments: [new TypeTagStruct(StructTag.fromString(coinStructType))],
|
|
26
|
+
arguments: [AccountAddress.fromHexInput(recipient), new U64(amount)],
|
|
27
|
+
},
|
|
28
|
+
options,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return transaction as SingleSignerTransaction;
|
|
32
|
+
}
|