From fe687078ff4d9502bdd0a6c25b49ddac65a9a994 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Tue, 5 Sep 2023 17:04:34 +0200 Subject: [PATCH 1/9] feat: add URDBundler --- .gitmodules | 3 ++ contracts/ERC4626Bundler.sol | 2 +- contracts/EVMBundler.sol | 5 ++-- contracts/URDBundler.sol | 30 +++++++++++++++++++ .../ethereum-mainnet/EthereumBundler.sol | 2 +- contracts/mocks/ERC20Mock.sol | 2 +- lib/universal-rewards-distributor | 1 + remappings.txt | 3 +- test/EVMBundlerLocalTest.sol | 7 +++-- .../EthereumBundlerEthereumEthereumTest.sol | 7 +++-- .../migration/BaseMigrationTest.sol | 2 +- 11 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 contracts/URDBundler.sol create mode 160000 lib/universal-rewards-distributor diff --git a/.gitmodules b/.gitmodules index e8e9c168..4475c96a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -20,6 +20,9 @@ path = lib/morpho-blue url = https://github.com/morpho-labs/morpho-blue branch = 0.8.21 +[submodule "lib/universal-rewards-distributor"] + path = lib/universal-rewards-distributor + url = https://github.com/morpho-org/universal-rewards-distributor [submodule "lib/solmate"] path = lib/solmate url = https://github.com/transmissions11/solmate diff --git a/contracts/ERC4626Bundler.sol b/contracts/ERC4626Bundler.sol index 0be0ab61..48217230 100644 --- a/contracts/ERC4626Bundler.sol +++ b/contracts/ERC4626Bundler.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol"; +import {IERC4626} from "@openzeppelin/interfaces/IERC4626.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; import {Math} from "@morpho-utils/math/Math.sol"; diff --git a/contracts/EVMBundler.sol b/contracts/EVMBundler.sol index 43bac1e3..12fdcead 100644 --- a/contracts/EVMBundler.sol +++ b/contracts/EVMBundler.sol @@ -3,12 +3,13 @@ pragma solidity 0.8.21; import {ERC20Bundler} from "./ERC20Bundler.sol"; import {ERC4626Bundler} from "./ERC4626Bundler.sol"; +import {URDBundler} from "./URDBundler.sol"; import {MorphoBundler} from "./MorphoBundler.sol"; /// @title EVMBundler /// @author Morpho Labs /// @custom:contact security@morpho.xyz /// @notice Common bundler layer guaranteeing it can be deployed to the same address on all EVM-compatible chains. -contract EVMBundler is ERC20Bundler, ERC4626Bundler, MorphoBundler { - constructor(address morpho) MorphoBundler(morpho) {} +contract EVMBundler is ERC20Bundler, ERC4626Bundler, URDBundler, MorphoBundler { + constructor(address urd, address morpho) URDBundler(urd) MorphoBundler(morpho) {} } diff --git a/contracts/URDBundler.sol b/contracts/URDBundler.sol new file mode 100644 index 00000000..d80c0720 --- /dev/null +++ b/contracts/URDBundler.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity 0.8.21; + +import {MerkleProof} from "@openzeppelin/utils/cryptography/MerkleProof.sol"; +import {IUniversalRewardsDistributor} from "@universal-rewards-distributor/interfaces/IUniversalRewardsDistributor.sol"; + +import {ErrorsLib} from "./libraries/ErrorsLib.sol"; + +import {BaseBundler} from "./BaseBundler.sol"; + +/// @title EVMBundler +/// @author Morpho Labs +/// @custom:contact security@morpho.xyz +/// @notice Common bundler layer guaranteeing it can be deployed to the same address on all EVM-compatible chains. +contract URDBundler is BaseBundler { + IUniversalRewardsDistributor public immutable URD; + + constructor(address urd) { + require(urd != address(0), ErrorsLib.ZERO_ADDRESS); + + URD = IUniversalRewardsDistributor(urd); + } + + function claim(uint256 distributionId, address account, address reward, uint256 claimable, bytes32[] calldata proof) + external + payable + { + URD.claim(distributionId, account, reward, claimable, proof); + } +} diff --git a/contracts/ethereum-mainnet/EthereumBundler.sol b/contracts/ethereum-mainnet/EthereumBundler.sol index 5d5b55bf..4d5bbc0d 100644 --- a/contracts/ethereum-mainnet/EthereumBundler.sol +++ b/contracts/ethereum-mainnet/EthereumBundler.sol @@ -17,5 +17,5 @@ contract EthereumBundler is EVMBundler, WNativeBundler, StEthBundler { /* CONSTRUCTOR */ - constructor(address morpho) EVMBundler(morpho) WNativeBundler(WETH) {} + constructor(address urd, address morpho) EVMBundler(urd, morpho) WNativeBundler(WETH) {} } diff --git a/contracts/mocks/ERC20Mock.sol b/contracts/mocks/ERC20Mock.sol index 3b59792a..a580886c 100644 --- a/contracts/mocks/ERC20Mock.sol +++ b/contracts/mocks/ERC20Mock.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import {ERC20} from "@openzeppelin/token/ERC20/ERC20.sol"; contract ERC20Mock is ERC20 { constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {} diff --git a/lib/universal-rewards-distributor b/lib/universal-rewards-distributor new file mode 160000 index 00000000..426ad796 --- /dev/null +++ b/lib/universal-rewards-distributor @@ -0,0 +1 @@ +Subproject commit 426ad7969840e82a76df24fd4eb5a7d2378accd4 diff --git a/remappings.txt b/remappings.txt index 17f90445..53ccc5fd 100644 --- a/remappings.txt +++ b/remappings.txt @@ -9,8 +9,9 @@ openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/ @morpho-v1/=lib/morpho-v1/src/ @morpho-blue/=lib/morpho-blue/src/ @morpho-utils/=lib/morpho-utils/src/ +@universal-rewards-distributor/=lib/universal-rewards-distributor/src/ @morpho-aave-v3/=lib/morpho-aave-v3/src -@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ +@openzeppelin/=lib/openzeppelin-contracts/contracts/ @permit2/=lib/permit2/src/ @uniswap/v3-core=lib/v3-core/contracts/ diff --git a/test/EVMBundlerLocalTest.sol b/test/EVMBundlerLocalTest.sol index 6690a854..dc1496b3 100644 --- a/test/EVMBundlerLocalTest.sol +++ b/test/EVMBundlerLocalTest.sol @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; +import {UniversalRewardsDistributor} from "@universal-rewards-distributor/UniversalRewardsDistributor.sol"; import {SigUtils} from "test/helpers/SigUtils.sol"; -import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import {ECDSA} from "@openzeppelin/utils/cryptography/ECDSA.sol"; import {ErrorsLib as BulkerErrorsLib} from "contracts/libraries/ErrorsLib.sol"; import "./helpers/LocalTest.sol"; @@ -18,6 +19,7 @@ contract EVMBundlerLocalTest is LocalTest { uint256 internal constant SIG_DEADLINE = type(uint32).max; + UniversalRewardsDistributor private urd; EVMBundler private bundler; ERC4626Mock private vault; bytes[] private bundleData; @@ -25,8 +27,9 @@ contract EVMBundlerLocalTest is LocalTest { function setUp() public override { super.setUp(); + urd = new UniversalRewardsDistributor(); vault = new ERC4626Mock(address(borrowableToken), "borrowable Vault", "BV"); - bundler = new EVMBundler(address(morpho)); + bundler = new EVMBundler(address(urd), address(morpho)); vm.startPrank(USER); borrowableToken.approve(address(morpho), type(uint256).max); diff --git a/test/ethereum-mainnet/EthereumBundlerEthereumEthereumTest.sol b/test/ethereum-mainnet/EthereumBundlerEthereumEthereumTest.sol index 6b2217d8..7f3a8e24 100644 --- a/test/ethereum-mainnet/EthereumBundlerEthereumEthereumTest.sol +++ b/test/ethereum-mainnet/EthereumBundlerEthereumEthereumTest.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.0; import {IAllowanceTransfer} from "@permit2/interfaces/IAllowanceTransfer.sol"; -import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import {ECDSA} from "@openzeppelin/utils/cryptography/ECDSA.sol"; import {ERC20Bundler} from "contracts/ERC20Bundler.sol"; +import {UniversalRewardsDistributor} from "@universal-rewards-distributor/UniversalRewardsDistributor.sol"; import "contracts/ethereum-mainnet/EthereumBundler.sol"; @@ -17,6 +18,7 @@ contract EthereumBundlerEthereumTest is ForkTest { using MarketParamsLib for MarketParams; using SafeTransferLib for ERC20; + UniversalRewardsDistributor private urd; EthereumBundler private bundler; function _network() internal pure override returns (string memory) { @@ -26,7 +28,8 @@ contract EthereumBundlerEthereumTest is ForkTest { function setUp() public override { super.setUp(); - bundler = new EthereumBundler(address(morpho)); + urd = new UniversalRewardsDistributor(); + bundler = new EthereumBundler(address(urd), address(morpho)); vm.prank(USER); morpho.setAuthorization(address(bundler), true); diff --git a/test/ethereum-mainnet/migration/BaseMigrationTest.sol b/test/ethereum-mainnet/migration/BaseMigrationTest.sol index d7785c87..63991413 100644 --- a/test/ethereum-mainnet/migration/BaseMigrationTest.sol +++ b/test/ethereum-mainnet/migration/BaseMigrationTest.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {IAllowanceTransfer} from "@permit2/interfaces/IAllowanceTransfer.sol"; import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; -import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import {ECDSA} from "@openzeppelin/utils/cryptography/ECDSA.sol"; import {MarketParamsLib} from "@morpho-blue/libraries/MarketParamsLib.sol"; import {MorphoLib} from "@morpho-blue/libraries/periphery/MorphoLib.sol"; import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol"; From 83c193098a178f056a0d8086df430b3014089a45 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Tue, 5 Sep 2023 17:14:12 +0200 Subject: [PATCH 2/9] fix: URDBundler natspec --- contracts/URDBundler.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/URDBundler.sol b/contracts/URDBundler.sol index d80c0720..2c4669ee 100644 --- a/contracts/URDBundler.sol +++ b/contracts/URDBundler.sol @@ -8,10 +8,10 @@ import {ErrorsLib} from "./libraries/ErrorsLib.sol"; import {BaseBundler} from "./BaseBundler.sol"; -/// @title EVMBundler +/// @title URDBudnler /// @author Morpho Labs /// @custom:contact security@morpho.xyz -/// @notice Common bundler layer guaranteeing it can be deployed to the same address on all EVM-compatible chains. +/// @notice Bundler that allows to claim token rewards on the Universal Reward Distributor. contract URDBundler is BaseBundler { IUniversalRewardsDistributor public immutable URD; From 5110c0fe631d5d9a7733c3e2ebbeae2f7ed9279d Mon Sep 17 00:00:00 2001 From: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> Date: Tue, 5 Sep 2023 17:46:14 +0200 Subject: [PATCH 3/9] Update contracts/URDBundler.sol Co-authored-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> Signed-off-by: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> --- contracts/URDBundler.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/URDBundler.sol b/contracts/URDBundler.sol index 2c4669ee..b384e53b 100644 --- a/contracts/URDBundler.sol +++ b/contracts/URDBundler.sol @@ -11,7 +11,7 @@ import {BaseBundler} from "./BaseBundler.sol"; /// @title URDBudnler /// @author Morpho Labs /// @custom:contact security@morpho.xyz -/// @notice Bundler that allows to claim token rewards on the Universal Reward Distributor. +/// @notice Bundler that allows to claim token rewards on the Universal Rewards Distributor. contract URDBundler is BaseBundler { IUniversalRewardsDistributor public immutable URD; From 2d66fbdbcea10fd429a002b7c98642e833fd4b02 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Wed, 6 Sep 2023 15:20:10 +0200 Subject: [PATCH 4/9] feat: add tests --- .gitmodules | 3 ++ contracts/URDBundler.sol | 2 +- lib/murky | 1 + remappings.txt | 2 ++ test/EVMBundlerLocalTest.sol | 69 ++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 160000 lib/murky diff --git a/.gitmodules b/.gitmodules index 4475c96a..bd3d4923 100644 --- a/.gitmodules +++ b/.gitmodules @@ -35,3 +35,6 @@ [submodule "lib/morpho-v1"] path = lib/morpho-v1 url = https://github.com/morpho-org/morpho-v1 +[submodule "lib/murky"] + path = lib/murky + url = https://github.com/dmfxyz/murky diff --git a/contracts/URDBundler.sol b/contracts/URDBundler.sol index 2c4669ee..b384e53b 100644 --- a/contracts/URDBundler.sol +++ b/contracts/URDBundler.sol @@ -11,7 +11,7 @@ import {BaseBundler} from "./BaseBundler.sol"; /// @title URDBudnler /// @author Morpho Labs /// @custom:contact security@morpho.xyz -/// @notice Bundler that allows to claim token rewards on the Universal Reward Distributor. +/// @notice Bundler that allows to claim token rewards on the Universal Rewards Distributor. contract URDBundler is BaseBundler { IUniversalRewardsDistributor public immutable URD; diff --git a/lib/murky b/lib/murky new file mode 160000 index 00000000..40de6e80 --- /dev/null +++ b/lib/murky @@ -0,0 +1 @@ +Subproject commit 40de6e80117f39cda69d71b07b7c824adac91b29 diff --git a/remappings.txt b/remappings.txt index 53ccc5fd..e138c5d3 100644 --- a/remappings.txt +++ b/remappings.txt @@ -18,3 +18,5 @@ openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/ @uniswap/v3-periphery=lib/v3-periphery/contracts/ @aave/v3-core=lib/aave-v3-core/contracts/ + +@murky/=lib/murky/ diff --git a/test/EVMBundlerLocalTest.sol b/test/EVMBundlerLocalTest.sol index dc1496b3..48210db2 100644 --- a/test/EVMBundlerLocalTest.sol +++ b/test/EVMBundlerLocalTest.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.0; import {UniversalRewardsDistributor} from "@universal-rewards-distributor/UniversalRewardsDistributor.sol"; + import {SigUtils} from "test/helpers/SigUtils.sol"; import {ECDSA} from "@openzeppelin/utils/cryptography/ECDSA.sol"; import {ErrorsLib as BulkerErrorsLib} from "contracts/libraries/ErrorsLib.sol"; @@ -11,6 +12,8 @@ import "./helpers/LocalTest.sol"; import "contracts/EVMBundler.sol"; import {ERC4626Mock} from "./mocks/ERC4626Mock.sol"; +import {Merkle} from "@murky/src/Merkle.sol"; + contract EVMBundlerLocalTest is LocalTest { using MathLib for uint256; using MorphoLib for IMorpho; @@ -24,12 +27,15 @@ contract EVMBundlerLocalTest is LocalTest { ERC4626Mock private vault; bytes[] private bundleData; + Merkle merkle; + function setUp() public override { super.setUp(); urd = new UniversalRewardsDistributor(); vault = new ERC4626Mock(address(borrowableToken), "borrowable Vault", "BV"); bundler = new EVMBundler(address(urd), address(morpho)); + merkle = new Merkle(); vm.startPrank(USER); borrowableToken.approve(address(morpho), type(uint256).max); @@ -811,4 +817,67 @@ contract EVMBundlerLocalTest is LocalTest { vars.expectedBundlerCollateralBalance += missingAmount; } } + + /* TESTS URDBUNDLER */ + + function testClaimRewards(uint256 claimable, uint8 size) public { + claimable = bound(claimable, 1 ether, 1000 ether); + uint256 boundedSize = bound(size, 2, 20); + + (bytes32[] memory proofs, bytes32 root) = _setupRewards(claimable, boundedSize); + + borrowableToken.setBalance(address(this), claimable); + borrowableToken.approve(address(urd), type(uint256).max); + collateralToken.setBalance(address(this), claimable); + collateralToken.approve(address(urd), type(uint256).max); + + uint256 distribution = urd.createDistribution(0, root); + + bytes32[] memory borrowableTokenProof = merkle.getProof(proofs, 0); + bytes32[] memory collateralTokenProof = merkle.getProof(proofs, 1); + + bytes[] memory data = new bytes[](2); + data[0] = abi.encodeCall( + URDBundler.claim, (distribution, USER, address(borrowableToken), claimable, borrowableTokenProof) + ); + data[1] = abi.encodeCall( + URDBundler.claim, (distribution, USER, address(collateralToken), claimable, collateralTokenProof) + ); + + vm.prank(USER); + bundler.multicall(block.timestamp, data); + + assertEq(borrowableToken.balanceOf(USER), claimable, "User's borrowable balance"); + assertEq(collateralToken.balanceOf(USER), claimable, "User's collateral balance"); + } + + function _setupRewards(uint256 claimable, uint256 size) + internal + view + returns (bytes32[] memory data, bytes32 root) + { + data = new bytes32[](size); + + data[0] = keccak256(bytes.concat(keccak256(abi.encode(USER, address(borrowableToken), claimable)))); + data[1] = keccak256(bytes.concat(keccak256(abi.encode(USER, address(collateralToken), claimable)))); + + uint256 i = 2; + while (i < size / 2) { + uint256 index = i + 1; + data[i] = keccak256( + bytes.concat( + keccak256(abi.encode(vm.addr(index), address(borrowableToken), uint256(claimable / index))) + ) + ); + data[i + 1] = keccak256( + bytes.concat( + keccak256(abi.encode(vm.addr(index), address(collateralToken), uint256(claimable / index))) + ) + ); + + i += 2; + } + + root = merkle.getRoot(data); + } } From d9ec68b63f6bdfb5d31f833391de5c94ab64fa62 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Mon, 11 Sep 2023 10:41:23 +0200 Subject: [PATCH 5/9] fix: appky suggestions --- contracts/URDBundler.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/URDBundler.sol b/contracts/URDBundler.sol index b384e53b..913818fe 100644 --- a/contracts/URDBundler.sol +++ b/contracts/URDBundler.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {MerkleProof} from "@openzeppelin/utils/cryptography/MerkleProof.sol"; import {IUniversalRewardsDistributor} from "@universal-rewards-distributor/interfaces/IUniversalRewardsDistributor.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; @@ -25,6 +24,7 @@ contract URDBundler is BaseBundler { external payable { + require(account != address(0), ErrorsLib.ZERO_ADDRESS); URD.claim(distributionId, account, reward, claimable, proof); } } From 9bfe3c385209405d4c8df424ec169f9e2102d69e Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Mon, 11 Sep 2023 12:45:34 +0200 Subject: [PATCH 6/9] fix: add bundler address error --- contracts/URDBundler.sol | 2 ++ test/EVMBundlerLocalTest.sol | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/contracts/URDBundler.sol b/contracts/URDBundler.sol index 913818fe..0211e59a 100644 --- a/contracts/URDBundler.sol +++ b/contracts/URDBundler.sol @@ -24,7 +24,9 @@ contract URDBundler is BaseBundler { external payable { + require(account != address(this), ErrorsLib.BUNDLER_ADDRESS); require(account != address(0), ErrorsLib.ZERO_ADDRESS); + URD.claim(distributionId, account, reward, claimable, proof); } } diff --git a/test/EVMBundlerLocalTest.sol b/test/EVMBundlerLocalTest.sol index 48210db2..2faf56be 100644 --- a/test/EVMBundlerLocalTest.sol +++ b/test/EVMBundlerLocalTest.sol @@ -820,6 +820,33 @@ contract EVMBundlerLocalTest is LocalTest { /* TESTS URDBUNDLER */ + function testClaimRewardsIncorrectAddresses(uint256 claimable, uint8 size) public { + claimable = bound(claimable, 1 ether, 1000 ether); + uint256 boundedSize = bound(size, 2, 20); + + (bytes32[] memory proofs, bytes32 root) = _setupRewards(claimable, boundedSize); + + uint256 distribution = urd.createDistribution(0, root); + + bytes32[] memory proof = merkle.getProof(proofs, 0); + + bytes[] memory zeroAddressdata = new bytes[](1); + bytes[] memory bundlerAddressdata = new bytes[](1); + zeroAddressdata[0] = abi.encodeCall( + URDBundler.claim, (distribution, address(0), address(borrowableToken), claimable, proof) + ); + bundlerAddressdata[0] = abi.encodeCall( + URDBundler.claim, (distribution, address(bundler), address(borrowableToken), claimable, proof) + ); + + vm.startPrank(USER); + vm.expectRevert(bytes(BulkerErrorsLib.ZERO_ADDRESS)); + bundler.multicall(block.timestamp, zeroAddressdata); + vm.expectRevert(bytes(BulkerErrorsLib.BUNDLER_ADDRESS)); + bundler.multicall(block.timestamp, bundlerAddressdata); + vm.stopPrank(); + } + function testClaimRewards(uint256 claimable, uint8 size) public { claimable = bound(claimable, 1 ether, 1000 ether); uint256 boundedSize = bound(size, 2, 20); From f79626628803aac9cacf314d6496e458021b6515 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Mon, 11 Sep 2023 12:51:40 +0200 Subject: [PATCH 7/9] fix: lint --- test/EVMBundlerLocalTest.sol | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/EVMBundlerLocalTest.sol b/test/EVMBundlerLocalTest.sol index 2faf56be..fb63c8ee 100644 --- a/test/EVMBundlerLocalTest.sol +++ b/test/EVMBundlerLocalTest.sol @@ -829,12 +829,11 @@ contract EVMBundlerLocalTest is LocalTest { uint256 distribution = urd.createDistribution(0, root); bytes32[] memory proof = merkle.getProof(proofs, 0); - + bytes[] memory zeroAddressdata = new bytes[](1); bytes[] memory bundlerAddressdata = new bytes[](1); - zeroAddressdata[0] = abi.encodeCall( - URDBundler.claim, (distribution, address(0), address(borrowableToken), claimable, proof) - ); + zeroAddressdata[0] = + abi.encodeCall(URDBundler.claim, (distribution, address(0), address(borrowableToken), claimable, proof)); bundlerAddressdata[0] = abi.encodeCall( URDBundler.claim, (distribution, address(bundler), address(borrowableToken), claimable, proof) ); From eb1bae4f0e32a0c3e8cd9ed9e6d57b1f893d1a52 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Tue, 12 Sep 2023 10:23:27 +0200 Subject: [PATCH 8/9] fix: apply suggestions --- test/EVMBundlerLocalTest.sol | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/EVMBundlerLocalTest.sol b/test/EVMBundlerLocalTest.sol index fb63c8ee..f3006d51 100644 --- a/test/EVMBundlerLocalTest.sol +++ b/test/EVMBundlerLocalTest.sol @@ -820,30 +820,39 @@ contract EVMBundlerLocalTest is LocalTest { /* TESTS URDBUNDLER */ - function testClaimRewardsIncorrectAddresses(uint256 claimable, uint8 size) public { - claimable = bound(claimable, 1 ether, 1000 ether); - uint256 boundedSize = bound(size, 2, 20); + function testClaimRewardsZeroAddresses(uint256 claimable) public { + claimable = bound(claimable, MIN_AMOUNT, MAX_AMOUNT); - (bytes32[] memory proofs, bytes32 root) = _setupRewards(claimable, boundedSize); + bytes32 root; + bytes32[] memory proof; uint256 distribution = urd.createDistribution(0, root); - bytes32[] memory proof = merkle.getProof(proofs, 0); - bytes[] memory zeroAddressdata = new bytes[](1); - bytes[] memory bundlerAddressdata = new bytes[](1); zeroAddressdata[0] = abi.encodeCall(URDBundler.claim, (distribution, address(0), address(borrowableToken), claimable, proof)); + + vm.prank(USER); + vm.expectRevert(bytes(BulkerErrorsLib.ZERO_ADDRESS)); + bundler.multicall(block.timestamp, zeroAddressdata); + } + + function testClaimRewardsBundlerAddresses(uint256 claimable) public { + claimable = bound(claimable, MIN_AMOUNT, MAX_AMOUNT); + + bytes32 root; + bytes32[] memory proof; + + uint256 distribution = urd.createDistribution(0, root); + + bytes[] memory bundlerAddressdata = new bytes[](1); bundlerAddressdata[0] = abi.encodeCall( URDBundler.claim, (distribution, address(bundler), address(borrowableToken), claimable, proof) ); - vm.startPrank(USER); - vm.expectRevert(bytes(BulkerErrorsLib.ZERO_ADDRESS)); - bundler.multicall(block.timestamp, zeroAddressdata); + vm.prank(USER); vm.expectRevert(bytes(BulkerErrorsLib.BUNDLER_ADDRESS)); bundler.multicall(block.timestamp, bundlerAddressdata); - vm.stopPrank(); } function testClaimRewards(uint256 claimable, uint8 size) public { From 03a61d223b7c0a1bf8e9e8a09ef9b019ac61e1f3 Mon Sep 17 00:00:00 2001 From: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:00:41 +0200 Subject: [PATCH 9/9] test: fix naming Signed-off-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> --- test/EVMBundlerLocalTest.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/EVMBundlerLocalTest.sol b/test/EVMBundlerLocalTest.sol index f93f368b..4fdd1c6d 100644 --- a/test/EVMBundlerLocalTest.sol +++ b/test/EVMBundlerLocalTest.sol @@ -1011,7 +1011,7 @@ contract EVMBundlerLocalTest is LocalTest { /* TESTS URDBUNDLER */ - function testClaimRewardsZeroAddresses(uint256 claimable) public { + function testClaimRewardsZeroAddress(uint256 claimable) public { claimable = bound(claimable, MIN_AMOUNT, MAX_AMOUNT); bytes32 root; @@ -1028,7 +1028,7 @@ contract EVMBundlerLocalTest is LocalTest { bundler.multicall(block.timestamp, zeroAddressdata); } - function testClaimRewardsBundlerAddresses(uint256 claimable) public { + function testClaimRewardsBundlerAddress(uint256 claimable) public { claimable = bound(claimable, MIN_AMOUNT, MAX_AMOUNT); bytes32 root;