-
Notifications
You must be signed in to change notification settings - Fork 39
feat: Payer interface #558
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
Conversation
WalkthroughThis pull request introduces a new Solidity interface, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant IPayer
User->>IPayer: register(amount)
User->>IPayer: deposit(amount)
User->>IPayer: requestWithdrawal(amount)
Note over IPayer: Validate request, emit WithdrawalRequest event
User->>IPayer: cancelWithdrawal() or finalizeWithdrawal()
Note over IPayer: Emit WithdrawalCancelled or WithdrawalFinalized event
sequenceDiagram
participant NodeOperator
participant IPayer
NodeOperator->>IPayer: settleUsage(fees, payer, nodeId, timestamp)
Note over IPayer: Validate usage data and emit UsageSettled event
NodeOperator->>IPayer: settleUsageBatch(payers, fees, timestamp, nodeId)
Note over IPayer: Process batch settlement and emit BatchUsageSettled event
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 (
|
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: 2
🧹 Nitpick comments (3)
contracts/src/interfaces/IPayer.sol (3)
197-205: Consider clarifying deposit edge cases.The
deposit(uint256 amount)function docs do not indicate whether depositing below the minimum required amount is disallowed. Adding clarifications about such scenarios can prevent user confusion.
327-373: Validate usage settlement ordering and potential conflicts.Since partial or backdated settlement is allowed, ensure that out-of-order usage reports do not generate negative or stale fee calculations. Documenting how conflicting timestamps or repeated reports are handled could prevent misuse.
573-584: Enforce robust access control for pause/unpause operations.The interface allows pausing/unpausing the contract, but the exact role-based restrictions are unspecified. Adopting or referencing a well-reviewed approach (e.g., OpenZeppelin's Pausable) can strengthen security and clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
contracts/src/interfaces/IPayer.sol(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Solidity
contracts/src/interfaces/IPayer.sol
[warning] 2-2: Version constraint ^0.8.0 contains known severe issues. Refer to the documentation for details.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build pre-baked anvil-xmtpd
- GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
🔇 Additional comments (2)
contracts/src/interfaces/IPayer.sol (2)
4-7: Documentation is well-structured.Your use of NatSpec comments for the interface is commendable and provides clear guidance for integrators.
188-196: Clarify repeated registrations.The
register(uint256 amount)function does not specify what happens if the caller is already registered. Consider documenting or enforcing a one-time registration rule, e.g., by adding an error condition or clarifying in comments.
contracts/src/interfaces/IPayer.sol
Outdated
| } | ||
|
|
||
| /** | ||
| * @dev Struct to store batch commitment information. |
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.
Can you add a little more context around how batch commitments work
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.
So this is an idea aiming to make the protocol auditable from end to end. Completely optional, as we rely on trusted NOPs and the PayerReport attestation process.
We'd submit a PayerReport to the Treasury contract. After being accepted, Treasury calls payer.settleUsageBatch([]payers, []fees) which in turn creates a BatchCommitment storing hash(payers, fees, timestamp), subtract all the funds, etc.
The hash could be used to verify the settlement was processed correctly and noone tampered with the amounts/payers.
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.
I see. So it's basically a "receipt" that the settlement was done.
contracts/src/interfaces/IPayer.sol
Outdated
| * @return debtors Array of payer addresses with debt. | ||
| * @return debtAmounts Corresponding debt amounts for each payer. | ||
| */ | ||
| function getPayersInDebt(uint256 limit) external view returns ( |
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.
Do we also want an offset to go with the limit?
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.
Good catch, we could paginate the response with an offset. Adding it.
contracts/src/interfaces/IPayer.sol
Outdated
| * @param messageCount Number of messages processed during this period. | ||
| * @param dataSize Total size of data processed in bytes. | ||
| * @param timestamp The timestamp when the usage occurred (can be backdated). | ||
| * @param commitmentHash Optional hash for additional off-chain data verification. |
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.
What would the commitmentHash typically be set to?
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.
This is a typo, thanks for catching it. The commitmentHash should be calculated by the settleUsage itself and not passed as param (security risk).
As mentioned before, the hash can be hash(payer, fee, nodeId, timestamp/block), any combination that gives us unique hashes and be used for verification. It's optional given our current design and we can live without it.
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.
It does seem like we want to somehow guarantee uniqueness of the report, so I'm in favour. But yes, let's have the smart contract handle the hashing.
| * | ||
| * Emits `DonationMade`. | ||
| */ | ||
| function donate(address payer, uint256 amount) external; |
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.
I like that idea
f6f2f17 to
ed4824a
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
♻️ Duplicate comments (1)
contracts/src/interfaces/IPayer.sol (1)
8-8: 🛠️ Refactor suggestionReplace EIP-1283 references with EIP-2200 for accuracy.
Prior comments and learnings indicate EIP-1283 was superseded by EIP-2200, which introduced changes to gas accounting, reentrancy checks, and refunds. Consider updating these references in the docstrings and function descriptions to reflect EIP-2200 instead.
Also applies to: 323-323, 342-342, 409-409, 435-435
🧹 Nitpick comments (1)
contracts/src/interfaces/IPayer.sol (1)
511-521: Consider returning the total count of debtors for better pagination.Your pagination strategy (offset, limit) is good, but it might be more ergonomic to return a
totalCountalongside the current paginated list. This helps callers implement UI pagination without requiring a second call to derive the total number of debtors.function getPayersInDebt(uint256 offset, uint256 limit) external view returns ( address[] memory debtors, uint256[] memory debtAmounts + // , uint256 totalCount <-- Possibly add this );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
contracts/src/interfaces/IPayer.sol(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
contracts/src/interfaces/IPayer.sol (1)
Learnt from: neekolas
PR: xmtp/xmtpd#558
File: contracts/src/interfaces/IPayer.sol:2-2
Timestamp: 2025-02-26T20:01:33.924Z
Learning: All Solidity files in the xmtp/xmtpd repository should use `pragma solidity 0.8.28;` (exact version) for consistency.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build pre-baked anvil-xmtpd
🔇 Additional comments (2)
contracts/src/interfaces/IPayer.sol (2)
2-2: Great job aligning with the repository's versioning guidelines!Using
pragma solidity 0.8.28;matches the project's standard for Solidity versioning.
1-601: Overall interface design is well-structured and comprehensive.Aside from the references to EIP-1283, there are no major issues. This interface covers account lifecycle, usage settlement, withdrawals, and includes robust event logging. Excellent work!
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: 1
🧹 Nitpick comments (1)
contracts/src/interfaces/IPayer.sol (1)
9-437: Consider splitting this interface into smaller interfaces for better maintainability.The
IPayerinterface defines a large set of functionalities (registration, deposits, withdrawals, settlements, administrative tasks, etc.). Splitting it into dedicated interfaces can simplify implementations, reduce complexity, and align closely with the SOLID principles.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
contracts/src/interfaces/IPayer.sol(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
contracts/src/interfaces/IPayer.sol (1)
Learnt from: neekolas
PR: xmtp/xmtpd#558
File: contracts/src/interfaces/IPayer.sol:2-2
Timestamp: 2025-02-26T20:01:33.924Z
Learning: All Solidity files in the xmtp/xmtpd repository should use `pragma solidity 0.8.28;` (exact version) for consistency.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build pre-baked anvil-xmtpd
🔇 Additional comments (1)
contracts/src/interfaces/IPayer.sol (1)
2-2: Locking compiler to 0.8.28 is consistent with the codebase.Thank you for aligning with the established Solidity version in this repository.
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 (3)
contracts/src/interfaces/IPayer.sol (3)
266-292: Good reference to EIP-2200 optimizations.Ensure there are no lingering references to EIP-1283 in any related documentation or code comments, to keep everything consistent with the chosen EIP-2200 gas model.
356-369: Consider exposing offset-limit pagination in other relevant listing functions.Your offset-limit approach for retrieving payers in debt is great for large data sets. If you foresee the need to paginate other enumerations (e.g., a list of all payers), providing similar offset-limit methods can improve scalability.
9-429: Consider splitting this interface to adhere to single responsibility principles.The interface covers registration, deposits, withdrawals, usage settlement, observability, and admin tasks. If it grows further, separating it into smaller interfaces (e.g., IPayerRegistration, IPayerWithdrawals, IPayerSettlement) can improve maintainability and clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
contracts/src/interfaces/IPayer.sol(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
contracts/src/interfaces/IPayer.sol (1)
Learnt from: neekolas
PR: xmtp/xmtpd#558
File: contracts/src/interfaces/IPayer.sol:2-2
Timestamp: 2025-02-26T20:01:33.924Z
Learning: All Solidity files in the xmtp/xmtpd repository should use `pragma solidity 0.8.28;` (exact version) for consistency.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build pre-baked anvil-xmtpd
🔇 Additional comments (2)
contracts/src/interfaces/IPayer.sol (2)
2-2: Great job pinning the Solidity version to 0.8.28.This matches the project-wide requirement for using an exact version of 0.8.28.
409-422: Verify access restriction for pause/unpause operations.While this is just an interface, confirm in the implementation that these functions can only be called by authorized roles (e.g., owner/admin). Otherwise, a malicious actor could disrupt or restart the contract arbitrarily.
What's in this interface
Core funcionality:
Security:
Observability functions.
Summary by CodeRabbit