Skip to content

[FEAT] Implement Graceful Member Removal and Pro-Rata Refunds #19

Description

@Queenode

🔴 Priority: Critical
Difficulty: Hard
Estimated Effort: 3-4 days
Relevant Files: contracts/src/lib.rs, contracts/src/test.rs
Labels: enhancement, priority:critical, logic

Requirements

  1. Remove Member Function

    • Implement pub fn remove_member(env: Env, member_to_remove: Address)
    • Only the Admin can call this function.
    • It must remove the member from the DataKey::Members vector.
  2. Refund Logic

    • If the member is removed mid-cycle (i.e., they have HasContributedThisCycle == true but HasReceivedPayout == false), the contract must refund their current cycle contribution.
    • Check if the member has contributed this cycle.
    • If yes, read ContributionAmount and execute a token_client.transfer() sending the amount back to member_to_remove.
    • Clear HasContributedThisCycle(member) and HasReceivedPayout(member) from persistent storage to free up ledger space.
  3. Cycle State Integrity

    • If a member is removed while a cycle is active (i.e., CycleMemberCount exists), the CycleMemberCount must be decremented by 1.
    • This ensures that the next payout() calculation (contribution_amount * cycle_member_count) remains mathematically correct for the reduced pool size.
    • If the removal drops the member count to 0, clear CycleMemberCount.
  4. Constraints

    • A member cannot be removed if they have already received a payout in the current cycle (this would mean they take the money and leave others at a loss).
    • Panic with "Cannot remove member after payout" if HasReceivedPayout == true.
  5. Testing

    • Unit test: Admin successfully removes a member who hasn't contributed yet.
    • Unit test: Admin removes a member who has contributed, verify the refund is processed.
    • Unit test: Admin attempts to remove a member who has received a payout (must panic).
    • Unit test: Verify CycleMemberCount adjusts correctly and subsequent payouts calculate the correct pool size.
    • Target: >90% coverage on removal logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions