@gurge/sdk 0.3.13 → 0.3.15

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 (321) hide show
  1. package/README.md +184 -32
  2. package/common/src/API/API.cjs +1 -1
  3. package/common/src/API/API.d.ts +0 -5
  4. package/common/src/API/API.mjs +114 -119
  5. package/common/src/API/TokenCallsCachedHelper.cjs +1 -0
  6. package/common/src/API/TokenCallsCachedHelper.d.ts +15 -0
  7. package/common/src/API/TokenCallsCachedHelper.mjs +62 -0
  8. package/common/src/API/callLifiAPI.cjs +1 -1
  9. package/common/src/API/callLifiAPI.mjs +2 -7
  10. package/common/src/API/enclaveUtxoCalls.cjs +1 -1
  11. package/common/src/API/enclaveUtxoCalls.mjs +6 -7
  12. package/common/src/API/getServerURL.cjs +1 -1
  13. package/common/src/API/getServerURL.mjs +2 -2
  14. package/common/src/API/scheduled-transactions-calls.cjs +1 -1
  15. package/common/src/API/scheduled-transactions-calls.mjs +3 -3
  16. package/common/src/API/token-calls.cjs +1 -1
  17. package/common/src/API/token-calls.d.ts +1 -1
  18. package/common/src/API/token-calls.mjs +3 -13
  19. package/common/src/constants/chains.constants.cjs +1 -1
  20. package/common/src/constants/chains.constants.d.ts +1 -0
  21. package/common/src/constants/chains.constants.mjs +3 -2
  22. package/common/src/constants/deploy-data/mergeDeployData.cjs +1 -1
  23. package/common/src/constants/deploy-data/mergeDeployData.mjs +11 -10
  24. package/common/src/constants/deploy-data/shared-deploy-data-tron.json.cjs +1 -1
  25. package/common/src/constants/deploy-data/shared-deploy-data-tron.json.mjs +60 -3517
  26. package/common/src/constants/events.constants.cjs +1 -1
  27. package/common/src/constants/events.constants.mjs +3 -1
  28. package/common/src/constants/index.cjs +1 -1
  29. package/common/src/constants/index.d.ts +0 -3
  30. package/common/src/constants/index.mjs +0 -3
  31. package/common/src/constants/lifi.constants.cjs +1 -1
  32. package/common/src/constants/lifi.constants.mjs +3 -6
  33. package/common/src/constants/mediaUrls.constants.d.ts +0 -1
  34. package/common/src/constants/rewards.constants.d.ts +0 -2
  35. package/common/src/constants/server.constants.cjs +1 -1
  36. package/common/src/constants/server.constants.d.ts +1 -5
  37. package/common/src/constants/server.constants.mjs +3 -8
  38. package/common/src/constants/vite.constants.cjs +1 -1
  39. package/common/src/constants/vite.constants.d.ts +1 -0
  40. package/common/src/constants/vite.constants.mjs +3 -3
  41. package/common/src/crypto/BabyJubRN.cjs +1 -0
  42. package/common/src/crypto/BabyJubRN.d.ts +18 -0
  43. package/common/src/crypto/BabyJubRN.mjs +33 -0
  44. package/common/src/crypto/babyJub.cjs +1 -1
  45. package/common/src/crypto/babyJub.mjs +7 -5
  46. package/common/src/crypto/poseidon.cjs +1 -1
  47. package/common/src/crypto/poseidon.mjs +22 -12
  48. package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
  49. package/common/src/data-structures/Hinkal/Hinkal.d.ts +10 -6
  50. package/common/src/data-structures/Hinkal/Hinkal.mjs +104 -113
  51. package/common/src/data-structures/Hinkal/IHinkal.d.ts +9 -5
  52. package/common/src/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
  53. package/common/src/data-structures/Hinkal/handleAutoDepositBack.mjs +37 -37
  54. package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
  55. package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.d.ts +2 -2
  56. package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.mjs +8 -5
  57. package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
  58. package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.d.ts +2 -2
  59. package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +4 -1
  60. package/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.cjs +1 -1
  61. package/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.mjs +1 -1
  62. package/common/src/data-structures/Hinkal/hinkalProoflessDeposit.cjs +1 -1
  63. package/common/src/data-structures/Hinkal/hinkalProoflessDeposit.mjs +4 -4
  64. package/common/src/data-structures/Hinkal/hinkalProoflessDeposit.utils.cjs +1 -1
  65. package/common/src/data-structures/Hinkal/hinkalProoflessDeposit.utils.mjs +3 -3
  66. package/common/src/data-structures/Hinkal/hinkalProoflessDepositViaWrapper.cjs +1 -1
  67. package/common/src/data-structures/Hinkal/hinkalProoflessDepositViaWrapper.mjs +15 -15
  68. package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
  69. package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.d.ts +2 -2
  70. package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +4 -1
  71. package/common/src/data-structures/Hinkal/index.d.ts +0 -1
  72. package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.cjs +1 -1
  73. package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.mjs +1 -1
  74. package/common/src/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
  75. package/common/src/data-structures/Hinkal/resetMerkleTrees.mjs +29 -31
  76. package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.cjs +1 -1
  77. package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.mjs +7 -6
  78. package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.cjs +1 -1
  79. package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.mjs +18 -18
  80. package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
  81. package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.mjs +43 -43
  82. package/common/src/data-structures/TokenDBs/PublicTokensDB.cjs +1 -1
  83. package/common/src/data-structures/TokenDBs/PublicTokensDB.mjs +23 -20
  84. package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.cjs +1 -0
  85. package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.d.ts +9 -0
  86. package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.mjs +41 -0
  87. package/common/src/data-structures/TokenDBs/TronPublicTokensDB.cjs +1 -0
  88. package/common/src/data-structures/TokenDBs/TronPublicTokensDB.d.ts +9 -0
  89. package/common/src/data-structures/TokenDBs/TronPublicTokensDB.mjs +47 -0
  90. package/common/src/data-structures/TokenDBs/index.cjs +1 -1
  91. package/common/src/data-structures/TokenDBs/index.d.ts +2 -0
  92. package/common/src/data-structures/TokenDBs/index.mjs +2 -0
  93. package/common/src/data-structures/event-service/evm/BlockchainEventEmitter.d.ts +3 -3
  94. package/common/src/data-structures/event-service/evm/ClientBlockchainEventEmitter.d.ts +2 -2
  95. package/common/src/data-structures/event-service/solana/ClientSolanaBlockchainEventEmitter.d.ts +2 -2
  96. package/common/src/data-structures/event-service/solana/SolanaBlockchainEventEmitter.d.ts +3 -3
  97. package/common/src/data-structures/index.d.ts +1 -0
  98. package/common/src/data-structures/private-balances/BalanceChangedHandler.cjs +1 -0
  99. package/common/src/data-structures/private-balances/BalanceChangedHandler.d.ts +9 -0
  100. package/common/src/data-structures/private-balances/BalanceChangedHandler.mjs +12 -0
  101. package/common/src/data-structures/private-balances/HinkalPrivateBalanceController.cjs +1 -0
  102. package/common/src/data-structures/{Hinkal → private-balances}/HinkalPrivateBalanceController.d.ts +4 -2
  103. package/common/src/data-structures/{Hinkal → private-balances}/HinkalPrivateBalanceController.mjs +34 -90
  104. package/common/src/data-structures/private-balances/index.cjs +1 -0
  105. package/common/src/data-structures/private-balances/index.d.ts +3 -0
  106. package/common/src/data-structures/private-balances/index.mjs +3 -0
  107. package/common/src/data-structures/private-balances/privateBalancesReducer.cjs +1 -0
  108. package/common/src/data-structures/private-balances/privateBalancesReducer.d.ts +2 -0
  109. package/common/src/data-structures/private-balances/privateBalancesReducer.mjs +73 -0
  110. package/common/src/data-structures/token-price-fetcher/TokenChecker.cjs +1 -1
  111. package/common/src/data-structures/token-price-fetcher/TokenChecker.mjs +5 -5
  112. package/common/src/error-handling/error-codes.constants.cjs +1 -1
  113. package/common/src/error-handling/error-codes.constants.d.ts +2 -5
  114. package/common/src/error-handling/error-codes.constants.mjs +3 -6
  115. package/common/src/externalABIs/index.cjs +1 -1
  116. package/common/src/externalABIs/index.d.ts +1 -36
  117. package/common/src/externalABIs/index.mjs +3 -5
  118. package/common/src/functions/index.cjs +1 -1
  119. package/common/src/functions/index.d.ts +0 -1
  120. package/common/src/functions/index.mjs +4 -5
  121. package/common/src/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
  122. package/common/src/functions/pre-transaction/buildCommitmentValidationData.mjs +37 -36
  123. package/common/src/functions/pre-transaction/merge-with-fee-structure-emporium.cjs +1 -1
  124. package/common/src/functions/pre-transaction/merge-with-fee-structure-emporium.mjs +4 -4
  125. package/common/src/functions/pre-transaction/sendV0Transaction.cjs +2 -2
  126. package/common/src/functions/pre-transaction/sendV0Transaction.mjs +54 -42
  127. package/common/src/functions/private-wallet/emporium.helpers.cjs +1 -1
  128. package/common/src/functions/private-wallet/emporium.helpers.mjs +17 -17
  129. package/common/src/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
  130. package/common/src/functions/private-wallet/emporium.swap.helpers.mjs +16 -16
  131. package/common/src/functions/snarkjs/common.snarkjs.cjs +1 -1
  132. package/common/src/functions/snarkjs/common.snarkjs.d.ts +9 -1
  133. package/common/src/functions/snarkjs/common.snarkjs.mjs +13 -9
  134. package/common/src/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.cjs +1 -1
  135. package/common/src/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.d.ts +2 -3
  136. package/common/src/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.mjs +49 -32
  137. package/common/src/functions/utils/abi.utils.cjs +1 -0
  138. package/common/src/functions/utils/abi.utils.d.ts +3 -0
  139. package/common/src/functions/utils/abi.utils.mjs +5 -0
  140. package/common/src/functions/utils/bigint-math.utils.cjs +1 -0
  141. package/common/src/functions/utils/bigint-math.utils.d.ts +2 -0
  142. package/common/src/functions/utils/bigint-math.utils.mjs +12 -0
  143. package/common/src/functions/utils/dispatchBalanceRefreshes.cjs +1 -1
  144. package/common/src/functions/utils/dispatchBalanceRefreshes.mjs +1 -1
  145. package/common/src/functions/utils/enclaveHandshakeService.cjs +1 -0
  146. package/common/src/functions/utils/enclaveHandshakeService.d.ts +10 -0
  147. package/common/src/functions/utils/enclaveHandshakeService.mjs +22 -0
  148. package/common/src/functions/utils/encryptInputForEnclave.cjs +1 -1
  149. package/common/src/functions/utils/encryptInputForEnclave.mjs +23 -25
  150. package/common/src/functions/utils/erc20tokenFunctions.cjs +1 -1
  151. package/common/src/functions/utils/erc20tokenFunctions.d.ts +4 -1
  152. package/common/src/functions/utils/erc20tokenFunctions.mjs +28 -12
  153. package/common/src/functions/utils/evmNetworkFunctions.cjs +1 -1
  154. package/common/src/functions/utils/evmNetworkFunctions.d.ts +1 -0
  155. package/common/src/functions/utils/evmNetworkFunctions.mjs +4 -0
  156. package/common/src/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
  157. package/common/src/functions/utils/getUtxosFromReceipt.utils.mjs +10 -10
  158. package/common/src/functions/utils/index.cjs +1 -1
  159. package/common/src/functions/utils/index.d.ts +4 -0
  160. package/common/src/functions/utils/index.mjs +4 -0
  161. package/common/src/functions/utils/map.utils.cjs +1 -0
  162. package/common/src/functions/utils/map.utils.d.ts +1 -0
  163. package/common/src/functions/utils/map.utils.mjs +9 -0
  164. package/common/src/functions/utils/mutexes.utils.cjs +1 -1
  165. package/common/src/functions/utils/mutexes.utils.d.ts +2 -2
  166. package/common/src/functions/utils/mutexes.utils.mjs +4 -3
  167. package/common/src/functions/utils/process.utils.cjs +1 -1
  168. package/common/src/functions/utils/process.utils.d.ts +1 -0
  169. package/common/src/functions/utils/process.utils.mjs +7 -2
  170. package/common/src/functions/utils/tron.utils.cjs +1 -1
  171. package/common/src/functions/utils/tron.utils.d.ts +1 -0
  172. package/common/src/functions/utils/tron.utils.mjs +1 -1
  173. package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
  174. package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +26 -26
  175. package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
  176. package/common/src/functions/web3/events/getShieldedBalance.mjs +29 -11
  177. package/common/src/functions/web3/events/index.cjs +1 -1
  178. package/common/src/functions/web3/events/index.d.ts +0 -1
  179. package/common/src/functions/web3/events/index.mjs +0 -1
  180. package/common/src/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
  181. package/common/src/functions/web3/functionCalls/transactCallDirect.mjs +4 -4
  182. package/common/src/functions/web3/functionCalls/waitForErc20Approvals.cjs +1 -1
  183. package/common/src/functions/web3/functionCalls/waitForErc20Approvals.mjs +10 -10
  184. package/common/src/functions/web3/index.cjs +1 -1
  185. package/common/src/functions/web3/index.mjs +0 -1
  186. package/common/src/functions/web3/lifiAPI.cjs +1 -1
  187. package/common/src/functions/web3/lifiAPI.mjs +7 -38
  188. package/common/src/functions/web3/oneInchAPI.cjs +1 -1
  189. package/common/src/functions/web3/oneInchAPI.mjs +10 -10
  190. package/common/src/functions/web3/uniswapAPI.cjs +1 -1
  191. package/common/src/functions/web3/uniswapAPI.mjs +16 -16
  192. package/common/src/mutexes/chainBalanceRwLock.cjs +1 -0
  193. package/common/src/mutexes/chainBalanceRwLock.d.ts +18 -0
  194. package/common/src/mutexes/chainBalanceRwLock.mjs +31 -0
  195. package/common/src/mutexes/index.d.ts +1 -0
  196. package/common/src/types/cache.types.cjs +1 -1
  197. package/common/src/types/cache.types.d.ts +2 -0
  198. package/common/src/types/cache.types.mjs +1 -1
  199. package/common/src/types/commitments.types.d.ts +0 -10
  200. package/common/src/types/hinkal.types.cjs +1 -1
  201. package/common/src/types/hinkal.types.d.ts +4 -7
  202. package/common/src/types/hinkal.types.mjs +1 -1
  203. package/common/src/types/index.cjs +1 -1
  204. package/common/src/types/index.d.ts +0 -1
  205. package/common/src/types/index.mjs +1 -2
  206. package/common/src/types/new-rewards.type.cjs +1 -1
  207. package/common/src/types/new-rewards.type.d.ts +0 -1
  208. package/common/src/types/new-rewards.type.mjs +1 -1
  209. package/common/src/types/scheduled-transactions.types.d.ts +5 -0
  210. package/common/src/webworker/logError-BTCYh_YM.js +2 -0
  211. package/common/src/webworker/package.json +34 -4
  212. package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
  213. package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
  214. package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
  215. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
  216. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
  217. package/common/src/webworker/utxoWorkerNode.cjs +1 -1
  218. package/common/src/webworker/viteWorkerURL.constant.cjs +4 -4
  219. package/common/src/webworker/viteWorkerURL.constant.mjs +4 -4
  220. package/common/src/webworker/workerFactory.cjs +1 -1
  221. package/common/src/webworker/workerFactory.d.ts +1 -0
  222. package/common/src/webworker/workerFactory.mjs +3 -2
  223. package/common/src/webworker/workerProxy-DPeuP2Mg.js +1 -0
  224. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
  225. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
  226. package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
  227. package/functions/index.cjs +1 -1
  228. package/functions/index.mjs +0 -4
  229. package/functions/integrations/index.cjs +1 -1
  230. package/functions/integrations/index.mjs +0 -4
  231. package/functions/integrations/swapApi.cjs +1 -1
  232. package/functions/integrations/swapApi.d.ts +21 -7
  233. package/functions/integrations/swapApi.mjs +29 -10
  234. package/functions/utils/refreshBalance.cjs +1 -1
  235. package/functions/utils/refreshBalance.mjs +2 -2
  236. package/index.cjs +1 -1
  237. package/index.mjs +4 -8
  238. package/internal/token.utils.cjs +1 -1
  239. package/internal/token.utils.d.ts +1 -3
  240. package/internal/token.utils.mjs +10 -21
  241. package/package.json +34 -4
  242. package/react-native/HinkalWebViewWorker.cjs +98 -0
  243. package/react-native/HinkalWebViewWorker.d.ts +2 -0
  244. package/react-native/HinkalWebViewWorker.mjs +174 -0
  245. package/react-native/bridge/HinkalRNWorker.cjs +1 -0
  246. package/react-native/bridge/HinkalRNWorker.d.ts +13 -0
  247. package/react-native/bridge/HinkalRNWorker.mjs +26 -0
  248. package/react-native/bridge/serialization.utils.cjs +1 -0
  249. package/react-native/bridge/serialization.utils.d.ts +3 -0
  250. package/react-native/bridge/serialization.utils.mjs +13 -0
  251. package/react-native/metro-config.js +90 -0
  252. package/react-native/shims/circomlibjs-hinkal-fork.js +14 -0
  253. package/react-native/shims/circomlibjs.js +15 -0
  254. package/react-native/shims/constants.js +7 -0
  255. package/react-native/shims/crypto.js +103 -0
  256. package/react-native/shims/ffjavascript.js +5 -0
  257. package/react-native/shims/fs.js +5 -0
  258. package/react-native/shims/globals.js +10 -0
  259. package/react-native/shims/idb-keyval.js +75 -0
  260. package/react-native/shims/multiformats.js +1 -0
  261. package/react-native/shims/os.js +7 -0
  262. package/react-native/shims/path.js +11 -0
  263. package/react-native/shims/readline.js +6 -0
  264. package/react-native/shims/snarkjs.js +21 -0
  265. package/react-native/shims/url.js +5 -0
  266. package/react-native/shims/web-worker.js +7 -0
  267. package/react-native/shims/worker_threads.js +6 -0
  268. package/react-native/shims.d.ts +16 -0
  269. package/react-native/workerCDNUrls.cjs +1 -0
  270. package/react-native/workerCDNUrls.d.ts +2 -0
  271. package/react-native/workerCDNUrls.mjs +14 -0
  272. package/sdk/package.json.cjs +1 -0
  273. package/sdk/package.json.mjs +130 -0
  274. package/services/Hinkal.cjs +1 -1
  275. package/services/Hinkal.d.ts +6 -5
  276. package/services/Hinkal.mjs +50 -48
  277. package/types/IHinkal.d.ts +6 -5
  278. package/common/src/API/kycCalls.cjs +0 -1
  279. package/common/src/API/kycCalls.d.ts +0 -14
  280. package/common/src/API/kycCalls.mjs +0 -26
  281. package/common/src/constants/assets.constants.cjs +0 -1
  282. package/common/src/constants/assets.constants.d.ts +0 -13
  283. package/common/src/constants/assets.constants.mjs +0 -4
  284. package/common/src/constants/kyc.constants.cjs +0 -1
  285. package/common/src/constants/kyc.constants.d.ts +0 -29
  286. package/common/src/constants/kyc.constants.mjs +0 -126
  287. package/common/src/constants/token.limits.constants.cjs +0 -1
  288. package/common/src/constants/token.limits.constants.d.ts +0 -5
  289. package/common/src/constants/token.limits.constants.mjs +0 -3
  290. package/common/src/data-structures/Hinkal/HinkalPrivateBalanceController.cjs +0 -1
  291. package/common/src/data-structures/Hinkal/hinkalGetZkMeProvider.cjs +0 -1
  292. package/common/src/data-structures/Hinkal/hinkalGetZkMeProvider.d.ts +0 -28
  293. package/common/src/data-structures/Hinkal/hinkalGetZkMeProvider.mjs +0 -22
  294. package/common/src/externalABIs/BabPassport.json.cjs +0 -1
  295. package/common/src/externalABIs/BabPassport.json.mjs +0 -20
  296. package/common/src/externalABIs/GalxePassport.json.cjs +0 -1
  297. package/common/src/externalABIs/GalxePassport.json.mjs +0 -37
  298. package/common/src/functions/kyc/aiPriseHelper.d.ts +0 -0
  299. package/common/src/functions/kyc/checkTokenLimitsUSD.cjs +0 -1
  300. package/common/src/functions/kyc/checkTokenLimitsUSD.d.ts +0 -1
  301. package/common/src/functions/kyc/checkTokenLimitsUSD.mjs +0 -29
  302. package/common/src/functions/kyc/index.cjs +0 -1
  303. package/common/src/functions/kyc/index.d.ts +0 -3
  304. package/common/src/functions/kyc/index.mjs +0 -3
  305. package/common/src/functions/kyc/openDefaultPassportWindow.cjs +0 -1
  306. package/common/src/functions/kyc/openDefaultPassportWindow.d.ts +0 -1
  307. package/common/src/functions/kyc/openDefaultPassportWindow.mjs +0 -7
  308. package/common/src/functions/kyc/passportHelper.cjs +0 -1
  309. package/common/src/functions/kyc/passportHelper.d.ts +0 -3
  310. package/common/src/functions/kyc/passportHelper.mjs +0 -1
  311. package/common/src/functions/kyc/zkMeHelper.cjs +0 -1
  312. package/common/src/functions/kyc/zkMeHelper.d.ts +0 -4
  313. package/common/src/functions/kyc/zkMeHelper.mjs +0 -42
  314. package/common/src/functions/web3/events/balanceChangedHandler.cjs +0 -1
  315. package/common/src/functions/web3/events/balanceChangedHandler.d.ts +0 -5
  316. package/common/src/functions/web3/events/balanceChangedHandler.mjs +0 -21
  317. package/common/src/types/kyc.types.cjs +0 -1
  318. package/common/src/types/kyc.types.d.ts +0 -41
  319. package/common/src/types/kyc.types.mjs +0 -10
  320. package/common/src/webworker/logError-CmD5XYI9.js +0 -2
  321. package/common/src/webworker/workerProxy-C49-EPZz.js +0 -1
