From c6bde0b4234017a87c4ea96654f172f2d633c83a Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Wed, 11 Oct 2023 17:22:38 +0000 Subject: [PATCH] add sudoswap fees --- fees/sudoswap-v1.ts | 48 +++++++++++++++++++++++++++++++++++++++++++ fees/sudoswap-v2.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 fees/sudoswap-v1.ts create mode 100644 fees/sudoswap-v2.ts diff --git a/fees/sudoswap-v1.ts b/fees/sudoswap-v1.ts new file mode 100644 index 0000000000..b167be2f8d --- /dev/null +++ b/fees/sudoswap-v1.ts @@ -0,0 +1,48 @@ +import postgres from "postgres"; +import { Adapter, FetchResultFees } from "../adapters/types"; +import { CHAIN } from "../helpers/chains"; +import { getPrices } from "../utils/prices"; + +const fetchFees = async (timestamp: number): Promise => { + const sql = postgres(process.env.INDEXA_DB!); + try { + const now = new Date(timestamp * 1e3) + const dayAgo = new Date(now.getTime() - 1000 * 60 * 60 * 24) + const eth_transfer_logs = await sql` + SELECT + sum("value") / 1e18 AS eth_value + FROM + ethereum.traces + WHERE + block_number > 14645816 + AND to_address = '\\xb16c1342E617A5B6E4b631EB114483FDB289c0A4' + AND block_time BETWEEN ${dayAgo.toISOString()} AND ${now.toISOString()}; + ` + const eth_value = Number(eth_transfer_logs[0].eth_value); + const ethAddress = "ethereum:0x0000000000000000000000000000000000000000"; + const ethPrice = (await getPrices([ethAddress], timestamp))[ethAddress].price; + const dailyFees = eth_value * ethPrice; + const dailyRevenue = dailyFees; + await sql.end({ timeout: 3 }) + return { + dailyFees: `${dailyFees}`, + dailyRevenue: `${dailyRevenue}`, + timestamp + } + } catch (e) { + await sql.end({ timeout: 3 }) + console.error(e) + throw e; + } +} + +const adapter: Adapter = { + adapter: { + [CHAIN.ETHEREUM]: { + fetch: fetchFees, + start: async () => 1672531200 + }, + }, +}; + +export default adapter; diff --git a/fees/sudoswap-v2.ts b/fees/sudoswap-v2.ts new file mode 100644 index 0000000000..1ee2f26cc9 --- /dev/null +++ b/fees/sudoswap-v2.ts @@ -0,0 +1,50 @@ +import postgres from "postgres"; +import { Adapter, FetchResultFees } from "../adapters/types"; +import { getTimestampAtStartOfDayUTC } from "../utils/date"; +import { CHAIN } from "../helpers/chains"; +import { getPrices } from "../utils/prices"; + +const fetchFees = async (timestamp: number): Promise => { + const sql = postgres(process.env.INDEXA_DB!); + try { + const now = new Date(timestamp * 1e3) + const dayAgo = new Date(now.getTime() - 1000 * 60 * 60 * 24) + + const eth_transfer_logs = await sql` + SELECT + sum("value") / 1e18 AS eth_value + FROM + ethereum.traces + WHERE + block_number > 17309203 + AND to_address = '\\xA020d57aB0448Ef74115c112D18a9C231CC86000' + AND block_time BETWEEN ${dayAgo.toISOString()} AND ${now.toISOString()}; + ` + const eth_value = Number(eth_transfer_logs[0].eth_value); + const ethAddress = "ethereum:0x0000000000000000000000000000000000000000"; + const ethPrice = (await getPrices([ethAddress], timestamp))[ethAddress].price; + const dailyFees = eth_value * ethPrice; + const dailyRevenue = dailyFees; + await sql.end({ timeout: 3 }) + return { + dailyFees: `${dailyFees}`, + dailyRevenue: `${dailyRevenue}`, + timestamp + } + } catch (e) { + await sql.end({ timeout: 3 }) + console.error(e) + throw e; + } +} + +const adapter: Adapter = { + adapter: { + [CHAIN.ETHEREUM]: { + fetch: fetchFees, + start: async () => 1684627200 + }, + }, +}; + +export default adapter;