From c155be4c11ee3c9ea468360761e7ac4d6bcb1fa7 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Mon, 9 Sep 2024 18:49:55 +0800 Subject: [PATCH 01/11] add protocolFees poolFees --- fees/solv-finance/index.ts | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 fees/solv-finance/index.ts diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts new file mode 100644 index 0000000000..8f3c6d868b --- /dev/null +++ b/fees/solv-finance/index.ts @@ -0,0 +1,66 @@ +import { Chain } from "@defillama/sdk/build/general"; +import { CHAIN } from "../../helpers/chains"; +import { BreakdownAdapter, FetchV2, SimpleAdapter } from "../../adapters/types"; +import { addTokensReceived } from "../../helpers/token"; +import { httpGet } from "../../utils/fetchURL"; + +const feesConfig = "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solv-fees.json"; + +const chains: { + [chain: Chain]: { deployedAt: number }; +} = { + [CHAIN.ETHEREUM]: { + deployedAt: 1718236800, + } +}; + +const protocol: FetchV2 = async (options) => { + const contracts: { + [chain: Chain]: { + [protocolFees: string]: { address: string[]; token: string[]; deployedAt: number }; + } + } = await httpGet(feesConfig); + + const dailyFees = await addTokensReceived({ + options, + targets: contracts[options.chain]["protocolFees"].address, + tokens: contracts[options.chain]["protocolFees"].token, + }); + + return { + dailyFees, + dailyRevenue: dailyFees, + dailyProtocolRevenue: dailyFees, + }; +}; + +const pool: FetchV2 = async (options) => { + const dailyFees = options.createBalances(); + + return { + dailyFees, + dailyRevenue: dailyFees, + dailyProtocolRevenue: dailyFees, + }; +} + +const adapter: BreakdownAdapter = { breakdown: {}, version: 2 }; + +Object.keys(chains).forEach((chain: Chain) => { + adapter.breakdown = { + protocolFees: { + [chain]: { + fetch: protocol, + start: chains[chain].deployedAt, + } + }, + poolFees: { + [chain]: { + fetch: pool, + start: chains[chain].deployedAt, + } + } + } +}); + +export default adapter; \ No newline at end of file From cefaa32d799e13b633327344a0d90aadf3b66154 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Tue, 10 Sep 2024 15:53:44 +0800 Subject: [PATCH 02/11] solv finance poolFees --- fees/solv-finance/index.ts | 130 +++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 7 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 8f3c6d868b..0e5462d2a5 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -1,11 +1,24 @@ import { Chain } from "@defillama/sdk/build/general"; import { CHAIN } from "../../helpers/chains"; -import { BreakdownAdapter, FetchV2, SimpleAdapter } from "../../adapters/types"; +import { BreakdownAdapter, FetchOptions, FetchV2, SimpleAdapter } from "../../adapters/types"; import { addTokensReceived } from "../../helpers/token"; import { httpGet } from "../../utils/fetchURL"; +import { gql, request } from "graphql-request"; +import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; +import { getPrices } from "../../utils/prices"; +import { BigNumber } from "bignumber.js" const feesConfig = "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solv-fees.json"; +// The Graph +const graphUrlList = { + ethereum: 'https://api.studio.thegraph.com/query/40045/solv-payable-factory-prod/version/latest', + bsc: 'https://api.studio.thegraph.com/query/40045/solv-payable-factory-bsc/version/latest', + arbitrum: 'https://api.studio.thegraph.com/query/40045/solv-payable-factory-arbitrum/version/latest', + mantle: 'https://api.0xgraph.xyz/api/public/65c5cf65-bd77-4da0-b41c-cb6d237e7e2f/subgraphs/solv-payable-factory-mantle/-/gn', + merlin: 'http://solv-subgraph-server-alb-694489734.us-west-1.elb.amazonaws.com:8000/subgraphs/name/solv-payable-factory-merlin', +} + const chains: { [chain: Chain]: { deployedAt: number }; } = { @@ -29,21 +42,124 @@ const protocol: FetchV2 = async (options) => { return { dailyFees, - dailyRevenue: dailyFees, - dailyProtocolRevenue: dailyFees, }; }; const pool: FetchV2 = async (options) => { - const dailyFees = options.createBalances(); + let dailyFees = options.createBalances(); + + const contracts: { + [chain: Chain]: { + [poolFees: string]: string[]; + } + } = await httpGet(feesConfig); + + const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain) + const concretes = await concrete(pools, options) + + const timestamp = getUniqStartOfTodayTimestamp(new Date()); + const yesterday = timestamp - 86400; + let poolNavs: any[] = []; + for (const pool of pools) { + const [yesterdayNav, todayNav] = await options.api.multiCall({ + calls: [{ + target: pool.navOracle, + params: [pool.poolId, yesterday], + }, { + target: pool.navOracle, + params: [pool.poolId, timestamp], + }], + abi: 'function getSubscribeNav(bytes32 poolId_, uint256 time_) view returns (uint256 nav_, uint256 navTime_)', + }) + + let nav = todayNav.nav_ - yesterdayNav.nav_; + if (nav < 0) { + nav = 0; + } + poolNavs.push(nav) + } + + 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], + params: [index.openFundShareSlot] + })), + }) + + const totalValues = await options.api.multiCall({ + abi: 'function slotTotalValue(uint256) view returns (uint256)', + calls: pools.map((index: { contractAddress: string | number; openFundShareSlot: any; }) => ({ + target: concretes[index.contractAddress], + params: [index.openFundShareSlot] + })), + }) + + const prices = (await getPrices(poolBaseInfos.map((index: { currency: string; }) => `${options.chain}:${index.currency.toLowerCase()}`), timestamp)); + let dailyFeeUsd = 0; + for (let i = 0; i < pools.length; i++) { + const poolNav = poolNavs[i]; + const poolBaseInfo = poolBaseInfos[i]; + const totalValue = totalValues[i]; + const priceData = prices[`${options.chain}:${poolBaseInfo.currency.toLowerCase()}`]; + + const total = BigNumber(totalValue) + .div(BigNumber(10e18)) + .times( + BigNumber(poolNav).dividedBy(BigNumber(10).pow(priceData.decimals)) + ).times(priceData.price); + + dailyFeeUsd = BigNumber(dailyFeeUsd).plus(total).toNumber(); + } return { - dailyFees, - dailyRevenue: dailyFees, - dailyProtocolRevenue: dailyFees, + dailyFees: dailyFeeUsd, }; } +async function getGraphData(poolId: string[], chain: Chain) { + const query = gql`{ + poolOrderInfos(first: 1000 where:{poolId_in: ${JSON.stringify(poolId)}}) { + marketContractAddress + contractAddress + navOracle + poolId + vault + openFundShareSlot + } + }`; + let response: any; + if (graphUrlList[chain]) { + response = (await request(graphUrlList[chain], query)).poolOrderInfos; + } + + return response; +} + + +async function concrete(slots: any[], options: FetchOptions): Promise { + var slotsList: any[] = []; + var only = {}; + for (var i = 0; i < slots.length; i++) { + if (!only[slots[i].contractAddress]) { + slotsList.push(slots[i]); + only[slots[i].contractAddress] = true; + } + } + + const concreteLists = await options.api.multiCall({ + calls: slotsList.map((index) => index.contractAddress), + abi: 'address:concrete', + }) + + let concretes = {}; + for (var k = 0; k < concreteLists.length; k++) { + concretes[slotsList[k].contractAddress] = concreteLists[k]; + } + + return concretes; +} + const adapter: BreakdownAdapter = { breakdown: {}, version: 2 }; Object.keys(chains).forEach((chain: Chain) => { From e846e37f2616d740a2e7f07786c2f18883f688e2 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Tue, 10 Sep 2024 15:56:44 +0800 Subject: [PATCH 03/11] fix --- fees/solv-finance/index.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 0e5462d2a5..5d62ee7d7b 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -46,16 +46,14 @@ const protocol: FetchV2 = async (options) => { }; const pool: FetchV2 = async (options) => { - let dailyFees = options.createBalances(); - const contracts: { [chain: Chain]: { [poolFees: string]: string[]; } } = await httpGet(feesConfig); - const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain) - const concretes = await concrete(pools, options) + const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain); + const concretes = await concrete(pools, options); const timestamp = getUniqStartOfTodayTimestamp(new Date()); const yesterday = timestamp - 86400; @@ -70,13 +68,13 @@ const pool: FetchV2 = async (options) => { params: [pool.poolId, timestamp], }], abi: 'function getSubscribeNav(bytes32 poolId_, uint256 time_) view returns (uint256 nav_, uint256 navTime_)', - }) + }); let nav = todayNav.nav_ - yesterdayNav.nav_; if (nav < 0) { nav = 0; } - poolNavs.push(nav) + poolNavs.push(nav); } const poolBaseInfos = await options.api.multiCall({ @@ -85,7 +83,7 @@ const pool: FetchV2 = async (options) => { target: concretes[index.contractAddress], params: [index.openFundShareSlot] })), - }) + }); const totalValues = await options.api.multiCall({ abi: 'function slotTotalValue(uint256) view returns (uint256)', @@ -93,7 +91,7 @@ const pool: FetchV2 = async (options) => { target: concretes[index.contractAddress], params: [index.openFundShareSlot] })), - }) + }); const prices = (await getPrices(poolBaseInfos.map((index: { currency: string; }) => `${options.chain}:${index.currency.toLowerCase()}`), timestamp)); let dailyFeeUsd = 0; From 3ce005803dab696d6db1ca97a844589d6069b13c Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Tue, 10 Sep 2024 16:01:59 +0800 Subject: [PATCH 04/11] if --- fees/solv-finance/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 5d62ee7d7b..6d5e9b68d2 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -34,6 +34,12 @@ const protocol: FetchV2 = async (options) => { } } = await httpGet(feesConfig); + if (!contracts[options.chain]) { + return { + timestamp: new Date().getTime(), + }; + } + const dailyFees = await addTokensReceived({ options, targets: contracts[options.chain]["protocolFees"].address, @@ -52,6 +58,12 @@ const pool: FetchV2 = async (options) => { } } = await httpGet(feesConfig); + if (!contracts[options.chain]) { + return { + timestamp: new Date().getTime(), + }; + } + const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain); const concretes = await concrete(pools, options); From 34e8deb45d09706c16ce0e1f51f3eda51739e9a5 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Wed, 11 Sep 2024 17:45:26 +0800 Subject: [PATCH 05/11] timestamp update --- fees/solv-finance/index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 6d5e9b68d2..c6a9cabcfb 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -1,10 +1,10 @@ import { Chain } from "@defillama/sdk/build/general"; import { CHAIN } from "../../helpers/chains"; -import { BreakdownAdapter, FetchOptions, FetchV2, SimpleAdapter } from "../../adapters/types"; +import { BreakdownAdapter, FetchOptions, FetchV2 } from "../../adapters/types"; +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; import { addTokensReceived } from "../../helpers/token"; import { httpGet } from "../../utils/fetchURL"; import { gql, request } from "graphql-request"; -import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; import { getPrices } from "../../utils/prices"; import { BigNumber } from "bignumber.js" @@ -67,17 +67,18 @@ const pool: FetchV2 = async (options) => { const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain); const concretes = await concrete(pools, options); - const timestamp = getUniqStartOfTodayTimestamp(new Date()); - const yesterday = timestamp - 86400; + const fromTimestamp = getTimestampAtStartOfDayUTC(options.fromTimestamp); + const toTimestamp = getTimestampAtStartOfDayUTC(options.toTimestamp); + let poolNavs: any[] = []; for (const pool of pools) { const [yesterdayNav, todayNav] = await options.api.multiCall({ calls: [{ target: pool.navOracle, - params: [pool.poolId, yesterday], + params: [pool.poolId, toTimestamp], }, { target: pool.navOracle, - params: [pool.poolId, timestamp], + params: [pool.poolId, fromTimestamp], }], abi: 'function getSubscribeNav(bytes32 poolId_, uint256 time_) view returns (uint256 nav_, uint256 navTime_)', }); @@ -105,7 +106,7 @@ const pool: FetchV2 = async (options) => { })), }); - const prices = (await getPrices(poolBaseInfos.map((index: { currency: string; }) => `${options.chain}:${index.currency.toLowerCase()}`), timestamp)); + const prices = (await getPrices(poolBaseInfos.map((index: { currency: string; }) => `${options.chain}:${index.currency.toLowerCase()}`), toTimestamp)); let dailyFeeUsd = 0; for (let i = 0; i < pools.length; i++) { const poolNav = poolNavs[i]; From 79fe26253960cd35956d2e37c5a1f33597de54f6 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Thu, 12 Sep 2024 17:35:48 +0800 Subject: [PATCH 06/11] update logic --- fees/solv-finance/index.ts | 98 +++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index c6a9cabcfb..d968c6a9d8 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -1,33 +1,38 @@ import { Chain } from "@defillama/sdk/build/general"; import { CHAIN } from "../../helpers/chains"; -import { BreakdownAdapter, FetchOptions, FetchV2 } from "../../adapters/types"; +import { FetchOptions, FetchV2, SimpleAdapter } from "../../adapters/types"; import { getTimestampAtStartOfDayUTC } from "../../utils/date"; import { addTokensReceived } from "../../helpers/token"; import { httpGet } from "../../utils/fetchURL"; import { gql, request } from "graphql-request"; import { getPrices } from "../../utils/prices"; import { BigNumber } from "bignumber.js" +import { Balances } from "@defillama/sdk"; const feesConfig = "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solv-fees.json"; - -// The Graph -const graphUrlList = { - ethereum: 'https://api.studio.thegraph.com/query/40045/solv-payable-factory-prod/version/latest', - bsc: 'https://api.studio.thegraph.com/query/40045/solv-payable-factory-bsc/version/latest', - arbitrum: 'https://api.studio.thegraph.com/query/40045/solv-payable-factory-arbitrum/version/latest', - mantle: 'https://api.0xgraph.xyz/api/public/65c5cf65-bd77-4da0-b41c-cb6d237e7e2f/subgraphs/solv-payable-factory-mantle/-/gn', - merlin: 'http://solv-subgraph-server-alb-694489734.us-west-1.elb.amazonaws.com:8000/subgraphs/name/solv-payable-factory-merlin', -} +const graphUrl = "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/refs/heads/main/solv-graph.json"; const chains: { [chain: Chain]: { deployedAt: number }; } = { [CHAIN.ETHEREUM]: { - deployedAt: 1718236800, - } + deployedAt: 1681084800, + }, + [CHAIN.BSC]: { + deployedAt: 1679097600, + }, + [CHAIN.ARBITRUM]: { + deployedAt: 1682380800, + }, + [CHAIN.MANTLE]: { + deployedAt: 1692835200, + }, + [CHAIN.MERLIN]: { + deployedAt: 1710892800, + }, }; -const protocol: FetchV2 = async (options) => { +const fetch: FetchV2 = async (options) => { const contracts: { [chain: Chain]: { [protocolFees: string]: { address: string[]; token: string[]; deployedAt: number }; @@ -40,30 +45,28 @@ const protocol: FetchV2 = async (options) => { }; } + const dailyFees = options.createBalances(); + const protocolFees = await protocol(options, contracts); + dailyFees.addBalances(protocolFees); + + const poolFees = await pool(options, contracts); + dailyFees.addBalances(poolFees); + return { + dailyFees + } +}; + +async function protocol(options: FetchOptions, contracts: any): Promise { const dailyFees = await addTokensReceived({ options, targets: contracts[options.chain]["protocolFees"].address, tokens: contracts[options.chain]["protocolFees"].token, }); - return { - dailyFees, - }; -}; - -const pool: FetchV2 = async (options) => { - const contracts: { - [chain: Chain]: { - [poolFees: string]: string[]; - } - } = await httpGet(feesConfig); - - if (!contracts[options.chain]) { - return { - timestamp: new Date().getTime(), - }; - } + return dailyFees; +} +async function pool(options: FetchOptions, contracts: any): Promise { const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain); const concretes = await concrete(pools, options); @@ -87,6 +90,7 @@ const pool: FetchV2 = async (options) => { if (nav < 0) { nav = 0; } + poolNavs.push(nav); } @@ -107,28 +111,32 @@ const pool: FetchV2 = async (options) => { }); const prices = (await getPrices(poolBaseInfos.map((index: { currency: string; }) => `${options.chain}:${index.currency.toLowerCase()}`), toTimestamp)); + let dailyFeeUsd = 0; + const dailyFees = options.createBalances(); for (let i = 0; i < pools.length; i++) { const poolNav = poolNavs[i]; const poolBaseInfo = poolBaseInfos[i]; const totalValue = totalValues[i]; const priceData = prices[`${options.chain}:${poolBaseInfo.currency.toLowerCase()}`]; + const token = `${options.chain}:${poolBaseInfo.currency}`; const total = BigNumber(totalValue) .div(BigNumber(10e18)) .times( BigNumber(poolNav).dividedBy(BigNumber(10).pow(priceData.decimals)) - ).times(priceData.price); + ); - dailyFeeUsd = BigNumber(dailyFeeUsd).plus(total).toNumber(); + dailyFees.addBalances({ [token]: total.toNumber() }); } - return { - dailyFees: dailyFeeUsd, - }; + return dailyFees; } async function getGraphData(poolId: string[], chain: Chain) { + const graphUrlList: { + [chain: Chain]: string; + } = (await httpGet(graphUrl)) const query = gql`{ poolOrderInfos(first: 1000 where:{poolId_in: ${JSON.stringify(poolId)}}) { marketContractAddress @@ -171,23 +179,13 @@ async function concrete(slots: any[], options: FetchOptions): Promise { return concretes; } -const adapter: BreakdownAdapter = { breakdown: {}, version: 2 }; +const adapter: SimpleAdapter = { adapter: {}, version: 2 }; Object.keys(chains).forEach((chain: Chain) => { - adapter.breakdown = { - protocolFees: { - [chain]: { - fetch: protocol, - start: chains[chain].deployedAt, - } - }, - poolFees: { - [chain]: { - fetch: pool, - start: chains[chain].deployedAt, - } - } - } + adapter.adapter[chain] = { + fetch, + start: chains[chain].deployedAt, + }; }); export default adapter; \ No newline at end of file From 89c83cda668b48494cdf1b15c6954bdf1fc40a1e Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Thu, 12 Sep 2024 18:28:43 +0800 Subject: [PATCH 07/11] add core --- fees/solv-finance/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index d968c6a9d8..9d34d3ddb8 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -30,6 +30,9 @@ const chains: { [CHAIN.MERLIN]: { deployedAt: 1710892800, }, + [CHAIN.CORE]: { + deployedAt: 1726012800, + }, }; const fetch: FetchV2 = async (options) => { From 3157d4da9ad610e190f5a49a9a95b0548a7e3b24 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Fri, 13 Sep 2024 17:00:18 +0800 Subject: [PATCH 08/11] add dailyRevenue --- fees/solv-finance/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 9d34d3ddb8..11a7ff7acf 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -11,6 +11,7 @@ import { Balances } from "@defillama/sdk"; const feesConfig = "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solv-fees.json"; const graphUrl = "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/refs/heads/main/solv-graph.json"; +const yields = 0.2; const chains: { [chain: Chain]: { deployedAt: number }; @@ -55,7 +56,8 @@ const fetch: FetchV2 = async (options) => { const poolFees = await pool(options, contracts); dailyFees.addBalances(poolFees); return { - dailyFees + dailyFees, + dailyRevenue: dailyFees.clone(yields) } }; @@ -125,7 +127,6 @@ async function pool(options: FetchOptions, contracts: any): Promise { const token = `${options.chain}:${poolBaseInfo.currency}`; const total = BigNumber(totalValue) - .div(BigNumber(10e18)) .times( BigNumber(poolNav).dividedBy(BigNumber(10).pow(priceData.decimals)) ); From 56862f1227d19bb8b6a030a936e14dcef1b58f7c Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Sat, 14 Sep 2024 09:23:27 +0800 Subject: [PATCH 09/11] fix pool total decimals --- fees/solv-finance/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 11a7ff7acf..416459dc32 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -62,6 +62,9 @@ const fetch: FetchV2 = async (options) => { }; async function protocol(options: FetchOptions, contracts: any): Promise { + if (!contracts[options.chain]["protocolFees"]) { + return options.createBalances(); + } const dailyFees = await addTokensReceived({ options, targets: contracts[options.chain]["protocolFees"].address, @@ -72,6 +75,9 @@ async function protocol(options: FetchOptions, contracts: any): Promise { + if (!contracts[options.chain]["poolFees"]) { + return options.createBalances(); + } const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain); const concretes = await concrete(pools, options); @@ -117,7 +123,6 @@ async function pool(options: FetchOptions, contracts: any): Promise { const prices = (await getPrices(poolBaseInfos.map((index: { currency: string; }) => `${options.chain}:${index.currency.toLowerCase()}`), toTimestamp)); - let dailyFeeUsd = 0; const dailyFees = options.createBalances(); for (let i = 0; i < pools.length; i++) { const poolNav = poolNavs[i]; @@ -127,6 +132,8 @@ async function pool(options: FetchOptions, contracts: any): Promise { const token = `${options.chain}:${poolBaseInfo.currency}`; const total = BigNumber(totalValue) + .dividedBy(BigNumber(10).pow(18)) + .times(BigNumber(10).pow(priceData.decimals)) .times( BigNumber(poolNav).dividedBy(BigNumber(10).pow(priceData.decimals)) ); From b9232455f404c376009795014027dc4aacf727c8 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Sat, 14 Sep 2024 09:41:04 +0800 Subject: [PATCH 10/11] fix timestamp decimals --- fees/solv-finance/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 416459dc32..7fc740bad1 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -81,8 +81,8 @@ async function pool(options: FetchOptions, contracts: any): Promise { const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain); const concretes = await concrete(pools, options); - const fromTimestamp = getTimestampAtStartOfDayUTC(options.fromTimestamp); - const toTimestamp = getTimestampAtStartOfDayUTC(options.toTimestamp); + const fromTimestamp = getTimestampAtStartOfDayUTC(options.fromTimestamp) * 1000; + const toTimestamp = getTimestampAtStartOfDayUTC(options.toTimestamp) * 1000; let poolNavs: any[] = []; for (const pool of pools) { @@ -121,21 +121,24 @@ async function pool(options: FetchOptions, contracts: any): Promise { })), }); - const prices = (await getPrices(poolBaseInfos.map((index: { currency: string; }) => `${options.chain}:${index.currency.toLowerCase()}`), toTimestamp)); + 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 poolBaseInfo = poolBaseInfos[i]; const totalValue = totalValues[i]; - const priceData = prices[`${options.chain}:${poolBaseInfo.currency.toLowerCase()}`]; + const decimals = poolDecimalList[i]; const token = `${options.chain}:${poolBaseInfo.currency}`; const total = BigNumber(totalValue) .dividedBy(BigNumber(10).pow(18)) - .times(BigNumber(10).pow(priceData.decimals)) + .times(BigNumber(10).pow(decimals)) .times( - BigNumber(poolNav).dividedBy(BigNumber(10).pow(priceData.decimals)) + BigNumber(poolNav).dividedBy(BigNumber(10).pow(decimals)) ); dailyFees.addBalances({ [token]: total.toNumber() }); From 158b7670db90baf29209da358cc9cc6d309077c6 Mon Sep 17 00:00:00 2001 From: buchaoqun Date: Sat, 14 Sep 2024 11:11:05 +0800 Subject: [PATCH 11/11] fix timesatmp edit --- fees/solv-finance/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 7fc740bad1..3e76946499 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -81,12 +81,12 @@ async function pool(options: FetchOptions, contracts: any): Promise { const pools = await getGraphData(contracts[options.chain]["poolFees"], options.chain); const concretes = await concrete(pools, options); - const fromTimestamp = getTimestampAtStartOfDayUTC(options.fromTimestamp) * 1000; - const toTimestamp = getTimestampAtStartOfDayUTC(options.toTimestamp) * 1000; + const fromTimestamp = getTimestampAtStartOfDayUTC(options.fromTimestamp); + const toTimestamp = getTimestampAtStartOfDayUTC(options.toTimestamp); let poolNavs: any[] = []; for (const pool of pools) { - const [yesterdayNav, todayNav] = await options.api.multiCall({ + const [todayNav, yesterdayNav] = await options.api.multiCall({ calls: [{ target: pool.navOracle, params: [pool.poolId, toTimestamp],