Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Conversation

@bguiz
Copy link
Contributor

@bguiz bguiz commented Sep 19, 2025

Summary by CodeRabbit

  • Documentation
    • Reorganized navigation: Token Standards moved from Trading to Wallet, including INJ coin, Token Factory, and CW20.
    • Added an Order Book section under Wallet introducing on-chain CLOBs and Injective’s Exchange Module, covering markets, order types, MEV resistance, gas model, and atomic operations.
    • Published a detailed architecture guide explaining Frequent Batch Auctions, price discovery, state management, throughput, and user experience parity with traditional orderbooks.

@coderabbitai
Copy link

coderabbitai bot commented Sep 19, 2025

Walkthrough

Reorganized .gitbook/SUMMARY.md to move Token Standards under Wallet and add Order Book under Wallet. Added two new documentation files describing the Order Book (CLOB) and its architecture within .gitbook/defi/order-book/.

Changes

Cohort / File(s) Summary of changes
Navigation restructure
./.gitbook/SUMMARY.md
Moved “Token Standards” (and its INJ coin, Token Factory, CW20 Standard subitems) from Trading to Wallet; added “Order Book” under Wallet.
New Order Book docs
.gitbook/defi/order-book/README.md, .gitbook/defi/order-book/architecture.md
Added high-level CLOB overview and detailed architecture for Injective’s Exchange Module, including FBA matching, supported order types, state management, and cross-module atomicity.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Trader
    participant Wallet
    participant Node as Injective Node
    participant Ex as Exchange Module (CLOB)
    participant Oracle
    participant Ins as Insurance/Auction Modules
    participant Settlement

    rect rgb(235, 245, 255)
    note over Trader,Ex: Order submission (within block)
    Trader->>Wallet: Create order (market/limit/stop)
    Wallet->>Node: Broadcast tx
    Node->>Ex: Validate & enqueue order
    Ex->>Ex: Batch orders for current block
    end

    rect rgb(242, 255, 235)
    note over Ex: Frequent Batch Auction (FBA) clearing
    Ex->>Oracle: Read prices (if needed)
    Ex->>Ex: Aggregate bids/asks per market
    Ex->>Ex: Compute uniform clearing price
    Ex->>Ex: Match orders at clearing price
    end

    rect rgb(255, 250, 235)
    note over Ex,Settlement: Atomic state transitions
    Ex->>Settlement: Update balances/positions/fees
    Ex->>Ins: Trigger liquidations/insurance if needed
    Ex-->>Node: Commit block results
    Node-->>Wallet: Tx receipt & fills
    Wallet-->>Trader: Execution details
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Poem

I nibbled through the docs with glee,
Moved tokens to their Wallet tree;
An order book hopped into place,
With batches clearing, block by block pace.
Thump goes my paw—FBA’s neat!
On-chain trails where traders meet.
Carrots for code, and matching complete. 🥕

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 "docs: order book architecture" is a concise, single-line summary that accurately describes the primary change — adding the order-book architecture documentation and README — and is specific enough for a reviewer scanning commit history. It is clear and free of noise; the secondary reorganization of Token Standards in SUMMARY.md does not make the title misleading. Therefore the title meets the project's expectations for clarity and relevance.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/order-book-architecture

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

🧹 Nitpick comments (13)
.gitbook/defi/order-book/README.md (5)

3-6: Tighten intro; reduce hype and time-sensitive phrasing.

Suggest trimming marketing tone and anchoring to dates to avoid staleness.

-The cryptocurrency industry is experiencing a renewed fascination...
+Central Limit Order Books (CLOBs) have re‑emerged as a core design for on‑chain trading. This page outlines CLOB concepts and how Injective implements a fully on‑chain order book.

7-7: Add citations/cross‑links for historical claims.

“Founded in 2018… launched with comprehensive orderbook functionality…” needs an internal reference (e.g., Exchange module docs, release notes) and/or date anchoring.

-Injective has been operating a decentralized, fully on-chain CLOB infrastructure since its inception. Founded in 2018...
+Injective has operated a decentralized, fully on‑chain CLOB since its inception (2018). See Exchange module docs for historical context and releases.
+See also: Developers › Native › Injective › Exchange.

