diff --git a/contracts/payments.json b/contracts/payments.json index 79ae1679..77873afa 100644 --- a/contracts/payments.json +++ b/contracts/payments.json @@ -1,10 +1,11 @@ { "leaves": [ - "0x0000000000000000000000000000000000000000000000000000000000000001", - "0x0000000000000000000000000000000000000000000000000000000000000002" + "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42", + "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42", + "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42", + "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42" ], "tokenLeaves": [ - "0x0000000000000000000000000000000000000000000000000000000000000003", - "0x0000000000000000000000000000000000000000000000000000000000000004" + "0xf5d87050cb923194fe63c7ed2c45cbc913fa6ecf322f3631149c36d9460b3ad6" ] } \ No newline at end of file diff --git a/contracts/script/SetupPayments.s.sol b/contracts/script/SetupPayments.s.sol index f7fc244e..fbced18e 100644 --- a/contracts/script/SetupPayments.s.sol +++ b/contracts/script/SetupPayments.s.sol @@ -1,80 +1,81 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.0; +// // SPDX-License-Identifier: UNLICENSED +// pragma solidity ^0.8.0; -import {Script} from "forge-std/Script.sol"; -import {HelloWorldDeploymentLib} from "./utils/HelloWorldDeploymentLib.sol"; -import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol"; -import {SetupPaymentsLib} from "./utils/SetupPaymentsLib.sol"; -import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol"; +// import {Script} from "forge-std/Script.sol"; +// import {HelloWorldDeploymentLib} from "./utils/HelloWorldDeploymentLib.sol"; +// import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol"; +// import {SetupPaymentsLib} from "./utils/SetupPaymentsLib.sol"; +// import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol"; -contract SetupPayments is Script { - address private deployer; - CoreDeploymentLib.DeploymentData coreDeployment; - HelloWorldDeploymentLib.DeploymentData helloWorldDeployment; +// contract SetupPayments is Script { +// address private deployer; +// CoreDeploymentLib.DeploymentData coreDeployment; +// HelloWorldDeploymentLib.DeploymentData helloWorldDeployment; - uint256 constant NUM_PAYMENTS = 8; - uint256 constant NUM_TOKEN_EARNINGS = 1; - uint256 constant TOKEN_EARNINGS = 100; +// uint256 constant NUM_PAYMENTS = 8; +// uint256 constant NUM_TOKEN_EARNINGS = 1; +// uint256 constant TOKEN_EARNINGS = 100; - function setUp() public { - deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY")); - vm.label(deployer, "Deployer"); +// function setUp() public { +// deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY")); +// vm.label(deployer, "Deployer"); - coreDeployment = CoreDeploymentLib.readDeploymentJson("deployments/core/", block.chainid); - helloWorldDeployment = HelloWorldDeploymentLib.readDeploymentJson("deployments/hello-world/", block.chainid); - } +// coreDeployment = CoreDeploymentLib.readDeploymentJson("deployments/core/", block.chainid); +// helloWorldDeployment = HelloWorldDeploymentLib.readDeploymentJson("deployments/hello-world/", block.chainid); +// } - function run() external { - vm.startBroadcast(deployer); - IRewardsCoordinator(coreDeployment.rewardsCoordinator).setRewardsUpdater(deployer); +// function run() external { +// vm.startBroadcast(deployer); +// IRewardsCoordinator(coreDeployment.rewardsCoordinator).setRewardsUpdater(deployer); - vm.stopBroadcast(); - } +// vm.stopBroadcast(); +// } - function createPaymentSubmissions(uint256 numPayments, uint256 amountPerPayment, uint32 duration, uint32 startTimestamp) public { - SetupPaymentsLib.createPaymentSubmissions( - IRewardsCoordinator(coreDeployment.rewardsCoordinator), - helloWorldDeployment.strategy, - numPayments, - amountPerPayment, - duration, - startTimestamp - ); - } +// function createPaymentSubmissions(uint256 numPayments, uint256 amountPerPayment, uint32 duration, uint32 startTimestamp) public { +// SetupPaymentsLib.createPaymentSubmissions( +// IRewardsCoordinator(coreDeployment.rewardsCoordinator), +// helloWorldDeployment.strategy, +// numPayments, +// amountPerPayment, +// duration, +// startTimestamp +// ); +// } - function processClaim(string memory filePath, uint256 indexToProve, address recipient, IRewardsCoordinator.EarnerTreeMerkleLeaf calldata earnerLeaf) public { - SetupPaymentsLib.processClaim( - IRewardsCoordinator(coreDeployment.rewardsCoordinator), - filePath, - indexToProve, - recipient, - earnerLeaf, - NUM_TOKEN_EARNINGS, - helloWorldDeployment.strategy - ); - } +// function processClaim(string memory filePath, uint256 indexToProve, address recipient, IRewardsCoordinator.EarnerTreeMerkleLeaf calldata earnerLeaf) public { +// SetupPaymentsLib.processClaim( +// IRewardsCoordinator(coreDeployment.rewardsCoordinator), +// filePath, +// indexToProve, +// recipient, +// earnerLeaf, +// NUM_TOKEN_EARNINGS, +// helloWorldDeployment.strategy +// ); +// } - function submitPaymentRoot(address[] calldata earners) public { - SetupPaymentsLib.submitPaymentRoot( - IRewardsCoordinator(coreDeployment.rewardsCoordinator), - earners, - helloWorldDeployment.strategy, - NUM_PAYMENTS, - NUM_TOKEN_EARNINGS, - TOKEN_EARNINGS - ); - } +// function submitPaymentRoot(address[] calldata earners, uint32 endTimestamp) public { +// SetupPaymentsLib.submitRoot( +// IRewardsCoordinator(coreDeployment.rewardsCoordinator), +// earners, +// helloWorldDeployment.strategy, +// endTimestamp, +// NUM_PAYMENTS, +// NUM_TOKEN_EARNINGS, +// TOKEN_EARNINGS +// ); +// } - function createPaymentRoot(address[] calldata earners) public returns (bytes32) { - return SetupPaymentsLib.createPaymentRoot( - IRewardsCoordinator(coreDeployment.rewardsCoordinator), - earners, - NUM_PAYMENTS, - NUM_TOKEN_EARNINGS, - TOKEN_EARNINGS, - helloWorldDeployment.strategy - ); - } -} \ No newline at end of file +// function createPaymentRoot(address[] calldata earners) public returns (bytes32) { +// return SetupPaymentsLib.createPaymentRoot( +// IRewardsCoordinator(coreDeployment.rewardsCoordinator), +// earners, +// NUM_PAYMENTS, +// NUM_TOKEN_EARNINGS, +// TOKEN_EARNINGS, +// helloWorldDeployment.strategy +// ); +// } +// } \ No newline at end of file diff --git a/contracts/script/utils/SetupPaymentsLib.sol b/contracts/script/utils/SetupPaymentsLib.sol index 2f0c89a4..ac86b14d 100644 --- a/contracts/script/utils/SetupPaymentsLib.sol +++ b/contracts/script/utils/SetupPaymentsLib.sol @@ -5,6 +5,7 @@ import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoor import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol"; import {Vm} from "forge-std/Vm.sol"; + library SetupPaymentsLib { Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); @@ -79,45 +80,53 @@ library SetupPaymentsLib { rewardsCoordinator.processClaim(claim, recipient); } - function submitPaymentRoot( + function submitRoot( IRewardsCoordinator rewardsCoordinator, - address[] calldata earners, + bytes32[] memory tokenLeaves, + IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves, address strategy, + uint32 rewardsCalculationEndTimestamp, uint256 NUM_PAYMENTS, uint256 NUM_TOKEN_EARNINGS, uint256 TOKEN_EARNINGS ) public { - bytes32 paymentRoot = createPaymentRoot(rewardsCoordinator, earners, NUM_PAYMENTS, NUM_TOKEN_EARNINGS, TOKEN_EARNINGS, strategy); - uint32 rewardsCalculationEndTimestamp = rewardsCoordinator.currRewardsCalculationEndTimestamp() + 1 weeks; + bytes32 paymentRoot = createPaymentRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, NUM_PAYMENTS, NUM_TOKEN_EARNINGS, TOKEN_EARNINGS, strategy); rewardsCoordinator.submitRoot(paymentRoot, rewardsCalculationEndTimestamp); } function createPaymentRoot( IRewardsCoordinator rewardsCoordinator, - address[] calldata earners, + bytes32[] memory tokenLeaves, + IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves, uint256 NUM_PAYMENTS, uint256 NUM_TOKEN_EARNINGS, uint256 TOKEN_EARNINGS, address strategy ) public returns (bytes32) { - require(earners.length == NUM_PAYMENTS, "Number of earners must match number of payments"); + require(earnerLeaves.length == NUM_PAYMENTS, "Number of earners must match number of payments"); bytes32[] memory leaves = new bytes32[](NUM_PAYMENTS); - IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves = new IRewardsCoordinator.EarnerTreeMerkleLeaf[](NUM_PAYMENTS); - bytes32[] memory tokenLeaves = createTokenLeaves(rewardsCoordinator, NUM_TOKEN_EARNINGS, TOKEN_EARNINGS, strategy); require(tokenLeaves.length == NUM_TOKEN_EARNINGS, "Number of token leaves must match number of token earnings"); for (uint256 i = 0; i < NUM_PAYMENTS; i++) { - address earner = earners[i]; - bytes32 earnerTokenRoot = createTokenRoot(tokenLeaves); - IRewardsCoordinator.EarnerTreeMerkleLeaf memory leaf = IRewardsCoordinator.EarnerTreeMerkleLeaf({ + leaves[i] = rewardsCoordinator.calculateEarnerLeafHash(earnerLeaves[i]); + } + + writeLeavesToJson(leaves, tokenLeaves); + return (merkleizeKeccak(leaves)); + } + + function createEarnerLeaves( + address[] calldata earners, + bytes32[] memory tokenLeaves + ) public returns (IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory) { + IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory leaves = new IRewardsCoordinator.EarnerTreeMerkleLeaf[](earners.length); + for (uint256 i = 0; i < earners.length; i++) { + leaves[i] = IRewardsCoordinator.EarnerTreeMerkleLeaf({ earner: earners[i], earnerTokenRoot: createTokenRoot(tokenLeaves) }); - leaves[i] = rewardsCoordinator.calculateEarnerLeafHash(leaf); - earnerLeaves[i] = leaf; } - writeLeavesToJson(leaves, tokenLeaves); - return merkleizeKeccak(leaves); + return leaves; } function createTokenRoot(bytes32[] memory tokenLeaves) public pure returns (bytes32) { @@ -156,7 +165,7 @@ library SetupPaymentsLib { string memory parent_object = "parent_object"; vm.serializeBytes32(parent_object, "leaves", leaves); string memory finalJson = vm.serializeBytes32(parent_object, "tokenLeaves", tokenLeaves); - vm.writeJson(finalJson, "payments.json"); + vm.writeJson(finalJson, "test/mockData/scratch/payments.json"); } function parseLeavesFromJson(string memory filePath) public returns (PaymentLeaves memory) { @@ -210,7 +219,7 @@ library SetupPaymentsLib { * @return The computed Merkle root of the tree. * @dev This pads to the next power of 2. very inefficient! just for POC */ - function merkleizeKeccak(bytes32[] memory leaves) internal pure returns (bytes32) { + function merkleizeKeccak(bytes32[] memory leaves) public pure returns (bytes32) { // uint256 paddedLength = 2; // while(paddedLength < leaves.length) { // paddedLength <<= 1;