Skip to content

Commit

Permalink
Merge pull request #2237 from Javsphere/master
Browse files Browse the repository at this point in the history
Add volumes and fees for LeverageX by Javsphere
  • Loading branch information
dtmkeng authored Dec 19, 2024
2 parents f2da352 + c54a07d commit 1b5bfae
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
37 changes: 31 additions & 6 deletions dexs/javsphere/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
import fetchURL from "../../utils/fetchURL";
import type { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import {getPrices} from "../../utils/prices";

type DexData = {
volumeTotal: number,
volume24: number,
const tokenMap = {
WETH: "coingecko:weth",
cbBTC: "coingecko:coinbase-wrapped-btc",
USDC: "coingecko:usd-coin"
};

const methodology = {
Volume: "User buys and sell JAV token on CEXes and DEXes.",
Volume: "LeverageX Traders create Volume by placing Trades. User buys and sell JAV token on CEXes and DEXes.",
}

const API_VOLUME_DEX = `https://aws-api.javlis.com/api/javsphere/coin-volume`;
const API_LEVERAGE_STAT = 'https://1f5i4e87mf.execute-api.eu-central-1.amazonaws.com/prod/cols-stats'

const fetch = async (timestamp: number) => {
const stats: DexData = await fetchURL(`https://aws-api.javlis.com/api/javsphere/coin-volume`);
const [stats, statsLevX, prices] = await Promise.all([
fetchURL(API_VOLUME_DEX),
fetchURL(API_LEVERAGE_STAT),
getPrices([tokenMap.WETH, tokenMap.cbBTC, tokenMap.USDC], timestamp)
]);

const totalVolumeInUSD = Object.keys(statsLevX.yield.totalVolume).reduce((total, token) => {
const tokenKey = token as keyof typeof tokenMap;
const volume = statsLevX.yield.totalVolume[token];
const price = prices[tokenMap[tokenKey]];
return total + (volume * price.price);
}, 0);

const totalDailyVolumeInUSD = statsLevX.collaterals.reduce((total: number, collateral: any) => {
const tokenKey = collateral.collateralName as keyof typeof tokenMap;
const volume = collateral.lastDayEarned.totalVolume;
const price = prices[tokenMap[tokenKey]]?.price;

return total + (volume * price || 0);
}, 0);

return {
dailyVolume: `${stats.volume24}`,
dailyVolume: totalDailyVolumeInUSD + stats.volume24,
totalVolume: totalVolumeInUSD + stats.volume24,
timestamp,
};
};
Expand Down
59 changes: 59 additions & 0 deletions fees/javsphere/index.ts
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;

0 comments on commit 1b5bfae

Please sign in to comment.