Skip to content

Commit

Permalink
Peter/fix q token vaults volumes fetching (#1535)
Browse files Browse the repository at this point in the history
* chore: update monetary to latest 0.7.3

* fix: update vaults dashboard volumes query to include qToken vaults correctly
  • Loading branch information
peterslany authored Aug 21, 2023
1 parent 9af1253 commit 444b23a
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions src/services/fetchers/cumulative-volumes-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CollateralCurrencyExt, CurrencyExt, newMonetaryAmount, WrappedCurrency
import { MonetaryAmount } from '@interlay/monetary-js';

import graphqlFetcher, { GRAPHQL_FETCHER } from '@/services/fetchers/graphql-fetcher';
import { getCurrencyEqualityCondition } from '@/utils/helpers/currencies';

const CUMULATIVE_VOLUMES_FETCHER = 'cumulative-volumes-fetcher';

Expand Down Expand Up @@ -35,41 +36,26 @@ const cumulativeVolumesFetcher = async (
const queryFragment = (
type: VolumeType,
date: Date,
collateralCurrencyIdLiteral?: string | number,
wrappedCurrencyIdLiteral?: string | number
collateralCurrency?: CurrencyExt,
wrappedCurrency?: CurrencyExt
) => {
let colCurrCond = '';
if (collateralCurrencyIdLiteral !== undefined) {
colCurrCond =
(typeof collateralCurrencyIdLiteral === 'number' ? 'asset_eq: ' : 'token_eq: ') +
collateralCurrencyIdLiteral.toString();
}
let wrapCurrCond = '';
if (wrappedCurrencyIdLiteral !== undefined) {
wrapCurrCond =
(typeof wrappedCurrencyIdLiteral === 'number' ? 'asset_eq: ' : 'token_eq: ') +
wrappedCurrencyIdLiteral.toString();
}
const where = `{
tillTimestamp_lte: "${date.toISOString()}",
type_eq: ${type},
${
collateralCurrencyIdLiteral
collateralCurrency
? `collateralCurrency: {
${colCurrCond}}`
${getCurrencyEqualityCondition(collateralCurrency)}}`
: ``
},
${
wrappedCurrencyIdLiteral
wrappedCurrency
? `wrappedCurrency: {
${wrapCurrCond}}`
${getCurrencyEqualityCondition(wrappedCurrency)}}`
: ``
},
}`;
const entityName =
collateralCurrencyIdLiteral || wrappedCurrencyIdLiteral
? `cumulativeVolumePerCurrencyPairs`
: `cumulativeVolumes`;
const entityName = collateralCurrency || wrappedCurrency ? `cumulativeVolumePerCurrencyPairs` : `cumulativeVolumes`;
return `
ts${date.getTime()}: ${entityName} (where: ${where}, orderBy: tillTimestamp_DESC, limit: 1) {
amount
Expand All @@ -80,14 +66,7 @@ const cumulativeVolumesFetcher = async (

const query = `
{
${cutoffTimestamps.map((date) => {
let col;
// TODO: Need to refactor when we want to support lend tokens as collateral for vaults.
if (collateralCurrency) {
col = 'foreignAsset' in collateralCurrency ? collateralCurrency.foreignAsset.id : collateralCurrency.ticker;
}
return queryFragment(type, date, col, wrappedCurrency?.ticker);
})}
${cutoffTimestamps.map((date) => queryFragment(type, date, collateralCurrency, wrappedCurrency))}
}
`;

Expand Down

2 comments on commit 444b23a

@vercel
Copy link

@vercel vercel bot commented on 444b23a Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 444b23a Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.