Skip to content

Commit

Permalink
Merge pull request #928 from yruej301/chore/update-vertex-protocol-url
Browse files Browse the repository at this point in the history
chore: update vertex-protocol backend URL
  • Loading branch information
dtmkeng authored Oct 27, 2023
2 parents a5ad2e4 + f088985 commit 3fcff3a
Showing 1 changed file with 69 additions and 56 deletions.
125 changes: 69 additions & 56 deletions fees/vertex-protocol.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,71 +22,84 @@ interface Snapshot {
}

interface Response {
snapshots: Snapshot[];
snapshots: Snapshot[];
}

const query = async (max_time: number): Promise<Response> => {
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<number> => {
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<number> => {
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<number> => {
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<number> => {
const response = await query(max_time);
const cur_res = response.snapshots[0];
return sumAllProductStats(cur_res[field]);
};

const getCumulativeFees = async (max_time: number): Promise<number> => {
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<number> => {
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<number> => {
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<number> => {
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<FetchResultFees> => {
const dailyFees = await get24hrFees(timestamp);
const dailyRevenue = await get24hrRevenue(timestamp);
Expand All @@ -97,18 +110,18 @@ const fetch = async (timestamp: number): Promise<FetchResultFees> => {
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;

0 comments on commit 3fcff3a

Please sign in to comment.