Skip to content

Commit

Permalink
feat: add funding contract deployer
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasbusa committed Jun 3, 2024
1 parent 3f543c0 commit d42bd33
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 4 deletions.
67 changes: 67 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Use the Debian base image for broader compatibility
FROM debian:latest

# Install dependencies using apt
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
make \
jq \
direnv \
bash \
curl \
gcc \
g++ \
python3 \
python3-pip \
nodejs \
npm \
vim \
build-essential \
libusb-1.0-0-dev \
libssl-dev \
ca-certificates \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Go from the official golang image
COPY --from=golang:alpine /usr/local/go/ /usr/local/go/
ENV PATH="/usr/local/go/bin:${PATH}"

# Install pnpm
RUN npm install -g pnpm@9

# Install web3 cli
RUN curl -LSs https://raw.githubusercontent.com/gochain/web3/master/install.sh | sh

# Install Rust and Foundry
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
. $HOME/.cargo/env && \
cargo install --git https://github.com/foundry-rs/foundry --profile local --locked forge cast chisel anvil

# Ensure Foundry binaries are in PATH
ENV PATH="/root/.cargo/bin:${PATH}"

# Clone the Optimism repository and set up the environment
WORKDIR /workspace
RUN git clone https://github.com/ethereum-optimism/optimism.git && \
cd optimism && \
git checkout tutorials/chain && \
pnpm install && \
#make op-node op-batcher op-proposer && \
pnpm build

# Verify installed versions
RUN git --version && \
go version && \
node --version && \
pnpm --version && \
forge --version && \
cast --version && \
make --version && \
jq --version && \
direnv --version

# Set the working directory
WORKDIR /workspace/optimism

# Default command
CMD ["bash"]
12 changes: 10 additions & 2 deletions main.star
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
input_parser = import_module("./src/package_io/input_parser.star")
ethereum_package = import_module("github.com/kurtosis-tech/ethereum-package/main.star@add-arbitrary-contract-def")
ethereum_package = import_module("github.com/kurtosis-tech/ethereum-package/main.star")
contract_deployer = import_module("./src/contracts/contract_deployer.star")

def run(plan,args={}):
"""Deploy a Optimism L2 with a local L1.
Expand All @@ -17,7 +18,14 @@ def run(plan,args={}):

# Deploy the L1
plan.print("Deploying a local L1")
ethereum_package.run(plan, ethereum_args)
l1 = ethereum_package.run(plan, ethereum_args)
all_l1_participants = l1.all_participants
priv_key = l1.pre_funded_accounts[12].private_key # reserved for L2 contract deployer
# Deploy L2 smart contracts
plan.print("Deploying the L2 smart contracts")
first_l1_el_node = all_l1_participants[0].el_context.rpc_http_url
first_l1_cl_node = all_l1_participants[0].cl_context.beacon_http_url
contract_deployer.launch_contract_deployer(plan, first_l1_el_node, first_l1_cl_node, priv_key)

# Parse the values for the args
plan.print("Parsing the L2 input args")
Expand Down
6 changes: 4 additions & 2 deletions network_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ optimism_package:

ethereum_package:
participants:
- count: 2
- el_type: geth
- el_type: reth
network_params:
additional_preloaded_contracts: '{"0x123463a4B065722E99115D6c222f267d9cABb524": {"balance": "2ETH","code": "0x1234","storage": {}}}'
preset: minimal
additional_services:
- dora
- blockscout
65 changes: 65 additions & 0 deletions src/contracts/contract_deployer.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# The min/max CPU/memory that mev-flood can use
MIN_CPU = 100
MAX_CPU = 2000
MIN_MEMORY = 128
MAX_MEMORY = 1024

IMAGE = "bbusa/op:latest"

ENVRC_PATH = "/workspace/optimism/.envrc"
ENTRYPOINT_ARGS = ["/bin/bash", "-c"]
def launch_contract_deployer(
plan,
el_rpc_http_url,
cl_rpc_http_url,
priv_key,
):
plan.add_service(
name="op-contract-deployer",
config=ServiceConfig(
image=IMAGE,
min_cpu=MIN_CPU,
max_cpu=MAX_CPU,
min_memory=MIN_MEMORY,
max_memory=MAX_MEMORY,
entrypoint=ENTRYPOINT_ARGS,
env_vars = {
"WEB3_RPC_URL": str(el_rpc_http_url),
"WEB3_PRIVATE_KEY": str(priv_key),
"CL_RPC_URL": str(cl_rpc_http_url),
"FUND_VALUE": "10",
},
cmd=[
" && ".join(
[
"./packages/contracts-bedrock/scripts/getting-started/wallets.sh >> {0}".format(ENVRC_PATH),
"sed -i '1d' {0}".format(ENVRC_PATH), # Remove the first line (not commented out)
"echo 'export L1_RPC_KIND=any' >> {0}".format(ENVRC_PATH),
"echo 'export L1_RPC_URL={0}' >> {1}".format(el_rpc_http_url, ENVRC_PATH),
"echo 'export IMPL_SALT=$(openssl rand -hex 32)' >> {0}".format(ENVRC_PATH),
"echo 'export DEPLOYMENT_CONTEXT=getting-started' >> {0}".format(ENVRC_PATH),
"source {0}".format(ENVRC_PATH),
"web3 transfer $FUND_VALUE to $GS_ADMIN_ADDRESS", # Fund Admin
"sleep 3",
"web3 transfer $FUND_VALUE to $GS_BATCHER_ADDRESS", # Fund Batcher
"sleep 3",
"web3 transfer $FUND_VALUE to $GS_PROPOSER_ADDRESS", # Fund Proposer
"sleep 3",
# sleep till chain is finalized
"while true; do sleep 3; echo 'Chain is not yet finalized...'; if [ $(curl -s $CL_RPC_URL/eth/v1/beacon/states/1/finality_checkpoints | jq '.finalized') = true ]; then echo 'Chain is finalized!'; break; fi; done",
"cd /workspace/optimism/packages/contracts-bedrock",
"./scripts/getting-started/config.sh",
"cd /workspace/optimism",
"sleep 3",
# "cast codesize 0x4e59b44847b379578588920cA78FbF26c0B4956C --rpc-url $WEB3_RPC_URL",
# "web3 transfer $FUND_VALUE to 0x3fAB184622Dc19b6109349B94811493BF2a45362", # Fund Factory deployer

# "sleep 12",
# "cast publish --rpc-url $WEB3_RPC_URL 0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222",
"sleep 100000",
]
)
],
),
)

0 comments on commit d42bd33

Please sign in to comment.