Skip to content

feat: persist routing fee paid on community earnings withdrawals#868

Open
grunch wants to merge 1 commit into
mainfrom
fix/867-persist-withdrawal-fee
Open

feat: persist routing fee paid on community earnings withdrawals#868
grunch wants to merge 1 commit into
mainfrom
fix/867-persist-withdrawal-fee

Conversation

@grunch

@grunch grunch commented Jul 7, 2026

Copy link
Copy Markdown
Member

Closes #867.

Problem

Community earnings withdrawals pay the withdrawal amount plus a Lightning routing fee. That fee is available on the payment result (payment.fee) but is discarded — only written to the log, never persisted. Unlike buyer payouts (whose fee is stored on the order as order.routing_fee), community withdrawals have no associated order, so the routing cost is lost and the operator has no DB record of what these payouts actually cost.

Fix

  • Add a numeric fee field to PendingPayment (models/pending_payment.ts), defaulting to 0.
  • Set pending.fee = payment.fee in the success branch of attemptCommunitiesPendingPayments, so the routing cost lives in the record the bot already writes.

Scoped to the community-withdrawal path (the actual gap); buyer payouts already capture the fee on the order.

Scope note

This records the fee going forward. Withdrawals already paid before this change have no stored fee, so external consumers (e.g. the stats dashboard) still need a node-side fallback for the historical backlog. The two are complementary.

Tests

Adds tests/jobs/community_pending_payments.spec.ts:

  • successful withdrawal → pending.fee is set to the paid routing fee, pending.paid true, community orders_to_redeem reset;
  • non-confirming payment → pending.fee stays 0 and the payment is not marked paid.

Both pass; npx tsc compiles cleanly and Prettier/ESLint report no issues.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X5uNqd26cC88p5HVqErRDU


Generated by Claude Code

Community earnings withdrawals pay the withdrawal amount plus a Lightning
routing fee. That fee (payment.fee) was available but discarded, only ever
written to the log, so the operator had no DB record of what community
withdrawals cost to route. Unlike buyer payouts, these payments have no
associated order to hold the fee.

Add a `fee` field to PendingPayment (default 0) and set it from payment.fee
in the community-withdrawal success branch of
attemptCommunitiesPendingPayments, so the routing cost lives in the record
the bot already writes.

Adds a regression spec covering the successful and non-confirming paths.

Closes #867.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5uNqd26cC88p5HVqErRDU
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@grunch, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 54a7153b-c0c5-4923-89ef-5a4a6d05d645

📥 Commits

Reviewing files that changed from the base of the PR and between e45b8ec and 49e2f63.

📒 Files selected for processing (3)
  • jobs/pending_payments.ts
  • models/pending_payment.ts
  • tests/jobs/community_pending_payments.spec.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/867-persist-withdrawal-fee

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@grunch

grunch commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@grunch
grunch requested a review from Luquitasjeffrey July 7, 2026 18:36
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 49e2f63855

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread jobs/pending_payments.ts
// payouts (whose fee is stored on the order), community withdrawals
// have no order, so without this the cost would only live in the log
// and be invisible to the operator/accounting (see issue #867).
pending.fee = payment.fee;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for completitue i think it will be better if fee is also persisted on buyer payouts, it creates a little inconsistency that fee in PendingPayments is only persisted on community earnings payout.
I know it is persisted in Order but just for completitude i would add it on buyer payouts

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.

Routing fee paid on community earnings withdrawals is not persisted (only logged)

3 participants