Skip to content

Conversation

@rayedsikder
Copy link
Member

Contract Structure and Deployment Enhancements

This PR builds upon the foundation established by our recent architecture redesign, focusing on deployment workflow improvements, contract validation logic, and better code organization.

Key Improvements

Enhanced Deployment Infrastructure

  • Modularized Deployment Scripts: Restructured scripts for more flexible and maintainable deployments
  • Implementation-Specific Deployment: Added dedicated script for implementation contracts
  • Platform Setup Automation: New script to automate platform configuration during deployment
  • Configurable Fee Parameters: Updated environment structure to support fine-grained fee configuration

Strengthened Contract Validation

  • Logic Optimization: Replaced complex && validations with clearer || patterns for better readability and gas efficiency
  • Redundancy Elimination: Removed unnecessary validation checks that duplicated existing functionality
  • State Protection: Added guards to prevent unauthorized or erroneous state modifications
    • Now prevents setting platform info more than once
    • Prevents re-approval of already approved platforms

Refactored Data Structures

  • Naming Improvements:
    • Renamed s_selectedPlatformHash to isSelectedPlatform
    • Renamed s_approvedplatformHash to s_approvedPlatformHashes
  • Added Critical Tracking:
    • New mapping s_isApprovedPlatform for more explicit approval status tracking
  • Improved State Management:
    • Now automatically resets fees when platform is deselected
    • Fixed logic in updateGoalAmount() to properly validate changes

Project Organization

  • Reorganized Test Structure: Moved TestUSD to dedicated mocks directory
  • Updated License Information: Standardized license references across files
  • Documentation Improvements: Enhanced code docs and updated README

Safety Enhancements

  • Proper Token Minting: Now calls _safeMint after state changes in _pledge to follow check-effects-interactions pattern
  • Removed Redundant Event: Eliminated redundant CampaignInfoPlatformSelected event

- Rename `s_selectedPlatformHash` to `isSelectedPlatform
- Add mapping s_isApprovedPlatform
- Rename `s_approvedplatformHash` to `s_approvedPlatformHashes`
- Remove event `CampaignInfoPlatformSelected`
- Add error `CampaignInfoPlatformAlreadyApproved`
- Add view function `checkIfPlatformApproved`
- Improve validations, and replace && logic with ||
- Fix updateGoalAmount() logic
- Add restriction to not allow already approved platform to be updated
- Reset fees to 0 when platform is no longer a selected platform in `updateSelectedPlatform`
- Add check in `_setPlatformInfo` to not allow setting platform info more than once
- Update mapping for `s_isApprovedPlatform` in `_setPlatformInfo`
- Remove redundant validation `platformIsListed`and `ZERO_BYTES` check in `getPlatformDataOwner`
- Remove redundant validation `platformAdminAddress` in `enlistPlatform`
- Optimize logic and remove redundant validation of `s_platformDataOwner` comparison
- Optimize validation in `removePlatformData`
@rayedsikder rayedsikder requested a review from mahabubAlahi May 15, 2025 00:51
@rayedsikder rayedsikder self-assigned this May 15, 2025
@rayedsikder rayedsikder added the enhancement New feature or request label May 15, 2025
Copy link
Collaborator

@mahabubAlahi mahabubAlahi left a comment

Choose a reason for hiding this comment

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

Looks Good To Me.

…eIsNotGreater` instead of >,< to improve checks
- Add `removeReward`
- Add `pauseTreasury`
- Add `unpauseTreasury`
- Add `cancelTreasury`
- Receive `warpTime` in params to better simulate the timing constraints
- `getplatformHash` to `getPlatformHash`
- `getplatformFeePercent` to `getPlatformFeePercent`
- `test_removeReward`
- `test_getReward`
- `test_getRaisedAmount`
- `test_pauseTreasury`
- `test_unpauseTreasury`
- `test_cancelTreasury`
- `test_cancelTreasuryByCampaignOwner`
- `test_name`
- `test_symbol`
- `test_getPlatformHash`
- `test_getPlatformFeePercent`
@rayedsikder rayedsikder merged commit 8169e5a into main Oct 20, 2025
1 check passed
rayedsikder pushed a commit that referenced this pull request Dec 9, 2025
* Fix incorrect description of the `claimFund` function (#6)

  (immunefi)(issue#06)
  - Updated the NatSpec comment for claimFund()

* Refactor `platformDataKey` parameter validation optimization (#7)

  (immunefi)(issue#09)
  - Move `platformDataKey` parameter validation to an earlier stage of the `createCampaign` flow

* Add configuring platform data during `updateSelectedPlatform` (#8)

  (immunefi)(issue#10)

* Add creator's non-zero validation during `createCampaign` (#9)

  (immunefi)(issue#16)

* Add zero validation for `platformDataValue` in `createCampaign` (#10)

  (immunefi)(issue#12)

* Add reward value zero validation in pledge (#11)

  (immunefi)(issue#14)

* Fix `updateDeadline` allowing past deadline that blocks `claimRefund` (#12)

  (immunefi)(issue#05)
  - Added check to ensure new deadline is after current block timestamp

* Fix blocking KeepWhatsRaised pledge functions via front-running (#13)

  (immunefi)(issue#04)
  - Add internal pledge ID generation using msg.sender and pledgeId

* Add fee configuration via configure treasury (#14)

  (immunefi)(issue#11)
  - Update configure treasury to support fee values
  - Add getter function for fee value

* Add campaign data validation in configure treasury (#15)

  (immunefi)(issue#20)
  - Update fee values js doc
  - Update custom error

* Fix Gateway fee bypass (#16)

  (immunefi)(issue#19)
  - When `setFeeAndPledge` is called, tokens are transferred from the admin's wallet (msg.sender)
  - When `pledgeWithoutAReward` or `pledgeForAReward` is called directly, tokens are transferred from the backer's wallet

* Add expected fee description in create campaign jsdoc (#17)

  (immunefi)(issue#03)

* Refactor withdrawal and pledge calculation (#19)

  (immunefi)(issue#15)
  (immunefi)(issue#18)

  - Restrict access to the withdrawal function so that only the campaign owner and platform administrator can use it.
  - Move the protocol fee calculation from the withdrawal process to the pledge stage.
  - For withdrawals:
    - Partial Withdrawals:
       - Conditions: amount > 0 and amount + fees ≤ available balance.
       - The creator must specify the exact withdrawal amount, and the system will ensure there are sufficient funds to cover both the withdrawal and the fees.

    - Final Withdrawals:
      - Conditions: available balance > 0 and fees ≤ available balance.
      - The creator can withdraw the entire remaining balance. The system will check if there are enough funds to cover the fees and will then provide the remainder to the creator.

---------

Co-authored-by: mahabubAlahi <mahabub@ccprotocol.xyz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants