|
| 1 | +## Allocs |
| 2 | + |
| 3 | +These scripts are utilities for setting up the `genesis.json` file for a new chain. |
| 4 | + |
| 5 | +Developers write Forge script(s) that deploy and configure the contracts they wish to be pre-deployed on their chain. These scripts can then produce an `alloc` JSON file to input to `genesis.json`, which will setup those contracts with the correct code and storage slots. |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +### Dependencies |
| 10 | + |
| 11 | +Install `heimdall` - instructions [here](https://github.com/Jon-Becker/heimdall-rs/tree/main?tab=readme-ov-file#installation--usage) |
| 12 | + |
| 13 | +Install `foundry` - instructions [here](https://book.getfoundry.sh/getting-started/installation) |
| 14 | + |
| 15 | +### Setup Scripts |
| 16 | + |
| 17 | +First, the developer must setup their `deploy-scripts.json` with the Forge scripts they want to run. |
| 18 | + |
| 19 | +Each script is represented in JSON with the following fields: |
| 20 | +- `relativePath`: the relative path to the repo containing the Forge script to run. |
| 21 | +- `deployFile`: the file name that contains the Forge script. |
| 22 | +- `deployContract`: the name of the contract in which the script is defined. |
| 23 | +- `deploySignature`: the function signature of the deploy script |
| 24 | + |
| 25 | +Using Uniswap's [Permit2](https://github.com/Uniswap/permit2/blob/main/script/DeployPermit2.s.sol) as an example, the JSON would look like this: |
| 26 | +``` |
| 27 | + { |
| 28 | + "relativePath": "../permit2", |
| 29 | + "deployFile": "DeployPermit2.s.sol", |
| 30 | + "deployContract": "DeployPermit2", |
| 31 | + "deploySignature": "run" |
| 32 | + } |
| 33 | +``` |
| 34 | + |
| 35 | +### Deploy |
| 36 | + |
| 37 | +This bash script will run each of the deploy scripts within their respective repos, then output the addresses of every contract deployed: |
| 38 | + |
| 39 | +```shell |
| 40 | +$ ./allocs/deploy.sh $RPC_URL $PRIVATE_KEY |
| 41 | +``` |
| 42 | + |
| 43 | +### Generate Alloc |
| 44 | + |
| 45 | +This script will read from the outputs generated by the deploy script, then use `cast code` and `heimdall dump` to generate a complete `alloc` JSON: |
| 46 | + |
| 47 | +```shell |
| 48 | +$ ./allocs/generate-alloc.sh $ARCHIVE_RPC_URL |
| 49 | +``` |
| 50 | + |
| 51 | +NOTE: You MUST provide an archive RPC endpoint that supports `trace_replayBlockTransactions`, as `heimdall dump` relies on this endpoint. Unfortuntately, at the time of writing, `anvil` does not support this endpoint. |
| 52 | + |
| 53 | +### Check Alloc |
| 54 | + |
| 55 | +If you have an `alloc` JSON and you wish to check the storage slots against a deployed chain, you can run the following script: |
| 56 | +```shell |
| 57 | +$ ./allocs/check-alloc.sh $RPC_URL |
| 58 | +``` |
| 59 | +Note that a non-archive RPC endpoint is fine for this command. |
0 commit comments