-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding 2 new apr handlers, bloom and maker;
- Loading branch information
Luiz Gustavo Abou Hatem De Liz
committed
Sep 8, 2023
1 parent
94f9fe3
commit 5cf2e3f
Showing
11 changed files
with
219 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
modules/pool/lib/apr-data-sources/ib-linear-apr-handlers/sources/abis/bloom-bps-feed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
9 changes: 9 additions & 0 deletions
9
modules/pool/lib/apr-data-sources/ib-linear-apr-handlers/sources/abis/maker-pot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
34 changes: 34 additions & 0 deletions
34
modules/pool/lib/apr-data-sources/ib-linear-apr-handlers/sources/bloom-apr-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} catch (error) { | ||
console.error(`Bloom APR Failed for token ${address}: `, error); | ||
Sentry.captureException(`Bloom APR Failed for token ${address}: ${error}`); | ||
} | ||
} | ||
return aprs; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
modules/pool/lib/apr-data-sources/ib-linear-apr-handlers/sources/maker-apr-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |