@ledgerhq/coin-aptos 2.0.0-nightly.3 → 2.0.0-nightly.5

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.
Files changed (159) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +17 -0
  3. package/lib/__tests__/api/index.test.js +5 -61
  4. package/lib/__tests__/api/index.test.js.map +1 -1
  5. package/lib/__tests__/bridge/buildTransaction.test.js +2 -57
  6. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
  7. package/lib/__tests__/bridge/getFeesForTransaction.test.js +8 -109
  8. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  9. package/lib/__tests__/bridge/getTransactionStatus.test.js +37 -175
  10. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  11. package/lib/__tests__/bridge/logic.test.js +115 -889
  12. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  13. package/lib/__tests__/bridge/signOperation.test.js +2 -128
  14. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  15. package/lib/__tests__/bridge/synchronisation.test.js +67 -1214
  16. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  17. package/lib/api/graphql/queries.js +6 -6
  18. package/lib/api/graphql/types.d.ts +9 -9
  19. package/lib/api/graphql/types.d.ts.map +1 -1
  20. package/lib/api/index.d.ts +2 -5
  21. package/lib/api/index.d.ts.map +1 -1
  22. package/lib/api/index.js +4 -30
  23. package/lib/api/index.js.map +1 -1
  24. package/lib/bridge/bridge.fixture.d.ts +0 -2
  25. package/lib/bridge/bridge.fixture.d.ts.map +1 -1
  26. package/lib/bridge/bridge.fixture.js +13 -85
  27. package/lib/bridge/bridge.fixture.js.map +1 -1
  28. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  29. package/lib/bridge/buildTransaction.js +3 -29
  30. package/lib/bridge/buildTransaction.js.map +1 -1
  31. package/lib/bridge/estimateMaxSpendable.js +1 -1
  32. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  33. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  34. package/lib/bridge/getFeesForTransaction.js +7 -12
  35. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  36. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  37. package/lib/bridge/getTransactionStatus.js +14 -28
  38. package/lib/bridge/getTransactionStatus.js.map +1 -1
  39. package/lib/bridge/logic.d.ts +8 -13
  40. package/lib/bridge/logic.d.ts.map +1 -1
  41. package/lib/bridge/logic.js +54 -152
  42. package/lib/bridge/logic.js.map +1 -1
  43. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  44. package/lib/bridge/prepareTransaction.js +2 -2
  45. package/lib/bridge/prepareTransaction.js.map +1 -1
  46. package/lib/bridge/signOperation.d.ts.map +1 -1
  47. package/lib/bridge/signOperation.js +3 -17
  48. package/lib/bridge/signOperation.js.map +1 -1
  49. package/lib/bridge/synchronisation.d.ts +0 -15
  50. package/lib/bridge/synchronisation.d.ts.map +1 -1
  51. package/lib/bridge/synchronisation.js +4 -127
  52. package/lib/bridge/synchronisation.js.map +1 -1
  53. package/lib/constants.d.ts +1 -5
  54. package/lib/constants.d.ts.map +1 -1
  55. package/lib/constants.js +2 -6
  56. package/lib/constants.js.map +1 -1
  57. package/lib/test/bot-specs.d.ts.map +1 -1
  58. package/lib/test/bot-specs.js +1 -40
  59. package/lib/test/bot-specs.js.map +1 -1
  60. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  61. package/lib/test/bridgeDatasetTest.js +62 -43
  62. package/lib/test/bridgeDatasetTest.js.map +1 -1
  63. package/lib/test/speculos-deviceActions.d.ts +0 -1
  64. package/lib/test/speculos-deviceActions.d.ts.map +1 -1
  65. package/lib/test/speculos-deviceActions.js +5 -37
  66. package/lib/test/speculos-deviceActions.js.map +1 -1
  67. package/lib/types/index.d.ts +7 -18
  68. package/lib/types/index.d.ts.map +1 -1
  69. package/lib-es/__tests__/api/index.test.js +5 -61
  70. package/lib-es/__tests__/api/index.test.js.map +1 -1
  71. package/lib-es/__tests__/bridge/buildTransaction.test.js +3 -58
  72. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
  73. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +9 -110
  74. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  75. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +39 -177
  76. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  77. package/lib-es/__tests__/bridge/logic.test.js +117 -891
  78. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  79. package/lib-es/__tests__/bridge/signOperation.test.js +2 -128
  80. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  81. package/lib-es/__tests__/bridge/synchronisation.test.js +69 -1213
  82. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  83. package/lib-es/api/graphql/queries.js +6 -6
  84. package/lib-es/api/graphql/types.d.ts +9 -9
  85. package/lib-es/api/graphql/types.d.ts.map +1 -1
  86. package/lib-es/api/index.d.ts +2 -5
  87. package/lib-es/api/index.d.ts.map +1 -1
  88. package/lib-es/api/index.js +4 -30
  89. package/lib-es/api/index.js.map +1 -1
  90. package/lib-es/bridge/bridge.fixture.d.ts +0 -2
  91. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
  92. package/lib-es/bridge/bridge.fixture.js +12 -82
  93. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  94. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  95. package/lib-es/bridge/buildTransaction.js +4 -30
  96. package/lib-es/bridge/buildTransaction.js.map +1 -1
  97. package/lib-es/bridge/estimateMaxSpendable.js +1 -1
  98. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  99. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  100. package/lib-es/bridge/getFeesForTransaction.js +8 -13
  101. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  102. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  103. package/lib-es/bridge/getTransactionStatus.js +14 -28
  104. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  105. package/lib-es/bridge/logic.d.ts +8 -13
  106. package/lib-es/bridge/logic.d.ts.map +1 -1
  107. package/lib-es/bridge/logic.js +52 -146
  108. package/lib-es/bridge/logic.js.map +1 -1
  109. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  110. package/lib-es/bridge/prepareTransaction.js +2 -2
  111. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  112. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  113. package/lib-es/bridge/signOperation.js +3 -17
  114. package/lib-es/bridge/signOperation.js.map +1 -1
  115. package/lib-es/bridge/synchronisation.d.ts +0 -15
  116. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  117. package/lib-es/bridge/synchronisation.js +3 -123
  118. package/lib-es/bridge/synchronisation.js.map +1 -1
  119. package/lib-es/constants.d.ts +1 -5
  120. package/lib-es/constants.d.ts.map +1 -1
  121. package/lib-es/constants.js +1 -5
  122. package/lib-es/constants.js.map +1 -1
  123. package/lib-es/test/bot-specs.d.ts.map +1 -1
  124. package/lib-es/test/bot-specs.js +2 -41
  125. package/lib-es/test/bot-specs.js.map +1 -1
  126. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  127. package/lib-es/test/bridgeDatasetTest.js +59 -43
  128. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  129. package/lib-es/test/speculos-deviceActions.d.ts +0 -1
  130. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
  131. package/lib-es/test/speculos-deviceActions.js +4 -36
  132. package/lib-es/test/speculos-deviceActions.js.map +1 -1
  133. package/lib-es/types/index.d.ts +7 -18
  134. package/lib-es/types/index.d.ts.map +1 -1
  135. package/package.json +5 -6
  136. package/src/__tests__/api/index.test.ts +5 -75
  137. package/src/__tests__/bridge/buildTransaction.test.ts +3 -85
  138. package/src/__tests__/bridge/getFeesForTransaction.test.ts +9 -144
  139. package/src/__tests__/bridge/getTransactionStatus.test.ts +38 -217
  140. package/src/__tests__/bridge/logic.test.ts +118 -922
  141. package/src/__tests__/bridge/signOperation.test.ts +2 -141
  142. package/src/__tests__/bridge/synchronisation.test.ts +71 -1265
  143. package/src/api/graphql/queries.ts +6 -6
  144. package/src/api/graphql/types.ts +9 -9
  145. package/src/api/index.ts +5 -32
  146. package/src/bridge/bridge.fixture.ts +12 -91
  147. package/src/bridge/buildTransaction.ts +6 -39
  148. package/src/bridge/estimateMaxSpendable.ts +1 -1
  149. package/src/bridge/getFeesForTransaction.ts +9 -14
  150. package/src/bridge/getTransactionStatus.ts +13 -35
  151. package/src/bridge/logic.ts +63 -202
  152. package/src/bridge/prepareTransaction.ts +3 -4
  153. package/src/bridge/signOperation.ts +3 -19
  154. package/src/bridge/synchronisation.ts +3 -170
  155. package/src/constants.ts +1 -12
  156. package/src/test/bot-specs.ts +3 -63
  157. package/src/test/bridgeDatasetTest.ts +59 -45
  158. package/src/test/speculos-deviceActions.ts +4 -40
  159. package/src/types/index.ts +1 -15
@@ -6,35 +6,25 @@ import {
6
6
  } from "@aptos-labs/ts-sdk";
7
7
  import type { Operation, OperationType } from "@ledgerhq/types-live";
8
8
  import BigNumber from "bignumber.js";
9
- import {
10
- APTOS_ASSET_ID,
11
- APTOS_COIN_CHANGE,
12
- APTOS_FUNGIBLE_STORE,
13
- APTOS_OBJECT_CORE,
14
- DIRECTION,
15
- } from "../../constants";
9
+ import { APTOS_ASSET_ID, APTOS_COIN_CHANGE, DIRECTION } from "../../constants";
16
10
  import {
17
11
  calculateAmount,
18
12
  compareAddress,
19
- getCoinAndAmounts,
13
+ getAptosAmounts,
20
14
  getFunctionAddress,
21
- getResourceAddress,
15
+ isChangeOfAptos,
22
16
  isTestnet,
23
17
  processRecipients,
24
18
  getMaxSendBalance,
25
19
  normalizeTransactionOptions,
26
20
  getBlankOperation,
27
21
  txsToOps,
28
- getEventCoinAddress,
29
- getEventFAAddress,
30
22
  } from "../../bridge/logic";
31
23
  import type { AptosTransaction, TransactionOptions } from "../../types";
