@berachain/berajs 0.1.2 → 0.2.0

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 (453) hide show
  1. package/dist/{BeraError-D1HS_rbb.d.cts → BeraError-_mQdkanr.d.cts} +35 -10
  2. package/dist/{BeraError-D1HS_rbb.d.ts → BeraError-_mQdkanr.d.ts} +35 -10
  3. package/dist/HoneyConfigProvider-CK6mOKFH.d.ts +390 -0
  4. package/dist/HoneyConfigProvider-Ca3ouozs.d.cts +390 -0
  5. package/dist/{RequestError-D8AE6xnI.d.cts → RequestError-A8XJ6QR9.d.cts} +1 -1
  6. package/dist/{RequestError-m4jxyM7D.d.ts → RequestError-Dk97z8rm.d.ts} +1 -1
  7. package/dist/abi/exports.cjs +2 -0
  8. package/dist/abi/exports.cjs.map +1 -0
  9. package/dist/abi/{index.d.cts → exports.d.cts} +12369 -9122
  10. package/dist/abi/{index.d.ts → exports.d.ts} +12369 -9122
  11. package/dist/abi/exports.mjs +2 -0
  12. package/dist/abi/exports.mjs.map +1 -0
  13. package/dist/actions/exports.cjs +2 -0
  14. package/dist/actions/exports.cjs.map +1 -0
  15. package/dist/actions/{index.d.cts → exports.d.cts} +80 -107
  16. package/dist/actions/{index.d.ts → exports.d.ts} +80 -107
  17. package/dist/actions/exports.mjs +2 -0
  18. package/dist/actions/exports.mjs.map +1 -0
  19. package/dist/chunk-575OK77P.mjs +2 -0
  20. package/dist/chunk-575OK77P.mjs.map +1 -0
  21. package/dist/chunk-7GWTHOLO.mjs +2 -0
  22. package/dist/chunk-7GWTHOLO.mjs.map +1 -0
  23. package/dist/chunk-7SC4VD3U.cjs +2 -0
  24. package/dist/chunk-7SC4VD3U.cjs.map +1 -0
  25. package/dist/chunk-BHNQX4XC.mjs +2 -0
  26. package/dist/chunk-BHNQX4XC.mjs.map +1 -0
  27. package/dist/chunk-BOYZVULX.cjs +2 -0
  28. package/dist/chunk-BOYZVULX.cjs.map +1 -0
  29. package/dist/chunk-C3FHGFLK.mjs +2 -0
  30. package/dist/chunk-C3FHGFLK.mjs.map +1 -0
  31. package/dist/chunk-C3G5KXCH.mjs +2 -0
  32. package/dist/chunk-C3G5KXCH.mjs.map +1 -0
  33. package/dist/chunk-CYKCYPFR.cjs +2 -0
  34. package/dist/chunk-CYKCYPFR.cjs.map +1 -0
  35. package/dist/chunk-F4BKSBEM.mjs +2 -0
  36. package/dist/chunk-F4BKSBEM.mjs.map +1 -0
  37. package/dist/chunk-FL2N3XHK.cjs +2 -0
  38. package/dist/chunk-FL2N3XHK.cjs.map +1 -0
  39. package/dist/chunk-G6NA6NSM.mjs +4 -0
  40. package/dist/chunk-G6NA6NSM.mjs.map +1 -0
  41. package/dist/chunk-H2QSRMVS.mjs +2 -0
  42. package/dist/chunk-H2QSRMVS.mjs.map +1 -0
  43. package/dist/chunk-IJM76AWK.cjs +4 -0
  44. package/dist/chunk-IJM76AWK.cjs.map +1 -0
  45. package/dist/chunk-MTS5SZLA.mjs +2 -0
  46. package/dist/chunk-MTS5SZLA.mjs.map +1 -0
  47. package/dist/chunk-MUNAP5TM.cjs +2 -0
  48. package/dist/chunk-MUNAP5TM.cjs.map +1 -0
  49. package/dist/chunk-NAXAZJJY.mjs +2 -0
  50. package/dist/chunk-NAXAZJJY.mjs.map +1 -0
  51. package/dist/chunk-OGJMSGB2.mjs +2 -0
  52. package/dist/chunk-OGJMSGB2.mjs.map +1 -0
  53. package/dist/chunk-OIYXOKTT.cjs +2 -0
  54. package/dist/chunk-OIYXOKTT.cjs.map +1 -0
  55. package/dist/chunk-OS5AJMYJ.cjs +2 -0
  56. package/dist/chunk-OS5AJMYJ.cjs.map +1 -0
  57. package/dist/chunk-Q3SCM6WL.mjs +2 -0
  58. package/dist/chunk-Q3SCM6WL.mjs.map +1 -0
  59. package/dist/chunk-SWMJQOH6.cjs +2 -0
  60. package/dist/chunk-SWMJQOH6.cjs.map +1 -0
  61. package/dist/chunk-TEBJWAVU.mjs +2 -0
  62. package/dist/chunk-TEBJWAVU.mjs.map +1 -0
  63. package/dist/chunk-TJWKS54T.mjs +2 -0
  64. package/dist/chunk-TJWKS54T.mjs.map +1 -0
  65. package/dist/chunk-UQUWMHVF.cjs +2 -0
  66. package/dist/chunk-UQUWMHVF.cjs.map +1 -0
  67. package/dist/chunk-UXUWSRVV.cjs +2 -0
  68. package/dist/chunk-UXUWSRVV.cjs.map +1 -0
  69. package/dist/chunk-VP7XUOSI.cjs +2 -0
  70. package/dist/chunk-VP7XUOSI.cjs.map +1 -0
  71. package/dist/chunk-VXL2ZZ4X.cjs +2 -0
  72. package/dist/chunk-VXL2ZZ4X.cjs.map +1 -0
  73. package/dist/chunk-WRFDB3QJ.cjs +2 -0
  74. package/dist/chunk-WRFDB3QJ.cjs.map +1 -0
  75. package/dist/chunk-WTCBORPB.cjs +2 -0
  76. package/dist/chunk-WTCBORPB.cjs.map +1 -0
  77. package/dist/chunk-XNJLSA6P.cjs +2 -0
  78. package/dist/chunk-XNJLSA6P.cjs.map +1 -0
  79. package/dist/chunk-YQGZMWDT.mjs +2 -0
  80. package/dist/chunk-YQGZMWDT.mjs.map +1 -0
  81. package/dist/chunk-YXLFOEZN.mjs +2 -0
  82. package/dist/chunk-YXLFOEZN.mjs.map +1 -0
  83. package/dist/chunk-ZAKA4TGK.cjs +2 -0
  84. package/dist/chunk-ZAKA4TGK.cjs.map +1 -0
  85. package/dist/chunk-ZQRACIGR.mjs +2 -0
  86. package/dist/chunk-ZQRACIGR.mjs.map +1 -0
  87. package/dist/contexts/exports.cjs +2 -0
  88. package/dist/contexts/exports.cjs.map +1 -0
  89. package/dist/contexts/{index.d.ts → exports.d.cts} +19 -28
  90. package/dist/contexts/{index.d.cts → exports.d.ts} +19 -28
  91. package/dist/contexts/exports.mjs +2 -0
  92. package/dist/contexts/exports.mjs.map +1 -0
  93. package/dist/contracts-CQIPk0Jc.d.cts +74 -0
  94. package/dist/contracts-CQIPk0Jc.d.ts +74 -0
  95. package/dist/{defaultFlags-V-tJs2K8.d.cts → defaultFlags-d0kPbT0i.d.cts} +1 -1
  96. package/dist/{defaultFlags-V-tJs2K8.d.ts → defaultFlags-d0kPbT0i.d.ts} +1 -1
  97. package/dist/dex-C_BB0b0O.d.cts +37 -0
  98. package/dist/dex-C_BB0b0O.d.ts +37 -0
  99. package/dist/enum/exports.cjs +2 -0
  100. package/dist/enum/exports.cjs.map +1 -0
  101. package/dist/enum/exports.d.cts +24 -0
  102. package/dist/enum/exports.d.ts +24 -0
  103. package/dist/enum/exports.mjs +2 -0
  104. package/dist/enum/exports.mjs.map +1 -0
  105. package/dist/errors/exports.cjs +2 -0
  106. package/dist/errors/exports.cjs.map +1 -0
  107. package/dist/errors/exports.d.cts +385 -0
  108. package/dist/errors/exports.d.ts +385 -0
  109. package/dist/errors/exports.mjs +2 -0
  110. package/dist/{getValidatorQueuedOperatorAddress-9xY2RUGe.d.cts → getValidatorQueuedOperatorAddress-BX35p2Lv.d.ts} +125 -15
  111. package/dist/{getValidatorQueuedOperatorAddress-Ne2zoiiV.d.ts → getValidatorQueuedOperatorAddress-It0GsdvQ.d.cts} +125 -15
  112. package/dist/global.d-Ba-NIojH.d.cts +474 -0
  113. package/dist/global.d-By70bEv2.d.ts +474 -0
  114. package/dist/honey-CYm0RWf4.d.cts +14 -0
  115. package/dist/honey-CYm0RWf4.d.ts +14 -0
  116. package/dist/hooks/exports.cjs +4 -0
  117. package/dist/hooks/exports.cjs.map +1 -0
  118. package/dist/hooks/{index.d.cts → exports.d.cts} +223 -173
  119. package/dist/hooks/{index.d.ts → exports.d.ts} +223 -173
  120. package/dist/hooks/exports.mjs +4 -0
  121. package/dist/hooks/exports.mjs.map +1 -0
  122. package/dist/{BexStatusProvider-nS3NcdxI.d.cts → transactionStore-BvStaXf3.d.ts} +41 -1
  123. package/dist/{BexStatusProvider-nS3NcdxI.d.ts → transactionStore-CQrGYSY2.d.cts} +41 -1
  124. package/dist/{txnEnum-BQKDfaeH.d.cts → txnEnum-BYNbCxla.d.cts} +1 -0
  125. package/dist/{txnEnum-BQKDfaeH.d.ts → txnEnum-BYNbCxla.d.ts} +1 -0
  126. package/dist/types/exports.cjs +1 -0
  127. package/dist/types/exports.cjs.map +1 -0
  128. package/dist/types/exports.d.cts +58 -0
  129. package/dist/types/exports.d.ts +58 -0
  130. package/dist/types/exports.mjs +1 -0
  131. package/dist/{useHoneySwapState-C-9BV4VB.d.cts → useHoneySwapState-B-vmIP1b.d.cts} +1 -1
  132. package/dist/{useHoneySwapState-CUY5Sm1b.d.ts → useHoneySwapState-D1DKG_Of.d.ts} +1 -1
  133. package/dist/utils/exports.cjs +2 -0
  134. package/dist/utils/exports.cjs.map +1 -0
  135. package/dist/utils/{index.d.cts → exports.d.cts} +83 -20
  136. package/dist/utils/{index.d.ts → exports.d.ts} +83 -20
  137. package/dist/utils/exports.mjs +2 -0
  138. package/dist/utils/exports.mjs.map +1 -0
  139. package/package.json +16 -17
  140. package/src/abi/{index.ts → exports.ts} +3 -0
  141. package/src/abi/pol/LSTStakerVault.ts +2032 -0
  142. package/src/abi/utils/openChainErrors.ts +71 -30
  143. package/src/abi/utils/thirdwebMinimalAccount.ts +616 -0
  144. package/src/actions/clients/BeraApolloClient.ts +8 -6
  145. package/src/actions/dex/__tests__/aggregators.unit.test.ts +2 -5
  146. package/src/actions/dex/aggregators/base.ts +74 -16
  147. package/src/actions/dex/aggregators/bex.ts +54 -74
  148. package/src/actions/dex/aggregators/bgt.ts +31 -8
  149. package/src/actions/dex/aggregators/{enso.ts → enso/enso.ts} +18 -14
  150. package/src/actions/dex/aggregators/enso/ensoErc4626.debug.test.ts +37 -0
  151. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +176 -0
  152. package/src/actions/dex/aggregators/erc4626.ts +122 -0
  153. package/src/actions/dex/aggregators/fly.ts +59 -53
  154. package/src/actions/dex/aggregators/haiku.ts +52 -54
  155. package/src/actions/dex/aggregators/honey.ts +54 -45
  156. package/src/actions/dex/aggregators/kyberswap.ts +41 -39
  157. package/src/actions/dex/aggregators/oogabooga.ts +47 -46
  158. package/src/actions/dex/aggregators/openOcean.ts +51 -46
  159. package/src/actions/dex/aggregators/wbera.ts +54 -42
  160. package/src/actions/dex/b-sdk.ts +5 -2
  161. package/src/actions/dex/getIsTokenExploited.ts +2 -2
  162. package/src/actions/enso/{zap.ts → getEnsoSwapBundle.ts} +4 -5
  163. package/src/actions/enso/getEnsoUserTokensWithBalances.debug.test.ts +73 -0
  164. package/src/actions/enso/{getEnsoUserToken.ts → getEnsoUserTokensWithBalances.ts} +42 -30
  165. package/src/actions/enso/util.ts +1 -1
  166. package/src/actions/{index.ts → exports.ts} +5 -0
  167. package/src/actions/governance/__tests__/checkProposalField.unit.test.ts +1 -1
  168. package/src/actions/governance/__tests__/getQuorum.integration.test.ts +1 -1
  169. package/src/actions/governance/checkProposalField.ts +1 -1
  170. package/src/actions/governance/computeActualStatus.ts +1 -1
  171. package/src/actions/governance/getBodyErrors.ts +1 -1
  172. package/src/actions/governance/getDecodedFunctionData.ts +1 -4
  173. package/src/actions/governance/getProposalDetails.ts +2 -2
  174. package/src/actions/governance/getProposalFromTx.ts +1 -2
  175. package/src/actions/governance/getProposalParams.ts +7 -8
  176. package/src/actions/governance/getQuorum.ts +1 -2
  177. package/src/actions/honey/getCollateralWeights.ts +1 -1
  178. package/src/actions/honey/getHoneyCollaterals.ts +1 -0
  179. package/src/actions/honey/getHoneyVaultsBalance.ts +51 -55
  180. package/src/actions/honey/getSwapPayload.ts +37 -35
  181. package/src/actions/honey/tests/pyth.integration.test.ts +0 -1
  182. package/src/actions/pol/__tests__/getAllValidators.integration.test.ts +1 -1
  183. package/src/actions/pol/getEarnedStakedBeraVault.ts +31 -0
  184. package/src/actions/pol/getGlobalData.ts +14 -13
  185. package/src/actions/pol/getLSTStakeConfig.ts +67 -0
  186. package/src/actions/pol/getMarkets.ts +1 -1
  187. package/src/actions/pol/getRewardProofsByValidator.ts +1 -1
  188. package/src/actions/pol/getRewardVaultIncentives.ts +3 -5
  189. package/src/actions/pol/getRewardVaults.ts +2 -3
  190. package/src/actions/pol/getSWBeraVaultMetadata.ts +7 -5
  191. package/src/actions/pol/getSWBeraWithdrawal.ts +41 -27
  192. package/src/actions/pol/getStakeWithdrawalCooldown.ts +5 -7
  193. package/src/actions/pol/getStakingDailyAssets.ts +21 -0
  194. package/src/actions/pol/getStakingTokenInformation.ts +3 -4
  195. package/src/actions/pol/getTotalStakedAmount.ts +47 -0
  196. package/src/actions/pol/getUserClaimableIncentives.ts +1 -1
  197. package/src/actions/pol/getUserVaults.ts +8 -6
  198. package/src/actions/pol/getUserVaultsBalance.ts +4 -16
  199. package/src/actions/prices/getTokenCurrentPrices.ts +8 -3
  200. package/src/actions/tokens/getAllowances.ts +68 -41
  201. package/src/actions/tokens/getTokenInformation.ts +4 -1
  202. package/src/actions/tokens/getTokens.ts +1 -1
  203. package/src/actions/tokens/getUnderlyingToken.ts +53 -0
  204. package/src/actions/tokens/getWalletBalances.integration.test.ts +53 -14
  205. package/src/actions/tokens/getWalletBalances.ts +69 -43
  206. package/src/actions/transactions/beraWriteContract.integration.test.ts +18 -6
  207. package/src/actions/transactions/beraWriteContract.ts +3 -3
  208. package/src/actions/validators/getUserActiveValidators.ts +2 -3
  209. package/src/actions/validators/getUserBoostsOnValidator.ts +2 -3
  210. package/src/contexts/BeraFlags/defaultFlags.ts +4 -0
  211. package/src/contexts/SwrFallback.tsx +13 -3
  212. package/src/contexts/TokensProvider.tsx +35 -8
  213. package/src/{hooks/transactions → contexts}/TransactionStoreContext.tsx +32 -4
  214. package/src/contexts/block-time-provider.tsx +1 -1
  215. package/src/contexts/{index.ts → exports.ts} +1 -1
  216. package/src/data/contracts.ts +16 -1
  217. package/src/enum/contracts.ts +13 -0
  218. package/src/enum/dex.ts +29 -0
  219. package/src/enum/{index.ts → exports.ts} +3 -0
  220. package/src/enum/governance.ts +61 -0
  221. package/src/enum/honey.ts +12 -0
  222. package/src/enum/txnEnum.ts +1 -0
  223. package/src/errors/BeraError.ts +50 -11
  224. package/src/errors/BeraMonitoring.ts +66 -0
  225. package/src/errors/BeraTracing.ts +79 -0
  226. package/src/errors/BeraTracing.unit.test.ts +198 -0
  227. package/src/errors/RequestError.ts +2 -2
  228. package/src/errors/assert.ts +4 -2
  229. package/src/errors/assert.unit.test.ts +6 -2
  230. package/src/errors/errorMap.ts +16 -6
  231. package/src/errors/{index.ts → exports.ts} +7 -0
  232. package/src/errors/getErrorMessage.ts +22 -3
  233. package/src/errors/getRevertReason.integration.test.ts +17 -5
  234. package/src/errors/getRevertReason.ts +41 -2
  235. package/src/errors/initBeraError.ts +52 -7
  236. package/src/errors/parseViemError.ts +114 -27
  237. package/src/errors/severity.ts +12 -0
  238. package/src/hooks/bend/useGetConvertToAssets.ts +3 -2
  239. package/src/hooks/dex/useAggregatorsQuotes.ts +126 -365
  240. package/src/hooks/dex/useAllUserPools.ts +1 -1
  241. package/src/hooks/dex/useApiPool.ts +1 -1
  242. package/src/hooks/dex/useCreatePool.ts +6 -5
  243. package/src/hooks/dex/useExploitedTokens.ts +1 -1
  244. package/src/hooks/dex/useLiquidityMismatch.ts +2 -5
  245. package/src/hooks/dex/useLpPosition.ts +21 -20
  246. package/src/hooks/dex/useMultipleTokenApprovalsWithSlippage.ts +40 -29
  247. package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +1 -1
  248. package/src/hooks/dex/usePoolEvents.ts +1 -1
  249. package/src/hooks/dex/usePools.ts +1 -1
  250. package/src/hooks/dex/usePriceImpact.ts +40 -0
  251. package/src/hooks/dex/useSingleAggregatorQuote.ts +350 -0
  252. package/src/hooks/enso/useBendZapSupply.ts +216 -0
  253. package/src/hooks/enso/useEnsoSwapBundle.ts +107 -0
  254. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +43 -0
  255. package/src/hooks/enso/useZapStakeBera.ts +113 -0
  256. package/src/hooks/{index.ts → exports.ts} +18 -7
  257. package/src/hooks/governance/useCreateProposal.ts +8 -8
  258. package/src/hooks/governance/usePollAllProposals.ts +1 -1
  259. package/src/hooks/governance/usePollProposal.ts +1 -1
  260. package/src/hooks/governance/usePollProposalThreshold.ts +1 -1
  261. package/src/hooks/governance/usePollUserDelegates.ts +1 -1
  262. package/src/hooks/governance/useProposalState.ts +2 -2
  263. package/src/hooks/honey/useCappedGlobally.ts +2 -1
  264. package/src/hooks/honey/useCappedRelatively.ts +1 -1
  265. package/src/hooks/honey/useCollateralWeights.ts +2 -1
  266. package/src/hooks/honey/useHoneyAlerts.ts +11 -11
  267. package/src/hooks/honey/useHoneyBalances.ts +7 -3
  268. package/src/hooks/honey/useHoneyGlobalData.ts +2 -1
  269. package/src/hooks/honey/useHoneySwapState.ts +2 -1
  270. package/src/hooks/honey/useHoneyVaultsBalance.ts +1 -1
  271. package/src/hooks/honey/useIsBadCollateralAsset.ts +2 -1
  272. package/src/hooks/honey/useIsBasketModeEnabled.ts +1 -1
  273. package/src/hooks/honey/usePythLatestPrices.ts +1 -1
  274. package/src/hooks/pol/useOnChainRewardVault.ts +3 -2
  275. package/src/hooks/pol/usePollGlobalData.ts +1 -1
  276. package/src/hooks/pol/usePollMarkets.ts +1 -1
  277. package/src/hooks/pol/useQueuedBeraUnlock.ts +17 -15
  278. package/src/hooks/pol/useRewardTokenToBeraRate.ts +6 -3
  279. package/src/hooks/pol/useRewardVault.ts +1 -1
  280. package/src/hooks/pol/useRewardVaults.ts +1 -1
  281. package/src/hooks/pol/useSWBeraVaultMetadata.ts +35 -0
  282. package/src/hooks/pol/useStakedAPR.ts +38 -0
  283. package/src/hooks/pol/useStakedData.ts +117 -0
  284. package/src/hooks/pol/useStakedSnapshots.ts +52 -0
  285. package/src/hooks/pol/useTotalStakedAmount.ts +30 -0
  286. package/src/hooks/pol/useUserVaultInfo.ts +1 -1
  287. package/src/hooks/pol/useVaultValidators.ts +1 -1
  288. package/src/hooks/tokens/useMultipleTokenInformation.ts +15 -6
  289. package/src/hooks/tokens/usePollAllowances.ts +15 -19
  290. package/src/hooks/tokens/usePollBalance.ts +8 -4
  291. package/src/hooks/tokens/usePollWalletBalances.ts +14 -11
  292. package/src/hooks/tokens/useStakingTokenInformation.ts +2 -1
  293. package/src/hooks/tokens/useTokenCurrentPrice.ts +4 -2
  294. package/src/hooks/tokens/useTokenCurrentPrices.ts +92 -13
  295. package/src/hooks/tokens/useTokenInformation.ts +11 -6
  296. package/src/hooks/tokens/useTokenPrice.ts +21 -0
  297. package/src/hooks/tokens/useTokenPrices.ts +133 -0
  298. package/src/hooks/tokens/useTokens.ts +1 -0
  299. package/src/hooks/tokens/useUnderlyingAsset.ts +23 -0
  300. package/src/hooks/transactions/transactionStore.ts +86 -65
  301. package/src/hooks/transactions/transactionStore.unit.test.ts +54 -1
  302. package/src/hooks/transactions/useAddRecentTransaction.ts +1 -1
  303. package/src/hooks/transactions/useRecentTransactions.ts +1 -1
  304. package/src/hooks/transactions/useSetTransactionStatus.ts +31 -0
  305. package/src/hooks/useContractWrite/useBeraContractWrite.ts +2 -1
  306. package/src/hooks/validators/useAllValidators.ts +1 -1
  307. package/src/hooks/validators/useApiValidator.ts +1 -1
  308. package/src/hooks/validators/useDailyValidatorBlockStats.ts +1 -1
  309. package/src/hooks/validators/useManagedValidatorByAccount.ts +1 -1
  310. package/src/hooks/validators/useManagedValidatorRole.ts +1 -1
  311. package/src/hooks/validators/useOnChainValidator.ts +1 -1
  312. package/src/hooks/validators/useStakingPoolBatch.ts +1 -1
  313. package/src/hooks/validators/useUserActiveValidators.ts +1 -1
  314. package/src/hooks/validators/useUserBoostsOnValidator.ts +1 -1
  315. package/src/hooks/validators/useUserClaimableIncentives.ts +8 -8
  316. package/src/hooks/validators/useValidator.ts +1 -1
  317. package/src/hooks/validators/useValidatorAnalytics.ts +1 -1
  318. package/src/hooks/validators/useValidatorCommission.ts +1 -1
  319. package/src/hooks/validators/useValidatorQueuedCommission.ts +1 -1
  320. package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +1 -1
  321. package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +1 -1
  322. package/src/hooks/validators/useValidatorRewardAllocation.ts +1 -1
  323. package/src/types/{dex.ts → dex.d.ts} +96 -67
  324. package/src/types/{enso.ts → enso.d.ts} +1 -1
  325. package/src/types/exports.ts +8 -0
  326. package/src/types/{global.ts → global.d.ts} +1 -30
  327. package/src/types/{governance.ts → governance.d.ts} +2 -64
  328. package/src/types/{honeySwap.ts → honeySwap.d.ts} +1 -13
  329. package/src/types/{pol.ts → pol.d.ts} +12 -1
  330. package/src/types/staking.d.ts +22 -0
  331. package/src/utils/createEmitter.ts +122 -0
  332. package/src/utils/createEmitter.unit.test.ts +149 -0
  333. package/src/utils/{index.ts → exports.ts} +3 -2
  334. package/src/utils/filter.ts +34 -0
  335. package/src/utils/formatNumber.ts +1 -1
  336. package/src/utils/formatNumber.unit.test.ts +2 -1
  337. package/src/utils/formatTokenList.ts +4 -10
  338. package/src/utils/getHoneySwapMessage.test.ts +1 -2
  339. package/src/utils/getServerSideClient.ts +4 -5
  340. package/src/utils/isDifferenceExceedingThreshold.ts +1 -1
  341. package/src/utils/layerZeroScan.ts +122 -0
  342. package/src/utils/math.ts +1 -1
  343. package/src/utils/parseWhiskToken.ts +15 -0
  344. package/src/utils/poolNamings.ts +1 -1
  345. package/src/utils/tokens.ts +23 -7
  346. package/dist/HoneyConfigProvider-6PXZJMSU.d.cts +0 -562
  347. package/dist/HoneyConfigProvider-CwDFrt02.d.ts +0 -562
  348. package/dist/abi/index.cjs +0 -2
  349. package/dist/abi/index.cjs.map +0 -1
  350. package/dist/abi/index.mjs +0 -2
  351. package/dist/actions/index.cjs +0 -2
  352. package/dist/actions/index.cjs.map +0 -1
  353. package/dist/actions/index.mjs +0 -2
  354. package/dist/aggregatorsRouter-Cny4B_MB.d.cts +0 -593
  355. package/dist/aggregatorsRouter-Cny4B_MB.d.ts +0 -593
  356. package/dist/chunk-22MQVFHP.cjs +0 -2
  357. package/dist/chunk-22MQVFHP.cjs.map +0 -1
  358. package/dist/chunk-3TKSVFZ3.mjs +0 -2
  359. package/dist/chunk-3TKSVFZ3.mjs.map +0 -1
  360. package/dist/chunk-6VF3RF53.cjs +0 -3
  361. package/dist/chunk-6VF3RF53.cjs.map +0 -1
  362. package/dist/chunk-6W22TFYA.mjs +0 -2
  363. package/dist/chunk-6W22TFYA.mjs.map +0 -1
  364. package/dist/chunk-AMRJ4B36.mjs +0 -2
  365. package/dist/chunk-AMRJ4B36.mjs.map +0 -1
  366. package/dist/chunk-DS2ZDVKU.mjs +0 -2
  367. package/dist/chunk-DS2ZDVKU.mjs.map +0 -1
  368. package/dist/chunk-ED43NYSE.cjs +0 -2
  369. package/dist/chunk-ED43NYSE.cjs.map +0 -1
  370. package/dist/chunk-EU4WFADK.cjs +0 -2
  371. package/dist/chunk-EU4WFADK.cjs.map +0 -1
  372. package/dist/chunk-HCTFDGXL.mjs +0 -2
  373. package/dist/chunk-HCTFDGXL.mjs.map +0 -1
  374. package/dist/chunk-IOSYBHKU.mjs +0 -2
  375. package/dist/chunk-IOSYBHKU.mjs.map +0 -1
  376. package/dist/chunk-JMKLDDKY.cjs +0 -2
  377. package/dist/chunk-JMKLDDKY.cjs.map +0 -1
  378. package/dist/chunk-KMKUXP2S.mjs +0 -3
  379. package/dist/chunk-KMKUXP2S.mjs.map +0 -1
  380. package/dist/chunk-OJXJ6CZ4.mjs +0 -4
  381. package/dist/chunk-OJXJ6CZ4.mjs.map +0 -1
  382. package/dist/chunk-PHIOKO3A.mjs +0 -2
  383. package/dist/chunk-PHIOKO3A.mjs.map +0 -1
  384. package/dist/chunk-QCK474XD.cjs +0 -2
  385. package/dist/chunk-QCK474XD.cjs.map +0 -1
  386. package/dist/chunk-REDXXUK7.cjs +0 -2
  387. package/dist/chunk-REDXXUK7.cjs.map +0 -1
  388. package/dist/chunk-S74ZMG2G.cjs +0 -2
  389. package/dist/chunk-S74ZMG2G.cjs.map +0 -1
  390. package/dist/chunk-TOAXF4YW.cjs +0 -2
  391. package/dist/chunk-TOAXF4YW.cjs.map +0 -1
  392. package/dist/chunk-UZ5CB33M.cjs +0 -2
  393. package/dist/chunk-UZ5CB33M.cjs.map +0 -1
  394. package/dist/chunk-VYWYJR63.mjs +0 -2
  395. package/dist/chunk-VYWYJR63.mjs.map +0 -1
  396. package/dist/chunk-XFPTQMAK.cjs +0 -4
  397. package/dist/chunk-XFPTQMAK.cjs.map +0 -1
  398. package/dist/chunk-YK4NINF5.mjs +0 -2
  399. package/dist/chunk-YK4NINF5.mjs.map +0 -1
  400. package/dist/contexts/index.cjs +0 -2
  401. package/dist/contexts/index.cjs.map +0 -1
  402. package/dist/contexts/index.mjs +0 -2
  403. package/dist/contexts/index.mjs.map +0 -1
  404. package/dist/enum/index.cjs +0 -2
  405. package/dist/enum/index.cjs.map +0 -1
  406. package/dist/enum/index.d.cts +0 -31
  407. package/dist/enum/index.d.ts +0 -31
  408. package/dist/enum/index.mjs +0 -2
  409. package/dist/enum/index.mjs.map +0 -1
  410. package/dist/errors/index.cjs +0 -2
  411. package/dist/errors/index.cjs.map +0 -1
  412. package/dist/errors/index.d.cts +0 -204
  413. package/dist/errors/index.d.ts +0 -204
  414. package/dist/errors/index.mjs +0 -2
  415. package/dist/errors/index.mjs.map +0 -1
  416. package/dist/hooks/index.cjs +0 -4
  417. package/dist/hooks/index.cjs.map +0 -1
  418. package/dist/hooks/index.mjs +0 -4
  419. package/dist/hooks/index.mjs.map +0 -1
  420. package/dist/staking-F9Nx9TKD.d.ts +0 -246
  421. package/dist/staking-f4BpYH7l.d.cts +0 -246
  422. package/dist/types/index.cjs +0 -2
  423. package/dist/types/index.cjs.map +0 -1
  424. package/dist/types/index.d.cts +0 -56
  425. package/dist/types/index.d.ts +0 -56
  426. package/dist/types/index.mjs +0 -2
  427. package/dist/types/index.mjs.map +0 -1
  428. package/dist/utils/index.cjs +0 -2
  429. package/dist/utils/index.cjs.map +0 -1
  430. package/dist/utils/index.mjs +0 -2
  431. package/dist/utils/index.mjs.map +0 -1
  432. package/src/actions/dex/getTransactionCount.ts +0 -29
  433. package/src/actions/enso/bend.ts +0 -143
  434. package/src/actions/enso/getEnsoUserToken.debug.test.ts +0 -57
  435. package/src/contexts/berajsProvider/context.tsx +0 -49
  436. package/src/contexts/berajsProvider/index.ts +0 -2
  437. package/src/contexts/berajsProvider/useBeraJs.ts +0 -18
  438. package/src/hooks/dex/usePollVaultIsPaused.ts +0 -30
  439. package/src/hooks/enso/useBendTransactionRequests.ts +0 -247
  440. package/src/hooks/enso/useEnsoZap.ts +0 -166
  441. package/src/hooks/enso/useZapTransactionRequests.ts +0 -81
  442. package/src/hooks/pol/useEarnedStakedBeraVault.ts +0 -59
  443. package/src/hooks/pol/useStakedBeraSnapshots.ts +0 -27
  444. package/src/hooks/validators/validatorRoleManager.ts +0 -0
  445. package/src/types/index.ts +0 -8
  446. package/src/types/staking.ts +0 -7
  447. package/src/utils/formatAggregatorsQuotes.ts +0 -57
  448. package/src/utils/formatAggregatorsQuotes.unit.test.ts +0 -191
  449. package/src/utils/sentryBeforeSend.ts +0 -52
  450. /package/dist/{abi/index.mjs.map → errors/exports.mjs.map} +0 -0
  451. /package/dist/{actions/index.mjs.map → types/exports.mjs.map} +0 -0
  452. /package/src/actions/dex/{__tests__ → aggregators}/haiku.integration.test.ts +0 -0
  453. /package/src/types/{bribe-boost.ts → bribe-boost.d.ts} +0 -0