8-12: Soften competitor comparisons and avoid unverifiable absolutes.

Calls out specific chains/projects and states “compromise decentralization” and “without … constraints.” Prefer neutral phrasing or provide references.

-Most CLOB-based projects ... suffer from gas economics, computational overhead, and architectural boundaries.
+Many CLOB implementations inherit VM and fee‑model trade‑offs (e.g., per‑op gas metering, bytecode constraints).
@@
-However, it employs a dual architecture...
+Some projects adopt dual architectures; this can introduce separate execution contexts and developer trade‑offs.
@@
-...executing sophisticated financial operations without gas optimization constraints or architectural compromises.
+...executing sophisticated financial operations with fewer VM‑imposed constraints and without cross‑layer complexity.

14-14: “This paper” → “This guide”; add internal links.

Improve tone and navigability.

-This paper provides a comprehensive examination...
+This guide provides a comprehensive examination...
+Related: Order Book › Architecture (this section’s deep dive).

1-15: Standardize terminology.

Use one style consistently: “order book” (two words), “on‑chain” (hyphenated), “Exchange module” (pick casing and keep consistent).

Proposed global edits on this page:

  • orderbook → order book
  • onchain/on chain → on‑chain
  • Exchange module vs Exchange Module → choose one (docs elsewhere seem to use “Exchange” as module name; keep headings consistent)
.gitbook/defi/order-book/architecture.md (8)

5-6: Cross‑link market types.

Link each market type to existing Trading docs for continuity.

-...spot markets, perpetual futures, expiry futures, and binary options markets...
+...spot, perpetual futures, expiry futures, and binary options markets (see DeFi › Trading for concepts and parameters)...

21-30: Add module cross‑references.

Link Oracle, Insurance, Auction to their module docs to help readers jump.

-The Oracle module provides...
+The Oracle module provides... (see Developers › Native › Injective › Oracle)
-The Insurance module...
+The Insurance module... (see Developers › Native › Injective › Insurance)
-The Auction module...
+The Auction module... (see Developers › Native › Injective › Auction)

31-31: Heading level jump (H1 → H2 → H1).

Change “# Orderbook Implementation” to “## Order Book Implementation”.

-# Orderbook Implementation
+## Order Book Implementation

33-37: Clarify price‑time priority vs batch uniform pricing.

Stating price‑time priority conflicts with FBA. Document allocation within a batch (e.g., pro‑rata, time within block, random).

-The Exchange module implements a traditional price-time priority matching system...
+Across blocks, the book respects price‑time priority. Within a block, FBA computes a uniform clearing price; executions at the clearing price follow the module’s allocation policy (documented below).
+
+Allocation within a batch: <pro‑rata | time‑priority within block | other>. Please specify.

41-44: Benchmark claims need a reference.

“Thousands of orders per second” and “deterministic execution” should cite internal benchmarks/version/date or be softened.

-The module processes thousands of orders per second...
+The module is engineered for high throughput and deterministic execution across validators (see Benchmarks, vX.Y, measured on DATE).

73-78: Uncomment price discovery details (they’re useful).

Replace HTML comments with concise public text.

-<!-- The price discovery mechanism ... -->
-<!-- For limit orders, ... -->
+Within each batch, aggregate demand/supply curves determine the clearing price that maximizes executable volume, honoring limit prices. Unfilled remainder rests on the book.

81-89: Acknowledge residual MEV vectors explicitly.

Note cross‑block ordering and external venue arbitrage remain, by design.

-However, the system does not eliminate all forms of MEV. Cross-block arbitrage opportunities may still exist...
+The system does not eliminate inter‑block MEV or external venue arbitrage. These typically manifest as market‑making/arbitrage that improves cross‑venue price efficiency rather than predatory intra‑block strategies.

99-106: Add a balanced “Trade‑offs” note.

Briefly mention potential trade‑offs (e.g., uniform pricing vs continuous fills).

+{% hint style="warning" %}
+Trade‑offs: Uniform clearing prices may differ from top‑of‑book quotes; ultra‑low‑latency strategies reliant on deterministic intra‑tx ordering won’t apply within a batch.
+{% endhint %}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d73a7e and 1623c2e.

