@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
@@ -2,6 +2,7 @@ import * as sdk from "./sdk";
2
2
  import coinConfig from "../config";
3
3
  import { BigNumber } from "bignumber.js";
4
4
  import { SuiClient } from "@mysten/sui/client";
5
+ import assert from "assert";
5
6
  // Mock SUI client for tests
6
7
  jest.mock("@mysten/sui/client", () => {
7
8
  return {
@@ -180,6 +181,87 @@ const mockTransaction = {
180
181
  timestampMs: "1742294454878",
181
182
  checkpoint: "313024",
182
183
  };
184
+ // Create a mock staking transaction
185
+ // amount must be a negative number
186
+ function mockStakingTx(address, amount) {
187
+ assert(new BigNumber(amount).lte(0), "amount must be a negative number");
188
+ return {
189
+ digest: "delegate_tx_digest_123",
190
+ transaction: {
191
+ data: {
192
+ sender: address,
193
+ transaction: {
194
+ kind: "ProgrammableTransaction",
195
+ inputs: [],
196
+ transactions: [
197
+ {
198
+ MoveCall: {
199
+ function: "request_add_stake",
200
+ },
201
+ },
202
+ ],
203
+ },
204
+ },
205
+ },
206
+ effects: {
207
+ status: { status: "success" },
208
+ gasUsed: {
209
+ computationCost: "1000000",
210
+ storageCost: "500000",
211
+ storageRebate: "450000",
212
+ },
213
+ },
214
+ balanceChanges: [
215
+ {
216
+ owner: { AddressOwner: address },
217
+ coinType: "0x2::sui::SUI",
218
+ amount: amount.startsWith("-") ? amount : `-${amount}`,
219
+ },
220
+ ],
221
+ timestampMs: "1742294454878",
222
+ checkpoint: "313024",
223
+ };
224
+ }
225
+ // amount must be a positive number
226
+ function mockUnstakingTx(address, amount) {
227
+ assert(new BigNumber(amount).gte(0), "amount must be a positive number");
228
+ return {
229
+ digest: "undelegate_tx_digest_456",
230
+ transaction: {
231
+ data: {
232
+ sender: address,
233
+ transaction: {
234
+ kind: "ProgrammableTransaction",
235
+ inputs: [],
236
+ transactions: [
237
+ {
238
+ MoveCall: {
239
+ function: "request_withdraw_stake",
240
+ },
241
+ },
242
+ ],
243
+ },
244
+ },
245
+ },
246
+ effects: {
247
+ status: { status: "success" },
248
+ gasUsed: {
249
+ computationCost: "1000000",
250
+ storageCost: "500000",
251
+ storageRebate: "450000",
252
+ },
253
+ },
254
+ balanceChanges: [
255
+ {
256
+ owner: { AddressOwner: address },
257
+ coinType: "0x2::sui::SUI",
258
+ amount: amount,
259
+ },
260
+ ],
261
+ timestampMs: "1742294454878",
262
+ checkpoint: "313024",
263
+ };
264
+ }
183
265
  const mockApi = new SuiClient({ url: "mock" });
184
266
  // Add getTransactionBlock method to mockApi
185
267
  mockApi.getTransactionBlock = jest.fn();
@@ -250,14 +332,6 @@ describe("SDK Functions", () => {
250
332
  test("getOperationRecipients should return recipient addresses", () => {
251
333
  expect(sdk.getOperationRecipients(mockTransaction.transaction?.data)).toEqual(["0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0"]);
252
334
  });
253
- test("getOperationAmount should calculate amount correctly for SUI", () => {
254
- const address = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
255
- expect(sdk.getOperationAmount(address, mockTransaction, sdk.DEFAULT_COIN_TYPE)).toEqual(new BigNumber("9998990120"));
256
- });
257
- test("getOperationAmount should calculate amount correctly for tokens", () => {
258
- const address = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
259
- expect(sdk.getOperationAmount(address, mockTransaction, "0x123::test::TOKEN")).toEqual(new BigNumber("500000"));
260
- });
261
335
  test("getOperationFee should calculate fee correctly", () => {
262
336
  expect(sdk.getOperationFee(mockTransaction)).toEqual(new BigNumber(1009880));
263
337
  });
@@ -402,7 +476,7 @@ describe("SDK Functions", () => {
402
476
  },
403
477
  ],
404
478
  };
405
- const operation = sdk.transactionToOp(address, tokenTx);
479
+ const operation = sdk.alpacaTransactionToOp(address, tokenTx);
406
480
  expect(operation.id).toEqual("DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt");
407
481
  expect(operation.type).toEqual("IN");
408
482
  expect(operation.senders).toEqual([
@@ -473,186 +547,39 @@ describe("Staking Operations", () => {
473
547
  describe("Operation Type Detection", () => {
474
548
  test("getOperationType should return DELEGATE for staking transaction", () => {
475
549
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
476
- // Create a mock staking transaction
477
- const mockStakingTx = {
478
- digest: "delegate_tx_digest_123",
479
- transaction: {
480
- data: {
481
- sender: address,
482
- transaction: {
483
- kind: "ProgrammableTransaction",
484
- inputs: [],
485
- transactions: [
486
- {
487
- MoveCall: {
488
- function: "request_add_stake",
489
- },
490
- },
491
- ],
492
- },
493
- },
494
- },
495
- effects: {
496
- status: { status: "success" },
497
- gasUsed: {
498
- computationCost: "1000000",
499
- storageCost: "500000",
500
- storageRebate: "450000",
501
- },
502
- },
503
- balanceChanges: [
504
- {
505
- owner: { AddressOwner: address },
506
- coinType: "0x2::sui::SUI",
507
- amount: "-1000000000",
508
- },
509
- ],
510
- timestampMs: "1742294454878",
511
- checkpoint: "313024",
512
- };
513
- expect(sdk.getOperationType(address, mockStakingTx)).toBe("DELEGATE");
550
+ expect(sdk.getOperationType(address, mockStakingTx(address, "-1000000000"))).toBe("DELEGATE");
514
551
  });
515
552
  test("getOperationType should return UNDELEGATE for unstaking transaction", () => {
516
553
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
517
- // Create a mock unstaking transaction
518
- const mockUnstakingTx = {
519
- digest: "undelegate_tx_digest_456",
520
- transaction: {
521
- data: {
522
- sender: address,
523
- transaction: {
524
- kind: "ProgrammableTransaction",
525
- inputs: [],
526
- transactions: [
527
- {
528
- MoveCall: {
529
- function: "request_withdraw_stake",
530
- },
531
- },
532
- ],
533
- },
534
- },
535
- },
536
- effects: {
537
- status: { status: "success" },
538
- gasUsed: {
539
- computationCost: "1000000",
540
- storageCost: "500000",
541
- storageRebate: "450000",
542
- },
543
- },
544
- balanceChanges: [
545
- {
546
- owner: { AddressOwner: address },
547
- coinType: "0x2::sui::SUI",
548
- amount: "0",
549
- },
550
- ],
551
- timestampMs: "1742294454878",
552
- checkpoint: "313024",
553
- };
554
- expect(sdk.getOperationType(address, mockUnstakingTx)).toBe("UNDELEGATE");
554
+ expect(sdk.getOperationType(address, mockUnstakingTx(address, "1000000000"))).toBe("UNDELEGATE");
555
555
  });
556
556
  });
557
557
  describe("Operation Amount Calculation", () => {
558
- test("getOperationAmount should calculate staking amount correctly", () => {
559
- const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
560
- const mockStakingTx = {
561
- transaction: {
562
- data: {
563
- transaction: {
564
- kind: "ProgrammableTransaction",
565
- transactions: [
566
- {
567
- MoveCall: {
568
- function: "request_add_stake",
569
- },
570
- },
571
- ],
572
- },
573
- },
574
- },
575
- balanceChanges: [
576
- {
577
- owner: { AddressOwner: address },
578
- coinType: "0x2::sui::SUI",
579
- amount: "-1000000000",
580
- },
581
- ],
582
- };
583
- const amount = sdk.getOperationAmount(address, mockStakingTx, sdk.DEFAULT_COIN_TYPE);
584
- expect(amount).toEqual(new BigNumber("1000000000")); // The function returns minus of the balance change
585
- });
586
- test("getOperationAmount should calculate unstaking amount correctly", () => {
587
- const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
588
- const mockUnstakingTx = {
589
- transaction: {
590
- data: {
591
- transaction: {
592
- kind: "ProgrammableTransaction",
593
- transactions: [
594
- {
595
- MoveCall: {
596
- function: "request_withdraw_stake",
597
- },
598
- },
599
- ],
600
- },
601
- },
602
- },
603
- balanceChanges: [
604
- {
605
- owner: { AddressOwner: address },
606
- coinType: "0x2::sui::SUI",
607
- amount: "0",
608
- },
609
- ],
610
- };
611
- const amount = sdk.getOperationAmount(address, mockUnstakingTx, sdk.DEFAULT_COIN_TYPE);
612
- expect(amount).toEqual(new BigNumber("0"));
613
- });
558
+ const address = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
559
+ function bridgeOperationAmount(mock, coinType = sdk.DEFAULT_COIN_TYPE) {
560
+ return sdk.getOperationAmount(address, mock, coinType);
561
+ }
562
+ test("getOperationAmount should calculate staking amount", () => expect(bridgeOperationAmount(mockStakingTx(address, "-1000000000"))).toEqual(new BigNumber("1000000000")));
563
+ test("getOperationAmount should calculate unstaking amount of 1000", () => expect(bridgeOperationAmount(mockUnstakingTx(address, "1000"))).toEqual(new BigNumber("-1000")));
564
+ test("getOperationAmount should calculate unstaking amount of 0", () => expect(bridgeOperationAmount(mockUnstakingTx(address, "0"))).toEqual(new BigNumber("0")));
565
+ test("getOperationAmount should calculate amount correctly for SUI", () => expect(bridgeOperationAmount(mockTransaction)).toEqual(new BigNumber("9998990120")));
566
+ test("getOperationAmount should calculate amount correctly for tokens", () => expect(bridgeOperationAmount(mockTransaction, "0x123::test::TOKEN")).toEqual(new BigNumber("500000")));
567
+ function alpacaOperationAmount(mock, coinType = sdk.DEFAULT_COIN_TYPE) {
568
+ return sdk.alpacaGetOperationAmount(address, mock, coinType);
569
+ }
570
+ test("alpaca getOperationAmount should calculate staking amount", () => expect(alpacaOperationAmount(mockStakingTx(address, "-1000000000"))).toEqual(new BigNumber("1000000000")));
571
+ test("alpaca getOperationAmount should calculate unstaking amount of 1000", () => expect(alpacaOperationAmount(mockUnstakingTx(address, "1000"))).toEqual(new BigNumber("1000")));
572
+ test("alpaca getOperationAmount should calculate unstaking amount of 0", () => expect(alpacaOperationAmount(mockUnstakingTx(address, "0"))).toEqual(new BigNumber("0")));
573
+ test("alpaca getOperationAmount should calculate amount correctly for SUI", () => expect(alpacaOperationAmount(mockTransaction)).toEqual(new BigNumber("9998990120")));
574
+ test("alpaca getOperationAmount should calculate amount correctly for tokens", () => expect(alpacaOperationAmount(mockTransaction, "0x123::test::TOKEN")).toEqual(new BigNumber("500000")));
614
575
  });
615
576
  describe("Operation Recipients", () => {
616
577
  test("getOperationRecipients should return empty array for staking transaction", () => {
617
- const mockStakingTx = {
618
- transaction: {
619
- data: {
620
- transaction: {
621
- kind: "ProgrammableTransaction",
622
- inputs: [],
623
- transactions: [
624
- {
625
- MoveCall: {
626
- function: "request_add_stake",
627
- },
628
- },
629
- ],
630
- },
631
- },
632
- },
633
- };
634
- const recipients = sdk.getOperationRecipients(mockStakingTx.transaction?.data);
578
+ const recipients = sdk.getOperationRecipients(mockStakingTx("0xdeadbeef", "-1000000000").transaction?.data);
635
579
  expect(recipients).toEqual([]);
636
580
  });
637
581
  test("getOperationRecipients should return empty array for unstaking transaction", () => {
638
- const mockUnstakingTx = {
639
- transaction: {
640
- data: {
641
- transaction: {
642
- kind: "ProgrammableTransaction",
643
- inputs: [],
644
- transactions: [
645
- {
646
- MoveCall: {
647
- function: "request_withdraw_stake",
648
- },
649
- },
650
- ],
651
- },
652
- },
653
- },
654
- };
655
- const recipients = sdk.getOperationRecipients(mockUnstakingTx.transaction?.data);
582
+ const recipients = sdk.getOperationRecipients(mockUnstakingTx("0xdeadbeef", "1000000000").transaction?.data);
656
583
  expect(recipients).toEqual([]);
657
584
  });
658
585
  });
@@ -733,43 +660,7 @@ describe("Staking Operations", () => {
733
660
  test("transactionToOperation should map staking transaction correctly", () => {
734
661
  const accountId = "mockAccountId";
735
662
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
736
- const mockStakingTx = {
737
- digest: "delegate_tx_digest_123",
738
- transaction: {
739
- data: {
740
- sender: address,
741
- transaction: {
742
- kind: "ProgrammableTransaction",
743
- inputs: [],
744
- transactions: [
745
- {
746
- MoveCall: {
747
- function: "request_add_stake",
748
- },
749
- },
750
- ],
751
- },
752
- },
753
- },
754
- effects: {
755
- status: { status: "success" },
756
- gasUsed: {
757
- computationCost: "1000000",
758
- storageCost: "500000",
759
- storageRebate: "450000",
760
- },
761
- },
762
- balanceChanges: [
763
- {
764
- owner: { AddressOwner: address },
765
- coinType: "0x2::sui::SUI",
766
- amount: "-1000000000",
767
- },
768
- ],
769
- timestampMs: "1742294454878",
770
- checkpoint: "313024",
771
- };
772
- const operation = sdk.transactionToOperation(accountId, address, mockStakingTx);
663
+ const operation = sdk.transactionToOperation(accountId, address, mockStakingTx(address, "-1000000000"));
773
664
  expect(operation).toHaveProperty("id");
774
665
  expect(operation).toHaveProperty("accountId", accountId);
775
666
  expect(operation).toHaveProperty("type", "DELEGATE");
@@ -783,92 +674,20 @@ describe("Staking Operations", () => {
783
674
  test("transactionToOperation should map unstaking transaction correctly", () => {
784
675
  const accountId = "mockAccountId";
785
676
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
786
- const mockUnstakingTx = {
787
- digest: "undelegate_tx_digest_456",
788
- transaction: {
789
- data: {
790
- sender: address,
791
- transaction: {
792
- kind: "ProgrammableTransaction",
793
- inputs: [],
794
- transactions: [
795
- {
796
- MoveCall: {
797
- function: "request_withdraw_stake",
798
- },
799
- },
800
- ],
801
- },
802
- },
803
- },
804
- effects: {
805
- status: { status: "success" },
806
- gasUsed: {
807
- computationCost: "1000000",
808
- storageCost: "500000",
809
- storageRebate: "450000",
810
- },
811
- },
812
- balanceChanges: [
813
- {
814
- owner: { AddressOwner: address },
815
- coinType: "0x2::sui::SUI",
816
- amount: "0",
817
- },
818
- ],
819
- timestampMs: "1742294454878",
820
- checkpoint: "313024",
821
- };
822
- const operation = sdk.transactionToOperation(accountId, address, mockUnstakingTx);
677
+ const operation = sdk.transactionToOperation(accountId, address, mockUnstakingTx(address, "1000000000"));
823
678
  expect(operation).toHaveProperty("id");
824
679
  expect(operation).toHaveProperty("accountId", accountId);
825
680
  expect(operation).toHaveProperty("type", "UNDELEGATE");
826
681
  expect(operation).toHaveProperty("hash", "undelegate_tx_digest_456");
827
682
  expect(operation).toHaveProperty("extra");
828
683
  expect(operation.extra.coinType).toBe(sdk.DEFAULT_COIN_TYPE);
829
- expect(operation.value).toEqual(new BigNumber("0"));
684
+ expect(operation.value).toEqual(new BigNumber("-1000000000"));
830
685
  expect(operation.recipients).toEqual([]);
831
686
  expect(operation.senders).toEqual([address]);
832
687
  });
833
688
  test("transactionToOp should map staking transaction correctly", () => {
834
689
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
835
- const mockStakingTx = {
836
- digest: "delegate_tx_digest_123",
837
- transaction: {
838
- data: {
839
- sender: address,
840
- transaction: {
841
- kind: "ProgrammableTransaction",
842
- inputs: [],
843
- transactions: [
844
- {
845
- MoveCall: {
846
- function: "request_add_stake",
847
- },
848
- },
849
- ],
850
- },
851
- },
852
- },
853
- effects: {
854
- status: { status: "success" },
855
- gasUsed: {
856
- computationCost: "1000000",
857
- storageCost: "500000",
858
- storageRebate: "450000",
859
- },
860
- },
861
- balanceChanges: [
862
- {
863
- owner: { AddressOwner: address },
864
- coinType: "0x2::sui::SUI",
865
- amount: "-1000000000",
866
- },
867
- ],
868
- timestampMs: "1742294454878",
869
- checkpoint: "313024",
870
- };
871
- const operation = sdk.transactionToOp(address, mockStakingTx);
690
+ const operation = sdk.alpacaTransactionToOp(address, mockStakingTx(address, "-1000000000"));
872
691
  expect(operation.id).toEqual("delegate_tx_digest_123");
873
692
  expect(operation.type).toEqual("DELEGATE");
874
693
  expect(operation.senders).toEqual([address]);
@@ -879,48 +698,12 @@ describe("Staking Operations", () => {
879
698
  });
880
699
  test("transactionToOp should map unstaking transaction correctly", () => {
881
700
  const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
882
- const mockUnstakingTx = {
883
- digest: "undelegate_tx_digest_456",
884
- transaction: {
885
- data: {
886
- sender: address,
887
- transaction: {
888
- kind: "ProgrammableTransaction",
889
- inputs: [],
890
- transactions: [
891
- {
892
- MoveCall: {
893
- function: "request_withdraw_stake",
894
- },
895
- },
896
- ],
897
- },
898
- },
899
- },
900
- effects: {
901
- status: { status: "success" },
902
- gasUsed: {
903
- computationCost: "1000000",
904
- storageCost: "500000",
905
- storageRebate: "450000",
906
- },
907
- },
908
- balanceChanges: [
909
- {
910
- owner: { AddressOwner: address },
911
- coinType: "0x2::sui::SUI",
912
- amount: "0",
913
- },
914
- ],
915
- timestampMs: "1742294454878",
916
- checkpoint: "313024",
917
- };
918
- const operation = sdk.transactionToOp(address, mockUnstakingTx);
701
+ const operation = sdk.alpacaTransactionToOp(address, mockUnstakingTx(address, "1000000000"));
919
702
  expect(operation.id).toEqual("undelegate_tx_digest_456");
920
703
  expect(operation.type).toEqual("UNDELEGATE");
921
704
  expect(operation.senders).toEqual([address]);
922
705
  expect(operation.recipients).toEqual([]);
923
- expect(operation.value).toEqual(0n);
706
+ expect(operation.value).toEqual(1000000000n);
924
707
  expect(operation.asset).toEqual({ type: "native" });
925
708
  expect(operation.tx.block.hash).toBeUndefined();
926
709
  });
@@ -1661,7 +1444,7 @@ describe("filterOperations", () => {
1661
1444
  });
1662
1445
  describe("conversion methods", () => {
1663
1446
  test("toBlockOperation should map native transfers correctly", () => {
1664
- expect(sdk.toBlockOperation({
1447
+ expect(sdk.toBlockOperation(mockTransaction, {
1665
1448
  owner: {
1666
1449
  AddressOwner: "0x65449f57946938c84c5127",
1667
1450
  },
@@ -1677,7 +1460,7 @@ describe("filterOperations", () => {
1677
1460
  ]);
1678
1461
  });
1679
1462
  test("toBlockOperation should ignore transfers from shared owner", () => {
1680
- expect(sdk.toBlockOperation({
1463
+ expect(sdk.toBlockOperation(mockTransaction, {
1681
1464
  owner: {
1682
1465
  Shared: {
1683
1466
  initial_shared_version: "0",
@@ -1688,7 +1471,7 @@ describe("filterOperations", () => {
1688
1471
  })).toEqual([]);
1689
1472
  });
1690
1473
  test("toBlockOperation should ignore transfers from object owner", () => {
1691
- expect(sdk.toBlockOperation({
1474
+ expect(sdk.toBlockOperation(mockTransaction, {
1692
1475
  owner: {
1693
1476
  ObjectOwner: "test",
1694
1477
  },
@@ -1697,14 +1480,14 @@ describe("filterOperations", () => {
1697
1480
  })).toEqual([]);
1698
1481
  });
1699
1482
  test("toBlockOperation should ignore transfers from immutable owner", () => {
1700
- expect(sdk.toBlockOperation({
1483
+ expect(sdk.toBlockOperation(mockTransaction, {
1701
1484
  owner: "Immutable",
1702
1485
  coinType: sdk.DEFAULT_COIN_TYPE,
1703
1486
  amount: "-10000000000",
1704
1487
  })).toEqual([]);
1705
1488
  });
1706
1489
  test("toBlockOperation should ignore transfers from consensus owner", () => {
1707
- expect(sdk.toBlockOperation({
1490
+ expect(sdk.toBlockOperation(mockTransaction, {
1708
1491
  owner: {
1709
1492
  ConsensusAddressOwner: {
1710
1493
  owner: "test",
@@ -1716,7 +1499,7 @@ describe("filterOperations", () => {
1716
1499
  })).toEqual([]);
1717
1500
  });
1718
1501
  test("toBlockOperation should map token transfers correctly", () => {
1719
- expect(sdk.toBlockOperation({
1502
+ expect(sdk.toBlockOperation(mockTransaction, {
1720
1503
  owner: {
1721
1504
  AddressOwner: "0x65449f57946938c84c5127",
1722
1505
  },
@@ -1734,6 +1517,38 @@ describe("filterOperations", () => {
1734
1517
  },
1735
1518
  ]);
1736
1519
  });
1520
+ test("toBlockOperation should map staking operations correctly", () => {
1521
+ const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
1522
+ expect(sdk.toBlockOperation(mockStakingTx(address, "-1000000000"), {
1523
+ owner: { AddressOwner: address },
1524
+ coinType: sdk.DEFAULT_COIN_TYPE,
1525
+ amount: "-10000000000",
1526
+ })).toEqual([
1527
+ {
1528
+ type: "other",
1529
+ operationType: "DELEGATE",
1530
+ address: address,
1531
+ asset: { type: "native" },
1532
+ amount: 10000000000n,
1533
+ },
1534
+ ]);
1535
+ });
1536
+ test("toBlockOperation should map unstaking operations correctly", () => {
1537
+ const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
1538
+ expect(sdk.toBlockOperation(mockUnstakingTx(address, "1000000000"), {
1539
+ owner: { AddressOwner: address },
1540
+ coinType: sdk.DEFAULT_COIN_TYPE,
1541
+ amount: "10000000000",
1542
+ })).toEqual([
1543
+ {
1544
+ type: "other",
1545
+ operationType: "UNDELEGATE",
1546
+ address: address,
1547
+ asset: { type: "native" },
1548
+ amount: 10000000000n,
1549
+ },
1550
+ ]);
1551
+ });
1737
1552
  test("toBlockInfo should map checkpoints correctly", () => {
1738
1553
  expect(sdk.toBlockInfo({
1739
1554
  checkpointCommitments: [],