-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces a new Solidity contract, Changes
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
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this 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.
Theadmin
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 callingaddRate
, you already verify the array contents. It might be more robust to also checkratesManager.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 theview
specifier to allow for potential state modifications if needed. It still works with Foundry, but you might consider removingview
for consistency with other test functions.contracts/src/RatesManager.sol (1)
58-93
: Pagination approach is clear.
ThepageSize
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
📒 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 freshRatesManager
for each test ensures isolation. This approach is correct.
21-23
: Helper function improves reusability.
UsingaddRate
to wrapratesManager.addRates(...)
is a neat way to streamline repetitive calls.
42-52
: Unauthorized revert check is valid.
The test accurately verifies that an address withoutRATES_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 samestartTime
reverts. For stronger coverage, test if a paststartTime
(e.g., below currentblock.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 customRATES_ADMIN_ROLE
ensures proper flexibility. TheadminTransferDelay
set to1 days
appears consistent with typical upgrade or permission transfer safety measures.
37-56
: Chronological order enforced.
The require statement ensures strictly increasingstartTime
. Be aware that you currently allow any future or even paststartTime
not relative toblock.timestamp
. If needed, consider adding a check thatstartTime >= block.timestamp
if that aligns with the contract’s intended usage.
275058d
to
1775be1
Compare
There was a problem hiding this 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
EmittingRatesAdded
is helpful, but you might also consider loggingmsg.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
📒 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
DefiningRATES_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 (andstartTime
) 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
StoringallRates
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-dayadminTransferDelay
, 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
EnforcingstartTime > 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 ofallRates
. This appears correct with no concerns.
TL;DR
What changed?
How to test?
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