Skip to content

Add eth,bsc,base fee tracker to mevx.ts #2729

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

Open
wants to merge 4 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
80 changes: 77 additions & 3 deletions fees/mevx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,68 @@
import { FetchOptions, SimpleAdapter } from "../adapters/types";
import { Chain } from "@defillama/sdk/build/general"
import { Adapter, ChainBlocks, FetchOptions, FetchResultFees, } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { getSolanaReceived } from "../helpers/token";
import { queryFlipside } from "../helpers/flipsidecrypto";

interface IVolume {
amount: number;
tokenAddress: string;
tx: string;
}

type TAddress = {
[s: string | Chain]: string;
}

const address: TAddress = {
[CHAIN.ETHEREUM]: '0x087297b9987F16Ee251137b59D001aCf2457579e',
[CHAIN.BASE]: '0x764B099A48187D5f27806C6739BDa0BEF90B69F9',
[CHAIN.BSC]: '0xfA90769c3D13Feab848bfBC06A99a8B86B981dC6',

}

async function fetchEVM({ createBalances, getFromBlock, getToBlock, chain}: FetchOptions){

const query = `
select
input_data,
TX_HASH
from
${chain}.core.fact_transactions
WHERE
BLOCK_NUMBER > ${await getFromBlock()} AND BLOCK_NUMBER < ${await getToBlock()}
and to_address = '${address[chain]}'
and status = 'SUCCESS'
`


const value: string[][] = (await queryFlipside(query, 260))
const rawData = value.map((a: string[]) => {
const data = a[0].replace('0x5f575529', '');
const address = data.slice(64, 128);
const amount = Number('0x' + data.slice(128, 192));
const tokenAddress = '0x' + address.slice(24, address.length);
return {
amount: amount,
tokenAddress: tokenAddress,
tx: a[1]
} as IVolume
})
const dailyFees = createBalances()

rawData.map((e: IVolume) => {
dailyFees.add(e.tokenAddress, e.amount)
})

return {
dailyFees: dailyFees,
dailyProtocolRevenue: dailyFees,
dailyRevenue: dailyFees,
}

}



const fetch: any = async (options: FetchOptions) => {
const dailyFees = await getSolanaReceived({
Expand All @@ -15,12 +77,24 @@ const fetch: any = async (options: FetchOptions) => {
return { dailyFees, dailyRevenue: dailyFees };
};

const adapter: SimpleAdapter = {
const adapter: Adapter = {
version: 2,
adapter: {
[CHAIN.SOLANA]: {
fetch: fetch,
},
},
[CHAIN.ETHEREUM]: {
fetch: fetchEVM,
start: '2025-01-01',
},
[CHAIN.BASE]: {
fetch: fetchEVM,
start: '2025-01-01',
},
[CHAIN.BSC]: {
fetch: fetchEVM,
start: '2025-01-01',
},
},
isExpensiveAdapter: true,
};
Expand Down
Loading