Skip to content

Commit

Permalink
Merge pull request #37 from pimlicolabs/feat/gas-estimation
Browse files Browse the repository at this point in the history
Improve gas estimation and add further configuration options
  • Loading branch information
nikmel2803 authored Dec 2, 2023
2 parents 199cdd3 + c0882ee commit 6f1447e
Show file tree
Hide file tree
Showing 25 changed files with 831 additions and 106 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ packages/**/lib
.idea
.tmp

.env
.env
contracts
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ node_modules
.nyc
dist
.nyc_output
**/lib
packages/**/lib
**/.nyc_output
test/spec-tests/bundler-spec-tests
test/build
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[submodule "test/spec-tests/bundler-spec-tests"]
path = test/spec-tests/bundler-spec-tests
url = https://github.com/eth-infinitism/bundler-spec-tests.git
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts/lib/account-abstraction"]
path = contracts/lib/account-abstraction
url = https://github.com/eth-infinitism/account-abstraction
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
34 changes: 34 additions & 0 deletions contracts/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
14 changes: 14 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
66 changes: 66 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
13 changes: 13 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

remappings = [
'forge-std/=lib/forge-std/src',
'ds-test/=lib/forge-std/lib/ds-test/src/',
'account-abstraction/=lib/account-abstraction/contracts/',
'@openzeppelin/=lib/openzeppelin-contracts/',
]
1 change: 1 addition & 0 deletions contracts/lib/account-abstraction
Submodule account-abstraction added at abff2a
1 change: 1 addition & 0 deletions contracts/lib/forge-std
Submodule forge-std added at f73c73
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at fd81a9
12 changes: 12 additions & 0 deletions contracts/script/Counter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";

contract CounterScript is Script {
function setUp() public {}

function run() public {
vm.broadcast();
}
}
23 changes: 23 additions & 0 deletions contracts/src/ExecuteSimulator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "account-abstraction/core/EntryPoint.sol";

contract ExecuteSimulator is EntryPoint {
error CallExecuteResult(bool success, bytes data, uint256 gasUsed);

function callExecute(
address sender,
bytes calldata callData,
uint256 gas
) external {
require(msg.sender == 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789);
uint256 initialGas = gasleft();
(bool success, bytes memory returnData) = sender.call{gas: gas}(
callData
);
uint gasUsed = initialGas - gasleft();
bytes memory data = success ? bytes("") : returnData;
revert CallExecuteResult(success, data, gasUsed);
}
}
9 changes: 8 additions & 1 deletion packages/cli/src/config/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ export const bundlerArgsSchema = z.object({
logEnvironment: z.enum(["production", "development"]),

tenderlyEnabled: z.boolean().optional(),
noEip1559Support: z.boolean()
minimumGasPricePercent: z.number().int().min(0),
noEip1559Support: z.boolean(),
noEthCallOverrideSupport: z.boolean(),
useUserOperationGasLimitsForSubmission: z.boolean(),
customGasLimitForEstimation: z
.string()
.transform((val) => BigInt(val))
.optional()
})

export type IBundlerArgs = z.infer<typeof bundlerArgsSchema>
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/src/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,33 @@ export const bundlerOptions: CliCommandOptions<IBundlerArgsInput> = {
require: true,
default: false
},
minimumGasPricePercent: {
description: "Minimum % of userop gasPrice compared to gasPrice used by the bundler",
type: "number",
require: true,
default: 0
},
noEip1559Support: {
description: "Rpc url does not support EIP1559",
type: "boolean",
require: true,
default: false
},
noEthCallOverrideSupport: {
description: "Rpc url does not support eth_call overrides",
type: "boolean",
require: true,
default: false
},
useUserOperationGasLimitsForSubmission: {
description: "Use user operation gas limits during submission",
type: "boolean",
require: true,
default: false
},
customGasLimitForEstimation: {
description: "Custom gas limit for estimation",
type: "string"
}
}

Expand Down
53 changes: 46 additions & 7 deletions packages/cli/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { NonceQueuer, RpcHandler, Server, UnsafeValidator } from "@alto/rpc"
import { IBundlerArgs, IBundlerArgsInput, bundlerArgsSchema } from "./config"
import { BasicExecutor, ExecutorManager, SenderManager } from "@alto/executor"
import { Logger, initDebugLogger, initProductionLogger } from "@alto/utils"
import { createMetrics } from "@alto/utils"
import { MemoryMempool, Monitor } from "@alto/mempool"
import { NonceQueuer, RpcHandler, Server, UnsafeValidator } from "@alto/rpc"
import { Logger, createMetrics, initDebugLogger, initProductionLogger } from "@alto/utils"
import { Registry } from "prom-client"
import { Chain, PublicClient, Transport, createPublicClient, createWalletClient, http } from "viem"
import * as chains from "viem/chains"
import { fromZodError } from "zod-validation-error"
import { Registry } from "prom-client"
import { MemoryMempool, Monitor } from "@alto/mempool"
import { IBundlerArgs, IBundlerArgsInput, bundlerArgsSchema } from "./config"

const parseArgs = (args: IBundlerArgsInput): IBundlerArgs => {
// validate every arg, make typesafe so if i add a new arg i have to validate it
Expand Down Expand Up @@ -122,6 +121,42 @@ const customChains: Chain[] = [
},
},
testnet: true,
},
{
id: 901,
name: "Lyra",
network: "lyra",
nativeCurrency: {
name: "ETH",
symbol: "ETH",
decimals: 18
},
rpcUrls: {
default: {
http: []
},
public: {
http: []
}
}
},
{
id: 22222,
name: "Nautilus",
network: "nautilus",
nativeCurrency: {
name: "ZBC",
symbol: "ZBC",
decimals: 18
},
rpcUrls: {
default: {
http: []
},
public: {
http: []
}
}
}
]

Expand Down Expand Up @@ -215,7 +250,9 @@ export const bundlerHandler = async (args: IBundlerArgsInput): Promise<void> =>
logger.child({ module: "executor" }),
metrics,
!parsedArgs.tenderlyEnabled,
parsedArgs.noEip1559Support
parsedArgs.noEip1559Support,
parsedArgs.customGasLimitForEstimation,
parsedArgs.useUserOperationGasLimitsForSubmission
)

new ExecutorManager(
Expand Down Expand Up @@ -244,6 +281,8 @@ export const bundlerHandler = async (args: IBundlerArgsInput): Promise<void> =>
monitor,
nonceQueuer,
parsedArgs.tenderlyEnabled ?? false,
parsedArgs.minimumGasPricePercent,
parsedArgs.noEthCallOverrideSupport,
logger.child({ module: "rpc" }),
metrics
)
Expand Down
Loading

0 comments on commit 6f1447e

Please sign in to comment.