From 3b8ca8eaa26898561f3d4ee3cf9cb3223095ba86 Mon Sep 17 00:00:00 2001 From: chanson Date: Wed, 18 Sep 2024 17:47:26 +0800 Subject: [PATCH 1/4] fix pool fees logic --- fees/solv-finance/index.ts | 72 ++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 3e76946499..1015580d5a 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -79,69 +79,65 @@ async function pool(options: FetchOptions, contracts: any): Promise { 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) { + console.log(`chain: ${options.chain} poolId: ${pools[i].poolId} poolNavIncrease: ${poolNavIncrease}, skip`); + continue; + } + if (shareTotalValue == 0) { + console.log(`chain: ${options.chain} poolId: ${pools[i].poolId} shareTotalValue is 0, skip`); + continue; + } const token = `${options.chain}:${poolBaseInfo.currency}`; - const total = BigNumber(totalValue) + // PoolFee = (ShareTotalValue / 10^(ShareDecimals)) * (PoolNavIncrease / 10^(PoolTokenDecimals)) * 10^(PoolFeeDecimals) + 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() }); + console.log('chain', options.chain, 'poolId', pools[i].poolId, 'poolNavIncrease', poolNavIncrease, 'shareTotalValue', shareTotalValue, 'poolFee', poolFee.toNumber()); } return dailyFees; From 0107ce7933b2b67b5f30e8f3a83f8e170888b3cc Mon Sep 17 00:00:00 2001 From: chanson Date: Wed, 18 Sep 2024 17:50:40 +0800 Subject: [PATCH 2/4] Update index.ts --- fees/solv-finance/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 1015580d5a..62edf392d0 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -132,7 +132,7 @@ async function pool(options: FetchOptions, contracts: any): Promise { } const token = `${options.chain}:${poolBaseInfo.currency}`; - // PoolFee = (ShareTotalValue / 10^(ShareDecimals)) * (PoolNavIncrease / 10^(PoolTokenDecimals)) * 10^(PoolFeeDecimals) + // PoolFee = (ShareTotalValue / 10^(ShareDecimals)) * (PoolNavIncrease / 10^(PoolTokenDecimals)) * 10^(PoolTokenFeeDecimals) const poolFee = BigNumber(shareTotalValue) .dividedBy(BigNumber(10).pow(18)) .times(BigNumber(poolNavIncrease)); @@ -198,4 +198,4 @@ Object.keys(chains).forEach((chain: Chain) => { }; }); -export default adapter; \ No newline at end of file +export default adapter; From 325777c366f581a7e7da60a3ed67268e6f341e60 Mon Sep 17 00:00:00 2001 From: chanson Date: Wed, 18 Sep 2024 17:50:57 +0800 Subject: [PATCH 3/4] Update index.ts --- fees/solv-finance/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 62edf392d0..29a6f98826 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -132,7 +132,7 @@ async function pool(options: FetchOptions, contracts: any): Promise { } const token = `${options.chain}:${poolBaseInfo.currency}`; - // PoolFee = (ShareTotalValue / 10^(ShareDecimals)) * (PoolNavIncrease / 10^(PoolTokenDecimals)) * 10^(PoolTokenFeeDecimals) + // PoolFee = (ShareTotalValue / 10^(ShareDecimals)) * (PoolNavIncrease / 10^(PoolTokenDecimals)) * 10^(PoolTokenDecimals) const poolFee = BigNumber(shareTotalValue) .dividedBy(BigNumber(10).pow(18)) .times(BigNumber(poolNavIncrease)); From d17068a17891801774e9a56b8e2da7244e032842 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Wed, 18 Sep 2024 19:03:33 +0800 Subject: [PATCH 4/4] update deployed time del console.log --- fees/solv-finance/index.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 29a6f98826..c17ff9145c 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -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, }, }; @@ -123,11 +123,9 @@ async function pool(options: FetchOptions, contracts: any): Promise { const shareTotalValue = shareTotalValues[i]; if (poolNavIncrease <= 0) { - console.log(`chain: ${options.chain} poolId: ${pools[i].poolId} poolNavIncrease: ${poolNavIncrease}, skip`); continue; } if (shareTotalValue == 0) { - console.log(`chain: ${options.chain} poolId: ${pools[i].poolId} shareTotalValue is 0, skip`); continue; } @@ -137,7 +135,6 @@ async function pool(options: FetchOptions, contracts: any): Promise { .dividedBy(BigNumber(10).pow(18)) .times(BigNumber(poolNavIncrease)); dailyFees.addBalances({ [token]: poolFee.toNumber() }); - console.log('chain', options.chain, 'poolId', pools[i].poolId, 'poolNavIncrease', poolNavIncrease, 'shareTotalValue', shareTotalValue, 'poolFee', poolFee.toNumber()); } return dailyFees;