Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor hardcoded variables to .env files #83

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# These default values work for devnet deployment only

AGGREGATOR_ECDSA_PRIV_KEY=0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
CHALLENGER_ECDSA_PRIV_KEY=0x5de4111afa1a4b94908f83103eb1f17

CHAINID=31337
# Make sure to update this if the strategy address changes
# check in contracts/script/output/${CHAINID}/credible_squaring_avs_deployment_output.json
STRATEGY_ADDRESS=0x7a2088a1bFc9d81c55368AE168C2C02570cB814F

7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

AGGREGATOR_ECDSA_PRIV_KEY=0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
CHALLENGER_ECDSA_PRIV_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
include .env
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, also, the .env file is not in the root of the repository so nothing would be included


CHAINID=31337
# Make sure to update this if the strategy address changes
# check in contracts/script/output/${CHAINID}/credible_squaring_avs_deployment_output.json
STRATEGY_ADDRESS=0x7a2088a1bFc9d81c55368AE168C2C02570cB814F
DEPLOYMENT_FILES_DIR=contracts/script/output/${CHAINID}

-----------------------------: ##
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

Basic repo demoing a simple AVS middleware with full eigenlayer integration. See this [video walkthrough](https://www.loom.com/share/50314b3ec0f34e2ba386d45724602d76?sid=9d68d8cb-d2d5-4123-bd06-776de2076de0).

## Set environment variables

```
cp .env.template .env
cp contracts/.env.template contracts/.env
```
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be copied to contracts/.env in the Makefile, so the user doesn't have to do it manually

The .env templates provide default values for devnet development, you should modify them for testnet deployment.

## Dependencies

You will need [foundry](https://book.getfoundry.sh/getting-started/installation) and [zap-pretty](https://github.com/maoueh/zap-pretty) and docker to run the examples below.
Expand All @@ -19,6 +27,7 @@ You will also need to [install docker](https://docs.docker.com/get-docker/), and
make build-contracts
```


## Running via make

This simple session illustrates the basic flow of the AVS. The makefile commands are hardcoded for a single operator, but it's however easy to create new operator config files, and start more operators manually (see the actual commands that the makefile calls).
Expand Down Expand Up @@ -114,4 +123,4 @@ When running on anvil, a typical log for the operator is
[2024-04-09 18:25:10.679 PDT] INFO (logging/zap_logger.go:49) Signed task response header accepted by aggregator. {"reply":false}
```

The error `task 2 not initialized or already completed` is expected behavior. This is because the aggregator needs to setup its data structures before it can accept responses. But on a local anvil setup, the operator had time to receive the websocket event for the new task, square the number, sign the response, and send it to the aggregator process before the aggregator has finalized its setup. Hence, the operator retries sending the response 2 seconds later and it is accepted.
The error `task 2 not initialized or already completed` is expected behavior. This is because the aggregator needs to setup its data structures before it can accept responses. But on a local anvil setup, the operator had time to receive the websocket event for the new task, square the number, sign the response, and send it to the aggregator process before the aggregator has finalized its setup. Hence, the operator retries sending the response 2 seconds later and it is accepted.
3 changes: 3 additions & 0 deletions contracts/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AGGREGATOR_ADDR=0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
TASK_GENERATOR_ADDR=0xa0Ee7A142d267C1f36714E4a8F75612F20a79720

17 changes: 8 additions & 9 deletions contracts/script/IncredibleSquaringDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@ import "forge-std/StdJson.sol";
import "forge-std/console.sol";

// # To deploy and verify our contract
// forge script script/CredibleSquaringDeployer.s.sol:CredibleSquaringDeployer --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vvvv
// forge script script/IncredibleSquaringDeployer.s.sol:IncredibleSquaringDeployer --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $AGGREGATOR_ADDR $TASK_GENERATOR_ADDR --broadcast -vvvv
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// forge script script/IncredibleSquaringDeployer.s.sol:IncredibleSquaringDeployer --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $AGGREGATOR_ADDR $TASK_GENERATOR_ADDR --broadcast -vvvv
// forge script script/IncredibleSquaringDeployer.s.sol:IncredibleSquaringDeployer --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vvvv

Th constructor-args are not necessary

contract IncredibleSquaringDeployer is Script, Utils {
// DEPLOYMENT CONSTANTS
uint256 public constant QUORUM_THRESHOLD_PERCENTAGE = 100;
uint32 public constant TASK_RESPONSE_WINDOW_BLOCK = 30;
uint32 public constant TASK_DURATION_BLOCKS = 0;
// TODO: right now hardcoding these (this address is anvil's default address 9)
address public constant AGGREGATOR_ADDR =
0xa0Ee7A142d267C1f36714E4a8F75612F20a79720;
address public constant TASK_GENERATOR_ADDR =
0xa0Ee7A142d267C1f36714E4a8F75612F20a79720;

// ERC20 and Strategy: we need to deploy this erc20, create a strategy for it, and whitelist this strategy in the strategymanager

ERC20Mock public erc20Mock;
Expand Down Expand Up @@ -73,7 +67,12 @@ contract IncredibleSquaringDeployer is Script, Utils {
IIncredibleSquaringTaskManager
public incredibleSquaringTaskManagerImplementation;

address public aggregatorAddr;
address public taskGeneratorAddr;

function run() external {
aggregatorAddr = vm.envAddress("AGGREGATOR_ADDR");
taskGeneratorAddr = vm.envAddress("TASK_GENERATOR_ADDR");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetching of the environment variables should go in a setUp() function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    function setUp() public virtual {
        aggregatorAddress = vm.envAddress("AGGREGATOR_ADDRESS");
        taskGeneratorAddress = vm.envAddress("TASK_GENERATOR_ADDRESS");
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, can we also move reading the json into the setup function and make the Eigenlayer contracts state variables of the script contract

// Eigenlayer contracts
string memory eigenlayerDeployedContracts = readOutput(
"eigenlayer_deployment_output"
Expand Down Expand Up @@ -387,8 +386,8 @@ contract IncredibleSquaringDeployer is Script, Utils {
incredibleSquaringTaskManager.initialize.selector,
incredibleSquaringPauserReg,
incredibleSquaringCommunityMultisig,
AGGREGATOR_ADDR,
TASK_GENERATOR_ADDR
aggregatorAddr,
taskGeneratorAddr
)
);

Expand Down