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

Add initial Rates contract #557

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

neekolas
Copy link
Contributor

@neekolas neekolas commented Feb 26, 2025

TL;DR

  • Introduces a new RatesManager contract to manage message, storage, and congestion fees with role-based access control.
  • Will be used in a RatesFetcher so that we can get a centralized source of rate changes

What changed?

  • Created new RatesManager contract with AccessControl functionality
  • Implemented a Rates struct to store messageFee, storageFee, congestionFee, and startTime
  • Added functions to append new rates chronologically
  • Included paginated view function to retrieve rates in batches of 50
  • Added comprehensive test coverage for the new contract

How to test?

  1. Run the test suite in RatesManager.t.sol
  2. Verify role-based access control by attempting unauthorized rate additions
  3. Test pagination by adding >50 rates and retrieving them in chunks
  4. Confirm chronological ordering by attempting to add rates out of sequence
  5. Check empty state handling with a fresh contract instance

Why make this change?

To provide a secure and organized way to manage protocol fees over time while maintaining historical records. The implementation ensures only authorized addresses can modify rates while allowing anyone to view the fee history through a paginated interface.

Summary by CodeRabbit

  • New Features
    • Introduced a new rate management functionality that lets authorized users securely add and retrieve rate settings. The feature enforces a chronological order for entries and supports paginated queries for an improved user experience.

Copy link

coderabbitai bot commented Feb 26, 2025

Walkthrough

The pull request introduces a new Solidity contract, RatesManager, to manage rate settings with fee parameters and controlled access via OpenZeppelin’s access control framework. The contract allows authorized users to add new rates, ensuring rates are added in chronological order, and provides a paginated retrieval of stored rates. Additionally, a new test suite (RatesTest) has been created to validate these functionalities. A minor formatting update has been made in the identity-related tests to streamline the error revert expectations.

Changes

File(s) Change Summary
contracts/src/RatesManager.sol Added new contract RatesManager with a Rates struct, a dedicated RATES_ADMIN_ROLE, functions addRates, getRates, and getRatesCount, and an emitted RatesAdded event when new rates are appended.
contracts/test/RatesManager.t.sol Added new test contract RatesTest to validate rate addition, unauthorized access rejections, chronological ordering of rates, and pagination functionality.
contracts/test/IdentityUpdates.t.sol Refactored revert error handling formatting by consolidating the multi-line abi.encodeWithSelector call into a single line in the expectRevert assertion.
contracts/dev/generate Updated the default list of contracts in the main function to include RatesManager, expanding the list from four to five contracts.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Rate Admin
    participant RM as RatesManager
    participant Test as Test Suite
    Admin->>RM: Call addRates(messageFee, storageFee, congestionFee, startTime)
    RM-->>Admin: Validate input, update allRates, emit RatesAdded event
    Test->>RM: Call getRates(fromIndex)
    RM-->>Test: Return paginated rates array with hasMore flag
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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 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
Contributor Author

neekolas commented Feb 26, 2025

@neekolas neekolas marked this pull request as ready for review February 26, 2025 19:41
@neekolas neekolas requested a review from a team as a code owner February 26, 2025 19:41
Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (5)
contracts/test/RatesManager.t.sol (4)

8-12: Unused admin address.
The admin variable is declared at line 10 but never used throughout the test. Consider removing or using it to verify that the admin can perform privileged actions accordingly.


25-40: Consider verifying the rates count.
After calling addRate, you already verify the array contents. It might be more robust to also check ratesManager.getRatesCount() to ensure consistency with the stored length.

 function testAddRatesValid() public {
     ...
+    assertEq(ratesManager.getRatesCount(), 1);
 }

70-82: Pagination test covers standard scenario.
Testing with 60 items ensures a valid pagination scenario of 50 + 10. This is an effective coverage for paging logic. For completeness, consider testing an edge case like exactly 50 items or a small fraction.


84-92: Test function marked as 'view'.
Although the test is read-only, typically test functions omit the view specifier to allow for potential state modifications if needed. It still works with Foundry, but you might consider removing view for consistency with other test functions.

contracts/src/RatesManager.sol (1)

58-93: Pagination approach is clear.
The pageSize is hardcoded to 50. This is fine for typical use-cases, but if dynamic pagination or user-configurable pages are desired in the future, consider refactoring.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8dc2a5 and 275058d.

