@ledgerhq/coin-sui 0.7.1-nightly.0 → 0.8.0-nightly.2

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 (86) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +2 -1
  3. package/CHANGELOG.md +24 -0
  4. package/lib/api/index.d.ts +2 -3
  5. package/lib/api/index.d.ts.map +1 -1
  6. package/lib/api/index.js.map +1 -1
  7. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  8. package/lib/bridge/buildTransaction.js +11 -2
  9. package/lib/bridge/buildTransaction.js.map +1 -1
  10. package/lib/bridge/buildTransaction.test.js +0 -2
  11. package/lib/bridge/buildTransaction.test.js.map +1 -1
  12. package/lib/logic/craftTransaction.d.ts +1 -4
  13. package/lib/logic/craftTransaction.d.ts.map +1 -1
  14. package/lib/logic/craftTransaction.js +6 -2
  15. package/lib/logic/craftTransaction.js.map +1 -1
  16. package/lib/logic/estimateFees.d.ts +1 -2
  17. package/lib/logic/estimateFees.d.ts.map +1 -1
  18. package/lib/logic/estimateFees.js.map +1 -1
  19. package/lib/logic/getBalance.d.ts +1 -2
  20. package/lib/logic/getBalance.d.ts.map +1 -1
  21. package/lib/logic/getBalance.js.map +1 -1
  22. package/lib/logic/getBlock.d.ts +1 -2
  23. package/lib/logic/getBlock.d.ts.map +1 -1
  24. package/lib/logic/getBlock.js.map +1 -1
  25. package/lib/logic/listOperations.d.ts +1 -2
  26. package/lib/logic/listOperations.d.ts.map +1 -1
  27. package/lib/logic/listOperations.js.map +1 -1
  28. package/lib/logic/listOperations.test.js.map +1 -1
  29. package/lib/network/sdk.d.ts +7 -7
  30. package/lib/network/sdk.d.ts.map +1 -1
  31. package/lib/network/sdk.js +4 -3
  32. package/lib/network/sdk.js.map +1 -1
  33. package/lib/network/sdk.test.js +52 -3
  34. package/lib/network/sdk.test.js.map +1 -1
  35. package/lib-es/api/index.d.ts +2 -3
  36. package/lib-es/api/index.d.ts.map +1 -1
  37. package/lib-es/api/index.js.map +1 -1
  38. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  39. package/lib-es/bridge/buildTransaction.js +11 -2
  40. package/lib-es/bridge/buildTransaction.js.map +1 -1
  41. package/lib-es/bridge/buildTransaction.test.js +0 -2
  42. package/lib-es/bridge/buildTransaction.test.js.map +1 -1
  43. package/lib-es/logic/craftTransaction.d.ts +1 -4
  44. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  45. package/lib-es/logic/craftTransaction.js +6 -2
  46. package/lib-es/logic/craftTransaction.js.map +1 -1
  47. package/lib-es/logic/estimateFees.d.ts +1 -2
  48. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  49. package/lib-es/logic/estimateFees.js.map +1 -1
  50. package/lib-es/logic/getBalance.d.ts +1 -2
  51. package/lib-es/logic/getBalance.d.ts.map +1 -1
  52. package/lib-es/logic/getBalance.js.map +1 -1
  53. package/lib-es/logic/getBlock.d.ts +1 -2
  54. package/lib-es/logic/getBlock.d.ts.map +1 -1
  55. package/lib-es/logic/getBlock.js.map +1 -1
  56. package/lib-es/logic/listOperations.d.ts +1 -2
  57. package/lib-es/logic/listOperations.d.ts.map +1 -1
  58. package/lib-es/logic/listOperations.js.map +1 -1
  59. package/lib-es/logic/listOperations.test.js.map +1 -1
  60. package/lib-es/network/sdk.d.ts +7 -7
  61. package/lib-es/network/sdk.d.ts.map +1 -1
  62. package/lib-es/network/sdk.js +3 -3
  63. package/lib-es/network/sdk.js.map +1 -1
  64. package/lib-es/network/sdk.test.js +52 -3
  65. package/lib-es/network/sdk.test.js.map +1 -1
  66. package/package.json +6 -8
  67. package/src/api/index.ts +5 -9
  68. package/src/bridge/buildTransaction.test.ts +0 -2
  69. package/src/bridge/buildTransaction.ts +12 -2
  70. package/src/logic/craftTransaction.ts +7 -4
  71. package/src/logic/estimateFees.ts +1 -2
  72. package/src/logic/getBalance.ts +1 -2
  73. package/src/logic/getBlock.ts +1 -2
  74. package/src/logic/listOperations.test.ts +1 -2
  75. package/src/logic/listOperations.ts +1 -2
  76. package/src/network/sdk.test.ts +55 -3
  77. package/src/network/sdk.ts +9 -11
  78. package/lib/api/types.d.ts +0 -6
  79. package/lib/api/types.d.ts.map +0 -1
  80. package/lib/api/types.js +0 -3
  81. package/lib/api/types.js.map +0 -1
  82. package/lib-es/api/types.d.ts +0 -6
  83. package/lib-es/api/types.d.ts.map +0 -1
  84. package/lib-es/api/types.js +0 -2
  85. package/lib-es/api/types.js.map +0 -1
  86. package/src/api/types.ts +0 -7
