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

IB Yield APR Service - Adding new tokens and handlers #451

Merged
merged 4 commits into from
Sep 13, 2023
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
22 changes: 22 additions & 0 deletions modules/network/apr-config-types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export interface IbAprConfig {
aave?: AaveAprConfig;
ankr?: AnkrAprConfig;
bloom?: BloomAprConfig;
beefy?: BeefyAprConfig;
euler?: EulerAprConfig;
gearbox?: GearBoxAprConfig;
idle?: IdleAprConfig;
maker?: MakerAprConfig;
ovix?: OvixAprConfig;
reaper?: ReaperAprConfig;
tessera?: TesseraAprConfig;
Expand Down Expand Up @@ -55,6 +57,16 @@ export interface BeefyAprConfig {
};
}

export interface BloomAprConfig {
tokens: {
[tokenName: string]: {
address: string;
feedAddress: string;
isIbYield?: boolean;
};
};
}

export interface EulerAprConfig {
subgraphUrl: string;
tokens: {
Expand Down Expand Up @@ -87,6 +99,16 @@ export interface IdleAprConfig {
};
}

export interface MakerAprConfig {
tokens: {
[tokenName: string]: {
address: string;
potAddress: string;
isIbYield?: boolean;
};
};
}

export interface OvixAprConfig {
tokens: {
[tokenName: string]: {
Expand Down
34 changes: 34 additions & 0 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,47 @@ const arbitrumNetworkData: NetworkData = {
},
},
},
reaper: {
onchainSource: {
averageAPRAcrossLastNHarvests: 5,
tokens: {
rfGrainDAI: {
address: '0x12f256109e744081f633a827be80e06d97ff7447',
},
rfGrainUSDT: {
address: '0x0179bac7493a92ac812730a4c64a0b41b7ea0ecf',
},
rfGrainUSDC: {
address: '0xaeacf641a0342330ec681b57c0a6af0b71d5cbff',
},
},
},
},
defaultHandlers: {
wstETH: {
tokenAddress: '0x5979d7b546e38e414f7e9822514be443a4800529',
sourceUrl: 'https://eth-api.lido.fi/v1/protocol/steth/apr/sma',
path: 'data.smaApr',
isIbYield: true,
},
rETH: {
tokenAddress: '0xec70dcb4a1efa46b8f2d97c310c9c4790ba5ffa8',
sourceUrl: 'https://rocketpool.net/api/mainnet/payload',
path: 'rethAPR',
isIbYield: true,
},
cbETH: {
tokenAddress: '0x1debd73e752beaf79865fd6446b0c970eae7732f',
sourceUrl: 'https://api.exchange.coinbase.com/wrapped-assets/CBETH/',
path: 'apy',
scale: 1,
},
sfrxETH: {
tokenAddress: '0x95ab45875cffdba1e5f451b950bc2e42c0053f39',
sourceUrl: 'https://api.frax.finance/v2/frxeth/summary/latest',
path: 'sfrxethApr',
isIbYield: true,
},
},
},
beefy: {
Expand Down
23 changes: 23 additions & 0 deletions modules/network/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ const avalancheNetworkData: NetworkData = {
},
},
},
defaultHandlers: {
sAVAX: {
tokenAddress: '0x2b2c81e08f1af8835a78bb2a90ae924ace0ea4be',
sourceUrl: 'https://api.benqi.fi/liquidstaking/apr',
path: 'apr',
scale: 1,
},
yyAVAX: {
tokenAddress: '0xf7d9281e8e363584973f946201b82ba72c965d27',
sourceUrl: 'https://staging-api.yieldyak.com/yyavax',
path: 'yyAVAX.apr',
},
ggAVAX: {
tokenAddress: '0xa25eaf2906fa1a3a13edac9b9657108af7b703e3',
sourceUrl: 'https://ceres.gogopool.com',
path: 'ggAVAXMonthlyInterestMonth.value',
// According to solarcurve, the AVAX Monthly Interest must be multiplied by -12 to represent the APR in normal scale, for example, if the monthly interest is -0,15, the APR would be -0,15 * -12 = 1,8%.
// @solarcurve: We estimate by multiplying that value by -12 since its the exchange rate of AVAX -> ggAVAX, which will always return less ggAVAX than AVAX
// How this -12 became -8,333? It's because the scale parameter is used to divide the number, and the final apr percentage is in decimal format (1,8% = 0,018), so if:
// M * -12 = A (M is monthly rate and A is APR) => (M/x) = (A/100) => (A / -12x) = (A / 100) [replacing M by A/-12] => x = 100/-12 = -8,33333
scale: -8.3333,
},
},
},
beefy: {
linearPools: [''],
Expand Down
24 changes: 23 additions & 1 deletion modules/network/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const mainnetNetworkData: NetworkData = {
aTokenAddress: '0x018008bfb33d285247a21d44e50697654f754e63',
wrappedTokens: {
waDAI: '0x098256c06ab24f5655c5506a6488781bd711c14b',
stataEthDAI: '0x098256c06ab24f5655c5506a6488781bd711c14b',
stataEthDAI: '0xeb708639e8e518b86a916db3685f90216b1c1c67',
},
},
wETH: {
Expand All @@ -187,6 +187,14 @@ export const mainnetNetworkData: NetworkData = {
},
},
},
bloom: {
tokens: {
tbyFeb1924: {
address: '0xc4cafefbc3dfea629c589728d648cb6111db3136',
feedAddress: '0xde1f5f2d69339171d679fb84e4562febb71f36e6',
},
},
},
euler: {
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet',
tokens: {
Expand Down Expand Up @@ -222,6 +230,14 @@ export const mainnetNetworkData: NetworkData = {
},
},
},
maker: {
tokens: {
sDAI: {
address: '0x83f20f44975d03b1b09e64809b757c47f942beea',
potAddress: '0x197e90f9fad81970ba7976f33cbd77088e5d7cf7',
},
},
},
tessera: {
tokens: {
sAPE: {
Expand Down Expand Up @@ -299,6 +315,12 @@ export const mainnetNetworkData: NetworkData = {
path: 'wjauraApy',
isIbYield: true,
},
ETHx: {
tokenAddress: '0x0f7f961648ae6db43c75663ac7e5414eb79b5704',
sourceUrl: 'https://universe.staderlabs.com/eth/apy',
path: 'value',
isIbYield: true,
},
},
},
beefy: {
Expand Down
12 changes: 12 additions & 0 deletions modules/network/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ const polygonNetworkData: NetworkData = {
path: 'value',
isIbYield: true,
},
overnightUSDPlus: {
tokenAddress: '0x5d9d8509c522a47d9285b9e4e9ec686e6a580850',
sourceUrl: 'https://api.overnight.fi/optimism/usd+/fin-data/avg-apr/week',
path: 'value',
group: 'OVERNIGHT',
},
overnightstUSDPlus: {
Copy link
Contributor

Choose a reason for hiding this comment

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

same token different address?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is the stUSD+, the other one is the USD+

Copy link
Contributor

Choose a reason for hiding this comment

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

ah didn't catch that 👍

tokenAddress: '0x5a5c6aa6164750b530b8f7658b827163b3549a4d',
sourceUrl: 'https://api.overnight.fi/optimism/usd+/fin-data/avg-apr/week',
path: 'value',
group: 'OVERNIGHT',
},
wbETH: {
tokenAddress: '0xa2e3356610840701bdf5611a53974510ae27e2e1',
sourceUrl:
Expand Down
6 changes: 6 additions & 0 deletions modules/network/zkevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ const zkevmNetworkData: NetworkData = {
path: 'data.smaApr',
isIbYield: true,
},
rETH: {
tokenAddress: '0xb23c20efce6e24acca0cef9b7b7aa196b84ec942',
sourceUrl: 'https://rocketpool.net/api/mainnet/payload',
path: 'rethAPR',
isIbYield: true,
},
},
},
beefy: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { YearnAprHandler } from './sources/yearn-apr-handler';
import { ReaperCryptAprHandler } from './sources/reaper-crypt-apr-handler';
import { BeefyAprHandler } from './sources/beefy-apr-handler';
import { IbAprConfig } from '../../../../network/apr-config-types';
import { MakerAprHandler } from './sources/maker-apr-handler';
import { BloomAprHandler } from './sources/bloom-apr-handler';

export class IbLinearAprHandlers {
private handlers: AprHandler[] = [];
Expand All @@ -38,6 +40,10 @@ export class IbLinearAprHandlers {
const beefyHandler = new BeefyAprHandler(aprConfig.beefy);
handlers.push(beefyHandler);
}
if (aprConfig.bloom) {
const bloomAprHandler = new BloomAprHandler(aprConfig.bloom);
handlers.push(bloomAprHandler);
}
if (aprConfig.euler) {
const eulerHandler = new EulerAprHandler(aprConfig.euler);
handlers.push(eulerHandler);
Expand All @@ -50,6 +56,10 @@ export class IbLinearAprHandlers {
const idleHandler = new IdleAprHandler(aprConfig.idle);
handlers.push(idleHandler);
}
if (aprConfig.maker) {
const makerHandler = new MakerAprHandler(aprConfig.maker);
handlers.push(makerHandler);
}
if (aprConfig.ovix) {
const ovixHandler = new OvixAprHandler({
...aprConfig.ovix,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const abi = [{
"inputs":[],
"name":"currentRate",
"outputs":[{
"internalType":"uint256",
"name":"",
"type":"uint256"
}],
"stateMutability":"view",
"type":"function"
}] as const
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const abi = [{
constant: true,
inputs: [],
name: "dsr",
outputs: [{ "internalType": "uint256", "name": "", "type": "uint256" }],
payable: false,
stateMutability: "view",
type: "function"
}] as const
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { AprHandler } from '../ib-linear-apr-handlers';
import { BloomAprConfig } from '../../../../../network/apr-config-types';
import { getContractAt } from '../../../../../web3/contract';
import { abi as bloomBpsFeed } from './abis/bloom-bps-feed';
import * as Sentry from '@sentry/node';

export class BloomAprHandler implements AprHandler {
group: string | undefined;

tokens: BloomAprConfig['tokens'];

constructor(aprConfig: BloomAprConfig) {
this.tokens = aprConfig.tokens;
}

async getAprs(): Promise<{ [p: string]: { apr: number; isIbYield: boolean } }> {
const aprs: { [p: string]: { apr: number; isIbYield: boolean } } = {};
for (const { address, feedAddress, isIbYield } of Object.values(this.tokens)) {
try {
const feedContract = getContractAt(feedAddress, bloomBpsFeed);
const currentRate = await feedContract.currentRate();
if (!currentRate) {
continue;
}
const tokenApr = (Number(currentRate) - 10000) / 10000;
aprs[address] = { apr: tokenApr, isIbYield: isIbYield ?? false };
Copy link
Contributor

Choose a reason for hiding this comment

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

why do isIbYield: isIbYield ?? false ? just set it to false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made like this because I didn't know if this apr handler would be used for non-ib-yield tokens in the future

} catch (error) {
console.error(`Bloom APR Failed for token ${address}: `, error);
Sentry.captureException(`Bloom APR Failed for token ${address}: ${error}`);
}
}
return aprs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { AprHandler } from '../ib-linear-apr-handlers';
import { MakerAprConfig } from '../../../../../network/apr-config-types';
import { getContractAt } from '../../../../../web3/contract';
import { abi as makerPotAbi } from './abis/maker-pot';
import * as Sentry from '@sentry/node';

export class MakerAprHandler implements AprHandler {
group: string | undefined;
tokens: {
[tokenName: string]: {
address: string;
potAddress: string;
isIbYield?: boolean;
};
};

constructor(aprConfig: MakerAprConfig) {
this.tokens = aprConfig.tokens;
}

async getAprs(): Promise<{ [p: string]: { apr: number; isIbYield: boolean } }> {
const aprs: { [p: string]: { apr: number; isIbYield: boolean } } = {};
for (const { address, potAddress, isIbYield } of Object.values(this.tokens)) {
try {
const potContract = getContractAt(potAddress, makerPotAbi);
const dsr = await potContract.dsr();
if (!dsr) {
continue;
}
const tokenApr = (Number(dsr) * 10 ** -27 - 1) * 365 * 24 * 60 * 60;
aprs[address] = { apr: tokenApr, isIbYield: isIbYield ?? false };
} catch (error) {
console.error(`Maker APR Failed for token ${address}: `, error);
Sentry.captureException(`Maker APR Failed for token ${address}: ${error}`);
}
}
return aprs;
}
}