32
- import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
33
- import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
34
- import { decodeTokenAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
35
24
 
36
- jest.mock("@ledgerhq/cryptoassets");
37
- jest.mock("@ledgerhq/coin-framework/account/index");
25
+ jest.mock("@ledgerhq/cryptoassets", () => ({
26
+ getCryptoCurrencyById: jest.fn(),
27
+ }));
38
28
 
39
29
  describe("Aptos logic ", () => {
40
30
  describe("isTestnet", () => {
@@ -50,48 +40,41 @@ describe("Aptos logic ", () => {
50
40
  describe("getMaxSendBalance", () => {
51
41
  it("should return the correct max send balance when amount is greater than total gas", () => {
52
42
  const amount = new BigNumber(1000000);
53
- const account = createFixtureAccount({ balance: amount, spendableBalance: amount });
54
- const transaction = createFixtureTransaction();
55
43
  const gas = new BigNumber(200);
56
44
  const gasPrice = new BigNumber(100);
57
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
45
+ const result = getMaxSendBalance(amount, gas, gasPrice);
58
46
  expect(result.isEqualTo(amount.minus(gas.multipliedBy(gasPrice)))).toBe(true);
59
47
  });
60
48
 
61
49
  it("should return zero when amount is less than total gas", () => {
62
- const account = createFixtureAccount();
63
- const transaction = createFixtureTransaction();
50
+ const amount = new BigNumber(1000);
64
51
  const gas = new BigNumber(200);
65
52
  const gasPrice = new BigNumber(100);
66
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
53
+ const result = getMaxSendBalance(amount, gas, gasPrice);
67
54
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
68
55
  });
69
56
 
70
57
  it("should return zero when amount is equal to total gas", () => {
71
- const account = createFixtureAccount();
72
- const transaction = createFixtureTransaction();
58
+ const amount = new BigNumber(20000);
73
59
  const gas = new BigNumber(200);
74
60
  const gasPrice = new BigNumber(100);
75
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
61
+ const result = getMaxSendBalance(amount, gas, gasPrice);
76
62
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
77
63
  });
78
64
 
79
65
  it("should handle zero amount", () => {
80
- const account = createFixtureAccount();
81
- const transaction = createFixtureTransaction();
66
+ const amount = new BigNumber(0);
82
67
  const gas = new BigNumber(200);
83
68
  const gasPrice = new BigNumber(100);
84
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
69
+ const result = getMaxSendBalance(amount, gas, gasPrice);
85
70
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
86
71
  });
87
72
 
88
73
  it("should handle zero gas and gas price", () => {
89
74
  const amount = new BigNumber(1000000);
90
- const account = createFixtureAccount({ balance: amount, spendableBalance: amount });
91
- const transaction = createFixtureTransaction();
92
75
  const gas = new BigNumber(0);
93
76
  const gasPrice = new BigNumber(0);
94
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
77
+ const result = getMaxSendBalance(amount, gas, gasPrice);
95
78
  expect(result.isEqualTo(amount)).toBe(true);
96
79
  });
97
80
  });
@@ -131,7 +114,7 @@ describe("Aptos logic ", () => {
131
114
  version: "1",
132
115
  } as unknown as AptosTransaction;
133
116
 
134
- const id = "test_id";
117
+ const id = "test-id";
135
118
  const result = getBlankOperation(tx, id);
136
119
 
137
120
  expect(result).toEqual({
@@ -159,7 +142,7 @@ describe("Aptos logic ", () => {
159
142
  sequence_number: "1",
160
143
  } as unknown as AptosTransaction;
161
144
 
162
- const id = "test_id";
145
+ const id = "test-id";
163
146
  const result = getBlankOperation(tx, id);
164
147
 
165
148
  expect(result).toEqual({
@@ -309,21 +292,10 @@ describe("Aptos sync logic ", () => {
309
292
  processRecipients(payload, "0x11", op, "0x2");
310
293
  expect(op.recipients).toContain("0x2");
311
294
  });
312
-
313
- it("should add recipient for fungible assets transfer-like functions", () => {
314
- const payload: InputEntryFunctionData = {
315
- function: "0x1::primary_fungible_store::transfer",
316
- typeArguments: [],
317
- functionArguments: [["0xfff"], "0x13"],
318
- };
319
-
320
- processRecipients(payload, "0x13", op, "0x1");
321
- expect(op.recipients).toContain("0x13");
322
- });
323
295
  });
324
296
 
325
- describe("getResourceAddress", () => {
326
- it("should return coin name from the change", () => {
297
+ describe("isChangeOfAptos", () => {
298
+ it("should return true for a valid change of Aptos", () => {
327
299
  const change = {
328
300
  type: "write_resource",
329
301
  data: {
@@ -341,15 +313,6 @@ describe("Aptos sync logic ", () => {
341
313
  },
342
314
  } as unknown as WriteSetChange;
343
315
 
344
- const tx: AptosTransaction = {
345
- hash: "0x123",
346
- block: { hash: "0xabc", height: 1 },
347
- timestamp: "1000000",
348
- sequence_number: "1",
349
- version: "1",
350
- changes: [change],
351
- } as unknown as AptosTransaction;
352
-
353
316
  const event = {
354
317
  guid: {
355
318
  account_address: "0x11",
@@ -358,11 +321,11 @@ describe("Aptos sync logic ", () => {
358
321
  type: "0x1::coin::WithdrawEvent",
359
322
  } as Event;
360
323
 
361
- const result = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
362
- expect(result).toEqual(APTOS_ASSET_ID);
324
+ const result = isChangeOfAptos(change, event, "withdraw_events");
325
+ expect(result).toBe(true);
363
326
  });
364
327
 
365
- it("should return null for not finding the valid coin in change", () => {
328
+ it("should return false for an invalid change of Aptos", () => {
366
329
  const change = {
367
330
  type: "write_resource",
368
331
  data: {
@@ -380,15 +343,6 @@ describe("Aptos sync logic ", () => {
380
343
  },
381
344
  } as unknown as WriteSetChange;
382
345
 
383
- const tx: AptosTransaction = {
384
- hash: "0x123",
385
- block: { hash: "0xabc", height: 1 },
386
- timestamp: "1000000",
387
- sequence_number: "1",
388
- version: "1",
389
- changes: [change],
390
- } as unknown as AptosTransaction;
391
-
392
346
  const event = {
393
347
  guid: {
394
348
  account_address: "0x11",
@@ -397,169 +351,107 @@ describe("Aptos sync logic ", () => {
397
351
  type: "0x1::coin::WithdrawEvent",
398
352
  } as Event;
399
353
 
400
- const result = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
401
- expect(result).toBe(null);
354
+ const result = isChangeOfAptos(change, event, "withdraw_events");
355
+ expect(result).toBe(false);
402
356
  });
403
357
 
404
- it("should return null for not finding the event name in change", () => {
358
+ it("should return false for a change with a different WriteSet type", () => {
405
359
  const change = {
406
- type: "write_resource",
407
- data: {
408
- type: APTOS_COIN_CHANGE,
409
- data: {
410
- other_events: {
411
- guid: {
412
- id: {
413
- addr: "0x12",
414
- creation_num: "2",
415
- },
416
- },
417
- },
418
- },
419
- },
360
+ type: "write_module",
361
+ data: {},
420
362
  } as unknown as WriteSetChange;
421
363
 
422
- const tx: AptosTransaction = {
423
- hash: "0x123",
424
- block: { hash: "0xabc", height: 1 },
425
- timestamp: "1000000",
426
- sequence_number: "1",
427
- version: "1",
428
- changes: [change],
429
- } as unknown as AptosTransaction;
430
-
431
364
  const event = {
432
365
  guid: {
433
- account_address: "0x11",
366
+ account_address: "0x1",
434
367
  creation_number: "1",
435
368
  },
436
369
  type: "0x1::coin::WithdrawEvent",
437
370
  } as Event;
438
371
 
439
- const result = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
440
- expect(result).toBe(null);
372
+ const result = isChangeOfAptos(change, event, "withdraw_events");
373
+ expect(result).toBe(false);
441
374
  });
442
375
 
443
- it("should return fungible asset address", () => {
376
+ it("should return false if no data in WriteSet Change", () => {
444
377
  const change = {
445
378
  type: "write_resource",
446
- address: "0xsomeaddress",
447
- data: {
448
- type: APTOS_FUNGIBLE_STORE,
449
- data: {
450
- metadata: {
451
- inner: "0xassetaddress",
452
- },
453
- },
454
- },
455
379
  } as unknown as WriteSetChange;
456
380
 
457
- const tx: AptosTransaction = {
458
- hash: "0x123",
459
- block: { hash: "0xabc", height: 1 },
460
- timestamp: "1000000",
461
- sequence_number: "1",
462
- version: "1",
463
- changes: [change],
464
- } as unknown as AptosTransaction;
465
-
466
381
  const event = {
467
382
  guid: {
468
- account_address: "0x0",
469
- creation_number: "0",
470
- },
471
- type: "0x1::fungible_asset::Deposit",
472
- data: {
473
- amount: "100",
474
- store: "0xsomeaddress",
383
+ account_address: "0x11",
384
+ creation_number: "2",
475
385
  },
386
+ type: "0x1::coin::WithdrawEvent",
476
387
  } as Event;
477
388
 
478
- const result = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
479
- expect(result).toEqual("0xassetaddress");
389
+ const result = isChangeOfAptos(change, event, "withdraw_events");
390
+ expect(result).toBe(false);
480
391
  });
481
392
 
482
- it("should return null address instead of fungible asset when wrong type", () => {
393
+ it("should return false if no type in change data", () => {
483
394
  const change = {
484
395
  type: "write_resource",
485
- address: "0xsomeaddress",
486
396
  data: {
487
- type: APTOS_COIN_CHANGE,
488
397
  data: {
489
- metadata: {
490
- inner: "0xassetaddress",
398
+ withdraw_events: {
399
+ guid: {
400
+ id: {
401
+ addr: "0x11",
402
+ creation_num: "2",
403
+ },
404
+ },
491
405
  },
492
406
  },
493
407
  },
494
408
  } as unknown as WriteSetChange;
495
409
 
496
- const tx: AptosTransaction = {
497
- hash: "0x123",
498
- block: { hash: "0xabc", height: 1 },
499
- timestamp: "1000000",
500
- sequence_number: "1",
501
- version: "1",
502
- changes: [change],
503
- } as unknown as AptosTransaction;
504
-
505
410
  const event = {
506
411
  guid: {
507
- account_address: "0x0",
508
- creation_number: "0",
509
- },
510
- type: "0x1::fungible_asset::Deposit",
511
- data: {
512
- amount: "100",
513
- store: "0xsomeaddress",
412
+ account_address: "0x11",
413
+ creation_number: "2",
514
414
  },
415
+ type: "0x1::coin::WithdrawEvent",
515
416
  } as Event;
516
417
 
517
- const result = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
518
- expect(result).toEqual(null);
418
+ const result = isChangeOfAptos(change, event, "withdraw_events");
419
+ expect(result).toBe(false);
519
420
  });
520
421
 
521
- it("should return null address instead of fungible asset when wrong event address", () => {
422
+ it("should return false for a change with a different WriteSet Change type", () => {
522
423
  const change = {
523
424
  type: "write_resource",
524
- address: "0xsomeaddress",
525
425
  data: {
526
- type: APTOS_FUNGIBLE_STORE,
426
+ type: "0x1::coin::CoinStore<0x1::aptos_coin::ANY_OTHER_COIN>",
527
427
  data: {
528
- metadata: {
529
- inner: "0xassetaddress",
428
+ withdraw_events: {
429
+ guid: {
430
+ id: {
431
+ addr: "0x11",
432
+ creation_num: "2",
433
+ },
434
+ },
530
435
  },
531
436
  },
532
437
  },
533
438
  } as unknown as WriteSetChange;
534
439
 
535
- const tx: AptosTransaction = {
536
- hash: "0x123",
537
- block: { hash: "0xabc", height: 1 },
538
- timestamp: "1000000",
539
- sequence_number: "1",
540
- version: "1",
541
- changes: [change],
542
- } as unknown as AptosTransaction;
543
-
544
440
  const event = {
545
441
  guid: {
546
- account_address: "0x0",
547
- creation_number: "0",
548
- },
549
- type: "0x1::fungible_asset::Deposit",
550
- data: {
551
- amount: "100",
552
- store: "0xwrongaddress",
442
+ account_address: "0x11",
443
+ creation_number: "2",
553
444
  },
445
+ type: "0x1::coin::WithdrawEvent",
554
446
  } as Event;
555
447
 
556
- const result = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
557
- expect(result).toEqual(null);
448
+ const result = isChangeOfAptos(change, event, "withdraw_events");
449
+ expect(result).toBe(false);
558
450
  });
559
451
  });
560
452
 
561
- describe("getCoinAndAmounts", () => {
562
- it("should calculate the correct legacy coins amounts for withdraw and deposit events", () => {
453
+ describe("getAptosAmounts", () => {
454
+ it("should calculate the correct amounts for withdraw and deposit events", () => {
563
455
  const tx = {
564
456
  events: [
565
457
  {
@@ -612,78 +504,37 @@ describe("Aptos sync logic ", () => {
612
504
  } as unknown as AptosTransaction;
613
505
 
614
506
  const address = "0x11";
615
- const result = getCoinAndAmounts(tx, address);
507
+ const result = getAptosAmounts(tx, address);
616
508
 
617
509
  expect(result.amount_in).toEqual(new BigNumber(50));
618
510
  expect(result.amount_out).toEqual(new BigNumber(100));
619
- expect(result.coin_id).toEqual(APTOS_ASSET_ID);
620
511
  });
621
512
 
622
- it("should calculate the correct fungible asset amounts for withdraw and deposit events", () => {
513
+ it("should return zero amounts if no matching events are found", () => {
623
514
  const tx = {
624
515
  events: [
625
516
  {
626
- type: "0x1::fungible_asset::Withdraw",
517
+ type: "0x1::coin::WithdrawEvent",
627
518
  guid: {
628
519
  account_address: "0x11",
629
520
  creation_number: "1",
630
521
  },
631
522
  data: {
632
523
  amount: "100",
633
- store: "0x22",
634
524
  },
635
525
  },
636
526
  {
637
- type: "0x1::fungible_asset::Deposit",
527
+ type: "0x1::coin::DepositEvent",
638
528
  guid: {
639
529
  account_address: "0x11",
640
530
  creation_number: "2",
641
531
  },
642
532
  data: {
643
533
  amount: "50",
644
- store: "0x33",
645
534
  },
646
535
  },
647
536
  ],
648
537
  changes: [
649
- {
650
- type: "write_resource",
651
- address: "0x22",
652
- data: {
653
- type: APTOS_FUNGIBLE_STORE,
654
- data: {
655
- metadata: {
656
- inner: "0x44",
657
- },
658
- transfer_events: {
659
- guid: {
660
- id: {
661
- addr: "0x11",
662
- creation_num: "2",
663
- },
664
- },
665
- },
666
- },
667
- },
668
- },
669
- {
670
- type: "write_resource",
671
- address: "0x22",
672
- data: {
673
- type: APTOS_OBJECT_CORE,
674
- data: {
675
- owner: "0x11",
676
- transfer_events: {
677
- guid: {
678
- id: {
679
- addr: "0x22",
680
- creation_num: "2",
681
- },
682
- },
683
- },
684
- },
685
- },
686
- },
687
538
  {
688
539
  type: "write_resource",
689
540
  data: {
@@ -692,7 +543,7 @@ describe("Aptos sync logic ", () => {
692
543
  withdraw_events: {
693
544
  guid: {
694
545
  id: {
695
- addr: "0x11",
546
+ addr: "0x12", // should fail by address check
696
547
  creation_num: "1",
697
548
  },
698
549
  },
@@ -701,7 +552,7 @@ describe("Aptos sync logic ", () => {
701
552
  guid: {
702
553
  id: {
703
554
  addr: "0x11",
704
- creation_num: "2",
555
+ creation_num: "3", // should fail by number check
705
556
  },
706
557
  },
707
558
  },
@@ -712,11 +563,10 @@ describe("Aptos sync logic ", () => {
712
563
  } as unknown as AptosTransaction;
713
564
 
714
565
  const address = "0x11";
715
- const result = getCoinAndAmounts(tx, address);
566
+ const result = getAptosAmounts(tx, address);
716
567
 
717
568
  expect(result.amount_in).toEqual(new BigNumber(0));
718
- expect(result.amount_out).toEqual(new BigNumber(100));
719
- expect(result.coin_id).toEqual("0x44");
569
+ expect(result.amount_out).toEqual(new BigNumber(0));
720
570
  });
721
571
 
722
572
  it("should handle transactions with other events", () => {
@@ -736,11 +586,10 @@ describe("Aptos sync logic ", () => {
736
586
  } as unknown as AptosTransaction;
737
587
 
738
588
  const address = "0x1";
739
- const result = getCoinAndAmounts(tx, address);
589
+ const result = getAptosAmounts(tx, address);
740
590
 
741
591
  expect(result.amount_in).toEqual(new BigNumber(0));
742
592
  expect(result.amount_out).toEqual(new BigNumber(0));
743
- expect(result.coin_id).toEqual(null);
744
593
  });
745
594
  });
746
595
 
@@ -748,22 +597,24 @@ describe("Aptos sync logic ", () => {
748
597
  it("should calculate the correct amount when the address is the sender", () => {
749
598
  const address = "0x11";
750
599
  const sender = "0x11";
600
+ const fee = new BigNumber(10); // account pays fees
751
601
  const amount_in = new BigNumber(50);
752
602
  const amount_out = new BigNumber(100);
753
603
 
754
- const result = calculateAmount(sender, address, amount_in, amount_out);
604
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
755
605
 
756
606
  // LL negates the amount for SEND transactions during output
757
- expect(result).toEqual(new BigNumber(50)); // -(50 - 100 - 10)
607
+ expect(result).toEqual(new BigNumber(60)); // -(50 - 100 - 10)
758
608
  });
759
609
 
760
610
  it("should calculate the correct amount when the address is not the sender", () => {
761
611
  const address = "0x11";
762
612
  const sender = "0x12";
613
+ const fee = new BigNumber(10); // sender pays fees
763
614
  const amount_in = new BigNumber(100);
764
615
  const amount_out = new BigNumber(50);
765
616
 
766
- const result = calculateAmount(sender, address, amount_in, amount_out);
617
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
767
618
 
768
619
  expect(result).toEqual(new BigNumber(50)); // 100 - 50
769
620
  });
@@ -771,32 +622,34 @@ describe("Aptos sync logic ", () => {
771
622
  it("should handle transactions with zero amounts", () => {
772
623
  const address = "0x11";
773
624
  const sender = "0x11";
625
+ const fee = new BigNumber(10);
774
626
  const amount_in = new BigNumber(0);
775
627
  const amount_out = new BigNumber(0);
776
628
 
777
- const result = calculateAmount(sender, address, amount_in, amount_out);
629
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
778
630
 
779
631
  // LL negates the amount for SEND transactions during output
780
- expect(result).toEqual(new BigNumber(0)); // -(0 - 0 - 10)
632
+ expect(result).toEqual(new BigNumber(10)); // -(0 - 0 - 10)
781
633
  });
782
634
 
783
635
  it("should get negative numbers (for send tx with deposit to account)", () => {
784
636
  const address = "0x11";
785
637
  const sender = "0x11";
638
+ const fee = new BigNumber(10);
786
639
  const amount_in = new BigNumber(100);
787
640
  const amount_out = new BigNumber(0);
788
641
 
789
- const result = calculateAmount(sender, address, amount_in, amount_out);
642
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
790
643
 
791
644
  // LL negates the amount for SEND transactions during output
792
- expect(result).toEqual(new BigNumber(100).negated()); // 100 - 10
645
+ expect(result).toEqual(new BigNumber(90).negated()); // 100 - 10
793
646
  });
794
647
  });
795
648
 
796
649
  describe("txsToOps", () => {
797
- it("should convert Aptos transactions to operations correctly", () => {
650
+ it("should convert transactions to operations correctly", () => {
798
651
  const address = "0x11";
799
- const id = "test_id";
652
+ const id = "test-id";
800
653
  const txs: AptosTransaction[] = [
801
654
  {
802
655
  hash: "0x123",
@@ -864,14 +717,14 @@ describe("Aptos sync logic ", () => {
864
717
  } as unknown as AptosTransaction,
865
718
  ];
866
719
 
867
- const [result] = txsToOps({ address }, id, txs);
720
+ const result = txsToOps({ address }, id, txs);
868
721
 
869
722
  expect(result).toHaveLength(1);
870
723
  expect(result[0]).toEqual({
871
724
  id: expect.any(String),
872
725
  hash: "0x123",
873
726
  type: DIRECTION.OUT,
874
- value: new BigNumber(100),
727
+ value: new BigNumber(20100),
875
728
  fee: new BigNumber(20000),
876
729
  blockHash: "0xabc",
877
730
  blockHeight: 1,
@@ -887,7 +740,7 @@ describe("Aptos sync logic ", () => {
887
740
 
888
741
  it("should skip transactions without functions in payload", () => {
889
742
  const address = "0x11";
890
- const id = "test_id";
743
+ const id = "test-id";
891
744
  const txs: AptosTransaction[] = [
892
745
  {
893
746
  hash: "0x123",
@@ -896,6 +749,12 @@ describe("Aptos sync logic ", () => {
896
749
  gas_unit_price: "100",
897
750
  success: true,
898
751
  payload: {} as EntryFunctionPayloadResponse,
752
+ // payload: {
753
+ // type: "entry_function_payload",
754
+ // function: "0x1::coin::transfer",
755
+ // type_arguments: [],
756
+ // arguments: ["0x12", 100],
757
+ // } as EntryFunctionPayloadResponse,
899
758
  events: [],
900
759
  changes: [],
901
760
  block: { hash: "0xabc", height: 1 },
@@ -904,14 +763,14 @@ describe("Aptos sync logic ", () => {
904
763
  } as unknown as AptosTransaction,
905
764
  ];
906
765
 
907
- const [result] = txsToOps({ address }, id, txs);
766
+ const result = txsToOps({ address }, id, txs);
908
767
 
909
768
  expect(result).toHaveLength(0);
910
769
  });
911
770
 
912
771
  it("should skip transactions that result in no Aptos change", () => {
913
772
  const address = "0x11";
914
- const id = "test_id";
773
+ const id = "test-id";
915
774
  const txs: AptosTransaction[] = [
916
775
  {
917
776
  hash: "0x123",
@@ -933,719 +792,73 @@ describe("Aptos sync logic ", () => {
933
792
  } as unknown as AptosTransaction,
934
793
  ];
935
794
 
936
- const [result] = txsToOps({ address }, id, txs);
795
+ const result = txsToOps({ address }, id, txs);
937
796
 
938
797
  expect(result).toHaveLength(0);
939
798
  });
940
799
 
941
800
  it("should handle failed transactions", () => {
942
- const address = "0xa0d8";
943
- const id = "test_id";
944
- const txs: AptosTransaction[] = [
945
- {
946
- hash: "0x0189",
947
- sender: "0xa0d8",
948
- gas_used: "200",
949
- gas_unit_price: "100",
950
- success: false,
951
- payload: {
952
- function: "0x1::coin::transfer",
953
- type_arguments: ["0xd111::staked_coin::StakedAptos"],
954
- arguments: ["0x4e5e", "50000000"],
955
- type: "entry_function_payload",
956
- } as EntryFunctionPayloadResponse,
957
- events: [
958
- {
959
- guid: {
960
- creation_number: "0",
961
- account_address: "0x0",
962
- },
963
- sequence_number: "0",
964
- type: "0x1::transaction_fee::FeeStatement",
965
- data: {
966
- execution_gas_units: "5",
967
- io_gas_units: "4",
968
- storage_fee_octas: "0",
969
- storage_fee_refund_octas: "0",
970
- total_charge_gas_units: "8",
971
- },
972
- },
973
- ],
974
- changes: [
975
- {
976
- address: "0xa0d8",
977
- state_key_hash: "0x1709",
978
- data: {
979
- type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
980
- data: {
981
- coin: {
982
- value: "573163341",
983
- },
984
- deposit_events: {
985
- counter: "45",
986
- guid: {
987
- id: {
988
- addr: "0xa0d8",
989
- creation_num: "2",
990
- },
991
- },
992
- },
993
- frozen: false,
994
- withdraw_events: {
995
- counter: "82",
996
- guid: {
997
- id: {
998
- addr: "0xa0d8",
999
- creation_num: "3",
1000
- },
1001
- },
1002
- },
1003
- },
1004
- },
1005
- type: "write_resource",
1006
- },
1007
- {
1008
- address: "0xa0d8",
1009
- state_key_hash: "0x6f1e",
1010
- data: {
1011
- type: "0x1::account::Account",
1012
- data: {
1013
- authentication_key: "0xa0d8",
1014
- coin_register_events: {
1015
- counter: "5",
1016
- guid: {
1017
- id: {
1018
- addr: "0xa0d8",
1019
- creation_num: "0",
1020
- },
1021
- },
1022
- },
1023
- guid_creation_num: "12",
1024
- key_rotation_events: {
1025
- counter: "0",
1026
- guid: {
1027
- id: {
1028
- addr: "0xa0d8",
1029
- creation_num: "1",
1030
- },
1031
- },
1032
- },
1033
- rotation_capability_offer: {
1034
- for: {
1035
- vec: [],
1036
- },
1037
- },
1038
- sequence_number: "83",
1039
- signer_capability_offer: {
1040
- for: {
1041
- vec: [],
1042
- },
1043
- },
1044
- },
1045
- },
1046
- type: "write_resource",
1047
- },
1048
- {
1049
- state_key_hash: "0x6e4b",
1050
- handle: "0x1b85",
1051
- key: "0x0619",
1052
- value: "0x72c5e483c25c96010000000000000000",
1053
- data: null,
1054
- type: "write_table_item",
1055
- },
1056
- ],
1057
- block: {
1058
- hash: "0xc496",
1059
- height: 1,
1060
- },
1061
- timestamp: "1000000",
1062
- sequence_number: "1",
1063
- } as unknown as AptosTransaction,
1064
- ];
1065
-
1066
- const [result] = txsToOps({ address }, id, txs);
1067
-
1068
- expect(result).toHaveLength(1);
1069
- expect(result[0]).toEqual({
1070
- id: expect.any(String),
1071
- hash: "0x0189",
1072
- type: DIRECTION.OUT,
1073
- value: new BigNumber(20000),
1074
- fee: new BigNumber(20000),
1075
- blockHash: "0xc496",
1076
- blockHeight: 1,
1077
- senders: ["0xa0d8"],
1078
- recipients: ["0x4e5e"],
1079
- accountId: id,
1080
- date: new Date(1000),
1081
- extra: { version: undefined },
1082
- transactionSequenceNumber: 1,
1083
- hasFailed: true,
1084
- });
1085
- });
1086
-
1087
- it("should convert Aptos token transactions to operations correctly", () => {
1088
- (findTokenByAddressInCurrency as jest.Mock).mockReturnValue({
1089
- type: "TokenCurrency",
1090
- id: "aptos/coin/dstapt::staked_coin::stakedaptos",
1091
- contractAddress: "0xd111::staked_coin::StakedAptos",
1092
- parentCurrency: {
1093
- type: "CryptoCurrency",
1094
- id: "aptos",
1095
- coinType: 637,
1096
- name: "Aptos",
1097
- managerAppName: "Aptos",
1098
- ticker: "APT",
1099
- scheme: "aptos",
1100
- color: "#231F20",
1101
- family: "aptos",
1102
- units: [
1103
- {
1104
- name: "APT",
1105
- code: "APT",
1106
- magnitude: 8,
1107
- },
1108
- ],
1109
- explorerViews: [
1110
- {
1111
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1112
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1113
- },
1114
- ],
1115
- },
1116
- name: "dstAPT",
1117
- tokenType: "coin",
1118
- ticker: "dstAPT",
1119
- disableCountervalue: false,
1120
- delisted: false,
1121
- units: [
1122
- {
1123
- name: "dstAPT",
1124
- code: "dstAPT",
1125
- magnitude: 8,
1126
- },
1127
- ],
1128
- });
1129
-
1130
- jest.mock("../../bridge/logic", () => ({
1131
- ...jest.requireActual("../../bridge/logic"),
1132
- getResourceAddress: jest.fn().mockReturnValue("0xd111::staked_coin::StakedAptos"),
1133
- }));
1134
-
1135
- (decodeTokenAccountId as jest.Mock).mockReturnValue({
1136
- accountId: "token_account_id",
1137
- });
1138
-
1139
- const address = "0xa0d";
1140
- const id = "test_id";
801
+ const address = "0x11";
802
+ const id = "test-id";
1141
803
  const txs: AptosTransaction[] = [
1142
804
  {
1143
805
  hash: "0x123",
1144
- sender: address,
806
+ sender: "0x11",
1145
807
  gas_used: "200",
1146
808
  gas_unit_price: "100",
1147
- success: true,
809
+ success: false,
1148
810
  payload: {
1149
- function: "0x1::aptos_account::transfer_coins",
1150
- type_arguments: ["0xd111::staked_coin::StakedAptos"],
1151
- arguments: ["0x4e5", "1500000"],
1152
811
  type: "entry_function_payload",
812
+ function: "0x1::coin::transfer",
813
+ type_arguments: [],
814
+ arguments: ["0x12", 100],
1153
815
  } as EntryFunctionPayloadResponse,
1154
816
  events: [
1155
817
  {
1156
- guid: {
1157
- creation_number: "11",
1158
- account_address: "0xa0d",
1159
- },
1160
- sequence_number: "12",
1161
818
  type: "0x1::coin::WithdrawEvent",
1162
- data: {
1163
- amount: "1500000",
1164
- },
1165
- },
1166
- {
1167
819
  guid: {
1168
- creation_number: "4",
1169
- account_address: "0x4e5",
820
+ account_address: "0x11",
821
+ creation_number: "1",
1170
822
  },
1171
- sequence_number: "8",
1172
- type: "0x1::coin::DepositEvent",
1173
823
  data: {
1174
- amount: "1500000",
824
+ amount: "100",
1175
825
  },
1176
826
  },
1177
827
  {
828
+ type: "0x1::coin::DepositEvent",
1178
829
  guid: {
1179
- creation_number: "0",
1180
- account_address: "0x0",
830
+ account_address: "0x12",
831
+ creation_number: "2",
1181
832
  },
1182
- sequence_number: "0",
1183
- type: "0x1::transaction_fee::FeeStatement",
1184
833
  data: {
1185
- execution_gas_units: "6",
1186
- io_gas_units: "6",
1187
- storage_fee_octas: "0",
1188
- storage_fee_refund_octas: "0",
1189
- total_charge_gas_units: "12",
834
+ amount: "100",
1190
835
  },
1191
836
  },
1192
837
  ],
1193
838
  changes: [
1194
839
  {
1195
- address: "0x4e5",
1196
- state_key_hash: "0x3c0",
1197
- data: {
1198
- type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
1199
- data: {
1200
- coin: {
1201
- value: "4000000",
1202
- },
1203
- deposit_events: {
1204
- counter: "9",
1205
- guid: {
1206
- id: {
1207
- addr: "0x4e5",
1208
- creation_num: "4",
1209
- },
1210
- },
1211
- },
1212
- frozen: false,
1213
- withdraw_events: {
1214
- counter: "6",
1215
- guid: {
1216
- id: {
1217
- addr: "0x4e5",
1218
- creation_num: "5",
1219
- },
1220
- },
1221
- },
1222
- },
1223
- },
1224
840
  type: "write_resource",
1225
- },
1226
- {
1227
- address: "0xa0d",
1228
- state_key_hash: "0x1709",
1229
841
  data: {
1230
- type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
1231
- data: {
1232
- coin: {
1233
- value: "68254118",
1234
- },
1235
- deposit_events: {
1236
- counter: "46",
1237
- guid: {
1238
- id: {
1239
- addr: "0xa0d",
1240
- creation_num: "2",
1241
- },
1242
- },
1243
- },
1244
- frozen: false,
1245
- withdraw_events: {
1246
- counter: "89",
1247
- guid: {
1248
- id: {
1249
- addr: "0xa0d",
1250
- creation_num: "3",
1251
- },
1252
- },
1253
- },
1254
- },
1255
- },
1256
- type: "write_resource",
1257
- },
1258
- {
1259
- address: "0xa0d",
1260
- state_key_hash: "0x5520",
1261
- data: {
1262
- type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
842
+ type: APTOS_COIN_CHANGE,
1263
843
  data: {
1264
- coin: {
1265
- value: "1000000",
1266
- },
1267
- deposit_events: {
1268
- counter: "7",
1269
- guid: {
1270
- id: {
1271
- addr: "0xa0d",
1272
- creation_num: "10",
1273
- },
1274
- },
1275
- },
1276
- frozen: false,
1277
844
  withdraw_events: {
1278
- counter: "13",
1279
845
  guid: {
1280
846
  id: {
1281
- addr: "0xa0d",
1282
- creation_num: "11",
1283
- },
1284
- },
1285
- },
1286
- },
1287
- },
1288
- type: "write_resource",
1289
- },
1290
- {
1291
- address: "0xa0d",
1292
- state_key_hash: "0x6f1e",
1293
- data: {
1294
- type: "0x1::account::Account",
1295
- data: {
1296
- authentication_key: "0xa0d",
1297
- coin_register_events: {
1298
- counter: "5",
1299
- guid: {
1300
- id: {
1301
- addr: "0xa0d",
1302
- creation_num: "0",
1303
- },
1304
- },
1305
- },
1306
- guid_creation_num: "12",
1307
- key_rotation_events: {
1308
- counter: "0",
1309
- guid: {
1310
- id: {
1311
- addr: "0xa0d",
847
+ addr: "0x11",
1312
848
  creation_num: "1",
1313
849
  },
1314
850
  },
1315
851
  },
1316
- rotation_capability_offer: {
1317
- for: {
1318
- vec: [],
1319
- },
1320
- },
1321
- sequence_number: "122",
1322
- signer_capability_offer: {
1323
- for: {
1324
- vec: [],
1325
- },
1326
- },
1327
- },
1328
- },
1329
- type: "write_resource",
1330
- },
1331
- {
1332
- state_key_hash: "0x6e4b",
1333
- handle: "0x1b85",
1334
- key: "0x0619",
1335
- value: "0x1ddaf8da3b1497010000000000000000",
1336
- data: null,
1337
- type: "write_table_item",
1338
- },
1339
- ],
1340
- block: { hash: "0xabc", height: 1 },
1341
- timestamp: "1000000",
1342
- sequence_number: "1",
1343
- } as unknown as AptosTransaction,
1344
- ];
1345
-
1346
- const [ops, tokenOps] = txsToOps({ address }, id, txs);
1347
-
1348
- expect(ops).toHaveLength(1);
1349
- expect(ops[0]).toEqual({
1350
- id: expect.any(String),
1351
- hash: "0x123",
1352
- type: "FEES",
1353
- value: new BigNumber(20000),
1354
- fee: new BigNumber(20000),
1355
- blockHash: "0xabc",
1356
- blockHeight: 1,
1357
- senders: ["0xa0d"],
1358
- recipients: ["0x4e5"],
1359
- accountId: "token_account_id",
1360
- date: new Date(1000),
1361
- extra: { version: undefined },
1362
- transactionSequenceNumber: 1,
1363
- hasFailed: false,
1364
- });
1365
-
1366
- expect(tokenOps).toHaveLength(1);
1367
- expect(tokenOps[0]).toEqual({
1368
- id: expect.any(String),
1369
- hash: "0x123",
1370
- type: DIRECTION.OUT,
1371
- value: new BigNumber(1500000),
1372
- fee: new BigNumber(20000),
1373
- blockHash: "0xabc",
1374
- blockHeight: 1,
1375
- senders: ["0xa0d"],
1376
- recipients: ["0x4e5"],
1377
- date: new Date(1000),
1378
- extra: { version: undefined },
1379
- transactionSequenceNumber: 1,
1380
- hasFailed: false,
1381
- });
1382
- });
1383
-
1384
- it("should convert Aptos token transactions to operations correctly", () => {
1385
- (findTokenByAddressInCurrency as jest.Mock).mockReturnValue({
1386
- type: "TokenCurrency",
1387
- id: "aptos/fungible_asset/cellana_0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
1388
- contractAddress: "0x2ebb",
1389
- parentCurrency: {
1390
- type: "CryptoCurrency",
1391
- id: "aptos",
1392
- coinType: 637,
1393
- name: "Aptos",
1394
- managerAppName: "Aptos",
1395
- ticker: "APT",
1396
- scheme: "aptos",
1397
- color: "#231F20",
1398
- family: "aptos",
1399
- units: [
1400
- {
1401
- name: "APT",
1402
- code: "APT",
1403
- magnitude: 8,
1404
- },
1405
- ],
1406
- explorerViews: [
1407
- {
1408
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1409
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1410
- },
1411
- ],
1412
- },
1413
- name: "CELLANA",
1414
- tokenType: "fungible_asset",
1415
- ticker: "CELL",
1416
- disableCountervalue: false,
1417
- delisted: false,
1418
- units: [
1419
- {
1420
- name: "CELLANA",
1421
- code: "CELL",
1422
- magnitude: 8,
1423
- },
1424
- ],
1425
- });
1426
-
1427
- jest.mock("../../bridge/logic", () => ({
1428
- ...jest.requireActual("../../bridge/logic"),
1429
- getResourceAddress: jest.fn().mockReturnValue("0x2ebb"),
1430
- }));
1431
-
1432
- (encodeTokenAccountId as jest.Mock).mockReturnValue("token_account_id");
1433
-
1434
- const txs: AptosTransaction[] = [
1435
- {
1436
- hash: "0x10c9",
1437
- sender: "0xa0d8",
1438
- gas_used: "200",
1439
- gas_unit_price: "100",
1440
- success: true,
1441
- payload: {
1442
- function: "0x1::primary_fungible_store::transfer",
1443
- type_arguments: ["0x1::fungible_asset::Metadata"],
1444
- arguments: [
1445
- {
1446
- inner: "0x2ebb",
1447
- },
1448
- "0x6b8c",
1449
- "193",
1450
- ],
1451
- type: "entry_function_payload",
1452
- } as EntryFunctionPayloadResponse,
1453
- events: [
1454
- {
1455
- guid: {
1456
- creation_number: "0",
1457
- account_address: "0x0",
1458
- },
1459
- sequence_number: "0",
1460
- type: "0x1::fungible_asset::Withdraw",
1461
- data: {
1462
- amount: "193",
1463
- store: "0xd475",
1464
- },
1465
- },
1466
- {
1467
- guid: {
1468
- creation_number: "0",
1469
- account_address: "0x0",
1470
- },
1471
- sequence_number: "0",
1472
- type: "0x1::fungible_asset::Deposit",
1473
- data: {
1474
- amount: "193",
1475
- store: "0xaaa9",
1476
- },
1477
- },
1478
- {
1479
- guid: {
1480
- creation_number: "0",
1481
- account_address: "0x0",
1482
- },
1483
- sequence_number: "0",
1484
- type: "0x1::transaction_fee::FeeStatement",
1485
- data: {
1486
- execution_gas_units: "4",
1487
- io_gas_units: "6",
1488
- storage_fee_octas: "0",
1489
- storage_fee_refund_octas: "0",
1490
- total_charge_gas_units: "10",
1491
- },
1492
- },
1493
- ],
1494
- changes: [
1495
- {
1496
- address: "0xaaa9",
1497
- state_key_hash: "0x9a17",
1498
- data: {
1499
- type: "0x1::fungible_asset::FungibleStore",
1500
- data: {
1501
- balance: "10044959",
1502
- frozen: false,
1503
- metadata: {
1504
- inner: "0x2ebb",
1505
- },
1506
- },
1507
- },
1508
- type: "write_resource",
1509
- },
1510
- {
1511
- address: "0xaaa9",
1512
- state_key_hash: "0x9a17",
1513
- data: {
1514
- type: "0x1::object::ObjectCore",
1515
- data: {
1516
- allow_ungated_transfer: false,
1517
- guid_creation_num: "1125899906842625",
1518
- owner: "0x6b8c",
1519
- transfer_events: {
1520
- counter: "0",
1521
- guid: {
1522
- id: {
1523
- addr: "0xaaa9",
1524
- creation_num: "1125899906842624",
1525
- },
1526
- },
1527
- },
1528
- },
1529
- },
1530
- type: "write_resource",
1531
- },
1532
- {
1533
- address: "0xa0d8",
1534
- state_key_hash: "0x1709",
1535
- data: {
1536
- type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
1537
- data: {
1538
- coin: {
1539
- value: "98423118",
1540
- },
1541
852
  deposit_events: {
1542
- counter: "46",
1543
853
  guid: {
1544
854
  id: {
1545
- addr: "0xa0d8",
855
+ addr: "0x12",
1546
856
  creation_num: "2",
1547
857
  },
1548
858
  },
1549
859
  },
1550
- frozen: false,
1551
- withdraw_events: {
1552
- counter: "88",
1553
- guid: {
1554
- id: {
1555
- addr: "0xa0d8",
1556
- creation_num: "3",
1557
- },
1558
- },
1559
- },
1560
- },
1561
- },
1562
- type: "write_resource",
1563
- },
1564
- {
1565
- address: "0xa0d8",
1566
- state_key_hash: "0x6f1e",
1567
- data: {
1568
- type: "0x1::account::Account",
1569
- data: {
1570
- authentication_key: "0xa0d8",
1571
- coin_register_events: {
1572
- counter: "5",
1573
- guid: {
1574
- id: {
1575
- addr: "0xa0d8",
1576
- creation_num: "0",
1577
- },
1578
- },
1579
- },
1580
- guid_creation_num: "12",
1581
- key_rotation_events: {
1582
- counter: "0",
1583
- guid: {
1584
- id: {
1585
- addr: "0xa0d8",
1586
- creation_num: "1",
1587
- },
1588
- },
1589
- },
1590
- rotation_capability_offer: {
1591
- for: {
1592
- vec: [],
1593
- },
1594
- },
1595
- sequence_number: "108",
1596
- signer_capability_offer: {
1597
- for: {
1598
- vec: [],
1599
- },
1600
- },
1601
- },
1602
- },
1603
- type: "write_resource",
1604
- },
1605
- {
1606
- address: "0xd475",
1607
- state_key_hash: "0x7567",
1608
- data: {
1609
- type: "0x1::fungible_asset::FungibleStore",
1610
- data: {
1611
- balance: "14000",
1612
- frozen: false,
1613
- metadata: {
1614
- inner: "0x2ebb",
1615
- },
1616
860
  },
1617
861
  },
1618
- type: "write_resource",
1619
- },
1620
- {
1621
- address: "0xd475",
1622
- state_key_hash: "0x7567",
1623
- data: {
1624
- type: "0x1::object::ObjectCore",
1625
- data: {
1626
- allow_ungated_transfer: false,
1627
- guid_creation_num: "1125899906842625",
1628
- owner: "0xa0d8",
1629
- transfer_events: {
1630
- counter: "0",
1631
- guid: {
1632
- id: {
1633
- addr: "0xd475",
1634
- creation_num: "1125899906842624",
1635
- },
1636
- },
1637
- },
1638
- },
1639
- },
1640
- type: "write_resource",
1641
- },
1642
- {
1643
- state_key_hash: "0x6e4b",
1644
- handle: "0x1b85",
1645
- key: "0x0619",
1646
- value: "0xad4388dc7daf96010000000000000000",
1647
- data: null,
1648
- type: "write_table_item",
1649
862
  },
1650
863
  ],
1651
864
  block: { hash: "0xabc", height: 1 },
@@ -1654,27 +867,10 @@ describe("Aptos sync logic ", () => {
1654
867
  } as unknown as AptosTransaction,
1655
868
  ];
1656
869
 
1657
- const [ops, tokenOps] = txsToOps({ address: "0x6b8c" }, "test_id", txs);
870
+ const result = txsToOps({ address }, id, txs);
1658
871
 
1659
- expect(ops).toHaveLength(0);
1660
-
1661
- expect(tokenOps).toHaveLength(1);
1662
- expect(tokenOps[0]).toEqual({
1663
- id: expect.any(String),
1664
- accountId: "token_account_id",
1665
- hash: "0x10c9",
1666
- type: DIRECTION.IN,
1667
- value: new BigNumber(193),
1668
- fee: new BigNumber(20000),
1669
- blockHash: "0xabc",
1670
- blockHeight: 1,
1671
- senders: ["0xa0d8"],
1672
- recipients: ["0x6b8c"],
1673
- date: new Date(1000),
1674
- extra: { version: undefined },
1675
- transactionSequenceNumber: 1,
1676
- hasFailed: false,
1677
- });
872
+ expect(result).toHaveLength(1);
873
+ expect(result[0].hasFailed).toBe(true);
1678
874
  });
1679
875
  });
1680
876
  });