-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #707 from fextr/master
zunami fee adapter
- Loading branch information
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |