Skip to content

Commit 0a45f78

Browse files
authored
feat: deploy stylue deployer using create2 (#121)
* chore: remove bold upgrader * feat: deploy stylue deployer using create2 * fix: log * chore: use v3.1.0 bytecode * chore: import nitro-contract 3.1.0
1 parent 965bc97 commit 0a45f78

5 files changed

Lines changed: 82 additions & 2 deletions

File tree

scripts/ethcommands.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as fs from "fs";
1010
import { ARB_OWNER } from "./consts";
1111
import * as TransparentUpgradeableProxy from "@openzeppelin/contracts/build/contracts/TransparentUpgradeableProxy.json"
1212
import * as ExpressLaneAuctionContract from "@arbitrum/nitro-contracts/build/contracts/src/express-lane-auction/ExpressLaneAuction.sol/ExpressLaneAuction.json"
13+
import * as StylusDeployerContract from "@arbitrum/nitro-contracts/build/contracts/src/stylus/StylusDeployer.sol/StylusDeployer.json"
14+
1315
const path = require("path");
1416

1517
async function sendTransaction(argv: any, threadId: number) {
@@ -185,6 +187,36 @@ async function deployWETHContract(deployerWallet: Wallet): Promise<string> {
185187
return weth.address;
186188
}
187189

190+
async function createStylusDeployer(deployerWallet: Wallet): Promise<string> {
191+
// this factory should be deployed by the rollupcreater when deploy helper is used
192+
const create2factory = '0x4e59b44847b379578588920ca78fbf26c0b4956c'
193+
if (await deployerWallet.provider.getCode(create2factory) === '0x') {
194+
// wait for 30 seconds, check again before throwing an error
195+
await new Promise(resolve => setTimeout(resolve, 30000));
196+
if (await deployerWallet.provider.getCode(create2factory) === '0x') {
197+
throw new Error('Create2 factory not yet deployed')
198+
}
199+
}
200+
201+
const salt = ethers.constants.HashZero
202+
const stylusDeployerBytecode = StylusDeployerContract.bytecode
203+
const stylusDeployerAddress = ethers.utils.getCreate2Address(create2factory, salt, ethers.utils.keccak256(stylusDeployerBytecode))
204+
205+
// check if the address is already deployed
206+
const code = await deployerWallet.provider.getCode(stylusDeployerAddress)
207+
if (code !== '0x') {
208+
console.log("Stylus deployer already deployed")
209+
} else {
210+
const stylusDeployerTx = await deployerWallet.sendTransaction({
211+
to: create2factory,
212+
data: ethers.utils.concat([salt, stylusDeployerBytecode])
213+
})
214+
await stylusDeployerTx.wait()
215+
}
216+
217+
return stylusDeployerAddress
218+
}
219+
188220
export const bridgeFundsCommand = {
189221
command: "bridge-funds",
190222
describe: "sends funds from l1 to l2",
@@ -592,6 +624,30 @@ export const createWETHCommand = {
592624
},
593625
};
594626

627+
export const createStylusDeployerCommand = {
628+
command: "create-stylus-deployer",
629+
describe: "deploys the stylus deployer contract",
630+
builder: {
631+
deployer: { string: true, describe: "account (see general help)" },
632+
l3: { boolean: false, describe: "deploy on L3, otherwise deploy on L2" },
633+
},
634+
handler: async (argv: any) => {
635+
console.log("create-stylus-deployer");
636+
637+
const provider = new ethers.providers.WebSocketProvider(argv.l3 ? argv.l3url : argv.l2url);
638+
const deployerWallet = namedAccount(argv.deployer).connect(provider);
639+
640+
const stylusDeployerAddress = await createStylusDeployer(deployerWallet);
641+
if (argv.l3) {
642+
console.log("Stylus deployer deployed at L3 address:", stylusDeployerAddress);
643+
} else {
644+
console.log("Stylus deployer deployed at L2 address:", stylusDeployerAddress);
645+
}
646+
647+
provider.destroy();
648+
}
649+
};
650+
595651
export const sendL1Command = {
596652
command: "send-l1",
597653
describe: "sends funds between l1 accounts",

scripts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
createERC20Command,
2727
deployExpressLaneAuctionContractCommand,
2828
createWETHCommand,
29+
createStylusDeployerCommand,
2930
transferERC20Command,
3031
sendL1Command,
3132
sendL2Command,
@@ -56,6 +57,7 @@ async function main() {
5657
.command(deployExpressLaneAuctionContractCommand)
5758
.command(createFeeTokenPricerCommand)
5859
.command(createWETHCommand)
60+
.command(createStylusDeployerCommand)
5961
.command(transferERC20Command)
6062
.command(sendL1Command)
6163
.command(sendL2Command)

scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"author": "Offchain Labs, Inc.",
77
"license": "Apache-2.0",
88
"dependencies": {
9-
"@arbitrum/nitro-contracts": "^2.1.1",
9+
"@arbitrum/nitro-contracts": "^3.1.0",
1010
"@arbitrum/token-bridge-contracts": "1.2.0",
1111
"@node-redis/client": "^1.0.4",
1212
"@openzeppelin/contracts": "^4.9.3",

scripts/yarn.lock

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
optionalDependencies:
2020
sol2uml "2.2.0"
2121

22+
"@arbitrum/nitro-contracts@^3.1.0":
23+
version "3.1.0"
24+
resolved "https://registry.yarnpkg.com/@arbitrum/nitro-contracts/-/nitro-contracts-3.1.0.tgz#89488e798593dd8d36f44ab1f684e47410e375a1"
25+
integrity sha512-/nDcQ3bZ5D761vv5I2r2gS+HeMTj9A2wgKzSWGTkqJ1ewzz8b1892OLBWgNja24J5daBTgGYV4vlxT+75478+w==
26+
dependencies:
27+
"@offchainlabs/upgrade-executor" "1.1.0-beta.0"
28+
"@openzeppelin/contracts" "4.7.3"
29+
"@openzeppelin/contracts-upgradeable" "4.7.3"
30+
patch-package "^6.5.1"
31+
solady "0.0.182"
32+
2233
"@arbitrum/token-bridge-contracts@1.2.0":
2334
version "1.2.0"
2435
resolved "https://registry.yarnpkg.com/@arbitrum/token-bridge-contracts/-/token-bridge-contracts-1.2.0.tgz#b1dc02e123393848d0d8e5c167028bafa0ac8229"
@@ -2198,7 +2209,7 @@ parse5@^7.0.0:
21982209
dependencies:
21992210
entities "^4.4.0"
22002211

2201-
patch-package@^6.4.7:
2212+
patch-package@^6.4.7, patch-package@^6.5.1:
22022213
version "6.5.1"
22032214
resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.5.1.tgz#3e5d00c16997e6160291fee06a521c42ac99b621"
22042215
integrity sha512-I/4Zsalfhc6bphmJTlrLoOcAF87jcxko4q0qsv4bGcurbr8IskEOtdnt9iCmsQVGL1B+iUhSQqweyTLJfCF9rA==
@@ -2522,6 +2533,11 @@ sol2uml@2.2.0:
25222533
js-graph-algorithms "^1.0.18"
25232534
klaw "^4.0.1"
25242535

2536+
solady@0.0.182:
2537+
version "0.0.182"
2538+
resolved "https://registry.yarnpkg.com/solady/-/solady-0.0.182.tgz#bd8c47f128a3a752358ad052782773966d74c400"
2539+
integrity sha512-FW6xo1akJoYpkXMzu58/56FcNU3HYYNamEbnFO3iSibXk0nSHo0DV2Gu/zI3FPg3So5CCX6IYli1TT1IWATnvg==
2540+
25252541
solidity-ast@^0.4.51:
25262542
version "0.4.55"
25272543
resolved "https://registry.yarnpkg.com/solidity-ast/-/solidity-ast-0.4.55.tgz#00b685e6eefb2e8dfb67df1fe0afbe3b3bfb4b28"

test-node.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ if $force_init; then
582582
echo == Deploy CacheManager on L2
583583
docker compose run -e CHILD_CHAIN_RPC="http://sequencer:8547" -e CHAIN_OWNER_PRIVKEY=$l2ownerKey rollupcreator deploy-cachemanager-testnode
584584

585+
echo == Deploy Stylus Deployer on L2
586+
docker compose run scripts create-stylus-deployer --deployer l2owner
587+
585588
if $l3node; then
586589
echo == Funding l3 users
587590
docker compose run scripts send-l2 --ethamount 1000 --to validator --wait
@@ -661,6 +664,9 @@ if $force_init; then
661664
echo == Deploy CacheManager on L3
662665
docker compose run -e CHILD_CHAIN_RPC="http://l3node:3347" -e CHAIN_OWNER_PRIVKEY=$l3ownerkey rollupcreator deploy-cachemanager-testnode
663666

667+
echo == Deploy Stylus Deployer on L3
668+
docker compose run scripts create-stylus-deployer --deployer l3owner --l3
669+
664670
echo == create l3 traffic
665671
docker compose run scripts send-l3 --ethamount 10 --to user_traffic_generator --wait
666672
docker compose run scripts send-l3 --ethamount 0.0001 --from user_traffic_generator --to user_traffic_generator --wait --delay 5000 --times 1000000 > /dev/null &

0 commit comments

Comments
 (0)