Skip to content

feat: fetch round data from crisp server#811

Merged
ctrlc03 merged 7 commits into
devfrom
feat/get-round-data
Oct 9, 2025
Merged

feat: fetch round data from crisp server#811
ctrlc03 merged 7 commits into
devfrom
feat/get-round-data

Conversation

@ctrlc03

@ctrlc03 ctrlc03 commented Oct 8, 2025

Copy link
Copy Markdown
Collaborator

fix #808

merge #804 first

Summary by CodeRabbit

  • New Features

    • Introduced CRISP SDK package with typed APIs to fetch round details and token holder tree data, plus a consolidated entry point and constants.
    • Server state now includes token address and balance threshold.
    • Added a POST endpoint to retrieve token holder hashes.
  • Tests

    • Added unit tests covering round details, token/threshold extraction, and token tree retrieval.
  • Chores/Tooling

    • Added workspace entry for the SDK, TypeScript config, and Prettier config/ignores.
    • Updated deployment script to skip pre-deploy cleanup.

@vercel

vercel Bot commented Oct 8, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
crisp Skipped Skipped Oct 9, 2025 4:15pm
enclave-docs Skipped Skipped Oct 9, 2025 4:15pm

@ctrlc03 ctrlc03 requested a review from cedoor October 8, 2025 12:45
@coderabbitai

coderabbitai Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

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

Introduces a CRISP SDK package with TypeScript source, types, constants, and tests for fetching round details and token tree data. Updates server models, repository, indexer, and routes to persist token parameters, separate initialize vs. start round, and expose new endpoints. Adjusts workspace, formatting ignores, and a deploy script.

Changes

Cohort / File(s) Summary
SDK: Tooling & Config
examples/CRISP/sdk/.prettierignore, examples/CRISP/sdk/.prettierrc, examples/CRISP/sdk/package.json, examples/CRISP/sdk/tsconfig.json
Adds SDK package config, Prettier settings/ignores, scripts, dev deps, and TS build output to dist.
SDK: Source API
examples/CRISP/sdk/src/constants.ts, examples/CRISP/sdk/src/index.ts, examples/CRISP/sdk/src/state.ts, examples/CRISP/sdk/src/token.ts, examples/CRISP/sdk/src/types.ts
Adds constants and types; exports state/token APIs. Implements getRoundDetails, getRoundTokenAndThreshold, and getTreeData; adds placeholders for Merkle-proof and balance.
SDK: Tests
examples/CRISP/sdk/tests/constants.ts, examples/CRISP/sdk/tests/state.test.ts, examples/CRISP/sdk/tests/token.test.ts
Adds Vitest tests for state and token fetch operations against a local server URL.
Server: Models & Repo
examples/CRISP/server/src/server/models.rs, examples/CRISP/server/src/server/repo.rs
Adds token_address and balance_threshold to E3 structures and state-lite; introduces start_round() and changes initialize_round(token_address, balance_threshold); updates getters to include new fields.
Server: Indexer & Routes
examples/CRISP/server/src/server/indexer.rs, examples/CRISP/server/src/server/routes/state.rs
On E3 request, now persists token params via initialize_round; on activation, calls start_round. Adds POST /token-holders handler and related logging/contract handling adjustments.
Scripts
examples/CRISP/scripts/evm_deploy.sh
Removes deletion of deployments/localhost prior to pnpm deploy:mocks --network localhost.
Workspace & Formatting
pnpm-workspace.yaml, packages/enclave-contracts/.prettierignore
Includes SDK in workspace and ignores deployed_contracts.json for Prettier.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Chain as Chain Events
  participant Indexer as Server Indexer
  participant Repo as CrispE3Repository
  Note over Indexer,Repo: E3 lifecycle control flow (new/changed)

  Chain->>Indexer: E3 Requested
  Indexer->>Repo: initialize_round(token_address, balance_threshold)
  Repo-->>Indexer: Ok / Err

  Chain->>Indexer: E3 Activated
  Indexer->>Repo: start_round()
  Repo-->>Indexer: Ok / Err
