@ledgerhq/coin-aptos 2.2.0 → 2.2.1-nightly.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/CHANGELOG.md +8 -0
- 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 +16 -4
- package/lib/__tests__/api/index.integ.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 +63 -63
- package/lib/__tests__/network/client.test.js.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/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 +1 -5
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +25 -60
- package/lib/network/client.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 +16 -4
- package/lib-es/__tests__/api/index.integ.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 +63 -63
- package/lib-es/__tests__/network/client.test.js.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/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 +1 -5
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +25 -60
- package/lib-es/network/client.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/api/craftTransaction.unit.test.ts +1 -1
- package/src/__tests__/api/getBalance.unit.test.ts +82 -28
- package/src/__tests__/api/index.integ.test.ts +19 -4
- 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 +70 -79
- package/src/api/index.ts +2 -2
- package/src/bridge/synchronisation.ts +4 -2
- package/src/logic/getBalances.ts +27 -0
- package/src/network/client.ts +26 -64
- 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,
|
|
@@ -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,44 +175,6 @@ export class AptosAPI {
|
|
|
185
175
|
};
|
|
186
176
|
}
|
|
187
177
|
|
|
188
|
-
async getCoinBalance(address: string, contract_address: string): Promise<BigNumber> {
|
|
189
|
-
try {
|
|
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
178
|
async estimateFees(
|
|
227
179
|
transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
228
180
|
): Promise<FeeEstimation<AptosFeeParameters>> {
|
|
@@ -354,21 +306,31 @@ export class AptosAPI {
|
|
|
354
306
|
};
|
|
355
307
|
}
|
|
356
308
|
|
|
357
|
-
async getBalances(address: string): Promise<AptosBalance[]> {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
309
|
+
async getBalances(address: string, contractAddress?: string): Promise<AptosBalance[]> {
|
|
310
|
+
try {
|
|
311
|
+
const whereCondition: any = {
|
|
312
|
+
owner_address: { _eq: address },
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
if (contractAddress !== undefined && contractAddress !== "") {
|
|
316
|
+
whereCondition.asset_type = { _eq: contractAddress };
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const response = await this.aptosClient.getCurrentFungibleAssetBalances({
|
|
320
|
+
options: {
|
|
321
|
+
where: whereCondition,
|
|
365
322
|
},
|
|
366
|
-
}
|
|
367
|
-
});
|
|
323
|
+
});
|
|
368
324
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
325
|
+
return response.map(x => ({
|
|
326
|
+
contractAddress: x.asset_type ?? "",
|
|
327
|
+
amount: BigNumber(x.amount),
|
|
328
|
+
}));
|
|
329
|
+
} catch (error) {
|
|
330
|
+
log("error", "getCoinBalance", {
|
|
331
|
+
error,
|
|
332
|
+
});
|
|
333
|
+
return [{ amount: BigNumber(0), contractAddress: "" }];
|
|
334
|
+
}
|
|
373
335
|
}
|
|
374
336
|
}
|
|
@@ -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
|
-
}
|