Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,34 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T
Data: hexutil.Encode(callData),
}

addrToOverride := wallet

var storageValue string
rpcCall := ethrpc.NewCallBuilder[string]("eth_getStorageAt", nil, wallet.Hex(), common.BytesToHash(common.LeftPadBytes(wallet.Bytes(), 32)).Hex(), block)
_, err = provider.Do(context.Background(), rpcCall.Into(&storageValue))
if err != nil {
return nil, err
}

impAddr := common.BytesToAddress(common.FromHex(storageValue)[12:])

if impAddr != (common.Address{}) {
addrToOverride = impAddr
}

allOverrides := map[common.Address]*CallOverride{
wallet: {Code: walletGasEstimatorCodeV2},
addrToOverride: {Code: walletGasEstimatorCodeV2},
}
for address, override := range overrides {
if address == wallet {
return nil, fmt.Errorf("cannot override wallet address %v", wallet.Hex())
if address == addrToOverride || address == wallet {
return nil, fmt.Errorf("cannot override wallet or implementation address %v", addrToOverride.Hex())
}

allOverrides[address] = override
}

var response string
rpcCall := ethrpc.NewCallBuilder[string]("eth_call", nil, params, block, allOverrides)
rpcCall = ethrpc.NewCallBuilder[string]("eth_call", nil, params, block, allOverrides)
_, err = provider.Do(context.Background(), rpcCall.Into(&response))
if err != nil {
return nil, err
Expand Down
Loading