@hinkal/common 0.2.21 → 0.2.22

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 (516) hide show
  1. package/API/API.cjs +1 -1
  2. package/API/API.d.ts +14 -14
  3. package/API/API.mjs +88 -87
  4. package/API/admin-calls.cjs +1 -1
  5. package/API/admin-calls.d.ts +1 -1
  6. package/API/admin-calls.mjs +4 -4
  7. package/API/ai-calls.cjs +1 -0
  8. package/API/ai-calls.d.ts +17 -0
  9. package/API/ai-calls.mjs +21 -0
  10. package/API/callLifiAPI.cjs +1 -1
  11. package/API/callLifiAPI.d.ts +1 -1
  12. package/API/callLifiAPI.mjs +5 -5
  13. package/API/callMonitor.cjs +1 -1
  14. package/API/callMonitor.d.ts +1 -1
  15. package/API/callMonitor.mjs +7 -7
  16. package/API/callOdosAPI.cjs +1 -1
  17. package/API/callOdosAPI.mjs +11 -11
  18. package/API/callOkxAPI.cjs +1 -1
  19. package/API/callOkxAPI.d.ts +1 -1
  20. package/API/callOkxAPI.mjs +5 -5
  21. package/API/callOneInchAPI.cjs +1 -1
  22. package/API/callOneInchAPI.mjs +11 -10
  23. package/API/callRelayer.cjs +1 -1
  24. package/API/callRelayer.d.ts +5 -6
  25. package/API/callRelayer.mjs +11 -11
  26. package/API/checkRisk.cjs +1 -1
  27. package/API/checkRisk.d.ts +1 -1
  28. package/API/checkRisk.mjs +4 -4
  29. package/API/deposit-and-withdraw-status-calls.cjs +1 -0
  30. package/API/deposit-and-withdraw-status-calls.d.ts +20 -0
  31. package/API/deposit-and-withdraw-status-calls.mjs +18 -0
  32. package/API/duneAPI.cjs +1 -0
  33. package/API/duneAPI.d.ts +11 -0
  34. package/API/duneAPI.mjs +25 -0
  35. package/API/enclaveCalls.cjs +1 -1
  36. package/API/enclaveCalls.mjs +4 -5
  37. package/API/fetchCommitmentsCache.cjs +1 -1
  38. package/API/fetchCommitmentsCache.mjs +9 -9
  39. package/API/get-token-data.cjs +1 -1
  40. package/API/get-token-data.d.ts +1 -1
  41. package/API/get-token-data.mjs +5 -5
  42. package/API/getBridgeProtocols.cjs +1 -0
  43. package/API/getBridgeProtocols.d.ts +7 -0
  44. package/API/getBridgeProtocols.mjs +8 -0
  45. package/API/getGasEstimates.cjs +1 -1
  46. package/API/getGasEstimates.mjs +9 -9
  47. package/API/getLifiStatus.cjs +1 -0
  48. package/API/getLifiStatus.d.ts +24 -0
  49. package/API/getLifiStatus.mjs +15 -0
  50. package/API/getRelayerURL.cjs +1 -0
  51. package/API/getRelayerURL.d.ts +1 -0
  52. package/API/getRelayerURL.mjs +10 -0
  53. package/API/getServerURL.cjs +1 -1
  54. package/API/getServerURL.d.ts +3 -3
  55. package/API/getServerURL.mjs +67 -51
  56. package/API/getTokenPrice.cjs +1 -1
  57. package/API/getTokenPrice.d.ts +0 -5
  58. package/API/getTokenPrice.mjs +7 -14
  59. package/API/index.d.ts +3 -1
  60. package/API/is-tx-stateless.cjs +1 -1
  61. package/API/is-tx-stateless.d.ts +1 -1
  62. package/API/is-tx-stateless.mjs +12 -10
  63. package/API/kycCalls.cjs +1 -1
  64. package/API/kycCalls.d.ts +8 -4
  65. package/API/kycCalls.mjs +26 -23
  66. package/API/passwordCalls.cjs +1 -0
  67. package/API/passwordCalls.d.ts +9 -0
  68. package/API/passwordCalls.mjs +13 -0
  69. package/API/proxyAccountsCalls.cjs +1 -1
  70. package/API/proxyAccountsCalls.d.ts +2 -7
  71. package/API/proxyAccountsCalls.mjs +21 -27
  72. package/API/relayCalls.cjs +1 -1
  73. package/API/relayCalls.mjs +4 -4
  74. package/API/restoreSnapshots.cjs +1 -0
  75. package/API/restoreSnapshots.d.ts +1 -0
  76. package/API/restoreSnapshots.mjs +10 -0
  77. package/API/scheduled-transactions-calls.cjs +1 -1
  78. package/API/scheduled-transactions-calls.d.ts +9 -1
  79. package/API/scheduled-transactions-calls.mjs +9 -5
  80. package/API/simulate-batch-tx.cjs +1 -1
  81. package/API/simulate-batch-tx.d.ts +2 -2
  82. package/API/simulate-batch-tx.mjs +6 -7
  83. package/API/solana-calls.cjs +1 -1
  84. package/API/solana-calls.d.ts +3 -6
  85. package/API/solana-calls.mjs +15 -15
  86. package/API/temporaryWalletCalls.cjs +1 -1
  87. package/API/temporaryWalletCalls.mjs +19 -13
  88. package/API/token-calls.cjs +1 -1
  89. package/API/token-calls.mjs +5 -6
  90. package/README.md +54 -42
  91. package/constants/chains.constants.cjs +1 -1
  92. package/constants/chains.constants.d.ts +6 -0
  93. package/constants/chains.constants.mjs +52 -58
  94. package/constants/coingecko.constants.cjs +1 -1
  95. package/constants/coingecko.constants.d.ts +0 -1
  96. package/constants/coingecko.constants.mjs +10 -11
  97. package/constants/deploy-data/deploy-data-solana.json.cjs +1 -1
  98. package/constants/deploy-data/deploy-data-solana.json.mjs +2 -28
  99. package/constants/function-signatures.constants.cjs +1 -1
  100. package/constants/function-signatures.constants.d.ts +1 -0
  101. package/constants/function-signatures.constants.mjs +4 -3
  102. package/constants/kyc.constants.cjs +1 -1
  103. package/constants/kyc.constants.mjs +40 -39
  104. package/constants/mediaUrls.constants.cjs +1 -1
  105. package/constants/mediaUrls.constants.d.ts +0 -1
  106. package/constants/mediaUrls.constants.mjs +1 -2
  107. package/constants/permit2.constants.cjs +1 -1
  108. package/constants/permit2.constants.d.ts +1 -0
  109. package/constants/permit2.constants.mjs +11 -10
  110. package/constants/server.constants.cjs +1 -1
  111. package/constants/server.constants.d.ts +123 -19
  112. package/constants/server.constants.mjs +142 -38
  113. package/constants/vite.constants.cjs +1 -1
  114. package/constants/vite.constants.mjs +13 -36
  115. package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
  116. package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +71 -68
  117. package/data-structures/Hinkal/Hinkal.cjs +1 -1
  118. package/data-structures/Hinkal/Hinkal.d.ts +56 -45
  119. package/data-structures/Hinkal/Hinkal.mjs +348 -314
  120. package/data-structures/Hinkal/IHinkal.d.ts +54 -40
  121. package/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
  122. package/data-structures/Hinkal/handleAutoDepositBack.d.ts +1 -1
  123. package/data-structures/Hinkal/handleAutoDepositBack.mjs +49 -48
  124. package/data-structures/Hinkal/hinkalActionFundApproveAndTransact.cjs +1 -0
  125. package/data-structures/Hinkal/hinkalActionFundApproveAndTransact.d.ts +7 -0
  126. package/data-structures/Hinkal/hinkalActionFundApproveAndTransact.mjs +42 -0
  127. package/data-structures/Hinkal/hinkalActionReceive.cjs +1 -1
  128. package/data-structures/Hinkal/hinkalActionReceive.mjs +24 -29
  129. package/data-structures/Hinkal/hinkalApprove.cjs +1 -0
  130. package/data-structures/Hinkal/hinkalApprove.d.ts +3 -0
  131. package/data-structures/Hinkal/hinkalApprove.mjs +114 -0
  132. package/data-structures/Hinkal/hinkalCheckTokenRegistry.cjs +1 -1
  133. package/data-structures/Hinkal/hinkalCheckTokenRegistry.mjs +20 -20
  134. package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
  135. package/data-structures/Hinkal/hinkalDeposit.mjs +84 -88
  136. package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
  137. package/data-structures/Hinkal/hinkalDepositAndWithdraw.d.ts +1 -1
  138. package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +96 -77
  139. package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
  140. package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +4 -1
  141. package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +80 -75
  142. package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
  143. package/data-structures/Hinkal/hinkalDepostAndBridge.d.ts +1 -1
  144. package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +150 -138
  145. package/data-structures/Hinkal/hinkalGetZkMeProvider.cjs +1 -1
  146. package/data-structures/Hinkal/hinkalGetZkMeProvider.mjs +5 -4
  147. package/data-structures/Hinkal/hinkalInsideTransact.cjs +1 -0
  148. package/data-structures/Hinkal/hinkalInsideTransact.d.ts +4 -0
  149. package/data-structures/Hinkal/hinkalInsideTransact.mjs +119 -0
  150. package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
  151. package/data-structures/Hinkal/hinkalPrivateWallet.d.ts +2 -2
  152. package/data-structures/Hinkal/hinkalPrivateWallet.mjs +118 -114
  153. package/data-structures/Hinkal/hinkalProoflessDeposit.cjs +1 -1
  154. package/data-structures/Hinkal/hinkalProoflessDeposit.mjs +34 -36
  155. package/data-structures/Hinkal/hinkalProxySwap.cjs +1 -1
  156. package/data-structures/Hinkal/hinkalProxySwap.mjs +36 -40
  157. package/data-structures/Hinkal/hinkalProxyToPrivate.cjs +1 -1
  158. package/data-structures/Hinkal/hinkalProxyToPrivate.mjs +32 -37
  159. package/data-structures/Hinkal/hinkalSignSubAccount.cjs +1 -1
  160. package/data-structures/Hinkal/hinkalSignSubAccount.d.ts +2 -1
  161. package/data-structures/Hinkal/hinkalSignSubAccount.mjs +15 -17
  162. package/data-structures/Hinkal/hinkalSolanaDeposit.cjs +1 -1
  163. package/data-structures/Hinkal/hinkalSolanaDeposit.d.ts +3 -4
  164. package/data-structures/Hinkal/hinkalSolanaDeposit.mjs +95 -84
  165. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
  166. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.d.ts +1 -2
  167. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +182 -155
  168. package/data-structures/Hinkal/hinkalSolanaProxySend.cjs +1 -1
  169. package/data-structures/Hinkal/hinkalSolanaProxySend.d.ts +3 -2
  170. package/data-structures/Hinkal/hinkalSolanaProxySend.mjs +40 -43
  171. package/data-structures/Hinkal/hinkalSolanaProxyShield.cjs +1 -1
  172. package/data-structures/Hinkal/hinkalSolanaProxyShield.mjs +67 -71
  173. package/data-structures/Hinkal/hinkalSolanaProxySwap.cjs +1 -1
  174. package/data-structures/Hinkal/hinkalSolanaProxySwap.d.ts +1 -1
  175. package/data-structures/Hinkal/hinkalSolanaProxySwap.mjs +59 -63
  176. package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
  177. package/data-structures/Hinkal/hinkalSolanaSwap.mjs +45 -48
  178. package/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
  179. package/data-structures/Hinkal/hinkalSolanaTransfer.mjs +48 -49
  180. package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
  181. package/data-structures/Hinkal/hinkalSolanaWithdraw.d.ts +1 -2
  182. package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +68 -71
  183. package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
  184. package/data-structures/Hinkal/hinkalSwap.mjs +78 -71
  185. package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
  186. package/data-structures/Hinkal/hinkalTransfer.mjs +70 -71
  187. package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
  188. package/data-structures/Hinkal/hinkalWithdraw.mjs +79 -81
  189. package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
  190. package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +103 -105
  191. package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
  192. package/data-structures/Hinkal/resetMerkleTrees.d.ts +1 -1
  193. package/data-structures/Hinkal/resetMerkleTrees.mjs +53 -107
  194. package/data-structures/IndexedDB/activity-db.cjs +1 -1
  195. package/data-structures/IndexedDB/activity-db.d.ts +0 -1
  196. package/data-structures/IndexedDB/activity-db.mjs +75 -91
  197. package/data-structures/IndexedDB/balances-db.cjs +1 -1
  198. package/data-structures/IndexedDB/balances-db.mjs +37 -40
  199. package/data-structures/IndexedDB/contact-db.cjs +1 -1
  200. package/data-structures/IndexedDB/contact-db.mjs +13 -16
  201. package/data-structures/IndexedDB/signatures-db.cjs +1 -1
  202. package/data-structures/IndexedDB/signatures-db.mjs +40 -25
  203. package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
  204. package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +84 -82
  205. package/data-structures/TokenDBs/token-visibility-db.cjs +1 -1
  206. package/data-structures/TokenDBs/token-visibility-db.mjs +36 -22
  207. package/data-structures/crypto-keys/keys.cjs +1 -1
  208. package/data-structures/crypto-keys/keys.d.ts +11 -0
  209. package/data-structures/crypto-keys/keys.mjs +107 -47
  210. package/data-structures/event-service/evm/AbstractAccessTokenSnapshotService.cjs +1 -1
  211. package/data-structures/event-service/evm/AbstractAccessTokenSnapshotService.d.ts +2 -3
  212. package/data-structures/event-service/evm/AbstractAccessTokenSnapshotService.mjs +9 -9
  213. package/data-structures/event-service/evm/AbstractApprovalsSnapshotService.cjs +1 -1
  214. package/data-structures/event-service/evm/AbstractApprovalsSnapshotService.d.ts +2 -3
  215. package/data-structures/event-service/evm/AbstractApprovalsSnapshotService.mjs +5 -5
  216. package/data-structures/event-service/evm/AbstractCommitmentsSnapshotService.cjs +1 -1
  217. package/data-structures/event-service/evm/AbstractCommitmentsSnapshotService.d.ts +2 -3
  218. package/data-structures/event-service/evm/AbstractCommitmentsSnapshotService.mjs +6 -6
  219. package/data-structures/event-service/evm/AbstractEventService.cjs +1 -1
  220. package/data-structures/event-service/evm/AbstractEventService.d.ts +2 -4
  221. package/data-structures/event-service/evm/AbstractEventService.mjs +19 -19
  222. package/data-structures/event-service/evm/AbstractNullifierSnapshotService.cjs +1 -1
  223. package/data-structures/event-service/evm/AbstractNullifierSnapshotService.d.ts +3 -3
  224. package/data-structures/event-service/evm/AbstractNullifierSnapshotService.mjs +5 -6
  225. package/data-structures/event-service/evm/AbstractSnapshotService.cjs +1 -1
  226. package/data-structures/event-service/evm/AbstractSnapshotService.d.ts +2 -1
  227. package/data-structures/event-service/evm/AbstractSnapshotService.mjs +4 -3
  228. package/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
  229. package/data-structures/event-service/evm/BlockchainEventEmitter.d.ts +5 -10
  230. package/data-structures/event-service/evm/BlockchainEventEmitter.mjs +35 -39
  231. package/data-structures/event-service/index.d.ts +0 -4
  232. package/data-structures/event-service/solana/AbstractSolanaAccessTokenSnapshotService.cjs +1 -1
  233. package/data-structures/event-service/solana/AbstractSolanaAccessTokenSnapshotService.d.ts +2 -3
  234. package/data-structures/event-service/solana/AbstractSolanaAccessTokenSnapshotService.mjs +6 -6
  235. package/data-structures/event-service/solana/AbstractSolanaCommitmentsSnapshotService.cjs +1 -1
  236. package/data-structures/event-service/solana/AbstractSolanaCommitmentsSnapshotService.d.ts +3 -4
  237. package/data-structures/event-service/solana/AbstractSolanaCommitmentsSnapshotService.mjs +8 -8
  238. package/data-structures/event-service/solana/AbstractSolanaEventService.cjs +1 -1
  239. package/data-structures/event-service/solana/AbstractSolanaEventService.d.ts +10 -4
  240. package/data-structures/event-service/solana/AbstractSolanaEventService.mjs +7 -10
  241. package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.cjs +1 -1
  242. package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.d.ts +2 -3
  243. package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.mjs +1 -1
  244. package/data-structures/event-service/solana/AbstractSolanaSnapshotService.cjs +1 -1
  245. package/data-structures/event-service/solana/AbstractSolanaSnapshotService.d.ts +2 -1
  246. package/data-structures/event-service/solana/AbstractSolanaSnapshotService.mjs +2 -1
  247. package/data-structures/event-service/solana/SolanaBlockchainEventEmitter.cjs +1 -1
  248. package/data-structures/event-service/solana/SolanaBlockchainEventEmitter.d.ts +16 -11
  249. package/data-structures/event-service/solana/SolanaBlockchainEventEmitter.mjs +66 -64
  250. package/data-structures/index.d.ts +0 -3
  251. package/data-structures/provider-adapter/IProviderAdapter.d.ts +13 -8
  252. package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.cjs +1 -1
  253. package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.mjs +4 -6
  254. package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.cjs +1 -1
  255. package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.mjs +4 -6
  256. package/data-structures/snapshot/evm-snapshots/ClientCommitmentsSnapshotService.cjs +1 -1
  257. package/data-structures/snapshot/evm-snapshots/ClientCommitmentsSnapshotService.mjs +4 -6
  258. package/data-structures/snapshot/evm-snapshots/ClientNullifierSnapshotService.cjs +1 -1
  259. package/data-structures/snapshot/evm-snapshots/ClientNullifierSnapshotService.mjs +4 -6
  260. package/data-structures/snapshot/solana-snapshots/ClientSolanaAccessTokenSnapshotService.cjs +1 -1
  261. package/data-structures/snapshot/solana-snapshots/ClientSolanaAccessTokenSnapshotService.mjs +4 -6
  262. package/data-structures/snapshot/solana-snapshots/ClientSolanaCommitmentsSnapshotService.cjs +1 -1
  263. package/data-structures/snapshot/solana-snapshots/ClientSolanaCommitmentsSnapshotService.mjs +4 -5
  264. package/data-structures/snapshot/solana-snapshots/ClientSolanaNullifierSnapshotService.cjs +1 -1
  265. package/data-structures/snapshot/solana-snapshots/ClientSolanaNullifierSnapshotService.mjs +4 -6
  266. package/error-handling/error-codes.constants.cjs +1 -1
  267. package/error-handling/error-codes.constants.d.ts +0 -1
  268. package/error-handling/error-codes.constants.mjs +3 -4
  269. package/error-handling/get-error.message.cjs +1 -1
  270. package/error-handling/get-error.message.mjs +27 -21
  271. package/error-handling/handleErrorRestore.cjs +1 -0
  272. package/error-handling/handleErrorRestore.d.ts +2 -0
  273. package/error-handling/handleErrorRestore.mjs +11 -0
  274. package/error-handling/index.d.ts +1 -0
  275. package/functions/kyc/authentoHelper.cjs +1 -0
  276. package/functions/kyc/authentoHelper.d.ts +12 -0
  277. package/functions/kyc/authentoHelper.mjs +30 -0
  278. package/functions/kyc/zkMeHelper.cjs +1 -1
  279. package/functions/kyc/zkMeHelper.mjs +17 -18
  280. package/functions/pre-transaction/constructAdminData.cjs +1 -1
  281. package/functions/pre-transaction/constructAdminData.d.ts +2 -2
  282. package/functions/pre-transaction/constructAdminData.mjs +18 -12
  283. package/functions/pre-transaction/getExternalSwapAddress.cjs +1 -1
  284. package/functions/pre-transaction/getExternalSwapAddress.d.ts +2 -1
  285. package/functions/pre-transaction/getExternalSwapAddress.mjs +8 -8
  286. package/functions/pre-transaction/getVolatileTransferAmount.cjs +1 -1
  287. package/functions/pre-transaction/getVolatileTransferAmount.mjs +36 -21
  288. package/functions/pre-transaction/merge-with-fee-structure-emporium.cjs +1 -1
  289. package/functions/pre-transaction/merge-with-fee-structure-emporium.d.ts +1 -1
  290. package/functions/pre-transaction/merge-with-fee-structure-emporium.mjs +17 -17
  291. package/functions/pre-transaction/outputApprovalDataProcessing.cjs +1 -1
  292. package/functions/pre-transaction/outputApprovalDataProcessing.d.ts +9 -1
  293. package/functions/pre-transaction/outputApprovalDataProcessing.mjs +34 -19
  294. package/functions/pre-transaction/sendV0Transaction.cjs +1 -1
  295. package/functions/pre-transaction/sendV0Transaction.mjs +50 -53
  296. package/functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs +1 -1
  297. package/functions/pre-transaction/shouldPatchAccessTokenMerkleTree.d.ts +1 -1
  298. package/functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs +4 -4
  299. package/functions/private-wallet/emporium.helpers.cjs +1 -1
  300. package/functions/private-wallet/emporium.helpers.d.ts +6 -3
  301. package/functions/private-wallet/emporium.helpers.mjs +127 -89
  302. package/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
  303. package/functions/private-wallet/emporium.swap.helpers.d.ts +4 -1
  304. package/functions/private-wallet/emporium.swap.helpers.mjs +102 -100
  305. package/functions/snarkjs/constructEmporiumProof.cjs +1 -1
  306. package/functions/snarkjs/constructEmporiumProof.mjs +49 -49
  307. package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
  308. package/functions/snarkjs/constructSolanaZkProof.mjs +20 -18
  309. package/functions/snarkjs/fetchMerkleTreeSiblings.cjs +1 -1
  310. package/functions/snarkjs/fetchMerkleTreeSiblings.mjs +10 -11
  311. package/functions/utils/addresses.cjs +1 -1
  312. package/functions/utils/addresses.d.ts +0 -1
  313. package/functions/utils/addresses.mjs +12 -13
  314. package/functions/utils/cacheFunctions.cjs +1 -1
  315. package/functions/utils/cacheFunctions.mjs +2 -2
  316. package/functions/utils/create-provider.cjs +1 -1
  317. package/functions/utils/create-provider.d.ts +1 -1
  318. package/functions/utils/create-provider.mjs +9 -13
  319. package/functions/utils/get-hinkal-approvals.cjs +1 -0
  320. package/functions/utils/get-hinkal-approvals.d.ts +3 -0
  321. package/functions/utils/get-hinkal-approvals.mjs +38 -0
  322. package/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
  323. package/functions/utils/getUtxosFromReceipt.utils.d.ts +1 -1
  324. package/functions/utils/getUtxosFromReceipt.utils.mjs +11 -11
  325. package/functions/utils/index.d.ts +1 -0
  326. package/functions/utils/involves-permit2-op.cjs +1 -1
  327. package/functions/utils/involves-permit2-op.d.ts +1 -0
  328. package/functions/utils/involves-permit2-op.mjs +6 -4
  329. package/functions/utils/mutexes.utils.cjs +1 -1
  330. package/functions/utils/mutexes.utils.d.ts +1 -1
  331. package/functions/utils/mutexes.utils.mjs +3 -3
  332. package/functions/utils/nftTokenFunctions.cjs +1 -1
  333. package/functions/utils/nftTokenFunctions.mjs +23 -8
  334. package/functions/utils/prepareHinkal.cjs +1 -1
  335. package/functions/utils/prepareHinkal.d.ts +13 -6
  336. package/functions/utils/prepareHinkal.mjs +72 -45
  337. package/functions/utils/publicBalance.utils.cjs +1 -1
  338. package/functions/utils/publicBalance.utils.mjs +54 -49
  339. package/functions/utils/replaceAddressInCalldata.cjs +1 -0
  340. package/functions/utils/replaceAddressInCalldata.d.ts +1 -0
  341. package/functions/utils/replaceAddressInCalldata.mjs +7 -0
  342. package/functions/utils/string.utils.cjs +1 -1
  343. package/functions/utils/string.utils.d.ts +0 -1
  344. package/functions/utils/string.utils.mjs +14 -18
  345. package/functions/utils/token-check.utils.cjs +1 -1
  346. package/functions/utils/token-check.utils.d.ts +0 -3
  347. package/functions/utils/token-check.utils.mjs +7 -18
  348. package/functions/utils/upToDateState.cjs +1 -1
  349. package/functions/utils/upToDateState.d.ts +1 -1
  350. package/functions/utils/upToDateState.mjs +4 -4
  351. package/functions/utils/walletBalances.utils.cjs +1 -1
  352. package/functions/utils/walletBalances.utils.d.ts +17 -2
  353. package/functions/utils/walletBalances.utils.mjs +36 -5
  354. package/functions/web3/events/getApprovedBalance.cjs +1 -1
  355. package/functions/web3/events/getApprovedBalance.d.ts +4 -3
  356. package/functions/web3/events/getApprovedBalance.mjs +44 -39
  357. package/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
  358. package/functions/web3/events/getInputUtxoAndBalance.d.ts +3 -3
  359. package/functions/web3/events/getInputUtxoAndBalance.mjs +150 -129
  360. package/functions/web3/events/getShieldedBalance.cjs +2 -2
  361. package/functions/web3/events/getShieldedBalance.d.ts +1 -1
  362. package/functions/web3/events/getShieldedBalance.mjs +75 -73
  363. package/functions/web3/events/getTransactionLogEvents.cjs +1 -1
  364. package/functions/web3/events/getTransactionLogEvents.mjs +38 -38
  365. package/functions/web3/fetchSolanaMerkleTreeRootHash.cjs +1 -1
  366. package/functions/web3/fetchSolanaMerkleTreeRootHash.mjs +10 -13
  367. package/functions/web3/functionCalls/accessTokenCalls.cjs +1 -1
  368. package/functions/web3/functionCalls/accessTokenCalls.d.ts +6 -1
  369. package/functions/web3/functionCalls/accessTokenCalls.mjs +21 -12
  370. package/functions/web3/functionCalls/approveToken.cjs +1 -1
  371. package/functions/web3/functionCalls/approveToken.d.ts +1 -1
  372. package/functions/web3/functionCalls/approveToken.mjs +46 -50
  373. package/functions/web3/functionCalls/approveTokensToHinkal.cjs +1 -1
  374. package/functions/web3/functionCalls/approveTokensToHinkal.d.ts +1 -1
  375. package/functions/web3/functionCalls/approveTokensToHinkal.mjs +6 -6
  376. package/functions/web3/functionCalls/estimateGasRelayer.cjs +1 -1
  377. package/functions/web3/functionCalls/estimateGasRelayer.d.ts +2 -1
  378. package/functions/web3/functionCalls/estimateGasRelayer.mjs +10 -10
  379. package/functions/web3/functionCalls/inHinkalApprovalCalls.cjs +1 -0
  380. package/functions/web3/functionCalls/inHinkalApprovalCalls.d.ts +5 -0
  381. package/functions/web3/functionCalls/inHinkalApprovalCalls.mjs +32 -0
  382. package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
  383. package/functions/web3/functionCalls/transactCallDirect.d.ts +1 -1
  384. package/functions/web3/functionCalls/transactCallDirect.mjs +40 -36
  385. package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
  386. package/functions/web3/functionCalls/transactCallRelayer.d.ts +3 -3
  387. package/functions/web3/functionCalls/transactCallRelayer.mjs +54 -54
  388. package/functions/web3/getContractMetadata.cjs +1 -1
  389. package/functions/web3/getContractMetadata.mjs +22 -17
  390. package/functions/web3/getPublicAddressBalance.cjs +1 -1
  391. package/functions/web3/getPublicAddressBalance.d.ts +1 -1
  392. package/functions/web3/getPublicAddressBalance.mjs +6 -6
  393. package/functions/web3/getTokenHolder.cjs +1 -1
  394. package/functions/web3/getTokenHolder.mjs +27 -27
  395. package/functions/web3/index.d.ts +0 -1
  396. package/functions/web3/lifiAPI.cjs +1 -1
  397. package/functions/web3/lifiAPI.d.ts +1 -1
  398. package/functions/web3/lifiAPI.mjs +12 -12
  399. package/functions/web3/odosAPI.cjs +1 -1
  400. package/functions/web3/odosAPI.mjs +19 -6
  401. package/functions/web3/okxAPI.cjs +1 -1
  402. package/functions/web3/okxAPI.mjs +13 -13
  403. package/functions/web3/oneInchAPI.cjs +1 -1
  404. package/functions/web3/oneInchAPI.mjs +20 -7
  405. package/functions/web3/runContractFunction.cjs +1 -1
  406. package/functions/web3/runContractFunction.mjs +56 -38
  407. package/functions/web3/uniswapAPI.cjs +1 -1
  408. package/functions/web3/uniswapAPI.mjs +34 -22
  409. package/index.cjs +1 -1
  410. package/index.mjs +922 -920
  411. package/package.json +2 -3
  412. package/providers/EthersProviderAdapter.cjs +1 -1
  413. package/providers/EthersProviderAdapter.d.ts +17 -10
  414. package/providers/EthersProviderAdapter.mjs +76 -45
  415. package/providers/SolanaProviderAdapter.cjs +1 -1
  416. package/providers/SolanaProviderAdapter.d.ts +11 -7
  417. package/providers/SolanaProviderAdapter.mjs +31 -16
  418. package/providers/WagmiProviderAdapter.cjs +1 -1
  419. package/providers/WagmiProviderAdapter.d.ts +17 -11
  420. package/providers/WagmiProviderAdapter.mjs +117 -86
  421. package/providers/prepareEthersHinkal.cjs +1 -1
  422. package/providers/prepareEthersHinkal.mjs +9 -14
  423. package/providers/prepareWagmiHinkal.cjs +1 -1
  424. package/providers/prepareWagmiHinkal.mjs +9 -15
  425. package/types/TransactionSimulator.types.d.ts +9 -2
  426. package/types/activities.types.d.ts +0 -2
  427. package/types/admin.types.cjs +1 -1
  428. package/types/admin.types.d.ts +6 -0
  429. package/types/admin.types.mjs +2 -2
  430. package/types/balances.types.d.ts +1 -0
  431. package/types/bridging.types.d.ts +29 -0
  432. package/types/cache.types.cjs +1 -1
  433. package/types/cache.types.d.ts +3 -6
  434. package/types/cache.types.mjs +1 -1
  435. package/types/coingecko.types.d.ts +0 -5
  436. package/types/duneAPI.types.d.ts +9 -0
  437. package/types/ethereum-network.types.d.ts +0 -1
  438. package/types/hinkal.types.cjs +1 -1
  439. package/types/hinkal.types.d.ts +1 -1
  440. package/types/hinkal.types.mjs +18 -18
  441. package/types/index.d.ts +2 -2
  442. package/types/proxy.types.d.ts +3 -6
  443. package/types/sandbox.types.cjs +1 -1
  444. package/types/sandbox.types.d.ts +39 -10
  445. package/types/sandbox.types.mjs +2 -2
  446. package/types/scheduled-transactions.types.cjs +1 -1
  447. package/types/scheduled-transactions.types.d.ts +6 -0
  448. package/types/scheduled-transactions.types.mjs +3 -2
  449. package/types/session.types.d.ts +0 -2
  450. package/types/solana.types.d.ts +0 -9
  451. package/types/token-prices.types.cjs +1 -1
  452. package/types/token-prices.types.d.ts +0 -7
  453. package/types/token-prices.types.mjs +2 -4
  454. package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
  455. package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
  456. package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
  457. package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
  458. package/webworker/viteWorkerURL.constant.cjs +3 -3
  459. package/webworker/viteWorkerURL.constant.mjs +3 -3
  460. package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
  461. package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
  462. package/API/get-token-price-chart-data.cjs +0 -1
  463. package/API/get-token-price-chart-data.d.ts +0 -16
  464. package/API/get-token-price-chart-data.mjs +0 -13
  465. package/API/onrampCalls.cjs +0 -1
  466. package/API/onrampCalls.d.ts +0 -20
  467. package/API/onrampCalls.mjs +0 -15
  468. package/API/unspent-utxos-calls.cjs +0 -1
  469. package/API/unspent-utxos-calls.d.ts +0 -26
  470. package/API/unspent-utxos-calls.mjs +0 -26
  471. package/data-structures/AccountActions/AccountActions.cjs +0 -1
  472. package/data-structures/AccountActions/AccountActions.d.ts +0 -18
  473. package/data-structures/AccountActions/AccountActions.mjs +0 -78
  474. package/data-structures/AccountActions/index.d.ts +0 -1
  475. package/data-structures/BlockchainEvent/BlockchainEvent.cjs +0 -1
  476. package/data-structures/BlockchainEvent/BlockchainEvent.d.ts +0 -14
  477. package/data-structures/BlockchainEvent/BlockchainEvent.mjs +0 -41
  478. package/data-structures/PublicBalance/PublicBalanceWatcher.cjs +0 -1
  479. package/data-structures/PublicBalance/PublicBalanceWatcher.d.ts +0 -20
  480. package/data-structures/PublicBalance/PublicBalanceWatcher.mjs +0 -124
  481. package/data-structures/PublicBalance/SolanaPublicBalancerWatcher.cjs +0 -1
  482. package/data-structures/PublicBalance/SolanaPublicBalancerWatcher.d.ts +0 -15
  483. package/data-structures/PublicBalance/SolanaPublicBalancerWatcher.mjs +0 -64
  484. package/data-structures/PublicBalance/index.d.ts +0 -2
  485. package/data-structures/event-service/evm/ClientBlockchainEventEmitter.cjs +0 -1
  486. package/data-structures/event-service/evm/ClientBlockchainEventEmitter.d.ts +0 -11
  487. package/data-structures/event-service/evm/ClientBlockchainEventEmitter.mjs +0 -21
  488. package/data-structures/event-service/evm/PollingBlockchainEventEmitter.cjs +0 -1
  489. package/data-structures/event-service/evm/PollingBlockchainEventEmitter.d.ts +0 -6
  490. package/data-structures/event-service/evm/PollingBlockchainEventEmitter.mjs +0 -16
  491. package/data-structures/event-service/helpers/ClientEventHelper.cjs +0 -1
  492. package/data-structures/event-service/helpers/ClientEventHelper.d.ts +0 -11
  493. package/data-structures/event-service/helpers/ClientEventHelper.mjs +0 -26
  494. package/data-structures/event-service/helpers/PollingEventHelper.cjs +0 -1
  495. package/data-structures/event-service/helpers/PollingEventHelper.d.ts +0 -5
  496. package/data-structures/event-service/helpers/PollingEventHelper.mjs +0 -14
  497. package/data-structures/event-service/solana/ClientSolanaBlockchainEventEmitter.cjs +0 -1
  498. package/data-structures/event-service/solana/ClientSolanaBlockchainEventEmitter.d.ts +0 -11
  499. package/data-structures/event-service/solana/ClientSolanaBlockchainEventEmitter.mjs +0 -22
  500. package/data-structures/event-service/solana/PollingSolanaBlockchainEventEmitter.cjs +0 -1
  501. package/data-structures/event-service/solana/PollingSolanaBlockchainEventEmitter.d.ts +0 -6
  502. package/data-structures/event-service/solana/PollingSolanaBlockchainEventEmitter.mjs +0 -16
  503. package/functions/utils/enum.utils.cjs +0 -1
  504. package/functions/utils/enum.utils.mjs +0 -14
  505. package/functions/utils/socket.utils.cjs +0 -1
  506. package/functions/utils/socket.utils.d.ts +0 -1
  507. package/functions/utils/socket.utils.mjs +0 -12
  508. package/functions/web3/crypto.cjs +0 -1
  509. package/functions/web3/crypto.d.ts +0 -1
  510. package/functions/web3/crypto.mjs +0 -7
  511. package/types/events.types.cjs +0 -1
  512. package/types/events.types.d.ts +0 -9
  513. package/types/events.types.mjs +0 -5
  514. package/types/onramp.types.cjs +0 -1
  515. package/types/onramp.types.d.ts +0 -58
  516. package/types/onramp.types.mjs +0 -4
