Forward optional gas override on sendTransaction / sendCalls#14
Open
psmiratisu wants to merge 1 commit into
Open
Forward optional gas override on sendTransaction / sendCalls#14psmiratisu wants to merge 1 commit into
gas override on sendTransaction / sendCalls#14psmiratisu wants to merge 1 commit into
Conversation
The PrivyAlchemy EVM adapter currently lets viem auto-estimate gasLimit when broadcasting a tx. For complex routes (e.g. LiFi multi-hop via FeeCollector + a DEX) the auto-estimate runs too tight and txs revert at ~95% utilization. Observed on Base mainnet: 0x30b19449... gasLimit 549,099 gasUsed 522,654 (95.2%) reverted 0x17142457... gasLimit 515,171 gasUsed 491,293 (95.4%) reverted 0x445a73d0... gasLimit 434,657 gasUsed 409,803 (94.3%) reverted Aggregators like LiFi return a padded `gasLimit` in their quote response, but the adapter destructures only `to`/`data`/`value` from the Call and drops it. Changes: - Introduce `EvmCall` (re-export of viem's `Call` with an additional optional `gas?: bigint` field) for IEvmProviderAdapter's `sendTransaction` and `sendCalls` signatures. - `PrivyAlchemyEvmProviderAdapter.sendTransaction`: forward `call.gas` to walletClient.sendTransaction when set. - `PrivyAlchemyEvmProviderAdapter.sendCalls`: forward `call.gas` per-call into the Alchemy smart-wallet `sendCalls` payload. - `ViemProviderAdapter` (abstract): update the not-implemented stubs to use the new EvmCall type. Fully backward-compatible: omitting `gas` preserves current behaviour (viem/Alchemy estimates). Callers that want to pin the limit can now do so by setting `gas` on the call object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IEvmProviderAdapter.sendTransaction/sendCallscurrently let viem / Alchemy auto-estimate gas. For complex routes the auto-estimate runs too tight and txs revert with ~95% gas utilization (out-of-gas mid-execution).gas?: biginton the Call shape (EvmCall) and forward it through both methods inPrivyAlchemyEvmProviderAdapter. Backward-compatible — omittinggaspreserves current behaviour.Motivation
Observed on Base mainnet while integrating LiFi quotes through this adapter:
0x30b19449…0x17142457…0x445a73d0…Aggregators like LiFi return a padded
transactionRequest.gasLimitin their quote response, but the adapter destructures onlyto/data/valuefrom the Call object and drops it. Result: gas is estimated by the bundler with no margin and the tx OOMs partway through.Changes
providers/types.ts: newEvmCall = Call<unknown, { gas?: bigint }>type;IEvmProviderAdapter.sendTransactionandsendCallsuse it.providers/evm/privyAlchemyEvmProviderAdapter.ts:sendTransaction: forwardcall.gastowalletClient.sendTransactionwhen set.sendCalls: forwardcall.gasper-call into the Alchemy smart-walletsendCallspayload (best-effort — Alchemy ignores it if unsupported, same behaviour as today).providers/evm/viemProviderAdapter.ts: abstract stubs updated to the newEvmCalltype.Backward compatibility
Fully backward-compatible. Existing callers that pass plain
{ to, data, value }get the same auto-estimated gas behaviour. Only callers that setgassee a change.Suggested caller pattern
For LiFi or similar aggregators that return a
gasLimit:Test plan
sendTransactioncallers (nogasfield) continue to broadcast successfully on Base mainnet.gas: <padded value>see the limit reflected in the on-chain receipt (gas utilization drops below ~85%).gasis passed fromtransactionRequest.gasLimit * 1.2.🤖 Generated with Claude Code
Note
Medium Risk
Changes the on-chain broadcast path for EVM txs; risk is mitigated because
gasis optional and defaults preserve existing auto-estimation.Overview
Adds an optional
gaslimit on the EVM provider call type (EvmCall) and threads it throughsendTransactionandsendCallsso callers can supply aggregator-recommended limits instead of relying on the wallet/bundler auto-estimate.PrivyAlchemyEvmProviderAdapternow forwardscall.gasto viem’swalletClient.sendTransactionand per-call into Alchemy smart-walletsendCallswhen set; omittinggaskeeps today’s estimate-only behavior. The sharedIEvmProviderAdaptercontract andViemProviderAdapterstubs useEvmCallinstead of viem’s plainCall.This targets out-of-gas reverts on heavy routes (e.g. LiFi multi-hop) where bundled estimates ran near ~95% utilization while quote payloads already included a padded
gasLimitthat was previously dropped.Reviewed by Cursor Bugbot for commit c291333. Bugbot is set up for automated code reviews on this repo. Configure here.