Skip to content

Adding the juror's total stake for all courts in the StakeSet event back in #1935

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 7 commits into from
Mar 28, 2025

Conversation

jaybuidl
Copy link
Member

@jaybuidl jaybuidl commented Mar 27, 2025

PR-Codex overview

This PR updates the StakeSet event to include an additional parameter, amountAllCourts, and modifies related code to handle this change. It also refines event names and updates the version of the package.

Detailed summary

  • Updated StakeSet event to include amountAllCourts.
  • Modified createStakeSetEvent function to accept the new parameter.
  • Adjusted event handling in handleStakeSet to utilize the new parameter.
  • Renamed StakeDelayedAlreadyTransferred to StakeDelayedAlreadyTransferredDeposited.
  • Updated related tests to reflect the new event structure and parameters.
  • Incremented package version from 0.12.0 to 0.13.0.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Enhanced staking event logs with additional details for improved tracking and transparency.
    • Introduced notifications covering delayed and locked stake scenarios.
  • Tests

    • Updated validations to ensure the expanded event details are correctly captured during stake operations.
    • Adjusted assertions in tests to reflect changes in event names and parameters.
    • Added new parameters in test cases to align with updated event structures.

Copy link
Contributor

coderabbitai bot commented Mar 27, 2025

Walkthrough

This pull request updates the event logging functionality in staking-related contracts by modifying the StakeSet event to include an extra parameter representing total staked tokens across courts. It also adds new events to capture various delayed staking scenarios and stake locking actions. The corresponding tests have been updated to assert the new event parameter signatures, ensuring that the contracts emit detailed staking information.

Changes

File(s) Change Summary
contracts/src/arbitration/SortitionModuleBase.sol
contracts/src/arbitration/university/SortitionModuleUniversity.sol
Updated the StakeSet event signature to include an additional parameter (_amountAllCourts). Added new events: StakeDelayedNotTransferred, StakeDelayedAlreadyTransferredDeposited, StakeDelayedAlreadyTransferredWithdrawn (in Base) and StakeLocked to document stake delays and locking statuses. Also updated event emissions in stake-setting functions.
contracts/test/arbitration/staking-neo.ts
contracts/test/arbitration/staking.ts
contracts/test/foundry/KlerosCore.t.sol
Modified test cases to include an extra argument when asserting the emitted events. Test assertions now verify the additional parameter in the StakeSet events and adjust expected outcomes to reflect this change in both normal and delayed stake operations.
subgraph/core-neo/subgraph.yaml
subgraph/core/src/SortitionModule.ts
subgraph/core/subgraph.yaml
subgraph/core/tests/sortition-module-utils.ts
Updated event handlers and function signatures to reflect the renaming of StakeDelayedAlreadyTransferred to StakeDelayedAlreadyTransferredDeposited. Adjusted corresponding function names and return types to maintain consistency with the new event type.

Sequence Diagram(s)

sequenceDiagram
    participant Juror
    participant Contract
    participant EventLogger

    Juror->>Contract: setStake(stake, courtID, currentStake)
    Contract->>EventLogger: Emit StakeSet(juror, courtID, stake, totalStaked)
    alt Delayed Stake Scenario
        Contract->>EventLogger: Emit StakeDelayedNotTransferred / StakeDelayedAlreadyTransferredDeposited / StakeDelayedAlreadyTransferredWithdrawn
    end
    alt Stake Locking
        Contract->>EventLogger: Emit StakeLocked(juror, amount, unlockState)
    end
Loading

Possibly related PRs

  • Patches and various version bumps #1728: The changes in the main PR are related to those in the retrieved PR as both involve modifications to the StakeSet event, specifically the addition of a new parameter, _amountAllCourts, and the renaming of the StakeDelayedAlreadyTransferred event to StakeDelayedAlreadyTransferredDeposited.
  • feat(subgraph,web): fix coherent votes at vote level instead of dispute level #1702: The changes in the main PR regarding event modifications in the SortitionModuleBase contract are directly related to the updates in the SortitionModuleUniversity contract, as both PRs involve similar alterations to the StakeSet event and the introduction of the StakeLocked event.
  • Feat/dispute dates and hashes link #1816: The changes in the main PR regarding event modifications in the SortitionModuleBase contract are directly related to the updates in the SortitionModuleUniversity contract, as both PRs involve similar modifications to the StakeSet event and the introduction of the StakeLocked event.

Suggested labels

Type: Bug :bug:, Type: Security Patch🛡️

Suggested reviewers

  • alcercu

Poem

I hopped through lines of code so bright,
Tweaking events with all my might.
StakeSet now sings with extra cheer,
Logging tokens far and near.
With every fix, the code takes flight—
A rabbit's rhyme in code delight! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 4554947 and ba85c09.

