Skip to content

Optimize getQuote to skip calldata encoding when wallet is not needed#344

Open
its-applekid wants to merge 3 commits intoethereum-optimism:mainfrom
its-applekid:optimize-getquote-skip-calldata
Open

Optimize getQuote to skip calldata encoding when wallet is not needed#344
its-applekid wants to merge 3 commits intoethereum-optimism:mainfrom
its-applekid:optimize-getquote-skip-calldata

Conversation

@its-applekid
Copy link
Copy Markdown

Summary

Adds an includeCalldata parameter to the swap provider quoting flow. When ActionsSwapNamespace (read-only, no wallet) requests a quote, expensive calldata encoding is skipped entirely.

Changes

  • SwapQuote.execution is now optional — omitted for read-only quotes
  • SwapProvider gets a new public getQuoteReadOnly() method that skips encoding
  • _getQuote() accepts includeCalldata?: boolean parameter in both providers
  • UniswapSwapProvider conditionally skips encodeUniversalRouterSwap()
  • VelodromeSwapProvider conditionally skips encodePoolSwap()
  • ActionsSwapNamespace overrides getQuote() and getQuotes() to use read-only path
  • executeFromQuote() validates execution exists before use (clear error message)

Performance Impact

  • Read-only queries: Skip encoding per quote (non-trivial compute: encodeFunctionData, encodeAbiParameters, encodePacked)
  • Price routing (N providers): Skip (N-1) unnecessary encodings — only the winning quote needs calldata, and even that is deferred
  • WalletSwapNamespace: No change — still gets full execution data

Testing

  • All 138 swap tests pass
  • SDK typechecks clean
  • Lint passes (0 errors)

Closes #331

- GuardrailWallet contract with allowlists and spending limits
- Mock contracts (USDC, Morpho vault, Chainlink oracle)
- Comprehensive gas tests measuring overhead
- Results: ~96k gas overhead (+104%) with allowlist + spending limits
- Confirmed O(1) allowlist lookups (100 contracts = same cost as 2)
- Oracle read: 10k gas (mock), expect 40-50k in production
Add includeCalldata parameter to _getQuote() in swap providers.
ActionsSwapNamespace now calls getQuoteReadOnly() which skips
expensive encodeUniversalRouterSwap/encodePoolSwap operations.

WalletSwapNamespace unchanged — still gets full execution data.
executeFromQuote validates execution field exists before use.

Closes ethereum-optimism#331
@its-applekid its-applekid requested a review from a team as a code owner March 28, 2026 19:14
@its-applekid its-applekid requested a review from lucasmoore March 28, 2026 19:14
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 28, 2026

👷 Deploy request for actions-ui pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ce883fa

@wiz-inc-a178a98b5d
Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations 3 Low
SAST Finding SAST Findings 2 Medium
Software Management Finding Software Management Findings -
Total 2 Medium 3 Low

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

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.

Optimize getQuote to skip calldata encoding when wallet is not needed

1 participant