-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fund l2 accounts and deploy deterministic deployment proxy #316
Open
minhd-vu
wants to merge
41
commits into
main
Choose a base branch
from
minhd-vu/fund-l2-accounts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+283
−17
Open
Changes from 22 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
ffa80f9
fund l2 accounts
minhd-vu 4c83027
fix lint
minhd-vu b18f509
fix lint
minhd-vu 4b1a810
remove comment
minhd-vu 81e198b
remove additional services
minhd-vu 48bab40
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 112cbef
fix typo
minhd-vu b3e5ae1
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 3d234d4
use toolbox for l2 contracts image
minhd-vu 922b3e0
update docs
minhd-vu 12621f7
funded bridge autoclaimer
minhd-vu 7a22a03
fix typo
minhd-vu 1f228c2
remove extra space
minhd-vu ccf88dd
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 6f569b2
update dockerfiles
minhd-vu 180045d
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 6c65c52
update network helper
minhd-vu ae8f5ab
add ddp branch
minhd-vu a841ff9
deploy ddp
minhd-vu bc4ea58
add node to toolbox
minhd-vu 0ae219b
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 9e1b0ff
fix ddp deployment
minhd-vu 2bd3e66
try using ci
minhd-vu 240bf5a
sort
minhd-vu cde2d8f
fix external l1 ci
minhd-vu b8a9a02
fix: shell lint
minhd-vu e15c2f0
fix: shell lint
minhd-vu c7a30a6
maybe fix
minhd-vu 2dd7905
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 09d033a
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 734e664
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu cfc82c1
fix: l2_rpc_url
minhd-vu 4a80813
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu 7b14837
chore: shell if style
minhd-vu b09f443
address comments
minhd-vu 089e54a
update docs
minhd-vu 938d2ca
fix doc
minhd-vu 7b5bfe3
Merge branch 'main' into minhd-vu/fund-l2-accounts
minhd-vu d376d42
format readme
minhd-vu cb78ffc
reuse zkevm-contracts container
minhd-vu 4d4a339
update docs
minhd-vu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
service_package = import_module("./lib/service.star") | ||
|
||
ARTIFACTS = [ | ||
{ | ||
"name": "run-l2-contract-setup.sh", | ||
"file": "./templates/contract-deploy/run-l2-contract-setup.sh", | ||
}, | ||
] | ||
|
||
|
||
def run(plan, args): | ||
artifact_paths = list(ARTIFACTS) | ||
|
||
l2_rpc_service = plan.get_service( | ||
name="cdk-erigon-sequencer" + args["deployment_suffix"] | ||
) | ||
l2_rpc_url = "http://{}:{}".format( | ||
l2_rpc_service.ip_address, l2_rpc_service.ports["rpc"].number | ||
) | ||
|
||
artifacts = [] | ||
for artifact_cfg in artifact_paths: | ||
template = read_file(src=artifact_cfg["file"]) | ||
artifact = plan.render_templates( | ||
name=artifact_cfg["name"], | ||
config={ | ||
artifact_cfg["name"]: struct( | ||
template=template, | ||
data=args | ||
| { | ||
"l2_rpc_url": l2_rpc_url, | ||
"deterministic_deployment_proxy_branch": "master", | ||
}, | ||
) | ||
}, | ||
) | ||
artifacts.append(artifact) | ||
|
||
# Create helper service to deploy contracts | ||
contracts_service_name = "contracts-l2" + args["deployment_suffix"] | ||
plan.add_service( | ||
name=contracts_service_name, | ||
config=ServiceConfig( | ||
image=args["l2_contracts_image"], | ||
files={ | ||
"/opt/zkevm": Directory(persistent_key="zkevm-l2-artifacts"), | ||
"/opt/contract-deploy/": Directory(artifact_names=artifacts), | ||
}, | ||
# These two lines are only necessary to deploy to any Kubernetes environment (e.g. GKE). | ||
entrypoint=["bash", "-c"], | ||
cmd=["sleep infinity"], | ||
user=User(uid=0, gid=0), # Run the container as root user. | ||
), | ||
) | ||
|
||
# Deploy contracts. | ||
plan.exec( | ||
description="Deploying contracts on L2", | ||
service_name=contracts_service_name, | ||
recipe=ExecRecipe( | ||
command=[ | ||
"/bin/sh", | ||
"-c", | ||
"chmod +x {0} && {0}".format( | ||
"/opt/contract-deploy/run-l2-contract-setup.sh" | ||
), | ||
] | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#!/bin/bash | ||
|
||
global_log_level="{{.global_log_level}}" | ||
if [[ $global_log_level == "debug" ]]; then | ||
set -x | ||
fi | ||
|
||
echo_ts() { | ||
local green="\e[32m" | ||
local end_color="\e[0m" | ||
local timestamp | ||
timestamp=$(date +"[%Y-%m-%d %H:%M:%S]") | ||
|
||
echo -e "$green$timestamp$end_color $1" >&2 | ||
} | ||
|
||
wait_for_rpc_to_be_available() { | ||
local counter=0 | ||
local max_retries=20 | ||
local retry_interval=5 | ||
|
||
until cast send --legacy \ | ||
--rpc-url "{{.l2_rpc_url}}" \ | ||
--private-key "{{.zkevm_l2_admin_private_key}}" \ | ||
--value 0 "{{.zkevm_l2_sequencer_address}}" &> /dev/null; do | ||
((counter++)) | ||
echo_ts "Can't send L2 transfers yet... Retrying ($counter)..." | ||
if [[ $counter -ge $max_retries ]]; then | ||
echo_ts "Exceeded maximum retry attempts. Exiting." | ||
exit 1 | ||
fi | ||
sleep $retry_interval | ||
done | ||
} | ||
|
||
fund_account_on_l2() { | ||
local address="$1" | ||
echo_ts "Funding $address" | ||
cast send \ | ||
--legacy \ | ||
--rpc-url "{{.l2_rpc_url}}" \ | ||
--private-key "{{.zkevm_l2_admin_private_key}}" \ | ||
--value "{{.l2_funding_amount}}" \ | ||
"$address" | ||
} | ||
|
||
if [[ -e "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" ]]; then | ||
echo_ts "This script has already been executed" | ||
exit 1 | ||
fi | ||
|
||
echo_ts "Waiting for the L2 RPC to be available" | ||
wait_for_rpc_to_be_available | ||
echo_ts "L2 RPC is now available" | ||
|
||
echo_ts "Funding bridge autoclaimer account on l2" | ||
fund_account_on_l2 "{{.zkevm_l2_claimtxmanager_address}}" | ||
|
||
echo_ts "Funding accounts on l2" | ||
accounts=$( | ||
polycli wallet inspect \ | ||
--mnemonic "{{.l1_preallocated_mnemonic}}" \ | ||
--addresses "{{.l2_accounts_to_fund}}" | ||
) | ||
echo "$accounts" | jq -r ".Addresses[].ETHAddress" | while read -r address; do | ||
fund_account_on_l2 "$address" | ||
done | ||
|
||
echo_ts "Building deterministic deployment proxy" | ||
git clone https://github.com/Arachnid/deterministic-deployment-proxy.git \ | ||
minhd-vu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/opt/deterministic-deployment-proxy \ | ||
--branch "{{.deterministic_deployment_proxy_branch}}" | ||
cd /opt/deterministic-deployment-proxy | ||
npm ci | ||
npm run build | ||
minhd-vu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
signer_address="0x$(cat output/deployment.json | jq --raw-output '.signerAddress')" | ||
gas_price=$(cat output/deployment.json | jq --raw-output '.gasPrice') | ||
gas_limit=$(cat output/deployment.json | jq --raw-output '.gasLimit') | ||
gas_cost=$((gas_price * gas_limit)) | ||
transaction="0x$(cat output/deployment.json | jq --raw-output '.transaction')" | ||
deployer_address="0x$(cat output/deployment.json | jq --raw-output '.address')" | ||
l1_private_key=$( | ||
polycli wallet inspect \ | ||
--mnemonic "{{.l1_preallocated_mnemonic}}" \ | ||
--addresses 1 \ | ||
| jq -r ".Addresses[].HexPrivateKey" | ||
) | ||
|
||
echo_ts "Deploying deterministic deployment proxy on l1" | ||
cast send \ | ||
--rpc-url "{{.l1_rpc_url}}" \ | ||
--private-key "$l1_private_key" \ | ||
--value "$gas_cost" \ | ||
"$signer_address" | ||
cast publish --rpc-url "{{.l1_rpc_url}}" "$transaction" | ||
|
||
echo_ts "Deploying deterministic deployment proxy on l2" | ||
cast send \ | ||
--legacy \ | ||
--rpc-url "{{.l2_rpc_url}}" \ | ||
--private-key "{{.zkevm_l2_admin_private_key}}" \ | ||
--value "$gas_cost" \ | ||
"$signer_address" | ||
cast publish --rpc-url "{{.l2_rpc_url}}" "$transaction" | ||
|
||
contract_method_signature="banana()(uint8)" | ||
expected="42" | ||
salt="0x0000000000000000000000000000000000000000000000000000000000000000" | ||
# contract: pragma solidity 0.5.8; contract Apple {function banana() external pure returns (uint8) {return 42;}} | ||
bytecode="6080604052348015600f57600080fd5b5060848061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c3cafc6f14602d575b600080fd5b6033604f565b604051808260ff1660ff16815260200191505060405180910390f35b6000602a90509056fea165627a7a72305820ab7651cb86b8c1487590004c2444f26ae30077a6b96c6bc62dda37f1328539250029" | ||
contract_address=$(cast create2 --salt $salt --init-code $bytecode) | ||
|
||
echo_ts "Testing deterministic deployment proxy on l1" | ||
cast send \ | ||
--legacy \ | ||
--rpc-url "{{.l1_rpc_url}}" \ | ||
--private-key "$l1_private_key" \ | ||
"$deployer_address" \ | ||
"$salt$bytecode" | ||
l1_actual=$(cast call --rpc-url "{{.l1_rpc_url}}" "$contract_address" "$contract_method_signature") | ||
if [ "$expected" != "$l1_actual" ]; then | ||
minhd-vu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo_ts "Failed to deploy deterministic deployment proxy on l1 (expected: $expected, actual $l1_actual)" | ||
exit 1 | ||
fi | ||
|
||
echo_ts "Testing deterministic deployment proxy on l2" | ||
cast send \ | ||
--legacy \ | ||
--rpc-url "{{.l2_rpc_url}}" \ | ||
--private-key "{{.zkevm_l2_admin_private_key}}" \ | ||
"$deployer_address" \ | ||
"$salt$bytecode" | ||
l2_actual=$(cast call --rpc-url "{{.l2_rpc_url}}" "$contract_address" "$contract_method_signature") | ||
if [ "$expected" != "$l2_actual" ]; then | ||
echo_ts "Failed to deploy deterministic deployment proxy on l2 (expected: $expected, actual $l2_actual)" | ||
exit 1 | ||
fi | ||
|
||
# The contract setup is done! | ||
touch "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / SonarCloud
Arguments in long RUN instructions should be sorted