📒 Files selected for processing (14)
  • contracts/src/arbitration/SortitionModuleBase.sol (3 hunks)
  • contracts/src/arbitration/university/SortitionModuleUniversity.sol (2 hunks)
  • contracts/test/arbitration/staking-neo.ts (12 hunks)
  • contracts/test/arbitration/staking.ts (6 hunks)
  • contracts/test/foundry/KlerosCore.t.sol (6 hunks)
  • subgraph/core-neo/subgraph.yaml (1 hunks)
  • subgraph/core-university/src/SortitionModule.ts (1 hunks)
  • subgraph/core-university/subgraph.yaml (1 hunks)
  • subgraph/core/schema.graphql (0 hunks)
  • subgraph/core/src/SortitionModule.ts (2 hunks)
  • subgraph/core/subgraph.yaml (1 hunks)
  • subgraph/core/tests/sortition-module-utils.ts (2 hunks)
  • subgraph/core/tests/sortition-module.test.ts (1 hunks)
  • subgraph/package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • subgraph/core/schema.graphql
✅ Files skipped from review due to trivial changes (1)
  • subgraph/package.json
🚧 Files skipped from review as they are similar to previous changes (6)
  • subgraph/core-neo/subgraph.yaml
  • subgraph/core/subgraph.yaml
  • subgraph/core/src/SortitionModule.ts
  • subgraph/core/tests/sortition-module-utils.ts
  • contracts/test/foundry/KlerosCore.t.sol
  • contracts/src/arbitration/SortitionModuleBase.sol
🧰 Additional context used
🧬 Code Definitions (2)
subgraph/core/tests/sortition-module.test.ts (1)
subgraph/core/tests/sortition-module-utils.ts (1)
  • createStakeSetEvent (91-109)
subgraph/core-university/src/SortitionModule.ts (1)
subgraph/core/src/SortitionModule.ts (1)
  • handleStakeSet (26-34)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
🔇 Additional comments (19)
subgraph/core-university/subgraph.yaml (1)

158-158: Event signature updated correctly with new parameter

The event signature for StakeSet has been updated to include a fourth parameter (uint256) that represents the juror's total stake across all courts. This aligns with the PR objectives to provide more context in this event.

subgraph/core/tests/sortition-module.test.ts (2)

13-13: Added required parameter for total stake across all courts

The new amountAllCourts variable correctly implements the PR's objective to include the juror's total stake for all courts in the StakeSet event.


15-15: Updated function call with new parameter

The createStakeSetEvent function call has been correctly updated to include the new amountAllCourts parameter, ensuring test compatibility with the updated event signature.

subgraph/core-university/src/SortitionModule.ts (3)

1-1: Simplified import statement

The import statement has been updated to directly import StakeSet without aliasing it as StakeSetEvent, making the code more concise and consistent with the new event handling approach.


7-7: Updated function signature to match event type

The function signature for handleStakeSet has been updated to accept StakeSet directly, maintaining proper type safety with the event changes.


9-9: Simplified event handler implementation

The implementation has been refactored to use ensureUser directly, but doesn't utilize the new _amountAllCourts parameter from the event. This is acceptable since the event processing isn't directly using that value, but rather ensuring user existence and updating juror stake information.

contracts/test/arbitration/staking-neo.ts (2)

186-186: Updated event assertions with the new parameter

Test assertions for StakeSet events have been correctly updated to include the new fourth parameter representing the total stake across all courts, ensuring test compatibility with the updated event signature.

Also applies to: 204-204, 209-209, 214-214, 233-233, 282-282, 312-312, 343-343, 459-459, 527-527, 616-616, 707-707


275-275: Updated event name in assertions

Event name has been updated from StakeDelayedAlreadyTransferred to StakeDelayedAlreadyTransferredDeposited in the assertions, maintaining consistency with the renamed event in the contract implementation.

Also applies to: 337-337, 433-433, 461-461, 709-709

contracts/test/arbitration/staking.ts (8)

90-90: Event name update reflects more precise behavior.

The event name change from "StakeDelayedAlreadyTransferred" to "StakeDelayedAlreadyTransferredDeposited" better describes the action taking place - specifically indicating that tokens have been deposited.


116-116: Added total stake parameter improves event context.

The additional parameter PNK(5000) represents the juror's total stake across all courts, providing more comprehensive information in the event logs and allowing more effective tracking of a juror's overall position.


118-118: Consistent event name update.

Event name has been properly updated to match the renamed event in the contracts.


182-182: Added total stake parameter for consistency.