📒 Files selected for processing (3)
  • contracts/src/RatesManager.sol (1 hunks)
  • contracts/test/IdentityUpdates.t.sol (1 hunks)
  • contracts/test/RatesManager.t.sol (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • contracts/test/IdentityUpdates.t.sol
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build pre-baked anvil-xmtpd
🔇 Additional comments (7)
contracts/test/RatesManager.t.sol (5)

13-15: Constants usage looks good.
Defining the fee amounts as constants clarifies intent and ensures they cannot be inadvertently changed.


17-19: Setup function is concise.
Instantiating a fresh RatesManager for each test ensures isolation. This approach is correct.


21-23: Helper function improves reusability.
Using addRate to wrap ratesManager.addRates(...) is a neat way to streamline repetitive calls.


42-52: Unauthorized revert check is valid.
The test accurately verifies that an address without RATES_ADMIN_ROLE cannot add rates. This effectively tests access control.


54-68: Consider additional boundary checks.
You correctly test that adding a rate with the same startTime reverts. For stronger coverage, test if a past startTime (e.g., below current block.timestamp) reverts or is permitted based on your design.

contracts/src/RatesManager.sol (2)

6-35: Access control and default admin rules are set up correctly.
Granting both the default admin role and a custom RATES_ADMIN_ROLE ensures proper flexibility. The adminTransferDelay set to 1 days appears consistent with typical upgrade or permission transfer safety measures.


37-56: Chronological order enforced.
The require statement ensures strictly increasing startTime. Be aware that you currently allow any future or even past startTime not relative to block.timestamp. If needed, consider adding a check that startTime >= block.timestamp if that aligns with the contract’s intended usage.

@neekolas neekolas force-pushed the 02-26-add_initial_rates_contract branch from 275058d to 1775be1 Compare February 26, 2025 19:43
Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
contracts/src/RatesManager.sol (2)

21-22: Consider logging the caller in the event
Emitting RatesAdded is helpful, but you might also consider logging msg.sender to aid monitoring or auditing who added the new rates.


58-85: Fixed page size
Your pagination is implemented cleanly with a constant page size of 50. For flexibility, you could parameterize the page size or reference a constant variable to avoid hardcoding.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 275058d and 1775be1.

📒 Files selected for processing (4)
  • contracts/dev/generate (1 hunks)
  • contracts/src/RatesManager.sol (1 hunks)
  • contracts/test/IdentityUpdates.t.sol (1 hunks)
  • contracts/test/RatesManager.t.sol (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • contracts/test/IdentityUpdates.t.sol
  • contracts/test/RatesManager.t.sol
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build pre-baked anvil-xmtpd
🔇 Additional comments (8)
contracts/dev/generate (1)

54-54: Include new contract in generation list
It’s great to see the “RatesManager” contract added to the default array. This ensures that all default runs of the script will generate the corresponding ABIs and Go bindings for it.

contracts/src/RatesManager.sol (7)

1-5: Pin compiler version deliberately
Using a pinned compiler version (pragma solidity 0.8.28) is good for reproducibility. Double-check that 0.8.28 is the version you intend to support, as other team members might be familiar with a caret version range (^0.8.0).


6-8: Role definition is consistent
Defining RATES_ADMIN_ROLE for rate administration is a clear approach and follows recommended patterns for role-based access.


10-16: Confirm that uint64 is sufficient
uint64 for these fee fields (and startTime) might be perfectly fine. Just ensure that the range (up to 2^64-1) won’t be exceeded in production scenarios.


18-19: Private array storage
Storing allRates as a private array is appropriate. You’ve exposed public accessors for reading it, maintaining encapsulation.


24-35: Validate admin transfer delay
The constructor sets a 1-day adminTransferDelay, which might be a typical choice. Confirm that this delay aligns with your project’s governance processes and security requirements.


37-56: Chronological constraint on startTime
Enforcing startTime > lastStartTime ensures strict ordering. If you ever need overlapping or identical start times, consider adjusting the comparison. Otherwise, this logic is straightforward and correct for an ever-growing timeline of rates.


87-92: Simple and effective count retrieval
getRatesCount() is a straightforward way to expose the length of allRates. This appears correct with no concerns.

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.

2 participants