@@ -459,6 +459,58 @@ describe("SDK Functions", () => {
459
459
  expect(operation.value).toEqual(new BigNumber("500000"));
460
460
  });
461
461
 
462
+ test("transactionToOp should map token transaction to operation", () => {
463
+ const address = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
464
+
465
+ // Create a token transaction
466
+ const tokenTx = {
467
+ ...mockTransaction,
468
+ balanceChanges: [
469
+ {
470
+ owner: {
471
+ AddressOwner: "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24",
472
+ },
473
+ coinType: "0x123::test::TOKEN",
474
+ amount: "-500000",
475
+ },
476
+ {
477
+ owner: {
478
+ AddressOwner: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
479
+ },
480
+ coinType: "0x123::test::TOKEN",
481
+ amount: "500000",
482
+ },
483
+ {
484
+ owner: {
485
+ AddressOwner: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
486
+ },
487
+ coinType: sdk.DEFAULT_COIN_TYPE,
488
+ amount: "-1000000",
489
+ },
490
+ ],
491
+ };
492
+
493
+ const operation = sdk.transactionToOp(address, tokenTx as SuiTransactionBlockResponse);
494
+ expect(operation.id).toEqual("DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt");
495
+ expect(operation.type).toEqual("IN");
496
+ expect(operation.senders).toEqual([
497
+ "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24",
498
+ ]);
499
+ expect(operation.recipients).toEqual([
500
+ "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
501
+ ]);
502
+ expect(operation.value).toEqual(500000n);
503
+ expect(operation.asset).toEqual({ type: "token", assetReference: "0x123::test::TOKEN" });
504
+ expect(operation.memo).toBeUndefined();
505
+ expect(operation.details).toBeUndefined();
506
+ expect(operation.tx).toMatchObject({
507
+ hash: "DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt",
508
+ block: {},
509
+ fees: 1009880n,
510
+ date: new Date("2025-03-18T10:40:54.878Z"),
511
+ });
512
+ });
513
+
462
514
  test("getOperations should fetch operations", async () => {
463
515
  const accountId = "mockAccountId";
464
516
  const addr = "0x33444cf803c690db96527cec67e3c9ab512596f4ba2d4eace43f0b4f716e0164";
@@ -1397,7 +1449,7 @@ describe("filterOperations", () => {
1397
1449
  amount: 8824n,
1398
1450
  asset: {
1399
1451
  type: "token",
1400
- coinType: "0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC",
1452
+ assetReference: "0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC",
1401
1453
  },
1402
1454
  },
1403
1455
  ]);
@@ -1460,7 +1512,7 @@ describe("filterOperations", () => {
1460
1512
  {
1461
1513
  address: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
1462
1514
  amount: 500000n,
1463
- asset: { type: "token", coinType: "0x123::test::TOKEN" },
1515
+ asset: { type: "token", assetReference: "0x123::test::TOKEN" },
1464
1516
  type: "transfer",
1465
1517
  },
1466
1518
  ],
@@ -1474,7 +1526,7 @@ describe("filterOperations", () => {
1474
1526
  test("suiCoinTypeToAsset should map tokens correctly", () => {
1475
1527
  expect(sdk.toSuiAsset("0x123::test::TOKEN")).toEqual({
1476
1528
  type: "token",
1477
- coinType: "0x123::test::TOKEN",
1529
+ assetReference: "0x123::test::TOKEN",
1478
1530
  });
1479
1531
  });
1480
1532
  });
@@ -20,6 +20,7 @@ import type {
20
20
  BlockTransaction,
21
21
  BlockOperation,
22
22
  Operation as Op,
23
+ AssetInfo,
23
24
  } from "@ledgerhq/coin-framework/api/index";
24
25
  import type { Operation, OperationType } from "@ledgerhq/types-live";
25
26
  import uniqBy from "lodash/unionBy";
@@ -30,7 +31,6 @@ import type { Transaction as TransactionType } from "../types";
30
31
  import type { CreateExtrinsicArg } from "../logic/craftTransaction";
31
32
  import { ensureAddressFormat } from "../utils";
32
33
  import coinConfig from "../config";
33
- import { SuiAsset } from "../api/types";
34
34
  import { getEnv } from "@ledgerhq/live-env";
35
35
 
36
36
  type AsyncApiFunction<T> = (api: SuiClient) => Promise<T>;
@@ -253,7 +253,7 @@ export function transactionToOperation(
253
253
  };
254
254
  }
255
255
 
256
- function transactionToOp(address: string, transaction: SuiTransactionBlockResponse): Op<SuiAsset> {
256
+ export function transactionToOp(address: string, transaction: SuiTransactionBlockResponse): Op {
257
257
  const type = getOperationType(address, transaction.transaction?.data);
258
258
  const coinType = getOperationCoinType(transaction);
259
259
  const hash = transaction.digest;
@@ -270,7 +270,7 @@ function transactionToOp(address: string, transaction: SuiTransactionBlockRespon
270
270
  time: getOperationDate(transaction),
271
271
  },
272
272
  },
273
- asset: { type: "native" },
273
+ asset: toSuiAsset(coinType),
274
274
  recipients: getOperationRecipients(transaction.transaction?.data),
275
275
  senders: getOperationSenders(transaction.transaction?.data),
276
276
  type,
@@ -312,9 +312,7 @@ export function toBlockInfo(checkpoint: Checkpoint): BlockInfo {
312
312
  *
313
313
  * @param transaction SUI RPC transaction block response
314
314
  */
315
- export function toBlockTransaction(
316
- transaction: SuiTransactionBlockResponse,
317
- ): BlockTransaction<SuiAsset> {
315
+ export function toBlockTransaction(transaction: SuiTransactionBlockResponse): BlockTransaction {
318
316
  return {
319
317
  hash: transaction.digest,
320
318
  failed: transaction.effects?.status.status != "success",
@@ -329,7 +327,7 @@ export function toBlockTransaction(
329
327
  *
330
328
  * @param change balance change
331
329
  */
332
- export function toBlockOperation(change: BalanceChange): BlockOperation<SuiAsset>[] {
330
+ export function toBlockOperation(change: BalanceChange): BlockOperation[] {
333
331
  if (typeof change.owner == "string" || !("AddressOwner" in change.owner)) return [];
334
332
  return [
335
333
  {
@@ -346,12 +344,12 @@ export function toBlockOperation(change: BalanceChange): BlockOperation<SuiAsset
346
344
  *
347
345
  * @param coinType coin type, as returned from SUI RPC
348
346
  */
349
- export function toSuiAsset(coinType: string): SuiAsset {
347
+ export function toSuiAsset(coinType: string): AssetInfo {
350
348
  switch (coinType) {
351
349
  case DEFAULT_COIN_TYPE:
352
350
  return { type: "native" };
353
351
  default:
354
- return { type: "token", coinType };
352
+ return { type: "token", assetReference: coinType };
355
353
  }
356
354
  }
357
355
 
@@ -426,7 +424,7 @@ export const getListOperations = async (
426
424
  addr: string,
427
425
  cursor: QueryTransactionBlocksParams["cursor"] = null,
428
426
  withApiImpl: typeof withApi = withApi,
429
- ): Promise<Op<SuiAsset>[]> =>
427
+ ): Promise<Op[]> =>
430
428
  withApiImpl(async api => {
431
429
  const opsOut = await loadOperations({
432
430
  api,
@@ -475,7 +473,7 @@ export const getBlockInfo = async (id: string): Promise<BlockInfo> =>
475
473
  * @param id the checkpoint digest or sequence number (as a string)
476
474
  * @see {@link getBlockInfo}
477
475
  */
478
- export const getBlock = async (id: string): Promise<Block<SuiAsset>> =>
476
+ export const getBlock = async (id: string): Promise<Block> =>
479
477
  withApi(async api => {
480
478
  const checkpoint = await api.getCheckpoint({ id });
481
479
  const rawTxs = await queryTransactionsByDigest({ api, digests: checkpoint.transactions });
@@ -1,6 +0,0 @@
1
- import { type Asset } from "@ledgerhq/coin-framework/api/types";
2
- export type SuiAsset = Asset<SuiTokenInformation>;
3
- export type SuiTokenInformation = {
4
- coinType: string;
5
- };
6
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEhE,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,mBAAmB,CAAC,CAAC;AAElD,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
package/lib/api/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- import { type Asset } from "@ledgerhq/coin-framework/api/types";
2
- export type SuiAsset = Asset<SuiTokenInformation>;
3
- export type SuiTokenInformation = {
4
- coinType: string;
5
- };
6
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEhE,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,mBAAmB,CAAC,CAAC;AAElD,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":""}
package/src/api/types.ts DELETED
@@ -1,7 +0,0 @@
1
- import { type Asset } from "@ledgerhq/coin-framework/api/types";
2
-
3
- export type SuiAsset = Asset<SuiTokenInformation>;
4
-
5
- export type SuiTokenInformation = {
6
- coinType: string;
7
- };