From f2dbec818d88d46d7f1bf74be62665b66b86fa13 Mon Sep 17 00:00:00 2001 From: erhant Date: Mon, 23 Dec 2024 23:03:37 +0300 Subject: [PATCH] more doc rfks, added upgrade docs --- .vscode/settings.json | 9 ++- README.md | 70 ++++++++++---------- abis/parseAbi.cjs | 24 ------- deployment/README.md | 1 - {deployment => deployments}/.gitignore | 0 {deployment => deployments}/84532.json | 2 +- {abis => deployments/abis}/Swan.json | 2 +- {abis => deployments/abis}/SwanAgent.json | 2 +- {abis => deployments/abis}/SwanArtifact.json | 2 +- export-abis.sh | 11 --- foundry.toml | 2 +- lib/dria-oracle-contracts | 2 +- lib/forge-std | 2 +- script/HelperConfig.s.sol | 8 +-- storage.sh | 22 ------ 15 files changed, 54 insertions(+), 105 deletions(-) delete mode 100644 abis/parseAbi.cjs delete mode 100644 deployment/README.md rename {deployment => deployments}/.gitignore (100%) rename {deployment => deployments}/84532.json (90%) rename {abis => deployments/abis}/Swan.json (99%) rename {abis => deployments/abis}/SwanAgent.json (99%) rename {abis => deployments/abis}/SwanArtifact.json (99%) delete mode 100755 export-abis.sh delete mode 100755 storage.sh diff --git a/.vscode/settings.json b/.vscode/settings.json index 07e8ca4..9989531 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,12 @@ }, "solidity.formatter": "forge", "solidity.compileUsingRemoteVersion": "v0.8.26", - "solidity.defaultCompiler": "localFile" + "solidity.defaultCompiler": "localFile", + "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/", + "@firstbatch/dria-oracle-contracts/=lib/dria-oracle-contracts/src/" + ] } diff --git a/README.md b/README.md index 7ea3d3b..9b5d1f4 100644 --- a/README.md +++ b/README.md @@ -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: @@ -116,9 +116,23 @@ forge script ./script/Deploy.s.sol:Deploy \ --broadcast ``` -You can see deployed contract addresses under the `deployment/.json` +You can see deployed contract addresses under the [`deployments/.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 abi > ./deployments/abis/.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 \ @@ -129,39 +143,35 @@ forge script ./script/Deploy.s.sol:Deploy \ --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 ./src/.sol: \ ---verifier blockscout \ ---verifier-url +--verifier blockscout --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. +### Upgrade Contract -### Generate ABIs +Upgrading an existing contract is done as per the instructions in [openzeppelin-foundry-upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) repository. -To interact with the contracts, you need the contract ABIs. We store the ABIs under the [`abis`](./abis/) folder, and these can be generated using the following script: +First, we create a new contract with its name as `ContractNameV2`, and then we execute the following command: ```sh -./export-abis.sh +forge script ./script/Deploy.s.sol:Upgrade \ +--rpc-url \ +--account --broadcast \ +--sender \ +--verify --verifier blockscout \ +--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. -The `--sender
` field is required when deploying a contract, +> [!NOTE] +> +> The `--sender
` field is mandatory when deploying a contract, it can be obtained with the command below, which will prompt for keystore password: +> +> ```sh +> cast wallet address --account +> ``` ## Testing & Diagnostics @@ -194,16 +204,6 @@ Alternatively, you can see a summarized text-only output as well: forge coverage --no-match-coverage "(test|mock|script)" ``` -### Storage Layout - -You can print storage layouts for each contract using: - -```sh -./storage.sh -``` - -The resulting Markdown files will be created under the [`storage`](./storage/) directory. - ### Gas Snapshot You can examine the gas usage metrics using the command: diff --git a/abis/parseAbi.cjs b/abis/parseAbi.cjs deleted file mode 100644 index 7c0de5e..0000000 --- a/abis/parseAbi.cjs +++ /dev/null @@ -1,24 +0,0 @@ -const fs = require("fs"); - -if (process.argv.length < 3) { - console.error("Please provide a filename as a parameter."); - process.exit(1); -} - -const filename = process.argv[2]; - -const data = fs.readFileSync(filename, "utf8"); -try { - const jsonData = JSON.parse(data); - const abi = jsonData.abi; - if (!abi) { - console.error("No `abi` field found in the JSON data."); - process.exit(1); - } - - fs.writeFileSync(filename, JSON.stringify(abi, null, 2)); - console.log("ABI extracted and written to", filename); -} catch (parseErr) { - console.error(`Error parsing JSON: ${parseErr}`); - process.exit(1); -} diff --git a/deployment/README.md b/deployment/README.md deleted file mode 100644 index 1f5296f..0000000 --- a/deployment/README.md +++ /dev/null @@ -1 +0,0 @@ -# Deployment Commands diff --git a/deployment/.gitignore b/deployments/.gitignore similarity index 100% rename from deployment/.gitignore rename to deployments/.gitignore diff --git a/deployment/84532.json b/deployments/84532.json similarity index 90% rename from deployment/84532.json rename to deployments/84532.json index dc1123a..7dbb460 100644 --- a/deployment/84532.json +++ b/deployments/84532.json @@ -15,6 +15,6 @@ "addr": "0x348102400779c4c8f50ee9ad356c5fd8a9803795" }, "SwanArtifactFactory": { - "addr": "0x1a69a6c3c930c381b23abe555081437815876974" + "addr": "0x780384662fe6ee8ad1f75063b8ea0e03fa76f9d8" } } \ No newline at end of file diff --git a/abis/Swan.json b/deployments/abis/Swan.json similarity index 99% rename from abis/Swan.json rename to deployments/abis/Swan.json index 49f865f..5f12756 100644 --- a/abis/Swan.json +++ b/deployments/abis/Swan.json @@ -1123,4 +1123,4 @@ } ] } -] \ No newline at end of file +] diff --git a/abis/SwanAgent.json b/deployments/abis/SwanAgent.json similarity index 99% rename from abis/SwanAgent.json rename to deployments/abis/SwanAgent.json index 2524a2a..9c031f5 100644 --- a/abis/SwanAgent.json +++ b/deployments/abis/SwanAgent.json @@ -621,4 +621,4 @@ } ] } -] \ No newline at end of file +] diff --git a/abis/SwanArtifact.json b/deployments/abis/SwanArtifact.json similarity index 99% rename from abis/SwanArtifact.json rename to deployments/abis/SwanArtifact.json index b94e0d5..aeb4bed 100644 --- a/abis/SwanArtifact.json +++ b/deployments/abis/SwanArtifact.json @@ -563,4 +563,4 @@ } ] } -] \ No newline at end of file +] diff --git a/export-abis.sh b/export-abis.sh deleted file mode 100755 index 84db968..0000000 --- a/export-abis.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -forge compile - -cp ./out/Swan.sol/Swan.json ./abis/Swan.json -node ./abis/parseAbi.cjs ./abis/Swan.json - -cp ./out/SwanAgent.sol/SwanAgent.json ./abis/SwanAgent.json -node ./abis/parseAbi.cjs ./abis/SwanAgent.json - -cp ./out/SwanArtifact.sol/SwanArtifact.json ./abis/SwanArtifact.json -node ./abis/parseAbi.cjs ./abis/SwanArtifact.json diff --git a/foundry.toml b/foundry.toml index 2721f6b..1843540 100644 --- a/foundry.toml +++ b/foundry.toml @@ -19,7 +19,7 @@ force = true # fs permissions for deployment (false by default) fs_permissions = [ { access = "read", path = "out" }, - { access = "read-write", path = "deployment" }, + { access = "read-write", path = "deployments" }, ] # fuzzing options diff --git a/lib/dria-oracle-contracts b/lib/dria-oracle-contracts index b585866..b804b82 160000 --- a/lib/dria-oracle-contracts +++ b/lib/dria-oracle-contracts @@ -1 +1 @@ -Subproject commit b58586687c5321c5e6773f5e0fe8160687eba779 +Subproject commit b804b823a3afd04fc46ea474f753026e28fc8ad0 diff --git a/lib/forge-std b/lib/forge-std index 5f1b1c6..b93cf4b 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 5f1b1c6f607c34c76d5cefa33b41337b0d4699b4 +Subproject commit b93cf4bc34ff214c099dc970b153f85ade8c9f66 diff --git a/script/HelperConfig.s.sol b/script/HelperConfig.s.sol index bfef490..2d672ee 100644 --- a/script/HelperConfig.s.sol +++ b/script/HelperConfig.s.sol @@ -83,7 +83,7 @@ contract HelperConfig is Script { function deployLLMOracleCoordinator() external returns (address proxy, address impl) { // get the registry proxy address from chainid.json file under the deployment dir - string memory dir = "deployment/"; + string memory dir = "deployments/"; string memory fileName = Strings.toString(block.chainid); string memory path = string.concat(dir, fileName, ".json"); @@ -145,7 +145,7 @@ contract HelperConfig is Script { function deploySwan() external returns (address proxy, address impl) { // read deployed contract addresses - string memory dir = "deployment/"; + string memory dir = "deployments/"; string memory fileName = Strings.toString(block.chainid); string memory path = string.concat(dir, fileName, ".json"); @@ -199,7 +199,7 @@ contract HelperConfig is Script { function writeContractAddress(string memory name, address addr) internal { // create a deployment file if not exist - string memory dir = "deployment/"; + string memory dir = "deployments/"; string memory fileName = Strings.toString(block.chainid); string memory path = string.concat(dir, fileName, ".json"); @@ -242,7 +242,7 @@ contract HelperConfig is Script { function writeProxyAddresses(string memory name, address proxy, address impl) internal { // create a deployment file if not exist - string memory dir = "deployment/"; + string memory dir = "deployments/"; string memory fileName = Strings.toString(block.chainid); string memory path = string.concat(dir, fileName, ".json"); diff --git a/storage.sh b/storage.sh deleted file mode 100755 index 2637c5b..0000000 --- a/storage.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -OUTPUT_PATH=${1:-storage} -EXCLUDE="test|mock|script|" - -# FIXME: what does IFS do here? -IFS=$'\n' -CONTRACT_FILES=($(find ./src -type f)) -unset IFS - -echo "Outputting storage layouts to: $OUTPUT_PATH" -mkdir -p $OUTPUT_PATH - -for file in "${CONTRACT_FILES[@]}"; -do - if [[ $file =~ .*($EXCLUDE).* ]]; then - continue - fi - - contract=$(basename "$file" .sol) - echo "Generating storage layout for: $contract" - forge inspect "$contract" storage --pretty > "$OUTPUT_PATH/$contract.md" -done