diff --git a/fees/solv-finance/index.ts b/fees/solv-finance/index.ts index 5a4003a548..bd639cec46 100644 --- a/fees/solv-finance/index.ts +++ b/fees/solv-finance/index.ts @@ -1,37 +1,25 @@ import { Chain } from "@defillama/sdk/build/general"; import { CHAIN } from "../../helpers/chains"; import { FetchOptions, FetchV2, SimpleAdapter } from "../../adapters/types"; -import { addGasTokensReceived, addTokensReceived } from "../../helpers/token"; +import { addGasTokensReceived, addTokensReceived, getSolanaReceived } from "../../helpers/token"; import { request } from "graphql-request"; import { Balances } from "@defillama/sdk"; import { getConfig } from "../../helpers/cache"; const feesConfig = - "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solv-fees.json"; + "https://raw.githubusercontent.com/solv-finance/solv-protocol-defillama/main/solv-fees.json"; const graphUrl = - "https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/refs/heads/main/solv-graph.json"; + "https://raw.githubusercontent.com/solv-finance/solv-protocol-defillama/refs/heads/main/solv-graph.json"; const yields = 0.2; -const chains: { - [chain: Chain]: { deployedAt: number }; -} = { - [CHAIN.ETHEREUM]: { - deployedAt: 1726531200, - }, - [CHAIN.BSC]: { - deployedAt: 1726531200, - }, - [CHAIN.ARBITRUM]: { - deployedAt: 1726531200, - }, - [CHAIN.MANTLE]: { - deployedAt: 1726531200, - }, - [CHAIN.MERLIN]: { - deployedAt: 1726531200, - }, - [CHAIN.CORE]: { - deployedAt: 1726531200, - }, +const chains: { [chain: Chain]: { deployedAt: number } } = { + [CHAIN.ETHEREUM]: { deployedAt: 1726531200 }, + [CHAIN.BSC]: { deployedAt: 1726531200 }, + [CHAIN.ARBITRUM]: { deployedAt: 1726531200 }, + [CHAIN.MANTLE]: { deployedAt: 1726531200 }, + [CHAIN.MERLIN]: { deployedAt: 1726531200 }, + [CHAIN.CORE]: { deployedAt: 1726531200 }, + [CHAIN.SCROLL]: { deployedAt: 1726531200 }, + [CHAIN.SOLANA]: { deployedAt: 1726531200 }, }; const fetch: FetchV2 = async (options) => { @@ -49,42 +37,90 @@ const fetch: FetchV2 = async (options) => { return {} - const dailyFees = options.createBalances(); - const protocolFees = await protocol(options, contracts); - dailyFees.addBalances(protocolFees); + const dailyFees = await feeRevenues(options, contracts); + const dailyRevenue = await revenues(options, contracts); + const pureRevenueBalances = await pureRevenues(options, contracts); - const poolFees = await pool(options, contracts); - dailyFees.addBalances(poolFees); + dailyRevenue.addBalances(dailyFees.clone(yields)); + + dailyFees.addBalances(pureRevenueBalances); + dailyRevenue.addBalances(pureRevenueBalances); - const nativeTokenFees = await nativeToken(options, contracts); - dailyFees.addBalances(nativeTokenFees); return { dailyFees, - dailyRevenue: dailyFees.clone(yields), + dailyRevenue, }; }; -async function protocol( +async function pureRevenues(options: FetchOptions, contracts: any): Promise { + const pureRevenues = options.createBalances(); + + const receivedPureRevenue = await received(options, contracts, "receivedPureRevenue"); + pureRevenues.addBalances(receivedPureRevenue); + + const nativeTokenPureRevenue = await nativeToken(options, contracts, "nativeTokenPureRevenue"); + pureRevenues.addBalances(nativeTokenPureRevenue); + + return pureRevenues; +} + +async function revenues(options: FetchOptions, contracts: any): Promise { + const dailyRevenues = options.createBalances(); + + const receivedRevenue = await received(options, contracts, "receivedRevenue"); + dailyRevenues.addBalances(receivedRevenue); + + const nativeTokenRevenue = await nativeToken(options, contracts, "nativeTokenRevenue"); + dailyRevenues.addBalances(nativeTokenRevenue); + + const solanaRevenue = await solanas(options, contracts, "solanaRevenue"); + dailyRevenues.addBalances(solanaRevenue); + + return dailyRevenues; +} + +async function feeRevenues(options: FetchOptions, contracts: any): Promise { + const dailyFees = options.createBalances(); + + const protocolFees = await received(options, contracts, "protocolFees"); + dailyFees.addBalances(protocolFees); + + const poolFees = await pool(options, contracts, "poolFees"); + dailyFees.addBalances(poolFees); + + const nativeTokenFees = await nativeToken(options, contracts, "nativeTokenFees"); + dailyFees.addBalances(nativeTokenFees); + + const solanaFees = await solanas(options, contracts, "solanaFees"); + dailyFees.addBalances(solanaFees); + + return dailyFees; +} + +async function received( options: FetchOptions, - contracts: any + contracts: any, + configKey: string ): Promise { - if (!contracts[options.chain]["protocolFees"]) { + const protocolConfig = contracts[options.chain]?.[configKey]; + if (!protocolConfig) { return options.createBalances(); } return addTokensReceived({ options, - targets: contracts[options.chain]["protocolFees"].address, - tokens: contracts[options.chain]["protocolFees"].token, + targets: protocolConfig.address, + tokens: protocolConfig.token, }); } -async function pool(options: FetchOptions, contracts: any): Promise { - if (!contracts[options.chain]["poolFees"]) { +async function pool(options: FetchOptions, contracts: any, configKey: string): Promise { + const poolConfig = contracts[options.chain]?.[configKey]; + if (!poolConfig) { return options.createBalances(); } const pools = await getGraphData( - contracts[options.chain]["poolFees"], + poolConfig, options.chain ); const shareConcretes = await concrete(pools, options); @@ -204,13 +240,23 @@ async function concrete(slots: any[], options: FetchOptions): Promise { async function nativeToken( options: FetchOptions, - contracts: any + contracts: any, configKey: string ): Promise { - if (!contracts[options.chain]["nativeTokenFees"]) { + const nativeTokenConfig = contracts[options.chain]?.[configKey]; + if (!nativeTokenConfig) { + return options.createBalances(); + } + const multisig = nativeTokenConfig.address; + return addGasTokensReceived({ multisig, options }) +} + +async function solanas(options: FetchOptions, contracts: any, configKey: string): Promise { + const solanaFeesConfig = contracts[options.chain]?.[configKey]; + if (!solanaFeesConfig) { return options.createBalances(); } - const multisig = contracts[options.chain]["nativeTokenFees"].address; - return addGasTokensReceived({ multisig, options }) + + return await getSolanaReceived({ options, targets: solanaFeesConfig }); } const adapter: SimpleAdapter = { adapter: {}, version: 2 }; @@ -222,4 +268,4 @@ Object.keys(chains).forEach((chain: Chain) => { }; }); -export default adapter; +export default adapter; \ No newline at end of file