Skip to content

Commit

Permalink
Merge pull request #1924 from solv-finance-dev/master
Browse files Browse the repository at this point in the history
Change the method of obtaining navs.
  • Loading branch information
dtmkeng committed Sep 18, 2024
2 parents 310cbbd + 1420945 commit c9b392e
Showing 1 changed file with 38 additions and 45 deletions.
83 changes: 38 additions & 45 deletions fees/solv-finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ const chains: {
[chain: Chain]: { deployedAt: number };
} = {
[CHAIN.ETHEREUM]: {
deployedAt: 1681084800,
deployedAt: 1726531200,
},
[CHAIN.BSC]: {
deployedAt: 1679097600,
deployedAt: 1726531200,
},
[CHAIN.ARBITRUM]: {
deployedAt: 1682380800,
deployedAt: 1726531200,
},
[CHAIN.MANTLE]: {
deployedAt: 1692835200,
deployedAt: 1726531200,
},
[CHAIN.MERLIN]: {
deployedAt: 1710892800,
deployedAt: 1726531200,
},
[CHAIN.CORE]: {
deployedAt: 1726012800,
deployedAt: 1726531200,
},
};

Expand Down Expand Up @@ -79,69 +79,62 @@ async function pool(options: FetchOptions, contracts: any): Promise<Balances> {
return options.createBalances();
}
const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain);
const concretes = await concrete(pools, options);
const shareConcretes = await concrete(pools, options);

const fromTimestamp = getTimestampAtStartOfDayUTC(options.fromTimestamp);
const toTimestamp = getTimestampAtStartOfDayUTC(options.toTimestamp);

let poolNavs: any[] = [];
for (const pool of pools) {
const [todayNav, yesterdayNav] = await options.api.multiCall({
calls: [{
target: pool.navOracle,
params: [pool.poolId, toTimestamp],
}, {
target: pool.navOracle,
params: [pool.poolId, fromTimestamp],
}],
abi: 'function getSubscribeNav(bytes32 poolId_, uint256 time_) view returns (uint256 nav_, uint256 navTime_)',
});

let nav = todayNav.nav_ - yesterdayNav.nav_;
if (nav < 0) {
nav = 0;
}
const yesterdayNavs = await options.fromApi.multiCall({
abi: 'function getSubscribeNav(bytes32 poolId_, uint256 time_) view returns (uint256 nav_, uint256 navTime_)',
calls: pools.map((pool: { navOracle: string; poolId: string }) => ({
target: pool.navOracle,
params: [pool.poolId, fromTimestamp],
})),
});

poolNavs.push(nav);
}
const todayNavs = await options.toApi.multiCall({
abi: 'function getSubscribeNav(bytes32 poolId_, uint256 time_) view returns (uint256 nav_, uint256 navTime_)',
calls: pools.map((pool: { navOracle: string; poolId: string }) => ({
target: pool.navOracle,
params: [pool.poolId, toTimestamp],
})),
});

const poolBaseInfos = await options.api.multiCall({
abi: `function slotBaseInfo(uint256 slot_) view returns (tuple(address issuer, address currency, uint64 valueDate, uint64 maturity, uint64 createTime, bool transferable, bool isValid))`,
calls: pools.map((index: { contractAddress: string | number; openFundShareSlot: any; }) => ({
target: concretes[index.contractAddress],
target: shareConcretes[index.contractAddress],
params: [index.openFundShareSlot]
})),
});

const totalValues = await options.api.multiCall({
const shareTotalValues = await options.api.multiCall({
abi: 'function slotTotalValue(uint256) view returns (uint256)',
calls: pools.map((index: { contractAddress: string | number; openFundShareSlot: any; }) => ({
target: concretes[index.contractAddress],
target: shareConcretes[index.contractAddress],
params: [index.openFundShareSlot]
})),
});

const poolDecimalList = await options.api.multiCall({
abi: "uint8:decimals",
calls: poolBaseInfos.map(i => i[1]),
})

const dailyFees = options.createBalances();
for (let i = 0; i < pools.length; i++) {
const poolNav = poolNavs[i];
const poolNavIncrease = todayNavs[i].nav_ - yesterdayNavs[i].nav_;
const poolBaseInfo = poolBaseInfos[i];
const totalValue = totalValues[i];
const decimals = poolDecimalList[i];
const shareTotalValue = shareTotalValues[i];

if (poolNavIncrease <= 0) {
continue;
}
if (shareTotalValue == 0) {
continue;
}

const token = `${options.chain}:${poolBaseInfo.currency}`;
const total = BigNumber(totalValue)
// PoolFee = (ShareTotalValue / 10^(ShareDecimals)) * (PoolNavIncrease / 10^(PoolTokenDecimals)) * 10^(PoolTokenDecimals)
const poolFee = BigNumber(shareTotalValue)
.dividedBy(BigNumber(10).pow(18))
.times(BigNumber(10).pow(decimals))
.times(
BigNumber(poolNav).dividedBy(BigNumber(10).pow(decimals))
);

dailyFees.addBalances({ [token]: total.toNumber() });
.times(BigNumber(poolNavIncrease));
dailyFees.addBalances({ [token]: poolFee.toNumber() });
}

return dailyFees;
Expand Down Expand Up @@ -202,4 +195,4 @@ Object.keys(chains).forEach((chain: Chain) => {
};
});

export default adapter;
export default adapter;

0 comments on commit c9b392e

Please sign in to comment.