hicommonwealth / commonwealth

A platform for decentralized communities
https://commonwealth.im
GNU General Public License v3.0
67 stars 42 forks source link

[SPIKE] SubQuery Integration #8790

Closed timolegros closed 3 weeks ago

timolegros commented 1 month ago

Description

Notes

Additional context

timolegros commented 1 month ago

Intro

SubQuery is an indexing system built in Typescript that supports 208+ networks (any EVM chain, most Substrate chains, and most Cosmos chains). In SubQuery you create mapping functions at the block, transaction, or log level to populate a database with a fully customizable schema defined in GraphQL. SubQuery pairs a Postgres database with a PostGraphile server which enables running GraphQL queries over Postgres data. SubQuery supports real-time indexing via 'unfinalized blocks' and real-time client updates via GraphQL subscriptions.

Managed Hosting

Chain-Related functionality

Reserving Namespace

Existing

  1. Txn to reserve a namespace executes
  2. PATCH to /communities/:community_id
    • queries the chain to get namespace/namespace_address and saves it to Communities.namespace and Communities.namespace_address respectively.

Change

Deploy Community Stakes

Existing

  1. Txn to deploy stake ERC1155
  2. POST to /communityStakes/:community_id/:stake_id
    • queries the chain to verify that community stakes is configured for the namespace using Communities.namespace_address and stake_id
    • Creates a CommunityStakes record in the database
    • Creates a group for community members that own stake

Change TBD

My Stake Transactions (or any txns list UI)

Existing

  1. Community stake transactions indexed into the StakeTransactions table via CE v2
  2. Client GET community.getStakeTransaction (v1 tRPC API) to get transaction history

Change

  1. Index stake transactions in SubQuery using namespace address and wallet (from) address
  2. Client queries SubQuery to get relevant transactions
  3. Remove StakeTransactions table and community.getStakeTransaction route

Launch Contest

Existing

  1. Create contest txn
  2. Client POST contest.createContestMetadata
    • Creates a ContestManagers record
    • Creates ContestTopics records

Change

Other Contest Projections

Existing

Change

Notifications

Existing

Change

Notes

Next Steps

  1. Decide whether to move forward with SubQuery or maintain in-house indexing. It seems that Alchemy is no longer an option given Growth's demands to expand to new chains like Linea and BSC.
  2. If we decide to move forward with SubQuery, create new tickets for each of the above 'change' sections (include much more detail). Tackle the transition to SubQuery in small pieces by gradually transition specific features/sub-systems to use SubQuery.
timolegros commented 1 month ago

Bumping to reflect the amount of time this ticket really took. Creating the MVP took longer than anticipated since the MVP initially did not work due to caveats like:

While it may seem like a long time for a spike, using SubQuery would be a significant shift in how we interact with chain data so it warranted a deeper investigation to discover the caveats/underlying issues before diving into the deep end.

timolegros commented 3 weeks ago

We will not use SubQuery or its managed service until https://github.com/subquery/subql/issues/2493 and a follow-up ticket for unfinalized blocks in multichain projects are complete since the list of chains we need to index is growing and costs (both in the managed service and development) for separate SubQuery projects would become unsustainable.

jnaviask commented 3 weeks ago

Thanks for the research, Tim! I'll close this ticket as completed. Let's follow up once the subquery updates land.