@berachain/berajs 0.2.8-beta.8 → 0.2.9

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 (225) hide show
  1. package/dist/{BeraError-_mQdkanr.d.cts → BeraError-7-A5JYy_.d.ts} +31 -2
  2. package/dist/{HoneyConfigProvider-DVP_9KZn.d.ts → HoneyConfigProvider-Dkj-_a5x.d.ts} +1 -1
  3. package/dist/RequestError-DBOIV65x.d.ts +144 -0
  4. package/dist/abi/exports.mjs +3 -4
  5. package/dist/actions/clients/exports.d.ts +2 -0
  6. package/dist/actions/clients/exports.mjs +12 -0
  7. package/dist/actions/exports.d.ts +108 -187
  8. package/dist/actions/exports.mjs +97 -158
  9. package/dist/actions/governance/exports.d.ts +140 -0
  10. package/dist/actions/governance/exports.mjs +226 -0
  11. package/dist/actions/server/exports.d.ts +13 -0
  12. package/dist/actions/server/exports.mjs +27 -0
  13. package/dist/{chunk-VA3BQ34H.mjs → chunk-3EARVV7K.mjs} +20 -9
  14. package/dist/chunk-4Z4AK6SH.mjs +211 -0
  15. package/dist/chunk-75M6TF7M.mjs +25 -0
  16. package/dist/chunk-AFN4CVD3.mjs +326 -0
  17. package/dist/{chunk-7TFV6UKF.mjs → chunk-BGMRHTBQ.mjs} +0 -1
  18. package/dist/{chunk-3M47ZRXT.mjs → chunk-CDFWPU2R.mjs} +73 -17
  19. package/dist/{chunk-GWSTVITN.mjs → chunk-CDK4YV3D.mjs} +0 -1
  20. package/dist/{chunk-KL6YZ5VR.mjs → chunk-DKMAIU74.mjs} +0 -1
  21. package/dist/chunk-EXIUPSFN.mjs +86 -0
  22. package/dist/{chunk-VA5L5FDG.mjs → chunk-FFB5LFDW.mjs} +2 -3
  23. package/dist/{chunk-ZCEFC2TK.mjs → chunk-HQCOU6GY.mjs} +0 -1
  24. package/dist/{chunk-SGZP4O6R.mjs → chunk-HSSJKHZ4.mjs} +11 -11
  25. package/dist/{chunk-7QKRRIHI.mjs → chunk-J5I45WGQ.mjs} +77 -152
  26. package/dist/chunk-KQUMKB66.mjs +89 -0
  27. package/dist/{chunk-JA4DHMTG.mjs → chunk-NBYLMO2L.mjs} +0 -1
  28. package/dist/{chunk-4GFN4LEP.mjs → chunk-NPBQLVL3.mjs} +4 -21
  29. package/dist/{chunk-I3FTWD6I.mjs → chunk-O2NQFKJK.mjs} +1 -1
  30. package/dist/{chunk-2R73G2PO.mjs → chunk-QJIXTYTZ.mjs} +121 -765
  31. package/dist/{chunk-GLWPRM33.mjs → chunk-SGIJVHZO.mjs} +0 -1
  32. package/dist/chunk-SZ5C44L5.mjs +35 -0
  33. package/dist/{chunk-5NMATIH4.mjs → chunk-WXXOISTU.mjs} +1 -35
  34. package/dist/chunk-XIYN6AL6.mjs +160 -0
  35. package/dist/contexts/exports.d.ts +2 -2
  36. package/dist/contexts/exports.mjs +11 -9
  37. package/dist/enum/exports.d.ts +1 -1
  38. package/dist/enum/exports.mjs +3 -16
  39. package/dist/enum/governance/exports.d.ts +60 -0
  40. package/dist/enum/governance/exports.mjs +14 -0
  41. package/dist/errors/exports.d.ts +5 -90
  42. package/dist/errors/exports.mjs +19 -10
  43. package/dist/exports-BcUTGFUb.d.ts +40 -0
  44. package/dist/{getValidatorQueuedOperatorAddress-BcyxE9uw.d.ts → getValidatorQueuedOperatorAddress-Dw5KN5sh.d.ts} +2 -2
  45. package/dist/{global.d-5w_lvl2J.d.ts → global.d-BuGDKh4k.d.ts} +4 -240
  46. package/dist/hooks/exports.d.ts +80 -236
  47. package/dist/hooks/exports.mjs +609 -1508
  48. package/dist/hooks/governance/exports.d.ts +181 -0
  49. package/dist/hooks/governance/exports.mjs +888 -0
  50. package/dist/pol.d-CqPA9K6m.d.ts +142 -0
  51. package/dist/{txnEnum-7_o92X3N.d.cts → txnEnum-ByI5dtDi.d.ts} +2 -60
  52. package/dist/types/exports.d.ts +9 -9
  53. package/dist/types/exports.mjs +0 -1
  54. package/dist/types/governance/exports.d.ts +109 -0
  55. package/dist/types/governance/exports.mjs +0 -0
  56. package/dist/{useHoneySwapState-B494PQDl.d.ts → useHoneySwapState-vFmuFF0g.d.ts} +1 -1
  57. package/dist/utils/exports.d.ts +24 -7
  58. package/dist/utils/exports.mjs +49 -11
  59. package/package.json +60 -13
  60. package/src/actions/__test/transports.ts +61 -0
  61. package/src/actions/clients/BeraApolloClient.ts +9 -0
  62. package/src/actions/clients/exports.ts +4 -0
  63. package/src/actions/clients/getApolloClient.ts +70 -25
  64. package/src/actions/clients/getEnsoClient.ts +20 -9
  65. package/src/actions/dex/aggregators/base.ts +1 -1
  66. package/src/actions/dex/aggregators/enso/enso.ts +27 -17
  67. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
  68. package/src/actions/dex/aggregators/kyberswap.ts +18 -23
  69. package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
  70. package/src/actions/exports.ts +5 -10
  71. package/src/actions/governance/exports.ts +9 -0
  72. package/src/actions/governance/getAllProposals.ts +10 -65
  73. package/src/actions/governance/getProposalDetails.ts +6 -33
  74. package/src/actions/governance/getProposalVotes.ts +8 -15
  75. package/src/actions/honey/getChartData.ts +27 -21
  76. package/src/actions/honey/getHoney24hVolume.ts +27 -0
  77. package/src/actions/pol/getAutoclaimedIncentives.ts +30 -0
  78. package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
  79. package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +35 -0
  80. package/src/actions/pol/getEarnedStakedBeraVault.ts +15 -9
  81. package/src/actions/pol/getGlobalData.ts +1 -0
  82. package/src/actions/pol/getHeroEarnVaults.ts +62 -0
  83. package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
  84. package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
  85. package/src/actions/pol/getStakingDailyAssets.ts +11 -8
  86. package/src/actions/server/exports.ts +1 -0
  87. package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
  88. package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
  89. package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
  90. package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
  91. package/src/actions/validators/getValidatorAnalytics.ts +20 -21
  92. package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
  93. package/src/data/contracts.ts +5 -0
  94. package/src/enum/contracts.ts +1 -0
  95. package/src/enum/exports.ts +0 -1
  96. package/src/enum/governance/exports.ts +1 -0
  97. package/src/errors/BeraError.ts +47 -7
  98. package/src/errors/BeraTracing.unit.test.ts +65 -0
  99. package/src/errors/RequestError.ts +15 -2
  100. package/src/errors/exports.ts +5 -0
  101. package/src/errors/getRevertReason.integration.test.ts +3 -3
  102. package/src/errors/spanStatus.ts +78 -0
  103. package/src/errors/spanStatus.unit.test.ts +62 -0
  104. package/src/hooks/dex/useCreatePool.ts +1 -88
  105. package/src/hooks/dex/useOnChainPoolData.ts +27 -2
  106. package/src/hooks/dex/usePriceImpact.ts +12 -5
  107. package/src/hooks/enso/useBendDemultiply.ts +9 -1
  108. package/src/hooks/enso/useBendMultiply.ts +9 -1
  109. package/src/hooks/enso/useBendZapSupply.ts +26 -7
  110. package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
  111. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
  112. package/src/hooks/exports.ts +3 -16
  113. package/src/hooks/governance/exports.ts +14 -0
  114. package/src/hooks/honey/useHoney24hVolume.ts +16 -0
  115. package/src/hooks/pol/useAutoclaimedIncentives.ts +49 -0
  116. package/src/hooks/pol/useStakedAPR.ts +2 -2
  117. package/src/hooks/pol/useStakedSnapshots.ts +5 -9
  118. package/src/hooks/validators/useValidator.ts +2 -0
  119. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
  120. package/src/types/bribe-boost.d.ts +8 -0
  121. package/src/types/exports.ts +0 -1
  122. package/src/types/governance/exports.ts +1 -0
  123. package/src/utils/beraFetch.ts +76 -15
  124. package/src/utils/exports.ts +1 -0
  125. package/src/utils/getServerSideClient.ts +4 -2
  126. package/src/utils/sanitizeRpcUrl.ts +22 -0
  127. package/src/utils/tracedTransport.ts +35 -0
  128. package/dist/BeraError-_mQdkanr.d.ts +0 -94
  129. package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
  130. package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
  131. package/dist/RequestError-A8XJ6QR9.d.cts +0 -57
  132. package/dist/RequestError-Dk97z8rm.d.ts +0 -57
  133. package/dist/abi/exports.cjs +0 -4453
  134. package/dist/abi/exports.cjs.map +0 -1
  135. package/dist/abi/exports.d.cts +0 -6574
  136. package/dist/abi/exports.mjs.map +0 -1
  137. package/dist/actions/exports.cjs +0 -914
  138. package/dist/actions/exports.cjs.map +0 -1
  139. package/dist/actions/exports.d.cts +0 -1644
  140. package/dist/actions/exports.mjs.map +0 -1
  141. package/dist/chunk-2R73G2PO.mjs.map +0 -1
  142. package/dist/chunk-3M47ZRXT.mjs.map +0 -1
  143. package/dist/chunk-4GFN4LEP.mjs.map +0 -1
  144. package/dist/chunk-5N7QQS55.cjs +0 -130
  145. package/dist/chunk-5N7QQS55.cjs.map +0 -1
  146. package/dist/chunk-5NMATIH4.mjs.map +0 -1
  147. package/dist/chunk-7QKRRIHI.mjs.map +0 -1
  148. package/dist/chunk-7TFV6UKF.mjs.map +0 -1
  149. package/dist/chunk-A4FPM7U3.cjs +0 -63
  150. package/dist/chunk-A4FPM7U3.cjs.map +0 -1
  151. package/dist/chunk-BDHINMWQ.cjs +0 -417
  152. package/dist/chunk-BDHINMWQ.cjs.map +0 -1
  153. package/dist/chunk-BEHP54S3.cjs +0 -24
  154. package/dist/chunk-BEHP54S3.cjs.map +0 -1
  155. package/dist/chunk-EGDXV2PT.cjs +0 -36
  156. package/dist/chunk-EGDXV2PT.cjs.map +0 -1
  157. package/dist/chunk-EWBKSMPG.cjs +0 -13
  158. package/dist/chunk-EWBKSMPG.cjs.map +0 -1
  159. package/dist/chunk-F6ZW7ZDD.cjs +0 -403
  160. package/dist/chunk-F6ZW7ZDD.cjs.map +0 -1
  161. package/dist/chunk-FTXTRUYT.cjs +0 -170
  162. package/dist/chunk-FTXTRUYT.cjs.map +0 -1
  163. package/dist/chunk-GLWPRM33.mjs.map +0 -1
  164. package/dist/chunk-GWSTVITN.mjs.map +0 -1
  165. package/dist/chunk-H3Z37RYU.cjs +0 -15
  166. package/dist/chunk-H3Z37RYU.cjs.map +0 -1
  167. package/dist/chunk-I3FTWD6I.mjs.map +0 -1
  168. package/dist/chunk-JA4DHMTG.mjs.map +0 -1
  169. package/dist/chunk-KL6YZ5VR.mjs.map +0 -1
  170. package/dist/chunk-MXWPP6MS.cjs +0 -572
  171. package/dist/chunk-MXWPP6MS.cjs.map +0 -1
  172. package/dist/chunk-SGZP4O6R.mjs.map +0 -1
  173. package/dist/chunk-TDW5SPXR.cjs +0 -244
  174. package/dist/chunk-TDW5SPXR.cjs.map +0 -1
  175. package/dist/chunk-TGK3IXDN.cjs +0 -169
  176. package/dist/chunk-TGK3IXDN.cjs.map +0 -1
  177. package/dist/chunk-TJEW6YCJ.cjs +0 -97
  178. package/dist/chunk-TJEW6YCJ.cjs.map +0 -1
  179. package/dist/chunk-VA3BQ34H.mjs.map +0 -1
  180. package/dist/chunk-VA5L5FDG.mjs.map +0 -1
  181. package/dist/chunk-XSGCRLSD.cjs +0 -1844
  182. package/dist/chunk-XSGCRLSD.cjs.map +0 -1
  183. package/dist/chunk-XV3GG3HC.cjs +0 -135
  184. package/dist/chunk-XV3GG3HC.cjs.map +0 -1
  185. package/dist/chunk-Y5B224UX.cjs +0 -4698
  186. package/dist/chunk-Y5B224UX.cjs.map +0 -1
  187. package/dist/chunk-ZBTRKBSI.mjs +0 -169
  188. package/dist/chunk-ZBTRKBSI.mjs.map +0 -1
  189. package/dist/chunk-ZCEFC2TK.mjs.map +0 -1
  190. package/dist/contexts/exports.cjs +0 -83
  191. package/dist/contexts/exports.cjs.map +0 -1
  192. package/dist/contexts/exports.d.cts +0 -66
  193. package/dist/contexts/exports.mjs.map +0 -1
  194. package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
  195. package/dist/dex-C_BB0b0O.d.cts +0 -37
  196. package/dist/enum/exports.cjs +0 -59
  197. package/dist/enum/exports.cjs.map +0 -1
  198. package/dist/enum/exports.d.cts +0 -23
  199. package/dist/enum/exports.mjs.map +0 -1
  200. package/dist/errors/exports.cjs +0 -39
  201. package/dist/errors/exports.cjs.map +0 -1
  202. package/dist/errors/exports.d.cts +0 -413
  203. package/dist/errors/exports.mjs.map +0 -1
  204. package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
  205. package/dist/global.d-B7IeayVX.d.cts +0 -474
  206. package/dist/honey-CYm0RWf4.d.cts +0 -14
  207. package/dist/hooks/exports.cjs +0 -8333
  208. package/dist/hooks/exports.cjs.map +0 -1
  209. package/dist/hooks/exports.d.cts +0 -1748
  210. package/dist/hooks/exports.mjs.map +0 -1
  211. package/dist/polling-BKnyavLI.d.cts +0 -8
  212. package/dist/txnEnum-7_o92X3N.d.ts +0 -164
  213. package/dist/types/exports.cjs +0 -1
  214. package/dist/types/exports.cjs.map +0 -1
  215. package/dist/types/exports.d.cts +0 -90
  216. package/dist/types/exports.mjs.map +0 -1
  217. package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
  218. package/dist/utils/exports.cjs +0 -787
  219. package/dist/utils/exports.cjs.map +0 -1
  220. package/dist/utils/exports.d.cts +0 -412
  221. package/dist/utils/exports.mjs.map +0 -1
  222. package/src/actions/dex/getIsTokenExploited.ts +0 -63
  223. package/src/actions/honey/getHoneyGlobalData.ts +0 -21
  224. package/src/hooks/dex/useExploitedTokens.ts +0 -57
  225. package/src/hooks/honey/useHoneyGlobalData.ts +0 -23
