From 47371295b57472956bee958942469ddddc461bce Mon Sep 17 00:00:00 2001 From: Ignacio Date: Fri, 5 Jan 2024 15:45:18 +0800 Subject: [PATCH] fix: tvl value --- src/graphql/routes/oasis-api.ts | 2 +- src/graphql/routes/radix-api.ts | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/graphql/routes/oasis-api.ts b/src/graphql/routes/oasis-api.ts index 9aacdb1..758fbc5 100644 --- a/src/graphql/routes/oasis-api.ts +++ b/src/graphql/routes/oasis-api.ts @@ -36,7 +36,7 @@ export class OasisAPI extends RESTDataSource { async getOasisTVL() { // @hardcoded - const base = 932608; + const base = 57_164_450.3; const price = await this.gecko.getCoinPrice("rose"); return [ diff --git a/src/graphql/routes/radix-api.ts b/src/graphql/routes/radix-api.ts index 9239d60..273ea33 100644 --- a/src/graphql/routes/radix-api.ts +++ b/src/graphql/routes/radix-api.ts @@ -92,11 +92,24 @@ export class RadixAPI extends RESTDataSource { } async getRadixTVL() { - // @hardcoded - const tokens = 57_164_450.3; - const coinPrice = await this.gecko.getCoinPrice("radix"); + const [radixResponse, coinPrice] = await Promise.all([ + this.gateway.getValidator(), + this.gecko.getCoinPrice("radix"), + ]); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const validator = radixResponse.validators.items.find((i: any) => + (i.address as string).includes(radixValidatorAddress), + ); + + if (!validator) { + return { + status: "error", + }; + } - const TVL = tokens * Number(coinPrice); + const lockedUnit = Number(validator.locked_owner_stake_unit_vault.balance); + const TVL = lockedUnit * Number(coinPrice); if (Number.isNaN(TVL)) { return {