From c22cb8d22beaa378090d4201d42045cf94a4542e Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Mon, 3 Jul 2023 15:50:01 +0000 Subject: [PATCH] fix unibot fees --- fees/unibot.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/fees/unibot.ts b/fees/unibot.ts index 4500353258..01ade4725a 100644 --- a/fees/unibot.ts +++ b/fees/unibot.ts @@ -74,6 +74,51 @@ const fetch = async (timestamp: number): Promise => { AND to_address = '\\xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' AND block_time BETWEEN ${dayAgo.toISOString()} AND ${now.toISOString()}; `; + + const revFromToken: IData[] = await sql` + SELECT + block_number, + block_time, + "value" / 1e18 as eth_value, + encode(transaction_hash, 'hex') AS HASH, + encode(to_address, 'hex') AS to_address + FROM + ethereum.traces + WHERE + block_number > 17277183 + AND from_address = '\\xf819d9cb1c2a819fd991781a822de3ca8607c3c9' + AND block_time BETWEEN ${dayAgo.toISOString()} AND ${now.toISOString()} + UNION ALL + SELECT + block_number, + block_time, + "value" / 1e18 as eth_value, + encode(transaction_hash, 'hex') AS HASH, + encode(to_address, 'hex') AS to_address + FROM + ethereum.traces + WHERE + block_number > 17277183 + AND from_address = '\\xf819d9cb1c2a819fd991781a822de3ca8607c3c9' + and to_address = '\\xdc3d4e12ab9eee060dc4de6b3d0b8fbf129d7dad' + AND block_time BETWEEN ${dayAgo.toISOString()} AND ${now.toISOString()} + UNION ALL + SELECT + block_number, + block_time, + "value" / 1e18 as eth_value, + encode(transaction_hash, 'hex') AS HASH, + encode(to_address, 'hex') AS to_address + FROM + ethereum.traces + WHERE + block_number > 17277183 + AND from_address = '\\xf819d9cb1c2a819fd991781a822de3ca8607c3c9' + and to_address = '\\xd1b46363b778dc01704c74ef77e8b451046cccc9' + AND block_time BETWEEN ${dayAgo.toISOString()} AND ${now.toISOString()}; + ` + + const rev_gen_token: number = revFromToken.reduce((a: number, transaction: IData) => a+Number(transaction.eth_value), 0) const transactions: IData[] = [...router_v2, ...router_v3] as IData[] const amount = transactions.reduce((a: number, transaction: IData) => a+Number(transaction.eth_value), 0) @@ -81,7 +126,8 @@ const fetch = async (timestamp: number): Promise => { const ethPrice = (await getPrices([ethAddress], todaysTimestamp))[ethAddress].price; const amountUSD = amount * ethPrice; // ref https://dune.com/queries/2621049/4349967 - const dailyFees = amountUSD * 0.01; + const tokenRev = rev_gen_token * ethPrice; + const dailyFees = ((amountUSD * 0.01) * 0.4) + tokenRev; const dailyRevenue = dailyFees; await sql.end({ timeout: 3 }) return {