From d6f1b12f01d8d17e02816d0962f0c6d1f5152470 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Wed, 8 Oct 2025 12:27:48 +0100 Subject: [PATCH 1/7] fix: server resetting data --- examples/CRISP/server/src/server/repo.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/CRISP/server/src/server/repo.rs b/examples/CRISP/server/src/server/repo.rs index 4cbd0275c2..8eed709d91 100644 --- a/examples/CRISP/server/src/server/repo.rs +++ b/examples/CRISP/server/src/server/repo.rs @@ -260,7 +260,6 @@ impl CrispE3Repository { pub async fn set_token_holder_hashes(&mut self, hashes: Vec) -> Result<()> { let key = self.crisp_key(); - self.store .modify(&key, |e3_obj: Option| { e3_obj.map(|mut e| { @@ -270,13 +269,15 @@ impl CrispE3Repository { }) .await .map_err(|_| eyre::eyre!("Could not set token_holder_hashes for '{key}'"))?; - Ok(()) } pub async fn get_token_holder_hashes(&self) -> Result> { - let e3_crisp = self.get_crisp().await?; + + let key = self.crisp_key(); + info!("Getting token holder hashes for key: {}", key); + let e3_crisp = self.get_crisp().await?; Ok(e3_crisp.token_holder_hashes) } From e7f35b78a67349ebde0f33343ce44d6472a87156 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Wed, 8 Oct 2025 12:28:27 +0100 Subject: [PATCH 2/7] chore: add license --- examples/CRISP/server/src/server/repo.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/CRISP/server/src/server/repo.rs b/examples/CRISP/server/src/server/repo.rs index 8eed709d91..34bd16586d 100644 --- a/examples/CRISP/server/src/server/repo.rs +++ b/examples/CRISP/server/src/server/repo.rs @@ -269,15 +269,13 @@ impl CrispE3Repository { }) .await .map_err(|_| eyre::eyre!("Could not set token_holder_hashes for '{key}'"))?; + Ok(()) } pub async fn get_token_holder_hashes(&self) -> Result> { - - let key = self.crisp_key(); - info!("Getting token holder hashes for key: {}", key); - let e3_crisp = self.get_crisp().await?; + Ok(e3_crisp.token_holder_hashes) } From 1dee93c8903cf4847d7e2fc84b1db4aec48b542d Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Wed, 8 Oct 2025 13:41:59 +0100 Subject: [PATCH 3/7] feat: get round data from crisp server --- examples/CRISP/sdk/src/constants.ts | 1 + examples/CRISP/sdk/src/index.ts | 7 ++- examples/CRISP/sdk/src/state.ts | 55 +++++++++++++++++++++ examples/CRISP/sdk/src/token.ts | 36 ++++---------- examples/CRISP/sdk/src/types.ts | 54 ++++++++++++++++++++ examples/CRISP/sdk/tests/constants.ts | 7 +++ examples/CRISP/sdk/tests/state.test.ts | 27 ++++++++++ examples/CRISP/server/src/server/indexer.rs | 13 ++--- examples/CRISP/server/src/server/models.rs | 11 ++++- examples/CRISP/server/src/server/repo.rs | 7 ++- packages/enclave-contracts/.prettierignore | 2 + 11 files changed, 183 insertions(+), 37 deletions(-) create mode 100644 examples/CRISP/sdk/src/state.ts create mode 100644 examples/CRISP/sdk/src/types.ts create mode 100644 examples/CRISP/sdk/tests/constants.ts create mode 100644 examples/CRISP/sdk/tests/state.test.ts diff --git a/examples/CRISP/sdk/src/constants.ts b/examples/CRISP/sdk/src/constants.ts index f2fd540441..0fff8b6607 100644 --- a/examples/CRISP/sdk/src/constants.ts +++ b/examples/CRISP/sdk/src/constants.ts @@ -5,3 +5,4 @@ // or FITNESS FOR A PARTICULAR PURPOSE. export const CRISP_SERVER_TOKEN_TREE_ENDPOINT = 'state/token-holders' +export const CRISP_SERVER_STATE_LITE_ENDPOINT = 'state/lite' diff --git a/examples/CRISP/sdk/src/index.ts b/examples/CRISP/sdk/src/index.ts index f6d3f918d6..a2dc538db4 100644 --- a/examples/CRISP/sdk/src/index.ts +++ b/examples/CRISP/sdk/src/index.ts @@ -4,5 +4,8 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -export * from "./token"; -export * from "./constants"; +export * from './token' +export * from './state' +export * from './constants' + +export type { IRoundDetails, ITokenDetails } from './types' diff --git a/examples/CRISP/sdk/src/state.ts b/examples/CRISP/sdk/src/state.ts new file mode 100644 index 0000000000..1f3e618c25 --- /dev/null +++ b/examples/CRISP/sdk/src/state.ts @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +import { CRISP_SERVER_STATE_LITE_ENDPOINT } from './constants' + +import type { IRoundDetailsResponse, IRoundDetails, ITokenDetails } from './types' + +/** + * Get the details of a specific round + */ +export const getRoundDetails = async (serverUrl: string, e3Id: number): Promise => { + const response = await fetch(`${serverUrl}/${CRISP_SERVER_STATE_LITE_ENDPOINT}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ round_id: e3Id }), + }) + + const data = (await response.json()) as IRoundDetailsResponse + + return { + e3Id: Number(data.id), + tokenAddress: data.token_address, + balanceThreshold: data.balance_threshold, + chainId: Number(data.chain_id), + enclaveAddress: data.enclave_address, + status: data.status, + voteCount: Number(data.vote_count), + startTime: Number(data.start_time), + duration: Number(data.duration), + expiration: Number(data.expiration), + startBlock: Number(data.start_block), + committeePublicKey: data.committee_public_key, + emojis: data.emojis, + snapshotBlock: Number(data.start_block), + } +} + +/** + * Get the token address and balance threshold for a specific round + * @param serverUrl - The base URL of the CRISP server + * @param e3Id - The e3Id of the round + * @returns The token address and balance threshold + */ +export const getRoundTokenAndThreshold = async (serverUrl: string, e3Id: number): Promise => { + const roundDetails = await getRoundDetails(serverUrl, e3Id) + return { + tokenAddress: roundDetails.tokenAddress, + threshold: roundDetails.balanceThreshold, + } +} diff --git a/examples/CRISP/sdk/src/token.ts b/examples/CRISP/sdk/src/token.ts index a743ed5001..e0c10ded71 100644 --- a/examples/CRISP/sdk/src/token.ts +++ b/examples/CRISP/sdk/src/token.ts @@ -12,21 +12,17 @@ import { CRISP_SERVER_TOKEN_TREE_ENDPOINT } from './constants' * @param e3Id - The e3Id of the round */ export const getTreeData = async (serverUrl: string, e3Id: number) => { - try { - const response = await fetch(`${serverUrl}/${CRISP_SERVER_TOKEN_TREE_ENDPOINT}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ round_id: e3Id }), - }) + const response = await fetch(`${serverUrl}/${CRISP_SERVER_TOKEN_TREE_ENDPOINT}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ round_id: e3Id }), + }) - const hashes = await response.json() + const hashes = await response.json() - return hashes - } catch (error) { - console.error('Error fetching tree data:', error) - } + return hashes } /** @@ -38,17 +34,3 @@ export const generateMerkleProof = () => {} * Get the token balance at a specific block for a given address */ export const getBalanceAt = () => {} - -/** - * Interface representing the details of a specific round - */ -export interface IRoundDetails { - tokenAddress: string - snapshotBlock: string - threshold: string -} - -/** - * Get the details of a specific round - */ -export const getRoundDetails = () => {} diff --git a/examples/CRISP/sdk/src/types.ts b/examples/CRISP/sdk/src/types.ts new file mode 100644 index 0000000000..a0cd9ee745 --- /dev/null +++ b/examples/CRISP/sdk/src/types.ts @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +/** + * Interface representing the details of a specific round returned by the CRISP server + */ +export interface IRoundDetailsResponse { + id: string + chain_id: string + enclave_address: string + status: string + vote_count: string + start_time: string + duration: string + expiration: string + start_block: string + committee_public_key: string[] + emojis: [string, string] + token_address: string + balance_threshold: string + tokenAddress: string + snapshotBlock: string +} + +/** + * Interface representing the details of a specific round in a more convenient format + */ +export interface IRoundDetails { + e3Id: number + chainId: number + enclaveAddress: string + status: string + voteCount: number + startTime: number + duration: number + expiration: number + startBlock: number + committeePublicKey: string[] + emojis: [string, string] + tokenAddress: string + balanceThreshold: string + snapshotBlock: number +} + +/** + * Interface representing the token details required for participation in a round + */ +export interface ITokenDetails { + tokenAddress: string + threshold: string +} diff --git a/examples/CRISP/sdk/tests/constants.ts b/examples/CRISP/sdk/tests/constants.ts new file mode 100644 index 0000000000..ce3a8c6784 --- /dev/null +++ b/examples/CRISP/sdk/tests/constants.ts @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. + +export const CRISP_SERVER_URL = 'http://localhost:4000' diff --git a/examples/CRISP/sdk/tests/state.test.ts b/examples/CRISP/sdk/tests/state.test.ts new file mode 100644 index 0000000000..7e354d8507 --- /dev/null +++ b/examples/CRISP/sdk/tests/state.test.ts @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY + +import { describe, expect, it } from 'vitest' + +import { getRoundDetails, getRoundTokenAndThreshold } from '../src/state' +import { CRISP_SERVER_URL } from './constants' + +// or FITNESS FOR A PARTICULAR PURPOSE. +describe('State', () => { + describe('getRoundDetails', () => { + it('should get the state for a given e3Id from the CRISP server', async () => { + const state = await getRoundDetails(CRISP_SERVER_URL, 0) + expect(state).toBeDefined() + }) + }) + + describe('getTokenDetails', () => { + it('should return the details of the token for a given e3Id from the CRISP server', async () => { + const tokenDetails = await getRoundTokenAndThreshold(CRISP_SERVER_URL, 0) + expect(tokenDetails.tokenAddress).toBeDefined() + expect(tokenDetails.threshold).toBeDefined() + }) + }) +}) diff --git a/examples/CRISP/server/src/server/indexer.rs b/examples/CRISP/server/src/server/indexer.rs index 3d097f7597..a00dc9f533 100644 --- a/examples/CRISP/server/src/server/indexer.rs +++ b/examples/CRISP/server/src/server/indexer.rs @@ -47,12 +47,10 @@ pub async fn register_e3_requested( info!("E3Requested: {:?}", event); async move { - repo.initialize_round().await?; - - // Convert custom params bytes back to token address and balance threshold. - let custom_params: CustomParams = - serde_json::from_slice(&event.e3.customParams) - .with_context(|| "Failed to parse custom params from E3 event")?; + // Convert custom params bytes back to token address and balance threshold. + let custom_params: CustomParams = + serde_json::from_slice(&event.e3.customParams) + .with_context(|| "Failed to parse custom params from E3 event")?; let token_address: Address = custom_params .token_address @@ -63,6 +61,9 @@ pub async fn register_e3_requested( BigUint::parse_bytes(custom_params.balance_threshold.as_bytes(), 10) .ok_or_else(|| eyre::eyre!("Invalid balance threshold"))?; + // save the e3 details + repo.initialize_round(custom_params.token_address, custom_params.balance_threshold).await?; + // Get token holders from Bitquery API or mocked data. let token_holders = if matches!(CONFIG.chain_id, 31337 | 1337) { info!( diff --git a/examples/CRISP/server/src/server/models.rs b/examples/CRISP/server/src/server/models.rs index a0e328191a..33707c3c94 100644 --- a/examples/CRISP/server/src/server/models.rs +++ b/examples/CRISP/server/src/server/models.rs @@ -4,7 +4,6 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -use alloy::primitives::Address; use anyhow::Result; use num_bigint::BigUint; use serde::{Deserialize, Deserializer, Serialize}; @@ -130,6 +129,9 @@ pub struct E3StateLite { pub committee_public_key: Vec, pub emojis: [String; 2], + + pub token_address: String, + pub balance_threshold: String, } #[derive(Debug, Deserialize, Serialize)] @@ -165,6 +167,9 @@ pub struct E3 { // Emojis pub emojis: [String; 2], + + // Custom Parameters + pub custom_params: CustomParams, } #[derive(Debug, Deserialize, Serialize)] @@ -176,6 +181,8 @@ pub struct E3Crisp { pub votes_option_1: u64, pub votes_option_2: u64, pub token_holder_hashes: Vec, + pub token_address: String, + pub balance_threshold: String, } impl From for WebResultRequest { @@ -206,6 +213,8 @@ impl From for E3StateLite { expiration: e3.expiration, committee_public_key: e3.committee_public_key, emojis: e3.emojis, + token_address: e3.custom_params.token_address, + balance_threshold: e3.custom_params.balance_threshold, } } } diff --git a/examples/CRISP/server/src/server/repo.rs b/examples/CRISP/server/src/server/repo.rs index 34bd16586d..5b0e6a5d89 100644 --- a/examples/CRISP/server/src/server/repo.rs +++ b/examples/CRISP/server/src/server/repo.rs @@ -11,6 +11,7 @@ use super::{ use e3_sdk::indexer::{models::E3 as EnclaveE3, DataStore, E3Repository, SharedStore}; use eyre::Result; use log::info; +use num_bigint::BigUint; pub struct CurrentRoundRepository { store: SharedStore, @@ -111,7 +112,7 @@ impl CrispE3Repository { Ok(()) } - pub async fn initialize_round(&mut self) -> Result<()> { + pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String) -> Result<()> { self.set_crisp(E3Crisp { has_voted: vec![], start_time: 0u64, @@ -120,6 +121,8 @@ impl CrispE3Repository { votes_option_2: 0, emojis: generate_emoji(), token_holder_hashes: vec![], + token_address, + balance_threshold }) .await } @@ -208,6 +211,8 @@ impl CrispE3Repository { start_block: e3.request_block, enclave_address: e3.enclave_address, committee_public_key: e3.committee_public_key, + token_address: e3_crisp.token_address, + balance_threshold: e3_crisp.balance_threshold, }) } diff --git a/packages/enclave-contracts/.prettierignore b/packages/enclave-contracts/.prettierignore index c3995b0dbc..4dbc5c12db 100644 --- a/packages/enclave-contracts/.prettierignore +++ b/packages/enclave-contracts/.prettierignore @@ -20,3 +20,5 @@ coverage.json package-lock.json pnpm-lock.yaml yarn.lock + +deployed_contracts.json From e168fd7e6b2f9dd430c8a8b81ce0e2713501ffa5 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 9 Oct 2025 11:57:09 +0100 Subject: [PATCH 4/7] chore: add snapshot block to round data --- examples/CRISP/sdk/src/state.ts | 25 +++++++++++---------- examples/CRISP/sdk/src/types.ts | 24 ++++++++++---------- examples/CRISP/sdk/tests/state.test.ts | 10 +++++---- examples/CRISP/server/src/server/indexer.rs | 5 +++-- examples/CRISP/server/src/server/models.rs | 24 +++----------------- examples/CRISP/server/src/server/repo.rs | 7 +++--- 6 files changed, 41 insertions(+), 54 deletions(-) diff --git a/examples/CRISP/sdk/src/state.ts b/examples/CRISP/sdk/src/state.ts index 1f3e618c25..a84189d02e 100644 --- a/examples/CRISP/sdk/src/state.ts +++ b/examples/CRISP/sdk/src/state.ts @@ -23,33 +23,34 @@ export const getRoundDetails = async (serverUrl: string, e3Id: number): Promise< const data = (await response.json()) as IRoundDetailsResponse return { - e3Id: Number(data.id), + e3Id: BigInt(data.id), tokenAddress: data.token_address, - balanceThreshold: data.balance_threshold, - chainId: Number(data.chain_id), + balanceThreshold: BigInt(data.balance_threshold), + chainId: BigInt(data.chain_id), enclaveAddress: data.enclave_address, status: data.status, - voteCount: Number(data.vote_count), - startTime: Number(data.start_time), - duration: Number(data.duration), - expiration: Number(data.expiration), - startBlock: Number(data.start_block), + voteCount: BigInt(data.vote_count), + startTime: BigInt(data.start_time), + duration: BigInt(data.duration), + expiration: BigInt(data.expiration), + startBlock: BigInt(data.start_block), committeePublicKey: data.committee_public_key, emojis: data.emojis, - snapshotBlock: Number(data.start_block), + snapshotBlock: BigInt(data.block_number_requested), } } /** - * Get the token address and balance threshold for a specific round + * Get the token address, balance threshold and snapshot block for a specific round * @param serverUrl - The base URL of the CRISP server * @param e3Id - The e3Id of the round - * @returns The token address and balance threshold + * @returns The token address, balance threshold and snapshot block */ -export const getRoundTokenAndThreshold = async (serverUrl: string, e3Id: number): Promise => { +export const getRoundTokenDetails = async (serverUrl: string, e3Id: number): Promise => { const roundDetails = await getRoundDetails(serverUrl, e3Id) return { tokenAddress: roundDetails.tokenAddress, threshold: roundDetails.balanceThreshold, + snapshotBlock: roundDetails.snapshotBlock, } } diff --git a/examples/CRISP/sdk/src/types.ts b/examples/CRISP/sdk/src/types.ts index a0cd9ee745..e229d99f82 100644 --- a/examples/CRISP/sdk/src/types.ts +++ b/examples/CRISP/sdk/src/types.ts @@ -21,28 +21,27 @@ export interface IRoundDetailsResponse { emojis: [string, string] token_address: string balance_threshold: string - tokenAddress: string - snapshotBlock: string + block_number_requested: string } /** * Interface representing the details of a specific round in a more convenient format */ export interface IRoundDetails { - e3Id: number - chainId: number + e3Id: bigint + chainId: bigint enclaveAddress: string status: string - voteCount: number - startTime: number - duration: number - expiration: number - startBlock: number + voteCount: bigint + startTime: bigint + duration: bigint + expiration: bigint + startBlock: bigint committeePublicKey: string[] emojis: [string, string] tokenAddress: string - balanceThreshold: string - snapshotBlock: number + balanceThreshold: bigint + snapshotBlock: bigint } /** @@ -50,5 +49,6 @@ export interface IRoundDetails { */ export interface ITokenDetails { tokenAddress: string - threshold: string + threshold: bigint + snapshotBlock: bigint } diff --git a/examples/CRISP/sdk/tests/state.test.ts b/examples/CRISP/sdk/tests/state.test.ts index 7e354d8507..83ff070627 100644 --- a/examples/CRISP/sdk/tests/state.test.ts +++ b/examples/CRISP/sdk/tests/state.test.ts @@ -5,8 +5,9 @@ import { describe, expect, it } from 'vitest' -import { getRoundDetails, getRoundTokenAndThreshold } from '../src/state' +import { getRoundDetails, getRoundTokenDetails } from '../src/state' import { CRISP_SERVER_URL } from './constants' +import { zeroAddress } from 'viem' // or FITNESS FOR A PARTICULAR PURPOSE. describe('State', () => { @@ -19,9 +20,10 @@ describe('State', () => { describe('getTokenDetails', () => { it('should return the details of the token for a given e3Id from the CRISP server', async () => { - const tokenDetails = await getRoundTokenAndThreshold(CRISP_SERVER_URL, 0) - expect(tokenDetails.tokenAddress).toBeDefined() - expect(tokenDetails.threshold).toBeDefined() + const tokenDetails = await getRoundTokenDetails(CRISP_SERVER_URL, 0) + expect(tokenDetails.tokenAddress).not.toBe(zeroAddress) + expect(tokenDetails.threshold).toBeGreaterThan(0) + expect(tokenDetails.snapshotBlock).toBeGreaterThan(0) }) }) }) diff --git a/examples/CRISP/server/src/server/indexer.rs b/examples/CRISP/server/src/server/indexer.rs index a00dc9f533..d7e002ba9b 100644 --- a/examples/CRISP/server/src/server/indexer.rs +++ b/examples/CRISP/server/src/server/indexer.rs @@ -62,7 +62,8 @@ pub async fn register_e3_requested( .ok_or_else(|| eyre::eyre!("Invalid balance threshold"))?; // save the e3 details - repo.initialize_round(custom_params.token_address, custom_params.balance_threshold).await?; + let block_number = event.e3.requestBlock.to::(); + repo.initialize_round(custom_params.token_address, custom_params.balance_threshold, block_number).await?; // Get token holders from Bitquery API or mocked data. let token_holders = if matches!(CONFIG.chain_id, 31337 | 1337) { @@ -83,7 +84,7 @@ pub async fn register_e3_requested( .get_token_holders( token_address, balance_threshold, - event.e3.requestBlock.to::(), + block_number, CONFIG.chain_id, 10000, // TODO: this is fine for now, but we need pagination or chunking strategies // to retrieve large datasets efficiently. diff --git a/examples/CRISP/server/src/server/models.rs b/examples/CRISP/server/src/server/models.rs index 33707c3c94..0a88d20948 100644 --- a/examples/CRISP/server/src/server/models.rs +++ b/examples/CRISP/server/src/server/models.rs @@ -5,7 +5,6 @@ // or FITNESS FOR A PARTICULAR PURPOSE. use anyhow::Result; -use num_bigint::BigUint; use serde::{Deserialize, Deserializer, Serialize}; #[derive(Deserialize, Debug)] @@ -132,8 +131,10 @@ pub struct E3StateLite { pub token_address: String, pub balance_threshold: String, + pub block_number_requested: u64, } + #[derive(Debug, Deserialize, Serialize)] pub struct E3 { // Identifiers @@ -183,6 +184,7 @@ pub struct E3Crisp { pub token_holder_hashes: Vec, pub token_address: String, pub balance_threshold: String, + pub block_number_requested: u64, } impl From for WebResultRequest { @@ -198,23 +200,3 @@ impl From for WebResultRequest { } } } - -impl From for E3StateLite { - fn from(e3: E3) -> Self { - E3StateLite { - id: e3.id, - chain_id: e3.chain_id, - enclave_address: e3.enclave_address, - status: e3.status, - vote_count: e3.vote_count, - start_time: e3.start_time, - start_block: e3.block_start, - duration: e3.duration, - expiration: e3.expiration, - committee_public_key: e3.committee_public_key, - emojis: e3.emojis, - token_address: e3.custom_params.token_address, - balance_threshold: e3.custom_params.balance_threshold, - } - } -} diff --git a/examples/CRISP/server/src/server/repo.rs b/examples/CRISP/server/src/server/repo.rs index 5b0e6a5d89..8d71fa1e7f 100644 --- a/examples/CRISP/server/src/server/repo.rs +++ b/examples/CRISP/server/src/server/repo.rs @@ -11,7 +11,6 @@ use super::{ use e3_sdk::indexer::{models::E3 as EnclaveE3, DataStore, E3Repository, SharedStore}; use eyre::Result; use log::info; -use num_bigint::BigUint; pub struct CurrentRoundRepository { store: SharedStore, @@ -112,7 +111,7 @@ impl CrispE3Repository { Ok(()) } - pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String) -> Result<()> { + pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String, block_number: u64) -> Result<()> { self.set_crisp(E3Crisp { has_voted: vec![], start_time: 0u64, @@ -122,7 +121,8 @@ impl CrispE3Repository { emojis: generate_emoji(), token_holder_hashes: vec![], token_address, - balance_threshold + balance_threshold, + block_number_requested: block_number, }) .await } @@ -213,6 +213,7 @@ impl CrispE3Repository { committee_public_key: e3.committee_public_key, token_address: e3_crisp.token_address, balance_threshold: e3_crisp.balance_threshold, + block_number_requested: e3_crisp.block_number_requested, }) } From 4c399268667c6090b16f19f11c7a8d062c173190 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:38:29 +0100 Subject: [PATCH 5/7] chore: update start_round --- examples/CRISP/sdk/tests/state.test.ts | 2 +- examples/CRISP/sdk/tests/token.test.ts | 4 ++-- examples/CRISP/server/src/server/repo.rs | 28 ++++-------------------- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/examples/CRISP/sdk/tests/state.test.ts b/examples/CRISP/sdk/tests/state.test.ts index 83ff070627..5287ab4c37 100644 --- a/examples/CRISP/sdk/tests/state.test.ts +++ b/examples/CRISP/sdk/tests/state.test.ts @@ -2,6 +2,7 @@ // // This file is provided WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. import { describe, expect, it } from 'vitest' @@ -9,7 +10,6 @@ import { getRoundDetails, getRoundTokenDetails } from '../src/state' import { CRISP_SERVER_URL } from './constants' import { zeroAddress } from 'viem' -// or FITNESS FOR A PARTICULAR PURPOSE. describe('State', () => { describe('getRoundDetails', () => { it('should get the state for a given e3Id from the CRISP server', async () => { diff --git a/examples/CRISP/sdk/tests/token.test.ts b/examples/CRISP/sdk/tests/token.test.ts index 2dc6251a68..6bd95b68d7 100644 --- a/examples/CRISP/sdk/tests/token.test.ts +++ b/examples/CRISP/sdk/tests/token.test.ts @@ -7,12 +7,12 @@ import { describe, expect, it } from 'vitest' import { getTreeData } from '../src/token' +import { CRISP_SERVER_URL } from './constants' // @notice To run these tests you will need to have an instance of CRISP running locally describe('Token data fetching', () => { - const serverUrl = 'http://localhost:4000' it('should fetch token data from the CRISP server', async () => { - const data = await getTreeData(serverUrl, 0) + const data = await getTreeData(CRISP_SERVER_URL, 0) expect(data.length).toBeGreaterThan(0) }) }) diff --git a/examples/CRISP/server/src/server/repo.rs b/examples/CRISP/server/src/server/repo.rs index 8d71fa1e7f..2c7b9f9d17 100644 --- a/examples/CRISP/server/src/server/repo.rs +++ b/examples/CRISP/server/src/server/repo.rs @@ -85,30 +85,10 @@ impl CrispE3Repository { } pub async fn start_round(&mut self) -> Result<()> { - let start_time = chrono::Utc::now().timestamp() as u64; - let key = self.crisp_key(); - - self.store - .modify(&key, |e3_obj: Option| { - e3_obj.map(|mut e| { - e.start_time = start_time; - e - }) - }) - .await - .map_err(|_| eyre::eyre!("Could not update start_time for '{key}'"))?; - - self.store - .modify(&key, |e3_obj: Option| { - e3_obj.map(|mut e| { - e.status = "Active".to_string(); - e - }) - }) - .await - .map_err(|_| eyre::eyre!("Could not update status for '{key}'"))?; - - Ok(()) + let mut e3_crisp = self.get_crisp().await?; + e3_crisp.start_time = chrono::Utc::now().timestamp() as u64; + e3_crisp.status = "Active".to_string(); + self.set_crisp(e3_crisp).await } pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String, block_number: u64) -> Result<()> { From cd33596a94f40ca11b6f0faa9114d0bdd5fb8e4d Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 9 Oct 2025 17:05:55 +0100 Subject: [PATCH 6/7] chore: remove redundant block variable --- examples/CRISP/sdk/src/state.ts | 3 +-- examples/CRISP/sdk/src/types.ts | 2 -- examples/CRISP/server/src/server/models.rs | 1 - examples/CRISP/server/src/server/repo.rs | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/examples/CRISP/sdk/src/state.ts b/examples/CRISP/sdk/src/state.ts index a84189d02e..3a926121e6 100644 --- a/examples/CRISP/sdk/src/state.ts +++ b/examples/CRISP/sdk/src/state.ts @@ -36,7 +36,6 @@ export const getRoundDetails = async (serverUrl: string, e3Id: number): Promise< startBlock: BigInt(data.start_block), committeePublicKey: data.committee_public_key, emojis: data.emojis, - snapshotBlock: BigInt(data.block_number_requested), } } @@ -51,6 +50,6 @@ export const getRoundTokenDetails = async (serverUrl: string, e3Id: number): Pro return { tokenAddress: roundDetails.tokenAddress, threshold: roundDetails.balanceThreshold, - snapshotBlock: roundDetails.snapshotBlock, + snapshotBlock: roundDetails.startBlock, } } diff --git a/examples/CRISP/sdk/src/types.ts b/examples/CRISP/sdk/src/types.ts index e229d99f82..8daca5b4ea 100644 --- a/examples/CRISP/sdk/src/types.ts +++ b/examples/CRISP/sdk/src/types.ts @@ -21,7 +21,6 @@ export interface IRoundDetailsResponse { emojis: [string, string] token_address: string balance_threshold: string - block_number_requested: string } /** @@ -41,7 +40,6 @@ export interface IRoundDetails { emojis: [string, string] tokenAddress: string balanceThreshold: bigint - snapshotBlock: bigint } /** diff --git a/examples/CRISP/server/src/server/models.rs b/examples/CRISP/server/src/server/models.rs index 0a88d20948..d638ac8915 100644 --- a/examples/CRISP/server/src/server/models.rs +++ b/examples/CRISP/server/src/server/models.rs @@ -131,7 +131,6 @@ pub struct E3StateLite { pub token_address: String, pub balance_threshold: String, - pub block_number_requested: u64, } diff --git a/examples/CRISP/server/src/server/repo.rs b/examples/CRISP/server/src/server/repo.rs index 2c7b9f9d17..d39b284d8f 100644 --- a/examples/CRISP/server/src/server/repo.rs +++ b/examples/CRISP/server/src/server/repo.rs @@ -193,7 +193,6 @@ impl CrispE3Repository { committee_public_key: e3.committee_public_key, token_address: e3_crisp.token_address, balance_threshold: e3_crisp.balance_threshold, - block_number_requested: e3_crisp.block_number_requested, }) } From cc6b23f4face47430b06ea7b2a9753c8a814120b Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Thu, 9 Oct 2025 17:15:18 +0100 Subject: [PATCH 7/7] chore: remove block from e3crisp --- examples/CRISP/server/src/server/indexer.rs | 5 ++--- examples/CRISP/server/src/server/models.rs | 1 - examples/CRISP/server/src/server/repo.rs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/CRISP/server/src/server/indexer.rs b/examples/CRISP/server/src/server/indexer.rs index d7e002ba9b..a00dc9f533 100644 --- a/examples/CRISP/server/src/server/indexer.rs +++ b/examples/CRISP/server/src/server/indexer.rs @@ -62,8 +62,7 @@ pub async fn register_e3_requested( .ok_or_else(|| eyre::eyre!("Invalid balance threshold"))?; // save the e3 details - let block_number = event.e3.requestBlock.to::(); - repo.initialize_round(custom_params.token_address, custom_params.balance_threshold, block_number).await?; + repo.initialize_round(custom_params.token_address, custom_params.balance_threshold).await?; // Get token holders from Bitquery API or mocked data. let token_holders = if matches!(CONFIG.chain_id, 31337 | 1337) { @@ -84,7 +83,7 @@ pub async fn register_e3_requested( .get_token_holders( token_address, balance_threshold, - block_number, + event.e3.requestBlock.to::(), CONFIG.chain_id, 10000, // TODO: this is fine for now, but we need pagination or chunking strategies // to retrieve large datasets efficiently. diff --git a/examples/CRISP/server/src/server/models.rs b/examples/CRISP/server/src/server/models.rs index d638ac8915..b46c7b033d 100644 --- a/examples/CRISP/server/src/server/models.rs +++ b/examples/CRISP/server/src/server/models.rs @@ -183,7 +183,6 @@ pub struct E3Crisp { pub token_holder_hashes: Vec, pub token_address: String, pub balance_threshold: String, - pub block_number_requested: u64, } impl From for WebResultRequest { diff --git a/examples/CRISP/server/src/server/repo.rs b/examples/CRISP/server/src/server/repo.rs index d39b284d8f..6a96a081a3 100644 --- a/examples/CRISP/server/src/server/repo.rs +++ b/examples/CRISP/server/src/server/repo.rs @@ -91,7 +91,7 @@ impl CrispE3Repository { self.set_crisp(e3_crisp).await } - pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String, block_number: u64) -> Result<()> { + pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String) -> Result<()> { self.set_crisp(E3Crisp { has_voted: vec![], start_time: 0u64, @@ -102,7 +102,6 @@ impl CrispE3Repository { token_holder_hashes: vec![], token_address, balance_threshold, - block_number_requested: block_number, }) .await }