Skip to content

Conversation

@rouzwelt
Copy link
Collaborator

@rouzwelt rouzwelt commented Sep 23, 2025

Motivation

Do NOT merge before #397

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features
    • Introduced versioned Orderbook APIs (V4, V5) with organized Primary, Structs, and Signatures.
    • Added support for decoding versioned orders (V3, V4) from bytes.
    • Extended Deployer ABI with a new evaluation function.
  • Refactor
    • Migrated all internal references to the V4 Orderbook ABI for encoding/decoding, logs, and quoting.
    • Consolidated Order types under a versioned namespace.
  • Bug Fixes
    • Corrected vault ID handling using BigInt.
    • Standardized wallet amount formatting to 18 decimals for consistent gas/amount displays.
  • Tests
    • Updated unit and E2E tests to target versioned ABIs.

@rouzwelt rouzwelt self-assigned this Sep 23, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces versioned ABI namespaces for Orderbook (V4, V5), adds deployer eval4 ABI and related structs, migrates core logic/tests to use ABI.Orderbook.V4 paths, adds versioned Order types (V3, V4) with decoding utilities, adjusts vaultId handling to BigInt in places, and standardizes certain wallet formatting to 18 decimals.

Changes

Cohort / File(s) Summary
Deployer ABI additions
src/common/abis/deployer.ts
Adds _StackItem, _SourceIndexV2, _FullyQualifiedNamespace, _EvalV4; extends deployer ABI with eval4; exposes new DeployerAbi.Structs group.
Orderbook ABI versioning
src/common/abis/orderbook.ts
Replaces flat exports with OrderbookAbi.V4 and V5 namespaces (Primary, Structs, Signatures); adds internal _v4/_v5 literals; maintains default arb evaluable under V4.
Core inter simulate
src/core/modes/inter/simulate.ts, src/core/modes/inter/simulate.test.ts
Switches ABI references to ABI.Orderbook.V4.Primary.* for takeOrders2 and arb3; updates tests accordingly.
Core intra simulation
src/core/modes/intra/simulation.ts, src/core/modes/intra/simulation.test.ts
Uses ABI.Orderbook.V4.Primary.Orderbook for withdraw2, clear2, and multicall encoding; updates test expectation.
Core router simulate
src/core/modes/router/simulate.ts, src/core/modes/router/simulate.test.ts
Changes arb3 encoding ABI to ABI.Orderbook.V4.Primary.Arb; updates tests.
Core processing
src/core/process/log.ts, src/core/process/round.ts
Updates AfterClear event ABI path to V4; wraps vaultId lookups with BigInt for ownerTokenVaultMap indexing.
Error handling and logs
src/error/revert.ts, src/error/revert.test.ts
Migrates decodeFunctionData and log event selectors to ABI.Orderbook.V4.Primary.* indices for arb3/clear2 and frontrun detection; updates tests.
Order module refactor
src/order/index.ts, src/order/index.test.ts, src/order/types.ts, src/order/versions/index.ts, src/order/versions/v3.ts, src/order/versions/v4.ts
Introduces versioned Order types (V3, V4) and decoding via tryFromBytes; re-exports Order from versions; updates usages to Order.V3; adjusts IO shapes and vaultId BigInt handling; updates tests to V3.
Order quoting
src/order/quote.ts
Switches encode/decode ABIs to ABI.Orderbook.V4.Primary.Orderbook for quoteSingleOrder and gas estimation.
Wallet
src/wallet/fundVault.ts, src/wallet/index.ts, src/wallet/index.test.ts
Updates ABIs to V4 for vault calls; formats received amounts using 18 decimals; updates tests for 18-decimal expectations.
E2E and utils
test/e2e/e2e.test.js, test/utils.js
Uses ABI.Orderbook.V4.Primary.Arb for getContractAt; switches default evaluable to V4; encodes orderBytes with V4 struct paths.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Core as Core Logic
  participant ABI as OrderbookAbi (V4/V5)
  participant Viem as viem encoder/decoder

  Caller->>Core: request to build calldata (e.g., arb3 / takeOrders2)
  Core->>ABI: select ABI.Orderbook.V4.Primary.* 
  Core->>Viem: encodeFunctionData(abi=V4.*, fn, args)
  Viem-->>Core: encoded calldata
  Core-->>Caller: transaction data
  note over ABI,Core: ABI selection moved from Primary.* to V4.Primary.*
Loading
sequenceDiagram
  autonumber
  actor Consumer
  participant OrderV3 as Order.V3
  participant ABI as ABI.Orderbook.V4.Primary.OrderStructAbi
  participant Viem as viem.decodeAbiParameters

  Consumer->>OrderV3: tryFromBytes(orderBytes)
  OrderV3->>Viem: decodeAbiParameters(ABI, orderBytes)
  alt success
    Viem-->>OrderV3: decoded fields
    OrderV3-->>Consumer: Result.ok({ type: V3, owner, nonce, evaluable, validInputs/Outputs })
  else failure
    Viem--x OrderV3: error
    OrderV3-->>Consumer: Result.err(error)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

enhancement, update

Suggested reviewers

  • hardyjosh
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-09-23-v5-abis

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8a6da1 and a477829.

📒 Files selected for processing (24)
  • src/common/abis/deployer.ts (2 hunks)
  • src/common/abis/orderbook.ts (1 hunks)
  • src/core/modes/inter/simulate.test.ts (2 hunks)
  • src/core/modes/inter/simulate.ts (2 hunks)
  • src/core/modes/intra/simulation.test.ts (1 hunks)
  • src/core/modes/intra/simulation.ts (3 hunks)
  • src/core/modes/router/simulate.test.ts (1 hunks)
  • src/core/modes/router/simulate.ts (1 hunks)
  • src/core/process/log.ts (1 hunks)
  • src/core/process/round.ts (1 hunks)
  • src/error/revert.test.ts (2 hunks)
  • src/error/revert.ts (2 hunks)
  • src/order/index.test.ts (4 hunks)
  • src/order/index.ts (5 hunks)
  • src/order/quote.ts (3 hunks)
  • src/order/types.ts (1 hunks)
  • src/order/versions/index.ts (1 hunks)
  • src/order/versions/v3.ts (1 hunks)
  • src/order/versions/v4.ts (1 hunks)
  • src/wallet/fundVault.ts (2 hunks)
  • src/wallet/index.test.ts (1 hunks)
  • src/wallet/index.ts (1 hunks)
  • test/e2e/e2e.test.js (4 hunks)
  • test/utils.js (4 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

@rouzwelt rouzwelt mentioned this pull request Sep 26, 2025
4 tasks
@rouzwelt rouzwelt changed the base branch from 2025-09-22-module-simulator to master September 26, 2025 16:50
@rouzwelt rouzwelt marked this pull request as ready for review September 26, 2025 18:42
@rouzwelt rouzwelt merged commit 9e986b4 into master Sep 26, 2025
11 of 12 checks passed
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