Skip to content
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
2 changes: 2 additions & 0 deletions src/core/app/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getAPYTreehouse,
getAPYUpshift,
getAPYYearn,
getAPYYieldsreserve,
getAPYYuzu,
getGearAPY,
} from "../../tokens/apy";
Expand Down Expand Up @@ -325,6 +326,7 @@ export class Fetcher {
getAPYUpshift,
getAPYMagma,
getAPYMakina,
getAPYYieldsreserve,
];
const [
points,
Expand Down
19 changes: 14 additions & 5 deletions src/tokens/apy/merkle/apy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import type {
CommonPayload,
CompositePart,
CompositePayload,
MerklePayload,
} from "./constants";
import { PROTOCOL, TOKENS } from "./constants";

const getAPYMerkle: APYHandler = async network => {
const tokenEntries = Object.entries(TOKENS[network] || {}).map(
([k, v]) => [k.toLowerCase(), v] as const,
([k, v]): [Address, MerklePayload] => [k.toLowerCase() as Address, v],
);

return getAPYMerkle_withFilter(network, tokenEntries);
};

const getAPYMerkle_withFilter = async (
network: NetworkType,
tokenEntries: Array<[Address, MerklePayload]>,
) => {
if (tokenEntries.length === 0) return {};

// get all campaigns
Expand All @@ -33,7 +42,7 @@ const getAPYMerkle: APYHandler = async network => {
const currentChainId = getChain(network).id;

const allAPY = tokenEntries.reduce<APYResult>((acc, [addr, p], index) => {
const address = addr as Address;
const address = addr;
const tokenCampaignsRes = res[index];

const merkleAPY = getCampaignAPY(currentChainId, p, tokenCampaignsRes);
Expand Down Expand Up @@ -67,7 +76,7 @@ function getCampaignAPY(
currentChainId: number,
p: CommonPayload | CompositePayload,
tokenCampaignsRes: PromiseSettledResult<
CacheAxiosResponse<MerkleXYZV4CampaignsResponse, any>
CacheAxiosResponse<MerkleXYZV4CampaignsResponse, unknown>
>,
) {
if (tokenCampaignsRes && tokenCampaignsRes.status === "fulfilled") {
Expand Down Expand Up @@ -111,7 +120,7 @@ type GettersList = PartialRecord<HandlerTypes, [HandlerTypes, APYHandler]>;

async function getAdditionalAPYs(
network: NetworkType,
tokenEntries: (readonly [string, CommonPayload | CompositePayload])[],
tokenEntries: (readonly [Address, CommonPayload | CompositePayload])[],
) {
const uniqueGetters = tokenEntries.reduce<GettersList>((acc, [_, v]) => {
if (v.type === "composite") {
Expand Down Expand Up @@ -144,4 +153,4 @@ async function getAdditionalAPYs(
return additionalAPYs;
}

export { getAPYMerkle };
export { getAPYMerkle, getAPYMerkle_withFilter };
26 changes: 5 additions & 21 deletions src/tokens/apy/merkle/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import type { PartialRecord } from "../../../core/utils";
import type { APYHandler } from "../constants";
import { getAPYMidas } from "../midas";
import { TOKENS as TOKENS_MIDAS } from "../midas/constants";
import { getAPYYieldsreserve } from "../yieldsreserve";
import { TOKENS as TOKENS_YIELDRESERVE } from "../yieldsreserve/constants";

export const PROTOCOL = "merkle.xyz";

Expand All @@ -16,9 +14,7 @@ export interface CommonPayload {
}

export interface CompositePart {
handler:
| { getter: APYHandler; type: "midas" }
| { getter: APYHandler; type: "yieldsreserve" };
handler: { getter: APYHandler; type: "midas" };
token: Address;
fraction: number;
}
Expand All @@ -30,25 +26,13 @@ export interface CompositePayload {
tokens: Array<CompositePart>;
}

export type MerklePayload = CommonPayload | CompositePayload;

export const TOKENS: PartialRecord<
NetworkType,
Record<Address, CommonPayload | CompositePayload> // symbol to pool
Record<Address, MerklePayload> // symbol to pool
> = {
Mainnet: {
"0xe72b141df173b999ae7c1adcbf60cc9833ce56a8": {
id: "0x9ebe8c8e7a8d00b6085302e78cdba319932898c7",
symbol: "ETHPlus",
type: "composite",
tokens: [
{
handler: { getter: getAPYYieldsreserve, type: "yieldsreserve" },
token:
TOKENS_YIELDRESERVE.Mainnet?.["ETH+"]?.address || ("" as Address),
fraction: 1,
},
],
},
},
Mainnet: {},
Etherlink: {
"0x942644106B073E30D72c2C5D7529D5C296ea91ab": {
id: "0x942644106B073E30D72c2C5D7529D5C296ea91ab",
Expand Down
40 changes: 31 additions & 9 deletions src/tokens/tokenExtraCollateralAPY/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { NetworkType } from "@gearbox-protocol/sdk";
import type { Address } from "viem";
import type { PartialRecord } from "../../core/utils";
import type { Apy } from "../apy";
import { type Apy, getAPYMerkle_withFilter } from "../apy";

export interface ExtraCollateralAPY extends Omit<Apy, "protocol"> {
pool: Address;
// absolute apy completely replaces apy value of token for given pool
// relative apy adds to the apy value of token for given pool
type: "relative" | "absolute";
}

Expand All @@ -16,17 +18,37 @@ export type TokenExtraCollateralAPYHandler = (
network: NetworkType,
) => Promise<TokenExtraCollateralAPYResult>;

interface ExtraCollateralAPYPayload extends Omit<ExtraCollateralAPY, "value"> {
value: { getter: (network: NetworkType) => Promise<number> };
}

const ETHPlus = "0xE72B141DF173b999AE7c1aDcbF60Cc9833Ce56a8";

export const EXTRA_APY: PartialRecord<
NetworkType,
Array<ExtraCollateralAPY>
Array<ExtraCollateralAPYPayload>
> = {
Mainnet: [
// {
// pool: "0xff94993fa7ea27efc943645f95adb36c1b81244b", // WSTETH_POOL
// address: "0x7a4EffD87C2f3C55CA251080b1343b605f327E3a", // RSTETH
// symbol: "rstETH",
// value: 0.34,
// type: "relative",
// },
{
pool: "0x9396dcbf78fc526bb003665337c5e73b699571ef", // kpk WETH
address: ETHPlus, // ETH+
symbol: "ETH+",
value: {
getter: async network => {
const r = await getAPYMerkle_withFilter(network, [
[
ETHPlus,
{
id: "0x9ebe8c8e7a8d00b6085302e78cdba319932898c7",
symbol: "ETHPlus",
type: "common",
},
],
]);
return r[ETHPlus]?.apys[0]?.value || 0;
},
},
type: "relative",
},
],
};
25 changes: 19 additions & 6 deletions src/tokens/tokenExtraCollateralAPY/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ const getTokenExtraCollateralAPY: TokenExtraCollateralAPYHandler =
async network => {
const rewards = EXTRA_APY[network] || [];

const result = rewards.reduce<TokenExtraCollateralAPYResult>((acc, p) => {
const address = p.address.toLowerCase() as Address;
const pool = p.pool.toLowerCase() as Address;
const apyResponse = await Promise.allSettled(
rewards.map(p => p.value.getter(network)),
);

acc[address] = [...(acc[address] || []), { ...p, address, pool }];
const result = rewards.reduce<TokenExtraCollateralAPYResult>(
(acc, { value: _, ...p }, index) => {
const address = p.address.toLowerCase() as Address;
const pool = p.pool.toLowerCase() as Address;

return acc;
}, {});
const resp = apyResponse[index];
const value = resp?.status === "fulfilled" ? resp.value : 0;

acc[address] = [
...(acc[address] || []),
{ ...p, address, pool, value },
];

return acc;
},
{},
);

return result;
};
Expand Down