Skip to content

Commit

Permalink
feat: update oasis values
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Jan 4, 2024
1 parent 90f8ceb commit ecd132f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
18 changes: 6 additions & 12 deletions src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}));
},
Expand All @@ -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[]) => {
Expand Down
49 changes: 40 additions & 9 deletions src/graphql/routes/oasis-api.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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,
},
];
}
}
1 change: 1 addition & 0 deletions src/graphql/routes/radix-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/graphql/routes/sui-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/graphql/utils/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit ecd132f

Please sign in to comment.