@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,177 @@
1
+ import "ethers";
2
+ import "axios";
3
+ import "../../constants/chains.constants.js";
4
+ import "../../types/circom-data.types.js";
5
+ import "../../types/transactions.types.js";
6
+ import "../../types/curve.types.js";
7
+ import "circomlibjs";
8
+ import "../crypto-keys/keys.js";
9
+ import "../crypto-keys/encryptDecryptUtxo.js";
10
+ import "../../functions/web3/events/getShieldedBalance.js";
11
+ import "../../webworker/workerFactory.js";
12
+ import "../../functions/utils/external-action.utils.js";
13
+ import "../custom-token-registry/CustomTokenRegistry.js";
14
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
15
+ import "../../constants/coingecko.constants.js";
16
+ import { logError as l } from "../../error-handling/logError.js";
17
+ import "../../functions/utils/userAgent.js";
18
+ import { MerkleTreeIncompleteError as a } from "./MerkleTreeIncompleteError.js";
19
+ import "../../constants/reorg-depths.constants.js";
20
+ import "../../constants/kyc.constants.js";
21
+ import "../volatile-helper/VolatileHelper.js";
22
+ import "libsodium-wrappers";
23
+ import "../../constants/vite.constants.js";
24
+ import "../../constants/contracts.constants.js";
25
+ import "../../constants/axelar.constants.js";
26
+ import "../../constants/rewards.constants.js";
27
+ class o {
28
+ constructor(e, t, i, r, n, s) {
29
+ this.hashFunction = e, this.levels = t, this.defaultNodeValue = i, this.tree = r ?? /* @__PURE__ */ new Map(), this.count = s ?? 0n, this.index = n ?? 2n ** (t - 1n);
30
+ }
31
+ /**
32
+ * the map where the items are stored
33
+ */
34
+ tree;
35
+ /**
36
+ * amount of elements inserted inside the bottom row of the tree
37
+ */
38
+ count;
39
+ /**
40
+ * the maximum index inserted into the tree
41
+ * used together with count to make sure that the merkle tree is complete.
42
+ * meaning that there aren't any missing elements between getStartIndex() and index
43
+ */
44
+ index;
45
+ static createWithData(e, t, i, r, n, s) {
46
+ return new o(r, n, s, e, t, i);
47
+ }
48
+ /**
49
+ * @param hashFunction the hashFunction used to fill the upper layers of the merkle tree
50
+ * @param levels the amount of layers in the merkle tree
51
+ * @param defaultNodeValue the default value of an empty node in the merkle tree
52
+ */
53
+ static create(e, t, i) {
54
+ return new o(e, t, i);
55
+ }
56
+ /**
57
+ * get starting nodeIndex from which inserts are allowed
58
+ */
59
+ getStartIndex() {
60
+ return 2n ** (this.levels - 1n);
61
+ }
62
+ /**
63
+ * implementation of logarithm2 function from merkle contract
64
+ */
65
+ logarithm2(e) {
66
+ let t = 0n;
67
+ for (; 2n ** t < e; )
68
+ t += 1n;
69
+ return t;
70
+ }
71
+ bigIntMax(e, t) {
72
+ return e > t ? e : t;
73
+ }
74
+ forceInsert(e, t) {
75
+ if (t < this.getStartIndex())
76
+ throw new RangeError();
77
+ this.tree.set(t, e);
78
+ const i = this.index - this.getStartIndex(), r = this.logarithm2(i);
79
+ let n = t;
80
+ for (let s = 1n; s <= r; s += 1n) {
81
+ n /= 2n;
82
+ const h = this.hashFunction(
83
+ this.tree.get(n * 2n) || this.defaultNodeValue,
84
+ this.tree.get(n * 2n + 1n) || this.defaultNodeValue
85
+ );
86
+ this.tree.set(n, h);
87
+ }
88
+ }
89
+ /**
90
+ * insert value into the merkle tree
91
+ * @param value the value to insert
92
+ * @param nodeIndex the index to insert the value, you can get starting index from getStartIndex()
93
+ * @return true - if added, false - if already exists
94
+ * @throws will throw RangeError if nodeIndex is less than getStartIndex()
95
+ */
96
+ insert(e, t) {
97
+ let i = !1;
98
+ return this.tree.has(t) && (i = !0, l(`Editing commitment index: ${t} `)), i || (this.count += 1n), this.index = this.bigIntMax(this.index, t + 1n), this.forceInsert(e, t), !0;
99
+ }
100
+ remove(e) {
101
+ this.forceInsert(this.defaultNodeValue, e);
102
+ }
103
+ completenessCheck() {
104
+ if (this.count !== this.index - this.getStartIndex())
105
+ throw new a();
106
+ }
107
+ /**
108
+ * get root hash of the merkle tree
109
+ * @returns the hash, if the merkle tree is empty, will return
110
+ * @throws will throw MerkleTreeIncompleteError if there are missing elements in the tree
111
+ */
112
+ getRootHash() {
113
+ this.completenessCheck();
114
+ for (let e = 1n; e < 2n ** this.levels; e *= 2n)
115
+ if (this.tree.get(e))
116
+ return this.tree.get(e);
117
+ return this.defaultNodeValue;
118
+ }
119
+ getMerkleData() {
120
+ return this.completenessCheck(), new Map(this.tree);
121
+ }
122
+ getSiblingIndex(e) {
123
+ return e === 1n ? 1n : e % 2n === 1n ? e - 1n : e + 1n;
124
+ }
125
+ /**
126
+ * get sibling hashes needed by main.circom
127
+ * @throws will throw MerkleTreeIncompleteError if there are missing elements in the tree
128
+ */
129
+ getSiblingHashesForVerification(e) {
130
+ this.completenessCheck();
131
+ let t;
132
+ for (let r = this.getStartIndex(); r < this.getStartIndex() + this.index; r += 1n)
133
+ if (this.tree.get(r) === e) {
134
+ t = r;
135
+ break;
136
+ }
137
+ if (t === void 0)
138
+ return new Array(Number(this.levels)).fill(0n);
139
+ const i = [];
140
+ for (; t !== 0n; )
141
+ i.push(this.tree.get(this.getSiblingIndex(t)) || this.defaultNodeValue), t /= 2n;
142
+ return i;
143
+ }
144
+ /**
145
+ * get item's sibling hashes side
146
+ * @returns sibling's indexes
147
+ * @throws will throw MerkleTreeIncompleteError if there are missing elements in the tree
148
+ */
149
+ getSiblingSides(e) {
150
+ this.completenessCheck();
151
+ let t;
152
+ for (let r = this.getStartIndex(); r < this.getStartIndex() + this.index; r += 1n)
153
+ if (this.tree.get(r) === e) {
154
+ t = r;
155
+ break;
156
+ }
157
+ if (t === void 0)
158
+ return new Array(Number(this.levels)).fill(0n);
159
+ const i = [];
160
+ for (; t !== 0n; ) {
161
+ const r = t % 2n === 0n ? 0n : 1n;
162
+ i.push(r), t /= 2n;
163
+ }
164
+ return i;
165
+ }
166
+ toJSON() {
167
+ const { tree: e, count: t, index: i } = this;
168
+ return {
169
+ tree: Object.fromEntries(e),
170
+ count: t.toString(),
171
+ index: i.toString()
172
+ };
173
+ }
174
+ }
175
+ export {
176
+ o as MerkleTree
177
+ };
@@ -0,0 +1,8 @@
1
+ class r extends Error {
2
+ constructor() {
3
+ super("Merkle tree is incomplete"), this.name = "MerkleTreeIncompleteError";
4
+ }
5
+ }
6
+ export {
7
+ r as MerkleTreeIncompleteError
8
+ };
@@ -0,0 +1,48 @@
1
+ import { AbstractAccessTokenSnapshotService as e } from "../event-service/AbstractAccessTokenSnapshotService.js";
2
+ import "circomlibjs";
3
+ import "ethers";
4
+ import "axios";
5
+ import "../../constants/chains.constants.js";
6
+ import "../../types/circom-data.types.js";
7
+ import "../../types/transactions.types.js";
8
+ import "../../types/curve.types.js";
9
+ import "../crypto-keys/keys.js";
10
+ import "../crypto-keys/encryptDecryptUtxo.js";
11
+ import "../../functions/web3/events/getShieldedBalance.js";
12
+ import "../../webworker/workerFactory.js";
13
+ import "../../functions/utils/external-action.utils.js";
14
+ import "../custom-token-registry/CustomTokenRegistry.js";
15
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
16
+ import "../../constants/coingecko.constants.js";
17
+ import "../../constants/vite.constants.js";
18
+ import "../../functions/utils/userAgent.js";
19
+ import { fetchAccessTokenSnapshot as o } from "../../API/fetchCommitmentsCache.js";
20
+ import "../../constants/kyc.constants.js";
21
+ import "../volatile-helper/VolatileHelper.js";
22
+ import "libsodium-wrappers";
23
+ import "../../constants/contracts.constants.js";
24
+ import "../../constants/axelar.constants.js";
25
+ import "../../constants/rewards.constants.js";
26
+ import "../../constants/reorg-depths.constants.js";
27
+ class z extends e {
28
+ constructor(t, r) {
29
+ super(t, 0, !1, r);
30
+ }
31
+ async fetchSnapshot() {
32
+ const { chainId: t } = await this.contract.provider.getNetwork(), r = await o(t);
33
+ if (r.accessTokenContractAddress !== this.contract.address || r.chainId !== t)
34
+ throw Error("Commitment Snapshot: incorrect contract or chain id");
35
+ return {
36
+ latestBlockNumber: r.latestBlockNumber,
37
+ merkleTree: r.merkleTree,
38
+ senderAddresses: r.senderAddresses,
39
+ senderAddressIndexMap: r.senderAddressIndexMap
40
+ };
41
+ }
42
+ persistSnapshot(t) {
43
+ return Promise.resolve();
44
+ }
45
+ }
46
+ export {
47
+ z as ClientAccessTokenSnapshotService
48
+ };
@@ -0,0 +1,47 @@
1
+ import "../../constants/chains.constants.js";
2
+ import "../../types/circom-data.types.js";
3
+ import "../../types/transactions.types.js";
4
+ import "../../types/curve.types.js";
5
+ import "ethers";
6
+ import "circomlibjs";
7
+ import "../crypto-keys/keys.js";
8
+ import "axios";
9
+ import "../crypto-keys/encryptDecryptUtxo.js";
10
+ import "../../functions/web3/events/getShieldedBalance.js";
11
+ import "../../webworker/workerFactory.js";
12
+ import "../../functions/utils/external-action.utils.js";
13
+ import "../custom-token-registry/CustomTokenRegistry.js";
14
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
15
+ import "../../constants/coingecko.constants.js";
16
+ import "../../constants/vite.constants.js";
17
+ import "../../functions/utils/userAgent.js";
18
+ import { fetchCommitmentsSnapshot as o } from "../../API/fetchCommitmentsCache.js";
19
+ import "../../constants/kyc.constants.js";
20
+ import "../volatile-helper/VolatileHelper.js";
21
+ import "libsodium-wrappers";
22
+ import "../../constants/contracts.constants.js";
23
+ import "../../constants/axelar.constants.js";
24
+ import "../../constants/rewards.constants.js";
25
+ import "../../constants/reorg-depths.constants.js";
26
+ import { AbstractCommitmentsSnapshotService as i } from "../event-service/AbstractCommitmentsSnapshotService.js";
27
+ class z extends i {
28
+ constructor(r, t) {
29
+ super(r, 0, !1, t);
30
+ }
31
+ async fetchSnapshot() {
32
+ const { chainId: r } = await this.contract.provider.getNetwork(), t = await o(r);
33
+ if (t.hinkalAddress !== this.contract.address || t.chainId !== r)
34
+ throw Error("Commitment Snapshot: incorrect contract or chain id");
35
+ return {
36
+ latestBlockNumber: t.latestBlockNumber,
37
+ merkleTree: t.merkleTree,
38
+ encryptedOutputs: t.encryptedOutputs
39
+ };
40
+ }
41
+ persistSnapshot(r) {
42
+ return Promise.resolve();
43
+ }
44
+ }
45
+ export {
46
+ z as ClientCommitmentsSnapshotService
47
+ };
@@ -0,0 +1,44 @@
1
+ import "../../constants/chains.constants.js";
2
+ import "../../types/circom-data.types.js";
3
+ import "../../types/transactions.types.js";
4
+ import "../../types/curve.types.js";
5
+ import "ethers";
6
+ import "circomlibjs";
7
+ import "../crypto-keys/keys.js";
8
+ import "axios";
9
+ import "../crypto-keys/encryptDecryptUtxo.js";
10
+ import "../../functions/web3/events/getShieldedBalance.js";
11
+ import "../../webworker/workerFactory.js";
12
+ import "../../functions/utils/external-action.utils.js";
13
+ import "../custom-token-registry/CustomTokenRegistry.js";
14
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
15
+ import "../../constants/coingecko.constants.js";
16
+ import "../../constants/vite.constants.js";
17
+ import "../../functions/utils/userAgent.js";
18
+ import { fetchNullifiers as i } from "../../API/fetchNullifiers.js";
19
+ import "../../constants/kyc.constants.js";
20
+ import "../volatile-helper/VolatileHelper.js";
21
+ import "libsodium-wrappers";
22
+ import "../../constants/contracts.constants.js";
23
+ import "../../constants/axelar.constants.js";
24
+ import "../../constants/rewards.constants.js";
25
+ import "../../constants/reorg-depths.constants.js";
26
+ import { AbstractNullifierSnapshotService as o } from "../event-service/AbstractNullifierSnapshotService.js";
27
+ class P extends o {
28
+ constructor(t, r) {
29
+ super(t, 0, !1, r);
30
+ }
31
+ async fetchSnapshot() {
32
+ const { chainId: t } = await this.contract.provider.getNetwork(), r = await i(t);
33
+ return {
34
+ latestBlockNumber: r.latestBlockNumber,
35
+ nullifiers: r.nullifiers
36
+ };
37
+ }
38
+ persistSnapshot(t) {
39
+ return Promise.resolve();
40
+ }
41
+ }
42
+ export {
43
+ P as ClientNullifierSnapshotService
44
+ };
@@ -0,0 +1,29 @@
1
+ import { lowerCaseIncludes as a } from "../../functions/utils/caseInsensitive.utils.js";
2
+ import { wstEthSymbol as r, stMaticSymbol as o } from "../../constants/lido.constants.js";
3
+ import { chainIds as T } from "../../constants/chains.constants.js";
4
+ class m {
5
+ static isCurveLPToken = (s, e) => a(e, s.erc20TokenAddress);
6
+ static isCurveStakeToken = (s) => s.name.includes("Gauge") && s.symbol.includes("-gauge");
7
+ static isConvexToken = (s) => s.name.includes("Convex") && s.symbol.includes("cvx");
8
+ static isBeefyLpToken = (s) => s.name.startsWith("moo") && s.symbol.startsWith("moo");
9
+ static isBeefyStakeToken = (s) => s.name.includes("-Boost") && s.symbol.includes("-Boost");
10
+ static isLidoToken = (s) => s.symbol === r || s.symbol === o;
11
+ static isCurveOrConvex = (s, e) => this.isCurveLPToken(s, e) || this.isCurveStakeToken(s) || this.isConvexToken(s);
12
+ static isBeefyToken = (s) => this.isBeefyLpToken(s) || this.isBeefyStakeToken(s);
13
+ static isStakeToken = (s) => this.isCurveStakeToken(s) || this.isConvexToken(s) || this.isBeefyStakeToken(s);
14
+ static isPendleYtToken = (s) => s.name.startsWith("Pendle-YT-") && s.symbol.startsWith("Pendle-YT-");
15
+ static isPendleLPToken = (s) => s.name.startsWith("Pendle-LP-") && s.symbol.startsWith("Pendle-LP-");
16
+ static isPendleSyToken = (s) => s.name.startsWith("SY ") && s.symbol.includes("SY-");
17
+ static isPendleNativeToken = (s) => {
18
+ const e = s.name.startsWith("YT ") && s.symbol.includes("YT-"), i = this.isPendleSyToken(s), t = s.name.startsWith("PT ") && s.symbol.includes("PT-"), n = s.name.startsWith("LP ") && s.symbol.includes("LP-");
19
+ return e || i || t || n;
20
+ };
21
+ static isPendleToken = (s) => this.isPendleYtToken(s) || this.isPendleLPToken(s) || this.isPendleNativeToken(s);
22
+ static isAaveToken = (s) => s.aaveToken;
23
+ static isNonRebasingBlastToken = (s) => s.chainId === T.blast && s.symbol.startsWith("nr");
24
+ static isKinzaToken = (s) => s.name.startsWith("Kinza");
25
+ static isProtocolToken = (s, e) => this.isCurveLPToken(s, e) || this.isCurveStakeToken(s) || this.isConvexToken(s) || this.isBeefyLpToken(s) || this.isBeefyStakeToken(s) || this.isLidoToken(s) || this.isPendleToken(s) || this.isAaveToken(s) || this.isNonRebasingBlastToken(s);
26
+ }
27
+ export {
28
+ m as TokenChecker
29
+ };
@@ -0,0 +1,218 @@
1
+ import l from "axios";
2
+ import { ethers as u } from "ethers";
3
+ import { getCoingeckoPrice as g, getCoingeckoPrice2 as m } from "../../API/getCoingeckoPrice.js";
4
+ import { getCurvePoolsforPriceFetching as y } from "../../API/callCurveAPI.js";
5
+ import { coingeckoRegistry as P } from "../../constants/token-data/index.js";
6
+ import { getNonLocalhostChainId as h, chainIds as k, networkRegistry as T } from "../../constants/chains.constants.js";
7
+ import "../../types/circom-data.types.js";
8
+ import "../../types/transactions.types.js";
9
+ import "../../types/curve.types.js";
10
+ import { zeroAddress as p, beefyChainIds as v } from "../../constants/protocol.constants.js";
11
+ import "circomlibjs";
12
+ import "../crypto-keys/keys.js";
13
+ import "../crypto-keys/encryptDecryptUtxo.js";
14
+ import "../../functions/web3/events/getShieldedBalance.js";
15
+ import "../../webworker/workerFactory.js";
16
+ import "../../functions/utils/external-action.utils.js";
17
+ import { getERC20Token as I } from "../../functions/utils/erc20tokenFunctions.js";
18
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
19
+ import { getOdosPriceForToken as b } from "../../API/callOdosAPI.js";
20
+ import "../../functions/utils/userAgent.js";
21
+ import { caseInsensitiveEqual as c } from "../../functions/utils/caseInsensitive.utils.js";
22
+ import "../../constants/reorg-depths.constants.js";
23
+ import "../../constants/kyc.constants.js";
24
+ import { TokenChecker as a } from "./TokenChecker.js";
25
+ import { abi as C } from "../../externalABIs/BeefyVaultAbi.json.js";
26
+ import { urlForBeefyVaultTokens as A, urlForBeefyVaultTotalInUSD as w, urlForPendleAPI as B, urlForBeefyVaultLpTokens as D } from "../../constants/token-data/tokenPricing.consts.js";
27
+ import "../volatile-helper/VolatileHelper.js";
28
+ import "../custom-token-registry/CustomTokenRegistry.js";
29
+ import "../../constants/vite.constants.js";
30
+ import "libsodium-wrappers";
31
+ import "../../constants/contracts.constants.js";
32
+ import { CoinGeckoChainLabels as R, getCoingeckoIdForNativeTokens as E, getCoingeckoPlatform as S } from "../../constants/coingecko.constants.js";
33
+ import "../../constants/axelar.constants.js";
34
+ import { getCrvCvxWithChainId as L } from "../../constants/crvCvx.registry.js";
35
+ import "../../constants/rewards.constants.js";
36
+ import { getERC20Registry as x } from "../../constants/token-data/ERC20Registry.js";
37
+ class Pe extends a {
38
+ chainId;
39
+ provider;
40
+ erc20Registry = [];
41
+ // Curve state variables
42
+ crvCvxRegistry = [];
43
+ curvePools = [];
44
+ // Beefy state variables:
45
+ beefyVaults = [];
46
+ beefyTvlData = {};
47
+ usdcSymbol = "USDC";
48
+ supportsCurve = () => h(this.chainId) !== k.bnbMainnet;
49
+ constructor(r, t) {
50
+ super(), this.chainId = r, this.provider = t;
51
+ const e = h(this.chainId);
52
+ this.erc20Registry = x(this.chainId), this.crvCvxRegistry = L(e), this.supportsCurve() && y(this.chainId).then((i) => {
53
+ this.curvePools = i;
54
+ });
55
+ }
56
+ async updateBeefyVault() {
57
+ this.beefyVaults.length === 0 && (this.beefyVaults = (await l.get(A)).data);
58
+ }
59
+ findTokenId(r) {
60
+ let t;
61
+ const e = R[this.chainId];
62
+ return r === p ? E[this.chainId] : (P.find((i) => Object.entries(i.platforms).find(
63
+ ([s, n]) => s === e && (r ? c(r, n) : !1)
64
+ ) ? (t = i.id, !0) : !1), t);
65
+ }
66
+ async fetchPriceById(r) {
67
+ const t = await g(r);
68
+ return { usd: t?.usd, eth: t.eth };
69
+ }
70
+ async fetchPriceByAddress(r) {
71
+ const t = S(this.chainId);
72
+ return (await m(r, t))?.usd;
73
+ }
74
+ async fetchHETHPrice(r) {
75
+ const t = I(r, this.chainId);
76
+ if (!t || t.underlyingErc20TokenAddress !== p || !t.isHToken || !this.provider)
77
+ return;
78
+ const { contractData: e } = T[this.chainId];
79
+ if (!e.hETHOracleAddress || !e.HTokenOracleABI)
80
+ return;
81
+ const o = await new u.Contract(
82
+ e.hETHOracleAddress,
83
+ e.HTokenOracleABI,
84
+ this.provider
85
+ ).callStatic.exchangeRate(), s = Number(u.utils.formatEther(o)), n = await this.fetchPriceByTokenAddress(t.underlyingErc20TokenAddress);
86
+ if (n)
87
+ return s * n;
88
+ }
89
+ // This is general fetch price function: it has flexibility to fetch only with coingecko or also to try to find protocol specific price (use onlyMainRegistry parameter)
90
+ async fetchPriceByTokenAddress(r, t = !1) {
91
+ try {
92
+ console.log("fetchPriceByTokenAddress", { address: r });
93
+ const e = await this.fetchHETHPrice(r);
94
+ if (e)
95
+ return e;
96
+ const i = this.findTokenId(r);
97
+ if (i) {
98
+ const f = (await this.fetchPriceById(i)).usd;
99
+ if (f)
100
+ return f;
101
+ }
102
+ const o = await this.fetchPriceByAddress(r);
103
+ if (console.log({ coingecko: o }), o || t)
104
+ return o;
105
+ const s = await this.fetchProtocolPriceinUSD(r);
106
+ if (console.log({ protocolPrice: s }), s)
107
+ return s;
108
+ const n = await this.fetchOdosPriceinUSD(r);
109
+ if (console.log({ odosPrice: n }), n)
110
+ return n;
111
+ const d = await this.findBeefyLpPrice(r);
112
+ return console.log({ beefyLpPrice: d }), d || void 0;
113
+ } catch (e) {
114
+ console.log("fetchPriceByTokenAddress error ", e);
115
+ return;
116
+ }
117
+ }
118
+ async fetchOdosPriceinUSD(r) {
119
+ const t = h(this.chainId), e = await b(t, r);
120
+ if (e)
121
+ return e;
122
+ }
123
+ async fetchProtocolPriceinUSD(r) {
124
+ const t = this.erc20Registry.find(
125
+ (e) => c(e.erc20TokenAddress, r)
126
+ );
127
+ if (t) {
128
+ if (this.supportsCurve() && this.curvePools.length === 0 && (this.curvePools = await y(this.chainId)), a.isCurveOrConvex(
129
+ t,
130
+ this.curvePools.map((e) => e.lpTokenAddress)
131
+ )) {
132
+ const e = await this.fetchCurvePriceinUSD(t.underlyingErc20TokenAddress ?? r);
133
+ if (e)
134
+ return e;
135
+ }
136
+ if (a.isBeefyToken(t)) {
137
+ const e = await this.findBeefyPriceInUSD(t.underlyingErc20TokenAddress ?? r);
138
+ if (e)
139
+ return e;
140
+ }
141
+ if (a.isPendleToken(t)) {
142
+ const e = await this.fetchPendleTokenPriceInUSD(r);
143
+ if (e)
144
+ return e;
145
+ }
146
+ if (a.isAaveToken(t)) {
147
+ const { underlyingErc20TokenAddress: e } = t;
148
+ if (!e)
149
+ return console.log("missing underlying token for aave"), 0;
150
+ const i = await this.fetchPriceByTokenAddress(e);
151
+ if (i)
152
+ return i;
153
+ }
154
+ if (a.isNonRebasingBlastToken(t)) {
155
+ const e = this.erc20Registry.find((o) => o.symbol === t.symbol.slice(2));
156
+ if (!e)
157
+ return console.log("missing rebasing variant for non-rebasing token"), 0;
158
+ const i = await this.fetchPriceByTokenAddress(e.erc20TokenAddress);
159
+ if (i)
160
+ return i;
161
+ }
162
+ if (a.isKinzaToken(t)) {
163
+ const { underlyingErc20TokenAddress: e } = t;
164
+ if (!e)
165
+ return console.log("underlying token does not exists for Kinza token"), 0;
166
+ const i = await this.fetchPriceByTokenAddress(e);
167
+ if (i)
168
+ return i;
169
+ }
170
+ }
171
+ }
172
+ // this should work for Curve Pools, Curve Staking and Convex
173
+ async fetchCurvePriceinUSD(r) {
174
+ const t = this.crvCvxRegistry.find(
175
+ (i) => c(i.lpToken, r) || c(i.gauge, r) || c(i.cvxRewards, r)
176
+ ), e = this.curvePools.find(
177
+ (i) => c(i.address, t?.pool) || c(i.lpTokenAddress, r) || c(i.gaugeAddress, r)
178
+ );
179
+ if (e?.lpPrice)
180
+ return e.lpPrice;
181
+ }
182
+ // this should work for Beefy Lp Provision and Beefy Staking
183
+ async findBeefyPriceInUSD(r) {
184
+ await this.updateBeefyVault();
185
+ const t = h(this.chainId), e = this.beefyVaults.find(
186
+ (i) => c(r, i.earnedTokenAddress) && v[t] === i.chain
187
+ );
188
+ if (e && this.provider) {
189
+ const { earnedTokenAddress: i, id: o } = e, n = (await new u.Contract(i, C, this.provider).totalSupply()).toBigInt(), d = Number(u.utils.formatUnits(n, 18));
190
+ Object.keys(this.beefyTvlData).length === 0 && (this.beefyTvlData = (await l.get(w)).data);
191
+ const f = this.beefyTvlData[t][o];
192
+ return !f || !d ? void 0 : f / d;
193
+ }
194
+ }
195
+ async fetchPendleTokenPriceInUSD(r) {
196
+ const t = h(this.chainId), i = this.erc20Registry.find(
197
+ (n) => c(n.erc20TokenAddress, r)
198
+ )?.underlyingErc20TokenAddress ?? r;
199
+ console.log({ searchToken: i });
200
+ const o = `${t}/assets/${i}`, s = (await l.get(`${B}${o}`)).data;
201
+ return s ? s?.price.usd : 0;
202
+ }
203
+ async findBeefyLpPrice(r) {
204
+ await this.updateBeefyVault();
205
+ const t = this.beefyVaults.find((e) => c(r, e.tokenAddress));
206
+ if (t)
207
+ try {
208
+ const { oracleId: e } = t;
209
+ return (await l.get(D)).data?.[e];
210
+ } catch (e) {
211
+ console.log("findBeefyLpPrice error:", e);
212
+ return;
213
+ }
214
+ }
215
+ }
216
+ export {
217
+ Pe as TokenPriceFetcher
218
+ };