@@ -1,9 +1,12 @@
1
1
  import { ERC20Token, TokenChanges } from '../../types/token.types';
2
2
  export declare const getErc20TokenFromAPI: (chainId: number, address: string) => Promise<ERC20Token | undefined>;
3
3
  export declare const getErc20TokensFromAPI: (chainId: number, addresses: string[]) => Promise<(ERC20Token | undefined)[]>;
4
+ export declare const resolveErc20Token: (chainId: number, erc20Address: string) => Promise<ERC20Token>;
5
+ export declare const resolveErc20Tokens: (chainId: number, erc20Addresses: string[]) => Promise<ERC20Token[]>;
4
6
  export declare const getErc20TokensForChainAPI: (chainId: number) => Promise<ERC20Token[]>;
7
+ export declare const getErc20TokensBySymbolsFromAPI: (symbols: string[], chainId: number) => Promise<(ERC20Token | undefined)[]>;
5
8
  export declare const getErc20TokenBySymbolFromAPI: (symbol: string, chainId: number) => Promise<ERC20Token | undefined>;
6
- export declare const overlayTokenWithRegistryData: (token: ERC20Token, chainId: number) => Promise<ERC20Token>;
9
+ export declare const overlayTokensWithRegistryData: (tokens: ERC20Token[], chainId: number) => Promise<ERC20Token[]>;
7
10
  export declare const aggregateTokenChanges: (tokenChanges: TokenChanges<bigint>[]) => TokenChanges<bigint>[];
