Skip to content

Feat/replace token strategy by pledge manager#11

Closed
0xrafasec wants to merge 19 commits intominipayfrom
feat/replace-token-strategy-by-pledge-manager
Closed

Feat/replace token strategy by pledge manager#11
0xrafasec wants to merge 19 commits intominipayfrom
feat/replace-token-strategy-by-pledge-manager

Conversation

@0xrafasec
Copy link
Collaborator

@0xrafasec 0xrafasec commented Apr 8, 2025

Disclaimer

WIP BRANCH

This PR refactors the treasury contracts to improve code maintainability, reduce duplication, and align the logic with the PledgeManager abstraction. The changes include:

Centralized Fee Disbursement Logic

The disbursement fees logic, previously duplicated across BaseTreasury, AllOrNothing, and MinimumOrder, has been centralized into the BaseTreasury contract.
A new internal function _disburseFeesInternal in BaseTreasury handles the common logic for fee disbursement. Derived contracts now call this function, reducing redundancy.

Transition to PledgeManager
Removed legacy crypto-token-based tracking and replaced it with PledgeManager's totalPledged for managing pledges.
Simplified pledge-related operations (e.g., refunds, confirmations) by leveraging PledgeManager's centralized logic.

Removed Redundant State Variables:
Eliminated unnecessary variables like s_cryptoFeeDisbursed and redundant pledge tracking in derived contracts, as PledgeManager already provides this functionality.

Improved Maintainability
Consolidated shared logic into reusable functions in BaseTreasury.
Simplified derived contracts (AllOrNothing and MinimumOrder) by delegating everyday operations to BaseTreasury and PledgeManager.

Installment-Ready Foundation
The refactoring lays the groundwork for future installment-based functionality by centralizing pledge and fee management, making it easier to extend the system.

Impact

  • Move away from token dependency, adding a contract to manager pledges
  • Reduces code duplication and improves readability.
  • Ensures consistent behavior across treasury contracts.
  • Simplifies future enhancements, such as adding installment-based pledges or partial fee disbursements.

Testing

  • Verified that pledge-related operations (e.g., refunds, confirmations) work seamlessly with the new centralized logic.
  • Commented on some tests until we have a clear understanding of the changes.

0xrafasec added 19 commits April 2, 2025 18:55
…oken ID dependencies and updating refund logic to utilize backer address
…ons to use totalPledged and enhancing pause/unpause functionality
…e pledge and refund logic, and enhance fee disbursement calculations
…pledged, update refund logic, and implement fee disbursement calculations
…ace pledged amount with fee disbursement status, and update withdrawal process to reset total pledged after withdrawal
…able, ensure fees are disbursed before withdrawal, and prevent over-disbursement during fee calculations
…acing manual calculations with a dedicated internal function
…fee disbursement logic, enhancing code reusability and clarity.
@0xrafasec 0xrafasec closed this Apr 30, 2025
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant