From 916e28b64c6e116d901121b0f424cd268906265a Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 11:48:20 +0200 Subject: [PATCH 01/17] fix: review of the base contracts --- README.md | 11 +++++ src/BaseBundler.sol | 20 +++------ src/ERC4626Bundler.sol | 4 ++ src/Init.sol | 45 +++++++++++++++++++ src/MorphoBundler.sol | 8 ++-- src/Permit2Bundler.sol | 1 + src/PermitBundler.sol | 2 +- src/StEthBundler.sol | 12 ++--- src/TransferBundler.sol | 1 + src/ethereum/EthereumPermitBundler.sol | 2 +- src/migration/AaveV2MigrationBundler.sol | 2 +- src/migration/AaveV3MigrationBundler.sol | 2 +- .../AaveV3OptimizerMigrationBundler.sol | 8 ++-- src/migration/CompoundV2MigrationBundler.sol | 4 +- src/migration/CompoundV3MigrationBundler.sol | 6 +-- 15 files changed, 90 insertions(+), 38 deletions(-) create mode 100644 src/Init.sol diff --git a/README.md b/README.md index 3850ed23..d4ab2155 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,14 @@ Each Bundler is a domain-specific abstract layer of contract that implements som 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)). User-end bundlers are provided in each chain-specific folder, instanciating all the intermediary domain-specific bundlers and associated parameters (such as chain-specific protocol addresses, e.g. [`EthereumBundler`](./src/ethereum/EthereumBundler.sol)). + +## Usage + +Install dependencies with `forge install`. + +You need to build Morpho Blue to run tests for the first time: + +``` +cd lib/morpho-blue +forge build +``` diff --git a/src/BaseBundler.sol b/src/BaseBundler.sol index 9d08d990..a84ef9f6 100644 --- a/src/BaseBundler.sol +++ b/src/BaseBundler.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.21; import {IMulticall} from "./interfaces/IMulticall.sol"; +import {Init} from "./Init.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; @@ -9,28 +10,22 @@ import {ErrorsLib} from "./libraries/ErrorsLib.sol"; /// @author Morpho Labs /// @custom:contact security@morpho.org /// @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 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 { - /* STORAGE */ - - /// @notice Keeps track of the bundler's latest bundle initiator. - /// @dev Also prevents interacting with the bundler outside of an initiated execution context. - address public initiator; - +abstract contract BaseBundler is IMulticall, Init { /* EXTERNAL */ /// @notice Executes a series of delegate calls to the contract itself. /// @dev Locks the initiator so that the sender can uniquely be identified in callbacks. /// @dev All functions delegatecalled must be `payable` if `msg.value` is non-zero. function multicall(bytes[] memory data) external payable { - initiator = msg.sender; + _init(); _multicall(data); - delete initiator; + _resetInit(); } /* INTERNAL */ @@ -46,11 +41,6 @@ abstract contract BaseBundler is IMulticall { } } - /// @dev Checks that the contract is in an initiated execution context. - function _checkInitiated() internal view { - require(initiator != address(0), ErrorsLib.UNINITIATED); - } - /// @dev Bubbles up the revert reason / custom error encoded in `returnData`. /// @dev Assumes `returnData` is the return data of any kind of failing CALL to a contract. function _revert(bytes memory returnData) internal pure { diff --git a/src/ERC4626Bundler.sol b/src/ERC4626Bundler.sol index d83b52ab..d2fc831b 100644 --- a/src/ERC4626Bundler.sol +++ b/src/ERC4626Bundler.sol @@ -67,6 +67,8 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. + address initiator = getInitiator(); + assets = Math.min(assets, IERC4626(vault).maxWithdraw(initiator)); require(assets != 0, ErrorsLib.ZERO_AMOUNT); @@ -82,6 +84,8 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. + address initiator = getInitiator(); + shares = Math.min(shares, IERC4626(vault).maxRedeem(initiator)); require(shares != 0, ErrorsLib.ZERO_SHARES); diff --git a/src/Init.sol b/src/Init.sol new file mode 100644 index 00000000..db28c724 --- /dev/null +++ b/src/Init.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity 0.8.21; + +import {ErrorsLib} from "./libraries/ErrorsLib.sol"; + +contract Init { + /* CONSTANT */ + + /// @dev The default value of the initiator is not the address zero to save gas. + address internal constant UNSET_INITIATOR = address(1); + + /* STORAGE */ + + /// @notice Keeps track of the bundler's latest bundle initiator. + /// @dev Also prevents interacting with the bundler outside of an initiated execution context. + address private initiator; + + constructor() { + initiator = UNSET_INITIATOR; + } + + /* PUBLIC */ + + /// @dev Specialized getter to prevent using `initiator` directly. + function getInitiator() public view returns (address) { + return initiator; + } + + /* INTERNAL */ + + /// @dev To initiate the contract's execution context. + function _init() internal { + initiator = msg.sender; + } + + /// @dev To reset the contract's execution context. + function _resetInit() internal { + initiator = UNSET_INITIATOR; + } + + /// @dev Checks that the contract is in an initiated execution context. + function _checkInit() internal view { + require(initiator != UNSET_INITIATOR, ErrorsLib.UNINITIATED); + } +} diff --git a/src/MorphoBundler.sol b/src/MorphoBundler.sol index b2a9f624..4ad68f60 100644 --- a/src/MorphoBundler.sol +++ b/src/MorphoBundler.sol @@ -117,7 +117,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { external payable { - MORPHO.borrow(marketParams, amount, shares, initiator, receiver); + MORPHO.borrow(marketParams, amount, shares, getInitiator(), receiver); } /// @notice Repays `amount` of `asset` on behalf of `onBehalf`. @@ -148,7 +148,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { external payable { - MORPHO.withdraw(marketParams, amount, shares, initiator, receiver); + MORPHO.withdraw(marketParams, amount, shares, getInitiator(), receiver); } /// @notice Withdraws `amount` of the collateral asset on behalf of sender. @@ -158,7 +158,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { external payable { - MORPHO.withdrawCollateral(marketParams, amount, initiator, receiver); + MORPHO.withdrawCollateral(marketParams, amount, getInitiator(), receiver); } /// @notice Triggers a liquidation on Morpho. @@ -185,7 +185,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { /// @dev Triggers `_multicall` logic during a callback. function _callback(bytes calldata data) internal { - _checkInitiated(); + _checkInit(); _multicall(abi.decode(data, (bytes[]))); } diff --git a/src/Permit2Bundler.sol b/src/Permit2Bundler.sol index fce39062..6dd170bb 100644 --- a/src/Permit2Bundler.sol +++ b/src/Permit2Bundler.sol @@ -24,6 +24,7 @@ abstract contract Permit2Bundler is BaseBundler { external payable { + address initiator = getInitiator(); uint256 amount = Math.min(permit.permitted.amount, ERC20(permit.permitted.token).balanceOf(initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); diff --git a/src/PermitBundler.sol b/src/PermitBundler.sol index 8232b40b..e8f19c93 100644 --- a/src/PermitBundler.sol +++ b/src/PermitBundler.sol @@ -18,7 +18,7 @@ abstract contract PermitBundler is BaseBundler { external payable { - try IERC20Permit(asset).permit(initiator, address(this), amount, deadline, v, r, s) {} + try IERC20Permit(asset).permit(getInitiator(), address(this), amount, deadline, v, r, s) {} catch (bytes memory returnData) { if (!skipRevert) _revert(returnData); } diff --git a/src/StEthBundler.sol b/src/StEthBundler.sol index cd31efdd..bc4fac68 100644 --- a/src/StEthBundler.sol +++ b/src/StEthBundler.sol @@ -38,8 +38,8 @@ abstract contract StEthBundler is BaseBundler { /* ACTIONS */ /// @notice Stakes the given `amount` of ETH via Lido, using the `referral` id. - /// @dev Use `BaseBundler.erc20Transfer` to transfer the stEth to some `receiver`. - /// @dev Pass `amount = type(uint256).max` to stake all. + /// @dev Use `BaseBundler.erc20Transfer` to transfer the stEth to some receiver. + /// @dev Pass `amount == type(uint256).max` to stake all. function stakeEth(uint256 amount, address referral) external payable { amount = Math.min(amount, address(this).balance); @@ -48,8 +48,8 @@ abstract contract StEthBundler is BaseBundler { } /// @notice Wraps the given `amount` of stETH to wstETH. - /// @dev Use `BaseBundler.erc20Transfer` to transfer the wrapped stEth to some `receiver`. - /// @dev Pass `amount = type(uint256).max` to wrap all. + /// @dev Use `BaseBundler.erc20Transfer` to transfer the wrapped stEth to some receiver. + /// @dev Pass `amount == type(uint256).max` to wrap all. function wrapStEth(uint256 amount) external payable { amount = Math.min(amount, ERC20(ST_ETH).balanceOf(address(this))); @@ -59,8 +59,8 @@ abstract contract StEthBundler is BaseBundler { } /// @notice Unwraps the given `amount` of wstETH to stETH. - /// @dev Use `BaseBundler.erc20Transfer` to transfer the unwrapped stEth to some `receiver`. - /// @dev Pass `amount = type(uint256).max` to unwrap all. + /// @dev Use `BaseBundler.erc20Transfer` to transfer the unwrapped stEth to some receiver. + /// @dev Pass `amount == type(uint256).max` to unwrap all. function unwrapStEth(uint256 amount) external payable { amount = Math.min(amount, ERC20(WST_ETH).balanceOf(address(this))); diff --git a/src/TransferBundler.sol b/src/TransferBundler.sol index f62cdb07..1f35eba5 100644 --- a/src/TransferBundler.sol +++ b/src/TransferBundler.sol @@ -49,6 +49,7 @@ abstract contract TransferBundler is BaseBundler { /// @notice Warning: should only be called via the bundler's `multicall` function. /// @dev Pass `amount = type(uint256).max` to transfer all. function erc20TransferFrom(address asset, uint256 amount) external payable { + address initiator = getInitiator(); amount = Math.min(amount, ERC20(asset).balanceOf(initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); diff --git a/src/ethereum/EthereumPermitBundler.sol b/src/ethereum/EthereumPermitBundler.sol index 69e05af8..39cd05c5 100644 --- a/src/ethereum/EthereumPermitBundler.sol +++ b/src/ethereum/EthereumPermitBundler.sol @@ -20,7 +20,7 @@ abstract contract EthereumPermitBundler is PermitBundler { external payable { - try IDaiPermit(MainnetLib.DAI).permit(initiator, address(this), nonce, expiry, allowed, v, r, s) {} + try IDaiPermit(MainnetLib.DAI).permit(getInitiator(), address(this), nonce, expiry, allowed, v, r, s) {} catch (bytes memory returnData) { if (!skipRevert) _revert(returnData); } diff --git a/src/migration/AaveV2MigrationBundler.sol b/src/migration/AaveV2MigrationBundler.sol index 3045de4e..e484133f 100644 --- a/src/migration/AaveV2MigrationBundler.sol +++ b/src/migration/AaveV2MigrationBundler.sol @@ -36,7 +36,7 @@ contract AaveV2MigrationBundler is MigrationBundler { _approveMaxTo(asset, address(AAVE_V2_POOL)); - AAVE_V2_POOL.repay(asset, amount, interestRateMode, initiator); + AAVE_V2_POOL.repay(asset, amount, interestRateMode, getInitiator()); } /// @notice Withdraws `amount` of `asset` on AaveV2, on behalf of the initiator, transferring funds to `receiver`. diff --git a/src/migration/AaveV3MigrationBundler.sol b/src/migration/AaveV3MigrationBundler.sol index fa7f16f9..d82f9f19 100644 --- a/src/migration/AaveV3MigrationBundler.sol +++ b/src/migration/AaveV3MigrationBundler.sol @@ -35,7 +35,7 @@ contract AaveV3MigrationBundler is MigrationBundler { _approveMaxTo(asset, address(AAVE_V3_POOL)); - AAVE_V3_POOL.repay(asset, amount, interestRateMode, initiator); + AAVE_V3_POOL.repay(asset, amount, interestRateMode, getInitiator()); } /// @notice Withdraws `amount` of `asset` on AaveV3, on behalf of the initiator, transferring funds to `receiver`. diff --git a/src/migration/AaveV3OptimizerMigrationBundler.sol b/src/migration/AaveV3OptimizerMigrationBundler.sol index aaa8faa1..cce619f4 100644 --- a/src/migration/AaveV3OptimizerMigrationBundler.sol +++ b/src/migration/AaveV3OptimizerMigrationBundler.sol @@ -36,7 +36,7 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { _approveMaxTo(underlying, address(AAVE_V3_OPTIMIZER)); - AAVE_V3_OPTIMIZER.repay(underlying, amount, initiator); + AAVE_V3_OPTIMIZER.repay(underlying, amount, getInitiator()); } /// @notice Repays `amount` of `underlying` on the AaveV3 Optimizer, on behalf of the initiator, transferring funds @@ -48,7 +48,7 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { external payable { - AAVE_V3_OPTIMIZER.withdraw(underlying, amount, initiator, receiver, maxIterations); + AAVE_V3_OPTIMIZER.withdraw(underlying, amount, getInitiator(), receiver, maxIterations); } /// @notice Repays `amount` of `underlying` on the AaveV3 Optimizer, on behalf of the initiator, transferring funds @@ -57,7 +57,7 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { /// @dev Initiator must have previously approved the bundler to manage their AaveV3 Optimizer position. /// @dev Pass `amount = type(uint256).max` to withdraw all. function aaveV3OptimizerWithdrawCollateral(address underlying, uint256 amount, address receiver) external payable { - AAVE_V3_OPTIMIZER.withdrawCollateral(underlying, amount, initiator, receiver); + AAVE_V3_OPTIMIZER.withdrawCollateral(underlying, amount, getInitiator(), receiver); } /// @notice Approves the bundler to act on behalf of the initiator on the AaveV3 Optimizer, given a signed EIP-712 @@ -69,6 +69,6 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { uint256 deadline, Types.Signature calldata signature ) external payable { - AAVE_V3_OPTIMIZER.approveManagerWithSig(initiator, address(this), isApproved, nonce, deadline, signature); + AAVE_V3_OPTIMIZER.approveManagerWithSig(getInitiator(), address(this), isApproved, nonce, deadline, signature); } } diff --git a/src/migration/CompoundV2MigrationBundler.sol b/src/migration/CompoundV2MigrationBundler.sol index 31cb2767..b05f42b6 100644 --- a/src/migration/CompoundV2MigrationBundler.sol +++ b/src/migration/CompoundV2MigrationBundler.sol @@ -44,7 +44,7 @@ contract CompoundV2MigrationBundler is WNativeBundler, MigrationBundler { require(amount != 0, ErrorsLib.ZERO_AMOUNT); - ICEth(C_ETH).repayBorrowBehalf{value: amount}(initiator); + ICEth(C_ETH).repayBorrowBehalf{value: amount}(getInitiator()); } else { address underlying = ICToken(cToken).underlying(); @@ -55,7 +55,7 @@ contract CompoundV2MigrationBundler is WNativeBundler, MigrationBundler { _approveMaxTo(underlying, cToken); // Doesn't revert in case of error. - uint256 err = ICToken(cToken).repayBorrowBehalf(initiator, amount); + uint256 err = ICToken(cToken).repayBorrowBehalf(getInitiator(), amount); require(err == 0, ErrorsLib.REPAY_ERROR); } } diff --git a/src/migration/CompoundV3MigrationBundler.sol b/src/migration/CompoundV3MigrationBundler.sol index 918be073..14396fd7 100644 --- a/src/migration/CompoundV3MigrationBundler.sol +++ b/src/migration/CompoundV3MigrationBundler.sol @@ -31,7 +31,7 @@ contract CompoundV3MigrationBundler is MigrationBundler { _approveMaxTo(asset, instance); // Compound V3 uses signed accounting: supplying to a negative balance actually repays the borrow position. - ICompoundV3(instance).supplyTo(initiator, asset, amount); + ICompoundV3(instance).supplyTo(getInitiator(), asset, amount); } /// @notice Withdraws `amount` of `asset` on the CompoundV3 `instance`. @@ -48,7 +48,7 @@ contract CompoundV3MigrationBundler is MigrationBundler { /// @dev Assumes the given `instance` is a CompoundV3 instance. /// @dev Pass `amount = type(uint256).max` to withdraw all. function compoundV3WithdrawFrom(address instance, address asset, uint256 amount) external payable { - ICompoundV3(instance).withdrawFrom(initiator, address(this), asset, amount); + ICompoundV3(instance).withdrawFrom(getInitiator(), address(this), asset, amount); } /// @notice Approves the bundler to act on behalf of the initiator on the CompoundV3 `instance`, given a signed @@ -64,6 +64,6 @@ contract CompoundV3MigrationBundler is MigrationBundler { bytes32 r, bytes32 s ) external payable { - ICompoundV3(instance).allowBySig(initiator, address(this), isAllowed, nonce, expiry, v, r, s); + ICompoundV3(instance).allowBySig(getInitiator(), address(this), isAllowed, nonce, expiry, v, r, s); } } From efb5c1247ac273acf0cd69400d12b9205f1d3ee9 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 15:18:27 +0200 Subject: [PATCH 02/17] refactor: review fixes --- README.md | 9 ++------- foundry.toml | 1 + src/Init.sol | 6 +----- src/MorphoBundler.sol | 2 +- src/PermitBundler.sol | 2 +- src/StEthBundler.sol | 12 ++++++------ src/UrdBundler.sol | 2 +- src/ethereum/EthereumPermitBundler.sol | 2 +- 8 files changed, 14 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d4ab2155..05869afe 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,6 @@ User-end bundlers are provided in each chain-specific folder, instanciating all ## Usage -Install dependencies with `forge install`. +Install dependencies with `yarn`. -You need to build Morpho Blue to run tests for the first time: - -``` -cd lib/morpho-blue -forge build -``` +The first time running the tests with `yarn test:forge` will build Morpho Blue. diff --git a/foundry.toml b/foundry.toml index a433af44..d90b5189 100644 --- a/foundry.toml +++ b/foundry.toml @@ -9,6 +9,7 @@ fs_permissions = [ { access = "read", path = "./config/"}, { access = "read", path = "./lib/morpho-blue/out/"} ] +libs = ["node_modules", "lib"] [profile.default.fuzz] runs = 32 diff --git a/src/Init.sol b/src/Init.sol index db28c724..d8170ffd 100644 --- a/src/Init.sol +++ b/src/Init.sol @@ -13,11 +13,7 @@ contract Init { /// @notice Keeps track of the bundler's latest bundle initiator. /// @dev Also prevents interacting with the bundler outside of an initiated execution context. - address private initiator; - - constructor() { - initiator = UNSET_INITIATOR; - } + address private initiator = UNSET_INITIATOR; /* PUBLIC */ diff --git a/src/MorphoBundler.sol b/src/MorphoBundler.sol index 4ad68f60..1bb42fba 100644 --- a/src/MorphoBundler.sol +++ b/src/MorphoBundler.sol @@ -56,7 +56,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { /* ACTIONS */ /// @notice Approves this contract to manage the `authorization.authorizer`'s position via EIP712 `signature`. - /// @dev Pass `skipRevert == true` to avoid reverting the whole bundle in case the signature expired. + /// @dev Pass `skipRevert = true` to avoid reverting the whole bundle in case the signature expired. function morphoSetAuthorizationWithSig( Authorization calldata authorization, Signature calldata signature, diff --git a/src/PermitBundler.sol b/src/PermitBundler.sol index e8f19c93..16125708 100644 --- a/src/PermitBundler.sol +++ b/src/PermitBundler.sol @@ -13,7 +13,7 @@ abstract contract PermitBundler is BaseBundler { /// @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`. /// @notice Warning: should only be called via the bundler's `multicall` function. - /// @dev Pass `skipRevert == true` to avoid reverting the whole bundle in case the signature expired. + /// @dev Pass `skipRevert = true` to avoid reverting the whole bundle in case the signature expired. function permit(address asset, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s, bool skipRevert) external payable diff --git a/src/StEthBundler.sol b/src/StEthBundler.sol index bc4fac68..4fae15e0 100644 --- a/src/StEthBundler.sol +++ b/src/StEthBundler.sol @@ -38,8 +38,8 @@ abstract contract StEthBundler is BaseBundler { /* ACTIONS */ /// @notice Stakes the given `amount` of ETH via Lido, using the `referral` id. - /// @dev Use `BaseBundler.erc20Transfer` to transfer the stEth to some receiver. - /// @dev Pass `amount == type(uint256).max` to stake all. + /// @dev Use `TransferBundler.erc20Transfer` to transfer the stEth to some receiver. + /// @dev Pass `amount = type(uint256).max` to stake all. function stakeEth(uint256 amount, address referral) external payable { amount = Math.min(amount, address(this).balance); @@ -48,8 +48,8 @@ abstract contract StEthBundler is BaseBundler { } /// @notice Wraps the given `amount` of stETH to wstETH. - /// @dev Use `BaseBundler.erc20Transfer` to transfer the wrapped stEth to some receiver. - /// @dev Pass `amount == type(uint256).max` to wrap all. + /// @dev Use `TransferBundler.erc20Transfer` to transfer the wrapped stEth to some receiver. + /// @dev Pass `amount = type(uint256).max` to wrap all. function wrapStEth(uint256 amount) external payable { amount = Math.min(amount, ERC20(ST_ETH).balanceOf(address(this))); @@ -59,8 +59,8 @@ abstract contract StEthBundler is BaseBundler { } /// @notice Unwraps the given `amount` of wstETH to stETH. - /// @dev Use `BaseBundler.erc20Transfer` to transfer the unwrapped stEth to some receiver. - /// @dev Pass `amount == type(uint256).max` to unwrap all. + /// @dev Use `TransferBundler.erc20Transfer` to transfer the unwrapped stEth to some receiver. + /// @dev Pass `amount = type(uint256).max` to unwrap all. function unwrapStEth(uint256 amount) external payable { amount = Math.min(amount, ERC20(WST_ETH).balanceOf(address(this))); diff --git a/src/UrdBundler.sol b/src/UrdBundler.sol index 301ae6be..c1be286d 100644 --- a/src/UrdBundler.sol +++ b/src/UrdBundler.sol @@ -14,7 +14,7 @@ import {BaseBundler} from "./BaseBundler.sol"; abstract contract UrdBundler is BaseBundler { /// @notice Claims `amount` of `reward` on behalf of `account` on the given rewards distributor, using `proof`. /// @dev Assumes the given distributor implements IUniversalRewardsDistributor. - /// @dev Pass `skipRevert == true` to avoid reverting the whole bundle in case the proof expired. + /// @dev Pass `skipRevert = true` to avoid reverting the whole bundle in case the proof expired. function urdClaim( address distributor, address account, diff --git a/src/ethereum/EthereumPermitBundler.sol b/src/ethereum/EthereumPermitBundler.sol index 39cd05c5..abda081d 100644 --- a/src/ethereum/EthereumPermitBundler.sol +++ b/src/ethereum/EthereumPermitBundler.sol @@ -15,7 +15,7 @@ abstract contract EthereumPermitBundler is PermitBundler { /// @notice Permits DAI from sender to be spent by the bundler with the given `nonce`, `expiry` & EIP-712 /// signature's `v`, `r` & `s`. /// @notice Warning: should only be called via the bundler's `multicall` function. - /// @dev Pass `skipRevert == true` to avoid reverting the whole bundle in case the signature expired. + /// @dev Pass `skipRevert = true` to avoid reverting the whole bundle in case the signature expired. function permitDai(uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s, bool skipRevert) external payable From 45d787955babd56c73151cb762bbf7b25ba8c105 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 15:23:33 +0200 Subject: [PATCH 03/17] fix: forgot some transfer bundler function in comments --- src/WNativeBundler.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WNativeBundler.sol b/src/WNativeBundler.sol index 36ea358d..8862a979 100644 --- a/src/WNativeBundler.sol +++ b/src/WNativeBundler.sol @@ -39,7 +39,7 @@ abstract contract WNativeBundler is BaseBundler { /// @notice Wraps the given `amount` of the native token to wNative. /// @notice Warning: should only be called via the bundler's `multicall` function. - /// @dev Use `BaseBundler.erc20Transfer` to transfer the wrapped native tokens to some `receiver`. + /// @dev Use `TransferBundler.erc20Transfer` to transfer the wrapped native tokens to some `receiver`. /// @dev Pass `amount = type(uint256).max` to wrap all. function wrapNative(uint256 amount) external payable { amount = Math.min(amount, address(this).balance); @@ -51,7 +51,7 @@ abstract contract WNativeBundler is BaseBundler { /// @notice Unwraps the given `amount` of wNative to the native token. /// @notice Warning: should only be called via the bundler's `multicall` function. - /// @dev Use `BaseBundler.nativeTransfer` to transfer the unwrapped native tokens to some `receiver`. + /// @dev Use `TransferBundler.nativeTransfer` to transfer the unwrapped native tokens to some `receiver`. /// @dev Pass `amount = type(uint256).max` to unwrap all. function unwrapNative(uint256 amount) external payable { amount = Math.min(amount, ERC20(WRAPPED_NATIVE).balanceOf(address(this))); From 7987db0a35371acbaea2ead9f4edaca01b61642f Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 17:49:35 +0200 Subject: [PATCH 04/17] refactor: merge Init in BaseBundler contract --- foundry.toml | 1 - src/BaseBundler.sol | 36 ++++++++++++++++++++++++++++++++++-- src/Init.sol | 41 ----------------------------------------- 3 files changed, 34 insertions(+), 44 deletions(-) delete mode 100644 src/Init.sol diff --git a/foundry.toml b/foundry.toml index d90b5189..51c0e2a5 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,7 +1,6 @@ [profile.default] names = true sizes = true -via-ir = true src = "src" test = "test/forge" evm_version = "paris" diff --git a/src/BaseBundler.sol b/src/BaseBundler.sol index a84ef9f6..e32fc374 100644 --- a/src/BaseBundler.sol +++ b/src/BaseBundler.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.21; import {IMulticall} from "./interfaces/IMulticall.sol"; -import {Init} from "./Init.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; @@ -14,7 +13,25 @@ import {ErrorsLib} from "./libraries/ErrorsLib.sol"; /// @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, Init { +abstract contract BaseBundler is IMulticall { + /* CONSTANT */ + + /// @dev The default value of the initiator is not the address zero to save gas. + address internal constant UNSET_INITIATOR = address(1); + + /* STORAGE */ + + /// @notice Keeps track of the bundler's latest bundle initiator. + /// @dev Also prevents interacting with the bundler outside of an initiated execution context. + address private _initiator = UNSET_INITIATOR; + + /* PUBLIC */ + + /// @dev Specialized getter to prevent using `_initiator` directly. + function getInitiator() public view returns (address) { + return _initiator; + } + /* EXTERNAL */ /// @notice Executes a series of delegate calls to the contract itself. @@ -51,4 +68,19 @@ abstract contract BaseBundler is IMulticall, Init { revert(add(32, returnData), length) } } + + /// @dev To initiate the contract's execution context. + function _init() internal { + _initiator = msg.sender; + } + + /// @dev To reset the contract's execution context. + function _resetInit() internal { + _initiator = UNSET_INITIATOR; + } + + /// @dev Checks that the contract is in an initiated execution context. + function _checkInit() internal view { + require(_initiator != UNSET_INITIATOR, ErrorsLib.UNINITIATED); + } } diff --git a/src/Init.sol b/src/Init.sol deleted file mode 100644 index d8170ffd..00000000 --- a/src/Init.sol +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity 0.8.21; - -import {ErrorsLib} from "./libraries/ErrorsLib.sol"; - -contract Init { - /* CONSTANT */ - - /// @dev The default value of the initiator is not the address zero to save gas. - address internal constant UNSET_INITIATOR = address(1); - - /* STORAGE */ - - /// @notice Keeps track of the bundler's latest bundle initiator. - /// @dev Also prevents interacting with the bundler outside of an initiated execution context. - address private initiator = UNSET_INITIATOR; - - /* PUBLIC */ - - /// @dev Specialized getter to prevent using `initiator` directly. - function getInitiator() public view returns (address) { - return initiator; - } - - /* INTERNAL */ - - /// @dev To initiate the contract's execution context. - function _init() internal { - initiator = msg.sender; - } - - /// @dev To reset the contract's execution context. - function _resetInit() internal { - initiator = UNSET_INITIATOR; - } - - /// @dev Checks that the contract is in an initiated execution context. - function _checkInit() internal view { - require(initiator != UNSET_INITIATOR, ErrorsLib.UNINITIATED); - } -} From 199682ef6bb265ba4b2e3ecab35330b182263204 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 17:51:24 +0200 Subject: [PATCH 05/17] docs: change get started section title Co-authored-by: Romain Milon Signed-off-by: Quentin Garchery --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 05869afe..e394f594 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Some chain-specific domains are also scoped to the chain-specific folder, becaus User-end bundlers are provided in each chain-specific folder, instanciating all the intermediary domain-specific bundlers and associated parameters (such as chain-specific protocol addresses, e.g. [`EthereumBundler`](./src/ethereum/EthereumBundler.sol)). -## Usage +## Get Started Install dependencies with `yarn`. From 8da8dc18ca519915187dbb076e5160a4272c8fa5 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 17:52:32 +0200 Subject: [PATCH 06/17] refactor: rename initiator getter --- src/BaseBundler.sol | 2 +- src/ERC4626Bundler.sol | 4 ++-- src/MorphoBundler.sol | 6 +++--- src/Permit2Bundler.sol | 2 +- src/PermitBundler.sol | 2 +- src/TransferBundler.sol | 2 +- src/ethereum/EthereumPermitBundler.sol | 2 +- src/migration/AaveV2MigrationBundler.sol | 2 +- src/migration/AaveV3MigrationBundler.sol | 2 +- src/migration/AaveV3OptimizerMigrationBundler.sol | 8 ++++---- src/migration/CompoundV2MigrationBundler.sol | 4 ++-- src/migration/CompoundV3MigrationBundler.sol | 6 +++--- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/BaseBundler.sol b/src/BaseBundler.sol index e32fc374..b3b1fccd 100644 --- a/src/BaseBundler.sol +++ b/src/BaseBundler.sol @@ -28,7 +28,7 @@ abstract contract BaseBundler is IMulticall { /* PUBLIC */ /// @dev Specialized getter to prevent using `_initiator` directly. - function getInitiator() public view returns (address) { + function initiator() public view returns (address) { return _initiator; } diff --git a/src/ERC4626Bundler.sol b/src/ERC4626Bundler.sol index d2fc831b..9cc12efb 100644 --- a/src/ERC4626Bundler.sol +++ b/src/ERC4626Bundler.sol @@ -67,7 +67,7 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. - address initiator = getInitiator(); + address initiator = initiator(); assets = Math.min(assets, IERC4626(vault).maxWithdraw(initiator)); @@ -84,7 +84,7 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. - address initiator = getInitiator(); + address initiator = initiator(); shares = Math.min(shares, IERC4626(vault).maxRedeem(initiator)); diff --git a/src/MorphoBundler.sol b/src/MorphoBundler.sol index 1bb42fba..a83feaed 100644 --- a/src/MorphoBundler.sol +++ b/src/MorphoBundler.sol @@ -117,7 +117,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { external payable { - MORPHO.borrow(marketParams, amount, shares, getInitiator(), receiver); + MORPHO.borrow(marketParams, amount, shares, initiator(), receiver); } /// @notice Repays `amount` of `asset` on behalf of `onBehalf`. @@ -148,7 +148,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { external payable { - MORPHO.withdraw(marketParams, amount, shares, getInitiator(), receiver); + MORPHO.withdraw(marketParams, amount, shares, initiator(), receiver); } /// @notice Withdraws `amount` of the collateral asset on behalf of sender. @@ -158,7 +158,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { external payable { - MORPHO.withdrawCollateral(marketParams, amount, getInitiator(), receiver); + MORPHO.withdrawCollateral(marketParams, amount, initiator(), receiver); } /// @notice Triggers a liquidation on Morpho. diff --git a/src/Permit2Bundler.sol b/src/Permit2Bundler.sol index 6dd170bb..6a78659e 100644 --- a/src/Permit2Bundler.sol +++ b/src/Permit2Bundler.sol @@ -24,7 +24,7 @@ abstract contract Permit2Bundler is BaseBundler { external payable { - address initiator = getInitiator(); + address initiator = initiator(); uint256 amount = Math.min(permit.permitted.amount, ERC20(permit.permitted.token).balanceOf(initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); diff --git a/src/PermitBundler.sol b/src/PermitBundler.sol index 16125708..c690b16b 100644 --- a/src/PermitBundler.sol +++ b/src/PermitBundler.sol @@ -18,7 +18,7 @@ abstract contract PermitBundler is BaseBundler { external payable { - try IERC20Permit(asset).permit(getInitiator(), address(this), amount, deadline, v, r, s) {} + try IERC20Permit(asset).permit(initiator(), address(this), amount, deadline, v, r, s) {} catch (bytes memory returnData) { if (!skipRevert) _revert(returnData); } diff --git a/src/TransferBundler.sol b/src/TransferBundler.sol index 1f35eba5..fab73ae4 100644 --- a/src/TransferBundler.sol +++ b/src/TransferBundler.sol @@ -49,7 +49,7 @@ abstract contract TransferBundler is BaseBundler { /// @notice Warning: should only be called via the bundler's `multicall` function. /// @dev Pass `amount = type(uint256).max` to transfer all. function erc20TransferFrom(address asset, uint256 amount) external payable { - address initiator = getInitiator(); + address initiator = initiator(); amount = Math.min(amount, ERC20(asset).balanceOf(initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); diff --git a/src/ethereum/EthereumPermitBundler.sol b/src/ethereum/EthereumPermitBundler.sol index abda081d..780d88f9 100644 --- a/src/ethereum/EthereumPermitBundler.sol +++ b/src/ethereum/EthereumPermitBundler.sol @@ -20,7 +20,7 @@ abstract contract EthereumPermitBundler is PermitBundler { external payable { - try IDaiPermit(MainnetLib.DAI).permit(getInitiator(), address(this), nonce, expiry, allowed, v, r, s) {} + try IDaiPermit(MainnetLib.DAI).permit(initiator(), address(this), nonce, expiry, allowed, v, r, s) {} catch (bytes memory returnData) { if (!skipRevert) _revert(returnData); } diff --git a/src/migration/AaveV2MigrationBundler.sol b/src/migration/AaveV2MigrationBundler.sol index e484133f..b7523e62 100644 --- a/src/migration/AaveV2MigrationBundler.sol +++ b/src/migration/AaveV2MigrationBundler.sol @@ -36,7 +36,7 @@ contract AaveV2MigrationBundler is MigrationBundler { _approveMaxTo(asset, address(AAVE_V2_POOL)); - AAVE_V2_POOL.repay(asset, amount, interestRateMode, getInitiator()); + AAVE_V2_POOL.repay(asset, amount, interestRateMode, initiator()); } /// @notice Withdraws `amount` of `asset` on AaveV2, on behalf of the initiator, transferring funds to `receiver`. diff --git a/src/migration/AaveV3MigrationBundler.sol b/src/migration/AaveV3MigrationBundler.sol index d82f9f19..9cc24168 100644 --- a/src/migration/AaveV3MigrationBundler.sol +++ b/src/migration/AaveV3MigrationBundler.sol @@ -35,7 +35,7 @@ contract AaveV3MigrationBundler is MigrationBundler { _approveMaxTo(asset, address(AAVE_V3_POOL)); - AAVE_V3_POOL.repay(asset, amount, interestRateMode, getInitiator()); + AAVE_V3_POOL.repay(asset, amount, interestRateMode, initiator()); } /// @notice Withdraws `amount` of `asset` on AaveV3, on behalf of the initiator, transferring funds to `receiver`. diff --git a/src/migration/AaveV3OptimizerMigrationBundler.sol b/src/migration/AaveV3OptimizerMigrationBundler.sol index cce619f4..c8d9897f 100644 --- a/src/migration/AaveV3OptimizerMigrationBundler.sol +++ b/src/migration/AaveV3OptimizerMigrationBundler.sol @@ -36,7 +36,7 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { _approveMaxTo(underlying, address(AAVE_V3_OPTIMIZER)); - AAVE_V3_OPTIMIZER.repay(underlying, amount, getInitiator()); + AAVE_V3_OPTIMIZER.repay(underlying, amount, initiator()); } /// @notice Repays `amount` of `underlying` on the AaveV3 Optimizer, on behalf of the initiator, transferring funds @@ -48,7 +48,7 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { external payable { - AAVE_V3_OPTIMIZER.withdraw(underlying, amount, getInitiator(), receiver, maxIterations); + AAVE_V3_OPTIMIZER.withdraw(underlying, amount, initiator(), receiver, maxIterations); } /// @notice Repays `amount` of `underlying` on the AaveV3 Optimizer, on behalf of the initiator, transferring funds @@ -57,7 +57,7 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { /// @dev Initiator must have previously approved the bundler to manage their AaveV3 Optimizer position. /// @dev Pass `amount = type(uint256).max` to withdraw all. function aaveV3OptimizerWithdrawCollateral(address underlying, uint256 amount, address receiver) external payable { - AAVE_V3_OPTIMIZER.withdrawCollateral(underlying, amount, getInitiator(), receiver); + AAVE_V3_OPTIMIZER.withdrawCollateral(underlying, amount, initiator(), receiver); } /// @notice Approves the bundler to act on behalf of the initiator on the AaveV3 Optimizer, given a signed EIP-712 @@ -69,6 +69,6 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler { uint256 deadline, Types.Signature calldata signature ) external payable { - AAVE_V3_OPTIMIZER.approveManagerWithSig(getInitiator(), address(this), isApproved, nonce, deadline, signature); + AAVE_V3_OPTIMIZER.approveManagerWithSig(initiator(), address(this), isApproved, nonce, deadline, signature); } } diff --git a/src/migration/CompoundV2MigrationBundler.sol b/src/migration/CompoundV2MigrationBundler.sol index b05f42b6..076c0a00 100644 --- a/src/migration/CompoundV2MigrationBundler.sol +++ b/src/migration/CompoundV2MigrationBundler.sol @@ -44,7 +44,7 @@ contract CompoundV2MigrationBundler is WNativeBundler, MigrationBundler { require(amount != 0, ErrorsLib.ZERO_AMOUNT); - ICEth(C_ETH).repayBorrowBehalf{value: amount}(getInitiator()); + ICEth(C_ETH).repayBorrowBehalf{value: amount}(initiator()); } else { address underlying = ICToken(cToken).underlying(); @@ -55,7 +55,7 @@ contract CompoundV2MigrationBundler is WNativeBundler, MigrationBundler { _approveMaxTo(underlying, cToken); // Doesn't revert in case of error. - uint256 err = ICToken(cToken).repayBorrowBehalf(getInitiator(), amount); + uint256 err = ICToken(cToken).repayBorrowBehalf(initiator(), amount); require(err == 0, ErrorsLib.REPAY_ERROR); } } diff --git a/src/migration/CompoundV3MigrationBundler.sol b/src/migration/CompoundV3MigrationBundler.sol index 14396fd7..a5db968c 100644 --- a/src/migration/CompoundV3MigrationBundler.sol +++ b/src/migration/CompoundV3MigrationBundler.sol @@ -31,7 +31,7 @@ contract CompoundV3MigrationBundler is MigrationBundler { _approveMaxTo(asset, instance); // Compound V3 uses signed accounting: supplying to a negative balance actually repays the borrow position. - ICompoundV3(instance).supplyTo(getInitiator(), asset, amount); + ICompoundV3(instance).supplyTo(initiator(), asset, amount); } /// @notice Withdraws `amount` of `asset` on the CompoundV3 `instance`. @@ -48,7 +48,7 @@ contract CompoundV3MigrationBundler is MigrationBundler { /// @dev Assumes the given `instance` is a CompoundV3 instance. /// @dev Pass `amount = type(uint256).max` to withdraw all. function compoundV3WithdrawFrom(address instance, address asset, uint256 amount) external payable { - ICompoundV3(instance).withdrawFrom(getInitiator(), address(this), asset, amount); + ICompoundV3(instance).withdrawFrom(initiator(), address(this), asset, amount); } /// @notice Approves the bundler to act on behalf of the initiator on the CompoundV3 `instance`, given a signed @@ -64,6 +64,6 @@ contract CompoundV3MigrationBundler is MigrationBundler { bytes32 r, bytes32 s ) external payable { - ICompoundV3(instance).allowBySig(getInitiator(), address(this), isAllowed, nonce, expiry, v, r, s); + ICompoundV3(instance).allowBySig(initiator(), address(this), isAllowed, nonce, expiry, v, r, s); } } From 3f07e870c59101a050bff02faa5614a563f50b52 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 17:56:04 +0200 Subject: [PATCH 07/17] refactor: inline setter init functions --- foundry.toml | 1 + src/BaseBundler.sol | 14 ++------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/foundry.toml b/foundry.toml index 51c0e2a5..d90b5189 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,6 +1,7 @@ [profile.default] names = true sizes = true +via-ir = true src = "src" test = "test/forge" evm_version = "paris" diff --git a/src/BaseBundler.sol b/src/BaseBundler.sol index b3b1fccd..0e3eb9df 100644 --- a/src/BaseBundler.sol +++ b/src/BaseBundler.sol @@ -38,11 +38,11 @@ abstract contract BaseBundler is IMulticall { /// @dev Locks the initiator so that the sender can uniquely be identified in callbacks. /// @dev All functions delegatecalled must be `payable` if `msg.value` is non-zero. function multicall(bytes[] memory data) external payable { - _init(); + _initiator = msg.sender; _multicall(data); - _resetInit(); + _initiator = UNSET_INITIATOR; } /* INTERNAL */ @@ -69,16 +69,6 @@ abstract contract BaseBundler is IMulticall { } } - /// @dev To initiate the contract's execution context. - function _init() internal { - _initiator = msg.sender; - } - - /// @dev To reset the contract's execution context. - function _resetInit() internal { - _initiator = UNSET_INITIATOR; - } - /// @dev Checks that the contract is in an initiated execution context. function _checkInit() internal view { require(_initiator != UNSET_INITIATOR, ErrorsLib.UNINITIATED); From 3c067f6445ee0c9134548ddf47ffd9535adb7f90 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 18:08:40 +0200 Subject: [PATCH 08/17] refactor: recover checkInitiated name --- src/BaseBundler.sol | 10 +++++----- src/MorphoBundler.sol | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BaseBundler.sol b/src/BaseBundler.sol index 0e3eb9df..9ea103d1 100644 --- a/src/BaseBundler.sol +++ b/src/BaseBundler.sol @@ -58,6 +58,11 @@ abstract contract BaseBundler is IMulticall { } } + /// @dev Checks that the contract is in an initiated execution context. + function _checkInitiated() internal view { + require(_initiator != UNSET_INITIATOR, ErrorsLib.UNINITIATED); + } + /// @dev Bubbles up the revert reason / custom error encoded in `returnData`. /// @dev Assumes `returnData` is the return data of any kind of failing CALL to a contract. function _revert(bytes memory returnData) internal pure { @@ -68,9 +73,4 @@ abstract contract BaseBundler is IMulticall { revert(add(32, returnData), length) } } - - /// @dev Checks that the contract is in an initiated execution context. - function _checkInit() internal view { - require(_initiator != UNSET_INITIATOR, ErrorsLib.UNINITIATED); - } } diff --git a/src/MorphoBundler.sol b/src/MorphoBundler.sol index a83feaed..34526ad0 100644 --- a/src/MorphoBundler.sol +++ b/src/MorphoBundler.sol @@ -185,7 +185,7 @@ abstract contract MorphoBundler is BaseBundler, IMorphoBundler { /// @dev Triggers `_multicall` logic during a callback. function _callback(bytes calldata data) internal { - _checkInit(); + _checkInitiated(); _multicall(abi.decode(data, (bytes[]))); } From 307aa78c356812ac6869aa5e585b4eecaea19714 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 18:14:56 +0200 Subject: [PATCH 09/17] refactor: move constants to the dedicated library --- src/BaseBundler.sol | 7 ++----- src/libraries/ConstantsLib.sol | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BaseBundler.sol b/src/BaseBundler.sol index 9ea103d1..f8fef032 100644 --- a/src/BaseBundler.sol +++ b/src/BaseBundler.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.21; import {IMulticall} from "./interfaces/IMulticall.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; +import {UNSET_INITIATOR} from "./libraries/ConstantsLib.sol"; /// @title BaseBundler /// @author Morpho Labs @@ -14,11 +15,6 @@ import {ErrorsLib} from "./libraries/ErrorsLib.sol"; /// 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 { - /* CONSTANT */ - - /// @dev The default value of the initiator is not the address zero to save gas. - address internal constant UNSET_INITIATOR = address(1); - /* STORAGE */ /// @notice Keeps track of the bundler's latest bundle initiator. @@ -27,6 +23,7 @@ abstract contract BaseBundler is IMulticall { /* PUBLIC */ + /// @notice Returns the address of the initiator of the multicall transaction. /// @dev Specialized getter to prevent using `_initiator` directly. function initiator() public view returns (address) { return _initiator; diff --git a/src/libraries/ConstantsLib.sol b/src/libraries/ConstantsLib.sol index c72d8500..d2d60676 100644 --- a/src/libraries/ConstantsLib.sol +++ b/src/libraries/ConstantsLib.sol @@ -3,3 +3,6 @@ pragma solidity ^0.8.0; /// @dev The address of the Permit2 contract on all chains. address constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; + +/// @dev The default value of the initiator of the multicall transaction is not the address zero to save gas. +address constant UNSET_INITIATOR = address(1); From 330cc6d24359483621ac3875f010012947c1687e Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 19:22:33 +0200 Subject: [PATCH 10/17] fix: remove node modules as forge dependencies --- foundry.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foundry.toml b/foundry.toml index d90b5189..ff3fc81c 100644 --- a/foundry.toml +++ b/foundry.toml @@ -9,7 +9,7 @@ fs_permissions = [ { access = "read", path = "./config/"}, { access = "read", path = "./lib/morpho-blue/out/"} ] -libs = ["node_modules", "lib"] +libs = ["lib"] [profile.default.fuzz] runs = 32 From e150f4463d140035ccf097dfa34bdd8e6a413cd2 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 3 Oct 2023 19:27:42 +0200 Subject: [PATCH 11/17] docs: remove unneceary comments --- src/StEthBundler.sol | 3 --- src/WNativeBundler.sol | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/StEthBundler.sol b/src/StEthBundler.sol index 4fae15e0..83c47aaa 100644 --- a/src/StEthBundler.sol +++ b/src/StEthBundler.sol @@ -38,7 +38,6 @@ abstract contract StEthBundler is BaseBundler { /* ACTIONS */ /// @notice Stakes the given `amount` of ETH via Lido, using the `referral` id. - /// @dev Use `TransferBundler.erc20Transfer` to transfer the stEth to some receiver. /// @dev Pass `amount = type(uint256).max` to stake all. function stakeEth(uint256 amount, address referral) external payable { amount = Math.min(amount, address(this).balance); @@ -48,7 +47,6 @@ abstract contract StEthBundler is BaseBundler { } /// @notice Wraps the given `amount` of stETH to wstETH. - /// @dev Use `TransferBundler.erc20Transfer` to transfer the wrapped stEth to some receiver. /// @dev Pass `amount = type(uint256).max` to wrap all. function wrapStEth(uint256 amount) external payable { amount = Math.min(amount, ERC20(ST_ETH).balanceOf(address(this))); @@ -59,7 +57,6 @@ abstract contract StEthBundler is BaseBundler { } /// @notice Unwraps the given `amount` of wstETH to stETH. - /// @dev Use `TransferBundler.erc20Transfer` to transfer the unwrapped stEth to some receiver. /// @dev Pass `amount = type(uint256).max` to unwrap all. function unwrapStEth(uint256 amount) external payable { amount = Math.min(amount, ERC20(WST_ETH).balanceOf(address(this))); diff --git a/src/WNativeBundler.sol b/src/WNativeBundler.sol index 8862a979..447fa1a8 100644 --- a/src/WNativeBundler.sol +++ b/src/WNativeBundler.sol @@ -39,7 +39,6 @@ abstract contract WNativeBundler is BaseBundler { /// @notice Wraps the given `amount` of the native token to wNative. /// @notice Warning: should only be called via the bundler's `multicall` function. - /// @dev Use `TransferBundler.erc20Transfer` to transfer the wrapped native tokens to some `receiver`. /// @dev Pass `amount = type(uint256).max` to wrap all. function wrapNative(uint256 amount) external payable { amount = Math.min(amount, address(this).balance); @@ -51,7 +50,6 @@ abstract contract WNativeBundler is BaseBundler { /// @notice Unwraps the given `amount` of wNative to the native token. /// @notice Warning: should only be called via the bundler's `multicall` function. - /// @dev Use `TransferBundler.nativeTransfer` to transfer the unwrapped native tokens to some `receiver`. /// @dev Pass `amount = type(uint256).max` to unwrap all. function unwrapNative(uint256 amount) external payable { amount = Math.min(amount, ERC20(WRAPPED_NATIVE).balanceOf(address(this))); From 0abb4fdf022734e8a0a1c9a19af9acb27cc445fd Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Wed, 4 Oct 2023 17:06:29 +0200 Subject: [PATCH 12/17] fix: duplicate in ERC4626 tests --- test/forge/ERC4626BundlerLocalTest.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/forge/ERC4626BundlerLocalTest.sol b/test/forge/ERC4626BundlerLocalTest.sol index 1c15cb46..06b53015 100644 --- a/test/forge/ERC4626BundlerLocalTest.sol +++ b/test/forge/ERC4626BundlerLocalTest.sol @@ -130,7 +130,7 @@ contract ERC4626BundlerLocalTest is LocalTest { uint256 shares = vault.previewDeposit(assets); bundle.push(_erc20TransferFrom(address(loanToken), assets)); - bundle.push(_erc4626Mint(address(vault), assets, USER)); + bundle.push(_erc4626Deposit(address(vault), assets, USER)); loanToken.setBalance(USER, assets); @@ -145,7 +145,7 @@ contract ERC4626BundlerLocalTest is LocalTest { assertEq(vault.balanceOf(USER), shares, "vault.balanceOf(USER)"); } - function testErc4626Redeem(uint256 deposited, uint256 assets) public { + function testErc4626Withdraw(uint256 deposited, uint256 assets) public { deposited = bound(deposited, MIN_AMOUNT, MAX_AMOUNT); uint256 minted = _depositVault(deposited); @@ -168,7 +168,7 @@ contract ERC4626BundlerLocalTest is LocalTest { assertEq(vault.balanceOf(RECEIVER), 0, "vault.balanceOf(RECEIVER)"); } - function testErc4626Withdraw(uint256 deposited, uint256 shares) public { + function testErc4626Redeem(uint256 deposited, uint256 shares) public { deposited = bound(deposited, MIN_AMOUNT, MAX_AMOUNT); uint256 minted = _depositVault(deposited); From a98377620216f989034b685997a3095fb08eef1a Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Tue, 10 Oct 2023 11:51:47 +0200 Subject: [PATCH 13/17] test: makeAddr --- test/forge/helpers/BaseTest.sol | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/test/forge/helpers/BaseTest.sol b/test/forge/helpers/BaseTest.sol index 4458f0ec..253dbb45 100644 --- a/test/forge/helpers/BaseTest.sol +++ b/test/forge/helpers/BaseTest.sol @@ -56,11 +56,11 @@ abstract contract BaseTest is Test { bytes[] internal callbackBundle; function setUp() public virtual { - USER = _addrFromHashedString("User"); - OWNER = _addrFromHashedString("Owner"); - SUPPLIER = _addrFromHashedString("Supplier"); - RECEIVER = _addrFromHashedString("Receiver"); - LIQUIDATOR = _addrFromHashedString("Liquidator"); + USER = makeAddr("User"); + OWNER = makeAddr("Owner"); + SUPPLIER = makeAddr("Supplier"); + RECEIVER = makeAddr("Receiver"); + LIQUIDATOR = makeAddr("Liquidator"); morpho = IMorpho(_deploy("lib/morpho-blue/out/Morpho.sol/Morpho.json", abi.encode(OWNER))); vm.label(address(morpho), "Morpho"); @@ -78,11 +78,6 @@ abstract contract BaseTest is Test { morpho.setAuthorization(address(this), true); } - function _addrFromHashedString(string memory name) internal returns (address addr) { - addr = address(uint160(uint256(keccak256(bytes(name))))); - vm.label(addr, name); - } - function _deploy(string memory artifactPath, bytes memory constructorArgs) internal returns (address deployed) { string memory artifact = vm.readFile(artifactPath); bytes memory bytecode = bytes.concat(artifact.readBytes("$.bytecode.object"), constructorArgs); From 7482c20f749d02a4c022d43a93450fc714e03b85 Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Tue, 17 Oct 2023 08:38:11 +0200 Subject: [PATCH 14/17] test: make addr outside constructor --- test/forge/helpers/BaseTest.sol | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/test/forge/helpers/BaseTest.sol b/test/forge/helpers/BaseTest.sol index 253dbb45..691d78cf 100644 --- a/test/forge/helpers/BaseTest.sol +++ b/test/forge/helpers/BaseTest.sol @@ -40,11 +40,11 @@ abstract contract BaseTest is Test { using SafeTransferLib for ERC20; using stdJson for string; - address internal USER; - address internal SUPPLIER; - address internal OWNER; - address internal RECEIVER; - address internal LIQUIDATOR; + address internal USER = makeAddr("User"); + address internal SUPPLIER = makeAddr("Owner"); + address internal OWNER = makeAddr("Supplier"); + address internal RECEIVER = makeAddr("Receiver"); + address internal LIQUIDATOR = makeAddr("Liquidator"); IMorpho internal morpho; IrmMock internal irm; @@ -56,12 +56,6 @@ abstract contract BaseTest is Test { bytes[] internal callbackBundle; function setUp() public virtual { - USER = makeAddr("User"); - OWNER = makeAddr("Owner"); - SUPPLIER = makeAddr("Supplier"); - RECEIVER = makeAddr("Receiver"); - LIQUIDATOR = makeAddr("Liquidator"); - morpho = IMorpho(_deploy("lib/morpho-blue/out/Morpho.sol/Morpho.json", abi.encode(OWNER))); vm.label(address(morpho), "Morpho"); From 870a38d84501ba1d06172e3cd7f55b391e70b20a Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Tue, 17 Oct 2023 09:08:21 +0200 Subject: [PATCH 15/17] refactor(remappings): use relative imports --- config/ConfigLib.sol | 2 +- config/Configured.sol | 2 +- remappings.txt | 21 +---------- src/ERC4626Bundler.sol | 18 +++++----- src/MorphoBundler.sol | 6 ++-- src/Permit2Bundler.sol | 12 +++---- src/PermitBundler.sol | 4 +-- src/StEthBundler.sol | 4 +-- src/TransferBundler.sol | 10 +++--- src/UrdBundler.sol | 3 +- src/WNativeBundler.sol | 4 +-- src/interfaces/IMorphoBundler.sol | 2 +- src/migration/AaveV2MigrationBundler.sol | 4 +-- src/migration/AaveV3MigrationBundler.sol | 4 +-- .../AaveV3OptimizerMigrationBundler.sol | 6 ++-- src/migration/CompoundV2MigrationBundler.sol | 2 +- src/migration/CompoundV3MigrationBundler.sol | 2 +- src/migration/MigrationBundler.sol | 2 +- src/mocks/ERC20Mock.sol | 2 +- src/mocks/ERC20PermitMock.sol | 4 +-- src/mocks/ERC4626Mock.sol | 6 ++-- src/mocks/IrmMock.sol | 6 ++-- src/mocks/OracleMock.sol | 2 +- test/forge/ERC4626BundlerLocalTest.sol | 6 ++-- test/forge/MorphoBundlerLocalTest.sol | 6 ++-- test/forge/PermitBundlerLocalTest.sol | 4 +-- test/forge/TransferBundlerLocalTest.sol | 4 +-- test/forge/UrdBundlerLocalTest.sol | 13 +++---- .../ethereum/EthereumBundlerEthereumTest.sol | 4 +-- .../EthereumPermitBundlerEthereumTest.sol | 2 +- .../EthereumStEthBundlerEthereumTest.sol | 6 ++-- .../ethereum/Permit2BundlerEthereumTest.sol | 4 +-- .../ethereum/WNativeBundlerEthereumTest.sol | 4 +-- ...V2EthereumMigrationBundlerEthereumTest.sol | 10 +++--- .../AaveV3MigrationBundlerEthereumTest.sol | 6 ++-- ...3OptimizerMigrationBundlerEthereumTest.sol | 6 ++-- ...BorrowableMigrationBundlerEthereumTest.sol | 4 +-- ...CollateralMigrationBundlerEthereumTest.sol | 4 +-- ...undV2NoEthMigrationBundlerEthereumTest.sol | 4 +-- ...CompoundV3MigrationBundlerEthereumTest.sol | 2 +- .../helpers/EthereumMigrationTest.sol | 22 ++++++------ test/forge/helpers/BaseTest.sol | 36 +++++++++---------- test/forge/helpers/ForkTest.sol | 14 ++++---- test/forge/helpers/LocalTest.sol | 2 +- test/forge/helpers/SigUtils.sol | 16 ++++----- 45 files changed, 145 insertions(+), 162 deletions(-) diff --git a/config/ConfigLib.sol b/config/ConfigLib.sol index 767c6bd0..572dafbc 100644 --- a/config/ConfigLib.sol +++ b/config/ConfigLib.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {stdJson} from "@forge-std/StdJson.sol"; +import {stdJson} from "../lib/forge-std/src/StdJson.sol"; struct Config { string json; diff --git a/config/Configured.sol b/config/Configured.sol index 60f793b2..deaa03fc 100644 --- a/config/Configured.sol +++ b/config/Configured.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Config, ConfigMarket, ConfigLib} from "./ConfigLib.sol"; -import {StdChains, VmSafe} from "@forge-std/StdChains.sol"; +import {StdChains, VmSafe} from "../lib/forge-std/src/StdChains.sol"; abstract contract Configured is StdChains { using ConfigLib for Config; diff --git a/remappings.txt b/remappings.txt index 4d43a219..ed7fc103 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,22 +1,3 @@ -config/=config/ src/=src/ -test/=test/ -solmate/=lib/solmate/ - -@forge-std/=lib/morpho-blue/lib/forge-std/src/ -@solmate/=lib/solmate/src/ -@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/=lib/openzeppelin-contracts/contracts/ -@permit2/=lib/permit2/src/ - -@uniswap/v3-core=lib/v3-core/contracts/ -@uniswap/v3-periphery=lib/v3-periphery/contracts/ - -@aave/v3-core=lib/aave-v3-core/contracts/ - -@murky/=lib/murky/ +solmate/=lib/morpho-aave-v3/lib/permit2/lib/solmate/ diff --git a/src/ERC4626Bundler.sol b/src/ERC4626Bundler.sol index 9cc12efb..efa9a5a0 100644 --- a/src/ERC4626Bundler.sol +++ b/src/ERC4626Bundler.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {IERC4626} from "@openzeppelin/interfaces/IERC4626.sol"; +import {IERC4626} from "../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; +import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol"; import {BaseBundler} from "./BaseBundler.sol"; @@ -67,13 +67,13 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. - address initiator = initiator(); + address _initiator = initiator(); - assets = Math.min(assets, IERC4626(vault).maxWithdraw(initiator)); + assets = Math.min(assets, IERC4626(vault).maxWithdraw(_initiator)); require(assets != 0, ErrorsLib.ZERO_AMOUNT); - IERC4626(vault).withdraw(assets, receiver, initiator); + IERC4626(vault).withdraw(assets, receiver, _initiator); } /// @notice Redeems the given amount of `shares` from the given ERC4626 `vault`, transferring assets to `receiver`. @@ -84,12 +84,12 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. - address initiator = initiator(); + address _initiator = initiator(); - shares = Math.min(shares, IERC4626(vault).maxRedeem(initiator)); + shares = Math.min(shares, IERC4626(vault).maxRedeem(_initiator)); require(shares != 0, ErrorsLib.ZERO_SHARES); - IERC4626(vault).redeem(shares, receiver, initiator); + IERC4626(vault).redeem(shares, receiver, _initiator); } } diff --git a/src/MorphoBundler.sol b/src/MorphoBundler.sol index 34526ad0..00aa7bb4 100644 --- a/src/MorphoBundler.sol +++ b/src/MorphoBundler.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.21; import {IMorphoBundler} from "./interfaces/IMorphoBundler.sol"; -import {MarketParams, Signature, Authorization, IMorpho} from "@morpho-blue/interfaces/IMorpho.sol"; +import {MarketParams, Signature, Authorization, IMorpho} from "../lib/morpho-blue/src/interfaces/IMorpho.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.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"; diff --git a/src/Permit2Bundler.sol b/src/Permit2Bundler.sol index 6a78659e..5d642427 100644 --- a/src/Permit2Bundler.sol +++ b/src/Permit2Bundler.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {ISignatureTransfer} from "@permit2/interfaces/ISignatureTransfer.sol"; +import {ISignatureTransfer} from "../lib/permit2/src/interfaces/ISignatureTransfer.sol"; import "./libraries/ConstantsLib.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; -import {ERC20} from "solmate/src/tokens/ERC20.sol"; +import {Math} from "../lib/morpho-utils/src/math/Math.sol"; +import {ERC20} from "../lib/solmate/src/tokens/ERC20.sol"; import {BaseBundler} from "./BaseBundler.sol"; @@ -24,14 +24,14 @@ abstract contract Permit2Bundler is BaseBundler { external payable { - address initiator = initiator(); - uint256 amount = Math.min(permit.permitted.amount, ERC20(permit.permitted.token).balanceOf(initiator)); + address _initiator = initiator(); + uint256 amount = Math.min(permit.permitted.amount, ERC20(permit.permitted.token).balanceOf(_initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); ISignatureTransfer.SignatureTransferDetails memory transferDetails = ISignatureTransfer.SignatureTransferDetails({to: address(this), requestedAmount: amount}); - ISignatureTransfer(PERMIT2).permitTransferFrom(permit, transferDetails, initiator, signature); + ISignatureTransfer(PERMIT2).permitTransferFrom(permit, transferDetails, _initiator, signature); } } diff --git a/src/PermitBundler.sol b/src/PermitBundler.sol index c690b16b..ee916336 100644 --- a/src/PermitBundler.sol +++ b/src/PermitBundler.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {IERC20Permit} from "@openzeppelin/token/ERC20/extensions/IERC20Permit.sol"; +import {IERC20Permit} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol"; import {BaseBundler} from "./BaseBundler.sol"; @@ -13,7 +13,7 @@ abstract contract PermitBundler is BaseBundler { /// @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`. /// @notice Warning: should only be called via the bundler's `multicall` function. - /// @dev Pass `skipRevert = true` to avoid reverting the whole bundle in case the signature expired. + /// @dev Pass `skipRevert == true` to avoid reverting the whole bundle in case the signature expired. function permit(address asset, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s, bool skipRevert) external payable diff --git a/src/StEthBundler.sol b/src/StEthBundler.sol index 83c47aaa..1459fb83 100644 --- a/src/StEthBundler.sol +++ b/src/StEthBundler.sol @@ -4,9 +4,9 @@ pragma solidity 0.8.21; import {IWstEth} from "./interfaces/IWstEth.sol"; import {IStEth} from "./interfaces/IStEth.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; +import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol"; import {BaseBundler} from "./BaseBundler.sol"; diff --git a/src/TransferBundler.sol b/src/TransferBundler.sol index fab73ae4..74d76816 100644 --- a/src/TransferBundler.sol +++ b/src/TransferBundler.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; +import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol"; import {BaseBundler} from "./BaseBundler.sol"; @@ -49,11 +49,11 @@ abstract contract TransferBundler is BaseBundler { /// @notice Warning: should only be called via the bundler's `multicall` function. /// @dev Pass `amount = type(uint256).max` to transfer all. function erc20TransferFrom(address asset, uint256 amount) external payable { - address initiator = initiator(); - amount = Math.min(amount, ERC20(asset).balanceOf(initiator)); + address _initiator = initiator(); + amount = Math.min(amount, ERC20(asset).balanceOf(_initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); - ERC20(asset).safeTransferFrom(initiator, address(this), amount); + ERC20(asset).safeTransferFrom(_initiator, address(this), amount); } } diff --git a/src/UrdBundler.sol b/src/UrdBundler.sol index c1be286d..dc8cd165 100644 --- a/src/UrdBundler.sol +++ b/src/UrdBundler.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {IUniversalRewardsDistributor} from "@universal-rewards-distributor/interfaces/IUniversalRewardsDistributor.sol"; +import {IUniversalRewardsDistributor} from + "../lib/universal-rewards-distributor/src/interfaces/IUniversalRewardsDistributor.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; diff --git a/src/WNativeBundler.sol b/src/WNativeBundler.sol index 447fa1a8..88d64525 100644 --- a/src/WNativeBundler.sol +++ b/src/WNativeBundler.sol @@ -3,9 +3,9 @@ pragma solidity 0.8.21; import {IWNative} from "./interfaces/IWNative.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "./libraries/ErrorsLib.sol"; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; +import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol"; import {BaseBundler} from "./BaseBundler.sol"; diff --git a/src/interfaces/IMorphoBundler.sol b/src/interfaces/IMorphoBundler.sol index a421ee5d..e181f53f 100644 --- a/src/interfaces/IMorphoBundler.sol +++ b/src/interfaces/IMorphoBundler.sol @@ -6,7 +6,7 @@ import { IMorphoSupplyCallback, IMorphoSupplyCollateralCallback, IMorphoFlashLoanCallback -} from "@morpho-blue/interfaces/IMorphoCallbacks.sol"; +} from "../../lib/morpho-blue/src/interfaces/IMorphoCallbacks.sol"; interface IMorphoBundler is IMorphoSupplyCallback, diff --git a/src/migration/AaveV2MigrationBundler.sol b/src/migration/AaveV2MigrationBundler.sol index b7523e62..a52ba9ae 100644 --- a/src/migration/AaveV2MigrationBundler.sol +++ b/src/migration/AaveV2MigrationBundler.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {ILendingPool} from "@morpho-v1/aave-v2/interfaces/aave/ILendingPool.sol"; +import {ILendingPool} from "../../lib/morpho-v1/src/aave-v2/interfaces/aave/ILendingPool.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "../libraries/ErrorsLib.sol"; import {MigrationBundler, ERC20} from "./MigrationBundler.sol"; diff --git a/src/migration/AaveV3MigrationBundler.sol b/src/migration/AaveV3MigrationBundler.sol index 9cc24168..270f49bf 100644 --- a/src/migration/AaveV3MigrationBundler.sol +++ b/src/migration/AaveV3MigrationBundler.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {IPool} from "@aave/v3-core/interfaces/IPool.sol"; +import {IPool} from "../../lib/aave-v3-core/contracts/interfaces/IPool.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "../libraries/ErrorsLib.sol"; import {MigrationBundler, ERC20} from "./MigrationBundler.sol"; diff --git a/src/migration/AaveV3OptimizerMigrationBundler.sol b/src/migration/AaveV3OptimizerMigrationBundler.sol index c8d9897f..6bd25279 100644 --- a/src/migration/AaveV3OptimizerMigrationBundler.sol +++ b/src/migration/AaveV3OptimizerMigrationBundler.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {IMorpho as IAaveV3Optimizer} from "@morpho-aave-v3/interfaces/IMorpho.sol"; +import {IMorpho as IAaveV3Optimizer} from "../../lib/morpho-aave-v3/src/interfaces/IMorpho.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "../libraries/ErrorsLib.sol"; -import {Types} from "@morpho-aave-v3/libraries/Types.sol"; +import {Types} from "../../lib/morpho-aave-v3/src/libraries/Types.sol"; import {MigrationBundler, ERC20} from "./MigrationBundler.sol"; diff --git a/src/migration/CompoundV2MigrationBundler.sol b/src/migration/CompoundV2MigrationBundler.sol index 076c0a00..b5a46cbf 100644 --- a/src/migration/CompoundV2MigrationBundler.sol +++ b/src/migration/CompoundV2MigrationBundler.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.21; import {ICEth} from "./interfaces/ICEth.sol"; import {ICToken} from "./interfaces/ICToken.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "../libraries/ErrorsLib.sol"; import {WNativeBundler} from "../WNativeBundler.sol"; diff --git a/src/migration/CompoundV3MigrationBundler.sol b/src/migration/CompoundV3MigrationBundler.sol index a5db968c..9bd7fd97 100644 --- a/src/migration/CompoundV3MigrationBundler.sol +++ b/src/migration/CompoundV3MigrationBundler.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.21; import {ICompoundV3} from "./interfaces/ICompoundV3.sol"; -import {Math} from "@morpho-utils/math/Math.sol"; +import {Math} from "../../lib/morpho-utils/src/math/Math.sol"; import {ErrorsLib} from "../libraries/ErrorsLib.sol"; import {MigrationBundler, ERC20} from "./MigrationBundler.sol"; diff --git a/src/migration/MigrationBundler.sol b/src/migration/MigrationBundler.sol index fac61d25..fa0f0e79 100644 --- a/src/migration/MigrationBundler.sol +++ b/src/migration/MigrationBundler.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; +import {SafeTransferLib, ERC20} from "../../lib/solmate/src/utils/SafeTransferLib.sol"; import {TransferBundler} from "../TransferBundler.sol"; import {PermitBundler} from "../PermitBundler.sol"; diff --git a/src/mocks/ERC20Mock.sol b/src/mocks/ERC20Mock.sol index a580886c..595bdd21 100644 --- a/src/mocks/ERC20Mock.sol +++ b/src/mocks/ERC20Mock.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ERC20} from "@openzeppelin/token/ERC20/ERC20.sol"; +import {ERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; contract ERC20Mock is ERC20 { constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {} diff --git a/src/mocks/ERC20PermitMock.sol b/src/mocks/ERC20PermitMock.sol index 6d94a9f1..34c24488 100644 --- a/src/mocks/ERC20PermitMock.sol +++ b/src/mocks/ERC20PermitMock.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ERC20Permit} from "@openzeppelin/token/ERC20/extensions/ERC20Permit.sol"; -import {ERC20} from "@openzeppelin/token/ERC20/ERC20.sol"; +import {ERC20Permit} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Permit.sol"; +import {ERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; contract ERC20PermitMock is ERC20Permit { constructor(string memory _name, string memory _symbol) ERC20Permit(_name) ERC20(_name, _symbol) {} diff --git a/src/mocks/ERC4626Mock.sol b/src/mocks/ERC4626Mock.sol index 6ca1bf9e..51f4db77 100644 --- a/src/mocks/ERC4626Mock.sol +++ b/src/mocks/ERC4626Mock.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IERC20} from "@openzeppelin/token/ERC20/IERC20.sol"; -import {ERC20} from "@openzeppelin/token/ERC20/ERC20.sol"; -import {ERC4626} from "@openzeppelin/token/ERC20/extensions/ERC4626.sol"; +import {IERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; +import {ERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; +import {ERC4626} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC4626.sol"; contract ERC4626Mock is ERC4626 { constructor(address asset, string memory name, string memory symbol) ERC4626(IERC20(asset)) ERC20(name, symbol) {} diff --git a/src/mocks/IrmMock.sol b/src/mocks/IrmMock.sol index 53d07a0c..16042f3f 100644 --- a/src/mocks/IrmMock.sol +++ b/src/mocks/IrmMock.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IIrm} from "@morpho-blue/interfaces/IIrm.sol"; -import {MarketParams, Market} from "@morpho-blue/interfaces/IMorpho.sol"; +import {IIrm} from "../../lib/morpho-blue/src/interfaces/IIrm.sol"; +import {MarketParams, Market} from "../../lib/morpho-blue/src/interfaces/IMorpho.sol"; -import {MathLib} from "@morpho-blue/libraries/MathLib.sol"; +import {MathLib} from "../../lib/morpho-blue/src/libraries/MathLib.sol"; contract IrmMock is IIrm { using MathLib for uint128; diff --git a/src/mocks/OracleMock.sol b/src/mocks/OracleMock.sol index f3db86b9..ffccee1f 100644 --- a/src/mocks/OracleMock.sol +++ b/src/mocks/OracleMock.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IOracle} from "@morpho-blue/interfaces/IOracle.sol"; +import {IOracle} from "../../lib/morpho-blue/src/interfaces/IOracle.sol"; contract OracleMock is IOracle { uint256 public price; diff --git a/test/forge/ERC4626BundlerLocalTest.sol b/test/forge/ERC4626BundlerLocalTest.sol index 06b53015..2b05fc5e 100644 --- a/test/forge/ERC4626BundlerLocalTest.sol +++ b/test/forge/ERC4626BundlerLocalTest.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ErrorsLib} from "src/libraries/ErrorsLib.sol"; +import {ErrorsLib} from "../../src/libraries/ErrorsLib.sol"; -import {ERC4626Mock} from "src/mocks/ERC4626Mock.sol"; -import "src/mocks/bundlers/ERC4626BundlerMock.sol"; +import {ERC4626Mock} from "../../src/mocks/ERC4626Mock.sol"; +import "../../src/mocks/bundlers/ERC4626BundlerMock.sol"; import "./helpers/LocalTest.sol"; diff --git a/test/forge/MorphoBundlerLocalTest.sol b/test/forge/MorphoBundlerLocalTest.sol index 2cb898f4..4a652e9e 100644 --- a/test/forge/MorphoBundlerLocalTest.sol +++ b/test/forge/MorphoBundlerLocalTest.sol @@ -2,10 +2,10 @@ pragma solidity ^0.8.0; import {SigUtils} from "./helpers/SigUtils.sol"; -import {ErrorsLib} from "src/libraries/ErrorsLib.sol"; -import {ErrorsLib as MorphoErrorsLib} from "@morpho-blue/libraries/ErrorsLib.sol"; +import {ErrorsLib} from "../../src/libraries/ErrorsLib.sol"; +import {ErrorsLib as MorphoErrorsLib} from "../../lib/morpho-blue/src/libraries/ErrorsLib.sol"; -import "src/mocks/bundlers/MorphoBundlerMock.sol"; +import "../../src/mocks/bundlers/MorphoBundlerMock.sol"; import "./helpers/LocalTest.sol"; diff --git a/test/forge/PermitBundlerLocalTest.sol b/test/forge/PermitBundlerLocalTest.sol index e4c79ec8..6dc2f55e 100644 --- a/test/forge/PermitBundlerLocalTest.sol +++ b/test/forge/PermitBundlerLocalTest.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.0; import {SigUtils, Permit} from "test/forge/helpers/SigUtils.sol"; -import "src/mocks/bundlers/PermitBundlerMock.sol"; -import {ERC20PermitMock} from "src/mocks/ERC20PermitMock.sol"; +import "../../src/mocks/bundlers/PermitBundlerMock.sol"; +import {ERC20PermitMock} from "../../src/mocks/ERC20PermitMock.sol"; import "./helpers/LocalTest.sol"; diff --git a/test/forge/TransferBundlerLocalTest.sol b/test/forge/TransferBundlerLocalTest.sol index c2cd1d3e..3b3d0dbf 100644 --- a/test/forge/TransferBundlerLocalTest.sol +++ b/test/forge/TransferBundlerLocalTest.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ErrorsLib} from "src/libraries/ErrorsLib.sol"; +import {ErrorsLib} from "../../src/libraries/ErrorsLib.sol"; -import "src/mocks/bundlers/TransferBundlerMock.sol"; +import "../../src/mocks/bundlers/TransferBundlerMock.sol"; import "./helpers/LocalTest.sol"; diff --git a/test/forge/UrdBundlerLocalTest.sol b/test/forge/UrdBundlerLocalTest.sol index b74357e4..915369a1 100644 --- a/test/forge/UrdBundlerLocalTest.sol +++ b/test/forge/UrdBundlerLocalTest.sol @@ -1,15 +1,16 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IUniversalRewardsDistributor} from "@universal-rewards-distributor/interfaces/IUniversalRewardsDistributor.sol"; +import {IUniversalRewardsDistributor} from + "../../lib/universal-rewards-distributor/src/interfaces/IUniversalRewardsDistributor.sol"; -import {ErrorsLib} from "src/libraries/ErrorsLib.sol"; -import {ErrorsLib as UrdErrorsLib} from "@universal-rewards-distributor/libraries/ErrorsLib.sol"; +import {ErrorsLib} from "../../src/libraries/ErrorsLib.sol"; +import {ErrorsLib as UrdErrorsLib} from "../../lib/universal-rewards-distributor/src/libraries/ErrorsLib.sol"; -import {Merkle} from "@murky/src/Merkle.sol"; -import {UrdFactory} from "@universal-rewards-distributor/UrdFactory.sol"; +import {Merkle} from "../../lib/murky/src/Merkle.sol"; +import {UrdFactory} from "../../lib/universal-rewards-distributor/src/UrdFactory.sol"; -import "src/mocks/bundlers/UrdBundlerMock.sol"; +import "../../src/mocks/bundlers/UrdBundlerMock.sol"; import "./helpers/LocalTest.sol"; diff --git a/test/forge/ethereum/EthereumBundlerEthereumTest.sol b/test/forge/ethereum/EthereumBundlerEthereumTest.sol index b0417d60..32755909 100644 --- a/test/forge/ethereum/EthereumBundlerEthereumTest.sol +++ b/test/forge/ethereum/EthereumBundlerEthereumTest.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IAllowanceTransfer} from "@permit2/interfaces/IAllowanceTransfer.sol"; +import {IAllowanceTransfer} from "../../../lib/permit2/src/interfaces/IAllowanceTransfer.sol"; -import "src/ethereum/EthereumBundler.sol"; +import "../../../src/ethereum/EthereumBundler.sol"; import "./helpers/EthereumTest.sol"; diff --git a/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol b/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol index c6e3a492..30fde51e 100644 --- a/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol +++ b/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {DaiPermit} from "../helpers/SigUtils.sol"; -import "src/mocks/bundlers/ethereum/EthereumPermitBundlerMock.sol"; +import "../../../src/mocks/bundlers/ethereum/EthereumPermitBundlerMock.sol"; import "./helpers/EthereumTest.sol"; diff --git a/test/forge/ethereum/EthereumStEthBundlerEthereumTest.sol b/test/forge/ethereum/EthereumStEthBundlerEthereumTest.sol index 8a0de69d..cb9ae4c9 100644 --- a/test/forge/ethereum/EthereumStEthBundlerEthereumTest.sol +++ b/test/forge/ethereum/EthereumStEthBundlerEthereumTest.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IAllowanceTransfer} from "@permit2/interfaces/IAllowanceTransfer.sol"; +import {IAllowanceTransfer} from "../../../lib/permit2/src/interfaces/IAllowanceTransfer.sol"; -import {ErrorsLib} from "src/libraries/ErrorsLib.sol"; +import {ErrorsLib} from "../../../src/libraries/ErrorsLib.sol"; -import "src/mocks/bundlers/ethereum/EthereumStEthBundlerMock.sol"; +import "../../../src/mocks/bundlers/ethereum/EthereumStEthBundlerMock.sol"; import "./helpers/EthereumTest.sol"; diff --git a/test/forge/ethereum/Permit2BundlerEthereumTest.sol b/test/forge/ethereum/Permit2BundlerEthereumTest.sol index b98fe25a..659951d4 100644 --- a/test/forge/ethereum/Permit2BundlerEthereumTest.sol +++ b/test/forge/ethereum/Permit2BundlerEthereumTest.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ErrorsLib} from "src/libraries/ErrorsLib.sol"; +import {ErrorsLib} from "../../../src/libraries/ErrorsLib.sol"; -import "src/mocks/bundlers/Permit2BundlerMock.sol"; +import "../../../src/mocks/bundlers/Permit2BundlerMock.sol"; import "./helpers/EthereumTest.sol"; diff --git a/test/forge/ethereum/WNativeBundlerEthereumTest.sol b/test/forge/ethereum/WNativeBundlerEthereumTest.sol index cd583e38..2b3bc7c0 100644 --- a/test/forge/ethereum/WNativeBundlerEthereumTest.sol +++ b/test/forge/ethereum/WNativeBundlerEthereumTest.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ErrorsLib} from "src/libraries/ErrorsLib.sol"; +import {ErrorsLib} from "../../../src/libraries/ErrorsLib.sol"; -import "src/mocks/bundlers/WNativeBundlerMock.sol"; +import "../../../src/mocks/bundlers/WNativeBundlerMock.sol"; import "./helpers/EthereumTest.sol"; diff --git a/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol index 30cab518..7b11204d 100644 --- a/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ILendingPool} from "@morpho-v1/aave-v2/interfaces/aave/ILendingPool.sol"; -import {IAToken} from "@morpho-v1/aave-v2/interfaces/aave/IAToken.sol"; -import {IERC4626} from "@openzeppelin/interfaces/IERC4626.sol"; -import {IStEth} from "src/interfaces/IStEth.sol"; +import {ILendingPool} from "../../../../lib/morpho-v1/src/aave-v2/interfaces/aave/ILendingPool.sol"; +import {IAToken} from "../../../../lib/morpho-v1/src/aave-v2/interfaces/aave/IAToken.sol"; +import {IERC4626} from "../../../../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol"; +import {IStEth} from "../../../../src/interfaces/IStEth.sol"; -import "src/ethereum/migration/AaveV2EthereumMigrationBundler.sol"; +import "../../../../src/ethereum/migration/AaveV2EthereumMigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol index a645d4e0..dabbf826 100644 --- a/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IPool} from "@aave/v3-core/interfaces/IPool.sol"; -import {IAToken} from "@aave/v3-core/interfaces/IAToken.sol"; +import {IPool} from "../../../../lib/aave-v3-core/contracts/interfaces/IPool.sol"; +import {IAToken} from "../../../../lib/aave-v3-core/contracts/interfaces/IAToken.sol"; import {SigUtils, Permit} from "test/forge/helpers/SigUtils.sol"; -import "src/migration/AaveV3MigrationBundler.sol"; +import "../../../../src/migration/AaveV3MigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol index 4807140f..2d6eb90d 100644 --- a/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IMorpho as IAaveV3Optimizer} from "@morpho-aave-v3/interfaces/IMorpho.sol"; +import {IMorpho as IAaveV3Optimizer} from "../../../../lib/morpho-aave-v3/src/interfaces/IMorpho.sol"; -import {Types} from "@morpho-aave-v3/libraries/Types.sol"; +import {Types} from "../../../../lib/morpho-aave-v3/src/libraries/Types.sol"; import {AaveV3OptimizerAuthorization} from "../../helpers/SigUtils.sol"; -import "src/migration/AaveV3OptimizerMigrationBundler.sol"; +import "../../../../src/migration/AaveV3OptimizerMigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol index 01fd1f91..cc697ca9 100644 --- a/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IComptroller} from "src/migration/interfaces/IComptroller.sol"; +import {IComptroller} from "../../../../src/migration/interfaces/IComptroller.sol"; -import "src/migration/CompoundV2MigrationBundler.sol"; +import "../../../../src/migration/CompoundV2MigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/ethereum/migration/CompoundV2EthCollateralMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/CompoundV2EthCollateralMigrationBundlerEthereumTest.sol index fd0035b7..c3f7ea69 100644 --- a/test/forge/ethereum/migration/CompoundV2EthCollateralMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/CompoundV2EthCollateralMigrationBundlerEthereumTest.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IComptroller} from "src/migration/interfaces/IComptroller.sol"; +import {IComptroller} from "../../../../src/migration/interfaces/IComptroller.sol"; -import "src/migration/CompoundV2MigrationBundler.sol"; +import "../../../../src/migration/CompoundV2MigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/ethereum/migration/CompoundV2NoEthMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/CompoundV2NoEthMigrationBundlerEthereumTest.sol index 2792629b..0adc1a1b 100644 --- a/test/forge/ethereum/migration/CompoundV2NoEthMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/CompoundV2NoEthMigrationBundlerEthereumTest.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {IComptroller} from "src/migration/interfaces/IComptroller.sol"; +import {IComptroller} from "../../../../src/migration/interfaces/IComptroller.sol"; -import "src/migration/CompoundV2MigrationBundler.sol"; +import "../../../../src/migration/CompoundV2MigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol index 0d19f592..ecb7930e 100644 --- a/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {CompoundV3Authorization} from "../../helpers/SigUtils.sol"; -import "src/migration/CompoundV3MigrationBundler.sol"; +import "../../../../src/migration/CompoundV3MigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/ethereum/migration/helpers/EthereumMigrationTest.sol b/test/forge/ethereum/migration/helpers/EthereumMigrationTest.sol index 72519fdf..f0929f21 100644 --- a/test/forge/ethereum/migration/helpers/EthereumMigrationTest.sol +++ b/test/forge/ethereum/migration/helpers/EthereumMigrationTest.sol @@ -1,19 +1,19 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; -import {ErrorsLib} from "src/libraries/ErrorsLib.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"; +import {SafeTransferLib, ERC20} from "../../../../../lib/solmate/src/utils/SafeTransferLib.sol"; +import {ErrorsLib} from "../../../../../src/libraries/ErrorsLib.sol"; +import {MarketParamsLib} from "../../../../../lib/morpho-blue/src/libraries/MarketParamsLib.sol"; +import {MorphoLib} from "../../../../../lib/morpho-blue/src/libraries/periphery/MorphoLib.sol"; +import {MorphoBalancesLib} from "../../../../../lib/morpho-blue/src/libraries/periphery/MorphoBalancesLib.sol"; import "../../helpers/EthereumTest.sol"; -import {BaseBundler} from "src/BaseBundler.sol"; -import {PermitBundler} from "src/PermitBundler.sol"; -import {Permit2Bundler} from "src/Permit2Bundler.sol"; -import {ERC4626Bundler} from "src/ERC4626Bundler.sol"; -import {MorphoBundler} from "src/MorphoBundler.sol"; -import {ERC4626Mock} from "src/mocks/ERC4626Mock.sol"; +import {BaseBundler} from "../../../../../src/BaseBundler.sol"; +import {PermitBundler} from "../../../../../src/PermitBundler.sol"; +import {Permit2Bundler} from "../../../../../src/Permit2Bundler.sol"; +import {ERC4626Bundler} from "../../../../../src/ERC4626Bundler.sol"; +import {MorphoBundler} from "../../../../../src/MorphoBundler.sol"; +import {ERC4626Mock} from "../../../../../src/mocks/ERC4626Mock.sol"; contract EthereumMigrationTest is EthereumTest { using SafeTransferLib for ERC20; diff --git a/test/forge/helpers/BaseTest.sol b/test/forge/helpers/BaseTest.sol index 691d78cf..7ba80a65 100644 --- a/test/forge/helpers/BaseTest.sol +++ b/test/forge/helpers/BaseTest.sol @@ -1,33 +1,33 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import "@morpho-blue/interfaces/IMorpho.sol"; +import "../../../lib/morpho-blue/src/interfaces/IMorpho.sol"; import {SigUtils} from "./SigUtils.sol"; -import {MarketParamsLib} from "@morpho-blue/libraries/MarketParamsLib.sol"; -import {SharesMathLib} from "@morpho-blue/libraries/SharesMathLib.sol"; -import {MathLib, WAD} from "@morpho-blue/libraries/MathLib.sol"; -import {UtilsLib} from "@morpho-blue/libraries/UtilsLib.sol"; -import {SafeTransferLib, ERC20} from "solmate/src/utils/SafeTransferLib.sol"; -import {MorphoLib} from "@morpho-blue/libraries/periphery/MorphoLib.sol"; -import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol"; +import {MarketParamsLib} from "../../../lib/morpho-blue/src/libraries/MarketParamsLib.sol"; +import {SharesMathLib} from "../../../lib/morpho-blue/src/libraries/SharesMathLib.sol"; +import {MathLib, WAD} from "../../../lib/morpho-blue/src/libraries/MathLib.sol"; +import {UtilsLib} from "../../../lib/morpho-blue/src/libraries/UtilsLib.sol"; +import {SafeTransferLib, ERC20} from "../../../lib/solmate/src/utils/SafeTransferLib.sol"; +import {MorphoLib} from "../../../lib/morpho-blue/src/libraries/periphery/MorphoLib.sol"; +import {MorphoBalancesLib} from "../../../lib/morpho-blue/src/libraries/periphery/MorphoBalancesLib.sol"; import { LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE -} from "@morpho-blue/libraries/ConstantsLib.sol"; +} from "../../../lib/morpho-blue/src/libraries/ConstantsLib.sol"; -import {IrmMock} from "@morpho-blue/mocks/IrmMock.sol"; -import {OracleMock} from "@morpho-blue/mocks/OracleMock.sol"; +import {IrmMock} from "../../../lib/morpho-blue/src/mocks/IrmMock.sol"; +import {OracleMock} from "../../../lib/morpho-blue/src/mocks/OracleMock.sol"; -import {BaseBundler} from "src/BaseBundler.sol"; -import {TransferBundler} from "src/TransferBundler.sol"; -import {ERC4626Bundler} from "src/ERC4626Bundler.sol"; -import {UrdBundler} from "src/UrdBundler.sol"; -import {MorphoBundler} from "src/MorphoBundler.sol"; +import {BaseBundler} from "../../../src/BaseBundler.sol"; +import {TransferBundler} from "../../../src/TransferBundler.sol"; +import {ERC4626Bundler} from "../../../src/ERC4626Bundler.sol"; +import {UrdBundler} from "../../../src/UrdBundler.sol"; +import {MorphoBundler} from "../../../src/MorphoBundler.sol"; -import "@forge-std/Test.sol"; -import "@forge-std/console2.sol"; +import "../../../lib/forge-std/src/Test.sol"; +import "../../../lib/forge-std/src/console2.sol"; uint256 constant MIN_AMOUNT = 1000; uint256 constant MAX_AMOUNT = 2 ** 64; // Must be less than or equal to type(uint160).max. diff --git a/test/forge/helpers/ForkTest.sol b/test/forge/helpers/ForkTest.sol index fe9e147e..6eb8352a 100644 --- a/test/forge/helpers/ForkTest.sol +++ b/test/forge/helpers/ForkTest.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IStEth} from "src/interfaces/IStEth.sol"; -import {IWstEth} from "src/interfaces/IWstEth.sol"; -import {ISignatureTransfer} from "@permit2/interfaces/ISignatureTransfer.sol"; +import {IStEth} from "../../../src/interfaces/IStEth.sol"; +import {IWstEth} from "../../../src/interfaces/IWstEth.sol"; +import {ISignatureTransfer} from "../../../lib/permit2/src/interfaces/ISignatureTransfer.sol"; -import {Permit2Lib} from "@permit2/libraries/Permit2Lib.sol"; +import {Permit2Lib} from "../../../lib/permit2/src/libraries/Permit2Lib.sol"; -import {Permit2Bundler} from "src/Permit2Bundler.sol"; -import {WNativeBundler} from "src/WNativeBundler.sol"; -import {StEthBundler} from "src/StEthBundler.sol"; +import {Permit2Bundler} from "../../../src/Permit2Bundler.sol"; +import {WNativeBundler} from "../../../src/WNativeBundler.sol"; +import {StEthBundler} from "../../../src/StEthBundler.sol"; import "config/Configured.sol"; import "./BaseTest.sol"; diff --git a/test/forge/helpers/LocalTest.sol b/test/forge/helpers/LocalTest.sol index c138ca0e..10bdf4ff 100644 --- a/test/forge/helpers/LocalTest.sol +++ b/test/forge/helpers/LocalTest.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ERC20Mock} from "src/mocks/ERC20Mock.sol"; +import {ERC20Mock} from "../../../src/mocks/ERC20Mock.sol"; import "./BaseTest.sol"; diff --git a/test/forge/helpers/SigUtils.sol b/test/forge/helpers/SigUtils.sol index 00e57c2d..c8ae76b9 100644 --- a/test/forge/helpers/SigUtils.sol +++ b/test/forge/helpers/SigUtils.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {ICompoundV3} from "src/migration/interfaces/ICompoundV3.sol"; -import {Authorization} from "@morpho-blue/interfaces/IMorpho.sol"; -import {ISignatureTransfer} from "@permit2/interfaces/ISignatureTransfer.sol"; - -import {PermitHash} from "@permit2/libraries/PermitHash.sol"; -import {ECDSA} from "@openzeppelin/utils/cryptography/ECDSA.sol"; -import {AUTHORIZATION_TYPEHASH} from "@morpho-blue/libraries/ConstantsLib.sol"; -import {Constants as AaveV3OptimizerConstants} from "@morpho-aave-v3/libraries/Constants.sol"; +import {ICompoundV3} from "../../../src/migration/interfaces/ICompoundV3.sol"; +import {Authorization} from "../../../lib/morpho-blue/src/interfaces/IMorpho.sol"; +import {ISignatureTransfer} from "../../../lib/permit2/src/interfaces/ISignatureTransfer.sol"; + +import {PermitHash} from "../../../lib/permit2/src/libraries/PermitHash.sol"; +import {ECDSA} from "../../../lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol"; +import {AUTHORIZATION_TYPEHASH} from "../../../lib/morpho-blue/src/libraries/ConstantsLib.sol"; +import {Constants as AaveV3OptimizerConstants} from "../../../lib/morpho-aave-v3/src/libraries/Constants.sol"; bytes32 constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); From 35b7c8e6a2628c2fb65b91f555afc2863513c4fc Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Tue, 17 Oct 2023 09:46:18 +0200 Subject: [PATCH 16/17] build(test): fix imports --- lib/forge-std | 1 + lib/morpho-blue | 2 +- lib/universal-rewards-distributor | 2 +- remappings.txt | 2 ++ test/forge/PermitBundlerLocalTest.sol | 2 +- test/forge/ethereum/helpers/EthereumTest.sol | 2 +- .../ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol | 2 +- test/forge/helpers/ForkTest.sol | 2 +- 8 files changed, 9 insertions(+), 6 deletions(-) create mode 160000 lib/forge-std diff --git a/lib/forge-std b/lib/forge-std new file mode 160000 index 00000000..f73c73d2 --- /dev/null +++ b/lib/forge-std @@ -0,0 +1 @@ +Subproject commit f73c73d2018eb6a111f35e4dae7b4f27401e9421 diff --git a/lib/morpho-blue b/lib/morpho-blue index 5de3552d..82884a63 160000 --- a/lib/morpho-blue +++ b/lib/morpho-blue @@ -1 +1 @@ -Subproject commit 5de3552dbdf7fd8ea1f5f175313ce3bbdfda2e1f +Subproject commit 82884a63c6a108b69f2617dbc01be8d09ba2924d diff --git a/lib/universal-rewards-distributor b/lib/universal-rewards-distributor index af5c6981..26388ed6 160000 --- a/lib/universal-rewards-distributor +++ b/lib/universal-rewards-distributor @@ -1 +1 @@ -Subproject commit af5c69815a6cfff532829001573443395443d73b +Subproject commit 26388ed651c0d774d74c1335c104b4a11718e3bd diff --git a/remappings.txt b/remappings.txt index ed7fc103..37c8fbd7 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,3 +1,5 @@ src/=src/ +test/=test/ +config/=config/ solmate/=lib/morpho-aave-v3/lib/permit2/lib/solmate/ diff --git a/test/forge/PermitBundlerLocalTest.sol b/test/forge/PermitBundlerLocalTest.sol index 6dc2f55e..b3722cf6 100644 --- a/test/forge/PermitBundlerLocalTest.sol +++ b/test/forge/PermitBundlerLocalTest.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import {SigUtils, Permit} from "test/forge/helpers/SigUtils.sol"; +import {SigUtils, Permit} from "./helpers/SigUtils.sol"; import "../../src/mocks/bundlers/PermitBundlerMock.sol"; import {ERC20PermitMock} from "../../src/mocks/ERC20PermitMock.sol"; diff --git a/test/forge/ethereum/helpers/EthereumTest.sol b/test/forge/ethereum/helpers/EthereumTest.sol index 4df952d5..ef7bf2f9 100644 --- a/test/forge/ethereum/helpers/EthereumTest.sol +++ b/test/forge/ethereum/helpers/EthereumTest.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; -import "config/ConfiguredEthereum.sol"; +import "../../../../config/ConfiguredEthereum.sol"; import "../../helpers/ForkTest.sol"; diff --git a/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol index dabbf826..b8632637 100644 --- a/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {IPool} from "../../../../lib/aave-v3-core/contracts/interfaces/IPool.sol"; import {IAToken} from "../../../../lib/aave-v3-core/contracts/interfaces/IAToken.sol"; -import {SigUtils, Permit} from "test/forge/helpers/SigUtils.sol"; +import {SigUtils, Permit} from "../../helpers/SigUtils.sol"; import "../../../../src/migration/AaveV3MigrationBundler.sol"; import "./helpers/EthereumMigrationTest.sol"; diff --git a/test/forge/helpers/ForkTest.sol b/test/forge/helpers/ForkTest.sol index 6eb8352a..64039f4e 100644 --- a/test/forge/helpers/ForkTest.sol +++ b/test/forge/helpers/ForkTest.sol @@ -11,7 +11,7 @@ import {Permit2Bundler} from "../../../src/Permit2Bundler.sol"; import {WNativeBundler} from "../../../src/WNativeBundler.sol"; import {StEthBundler} from "../../../src/StEthBundler.sol"; -import "config/Configured.sol"; +import "../../../config/Configured.sol"; import "./BaseTest.sol"; abstract contract ForkTest is BaseTest, Configured { From 5ae0d8b910cce69d9fa1dd423905bf6a12cf7b7c Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 18 Oct 2023 10:58:41 +0200 Subject: [PATCH 17/17] refactor(initiator): revert shadowing --- lib/morpho-blue | 2 +- src/ERC4626Bundler.sol | 12 ++++++------ src/Permit2Bundler.sol | 6 +++--- src/TransferBundler.sol | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/morpho-blue b/lib/morpho-blue index 82884a63..7209539d 160000 --- a/lib/morpho-blue +++ b/lib/morpho-blue @@ -1 +1 @@ -Subproject commit 82884a63c6a108b69f2617dbc01be8d09ba2924d +Subproject commit 7209539d4a0ee968441312a63a5b70dc7b476d38 diff --git a/src/ERC4626Bundler.sol b/src/ERC4626Bundler.sol index efa9a5a0..22219e9d 100644 --- a/src/ERC4626Bundler.sol +++ b/src/ERC4626Bundler.sol @@ -67,13 +67,13 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. - address _initiator = initiator(); + address initiator = initiator(); - assets = Math.min(assets, IERC4626(vault).maxWithdraw(_initiator)); + assets = Math.min(assets, IERC4626(vault).maxWithdraw(initiator)); require(assets != 0, ErrorsLib.ZERO_AMOUNT); - IERC4626(vault).withdraw(assets, receiver, _initiator); + IERC4626(vault).withdraw(assets, receiver, initiator); } /// @notice Redeems the given amount of `shares` from the given ERC4626 `vault`, transferring assets to `receiver`. @@ -84,12 +84,12 @@ abstract contract ERC4626Bundler is BaseBundler { require(receiver != address(0), ErrorsLib.ZERO_ADDRESS); /// Do not check `receiver != address(this)` to allow the bundler to receive the underlying asset. - address _initiator = initiator(); + address initiator = initiator(); - shares = Math.min(shares, IERC4626(vault).maxRedeem(_initiator)); + shares = Math.min(shares, IERC4626(vault).maxRedeem(initiator)); require(shares != 0, ErrorsLib.ZERO_SHARES); - IERC4626(vault).redeem(shares, receiver, _initiator); + IERC4626(vault).redeem(shares, receiver, initiator); } } diff --git a/src/Permit2Bundler.sol b/src/Permit2Bundler.sol index 5d642427..7be7d88e 100644 --- a/src/Permit2Bundler.sol +++ b/src/Permit2Bundler.sol @@ -24,14 +24,14 @@ abstract contract Permit2Bundler is BaseBundler { external payable { - address _initiator = initiator(); - uint256 amount = Math.min(permit.permitted.amount, ERC20(permit.permitted.token).balanceOf(_initiator)); + address initiator = initiator(); + uint256 amount = Math.min(permit.permitted.amount, ERC20(permit.permitted.token).balanceOf(initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); ISignatureTransfer.SignatureTransferDetails memory transferDetails = ISignatureTransfer.SignatureTransferDetails({to: address(this), requestedAmount: amount}); - ISignatureTransfer(PERMIT2).permitTransferFrom(permit, transferDetails, _initiator, signature); + ISignatureTransfer(PERMIT2).permitTransferFrom(permit, transferDetails, initiator, signature); } } diff --git a/src/TransferBundler.sol b/src/TransferBundler.sol index 74d76816..4b3e5169 100644 --- a/src/TransferBundler.sol +++ b/src/TransferBundler.sol @@ -49,11 +49,11 @@ abstract contract TransferBundler is BaseBundler { /// @notice Warning: should only be called via the bundler's `multicall` function. /// @dev Pass `amount = type(uint256).max` to transfer all. function erc20TransferFrom(address asset, uint256 amount) external payable { - address _initiator = initiator(); - amount = Math.min(amount, ERC20(asset).balanceOf(_initiator)); + address initiator = initiator(); + amount = Math.min(amount, ERC20(asset).balanceOf(initiator)); require(amount != 0, ErrorsLib.ZERO_AMOUNT); - ERC20(asset).safeTransferFrom(_initiator, address(this), amount); + ERC20(asset).safeTransferFrom(initiator, address(this), amount); } }