8
11
  export declare const formatTokenChangesList: (tokenChanges: TokenChanges<bigint>[]) => {
9
12
  token: ERC20Token;
@@ -1,21 +1,37 @@
1
1
  import "../../constants/chains.constants.mjs";
2
2
  import { TokenType as e } from "../../constants/protocol.constants.mjs";
3
3
  import "../web3/etherFunctions.mjs";
4
- import { getTokenBySymbolCall as t, getTokensForChainCall as n, tokensInfoCall as r } from "../../API/token-calls.mjs";
4
+ import { getTokensBySymbolsCall as t, getTokensForChainCall as n, tokensInfoCall as r } from "../../API/token-calls.mjs";
5
5
  import "../../constants/tokens.constants.mjs";
6
6
  //#region libs/shared/common/src/functions/utils/erc20tokenFunctions.ts
7
7
  var i = async (e, t) => {
8
8
  let [n] = await r(e, [t]);
9
9
  return n;
10
- }, a = async (e, t) => t.length === 0 ? [] : r(e, t), o = async (e) => await n(e), s = async (e, n) => await t(n, e), c = async (e, t) => {
11
- let n = await i(t, e.erc20TokenAddress);
12
- return n ? {
13
- ...e,
14
- name: n.name,
15
- symbol: n.symbol,
16
- logoURI: n.logoURI,
17
- decimals: n.decimals
18
- } : e;
19
- }, l = (t) => t.nftTokenType === e.ERC721 || t.nftTokenType === e.ERC1155 || t.nftTokenType === e.MetaplexNFT || t.nftTokenType === e.Token2022NFT || t.nftTokenType === e.CompressedNFT;
10
+ }, a = async (e, t) => t.length === 0 ? [] : r(e, t), o = async (e, t) => {
11
+ let n = await i(e, t);
12
+ if (!n) throw Error(`Token not found: ${t} on chain ${e}`);
13
+ return n;
14
+ }, s = async (e, t) => {
15
+ if (t.length === 0) return [];
16
+ let n = await a(e, t);
17
+ return t.map((t, r) => {
18
+ let i = n[r];
19
+ if (!i) throw Error(`Token not found: ${t} on chain ${e}`);
20
+ return i;
21
+ });
22
+ }, c = async (e) => await n(e), l = async (e, n) => await t(n, e), u = async (e, t) => {
23
+ if (e.length === 0) return [];
24
+ let n = await a(t, e.map((e) => e.erc20TokenAddress));
25
+ return e.map((e, t) => {
26
+ let r = n[t];
27
+ return r ? {
28
+ ...e,
29
+ name: r.name,
30
+ symbol: r.symbol,
31
+ logoURI: r.logoURI,
32
+ decimals: r.decimals
33
+ } : e;
34
+ });
35
+ }, d = (t) => t.nftTokenType === e.ERC721 || t.nftTokenType === e.ERC1155 || t.nftTokenType === e.MetaplexNFT || t.nftTokenType === e.Token2022NFT || t.nftTokenType === e.CompressedNFT;
20
36
  //#endregion
21
- export { s as getErc20TokenBySymbolFromAPI, i as getErc20TokenFromAPI, o as getErc20TokensForChainAPI, a as getErc20TokensFromAPI, l as isNFTToken, c as overlayTokenWithRegistryData };
37
+ export { i as getErc20TokenFromAPI, l as getErc20TokensBySymbolsFromAPI, c as getErc20TokensForChainAPI, a as getErc20TokensFromAPI, d as isNFTToken, u as overlayTokensWithRegistryData, o as resolveErc20Token, s as resolveErc20Tokens };
@@ -1 +1 @@
1
- require(`../../constants/index.cjs`);
1
+ const e=require(`../../types/chains.types.cjs`);require(`../../types/index.cjs`),require(`../../constants/index.cjs`),e.EthereumNetworkType.Mainnet,e.EthereumNetworkType.Testnet,e.EthereumNetworkType.Local;
@@ -1,3 +1,4 @@
1
1
  import { EthereumNetwork, EthereumNetworkType } from '../../types';
2
2
  export declare const getNetworkObject: (chainId: number) => EthereumNetwork;
3
3
  export declare const getNetworkType: (network: EthereumNetwork) => EthereumNetworkType;
4
+ export declare const compareNetworksByTypeAndPriority: (network1: EthereumNetwork, network2: EthereumNetwork) => number;
@@ -1 +1,5 @@
1
+ import { EthereumNetworkType as e } from "../../types/chains.types.mjs";
2
+ import "../../types/index.mjs";
1
3
  import "../../constants/index.mjs";
4
+ e.Mainnet, e.Testnet, e.Local;
5
+ //#endregion
@@ -1 +1 @@
1
- require(`../../constants/chains.constants.cjs`);const e=require(`../../types/ethereum-network.types.cjs`),t=require(`./caseInsensitive.utils.cjs`),n=require(`./amounts.utils.cjs`);require(`../../data-structures/crypto-keys/keys.cjs`),require(`../../types/index.cjs`),require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const r=require(`../../data-structures/crypto-keys/decodeUTXO.cjs`),i=require(`./getContractAddress.cjs`);require(`ethers`);var a=(a,o,s,c)=>{let l=o.getContractWithFetcher(s,e.ContractType.HinkalContract),u=l.interface,d=o.userKeys.getShieldedPrivateKey(),f=i.getContractAddress(l);return a.logs.filter(e=>t.caseInsensitiveEqual(e.address,f)).map(e=>{try{let i=u.parseLog(e);if(i?.name===`NewCommitment`){let{encryptedOutput:e,index:a}=i.args;if(n.toBigInt(a)<0n){let n=r.decodeUtxo(e,d,s);if(t.caseInsensitiveEqual(n.erc20TokenAddress,c))return n}}}catch{return null}return null}).filter(e=>e!==null)};exports.getOnChainUtxosFromReceipt=a;
1
+ require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`./amounts.utils.cjs`);require(`../../data-structures/crypto-keys/keys.cjs`);const n=require(`../../types/ethereum-network.types.cjs`);require(`../../types/index.cjs`),require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const r=require(`../../data-structures/crypto-keys/decodeUTXO.cjs`),i=require(`./getContractAddress.cjs`);require(`ethers`);var a=(a,o,s,c)=>{let l=o.getContractWithFetcher(s,n.ContractType.HinkalContract),u=l.interface,d=o.userKeys.getShieldedPrivateKey(),f=i.getContractAddress(l);return a.logs.filter(t=>e.caseInsensitiveEqual(t.address,f)).map(n=>{try{let i=u.parseLog(n);if(i?.name===`NewCommitment`){let{encryptedOutput:n,index:a}=i.args;if(t.toBigInt(a)<0n){let t=r.decodeUtxo(n,d,s);if(e.caseInsensitiveEqual(t.erc20TokenAddress,c))return t}}}catch{return null}return null}).filter(e=>e!==null)};exports.getOnChainUtxosFromReceipt=a;
@@ -1,8 +1,8 @@
1
1
  import "../../constants/chains.constants.mjs";
2
- import { ContractType as e } from "../../types/ethereum-network.types.mjs";
3
- import { caseInsensitiveEqual as t } from "./caseInsensitive.utils.mjs";
4
- import { toBigInt as n } from "./amounts.utils.mjs";
2
+ import { caseInsensitiveEqual as e } from "./caseInsensitive.utils.mjs";
3
+ import { toBigInt as t } from "./amounts.utils.mjs";
5
4
  import "../../data-structures/crypto-keys/keys.mjs";
5
+ import { ContractType as n } from "../../types/ethereum-network.types.mjs";
6
6
  import "../../types/index.mjs";
7
7
  import "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
8
8
  import { decodeUtxo as r } from "../../data-structures/crypto-keys/decodeUTXO.mjs";
@@ -10,15 +10,15 @@ import { getContractAddress as i } from "./getContractAddress.mjs";
10
10
  import "ethers";
11
11
  //#region libs/shared/common/src/functions/utils/getUtxosFromReceipt.utils.ts
