Skip to content

Commit

Permalink
better abi export, added upgrade docs
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Dec 23, 2024
1 parent 45b119b commit 9576190
Show file tree
Hide file tree
Showing 15 changed files with 1,940 additions and 1,936 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
"editor.defaultFormatter": "JuanBlanco.solidity"
},
"solidity.formatter": "forge",
"solidity.compileUsingRemoteVersion": "v0.8.26",
"solidity.defaultCompiler": "localFile",
// remappings.txt here fixes random errors
"solidity.remappingsUnix": [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/"
],
"material-icon-theme.files.associations": {
".gas-snapshot": "bench-ts"
}
Expand Down
62 changes: 29 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ To interact with the blockchain, we require an RPC endpoint. You can get one fro

You will use this endpoint for the commands that interact with the blockchain, such as deploying and upgrading; or while doing fork tests.

### Deploy & Verify Contract
### Deploy Contract

Deploy the contract with:

Expand All @@ -116,9 +116,23 @@ forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
--broadcast
```

You can see deployed contract addresses under the [`deployments/<chainid>.json`](./deployments/)
You can see deployed contract addresses under the [`deployments/<chainid>.json`](./deployments/) folder.

You can verify the contract during deployment by adding the verification arguments as well:
You will need the contract ABIs to interact with them as well, thankfully there is a nice short-hand command to export that:

```sh
forge inspect <CONTRACT_NAME> abi > ./deployments/abis/<CONTRACT_NAME>.json
```

### Verify Contract

Verification requires the following values, based on which provider you are using:

- **Provider**: can accept any of `etherscan`, `blockscout`, `sourcify`, `oklink` or `custom` for more fine-grained stuff.
- **URL**: based on the chosen provider, we require its URL as well, e.g. `https://base-sepolia.blockscout.com/api/` for `blockscout` on Base Sepolia
- **API Key**: an API key from the chosen provider, must be stored as `ETHERSCAN_API_KEY` in environment no matter whicih provider it is!.

You can actually verify the contract during deployment by adding the verification arguments as well:

```sh
forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
Expand All @@ -129,51 +143,33 @@ forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
--verifier-url <VERIFIER_URL>
```

You can verify an existing contract with:
Alternatively, you can verify an existing contract (perhaps deployed from a factory) with:

```sh
forge verify-contract <CONTRACT_ADDRESS> ./src/<CONTRACT_NAME>.sol:<CONTRACT_NAME> \
--verifier blockscout \
--verifier-url <VERIFIER_URL>
--verifier blockscout --verifier-url <VERIFIER_URL>
```

Note that the `--verifier-url` value should be the target explorer's homepage URL. Some example URLs are:

- `https://base.blockscout.com/api/` for Base (Mainnet)
- `https://base-sepolia.blockscout.com/api/` for Base Sepolia (Testnet)

> [!NOTE]
>
> URL should not contain the API key! Foundry will read your `ETHERSCAN_API_KEY` from environment.
> [!NOTE]
>
> The `--verifier` can accept any of the following: `etherscan`, `blockscout`, `sourcify`, `oklink`. We are using Blockscout most of the time.
After deployment, we need to take care of two things:
### Upgrade Contract

- **ABIs**: to interact with the contracts
- **Artifacts**: required if we need to upgrade in future
Upgrading an existing contract is done as per the instructions in [openzeppelin-foundry-upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) repository.

We have a post-deployment script that outputs these files under the [`deployments/abis`](./deployments/abis/) folder:
First, we create a new contract with its name as `ContractNameV2`, and then we execute the following command:

```sh
# requires NodeJS
./post-deploy.sh
forge script ./script/Deploy.s.sol:Upgrade<CONTRACT_NAME> \
--rpc-url <RPC_URL> \
--account <WALLET_NAME> --broadcast \
--sender <WALLET_ADDRESS> \
--verify --verifier blockscout \
--verifier-url <VERIFIER_URL>
```

### Upgrade Contract

Upgrading an existing contract is done as per the instructions in [openzeppelin-foundry-upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) repository.

To upgrade, you must

> [!NOTE]
>
> The `--sender <ADDRESS>` field is mandatory when deploying a contract, it can be obtained with:
> The `--sender <ADDRESS>` field is mandatory when deploying a contract, it can be obtained with the command below, which will prompt for keystore password:
>
> ```sh
> # will prompt for password
> cast wallet address --account <WALLET_NAME>
> ```
Expand Down
136 changes: 68 additions & 68 deletions broadcast/Deploy.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31337.json
31337/
Loading

0 comments on commit 9576190

Please sign in to comment.