Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 15 additions & 3 deletions src/routes/pools/svm.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,33 @@ pools_with_tokens AS (
FROM {db_dex:Identifier}.state_pools_aggregating_by_mint AS pt
WHERE amm_pool IN (SELECT amm_pool FROM pools)
GROUP BY protocol, program_id, amm, amm_pool
),
decimals AS (
SELECT mint, decimals AS dec_value
FROM {db_accounts:Identifier}.decimals_state
WHERE mint IN (
SELECT arrayJoin([token0, token1]) AS mint FROM pools_with_tokens
)
LIMIT 1 BY mint
)
SELECT
/* DEX */
p.program_id AS program_id,
program_names(p.program_id) AS program_name,
p.protocol AS protocol,
p.amm as amm,
program_names(p.amm) as amm_name,
p.amm AS amm,
program_names(p.amm) AS amm_name,
p.amm_pool AS amm_pool,
pt.token0 AS input_mint,
if(d0.mint != '', d0.dec_value, NULL) AS input_decimals,
pt.token1 AS output_mint,
p.transactions as transactions,
if(d1.mint != '', d1.dec_value, NULL) AS output_decimals,
p.transactions AS transactions,

/* Network */
{network: String} AS network
FROM pools AS p
JOIN pools_with_tokens AS pt ON p.amm_pool = pt.amm_pool AND p.protocol = pt.protocol
LEFT JOIN decimals AS d0 ON d0.mint = pt.token0
LEFT JOIN decimals AS d1 ON d1.mint = pt.token1
ORDER BY p.transactions DESC
4 changes: 4 additions & 0 deletions src/routes/pools/svm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const responseSchema = apiUsageResponseSchema.extend({
amm_pool: svmAmmPoolSchema,

input_mint: svmMintSchema,
input_decimals: z.number().nullable(),
output_mint: svmMintSchema,
output_decimals: z.number().nullable(),
transactions: z.number(),

// -- chain --
Expand Down Expand Up @@ -74,7 +76,9 @@ const openapi = describeRoute(
amm_name: 'Raydium Liquidity Pool V4',
amm_pool: 'Dqb7bL7MZkuDgHrZZphRMRViJnepHxf9odx3RRwmifur',
input_mint: '9bJKq2eLbLFKbcD9zYBNTrQ5Pua7hXMeivu7Fk3iWWoQ',
input_decimals: 6,
output_mint: 'Fm34vVNQYoEkenNjCeM8MVP8mBV5EGLwA86WFHwyMcz4',
output_decimals: 9,
transactions: 43062555,
network: 'solana',
},
Expand Down
4 changes: 3 additions & 1 deletion src/routes/routes.sql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ describe.skipIf(!DB_TESTS)('SQL queries', () => {
// --- SVM Pools ---
it('GET /v1/svm/pools', async () => {
if (!hasSvmDex) return;
const { response, body } = await fetchRoute(`/v1/svm/pools?network=${svmNetwork}`);
const { response, body } = await fetchRoute(
`/v1/svm/pools?network=${svmNetwork}&amm_pool=${SVM_AMM_POOL_PUMP_EXAMPLE}`
);
expect(response.status).toBe(200);
expect(body.data).toBeArray();
expect(body.data.length).toBeGreaterThan(0);
Expand Down
Loading