Skip to content

fix: improve withdrawal queue fairness#592

Open
Mosas2000 wants to merge 1 commit into
astera-hq:mainfrom
Mosas2000:fix/withdrawal-queue-max-wait
Open

fix: improve withdrawal queue fairness#592
Mosas2000 wants to merge 1 commit into
astera-hq:mainfrom
Mosas2000:fix/withdrawal-queue-max-wait

Conversation

@Mosas2000

Copy link
Copy Markdown
Contributor

Summary

Fixes withdrawal queue starvation under sustained high pool utilization by adding fair partial fulfillment, cancellable queued requests, and investor-facing wait estimates.

What Changed

  • Added a dedicated withdrawal queue counter so request IDs no longer overwrite queue storage.
  • Added cancellable queued withdrawals by token through cancel_withdrawal_request.
  • Added estimate_withdrawal_wait to expose:
    • queue position
    • capital ahead
    • nearest active invoice due date
  • Added max_withdrawal_queue_age_days to pool config with an admin setter.
  • Updated withdrawal queue processing to distribute available liquidity pro-rata instead of strict FIFO.
  • Preserved aged withdrawal requests as the priority group when processing repayments.
  • Updated the portfolio page to show queued withdrawal position, capital ahead, and nearest invoice due date.
  • Added tests for queue persistence, cancellation, wait estimates, and pro-rata partial fulfillment.

Why

The previous queue could leave late investors waiting indefinitely when utilization stayed near 100% and repayments were continuously redeployed. This change gives queued investors better visibility and ensures repayment liquidity is shared fairly instead of only serving the front of the queue.

Testing

  • git diff --check passed.
  • cargo test -p pool was not run because cargo is unavailable in the local environment.
  • npm run typecheck was not run because tsc is unavailable in the local environment.

Fixes

Closes #574

@sanmipaul

Copy link
Copy Markdown
Contributor

LGTM. Thanks for tackling this, the counter key fix, the checked-arithmetic helpers, and the aged-request priority concept are all the right calls. Please, fix CI/CD errors.

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.

fix: withdrawal queue has no max-wait guarantee — late depositors starve under sustained high pool utilization

2 participants