12
12
  var a = (a, o, s, c) => {
13
- let l = o.getContractWithFetcher(s, e.HinkalContract), u = l.interface, d = o.userKeys.getShieldedPrivateKey(), f = i(l);
14
- return a.logs.filter((e) => t(e.address, f)).map((e) => {
13
+ let l = o.getContractWithFetcher(s, n.HinkalContract), u = l.interface, d = o.userKeys.getShieldedPrivateKey(), f = i(l);
14
+ return a.logs.filter((t) => e(t.address, f)).map((n) => {
15
15
  try {
16
- let i = u.parseLog(e);
16
+ let i = u.parseLog(n);
17
17
  if (i?.name === "NewCommitment") {
18
- let { encryptedOutput: e, index: a } = i.args;
19
- if (n(a) < 0n) {
20
- let n = r(e, d, s);
21
- if (t(n.erc20TokenAddress, c)) return n;
18
+ let { encryptedOutput: n, index: a } = i.args;
19
+ if (t(a) < 0n) {
20
+ let t = r(n, d, s);
21
+ if (e(t.erc20TokenAddress, c)) return t;
22
22
  }
23
23
  }
24
24
  } catch {
@@ -1 +1 @@
1
- require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.utils.cjs`),require(`./time.utils.cjs`),require(`./upToDateState.cjs`),require(`./cacheFunctions.cjs`),require(`./encryptInputForEnclave.cjs`),require(`./solanaMint.utils.cjs`),require(`./customEnclaveFunctionsRegister.cjs`),require(`./addresses.cjs`),require(`./tron.utils.cjs`),require(`./get-signature-header.cjs`),require(`./auth.utils.cjs`),require(`./string.utils.cjs`),require(`./token-check.utils.cjs`),require(`./mutexes.utils.cjs`),require(`./erc20tokenFunctions.cjs`),require(`../pre-transaction/outputUtxoProcessing.cjs`),require(`./external-action.utils.cjs`),require(`./bit.operations.cjs`),require(`../pre-transaction/solana.cjs`),require(`../pre-transaction/process-gas-estimates.cjs`),require(`../pre-transaction/getVolatileTransferAmount.cjs`),require(`../pre-transaction/constructAdminData.cjs`),require(`./create-provider.cjs`),require(`../pre-transaction/convert-okx-instructions.cjs`),require(`./process.utils.cjs`),require(`../pre-transaction/sendV0Transaction.cjs`),require(`./bytes32.utils.cjs`),require(`../pre-transaction/recipientUtxoProcessing.cjs`),require(`../pre-transaction/ensureAmountChanges.cjs`),require(`../pre-transaction/getFeeStructure.cjs`),require(`../pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),require(`../pre-transaction/buildCommitmentValidationData.cjs`),require(`../pre-transaction/index.cjs`),require(`./serialize-utxos.utils.cjs`),require(`./resolve-sync.utils.cjs`),require(`./convertIntegrationProviderToExternalActionId.cjs`),require(`./evmNetworkFunctions.cjs`),require(`./userAgent.cjs`),require(`./reloadPage.cjs`),require(`./cacheDevice.utils.cjs`),require(`./getBlockExplorerUrl.cjs`),require(`./involves-permit2-op.cjs`),require(`./convertEmporiumOpToCallInfo.cjs`),require(`./getRecipientInfoFromUserKeys.cjs`),require(`./publicBalance.utils.cjs`),require(`./rpc-int-encode.cjs`),require(`./walletBalances.utils.cjs`),require(`./nftTokenFunctions.cjs`),require(`./inLogicMetadata.cjs`),require(`./networks.utils.cjs`),require(`./postToOffscreen.cjs`),require(`./solanaSendPreflight.utils.cjs`),require(`./prepareHinkal.cjs`),require(`./getContractAddress.cjs`),require(`./getUtxosFromReceipt.utils.cjs`),require(`./getUtxosFromReceiptSolana.cjs`),require(`./fees.utils.cjs`),require(`./enclave-utxo-storage.cjs`),require(`./enclave-signature-storage.cjs`),require(`./tx-confirmation.utils.cjs`),require(`./buildClaimableDepositPlan.cjs`),require(`./formatter.cjs`),require(`./tronSimulation.utils.cjs`),require(`./getSignerFromContract.cjs`),require(`./deposit-claimable.utils.cjs`),require(`./transfer-claimable.utils.cjs`),require(`./dispatchBalanceRefreshes.cjs`),require(`./lifi.utils.cjs`),require(`./enclave-recipient-info-storage.cjs`),require(`./solana-memo.cjs`),require(`./mnemonics.cjs`),require(`./nearIntents.utils.cjs`);
1
+ require(`./abi.utils.cjs`),require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.utils.cjs`),require(`./bigint-math.utils.cjs`),require(`./time.utils.cjs`),require(`./upToDateState.cjs`),require(`./cacheFunctions.cjs`),require(`./enclaveHandshakeService.cjs`),require(`./encryptInputForEnclave.cjs`),require(`./solanaMint.utils.cjs`),require(`./customEnclaveFunctionsRegister.cjs`),require(`./addresses.cjs`),require(`./tron.utils.cjs`),require(`./get-signature-header.cjs`),require(`./auth.utils.cjs`),require(`./string.utils.cjs`),require(`./token-check.utils.cjs`),require(`./map.utils.cjs`),require(`./mutexes.utils.cjs`),require(`./erc20tokenFunctions.cjs`),require(`../pre-transaction/outputUtxoProcessing.cjs`),require(`./external-action.utils.cjs`),require(`./bit.operations.cjs`),require(`../pre-transaction/solana.cjs`),require(`../pre-transaction/process-gas-estimates.cjs`),require(`../pre-transaction/getVolatileTransferAmount.cjs`),require(`../pre-transaction/constructAdminData.cjs`),require(`./create-provider.cjs`),require(`../pre-transaction/convert-okx-instructions.cjs`),require(`./process.utils.cjs`),require(`../pre-transaction/sendV0Transaction.cjs`),require(`./bytes32.utils.cjs`),require(`../pre-transaction/recipientUtxoProcessing.cjs`),require(`../pre-transaction/ensureAmountChanges.cjs`),require(`../pre-transaction/getFeeStructure.cjs`),require(`../pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),require(`../pre-transaction/buildCommitmentValidationData.cjs`),require(`../pre-transaction/index.cjs`),require(`./serialize-utxos.utils.cjs`),require(`./resolve-sync.utils.cjs`),require(`./convertIntegrationProviderToExternalActionId.cjs`),require(`./evmNetworkFunctions.cjs`),require(`./userAgent.cjs`),require(`./reloadPage.cjs`),require(`./cacheDevice.utils.cjs`),require(`./getBlockExplorerUrl.cjs`),require(`./involves-permit2-op.cjs`),require(`./convertEmporiumOpToCallInfo.cjs`),require(`./getRecipientInfoFromUserKeys.cjs`),require(`./publicBalance.utils.cjs`),require(`./rpc-int-encode.cjs`),require(`./walletBalances.utils.cjs`),require(`./nftTokenFunctions.cjs`),require(`./inLogicMetadata.cjs`),require(`./networks.utils.cjs`),require(`./postToOffscreen.cjs`),require(`./solanaSendPreflight.utils.cjs`),require(`./prepareHinkal.cjs`),require(`./getContractAddress.cjs`),require(`./getUtxosFromReceipt.utils.cjs`),require(`./getUtxosFromReceiptSolana.cjs`),require(`./fees.utils.cjs`),require(`./enclave-utxo-storage.cjs`),require(`./enclave-signature-storage.cjs`),require(`./tx-confirmation.utils.cjs`),require(`./buildClaimableDepositPlan.cjs`),require(`./formatter.cjs`),require(`./tronSimulation.utils.cjs`),require(`./getSignerFromContract.cjs`),require(`./deposit-claimable.utils.cjs`),require(`./transfer-claimable.utils.cjs`),require(`./dispatchBalanceRefreshes.cjs`),require(`./lifi.utils.cjs`),require(`./enclave-recipient-info-storage.cjs`),require(`./solana-memo.cjs`),require(`./mnemonics.cjs`),require(`./nearIntents.utils.cjs`);
@@ -1,4 +1,6 @@
1
1
  export * from './amounts.utils';
2
+ export * from './abi.utils';
3
+ export * from './bigint-math.utils';
2
4
  export * from './cacheFunctions';
3
5
  export * from './create-provider';
4
6
  export * from './external-action.utils';
@@ -31,6 +33,7 @@ export * from './addresses';
31
33
  export * from './trimFieldValues';
32
34
  export * from './walletBalances.utils';
33
35
  export * from './mutexes.utils';
36
+ export * from './map.utils';
34
37
  export * from './nftTokenFunctions';
35
38
  export * from './inLogicMetadata';
36
39
  export * from './networks.utils';
@@ -62,6 +65,7 @@ export * from './transfer-claimable.utils';
62
65
  export * from './auth.utils';
63
66
  export * from './getWalletGroupKey.utils';
64
67
  export * from './encryptInputForEnclave';
68
+ export * from './enclaveHandshakeService';
65
69
  export * from './dispatchBalanceRefreshes';
66
70
  export * from './lifi.utils';
67
71
  export * from './enclave-recipient-info-storage';
@@ -1,9 +1,12 @@
1
+ import "./abi.utils.mjs";
1
2
  import "./serialize.utils.mjs";
2
3
  import "./caseInsensitive.utils.mjs";
3
4
  import "./amounts.utils.mjs";
5
+ import "./bigint-math.utils.mjs";
4
6
  import "./time.utils.mjs";
5
7
  import "./upToDateState.mjs";
6
8
  import "./cacheFunctions.mjs";
9
+ import "./enclaveHandshakeService.mjs";
7
10
  import "./encryptInputForEnclave.mjs";
8
11
  import "./solanaMint.utils.mjs";
9
12
  import "./customEnclaveFunctionsRegister.mjs";
@@ -13,6 +16,7 @@ import "./get-signature-header.mjs";
13
16
  import "./auth.utils.mjs";
14
17
  import "./string.utils.mjs";
15
18
  import "./token-check.utils.mjs";
19
+ import "./map.utils.mjs";
16
20
  import "./mutexes.utils.mjs";
17
21
  import "./erc20tokenFunctions.mjs";
18
22
  import "../pre-transaction/outputUtxoProcessing.mjs";
@@ -0,0 +1 @@
1
+ var e=(e,t,n)=>{let r=e.get(t);if(r!==void 0)return r;let i=n();return e.set(t,i),i};exports.getOrCreateMapValue=e;
@@ -0,0 +1 @@
1
+ export declare const getOrCreateMapValue: <K, V>(map: Map<K, V>, key: K, createValue: () => V) => V;
@@ -0,0 +1,9 @@
1
+ //#region libs/shared/common/src/functions/utils/map.utils.ts
2
+ var e = (e, t, n) => {
3
+ let r = e.get(t);
4
+ if (r !== void 0) return r;
5
+ let i = n();
6
+ return e.set(t, i), i;
7
+ };
8
+ //#endregion
9
+ export { e as getOrCreateMapValue };
@@ -1 +1 @@
1
- require(`../../../../_virtual/_rolldown/runtime.cjs`);let e=require(`async-mutex`);var t=new Map,n=n=>(t.has(n)||t.set(n,new e.Mutex),t.get(n)??new e.Mutex);exports.getChainBalanceFetchingMutex=n;
1
+ const e=require(`../../mutexes/chainBalanceRwLock.cjs`),t=require(`./map.utils.cjs`);var n=new Map,r=r=>t.getOrCreateMapValue(n,r,()=>new e.ChainBalanceRwLock);exports.getChainBalanceFetchingMutex=r;
@@ -1,2 +1,2 @@
1
- import { Mutex } from 'async-mutex';
2
- export declare const getChainBalanceFetchingMutex: (chainId: number) => Mutex;
1
+ import { ChainBalanceFetchingLock } from '../../mutexes/chainBalanceRwLock';
2
+ export declare const getChainBalanceFetchingMutex: (chainId: number) => ChainBalanceFetchingLock;
@@ -1,5 +1,6 @@
1
- import { Mutex as e } from "async-mutex";
1
+ import { ChainBalanceRwLock as e } from "../../mutexes/chainBalanceRwLock.mjs";
2
+ import { getOrCreateMapValue as t } from "./map.utils.mjs";
2
3
  //#region libs/shared/common/src/functions/utils/mutexes.utils.ts
3
- var t = /* @__PURE__ */ new Map(), n = (n) => (t.has(n) || t.set(n, new e()), t.get(n) ?? new e());
4
+ var n = /* @__PURE__ */ new Map(), r = (r) => t(n, r, () => new e());
4
5
  //#endregion
5
- export { n as getChainBalanceFetchingMutex };
6
+ export { r as getChainBalanceFetchingMutex };
@@ -1 +1 @@
1
- var e=e=>new Promise(t=>{setTimeout(t,e)}),t=async(t,n={})=>{let r=n.intervalMs??5e3,i=n.timeoutMs??6e4,a=Math.floor(i/r)+1;for(let n=0;n<a;n+=1){try{let e=await t();if(e!=null)return e}catch{}n<a-1&&await e(r)}};exports.pollForValue=t,exports.wait=e;
1
+ var e=e=>new Promise(t=>{setTimeout(t,e)}),t=async(e,t=1e4)=>Promise.race([e,new Promise((n,r)=>{let i=setTimeout(()=>{r(Error(`Timeout after ${t}ms`))},t);e.finally(()=>clearTimeout(i))})]),n=async(t,n={})=>{let r=n.intervalMs??5e3,i=n.timeoutMs??6e4,a=Math.floor(i/r)+1;for(let n=0;n<a;n+=1){try{let e=await t();if(e!=null)return e}catch{}n<a-1&&await e(r)}};exports.pollForValue=n,exports.wait=e,exports.withTimeout=t;
@@ -1,5 +1,6 @@
1
1
  /** pause execution for a number of miliseconds */
2
2
  export declare const wait: (miliseconds: number) => Promise<unknown>;
3
+ export declare const withTimeout: <T>(promise: Promise<T>, timeoutMs?: number) => Promise<T>;
3
4
  type PollForValueOptions = {
4
5
  intervalMs?: number;
5
6
  timeoutMs?: number;
@@ -1,7 +1,12 @@
1
1
  //#region libs/shared/common/src/functions/utils/process.utils.ts
2
2
  var e = (e) => new Promise((t) => {
3
3
  setTimeout(t, e);
4
- }), t = async (t, n = {}) => {
4
+ }), t = async (e, t = 1e4) => Promise.race([e, new Promise((n, r) => {
5
+ let i = setTimeout(() => {
6
+ r(/* @__PURE__ */ Error(`Timeout after ${t}ms`));
7
+ }, t);
8
+ e.finally(() => clearTimeout(i));
9
+ })]), n = async (t, n = {}) => {
5
10
  let r = n.intervalMs ?? 5e3, i = n.timeoutMs ?? 6e4, a = Math.floor(i / r) + 1;
6
11
  for (let n = 0; n < a; n += 1) {
7
12
  try {
@@ -12,4 +17,4 @@ var e = (e) => new Promise((t) => {
12
17
  }
13
18
  };
14
19
  //#endregion
15
- export { t as pollForValue, e as wait };
20
+ export { n as pollForValue, e as wait, t as withTimeout };
@@ -1 +1 @@
1
- require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`./caseInsensitive.utils.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../snarkjs/constant.cjs`),a=require(`../../data-structures/http/HttpClient.cjs`),o=require(`../../externalABIs/index.cjs`),s=require(`../../error-handling/logger.cjs`);let c=require(`ethers`),l=require(`tronweb`);var u=2000n,d=e=>{let t=e.trim(),n=t.startsWith(`0x`)?t.slice(2):t;if(!/^[0-9a-fA-F]{64}$/.test(n))throw Error(`Tron private key must be 32 bytes (64 hex characters), with or without 0x prefix`);return n},f=(t,n)=>{let r=e.networkRegistry[t].fetchRpcUrl,i=n?d(n):void 0,a=i?new l.TronWeb({fullHost:r,privateKey:i}):new l.TronWeb({fullHost:r});return n||a.setAddress(`T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb`),a},p=e=>e?.startsWith(`T`)?e:l.TronWeb.address.fromHex(e),m=e=>e.startsWith(`0x`)?p(e):e,h=e=>{if(e.startsWith(`0x`))return e;if(e.startsWith(`41`))return e.replace(`41`,`0x`);if(e.startsWith(`T`))return h(l.TronWeb.address.toHex(e));throw Error(`Failed to convert address to hex format`)},g=t=>{if(t===e.chainIds.tronNile)return`https://nile.trongrid.io`;if(t===e.chainIds.tronMainnet)return`https://api.trongrid.io`;throw Error(`Unsupported Tron chain for wallet RPC: ${t}`)},_=(e,t)=>e.map(e=>Array.isArray(e)?_(e,t):t(e)),v=(e,t,n)=>{let r=new c.ethers.Interface(e);if(!r.getFunction(t))throw Error(`${t} ABI is missing for Tron call data creation`);let i=_(n,e=>typeof e==`string`&&e.startsWith(`T`)?h(e):e);return r.encodeFunctionData(t,i)},y=(e,t,n)=>e?BigInt(Math.max((e[t]??0)-(e[n]??0),0)):0n,b=(e,t)=>{let n=e.find(e=>e.key===t);if(!n||typeof n.value!=`number`)throw Error(`Missing Tron chain parameter: ${t}`);return BigInt(n.value)},x=async e=>{let t=`${g(e)}/wallet/getchainparameters`,n=await a.httpClient.post(t,{});if(!n?.chainParameter?.length)throw Error(`Failed to fetch Tron chain parameters from wallet RPC`);return n.chainParameter},S=async(e,t)=>{let n=`${g(e)}/wallet/getaccountresource`,r=h(t),i=r.startsWith(`0x`)?`41${r.slice(2)}`:r;return await a.httpClient.post(n,{address:i,visible:!1})},C=async(e,n,r,i,a,o)=>{let s={input:a,callValue:Number(o),feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[c,l]=await Promise.all([e.transactionBuilder.estimateEnergy(r,``,s,[],i),e.transactionBuilder.triggerConstantContract(r,``,s,[],i)]),d=await x(n),f=b(d,`getEnergyFee`),p=b(d,`getTransactionFee`),m=await S(n,i),h=BigInt(c?.energy_required??l?.energy_used??0),g=y(m,`EnergyLimit`,`EnergyUsed`),_=(h>g?h-g:0n)*f,v=BigInt(Math.ceil((l?.transaction?.raw_data_hex?.length??0)/2)),C=y(m,`freeNetLimit`,`freeNetUsed`)+y(m,`NetLimit`,`NetUsed`),w=_+(v>C?v-C:0n)*p,T=w+w*u/10000n;return T>BigInt(1e9)?BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN):T},w=e=>{let t=e[0].map(BigInt),n=e[1][0].map(BigInt),r=e[1][1].map(BigInt),i=e[2].map(BigInt),a=e[3].map(BigInt);return{a:t,b:[[n[1],n[0]],[r[1],r[0]]],c:i,publicSignals:a}},T=(e,t)=>{let n=c.ethers.AbiCoder.defaultAbiCoder().encode([`uint16`,`uint16`,`uint16`,`uint256`],[e.tokenNumber,e.nullifierAmount,e.outputAmount,t]);return BigInt(c.ethers.keccak256(n))},E=async(e,t,n,r,o,s)=>{let l=T(o,s),u=e.map(String),d=n.map(String),f=r.map(String),p={a:u,b:[t[0].map(String),t[1].map(String)],c:d,inputs:f,verifier_id:String(l)},m=await a.httpClient.post(`${i.ENCLAVE_URL}/sign-proof`,p),{v:h,r:g,s:_}=c.ethers.Signature.from(m.signature.trim());return{v:h,r:g,s:_}},D=e=>[e.rootHashHinkal,e.erc20TokenAddresses,e.tokenIds,e.amountChanges,e.onChainCreation,e.slippageValues,e.inputNullifiers,e.outCommitments,e.encryptedOutputs,[e.feeStructure.feeToken,e.feeStructure.flatFee,e.feeStructure.variableRate],e.timeStamp,[e.stealthAddressStructure.extraRandomization,e.stealthAddressStructure.stealthAddress,e.stealthAddressStructure.H0,e.stealthAddressStructure.H1],e.rootHashAccessToken,e.calldataHash,e.publicSignalCount,e.relay,e.externalAddress,e.externalActionId,e.externalActionMetadata,[e.hinkalLogicArgs.hinkalLogicAction,e.hinkalLogicArgs.inHinkalAddress,e.hinkalLogicArgs.executeApprovalChanges,e.hinkalLogicArgs.doPreTxApproval,e.hinkalLogicArgs.useApprovalUtxoData.map(e=>[e.approvalChanges,e.externalApprovalAddresses,e.conversionInHinkalAddress])],[e.hookData.preHookContract,e.hookData.hookContract,e.hookData.preHookMetadata,e.hookData.postHookMetadata],[e.signatureData.v,e.signatureData.r,e.signatureData.s,e.signatureData.accessKey,e.signatureData.nonce,e.signatureData.ethereumAddress],e.originalSender],O=async(e,t,n,r,i=!0)=>{if(e){let{a:e,b:a,c:o,publicSignals:s}=w(t),c=await E(e,a,o,s,n,BigInt(r.externalActionId)),l={v:c.v,r:c.r,s:c.s};return i&&(t[1]=[[t[1][0][1],t[1][0][0]],[t[1][1][1],t[1][1][0]]]),l}},k=(e,r)=>{let i=0n,a=new Map;for(let o=0;o<e.length;o+=1)if(n.caseInsensitiveEqual(e[o].erc20TokenAddress,t.zeroAddress))i+=r[o];else{let t=p(e[o].erc20TokenAddress);a.set(t,(a.get(t)??0n)+r[o])}return{totalTrxValue:i,tokensNeedingApproval:a}},A=async(e,n,i,a,o,c)=>{let l=BigInt(await e.trx.getBalance(a)),u=BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN);try{u=await C(e,n,i,a,o,c)}catch(e){s.Logger.error(`Error estimating Tron deposit fee`,e)}if(l<c+u)throw Error(r.insufficientResourcesErrorCodes.INSUFFICIENT_TRON_BALANCE_FOR_FEE)},j=async(e,n,r,i)=>{let a=Array.from(i.entries());for(let i=0;i<a.length;i+=1){let[s,c]=a[i],l=await e.contract(o.ERC20ABI,s).allowance(n,r).call({from:n});if(BigInt(String(l))<c){let{transaction:i}=await e.transactionBuilder.triggerSmartContract(s,`approve(address,uint256)`,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[{type:`address`,value:r},{type:`uint256`,value:c.toString()}],n),a=await e.trx.sign(i),o=await e.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}`)}}}};exports.addressToHexFormat=h,exports.approveTronTokens=j,exports.assertTronSufficientBalance=A,exports.circomDataToArray=D,exports.createTronCallData=v,exports.createTronWeb=f,exports.estimateTronFeeSunWithPadding=C,exports.evmHexToTronBase58Address=p,exports.fetchTronAccountResources=S,exports.fetchTronChainParameters=x,exports.generateProofSignatureRemotely=E,exports.getAvailableResource=y,exports.getChainParameterValue=b,exports.getVerifierId=T,exports.normalizeTronPrivateKey=d,exports.parseZkCalldata=w,exports.reorderZkCallData=O,exports.splitTronTokensByNative=k,exports.toTronBase58IfHex=m;
1
+ require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`./caseInsensitive.utils.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../snarkjs/constant.cjs`),a=require(`../../data-structures/http/HttpClient.cjs`),o=require(`../../externalABIs/index.cjs`),s=require(`../../error-handling/logger.cjs`);let c=require(`ethers`),l=require(`tronweb`);var u=2000n,d=e=>{let t=e.trim(),n=t.startsWith(`0x`)?t.slice(2):t;if(!/^[0-9a-fA-F]{64}$/.test(n))throw Error(`Tron private key must be 32 bytes (64 hex characters), with or without 0x prefix`);return n},f=(t,n)=>{let r=e.networkRegistry[t].fetchRpcUrl,i=n?d(n):void 0,a=i?new l.TronWeb({fullHost:r,privateKey:i}):new l.TronWeb({fullHost:r});return n||a.setAddress(`T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb`),a},p=e=>e?.startsWith(`T`)?e:l.TronWeb.address.fromHex(e),m=e=>e.startsWith(`0x`)?p(e):e,h=e=>{if(e.startsWith(`0x`))return e;if(e.startsWith(`41`))return e.replace(`41`,`0x`);if(e.startsWith(`T`))return h(l.TronWeb.address.toHex(e));throw Error(`Failed to convert address to hex format`)},g=t=>{if(t===e.chainIds.tronNile)return`https://nile.trongrid.io`;if(t===e.chainIds.tronMainnet)return`https://api.trongrid.io`;throw Error(`Unsupported Tron chain for wallet RPC: ${t}`)},_=(e,t)=>e.map(e=>Array.isArray(e)?_(e,t):t(e)),v=(e,t,n)=>{let r=new c.ethers.Interface(e);if(!r.getFunction(t))throw Error(`${t} ABI is missing for Tron call data creation`);let i=_(n,e=>typeof e==`string`&&e.startsWith(`T`)?h(e):e);return r.encodeFunctionData(t,i)},y=(e,t,n)=>e?BigInt(Math.max((e[t]??0)-(e[n]??0),0)):0n,b=(e,t)=>{let n=e.find(e=>e.key===t);if(!n||typeof n.value!=`number`)throw Error(`Missing Tron chain parameter: ${t}`);return BigInt(n.value)},x=async e=>{let t=`${g(e)}/wallet/getchainparameters`,n=await a.httpClient.post(t,{});if(!n?.chainParameter?.length)throw Error(`Failed to fetch Tron chain parameters from wallet RPC`);return n.chainParameter},S=async(e,t)=>{let n=`${g(e)}/wallet/getaccountresource`,r=h(t),i=r.startsWith(`0x`)?`41${r.slice(2)}`:r;return await a.httpClient.post(n,{address:i,visible:!1})},C=async(e,n,r,i,a,o)=>{let s={input:a,callValue:Number(o),feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[c,l]=await Promise.all([e.transactionBuilder.estimateEnergy(r,``,s,[],i),e.transactionBuilder.triggerConstantContract(r,``,s,[],i)]),d=await x(n),f=b(d,`getEnergyFee`),p=b(d,`getTransactionFee`),m=await S(n,i),h=BigInt(c?.energy_required??l?.energy_used??0),g=y(m,`EnergyLimit`,`EnergyUsed`),_=(h>g?h-g:0n)*f,v=BigInt(Math.ceil((l?.transaction?.raw_data_hex?.length??0)/2)),C=y(m,`freeNetLimit`,`freeNetUsed`)+y(m,`NetLimit`,`NetUsed`),w=_+(v>C?v-C:0n)*p,T=w+w*u/10000n;return T>BigInt(1e9)?BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN):T},w=e=>{let t=e[0].map(BigInt),n=e[1][0].map(BigInt),r=e[1][1].map(BigInt),i=e[2].map(BigInt),a=e[3].map(BigInt);return{a:t,b:[[n[1],n[0]],[r[1],r[0]]],c:i,publicSignals:a}},T=(e,t)=>{let n=c.ethers.AbiCoder.defaultAbiCoder().encode([`uint16`,`uint16`,`uint16`,`uint256`],[e.tokenNumber,e.nullifierAmount,e.outputAmount,t]);return BigInt(c.ethers.keccak256(n))},E=async(e,t,n,r,o,s)=>{let l=T(o,s),u=e.map(String),d=n.map(String),f=r.map(String),p={a:u,b:[t[0].map(String),t[1].map(String)],c:d,inputs:f,verifier_id:String(l)},m=await a.httpClient.post(`${i.ENCLAVE_URL}/sign-proof`,p),{v:h,r:g,s:_}=c.ethers.Signature.from(m.signature.trim());return{v:h,r:g,s:_}},D=e=>[e.rootHashHinkal,e.erc20TokenAddresses,e.tokenIds,e.amountChanges,e.onChainCreation,e.slippageValues,e.inputNullifiers,e.outCommitments,e.encryptedOutputs,[e.feeStructure.feeToken,e.feeStructure.flatFee,e.feeStructure.variableRate],e.timeStamp,[e.stealthAddressStructure.extraRandomization,e.stealthAddressStructure.stealthAddress,e.stealthAddressStructure.H0,e.stealthAddressStructure.H1],e.rootHashAccessToken,e.calldataHash,e.publicSignalCount,e.relay,e.externalAddress,e.externalActionId,e.externalActionMetadata,[e.hinkalLogicArgs.hinkalLogicAction,e.hinkalLogicArgs.inHinkalAddress,e.hinkalLogicArgs.executeApprovalChanges,e.hinkalLogicArgs.doPreTxApproval,e.hinkalLogicArgs.useApprovalUtxoData.map(e=>[e.approvalChanges,e.externalApprovalAddresses,e.conversionInHinkalAddress])],[e.hookData.preHookContract,e.hookData.hookContract,e.hookData.preHookMetadata,e.hookData.postHookMetadata],[e.signatureData.v,e.signatureData.r,e.signatureData.s,e.signatureData.accessKey,e.signatureData.nonce,e.signatureData.ethereumAddress],e.originalSender],O=async(e,t,n,r,i=!0)=>{if(e){let{a:e,b:a,c:o,publicSignals:s}=w(t),c=await E(e,a,o,s,n,BigInt(r.externalActionId)),l={v:c.v,r:c.r,s:c.s};return i&&(t[1]=[[t[1][0][1],t[1][0][0]],[t[1][1][1],t[1][1][0]]]),l}},k=(e,r)=>{let i=0n,a=new Map;for(let o=0;o<e.length;o+=1)if(n.caseInsensitiveEqual(e[o].erc20TokenAddress,t.zeroAddress))i+=r[o];else{let t=p(e[o].erc20TokenAddress);a.set(t,(a.get(t)??0n)+r[o])}return{totalTrxValue:i,tokensNeedingApproval:a}},A=async(e,n,i,a,o,c)=>{let l=BigInt(await e.trx.getBalance(a)),u=BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN);try{u=await C(e,n,i,a,o,c)}catch(e){s.Logger.error(`Error estimating Tron deposit fee`,e)}if(l<c+u)throw Error(r.insufficientResourcesErrorCodes.INSUFFICIENT_TRON_BALANCE_FOR_FEE)},j=async(e,n,r,i)=>{let a=Array.from(i.entries());for(let i=0;i<a.length;i+=1){let[s,c]=a[i],l=await e.contract(o.ERC20ABI,s).allowance(n,r).call({from:n});if(BigInt(String(l))<c){let{transaction:i}=await e.transactionBuilder.triggerSmartContract(s,`approve(address,uint256)`,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[{type:`address`,value:r},{type:`uint256`,value:c.toString()}],n),a=await e.trx.sign(i),o=await e.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}`)}}}};exports.addressToHexFormat=h,exports.approveTronTokens=j,exports.assertTronSufficientBalance=A,exports.circomDataToArray=D,exports.createTronCallData=v,exports.createTronWeb=f,exports.estimateTronFeeSunWithPadding=C,exports.evmHexToTronBase58Address=p,exports.fetchTronAccountResources=S,exports.fetchTronChainParameters=x,exports.generateProofSignatureRemotely=E,exports.getAvailableResource=y,exports.getChainParameterValue=b,exports.getTronWalletRpcUrl=g,exports.getVerifierId=T,exports.normalizeTronPrivateKey=d,exports.parseZkCalldata=w,exports.reorderZkCallData=O,exports.splitTronTokensByNative=k,exports.toTronBase58IfHex=m;
@@ -11,6 +11,7 @@ export declare const evmHexToTronBase58Address: (addr: string) => string;
11
11
  export declare const toTronBase58IfHex: (addr: string) => string;
12
12
  export declare const addressToHexFormat: (addr: string) => string;
13
13
  export declare const normalizeTronAddr: (addr: string) => string;
14
+ export declare const getTronWalletRpcUrl: (chainId: number) => "https://nile.trongrid.io" | "https://api.trongrid.io";
14
15
  export declare const createTronCallData: (abi: ethers.InterfaceAbi, functionName: string, args: unknown[]) => string;
15
16
  export declare const getAvailableResource: (resources: TronAccountResources | undefined, limitKey: string, usedKey: string) => bigint;
16
17
  export declare const getChainParameterValue: (params: TronChainParameter[], key: string) => bigint;
@@ -191,4 +191,4 @@ var f = 2000n, p = (e) => {
191
191
  }
192
192
  };
193
193
  //#endregion
194
- export { _ as addressToHexFormat, N as approveTronTokens, M as assertTronSufficientBalance, k as circomDataToArray, b as createTronCallData, m as createTronWeb, T as estimateTronFeeSunWithPadding, h as evmHexToTronBase58Address, w as fetchTronAccountResources, C as fetchTronChainParameters, O as generateProofSignatureRemotely, x as getAvailableResource, S as getChainParameterValue, D as getVerifierId, p as normalizeTronPrivateKey, E as parseZkCalldata, A as reorderZkCallData, j as splitTronTokensByNative, g as toTronBase58IfHex };
194
+ export { _ as addressToHexFormat, N as approveTronTokens, M as assertTronSufficientBalance, k as circomDataToArray, b as createTronCallData, m as createTronWeb, T as estimateTronFeeSunWithPadding, h as evmHexToTronBase58Address, w as fetchTronAccountResources, C as fetchTronChainParameters, O as generateProofSignatureRemotely, x as getAvailableResource, S as getChainParameterValue, v as getTronWalletRpcUrl, D as getVerifierId, p as normalizeTronPrivateKey, E as parseZkCalldata, A as reorderZkCallData, j as splitTronTokensByNative, g as toTronBase58IfHex };
@@ -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/addresses.cjs`),l=require(`../../../API/scheduled-transactions-calls.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t,n,a,o,s,c,l,u)=>d.runExclusive(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)}),p=async(e,t,n,r)=>{let{utxos:a,encryptedOutputs:o,lastOutput:c}=await s.getInputUtxosEnclave(e,n,t);return i.setHinkalCache({encryptedOutputs:o,lastOutput:c},e,n,r),a},m=async(e,t,n,r,i,a,o,s,c)=>{try{return await p(e,t,n,i)}catch{return f(e,t,n,r,i,a,o,s,c)}},h=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},g=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),_=(e,t,r,i,a,o,s,c)=>{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:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0})),r)for(;e.length>6;)e.splice(e.length-1)},v=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=a??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);o&&i.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=i.getHinkalCache(e,t,u);await r.checkAddressNotUpdated(e,l);let b=y!==``,x=_.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1,w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E,O=[];T?O=await f(e,d,t,l,u,_,v,y,x):E?O=await m(e,d,t,l,u,_,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),await r.checkAddressNotUpdated(e,l);let k=await g(e,O,h);return{inputUtxos:c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked)}},y=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1,allowRemoteDecryption:o=!1})=>{let s=i??await t.getEthereumAddressByChain(n),d=c.hashEthereumAddress(e.isTronLike(n)?u.addressToHexFormat(s):s),{inputUtxos:f}=await v({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:s,resetCacheBefore:a,allowRemoteDecryption:o,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await l.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},b=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,allowRemoteDecryption:m=!1,useBlockedUtxos:g=!1})=>{let b=l??n.userKeys.getShieldedPrivateKey(),x=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:S}=g?await y({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await v({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=h(r),w=new Map;S.forEach(e=>{let n=e.getTokenAddress(c);if(C&&!C.some(e=>t.caseInsensitiveEqual(e.erc20TokenAddress,n)))return;let r=a.encodeTokenWithId(c,{erc20TokenAddress:n,tokenId:0}),i=w.get(r)??[];w.set(r,[...i,e])}),p?.forEach(e=>{let t=a.encodeTokenWithId(c,{erc20TokenAddress:e.erc20TokenAddress,tokenId:0});w.set(t,w.get(t)??[])});for(let[t,n]of w){let r=t.split(`-`)[0],a=Number(t.split(`-`)[1]),l=e.isSolanaLike(c),u=l?r:void 0;_(n,i,s,b,x,l?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),a,u)}return w};exports.attemptGetInputUtxosRemotely=m,exports.getInputUtxoAndBalance=v,exports.getInputUtxoAndBalanceOfStuckUtxos=y,exports.getInputUtxoAndBalancePerToken=b,exports.getInputUtxosRemotely=p;
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/addresses.cjs`),l=require(`../../../API/scheduled-transactions-calls.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t)=>e.allowParallelBalanceLocalDecryption?t():d.runExclusive(t),p=async(e,t,n,a,o,s,c,l,u)=>f(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)}),m=async(e,t,n,r)=>{let{utxos:a,encryptedOutputs:o,lastOutput:c}=await s.getInputUtxosEnclave(e,n,t);return i.setHinkalCache({encryptedOutputs:o,lastOutput:c},e,n,r),a},h=async(e,t,n,r,i,a,o,s,c)=>{try{return await m(e,t,n,i)}catch{return p(e,t,n,r,i,a,o,s,c)}},g=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},_=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),v=(e,t,r,i,a,o,s,c)=>{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:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0})),r)for(;e.length>6;)e.splice(e.length-1)},y=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=a??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,f=e.encryptedOutputsByChain[t],m=e.nullifiersByChain[t],g=Array.from(f);o&&i.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=i.getHinkalCache(e,t,u);await r.checkAddressNotUpdated(e,l);let b=y!==``,x=g.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1,w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E,O=[];T?O=await p(e,d,t,l,u,g,v,y,x):E?O=await h(e,d,t,l,u,g,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),await r.checkAddressNotUpdated(e,l);let k=await _(e,O,m);return{inputUtxos:c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked)}},b=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1,allowRemoteDecryption:o=!1})=>{let s=i??await t.getEthereumAddressByChain(n),d=c.hashEthereumAddress(e.isTronLike(n)?u.addressToHexFormat(s):s),{inputUtxos:f}=await y({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:s,resetCacheBefore:a,allowRemoteDecryption:o,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await l.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},x=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,allowRemoteDecryption:m=!1,useBlockedUtxos:h=!1})=>{let _=l??n.userKeys.getShieldedPrivateKey(),x=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:S}=h?await b({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await y({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=g(r),w=new Map;S.forEach(e=>{let n=e.getTokenAddress(c);if(C&&!C.some(e=>t.caseInsensitiveEqual(e.erc20TokenAddress,n)))return;let r=a.encodeTokenWithId(c,{erc20TokenAddress:n,tokenId:0}),i=w.get(r)??[];w.set(r,[...i,e])}),p?.forEach(e=>{let t=a.encodeTokenWithId(c,{erc20TokenAddress:e.erc20TokenAddress,tokenId:0});w.set(t,w.get(t)??[])});for(let[t,n]of w){let r=t.split(`-`)[0],a=Number(t.split(`-`)[1]),l=e.isSolanaLike(c),u=l?r:void 0;v(n,i,s,_,x,l?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),a,u)}return w};exports.attemptGetInputUtxosRemotely=h,exports.getInputUtxoAndBalance=y,exports.getInputUtxoAndBalanceOfStuckUtxos=b,exports.getInputUtxoAndBalancePerToken=x,exports.getInputUtxosRemotely=m;
@@ -11,29 +11,29 @@ import { getScheduledTransactionsNullifierIndexes as f } from "../../../API/sche
11
11
  import { addressToHexFormat as p } from "../../utils/tron.utils.mjs";
12
12
  import { Mutex as m } from "async-mutex";
13
13
  //#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
14
- var h = new m(), g = async (e, t, n, r, a, o, c, l, u) => h.runExclusive(async () => {
14
+ var h = new m(), g = async (e, t) => e.allowParallelBalanceLocalDecryption ? t() : h.runExclusive(t), _ = async (e, t, n, r, a, o, c, l, u) => g(e, async () => {
15
15
  u += 1;
16
16
  let d = o.slice(u), { lastOutput: f, additionalEncryptedOutputs: p } = await e.utxoUtils.batchProcess(d, l, t, n), m = [...c, ...p];
17
17
  return await i(e, r), s({
18
18
  lastOutput: f,
19
19
  encryptedOutputs: m
20
20
  }, e, n, a), await e.utxoUtils.buildBatchProcess(m, t, n);
21
- }), _ = async (e, t, n, r) => {
21
+ }), v = async (e, t, n, r) => {
22
22
  let { utxos: i, encryptedOutputs: a, lastOutput: o } = await u(e, n, t);
23
23
  return s({
24
24
  encryptedOutputs: a,
25
25
  lastOutput: o
26
26
  }, e, n, r), i;
27
- }, v = async (e, t, n, r, i, a, o, s, c) => {
27
+ }, y = async (e, t, n, r, i, a, o, s, c) => {
28
28
  try {
29
- return await _(e, t, n, i);
29
+ return await v(e, t, n, i);
30
30
  } catch {
31
- return g(e, t, n, r, i, a, o, s, c);
31
+ return _(e, t, n, r, i, a, o, s, c);
32
32
  }
33
- }, y = (e) => {
33
+ }, b = (e) => {
34
34
  if (Array.isArray(e)) return e;
35
35
  if (e !== void 0) return [e];
36
- }, b = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), x = (e, t, n, i, a, o, s, c) => {
36
+ }, x = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), S = (e, t, n, i, a, o, s, c) => {
37
37
  for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) if (e.push(new r({
38
38
  amount: 0n,
39
39
  erc20TokenAddress: o,
@@ -42,17 +42,17 @@ var h = new m(), g = async (e, t, n, r, a, o, c, l, u) => h.runExclusive(async (
42
42
  spendingPublicKey: a,
43
43
  isNewStyle: !0
44
44
  })), n) for (; e.length > 6;) e.splice(e.length - 1);
45
- }, S = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
45
+ }, C = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
46
46
  let u = r ?? await e.getEthereumAddress(), d = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: f } = e, p = e.encryptedOutputsByChain[t], m = e.nullifiersByChain[t], h = Array.from(p);
