Skip to content

Mltpl asset type#119

Merged
mubarak23 merged 8 commits into
Fundable-Protocol:mainfrom
Akshola00:mltpl-asset-type
Jun 30, 2025
Merged

Mltpl asset type#119
mubarak23 merged 8 commits into
Fundable-Protocol:mainfrom
Akshola00:mltpl-asset-type

Conversation

@Akshola00

@Akshola00 Akshola00 commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

closes #116

  • The create_campaign function now requires a donation_token: ContractAddress parameter, making each campaign support its own ERC-20 token.

Changes in Detail

1. Errors Module

  • Added new error:
    Used to validate the provided token address is not zero.

2. CampaignDonation Contract

  • Updated create_campaign function signature:
fn create_campaign(
  ref self: ContractState,
  campaign_ref: felt252,
  target_amount: u256,
  donation_token: ContractAddress,
) -> u256
  • Updated the internal _create_campaign method to accept and store donation_token:
fn _create_campaign(
  ref self: ContractState,
  campaign_ref: felt252,
  target_amount: u256,
  donation_token: ContractAddress,
) -> u256
  • Added validation to reject zero address tokens:

  • Modified logic in places like donate_to_campaign, withdraw_funds, etc., to use campaign.donation_token instead of a globally stored token:

3. Interface (ICampaignDonation)

  • Updated interface to match the new create_campaign signature with donation_token.

4. Test File (test_campaign_donation.cairo)

  • Updated all calls to create_campaign(...) to include the donation_token as an extra argument.

  • Added a new test to assert that an invalid donation token (zero address) causes a panic.

  • Supports multiple tokens per campaign instead of relying on a single global token.

  • Prevents campaigns with invalid token addresses from being created.

  • Improves test coverage and correctness by updating all existing test cases and adding necessary edge cases.

  • Ensures backward compatibility is broken in a controlled way (tests are updated accordingly).

Summary by CodeRabbit

  • New Features

    • Added support for specifying a unique donation token for each campaign.
    • Campaign creation now requires providing a donation token address.
    • Error handling improved with a new message for invalid donation tokens.
  • Bug Fixes

    • Ensured validation to prevent campaigns from being created with an invalid (zero) donation token address.
  • Tests

    • Updated tests to include the donation token parameter in campaign creation.
    • Added tests to verify behavior when an invalid donation token is provided.

@coderabbitai

coderabbitai Bot commented Jun 27, 2025

Copy link
Copy Markdown

"""

Walkthrough

The changes introduce support for campaign-specific donation tokens, allowing each campaign to define its own donation asset. The create_campaign and related internal functions are updated to accept a donation_token parameter. Validation and error handling for invalid token addresses are added, and all relevant tests are updated or added to reflect these changes.

Changes

File(s) Change Summary
src/base/errors.cairo Added INVALID_DONATION_TOKEN error constant to the Errors module.
src/campaign_donation.cairo Updated campaign creation logic to accept and validate a campaign-specific donation token; replaced global token usage with campaign-specific token in all operations; updated error handling.
src/interfaces/ICampaignDonation.cairo Modified create_campaign method signature to include donation_token parameter.
tests/test_campaign_donation.cairo Updated all campaign creation calls to include donation token; added tests for invalid token.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract
    participant TokenContract

    User->>Contract: create_campaign(campaign_ref, target_amount, donation_token)
    Contract->>Contract: Validate donation_token != 0
    alt Invalid token
        Contract-->>User: Error(INVALID_DONATION_TOKEN)
    else Valid token
        Contract->>Contract: Store campaign with donation_token
        Contract-->>User: campaign_id
    end

    User->>Contract: donate_to_campaign(campaign_id, amount)
    Contract->>Contract: Retrieve campaign's donation_token
    Contract->>TokenContract: Transfer tokens from User to Contract
    TokenContract-->>Contract: Transfer result
    Contract-->>User: Donation result
Loading

Assessment against linked issues

Objective Addressed Explanation
Update create_campaign function to accept donation_token parameter (#116)
Add validation for donation_token (nonzero, error handling) (#116)
Modify campaign creation logic to use provided token, not global default (#116)
Update tests to cover donation token validation and ensure all pass (#116)
Maintain same return behavior and parameter validation for other fields (#116)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • Utilitycoder

Poem

In fields of code where campaigns grow,
Each picks a token—let donations flow!
No longer bound to just one type,
Owners choose what feels just right.
With tests and checks, this patch is done—
🐇 Hopping forward, one by one!

"""


