@ledgerhq/coin-aptos 2.7.0-nightly.2 → 2.7.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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +7 -1
- package/CHANGELOG.md +37 -15
- package/lib/__tests__/api/craftTransaction.unit.test.js +4 -4
- package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib/__tests__/api/getBalance.unit.test.js +4 -3
- package/lib/__tests__/api/getBalance.unit.test.js.map +1 -1
- package/lib/__tests__/api/index.integ.test.js +28 -19
- package/lib/__tests__/api/index.integ.test.js.map +1 -1
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/logic/getBalances.test.js +4 -3
- package/lib/__tests__/logic/getBalances.test.js.map +1 -1
- package/lib/__tests__/network/client.test.js +8 -4
- package/lib/__tests__/network/client.test.js.map +1 -1
- package/lib/api/index.d.ts +2 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/logic/buildTransaction.d.ts.map +1 -1
- package/lib/logic/buildTransaction.js +0 -1
- package/lib/logic/buildTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +2 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +4 -6
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/getBalances.d.ts +2 -1
- package/lib/logic/getBalances.d.ts.map +1 -1
- package/lib/logic/getBalances.js +2 -2
- package/lib/logic/getBalances.js.map +1 -1
- package/lib/logic/processRecipients.d.ts +2 -1
- package/lib/logic/processRecipients.d.ts.map +1 -1
- package/lib/logic/processRecipients.js.map +1 -1
- package/lib/logic/transactionsToOperations.d.ts +2 -1
- package/lib/logic/transactionsToOperations.d.ts.map +1 -1
- package/lib/logic/transactionsToOperations.js +4 -3
- package/lib/logic/transactionsToOperations.js.map +1 -1
- package/lib/network/client.d.ts +3 -2
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +15 -8
- package/lib/network/client.js.map +1 -1
- package/lib/network/graphql/queries.d.ts.map +1 -1
- package/lib/network/graphql/queries.js +1 -6
- package/lib/network/graphql/queries.js.map +1 -1
- package/lib/network/graphql/types.d.ts +0 -2
- package/lib/network/graphql/types.d.ts.map +1 -1
- package/lib/preload.d.ts.map +1 -1
- package/lib/preload.js +5 -1
- package/lib/preload.js.map +1 -1
- package/lib/types/assets.d.ts +6 -0
- package/lib/types/assets.d.ts.map +1 -1
- package/lib-es/__tests__/api/craftTransaction.unit.test.js +4 -4
- package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib-es/__tests__/api/getBalance.unit.test.js +4 -3
- package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -1
- package/lib-es/__tests__/api/index.integ.test.js +28 -19
- 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__/logic/getBalances.test.js +4 -3
- package/lib-es/__tests__/logic/getBalances.test.js.map +1 -1
- package/lib-es/__tests__/network/client.test.js +8 -4
- package/lib-es/__tests__/network/client.test.js.map +1 -1
- package/lib-es/api/index.d.ts +2 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/logic/buildTransaction.d.ts.map +1 -1
- package/lib-es/logic/buildTransaction.js +0 -1
- package/lib-es/logic/buildTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +2 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +4 -6
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/getBalances.d.ts +2 -1
- package/lib-es/logic/getBalances.d.ts.map +1 -1
- package/lib-es/logic/getBalances.js +2 -2
- package/lib-es/logic/getBalances.js.map +1 -1
- package/lib-es/logic/processRecipients.d.ts +2 -1
- package/lib-es/logic/processRecipients.d.ts.map +1 -1
- package/lib-es/logic/processRecipients.js.map +1 -1
- package/lib-es/logic/transactionsToOperations.d.ts +2 -1
- package/lib-es/logic/transactionsToOperations.d.ts.map +1 -1
- package/lib-es/logic/transactionsToOperations.js +4 -3
- package/lib-es/logic/transactionsToOperations.js.map +1 -1
- package/lib-es/network/client.d.ts +3 -2
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +16 -9
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/network/graphql/queries.d.ts.map +1 -1
- package/lib-es/network/graphql/queries.js +1 -6
- package/lib-es/network/graphql/queries.js.map +1 -1
- package/lib-es/network/graphql/types.d.ts +0 -2
- package/lib-es/network/graphql/types.d.ts.map +1 -1
- package/lib-es/preload.d.ts.map +1 -1
- package/lib-es/preload.js +5 -1
- package/lib-es/preload.js.map +1 -1
- package/lib-es/types/assets.d.ts +6 -0
- package/lib-es/types/assets.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/__tests__/api/craftTransaction.unit.test.ts +10 -9
- package/src/__tests__/api/getBalance.unit.test.ts +4 -3
- package/src/__tests__/api/index.integ.test.ts +28 -19
- package/src/__tests__/api/index.test.ts +3 -2
- package/src/__tests__/logic/getBalances.test.ts +4 -3
- package/src/__tests__/network/client.test.ts +12 -7
- package/src/api/index.ts +6 -4
- package/src/logic/buildTransaction.ts +0 -1
- package/src/logic/craftTransaction.ts +7 -10
- package/src/logic/getBalances.ts +4 -3
- package/src/logic/processRecipients.ts +8 -4
- package/src/logic/transactionsToOperations.ts +8 -6
- package/src/network/client.ts +24 -10
- package/src/network/graphql/queries.ts +1 -6
- package/src/network/graphql/types.ts +0 -2
- package/src/preload.ts +5 -1
- package/src/types/assets.ts +9 -0
|
@@ -71,8 +71,9 @@ describe("createApi", () => {
|
|
|
71
71
|
|
|
72
72
|
const fees = await api.estimateFees({
|
|
73
73
|
asset: {
|
|
74
|
-
type: "
|
|
75
|
-
|
|
74
|
+
type: "token",
|
|
75
|
+
standard: "coin",
|
|
76
|
+
contractAddress:
|
|
76
77
|
"0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::usdc_coin::USDCoin",
|
|
77
78
|
},
|
|
78
79
|
type: "send",
|
|
@@ -90,8 +91,9 @@ describe("createApi", () => {
|
|
|
90
91
|
|
|
91
92
|
const fees = await api.estimateFees({
|
|
92
93
|
asset: {
|
|
93
|
-
type: "
|
|
94
|
-
|
|
94
|
+
type: "token",
|
|
95
|
+
standard: "fungible_asset",
|
|
96
|
+
contractAddress: "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b",
|
|
95
97
|
},
|
|
96
98
|
type: "send",
|
|
97
99
|
sender: sender.freshAddress,
|
|
@@ -136,8 +138,9 @@ describe("createApi", () => {
|
|
|
136
138
|
recipient: recipient.freshAddress,
|
|
137
139
|
type: "send",
|
|
138
140
|
asset: {
|
|
139
|
-
type: "
|
|
140
|
-
|
|
141
|
+
type: "token",
|
|
142
|
+
standard: "coin",
|
|
143
|
+
contractAddress:
|
|
141
144
|
"0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::aptos_coin::AptosCoin",
|
|
142
145
|
},
|
|
143
146
|
},
|
|
@@ -162,8 +165,9 @@ describe("createApi", () => {
|
|
|
162
165
|
recipient: recipient.freshAddress,
|
|
163
166
|
type: "send",
|
|
164
167
|
asset: {
|
|
165
|
-
type: "
|
|
166
|
-
|
|
168
|
+
type: "token",
|
|
169
|
+
standard: "coin",
|
|
170
|
+
contractAddress:
|
|
167
171
|
"0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::aptos_coin::AptosCoin",
|
|
168
172
|
},
|
|
169
173
|
},
|
|
@@ -190,8 +194,9 @@ describe("createApi", () => {
|
|
|
190
194
|
recipient: r.freshAddress,
|
|
191
195
|
type: "send",
|
|
192
196
|
asset: {
|
|
193
|
-
type: "
|
|
194
|
-
|
|
197
|
+
type: "token",
|
|
198
|
+
standard: "fungible_asset",
|
|
199
|
+
contractAddress: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
|
|
195
200
|
},
|
|
196
201
|
},
|
|
197
202
|
0n,
|
|
@@ -220,7 +225,7 @@ describe("createApi", () => {
|
|
|
220
225
|
const tokenBalances = balances.filter(
|
|
221
226
|
b =>
|
|
222
227
|
b.asset.type === assetTypeToken &&
|
|
223
|
-
b.asset.
|
|
228
|
+
b.asset.contractAddress ===
|
|
224
229
|
"0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
|
|
225
230
|
);
|
|
226
231
|
expect(tokenBalances.length).toBeGreaterThan(0);
|
|
@@ -340,8 +345,9 @@ describe("createApi", () => {
|
|
|
340
345
|
recipients: [tokenAccount.freshAddress],
|
|
341
346
|
senders: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
|
|
342
347
|
asset: {
|
|
343
|
-
type: "
|
|
344
|
-
|
|
348
|
+
type: "token",
|
|
349
|
+
standard: "coin",
|
|
350
|
+
contractAddress:
|
|
345
351
|
"0xd11107bdf0d6d7040c6c0bfbdecb6545191fdf13e8d8d259952f53e1713f61b5::staked_coin::StakedAptos",
|
|
346
352
|
},
|
|
347
353
|
tx: {
|
|
@@ -358,8 +364,9 @@ describe("createApi", () => {
|
|
|
358
364
|
recipients: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
|
|
359
365
|
senders: [tokenAccount.freshAddress],
|
|
360
366
|
asset: {
|
|
361
|
-
type: "
|
|
362
|
-
|
|
367
|
+
type: "token",
|
|
368
|
+
standard: "coin",
|
|
369
|
+
contractAddress:
|
|
363
370
|
"0xd11107bdf0d6d7040c6c0bfbdecb6545191fdf13e8d8d259952f53e1713f61b5::staked_coin::StakedAptos",
|
|
364
371
|
},
|
|
365
372
|
tx: {
|
|
@@ -381,8 +388,9 @@ describe("createApi", () => {
|
|
|
381
388
|
recipients: [tokenAccount.freshAddress],
|
|
382
389
|
senders: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
|
|
383
390
|
asset: {
|
|
384
|
-
type: "
|
|
385
|
-
|
|
391
|
+
type: "token",
|
|
392
|
+
standard: "fungible_asset",
|
|
393
|
+
contractAddress: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
|
|
386
394
|
},
|
|
387
395
|
tx: {
|
|
388
396
|
hash: "0x88856968603dee4f08579036bc30322b9a5f329561656888e3467ce27cc11ea7",
|
|
@@ -398,8 +406,9 @@ describe("createApi", () => {
|
|
|
398
406
|
recipients: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
|
|
399
407
|
senders: [tokenAccount.freshAddress],
|
|
400
408
|
asset: {
|
|
401
|
-
type: "
|
|
402
|
-
|
|
409
|
+
type: "token",
|
|
410
|
+
standard: "fungible_asset",
|
|
411
|
+
contractAddress: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
|
|
403
412
|
},
|
|
404
413
|
tx: {
|
|
405
414
|
hash: "0x8aa9e980760fe8aeb6804f387350b3019a2471aa61a5506a260c32cd5d6db32c",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Aptos } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import type { AlpacaApi } from "@ledgerhq/coin-framework/api/types";
|
|
3
|
+
import type { AptosAsset } from "../../types/assets";
|
|
3
4
|
import type { AptosConfig } from "../../config";
|
|
4
5
|
import { createApi } from "../../api";
|
|
5
6
|
import coinConfig from "../../config";
|
|
@@ -32,7 +33,7 @@ describe("createApi", () => {
|
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
it("should return an API object with alpaca api methods", () => {
|
|
35
|
-
const api: AlpacaApi = createApi(mockAptosConfig);
|
|
36
|
+
const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
|
|
36
37
|
|
|
37
38
|
// Check that methods are set with what we expect
|
|
38
39
|
expect(api.broadcast).toBeDefined();
|
|
@@ -68,7 +69,7 @@ describe("lastBlock", () => {
|
|
|
68
69
|
}),
|
|
69
70
|
}));
|
|
70
71
|
|
|
71
|
-
const api: AlpacaApi = createApi(mockAptosConfig);
|
|
72
|
+
const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
|
|
72
73
|
|
|
73
74
|
expect(await api.lastBlock()).toStrictEqual({
|
|
74
75
|
height: 123,
|
|
@@ -51,7 +51,7 @@ describe("getBalance", () => {
|
|
|
51
51
|
expect(balances).toStrictEqual([
|
|
52
52
|
{
|
|
53
53
|
value: 25n,
|
|
54
|
-
asset: { type:
|
|
54
|
+
asset: { type: "token", contractAddress: TOKEN_ASSET_ID, standard: TOKEN_TYPE.COIN },
|
|
55
55
|
},
|
|
56
56
|
]);
|
|
57
57
|
});
|
|
@@ -70,8 +70,9 @@ describe("getBalance", () => {
|
|
|
70
70
|
{
|
|
71
71
|
value: 25n,
|
|
72
72
|
asset: {
|
|
73
|
-
type:
|
|
74
|
-
|
|
73
|
+
type: "token",
|
|
74
|
+
contractAddress: TOKEN_ASSET_ID,
|
|
75
|
+
standard: TOKEN_TYPE.FUNGIBLE_ASSET,
|
|
75
76
|
},
|
|
76
77
|
},
|
|
77
78
|
]);
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import network from "@ledgerhq/live-network";
|
|
15
15
|
import BigNumber from "bignumber.js";
|
|
16
16
|
import { AptosAPI } from "../../network";
|
|
17
|
+
import { AptosAsset } from "../../types/assets";
|
|
17
18
|
import { Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
18
19
|
import { APTOS_ASSET_ID } from "../../constants";
|
|
19
20
|
import { AptosBalance, AptosTransaction } from "../../types";
|
|
@@ -621,7 +622,7 @@ describe("Aptos API", () => {
|
|
|
621
622
|
const recipient = "address2";
|
|
622
623
|
|
|
623
624
|
const api = new AptosAPI("aptos");
|
|
624
|
-
const transactionIntent: TransactionIntent = {
|
|
625
|
+
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
625
626
|
asset: {
|
|
626
627
|
type: "native",
|
|
627
628
|
},
|
|
@@ -686,10 +687,11 @@ describe("Aptos API", () => {
|
|
|
686
687
|
const recipient = "address2";
|
|
687
688
|
|
|
688
689
|
const api = new AptosAPI("aptos");
|
|
689
|
-
const transactionIntent: TransactionIntent = {
|
|
690
|
+
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
690
691
|
asset: {
|
|
691
|
-
type: "
|
|
692
|
-
|
|
692
|
+
type: "token",
|
|
693
|
+
standard: "coin",
|
|
694
|
+
contractAddress: "0x111",
|
|
693
695
|
},
|
|
694
696
|
type: "send",
|
|
695
697
|
sender: sender.freshAddress,
|
|
@@ -751,10 +753,11 @@ describe("Aptos API", () => {
|
|
|
751
753
|
const recipient = "address2";
|
|
752
754
|
|
|
753
755
|
const api = new AptosAPI("aptos");
|
|
754
|
-
const transactionIntent: TransactionIntent = {
|
|
756
|
+
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
755
757
|
asset: {
|
|
756
|
-
type: "
|
|
757
|
-
|
|
758
|
+
type: "token",
|
|
759
|
+
standard: "fungible_asset",
|
|
760
|
+
contractAddress: "0x111",
|
|
758
761
|
},
|
|
759
762
|
type: "send",
|
|
760
763
|
sender: sender.freshAddress,
|
|
@@ -865,6 +868,7 @@ describe("Aptos API", () => {
|
|
|
865
868
|
const txs: AptosTransaction[] = [
|
|
866
869
|
{
|
|
867
870
|
version: "2532591427",
|
|
871
|
+
replay_protection_nonce: "replay_protection_nonce",
|
|
868
872
|
hash: "0x3f35",
|
|
869
873
|
state_change_hash: "0xb480",
|
|
870
874
|
event_root_hash: "0x3fa1",
|
|
@@ -1078,6 +1082,7 @@ describe("Aptos API", () => {
|
|
|
1078
1082
|
},
|
|
1079
1083
|
{
|
|
1080
1084
|
version: "2532549325",
|
|
1085
|
+
replay_protection_nonce: "replay_protection_nonce",
|
|
1081
1086
|
hash: "0x9a6b",
|
|
1082
1087
|
state_change_hash: "0xa424",
|
|
1083
1088
|
event_root_hash: "0x0321",
|
package/src/api/index.ts
CHANGED
|
@@ -2,12 +2,13 @@ import type { AlpacaApi, Block, BlockInfo } from "@ledgerhq/coin-framework/api/i
|
|
|
2
2
|
import type { AptosConfig as AptosConfigApi } from "../config";
|
|
3
3
|
import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
4
4
|
import coinConfig from "../config";
|
|
5
|
+
import type { AptosAsset } from "../types/assets";
|
|
5
6
|
import { AptosAPI } from "../network";
|
|
6
7
|
import { combine } from "../logic/combine";
|
|
7
8
|
import { craftTransaction } from "../logic/craftTransaction";
|
|
8
9
|
import { getBalances } from "../logic/getBalances";
|
|
9
10
|
|
|
10
|
-
export function createApi(config: AptosConfigApi): AlpacaApi {
|
|
11
|
+
export function createApi(config: AptosConfigApi): AlpacaApi<AptosAsset> {
|
|
11
12
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
12
13
|
|
|
13
14
|
const client = new AptosAPI(config.aptosSettings);
|
|
@@ -17,12 +18,13 @@ export function createApi(config: AptosConfigApi): AlpacaApi {
|
|
|
17
18
|
combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
|
|
18
19
|
craftTransaction: (transactionIntent, _customFees): Promise<string> =>
|
|
19
20
|
craftTransaction(client, transactionIntent),
|
|
20
|
-
estimateFees: (transactionIntent: TransactionIntent) =>
|
|
21
|
-
|
|
21
|
+
estimateFees: (transactionIntent: TransactionIntent<AptosAsset>) =>
|
|
22
|
+
client.estimateFees(transactionIntent),
|
|
23
|
+
getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalances(client, address),
|
|
22
24
|
lastBlock: () => client.getLastBlock(),
|
|
23
25
|
listOperations: (address: string, pagination: Pagination) =>
|
|
24
26
|
client.listOperations(address, pagination),
|
|
25
|
-
getBlock(_height): Promise<Block
|
|
27
|
+
getBlock(_height): Promise<Block<AptosAsset>> {
|
|
26
28
|
throw new Error("getBlock is not supported");
|
|
27
29
|
},
|
|
28
30
|
getBlockInfo(_height: number): Promise<BlockInfo> {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
+
import type { AptosAsset } from "../types/assets";
|
|
2
3
|
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
3
4
|
import type { AptosAPI } from "../network";
|
|
4
5
|
import buildTransaction, { isTokenType } from "./buildTransaction";
|
|
@@ -9,7 +10,7 @@ import type { AptosBalance } from "../types";
|
|
|
9
10
|
|
|
10
11
|
export async function craftTransaction(
|
|
11
12
|
aptosClient: AptosAPI,
|
|
12
|
-
transactionIntent: TransactionIntent
|
|
13
|
+
transactionIntent: TransactionIntent<AptosAsset>,
|
|
13
14
|
): Promise<string> {
|
|
14
15
|
const newTx = createTransaction();
|
|
15
16
|
newTx.amount = BigNumber(transactionIntent.amount.toString());
|
|
@@ -38,8 +39,8 @@ export async function craftTransaction(
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
if (transactionIntent.asset.type
|
|
42
|
-
tokenType = transactionIntent.asset.
|
|
42
|
+
if (transactionIntent.asset.type === "token") {
|
|
43
|
+
tokenType = transactionIntent.asset.standard as TOKEN_TYPE;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
const aptosTx = await buildTransaction(
|
|
@@ -53,13 +54,9 @@ export async function craftTransaction(
|
|
|
53
54
|
return aptosTx.bcsToHex().toString();
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
function getContractAddress(txIntent: TransactionIntent): string {
|
|
57
|
-
if (
|
|
58
|
-
txIntent.asset.
|
|
59
|
-
isTokenType(txIntent.asset.type as string) &&
|
|
60
|
-
"assetReference" in txIntent.asset
|
|
61
|
-
) {
|
|
62
|
-
return txIntent.asset.assetReference as string;
|
|
57
|
+
function getContractAddress(txIntent: TransactionIntent<AptosAsset>): string {
|
|
58
|
+
if (txIntent.asset.type === "token" && isTokenType(txIntent.asset.standard)) {
|
|
59
|
+
return txIntent.asset.contractAddress;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
return APTOS_ASSET_ID;
|
package/src/logic/getBalances.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
+
import type { AptosAsset } from "../types/assets";
|
|
2
3
|
import type { AptosAPI } from "../network";
|
|
3
4
|
import { APTOS_ASSET_ID, TOKEN_TYPE } from "../constants";
|
|
4
5
|
|
|
@@ -6,12 +7,12 @@ export async function getBalances(
|
|
|
6
7
|
aptosClient: AptosAPI,
|
|
7
8
|
address: string,
|
|
8
9
|
contract_address?: string,
|
|
9
|
-
): Promise<Balance[]> {
|
|
10
|
+
): Promise<Balance<AptosAsset>[]> {
|
|
10
11
|
const balances = await aptosClient.getBalances(address, contract_address);
|
|
11
12
|
|
|
12
13
|
return balances.map(balance => {
|
|
13
14
|
const isNative = balance.contractAddress === APTOS_ASSET_ID;
|
|
14
|
-
const
|
|
15
|
+
const standard =
|
|
15
16
|
balance.contractAddress.split("::").length === 3
|
|
16
17
|
? TOKEN_TYPE.COIN
|
|
17
18
|
: TOKEN_TYPE.FUNGIBLE_ASSET;
|
|
@@ -20,7 +21,7 @@ export async function getBalances(
|
|
|
20
21
|
value: BigInt(balance.amount.toString()),
|
|
21
22
|
asset: isNative
|
|
22
23
|
? { type: "native" }
|
|
23
|
-
: { type:
|
|
24
|
+
: { type: "token", contractAddress: balance.contractAddress, standard: standard },
|
|
24
25
|
};
|
|
25
26
|
});
|
|
26
27
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import { Operation } from "@ledgerhq/types-live";
|
|
3
3
|
import { Operation as APIOperation } from "@ledgerhq/coin-framework/api/types";
|
|
4
|
+
import { AptosAsset } from "../types/assets";
|
|
4
5
|
import {
|
|
5
6
|
BATCH_TRANSFER_TYPES,
|
|
6
7
|
COIN_TRANSFER_TYPES,
|
|
@@ -15,7 +16,7 @@ const transferLikeFunctions = (payload: InputEntryFunctionData) =>
|
|
|
15
16
|
DELEGATION_POOL_TYPES.includes(payload.function);
|
|
16
17
|
|
|
17
18
|
const addLikeFunctionsToRecipients = (
|
|
18
|
-
op: Operation | APIOperation
|
|
19
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
19
20
|
payload: InputEntryFunctionData,
|
|
20
21
|
) => {
|
|
21
22
|
if (
|
|
@@ -27,7 +28,10 @@ const addLikeFunctionsToRecipients = (
|
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
const addFungibleToRecipients = (
|
|
31
|
+
const addFungibleToRecipients = (
|
|
32
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
33
|
+
payload: InputEntryFunctionData,
|
|
34
|
+
) => {
|
|
31
35
|
if (
|
|
32
36
|
payload.functionArguments &&
|
|
33
37
|
payload.functionArguments.length > 1 &&
|
|
@@ -39,7 +43,7 @@ const addFungibleToRecipients = (op: Operation | APIOperation, payload: InputEnt
|
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
const addBatchedFunctions = (
|
|
42
|
-
op: Operation | APIOperation
|
|
46
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
43
47
|
payload: InputEntryFunctionData,
|
|
44
48
|
address: string,
|
|
45
49
|
) => {
|
|
@@ -62,7 +66,7 @@ const addBatchedFunctions = (
|
|
|
62
66
|
export function processRecipients(
|
|
63
67
|
payload: InputEntryFunctionData,
|
|
64
68
|
address: string,
|
|
65
|
-
op: Operation | APIOperation
|
|
69
|
+
op: Operation | APIOperation<AptosAsset>,
|
|
66
70
|
function_address: string,
|
|
67
71
|
): void {
|
|
68
72
|
// get recipients by 3 groups
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AptosTransaction } from "../types";
|
|
2
2
|
import { Operation } from "@ledgerhq/coin-framework/api/types";
|
|
3
|
+
import { AptosAsset } from "../types/assets";
|
|
3
4
|
import BigNumber from "bignumber.js";
|
|
4
5
|
import { EntryFunctionPayloadResponse, InputEntryFunctionData } from "@aptos-labs/ts-sdk";
|
|
5
6
|
import { APTOS_ASSET_ID, OP_TYPE } from "../constants";
|
|
@@ -28,7 +29,7 @@ const detectType = (address: string, tx: AptosTransaction, value: BigNumber): OP
|
|
|
28
29
|
return type;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
const
|
|
32
|
+
const getTokenStandard = (coin_id: string): string => {
|
|
32
33
|
const parts = coin_id.split("::");
|
|
33
34
|
if (parts.length === 3) {
|
|
34
35
|
return "coin";
|
|
@@ -39,8 +40,8 @@ const getTokenType = (coin_id: string) => {
|
|
|
39
40
|
export function transactionsToOperations(
|
|
40
41
|
address: string,
|
|
41
42
|
txs: (AptosTransaction | null)[],
|
|
42
|
-
): Operation[] {
|
|
43
|
-
const operations: Operation[] = [];
|
|
43
|
+
): Operation<AptosAsset>[] {
|
|
44
|
+
const operations: Operation<AptosAsset>[] = [];
|
|
44
45
|
|
|
45
46
|
return txs.reduce((acc, tx) => {
|
|
46
47
|
if (tx === null) {
|
|
@@ -61,7 +62,7 @@ export function transactionsToOperations(
|
|
|
61
62
|
const value = calculateAmount(tx.sender, address, amount_in, amount_out);
|
|
62
63
|
const type = detectType(address, tx, value);
|
|
63
64
|
|
|
64
|
-
const op: Operation = {
|
|
65
|
+
const op: Operation<AptosAsset> = {
|
|
65
66
|
id: tx.hash,
|
|
66
67
|
type,
|
|
67
68
|
senders: [],
|
|
@@ -93,8 +94,9 @@ export function transactionsToOperations(
|
|
|
93
94
|
return acc;
|
|
94
95
|
} else {
|
|
95
96
|
op.asset = {
|
|
96
|
-
type:
|
|
97
|
-
|
|
97
|
+
type: "token",
|
|
98
|
+
standard: getTokenStandard(coin_id),
|
|
99
|
+
contractAddress: coin_id,
|
|
98
100
|
};
|
|
99
101
|
acc.push(op);
|
|
100
102
|
}
|
package/src/network/client.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
Hex,
|
|
19
19
|
postAptosFullNode,
|
|
20
20
|
type PendingTransactionResponse,
|
|
21
|
+
Network,
|
|
21
22
|
} from "@aptos-labs/ts-sdk";
|
|
22
23
|
import { getEnv } from "@ledgerhq/live-env";
|
|
23
24
|
import network from "@ledgerhq/live-network";
|
|
@@ -48,6 +49,7 @@ import {
|
|
|
48
49
|
Pagination,
|
|
49
50
|
TransactionIntent,
|
|
50
51
|
} from "@ledgerhq/coin-framework/api/types";
|
|
52
|
+
import { AptosAsset } from "../types/assets";
|
|
51
53
|
import { log } from "@ledgerhq/logs";
|
|
52
54
|
import { transactionsToOperations } from "../logic/transactionsToOperations";
|
|
53
55
|
import { isTestnet } from "../logic/isTestnet";
|
|
@@ -59,6 +61,8 @@ const getIndexerEndpoint = (currencyId: string) =>
|
|
|
59
61
|
isTestnet(currencyId)
|
|
60
62
|
? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
|
|
61
63
|
: getEnv("APTOS_INDEXER_ENDPOINT");
|
|
64
|
+
const getNetwork = (currencyId: string) =>
|
|
65
|
+
isTestnet(currencyId) ? Network.TESTNET : Network.MAINNET;
|
|
62
66
|
|
|
63
67
|
export class AptosAPI {
|
|
64
68
|
private readonly aptosConfig: AptosConfig;
|
|
@@ -67,10 +71,18 @@ export class AptosAPI {
|
|
|
67
71
|
readonly apolloClient: ApolloClient<object>;
|
|
68
72
|
|
|
69
73
|
constructor(currencyIdOrSettings: AptosSettings | string) {
|
|
74
|
+
const appVersion = getEnv("LEDGER_CLIENT_VERSION");
|
|
75
|
+
|
|
70
76
|
if (typeof currencyIdOrSettings === "string") {
|
|
71
77
|
this.aptosConfig = new AptosConfig({
|
|
78
|
+
network: getNetwork(currencyIdOrSettings),
|
|
72
79
|
fullnode: getApiEndpoint(currencyIdOrSettings),
|
|
73
80
|
indexer: getIndexerEndpoint(currencyIdOrSettings),
|
|
81
|
+
clientConfig: {
|
|
82
|
+
HEADERS: {
|
|
83
|
+
"X-Ledger-Client-Version": appVersion,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
74
86
|
});
|
|
75
87
|
} else {
|
|
76
88
|
this.aptosConfig = new AptosConfig(currencyIdOrSettings);
|
|
@@ -81,7 +93,7 @@ export class AptosAPI {
|
|
|
81
93
|
uri: this.aptosConfig.indexer ?? "",
|
|
82
94
|
cache: new InMemoryCache(),
|
|
83
95
|
headers: {
|
|
84
|
-
"
|
|
96
|
+
"X-Ledger-Client-Version": appVersion,
|
|
85
97
|
},
|
|
86
98
|
});
|
|
87
99
|
}
|
|
@@ -180,7 +192,7 @@ export class AptosAPI {
|
|
|
180
192
|
};
|
|
181
193
|
}
|
|
182
194
|
|
|
183
|
-
async estimateFees(transactionIntent: TransactionIntent): Promise<FeeEstimation> {
|
|
195
|
+
async estimateFees(transactionIntent: TransactionIntent<AptosAsset>): Promise<FeeEstimation> {
|
|
184
196
|
const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
|
|
185
197
|
|
|
186
198
|
const txPayload: InputEntryFunctionData = {
|
|
@@ -189,21 +201,20 @@ export class AptosAPI {
|
|
|
189
201
|
functionArguments: [transactionIntent.recipient, transactionIntent.amount],
|
|
190
202
|
};
|
|
191
203
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const { type } = transactionIntent.asset;
|
|
204
|
+
if (transactionIntent.asset.type === "token") {
|
|
205
|
+
const { standard } = transactionIntent.asset;
|
|
195
206
|
|
|
196
|
-
if (
|
|
207
|
+
if (standard === TOKEN_TYPE.FUNGIBLE_ASSET) {
|
|
197
208
|
txPayload.function = "0x1::primary_fungible_store::transfer";
|
|
198
209
|
txPayload.typeArguments = ["0x1::fungible_asset::Metadata"];
|
|
199
210
|
txPayload.functionArguments = [
|
|
200
|
-
transactionIntent.asset.
|
|
211
|
+
transactionIntent.asset.contractAddress,
|
|
201
212
|
transactionIntent.recipient,
|
|
202
213
|
transactionIntent.amount,
|
|
203
214
|
];
|
|
204
|
-
} else if (
|
|
215
|
+
} else if (standard === TOKEN_TYPE.COIN) {
|
|
205
216
|
txPayload.function = "0x1::aptos_account::transfer_coins";
|
|
206
|
-
txPayload.typeArguments = [transactionIntent.asset.
|
|
217
|
+
txPayload.typeArguments = [transactionIntent.asset.contractAddress];
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
|
|
@@ -266,7 +277,10 @@ export class AptosAPI {
|
|
|
266
277
|
}
|
|
267
278
|
}
|
|
268
279
|
|
|
269
|
-
async listOperations(
|
|
280
|
+
async listOperations(
|
|
281
|
+
rawAddress: string,
|
|
282
|
+
pagination: Pagination,
|
|
283
|
+
): Promise<[Operation<AptosAsset>[], string]> {
|
|
270
284
|
const address = normalizeAddress(rawAddress);
|
|
271
285
|
const transactions = await this.getAccountInfo(address, pagination.minHeight.toString());
|
|
272
286
|
const newOperations = transactionsToOperations(address, transactions.transactions);
|
|
@@ -8,8 +8,6 @@ export const GetDelegatedStakingActivities = gql`
|
|
|
8
8
|
) {
|
|
9
9
|
amount
|
|
10
10
|
delegator_address
|
|
11
|
-
event_index
|
|
12
|
-
event_type
|
|
13
11
|
pool_address
|
|
14
12
|
transaction_version
|
|
15
13
|
}
|
|
@@ -76,10 +74,7 @@ export const GetNumActiveDelegatorPerPoolData = gql`
|
|
|
76
74
|
|
|
77
75
|
export const GetCurrentDelegatorBalancesData = gql`
|
|
78
76
|
query GetCurrentDelegatorBalances {
|
|
79
|
-
current_delegator_balances(
|
|
80
|
-
distinct_on: pool_address
|
|
81
|
-
order_by: { current_pool_balance: { total_coins: desc }, pool_address: asc }
|
|
82
|
-
) {
|
|
77
|
+
current_delegator_balances(distinct_on: pool_address) {
|
|
83
78
|
current_pool_balance {
|
|
84
79
|
total_coins
|
|
85
80
|
operator_commission_percentage
|
package/src/preload.ts
CHANGED
|
@@ -2,11 +2,15 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
|
2
2
|
import { setAptosPreloadData } from "./preload-data";
|
|
3
3
|
import { AptosPreloadData, AptosValidator } from "./types";
|
|
4
4
|
import { getValidators } from "./network/validators";
|
|
5
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
5
6
|
|
|
6
7
|
export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
|
|
7
8
|
|
|
8
9
|
export async function preloadWithValidators(currency: CryptoCurrency): Promise<AptosPreloadData> {
|
|
9
|
-
|
|
10
|
+
let validators: AptosValidator[] = [];
|
|
11
|
+
if (getEnv("APTOS_ENABLE_STAKING") === true) {
|
|
12
|
+
validators = await getValidators(currency.id);
|
|
13
|
+
}
|
|
10
14
|
|
|
11
15
|
const data: AptosPreloadData = {
|
|
12
16
|
validatorsWithMeta: [],
|
package/src/types/assets.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import type { Asset } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
+
|
|
3
|
+
export type AptosAsset = Asset<AptosTokenInformation>;
|
|
4
|
+
|
|
5
|
+
export type AptosTokenInformation = {
|
|
6
|
+
standard: string;
|
|
7
|
+
contractAddress: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
1
10
|
export type AptosExtra = Record<string, unknown>;
|
|
2
11
|
|
|
3
12
|
export type AptosFeeParameters = {
|