Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
skords committed Dec 3, 2024
1 parent 51c06f8 commit 97dfbea
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/adaptors/avantis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const utils = require('../utils');
const sdk = require('@defillama/sdk');
const { request, gql } = require('graphql-request');
const { chunkArray, calculateTrancheTotal } = require('./helpers');
const { getBlocksByTime } = require('../utils');
const { getBlocksByTime, getData } = require('../utils');

const ADDRESSES = {
base: {
Expand Down Expand Up @@ -97,16 +97,25 @@ const fetchTransfersForFeeDistributedIds = async (ids) => {
return { totalJunior: totalJunior / 7, totalSenior: totalSenior / 7 };
};

// NOTE: OUR SUBGRAPH IS NOT CAUGHT UP TO DATE, SO WE ARE USING THE API FOR NOW
// -----------------------------------------------------------------------------
// We will reenable time travel once our subgraph is caught up
const main = async (timestamp = null) => {
timestamp = timestamp ? parseInt(timestamp) : Math.floor(Date.now() / 1000);
// timestamp = timestamp ? parseInt(timestamp) : Math.floor(Date.now() / 1000);

// NOTE: OUR SUBGRAPH IS NOT CAUGHT UP TO DATE, SO WE ARE USING THE API FOR NOW
// -----------------------------------------------------------------------------
// Get total fees distributed for junior and senior tranches
const feesDistributedIds = await fetchFeeDistributedIds(timestamp);
const { totalJunior, totalSenior } = await fetchTransfersForFeeDistributedIds(
feesDistributedIds
);
// const feesDistributedIds = await fetchFeeDistributedIds(timestamp);
// const { totalJunior, totalSenior } = await fetchTransfersForFeeDistributedIds(
// feesDistributedIds
// );

// const [block] = await getBlocksByTime([timestamp], 'base');

const [block] = await getBlocksByTime([timestamp], 'base');
const { meta } = await getData(
'https://api.avantisfi.com/v1/vault/returns-7-days'
);

// Get TVL for junior and senior tranches
let [juniorTvl, seniorTvl] = await Promise.all([
Expand All @@ -115,23 +124,25 @@ const main = async (timestamp = null) => {
target: ADDRESSES.base.USDC,
params: [ADDRESSES.base.AvantisJuniorTranche],
chain: 'base',
block: block,
// block: block,
}),
sdk.api.abi.call({
abi: 'erc20:balanceOf',
target: ADDRESSES.base.USDC,
params: [ADDRESSES.base.AvantisSeniorTranche],
chain: 'base',
block: block,
// block: block,
}),
]);

juniorTvl = juniorTvl.output / 1e6;
seniorTvl = seniorTvl.output / 1e6;

// Calculate daily returns for junior and senior tranches
const juniorDailyReturns = totalJunior / juniorTvl;
const seniorDailyReturns = totalSenior / seniorTvl;
// const juniorDailyReturns = totalJunior / juniorTvl;
// const seniorDailyReturns = totalSenior / seniorTvl;
const juniorDailyReturns = meta.averageJrFees / juniorTvl;
const seniorDailyReturns = meta.averageSrFees / seniorTvl;

// Calculate APY for junior and senior tranches
const juniorApy = (1 + juniorDailyReturns) ** 365 - 1;
Expand Down Expand Up @@ -162,6 +173,6 @@ const main = async (timestamp = null) => {
};

module.exports = {
timetravel: true,
timetravel: false,
apy: main,
};

0 comments on commit 97dfbea

Please sign in to comment.