From 406440868c68c725e75d361d49724bd89e1f4a97 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Mon, 16 Nov 2026 14:33:09 -0600 Subject: [PATCH 1/3] feat: make the SDK backend URL configurable Select the Aave SDK backend preset with NEXT_PUBLIC_BACKEND_ENVIRONMENT (production | staging | local, defaults to production) and optionally override its GraphQL URL with NEXT_PUBLIC_GRAPHQL_ENDPOINT, mirroring interface-v4. Co-Authored-By: Claude Opus 5.5 --- .env.example | 4 ++++ pages/_app.page.tsx | 3 ++- src/utils/sdkEnvironment.ts | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/utils/sdkEnvironment.ts diff --git a/.env.example b/.env.example index 5f0dcb804a..26619ea5e6 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,10 @@ NEXT_PUBLIC_ENABLE_STAKING=true # Force-build the /dev/components showcase. Automatic on `next dev` and Vercel previews. NEXT_PUBLIC_ENABLE_DEV_PAGES=false NEXT_PUBLIC_API_BASEURL=https://aave-api-v2.aave.com +# Aave SDK backend: production | staging | local (optional, defaults to production) +NEXT_PUBLIC_BACKEND_ENVIRONMENT= +# Overrides the GraphQL URL of the backend environment above, keeping its other settings (optional) +NEXT_PUBLIC_GRAPHQL_ENDPOINT= NEXT_PUBLIC_TRANSAK_APP_URL=https://global.transak.com NEXT_PUBLIC_TRANSAK_API_URL=https://api.transak.com NEXT_PUBLIC_TRANSAK_API_KEY=799087ea-c2be-44b8-a0fe-56d96b37ee3c diff --git a/pages/_app.page.tsx b/pages/_app.page.tsx index a5e6481982..af0765de21 100644 --- a/pages/_app.page.tsx +++ b/pages/_app.page.tsx @@ -29,6 +29,7 @@ import { Web3ContextProvider } from 'src/libs/web3-data-provider/Web3Provider'; import { useRootStore } from 'src/store/root'; import { SharedDependenciesProvider } from 'src/ui-config/SharedDependenciesProvider'; import { wagmiConfig } from 'src/ui-config/wagmiConfig'; +import { SDK_ENVIRONMENT } from 'src/utils/sdkEnvironment'; import { WagmiProvider } from 'wagmi'; import createEmotionCache from '../src/createEmotionCache'; @@ -116,7 +117,7 @@ type NextPageWithLayout = NextPage & { getLayout?: (page: React.ReactElement) => React.ReactNode; }; -export const client = AaveClient.create(); +export const client = AaveClient.create({ environment: SDK_ENVIRONMENT }); interface MyAppProps extends AppProps { emotionCache?: EmotionCache; diff --git a/src/utils/sdkEnvironment.ts b/src/utils/sdkEnvironment.ts new file mode 100644 index 0000000000..d40e119745 --- /dev/null +++ b/src/utils/sdkEnvironment.ts @@ -0,0 +1,17 @@ +import { local, production, staging } from '@aave/react'; + +const SDK_ENVIRONMENT_PRESET = (() => { + switch (process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT) { + case 'local': + return local; + case 'staging': + return staging; + default: + return production; + } +})(); + +export const SDK_ENVIRONMENT = { + ...SDK_ENVIRONMENT_PRESET, + backend: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || SDK_ENVIRONMENT_PRESET.backend, +}; From de03cdb52958b6ff538f69d2c373bf410aa2fbfe Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Mon, 30 Nov 2026 11:03:55 -0600 Subject: [PATCH 2/3] Revert "fix: trim payoutToken in markets query to unblock X Layer (#3199)" This reverts commit 288d8ae1e713d3f29746d8d54c5bc9dcc706d192. Co-Authored-By: Claude Opus 5.5 --- src/hooks/app-data-provider/useMarketsData.ts | 39 ++----------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/src/hooks/app-data-provider/useMarketsData.ts b/src/hooks/app-data-provider/useMarketsData.ts index f123d61aaa..8952de3353 100644 --- a/src/hooks/app-data-provider/useMarketsData.ts +++ b/src/hooks/app-data-provider/useMarketsData.ts @@ -1,38 +1,9 @@ import { AaveClient, chainId, evmAddress, OrderDirection } from '@aave/client'; -import { MarketsQuery } from '@aave/graphql'; +import { markets } from '@aave/client/actions'; import { useQuery } from '@tanstack/react-query'; -import { FieldNode, Kind, visit } from 'graphql'; import { MarketDataType } from 'src/ui-config/marketsConfig'; import { queryKeysFactory } from 'src/ui-config/queries'; -// TEMPORARY WORKAROUND: remove once the backend resolves Merkl payout tokens on -// their own chain. -// -// A Merkl campaign can pay out on a different chain than its market (e.g. an -// X Layer campaign paying mainnet USDC). The API currently labels the payout -// token with the market's chain, so resolving its `decimals`/`name`/`symbol` -// calls a non-existent contract and fails the whole `markets` query, which -// blanks the market page. The interface never reads `payoutToken`, so we send -// the SDK's own Markets document with `payoutToken` trimmed to fields that need -// no on-chain lookup. Same shape as the SDK's `markets()` action otherwise. -const SAFE_PAYOUT_TOKEN_FIELDS = ['__typename', 'address', 'chainId']; - -const SafeMarketsQuery = visit(MarketsQuery, { - Field(node): FieldNode | undefined { - if (node.name.value !== 'payoutToken') return undefined; - return { - ...node, - selectionSet: { - kind: Kind.SELECTION_SET, - selections: SAFE_PAYOUT_TOKEN_FIELDS.map((field) => ({ - kind: Kind.FIELD, - name: { kind: Kind.NAME, value: field }, - })), - }, - }; - }, -}) as typeof MarketsQuery; - type UseMarketsDataParams = { client: AaveClient; marketData: MarketDataType; @@ -50,11 +21,9 @@ export const useMarketsData = ({ client, marketData, account }: UseMarketsDataPa queryKey: marketKey, enabled: !!client, queryFn: async () => { - const response = await client.query(SafeMarketsQuery, { - request: { - chainIds: [chainId(marketData.chainId)], - user: userAddress, - }, + const response = await markets(client, { + chainIds: [chainId(marketData.chainId)], + user: userAddress, suppliesOrderBy: { tokenName: OrderDirection.Asc }, borrowsOrderBy: { tokenName: OrderDirection.Asc }, }); From d1aa9f182712354e97b577a24cc9373d47a44032 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Tue, 1 Dec 2026 12:05:19 -0500 Subject: [PATCH 3/3] query hash interceptor --- src/utils/queryHash.ts | 87 +++++++++++++++++++++++++++++++++++++ src/utils/sdkEnvironment.ts | 4 ++ 2 files changed, 91 insertions(+) create mode 100644 src/utils/queryHash.ts diff --git a/src/utils/queryHash.ts b/src/utils/queryHash.ts new file mode 100644 index 0000000000..f32e6cd190 --- /dev/null +++ b/src/utils/queryHash.ts @@ -0,0 +1,87 @@ +// The edge cache keys GraphQL responses on the sha256 of the POST body, one comma-separated hash per element for a batch +const QUERY_HASH_HEADER = 'x-query-hash'; + +const installed = Symbol.for('aave-interface.queryHashFetch'); + +async function sha256Hex(body: string): Promise { + const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(body)); + return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join(''); +} + +// Sliced from the text rather than re-serialised, so the bytes match what the edge hashes +function splitElements(text: string): string[] | null { + try { + if (!Array.isArray(JSON.parse(text))) return null; + } catch { + return null; + } + + const elements: string[] = []; + let start = text.indexOf('[') + 1; + let depth = 0; + let inString = false; + let escaped = false; + + for (let i = start; i < text.length; i++) { + const c = text[i]; + + if (inString) { + if (escaped) escaped = false; + else if (c === '\\') escaped = true; + else if (c === '"') inString = false; + } else if (c === '"') { + inString = true; + } else if (c === '{' || c === '[') { + depth++; + } else if ((c === '}' || c === ']') && depth > 0) { + depth--; + } else if ((c === ',' || c === ']') && depth === 0) { + const element = text.slice(start, i).trim(); + if (element.length > 0) elements.push(element); + if (c === ']') break; + start = i + 1; + } + } + + return elements; +} + +async function queryHash(body: string): Promise { + const elements = body.trimStart().startsWith('[') ? splitElements(body) : null; + if (elements === null || elements.length === 0) return sha256Hex(body); + + return (await Promise.all(elements.map(sha256Hex))).join(','); +} + +function requestUrl(input: RequestInfo | URL): string | null { + if (typeof input === 'string') return input; + if (input instanceof URL) return input.href; + return null; +} + +// The SDK exposes neither a custom fetch nor per-request headers, so the global fetch is wrapped instead +export function installQueryHashFetch(endpoint: string) { + if (typeof globalThis.fetch !== 'function') return; + if (typeof crypto === 'undefined' || !crypto.subtle) return; + + const current = globalThis.fetch as typeof fetch & { [installed]?: true }; + if (current[installed]) return; + + const original = current; + const wrapped: typeof fetch = async (input, init) => { + const url = requestUrl(input); + if ( + !url?.startsWith(endpoint) || + init?.method?.toUpperCase() !== 'POST' || + typeof init.body !== 'string' + ) { + return original(input, init); + } + + const headers = new Headers(init.headers); + headers.set(QUERY_HASH_HEADER, await queryHash(init.body)); + return original(input, { ...init, headers }); + }; + + globalThis.fetch = Object.assign(wrapped, { [installed]: true as const }); +} diff --git a/src/utils/sdkEnvironment.ts b/src/utils/sdkEnvironment.ts index d40e119745..b2674ee62c 100644 --- a/src/utils/sdkEnvironment.ts +++ b/src/utils/sdkEnvironment.ts @@ -1,5 +1,7 @@ import { local, production, staging } from '@aave/react'; +import { installQueryHashFetch } from './queryHash'; + const SDK_ENVIRONMENT_PRESET = (() => { switch (process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT) { case 'local': @@ -15,3 +17,5 @@ export const SDK_ENVIRONMENT = { ...SDK_ENVIRONMENT_PRESET, backend: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || SDK_ENVIRONMENT_PRESET.backend, }; + +installQueryHashFetch(SDK_ENVIRONMENT.backend);