@hinkal/common 0.3.8 → 0.3.10

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 (230) hide show
  1. package/README.md +2 -8
  2. package/common/src/API/API.cjs +1 -1
  3. package/common/src/API/API.d.ts +4 -5
  4. package/common/src/API/API.mjs +79 -80
  5. package/common/src/API/dashboardTransactionCalls.cjs +1 -1
  6. package/common/src/API/dashboardTransactionCalls.d.ts +4 -1
  7. package/common/src/API/dashboardTransactionCalls.mjs +2 -2
  8. package/common/src/API/enclaveRecipientInfoCalls.d.ts +0 -2
  9. package/common/src/API/enclaveSignatureCalls.cjs +1 -1
  10. package/common/src/API/enclaveSignatureCalls.d.ts +2 -1
  11. package/common/src/API/enclaveSignatureCalls.mjs +5 -8
  12. package/common/src/API/enclaveUtxoCalls.cjs +1 -1
  13. package/common/src/API/enclaveUtxoCalls.d.ts +12 -8
  14. package/common/src/API/enclaveUtxoCalls.mjs +17 -20
  15. package/common/src/API/privateSendRecipientInfoCalls.cjs +1 -1
  16. package/common/src/API/privateSendRecipientInfoCalls.d.ts +3 -6
  17. package/common/src/API/privateSendRecipientInfoCalls.mjs +12 -6
  18. package/common/src/API/scheduled-transactions-calls.cjs +1 -1
  19. package/common/src/API/scheduled-transactions-calls.d.ts +1 -5
  20. package/common/src/API/scheduled-transactions-calls.mjs +2 -6
  21. package/common/src/constants/bridging.constants.cjs +1 -1
  22. package/common/src/constants/bridging.constants.d.ts +1 -0
  23. package/common/src/constants/bridging.constants.mjs +1 -1
  24. package/common/src/constants/chains.constants.cjs +1 -1
  25. package/common/src/constants/chains.constants.d.ts +18 -17
  26. package/common/src/constants/chains.constants.mjs +108 -89
  27. package/common/src/constants/deploy-data/deploy-data-arbMainnet.json.cjs +1 -1
  28. package/common/src/constants/deploy-data/deploy-data-arbMainnet.json.mjs +2 -1
  29. package/common/src/constants/deploy-data/deploy-data-base.json.cjs +1 -1
  30. package/common/src/constants/deploy-data/deploy-data-base.json.mjs +2 -1
  31. package/common/src/constants/deploy-data/deploy-data-bnbMainnet.json.cjs +1 -1
  32. package/common/src/constants/deploy-data/deploy-data-bnbMainnet.json.mjs +2 -1
  33. package/common/src/constants/deploy-data/deploy-data-ethMainnet.json.cjs +1 -1
  34. package/common/src/constants/deploy-data/deploy-data-ethMainnet.json.mjs +2 -1
  35. package/common/src/constants/deploy-data/deploy-data-optimism.json.cjs +1 -1
  36. package/common/src/constants/deploy-data/deploy-data-optimism.json.mjs +2 -1
  37. package/common/src/constants/deploy-data/deploy-data-polygon.json.cjs +1 -1
  38. package/common/src/constants/deploy-data/deploy-data-polygon.json.mjs +2 -1
  39. package/common/src/constants/events.constants.cjs +1 -1
  40. package/common/src/constants/events.constants.mjs +1 -16
  41. package/common/src/constants/protocol.constants.d.ts +1 -3
  42. package/common/src/constants/server.constants.cjs +1 -1
  43. package/common/src/constants/server.constants.d.ts +1 -4
  44. package/common/src/constants/server.constants.mjs +1 -4
  45. package/common/src/constants/tx-confirmation.constants.cjs +1 -1
  46. package/common/src/constants/tx-confirmation.constants.d.ts +1 -0
  47. package/common/src/constants/tx-confirmation.constants.mjs +2 -2
  48. package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
  49. package/common/src/data-structures/Hinkal/Hinkal.d.ts +6 -9
  50. package/common/src/data-structures/Hinkal/Hinkal.mjs +129 -160
  51. package/common/src/data-structures/Hinkal/IHinkal.d.ts +5 -9
  52. package/common/src/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
  53. package/common/src/data-structures/Hinkal/handleAutoDepositBack.mjs +23 -23
  54. package/common/src/data-structures/Hinkal/hinkalBridgePrivateToPrivate.cjs +1 -1
  55. package/common/src/data-structures/Hinkal/hinkalBridgePrivateToPrivate.mjs +1 -1
  56. package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
  57. package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +10 -10
  58. package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
  59. package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +18 -18
  60. package/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.cjs +1 -1
  61. package/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.mjs +3 -2
  62. package/common/src/data-structures/Hinkal/hinkalProxySend.cjs +1 -0
  63. package/common/src/data-structures/Hinkal/hinkalProxySend.d.ts +6 -0
  64. package/common/src/data-structures/Hinkal/hinkalProxySend.mjs +16 -0
  65. package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
  66. package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +44 -47
  67. package/common/src/data-structures/Hinkal/hinkalSolanaTransact.cjs +1 -1
  68. package/common/src/data-structures/Hinkal/hinkalSolanaTransact.mjs +2 -2
  69. package/common/src/data-structures/Hinkal/hinkalTransact.cjs +1 -1
  70. package/common/src/data-structures/Hinkal/hinkalTransact.mjs +1 -1
  71. package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
  72. package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +4 -4
  73. package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
  74. package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +101 -94
  75. package/common/src/data-structures/Hinkal/index.d.ts +0 -1
  76. package/common/src/data-structures/IndexedDB/activity-db.cjs +1 -1
  77. package/common/src/data-structures/IndexedDB/activity-db.mjs +34 -34
  78. package/common/src/data-structures/IndexedDB/index.cjs +1 -1
  79. package/common/src/data-structures/IndexedDB/index.d.ts +1 -0
  80. package/common/src/data-structures/IndexedDB/index.mjs +1 -0
  81. package/common/src/data-structures/IndexedDB/scheduled-transactions-db.cjs +1 -0
  82. package/common/src/data-structures/IndexedDB/scheduled-transactions-db.d.ts +11 -0
  83. package/common/src/data-structures/IndexedDB/scheduled-transactions-db.mjs +34 -0
  84. package/common/src/data-structures/IndexedDB/signatures-db.cjs +1 -1
  85. package/common/src/data-structures/IndexedDB/signatures-db.mjs +11 -11
  86. package/common/src/data-structures/TokenDBs/PrivateTokensDB.cjs +1 -1
  87. package/common/src/data-structures/TokenDBs/PrivateTokensDB.mjs +18 -19
  88. package/common/src/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
  89. package/common/src/data-structures/event-service/evm/BlockchainEventEmitter.mjs +11 -11
  90. package/common/src/data-structures/event-service/helpers/ClientEventHelper.cjs +1 -1
  91. package/common/src/data-structures/event-service/helpers/ClientEventHelper.mjs +6 -6
  92. package/common/src/data-structures/private-balances/HinkalPrivateBalanceController.cjs +1 -1
  93. package/common/src/data-structures/private-balances/HinkalPrivateBalanceController.d.ts +1 -0
  94. package/common/src/data-structures/private-balances/HinkalPrivateBalanceController.mjs +79 -75
  95. package/common/src/data-structures/provider-adapter/IProviderAdapter.d.ts +1 -4
  96. package/common/src/error-handling/error-codes.constants.cjs +1 -1
  97. package/common/src/error-handling/error-codes.constants.d.ts +6 -0
  98. package/common/src/error-handling/error-codes.constants.mjs +10 -4
  99. package/common/src/functions/auto-deposit-back-helpers/get-gas-token-records.cjs +1 -1
  100. package/common/src/functions/auto-deposit-back-helpers/get-gas-token-records.mjs +7 -6
  101. package/common/src/functions/auto-deposit-back-helpers/select-gas-token.cjs +1 -1
  102. package/common/src/functions/auto-deposit-back-helpers/select-gas-token.mjs +8 -8
  103. package/common/src/functions/index.cjs +1 -1
  104. package/common/src/functions/index.mjs +1 -2
  105. package/common/src/functions/pre-transaction/getVolatileTransferAmount.cjs +1 -1
  106. package/common/src/functions/pre-transaction/getVolatileTransferAmount.mjs +12 -12
  107. package/common/src/functions/private-wallet/emporium.helpers.cjs +1 -1
  108. package/common/src/functions/private-wallet/emporium.helpers.mjs +13 -13
  109. package/common/src/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
  110. package/common/src/functions/private-wallet/emporium.swap.helpers.mjs +13 -13
  111. package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
  112. package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +4 -4
  113. package/common/src/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
  114. package/common/src/functions/snarkjs/constructSolanaZkProof.mjs +5 -5
  115. package/common/src/functions/snarkjs/constructTxEnclave.cjs +1 -1
  116. package/common/src/functions/snarkjs/constructTxEnclave.d.ts +1 -1
  117. package/common/src/functions/snarkjs/constructTxEnclave.mjs +61 -133
  118. package/common/src/functions/snarkjs/constructTxEnclaveVerify.cjs +1 -0
  119. package/common/src/functions/snarkjs/constructTxEnclaveVerify.d.ts +5 -0
  120. package/common/src/functions/snarkjs/constructTxEnclaveVerify.mjs +295 -0
  121. package/common/src/functions/utils/addresses.cjs +1 -1
  122. package/common/src/functions/utils/addresses.d.ts +1 -0
  123. package/common/src/functions/utils/addresses.mjs +13 -12
  124. package/common/src/functions/utils/bridge-arrival.utils.cjs +1 -1
  125. package/common/src/functions/utils/bridge-arrival.utils.mjs +12 -11
  126. package/common/src/functions/utils/create-provider.cjs +1 -1
  127. package/common/src/functions/utils/create-provider.mjs +4 -1
  128. package/common/src/functions/utils/enclave-recipient-info-storage.cjs +1 -1
  129. package/common/src/functions/utils/enclave-recipient-info-storage.d.ts +4 -1
  130. package/common/src/functions/utils/enclave-recipient-info-storage.mjs +1 -0
  131. package/common/src/functions/utils/enclave-signature-storage.cjs +1 -1
  132. package/common/src/functions/utils/enclave-signature-storage.d.ts +1 -1
  133. package/common/src/functions/utils/enclave-signature-storage.mjs +3 -3
  134. package/common/src/functions/utils/enclave-utxo-storage.cjs +1 -1
  135. package/common/src/functions/utils/enclave-utxo-storage.d.ts +3 -3
  136. package/common/src/functions/utils/enclave-utxo-storage.mjs +8 -5
  137. package/common/src/functions/utils/encryptInputForEnclave.cjs +1 -1
  138. package/common/src/functions/utils/encryptInputForEnclave.d.ts +8 -0
  139. package/common/src/functions/utils/encryptInputForEnclave.mjs +43 -23
  140. package/common/src/functions/utils/erc20tokenFunctions.cjs +1 -1
  141. package/common/src/functions/utils/erc20tokenFunctions.mjs +2 -15
  142. package/common/src/functions/utils/fees.utils.cjs +1 -1
  143. package/common/src/functions/utils/fees.utils.mjs +6 -6
  144. package/common/src/functions/utils/index.cjs +1 -1
  145. package/common/src/functions/utils/index.d.ts +1 -0
  146. package/common/src/functions/utils/index.mjs +3 -3
  147. package/common/src/functions/utils/ipfs.d.ts +2 -3
  148. package/common/src/functions/utils/lifi.utils.d.ts +2 -0
  149. package/common/src/functions/utils/nearIntents.utils.cjs +1 -1
  150. package/common/src/functions/utils/nearIntents.utils.mjs +6 -6
  151. package/common/src/functions/utils/publicBalance.utils.cjs +1 -1
  152. package/common/src/functions/utils/publicBalance.utils.mjs +9 -10
  153. package/common/src/functions/utils/temporary-wallet-recovery.utils.cjs +1 -0
  154. package/common/src/functions/utils/temporary-wallet-recovery.utils.d.ts +7 -0
  155. package/common/src/functions/utils/temporary-wallet-recovery.utils.mjs +10 -0
  156. package/common/src/functions/utils/tron.utils.cjs +1 -1
  157. package/common/src/functions/utils/tron.utils.mjs +16 -29
  158. package/common/src/functions/utils/tx-confirmation.utils.cjs +1 -1
  159. package/common/src/functions/utils/tx-confirmation.utils.d.ts +1 -0
  160. package/common/src/functions/utils/tx-confirmation.utils.mjs +16 -13
  161. package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
  162. package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +5 -5
  163. package/common/src/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
  164. package/common/src/functions/web3/events/getInputUtxosEnclave.d.ts +1 -1
  165. package/common/src/functions/web3/events/getInputUtxosEnclave.mjs +19 -11
  166. package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
  167. package/common/src/functions/web3/events/getShieldedBalance.d.ts +4 -4
  168. package/common/src/functions/web3/events/getShieldedBalance.mjs +113 -102
  169. package/common/src/functions/web3/functionCalls/transactCallDirectTron.cjs +1 -1
  170. package/common/src/functions/web3/functionCalls/transactCallDirectTron.mjs +16 -16
  171. package/common/src/providers/SolanaProviderAdapter.cjs +1 -1
  172. package/common/src/providers/SolanaProviderAdapter.d.ts +1 -4
  173. package/common/src/providers/SolanaProviderAdapter.mjs +3 -6
  174. package/common/src/providers/WagmiProviderAdapter.cjs +1 -1
  175. package/common/src/providers/WagmiProviderAdapter.mjs +5 -5
  176. package/common/src/types/cache.types.cjs +1 -1
  177. package/common/src/types/cache.types.d.ts +2 -1
  178. package/common/src/types/cache.types.mjs +1 -1
  179. package/common/src/types/enclaveApi.types.d.ts +2 -3
  180. package/common/src/types/ethereum-network.types.d.ts +1 -0
  181. package/common/src/types/events.types.d.ts +1 -0
  182. package/common/src/types/near-intents.types.d.ts +1 -0
  183. package/common/src/types/remote-proof.types.d.ts +5 -0
  184. package/common/src/types/remote-tx-build.types.d.ts +37 -4
  185. package/common/src/types/scheduled-transactions.types.d.ts +18 -0
  186. package/common/src/types/solana.types.d.ts +0 -3
  187. package/common/src/webworker/{logError-RKYfeI6h.js → logError-CIIt1CO3.js} +1 -1
  188. package/common/src/webworker/package.json +5 -6
  189. package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
  190. package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
  191. package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
  192. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
  193. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
  194. package/common/src/webworker/utxoWorkerNode.cjs +1 -1
  195. package/common/src/webworker/viteWorkerURL.constant.cjs +3 -3
  196. package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
  197. package/common/src/webworker/workerProxy-BHzCZ9HT.js +1 -0
  198. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
  199. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
  200. package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
  201. package/package.json +5 -6
  202. package/services/Hinkal.cjs +1 -1
  203. package/services/Hinkal.d.ts +6 -2
  204. package/services/Hinkal.mjs +9 -4
  205. package/types/IHinkal.d.ts +6 -2
  206. package/common/src/API/evm-token-assets.cjs +0 -1
  207. package/common/src/API/evm-token-assets.mjs +0 -20
  208. package/common/src/API/getAnyRecipientInfo.d.ts +0 -1
  209. package/common/src/API/solana-nft-assets.cjs +0 -1
  210. package/common/src/API/solana-nft-assets.mjs +0 -11
  211. package/common/src/data-structures/Hinkal/hinkalSolanaSponsoredProxySend.d.ts +0 -5
  212. package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.cjs +0 -1
  213. package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.mjs +0 -109
  214. package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.cjs +0 -1
  215. package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.mjs +0 -94
  216. package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.cjs +0 -1
  217. package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.mjs +0 -134
  218. package/common/src/data-structures/TokenDBs/PublicTokensDB.cjs +0 -1
  219. package/common/src/data-structures/TokenDBs/PublicTokensDB.mjs +0 -32
  220. package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.cjs +0 -1
  221. package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.mjs +0 -37
  222. package/common/src/data-structures/TokenDBs/TronPublicTokensDB.cjs +0 -1
  223. package/common/src/data-structures/TokenDBs/TronPublicTokensDB.mjs +0 -51
  224. package/common/src/data-structures/TokenDBs/index.cjs +0 -1
  225. package/common/src/data-structures/TokenDBs/index.mjs +0 -6
  226. package/common/src/functions/utils/ipfs.cjs +0 -1
  227. package/common/src/functions/utils/ipfs.mjs +0 -1
  228. package/common/src/functions/utils/reloadPage.cjs +0 -1
  229. package/common/src/functions/utils/reloadPage.mjs +0 -4
  230. package/common/src/webworker/workerProxy-COB7g4Qc.js +0 -1
