Skip to content

Commit

Permalink
Auto deploy contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Dec 20, 2024
1 parent 71822a3 commit 8b18957
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/cli/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const bundlerOptions: CliCommandOptions<IBundlerArgsInput> = {
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
64 changes: 52 additions & 12 deletions src/cli/deploySimulationsContract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ENTRY_POINT_SIMULATIONS_CREATECALL } 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 @@ -12,6 +17,16 @@ import type { IOptions } from "@alto/cli"

const DETERMINISTIC_DEPLOYER = "0x4e59b44847b379578588920ca78fbf26c0b4956c"

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 @@ -27,11 +42,12 @@ export const deploySimulationsContract = async ({
}

if (args.entrypointSimulationContract) {
const simulations = args.entrypointSimulationContract
const simulationsCode = await publicClient.getCode({
address: simulations
})
if (simulationsCode !== undefined && simulationsCode !== "0x") {
if (
await isContractDeployed({
publicClient,
address: args.entrypointSimulationContract
})
) {
return args.entrypointSimulationContract
}
}
Expand All @@ -41,21 +57,45 @@ export const deploySimulationsContract = async ({
account: utilityPrivateKey
})

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

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

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

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

const deployHash = await walletClient.sendTransaction({
chain: publicClient.chain,
to: DETERMINISTIC_DEPLOYER,
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")
}
3 changes: 3 additions & 0 deletions src/types/contracts/PimlicoEntryPointSimulations.ts

Large diffs are not rendered by default.

0 comments on commit 8b18957

Please sign in to comment.