Skip to content

Commit

Permalink
Merge pull request #2 from ethpandaops/bbusa/contracts
Browse files Browse the repository at this point in the history
feat: add funding contract deployer
  • Loading branch information
barnabasbusa authored Jun 4, 2024
2 parents 3f543c0 + 3232610 commit f107864
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/conventional-pr-title-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Check PR title for conventional commits
name: Check PR title
on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

# cancel redundant builds
concurrency:
group: "title-checker-${{ github.head_ref }}"
cancel-in-progress: true

jobs:
title_check:
runs-on: ubuntu-latest
steps:
- uses: aslafy-z/conventional-pr-title-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48 changes: 48 additions & 0 deletions .github/workflows/per-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
pull_request:

concurrency:
group: "tests-${{ github.head_ref }}"
cancel-in-progress: true

jobs:
run_with_args:
strategy:
matrix:
file_name:
[
"./network_params.yaml"
]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Kurtosis
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
kurtosis analytics disable
- name: Run Starlark
run: kurtosis run ${{ github.workspace }} --args-file ${{ matrix.file_name }}

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Kurtosis
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
kurtosis analytics disable
- name: Kurtosis Lint
run: kurtosis lint ${{ github.workspace }}

15 changes: 15 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
push:
branches: [main]

name: release-please
jobs:
release-please:
name: "Release please"
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
release-type: simple
package-name: kurtosis
include-v-in-tag: false
74 changes: 74 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
FROM debian:latest as builder

WORKDIR /workspace

# 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 pnpm
RUN npm install -g pnpm@9

# 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 web3 cli
RUN curl -LSs https://raw.githubusercontent.com/gochain/web3/master/install.sh | sh

# Install Rust and Foundry
RUN curl -L https://foundry.paradigm.xyz | bash
ENV PATH="/root/.foundry/bin:${PATH}"
RUN foundryup

RUN git clone https://github.com/ethereum-optimism/optimism.git && \
cd optimism && \
git checkout tutorials/chain && \
pnpm install && \
pnpm build


# Use multi-stage build to keep the final image lean
FROM debian:stable-slim

WORKDIR /workspace

# Install dependencies using apt
RUN apt-get update && apt-get install -y --no-install-recommends \
jq \
direnv \
bash \
curl \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/local /usr/local
COPY --from=builder /workspace/optimism /workspace/optimism
COPY --from=builder /root/.foundry /root/.foundry

# Set up environment variables
ENV PATH="/root/.foundry/bin:/usr/local/go/bin:${PATH}"


# Set the working directory and default command
WORKDIR /workspace/optimism
CMD ["bash"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Welcome to Optimism Package
20 changes: 16 additions & 4 deletions main.star
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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={}):

def run(plan, args={}):
"""Deploy a Optimism L2 with a local L1.
Args:
Expand All @@ -17,7 +19,18 @@ 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 All @@ -27,4 +40,3 @@ def run(plan,args={}):
plan.print("Deploying a local L2")
args_with_right_defaults = input_parser.input_parser(plan, optimism_args)
plan.print(args_with_right_defaults)

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
75 changes: 75 additions & 0 deletions src/contracts/contract_deployer.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
IMAGE = "parithoshj/op-test:v3"

ENVRC_PATH = "/workspace/optimism/.envrc"

FACTORY_DEPLOYER_ADDRESS = "0x3fAB184622Dc19b6109349B94811493BF2a45362"
FACTORY_DEPLOYER_CODE = "0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222"


def launch_contract_deployer(
plan,
el_rpc_http_url,
cl_rpc_http_url,
priv_key,
):
plan.run_sh(
description="Deploying L2 contracts (takes a few minutes (30 mins for mainnet preset - 4 mins for minimal preset) -- L1 has to be finalized first)",
image=IMAGE,
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",
},
store=[
StoreSpec(src="/network-configs", name="op-genesis-configs"),
],
run=" && ".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
),
". {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",
"web3 transfer $FUND_VALUE to {0}".format(
FACTORY_DEPLOYER_ADDRESS
), # Fund Factory deployer
"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/head/finality_checkpoints | jq -r '.data.finalized.epoch')\" != \"0\" ]; then echo 'Chain is finalized!'; break; fi; done",
"cd /workspace/optimism/packages/contracts-bedrock",
"./scripts/getting-started/config.sh",
"cast publish --rpc-url $WEB3_RPC_URL {0}".format(
FACTORY_DEPLOYER_CODE
),
"sleep 12",
"forge script scripts/Deploy.s.sol:Deploy --private-key $GS_ADMIN_PRIVATE_KEY --broadcast --rpc-url $L1_RPC_URL",
"sleep 3",
"cd /workspace/optimism/op-node",
"go run cmd/main.go genesis l2 --deploy-config ../packages/contracts-bedrock/deploy-config/getting-started.json --l1-deployments ../packages/contracts-bedrock/deployments/getting-started/.deploy --outfile.l2 genesis.json --outfile.rollup rollup.json --l1-rpc $L1_RPC_URL",
"mkdir -p /network-configs",
"mv /workspace/optimism/op-node/genesis.json /network-configs/genesis.json",
"mv /workspace/optimism/op-node/rollup.json /network-configs/rollup.json",
"mv /workspace/optimism/packages/contracts-bedrock/deployments/getting-started/.deploy /network-configs/.deploy",
]
),
wait="2000s",
)
15 changes: 13 additions & 2 deletions src/package_io/input_parser.star
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ethereum_package_input_parser = import_module("github.com/kurtosis-tech/ethereum-package/src/package_io/input_parser.star")
ethereum_package_input_parser = import_module(
"github.com/kurtosis-tech/ethereum-package/src/package_io/input_parser.star"
)

DEFAULT_EL_IMAGES = {
"op-geth": "us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:latest",
Expand All @@ -21,6 +23,7 @@ ATTR_TO_BE_SKIPPED_AT_ROOT = (
"participants",
)


def input_parser(plan, input_args):
result = parse_network_params(plan, input_args)

Expand All @@ -40,6 +43,7 @@ def input_parser(plan, input_args):
),
)


def parse_network_params(plan, input_args):
result = default_input_args(input_args)

Expand All @@ -60,7 +64,11 @@ def parse_network_params(plan, input_args):
# if the value is set in input we set it in participant
new_participant[sub_attr] = sub_value
for _ in range(0, new_participant["count"]):
participant_copy = ethereum_package_input_parser.deep_copy_participant(new_participant)
participant_copy = (
ethereum_package_input_parser.deep_copy_participant(
new_participant
)
)
participants.append(participant_copy)
result["participants"] = participants

Expand All @@ -72,6 +80,7 @@ def parse_network_params(plan, input_args):

return result


def default_input_args(input_args):
network_params = default_network_params()
participants = [default_participant()]
Expand All @@ -80,11 +89,13 @@ def default_input_args(input_args):
"network_params": network_params,
}


def default_network_params():
return {
"network": "kurtosis",
}


def default_participant():
return {
"el_type": "op-geth",
Expand Down

0 comments on commit f107864

Please sign in to comment.