Skip to content

Commit

Permalink
Merge pull request #2027 from 0xpeluche/fix_allium
Browse files Browse the repository at this point in the history
Fix Mevx, using option to blacklists with Allium queries
  • Loading branch information
0xpeluche authored Oct 22, 2024
2 parents 66dbf38 + ec673c9 commit a7b091c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 34 deletions.
20 changes: 12 additions & 8 deletions fees/mevx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,7 +23,7 @@ const adapter: SimpleAdapter = {
start: 0,
},
},
isExpensiveAdapter: true
isExpensiveAdapter: true,
};

export default adapter;
66 changes: 40 additions & 26 deletions helpers/token.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a7b091c

Please sign in to comment.