diff --git a/fees/dextools.ts b/fees/dextools.ts index 19d24399e6..c380f7d8b1 100644 --- a/fees/dextools.ts +++ b/fees/dextools.ts @@ -34,8 +34,8 @@ For Tokens created with https://creator.dextools.io, enter "//TOKENCREATOR//" as import { Adapter, FetchOptions } from "../adapters/types"; import { CHAIN } from "../helpers/chains"; -import { queryDune, queryDuneSql } from "../helpers/dune"; -import { addTokensReceived, nullAddress } from '../helpers/token'; +import { queryDune } from "../helpers/dune"; +import { evmReceivedGasAndTokens } from '../helpers/token'; const tokens = { ethereum: [ @@ -47,20 +47,6 @@ const tokens = { base: [] } as any -const evm = async (options: FetchOptions) => { - const receiverWallet = '0x997Cc123cF292F46E55E6E63e806CD77714DB70f' - const dailyFees = await addTokensReceived({ options, tokens: tokens[options.chain], target: receiverWallet }) - const nativeTransfers = await queryDuneSql(options, `select sum(value) as received from CHAIN.transactions - where to = ${receiverWallet} - AND TIME_RANGE`) - dailyFees.add(nullAddress, nativeTransfers[0].received) - - return { - dailyFees, - dailyRevenue: dailyFees, - } -} - const sol = async (options: FetchOptions) => { const dailyFees = options.createBalances(); const value = (await queryDune("3521814", { @@ -81,7 +67,7 @@ const adapter: Adapter = { adapter: [CHAIN.ETHEREUM, CHAIN.BASE, CHAIN.BSC].reduce((all, chain) => ({ ...all, [chain]: { - fetch: evm, + fetch: evmReceivedGasAndTokens('0x997Cc123cF292F46E55E6E63e806CD77714DB70f', tokens[chain]), start: 0, } }), { diff --git a/helpers/dune.ts b/helpers/dune.ts index 11da710219..f70cacd19a 100644 --- a/helpers/dune.ts +++ b/helpers/dune.ts @@ -74,7 +74,7 @@ const submitQuery = async (queryId: string, query_parameters = {}) => { } -export const queryDune = async (queryId: string, query_parameters = {}) => { +export const queryDune = async (queryId: string, query_parameters:any = {}) => { if (Object.keys(query_parameters).length === 0) { const latest_result = await getLatestData(queryId) if (latest_result !== undefined) return latest_result @@ -99,12 +99,12 @@ export const queryDune = async (queryId: string, query_parameters = {}) => { const tableName = { bsc: "bnb", ethereum: "ethereum", - base: "base" + base: "base", } as any export const queryDuneSql = (options:any, query:string) => { return queryDune("3996608", { - fullQuery: query.replace("CHAIN", tableName[options.chain]).replace("TIME_RANGE", `block_time >= from_unixtime(${options.startTimestamp}) + fullQuery: query.replace("CHAIN", tableName[options.chain] ?? options.chain).replace("TIME_RANGE", `block_time >= from_unixtime(${options.startTimestamp}) AND block_time <= from_unixtime(${options.endTimestamp})`) }) } diff --git a/helpers/token.ts b/helpers/token.ts index c7bf258997..a92220a6b8 100644 --- a/helpers/token.ts +++ b/helpers/token.ts @@ -6,6 +6,7 @@ import { getCache, setCache } from "./cache"; import { ethers } from "ethers"; import { getUniqueAddresses } from '@defillama/sdk/build/generalUtil'; import { getEnv } from './env'; +import { queryDuneSql } from './dune'; export const nullAddress = ADDRESSES.null @@ -244,3 +245,21 @@ export async function getTokenDiff(params: { return balances } + + +export const evmReceivedGasAndTokens = (receiverWallet:string, tokens:string[]) => + async (options: FetchOptions) => { + let dailyFees = options.createBalances() + if(tokens.length > 0){ + dailyFees = await addTokensReceived({ options, tokens: tokens, target: receiverWallet }) + } + const nativeTransfers = await queryDuneSql(options, `select sum(value) as received from CHAIN.traces + where to = ${receiverWallet} AND tx_success = TRUE + AND TIME_RANGE`) + dailyFees.add(nullAddress, nativeTransfers[0].received) + + return { + dailyFees, + dailyRevenue: dailyFees, + } +} \ No newline at end of file