Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pure Revenues #2126

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 91 additions & 45 deletions fees/solv-finance/index.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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<Balances> {
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<Balances> {
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<Balances> {
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<Balances> {
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<Balances> {
if (!contracts[options.chain]["poolFees"]) {
async function pool(options: FetchOptions, contracts: any, configKey: string): Promise<Balances> {
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);
Expand Down Expand Up @@ -204,13 +240,23 @@ async function concrete(slots: any[], options: FetchOptions): Promise<any> {

async function nativeToken(
options: FetchOptions,
contracts: any
contracts: any, configKey: string
): Promise<Balances> {
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<Balances> {
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 };
Expand All @@ -222,4 +268,4 @@ Object.keys(chains).forEach((chain: Chain) => {
};
});

export default adapter;
export default adapter;
Loading