📒 Files selected for processing (3)
  • .gitbook/SUMMARY.md (1 hunks)
  • .gitbook/defi/order-book/README.md (1 hunks)
  • .gitbook/defi/order-book/architecture.md (1 hunks)
🔇 Additional comments (2)
.gitbook/defi/order-book/architecture.md (1)

66-67: Block time value needs confirmation.

“~640ms” can drift with network conditions/upgrades. Either cite a range or link to network info.

-When a block is produced (approximately every 640ms on Injective)...
+When a block is produced (target ~640 ms; see Network Information for current parameters)...
.gitbook/SUMMARY.md (1)

13-27: No duplication — Token Standards not under Trading.
Token Standards are listed in .gitbook/SUMMARY.md under defi/tokens (lines 8–11); the Trading subtree begins at line 13 and contains only trading pages.

Comment on lines +7 to +19
{% hint style="info" %}
**Understanding Blockchain Modules**

Before examining Injective's Exchange module, it's important to understand what a blockchain module represents and why this architectural choice matters.

In traditional blockchain development, applications are built as smart contracts that execute within virtual machines on top of the base blockchain protocol. These smart contracts operate with inherent limitations: they must pay gas fees for every operation, work within the computational and memory constraints of their execution environment, and can only interact with the blockchain through predefined interfaces.

A blockchain module, by contrast, is a native component of the blockchain protocol itself. Modules are written in the same programming language as the core blockchain, compiled directly into the blockchain binary, and execute with the same privileges as core protocol functions like transaction validation and block production. This means modules can perform complex operations without gas constraints, access and modify blockchain state directly, and implement sophisticated logic that would be prohibitively expensive or impossible within a virtual machine environment.

Modules can also interact with each other natively within the blockchain runtime, enabling true composability without the overhead of external calls or cross-contract communication. When developers build applications on a blockchain with relevant modules, they can import and leverage this functionality directly rather than reimplementing complex systems or working around VM limitations.

This architectural distinction (native modules versus smart contract applications) fundamentally shapes what's possible in terms of performance, complexity, and user experience.
{% endhint %}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Gas/fees wording inside “Modules” hint.

“Perform complex operations without gas constraints” overstates. Rephrase to reflect reduced VM overhead while acknowledging fees.

-This means modules can perform complex operations without gas constraints...
+This means modules can perform complex operations with fewer VM‑imposed constraints, direct state access, and predictable fee models; base chain fees still apply.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{% hint style="info" %}
**Understanding Blockchain Modules**
Before examining Injective's Exchange module, it's important to understand what a blockchain module represents and why this architectural choice matters.
In traditional blockchain development, applications are built as smart contracts that execute within virtual machines on top of the base blockchain protocol. These smart contracts operate with inherent limitations: they must pay gas fees for every operation, work within the computational and memory constraints of their execution environment, and can only interact with the blockchain through predefined interfaces.
A blockchain module, by contrast, is a native component of the blockchain protocol itself. Modules are written in the same programming language as the core blockchain, compiled directly into the blockchain binary, and execute with the same privileges as core protocol functions like transaction validation and block production. This means modules can perform complex operations without gas constraints, access and modify blockchain state directly, and implement sophisticated logic that would be prohibitively expensive or impossible within a virtual machine environment.
Modules can also interact with each other natively within the blockchain runtime, enabling true composability without the overhead of external calls or cross-contract communication. When developers build applications on a blockchain with relevant modules, they can import and leverage this functionality directly rather than reimplementing complex systems or working around VM limitations.
This architectural distinction (native modules versus smart contract applications) fundamentally shapes what's possible in terms of performance, complexity, and user experience.
{% endhint %}
{% hint style="info" %}
**Understanding Blockchain Modules**
Before examining Injective's Exchange module, it's important to understand what a blockchain module represents and why this architectural choice matters.
In traditional blockchain development, applications are built as smart contracts that execute within virtual machines on top of the base blockchain protocol. These smart contracts operate with inherent limitations: they must pay gas fees for every operation, work within the computational and memory constraints of their execution environment, and can only interact with the blockchain through predefined interfaces.
A blockchain module, by contrast, is a native component of the blockchain protocol itself. Modules are written in the same programming language as the core blockchain, compiled directly into the blockchain binary, and execute with the same privileges as core protocol functions like transaction validation and block production. This means modules can perform complex operations with fewer VM‑imposed constraints, direct state access, and predictable fee models; base chain fees still apply.
Modules can also interact with each other natively within the blockchain runtime, enabling true composability without the overhead of external calls or cross-contract communication. When developers build applications on a blockchain with relevant modules, they can import and leverage this functionality directly rather than reimplementing complex systems or working around VM limitations.
This architectural distinction (native modules versus smart contract applications) fundamentally shapes what's possible in terms of performance, complexity, and user experience.
{% endhint %}
🤖 Prompt for AI Agents
In .gitbook/defi/order-book/architecture.md around lines 7 to 19, the hint text
currently states modules can "perform complex operations without gas
constraints," which overstates reality; update the wording to acknowledge that
native modules reduce virtual-machine overhead and can be more efficient but do
not universally eliminate fees or gas models. Edit the paragraph to replace the
absolute claim with phrasing that modules enable more efficient or
lower-overhead execution and may operate under a different or reduced fee model,
while still noting that resource accounting/fees can apply depending on the
chain implementation.

