@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,302 @@
|
|
|
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/digitalAsset}. By moving the methods out into a separate file,
|
|
7
|
+
* other namespaces and processes can access these methods without depending on the entire
|
|
8
|
+
* digitalAsset namespace and without having a dependency cycle error.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { AptosConfig } from "../api/aptosConfig";
|
|
12
|
+
import { MoveString, MoveVector, Bool, U64, U8 } from "../bcs";
|
|
13
|
+
import { Account, Hex } from "../core";
|
|
14
|
+
import { GenerateTransactionOptions, SingleSignerTransaction } from "../transactions/types";
|
|
15
|
+
import {
|
|
16
|
+
AnyNumber,
|
|
17
|
+
GetCollectionDataResponse,
|
|
18
|
+
GetCurrentTokenOwnershipResponse,
|
|
19
|
+
GetOwnedTokensResponse,
|
|
20
|
+
GetTokenActivityResponse,
|
|
21
|
+
GetTokenDataResponse,
|
|
22
|
+
HexInput,
|
|
23
|
+
OrderBy,
|
|
24
|
+
PaginationArgs,
|
|
25
|
+
TokenStandard,
|
|
26
|
+
} from "../types";
|
|
27
|
+
import {
|
|
28
|
+
GetCollectionDataQuery,
|
|
29
|
+
GetCurrentTokenOwnershipQuery,
|
|
30
|
+
GetTokenActivityQuery,
|
|
31
|
+
GetTokenDataQuery,
|
|
32
|
+
} from "../types/generated/operations";
|
|
33
|
+
import {
|
|
34
|
+
GetCollectionData,
|
|
35
|
+
GetCurrentTokenOwnership,
|
|
36
|
+
GetTokenActivity,
|
|
37
|
+
GetTokenData,
|
|
38
|
+
} from "../types/generated/queries";
|
|
39
|
+
import { queryIndexer } from "./general";
|
|
40
|
+
import { generateTransaction } from "./transactionSubmission";
|
|
41
|
+
import { MAX_U64_BIG_INT } from "../bcs/consts";
|
|
42
|
+
import { CurrentTokenOwnershipsV2BoolExp, TokenActivitiesV2BoolExp } from "../types/generated/types";
|
|
43
|
+
|
|
44
|
+
// TODO: Support properties when minting.
|
|
45
|
+
export interface MintTokenOptions {
|
|
46
|
+
propertyKeys?: Array<string>;
|
|
47
|
+
propertyTypes?: Array<string>;
|
|
48
|
+
propertyValues?: Array<string>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function mintTokenTransaction(args: {
|
|
52
|
+
aptosConfig: AptosConfig;
|
|
53
|
+
creator: Account;
|
|
54
|
+
collection: string;
|
|
55
|
+
description: string;
|
|
56
|
+
name: string;
|
|
57
|
+
uri: string;
|
|
58
|
+
options?: GenerateTransactionOptions;
|
|
59
|
+
}): Promise<SingleSignerTransaction> {
|
|
60
|
+
const { aptosConfig, options, creator } = args;
|
|
61
|
+
const transaction = await generateTransaction({
|
|
62
|
+
aptosConfig,
|
|
63
|
+
sender: creator.accountAddress.toString(),
|
|
64
|
+
data: {
|
|
65
|
+
function: "0x4::aptos_token::mint",
|
|
66
|
+
arguments: [
|
|
67
|
+
new MoveString(args.collection),
|
|
68
|
+
new MoveString(args.description),
|
|
69
|
+
new MoveString(args.name),
|
|
70
|
+
new MoveString(args.uri),
|
|
71
|
+
MoveVector.MoveString([]),
|
|
72
|
+
MoveVector.MoveString([]),
|
|
73
|
+
new MoveVector<MoveVector<U8>>([]),
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
options,
|
|
77
|
+
});
|
|
78
|
+
return transaction as SingleSignerTransaction;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function getTokenData(args: {
|
|
82
|
+
aptosConfig: AptosConfig;
|
|
83
|
+
tokenAddress: HexInput;
|
|
84
|
+
}): Promise<GetTokenDataResponse> {
|
|
85
|
+
const { aptosConfig, tokenAddress } = args;
|
|
86
|
+
|
|
87
|
+
const whereCondition: any = {
|
|
88
|
+
token_data_id: { _eq: Hex.fromHexInput(tokenAddress).toString() },
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const graphqlQuery = {
|
|
92
|
+
query: GetTokenData,
|
|
93
|
+
variables: {
|
|
94
|
+
where_condition: whereCondition,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const data = await queryIndexer<GetTokenDataQuery>({
|
|
99
|
+
aptosConfig,
|
|
100
|
+
query: graphqlQuery,
|
|
101
|
+
originMethod: "getTokenData",
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return data.current_token_datas_v2[0];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function getCurrentTokenOwnership(args: {
|
|
108
|
+
aptosConfig: AptosConfig;
|
|
109
|
+
tokenAddress: HexInput;
|
|
110
|
+
}): Promise<GetCurrentTokenOwnershipResponse> {
|
|
111
|
+
const { aptosConfig, tokenAddress } = args;
|
|
112
|
+
|
|
113
|
+
const whereCondition: CurrentTokenOwnershipsV2BoolExp = {
|
|
114
|
+
token_data_id: { _eq: Hex.fromHexInput(tokenAddress).toString() },
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const graphqlQuery = {
|
|
118
|
+
query: GetCurrentTokenOwnership,
|
|
119
|
+
variables: {
|
|
120
|
+
where_condition: whereCondition,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const data = await queryIndexer<GetCurrentTokenOwnershipQuery>({
|
|
125
|
+
aptosConfig,
|
|
126
|
+
query: graphqlQuery,
|
|
127
|
+
originMethod: "getCurrentTokenOwnership",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return data.current_token_ownerships_v2[0];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function getOwnedTokens(args: {
|
|
134
|
+
aptosConfig: AptosConfig;
|
|
135
|
+
ownerAddress: HexInput;
|
|
136
|
+
options?: {
|
|
137
|
+
pagination?: PaginationArgs;
|
|
138
|
+
orderBy?: OrderBy<GetTokenActivityResponse[0]>;
|
|
139
|
+
};
|
|
140
|
+
}): Promise<GetOwnedTokensResponse> {
|
|
141
|
+
const { aptosConfig, ownerAddress, options } = args;
|
|
142
|
+
|
|
143
|
+
const whereCondition: CurrentTokenOwnershipsV2BoolExp = {
|
|
144
|
+
owner_address: { _eq: Hex.fromHexInput(ownerAddress).toString() },
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const graphqlQuery = {
|
|
148
|
+
query: GetCurrentTokenOwnership,
|
|
149
|
+
variables: {
|
|
150
|
+
where_condition: whereCondition,
|
|
151
|
+
offset: options?.pagination?.offset,
|
|
152
|
+
limit: options?.pagination?.limit,
|
|
153
|
+
order_by: options?.orderBy,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const data = await queryIndexer<GetCurrentTokenOwnershipQuery>({
|
|
158
|
+
aptosConfig,
|
|
159
|
+
query: graphqlQuery,
|
|
160
|
+
originMethod: "getOwnedTokens",
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return data.current_token_ownerships_v2;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function getTokenActivity(args: {
|
|
167
|
+
aptosConfig: AptosConfig;
|
|
168
|
+
tokenAddress: HexInput;
|
|
169
|
+
options?: {
|
|
170
|
+
pagination?: PaginationArgs;
|
|
171
|
+
orderBy?: OrderBy<GetTokenActivityResponse[0]>;
|
|
172
|
+
};
|
|
173
|
+
}): Promise<GetTokenActivityResponse> {
|
|
174
|
+
const { aptosConfig, tokenAddress, options } = args;
|
|
175
|
+
|
|
176
|
+
const whereCondition: TokenActivitiesV2BoolExp = {
|
|
177
|
+
token_data_id: { _eq: Hex.fromHexInput(tokenAddress).toString() },
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const graphqlQuery = {
|
|
181
|
+
query: GetTokenActivity,
|
|
182
|
+
variables: {
|
|
183
|
+
where_condition: whereCondition,
|
|
184
|
+
offset: options?.pagination?.offset,
|
|
185
|
+
limit: options?.pagination?.limit,
|
|
186
|
+
order_by: options?.orderBy,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const data = await queryIndexer<GetTokenActivityQuery>({
|
|
191
|
+
aptosConfig,
|
|
192
|
+
query: graphqlQuery,
|
|
193
|
+
originMethod: "getTokenActivity",
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return data.token_activities_v2;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface CreateCollectionOptions {
|
|
200
|
+
maxSupply?: AnyNumber;
|
|
201
|
+
mutableDescription?: boolean;
|
|
202
|
+
mutableRoyalty?: boolean;
|
|
203
|
+
mutableURI?: boolean;
|
|
204
|
+
mutableTokenDescription?: boolean;
|
|
205
|
+
mutableTokenName?: boolean;
|
|
206
|
+
mutableTokenProperties?: boolean;
|
|
207
|
+
mutableTokenURI?: boolean;
|
|
208
|
+
tokensBurnableByCreator?: boolean;
|
|
209
|
+
tokensFreezableByCreator?: boolean;
|
|
210
|
+
royaltyNumerator?: number;
|
|
211
|
+
royaltyDenominator?: number;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function createCollectionTransaction(
|
|
215
|
+
args: {
|
|
216
|
+
aptosConfig: AptosConfig;
|
|
217
|
+
creator: Account;
|
|
218
|
+
description: string;
|
|
219
|
+
name: string;
|
|
220
|
+
uri: string;
|
|
221
|
+
options?: GenerateTransactionOptions;
|
|
222
|
+
} & CreateCollectionOptions,
|
|
223
|
+
): Promise<SingleSignerTransaction> {
|
|
224
|
+
const { aptosConfig, options, creator } = args;
|
|
225
|
+
const transaction = await generateTransaction({
|
|
226
|
+
aptosConfig,
|
|
227
|
+
sender: creator.accountAddress.toString(),
|
|
228
|
+
data: {
|
|
229
|
+
function: "0x4::aptos_token::create_collection",
|
|
230
|
+
arguments: [
|
|
231
|
+
// Do not change the order
|
|
232
|
+
new MoveString(args.description),
|
|
233
|
+
new U64(args.maxSupply ?? MAX_U64_BIG_INT),
|
|
234
|
+
new MoveString(args.name),
|
|
235
|
+
new MoveString(args.uri),
|
|
236
|
+
new Bool(args.mutableDescription ?? true),
|
|
237
|
+
new Bool(args.mutableRoyalty ?? true),
|
|
238
|
+
new Bool(args.mutableURI ?? true),
|
|
239
|
+
new Bool(args.mutableTokenDescription ?? true),
|
|
240
|
+
new Bool(args.mutableTokenName ?? true),
|
|
241
|
+
new Bool(args.mutableTokenProperties ?? true),
|
|
242
|
+
new Bool(args.mutableTokenURI ?? true),
|
|
243
|
+
new Bool(args.tokensBurnableByCreator ?? true),
|
|
244
|
+
new Bool(args.tokensFreezableByCreator ?? true),
|
|
245
|
+
new U64(args.royaltyNumerator ?? 0),
|
|
246
|
+
new U64(args.royaltyDenominator ?? 1),
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
options,
|
|
250
|
+
});
|
|
251
|
+
return transaction as SingleSignerTransaction;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export async function getCollectionData(args: {
|
|
255
|
+
aptosConfig: AptosConfig;
|
|
256
|
+
creatorAddress: HexInput;
|
|
257
|
+
collectionName: string;
|
|
258
|
+
options?: {
|
|
259
|
+
tokenStandard?: TokenStandard;
|
|
260
|
+
};
|
|
261
|
+
}): Promise<GetCollectionDataResponse> {
|
|
262
|
+
const { aptosConfig, creatorAddress, collectionName, options } = args;
|
|
263
|
+
const address = Hex.fromHexInput(creatorAddress).toString();
|
|
264
|
+
|
|
265
|
+
const whereCondition: any = {
|
|
266
|
+
collection_name: { _eq: collectionName },
|
|
267
|
+
creator_address: { _eq: address },
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
if (options?.tokenStandard) {
|
|
271
|
+
whereCondition.token_standard = { _eq: options?.tokenStandard ?? "v2" };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const graphqlQuery = {
|
|
275
|
+
query: GetCollectionData,
|
|
276
|
+
variables: {
|
|
277
|
+
where_condition: whereCondition,
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
const data = await queryIndexer<GetCollectionDataQuery>({
|
|
281
|
+
aptosConfig,
|
|
282
|
+
query: graphqlQuery,
|
|
283
|
+
originMethod: "getCollectionData",
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
if (data.current_collections_v2.length === 0) {
|
|
287
|
+
throw Error("Collection not found");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return data.current_collections_v2[0];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export async function getCollectionId(args: {
|
|
294
|
+
aptosConfig: AptosConfig;
|
|
295
|
+
creatorAddress: HexInput;
|
|
296
|
+
collectionName: string;
|
|
297
|
+
options?: {
|
|
298
|
+
tokenStandard?: TokenStandard;
|
|
299
|
+
};
|
|
300
|
+
}): Promise<string> {
|
|
301
|
+
return (await getCollectionData(args)).collection_id;
|
|
302
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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/event}. By moving the methods out into a separate file,
|
|
7
|
+
* other namespaces and processes can access these methods without depending on the entire
|
|
8
|
+
* event namespace and without having a dependency cycle error.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { AptosConfig } from "../api/aptosConfig";
|
|
12
|
+
import { AccountAddress } from "../core";
|
|
13
|
+
import { AnyNumber, GetEventsResponse, HexInput, PaginationArgs, MoveResourceType, OrderBy } from "../types";
|
|
14
|
+
import { GetEventsQuery } from "../types/generated/operations";
|
|
15
|
+
import { GetEvents } from "../types/generated/queries";
|
|
16
|
+
import { EventsBoolExp } from "../types/generated/types";
|
|
17
|
+
import { queryIndexer } from "./general";
|
|
18
|
+
|
|
19
|
+
export async function getAccountEventsByCreationNumber(args: {
|
|
20
|
+
aptosConfig: AptosConfig;
|
|
21
|
+
accountAddress: HexInput;
|
|
22
|
+
creationNumber: AnyNumber;
|
|
23
|
+
}): Promise<GetEventsResponse> {
|
|
24
|
+
const { accountAddress, aptosConfig, creationNumber } = args;
|
|
25
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
26
|
+
|
|
27
|
+
const whereCondition: EventsBoolExp = {
|
|
28
|
+
account_address: { _eq: address },
|
|
29
|
+
creation_number: { _eq: creationNumber },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return getEvents({ aptosConfig, options: { where: whereCondition } });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getAccountEventsByEventType(args: {
|
|
36
|
+
aptosConfig: AptosConfig;
|
|
37
|
+
accountAddress: HexInput;
|
|
38
|
+
eventType: MoveResourceType;
|
|
39
|
+
options?: {
|
|
40
|
+
pagination?: PaginationArgs;
|
|
41
|
+
orderBy?: OrderBy<GetEventsResponse[0]>;
|
|
42
|
+
};
|
|
43
|
+
}): Promise<GetEventsResponse> {
|
|
44
|
+
const { accountAddress, aptosConfig, eventType, options } = args;
|
|
45
|
+
const address = AccountAddress.fromHexInput(accountAddress).toString();
|
|
46
|
+
|
|
47
|
+
const whereCondition: EventsBoolExp = {
|
|
48
|
+
account_address: { _eq: address },
|
|
49
|
+
type: { _eq: eventType },
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const customOptions = {
|
|
53
|
+
where: whereCondition,
|
|
54
|
+
pagination: options?.pagination,
|
|
55
|
+
orderBy: options?.orderBy,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return getEvents({ aptosConfig, options: customOptions });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function getEvents(args: {
|
|
62
|
+
aptosConfig: AptosConfig;
|
|
63
|
+
options?: {
|
|
64
|
+
where?: EventsBoolExp;
|
|
65
|
+
pagination?: PaginationArgs;
|
|
66
|
+
orderBy?: OrderBy<GetEventsResponse[0]>;
|
|
67
|
+
};
|
|
68
|
+
}): Promise<GetEventsResponse> {
|
|
69
|
+
const { aptosConfig, options } = args;
|
|
70
|
+
|
|
71
|
+
const graphqlQuery = {
|
|
72
|
+
query: GetEvents,
|
|
73
|
+
variables: {
|
|
74
|
+
where_condition: options?.where,
|
|
75
|
+
offset: options?.pagination?.offset,
|
|
76
|
+
limit: options?.pagination?.limit,
|
|
77
|
+
order_by: options?.orderBy,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const data = await queryIndexer<GetEventsQuery>({
|
|
82
|
+
aptosConfig,
|
|
83
|
+
query: graphqlQuery,
|
|
84
|
+
originMethod: "getEvents",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return data.events;
|
|
88
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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/faucet}. By moving the methods out into a separate file,
|
|
7
|
+
* other namespaces and processes can access these methods without depending on the entire
|
|
8
|
+
* faucet namespace and without having a dependency cycle error.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { AptosConfig } from "../api/aptosConfig";
|
|
12
|
+
import { postAptosFaucet } from "../client";
|
|
13
|
+
import { AccountAddress } from "../core";
|
|
14
|
+
import { HexInput } from "../types";
|
|
15
|
+
import { DEFAULT_TXN_TIMEOUT_SEC } from "../utils/const";
|
|
16
|
+
import { waitForTransaction } from "./transaction";
|
|
17
|
+
|
|
18
|
+
export async function fundAccount(args: {
|
|
19
|
+
aptosConfig: AptosConfig;
|
|
20
|
+
accountAddress: HexInput;
|
|
21
|
+
amount: number;
|
|
22
|
+
timeoutSecs?: number;
|
|
23
|
+
}): Promise<string> {
|
|
24
|
+
const { aptosConfig, accountAddress, amount } = args;
|
|
25
|
+
const timeoutSecs = args.timeoutSecs ?? DEFAULT_TXN_TIMEOUT_SEC;
|
|
26
|
+
const { data } = await postAptosFaucet<any, { txn_hashes: Array<string> }>({
|
|
27
|
+
aptosConfig,
|
|
28
|
+
path: "fund",
|
|
29
|
+
body: {
|
|
30
|
+
address: AccountAddress.fromHexInput(accountAddress).toString(),
|
|
31
|
+
amount,
|
|
32
|
+
},
|
|
33
|
+
originMethod: "fundAccount",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const txnHash = data.txn_hashes[0];
|
|
37
|
+
|
|
38
|
+
await waitForTransaction({ aptosConfig, transactionHash: txnHash, options: { timeoutSecs } });
|
|
39
|
+
|
|
40
|
+
return txnHash;
|
|
41
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
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/fungible_asset}. By moving the methods out into a separate file,
|
|
7
|
+
* other namespaces and processes can access these methods without depending on the entire
|
|
8
|
+
* fungible_asset namespace and without having a dependency cycle error.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { AptosConfig } from "../api/aptosConfig";
|
|
12
|
+
import {
|
|
13
|
+
GetCurrentFungibleAssetBalancesResponse,
|
|
14
|
+
GetFungibleAssetActivitiesResponse,
|
|
15
|
+
GetFungibleAssetMetadataResponse,
|
|
16
|
+
PaginationArgs,
|
|
17
|
+
} from "../types";
|
|
18
|
+
import { queryIndexer } from "./general";
|
|
19
|
+
import {
|
|
20
|
+
GetCurrentFungibleAssetBalances,
|
|
21
|
+
GetFungibleAssetActivities,
|
|
22
|
+
GetFungibleAssetMetadata,
|
|
23
|
+
} from "../types/generated/queries";
|
|
24
|
+
import {
|
|
25
|
+
GetCurrentFungibleAssetBalancesQuery,
|
|
26
|
+
GetFungibleAssetActivitiesQuery,
|
|
27
|
+
GetFungibleAssetMetadataQuery,
|
|
28
|
+
} from "../types/generated/operations";
|
|
29
|
+
import {
|
|
30
|
+
CurrentFungibleAssetBalancesBoolExp,
|
|
31
|
+
FungibleAssetActivitiesBoolExp,
|
|
32
|
+
FungibleAssetMetadataBoolExp,
|
|
33
|
+
} from "../types/generated/types";
|
|
34
|
+
|
|
35
|
+
export async function getFungibleAssetMetadata(args: {
|
|
36
|
+
aptosConfig: AptosConfig;
|
|
37
|
+
options?: {
|
|
38
|
+
pagination?: PaginationArgs;
|
|
39
|
+
where?: FungibleAssetMetadataBoolExp;
|
|
40
|
+
};
|
|
41
|
+
}): Promise<GetFungibleAssetMetadataResponse> {
|
|
42
|
+
const { aptosConfig, options } = args;
|
|
43
|
+
|
|
44
|
+
const graphqlQuery = {
|
|
45
|
+
query: GetFungibleAssetMetadata,
|
|
46
|
+
variables: {
|
|
47
|
+
where_condition: options?.where,
|
|
48
|
+
limit: options?.pagination?.limit,
|
|
49
|
+
offset: options?.pagination?.offset,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const data = await queryIndexer<GetFungibleAssetMetadataQuery>({
|
|
54
|
+
aptosConfig,
|
|
55
|
+
query: graphqlQuery,
|
|
56
|
+
originMethod: "getFungibleAssetMetadata",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return data.fungible_asset_metadata;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function getFungibleAssetActivities(args: {
|
|
63
|
+
aptosConfig: AptosConfig;
|
|
64
|
+
options?: {
|
|
65
|
+
pagination?: PaginationArgs;
|
|
66
|
+
where?: FungibleAssetActivitiesBoolExp;
|
|
67
|
+
};
|
|
68
|
+
}): Promise<GetFungibleAssetActivitiesResponse> {
|
|
69
|
+
const { aptosConfig, options } = args;
|
|
70
|
+
|
|
71
|
+
const graphqlQuery = {
|
|
72
|
+
query: GetFungibleAssetActivities,
|
|
73
|
+
variables: {
|
|
74
|
+
where_condition: options?.where,
|
|
75
|
+
limit: options?.pagination?.limit,
|
|
76
|
+
offset: options?.pagination?.offset,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const data = await queryIndexer<GetFungibleAssetActivitiesQuery>({
|
|
81
|
+
aptosConfig,
|
|
82
|
+
query: graphqlQuery,
|
|
83
|
+
originMethod: "getFungibleAssetActivities",
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return data.fungible_asset_activities;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function getCurrentFungibleAssetBalances(args: {
|
|
90
|
+
aptosConfig: AptosConfig;
|
|
91
|
+
options?: {
|
|
92
|
+
pagination?: PaginationArgs;
|
|
93
|
+
where?: CurrentFungibleAssetBalancesBoolExp;
|
|
94
|
+
};
|
|
95
|
+
}): Promise<GetCurrentFungibleAssetBalancesResponse> {
|
|
96
|
+
const { aptosConfig, options } = args;
|
|
97
|
+
|
|
98
|
+
const graphqlQuery = {
|
|
99
|
+
query: GetCurrentFungibleAssetBalances,
|
|
100
|
+
variables: {
|
|
101
|
+
where_condition: options?.where,
|
|
102
|
+
limit: options?.pagination?.limit,
|
|
103
|
+
offset: options?.pagination?.offset,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const data = await queryIndexer<GetCurrentFungibleAssetBalancesQuery>({
|
|
108
|
+
aptosConfig,
|
|
109
|
+
query: graphqlQuery,
|
|
110
|
+
originMethod: "getCurrentFungibleAssetBalances",
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return data.current_fungible_asset_balances;
|
|
114
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
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/general}. By moving the methods out into a separate file,
|
|
7
|
+
* other namespaces and processes can access these methods without depending on the entire
|
|
8
|
+
* general namespace and without having a dependency cycle error.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { AptosConfig } from "../api/aptosConfig";
|
|
12
|
+
import { getAptosFullNode, postAptosFullNode, postAptosIndexer } from "../client";
|
|
13
|
+
import {
|
|
14
|
+
AnyNumber,
|
|
15
|
+
Block,
|
|
16
|
+
GetChainTopUserTransactionsResponse,
|
|
17
|
+
GetProcessorStatusResponse,
|
|
18
|
+
GraphqlQuery,
|
|
19
|
+
LedgerInfo,
|
|
20
|
+
LedgerVersion,
|
|
21
|
+
MoveValue,
|
|
22
|
+
TableItemRequest,
|
|
23
|
+
ViewRequest,
|
|
24
|
+
ViewRequestData,
|
|
25
|
+
} from "../types";
|
|
26
|
+
import { GetChainTopUserTransactionsQuery, GetProcessorStatusQuery } from "../types/generated/operations";
|
|
27
|
+
import { GetChainTopUserTransactions, GetProcessorStatus } from "../types/generated/queries";
|
|
28
|
+
|
|
29
|
+
export async function getLedgerInfo(args: { aptosConfig: AptosConfig }): Promise<LedgerInfo> {
|
|
30
|
+
const { aptosConfig } = args;
|
|
31
|
+
const { data } = await getAptosFullNode<{}, LedgerInfo>({
|
|
32
|
+
aptosConfig,
|
|
33
|
+
originMethod: "getLedgerInfo",
|
|
34
|
+
path: "",
|
|
35
|
+
});
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function getBlockByVersion(args: {
|
|
40
|
+
aptosConfig: AptosConfig;
|
|
41
|
+
ledgerVersion: AnyNumber;
|
|
42
|
+
options?: { withTransactions?: boolean };
|
|
43
|
+
}): Promise<Block> {
|
|
44
|
+
const { aptosConfig, ledgerVersion, options } = args;
|
|
45
|
+
const { data } = await getAptosFullNode<{}, Block>({
|
|
46
|
+
aptosConfig,
|
|
47
|
+
originMethod: "getBlockByVersion",
|
|
48
|
+
path: `blocks/by_version/${ledgerVersion}`,
|
|
49
|
+
params: { with_transactions: options?.withTransactions },
|
|
50
|
+
});
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function getBlockByHeight(args: {
|
|
55
|
+
aptosConfig: AptosConfig;
|
|
56
|
+
blockHeight: AnyNumber;
|
|
57
|
+
options?: { withTransactions?: boolean };
|
|
58
|
+
}): Promise<Block> {
|
|
59
|
+
const { aptosConfig, blockHeight, options } = args;
|
|
60
|
+
const { data } = await getAptosFullNode<{}, Block>({
|
|
61
|
+
aptosConfig,
|
|
62
|
+
originMethod: "getBlockByHeight",
|
|
63
|
+
path: `blocks/by_height/${blockHeight}`,
|
|
64
|
+
params: { with_transactions: options?.withTransactions },
|
|
65
|
+
});
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function getTableItem(args: {
|
|
70
|
+
aptosConfig: AptosConfig;
|
|
71
|
+
handle: string;
|
|
72
|
+
data: TableItemRequest;
|
|
73
|
+
options?: LedgerVersion;
|
|
74
|
+
}): Promise<any> {
|
|
75
|
+
const { aptosConfig, handle, data, options } = args;
|
|
76
|
+
const response = await postAptosFullNode<TableItemRequest, any>({
|
|
77
|
+
aptosConfig,
|
|
78
|
+
originMethod: "getTableItem",
|
|
79
|
+
path: `tables/${handle}/item`,
|
|
80
|
+
params: { ledger_version: options?.ledgerVersion },
|
|
81
|
+
body: data,
|
|
82
|
+
});
|
|
83
|
+
return response.data;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function view(args: {
|
|
87
|
+
aptosConfig: AptosConfig;
|
|
88
|
+
payload: ViewRequestData;
|
|
89
|
+
options?: LedgerVersion;
|
|
90
|
+
}): Promise<MoveValue[]> {
|
|
91
|
+
const { aptosConfig, payload, options } = args;
|
|
92
|
+
const { data } = await postAptosFullNode<ViewRequest, MoveValue[]>({
|
|
93
|
+
aptosConfig,
|
|
94
|
+
originMethod: "view",
|
|
95
|
+
path: "view",
|
|
96
|
+
params: { ledger_version: options?.ledgerVersion },
|
|
97
|
+
body: {
|
|
98
|
+
function: payload.function,
|
|
99
|
+
type_arguments: payload.typeArguments ?? [],
|
|
100
|
+
arguments: payload.arguments ?? [],
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function getChainTopUserTransactions(args: {
|
|
107
|
+
aptosConfig: AptosConfig;
|
|
108
|
+
limit: number;
|
|
109
|
+
}): Promise<GetChainTopUserTransactionsResponse> {
|
|
110
|
+
const { aptosConfig, limit } = args;
|
|
111
|
+
const graphqlQuery = {
|
|
112
|
+
query: GetChainTopUserTransactions,
|
|
113
|
+
variables: { limit },
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const data = await queryIndexer<GetChainTopUserTransactionsQuery>({
|
|
117
|
+
aptosConfig,
|
|
118
|
+
query: graphqlQuery,
|
|
119
|
+
originMethod: "getChainTopUserTransactions",
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return data.user_transactions;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export async function queryIndexer<T>(args: {
|
|
126
|
+
aptosConfig: AptosConfig;
|
|
127
|
+
query: GraphqlQuery;
|
|
128
|
+
originMethod?: string;
|
|
129
|
+
}): Promise<T> {
|
|
130
|
+
const { aptosConfig, query, originMethod } = args;
|
|
131
|
+
const { data } = await postAptosIndexer<GraphqlQuery, T>({
|
|
132
|
+
aptosConfig,
|
|
133
|
+
originMethod: originMethod ?? "queryIndexer",
|
|
134
|
+
path: "",
|
|
135
|
+
body: query,
|
|
136
|
+
overrides: { WITH_CREDENTIALS: false },
|
|
137
|
+
});
|
|
138
|
+
return data;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function getProcessorStatuses(args: { aptosConfig: AptosConfig }): Promise<GetProcessorStatusResponse> {
|
|
142
|
+
const { aptosConfig } = args;
|
|
143
|
+
|
|
144
|
+
const graphqlQuery = {
|
|
145
|
+
query: GetProcessorStatus,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const data = await queryIndexer<GetProcessorStatusQuery>({
|
|
149
|
+
aptosConfig,
|
|
150
|
+
query: graphqlQuery,
|
|
151
|
+
originMethod: "getProcessorStatuses",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return data.processor_status;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function getIndexerLastSuccessVersion(args: { aptosConfig: AptosConfig }): Promise<number> {
|
|
158
|
+
const response = await getProcessorStatuses({ aptosConfig: args.aptosConfig });
|
|
159
|
+
return response[0].last_success_version;
|
|
160
|
+
}
|