@ledgerhq/coin-aptos 2.7.0 → 2.8.0-nightly.1
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 +21 -0
- 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 -6
- package/lib/__tests__/network/client.test.js.map +1 -1
- package/lib/__tests__/network/validators.test.js +12 -8
- package/lib/__tests__/network/validators.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 +11 -7
- package/lib/network/client.js.map +1 -1
- package/lib/network/graphql/queries.d.ts +0 -3
- package/lib/network/graphql/queries.d.ts.map +1 -1
- package/lib/network/graphql/queries.js +2 -50
- package/lib/network/graphql/queries.js.map +1 -1
- package/lib/network/graphql/types.d.ts +0 -47
- package/lib/network/graphql/types.d.ts.map +1 -1
- package/lib/network/validators.d.ts.map +1 -1
- package/lib/network/validators.js +10 -5
- package/lib/network/validators.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 -6
- package/lib-es/__tests__/network/client.test.js.map +1 -1
- package/lib-es/__tests__/network/validators.test.js +12 -8
- package/lib-es/__tests__/network/validators.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 +11 -7
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/network/graphql/queries.d.ts +0 -3
- package/lib-es/network/graphql/queries.d.ts.map +1 -1
- package/lib-es/network/graphql/queries.js +1 -49
- package/lib-es/network/graphql/queries.js.map +1 -1
- package/lib-es/network/graphql/types.d.ts +0 -47
- package/lib-es/network/graphql/types.d.ts.map +1 -1
- package/lib-es/network/validators.d.ts.map +1 -1
- package/lib-es/network/validators.js +10 -5
- package/lib-es/network/validators.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 +6 -6
- 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 -10
- package/src/__tests__/network/validators.test.ts +12 -8
- 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 +15 -15
- package/src/network/graphql/queries.ts +1 -52
- package/src/network/graphql/types.ts +0 -56
- package/src/network/validators.ts +16 -6
- package/src/types/assets.ts +0 -9
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Hex, RawTransaction, Deserializer } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import type { TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
3
3
|
import { createApi } from "../../api";
|
|
4
|
-
import type { AptosAsset } from "../../types/assets";
|
|
5
4
|
import { AptosAPI } from "../../network";
|
|
6
5
|
import { APTOS_ASSET_ID } from "../../constants";
|
|
7
6
|
|
|
@@ -45,13 +44,13 @@ describe("craftTransaction", () => {
|
|
|
45
44
|
aptosSettings: {},
|
|
46
45
|
});
|
|
47
46
|
|
|
48
|
-
const txArg: TransactionIntent
|
|
47
|
+
const txArg: TransactionIntent = {
|
|
49
48
|
type: "send",
|
|
50
49
|
sender: SENDER_ADDR,
|
|
51
50
|
senderPublicKey: "public-key",
|
|
52
51
|
recipient: RECIPIENT_ADDR,
|
|
53
52
|
amount: 10n,
|
|
54
|
-
asset: { type: "
|
|
53
|
+
asset: { type: "coin", assetReference: "0x42::token::Token" },
|
|
55
54
|
};
|
|
56
55
|
|
|
57
56
|
const tx = await api.craftTransaction(txArg);
|
|
@@ -86,7 +85,7 @@ describe("craftTransaction", () => {
|
|
|
86
85
|
aptosSettings: {},
|
|
87
86
|
});
|
|
88
87
|
|
|
89
|
-
const txArg: TransactionIntent
|
|
88
|
+
const txArg: TransactionIntent = {
|
|
90
89
|
type: "send",
|
|
91
90
|
sender: SENDER_ADDR,
|
|
92
91
|
senderPublicKey: "public-key",
|
|
@@ -127,13 +126,13 @@ describe("craftTransaction", () => {
|
|
|
127
126
|
aptosSettings: {},
|
|
128
127
|
});
|
|
129
128
|
|
|
130
|
-
const txArg: TransactionIntent
|
|
129
|
+
const txArg: TransactionIntent = {
|
|
131
130
|
type: "send",
|
|
132
131
|
sender: SENDER_ADDR,
|
|
133
132
|
senderPublicKey: "public-key",
|
|
134
133
|
recipient: RECIPIENT_ADDR,
|
|
135
134
|
amount: 10n,
|
|
136
|
-
asset: { type: "
|
|
135
|
+
asset: { type: "coin", assetReference: "0x42::token::Token" },
|
|
137
136
|
};
|
|
138
137
|
|
|
139
138
|
const tx = await api.craftTransaction(txArg);
|
|
@@ -168,13 +167,13 @@ describe("craftTransaction", () => {
|
|
|
168
167
|
aptosSettings: {},
|
|
169
168
|
});
|
|
170
169
|
|
|
171
|
-
const txArg: TransactionIntent
|
|
170
|
+
const txArg: TransactionIntent = {
|
|
172
171
|
type: "send",
|
|
173
172
|
sender: SENDER_ADDR,
|
|
174
173
|
senderPublicKey: "public-key",
|
|
175
174
|
recipient: RECIPIENT_ADDR,
|
|
176
175
|
amount: 0n,
|
|
177
|
-
asset: { type: "
|
|
176
|
+
asset: { type: "fungible_asset", assetReference: "0x42" },
|
|
178
177
|
};
|
|
179
178
|
|
|
180
179
|
const tx = await api.craftTransaction(txArg);
|
|
@@ -209,13 +208,13 @@ describe("craftTransaction", () => {
|
|
|
209
208
|
aptosSettings: {},
|
|
210
209
|
});
|
|
211
210
|
|
|
212
|
-
const txArg: TransactionIntent
|
|
211
|
+
const txArg: TransactionIntent = {
|
|
213
212
|
type: "send",
|
|
214
213
|
sender: SENDER_ADDR,
|
|
215
214
|
senderPublicKey: "public-key",
|
|
216
215
|
recipient: RECIPIENT_ADDR,
|
|
217
216
|
amount: 10n,
|
|
218
|
-
asset: { type: "
|
|
217
|
+
asset: { type: "asset", assetReference: "0x42::token::Token" },
|
|
219
218
|
};
|
|
220
219
|
|
|
221
220
|
expect(async () => await api.craftTransaction(txArg)).rejects.toThrow(
|
|
@@ -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,
|
|
@@ -83,23 +83,27 @@ describe("getValidators", () => {
|
|
|
83
83
|
},
|
|
84
84
|
];
|
|
85
85
|
|
|
86
|
-
it("returns the correct information", async () => {
|
|
86
|
+
it("returns the correct information and caches the 2nd call", async () => {
|
|
87
87
|
mockedAptos.mockImplementation(() => ({
|
|
88
88
|
getAccountResource: async () => ({ locked_until_secs: "1750051574" }),
|
|
89
89
|
}));
|
|
90
90
|
|
|
91
|
+
const mockedGetValidatorsQuery = jest.fn().mockImplementation(async () => ({
|
|
92
|
+
data: {
|
|
93
|
+
current_delegator_balances,
|
|
94
|
+
},
|
|
95
|
+
}));
|
|
91
96
|
mockedApolloClient.mockImplementation(() => ({
|
|
92
|
-
query:
|
|
93
|
-
data: {
|
|
94
|
-
current_delegator_balances,
|
|
95
|
-
},
|
|
96
|
-
}),
|
|
97
|
+
query: mockedGetValidatorsQuery,
|
|
97
98
|
}));
|
|
98
99
|
|
|
99
100
|
jest.useFakeTimers().setSystemTime(new Date("2025-05-15"));
|
|
100
101
|
|
|
101
|
-
const
|
|
102
|
+
const validators1 = await getValidators("aptos");
|
|
103
|
+
const validators2 = await getValidators("aptos");
|
|
102
104
|
|
|
103
|
-
expect(
|
|
105
|
+
expect(validators1).toMatchObject(expectedResponse);
|
|
106
|
+
expect(validators1).toMatchObject(validators2);
|
|
107
|
+
expect(mockedGetValidatorsQuery.mock.calls.length).toBe(1);
|
|
104
108
|
});
|
|
105
109
|
});
|
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
|
@@ -49,7 +49,6 @@ import {
|
|
|
49
49
|
Pagination,
|
|
50
50
|
TransactionIntent,
|
|
51
51
|
} from "@ledgerhq/coin-framework/api/types";
|
|
52
|
-
import { AptosAsset } from "../types/assets";
|
|
53
52
|
import { log } from "@ledgerhq/logs";
|
|
54
53
|
import { transactionsToOperations } from "../logic/transactionsToOperations";
|
|
55
54
|
import { isTestnet } from "../logic/isTestnet";
|
|
@@ -192,7 +191,7 @@ export class AptosAPI {
|
|
|
192
191
|
};
|
|
193
192
|
}
|
|
194
193
|
|
|
195
|
-
async estimateFees(transactionIntent: TransactionIntent
|
|
194
|
+
async estimateFees(transactionIntent: TransactionIntent): Promise<FeeEstimation> {
|
|
196
195
|
const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
|
|
197
196
|
|
|
198
197
|
const txPayload: InputEntryFunctionData = {
|
|
@@ -201,20 +200,21 @@ export class AptosAPI {
|
|
|
201
200
|
functionArguments: [transactionIntent.recipient, transactionIntent.amount],
|
|
202
201
|
};
|
|
203
202
|
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
// TODO: this should be looked over again, might be more precise in terms of types..
|
|
204
|
+
if (transactionIntent.asset.type !== "native") {
|
|
205
|
+
const { type } = transactionIntent.asset;
|
|
206
206
|
|
|
207
|
-
if (
|
|
207
|
+
if (type === TOKEN_TYPE.FUNGIBLE_ASSET) {
|
|
208
208
|
txPayload.function = "0x1::primary_fungible_store::transfer";
|
|
209
209
|
txPayload.typeArguments = ["0x1::fungible_asset::Metadata"];
|
|
210
210
|
txPayload.functionArguments = [
|
|
211
|
-
transactionIntent.asset.
|
|
211
|
+
transactionIntent.asset.assetReference,
|
|
212
212
|
transactionIntent.recipient,
|
|
213
213
|
transactionIntent.amount,
|
|
214
214
|
];
|
|
215
|
-
} else if (
|
|
215
|
+
} else if (type === TOKEN_TYPE.COIN) {
|
|
216
216
|
txPayload.function = "0x1::aptos_account::transfer_coins";
|
|
217
|
-
txPayload.typeArguments = [transactionIntent.asset.
|
|
217
|
+
txPayload.typeArguments = [transactionIntent.asset.assetReference as string];
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -277,10 +277,7 @@ export class AptosAPI {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
async listOperations(
|
|
281
|
-
rawAddress: string,
|
|
282
|
-
pagination: Pagination,
|
|
283
|
-
): Promise<[Operation<AptosAsset>[], string]> {
|
|
280
|
+
async listOperations(rawAddress: string, pagination: Pagination): Promise<[Operation[], string]> {
|
|
284
281
|
const address = normalizeAddress(rawAddress);
|
|
285
282
|
const transactions = await this.getAccountInfo(address, pagination.minHeight.toString());
|
|
286
283
|
const newOperations = transactionsToOperations(address, transactions.transactions);
|
|
@@ -312,9 +309,12 @@ export class AptosAPI {
|
|
|
312
309
|
});
|
|
313
310
|
|
|
314
311
|
return Promise.all(
|
|
315
|
-
queryResponse.data.account_transactions
|
|
316
|
-
|
|
317
|
-
|
|
312
|
+
queryResponse.data.account_transactions
|
|
313
|
+
.slice()
|
|
314
|
+
.sort((a, b) => b.transaction_version - a.transaction_version)
|
|
315
|
+
.map(({ transaction_version }) => {
|
|
316
|
+
return this.richItemByVersion(transaction_version);
|
|
317
|
+
}),
|
|
318
318
|
);
|
|
319
319
|
}
|
|
320
320
|
|