@ledgerhq/coin-aptos 3.5.0-nightly.1 → 3.5.0-nightly.20251030160608
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 +14 -10
- package/lib/bridge/deviceTransactionConfig.d.ts +1 -1
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/bridge/deviceTransactionConfig.js +1 -1
- package/lib/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib/bridge/logic.d.ts +1 -1
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +14 -10
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +9 -9
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +0 -8
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.d.ts +1 -1
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.js +1 -1
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib-es/bridge/logic.d.ts +1 -1
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +15 -11
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +9 -9
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +0 -8
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/package.json +12 -12
- package/src/__tests__/api/craftTransaction.unit.test.ts +0 -84
- package/src/__tests__/bridge/deviceTransactionConfig.test.ts +8 -8
- package/src/__tests__/bridge/logic.test.ts +90 -83
- package/src/__tests__/bridge/synchronisation.test.ts +8 -8
- package/src/bridge/deviceTransactionConfig.ts +2 -2
- package/src/bridge/logic.ts +19 -13
- package/src/bridge/synchronisation.ts +11 -13
- package/src/logic/craftTransaction.ts +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-aptos",
|
|
3
|
-
"version": "3.5.0-nightly.
|
|
3
|
+
"version": "3.5.0-nightly.20251030160608",
|
|
4
4
|
"description": "Ledger Aptos Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -95,15 +95,15 @@
|
|
|
95
95
|
"invariant": "^2.2.4",
|
|
96
96
|
"lodash": "^4.17.21",
|
|
97
97
|
"rxjs": "^7.8.1",
|
|
98
|
-
"@ledgerhq/coin-framework": "^6.8.0-nightly.
|
|
99
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
100
|
-
"@ledgerhq/devices": "8.
|
|
101
|
-
"@ledgerhq/errors": "^6.27.0-nightly.
|
|
102
|
-
"@ledgerhq/live-env": "^2.
|
|
103
|
-
"@ledgerhq/live-network": "^2.0.
|
|
98
|
+
"@ledgerhq/coin-framework": "^6.8.0-nightly.20251030160608",
|
|
99
|
+
"@ledgerhq/cryptoassets": "^13.32.0-nightly.20251030160608",
|
|
100
|
+
"@ledgerhq/devices": "8.7.0-nightly.20251030160608",
|
|
101
|
+
"@ledgerhq/errors": "^6.27.0-nightly.20251030160608",
|
|
102
|
+
"@ledgerhq/live-env": "^2.20.0-nightly.20251030160608",
|
|
103
|
+
"@ledgerhq/live-network": "^2.1.0-nightly.20251030160608",
|
|
104
104
|
"@ledgerhq/logs": "^6.13.0",
|
|
105
|
-
"@ledgerhq/types-cryptoassets": "^7.
|
|
106
|
-
"@ledgerhq/types-live": "^6.88.0-nightly.
|
|
105
|
+
"@ledgerhq/types-cryptoassets": "^7.30.0-nightly.20251030160608",
|
|
106
|
+
"@ledgerhq/types-live": "^6.88.0-nightly.20251030160608"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
109
|
"@faker-js/faker": "^9.4.0",
|
|
@@ -111,12 +111,12 @@
|
|
|
111
111
|
"@types/jest": "^29.5.14",
|
|
112
112
|
"@types/lodash": "^4.17.14",
|
|
113
113
|
"@types/semver": "^7.5.8",
|
|
114
|
-
"axios": "1.
|
|
114
|
+
"axios": "1.12.2",
|
|
115
115
|
"jest": "^29.7.0",
|
|
116
116
|
"react": "18.3.1",
|
|
117
117
|
"ts-jest": "^29.2.5",
|
|
118
|
-
"@ledgerhq/disable-network-setup": "^0.0.
|
|
119
|
-
"@ledgerhq/types-cryptoassets": "^7.
|
|
118
|
+
"@ledgerhq/disable-network-setup": "^0.1.0-nightly.20251030160608",
|
|
119
|
+
"@ledgerhq/types-cryptoassets": "^7.30.0-nightly.20251030160608"
|
|
120
120
|
},
|
|
121
121
|
"scripts": {
|
|
122
122
|
"clean": "rimraf lib lib-es",
|
|
@@ -72,48 +72,6 @@ describe("craftTransaction", () => {
|
|
|
72
72
|
);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it("creates a native coin transaction using all amount available", async () => {
|
|
76
|
-
const mockGenerateTransaction = jest.fn().mockResolvedValue(rawTxn);
|
|
77
|
-
const mockGetBalances = jest
|
|
78
|
-
.fn()
|
|
79
|
-
.mockResolvedValue([{ contractAddress: APTOS_ASSET_ID, amount: 12345 }]);
|
|
80
|
-
mockedAptosApi.mockImplementation(() => ({
|
|
81
|
-
generateTransaction: mockGenerateTransaction,
|
|
82
|
-
getBalances: mockGetBalances,
|
|
83
|
-
}));
|
|
84
|
-
|
|
85
|
-
const api = createApi({
|
|
86
|
-
aptosSettings: {},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const txArg: TransactionIntent = {
|
|
90
|
-
intentType: "transaction",
|
|
91
|
-
type: "send",
|
|
92
|
-
sender: SENDER_ADDR,
|
|
93
|
-
senderPublicKey: "public-key",
|
|
94
|
-
recipient: RECIPIENT_ADDR,
|
|
95
|
-
amount: 0n,
|
|
96
|
-
asset: { type: "native" },
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const { transaction: tx } = await api.craftTransaction(txArg);
|
|
100
|
-
|
|
101
|
-
expect(tx).not.toEqual("");
|
|
102
|
-
expect(Hex.isValid(tx).valid).toBeTruthy();
|
|
103
|
-
expect(mockGetBalances).toHaveBeenCalledTimes(1);
|
|
104
|
-
expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
|
|
105
|
-
|
|
106
|
-
expect(mockGenerateTransaction).toHaveBeenCalledWith(
|
|
107
|
-
SENDER_ADDR,
|
|
108
|
-
expect.objectContaining({
|
|
109
|
-
function: "0x1::aptos_account::transfer_coins",
|
|
110
|
-
typeArguments: [APTOS_ASSET_ID],
|
|
111
|
-
functionArguments: [RECIPIENT_ADDR, "12345"],
|
|
112
|
-
}),
|
|
113
|
-
expect.anything(),
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
75
|
it("creates a coin token transaction", async () => {
|
|
118
76
|
const mockGenerateTransaction = jest.fn().mockResolvedValue(rawTxn);
|
|
119
77
|
const mockGetBalances = jest
|
|
@@ -156,48 +114,6 @@ describe("craftTransaction", () => {
|
|
|
156
114
|
);
|
|
157
115
|
});
|
|
158
116
|
|
|
159
|
-
it("creates a fungible_asset token transaction using all amount available", async () => {
|
|
160
|
-
const mockGenerateTransaction = jest.fn().mockResolvedValue(rawTxn);
|
|
161
|
-
const mockGetBalances = jest
|
|
162
|
-
.fn()
|
|
163
|
-
.mockResolvedValue([{ contractAddress: "0x42", amount: 12345 }]);
|
|
164
|
-
mockedAptosApi.mockImplementation(() => ({
|
|
165
|
-
generateTransaction: mockGenerateTransaction,
|
|
166
|
-
getBalances: mockGetBalances,
|
|
167
|
-
}));
|
|
168
|
-
|
|
169
|
-
const api = createApi({
|
|
170
|
-
aptosSettings: {},
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const txArg: TransactionIntent = {
|
|
174
|
-
intentType: "transaction",
|
|
175
|
-
type: "send",
|
|
176
|
-
sender: SENDER_ADDR,
|
|
177
|
-
senderPublicKey: "public-key",
|
|
178
|
-
recipient: RECIPIENT_ADDR,
|
|
179
|
-
amount: 0n,
|
|
180
|
-
asset: { type: "fungible_asset", assetReference: "0x42" },
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const { transaction: tx } = await api.craftTransaction(txArg);
|
|
184
|
-
|
|
185
|
-
expect(tx).not.toEqual("");
|
|
186
|
-
expect(Hex.isValid(tx).valid).toBeTruthy();
|
|
187
|
-
expect(mockGetBalances).toHaveBeenCalledTimes(1);
|
|
188
|
-
expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
|
|
189
|
-
|
|
190
|
-
expect(mockGenerateTransaction).toHaveBeenCalledWith(
|
|
191
|
-
SENDER_ADDR,
|
|
192
|
-
expect.objectContaining({
|
|
193
|
-
function: "0x1::primary_fungible_store::transfer",
|
|
194
|
-
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
195
|
-
functionArguments: ["0x42", RECIPIENT_ADDR, "12345"],
|
|
196
|
-
}),
|
|
197
|
-
expect.anything(),
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
117
|
it("throws an exception for invalid tokenType", async () => {
|
|
202
118
|
const mockGenerateTransaction = jest.fn().mockResolvedValue(rawTxn);
|
|
203
119
|
const mockGetBalances = jest
|
|
@@ -6,14 +6,14 @@ import { APTOS_PRECISION } from "../../constants";
|
|
|
6
6
|
const nonBreakableSpace = " ";
|
|
7
7
|
|
|
8
8
|
describe("deviceTransactionConfig", () => {
|
|
9
|
-
test("coin transfer", () => {
|
|
9
|
+
test("coin transfer", async () => {
|
|
10
10
|
const account = createFixtureAccount();
|
|
11
11
|
const parentAccount = null;
|
|
12
12
|
const transaction = createFixtureTransaction({
|
|
13
13
|
amount: BigNumber(123).shiftedBy(APTOS_PRECISION),
|
|
14
14
|
fees: BigNumber(456),
|
|
15
15
|
});
|
|
16
|
-
const fields = getDeviceTransactionConfig({
|
|
16
|
+
const fields = await getDeviceTransactionConfig({
|
|
17
17
|
account,
|
|
18
18
|
parentAccount,
|
|
19
19
|
transaction,
|
|
@@ -33,7 +33,7 @@ describe("deviceTransactionConfig", () => {
|
|
|
33
33
|
]);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
test("stake", () => {
|
|
36
|
+
test("stake", async () => {
|
|
37
37
|
const account = createFixtureAccount();
|
|
38
38
|
const parentAccount = null;
|
|
39
39
|
const transaction = createFixtureTransaction({
|
|
@@ -42,7 +42,7 @@ describe("deviceTransactionConfig", () => {
|
|
|
42
42
|
recipient: "delegator id",
|
|
43
43
|
mode: "stake",
|
|
44
44
|
});
|
|
45
|
-
const fields = getDeviceTransactionConfig({
|
|
45
|
+
const fields = await getDeviceTransactionConfig({
|
|
46
46
|
account,
|
|
47
47
|
parentAccount,
|
|
48
48
|
transaction,
|
|
@@ -67,7 +67,7 @@ describe("deviceTransactionConfig", () => {
|
|
|
67
67
|
]);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
test("unstake", () => {
|
|
70
|
+
test("unstake", async () => {
|
|
71
71
|
const account = createFixtureAccount();
|
|
72
72
|
const parentAccount = null;
|
|
73
73
|
const transaction = createFixtureTransaction({
|
|
@@ -76,7 +76,7 @@ describe("deviceTransactionConfig", () => {
|
|
|
76
76
|
recipient: "delegator id",
|
|
77
77
|
mode: "unstake",
|
|
78
78
|
});
|
|
79
|
-
const fields = getDeviceTransactionConfig({
|
|
79
|
+
const fields = await getDeviceTransactionConfig({
|
|
80
80
|
account,
|
|
81
81
|
parentAccount,
|
|
82
82
|
transaction,
|
|
@@ -101,7 +101,7 @@ describe("deviceTransactionConfig", () => {
|
|
|
101
101
|
]);
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
test("unstake", () => {
|
|
104
|
+
test("unstake", async () => {
|
|
105
105
|
const account = createFixtureAccount();
|
|
106
106
|
const parentAccount = null;
|
|
107
107
|
const transaction = createFixtureTransaction({
|
|
@@ -109,7 +109,7 @@ describe("deviceTransactionConfig", () => {
|
|
|
109
109
|
fees: BigNumber(456),
|
|
110
110
|
mode: "withdraw",
|
|
111
111
|
});
|
|
112
|
-
const fields = getDeviceTransactionConfig({
|
|
112
|
+
const fields = await getDeviceTransactionConfig({
|
|
113
113
|
account,
|
|
114
114
|
parentAccount,
|
|
115
115
|
transaction,
|
|
@@ -4,12 +4,13 @@ import { APTOS_COIN_CHANGE, OP_TYPE } from "../../constants";
|
|
|
4
4
|
import { getMaxSendBalance, getBlankOperation, txsToOps } from "../../bridge/logic";
|
|
5
5
|
import type { AptosTransaction, TransactionOptions } from "../../types";
|
|
6
6
|
import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
|
|
7
|
-
import {
|
|
7
|
+
import { getCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
|
|
8
8
|
import { decodeTokenAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
9
9
|
import { normalizeTransactionOptions } from "../../logic/normalizeTransactionOptions";
|
|
10
10
|
|
|
11
11
|
jest.mock("@ledgerhq/cryptoassets");
|
|
12
12
|
jest.mock("@ledgerhq/coin-framework/account/index");
|
|
13
|
+
jest.mock("@ledgerhq/coin-framework/crypto-assets/index");
|
|
13
14
|
|
|
14
15
|
describe("Aptos logic ", () => {
|
|
15
16
|
describe("getMaxSendBalance", () => {
|
|
@@ -149,7 +150,7 @@ describe("Aptos logic ", () => {
|
|
|
149
150
|
|
|
150
151
|
describe("Aptos sync logic ", () => {
|
|
151
152
|
describe("txsToOps", () => {
|
|
152
|
-
it("should convert Aptos transactions to operations correctly", () => {
|
|
153
|
+
it("should convert Aptos transactions to operations correctly", async () => {
|
|
153
154
|
const address = "0x11";
|
|
154
155
|
const id = "test_id";
|
|
155
156
|
const txs: AptosTransaction[] = [
|
|
@@ -219,7 +220,7 @@ describe("Aptos sync logic ", () => {
|
|
|
219
220
|
} as unknown as AptosTransaction,
|
|
220
221
|
];
|
|
221
222
|
|
|
222
|
-
const [result] = txsToOps({ address }, id, txs);
|
|
223
|
+
const [result] = await txsToOps({ address }, id, txs);
|
|
223
224
|
|
|
224
225
|
expect(result).toHaveLength(1);
|
|
225
226
|
expect(result[0]).toEqual({
|
|
@@ -240,7 +241,7 @@ describe("Aptos sync logic ", () => {
|
|
|
240
241
|
});
|
|
241
242
|
});
|
|
242
243
|
|
|
243
|
-
it("should skip transactions without functions in payload", () => {
|
|
244
|
+
it("should skip transactions without functions in payload", async () => {
|
|
244
245
|
const address = "0x11";
|
|
245
246
|
const id = "test_id";
|
|
246
247
|
const txs: AptosTransaction[] = [
|
|
@@ -259,12 +260,12 @@ describe("Aptos sync logic ", () => {
|
|
|
259
260
|
} as unknown as AptosTransaction,
|
|
260
261
|
];
|
|
261
262
|
|
|
262
|
-
const [result] = txsToOps({ address }, id, txs);
|
|
263
|
+
const [result] = await txsToOps({ address }, id, txs);
|
|
263
264
|
|
|
264
265
|
expect(result).toHaveLength(0);
|
|
265
266
|
});
|
|
266
267
|
|
|
267
|
-
it("should skip transactions that result in no Aptos change", () => {
|
|
268
|
+
it("should skip transactions that result in no Aptos change", async () => {
|
|
268
269
|
const address = "0x11";
|
|
269
270
|
const id = "test_id";
|
|
270
271
|
const txs: AptosTransaction[] = [
|
|
@@ -288,12 +289,12 @@ describe("Aptos sync logic ", () => {
|
|
|
288
289
|
} as unknown as AptosTransaction,
|
|
289
290
|
];
|
|
290
291
|
|
|
291
|
-
const [result] = txsToOps({ address }, id, txs);
|
|
292
|
+
const [result] = await txsToOps({ address }, id, txs);
|
|
292
293
|
|
|
293
294
|
expect(result).toHaveLength(0);
|
|
294
295
|
});
|
|
295
296
|
|
|
296
|
-
it("should handle failed transactions", () => {
|
|
297
|
+
it("should handle failed transactions", async () => {
|
|
297
298
|
const address = "0xa0d8";
|
|
298
299
|
const id = "test_id";
|
|
299
300
|
const txs: AptosTransaction[] = [
|
|
@@ -418,7 +419,7 @@ describe("Aptos sync logic ", () => {
|
|
|
418
419
|
} as unknown as AptosTransaction,
|
|
419
420
|
];
|
|
420
421
|
|
|
421
|
-
const [result] = txsToOps({ address }, id, txs);
|
|
422
|
+
const [result] = await txsToOps({ address }, id, txs);
|
|
422
423
|
|
|
423
424
|
expect(result).toHaveLength(1);
|
|
424
425
|
expect(result[0]).toEqual({
|
|
@@ -439,47 +440,50 @@ describe("Aptos sync logic ", () => {
|
|
|
439
440
|
});
|
|
440
441
|
});
|
|
441
442
|
|
|
442
|
-
it("should convert Aptos token transactions to operations correctly", () => {
|
|
443
|
-
(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
443
|
+
it("should convert Aptos token transactions to operations correctly", async () => {
|
|
444
|
+
(encodeTokenAccountId as jest.Mock).mockReturnValue("token_account_id");
|
|
445
|
+
(getCryptoAssetsStore as jest.Mock).mockReturnValue({
|
|
446
|
+
findTokenByAddressInCurrency: jest.fn().mockReturnValue({
|
|
447
|
+
type: "TokenCurrency",
|
|
448
|
+
id: "aptos/coin/dstapt::staked_coin::stakedaptos",
|
|
449
|
+
contractAddress: "0xd111::staked_coin::StakedAptos",
|
|
450
|
+
parentCurrency: {
|
|
451
|
+
type: "CryptoCurrency",
|
|
452
|
+
id: "aptos",
|
|
453
|
+
coinType: 637,
|
|
454
|
+
name: "Aptos",
|
|
455
|
+
managerAppName: "Aptos",
|
|
456
|
+
ticker: "APT",
|
|
457
|
+
scheme: "aptos",
|
|
458
|
+
color: "#231F20",
|
|
459
|
+
family: "aptos",
|
|
460
|
+
units: [
|
|
461
|
+
{
|
|
462
|
+
name: "APT",
|
|
463
|
+
code: "APT",
|
|
464
|
+
magnitude: 8,
|
|
465
|
+
},
|
|
466
|
+
],
|
|
467
|
+
explorerViews: [
|
|
468
|
+
{
|
|
469
|
+
address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
|
|
470
|
+
tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
},
|
|
474
|
+
name: "dstAPT",
|
|
475
|
+
tokenType: "coin",
|
|
476
|
+
ticker: "dstAPT",
|
|
477
|
+
disableCountervalue: false,
|
|
478
|
+
delisted: false,
|
|
457
479
|
units: [
|
|
458
480
|
{
|
|
459
|
-
name: "
|
|
460
|
-
code: "
|
|
481
|
+
name: "dstAPT",
|
|
482
|
+
code: "dstAPT",
|
|
461
483
|
magnitude: 8,
|
|
462
484
|
},
|
|
463
485
|
],
|
|
464
|
-
|
|
465
|
-
{
|
|
466
|
-
address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
|
|
467
|
-
tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
|
|
468
|
-
},
|
|
469
|
-
],
|
|
470
|
-
},
|
|
471
|
-
name: "dstAPT",
|
|
472
|
-
tokenType: "coin",
|
|
473
|
-
ticker: "dstAPT",
|
|
474
|
-
disableCountervalue: false,
|
|
475
|
-
delisted: false,
|
|
476
|
-
units: [
|
|
477
|
-
{
|
|
478
|
-
name: "dstAPT",
|
|
479
|
-
code: "dstAPT",
|
|
480
|
-
magnitude: 8,
|
|
481
|
-
},
|
|
482
|
-
],
|
|
486
|
+
}),
|
|
483
487
|
});
|
|
484
488
|
|
|
485
489
|
jest.mock("../../bridge/logic", () => ({
|
|
@@ -698,7 +702,7 @@ describe("Aptos sync logic ", () => {
|
|
|
698
702
|
} as unknown as AptosTransaction,
|
|
699
703
|
];
|
|
700
704
|
|
|
701
|
-
const [ops, tokenOps] = txsToOps({ address }, id, txs);
|
|
705
|
+
const [ops, tokenOps] = await txsToOps({ address }, id, txs);
|
|
702
706
|
|
|
703
707
|
expect(ops).toHaveLength(1);
|
|
704
708
|
expect(ops[0]).toEqual({
|
|
@@ -721,6 +725,7 @@ describe("Aptos sync logic ", () => {
|
|
|
721
725
|
expect(tokenOps).toHaveLength(1);
|
|
722
726
|
expect(tokenOps[0]).toEqual({
|
|
723
727
|
id: expect.any(String),
|
|
728
|
+
accountId: "token_account_id",
|
|
724
729
|
hash: "0x123",
|
|
725
730
|
type: OP_TYPE.OUT,
|
|
726
731
|
value: new BigNumber(1500000),
|
|
@@ -736,47 +741,49 @@ describe("Aptos sync logic ", () => {
|
|
|
736
741
|
});
|
|
737
742
|
});
|
|
738
743
|
|
|
739
|
-
it("should convert Aptos token transactions to operations correctly", () => {
|
|
740
|
-
(
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
744
|
+
it("should convert Aptos token transactions to operations correctly", async () => {
|
|
745
|
+
(getCryptoAssetsStore as jest.Mock).mockReturnValue({
|
|
746
|
+
findTokenByAddressInCurrency: jest.fn().mockReturnValue({
|
|
747
|
+
type: "TokenCurrency",
|
|
748
|
+
id: "aptos/fungible_asset/cellana_0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
|
|
749
|
+
contractAddress: "0x2ebb",
|
|
750
|
+
parentCurrency: {
|
|
751
|
+
type: "CryptoCurrency",
|
|
752
|
+
id: "aptos",
|
|
753
|
+
coinType: 637,
|
|
754
|
+
name: "Aptos",
|
|
755
|
+
managerAppName: "Aptos",
|
|
756
|
+
ticker: "APT",
|
|
757
|
+
scheme: "aptos",
|
|
758
|
+
color: "#231F20",
|
|
759
|
+
family: "aptos",
|
|
760
|
+
units: [
|
|
761
|
+
{
|
|
762
|
+
name: "APT",
|
|
763
|
+
code: "APT",
|
|
764
|
+
magnitude: 8,
|
|
765
|
+
},
|
|
766
|
+
],
|
|
767
|
+
explorerViews: [
|
|
768
|
+
{
|
|
769
|
+
address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
|
|
770
|
+
tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
|
|
771
|
+
},
|
|
772
|
+
],
|
|
773
|
+
},
|
|
774
|
+
name: "CELLANA",
|
|
775
|
+
tokenType: "fungible_asset",
|
|
776
|
+
ticker: "CELL",
|
|
777
|
+
disableCountervalue: false,
|
|
778
|
+
delisted: false,
|
|
754
779
|
units: [
|
|
755
780
|
{
|
|
756
|
-
name: "
|
|
757
|
-
code: "
|
|
781
|
+
name: "CELLANA",
|
|
782
|
+
code: "CELL",
|
|
758
783
|
magnitude: 8,
|
|
759
784
|
},
|
|
760
785
|
],
|
|
761
|
-
|
|
762
|
-
{
|
|
763
|
-
address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
|
|
764
|
-
tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
|
|
765
|
-
},
|
|
766
|
-
],
|
|
767
|
-
},
|
|
768
|
-
name: "CELLANA",
|
|
769
|
-
tokenType: "fungible_asset",
|
|
770
|
-
ticker: "CELL",
|
|
771
|
-
disableCountervalue: false,
|
|
772
|
-
delisted: false,
|
|
773
|
-
units: [
|
|
774
|
-
{
|
|
775
|
-
name: "CELLANA",
|
|
776
|
-
code: "CELL",
|
|
777
|
-
magnitude: 8,
|
|
778
|
-
},
|
|
779
|
-
],
|
|
786
|
+
}),
|
|
780
787
|
});
|
|
781
788
|
|
|
782
789
|
jest.mock("../../bridge/logic", () => ({
|
|
@@ -1009,7 +1016,7 @@ describe("Aptos sync logic ", () => {
|
|
|
1009
1016
|
} as unknown as AptosTransaction,
|
|
1010
1017
|
];
|
|
1011
1018
|
|
|
1012
|
-
const [ops, tokenOps] = txsToOps({ address: "0x6b8c" }, "test_id", txs);
|
|
1019
|
+
const [ops, tokenOps] = await txsToOps({ address: "0x6b8c" }, "test_id", txs);
|
|
1013
1020
|
|
|
1014
1021
|
expect(ops).toHaveLength(0);
|
|
1015
1022
|
|
|
@@ -66,7 +66,7 @@ describe("getAccountShape", () => {
|
|
|
66
66
|
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
|
|
67
67
|
|
|
68
68
|
jest.mocked(mergeOps).mockReturnValue([]);
|
|
69
|
-
jest.mocked(txsToOps).
|
|
69
|
+
jest.mocked(txsToOps).mockResolvedValue([[], [], []]);
|
|
70
70
|
|
|
71
71
|
const account = await getAccountShape(
|
|
72
72
|
{
|
|
@@ -120,7 +120,7 @@ describe("getAccountShape", () => {
|
|
|
120
120
|
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
|
|
121
121
|
|
|
122
122
|
jest.mocked(mergeOps).mockReturnValue([]);
|
|
123
|
-
jest.mocked(txsToOps).
|
|
123
|
+
jest.mocked(txsToOps).mockResolvedValue([[], [], []]);
|
|
124
124
|
|
|
125
125
|
const account = await getAccountShape(
|
|
126
126
|
{
|
|
@@ -173,7 +173,7 @@ describe("getAccountShape", () => {
|
|
|
173
173
|
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
|
|
174
174
|
|
|
175
175
|
jest.mocked(mergeOps).mockReturnValue([]);
|
|
176
|
-
jest.mocked(txsToOps).
|
|
176
|
+
jest.mocked(txsToOps).mockResolvedValue([[], [], []]);
|
|
177
177
|
|
|
178
178
|
const account = await getAccountShape(
|
|
179
179
|
{
|
|
@@ -206,7 +206,7 @@ describe("getAccountShape", () => {
|
|
|
206
206
|
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
|
|
207
207
|
|
|
208
208
|
jest.mocked(mergeOps).mockReturnValue([]);
|
|
209
|
-
jest.mocked(txsToOps).
|
|
209
|
+
jest.mocked(txsToOps).mockResolvedValue([[], [], []]);
|
|
210
210
|
|
|
211
211
|
const account = await getAccountShape(
|
|
212
212
|
{
|
|
@@ -259,7 +259,7 @@ describe("getAccountShape", () => {
|
|
|
259
259
|
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
|
|
260
260
|
|
|
261
261
|
jest.mocked(mergeOps).mockReturnValue([]);
|
|
262
|
-
jest.mocked(txsToOps).
|
|
262
|
+
jest.mocked(txsToOps).mockResolvedValue([[], [], []]);
|
|
263
263
|
|
|
264
264
|
const account = await getAccountShape(
|
|
265
265
|
{
|
|
@@ -312,7 +312,7 @@ describe("getAccountShape", () => {
|
|
|
312
312
|
const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
|
|
313
313
|
|
|
314
314
|
jest.mocked(mergeOps).mockReturnValue([]);
|
|
315
|
-
jest.mocked(txsToOps).
|
|
315
|
+
jest.mocked(txsToOps).mockResolvedValue([[], [], []]);
|
|
316
316
|
|
|
317
317
|
const account = await getAccountShape(
|
|
318
318
|
{
|
|
@@ -941,7 +941,7 @@ describe("getAccountShape", () => {
|
|
|
941
941
|
const stakingOperations = [] as Operation[];
|
|
942
942
|
|
|
943
943
|
jest.mocked(mergeOps).mockReturnValue(operations);
|
|
944
|
-
jest.mocked(txsToOps).
|
|
944
|
+
jest.mocked(txsToOps).mockResolvedValue([operations, tokenOperations, stakingOperations]);
|
|
945
945
|
|
|
946
946
|
const info = {
|
|
947
947
|
currency: {
|
|
@@ -2207,7 +2207,7 @@ describe("getStake", () => {
|
|
|
2207
2207
|
}));
|
|
2208
2208
|
|
|
2209
2209
|
jest.mocked(mergeOps).mockReturnValue(operations);
|
|
2210
|
-
jest.mocked(txsToOps).
|
|
2210
|
+
jest.mocked(txsToOps).mockResolvedValue([operations, tokenOperations, stakingOperations]);
|
|
2211
2211
|
|
|
2212
2212
|
const info = {
|
|
2213
2213
|
currency: {
|
|
@@ -4,7 +4,7 @@ import { Transaction } from "../types";
|
|
|
4
4
|
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
|
5
5
|
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account/helpers";
|
|
6
6
|
|
|
7
|
-
function getDeviceTransactionConfig({
|
|
7
|
+
async function getDeviceTransactionConfig({
|
|
8
8
|
account,
|
|
9
9
|
parentAccount,
|
|
10
10
|
transaction,
|
|
@@ -12,7 +12,7 @@ function getDeviceTransactionConfig({
|
|
|
12
12
|
account: AccountLike;
|
|
13
13
|
parentAccount: Account | null | undefined;
|
|
14
14
|
transaction: Transaction;
|
|
15
|
-
}): Array<DeviceTransactionField
|
|
15
|
+
}): Promise<Array<DeviceTransactionField>> {
|
|
16
16
|
const { mode } = transaction;
|
|
17
17
|
const fields: DeviceTransactionField[] = [];
|
|
18
18
|
const mainAccount = getMainAccount(account, parentAccount);
|
package/src/bridge/logic.ts
CHANGED
|
@@ -2,13 +2,12 @@ import BigNumber from "bignumber.js";
|
|
|
2
2
|
import { EntryFunctionPayloadResponse } from "@aptos-labs/ts-sdk";
|
|
3
3
|
import type { Account, Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
|
|
4
4
|
import {
|
|
5
|
-
decodeTokenAccountId,
|
|
6
5
|
encodeTokenAccountId,
|
|
7
6
|
findSubAccountById,
|
|
8
7
|
isTokenAccount,
|
|
9
8
|
} from "@ledgerhq/coin-framework/account/index";
|
|
10
9
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
11
|
-
import {
|
|
10
|
+
import { getCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
|
|
12
11
|
import { APTOS_ASSET_ID, OP_TYPE, DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
13
12
|
import type { AptosTransaction, Transaction } from "../types";
|
|
14
13
|
import { convertFunctionPayloadResponseToInputEntryFunctionData } from "../logic/transactionsToOperations";
|
|
@@ -58,17 +57,17 @@ export const getBlankOperation = (
|
|
|
58
57
|
hasFailed: false,
|
|
59
58
|
});
|
|
60
59
|
|
|
61
|
-
export const txsToOps = (
|
|
60
|
+
export const txsToOps = async (
|
|
62
61
|
info: { address: string },
|
|
63
62
|
id: string,
|
|
64
63
|
txs: (AptosTransaction | null)[],
|
|
65
|
-
): [Operation[], Operation[], Operation[]] => {
|
|
64
|
+
): Promise<[Operation[], Operation[], Operation[]]> => {
|
|
66
65
|
const { address } = info;
|
|
67
66
|
const ops: Operation[] = [];
|
|
68
67
|
const opsTokens: Operation[] = [];
|
|
69
68
|
const opsStaking: Operation[] = [];
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
for (const tx of txs) {
|
|
72
71
|
if (tx !== null) {
|
|
73
72
|
const op: Operation = getBlankOperation(tx, id);
|
|
74
73
|
op.fee = new BigNumber(tx.gas_used).multipliedBy(new BigNumber(tx.gas_unit_price));
|
|
@@ -80,7 +79,7 @@ export const txsToOps = (
|
|
|
80
79
|
const function_address = getFunctionAddress(payload);
|
|
81
80
|
|
|
82
81
|
if (!function_address) {
|
|
83
|
-
|
|
82
|
+
continue; // skip transaction without functions in payload
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
const { coin_id, amount_in, amount_out, type } = getCoinAndAmounts(tx, address);
|
|
@@ -113,24 +112,31 @@ export const txsToOps = (
|
|
|
113
112
|
if (coin_id === APTOS_ASSET_ID) {
|
|
114
113
|
ops.push(op);
|
|
115
114
|
} else {
|
|
116
|
-
const token =
|
|
115
|
+
const token = await getCryptoAssetsStore().findTokenByAddressInCurrency(
|
|
116
|
+
coin_id.toLowerCase(),
|
|
117
|
+
"aptos",
|
|
118
|
+
);
|
|
117
119
|
if (token !== undefined) {
|
|
118
|
-
|
|
120
|
+
const tokenAccountId = encodeTokenAccountId(id, token);
|
|
121
|
+
op.accountId = tokenAccountId;
|
|
119
122
|
opsTokens.push(op);
|
|
120
123
|
|
|
121
124
|
if (op.type === OP_TYPE.OUT) {
|
|
122
|
-
|
|
125
|
+
const accountId = tokenAccountId.split("+")[0];
|
|
126
|
+
// Create FEES operation with decoded main account ID
|
|
127
|
+
const feesOp = {
|
|
123
128
|
...op,
|
|
124
|
-
accountId
|
|
129
|
+
accountId,
|
|
125
130
|
value: op.fee,
|
|
126
|
-
type: "FEES",
|
|
127
|
-
}
|
|
131
|
+
type: "FEES" as const,
|
|
132
|
+
};
|
|
133
|
+
ops.push(feesOp);
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
|
-
}
|
|
139
|
+
}
|
|
134
140
|
|
|
135
141
|
return [ops, opsTokens, opsStaking];
|
|
136
142
|
};
|