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