@berachain/berajs 0.2.13 → 0.3.1

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 (387) hide show
  1. package/dist/actions/clients/BeraApolloClient.d.ts.map +1 -1
  2. package/dist/actions/clients/clientName.d.ts +10 -0
  3. package/dist/actions/clients/clientName.d.ts.map +1 -0
  4. package/dist/actions/clients/clientName.unit.test.d.ts +2 -0
  5. package/dist/actions/clients/clientName.unit.test.d.ts.map +1 -0
  6. package/dist/actions/clients/exports.d.ts +2 -0
  7. package/dist/actions/clients/exports.d.ts.map +1 -1
  8. package/dist/actions/clients/exports.mjs +26 -7
  9. package/dist/actions/clients/exports.mjs.map +1 -1
  10. package/dist/actions/clients/fetchBeep.d.ts +2 -2
  11. package/dist/actions/clients/fetchBeep.d.ts.map +1 -1
  12. package/dist/actions/clients/fetchEnso.d.ts +17 -0
  13. package/dist/actions/clients/fetchEnso.d.ts.map +1 -0
  14. package/dist/actions/clients/fetchLayerzero.d.ts +12 -0
  15. package/dist/actions/clients/fetchLayerzero.d.ts.map +1 -0
  16. package/dist/actions/clients/fetchOpenApi.d.ts +4 -1
  17. package/dist/actions/clients/fetchOpenApi.d.ts.map +1 -1
  18. package/dist/actions/clients/getApolloClient.d.ts.map +1 -1
  19. package/dist/actions/dex/aggregators/base.d.ts +30 -5
  20. package/dist/actions/dex/aggregators/base.d.ts.map +1 -1
  21. package/dist/actions/dex/aggregators/bex.d.ts +11 -1
  22. package/dist/actions/dex/aggregators/bex.d.ts.map +1 -1
  23. package/dist/actions/dex/aggregators/bgt.d.ts +2 -2
  24. package/dist/actions/dex/aggregators/bgt.d.ts.map +1 -1
  25. package/dist/actions/dex/aggregators/enso/enso.d.ts.map +1 -1
  26. package/dist/actions/dex/aggregators/enso/ensoErc4626.d.ts +1 -0
  27. package/dist/actions/dex/aggregators/enso/ensoErc4626.d.ts.map +1 -1
  28. package/dist/actions/dex/aggregators/erc4626.d.ts +2 -2
  29. package/dist/actions/dex/aggregators/erc4626.d.ts.map +1 -1
  30. package/dist/actions/dex/aggregators/fly.d.ts.map +1 -1
  31. package/dist/actions/dex/aggregators/haiku.d.ts +7 -1
  32. package/dist/actions/dex/aggregators/haiku.d.ts.map +1 -1
  33. package/dist/actions/dex/aggregators/honey.d.ts +2 -2
  34. package/dist/actions/dex/aggregators/honey.d.ts.map +1 -1
  35. package/dist/actions/dex/aggregators/kyberswap.d.ts.map +1 -1
  36. package/dist/actions/dex/aggregators/oogabooga.d.ts.map +1 -1
  37. package/dist/actions/dex/aggregators/openOcean.d.ts.map +1 -1
  38. package/dist/actions/dex/aggregators/wbera.d.ts +3 -2
  39. package/dist/actions/dex/aggregators/wbera.d.ts.map +1 -1
  40. package/dist/actions/dex/getAllPools.d.ts.map +1 -1
  41. package/dist/actions/dex/getApiPool.d.ts.map +1 -1
  42. package/dist/actions/enso/getEnsoUserTokensWithBalances.d.ts.map +1 -1
  43. package/dist/actions/enso/util.d.ts +1 -6
  44. package/dist/actions/enso/util.d.ts.map +1 -1
  45. package/dist/actions/exports.d.ts +3 -5
  46. package/dist/actions/exports.d.ts.map +1 -1
  47. package/dist/actions/exports.mjs +33 -64
  48. package/dist/actions/exports.mjs.map +1 -1
  49. package/dist/actions/governance/exports.mjs +3 -3
  50. package/dist/actions/honey/getChartData.d.ts +1 -1
  51. package/dist/actions/honey/getChartData.d.ts.map +1 -1
  52. package/dist/actions/honey/getHoney24hVolume.d.ts +2 -2
  53. package/dist/actions/honey/getHoney24hVolume.d.ts.map +1 -1
  54. package/dist/actions/honey/getHoneyCollaterals.d.ts +1 -1
  55. package/dist/actions/honey/getHoneyCollaterals.d.ts.map +1 -1
  56. package/dist/actions/honey/getHoneyTxns.d.ts +1 -1
  57. package/dist/actions/honey/getHoneyTxns.d.ts.map +1 -1
  58. package/dist/actions/pol/getBGTGlobalInfo.d.ts +0 -1
  59. package/dist/actions/pol/getBGTGlobalInfo.d.ts.map +1 -1
  60. package/dist/actions/pol/getBeraTokenTotalSupply.d.ts.map +1 -1
  61. package/dist/actions/pol/getEarnedStakedBeraVault.d.ts +4 -27
  62. package/dist/actions/pol/getEarnedStakedBeraVault.d.ts.map +1 -1
  63. package/dist/actions/pol/getLSTStakeConfig.d.ts.map +1 -1
  64. package/dist/actions/pol/getRewardVaults.d.ts.map +1 -1
  65. package/dist/actions/pol/getSWBeraVaultMetadata.d.ts +1 -14
  66. package/dist/actions/pol/getSWBeraVaultMetadata.d.ts.map +1 -1
  67. package/dist/actions/pol/getStakedBeraAPY.d.ts +14 -0
  68. package/dist/actions/pol/getStakedBeraAPY.d.ts.map +1 -0
  69. package/dist/actions/pol/getStakedBeraSnapshots.d.ts +14 -4
  70. package/dist/actions/pol/getStakedBeraSnapshots.d.ts.map +1 -1
  71. package/dist/actions/pol/getStakingDailyAssets.d.ts +2 -2
  72. package/dist/actions/pol/getStakingDailyAssets.d.ts.map +1 -1
  73. package/dist/actions/server/exports.mjs +5 -5
  74. package/dist/actions/server/exports.mjs.map +1 -1
  75. package/dist/actions/server/getDailyValidatorBlockStats.d.ts +1 -1
  76. package/dist/actions/server/getDailyValidatorBlockStats.d.ts.map +1 -1
  77. package/dist/actions/validators/getActiveBoostAndCommissionChangeDelay.d.ts +1 -1
  78. package/dist/actions/validators/getActiveBoostAndCommissionChangeDelay.d.ts.map +1 -1
  79. package/dist/actions/validators/getUserActiveValidators.d.ts +37 -1
  80. package/dist/actions/validators/getUserActiveValidators.d.ts.map +1 -1
  81. package/dist/actions/validators/getValidatorIncentiveDistribution.d.ts +1 -1
  82. package/dist/actions/validators/getValidatorIncentiveDistribution.d.ts.map +1 -1
  83. package/dist/actions/validators/getValidatorRewardAllocation.d.ts +4 -0
  84. package/dist/actions/validators/getValidatorRewardAllocation.d.ts.map +1 -1
  85. package/dist/chunk-3TRTSTDH.mjs +19 -0
  86. package/dist/chunk-3TRTSTDH.mjs.map +1 -0
  87. package/dist/{chunk-ZWTGVIPJ.mjs → chunk-4576RF2K.mjs} +29 -4
  88. package/dist/chunk-4576RF2K.mjs.map +1 -0
  89. package/dist/{chunk-PHYZRH4I.mjs → chunk-5MUCX35C.mjs} +9 -13
  90. package/dist/chunk-5MUCX35C.mjs.map +1 -0
  91. package/dist/{chunk-UA3Z47LT.mjs → chunk-6D4S3EAC.mjs} +97 -26
  92. package/dist/chunk-6D4S3EAC.mjs.map +1 -0
  93. package/dist/{chunk-AEN6IJFU.mjs → chunk-7KN7TDUC.mjs} +2 -2
  94. package/dist/{chunk-LE4CYW7S.mjs → chunk-FWRYUIJK.mjs} +3 -3
  95. package/dist/chunk-GDUKRUHE.mjs +29 -0
  96. package/dist/chunk-GDUKRUHE.mjs.map +1 -0
  97. package/dist/{chunk-PJRLHTGC.mjs → chunk-HPRLNT6R.mjs} +3 -3
  98. package/dist/{chunk-DOZJB6IJ.mjs → chunk-KY7JMIIS.mjs} +394 -346
  99. package/dist/chunk-KY7JMIIS.mjs.map +1 -0
  100. package/dist/{chunk-P3YZ7F22.mjs → chunk-LL7XR2H5.mjs} +34 -3
  101. package/dist/chunk-LL7XR2H5.mjs.map +1 -0
  102. package/dist/{chunk-EJIGERYM.mjs → chunk-M3MIGSH3.mjs} +2 -2
  103. package/dist/{chunk-NZAH3SGT.mjs → chunk-MVNQY2D4.mjs} +9 -4
  104. package/dist/chunk-MVNQY2D4.mjs.map +1 -0
  105. package/dist/{chunk-TGN55GKE.mjs → chunk-SC3BSCTN.mjs} +2 -2
  106. package/dist/{chunk-QQASX4LJ.mjs → chunk-TXWDUJOY.mjs} +2 -2
  107. package/dist/{chunk-EGAB6NFQ.mjs → chunk-UWJQ6UKG.mjs} +2 -2
  108. package/dist/chunk-XO2BFPTB.mjs +50 -0
  109. package/dist/chunk-XO2BFPTB.mjs.map +1 -0
  110. package/dist/{chunk-7TFV6UKF.mjs → chunk-XXKPXNQD.mjs} +1 -2
  111. package/dist/chunk-XXKPXNQD.mjs.map +1 -0
  112. package/dist/{chunk-IFNIPVTZ.mjs → chunk-Z337NBBW.mjs} +5 -49
  113. package/dist/chunk-Z337NBBW.mjs.map +1 -0
  114. package/dist/{chunk-J3LTASDE.mjs → chunk-ZHV3MQ4F.mjs} +4 -4
  115. package/dist/contexts/BeraFlags/BeraFlags.d.ts +1 -1
  116. package/dist/contexts/BeraFlags/BeraFlags.d.ts.map +1 -1
  117. package/dist/contexts/BeraFlags/defaultFlags.d.ts +2 -2
  118. package/dist/contexts/BeraFlags/defaultFlags.d.ts.map +1 -1
  119. package/dist/contexts/BexStatusProvider.d.ts +1 -1
  120. package/dist/contexts/BexStatusProvider.d.ts.map +1 -1
  121. package/dist/contexts/TokensProvider.d.ts +1 -1
  122. package/dist/contexts/TokensProvider.d.ts.map +1 -1
  123. package/dist/contexts/exports.mjs +9 -9
  124. package/dist/enum/contracts.d.ts +3 -0
  125. package/dist/enum/contracts.d.ts.map +1 -1
  126. package/dist/enum/exports.mjs +6 -4
  127. package/dist/enum/exports.mjs.map +1 -1
  128. package/dist/enum/txnEnum.d.ts +1 -1
  129. package/dist/enum/txnEnum.d.ts.map +1 -1
  130. package/dist/errors/RequestError.d.ts +19 -0
  131. package/dist/errors/RequestError.d.ts.map +1 -1
  132. package/dist/errors/errorMap.d.ts +4 -3
  133. package/dist/errors/errorMap.d.ts.map +1 -1
  134. package/dist/errors/exports.mjs +5 -5
  135. package/dist/errors/getErrorMessage.unit.test.d.ts +2 -0
  136. package/dist/errors/getErrorMessage.unit.test.d.ts.map +1 -0
  137. package/dist/generated/beep.d.ts +1597 -0
  138. package/dist/generated/beep.d.ts.map +1 -0
  139. package/dist/generated/enso.d.ts +4957 -0
  140. package/dist/generated/enso.d.ts.map +1 -0
  141. package/dist/generated/layerzero.d.ts +2057 -0
  142. package/dist/generated/layerzero.d.ts.map +1 -0
  143. package/dist/hooks/dex/useAggregatorsQuotes.d.ts.map +1 -1
  144. package/dist/hooks/dex/useAllUserPools.d.ts.map +1 -1
  145. package/dist/hooks/dex/useCrossChainNativeFee.d.ts +32 -0
  146. package/dist/hooks/dex/useCrossChainNativeFee.d.ts.map +1 -0
  147. package/dist/hooks/dex/useCrossChainNativeFee.unit.test.d.ts +2 -0
  148. package/dist/hooks/dex/useCrossChainNativeFee.unit.test.d.ts.map +1 -0
  149. package/dist/hooks/dex/useOnChainPoolData.d.ts.map +1 -1
  150. package/dist/hooks/dex/usePools.d.ts.map +1 -1
  151. package/dist/hooks/dex/useSingleAggregatorQuote.d.ts.map +1 -1
  152. package/dist/hooks/dex/useSingleAggregatorQuote.unit.test.d.ts +2 -0
  153. package/dist/hooks/dex/useSingleAggregatorQuote.unit.test.d.ts.map +1 -0
  154. package/dist/hooks/enso/useBendZapSupply.d.ts +2 -2
  155. package/dist/hooks/enso/useBendZapSupply.d.ts.map +1 -1
  156. package/dist/hooks/enso/useBendZapSupply.unit.test.d.ts +2 -0
  157. package/dist/hooks/enso/useBendZapSupply.unit.test.d.ts.map +1 -0
  158. package/dist/hooks/enso/useEnsoUserTokensWithBalances.d.ts.map +1 -1
  159. package/dist/hooks/enso/useEnsoUserTokensWithBalances.unit.test.d.ts +2 -0
  160. package/dist/hooks/enso/useEnsoUserTokensWithBalances.unit.test.d.ts.map +1 -0
  161. package/dist/hooks/enso/useZapStakeBera.d.ts.map +1 -1
  162. package/dist/hooks/enso/useZapStakeBera.unit.test.d.ts +2 -0
  163. package/dist/hooks/enso/useZapStakeBera.unit.test.d.ts.map +1 -0
  164. package/dist/hooks/exports.d.ts +2 -5
  165. package/dist/hooks/exports.d.ts.map +1 -1
  166. package/dist/hooks/exports.mjs +615 -911
  167. package/dist/hooks/exports.mjs.map +1 -1
  168. package/dist/hooks/governance/exports.mjs +4 -4
  169. package/dist/hooks/honey/useHoneyChartData.d.ts +4 -4
  170. package/dist/hooks/honey/useHoneyChartData.d.ts.map +1 -1
  171. package/dist/hooks/pol/useAutoclaimedIncentives.d.ts.map +1 -1
  172. package/dist/hooks/pol/useAutoclaimedIncentivesTxHash.d.ts.map +1 -1
  173. package/dist/hooks/pol/useRewardTokenToBeraRate.d.ts.map +1 -1
  174. package/dist/hooks/pol/useRewardVaultBalanceFromStakingToken.d.ts.map +1 -1
  175. package/dist/hooks/pol/useRewardVaults.d.ts.map +1 -1
  176. package/dist/hooks/pol/useStakedAPY.d.ts +11 -0
  177. package/dist/hooks/pol/useStakedAPY.d.ts.map +1 -0
  178. package/dist/hooks/pol/useStakedData.d.ts +4 -2
  179. package/dist/hooks/pol/useStakedData.d.ts.map +1 -1
  180. package/dist/hooks/pol/useStakedSnapshots.d.ts +1 -1
  181. package/dist/hooks/pol/useStakedSnapshots.d.ts.map +1 -1
  182. package/dist/hooks/pol/useStakingVaultsMetadata.d.ts +0 -1
  183. package/dist/hooks/pol/useStakingVaultsMetadata.d.ts.map +1 -1
  184. package/dist/hooks/tokens/useMultipleTokenInformation.d.ts +30 -0
  185. package/dist/hooks/tokens/useMultipleTokenInformation.d.ts.map +1 -1
  186. package/dist/hooks/tokens/useMultipleTokenInformation.unit.test.d.ts +2 -0
  187. package/dist/hooks/tokens/useMultipleTokenInformation.unit.test.d.ts.map +1 -0
  188. package/dist/hooks/tokens/usePollBalance.d.ts.map +1 -1
  189. package/dist/hooks/validators/useUserActiveValidators.d.ts +5 -0
  190. package/dist/hooks/validators/useUserActiveValidators.d.ts.map +1 -1
  191. package/dist/hooks/validators/useValidator.d.ts +0 -1
  192. package/dist/hooks/validators/useValidator.d.ts.map +1 -1
  193. package/dist/hooks/validators/useValidatorIncentiveDistribution.d.ts +4 -5
  194. package/dist/hooks/validators/useValidatorIncentiveDistribution.d.ts.map +1 -1
  195. package/dist/hooks/validators/useValidatorRewardAllocation.d.ts +1 -0
  196. package/dist/hooks/validators/useValidatorRewardAllocation.d.ts.map +1 -1
  197. package/dist/types/beep/exports.d.ts +2 -0
  198. package/dist/types/beep/exports.d.ts.map +1 -0
  199. package/dist/types/beep/exports.mjs +1 -0
  200. package/dist/types/beep/exports.mjs.map +1 -0
  201. package/dist/types/bribeBoost.d.ts +0 -49
  202. package/dist/types/dex.d.ts +17 -0
  203. package/dist/types/enso.d.ts +1 -27
  204. package/dist/types/global.d.ts +7 -0
  205. package/dist/types/pol.d.ts +3 -48
  206. package/dist/utils/crossChainBridge.d.ts +74 -0
  207. package/dist/utils/crossChainBridge.d.ts.map +1 -0
  208. package/dist/utils/crossChainBridge.unit.test.d.ts +2 -0
  209. package/dist/utils/crossChainBridge.unit.test.d.ts.map +1 -0
  210. package/dist/utils/exports.d.ts +1 -1
  211. package/dist/utils/exports.d.ts.map +1 -1
  212. package/dist/utils/exports.mjs +142 -72
  213. package/dist/utils/exports.mjs.map +1 -1
  214. package/dist/utils/getTestClient.d.ts +5 -3
  215. package/dist/utils/getTestClient.d.ts.map +1 -1
  216. package/dist/utils/parseWhiskToken.d.ts.map +1 -1
  217. package/package.json +14 -10
  218. package/src/actions/clients/BeraApolloClient.ts +4 -2
  219. package/src/actions/clients/clientName.ts +17 -0
  220. package/src/actions/clients/clientName.unit.test.ts +39 -0
  221. package/src/actions/clients/exports.ts +2 -0
  222. package/src/actions/clients/fetchBeep.ts +6 -4
  223. package/src/actions/clients/fetchEnso.ts +47 -0
  224. package/src/actions/clients/fetchLayerzero.ts +33 -0
  225. package/src/actions/clients/fetchOpenApi.ts +9 -2
  226. package/src/actions/clients/fetchOpenApi.unit.test.ts +27 -12
  227. package/src/actions/clients/getApolloClient.ts +3 -11
  228. package/src/actions/dex/__tests__/aggregators.unit.test.ts +231 -2
  229. package/src/actions/dex/aggregators/base.ts +75 -17
  230. package/src/actions/dex/aggregators/bex.ts +41 -1
  231. package/src/actions/dex/aggregators/bgt.ts +11 -6
  232. package/src/actions/dex/aggregators/enso/enso.ts +1 -0
  233. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +27 -9
  234. package/src/actions/dex/aggregators/erc4626.ts +19 -5
  235. package/src/actions/dex/aggregators/fly.ts +1 -0
  236. package/src/actions/dex/aggregators/haiku.ts +33 -2
  237. package/src/actions/dex/aggregators/honey.ts +17 -6
  238. package/src/actions/dex/aggregators/kyberswap.ts +1 -0
  239. package/src/actions/dex/aggregators/oogabooga.ts +1 -0
  240. package/src/actions/dex/aggregators/openOcean.ts +1 -0
  241. package/src/actions/dex/aggregators/wbera.ts +17 -11
  242. package/src/actions/enso/getBendMultiplyBundle.ts +1 -1
  243. package/src/actions/enso/getEnsoUserTokensWithBalances.ts +4 -8
  244. package/src/actions/enso/util.ts +0 -59
  245. package/src/actions/exports.ts +3 -5
  246. package/src/actions/honey/getChartData.ts +2 -3
  247. package/src/actions/honey/getHoney24hVolume.ts +4 -13
  248. package/src/actions/honey/getHoneyCollaterals.ts +1 -1
  249. package/src/actions/honey/getHoneyTxns.ts +2 -3
  250. package/src/actions/pol/getBGTGlobalInfo.ts +0 -2
  251. package/src/actions/pol/getBeraTokenTotalSupply.ts +3 -33
  252. package/src/actions/pol/getEarnedStakedBeraVault.ts +1 -1
  253. package/src/actions/pol/getLSTStakeConfig.ts +0 -6
  254. package/src/actions/pol/getRewardVaults.ts +0 -1
  255. package/src/actions/pol/getSWBeraVaultMetadata.ts +2 -106
  256. package/src/actions/pol/getStakedBeraAPY.ts +44 -0
  257. package/src/actions/pol/getStakedBeraSnapshots.ts +17 -34
  258. package/src/actions/pol/getStakingDailyAssets.ts +1 -1
  259. package/src/actions/server/getDailyValidatorBlockStats.ts +1 -2
  260. package/src/actions/validators/getActiveBoostAndCommissionChangeDelay.ts +1 -1
  261. package/src/actions/validators/getUserActiveValidators.ts +116 -54
  262. package/src/actions/validators/getValidatorIncentiveDistribution.ts +1 -2
  263. package/src/actions/validators/getValidatorRewardAllocation.ts +12 -1
  264. package/src/contexts/BeraFlags/BeraFlags.tsx +1 -4
  265. package/src/contexts/BeraFlags/defaultFlags.ts +1 -3
  266. package/src/contexts/BexStatusProvider.tsx +1 -1
  267. package/src/contexts/TokensProvider.tsx +1 -4
  268. package/src/enum/contracts.ts +3 -0
  269. package/src/enum/txnEnum.ts +1 -1
  270. package/src/errors/BeraError.unit.test.ts +23 -0
  271. package/src/errors/RequestError.ts +46 -9
  272. package/src/errors/RequestError.unit.test.ts +54 -0
  273. package/src/errors/errorMap.ts +8 -3
  274. package/src/errors/getErrorMessage.unit.test.ts +32 -0
  275. package/src/generated/beep.ts +1605 -0
  276. package/src/generated/enso.ts +4965 -0
  277. package/src/generated/layerzero.ts +2065 -0
  278. package/src/hooks/dex/useAggregatorsQuotes.ts +7 -1
  279. package/src/hooks/dex/useCrossChainNativeFee.ts +83 -0
  280. package/src/hooks/dex/useCrossChainNativeFee.unit.test.ts +63 -0
  281. package/src/hooks/dex/useOnChainPoolData.ts +30 -13
  282. package/src/hooks/dex/useSingleAggregatorQuote.ts +10 -5
  283. package/src/hooks/dex/useSingleAggregatorQuote.unit.test.ts +86 -0
  284. package/src/hooks/enso/useBendZapSupply.ts +10 -38
  285. package/src/hooks/enso/useBendZapSupply.unit.test.ts +98 -0
  286. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -3
  287. package/src/hooks/enso/useEnsoUserTokensWithBalances.unit.test.ts +69 -0
  288. package/src/hooks/enso/useZapStakeBera.ts +8 -1
  289. package/src/hooks/enso/useZapStakeBera.unit.test.ts +97 -0
  290. package/src/hooks/exports.ts +2 -5
  291. package/src/hooks/pol/useAutoclaimedIncentives.ts +6 -3
  292. package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +5 -2
  293. package/src/hooks/pol/useRewardTokenToBeraRate.ts +5 -4
  294. package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +0 -1
  295. package/src/hooks/pol/{useStakedAPR.ts → useStakedAPY.ts} +11 -9
  296. package/src/hooks/pol/useStakedData.ts +15 -14
  297. package/src/hooks/pol/useStakedSnapshots.ts +1 -1
  298. package/src/hooks/pol/useStakingVaultsMetadata.ts +3 -8
  299. package/src/hooks/tokens/useMultipleTokenInformation.ts +64 -21
  300. package/src/hooks/tokens/useMultipleTokenInformation.unit.test.ts +91 -0
  301. package/src/hooks/tokens/usePollBalance.ts +4 -2
  302. package/src/hooks/validators/useUserActiveValidators.ts +54 -9
  303. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +4 -5
  304. package/src/types/beep/exports.ts +4 -0
  305. package/src/types/bribeBoost.d.ts +0 -49
  306. package/src/types/dex.d.ts +17 -0
  307. package/src/types/enso.d.ts +1 -27
  308. package/src/types/global.d.ts +7 -0
  309. package/src/types/pol.d.ts +3 -48
  310. package/src/utils/crossChainBridge.ts +290 -0
  311. package/src/utils/crossChainBridge.unit.test.ts +177 -0
  312. package/src/utils/exports.ts +1 -1
  313. package/dist/BeraError-7-A5JYy_.d.ts +0 -123
  314. package/dist/BexStatusProvider-DRymVlQf.d.ts +0 -70
  315. package/dist/HoneyConfigProvider-COOuDNra.d.ts +0 -390
  316. package/dist/RequestError-DkUbo3ro.d.ts +0 -145
  317. package/dist/actions/dex/b-sdk.d.ts +0 -3
  318. package/dist/actions/enso/getEnsoSwapBundle.d.ts +0 -3
  319. package/dist/actions/enso/getEnsoSwapBundle.d.ts.map +0 -1
  320. package/dist/actions/pol/getBgtIncentiveDistributorPaused.d.ts +0 -10
  321. package/dist/actions/pol/getBgtIncentiveDistributorPaused.d.ts.map +0 -1
  322. package/dist/actions/pol/getRewardProofsByValidator.d.ts +0 -9
  323. package/dist/actions/pol/getRewardProofsByValidator.d.ts.map +0 -1
  324. package/dist/actions/pol/getStakedBeraAPR.d.ts +0 -12
  325. package/dist/actions/pol/getStakedBeraAPR.d.ts.map +0 -1
  326. package/dist/actions/pol/getUserClaimableIncentives.d.ts +0 -9
  327. package/dist/actions/pol/getUserClaimableIncentives.d.ts.map +0 -1
  328. package/dist/actions/validators/getValidatorAnalytics.d.ts +0 -12
  329. package/dist/actions/validators/getValidatorAnalytics.d.ts.map +0 -1
  330. package/dist/chunk-7TFV6UKF.mjs.map +0 -1
  331. package/dist/chunk-BSOWLS3W.mjs +0 -40
  332. package/dist/chunk-BSOWLS3W.mjs.map +0 -1
  333. package/dist/chunk-DOZJB6IJ.mjs.map +0 -1
  334. package/dist/chunk-IFNIPVTZ.mjs.map +0 -1
  335. package/dist/chunk-NZAH3SGT.mjs.map +0 -1
  336. package/dist/chunk-P3YZ7F22.mjs.map +0 -1
  337. package/dist/chunk-PHYZRH4I.mjs.map +0 -1
  338. package/dist/chunk-UA3Z47LT.mjs.map +0 -1
  339. package/dist/chunk-ZWTGVIPJ.mjs.map +0 -1
  340. package/dist/contexts/block-time-provider.d.ts +0 -10
  341. package/dist/defaultFlags-D6KfkTZx.d.ts +0 -10
  342. package/dist/dex-C_BB0b0O.d.ts +0 -37
  343. package/dist/getApolloClient-MWm_iq4u.d.ts +0 -39
  344. package/dist/getProposalVotes-DAUrdX2n.d.ts +0 -12
  345. package/dist/getValidatorQueuedOperatorAddress-N2I7wHd6.d.ts +0 -511
  346. package/dist/global.d-CR3zicga.d.ts +0 -231
  347. package/dist/global.d-CiZJ2eHz.d.ts +0 -231
  348. package/dist/honey-CYm0RWf4.d.ts +0 -14
  349. package/dist/hooks/enso/useEnsoSwapBundle.d.ts +0 -26
  350. package/dist/hooks/enso/useEnsoSwapBundle.d.ts.map +0 -1
  351. package/dist/hooks/pol/useBgtIncentiveDistributorPaused.d.ts +0 -8
  352. package/dist/hooks/pol/useBgtIncentiveDistributorPaused.d.ts.map +0 -1
  353. package/dist/hooks/pol/useStakedAPR.d.ts +0 -11
  354. package/dist/hooks/pol/useStakedAPR.d.ts.map +0 -1
  355. package/dist/hooks/validators/useUserClaimableIncentives.d.ts +0 -8
  356. package/dist/hooks/validators/useUserClaimableIncentives.d.ts.map +0 -1
  357. package/dist/hooks/validators/useValidatorAnalytics.d.ts +0 -11
  358. package/dist/hooks/validators/useValidatorAnalytics.d.ts.map +0 -1
  359. package/dist/pol.d-CeRgXBL8.d.ts +0 -167
  360. package/dist/txnEnum-ByI5dtDi.d.ts +0 -106
  361. package/dist/types/bribe-boost.d.ts +0 -69
  362. package/dist/useHoneySwapState-CXVWAThr.d.ts +0 -32
  363. package/dist/useHoneySwapState-twi7NTaO.d.ts +0 -32
  364. package/dist/utils/formatIncentivesTokenMap.d.ts +0 -3
  365. package/dist/utils/formatIncentivesTokenMap.d.ts.map +0 -1
  366. package/dist/utils/layerZeroScan.d.ts +0 -39
  367. package/dist/utils/layerZeroScan.d.ts.map +0 -1
  368. package/src/actions/enso/getEnsoSwapBundle.ts +0 -72
  369. package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +0 -28
  370. package/src/actions/pol/getRewardProofsByValidator.ts +0 -49
  371. package/src/actions/pol/getStakedBeraAPR.ts +0 -56
  372. package/src/actions/pol/getUserClaimableIncentives.ts +0 -40
  373. package/src/actions/validators/getValidatorAnalytics.ts +0 -37
  374. package/src/hooks/enso/useEnsoSwapBundle.ts +0 -121
  375. package/src/hooks/pol/useBgtIncentiveDistributorPaused.ts +0 -34
  376. package/src/hooks/validators/useUserClaimableIncentives.ts +0 -148
  377. package/src/hooks/validators/useValidatorAnalytics.ts +0 -37
  378. package/src/utils/formatIncentivesTokenMap.ts +0 -19
  379. package/src/utils/layerZeroScan.ts +0 -124
  380. /package/dist/{chunk-AEN6IJFU.mjs.map → chunk-7KN7TDUC.mjs.map} +0 -0
  381. /package/dist/{chunk-LE4CYW7S.mjs.map → chunk-FWRYUIJK.mjs.map} +0 -0
  382. /package/dist/{chunk-PJRLHTGC.mjs.map → chunk-HPRLNT6R.mjs.map} +0 -0
  383. /package/dist/{chunk-EJIGERYM.mjs.map → chunk-M3MIGSH3.mjs.map} +0 -0
  384. /package/dist/{chunk-TGN55GKE.mjs.map → chunk-SC3BSCTN.mjs.map} +0 -0
  385. /package/dist/{chunk-QQASX4LJ.mjs.map → chunk-TXWDUJOY.mjs.map} +0 -0
  386. /package/dist/{chunk-EGAB6NFQ.mjs.map → chunk-UWJQ6UKG.mjs.map} +0 -0
  387. /package/dist/{chunk-J3LTASDE.mjs.map → chunk-ZHV3MQ4F.mjs.map} +0 -0
