@ledgerhq/coin-aptos 2.2.0-next.1 → 2.2.0-nightly.2
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +19 -15
- package/lib/__tests__/api/craftTransaction.unit.test.js +16 -31
- package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib/__tests__/api/getBalance.unit.test.js +68 -28
- package/lib/__tests__/api/getBalance.unit.test.js.map +1 -1
- package/lib/__tests__/api/index.integ.test.js +30 -11
- package/lib/__tests__/api/index.integ.test.js.map +1 -1
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +15 -6
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/__tests__/logic/getBalances.test.d.ts +2 -0
- package/lib/__tests__/logic/getBalances.test.d.ts.map +1 -0
- package/lib/__tests__/logic/getBalances.test.js +63 -0
- package/lib/__tests__/logic/getBalances.test.js.map +1 -0
- package/lib/__tests__/network/client.test.js +69 -66
- package/lib/__tests__/network/client.test.js.map +1 -1
- package/lib/api/index.d.ts +3 -3
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -2
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +7 -2
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +2 -2
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +3 -3
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/getBalances.d.ts +5 -0
- package/lib/logic/getBalances.d.ts.map +1 -0
- package/lib/logic/getBalances.js +21 -0
- package/lib/logic/getBalances.js.map +1 -0
- package/lib/network/client.d.ts +3 -7
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +28 -62
- package/lib/network/client.js.map +1 -1
- package/lib/types/assets.d.ts +0 -4
- package/lib/types/assets.d.ts.map +1 -1
- package/lib-es/__tests__/api/craftTransaction.unit.test.js +16 -31
- package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib-es/__tests__/api/getBalance.unit.test.js +69 -26
- package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -1
- package/lib-es/__tests__/api/index.integ.test.js +30 -11
- package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +15 -6
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/__tests__/logic/getBalances.test.d.ts +2 -0
- package/lib-es/__tests__/logic/getBalances.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/getBalances.test.js +61 -0
- package/lib-es/__tests__/logic/getBalances.test.js.map +1 -0
- package/lib-es/__tests__/network/client.test.js +69 -66
- package/lib-es/__tests__/network/client.test.js.map +1 -1
- package/lib-es/api/index.d.ts +3 -3
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +4 -2
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +2 -2
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +3 -3
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/getBalances.d.ts +5 -0
- package/lib-es/logic/getBalances.d.ts.map +1 -0
- package/lib-es/logic/getBalances.js +17 -0
- package/lib-es/logic/getBalances.js.map +1 -0
- package/lib-es/network/client.d.ts +3 -7
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +28 -62
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/types/assets.d.ts +0 -4
- package/lib-es/types/assets.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/api/craftTransaction.unit.test.ts +23 -38
- package/src/__tests__/api/getBalance.unit.test.ts +82 -28
- package/src/__tests__/api/index.integ.test.ts +36 -15
- package/src/__tests__/api/index.test.ts +4 -6
- package/src/__tests__/bridge/synchronisation.test.ts +21 -6
- package/src/__tests__/logic/getBalances.test.ts +80 -0
- package/src/__tests__/network/client.test.ts +83 -89
- package/src/api/index.ts +6 -8
- package/src/bridge/synchronisation.ts +4 -2
- package/src/logic/craftTransaction.ts +6 -8
- package/src/logic/getBalances.ts +27 -0
- package/src/network/client.ts +31 -74
- package/src/types/assets.ts +0 -5
- package/lib/logic/getBalance.d.ts +0 -5
- package/lib/logic/getBalance.d.ts.map +0 -1
- package/lib/logic/getBalance.js +0 -12
- package/lib/logic/getBalance.js.map +0 -1
- package/lib-es/logic/getBalance.d.ts +0 -5
- package/lib-es/logic/getBalance.d.ts.map +0 -1
- package/lib-es/logic/getBalance.js +0 -8
- package/lib-es/logic/getBalance.js.map +0 -1
- package/src/logic/getBalance.ts +0 -15
package/src/network/client.ts
CHANGED
|
@@ -36,7 +36,6 @@ import type {
|
|
|
36
36
|
GetAccountTransactionsDataQuery,
|
|
37
37
|
GetAccountTransactionsDataGtQueryVariables,
|
|
38
38
|
} from "./graphql/types";
|
|
39
|
-
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
40
39
|
import {
|
|
41
40
|
BlockInfo,
|
|
42
41
|
FeeEstimation,
|
|
@@ -44,7 +43,7 @@ import {
|
|
|
44
43
|
Pagination,
|
|
45
44
|
TransactionIntent,
|
|
46
45
|
} from "@ledgerhq/coin-framework/api/types";
|
|
47
|
-
import { AptosAsset
|
|
46
|
+
import { AptosAsset } from "../types/assets";
|
|
48
47
|
import { log } from "@ledgerhq/logs";
|
|
49
48
|
import { transactionsToOperations } from "../logic/transactionsToOperations";
|
|
50
49
|
import { isTestnet } from "../logic/isTestnet";
|
|
@@ -88,13 +87,12 @@ export class AptosAPI {
|
|
|
88
87
|
|
|
89
88
|
async getAccountInfo(address: string, startAt?: string) {
|
|
90
89
|
const [balance, transactions, blockHeight] = await Promise.all([
|
|
91
|
-
this.
|
|
90
|
+
this.getBalances(address, APTOS_ASSET_ID),
|
|
92
91
|
this.fetchTransactions(address, startAt),
|
|
93
92
|
this.getHeight(),
|
|
94
93
|
]);
|
|
95
|
-
|
|
96
94
|
return {
|
|
97
|
-
balance,
|
|
95
|
+
balance: balance[0].amount ?? BigInt(0),
|
|
98
96
|
transactions,
|
|
99
97
|
blockHeight,
|
|
100
98
|
};
|
|
@@ -167,14 +165,6 @@ export class AptosAPI {
|
|
|
167
165
|
return pendingTx.data.hash;
|
|
168
166
|
}
|
|
169
167
|
|
|
170
|
-
async getBalance(address: string, token: TokenCurrency): Promise<BigNumber> {
|
|
171
|
-
if (token.tokenType === "coin") {
|
|
172
|
-
return await this.getCoinBalance(address, token.contractAddress);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return await this.getFABalance(address, token.contractAddress);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
168
|
async getLastBlock(): Promise<BlockInfo> {
|
|
179
169
|
const { block_height } = await this.aptosClient.getLedgerInfo();
|
|
180
170
|
const block = await this.aptosClient.getBlockByHeight({ blockHeight: Number(block_height) });
|
|
@@ -185,48 +175,8 @@ export class AptosAPI {
|
|
|
185
175
|
};
|
|
186
176
|
}
|
|
187
177
|
|
|
188
|
-
async
|
|
189
|
-
|
|
190
|
-
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
191
|
-
payload: {
|
|
192
|
-
function: "0x1::coin::balance",
|
|
193
|
-
typeArguments: [contract_address],
|
|
194
|
-
functionArguments: [address],
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
const balance = parseInt(balanceStr, 10);
|
|
198
|
-
return new BigNumber(balance);
|
|
199
|
-
} catch (error) {
|
|
200
|
-
log("error", "getCoinBalance", {
|
|
201
|
-
error,
|
|
202
|
-
});
|
|
203
|
-
return new BigNumber(0);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async getFABalance(address: string, contract_address: string): Promise<BigNumber> {
|
|
208
|
-
try {
|
|
209
|
-
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
210
|
-
payload: {
|
|
211
|
-
function: "0x1::primary_fungible_store::balance",
|
|
212
|
-
typeArguments: ["0x1::object::ObjectCore"],
|
|
213
|
-
functionArguments: [address, contract_address],
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
const balance = parseInt(balanceStr, 10);
|
|
217
|
-
return new BigNumber(balance);
|
|
218
|
-
} catch (error) {
|
|
219
|
-
log("error", "getFABalance", {
|
|
220
|
-
error,
|
|
221
|
-
});
|
|
222
|
-
return new BigNumber(0);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async estimateFees(
|
|
227
|
-
transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
228
|
-
): Promise<FeeEstimation<AptosFeeParameters>> {
|
|
229
|
-
const publicKeyEd = new Ed25519PublicKey(transactionIntent.sender.xpub);
|
|
178
|
+
async estimateFees(transactionIntent: TransactionIntent<AptosAsset>): Promise<FeeEstimation> {
|
|
179
|
+
const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
|
|
230
180
|
|
|
231
181
|
const txPayload: InputEntryFunctionData = {
|
|
232
182
|
function: "0x1::aptos_account::transfer_coins",
|
|
@@ -256,11 +206,7 @@ export class AptosAPI {
|
|
|
256
206
|
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
|
|
257
207
|
};
|
|
258
208
|
|
|
259
|
-
const tx = await this.generateTransaction(
|
|
260
|
-
transactionIntent.sender.freshAddress,
|
|
261
|
-
txPayload,
|
|
262
|
-
txOptions,
|
|
263
|
-
);
|
|
209
|
+
const tx = await this.generateTransaction(transactionIntent.sender, txPayload, txOptions);
|
|
264
210
|
|
|
265
211
|
const simulation = await this.simulateTransaction(publicKeyEd, tx);
|
|
266
212
|
const completedTx = simulation[0];
|
|
@@ -273,6 +219,7 @@ export class AptosAPI {
|
|
|
273
219
|
return {
|
|
274
220
|
value: BigInt(expectedGas.toString()),
|
|
275
221
|
parameters: {
|
|
222
|
+
storageLimit: BigInt(0),
|
|
276
223
|
gasLimit: BigInt(gasLimit.toString()),
|
|
277
224
|
gasPrice: BigInt(gasPrice.toString()),
|
|
278
225
|
},
|
|
@@ -354,21 +301,31 @@ export class AptosAPI {
|
|
|
354
301
|
};
|
|
355
302
|
}
|
|
356
303
|
|
|
357
|
-
async getBalances(address: string): Promise<AptosBalance[]> {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
304
|
+
async getBalances(address: string, contractAddress?: string): Promise<AptosBalance[]> {
|
|
305
|
+
try {
|
|
306
|
+
const whereCondition: any = {
|
|
307
|
+
owner_address: { _eq: address },
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
if (contractAddress !== undefined && contractAddress !== "") {
|
|
311
|
+
whereCondition.asset_type = { _eq: contractAddress };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const response = await this.aptosClient.getCurrentFungibleAssetBalances({
|
|
315
|
+
options: {
|
|
316
|
+
where: whereCondition,
|
|
365
317
|
},
|
|
366
|
-
}
|
|
367
|
-
});
|
|
318
|
+
});
|
|
368
319
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
320
|
+
return response.map(x => ({
|
|
321
|
+
contractAddress: x.asset_type ?? "",
|
|
322
|
+
amount: BigNumber(x.amount),
|
|
323
|
+
}));
|
|
324
|
+
} catch (error) {
|
|
325
|
+
log("error", "getCoinBalance", {
|
|
326
|
+
error,
|
|
327
|
+
});
|
|
328
|
+
return [{ amount: BigNumber(0), contractAddress: "" }];
|
|
329
|
+
}
|
|
373
330
|
}
|
|
374
331
|
}
|
package/src/types/assets.ts
CHANGED
|
@@ -9,11 +9,6 @@ export type AptosTokenInformation = {
|
|
|
9
9
|
|
|
10
10
|
export type AptosExtra = Record<string, unknown>;
|
|
11
11
|
|
|
12
|
-
export type AptosSender = {
|
|
13
|
-
xpub: string;
|
|
14
|
-
freshAddress: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
12
|
export type AptosFeeParameters = {
|
|
18
13
|
gasLimit: bigint;
|
|
19
14
|
gasPrice: bigint;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
-
import type { AptosAsset } from "../types/assets";
|
|
3
|
-
import type { AptosAPI } from "../network";
|
|
4
|
-
export declare function getBalance(aptosClient: AptosAPI, address: string): Promise<Balance<AptosAsset>[]>;
|
|
5
|
-
//# sourceMappingURL=getBalance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAsB,UAAU,CAC9B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAOhC"}
|
package/lib/logic/getBalance.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBalance = void 0;
|
|
4
|
-
async function getBalance(aptosClient, address) {
|
|
5
|
-
const balance = await aptosClient.getBalances(address);
|
|
6
|
-
return balance.map(x => ({
|
|
7
|
-
value: BigInt(x.amount.toString()),
|
|
8
|
-
asset: { type: "native" },
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
11
|
-
exports.getBalance = getBalance;
|
|
12
|
-
//# sourceMappingURL=getBalance.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":";;;AAIO,KAAK,UAAU,UAAU,CAC9B,WAAqB,EACrB,OAAe;IAEf,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEvD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC1B,CAAC,CAAC,CAAC;AACN,CAAC;AAVD,gCAUC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
-
import type { AptosAsset } from "../types/assets";
|
|
3
|
-
import type { AptosAPI } from "../network";
|
|
4
|
-
export declare function getBalance(aptosClient: AptosAPI, address: string): Promise<Balance<AptosAsset>[]>;
|
|
5
|
-
//# sourceMappingURL=getBalance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAsB,UAAU,CAC9B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAOhC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,WAAqB,EACrB,OAAe;IAEf,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEvD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC1B,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/src/logic/getBalance.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
-
import type { AptosAsset } from "../types/assets";
|
|
3
|
-
import type { AptosAPI } from "../network";
|
|
4
|
-
|
|
5
|
-
export async function getBalance(
|
|
6
|
-
aptosClient: AptosAPI,
|
|
7
|
-
address: string,
|
|
8
|
-
): Promise<Balance<AptosAsset>[]> {
|
|
9
|
-
const balance = await aptosClient.getBalances(address);
|
|
10
|
-
|
|
11
|
-
return balance.map(x => ({
|
|
12
|
-
value: BigInt(x.amount.toString()),
|
|
13
|
-
asset: { type: "native" },
|
|
14
|
-
}));
|
|
15
|
-
}
|