Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APR Services - Add some yield tokens APR to linear pools #396

Merged
merged 48 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e6a65b3
Created a service to fetch yield tokens APR and push into DB
Jun 30, 2023
1f18d5c
Merge remote-tracking branch 'origin/v3-canary' into non-reaper-yield…
Jun 30, 2023
27ca26d
Adding Apr Service to Mainnet network
Jul 3, 2023
3d84c4b
Added yield tokens fetch funcionality directly on beethovenx-backend,…
Jul 7, 2023
6120e3a
Adapting contracts from apr handler to ethers instead of viem;
Jul 8, 2023
65211ed
Changing apr type if pool type is linear;
Jul 8, 2023
304988e
removing viem
Jul 8, 2023
5cc075b
Merge commit 'fccc29b6e65ffd3df41b7b7de0c2e407e8de2c59' into non-reap…
Jul 13, 2023
11cd519
Fixing Ovix APR;
Jul 13, 2023
a1a20dd
Redesigning Ib Apr Handlers to be more scalable and open to new netwo…
Jul 28, 2023
b3d5575
adding interface to default, ankr and aave apr handlers;
Jul 28, 2023
65047bb
Adding multichain support;
Aug 1, 2023
19a48fc
Types files for ankr and default-fetch; (Missing in the last commit)
Aug 1, 2023
bfe33c1
Merge commit 'a0eb08ebd453441e8f566fb03cc684ec8b4e324d' into non-reap…
Aug 1, 2023
a7b904b
Creating new migration file;
Aug 2, 2023
4cff5b7
Removing test route;
Aug 2, 2023
1e74f53
removing unused imports;
Aug 7, 2023
6b00046
Removing ethers-multicall-provider package
Aug 7, 2023
8c2432e
removing undefined from "group" type
Aug 7, 2023
500f6c4
Moving tokens and types to apr-handler file;
Aug 9, 2023
4d97f48
Using prismaId instead of chain id;
Aug 11, 2023
37366a4
Checking if the pool is linear boosted by the token address;
Aug 18, 2023
32b5a52
Renaming ib-yield-apr-handlers to base-apr-handlers
Aug 21, 2023
74d2bce
Removing ib-yield-apr-handlers folder
Aug 21, 2023
8c04318
Refactoring all code to be more scalable;
Aug 24, 2023
8f040cd
removing aave tokens unused;
Aug 24, 2023
85f76fd
Renaming aprConfig to IbAprConfig;
Aug 29, 2023
c509044
Removing Reaper Crypt Apr Service;
Aug 29, 2023
3d568ca
Removing services that are already in the ib-yield service;
Aug 29, 2023
ae0d54c
Removing test route;
Aug 29, 2023
7913842
Merge branch 'v3-canary' into non-reaper-yield-tokens-apr
Aug 29, 2023
98e9df6
fixing base network incompatibilities;
Aug 29, 2023
fd7f136
fixing optional beefy property in network config;
Aug 29, 2023
a836720
Removing all unused functions of liquid staked base apr, left just xB…
Aug 29, 2023
114386d
Renaming AprConfig to IbAprConfig;
Aug 29, 2023
9ac7a10
clean up types
franzns Sep 1, 2023
a5ca109
simplify ib-tokens-apr service
franzns Sep 1, 2023
97a795f
change default handler, adapt token lists
franzns Sep 4, 2023
ea59577
fix percentage
franzns Sep 4, 2023
1a9352e
add try catch
franzns Sep 4, 2023
c174806
Changing the ib yield filter to network config;
Sep 4, 2023
b00f57d
ibyield flag
franzns Sep 5, 2023
21cd9ae
cleanup
franzns Sep 5, 2023
1261ec6
dont use nested query for apr
franzns Sep 5, 2023
5563895
Merge branch 'v3-canary' into non-reaper-yield-tokens-apr
franzns Sep 5, 2023
e68f06a
lower case all addresses in configs
franzns Sep 5, 2023
c511a9b
Merge branch 'v3-canary' into non-reaper-yield-tokens-apr
franzns Sep 5, 2023
57099bf
adding rocket eth apr
franzns Sep 6, 2023
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
3 changes: 3 additions & 0 deletions modules/network/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { GithubContentService } from '../content/github-content.service';
import { gaugeSubgraphService } from '../subgraphs/gauge-subgraph/gauge-subgraph.service';
import { coingeckoService } from '../coingecko/coingecko.service';
import { CoingeckoPriceHandlerService } from '../token/lib/token-price-handlers/coingecko-price-handler.service';
import { IbTokensAprService } from "../pool/lib/apr-data-sources/ib-tokens-apr.service";
import { networkContext } from "./network-context.service";

