diff --git a/src/routes/pools/svm.sql b/src/routes/pools/svm.sql index de7763bf..a10d3802 100644 --- a/src/routes/pools/svm.sql +++ b/src/routes/pools/svm.sql @@ -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 diff --git a/src/routes/pools/svm.ts b/src/routes/pools/svm.ts index a3d0a76d..4e753485 100644 --- a/src/routes/pools/svm.ts +++ b/src/routes/pools/svm.ts @@ -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 -- @@ -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', }, diff --git a/src/routes/routes.sql.spec.ts b/src/routes/routes.sql.spec.ts index 27c50058..ce79eaed 100644 --- a/src/routes/routes.sql.spec.ts +++ b/src/routes/routes.sql.spec.ts @@ -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);