Skip to content
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

[BOOST-4672] implement flexible fee structures for QuestBudget #291

Merged

Conversation

mmackz
Copy link
Contributor

@mmackz mmackz commented Sep 12, 2024

Management Fee Implementation for QuestBudget

Overview

This PR implements the management fee feature for the QuestBudget contract, allowing boost creators to earn a fee for managing boosts.

Key Changes

  1. Management Fee Setting:

    • Added setManagementFee function to allow the contract owner to set the management fee percentage.
    • Implemented managementFee state variable to store the fee percentage.
  2. Boost Creation with Management Fee:

    • Modified createERC20Quest to calculate and reserve the management fee during quest creation.
    • Added reservedFunds state variable to track funds reserved for management fees.
    • Updated available function to account for reserved funds.
  3. Management Fee Payment:

    • Implemented payManagementFee function to allow boost creators to claim their management fee after completion.
    • Added checks to ensure only the boost creator can claim the fee and only after the remaining rewards have been withdrawn.
  4. Manager Tracking:

    • Added questManagers mapping to associate quest IDs with their creators' addresses.
  5. Events:

    • Added ManagementFeeSet event for logging changes to the management fee percentage.
    • Added ManagementFeePaid event for logging management fee payments.
  6. Testing:

    • Implemented comprehensive test suite for new management fee functionality.
    • Added helper functions and structs to streamline quest creation using common parameters.

Implementation Details

  • The management fee is set in basis points (e.g., 500 = 5%).
  • The maximum management fee that can be set is 10000 (100%)
  • The fee is calculated based on the actual number of participants rather than the total possible participants.
  • Reserved funds are tracked separately to ensure accurate reporting of available funds.
  • Safeguards are in place to prevent unauthorized fee claims and to handle edge cases like insufficient funds.

Security Considerations

  • The setManagementFee function is restricted to the contract owner.
  • The payManagementFee function includes checks to prevent unauthorized claims.
  • The contract uses OpenZeppelin's SafeERC20 for secure token transfers.

Testing

  • Setting and updating the management fee
  • Creating quests with management fees
  • Paying out management fees under various scenarios
  • Edge cases such as insufficient funds and unauthorized access attempts

@mmackz mmackz requested a review from a team as a code owner September 12, 2024 06:41
function testCreateERC20Quest() public {
// Define the parameters for the new quest
uint32 txHashChainId_ = 1;
Copy link
Contributor Author

@mmackz mmackz Sep 12, 2024

Choose a reason for hiding this comment

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

Common parameters for quest creation are moved to helper functions at the bottom of this file setupQuestData and createQuestWithMockData . This is to avoid having to repeat the same quest setup on multiple tests.

Copy link

@topocount topocount left a comment

Choose a reason for hiding this comment

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

I don't have ownership permissions on this repo but this looks good to me

}

function testPayManagementFee_NotAuthorized() public {
vm.prank(address(0xc0ffee));

Choose a reason for hiding this comment

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

nit: you can use hoax instead of vm.prank

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info, I did not know about hoax.

Copy link
Member

@Quazia Quazia left a comment

Choose a reason for hiding this comment

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

Thank you

@mmackz mmackz merged commit bab77d5 into main Sep 16, 2024
2 checks passed
@mmackz mmackz deleted the matthew/boost-4672-implement-flexible-fee-structures-for-questbudget branch September 16, 2024 16:33
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.

3 participants