-
Notifications
You must be signed in to change notification settings - Fork 1.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 #2237 from Javsphere/master
Add volumes and fees for LeverageX by Javsphere
- Loading branch information
Showing
2 changed files
with
90 additions
and
6 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
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,59 @@ | ||
import fetchURL from "../../utils/fetchURL"; | ||
import type { SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import {getPrices} from "../../utils/prices"; | ||
|
||
const tokenMap = { | ||
WETH: "coingecko:weth", | ||
cbBTC: "coingecko:coinbase-wrapped-btc", | ||
USDC: "coingecko:usd-coin" | ||
}; | ||
|
||
const methodology = { | ||
Volume: "LeverageX traders paying fees for open trades.", | ||
} | ||
|
||
const API_LEVERAGE_STAT = 'https://1f5i4e87mf.execute-api.eu-central-1.amazonaws.com/prod/cols-stats' | ||
|
||
const fetch = async (timestamp: number) => { | ||
const [statsLevX, prices] = await Promise.all([ | ||
fetchURL(API_LEVERAGE_STAT), | ||
getPrices([tokenMap.WETH, tokenMap.cbBTC, tokenMap.USDC], timestamp) | ||
]); | ||
|
||
const totalFeesInUSD = Object.keys(statsLevX.yield.totalFees).reduce((total, token) => { | ||
const tokenKey = token as keyof typeof tokenMap; | ||
const volume = statsLevX.yield.totalFees[token]; | ||
const price = prices[tokenMap[tokenKey]]; | ||
return total + (volume * price.price); | ||
}, 0); | ||
|
||
const totalDailyFeesInUSD = statsLevX.collaterals.reduce((total: number, collateral: any) => { | ||
const tokenKey = collateral.collateralName as keyof typeof tokenMap; | ||
const volume = collateral.lastDayEarned.totalFees; | ||
const price = prices[tokenMap[tokenKey]]?.price; | ||
|
||
return total + (volume * price || 0); | ||
}, 0); | ||
|
||
|
||
return { | ||
dailyFees: totalDailyFeesInUSD, | ||
totalFees: totalFeesInUSD, | ||
timestamp, | ||
}; | ||
}; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.BASE]: { | ||
fetch, | ||
runAtCurrTime: true, | ||
meta: { | ||
methodology | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default adapter; |