This updated assertion correctly validates that the StakeSet event emits both the court-specific stake (1000 PNK) and the total stake across all courts (3000 PNK).


269-269: Total stake parameter correctly reflects the juror's position.

The assertion now checks that when delayed stakes are executed, the StakeSet event correctly reports both the court-specific stake (2000 PNK) and the global stake position (4000 PNK).


307-307: Updated event name is consistent.

This change maintains consistency with the contract implementation's updated event name.


358-358: Complete event parameter assertion.

The assertion now properly verifies all parameters of the StakeSet event, including the total stake across all courts.


360-360: Consistently updated event name in negative assertion.

The code correctly updates the event name in the negative assertion, ensuring that this event is not emitted during the specific test case.

contracts/src/arbitration/university/SortitionModuleUniversity.sol (3)

50-55: Improved event documentation with clear parameter descriptions.

The updated documentation for the StakeSet event now clearly explains all parameters, including the new _amountAllCourts parameter that represents the total amount of tokens staked across all courts. This addition enhances code readability and makes the event's purpose more explicit for developers.


57-61: Well-documented StakeLocked event.

The documentation for the StakeLocked event clearly describes its purpose and parameters, making it easy to understand when and why this event is emitted.


176-176: Event emission updated to include total stake information.

The StakeSet event emission now includes the juror's total stake across all courts (juror.stakedPnk), providing more comprehensive context about the juror's staking position when analyzing event logs.


🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 or @coderabbitai title 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.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the StakeSet event in the Sortition modules by adding an additional parameter that represents the juror's total stake across all courts.

  • Updated StakeSet event arguments in tests to include the total staked amount.
  • Adjusted test cases in both staking.ts and staking-neo.ts to account for the new parameter.

Reviewed Changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.

File Description
contracts/test/arbitration/staking.ts Updated test expectations for StakeSet event with the new total stake.
contracts/test/arbitration/staking-neo.ts Modified test assertions and totalStaked validations to include the new parameter.
Files not reviewed (3)
  • contracts/src/arbitration/SortitionModuleBase.sol: Language not supported
  • contracts/src/arbitration/university/SortitionModuleUniversity.sol: Language not supported
  • contracts/test/foundry/KlerosCore.t.sol: Language not supported

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit ba85c09
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/67e692052d23c20008dc03ee
😎 Deploy Preview https://deploy-preview-1935--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit ba85c09
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/67e69203a43d2d00082e9d6b
😎 Deploy Preview https://deploy-preview-1935--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit ba85c09
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/67e69203e14ecc000887022d
😎 Deploy Preview https://deploy-preview-1935--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 27, 2025
Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit ba85c09
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/67e69203f5c059000865bc02
😎 Deploy Preview https://deploy-preview-1935--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

kemuru
kemuru previously approved these changes Mar 27, 2025
@jaybuidl jaybuidl requested a review from Copilot March 27, 2025 22:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the StakeSet event in the staking contracts by including an additional parameter representing the total staked amount across all courts, and updates the related tests and documentation accordingly.

  • Updated the StakeSet event signature to include the new total staked parameter.
  • Adjusted test cases in both staking.ts and staking-neo.ts to validate the new event parameter.
  • Added detailed documentation for multiple staking-related events.

Reviewed Changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.

File Description
contracts/test/arbitration/staking.ts Updated test expectations for StakeSet to include the new parameter.
contracts/test/arbitration/staking-neo.ts Adjusted test cases to pass the new total staked parameter correctly.
Files not reviewed (3)
  • contracts/src/arbitration/SortitionModuleBase.sol: Language not supported
  • contracts/src/arbitration/university/SortitionModuleUniversity.sol: Language not supported
  • contracts/test/foundry/KlerosCore.t.sol: Language not supported
Comments suppressed due to low confidence (1)

contracts/test/arbitration/staking-neo.ts:706

  • The use of 'await sortition' with .to.emit is inconsistent with other tests where the contract instance is passed directly. Consider removing 'await' for consistency.
.to.emit(await sortition, "StakeSet")

@jaybuidl jaybuidl requested a review from a team as a code owner March 28, 2025 12:03
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 28, 2025
@jaybuidl jaybuidl force-pushed the feat/add-stakeset-total branch from 4554947 to c399c03 Compare March 28, 2025 12:10
…s-calculations

chore: revert stakeset handling in this subgraph and add new event parameter
Copy link

codeclimate bot commented Mar 28, 2025

Code Climate has analyzed commit ba85c09 and detected 17 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 15
Style 2

View more on Code Climate.

@jaybuidl jaybuidl merged commit 9b77f32 into dev Mar 28, 2025
25 of 26 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants