Skip to content

Commit

Permalink
Merge pull request #62 from FastLane-Labs/sim-gas-price
Browse files Browse the repository at this point in the history
Set gas price equal to userOp maxFeePerGas when simulating
  • Loading branch information
jj1980a authored May 7, 2024
2 parents bc6098f + 7b5e478 commit 3b3373e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
26 changes: 24 additions & 2 deletions auction/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ func (am *Manager) NewUserOperation(userOp *operation.UserOperation, hints []com
return common.Hash{}, nil, relayerror.ErrServerInternal
}

bData, err := am.ethClient.CallContract(context.Background(), ethereum.CallMsg{To: &am.config.Contracts.Simulator, Data: pData}, nil)
bData, err := am.ethClient.CallContract(
context.Background(),
ethereum.CallMsg{
To: &am.config.Contracts.Simulator,
Gas: userOp.Gas.Uint64() + 1000000, // Add gas for validateCalls and others
GasFeeCap: new(big.Int).Set(userOp.MaxFeePerGas),
Data: pData,
},
nil)
if err != nil {
log.Info("failed to call simulator contract", "err", err, "userOpHash", userOpHash.Hex())
return common.Hash{}, nil, relayerror.ErrServerInternal
Expand Down Expand Up @@ -246,7 +254,21 @@ func (am *Manager) simulateSolverOperation(userOp *operation.UserOperation, user
return relayerror.ErrServerInternal
}

bData, err := am.ethClient.CallContract(context.Background(), ethereum.CallMsg{To: &am.config.Contracts.Simulator, Data: pData}, nil)
gasPrice := new(big.Int).Set(userOp.MaxFeePerGas)
if solverOp.MaxFeePerGas.Cmp(userOp.MaxFeePerGas) > 0 {
gasPrice.Set(solverOp.MaxFeePerGas)
}

bData, err := am.ethClient.CallContract(
context.Background(),
ethereum.CallMsg{
To: &am.config.Contracts.Simulator,
Gas: userOp.Gas.Uint64() + solverOp.Gas.Uint64() + 1000000, // Add gas for validateCalls and others
GasFeeCap: gasPrice,
Data: pData,
},
nil,
)
if err != nil {
log.Info("failed to call simulator contract", "err", err, "userOpHash", userOpHash.Hex())
return relayerror.ErrServerInternal
Expand Down
19 changes: 16 additions & 3 deletions bundle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bundle

import (
"context"
"math/big"
"sync"
"time"

Expand Down Expand Up @@ -103,12 +104,24 @@ func (bm *Manager) NewBundle(bundleOps *operation.BundleOperations) (common.Hash
return common.Hash{}, nil, relayerror.ErrServerInternal
}

gasLimit := bundleOps.UserOperation.Gas.Uint64()
gasPrice := new(big.Int).Set(bundleOps.UserOperation.MaxFeePerGas)
for _, solverOp := range bundleOps.SolverOperations {
gasLimit += solverOp.Gas.Uint64()
if solverOp.MaxFeePerGas.Cmp(gasPrice) > 0 {
gasPrice.Set(solverOp.MaxFeePerGas)
}
}
gasLimit += bm.config.Relay.Gas.MaxPerDAppOperation.Uint64()

_, err = bm.ethClient.CallContract(
context.Background(),
ethereum.CallMsg{
From: bundleOps.DAppOperation.Bundler,
To: &bm.config.Contracts.Atlas,
Data: pData,
From: bundleOps.DAppOperation.Bundler,
To: &bm.config.Contracts.Atlas,
Gas: gasLimit + 1000000, // Add gas for validateCalls and others
GasFeeCap: gasPrice,
Data: pData,
},
nil,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/auctioneer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func newDemoUserOperation() *operation.UserOperation {
Deadline: deadline,
Gas: big.NewInt(100000),
Nonce: big.NewInt(1),
MaxFeePerGas: big.NewInt(20e9),
MaxFeePerGas: big.NewInt(150e9),
Value: big.NewInt(0),
Dapp: swapIntentDAppControl,
Control: swapIntentDAppControl,
Expand Down
10 changes: 5 additions & 5 deletions tests/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var (

tokenA = common.HexToAddress("0x7439E9Bb6D8a84dd3A23fe621A30F95403F87fB9")
tokenB = common.HexToAddress("0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9")
swapIntentDAppControl = common.HexToAddress("0x632767B79E67E30914c221CdE4383d1FeaE4768E")
simpleRfqSolver = common.HexToAddress("0x8729a958873d1B44B5A089d654bb9112A33cE624")
swapIntentDAppControl = common.HexToAddress("0xe9c7bEAF3da67d3FB00708ADAE8ab62e578246d7")
simpleRfqSolver = common.HexToAddress("0x2670c2366c889B4CF4813BAeA48b9cfe2B298998")

userPk, _ = crypto.ToECDSA(common.FromHex("0d3414024a8d727a824933d47460fd9ea5d65f88feec92761a476405cf2d5922"))
userEoa = crypto.PubkeyToAddress(userPk.PublicKey) // 0xeA402251DA4365c12BF9A3C9d88029A04988A712
Expand All @@ -38,9 +38,9 @@ var (
RpcUrl: "https://rpc.sepolia.org/",
},
Contracts: config.Contracts{
Atlas: common.HexToAddress("0xa892eb9F79E0D1b6277B3456b0a8FE770386f6DB"),
AtlasVerification: common.HexToAddress("0xeeB91b2d317e3A747E88c1CA542ae31E32B87FDF"),
Simulator: common.HexToAddress("0xAAdF6272cCE4121Db92da224C28d1B59C9feF4d5"),
Atlas: common.HexToAddress("0xab654945B45D32465f83bC8B1a13F075c89F7246"),
AtlasVerification: common.HexToAddress("0x95c8B9Cff6c3ff7E119B1D70C8E10c07D5160AD6"),
Simulator: common.HexToAddress("0xa76a0CD24769241F890B322c39ABDd52aa962094"),
},
Relay: config.Relay{
Auction: config.Auction{
Expand Down
2 changes: 1 addition & 1 deletion tests/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func runSolver(sendMsgOnWs bool,
}
} else {
if err := sendSolverOpHttp(solverOp); err != nil {
log.Error("failed to send solverOp on http:", err)
log.Error("failed to send solverOp on http", "err", err)
}
}
log.Info("solver sent solverOp", "userOpHash", solverOp.UserOpHash.Hex())
Expand Down

0 comments on commit 3b3373e

Please sign in to comment.