Skip to content

Commit

Permalink
add token taxes for unibot
Browse files Browse the repository at this point in the history
  • Loading branch information
0xngmi committed Oct 12, 2023
1 parent b546f1b commit f3b6cb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions adapters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type FetchResultFees = FetchResultBase & {
totalSupplySideRevenue?: string | IJSON<string>;
totalUserFees?: string | IJSON<string>;
dailyBribesRevenue?: string | IJSON<string>;
dailyTokenTaxes?: string | IJSON<string>;
};

// INCENTIVES
Expand Down
18 changes: 18 additions & 0 deletions fees/unibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,34 @@ const fetch = async (timestamp: number): Promise<FetchResultFees> => {
const transactions: IData[] = [...router_v2, ...router_v3] as IData[]
const amount = transactions.reduce((a: number, transaction: IData) => a+Number(transaction.eth_value), 0)

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()}
`
const rev_gen_token: number = revFromToken.reduce((a: number, transaction: IData) => a+Number(transaction.eth_value), 0)

const ethAddress = "ethereum:0x0000000000000000000000000000000000000000";
const ethPrice = (await getPrices([ethAddress], todaysTimestamp))[ethAddress].price;
const amountUSD = amount * ethPrice;
const tokenRev = rev_gen_token * ethPrice;
// ref https://dune.com/queries/2621049/4349967
const dailyFees = (amountUSD * 0.01);
const dailyRevenue = dailyFees;
await sql.end({ timeout: 3 })
return {
dailyFees: `${dailyFees}`,
dailyRevenue: `${dailyRevenue}`,
dailyTokenTaxes: `${tokenRev}`,
timestamp
}
} catch (error) {
Expand Down

0 comments on commit f3b6cb5

Please sign in to comment.