Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update URDBundler #177

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 distribution, address account, address reward, uint256 claimable, bytes32[] calldata proof)
external
payable
{
require(distribution != address(0), ErrorsLib.ZERO_ADDRESS);
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved
require(account != address(0), ErrorsLib.ZERO_ADDRESS);
require(account != address(this), ErrorsLib.BUNDLER_ADDRESS);

URD.claim(distributionId, account, reward, claimable, proof);
IUniversalRewardsDistributor(distribution).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
36 changes: 25 additions & 11 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,13 +784,28 @@ 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;

bytes[] memory zeroAddressdata = new bytes[](1);
zeroAddressdata[0] =
abi.encodeCall(URDBundler.claim, (address(0), account, address(borrowableToken), claimable, proof));
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

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

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

bytes32 root;
bytes32[] memory proof;

uint256 distribution = urd.createDistribution(0, root);
address distribution = factory.createUrd(OWNER, 0, root, hex"", hex"");

bytes[] memory zeroAddressdata = new bytes[](1);
zeroAddressdata[0] =
Expand All @@ -806,7 +822,7 @@ contract EVMBundlerLocalTest is LocalTest {
bytes32 root;
bytes32[] memory proof;

uint256 distribution = urd.createDistribution(0, root);
address distribution = factory.createUrd(OWNER, 0, root, hex"", hex"");

bytes[] memory bundlerAddressdata = new bytes[](1);
bundlerAddressdata[0] = abi.encodeCall(
Expand All @@ -824,12 +840,10 @@ 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 distribution = factory.createUrd(OWNER, 0, root, hex"", hex"");

uint256 distribution = urd.createDistribution(0, root);
borrowableToken.setBalance(distribution, claimable);
collateralToken.setBalance(distribution, claimable);

bytes32[] memory borrowableTokenProof = merkle.getProof(proofs, 0);
bytes32[] memory collateralTokenProof = merkle.getProof(proofs, 1);
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