Skip to content

Commit

Permalink
meta pool add 7day apy
Browse files Browse the repository at this point in the history
  • Loading branch information
slasher125 committed Apr 14, 2024
1 parent 8b63080 commit e36d5ad
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/adaptors/meta-pool-eth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,44 @@ const token = '0x48AFbBd342F64EF8a9Ab1C143719b63C2AD81710';
const weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';

const apy = async () => {
const timestamp1dayAgo = Math.floor(Date.now() / 1000) - 86400;
const duration = 1; // day
const now = Math.floor(Date.now() / 1000);
const timestamp1dayAgo = now - 86400;
const timestamp7dayAgo = now - 86400 * 7;
const block1dayAgo = (
await axios.get(`https://coins.llama.fi/block/ethereum/${timestamp1dayAgo}`)
).data.height;

const block7dayAgo = (
await axios.get(`https://coins.llama.fi/block/ethereum/${timestamp7dayAgo}`)
).data.height;

const amount = 1000000000000000000n;

const exchangeRates = await Promise.all([
sdk.api.abi.call({
target: token,
abi: abi.find((m) => m.name === 'convertToAssets'),
params: [1000000000000000000n],
params: [amount],
}),
sdk.api.abi.call({
target: token,
abi: abi.find((m) => m.name === 'convertToAssets'),
params: [1000000000000000000n],
params: [amount],
block: block1dayAgo,
}),
sdk.api.abi.call({
target: token,
abi: abi.find((m) => m.name === 'convertToAssets'),
params: [amount],
block: block7dayAgo,
}),
]);

const apr =
((exchangeRates[0].output - exchangeRates[1].output) / 1e18 / duration) *
const apyBase =
((exchangeRates[0].output - exchangeRates[1].output) / 1e18) * 365 * 100;

const apyBase7d =
((exchangeRates[0].output - exchangeRates[2].output) / 1e18 / 7) *
365 *
100;

Expand All @@ -52,7 +68,8 @@ const apy = async () => {
chain: 'ethereum',
symbol: 'mpETH',
tvlUsd: totalSupply * ethPrice,
apyBase: apr,
apyBase,
apyBase7d,
underlyingTokens: [weth],
},
];
Expand Down

0 comments on commit e36d5ad

Please sign in to comment.