Skip to content

feat:handle protocol fee interface functions#118

Merged
mubarak23 merged 6 commits into
mainfrom
ft_protocol_fees
Jun 30, 2025
Merged

feat:handle protocol fee interface functions#118
mubarak23 merged 6 commits into
mainfrom
ft_protocol_fees

Conversation

@mubarak23

@mubarak23 mubarak23 commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

closes #117
This pull request introduces interface functions for managing protocol fee parameters within the contract. It provides mechanisms to retrieve and update the protocol fee percentage and the associated fee collection address.

Changes Introduced
✅ get_protocol_fee_percent: Returns the current protocol fee rate (e.g., 100 = 1%)

✅ set_protocol_fee_percent: Allows updating the protocol fee percentage

✅ get_protocol_fee_address: Returns the current address used for collecting protocol fees

✅ set_protocol_fee_address: Allows updating the fee collection address

Why It Matters
These functions are essential for enabling dynamic configuration of protocol fees and supporting future integrations with fee management systems.

Summary by CodeRabbit

  • New Features
    • Introduced a protocol fee mechanism for campaign withdrawals, allowing a configurable fee percentage and recipient address.
    • Added functions to view and update the protocol fee percentage and recipient address, with updates restricted to the contract owner.
    • Implemented error handling for unset protocol fee addresses and invalid fee percentages exceeding 100%.
  • Tests
    • Added tests to verify protocol fee calculation and configuration settings.

@coderabbitai

coderabbitai Bot commented Jun 27, 2025

Copy link
Copy Markdown

Walkthrough

This change introduces protocol fee management to the CampaignDonation contract. It adds storage for fee percentage and recipient address, along with getter and setter functions (restricted to the owner). The withdrawal logic now calculates and transfers protocol fees. The interface is updated to expose these fee management functions. Tests are updated to include protocol fee parameters and a new test for fee calculation is added.

Changes

File(s) Change Summary
src/campaign_donation.cairo Added protocol fee storage, getter/setter functions, fee calculation logic, and withdrawal updates.
src/interfaces/ICampaignDonation.cairo Extended interface with protocol fee management functions.
tests/test_campaign_donation.cairo Updated setup to include protocol fee addresses, added test for protocol fee calculation.
src/base/errors.cairo Added new error constant for protocol fee percentage exceeding 100%.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Owner
    participant CampaignDonationContract
    participant ProtocolFeeRecipient

    Owner->>CampaignDonationContract: set_protocol_fee_percent(new_fee)
    Owner->>CampaignDonationContract: set_protocol_fee_address(new_address)

    User->>CampaignDonationContract: withdraw_from_campaign(campaign_id)
    CampaignDonationContract->>CampaignDonationContract: calculate_protocol_fee(amount)
    alt Protocol fee > 0
        CampaignDonationContract->>ProtocolFeeRecipient: transfer(fee_amount)
    end
    CampaignDonationContract->>User: transfer(full_amount)
Loading

Assessment against linked issues

Objective Addressed Explanation
Add protocol fee storage variables (protocol_fee_percent, protocol_fee_address) (#117)
Add getter and setter functions for fee percent and address to contract and interface (#117)
Implement protocol fee calculation and integrate into withdrawal logic (#117)
Restrict setters to owner only, validate address and fee percent, emit events, and add error handling (#117) No evidence of event emission, fee/address validation beyond zero address, or full error handling in the code change.
Add calculate_protocol_fee to interface and contract (#117)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of a new test function test_protocol_donation_fee_calculation in tests/test_campaign_donation.cairo The test function adds fee parameter setup and balance assertions which are beyond minimal required tests for fee calculation; it is an enhancement rather than a strict requirement from the linked issue.

Possibly related PRs

Poem

In the meadow of code, where carrots bloom bright,
A protocol fee hops in, bringing rules to the light.
With percent and address, the owner sets the pace,
While donations and withdrawals now leave a fee trace.
🥕
So let the rabbits cheer, for structure is near—
Transparent, precise, and hopping with cheer!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e7e05a1 and cc1da23.

📒 Files selected for processing (1)
  • tests/test_campaign_donation.cairo (36 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_campaign_donation.cairo
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34454fa and bc3dbd7.

📒 Files selected for processing (2)
  • src/campaign_donation.cairo (5 hunks)
  • src/interfaces/ICampaignDonation.cairo (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests
🔇 Additional comments (3)
src/campaign_donation.cairo (3)

63-64: LGTM! Storage variables properly documented

The storage variables are well-documented with the correct basis points format (10000 basis points).


437-453: LGTM! Protocol fee management functions implemented correctly

The getter and setter functions are properly implemented with appropriate ownership checks for the setter functions.


582-586: LGTM! Protocol fee calculation is correct

The calculation correctly uses basis points (10000 = 100%).

Comment on lines +227 to +228
/// @return The protocol fee percentage (100 = 1%)
fn get_protocol_fee_percent(self: @TContractState) -> u256;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent fee percentage documentation

The comment states "100 = 1%" but the implementation uses basis points where 100 = 1% would be represented as 100 basis points out of 10000. This should be clarified to avoid confusion.

Update the documentation to match the implementation:

-    /// @return The protocol fee percentage (100 = 1%)
+    /// @return The protocol fee percentage in basis points (100 = 1%, 10000 = 100%)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// @return The protocol fee percentage (100 = 1%)
fn get_protocol_fee_percent(self: @TContractState) -> u256;
/// @return The protocol fee percentage in basis points (100 = 1%, 10000 = 100%)
fn get_protocol_fee_percent(self: @TContractState) -> u256;
🤖 Prompt for AI Agents
In src/interfaces/ICampaignDonation.cairo at lines 227-228, the comment for
get_protocol_fee_percent incorrectly states "100 = 1%" which conflicts with the
basis points implementation. Update the comment to clarify that the fee
percentage is expressed in basis points, where 100 basis points equals 1%, to
align the documentation with the actual implementation.

Comment on lines +231 to +232
/// @param new_fee_percent The new fee percentage to set (100 = 1%)
fn set_protocol_fee_percent(ref self: TContractState, new_fee_percent: u256);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent fee percentage documentation

The parameter documentation should also clarify the basis points format.

Update the documentation:

-    /// @param new_fee_percent The new fee percentage to set (100 = 1%)
+    /// @param new_fee_percent The new fee percentage to set in basis points (100 = 1%, 10000 = 100%)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// @param new_fee_percent The new fee percentage to set (100 = 1%)
fn set_protocol_fee_percent(ref self: TContractState, new_fee_percent: u256);
/// @param new_fee_percent The new fee percentage to set in basis points (100 = 1%, 10000 = 100%)
fn set_protocol_fee_percent(ref self: TContractState, new_fee_percent: u256);
🤖 Prompt for AI Agents
In src/interfaces/ICampaignDonation.cairo at lines 231-232, the documentation
for the parameter new_fee_percent is unclear about the format. Update the
comment to specify that the fee percentage is expressed in basis points, where
100 basis points equal 1%. This clarifies how to interpret the new_fee_percent
value.

Comment thread src/campaign_donation.cairo
Comment thread src/campaign_donation.cairo

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc3dbd7 and 02dac22.

📒 Files selected for processing (2)
  • src/campaign_donation.cairo (6 hunks)
  • tests/test_campaign_donation.cairo (36 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/campaign_donation.cairo
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests
🔇 Additional comments (5)
tests/test_campaign_donation.cairo (5)

23-30: LGTM: Setup function signature updated correctly.

The function signature properly includes the new protocol fee parameters to support the protocol fee management functionality.


40-41: LGTM: Protocol address configuration added.

The setup correctly initializes the protocol address and includes it in the contract deployment calldata.


49-50: LGTM: Return values updated consistently.

The setup function now returns the protocol owner and address as expected by the updated signature.


535-535: ```shell
#!/bin/bash

Search for any occurrences of protocol fee logic in Cairo contracts

rg protocol_fee -n --glob '*.cairo'

Locate withdrawal functions in Cairo files to inspect fee handling

rg "fn withdraw" -n --glob '*.cairo'


---

`181-181`: ```shell
#!/bin/bash
# Search for fee logic and transfer calls in donation/withdrawal functions
rg -n "fn donate_to_campaign" -C10 --glob "*.cairo"
rg -n "fn withdraw_from_campaign" -C10 --glob "*.cairo"
rg -n "protocol_fee" -C5 --glob "*.cairo"
rg -n "transfer(" -C3 --glob "*.cairo"

Comment thread tests/test_campaign_donation.cairo Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 02dac22 and 3e986c1.

📒 Files selected for processing (2)
  • src/base/errors.cairo (1 hunks)
  • src/campaign_donation.cairo (6 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/base/errors.cairo
🔇 Additional comments (4)
src/campaign_donation.cairo (4)

63-66: Storage variables are well-documented and appropriately typed.

The protocol fee storage variables are correctly implemented with proper documentation explaining the basis points system.


153-162: Constructor properly initializes protocol fee address.

The constructor correctly accepts and initializes the protocol fee address parameter.


443-451: Protocol fee percentage functions are correctly implemented.

Both getter and setter functions are properly implemented with appropriate owner authorization and validation to prevent fees exceeding 100%.


591-595: Protocol fee calculation is mathematically correct.

The fee calculation properly uses basis points (dividing by 10000) and correctly applies the percentage to the total amount.

Comment thread src/campaign_donation.cairo
Comment thread src/campaign_donation.cairo
@mubarak23
mubarak23 merged commit fc6d1d2 into main Jun 30, 2025
1 of 3 checks passed
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.

Implement Protocol Fee Collection on Campaign Donation Contract

1 participant