@@ -0,0 +1,61 @@
1
+ import { fallback, http } from "viem";
2
+ import {
3
+ arbitrum,
4
+ avalanche,
5
+ base,
6
+ bsc,
7
+ mainnet,
8
+ optimism,
9
+ polygon,
10
+ } from "viem/chains";
11
+
12
+ import { publicJsonRpcUrl } from "@berachain/config/internal";
13
+ import { defaultChain } from "@berachain/config/internal/wagmi";
14
+
15
+ const transportOptions = {
16
+ batch: { wait: 35 },
17
+ };
18
+
19
+ const externalTransportOptions = {
20
+ batch: { wait: 15 },
21
+ };
22
+
23
+ export const urls = [publicJsonRpcUrl].filter(Boolean) as string[];
24
+
25
+ /**
26
+ * Thirdweb RPC URLs have a rate limit of 3 RPS.
27
+ * http() uses default viem transport which varies based on the chain definition.
28
+ *
29
+ * Quicknode RPC URLs are CORS restricted to *.berachain.com, *.berachain-staging.com. They have a 100rpm rate limit.
30
+ */
31
+ export const testTransports = {
32
+ [defaultChain.id]: fallback(urls.map((url) => http(url, transportOptions))),
33
+ [mainnet.id]: fallback([
34
+ http("https://1.rpc.thirdweb.com/", externalTransportOptions),
35
+ http(),
36
+ ]),
37
+ [polygon.id]: fallback([
38
+ http("https://137.rpc.thirdweb.com/", externalTransportOptions),
39
+ http(),
40
+ ]),
41
+ [optimism.id]: fallback([
42
+ http("https://10.rpc.thirdweb.com/", externalTransportOptions),
43
+ http(),
44
+ ]),
45
+ [base.id]: fallback([
46
+ http("https://8453.rpc.thirdweb.com/", externalTransportOptions),
47
+ http(),
48
+ ]),
49
+ [bsc.id]: fallback([
50
+ http("https://56.rpc.thirdweb.com/", externalTransportOptions),
51
+ http(),
52
+ ]),
53
+ [avalanche.id]: fallback([
54
+ http("https://43114.rpc.thirdweb.com/", externalTransportOptions),
55
+ http(),
56
+ ]),
57
+ [arbitrum.id]: fallback([
58
+ http("https://42161.rpc.thirdweb.com/", externalTransportOptions),
59
+ http(),
60
+ ]),
61
+ };
@@ -24,16 +24,22 @@ export class BeraApolloClient extends ApolloClient {
24
24
  */
25
25
  protected url: string;
26
26
 
27
+ protected serviceName: string;
27
28
  constructor(
28
29
  options: ApolloClient.Options & {
29
30
  /**
30
31
  * The URL of the endpoint. Used for error reporting only.
31
32
  */
32
33
  url: string;
34
+ /**
35
+ * The name of the graphql service. Used for error reporting only.
36
+ */
37
+ name: string;
33
38
  },
34
39
  ) {
35
40
  super(options);
36
41
  this.url = options.url;
42
+ this.serviceName = options.name;
37
43
  }
38
44
 
39
45
  async query<
@@ -47,13 +53,16 @@ export class BeraApolloClient extends ApolloClient {
47
53
  data: TData;
48
54
  }> {
49
55
  const queryName = getQueryName(options.query);
56
+
50
57
  const endpoint = {
51
58
  url: this.url,
52
59
  type: "graphql",
60
+ name: this.serviceName,
53
61
  } as const;
54
62
 
55
63
  const tags = {
56
64
  "operation.type": "query",
65
+ "operation.source.name": endpoint.name,
57
66
  "operation.source.url": endpoint.url,
58
67
  "operation.source.type": endpoint.type,
59
68
  "operation.source.queryName": queryName,
@@ -0,0 +1,4 @@
1
+ export {
2
+ getApolloClient,
3
+ gql,
4
+ } from "./getApolloClient";
@@ -3,7 +3,7 @@ import { HttpLink } from "@apollo/client/link/http";
3
3
 
4
4
  import type { HttpLink as BeraConfigHttpLink } from "@berachain/config";
5
5
  import { getUriFromLink } from "@berachain/config";
6
- import { currentDapp } from "@berachain/config/internal";
6
+ import { currentDapp, goldskyBaseUrl } from "@berachain/config/internal";
7
7
 
8
8
  import apiResults from "@berachain/graphql/dex/api";
9
9
 
@@ -20,8 +20,12 @@ function applyStellateClientName(url: BeraConfigHttpLink): BeraConfigHttpLink {
20
20
  const isDapp = !!currentDapp;
21
21
  const isTest = process.env.VERCEL_ENV === "test";
22
22
 
23
+ const uri = getUriFromLink(url);
24
+ const name = typeof url === "string" ? "unknown" : url.name;
25
+
23
26
  return {
24
- uri: getUriFromLink(url),
27
+ uri,
28
+ name,
25
29
  headers: {
26
30
  ...headers,
27
31
  "x-graphql-client-name": `berachain.${
@@ -51,9 +55,15 @@ function getClient(
51
55
  ) {
52
56
  const url = getUriFromLink(endpoint);
53
57
  const headers = typeof endpoint === "string" ? undefined : endpoint.headers;
58
+ let name = typeof endpoint === "string" ? undefined : endpoint.name;
59
+
60
+ if (!name && url.includes(goldskyBaseUrl)) {
61
+ name = url.replace(goldskyBaseUrl, "").replace("/gn", "");
62
+ }
54
63
 
55
64
  return new BeraApolloClient({
56
65
  url,
66
+ name: name ?? "unknown",
57
67
  link: new HttpLink({
58
68
  uri: url,
59
69
  headers,
@@ -70,28 +80,68 @@ function getClient(
70
80
  });
71
81
  }
72
82
 
73
- type GraphqlClient =
74
- | "honey.subgraph"
75
- | "pol.subgraph"
76
- | "pol.fees"
77
- | "governance.subgraph"
78
- | "bex.subgraph"
79
- | "api"
80
- | "bend.whisk";
83
+ /**
84
+ * Browser-reachable Apollo client factory for `api` and Bend's `whisk`
85
+ * endpoints. Subgraph clients (honey/pol) are server-only; browser data
86
+ * access goes through the typed `/api/honey/*` and `/api/pol/*` REST
87
+ * endpoints. Same auth shape as bend.whiskApi — non-public env values only
88
+ * resolve server-side.
89
+ */
90
+ type GraphqlClient = "api" | "bend.whisk" | "honey.subgraph" | "pol.subgraph";
91
+
92
+ const SUBGRAPH_CLIENTS = [
93
+ "honey.subgraph",
94
+ "pol.subgraph",
95
+ ] as const satisfies readonly GraphqlClient[];
96
+
97
+ type SubgraphClient = (typeof SUBGRAPH_CLIENTS)[number];
98
+
99
+ function isSubgraphClient(name: GraphqlClient): name is SubgraphClient {
100
+ return SUBGRAPH_CLIENTS.includes(name as SubgraphClient);
101
+ }
102
+
103
+ const clientCache = new Map<string, BeraApolloClient>();
104
+
105
+ function store(
106
+ cacheKey: string | null,
107
+ client: BeraApolloClient,
108
+ ): BeraApolloClient {
109
+ if (cacheKey) clientCache.set(cacheKey, client);
110
+ return client;
111
+ }
81
112
 
82
113
  export function getApolloClient(
83
114
  clientName: GraphqlClient,
84
115
  { ...args }: BeraJS.BaseFunctionArgs,
85
116
  ): BeraApolloClient {
86
- const { config } = parseBaseArgs(args);
117
+ if (typeof window !== "undefined" && isSubgraphClient(clientName)) {
118
+ throw new BeraError({
119
+ message: "Subgraph Apollo client is server-only",
120
+ level: "error",
121
+ });
122
+ }
123
+
124
+ const { config, chainId } = parseBaseArgs(args);
125
+
126
+ // Caller-supplied configs are treated as unique (may override URLs/headers),
127
+ // so they bypass the cache. The common path (chainId-only) is memoized.
128
+ const cacheKey = args.config ? null : `${chainId}:${clientName}`;
129
+
130
+ if (cacheKey) {
131
+ const cached = clientCache.get(cacheKey);
132
+ if (cached) return cached;
133
+ }
87
134
 
88
135
  switch (clientName) {
89
136
  case "api":
90
- return getClient(applyStellateClientName(config.api), {
91
- inMemoryCacheOptions: {
92
- possibleTypes: apiResults.possibleTypes,
93
- },
94
- });
137
+ return store(
138
+ cacheKey,
139
+ getClient(applyStellateClientName(config.api), {
140
+ inMemoryCacheOptions: {
141
+ possibleTypes: apiResults.possibleTypes,
142
+ },
143
+ }),
144
+ );
95
145
 
96
146
  case "bend.whisk":
97
147
  if (!config.bend.whiskApi) {
@@ -100,17 +150,12 @@ export function getApolloClient(
100
150
  level: "error",
101
151
  });
102
152
  }
103
- return getClient(config.bend.whiskApi);
153
+ return store(cacheKey, getClient(config.bend.whiskApi));
104
154
 
105
155
  case "honey.subgraph":
106
- return getClient(config.honey.subgraph);
156
+ return store(cacheKey, getClient(config.honey.subgraph));
157
+
107
158
  case "pol.subgraph":
108
- return getClient(config.pol.subgraph);
109
- case "pol.fees":
110
- return getClient(config.pol.feesSubgraph);
111
- case "governance.subgraph":
112
- return getClient(config.governance.subgraph);
113
- case "bex.subgraph":
114
- return getClient(config.bex.subgraph);
159
+ return store(cacheKey, getClient(config.pol.subgraph));
115
160
  }
116
161
  }
@@ -8,17 +8,28 @@ const isProduction =
8
8
  process.env.NODE_ENV !== "development" && process.env.NODE_ENV !== "test";
9
9
 
10
10
  export function getEnsoClient({
11
- useProxy = isProduction,
11
+ baseURL,
12
12
  ...args
13
- }: BeraJS.BaseFunctionArgs & { useProxy?: boolean } = {}) {
13
+ }: BeraJS.BaseFunctionArgs & {
14
+ /**
15
+ * Override the Enso API base URL.
16
+ *
17
+ * - Omit (or pass `undefined`) → external proxy in production, direct in dev/test
18
+ * - Pass a URL string (e.g. `"/api/enso"`) → route through that proxy
19
+ */
20
+ baseURL?: string;
21
+ } = {}) {
14
22
  const { config } = parseBaseArgs(args);
23
+ const resolvedBaseURL =
24
+ baseURL !== undefined
25
+ ? baseURL
26
+ : isProduction
27
+ ? `${config.bex.aggregatorsProxyUrl}/enso/api/v1/`
28
+ : undefined;
29
+
15
30
  return new EnsoClient({
16
- baseURL: useProxy
17
- ? `${config.bex.aggregatorsProxyUrl}/enso/api/v1/`
18
- : undefined,
19
- apiKey: useProxy
20
- ? // no API key since proxy has CORS for .berachain.com domains
21
- ""
22
- : appConfig.apiKeys.public.enso,
31
+ baseURL: resolvedBaseURL,
32
+ // no API key when routing through a proxy — the proxy handles auth
33
+ apiKey: resolvedBaseURL ? "" : appConfig.apiKeys.public.enso,
23
34
  });
24
35
  }
@@ -213,7 +213,7 @@ export abstract class BaseAggregator {
213
213
 
214
214
  protected async fetch(url: string | URL, options?: RequestInit) {
215
215
  try {
216
- return beraFetch(
216
+ return await beraFetch(
217
217
  { url, name: this.name, type: this.type },
218
218
  {
219
219
  method: "GET",
@@ -49,25 +49,35 @@ class EnsoAggregator extends BaseAggregator {
49
49
  aggregatorsFeeBps,
50
50
  );
51
51
 
52
+ // Enso rejects a zero-address `refundReceiver` with 400 Bad Request, so
53
+ // when no wallet is connected (or the account hasn't hydrated yet) fall
54
+ // back to the executor. Only matters for quotes — on execution the user's
55
+ // real address is always set.
56
+ const refundReceiver =
57
+ account === zeroAddress
58
+ ? this.config.bex.aggregatorsRouterExecutor
59
+ : account;
60
+
61
+ const params = new URLSearchParams({
62
+ fromAddress: this.config.bex.aggregatorsRouterExecutor,
63
+ receiver: this.config.bex.aggregatorsRouterExecutor,
64
+ spender: this.config.bex.aggregatorsRouterExecutor,
65
+ amountIn: inputAmountAfterFees,
66
+ tokenIn: tokenInAddress,
67
+ tokenOut: tokenOutAddress,
68
+ chainId: ChainId.MAINNET.toString(),
69
+ slippage: (Number(slippage) * 100).toString(),
70
+ refundReceiver,
71
+ });
72
+
73
+ // Build the URL via string concat — the `new URL(relative)` constructor
74
+ // throws on relative paths like `/api/aggregators?...`, which silently
75
+ // breaks the Vercel-proxy path.
52
76
  this.url = proxyAggregatorsThroughVercel
53
- ? `/api/aggregators?aggregator=enso`
54
- : `${this.config.bex.aggregatorsProxyUrl}/enso/api/v1/shortcuts/route?`;
77
+ ? `/api/aggregators?aggregator=enso&${params.toString()}`
78
+ : `${this.config.bex.aggregatorsProxyUrl}/enso/api/v1/shortcuts/route?${params.toString()}`;
55
79
 
56
- const url = new URL(this.url);
57
- url.searchParams.set(
58
- "fromAddress",
59
- this.config.bex.aggregatorsRouterExecutor,
60
- );
61
- url.searchParams.set("receiver", this.config.bex.aggregatorsRouterExecutor);
62
- url.searchParams.set("spender", this.config.bex.aggregatorsRouterExecutor);
63
- url.searchParams.set("amountIn", inputAmountAfterFees);
64
- url.searchParams.set("tokenIn", tokenInAddress);
65
- url.searchParams.set("tokenOut", tokenOutAddress);
66
- url.searchParams.set("chainId", ChainId.MAINNET.toString());
67
- url.searchParams.set("slippage", (Number(slippage) * 100).toString());
68
- url.searchParams.set("refundReceiver", account);
69
-
70
- const response = await this.fetch(url);
80
+ const response = await this.fetch(this.url);
71
81
 
72
82
  const quote = await response.json();
73
83
 
@@ -39,7 +39,7 @@ class EnsoErc4626Aggregator extends BaseAggregator {
39
39
  assertAddress(account, "account");
40
40
 
41
41
  const ensoClient = getEnsoClient({
42
- useProxy: !proxyAggregatorsThroughVercel,
42
+ baseURL: proxyAggregatorsThroughVercel ? "/api/enso" : undefined,
43
43
  });
44
44
 
45
45
  if (tokenIn.address === zeroAddress) tokenIn.address = ethAddress;
@@ -148,7 +148,7 @@ class EnsoErc4626Aggregator extends BaseAggregator {
148
148
 
149
149
  const amountOut =
150
150
  // @ts-expect-error enso has not typed this but is returned sometimes from API.
151
- bundle.minAmountsOut[tokenOutAddress] ??
151
+ bundle.minAmountsOut?.[tokenOutAddress] ??
152
152
  bundle.amountsOut[tokenOutAddress] ??
153
153
  "0";
154
154
 
@@ -41,20 +41,23 @@ class KyberSwapAggregator extends BaseAggregator {
41
41
  aggregatorsFeeBps,
42
42
  );
43
43
 
44
- this.url = proxyAggregatorsThroughVercel
45
- ? `/api/aggregators?aggregator=kyberswapRoutes`
46
- : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/routes`;
44
+ const params = new URLSearchParams({
45
+ tokenIn: tokenInAddress,
46
+ tokenOut: tokenOutAddress,
47
+ amountIn: inputAmountAfterFees,
48
+ slippageTolerance: (slippage / 100).toString(),
49
+ to: this.config.bex.aggregatorsRouterExecutor,
50
+ clientData: JSON.stringify({ source: "berachain" }),
51
+ });
47
52
 
48
- const url = new URL(this.url);
49
- // First, get route quote
50
- url.searchParams.set("tokenIn", tokenInAddress);
51
- url.searchParams.set("tokenOut", tokenOutAddress);
52
- url.searchParams.set("amountIn", inputAmountAfterFees);
53
- url.searchParams.set("slippageTolerance", (slippage / 100).toString());
54
- url.searchParams.set("to", this.config.bex.aggregatorsRouterExecutor);
55
- url.searchParams.set("clientData", JSON.stringify({ source: "berachain" }));
53
+ // Build URLs via string concat — the `new URL(relative)` constructor
54
+ // throws on relative paths like `/api/aggregators?...`, which silently
55
+ // breaks the Vercel-proxy path.
56
+ this.url = proxyAggregatorsThroughVercel
57
+ ? `/api/aggregators?aggregator=kyberswapRoutes&${params.toString()}`
58
+ : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/routes?${params.toString()}`;
56
59
 
57
- const routeResponse = await this.fetch(url);
60
+ const routeResponse = await this.fetch(this.url);
58
61
 
59
62
  const routeData = await routeResponse.json();
60
63
  const formattedQuote = {
@@ -79,17 +82,9 @@ class KyberSwapAggregator extends BaseAggregator {
79
82
  source: "berachain",
80
83
  };
81
84
 
82
- const params = url.searchParams.entries();
83
-
84
- const buildUrl = new URL(
85
- proxyAggregatorsThroughVercel
86
- ? `/api/aggregators?aggregator=kyberswapBuild`
87
- : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/route/build`,
88
- );
89
-
90
- for (const [key, value] of params) {
91
- buildUrl.searchParams.set(key, value);
92
- }
85
+ const buildUrl = proxyAggregatorsThroughVercel
86
+ ? `/api/aggregators?aggregator=kyberswapBuild&${params.toString()}`
87
+ : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/route/build?${params.toString()}`;
93
88
 
94
89
  const buildRouteResponse = await this.fetch(buildUrl, {
95
90
  method: "POST",
@@ -9,15 +9,12 @@ import {
9
9
  } from "vitest";
10
10
 
11
11
  import { appConfig } from "@berachain/config/internal";
12
- import {
13
- defaultChain,
14
- externalChains,
15
- transports,
16
- } from "@berachain/config/internal/wagmi";
12
+ import { defaultChain, externalChains } from "@berachain/config/internal/wagmi";
17
13
 
18
14
  import { getConfig } from "@berachain/wagmi/config";
19
15
 
20
16
  import { BeraMonitoring } from "../../../errors/BeraMonitoring";
17
+ import { testTransports } from "../../__test/transports";
21
18
  import { getEnsoClient } from "../../clients/getEnsoClient";
22
19
  import { getEnsoUserTokensWithBalances } from "../getEnsoUserTokensWithBalances";
23
20
 
@@ -41,7 +38,7 @@ describe("getEnsoUserTokensWithBalances", () => {
41
38
  const ensoClient = getEnsoClient();
42
39
 
43
40
  const beraWagmiConfig = getConfig({
44
- transports,
41
+ transports: testTransports,
45
42
  defaultChain,
46
43
  chains: externalChains,
47
44
  thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
@@ -25,21 +25,12 @@ export * from "./dex/getPoolHistoricalData";
25
25
  export * from "./dex/getPoolPausedState";
26
26
  export * from "./dex/getPoolWithState";
27
27
  export * from "./dex/getVaultPausedState";
28
- export * from "./governance/checkProposalField";
29
- export * from "./governance/computeActualStatus";
30
- export * from "./governance/getAllProposals";
31
- export * from "./governance/getBodyErrors";
32
- export * from "./governance/getDecodedFunctionData";
33
- export * from "./governance/getProposalDetails";
34
- export * from "./governance/getProposalFromTx";
35
- export * from "./governance/getProposalVotes";
36
- export * from "./governance/parseProposalBody";
37
28
  export * from "./honey/getChartData";
38
29
  export * from "./honey/getCollateralWeights";
39
30
  export * from "./honey/getGlobalCapLimit";
31
+ export * from "./honey/getHoney24hVolume";
40
32
  export * from "./honey/getHoneyCollaterals";
41
33
  export * from "./honey/getHoneyFees";
42
- export * from "./honey/getHoneyGlobalData";
43
34
  export * from "./honey/getHoneyPausedState";
44
35
  export * from "./honey/getHoneyPreview";
45
36
  export * from "./honey/getHoneyPythPriceOracle";
@@ -51,10 +42,14 @@ export * from "./honey/getSwapPayload";
51
42
  export * from "./honey/isBadCollateralAsset";
52
43
  export * from "./honey/isBasketModeEnabled";
53
44
  export * from "./misc/getBlockTimestamp";
45
+ export * from "./pol/getAutoclaimedIncentives";
46
+ export * from "./pol/getBeraTokenTotalSupply";
54
47
  export * from "./pol/getBgtAprSimulation";
48
+ export * from "./pol/getBgtIncentiveDistributorPaused";
55
49
  export * from "./pol/getBlockTime";
56
50
  export * from "./pol/getEarnedStakedBeraVault";
57
51
  export * from "./pol/getGlobalData";
52
+ export * from "./pol/getHeroEarnVaults";
58
53
  export * from "./pol/getIncentiveFeeClaimStats";
59
54
  export * from "./pol/getLSTStakeConfig";
60
55
  export * from "./pol/getMarkets";
@@ -0,0 +1,9 @@
1
+ export * from "./checkProposalField";
2
+ export * from "./computeActualStatus";
3
+ export * from "./getAllProposals";
4
+ export * from "./getBodyErrors";
5
+ export * from "./getDecodedFunctionData";
6
+ export * from "./getProposalDetails";
7
+ export * from "./getProposalFromTx";
8
+ export * from "./getProposalVotes";
9
+ export * from "./parseProposalBody";
@@ -1,19 +1,10 @@
1
- import {
2
- GetProposals,
3
- type GetProposalsQuery,
4
- type GetProposalsQueryVariables,
5
- type OrderDirection,
6
- type Proposal_Filter,
7
- type Proposal_OrderBy,
8
- type ProposalSelectionFragment,
9
- SearchProposals,
10
- type SearchProposalsQuery,
11
- type SearchProposalsQueryVariables,
1
+ import type {
2
+ OrderDirection,
3
+ Proposal_Filter,
4
+ Proposal_OrderBy,
5
+ ProposalSelectionFragment,
12
6
  } from "@berachain/graphql/governance";
13
7
 
14
- import { getApolloClient } from "../clients/getApolloClient";
15
- import { computeActualStatus } from "./computeActualStatus";
16
-
17
8
  export type GetAllProposalsArgs = BeraJS.BaseFunctionArgs & {
18
9
  /** Subgraph filter applied to the proposals query */
19
10
  where: Proposal_Filter;
@@ -28,55 +19,9 @@ export type GetAllProposalsArgs = BeraJS.BaseFunctionArgs & {
28
19
  };
29
20
 
30
21
  /** Fetches a paginated list of governance proposals from the subgraph */
31
- export async function getAllProposals({
32
- where,
33
- orderBy,
34
- orderDirection,
35
- offset = 0,
36
- perPage = 20,
37
- text,
38
- ...args
39
- }: GetAllProposalsArgs): Promise<ProposalSelectionFragment[] | undefined> {
40
- try {
41
- if (perPage > 1000) {
42
- throw new Error("perPage must be less than 1000");
43
- }
44
-
45
- const governanceClient = getApolloClient("governance.subgraph", args);
46
- const [response] = await Promise.all([
47
- text
48
- ? governanceClient.query<
49
- SearchProposalsQuery,
50
- SearchProposalsQueryVariables
51
- >({
52
- query: SearchProposals,
53
- variables: {
54
- offset,
55
- limit: perPage,
56
- where,
57
- text,
58
- },
59
- })
60
- : governanceClient.query<GetProposalsQuery, GetProposalsQueryVariables>(
61
- {
62
- query: GetProposals,
63
- variables: {
64
- offset,
65
- limit: perPage,
66
- where,
67
- orderBy,
68
- orderDirection,
69
- },
70
- },
71
- ),
72
- ]);
73
-
74
- return response.data.proposals.map((p) => ({
75
- ...p,
76
- status: computeActualStatus(p),
77
- }));
78
- } catch (e) {
79
- console.error("getAllProposals:", e);
80
- throw e;
81
- }
22
+ export async function getAllProposals(
23
+ _args: GetAllProposalsArgs,
24
+ ): Promise<ProposalSelectionFragment[] | undefined> {
25
+ // Governance subgraph not live — return empty until indexer is available
26
+ return [];
82
27
  }
@@ -1,14 +1,6 @@
1
1
  import type { PublicClient } from "viem";
2
2
 
3
- import {
4
- GetProposal,
5
- type GetProposalQuery,
6
- type GetProposalQueryVariables,
7
- type ProposalWithVotesFragment,
8
- } from "@berachain/graphql/governance";
9
-
10
- import { getApolloClient } from "../clients/getApolloClient";
11
- import { computeActualStatus } from "./computeActualStatus";
3
+ import type { ProposalWithVotesFragment } from "@berachain/graphql/governance";
12
4
 
13
5
  export type GetProposalDetailsArgs = BeraJS.BaseFunctionArgs & {
14
6
  /** On-chain proposal ID */
@@ -17,28 +9,9 @@ export type GetProposalDetailsArgs = BeraJS.BaseFunctionArgs & {
17
9
  };
18
10
 
19
11
  /** Fetches a single proposal with its vote data from the subgraph */
20
- export async function getProposalDetails({
21
- proposalId,
22
- ...args
23
- }: GetProposalDetailsArgs): Promise<ProposalWithVotesFragment | undefined> {
24
- const governanceClient = getApolloClient("governance.subgraph", args);
25
-
26
- const res = await governanceClient.query<
27
- GetProposalQuery,
28
- GetProposalQueryVariables
29
- >({
30
- query: GetProposal,
31
- variables: {
32
- id: proposalId,
33
- },
34
- });
35
-
36
- if (!res.data.proposal) {
37
- return undefined;
38
- }
39
-
40
- return {
41
- ...res.data.proposal,
42
- status: computeActualStatus(res.data.proposal),
43
- } as ProposalWithVotesFragment;
12
+ export async function getProposalDetails(
13
+ _args: GetProposalDetailsArgs,
14
+ ): Promise<ProposalWithVotesFragment | undefined> {
15
+ // Governance subgraph not live — return undefined until indexer is available
16
+ return undefined;
44
17
  }
@@ -1,24 +1,17 @@
1
- import {
2
- GetProposalVotes,
3
- type GetProposalVotesQuery,
4
- type GetProposalVotesQueryVariables,
1
+ import type {
2
+ GetProposalVotesQuery,
3
+ GetProposalVotesQueryVariables,
5
4
  } from "@berachain/graphql/governance";
6
5
 
7
- import { getApolloClient } from "../clients/getApolloClient";
8
-
9
6
  export type GetProposalVotesArgs = BeraJS.BaseFunctionArgs & {
10
7
  /** GraphQL variables forwarded to the GetProposalVotes query */
11
8
  variables: GetProposalVotesQueryVariables;
12
9
  };
13
10
 
14
11
  /** Fetches the votes for a proposal from the subgraph */
15
- export async function getProposalVotes({
16
- variables,
17
- ...args
18
- }: GetProposalVotesArgs) {
19
- const governanceClient = getApolloClient("governance.subgraph", args);
20
- return governanceClient.query<GetProposalVotesQuery>({
21
- query: GetProposalVotes,
22
- variables,
23
- });
12
+ export async function getProposalVotes(
13
+ _args: GetProposalVotesArgs,
14
+ ): Promise<{ data: GetProposalVotesQuery }> {
15
+ // Governance subgraph not live — return empty until indexer is available
16
+ return { data: { votes: [] } };
24
17
  }