@ledgerhq/coin-ton 0.7.0-nightly.3 → 0.7.0

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 (127) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +17 -26
  3. package/jest.config.js +0 -1
  4. package/lib/__tests__/fixtures/common.fixtures.d.ts +4 -3
  5. package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
  6. package/lib/__tests__/fixtures/common.fixtures.js +1 -9
  7. package/lib/__tests__/fixtures/common.fixtures.js.map +1 -1
  8. package/lib/__tests__/integration/bridge.integration.test.d.ts.map +1 -1
  9. package/lib/__tests__/integration/bridge.integration.test.js +2 -2
  10. package/lib/__tests__/integration/bridge.integration.test.js.map +1 -1
  11. package/lib/__tests__/unit/api.unit.test.js +0 -1
  12. package/lib/__tests__/unit/api.unit.test.js.map +1 -1
  13. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +3 -12
  14. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
  15. package/lib/__tests__/unit/prepareTransaction.unit.test.js +0 -38
  16. package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
  17. package/lib/__tests__/unit/utils.unit.test.js +1 -43
  18. package/lib/__tests__/unit/utils.unit.test.js.map +1 -1
  19. package/lib/bridge/js.d.ts +3 -3
  20. package/lib/bridge/js.d.ts.map +1 -1
  21. package/lib/config.d.ts +0 -2
  22. package/lib/config.d.ts.map +1 -1
  23. package/lib/config.js.map +1 -1
  24. package/lib/constants.d.ts +0 -18
  25. package/lib/constants.d.ts.map +1 -1
  26. package/lib/constants.js +1 -20
  27. package/lib/constants.js.map +1 -1
  28. package/lib/deviceTransactionConfig.d.ts.map +1 -1
  29. package/lib/deviceTransactionConfig.js +3 -14
  30. package/lib/deviceTransactionConfig.js.map +1 -1
  31. package/lib/estimateMaxSpendable.d.ts +3 -3
  32. package/lib/estimateMaxSpendable.d.ts.map +1 -1
  33. package/lib/estimateMaxSpendable.js +5 -6
  34. package/lib/estimateMaxSpendable.js.map +1 -1
  35. package/lib/getTransactionStatus.d.ts +3 -3
  36. package/lib/getTransactionStatus.d.ts.map +1 -1
  37. package/lib/getTransactionStatus.js +2 -2
  38. package/lib/getTransactionStatus.js.map +1 -1
  39. package/lib/prepareTransaction.d.ts +3 -3
  40. package/lib/prepareTransaction.d.ts.map +1 -1
  41. package/lib/prepareTransaction.js +2 -1
  42. package/lib/prepareTransaction.js.map +1 -1
  43. package/lib/signOperation.d.ts +4 -4
  44. package/lib/signOperation.d.ts.map +1 -1
  45. package/lib/signOperation.js.map +1 -1
  46. package/lib/synchronisation.d.ts +3 -3
  47. package/lib/synchronisation.d.ts.map +1 -1
  48. package/lib/synchronisation.js +3 -4
  49. package/lib/synchronisation.js.map +1 -1
  50. package/lib/types.d.ts +2 -79
  51. package/lib/types.d.ts.map +1 -1
  52. package/lib/utils.d.ts +4 -8
  53. package/lib/utils.d.ts.map +1 -1
  54. package/lib/utils.js +5 -30
  55. package/lib/utils.js.map +1 -1
  56. package/lib-es/__tests__/fixtures/common.fixtures.d.ts +4 -3
  57. package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
  58. package/lib-es/__tests__/fixtures/common.fixtures.js +1 -9
  59. package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -1
  60. package/lib-es/__tests__/integration/bridge.integration.test.d.ts.map +1 -1
  61. package/lib-es/__tests__/integration/bridge.integration.test.js +1 -1
  62. package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -1
  63. package/lib-es/__tests__/unit/api.unit.test.js +0 -1
  64. package/lib-es/__tests__/unit/api.unit.test.js.map +1 -1
  65. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +3 -12
  66. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
  67. package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +0 -15
  68. package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
  69. package/lib-es/__tests__/unit/utils.unit.test.js +1 -20
  70. package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -1
  71. package/lib-es/bridge/js.d.ts +3 -3
  72. package/lib-es/bridge/js.d.ts.map +1 -1
  73. package/lib-es/bridge/js.js +1 -1
  74. package/lib-es/bridge/js.js.map +1 -1
  75. package/lib-es/config.d.ts +0 -2
  76. package/lib-es/config.d.ts.map +1 -1
  77. package/lib-es/config.js.map +1 -1
  78. package/lib-es/constants.d.ts +0 -18
  79. package/lib-es/constants.d.ts.map +1 -1
  80. package/lib-es/constants.js +0 -19
  81. package/lib-es/constants.js.map +1 -1
  82. package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
  83. package/lib-es/deviceTransactionConfig.js +4 -15
  84. package/lib-es/deviceTransactionConfig.js.map +1 -1
  85. package/lib-es/estimateMaxSpendable.d.ts +3 -3
  86. package/lib-es/estimateMaxSpendable.d.ts.map +1 -1
  87. package/lib-es/estimateMaxSpendable.js +6 -7
  88. package/lib-es/estimateMaxSpendable.js.map +1 -1
  89. package/lib-es/getTransactionStatus.d.ts +3 -3
  90. package/lib-es/getTransactionStatus.d.ts.map +1 -1
  91. package/lib-es/getTransactionStatus.js +2 -2
  92. package/lib-es/getTransactionStatus.js.map +1 -1
  93. package/lib-es/prepareTransaction.d.ts +3 -3
  94. package/lib-es/prepareTransaction.d.ts.map +1 -1
  95. package/lib-es/prepareTransaction.js +2 -1
  96. package/lib-es/prepareTransaction.js.map +1 -1
  97. package/lib-es/signOperation.d.ts +4 -4
  98. package/lib-es/signOperation.d.ts.map +1 -1
  99. package/lib-es/signOperation.js.map +1 -1
  100. package/lib-es/synchronisation.d.ts +3 -3
  101. package/lib-es/synchronisation.d.ts.map +1 -1
  102. package/lib-es/synchronisation.js +3 -4
  103. package/lib-es/synchronisation.js.map +1 -1
  104. package/lib-es/types.d.ts +2 -79
  105. package/lib-es/types.d.ts.map +1 -1
  106. package/lib-es/utils.d.ts +4 -8
  107. package/lib-es/utils.d.ts.map +1 -1
  108. package/lib-es/utils.js +5 -29
  109. package/lib-es/utils.js.map +1 -1
  110. package/package.json +9 -9
  111. package/src/__tests__/fixtures/common.fixtures.ts +5 -12
  112. package/src/__tests__/integration/bridge.integration.test.ts +3 -3
  113. package/src/__tests__/unit/api.unit.test.ts +0 -1
  114. package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +3 -20
  115. package/src/__tests__/unit/prepareTransaction.unit.test.ts +0 -17
  116. package/src/__tests__/unit/utils.unit.test.ts +1 -22
  117. package/src/bridge/js.ts +3 -3
  118. package/src/config.ts +0 -2
  119. package/src/constants.ts +0 -20
  120. package/src/deviceTransactionConfig.ts +4 -23
  121. package/src/estimateMaxSpendable.ts +17 -13
  122. package/src/getTransactionStatus.ts +9 -9
  123. package/src/prepareTransaction.ts +6 -5
  124. package/src/signOperation.ts +4 -6
  125. package/src/synchronisation.ts +12 -17
  126. package/src/types.ts +1 -103
  127. package/src/utils.ts +8 -39
