chore: add voting token with balance 1#1172
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
📝 WalkthroughWalkthroughAdds a mock ERC20 (MockVotingToken) with per-address cap, consolidates mock deployment flags into USE_MOCKS and updates deploy scripts/records, reduces client mint amount from 1e18→1e9, and adds getMerkleLeaves to a voting hook dependency to avoid stale closures. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Deployer (script)
participant DeployTS as deploy/crisp.ts
participant Chain as Blockchain
participant Token as MockVotingToken
participant Client as Web Client
Dev->>DeployTS: run with USE_MOCKS=true
DeployTS->>Chain: deploy MockVotingToken
Chain-->>DeployTS: address & blockNumber
DeployTS->>DeployTS: write deployed_contracts.json (MockCRISPToken)
Dev->>Client: start client (uses mint hook)
Client->>Token: call mint(to, amount=1e9)
Token-->>Client: success / silent no-op if cap exceeded
Client->>Client: useVoteCasting uses updated getMerkleLeaves dependency
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@examples/CRISP/packages/crisp-contracts/deploy/crisp.ts`:
- Around line 29-43: The MockVotingToken deployment is not waited on, so the
blockNumber captured in storeDeploymentArgs may be before the tx is mined;
update the MockVotingToken deployment code (where you call
ethers.deployContract('MockVotingToken')) to call and await the
contract.waitForDeployment() before calling token.getAddress() and before
calling storeDeploymentArgs (using the same pattern as other deployments like
ZKTranscriptLib/RiscZeroGroth16Verifier), and also make the network name
derivation resilient by replacing the existing chain lookup with a safe fallback
using (await owner.provider?.getNetwork())?.name ?? "localhost" so chain is
never undefined.
🧹 Nitpick comments (2)
examples/CRISP/packages/crisp-contracts/deploy/crisp.ts (1)
117-117: Avoid logging undefined token address when mocks are off.
Line 117 printsTokenAddress: undefinedwhenUSE_MOCKSis false; consider guarding the line or logging a clearer message.examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockVotingToken.sol (1)
16-29: Use MAX_BALANCE constant and fix the stale comment.
Line 16’s “half of 10e18” doesn’t match1e9, and1e9is repeated in constructor/mint. Consider usingMAX_BALANCEto avoid drift.♻️ Suggested refactor
- // half of 10e18 + // Cap per address for mock voting power uint256 public constant MAX_BALANCE = 1e9; constructor() ERC20("Mock Voting Token", "MVT") { - _mint(msg.sender, 1e9); + _mint(msg.sender, MAX_BALANCE); } function mint(address to, uint256) external { - if (balanceOf(to) + 1e9 > MAX_BALANCE) { + if (balanceOf(to) + MAX_BALANCE > MAX_BALANCE) { // silently fail return; } - _mint(to, 1e9); + _mint(to, MAX_BALANCE); }
Fixes deployed demo on sepolia, where it is not possible to vote because of balance mismatch (crisp app hardcodes 1, and the backend creates the tree using the actual token balance)
Summary by CodeRabbit
New Features
Updates
✏️ Tip: You can customize this high-level summary in your review settings.