Skip to content

Commit

Permalink
Rewards V2 (#12)
Browse files Browse the repository at this point in the history
* update submodule to 0.2.1

* use latest sdk

* remove state dump, add eigenlayer-contracts submodule v0.4.3-mainnet-rewards-programmatic-incentives

* scripts WIP

* scripts working

* makefile update, some cilppy

* chore: update integration tests deps

* exclude incredible-binding crate in ci

* exclude incredible-binding in cargo check ci

* ignore clippy in bindings crate

* fmt

* install forge in ci

* add docker anvil in ci, comment the failing test for now

* fix:enter correct directory in ci

* port the rewards scripts and tests from hello world, use foundry-toolchain in ci

* nudge ci

* fix : payment script revert, todo: write correct reward params

* payment script working

* add payment script in make file

* cleanup

* remove eigenlayer-contracts from gitmodules

* use get_signer, fmt

* readme update

* remapping

* remove foundry toolchain ,install foundry using cargo

* fix: yml

* modify contract path in sh file, dd back toolchain for foundry

* update deploy-eigenlayer.sh

* update rev

* fix: submodule in ci, update readme

* add submodules in yml

* update middleware

* middleware update

* add forge-std

* testing ci

* update rev

* checking

* update middleware

* cd into contracts

* update .sh

* cd into contracts only once

* hit and trial

* fix: eigenlayer.sh script

* vv

* add submodule in ci

* env in ci

* 2 operators support

* clean up

* fix quorum, client

* fix:tests

* update readme

* fix:merge conflicts

* remove unwrap

* use separate config file and reuse error

* clippy

* common config for test in operators

* deploy-eigenlayer with debug comments

* print return value in deploy-eigenlayer.sh

* change foundry image to latest

* clean up

* update middleware to latest dev

* add createOperatorDirectedAVSRewardsSubmissions in paymentslib

* createOperatorDirectedAVSRewardsSubmissions in payment script working

---------

Co-authored-by: supernovahs <[email protected]>
Co-authored-by: Pablo Deymonnaz <[email protected]>
  • Loading branch information
3 people authored Nov 28, 2024
1 parent c350328 commit 86e2a9b
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 5 deletions.
1 change: 1 addition & 0 deletions contracts/anvil/deploy-avs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ forge script script/ContractsRegistry.s.sol --rpc-url $RPC_URL --private-key $PR

forge script script/SetupPayments.s.sol --rpc-url $RPC_URL --broadcast --slow --private-key $PRIVATE_KEY

forge script script/OperatorDirectedPayments.s.sol --rpc-url $RPC_URL --broadcast --slow --private-key $PRIVATE_KEY
4 changes: 4 additions & 0 deletions contracts/operator_reward_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"operator_addresses": ["0x0000000000000000000000000000000000000001"],
"amount": [1]
}
5 changes: 4 additions & 1 deletion contracts/script/IncredibleSquaringDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ contract IncredibleSquaringDeployer is Script {
FundOperator.fund_operator(address(erc20Mock), isConfig.operator_addr, 10e18);
FundOperator.fund_operator(address(erc20Mock), isConfig.operator_2_addr, 10e18);
console.log(isConfig.operator_2_addr);
(bool s ,) = isConfig.operator_2_addr.call{value: 0.1 ether}("");
(bool s,) = isConfig.operator_2_addr.call{value: 0.1 ether}("");
require(s);
console.log(isConfig.operator_2_addr.balance);
incredibleSquaringStrategy = IStrategy(StrategyFactory(configData.strategyFactory).deployNewStrategy(erc20Mock));
Expand All @@ -117,6 +117,9 @@ contract IncredibleSquaringDeployer is Script {
incrediblSquaringDeployment = IncredibleSquaringDeploymentLib.deployContracts(
proxyAdmin, configData, address(incredibleSquaringStrategy), isConfig, msg.sender
);
FundOperator.fund_operator(
address(erc20Mock), incrediblSquaringDeployment.incredibleSquaringServiceManager, 1e18
);

IncredibleSquaringDeploymentLib.writeDeploymentJson(incrediblSquaringDeployment);

Expand Down
81 changes: 81 additions & 0 deletions contracts/script/OperatorDirectedPayments.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;

import {Script} from "forge-std/Script.sol";
import {IncredibleSquaringDeploymentLib} from "./utils/IncredibleSquaringDeploymentLib.sol";
import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol";
import {SetupPaymentsLib} from "./utils/SetupPaymentsLib.sol";
import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol";
import {console2} from "forge-std/console2.sol";
import {UpgradeableProxyLib} from "./utils/UpgradeableProxyLib.sol";
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {stdJson} from "forge-std/StdJson.sol";

contract OperatorDirectedPayments is Script {
using stdJson for string;

address private deployer;
CoreDeploymentLib.DeploymentData coreDeployment;
IncredibleSquaringDeploymentLib.DeploymentData incredibleSquaringDeployment;
SetupPaymentsLib.OperatorConfig operatorRewardConfig;
string internal constant filePath = "test/mockData/scratch/payment_info.json";

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

coreDeployment = CoreDeploymentLib.readDeploymentJson("script/deployments/core/", block.chainid);
incredibleSquaringDeployment =
IncredibleSquaringDeploymentLib.readDeploymentJson("script/deployments/incredible-squaring/", block.chainid);
operatorRewardConfig = SetupPaymentsLib.readOperatorConfig("operator_reward_config");
}

function run() external {
vm.startBroadcast(deployer);

string memory json = vm.readFile(filePath);
uint32 duration = uint32(json.readUint(".duration"));
uint32 index_to_prove = uint32(json.readUint(".indexToProve"));
uint256 num_payments = json.readUint(".numPayments");
address recipient = json.readAddress(".recipient");
address[] memory earners = json.readAddressArray(".earners");
bytes32[] memory earner_token_roots = json.readBytes32Array(".earnerTokenRoots");
uint32 start_time = uint32(previousDivisibleTimestamp(block.timestamp));

IRewardsCoordinator.OperatorReward[] memory operator_reward =
new IRewardsCoordinator.OperatorReward[](operatorRewardConfig.operator_addr.length);

for (uint256 i = 0; i < operator_reward.length; i++) {
operator_reward[i] = IRewardsCoordinator.OperatorReward({
operator: operatorRewardConfig.operator_addr[i],
amount: operatorRewardConfig.amount[i]
});
}

SetupPaymentsLib.createOperatorDirectedAVSRewardsSubmissions(
incredibleSquaringDeployment.strategy,
incredibleSquaringDeployment.incredibleSquaringServiceManager,
operator_reward,
num_payments,
duration,
start_time
);

vm.stopBroadcast();
}

function previousDivisibleTimestamp(uint256 blockTimestamp) public pure returns (uint256) {
uint256 daySeconds = 86400;

// Calculate the remainder to check how far blockTimestamp is from the nearest multiple of daySeconds
uint256 remainder = blockTimestamp % daySeconds;

if (remainder == 0) {
// If blockTimestamp is already divisible by daySeconds, go two steps back
return blockTimestamp - (2 * daySeconds);
} else {
// Otherwise, move back to the previous divisible timestamp and then one more step
return blockTimestamp - remainder - daySeconds;
}
}
}
2 changes: 1 addition & 1 deletion contracts/script/deployments/core/31337.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"lastUpdate":{"timestamp":"1732362263","block_number":"1"},"addresses":{"proxyAdmin":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","delegation":"0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9","delegationManagerImpl":"0x68b1d87f95878fe05b998f19b66f4baba5de1aed","avsDirectory":"0x5fc8d32690cc91d4c39d9d3abcbd16989f875707","avsDirectoryImpl":"0x3aa5ebb10dc797cac828524e59a333d0a371443c","strategyManager":"0xa513e6e4b8f2a923d98304ec87f64353c4d5c853","strategyManagerImpl":"0xc6e7df5e7b4f2a278906862b61205850344d4e7d","eigenPodManager":"0x8a791620dd6260079bf849dc5567adc3f2fdc318","eigenPodManagerImpl":"0x4ed7c70f96b99c776995fb64377f0d4ab3b0e1c1","strategyFactory":"0x9a9f2ccfde556a7e9ff0848998aa4a0cfd8863ae","rewardsCoordinator":"0xb7f8bc63bbcad18155201308c8f3540b07f84f5e","strategyBeacon":"0xc5a5c42992decbae36851359345fe25997f5c42d"}}
{"lastUpdate":{"timestamp":"1732699447","block_number":"1"},"addresses":{"proxyAdmin":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","delegation":"0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9","delegationManagerImpl":"0x68b1d87f95878fe05b998f19b66f4baba5de1aed","avsDirectory":"0x5fc8d32690cc91d4c39d9d3abcbd16989f875707","avsDirectoryImpl":"0x3aa5ebb10dc797cac828524e59a333d0a371443c","strategyManager":"0xa513e6e4b8f2a923d98304ec87f64353c4d5c853","strategyManagerImpl":"0xc6e7df5e7b4f2a278906862b61205850344d4e7d","eigenPodManager":"0x8a791620dd6260079bf849dc5567adc3f2fdc318","eigenPodManagerImpl":"0x4ed7c70f96b99c776995fb64377f0d4ab3b0e1c1","strategyFactory":"0x9a9f2ccfde556a7e9ff0848998aa4a0cfd8863ae","rewardsCoordinator":"0xb7f8bc63bbcad18155201308c8f3540b07f84f5e","strategyBeacon":"0xc5a5c42992decbae36851359345fe25997f5c42d"}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"lastUpdate":{"timestamp":"1732362303","block_number":"36"},"addresses":{"proxyAdmin":"0x99bba657f2bbc93c02d617f8ba121cb8fc104acf","IncredibleSquaringServiceManager":"0x8f86403a4de0bb5791fa46b8e795c547942fe4cf","incredibleSquaringServiceManagerImpl":"0x4c4a2f8c81640e47606d3fd77b353e87ba015584","IncredibleSquaringTaskManager":"0x809d550fca64d94bd9f66e60752a544199cfac3d","registryCoordinator":"0x1291be112d480055dafd8a610b7d1e203891c274","blsapkRegistry":"0xb7278a61aa25c888815afc32ad3cc52ff24fe575","indexRegistry":"0x82e01223d51eb87e16a03e24687edf0f294da6f1","stakeRegistry":"0x5eb3bc0a489c5a8288765d2336659ebca68fcd00","operatorStateRetriever":"0x7bc06c482dead17c0e297afbc32f6e63d3846650","strategy":"0x2b961e3959b79326a8e7f64ef0d2d825707669b5","token":"0x0000000000000000000000000000000000000000"}}
{"lastUpdate":{"timestamp":"1732699449","block_number":"36"},"addresses":{"proxyAdmin":"0x99bba657f2bbc93c02d617f8ba121cb8fc104acf","IncredibleSquaringServiceManager":"0x8f86403a4de0bb5791fa46b8e795c547942fe4cf","incredibleSquaringServiceManagerImpl":"0x4c4a2f8c81640e47606d3fd77b353e87ba015584","IncredibleSquaringTaskManager":"0x809d550fca64d94bd9f66e60752a544199cfac3d","registryCoordinator":"0x1291be112d480055dafd8a610b7d1e203891c274","blsapkRegistry":"0xb7278a61aa25c888815afc32ad3cc52ff24fe575","indexRegistry":"0x82e01223d51eb87e16a03e24687edf0f294da6f1","stakeRegistry":"0x5eb3bc0a489c5a8288765d2336659ebca68fcd00","operatorStateRetriever":"0x7bc06c482dead17c0e297afbc32f6e63d3846650","strategy":"0x2b961e3959b79326a8e7f64ef0d2d825707669b5","token":"0x0000000000000000000000000000000000000000"}}
2 changes: 1 addition & 1 deletion contracts/script/utils/CoreDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ library CoreDeploymentLib {
/// TODO: Get actual values
uint32 CALCULATION_INTERVAL_SECONDS = 1 days;
uint32 MAX_REWARDS_DURATION = 1 days;
uint32 MAX_RETROACTIVE_LENGTH = 1;
uint32 MAX_RETROACTIVE_LENGTH = 3 days;
uint32 MAX_FUTURE_LENGTH = 1 days;
uint32 GENESIS_REWARDS_TIMESTAMP = 10 days;
address rewardsCoordinatorImpl = address(
Expand Down
54 changes: 54 additions & 0 deletions contracts/script/utils/SetupPaymentsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,35 @@ import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoor
import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {Vm} from "forge-std/Vm.sol";
import {console} from "forge-std/console.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {IncredibleSquaringServiceManager} from "../../src/IncredibleSquaringServiceManager.sol";

library SetupPaymentsLib {
Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));

using stdJson for string;

struct PaymentLeaves {
bytes32[] leaves;
bytes32[] tokenLeaves;
}

struct OperatorConfig {
address[] operator_addr;
uint256[] amount;
}

function readOperatorConfig(string memory path) internal returns (OperatorConfig memory config) {
string memory pathToFile = string.concat(path, ".json");
require(vm.exists(pathToFile), "Deployment file does not exist");
string memory json = vm.readFile(pathToFile);

config.operator_addr = json.readAddressArray(".operator_addresses");
config.amount = json.readUintArray(".amount");

return config;
}

function createAVSRewardsSubmissions(
IRewardsCoordinator rewardsCoordinator,
address strategy,
Expand Down Expand Up @@ -45,6 +65,40 @@ library SetupPaymentsLib {
rewardsCoordinator.createAVSRewardsSubmission(rewardsSubmissions);
}

function createOperatorDirectedAVSRewardsSubmissions(
address strategy,
address avs,
IRewardsCoordinator.OperatorReward[] memory operatorRewards,
uint256 numPayments,
uint32 duration,
uint32 startTimestamp
) internal {
IStrategy(strategy).underlyingToken();
IRewardsCoordinator.OperatorDirectedRewardsSubmission[] memory operatorDirectedRewardsSubmissions =
new IRewardsCoordinator.OperatorDirectedRewardsSubmission[](numPayments);
for (uint256 i = 0; i < numPayments; i++) {
IRewardsCoordinator.StrategyAndMultiplier[] memory strategiesAndMultipliers =
new IRewardsCoordinator.StrategyAndMultiplier[](1);
strategiesAndMultipliers[0] =
IRewardsCoordinator.StrategyAndMultiplier({strategy: IStrategy(strategy), multiplier: 10000});

IRewardsCoordinator.OperatorDirectedRewardsSubmission memory rewardSubmission = IRewardsCoordinator
.OperatorDirectedRewardsSubmission({
strategiesAndMultipliers: strategiesAndMultipliers,
token: IStrategy(strategy).underlyingToken(),
operatorRewards: operatorRewards,
startTimestamp: startTimestamp,
duration: duration,
description: ""
});

operatorDirectedRewardsSubmissions[i] = rewardSubmission;
}
IncredibleSquaringServiceManager(avs).createOperatorDirectedAVSRewardsSubmission(
avs, operatorDirectedRewardsSubmissions
);
}

function processClaim(
IRewardsCoordinator rewardsCoordinator,
string memory filePath,
Expand Down
7 changes: 7 additions & 0 deletions contracts/src/IncredibleSquaringServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ contract IncredibleSquaringServiceManager is ServiceManagerBase {
incredibleSquaringTaskManager = _incredibleSquaringTaskManager;
}

function createOperatorDirectedAVSRewardsSubmission(
address avs,
IRewardsCoordinator.OperatorDirectedRewardsSubmission[] memory operatorDirectedRewardsSubmission
) public {
_rewardsCoordinator.createOperatorDirectedAVSRewardsSubmission(avs, operatorDirectedRewardsSubmission);
}

/// @notice Called in the event of challenge resolution, in order to forward a call to the Slasher, which 'freezes' the `operator`.
/// @dev The Slasher contract is under active development and its interface expected to change.
/// We recommend writing slashing logic without integrating with the Slasher at this point in time.
Expand Down

0 comments on commit 86e2a9b

Please sign in to comment.