Skip to content

feat: enable viem multicall batching on the public client (0.12.0)#56

Merged
lukemacauley merged 1 commit into
mainfrom
feat/multicall-batching
Jul 6, 2026
Merged

feat: enable viem multicall batching on the public client (0.12.0)#56
lukemacauley merged 1 commit into
mainfrom
feat/multicall-batching

Conversation

@lukemacauley

@lukemacauley lukemacauley commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • The public client now sets viem's client-level batch: { multicall: true }: concurrent readContract calls (the 7 config reads in getPerpConfig, the 4 in fetchPerpContractData) are aggregated into a single Multicall3 aggregate3 eth_call — one billed RPC request instead of N. Transport-level HTTP batching stays for requests multicall cannot aggregate (simulateContract, calls with an account/value).
  • The estimateLiquidity maker-margin probe opts out with batch: false: routed through aggregate3 the inner msg.sender becomes the Multicall3 contract instead of the zero address, which can change which allowance-failure revert the margin transfer produces and break the revert-marker classification (PR fix!: size maker liquidity to the on-chain margin check #55 semantics preserved exactly).
  • On chains without a configured Multicall3 (e.g. bare Anvil test chains) viem falls back to individual eth_calls automatically; Arbitrum One and Sepolia both carry the canonical deployment.
  • Version bumped to 0.12.0 with a changelog entry. Publish fires on GitHub release; perpcity-client gets the dependency bump after that.

Test plan

  • pnpm run ci: build + 263 unit tests + tsc + biome
  • pnpm run test:integration: 38 Anvil integration tests (exercises the no-multicall fallback path)
  • After release + client bump: on a testnet market page, the config reads arrive as one eth_call to Multicall3 in devtools; trading/LP/balance flows unaffected

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Improved read performance by combining eligible contract reads into fewer network calls.
  • Bug Fixes

    • Preserved consistent behavior for liquidity checks and related margin validation.
    • Kept certain contract interactions on standard request paths when batching would affect results.
  • Chores

    • Updated the release version to 0.12.0 and added release notes.

Client-level batch.multicall aggregates concurrent readContract calls
into one Multicall3 aggregate3 eth_call (one billed RPC request instead
of N). The estimateLiquidity margin probe opts out (batch: false) so its
revert-marker classification keeps the same inner msg.sender semantics.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR enables viem's client-level batch.multicall on PerpCityContext's publicClient to aggregate concurrent readContract calls into a single Multicall3 eth_call, while explicitly disabling batching for passesMarginCheck's simulated call to preserve msg.sender consistency. Includes changelog entry and version bump to 0.12.0.

Changes

Multicall Batching Enablement

Layer / File(s) Summary
Enable client multicall batching for reads
src/context.ts
publicClient transport now sets batch.multicall: true; comments updated to describe the 7 config reads coalescing into one Multicall3 eth_call.
Exempt margin-check probe from batching
src/utils/liquidity.ts
passesMarginCheck's simulated openMaker call now explicitly sets batch: false to keep msg.sender consistent for revert marker matching.
Changelog and version bump
CHANGELOG.md, package.json
Adds a 0.12.0 changelog entry documenting the batching behavior and bumps package version from 0.11.0 to 0.12.0.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: enabling viem multicall batching on the public client.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/multicall-batching

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
package.json (1)

5-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Regenerate package-lock.json to match the version bump.

package-lock.json's root version field is still 0.11.0 per the provided context, out of sync with this bump to 0.12.0. Run npm install (or equivalent) to refresh the lockfile's root version metadata.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 5, The root version metadata in package-lock.json is
out of sync with the package version bump in package.json. Regenerate the
lockfile by running npm install (or equivalent) so the package-lock root version
matches 0.12.0, and keep the package-lock.json entry aligned with the version
field in package.json.
CHANGELOG.md (1)

15-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor wording nit flagged by static analysis.

✏️ Suggested tightening
-  requests, cutting billed RPC calls roughly in proportion to the read fan-out. Transport-level
+  requests, cutting billed RPC calls roughly proportional to the read fan-out. Transport-level
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CHANGELOG.md` at line 15, The changelog entry contains a minor wording issue
flagged by static analysis; tighten the phrasing in the affected sentence so it
reads more cleanly and consistently, keeping the same meaning. Update the text
in CHANGELOG.md around the “requests, cutting billed RPC calls...” sentence to
use a more concise, polished wording.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@CHANGELOG.md`:
- Line 15: The changelog entry contains a minor wording issue flagged by static
analysis; tighten the phrasing in the affected sentence so it reads more cleanly
and consistently, keeping the same meaning. Update the text in CHANGELOG.md
around the “requests, cutting billed RPC calls...” sentence to use a more
concise, polished wording.

In `@package.json`:
- Line 5: The root version metadata in package-lock.json is out of sync with the
package version bump in package.json. Regenerate the lockfile by running npm
install (or equivalent) so the package-lock root version matches 0.12.0, and
keep the package-lock.json entry aligned with the version field in package.json.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 19415b1b-fa51-4e16-b7be-897aa6394ca6

📥 Commits

Reviewing files that changed from the base of the PR and between 541e3d3 and c6aee4c.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • package.json
  • src/context.ts
  • src/utils/liquidity.ts

@lukemacauley
lukemacauley merged commit a96c15a into main Jul 6, 2026
7 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