Skip to content

Commit

Permalink
Merge pull request #384 from pimlicolabs/feat/binary-search-verificat…
Browse files Browse the repository at this point in the history
…ion-gas

Add binary search verification gas for 0.7
  • Loading branch information
plusminushalf authored Dec 20, 2024
2 parents f7ef6a1 + de80e23 commit 5f229bf
Show file tree
Hide file tree
Showing 14 changed files with 1,630 additions and 554 deletions.
1 change: 1 addition & 0 deletions src/cli/config/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const bundlerArgsSchema = z.object({
)
return validatedAddresses
}),
"deterministic-deployer-address": addressSchema,
"entrypoint-simulation-contract": z.preprocess(
(v) => (v === "" ? undefined : v),
addressSchema.optional()
Expand Down
10 changes: 8 additions & 2 deletions src/cli/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ export const bundlerOptions: CliCommandOptions<IBundlerArgsInput> = {
alias: "e",
require: true
},
"deterministic-deployer-address": {
description: "Address of the deterministic deployer contract",
type: "string",
alias: "d",
require: false,
default: "0x4e59b44847b379578588920ca78fbf26c0b4956c"
},
"entrypoint-simulation-contract": {
description: "Address of the EntryPoint simulations contract",
type: "string",
alias: "c",
require: false,
default: "0xBbe8A301FbDb2a4CD58c4A37c262ecef8f889c47"
require: false
},
"refill-helper-contract": {
description: "Address of the Executor refill helper contract",
Expand Down
78 changes: 59 additions & 19 deletions src/cli/deploySimulationsContract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { PimlicoEntryPointSimulationsDeployBytecode } from "@alto/types"
import {
DETERMINISTIC_DEPLOYER_TRANSACTION,
ENTRY_POINT_SIMULATIONS_CREATECALL,
PimlicoEntryPointSimulationsDeployBytecode
} from "@alto/types"
import {
type Chain,
createWalletClient,
getContractAddress,
type Hex,
http,
type PublicClient,
Expand All @@ -10,6 +15,16 @@ import {
import type { CamelCasedProperties } from "./parseArgs"
import type { IOptions } from "@alto/cli"

const isContractDeployed = async ({
publicClient,
address
}: { publicClient: PublicClient<Transport, Chain>; address: Hex }) => {
const code = await publicClient.getCode({
address
})
return code !== undefined && code !== "0x"
}

export const deploySimulationsContract = async ({
args,
publicClient
Expand All @@ -24,36 +39,61 @@ export const deploySimulationsContract = async ({
)
}

if (args.entrypointSimulationContract) {
const simulations = args.entrypointSimulationContract
const simulationsCode = await publicClient.getCode({
address: simulations
})
if (simulationsCode !== undefined && simulationsCode !== "0x") {
return args.entrypointSimulationContract
}
}
// if (args.entrypointSimulationContract) {
// if (
// await isContractDeployed({
// publicClient,
// address: args.entrypointSimulationContract
// })
// ) {
// return args.entrypointSimulationContract
// }
// }

const walletClient = createWalletClient({
transport: http(args.rpcUrl),
account: utilityPrivateKey
})

const deployHash = await walletClient.deployContract({
if (
!(await isContractDeployed({
publicClient,
address: args.deterministicDeployerAddress
}))
) {
const deterministicDeployHash = await walletClient.sendRawTransaction({
serializedTransaction: DETERMINISTIC_DEPLOYER_TRANSACTION
})

await publicClient.waitForTransactionReceipt({
hash: deterministicDeployHash
})
}

const contractAddress = getContractAddress({
opcode: "CREATE2",
bytecode: PimlicoEntryPointSimulationsDeployBytecode,
from: args.deterministicDeployerAddress,
salt: "0x3132333400000000000000000000000000000000000000000000000000000000" as Hex
})

if (await isContractDeployed({ publicClient, address: contractAddress })) {
return contractAddress
}

const deployHash = await walletClient.sendTransaction({
chain: publicClient.chain,
abi: [],
bytecode: PimlicoEntryPointSimulationsDeployBytecode
to: args.deterministicDeployerAddress,
data: ENTRY_POINT_SIMULATIONS_CREATECALL
})

const receipt = await publicClient.waitForTransactionReceipt({
await publicClient.waitForTransactionReceipt({
hash: deployHash
})

const simulationsContract = receipt.contractAddress

if (simulationsContract === null || simulationsContract === undefined) {
throw new Error("Failed to deploy simulationsContract")
if (await isContractDeployed({ publicClient, address: contractAddress })) {
return contractAddress
}

return simulationsContract
throw new Error("Failed to deploy simulationsContract")
}
Loading

0 comments on commit 5f229bf

Please sign in to comment.