Skip to content

Commit

Permalink
ZivoeAdaperFees
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudonaut committed Dec 23, 2024
1 parent ee016fd commit e9be7c7
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions fees/zivoe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import fetchURL from "../../utils/fetchURL";
import { getTimestampAtStartOfDayUTC } from "../../utils/date";

const ZIVOE_API_URL = "https://analytics.zivoe.com/api/stats/feesAndRevenue";

type DailyAmount = {
tokenAddress: string;
value: string;
};

type DailyFeesAndRevenue = {
fees: Array<DailyAmount>;
revenue: Array<DailyAmount>;
};

const fetch = async (options: FetchOptions) => {
const dailyFees = options.createBalances();
const dailyRevenue = options.createBalances();

const params = new URLSearchParams({
network: "MAINNET",
periodStart: getTimestampAtStartOfDayUTC(options.toTimestamp).toString(),
});

const { fees, revenue }: DailyFeesAndRevenue = await fetchURL(ZIVOE_API_URL + "?" + params.toString());

fees.forEach((record) => {
dailyFees.add(record.tokenAddress, BigInt(record.value));
});

revenue.forEach((record) => {
dailyRevenue.add(record.tokenAddress, BigInt(record.value));
});

return { dailyFees, dailyRevenue };
};

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.ETHEREUM]: {
fetch,
start: "2024-10-10",
meta: {
methodology: {
Fees: `Interest earned from borrowers + fees generated by deploying idle capital into DeFi.`,
Revenue: `Portion of fees retained by the protocol.`,
},
},
},
},
};

export default adapter;

0 comments on commit e9be7c7

Please sign in to comment.