Skip to content

Commit ad847d9

Browse files
committed
fix tvl
1 parent 7d738f7 commit ad847d9

1 file changed

Lines changed: 17 additions & 33 deletions

File tree

app/routes/hydration-web/v1/stats.mjs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { gql, request as gqlRequest } from "graphql-request";
2-
import { ApiPromise, WsProvider } from "@polkadot/api";
32

4-
const DECIMALS_ENDPOINT = "https://hydration.dipdup.net/api/rest/asset?id=";
53
const SPOT_PRICE_ENDPOINT =
64
"https://galacticcouncil.squids.live/hydration-pools:whale-prod/api/graphql";
75
const UNIFIED_GRAPHQL_ENDPOINT =
86
"https://galacticcouncil.squids.live/hydration-pools:unified-prod/api/graphql";
9-
const RPC_ENDPOINT = "wss://hydration-rpc.n.dwellir.com";
107
const XCM_API_ENDPOINT = "https://dev-api.ocelloids.net/query/xcm";
8+
const DECIMALS_ENDPOINT = "https://hydration.dipdup.net/api/rest/asset?id=";
119

1210
export default async (fastify, opts) => {
1311
fastify.route({
@@ -39,6 +37,7 @@ export default async (fastify, opts) => {
3937
xykPoolsData,
4038
stableAssetsData,
4139
accountsData,
40+
tvlData,
4241
] = await Promise.all([
4342
gqlRequest(
4443
UNIFIED_GRAPHQL_ENDPOINT,
@@ -88,6 +87,18 @@ export default async (fastify, opts) => {
8887
}
8988
`
9089
),
90+
gqlRequest(
91+
SPOT_PRICE_ENDPOINT,
92+
gql`
93+
{
94+
platformTotalTvl {
95+
nodes {
96+
totalTvlDecoratedNorm
97+
}
98+
}
99+
}
100+
`
101+
),
91102
]);
92103

93104
const omnipoolIds = new Set(
@@ -243,38 +254,11 @@ export default async (fastify, opts) => {
243254
request.log.warn("Failed to fetch xcm volume", e);
244255
}
245256

246-
const provider = new WsProvider(RPC_ENDPOINT);
247-
const api = await ApiPromise.create({ provider });
248-
249-
let tvl = 0;
250-
for (const assetId of priceMap.keys()) {
251-
try {
252-
const decimalRes = await fetch(`${DECIMALS_ENDPOINT}${assetId}`);
253-
const decimalJson = await decimalRes.json();
254-
const decimals = decimalJson.asset?.decimals;
255-
if (decimals == null) continue;
256-
257-
let issuance;
258-
if (assetId === "0") {
259-
issuance = await api.query.balances.totalIssuance();
260-
} else {
261-
issuance = await api.query.tokens.totalIssuance(assetId);
262-
}
263-
264-
const issuanceFloat = Number(issuance.toBigInt()) / 10 ** decimals;
265-
const tvlUsd = issuanceFloat * priceMap.get(assetId);
266-
if (assetId !== "1") tvl += tvlUsd;
267-
} catch (e) {
268-
request.log.warn(
269-
`TVL computation failed for asset ${assetId}: ${e.message}`
270-
);
271-
}
272-
}
273-
274-
await api.disconnect();
257+
// Get TVL from the new GraphQL query
258+
const tvl = tvlData.platformTotalTvl.nodes[0]?.totalTvlDecoratedNorm || 0;
275259

276260
const result = {
277-
tvl: Number(tvl.toFixed(12)),
261+
tvl: Number(tvl),
278262
vol_30d: Number(vol30d.toFixed(12)),
279263
xcm_vol_30d: Number(xcmVol30d.toFixed(12)),
280264
assets_count: assetsCount,

0 commit comments

Comments
 (0)