@@ -58,38 +58,25 @@ var s = 2000n, c = (e) => {
58
58
  c: i,
59
59
  publicSignals: a
60
60
  };
61
- }, S = (e, t) => {
62
- let n = a.AbiCoder.defaultAbiCoder().encode([
63
- "uint16",
64
- "uint16",
65
- "uint16",
66
- "uint256"
67
- ], [
68
- e.tokenNumber,
69
- e.nullifierAmount,
70
- e.outputAmount,
71
- t
72
- ]);
73
- return BigInt(a.keccak256(n));
74
- }, C = async (e, t, n, o, s, c, l, u = !1) => {
75
- let d = S(s, c), f = e.map(String), p = n.map(String), m = o.map(String), h = {
61
+ }, S = async (e, t, n, o, s, c, l, u = !1) => {
62
+ let d = e.map(String), f = n.map(String), p = o.map(String), m = {
76
63
  chainId: l,
77
- a: f,
64
+ a: d,
78
65
  b: [t[0].map(String), t[1].map(String)],
79
- c: p,
80
- inputs: m,
81
- verifier_id: String(d),
66
+ c: f,
67
+ inputs: p,
68
+ externalActionId: String(c),
82
69
  tokenNumber: s.tokenNumber,
83
70
  nullifierAmount: s.nullifierAmount,
84
71
  outputAmount: s.outputAmount,
85
72
  skipLock: u
86
- }, g = await i.post(`${r}/sign-proof`, h), { v: _, r: v, s: y } = a.Signature.from(g.signature.trim());
73
+ }, h = await i.post(`${r}/sign-proof`, m), { v: g, r: _, s: v } = a.Signature.from(h.signature.trim());
87
74
  return {
88
- v: _,
89
- r: v,
90
- s: y
75
+ v: g,
76
+ r: _,
77
+ s: v
91
78
  };
92
- }, w = (e) => {
79
+ }, C = (e) => {
93
80
  if (e.newRootHash === void 0) throw Error("circomData.newRootHash is required for Tron transactions");
94
81
  if (e.insertedLeafIndex === void 0) throw Error("circomData.insertedLeafIndex is required for Tron transactions");
95
82
  return [
@@ -128,17 +115,17 @@ var s = 2000n, c = (e) => {
128
115
  e.insertedLeafIndex,
129
116
  e.createBlockedUtxos ?? !1
130
117
  ];
131
- }, T = (e) => {
118
+ }, w = (e) => {
132
119
  e[1] = [[e[1][0][1], e[1][0][0]], [e[1][1][1], e[1][1][0]]];
133
- }, E = async (e, t, n, r, i, a = !0, o = !1) => {
120
+ }, T = async (e, t, n, r, i, a = !0, o = !1) => {
134
121
  if (e) {
135
- let { a: e, b: s, c, publicSignals: l } = x(t), u = await C(e, s, c, l, n, BigInt(r.externalActionData.externalActionId), i, o), d = {
122
+ let { a: e, b: s, c, publicSignals: l } = x(t), u = await S(e, s, c, l, n, BigInt(r.externalActionData.externalActionId), i, o), d = {
136
123
  v: u.v,
137
124
  r: u.r,
138
125
  s: u.s
139
126
  };
140
- return a && T(t), d;
127
+ return a && w(t), d;
141
128
  }
142
129
  };
143
130
  //#endregion
144
- export { f as addressToHexFormat, w as circomDataToArray, h as createTronCallData, l as createTronWeb, b as estimateTronFeeSunWithPadding, u as evmHexToTronBase58Address, y as fetchTronAccountResources, v as fetchTronChainParameters, C as generateProofSignatureRemotely, g as getAvailableResource, _ as getChainParameterValue, p as getTronWalletRpcUrl, S as getVerifierId, c as normalizeTronPrivateKey, x as parseZkCalldata, E as reorderZkCallData, T as swapTronBCoordinate, d as toTronBase58IfHex };
131
+ export { f as addressToHexFormat, C as circomDataToArray, h as createTronCallData, l as createTronWeb, b as estimateTronFeeSunWithPadding, u as evmHexToTronBase58Address, y as fetchTronAccountResources, v as fetchTronChainParameters, S as generateProofSignatureRemotely, g as getAvailableResource, _ as getChainParameterValue, p as getTronWalletRpcUrl, c as normalizeTronPrivateKey, x as parseZkCalldata, T as reorderZkCallData, w as swapTronBCoordinate, d as toTronBase58IfHex };
@@ -1 +1 @@
1
- const e=require(`../../constants/chains.constants.cjs`),t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../error-handling/logger.cjs`),r=require(`./create-provider.cjs`),i=require(`../../constants/tx-confirmation.constants.cjs`);require(`../../constants/index.cjs`);var a=`confirmed`,o=async(e,n,a={})=>{let{evmConfirmations:o=1,evmTimeoutMs:s=i.TX_CONFIRMATION_TIMEOUT_EXTENDED}=a,c=n.startsWith(`0x`)?n:`0x${n}`,l=await r.createJsonRpcProvider(e).waitForTransaction(c,o,s);if(!l||l.status!==1)throw Error(t.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED);return l},s=async(t,n,i={})=>{let{solanaCommitment:o=a}=i,{rpcUrl:s}=e.networkRegistry[t];if(!s)throw Error(`RPC URL not found for the specified chain ID`);let c=await r.createCustomSolanaConnection(s,o).confirmTransaction(n,o);if(c.value.err)throw Error(`Transaction failed`);return c},c=async(t,r,i={})=>{try{if(e.isSolanaLike(t)){await s(t,r,i);return}await o(t,r.startsWith(`0x`)?r:`0x${r}`,i)}catch(e){throw n.Logger.error(`waitForTransactionConfirmation failed`,{chainId:t,txHash:r,error:e}),e}};exports.waitForEthereumTransactionConfirmation=o,exports.waitForSolanaTransactionConfirmation=s,exports.waitForTransactionConfirmation=c;
1
+ const e=require(`../../constants/chains.constants.cjs`),t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../error-handling/logger.cjs`),r=require(`./create-provider.cjs`),i=require(`../../constants/tx-confirmation.constants.cjs`);require(`../../constants/index.cjs`);var a=`confirmed`,o=async(e,n,a={})=>{let{evmConfirmations:o=1,evmTimeoutMs:s=i.TX_CONFIRMATION_TIMEOUT_EXTENDED}=a,c=n.startsWith(`0x`)?n:`0x${n}`,l=await r.createJsonRpcProvider(e).waitForTransaction(c,o,s);if(!l||l.status!==1)throw Error(t.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED);return l},s=async(t,n,o={})=>{let{solanaCommitment:s=a,solanaTimeoutMs:c=i.SOLANA_TX_CONFIRMATION_TIMEOUT}=o,{rpcUrl:l}=e.networkRegistry[t];if(!l)throw Error(`RPC URL not found for the specified chain ID`);let u=await r.createCustomSolanaConnection(l,{commitment:s,confirmTransactionInitialTimeout:c}).confirmTransaction(n,s);if(u.value.err)throw Error(`Transaction failed`);return u},c=async(t,r,i={})=>{try{if(e.isSolanaLike(t)){await s(t,r,i);return}await o(t,r.startsWith(`0x`)?r:`0x${r}`,i)}catch(e){throw n.Logger.error(`waitForTransactionConfirmation failed`,{chainId:t,txHash:r,error:e}),e}};exports.waitForEthereumTransactionConfirmation=o,exports.waitForSolanaTransactionConfirmation=s,exports.waitForTransactionConfirmation=c;
@@ -3,6 +3,7 @@ type TxConfirmationOptions = {
3
3
  evmConfirmations?: number;
4
4
  evmTimeoutMs?: number;
5
5
  solanaCommitment?: Commitment;
6
+ solanaTimeoutMs?: number;
6
7
  };
7
8
  export declare const waitForEthereumTransactionConfirmation: (chainId: number, txHash: string, opts?: TxConfirmationOptions) => Promise<import('ethers').TransactionReceipt>;
8
9
  export declare const waitForSolanaTransactionConfirmation: (chainId: number, txHash: string, opts?: TxConfirmationOptions) => Promise<import('@solana/web3.js').RpcResponseAndContext<import('@solana/web3.js').SignatureResult>>;
@@ -2,26 +2,29 @@ import { isSolanaLike as e, networkRegistry as t } from "../../constants/chains.
2
2
  import { transactionErrorCodes as n } from "../../error-handling/error-codes.constants.mjs";
3
3
  import { Logger as r } from "../../error-handling/logger.mjs";
4
4
  import { createCustomSolanaConnection as i, createJsonRpcProvider as a } from "./create-provider.mjs";
5
- import { TX_CONFIRMATION_TIMEOUT_EXTENDED as o } from "../../constants/tx-confirmation.constants.mjs";
5
+ import { SOLANA_TX_CONFIRMATION_TIMEOUT as o, TX_CONFIRMATION_TIMEOUT_EXTENDED as s } from "../../constants/tx-confirmation.constants.mjs";
6
6
  import "../../constants/index.mjs";
7
7
  //#region libs/shared/common/src/functions/utils/tx-confirmation.utils.ts
8
- var s = "confirmed", c = async (e, t, r = {}) => {
9
- let { evmConfirmations: i = 1, evmTimeoutMs: s = o } = r, c = t.startsWith("0x") ? t : `0x${t}`, l = await a(e).waitForTransaction(c, i, s);
8
+ var c = "confirmed", l = async (e, t, r = {}) => {
9
+ let { evmConfirmations: i = 1, evmTimeoutMs: o = s } = r, c = t.startsWith("0x") ? t : `0x${t}`, l = await a(e).waitForTransaction(c, i, o);
10
10
  if (!l || l.status !== 1) throw Error(n.TRANSACTION_NOT_CONFIRMED);
11
11
  return l;
12
- }, l = async (e, n, r = {}) => {
13
- let { solanaCommitment: a = s } = r, { rpcUrl: o } = t[e];
14
- if (!o) throw Error("RPC URL not found for the specified chain ID");
15
- let c = await i(o, a).confirmTransaction(n, a);
16
- if (c.value.err) throw Error("Transaction failed");
17
- return c;
18
- }, u = async (t, n, i = {}) => {
12
+ }, u = async (e, n, r = {}) => {
13
+ let { solanaCommitment: a = c, solanaTimeoutMs: s = o } = r, { rpcUrl: l } = t[e];
14
+ if (!l) throw Error("RPC URL not found for the specified chain ID");
15
+ let u = await i(l, {
16
+ commitment: a,
17
+ confirmTransactionInitialTimeout: s
18
+ }).confirmTransaction(n, a);
19
+ if (u.value.err) throw Error("Transaction failed");
20
+ return u;
21
+ }, d = async (t, n, i = {}) => {
19
22
  try {
20
23
  if (e(t)) {
21
- await l(t, n, i);
24
+ await u(t, n, i);
22
25
  return;
23
26
  }
24
- await c(t, n.startsWith("0x") ? n : `0x${n}`, i);
27
+ await l(t, n.startsWith("0x") ? n : `0x${n}`, i);
25
28
  } catch (e) {
26
29
  throw r.error("waitForTransactionConfirmation failed", {
27
30
  chainId: t,
@@ -31,4 +34,4 @@ var s = "confirmed", c = async (e, t, r = {}) => {
31
34
  }
32
35
  };
33
36
  //#endregion
34
- export { c as waitForEthereumTransactionConfirmation, l as waitForSolanaTransactionConfirmation, u as waitForTransactionConfirmation };
37
+ export { l as waitForEthereumTransactionConfirmation, u as waitForSolanaTransactionConfirmation, d as waitForTransactionConfirmation };
@@ -1 +1 @@
1
- require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/upToDateState.cjs`),i=require(`../../utils/cacheFunctions.cjs`),a=require(`../../utils/encodeTokenWithId.cjs`),o=require(`../../utils/solanaMint.utils.cjs`),s=require(`./getInputUtxosEnclave.cjs`),c=require(`../../utils/customEnclaveFunctionsRegister.cjs`),l=require(`../../utils/addresses.cjs`),u=require(`../../../API/scheduled-transactions-calls.cjs`),d=require(`../../utils/tron.utils.cjs`);var f=new(require(`async-mutex`)).Mutex,p=async(e,t)=>e.allowParallelBalanceLocalDecryption?t():f.runExclusive(t),m=e=>e?.[0]===0n&&e?.[1]===1n,h=async(e,t,n,a,o,s,c,l,u)=>p(e,async()=>{u+=1;let d=s.slice(u),{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n),m=[...c,...p];return await r.checkAddressNotUpdated(e,a),i.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,o),await e.utxoUtils.buildBatchProcess(m,t,n)}),g=async(e,t,n,r,a,o,c,l,u,d)=>{try{let{utxos:r,encryptedOutputs:o,lastOutput:c}=await s.getInputUtxosEnclave(n,t,d);return i.setHinkalCache({encryptedOutputs:o,lastOutput:c},e,n,a),r}catch{return h(e,t,n,r,a,o,c,l,u)}},_=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},v=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),y=(e,t,r,i,a,o,s)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new n.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:s,nullifyingKey:i,spendingPublicKey:a})),r)for(;e.length>6;)e.splice(e.length-1)},b=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,useBlockedUtxos:s=!1})=>{let l=a??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,f=e.encryptedOutputsByChain[t],p=e.nullifiersByChain[t],_=Array.from(f);o&&i.resetCache(e,t,u);let{encryptedOutputs:y,lastOutput:b}=i.getHinkalCache(e,t,u);await r.checkAddressNotUpdated(e,l);let x=b!==``,S=_.findIndex(e=>e.value===b),C=S>-1,w=!x&&S===-1,T=e.areMerkleTreeUpdatesDisabled(),E=c.getCustomUtxoDecryptor(),D=!T&&(C||!E&&w),O=!T&&!!E&&w,k=!D&&!O,A=[];D?A=await h(e,d,t,l,u,_,y,b,S):O&&E?A=await g(e,d,t,l,u,_,y,b,S,E):k&&(A=await e.utxoUtils.buildBatchProcess(y,d,t)),await r.checkAddressNotUpdated(e,l);let j=await v(e,A,p);return{inputUtxos:(s?j.filter(e=>e.isBlocked):j.filter(e=>!e.isBlocked)).filter(e=>!m(e.H0))}},x=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1})=>{let o=i??await t.getEthereumAddressByChain(n),s=l.hashEthereumAddress(e.isTronLike(n)?d.addressToHexFormat(o):o),{inputUtxos:c}=await b({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:o,resetCacheBefore:a,useBlockedUtxos:!0});if(!c.length)return{inputUtxos:[]};let{indexes:f}=await u.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:s,nullifiers:c.map(e=>e.getNullifier())});return{inputUtxos:f.map(e=>c[e]).filter(e=>!!e)}},S=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:s=!0,chainId:c,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,useBlockedUtxos:m=!1})=>{let h=l??n.userKeys.getShieldedPrivateKey(),g=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:v}=m?await x({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f}):await b({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f}),S=_(r),C=new Map;v.forEach(e=>{let n=e.getTokenAddress(c);if(S&&!S.some(e=>t.caseInsensitiveEqual(e,n)))return;let r=a.normalizeTokenAddress(c,n),i=C.get(r)??[];C.set(r,[...i,e])}),p?.forEach(e=>{let t=a.normalizeTokenAddress(c,e);C.set(t,C.get(t)??[])});for(let[t,n]of C){let r=t,a=e.isSolanaLike(c),l=a?r:void 0;y(n,i,s,h,g,a?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),l)}return C};exports.getInputUtxoAndBalance=b,exports.getInputUtxoAndBalanceOfStuckUtxos=x,exports.getInputUtxoAndBalancePerToken=S;
1
+ require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/upToDateState.cjs`),i=require(`../../utils/cacheFunctions.cjs`),a=require(`../../utils/encodeTokenWithId.cjs`),o=require(`../../utils/solanaMint.utils.cjs`),s=require(`./getInputUtxosEnclave.cjs`),c=require(`../../utils/customEnclaveFunctionsRegister.cjs`),l=require(`../../utils/tron.utils.cjs`),u=require(`../../utils/addresses.cjs`),d=require(`../../../API/scheduled-transactions-calls.cjs`);var f=new(require(`async-mutex`)).Mutex,p=async(e,t)=>e.allowParallelBalanceLocalDecryption?t():f.runExclusive(t),m=e=>e?.[0]===0n&&e?.[1]===1n,h=async(e,t,n,a,o,s,c,l,u)=>p(e,async()=>{u+=1;let d=s.slice(u),{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n),m=[...c,...p];return await r.checkAddressNotUpdated(e,a),i.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,o),await e.utxoUtils.buildBatchProcess(m,t,n)}),g=async(e,t,n,r,a,o,c,l,u,d)=>{try{let{utxos:r,encryptedOutputs:o,lastOutput:c}=await s.getInputUtxosEnclave(n,t,d);return i.setHinkalCache({encryptedOutputs:o,lastOutput:c},e,n,a),r}catch{return h(e,t,n,r,a,o,c,l,u)}},_=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},v=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),y=(e,t,r,i,a,o,s)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new n.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:s,nullifyingKey:i,spendingPublicKey:a})),r)for(;e.length>6;)e.splice(e.length-1)},b=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,useBlockedUtxos:s=!1})=>{let l=a??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,f=e.encryptedOutputsByChain[t],p=e.nullifiersByChain[t],_=Array.from(f);o&&i.resetCache(e,t,u);let{encryptedOutputs:y,lastOutput:b}=i.getHinkalCache(e,t,u);await r.checkAddressNotUpdated(e,l);let x=b!==``,S=_.findIndex(e=>e.value===b),C=S>-1,w=!x&&S===-1,T=e.areMerkleTreeUpdatesDisabled(),E=c.getCustomUtxoDecryptor(),D=!T&&(C||!E&&w),O=!T&&!!E&&w,k=!D&&!O,A=[];D?A=await h(e,d,t,l,u,_,y,b,S):O&&E?A=await g(e,d,t,l,u,_,y,b,S,E):k&&(A=await e.utxoUtils.buildBatchProcess(y,d,t)),await r.checkAddressNotUpdated(e,l);let j=await v(e,A,p);return{inputUtxos:(s?j.filter(e=>e.isBlocked):j.filter(e=>!e.isBlocked)).filter(e=>!m(e.H0))}},x=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1})=>{let o=i??await t.getEthereumAddressByChain(n),s=u.hashEthereumAddress(e.isTronLike(n)?l.addressToHexFormat(o):o),{inputUtxos:c}=await b({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:o,resetCacheBefore:a,useBlockedUtxos:!0});if(!c.length)return{inputUtxos:[]};let{indexes:f}=await d.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:s,nullifiers:c.map(e=>e.getNullifier())});return{inputUtxos:f.map(e=>c[e]).filter(e=>!!e)}},S=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:s=!0,chainId:c,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,useBlockedUtxos:m=!1})=>{let h=l??n.userKeys.getShieldedPrivateKey(),g=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:v}=m?await x({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f}):await b({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f}),S=_(r),C=new Map;v.forEach(e=>{let n=e.getTokenAddress(c);if(S&&!S.some(e=>t.caseInsensitiveEqual(e,n)))return;let r=a.normalizeTokenAddress(c,n),i=C.get(r)??[];C.set(r,[...i,e])}),p?.forEach(e=>{let t=a.normalizeTokenAddress(c,e);C.set(t,C.get(t)??[])});for(let[t,n]of C){let r=t,a=e.isSolanaLike(c),l=a?r:void 0;y(n,i,s,h,g,a?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),l)}return C};exports.getInputUtxoAndBalance=b,exports.getInputUtxoAndBalanceOfStuckUtxos=x,exports.getInputUtxoAndBalancePerToken=S;
@@ -7,9 +7,9 @@ import { normalizeTokenAddress as c } from "../../utils/encodeTokenWithId.mjs";
7
7
  import { formatMintAddress as l } from "../../utils/solanaMint.utils.mjs";
