Skip to content

Commit

Permalink
add defillama apr adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Sep 27, 2024
1 parent b5f9c23 commit 5db419e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export default <NetworkData>{
},
},
},
defillama: [
{
defillamaPoolId: '46f3828a-cbf6-419e-8399-a83b905bf556',
tokenAddress: '0x5a7a183b6b44dc4ec2e3d2ef43f98c5152b1d76d',
},
],
reaper: {
onchainSource: {
averageAPRAcrossLastNHarvests: 5,
Expand Down
10 changes: 10 additions & 0 deletions config/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ export default <NetworkData>{
},
},
},
defillama: [
{
defillamaPoolId: '5a9c2073-2190-4002-9654-8c245d1e8534',
tokenAddress: '0x6dc3ce9c57b20131347fdc9089d740daf6eb34c5',
},
{
defillamaPoolId: '46f3828a-cbf6-419e-8399-a83b905bf556',
tokenAddress: '0xf073bac22dab7faf4a3dd6c6189a70d54110525c',
},
],
euler: {
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet',
tokens: {
Expand Down
6 changes: 6 additions & 0 deletions config/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ export default <NetworkData>{
// and search for the vault address in the link: https://api.beefy.finance/vaults
},
},
defillama: [
{
defillamaPoolId: '46f3828a-cbf6-419e-8399-a83b905bf556',
tokenAddress: '0x5a7a183b6b44dc4ec2e3d2ef43f98c5152b1d76d',
},
],
reaper: {
subgraphSource: {
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/byte-masons/multi-strategy-vaults-optimism',
Expand Down
4 changes: 4 additions & 0 deletions modules/network/apr-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export interface YbAprConfig {
};
etherfi?: string;
sveth?: boolean;
defillama?: {
defillamaPoolId: string;
tokenAddress: string;
}[];
defaultHandlers?: DefaultHandlerAprConfig;
fixedAprHandler?: FixedAprConfig;
}
Expand Down
1 change: 1 addition & 0 deletions modules/pool/lib/apr-data-sources/yb-apr-handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const sourceToHandler = {
etherfi: sources.Etherfi,
sveth: sources.svEthAprHandler,
dforce: sources.DForce,
defillama: sources.Defillama,
};

export class YbAprHandlers {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { AprHandler } from '..';
import { YbAprConfig } from '../../../../../network/apr-config-types';

const query = `
{
osTokens {
apy
}
}
`;

const requestQuery = {
query,
};

interface Response {
data: {
timestamp: string;
apyBase: number;
}[];
}

const baseURL = 'https://yields.llama.fi/chart/';

export class Defillama implements AprHandler {
constructor(private config: YbAprConfig['defillama']) {}

async getAprs() {
const aprs: { token: string; apr: number }[] = [];

for (const token of this.config!) {
{
const response = await fetch(baseURL + token.defillamaPoolId);

const data = (await response.json()) as Response;

const apr = Number(data.data[data.data.length - 1].apyBase) / 100;
aprs.push({ token: token.tokenAddress, apr });
}
}
return Object.fromEntries(aprs.map(({ token, apr }) => [token, { apr, isIbYield: true }]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './yieldnest-apr-handler';
export * from './etherfi-apr-handler';
export * from './sv-eth';
export * from './dforce-apr-handler';
export * from './defillama-apr-handler';

0 comments on commit 5db419e

Please sign in to comment.