Skip to content

chore: distribute rewards to data provider#1324

Merged
MicBun merged 2 commits intomainfrom
distribute
Mar 4, 2026
Merged

chore: distribute rewards to data provider#1324
MicBun merged 2 commits intomainfrom
distribute

Conversation

@MicBun
Copy link
Member

@MicBun MicBun commented Mar 4, 2026

resolves: https://github.com/truflation/website/issues/3419

Summary by CodeRabbit

  • Bug Fixes

    • Reworked fee distribution to a multi-stage allocation with explicit LP, data provider, and validator shares and improved remainder handling.
  • New Features

    • Distribution reporting expanded to include separate totals for data providers and validators and per-participant identifiers in detail views.
  • Chores

    • Increased liquidity provider rewards sampling interval default from 10 to 50 blocks.

@MicBun MicBun requested a review from pr-time-tracker March 4, 2026 15:53
@MicBun MicBun self-assigned this Mar 4, 2026
@holdex
Copy link

holdex bot commented Mar 4, 2026

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time Mar 4, 2026, 4:34 PM

You can submit time with the command. Example:

@holdex pr submit-time 15m

See available commands to help comply with our Guidelines.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Reworks order-book settlement fee distribution into a multi-stage flow (lp_share / infra_share), adds bridge-specific unlocks for Data Provider and Validator, updates per-LP zero-loss distribution and audit columns, and increases LP rewards sampling interval default.

Changes

Cohort / File(s) Summary
Fee distribution & settlement
internal/migrations/033-order-book-settlement.sql
Replaces single-phase distribution with multi-stage allocation (lp_share, infra_share), extracts query_components/DP address, adds bridge-specific unlocks (hoodi_tt2, sepolia_bridge, ethereum_bridge) and leader-based validator unlock, reorders steps, applies zero-loss per-LP reward calc with dust to first LP, and inserts total_dp_fees / total_validator_fees into ob_fee_distributions.
Audit schema & read functions
internal/migrations/036-order-book-audit.sql
Adds total_dp_fees and total_validator_fees columns to ob_fee_distributions; updates get_distribution_summary() to return total_lp_fees_distributed, total_dp_fees, total_validator_fees; updates get_distribution_details() to include participant_id and return (participant_id, wallet_address, reward_amount, total_reward_percent).
LP rewards config
internal/migrations/042-lp-rewards-config.sql
Changes default sampling_interval_blocks from 10 to 50 in table definition, initial INSERT, and get_lp_rewards_config() default return.

Sequence Diagram(s)

mermaid
sequenceDiagram
rect rgba(220,240,255,0.5)
participant Settler as Settlement Proc (SQL)
participant Queries as ob_queries
participant DB as Postgres (ob_fee_distributions / LP tables)
participant Bridge as Bridge Adapters (hoodi_tt2 / sepolia / ethereum)
end
Settler->>Queries: SELECT query_components, unpack DP/leader
Queries-->>Settler: dp_addr, leader_sender
Settler->>DB: compute lp_share & infra_share, create distribution record
Settler->>Bridge: unlock DP (bridge-specific) with infra_share
Bridge-->>Settler: unlock result
Settler->>Bridge: unlock Validator (leader) with infra_share
Bridge-->>Settler: unlock result
Settler->>DB: calculate per-LP rewards (zero-loss on lp_share), insert per-LP rows
Settler->>Bridge: batch unlock LP wallets
Bridge-->>Settler: unlock results
Settler->>DB: update distribution summary with total_dp_fees / total_validator_fees

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • pr-time-tracker

Poem

🐰
I nibbled numbers, split them fair,
LPs, DP, and leader share;
Bridges opened, dust hopped first—
Audit carrots in the burst;
Hooray—settlements carrot-cheer! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the pull request: implementing reward distribution to data providers through updated fee distribution logic and audit tracking across three migration files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch distribute

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/migrations/036-order-book-audit.sql (1)

