@hinkal/common 0.0.104 → 0.0.107

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 (272) hide show
  1. package/API/API.js +58 -0
  2. package/API/HinkalPointsCalls.js +38 -0
  3. package/API/callBeefyGraphAPI.js +37 -0
  4. package/API/callCurveAPI.js +156 -0
  5. package/API/callMonitor.js +30 -0
  6. package/API/callOdosAPI.js +44 -0
  7. package/API/callOneInchAPI.js +37 -0
  8. package/API/callRelayer.js +32 -0
  9. package/API/checkRisk.js +30 -0
  10. package/API/dataServerCalls.js +32 -0
  11. package/API/fetchCommitmentsCache.js +31 -0
  12. package/API/fetchNullifiers.js +30 -0
  13. package/API/getAxelarGasEstimate.js +37 -0
  14. package/API/getCoingeckoPrice.js +27 -0
  15. package/API/getConnextReceiveFee.js +30 -0
  16. package/API/getGasEstimates.js +38 -0
  17. package/API/getRelayerURL.js +32 -0
  18. package/API/getServerURL.js +67 -0
  19. package/API/getTokenPrice.js +41 -0
  20. package/API/kycCalls.js +32 -0
  21. package/API/passwordCalls.js +36 -0
  22. package/API/referralProgramCalls.js +58 -0
  23. package/API/relayCalls.js +30 -0
  24. package/API/restoreSnapshots.js +32 -0
  25. package/API/rewardsPointsCalls.js +40 -0
  26. package/API/userVerifyTransactions.js +45 -0
  27. package/README.md +116 -1
  28. package/assets/{snarkjsWorkerLogic-CatB8Hso.js → snarkjsWorkerLogic-Fv0M38Mc.js} +2 -2
  29. package/assets/{utxoWorkerLogic-DDqTe7hT.js → utxoWorkerLogic-CtFLQiAX.js} +2 -2
  30. package/assets/{zkProofWorkerLauncher-C-pvCm0b.js → zkProofWorkerLauncher-J3Ts5_Ba.js} +1 -1
  31. package/assets/{zkProofWorkerLogic-CLpRqNRx.js → zkProofWorkerLogic-CPNuu61R.js} +18 -19
  32. package/constants/assets.constants.js +16 -0
  33. package/constants/axelar.constants.js +55 -0
  34. package/constants/backend.constants.js +18 -0
  35. package/constants/beefy.registry.js +24 -0
  36. package/constants/chains.constants.js +204 -0
  37. package/constants/coingecko.constants.js +53 -0
  38. package/constants/contracts.constants.js +276 -0
  39. package/constants/crvCvx.registry.js +636 -0
  40. package/constants/crvDynamic.registry.js +24 -0
  41. package/constants/deploy-data/deploy-data-arbMainnet.json.js +7415 -0
  42. package/constants/deploy-data/deploy-data-avalanche.json.js +7411 -0
  43. package/constants/deploy-data/deploy-data-axelar1.json.js +4329 -0
  44. package/constants/deploy-data/deploy-data-axelar2.json.js +4329 -0
  45. package/constants/deploy-data/deploy-data-base.json.js +8425 -0
  46. package/constants/deploy-data/deploy-data-blast.json.js +9600 -0
  47. package/constants/deploy-data/deploy-data-bnbMainnet.json.js +6877 -0
  48. package/constants/deploy-data/deploy-data-ethMainnet.json.js +11427 -0
  49. package/constants/deploy-data/deploy-data-localhost.json.js +13283 -0
  50. package/constants/deploy-data/deploy-data-optimism.json.js +7417 -0
  51. package/constants/deploy-data/deploy-data-polygon.json.js +7439 -0
  52. package/constants/fees.constants.js +57 -0
  53. package/constants/kyc.constants.js +118 -0
  54. package/constants/lido.constants.js +13 -0
  55. package/constants/pendle.registry.js +253 -0
  56. package/constants/protocol.constants.js +26 -0
  57. package/constants/reorg-depths.constants.js +15 -0
  58. package/constants/rewards.constants.js +27 -0
  59. package/constants/server.constants.js +157 -0
  60. package/constants/token-data/ERC20Registry.js +85 -0
  61. package/constants/token-data/arbMainnetRegistry.json.js +946 -0
  62. package/constants/token-data/arbMainnetRegistryFixed.json.js +856 -0
  63. package/constants/token-data/avalancheRegistry.json.js +591 -0
  64. package/constants/token-data/avalancheRegistryFixed.json.js +591 -0
  65. package/constants/token-data/baseRegistry.json.js +490 -0
  66. package/constants/token-data/baseRegistryFixed.json.js +463 -0
  67. package/constants/token-data/blastRegistry.json.js +137 -0
  68. package/constants/token-data/blastRegistryFixed.json.js +137 -0
  69. package/constants/token-data/bnbMainnetRegistry.json.js +973 -0
  70. package/constants/token-data/bnbMainnetRegistryFixed.json.js +973 -0
  71. package/constants/token-data/coingeckoRegistry.json.js +115623 -0
  72. package/constants/token-data/ethMainnetRegistry.json.js +2700 -0
  73. package/constants/token-data/ethMainnetRegistryFixed.json.js +2251 -0
  74. package/constants/token-data/index.js +6 -0
  75. package/constants/token-data/localhostRegistry.json.js +2768 -0
  76. package/constants/token-data/optimismRegistry.json.js +1455 -0
  77. package/constants/token-data/optimismRegistryFixed.json.js +1392 -0
  78. package/constants/token-data/polygonRegistry.json.js +1327 -0
  79. package/constants/token-data/polygonRegistryFixed.json.js +1255 -0
  80. package/constants/token-data/popularTokens.constants.js +14 -0
  81. package/constants/token-data/tokenPricing.consts.js +8 -0
  82. package/constants/vite.constants.js +29 -0
  83. package/crypto/babyJub.js +15 -0
  84. package/crypto/poseidon.js +26 -0
  85. package/crypto/preProcessing.js +9 -0
  86. package/data-structures/Hinkal/Hinkal.js +299 -0
  87. package/data-structures/Hinkal/hinkalActionBeefy.js +101 -0
  88. package/data-structures/Hinkal/hinkalActionConvex.js +83 -0
  89. package/data-structures/Hinkal/hinkalActionCurve.js +112 -0
  90. package/data-structures/Hinkal/hinkalActionLidoEth.js +91 -0
  91. package/data-structures/Hinkal/hinkalActionPendle.js +140 -0
  92. package/data-structures/Hinkal/hinkalActionPendleLP.js +96 -0
  93. package/data-structures/Hinkal/hinkalActionStake.js +138 -0
  94. package/data-structures/Hinkal/hinkalActionVolatile.js +112 -0
  95. package/data-structures/Hinkal/hinkalDeposit.js +95 -0
  96. package/data-structures/Hinkal/hinkalGetZkMeProvider.js +47 -0
  97. package/data-structures/Hinkal/hinkalPrivateWallet.js +66 -0
  98. package/data-structures/Hinkal/hinkalSwap.js +98 -0
  99. package/data-structures/Hinkal/hinkalTransfer.js +5 -0
  100. package/data-structures/Hinkal/hinkalWithdraw.js +91 -0
  101. package/data-structures/Hinkal/resetMerkleTrees.js +49 -0
  102. package/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.js +83 -0
  103. package/data-structures/ValueCache/ValueCache.js +25 -0
  104. package/data-structures/crypto-keys/decodeUTXO.js +40 -0
  105. package/data-structures/crypto-keys/encryptDecryptUtxo.js +41 -0
  106. package/data-structures/crypto-keys/keyUtils.js +10 -0
  107. package/data-structures/crypto-keys/keys.js +90 -0
  108. package/data-structures/custom-token-registry/CustomTokenRegistry.js +33 -0
  109. package/data-structures/event-service/AbstractAccessTokenSnapshotService.js +131 -0
  110. package/data-structures/event-service/AbstractCommitmentsSnapshotService.js +132 -0
  111. package/data-structures/event-service/AbstractEventService.js +118 -0
  112. package/data-structures/event-service/AbstractNullifierSnapshotService.js +59 -0
  113. package/data-structures/event-service/AbstractSnapshotService.js +35 -0
  114. package/data-structures/merkle-tree/MerkleTree.js +177 -0
  115. package/data-structures/merkle-tree/MerkleTreeIncompleteError.js +8 -0
  116. package/data-structures/snapshot/ClientAccessTokenSnapshotService.js +48 -0
  117. package/data-structures/snapshot/ClientCommitmentsSnapshotService.js +47 -0
  118. package/data-structures/snapshot/ClientNullifierSnapshotService.js +44 -0
  119. package/data-structures/token-price-fetcher/TokenChecker.js +29 -0
  120. package/data-structures/token-price-fetcher/TokenPriceFetcher.js +218 -0
  121. package/data-structures/transactions-manager/TransactionsManager.js +194 -0
  122. package/data-structures/transactions-manager/history/getBeefyData.js +68 -0
  123. package/data-structures/transactions-manager/history/getConvexData.js +57 -0
  124. package/data-structures/transactions-manager/history/getCurveData.js +97 -0
  125. package/data-structures/transactions-manager/history/getDepositData.js +36 -0
  126. package/data-structures/transactions-manager/history/getLidoData.js +44 -0
  127. package/data-structures/transactions-manager/history/getPendleData.js +59 -0
  128. package/data-structures/transactions-manager/history/getSwapData.js +43 -0
  129. package/data-structures/transactions-manager/history/getTxDetails.js +74 -0
  130. package/data-structures/transactions-manager/history/getVolatileData.js +75 -0
  131. package/data-structures/transactions-manager/history/history.types.js +62 -0
  132. package/data-structures/transactions-manager/history/history.utils.js +8 -0
  133. package/data-structures/utxo/Utxo.js +134 -0
  134. package/data-structures/volatile-helper/VolatileHelper.js +181 -0
  135. package/error-handling/customErrors/ErrorWithAmount.js +9 -0
  136. package/error-handling/customErrors/FeeOverTransactionValueError.js +9 -0
  137. package/error-handling/customErrors/customErrors.helpers.js +21 -0
  138. package/error-handling/error-codes.constants.js +184 -0
  139. package/error-handling/get-error.message.js +53 -0
  140. package/error-handling/handleErrorRestore.js +35 -0
  141. package/error-handling/logError.js +7 -0
  142. package/error-handling/types.js +4 -0
  143. package/externalABIs/BUSD.js +519 -0
  144. package/externalABIs/BabPassport.json.js +24 -0
  145. package/externalABIs/BeefyRouterAbi.json.js +1022 -0
  146. package/externalABIs/BeefyStrategyAbi.json.js +1423 -0
  147. package/externalABIs/BeefyVaultAbi.json.js +570 -0
  148. package/externalABIs/BeefyZapAbi.json.js +208 -0
  149. package/externalABIs/BeefyZapOneInchAbi.json.js +340 -0
  150. package/externalABIs/ConvexBoosterAbi.json.js +674 -0
  151. package/externalABIs/ConvexBoosterAbiMainnet.json.js +1002 -0
  152. package/externalABIs/ConvexRewardPoolAbi.json.js +883 -0
  153. package/externalABIs/CurveReadingWrapperAbi.json.js +1422 -0
  154. package/externalABIs/CurveWrappedMainPool.json.js +1136 -0
  155. package/externalABIs/CurveZap.json.js +262 -0
  156. package/externalABIs/CvxCrvUtilities.json.js +264 -0
  157. package/externalABIs/DAI.js +334 -0
  158. package/externalABIs/ERC20.json.js +291 -0
  159. package/externalABIs/GalxePassport.json.js +41 -0
  160. package/externalABIs/IQuoterV2.json.js +205 -0
  161. package/externalABIs/ISwapRouter.json.js +568 -0
  162. package/externalABIs/IUniswapV3Factory.json.js +201 -0
  163. package/externalABIs/IUniswapV3Pool.json.js +999 -0
  164. package/externalABIs/LidoStEthAbi.json.js +1603 -0
  165. package/externalABIs/LidoStMaticAbi.json.js +1764 -0
  166. package/externalABIs/LidoStakeManagerAbi.json.js +2082 -0
  167. package/externalABIs/LidoWithdrawalQueueERC721Abi.json.js +2030 -0
  168. package/externalABIs/LidoWstEthAbi.json.js +480 -0
  169. package/externalABIs/OptimismGasPriceOracle.json.js +206 -0
  170. package/externalABIs/PendleRouterAbi.json.js +173 -0
  171. package/externalABIs/PoLidoNftAbi.json.js +701 -0
  172. package/externalABIs/SanctionsList.js +89 -0
  173. package/externalABIs/USDC.js +721 -0
  174. package/externalABIs/USDR.js +346 -0
  175. package/externalABIs/USDR3CRV.js +542 -0
  176. package/externalABIs/USDT.js +393 -0
  177. package/externalABIs/UniswapV2PoolAbi.json.js +80 -0
  178. package/externalABIs/WETH.js +156 -0
  179. package/externalABIs/amToken.js +350 -0
  180. package/externalABIs/transactionsProver.json.js +39 -0
  181. package/functions/kyc/authentoHelper.js +42 -0
  182. package/functions/kyc/passportHelper.js +39 -0
  183. package/functions/kyc/zkMeHelper.js +56 -0
  184. package/functions/pre-transaction/getFlatFees.js +203 -0
  185. package/functions/pre-transaction/interaction-to-action.js +57 -0
  186. package/functions/pre-transaction/outputUtxoProcessing.js +45 -0
  187. package/functions/pre-transaction/process-gas-estimates.js +57 -0
  188. package/functions/pre-transaction/processAmountChanges.js +229 -0
  189. package/functions/private-wallet/emporium.helpers.js +19 -0
  190. package/functions/private-wallet/opProducer.js +24 -0
  191. package/functions/protocols/convex.protocols.js +41 -0
  192. package/functions/protocols/curve.protocols.js +45 -0
  193. package/functions/protocols/pendle.helpers.js +108 -0
  194. package/functions/snarkjs/common.snarkjs.js +96 -0
  195. package/functions/snarkjs/constant.js +211 -0
  196. package/functions/snarkjs/constructEmporiumProof.js +105 -0
  197. package/functions/snarkjs/constructGeneralZkProof.js +129 -0
  198. package/functions/snarkjs/generateCircomData.js +60 -0
  199. package/functions/snarkjs/generateZkProof.js +18 -0
  200. package/functions/snarkjs/getZKFiles.js +30 -0
  201. package/functions/staking/index.js +40 -0
  202. package/functions/utils/amounts.utils.js +70 -0
  203. package/functions/utils/axelar.utils.js +38 -0
  204. package/functions/utils/cacheFunctions.js +67 -0
  205. package/functions/utils/caseInsensitive.utils.js +6 -0
  206. package/functions/utils/convertIntegrationProviderToExternalActionId.js +16 -0
  207. package/functions/utils/create-provider.js +5 -0
  208. package/functions/utils/enum.utils.js +14 -0
  209. package/functions/utils/erc20tokenFunctions.js +20 -0
  210. package/functions/utils/evmNetworkFunctions.js +29 -0
  211. package/functions/utils/external-action.utils.js +61 -0
  212. package/functions/utils/getDataFromTransaction.js +105 -0
  213. package/functions/utils/memoize.utils.js +14 -0
  214. package/functions/utils/nickname.utils.js +7 -0
  215. package/functions/utils/process.utils.js +4 -0
  216. package/functions/utils/reloadPage.js +4 -0
  217. package/functions/utils/requireEnv.js +7 -0
  218. package/functions/utils/resolve-sync.utils.js +22 -0
  219. package/functions/utils/serialize.utils.js +4 -0
  220. package/functions/utils/string.utils.js +14 -0
  221. package/functions/utils/time.utils.js +8 -0
  222. package/functions/utils/userAgent.js +15 -0
  223. package/functions/utils/volatile-patcher.utils.js +40 -0
  224. package/functions/web3/etherFunctions.js +41 -0
  225. package/functions/web3/events/balanceChangedHandler.js +10 -0
  226. package/functions/web3/events/getInputUtxoAndBalance.js +72 -0
  227. package/functions/web3/events/getShieldedBalance.js +107 -0
  228. package/functions/web3/events/web3RetrieveEvents.js +9 -0
  229. package/functions/web3/functionCalls/accessTokenCalls.js +48 -0
  230. package/functions/web3/functionCalls/approveToken.js +153 -0
  231. package/functions/web3/functionCalls/estimateGasRelayer.js +18 -0
  232. package/functions/web3/functionCalls/transactCallDirect.js +60 -0
  233. package/functions/web3/functionCalls/transactCallRelayer.js +42 -0
  234. package/functions/web3/odosAPI.js +65 -0
  235. package/functions/web3/oneInchAPI.js +61 -0
  236. package/functions/web3/runContractFunction.js +95 -0
  237. package/functions/web3/uniswapAPI.js +97 -0
  238. package/index.js +644 -0
  239. package/package.json +5 -4
  240. package/types/beefy.types.js +21 -0
  241. package/types/circom-data.types.js +22 -0
  242. package/types/curve.types.js +25 -0
  243. package/types/ethereum-network.types.js +4 -0
  244. package/types/external-action.types.js +4 -0
  245. package/types/hinkal.stake.types.js +4 -0
  246. package/types/hinkal.types.js +15 -0
  247. package/types/kyc.types.js +13 -0
  248. package/types/pendle.types.js +15 -0
  249. package/types/rewards.types.js +27 -0
  250. package/types/slippage.types.js +15 -0
  251. package/types/time.types.js +58 -0
  252. package/types/token.types.js +4 -0
  253. package/types/transactions.types.js +36 -0
  254. package/webworker/performTaskWithWorker.js +62 -0
  255. package/webworker/snarkjsWorker/snarkjsWorker.types.js +4 -0
  256. package/webworker/snarkjsWorker/snarkjsWorkerLogic.js +32 -0
  257. package/webworker/utxoWorker/utxoWorker.types.js +4 -0
  258. package/webworker/utxoWorker/utxoWorkerLogic.js +70 -0
  259. package/webworker/viteWorkerURL.constant.d.ts +3 -3
  260. package/webworker/worker.registry.js +4 -0
  261. package/webworker/workerFactory.d.ts +0 -1
  262. package/webworker/workerFactory.js +42 -0
  263. package/{workerProxy-BDj498Ht.mjs → webworker/workerProxy.js} +1 -1
  264. package/webworker/zkProofWorker/zkProofWorker.types.js +4 -0
  265. package/webworker/zkProofWorker/zkProofWorkerLogic.js +66 -0
  266. package/assets/viteWorkerURL.constant-DrIQXA2B.js +0 -11
  267. package/index-DbehuQxV.mjs +0 -398145
  268. package/index.mjs +0 -457
  269. package/snarkjsWorkerLogic-BpNWzeoy.mjs +0 -12086
  270. package/utxoWorkerLogic-D7NuHk_K.mjs +0 -64
  271. package/viteWorkerURL.constant-Bc7ufzqC.mjs +0 -9
  272. package/zkProofWorkerLogic-Bnalmuka.mjs +0 -60
@@ -0,0 +1,74 @@
1
+ import "../../../types/circom-data.types.js";
2
+ import { ExternalActionId as t } from "../../../types/external-action.types.js";
3
+ import "../../../types/transactions.types.js";
4
+ import "../../../types/curve.types.js";
5
+ import { getNonLocalhostChainId as n } from "../../../constants/chains.constants.js";
6
+ import "../../../constants/vite.constants.js";
7
+ import "../../../constants/contracts.constants.js";
8
+ import "../../../constants/kyc.constants.js";
9
+ import "../../../constants/coingecko.constants.js";
10
+ import "../../../constants/axelar.constants.js";
11
+ import "../../../constants/rewards.constants.js";
12
+ import "../../../constants/reorg-depths.constants.js";
13
+ import "ethers";
14
+ import "circomlibjs";
15
+ import "../../crypto-keys/keys.js";
16
+ import "axios";
17
+ import "../../crypto-keys/encryptDecryptUtxo.js";
18
+ import "../../../functions/web3/events/getShieldedBalance.js";
19
+ import "../../../webworker/workerFactory.js";
20
+ import { getExternalActionIdHash as r } from "../../../functions/utils/external-action.utils.js";
21
+ import "../../custom-token-registry/CustomTokenRegistry.js";
22
+ import "../../../functions/utils/convertIntegrationProviderToExternalActionId.js";
23
+ import { logError as c } from "../../../error-handling/logError.js";
24
+ import "../../../functions/utils/userAgent.js";
25
+ import { getBeefyData as p } from "./getBeefyData.js";
26
+ import { getConvexData as s } from "./getConvexData.js";
27
+ import { getCurveData as l } from "./getCurveData.js";
28
+ import { getDepositData as d } from "./getDepositData.js";
29
+ import { getSwapData as f } from "./getSwapData.js";
30
+ import { TransactionType as T, externalActionToTransactionType as g } from "./history.types.js";
31
+ import { getLidoData as C } from "./getLidoData.js";
32
+ import { getPendleData as D } from "./getPendleData.js";
33
+ import { getVolatileData as I } from "./getVolatileData.js";
34
+ import "../../volatile-helper/VolatileHelper.js";
35
+ import "libsodium-wrappers";
36
+ const tt = async (i, e, a = []) => {
37
+ try {
38
+ const o = n(i);
39
+ switch (e.externalActionId.toBigInt()) {
40
+ case r(t.Transact):
41
+ case 0n:
42
+ return d(e, o);
43
+ case r(t.Uniswap):
44
+ case r(t.Odos):
45
+ case r(t.OneInch):
46
+ return f(e, a, o);
47
+ case r(t.Beefy):
48
+ return p(e, a, o);
49
+ case r(t.Curve):
50
+ case r(t.CurveCRV):
51
+ case r(t.CurveDynamic):
52
+ case r(t.CurveCRVRewards):
53
+ return l(e, a, o);
54
+ case r(t.Convex):
55
+ return s(e, a, o);
56
+ case r(t.LidoETH):
57
+ case r(t.LidoETHNFT):
58
+ case r(t.LidoMATIC):
59
+ case r(t.LidoMATICNFT):
60
+ return C(e, a, o);
61
+ case r(t.Pendle):
62
+ return D(e, a, o);
63
+ case r(t.Volatile):
64
+ return await I(e, a, o);
65
+ default:
66
+ return { type: T.UNKNOWN };
67
+ }
68
+ } catch (o) {
69
+ return c(o), { type: g(e) };
70
+ }
71
+ };
72
+ export {
73
+ tt as getTxDetails
74
+ };
@@ -0,0 +1,75 @@
1
+ import { TransactionType as d } from "./history.types.js";
2
+ import "../../../types/circom-data.types.js";
3
+ import { VolatileAction as A } from "../../../types/hinkal.types.js";
4
+ import "../../../types/transactions.types.js";
5
+ import "../../../types/curve.types.js";
6
+ import { getERC20Registry as W } from "../../../constants/token-data/ERC20Registry.js";
7
+ import "../../../constants/chains.constants.js";
8
+ import "../../../constants/vite.constants.js";
9
+ import "../../../constants/contracts.constants.js";
10
+ import "../../../constants/kyc.constants.js";
11
+ import "../../../constants/coingecko.constants.js";
12
+ import "../../../constants/axelar.constants.js";
13
+ import "../../../constants/rewards.constants.js";
14
+ import "../../../constants/reorg-depths.constants.js";
15
+ import { caseInsensitiveEqual as a } from "../../../functions/utils/caseInsensitive.utils.js";
16
+ import "ethers";
17
+ import "circomlibjs";
18
+ import "../../crypto-keys/keys.js";
19
+ import "axios";
20
+ import "../../crypto-keys/encryptDecryptUtxo.js";
21
+ import "../../../functions/web3/events/getShieldedBalance.js";
22
+ import "../../../webworker/workerFactory.js";
23
+ import "../../../functions/utils/external-action.utils.js";
24
+ import { getERC20Token as l } from "../../../functions/utils/erc20tokenFunctions.js";
25
+ import "../../../functions/utils/convertIntegrationProviderToExternalActionId.js";
26
+ import "../../../functions/utils/userAgent.js";
27
+ import { VolatileHelper as g } from "../../volatile-helper/VolatileHelper.js";
28
+ import "../../custom-token-registry/CustomTokenRegistry.js";
29
+ import "libsodium-wrappers";
30
+ const _ = async (r, u, n) => {
31
+ const c = W(n), { externalActionMetadata: B } = r, { volatileAmounts: m, redirectActionId: E, volatileAction: p } = g.decodeVolatileMetadata(B);
32
+ if (p === A.Deposit) {
33
+ const s = r.erc20TokenAddresses[0], t = c.find((e) => a(e.sharedAddress, s));
34
+ if (!t)
35
+ throw Error("Volatile not found in statistics");
36
+ return {
37
+ tokenWithBalance: {
38
+ token: l(t.erc20TokenAddress, n) ?? { erc20TokenAddress: t.erc20TokenAddress },
39
+ balance: m[0].toBigInt()
40
+ },
41
+ type: d.DEPOSIT
42
+ };
43
+ }
44
+ if (p === A.Withdraw) {
45
+ const s = r.erc20TokenAddresses[0], t = c.find((e) => a(e.sharedAddress, s));
46
+ if (!t)
47
+ throw Error("Volatile not found in statistics");
48
+ return {
49
+ tokenWithBalance: {
50
+ token: l(t.erc20TokenAddress, n) ?? { erc20TokenAddress: t.erc20TokenAddress },
51
+ balance: m[0].toBigInt()
52
+ },
53
+ type: d.WITHDRAW
54
+ };
55
+ }
56
+ if (p === A.Swap) {
57
+ const s = r.erc20TokenAddresses[0], t = r.erc20TokenAddresses[1], k = r.amountChanges[0].toBigInt(), i = c.find((o) => a(o.sharedAddress, s)), e = c.find((o) => a(o.sharedAddress, t));
58
+ if (!i && !e)
59
+ throw Error("Volatile not found in swap statistics");
60
+ const V = {
61
+ token: l(i ? i.erc20TokenAddress : s, n),
62
+ balance: i ? m[0].toBigInt() : k
63
+ }, T = u.find((o) => a(o.erc20TokenAddress, t));
64
+ let f = { token: l(t, n), balance: T?.amount };
65
+ if (e) {
66
+ const o = await g.getVolatileTokenBalance(n, t, T?.amount ?? 0n);
67
+ console.log("VOLATILE OUTPUT BALANCE: ", { balance: o }), f = { token: e, balance: o };
68
+ }
69
+ return { tokenIn: V, tokenOut: f, type: d.SWAP, protocol: E.toBigInt() };
70
+ }
71
+ return { type: d.UNKNOWN };
72
+ };
73
+ export {
74
+ _ as getVolatileData
75
+ };
@@ -0,0 +1,62 @@
1
+ import "../../../constants/chains.constants.js";
2
+ import "../../../types/circom-data.types.js";
3
+ import { ExternalActionId as t } from "../../../types/external-action.types.js";
4
+ import "../../../types/transactions.types.js";
5
+ import "../../../types/curve.types.js";
6
+ import "../../../constants/vite.constants.js";
7
+ import "../../../constants/contracts.constants.js";
8
+ import "../../../constants/kyc.constants.js";
9
+ import "../../../constants/coingecko.constants.js";
10
+ import "../../../constants/axelar.constants.js";
11
+ import "../../../constants/rewards.constants.js";
12
+ import "../../../constants/reorg-depths.constants.js";
13
+ import "ethers";
14
+ import "circomlibjs";
15
+ import "../../crypto-keys/keys.js";
16
+ import "axios";
17
+ import "../../crypto-keys/encryptDecryptUtxo.js";
18
+ import "../../../functions/web3/events/getShieldedBalance.js";
19
+ import "../../../webworker/workerFactory.js";
20
+ import { getExternalActionIdFromNumber as o } from "../../../functions/utils/external-action.utils.js";
21
+ import "../../custom-token-registry/CustomTokenRegistry.js";
22
+ import "../../../functions/utils/convertIntegrationProviderToExternalActionId.js";
23
+ import "../../../functions/utils/userAgent.js";
24
+ import "../../volatile-helper/VolatileHelper.js";
25
+ import "libsodium-wrappers";
26
+ var m = /* @__PURE__ */ ((r) => (r[r.DEPOSIT = 0] = "DEPOSIT", r[r.WITHDRAW = 1] = "WITHDRAW", r[r.SWAP = 2] = "SWAP", r[r.BEEFY = 3] = "BEEFY", r[r.CURVE = 4] = "CURVE", r[r.CONVEX = 5] = "CONVEX", r[r.LIDO = 6] = "LIDO", r[r.PENDLE = 7] = "PENDLE", r[r.VOLATILE = 8] = "VOLATILE", r[r.UNKNOWN = 9] = "UNKNOWN", r))(m || {});
27
+ const p = (r) => {
28
+ const e = r.externalActionId.toBigInt();
29
+ switch (o(e)) {
30
+ case t.Transact:
31
+ return r.amountChanges[0].toBigInt() >= 0n ? 0 : 1;
32
+ case t.Uniswap:
33
+ case t.Odos:
34
+ case t.OneInch:
35
+ return 2;
36
+ case t.Beefy:
37
+ case t.BeefyStake:
38
+ return 3;
39
+ case t.Curve:
40
+ case t.CurveDynamic:
41
+ case t.CurveCRV:
42
+ case t.CurveCRVRewards:
43
+ return 4;
44
+ case t.Convex:
45
+ return 5;
46
+ case t.LidoETH:
47
+ case t.LidoMATIC:
48
+ case t.LidoETHNFT:
49
+ case t.LidoMATICNFT:
50
+ return 6;
51
+ case t.Pendle:
52
+ return 7;
53
+ case t.Volatile:
54
+ return r.amountChanges.length === 1 ? r.amountChanges[0].toBigInt() < 0n ? 1 : 0 : r.amountChanges.length === 2 ? 2 : 9;
55
+ default:
56
+ return 9;
57
+ }
58
+ };
59
+ export {
60
+ m as TransactionType,
61
+ p as externalActionToTransactionType
62
+ };
@@ -0,0 +1,8 @@
1
+ const o = (t) => ({
2
+ ...t,
3
+ amountChanges: t.amountChanges.map((n) => BigInt(n.toString())),
4
+ externalActionId: t.externalActionId.toBigInt()
5
+ });
6
+ export {
7
+ o as txHistoryToBigInt
8
+ };
@@ -0,0 +1,134 @@
1
+ import { ethers as y } from "ethers";
2
+ import { CIRCOM_P as o } from "../../constants/protocol.constants.js";
3
+ import { poseidonHash as a } from "../../crypto/poseidon.js";
4
+ import { randomBigInt as S } from "../../functions/web3/etherFunctions.js";
5
+ import { UserKeys as d } from "../crypto-keys/keys.js";
6
+ class h {
7
+ amount;
8
+ erc20TokenAddress;
9
+ timeStamp;
10
+ tokenId;
11
+ shieldedPrivateKey;
12
+ // 1) if it's own UTXO one provides private key and randomization -> computes stealth address and and eKey
13
+ randomization;
14
+ stealthAddress;
15
+ // 2) if it's other's utxo, stealth address and encryption key should be provided
16
+ encryptionKey;
17
+ commitment;
18
+ // computed
19
+ nullifier;
20
+ // computed
21
+ isStake;
22
+ isStakeOrUnstakeInput;
23
+ isUnstakeOutput;
24
+ /**
25
+ * creates new UTXO instance
26
+ * @param amount UTXO amount
27
+ * @param erc20TokenAddress contract address of ERC-20/ERC-721 token
28
+ * @param timeStamp timestamp
29
+ * @param tokenId tokenId
30
+ * @param randomization randomization parameter
31
+ * @param stealthAddress stealth address as a parameter(e.g. in case of transfers we will not know private key and randomization of payee
32
+ * @param encryptionKey encryption public key
33
+ * @param shieldedPrivateKey private key for nullification
34
+ * @param commitment [optional] commitment value if already computed
35
+ * @param nullifier [optional] nullifier value if already computed
36
+ */
37
+ constructor({
38
+ amount: t,
39
+ erc20TokenAddress: e,
40
+ timeStamp: s,
41
+ tokenId: i,
42
+ shieldedPrivateKey: r,
43
+ randomization: n,
44
+ stealthAddress: m,
45
+ encryptionKey: l,
46
+ commitment: u = void 0,
47
+ nullifier: c = void 0,
48
+ isStake: p = !1,
49
+ isStakeOrUnstakeInput: k = !1,
50
+ isUnstakeOutput: f = !1
51
+ }) {
52
+ this.amount = t, this.erc20TokenAddress = e, this.timeStamp = s ?? Math.floor(Date.now() / 1e3).toString(), this.tokenId = i ?? 0, this.shieldedPrivateKey = r, this.randomization = n ?? h.findCorrectRandomization(S(31), r), this.stealthAddress = m, this.encryptionKey = l, this.commitment = u, this.nullifier = c, this.isStake = p, this.isStakeOrUnstakeInput = k, this.isUnstakeOutput = f;
53
+ }
54
+ static createFrom(t, e) {
55
+ return new h({
56
+ ...t.getConstructableParams(),
57
+ nullifier: void 0,
58
+ commitment: void 0,
59
+ ...e
60
+ });
61
+ }
62
+ getConstructableParams() {
63
+ return {
64
+ amount: this.amount,
65
+ erc20TokenAddress: this.erc20TokenAddress,
66
+ timeStamp: this.timeStamp,
67
+ shieldedPrivateKey: this.shieldedPrivateKey,
68
+ randomization: this.randomization,
69
+ stealthAddress: this.stealthAddress,
70
+ encryptionKey: this.encryptionKey,
71
+ tokenId: this.tokenId,
72
+ commitment: this.commitment,
73
+ nullifier: this.nullifier,
74
+ isStake: this.isStake,
75
+ isStakeOrUnstakeInput: this.isStakeOrUnstakeInput,
76
+ isUnstakeOutput: this.isUnstakeOutput
77
+ };
78
+ }
79
+ /**
80
+ * @returns commitment hash of the UTXO instance
81
+ */
82
+ getCommitment() {
83
+ if (!this.commitment) {
84
+ const t = [this.amount, this.erc20TokenAddress, BigInt(this.getStealthAddress()), this.timeStamp];
85
+ this.tokenId > 0 && t.push(this.tokenId.toString()), (this.isStake || this.isUnstakeOutput) && t.push(0n, 1n), this.commitment = a(...t);
86
+ }
87
+ return this.commitment;
88
+ }
89
+ /**
90
+ * @returns nullifier hash of the UTXO instance
91
+ */
92
+ getNullifier() {
93
+ if (!this.nullifier) {
94
+ if (!this.shieldedPrivateKey)
95
+ throw new Error("No Nullifiers if private key is not provided");
96
+ const t = a(this.shieldedPrivateKey, this.getCommitment()), e = BigInt(a(this.commitment, t)), s = BigInt(this.isStakeOrUnstakeInput);
97
+ this.nullifier = y.BigNumber.from(e + s).toHexString();
98
+ }
99
+ return this.nullifier;
100
+ }
101
+ /**
102
+ * @returns stealth address from randomization and private shieldedPrivateKey
103
+ */
104
+ getStealthAddress() {
105
+ if (!this.stealthAddress) {
106
+ if (!this.shieldedPrivateKey)
107
+ throw Error("No stealth address in UTXO if private key is not provided");
108
+ const t = d.getStealthAddress(this.randomization, this.shieldedPrivateKey);
109
+ this.stealthAddress = t;
110
+ }
111
+ return this.stealthAddress;
112
+ }
113
+ getEncryptionKey() {
114
+ if (!this.shieldedPrivateKey) {
115
+ if (!this.encryptionKey)
116
+ throw Error("No encryption key provided in UTXO");
117
+ return this.encryptionKey;
118
+ }
119
+ return d.getEncryptionKeyPair(this.shieldedPrivateKey).publicKey;
120
+ }
121
+ static findCorrectRandomization(t, e) {
122
+ if (!e)
123
+ throw Error("No Private Shielded Key Provided");
124
+ const s = BigInt(e) % o;
125
+ let i, r, n = 0n;
126
+ do
127
+ i = t * 10n ** n % o, r = i * s % o, n += 1n;
128
+ while (r >= 2n ** 253n || i >= 2n ** 253n);
129
+ return i;
130
+ }
131
+ }
132
+ export {
133
+ h as Utxo
134
+ };
@@ -0,0 +1,181 @@
1
+ import { ethers as T } from "ethers";
2
+ import { networkRegistry as h } from "../../constants/chains.constants.js";
3
+ import "../../types/circom-data.types.js";
4
+ import { ContractType as w } from "../../types/ethereum-network.types.js";
5
+ import { ExternalActionId as f } from "../../types/external-action.types.js";
6
+ import { VolatileAction as l } from "../../types/hinkal.types.js";
7
+ import "../../types/transactions.types.js";
8
+ import "../../types/curve.types.js";
9
+ import { zeroAddress as d, ethVolatileAddress as u } from "../../constants/protocol.constants.js";
10
+ import "circomlibjs";
11
+ import "../crypto-keys/keys.js";
12
+ import "axios";
13
+ import "../crypto-keys/encryptDecryptUtxo.js";
14
+ import "../../functions/web3/events/getShieldedBalance.js";
15
+ import "../../webworker/workerFactory.js";
16
+ import { decodeMetadata as v, getExternalActionIdHash as g } from "../../functions/utils/external-action.utils.js";
17
+ import { getERC20Token as m } from "../../functions/utils/erc20tokenFunctions.js";
18
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
19
+ import "../../constants/coingecko.constants.js";
20
+ import "../../constants/vite.constants.js";
21
+ import "../../functions/utils/userAgent.js";
22
+ import "../../constants/reorg-depths.constants.js";
23
+ import "../../constants/kyc.constants.js";
24
+ import { toEnumValue as A } from "../../functions/utils/enum.utils.js";
25
+ import "../custom-token-registry/CustomTokenRegistry.js";
26
+ import "libsodium-wrappers";
27
+ import "../../constants/contracts.constants.js";
28
+ import "../../constants/axelar.constants.js";
29
+ import "../../constants/rewards.constants.js";
30
+ const p = new T.utils.Interface([
31
+ "function volatileTokenToShareToken(address volatileToken) external view returns (address)",
32
+ "function shareTokenToVolatileToken(address volatileToken) external view returns (address)",
33
+ "function shareToVolatile(address shareToken, uint shareValue) external view returns (uint)",
34
+ "function volatileToShare(address volatileToken, uint volatileTokenValue, uint volatileTokenBalanceOverride) external view returns (uint)"
35
+ ]);
36
+ class a {
37
+ static getVolatileTokenAction(r) {
38
+ const o = h[r], { fetchRpcUrl: t } = o, { volatileTokenActionInstanceAddress: e } = o.contractData;
39
+ if (!e)
40
+ throw Error("Volatile Token Address not found");
41
+ const n = new T.providers.JsonRpcProvider(t);
42
+ return new T.Contract(e, p, n);
43
+ }
44
+ static getVolatileTokenAddress = async (r, o) => {
45
+ try {
46
+ const e = await a.getVolatileTokenAction(r).shareTokenToVolatileToken(o);
47
+ if (e === d)
48
+ throw new Error("Can't get share token address");
49
+ return e;
50
+ } catch (t) {
51
+ console.log("getShareTokenAddress error ", t.message);
52
+ return;
53
+ }
54
+ };
55
+ static getShareTokenAddress = async (r, o) => {
56
+ if (o === d)
57
+ return a.getShareTokenAddress(r, u);
58
+ try {
59
+ const e = await a.getVolatileTokenAction(r).volatileTokenToShareToken(o);
60
+ if (e === d)
61
+ throw new Error("Can't get share token address");
62
+ return e;
63
+ } catch (t) {
64
+ console.log("getShareTokenAddress error ", t.message);
65
+ return;
66
+ }
67
+ };
68
+ static getVolatileTokenBalance = async (r, o, t, e) => {
69
+ try {
70
+ if (t === 0n)
71
+ return 0n;
72
+ const n = a.getVolatileTokenAction(r), c = t < 0n ? -1n : 1n, s = e ? { blockTag: e } : {};
73
+ return c * (await n.shareToVolatile(
74
+ o,
75
+ c * t,
76
+ s
77
+ )).toBigInt();
78
+ } catch (n) {
79
+ return console.log("getVolatileTokenBalance convertToShare error", n), 0n;
80
+ }
81
+ };
82
+ static getShareTokenBalance = async (r, o, t) => {
83
+ if (o === d)
84
+ return this.getShareTokenBalance(r, u, t);
85
+ try {
86
+ if (t === 0n)
87
+ return 0n;
88
+ const e = a.getVolatileTokenAction(r), n = t < 0n ? -1n : 1n;
89
+ return n * (await e.volatileToShare(
90
+ o,
91
+ n * t,
92
+ 0n
93
+ )).toBigInt();
94
+ } catch (e) {
95
+ return console.log("getShareTokenBalance convertToShare error", e), 0n;
96
+ }
97
+ };
98
+ static processVolatileData = async (r, o, t, e) => {
99
+ let n = [];
100
+ if (o === l.Deposit)
101
+ e[0] = 0n, t[0] = await a.getShareTokenAddress(r, t[0]), n = [!0];
102
+ else if (o === l.Withdraw)
103
+ e[0] = -1n * await a.getShareTokenBalance(r, t[0], -e[0]), t[0] = await a.getShareTokenAddress(r, t[0]), n = [!1];
104
+ else if (o === l.Swap) {
105
+ const c = t.map((s) => m(s, r));
106
+ await Promise.all(
107
+ c.map(async (s, i) => {
108
+ s?.isVolatile && (console.log("is volotile", s.erc20TokenAddress), e[i] < 0n ? e[i] = -1n * await a.getShareTokenBalance(r, t[i], -e[i]) : e[i] >= 0n && (e[i] = 0n), t[i] = await a.getShareTokenAddress(r, s.erc20TokenAddress), console.log("change address ", t[i]));
109
+ })
110
+ ), n = [!1, !0];
111
+ }
112
+ return { erc20Addresses: t, amountChanges: e, onChainCreation: n };
113
+ };
114
+ static decodeVolatileMetadata = (r) => {
115
+ const o = v(f.Volatile, r), t = o[0], e = o[2], n = o[4], c = A(l, n);
116
+ return { volatileAmounts: t, redirectActionId: e, volatileAction: c };
117
+ };
118
+ // TODO: Type descriminate these base on actionType
119
+ static encodeVolatileActionMetadata = ({
120
+ actionType: r = l.Deposit,
121
+ volatileAmounts: o = [],
122
+ withdrawRecipient: t = d,
123
+ redirectActionId: e = 0,
124
+ redirectMetadata: n = "0x00"
125
+ }) => (console.log({ volatileAmounts: o }), T.utils.defaultAbiCoder.encode(
126
+ ["uint256[]", "address", "uint256", "bytes", "uint8"],
127
+ [o, t, e, n, r]
128
+ ));
129
+ static getVolotileMetadata = (r, o, t, e, n) => {
130
+ if (r === l.Deposit)
131
+ return {
132
+ actionType: r,
133
+ volatileAmounts: o
134
+ };
135
+ if (r === l.Withdraw) {
136
+ if (!t)
137
+ throw Error("No withdrawal recipient");
138
+ return {
139
+ actionType: r,
140
+ volatileAmounts: o,
141
+ withdrawRecipient: t
142
+ };
143
+ }
144
+ if (r === l.Swap) {
145
+ if (e === void 0 || !n)
146
+ throw Error("No redirect action Id");
147
+ return {
148
+ actionType: r,
149
+ volatileAmounts: o,
150
+ redirectActionId: g(e),
151
+ redirectMetadata: n
152
+ };
153
+ }
154
+ throw new Error("Invalid Request");
155
+ };
156
+ static getVolatileExternalData = async (r, o, t, e, n, c) => {
157
+ const i = r.getContractWithFetcher(w.VolatileTokenAction).address;
158
+ let k = [];
159
+ return o === l.Deposit && (k = t), o === l.Withdraw && (k = [-t[0]]), o === l.Swap && (k = [-t[0], 0n]), {
160
+ externalActionId: f.Volatile,
161
+ externalAddress: i,
162
+ externalActionMetadata: this.encodeVolatileActionMetadata(
163
+ this.getVolotileMetadata(
164
+ o,
165
+ k,
166
+ e,
167
+ n,
168
+ c
169
+ )
170
+ )
171
+ };
172
+ };
173
+ static decodeExternalActionId = (r) => {
174
+ let o = !1, t;
175
+ const { externalActionId: e } = r.decodedInput;
176
+ return (typeof e == "string" ? e : e.toBigInt()) === g(f.Volatile) && ({ redirectActionId: t } = a.decodeVolatileMetadata(r.decodedInput.externalActionMetadata), o = !0), { isVolatile: o, redirectActionId: t };
177
+ };
178
+ }
179
+ export {
180
+ a as VolatileHelper
181
+ };
@@ -0,0 +1,9 @@
1
+ class s extends Error {
2
+ amount;
3
+ constructor(r, t) {
4
+ super(t), this.amount = r;
5
+ }
6
+ }
7
+ export {
8
+ s as ErrorWithAmount
9
+ };
@@ -0,0 +1,9 @@
1
+ import { transactionErrorCodes as t } from "../error-codes.constants.js";
2
+ class e extends Error {
3
+ constructor(r) {
4
+ super(t.FEES_OVER_TRANSACTION_VALUE), this.data = r, this.name = this.constructor.name;
5
+ }
6
+ }
7
+ export {
8
+ e as FeeOverTransactionValueError
9
+ };
@@ -0,0 +1,21 @@
1
+ import { fixDecimalsAmount as i } from "../../functions/utils/amounts.utils.js";
2
+ import { getAmountInToken as m } from "../../functions/web3/etherFunctions.js";
3
+ import { transactionErrorCodes as f } from "../error-codes.constants.js";
4
+ import { ErrorCategory as c } from "../types.js";
5
+ import { FeeOverTransactionValueError as l } from "./FeeOverTransactionValueError.js";
6
+ const v = (e, r) => {
7
+ const { totalFeeWEI: n, feeUnit: t } = e.data;
8
+ if (!t)
9
+ return e.message;
10
+ const s = m(t, n);
11
+ let o = "transact", a = "an equivalent of ";
12
+ return r === c.WITHDRAW && (o = "withdraw", a = ""), `Fees are over transaction value. Please ${o} at least ${a} ${i(
13
+ Number(s)
14
+ )} of ${t?.symbol} (subject to real-time price)`;
15
+ }, F = (e, r) => {
16
+ throw e instanceof l || e?.message === f.INSUFFICIENT_FUNDS_TO_TRANSACT ? e : Error(r);
17
+ };
18
+ export {
19
+ v as getGenericFeeOverTransactionValueErrorMessage,
20
+ F as rethrowKnownGasErrorIfPossible
21
+ };