Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a1df7ac
update tables names for breaking changes
YaroShkvorets Nov 20, 2025
b619cfb
fix decimals table
YaroShkvorets Nov 20, 2025
50ead74
tvm-tokens v0.2.0 changes
YaroShkvorets Nov 26, 2025
b261964
handle duplicate metadata
YaroShkvorets Nov 26, 2025
15eb1a5
changeset
YaroShkvorets Nov 26, 2025
02d79ed
preview bump
YaroShkvorets Nov 26, 2025
2a943eb
fix tvm/tokens
YaroShkvorets Nov 26, 2025
42adc83
clean up sql query
YaroShkvorets Nov 26, 2025
e0d7c99
fix tvm endpoints
YaroShkvorets Dec 1, 2025
1476bd3
first stab
YaroShkvorets Dec 1, 2025
39495db
add meta
YaroShkvorets Dec 2, 2025
c2ac08e
fix lazy materializtion error
YaroShkvorets Dec 2, 2025
2c341ae
add other filters
YaroShkvorets Dec 3, 2025
2ab772c
add 3 filters
YaroShkvorets Dec 5, 2025
3aca780
refactor swaps sql logic
YaroShkvorets Dec 8, 2025
c20f58f
add native tokens to query
YaroShkvorets Dec 8, 2025
b7a1164
add factory filter
YaroShkvorets Dec 8, 2025
c28356a
add 0xeee contract
YaroShkvorets Dec 8, 2025
8b498bc
refactor metadata query to use unique_contracts CTE
YaroShkvorets Dec 8, 2025
fc020e1
refactor /evm/pools
YaroShkvorets Dec 9, 2025
df46bcb
remap protocol names
YaroShkvorets Dec 9, 2025
5ea36a8
add protocol filter to /evm/swaps endpoint
YaroShkvorets Dec 9, 2025
bf5de96
refactor pools query to use initialize fields and improve token metad…
YaroShkvorets Dec 11, 2025
26b347c
replace user filter with separate caller, sender, and recipient filters
YaroShkvorets Dec 12, 2025
49120fa
refactor supported_dexes queries to use ohlc_prices table and add res…
YaroShkvorets Dec 12, 2025
f067083
refactor ohlc_prices_for_pool query to use token metadata and interva…
YaroShkvorets Dec 12, 2025
e4cdaa6
udpate changeset
YaroShkvorets Dec 12, 2025
4a0eef3
Update EVM Swaps
DenisCarriere Dec 13, 2025
bbff390
update tests
DenisCarriere Dec 13, 2025
688f962
Update pools (NOT FINISHED)
DenisCarriere Dec 15, 2025
60d45e4
Update OHLC
DenisCarriere Dec 15, 2025
9757205
Remove evm/prices
DenisCarriere Dec 15, 2025
4de7723
Update pools
DenisCarriere Dec 15, 2025
b4586c9
Fix Supported DEXes
DenisCarriere Dec 15, 2025
dcaaed6
update input/output
DenisCarriere Dec 15, 2025
1410a34
Update liquidity pools
DenisCarriere Dec 16, 2025
858e8a4
Remove extra fields from /evm/pools
DenisCarriere Dec 16, 2025
a4df8c7
update OHLC
DenisCarriere Dec 16, 2025
4dd456f
Update swaps
DenisCarriere Dec 16, 2025
a3b5d0a
Update TVM swaps
DenisCarriere Dec 16, 2025
c1e4431
fix start time
DenisCarriere Dec 16, 2025
91d7e05
add TVM liquidity pools
DenisCarriere Dec 16, 2025
829bc39
update TVM pools
DenisCarriere Dec 17, 2025
8a24a66
Add GROUP BY
DenisCarriere Dec 17, 2025
8cc1471
add network to metadata
DenisCarriere Dec 17, 2025
fbeb236
add network
DenisCarriere Dec 17, 2025
0816011
add network field
DenisCarriere Dec 17, 2025
78e6f9a
fix lint
DenisCarriere Dec 17, 2025
8bf8760
add network
DenisCarriere Dec 17, 2025
c021d8c
push fix to OHLC
DenisCarriere Dec 17, 2025
6e8166d
Fix duplicate pools
DenisCarriere Dec 17, 2025
4ffab9d
remove high_quantile
DenisCarriere Dec 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/floppy-feet-send.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"token-api": minor
---

Updated SQL queries for svm-tokens@v0.2.8, svm-dex@v0.3.1, tvm-tokens@v0.2.0, evm-dex@v0.2.5, evm-tokens@v1.17.4
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { z } from 'zod';

import pkg from '../package.json' with { type: 'json' };

// Set timezone to UTC
process.env.TZ = 'Etc/UTC';