47
47
  s && o(e, t, d);
48
- let { encryptedOutputs: _, lastOutput: y } = a(e, t, d);
48
+ let { encryptedOutputs: g, lastOutput: v } = a(e, t, d);
49
49
  await i(e, u);
50
- let x = y !== "", S = h.findIndex((e) => e.value === y), C = S > -1, w = !x && S === -1, T = e.areMerkleTreeUpdatesDisabled(), E = !T && (C || !c && w), D = !T && c && w, O = !E && !D, k = [];
51
- E ? k = await g(e, f, t, u, d, h, _, y, S) : D ? k = await v(e, f, t, u, d, h, _, y, S) : O && (k = await e.utxoUtils.buildBatchProcess(_, f, t)), await i(e, u);
52
- let A = await b(e, k, m);
50
+ let b = v !== "", S = h.findIndex((e) => e.value === v), C = S > -1, w = !b && S === -1, T = e.areMerkleTreeUpdatesDisabled(), E = !T && (C || !c && w), D = !T && c && w, O = !E && !D, k = [];
51
+ E ? k = await _(e, f, t, u, d, h, g, v, S) : D ? k = await y(e, f, t, u, d, h, g, v, S) : O && (k = await e.utxoUtils.buildBatchProcess(g, f, t)), await i(e, u);
52
+ let A = await x(e, k, m);
53
53
  return { inputUtxos: l ? A.filter((e) => e.isBlocked) : A.filter((e) => !e.isBlocked) };
