From ec673c9ff5b5fba2b80a71e6a138cf010df37256 Mon Sep 17 00:00:00 2001 From: 0xpeluche <0xpeluche@proton.me> Date: Mon, 21 Oct 2024 17:34:11 +0200 Subject: [PATCH] Fix Mevx, using option to blacklists with Allium queries --- fees/mevx.ts | 20 +++++++++------ helpers/token.ts | 66 +++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/fees/mevx.ts b/fees/mevx.ts index 8b12e491ed..44d0db6eb8 100644 --- a/fees/mevx.ts +++ b/fees/mevx.ts @@ -3,13 +3,17 @@ import { CHAIN } from "../helpers/chains"; import { getSolanaReceived } from "../helpers/token"; const fetch: any = async (options: FetchOptions) => { - const dailyFees = await getSolanaReceived({ options, targets: [ - '5wkyL2FLEcyUUgc3UeGntHTAfWfzDrVuxMnaMm7792Gk', - '4Lpvp1q69SHentfYcMBUrkgvppeEx6ovHCSYjg4UYXiq', - 'BS3CyJ9rRC4Tp8G7f86r6hGvuu3XdrVGNVpbNM9U5WRZ', - ] }) - return { dailyFees, dailyRevenue: dailyFees, } -} + const dailyFees = await getSolanaReceived({ + blacklists: ['3kxSQybWEeQZsMuNWMRJH4TxrhwoDwfv41TNMLRzFP5A', 'BS3CyJ9rRC4Tp8G7f86r6hGvuu3XdrVGNVpbNM9U5WRZ', '4Lpvp1q69SHentfYcMBUrkgvppeEx6ovHCSYjg4UYXiq'], + options, + targets: [ + "5wkyL2FLEcyUUgc3UeGntHTAfWfzDrVuxMnaMm7792Gk", + "4Lpvp1q69SHentfYcMBUrkgvppeEx6ovHCSYjg4UYXiq", + "BS3CyJ9rRC4Tp8G7f86r6hGvuu3XdrVGNVpbNM9U5WRZ", + ], + }); + return { dailyFees, dailyRevenue: dailyFees }; +}; const adapter: SimpleAdapter = { version: 2, @@ -19,7 +23,7 @@ const adapter: SimpleAdapter = { start: 0, }, }, - isExpensiveAdapter: true + isExpensiveAdapter: true, }; export default adapter; diff --git a/helpers/token.ts b/helpers/token.ts index 5f007ed104..d96c4420f7 100644 --- a/helpers/token.ts +++ b/helpers/token.ts @@ -1,12 +1,12 @@ -import ADDRESSES from './coreAssets.json' +import * as sdk from '@defillama/sdk'; +import { getUniqueAddresses } from '@defillama/sdk/build/generalUtil'; +import axios from 'axios'; +import { ethers } from "ethers"; import { FetchOptions } from "../adapters/types"; -import * as sdk from '@defillama/sdk' -import axios from 'axios' +import { queryAllium } from './allium'; import { getCache, setCache } from "./cache"; -import { ethers } from "ethers"; -import { getUniqueAddresses } from '@defillama/sdk/build/generalUtil'; +import ADDRESSES from './coreAssets.json'; import { getEnv } from './env'; -import { queryAllium } from './allium'; export const nullAddress = ADDRESSES.null @@ -310,27 +310,41 @@ export const evmReceivedGasAndTokens = (receiverWallet: string, tokens: string[] } } -export async function getSolanaReceived({ options, balances, target, targets }: { options: FetchOptions, balances?: sdk.Balances, target?: string, targets?: string[] }) { - if (!balances) balances = options.createBalances() - - if (targets?.length) { - for (const target of targets) - await getSolanaReceived({ options, balances, target }) - return balances + export async function getSolanaReceived({ options, balances, target, targets, blacklists }: { + options: FetchOptions; + balances?: sdk.Balances; + target?: string; + targets?: string[]; + blacklists?: string[]; + }) { + if (!balances) balances = options.createBalances(); + + if (targets?.length) { + for (const target of targets) + await getSolanaReceived({ options, balances, target, blacklists }); + return balances; + } + + let blacklistCondition = ''; + + if (blacklists && blacklists.length > 0) { + const formattedBlacklist = blacklists.map(addr => `'${addr}'`).join(', '); + blacklistCondition = `AND from_address NOT IN (${formattedBlacklist})`; + } + + const query = ` + SELECT SUM(usd_amount) as usd_value, SUM(amount) as amount + FROM solana.assets.transfers + WHERE to_address = '${target}' + AND block_timestamp BETWEEN TO_TIMESTAMP_NTZ(${options.startTimestamp}) AND TO_TIMESTAMP_NTZ(${options.endTimestamp}) + ${blacklistCondition} + `; + + const res = await queryAllium(query); + balances.addUSDValue(res[0]?.usd_value ?? 0); + return balances; } - - const query = ` - SELECT SUM(usd_amount) as usd_value, SUM(amount) as amount - FROM solana.assets.transfers - WHERE to_address = '${target}' - AND block_timestamp BETWEEN TO_TIMESTAMP_NTZ(${options.startTimestamp}) AND TO_TIMESTAMP_NTZ(${options.endTimestamp}) - ` - // AND transfer_type = 'sol_transfer'` // enable this if you want to track only SOL transfers - - const res = await queryAllium(query) - balances.addUSDValue(res[0].usd_value ?? 0) - return balances -} + export async function getETHReceived({ options, balances, target, targets }: { options: FetchOptions, balances?: sdk.Balances, target?: string, targets?: string[] }) { if (!balances) balances = options.createBalances()