8
8
  import { getInputUtxosEnclave as u } from "./getInputUtxosEnclave.mjs";
9
9
  import { getCustomUtxoDecryptor as d } from "../../utils/customEnclaveFunctionsRegister.mjs";
10
- import { hashEthereumAddress as f } from "../../utils/addresses.mjs";
11
- import { getScheduledTransactionsNullifierIndexes as p } from "../../../API/scheduled-transactions-calls.mjs";
12
- import { addressToHexFormat as m } from "../../utils/tron.utils.mjs";
10
+ import { addressToHexFormat as f } from "../../utils/tron.utils.mjs";
11
+ import { hashEthereumAddress as p } from "../../utils/addresses.mjs";
12
+ import { getScheduledTransactionsNullifierIndexes as m } from "../../../API/scheduled-transactions-calls.mjs";
13
13
  import { Mutex as h } from "async-mutex";
14
14
  //#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
15
15
  var g = new h(), _ = async (e, t) => e.allowParallelBalanceLocalDecryption ? t() : g.runExclusive(t), v = (e) => e?.[0] === 0n && e?.[1] === 1n, y = async (e, t, n, r, a, o, c, l, u) => _(e, async () => {
@@ -50,7 +50,7 @@ var g = new h(), _ = async (e, t) => e.allowParallelBalanceLocalDecryption ? t()
50
50
  let M = await S(e, j, m);
51
51
  return { inputUtxos: (c ? M.filter((e) => e.isBlocked) : M.filter((e) => !e.isBlocked)).filter((e) => !v(e.H0)) };
52
52
  }, T = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1 }) => {
53
- let o = i ?? await e.getEthereumAddressByChain(n), s = f(t(n) ? m(o) : o), { inputUtxos: c } = await w({
53
+ let o = i ?? await e.getEthereumAddressByChain(n), s = p(t(n) ? f(o) : o), { inputUtxos: c } = await w({
54
54
  hinkal: e,
55
55
  chainId: n,
56
56
  passedShieldedPublicKey: r,
@@ -59,7 +59,7 @@ var g = new h(), _ = async (e, t) => e.allowParallelBalanceLocalDecryption ? t()
59
59
  useBlockedUtxos: !0
60
60
  });
61
61
  if (!c.length) return { inputUtxos: [] };
62
- let { indexes: l } = await p({
62
+ let { indexes: l } = await m({
63
63
  hashedEthereumAddress: s,
64
64
  nullifiers: c.map((e) => e.getNullifier())
65
65
  });
@@ -1 +1 @@
1
- require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../data-structures/crypto-keys/keys.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/encodeTokenWithId.cjs`),i=require(`../../utils/encryptInputForEnclave.cjs`),a=require(`../../utils/solanaMint.utils.cjs`),o=require(`../../utils/serialize-utxos.utils.cjs`);let s=require(`ethers`);var c=async(r,i,c)=>{let l=i.getShieldedPrivateKey(),{privateKey:u,publicKey:d}=t.UserKeys.getEncryptionKeyPair(l),f=i.getSpendingKeyPair().pubSpendingBJJPoint,p=s.ethers.solidityPacked([`uint256`,`uint256`,`uint256`],[d,u,l]),{utxos:m,lastOutput:h,encryptedOutputs:g}=await c(r,s.ethers.getBytes(p));return{utxos:m.map(t=>{let i=t;if(e.isSolanaLike(r)){let e=a.normalizeSolanaMintAddress(t.mintAddress);if(!e)throw Error(`Invalid mint address`);i={...i,erc20TokenAddress:e.compressedAddress,mintAddress:e.mintBase58}}return new n.Utxo({...o.deserializeUtxoConstructorParams(i),nullifyingKey:l,spendingPublicKey:f})}),encryptedOutputs:g,lastOutput:h}},l=(t,n)=>{if(e.isSolanaLike(t)){let e=a.normalizeSolanaMintAddress(n);if(!e)throw Error(`Invalid mint address in enclave balance: ${n}`);return r.normalizeTokenAddress(t,e.mintBase58)}return r.normalizeTokenAddress(t,n.startsWith(`0x`)?n:s.ethers.toBeHex(BigInt(n),20))},u=async(e,t,n,r=!1,a)=>{let{keyCiphertext:o,inputCiphertext:c}=await i.makeEnclaveHandshakeAndEncryptUint8Array(s.ethers.getBytes(s.ethers.solidityPacked([`uint256`],[n]))),{preConfirmedBalances:u}=await e.getAPI().getBalancesEnclaveCall(t,o,c,r,a),d=new Map;return u.forEach(({erc20TokenAddress:e,amount:n})=>{d.set(l(t,e),BigInt(n))}),d};exports.getInputUtxosEnclave=c,exports.getRemoteManagedTokenBalances=u;
1
+ require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../data-structures/crypto-keys/keys.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/encodeTokenWithId.cjs`),i=require(`../../utils/encryptInputForEnclave.cjs`),a=require(`../../utils/solanaMint.utils.cjs`),o=require(`../../utils/serialize-utxos.utils.cjs`),s=require(`../../../error-handling/logger.cjs`);let c=require(`ethers`);var l=async(r,i,s)=>{let l=i.getShieldedPrivateKey(),{privateKey:u,publicKey:d}=t.UserKeys.getEncryptionKeyPair(l),f=i.getSpendingKeyPair().pubSpendingBJJPoint,p=c.ethers.solidityPacked([`uint256`,`uint256`,`uint256`],[d,u,l]),{utxos:m,lastOutput:h,encryptedOutputs:g}=await s(r,c.ethers.getBytes(p));return{utxos:m.map(t=>{let i=t;if(e.isSolanaLike(r)){let e=a.normalizeSolanaMintAddress(t.mintAddress);if(!e)throw Error(`Invalid mint address`);i={...i,erc20TokenAddress:e.compressedAddress,mintAddress:e.mintBase58}}return new n.Utxo({...o.deserializeUtxoConstructorParams(i),nullifyingKey:l,spendingPublicKey:f})}),encryptedOutputs:g,lastOutput:h}},u=(t,n)=>{if(e.isSolanaLike(t)){let e=a.normalizeSolanaMintAddress(n);if(!e)throw Error(`Invalid mint address in enclave balance: ${n}`);return r.normalizeTokenAddress(t,e.mintBase58)}return r.normalizeTokenAddress(t,n.startsWith(`0x`)?n:c.ethers.toBeHex(BigInt(n),20))},d=async(e,t,n,r=!1,a)=>{let o=await i.makeEnclaveHandshakeAndEncryptUint8Array(c.ethers.getBytes(c.ethers.solidityPacked([`uint256`],[n]))),{results:l}=await e.getAPI().getBalancesEnclaveCall(t,o,r,a),d=new Map;return l.forEach(({chainId:e,preConfirmedBalances:t,error:n})=>{if(n){s.Logger.error(`Enclave balance fetch failed for chainId ${e}:`,n);return}let r=new Map;t.forEach(({erc20TokenAddress:t,amount:n})=>{r.set(u(e,t),BigInt(n))}),d.set(e,r)}),d};exports.getInputUtxosEnclave=l,exports.getRemoteManagedTokenBalances=d;
@@ -7,4 +7,4 @@ export declare const getInputUtxosEnclave: (chainId: number, userKeys: UserKeys,
7
7
  encryptedOutputs: import('../../..').EncryptedOutputWithSign<boolean>[];
8
8
  lastOutput: string;
9
9
  }>;
10
- export declare const getRemoteManagedTokenBalances: (hinkal: IHinkal, chainId: number, shieldedPrivateKey: string, useBlockedUtxos?: boolean, hashedEthereumAddress?: string) => Promise<Map<string, bigint>>;
10
+ export declare const getRemoteManagedTokenBalances: (hinkal: IHinkal, chainIds: number[], shieldedPrivateKey: string, useBlockedUtxos?: boolean, hashedEthereumAddress?: string) => Promise<Map<number, Map<string, bigint>>>;
@@ -5,10 +5,11 @@ import { normalizeTokenAddress as r } from "../../utils/encodeTokenWithId.mjs";
5
5
  import { makeEnclaveHandshakeAndEncryptUint8Array as i } from "../../utils/encryptInputForEnclave.mjs";
6
6
  import { normalizeSolanaMintAddress as a } from "../../utils/solanaMint.utils.mjs";
7
7
  import { deserializeUtxoConstructorParams as o } from "../../utils/serialize-utxos.utils.mjs";
8
- import { ethers as s } from "ethers";
8
+ import { Logger as s } from "../../../error-handling/logger.mjs";
9
+ import { ethers as c } from "ethers";
9
10
  //#region libs/shared/common/src/functions/web3/events/getInputUtxosEnclave.ts
10
- var c = async (r, i, c) => {
11
- let l = i.getShieldedPrivateKey(), { privateKey: u, publicKey: d } = t.getEncryptionKeyPair(l), f = i.getSpendingKeyPair().pubSpendingBJJPoint, p = s.solidityPacked([
11
+ var l = async (r, i, s) => {
12
+ let l = i.getShieldedPrivateKey(), { privateKey: u, publicKey: d } = t.getEncryptionKeyPair(l), f = i.getSpendingKeyPair().pubSpendingBJJPoint, p = c.solidityPacked([
12
13
  "uint256",
13
14
  "uint256",
14
15
  "uint256"
@@ -16,7 +17,7 @@ var c = async (r, i, c) => {
16
17
  d,
17
18
  u,
18
19
  l
19
- ]), { utxos: m, lastOutput: h, encryptedOutputs: g } = await c(r, s.getBytes(p));
20
+ ]), { utxos: m, lastOutput: h, encryptedOutputs: g } = await s(r, c.getBytes(p));
20
21
  return {
21
22
  utxos: m.map((t) => {
22
23
  let i = t;
@@ -38,18 +39,25 @@ var c = async (r, i, c) => {
38
39
  encryptedOutputs: g,
39
40
  lastOutput: h
40
41
  };
41
- }, l = (t, n) => {
42
+ }, u = (t, n) => {
42
43
  if (e(t)) {
43
44
  let e = a(n);
44
45
  if (!e) throw Error(`Invalid mint address in enclave balance: ${n}`);
45
46
  return r(t, e.mintBase58);
46
47
  }
47
- return r(t, n.startsWith("0x") ? n : s.toBeHex(BigInt(n), 20));
48
- }, u = async (e, t, n, r = !1, a) => {
49
- let { keyCiphertext: o, inputCiphertext: c } = await i(s.getBytes(s.solidityPacked(["uint256"], [n]))), { preConfirmedBalances: u } = await e.getAPI().getBalancesEnclaveCall(t, o, c, r, a), d = /* @__PURE__ */ new Map();
50
- return u.forEach(({ erc20TokenAddress: e, amount: n }) => {
51
- d.set(l(t, e), BigInt(n));
48
+ return r(t, n.startsWith("0x") ? n : c.toBeHex(BigInt(n), 20));
49
+ }, d = async (e, t, n, r = !1, a) => {
50
+ let o = await i(c.getBytes(c.solidityPacked(["uint256"], [n]))), { results: l } = await e.getAPI().getBalancesEnclaveCall(t, o, r, a), d = /* @__PURE__ */ new Map();
51
+ return l.forEach(({ chainId: e, preConfirmedBalances: t, error: n }) => {
52
+ if (n) {
53
+ s.error(`Enclave balance fetch failed for chainId ${e}:`, n);
54
+ return;
55
+ }
56
+ let r = /* @__PURE__ */ new Map();
57
+ t.forEach(({ erc20TokenAddress: t, amount: n }) => {
58
+ r.set(u(e, t), BigInt(n));
59
+ }), d.set(e, r);
52
60
  }), d;
53
61
  };
54
62
  //#endregion
55
- export { c as getInputUtxosEnclave, u as getRemoteManagedTokenBalances };
63
+ export { l as getInputUtxosEnclave, d as getRemoteManagedTokenBalances };
@@ -1 +1 @@
1
- require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../data-structures/utxo/Utxo.cjs`),o=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxosEnclave.cjs`),u=require(`../../utils/addresses.cjs`),d=require(`../../utils/tron.utils.cjs`),f=require(`./getInputUtxoAndBalance.cjs`),p=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),m=require(`../../utils/map.utils.cjs`),h=require(`../../utils/mutexes.utils.cjs`),g=require(`../../utils/erc20tokenFunctions.cjs`);let _=require(`async-mutex`);var v=async(r,i,a,o,c,v=!1,y=!1,b=!1)=>m.getOrCreateMapValue(r.balanceFetchingMutexByChain,i,()=>new _.Mutex).runExclusive(async()=>h.getChainBalanceFetchingMutex(i).runShared(async()=>{if(r.generateProofRemotely){let n=await l.getRemoteManagedTokenBalances(r,i,a,b,b?u.hashEthereumAddress(t.isTronLike(i)?d.addressToHexFormat(c):c):void 0);y&&e.isExtension&&await p.privateTokensDB.fetchAndUpdatePrivateTokens([...n.keys()],i,c);let o=e.isExtension?await p.privateTokensDB.getPrivateTokens(i,c):await g.getErc20TokensForChainAPI(i),f=new Map;return o.forEach(e=>{f.set(e.erc20TokenAddress.toLowerCase(),{token:e,balance:n.get(s.normalizeTokenAddress(i,e.erc20TokenAddress))??0n,nfts:[]})}),f}let{inputUtxos:m}=b?await f.getInputUtxoAndBalanceOfStuckUtxos({hinkal:r,chainId:i,ethAddress:c,passedShieldedPrivateKey:a,resetCacheBefore:v}):await f.getInputUtxoAndBalance({hinkal:r,sliceIfMore6:!1,chainId:i,passedShieldedPrivateKey:a,passedShieldedPublicKey:o,ethAddress:c,resetCacheBefore:v});y&&e.isExtension&&await p.privateTokensDB.fetchAndUpdatePrivateTokens(m.map(e=>e.getTokenAddress(i)).filter(e=>e!==void 0),i,c);let h=(e.isExtension?await p.privateTokensDB.getPrivateTokens(i,c):await g.getErc20TokensForChainAPI(i)).map(e=>({token:e,balance:m.reduce((t,r)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,r.getTokenAddress(i))?t+r.amount:t},0n),timestamp:m.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(i),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),_=new Map;return h.forEach(e=>{_.set(e.token.erc20TokenAddress.toLowerCase(),e)}),_})),y=async(e,n,l,u,d=6,p=!1,m=!1)=>{let{userKeys:h}=e,_=h.getSpendingKeyPair().pubSpendingBJJPoint,v=[],y=[];if(l.length===0)return[];if(p){for(let e=0;e<l.length;e+=1){let r=t.isSolanaLike(n),i=r?l[e]:void 0,o=r?c.formatMintAddress(l[e]).compressedAddress:l[e];v.push(Array.from({length:d},()=>new a.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:i,nullifyingKey:h.getShieldedPrivateKey(),spendingPublicKey:_})))}return v}let b=await f.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:l,useBlockedUtxos:m,chainId:n}),x=0;for(let e=0;e<l.length;e+=1){let t=b.get(s.normalizeTokenAddress(n,l[e]))??[];if(!t)throw Error(`Missing utxos for token`);x=Math.max(t.length,x),y.push(t)}if(x===2)return y;for(let[e,s]of y.entries())if(s.length>d){let t=s.slice(0,d),a=t.reduce((e,t)=>e+t.amount,0n);if(u[e]<0n&&a<-u[e]){let t=await g.getErc20TokenFromAPI(n,l[e]);if(!t)throw Error(`Token not found`);let s=t.decimals===18?6:2,c=Number(i.getAmountWithPrecision(a,t,s));throw new o.ErrorWithAmount(c,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`)}v.push(t)}else if(s.length<=d){let r=[...s],i=d-s.length;for(;i>0;){--i;let o=t.isSolanaLike(n),s=o?l[e]:void 0,u=o?c.formatMintAddress(l[e]).compressedAddress:l[e];r.push(new a.Utxo({amount:0n,erc20TokenAddress:u,mintAddress:s,nullifyingKey:h.getShieldedPrivateKey(),spendingPublicKey:_}))}v.push(r)}return v};exports.addPaddingToUtxos=y,exports.getShieldedBalance=v;
1
+ require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../data-structures/utxo/Utxo.cjs`),o=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`../../../error-handling/logger.cjs`),u=require(`./getInputUtxosEnclave.cjs`),d=require(`../../utils/addresses.cjs`),f=require(`./getInputUtxoAndBalance.cjs`),p=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),m=require(`../../utils/map.utils.cjs`),h=require(`../../utils/mutexes.utils.cjs`),g=require(`../../utils/erc20tokenFunctions.cjs`);let _=require(`async-mutex`);var v=(e,t,n)=>m.getOrCreateMapValue(e.balanceFetchingMutexByChain,t,()=>new _.Mutex).runExclusive(()=>h.getChainBalanceFetchingMutex(t).runShared(n)),y=async(t,n,r,i,a)=>(r&&e.isExtension&&await p.privateTokensDB.fetchAndUpdatePrivateTokens(i,t,n),(e.isExtension?await p.privateTokensDB.getPrivateTokens(t,n):await g.getErc20TokensForChainAPI(t)).map(e=>({token:e,nfts:[],...a(e)}))),b=async(e,t,n,r,i)=>{let a=new Map;t.forEach((e,t)=>{m.getOrCreateMapValue(a,i?d.hashOwnerAddressForChain(t,e):``,()=>[]).push(t)});let o=new Map;await Promise.all([...a].map(async([t,r])=>{try{(await u.getRemoteManagedTokenBalances(e,r,n,i,t||void 0)).forEach((e,t)=>o.set(t,e))}catch(e){l.Logger.error(`Error fetching remote shielded balances for chainIds ${r.join(`, `)}:`,e)}}));let c=new Map;return await Promise.all([...o].map(async([n,i])=>{try{await v(e,n,async()=>{let e=await y(n,t.get(n),r,[...i.keys()],e=>({balance:i.get(s.normalizeTokenAddress(n,e.erc20TokenAddress))??0n}));c.set(n,e)})}catch(e){l.Logger.error(`Error fetching shielded balance for chainId ${n}:`,e)}})),c},x=async(e,t,r,i,a,o,s,c)=>{let{inputUtxos:l}=c?await f.getInputUtxoAndBalanceOfStuckUtxos({hinkal:e,chainId:t,ethAddress:a,passedShieldedPrivateKey:r,resetCacheBefore:o}):await f.getInputUtxoAndBalance({hinkal:e,sliceIfMore6:!1,chainId:t,passedShieldedPrivateKey:r,passedShieldedPublicKey:i,ethAddress:a,resetCacheBefore:o});return y(t,a,s,l.map(e=>e.getTokenAddress(t)).filter(e=>e!==void 0),e=>{let r=l.filter(r=>n.caseInsensitiveEqual(r.getTokenAddress(t),e.erc20TokenAddress));return{balance:r.reduce((e,t)=>e+t.amount,0n),timestamp:r[0]?.timeStamp}})},S=async(e,t,n,r,i=!1,a=!1,o=!1)=>{if(e.generateProofRemotely)return b(e,t,n,a,o);let s=new Map;return await Promise.all([...t].map(async([t,c])=>{try{let l=await v(e,t,()=>x(e,t,n,r,c,i,a,o));s.set(t,l)}catch(e){l.Logger.error(`Error fetching shielded balance for chainId ${t}:`,e)}})),s},C=(e,n,r,i,o)=>{let s=t.isSolanaLike(r),l=s?i:void 0,u=s?c.formatMintAddress(i).compressedAddress:i;return Array.from({length:o},()=>new a.Utxo({amount:0n,erc20TokenAddress:u,mintAddress:l,nullifyingKey:e.getShieldedPrivateKey(),spendingPublicKey:n}))},w=async(e,t,n,a,c=6,l=!1,u=!1,d)=>{let{userKeys:p}=e,m=p.getSpendingKeyPair().pubSpendingBJJPoint,h=[],_=[];if(n.length===0)return[];if(l){for(let e=0;e<n.length;e+=1)h.push(C(p,m,t,n[e],c));return h}let v=await f.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:n,useBlockedUtxos:u,chainId:t}),y=0;for(let e=0;e<n.length;e+=1){let r=v.get(s.normalizeTokenAddress(t,n[e]))??[];if(!r)throw Error(`Missing utxos for token`);let i=d?.[e]?C(p,m,t,n[e],2):r;y=Math.max(i.length,y),_.push(i)}if(y===2)return _;for(let[e,s]of _.entries())if(s.length>c){let l=s.slice(0,c),u=l.reduce((e,t)=>e+t.amount,0n);if(a[e]<0n&&u<-a[e]){let a=await g.getErc20TokenFromAPI(t,n[e]);if(!a)throw Error(`Token not found`);let s=a.decimals===18?6:2,c=Number(i.getAmountWithPrecision(u,a,s));throw new o.ErrorWithAmount(c,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${c} ${a.symbol}, including gas fees.`)}h.push(l)}else if(s.length<=c){let r=c-s.length;h.push([...s,...C(p,m,t,n[e],r)])}return h};exports.addPaddingToUtxos=w,exports.getShieldedBalances=S;
@@ -3,10 +3,10 @@ import { Utxo } from '../../../data-structures/utxo/Utxo';
3
3
  import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
4
4
  /**
5
5
  *
6
- * @param UserKeys to access user's encryption keys
7
- * @returns shielded balance
6
+ * @param ethAddressByChain address holding the shielded balance, per chain to read
7
+ * @returns shielded balances per chain, without the chains that failed
8
8
  */
9
- export declare const getShieldedBalance: (hinkal: IHinkal, chainId: number, passedShieldedPrivateKey: string, passedShieldedPublicKey: string, ethAddress: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean) => Promise<Map<string, TokenBalance>>;
9
+ export declare const getShieldedBalances: (hinkal: IHinkal, ethAddressByChain: Map<number, string>, passedShieldedPrivateKey: string, passedShieldedPublicKey: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean) => Promise<Map<number, TokenBalance[]>>;
10
10
  /**
11
11
  *
12
12
  * @param hinkal hinkal instance to get userKeys
@@ -15,4 +15,4 @@ export declare const getShieldedBalance: (hinkal: IHinkal, chainId: number, pass
15
15
  * @param maxInput to pad until maxInput number
16
16
  * @returns return padded UTXOs for every erc20 token
17
17
  */
18
- export declare const addPaddingToUtxos: (hinkal: IHinkal, chainId: number, erc20Addresses: string[], amountChanges: bigint[], maxInput?: number, forceEmptyUtxos?: boolean, useBlockedUtxos?: boolean) => Promise<Utxo[][]>;
18
+ export declare const addPaddingToUtxos: (hinkal: IHinkal, chainId: number, erc20Addresses: string[], amountChanges: bigint[], maxInput?: number, forceEmptyUtxos?: boolean, useBlockedUtxos?: boolean, onChainCreation?: boolean[]) => Promise<Utxo[][]>;
@@ -1,118 +1,129 @@
1
1
  import { isExtension as e } from "../../../constants/vite.constants.mjs";
2
- import { isSolanaLike as t, isTronLike as n } from "../../../constants/chains.constants.mjs";
3
- import { caseInsensitiveEqual as r } from "../../utils/caseInsensitive.utils.mjs";
4
- import { DIRECTLY_SHOW_MESSAGE_ERROR_CODES as i } from "../../../error-handling/error-codes.constants.mjs";
5
- import { getAmountWithPrecision as a } from "../etherFunctions.mjs";
6
- import { Utxo as o } from "../../../data-structures/utxo/Utxo.mjs";
7
- import { ErrorWithAmount as s } from "../../../error-handling/customErrors/ErrorWithAmount.mjs";
2
+ import { isSolanaLike as t } from "../../../constants/chains.constants.mjs";
3
+ import { caseInsensitiveEqual as n } from "../../utils/caseInsensitive.utils.mjs";
4
+ import { DIRECTLY_SHOW_MESSAGE_ERROR_CODES as r } from "../../../error-handling/error-codes.constants.mjs";
5
+ import { getAmountWithPrecision as i } from "../etherFunctions.mjs";
6
+ import { Utxo as a } from "../../../data-structures/utxo/Utxo.mjs";
7
+ import { ErrorWithAmount as o } from "../../../error-handling/customErrors/ErrorWithAmount.mjs";
8
8
  import "../../../error-handling/customErrors/index.mjs";
9
- import { normalizeTokenAddress as c } from "../../utils/encodeTokenWithId.mjs";
10
- import { formatMintAddress as l } from "../../utils/solanaMint.utils.mjs";
9
+ import { normalizeTokenAddress as s } from "../../utils/encodeTokenWithId.mjs";
10
+ import { formatMintAddress as c } from "../../utils/solanaMint.utils.mjs";
11
+ import { Logger as l } from "../../../error-handling/logger.mjs";
11
12
  import { getRemoteManagedTokenBalances as u } from "./getInputUtxosEnclave.mjs";
12
- import { hashEthereumAddress as d } from "../../utils/addresses.mjs";
13
- import { addressToHexFormat as f } from "../../utils/tron.utils.mjs";
14
- import { getInputUtxoAndBalance as p, getInputUtxoAndBalanceOfStuckUtxos as m, getInputUtxoAndBalancePerToken as h } from "./getInputUtxoAndBalance.mjs";
15
- import { privateTokensDB as g } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
16
- import { getOrCreateMapValue as _ } from "../../utils/map.utils.mjs";
17
- import { getChainBalanceFetchingMutex as v } from "../../utils/mutexes.utils.mjs";
18
- import { getErc20TokenFromAPI as y, getErc20TokensForChainAPI as b } from "../../utils/erc20tokenFunctions.mjs";
19
- import { Mutex as x } from "async-mutex";
13
+ import { hashOwnerAddressForChain as d } from "../../utils/addresses.mjs";
14
+ import { getInputUtxoAndBalance as f, getInputUtxoAndBalanceOfStuckUtxos as p, getInputUtxoAndBalancePerToken as m } from "./getInputUtxoAndBalance.mjs";
15
+ import { privateTokensDB as h } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
16
+ import { getOrCreateMapValue as g } from "../../utils/map.utils.mjs";
17
+ import { getChainBalanceFetchingMutex as _ } from "../../utils/mutexes.utils.mjs";
18
+ import { getErc20TokenFromAPI as v, getErc20TokensForChainAPI as y } from "../../utils/erc20tokenFunctions.mjs";
19
+ import { Mutex as b } from "async-mutex";
20
20
  //#region libs/shared/common/src/functions/web3/events/getShieldedBalance.ts
21
- var S = async (t, i, a, o, s, l = !1, h = !1, y = !1) => _(t.balanceFetchingMutexByChain, i, () => new x()).runExclusive(async () => v(i).runShared(async () => {
22
- if (t.generateProofRemotely) {
23
- let r = await u(t, i, a, y, y ? d(n(i) ? f(s) : s) : void 0);
24
- h && e && await g.fetchAndUpdatePrivateTokens([...r.keys()], i, s);
25
- let o = e ? await g.getPrivateTokens(i, s) : await b(i), l = /* @__PURE__ */ new Map();
26
- return o.forEach((e) => {
27
- l.set(e.erc20TokenAddress.toLowerCase(), {
28
- token: e,
29
- balance: r.get(c(i, e.erc20TokenAddress)) ?? 0n,
30
- nfts: []
21
+ var x = (e, t, n) => g(e.balanceFetchingMutexByChain, t, () => new b()).runExclusive(() => _(t).runShared(n)), S = async (t, n, r, i, a) => (r && e && await h.fetchAndUpdatePrivateTokens(i, t, n), (e ? await h.getPrivateTokens(t, n) : await y(t)).map((e) => ({
22
+ token: e,
23
+ nfts: [],
24
+ ...a(e)
25
+ }))), C = async (e, t, n, r, i) => {
26
+ let a = /* @__PURE__ */ new Map();
27
+ t.forEach((e, t) => {
28
+ g(a, i ? d(t, e) : "", () => []).push(t);
29
+ });
30
+ let o = /* @__PURE__ */ new Map();
31
+ await Promise.all([...a].map(async ([t, r]) => {
32
+ try {
33
+ (await u(e, r, n, i, t || void 0)).forEach((e, t) => o.set(t, e));
34
+ } catch (e) {
35
+ l.error(`Error fetching remote shielded balances for chainIds ${r.join(", ")}:`, e);
36
+ }
37
+ }));
38
+ let c = /* @__PURE__ */ new Map();
39
+ return await Promise.all([...o].map(async ([n, i]) => {
40
+ try {
41
+ await x(e, n, async () => {
42
+ let e = await S(n, t.get(n), r, [...i.keys()], (e) => ({ balance: i.get(s(n, e.erc20TokenAddress)) ?? 0n }));
43
+ c.set(n, e);
31
44
  });
32
- }), l;
33
- }
34
- let { inputUtxos: _ } = y ? await m({
35
- hinkal: t,
36
- chainId: i,
37
- ethAddress: s,
38
- passedShieldedPrivateKey: a,
39
- resetCacheBefore: l
40
- }) : await p({
41
- hinkal: t,
45
+ } catch (e) {
46
+ l.error(`Error fetching shielded balance for chainId ${n}:`, e);
47
+ }
48
+ })), c;
49
+ }, w = async (e, t, r, i, a, o, s, c) => {
50
+ let { inputUtxos: l } = c ? await p({
51
+ hinkal: e,
52
+ chainId: t,
53
+ ethAddress: a,
54
+ passedShieldedPrivateKey: r,
55
+ resetCacheBefore: o
56
+ }) : await f({
57
+ hinkal: e,
42
58
  sliceIfMore6: !1,
43
- chainId: i,
44
- passedShieldedPrivateKey: a,
45
- passedShieldedPublicKey: o,
46
- ethAddress: s,
47
- resetCacheBefore: l
59
+ chainId: t,
60
+ passedShieldedPrivateKey: r,
61
+ passedShieldedPublicKey: i,
62
+ ethAddress: a,
63
+ resetCacheBefore: o
48
64
  });
49
- h && e && await g.fetchAndUpdatePrivateTokens(_.map((e) => e.getTokenAddress(i)).filter((e) => e !== void 0), i, s);
50
- let v = (e ? await g.getPrivateTokens(i, s) : await b(i)).map((e) => ({
51
- token: e,
52
- balance: _.reduce((t, n) => {
53
- let a = e.erc20TokenAddress;
54
- return r(a, n.getTokenAddress(i)) ? t + n.amount : t;
55
- }, 0n),
56
- timestamp: _.filter((t) => r(t.getTokenAddress(i), e.erc20TokenAddress))[0]?.timeStamp,
57
- nfts: []
58
- })), x = /* @__PURE__ */ new Map();
59
- return v.forEach((e) => {
60
- x.set(e.token.erc20TokenAddress.toLowerCase(), e);
61
- }), x;
62
- })), C = async (e, n, r, u, d = 6, f = !1, p = !1) => {
63
- let { userKeys: m } = e, g = m.getSpendingKeyPair().pubSpendingBJJPoint, _ = [], v = [];
64
- if (r.length === 0) return [];
65
- if (f) {
66
- for (let e = 0; e < r.length; e += 1) {
67
- let i = t(n), a = i ? r[e] : void 0, s = i ? l(r[e]).compressedAddress : r[e];
68
- _.push(Array.from({ length: d }, () => new o({
69
- amount: 0n,
70
- erc20TokenAddress: s,
71
- mintAddress: a,
72
- nullifyingKey: m.getShieldedPrivateKey(),
73
- spendingPublicKey: g
74
- })));
65
+ return S(t, a, s, l.map((e) => e.getTokenAddress(t)).filter((e) => e !== void 0), (e) => {
66
+ let r = l.filter((r) => n(r.getTokenAddress(t), e.erc20TokenAddress));
67
+ return {
68
+ balance: r.reduce((e, t) => e + t.amount, 0n),
69
+ timestamp: r[0]?.timeStamp
70
+ };
71
+ });
72
+ }, T = async (e, t, n, r, i = !1, a = !1, o = !1) => {
73
+ if (e.generateProofRemotely) return C(e, t, n, a, o);
74
+ let s = /* @__PURE__ */ new Map();
75
+ return await Promise.all([...t].map(async ([t, c]) => {
76
+ try {
77
+ let l = await x(e, t, () => w(e, t, n, r, c, i, a, o));
78
+ s.set(t, l);
79
+ } catch (e) {
80
+ l.error(`Error fetching shielded balance for chainId ${t}:`, e);
75
81
  }
76
- return _;
82
+ })), s;
83
+ }, E = (e, n, r, i, o) => {
84
+ let s = t(r), l = s ? i : void 0, u = s ? c(i).compressedAddress : i;
85
+ return Array.from({ length: o }, () => new a({
86
+ amount: 0n,
87
+ erc20TokenAddress: u,
88
+ mintAddress: l,
89
+ nullifyingKey: e.getShieldedPrivateKey(),
90
+ spendingPublicKey: n
91
+ }));
92
+ }, D = async (e, t, n, a, c = 6, l = !1, u = !1, d) => {
93
+ let { userKeys: f } = e, p = f.getSpendingKeyPair().pubSpendingBJJPoint, h = [], g = [];
94
+ if (n.length === 0) return [];
95
+ if (l) {
96
+ for (let e = 0; e < n.length; e += 1) h.push(E(f, p, t, n[e], c));
97
+ return h;
77
98
  }
78
- let b = await h({
99
+ let _ = await m({
79
100
  hinkal: e,
80
101
  sliceIfMore6: !1,
81
- ensuredTokensWithId: r,
82
- useBlockedUtxos: p,
83
- chainId: n
84
- }), x = 0;
85
- for (let e = 0; e < r.length; e += 1) {
86
- let t = b.get(c(n, r[e])) ?? [];
87
- if (!t) throw Error("Missing utxos for token");
88
- x = Math.max(t.length, x), v.push(t);
102
+ ensuredTokensWithId: n,
103
+ useBlockedUtxos: u,
104
+ chainId: t
105
+ }), y = 0;
106
+ for (let e = 0; e < n.length; e += 1) {
107
+ let r = _.get(s(t, n[e])) ?? [];
108
+ if (!r) throw Error("Missing utxos for token");
109
+ let i = d?.[e] ? E(f, p, t, n[e], 2) : r;
110
+ y = Math.max(i.length, y), g.push(i);
89
111
  }
90
- if (x === 2) return v;
91
- for (let [e, c] of v.entries()) if (c.length > d) {
92
- let t = c.slice(0, d), o = t.reduce((e, t) => e + t.amount, 0n);
93
- if (u[e] < 0n && o < -u[e]) {
94
- let t = await y(n, r[e]);
95
- if (!t) throw Error("Token not found");
96
- let c = t.decimals === 18 ? 6 : 2, l = Number(a(o, t, c));
97
- throw new s(l, `${i.UTXO_LIMITATIONS}. Please try again with ${l} ${t.symbol}, including gas fees.`);
98
- }
99
- _.push(t);
100
- } else if (c.length <= d) {
101
- let i = [...c], a = d - c.length;
102
- for (; a > 0;) {
103
- --a;
104
- let s = t(n), c = s ? r[e] : void 0, u = s ? l(r[e]).compressedAddress : r[e];
105
- i.push(new o({
106
- amount: 0n,
107
- erc20TokenAddress: u,
108
- mintAddress: c,
109
- nullifyingKey: m.getShieldedPrivateKey(),
110
- spendingPublicKey: g
111
- }));
112
+ if (y === 2) return g;
113
+ for (let [e, s] of g.entries()) if (s.length > c) {
114
+ let l = s.slice(0, c), u = l.reduce((e, t) => e + t.amount, 0n);
115
+ if (a[e] < 0n && u < -a[e]) {
116
+ let a = await v(t, n[e]);
117
+ if (!a) throw Error("Token not found");
118
+ let s = a.decimals === 18 ? 6 : 2, c = Number(i(u, a, s));
119
+ throw new o(c, `${r.UTXO_LIMITATIONS}. Please try again with ${c} ${a.symbol}, including gas fees.`);
112
120
  }
113
- _.push(i);
121
+ h.push(l);
122
+ } else if (s.length <= c) {
123
+ let r = c - s.length;
124
+ h.push([...s, ...E(f, p, t, n[e], r)]);
114
125
  }
115
- return _;
126
+ return h;
116
127
  };
117
128
  //#endregion
118
- export { C as addPaddingToUtxos, S as getShieldedBalance };
129
+ export { D as addPaddingToUtxos, T as getShieldedBalances };
@@ -1 +1 @@
1
- const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../constants/protocol.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../../utils/tron.utils.cjs`),a=require(`../../../error-handling/logger.cjs`),o=require(`../../../externalABIs/index.cjs`),s=require(`./waitForErc20Approvals.cjs`),c=require(`../../utils/tronSimulation.utils.cjs`);var l=async(l,u,d,f,p,m,h,g,_,v=!0,y)=>{let b=Array.isArray(d)?d:[d],x=Array.isArray(f)?f:[f];if(b.length!==x.length)throw Error(`token and amount length mismatch`);let S=l.getTronWeb(),C=await l.getEthereumAddressByChain(u),{hinkalAddress:w,hinkalABI:T}=e.networkRegistry[u].contractData,E=S.contract(T,i.evmHexToTronBase58Address(w)),D=g??E,O=_??E;if(!D.address)throw Error(`contractForApproval address not set`);if(!O.address)throw Error(`contractForTransaction address not set`);let k=x.findIndex(({erc20TokenAddress:e})=>n.caseInsensitiveEqual(e,t.zeroAddress)),A=k===-1?0n:b[k],j=A>0n?A:0n;if(x.some(({erc20TokenAddress:e},r)=>!n.caseInsensitiveEqual(e,t.zeroAddress)&&b[r]>0n)){let e=D.address;if(!e)throw Error(`token approval spender not set`);let r=[];for(let a=0;a<x.length;a+=1){let s=x[a],c=b[a];if(c>0n&&!n.caseInsensitiveEqual(s.erc20TokenAddress,t.zeroAddress)){let n=i.evmHexToTronBase58Address(s.erc20TokenAddress),a=await S.contract(o.ERC20ABI,n).allowance(C,e).call({from:C});if(BigInt(String(a))<c){let{transaction:i}=await S.transactionBuilder.triggerSmartContract(n,`approve(address,uint256)`,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[{type:`address`,value:e},{type:`uint256`,value:c.toString()}],C),a=await S.trx.sign(i),o=await S.trx.sendRawTransaction(a);if(!o.result){let e=o.code??`UNKNOWN`,t=o.message?Buffer.from(o.message,`hex`).toString():`no message`;throw Error(`Tron token approval failed: ${e} - ${t}`)}r.push({tokenAddress:n,requiredAmount:c})}}}r.length>0&&await s.waitForTronErc20Approvals(S,C,e,r)}let{a:M,b:N,c:P}=i.parseZkCalldata(p),F=y??await i.reorderZkCallData(!0,p,h,m,u,!1);if(!F)throw Error(`Tron proof signature not found`);let I=[F.v,F.r,F.s],L=[h.tokenNumber,h.nullifierAmount,h.outputAmount],R=i.circomDataToArray(m);if(v){await c.simulateTronTransaction(u,O.address,`transact`,O.abi,[I,M,N,P,L,R],C,j);let e=BigInt(await S.trx.getBalance(C)),n=BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN);try{let e=i.createTronCallData(O.abi,`transact`,[I,M,N,P,L,R]);n=await i.estimateTronFeeSunWithPadding(S,u,O.address,C,e,j)}catch(e){a.Logger.error(`Error estimating Tron transact fee`,e)}if(e<j+n)throw Error(r.insufficientResourcesErrorCodes.INSUFFICIENT_TRON_BALANCE_FOR_FEE)}let z=await O.transact(I,M,N,P,L,R).send({feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:Number(j)}),B=typeof z==`string`?z:z?.txid??z?.transaction?.txID??z?.transaction?.txid;if(!B)throw Error(`Tron transact failed (missing txid)`);return B},u=async(r,a,o,s,c,l,u,d)=>{let f=Array.isArray(o)?o:[o],p=Array.isArray(s)?s:[s];if(f.length!==p.length)throw Error(`token and amount length mismatch`);let{hinkalAddress:m,hinkalABI:h}=e.networkRegistry[a].contractData;if(!m||!h)throw Error(`Missing Tron contract data (hinkalAddress/hinkalABI)`);let g=r.getTronWeb(),_=await r.getEthereumAddressByChain(a),v=p.findIndex(({erc20TokenAddress:e})=>n.caseInsensitiveEqual(e,t.zeroAddress)),y=v===-1?0n:f[v],b=y>0n?y:0n,{a:x,b:S,c:C}=i.parseZkCalldata(c),w=d??await i.reorderZkCallData(!0,c,u,l,a,!1);if(!w)throw Error(`Tron proof signature not found`);let T=i.createTronCallData(h,`transact`,[[w.v,w.r,w.s],x,S,C,[u.tokenNumber,u.nullifierAmount,u.outputAmount],i.circomDataToArray(l)]),{transaction:E}=await g.transactionBuilder.triggerSmartContract(i.evmHexToTronBase58Address(m),``,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:Number(b),input:T},[],_);return E};exports.buildTronUnsignedTransactTransaction=u,exports.transactCallDirectTron=l;
1
+ const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../constants/protocol.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../../../error-handling/logger.cjs`),a=require(`../../utils/tron.utils.cjs`),o=require(`../../../externalABIs/index.cjs`),s=require(`./waitForErc20Approvals.cjs`),c=require(`../../utils/tronSimulation.utils.cjs`);var l=async(l,u,d,f,p,m,h,g,_,v=!0,y)=>{let b=Array.isArray(d)?d:[d],x=Array.isArray(f)?f:[f];if(b.length!==x.length)throw Error(`token and amount length mismatch`);let S=l.getTronWeb(),C=await l.getEthereumAddressByChain(u),{hinkalAddress:w,hinkalABI:T}=e.networkRegistry[u].contractData,E=S.contract(T,a.evmHexToTronBase58Address(w)),D=g??E,O=_??E;if(!D.address)throw Error(`contractForApproval address not set`);if(!O.address)throw Error(`contractForTransaction address not set`);let k=x.findIndex(({erc20TokenAddress:e})=>n.caseInsensitiveEqual(e,t.zeroAddress)),A=k===-1?0n:b[k],j=A>0n?A:0n;if(x.some(({erc20TokenAddress:e},r)=>!n.caseInsensitiveEqual(e,t.zeroAddress)&&b[r]>0n)){let e=D.address;if(!e)throw Error(`token approval spender not set`);let r=[];for(let i=0;i<x.length;i+=1){let s=x[i],c=b[i];if(c>0n&&!n.caseInsensitiveEqual(s.erc20TokenAddress,t.zeroAddress)){let n=a.evmHexToTronBase58Address(s.erc20TokenAddress),i=await S.contract(o.ERC20ABI,n).allowance(C,e).call({from:C});if(BigInt(String(i))<c){let{transaction:i}=await S.transactionBuilder.triggerSmartContract(n,`approve(address,uint256)`,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[{type:`address`,value:e},{type:`uint256`,value:c.toString()}],C),a=await S.trx.sign(i),o=await S.trx.sendRawTransaction(a);if(!o.result){let e=o.code??`UNKNOWN`,t=o.message?Buffer.from(o.message,`hex`).toString():`no message`;throw Error(`Tron token approval failed: ${e} - ${t}`)}r.push({tokenAddress:n,requiredAmount:c})}}}r.length>0&&await s.waitForTronErc20Approvals(S,C,e,r)}let{a:M,b:N,c:P}=a.parseZkCalldata(p),F=y??await a.reorderZkCallData(!0,p,h,m,u,!1);if(!F)throw Error(`Tron proof signature not found`);let I=[F.v,F.r,F.s],L=[h.tokenNumber,h.nullifierAmount,h.outputAmount],R=a.circomDataToArray(m);if(v){await c.simulateTronTransaction(u,O.address,`transact`,O.abi,[I,M,N,P,L,R],C,j);let e=BigInt(await S.trx.getBalance(C)),n=BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN);try{let e=a.createTronCallData(O.abi,`transact`,[I,M,N,P,L,R]);n=await a.estimateTronFeeSunWithPadding(S,u,O.address,C,e,j)}catch(e){i.Logger.error(`Error estimating Tron transact fee`,e)}if(e<j+n)throw Error(r.insufficientResourcesErrorCodes.INSUFFICIENT_TRON_BALANCE_FOR_FEE)}let z=await O.transact(I,M,N,P,L,R).send({feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:Number(j)}),B=typeof z==`string`?z:z?.txid??z?.transaction?.txID??z?.transaction?.txid;if(!B)throw Error(`Tron transact failed (missing txid)`);return B},u=async(r,i,o,s,c,l,u,d)=>{let f=Array.isArray(o)?o:[o],p=Array.isArray(s)?s:[s];if(f.length!==p.length)throw Error(`token and amount length mismatch`);let{hinkalAddress:m,hinkalABI:h}=e.networkRegistry[i].contractData;if(!m||!h)throw Error(`Missing Tron contract data (hinkalAddress/hinkalABI)`);let g=r.getTronWeb(),_=await r.getEthereumAddressByChain(i),v=p.findIndex(({erc20TokenAddress:e})=>n.caseInsensitiveEqual(e,t.zeroAddress)),y=v===-1?0n:f[v],b=y>0n?y:0n,{a:x,b:S,c:C}=a.parseZkCalldata(c),w=d??await a.reorderZkCallData(!0,c,u,l,i,!1);if(!w)throw Error(`Tron proof signature not found`);let T=a.createTronCallData(h,`transact`,[[w.v,w.r,w.s],x,S,C,[u.tokenNumber,u.nullifierAmount,u.outputAmount],a.circomDataToArray(l)]),{transaction:E}=await g.transactionBuilder.triggerSmartContract(a.evmHexToTronBase58Address(m),``,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:Number(b),input:T},[],_);return E};exports.buildTronUnsignedTransactTransaction=u,exports.transactCallDirectTron=l;