Skip to content

Commit

Permalink
Fix type casting in volume calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Feb 3, 2024
1 parent cbedf61 commit ef7809d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions fees/apeswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const adapterObj = volumeAdapter.adapter;
const fetch = (chain: string, totalFees: number, revenueFee: number) => {
return async (timestamp: number, chainBlocks: ChainBlocks) => {
const fetchedResult = await adapterObj[chain].fetch(timestamp, chainBlocks);
const chainDailyVolume = fetchedResult.dailyVolume || '0';
const chainTotalVolume = fetchedResult.totalVolume || '0';
const chainDailyVolume = fetchedResult.dailyVolume as number || '0';
const chainTotalVolume = fetchedResult.totalVolume as number || '0';
const ssrFee = totalFees - revenueFee
const protocolFee = chain === CHAIN.TELOS ? 0.000375 : revenueFee / 2
const buybackFee = revenueFee / 2
Expand Down
4 changes: 2 additions & 2 deletions fees/verse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const adapterObj = volumeAdapter.adapter;
const fetch = (chain: string, totalFees: number, revenueFee: number, ssrFee: number) => {
return async (timestamp: number, chainBlocks: ChainBlocks) => {
const fetchedResult = await adapterObj[chain].fetch(timestamp, chainBlocks);
const chainDailyVolume = fetchedResult.dailyVolume;
const chainTotalVolume = fetchedResult.totalVolume;
const chainDailyVolume = fetchedResult.dailyVolume as any;
const chainTotalVolume = fetchedResult.totalVolume as any;

return {
timestamp,
Expand Down
3 changes: 1 addition & 2 deletions fees/zkswap-finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ const fetch = (chain: string, totalFees: number, revenueFee: number) => {
const fetchedResult = await adapterObj[chain].fetch(timestamp, chainBlocks);
const fetchedResultStartTime = await adapterObj[chain].fetch(FEE_COLLECTED_START_TIME, chainBlocks);

const chainDailyVolume = fetchedResult.dailyVolume || '0';
const chainDailyVolume = fetchedResult.dailyVolume as number || '0';
const chainTotalVolumeFromFeeCollectedDate = (Number(fetchedResult.totalVolume) - Number(fetchedResultStartTime.totalVolume))
const chainTotalVolume = chainTotalVolumeFromFeeCollectedDate || '0';

const ssrFee = totalFees - revenueFee
const protocolFee = revenueFee
const buybackFee = 0

return {
timestamp,
Expand Down
4 changes: 2 additions & 2 deletions helpers/customBackfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default (chain: Chain, graphs: IGraphs): Fetch => async (timestamp: numbe
Object.keys(resultPreviousDayN).filter((key) => key.includes('total')).forEach(key => {
const dimension = `daily${key.slice(5)}`
if (resultDayN[dimension] === undefined) {
const dataResultDayN = resultDayN[key]
const dataResultPreviousDayN = resultPreviousDayN[key]
const dataResultDayN = resultDayN[key] as any
const dataResultPreviousDayN = resultPreviousDayN[key] as any
if (dataResultPreviousDayN !== undefined && dataResultDayN !== undefined) {
if (typeof dataResultDayN === 'object' && typeof dataResultPreviousDayN === 'object') {
response[dimension] = Object.keys(dataResultDayN).reduce((acc, key) => {
Expand Down
8 changes: 4 additions & 4 deletions helpers/getUniSubgraphFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ const getDexChainBreakdownFees = ({ volumeAdapter, totalFees = 0, protocolFees =
const baseAdapters = Object.keys(volAdapter).map(chain => {
const fetchFees = async (timestamp: number, chainBlocks: ChainBlocks) => {
const fetchedResult: FetchResultVolume = await volAdapter[chain].fetch(timestamp, chainBlocks)
const chainDailyVolume = fetchedResult.dailyVolume ? fetchedResult.dailyVolume : "0";
const chainTotalVolume = fetchedResult.totalVolume ? fetchedResult.totalVolume : "0";
const chainDailyVolume = fetchedResult.dailyVolume ? fetchedResult.dailyVolume as number : "0";
const chainTotalVolume = fetchedResult.totalVolume ? fetchedResult.totalVolume as number : "0";

return {
timestamp,
Expand Down Expand Up @@ -140,8 +140,8 @@ const getDexChainFees = ({ volumeAdapter, totalFees = 0, protocolFees = 0, ...pa
Object.keys(adapterObj).map(chain => {
const fetchFees = async (timestamp: number, chainBlocks: ChainBlocks) => {
const fetchedResult: FetchResultVolume = await adapterObj[chain].fetch(timestamp, chainBlocks)
const chainDailyVolume = fetchedResult.dailyVolume;
const chainTotalVolume = fetchedResult.totalVolume;
const chainDailyVolume = fetchedResult.dailyVolume as number;
const chainTotalVolume = fetchedResult.totalVolume as number;
const response: FetchResultGeneric = { timestamp }
if (chainDailyVolume !== undefined) {
if (totalFees)
Expand Down

0 comments on commit ef7809d

Please sign in to comment.