Skip to content

Commit

Permalink
chore: update readme and script to allow running on anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Sep 11, 2024
1 parent a658315 commit 3fbcbfe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ $ 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
Expand Down
21 changes: 18 additions & 3 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions test/TestToken.sol
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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());
}
}
4 changes: 2 additions & 2 deletions test/WakuRlnV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3fbcbfe

Please sign in to comment.