From 4a083638303ab21cd461e33bd8e1020c5428b21f Mon Sep 17 00:00:00 2001 From: kachapah <60323455+Sidu28@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:47:13 -0700 Subject: [PATCH 1/2] fix filepaths --- contracts/payments.json | 9 ++++----- contracts/script/SetupPayments.s.sol | 6 ++++-- contracts/script/utils/SetupPaymentsLib.sol | 18 ++++++++---------- contracts/test/SetupPaymentsLib.t.sol | 10 +++++++--- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/contracts/payments.json b/contracts/payments.json index 77873af..79ae167 100644 --- a/contracts/payments.json +++ b/contracts/payments.json @@ -1,11 +1,10 @@ { "leaves": [ - "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42", - "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42", - "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42", - "0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42" + "0x0000000000000000000000000000000000000000000000000000000000000001", + "0x0000000000000000000000000000000000000000000000000000000000000002" ], "tokenLeaves": [ - "0xf5d87050cb923194fe63c7ed2c45cbc913fa6ecf322f3631149c36d9460b3ad6" + "0x0000000000000000000000000000000000000000000000000000000000000003", + "0x0000000000000000000000000000000000000000000000000000000000000004" ] } \ No newline at end of file diff --git a/contracts/script/SetupPayments.s.sol b/contracts/script/SetupPayments.s.sol index 345803d..2ffac0b 100644 --- a/contracts/script/SetupPayments.s.sol +++ b/contracts/script/SetupPayments.s.sol @@ -50,7 +50,8 @@ contract SetupPayments is Script { earner: info.earners[info.indexToProve], earnerTokenRoot: info.earnerTokenRoots[info.indexToProve] }); - processClaim(SetupPaymentsLib.getFilePath(), info.indexToProve, info.recipient, earnerLeaf); + + processClaim("test/mockData/scratch/payments.json", info.indexToProve, info.recipient, earnerLeaf); vm.stopBroadcast(); } @@ -95,7 +96,8 @@ contract SetupPayments is Script { helloWorldDeployment.strategy, endTimestamp, numPayments, - NUM_TOKEN_EARNINGS + NUM_TOKEN_EARNINGS, + "test/mockData/scratch/payments.json" ); } } \ No newline at end of file diff --git a/contracts/script/utils/SetupPaymentsLib.sol b/contracts/script/utils/SetupPaymentsLib.sol index 364a97d..cde8379 100644 --- a/contracts/script/utils/SetupPaymentsLib.sol +++ b/contracts/script/utils/SetupPaymentsLib.sol @@ -9,7 +9,6 @@ import {Vm} from "forge-std/Vm.sol"; library SetupPaymentsLib { Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); - string internal constant filePath = "test/mockData/scratch/payments.json"; struct PaymentLeaves { bytes32[] leaves; @@ -87,9 +86,10 @@ library SetupPaymentsLib { address strategy, uint32 rewardsCalculationEndTimestamp, uint256 NUM_PAYMENTS, - uint256 NUM_TOKEN_EARNINGS + uint256 NUM_TOKEN_EARNINGS, + string memory filePath ) internal { - bytes32 paymentRoot = createPaymentRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, NUM_PAYMENTS, NUM_TOKEN_EARNINGS, strategy); + bytes32 paymentRoot = createPaymentRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, NUM_PAYMENTS, NUM_TOKEN_EARNINGS, strategy, filePath); rewardsCoordinator.submitRoot(paymentRoot, rewardsCalculationEndTimestamp); } @@ -99,7 +99,8 @@ library SetupPaymentsLib { IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves, uint256 NUM_PAYMENTS, uint256 NUM_TOKEN_EARNINGS, - address strategy + address strategy, + string memory filePath ) internal returns (bytes32) { require(earnerLeaves.length == NUM_PAYMENTS, "Number of earners must match number of payments"); bytes32[] memory leaves = new bytes32[](NUM_PAYMENTS); @@ -109,7 +110,7 @@ library SetupPaymentsLib { leaves[i] = rewardsCoordinator.calculateEarnerLeafHash(earnerLeaves[i]); } - writeLeavesToJson(leaves, tokenLeaves); + writeLeavesToJson(leaves, tokenLeaves, filePath); return (merkleizeKeccak(leaves)); } @@ -158,7 +159,8 @@ library SetupPaymentsLib { function writeLeavesToJson( bytes32[] memory leaves, - bytes32[] memory tokenLeaves + bytes32[] memory tokenLeaves, + string memory filePath ) internal { string memory parent_object = "parent_object"; vm.serializeBytes32(parent_object, "leaves", leaves); @@ -264,8 +266,4 @@ library SetupPaymentsLib { } return paddedLeaves; } - - function getFilePath() public pure returns (string memory) { - return filePath; - } } \ No newline at end of file diff --git a/contracts/test/SetupPaymentsLib.t.sol b/contracts/test/SetupPaymentsLib.t.sol index 9295359..0aeebd6 100644 --- a/contracts/test/SetupPaymentsLib.t.sol +++ b/contracts/test/SetupPaymentsLib.t.sol @@ -38,6 +38,8 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup IStrategy public strategy; address proxyAdmin; + string internal constant filePath = "test/mockData/scratch/payments.json"; + function setUp() public override virtual { proxyAdmin = UpgradeableProxyLib.deployProxyAdmin(); @@ -73,7 +75,7 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves); cheats.startPrank(address(0), address(0)); - SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1); + SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath); cheats.stopPrank(); } @@ -86,7 +88,9 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup tokenLeaves[0] = bytes32(uint256(3)); tokenLeaves[1] = bytes32(uint256(4)); - SetupPaymentsLib.writeLeavesToJson(leaves, tokenLeaves); + string memory filePath = ("payments.json"); + + SetupPaymentsLib.writeLeavesToJson(leaves, tokenLeaves, filePath); assertTrue(vm.exists("payments.json"), "JSON file should be created"); } @@ -146,7 +150,7 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves); cheats.startPrank(address(0)); - SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1); + SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath); cheats.stopPrank(); From 1204c737637ed38f57a92283b249f3c04500254a Mon Sep 17 00:00:00 2001 From: kachapah <60323455+Sidu28@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:01:09 -0700 Subject: [PATCH 2/2] cleanup --- contracts/script/SetupPayments.s.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/script/SetupPayments.s.sol b/contracts/script/SetupPayments.s.sol index 2ffac0b..657f085 100644 --- a/contracts/script/SetupPayments.s.sol +++ b/contracts/script/SetupPayments.s.sol @@ -23,7 +23,7 @@ contract SetupPayments is Script { address private deployer; CoreDeploymentLib.DeploymentData coreDeployment; HelloWorldDeploymentLib.DeploymentData helloWorldDeployment; - string private filePath; + string internal constant filePath = "test/mockData/scratch/payments.json"; uint256 constant NUM_TOKEN_EARNINGS = 1; uint256 constant DURATION = 1 weeks; @@ -51,7 +51,7 @@ contract SetupPayments is Script { earnerTokenRoot: info.earnerTokenRoots[info.indexToProve] }); - processClaim("test/mockData/scratch/payments.json", info.indexToProve, info.recipient, earnerLeaf); + processClaim(filePath, info.indexToProve, info.recipient, earnerLeaf); vm.stopBroadcast(); } @@ -97,7 +97,7 @@ contract SetupPayments is Script { endTimestamp, numPayments, NUM_TOKEN_EARNINGS, - "test/mockData/scratch/payments.json" + filePath ); } } \ No newline at end of file