package/src/utils.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { decodeAccountId } from "@ledgerhq/coin-framework/account/index";
1
+ import { decodeAccountId, findSubAccountById } from "@ledgerhq/coin-framework/account/index";
2
+ import { Account } from "@ledgerhq/types-live";
2
3
  import {
3
4
  Builder,
4
5
  SendMode,
@@ -10,22 +11,17 @@ import {
10
11
  } from "@ton/ton";
11
12
  import BigNumber from "bignumber.js";
12
13
  import { estimateFee } from "./bridge/bridgeHelpers/api";
13
- import { getCoinConfig } from "./config";
14
14
  import {
15
15
  JettonOpCode,
16
16
  MAX_COMMENT_BYTES,
17
17
  TOKEN_TRANSFER_FORWARD_AMOUNT,
18
18
  TOKEN_TRANSFER_MAX_FEE,
19
19
  TOKEN_TRANSFER_QUERY_ID,
20
- WORKCHAIN,
21
20
  } from "./constants";
22
21
  import {
23
- KnownJetton,
24
- TonAccount,
25
22
  TonCell,
26
23
  TonComment,
27
24
  TonPayloadJettonTransfer,
28
- TonSubAccount,
29
25
  TonTransaction,
30
26
  Transaction,
31
27
  } from "./types";
@@ -59,31 +55,14 @@ export const addressesAreEqual = (addr1: string, addr2: string) => {
59
55
  }
60
56
  };
