Skip to content

Commit

Permalink
refactor(pol): removes indexer /homepage endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bearpong committed Dec 18, 2024
1 parent d5e4082 commit 48f6c3d
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 40 deletions.
1 change: 0 additions & 1 deletion .env.bartio
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ NEXT_PUBLIC_BALANCER_API_CHAIN_NAME="BARTIO"
# HUB Addresses ===================================================================
NEXT_PUBLIC_BGT_ADDRESS="0xbDa130737BDd9618301681329bF2e46A016ff9Ad"
NEXT_PUBLIC_BGT_STAKER="0x791fb53432eED7e2fbE4cf8526ab6feeA604Eb6d"
NEXT_PUBLIC_POL_ENDPOINT="https://bartio-pol-indexer.berachain.com/berachain/v1alpha1/beacon"
NEXT_PUBLIC_BERA_CHEF_ADDRESS="0xfb81E39E3970076ab2693fA5C45A07Cc724C93c2"
NEXT_PUBLIC_REWARD_VAULT_FACTORY_ADDRESS="0x2B6e40f65D82A0cB98795bC7587a71bfa49fBB2B"

Expand Down
1 change: 0 additions & 1 deletion apps/hub/src/app/pools/usePoolTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export const usePoolTable = ({
/>
),
cell: ({ row }) => {
const { data: bgtInflation } = useBgtInflation();
return (
<div
className={`flex items-center justify-start text-sm ${
Expand Down
14 changes: 12 additions & 2 deletions apps/hub/src/app/vaults/components/gauge-info-card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from "react";
import Link from "next/link";
import { truncateHash, usePollGlobalData, type Validator } from "@bera/berajs";
import {
truncateHash,
useBlockTime,
usePollGlobalData,
type Validator,
} from "@bera/berajs";
import { FormattedNumber, ValidatorIcon } from "@bera/shared-ui";
import { getHubValidatorPath } from "@bera/shared-ui";
import { Icons } from "@bera/ui/icons";
Expand All @@ -11,6 +16,11 @@ import { Address } from "viem";

export default function GaugeInfoCard() {
const { data: globalData, isLoading } = usePollGlobalData();

const timePerBlock = useBlockTime();
const blockCountPerYear = timePerBlock
? (60 * 60 * 24 * 365) / timePerBlock
: 0;
return (
<div className="flex w-full flex-1 flex-col gap-6 sm:flex-row">
<div className="flex flex-1 flex-row gap-6 sm:flex-col">
Expand Down Expand Up @@ -71,7 +81,7 @@ export default function GaugeInfoCard() {
<Skeleton className="h-8 w-full" />
) : (
<FormattedNumber
value={globalData?.bgtInfo?.blockCountPerYear ?? 0}
value={blockCountPerYear}
compact={false}
compactThreshold={999_999}
symbol="BGT"
Expand Down
45 changes: 22 additions & 23 deletions packages/berajs/src/actions/bgt/getBGTGlobalInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { balancerApiChainName } from "@bera/config";
import { bexApiGraphqlClient } from "@bera/graphql";
import { GqlChain } from "@bera/graphql/dex/api";
import {
ApiValidatorFragment,
ApiVaultFragment,
Expand All @@ -11,14 +13,9 @@ import type { BeraConfig, RewardVaultIncentive, Validator } from "~/types";
export interface GlobalInfo {
bgtInfo: {
bgtInflation: number;
bgtPerBlock: number;
blockCountPerYear: number;
totalStakeBgt: number;
};
incentiveCount: number;
sumAllIncentivesInHoney: string;
top3Incentives: { activeIncentives: RewardVaultIncentive[] };
top3Vaults: ApiVaultFragment[];
top3EmittingValidators: ApiValidatorFragment[];
validatorCount: number;
vaultCount: number;
Expand All @@ -27,26 +24,28 @@ export interface GlobalInfo {
export const getBGTGlobalInfo = async (
config: BeraConfig,
): Promise<GlobalInfo | undefined> => {
if (!config.endpoints?.polEndpoint) {
throw new Error("Missing backend endpoint in config");
}
const [res, apiRes] = await Promise.all([
fetch(`${config.endpoints.polEndpoint}/homepage`),
bexApiGraphqlClient.query<GlobalDataQuery, GlobalDataQueryVariables>({
query: GlobalData,
}),
]);
const apiRes = await bexApiGraphqlClient.query<
GlobalDataQuery,
GlobalDataQueryVariables
>({
query: GlobalData,
variables: {
chain: balancerApiChainName as GqlChain,
},
});

const data = await res.json();
const apiData = apiRes.data;
const data = apiRes.data;

return {
bgtInfo: data.bgtInfo,
sumAllIncentivesInHoney: data.sumAllIncentivesInHoney,
validatorCount: data.validatorCount,
vaultCount: data.vaultCount,
incentiveCount: data.incentiveCount,
top3Incentives: data.top3Incentives,
...apiData,
bgtInfo: {
// TODO: get bgt inflation somehow, maybe from the backend
bgtInflation: 0,
totalStakeBgt: Number(data.polGetGlobalInfo?.totalBGTStaked ?? "0"),
},
sumAllIncentivesInHoney:
data.polGetGlobalInfo?.totalActiveIncentivesValueUSD ?? "0",
validatorCount: data.polGetGlobalInfo?.totalValidators ?? 0,
vaultCount: data.polGetGlobalInfo?.totalRewardVaults ?? 0,
top3EmittingValidators: apiRes.data.top3EmittingValidators,
} satisfies GlobalInfo;
};
2 changes: 0 additions & 2 deletions packages/berajs/src/config/defaultBeraConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
lendUIDataProviderAddress,
marketListUrl,
multicallAddress,
polEndpointUrl,
polSubgraphUrl,
tokenListUrl,
tradingContractAddress,
Expand All @@ -31,7 +30,6 @@ export const defaultBeraConfig: BeraConfig = {
validatorList: validatorListUrl,
marketList: marketListUrl,
validatorInfo: validatorListUrl,
polEndpoint: polEndpointUrl,
},
subgraphs: {
honeySubgraph: honeySubgraphUrl,
Expand Down
1 change: 0 additions & 1 deletion packages/berajs/src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface BeraConfig {
validatorList?: string;
marketList?: string;
validatorInfo?: string;
polEndpoint?: string;
};
subgraphs?: {
honeySubgraph?: string;
Expand Down
1 change: 0 additions & 1 deletion packages/config/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const blockExplorerUrl = process.env
.NEXT_PUBLIC_BLOCK_EXPLORER as string;
export const blockExplorerName = process.env
.NEXT_PUBLIC_BLOCK_EXPLORER_NAME as string;
export const polEndpointUrl = process.env.NEXT_PUBLIC_POL_ENDPOINT as string;

// Subgraphs
export const balancerApiUrl = process.env
Expand Down
16 changes: 8 additions & 8 deletions packages/graphql/src/modules/pol/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ fragment ApiVaultIncentive on GqlRewardVaultIncentive {
active
amountRemaining
incentiveRate

tokenAddress
token {
address
Expand Down Expand Up @@ -133,20 +132,21 @@ query GetRewardVault($vaultId: String!, $chain: GqlChain!) {
}
}

query GlobalData {
query GlobalData($chain: GqlChain!) {
top3EmittingValidators: polGetValidators(
orderBy: bgtCapturePercentage
orderDirection: desc
first: 3
) {
...ApiValidator
}
top3Vaults: polGetRewardVaults(
orderBy: last24hBGTReceived
orderDirection: desc
first: 3
) {
...ApiVault

polGetGlobalInfo(chain: $chain) {
totalBGTStaked
totalValidators
totalRewardVaults
totalActiveIncentives
totalActiveIncentivesValueUSD
}
}

Expand Down
2 changes: 1 addition & 1 deletion secrets

0 comments on commit 48f6c3d

Please sign in to comment.