const mainnetNetworkData: NetworkData = {
chain: {
Expand Down Expand Up @@ -157,6 +159,7 @@ export const mainnetNetworkConfig: NetworkConfig = {
contentService: new GithubContentService(),
provider: new ethers.providers.JsonRpcProvider(mainnetNetworkData.rpcUrl),
poolAprServices: [
new IbTokensAprService(),
new WstethAprService(tokenService, mainnetNetworkData.lido!.wstEthContract),
new ReaperCryptAprService(
mainnetNetworkData.reaper.linearPoolFactories,
Expand Down
2 changes: 2 additions & 0 deletions modules/pool/lib/apr-data-sources/apr-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Dictionary } from 'lodash'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still there :)

export interface YearnVault {
inception: number;
address: string;
Expand Down
59 changes: 59 additions & 0 deletions modules/pool/lib/apr-data-sources/ib-tokens-apr.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PoolAprService } from "../../pool-types";
import { PrismaPoolWithExpandedNesting } from "../../../../prisma/prisma-types";
import { prisma } from "../../../../prisma/prisma-client";
import { networkContext } from "../../../network/network-context.service";
import { prismaBulkExecuteOperations } from "../../../../prisma/prisma-util";
import { fetchAllAprs } from "../../../token/lib/token-apr-handler/fetch-all";
import { TokenApr } from "../../../token/lib/token-apr-handler/types";
import { PrismaPoolAprItemGroup } from "@prisma/client";

export class IbTokensAprService implements PoolAprService {

getAprServiceName(): string {
return "IbTokensAprService";
}

public async updateAprForPools(pools: PrismaPoolWithExpandedNesting[]): Promise<void> {
const operations: any[] = [];
const aprs = await this.fetchYieldTokensApr();
const tokenYieldPools = pools.filter((pool) => {
return pool.tokens.find((token) => {
return Array.from(aprs.keys()).map((key) => key.toLowerCase()).includes(token.address.toLowerCase());
})
}
);
for (const pool of tokenYieldPools) {
for (const token of pool.tokens) {
if ((aprs.get(token.address) !== undefined)) {
const tokenSymbol = token.token.symbol ?? (<TokenApr>aprs.get(token.address)).name
const itemId = `${ pool.id }-${ tokenSymbol }-yield-apr`

operations.push(prisma.prismaPoolAprItem.upsert({
where: { id_chain: { id: itemId, chain: networkContext.chain } },
create: {
id: itemId,
chain: networkContext.chain,
poolId: pool.id,
title: `${ tokenSymbol} APR`,
apr: aprs.get(token.address)?.val ?? 0,
group: (aprs.get(token.address)?.group as PrismaPoolAprItemGroup) ?? null,
type: pool.type === 'LINEAR' ? 'LINEAR_BOOSTED' : 'IB_YIELD',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is not enough, you'll need to check if it is the wrapped token when it is in a linear pool. only then it is linear_boosted, otherwise its IB_yield. E.g. for a wsteth/rfWSTETH linear pool

},
update: {
title: `${ tokenSymbol } APR`,
apr: aprs.get(token.address)?.val
},
}));
}
}
}

await prismaBulkExecuteOperations(operations);
}

private async fetchYieldTokensApr(): Promise<Map<string, TokenApr>> {
const data = await fetchAllAprs()
return new Map<string, TokenApr>(data.filter((apr)=>!isNaN(apr.val)).map((apr) => [apr.address, apr]));
}

}
8 changes: 8 additions & 0 deletions modules/pool/pool.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ enum PrismaPoolAprItemGroup {
OVERNIGHT
REAPER
YEARN
IDLE
TRANCHESS
GEARBOX
AAVE
ANKR
TESSERA
TETU
OVIX
}

model PrismaPoolCategory {
Expand Down
16 changes: 16 additions & 0 deletions modules/token/lib/token-apr-handler/fetch-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { tokens } from "./tokens";
import { TokenApr } from "./types";

export const fetchAllAprs = async (): Promise<TokenApr[]> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a proper function for this

const res = await Promise.all(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any of these fetches can fail for various reasons. I'd rather do that sequential (no need to optimize in the cron) and log proper errors to sentry

tokens.map(async ({ name, group, fetchFn }) => {
const fetchedResponse: {[key:string]:number} = await fetchFn()
return Object.entries(fetchedResponse).map(([address, aprValue]) => ({
val: aprValue * 0.0001 /*Values come in BPS 10000=>100% */,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the apr services should already provide values in %

group,
name,
address
}))
}));
return res.flat();
}
Loading