61
57
 
62
- /**
63
- * Returns the known jetton ID and workchain for a given token address.
64
- * Returns null if the token is not found in the known jettons list.
65
- */
66
- function getKnownJettonId(tokenAddress: string, knownJettons: KnownJetton[]) {
67
- const index = knownJettons.findIndex(jetton => jetton.masterAddress.toString() === tokenAddress);
68
- return index > -1 ? { jettonId: index, workchain: WORKCHAIN } : null;
69
- }
70
-
71
- /**
72
- * Finds a sub-account by its ID in a TON account.
73
- * Returns undefined if no matching sub-account is found.
74
- */
75
- export function findSubAccountById(account: TonAccount, id: string): TonSubAccount | undefined {
76
- return account.subAccounts?.find(a => a.id === id) as TonSubAccount | undefined;
77
- }
78
-
79
58
  /**
80
59
  * Builds a TonTransaction object based on the given transaction details.
81
60
  */
82
- export function buildTonTransaction(
61
+ export const buildTonTransaction = (
83
62
  transaction: Transaction,
84
63
  seqno: number,
85
- account: TonAccount,
86
- ): TonTransaction {
64
+ account: Account,
65
+ ): TonTransaction => {
87
66
  const { subAccountId, useAllAmount, amount, comment: commentTx, recipient } = transaction;
88
67
  let recipientParsed = recipient;
89
68
  // if recipient is not valid calculate fees with empty address
@@ -97,16 +76,12 @@ export function buildTonTransaction(
97
76
  // if there is a sub account, the transaction is a token transfer
98
77
  const subAccount = findSubAccountById(account, subAccountId ?? "");
99
78
 
100
- if (subAccount && !subAccount.jettonWallet) {
101
- throw new Error("[ton] jetton wallet not found");
102
- }
103
-
104
79
  const finalAmount = subAccount
105
80
  ? toNano(TOKEN_TRANSFER_MAX_FEE) // for commission fees, excess will be returned
106
81
  : useAllAmount
107
82
  ? BigInt(0)
108
83
  : BigInt(amount.toFixed());
109
- const to = subAccount?.jettonWallet ?? recipientParsed;
84
+ const to = subAccount ? subAccount.token.contractAddress : recipientParsed;
110
85
 
111
86
  const tonTransaction: TonTransaction = {
112
87
  to: TonAddress.parse(to),
@@ -127,9 +102,6 @@ export function buildTonTransaction(
127
102
  if (subAccount) {
128
103
  const forwardPayload = commentTx.text.length ? comment(commentTx.text) : null;
129
104
 
130
- const currencyConfig = getCoinConfig();
131
- const knownJettons = currencyConfig.infra.KNOWN_JETTONS;
132
-
133
105
  tonTransaction.payload = {
134
106
  type: "jetton-transfer",
135
107
  queryId: BigInt(TOKEN_TRANSFER_QUERY_ID),
@@ -139,14 +111,11 @@ export function buildTonTransaction(
139
111
  customPayload: null,
140
112
  forwardAmount: BigInt(TOKEN_TRANSFER_FORWARD_AMOUNT),
141
113
  forwardPayload,
142
- knownJetton: knownJettons
143
- ? getKnownJettonId(subAccount?.token.contractAddress, knownJettons)
144
- : null,
145
114
  };
146
115
  }
147
116
 
148
117
  return tonTransaction;
149
- }
118
+ };
150
119
 
151
120
  /**
152
121
  * Validates if the given comment is valid.
@@ -163,7 +132,7 @@ export const getTransferExpirationTime = () => Math.floor(Date.now() / 1000 + 60
163
132
  * Estimates the fees for a Ton transaction.
164
133
  */
165
134
  export const getTonEstimatedFees = async (
166
- account: TonAccount,
135
+ account: Account,
167
136
  needsInit: boolean,
168
137
  tx: TonTransaction,
169
138
  ) => {