Skip to content

fix: split pay-in booking into fund base and platform fee#1655

Draft
jdijkstra-eyra wants to merge 1 commit into
developfrom
fix/pay-in-book-paid-amount
Draft

fix: split pay-in booking into fund base and platform fee#1655
jdijkstra-eyra wants to merge 1 commit into
developfrom
fix/pay-in-book-paid-amount

Conversation

@jdijkstra-eyra

@jdijkstra-eyra jdijkstra-eyra commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Draft — money bookkeeping change (adds a migration + a new ledger account); worth a careful look before merge.

do_complete_transaction re-derived the credited amount as subject_count × live subject_reward, which had two problems:

  • BUG 5 — it read the current subject_reward, so lowering the reward between payment and confirmation credited the wrong amount.
  • BUG 1 — the partner fee the researcher paid was never booked anywhere.

Corrected accounting (per review): the researcher pays total = base + partner_fee. The fund's available may only be credited base — what they can pay participants with — and the fee is platform revenue that the ledger must record.

Changes:

  • Persist partner_fee on the transaction (migration), so completion books the immutable paid amount instead of re-deriving from the live reward.
  • Add a per-currency margin account to currency_ledger (backfilled for existing ledgers), hanging off the ledger alongside inbound/outbound.
  • Split the completion entry:
    debit  inbound  total   (full amount received)
    credit fund     base    (base → participants)
    credit margin   fee     (partner fee → platform revenue)
    
    When partner_fee is 0 the margin line is omitted.

partner_fee_percentage defaults to 0, so with no fee configured this is purely the BUG 5 immutability fix; the split only diverges once a fee is set.

Fixes Flux 10088720661. Surfaced by the money-flow assurance audit (BUG 1 + BUG 5).

🤖 Generated with Claude Code

do_complete_transaction re-derived the booked amount as
subject_count * live subject_reward, which (1) used the current reward,
so changing it between payment and confirmation credited the wrong
amount (BUG 5), and (2) never booked the partner fee anywhere (BUG 1).

Persist partner_fee on the transaction and split the completion entry
using the immutable paid amount: debit the ledger inbound the full
total, credit the fund the base (total - fee) it can pay participants
with, and credit the fee to a new per-currency ledger margin account as
platform revenue. Adds the margin account to currency_ledger
(backfilled for existing ledgers).

Fixes Flux 10088720661.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jdijkstra-eyra
jdijkstra-eyra force-pushed the fix/pay-in-book-paid-amount branch from 0b10582 to cd295a9 Compare July 16, 2026 08:29
@jdijkstra-eyra jdijkstra-eyra changed the title fix: book the paid amount on pay-in completion, not a live re-derivation fix: split pay-in booking into fund base and platform fee Jul 16, 2026
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.

1 participant