📜 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 42e4ddc and a2b9a65.

📒 Files selected for processing (4)
  • src/base/errors.cairo (1 hunks)
  • src/campaign_donation.cairo (6 hunks)
  • src/interfaces/ICampaignDonation.cairo (2 hunks)
  • tests/test_campaign_donation.cairo (32 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/base/errors.cairo
  • src/interfaces/ICampaignDonation.cairo
  • src/campaign_donation.cairo
  • 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: 0

🧹 Nitpick comments (2)
src/interfaces/ICampaignDonation.cairo (1)

28-33: Update documentation to include the new parameter.

The donation_token parameter should be documented in the function comments for clarity.

 /// Creates a new fundraising campaign
 ///
 /// # Arguments
 /// * `campaign_ref` - A unique 5-character identifier for the campaign
 /// * `target_amount` - The fundraising goal amount in the donation token
+/// * `donation_token` - The ERC-20 token contract address for this campaign
 ///
 /// # Returns
 /// * `u256` - The newly created campaign's ID
 ///
 /// # Panics
 /// * If `campaign_ref` is empty
 /// * If `campaign_ref` already exists
 /// * If `target_amount` is zero
+/// * If `donation_token` is a zero address
tests/test_campaign_donation.cairo (1)

57-57: Remove or implement the placeholder function.

The deploy_donation_token() function is currently empty. Consider removing it if not needed or adding a TODO comment if it's intended for future implementation.

-fn deploy_donation_token() {}
+// TODO: Implement deploy_donation_token() function for future use
+fn deploy_donation_token() {}
📜 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 6cdcdd9.

📒 Files selected for processing (4)
  • src/base/errors.cairo (1 hunks)
  • src/campaign_donation.cairo (6 hunks)
  • src/interfaces/ICampaignDonation.cairo (1 hunks)
  • tests/test_campaign_donation.cairo (37 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests
🔇 Additional comments (9)
src/base/errors.cairo (1)

137-138: LGTM! Error constant is well-defined.

The new INVALID_DONATION_TOKEN error constant follows the established pattern and provides a clear error message for validation of campaign-specific donation tokens.

tests/test_campaign_donation.cairo (2)

99-110: LGTM! Excellent test coverage for validation.

The new test properly validates that creating a campaign with a zero donation token address triggers the expected error. This ensures the validation logic works correctly.


62-70: LGTM! Test updates are comprehensive.

All test functions have been properly updated to include the new donation_token parameter, maintaining test coverage while adapting to the new interface.

src/campaign_donation.cairo (6)

156-167: LGTM! Function signature correctly updated.

The create_campaign function now properly accepts the donation_token parameter and passes it to the internal implementation function.


440-471: LGTM! Validation and storage implementation is correct.

The _create_campaign function properly validates the donation token address and stores it in the campaign struct. The validation ensures the token address is non-zero, preventing invalid campaigns.


479-479: LGTM! Correct use of campaign-specific token.

The donation logic now correctly uses the campaign-specific donation_token instead of the global token, enabling multi-token support.


542-542: LGTM! Withdrawal uses campaign-specific token.

The withdrawal function correctly uses the campaign-specific donation_token for transfers.


24-26: LGTM! Error import updated correctly.

The error imports have been properly updated to include the new INVALID_DONATION_TOKEN constant used for validation.


417-418: To confirm that each campaign stores its own token and that campaign.donation_token is available, let’s locate the Campaigns struct and the get_campaign helper:

#!/bin/bash
# Find the Campaigns struct definition
rg -n "struct Campaigns" --glob "*.cairo" -A 10 -B 5

# Find the get_campaign implementation
rg -n "fn get_campaign" --glob "*.cairo" -A 5 -B 2

@Akshola00

Copy link
Copy Markdown
Contributor Author

@mubarak23 ptal

@mubarak23
mubarak23 self-requested a review June 29, 2025 07:10
Comment thread src/campaign_donation.cairo Outdated
@Akshola00
Akshola00 requested a review from mubarak23 June 30, 2025 07:38
@Akshola00

Copy link
Copy Markdown
Contributor Author

@mubarak23 gm sir, fixed the check and wrote a unit test for it.

failing tests are from the code last code merged into the code base

https://github.com/Fundable-Protocol/fundable/actions/runs/15964704698/job/45022914786

those are the ones also failing in my pr

@mubarak23
mubarak23 merged commit 2b04b8f into Fundable-Protocol: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.

Allow Campaign Owners to Define Donation Asset Type

2 participants