Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add cumulative dex volumes #81

Merged
merged 20 commits into from
Mar 2, 2023
Merged

Feat: Add cumulative dex volumes #81

merged 20 commits into from
Mar 2, 2023

Conversation

bvotteler
Copy link
Contributor

@bvotteler bvotteler commented Feb 3, 2023

Split off from #35

[x] Trading volume 7 days per pool
[x] Trading volume 24 hours per pool

Added cumulative volumes per pool, containing volume per token of the swap.

Resolves #80

@bvotteler
Copy link
Contributor Author

7-day, 24-hour volumes can be calculated using the cumulative volumes. See this comment for example queries.

@bvotteler bvotteler marked this pull request as ready for review February 13, 2023 10:36
@bvotteler
Copy link
Contributor Author

bvotteler commented Feb 13, 2023

This is what a 7-day volume query could look like:
Query:

fragment AmountFields on PooledAmount {
    amount
    amountHuman
    token {
      ... on NativeToken {
        __typename
        token
      }
      ... on ForeignAsset {
        __typename
        asset
      }
      ... on StableLpToken {
        __typename
        poolId
      }
    }
}

fragment PoolVolumeFields on CumulativeDexTradingVolumePerPool {
    poolId
    poolType
    tillTimestamp
    amounts {
      ...AmountFields
    }
}

query poolVolumes($start: DateTime, $end: DateTime, $poolIdSubstr1: String, $poolIdSubstr2: String) {
  startVolumes: cumulativeDexTradingVolumePerPools(limit: 1, orderBy: tillTimestamp_DESC, where: {poolId_contains: $poolIdSubstr1, tillTimestamp_lte: $start, AND: {poolId_contains: $poolIdSubstr2}}) {
    ...PoolVolumeFields
  }
  endVolumes: cumulativeDexTradingVolumePerPools(limit: 1, orderBy: tillTimestamp_DESC, where: {poolId_contains: $poolIdSubstr1, tillTimestamp_lte: $end, AND: {poolId_contains: $poolIdSubstr2}}) {
    ...PoolVolumeFields
  }
}

eg. using these parameter values

{
  "poolIdSubstr1": "KBTC",
  "poolIdSubstr2": "KSM",
  "start": "2023-02-01T00:00:00.000000Z",
  "end": "2023-02-08T00:00:00.000000Z"
}

Copy link
Contributor

@peterslany peterslany left a comment

Choose a reason for hiding this comment

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

Great job with the implementation 👏 Just left couple of comments to clarify some aspects - but nothing serious :)

distributable/schema.graphql Show resolved Hide resolved
src/mappings/utils/cumulativeVolumes.ts Outdated Show resolved Hide resolved
src/mappings/utils/cumulativeVolumes.ts Outdated Show resolved Hide resolved
src/mappings/utils/pools.ts Show resolved Hide resolved
Copy link
Contributor

@peterslany peterslany left a comment

Choose a reason for hiding this comment

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

@bvotteler This looks good to me, approving now. This comment does not need to be handled as we are sure other types of currencies won't be used, right?
https://github.com/interlay/interbtc-squid/pull/81/files#r1106863865

@bvotteler
Copy link
Contributor Author

bvotteler commented Mar 2, 2023

@bvotteler This looks good to me, approving now. This comment does not need to be handled as we are sure other types of currencies won't be used, right? https://github.com/interlay/interbtc-squid/pull/81/files#r1106863865

Yes, I am assuming this holds true until our types are updated to include those.
When that happens, the interbtc-types definition here will need to be updated, too, at which point we know squid needs to follow suit.

@bvotteler bvotteler merged commit 2aee676 into interlay:master Mar 2, 2023
@bvotteler bvotteler deleted the feat-add-cumulative-amm-volumes branch March 2, 2023 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add cumulative trading volumes of dex pools
3 participants