Skip to content

[MEDIUM] — recalculateCampaignStats never decrements raisedAmount after a refund, permanently inflating the campaign total #8

Description

@ibrahimmosouf-png

Severity: Medium
Type: Bug
Scope: Campaigns, Donations
Labels: bug, help wanted, Official Campaign

Description

CampaignsService.recalculateCampaignStats (src/campaigns/campaigns.service.ts, lines ~270–286) sets raisedAmount = sum(donations where status = 'CONFIRMED'). It is invoked from createDonation after each successful confirmation.

The Donation.status enum supports REFUNDED (prisma/schema.prisma); when a refund flow lands, the underlying row flips from CONFIRMED to REFUNDED and is excluded from the aggregation. However, no caller ever re-runs recalculateCampaignStats on refund, so Campaign.raisedAmount continues to include the refunded value. Sequential refunds will monotonically grow the discrepancy between on-chain balance and recorded total.

Recommendation

  • After any state transition that flips a donation out of CONFIRMED (REFUNDED, FAILED), re-call recalculateCampaignStats from the same code path.
  • Add a Prisma $transaction that updates the status and the campaign aggregate atomically.
  • Add a regression test that issues a refund and asserts Campaign.raisedAmount decreases by exactly the refunded amount.

Activity

  1. added
    bugSomething isn't working
    help wantedExtra attention is needed
    Official CampaignAudit finding under the Official Campaign
    and removed
    Official CampaignAudit finding under the Official Campaign
    on Jun 18, 2026
  2. added
    GrantFox OSSIssue tracked in GrantFox OSS
    Maybe RewardedIssue may be eligible for a GrantFox reward
    Official CampaignAudit finding under the Official Campaign
    on Jun 18, 2026
  3. iyanumajekodunmi756 commented on Jun 20, 2026

    @iyanumajekodunmi756
    Contributor

    Hi maintainer, I would love to work on this issue. I have studied the details of the issue description and I understood the requirements. I shall deliver with qualitative feedback and promptly.

  4. grantfox-oss commented on Jun 20, 2026

    @grantfox-oss

    🦊 GrantFox — @iyanumajekodunmi756 has been assigned to this issue as part of the Official Campaign campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #8)
    2. Your PR will be reviewed by the OrbitChainLabs maintainers

    Good luck! Track your progress on GrantFox.

  5. grantfox-oss commented on Jun 23, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox as part of the Official Campaign campaign!

    @iyanumajekodunmi756's PR #37 was approved and merged by @Alqku.

    🏆 @iyanumajekodunmi756: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (681 total points). Track your full progress on GrantFox.

    👏 Great work, @iyanumajekodunmi756! Keep contributing to OrbitChainLabs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignAudit finding under the Official CampaignbugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions