Skip to content

subgraph upgrade#2010

Merged
0xgleb merged 3 commits into2024-09-12-i9rfrom
feat/subgraph-upgrade
Jul 23, 2025
Merged

subgraph upgrade#2010
0xgleb merged 3 commits into2024-09-12-i9rfrom
feat/subgraph-upgrade

Conversation

@0xgleb
Copy link
Copy Markdown
Collaborator

@0xgleb 0xgleb commented Jul 21, 2025

Motivation

We need to index orderbook V5 events

Solution

Update subgraph to work with V5 orderbook

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced decimal floating-point arithmetic for vault balances and amounts, improving precision across deposit, withdrawal, and trading operations.
    • Added support for a new decimal float contract, enabling accurate handling of token decimals.
  • Improvements

    • Updated event handling to support new versions with enhanced parameter structures and byte-based vault identifiers.
    • Simplified ERC20 entity management for improved reliability.
    • Streamlined network configuration to focus on mainnet and arbitrum-one deployments.
    • Enhanced subgraph manifest with updated ABIs and event signatures for improved compatibility.
  • Tests

    • Refactored and expanded test coverage to support new data types and floating-point arithmetic, ensuring robust validation of all major features.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 21, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update migrates the subgraph and its supporting scripts to use decimal floating-point arithmetic (via a new DecimalFloat contract) for all amounts and balances, replacing previous BigInt usage. It updates event types and schemas, modifies handler and entity logic, refactors vault and order identifiers to Bytes, and adapts all tests and configuration files accordingly. Network configuration is also streamlined.

Changes

Files/Groups Change Summary
.github/workflows/deploy-subgraph.yaml, .github/workflows/test-subgraph.yml Updated workflow steps to run rainix-sol-prelude and rainix-rs-prelude in nested directories; added extra setup steps for subgraph unit tests.
lib/rain.interpreter Updated submodule commit reference.
pointers.sh, prep-all.sh Added setup commands for rain.math.float library in nested directories using nix develop.
subgraph/networks.json Removed all networks except "arbitrum-one" and "mainnet"; updated or cleared OrderBook addresses and startBlocks.
subgraph/package.json Added dependency: source-map-support@^0.5.21.
subgraph/schema.graphql Changed all BigInt! fields for amounts, balances, and vault IDs to Bytes!; updated interface implementations.
subgraph/subgraph.yaml Added DecimalFloat ABI; updated event handler mappings to new event versions with changed parameter types and structures.
subgraph/src/float.ts New module providing Float type alias, network-to-address mapping, and calculator contract instantiation.
subgraph/src/erc20.ts Removed makeERC20EntityId; now uses raw addresses as ERC20 entity IDs.
subgraph/src/vault.ts Refactored vault IDs to Bytes; introduced VaultBalanceChange class; all balance logic uses decimal float calculator.
subgraph/src/deposit.ts, subgraph/src/withdraw.ts, subgraph/src/clear.ts, subgraph/src/takeorder.ts, subgraph/src/tradevaultbalancechange.ts Refactored all event handlers and entity creation to use decimal float calculator, new event types, and Bytes for vault IDs and amounts; updated function signatures and logic accordingly.
subgraph/src/handlers.ts, subgraph/src/order.ts Updated all handler and entity creation signatures to use new event versions (V2/V3), Bytes vault IDs, and float arithmetic; adjusted imports.
subgraph/tests/*.ts Refactored all tests to use new IOV2 class, Bytes for vault IDs, and decimal float constants for amounts/balances; updated event mocks, assertions, and setup to match new types and logic; added/updated float mock utilities and test helpers.

Sequence Diagram(s)

sequenceDiagram
    participant Subgraph
    participant DecimalFloatContract
    participant Vault
    participant EventHandler

    Note over Subgraph: On event (DepositV2, WithdrawV2, etc.)
    Subgraph->>EventHandler: Receives event with Bytes vaultId, Float amount
    EventHandler->>DecimalFloatContract: Uses calculator for arithmetic (add, sub, minus, gt)
    DecimalFloatContract-->>EventHandler: Returns Float result
    EventHandler->>Vault: Updates vault balance with Float values
    EventHandler->>Subgraph: Creates/updates entities with Bytes/Float fields
Loading

Estimated code review effort

5 (>120 minutes)

Possibly related PRs

Suggested labels

rust


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@0xgleb 0xgleb changed the base branch from main to upd/alloy July 21, 2025 13:36
@0xgleb 0xgleb changed the base branch from upd/alloy to 2024-09-12-i9r July 21, 2025 13:37
@0xgleb 0xgleb self-assigned this Jul 21, 2025
@0xgleb 0xgleb linked an issue Jul 21, 2025 that may be closed by this pull request
@0xgleb 0xgleb marked this pull request as ready for review July 21, 2025 13:47
@0xgleb
Copy link
Copy Markdown
Collaborator Author

0xgleb commented Jul 21, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@0xgleb
Copy link
Copy Markdown
Collaborator Author

0xgleb commented Jul 21, 2025

@CodeRabbit full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 21, 2025

✅ Actions performed

Full review triggered.

@0xgleb
Copy link
Copy Markdown
Collaborator Author

0xgleb commented Jul 21, 2025

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 21, 2025

✅ Actions performed

Full review triggered.

@0xgleb 0xgleb requested review from findolor and hardyjosh July 21, 2025 16:01
@rouzwelt
Copy link
Copy Markdown
Contributor

@CodeRabbit full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 21, 2025

✅ Actions performed

Full review triggered.

Comment thread subgraph/src/handlers.ts Outdated
} from "../generated/OrderBook/OrderBook";
import { Withdraw } from "../generated/OrderBook/OrderBook";
import { WithdrawV2 } from "../generated/OrderBook/OrderBook";
import { log } from "@graphprotocol/graph-ts";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this used?

@0xgleb 0xgleb merged commit 449e5e4 into 2024-09-12-i9r Jul 23, 2025
7 of 18 checks passed
@0xgleb 0xgleb deleted the feat/subgraph-upgrade branch July 23, 2025 11:27
@coderabbitai coderabbitai Bot mentioned this pull request Feb 1, 2026
4 tasks
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.

Update subgraph

4 participants