54
- }, C = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
55
- let s = i ?? await e.getEthereumAddressByChain(n), c = d(t(n) ? p(s) : s), { inputUtxos: l } = await S({
54
+ }, w = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
55
+ let s = i ?? await e.getEthereumAddressByChain(n), c = d(t(n) ? p(s) : s), { inputUtxos: l } = await C({
56
56
  hinkal: e,
57
57
  chainId: n,
58
58
  passedShieldedPublicKey: r,
@@ -67,15 +67,15 @@ var h = new m(), g = async (e, t, n, r, a, o, c, l, u) => h.runExclusive(async (
67
67
  nullifiers: l.map((e) => e.getNullifier())
68
68
  });
69
69
  return { inputUtxos: u.map((e) => l[e]).filter((e) => !!e) };
70
- }, w = async ({ hinkal: t, tokenWithId: r, minInput: i = 2, sliceIfMore6: a = !0, chainId: o, passedShieldedPrivateKey: s = void 0, passedShieldedPublicKey: u = void 0, ethAddress: d = void 0, resetCacheBefore: f = !1, ensuredTokensWithId: p, allowRemoteDecryption: m = !1, useBlockedUtxos: h = !1 }) => {
71
- let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await C({
70
+ }, T = async ({ hinkal: t, tokenWithId: r, minInput: i = 2, sliceIfMore6: a = !0, chainId: o, passedShieldedPrivateKey: s = void 0, passedShieldedPublicKey: u = void 0, ethAddress: d = void 0, resetCacheBefore: f = !1, ensuredTokensWithId: p, allowRemoteDecryption: m = !1, useBlockedUtxos: h = !1 }) => {
71
+ let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await w({
72
72
  hinkal: t,
73
73
  chainId: o,
74
74
  ethAddress: d,
75
75
  passedShieldedPrivateKey: s,
76
76
  resetCacheBefore: f,
77
77
  allowRemoteDecryption: m
78
- }) : await S({
78
+ }) : await C({
79
79
  hinkal: t,
80
80
  tokenWithId: r,
81
81
  minInput: i,
@@ -86,27 +86,27 @@ var h = new m(), g = async (e, t, n, r, a, o, c, l, u) => h.runExclusive(async (
86
86
  ethAddress: d,
87
87
  resetCacheBefore: f,
88
88
  allowRemoteDecryption: m
89
- }), b = y(r), w = /* @__PURE__ */ new Map();
89
+ }), y = b(r), x = /* @__PURE__ */ new Map();
90
90
  v.forEach((e) => {
91
91
  let t = e.getTokenAddress(o);
92
- if (b && !b.some((e) => n(e.erc20TokenAddress, t))) return;
92
+ if (y && !y.some((e) => n(e.erc20TokenAddress, t))) return;
93
93
  let r = c(o, {
94
94
  erc20TokenAddress: t,
95
95
  tokenId: 0
96
- }), i = w.get(r) ?? [];
97
- w.set(r, [...i, e]);
96
+ }), i = x.get(r) ?? [];
97
+ x.set(r, [...i, e]);
98
98
  }), p?.forEach((e) => {
99
99
  let t = c(o, {
100
100
  erc20TokenAddress: e.erc20TokenAddress,
101
101
  tokenId: 0
102
102
  });
103
- w.set(t, w.get(t) ?? []);
103
+ x.set(t, x.get(t) ?? []);
104
104
  });
105
- for (let [t, n] of w) {
105
+ for (let [t, n] of x) {
106
106
  let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), u = c ? r : void 0;
107
- x(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
107
+ S(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
108
108
  }
109
- return w;
109
+ return x;
110
110
  };
111
111
  //#endregion
112
- export { v as attemptGetInputUtxosRemotely, S as getInputUtxoAndBalance, C as getInputUtxoAndBalanceOfStuckUtxos, w as getInputUtxoAndBalancePerToken, _ as getInputUtxosRemotely };
112
+ export { y as attemptGetInputUtxosRemotely, C as getInputUtxoAndBalance, w as getInputUtxoAndBalanceOfStuckUtxos, T as getInputUtxoAndBalancePerToken, v as getInputUtxosRemotely };
@@ -1 +1 @@
1
- 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(`./getInputUtxoAndBalance.cjs`),u=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),d=require(`../../utils/mutexes.utils.cjs`),f=require(`../../utils/erc20tokenFunctions.cjs`);var p=async(t,r,i,a,o,s=!1,c,p=!1,m=!1)=>d.getChainBalanceFetchingMutex(r).runExclusive(async()=>{let{inputUtxos:d}=m?await l.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:o,passedShieldedPrivateKey:i,resetCacheBefore:s,allowRemoteDecryption:c}):await l.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:a,ethAddress:o,resetCacheBefore:s,allowRemoteDecryption:c});p&&e.isExtension&&await u.privateTokensDB.fetchAndUpdatePrivateTokens(d.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,o);let h=(e.isExtension?await u.privateTokensDB.getPrivateTokens(r,o):await f.getErc20TokensForChainAPI(r)).map(e=>({token:e,balance:d.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:d.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),g=new Map;return h.forEach(e=>{g.set(e.token.erc20TokenAddress.toLowerCase(),e)}),g}),m=async(e,n,u,d,p=6,m=u.map(()=>0),h=!1,g=!1)=>{let{userKeys:_}=e,v=_.getSpendingKeyPair().pubSpendingBJJPoint,y=[],b=[];if(u.length===0)return[];let x=await l.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:u.map((e,t)=>({erc20TokenAddress:u[t],tokenId:m[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:g,chainId:n}),S=0;for(let e=0;e<u.length;e+=1)if(h===!1){let t=x.get(s.encodeTokenWithId(n,{erc20TokenAddress:u[e],tokenId:m[e]}))??[];if(!t)throw Error(`Missing utxos for token`);S=Math.max(t.length,S),b.push(t)}else b.push([]);if(S===2)return b;for(let[e,s]of b.entries())if(s.length>p){let t=s.slice(0,p),a=t.reduce((e,t)=>e+t.amount,0n);if(d[e]<0n&&a<-d[e]){let t=await f.getErc20TokenFromAPI(n,u[e]),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.`)}y.push(t)}else if(s.length<=p){let r=[...s],i=p-s.length;for(;i>0;){--i;let o=t.isSolanaLike(n),s=o?u[e]:void 0,l=o?c.formatMintAddress(u[e]).compressedAddress:u[e];r.push(new a.Utxo({amount:0n,erc20TokenAddress:l,mintAddress:s,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0}))}y.push(r)}return y};exports.addPaddingToUtxos=m,exports.getShieldedBalance=p;
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(`./getInputUtxoAndBalance.cjs`),u=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),d=require(`../../utils/map.utils.cjs`),f=require(`../../utils/mutexes.utils.cjs`),p=require(`../../utils/erc20tokenFunctions.cjs`);let m=require(`async-mutex`);var h=async(t,r,i,a,o,s=!1,c,h=!1,g=!1)=>d.getOrCreateMapValue(t.balanceFetchingMutexByChain,r,()=>new m.Mutex).runExclusive(async()=>f.getChainBalanceFetchingMutex(r).runShared(async()=>{let{inputUtxos:d}=g?await l.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:o,passedShieldedPrivateKey:i,resetCacheBefore:s,allowRemoteDecryption:c}):await l.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:a,ethAddress:o,resetCacheBefore:s,allowRemoteDecryption:c});h&&e.isExtension&&await u.privateTokensDB.fetchAndUpdatePrivateTokens(d.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,o);let f=(e.isExtension?await u.privateTokensDB.getPrivateTokens(r,o):await p.getErc20TokensForChainAPI(r)).map(e=>({token:e,balance:d.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:d.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),m=new Map;return f.forEach(e=>{m.set(e.token.erc20TokenAddress.toLowerCase(),e)}),m})),g=async(e,n,u,d,f=6,m=u.map(()=>0),h=!1,g=!1)=>{let{userKeys:_}=e,v=_.getSpendingKeyPair().pubSpendingBJJPoint,y=[],b=[];if(u.length===0)return[];if(h){for(let e=0;e<u.length;e+=1){let r=t.isSolanaLike(n),i=r?u[e]:void 0,o=r?c.formatMintAddress(u[e]).compressedAddress:u[e];y.push(Array.from({length:f},()=>new a.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:i,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0})))}return y}let x=await l.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:u.map((e,t)=>({erc20TokenAddress:u[t],tokenId:m[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:g,chainId:n}),S=0;for(let e=0;e<u.length;e+=1){let t=x.get(s.encodeTokenWithId(n,{erc20TokenAddress:u[e],tokenId:m[e]}))??[];if(!t)throw Error(`Missing utxos for token`);S=Math.max(t.length,S),b.push(t)}if(S===2)return b;for(let[e,s]of b.entries())if(s.length>f){let t=s.slice(0,f),a=t.reduce((e,t)=>e+t.amount,0n);if(d[e]<0n&&a<-d[e]){let t=await p.getErc20TokenFromAPI(n,u[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.`)}y.push(t)}else if(s.length<=f){let r=[...s],i=f-s.length;for(;i>0;){--i;let o=t.isSolanaLike(n),s=o?u[e]:void 0,l=o?c.formatMintAddress(u[e]).compressedAddress:u[e];r.push(new a.Utxo({amount:0n,erc20TokenAddress:l,mintAddress:s,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0}))}y.push(r)}return y};exports.addPaddingToUtxos=g,exports.getShieldedBalance=h;
@@ -10,11 +10,13 @@ import { encodeTokenWithId as s } from "../../utils/encodeTokenWithId.mjs";
10
10
  import { formatMintAddress as c } from "../../utils/solanaMint.utils.mjs";
11
11
  import { getInputUtxoAndBalance as l, getInputUtxoAndBalanceOfStuckUtxos as u, getInputUtxoAndBalancePerToken as d } from "./getInputUtxoAndBalance.mjs";
12
12
  import { privateTokensDB as f } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
13
- import { getChainBalanceFetchingMutex as p } from "../../utils/mutexes.utils.mjs";
14
- import { getErc20TokenFromAPI as m, getErc20TokensForChainAPI as h } from "../../utils/erc20tokenFunctions.mjs";
13
+ import { getOrCreateMapValue as p } from "../../utils/map.utils.mjs";
14
+ import { getChainBalanceFetchingMutex as m } from "../../utils/mutexes.utils.mjs";
15
+ import { getErc20TokenFromAPI as h, getErc20TokensForChainAPI as g } from "../../utils/erc20tokenFunctions.mjs";
16
+ import { Mutex as _ } from "async-mutex";
15
17
  //#region libs/shared/common/src/functions/web3/events/getShieldedBalance.ts
16
- var g = async (t, r, i, a, o, s = !1, c, d = !1, m = !1) => p(r).runExclusive(async () => {
17
- let { inputUtxos: p } = m ? await u({
18
+ var v = async (t, r, i, a, o, s = !1, c, d = !1, h = !1) => p(t.balanceFetchingMutexByChain, r, () => new _()).runExclusive(async () => m(r).runShared(async () => {
19
+ let { inputUtxos: p } = h ? await u({
18
20
  hinkal: t,
19
21
  chainId: r,
20
22
  ethAddress: o,
@@ -32,7 +34,7 @@ var g = async (t, r, i, a, o, s = !1, c, d = !1, m = !1) => p(r).runExclusive(as
32
34
  allowRemoteDecryption: c
33
35
  });
34
36
  d && e && await f.fetchAndUpdatePrivateTokens(p.map((e) => e.getTokenAddress(r)).filter((e) => e !== void 0), r, o);
35
- let g = (e ? await f.getPrivateTokens(r, o) : await h(r)).map((e) => ({
37
+ let m = (e ? await f.getPrivateTokens(r, o) : await g(r)).map((e) => ({
36
38
  token: e,
37
39
  balance: p.reduce((t, i) => {
38
40
  let a = e.erc20TokenAddress;
@@ -41,12 +43,26 @@ var g = async (t, r, i, a, o, s = !1, c, d = !1, m = !1) => p(r).runExclusive(as
41
43
  timestamp: p.filter((t) => n(t.getTokenAddress(r), e.erc20TokenAddress))[0]?.timeStamp,
42
44
  nfts: []
43
45
  })), _ = /* @__PURE__ */ new Map();
44
- return g.forEach((e) => {
46
+ return m.forEach((e) => {
45
47
  _.set(e.token.erc20TokenAddress.toLowerCase(), e);
46
48
  }), _;
47
- }), _ = async (e, n, l, u, f = 6, p = l.map(() => 0), h = !1, g = !1) => {
49
+ })), y = async (e, n, l, u, f = 6, p = l.map(() => 0), m = !1, g = !1) => {
48
50
  let { userKeys: _ } = e, v = _.getSpendingKeyPair().pubSpendingBJJPoint, y = [], b = [];
49
51
  if (l.length === 0) return [];
52
+ if (m) {
53
+ for (let e = 0; e < l.length; e += 1) {
54
+ let r = t(n), i = r ? l[e] : void 0, o = r ? c(l[e]).compressedAddress : l[e];
55
+ y.push(Array.from({ length: f }, () => new a({
56
+ amount: 0n,
57
+ erc20TokenAddress: o,
58
+ mintAddress: i,
59
+ nullifyingKey: _.getShieldedPrivateKey(),
60
+ spendingPublicKey: v,
61
+ isNewStyle: !0
62
+ })));
63
+ }
64
+ return y;
65
+ }
50
66
  let x = await d({
51
67
  hinkal: e,
52
68
  sliceIfMore6: !1,
@@ -58,19 +74,21 @@ var g = async (t, r, i, a, o, s = !1, c, d = !1, m = !1) => p(r).runExclusive(as
58
74
  useBlockedUtxos: g,
59
75
  chainId: n
60
76
  }), S = 0;
61
- for (let e = 0; e < l.length; e += 1) if (h === !1) {
77
+ for (let e = 0; e < l.length; e += 1) {
62
78
  let t = x.get(s(n, {
63
79
  erc20TokenAddress: l[e],
64
80
  tokenId: p[e]
65
81
  })) ?? [];
66
82
  if (!t) throw Error("Missing utxos for token");
67
83
  S = Math.max(t.length, S), b.push(t);
68
- } else b.push([]);
84
+ }
69
85
  if (S === 2) return b;
70
86
  for (let [e, s] of b.entries()) if (s.length > f) {
71
87
  let t = s.slice(0, f), a = t.reduce((e, t) => e + t.amount, 0n);
72
88
  if (u[e] < 0n && a < -u[e]) {
73
- let t = await m(n, l[e]), s = t.decimals === 18 ? 6 : 2, c = Number(i(a, t, s));
89
+ let t = await h(n, l[e]);
90
+ if (!t) throw Error("Token not found");
91
+ let s = t.decimals === 18 ? 6 : 2, c = Number(i(a, t, s));
74
92
  throw new o(c, `${r.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`);
75
93
  }
76
94
  y.push(t);
@@ -93,4 +111,4 @@ var g = async (t, r, i, a, o, s = !1, c, d = !1, m = !1) => p(r).runExclusive(as
93
111
  return y;
94
112
  };
95
113
  //#endregion
96
- export { _ as addPaddingToUtxos, g as getShieldedBalance };
114
+ export { y as addPaddingToUtxos, v as getShieldedBalance };
@@ -1 +1 @@
1
- require(`./getInputUtxoAndBalance.cjs`),require(`./getShieldedBalance.cjs`),require(`./balanceChangedHandler.cjs`),require(`./getTransactionLogEvents.cjs`);
1
+ require(`./getInputUtxoAndBalance.cjs`),require(`./getShieldedBalance.cjs`),require(`./getTransactionLogEvents.cjs`);
@@ -1,4 +1,3 @@
1
1
  export * from './getInputUtxoAndBalance';
2
2
  export * from './getShieldedBalance';
3
- export * from './balanceChangedHandler';
4
3
  export * from './getTransactionLogEvents';
@@ -1,4 +1,3 @@
1
1
  import "./getInputUtxoAndBalance.mjs";
2
2
  import "./getShieldedBalance.mjs";
3
- import "./balanceChangedHandler.mjs";
4
3
  import "./getTransactionLogEvents.mjs";
@@ -1 +1 @@
1
- require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/protocol.constants.cjs`),t=require(`../../../types/ethereum-network.types.cjs`),n=require(`../../utils/time.utils.cjs`),r=require(`../../utils/getContractAddress.cjs`),i=require(`./recoverTransactionFromError.cjs`),a=require(`./approveTokensToHinkal.cjs`),o=require(`./constructBatchCall.cjs`),s=require(`./waitForErc20Approvals.cjs`);let c=require(`ethers`);var l=async(l,u,d,f,p,m,h,g,_,v=!0,y=!1)=>{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.getContractWithSigner(u,t.ContractType.HinkalContract),C=await l.getEthereumAddressByChain(u),w=g??S,T=_??S,E=`transact`,D=x.findIndex(({erc20TokenAddress:t})=>t===e.zeroAddress),O=x.some(({erc20TokenAddress:t})=>t!==e.zeroAddress),k=D===-1?0n:b[D],A=l.getProviderAdapter(u),j=await A.supportsBatchCall?.(u);if(!y&&O&&j&&A.sendBatchCallsTransaction){let e=o.buildApproveAndTransactCalls(x.map(e=>e.erc20TokenAddress),b,r.getContractAddress(w),T,p,h,m,k);return await A.sendBatchCallsTransaction(u,e)}if(!y&&(await a.approveTokensToHinkal(l,u,w,x,b),O)){let e=x.map(({erc20TokenAddress:e},t)=>({tokenAddress:e,requiredAmount:b[t]}));await s.waitForErc20Approvals(l,u,C,r.getContractAddress(w),e)}let M={value:k>0n?BigInt(k).toString():void 0,gasLimit:void 0},N,P=[p[0],p[1],p[2],h,m,{...M,from:C}],{runner:F}=T;if(!(F instanceof c.ethers.AbstractSigner))throw Error(`expected signer`);if(v)try{N=Number(await T[E].estimateGas(...P))}catch(e){console.log(`hinkalDeposit: gas estimation error`,{err:e})}let I=N&&N>=0?Math.ceil(N*12/10):void 0;I&&(P[5].gasLimit=I),await n.waitLittle();let L;try{L=y?await T[E].populateTransaction(...P):await T[E](...P)}catch(e){if(!e?.transactionHash)throw e;let t=await i.recoverTransactionFromError(F.provider,e.transactionHash);if(!t)throw e;L=t}return L};exports.transactCallDirect=l;
1
+ require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/protocol.constants.cjs`),t=require(`../../utils/time.utils.cjs`),n=require(`../../../types/ethereum-network.types.cjs`),r=require(`../../utils/getContractAddress.cjs`),i=require(`./recoverTransactionFromError.cjs`),a=require(`./approveTokensToHinkal.cjs`),o=require(`./constructBatchCall.cjs`),s=require(`./waitForErc20Approvals.cjs`);let c=require(`ethers`);var l=async(l,u,d,f,p,m,h,g,_,v=!0,y=!1)=>{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.getContractWithSigner(u,n.ContractType.HinkalContract),C=await l.getEthereumAddressByChain(u),w=g??S,T=_??S,E=`transact`,D=x.findIndex(({erc20TokenAddress:t})=>t===e.zeroAddress),O=x.some(({erc20TokenAddress:t})=>t!==e.zeroAddress),k=D===-1?0n:b[D],A=l.getProviderAdapter(u),j=await A.supportsBatchCall?.(u);if(!y&&O&&j&&A.sendBatchCallsTransaction){let e=o.buildApproveAndTransactCalls(x.map(e=>e.erc20TokenAddress),b,r.getContractAddress(w),T,p,h,m,k);return await A.sendBatchCallsTransaction(u,e)}if(!y&&(await a.approveTokensToHinkal(l,u,w,x,b),O)){let e=x.map(({erc20TokenAddress:e},t)=>({tokenAddress:e,requiredAmount:b[t]}));await s.waitForErc20Approvals(l,u,C,r.getContractAddress(w),e)}let M={value:k>0n?BigInt(k).toString():void 0,gasLimit:void 0},N,P=[p[0],p[1],p[2],h,m,{...M,from:C}],{runner:F}=T;if(!(F instanceof c.ethers.AbstractSigner))throw Error(`expected signer`);if(v)try{N=Number(await T[E].estimateGas(...P))}catch(e){console.log(`hinkalDeposit: gas estimation error`,{err:e})}let I=N&&N>=0?Math.ceil(N*12/10):void 0;I&&(P[5].gasLimit=I),await t.waitLittle();let L;try{L=y?await T[E].populateTransaction(...P):await T[E](...P)}catch(e){if(!e?.transactionHash)throw e;let t=await i.recoverTransactionFromError(F.provider,e.transactionHash);if(!t)throw e;L=t}return L};exports.transactCallDirect=l;