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

BaseBundler renaming #434

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

![image (4)](https://github.com/morpho-org/morpho-blue-bundlers/assets/44097430/5cb0796b-c20c-415e-840d-8b0705836dc8)

Each Bundler is a domain-specific abstract layer of contract that implements some functions that can be bundled in a single call by EOAs to a single contract. They all inherit from [`BaseBundler`](./src/BaseBundler.sol) that enables bundling multiple function calls into a single `multicall(bytes[] calldata data)` call to the end bundler contract. Each chain-specific bundler is available under their chain-specific folder (e.g. [`ethereum`](./src/ethereum/)).
Each Bundler is a domain-specific abstract layer of contract that implements some functions that can be bundled in a single call by EOAs to a single contract. They all inherit from [`CoreBundler`](./src/CoreBundler.sol) that enables bundling multiple function calls into a single `multicall(bytes[] calldata data)` call to the end bundler contract. Each chain-specific bundler is available under their chain-specific folder (e.g. [`ethereum`](./src/ethereum/)).

Some chain-specific domains are also scoped to the chain-specific folder, because they are not expected to be used on any other chain (e.g. DAI and its specific `permit` function is only available on Ethereum - see [`EthereumPermitBundler`](./src/ethereum/EthereumPermitBundler.sol)).

Expand Down
4 changes: 2 additions & 2 deletions src/BaseBundler.sol → src/CoreBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {UNSET_INITIATOR} from "./libraries/ConstantsLib.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";

/// @title BaseBundler
/// @title CoreBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Enables calling multiple functions in a single call to the same contract (self).
/// @dev Every bundler must inherit from this contract.
/// @dev Every bundler inheriting from this contract must have their external functions payable as they will be
/// delegate called by the `multicall` function (which is payable, and thus might pass a non-null ETH value). It is
/// recommended not to rely on `msg.value` as the same value can be reused for multiple calls.
abstract contract BaseBundler is IMulticall {
abstract contract CoreBundler is IMulticall {
using SafeTransferLib for ERC20;

/* STORAGE */
Expand Down
4 changes: 2 additions & 2 deletions src/ERC20WrapperBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {Math} from "../lib/morpho-utils/src/math/Math.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";
import {ERC20Wrapper} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Wrapper.sol";

/// @title ERC20WrapperBundler
Expand All @@ -14,7 +14,7 @@ import {ERC20Wrapper} from "../lib/openzeppelin-contracts/contracts/token/ERC20/
/// @notice Enables the wrapping and unwrapping of ERC20 tokens. The largest usecase is to wrap permissionless tokens to
/// their permissioned counterparts and access permissioned markets on Morpho Blue. Permissioned tokens can be built
/// using: https://github.com/morpho-org/erc20-permissioned
abstract contract ERC20WrapperBundler is BaseBundler {
abstract contract ERC20WrapperBundler is CoreBundler {
using SafeTransferLib for ERC20;

/* WRAPPER ACTIONS */
Expand Down
4 changes: 2 additions & 2 deletions src/ERC4626Bundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {Math} from "../lib/morpho-utils/src/math/Math.sol";
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title ERC4626Bundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Bundler contract managing interactions with ERC4626 compliant tokens.
abstract contract ERC4626Bundler is BaseBundler {
abstract contract ERC4626Bundler is CoreBundler {
using SafeTransferLib for ERC20;

/* ACTIONS */
Expand Down
6 changes: 3 additions & 3 deletions src/MorphoBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {MarketParams, Signature, Authorization, IMorpho} from "../lib/morpho-blu
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title MorphoBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Bundler contract managing interactions with Morpho.
abstract contract MorphoBundler is BaseBundler, IMorphoBundler {
abstract contract MorphoBundler is CoreBundler, IMorphoBundler {
using SafeTransferLib for ERC20;

/* IMMUTABLES */
Expand Down Expand Up @@ -264,7 +264,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler {
_multicall(abi.decode(data, (bytes[])));
}

/// @inheritdoc BaseBundler
/// @inheritdoc CoreBundler
function _isSenderAuthorized() internal view virtual override returns (bool) {
return super._isSenderAuthorized() || msg.sender == address(MORPHO);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Permit2Bundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {Permit2Lib} from "../lib/permit2/src/libraries/Permit2Lib.sol";
import {SafeCast160} from "../lib/permit2/src/libraries/SafeCast160.sol";
import {ERC20} from "../lib/solmate/src/tokens/ERC20.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title Permit2Bundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Bundler contract managing interactions with Uniswap's Permit2.
abstract contract Permit2Bundler is BaseBundler {
abstract contract Permit2Bundler is CoreBundler {
using SafeCast160 for uint256;

/* ACTIONS */
Expand Down
4 changes: 2 additions & 2 deletions src/PermitBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pragma solidity 0.8.24;

import {IERC20Permit} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title PermitBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Bundler contract managing interactions with tokens implementing EIP-2612.
abstract contract PermitBundler is BaseBundler {
abstract contract PermitBundler is CoreBundler {
/// @notice Permits the given `amount` of `asset` from sender to be spent by the bundler via EIP-2612 Permit with
/// the given `deadline` & EIP-712 signature's `v`, `r` & `s`.
/// @param asset The address of the token to be permitted.
Expand Down
4 changes: 2 additions & 2 deletions src/StEthBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {Math} from "../lib/morpho-utils/src/math/Math.sol";
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title StEthBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Contract allowing to bundle multiple interactions with stETH together.
abstract contract StEthBundler is BaseBundler {
abstract contract StEthBundler is CoreBundler {
using SafeTransferLib for ERC20;

/* IMMUTABLES */
Expand Down
4 changes: 2 additions & 2 deletions src/TransferBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {Math} from "../lib/morpho-utils/src/math/Math.sol";
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title TransferBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Enables transfer of ERC20 and native tokens.
/// @dev Assumes that any tokens left on the contract can be seized by anyone.
abstract contract TransferBundler is BaseBundler {
abstract contract TransferBundler is CoreBundler {
using SafeTransferLib for ERC20;

/* TRANSFER ACTIONS */
Expand Down
4 changes: 2 additions & 2 deletions src/UrdBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {IUniversalRewardsDistributor} from

import {ErrorsLib} from "./libraries/ErrorsLib.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title UrdBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Bundler that allows to claim token rewards on the Universal Rewards Distributor.
abstract contract UrdBundler is BaseBundler {
abstract contract UrdBundler is CoreBundler {
/// @notice Claims `amount` of `reward` on behalf of `account` on the given rewards distributor, using `proof`.
/// @dev Assumes the given distributor implements IUniversalRewardsDistributor.
/// @param distributor The address of the reward distributor contract.
Expand Down
4 changes: 2 additions & 2 deletions src/WNativeBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {Math} from "../lib/morpho-utils/src/math/Math.sol";
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";

import {BaseBundler} from "./BaseBundler.sol";
import {CoreBundler} from "./CoreBundler.sol";

/// @title WNativeBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Bundler contract managing interactions with network's wrapped native token.
/// @notice "wrapped native" refers to forks of WETH.
abstract contract WNativeBundler is BaseBundler {
abstract contract WNativeBundler is CoreBundler {
using SafeTransferLib for ERC20;

/* IMMUTABLES */
Expand Down
4 changes: 2 additions & 2 deletions src/base/BaseBundlerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.24;

import {BaseLib} from "./libraries/BaseLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {CoreBundler} from "../CoreBundler.sol";
import {TransferBundler} from "../TransferBundler.sol";
import {Permit2Bundler} from "../Permit2Bundler.sol";
import {ERC4626Bundler} from "../ERC4626Bundler.sol";
Expand Down Expand Up @@ -32,7 +32,7 @@ contract BaseBundlerV2 is
/* INTERNAL */

/// @inheritdoc MorphoBundler
function _isSenderAuthorized() internal view override(BaseBundler, MorphoBundler) returns (bool) {
function _isSenderAuthorized() internal view override(CoreBundler, MorphoBundler) returns (bool) {
return MorphoBundler._isSenderAuthorized();
}
}
4 changes: 2 additions & 2 deletions src/ethereum/EthereumBundlerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.24;

import {MainnetLib} from "./libraries/MainnetLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {CoreBundler} from "../CoreBundler.sol";
import {TransferBundler} from "../TransferBundler.sol";
import {EthereumPermitBundler} from "./EthereumPermitBundler.sol";
import {Permit2Bundler} from "../Permit2Bundler.sol";
Expand Down Expand Up @@ -36,7 +36,7 @@ contract EthereumBundlerV2 is
/* INTERNAL */

/// @inheritdoc MorphoBundler
function _isSenderAuthorized() internal view override(BaseBundler, MorphoBundler) returns (bool) {
function _isSenderAuthorized() internal view override(CoreBundler, MorphoBundler) returns (bool) {
return MorphoBundler._isSenderAuthorized();
}
}
4 changes: 2 additions & 2 deletions src/goerli/GoerliBundlerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.24;

import {GoerliLib} from "./libraries/GoerliLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {CoreBundler} from "../CoreBundler.sol";
import {TransferBundler} from "../TransferBundler.sol";
import {PermitBundler} from "../PermitBundler.sol";
import {Permit2Bundler} from "../Permit2Bundler.sol";
Expand Down Expand Up @@ -36,7 +36,7 @@ contract GoerliBundlerV2 is
/* INTERNAL */

/// @inheritdoc MorphoBundler
function _isSenderAuthorized() internal view override(BaseBundler, MorphoBundler) returns (bool) {
function _isSenderAuthorized() internal view override(CoreBundler, MorphoBundler) returns (bool) {
return MorphoBundler._isSenderAuthorized();
}
}
4 changes: 2 additions & 2 deletions src/migration/AaveV2MigrationBundlerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV2} from "./interfaces/IAaveV2.sol";
import {Math} from "../../lib/morpho-utils/src/math/Math.sol";
import {ErrorsLib} from "../libraries/ErrorsLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {CoreBundler} from "../CoreBundler.sol";
import {StEthBundler} from "../StEthBundler.sol";
import {MigrationBundler, ERC20} from "./MigrationBundler.sol";

Expand Down Expand Up @@ -62,7 +62,7 @@ contract AaveV2MigrationBundlerV2 is MigrationBundler, StEthBundler {
/* INTERNAL */

/// @inheritdoc MigrationBundler
function _isSenderAuthorized() internal view virtual override(BaseBundler, MigrationBundler) returns (bool) {
function _isSenderAuthorized() internal view virtual override(CoreBundler, MigrationBundler) returns (bool) {
return MigrationBundler._isSenderAuthorized();
}
}
4 changes: 2 additions & 2 deletions src/migration/CompoundV2MigrationBundlerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ICToken} from "./interfaces/ICToken.sol";
import {Math} from "../../lib/morpho-utils/src/math/Math.sol";
import {ErrorsLib} from "../libraries/ErrorsLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {CoreBundler} from "../CoreBundler.sol";
import {WNativeBundler} from "../WNativeBundler.sol";
import {MigrationBundler, ERC20} from "./MigrationBundler.sol";

Expand Down Expand Up @@ -80,7 +80,7 @@ contract CompoundV2MigrationBundlerV2 is WNativeBundler, MigrationBundler {
/* INTERNAL */

/// @inheritdoc MigrationBundler
function _isSenderAuthorized() internal view override(BaseBundler, MigrationBundler) returns (bool) {
function _isSenderAuthorized() internal view override(CoreBundler, MigrationBundler) returns (bool) {
return MigrationBundler._isSenderAuthorized();
}
}
4 changes: 2 additions & 2 deletions src/migration/MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.24;

import {SafeTransferLib, ERC20} from "../../lib/solmate/src/utils/SafeTransferLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {CoreBundler} from "../CoreBundler.sol";
import {TransferBundler} from "../TransferBundler.sol";
import {PermitBundler} from "../PermitBundler.sol";
import {Permit2Bundler} from "../Permit2Bundler.sol";
Expand All @@ -24,7 +24,7 @@ abstract contract MigrationBundler is TransferBundler, PermitBundler, Permit2Bun
/* INTERNAL */

/// @inheritdoc MorphoBundler
function _isSenderAuthorized() internal view virtual override(BaseBundler, MorphoBundler) returns (bool) {
function _isSenderAuthorized() internal view virtual override(CoreBundler, MorphoBundler) returns (bool) {
return MorphoBundler._isSenderAuthorized();
}
}
6 changes: 0 additions & 6 deletions src/mocks/bundlers/BaseBundlerMock.sol

This file was deleted.

6 changes: 6 additions & 0 deletions src/mocks/bundlers/CoreBundlerMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import "../../CoreBundler.sol";

contract CoreBundlerMock is CoreBundler {}
2 changes: 1 addition & 1 deletion src/mocks/bundlers/MorphoBundlerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {MorphoBundler} from "../../MorphoBundler.sol";
contract MorphoBundlerMock is TransferBundler, MorphoBundler {
constructor(address morpho) MorphoBundler(morpho) {}

function _isSenderAuthorized() internal view override(BaseBundler, MorphoBundler) returns (bool) {
function _isSenderAuthorized() internal view override(CoreBundler, MorphoBundler) returns (bool) {
return MorphoBundler._isSenderAuthorized();
}
}
4 changes: 2 additions & 2 deletions src/sepolia/SepoliaBundlerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.24;

import {SepoliaLib} from "./libraries/SepoliaLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {CoreBundler} from "../CoreBundler.sol";
import {TransferBundler} from "../TransferBundler.sol";
import {PermitBundler} from "../PermitBundler.sol";
import {Permit2Bundler} from "../Permit2Bundler.sol";
Expand Down Expand Up @@ -40,7 +40,7 @@ contract SepoliaBundlerV2 is
/* INTERNAL */

/// @inheritdoc MorphoBundler
function _isSenderAuthorized() internal view override(BaseBundler, MorphoBundler) returns (bool) {
function _isSenderAuthorized() internal view override(CoreBundler, MorphoBundler) returns (bool) {
return MorphoBundler._isSenderAuthorized();
}
}
4 changes: 2 additions & 2 deletions test/forge/BaseBundlerEnshrinedLocalTest.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {BaseBundler} from "src/mocks/bundlers/BaseBundlerMock.sol";
import {CoreBundler} from "src/mocks/bundlers/CoreBundlerMock.sol";

import "./helpers/LocalTest.sol";

contract BaseBundlerEnshrinedLocalTest is BaseBundler, LocalTest {
contract CoreBundlerEnshrinedLocalTest is CoreBundler, LocalTest {
function checkInitiator(address expectedInitiator) public payable protected {
require(initiator() == expectedInitiator, "unexpected initiator");
}
Expand Down
8 changes: 4 additions & 4 deletions test/forge/BaseBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ pragma solidity ^0.8.0;

import {ErrorsLib} from "src/libraries/ErrorsLib.sol";

import "src/mocks/bundlers/BaseBundlerMock.sol";
import "src/mocks/bundlers/CoreBundlerMock.sol";

import "./helpers/LocalTest.sol";

contract BaseBundlerLocalTest is LocalTest {
contract CoreBundlerLocalTest is LocalTest {
function setUp() public override {
super.setUp();

bundler = new BaseBundlerMock();
bundler = new CoreBundlerMock();
}

function testMulticallEmpty() public {
bundler.multicall(bundle);
}

function testNestedMulticall() public {
bundle.push(abi.encodeCall(BaseBundler.multicall, (callbackBundle)));
bundle.push(abi.encodeCall(CoreBundler.multicall, (callbackBundle)));

vm.expectRevert(bytes(ErrorsLib.ALREADY_INITIATED));
bundler.multicall(bundle);
Expand Down
4 changes: 2 additions & 2 deletions test/forge/fork/helpers/ForkTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {WNativeBundler} from "../../../../src/WNativeBundler.sol";
import {StEthBundler} from "../../../../src/StEthBundler.sol";

import "../../../../config/Configured.sol";
import "../../helpers/BaseTest.sol";
import "../../helpers/CommonTest.sol";

abstract contract ForkTest is BaseTest, Configured {
abstract contract ForkTest is CommonTest, Configured {
using ConfigLib for Config;
using SafeTransferLib for ERC20;

Expand Down
2 changes: 1 addition & 1 deletion test/forge/fork/migration/helpers/MigrationForkTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Market} from "../../../../../lib/morpho-blue/src/interfaces/IMorpho.sol"
import {MorphoBalancesLib} from "../../../../../lib/morpho-blue/src/libraries/periphery/MorphoBalancesLib.sol";

import "../../helpers/ForkTest.sol";
import {BaseBundler} from "../../../../../src/BaseBundler.sol";
import {CoreBundler} from "../../../../../src/CoreBundler.sol";
import {PermitBundler} from "../../../../../src/PermitBundler.sol";
import {Permit2Bundler} from "../../../../../src/Permit2Bundler.sol";
import {ERC4626Bundler} from "../../../../../src/ERC4626Bundler.sol";
Expand Down
Loading
Loading