Skip to content

Commit

Permalink
Expand RewardResolver into a RewardConfig (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyDelott authored Jan 22, 2025
1 parent bfa41f4 commit fe94fe1
Show file tree
Hide file tree
Showing 13 changed files with 665 additions and 618 deletions.
458 changes: 229 additions & 229 deletions packages/hyperdrive-appconfig/src/generated/all.appconfig.ts

Large diffs are not rendered by default.

326 changes: 163 additions & 163 deletions packages/hyperdrive-appconfig/src/generated/mainnet.appconfig.ts

Large diffs are not rendered by default.

238 changes: 119 additions & 119 deletions packages/hyperdrive-appconfig/src/generated/testnet.appconfig.ts

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/hyperdrive-appconfig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export type {
ApyReward,
InfoReward,
PointMultiplierReward,
RewardsResolver,
RewardConfig,
RewardResolver,
TokenAmountReward,
} from "src/rewards/types";

Expand Down
92 changes: 48 additions & 44 deletions packages/hyperdrive-appconfig/src/rewards/resolvers/aero.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
import { parseAbi } from "abitype";
import { fixed, parseFixed } from "src/base/fixedPoint";
import { RewardsResolver } from "src/rewards/types";
import { RewardConfig } from "src/rewards/types";
import { fetchDefiLlamaTokenPrice } from "src/tokens/priceOracles/defillama";
import { base } from "viem/chains";

const AERO_TOKEN_ADDRESS = "0x940181a94A35A4569E4529A3CDfB74e38FD98631";
export const fetchAeroRewards: RewardsResolver = async (publicClient) => {
// Amount of AERO rewarded per second (~1.9 AERO per second)
const rewardRate = await publicClient.readContract({
address: "0x4F09bAb2f0E15e2A078A227FE1537665F55b8360",
functionName: "rewardRate",
abi: parseAbi(gaugeAbi),
});
const fixedPointRate = fixed(rewardRate);
export const fetchAeroRewards: RewardConfig = {
id: "fetchAeroRewards",
chainIds: [base.id],
resolver: async (publicClient) => {
// Amount of AERO rewarded per second (~1.9 AERO per second)
const rewardRate = await publicClient.readContract({
address: "0x4F09bAb2f0E15e2A078A227FE1537665F55b8360",
functionName: "rewardRate",
abi: parseAbi(gaugeAbi),
});
const fixedPointRate = fixed(rewardRate);

// Multiply this by the number of seconds in a year
const secondsPerYear = 31_536_000;
const fixedSecondsPerYear = parseFixed(secondsPerYear);
const aeroRewardsPerYear = fixedPointRate.mul(fixedSecondsPerYear);
// Multiply this by the number of seconds in a year
const secondsPerYear = 31_536_000;
const fixedSecondsPerYear = parseFixed(secondsPerYear);
const aeroRewardsPerYear = fixedPointRate.mul(fixedSecondsPerYear);

const aeroPrice = await fetchDefiLlamaTokenPrice({
// price per AERO token
tokenAddress: AERO_TOKEN_ADDRESS,
chainId: base.id,
denomination: "usd",
publicClient,
});
const aeroPrice = await fetchDefiLlamaTokenPrice({
// price per AERO token
tokenAddress: AERO_TOKEN_ADDRESS,
chainId: base.id,
denomination: "usd",
publicClient,
});

const dollarAmountRewardedPerYear = aeroRewardsPerYear.mul(aeroPrice);
const dollarAmountRewardedPerYear = aeroRewardsPerYear.mul(aeroPrice);

const totalSupply = await publicClient.readContract({
address: "0x4F09bAb2f0E15e2A078A227FE1537665F55b8360",
functionName: "totalSupply",
abi: parseAbi(gaugeAbi),
});
const totalSupply = await publicClient.readContract({
address: "0x4F09bAb2f0E15e2A078A227FE1537665F55b8360",
functionName: "totalSupply",
abi: parseAbi(gaugeAbi),
});

const fixedTotalSupply = fixed(totalSupply);
const fixedTotalSupply = fixed(totalSupply);

const aeroLpPrice = await fetchDefiLlamaTokenPrice({
// price per LP token
tokenAddress: "0x6cDcb1C4A4D1C3C6d054b27AC5B77e89eAFb971d",
chainId: base.id,
denomination: "usd",
publicClient,
});
const aeroLpPrice = await fetchDefiLlamaTokenPrice({
// price per LP token
tokenAddress: "0x6cDcb1C4A4D1C3C6d054b27AC5B77e89eAFb971d",
chainId: base.id,
denomination: "usd",
publicClient,
});

const dollarValueOfPool = fixed(aeroLpPrice).mul(fixedTotalSupply);
const dollarValueOfPool = fixed(aeroLpPrice).mul(fixedTotalSupply);

const apr = dollarAmountRewardedPerYear.div(dollarValueOfPool);
const apr = dollarAmountRewardedPerYear.div(dollarValueOfPool);

return [
{
type: "apy",
apy: apr.bigint,
chainId: base.id,
tokenAddress: AERO_TOKEN_ADDRESS,
},
];
return [
{
type: "apy",
apy: apr.bigint,
chainId: base.id,
tokenAddress: AERO_TOKEN_ADDRESS,
},
];
},
};

export const gaugeAbi = [
Expand Down
25 changes: 15 additions & 10 deletions packages/hyperdrive-appconfig/src/rewards/resolvers/etherfi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { RewardsResolver } from "src/rewards/types";
import { RewardConfig } from "src/rewards/types";
import { EETH_ICON_URL } from "src/tokens/tokenIconsUrls";
import { mainnet } from "viem/chains";

export const fetchEtherfiRewards: RewardsResolver = async () => {
return [
{
type: "pointMultiplier",
iconUrl: EETH_ICON_URL,
pointMultiplier: 2n,
pointTokenLabel: "Ether.fi Loyalty Points",
},
];
export const fetchEtherfiRewards: RewardConfig = {
id: "fetchEtherfiRewards",
chainIds: [mainnet.id],
resolver: async () => {
return [
{
type: "pointMultiplier",
iconUrl: EETH_ICON_URL,
pointMultiplier: 2n,
pointTokenLabel: "Ether.fi Loyalty Points",
},
];
},
};
25 changes: 15 additions & 10 deletions packages/hyperdrive-appconfig/src/rewards/resolvers/gyroscope.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { RewardsResolver } from "src/rewards/types";
import { RewardConfig } from "src/rewards/types";
import { GYD_ICON_URL } from "src/tokens/tokenIconsUrls";
import { gnosis, mainnet } from "viem/chains";

export const fetchGyroscopeRewards: RewardsResolver = async () => {
return [
{
type: "pointMultiplier",
iconUrl: GYD_ICON_URL,
pointMultiplier: 2n,
pointTokenLabel: "SPIN Rewards",
},
];
export const fetchGyroscopeRewards: RewardConfig = {
id: "fetchGyroscopeRewards",
chainIds: [mainnet.id, gnosis.id],
resolver: async () => {
return [
{
type: "pointMultiplier",
iconUrl: GYD_ICON_URL,
pointMultiplier: 2n,
pointTokenLabel: "SPIN Rewards",
},
];
},
};

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions packages/hyperdrive-appconfig/src/rewards/resolvers/linea.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { lineaChainConfig } from "src/chains/chains";
import { RewardsResolver } from "src/rewards/types";
import { RewardConfig } from "src/rewards/types";
import { linea } from "viem/chains";

export const fetchLineaRewards: RewardsResolver = async () => {
return [
{
type: "pointMultiplier",
pointMultiplier: 1n,
pointTokenLabel: "LXP-L Rewards",
iconUrl: lineaChainConfig.iconUrl,
},
];
export const fetchLineaRewards: RewardConfig = {
id: "fetchLineaRewards",
chainIds: [linea.id],
resolver: async () => {
return [
{
type: "pointMultiplier",
pointMultiplier: 1n,
pointTokenLabel: "LXP-L Rewards",
iconUrl: lineaChainConfig.iconUrl,
},
];
},
};
52 changes: 34 additions & 18 deletions packages/hyperdrive-appconfig/src/rewards/resolvers/morpho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,64 @@ import { fixed, FixedPoint, parseFixed } from "src/base/fixedPoint";
import {
AnyReward,
ApyReward,
RewardsResolver,
RewardConfig,
TokenAmountReward,
} from "src/rewards/types";
import { base } from "viem/chains";
/**
* Resolver for rewards on Morpho Flagship EURC
* https://app.morpho.org/vault?vault=0xf24608E0CCb972b0b0f4A6446a0BBf58c701a026&network=base
*/
export const fetchMorphoMweurcRewards: RewardsResolver = async () => {
return fetchMorphoVaultRewards(
"0xf24608E0CCb972b0b0f4A6446a0BBf58c701a026",
base.id,
);
export const fetchMorphoMweurcRewards: RewardConfig = {
id: "fetchMorphoMweurcRewards",
chainIds: [base.id],
resolver: async () => {
return fetchMorphoVaultRewards(
"0xf24608E0CCb972b0b0f4A6446a0BBf58c701a026",
base.id,
);
},
};
/**
* Resolver for rewards on Morpho Flagship USDC
* https://app.morpho.org/vault?vault=0xc1256Ae5FF1cf2719D4937adb3bbCCab2E00A2Ca&network=base
*/
export const fetchMorphoMwusdcRewards: RewardsResolver = async () => {
return fetchMorphoVaultRewards(
"0xc1256Ae5FF1cf2719D4937adb3bbCCab2E00A2Ca",
base.id,
);
export const fetchMorphoMwusdcRewards: RewardConfig = {
id: "fetchMorphoMwusdcRewards",
chainIds: [base.id],
resolver: async () => {
return fetchMorphoVaultRewards(
"0xc1256Ae5FF1cf2719D4937adb3bbCCab2E00A2Ca",
base.id,
);
},
};

/**
* Resolver for rewards on Morpho Flagship ETH
* https://app.morpho.org/vault?vault=0xa0E430870c4604CcfC7B38Ca7845B1FF653D0ff1&network=base
*/
export const fetchMorphoMwethRewards: RewardsResolver = async () => {
return fetchMorphoVaultRewards(
"0xa0E430870c4604CcfC7B38Ca7845B1FF653D0ff1",
base.id,
);
export const fetchMorphoMwethRewards: RewardConfig = {
id: "fetchMorphoMwethRewards",
chainIds: [base.id],
resolver: async () => {
return fetchMorphoVaultRewards(
"0xa0E430870c4604CcfC7B38Ca7845B1FF653D0ff1",
base.id,
);
},
};

/**
* Resolver for rewards on Morpho Market cbETH/USDC
* https://app.morpho.org/market?id=0x1c21c59df9db44bf6f645d854ee710a8ca17b479451447e9f56758aee10a2fad&network=base
*/
export const fetchMorphoCbethUsdcRewards: RewardsResolver = async () => {
return fetchMorphoMarketRewards("ffbf9c87-73ed-4188-aa50-20b1e1101a15");
export const fetchMorphoCbethUsdcRewards: RewardConfig = {
id: "fetchMorphoCbethUsdcRewards",
chainIds: [base.id],
resolver: async () => {
return fetchMorphoMarketRewards("ffbf9c87-73ed-4188-aa50-20b1e1101a15");
},
};

interface MorphoReward {
Expand Down
6 changes: 3 additions & 3 deletions packages/hyperdrive-appconfig/src/rewards/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { getAddLiquidityRewardId } from "src/rewards/actions/lp";
import { getOpenShortRewardId } from "src/rewards/actions/short";
import { getYieldSourceRewardId } from "src/rewards/actions/yieldSource";
import { RewardResolverId, rewardResolvers } from "src/rewards/resolvers";
import { RewardsResolver } from "src/rewards/types";
import { RewardResolver } from "src/rewards/types";
import { YieldSourceId } from "src/yieldSources/types";
import { Address } from "viem";

export function getRewardsResolver({
resolverId,
}: {
resolverId: RewardResolverId;
}): RewardsResolver | undefined {
return rewardResolvers[resolverId];
}): RewardResolver | undefined {
return rewardResolvers[resolverId].resolver;
}

export function getYieldSourceRewardResolverIds({
Expand Down
8 changes: 7 additions & 1 deletion packages/hyperdrive-appconfig/src/rewards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export type AnyReward =
| PointMultiplierReward
| InfoReward;

export type RewardsResolver = (
export type RewardResolver = (
publicClient: PublicClient,
) => Promise<AnyReward[]>;

export interface RewardConfig {
id: string;
chainIds: number[];
resolver: RewardResolver;
}
2 changes: 1 addition & 1 deletion packages/hyperdrive-appconfig/src/scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async function addRewardTokenConfigs({ appConfig }: { appConfig: AppConfig }) {
Object.entries(yieldSources)
.filter(([unusedKey, yieldSource]) => yieldSource.rewardsFn)
.map(async ([unusedKey, yieldSource]) => {
const rewardFn = rewardResolvers[yieldSource.rewardsFn!]; // safe to cast due to filter above
const rewardFn = rewardResolvers[yieldSource.rewardsFn!].resolver; // safe to cast due to filter above
const publicClient = publicClients[yieldSource.chainId];
const rewards = await rewardFn(publicClient);

Expand Down

0 comments on commit fe94fe1

Please sign in to comment.