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

rewards v2 #165

Draft
wants to merge 4 commits into
base: main
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ start-anvil-chain-with-contracts-deployed: ##
deploy-contracts-to-anvil-and-save-state: ##
./crates/contracts/anvil/deploy-contracts-save-anvil-state.sh

deploy-eigenlayer:
./crates/contracts/anvil/deploy-eigenlayer.sh

deploy-avs:
chmod +x ./crates/contracts/anvil/deploy-avs.sh
./crates/contracts/anvil/deploy-avs.sh

dump-state:
chmod +x ./crates/contracts/anvil/dump-state.sh
./crates/contracts/anvil/dump-state.sh

__TESTING__: ##

reset-anvil:
Expand Down
29 changes: 15 additions & 14 deletions crates/chainio/clients/avsregistry/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ impl AvsRegistryChainWriter {
.sign_hash(&msg_to_sign)
.await
.map_err(|_| AvsRegistryError::InvalidSignature)?;

let operator_signature_with_salt_and_expiry = SignatureWithSaltAndExpiry {
signature: operator_signature.as_bytes().into(),
salt: operator_to_avs_registration_sig_salt,
Expand Down Expand Up @@ -220,7 +219,6 @@ impl AvsRegistryChainWriter {
.send()
.await
.map_err(AvsRegistryError::AlloyContractError)?;

info!(tx_hash = ?tx,"Sent transaction to register operator in the AVS's registry coordinator" );
Ok(*tx.tx_hash())
}
Expand Down Expand Up @@ -330,6 +328,8 @@ impl AvsRegistryChainWriter {
#[cfg(test)]
mod tests {
use super::AvsRegistryChainWriter;
use alloy::providers::{Provider, ProviderBuilder};
use alloy::transports::http::reqwest::Url;
use alloy_primitives::{Address, Bytes, FixedBytes, U256};
use eigen_crypto_bls::BlsKeyPair;
use eigen_logging::get_test_logger;
Expand Down Expand Up @@ -380,16 +380,16 @@ mod tests {
http_endpoint.clone(),
)
.await;
test_update_stake_of_operator_subset(&avs_writer, operator_addr, http_endpoint.clone())
.await;
test_update_stake_of_entire_operator_set(
&avs_writer,
operator_addr,
quorum_nums.clone(),
http_endpoint.clone(),
)
.await;
test_deregister_operator(&avs_writer, quorum_nums, http_endpoint).await;
// test_update_stake_of_operator_subset(&avs_writer, operator_addr, http_endpoint.clone())
// .await;
// test_update_stake_of_entire_operator_set(
// &avs_writer,
// operator_addr,
// quorum_nums.clone(),
// http_endpoint.clone(),
// )
// .await;
// test_deregister_operator(&avs_writer, quorum_nums, http_endpoint).await;
}

// this function is caller from test_avs_writer_methods
Expand Down Expand Up @@ -435,6 +435,7 @@ mod tests {

// this is set to U256::MAX so that the registry does not take the signature as expired.
let signature_expiry = U256::MAX;
let url = Url::from_str(&http_url).unwrap();
let tx_hash = avs_writer
.register_operator_in_quorum_with_avs_registry_coordinator(
bls_key_pair,
Expand All @@ -444,8 +445,8 @@ mod tests {
"".into(),
)
.await
.unwrap();

.expect("regg");
println!("tx_hash{:?}", tx_hash);
let tx_status = wait_transaction(&http_url, tx_hash).await.unwrap().status();
assert!(tx_status);
}
Expand Down
1 change: 1 addition & 0 deletions crates/chainio/txmanager/src/geometric_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ mod tests {
}

#[tokio::test]
#[ignore]
async fn test_send_single_transaction() {
// Send transaction using Alloy RootProvider
let (_container, rpc_url, _ws_endpoint) = start_anvil_container().await;
Expand Down
2 changes: 2 additions & 0 deletions crates/chainio/txmanager/src/simple_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ mod tests {
use tokio;

#[tokio::test]
#[ignore]
async fn test_send_transaction_from_legacy() {
let (_container, rpc_url, _ws_endpoint) = start_anvil_container().await;
let logger = get_test_logger();
Expand Down Expand Up @@ -311,6 +312,7 @@ mod tests {
}

#[tokio::test]
#[ignore]
async fn test_send_transaction_from_eip1559() {
let (_container, rpc_url, _ws_endpoint) = start_anvil_container().await;
let logger = get_test_logger();
Expand Down
2 changes: 2 additions & 0 deletions crates/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
CONTRACTS_REGISTRY_ADDR=0x5FbDB2315678afecb367f032d93F642f64180aa3

This file was deleted.

19 changes: 19 additions & 0 deletions crates/contracts/anvil/deploy-avs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

RPC_URL=http://localhost:8545
DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

# cd to the directory of this script so that this can be run from anywhere
parent_path=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)
cd "$parent_path"

cd ../
forge script script/DeployMockAvs.s.sol --rpc-url $RPC_URL --private-key $DEPLOYER_PRIVATE_KEY --broadcast --slow -vvv

forge script script/ContractsRegistry.s.sol --rpc-url $RPC_URL --private-key $DEPLOYER_PRIVATE_KEY --broadcast --slow


# forge script script/SetupPayments.s.sol --rpc-url $RPC_URL --broadcast --slow --private-key $PRIVATE_KEY
15 changes: 15 additions & 0 deletions crates/contracts/anvil/deploy-eigenlayer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

RPC_URL=http://localhost:8545
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

# Navigate to the script directory
parent_path=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
cd "$parent_path"

root_dir=$(realpath "$parent_path/../..")

# Deploy Contracts
cd "$root_dir/contracts"
forge create src/ContractsRegistry.sol:ContractsRegistry --rpc-url $RPC_URL --private-key $PRIVATE_KEY
forge script script/DeployEigenLayerCore.s.sol:DeployEigenlayerCore --rpc-url $RPC_URL --broadcast --slow
37 changes: 37 additions & 0 deletions crates/contracts/anvil/dump-state.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Enable the script to exit immediately if a command exits with a non-zero status
set -o errexit -o nounset -o pipefail

# Define your cleanup function
clean_up() {
echo "Executing cleanup function..."
set +e
pkill -f anvil

# Check if the exit status is non-zero
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "Script exited due to set -e on line $1 with command '$2'. Exit status: $exit_status"
fi
}
# Use trap to call the clean_up function when the script exits
trap 'clean_up $LINENO "$BASH_COMMAND"' EXIT

# cd to the directory of this script so that this can be run from anywhere
anvil_dir=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)
root_dir=$(realpath $anvil_dir/../..)

set -a
source $anvil_dir/utils.sh
# we overwrite some variables here because should always deploy to anvil (localhost)
ETH_HTTP_URL=http://localhost:8545
DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
set +a

# start an empty anvil chain in the background and dump its state to a json file upon exit
start_anvil_docker "" $anvil_dir/dump_state.json
sleep 1
1 change: 1 addition & 0 deletions crates/contracts/anvil/dump_state.json/state.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/contracts/anvil/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# pinning at old foundry commit because of https://github.com/foundry-rs/foundry/issues/7502
FOUNDRY_IMAGE=ghcr.io/foundry-rs/foundry:nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a
FOUNDRY_IMAGE=ghcr.io/foundry-rs/foundry:latest

set -e -o nounset

Expand Down Expand Up @@ -32,7 +32,7 @@ start_anvil_docker() {
DUMP_STATE_ANVIL_ARG=$([[ -z $DUMP_STATE_FILE ]] && echo "" || echo "--dump-state /dump-state.json")

trap 'docker stop anvil 2>/dev/null || true' EXIT
docker run -d --name anvil -p 8545:8545 $LOAD_STATE_VOLUME_DOCKER_ARG $DUMP_STATE_VOLUME_DOCKER_ARG \
docker run --name anvil -p 8545:8545 $LOAD_STATE_VOLUME_DOCKER_ARG $DUMP_STATE_VOLUME_DOCKER_ARG \
--entrypoint anvil \
$FOUNDRY_IMAGE \
$LOAD_STATE_ANVIL_ARG $DUMP_STATE_ANVIL_ARG --host 0.0.0.0
Expand Down
16 changes: 14 additions & 2 deletions crates/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./" }]
fs_permissions = [{ access = "read-write", path = "./"}]
solc = "0.8.26"
via-ir = true

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
remappings = [
"@eigenlayer/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/src/",
"@eigenlayer-scripts/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/script/",
"@eigenlayer-middleware/=lib/eigenlayer-middleware/",
"@openzeppelin/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts/",
"@openzeppelin-upgrades/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable/",
"forge-std/=lib/forge-std/src/",
]


# See more config options https://github.com/foundry-rs/foundry/tree/master/config
8 changes: 8 additions & 0 deletions crates/contracts/mock_avs_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"num_quorums": 1,
"operator_params": [10000,15000,100],
"operator_addr": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"contracts_registry_addr": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"task_generator_addr": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"aggregator_addr":"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
}
17 changes: 9 additions & 8 deletions crates/contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
@openzeppelin-upgrades-v4.9.0/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/
@openzeppelin-upgrades/=lib/eigenlayer-middleware/lib/openzeppelin-contracts-upgradeable/
@openzeppelin-v4.9.0/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-v4.9.0/
@openzeppelin/=lib/eigenlayer-middleware/lib/openzeppelin-contracts/
@eigenlayer/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/src/
@eigenlayer-scripts/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/script/
@eigenlayer-middleware/=lib/eigenlayer-middleware/
@openzeppelin/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts/
@openzeppelin-upgrades/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable/
forge-std/=lib/forge-std/src/
ds-test/=lib/eigenlayer-middleware/lib/ds-test/src/
eigenlayer-contracts/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/
eigenlayer-middleware/=lib/eigenlayer-middleware/
forge-std/=lib/forge-std/src/
openzeppelin-contracts-upgradeable/=lib/eigenlayer-middleware/lib/openzeppelin-contracts-upgradeable/
openzeppelin-contracts/=lib/eigenlayer-middleware/lib/openzeppelin-contracts/
erc4626-tests/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/lib/erc4626-tests/
openzeppelin-contracts-upgradeable-v4.9.0/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/
openzeppelin-contracts-upgradeable/=lib/eigenlayer-middleware/lib/openzeppelin-contracts-upgradeable/
openzeppelin-contracts-v4.9.0/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-v4.9.0/
openzeppelin/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/contracts/
openzeppelin-contracts/=lib/eigenlayer-middleware/lib/openzeppelin-contracts/
openzeppelin/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/contracts/
33 changes: 33 additions & 0 deletions crates/contracts/script/ContractsRegistry.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;

import {Script} from "forge-std/Script.sol";

import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol";
import {MockAvsDeploymentLib} from "./utils/MockAvsDeploymentLib.sol";
import {WriteToContractsRegistryLib} from "./utils/WriteToContractsRegistryLib.sol";

contract ContractsRegistry is Script {
address private deployer;
address public CONTRACT_REGISTRY;
CoreDeploymentLib.DeploymentData coreConfigData;
MockAvsDeploymentLib.DeploymentData avsConfigData;

function setUp() public {
deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
vm.label(deployer, "Deployer");
CONTRACT_REGISTRY = vm.envAddress("CONTRACTS_REGISTRY_ADDR");

coreConfigData = CoreDeploymentLib.readDeploymentJson("script/deployments/core/", "31337.json");
avsConfigData = MockAvsDeploymentLib.readDeploymentJson("script/deployments/mock-avs/", block.chainid);
}

function run() external {
vm.startBroadcast(deployer);
if (block.chainid == 31337 || block.chainid == 1337) {
WriteToContractsRegistryLib.writeCoreContractsToRegistry(CONTRACT_REGISTRY, coreConfigData);
WriteToContractsRegistryLib.writeMockAvsContractsToRegistry(CONTRACT_REGISTRY, avsConfigData);
}
vm.stopBroadcast();
}
}
31 changes: 31 additions & 0 deletions crates/contracts/script/DeployEigenLayerCore.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol";
import {UpgradeableProxyLib} from "./utils/UpgradeableProxyLib.sol";

contract DeployEigenlayerCore is Script {
using CoreDeploymentLib for *;
using UpgradeableProxyLib for address;

address internal deployer;
address internal proxyAdmin;
CoreDeploymentLib.DeploymentData internal deploymentData;
CoreDeploymentLib.DeploymentConfigData internal configData;

function setUp() public virtual {
deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
vm.label(deployer, "Deployer");
}

function run() external {
vm.startBroadcast(deployer);
proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();
deploymentData = CoreDeploymentLib.deployContracts(deployer, proxyAdmin, configData);
vm.stopBroadcast();
string memory deploymentPath = "script/deployments/core/";
CoreDeploymentLib.writeDeploymentJson(deploymentPath, block.chainid, deploymentData);
}
}
Loading
Loading