From f08898535a667cc246f5c101d2ffa66fad6176ab Mon Sep 17 00:00:00 2001 From: yruej301 Date: Fri, 27 Oct 2023 11:51:01 -0400 Subject: [PATCH] update vertex-protocol backend URL --- fees/vertex-protocol.ts | 125 ++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 56 deletions(-) diff --git a/fees/vertex-protocol.ts b/fees/vertex-protocol.ts index 9042963e5a..517830ca5a 100644 --- a/fees/vertex-protocol.ts +++ b/fees/vertex-protocol.ts @@ -1,17 +1,17 @@ -import axios from 'axios'; -import { CHAIN } from '../helpers/chains'; -import { Adapter, FetchResultFees } from '../adapters/types'; +import axios from "axios"; +import { CHAIN } from "../helpers/chains"; +import { Adapter, FetchResultFees } from "../adapters/types"; interface MarketSnapshots { - interval: { - count: number; - granularity: number; - max_time: number; - }; + interval: { + count: number; + granularity: number; + max_time: number; + }; } interface QueryBody { - market_snapshots: MarketSnapshots; + market_snapshots: MarketSnapshots; } interface IData { [s: string]: string; @@ -22,71 +22,84 @@ interface Snapshot { } interface Response { - snapshots: Snapshot[]; + snapshots: Snapshot[]; } const query = async (max_time: number): Promise => { - const body: QueryBody = { - market_snapshots: { - interval: { - count: 2, - granularity: 86400, - max_time: max_time, - }, - }, - }; - - const url = 'https://prod.vertexprotocol-backend.com'; - const response = await axios.post(url + '/indexer', body); - return response.data; + const body: QueryBody = { + market_snapshots: { + interval: { + count: 2, + granularity: 86400, + max_time: max_time, + }, + }, + }; + + const url = "https://api.prod.vertexprotocol.com"; + const response = await axios.post(url + "/indexer", body); + return response.data; }; const sumAllProductStats = (stat_map: IData): number => { - let stat_sum = 0; - for (const v of Object.values(stat_map)) { - stat_sum += parseInt(v); - } - return stat_sum / 1e18; + let stat_sum = 0; + for (const v of Object.values(stat_map)) { + stat_sum += parseInt(v); + } + return stat_sum / 1e18; }; -const get24hrStat = async (field: string, max_time: number): Promise => { - const response = await query(max_time); - const cur_res: Snapshot = response.snapshots[0]; - const past_res: Snapshot = response.snapshots[1]; - return sumAllProductStats(cur_res[field]) - sumAllProductStats(past_res[field]); +const get24hrStat = async ( + field: string, + max_time: number +): Promise => { + const response = await query(max_time); + const cur_res: Snapshot = response.snapshots[0]; + const past_res: Snapshot = response.snapshots[1]; + return ( + sumAllProductStats(cur_res[field]) - sumAllProductStats(past_res[field]) + ); }; -const getCumulativeStat = async (field: string, max_time: number): Promise => { - const response = await query(max_time); - const cur_res = response.snapshots[0]; - return sumAllProductStats(cur_res[field]); +const getCumulativeStat = async ( + field: string, + max_time: number +): Promise => { + const response = await query(max_time); + const cur_res = response.snapshots[0]; + return sumAllProductStats(cur_res[field]); }; const getCumulativeFees = async (max_time: number): Promise => { - const fees = await getCumulativeStat('cumulative_taker_fees', max_time); - const sequencer_fees = await getCumulativeStat('cumulative_sequencer_fees', max_time); - return fees - sequencer_fees; + const fees = await getCumulativeStat("cumulative_taker_fees", max_time); + const sequencer_fees = await getCumulativeStat( + "cumulative_sequencer_fees", + max_time + ); + return fees - sequencer_fees; }; const getCumulativeRevenue = async (max_time: number): Promise => { - const fees = await getCumulativeFees(max_time); - const rebates = await getCumulativeStat('cumulative_maker_fees', max_time); - return fees + rebates; + const fees = await getCumulativeFees(max_time); + const rebates = await getCumulativeStat("cumulative_maker_fees", max_time); + return fees + rebates; }; const get24hrFees = async (max_time: number): Promise => { - const fees = await get24hrStat('cumulative_taker_fees', max_time); - const sequencer_fees = await get24hrStat('cumulative_sequencer_fees', max_time); - return fees - sequencer_fees; + const fees = await get24hrStat("cumulative_taker_fees", max_time); + const sequencer_fees = await get24hrStat( + "cumulative_sequencer_fees", + max_time + ); + return fees - sequencer_fees; }; const get24hrRevenue = async (max_time: number): Promise => { - const fees = await get24hrFees(max_time); - const rebates = await get24hrStat('cumulative_maker_fees', max_time); - return fees + rebates; + const fees = await get24hrFees(max_time); + const rebates = await get24hrStat("cumulative_maker_fees", max_time); + return fees + rebates; }; - const fetch = async (timestamp: number): Promise => { const dailyFees = await get24hrFees(timestamp); const dailyRevenue = await get24hrRevenue(timestamp); @@ -97,18 +110,18 @@ const fetch = async (timestamp: number): Promise => { dailyRevenue: `${dailyRevenue}`, totalRevenue: `${totalRev}`, totalFees: `${totalFees}`, - timestamp - } -} + timestamp, + }; +}; const adapter: Adapter = { adapter: { [CHAIN.ARBITRUM]: { fetch: fetch, runAtCurrTime: true, - start: async () => 1682514000, + start: async () => 1682514000, }, - } -} + }, +}; export default adapter;