From 9d786886d85d151b02cf041082c4172a1b478fa1 Mon Sep 17 00:00:00 2001 From: vlbhtcno1 Date: Sat, 29 Mar 2025 22:05:04 +0700 Subject: [PATCH 1/4] add eth,bsc,base to mevx --- fees/mevx.ts | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/fees/mevx.ts b/fees/mevx.ts index e0128d644b..0e25255acd 100644 --- a/fees/mevx.ts +++ b/fees/mevx.ts @@ -1,6 +1,73 @@ -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', + +} + +const graph = (chain: Chain) => { + return async (timestamp: number, _: ChainBlocks, { createBalances, getFromBlock, getToBlock, }: FetchOptions): Promise => { + + 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) + }) + + dailyFees.resizeBy(0.0085) + + return { + dailyFees: dailyFees, + dailyProtocolRevenue: dailyFees, + dailyRevenue: dailyFees, + timestamp + } + + } +} + + const fetch: any = async (options: FetchOptions) => { const dailyFees = await getSolanaReceived({ @@ -15,12 +82,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: graph(CHAIN.ETHEREUM), + start: '2025-01-01', + }, + [CHAIN.BASE]: { + fetch: graph(CHAIN.BASE), + start: '2025-01-01', + }, + [CHAIN.BSC]: { + fetch: graph(CHAIN.BSC), + start: '2025-01-01', + }, }, isExpensiveAdapter: true, }; From 96934cd41e105cbab78f4b80b562fbcc60411129 Mon Sep 17 00:00:00 2001 From: vlbhtcno1 Date: Sat, 19 Apr 2025 21:24:17 +0700 Subject: [PATCH 2/4] Update to adap v2 adapters --- fees/mevx.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fees/mevx.ts b/fees/mevx.ts index 0e25255acd..3bc4a08c41 100644 --- a/fees/mevx.ts +++ b/fees/mevx.ts @@ -22,7 +22,7 @@ const address: TAddress = { } const graph = (chain: Chain) => { - return async (timestamp: number, _: ChainBlocks, { createBalances, getFromBlock, getToBlock, }: FetchOptions): Promise => { + return async ({ createBalances, getFromBlock, getToBlock, }: FetchOptions): Promise => { const query = ` select @@ -61,7 +61,6 @@ const graph = (chain: Chain) => { dailyFees: dailyFees, dailyProtocolRevenue: dailyFees, dailyRevenue: dailyFees, - timestamp } } From ce9551dadc9249196b5d7ccc4fb5c2b38e5e64fb Mon Sep 17 00:00:00 2001 From: vlbhtcno1 Date: Sat, 19 Apr 2025 21:25:11 +0700 Subject: [PATCH 3/4] Update to adap v2 adapters1 --- fees/mevx.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fees/mevx.ts b/fees/mevx.ts index 3bc4a08c41..ea51eb3003 100644 --- a/fees/mevx.ts +++ b/fees/mevx.ts @@ -54,9 +54,7 @@ const graph = (chain: Chain) => { rawData.map((e: IVolume) => { dailyFees.add(e.tokenAddress, e.amount) }) - - dailyFees.resizeBy(0.0085) - + return { dailyFees: dailyFees, dailyProtocolRevenue: dailyFees, From ccbb9e2ee83d5c5b9a7bf207a51d975f2467c35c Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Wed, 30 Apr 2025 09:51:25 +0200 Subject: [PATCH 4/4] minor fix --- fees/mevx.ts | 54 +++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/fees/mevx.ts b/fees/mevx.ts index ea51eb3003..a3af4f29da 100644 --- a/fees/mevx.ts +++ b/fees/mevx.ts @@ -21,10 +21,9 @@ const address: TAddress = { } -const graph = (chain: Chain) => { - return async ({ createBalances, getFromBlock, getToBlock, }: FetchOptions): Promise => { +async function fetchEVM({ createBalances, getFromBlock, getToBlock, chain}: FetchOptions){ - const query = ` + const query = ` select input_data, TX_HASH @@ -37,31 +36,30 @@ const graph = (chain: Chain) => { ` - 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) - }) - + 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 { - dailyFees: dailyFees, - dailyProtocolRevenue: dailyFees, - dailyRevenue: dailyFees, - } + 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, } + } @@ -86,15 +84,15 @@ const adapter: Adapter = { fetch: fetch, }, [CHAIN.ETHEREUM]: { - fetch: graph(CHAIN.ETHEREUM), + fetch: fetchEVM, start: '2025-01-01', }, [CHAIN.BASE]: { - fetch: graph(CHAIN.BASE), + fetch: fetchEVM, start: '2025-01-01', }, [CHAIN.BSC]: { - fetch: graph(CHAIN.BSC), + fetch: fetchEVM, start: '2025-01-01', }, },