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: Store swaps #114

Merged
merged 16 commits into from
Apr 21, 2023
Merged

Feat: Store swaps #114

merged 16 commits into from
Apr 21, 2023

Conversation

bvotteler
Copy link
Contributor

@bvotteler bvotteler commented Apr 20, 2023

Resolves #106

Store swap information:

  • From / To:
    • account
    • asset
    • amount
    • amountHuman
  • Fees paid
  • Timestamp

Todo before ready for review:

  • Run against Kintsugi mainnet and check if results look plausible
  • ❌ (attempted, too slow) Attempt to run against Kintsugi testnet - if performance allows it
  • Regenerate db migration files after last fixes/changes have been made

@bvotteler
Copy link
Contributor Author

bvotteler commented Apr 20, 2023

Sample query:

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

query SwapQuery {
  swaps(limit: 10) {
    id
    timestamp
    fromAccount
    toAccount
    feeRate
    from {
      ...AmountFields
    }
    to {
      ...AmountFields
    }
  }
}

Sample result:

      {
        "id": "swap_(KSM,KBTC)_0002681725-000012-2842a",
        "timestamp": "2023-03-23T03:01:36.212000Z",
        "fromAccount": "a3dkY3yWweLMkUjbSSNC2NawWegH3NZkWpYjsnBr2srQsp9LZ",
        "toAccount": "a3dkY3yWweLMkUjbSSNC2NawWegH3NZkWpYjsnBr2srQsp9LZ",
        "feeRate": "0.0015",
        "from": {
          "amount": "21370527482",
          "amountHuman": "0.021370527482",
          "token": {
            "__typename": "NativeToken",
            "token": "KSM"
          }
        },
        "to": {
          "amount": "2538",
          "amountHuman": "0.00002538",
          "token": {
            "__typename": "NativeToken",
            "token": "KBTC"
          }
        }
      }

It looks a bit awkward to have the from/to account ids outside of the fields from and to which contain PooledAmount data (ie. no account in there, because it's also used for cumulative volumes).

I was in two minds whether we should introduce a new type including the account ids, or keep it as is. Slightly leaning towards keeping it so we can better reuse fragments when structuring queries.
Having said that, I am more than happy to be challenged on that.

@bvotteler bvotteler marked this pull request as ready for review April 20, 2023 14:26
@bvotteler bvotteler requested a review from peterslany April 20, 2023 14:26
@bvotteler bvotteler mentioned this pull request Apr 20, 2023
7 tasks
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.

Looks very good, great job implementing this!

src/mappings/utils/pools.ts Outdated Show resolved Hide resolved
src/mappings/utils/pools.ts Outdated Show resolved Hide resolved
src/mappings/utils/pools.ts Outdated Show resolved Hide resolved
@bvotteler bvotteler merged commit f696f19 into interlay:master Apr 21, 2023
@bvotteler bvotteler deleted the feat-store-swaps branch April 21, 2023 15:21
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.

Store all swaps
2 participants