@ledgerhq/coin-sui 0.15.0 → 0.16.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.
Files changed (102) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +22 -0
  3. package/lib/api/index.d.ts.map +1 -1
  4. package/lib/api/index.integration.test.js +1 -0
  5. package/lib/api/index.integration.test.js.map +1 -1
  6. package/lib/api/index.js +10 -2
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/api/index.test.js +1 -1
  9. package/lib/api/index.test.js.map +1 -1
  10. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  11. package/lib/bridge/buildTransaction.js +1 -0
  12. package/lib/bridge/buildTransaction.js.map +1 -1
  13. package/lib/bridge/buildTransaction.test.js +2 -0
  14. package/lib/bridge/buildTransaction.test.js.map +1 -1
  15. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  16. package/lib/bridge/getFeesForTransaction.js +4 -0
  17. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  18. package/lib/bridge/index.d.ts.map +1 -1
  19. package/lib/bridge/index.js +3 -0
  20. package/lib/bridge/index.js.map +1 -1
  21. package/lib/logic/craftTransaction.d.ts +1 -1
  22. package/lib/logic/craftTransaction.d.ts.map +1 -1
  23. package/lib/logic/craftTransaction.integration.test.js +42 -0
  24. package/lib/logic/craftTransaction.integration.test.js.map +1 -1
  25. package/lib/logic/craftTransaction.js +3 -4
  26. package/lib/logic/craftTransaction.js.map +1 -1
  27. package/lib/logic/craftTransaction.test.js +19 -5
  28. package/lib/logic/craftTransaction.test.js.map +1 -1
  29. package/lib/logic/estimateFees.integration.test.js +4 -1
  30. package/lib/logic/estimateFees.integration.test.js.map +1 -1
  31. package/lib/logic/estimateFees.test.js +2 -0
  32. package/lib/logic/estimateFees.test.js.map +1 -1
  33. package/lib/network/index.d.ts +1 -1
  34. package/lib/network/sdk.d.ts +8 -4
  35. package/lib/network/sdk.d.ts.map +1 -1
  36. package/lib/network/sdk.integration.test.js +2 -2
  37. package/lib/network/sdk.integration.test.js.map +1 -1
  38. package/lib/network/sdk.js +78 -31
  39. package/lib/network/sdk.js.map +1 -1
  40. package/lib/network/sdk.test.js +148 -333
  41. package/lib/network/sdk.test.js.map +1 -1
  42. package/lib/types/model.d.ts +3 -0
  43. package/lib/types/model.d.ts.map +1 -1
  44. package/lib-es/api/index.d.ts.map +1 -1
  45. package/lib-es/api/index.integration.test.js +1 -0
  46. package/lib-es/api/index.integration.test.js.map +1 -1
  47. package/lib-es/api/index.js +10 -2
  48. package/lib-es/api/index.js.map +1 -1
  49. package/lib-es/api/index.test.js +1 -1
  50. package/lib-es/api/index.test.js.map +1 -1
  51. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  52. package/lib-es/bridge/buildTransaction.js +1 -0
  53. package/lib-es/bridge/buildTransaction.js.map +1 -1
  54. package/lib-es/bridge/buildTransaction.test.js +2 -0
  55. package/lib-es/bridge/buildTransaction.test.js.map +1 -1
  56. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  57. package/lib-es/bridge/getFeesForTransaction.js +4 -0
  58. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  59. package/lib-es/bridge/index.d.ts.map +1 -1
  60. package/lib-es/bridge/index.js +3 -0
  61. package/lib-es/bridge/index.js.map +1 -1
  62. package/lib-es/logic/craftTransaction.d.ts +1 -1
  63. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  64. package/lib-es/logic/craftTransaction.integration.test.js +42 -0
  65. package/lib-es/logic/craftTransaction.integration.test.js.map +1 -1
  66. package/lib-es/logic/craftTransaction.js +3 -4
  67. package/lib-es/logic/craftTransaction.js.map +1 -1
  68. package/lib-es/logic/craftTransaction.test.js +19 -5
  69. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  70. package/lib-es/logic/estimateFees.integration.test.js +4 -1
  71. package/lib-es/logic/estimateFees.integration.test.js.map +1 -1
  72. package/lib-es/logic/estimateFees.test.js +2 -0
  73. package/lib-es/logic/estimateFees.test.js.map +1 -1
  74. package/lib-es/network/index.d.ts +1 -1
  75. package/lib-es/network/sdk.d.ts +8 -4
  76. package/lib-es/network/sdk.d.ts.map +1 -1
  77. package/lib-es/network/sdk.integration.test.js +2 -2
  78. package/lib-es/network/sdk.integration.test.js.map +1 -1
  79. package/lib-es/network/sdk.js +75 -29
  80. package/lib-es/network/sdk.js.map +1 -1
  81. package/lib-es/network/sdk.test.js +148 -333
  82. package/lib-es/network/sdk.test.js.map +1 -1
  83. package/lib-es/types/model.d.ts +3 -0
  84. package/lib-es/types/model.d.ts.map +1 -1
  85. package/package.json +7 -7
  86. package/src/api/index.integration.test.ts +1 -0
  87. package/src/api/index.test.ts +1 -1
  88. package/src/api/index.ts +15 -2
  89. package/src/bridge/buildTransaction.test.ts +2 -0
  90. package/src/bridge/buildTransaction.ts +1 -0
  91. package/src/bridge/getFeesForTransaction.ts +4 -0
  92. package/src/bridge/index.ts +3 -0
  93. package/src/logic/craftTransaction.integration.test.ts +52 -0
  94. package/src/logic/craftTransaction.test.ts +55 -25
  95. package/src/logic/craftTransaction.ts +25 -20
  96. package/src/logic/estimateFees.integration.test.ts +4 -1
  97. package/src/logic/estimateFees.test.ts +2 -0
  98. package/src/network/sdk.integration.test.ts +2 -2
  99. package/src/network/sdk.test.ts +210 -369
  100. package/src/network/sdk.ts +114 -36
  101. package/src/types/model.ts +4 -0
  102. package/index.d.ts +0 -0
