diff --git a/scripts/config.ts b/scripts/config.ts index f82c3314de..9aa1045914 100644 --- a/scripts/config.ts +++ b/scripts/config.ts @@ -271,6 +271,8 @@ function writeConfigs(argv: any) { l3Config.execution["sequencer"].enable = true l3Config.node["dangerous"]["no-sequencer-coordinator"] = true l3Config.node["delayed-sequencer"].enable = true + l3Config.node["delayed-sequencer"]["finalize-distance"] = 0 + l3Config.node["delayed-sequencer"]["require-full-finality"] = false l3Config.node["batch-poster"].enable = true l3Config.node["batch-poster"]["redis-url"] = "" fs.writeFileSync(path.join(consts.configpath, "l3node_config.json"), JSON.stringify(l3Config)) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index b5572f4321..7442fb4764 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -1,7 +1,8 @@ import { runStress } from "./stress"; -import { ethers } from "ethers"; +import { ContractFactory, ethers, Wallet } from "ethers"; import * as consts from "./consts"; import { namedAccount, namedAddress } from "./accounts"; +import * as ERC20PresetFixedSupplyArtifact from "@openzeppelin/contracts/build/contracts/ERC20PresetFixedSupply.json"; import * as fs from "fs"; const path = require("path"); @@ -43,7 +44,7 @@ async function bridgeFunds(argv: any, parentChainUrl: string, chainUrl: string, const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); while (true) { const balance = await account.getBalance() - if (balance >= ethers.utils.parseEther(argv.ethamount)) { + if (balance.gte(ethers.utils.parseEther(argv.ethamount))) { return } await sleep(100) @@ -116,6 +117,45 @@ export const bridgeToL3Command = { }, }; +export const createERC20Command = { + command: "create-erc20", + describe: "creates simple ERC20 on L2", + builder: { + deployer: { + string: true, + describe: "account (see general help)", + default: "user_l2user", + }, + mintTo: { + string: true, + describe: "account (see general help)", + default: "user_l2user", + }, + }, + handler: async (argv: any) => { + console.log("create-erc20"); + + argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); + const deployerWallet = new Wallet( + ethers.utils.sha256(ethers.utils.toUtf8Bytes(argv.deployer)), + argv.provider + ); + + const contractFactory = new ContractFactory( + ERC20PresetFixedSupplyArtifact.abi, + ERC20PresetFixedSupplyArtifact.bytecode, + deployerWallet + ); + const contract = await contractFactory.deploy("AppTestToken", "APP", ethers.utils.parseEther("1000000000"), namedAccount(argv.mintTo).address); + await contract.deployTransaction.wait(); + + console.log("Contract deployed at address:", contract.address); + + argv.provider.destroy(); + }, +}; + + export const sendL1Command = { command: "send-l1", describe: "sends funds between l1 accounts", diff --git a/scripts/index.ts b/scripts/index.ts index 62f3d49d8b..ee27b9e164 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -11,6 +11,7 @@ import { import { bridgeFundsCommand, bridgeToL3Command, + createERC20Command, sendL1Command, sendL2Command, sendL3Command, @@ -30,6 +31,7 @@ async function main() { .options(stressOptions) .command(bridgeFundsCommand) .command(bridgeToL3Command) + .command(createERC20Command) .command(sendL1Command) .command(sendL2Command) .command(sendL3Command) diff --git a/scripts/package.json b/scripts/package.json index e6ab62ec98..49e8aed877 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -7,6 +7,7 @@ "license": "Apache-2.0", "dependencies": { "@node-redis/client": "^1.0.4", + "@openzeppelin/contracts": "^4.9.3", "@types/node": "^17.0.22", "@types/yargs": "^17.0.10", "ethers": "^5.6.1", diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index c90e21b482..fc6307bc96 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -4,7 +4,8 @@ "module": "CommonJS", "strict": true, "esModuleInterop": true, - "moduleResolution": "node" + "moduleResolution": "node", + "resolveJsonModule": true }, "files": ["index.ts"] } diff --git a/scripts/yarn.lock b/scripts/yarn.lock index 624f5bcc28..eaeb8d5cab 100644 --- a/scripts/yarn.lock +++ b/scripts/yarn.lock @@ -352,6 +352,11 @@ redis-parser "3.0.0" yallist "4.0.0" +"@openzeppelin/contracts@^4.9.3": + version "4.9.3" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.3.tgz#00d7a8cf35a475b160b3f0293a6403c511099364" + integrity sha512-He3LieZ1pP2TNt5JbkPA4PNT9WC3gOTOlDcFGJW4Le4QKqwmiNJCRt44APfxMxvq7OugU/cqYuPcSBzOw38DAg== + "@types/node@^17.0.22": version "17.0.22" resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.22.tgz#38b6c4b9b2f3ed9f2e376cce42a298fb2375251e" diff --git a/test-node.bash b/test-node.bash index 34c361e80c..355d622add 100755 --- a/test-node.bash +++ b/test-node.bash @@ -40,6 +40,7 @@ consensusclient=false redundantsequencers=0 dev_build_nitro=false dev_build_blockscout=false +l3CustomFeeToken=false batchposters=1 devprivkey=b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 l1chainid=1337 @@ -117,6 +118,14 @@ while [[ $# -gt 0 ]]; do l3node=true shift ;; + --l3-fee-token) + if ! $l3node; then + echo "Error: --l3-fee-token requires --l3node to be provided." + exit 1 + fi + l3CustomFeeToken=true + shift + ;; --redundantsequencers) redundantsequencers=$2 if ! [[ $redundantsequencers =~ [0-3] ]] ; then @@ -136,6 +145,7 @@ while [[ $# -gt 0 ]]; do echo --init: remove all data, rebuild, deploy new rollup echo --pos: l1 is a proof-of-stake chain \(using prysm for consensus\) echo --validate: heavy computation, validating all blocks in WASM + echo --l3-fee-token: L3 chain is set up to use custom fee token. Only valid if also '--l3node' is provided echo --batchposters: batch posters [0-3] echo --redundantsequencers redundant sequencers [0-3] echo --detach: detach from nodes after running them @@ -300,11 +310,12 @@ if $force_init; then echo == Writing l2 chain config docker-compose run scripts write-l2-chain-config - echo == Deploying L2 sequenceraddress=`docker-compose run scripts print-address --account sequencer | tail -n 1 | tr -d '\r\n'` + echo == Deploying L2 docker-compose run --entrypoint /usr/local/bin/deploy poster --l1conn ws://geth:8546 --l1keystore /home/user/l1keystore --sequencerAddress $sequenceraddress --ownerAddress $sequenceraddress --l1DeployAccount $sequenceraddress --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 poster -c "jq [.[]] /config/deployed_chain_info.json > /config/l2_chain_info.json" + echo == Writing configs docker-compose run scripts write-config @@ -328,26 +339,36 @@ if $force_init; then docker-compose run scripts send-l2 --ethamount 1000 --to l3owner --wait docker-compose run scripts send-l2 --ethamount 1000 --to l3sequencer --wait + echo == Funding l2 deployers + docker-compose run scripts send-l2 --ethamount 100 --to user_token_bridge_deployer --wait + docker-compose run scripts send-l2 --ethamount 100 --to user_fee_token_deployer --wait echo == create l2 traffic - docker-compose run scripts send-l2 --ethamount 100 --to user_l2user --wait - docker-compose run scripts send-l2 --ethamount 0.0001 --from user_l2user --to user_l2user_b --wait --delay 500 --times 500 > /dev/null & + docker-compose run scripts send-l2 --ethamount 100 --to user_traffic_generator --wait + docker-compose run scripts send-l2 --ethamount 0.0001 --from user_traffic_generator --to user_fee_token_deployer --wait --delay 500 --times 500 > /dev/null & echo == Writing l3 chain config docker-compose run scripts write-l3-chain-config + if $l3CustomFeeToken; then + echo == Deploying custom fee token + nativeTokenAddress=`docker-compose run scripts create-erc20 --deployer user_fee_token_deployer --mintTo user_token_bridge_deployer | tail -n 1 | awk '{ print $NF }'` + EXTRA_L3_DEPLOY_FLAG="--nativeTokenAddress $nativeTokenAddress" + fi + echo == Deploying L3 l3owneraddress=`docker-compose run scripts print-address --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 poster --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 + docker-compose run --entrypoint /usr/local/bin/deploy poster --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 poster -c "jq [.[]] /config/deployed_l3_chain_info.json > /config/l3_chain_info.json" echo == Funding l3 funnel and dev key docker-compose up -d l3node poster - docker-compose run scripts bridge-to-l3 --ethamount 50000 --wait - docker-compose run scripts bridge-to-l3 --ethamount 500 --wait --from "key_0x$devprivkey" + + if ! $l3CustomFeeToken; then + docker-compose run scripts bridge-to-l3 --ethamount 50000 --wait + docker-compose run scripts bridge-to-l3 --ethamount 500 --wait --from "key_0x$devprivkey" + fi fi fi