From ddbfb348623ce75ee42cb38caaceabbbf4c7dc7f Mon Sep 17 00:00:00 2001 From: gzeon Date: Mon, 25 Nov 2024 17:28:31 +0800 Subject: [PATCH] feat: use weth as bold stake token --- scripts/ethcommands.ts | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/index.ts | 2 ++ test-node.bash | 6 +++--- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 533f9471..aa5b333d 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -5,6 +5,7 @@ import { namedAccount, namedAddress } from "./accounts"; import * as L1GatewayRouter from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol/L1GatewayRouter.json"; import * as L1AtomicTokenBridgeCreator from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json"; import * as ERC20 from "@openzeppelin/contracts/build/contracts/ERC20.json"; +import * as TestWETH9 from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/test/TestWETH9.sol/TestWETH9.json"; import * as fs from "fs"; import { ARB_OWNER } from "./consts"; const path = require("path"); @@ -139,6 +140,14 @@ async function deployERC20Contract(deployerWallet: Wallet, decimals: number): Pr return token.address; } +async function deployWETHContract(deployerWallet: Wallet): Promise { + const wethFactory = new ContractFactory(TestWETH9.abi, TestWETH9.bytecode, deployerWallet); + const weth = await wethFactory.deploy("Wrapped Ether", "WETH"); + await weth.deployTransaction.wait(); + + return weth.address; +} + export const bridgeFundsCommand = { command: "bridge-funds", describe: "sends funds from l1 to l2", @@ -415,6 +424,38 @@ export const transferERC20Command = { }, }; +export const createWETHCommand = { + command: "create-weth", + describe: "creates WETH on L1", + builder: { + deployer: { + string: true, + describe: "account (see general help)" + }, + deposit: { + number: true, + describe: "amount of weth to deposit", + default: 100, + } + }, + handler: async (argv: any) => { + console.log("create-weth"); + + const l1provider = new ethers.providers.WebSocketProvider(argv.l1url); + const deployerWallet = namedAccount(argv.deployer).connect(l1provider); + + const wethAddress = await deployWETHContract(deployerWallet); + const weth = new ethers.Contract(wethAddress, TestWETH9.abi, deployerWallet); + console.log("WETH deployed at L1 address:", weth.address); + + if (argv.deposit > 0) { + const amount = ethers.utils.parseEther(argv.deposit.toString()); + const depositTx = await deployerWallet.sendTransaction({ to: wethAddress, value: amount, data:"0xd0e30db0" }); // deposit() + await depositTx.wait(); + } + }, +}; + export const sendL1Command = { command: "send-l1", describe: "sends funds between l1 accounts", diff --git a/scripts/index.ts b/scripts/index.ts index 69cfe156..46066f07 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -14,6 +14,7 @@ import { bridgeNativeTokenToL3Command, bridgeToL3Command, createERC20Command, + createWETHCommand, transferERC20Command, sendL1Command, sendL2Command, @@ -38,6 +39,7 @@ async function main() { .command(bridgeToL3Command) .command(bridgeNativeTokenToL3Command) .command(createERC20Command) + .command(createWETHCommand) .command(transferERC20Command) .command(sendL1Command) .command(sendL2Command) diff --git a/test-node.bash b/test-node.bash index 678e65c8..ee988620 100755 --- a/test-node.bash +++ b/test-node.bash @@ -497,10 +497,10 @@ if $force_init; then docker compose run -e CHILD_CHAIN_RPC="http://sequencer:8547" -e CHAIN_OWNER_PRIVKEY=$l2ownerKey rollupcreator deploy-cachemanager-testnode if $boldupgrade; then - echo == Deploying BOLD stake token - stakeTokenAddress=`docker compose run scripts create-erc20 --l1 --deployer l2owner --decimals 18 | tail -n 1 | awk '{ print $NF }'` + echo == Deploying WETH as BOLD stake token + stakeTokenAddress=`docker compose run scripts create-weth --deployer l2owner --deposit 100 | tail -n 1 | awk '{ print $NF }'` echo BOLD stake token address: $stakeTokenAddress - docker compose run scripts transfer-erc20 --token $stakeTokenAddress --l1 --amount 10000 --from l2owner --to validator + docker compose run scripts transfer-erc20 --token $stakeTokenAddress --l1 --amount 100 --from l2owner --to validator echo == Preparing BOLD upgrade docker compose run -e TESTNODE_MODE=true -e ROLLUP_ADDRESS=$rollupAddress -e STAKE_TOKEN=$stakeTokenAddress boldupgrader script:bold-prepare # retry this 10 times because the staker might not have made a node yet