// defaults
export const DEFAULT_PORT = '8000';
export const DEFAULT_HOSTNAME = 'localhost';
Expand Down
11 changes: 5 additions & 6 deletions src/routes/v1/evm/dexes/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import {
} from '../../../../types/zod.js';
import { validatorHook, withErrorResponses } from '../../../../utils.js';

const querySchema = createQuerySchema(
{
network: { schema: evmNetworkIdSchema },
},
false // Disable pagination for this endpoint, return all results in one go
);
const querySchema = createQuerySchema({
network: { schema: evmNetworkIdSchema },
});

const responseSchema = apiUsageResponseSchema.extend({
data: z.array(
Expand All @@ -29,6 +26,7 @@ const responseSchema = apiUsageResponseSchema.extend({
uaw: z.number(),
transactions: z.number(),
last_activity: z.string().describe('ISO 8601 datetime string'),
network: evmNetworkIdSchema,
})
),
});
Expand All @@ -55,6 +53,7 @@ const openapi = describeRoute(
uaw: 10432787,
transactions: 16029788,
last_activity: '2025-11-06 16:00:00',
network: 'mainnet',
},
],
},
Expand Down
23 changes: 15 additions & 8 deletions src/routes/v1/evm/pools/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,27 @@ const querySchema = createQuerySchema({
const responseSchema = apiUsageResponseSchema.extend({
data: z.array(
z.object({
// -- block --
// // -- block --
// block_num: z.number(),
// datetime: dateTimeSchema,
// timestamp: z.number(),

// -- transaction --
// // -- transaction --
// transaction_id: z.string(),

// -- pool --
factory: evmFactorySchema,
pool: evmPoolSchema,
factory: evmFactorySchema,
protocol: evmProtocolSchema,

// -- tokens --
input_token: evmTokenResponseSchema,
output_token: evmTokenResponseSchema,
fee: z.number(),
protocol: evmProtocolSchema,

// // -- stats --
// transactions: z.number(),
// uaw: z.number(),
// fee: z.number(),

// -- chain --
network: evmNetworkIdSchema,
Expand All @@ -75,7 +82,7 @@ const responseSchema = apiUsageResponseSchema.extend({
const openapi = describeRoute(
withErrorResponses({
summary: 'Liquidity Pools',
description: 'Returns Uniswap liquidity pool metadata including token pairs, fees, and protocol versions.',
description: 'Returns DEX pool metadata including tokens, fees and protocol.',

tags: ['EVM DEXs'],
security: [{ bearerAuth: [] }],
Expand All @@ -90,8 +97,9 @@ const openapi = describeRoute(
value: {
data: [
{
factory: '0x1f98431c8ad98523631ae4a59f267346ea31f984',
pool: '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640',
factory: '0x1f98431c8ad98523631ae4a59f267346ea31f984',
protocol: 'uniswap_v3',
input_token: {
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
symbol: 'USDC',
Expand All @@ -103,7 +111,6 @@ const openapi = describeRoute(
decimals: 18,
},
fee: 500,
protocol: 'uniswap_v3',
network: 'mainnet',
},
],
Expand Down
7 changes: 4 additions & 3 deletions src/routes/v1/evm/pools/ohlc/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ const responseSchema = apiUsageResponseSchema.extend({
volume: z.number(),
uaw: z.number(),
transactions: z.number(),
network: evmNetworkIdSchema,
})
),
});

const openapi = describeRoute(
withErrorResponses({
summary: 'Pool OHLCV Data',
summary: 'Pool OHLCV',
description:
'Returns OHLCV price data for liquidity pools.\n\nOHLCV historical depth is subject to plan restrictions.',
tags: ['EVM DEXs'],
Expand All @@ -72,6 +73,7 @@ const openapi = describeRoute(
volume: 32956701.586648002,
uaw: 1363,
transactions: 3066,
network: 'mainnet',
},
],
},
Expand All @@ -90,6 +92,7 @@ route.get('/', openapi, zValidator('query', querySchema, validatorHook), validat
const params = c.req.valid('query');

const dbConfig = config.uniswapDatabases[params.network];

if (!dbConfig) {
return c.json({ error: `Network not found: ${params.network}` }, 400);
}
Expand All @@ -101,8 +104,6 @@ route.get('/', openapi, zValidator('query', querySchema, validatorHook), validat
[query],
{
...params,
high_quantile: 1 - config.ohlcQuantile,
low_quantile: config.ohlcQuantile,
stablecoin_contracts: [...stables],
},
{ database: dbConfig.database }
Expand Down
105 changes: 0 additions & 105 deletions src/routes/v1/evm/prices/evm.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/routes/v1/evm/prices/index.ts

This file was deleted.

31 changes: 29 additions & 2 deletions src/routes/v1/evm/swaps/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { handleUsageQueryError, makeUsageQueryJson } from '../../../../handleQue
import { sqlQueries } from '../../../../sql/index.js';
import {
EVM_ADDRESS_SWAP_EXAMPLE,
EVM_CONTRACT_USDC_EXAMPLE,
EVM_CONTRACT_WETH_EXAMPLE,
EVM_FACTORY_UNISWAP_V2_EXAMPLE,
EVM_POOL_USDC_WETH_EXAMPLE,
EVM_TRANSACTION_SWAP_EXAMPLE,
} from '../../../../types/examples.js';
Expand All @@ -16,6 +19,7 @@ import {
createQuerySchema,
dateTimeSchema,
evmAddressSchema,
evmContractSchema,
evmFactorySchema,
evmNetworkIdSchema,
evmPoolSchema,
Expand All @@ -35,10 +39,28 @@ const querySchema = createQuerySchema({
default: '',
meta: { example: EVM_TRANSACTION_SWAP_EXAMPLE },
},
factory: {
schema: evmFactorySchema,
batched: true,
default: '',
meta: { example: EVM_FACTORY_UNISWAP_V2_EXAMPLE },
},
pool: { schema: evmPoolSchema, batched: true, default: '', meta: { example: EVM_POOL_USDC_WETH_EXAMPLE } },
caller: { schema: evmAddressSchema, batched: true, default: '', meta: { example: EVM_ADDRESS_SWAP_EXAMPLE } },
sender: { schema: evmAddressSchema, batched: true, default: '', meta: { example: EVM_ADDRESS_SWAP_EXAMPLE } },
recipient: { schema: evmAddressSchema, batched: true, default: '', meta: { example: EVM_ADDRESS_SWAP_EXAMPLE } },
input_contract: {
schema: evmContractSchema,
batched: true,
default: '',
meta: { example: EVM_CONTRACT_USDC_EXAMPLE },
},
output_contract: {
schema: evmContractSchema,
batched: true,
default: '',
meta: { example: EVM_CONTRACT_WETH_EXAMPLE },
},
protocol: { schema: evmProtocolSchema, default: '' },

start_time: { schema: timestampSchema, prefault: '2015-01-01' },
Expand Down Expand Up @@ -66,6 +88,10 @@ const responseSchema = apiUsageResponseSchema.extend({
sender: evmAddressSchema,
recipient: evmAddressSchema,

// -- log --
// ordinal: z.number(),

// -- price --
input_amount: z.string(),
input_value: z.number(),
output_amount: z.string(),
Expand All @@ -84,7 +110,7 @@ const responseSchema = apiUsageResponseSchema.extend({
const openapi = describeRoute(
withErrorResponses({
summary: 'Swap Events',
description: 'Returns DEX swap transactions from Uniswap protocols with token amounts and prices.',
description: 'Returns DEX swaps events with input & output token amounts.',

tags: ['EVM DEXs'],
security: [{ bearerAuth: [] }],
Expand Down Expand Up @@ -147,13 +173,14 @@ route.get('/', openapi, zValidator('query', querySchema, validatorHook), validat
const params = c.req.valid('query');

const dbConfig = config.uniswapDatabases[params.network];

if (!dbConfig) {
return c.json({ error: `Network not found: ${params.network}` }, 400);
}
const query = sqlQueries.swaps?.[dbConfig.type];
if (!query) return c.json({ error: 'Query for swaps could not be loaded' }, 500);

const response = await makeUsageQueryJson(c, [query], params, { database: dbConfig.database });
const response = await makeUsageQueryJson(c, [query], { ...params }, { database: dbConfig.database });
return handleUsageQueryError(c, response);
});

Expand Down
9 changes: 3 additions & 6 deletions src/routes/v1/svm/dexes/svm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import {
} from '../../../../types/zod.js';
import { validatorHook, withErrorResponses } from '../../../../utils.js';

const querySchema = createQuerySchema(
{
network: { schema: svmNetworkIdSchema },
},
false // Disable pagination for this endpoint, return all results in one go
);
const querySchema = createQuerySchema({
network: { schema: svmNetworkIdSchema },
});

const responseSchema = apiUsageResponseSchema.extend({
data: z.array(
Expand Down
4 changes: 1 addition & 3 deletions src/routes/v1/svm/pools/ohlc/svm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const responseSchema = apiUsageResponseSchema.extend({

const openapi = describeRoute(
withErrorResponses({
summary: 'Pool OHLCV Data',
summary: 'Pool OHLCV',
description: 'Provides pricing data in the Open/High/Low/Close/Volume (OHCLV) format for DEX pools.',
tags: ['SVM DEXs'],
security: [{ bearerAuth: [] }],
Expand Down Expand Up @@ -113,8 +113,6 @@ route.get('/', openapi, zValidator('query', querySchema, validatorHook), validat
[query],
{
...params,
high_quantile: 0.95,
low_quantile: 0.05,
stablecoin_contracts: [...stables],
db_svm_tokens: db_svm_tokens.database,
},
Expand Down
Loading