152-177: ⚠️ Potential issue | 🔴 Critical

Fix positional field indices in test code; schema change breaks consumers.

The schema adds 2 new fields (total_dp_fees, total_validator_fees) at positions 2–3, shifting lp_count and block_count to positions 4–5. Test code at tests/streams/order_book/fee_distribution_audit_test.go lines 113 and 354 reads row.Values[2] expecting lp_count but now receives total_dp_fees (a NUMERIC type), causing type assertion failures at runtime.

Update test indices: row.Values[4] for total_lp_count, row.Values[5] for block_count. Any external API consumer using positional parsing (strict decoder or positional reader) will similarly fail and must be updated.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/migrations/036-order-book-audit.sql` around lines 152 - 177, The
schema change to get_distribution_summary added two NUMERIC fields
(total_dp_fees, total_validator_fees) shifting positional columns: update any
tests or consumers that read positional columns (e.g., code referencing
row.Values[2] expecting lp_count) to use the new indices—use row.Values[4] for
total_lp_count and row.Values[5] for block_count—and scan/update any other
positional readers/decoders to account for the two inserted columns so type
assertions match the renamed field types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/migrations/033-order-book-settlement.sql`:
- Around line 150-171: The audit is recording $infra_share as paid even when the
DP or validator payouts are skipped (missing $dp_addr or `@leader_sender` or
unsupported $bridge); update the payout logic around $dp_addr/$dp_wallet and
`@leader_sender/`$validator_wallet (and calls hoodi_tt2.unlock,
sepolia_bridge.unlock, ethereum_bridge.unlock) to track whether each unlock
actually executed (e.g., set dp_paid and validator_paid flags or accumulate an
actual_paid amount) and then persist the true executed amount (or only mark as
paid when the corresponding unlock ran) instead of always persisting
$infra_share in the audit rows.
- Around line 205-206: The NUMERIC(78,0) casts in the SUM and per-participant
allocation expressions (involving $lp_share, total_percent_numeric,
$block_count) perform rounding and can violate LP conservation; replace those
casts with explicit truncation using TRUNC(...) to force deterministic
truncation toward zero for both the aggregated total calculation (used to set
$total_distributed_base) and the per-participant allocation expressions
(including the adjustment applied to $min_participant_id and the filtering
condition) so that the sum of individual allocations never exceeds $lp_share.

In `@internal/migrations/036-order-book-audit.sql`:
- Around line 53-54: The new monetary columns total_dp_fees and
total_validator_fees lack non-negative constraints; update the migration to
enforce CHECK >= 0 for each column (e.g., add a column-level CHECK or named
CONSTRAINT like total_dp_fees_nonneg and total_validator_fees_nonneg ensuring
total_dp_fees >= 0 and total_validator_fees >= 0) to match the existing
fee/count guardrails in the table definition.

---

Outside diff comments:
In `@internal/migrations/036-order-book-audit.sql`:
- Around line 152-177: The schema change to get_distribution_summary added two
NUMERIC fields (total_dp_fees, total_validator_fees) shifting positional
columns: update any tests or consumers that read positional columns (e.g., code
referencing row.Values[2] expecting lp_count) to use the new indices—use
row.Values[4] for total_lp_count and row.Values[5] for block_count—and
scan/update any other positional readers/decoders to account for the two
inserted columns so type assertions match the renamed field types.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d4ca9572-040f-4213-91c8-2848a74bad92

📥 Commits

Reviewing files that changed from the base of the PR and between 06b16d3 and 70da7c0.

📒 Files selected for processing (3)
  • internal/migrations/033-order-book-settlement.sql
  • internal/migrations/036-order-book-audit.sql
  • internal/migrations/042-lp-rewards-config.sql

@MicBun MicBun merged commit 38c4426 into main Mar 4, 2026
7 of 8 checks passed
@MicBun MicBun deleted the distribute branch March 4, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant