diff --git a/src/components/IndexSupplyQuery.tsx b/src/components/IndexSupplyQuery.tsx index 6df8045c..7bec084d 100644 --- a/src/components/IndexSupplyQuery.tsx +++ b/src/components/IndexSupplyQuery.tsx @@ -57,6 +57,7 @@ const EVM_TABLE_COLUMNS = { } as const type IndexSupplyQueryProps = { + chainId: number signatures?: string[] query?: string title?: string @@ -132,7 +133,7 @@ function renderCellValue(cell: string | number | boolean | null): React.ReactNod ) } -export function IndexSupplyQuery(props: IndexSupplyQueryProps = {}) { +export function IndexSupplyQuery(props: IndexSupplyQueryProps) { const isReadOnly = props.query !== undefined const allSignatures = React.useMemo(() => getAllSignatures(), []) @@ -207,7 +208,10 @@ export function IndexSupplyQuery(props: IndexSupplyQueryProps = {}) { setResult(null) try { - const options = signatures.length > 0 ? { signatures } : {} + const options = { + chainId: props.chainId, + ...(signatures.length > 0 ? { signatures } : {}), + } const queryResult = await runIndexSupplyQuery(queryToRun, options) setResult(queryResult) } catch (err) { @@ -230,7 +234,10 @@ export function IndexSupplyQuery(props: IndexSupplyQueryProps = {}) { setError(null) setResult(null) - runIndexSupplyQuery(queryToRun, signatures.length > 0 ? { signatures } : {}) + runIndexSupplyQuery(queryToRun, { + chainId: props.chainId, + ...(signatures.length > 0 ? { signatures } : {}), + }) .then((queryResult) => { setResult(queryResult) }) diff --git a/src/components/lib/IndexSupply.ts b/src/components/lib/IndexSupply.ts index 400cea1b..bceb76a0 100644 --- a/src/components/lib/IndexSupply.ts +++ b/src/components/lib/IndexSupply.ts @@ -43,16 +43,18 @@ export function toAddressValue(value: RowValue | null | undefined): Address.Addr } type RunQueryOptions = { + chainId: number signatures?: string[] } -export async function runIndexSupplyQuery(query: string, options: RunQueryOptions = {}) { +export async function runIndexSupplyQuery(query: string, options: RunQueryOptions) { const response = await fetch('/api/index-supply', { method: 'POST', headers: { 'content-type': 'application/json', }, body: JSON.stringify({ + chainId: options.chainId, query: query.replace(/\s+/g, ' ').trim(), signatures: options.signatures, }), diff --git a/src/pages/_api/api/index-supply.ts b/src/pages/_api/api/index-supply.ts index b796567e..ed8f4782 100644 --- a/src/pages/_api/api/index-supply.ts +++ b/src/pages/_api/api/index-supply.ts @@ -1,6 +1,5 @@ -import { tempo } from 'viem/chains' - type QueryRequest = { + chainId: number query: string signatures?: string[] } @@ -35,9 +34,16 @@ export async function POST(request: Request): Promise { ) } - const apiKey = import.meta.env.VITE_INDEXSUPPLY_API_KEY + if (!Number.isInteger(body.chainId) || body.chainId <= 0) { + return Response.json( + { error: 'Invalid request: chainId is required and must be a positive integer' }, + { status: 400, headers: corsHeaders }, + ) + } + + const apiKey = process.env.INDEXSUPPLY_API_KEY if (!apiKey) { - console.error('VITE_INDEXSUPPLY_API_KEY is not configured') + console.error('INDEXSUPPLY_API_KEY is not configured') return Response.json( { error: 'Server configuration error: API key not found' }, { status: 500, headers: corsHeaders }, @@ -51,8 +57,7 @@ export async function POST(request: Request): Promise { const signatures = body.signatures && body.signatures.length > 0 ? body.signatures : [''] - const chainId = tempo.id - const chainCursor = `${chainId}-0` + const chainCursor = `${body.chainId}-0` const response = await fetch(url.toString(), { method: 'POST', diff --git a/src/pages/guide/stablecoin-dex/view-the-orderbook.mdx b/src/pages/guide/stablecoin-dex/view-the-orderbook.mdx index 3666a078..c151d7b7 100644 --- a/src/pages/guide/stablecoin-dex/view-the-orderbook.mdx +++ b/src/pages/guide/stablecoin-dex/view-the-orderbook.mdx @@ -21,15 +21,18 @@ In this guide, we use [Index Supply](https://www.indexsupply.net) as our indexin Query the best bid and ask prices to calculate the current spread for a token pair. -Find the highest bid prices (buyers) for PathUSD. This query filters out fully filled and cancelled orders, groups by price level (tick), and shows the top 5 bid prices with their total liquidity. +These examples use the mainnet `USDC.e / pathUSD` orderbook; `pathUSD` is the quote token for `USDC.e` — see [Quote Tokens](/protocol/exchange/quote-tokens). + +Find the highest bid prices (buyers) for the `USDC.e / pathUSD` book. This query filters out fully filled and cancelled orders, groups by price level (tick), and shows the top 5 bid prices with their total liquidity. -Find the lowest ask prices (sellers) for PathUSD. The spread is the difference between the highest bid and lowest ask price. +Find the lowest ask prices (sellers) for the `USDC.e / pathUSD` book. The spread is the difference between the highest bid and lowest ask price. #### Cancelled orders -Check if an order has been cancelled. This query returns an order for PathUSD that was explicitly cancelled by the maker before being fully filled. +Check if a `USDC.e` order has been cancelled. This query returns a recent order from the `USDC.e / pathUSD` book that was explicitly cancelled by the maker before being fully filled. @@ -170,10 +180,11 @@ Check if an order has been cancelled. This query returns an order for PathUSD th View the last prices a token traded at to understand recent market activity. -This query joins order fill events with their corresponding placement details to show the price tick and amount for recent trades. +This query joins order fill events with their corresponding placement details to show the price tick and amount for recent trades in the `USDC.e / pathUSD` book.