Skip to content

Commit

Permalink
docs+script: Update to create based deployment instead of Greenhouse …
Browse files Browse the repository at this point in the history
…factory
  • Loading branch information
pmerkleplant committed Jul 24, 2024
1 parent b041b8a commit aca1ad8
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 83 deletions.
21 changes: 14 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Wallet Management
export PRIVATE_KEY=
export KEYSTORE=
export KEYSTORE_PASSWORD=""

# RPC URL
export RPC_URL=
Expand All @@ -9,15 +10,21 @@ export ETHERSCAN_API_URL=
export ETHERSCAN_API_KEY=

# Deployment Configurations
export GREENHOUSE=
export SALT=
export INITIAL_AUTHED=

# Management Configurations
export AGGOR=
export BUD=
export CHRONICLE=
export CHAINLINK=
export UNISWAP_POOL=
export UNISWAP_BASE_TOKEN=
export UNISWAP_QUOTE_TOKEN=
export UNISWAP_BASE_TOKEN_DECIMALS=
export UNISWAP_LOOKBACK=
## IAggor::setAgreementDistance
export AGREEMENT_DISTANCE=
## IAggor::setAgeThreshold
export AGE_THRESHOLD=
## IAuth::{rely,deny}, IToll::{kiss,diss}

# Management Configurations
export AGGOR=
## IAuth::{rely,deny}
export WHO=
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
path = lib/chronicle-std
url = https://github.com/chronicleprotocol/chronicle-std
branch = v2
[submodule "lib/greenhouse"]
path = lib/greenhouse
url = https://github.com/chronicleprotocol/greenhouse
branch = v1
[submodule "lib/uniswap/v3-periphery"]
path = lib/uniswap/v3-periphery
url = https://github.com/Uniswap/v3-periphery.git
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ $ forge fmt [--check]
- [chronicleprotocol/chronicle-std@v2](https://github.com/chronicleprotocol/chronicle-std/tree/v2)
- [uniswap/[email protected]](https://github.com/Uniswap/v3-periphery/tree/0.8)
- [uniswap/[email protected]](https://github.com/Uniswap/v3-core/tree/0.8)

Deployment via:

- [chronicleprotocol/greenhouse@v1](https://github.com/chronicleprotocol/greenhouse/tree/v1)
44 changes: 21 additions & 23 deletions docs/Deployment.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
# Deployment

This document describes how to deploy a new `Aggor` instance via _Chronicle Protocol_'s [`Greenhouse`](https://github.com/chronicleprotocol/greenhouse) contract factory.
This document describes how to deploy a new `Aggor` instance.

## Environment Variables

The following environment variables must be set:

- `RPC_URL`: The RPC URL of an EVM node
- `PRIVATE_KEY`: The private key to use
- `KEYSTORE`: The path to the keystore file containing the encrypted private key
- Note that password can either be entered on request or set via the `KEYSTORE_PASSWORD` environment variable
- `KEYSTORE_PASSWORD`: The password for the keystore file
- `ETHERSCAN_API_URL`: The Etherscan API URL for the Etherscan's chain instance
- Note that the API endpoint varies per Etherscan chain instance
- Note to point to actual API endpoint (e.g. `/api`) and not just host
- `ETHERSCAN_API_KEY`: The Etherscan API key for the Etherscan's chain instance
- `GREENHOUSE`: The `Greenhouse` instance to use for deployment
- `SALT`: The salt to deploy the `Aggor` instance to
- Note to use the salt's string representation
- Note that the salt must not exceed 32 bytes in length
- Note that the salt should match the name of the contract deployed!
- `INITIAL_AUTHED`: The address being auth'ed on the newly deployed `Aggor` instance

Note that an `.env.example` file is provided in the project root. To set all environment variables at once, create a copy of the file and rename the copy to `.env`, adjust the variables' values, and run `source .env`.

To easily check the environment variables, run:

```bash
$ env | grep -e "RPC_URL" -e "PRIVATE_KEY" -e "ETHERSCAN_API_URL" -e "ETHERSCAN_API_KEY" -e "GREENHOUSE" -e "SALT" -e "INITIAL_AUTHED"
$ env | grep -e "RPC_URL" -e "KEYSTORE" -e "KEYSTORE_PASSWORD" -e "ETHERSCAN_API_URL" -e "ETHERSCAN_API_KEY" -e "INITIAL_AUTHED"
```

## Configuration Setting

The following variables inside `script/Aggor.s.sol` need to be set:
- `bud`: The address allowed to read Aggor
- `chronicle`: The Chronicle oracle
- `chainlink`: The Chainlink oracle
- `uniswapPool`: The Uniswap pool to use as TWAP
- `uniswapBaseToken`: The Uniswap pool's base token
- `uniswapQuoteToken`: The Uniswap pool's quote token
- `uniswapBaseTokenDecimals`: The Uniswap pool's base token's decimals
- `uniswapLookback`: The TWAP lookback argument in seconds
- `agreementDistance`: The agreement distance in WAD
- `ageThreshold`: The age staleness threshold in seconds
The following additional environment variables must be set:

- `BUD`: The address allowed to read Aggor
- `CHRONICLE`: The Chronicle oracle
- `CHAINLINK`: The Chainlink oracle
- `UNISWAP_POOL`: The Uniswap pool to use as TWAP
- `UNISWAP_BASE_TOKEN`: The Uniswap pool's base token
- `UNISWAP_QUOTE_TOKEN`: The Uniswap pool's quote token
- `UNISWAP_BASE_TOKEN_DECIMALS`: The Uniswap pool's base token's decimals
- `UNISWAP_LOOKBACK`: The TWAP lookback argument in seconds
- `AGREEMENT_DISTANCE`: The agreement distance in WAD
- `AGE_THRESHOLD`: The age staleness threshold in seconds

## Code Adjustments

Expand All @@ -55,12 +53,12 @@ The deployment process consists of two steps - the actual deployment and the sub
Deployment:

```bash
$ SALT_BYTES32=$(cast format-bytes32-string $SALT) && \
forge script \
--private-key "$PRIVATE_KEY" \
$ forge script \
--keystore "$KEYSTORE" \
--password "$KEYSTORE_PASSWORD" \
--broadcast \
--rpc-url "$RPC_URL" \
--sig "$(cast calldata "deploy(address,bytes32,address)" "$GREENHOUSE" "$SALT_BYTES32" "$INITIAL_AUTHED")" \
--sig "$(cast calldata "deploy(address,address,address,address,address,address,address,uint8,uint32,uint128,uint32)" "$INITIAL_AUTHED" "$BUD" "$CHRONICLE" "$CHAINLINK" "$UNISWAP_POOL" "$UNISWAP_BASE_TOKEN" "$UNISWAP_QUOTE_TOKEN" "$UNISWAP_BASE_TOKEN_DECIMALS" "$UNISWAP_LOOKBACK" "$AGREEMENT_DISTANCE" "$AGE_THRESHOLD")" \
-vvv \
script/Aggor.s.sol:AggorScript
```
Expand Down
1 change: 0 additions & 1 deletion lib/greenhouse
Submodule greenhouse deleted from 88d3ef
3 changes: 0 additions & 3 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/

chronicle-std/=lib/chronicle-std/src/

greenhouse/=lib/greenhouse/src

58 changes: 18 additions & 40 deletions script/Aggor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {console2 as console} from "forge-std/console2.sol";

import {IAuth} from "chronicle-std/auth/IAuth.sol";

import {IGreenhouse} from "greenhouse/IGreenhouse.sol";

import {IAggor} from "src/IAggor.sol";
import {Aggor_BASE_QUOTE_COUNTER as Aggor} from "src/Aggor.sol";
// @todo ^^^^ ^^^^^ ^^^^^^^ Adjust name of Aggor instance
Expand All @@ -16,36 +14,24 @@ import {Aggor_BASE_QUOTE_COUNTER as Aggor} from "src/Aggor.sol";
* @notice Aggor Management Script
*/
contract AggorScript is Script {
// -- Deployment Configuration --

// -- Immutable

address bud;
address chronicle;
address chainlink;
address uniswapPool;
address uniswapBaseToken;
address uniswapQuoteToken;
uint8 uniswapBaseTokenDecimals;
uint32 uniswapLookback;

// -- Mutable

uint128 agreementDistance;
uint32 ageThreshold;

// -- Deployment Function --

/// @dev Deploys a new Aggor instance via Greenhouse instance
/// `greenhouse` and salt `salt` with `initialAuthed` being the
/// address initially auth'ed.
function deploy(address greenhouse, bytes32 salt, address initialAuthed)
public
{
// Create creation code with constructor arguments.
bytes memory creationCode = abi.encodePacked(
type(Aggor).creationCode,
abi.encode(
/// @dev Deploys a new Aggor instance with `initialAuthed` being the address
/// initially auth'ed.
function deploy(
address initialAuthed,
address bud,
address chronicle,
address chainlink,
address uniswapPool,
address uniswapBaseToken,
address uniswapQuoteToken,
uint8 uniswapBaseTokenDecimals,
uint32 uniswapLookback,
uint128 agreementDistance,
uint32 ageThreshold
) public {
vm.startBroadcast();
address deployed = address(
new Aggor(
initialAuthed,
bud,
chronicle,
Expand All @@ -59,14 +45,6 @@ contract AggorScript is Script {
ageThreshold
)
);

// Ensure salt not yet used.
address deployed = IGreenhouse(greenhouse).addressOf(salt);
require(deployed.code.length == 0, "Salt already used");

// Plant creation code via greenhouse.
vm.startBroadcast();
IGreenhouse(greenhouse).plant(salt, creationCode);
vm.stopBroadcast();

console.log("Deployed at", deployed);
Expand Down
1 change: 0 additions & 1 deletion slither.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"filter_paths": "lib,test,script",
"solc_remaps": [
"chronicle-std/=lib/chronicle-std/src",
"greenhouse/=lib/greenhouse/src",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/"
]
Expand Down

0 comments on commit aca1ad8

Please sign in to comment.