Enable timeseries for stateful-m-token (M Token subgraph for mainnet)#26
Enable timeseries for stateful-m-token (M Token subgraph for mainnet)#26oleksandr-fedorenko-m0 wants to merge 1 commit intomainfrom
stateful-m-token (M Token subgraph for mainnet)#26Conversation
|
@jonalvarezz check it please |
There was a problem hiding this comment.
Pull request overview
This PR enables timeseries functionality for the M Token mainnet subgraph, allowing time-based aggregation of key metrics (latestIndex, latestRate, and latestUpdateTimestamp). The changes upgrade the subgraph infrastructure to support The Graph's timeseries features and migrate deployment from Alchemy to Goldsky.
Changes:
- Upgraded subgraph spec version from 1.0.0 to 1.2.0 and API version from 0.0.7 to 0.0.9 to support timeseries entities
- Converted LatestIndexSnapshot, LatestRateSnapshot, and LatestUpdateTimestampSnapshot to timeseries entities with corresponding aggregation types for hourly and daily data
- Migrated deployment infrastructure from Alchemy to Goldsky with improved dependency checks
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| stateful-m-token/subgraph.yaml | Updated spec and API versions; added LatestIndex entity to support timeseries aggregation |
| stateful-m-token/src/m-token.ts | Modified snapshot update functions to use constant timeseries ID; removed load logic for timeseries entities |
| stateful-m-token/schema.graphql | Converted three snapshot entities to timeseries format with Int8 IDs; added aggregation types; marked entities as immutable: false |
| stateful-m-token/package.json | Updated graph-cli to 0.98.1 and graph-ts to 0.38.2 for timeseries support |
| stateful-m-token/deploy.sh | Migrated from Alchemy to Goldsky deployment with dependency validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type LatestRate | ||
| @aggregation(intervals: ["hour", "day"], source: "LatestRateSnapshot") { | ||
| id: Int8! | ||
| timestamp: Timestamp! | ||
| value: BigInt! @aggregate(fn: "last", arg: "value") | ||
| count: Int8! @aggregate(fn: "count", cumulative: true) | ||
| } | ||
|
|
||
| type LatestUpdateTimestampSnapshot @entity(timeseries: true) { | ||
| id: Int8! | ||
| timestamp: Timestamp! @unique | ||
| value: Timestamp! | ||
| value: Int! | ||
| } | ||
|
|
||
| type LatestUpdateTimestamp | ||
| @aggregation(intervals: ["hour", "day"], source: "LatestUpdateTimestampSnapshot") { | ||
| id: Int8! | ||
| timestamp: Timestamp! | ||
| value: Int! @aggregate(fn: "last", arg: "value") | ||
| count: Int8! @aggregate(fn: "count", cumulative: true) |
There was a problem hiding this comment.
Inconsistent indentation in aggregation type definitions. The LatestRate and LatestUpdateTimestamp aggregation types use 2-space indentation while LatestIndex uses 4-space indentation. These should be consistent - all aggregation type fields should use the same indentation as LatestIndex (4 spaces to match the surrounding schema style).
| - LatestRateSnapshot | ||
| - LatestUpdateTimestampSnapshot |
There was a problem hiding this comment.
Missing aggregation entities in the entities list. The LatestRate and LatestUpdateTimestamp aggregation types should be added here, similar to how LatestIndex is included. These are derived from the timeseries entities and should be registered in the subgraph manifest.
| - LatestRateSnapshot | |
| - LatestUpdateTimestampSnapshot | |
| - LatestRateSnapshot | |
| - LatestRate | |
| - LatestUpdateTimestampSnapshot | |
| - LatestUpdateTimestamp |
There was a problem hiding this comment.
This is correct too, although, I am able to query LatestRate and LatestUpdateTimestamp anyway – did you forget to commit the change? let's add them explicitly here
| type MToken @entity(immutable: false) { | ||
| id: ID! @unique | ||
| holders: [Holder!] | ||
| totalNonEarningSupply: BigInt! |
There was a problem hiding this comment.
The MToken entity should not have direct array references to timeseries snapshot entities. Timeseries entities like LatestIndexSnapshot use a constant ID (TIMESERIES_ID = 1) and are designed for time-based aggregation, not for one-to-many relationships. These array fields (latestIndexSnapshots, latestRateSnapshots, latestUpdateTimestampSnapshots) at lines 170, 172, and 174 should be removed from the MToken entity, as they would not function correctly with timeseries entities. Users should query the timeseries entities directly or use the aggregation entities (LatestIndex, LatestRate, LatestUpdateTimestamp) instead.
There was a problem hiding this comment.
makes sense, let's remove it from this entity
jonalvarezz
left a comment
There was a problem hiding this comment.
I checked the information and compared to the one we in production (m-token-mainnet/0.0.1) and it matches the information ✅
It's a bummer though that the timeseries don't return the current value for the partially filled day. The documentation mentions an optional currentData arg, but I can't find it. So we had to get the latest one from the entity itself
However, the data to download is significantly lower for calculating daily yields.
I couldn't figure out how to add the _collection postfix.
It was automatically added for timeseries. Seems like they, luckily, removed it on recent versions.
Action: Let's add our prefix so it is explicit, how about latestRateTimeseries? so we can tell them apart from regular entities.
as for production deployment, it needs follow up on M earner worker to account for this changes. Let's have a call about it
https://linear.app/mzero/issue/FS-553/improve-how-index-and-rate-are-stored
Deployment: https://api.goldsky.com/api/public/project_cmgzirwl000165np20d5n16h6/subgraphs/m-token-mainnet/0.0.2/gn
I couldn't figure out how to add the
_collectionpostfix.