Skip to content

chore: add multi-bridge support to order book markets#1302

Merged
MicBun merged 2 commits into
mainfrom
parameterizedBridge
Jan 23, 2026
Merged

chore: add multi-bridge support to order book markets#1302
MicBun merged 2 commits into
mainfrom
parameterizedBridge

Conversation

@MicBun
Copy link
Copy Markdown
Contributor

@MicBun MicBun commented Jan 23, 2026

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

Summary by CodeRabbit

  • New Features
    • Added multi-bridge support across the order book: markets now record a bridge, and collateral, balances, transfers, and matching operate via the selected bridge with validation for invalid bridge values.
  • Tests
    • Updated test scenarios to include the bridge/extension identifier when creating markets to reflect bridge-aware behavior.

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

@MicBun MicBun self-assigned this Jan 23, 2026
@holdex
Copy link
Copy Markdown

holdex Bot commented Jan 23, 2026

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 8h Update time Jan 23, 2026, 11:12 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
Copy Markdown

coderabbitai Bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Adds bridge support to the order-book: a new non-null bridge column on ob_queries, bridge-aware vault functions and dispatch, and threading of a bridge parameter through market creation and matching actions. Tests updated to pass an extension/bridge identifier to create_market.

Changes

Cohort / File(s) Summary
Schema Migration
internal/migrations/030-order-book-schema.sql
Added bridge TEXT NOT NULL column to ob_queries.
Vault Operations
internal/migrations/031-order-book-vault.sql
ob_lock_collateral and ob_unlock_collateral gain $bridge TEXT; added runtime validation and conditional dispatch to hoodi_tt2, sepolia_bridge, or ethereum_bridge.
Order Book Actions
internal/migrations/032-order-book-actions.sql
Added validate_bridge() and get_market_bridge() helpers; create_market accepts and persists $bridge; threaded $bridge through balance, transfer, lock/unlock flows; updated match_* actions to accept $bridge.
Tests
tests/streams/order_book/*, extensions/tn_settlement/*
All create_market invocations updated to include testExtensionName (bridge) as first argument across market creation and settlement tests.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Client
    participant CreateMarket as create_market Action
    participant OBQueries as ob_queries Table
    participant Matching as Matching Engine
    participant Vault as Vault Ops
    participant Bridge as Bridge Dispatcher

    Test->>CreateMarket: create_market($bridge, $query_hash, ...)
    CreateMarket->>OBQueries: INSERT ... bridge=$bridge
    OBQueries-->>CreateMarket: query_id

    Note over Test,Matching: Order lifecycle / matching
    Test->>Matching: match_orders($query_id, ..., $bridge)
    Matching->>OBQueries: SELECT bridge FROM ob_queries WHERE query_id
    OBQueries-->>Matching: bridge
    Matching->>Vault: ob_lock_collateral($bridge, $amount)
    Vault->>Bridge: route request (CASE $bridge)
    Bridge->>Bridge: call hoodi_tt2 / sepolia_bridge / ethereum_bridge
    Bridge-->>Vault: result
    Vault-->>Matching: success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • pr-time-tracker

Poem

🐰
I hopped through rows of SQL night,
Added bridges, set them right,
Lock and route, a vault-bound song,
Hoodi, Sepolia, Ethereum along,
Markets bridge where rabbits hop along!

🚥 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 describes the main change: adding multi-bridge support to order book markets, which is the core theme across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

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
Copy Markdown

@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: 2

Caution

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

⚠️ Outside diff range comments (3)
internal/migrations/032-order-book-actions.sql (3)

561-561: Critical: Recursive call missing $bridge parameter.

The recursive call to match_direct is missing the $bridge parameter. The function signature requires 4 parameters ($query_id INT, $outcome BOOL, $price INT, $bridge TEXT), but only 3 are passed.

This will cause the recursive matching to fail.

🐛 Proposed fix
     -- Recursively call to match next orders
-    match_direct($query_id, $outcome, $price);
+    match_direct($query_id, $outcome, $price, $bridge);
 };

711-711: Critical: Recursive call missing $bridge parameter.

Same issue as match_direct - the recursive call to match_mint is missing the required $bridge parameter.

🐛 Proposed fix
     -- Recursively match next orders
-    match_mint($query_id, $yes_price, $no_price);
+    match_mint($query_id, $yes_price, $no_price, $bridge);
 };

879-879: Critical: Recursive call missing $bridge parameter.

Same issue - the recursive call to match_burn is missing the required $bridge parameter.

🐛 Proposed fix
     -- Recursively match next orders
-    match_burn($query_id, $yes_price, $no_price);
+    match_burn($query_id, $yes_price, $no_price, $bridge);
 };
🤖 Fix all issues with AI agents
In `@internal/migrations/031-order-book-vault.sql`:
- Around line 29-50: The comment in ob_lock_collateral claims validate_bridge is
called but no such call exists and the validate_bridge procedure is defined in a
later migration (032), so either (A) remove or update the misleading comment to
state that bridge validation is performed inline via the final else branch
(supported bridges: hoodi_tt2, sepolia_bridge, ethereum_bridge), or (B) if you
intend to call validate_bridge from ob_lock_collateral, move or ensure
validate_bridge is available before this migration and add a call to
validate_bridge($bridge) at the start of ob_lock_collateral; reference:
ob_lock_collateral and validate_bridge.
- Around line 17-22: The comment in the migration references a procedure named
validate_bridge that does not exist yet at runtime (it’s defined in a later
migration), so update the comment in 031-order-book-vault.sql to avoid implying
the procedure is available: either remove the reference to validate_bridge
entirely or reword to explicitly state that validate_bridge is defined in a
subsequent migration (migration 032) and is used by this migration, so readers
aren’t misled about runtime availability; ensure the updated comment mentions
the procedure name validate_bridge so it’s easy to locate.
🧹 Nitpick comments (4)
internal/migrations/030-order-book-schema.sql (1)

31-31: Consider adding a CHECK constraint for valid bridge values.

The bridge column is added without validation constraints. Given that 031-order-book-vault.sql explicitly validates bridges against a known list (hoodi_tt2, sepolia_bridge, ethereum_bridge), consider adding a CHECK constraint here for data integrity at the schema level.

♻️ Suggested constraint
     bridge TEXT NOT NULL,
+    CONSTRAINT chk_ob_queries_bridge CHECK (bridge IN ('hoodi_tt2', 'sepolia_bridge', 'ethereum_bridge')),
tests/streams/order_book/queries_test.go (1)

27-31: Unused constant testExtensionNameQueries defined.

This file defines testExtensionNameQueries but Line 880 uses testExtensionName (from market_creation_test.go). Since both are in the same package with identical values, this works but creates confusion.

♻️ Suggested fix - use the local constant
 func createTestMarketQueries(t *testing.T, ctx context.Context, platform *kwilTesting.Platform, signer *util.EthereumAddress) (int, []byte) {
 	queryData := []byte(fmt.Sprintf("test:stream:%d", time.Now().UnixNano()))
 	queryHash := sha256.Sum256(queryData)
 	settleTime := time.Now().Add(1 * time.Hour).Unix()

 	var queryID int64
 	err := callActionQueries(ctx, platform, signer, "create_market",
-		[]any{testExtensionName, queryHash[:], settleTime, int64(5), int64(20)},
+		[]any{testExtensionNameQueries, queryHash[:], settleTime, int64(5), int64(20)},
 		func(row *common.Row) error {
 			queryID = row.Values[0].(int64)
 			return nil
 		})
 	require.NoError(t, err)
internal/migrations/031-order-book-vault.sql (1)

41-49: Consider extracting bridge dispatch logic to reduce duplication.

The bridge dispatch logic (if-else chain for hoodi_tt2, sepolia_bridge, ethereum_bridge) is duplicated between ob_lock_collateral and ob_unlock_collateral. If more bridges are added, both functions must be updated.

This is acceptable for now with 3 bridges, but consider centralizing the supported bridges list if the number grows.

internal/migrations/032-order-book-actions.sql (1)

135-162: Consider extracting bridge dispatch logic to reduce code duplication.

The if-else chain for bridge-specific operations (balance, lock, transfer, unlock) is repeated multiple times throughout this file. While currently functional, this pattern makes adding new bridges error-prone and increases maintenance burden.

Consider creating helper actions like ob_get_balance($bridge TEXT, $address TEXT), ob_lock($bridge TEXT, $amount NUMERIC), and ob_transfer($bridge TEXT, $to TEXT, $amount NUMERIC) to centralize the dispatch logic.

Comment thread internal/migrations/031-order-book-vault.sql
Comment thread internal/migrations/031-order-book-vault.sql
@MicBun MicBun merged commit 8c3cb5e into main Jan 23, 2026
7 of 8 checks passed
@MicBun MicBun deleted the parameterizedBridge branch January 23, 2026 23:24
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