From e0b390575757d8b500e7b9bf513bbfd8064c3483 Mon Sep 17 00:00:00 2001 From: green-jay Date: Thu, 2 Nov 2023 09:44:42 +0100 Subject: [PATCH 1/7] fix volume & categorize endpoints --- .../hydradx-ui/v1/stats/alltime/volume.mjs | 61 +++++++++++++++++++ .../hydradx-ui/v1/stats/current/price.mjs | 2 +- .../hydradx-ui/v1/stats/current/tvl.mjs | 2 +- .../hydradx-ui/v1/stats/current/volume.mjs | 2 +- .../v1/stats/{ => historical}/lrna.mjs | 17 +++--- .../v1/stats/{ => historical}/tvl.mjs | 23 ++++--- .../v1/stats/{ => historical}/volume.mjs | 23 ++++--- .../hydradx-ui/v1/stats/alltime/volume.sql | 34 +++++++++++ .../v1/stats/{ => historical}/lrna.sql | 0 .../v1/stats/{ => historical}/tvl.sql | 2 +- .../v1/stats/{ => historical}/volume.sql | 16 ++++- 11 files changed, 149 insertions(+), 33 deletions(-) create mode 100644 app/routes/hydradx-ui/v1/stats/alltime/volume.mjs rename app/routes/hydradx-ui/v1/stats/{ => historical}/lrna.mjs (72%) rename app/routes/hydradx-ui/v1/stats/{ => historical}/tvl.mjs (66%) rename app/routes/hydradx-ui/v1/stats/{ => historical}/volume.mjs (73%) create mode 100644 queries/hydradx-ui/v1/stats/alltime/volume.sql rename queries/hydradx-ui/v1/stats/{ => historical}/lrna.sql (100%) rename queries/hydradx-ui/v1/stats/{ => historical}/tvl.sql (98%) rename queries/hydradx-ui/v1/stats/{ => historical}/volume.sql (78%) diff --git a/app/routes/hydradx-ui/v1/stats/alltime/volume.mjs b/app/routes/hydradx-ui/v1/stats/alltime/volume.mjs new file mode 100644 index 0000000..d992ea3 --- /dev/null +++ b/app/routes/hydradx-ui/v1/stats/alltime/volume.mjs @@ -0,0 +1,61 @@ +import yesql from "yesql"; +import path from "path"; +import { dirname } from "../../../../../../variables.mjs"; +import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; +import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; + +const sqlQueries = yesql( + path.join(dirname(), "queries/hydradx-ui/v1/stats/alltime"), + { + type: "pg", + } +); + +export default async (fastify, opts) => { + fastify.route({ + url: "/volume/:asset?", + method: ["GET"], + schema: { + description: "All time trading volume.", + tags: ["hydradx-ui/v1"], + params: { + type: "object", + properties: { + asset: { + type: "integer", + description: "Asset (id). Leave empty for all assets.", + }, + }, + }, + response: { + 200: { + description: "Success Response", + type: "array", + items: { + type: "object", + properties: { + volume_usd: { type: "number" }, + }, + }, + }, + }, + }, + handler: async (request, reply) => { + const asset = request.params.asset ? request.params.asset : null; + + const sqlQuery = sqlQueries.statsAlltimeVolume({ asset }); + + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1statsAlltimeVolume"] }; + cacheSetting.key = cacheSetting.key + "_" + asset; + + const result = await cachedFetch( + fastify.pg, + fastify.redis, + cacheSetting, + sqlQuery + ); + + reply.send(JSON.parse(result)); + }, + }); +}; diff --git a/app/routes/hydradx-ui/v1/stats/current/price.mjs b/app/routes/hydradx-ui/v1/stats/current/price.mjs index d5bca48..e08901a 100644 --- a/app/routes/hydradx-ui/v1/stats/current/price.mjs +++ b/app/routes/hydradx-ui/v1/stats/current/price.mjs @@ -23,7 +23,7 @@ export default async (fastify, opts) => { type: "object", properties: { asset: { - type: "string", + type: "integer", description: "Asset (id)", }, }, diff --git a/app/routes/hydradx-ui/v1/stats/current/tvl.mjs b/app/routes/hydradx-ui/v1/stats/current/tvl.mjs index 830dca8..9a5f708 100644 --- a/app/routes/hydradx-ui/v1/stats/current/tvl.mjs +++ b/app/routes/hydradx-ui/v1/stats/current/tvl.mjs @@ -22,7 +22,7 @@ export default async (fastify, opts) => { type: "object", properties: { asset: { - type: "string", + type: "integer", description: "Asset (id). Leave empty for all assets.", }, }, diff --git a/app/routes/hydradx-ui/v1/stats/current/volume.mjs b/app/routes/hydradx-ui/v1/stats/current/volume.mjs index e81f483..fe0c303 100644 --- a/app/routes/hydradx-ui/v1/stats/current/volume.mjs +++ b/app/routes/hydradx-ui/v1/stats/current/volume.mjs @@ -22,7 +22,7 @@ export default async (fastify, opts) => { type: "object", properties: { asset: { - type: "string", + type: "integer", description: "Asset (id). Leave empty for all assets.", }, }, diff --git a/app/routes/hydradx-ui/v1/stats/lrna.mjs b/app/routes/hydradx-ui/v1/stats/historical/lrna.mjs similarity index 72% rename from app/routes/hydradx-ui/v1/stats/lrna.mjs rename to app/routes/hydradx-ui/v1/stats/historical/lrna.mjs index 652a54c..5a781ed 100644 --- a/app/routes/hydradx-ui/v1/stats/lrna.mjs +++ b/app/routes/hydradx-ui/v1/stats/historical/lrna.mjs @@ -1,13 +1,16 @@ import yesql from "yesql"; import path from "path"; -import { dirname } from "../../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../../variables.mjs"; -import { cachedFetch } from "../../../../../helpers/cache_helpers.mjs"; -import { getAssets } from "../../../../../helpers/asset_helpers.mjs"; +import { dirname } from "../../../../../../variables.mjs"; +import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; +import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; +import { getAssets } from "../../../../../../helpers/asset_helpers.mjs"; -const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), { - type: "pg", -}); +const sqlQueries = yesql( + path.join(dirname(), "queries/hydradx-ui/v1/stats/historical"), + { + type: "pg", + } +); export default async (fastify, opts) => { fastify.route({ diff --git a/app/routes/hydradx-ui/v1/stats/tvl.mjs b/app/routes/hydradx-ui/v1/stats/historical/tvl.mjs similarity index 66% rename from app/routes/hydradx-ui/v1/stats/tvl.mjs rename to app/routes/hydradx-ui/v1/stats/historical/tvl.mjs index 38f3e01..7af1837 100644 --- a/app/routes/hydradx-ui/v1/stats/tvl.mjs +++ b/app/routes/hydradx-ui/v1/stats/historical/tvl.mjs @@ -1,13 +1,16 @@ import yesql from "yesql"; import path from "path"; -import { dirname } from "../../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../../variables.mjs"; -import { cachedFetch } from "../../../../../helpers/cache_helpers.mjs"; -import { getAssets } from "../../../../../helpers/asset_helpers.mjs"; +import { dirname } from "../../../../../../variables.mjs"; +import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; +import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; +import { getAssets } from "../../../../../../helpers/asset_helpers.mjs"; -const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), { - type: "pg", -}); +const sqlQueries = yesql( + path.join(dirname(), "queries/hydradx-ui/v1/stats/historical"), + { + type: "pg", + } +); export default async (fastify, opts) => { fastify.route({ @@ -20,7 +23,7 @@ export default async (fastify, opts) => { type: "object", properties: { asset: { - type: "string", + type: "integer", description: "Asset (id). Leave empty for all assets.", }, }, @@ -42,9 +45,9 @@ export default async (fastify, opts) => { handler: async (request, reply) => { const asset = request.params.asset ? request.params.asset : null; - const sqlQuery = sqlQueries.statsTvl({ asset }); + const sqlQuery = sqlQueries.statsHistoricalTvl({ asset }); - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsTvl"] }; + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1statsHistoricalTvl"] }; cacheSetting.key = cacheSetting.key + "_" + asset; const result = await cachedFetch( diff --git a/app/routes/hydradx-ui/v1/stats/volume.mjs b/app/routes/hydradx-ui/v1/stats/historical/volume.mjs similarity index 73% rename from app/routes/hydradx-ui/v1/stats/volume.mjs rename to app/routes/hydradx-ui/v1/stats/historical/volume.mjs index b2f8608..a3ffcc0 100644 --- a/app/routes/hydradx-ui/v1/stats/volume.mjs +++ b/app/routes/hydradx-ui/v1/stats/historical/volume.mjs @@ -1,12 +1,15 @@ import yesql from "yesql"; import path from "path"; -import { dirname } from "../../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../../variables.mjs"; -import { cachedFetch } from "../../../../../helpers/cache_helpers.mjs"; +import { dirname } from "../../../../../../variables.mjs"; +import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; +import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; -const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), { - type: "pg", -}); +const sqlQueries = yesql( + path.join(dirname(), "queries/hydradx-ui/v1/stats/historical"), + { + type: "pg", + } +); export const VALID_TIMEFRAMES = ["hourly", "daily"]; @@ -21,7 +24,7 @@ export default async (fastify, opts) => { type: "object", properties: { asset: { - type: "string", + type: "integer", description: "Asset (id). Leave empty for all assets.", }, }, @@ -54,9 +57,11 @@ export default async (fastify, opts) => { const asset = request.params.asset ? request.params.asset : null; const timeframe = request.query.timeframe; - const sqlQuery = sqlQueries.statsVolume({ asset, timeframe }); + const sqlQuery = sqlQueries.statsHistoricalVolume({ asset, timeframe }); - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsVolume"] }; + let cacheSetting = { + ...CACHE_SETTINGS["hydradxUiV1statsHistoricalVolume"], + }; cacheSetting.key = cacheSetting.key + "_" + asset + "_" + timeframe; const result = await cachedFetch( diff --git a/queries/hydradx-ui/v1/stats/alltime/volume.sql b/queries/hydradx-ui/v1/stats/alltime/volume.sql new file mode 100644 index 0000000..1efe82c --- /dev/null +++ b/queries/hydradx-ui/v1/stats/alltime/volume.sql @@ -0,0 +1,34 @@ +-- statsAlltimeVolume + +/* Returns all time volume */ + +SELECT + CASE + WHEN :asset::text IS NOT NULL THEN + round(SUM(volume_omnipool_roll_24_usd)) + ELSE + round(SUM(volume_omnipool_roll_24_usd)/2) + END AS volume_usd +FROM ( + SELECT + symbol, + volume_omnipool_roll_24_usd, + timestamp, + ROW_NUMBER() OVER ( + PARTITION BY symbol, timestamp::date + ORDER BY timestamp DESC + ) AS rn + FROM + stats_historical + WHERE + CASE + WHEN :asset::text IS NOT NULL + THEN asset_id = :asset::integer + ELSE + true + END +) a +WHERE + rn = 1 +ORDER BY + 1 DESC; diff --git a/queries/hydradx-ui/v1/stats/lrna.sql b/queries/hydradx-ui/v1/stats/historical/lrna.sql similarity index 100% rename from queries/hydradx-ui/v1/stats/lrna.sql rename to queries/hydradx-ui/v1/stats/historical/lrna.sql diff --git a/queries/hydradx-ui/v1/stats/tvl.sql b/queries/hydradx-ui/v1/stats/historical/tvl.sql similarity index 98% rename from queries/hydradx-ui/v1/stats/tvl.sql rename to queries/hydradx-ui/v1/stats/historical/tvl.sql index 4b9b40d..c93b953 100644 --- a/queries/hydradx-ui/v1/stats/tvl.sql +++ b/queries/hydradx-ui/v1/stats/historical/tvl.sql @@ -1,4 +1,4 @@ --- statsTvl +-- statsHistoricalTvl /* Returns 60 rows with all time TVL in USD */ diff --git a/queries/hydradx-ui/v1/stats/volume.sql b/queries/hydradx-ui/v1/stats/historical/volume.sql similarity index 78% rename from queries/hydradx-ui/v1/stats/volume.sql rename to queries/hydradx-ui/v1/stats/historical/volume.sql index 6e1444c..092319a 100644 --- a/queries/hydradx-ui/v1/stats/volume.sql +++ b/queries/hydradx-ui/v1/stats/historical/volume.sql @@ -1,4 +1,4 @@ --- statsVolume +-- statsHistoricalVolume /* :timeframe = hourly @@ -11,7 +11,12 @@ Returns 30 rows with volume in USD, one daily for last 30d, last record is for y WITH CombinedQuery AS ( SELECT timestamp::date as "timestamp", - round(sum(volume_usd)/2) as volume_usd, + CASE + WHEN :asset::text IS NOT NULL + THEN round(sum(volume_usd)) + ELSE + round(sum(volume_usd)/2) + END as volume_usd, 'daily' as type FROM stats_historical @@ -28,7 +33,12 @@ WITH CombinedQuery AS ( UNION ALL SELECT date_trunc('hour', timestamp) as "timestamp", - round(sum(volume_usd)/2) as volume_usd, + CASE + WHEN :asset::text IS NOT NULL + THEN round(sum(volume_usd)) + ELSE + round(sum(volume_usd)/2) + END as volume_usd, 'hourly' as type FROM stats_historical From bc6e12dc2adb647460a39233db01c38a3cb6050a Mon Sep 17 00:00:00 2001 From: green-jay Date: Thu, 2 Nov 2023 11:54:24 +0100 Subject: [PATCH 2/7] faster cache and smol refactoring --- queries/defillama/v1/tvl.sql | 2 +- queries/defillama/v1/volume.sql | 4 ++-- queries/hydradx-ui/v1/stats/alltime/volume.sql | 6 +++--- queries/hydradx-ui/v1/stats/current/tvl.sql | 4 ++-- queries/hydradx-ui/v1/stats/current/volume.sql | 6 +++--- queries/hydradx-ui/v1/stats/historical/tvl.sql | 4 ++-- queries/hydradx-ui/v1/stats/historical/volume.sql | 12 ++++++------ variables.mjs | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/queries/defillama/v1/tvl.sql b/queries/defillama/v1/tvl.sql index 3b30f84..d0268a7 100644 --- a/queries/defillama/v1/tvl.sql +++ b/queries/defillama/v1/tvl.sql @@ -16,7 +16,7 @@ FROM JOIN omnipool_asset oa ON leb.height = oa.block JOIN token_metadata tm ON oa.asset_id = tm.id WHERE CASE - WHEN :asset::text IS NOT NULL + WHEN :asset::integer IS NOT NULL THEN symbol = :asset ELSE true diff --git a/queries/defillama/v1/volume.sql b/queries/defillama/v1/volume.sql index 022f48d..7fa5980 100644 --- a/queries/defillama/v1/volume.sql +++ b/queries/defillama/v1/volume.sql @@ -4,7 +4,7 @@ SELECT CASE - WHEN :asset::text IS NOT NULL + WHEN :asset::integer IS NOT NULL THEN SUM(round(volume_roll_24_usd)) ELSE @@ -22,7 +22,7 @@ FROM ( stats_historical WHERE CASE - WHEN :asset::text IS NOT NULL + WHEN :asset::integer IS NOT NULL THEN symbol = :asset ELSE true diff --git a/queries/hydradx-ui/v1/stats/alltime/volume.sql b/queries/hydradx-ui/v1/stats/alltime/volume.sql index 1efe82c..e5911a7 100644 --- a/queries/hydradx-ui/v1/stats/alltime/volume.sql +++ b/queries/hydradx-ui/v1/stats/alltime/volume.sql @@ -4,7 +4,7 @@ SELECT CASE - WHEN :asset::text IS NOT NULL THEN + WHEN :asset::integer IS NOT NULL THEN round(SUM(volume_omnipool_roll_24_usd)) ELSE round(SUM(volume_omnipool_roll_24_usd)/2) @@ -22,8 +22,8 @@ FROM ( stats_historical WHERE CASE - WHEN :asset::text IS NOT NULL - THEN asset_id = :asset::integer + WHEN :asset::integer IS NOT NULL + THEN asset_id = :asset ELSE true END diff --git a/queries/hydradx-ui/v1/stats/current/tvl.sql b/queries/hydradx-ui/v1/stats/current/tvl.sql index 3ef46fc..687b6c4 100644 --- a/queries/hydradx-ui/v1/stats/current/tvl.sql +++ b/queries/hydradx-ui/v1/stats/current/tvl.sql @@ -16,8 +16,8 @@ FROM JOIN omnipool_asset oa ON leb.height = oa.block JOIN token_metadata tm ON oa.asset_id = tm.id WHERE CASE - WHEN :asset::text IS NOT NULL - THEN asset_id = :asset::integer + WHEN :asset::integer IS NOT NULL + THEN asset_id = :asset ELSE true END diff --git a/queries/hydradx-ui/v1/stats/current/volume.sql b/queries/hydradx-ui/v1/stats/current/volume.sql index 4a2409c..c09fe1e 100644 --- a/queries/hydradx-ui/v1/stats/current/volume.sql +++ b/queries/hydradx-ui/v1/stats/current/volume.sql @@ -4,7 +4,7 @@ SELECT CASE - WHEN :asset::text IS NOT NULL + WHEN :asset::integer IS NOT NULL THEN SUM(round(volume_roll_24_usd)) ELSE @@ -22,8 +22,8 @@ FROM ( stats_historical WHERE CASE - WHEN :asset::text IS NOT NULL - THEN asset_id = :asset::integer + WHEN :asset::integer IS NOT NULL + THEN asset_id = :asset ELSE true END diff --git a/queries/hydradx-ui/v1/stats/historical/tvl.sql b/queries/hydradx-ui/v1/stats/historical/tvl.sql index c93b953..25cd895 100644 --- a/queries/hydradx-ui/v1/stats/historical/tvl.sql +++ b/queries/hydradx-ui/v1/stats/historical/tvl.sql @@ -46,8 +46,8 @@ ordered_data AS ( WHERE src.rn = 1 AND CASE - WHEN :asset::text IS NOT NULL - THEN asset_id = :asset::integer + WHEN :asset::integer IS NOT NULL + THEN asset_id = :asset ELSE true END diff --git a/queries/hydradx-ui/v1/stats/historical/volume.sql b/queries/hydradx-ui/v1/stats/historical/volume.sql index 092319a..814eafc 100644 --- a/queries/hydradx-ui/v1/stats/historical/volume.sql +++ b/queries/hydradx-ui/v1/stats/historical/volume.sql @@ -12,7 +12,7 @@ WITH CombinedQuery AS ( SELECT timestamp::date as "timestamp", CASE - WHEN :asset::text IS NOT NULL + WHEN :asset::integer IS NOT NULL THEN round(sum(volume_usd)) ELSE round(sum(volume_usd)/2) @@ -24,8 +24,8 @@ WITH CombinedQuery AS ( timestamp between now() - interval '30d' and (current_date::timestamp) - interval '1 microsecond' AND CASE - WHEN :asset::text IS NOT NULL - THEN asset_id = :asset::integer + WHEN :asset::integer IS NOT NULL + THEN asset_id = :asset ELSE true END @@ -34,7 +34,7 @@ WITH CombinedQuery AS ( SELECT date_trunc('hour', timestamp) as "timestamp", CASE - WHEN :asset::text IS NOT NULL + WHEN :asset::integer IS NOT NULL THEN round(sum(volume_usd)) ELSE round(sum(volume_usd)/2) @@ -46,8 +46,8 @@ WITH CombinedQuery AS ( timestamp between now() - interval '24h' and date_trunc('hour', now()) - interval '1 microsecond' AND CASE - WHEN :asset::text IS NOT NULL - THEN asset_id = :asset::integer + WHEN :asset::integer IS NOT NULL + THEN asset_id = :asset ELSE true END diff --git a/variables.mjs b/variables.mjs index 4b90d70..c9c9b84 100644 --- a/variables.mjs +++ b/variables.mjs @@ -52,7 +52,7 @@ export const CACHE_SETTINGS = { }, hydradxUiV1StatsVolume: { key: "hydradx-ui_v1_stats_volume", - expire_after: 10 * 60, + expire_after: 60, }, hydradxUiV1StatsLrna: { key: "hydradx-ui_v1_stats_lrna", @@ -64,7 +64,7 @@ export const CACHE_SETTINGS = { }, hydradxUiV1StatsCurrentVolume: { key: "hydradx-ui_v1_stats_current_volume", - expire_after: 10 * 60, + expire_after: 60, }, hydradxUiV1StatsCurrentPrice: { key: "hydradx-ui_v1_stats_current_price", From 2aa9fae5100cadb1547086374dd2fbcc67eb8143 Mon Sep 17 00:00:00 2001 From: Valery Gantchev Date: Thu, 9 Nov 2023 23:50:53 +0100 Subject: [PATCH 3/7] move historical/ to charts/ --- .../v1/stats/{historical => charts}/lrna.mjs | 8 ++++---- .../v1/stats/{historical => charts}/tvl.mjs | 8 ++++---- .../v1/stats/{historical => charts}/volume.mjs | 8 ++++---- .../v1/stats/{historical => charts}/lrna.sql | 2 +- .../v1/stats/{historical => charts}/tvl.sql | 2 +- .../v1/stats/{historical => charts}/volume.sql | 2 +- variables.mjs | 12 ++++++++++-- 7 files changed, 25 insertions(+), 17 deletions(-) rename app/routes/hydradx-ui/v1/stats/{historical => charts}/lrna.mjs (82%) rename app/routes/hydradx-ui/v1/stats/{historical => charts}/tvl.mjs (83%) rename app/routes/hydradx-ui/v1/stats/{historical => charts}/volume.mjs (85%) rename queries/hydradx-ui/v1/stats/{historical => charts}/lrna.sql (99%) rename queries/hydradx-ui/v1/stats/{historical => charts}/tvl.sql (98%) rename queries/hydradx-ui/v1/stats/{historical => charts}/volume.sql (98%) diff --git a/app/routes/hydradx-ui/v1/stats/historical/lrna.mjs b/app/routes/hydradx-ui/v1/stats/charts/lrna.mjs similarity index 82% rename from app/routes/hydradx-ui/v1/stats/historical/lrna.mjs rename to app/routes/hydradx-ui/v1/stats/charts/lrna.mjs index 5a781ed..4532afe 100644 --- a/app/routes/hydradx-ui/v1/stats/historical/lrna.mjs +++ b/app/routes/hydradx-ui/v1/stats/charts/lrna.mjs @@ -6,7 +6,7 @@ import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; import { getAssets } from "../../../../../../helpers/asset_helpers.mjs"; const sqlQueries = yesql( - path.join(dirname(), "queries/hydradx-ui/v1/stats/historical"), + path.join(dirname(), "queries/hydradx-ui/v1/stats/charts"), { type: "pg", } @@ -17,7 +17,7 @@ export default async (fastify, opts) => { url: "/lrna", method: ["GET"], schema: { - description: "LRNA price & supply for the HydraDX stats page.", + description: "Chart data for LRNA price & supply.", tags: ["hydradx-ui/v1"], response: { 200: { @@ -37,9 +37,9 @@ export default async (fastify, opts) => { handler: async (request, reply) => { const asset = request.params.asset ? request.params.asset : null; - const sqlQuery = sqlQueries.statsLrna(); + const sqlQuery = sqlQueries.statsChartLrna(); - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsLrna"] }; + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsChartLrna"] }; const result = await cachedFetch( fastify.pg, diff --git a/app/routes/hydradx-ui/v1/stats/historical/tvl.mjs b/app/routes/hydradx-ui/v1/stats/charts/tvl.mjs similarity index 83% rename from app/routes/hydradx-ui/v1/stats/historical/tvl.mjs rename to app/routes/hydradx-ui/v1/stats/charts/tvl.mjs index 7af1837..7a6255f 100644 --- a/app/routes/hydradx-ui/v1/stats/historical/tvl.mjs +++ b/app/routes/hydradx-ui/v1/stats/charts/tvl.mjs @@ -6,7 +6,7 @@ import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; import { getAssets } from "../../../../../../helpers/asset_helpers.mjs"; const sqlQueries = yesql( - path.join(dirname(), "queries/hydradx-ui/v1/stats/historical"), + path.join(dirname(), "queries/hydradx-ui/v1/stats/charts"), { type: "pg", } @@ -17,7 +17,7 @@ export default async (fastify, opts) => { url: "/tvl/:asset?", method: ["GET"], schema: { - description: "Omnipool TVL for the HydraDX stats page.", + description: "Chart data for Omnipool TVL.", tags: ["hydradx-ui/v1"], params: { type: "object", @@ -45,9 +45,9 @@ export default async (fastify, opts) => { handler: async (request, reply) => { const asset = request.params.asset ? request.params.asset : null; - const sqlQuery = sqlQueries.statsHistoricalTvl({ asset }); + const sqlQuery = sqlQueries.statsChartTvl({ asset }); - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1statsHistoricalTvl"] }; + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1statsChartTvl"] }; cacheSetting.key = cacheSetting.key + "_" + asset; const result = await cachedFetch( diff --git a/app/routes/hydradx-ui/v1/stats/historical/volume.mjs b/app/routes/hydradx-ui/v1/stats/charts/volume.mjs similarity index 85% rename from app/routes/hydradx-ui/v1/stats/historical/volume.mjs rename to app/routes/hydradx-ui/v1/stats/charts/volume.mjs index a3ffcc0..ba602cd 100644 --- a/app/routes/hydradx-ui/v1/stats/historical/volume.mjs +++ b/app/routes/hydradx-ui/v1/stats/charts/volume.mjs @@ -5,7 +5,7 @@ import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; const sqlQueries = yesql( - path.join(dirname(), "queries/hydradx-ui/v1/stats/historical"), + path.join(dirname(), "queries/hydradx-ui/v1/stats/charts"), { type: "pg", } @@ -18,7 +18,7 @@ export default async (fastify, opts) => { url: "/volume/:asset?", method: ["GET"], schema: { - description: "Omnipool trading volume for the HydraDX stats page.", + description: "Chart data for Omnipool trading volume.", tags: ["hydradx-ui/v1"], params: { type: "object", @@ -57,10 +57,10 @@ export default async (fastify, opts) => { const asset = request.params.asset ? request.params.asset : null; const timeframe = request.query.timeframe; - const sqlQuery = sqlQueries.statsHistoricalVolume({ asset, timeframe }); + const sqlQuery = sqlQueries.statsChartVolume({ asset, timeframe }); let cacheSetting = { - ...CACHE_SETTINGS["hydradxUiV1statsHistoricalVolume"], + ...CACHE_SETTINGS["hydradxUiV1statsChartVolume"], }; cacheSetting.key = cacheSetting.key + "_" + asset + "_" + timeframe; diff --git a/queries/hydradx-ui/v1/stats/historical/lrna.sql b/queries/hydradx-ui/v1/stats/charts/lrna.sql similarity index 99% rename from queries/hydradx-ui/v1/stats/historical/lrna.sql rename to queries/hydradx-ui/v1/stats/charts/lrna.sql index fc0915d..6b01c90 100644 --- a/queries/hydradx-ui/v1/stats/historical/lrna.sql +++ b/queries/hydradx-ui/v1/stats/charts/lrna.sql @@ -1,4 +1,4 @@ --- statsLrna +-- statsChartLrna /* Returns 60 rows with all time historical LRNA price in USD */ diff --git a/queries/hydradx-ui/v1/stats/historical/tvl.sql b/queries/hydradx-ui/v1/stats/charts/tvl.sql similarity index 98% rename from queries/hydradx-ui/v1/stats/historical/tvl.sql rename to queries/hydradx-ui/v1/stats/charts/tvl.sql index 25cd895..4c030bd 100644 --- a/queries/hydradx-ui/v1/stats/historical/tvl.sql +++ b/queries/hydradx-ui/v1/stats/charts/tvl.sql @@ -1,4 +1,4 @@ --- statsHistoricalTvl +-- statsChartTvl /* Returns 60 rows with all time TVL in USD */ diff --git a/queries/hydradx-ui/v1/stats/historical/volume.sql b/queries/hydradx-ui/v1/stats/charts/volume.sql similarity index 98% rename from queries/hydradx-ui/v1/stats/historical/volume.sql rename to queries/hydradx-ui/v1/stats/charts/volume.sql index 814eafc..31aea3a 100644 --- a/queries/hydradx-ui/v1/stats/historical/volume.sql +++ b/queries/hydradx-ui/v1/stats/charts/volume.sql @@ -1,4 +1,4 @@ --- statsHistoricalVolume +-- statsChartVolume /* :timeframe = hourly diff --git a/variables.mjs b/variables.mjs index c9c9b84..06c6a66 100644 --- a/variables.mjs +++ b/variables.mjs @@ -54,8 +54,16 @@ export const CACHE_SETTINGS = { key: "hydradx-ui_v1_stats_volume", expire_after: 60, }, - hydradxUiV1StatsLrna: { - key: "hydradx-ui_v1_stats_lrna", + hydradxUiV1StatsChartLrna: { + key: "hydradx-ui_v1_stats_chart_lrna", + expire_after: 10 * 60, + }, + hydradxUiV1statsChartTvl: { + key: "hydradx-ui_v1_stats_chart_tvl", + expire_after: 10 * 60, + }, + hydradxUiV1statsChartVolume: { + key: "hydradx-ui_v1_stats_chart_volume", expire_after: 10 * 60, }, hydradxUiV1StatsCurrentTvl: { From 694545bf78aaebbb2c2ea6da43f98ea387e35eb0 Mon Sep 17 00:00:00 2001 From: Valery Gantchev Date: Fri, 10 Nov 2023 00:05:05 +0100 Subject: [PATCH 4/7] move current/ to root --- .../v1/stats/{current => }/price.mjs | 21 ++++++++----------- .../hydradx-ui/v1/stats/{current => }/tvl.mjs | 19 +++++++---------- .../v1/stats/{current => }/volume.mjs | 19 +++++++---------- .../v1/stats/{current => }/price.sql | 2 +- .../hydradx-ui/v1/stats/{current => }/tvl.sql | 2 +- .../v1/stats/{current => }/volume.sql | 2 +- variables.mjs | 14 +++++-------- 7 files changed, 33 insertions(+), 46 deletions(-) rename app/routes/hydradx-ui/v1/stats/{current => }/price.mjs (66%) rename app/routes/hydradx-ui/v1/stats/{current => }/tvl.mjs (70%) rename app/routes/hydradx-ui/v1/stats/{current => }/volume.mjs (70%) rename queries/hydradx-ui/v1/stats/{current => }/price.sql (92%) rename queries/hydradx-ui/v1/stats/{current => }/tvl.sql (97%) rename queries/hydradx-ui/v1/stats/{current => }/volume.sql (95%) diff --git a/app/routes/hydradx-ui/v1/stats/current/price.mjs b/app/routes/hydradx-ui/v1/stats/price.mjs similarity index 66% rename from app/routes/hydradx-ui/v1/stats/current/price.mjs rename to app/routes/hydradx-ui/v1/stats/price.mjs index e08901a..6f8d0b9 100644 --- a/app/routes/hydradx-ui/v1/stats/current/price.mjs +++ b/app/routes/hydradx-ui/v1/stats/price.mjs @@ -1,16 +1,13 @@ import yesql from "yesql"; import path from "path"; -import { dirname } from "../../../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; -import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; -import { getAssets } from "../../../../../../helpers/asset_helpers.mjs"; +import { dirname } from "../../../../../variables.mjs"; +import { CACHE_SETTINGS } from "../../../../../variables.mjs"; +import { cachedFetch } from "../../../../../helpers/cache_helpers.mjs"; +import { getAssets } from "../../../../../helpers/asset_helpers.mjs"; -const sqlQueries = yesql( - path.join(dirname(), "queries/hydradx-ui/v1/stats/current"), - { - type: "pg", - } -); +const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), { + type: "pg", +}); export default async (fastify, opts) => { fastify.route({ @@ -44,9 +41,9 @@ export default async (fastify, opts) => { handler: async (request, reply) => { const asset = request.params.asset ? request.params.asset : null; - const sqlQuery = sqlQueries.statsCurrentPrice({ asset }); + const sqlQuery = sqlQueries.statsPrice({ asset }); - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsCurrentPrice"] }; + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsPrice"] }; cacheSetting.key = cacheSetting.key + "_" + asset; const result = await cachedFetch( diff --git a/app/routes/hydradx-ui/v1/stats/current/tvl.mjs b/app/routes/hydradx-ui/v1/stats/tvl.mjs similarity index 70% rename from app/routes/hydradx-ui/v1/stats/current/tvl.mjs rename to app/routes/hydradx-ui/v1/stats/tvl.mjs index 9a5f708..e5fd90e 100644 --- a/app/routes/hydradx-ui/v1/stats/current/tvl.mjs +++ b/app/routes/hydradx-ui/v1/stats/tvl.mjs @@ -1,15 +1,12 @@ import yesql from "yesql"; import path from "path"; -import { dirname } from "../../../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; -import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; +import { dirname } from "../../../../../variables.mjs"; +import { CACHE_SETTINGS } from "../../../../../variables.mjs"; +import { cachedFetch } from "../../../../../helpers/cache_helpers.mjs"; -const sqlQueries = yesql( - path.join(dirname(), "queries/hydradx-ui/v1/stats/current"), - { - type: "pg", - } -); +const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), { + type: "pg", +}); export default async (fastify, opts) => { fastify.route({ @@ -43,9 +40,9 @@ export default async (fastify, opts) => { handler: async (request, reply) => { const asset = request.params.asset ? request.params.asset : null; - const sqlQuery = sqlQueries.statsCurrentTvl({ asset }); + const sqlQuery = sqlQueries.statsTvl({ asset }); - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsCurrentTvl"] }; + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsTvl"] }; cacheSetting.key = cacheSetting.key + "_" + asset; const result = await cachedFetch( diff --git a/app/routes/hydradx-ui/v1/stats/current/volume.mjs b/app/routes/hydradx-ui/v1/stats/volume.mjs similarity index 70% rename from app/routes/hydradx-ui/v1/stats/current/volume.mjs rename to app/routes/hydradx-ui/v1/stats/volume.mjs index fe0c303..b742e61 100644 --- a/app/routes/hydradx-ui/v1/stats/current/volume.mjs +++ b/app/routes/hydradx-ui/v1/stats/volume.mjs @@ -1,15 +1,12 @@ import yesql from "yesql"; import path from "path"; -import { dirname } from "../../../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; -import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; +import { dirname } from "../../../../../variables.mjs"; +import { CACHE_SETTINGS } from "../../../../../variables.mjs"; +import { cachedFetch } from "../../../../../helpers/cache_helpers.mjs"; -const sqlQueries = yesql( - path.join(dirname(), "queries/hydradx-ui/v1/stats/current"), - { - type: "pg", - } -); +const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), { + type: "pg", +}); export default async (fastify, opts) => { fastify.route({ @@ -43,9 +40,9 @@ export default async (fastify, opts) => { handler: async (request, reply) => { const asset = request.params.asset ? request.params.asset : null; - const sqlQuery = sqlQueries.statsCurrentVolume({ asset }); + const sqlQuery = sqlQueries.statsVolume({ asset }); - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsCurrentVolume"] }; + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsVolume"] }; cacheSetting.key = cacheSetting.key + "_" + asset; const result = await cachedFetch( diff --git a/queries/hydradx-ui/v1/stats/current/price.sql b/queries/hydradx-ui/v1/stats/price.sql similarity index 92% rename from queries/hydradx-ui/v1/stats/current/price.sql rename to queries/hydradx-ui/v1/stats/price.sql index ef690b5..188a428 100644 --- a/queries/hydradx-ui/v1/stats/current/price.sql +++ b/queries/hydradx-ui/v1/stats/price.sql @@ -1,4 +1,4 @@ --- statsCurrentPrice +-- statsPrice /* Returns current asset price */ diff --git a/queries/hydradx-ui/v1/stats/current/tvl.sql b/queries/hydradx-ui/v1/stats/tvl.sql similarity index 97% rename from queries/hydradx-ui/v1/stats/current/tvl.sql rename to queries/hydradx-ui/v1/stats/tvl.sql index 687b6c4..f4aa6ed 100644 --- a/queries/hydradx-ui/v1/stats/current/tvl.sql +++ b/queries/hydradx-ui/v1/stats/tvl.sql @@ -1,4 +1,4 @@ --- statsCurrentTvl +-- statsTvl /* Returns actual TVL */ diff --git a/queries/hydradx-ui/v1/stats/current/volume.sql b/queries/hydradx-ui/v1/stats/volume.sql similarity index 95% rename from queries/hydradx-ui/v1/stats/current/volume.sql rename to queries/hydradx-ui/v1/stats/volume.sql index c09fe1e..96b9102 100644 --- a/queries/hydradx-ui/v1/stats/current/volume.sql +++ b/queries/hydradx-ui/v1/stats/volume.sql @@ -1,4 +1,4 @@ --- statsCurrentVolume +-- statsVolume /* Returns actual 24h rolling volume */ diff --git a/variables.mjs b/variables.mjs index 06c6a66..b7a1bfa 100644 --- a/variables.mjs +++ b/variables.mjs @@ -50,10 +50,6 @@ export const CACHE_SETTINGS = { key: "hydradx-ui_v1_stats_tvl", expire_after: 60 * 60, }, - hydradxUiV1StatsVolume: { - key: "hydradx-ui_v1_stats_volume", - expire_after: 60, - }, hydradxUiV1StatsChartLrna: { key: "hydradx-ui_v1_stats_chart_lrna", expire_after: 10 * 60, @@ -66,15 +62,15 @@ export const CACHE_SETTINGS = { key: "hydradx-ui_v1_stats_chart_volume", expire_after: 10 * 60, }, - hydradxUiV1StatsCurrentTvl: { - key: "hydradx-ui_v1_stats_tvl_current", + hydradxUiV1StatsTvl: { + key: "hydradx-ui_v1_stats_tvl", expire_after: 10 * 60, }, - hydradxUiV1StatsCurrentVolume: { - key: "hydradx-ui_v1_stats_current_volume", + hydradxUiV1StatsVolume: { + key: "hydradx-ui_v1_stats_volume", expire_after: 60, }, - hydradxUiV1StatsCurrentPrice: { + hydradxUiV1StatsPrice: { key: "hydradx-ui_v1_stats_current_price", expire_after: 60, }, From ba73931b31bd61f742460882a298b9fec30c3099 Mon Sep 17 00:00:00 2001 From: Valery Gantchev Date: Fri, 10 Nov 2023 00:14:31 +0100 Subject: [PATCH 5/7] move volume_alltime to volume --- .../hydradx-ui/v1/stats/alltime/volume.mjs | 61 ------------------- app/routes/hydradx-ui/v1/stats/volume.mjs | 48 +++++++++++++++ .../volume.sql => volume_alltime.sql} | 2 +- variables.mjs | 4 ++ 4 files changed, 53 insertions(+), 62 deletions(-) delete mode 100644 app/routes/hydradx-ui/v1/stats/alltime/volume.mjs rename queries/hydradx-ui/v1/stats/{alltime/volume.sql => volume_alltime.sql} (96%) diff --git a/app/routes/hydradx-ui/v1/stats/alltime/volume.mjs b/app/routes/hydradx-ui/v1/stats/alltime/volume.mjs deleted file mode 100644 index d992ea3..0000000 --- a/app/routes/hydradx-ui/v1/stats/alltime/volume.mjs +++ /dev/null @@ -1,61 +0,0 @@ -import yesql from "yesql"; -import path from "path"; -import { dirname } from "../../../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../../../variables.mjs"; -import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs"; - -const sqlQueries = yesql( - path.join(dirname(), "queries/hydradx-ui/v1/stats/alltime"), - { - type: "pg", - } -); - -export default async (fastify, opts) => { - fastify.route({ - url: "/volume/:asset?", - method: ["GET"], - schema: { - description: "All time trading volume.", - tags: ["hydradx-ui/v1"], - params: { - type: "object", - properties: { - asset: { - type: "integer", - description: "Asset (id). Leave empty for all assets.", - }, - }, - }, - response: { - 200: { - description: "Success Response", - type: "array", - items: { - type: "object", - properties: { - volume_usd: { type: "number" }, - }, - }, - }, - }, - }, - handler: async (request, reply) => { - const asset = request.params.asset ? request.params.asset : null; - - const sqlQuery = sqlQueries.statsAlltimeVolume({ asset }); - - let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1statsAlltimeVolume"] }; - cacheSetting.key = cacheSetting.key + "_" + asset; - - const result = await cachedFetch( - fastify.pg, - fastify.redis, - cacheSetting, - sqlQuery - ); - - reply.send(JSON.parse(result)); - }, - }); -}; diff --git a/app/routes/hydradx-ui/v1/stats/volume.mjs b/app/routes/hydradx-ui/v1/stats/volume.mjs index b742e61..cab0bdd 100644 --- a/app/routes/hydradx-ui/v1/stats/volume.mjs +++ b/app/routes/hydradx-ui/v1/stats/volume.mjs @@ -55,4 +55,52 @@ export default async (fastify, opts) => { reply.send(JSON.parse(result)); }, }); + + fastify.route({ + url: "/volume/alltime/:asset?", + method: ["GET"], + schema: { + description: "All time trading volume.", + tags: ["hydradx-ui/v1"], + params: { + type: "object", + properties: { + asset: { + type: "integer", + description: "Asset (id). Leave empty for all assets.", + }, + }, + }, + response: { + 200: { + description: "Success Response", + type: "array", + items: { + type: "object", + properties: { + volume_usd: { type: "number" }, + }, + }, + }, + }, + }, + handler: async (request, reply) => { + const asset = request.params.asset ? request.params.asset : null; + + const sqlQuery = sqlQueries.statsVolumeAlltime({ asset }); + + let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1statsVolumeAlltime"] }; + cacheSetting.key = cacheSetting.key + "_" + asset; + + const result = await cachedFetch( + fastify.pg, + fastify.redis, + cacheSetting, + sqlQuery + ); + + reply.send(JSON.parse(result)); + }, + }); }; + diff --git a/queries/hydradx-ui/v1/stats/alltime/volume.sql b/queries/hydradx-ui/v1/stats/volume_alltime.sql similarity index 96% rename from queries/hydradx-ui/v1/stats/alltime/volume.sql rename to queries/hydradx-ui/v1/stats/volume_alltime.sql index e5911a7..fe81c26 100644 --- a/queries/hydradx-ui/v1/stats/alltime/volume.sql +++ b/queries/hydradx-ui/v1/stats/volume_alltime.sql @@ -1,4 +1,4 @@ --- statsAlltimeVolume +-- statsVolumeAlltime /* Returns all time volume */ diff --git a/variables.mjs b/variables.mjs index b7a1bfa..5391cf8 100644 --- a/variables.mjs +++ b/variables.mjs @@ -70,6 +70,10 @@ export const CACHE_SETTINGS = { key: "hydradx-ui_v1_stats_volume", expire_after: 60, }, + hydradxUiV1statsVolumeAlltime: { + key: "hydradx-ui_v1_stats_volume_alltime", + expire_after: 60, + }, hydradxUiV1StatsPrice: { key: "hydradx-ui_v1_stats_current_price", expire_after: 60, From 923ea3fd240317bdf1b8f84b29b2aa9c4d9ce044 Mon Sep 17 00:00:00 2001 From: green-jay Date: Mon, 13 Nov 2023 09:14:06 +0100 Subject: [PATCH 6/7] remove defillama tvl --- app/routes/defillama/v1/tvl.mjs | 58 ----------------------- app/routes/hydradx-ui/v1/stats/volume.mjs | 1 - queries/defillama/v1/tvl.sql | 23 --------- queries/defillama/v1/volume.sql | 2 +- variables.mjs | 4 -- 5 files changed, 1 insertion(+), 87 deletions(-) delete mode 100644 app/routes/defillama/v1/tvl.mjs delete mode 100644 queries/defillama/v1/tvl.sql diff --git a/app/routes/defillama/v1/tvl.mjs b/app/routes/defillama/v1/tvl.mjs deleted file mode 100644 index 7970010..0000000 --- a/app/routes/defillama/v1/tvl.mjs +++ /dev/null @@ -1,58 +0,0 @@ -import yesql from "yesql"; -import path from "path"; -import { dirname } from "../../../../variables.mjs"; -import { CACHE_SETTINGS } from "../../../../variables.mjs"; -import { cachedFetch } from "../../../../helpers/cache_helpers.mjs"; - -const sqlQueries = yesql(path.join(dirname(), "queries/defillama/v1/"), { - type: "pg", -}); - -export default async (fastify, opts) => { - fastify.route({ - url: "/tvl/:asset?", - method: ["GET"], - schema: { - description: "Current Omnipool TVL for DefiLlama.", - tags: ["defillama/v1"], - params: { - type: "object", - properties: { - asset: { - type: "string", - description: "Asset (symbol). Leave empty for all assets.", - }, - }, - }, - response: { - 200: { - description: "Success Response", - type: "array", - items: { - type: "object", - properties: { - tvl_usd: { type: "number" }, - }, - }, - }, - }, - }, - handler: async (request, reply) => { - const asset = request.params.asset ? request.params.asset : null; - - const sqlQuery = sqlQueries.defillamaTvl({ asset }); - - let cacheSetting = { ...CACHE_SETTINGS["defillamaV1Tvl"] }; - cacheSetting.key = cacheSetting.key + "_" + asset; - - const result = await cachedFetch( - fastify.pg, - fastify.redis, - cacheSetting, - sqlQuery - ); - - reply.send(JSON.parse(result)); - }, - }); -}; diff --git a/app/routes/hydradx-ui/v1/stats/volume.mjs b/app/routes/hydradx-ui/v1/stats/volume.mjs index cab0bdd..726e3be 100644 --- a/app/routes/hydradx-ui/v1/stats/volume.mjs +++ b/app/routes/hydradx-ui/v1/stats/volume.mjs @@ -103,4 +103,3 @@ export default async (fastify, opts) => { }, }); }; - diff --git a/queries/defillama/v1/tvl.sql b/queries/defillama/v1/tvl.sql deleted file mode 100644 index d0268a7..0000000 --- a/queries/defillama/v1/tvl.sql +++ /dev/null @@ -1,23 +0,0 @@ --- defillamaTvl - -/* Returns actual TVL */ - -SELECT - round(sum(oa.hub_reserve/10^12 * leb.last_lrna_price)) as tvl_usd -FROM - lrna_every_block leb - JOIN ( - SELECT - LEAST(max_leb.max_height, max_oa.max_block) AS joined_height - FROM - (SELECT MAX(height) as max_height FROM lrna_every_block) max_leb, - (SELECT MAX(block) as max_block FROM omnipool_asset) max_oa - ) subq ON leb.height = subq.joined_height - JOIN omnipool_asset oa ON leb.height = oa.block - JOIN token_metadata tm ON oa.asset_id = tm.id -WHERE CASE - WHEN :asset::integer IS NOT NULL - THEN symbol = :asset - ELSE - true - END diff --git a/queries/defillama/v1/volume.sql b/queries/defillama/v1/volume.sql index 7fa5980..de29e23 100644 --- a/queries/defillama/v1/volume.sql +++ b/queries/defillama/v1/volume.sql @@ -22,7 +22,7 @@ FROM ( stats_historical WHERE CASE - WHEN :asset::integer IS NOT NULL + WHEN :asset::text IS NOT NULL THEN symbol = :asset ELSE true diff --git a/variables.mjs b/variables.mjs index 5391cf8..cc3eb68 100644 --- a/variables.mjs +++ b/variables.mjs @@ -78,10 +78,6 @@ export const CACHE_SETTINGS = { key: "hydradx-ui_v1_stats_current_price", expire_after: 60, }, - defillamaV1Tvl: { - key: "defillama_v1_tvl", - expire_after: 10 * 60, - }, defillamaV1Volume: { key: "defillama_v1_volume", expire_after: 10 * 60, From add14f5b2ebe599d6d831a0f667ad6514893ab96 Mon Sep 17 00:00:00 2001 From: green-jay Date: Tue, 14 Nov 2023 15:22:56 +0100 Subject: [PATCH 7/7] revert defillama asset type --- queries/defillama/v1/volume.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/defillama/v1/volume.sql b/queries/defillama/v1/volume.sql index de29e23..022f48d 100644 --- a/queries/defillama/v1/volume.sql +++ b/queries/defillama/v1/volume.sql @@ -4,7 +4,7 @@ SELECT CASE - WHEN :asset::integer IS NOT NULL + WHEN :asset::text IS NOT NULL THEN SUM(round(volume_roll_24_usd)) ELSE