Skip to content

fix(maintenance-pool): restore balance on failed escrow withdrawal (#459) - #471

Open
Proxima84-code wants to merge 3 commits into
MergeFi:mainfrom
Proxima84-code:fix/restore-balance-on-failed-reward-459
Open

Proxima84-code wants to merge 3 commits into
MergeFi:mainfrom
Proxima84-code:fix/restore-balance-on-failed-reward-459

Conversation

@Proxima84-code

Copy link
Copy Markdown

Resolves #459.

Root Cause

In MaintenancePoolService.assignReward(), the pool balance is atomically decremented in PostgreSQL before executing escrowService.poolWithdraw(). If the on-chain Soroban withdrawal fails (RPC simulation failure, recipient mismatch, or payment record persistence error), the deducted amount was never restored. This resulted in permanent database balance drift against the actual contract balance.

Fix

  • Wrapped escrowService.poolWithdraw() in a try/catch block.
  • Implemented a compensating transaction via this.poolRepo.increment({ id: pool.id }, 'balance', Number(amount)) on error before rethrowing the original exception.
  • Added a regression test ensuring pool balance restoration when poolWithdraw rejects.
  • Verified test suite: 17/17 tests passing.

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

@Proxima84-code is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

@Proxima84-code

Copy link
Copy Markdown
Author

Hi @maintainers,

Since the deadline for issue #459 passed on September 30 without a solution from the original assignee, I have submitted a complete and verified fix here (all 17 unit tests passing, clean TypeScript build).

Could you please approve the CI workflow run and review the PR? Thank you!

This branch has not been deployed

No deployments
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.

assignReward decrements MaintenancePool.balance before poolWithdraw() and never restores it when the withdrawal fails

1 participant