Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update oasis values #38

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";