From ecd132fcf057a866d32aeed19003286f323ebda8 Mon Sep 17 00:00:00 2001 From: Ignacio Date: Thu, 4 Jan 2024 13:53:26 +0800 Subject: [PATCH] feat: update oasis values --- src/graphql/resolvers/index.ts | 18 ++++-------- src/graphql/routes/oasis-api.ts | 49 +++++++++++++++++++++++++++------ src/graphql/routes/radix-api.ts | 1 + src/graphql/routes/sui-api.ts | 1 + src/graphql/utils/addresses.ts | 4 ++- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/graphql/resolvers/index.ts b/src/graphql/resolvers/index.ts index 9c6eabe..86c7b90 100644 --- a/src/graphql/resolvers/index.ts +++ b/src/graphql/resolvers/index.ts @@ -300,14 +300,12 @@ export const resolvers = { oasisBondedToken: async (...params: unknown[]) => { const { dataSources } = params[2] as ContextValue; - const result = commonHandler( - (await dataSources.oasisAPI.getOasisBondedToken()) as Response, - ); + const result = await dataSources.oasisAPI.getOasisBondedToken(); if (!result) return; return result.map((res) => ({ - bondedToken: res.value[1], + bondedToken: res.value, metric: { instance: "oasis", validator_address: res.metric.identity }, })); }, @@ -328,29 +326,25 @@ export const resolvers = { oasisTVL: async (...params: unknown[]) => { const { dataSources } = params[2] as ContextValue; - const result = commonHandler( - (await dataSources.oasisAPI.getOasisTVL()) as Response, - ); + const result = await dataSources.oasisAPI.getOasisTVL(); if (!result) return; return result.map((res) => ({ metric: { instance: "oasis" }, - TVL: res.value[1], + TVL: res.value, })); }, oasisUsers: async (...params: unknown[]) => { const { dataSources } = params[2] as ContextValue; - const result = commonHandler( - (await dataSources.oasisAPI.getOasisUsers()) as Response, - ); + const result = await dataSources.oasisAPI.getOasisUsers(); if (!result) return; return result.map((res) => ({ metric: { instance: "oasis", validator_address: res.metric.identity }, - usersCount: res.value[1], + usersCount: res.value, })); }, radixAPY: async (...params: unknown[]) => { diff --git a/src/graphql/routes/oasis-api.ts b/src/graphql/routes/oasis-api.ts index c2acd8a..9aacdb1 100644 --- a/src/graphql/routes/oasis-api.ts +++ b/src/graphql/routes/oasis-api.ts @@ -1,12 +1,31 @@ +import type { DataSourceConfig } from "@apollo/datasource-rest"; import { RESTDataSource } from "@apollo/datasource-rest"; +import { oasisValidatorAddress } from "../utils/addresses"; +import { CoinGeckoDataSource } from "../utils/coingecko-data"; + +// https://www.oasisscan.com/validators/detail/oasis1qrtq873ddwnnjqyv66ezdc9ql2a07l37d5vae9k0 + export class OasisAPI extends RESTDataSource { override baseURL = `${process.env.PROM_QUERY_URL}/prometheus/api/v1/`; + private gecko: CoinGeckoDataSource; + + constructor(options: DataSourceConfig) { + super(options); + + this.gecko = new CoinGeckoDataSource(options); + } async getOasisBondedToken() { - return this.get( - `query?query=max_over_time(oasis_validator_staked[${process.env.MAX_OVER_TIME_DURATION}])`, - ); + return [ + { + metric: { + identity: oasisValidatorAddress, + }, + // @hardcoded + value: 57163716.09, + }, + ]; } async getOasisCommission() { @@ -16,14 +35,26 @@ export class OasisAPI extends RESTDataSource { } async getOasisTVL() { - return this.get( - `query?query=max_over_time(oasis_validator_staked{}[${process.env.MAX_OVER_TIME_DURATION}]) * on (denom) group_left token_price`, - ); + // @hardcoded + const base = 932608; + const price = await this.gecko.getCoinPrice("rose"); + + return [ + { + value: base * price, + }, + ]; } async getOasisUsers() { - return this.get( - `query?query=max_over_time(oasis_validator_delegators_total[${process.env.MAX_OVER_TIME_DURATION}])`, - ); + return [ + { + metric: { + identity: oasisValidatorAddress, + }, + // @hardcoded + value: 137, + }, + ]; } } diff --git a/src/graphql/routes/radix-api.ts b/src/graphql/routes/radix-api.ts index 1667be9..273ea33 100644 --- a/src/graphql/routes/radix-api.ts +++ b/src/graphql/routes/radix-api.ts @@ -54,6 +54,7 @@ export class RadixAPI extends RESTDataSource { async getRadixAPY() { // https://dashboard.radixdlt.com/network-staking/validator_rdx1swkmn6yvrqjzpaytvug5fp0gzfy9zdzq7j7nlxe8wgjpg76vdcma8p + // @hardcoded const APY = 0.0783; return { diff --git a/src/graphql/routes/sui-api.ts b/src/graphql/routes/sui-api.ts index 2a78338..bad3c90 100644 --- a/src/graphql/routes/sui-api.ts +++ b/src/graphql/routes/sui-api.ts @@ -11,6 +11,7 @@ if (!process.env.DEVTOOLS_API_KEY) { const coinDecimals = 9; // https://docs.sui.io/ +// https://suiexplorer.com/validator/0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059 export class SuiAPI extends RESTDataSource { override baseURL = `https://rpc-mainnet-sui.forbole.com`; private gecko: CoinGeckoDataSource; diff --git a/src/graphql/utils/addresses.ts b/src/graphql/utils/addresses.ts index dcb826e..d038147 100644 --- a/src/graphql/utils/addresses.ts +++ b/src/graphql/utils/addresses.ts @@ -4,6 +4,8 @@ export const archwayValidatorAddress = export const radixValidatorAddress = "validator_rdx1swkmn6yvrqjzpaytvug5fp0gzfy9zdzq7j7nlxe8wgjpg76vdcma8p"; -// https://suiexplorer.com/validator/0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059 export const suiValidatorAddress = "0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059"; + +export const oasisValidatorAddress = + "oasis1qrtq873ddwnnjqyv66ezdc9ql2a07l37d5vae9k0";