Skip to content

Commit

Permalink
Merge pull request #707 from fextr/master
Browse files Browse the repository at this point in the history
zunami fee adapter
  • Loading branch information
dtmkeng authored Aug 4, 2023
2 parents ec76346 + f4a6b3b commit 10143a0
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions fees/zunami/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {CHAIN} from "../../helpers/chains";
import {Chain} from '@defillama/sdk/build/general';
import {ChainBlocks, SimpleAdapter} from "../../adapters/types";
import {getBlock} from "../../helpers/getBlock";
import * as sdk from "@defillama/sdk";
import fetchURL from "../../utils/fetchURL";

const dataEndpoint = (fromTimestamp: number, toTimestamp: number): string => {
return "https://api.zunami.io/api/v2/zunami/yield?from=" + fromTimestamp + "&to=" + toTimestamp;
};

const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
const ZUNAMI_ADDRESS = "0x2ffCC661011beC72e1A9524E12060983E74D14ce";
const APS_ADDRESS = "0xCaB49182aAdCd843b037bBF885AD56A3162698Bd";
const FEE_DENOMINATOR = 1000;
const START_TIMESTAMP = 1646956800;

interface YieldData {
omnipoolYield: number;
apsYield: number;
rigidYield: number;
totalYield: number;
}

type TABI = {
[k: string]: object;
}
const ABIs: TABI = {
getManagementFee: {
"inputs": [],
"name": "managementFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
};

const getData = (chain: Chain) => {
return async (timestamp: number, _: ChainBlocks) => {
const from = timestamp - ONE_DAY_IN_SECONDS;
const to = timestamp;
const block = await getBlock(from, chain, {});
const omnipoolManagementFee = Number((
await sdk.api.abi.call({
target: ZUNAMI_ADDRESS,
chain: chain,
abi: ABIs.getManagementFee,
block: block
})
).output) / FEE_DENOMINATOR
const apsManagementFee = Number((
await sdk.api.abi.call({
target: APS_ADDRESS,
chain: chain,
abi: ABIs.getManagementFee,
block: block
})
).output) / FEE_DENOMINATOR

const dailyData: YieldData = (await fetchURL(dataEndpoint(from, to))).data;
const dailyRevenue = (dailyData.omnipoolYield * omnipoolManagementFee)
+ (dailyData.apsYield * apsManagementFee) + dailyData.rigidYield;
const dailyHoldersRevenue = dailyData.omnipoolYield + dailyData.apsYield;

const totalData: YieldData = (await fetchURL(dataEndpoint(START_TIMESTAMP, to))).data
const totalRevenue = (totalData.omnipoolYield * omnipoolManagementFee)
+ (totalData.apsYield * apsManagementFee) + totalData.rigidYield
const totalDailyHoldersRevenue = totalData.omnipoolYield + totalData.apsYield;

return {
dailyFees: `${dailyData.totalYield}`,
totalFees: `${totalData.totalYield}`,
dailyRevenue: `${dailyRevenue}`,
totalRevenue: `${totalRevenue}`,
dailyHoldersRevenue: `${dailyHoldersRevenue}`,
totalDailyHoldersRevenue: `${totalDailyHoldersRevenue}`,
timestamp
}
}
}

const methodology = {
Fees: "The protocol's revenue from Omnipools (performance fee) & Yield from Omnipools, Protocol's revenue from " +
"APS (performance fee) & Yield from APS, Yield from zStables collateral located in the pool.",
Revenue: "The protocol's revenue from Omnipools (performance fee), Protocol's revenue from APS (performance fee), " +
"Yield from zStables collateral located in the pool",
HoldersRevenue: "Yield from Omnipools, Yield from APS.",
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ETHEREUM]: {fetch: getData(CHAIN.ETHEREUM), start: async () => START_TIMESTAMP, meta: {methodology}},
}
};

export default adapter;

0 comments on commit 10143a0

Please sign in to comment.