diff --git a/.github/workflows/testnode.bash b/.github/workflows/testnode.bash index 29525cb..b6d1f59 100755 --- a/.github/workflows/testnode.bash +++ b/.github/workflows/testnode.bash @@ -5,6 +5,7 @@ # Start the test node and get PID, to terminate it once send-l2 is done. cd ${GITHUB_WORKSPACE} +# TODO once develop is merged into nitro-contract's master, remove the NITRO_CONTRACTS_BRANCH env var ./test-node.bash --init-force --detach START=$(date +%s) diff --git a/docker-compose.yaml b/docker-compose.yaml index ee8eb4b..1289560 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -328,7 +328,10 @@ services: - geth - sequencer pid: host - build: tokenbridge/ + build: + context: tokenbridge/ + args: + TOKEN_BRIDGE_BRANCH: ${TOKEN_BRIDGE_BRANCH:-} environment: - ARB_URL=http://sequencer:8547 - ETH_URL=http://geth:8545 @@ -336,6 +339,19 @@ services: - "tokenbridge-data:/workspace" - /var/run/docker.sock:/var/run/docker.sock + rollupcreator: + depends_on: + - geth + - sequencer + pid: host + build: + context: rollupcreator/ + args: + NITRO_CONTRACTS_BRANCH: ${NITRO_CONTRACTS_BRANCH:-} + volumes: + - "config:/config" + - /var/run/docker.sock:/var/run/docker.sock + volumes: l1data: consensus: diff --git a/rollupcreator/Dockerfile b/rollupcreator/Dockerfile new file mode 100644 index 0000000..17b065a --- /dev/null +++ b/rollupcreator/Dockerfile @@ -0,0 +1,14 @@ +FROM node:16-bullseye-slim +ARG NITRO_CONTRACTS_BRANCH=main +RUN apt-get update && \ + apt-get install -y git docker.io python3 build-essential curl jq +WORKDIR /workspace +RUN git clone --no-checkout https://github.com/OffchainLabs/nitro-contracts.git ./ +RUN git checkout ${NITRO_CONTRACTS_BRANCH} +RUN curl -L https://foundry.paradigm.xyz | bash +ENV PATH="${PATH}:/root/.foundry/bin" +RUN foundryup +RUN touch scripts/config.ts +RUN yarn install +RUN yarn build:all +ENTRYPOINT ["yarn"] diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 00fdbb1..82eeadb 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -279,6 +279,38 @@ export const createERC20Command = { }, }; +export const transferERC20Command = { + command: "transfer-erc20", + describe: "transfers ERC20 token", + builder: { + token: { + string: true, + describe: "token address", + }, + amount: { + string: true, + describe: "amount to transfer", + }, + from: { + string: true, + describe: "account (see general help)", + }, + to: { + string: true, + describe: "address (see general help)", + }, + }, + handler: async (argv: any) => { + console.log("transfer-erc20"); + + argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); + const account = namedAccount(argv.from).connect(argv.provider); + const tokenContract = new ethers.Contract(argv.token, ERC20.abi, account); + const decimals = await tokenContract.decimals(); + await(await tokenContract.transfer(namedAccount(argv.to).address, ethers.utils.parseUnits(argv.amount, decimals))).wait(); + argv.provider.destroy(); + }, +}; export const sendL1Command = { command: "send-l1", diff --git a/scripts/index.ts b/scripts/index.ts index 9f25c6e..2fd189f 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -14,6 +14,7 @@ import { bridgeNativeTokenToL3Command, bridgeToL3Command, createERC20Command, + transferERC20Command, sendL1Command, sendL2Command, sendL3Command, @@ -35,6 +36,7 @@ async function main() { .command(bridgeToL3Command) .command(bridgeNativeTokenToL3Command) .command(createERC20Command) + .command(transferERC20Command) .command(sendL1Command) .command(sendL2Command) .command(sendL3Command) diff --git a/test-node.bash b/test-node.bash index 1e8506a..0b5f3d8 100755 --- a/test-node.bash +++ b/test-node.bash @@ -5,6 +5,20 @@ set -e NITRO_NODE_VERSION=offchainlabs/nitro-node:v2.3.3-6a1c1a7-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.0.0-c8db5b1 +# This commit matches the v1.2.1 contracts, with additional fixes for rollup deployment script. +# Once v1.2.2 is released, we can switch to that version. +DEFAULT_NITRO_CONTRACTS_VERSION="a00d2faac01e050339ff7b0ac5bc91df06e8dbff" +DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.1" + +# Set default versions if not overriden by provided env vars +: ${NITRO_CONTRACTS_BRANCH:=$DEFAULT_NITRO_CONTRACTS_VERSION} +: ${TOKEN_BRIDGE_BRANCH:=$DEFAULT_TOKEN_BRIDGE_VERSION} +export NITRO_CONTRACTS_BRANCH +export TOKEN_BRIDGE_BRANCH + +echo "Using NITRO_CONTRACTS_BRANCH: $NITRO_CONTRACTS_BRANCH" +echo "Using TOKEN_BRIDGE_BRANCH: $TOKEN_BRIDGE_BRANCH" + mydir=`dirname $0` cd "$mydir" @@ -259,7 +273,8 @@ if $force_build; then docker build blockscout -t blockscout -f blockscout/docker/Dockerfile fi fi - LOCAL_BUILD_NODES=scripts + + LOCAL_BUILD_NODES="scripts rollupcreator" if $tokenbridge || $l3_token_bridge; then LOCAL_BUILD_NODES="$LOCAL_BUILD_NODES tokenbridge" fi @@ -344,9 +359,12 @@ if $force_init; then sequenceraddress=`docker compose run scripts print-address --account sequencer | tail -n 1 | tr -d '\r\n'` l2ownerAddress=`docker compose run scripts print-address --account l2owner | tail -n 1 | tr -d '\r\n'` + l2ownerKey=`docker compose run scripts print-private-key --account l2owner | tail -n 1 | tr -d '\r\n'` + wasmroot=`docker compose run --entrypoint sh sequencer -c "cat /home/user/target/machines/latest/module-root.txt"` - docker compose run --entrypoint /usr/local/bin/deploy sequencer --l1conn ws://geth:8546 --l1keystore /home/user/l1keystore --sequencerAddress $sequenceraddress --ownerAddress $l2ownerAddress --l1DeployAccount $l2ownerAddress --l1deployment /config/deployment.json --authorizevalidators 10 --wasmrootpath /home/user/target/machines --l1chainid=$l1chainid --l2chainconfig /config/l2_chain_config.json --l2chainname arb-dev-test --l2chaininfo /config/deployed_chain_info.json - docker compose run --entrypoint sh sequencer -c "jq [.[]] /config/deployed_chain_info.json > /config/l2_chain_info.json" + echo == Deploying L2 chain + docker compose run -e PARENT_CHAIN_RPC="http://geth:8545" -e DEPLOYER_PRIVKEY=$l2ownerKey -e PARENT_CHAIN_ID=$l1chainid -e CHILD_CHAIN_NAME="arb-dev-test" -e MAX_DATA_SIZE=117964 -e OWNER_ADDRESS=$l2ownerAddress -e WASM_MODULE_ROOT=$wasmroot -e SEQUENCER_ADDRESS=$sequenceraddress -e AUTHORIZE_VALIDATORS=10 -e CHILD_CHAIN_CONFIG_PATH="/config/l2_chain_config.json" -e CHAIN_DEPLOYMENT_INFO="/config/deployment.json" -e CHILD_CHAIN_INFO="/config/deployed_chain_info.json" rollupcreator create-rollup-testnode + docker compose run --entrypoint sh rollupcreator -c "jq [.[]] /config/deployed_chain_info.json > /config/l2_chain_info.json" if $simple; then echo == Writing configs @@ -369,7 +387,6 @@ if $force_init; then echo == Deploying L1-L2 token bridge sleep 10 # no idea why this sleep is needed but without it the deploy fails randomly rollupAddress=`docker compose run --entrypoint sh poster -c "jq -r '.[0].rollup.rollup' /config/deployed_chain_info.json | tail -n 1 | tr -d '\r\n'"` - l2ownerKey=`docker compose run scripts print-private-key --account l2owner | tail -n 1 | tr -d '\r\n'` docker compose run -e ROLLUP_OWNER_KEY=$l2ownerKey -e ROLLUP_ADDRESS=$rollupAddress -e PARENT_KEY=$devprivkey -e PARENT_RPC=http://geth:8545 -e CHILD_KEY=$devprivkey -e CHILD_RPC=http://sequencer:8547 tokenbridge deploy:local:token-bridge docker compose run --entrypoint sh tokenbridge -c "cat network.json && cp network.json l1l2_network.json && cp network.json localNetwork.json" echo @@ -398,15 +415,17 @@ if $force_init; then if $l3_custom_fee_token; then echo == Deploying custom fee token nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --mintTo user_token_bridge_deployer --bridgeable $tokenbridge | tail -n 1 | awk '{ print $NF }'` - EXTRA_L3_DEPLOY_FLAG="--nativeTokenAddress $nativeTokenAddress" + docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 100 --from user_token_bridge_deployer --to l3owner + EXTRA_L3_DEPLOY_FLAG="-e FEE_TOKEN_ADDRESS=$nativeTokenAddress" fi echo == Deploying L3 l3owneraddress=`docker compose run scripts print-address --account l3owner | tail -n 1 | tr -d '\r\n'` l3ownerkey=`docker compose run scripts print-private-key --account l3owner | tail -n 1 | tr -d '\r\n'` l3sequenceraddress=`docker compose run scripts print-address --account l3sequencer | tail -n 1 | tr -d '\r\n'` - docker compose run --entrypoint /usr/local/bin/deploy sequencer --l1conn ws://sequencer:8548 --l1keystore /home/user/l1keystore --sequencerAddress $l3sequenceraddress --ownerAddress $l3owneraddress --l1DeployAccount $l3owneraddress --l1deployment /config/l3deployment.json --authorizevalidators 10 --wasmrootpath /home/user/target/machines --l1chainid=412346 --l2chainconfig /config/l3_chain_config.json --l2chainname orbit-dev-test --l2chaininfo /config/deployed_l3_chain_info.json --maxDataSize 104857 $EXTRA_L3_DEPLOY_FLAG - docker compose run --entrypoint sh sequencer -c "jq [.[]] /config/deployed_l3_chain_info.json > /config/l3_chain_info.json" + + docker compose run -e DEPLOYER_PRIVKEY=$l3ownerkey -e PARENT_CHAIN_RPC="http://sequencer:8547" -e PARENT_CHAIN_ID=412346 -e CHILD_CHAIN_NAME="orbit-dev-test" -e MAX_DATA_SIZE=104857 -e OWNER_ADDRESS=$l3owneraddress -e WASM_MODULE_ROOT=$wasmroot -e SEQUENCER_ADDRESS=$l3sequenceraddress -e AUTHORIZE_VALIDATORS=10 -e CHILD_CHAIN_CONFIG_PATH="/config/l3_chain_config.json" -e CHAIN_DEPLOYMENT_INFO="/config/l3deployment.json" -e CHILD_CHAIN_INFO="/config/deployed_l3_chain_info.json" $EXTRA_L3_DEPLOY_FLAG rollupcreator create-rollup-testnode + docker compose run --entrypoint sh rollupcreator -c "jq [.[]] /config/deployed_l3_chain_info.json > /config/l3_chain_info.json" echo == Funding l3 funnel and dev key docker compose up --wait l3node sequencer diff --git a/tokenbridge/Dockerfile b/tokenbridge/Dockerfile index 344e537..3d8cbac 100644 --- a/tokenbridge/Dockerfile +++ b/tokenbridge/Dockerfile @@ -1,8 +1,10 @@ FROM node:16-bullseye-slim +ARG TOKEN_BRIDGE_BRANCH=main RUN apt-get update && \ apt-get install -y git docker.io python3 build-essential WORKDIR /workspace -RUN git clone https://github.com/OffchainLabs/token-bridge-contracts.git ./ +RUN git clone --no-checkout https://github.com/OffchainLabs/token-bridge-contracts.git ./ +RUN git checkout ${TOKEN_BRIDGE_BRANCH} RUN yarn install RUN yarn build ENTRYPOINT ["yarn"]