Skip to content
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

feat(perp): Add DNR Epoch Wiring #1683

Merged
merged 11 commits into from
Dec 1, 2023
Merged

feat(perp): Add DNR Epoch Wiring #1683

merged 11 commits into from
Dec 1, 2023

Conversation

testinginprod
Copy link
Collaborator

@testinginprod testinginprod commented Nov 29, 2023

Description

This PR wires the AfterEpochEnd hook to the DnR StartNewEpoch function.

Purpose

Wraps up DnR feature.

Summary by CodeRabbit

  • New Features

    • Introduced a new Discounts and Rebates (DnR) epoch tracking system to enhance reward mechanisms.
  • Enhancements

    • Improved the epoch handling logic to automatically update DnR epochs based on predefined schedules.
  • Bug Fixes

    • Fixed an issue where DnR epochs were not correctly initialized and tracked within the system.
  • Documentation

    • Updated documentation to reflect the new DnR epoch functionality and its impact on end-users.
  • Tests

    • Added comprehensive tests to ensure the reliability of the DnR epoch tracking and update mechanisms.

@testinginprod testinginprod requested a review from a team as a code owner November 29, 2023 14:21
Copy link
Contributor

coderabbitai bot commented Nov 29, 2023

Warning

Rate Limit Exceeded

@testinginprod has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 9 minutes and 11 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 1437748 and 976301c.

Walkthrough

The updates involve the introduction of a new Discounts and Rebates (DnR) epoch mechanism within a blockchain module. A field to track the DnR epoch name has been added to the genesis state and keeper structure. New logic ensures that when an epoch ends, if it matches the DnR epoch name, a new DnR epoch is started. Additionally, tests have been added to verify the correct behavior of the DnR epoch functionality.

Changes

File Path Changes
proto/nibiru/perp/v2/genesis.proto Added dnr_epoch_name field to GenesisState.
x/perp/v2/keeper/... Added maybeUpdateDnREpoch function and DnREpochName field to Keeper. Updated AfterEpochEnd to call maybeUpdateDnREpoch.
x/perp/v2/module/... Updated InitGenesis and ExportGenesis to handle DnrEpochName.
x/perp/v2/keeper/dnr_test.go Added tests for DnR epoch functionality with new actionFn type and helper functions.

🐇✨
A field of epochs, a keeper's new quest,
To track the DnR, and start it afresh.
Tests hop along, ensuring it's best,
CodeRabbit's work, in the blockchain's nest.
🌟🚀


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2d59c9d and 8e860ac.
Files ignored due to filter (1)
  • x/perp/v2/types/genesis.pb.go
Files selected for processing (7)
  • proto/nibiru/perp/v2/genesis.proto (1 hunks)
  • x/perp/v2/keeper/dnr.go (1 hunks)
  • x/perp/v2/keeper/dnr_test.go (2 hunks)
  • x/perp/v2/keeper/hooks.go (1 hunks)
  • x/perp/v2/keeper/keeper.go (3 hunks)
  • x/perp/v2/module/genesis.go (2 hunks)
  • x/perp/v2/module/genesis_test.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • proto/nibiru/perp/v2/genesis.proto
  • x/perp/v2/module/genesis.go
Additional comments: 9
x/perp/v2/keeper/dnr_test.go (4)
  • 5-13: The imports added are consistent with the summary and seem to be necessary for the new test functions introduced.

  • 257-261: The new type actionFn and its method Do are correctly implemented and follow the description provided in the summary.

  • 264-282: The new functions dnrEpochIdentifierIs, triggerEpoch, and expectDnREpoch are implemented as described in the summary and return an actionFn as expected.

  • 263-301: The TestDnREpoch function is correctly implemented with test cases for DnR epochs, including scenarios for valid and invalid identifiers, as outlined in the summary.

x/perp/v2/keeper/keeper.go (3)
  • 38-45: The addition of the DnREpochName field to the Keeper struct aligns with the summary and the purpose of the pull request to track the DnR epoch identifier.

  • 129-138: The initialization of the DnREpochName field in the NewKeeper function is correctly done using the collections.NewItem() with the appropriate namespace and value encoder.

  • 151-155: The addition of the NamespaceDnrEpochName constant is consistent with the new field added to the Keeper struct and is necessary for the correct functioning of the DnREpochName field.

x/perp/v2/module/genesis_test.go (2)
  • 104-108: The addition of setting DnREpochName and DnREpoch in the context is consistent with the summary and the pull request description. This ensures that the DnR feature is correctly initialized with the epoch mechanism.

  • 156-157: The assertions for DnrEpochName and DnrEpoch are correctly placed to ensure that the genesis state is properly initialized and exported with the new fields related to the DnR feature.

x/perp/v2/keeper/dnr.go Show resolved Hide resolved
x/perp/v2/keeper/hooks.go Show resolved Hide resolved
Copy link

codecov bot commented Nov 29, 2023

Codecov Report

Merging #1683 (976301c) into master (2d59c9d) will increase coverage by 0.00%.
The diff coverage is 80.95%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1683   +/-   ##
=======================================
  Coverage   73.92%   73.93%           
=======================================
  Files         192      192           
  Lines       15398    15418   +20     
=======================================
+ Hits        11383    11399   +16     
- Misses       3355     3358    +3     
- Partials      660      661    +1     
Files Coverage Δ
x/perp/v2/keeper/hooks.go 80.43% <100.00%> (+0.43%) ⬆️
x/perp/v2/keeper/keeper.go 97.46% <100.00%> (+0.13%) ⬆️
x/perp/v2/module/genesis.go 95.86% <100.00%> (+0.08%) ⬆️
x/perp/v2/keeper/dnr.go 80.51% <66.66%> (-1.18%) ⬇️

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8e860ac and 1437748.
Files selected for processing (1)
  • x/perp/v2/keeper/dnr_test.go (2 hunks)
Additional comments: 4
x/perp/v2/keeper/dnr_test.go (4)
  • 9-9: The addition of "github.com/stretchr/testify/require" is appropriate for the new test cases that use require assertions.

  • 258-262: The actionFn type and its Do method are well-defined and provide a clear way to define actions for test cases.

  • 265-283: The helper functions dnrEpochIdentifierIs, triggerEpoch, and expectDnREpoch are correctly implemented to facilitate the testing of DnR epoch functionality.

  • 286-300: The test cases in TestDnREpoch are well-structured, using the helper functions to effectively test both valid and invalid DnR epoch identifiers.

@Unique-Divine Unique-Divine merged commit 7792ff0 into master Dec 1, 2023
17 checks passed
@Unique-Divine Unique-Divine deleted the tip/dnr/epoch branch December 1, 2023 07:53
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.

4 participants