@@ -1,143 +0,0 @@
1
- import type { BundleAction, EnsoClient } from "@ensofinance/sdk";
2
- import { type Address, ethAddress, type PublicClient, zeroAddress } from "viem";
3
-
4
- import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
5
- import type { GetZapTransactionResponse, Quantity } from "~/types";
6
- import { getTransactionsFromBundle } from "./util";
7
-
8
- export interface GetBendTransactionRequestsArgs {
9
- fromAddress: Address;
10
- amountIn: Quantity;
11
- tokenIn: Address;
12
- loanToken: Address;
13
- bendVault: Address;
14
- rewardVault?: Address;
15
- chainId: number;
16
- ensoClient: EnsoClient;
17
- destinationChainId?: number;
18
- slippage: number;
19
- publicClient: PublicClient;
20
- }
21
-
22
- export async function getBendTransactionRequests({
23
- fromAddress,
24
- amountIn,
25
- tokenIn,
26
- loanToken,
27
- bendVault,
28
- rewardVault,
29
- chainId,
30
- ensoClient,
31
- destinationChainId,
32
- slippage,
33
- publicClient,
34
- }: GetBendTransactionRequestsArgs): Promise<GetZapTransactionResponse> {
35
- if (!fromAddress) {
36
- throw new InvalidArgumentError({
37
- property: "fromAddress",
38
- value: fromAddress,
39
- expected: "string",
40
- });
41
- }
42
- if (loanToken === zeroAddress) loanToken = ethAddress;
43
-
44
- const bundleActions: BundleAction[] = [
45
- {
46
- protocol: "enso",
47
- action: "route",
48
- args: {
49
- tokenIn,
50
- tokenOut: loanToken,
51
- amountIn,
52
- slippage: slippage * 100, // Enso expects slippage in basis points
53
- },
54
- },
55
- ];
56
- /**
57
- * If the zap is cross chain, we need to add the destination chain id and the refund receiver.
58
- *
59
- * Enso still need to update the sdk types to support this.
60
- */
61
- if (destinationChainId && destinationChainId !== chainId) {
62
- bundleActions[0].args = {
63
- ...bundleActions[0].args,
64
- //@ts-expect-error enso are releasing a fix in the next 2 weeks for this.
65
- destinationChainId: destinationChainId,
66
- refundReceiver: fromAddress,
67
- };
68
- }
69
- // vault output is the vault address
70
- // vaults are in morpho-blue-vaults-v1
71
- // markets are here morpho-markets-v1"
72
- bundleActions.push({
73
- protocol: "erc4626",
74
- action: "deposit",
75
- args: {
76
- amountIn: { useOutputOfCallAt: 0 },
77
- tokenIn: loanToken,
78
- primaryAddress: bendVault,
79
- tokenOut: bendVault,
80
- },
81
- });
82
- if (rewardVault) {
83
- bundleActions.push(
84
- {
85
- protocol: "enso",
86
- action: "balance",
87
- args: {
88
- token: bendVault,
89
- },
90
- },
91
- {
92
- protocol: "erc20",
93
- action: "approve",
94
- args: {
95
- amount: { useOutputOfCallAt: 2 },
96
- spender: rewardVault,
97
- token: bendVault,
98
- },
99
- },
100
- {
101
- protocol: "enso",
102
- action: "call",
103
- args: {
104
- address: rewardVault,
105
- args: [fromAddress, { useOutputOfCallAt: 2 }],
106
- method: "stakeOnBehalf",
107
- abi: "function stakeOnBehalf(address account, uint256 amount) external",
108
- },
109
- },
110
- {
111
- protocol: "enso",
112
- action: "balance",
113
- args: {
114
- token: rewardVault,
115
- },
116
- },
117
- );
118
- }
119
-
120
- const bundle = await ensoClient.getBundleData(
121
- {
122
- fromAddress: fromAddress,
123
- receiver: fromAddress,
124
- spender: fromAddress,
125
- chainId: chainId,
126
- routingStrategy: "router",
127
- },
128
- bundleActions,
129
- );
130
- const transactions = await getTransactionsFromBundle({
131
- fromAddress,
132
- amountIn,
133
- tokenIn,
134
- chainId,
135
- ensoClient,
136
- bundle,
137
- publicClient,
138
- });
139
- return {
140
- bundle,
141
- transactions,
142
- };
143
- }
@@ -1,57 +0,0 @@
1
- import * as Sentry from "@sentry/nextjs";
2
- import {
3
- afterEach,
4
- beforeEach,
5
- describe,
6
- expect,
7
- it,
8
- type MockInstance,
9
- vi,
10
- } from "vitest";
11
-
12
- import { wagmiConfig } from "@berachain/wagmi/config";
13
-
14
- import { getEnsoClient } from "../clients/getEnsoClient";
15
- import { getEnsoUserToken } from "./getEnsoUserToken";
16
-
17
- describe("getEnsoUserToken", () => {
18
- let fetchSpy: MockInstance<typeof global.fetch>;
19
-
20
- beforeEach(() => {
21
- vi.clearAllMocks();
22
-
23
- vi.mock(import("@sentry/nextjs"), () => ({
24
- captureException: vi.fn(),
25
- }));
26
-
27
- fetchSpy = vi.spyOn(global, "fetch");
28
- });
29
-
30
- afterEach(() => {
31
- vi.clearAllMocks();
32
- });
33
-
34
- const address = "0x79f453D56C4bC66586215827FbBc7B34Bc006b33";
35
- it("should be using multicall for each chain", async () => {
36
- const ensoClient = getEnsoClient();
37
-
38
- const ensoUserToken = await getEnsoUserToken({
39
- account: address,
40
- wagmiConfig: wagmiConfig,
41
- chainId: "all",
42
- ensoClient: ensoClient,
43
- });
44
-
45
- expect(ensoUserToken.length).toBeGreaterThan(0);
46
-
47
- expect(fetchSpy).toHaveBeenCalled();
48
- expect(Sentry.captureException).not.toHaveBeenCalled();
49
-
50
- const chains = Object.groupBy(ensoUserToken, (token) => token.chainId ?? 0);
51
- const chainIds = Object.keys(chains)
52
- .map(Number)
53
- .filter((chainId) => chainId !== 0);
54
-
55
- expect(fetchSpy).toHaveBeenCalledTimes(1 + chainIds.length);
56
- });
57
- });
@@ -1,49 +0,0 @@
1
- "use client";
2
-
3
- import {
4
- createContext,
5
- type PropsWithChildren,
6
- useEffect,
7
- useMemo,
8
- useState,
9
- } from "react";
10
- import BigNumber from "bignumber.js";
11
-
12
- import { useBeraAccount, useBeraWagmi } from "@berachain/wagmi/hooks";
13
-
14
- import { TransactionStoreProvider } from "~/hooks/transactions/TransactionStoreContext";
15
-
16
- BigNumber.config({
17
- EXPONENTIAL_AT: 1e9,
18
- });
19
-
20
- export interface IBeraJsAPI {
21
- /**
22
- * @deprecated check `useBeraAccount.isConnected` instead and wrap transaction in ActionButton to ensure it's wallet chain is connected.
23
- */
24
- isReady?: boolean;
25
- }
26
-
27
- export const BeraJsContext = createContext<IBeraJsAPI | undefined>(undefined);
28
-
29
- export function BeraJsProvider({ children }: PropsWithChildren) {
30
- const [isMounted, setIsMounted] = useState(false);
31
- const { walletClient } = useBeraWagmi();
32
- const { wallet } = useBeraAccount();
33
-
34
- useEffect(() => setIsMounted(true), []);
35
-
36
- return (
37
- <BeraJsContext.Provider
38
- value={{
39
- isReady: useMemo(
40
- () => !!wallet?.address && isMounted,
41
- [wallet?.address, isMounted, walletClient],
42
- ),
43
- }}
44
- >
45
- <TransactionStoreProvider>{children}</TransactionStoreProvider>
46
- </BeraJsContext.Provider>
47
- );
48
- }
49
- export default BeraJsProvider;
@@ -1,2 +0,0 @@
1
- export * from "./context";
2
- export { default as useBeraJs } from "./useBeraJs";
@@ -1,18 +0,0 @@
1
- import { useContext } from "react";
2
-
3
- import { BeraJsContext } from "./context";
4
-
5
- /**
6
- * @deprecated use useBeraAccount and useBeraWagmi instead
7
- */
8
- export function useBeraJs() {
9
- const beraJsContext = useContext(BeraJsContext);
10
-
11
- if (beraJsContext === undefined) {
12
- throw new Error("bera js context undefined");
13
- }
14
-
15
- return beraJsContext;
16
- }
17
-
18
- export default useBeraJs;
@@ -1,30 +0,0 @@
1
- import useSWR from "swr";
2
-
3
- import { usePublicClient } from "@berachain/wagmi/hooks";
4
-
5
- import { getVaultPausedState } from "~/actions/dex/getVaultPausedState";
6
- import { POLLING } from "~/enum/polling";
7
- import { assertPublicClient } from "~/errors/assert";
8
- import type { DefaultHookOptions } from "~/types/global";
9
-
10
- // Determine if a Vault status is paused or not NOTE: there is no recovery mode for vaults.
11
- export function usePollVaultIsPaused(options?: DefaultHookOptions) {
12
- const publicClient = usePublicClient();
13
-
14
- const swrResponse = useSWR(
15
- publicClient ? ["usePollVaultIsPaused"] : null,
16
- async () => {
17
- assertPublicClient(publicClient);
18
-
19
- return getVaultPausedState({ publicClient });
20
- },
21
- {
22
- ...options?.opts,
23
- refreshInterval: options?.opts?.refreshInterval ?? POLLING.NORMAL,
24
- },
25
- );
26
-
27
- return {
28
- ...swrResponse,
29
- };
30
- }
@@ -1,247 +0,0 @@
1
- "use client";
2
-
3
- import useSWR from "swr";
4
- import type { Address } from "viem";
5
-
6
- import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
7
-
8
- import { getConvertToAssets } from "~/actions";
9
- import { POLLING } from "~/enum/polling";
10
- import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
11
- import type {
12
- BalanceTokenWithMetadata,
13
- GetZapTransactionResponse,
14
- } from "~/types";
15
- import type { DefaultHookOptions } from "~/types/global";
16
- import { computePriceImpact } from "~/utils/math";
17
- import { isToken } from "~/utils/tokens";
18
- import { useEnsoZap } from "./useEnsoZap";
19
-
20
- type UseBendTransactionRequestsArgs = {
21
- /*
22
- * The input token to swap from
23
- */
24
- tokenIn?: Pick<
25
- BalanceTokenWithMetadata,
26
- "address" | "decimals" | "price" | "formattedBalance" | "chainId"
27
- >;
28
- /*
29
- * The loan token to swap to
30
- */
31
- loanTokenAddress: Address;
32
- /*
33
- * The price of the loan token
34
- */
35
- loanTokenPrice: number | undefined;
36
- /*
37
- * The bend vault to swap to
38
- */
39
- bendVault: Address;
40
- /*
41
- * The reward vault to swap to
42
- */
43
- rewardVault?: Address;
44
- /*
45
- * The amount of input token to swap
46
- */
47
- amount?: string;
48
- /*
49
- * The slippage tolerance to use for the route in percentage
50
- */
51
- slippage?: number;
52
- /*
53
- * The chain id to use for the public client
54
- */
55
- chainId?: number;
56
- };
57
-
58
- /**
59
- * Get the bend transaction requests for swapping tokens using Enso.
60
- * @param {UseBendTransactionRequestsArgs} props - The props for the hook see {@link UseBendTransactionRequestsArgs}
61
- * @returns {DefaultHookReturnType<GetZapTransactionResponse> & {tokens: BalanceTokenWithMetadata[], refresh: () => void}}
62
- *
63
- * The bend transaction response data with polling enabled, see {@link GetZapTransactionResponse} and {@link BalanceTokenWithMetadata}
64
- * @remarks The hook is only enabled when all parameters are provided and amount is greater than 0
65
- * @see {@link useEnsoZap}
66
- */
67
- export function useBendTransactionRequests(
68
- {
69
- tokenIn,
70
- loanTokenAddress,
71
- loanTokenPrice,
72
- bendVault,
73
- rewardVault,
74
- amount,
75
- slippage,
76
- chainId,
77
- }: UseBendTransactionRequestsArgs,
78
- options?: DefaultHookOptions,
79
- ) {
80
- const { tokens, refreshTokens } = useEnsoZap({
81
- chainId,
82
- });
83
-
84
- // this is using a dummy amount to get the gas
85
- // this allows us to not wait on the user input for fees
86
- const { data: dataForGas, error: errorForGas } =
87
- useBendTransactionRequestsHelper(
88
- {
89
- tokenIn,
90
- loanTokenAddress,
91
- loanTokenPrice,
92
- bendVault,
93
- rewardVault,
94
- amount: tokenIn?.formattedBalance,
95
- slippage,
96
- chainId: tokenIn?.chainId,
97
- },
98
- options,
99
- );
100
-
101
- // sum the value of the transactions
102
- const transactionValue =
103
- dataForGas?.transactions?.reduce(
104
- (acc, transaction) => acc + BigInt(transaction.value ?? 0n),
105
- 0n,
106
- ) ?? 0n;
107
-
108
- const nativeToken = tokens?.find(
109
- (token) => isToken(token, "ETH") && token.chainId === tokenIn?.chainId,
110
- );
111
-
112
- // enso is charging a fee, we need to subtract the value of the transaction from the chain token balance to get fee
113
- const nativeFee =
114
- BigInt(transactionValue) - BigInt(nativeToken?.balance ?? 0n);
115
-
116
- const swrResponse = useBendTransactionRequestsHelper(
117
- {
118
- tokenIn,
119
- loanTokenAddress,
120
- loanTokenPrice,
121
- bendVault,
122
- rewardVault,
123
- amount,
124
- slippage,
125
- chainId,
126
- },
127
- options,
128
- );
129
-
130
- return {
131
- ...swrResponse,
132
- nativeFee,
133
- error: errorForGas || swrResponse.error,
134
- tokens,
135
- refresh: () => {
136
- swrResponse.mutate();
137
- refreshTokens();
138
- },
139
- };
140
- }
141
-
142
- export function useBendTransactionRequestsHelper(
143
- {
144
- tokenIn,
145
- loanTokenAddress,
146
- loanTokenPrice,
147
- bendVault,
148
- rewardVault,
149
- amount,
150
- slippage,
151
- chainId,
152
- }: UseBendTransactionRequestsArgs,
153
- options?: DefaultHookOptions,
154
- ) {
155
- const { address: fromAddress } = useBeraWallet();
156
- const { getBendTransactionRequests } = useEnsoZap({
157
- chainId,
158
- });
159
- const isEnabled =
160
- !!tokenIn &&
161
- !!loanTokenAddress &&
162
- !!bendVault &&
163
- !!amount &&
164
- !!fromAddress &&
165
- !isToken(loanTokenAddress, tokenIn?.address) &&
166
- tokenIn.chainId &&
167
- Number(amount) > 0 &&
168
- !!slippage;
169
- const publicClient = usePublicClient({
170
- chainId,
171
- });
172
- const publicClientBeraChain = usePublicClient();
173
- const QUERY_KEY = isEnabled
174
- ? ([
175
- "useBendTransactionRequests",
176
- tokenIn,
177
- loanTokenAddress,
178
- loanTokenPrice,
179
- bendVault,
180
- rewardVault,
181
- amount,
182
- slippage,
183
- ] as const)
184
- : null;
185
-
186
- return useSWR(
187
- QUERY_KEY,
188
- async ([
189
- ,
190
- tokenIn,
191
- loanTokenAddress,
192
- loanTokenPrice,
193
- bendVault,
194
- rewardVault,
195
- amount,
196
- slippage,
197
- ]) => {
198
- if (!publicClient || !publicClientBeraChain) {
199
- throw new InvalidArgumentError({
200
- property: "publicClient",
201
- value: publicClient,
202
- expected: "PublicClient",
203
- });
204
- }
205
-
206
- const response = await getBendTransactionRequests({
207
- amount,
208
- tokenIn: tokenIn,
209
- loanToken: loanTokenAddress,
210
- bendVault,
211
- rewardVault,
212
- slippage,
213
- });
214
-
215
- const amountOutObject = response.bundle.amountsOut;
216
- const address = rewardVault
217
- ? (rewardVault.toLowerCase() as Address)
218
- : (bendVault.toLowerCase() as Address);
219
- const amountOut = amountOutObject[address];
220
- const supplyAmount = await getConvertToAssets({
221
- sharesAmount: BigInt(amountOut),
222
- vaultAddress: bendVault,
223
- publicClient: publicClientBeraChain,
224
- });
225
-
226
- const priceImpact =
227
- tokenIn?.price && loanTokenPrice
228
- ? computePriceImpact(
229
- tokenIn?.price?.toString(),
230
- loanTokenPrice?.toString(),
231
- amount,
232
- supplyAmount.formatted,
233
- )
234
- : undefined;
235
-
236
- return {
237
- supplyAmount,
238
- priceImpact,
239
- ...response,
240
- };
241
- },
242
- {
243
- ...options?.opts,
244
- refreshInterval: POLLING.NORMAL,
245
- },
246
- );
247
- }
@@ -1,166 +0,0 @@
1
- "use client";
2
-
3
- import { useCallback } from "react";
4
- import type { BundleData, EnsoClient } from "@ensofinance/sdk";
5
- import { getPublicClient } from "@wagmi/core";
6
- import useSWR from "swr";
7
- import { type Address, isAddress, parseUnits } from "viem";
8
-
9
- import { defaultChainId as berachainChainId } from "@berachain/config/internal";
10
-
11
- import { useBeraWallet, useConfig } from "@berachain/wagmi/hooks";
12
-
13
- import { getBendTransactionRequests as getBendTransactionRequestsHelper } from "~/actions/enso/bend";
14
- import { getZapTransactionRequests as getZapTransactionRequestsHelper } from "~/actions/enso/zap";
15
- import type {
16
- BalanceToken,
17
- BalanceTokenWithMetadata,
18
- GetZapTransactionResponse,
19
- } from "~/types";
20
-
21
- export type { GetZapTransactionResponse, BundleData, BalanceTokenWithMetadata };
22
-
23
- import { getEnsoClient } from "~/actions/clients/getEnsoClient";
24
- import { getEnsoUserToken } from "~/actions/enso/getEnsoUserToken";
25
- import { POLLING } from "~/enum/polling";
26
- import {
27
- assertAddress,
28
- assertDefined,
29
- assertPublicClient,
30
- } from "~/errors/assert";
31
- import type { DefaultHookOptions } from "~/types/global";
32
-
33
- function useEnsoBalances(
34
- { ensoClient, chainId }: { ensoClient: EnsoClient; chainId?: number },
35
- options?: DefaultHookOptions,
36
- ) {
37
- const { address: fromAddress } = useBeraWallet();
38
- const wagmiConfig = useConfig();
39
- const isEnabled = !!fromAddress && isAddress(fromAddress);
40
-
41
- const QUERY_KEY =
42
- isEnabled && wagmiConfig
43
- ? (["useEnsoBalances", fromAddress, chainId] as const)
44
- : null;
45
-
46
- const swrResponse = useSWR(
47
- QUERY_KEY,
48
- async ([, fromAddress, chainId]): Promise<BalanceTokenWithMetadata[]> =>
49
- getEnsoUserToken({
50
- account: fromAddress,
51
- wagmiConfig,
52
- chainId: chainId ?? "all",
53
- ensoClient,
54
- }),
55
- {
56
- refreshInterval: POLLING.FAST,
57
- isEnabled,
58
- ...options?.opts,
59
- },
60
- );
61
- return {
62
- ...swrResponse,
63
- refresh: () => swrResponse.mutate(),
64
- };
65
- }
66
-
67
- /**
68
- * Get the enso client.
69
- * @returns {EnsoClient} The enso client, see {@link EnsoClient}
70
- * @see {@link useEnsoBalances}
71
- * @see {@link useTokens}
72
- */
73
- export function useEnsoZap({ chainId }: { chainId?: number }) {
74
- const { address: fromAddress } = useBeraWallet();
75
- const wagmiConfig = useConfig();
76
- const ensoClient = getEnsoClient();
77
- const { data: tokens, refresh: refreshTokens } = useEnsoBalances({
78
- ensoClient,
79
- chainId,
80
- });
81
-
82
- const getZapTransactionRequests = useCallback(
83
- async ({
84
- tokenIn,
85
- tokenOut,
86
- amount,
87
- slippage,
88
- }: {
89
- tokenIn?: Pick<BalanceToken, "address" | "decimals" | "chainId">;
90
- tokenOut: Address;
91
- amount: string;
92
- slippage: number;
93
- }): Promise<GetZapTransactionResponse> => {
94
- assertAddress(fromAddress, "fromAddress");
95
- assertAddress(tokenIn?.address, "tokenInAddress");
96
- assertDefined(tokenIn?.chainId, "tokenInChainId");
97
- const publicClient = getPublicClient(wagmiConfig, {
98
- chainId: tokenIn.chainId,
99
- });
100
- assertPublicClient(publicClient);
101
- const rawAmount = parseUnits(amount, tokenIn.decimals).toString();
102
-
103
- return getZapTransactionRequestsHelper({
104
- fromAddress,
105
- amountIn: rawAmount,
106
- tokenIn: tokenIn?.address,
107
- tokenOut,
108
- chainId: tokenIn.chainId,
109
- ensoClient,
110
- destinationChainId: berachainChainId,
111
- slippage,
112
- publicClient,
113
- });
114
- },
115
- [fromAddress, ensoClient, wagmiConfig],
116
- );
117
-
118
- const getBendTransactionRequests = useCallback(
119
- async ({
120
- tokenIn,
121
- amount,
122
- loanToken,
123
- bendVault,
124
- rewardVault,
125
- slippage,
126
- }: {
127
- tokenIn?: Pick<BalanceToken, "address" | "decimals" | "chainId">;
128
- amount: string;
129
- loanToken: Address;
130
- bendVault: Address;
131
- rewardVault?: Address;
132
- slippage: number;
133
- }): Promise<GetZapTransactionResponse> => {
134
- assertAddress(fromAddress, "fromAddress");
135
- assertAddress(tokenIn?.address, "tokenInAddress");
136
- assertDefined(tokenIn?.chainId, "tokenInChainId");
137
- const publicClient = getPublicClient(wagmiConfig, {
138
- chainId: tokenIn.chainId,
139
- });
140
- assertPublicClient(publicClient);
141
- const rawAmount = parseUnits(amount, tokenIn.decimals).toString();
142
-
143
- return getBendTransactionRequestsHelper({
144
- fromAddress,
145
- amountIn: rawAmount,
146
- tokenIn: tokenIn.address,
147
- loanToken,
148
- bendVault,
149
- rewardVault,
150
- chainId: tokenIn.chainId,
151
- ensoClient,
152
- destinationChainId: berachainChainId,
153
- slippage,
154
- publicClient,
155
- });
156
- },
157
- [fromAddress, ensoClient, wagmiConfig],
158
- );
159
-
160
- return {
161
- tokens,
162
- getBendTransactionRequests,
163
- getZapTransactionRequests,
164
- refreshTokens,
165
- };
166
- }