Skip to content

Commit 21b0ac3

Browse files
authored
fix(docs): fix Index Supply query examples (#218)
1 parent 1c457a0 commit 21b0ac3

4 files changed

Lines changed: 65 additions & 40 deletions

File tree

src/components/IndexSupplyQuery.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const EVM_TABLE_COLUMNS = {
5757
} as const
5858

5959
type IndexSupplyQueryProps = {
60+
chainId: number
6061
signatures?: string[]
6162
query?: string
6263
title?: string
@@ -132,7 +133,7 @@ function renderCellValue(cell: string | number | boolean | null): React.ReactNod
132133
)
133134
}
134135

135-
export function IndexSupplyQuery(props: IndexSupplyQueryProps = {}) {
136+
export function IndexSupplyQuery(props: IndexSupplyQueryProps) {
136137
const isReadOnly = props.query !== undefined
137138

138139
const allSignatures = React.useMemo(() => getAllSignatures(), [])
@@ -207,7 +208,10 @@ export function IndexSupplyQuery(props: IndexSupplyQueryProps = {}) {
207208
setResult(null)
208209

209210
try {
210-
const options = signatures.length > 0 ? { signatures } : {}
211+
const options = {
212+
chainId: props.chainId,
213+
...(signatures.length > 0 ? { signatures } : {}),
214+
}
211215
const queryResult = await runIndexSupplyQuery(queryToRun, options)
212216
setResult(queryResult)
213217
} catch (err) {
@@ -230,7 +234,10 @@ export function IndexSupplyQuery(props: IndexSupplyQueryProps = {}) {
230234
setError(null)
231235
setResult(null)
232236

233-
runIndexSupplyQuery(queryToRun, signatures.length > 0 ? { signatures } : {})
237+
runIndexSupplyQuery(queryToRun, {
238+
chainId: props.chainId,
239+
...(signatures.length > 0 ? { signatures } : {}),
240+
})
234241
.then((queryResult) => {
235242
setResult(queryResult)
236243
})

src/components/lib/IndexSupply.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ export function toAddressValue(value: RowValue | null | undefined): Address.Addr
4343
}
4444

4545
type RunQueryOptions = {
46+
chainId: number
4647
signatures?: string[]
4748
}
4849

49-
export async function runIndexSupplyQuery(query: string, options: RunQueryOptions = {}) {
50+
export async function runIndexSupplyQuery(query: string, options: RunQueryOptions) {
5051
const response = await fetch('/api/index-supply', {
5152
method: 'POST',
5253
headers: {
5354
'content-type': 'application/json',
5455
},
5556
body: JSON.stringify({
57+
chainId: options.chainId,
5658
query: query.replace(/\s+/g, ' ').trim(),
5759
signatures: options.signatures,
5860
}),

src/pages/_api/api/index-supply.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { tempo } from 'viem/chains'
2-
31
type QueryRequest = {
2+
chainId: number
43
query: string
54
signatures?: string[]
65
}
@@ -35,9 +34,16 @@ export async function POST(request: Request): Promise<Response> {
3534
)
3635
}
3736

38-
const apiKey = import.meta.env.VITE_INDEXSUPPLY_API_KEY
37+
if (!Number.isInteger(body.chainId) || body.chainId <= 0) {
38+
return Response.json(
39+
{ error: 'Invalid request: chainId is required and must be a positive integer' },
40+
{ status: 400, headers: corsHeaders },
41+
)
42+
}
43+
44+
const apiKey = process.env.INDEXSUPPLY_API_KEY
3945
if (!apiKey) {
40-
console.error('VITE_INDEXSUPPLY_API_KEY is not configured')
46+
console.error('INDEXSUPPLY_API_KEY is not configured')
4147
return Response.json(
4248
{ error: 'Server configuration error: API key not found' },
4349
{ status: 500, headers: corsHeaders },
@@ -51,8 +57,7 @@ export async function POST(request: Request): Promise<Response> {
5157

5258
const signatures = body.signatures && body.signatures.length > 0 ? body.signatures : ['']
5359

54-
const chainId = tempo.id
55-
const chainCursor = `${chainId}-0`
60+
const chainCursor = `${body.chainId}-0`
5661

5762
const response = await fetch(url.toString(), {
5863
method: 'POST',

src/pages/guide/stablecoin-dex/view-the-orderbook.mdx

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ In this guide, we use [Index Supply](https://www.indexsupply.net) as our indexin
2121

2222
Query the best bid and ask prices to calculate the current spread for a token pair.
2323

24-
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.
24+
These examples use the mainnet `USDC.e / pathUSD` orderbook; `pathUSD` is the quote token for `USDC.e` — see [Quote Tokens](/protocol/exchange/quote-tokens).
25+
26+
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.
2527

2628
<IndexSupplyQuery
27-
title={'Best Bid Prices for PathUSD'}
29+
chainId={4217}
30+
title={'Best Bid Prices for USDC.e'}
2831
query={`SELECT
2932
tick as price,
3033
SUM(amount) as total_liquidity
3134
FROM orderplaced
32-
WHERE token = '0x20c0000000000000000000000000000000000000'
35+
WHERE token = '0x20c000000000000000000000b9537d11c60e8b50'
3336
AND "isBid" = true
3437
AND NOT EXISTS (
3538
SELECT 1 FROM orderfilled
@@ -46,15 +49,16 @@ Find the highest bid prices (buyers) for PathUSD. This query filters out fully f
4649
signatures={["OrderPlaced", "OrderFilled", "OrderCancelled"]}
4750
/>
4851

49-
Find the lowest ask prices (sellers) for PathUSD. The spread is the difference between the highest bid and lowest ask price.
52+
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.
5053

5154
<IndexSupplyQuery
52-
title={'Best Ask Prices for PathUSD'}
55+
chainId={4217}
56+
title={'Best Ask Prices for USDC.e'}
5357
query={`SELECT
5458
tick as price,
5559
SUM(amount) as total_liquidity
5660
FROM orderplaced
57-
WHERE token = '0x20c0000000000000000000000000000000000000'
61+
WHERE token = '0x20c000000000000000000000b9537d11c60e8b50'
5862
AND "isBid" = false
5963
AND NOT EXISTS (
6064
SELECT 1 FROM orderfilled
@@ -75,17 +79,18 @@ Find the lowest ask prices (sellers) for PathUSD. The spread is the difference b
7579

7680
View aggregated liquidity at each price level to understand the orderbook structure.
7781

78-
This query shows all active orders for BetaUSD, including both regular and flip orders.
82+
This query shows all active orders in the `USDC.e / pathUSD` book, including both regular and flip orders.
7983

8084
<IndexSupplyQuery
81-
title={'BetaUSD Order Depth by Price Level'}
85+
chainId={4217}
86+
title={'USDC.e Order Depth by Price Level'}
8287
query={`SELECT
8388
tick as price,
8489
"isBid" as is_bid,
8590
COUNT("orderId") as num_orders,
8691
SUM(amount) as total_amount
8792
FROM orderplaced
88-
WHERE token = '0x20c0000000000000000000000000000000000002'
93+
WHERE token = '0x20c000000000000000000000b9537d11c60e8b50'
8994
AND NOT EXISTS (
9095
SELECT 1 FROM orderfilled
9196
WHERE orderfilled."orderId" = orderplaced."orderId"
@@ -107,10 +112,11 @@ This query shows all active orders for BetaUSD, including both regular and flip
107112

108113
Get detailed information about a specific order including its placement details, fill history, and cancellation status.
109114

110-
This query inspects the details of the most recent order for PathUSD. It shows when the order was created, at what price (tick), the order size, whether it's a flip order, and who placed it.
115+
This query inspects the details of the most recent order in the `USDC.e / pathUSD` book. It shows when the order was created, at what price (tick), the order size, whether it's a flip order, and who placed it.
111116

112117
<IndexSupplyQuery
113-
title={'Order Placement Details'}
118+
chainId={4217}
119+
title={'Order Placement Details for USDC.e'}
114120
query={`SELECT
115121
"orderId",
116122
tick,
@@ -123,45 +129,49 @@ This query inspects the details of the most recent order for PathUSD. It shows w
123129
block_num,
124130
tx_hash
125131
FROM orderplaced
126-
WHERE token = '0x20c0000000000000000000000000000000000000'
132+
WHERE token = '0x20c000000000000000000000b9537d11c60e8b50'
127133
ORDER BY block_num DESC
128134
LIMIT 1`}
129135
signatures={["OrderPlaced"]}
130136
/>
131137

132138
#### Order fill status
133139

134-
Check if an order has been partially or fully filled. This query shows up to 5 fill events for order number `2`, including the amount filled in each transaction and whether it was a partial fill.
140+
Check if recent `USDC.e` orders have been partially or fully filled. This query shows up to 5 fill events for the `USDC.e / pathUSD` market, including the amount filled in each transaction and whether it was a partial fill.
135141

136142
<IndexSupplyQuery
137-
title={'Order Fill History'}
143+
chainId={4217}
144+
title={'Order Fill History for USDC.e'}
138145
query={`SELECT
139-
"orderId",
140-
"amountFilled",
141-
"partialFill",
142-
block_num,
143-
tx_hash
144-
FROM orderfilled
145-
WHERE "orderId" = 2
146-
ORDER BY block_num DESC
146+
ofl."orderId",
147+
ofl."amountFilled",
148+
ofl."partialFill",
149+
ofl.block_num,
150+
ofl.tx_hash
151+
FROM orderfilled ofl
152+
INNER JOIN orderplaced op
153+
ON ofl."orderId" = op."orderId"
154+
WHERE op.token = '0x20c000000000000000000000b9537d11c60e8b50'
155+
ORDER BY ofl.block_num DESC
147156
LIMIT 5`}
148-
signatures={["OrderFilled"]}
157+
signatures={["OrderFilled", "OrderPlaced"]}
149158
/>
150159

151160
#### Cancelled orders
152161

153-
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.
162+
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.
154163

155164
<IndexSupplyQuery
156-
title={'Order Cancellation Status'}
165+
chainId={4217}
166+
title={'Order Cancellation Status for USDC.e'}
157167
query={`SELECT
158168
oc."orderId",
159169
oc.block_num,
160170
oc.tx_hash
161171
FROM ordercancelled oc
162172
INNER JOIN orderplaced op ON oc."orderId" = op."orderId"
163-
WHERE op.token = '0x20c0000000000000000000000000000000000000'
164-
ORDER BY op.block_num DESC
173+
WHERE op.token = '0x20c000000000000000000000b9537d11c60e8b50'
174+
ORDER BY oc.block_num DESC
165175
LIMIT 1`}
166176
signatures={["OrderCancelled", "OrderPlaced"]}
167177
/>
@@ -170,10 +180,11 @@ Check if an order has been cancelled. This query returns an order for PathUSD th
170180

171181
View the last prices a token traded at to understand recent market activity.
172182

173-
This query joins order fill events with their corresponding placement details to show the price tick and amount for recent trades.
183+
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.
174184

175185
<IndexSupplyQuery
176-
title={'Recent Trade Prices for PathUSD'}
186+
chainId={4217}
187+
title={'Recent Trade Prices for USDC.e'}
177188
query={`SELECT
178189
ofl.block_num,
179190
ofl."orderId",
@@ -183,7 +194,7 @@ This query joins order fill events with their corresponding placement details to
183194
FROM orderfilled ofl
184195
INNER JOIN orderplaced o
185196
ON ofl."orderId" = o."orderId"
186-
WHERE o.token = '0x20c0000000000000000000000000000000000000'
197+
WHERE o.token = '0x20c000000000000000000000b9537d11c60e8b50'
187198
ORDER BY ofl.block_num DESC
188199
LIMIT 10`}
189200
signatures={["OrderFilled", "OrderPlaced"]}

0 commit comments

Comments
 (0)