@@ -30,6 +30,7 @@ const sdk = __importStar(require("./sdk"));
30
30
  const config_1 = __importDefault(require("../config"));
31
31
  const bignumber_js_1 = require("bignumber.js");
32
32
  const client_1 = require("@mysten/sui/client");
33
+ const assert_1 = __importDefault(require("assert"));
33
34
  // Mock SUI client for tests
34
35
  jest.mock("@mysten/sui/client", () => {
35
36
  return {
@@ -208,6 +209,87 @@ const mockTransaction = {
208
209
  timestampMs: "1742294454878",
209
210
  checkpoint: "313024",
210
211
  };
212
+ // Create a mock staking transaction
213
+ // amount must be a negative number
214
+ function mockStakingTx(address, amount) {
215
+ (0, assert_1.default)(new bignumber_js_1.BigNumber(amount).lte(0), "amount must be a negative number");
216
+ return {
217
+ digest: "delegate_tx_digest_123",
218
+ transaction: {
219
+ data: {
220
+ sender: address,
221
+ transaction: {
222
+ kind: "ProgrammableTransaction",
223
+ inputs: [],
224
+ transactions: [
225
+ {
226
+ MoveCall: {
227
+ function: "request_add_stake",
228
+ },
229
+ },
230
+ ],
231
+ },
232
+ },
233
+ },
234
+ effects: {
235
+ status: { status: "success" },
236
+ gasUsed: {
237
+ computationCost: "1000000",
238
+ storageCost: "500000",
239
+ storageRebate: "450000",
240
+ },
241
+ },
242
+ balanceChanges: [
243
+ {
244
+ owner: { AddressOwner: address },
245
+ coinType: "0x2::sui::SUI",
246
+ amount: amount.startsWith("-") ? amount : `-${amount}`,
247
+ },
248
+ ],
249
+ timestampMs: "1742294454878",
250
+ checkpoint: "313024",
251
+ };
252
+ }
253
+ // amount must be a positive number
254
+ function mockUnstakingTx(address, amount) {
255
+ (0, assert_1.default)(new bignumber_js_1.BigNumber(amount).gte(0), "amount must be a positive number");
256
+ return {
257
+ digest: "undelegate_tx_digest_456",
258
+ transaction: {
259
+ data: {
260
+ sender: address,
261
+ transaction: {
262
+ kind: "ProgrammableTransaction",
263
+ inputs: [],
264
+ transactions: [
265
+ {
266
+ MoveCall: {
267
+ function: "request_withdraw_stake",
268
+ },
269
+ },
270
+ ],
271
+ },
272
+ },
273
+ },
274
+ effects: {
275
+ status: { status: "success" },
276
+ gasUsed: {
277
+ computationCost: "1000000",
278
+ storageCost: "500000",
279
+ storageRebate: "450000",
280
+ },
281
+ },
282
+ balanceChanges: [
283
+ {
284
+ owner: { AddressOwner: address },
285
+ coinType: "0x2::sui::SUI",
286
+ amount: amount,
287
+ },
288
+ ],
289
+ timestampMs: "1742294454878",
290
+ checkpoint: "313024",
291
+ };
292
+ }
211
293
  const mockApi = new client_1.SuiClient({ url: "mock" });
212
294
  // Add getTransactionBlock method to mockApi
213
295
  mockApi.getTransactionBlock = jest.fn();
@@ -278,14 +360,6 @@ describe("SDK Functions", () => {
278
360
  test("getOperationRecipients should return recipient addresses", () => {
279
361
  expect(sdk.getOperationRecipients(mockTransaction.transaction?.data)).toEqual(["0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0"]);
280
362
  });
281
- test("getOperationAmount should calculate amount correctly for SUI", () => {
282
- const address = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
283
- expect(sdk.getOperationAmount(address, mockTransaction, sdk.DEFAULT_COIN_TYPE)).toEqual(new bignumber_js_1.BigNumber("9998990120"));
284
- });
285
- test("getOperationAmount should calculate amount correctly for tokens", () => {
286
- const address = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
287
- expect(sdk.getOperationAmount(address, mockTransaction, "0x123::test::TOKEN")).toEqual(new bignumber_js_1.BigNumber("500000"));
288
- });
289
363
  test("getOperationFee should calculate fee correctly", () => {
290
364
  expect(sdk.getOperationFee(mockTransaction)).toEqual(new bignumber_js_1.BigNumber(1009880));
291
365
  });
@@ -430,7 +504,7 @@ describe("SDK Functions", () => {
430
504
  },
431
505
  ],
432
506
  };
433
- const operation = sdk.transactionToOp(address, tokenTx);
507
+ const operation = sdk.alpacaTransactionToOp(address, tokenTx);
434
508
  expect(operation.id).toEqual("DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt");
435
509
  expect(operation.type).toEqual("IN");
436
510
  expect(operation.senders).toEqual([
@@ -501,186 +575,39 @@ describe("Staking Operations", () => {
501
575
  describe("Operation Type Detection", () => {
502
576
  test("getOperationType should return DELEGATE for staking transaction", () => {
503
577
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
504
- // Create a mock staking transaction
505
- const mockStakingTx = {
506
- digest: "delegate_tx_digest_123",
507
- transaction: {
508
- data: {
509
- sender: address,
510
- transaction: {
511
- kind: "ProgrammableTransaction",
512
- inputs: [],
513
- transactions: [
514
- {
515
- MoveCall: {
516
- function: "request_add_stake",
517
- },
518
- },
519
- ],
520
- },
521
- },
522
- },
523
- effects: {
524
- status: { status: "success" },
525
- gasUsed: {
526
- computationCost: "1000000",
527
- storageCost: "500000",
528
- storageRebate: "450000",
529
- },
530
- },
531
- balanceChanges: [
532
- {
533
- owner: { AddressOwner: address },
534
- coinType: "0x2::sui::SUI",
535
- amount: "-1000000000",
536
- },
537
- ],
538
- timestampMs: "1742294454878",
539
- checkpoint: "313024",
540
- };
541
- expect(sdk.getOperationType(address, mockStakingTx)).toBe("DELEGATE");
578
+ expect(sdk.getOperationType(address, mockStakingTx(address, "-1000000000"))).toBe("DELEGATE");
542
579
  });
543
580
  test("getOperationType should return UNDELEGATE for unstaking transaction", () => {
544
581
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
545
- // Create a mock unstaking transaction
546
- const mockUnstakingTx = {
547
- digest: "undelegate_tx_digest_456",
548
- transaction: {
549
- data: {
550
- sender: address,
551
- transaction: {
552
- kind: "ProgrammableTransaction",
553
- inputs: [],
554
- transactions: [
555
- {
556
- MoveCall: {
557
- function: "request_withdraw_stake",
558
- },
559
- },
560
- ],
561
- },
562
- },
563
- },
564
- effects: {
565
- status: { status: "success" },
566
- gasUsed: {
567
- computationCost: "1000000",
568
- storageCost: "500000",
569
- storageRebate: "450000",
570
- },
571
- },
572
- balanceChanges: [
573
- {
574
- owner: { AddressOwner: address },
575
- coinType: "0x2::sui::SUI",
576
- amount: "0",
577
- },
578
- ],
579
- timestampMs: "1742294454878",
580
- checkpoint: "313024",
581
- };
582
- expect(sdk.getOperationType(address, mockUnstakingTx)).toBe("UNDELEGATE");
582
+ expect(sdk.getOperationType(address, mockUnstakingTx(address, "1000000000"))).toBe("UNDELEGATE");
583
583
  });
584
584
  });
585
585
  describe("Operation Amount Calculation", () => {
586
- test("getOperationAmount should calculate staking amount correctly", () => {
587
- const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
588
- const mockStakingTx = {
589
- transaction: {
590
- data: {
591
- transaction: {
592
- kind: "ProgrammableTransaction",
593
- transactions: [
594
- {
595
- MoveCall: {
596
- function: "request_add_stake",
597
- },
598
- },
599
- ],
600
- },
601
- },
602
- },
603
- balanceChanges: [
604
- {
605
- owner: { AddressOwner: address },
606
- coinType: "0x2::sui::SUI",
607
- amount: "-1000000000",
608
- },
609
- ],
610
- };
611
- const amount = sdk.getOperationAmount(address, mockStakingTx, sdk.DEFAULT_COIN_TYPE);
612
- expect(amount).toEqual(new bignumber_js_1.BigNumber("1000000000")); // The function returns minus of the balance change
613
- });
614
- test("getOperationAmount should calculate unstaking amount correctly", () => {
615
- const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
616
- const mockUnstakingTx = {
617
- transaction: {
618
- data: {
619
- transaction: {
620
- kind: "ProgrammableTransaction",
621
- transactions: [
622
- {
623
- MoveCall: {
624
- function: "request_withdraw_stake",
625
- },
626
- },
627
- ],
628
- },
629
- },
630
- },
631
- balanceChanges: [
632
- {
633
- owner: { AddressOwner: address },
634
- coinType: "0x2::sui::SUI",
635
- amount: "0",
636
- },
637
- ],
638
- };
639
- const amount = sdk.getOperationAmount(address, mockUnstakingTx, sdk.DEFAULT_COIN_TYPE);
640
- expect(amount).toEqual(new bignumber_js_1.BigNumber("0"));
641
- });
586
+ const address = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
587
+ function bridgeOperationAmount(mock, coinType = sdk.DEFAULT_COIN_TYPE) {
588
+ return sdk.getOperationAmount(address, mock, coinType);
589
+ }
590
+ test("getOperationAmount should calculate staking amount", () => expect(bridgeOperationAmount(mockStakingTx(address, "-1000000000"))).toEqual(new bignumber_js_1.BigNumber("1000000000")));
591
+ test("getOperationAmount should calculate unstaking amount of 1000", () => expect(bridgeOperationAmount(mockUnstakingTx(address, "1000"))).toEqual(new bignumber_js_1.BigNumber("-1000")));
592
+ test("getOperationAmount should calculate unstaking amount of 0", () => expect(bridgeOperationAmount(mockUnstakingTx(address, "0"))).toEqual(new bignumber_js_1.BigNumber("0")));
593
+ test("getOperationAmount should calculate amount correctly for SUI", () => expect(bridgeOperationAmount(mockTransaction)).toEqual(new bignumber_js_1.BigNumber("9998990120")));
594
+ test("getOperationAmount should calculate amount correctly for tokens", () => expect(bridgeOperationAmount(mockTransaction, "0x123::test::TOKEN")).toEqual(new bignumber_js_1.BigNumber("500000")));
595
+ function alpacaOperationAmount(mock, coinType = sdk.DEFAULT_COIN_TYPE) {
596
+ return sdk.alpacaGetOperationAmount(address, mock, coinType);
597
+ }
598
+ test("alpaca getOperationAmount should calculate staking amount", () => expect(alpacaOperationAmount(mockStakingTx(address, "-1000000000"))).toEqual(new bignumber_js_1.BigNumber("1000000000")));
599
+ test("alpaca getOperationAmount should calculate unstaking amount of 1000", () => expect(alpacaOperationAmount(mockUnstakingTx(address, "1000"))).toEqual(new bignumber_js_1.BigNumber("1000")));
600
+ test("alpaca getOperationAmount should calculate unstaking amount of 0", () => expect(alpacaOperationAmount(mockUnstakingTx(address, "0"))).toEqual(new bignumber_js_1.BigNumber("0")));
601
+ test("alpaca getOperationAmount should calculate amount correctly for SUI", () => expect(alpacaOperationAmount(mockTransaction)).toEqual(new bignumber_js_1.BigNumber("9998990120")));
602
+ test("alpaca getOperationAmount should calculate amount correctly for tokens", () => expect(alpacaOperationAmount(mockTransaction, "0x123::test::TOKEN")).toEqual(new bignumber_js_1.BigNumber("500000")));
642
603
  });
643
604
  describe("Operation Recipients", () => {
644
605
  test("getOperationRecipients should return empty array for staking transaction", () => {
645
- const mockStakingTx = {
646
- transaction: {
647
- data: {
648
- transaction: {
649
- kind: "ProgrammableTransaction",
650
- inputs: [],
651
- transactions: [
652
- {
653
- MoveCall: {
654
- function: "request_add_stake",
655
- },
656
- },
657
- ],
658
- },
659
- },
660
- },
661
- };
662
- const recipients = sdk.getOperationRecipients(mockStakingTx.transaction?.data);
606
+ const recipients = sdk.getOperationRecipients(mockStakingTx("0xdeadbeef", "-1000000000").transaction?.data);
663
607
  expect(recipients).toEqual([]);
664
608
  });
665
609
  test("getOperationRecipients should return empty array for unstaking transaction", () => {
666
- const mockUnstakingTx = {
667
- transaction: {
668
- data: {
669
- transaction: {
670
- kind: "ProgrammableTransaction",
671
- inputs: [],
672
- transactions: [
673
- {
674
- MoveCall: {
675
- function: "request_withdraw_stake",
676
- },
677
- },
678
- ],
679
- },
680
- },
681
- },
682
- };
683
- const recipients = sdk.getOperationRecipients(mockUnstakingTx.transaction?.data);
610
+ const recipients = sdk.getOperationRecipients(mockUnstakingTx("0xdeadbeef", "1000000000").transaction?.data);
684
611
  expect(recipients).toEqual([]);
685
612
  });
686
613
  });
@@ -761,43 +688,7 @@ describe("Staking Operations", () => {
761
688
  test("transactionToOperation should map staking transaction correctly", () => {
762
689
  const accountId = "mockAccountId";
763
690
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
764
- const mockStakingTx = {
765
- digest: "delegate_tx_digest_123",
766
- transaction: {
767
- data: {
768
- sender: address,
769
- transaction: {
770
- kind: "ProgrammableTransaction",
771
- inputs: [],
772
- transactions: [
773
- {
774
- MoveCall: {
775
- function: "request_add_stake",
776
- },
777
- },
778
- ],
779
- },
780
- },
781
- },
782
- effects: {
783
- status: { status: "success" },
784
- gasUsed: {
785
- computationCost: "1000000",
786
- storageCost: "500000",
787
- storageRebate: "450000",
788
- },
789
- },
790
- balanceChanges: [
791
- {
792
- owner: { AddressOwner: address },
793
- coinType: "0x2::sui::SUI",
794
- amount: "-1000000000",
795
- },
796
- ],
797
- timestampMs: "1742294454878",
798
- checkpoint: "313024",
799
- };
800
- const operation = sdk.transactionToOperation(accountId, address, mockStakingTx);
691
+ const operation = sdk.transactionToOperation(accountId, address, mockStakingTx(address, "-1000000000"));
801
692
  expect(operation).toHaveProperty("id");
802
693
  expect(operation).toHaveProperty("accountId", accountId);
803
694
  expect(operation).toHaveProperty("type", "DELEGATE");
@@ -811,92 +702,20 @@ describe("Staking Operations", () => {
811
702
  test("transactionToOperation should map unstaking transaction correctly", () => {
812
703
  const accountId = "mockAccountId";
813
704
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
814
- const mockUnstakingTx = {
815
- digest: "undelegate_tx_digest_456",
816
- transaction: {
817
- data: {
818
- sender: address,
819
- transaction: {
820
- kind: "ProgrammableTransaction",
821
- inputs: [],
822
- transactions: [
823
- {
824
- MoveCall: {
825
- function: "request_withdraw_stake",
826
- },
827
- },
828
- ],
829
- },
830
- },
831
- },
832
- effects: {
833
- status: { status: "success" },
834
- gasUsed: {
835
- computationCost: "1000000",
836
- storageCost: "500000",
837
- storageRebate: "450000",
838
- },
839
- },
840
- balanceChanges: [
841
- {
842
- owner: { AddressOwner: address },
843
- coinType: "0x2::sui::SUI",
844
- amount: "0",
845
- },
846
- ],
847
- timestampMs: "1742294454878",
848
- checkpoint: "313024",
849
- };
850
- const operation = sdk.transactionToOperation(accountId, address, mockUnstakingTx);
705
+ const operation = sdk.transactionToOperation(accountId, address, mockUnstakingTx(address, "1000000000"));
851
706
  expect(operation).toHaveProperty("id");
852
707
  expect(operation).toHaveProperty("accountId", accountId);
853
708
  expect(operation).toHaveProperty("type", "UNDELEGATE");
854
709
  expect(operation).toHaveProperty("hash", "undelegate_tx_digest_456");
855
710
  expect(operation).toHaveProperty("extra");
856
711
  expect(operation.extra.coinType).toBe(sdk.DEFAULT_COIN_TYPE);
857
- expect(operation.value).toEqual(new bignumber_js_1.BigNumber("0"));
712
+ expect(operation.value).toEqual(new bignumber_js_1.BigNumber("-1000000000"));
858
713
  expect(operation.recipients).toEqual([]);
859
714
  expect(operation.senders).toEqual([address]);
860
715
  });
861
716
  test("transactionToOp should map staking transaction correctly", () => {
862
717
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
863
- const mockStakingTx = {
864
- digest: "delegate_tx_digest_123",
865
- transaction: {
866
- data: {
867
- sender: address,
868
- transaction: {
869
- kind: "ProgrammableTransaction",
870
- inputs: [],
871
- transactions: [
872
- {
873
- MoveCall: {
874
- function: "request_add_stake",
875
- },
876
- },
877
- ],
878
- },
879
- },
880
- },
881
- effects: {
882
- status: { status: "success" },
883
- gasUsed: {
884
- computationCost: "1000000",
885
- storageCost: "500000",
886
- storageRebate: "450000",
887
- },
888
- },
889
- balanceChanges: [
890
- {
891
- owner: { AddressOwner: address },
892
- coinType: "0x2::sui::SUI",
893
- amount: "-1000000000",
894
- },
895
- ],
896
- timestampMs: "1742294454878",
897
- checkpoint: "313024",
898
- };
899
- const operation = sdk.transactionToOp(address, mockStakingTx);
718
+ const operation = sdk.alpacaTransactionToOp(address, mockStakingTx(address, "-1000000000"));
900
719
  expect(operation.id).toEqual("delegate_tx_digest_123");
901
720
  expect(operation.type).toEqual("DELEGATE");
902
721
  expect(operation.senders).toEqual([address]);
@@ -907,48 +726,12 @@ describe("Staking Operations", () => {
907
726
  });
908
727
  test("transactionToOp should map unstaking transaction correctly", () => {
909
728
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
910
- const mockUnstakingTx = {
911
- digest: "undelegate_tx_digest_456",
912
- transaction: {
913
- data: {
914
- sender: address,
915
- transaction: {
916
- kind: "ProgrammableTransaction",
917
- inputs: [],
918
- transactions: [
919
- {
920
- MoveCall: {
921
- function: "request_withdraw_stake",
922
- },
923
- },
924
- ],
925
- },
926
- },
927
- },
928
- effects: {
929
- status: { status: "success" },
930
- gasUsed: {
931
- computationCost: "1000000",
932
- storageCost: "500000",
933
- storageRebate: "450000",
934
- },
935
- },
936
- balanceChanges: [
937
- {
938
- owner: { AddressOwner: address },
939
- coinType: "0x2::sui::SUI",
940
- amount: "0",
941
- },
942
- ],
943
- timestampMs: "1742294454878",
944
- checkpoint: "313024",
945
- };
946
- const operation = sdk.transactionToOp(address, mockUnstakingTx);
729
+ const operation = sdk.alpacaTransactionToOp(address, mockUnstakingTx(address, "1000000000"));
947
730
  expect(operation.id).toEqual("undelegate_tx_digest_456");
948
731
  expect(operation.type).toEqual("UNDELEGATE");
949
732
  expect(operation.senders).toEqual([address]);
950
733
  expect(operation.recipients).toEqual([]);
951
- expect(operation.value).toEqual(0n);
734
+ expect(operation.value).toEqual(1000000000n);
952
735
  expect(operation.asset).toEqual({ type: "native" });
953
736
  expect(operation.tx.block.hash).toBeUndefined();
954
737
  });
@@ -1689,7 +1472,7 @@ describe("filterOperations", () => {
1689
1472
  });
1690
1473
  describe("conversion methods", () => {
1691
1474
  test("toBlockOperation should map native transfers correctly", () => {
1692
- expect(sdk.toBlockOperation({
1475
+ expect(sdk.toBlockOperation(mockTransaction, {
1693
1476
  owner: {
1694
1477
  AddressOwner: "0x65449f57946938c84c5127",
1695
1478
  },
@@ -1705,7 +1488,7 @@ describe("filterOperations", () => {
1705
1488
  ]);
1706
1489
  });
1707
1490
  test("toBlockOperation should ignore transfers from shared owner", () => {
1708
- expect(sdk.toBlockOperation({
1491
+ expect(sdk.toBlockOperation(mockTransaction, {
1709
1492
  owner: {
1710
1493
  Shared: {
1711
1494
  initial_shared_version: "0",
@@ -1716,7 +1499,7 @@ describe("filterOperations", () => {
1716
1499
  })).toEqual([]);
1717
1500
  });
1718
1501
  test("toBlockOperation should ignore transfers from object owner", () => {
1719
- expect(sdk.toBlockOperation({
1502
+ expect(sdk.toBlockOperation(mockTransaction, {
1720
1503
  owner: {
1721
1504
  ObjectOwner: "test",
1722
1505
  },
@@ -1725,14 +1508,14 @@ describe("filterOperations", () => {
1725
1508
  })).toEqual([]);
1726
1509
  });
1727
1510
  test("toBlockOperation should ignore transfers from immutable owner", () => {
1728
- expect(sdk.toBlockOperation({
1511
+ expect(sdk.toBlockOperation(mockTransaction, {
1729
1512
  owner: "Immutable",
1730
1513
  coinType: sdk.DEFAULT_COIN_TYPE,
1731
1514
  amount: "-10000000000",
1732
1515
  })).toEqual([]);
1733
1516
  });
1734
1517
  test("toBlockOperation should ignore transfers from consensus owner", () => {
1735
- expect(sdk.toBlockOperation({
1518
+ expect(sdk.toBlockOperation(mockTransaction, {
1736
1519
  owner: {
1737
1520
  ConsensusAddressOwner: {
1738
1521
  owner: "test",
@@ -1744,7 +1527,7 @@ describe("filterOperations", () => {
1744
1527
  })).toEqual([]);
1745
1528
  });
1746
1529
  test("toBlockOperation should map token transfers correctly", () => {
1747
- expect(sdk.toBlockOperation({
1530
+ expect(sdk.toBlockOperation(mockTransaction, {
1748
1531
  owner: {
1749
1532
  AddressOwner: "0x65449f57946938c84c5127",
1750
1533
  },
@@ -1762,6 +1545,38 @@ describe("filterOperations", () => {
1762
1545
  },
1763
1546
  ]);
1764
1547
  });
1548
+ test("toBlockOperation should map staking operations correctly", () => {
1549
+ const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
1550
+ expect(sdk.toBlockOperation(mockStakingTx(address, "-1000000000"), {
1551
+ owner: { AddressOwner: address },
1552
+ coinType: sdk.DEFAULT_COIN_TYPE,
1553
+ amount: "-10000000000",
1554
+ })).toEqual([
1555
+ {
1556
+ type: "other",
1557
+ operationType: "DELEGATE",
1558
+ address: address,
1559
+ asset: { type: "native" },
1560
+ amount: 10000000000n,
1561
+ },
1562
+ ]);
1563
+ });
1564
+ test("toBlockOperation should map unstaking operations correctly", () => {
1565
+ const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
1566
+ expect(sdk.toBlockOperation(mockUnstakingTx(address, "1000000000"), {
1567
+ owner: { AddressOwner: address },
1568
+ coinType: sdk.DEFAULT_COIN_TYPE,
1569
+ amount: "10000000000",
1570
+ })).toEqual([
1571
+ {
1572
+ type: "other",
1573
+ operationType: "UNDELEGATE",
1574
+ address: address,
1575
+ asset: { type: "native" },
1576
+ amount: 10000000000n,
1577
+ },
1578
+ ]);
1579
+ });
1765
1580
  test("toBlockInfo should map checkpoints correctly", () => {
1766
1581
  expect(sdk.toBlockInfo({
1767
1582
  checkpointCommitments: [],