-
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
IB Yield APR Service - Adding new tokens and handlers #451
Changes from all commits
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 |
---|---|---|
@@ -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 }; | ||
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. why do 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. 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; | ||
} | ||
} |
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.
same token different address?
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.
No, this is the stUSD+, the other one is the USD+
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.
ah didn't catch that 👍