Loading
sequenceDiagram
  autonumber
  actor App as Client App
  participant SDK as CRISP SDK
  participant API as CRISP Server

  rect rgb(240,248,255)
    note right of SDK: New SDK fetch APIs
    App->>SDK: getRoundDetails(serverUrl, e3Id)
    SDK->>API: POST /state/lite { id: e3Id }
    API-->>SDK: IRoundDetailsResponse
    SDK-->>App: IRoundDetails
  end

  App->>SDK: getTreeData(serverUrl, e3Id)
  SDK->>API: POST /token-holders { round_id: e3Id }
  API-->>SDK: token holder hashes
  SDK-->>App: data
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • ryardley
  • hmzakhalid
  • auryn-macmillan

Poem

In burrows of code I hop and peep,
New SDK sprouts where servers keep.
Rounds now start, tokens align,
Hashes rustle down the vine.
Tests nibble bytes, all tidy and neat—
Thump-thump! Another commit complete. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request includes infrastructure and formatting updates such as Prettier configs, workspace and package manifest changes, an unrelated script modification, and placeholder SDK functions with tests that do not pertain to fetching round data, which fall outside the scope of issue #808. Please separate the unrelated configuration, tooling, script adjustments, and placeholder SDK functions into distinct pull requests so this one can focus solely on implementing round data fetching.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues Check ✅ Passed The pull request adds the getRoundDetails and getRoundTokenAndThreshold functions, associated types, index exports, server persistence, and tests to fulfill the requirement from issue #808 to fetch round-related data from the CRISP SDK, thereby meeting the linked issue’s objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the primary feature introduced in this changeset—adding the ability to fetch round data from the CRISP server—and uses a standardized “feat:” prefix without extraneous detail. It directly reflects the linked issue’s objective to retrieve round-related information, making it easy for a reviewer to understand the main purpose of the PR at a glance.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 10

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/CRISP/server/src/server/indexer.rs (1)

50-66: Persist after validation to avoid stale "Requested" rounds.

You call initialize_round before fetching/validating token holders. If Bitquery fails or returns empty, you return Err leaving a persisted "Requested" round with no data.

Apply this local change: remove the early initialize_round call here and invoke it only after token_holders is verified non-empty.

-                // save the e3 details
-                repo.initialize_round(custom_params.token_address, custom_params.balance_threshold).await?;
+                // defer persistence until after token_holders are verified non-empty

Then, after the if token_holders.is_empty() check (on success path), initialize:

// After verifying token_holders is not empty
repo.initialize_round(custom_params.token_address, custom_params.balance_threshold).await?;

Optionally, if you prefer keeping the early write, add a compensating action on error (e.g., set status="Error" or delete the entry) to avoid dangling state.

🧹 Nitpick comments (9)
examples/CRISP/sdk/tests/token.test.ts (1)

14-17: Strengthen test assertions to validate data structure.

The test only verifies that data.length > 0 but doesn't validate the structure or content of the returned data. Consider adding assertions to check that the data conforms to expected shape (e.g., array of objects with specific properties).

examples/CRISP/sdk/tests/state.test.ts (2)

14-17: Strengthen test assertions to validate state structure.

The test only checks that state is defined but doesn't validate the structure or content. Consider adding assertions for key properties (e.g., e3Id, tokenAddress, status) to ensure the returned data conforms to IRoundDetails.


21-25: Strengthen test assertions to validate token details structure.

The test checks that tokenAddress and threshold are defined but doesn't validate their types or values. Consider adding type checks or value validations to ensure data integrity.

examples/CRISP/sdk/src/token.ts (3)

14-26: Add explicit return type for type safety.

The function has an implicit any return type. Consider defining a proper type for the tree data structure and using it as the return type.


23-23: Consider renaming variable for clarity.

The variable name hashes suggests it contains hash values, but based on the endpoint name token-holders and the generic return, it might contain broader data. Consider using a more descriptive name like data or treeData.


31-31: Document TODO for stub functions.

The stub functions generateMerkleProof and getBalanceAt are placeholders. Consider adding TODO comments or tracking these in an issue.

Would you like me to open an issue to track the implementation of these placeholder functions?

Also applies to: 36-36

examples/CRISP/server/src/server/repo.rs (3)

14-14: Remove unused import.

num_bigint::BigUint is not used in this file.

-use num_bigint::BigUint;

115-128: Consider making initialize_round idempotent and validating inputs.

To handle duplicate E3Requested events safely, skip overwriting if a CRISP entry already exists, and optionally validate non-empty token_address/balance_threshold.

Example:

pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String) -> Result<()> {
    // If already initialized, return early (idempotent)
    if self.store.get::<E3Crisp>(&self.crisp_key()).await?.is_some() {
        return Ok(());
    }
    // Optionally validate inputs here
    self.set_crisp(E3Crisp {
        has_voted: vec![],
        start_time: 0,
        status: "Requested".to_string(),
        votes_option_1: 0,
        votes_option_2: 0,
        emojis: generate_emoji(),
        token_holder_hashes: vec![],
        token_address,
        balance_threshold,
    }).await
}

268-279: LGTM: persist token_holder_hashes.

Closure clone is fine here; consider moving clone outside only if hot path.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b4b7dc and ab3aecb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (19)
  • examples/CRISP/scripts/evm_deploy.sh (0 hunks)
  • examples/CRISP/sdk/.prettierignore (1 hunks)
  • examples/CRISP/sdk/.prettierrc (1 hunks)
  • examples/CRISP/sdk/package.json (1 hunks)
  • examples/CRISP/sdk/src/constants.ts (1 hunks)
  • examples/CRISP/sdk/src/index.ts (1 hunks)
  • examples/CRISP/sdk/src/state.ts (1 hunks)
  • examples/CRISP/sdk/src/token.ts (1 hunks)
  • examples/CRISP/sdk/src/types.ts (1 hunks)
  • examples/CRISP/sdk/tests/constants.ts (1 hunks)
  • examples/CRISP/sdk/tests/state.test.ts (1 hunks)
  • examples/CRISP/sdk/tests/token.test.ts (1 hunks)
  • examples/CRISP/sdk/tsconfig.json (1 hunks)
  • examples/CRISP/server/src/server/indexer.rs (3 hunks)
  • examples/CRISP/server/src/server/models.rs (4 hunks)
  • examples/CRISP/server/src/server/repo.rs (5 hunks)
  • examples/CRISP/server/src/server/routes/state.rs (3 hunks)
  • packages/enclave-contracts/.prettierignore (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • examples/CRISP/scripts/evm_deploy.sh
🧰 Additional context used
🧬 Code graph analysis (7)
examples/CRISP/sdk/src/types.ts (1)
examples/CRISP/sdk/src/index.ts (2)
  • IRoundDetails (11-11)
  • ITokenDetails (11-11)
examples/CRISP/sdk/src/token.ts (1)
examples/CRISP/sdk/src/constants.ts (1)
  • CRISP_SERVER_TOKEN_TREE_ENDPOINT (7-7)
examples/CRISP/sdk/src/state.ts (2)
examples/CRISP/sdk/src/types.ts (3)
  • IRoundDetails (31-46)
  • IRoundDetailsResponse (10-26)
  • ITokenDetails (51-54)
examples/CRISP/sdk/src/constants.ts (1)
  • CRISP_SERVER_STATE_LITE_ENDPOINT (8-8)
examples/CRISP/sdk/tests/state.test.ts (2)
examples/CRISP/sdk/src/state.ts (2)
  • getRoundDetails (14-41)
  • getRoundTokenAndThreshold (49-55)
examples/CRISP/sdk/tests/constants.ts (1)
  • CRISP_SERVER_URL (7-7)
examples/CRISP/sdk/tests/token.test.ts (1)
examples/CRISP/sdk/src/token.ts (1)
  • getTreeData (14-26)
examples/CRISP/server/src/server/routes/state.rs (2)
crates/evm-helpers/src/contracts.rs (1)
  • create_write (251-271)
examples/CRISP/server/src/server/repo.rs (2)
  • store (36-38)
  • store (79-81)
examples/CRISP/server/src/server/repo.rs (1)
examples/CRISP/server/src/server/database.rs (1)
  • generate_emoji (80-101)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: test_enclave_init
  • GitHub Check: crisp_e2e
  • GitHub Check: integration_prebuild
  • GitHub Check: test_net
  • GitHub Check: rust_unit
  • GitHub Check: build_sdk
  • GitHub Check: test_contracts
  • GitHub Check: Build & Push Image
🔇 Additional comments (18)
examples/CRISP/server/src/server/routes/state.rs (4)

13-16: LGTM!

The expanded imports are correctly aligned with the contract creation and interaction code below.


29-29: Evaluate access control requirements for token holder data.

The new /token-holders endpoint exposes token holder hashes (hash of address and token balance) for any round. Consider whether this data should be publicly accessible or if it requires authentication/authorization, as it could reveal:

  • Token distribution patterns
  • Voting power distribution (if used in governance)
  • Round participation information

If this data is intentionally public for transparency purposes, consider documenting this design decision. Otherwise, add appropriate access controls.


34-39: LGTM!

The added documentation improves code maintainability by clearly describing the webhook callback's purpose, arguments, and return value.


43-46: LGTM!

The logging and error handling improvements enhance observability:

  • Structured logging with E3 ID and transaction hash aids debugging
  • JSON error responses provide consistency across the API
  • Error handling properly propagates failures with descriptive messages

Also applies to: 48-62, 82-86

examples/CRISP/sdk/.prettierignore (1)

3-3: Verify: ignoring .prettierrc may prevent formatting validation.

It's unusual to ignore the .prettierrc configuration file itself. This prevents Prettier from formatting or checking the config file, which might hide formatting inconsistencies if the config is manually edited.

If this was intentional (e.g., to avoid conflicts), document the reason. Otherwise, consider removing this entry to allow Prettier to validate its own configuration file.

packages/enclave-contracts/.prettierignore (1)

24-24: LGTM!

Adding deployed_contracts.json to the ignore list is appropriate, as deployment artifacts are typically generated files that should not be formatted.

examples/CRISP/sdk/.prettierrc (1)

1-10: LGTM!

The Prettier configuration is well-structured with reasonable formatting preferences. The wider printWidth of 140 is acceptable for modern development, and all other settings follow common conventions.

pnpm-workspace.yaml (1)

6-6: LGTM!

Adding the SDK package to the workspace correctly integrates it into the monorepo, enabling proper dependency management and linking.

examples/CRISP/sdk/tests/constants.ts (1)

7-7: LGTM!

The test server URL constant is appropriately defined for local testing. Hardcoding localhost:4000 is standard practice for test configurations.

examples/CRISP/sdk/src/types.ts (1)

10-26: Verify and align naming in IRoundDetailsResponse
The interface mixes snake_case (token_address, balance_threshold) and camelCase (tokenAddress, snapshotBlock), creating apparent duplicates. Confirm the actual server response naming convention and remove or rename duplicates accordingly.

examples/CRISP/sdk/tsconfig.json (1)

6-6: moduleResolution "bundler" is supported by the project’s TypeScript 5.8.3—no changes required.

examples/CRISP/sdk/src/constants.ts (1)

7-8: LGTM!

The endpoint constants are well-defined and follow a clear naming convention.

examples/CRISP/sdk/src/index.ts (1)

7-11: LGTM!

The public API surface is well-organized with clear re-exports of functionality and types.

examples/CRISP/sdk/src/state.ts (1)

49-55: LGTM!

The function provides a clean abstraction for fetching just the token details, making the API more convenient for callers who don't need the full round details.

examples/CRISP/server/src/server/models.rs (1)

132-135: LGTM: token params plumbed through models and mapping.

Added fields and From mapping are consistent with repo/indexer usage.

Also applies to: 171-173, 184-186, 216-218

examples/CRISP/server/src/server/indexer.rs (1)

140-140: Activation flow looks good; ensure start_round fails if CRISP not initialized.

Assuming repo.start_round() errors when the CRISP record is absent; otherwise this silently no-ops. See repo fix.

examples/CRISP/server/src/server/repo.rs (2)

214-216: LGTM: expose token params in E3StateLite.

Mapping from CRISP to E3StateLite looks correct.


284-286: LGTM: return holder hashes.

Returning owned Vec is appropriate.

Comment thread examples/CRISP/sdk/package.json
Comment thread examples/CRISP/sdk/package.json
Comment thread examples/CRISP/sdk/src/state.ts
Comment thread examples/CRISP/sdk/src/state.ts Outdated
Comment thread examples/CRISP/sdk/src/token.ts
Comment thread examples/CRISP/sdk/tests/state.test.ts Outdated
Comment thread examples/CRISP/sdk/tests/token.test.ts Outdated
Comment thread examples/CRISP/server/src/server/repo.rs
Comment thread examples/CRISP/server/src/server/routes/state.rs
Comment thread examples/CRISP/server/src/server/routes/state.rs
@ctrlc03 ctrlc03 changed the title feat: fetch token data from crisp server feat: fetch round data from crisp server Oct 8, 2025
@ctrlc03 ctrlc03 deleted the branch dev October 8, 2025 15:11
@ctrlc03 ctrlc03 closed this Oct 8, 2025
@cedoor cedoor reopened this Oct 8, 2025
@cedoor cedoor changed the base branch from main to dev October 8, 2025 15:25
@ctrlc03 ctrlc03 force-pushed the feat/get-round-data branch from ab3aecb to 6f23863 Compare October 9, 2025 10:30
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 9, 2025 10:31 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp October 9, 2025 10:31 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp October 9, 2025 10:57 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 9, 2025 10:57 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 9, 2025 11:38 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp October 9, 2025 11:38 Inactive
@ctrlc03 ctrlc03 enabled auto-merge (squash) October 9, 2025 11:41
Comment thread examples/CRISP/server/src/server/repo.rs Outdated
@ctrlc03 ctrlc03 requested a review from cedoor October 9, 2025 12:18
@ctrlc03 ctrlc03 self-assigned this Oct 9, 2025
@ctrlc03 ctrlc03 force-pushed the feat/get-round-data branch from 59546e3 to cd33596 Compare October 9, 2025 16:06
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 9, 2025 16:06 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp October 9, 2025 16:06 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp October 9, 2025 16:15 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 9, 2025 16:15 Inactive
@ctrlc03 ctrlc03 merged commit 0b305d1 into dev Oct 9, 2025
6 checks passed
@ctrlc03 ctrlc03 deleted the feat/get-round-data branch October 11, 2025 16:06
ctrlc03 added a commit that referenced this pull request Oct 11, 2025
* fix: server resetting data

* chore: add license

* feat: get round data from crisp server

* chore: add snapshot block to round data

* chore: update start_round
ctrlc03 added a commit that referenced this pull request Oct 11, 2025
* fix: server resetting data

* chore: add license

* feat: get round data from crisp server

* chore: add snapshot block to round data

* chore: update start_round
cedoor pushed a commit that referenced this pull request Oct 14, 2025
* fix: server resetting data

* chore: add license

* feat: get round data from crisp server

* chore: add snapshot block to round data

* chore: update start_round
cedoor pushed a commit that referenced this pull request Oct 14, 2025
* fix: server resetting data

* chore: add license

* feat: get round data from crisp server

* chore: add snapshot block to round data

* chore: update start_round
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.

CRISP SDK fetch round data from the server

2 participants