Skip to content

Commit

Permalink
Merge pull request #6 from OffchainLabs/fee-token-support
Browse files Browse the repository at this point in the history
Add support for running erc20 rollup which uses custom fee token
  • Loading branch information
tsahee authored Oct 31, 2023
2 parents 1f27c10 + fe900a5 commit bb3f094
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 11 deletions.
2 changes: 2 additions & 0 deletions scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
44 changes: 42 additions & 2 deletions scripts/ethcommands.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {
bridgeFundsCommand,
bridgeToL3Command,
createERC20Command,
sendL1Command,
sendL2Command,
sendL3Command,
Expand All @@ -30,6 +31,7 @@ async function main() {
.options(stressOptions)
.command(bridgeFundsCommand)
.command(bridgeToL3Command)
.command(createERC20Command)
.command(sendL1Command)
.command(sendL2Command)
.command(sendL3Command)
Expand Down
1 change: 1 addition & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"module": "CommonJS",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "node"
"moduleResolution": "node",
"resolveJsonModule": true
},
"files": ["index.ts"]
}
5 changes: 5 additions & 0 deletions scripts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 29 additions & 8 deletions test-node.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ consensusclient=false
redundantsequencers=0
dev_build_nitro=false
dev_build_blockscout=false
l3CustomFeeToken=false
batchposters=1
devprivkey=b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659
l1chainid=1337
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit bb3f094

Please sign in to comment.