-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 9 commits
e6a65b3
1f18d5c
27ca26d
3d84c4b
6120e3a
65211ed
304988e
5cc075b
11cd519
a1a20dd
b3d5575
65047bb
19a48fc
bfe33c1
a7b904b
4cff5b7
1e74f53
6b00046
8c2432e
500f6c4
4d97f48
37366a4
32b5a52
74d2bce
8c04318
8f040cd
85f76fd
c509044
3d568ca
ae0d54c
7913842
98e9df6
fd7f136
a836720
114386d
9ac7a10
a5ca109
97a795f
ea59577
1a9352e
c174806
b00f57d
21cd9ae
1261ec6
5563895
e68f06a
c511a9b
57099bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { Dictionary } from 'lodash' | ||
|
||
export interface YearnVault { | ||
inception: number; | ||
address: string; | ||
|
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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])); | ||
} | ||
|
||
} |
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[]> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a proper function for this |
||
const res = await Promise.all( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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% */, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still there :)