Skip to content

Commit

Permalink
refactor: validator addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Dec 7, 2023
1 parent 97df7da commit 046e566
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ export const resolvers = {
const { dataSources } = params[2] as ContextValue;
const { status, data } = await dataSources.radixAPI.getRadixTVL();

if (status === "error") return;
if (status === "error" || !data) return;

const { address, TVL } = data as NonNullable<typeof data>;
const { address, TVL } = data;

return [
{
Expand Down
19 changes: 10 additions & 9 deletions src/graphql/routes/archway-api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { DataSourceConfig } from "@apollo/datasource-rest";
import { RESTDataSource } from "@apollo/datasource-rest";

import { archwayValidatorAddress } from "../utils/addresses";
import { CoinGeckoDataSource } from "../utils/coingecko-data";

const validatorAddress =
"archwayvaloper1esg4kluvdkfcxl0atcf2us2p9m9y9sjjsu04ex";

// GET https://api.mainnet.archway.io/cosmos/bank/v1beta1/denoms_metadata
const decimalsOfAArchwayBondenToken = 18;

Expand All @@ -22,7 +20,7 @@ export class ArchwayAPI extends RESTDataSource {

async getTVL() {
const [validatorResponse, coinPrice] = await Promise.all([
this.get(`/staking/validators/${validatorAddress}`, {
this.get(`/staking/validators/${archwayValidatorAddress}`, {
headers: {
"Content-Type": "application/json",
},
Expand Down Expand Up @@ -54,7 +52,7 @@ export class ArchwayAPI extends RESTDataSource {
"Content-Type": "application/json",
},
}),
this.get(`/staking/validators/${validatorAddress}`, {
this.get(`/staking/validators/${archwayValidatorAddress}`, {
headers: {
"Content-Type": "application/json",
},
Expand Down Expand Up @@ -99,11 +97,14 @@ export class ArchwayAPI extends RESTDataSource {
}

async getBondedToken() {
const result = await this.get(`/staking/validators/${validatorAddress}`, {
headers: {
"Content-Type": "application/json",
const result = await this.get(
`/staking/validators/${archwayValidatorAddress}`,
{
headers: {
"Content-Type": "application/json",
},
},
});
);

const bondedToken =
result?.result?.tokens / 10 ** decimalsOfAArchwayBondenToken;
Expand Down
10 changes: 4 additions & 6 deletions src/graphql/routes/radix-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DataSourceConfig } from "@apollo/datasource-rest";
import { RESTDataSource } from "@apollo/datasource-rest";

import { radixValidatorAddress } from "../utils/addresses";
import { CoinGeckoDataSource } from "../utils/coingecko-data";

const { RADIX_URL } = process.env;
Expand All @@ -17,9 +18,6 @@ type RadixResponse = {
};
};

const validatorAddress =
"validator_rdx1swkmn6yvrqjzpaytvug5fp0gzfy9zdzq7j7nlxe8wgjpg76vdcma8p";

// https://dashboard.radixdlt.com/network-staking
// https://radix-babylon-gateway-api.redoc.ly/#tag/Status

Expand Down Expand Up @@ -58,7 +56,7 @@ export class RadixAPI extends RESTDataSource {
network: "mainnet",
},
validator_identifier: {
address: validatorAddress,
address: radixValidatorAddress,
},
}),
}),
Expand All @@ -67,7 +65,7 @@ export class RadixAPI extends RESTDataSource {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const validator = radixResponse.validators.items.find((i: any) =>
(i.address as string).includes(validatorAddress),
(i.address as string).includes(radixValidatorAddress),
);

if (!validator) {
Expand All @@ -89,7 +87,7 @@ export class RadixAPI extends RESTDataSource {
status: "ok",
data: {
TVL,
address: validatorAddress,
address: radixValidatorAddress,
},
};
}
Expand Down
9 changes: 3 additions & 6 deletions src/graphql/routes/sui-api.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import type { DataSourceConfig } from "@apollo/datasource-rest";
import { RESTDataSource } from "@apollo/datasource-rest";

import { suiValidatorAddress } from "../utils/addresses";
import { CoinGeckoDataSource } from "../utils/coingecko-data";

if (!process.env.DEVTOOLS_API_KEY) {
throw new Error("DEVTOOLS_API_KEY is not set");
}

// https://suiexplorer.com/validator/0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059
const validatorAddress =
"0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059";

const coinDecimals = 9;

// https://docs.sui.io/
Expand Down Expand Up @@ -48,7 +45,7 @@ export class SuiAPI extends RESTDataSource {

return response.result.activeValidators.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(v: any) => v.suiAddress === validatorAddress,
(v: any) => v.suiAddress === suiValidatorAddress,
);
}

Expand All @@ -65,7 +62,7 @@ export class SuiAPI extends RESTDataSource {

const validatorItem = response.result.apys.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(v: any) => v.address === validatorAddress,
(v: any) => v.address === suiValidatorAddress,
);

if (!validatorItem) {
Expand Down
9 changes: 9 additions & 0 deletions src/graphql/utils/addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const archwayValidatorAddress =
"archwayvaloper1esg4kluvdkfcxl0atcf2us2p9m9y9sjjsu04ex";

export const radixValidatorAddress =
"validator_rdx1swkmn6yvrqjzpaytvug5fp0gzfy9zdzq7j7nlxe8wgjpg76vdcma8p";

// https://suiexplorer.com/validator/0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059
export const suiValidatorAddress =
"0x1e1985024aafe50a8e4eafc5a89eb7ecd58ba08c39f37688bee00bd55c8b2059";

0 comments on commit 046e566

Please sign in to comment.