Comment on lines +45 to +47

This native implementation eliminates the gas cost considerations that constrain smart contract-based orderbooks, where each order placement, modification, or cancellation consumes gas that must be paid by the user. Instead, users pay only a small fixed trading fee when orders execute, making the system economically viable for high-frequency trading strategies and market making operations.

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fees model wording.

“Users pay only a small fixed trading fee” may omit base tx fees. Clarify.

-Instead, users pay only a small fixed trading fee when orders execute...
+In addition to base chain fees, orders incur a small fixed trading fee upon execution, enabling HFT and market making viability.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
This native implementation eliminates the gas cost considerations that constrain smart contract-based orderbooks, where each order placement, modification, or cancellation consumes gas that must be paid by the user. Instead, users pay only a small fixed trading fee when orders execute, making the system economically viable for high-frequency trading strategies and market making operations.
This native implementation eliminates the gas cost considerations that constrain smart contract-based orderbooks, where each order placement, modification, or cancellation consumes gas that must be paid by the user. In addition to base chain fees, orders incur a small fixed trading fee upon execution, enabling HFT and market making viability.
🤖 Prompt for AI Agents
In .gitbook/defi/order-book/architecture.md around lines 45–47, the sentence
“Users pay only a small fixed trading fee” omits other mandatory transaction
costs; update the wording to explicitly state that the fixed trading fee applies
on execution but users are still responsible for any underlying network/base
transaction (gas) fees or relayer/settlement layer fees for on-chain actions
(e.g., deposits, withdrawals, settlements), and mention if those are typically
negligible, paid by relayers, or charged separately so readers aren’t misled.


To be fair, Injective is not the only project to recognize these architectural limitations. Hyperliquid, which launched in 2022 and has captured massive attention in the current CLOB narrative, has also built a custom L1 to avoid VM constraints. However, it employs a dual architecture, splitting state execution between HyperCore and HyperEVM, introducing development complexity and performance implications for applications hoping to leverage the CLOB.

Injective's approach is fundamentally different: implementing orderbook functionality as a native blockchain module rather than an application layer. This enables permissionless plug-and-play access for any application built on Injective, eliminating cross-layer complexity while executing sophisticated financial operations without gas optimization constraints or architectural compromises.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Accuracy: “without gas constraints” is misleading.

Even as a native module, transactions still incur base fees/gas. Rephrase to “reduced sensitivity to VM gas metering; fixed trading fee model.”

