-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from galacticcouncil/add-stats-queries
New endpoints for hydradx-ui/stats and defillama
- Loading branch information
Showing
25 changed files
with
624 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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)); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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: "/volume/:asset?", | ||
method: ["GET"], | ||
schema: { | ||
description: "Current 24h rolling trading volume 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: { | ||
volume_usd: { type: "number" }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
handler: async (request, reply) => { | ||
const asset = request.params.asset ? request.params.asset : null; | ||
|
||
const sqlQuery = sqlQueries.defillamaVolume({ asset }); | ||
|
||
let cacheSetting = { ...CACHE_SETTINGS["defillamaV1Volume"] }; | ||
cacheSetting.key = cacheSetting.key + "_" + asset; | ||
|
||
const result = await cachedFetch( | ||
fastify.pg, | ||
fastify.redis, | ||
cacheSetting, | ||
sqlQuery | ||
); | ||
|
||
reply.send(JSON.parse(result)); | ||
}, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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"; | ||
|
||
const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), { | ||
type: "pg", | ||
}); | ||
|
||
export default async (fastify, opts) => { | ||
fastify.route({ | ||
url: "/tvl/:asset?", | ||
method: ["GET"], | ||
schema: { | ||
description: "Omnipool TVL for the HydraDX stats page.", | ||
tags: ["hydradx-ui/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: { | ||
interval: { type: "string" }, | ||
tvl_usd: { type: "number" }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
handler: async (request, reply) => { | ||
const asset = request.params.asset ? request.params.asset : null; | ||
|
||
const sqlQuery = sqlQueries.statsTvl({ asset }); | ||
|
||
let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsTvl"] }; | ||
cacheSetting.key = cacheSetting.key + "_" + asset; | ||
|
||
const result = await cachedFetch( | ||
fastify.pg, | ||
fastify.redis, | ||
cacheSetting, | ||
sqlQuery | ||
); | ||
|
||
reply.send(JSON.parse(result)); | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.