From 683ba158115d64c56a3b1f938a68aa61e141d3f8 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 11 Sep 2024 11:15:43 -0400 Subject: [PATCH] chore: update readme and script to allow running on anvil --- README.md | 6 +++++- script/Deploy.s.sol | 21 ++++++++++++++++++--- test/TestToken.sol | 7 +++++++ test/WakuRlnV2.t.sol | 4 ++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 486a37f..7376b22 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,11 @@ $ forge coverage #### Deploy to Anvil: ```sh -$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545 +$ TOKEN_ADDRESS=0x1122334455667788990011223344556677889900 forge script script/Deploy.s.sol --broadcast --rpc-url localhost --tc Deploy +``` +Replace the `TOKEN_ADDRESS` value by a token address you have deployed on anvil. A `TestToken` is available in `test/TestToken.sol` and can be deployed with +```sh +forge script test/TestToken.sol --broadcast --rpc-url localhost --tc TestTokenFactory ``` For this script to work, you need to have a `MNEMONIC` environment variable set to a valid diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 10c778a..ed9c70e 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -11,15 +11,30 @@ import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils import { BaseScript } from "./Base.s.sol"; contract Deploy is BaseScript { - function run(address _token) public broadcast returns (WakuRlnV2 w, address impl) { - // TODO: Use the correct values when deploying to mainnet + function run() public broadcast returns (WakuRlnV2 w, address impl) { + address _token = _getTokenAddress(); + return deploy(_token); + } + + function deploy(address _token) public returns (WakuRlnV2 w, address impl) { address priceCalcAddr = address(new LinearPriceCalculator(_token, 0.05 ether)); - // TODO: set DAI address 0x6B175474E89094C44Da98b954EedeAC495271d0F impl = address(new WakuRlnV2()); bytes memory data = abi.encodeCall(WakuRlnV2.initialize, (priceCalcAddr, 160_000, 20, 600, 180 days, 30 days)); address proxy = address(new ERC1967Proxy(impl, data)); w = WakuRlnV2(proxy); } + + function _getTokenAddress() internal view returns (address) { + try vm.envAddress("TOKEN_ADDRESS") returns (address passedAddress) { + return passedAddress; + } catch { + if (block.chainid == 1) { + return 0x6B175474E89094C44Da98b954EedeAC495271d0F; // DAI address on mainnet + } else { + revert("no TOKEN_ADDRESS was specified"); + } + } + } } contract DeployLibs is BaseScript { diff --git a/test/TestToken.sol b/test/TestToken.sol index 90870cd..51ac926 100644 --- a/test/TestToken.sol +++ b/test/TestToken.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.19 <0.9.0; +import { BaseScript } from "../script/Base.s.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract TestToken is ERC20 { @@ -10,3 +11,9 @@ contract TestToken is ERC20 { _mint(to, amount); } } + +contract TestTokenFactory is BaseScript { + function run() public broadcast returns (address) { + return address(new TestToken()); + } +} diff --git a/test/WakuRlnV2.t.sol b/test/WakuRlnV2.t.sol index 635f377..79068a0 100644 --- a/test/WakuRlnV2.t.sol +++ b/test/WakuRlnV2.t.sol @@ -26,7 +26,7 @@ contract WakuRlnV2Test is Test { token = new TestToken(); Deploy deployment = new Deploy(); - (w, impl) = deployment.run(address(token)); + (w, impl) = deployment.deploy(address(token)); // Minting a large number of tokens to not have to worry about // Not having enough balance @@ -898,7 +898,7 @@ contract WakuRlnV2Test is Test { /*| Name | Type | Slot | Offset | Bytes | |---------------------|-----------------------------------------------------|------|--------|-------| - | nextCommitmentIndex | uint32 | 206 | 0 | 4 | */ + | nextCommitmentIndex | uint32 | 206 | 0 | 4 | */ /* Pro tip: to easily find the storage slot of a variable, without having to calculate the storage layout