Skip to content

Commit

Permalink
evmReceivedGasAndTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
0xngmi committed Aug 26, 2024
1 parent b152138 commit e7fbb8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
20 changes: 3 additions & 17 deletions fees/dextools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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", {
Expand All @@ -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,
}
}), {
Expand Down
6 changes: 3 additions & 3 deletions helpers/dune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})`)
})
}
19 changes: 19 additions & 0 deletions helpers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
}
}

0 comments on commit e7fbb8a

Please sign in to comment.