@@ -1,2 +1,17 @@
1
- import { ERC20Token } from '../../types/token.types';
2
- export declare const hasEnoughBalance: (tokenAmount: string, maxPossibleAmount: string, token: ERC20Token | undefined, isDollarMode: boolean, tokenPriceDollar: number | undefined) => boolean;
1
+ import { IHinkal } from '../../data-structures/Hinkal/IHinkal';
2
+ import { ERC20Token, TokenBalance, TokenChanges } from '../../types/token.types';
3
+ import { SubAccount } from '../../types/proxy.types';
4
+ export declare const getNecessaryAssetsForFundingFromBalance: (tokenChanges: TokenChanges<bigint>[], subAccountBalances: TokenBalance[]) => {
5
+ fundAmounts: bigint[];
6
+ tokensToFund: ERC20Token[];
7
+ };
8
+ export declare const getNecessaryAssetsForFunding: (hinkal: IHinkal, subAccount: SubAccount, tokenChanges: TokenChanges<bigint>[]) => Promise<{
9
+ fundAmounts: bigint[];
10
+ tokensToFund: ERC20Token[];
11
+ approveTokenAddresses: string[];
12
+ approvedTokenAmounts: bigint[];
13
+ }>;
14
+ export declare const getNecessaryApprovalChangesData: (hinkal: IHinkal, tokenChanges: TokenChanges<bigint>[], to: string) => {
15
+ approvalChanges: bigint[];
16
+ };
17
+ export declare function hasEnoughBalance(tokenAmount: string, maxPossibleAmount: string, token?: ERC20Token, isDollarMode?: boolean, tokenPriceDollar?: number): boolean;
@@ -1,11 +1,42 @@
1
- import { getAmountInWei as f } from "../web3/etherFunctions.mjs";
2
- const a = (r, u, t, c, e) => {
1
+ import { zeroAddress as f } from "../../constants/protocol.constants.mjs";
2
+ import { absBigInt as c } from "./amounts.utils.mjs";
3
+ import { caseInsensitiveEqual as l } from "./caseInsensitive.utils.mjs";
4
+ import { getPublicBalancesOfTokens as g } from "./publicBalance.utils.mjs";
5
+ import { getAmountInWei as m } from "../web3/etherFunctions.mjs";
6
+ import { UserKeys as v } from "../../data-structures/crypto-keys/keys.mjs";
7
+ const T = (t, s) => t?.length ? t.reduce(
8
+ (r, { amount: u, token: e }) => {
9
+ if (u >= 0n)
10
+ return r;
11
+ const o = -u, d = s.find(
12
+ (p) => l(p.token.erc20TokenAddress, e.erc20TokenAddress)
13
+ )?.balance ?? 0n;
14
+ return d < o && (r.tokensToFund.push(e), r.fundAmounts.push(o - d)), r;
15
+ },
16
+ { fundAmounts: [], tokensToFund: [] }
17
+ ) : { fundAmounts: [], tokensToFund: [] }, K = async (t, s, n) => {
18
+ if (!n?.length)
19
+ return { fundAmounts: [], tokensToFund: [], approveTokenAddresses: [], approvedTokenAmounts: [] };
20
+ const r = t.getCurrentChainId(), u = v.getSignerAddressFromPrivateKey(r, s.privateKey), e = await g(
21
+ r,
22
+ u,
23
+ n.map(({ token: a }) => a)
24
+ ), { fundAmounts: o, tokensToFund: d } = T(n, e), p = n.length ? n.filter(({ amount: a, token: A }) => a < 0n && A.erc20TokenAddress !== f).map(({ token: a }) => a.erc20TokenAddress) : [], i = p.map(() => 2n ** 256n - 1n);
25
+ return { fundAmounts: o, tokensToFund: d, approveTokenAddresses: p, approvedTokenAmounts: i };
26
+ }, N = (t, s, n) => {
27
+ const r = s.map((e) => e.amount < 0n ? t.getMyApprovalAmountForInteraction(n, e.token.erc20TokenAddress) : 0n);
28
+ return { approvalChanges: s.map((e, o) => e.amount < 0n && r[o] > 0n ? c(e.amount) < c(r[o]) ? e.amount : -r[o] : 0n) };
29
+ };
30
+ function k(t, s, n, r, u) {
3
31
  try {
4
- return !t || !r ? !0 : c ? e ? +r * e <= +u : !0 : f(t, r) <= f(t, u);
32
+ return !n || !t ? !0 : r ? u ? +t * u <= +s : !0 : m(n, t) <= m(n, s);
5
33
  } catch {
6
34
  return !0;
7
35
  }
8
- };
36
+ }
9
37
  export {
10
- a as hasEnoughBalance
38
+ N as getNecessaryApprovalChangesData,
39
+ K as getNecessaryAssetsForFunding,
40
+ T as getNecessaryAssetsForFundingFromBalance,
41
+ k as hasEnoughBalance
11
42
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("../../utils/caseInsensitive.utils.cjs"),l=require("../../utils/cacheFunctions.cjs"),f=require("async-mutex"),m=require("../../utils/erc20tokenFunctions.cjs"),A=require("../../../data-structures/TokenDBs/PrivateTokensDB.cjs"),g=require("../../../constants/vite.constants.cjs"),y=new f.Mutex,x=(t,e,a)=>(t.forEach(s=>{s.inHinkalAddress===a&&e.push(s)}),e),v=(t,e,a=!1)=>{const{userKeys:s}=t;a&&l.resetInHinkalAddressesCache(t,e,s.getShieldedPublicKey());const{approvalsByChain:i}=t,n=l.getInHinkalAddressesCache(t,e,s.getShieldedPublicKey());let o=[];return i[e].forEach((p,u)=>{const r=n[u];let c;r?c=BigInt(r):(c=s.getInHinkalAddress(u),n[u]=c.toString()),o=x(p.map(d=>({...d,interactionAddress:u,chainId:e})),o,c)}),l.setInHinkalAddressesCache(n,t,e,s.getShieldedPublicKey()),o},T=(t,e,a,s)=>v(t,a,s).filter(n=>k.caseInsensitiveEqual(n.tokenAddress,e)).sort((n,o)=>n.amount===o.amount?0:n.amount>o.amount?-1:1),B=async(t,e,a,s)=>{const i=await t.getEthereumAddressByChain(e);let n=[];const o=new Map;return await y.runExclusive(async()=>{const p=v(t,e,a);s&&g.isExtension&&await A.privateTokensDB.fetchAndUpdatePrivateTokens(p.map(r=>r.tokenAddress),e,i),n=(g.isExtension?await A.privateTokensDB.getPrivateTokens(e,i):m.getErc20TokensForChain(e)).map(r=>({token:r,balance:p.reduce((c,d)=>k.caseInsensitiveEqual(r.erc20TokenAddress,d.tokenAddress)?c+d.amount:c,0n),timestamp:"0",nfts:[]})),n.forEach(r=>{o.set(r.token.erc20TokenAddress.toLowerCase(),r)})}),o};exports.getApprovedBalance=B;exports.getApprovedUtxos=v;exports.getApprovedUtxosForToken=T;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("../../utils/caseInsensitive.utils.cjs"),l=require("../../utils/cacheFunctions.cjs"),k=require("async-mutex"),y=require("ethers"),I=require("../../utils/erc20tokenFunctions.cjs"),g=require("../../../data-structures/TokenDBs/PrivateTokensDB.cjs"),m=require("../../../constants/vite.constants.cjs"),h=new k.Mutex,f=(e,c,n)=>(e.forEach(t=>{t.inHinkalAddress===n&&c.push(t)}),c),v=(e,c=!1)=>{const{userKeys:n}=e,t=e.getCurrentChainId();c&&l.resetInHinkalAddressesCache(e,t,n.getShieldedPublicKey());const{approvals:o}=e,r=l.getInHinkalAddressesCache(e,t,n.getShieldedPublicKey());let i=[];return o.forEach((d,u)=>{const s=r[u];let a;s?a=BigInt(s):(a=n.getInHinkalAddress(u),r[u]=a.toString()),i=f(d.map(p=>({...p,interactionAddress:u})),i,a)}),l.setInHinkalAddressesCache(r,e,t,n.getShieldedPublicKey()),i},x=(e,c,n)=>v(e,n).filter(o=>A.caseInsensitiveEqual(o.tokenAddress,c)).sort((o,r)=>o.amount===r.amount?0:o.amount>r.amount?-1:1),E=async(e,c,n)=>{const t=e.getCurrentChainId(),o=await e.getEthereumAddress();let r=[];const i=new Map;return await h.runExclusive(async()=>{const d=v(e,c);n&&m.isExtension&&await g.privateTokensDB.fetchAndUpdatePrivateTokens(d.map(s=>s.tokenAddress),t,o),r=(m.isExtension?await g.privateTokensDB.getPrivateTokens(t,o):I.getErc20TokensForChain(t)).map(s=>({token:s,balance:d.reduce((a,p)=>A.caseInsensitiveEqual(s.erc20TokenAddress,p.tokenAddress)?a+p.amount:a,0n),timestamp:"0",nfts:[]})),r.forEach(s=>{i.set(s.token.erc20TokenAddress.toLowerCase(),s)})}),i},T=(e,c,n)=>{const{userKeys:t,approvals:o}=e,r=y.ethers.utils.getAddress(c),i=o.get(r)??[],d=t.getInHinkalAddress(r);return i.reduce((s,a)=>A.caseInsensitiveEqual(a.tokenAddress,n)&&a.inHinkalAddress===d?s+a.amount:s,0n)};exports.getApprovedBalance=E;exports.getApprovedUtxos=v;exports.getApprovedUtxosForToken=x;exports.getMyApprovalAmountForInteraction=T;
@@ -1,6 +1,7 @@
1
1
  import type { ApprovedUtxoWithInteractionAddress } from '../../../types/hinkal.types';
2
2
  import { type IHinkal } from '../../../data-structures/Hinkal/IHinkal';
3
3
  import type { TokenBalance } from '../../../types/token.types';
4
- export declare const getApprovedUtxos: (hinkal: IHinkal, chainId: number, resetCacheBefore?: boolean) => ApprovedUtxoWithInteractionAddress[];
5
- export declare const getApprovedUtxosForToken: (hinkal: IHinkal, erc20Address: string, chainId: number, resetCacheBefore: boolean) => ApprovedUtxoWithInteractionAddress[];
6
- export declare const getApprovedBalance: (hinkal: IHinkal, chainId: number, resetCacheBefore: boolean, updateTokensListBefore: boolean) => Promise<Map<string, TokenBalance>>;
4
+ export declare const getApprovedUtxos: (hinkal: IHinkal, resetCacheBefore?: boolean) => ApprovedUtxoWithInteractionAddress[];
5
+ export declare const getApprovedUtxosForToken: (hinkal: IHinkal, erc20Address: string, resetCacheBefore: boolean) => ApprovedUtxoWithInteractionAddress[];
6
+ export declare const getApprovedBalance: (hinkal: IHinkal, resetCacheBefore: boolean, updateTokensListBefore: boolean) => Promise<Map<string, TokenBalance>>;
7
+ export declare const getMyApprovalAmountForInteraction: (hinkal: IHinkal, interactionAddress: string, tokenAddress: string) => bigint;
@@ -1,49 +1,54 @@
1
- import { caseInsensitiveEqual as f } from "../../utils/caseInsensitive.utils.mjs";
1
+ import { caseInsensitiveEqual as u } from "../../utils/caseInsensitive.utils.mjs";
2
2
  import { resetInHinkalAddressesCache as g, getInHinkalAddressesCache as v, setInHinkalAddressesCache as k } from "../../utils/cacheFunctions.mjs";
3
- import { Mutex as y } from "async-mutex";
4
- import { getErc20TokensForChain as x } from "../../utils/erc20tokenFunctions.mjs";
5
- import { privateTokensDB as m } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
6
- import { isExtension as u } from "../../../constants/vite.constants.mjs";
7
- const C = new y(), E = (t, e, a) => (t.forEach((s) => {
8
- s.inHinkalAddress === a && e.push(s);
9
- }), e), A = (t, e, a = !1) => {
10
- const { userKeys: s } = t;
11
- a && g(t, e, s.getShieldedPublicKey());
12
- const { approvalsByChain: i } = t, r = v(t, e, s.getShieldedPublicKey());
13
- let n = [];
14
- return i[e].forEach((l, d) => {
15
- const o = r[d];
16
- let p;
17
- o ? p = BigInt(o) : (p = s.getInHinkalAddress(d), r[d] = p.toString()), n = E(
18
- l.map(
19
- (c) => ({ ...c, interactionAddress: d, chainId: e })
3
+ import { Mutex as h } from "async-mutex";
4
+ import { ethers as y } from "ethers";
5
+ import { getErc20TokensForChain as I } from "../../utils/erc20tokenFunctions.mjs";
6
+ import { privateTokensDB as l } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
7
+ import { isExtension as A } from "../../../constants/vite.constants.mjs";
8
+ const C = new h(), H = (e, d, r) => (e.forEach((t) => {
9
+ t.inHinkalAddress === r && d.push(t);
10
+ }), d), f = (e, d = !1) => {
11
+ const { userKeys: r } = e, t = e.getCurrentChainId();
12
+ d && g(e, t, r.getShieldedPublicKey());
13
+ const { approvals: o } = e, n = v(e, t, r.getShieldedPublicKey());
14
+ let i = [];
15
+ return o.forEach((c, p) => {
16
+ const s = n[p];
17
+ let a;
18
+ s ? a = BigInt(s) : (a = r.getInHinkalAddress(p), n[p] = a.toString()), i = H(
19
+ c.map(
20
+ (m) => ({ ...m, interactionAddress: p })
20
21
  ),
21
- n,
22
- p
22
+ i,
23
+ a
23
24
  );
24
- }), k(r, t, e, s.getShieldedPublicKey()), n;
25
- }, K = (t, e, a, s) => A(t, a, s).filter((r) => f(r.tokenAddress, e)).sort((r, n) => r.amount === n.amount ? 0 : r.amount > n.amount ? -1 : 1), M = async (t, e, a, s) => {
26
- const i = await t.getEthereumAddressByChain(e);
27
- let r = [];
28
- const n = /* @__PURE__ */ new Map();
25
+ }), k(n, e, t, r.getShieldedPublicKey()), i;
26
+ }, P = (e, d, r) => f(e, r).filter((o) => u(o.tokenAddress, d)).sort((o, n) => o.amount === n.amount ? 0 : o.amount > n.amount ? -1 : 1), S = async (e, d, r) => {
27
+ const t = e.getCurrentChainId(), o = await e.getEthereumAddress();
28
+ let n = [];
29
+ const i = /* @__PURE__ */ new Map();
29
30
  return await C.runExclusive(async () => {
30
- const l = A(t, e, a);
31
- s && u && await m.fetchAndUpdatePrivateTokens(
32
- l.map((o) => o.tokenAddress),
33
- e,
34
- i
35
- ), r = (u ? await m.getPrivateTokens(e, i) : x(e)).map((o) => ({
36
- token: o,
37
- balance: l.reduce((p, c) => f(o.erc20TokenAddress, c.tokenAddress) ? p + c.amount : p, 0n),
31
+ const c = f(e, d);
32
+ r && A && await l.fetchAndUpdatePrivateTokens(
33
+ c.map((s) => s.tokenAddress),
34
+ t,
35
+ o
36
+ ), n = (A ? await l.getPrivateTokens(t, o) : I(t)).map((s) => ({
37
+ token: s,
38
+ balance: c.reduce((a, m) => u(s.erc20TokenAddress, m.tokenAddress) ? a + m.amount : a, 0n),
38
39
  timestamp: "0",
39
40
  nfts: []
40
- })), r.forEach((o) => {
41
- n.set(o.token.erc20TokenAddress.toLowerCase(), o);
41
+ })), n.forEach((s) => {
42
+ i.set(s.token.erc20TokenAddress.toLowerCase(), s);
42
43
  });
43
- }), n;
44
+ }), i;
45
+ }, U = (e, d, r) => {
46
+ const { userKeys: t, approvals: o } = e, n = y.utils.getAddress(d), i = o.get(n) ?? [], c = t.getInHinkalAddress(n);
47
+ return i.reduce((s, a) => u(a.tokenAddress, r) && a.inHinkalAddress === c ? s + a.amount : s, 0n);
44
48
  };
45
49
  export {
46
- M as getApprovedBalance,
47
- A as getApprovedUtxos,
48
- K as getApprovedUtxosForToken
50
+ S as getApprovedBalance,
51
+ f as getApprovedUtxos,
52
+ P as getApprovedUtxosForToken,
53
+ U as getMyApprovalAmountForInteraction
49
54
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../../../data-structures/utxo/Utxo.cjs"),B=require("../../utils/upToDateState.cjs"),O=require("../../utils/cacheFunctions.cjs"),I=require("../../utils/caseInsensitive.utils.cjs"),q=require("../../utils/encodeTokenWithId.cjs"),K=require("./getInputUtxosEnclave.cjs"),L=require("../../utils/solanaMint.utils.cjs"),M=require("../../../constants/chains.constants.cjs"),N=require("../../utils/addresses.cjs"),R=require("../../../API/unspent-utxos-calls.cjs"),F=require("async-mutex"),z=new F.Mutex,k=async(t,e,s,r,o,a,c,n,d)=>z.runExclusive(async()=>{d+=1;const A=a.slice(d),{lastOutput:w,additionalEncryptedOutputs:f}=await t.utxoUtils.batchProcess(A,n,e,s),p=[...c,...f];return await B.checkAddressNotUpdated(t,r),O.setHinkalCache({lastOutput:w,encryptedOutputs:p},t,s,o),await t.utxoUtils.buildBatchProcess(p,e,s)}),S=async(t,e,s,r)=>{const{utxos:o,encryptedOutputs:a,lastOutput:c}=await K.getInputUtxosEnclave(t,s,e);return O.setHinkalCache({encryptedOutputs:a,lastOutput:c},t,s,r),o},h=async(t,e,s,r,o,a,c,n,d)=>{try{return await S(t,e,s,o)}catch{return k(t,e,s,r,o,a,c,n,d)}},H=t=>{if(Array.isArray(t))return t;if(t!==void 0)return[t]},_=async(t,e,s)=>await t.utxoUtils.batchFilterUtxosWithNullifier(e,s),G=(t,e,s,r,o,a,c)=>{for(t.sort((n,d)=>n.amount<=d.amount?1:-1);t.length<e||t.length>e&&t.length<6;)if(t.push(new P.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:c,shieldedPrivateKey:r,tokenId:a})),s)for(;t.length>6;)t.splice(t.length-1)},b=async({hinkal:t,chainId:e,passedShieldedPublicKey:s=void 0,ethAddress:r=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:a=!1})=>{const c=r??await t.getEthereumAddress(),n=s??t.userKeys.getShieldedPublicKey(),{userKeys:d}=t,A=t.encryptedOutputsByChain[e],w=t.nullifiersByChain[e],f=Array.from(A);o&&O.resetCache(t,e,n);let{encryptedOutputs:p,lastOutput:y}=O.getHinkalCache(t,e,n);await B.checkAddressNotUpdated(t,c);const x=y!=="",u=f.findIndex(T=>T.value===y),i=u>-1,l=!x&&u===-1,g=t.areMerkleTreeUpdatesDisabled(),U=!g&&(i||!a&&l),m=!g&&a&&l,E=!U&&!m;let v=[];return U?v=await k(t,d,e,c,n,f,p,y,u):m?v=await h(t,d,e,c,n,f,p,y,u):E&&(v=await t.utxoUtils.buildBatchProcess(p,d,e)),await B.checkAddressNotUpdated(t,c),{inputUtxos:(await _(t,v,w)).filter(T=>!T.isBlocked)}},C=async({hinkal:t,chainId:e,ethAddress:s=void 0})=>{const r=s??await t.getEthereumAddressByChain(e),o=N.hashEthereumAddress(r);return{inputUtxos:(await R.getUnspentUtxos(e,o)).utxos.map(({utxo:n})=>new P.Utxo({...n,amount:BigInt(n.amount),randomization:n.randomization?BigInt(n.randomization):void 0,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()}))}},j=async({hinkal:t,tokenWithId:e,minInput:s=2,sliceIfMore6:r=!0,chainId:o,passedShieldedPrivateKey:a=void 0,passedShieldedPublicKey:c=void 0,ethAddress:n=void 0,resetCacheBefore:d=!1,ensuredTokensWithId:A,useBlockedUtxos:w=!1})=>{const f=a??t.userKeys.getShieldedPrivateKey(),{inputUtxos:p}=w?await C({hinkal:t,chainId:o,ethAddress:n}):await b({hinkal:t,tokenWithId:e,minInput:s,sliceIfMore6:r,chainId:o,passedShieldedPrivateKey:a,passedShieldedPublicKey:c,ethAddress:n,resetCacheBefore:d}),y=H(e),x=new Map;p.forEach(u=>{const i=u.getTokenAddress(o);if(y&&!y.some(U=>I.caseInsensitiveEqual(U.erc20TokenAddress,i)&&U.tokenId===u.tokenId))return;const l=q.encodeTokenWithId(o,{erc20TokenAddress:i,tokenId:u.tokenId}),g=x.get(l)??[];x.set(l,[...g,u])}),A?.forEach(u=>{const i=q.encodeTokenWithId(o,{erc20TokenAddress:u.erc20TokenAddress,tokenId:u.tokenId});x.set(i,x.get(i)??[])});for(const[u,i]of x){const l=u.split("-")[0],g=Number(u.split("-")[1]),U=M.isSolanaLike(o),m=U?l:void 0,E=U?L.formatMintAddress(l).compressedAddress.toLowerCase():l.toLowerCase();G(i,s,r,f,E,g,m)}return x};exports.attemptGetInputUtxosRemotely=h;exports.getInputUtxoAndBalance=b;exports.getInputUtxoAndBalanceOfStuckUtxos=C;exports.getInputUtxoAndBalancePerToken=j;exports.getInputUtxosRemotely=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("../../../data-structures/utxo/Utxo.cjs"),C=require("../../utils/upToDateState.cjs"),m=require("../../utils/cacheFunctions.cjs"),R=require("../../utils/caseInsensitive.utils.cjs"),k=require("../../utils/encodeTokenWithId.cjs"),K=require("./getInputUtxosEnclave.cjs"),M=require("../../../error-handling/logger.cjs"),F=require("../../utils/solanaMint.utils.cjs"),H=require("../../../constants/chains.constants.cjs"),_=require("../../utils/addresses.cjs"),G=require("../../../API/scheduled-transactions-calls.cjs"),S=async(t,s,e,a,n,r,u,c,o)=>{o+=1;const d=r.slice(o),{lastOutput:y,additionalEncryptedOutputs:A}=await t.utxoUtils.batchProcess(d,c,s,e),i=[...u,...A];return await C.checkChainOrAddressNotUpdated(t,e,a),m.setHinkalCache({lastOutput:y,encryptedOutputs:i},t,e,n),await t.utxoUtils.buildBatchProcess(i,s,e)},b=async(t,s,e,a)=>{const{utxos:n,encryptedOutputs:r,lastOutput:u}=await K.getInputUtxosEnclave(t,e,s);return m.setHinkalCache({encryptedOutputs:r,lastOutput:u},t,e,a),n},B=async(t,s,e,a,n,r,u,c,o)=>{try{return await b(t,s,e,n)}catch{return S(t,s,e,a,n,r,u,c,o)}},j=t=>{if(Array.isArray(t))return t;if(t!==void 0)return[t]},D=async(t,s,e)=>await t.utxoUtils.batchFilterUtxosWithNullifier(s,e),W=(t,s,e,a,n,r,u)=>{for(t.sort((c,o)=>c.amount<=o.amount?1:-1);t.length<s||t.length>s&&t.length<6;)if(t.push(new L.Utxo({amount:0n,erc20TokenAddress:n,mintAddress:u,shieldedPrivateKey:a,tokenId:r})),e)for(;t.length>6;)t.splice(t.length-1)},E=async({hinkal:t,chainId:s=void 0,passedShieldedPublicKey:e=void 0,ethAddress:a=void 0,resetCacheBefore:n=!1,allowRemoteDecryption:r=!1,useBlockedUtxos:u=!1})=>{if(!t.getCurrentChainId||!t.getSelectedNetwork())return M.Logger.log("returning empty balance"),{inputUtxos:[]};const c=a??await t.getEthereumAddress(),o=s??t.getCurrentChainId(),d=e??t.userKeys.getShieldedPublicKey(),{encryptedOutputs:y,nullifiers:A,userKeys:i}=t,l=Array.from(y);n&&m.resetCache(t,o,d);let{encryptedOutputs:w,lastOutput:U}=m.getHinkalCache(t,o,d);await C.checkChainOrAddressNotUpdated(t,o,c);const p=U!=="",x=l.findIndex(T=>T.value===U),g=x>-1,I=!p&&x===-1,f=t.areMerkleTreeUpdatesDisabled(),h=!f&&(g||!r&&I),v=!f&&r&&I,P=!h&&!v;let O=[];h?O=await S(t,i,o,c,d,l,w,U,x):v?O=await B(t,i,o,c,d,l,w,U,x):P&&(O=await t.utxoUtils.buildBatchProcess(w,i,o)),await C.checkChainOrAddressNotUpdated(t,o,c);const q=await D(t,O,A);return{inputUtxos:u?q:q.filter(T=>!T.isBlocked)}},N=async({hinkal:t,chainId:s=void 0,passedShieldedPublicKey:e=void 0,ethAddress:a=void 0,resetCacheBefore:n=!1,allowRemoteDecryption:r=!1})=>{const u=s??t.getCurrentChainId(),c=a??await t.getEthereumAddress(),o=_.hashEthereumAddress(c),{inputUtxos:d}=await E({hinkal:t,chainId:u,passedShieldedPublicKey:e,ethAddress:c,resetCacheBefore:n,allowRemoteDecryption:r,useBlockedUtxos:!0});if(!d.length)return{inputUtxos:[]};const y=d.map(l=>l.getNullifier()),{indexes:A}=await G.getScheduledTransactionsNullifierIndexes(u,{hashedEthereumAddress:o,nullifiers:y});return{inputUtxos:A.map(l=>d[l]).filter(l=>!!l)}},z=async({hinkal:t,tokenWithId:s,minInput:e=2,sliceIfMore6:a=!0,chainId:n=void 0,passedShieldedPrivateKey:r=void 0,passedShieldedPublicKey:u=void 0,ethAddress:c=void 0,resetCacheBefore:o=!1,ensuredTokensWithId:d,useBlockedUtxos:y=!1})=>{const A=r??t.userKeys.getShieldedPrivateKey(),i=n??t.getCurrentChainId(),{inputUtxos:l}=y?await N({hinkal:t,chainId:n,ethAddress:c,passedShieldedPrivateKey:r,resetCacheBefore:o}):await E({hinkal:t,tokenWithId:s,minInput:e,sliceIfMore6:a,chainId:n,passedShieldedPrivateKey:r,passedShieldedPublicKey:u,ethAddress:c,resetCacheBefore:o}),w=j(s),U=new Map;l.forEach(p=>{const x=p.getTokenAddress(i);if(w&&!w.some(f=>R.caseInsensitiveEqual(f.erc20TokenAddress,x)&&f.tokenId===p.tokenId))return;const g=k.encodeTokenWithId(i,{erc20TokenAddress:x,tokenId:p.tokenId}),I=U.get(g)??[];U.set(g,[...I,p])}),d?.forEach(p=>{const x=k.encodeTokenWithId(i,{erc20TokenAddress:p.erc20TokenAddress,tokenId:p.tokenId});U.set(x,U.get(x)??[])});for(const[p,x]of U){const g=p.split("-")[0],I=Number(p.split("-")[1]),f=H.isSolanaLike(i),h=f?g:void 0,v=f?F.formatMintAddress(g).compressedAddress.toLowerCase():g.toLowerCase();W(x,e,a,A,v,I,h)}return U};exports.attemptGetInputUtxosRemotely=B;exports.getInputUtxoAndBalance=E;exports.getInputUtxoAndBalanceOfStuckUtxos=N;exports.getInputUtxoAndBalancePerToken=z;exports.getInputUtxosRemotely=b;
@@ -5,11 +5,11 @@ import { EncryptedOutputWithSign } from '../../../types/commitments.types';
5
5
  import { type TokenWithId } from '../../../types/token-with-id.types';
6
6
  interface IGetInputUtxos {
7
7
  hinkal: IHinkal;
8
- chainId: number;
9
8
  tokenWithId?: TokenWithId | TokenWithId[];
10
9
  minInput?: number;
11
10
  sliceIfMore6?: boolean;
12
11
  tokenId?: number;
12
+ chainId?: number;
13
13
  passedShieldedPrivateKey?: string;
14
14
  passedShieldedPublicKey?: string;
15
15
  ethAddress?: string;
@@ -28,10 +28,10 @@ export declare const attemptGetInputUtxosRemotely: (hinkal: IHinkal, userKeys: U
28
28
  * @param sliceIfMore6 max upper bound on input UTXOs controller
29
29
  * @returns UTXOs for particular erc20 token address
30
30
  */
31
- export declare const getInputUtxoAndBalance: ({ hinkal, chainId, passedShieldedPublicKey, ethAddress, resetCacheBefore, allowRemoteDecryption, }: IGetInputUtxos) => Promise<{
31
+ export declare const getInputUtxoAndBalance: ({ hinkal, chainId, passedShieldedPublicKey, ethAddress, resetCacheBefore, allowRemoteDecryption, useBlockedUtxos, }: IGetInputUtxos) => Promise<{
32
32
  inputUtxos: Utxo[];
33
33
  }>;
34
- export declare const getInputUtxoAndBalanceOfStuckUtxos: ({ hinkal, chainId, ethAddress, }: IGetInputUtxos) => Promise<{
34
+ export declare const getInputUtxoAndBalanceOfStuckUtxos: ({ hinkal, chainId, passedShieldedPublicKey, ethAddress, resetCacheBefore, allowRemoteDecryption, }: IGetInputUtxos) => Promise<{
35
35
  inputUtxos: Utxo[];
36
36
  }>;
37
37
  export declare const getInputUtxoAndBalancePerToken: ({ hinkal, tokenWithId, minInput, sliceIfMore6, chainId, passedShieldedPrivateKey, passedShieldedPublicKey, ethAddress, resetCacheBefore, ensuredTokensWithId, useBlockedUtxos, }: IGetInputUtxos) => Promise<Map<string, Utxo[]>>;
@@ -1,174 +1,195 @@
1
- import { Utxo as P } from "../../../data-structures/utxo/Utxo.mjs";
2
- import { checkAddressNotUpdated as B } from "../../utils/upToDateState.mjs";
3
- import { setHinkalCache as K, resetCache as C, getHinkalCache as S } from "../../utils/cacheFunctions.mjs";
4
- import { caseInsensitiveEqual as L } from "../../utils/caseInsensitive.utils.mjs";
5
- import { encodeTokenWithId as T } from "../../utils/encodeTokenWithId.mjs";
6
- import { getInputUtxosEnclave as k } from "./getInputUtxosEnclave.mjs";
7
- import { formatMintAddress as N } from "../../utils/solanaMint.utils.mjs";
8
- import { isSolanaLike as h } from "../../../constants/chains.constants.mjs";
9
- import { hashEthereumAddress as z } from "../../utils/addresses.mjs";
10
- import { getUnspentUtxos as F } from "../../../API/unspent-utxos-calls.mjs";
11
- import { Mutex as M } from "async-mutex";
12
- const R = new M(), b = async (t, e, s, n, o, a, c, r, d) => R.runExclusive(async () => {
13
- d += 1;
14
- const U = a.slice(d), { lastOutput: A, additionalEncryptedOutputs: x } = await t.utxoUtils.batchProcess(
15
- U,
16
- r,
17
- e,
18
- s
19
- ), l = [...c, ...x];
20
- return await B(t, n), K(
1
+ import { Utxo as B } from "../../../data-structures/utxo/Utxo.mjs";
2
+ import { checkChainOrAddressNotUpdated as T } from "../../utils/upToDateState.mjs";
3
+ import { setHinkalCache as b, resetCache as L, getHinkalCache as k } from "../../utils/cacheFunctions.mjs";
4
+ import { caseInsensitiveEqual as K } from "../../utils/caseInsensitive.utils.mjs";
5
+ import { encodeTokenWithId as C } from "../../utils/encodeTokenWithId.mjs";
6
+ import { getInputUtxosEnclave as R } from "./getInputUtxosEnclave.mjs";
7
+ import { Logger as F } from "../../../error-handling/logger.mjs";
8
+ import { formatMintAddress as H } from "../../utils/solanaMint.utils.mjs";
9
+ import { isSolanaLike as M } from "../../../constants/chains.constants.mjs";
10
+ import { hashEthereumAddress as q } from "../../utils/addresses.mjs";
11
+ import { getScheduledTransactionsNullifierIndexes as G } from "../../../API/scheduled-transactions-calls.mjs";
12
+ const N = async (t, s, e, d, r, n, u, c, o) => {
13
+ o += 1;
14
+ const a = n.slice(o), { lastOutput: U, additionalEncryptedOutputs: g } = await t.utxoUtils.batchProcess(
15
+ a,
16
+ c,
17
+ s,
18
+ e
19
+ ), i = [...u, ...g];
20
+ return await T(t, e, d), b(
21
21
  {
22
- lastOutput: A,
23
- encryptedOutputs: l
22
+ lastOutput: U,
23
+ encryptedOutputs: i
24
24
  },
25
25
  t,
26
- s,
27
- o
28
- ), await t.utxoUtils.buildBatchProcess(l, e, s);
29
- }), H = async (t, e, s, n) => {
26
+ e,
27
+ r
28
+ ), await t.utxoUtils.buildBatchProcess(i, s, e);
29
+ }, j = async (t, s, e, d) => {
30
30
  const {
31
- utxos: o,
32
- encryptedOutputs: a,
33
- lastOutput: c
34
- } = await k(t, s, e);
35
- return K(
31
+ utxos: r,
32
+ encryptedOutputs: n,
33
+ lastOutput: u
34
+ } = await R(t, e, s);
35
+ return b(
36
36
  {
37
- encryptedOutputs: a,
38
- lastOutput: c
37
+ encryptedOutputs: n,
38
+ lastOutput: u
39
39
  },
40
40
  t,
41
- s,
42
- n
43
- ), o;
44
- }, q = async (t, e, s, n, o, a, c, r, d) => {
41
+ e,
42
+ d
43
+ ), r;
44
+ }, z = async (t, s, e, d, r, n, u, c, o) => {
45
45
  try {
46
- return await H(t, e, s, o);
46
+ return await j(t, s, e, r);
47
47
  } catch {
48
- return b(
48
+ return N(
49
49
  t,
50
- e,
51
50
  s,
51
+ e,
52
+ d,
53
+ r,
52
54
  n,
53
- o,
54
- a,
55
+ u,
55
56
  c,
56
- r,
57
- d
57
+ o
58
58
  );
59
59
  }
60
- }, G = (t) => {
60
+ }, D = (t) => {
61
61
  if (Array.isArray(t))
62
62
  return t;
63
63
  if (t !== void 0)
64
64
  return [t];
65
- }, j = async (t, e, s) => await t.utxoUtils.batchFilterUtxosWithNullifier(e, s), D = (t, e, s, n, o, a, c) => {
66
- for (t.sort((r, d) => r.amount <= d.amount ? 1 : -1); t.length < e || t.length > e && t.length < 6; )
67
- if (t.push(new P({ amount: 0n, erc20TokenAddress: o, mintAddress: c, shieldedPrivateKey: n, tokenId: a })), s)
65
+ }, J = async (t, s, e) => await t.utxoUtils.batchFilterUtxosWithNullifier(s, e), Q = (t, s, e, d, r, n, u) => {
66
+ for (t.sort((c, o) => c.amount <= o.amount ? 1 : -1); t.length < s || t.length > s && t.length < 6; )
67
+ if (t.push(new B({ amount: 0n, erc20TokenAddress: r, mintAddress: u, shieldedPrivateKey: d, tokenId: n })), e)
68
68
  for (; t.length > 6; )
69
69
  t.splice(t.length - 1);
70
- }, J = async ({
70
+ }, P = async ({
71
71
  hinkal: t,
72
- chainId: e,
73
- passedShieldedPublicKey: s = void 0,
74
- ethAddress: n = void 0,
75
- resetCacheBefore: o = !1,
76
- allowRemoteDecryption: a = !1
72
+ chainId: s = void 0,
73
+ passedShieldedPublicKey: e = void 0,
74
+ ethAddress: d = void 0,
75
+ resetCacheBefore: r = !1,
76
+ allowRemoteDecryption: n = !1,
77
+ useBlockedUtxos: u = !1
77
78
  }) => {
78
- const c = n ?? await t.getEthereumAddress(), r = s ?? t.userKeys.getShieldedPublicKey(), { userKeys: d } = t, U = t.encryptedOutputsByChain[e], A = t.nullifiersByChain[e], x = Array.from(U);
79
- o && C(t, e, r);
80
- let { encryptedOutputs: l, lastOutput: m } = S(t, e, r);
81
- await B(t, c);
82
- const y = m !== "", u = x.findIndex((E) => E.value === m), i = u > -1, p = !y && u === -1, w = t.areMerkleTreeUpdatesDisabled(), f = !w && (i || !a && p), g = !w && a && p, O = !f && !g;
83
- let v = [];
84
- return f ? v = await b(
79
+ if (!t.getCurrentChainId || !t.getSelectedNetwork())
80
+ return F.log("returning empty balance"), { inputUtxos: [] };
81
+ const c = d ?? await t.getEthereumAddress(), o = s ?? t.getCurrentChainId(), a = e ?? t.userKeys.getShieldedPublicKey(), { encryptedOutputs: U, nullifiers: g, userKeys: i } = t, l = Array.from(U);
82
+ r && L(t, o, a);
83
+ let { encryptedOutputs: w, lastOutput: m } = k(
85
84
  t,
86
- d,
87
- e,
85
+ o,
86
+ a
87
+ );
88
+ await T(t, o, c);
89
+ const p = m !== "", f = l.findIndex((E) => E.value === m), x = f > -1, A = !p && f === -1, y = t.areMerkleTreeUpdatesDisabled(), v = !y && (x || !n && A), O = !y && n && A, S = !v && !O;
90
+ let I = [];
91
+ v ? I = await N(
92
+ t,
93
+ i,
94
+ o,
88
95
  c,
89
- r,
90
- x,
96
+ a,
91
97
  l,
98
+ w,
92
99
  m,
93
- u
94
- ) : g ? v = await q(
100
+ f
101
+ ) : O ? I = await z(
95
102
  t,
96
- d,
97
- e,
103
+ i,
104
+ o,
98
105
  c,
99
- r,
100
- x,
106
+ a,
101
107
  l,
108
+ w,
102
109
  m,
103
- u
104
- ) : O && (v = await t.utxoUtils.buildBatchProcess(l, d, e)), await B(t, c), { inputUtxos: (await j(t, v, A)).filter((E) => !E.isBlocked) };
105
- }, Q = async ({
110
+ f
111
+ ) : S && (I = await t.utxoUtils.buildBatchProcess(w, i, o)), await T(t, o, c);
112
+ const h = await J(t, I, g);
113
+ return { inputUtxos: u ? h : h.filter((E) => !E.isBlocked) };
114
+ }, V = async ({
106
115
  hinkal: t,
107
- chainId: e,
108
- ethAddress: s = void 0
116
+ chainId: s = void 0,
117
+ passedShieldedPublicKey: e = void 0,
118
+ ethAddress: d = void 0,
119
+ resetCacheBefore: r = !1,
120
+ allowRemoteDecryption: n = !1
109
121
  }) => {
110
- const n = s ?? await t.getEthereumAddressByChain(e), o = z(n);
111
- return { inputUtxos: (await F(e, o)).utxos.map(
112
- ({ utxo: r }) => new P({
113
- ...r,
114
- amount: BigInt(r.amount),
115
- randomization: r.randomization ? BigInt(r.randomization) : void 0,
116
- shieldedPrivateKey: t.userKeys.getShieldedPrivateKey()
117
- })
118
- ) };
119
- }, nt = async ({
122
+ const u = s ?? t.getCurrentChainId(), c = d ?? await t.getEthereumAddress(), o = q(c), { inputUtxos: a } = await P({
123
+ hinkal: t,
124
+ chainId: u,
125
+ passedShieldedPublicKey: e,
126
+ ethAddress: c,
127
+ resetCacheBefore: r,
128
+ allowRemoteDecryption: n,
129
+ useBlockedUtxos: !0
130
+ });
131
+ if (!a.length)
132
+ return { inputUtxos: [] };
133
+ const U = a.map((l) => l.getNullifier()), { indexes: g } = await G(u, {
134
+ hashedEthereumAddress: o,
135
+ nullifiers: U
136
+ });
137
+ return { inputUtxos: g.map((l) => a[l]).filter((l) => !!l) };
138
+ }, ct = async ({
120
139
  hinkal: t,
121
- tokenWithId: e,
122
- minInput: s = 2,
123
- sliceIfMore6: n = !0,
124
- chainId: o,
125
- passedShieldedPrivateKey: a = void 0,
126
- passedShieldedPublicKey: c = void 0,
127
- ethAddress: r = void 0,
128
- resetCacheBefore: d = !1,
129
- ensuredTokensWithId: U,
130
- useBlockedUtxos: A = !1
140
+ tokenWithId: s,
141
+ minInput: e = 2,
142
+ sliceIfMore6: d = !0,
143
+ chainId: r = void 0,
144
+ passedShieldedPrivateKey: n = void 0,
145
+ passedShieldedPublicKey: u = void 0,
146
+ ethAddress: c = void 0,
147
+ resetCacheBefore: o = !1,
148
+ ensuredTokensWithId: a,
149
+ useBlockedUtxos: U = !1
131
150
  }) => {
132
- const x = a ?? t.userKeys.getShieldedPrivateKey(), { inputUtxos: l } = A ? await Q({
151
+ const g = n ?? t.userKeys.getShieldedPrivateKey(), i = r ?? t.getCurrentChainId(), { inputUtxos: l } = U ? await V({
133
152
  hinkal: t,
134
- chainId: o,
135
- ethAddress: r
136
- }) : await J({
153
+ chainId: r,
154
+ ethAddress: c,
155
+ passedShieldedPrivateKey: n,
156
+ resetCacheBefore: o
157
+ }) : await P({
137
158
  hinkal: t,
138
- tokenWithId: e,
139
- minInput: s,
140
- sliceIfMore6: n,
141
- chainId: o,
142
- passedShieldedPrivateKey: a,
143
- passedShieldedPublicKey: c,
144
- ethAddress: r,
145
- resetCacheBefore: d
146
- }), m = G(e), y = /* @__PURE__ */ new Map();
147
- l.forEach((u) => {
148
- const i = u.getTokenAddress(o);
149
- if (m && !m.some(
150
- (f) => L(f.erc20TokenAddress, i) && f.tokenId === u.tokenId
159
+ tokenWithId: s,
160
+ minInput: e,
161
+ sliceIfMore6: d,
162
+ chainId: r,
163
+ passedShieldedPrivateKey: n,
164
+ passedShieldedPublicKey: u,
165
+ ethAddress: c,
166
+ resetCacheBefore: o
167
+ }), w = D(s), m = /* @__PURE__ */ new Map();
168
+ l.forEach((p) => {
169
+ const f = p.getTokenAddress(i);
170
+ if (w && !w.some(
171
+ (y) => K(y.erc20TokenAddress, f) && y.tokenId === p.tokenId
151
172
  ))
152
173
  return;
153
- const p = T(o, { erc20TokenAddress: i, tokenId: u.tokenId }), w = y.get(p) ?? [];
154
- y.set(p, [...w, u]);
155
- }), U?.forEach((u) => {
156
- const i = T(o, {
157
- erc20TokenAddress: u.erc20TokenAddress,
158
- tokenId: u.tokenId
174
+ const x = C(i, { erc20TokenAddress: f, tokenId: p.tokenId }), A = m.get(x) ?? [];
175
+ m.set(x, [...A, p]);
176
+ }), a?.forEach((p) => {
177
+ const f = C(i, {
178
+ erc20TokenAddress: p.erc20TokenAddress,
179
+ tokenId: p.tokenId
159
180
  });
160
- y.set(i, y.get(i) ?? []);
181
+ m.set(f, m.get(f) ?? []);
161
182
  });
162
- for (const [u, i] of y) {
163
- const p = u.split("-")[0], w = Number(u.split("-")[1]), f = h(o), g = f ? p : void 0, O = f ? N(p).compressedAddress.toLowerCase() : p.toLowerCase();
164
- D(i, s, n, x, O, w, g);
183
+ for (const [p, f] of m) {
184
+ const x = p.split("-")[0], A = Number(p.split("-")[1]), y = M(i), v = y ? x : void 0, O = y ? H(x).compressedAddress.toLowerCase() : x.toLowerCase();
185
+ Q(f, e, d, g, O, A, v);
165
186
  }
166
- return y;
187
+ return m;
167
188
  };
168
189
  export {
169
- q as attemptGetInputUtxosRemotely,
170
- J as getInputUtxoAndBalance,
171
- Q as getInputUtxoAndBalanceOfStuckUtxos,
172
- nt as getInputUtxoAndBalancePerToken,
173
- H as getInputUtxosRemotely
190
+ z as attemptGetInputUtxosRemotely,
191
+ P as getInputUtxoAndBalance,
192
+ V as getInputUtxoAndBalanceOfStuckUtxos,
193
+ ct as getInputUtxoAndBalancePerToken,
194
+ j as getInputUtxosRemotely
174
195
  };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../utils/erc20tokenFunctions.cjs"),x=require("../../utils/caseInsensitive.utils.cjs"),w=require("../../../data-structures/utxo/Utxo.cjs"),E=require("../etherFunctions.cjs"),P=require("../../../error-handling/customErrors/ErrorWithAmount.cjs");require("../../../error-handling/error-codes.constants.cjs");const y=require("./getInputUtxoAndBalance.cjs"),U=require("../../../data-structures/TokenDBs/PrivateTokensDB.cjs"),q=require("../../../constants/vite.constants.cjs"),B=require("../../utils/encodeTokenWithId.cjs"),S=require("../../utils/mutexes.utils.cjs"),M=require("../../utils/solanaMint.utils.cjs"),b=require("../../../constants/chains.constants.cjs"),W=async(l,n,s,g,i,d=!1,m,T=!1,p=!1)=>S.getChainBalanceFetchingMutex(n).runExclusive(async()=>{const{inputUtxos:r}=p?await y.getInputUtxoAndBalanceOfStuckUtxos({hinkal:l,chainId:n,ethAddress:i}):await y.getInputUtxoAndBalance({hinkal:l,sliceIfMore6:!1,chainId:n,passedShieldedPrivateKey:s,passedShieldedPublicKey:g,ethAddress:i,resetCacheBefore:d,allowRemoteDecryption:m});T&&q.isExtension&&await U.privateTokensDB.fetchAndUpdatePrivateTokens(r.map(e=>e.getTokenAddress(n)).filter(e=>e!==void 0),n,i);const f=(q.isExtension?await U.privateTokensDB.getPrivateTokens(n,i):v.getErc20TokensForChain(n)).map(e=>({token:e,balance:r.reduce((t,c)=>{const a=e.erc20TokenAddress,u=c.getTokenAddress(n);return x.caseInsensitiveEqual(a,u)?t+c.amount:t},0n),timestamp:r.filter(t=>x.caseInsensitiveEqual(t.getTokenAddress(n),e.erc20TokenAddress))[0]?.timeStamp,nfts:r.filter(t=>x.caseInsensitiveEqual(t.getTokenAddress(n),e.erc20TokenAddress)&&t.tokenId!==0).map(t=>({tokenId:t.tokenId,timestamp:t.timeStamp}))})),o=new Map;return f.forEach(e=>{o.set(e.token.erc20TokenAddress.toLowerCase(),e)}),o}),_=async(l,n,s,g,i=6,d=s.map(()=>0),m=!1,T=!1)=>{const{userKeys:p}=l,k=[],r=[],A=await y.getInputUtxoAndBalancePerToken({hinkal:l,sliceIfMore6:!1,ensuredTokensWithId:s.map((o,e)=>({erc20TokenAddress:s[e],tokenId:d[e]})),allowRemoteDecryption:!1,useBlockedUtxos:T,chainId:n});let f=0;for(let o=0;o<s.length;o+=1)if(m===!1){const e=A.get(B.encodeTokenWithId(n,{erc20TokenAddress:s[o],tokenId:d[o]}))??[];if(!e)throw new Error("Missing utxos for token");f=Math.max(e.length,f),r.push(e)}else r.push([]);return f===2?r:(r.forEach((o,e)=>{if(o.length>i){const t=o.slice(0,i),c=t.reduce((a,u)=>a+u.amount,0n);if(g[e]<0n&&c<-g[e]){const a=v.getERC20Token(s[e],n),u=Number(E.getAmountWithPrecision(c,a,2)),h=`Unfortunately your transaction did not go through due to UTXOs limitations.
2
- Please try again with ${a.symbol}`;throw new P.ErrorWithAmount(u,h)}k.push(t)}else if(o.length<=i){const t=[...o];let c=i-o.length;for(;c>0;){c-=1;const a=b.isSolanaLike(n),u=a?s[e]:void 0,h=a?M.formatMintAddress(s[e]).compressedAddress:s[e];t.push(new w.Utxo({amount:0n,erc20TokenAddress:h,mintAddress:u,shieldedPrivateKey:p.getShieldedPrivateKey(),tokenId:d[e]}))}k.push(t)}}),k)};exports.addPaddingToUtxos=_;exports.getShieldedBalance=W;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("../../utils/erc20tokenFunctions.cjs"),h=require("../../utils/caseInsensitive.utils.cjs"),v=require("../../../data-structures/utxo/Utxo.cjs"),w=require("../etherFunctions.cjs"),E=require("../../../error-handling/customErrors/ErrorWithAmount.cjs");require("../../../error-handling/error-codes.constants.cjs");const x=require("./getInputUtxoAndBalance.cjs"),U=require("../../../data-structures/TokenDBs/PrivateTokensDB.cjs"),q=require("../../../constants/vite.constants.cjs"),P=require("../../utils/encodeTokenWithId.cjs"),S=require("../../utils/mutexes.utils.cjs"),I=require("../../utils/solanaMint.utils.cjs"),M=require("../../../constants/chains.constants.cjs"),B=async(i,t,l,d,a,k=!1,m,T=!1,f=!1)=>S.balanceFetchingMutex.runExclusive(async()=>{const{inputUtxos:s}=f?await x.getInputUtxoAndBalanceOfStuckUtxos({hinkal:i,chainId:t,ethAddress:a,passedShieldedPrivateKey:l,resetCacheBefore:k,allowRemoteDecryption:m}):await x.getInputUtxoAndBalance({hinkal:i,sliceIfMore6:!1,chainId:t,passedShieldedPrivateKey:l,passedShieldedPublicKey:d,ethAddress:a,resetCacheBefore:k,allowRemoteDecryption:m});T&&q.isExtension&&await U.privateTokensDB.fetchAndUpdatePrivateTokens(s.map(e=>e.getTokenAddress(t)).filter(e=>e!==void 0),t,a);const g=(q.isExtension?await U.privateTokensDB.getPrivateTokens(t,a):y.getErc20TokensForChain(t)).map(e=>({token:e,balance:s.reduce((n,c)=>{const r=e.erc20TokenAddress,u=c.getTokenAddress(t);return h.caseInsensitiveEqual(r,u)?n+c.amount:n},0n),timestamp:s.filter(n=>h.caseInsensitiveEqual(n.getTokenAddress(t),e.erc20TokenAddress))[0]?.timeStamp,nfts:s.filter(n=>h.caseInsensitiveEqual(n.getTokenAddress(t),e.erc20TokenAddress)&&n.tokenId!==0).map(n=>({tokenId:n.tokenId,timestamp:n.timeStamp}))})),o=new Map;return g.forEach(e=>{o.set(e.token.erc20TokenAddress.toLowerCase(),e)}),o}),C=async(i,t,l,d=6,a=t.map(()=>0),k=!1,m=!1)=>{const{userKeys:T}=i,f=[],s=[],A=await x.getInputUtxoAndBalancePerToken({hinkal:i,sliceIfMore6:!1,ensuredTokensWithId:t.map((o,e)=>({erc20TokenAddress:t[e],tokenId:a[e]})),allowRemoteDecryption:!1,useBlockedUtxos:m});let g=0;for(let o=0;o<t.length;o+=1)if(k===!1){const e=A.get(P.encodeTokenWithId(i.getCurrentChainId(),{erc20TokenAddress:t[o],tokenId:a[o]}))??[];if(!e)throw new Error("Missing utxos for token");g=Math.max(e.length,g),s.push(e)}else s.push([]);return g===2?s:(s.forEach((o,e)=>{if(o.length>d){const n=o.slice(0,d),c=n.reduce((r,u)=>r+u.amount,0n);if(l[e]<0n&&c<-l[e]){const r=y.getERC20Token(t[e],i.getCurrentChainId()),u=Number(w.getAmountWithPrecision(c,r,2)),p=`Unfortunately your transaction did not go through due to UTXOs limitations.
2
+ Please try again with ${r.symbol}`;throw new E.ErrorWithAmount(u,p)}f.push(n)}else if(o.length<=d){const n=[...o];let c=d-o.length;for(;c>0;){c-=1;const r=M.isSolanaLike(i.getCurrentChainId()),u=r?t[e]:void 0,p=r?I.formatMintAddress(t[e]).compressedAddress:t[e];n.push(new v.Utxo({amount:0n,erc20TokenAddress:p,mintAddress:u,shieldedPrivateKey:T.getShieldedPrivateKey(),tokenId:a[e]}))}f.push(n)}}),f)};exports.addPaddingToUtxos=C;exports.getShieldedBalance=B;
@@ -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, tokenIds?: number[], forceEmptyUtxos?: boolean, useBlockedUtxos?: boolean) => Promise<Utxo[][]>;
18
+ export declare const addPaddingToUtxos: (hinkal: IHinkal, erc20Addresses: string[], amountChanges: bigint[], maxInput?: number, tokenIds?: number[], forceEmptyUtxos?: boolean, useBlockedUtxos?: boolean) => Promise<Utxo[][]>;