Skip to content

Commit

Permalink
Add rewards field to top-level appconfig (#1701)
Browse files Browse the repository at this point in the history
* Refactor chainlog to makeQueryKey2

* Add rewards field to appconfig, DRY up some references

* Move to own file

* Add rewardsMap parsing to getHyperdriveConfig functions

* overly wordy

* Remove stray log
  • Loading branch information
DannyDelott authored Jan 3, 2025
1 parent 5614d76 commit 5180d5e
Show file tree
Hide file tree
Showing 19 changed files with 830 additions and 555 deletions.
11 changes: 7 additions & 4 deletions apps/hyperdrive-trading/src/ui/chainlog/FactoriesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@tanstack/react-table";
import classNames from "classnames";
import { ReactElement } from "react";
import { makeQueryKey } from "src/base/makeQueryKey";
import { makeQueryKey2 } from "src/base/makeQueryKey";
import { getDrift } from "src/drift/getDrift";
import { Status, getStatus } from "src/registry/data";
import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain";
Expand Down Expand Up @@ -166,9 +166,12 @@ function useFactoriesQuery(): UseQueryResult<Factory[]> {
const chainIds = Object.keys(connectedAppConfig.registries).map(Number);

return useQuery({
queryKey: makeQueryKey("chainlog", {
tab: "factories",
chainIds,
queryKey: makeQueryKey2({
namespace: "chainlog",
queryId: "factories",
params: {
chainIds,
},
}),
placeholderData: [],
queryFn: async () => {
Expand Down
11 changes: 7 additions & 4 deletions apps/hyperdrive-trading/src/ui/chainlog/PoolsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@tanstack/react-table";
import classNames from "classnames";
import { ReactElement } from "react";
import { makeQueryKey } from "src/base/makeQueryKey";
import { makeQueryKey2 } from "src/base/makeQueryKey";
import { getDrift } from "src/drift/getDrift";
import { getStatus, Status } from "src/registry/data";
import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain";
Expand Down Expand Up @@ -212,9 +212,12 @@ function usePoolsQuery(): UseQueryResult<Pool[]> {
const chainIds = Object.keys(connectedAppConfig.registries).map(Number);

return useQuery({
queryKey: makeQueryKey("chainlog", {
tab: "pools",
chainIds,
queryKey: makeQueryKey2({
namespace: "chainlog",
queryId: "pools",
params: {
chainIds,
},
}),
placeholderData: [],
queryFn: async () =>
Expand Down
16 changes: 16 additions & 0 deletions apps/hyperdrive-trading/src/ui/chainlog/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "src/base/makeQueryKey";

interface ChainlogQueryKeys {
pools: {
chainIds: number[];
};
factories: {
chainIds: number[];
};
}

declare module "src/base/makeQueryKey" {
interface QueryKeys {
chainlog: ChainlogQueryKeys;
}
}
2 changes: 1 addition & 1 deletion apps/hyperdrive-trading/src/ui/landing/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function Landing(): ReactElement | null {
Hyperdrive Pools
</h1>
<p className="font-inter text-lg leading-bodyText text-neutral-content">
Earn predictable fixed rate yield or multiply your capital exposure to
Earn predictable fixed rate yield or multiply your exposure to
DeFi&apos;s top variable rates.
</p>
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/hyperdrive-appconfig/src/appconfig/AppConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Address } from "abitype";
import { ChainConfig, ChainId } from "src/chains/chains";
import { HyperdriveConfig } from "src/hyperdrives/HyperdriveConfig";
import { AnyRewardKey } from "src/hyperdrives/rewards";
import { protocols } from "src/protocols";
import { RewardResolverKey } from "src/rewards/rewards";
import { TokenConfig } from "src/tokens/types";
import { yieldSources } from "src/yieldSources/yieldSources";
import { ZapConfig } from "src/zaps/ZapsConfig";
Expand All @@ -17,4 +19,5 @@ export interface AppConfig {
protocols: typeof protocols;
yieldSources: typeof yieldSources;
zaps: Record<ChainId, ZapConfig>;
rewards: Record<AnyRewardKey, RewardResolverKey[]>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ReadHyperdrive } from "@delvtech/hyperdrive-viem";
import { HyperdriveConfig } from "src/hyperdrives/HyperdriveConfig";
import { AnyRewardKey } from "src/hyperdrives/rewards";
import { RewardResolverKey } from "src/rewards/rewards";
import { TokenConfig } from "src/tokens/types";
import { PublicClient } from "viem";

export interface HyperdriveConfigResolverResult {
hyperdriveConfig: HyperdriveConfig;
sharesTokenConfig?: TokenConfig;
baseTokenConfig?: TokenConfig;
rewards?: Record<AnyRewardKey, RewardResolverKey[]>;
}

export type HyperdriveConfigResolver = (
hyperdrive: ReadHyperdrive,
publicClient: PublicClient,
/**
* Block number to clamp the beginning of event requests to. This is useful
* for L2s that have too many blocks where the default "earliest" blockTag
* would timeout.
*/
earliestBlock?: bigint,
) => Promise<HyperdriveConfigResolverResult>;
46 changes: 22 additions & 24 deletions packages/hyperdrive-appconfig/src/appconfig/getAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { ReadHyperdrive, ReadRegistry } from "@delvtech/hyperdrive-viem";
import chalk from "chalk";
import uniqBy from "lodash.uniqby";
import { AppConfig } from "src/appconfig/AppConfig";
import { HyperdriveConfigResolver } from "src/appconfig/HyperdriveConfigResolver";
import { chains } from "src/chains/chains";
import { HyperdriveConfig } from "src/hyperdrives/HyperdriveConfig";
import { getAeroLpHyperdrive } from "src/hyperdrives/aero/getAeroHyperdrive";
import { getCbethHyperdrive } from "src/hyperdrives/cbeth/getCbethHyperdrive";
import { getCustomHyperdrive } from "src/hyperdrives/custom/getCustomHyperdrive";
import { getGnosisWstethHyperdrive } from "src/hyperdrives/gnosisWsteth/getGnosisWstethHyperdrive";
import { getMorphoHyperdrive } from "src/hyperdrives/morpho/getMorphoHyperdrive";
import { AnyRewardKey } from "src/hyperdrives/rewards";
import { getStethHyperdrive } from "src/hyperdrives/steth/getStethHyperdrive";
import { protocols } from "src/protocols";
import { RewardResolverKey } from "src/rewards/rewards";
import {
AERO_ICON_URL,
DAI_ICON_URL,
Expand Down Expand Up @@ -42,20 +45,6 @@ import { YieldSourceId } from "src/yieldSources/types";
import { yieldSources } from "src/yieldSources/yieldSources";
import { zaps } from "src/zaps/zaps";
import { Address, PublicClient } from "viem";
type HyperdriveConfigResolver = (
hyperdrive: ReadHyperdrive,
publicClient: PublicClient,
/**
* Block number to clamp the beginning of event requests to. This is useful
* for L2s that have too many blocks where the default "earliest" blockTag
* would timeout.
*/
earliestBlock?: bigint,
) => Promise<{
hyperdriveConfig: HyperdriveConfig;
sharesTokenConfig?: TokenConfig;
baseTokenConfig?: TokenConfig;
}>;

const hyperdriveKindResolvers: Record<
string /* kind */,
Expand All @@ -77,7 +66,7 @@ const hyperdriveKindResolvers: Record<
isBaseTokenWithdrawalEnabled: false,
isShareTokenWithdrawalEnabled: true,
},
rewards: {
rewardsMap: {
short: ["fetchLineaRewards"],
lp: ["fetchLineaRewards"],
},
Expand All @@ -97,7 +86,7 @@ const hyperdriveKindResolvers: Record<
isBaseTokenDepositEnabled: false,
isShareTokenDepositsEnabled: true,
},
rewards: {
rewardsMap: {
short: ["fetchLineaRewards"],
lp: ["fetchLineaRewards"],
},
Expand Down Expand Up @@ -147,7 +136,7 @@ const hyperdriveKindResolvers: Record<
isBaseTokenDepositEnabled: true,
isShareTokenDepositsEnabled: true,
},
rewards: {
rewardsMap: {
short: ["fetchEtherfiRewards"],
lp: ["fetchEtherfiRewards"],
},
Expand Down Expand Up @@ -231,7 +220,7 @@ const hyperdriveKindResolvers: Record<
isBaseTokenWithdrawalEnabled: true,
isShareTokenWithdrawalEnabled: true,
},
rewards: {
rewardsMap: {
short: ["fetchGyroscopeRewards"],
lp: ["fetchGyroscopeRewards"],
},
Expand Down Expand Up @@ -371,7 +360,7 @@ const hyperdriveKindResolvers: Record<
isShareTokenWithdrawalEnabled: true,
},
tokenPlaces: 4,
rewards: {
rewardsMap: {
short: ["fetchMorphoMwethRewards"],
lp: ["fetchMorphoMwethRewards"],
},
Expand All @@ -394,7 +383,7 @@ const hyperdriveKindResolvers: Record<
isShareTokenWithdrawalEnabled: true,
},
tokenPlaces: 2,
rewards: {
rewardsMap: {
short: ["fetchMorphoMwusdcRewards"],
lp: ["fetchMorphoMwusdcRewards"],
},
Expand All @@ -417,7 +406,7 @@ const hyperdriveKindResolvers: Record<
isShareTokenWithdrawalEnabled: true,
},
tokenPlaces: 2,
rewards: {
rewardsMap: {
short: ["fetchMorphoMweurcRewards"],
lp: ["fetchMorphoMweurcRewards"],
},
Expand Down Expand Up @@ -494,7 +483,7 @@ const hyperdriveKindResolvers: Record<
yieldSourceId: "aeroUsdcAero",
baseTokenPlaces: 9, // aero lp tokens are super small
baseTokenTags: [],
rewards: {
rewardsMap: {
short: ["fetchAeroRewards"],
lp: ["fetchAeroRewards"],
},
Expand Down Expand Up @@ -569,7 +558,7 @@ const hyperdriveKindResolvers: Record<
baseTokenIconUrl: USDC_ICON_URL,
baseTokenPlaces: 2,
yieldSourceId: "morphoCbethUsdc",
rewards: {
rewardsMap: {
short: ["fetchMorphoCbethUsdcRewards"],
lp: ["fetchMorphoCbethUsdcRewards"],
},
Expand All @@ -592,6 +581,7 @@ export async function getAppConfig({
earliestBlock?: bigint;
}): Promise<AppConfig> {
const tokens: TokenConfig[] = [];
let allRewards: Record<AnyRewardKey, RewardResolverKey[]> = {};
const chainId = publicClient.chain?.id as number;

// Get ReadHyperdrive instances from the registry to ensure
Expand All @@ -612,7 +602,7 @@ export async function getAppConfig({
throw new Error(`Missing resolver for hyperdrive kind: ${kind}.`);
}

const { hyperdriveConfig, baseTokenConfig, sharesTokenConfig } =
const { hyperdriveConfig, baseTokenConfig, sharesTokenConfig, rewards } =
await hyperdriveResolver(hyperdrive, publicClient, earliestBlock);

// Not all hyperdrives have a base or shares token, so only add them if
Expand All @@ -624,6 +614,13 @@ export async function getAppConfig({
tokens.push(sharesTokenConfig);
}

if (rewards) {
allRewards = {
...allRewards,
...rewards,
};
}

return hyperdriveConfig;
}),
);
Expand All @@ -638,6 +635,7 @@ export async function getAppConfig({
yieldSources,
chains,
zaps,
rewards: allRewards,
};

return config;
Expand Down
Loading

0 comments on commit 5180d5e

Please sign in to comment.