@@ -1,8 +1,12 @@
1
+ import { useMemo } from "react";
2
+
1
3
  import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
2
4
  import { useSWR } from "@berachain/utils/pkg/swr";
3
5
 
4
6
  import {
5
- getUserActiveValidators,
7
+ getUserActiveValidatorsApi,
8
+ getUserActiveValidatorsOnChain,
9
+ mergeUserActiveValidators,
6
10
  type ValidatorWithUserBoost,
7
11
  } from "../../actions/validators/getUserActiveValidators";
8
12
  import { POLLING } from "../../enum/polling";
@@ -12,23 +16,42 @@ import type {
12
16
  } from "../../types/global";
13
17
 
14
18
  interface UseUserActiveValidatorsResponse
15
- extends DefaultHookReturnType<ValidatorWithUserBoost[] | undefined> {}
19
+ extends DefaultHookReturnType<ValidatorWithUserBoost[] | undefined> {
20
+ /**
21
+ * Re-reads the on-chain boost amounts without re-fetching the API validator
22
+ * list. Use after a boost/drop tx to reflect new amounts immediately.
23
+ */
24
+ refreshOnChain: () => void;
25
+ }
16
26
 
17
27
  export function useUserActiveValidators(
18
28
  options?: DefaultHookOptions,
19
29
  ): UseUserActiveValidatorsResponse {
20
30
  const { address: account } = useBeraWallet();
21
31
  const publicClient = usePublicClient();
22
- const QUERY_KEY =
23
- publicClient && account
24
- ? (["useUserActiveValidators", account] as const)
25
- : null;
26
32
 
27
- return useSWR(
28
- QUERY_KEY,
33
+ const apiSwr = useSWR(
34
+ account ? (["useUserActiveValidatorsApi", account] as const) : null,
29
35
  async ([, account]) => {
30
- return await getUserActiveValidators({
36
+ return await getUserActiveValidatorsApi({ account });
37
+ },
38
+ {
39
+ ...options,
40
+ refreshInterval: options?.refreshInterval ?? POLLING.SLOW,
41
+ keepPreviousData: true,
42
+ },
43
+ );
44
+
45
+ const validators = apiSwr.data;
46
+
47
+ const onChainSwr = useSWR(
48
+ publicClient && account && validators
49
+ ? (["useUserActiveValidatorsOnChain", account, validators] as const)
50
+ : null,
51
+ async ([, account, validators]) => {
52
+ return await getUserActiveValidatorsOnChain({
31
53
  account,
54
+ validators,
32
55
  publicClient,
33
56
  });
34
57
  },
@@ -38,4 +61,26 @@ export function useUserActiveValidators(
38
61
  keepPreviousData: true,
39
62
  },
40
63
  );
64
+
65
+ const onChainBoosts = onChainSwr.data;
66
+
67
+ const data = useMemo(() => {
68
+ if (!validators || !onChainBoosts) return undefined;
69
+ return mergeUserActiveValidators({ validators, onChainBoosts });
70
+ }, [validators, onChainBoosts]);
71
+
72
+ return {
73
+ ...apiSwr,
74
+ data,
75
+ isLoading: apiSwr.isLoading || onChainSwr.isLoading,
76
+ isValidating: apiSwr.isValidating || onChainSwr.isValidating,
77
+ error: apiSwr.error ?? onChainSwr.error,
78
+ refresh: () => {
79
+ apiSwr.refresh();
80
+ onChainSwr.refresh();
81
+ },
82
+ refreshOnChain: () => {
83
+ onChainSwr.refresh();
84
+ },
85
+ };
41
86
  }
@@ -1,17 +1,16 @@
1
1
  import type { Address } from "viem";
2
2
 
3
- import type { ValidatorIncentivesResponse } from "@berachain/graphql/beep";
4
3
  import { useSWR } from "@berachain/utils/pkg/swr";
5
4
 
6
5
  import { getValidatorIncentiveDistribution } from "../../actions/validators/getValidatorIncentiveDistribution";
7
6
  import { POLLING } from "../../enum/polling";
7
+ import type { ValidatorIncentivesResponse } from "../../generated/beep";
8
8
  import type { DefaultHookReturnType } from "../../types/global";
9
9
 
10
10
  /**
11
- * Historical per-validator incentive distribution. Split from
12
- * `useValidatorAnalytics` so the IncentivesEarned chart can switch data
13
- * sources independently of the other charts that still consume the umbrella
14
- * `GetValidatorAnalytics` query.
11
+ * Historical per-validator incentive distribution, powering the
12
+ * IncentivesEarned chart. Owns its own data source so it can be swapped
13
+ * independently.
15
14
  */
16
15
  export function useValidatorIncentiveDistribution({
17
16
  pubkey,
@@ -0,0 +1,4 @@
1
+ // Type-only OpenAPI beep types, re-exported for hub/honey via
2
+ // `@berachain/berajs/types/beep`. The source is generated at prebuild
3
+ // (`codegen:api`, skipped on Vercel) into src/generated/beep.ts.
4
+ export type * from "../../generated/beep";
@@ -1,37 +1,5 @@
1
1
  import type { Address } from "viem";
2
2
 
3
- export interface BribeBoostReward {
4
- token: string;
5
- total_unclaimed: string;
6
- }
7
-
8
- export interface BribeBoostRewardItem {
9
- rewards: BribeBoostReward[];
10
- validator: string;
11
- }
12
-
13
- export interface BribeBoostRewardProof {
14
- validator?: string;
15
- pagination: {
16
- next: number;
17
- previous: number;
18
- record_per_page: number;
19
- current_page: number;
20
- total_page: number;
21
- };
22
- rewards:
23
- | {
24
- id: string;
25
- dist_id: string;
26
- token: Address;
27
- recipient: string;
28
- amount: string;
29
- merkle_proof: string[];
30
- available_at: number;
31
- }[]
32
- | null;
33
- }
34
-
35
3
  // Response shape of GET /api/v1/wallets/:wallet/autoclaimed:
36
4
  // { [wallet]: { [validatorPubkey]: { [tokenAddress]: { amount } } } }
37
5
  // `amount` is a stringified bigint in token base units. The backend now
@@ -50,20 +18,3 @@ export type AutoclaimedIncentivesTxHashResponse = Record<
50
18
  Address,
51
19
  Record<Address, Record<Address, { txhash: string }>>
52
20
  >;
53
-
54
- export interface BribeBoostValidatorApr {
55
- id: string;
56
- boost_total_bgt: string;
57
- rewards_total_usd: string;
58
- daily_rate: string;
59
- apr: string;
60
- apy: string;
61
- tokens: Address[]; // Confirm this type with backend real data
62
- validator: string;
63
- start_block: number;
64
- end_block: number;
65
- start_timestamp: number;
66
- end_timestamp: number;
67
- created_at: string;
68
- updated_at: string;
69
- }
@@ -195,6 +195,13 @@ export type Calldata = {
195
195
  data?: Hex;
196
196
  value: bigint;
197
197
  gasLimit?: bigint;
198
+ /**
199
+ * Extra Sentry tags to attach when this calldata is submitted via `useTxn`.
200
+ * Aggregators set `{ aggregator: this.name }` so failures like
201
+ * AggregatorNotWhitelisted can be attributed to a source without decoding
202
+ * calldata.
203
+ */
204
+ extraTags?: Record<string, string>;
198
205
  };
199
206
 
200
207
  export type IRawAggregatorQuote = {
@@ -208,6 +215,16 @@ export type IRawAggregatorQuote = {
208
215
  isNativeSwap?: boolean;
209
216
  priceImpactPercentage?: number | null;
210
217
  swapFeeBps: number;
218
+ /** True when the route bridges chains; set by the aggregator (source of truth). */
219
+ isCrossChain?: boolean;
220
+ /** Chain the input token (and therefore the tx) lives on. */
221
+ srcChainId?: number;
222
+ /**
223
+ * Bridge the cross-chain route uses, from Enso's chosen bridge hop
224
+ * (`relay` | `stargate` | `ccip`). Drives which explorer/status API the
225
+ * tracker uses; undefined for same-chain routes.
226
+ */
227
+ bridgeProtocol?: string;
211
228
  getCalldata?: ({ account }: { account: Address }) => Calldata;
212
229
  };
213
230
 
@@ -1,26 +1,9 @@
1
- import type { BundleData, EnsoClient } from "@ensofinance/sdk";
1
+ import type { BundleData } from "@ensofinance/sdk";
2
2
  import type { Address, Hex, PublicClient, TransactionRequest } from "viem";
3
3
 
4
4
  import type { MinimalERC20 } from "./dex";
5
5
 
6
6
  export type Quantity = string | number;
7
- export type ActionOutputReference<T> = T | StrictOutputReference<T>;
8
- type StrictOutputReference<T> = {
9
- useOutputOfCallAt: number;
10
- index?: number;
11
- };
12
-
13
- export interface GetEnsoSwapBundleArgs {
14
- fromAddress: Address;
15
- amountIn: Quantity;
16
- tokenIn: Address;
17
- tokenOut: Address;
18
- chainId: number;
19
- ensoClient: EnsoClient;
20
- slippage: number;
21
- destinationChainId?: number;
22
- publicClient: PublicClient;
23
- }
24
7
 
25
8
  export type GetZapTransaction = TransactionRequest & {
26
9
  to: Address;
@@ -29,15 +12,6 @@ export type GetZapTransaction = TransactionRequest & {
29
12
  gasLimit?: bigint;
30
13
  };
31
14
  export type GetZapTransactions = GetZapTransaction[];
32
- export interface GetZapTransactionsArgs {
33
- fromAddress: Address;
34
- amountIn: Quantity;
35
- tokenIn: Address;
36
- chainId: number;
37
- ensoClient: EnsoClient;
38
- bundle: BundleData;
39
- publicClient: PublicClient;
40
- }
41
15
 
42
16
  export interface GetEnsoWalletTransactionsWithApprovalArgs {
43
17
  fromAddress: Address;
@@ -94,6 +94,13 @@ export type IContractWrite<
94
94
  */
95
95
  actionType: TransactionActionType;
96
96
  txnName?: string;
97
+ /**
98
+ * Extra Sentry tags to attach to this transaction's scope, merged under the
99
+ * `operation.txn.*` namespace (e.g. `{ aggregator: "oogabooga" }` becomes the
100
+ * `operation.txn.aggregator` tag). Use for context that helps triage failures
101
+ * without decoding calldata.
102
+ */
103
+ extraTags?: Record<string, string>;
97
104
  gasLimit?: bigint;
98
105
  account?: Account | Address;
99
106
  /**
@@ -1,49 +1,4 @@
1
- import type { Address } from "viem";
2
-
3
- import type { ApiValidatorFragment } from "@berachain/graphql/pol/api";
4
-
5
- import type { Token, TokenWithMetadata } from "./dex";
6
-
7
- export type IncentiveReward = {
8
- tokenMetadata: Token | undefined;
9
- tokenPrice: number;
10
- tokenValue: number;
11
- id: string;
12
- dist_id: string;
13
- token: string;
14
- recipient: string;
15
- formattedAmount: string;
16
- amount: string;
17
- merkle_proof: string[];
18
- available_at: number;
19
- };
20
- export interface IncentiveRewardChunksWithValidatorData {
21
- validator: ApiValidatorInListFragment | ApiValidatorFragment | undefined;
22
- maxTimestamp: number | undefined;
23
- minTimestamp: number | undefined;
24
- totalValue: number;
25
- tokenTotals: {
26
- chainId: number;
27
- address: Address;
28
- amount: number;
29
- value: number;
30
- metadata: Token | undefined;
31
- }[];
32
- rewards: IncentiveReward[];
33
- isCurrent: boolean;
34
- }
35
-
36
- export interface AggregatedTokenTotals {
37
- address: Address;
38
- amount: number;
39
- value: number;
40
- metadata: Token | undefined;
41
- chainId: number;
42
- }
43
-
44
- export type ClaimedIncentives = Record<string, string>;
45
-
46
- export type ClaimedIncentivesLocalState = Record<string, ClaimedIncentives>;
1
+ import type { TokenWithMetadata } from "./dex";
47
2
 
48
3
  export interface UserVaultInfo {
49
4
  balance: bigint;
@@ -56,11 +11,11 @@ export interface UserVaultInfo {
56
11
  export type StakedBeraAsset = {
57
12
  token: TokenWithMetadata;
58
13
  /**
59
- * Staking APR, or `undefined` when unavailable (e.g. the APR backend is
14
+ * Staking APY, or `undefined` when unavailable (e.g. the APY backend is
60
15
  * down). `undefined` lets the UI render a "—" placeholder instead of a
61
16
  * misleading "0%".
62
17
  */
63
- apr: number | undefined;
18
+ apy: number | undefined;
64
19
  stakedAmount: number;
65
20
  /**
66
21
  * USD value of the staked amount, or `undefined` when the token price is
@@ -0,0 +1,290 @@
1
+ import { fetchLayerzero } from "../actions/clients/fetchLayerzero";
2
+ import { BeraError } from "../errors/BeraError";
3
+ import { InvalidArgumentError } from "../errors/InvalidArgumentError";
4
+ import { RequestError } from "../errors/RequestError";
5
+ import { beraFetchJson } from "./beraFetch";
6
+
7
+ // Enso routes cross-chain zaps over one of these bridges (from the "bridge"
8
+ // hop's `protocol` in its route response). Each has its own status API +
9
+ // explorer, so tracking has to branch on the bridge.
10
+ export type BridgeProtocol = "relay" | "stargate" | "ccip" | "layerzero";
11
+
12
+ const RELAY_API_URL = "https://api.relay.link";
13
+
14
+ // Public explorer origins for deep-linking a bridged tx. See getBridgeExplorerUrl.
15
+ const LAYERZERO_SCAN_EXPLORER = "https://layerzeroscan.com";
16
+ const RELAY_EXPLORER = "https://relay.link";
17
+
18
+ export enum BridgeMessageStatus {
19
+ INFLIGHT = "INFLIGHT",
20
+ DELIVERED = "DELIVERED",
21
+ FAILED = "FAILED",
22
+ }
23
+
24
+ export type BridgeMessage = {
25
+ srcTxHash?: string;
26
+ dstTxHash?: string;
27
+ status: BridgeMessageStatus;
28
+ statusMessage?: string;
29
+ /**
30
+ * Bridge-specific id for deep-linking the explorer, when the explorer keys
31
+ * on something other than the source tx hash (Relay uses its requestId).
32
+ */
33
+ explorerId?: string;
34
+ };
35
+
36
+ export type BridgeDeliveredMessage = BridgeMessage & {
37
+ dstTxHash: string;
38
+ };
39
+
40
+ // --- LayerZero / Stargate ---------------------------------------------------
41
+
42
+ async function getLayerZeroMessage(srcTxHash: string): Promise<BridgeMessage> {
43
+ const { data } = await fetchLayerzero("/messages/tx/{tx}", {
44
+ path: { tx: srcTxHash },
45
+ });
46
+
47
+ const message = data[0];
48
+ if (!message) {
49
+ // not indexed yet — keep polling
50
+ return { srcTxHash, status: BridgeMessageStatus.INFLIGHT };
51
+ }
52
+
53
+ return {
54
+ srcTxHash: message.source?.tx?.txHash,
55
+ // the destination union has several shapes; only the plain-delivery one
56
+ // carries `tx.txHash`, so narrow before reading it.
57
+ dstTxHash:
58
+ message.destination && "tx" in message.destination
59
+ ? message.destination.tx?.txHash
60
+ : undefined,
61
+ statusMessage: message.status?.message,
62
+ // v1 exposes many transient states; anything not DELIVERED/FAILED means
63
+ // "keep polling", so collapse unknown names to INFLIGHT.
64
+ status:
65
+ message.status?.name === "DELIVERED"
66
+ ? BridgeMessageStatus.DELIVERED
67
+ : message.status?.name === "FAILED"
68
+ ? BridgeMessageStatus.FAILED
69
+ : BridgeMessageStatus.INFLIGHT,
70
+ };
71
+ }
72
+
73
+ // --- Relay ------------------------------------------------------------------
74
+
75
+ // Relay has no OpenAPI schema/client yet (unlike LayerZero's fetchLayerzero),
76
+ // so this stays hand-rolled over beraFetchJson with a local response type.
77
+ // Raw shape of the Relay requests API (only the fields we consume).
78
+ type RelayRequestsResponse = {
79
+ requests: {
80
+ id: string;
81
+ status: string;
82
+ data?: {
83
+ failReason?: string;
84
+ outTxs?: { hash?: string }[];
85
+ };
86
+ }[];
87
+ };
88
+
89
+ async function getRelayMessage(srcTxHash: string): Promise<BridgeMessage> {
90
+ const { requests } = await beraFetchJson<RelayRequestsResponse>({
91
+ url: `${RELAY_API_URL}/requests/v2?hash=${srcTxHash}`,
92
+ type: "rest",
93
+ name: "Relay",
94
+ });
95
+
96
+ const request = requests[0];
97
+ if (!request) {
98
+ // not indexed yet — keep polling
99
+ return { srcTxHash, status: BridgeMessageStatus.INFLIGHT };
100
+ }
101
+
102
+ return {
103
+ srcTxHash,
104
+ dstTxHash: request.data?.outTxs?.[0]?.hash,
105
+ statusMessage: request.data?.failReason,
106
+ // Relay's explorer keys on the requestId, not the source tx hash.
107
+ explorerId: request.id,
108
+ status:
109
+ request.status === "success"
110
+ ? BridgeMessageStatus.DELIVERED
111
+ : request.status === "failure" || request.status === "refund"
112
+ ? BridgeMessageStatus.FAILED
113
+ : BridgeMessageStatus.INFLIGHT,
114
+ };
115
+ }
116
+
117
+ // --- Unified poller ---------------------------------------------------------
118
+
119
+ function sleep(ms: number) {
120
+ return new Promise((resolve) => setTimeout(resolve, ms));
121
+ }
122
+
123
+ function getBridgeMessage(
124
+ bridgeProtocol: string,
125
+ srcTxHash: string,
126
+ ): Promise<BridgeMessage> {
127
+ switch (bridgeProtocol) {
128
+ case "relay":
129
+ return getRelayMessage(srcTxHash);
130
+ // Enso's "stargate" is LayerZero's Stargate; both track on LayerZero Scan.
131
+ case "stargate":
132
+ case "layerzero":
133
+ return getLayerZeroMessage(srcTxHash);
134
+ default:
135
+ // ccip and anything else aren't tracked (ccip is excluded at routing time
136
+ // via `ignoreBridges` in ensoErc4626) — reject so the caller can decide
137
+ // (the tracker treats this as "can't poll", not "failed").
138
+ throw new InvalidArgumentError({
139
+ property: "bridgeProtocol",
140
+ value: bridgeProtocol,
141
+ expected: "relay | stargate | layerzero",
142
+ });
143
+ }
144
+ }
145
+
146
+ export interface BridgeExplorerUrlArgs {
147
+ /** Bridge Enso routed through; picks which explorer to link. */
148
+ bridgeProtocol?: string;
149
+ /** Source-chain tx hash — how LayerZero/Stargate + the fallback key. */
150
+ srcTxHash?: string;
151
+ /**
152
+ * Relay's requestId, when known. Relay's explorer prefers it but also resolves
153
+ * on the src tx hash, so a missing id still links to the bridge explorer.
154
+ */
155
+ explorerId?: string;
156
+ /**
157
+ * Source-chain block explorer origin (e.g. https://etherscan.io). Only a
158
+ * last resort for an unknown/untracked bridge; tracked bridges always link to
159
+ * their own bridge explorer (which shows the src→dst delivery still in flight).
160
+ */
161
+ fallbackExplorerUrl: string;
162
+ }
163
+
164
+ /**
165
+ * Deep-link a bridged tx to the right *bridge* explorer — the one showing the
166
+ * source→destination delivery, which is what's still in flight once a tracker is
167
+ * visible (the source tx already confirmed). Enso picks the bridge per-route, so
168
+ * a single hardcoded explorer is wrong for the others; each keys differently
169
+ * (LayerZero/Stargate on the src tx hash, Relay on its requestId or the src tx
170
+ * hash). Only a genuinely unknown protocol falls back to the source chain's own
171
+ * block explorer.
172
+ *
173
+ * We deliberately don't route this through Enso's `getBridgeStatus`
174
+ * (`/{protocol}/bridge/check`): it normalizes status but doesn't return Relay's
175
+ * requestId, which the Relay deep link prefers — so we'd still branch per bridge.
176
+ */
177
+ export function getBridgeExplorerUrl({
178
+ bridgeProtocol,
179
+ srcTxHash,
180
+ explorerId,
181
+ fallbackExplorerUrl,
182
+ }: BridgeExplorerUrlArgs): string | undefined {
183
+ switch (bridgeProtocol) {
184
+ case "relay":
185
+ // Relay's explorer resolves on either the requestId or the src tx hash,
186
+ // so stay on the bridge explorer even before we've fetched the id.
187
+ return srcTxHash || explorerId
188
+ ? `${RELAY_EXPLORER}/transaction/${explorerId ?? srcTxHash}`
189
+ : undefined;
190
+ case "stargate":
191
+ case "layerzero":
192
+ return srcTxHash
193
+ ? `${LAYERZERO_SCAN_EXPLORER}/tx/${srcTxHash}`
194
+ : undefined;
195
+ default:
196
+ // Unknown/untracked bridge (shouldn't surface — ccip is routed out and the
197
+ // tracker needs a known protocol to poll): no bridge explorer exists, so
198
+ // the source chain's block explorer is the only link we can build.
199
+ return srcTxHash ? `${fallbackExplorerUrl}/tx/${srcTxHash}` : undefined;
200
+ }
201
+ }
202
+
203
+ /**
204
+ * One-shot status lookup for a bridged tx. Used to grab the explorer id (e.g.
205
+ * Relay's requestId) for the pending-state link before delivery. Swallows
206
+ * errors into an INFLIGHT result so a not-yet-indexed tx doesn't throw.
207
+ */
208
+ export async function getBridgeMessageOnce(
209
+ bridgeProtocol: string,
210
+ srcTxHash: string,
211
+ ): Promise<BridgeMessage> {
212
+ try {
213
+ return await getBridgeMessage(bridgeProtocol, srcTxHash);
214
+ } catch {
215
+ return { srcTxHash, status: BridgeMessageStatus.INFLIGHT };
216
+ }
217
+ }
218
+
219
+ export type WaitForMessageReceivedOptions = {
220
+ /** Which bridge Enso routed through; narrowed at getBridgeMessage's switch. */
221
+ bridgeProtocol: string;
222
+ /** Polling interval in ms (default: 3000). */
223
+ pollInterval?: number;
224
+ /** Timeout in ms (default: 600000 / 10 minutes). */
225
+ timeout?: number;
226
+ };
227
+
228
+ /**
229
+ * Polls the bridge's status API until the cross-chain message is delivered or
230
+ * fails, then resolves with the delivered message (incl. destination tx hash).
231
+ * HTTP errors are silently retried until timeout. Throws InvalidArgumentError
232
+ * if srcTxHash/bridgeProtocol is missing or unsupported, or BeraError if the
233
+ * message fails or times out.
234
+ */
235
+ export async function waitForBridgeMessageReceived(
236
+ srcTxHash: string,
237
+ options: WaitForMessageReceivedOptions,
238
+ ): Promise<BridgeDeliveredMessage> {
239
+ const { bridgeProtocol, pollInterval = 3000, timeout = 600_000 } = options;
240
+
241
+ if (!srcTxHash) {
242
+ throw new InvalidArgumentError({
243
+ property: "srcTxHash",
244
+ value: srcTxHash,
245
+ expected: "string",
246
+ });
247
+ }
248
+
249
+ const startTime = Date.now();
250
+
251
+ while (true) {
252
+ if (Date.now() - startTime > timeout) {
253
+ throw new BeraError({
254
+ message: `Bridge message tracking timed out after ${timeout}ms`,
255
+ reason: "BRIDGE_TIMEOUT",
256
+ level: "warning",
257
+ });
258
+ }
259
+
260
+ try {
261
+ const message = await getBridgeMessage(bridgeProtocol, srcTxHash);
262
+
263
+ if (message.status === BridgeMessageStatus.FAILED) {
264
+ throw new BeraError({
265
+ message: `Bridge message failed: ${message.statusMessage}`,
266
+ reason: "BRIDGE_MESSAGE_FAILED",
267
+ });
268
+ }
269
+
270
+ // Only resolve once we actually have the destination tx hash the type
271
+ // promises. A DELIVERED status without one (e.g. LZ's destination union
272
+ // lacking `tx`) means the dst tx isn't indexed yet — keep polling rather
273
+ // than cast a message with `dstTxHash: undefined`.
274
+ if (
275
+ message.status === BridgeMessageStatus.DELIVERED &&
276
+ message.dstTxHash
277
+ ) {
278
+ return message as BridgeDeliveredMessage;
279
+ }
280
+ } catch (error) {
281
+ // re-throw non-retryable errors (validation, failed message) but allow
282
+ // RequestError to retry (network issues, temporary API errors)
283
+ if (error instanceof BeraError && !(error instanceof RequestError)) {
284
+ throw error;
285
+ }
286
+ }
287
+
288
+ await sleep(pollInterval);
289
+ }
290
+ }