diff --git a/contracts/script/HelloWorldDeployer.s.sol b/contracts/script/HelloWorldDeployer.s.sol index 8af2216a..55225289 100644 --- a/contracts/script/HelloWorldDeployer.s.sol +++ b/contracts/script/HelloWorldDeployer.s.sol @@ -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(); @@ -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); diff --git a/contracts/script/utils/CoreDeploymentLib.sol b/contracts/script/utils/CoreDeploymentLib.sol index bb24138f..1c638071 100644 --- a/contracts/script/utils/CoreDeploymentLib.sol +++ b/contracts/script/utils/CoreDeploymentLib.sol @@ -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 ) diff --git a/contracts/script/utils/HelloWorldDeploymentLib.sol b/contracts/script/utils/HelloWorldDeploymentLib.sol index fa8c0ba9..7b6d2a46 100644 --- a/contracts/script/utils/HelloWorldDeploymentLib.sol +++ b/contracts/script/utils/HelloWorldDeploymentLib.sol @@ -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; @@ -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; } @@ -83,6 +91,7 @@ library HelloWorldDeploymentLib { return data; } + /// write to default output path function writeDeploymentJson( @@ -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, diff --git a/contracts/src/HelloWorldServiceManager.sol b/contracts/src/HelloWorldServiceManager.sol index 07f482d7..3956b03e 100644 --- a/contracts/src/HelloWorldServiceManager.sol +++ b/contracts/src/HelloWorldServiceManager.sol @@ -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( diff --git a/contracts/test/HelloWorldServiceManager.t.sol b/contracts/test/HelloWorldServiceManager.t.sol index f7ad8b55..af959b02 100644 --- a/contracts/test/HelloWorldServiceManager.t.sol +++ b/contracts/test/HelloWorldServiceManager.t.sol @@ -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; @@ -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(); @@ -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); } diff --git a/contracts/test/SetupPaymentsLib.t.sol b/contracts/test/SetupPaymentsLib.t.sol index baa6e294..06203ab0 100644 --- a/contracts/test/SetupPaymentsLib.t.sol +++ b/contracts/test/SetupPaymentsLib.t.sol @@ -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; @@ -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 { @@ -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); @@ -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(); @@ -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(); diff --git a/contracts/test/mockData/config/hello-world/1337.json b/contracts/test/mockData/config/hello-world/1337.json index e69de29b..b0554185 100644 --- a/contracts/test/mockData/config/hello-world/1337.json +++ b/contracts/test/mockData/config/hello-world/1337.json @@ -0,0 +1,4 @@ +{ + "rewardsOwner": "0x", + "rewardsInitiator": "0x" +} \ No newline at end of file diff --git a/contracts/test/mockData/deployments/hello-world/1337.json b/contracts/test/mockData/deployments/hello-world/1337.json index e69de29b..6e2fac83 100644 --- a/contracts/test/mockData/deployments/hello-world/1337.json +++ b/contracts/test/mockData/deployments/hello-world/1337.json @@ -0,0 +1,4 @@ +{ + "rewardsOwner": "0x3C4293F66941ECa00f4950C10d4255d5c271bAe1", + "rewardsInitiator": "0x3C4293F66941ECa00f4950C10d4255d5c271bAe1" +} \ No newline at end of file