Skip to content

Commit

Permalink
Merge pull request #177 from morpho-labs/feat/update-URD
Browse files Browse the repository at this point in the history
update URDBundler
  • Loading branch information
Rubilmax authored Sep 20, 2023
2 parents 25799fe + 81c2f5c commit 7b8f371
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion contracts/EVMBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import {ERC4626Bundler} from "./ERC4626Bundler.sol";
/// @custom:contact [email protected]
/// @notice Common bundler layer guaranteeing it can be deployed to the same address on all EVM-compatible chains.
contract EVMBundler is Permit2Bundler, ERC4626Bundler, URDBundler, MorphoBundler {
constructor(address urd, address morpho) URDBundler(urd) MorphoBundler(morpho) {}
constructor(address morpho) MorphoBundler(morpho) {}
}
13 changes: 3 additions & 10 deletions contracts/URDBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +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 {
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)
function claim(address distributor, address account, address reward, uint256 claimable, bytes32[] calldata proof)
external
payable
{
require(distributor != address(0), ErrorsLib.ZERO_ADDRESS);
require(account != address(0), ErrorsLib.ZERO_ADDRESS);
require(account != address(this), ErrorsLib.BUNDLER_ADDRESS);

URD.claim(distributionId, account, reward, claimable, proof);
IUniversalRewardsDistributor(distributor).claim(account, reward, claimable, proof);
}
}
2 changes: 1 addition & 1 deletion contracts/ethereum-mainnet/EthereumBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ import {WNativeBundler} from "../WNativeBundler.sol";
contract EthereumBundler is EVMBundler, WNativeBundler, StEthBundler {
/* CONSTRUCTOR */

constructor(address urd, address morpho) EVMBundler(urd, morpho) WNativeBundler(WETH) {}
constructor(address morpho) EVMBundler(morpho) WNativeBundler(WETH) {}
}
2 changes: 1 addition & 1 deletion lib/morpho-blue
66 changes: 41 additions & 25 deletions test/forge/EVMBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.0;

import {UniversalRewardsDistributor} from "@universal-rewards-distributor/UniversalRewardsDistributor.sol";
import {UrdFactory} from "@universal-rewards-distributor/UrdFactory.sol";

import {SigUtils} from "./helpers/SigUtils.sol";
import {ErrorsLib} from "contracts/libraries/ErrorsLib.sol";
Expand All @@ -22,7 +23,7 @@ contract EVMBundlerLocalTest is LocalTest {

uint256 internal constant SIG_DEADLINE = type(uint32).max;

UniversalRewardsDistributor private urd;
UrdFactory private factory;
EVMBundler private bundler;

bytes[] private bundle;
Expand All @@ -32,8 +33,8 @@ contract EVMBundlerLocalTest is LocalTest {
function setUp() public override {
super.setUp();

urd = new UniversalRewardsDistributor();
bundler = new EVMBundler(address(urd),address(morpho));
factory = new UrdFactory();
bundler = new EVMBundler(address(morpho));
merkle = new Merkle();

vm.startPrank(USER);
Expand Down Expand Up @@ -783,21 +784,34 @@ contract EVMBundlerLocalTest is LocalTest {

/* TESTS URDBUNDLER */

function testClaimRewardsZeroAddress(uint256 claimable) public {
function testClaimRewardsZeroAddressDistribution(uint256 claimable, address account) public {
vm.assume(account != address(0));
claimable = bound(claimable, MIN_AMOUNT, MAX_AMOUNT);

bytes32[] memory 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, bundle);
}

function testClaimRewardsZeroAddressAccount(uint256 claimable) public {
claimable = bound(claimable, MIN_AMOUNT, MAX_AMOUNT);

bytes32 root;
bytes32[] memory proof;

uint256 distribution = urd.createDistribution(0, root);
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 @@ -806,16 +820,17 @@ contract EVMBundlerLocalTest is LocalTest {
bytes32 root;
bytes32[] memory proof;

uint256 distribution = urd.createDistribution(0, root);
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 @@ -824,26 +839,27 @@ contract EVMBundlerLocalTest is LocalTest {

(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);
address distributor = factory.createUrd(OWNER, 0, root, hex"", hex"");

uint256 distribution = urd.createDistribution(0, root);
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
5 changes: 1 addition & 4 deletions test/forge/ethereum-mainnet/EthereumBundlerEthereumTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.0;
import {IAllowanceTransfer} from "@permit2/interfaces/IAllowanceTransfer.sol";

import {ECDSA} from "@openzeppelin/utils/cryptography/ECDSA.sol";
import {UniversalRewardsDistributor} from "@universal-rewards-distributor/UniversalRewardsDistributor.sol";

import "contracts/ethereum-mainnet/EthereumBundler.sol";
import {MorphoBundler} from "contracts/MorphoBundler.sol";
Expand All @@ -19,14 +18,12 @@ contract EthereumBundlerEthereumTest is EthereumTest {
using MarketParamsLib for MarketParams;
using SafeTransferLib for ERC20;

UniversalRewardsDistributor private urd;
EthereumBundler private bundler;

function setUp() public override {
super.setUp();

urd = new UniversalRewardsDistributor();
bundler = new EthereumBundler(address(urd), address(morpho));
bundler = new EthereumBundler(address(morpho));

vm.prank(USER);
morpho.setAuthorization(address(bundler), true);
Expand Down

0 comments on commit 7b8f371

Please sign in to comment.