-...without gas optimization constraints...
+...with reduced sensitivity to VM gas metering and a fixed trading fee model...
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Injective's approach is fundamentally different: implementing orderbook functionality as a native blockchain module rather than an application layer. This enables permissionless plug-and-play access for any application built on Injective, eliminating cross-layer complexity while executing sophisticated financial operations without gas optimization constraints or architectural compromises.
Injective's approach is fundamentally different: implementing orderbook functionality as a native blockchain module rather than an application layer. This enables permissionless plug-and-play access for any application built on Injective, eliminating cross-layer complexity while executing sophisticated financial operations with reduced sensitivity to VM gas metering and a fixed trading fee model or architectural compromises.
🤖 Prompt for AI Agents
In .gitbook/defi/order-book/README.md around line 12, the sentence claims
Injective executes sophisticated financial operations "without gas optimization
constraints or architectural compromises," which is misleading; update the
wording to indicate that native module design reduces sensitivity to VM gas
metering and uses a fixed trading fee model. Replace "without gas optimization
constraints" with phrasing like "reduced sensitivity to VM gas metering; fixed
trading fee model" and ensure the sentence still communicates native-module
benefits while acknowledging transactions still incur base fees.

Comment on lines +8 to +12
* [Token Standards](defi/tokens/README.md)
* [INJ coin](defi/tokens/inj-coin.md)
* [Token Factory](defi/tokens/token-factory.md)
* [CW20 Standard](defi/tokens/cw20-standard.md)
* [Order Book](defi/order-book/README.md)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Indentation is wrong: “Token Standards” is not under Wallet.

Current two‑space indent makes it a sibling of Wallet. Use four‑space indent to nest under Wallet.

-  * [Token Standards](defi/tokens/README.md)
-    * [INJ coin](defi/tokens/inj-coin.md)
-    * [Token Factory](defi/tokens/token-factory.md)
-    * [CW20 Standard](defi/tokens/cw20-standard.md)
+    * [Token Standards](defi/tokens/README.md)
+      * [INJ coin](defi/tokens/inj-coin.md)
+      * [Token Factory](defi/tokens/token-factory.md)
+      * [CW20 Standard](defi/tokens/cw20-standard.md)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* [Token Standards](defi/tokens/README.md)
* [INJ coin](defi/tokens/inj-coin.md)
* [Token Factory](defi/tokens/token-factory.md)
* [CW20 Standard](defi/tokens/cw20-standard.md)
* [Order Book](defi/order-book/README.md)
* [Token Standards](defi/tokens/README.md)
* [INJ coin](defi/tokens/inj-coin.md)
* [Token Factory](defi/tokens/token-factory.md)
* [CW20 Standard](defi/tokens/cw20-standard.md)
* [Order Book](defi/order-book/README.md)
🤖 Prompt for AI Agents
In .gitbook/SUMMARY.md around lines 8 to 12, the "Token Standards" section is
indented with two spaces, placing it as a sibling of "Wallet" instead of nested
under it; increase the indent to four spaces for the "Token Standards" line and
all its child list items (INJ coin, Token Factory, CW20 Standard) so they are
correctly nested under Wallet and maintain consistent indentation for the block.

* [INJ coin](defi/tokens/inj-coin.md)
* [Token Factory](defi/tokens/token-factory.md)
* [CW20 Standard](defi/tokens/cw20-standard.md)
* [Order Book](defi/order-book/README.md)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Indentation is wrong: “Order Book” should be under Wallet; add Architecture subpage.

Fix nesting and include architecture.md to surface the deep dive.

-  * [Order Book](defi/order-book/README.md)
+    * [Order Book](defi/order-book/README.md)
+      * [Architecture](defi/order-book/architecture.md)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* [Order Book](defi/order-book/README.md)
* [Order Book](defi/order-book/README.md)
* [Architecture](defi/order-book/architecture.md)
🤖 Prompt for AI Agents
In .gitbook/SUMMARY.md around line 12, the "Order Book" entry is incorrectly
top-level instead of nested under "Wallet" and you need to add an "Architecture"
subpage; move the "* [Order Book](defi/order-book/README.md)" line to be
indented under the Wallet section (increase indentation by two spaces or one tab
to match other subitems) and add a new line for the architecture deep dive such
as "* [Architecture](defi/order-book/architecture.md)" as a sibling to Order
Book under the Wallet group, ensuring the path and indentation match the rest of
the SUMMARY.md structure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants