-
Notifications
You must be signed in to change notification settings - Fork 22
feat: fetch round data from crisp server #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d6f1b12
fix: server resetting data
ctrlc03 e7f35b7
chore: add license
ctrlc03 1dee93c
feat: get round data from crisp server
ctrlc03 e168fd7
chore: add snapshot block to round data
ctrlc03 4c39926
chore: update start_round
ctrlc03 cd33596
chore: remove redundant block variable
ctrlc03 cc6b23f
chore: remove block from e3crisp
ctrlc03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<IRoundDetails> => { | ||
| 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: BigInt(data.id), | ||
| tokenAddress: data.token_address, | ||
| balanceThreshold: BigInt(data.balance_threshold), | ||
| chainId: BigInt(data.chain_id), | ||
| enclaveAddress: data.enclave_address, | ||
| status: data.status, | ||
| 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, | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 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, balance threshold and snapshot block | ||
| */ | ||
| export const getRoundTokenDetails = async (serverUrl: string, e3Id: number): Promise<ITokenDetails> => { | ||
| const roundDetails = await getRoundDetails(serverUrl, e3Id) | ||
| return { | ||
| tokenAddress: roundDetails.tokenAddress, | ||
| threshold: roundDetails.balanceThreshold, | ||
| snapshotBlock: roundDetails.startBlock, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // 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 | ||
| } | ||
|
|
||
| /** | ||
| * Interface representing the details of a specific round in a more convenient format | ||
| */ | ||
| export interface IRoundDetails { | ||
| e3Id: bigint | ||
| chainId: bigint | ||
| enclaveAddress: string | ||
| status: string | ||
| voteCount: bigint | ||
| startTime: bigint | ||
| duration: bigint | ||
| expiration: bigint | ||
| startBlock: bigint | ||
| committeePublicKey: string[] | ||
| emojis: [string, string] | ||
| tokenAddress: string | ||
| balanceThreshold: bigint | ||
| } | ||
|
|
||
| /** | ||
| * Interface representing the token details required for participation in a round | ||
| */ | ||
| export interface ITokenDetails { | ||
| tokenAddress: string | ||
| threshold: bigint | ||
| snapshotBlock: bigint | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // 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 { describe, expect, it } from 'vitest' | ||
|
|
||
| import { getRoundDetails, getRoundTokenDetails } from '../src/state' | ||
| import { CRISP_SERVER_URL } from './constants' | ||
| import { zeroAddress } from 'viem' | ||
|
|
||
| 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 getRoundTokenDetails(CRISP_SERVER_URL, 0) | ||
| expect(tokenDetails.tokenAddress).not.toBe(zeroAddress) | ||
| expect(tokenDetails.threshold).toBeGreaterThan(0) | ||
| expect(tokenDetails.snapshotBlock).toBeGreaterThan(0) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,5 @@ coverage.json | |
| package-lock.json | ||
| pnpm-lock.yaml | ||
| yarn.lock | ||
|
|
||
| deployed_contracts.json | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.