Skip to content

Commit 82da1b4

Browse files
committed
fix
1 parent b6cc2ee commit 82da1b4

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

estimator.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,24 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T
603603
Data: hexutil.Encode(callData),
604604
}
605605

606-
encodedImpAddr, err := provider.ContractQuery(context.Background(), wallet.Hex(), "PROXY_getImplementation()", "address", nil)
606+
addrToOverride := wallet
607+
608+
// Get implementation address and override code with walletGasEstimatorCodeV2
609+
var storageValue string
610+
rpcCall := ethrpc.NewCallBuilder[string]("eth_getStorageAt", nil, wallet.Hex(), common.BytesToHash(common.LeftPadBytes(wallet.Bytes(), 32)).Hex(), block)
611+
_, err = provider.Do(context.Background(), rpcCall.Into(&storageValue))
607612
if err != nil {
608613
return nil, err
609614
}
610-
if len(encodedImpAddr) == 0 {
611-
return nil, fmt.Errorf("cannot get implementation address of wallet %v", wallet.Hex())
612-
}
613615

614-
impAddr := common.HexToAddress(encodedImpAddr[0])
616+
impAddr := common.BytesToAddress(common.FromHex(storageValue)[12:])
617+
618+
if impAddr != (common.Address{}) {
619+
addrToOverride = impAddr
620+
}
615621

616622
allOverrides := map[common.Address]*CallOverride{
617-
impAddr: {Code: walletGasEstimatorCodeV2},
623+
addrToOverride: {Code: walletGasEstimatorCodeV2},
618624
}
619625
for address, override := range overrides {
620626
if address == wallet {
@@ -625,7 +631,7 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T
625631
}
626632

627633
var response string
628-
rpcCall := ethrpc.NewCallBuilder[string]("eth_call", nil, params, block, allOverrides)
634+
rpcCall = ethrpc.NewCallBuilder[string]("eth_call", nil, params, block, allOverrides)
629635
_, err = provider.Do(context.Background(), rpcCall.Into(&response))
630636
if err != nil {
631637
return nil, err

0 commit comments

Comments
 (0)