Skip to content

feat: place split limit orders#1266

Merged
MicBun merged 1 commit intomainfrom
splitOrder
Nov 27, 2025
Merged

feat: place split limit orders#1266
MicBun merged 1 commit intomainfrom
splitOrder

Conversation

@MicBun
Copy link
Member

@MicBun MicBun commented Nov 27, 2025

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

Summary by CodeRabbit

  • New Features

    • Added split-limit order placement for liquidity providers, enabling simultaneous provision of long and short positions with built-in parameter validation and market checks.
  • Tests

    • Comprehensive test suite added for split-limit orders covering validation, error handling, and position verification scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@MicBun MicBun self-assigned this Nov 27, 2025
@MicBun MicBun added the type: feat New feature or request label Nov 27, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: place split limit orders' directly and clearly describes the main change—a new feature implementing split-limit order placement functionality, which is the primary addition across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch splitOrder

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

@holdex
Copy link

holdex bot commented Nov 27, 2025

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 5h Update time Nov 27, 2025, 2:18 PM

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: 0

🧹 Nitpick comments (2)
internal/migrations/032-order-book-actions.sql (1)

698-902: New place_split_limit_order action is coherent with existing trading flow

The split-limit action’s structure (validation → market status → collateral calc → balance check → participant get/create → lock → YES @0 + NO @ 100-true_price → match_orders) matches the patterns used in place_buy_order / place_sell_order, and the collateral/price math aligns with the tests (1 TRUF per pair, NO price = 100 − true_price). Error messages also match the test assertions that use Contains.

As a minor follow-up, you might consider extracting the repeated caller-format validation and participant get-or-create logic into shared helpers or a private action to DRY up place_buy_order, place_sell_order, and place_split_limit_order, but that’s optional and can be deferred.

tests/streams/order_book/split_limit_order_test.go (1)

72-136: Consider factoring the manual-settlement test shortcut into a shared helper

The manual settlement block here (creating a TxContext with OverrideAuthz: true and UPDATE ob_queries SET settled = true) is very similar in intent to the shortcut used in testSellOrderMarketSettled in sell_order_test.go. Extracting a small settleMarketForTesting(ctx, platform, marketID) helper shared across test files would reduce duplication and keep the settlement stub behavior consistent if it ever needs tweaking.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54015f4 and 294d057.

📒 Files selected for processing (3)
  • internal/migrations/032-order-book-actions.sql (1 hunks)
  • tests/streams/order_book/sell_order_test.go (1 hunks)
  • tests/streams/order_book/split_limit_order_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-14T18:18:20.905Z
Learnt from: outerlook
Repo: trufnetwork/node PR: 1055
File: extensions/tn_cache/internal/db_ops.go:40-43
Timestamp: 2025-07-14T18:18:20.905Z
Learning: The SetTx method in extensions/tn_cache/internal/db_ops.go is only used in tests that run sequentially, so concurrency concerns about race conditions don't apply to this method.

Applied to files:

  • tests/streams/order_book/sell_order_test.go
🧬 Code graph analysis (1)
tests/streams/order_book/split_limit_order_test.go (4)
tests/streams/utils/runner.go (1)
  • RunSchemaTest (37-116)
internal/migrations/migration.go (1)
  • GetSeedScriptStatements (60-109)
tests/streams/utils/utils.go (1)
  • GetTestOptionsWithCache (75-88)
tests/streams/order_book/buy_order_test.go (1)
  • Position (399-406)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: acceptance-test
🔇 Additional comments (6)
tests/streams/order_book/sell_order_test.go (1)

254-258: Clarifying comment around test-only settlement looks good

The added TODO block clearly documents that this UPDATE is a test-only shortcut and points to the future settlement action, which should help avoid confusion between test setup and production flows.

tests/streams/order_book/split_limit_order_test.go (5)

22-48: Test suite wiring and grouping are solid

The main TestPlaceSplitLimitOrder harness is wired correctly into RunSchemaTest, and the grouping into validation, success-path, and (future) matching tests makes the scenarios easy to navigate and extend.


138-255: Validation-path tests closely mirror on-chain error conditions

The invalid price, invalid amount, and insufficient-balance tests exercise the key boundary cases (0/100/150 for true_price, 0/negative/>1e9 for amount, and underfunded collateral), and the Contains checks for error text line up with the messages in place_split_limit_order. This gives good confidence that the action’s guardrails behave as intended.


257-435: Success-path tests correctly assert YES/NO positions and UPSERT behavior

The successful, multi-price, and same-price scenarios validate exactly what place_split_limit_order is supposed to do: accumulate a single YES holding at price 0, create NO sell orders at 100-true_price, and rely on UPSERT behavior to merge amounts at identical price levels. The position-count and amount assertions match the schema (Position.Price as int16, Amount as int64, per buy_order_test.go) and the Kuneiform upsert logic.


437-482: Balance delta check matches the 1 TRUF-per-pair collateral design

The balance-change test for 75 pairs correctly expects a 75 TRUF decrease (using toWei("75") and a big.Int diff). This neatly ties the ERC20 bridge behavior to the amount × 10^18 collateral formula in the SQL action and should catch any future drift in collateral calculation.


484-579: Position verification and helper invocation match the on-chain contract

The detailed position-verification test for the 35/65 split confirms both sides of the trade (YES holding @0, NO sell @65) with outcome and price checks, which aligns with $false_price := 100 - $true_price in the action. The callPlaceSplitLimitOrder helper sets up TxContext/Engine.Call in the same style as existing buy/sell helpers, so it should integrate cleanly with the engine.

@MicBun MicBun merged commit e674aa6 into main Nov 27, 2025
6 checks passed
@MicBun MicBun deleted the splitOrder branch November 27, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant