Skip to content

Add a background job to auto-refund expired FUNDED bounties on-chain, not just flip a status flag locally #26

Closed

Description

@chonilius

Background

BountiesService.expireOverdue finds overdue bounties still in
OPEN/FUNDED/CLAIMED and flips their status to EXPIRED. Per the state
machine, EXPIRED -> REFUNDED is a valid subsequent transition, but
nothing in expireOverdue actually calls EscrowService.refund — it only
updates the Bounty.status column. There's also no visible scheduled job
(no @nestjs/schedule cron, confirm it's not a dependency) that even calls
expireOverdue automatically — investigate whether it's wired to run on
any schedule at all, or whether it's dead code only reachable via a manual
admin call.

Problem Statement

If a sponsor funds a bounty (locking real funds in escrow) and it expires
unclaimed/unmerged, the current behavior — even in the best case where
expireOverdue is actually invoked on a schedule — only marks it
EXPIRED in Postgres while the sponsor's funds remain locked in the escrow
contract indefinitely. The sponsor has no automatic recourse; someone must
manually notice the bounty is expired and manually call the refund flow
(assuming a controller endpoint for it even exists and is discoverable —
verify). For a platform whose core promise is "funds move automatically,"
silently stranding sponsor funds in escrow after expiry is a serious product
and trust failure.

Requirements

  • Wire up an actual recurring job (add @nestjs/schedule if not present,
    or document/implement an equivalent — a documented external cron hitting
    an admin endpoint is acceptable if justified) that calls
    expireOverdue on a sensible interval.
  • Extend expireOverdue (or add a follow-up step) to automatically trigger
    EscrowService.refund for each bounty that had funds locked
    (escrowId set) when it expires — respecting the existing state machine
    (EXPIRED -> REFUNDED) and the locking/transaction fixes from the other
    issues in this batch so this doesn't introduce a new race against a
    simultaneous claim/merge.
  • Handle partial failure: if the on-chain refund call fails for one bounty
    in a batch of expiring bounties, the rest must still be processed (don't
    let one failure abort the whole batch), and the failure must be visibly
    logged/retried, not silently dropped.
  • Add tests: an expired, funded bounty is automatically refunded on-chain
    (verified via the mocked SorobanClientService); an expired, never
    funded
    bounty (still OPEN, no escrow) is marked expired without
    attempting a refund; a batch with one failing refund still processes the
    rest.

Acceptance Criteria

  • A real scheduled job invokes expireOverdue-and-refund on an
    interval, not just a manually-reachable method.
  • Every expired bounty with locked funds is automatically refunded
    on-chain, verified by tests against the escrow layer, not just a
    status-column check.
  • One failing refund in a batch does not prevent the rest from
    processing, and failures are logged/retryable.
  • No new race introduced against concurrent claim/merge flows for the
    same bounty (reuse the locking pattern from the bounty-claim-race
    issue).

Technical Notes

Files: src/bounties/bounties.service.ts, src/escrow/escrow.service.ts,
package.json (add @nestjs/schedule if used), src/bounties/bounties.module.ts.

Difficulty Justification

This closes an actual fund-stranding gap in the product's core value
proposition, requires integrating a new scheduling mechanism correctly with
existing transaction/locking patterns, and requires careful partial-failure
handling across a batch operation touching a live smart contract — not a
simple "add a cron decorator" change.

Activity

  1. added
    very hard
    bug
    enhancement
    architecture
    on Jul 15, 2026
  2. added
    GrantFox OSS
    Maybe Rewarded
    Official Campaign | FWC26
    on Jul 15, 2026
  3. added
    Stellar Wave
    on Aug 27, 2026
  4. OkonkwoEmeka commented on Aug 27, 2026

    @OkonkwoEmeka

    @OkonkwoEmeka has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    hi maintainer, please i'd love to work on this issue. i'm a professional developer with relevant experience, and i'm confident i can complete it properly and on time.

    i've reviewed the issue and understand what's needed. i'll follow the project's existing patterns, keep the implementation clean, and make sure the final pr is well-tested.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @OkonkwoEmeka to this issue.

  5. benedict-cmd commented on Aug 27, 2026

    @benedict-cmd

    @benedict-cmd has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hey I am a developer please assign me to this issue and I'll deliver more than expected

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @benedict-cmd to this issue.

  6. oluwadindodosimilenuotunfatasi commented on Aug 27, 2026

    @oluwadindodosimilenuotunfatasi

    @oluwadindodosimilenuotunfatasi has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello! I've taken the time to go through this issue carefully, and I have a clear picture of what's required to resolve it properly. I'm confident in my ability to design and implement a solution that not only meets but fully satisfies the acceptance criteria. I'd be glad to be assigned this task and get started right away.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @oluwadindodosimilenuotunfatasi to this issue.

  7. oluwagbemigaphilip commented on Aug 27, 2026

    @oluwagbemigaphilip

    @oluwagbemigaphilip has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    GM Maintainer, please can you assign me this

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @oluwagbemigaphilip to this issue.

  8. drips-wave commented on Aug 27, 2026

    @drips-wave

    Congratulations, @oluwagbemigaphilip! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

    🧑‍💻 @oluwagbemigaphilip: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  9. drips-wave commented on Aug 27, 2026

    @drips-wave

    This issue has been completed by @oluwagbemigaphilip as part of the Stellar Wave Program's 8th Wave 🥳

    😎 @oluwagbemigaphilip: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

  10. removed
    Stellar Wave
    on Oct 15, 2026
  11. added
    Stellar Wave
    on Oct 15, 2026
  12. removed
    Stellar Wave
    on Oct 15, 2026
  13. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

GrantFox OSSMaybe RewardedOfficial Campaign | FWC26Stellar Wavearchitecturebugenhancementvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions