Skip to content

Commit

Permalink
fix: initialize sm and rewards coordinator config (#93)
Browse files Browse the repository at this point in the history
* fix: initialize sm and rewards coordinator config

* add rewards owner and initiator as inputs to deploy

* added helloWorld config

---------

Co-authored-by: kachapah <[email protected]>
  • Loading branch information
stevennevins and Sidu28 authored Oct 31, 2024
1 parent b239267 commit 3d771b4
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 9 deletions.
7 changes: 6 additions & 1 deletion contracts/script/HelloWorldDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ contract HelloWorldDeployer is Script {

address private deployer;
address proxyAdmin;
address rewardsOwner;
address rewardsInitiator;
IStrategy helloWorldStrategy;
CoreDeploymentLib.DeploymentData coreDeployment;
HelloWorldDeploymentLib.DeploymentData helloWorldDeployment;
HelloWorldDeploymentLib.DeploymentConfigData helloWorldConfig;
Quorum internal quorum;
ERC20Mock token;
function setUp() public virtual {
deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
vm.label(deployer, "Deployer");

helloWorldConfig = HelloWorldDeploymentLib.readDeploymentConfigValues("deployments/hello-world/", block.chainid);

coreDeployment = CoreDeploymentLib.readDeploymentJson("deployments/core/", block.chainid);

token = new ERC20Mock();
Expand All @@ -50,7 +55,7 @@ contract HelloWorldDeployer is Script {
proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();

helloWorldDeployment =
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum);
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum, rewardsInitiator, rewardsOwner);

helloWorldDeployment.strategy = address(helloWorldStrategy);
helloWorldDeployment.token = address(token);
Expand Down
3 changes: 1 addition & 2 deletions contracts/script/utils/CoreDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ library CoreDeploymentLib {
proxyAdmin, // initialOwner
IPauserRegistry(result.pauserRegistry), // _pauserRegistry
configData.rewardsCoordinator.initPausedStatus, // initialPausedStatus
/// TODO: is there a setter and is this expected?
address(0), // rewards updater
configData.rewardsCoordinator.updater,
uint32(configData.rewardsCoordinator.activationDelay), // _activationDelay
uint16(configData.rewardsCoordinator.globalOperatorCommissionBips) // _globalCommissionBips
)
Expand Down
39 changes: 37 additions & 2 deletions contracts/script/utils/HelloWorldDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ library HelloWorldDeploymentLib {
address token;
}

struct DeploymentConfigData {
address rewardsOwner;
address rewardsInitiator;
}

function deployContracts(
address proxyAdmin,
CoreDeploymentLib.DeploymentData memory core,
Quorum memory quorum
Quorum memory quorum,
address rewardsInitiator,
address owner
) internal returns (DeploymentData memory) {
DeploymentData memory result;

Expand All @@ -53,7 +60,8 @@ library HelloWorldDeploymentLib {
ECDSAStakeRegistry.initialize, (result.helloWorldServiceManager, 0, quorum)
);
UpgradeableProxyLib.upgradeAndCall(result.stakeRegistry, stakeRegistryImpl, upgradeCall);
UpgradeableProxyLib.upgrade(result.helloWorldServiceManager, helloWorldServiceManagerImpl);
upgradeCall = abi.encodeCall(HelloWorldServiceManager.initialize, (owner, rewardsInitiator));
UpgradeableProxyLib.upgradeAndCall(result.helloWorldServiceManager, helloWorldServiceManagerImpl, upgradeCall);

return result;
}
Expand Down Expand Up @@ -83,6 +91,7 @@ library HelloWorldDeploymentLib {

return data;
}


/// write to default output path
function writeDeploymentJson(
Expand All @@ -109,6 +118,32 @@ library HelloWorldDeploymentLib {
vm.writeFile(fileName, deploymentData);
console2.log("Deployment artifacts written to:", fileName);
}


function readDeploymentConfigValues(
string memory directoryPath,
string memory fileName
) internal returns (DeploymentConfigData memory) {
string memory pathToFile = string.concat(directoryPath, fileName);

require(vm.exists(pathToFile), "Deployment file does not exist");

string memory json = vm.readFile(pathToFile);

DeploymentConfigData memory data;

data.rewardsOwner = json.readAddress(".rewardsOwner");
data.rewardsInitiator = json.readAddress(".rewardsInitiator");
return data;
}

function readDeploymentConfigValues(
string memory directoryPath,
uint256 chainId
) internal returns (DeploymentConfigData memory) {
return
readDeploymentConfigValues(directoryPath, string.concat(vm.toString(chainId), ".json"));
}

function _generateDeploymentJson(
DeploymentData memory data,
Expand Down
7 changes: 7 additions & 0 deletions contracts/src/HelloWorldServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ contract HelloWorldServiceManager is ECDSAServiceManagerBase, IHelloWorldService
)
{}

function initialize(
address initialOwner,
address _rewardsInitiator
) external initializer {
__ServiceManagerBase_init(initialOwner, _rewardsInitiator);
}

/* FUNCTIONS */
// NOTE: this function creates new task, assigns it a taskId
function createNewTask(
Expand Down
8 changes: 7 additions & 1 deletion contracts/test/HelloWorldServiceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ contract HelloWorldTaskManagerSetup is Test {
Vm.Wallet key;
}

struct AVSOwner {
Vm.Wallet key;
}

Operator[] internal operators;
TrafficGenerator internal generator;
AVSOwner internal owner;

HelloWorldDeploymentLib.DeploymentData internal helloWorldDeployment;
CoreDeploymentLib.DeploymentData internal coreDeployment;
Expand All @@ -52,6 +57,7 @@ contract HelloWorldTaskManagerSetup is Test {

function setUp() public virtual {
generator = TrafficGenerator({key: vm.createWallet("generator_wallet")});
owner = AVSOwner({key: vm.createWallet("owner_wallet")});

address proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();

Expand All @@ -65,7 +71,7 @@ contract HelloWorldTaskManagerSetup is Test {
quorum.strategies.push(StrategyParams({strategy: strategy, multiplier: 10_000}));

helloWorldDeployment =
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum);
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum, owner.key.addr, owner.key.addr);
labelContracts(coreDeployment, helloWorldDeployment);
}

Expand Down
10 changes: 7 additions & 3 deletions contracts/test/SetupPaymentsLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
StrategyParams,
IStrategy
} from "@eigenlayer-middleware/src/interfaces/IECDSAStakeRegistryEventsAndErrors.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";


contract TestConstants {
uint256 constant NUM_PAYMENTS = 8;
Expand All @@ -43,6 +45,7 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup

string internal constant filePath = "test/mockData/scratch/payments.json";
address rewardsInitiator = address(1);
address rewardsOwner = address(2);


function setUp() public override virtual {
Expand All @@ -57,10 +60,11 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
quorum.strategies.push(StrategyParams({strategy: strategy, multiplier: 10_000}));

helloWorldDeployment =
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum);
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum, rewardsInitiator, rewardsOwner);
labelContracts(coreDeployment, helloWorldDeployment);

cheats.prank(address(0));

cheats.prank(rewardsOwner);
ECDSAServiceManagerBase(helloWorldDeployment.helloWorldServiceManager).setRewardsInitiator(rewardsInitiator);

rewardsCoordinator = IRewardsCoordinator(coreDeployment.rewardsCoordinator);
Expand All @@ -83,7 +87,6 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
bytes32[] memory tokenLeaves = SetupPaymentsLib.createTokenLeaves(rewardsCoordinator, NUM_TOKEN_EARNINGS, TOKEN_EARNINGS, address(strategy));
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);


cheats.startPrank(rewardsCoordinator.rewardsUpdater());
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath);
cheats.stopPrank();
Expand Down Expand Up @@ -159,6 +162,7 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
bytes32[] memory tokenLeaves = SetupPaymentsLib.createTokenLeaves(rewardsCoordinator, NUM_TOKEN_EARNINGS, TOKEN_EARNINGS, address(strategy));
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);


cheats.startPrank(rewardsCoordinator.rewardsUpdater());
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath);
cheats.stopPrank();
Expand Down
4 changes: 4 additions & 0 deletions contracts/test/mockData/config/hello-world/1337.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rewardsOwner": "0x",
"rewardsInitiator": "0x"
}
4 changes: 4 additions & 0 deletions contracts/test/mockData/deployments/hello-world/1337.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rewardsOwner": "0x3C4293F66941ECa00f4950C10d4255d5c271bAe1",
"rewardsInitiator": "0x3C4293F66941ECa00f4950C10d4255d5c271bAe1"
}

0 comments on commit 3d771b4

Please sign in to comment.