Skip to content

Enable timeseries for stateful-m-token (M Token subgraph for mainnet)#26

Open
oleksandr-fedorenko-m0 wants to merge 1 commit intomainfrom
feat/FS-553
Open

Enable timeseries for stateful-m-token (M Token subgraph for mainnet)#26
oleksandr-fedorenko-m0 wants to merge 1 commit intomainfrom
feat/FS-553

Conversation

@oleksandr-fedorenko-m0
Copy link
Contributor

@oleksandr-fedorenko-m0 oleksandr-fedorenko-m0 commented Feb 6, 2026

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 _collection postfix.

{
  latestIndexes (interval:day, orderBy:timestamp, first:5) {
    id
    timestamp
    value
    count
	}
  latestRates (interval:day,orderBy:timestamp, first:5) {
    id
    timestamp
    value
    count
	}
  latestUpdateTimestamps(interval:day, orderBy:timestamp, first:5) {
    id
    timestamp
    value
    count
	}
}

@oleksandr-fedorenko-m0
Copy link
Contributor Author

@jonalvarezz check it please

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +121 to +140
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)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines 29 to 30
- LatestRateSnapshot
- LatestUpdateTimestampSnapshot
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
- LatestRateSnapshot
- LatestUpdateTimestampSnapshot
- LatestRateSnapshot
- LatestRate
- LatestUpdateTimestampSnapshot
- LatestUpdateTimestamp

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines +161 to 164
type MToken @entity(immutable: false) {
id: ID! @unique
holders: [Holder!]
totalNonEarningSupply: BigInt!
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, let's remove it from this entity

Copy link
Contributor

@jonalvarezz jonalvarezz left a comment

Choose a reason for hiding this comment

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

I checked the information and compared to the one we in production (m-token-mainnet/0.0.1) and it matches the information ✅

Image

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

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.

3 participants