Skip to content

Commit

Permalink
fix: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Sep 19, 2023
1 parent dd4716e commit a06005a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
6 changes: 3 additions & 3 deletions contracts/URDBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {BaseBundler} from "./BaseBundler.sol";
/// @custom:contact [email protected]
/// @notice Bundler that allows to claim token rewards on the Universal Rewards Distributor.
contract URDBundler is BaseBundler {
function claim(address distribution, address account, address reward, uint256 claimable, bytes32[] calldata proof)
function claim(address distributor, address account, address reward, uint256 claimable, bytes32[] calldata proof)
external
payable
{
require(distribution != address(0), ErrorsLib.ZERO_ADDRESS);
require(distributor != address(0), ErrorsLib.ZERO_ADDRESS);
require(account != address(0), ErrorsLib.ZERO_ADDRESS);
require(account != address(this), ErrorsLib.BUNDLER_ADDRESS);

IUniversalRewardsDistributor(distribution).claim(account, reward, claimable, proof);
IUniversalRewardsDistributor(distributor).claim(account, reward, claimable, proof);
}
}
47 changes: 25 additions & 22 deletions test/forge/EVMBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,11 @@ contract EVMBundlerLocalTest is LocalTest {
bytes32[] memory proof;

bytes[] memory zeroAddressdata = new bytes[](1);
zeroAddressdata[0] =
abi.encodeCall(URDBundler.claim, (address(0), account, address(borrowableToken), claimable, proof));
bundle.push(abi.encodeCall(URDBundler.claim, (address(0), account, address(borrowableToken), claimable, proof)));

vm.prank(USER);
vm.expectRevert(bytes(ErrorsLib.ZERO_ADDRESS));
bundler.multicall(block.timestamp, zeroAddressdata);
bundler.multicall(block.timestamp, bundle);
}

function testClaimRewardsZeroAddressAccount(uint256 claimable) public {
Expand All @@ -805,15 +804,15 @@ contract EVMBundlerLocalTest is LocalTest {
bytes32 root;
bytes32[] memory proof;

address distribution = factory.createUrd(OWNER, 0, root, hex"", hex"");
address distributor = factory.createUrd(OWNER, 0, root, hex"", hex"");

bytes[] memory zeroAddressdata = new bytes[](1);
zeroAddressdata[0] =
abi.encodeCall(URDBundler.claim, (distribution, address(0), address(borrowableToken), claimable, proof));
bundle.push(
abi.encodeCall(URDBundler.claim, (distributor, address(0), address(borrowableToken), claimable, proof))
);

vm.prank(USER);
vm.expectRevert(bytes(ErrorsLib.ZERO_ADDRESS));
bundler.multicall(block.timestamp, zeroAddressdata);
bundler.multicall(block.timestamp, bundle);
}

function testClaimRewardsBundlerAddress(uint256 claimable) public {
Expand All @@ -822,16 +821,17 @@ contract EVMBundlerLocalTest is LocalTest {
bytes32 root;
bytes32[] memory proof;

address distribution = factory.createUrd(OWNER, 0, root, hex"", hex"");
address distributor = factory.createUrd(OWNER, 0, root, hex"", hex"");

bytes[] memory bundlerAddressdata = new bytes[](1);
bundlerAddressdata[0] = abi.encodeCall(
URDBundler.claim, (distribution, address(bundler), address(borrowableToken), claimable, proof)
bundle.push(
abi.encodeCall(
URDBundler.claim, (distributor, address(bundler), address(borrowableToken), claimable, proof)
)
);

vm.prank(USER);
vm.expectRevert(bytes(ErrorsLib.BUNDLER_ADDRESS));
bundler.multicall(block.timestamp, bundlerAddressdata);
bundler.multicall(block.timestamp, bundle);
}

function testClaimRewards(uint256 claimable, uint8 size) public {
Expand All @@ -840,24 +840,27 @@ contract EVMBundlerLocalTest is LocalTest {

(bytes32[] memory proofs, bytes32 root) = _setupRewards(claimable, boundedSize);

address distribution = factory.createUrd(OWNER, 0, root, hex"", hex"");
address distributor = factory.createUrd(OWNER, 0, root, hex"", hex"");

borrowableToken.setBalance(distribution, claimable);
collateralToken.setBalance(distribution, claimable);
borrowableToken.setBalance(distributor, claimable);
collateralToken.setBalance(distributor, claimable);

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)
bundle.push(
abi.encodeCall(
URDBundler.claim, (distributor, USER, address(borrowableToken), claimable, borrowableTokenProof)
)
);
data[1] = abi.encodeCall(
URDBundler.claim, (distribution, USER, address(collateralToken), claimable, collateralTokenProof)
bundle.push(
abi.encodeCall(
URDBundler.claim, (distributor, USER, address(collateralToken), claimable, collateralTokenProof)
)
);

vm.prank(USER);
bundler.multicall(block.timestamp, data);
bundler.multicall(block.timestamp, bundle);

assertEq(borrowableToken.balanceOf(USER), claimable, "User's borrowable balance");
assertEq(collateralToken.balanceOf(USER), claimable, "User's collateral balance");
Expand Down

0 comments on commit a06005a

Please sign in to comment.