From 2ca7b19ab53d8cd1d57a612fcf90e8c122a0faae Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 23 Feb 2023 11:34:03 -0500 Subject: [PATCH 01/34] add MorphoAave3 --- .../connectors/morpho-aave-v3/events.sol | 114 ++++ .../connectors/morpho-aave-v3/helpers.sol | 32 ++ .../connectors/morpho-aave-v3/interface.sol | 106 ++++ .../connectors/morpho-aave-v3/main.sol | 541 ++++++++++++++++++ 4 files changed, 793 insertions(+) create mode 100644 contracts/mainnet/connectors/morpho-aave-v3/events.sol create mode 100644 contracts/mainnet/connectors/morpho-aave-v3/helpers.sol create mode 100644 contracts/mainnet/connectors/morpho-aave-v3/interface.sol create mode 100644 contracts/mainnet/connectors/morpho-aave-v3/main.sol diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol new file mode 100644 index 00000000..543325be --- /dev/null +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -0,0 +1,114 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +contract Events { + event LogDeposit( + address tokenAddress, + uint256 amount, + uint256 maxIteration, + uint256 getId, + uint256 setId + ); + + event LogDepositWithMaxGas( + address tokenAddress, + address poolTokenAddress, + uint256 amount, + uint256 maxGasForMatching, + uint256 getId, + uint256 setId + ); + + event LogDepositOnBehalf( + address tokenAddress, + uint256 amount, + address onBehalf, + uint256 maxIteration, + uint256 getId, + uint256 setId + ); + + event LogDepositWithPermit( + address tokenAddress, + uint256 amount, + address onBehalf, + uint256 maxIteration, + uint256 time, + uint8 v, + bytes32 r, + bytes32 s, + uint256 getId, + uint256 setId + ); + + event LogDepositCollateral( + address tokenAddress, + uint256 amount, + uint256 getId, + uint256 setId + ); + + event LogDepositCollateralOnBehalf( + address tokenAddress, + uint256 amount, + address onBehalf, + uint256 getId, + uint256 setId + ); + + event LogDepositCollateralWithPermit( + address tokenAddress, + uint256 amount, + address onBehalf, + uint256 maxIteration, + uint256 time, + uint8 v, + bytes32 r, + bytes32 s, + uint256 getId, + uint256 setId + ); + + event LogBorrow( + address tokenAddress, + address poolTokenAddress, + uint256 amount, + uint256 getId, + uint256 setId + ); + + event LogBorrowWithMaxGas( + address tokenAddress, + address poolTokenAddress, + uint256 amount, + uint256 maxGasForMatching, + uint256 getId, + uint256 setId + ); + + event LogWithdraw( + address tokenAddress, + address poolTokenAddress, + uint256 amount, + uint256 getId, + uint256 setId + ); + + event LogPayback( + address tokenAddress, + address poolTokenAddress, + uint256 amount, + uint256 getId, + uint256 setId + ); + + event LogPaybackOnBehalf( + address tokenAddress, + address poolTokenAddress, + address onBehalf, + uint256 amount, + uint256 getId, + uint256 setId + ); +} diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol new file mode 100644 index 00000000..7c5d554b --- /dev/null +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -0,0 +1,32 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; +import "./interface.sol"; +import "../../common/stores.sol"; +import "../../common/basic.sol"; +import "../../common/interfaces.sol"; + +abstract contract Helpers is Stores, Basic { + IMorphoCore public constant MORPHO_AAVE_V3 = + IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); + + IMorphoAaveLens public constant MORPHO_AAVE_LENS = + IMorphoAaveLens(0x507fA343d0A90786d86C7cd885f5C49263A91FF4); + + function _performEthToWethConversion( + address _tokenAddress, + uint256 _amount, + uint256 _getId + ) internal returns (TokenInterface _tokenContract, uint256 _amt) { + _amt = getUint(_getId, _amount); + + if (_tokenAddress == ethAddr) { + _tokenContract = TokenInterface(wethAddr); + if (_amt == uint256(-1)) _amt = address(this).balance; + convertEthToWeth(true, _tokenContract, _amt); + } else { + _tokenContract = TokenInterface(_tokenAddress); + if (_amt == uint256(-1)) _amt = _tokenContract.balanceOf(address(this)); + } + } +} diff --git a/contracts/mainnet/connectors/morpho-aave-v3/interface.sol b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol new file mode 100644 index 00000000..4e35d487 --- /dev/null +++ b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol @@ -0,0 +1,106 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +interface IMorphoCore { + // function supply( + // address _poolTokenAddress, + // address _onBehalf, + // uint256 _amount + // ) external; + + // function supply( + // address _poolToken, + // address _onBehalf, + // uint256 _amount, + // uint256 _maxGasForMatching + // ) external; + + // function borrow(address _poolTokenAddress, uint256 _amount) external; + + // function borrow( + // address _poolToken, + // uint256 _amount, + // uint256 _maxGasForMatching + // ) external; + + // function withdraw(address _poolTokenAddress, uint256 _amount) external; + + // function repay( + // address _poolTokenAddress, + // address _onBehalf, + // uint256 _amount + // ) external; + struct Signature { + uint8 v; + bytes32 r; + bytes32 s; + } + + function supply(address underlying, uint256 amount, address onBehalf, uint256 maxIterations) + external + returns (uint256 supplied); + + function supplyWithPermit( + address underlying, + uint256 amount, + address onBehalf, + uint256 maxIterations, + uint256 deadline, + Signature calldata signature + ) external returns (uint256 supplied); + + function supplyCollateral(address underlying, uint256 amount, address onBehalf) + external + returns (uint256 supplied); + + function supplyCollateralWithPermit( + address underlying, + uint256 amount, + address onBehalf, + uint256 deadline, + Signature calldata signature + ) external returns (uint256 supplied); + + function borrow(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations) + external + returns (uint256 borrowed); + + function repay(address underlying, uint256 amount, address onBehalf) external returns (uint256 repaid); + + function repayWithPermit( + address underlying, + uint256 amount, + address onBehalf, + uint256 deadline, + Signature calldata signature + ) external returns (uint256 repaid); + + function withdraw(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations) + external + returns (uint256 withdrawn); + + function withdrawCollateral(address underlying, uint256 amount, address onBehalf, address receiver) + external + returns (uint256 withdrawn); +} + +interface IMorphoAaveLens { + function getCurrentBorrowBalanceInOf(address _poolToken, address _user) + external + view + returns ( + uint256 balanceInP2P, + uint256 balanceOnPool, + uint256 totalBalance + ); + + function getCurrentSupplyBalanceInOf(address _poolToken, address _user) + external + view + returns ( + uint256 balanceInP2P, + uint256 balanceOnPool, + uint256 totalBalance + ); +} diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol new file mode 100644 index 00000000..960125a9 --- /dev/null +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -0,0 +1,541 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; +import "./helpers.sol"; +import "./events.sol"; + +abstract contract MorphoAaveV3 is Helpers, Events { + /** + * @dev Deposit ETH/ERC20_Token. + * @notice Deposit a token to Morpho Aave for lending / collaterization. + * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + * @param _maxIterations The maximum number of iterations allowed during the matching process. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens deposited. + */ + function deposit( + address _tokenAddress, + uint256 _amount, + uint256 _maxIterations, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), _maxIterations); + + setUint(_setId, _amt); + + _eventName = "LogDeposit(address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _maxIterations, + _getId, + _setId + ); + } + + /** + * @dev Deposit ETH/ERC20_Token on behalf of a user. + * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. + * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + * @param _maxIterations The maximum number of iterations allowed during the matching process. + * @param _onBehalf The address of user on behalf to deposit. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens deposited. + */ + function depositOnBehalf( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + uint256 _maxIterations, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, _maxIterations); + + setUint(_setId, _amt); + + _eventName = "LogDepositOnBehalf(address,uint256,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _onBehalf, + _maxIterations, + _getId, + _setId + ); + } + + /** + * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. + * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + * @param _onBehalf The address of user on behalf to deposit. + * @param _maxIterations The maximum number of iterations allowed during the matching process. + * @param _signature The permit2 signature. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens deposited. + */ + function depositWithPermit( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + uint256 _maxIterations, + Signature calldata _signature, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.supplyWithPermit(_tokenContract, _amt, _onBehalf, _maxIterations, block.timestamp, _signature); + + setUint(_setId, _amt); + + _eventName = "LogDepositWithPermit(address,uint256,address,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _onBehalf, + _maxIterations, + block.timestamp, + _signature.v, + _signature.r, + _signature.s, + _getId, + _setId + ); + } + + /** + * @dev Deposit ETH/ERC20_Token on behalf of a user. + * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. + * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens deposited. + */ + function depositCollateral( + address _tokenAddress, + uint256 _amount, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.supplyCollateral(_tokenContract, _amt, address(this)); + + setUint(_setId, _amt); + + _eventName = "LogDepositCollateral(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _getId, + _setId + ); + } + + /** + * @dev Deposit ETH/ERC20_Token on behalf of a user. + * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. + * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + * @param _onBehalf The address of user on behalf to deposit. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens deposited. + */ + function depositCollateralOnBehalf( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.supplyCollateral(_tokenContract, _amt, _onBehalf); + + setUint(_setId, _amt); + + _eventName = "LogDepositCollateralOnBehalf(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _onBehalf, + _getId, + _setId + ); + } + + /** + * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. + * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + * @param _onBehalf The address of user on behalf to deposit. + * @param _signature The permit2 signature. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens deposited. + */ + function depositCollateralWithPermit( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + Signature calldata _signature, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.supplyCollateralWithPermit(_tokenContract, _amt, _onBehalf, block.timestamp, _signature); + + setUint(_setId, _amt); + + _eventName = "LogDepositCollateralWithPermit(address,uint256,address,uint256,uint8,bytes32,bytes32,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _onBehalf, + block.timestamp, + _signature.v, + _signature.r, + _signature.s, + _getId, + _setId + ); + } + + /** + * @dev Borrow ETH/ERC20_Token. + * @notice Borrow a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to borrow. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens borrowed. + */ + function borrow( + address _tokenAddress, + uint256 _amount, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + + MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt); + + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogBorrow(address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _poolTokenAddress, + _amt, + _getId, + _setId + ); + } + + /** + * @dev Borrow ETH/ERC20_Token. + * @notice Borrow a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to borrow. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens borrowed. + */ + function borrow( + address _tokenAddress, + uint256 _amount, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + + MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt); + + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogBorrow(address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _poolTokenAddress, + _amt, + _getId, + _setId + ); + } + + // /** + // * @dev Borrow ETH/ERC20_Token with max gas. + // * @notice Borrow a token from Morpho Aave with max gas. + // * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE). + // * @param _poolTokenAddress The address of aToken to borrow.(For ETH: aWETH address). + // * @param _amount The amount of the token (in underlying) to borrow. + // * @param _maxGasForMatching The maximum amount of gas to consume within a matching engine loop. + // * @param _getId ID to retrieve amt. + // * @param _setId ID stores the amount of tokens borrowed. + // */ + // function borrowWithMaxGas( + // address _tokenAddress, + // address _poolTokenAddress, + // uint256 _amount, + // uint256 _maxGasForMatching, + // uint256 _getId, + // uint256 _setId + // ) + // external + // payable + // returns (string memory _eventName, bytes memory _eventParam) + // { + // uint256 _amt = getUint(_getId, _amount); + + // MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt, _maxGasForMatching); + + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + // setUint(_setId, _amt); + + // _eventName = "LogBorrowWithMaxGas(address,address,uint256,uint256,uint256,uint256)"; + // _eventParam = abi.encode( + // _tokenAddress, + // _poolTokenAddress, + // _amt, + // _maxGasForMatching, + // _getId, + // _setId + // ); + // } + + /** + * @dev Withdraw ETH/ERC20_Token. + * @notice Withdraw a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _poolTokenAddress The address of aToken to withdraw.(For ETH: aWETH address) + * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens withdrawed. + */ + function withdraw( + address _tokenAddress, + address _poolTokenAddress, + uint256 _amount, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + if (_amt == uint256(-1)) + (, , _amt) = MORPHO_AAVE_LENS.getCurrentSupplyBalanceInOf( + _poolTokenAddress, + address(this) + ); + + MORPHO_AAVE_V3.withdraw(_poolTokenAddress, _amt); + + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogWithdraw(address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _poolTokenAddress, + _amt, + _getId, + _setId + ); + } + + /** + * @dev Payback ETH/ERC20_Token. + * @notice Payback a token to Morpho Aave. + * @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _poolTokenAddress The address of aToken to payback.(For ETH: aWETH address) + * @param _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`) + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens paid back. + */ + function payback( + address _tokenAddress, + address _poolTokenAddress, + uint256 _amount, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + bool _isETH = _tokenAddress == ethAddr; + uint256 _amt = getUint(_getId, _amount); + + TokenInterface _tokenContract = _isETH + ? TokenInterface(wethAddr) + : TokenInterface(_tokenAddress); + + if (_amt == uint256(-1)) { + uint256 _amtDSA = _isETH + ? address(this).balance + : _tokenContract.balanceOf(address(this)); + + (, , uint256 _amtDebt) = MORPHO_AAVE_LENS + .getCurrentBorrowBalanceInOf(_poolTokenAddress, address(this)); + + _amt = _amtDSA < _amtDebt ? _amtDSA : _amtDebt; + } + + convertEthToWeth(_isETH, _tokenContract, _amt); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.repay(_poolTokenAddress, address(this), _amt); + + setUint(_setId, _amt); + + _eventName = "LogPayback(address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _poolTokenAddress, + _amt, + _getId, + _setId + ); + } + + /** + * @dev Payback ETH/ERC20_Token. + * @notice Payback a token to Morpho Aave. + * @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _poolTokenAddress The address of aToken to payback.(For ETH: aWETH address) + * @param _onBehalf The address of user who's debt to repay. + * @param _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`) + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens paid back. + */ + function paybackOnBehalf( + address _tokenAddress, + address _poolTokenAddress, + address _onBehalf, + uint256 _amount, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + bool _isETH = _tokenAddress == ethAddr; + uint256 _amt = getUint(_getId, _amount); + + TokenInterface _tokenContract = _isETH + ? TokenInterface(wethAddr) + : TokenInterface(_tokenAddress); + + if (_amt == uint256(-1)) { + uint256 _amtDSA = _isETH + ? address(this).balance + : _tokenContract.balanceOf(address(this)); + + (, , uint256 _amtDebt) = MORPHO_AAVE_LENS + .getCurrentBorrowBalanceInOf(_poolTokenAddress, _onBehalf); + + _amt = _amtDSA < _amtDebt ? _amtDSA : _amtDebt; + } + + convertEthToWeth(_isETH, _tokenContract, _amt); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.repay(_poolTokenAddress, _onBehalf, _amt); + + setUint(_setId, _amt); + + _eventName = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _poolTokenAddress, + _onBehalf, + _amt, + _getId, + _setId + ); + } +} + +contract ConnectV3MorphoAaveV3 is MorphoAaveV3 { + string public constant name = "Morpho-AaveV3-v1.0"; +} From 7482153adbceecf61630cf34b1f42e98b43fa732 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 23 Feb 2023 20:21:01 -0500 Subject: [PATCH 02/34] add temp result --- .../connectors/morpho-aave-v3/events.sol | 32 +- .../connectors/morpho-aave-v3/helpers.sol | 2 + .../connectors/morpho-aave-v3/main.sol | 391 ++++++++++++------ 3 files changed, 302 insertions(+), 123 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol index 543325be..189d6889 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/events.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -4,6 +4,13 @@ pragma experimental ABIEncoderV2; contract Events { event LogDeposit( + address tokenAddress, + uint256 amount, + uint256 getId, + uint256 setId + ); + + event LogDepositWithMaxIterations( address tokenAddress, uint256 amount, uint256 maxIteration, @@ -11,16 +18,15 @@ contract Events { uint256 setId ); - event LogDepositWithMaxGas( + event LogDepositOnBehalf( address tokenAddress, - address poolTokenAddress, uint256 amount, - uint256 maxGasForMatching, + address onBehalf, uint256 getId, uint256 setId ); - event LogDepositOnBehalf( + event LogDepositOnBehalfWithMaxIterations( address tokenAddress, uint256 amount, address onBehalf, @@ -72,17 +78,27 @@ contract Events { event LogBorrow( address tokenAddress, - address poolTokenAddress, uint256 amount, + address receiver, uint256 getId, uint256 setId ); - event LogBorrowWithMaxGas( + event LogBorrowWithMaxIterations( address tokenAddress, - address poolTokenAddress, uint256 amount, - uint256 maxGasForMatching, + address receiver, + uint256 maxIteration, + uint256 getId, + uint256 setId + ); + + event LogBorrowOnBehalfWithMaxIterations( + address tokenAddress, + uint256 amount, + address receiver, + address onBehalf, + uint256 maxIteration, uint256 getId, uint256 setId ); diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index 7c5d554b..038c4ea6 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -9,6 +9,8 @@ import "../../common/interfaces.sol"; abstract contract Helpers is Stores, Basic { IMorphoCore public constant MORPHO_AAVE_V3 = IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); + + uint256 public constant MAX_ITERATION = 10; IMorphoAaveLens public constant MORPHO_AAVE_LENS = IMorphoAaveLens(0x507fA343d0A90786d86C7cd885f5C49263A91FF4); diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 960125a9..08acbc03 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -10,14 +10,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Deposit a token to Morpho Aave for lending / collaterization. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - * @param _maxIterations The maximum number of iterations allowed during the matching process. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens deposited. */ function deposit( address _tokenAddress, uint256 _amount, - uint256 _maxIterations, uint256 _getId, uint256 _setId ) @@ -32,15 +30,55 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), _maxIterations); + MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), MAX_ITERATION); setUint(_setId, _amt); - _eventName = "LogDeposit(address,uint256,uint256,uint256,uint256)"; + _eventName = "LogDeposit(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, - _maxIterations, + _getId, + _setId + ); + } + + /** + * @dev Deposit ETH/ERC20_Token. + * @notice Deposit a token to Morpho Aave for lending / collaterization. + * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + * @param _onBehalf The address of user on behalf to deposit. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens deposited. + */ + function depositWithMaxIterations( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION); + + setUint(_setId, _amt); + + _eventName = "LogDepositWithMaxIterations(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _onBehalf, _getId, _setId ); @@ -51,7 +89,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - * @param _maxIterations The maximum number of iterations allowed during the matching process. * @param _onBehalf The address of user on behalf to deposit. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens deposited. @@ -60,7 +97,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _tokenAddress, uint256 _amount, address _onBehalf, - uint256 _maxIterations, uint256 _getId, uint256 _setId ) @@ -75,37 +111,35 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, _maxIterations); + MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION); setUint(_setId, _amt); - _eventName = "LogDepositOnBehalf(address,uint256,address,uint256,uint256,uint256)"; + _eventName = "LogDepositOnBehalf(address,uint256,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, _onBehalf, - _maxIterations, _getId, _setId ); } /** - * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. + * @dev Deposit ETH/ERC20_Token on behalf of a user. + * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) * @param _onBehalf The address of user on behalf to deposit. - * @param _maxIterations The maximum number of iterations allowed during the matching process. - * @param _signature The permit2 signature. + * @param _onBehalf The address of user on behalf to deposit. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens deposited. */ - function depositWithPermit( + function depositOnBehalfWithMaxIterations ( address _tokenAddress, uint256 _amount, address _onBehalf, - uint256 _maxIterations, - Signature calldata _signature, + uint256 _maxIteration, uint256 _getId, uint256 _setId ) @@ -120,25 +154,70 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supplyWithPermit(_tokenContract, _amt, _onBehalf, _maxIterations, block.timestamp, _signature); + MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, _maxIteration); setUint(_setId, _amt); - _eventName = "LogDepositWithPermit(address,uint256,address,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)"; + _eventName = "LogDepositOnBehalfWithMaxIterations(address,uint256,address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, _onBehalf, - _maxIterations, - block.timestamp, - _signature.v, - _signature.r, - _signature.s, + _maxIteration, _getId, _setId ); } + // /** + // * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. + // * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + // * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + // * @param _onBehalf The address of user on behalf to deposit. + // * @param _maxIterations The maximum number of iterations allowed during the matching process. + // * @param _signature The permit2 signature. + // * @param _getId ID to retrieve amt. + // * @param _setId ID stores the amount of tokens deposited. + // */ + // function depositWithPermit( + // address _tokenAddress, + // uint256 _amount, + // address _onBehalf, + // uint256 _maxIterations, + // Signature calldata _signature, + // uint256 _getId, + // uint256 _setId + // ) + // external + // payable + // returns (string memory _eventName, bytes memory _eventParam) + // { + // ( + // TokenInterface _tokenContract, + // uint256 _amt + // ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + // approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + // MORPHO_AAVE_V3.supplyWithPermit(_tokenContract, _amt, _onBehalf, _maxIterations, block.timestamp, _signature); + + // setUint(_setId, _amt); + + // _eventName = "LogDepositWithPermit(address,uint256,address,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)"; + // _eventParam = abi.encode( + // _tokenAddress, + // _amt, + // _onBehalf, + // _maxIterations, + // block.timestamp, + // _signature.v, + // _signature.r, + // _signature.s, + // _getId, + // _setId + // ); + // } + /** * @dev Deposit ETH/ERC20_Token on behalf of a user. * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. @@ -168,7 +247,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { setUint(_setId, _amt); - _eventName = "LogDepositCollateral(address,uint256,address,uint256,uint256)"; + _eventName = "LogDepositCollateral(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, @@ -218,63 +297,180 @@ abstract contract MorphoAaveV3 is Helpers, Events { ); } + // /** + // * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. + // * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + // * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) + // * @param _onBehalf The address of user on behalf to deposit. + // * @param _signature The permit2 signature. + // * @param _getId ID to retrieve amt. + // * @param _setId ID stores the amount of tokens deposited. + // */ + // function depositCollateralWithPermit( + // address _tokenAddress, + // uint256 _amount, + // address _onBehalf, + // Signature calldata _signature, + // uint256 _getId, + // uint256 _setId + // ) + // external + // payable + // returns (string memory _eventName, bytes memory _eventParam) + // { + // ( + // TokenInterface _tokenContract, + // uint256 _amt + // ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); + + // approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); + + // MORPHO_AAVE_V3.supplyCollateralWithPermit(_tokenContract, _amt, _onBehalf, block.timestamp, _signature); + + // setUint(_setId, _amt); + + // _eventName = "LogDepositCollateralWithPermit(address,uint256,address,uint256,uint8,bytes32,bytes32,uint256,uint256)"; + // _eventParam = abi.encode( + // _tokenAddress, + // _amt, + // _onBehalf, + // block.timestamp, + // _signature.v, + // _signature.r, + // _signature.s, + // _getId, + // _setId + // ); + // } + /** - * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. - * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - * @param _onBehalf The address of user on behalf to deposit. - * @param _signature The permit2 signature. + * @dev Borrow ETH/ERC20_Token. + * @notice Borrow a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to borrow. * @param _getId ID to retrieve amt. - * @param _setId ID stores the amount of tokens deposited. + * @param _setId ID stores the amount of tokens borrowed. */ - function depositCollateralWithPermit( + function borrow( + address _tokenAddress, + uint256 _amount, + address _receiver, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + + MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION); + + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogBorrow(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _receiver, + _getId, + _setId + ); + } + + /** + * @dev Borrow ETH/ERC20_Token. + * @notice Borrow a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to borrow. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens borrowed. + */ + function borrowOnBehalf( + address _tokenAddress, + uint256 _amount, + address _receiver, + address _onBehalf, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + + MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION); + + convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt); + + setUint(_setId, _amt); + + _eventName = "LogBorrowOnBehalf(address,uint256,addresss,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _receiver, + _getId, + _setId + ); + } + + /** + * @dev Borrow ETH/ERC20_Token. + * @notice Borrow a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to borrow. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens borrowed. + */ + function borrowWithMaxIterations( + address _tokenAddress, + uint256 _amount, + address _receiver, + uint256 _maxIteration, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + + MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, _maxIteration); + + convertWethToEth(_tokenAddress == ethAddr, address(this), _amt); + + setUint(_setId, _amt); + + _eventName = "LogBorrowWithMaxIterations(address,uint256,addresss,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _receiver, + _maxIteration, + _getId, + _setId + ); + } + + /** + * @dev Borrow ETH/ERC20_Token. + * @notice Borrow a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to borrow. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens borrowed. + */ + function borrowOnBehalfWithMaxIterations ( address _tokenAddress, uint256 _amount, address _onBehalf, - Signature calldata _signature, - uint256 _getId, - uint256 _setId - ) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - ( - TokenInterface _tokenContract, - uint256 _amt - ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); - - approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - - MORPHO_AAVE_V3.supplyCollateralWithPermit(_tokenContract, _amt, _onBehalf, block.timestamp, _signature); - - setUint(_setId, _amt); - - _eventName = "LogDepositCollateralWithPermit(address,uint256,address,uint256,uint8,bytes32,bytes32,uint256,uint256)"; - _eventParam = abi.encode( - _tokenAddress, - _amt, - _onBehalf, - block.timestamp, - _signature.v, - _signature.r, - _signature.s, - _getId, - _setId - ); - } - - /** - * @dev Borrow ETH/ERC20_Token. - * @notice Borrow a token from Morpho Aave. - * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param _amount The amount of the token (in underlying) to borrow. - * @param _getId ID to retrieve amt. - * @param _setId ID stores the amount of tokens borrowed. - */ - function borrow( - address _tokenAddress, - uint256 _amount, + address _receiver, + uint256 _maxIteration, uint256 _getId, uint256 _setId ) @@ -284,53 +480,18 @@ abstract contract MorphoAaveV3 is Helpers, Events { { uint256 _amt = getUint(_getId, _amount); - MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt); + MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, _maxIteration); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt); setUint(_setId, _amt); - _eventName = "LogBorrow(address,address,uint256,uint256,uint256)"; + _eventName = "LogBorrowOnBehalfWithMaxIterations(address,uint256,addresss,address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _poolTokenAddress, - _amt, - _getId, - _setId - ); - } - - /** - * @dev Borrow ETH/ERC20_Token. - * @notice Borrow a token from Morpho Aave. - * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param _amount The amount of the token (in underlying) to borrow. - * @param _getId ID to retrieve amt. - * @param _setId ID stores the amount of tokens borrowed. - */ - function borrow( - address _tokenAddress, - uint256 _amount, - uint256 _getId, - uint256 _setId - ) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - uint256 _amt = getUint(_getId, _amount); - - MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt); - - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - - setUint(_setId, _amt); - - _eventName = "LogBorrow(address,address,uint256,uint256,uint256)"; - _eventParam = abi.encode( - _tokenAddress, - _poolTokenAddress, _amt, + _receiver, + _maxIteration, _getId, _setId ); From 0624c0a4ca258c6b25d39cbf5d21d908438cd1a3 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 23 Feb 2023 22:19:23 -0500 Subject: [PATCH 03/34] update connector --- .../connectors/morpho-aave-v3/events.sol | 68 ++-- .../connectors/morpho-aave-v3/helpers.sol | 9 +- .../connectors/morpho-aave-v3/interface.sol | 48 --- .../connectors/morpho-aave-v3/main.sol | 343 ++++++++---------- 4 files changed, 210 insertions(+), 258 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol index 189d6889..295bc51c 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/events.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -35,19 +35,6 @@ contract Events { uint256 setId ); - event LogDepositWithPermit( - address tokenAddress, - uint256 amount, - address onBehalf, - uint256 maxIteration, - uint256 time, - uint8 v, - bytes32 r, - bytes32 s, - uint256 getId, - uint256 setId - ); - event LogDepositCollateral( address tokenAddress, uint256 amount, @@ -63,22 +50,18 @@ contract Events { uint256 setId ); - event LogDepositCollateralWithPermit( + event LogBorrow( address tokenAddress, uint256 amount, - address onBehalf, - uint256 maxIteration, - uint256 time, - uint8 v, - bytes32 r, - bytes32 s, + address receiver, uint256 getId, uint256 setId ); - event LogBorrow( + event LogBorrowOnBehalf( address tokenAddress, uint256 amount, + address onBehalf, address receiver, uint256 getId, uint256 setId @@ -96,8 +79,8 @@ contract Events { event LogBorrowOnBehalfWithMaxIterations( address tokenAddress, uint256 amount, - address receiver, address onBehalf, + address receiver, uint256 maxIteration, uint256 getId, uint256 setId @@ -105,15 +88,49 @@ contract Events { event LogWithdraw( address tokenAddress, - address poolTokenAddress, uint256 amount, + address receiver, + uint256 getId, + uint256 setId + ); + + event LogWithdrawOnBehalf( + address tokenAddress, + uint256 amount, + address onBehalf, + address receiver, + uint256 getId, + uint256 setId + ); + + event LogWithdrawWithMaxIterations( + address tokenAddress, + uint256 amount, + address receiver, + uint256 maxIteration, + uint256 getId, + uint256 setId + ); + + event LogWithdrawCollateral( + address tokenAddress, + uint256 amount, + address receiver, + uint256 getId, + uint256 setId + ); + + event LogWithdrawCollateralOnBehalf( + address tokenAddress, + uint256 amount, + address onBehalf, + address receiver, uint256 getId, uint256 setId ); event LogPayback( address tokenAddress, - address poolTokenAddress, uint256 amount, uint256 getId, uint256 setId @@ -121,9 +138,8 @@ contract Events { event LogPaybackOnBehalf( address tokenAddress, - address poolTokenAddress, - address onBehalf, uint256 amount, + address onBehalf, uint256 getId, uint256 setId ); diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index 038c4ea6..d8041c01 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -5,12 +5,13 @@ import "./interface.sol"; import "../../common/stores.sol"; import "../../common/basic.sol"; import "../../common/interfaces.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; -abstract contract Helpers is Stores, Basic { +abstract contract Helpers is Stores, Basic, Ownable { IMorphoCore public constant MORPHO_AAVE_V3 = IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); - uint256 public constant MAX_ITERATION = 10; + uint256 public max_iteration = 10; IMorphoAaveLens public constant MORPHO_AAVE_LENS = IMorphoAaveLens(0x507fA343d0A90786d86C7cd885f5C49263A91FF4); @@ -31,4 +32,8 @@ abstract contract Helpers is Stores, Basic { if (_amt == uint256(-1)) _amt = _tokenContract.balanceOf(address(this)); } } + + function setMaxIteration(uint256 _iter) external onlyOwner { + max_iteration = _iter; + } } diff --git a/contracts/mainnet/connectors/morpho-aave-v3/interface.sol b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol index 4e35d487..27e34422 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/interface.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol @@ -3,34 +3,6 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; interface IMorphoCore { - // function supply( - // address _poolTokenAddress, - // address _onBehalf, - // uint256 _amount - // ) external; - - // function supply( - // address _poolToken, - // address _onBehalf, - // uint256 _amount, - // uint256 _maxGasForMatching - // ) external; - - // function borrow(address _poolTokenAddress, uint256 _amount) external; - - // function borrow( - // address _poolToken, - // uint256 _amount, - // uint256 _maxGasForMatching - // ) external; - - // function withdraw(address _poolTokenAddress, uint256 _amount) external; - - // function repay( - // address _poolTokenAddress, - // address _onBehalf, - // uint256 _amount - // ) external; struct Signature { uint8 v; bytes32 r; @@ -84,23 +56,3 @@ interface IMorphoCore { external returns (uint256 withdrawn); } - -interface IMorphoAaveLens { - function getCurrentBorrowBalanceInOf(address _poolToken, address _user) - external - view - returns ( - uint256 balanceInP2P, - uint256 balanceOnPool, - uint256 totalBalance - ); - - function getCurrentSupplyBalanceInOf(address _poolToken, address _user) - external - view - returns ( - uint256 balanceInP2P, - uint256 balanceOnPool, - uint256 totalBalance - ); -} diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 08acbc03..c7ad517a 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -30,7 +30,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), MAX_ITERATION); + MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), max_iteration); setUint(_setId, _amt); @@ -48,14 +48,14 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Deposit a token to Morpho Aave for lending / collaterization. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - * @param _onBehalf The address of user on behalf to deposit. + * @param _maxIteration The maximum number of iterations allowed during the matching process. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens deposited. */ function depositWithMaxIterations( address _tokenAddress, uint256 _amount, - address _onBehalf, + address _maxIteration, uint256 _getId, uint256 _setId ) @@ -70,15 +70,15 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION); + MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), _maxIteration); setUint(_setId, _amt); - _eventName = "LogDepositWithMaxIterations(address,uint256,address,uint256,uint256)"; + _eventName = "LogDepositWithMaxIterations(address,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, - _onBehalf, + _maxIteration, _getId, _setId ); @@ -111,7 +111,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION); + MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, max_iteration); setUint(_setId, _amt); @@ -131,7 +131,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) * @param _onBehalf The address of user on behalf to deposit. - * @param _onBehalf The address of user on behalf to deposit. + * @param _maxIteration The maximum number of iterations allowed during the matching process. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens deposited. */ @@ -169,55 +169,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { ); } - // /** - // * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. - // * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - // * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - // * @param _onBehalf The address of user on behalf to deposit. - // * @param _maxIterations The maximum number of iterations allowed during the matching process. - // * @param _signature The permit2 signature. - // * @param _getId ID to retrieve amt. - // * @param _setId ID stores the amount of tokens deposited. - // */ - // function depositWithPermit( - // address _tokenAddress, - // uint256 _amount, - // address _onBehalf, - // uint256 _maxIterations, - // Signature calldata _signature, - // uint256 _getId, - // uint256 _setId - // ) - // external - // payable - // returns (string memory _eventName, bytes memory _eventParam) - // { - // ( - // TokenInterface _tokenContract, - // uint256 _amt - // ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); - - // approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - - // MORPHO_AAVE_V3.supplyWithPermit(_tokenContract, _amt, _onBehalf, _maxIterations, block.timestamp, _signature); - - // setUint(_setId, _amt); - - // _eventName = "LogDepositWithPermit(address,uint256,address,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)"; - // _eventParam = abi.encode( - // _tokenAddress, - // _amt, - // _onBehalf, - // _maxIterations, - // block.timestamp, - // _signature.v, - // _signature.r, - // _signature.s, - // _getId, - // _setId - // ); - // } - /** * @dev Deposit ETH/ERC20_Token on behalf of a user. * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. @@ -297,52 +248,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { ); } - // /** - // * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx. - // * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - // * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - // * @param _onBehalf The address of user on behalf to deposit. - // * @param _signature The permit2 signature. - // * @param _getId ID to retrieve amt. - // * @param _setId ID stores the amount of tokens deposited. - // */ - // function depositCollateralWithPermit( - // address _tokenAddress, - // uint256 _amount, - // address _onBehalf, - // Signature calldata _signature, - // uint256 _getId, - // uint256 _setId - // ) - // external - // payable - // returns (string memory _eventName, bytes memory _eventParam) - // { - // ( - // TokenInterface _tokenContract, - // uint256 _amt - // ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); - - // approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - - // MORPHO_AAVE_V3.supplyCollateralWithPermit(_tokenContract, _amt, _onBehalf, block.timestamp, _signature); - - // setUint(_setId, _amt); - - // _eventName = "LogDepositCollateralWithPermit(address,uint256,address,uint256,uint8,bytes32,bytes32,uint256,uint256)"; - // _eventParam = abi.encode( - // _tokenAddress, - // _amt, - // _onBehalf, - // block.timestamp, - // _signature.v, - // _signature.r, - // _signature.s, - // _getId, - // _setId - // ); - // } - /** * @dev Borrow ETH/ERC20_Token. * @notice Borrow a token from Morpho Aave. @@ -364,7 +269,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { { uint256 _amt = getUint(_getId, _amount); - MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION); + MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, max_iteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); @@ -391,8 +296,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { function borrowOnBehalf( address _tokenAddress, uint256 _amount, - address _receiver, address _onBehalf, + address _receiver, uint256 _getId, uint256 _setId ) @@ -402,16 +307,17 @@ abstract contract MorphoAaveV3 is Helpers, Events { { uint256 _amt = getUint(_getId, _amount); - MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION); + MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, max_iteration); convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt); setUint(_setId, _amt); - _eventName = "LogBorrowOnBehalf(address,uint256,addresss,uint256,uint256)"; + _eventName = "LogBorrowOnBehalf(address,uint256,addresss,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, + _onBehalf, _receiver, _getId, _setId @@ -490,6 +396,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { _eventParam = abi.encode( _tokenAddress, _amt, + _onBehalf, _receiver, _maxIteration, _getId, @@ -497,60 +404,18 @@ abstract contract MorphoAaveV3 is Helpers, Events { ); } - // /** - // * @dev Borrow ETH/ERC20_Token with max gas. - // * @notice Borrow a token from Morpho Aave with max gas. - // * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE). - // * @param _poolTokenAddress The address of aToken to borrow.(For ETH: aWETH address). - // * @param _amount The amount of the token (in underlying) to borrow. - // * @param _maxGasForMatching The maximum amount of gas to consume within a matching engine loop. - // * @param _getId ID to retrieve amt. - // * @param _setId ID stores the amount of tokens borrowed. - // */ - // function borrowWithMaxGas( - // address _tokenAddress, - // address _poolTokenAddress, - // uint256 _amount, - // uint256 _maxGasForMatching, - // uint256 _getId, - // uint256 _setId - // ) - // external - // payable - // returns (string memory _eventName, bytes memory _eventParam) - // { - // uint256 _amt = getUint(_getId, _amount); - - // MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt, _maxGasForMatching); - - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - - // setUint(_setId, _amt); - - // _eventName = "LogBorrowWithMaxGas(address,address,uint256,uint256,uint256,uint256)"; - // _eventParam = abi.encode( - // _tokenAddress, - // _poolTokenAddress, - // _amt, - // _maxGasForMatching, - // _getId, - // _setId - // ); - // } - /** * @dev Withdraw ETH/ERC20_Token. * @notice Withdraw a token from Morpho Aave. * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param _poolTokenAddress The address of aToken to withdraw.(For ETH: aWETH address) * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. */ function withdraw( address _tokenAddress, - address _poolTokenAddress, uint256 _amount, + address _receiver, uint256 _getId, uint256 _setId ) @@ -559,23 +424,153 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - if (_amt == uint256(-1)) - (, , _amt) = MORPHO_AAVE_LENS.getCurrentSupplyBalanceInOf( - _poolTokenAddress, - address(this) - ); - - MORPHO_AAVE_V3.withdraw(_poolTokenAddress, _amt); + MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, address(this), _receiver, max_iteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); - _eventName = "LogWithdraw(address,address,uint256,uint256,uint256)"; + _eventName = "LogWithdraw(address,uint256,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _poolTokenAddress, _amt, + _receiver, + _getId, + _setId + ); + } + + /** + * @dev Withdraw ETH/ERC20_Token. + * @notice Withdraw a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens withdrawed. + */ + function withdrawOnBehalf( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + address _receiver, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, _onBehalf, _receiver, max_iteration); + + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogWithdrawOnBehalf(address,uint256,address,address,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _onBehalf, + _receiver, + _getId, + _setId + ); + } + + /** + * @dev Withdraw ETH/ERC20_Token. + * @notice Withdraw a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens withdrawed. + */ + function withdrawWithMaxIterations( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + address _receiver, + uint256 _maxIteration, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + + MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, _onBehalf, _receiver, _maxIteration); + + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogWithdrawWithMaxIterations(address,uint256,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _receiver, + _maxIteration, + _getId, + _setId + ); + } + + function withdrawCollateral( + address _tokenAddress, + uint256 _amount, + address _receiver, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + + MORPHO_AAVE_V3.withdrawCollateral(_tokenAddress, _amt, address(this), _receiver); + + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogWithdrawCollateral(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _receiver, + _getId, + _setId + ); + } + + function withdrawCollateralOnBehalf( + address _tokenAddress, + uint256 _amount, + address _onBehalf, + address _receiver, + uint256 _getId, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(_getId, _amount); + MORPHO_AAVE_V3.withdrawCollateral(_tokenAddress, _amt, _onBehalf, _receiver); + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + + setUint(_setId, _amt); + + _eventName = "LogWithdrawCollateralOnBehalf(address,uint256,address,address,uint256,uint256)"; + _eventParam = abi.encode( + _tokenAddress, + _amt, + _onBehalf, + _receiver, _getId, _setId ); @@ -585,14 +580,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @dev Payback ETH/ERC20_Token. * @notice Payback a token to Morpho Aave. * @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param _poolTokenAddress The address of aToken to payback.(For ETH: aWETH address) * @param _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`) * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens paid back. */ function payback( address _tokenAddress, - address _poolTokenAddress, uint256 _amount, uint256 _getId, uint256 _setId @@ -609,28 +602,22 @@ abstract contract MorphoAaveV3 is Helpers, Events { : TokenInterface(_tokenAddress); if (_amt == uint256(-1)) { - uint256 _amtDSA = _isETH + _amt = _isETH ? address(this).balance : _tokenContract.balanceOf(address(this)); - - (, , uint256 _amtDebt) = MORPHO_AAVE_LENS - .getCurrentBorrowBalanceInOf(_poolTokenAddress, address(this)); - - _amt = _amtDSA < _amtDebt ? _amtDSA : _amtDebt; } convertEthToWeth(_isETH, _tokenContract, _amt); approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.repay(_poolTokenAddress, address(this), _amt); + MORPHO_AAVE_V3.repay(_tokenAddress, _amt, address(this)); setUint(_setId, _amt); - _eventName = "LogPayback(address,address,uint256,uint256,uint256)"; + _eventName = "LogPayback(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _poolTokenAddress, _amt, _getId, _setId @@ -641,7 +628,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @dev Payback ETH/ERC20_Token. * @notice Payback a token to Morpho Aave. * @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param _poolTokenAddress The address of aToken to payback.(For ETH: aWETH address) * @param _onBehalf The address of user who's debt to repay. * @param _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`) * @param _getId ID to retrieve amt. @@ -649,7 +635,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { */ function paybackOnBehalf( address _tokenAddress, - address _poolTokenAddress, address _onBehalf, uint256 _amount, uint256 _getId, @@ -667,30 +652,24 @@ abstract contract MorphoAaveV3 is Helpers, Events { : TokenInterface(_tokenAddress); if (_amt == uint256(-1)) { - uint256 _amtDSA = _isETH + _amt = _isETH ? address(this).balance : _tokenContract.balanceOf(address(this)); - - (, , uint256 _amtDebt) = MORPHO_AAVE_LENS - .getCurrentBorrowBalanceInOf(_poolTokenAddress, _onBehalf); - - _amt = _amtDSA < _amtDebt ? _amtDSA : _amtDebt; } convertEthToWeth(_isETH, _tokenContract, _amt); approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.repay(_poolTokenAddress, _onBehalf, _amt); + MORPHO_AAVE_V3.repay(_tokenAddress, _amt, _onBehalf); setUint(_setId, _amt); - _eventName = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)"; + _eventName = "LogPaybackOnBehalf(address,uint256,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _poolTokenAddress, - _onBehalf, _amt, + _onBehalf, _getId, _setId ); From a1452d5f460db84557688753dbbeb251a6a605e1 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 23 Feb 2023 23:18:52 -0500 Subject: [PATCH 04/34] update minor and fix bug --- .../connectors/morpho-aave-v3/helpers.sol | 3 --- .../connectors/morpho-aave-v3/main.sol | 20 +++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index d8041c01..6aa792a5 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -13,9 +13,6 @@ abstract contract Helpers is Stores, Basic, Ownable { uint256 public max_iteration = 10; - IMorphoAaveLens public constant MORPHO_AAVE_LENS = - IMorphoAaveLens(0x507fA343d0A90786d86C7cd885f5C49263A91FF4); - function _performEthToWethConversion( address _tokenAddress, uint256 _amount, diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index c7ad517a..19716040 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -30,7 +30,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), max_iteration); + MORPHO_AAVE_V3.supply(address(_tokenContract), _amt, address(this), max_iteration); setUint(_setId, _amt); @@ -55,7 +55,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { function depositWithMaxIterations( address _tokenAddress, uint256 _amount, - address _maxIteration, + uint256 _maxIteration, uint256 _getId, uint256 _setId ) @@ -70,7 +70,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), _maxIteration); + MORPHO_AAVE_V3.supply(address(_tokenContract), _amt, address(this), _maxIteration); setUint(_setId, _amt); @@ -111,7 +111,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, max_iteration); + MORPHO_AAVE_V3.supply(address(_tokenContract), _amt, _onBehalf, max_iteration); setUint(_setId, _amt); @@ -154,7 +154,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, _maxIteration); + MORPHO_AAVE_V3.supply(address(_tokenContract), _amt, _onBehalf, _maxIteration); setUint(_setId, _amt); @@ -194,7 +194,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supplyCollateral(_tokenContract, _amt, address(this)); + MORPHO_AAVE_V3.supplyCollateral(address(_tokenContract), _amt, address(this)); setUint(_setId, _amt); @@ -234,7 +234,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.supplyCollateral(_tokenContract, _amt, _onBehalf); + MORPHO_AAVE_V3.supplyCollateral(address(_tokenContract), _amt, _onBehalf); setUint(_setId, _amt); @@ -309,7 +309,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, max_iteration); - convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt); + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -348,7 +348,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, _maxIteration); - convertWethToEth(_tokenAddress == ethAddr, address(this), _amt); + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -388,7 +388,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, _maxIteration); - convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt); + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); From c89f153822907a15e9c29159119090ab1efa1794 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Mon, 27 Feb 2023 03:45:06 -0500 Subject: [PATCH 05/34] add morpho aave v3 --- test/mainnet/morpho/morpho-aave-v3.test.ts | 505 +++++++++++++++++++++ 1 file changed, 505 insertions(+) create mode 100644 test/mainnet/morpho/morpho-aave-v3.test.ts diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts new file mode 100644 index 00000000..7ee1edbf --- /dev/null +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -0,0 +1,505 @@ +import { expect } from "chai"; +import hre from "hardhat"; +import { abis } from "../../../scripts/constant/abis"; +import { addresses } from "../../../scripts/tests/mainnet/addresses"; +import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; +import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; +import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; +import { ConnectV3MorphoAaveV3__factory, IERC20Minimal__factory } from "../../../typechain"; +import { parseEther, parseUnits } from "@ethersproject/units"; +import { encodeSpells } from "../../../scripts/tests/encodeSpells"; +import { dsaMaxValue, tokens } from "../../../scripts/tests/mainnet/tokens"; +const { ethers } = hre; +import type { Signer, Contract } from "ethers"; + +const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' +const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0' +const Usdc = parseUnits('500', 6) + +const DAI = '0x6b175474e89094c44da98b954eedeac495271d0f' +const ACC_DAI = '0xcd6Eb888e76450eF584E8B51bB73c76ffBa21FF2' +const Dai = parseUnits('1', 18) + +const user = "0x41bc7d0687e6cea57fa26da78379dfdc5627c56d" + +const token_usdc = new ethers.Contract( + USDC, + IERC20Minimal__factory.abi, + ethers.provider, +) + +const token_dai = new ethers.Contract( + DAI, + IERC20Minimal__factory.abi, + ethers.provider, +) + +describe("Morpho-Aave-v3", function () { + const connectorName = "MORPHO-AAVE-V3-TEST-A"; + let connector: any; + + let wallet0: Signer, wallet1:Signer; + let dsaWallet0: any; + let instaConnectorsV2: Contract; + let masterSigner: Signer; + + before(async () => { + await hre.network.provider.request({ + method: "hardhat_reset", + params: [ + { + forking: { + // @ts-ignore + jsonRpcUrl: hre.config.networks.hardhat.forking.url, + blockNumber: 15714501, + }, + }, + ], + }); + [wallet0, wallet1] = await ethers.getSigners(); + masterSigner = await getMasterSigner(); + instaConnectorsV2 = await ethers.getContractAt( + abis.core.connectorsV2, + addresses.core.connectorsV2 + ); + connector = await deployAndEnableConnector({ + connectorName, + contractArtifact: ConnectV3MorphoAaveV3__factory, + signer: masterSigner, + connectors: instaConnectorsV2, + }); + console.log("Connector address", connector.address); + }); + + it("should have contracts deployed", async () => { + expect(!!instaConnectorsV2.address).to.be.true; + expect(!!connector.address).to.be.true; + expect(!!(await masterSigner.getAddress())).to.be.true; + }); + + describe("DSA wallet setup", function () { + it("Should build DSA v2", async function () { + dsaWallet0 = await buildDSAv2(wallet0.getAddress()); + expect(!!dsaWallet0.address).to.be.true; + }); + + it("Deposit 1000 ETH into DSA wallet", async function () { + await wallet0.sendTransaction({ + to: dsaWallet0.address, + value: parseEther("1000"), + }); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + parseEther("1000") + ); + }); + + it("Deposit 500 USDC into DSA wallet", async function () { + + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [ACC_USDC], + }) + + const signer_usdc = await ethers.getSigner(ACC_USDC) + await token_usdc.connect(signer_usdc).transfer(wallet0.getAddress(), Usdc) + + await hre.network.provider.request({ + method: 'hardhat_stopImpersonatingAccount', + params: [ACC_USDC], + }) + + await token_usdc.connect(wallet0).transfer(dsaWallet0.address, Usdc); + + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('500', 6) + ); + }); + + it("Deposit 1 DAI into DSA wallet", async function () { + + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [ACC_DAI], + }) + + const signer_dai = await ethers.getSigner(ACC_DAI) + await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) + + await hre.network.provider.request({ + method: 'hardhat_stopImpersonatingAccount', + params: [ACC_DAI], + }) + + await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); + + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('1', 18) + ); + }); + }); + + describe("Main", function () { + + it("Should deposit 10 ETH", async function () { + const spells = [ + { + connector: connectorName, + method: "deposit", + args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('990', 18)) + ); + }) + + it("Should deposit 10 USDC", async function () { + const spells = [ + { + connector: connectorName, + method: "deposit", + args: [tokens.usdc.address, "10000000", "0", "0"], // 10 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('490', 6) + ); + }) + + it("Should deposit 100 USDC with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "depositWithMaxIterations", + args: [tokens.usdc.address, "100000000", 5, "0", "0"], // 100 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('390', 6) + ); + }) + + it("Should deposit 100 USDC on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "depositOnBehalf", + args: [tokens.usdc.address, "100000000", user, "0", "0"], // 100 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('290', 6) + ); + }) + + it("Should deposit 100 USDC on behalf with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "depositOnBehalfWithMaxIterations", + args: [tokens.usdc.address, "100000000", user, 5, "0", "0"], // 100 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('190', 6) + ); + }) + + it("Should deposit 100 USDC as collateral", async function () { + const spells = [ + { + connector: connectorName, + method: "depositCollateral", + args: [tokens.usdc.address, "50000000", "0", "0"], // 50 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('140', 6) + ); + }) + + it("Should deposit 100 USDC as collateral on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "depositCollateralOnBehalf", + args: [tokens.usdc.address, "50000000", user, "0", "0"], // 50 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('90', 6) + ); + }) + + it("Should borrow DAI into DSA", async function () { + const spells = [ + { + connector: connectorName, + method: "borrow", + args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, "0", "0"], // 10 DAI + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + .to.be.gte(parseUnits('11', 18)); + }) + + it("Should borrow DAI into DSA on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "borrowOnBehalf", + args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, "0", "0"], // 10 DAI + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + .to.be.gte(parseUnits('21', 18)); + }) + + it("Should borrow DAI into DSA with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "borrowWithMaxIterations", + args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, 5, "0", "0"], // 10 DAI + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + .to.be.gte(parseUnits('31', 18)); + }) + + it("Should borrow DAI into DSA on behalf with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "borrowOnBehalfWithMaxIterations", + args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, 5, "0", "0"], // 10 DAI + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + .to.be.gte(parseUnits('41', 18)); + }) + + it("Should payback DAI MAX", async function () { + const spells = [ + { + connector: connectorName, + method: "payback", + args: [tokens.dai.address, dsaMaxValue, "0", "0"], // Max DAI + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('1', 18) + ); + }) + + it("Should payback ETH on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "paybackOnBehalf", + args: [tokens.eth.address, user, dsaMaxValue, "0", "0"], // Max ETH + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('125', 18) + ); + }) + + it("Should withdraw ETH max", async function () { + const spells = [ + { + connector: connectorName, + method: "withdraw", + args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, "0", "0"], // Max ETH + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + parseUnits('134', 18)) + ); + }) + + it("Should withdraw 8 USDC on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawOnBehalf", + args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) + + it("Should withdraw 8 USDC on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawOnBehalf", + args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) + + it("Should withdraw 8 USDC on behalf with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawWithMaxIterations", + args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) + + it("Should withdraw 8 USDC as collateral", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawCollateral", + args: [tokens.usdc.address, "8000000", dsaWallet0.address, 5, "0", "0"], // 8 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) + + it("Should withdraw 8 USDC as collateral on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawCollateralOnBehalf", + args: [tokens.usdc.address, "8000000",user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) + }); +}); From b713ac9d81160184285ebcf12c93892d9116bc32 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Tue, 28 Feb 2023 18:46:35 -0500 Subject: [PATCH 06/34] update interface --- .../connectors/morpho-aave-v3/interface.sol | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/interface.sol b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol index 27e34422..9535f033 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/interface.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol @@ -3,36 +3,14 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; interface IMorphoCore { - struct Signature { - uint8 v; - bytes32 r; - bytes32 s; - } function supply(address underlying, uint256 amount, address onBehalf, uint256 maxIterations) external returns (uint256 supplied); - function supplyWithPermit( - address underlying, - uint256 amount, - address onBehalf, - uint256 maxIterations, - uint256 deadline, - Signature calldata signature - ) external returns (uint256 supplied); - function supplyCollateral(address underlying, uint256 amount, address onBehalf) external returns (uint256 supplied); - - function supplyCollateralWithPermit( - address underlying, - uint256 amount, - address onBehalf, - uint256 deadline, - Signature calldata signature - ) external returns (uint256 supplied); function borrow(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations) external @@ -40,14 +18,6 @@ interface IMorphoCore { function repay(address underlying, uint256 amount, address onBehalf) external returns (uint256 repaid); - function repayWithPermit( - address underlying, - uint256 amount, - address onBehalf, - uint256 deadline, - Signature calldata signature - ) external returns (uint256 repaid); - function withdraw(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations) external returns (uint256 withdrawn); From 027e9c264b77f832ae5e985272e3e3372e761a03 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Tue, 28 Feb 2023 18:50:17 -0500 Subject: [PATCH 07/34] remove owner lib --- contracts/mainnet/connectors/morpho-aave-v3/helpers.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index 6aa792a5..f31eff27 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -5,9 +5,8 @@ import "./interface.sol"; import "../../common/stores.sol"; import "../../common/basic.sol"; import "../../common/interfaces.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; -abstract contract Helpers is Stores, Basic, Ownable { +abstract contract Helpers is Stores, Basic { IMorphoCore public constant MORPHO_AAVE_V3 = IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); @@ -30,7 +29,7 @@ abstract contract Helpers is Stores, Basic, Ownable { } } - function setMaxIteration(uint256 _iter) external onlyOwner { + function setMaxIteration(uint256 _iter) external { max_iteration = _iter; } } From df5f92234396cdf6b1359073b32d70de6ee2eb23 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:03:20 +0530 Subject: [PATCH 08/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 19716040..8a614ba7 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -89,7 +89,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - * @param _onBehalf The address of user on behalf to deposit. + * @param _onBehalf The address of user on behalf of whom we want to deposit. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens deposited. */ From 740adbc8207bdc3b6019793bb544c34e70a09b19 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:03:32 +0530 Subject: [PATCH 09/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 8a614ba7..8684eb9d 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -130,7 +130,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) - * @param _onBehalf The address of user on behalf to deposit. + * @param _onBehalf The address of user on behalf of whom we want to deposit. * @param _maxIteration The maximum number of iterations allowed during the matching process. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens deposited. From 2aca0febf194759ba46851e1d62fa1092563da40 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:03:53 +0530 Subject: [PATCH 10/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 8684eb9d..b63c2794 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -7,7 +7,7 @@ import "./events.sol"; abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Deposit ETH/ERC20_Token. - * @notice Deposit a token to Morpho Aave for lending / collaterization. + * @notice Deposit a token to Morpho Aave for lending. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) * @param _getId ID to retrieve amt. From fadb8021cdde5cef62837a1c827b4c56e94b72e1 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:04:02 +0530 Subject: [PATCH 11/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index b63c2794..0501864c 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -86,7 +86,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Deposit ETH/ERC20_Token on behalf of a user. - * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. + * @notice Deposit a token to Morpho Aave for lending on behalf of a user. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) * @param _onBehalf The address of user on behalf of whom we want to deposit. From b6f9e55149accb78a88a9df56f5212b9502bfe30 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:04:13 +0530 Subject: [PATCH 12/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 0501864c..28afa168 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -45,7 +45,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Deposit ETH/ERC20_Token. - * @notice Deposit a token to Morpho Aave for lending / collaterization. + * @notice Deposit a token to Morpho Aave for lending. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) * @param _maxIteration The maximum number of iterations allowed during the matching process. From 0f56614f3e6373fce3c3f54416cfa7217f5a1e10 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:04:46 +0530 Subject: [PATCH 13/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 28afa168..6e3379f7 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -127,7 +127,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Deposit ETH/ERC20_Token on behalf of a user. - * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. + * @notice Deposit a token to Morpho Aave for lending on behalf of a user with max iterations. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) * @param _onBehalf The address of user on behalf of whom we want to deposit. From f5b9ee1d60e713507455b047ee42e451ee7fc89e Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:05:01 +0530 Subject: [PATCH 14/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 6e3379f7..07e63dde 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -171,7 +171,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Deposit ETH/ERC20_Token on behalf of a user. - * @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user. + * @notice Deposit a token to Morpho Aave for lending / collaterization. * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`) * @param _getId ID to retrieve amt. From 810de5d9d35b537ccf942ac5f68c130d74145155 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:06:39 +0530 Subject: [PATCH 15/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 07e63dde..ab16f88e 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -287,7 +287,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Borrow ETH/ERC20_Token. - * @notice Borrow a token from Morpho Aave. + * @notice Borrow a token from Morpho Aave V3. * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to borrow. * @param _getId ID to retrieve amt. From 541f22c21401229d56e5b019df56abf15c8a16d4 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 1 Mar 2023 10:01:50 -0500 Subject: [PATCH 16/34] Update contracts/mainnet/connectors/morpho-aave-v3/main.sol I think we can reduce a line like this so that gas fee will be more reduced. Co-authored-by: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index ab16f88e..5323ea81 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -307,7 +307,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { { uint256 _amt = getUint(_getId, _amount); - MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, max_iteration); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); From a5840aa3fe5e0ef4b389958c735ac28ceaf637da Mon Sep 17 00:00:00 2001 From: q1q0 Date: Wed, 1 Mar 2023 10:13:15 -0500 Subject: [PATCH 17/34] update borrow functions --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 5323ea81..9ee44225 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -346,8 +346,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - - MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, _maxIteration); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); @@ -386,8 +386,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - - MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, _maxIteration); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, _maxIteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); From eb88da980263b06769774a8a8d3ce0749db72d11 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Wed, 1 Mar 2023 10:51:05 -0500 Subject: [PATCH 18/34] update withdraw functions --- .../mainnet/connectors/morpho-aave-v3/main.sol | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 9ee44225..27d43f4c 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -425,7 +425,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, address(this), _receiver, max_iteration); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), _receiver, max_iteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); @@ -462,7 +463,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, _onBehalf, _receiver, max_iteration); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, max_iteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); @@ -501,8 +503,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - - MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, _onBehalf, _receiver, _maxIteration); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, _maxIteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); @@ -531,8 +533,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - - MORPHO_AAVE_V3.withdrawCollateral(_tokenAddress, _amt, address(this), _receiver); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), _receiver); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); @@ -561,7 +563,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - MORPHO_AAVE_V3.withdrawCollateral(_tokenAddress, _amt, _onBehalf, _receiver); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, _onBehalf, _receiver); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); From b3d1b17adfdf3f2e8b87b7730aa99302facddbe1 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 2 Mar 2023 03:00:21 -0500 Subject: [PATCH 19/34] upate repay functions --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 27d43f4c..f3ec1a8c 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -268,8 +268,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - - MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, max_iteration); + address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, max_iteration); convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); @@ -615,7 +615,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.repay(_tokenAddress, _amt, address(this)); + MORPHO_AAVE_V3.repay(address(_tokenContract), _amt, address(this)); setUint(_setId, _amt); @@ -665,7 +665,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); - MORPHO_AAVE_V3.repay(_tokenAddress, _amt, _onBehalf); + MORPHO_AAVE_V3.repay(address(_tokenContract), _amt, _onBehalf); setUint(_setId, _amt); From c405025c213c3ae33f2b12f0c9da0e7000285e38 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Wed, 10 May 2023 07:26:40 -0400 Subject: [PATCH 20/34] remove convertEth function (not complete) --- .../connectors/morpho-aave-v3/helpers.sol | 4 +- .../connectors/morpho-aave-v3/main.sol | 20 +- test/mainnet/morpho/morpho-aave-v3.test.ts | 497 ++++++++++-------- 3 files changed, 284 insertions(+), 237 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index f31eff27..22fc92f2 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -8,9 +8,9 @@ import "../../common/interfaces.sol"; abstract contract Helpers is Stores, Basic { IMorphoCore public constant MORPHO_AAVE_V3 = - IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); + IMorphoCore(0x33333aea097c193e66081E930c33020272b33333); - uint256 public max_iteration = 10; + uint256 public max_iteration = 4; function _performEthToWethConversion( address _tokenAddress, diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index f3ec1a8c..d7583753 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -271,7 +271,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, max_iteration); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -310,7 +310,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -349,7 +349,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -389,7 +389,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, _maxIteration); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -428,8 +428,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), _receiver, max_iteration); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); _eventName = "LogWithdraw(address,uint256,address,uint256,uint256)"; @@ -465,8 +464,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { uint256 _amt = getUint(_getId, _amount); address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, max_iteration); - - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -506,7 +504,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, _maxIteration); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -536,7 +534,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), _receiver); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -565,7 +563,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { uint256 _amt = getUint(_getId, _amount); address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, _onBehalf, _receiver); - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 7ee1edbf..56699cee 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -14,12 +14,14 @@ import type { Signer, Contract } from "ethers"; const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0' -const Usdc = parseUnits('500', 6) +const Usdc = parseUnits('5000', 6) const DAI = '0x6b175474e89094c44da98b954eedeac495271d0f' const ACC_DAI = '0xcd6Eb888e76450eF584E8B51bB73c76ffBa21FF2' const Dai = parseUnits('1', 18) +const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' + const user = "0x41bc7d0687e6cea57fa26da78379dfdc5627c56d" const token_usdc = new ethers.Contract( @@ -34,6 +36,12 @@ const token_dai = new ethers.Contract( ethers.provider, ) +const token_weth = new ethers.Contract( + WETH, + IERC20Minimal__factory.abi, + ethers.provider, +) + describe("Morpho-Aave-v3", function () { const connectorName = "MORPHO-AAVE-V3-TEST-A"; let connector: any; @@ -51,7 +59,7 @@ describe("Morpho-Aave-v3", function () { forking: { // @ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 15714501, + // blockNumber: 15714501, }, }, ], @@ -93,7 +101,7 @@ describe("Morpho-Aave-v3", function () { ); }); - it("Deposit 500 USDC into DSA wallet", async function () { + it("Deposit 5000 USDC into DSA wallet", async function () { await hre.network.provider.request({ method: 'hardhat_impersonateAccount', @@ -111,31 +119,31 @@ describe("Morpho-Aave-v3", function () { await token_usdc.connect(wallet0).transfer(dsaWallet0.address, Usdc); expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - parseUnits('500', 6) + parseUnits('5000', 6) ); }); - it("Deposit 1 DAI into DSA wallet", async function () { + // it("Deposit 1 DAI into DSA wallet", async function () { - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [ACC_DAI], - }) + // await hre.network.provider.request({ + // method: 'hardhat_impersonateAccount', + // params: [ACC_DAI], + // }) - const signer_dai = await ethers.getSigner(ACC_DAI) - await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) + // const signer_dai = await ethers.getSigner(ACC_DAI) + // await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [ACC_DAI], - }) + // await hre.network.provider.request({ + // method: 'hardhat_stopImpersonatingAccount', + // params: [ACC_DAI], + // }) - await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); + // await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - parseUnits('1', 18) - ); - }); + // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('1', 18) + // ); + // }); }); describe("Main", function () { @@ -159,31 +167,12 @@ describe("Morpho-Aave-v3", function () { ); }) - it("Should deposit 10 USDC", async function () { - const spells = [ - { - connector: connectorName, - method: "deposit", - args: [tokens.usdc.address, "10000000", "0", "0"], // 10 USDC - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('490', 6) - ); - }) - - it("Should deposit 100 USDC with MaxIteration", async function () { + it("Should deposit 1 ETH with MaxIteration", async function () { const spells = [ { connector: connectorName, method: "depositWithMaxIterations", - args: [tokens.usdc.address, "100000000", 5, "0", "0"], // 100 USDC + args: [tokens.eth.address, "1000000000000000000", 5, "0", "0"], // 1 ETH }, ]; @@ -192,17 +181,17 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('390', 6) + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('989', 18)) ); }) - it("Should deposit 100 USDC on behalf", async function () { + it("Should deposit 10 ETH on behalf", async function () { const spells = [ { connector: connectorName, method: "depositOnBehalf", - args: [tokens.usdc.address, "100000000", user, "0", "0"], // 100 USDC + args: [tokens.eth.address, "10000000000000000000", user, "0", "0"], // 1 ETH }, ]; @@ -211,17 +200,17 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('290', 6) + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('979', 18)) ); }) - it("Should deposit 100 USDC on behalf with MaxIteration", async function () { + it("Should deposit 1 ETH on behalf with MaxIteration", async function () { const spells = [ { connector: connectorName, method: "depositOnBehalfWithMaxIterations", - args: [tokens.usdc.address, "100000000", user, 5, "0", "0"], // 100 USDC + args: [tokens.eth.address, "1000000000000000000", user, 5, "0", "0"], // 1 ETH }, ]; @@ -230,17 +219,17 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('190', 6) + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('978', 18)) ); }) - it("Should deposit 100 USDC as collateral", async function () { + it("Should deposit 2000 USDC as collateral", async function () { const spells = [ { connector: connectorName, method: "depositCollateral", - args: [tokens.usdc.address, "50000000", "0", "0"], // 50 USDC + args: [tokens.usdc.address, "2000000000", "0", "0"], // 50 USDC }, ]; @@ -250,16 +239,16 @@ describe("Morpho-Aave-v3", function () { await tx.wait(); expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('140', 6) + parseUnits('3000', 6) ); }) - it("Should deposit 100 USDC as collateral on behalf", async function () { + it("Should deposit 2000 USDC as collateral on behalf", async function () { const spells = [ { connector: connectorName, method: "depositCollateralOnBehalf", - args: [tokens.usdc.address, "50000000", user, "0", "0"], // 50 USDC + args: [tokens.usdc.address, "2000000000", user, "0", "0"], // 50 USDC }, ]; @@ -269,126 +258,16 @@ describe("Morpho-Aave-v3", function () { await tx.wait(); expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('90', 6) + parseUnits('1000', 6) ); }) - it("Should borrow DAI into DSA", async function () { - const spells = [ - { - connector: connectorName, - method: "borrow", - args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, "0", "0"], // 10 DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - .to.be.gte(parseUnits('11', 18)); - }) - - it("Should borrow DAI into DSA on behalf", async function () { - const spells = [ - { - connector: connectorName, - method: "borrowOnBehalf", - args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, "0", "0"], // 10 DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - .to.be.gte(parseUnits('21', 18)); - }) - - it("Should borrow DAI into DSA with MaxIteration", async function () { - const spells = [ - { - connector: connectorName, - method: "borrowWithMaxIterations", - args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, 5, "0", "0"], // 10 DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - .to.be.gte(parseUnits('31', 18)); - }) - - it("Should borrow DAI into DSA on behalf with MaxIteration", async function () { - const spells = [ - { - connector: connectorName, - method: "borrowOnBehalfWithMaxIterations", - args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, 5, "0", "0"], // 10 DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - .to.be.gte(parseUnits('41', 18)); - }) - - it("Should payback DAI MAX", async function () { - const spells = [ - { - connector: connectorName, - method: "payback", - args: [tokens.dai.address, dsaMaxValue, "0", "0"], // Max DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('1', 18) - ); - }) - - it("Should payback ETH on behalf", async function () { - const spells = [ - { - connector: connectorName, - method: "paybackOnBehalf", - args: [tokens.eth.address, user, dsaMaxValue, "0", "0"], // Max ETH - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - parseUnits('125', 18) - ); - }) - - it("Should withdraw ETH max", async function () { + it("Should withdraw 10 ETH", async function () { const spells = [ { connector: connectorName, method: "withdraw", - args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, "0", "0"], // Max ETH + args: [tokens.eth.address, "10000000000000000000", dsaWallet0.address, "0", "0"], // 10 ETH }, ]; @@ -398,16 +277,16 @@ describe("Morpho-Aave-v3", function () { await tx.wait(); expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( - parseUnits('134', 18)) + parseUnits('978', 18)) ); }) - it("Should withdraw 8 USDC on behalf", async function () { + it("Should withdraw ETH max on behalf", async function () { const spells = [ { connector: connectorName, method: "withdrawOnBehalf", - args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // Max ETH }, ]; @@ -416,18 +295,37 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); + console.log("------------user balance----------",(await token_weth.balanceOf(user)).toString()) + expect(await token_weth.balanceOf(user)).to.be.gte(parseUnits('1', 18)) }) - it("Should withdraw 8 USDC on behalf", async function () { + it("Should borrow WETH into DSA", async function () { + const balance = await token_weth.balanceOf(dsaWallet0.address); + const spells = [ + { + connector: connectorName, + method: "borrow", + args: [tokens.weth.address, "500000000000000000", dsaWallet0.address, "0", "0"], // 0.7 WETH + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + console.log("====================", balance.toString(), (await token_weth.balanceOf(dsaWallet0.address)).toString()) + expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) + .to.be.eq(parseUnits('5', 17)); + }) + + it("Should borrow WETH into user", async function () { + const balance = await token_weth.balanceOf(user); const spells = [ { connector: connectorName, - method: "withdrawOnBehalf", - args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + method: "borrowOnBehalf", + args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH }, ]; @@ -436,18 +334,18 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); + console.log("====================", balance.toString(), (await token_weth.balanceOf(user)).toString()) + expect((await token_weth.balanceOf(user)).sub(balance)) + .to.be.eq(parseUnits('2', 17)); }) - it("Should withdraw 8 USDC on behalf with MaxIteration", async function () { + it("Should borrow WETH into wallet1 using iteration", async function () { + const balance = await token_weth.balanceOf(dsaWallet0.address); const spells = [ { connector: connectorName, - method: "withdrawWithMaxIterations", - args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + method: "borrowWithMaxIterations", + args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.7 WETH }, ]; @@ -456,50 +354,201 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); + console.log("====================", balance.toString(), (await token_weth.balanceOf(dsaWallet0.address)).toString()) + expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) + .to.be.eq(parseUnits('2', 17)); }) - it("Should withdraw 8 USDC as collateral", async function () { - const spells = [ - { - connector: connectorName, - method: "withdrawCollateral", - args: [tokens.usdc.address, "8000000", dsaWallet0.address, 5, "0", "0"], // 8 USDC - }, - ]; + // it("Should borrow DAI into DSA on behalf", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "borrowOnBehalf", + // args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, "0", "0"], // 10 DAI + // }, + // ]; - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); - }) + // await tx.wait(); + // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + // .to.be.gte(parseUnits('21', 18)); + // }) - it("Should withdraw 8 USDC as collateral on behalf", async function () { - const spells = [ - { - connector: connectorName, - method: "withdrawCollateralOnBehalf", - args: [tokens.usdc.address, "8000000",user, dsaWallet0.address, 5, "0", "0"], // 8 USDC - }, - ]; + // it("Should borrow DAI into DSA with MaxIteration", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "borrowWithMaxIterations", + // args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, 5, "0", "0"], // 10 DAI + // }, + // ]; - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); - }) + // await tx.wait(); + // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + // .to.be.gte(parseUnits('31', 18)); + // }) + + // it("Should borrow DAI into DSA on behalf with MaxIteration", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "borrowOnBehalfWithMaxIterations", + // args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, 5, "0", "0"], // 10 DAI + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + // .to.be.gte(parseUnits('41', 18)); + // }) + + // it("Should payback DAI MAX", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "payback", + // args: [tokens.dai.address, dsaMaxValue, "0", "0"], // Max DAI + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.lte( + // parseUnits('1', 18) + // ); + // }) + + // it("Should payback ETH on behalf", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "paybackOnBehalf", + // args: [tokens.eth.address, user, dsaMaxValue, "0", "0"], // Max ETH + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + // parseUnits('125', 18) + // ); + // }) + + // it("Should withdraw 8 USDC on behalf", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "withdrawOnBehalf", + // args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // // parseUnits('398', 6)) + // // ); + // }) + + // it("Should withdraw 8 USDC on behalf", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "withdrawOnBehalf", + // args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // // parseUnits('398', 6)) + // // ); + // }) + + // it("Should withdraw 8 USDC on behalf with MaxIteration", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "withdrawWithMaxIterations", + // args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // // parseUnits('398', 6)) + // // ); + // }) + + // it("Should withdraw 8 USDC as collateral", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "withdrawCollateral", + // args: [tokens.usdc.address, "8000000", dsaWallet0.address, 5, "0", "0"], // 8 USDC + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // // parseUnits('398', 6)) + // // ); + // }) + + // it("Should withdraw 8 USDC as collateral on behalf", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "withdrawCollateralOnBehalf", + // args: [tokens.usdc.address, "8000000",user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // // parseUnits('398', 6)) + // // ); + // }) }); }); From bb8914afde0eaf61879ed6accf06caa05d27d67c Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 22 Jun 2023 12:30:36 -0400 Subject: [PATCH 21/34] update logic --- .../connectors/morpho-aave-v3/interface.sol | 2 + .../connectors/morpho-aave-v3/main.sol | 62 ++- test/mainnet/morpho/morpho-aave-v3.test.ts | 371 +++++++++--------- 3 files changed, 238 insertions(+), 197 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/interface.sol b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol index 9535f033..d1f79f64 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/interface.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/interface.sol @@ -25,4 +25,6 @@ interface IMorphoCore { function withdrawCollateral(address underlying, uint256 amount, address onBehalf, address receiver) external returns (uint256 withdrawn); + + function approveManager(address manager, bool isAllowed) external; } diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index d7583753..0ebde07a 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -271,7 +271,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, max_iteration); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -310,7 +314,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -349,7 +357,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -389,7 +401,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, _maxIteration); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -428,7 +444,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), _receiver, max_iteration); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } + setUint(_setId, _amt); _eventName = "LogWithdraw(address,uint256,address,uint256,uint256)"; @@ -464,7 +485,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { uint256 _amt = getUint(_getId, _amount); address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, max_iteration); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -504,7 +529,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, _maxIteration); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -534,7 +563,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), _receiver); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -563,7 +596,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { uint256 _amt = getUint(_getId, _amount); address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, _onBehalf, _receiver); - // convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + if(_tokenAddress == ethAddr) { + if(_receiver == address(this)) + convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); + else revert("cannot convert"); + } setUint(_setId, _amt); @@ -676,6 +713,13 @@ abstract contract MorphoAaveV3 is Helpers, Events { _setId ); } + + /// @notice Approves a `manager` to borrow/withdraw on behalf of the sender. + /// @param _manager The address of the manager. + /// @param _isAllowed Whether `manager` is allowed to manage `msg.sender`'s position or not. + function approveManager(address _manager, bool _isAllowed) external { + MORPHO_AAVE_V3.approveManager(_manager, _isAllowed); + } } contract ConnectV3MorphoAaveV3 is MorphoAaveV3 { diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 56699cee..7c446158 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -123,27 +123,27 @@ describe("Morpho-Aave-v3", function () { ); }); - // it("Deposit 1 DAI into DSA wallet", async function () { + it("Deposit 1 DAI into DSA wallet", async function () { - // await hre.network.provider.request({ - // method: 'hardhat_impersonateAccount', - // params: [ACC_DAI], - // }) + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [ACC_DAI], + }) - // const signer_dai = await ethers.getSigner(ACC_DAI) - // await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) + const signer_dai = await ethers.getSigner(ACC_DAI) + await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) - // await hre.network.provider.request({ - // method: 'hardhat_stopImpersonatingAccount', - // params: [ACC_DAI], - // }) + await hre.network.provider.request({ + method: 'hardhat_stopImpersonatingAccount', + params: [ACC_DAI], + }) - // await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); + await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); - // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('1', 18) - // ); - // }); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('1', 18) + ); + }); }); describe("Main", function () { @@ -281,7 +281,7 @@ describe("Morpho-Aave-v3", function () { ); }) - it("Should withdraw ETH max on behalf", async function () { + it("Should revert because behalf is different with dsa address", async function () { const spells = [ { connector: connectorName, @@ -290,13 +290,10 @@ describe("Morpho-Aave-v3", function () { }, ]; - const tx = await dsaWallet0 + await expect(dsaWallet0 .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + .cast(...encodeSpells(spells), wallet1.getAddress())).to.be.revertedWith("cannot convert"); - await tx.wait(); - console.log("------------user balance----------",(await token_weth.balanceOf(user)).toString()) - expect(await token_weth.balanceOf(user)).to.be.gte(parseUnits('1', 18)) }) it("Should borrow WETH into DSA", async function () { @@ -314,7 +311,6 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("====================", balance.toString(), (await token_weth.balanceOf(dsaWallet0.address)).toString()) expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) .to.be.eq(parseUnits('5', 17)); }) @@ -334,7 +330,6 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("====================", balance.toString(), (await token_weth.balanceOf(user)).toString()) expect((await token_weth.balanceOf(user)).sub(balance)) .to.be.eq(parseUnits('2', 17)); }) @@ -345,7 +340,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "borrowWithMaxIterations", - args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.7 WETH + args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.7 WETH }, ]; @@ -356,199 +351,199 @@ describe("Morpho-Aave-v3", function () { await tx.wait(); console.log("====================", balance.toString(), (await token_weth.balanceOf(dsaWallet0.address)).toString()) expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) - .to.be.eq(parseUnits('2', 17)); + .to.be.eq(parseUnits('2', 16)); }) - // it("Should borrow DAI into DSA on behalf", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "borrowOnBehalf", - // args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, "0", "0"], // 10 DAI - // }, - // ]; + it("Should borrow DAI into DSA on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "borrowOnBehalf", + args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, "0", "0"], // 10 DAI + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - // .to.be.gte(parseUnits('21', 18)); - // }) + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + .to.be.gte(parseUnits('21', 18)); + }) - // it("Should borrow DAI into DSA with MaxIteration", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "borrowWithMaxIterations", - // args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, 5, "0", "0"], // 10 DAI - // }, - // ]; + it("Should borrow DAI into DSA with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "borrowWithMaxIterations", + args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, 5, "0", "0"], // 10 DAI + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - // .to.be.gte(parseUnits('31', 18)); - // }) + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + .to.be.gte(parseUnits('31', 18)); + }) - // it("Should borrow DAI into DSA on behalf with MaxIteration", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "borrowOnBehalfWithMaxIterations", - // args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, 5, "0", "0"], // 10 DAI - // }, - // ]; + it("Should borrow DAI into DSA on behalf with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "borrowOnBehalfWithMaxIterations", + args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, 5, "0", "0"], // 10 DAI + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - // .to.be.gte(parseUnits('41', 18)); - // }) + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) + .to.be.gte(parseUnits('41', 18)); + }) - // it("Should payback DAI MAX", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "payback", - // args: [tokens.dai.address, dsaMaxValue, "0", "0"], // Max DAI - // }, - // ]; + it("Should payback DAI MAX", async function () { + const spells = [ + { + connector: connectorName, + method: "payback", + args: [tokens.dai.address, dsaMaxValue, "0", "0"], // Max DAI + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.lte( - // parseUnits('1', 18) - // ); - // }) + await tx.wait(); + expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('1', 18) + ); + }) - // it("Should payback ETH on behalf", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "paybackOnBehalf", - // args: [tokens.eth.address, user, dsaMaxValue, "0", "0"], // Max ETH - // }, - // ]; + it("Should payback ETH on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "paybackOnBehalf", + args: [tokens.eth.address, user, dsaMaxValue, "0", "0"], // Max ETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - // parseUnits('125', 18) - // ); - // }) + await tx.wait(); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('125', 18) + ); + }) - // it("Should withdraw 8 USDC on behalf", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "withdrawOnBehalf", - // args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC - // }, - // ]; + it("Should withdraw 8 USDC on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawOnBehalf", + args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // // parseUnits('398', 6)) - // // ); - // }) + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) - // it("Should withdraw 8 USDC on behalf", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "withdrawOnBehalf", - // args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC - // }, - // ]; + it("Should withdraw 8 USDC on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawOnBehalf", + args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // // parseUnits('398', 6)) - // // ); - // }) + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) - // it("Should withdraw 8 USDC on behalf with MaxIteration", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "withdrawWithMaxIterations", - // args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, 5, "0", "0"], // 8 USDC - // }, - // ]; + it("Should withdraw 8 USDC on behalf with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawWithMaxIterations", + args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // // parseUnits('398', 6)) - // // ); - // }) + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) - // it("Should withdraw 8 USDC as collateral", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "withdrawCollateral", - // args: [tokens.usdc.address, "8000000", dsaWallet0.address, 5, "0", "0"], // 8 USDC - // }, - // ]; + it("Should withdraw 8 USDC as collateral", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawCollateral", + args: [tokens.usdc.address, "8000000", dsaWallet0.address, 5, "0", "0"], // 8 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // // parseUnits('398', 6)) - // // ); - // }) + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) - // it("Should withdraw 8 USDC as collateral on behalf", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "withdrawCollateralOnBehalf", - // args: [tokens.usdc.address, "8000000",user, dsaWallet0.address, 5, "0", "0"], // 8 USDC - // }, - // ]; + it("Should withdraw 8 USDC as collateral on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "withdrawCollateralOnBehalf", + args: [tokens.usdc.address, "8000000",user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // // parseUnits('398', 6)) - // // ); - // }) + await tx.wait(); + console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) + // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('398', 6)) + // ); + }) }); }); From b8e26934d46e5140342e63ebae6f96a2953a3e16 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 22 Jun 2023 14:59:51 -0400 Subject: [PATCH 22/34] update test script --- .../connectors/morpho-aave-v3/events.sol | 2 + .../connectors/morpho-aave-v3/main.sol | 7 +- test/mainnet/morpho/morpho-aave-v3.test.ts | 250 +++++------------- 3 files changed, 81 insertions(+), 178 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol index 295bc51c..cc13ace6 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/events.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -143,4 +143,6 @@ contract Events { uint256 getId, uint256 setId ); + + event LogApproveManger(address manger, bool isAllowed); } diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 0ebde07a..f55ace7a 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -717,8 +717,13 @@ abstract contract MorphoAaveV3 is Helpers, Events { /// @notice Approves a `manager` to borrow/withdraw on behalf of the sender. /// @param _manager The address of the manager. /// @param _isAllowed Whether `manager` is allowed to manage `msg.sender`'s position or not. - function approveManager(address _manager, bool _isAllowed) external { + function approveManager(address _manager, bool _isAllowed) external returns (string memory _eventName, bytes memory _eventParam) { MORPHO_AAVE_V3.approveManager(_manager, _isAllowed); + _eventName = "LogApproveManger(address,bool)"; + _eventParam = abi.encode( + _manager, + _isAllowed + ); } } diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 7c446158..d91d55a6 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -123,27 +123,27 @@ describe("Morpho-Aave-v3", function () { ); }); - it("Deposit 1 DAI into DSA wallet", async function () { + // it("Deposit 1 DAI into DSA wallet", async function () { - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [ACC_DAI], - }) + // await hre.network.provider.request({ + // method: 'hardhat_impersonateAccount', + // params: [ACC_DAI], + // }) - const signer_dai = await ethers.getSigner(ACC_DAI) - await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) + // const signer_dai = await ethers.getSigner(ACC_DAI) + // await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [ACC_DAI], - }) + // await hre.network.provider.request({ + // method: 'hardhat_stopImpersonatingAccount', + // params: [ACC_DAI], + // }) - await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); + // await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - parseUnits('1', 18) - ); - }); + // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('1', 18) + // ); + // }); }); describe("Main", function () { @@ -354,164 +354,18 @@ describe("Morpho-Aave-v3", function () { .to.be.eq(parseUnits('2', 16)); }) - it("Should borrow DAI into DSA on behalf", async function () { + it("Test withdrawCollateral ", async function () { + const balance = await token_weth.balanceOf(dsaWallet0.address); const spells = [ { connector: connectorName, - method: "borrowOnBehalf", - args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, "0", "0"], // 10 DAI + method: "depositCollateral", + args: [tokens.usdc.address, "20000000", "0", "0"], // 20 USDC }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - .to.be.gte(parseUnits('21', 18)); - }) - - it("Should borrow DAI into DSA with MaxIteration", async function () { - const spells = [ - { - connector: connectorName, - method: "borrowWithMaxIterations", - args: [tokens.dai.address, "10000000000000000000", dsaWallet0.address, 5, "0", "0"], // 10 DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - .to.be.gte(parseUnits('31', 18)); - }) - - it("Should borrow DAI into DSA on behalf with MaxIteration", async function () { - const spells = [ - { - connector: connectorName, - method: "borrowOnBehalfWithMaxIterations", - args: [tokens.dai.address, "10000000000000000000", user, dsaWallet0.address, 5, "0", "0"], // 10 DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)) - .to.be.gte(parseUnits('41', 18)); - }) - - it("Should payback DAI MAX", async function () { - const spells = [ - { - connector: connectorName, - method: "payback", - args: [tokens.dai.address, dsaMaxValue, "0", "0"], // Max DAI - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('1', 18) - ); - }) - - it("Should payback ETH on behalf", async function () { - const spells = [ - { - connector: connectorName, - method: "paybackOnBehalf", - args: [tokens.eth.address, user, dsaMaxValue, "0", "0"], // Max ETH - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - parseUnits('125', 18) - ); - }) - - it("Should withdraw 8 USDC on behalf", async function () { - const spells = [ - { - connector: connectorName, - method: "withdrawOnBehalf", - args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); - }) - - it("Should withdraw 8 USDC on behalf", async function () { - const spells = [ - { - connector: connectorName, - method: "withdrawOnBehalf", - args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, "0", "0"], // 8 USDC - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); - }) - - it("Should withdraw 8 USDC on behalf with MaxIteration", async function () { - const spells = [ - { - connector: connectorName, - method: "withdrawWithMaxIterations", - args: [tokens.usdc.address, "8000000", user, dsaWallet0.address, 5, "0", "0"], // 8 USDC - }, - ]; - - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); - }) - - it("Should withdraw 8 USDC as collateral", async function () { - const spells = [ { connector: connectorName, method: "withdrawCollateral", - args: [tokens.usdc.address, "8000000", dsaWallet0.address, 5, "0", "0"], // 8 USDC + args: [tokens.usdc.address, "20000000", dsaWallet0.address, "0", "0"], // 20 USDC }, ]; @@ -520,18 +374,21 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); + }) - it("Should withdraw 8 USDC as collateral on behalf", async function () { + it("Test withdrawCollateralOnBehalf ", async function () { + const balance = await token_weth.balanceOf(dsaWallet0.address); const spells = [ + { + connector: connectorName, + method: "depositCollateralOnBehalf", + args: [tokens.usdc.address, "20000000", user, "0", "0"], // 20 USDC + }, { connector: connectorName, method: "withdrawCollateralOnBehalf", - args: [tokens.usdc.address, "8000000",user, dsaWallet0.address, 5, "0", "0"], // 8 USDC + args: [tokens.usdc.address, "20000000", dsaWallet0.address, user, "0", "0"], // 20 USDC }, ]; @@ -540,10 +397,49 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("----balance of USDC----", (await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).toString()) - // expect(expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('398', 6)) - // ); + + }) + + it("Test payback ", async function () { + const spells = [ + { + connector: connectorName, + method: "depositCollateral", + args: [tokens.usdc.address, "2000000000", "0", "0"], // 2 ETH + }, + { + connector: connectorName, + method: "borrow", + args: [tokens.eth.address, "10000000000000000", dsaWallet0.address, "0", "0"], // 20 USDC + }, + { + connector: connectorName, + method: "payback", + args: [tokens.eth.address, "10000000000000000", "0", "0"], // 20 USDC + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + + }) + + it("approve manger", async () => { + const spells = [ + { + connector: connectorName, + method: "approveManager", + args: [user, true], // 2 ETH + }, + ] + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); }) }); }); From 0b7c98b84ac4c364a4c667f69c41618bfee57e1a Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 22 Jun 2023 15:04:06 -0400 Subject: [PATCH 23/34] update minor --- test/mainnet/morpho/morpho-aave-v3.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index d91d55a6..823e7313 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -405,17 +405,17 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "depositCollateral", - args: [tokens.usdc.address, "2000000000", "0", "0"], // 2 ETH + args: [tokens.usdc.address, "200000000", "0", "0"], // 2 ETH }, { connector: connectorName, method: "borrow", - args: [tokens.eth.address, "10000000000000000", dsaWallet0.address, "0", "0"], // 20 USDC + args: [tokens.eth.address, "1000000000000000", dsaWallet0.address, "0", "0"], // 20 USDC }, { connector: connectorName, method: "payback", - args: [tokens.eth.address, "10000000000000000", "0", "0"], // 20 USDC + args: [tokens.eth.address, "1000000000000000", "0", "0"], // 20 USDC }, ]; From 68fd773773a74404255228561832fb8615489933 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Fri, 23 Jun 2023 04:21:04 +0800 Subject: [PATCH 24/34] Optimise and update --- .../connectors/morpho-aave-v3/events.sol | 2 - .../connectors/morpho-aave-v3/helpers.sol | 8 +- .../connectors/morpho-aave-v3/main.sol | 148 ++++++++++-------- 3 files changed, 86 insertions(+), 72 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol index cc13ace6..456c7f8d 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/events.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -53,7 +53,6 @@ contract Events { event LogBorrow( address tokenAddress, uint256 amount, - address receiver, uint256 getId, uint256 setId ); @@ -89,7 +88,6 @@ contract Events { event LogWithdraw( address tokenAddress, uint256 amount, - address receiver, uint256 getId, uint256 setId ); diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index 22fc92f2..6afd0997 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -21,15 +21,11 @@ abstract contract Helpers is Stores, Basic { if (_tokenAddress == ethAddr) { _tokenContract = TokenInterface(wethAddr); - if (_amt == uint256(-1)) _amt = address(this).balance; + if (_amt == type(uint256).max) _amt = address(this).balance; convertEthToWeth(true, _tokenContract, _amt); } else { _tokenContract = TokenInterface(_tokenAddress); - if (_amt == uint256(-1)) _amt = _tokenContract.balanceOf(address(this)); + if (_amt == type(uint256).max) _amt = _tokenContract.balanceOf(address(this)); } } - - function setMaxIteration(uint256 _iter) external { - max_iteration = _iter; - } } diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index f55ace7a..e110dcb9 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -259,7 +259,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { function borrow( address _tokenAddress, uint256 _amount, - address _receiver, uint256 _getId, uint256 _setId ) @@ -268,22 +267,19 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, max_iteration); + bool _isETH = _tokenAddress == ethAddr; + address _token = _isETH ? wethAddr : _tokenAddress; + + MORPHO_AAVE_V3.borrow(_token, _amt, address(this), address(this), max_iteration); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + convertWethToEth(_isETH, TokenInterface(_token), _amt); setUint(_setId, _amt); - _eventName = "LogBorrow(address,uint256,address,uint256,uint256)"; + _eventName = "LogBorrow(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, - _receiver, _getId, _setId ); @@ -294,6 +290,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Borrow a token from Morpho Aave V3. * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to borrow. + * @param _onBehalf The address of user on behalf to borrow. + * @param _receiver The address of receiver to receive the borrowed tokens. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens borrowed. */ @@ -310,15 +308,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); + bool _isETH = _tokenAddress == ethAddr; + address _token = _isETH ? wethAddr : _tokenAddress; - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(wethAddr), _amt); setUint(_setId, _amt); @@ -338,6 +333,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Borrow a token from Morpho Aave. * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to borrow. + * @param _receiver The address of receiver to receive the borrowed tokens. + * @param _maxIteration The maximum number of iterations to be used for borrow. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens borrowed. */ @@ -354,14 +351,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + bool _isETH = _tokenAddress == ethAddr; + address _token = _isETH ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _amt); setUint(_setId, _amt); @@ -398,14 +393,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + bool _isETH = _tokenAddress == ethAddr; + address _token = _isETH ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, _maxIteration); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _amt); setUint(_setId, _amt); @@ -432,7 +425,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { function withdraw( address _tokenAddress, uint256 _amount, - address _receiver, uint256 _getId, uint256 _setId ) @@ -441,22 +433,20 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), _receiver, max_iteration); + bool _isEth = _tokenAddress == ethAddr; + address _token = _isEth? wethAddr : _tokenAddress; + + // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. + MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), address(this), max_iteration); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + convertWethToEth(_isEth, TokenInterface(_token), _amt); setUint(_setId, _amt); - _eventName = "LogWithdraw(address,uint256,address,uint256,uint256)"; + _eventName = "LogWithdraw(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, - _receiver, _getId, _setId ); @@ -467,6 +457,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Withdraw a token from Morpho Aave. * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) + * @param _onBehalf Address for which tokens are being withdrawn. + * @param _receiver Address to which tokens are being transferred. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. */ @@ -483,13 +475,13 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + bool _isEth = _tokenAddress == ethAddr; + address _token = _isEth ? wethAddr : _tokenAddress; + + // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, max_iteration); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); setUint(_setId, _amt); @@ -509,6 +501,9 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Withdraw a token from Morpho Aave. * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) + * @param _onBehalf Address for which tokens are being withdrawn. + * @param _receiver Address to which tokens are being transferred. + * @param _maxIteration Max number of iterations to run. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. */ @@ -526,14 +521,13 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + bool _isEth = _tokenAddress == ethAddr; + address _token = _isEth ? wethAddr : _tokenAddress; + + // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, _maxIteration); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); setUint(_setId, _amt); @@ -548,6 +542,15 @@ abstract contract MorphoAaveV3 is Helpers, Events { ); } + /** + * @dev Withdraw ETH/ERC20 collateral token. + * @notice Withdraw a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) + * @param _receiver Address to which tokens are being transferred. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens withdrawed. + */ function withdrawCollateral( address _tokenAddress, uint256 _amount, @@ -560,14 +563,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + bool _isEth = _tokenAddress == ethAddr; + address _token = _isEth ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), _receiver); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); setUint(_setId, _amt); @@ -581,6 +582,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { ); } + /** + * @dev Withdraw ETH/ERC20 collateral token. + * @notice Withdraw a token from Morpho Aave. + * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) + * @param _onBehalf Address for which tokens are being withdrawn. + * @param _receiver Address to which tokens are being transferred. + * @param _getId ID to retrieve amt. + * @param _setId ID stores the amount of tokens withdrawed. + */ function withdrawCollateralOnBehalf( address _tokenAddress, uint256 _amount, @@ -594,13 +605,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { uint256 _amt = getUint(_getId, _amount); - address _token = _tokenAddress == ethAddr ? wethAddr : _tokenAddress; + bool _isEth = _tokenAddress == ethAddr; + address _token = _isEth ? wethAddr : _tokenAddress; + MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, _onBehalf, _receiver); - if(_tokenAddress == ethAddr) { - if(_receiver == address(this)) - convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt); - else revert("cannot convert"); - } + + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); setUint(_setId, _amt); @@ -717,16 +727,26 @@ abstract contract MorphoAaveV3 is Helpers, Events { /// @notice Approves a `manager` to borrow/withdraw on behalf of the sender. /// @param _manager The address of the manager. /// @param _isAllowed Whether `manager` is allowed to manage `msg.sender`'s position or not. - function approveManager(address _manager, bool _isAllowed) external returns (string memory _eventName, bytes memory _eventParam) { + function approveManager(address _manager, bool _isAllowed) + external + returns (string memory _eventName, bytes memory _eventParam) + { MORPHO_AAVE_V3.approveManager(_manager, _isAllowed); + _eventName = "LogApproveManger(address,bool)"; _eventParam = abi.encode( _manager, _isAllowed ); } + + /// @notice Updates the max iterations for a `repay` or a `withdraw`. + /// @param _iterations New iteration count. + function updateMaxIterations(uint256 _iterations) external { + max_iteration = _iterations; + } } -contract ConnectV3MorphoAaveV3 is MorphoAaveV3 { +contract ConnectV2MorphoAaveV3 is MorphoAaveV3 { string public constant name = "Morpho-AaveV3-v1.0"; } From 448817d8ea264fd4a191c6d2de42f309afd00ace Mon Sep 17 00:00:00 2001 From: q1q0 Date: Fri, 23 Jun 2023 05:09:36 -0400 Subject: [PATCH 25/34] add claim reward in morpho-v3 --- .../connectors/morpho-rewards/events.sol | 7 +++++ .../connectors/morpho-rewards/helpers.sol | 3 ++ .../connectors/morpho-rewards/interface.sol | 7 +++++ .../connectors/morpho-rewards/main.sol | 30 +++++++++++++++++++ test/mainnet/morpho/morpho-aave-v3.test.ts | 24 +++++++++------ 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-rewards/events.sol b/contracts/mainnet/connectors/morpho-rewards/events.sol index 905a08b4..c272dc61 100644 --- a/contracts/mainnet/connectors/morpho-rewards/events.sol +++ b/contracts/mainnet/connectors/morpho-rewards/events.sol @@ -16,6 +16,13 @@ contract Events { uint256 setId ); + event LogClaimedAaveV3( + address[] poolTokenAddresses, + address onBehalf, + address[] rewardTokens, + uint256[] claimedAmounts + ); + event LogClaimedCompound( address[] poolTokenAddresses, bool tradeForMorphoToken, diff --git a/contracts/mainnet/connectors/morpho-rewards/helpers.sol b/contracts/mainnet/connectors/morpho-rewards/helpers.sol index 7cd6799d..caa43cf9 100644 --- a/contracts/mainnet/connectors/morpho-rewards/helpers.sol +++ b/contracts/mainnet/connectors/morpho-rewards/helpers.sol @@ -11,6 +11,9 @@ abstract contract Helpers is Basic { IMorphoCore public constant MORPHO_AAVE = IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); + IMorphoCoreV3 public constant MORPHO_AAVE_V3 = + IMorphoCoreV3(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); + IMorphoRewardsDistributor public constant MORPHO_REWARDS = IMorphoRewardsDistributor(0x3B14E5C73e0A56D607A8688098326fD4b4292135); } diff --git a/contracts/mainnet/connectors/morpho-rewards/interface.sol b/contracts/mainnet/connectors/morpho-rewards/interface.sol index 46fefd84..bbc5016e 100644 --- a/contracts/mainnet/connectors/morpho-rewards/interface.sol +++ b/contracts/mainnet/connectors/morpho-rewards/interface.sol @@ -15,3 +15,10 @@ interface IMorphoRewardsDistributor { bytes32[] calldata _proof ) external; } + +interface IMorphoCoreV3 { + function claimRewards( + address[] calldata _assets, + address _onBehalf + ) external returns (address[] memory _rewardTokens, uint256[] memory _claimedAmounts); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/morpho-rewards/main.sol b/contracts/mainnet/connectors/morpho-rewards/main.sol index f096c6e4..e7658b5f 100644 --- a/contracts/mainnet/connectors/morpho-rewards/main.sol +++ b/contracts/mainnet/connectors/morpho-rewards/main.sol @@ -100,6 +100,36 @@ abstract contract MorphoRewards is Helpers, Events { _setId ); } + + /** + * @dev Claim Underlying Pool Rewards. + * @notice Claims rewards for the given assets. + * @param _poolTokenAddresses The assets to claim rewards from (aToken or variable debt token). + * @param _onBehalf The address for which rewards are claimed and sent to. + */ + function claimAaveV3( + address[] calldata _poolTokenAddresses, + address _onBehalf + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + (address[] memory _rewardTokens, uint256[] memory _claimedAmounts) = MORPHO_AAVE_V3.claimRewards( + _poolTokenAddresses, + _onBehalf + ); + + // setUint(_setId, _amountOfRewards); + + _eventName = "LogClaimedAaveV3(address[],address,address[],uint256[])"; + _eventParam = abi.encode( + _poolTokenAddresses, + _onBehalf, + _rewardTokens, + _claimedAmounts + ); + } } contract ConnectV2MorphoRewards is MorphoRewards { diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 823e7313..16d38f01 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -5,7 +5,7 @@ import { addresses } from "../../../scripts/tests/mainnet/addresses"; import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; -import { ConnectV3MorphoAaveV3__factory, IERC20Minimal__factory } from "../../../typechain"; +import { ConnectV2MorphoAaveV3__factory, IERC20Minimal__factory } from "../../../typechain"; import { parseEther, parseUnits } from "@ethersproject/units"; import { encodeSpells } from "../../../scripts/tests/encodeSpells"; import { dsaMaxValue, tokens } from "../../../scripts/tests/mainnet/tokens"; @@ -72,7 +72,7 @@ describe("Morpho-Aave-v3", function () { ); connector = await deployAndEnableConnector({ connectorName, - contractArtifact: ConnectV3MorphoAaveV3__factory, + contractArtifact: ConnectV2MorphoAaveV3__factory, signer: masterSigner, connectors: instaConnectorsV2, }); @@ -267,7 +267,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "withdraw", - args: [tokens.eth.address, "10000000000000000000", dsaWallet0.address, "0", "0"], // 10 ETH + args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH }, ]; @@ -281,7 +281,10 @@ describe("Morpho-Aave-v3", function () { ); }) - it("Should revert because behalf is different with dsa address", async function () { + it("Should withdraw on behalf of user", async function () { + let ethBala = await ethers.provider.getBalance(user) + let wethBala = await token_weth.balanceOf(user) + const spells = [ { connector: connectorName, @@ -290,9 +293,13 @@ describe("Morpho-Aave-v3", function () { }, ]; - await expect(dsaWallet0 + const tx = await dsaWallet0 .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress())).to.be.revertedWith("cannot convert"); + .cast(...encodeSpells(spells), wallet1.getAddress()); + + await tx.wait(); + ethBala = await ethers.provider.getBalance(user) + wethBala = await token_weth.balanceOf(user) }) @@ -302,7 +309,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "borrow", - args: [tokens.weth.address, "500000000000000000", dsaWallet0.address, "0", "0"], // 0.7 WETH + args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.7 WETH }, ]; @@ -349,7 +356,6 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - console.log("====================", balance.toString(), (await token_weth.balanceOf(dsaWallet0.address)).toString()) expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) .to.be.eq(parseUnits('2', 16)); }) @@ -410,7 +416,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "borrow", - args: [tokens.eth.address, "1000000000000000", dsaWallet0.address, "0", "0"], // 20 USDC + args: [tokens.eth.address, "1000000000000000", "0", "0"], // 20 USDC }, { connector: connectorName, From 92c47b993d22a6eb0dbf7ed52aed7c3ab1030215 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Fri, 23 Jun 2023 05:52:33 -0400 Subject: [PATCH 26/34] fixed minor bug --- contracts/mainnet/connectors/morpho-rewards/helpers.sol | 2 +- contracts/mainnet/connectors/morpho-rewards/main.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-rewards/helpers.sol b/contracts/mainnet/connectors/morpho-rewards/helpers.sol index caa43cf9..f3c3ca9e 100644 --- a/contracts/mainnet/connectors/morpho-rewards/helpers.sol +++ b/contracts/mainnet/connectors/morpho-rewards/helpers.sol @@ -12,7 +12,7 @@ abstract contract Helpers is Basic { IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); IMorphoCoreV3 public constant MORPHO_AAVE_V3 = - IMorphoCoreV3(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); + IMorphoCoreV3(0x33333aea097c193e66081E930c33020272b33333); IMorphoRewardsDistributor public constant MORPHO_REWARDS = IMorphoRewardsDistributor(0x3B14E5C73e0A56D607A8688098326fD4b4292135); diff --git a/contracts/mainnet/connectors/morpho-rewards/main.sol b/contracts/mainnet/connectors/morpho-rewards/main.sol index e7658b5f..d5aba24e 100644 --- a/contracts/mainnet/connectors/morpho-rewards/main.sol +++ b/contracts/mainnet/connectors/morpho-rewards/main.sol @@ -107,7 +107,7 @@ abstract contract MorphoRewards is Helpers, Events { * @param _poolTokenAddresses The assets to claim rewards from (aToken or variable debt token). * @param _onBehalf The address for which rewards are claimed and sent to. */ - function claimAaveV3( + function claimMorphoAaveV3( address[] calldata _poolTokenAddresses, address _onBehalf ) From 7f5044222ef90f42d54051983bfd45cfce70d8dd Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sat, 24 Jun 2023 02:54:10 +0800 Subject: [PATCH 27/34] Minor reward connector updates --- contracts/mainnet/connectors/morpho-rewards/events.sol | 2 +- contracts/mainnet/connectors/morpho-rewards/helpers.sol | 6 +++--- contracts/mainnet/connectors/morpho-rewards/main.sol | 8 +++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-rewards/events.sol b/contracts/mainnet/connectors/morpho-rewards/events.sol index c272dc61..431ce57e 100644 --- a/contracts/mainnet/connectors/morpho-rewards/events.sol +++ b/contracts/mainnet/connectors/morpho-rewards/events.sol @@ -16,7 +16,7 @@ contract Events { uint256 setId ); - event LogClaimedAaveV3( + event LogClaimedMorphoAaveV3( address[] poolTokenAddresses, address onBehalf, address[] rewardTokens, diff --git a/contracts/mainnet/connectors/morpho-rewards/helpers.sol b/contracts/mainnet/connectors/morpho-rewards/helpers.sol index f3c3ca9e..6ede03c8 100644 --- a/contracts/mainnet/connectors/morpho-rewards/helpers.sol +++ b/contracts/mainnet/connectors/morpho-rewards/helpers.sol @@ -11,9 +11,9 @@ abstract contract Helpers is Basic { IMorphoCore public constant MORPHO_AAVE = IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); - IMorphoCoreV3 public constant MORPHO_AAVE_V3 = - IMorphoCoreV3(0x33333aea097c193e66081E930c33020272b33333); - IMorphoRewardsDistributor public constant MORPHO_REWARDS = IMorphoRewardsDistributor(0x3B14E5C73e0A56D607A8688098326fD4b4292135); + + IMorphoCoreV3 public constant MORPHO_AAVE_V3 = + IMorphoCoreV3(0x33333aea097c193e66081E930c33020272b33333); } diff --git a/contracts/mainnet/connectors/morpho-rewards/main.sol b/contracts/mainnet/connectors/morpho-rewards/main.sol index d5aba24e..86cf96c9 100644 --- a/contracts/mainnet/connectors/morpho-rewards/main.sol +++ b/contracts/mainnet/connectors/morpho-rewards/main.sol @@ -102,7 +102,7 @@ abstract contract MorphoRewards is Helpers, Events { } /** - * @dev Claim Underlying Pool Rewards. + * @dev Claims rewards for the given assets from Morpho Aave V3. * @notice Claims rewards for the given assets. * @param _poolTokenAddresses The assets to claim rewards from (aToken or variable debt token). * @param _onBehalf The address for which rewards are claimed and sent to. @@ -120,9 +120,7 @@ abstract contract MorphoRewards is Helpers, Events { _onBehalf ); - // setUint(_setId, _amountOfRewards); - - _eventName = "LogClaimedAaveV3(address[],address,address[],uint256[])"; + _eventName = "LogClaimedMorphoAaveV3(address[],address,address[],uint256[])"; _eventParam = abi.encode( _poolTokenAddresses, _onBehalf, @@ -133,5 +131,5 @@ abstract contract MorphoRewards is Helpers, Events { } contract ConnectV2MorphoRewards is MorphoRewards { - string public constant name = "Morpho-Rewards-v1.0"; + string public constant name = "Morpho-Rewards-v1.1"; } From c50e7e2ec16d448b289deb78d1a8859a8eaf971a Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sat, 24 Jun 2023 04:43:28 +0800 Subject: [PATCH 28/34] Morpho aave v3 updates --- .../connectors/morpho-aave-v3/events.sol | 8 +- .../connectors/morpho-aave-v3/main.sol | 67 ++++++------- test/mainnet/morpho/morpho-aave-v3.test.ts | 99 ++++++++++++++++--- 3 files changed, 124 insertions(+), 50 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol index 456c7f8d..404eb789 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/events.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -101,9 +101,10 @@ contract Events { uint256 setId ); - event LogWithdrawWithMaxIterations( + event LogWithdrawOnBehalfWithMaxIterations( address tokenAddress, uint256 amount, + address onBehalf, address receiver, uint256 maxIteration, uint256 getId, @@ -143,4 +144,9 @@ contract Events { ); event LogApproveManger(address manger, bool isAllowed); + + event LogUpdateMaxIterations( + uint256 oldIterations, + uint256 newIterations + ); } diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index e110dcb9..d614193d 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -291,7 +291,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to borrow. * @param _onBehalf The address of user on behalf to borrow. - * @param _receiver The address of receiver to receive the borrowed tokens. + * @param _receiver The address of receiver to receive the borrowed tokens. + Note that if receiver is not the same as the borrower, receiver will receive WETH instead of ETH. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens borrowed. */ @@ -313,7 +314,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); - if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(wethAddr), _amt); + if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _amt); setUint(_setId, _amt); @@ -334,6 +335,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to borrow. * @param _receiver The address of receiver to receive the borrowed tokens. + Note that if receiver is not the same as the borrower, receiver will receive WETH instead of ETH. * @param _maxIteration The maximum number of iterations to be used for borrow. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens borrowed. @@ -376,6 +378,10 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @notice Borrow a token from Morpho Aave. * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to borrow. + * @param _onBehalf The address of user on behalf to borrow. + * @param _receiver The address of receiver to receive the borrowed tokens. + Note that if receiver is not the same as the borrower, receiver will receive WETH instead of ETH. + * @param _maxIteration The maximum number of iterations to be used for borrow. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens borrowed. */ @@ -459,6 +465,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) * @param _onBehalf Address for which tokens are being withdrawn. * @param _receiver Address to which tokens are being transferred. + Note that if receiver is not the same as the supplier, receiver will receive WETH instead of ETH. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. */ @@ -503,11 +510,12 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) * @param _onBehalf Address for which tokens are being withdrawn. * @param _receiver Address to which tokens are being transferred. + Note that if receiver is not the same as the supplier, receiver will receive WETH instead of ETH. * @param _maxIteration Max number of iterations to run. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. */ - function withdrawWithMaxIterations( + function withdrawOnBehalfWithMaxIterations( address _tokenAddress, uint256 _amount, address _onBehalf, @@ -531,10 +539,11 @@ abstract contract MorphoAaveV3 is Helpers, Events { setUint(_setId, _amt); - _eventName = "LogWithdrawWithMaxIterations(address,uint256,address,uint256,uint256,uint256)"; + _eventName = "LogWithdrawOnBehalfWithMaxIterations(address,uint256,address,address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _amt, + _onBehalf, _receiver, _maxIteration, _getId, @@ -548,6 +557,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) * @param _receiver Address to which tokens are being transferred. + Note that if receiver is not the same as the supplier, receiver will receive WETH instead of ETH. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. */ @@ -589,6 +599,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { * @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`) * @param _onBehalf Address for which tokens are being withdrawn. * @param _receiver Address to which tokens are being transferred. + Note that if receiver is not the same as the supplier, receiver will receive WETH instead of ETH. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. */ @@ -643,20 +654,10 @@ abstract contract MorphoAaveV3 is Helpers, Events { payable returns (string memory _eventName, bytes memory _eventParam) { - bool _isETH = _tokenAddress == ethAddr; - uint256 _amt = getUint(_getId, _amount); - - TokenInterface _tokenContract = _isETH - ? TokenInterface(wethAddr) - : TokenInterface(_tokenAddress); - - if (_amt == uint256(-1)) { - _amt = _isETH - ? address(this).balance - : _tokenContract.balanceOf(address(this)); - } - - convertEthToWeth(_isETH, _tokenContract, _amt); + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); @@ -693,20 +694,10 @@ abstract contract MorphoAaveV3 is Helpers, Events { payable returns (string memory _eventName, bytes memory _eventParam) { - bool _isETH = _tokenAddress == ethAddr; - uint256 _amt = getUint(_getId, _amount); - - TokenInterface _tokenContract = _isETH - ? TokenInterface(wethAddr) - : TokenInterface(_tokenAddress); - - if (_amt == uint256(-1)) { - _amt = _isETH - ? address(this).balance - : _tokenContract.balanceOf(address(this)); - } - - convertEthToWeth(_isETH, _tokenContract, _amt); + ( + TokenInterface _tokenContract, + uint256 _amt + ) = _performEthToWethConversion(_tokenAddress, _amount, _getId); approve(_tokenContract, address(MORPHO_AAVE_V3), _amt); @@ -742,8 +733,18 @@ abstract contract MorphoAaveV3 is Helpers, Events { /// @notice Updates the max iterations for a `repay` or a `withdraw`. /// @param _iterations New iteration count. - function updateMaxIterations(uint256 _iterations) external { + function updateMaxIterations(uint256 _iterations) + external + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _oldIterations = max_iteration; max_iteration = _iterations; + + _eventName = "LogUpdateMaxIterations(uint256,uint256)"; + _eventParam = abi.encode( + _oldIterations, + max_iteration + ); } } diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 16d38f01..715df2e4 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -59,7 +59,7 @@ describe("Morpho-Aave-v3", function () { forking: { // @ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - // blockNumber: 15714501, + blockNumber: 17544460, }, }, ], @@ -224,7 +224,7 @@ describe("Morpho-Aave-v3", function () { ); }) - it("Should deposit 2000 USDC as collateral", async function () { + it("Should deposit collateral 2000 USDC", async function () { const spells = [ { connector: connectorName, @@ -243,12 +243,12 @@ describe("Morpho-Aave-v3", function () { ); }) - it("Should deposit 2000 USDC as collateral on behalf", async function () { + it("Should deposit collateral 2000 USDC on behalf with maxValue", async function () { const spells = [ { connector: connectorName, method: "depositCollateralOnBehalf", - args: [tokens.usdc.address, "2000000000", user, "0", "0"], // 50 USDC + args: [tokens.usdc.address, dsaMaxValue, user, "0", "0"], // ~3000 USDC }, ]; @@ -258,7 +258,7 @@ describe("Morpho-Aave-v3", function () { await tx.wait(); expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('1000', 6) + parseUnits('1', 6) ); }) @@ -281,7 +281,7 @@ describe("Morpho-Aave-v3", function () { ); }) - it("Should withdraw on behalf of user", async function () { + it("Should withdraw on behalf of user with maxValue", async function () { let ethBala = await ethers.provider.getBalance(user) let wethBala = await token_weth.balanceOf(user) @@ -309,7 +309,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "borrow", - args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.7 WETH + args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.5 WETH }, ]; @@ -347,7 +347,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "borrowWithMaxIterations", - args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.7 WETH + args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.02 WETH }, ]; @@ -361,7 +361,26 @@ describe("Morpho-Aave-v3", function () { }) it("Test withdrawCollateral ", async function () { - const balance = await token_weth.balanceOf(dsaWallet0.address); + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [ACC_USDC], + }) + + const signer_usdc = await ethers.getSigner(ACC_USDC) + await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) + + await hre.network.provider.request({ + method: 'hardhat_stopImpersonatingAccount', + params: [ACC_USDC], + }) + + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('500', 6) + ); + + const balance = await token_usdc.balanceOf(dsaWallet0.address); + console.log('balance: ', balance.toString()); + const spells = [ { connector: connectorName, @@ -371,7 +390,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "withdrawCollateral", - args: [tokens.usdc.address, "20000000", dsaWallet0.address, "0", "0"], // 20 USDC + args: [tokens.usdc.address, "19000000", dsaWallet0.address, "0", "0"], // 19 USDC }, ]; @@ -383,8 +402,26 @@ describe("Morpho-Aave-v3", function () { }) - it("Test withdrawCollateralOnBehalf ", async function () { - const balance = await token_weth.balanceOf(dsaWallet0.address); + it("Test withdrawCollateralOnBehalf with maxValue", async function () { + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [ACC_USDC], + }) + + const signer_usdc = await ethers.getSigner(ACC_USDC) + await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) + + await hre.network.provider.request({ + method: 'hardhat_stopImpersonatingAccount', + params: [ACC_USDC], + }) + + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('500', 6) + ); + + const balance = await token_usdc.balanceOf(dsaWallet0.address); + const spells = [ { connector: connectorName, @@ -394,7 +431,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "withdrawCollateralOnBehalf", - args: [tokens.usdc.address, "20000000", dsaWallet0.address, user, "0", "0"], // 20 USDC + args: [tokens.usdc.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // 20 USDC }, ]; @@ -404,9 +441,36 @@ describe("Morpho-Aave-v3", function () { await tx.wait(); + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('499', 6) + ); }) - it("Test payback ", async function () { + it("Test payback with maxValue", async function () { + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [ACC_USDC], + }) + + await hre.network.provider.request({ + method: 'hardhat_setBalance', + params: [dsaWallet0.address, "1000000000000000000"], + }) + + const signer_usdc = await ethers.getSigner(ACC_USDC) + await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) + + await hre.network.provider.request({ + method: 'hardhat_stopImpersonatingAccount', + params: [ACC_USDC], + }) + + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('500', 6) + ); + + const balance = await token_usdc.balanceOf(dsaWallet0.address); + const spells = [ { connector: connectorName, @@ -421,7 +485,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "payback", - args: [tokens.eth.address, "1000000000000000", "0", "0"], // 20 USDC + args: [tokens.eth.address, dsaMaxValue, "0", "0"], // 20 USDC }, ]; @@ -431,6 +495,9 @@ describe("Morpho-Aave-v3", function () { await tx.wait(); + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('499', 6) + ); }) it("approve manger", async () => { @@ -438,7 +505,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "approveManager", - args: [user, true], // 2 ETH + args: [user, true], }, ] const tx = await dsaWallet0 From b7002335b7de9743e5319244e27199db0541a29b Mon Sep 17 00:00:00 2001 From: q1q0 Date: Sun, 25 Jun 2023 03:46:38 -0400 Subject: [PATCH 29/34] fixed some bugs and update test script --- .../connectors/morpho-aave-v3/main.sol | 74 +- test/mainnet/morpho/morpho-aave-v3.test.ts | 596 ++++++------ test/mainnet/morpho/morpho-abi.json | 876 ++++++++++++++++++ 3 files changed, 1210 insertions(+), 336 deletions(-) create mode 100644 test/mainnet/morpho/morpho-abi.json diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index d614193d..381cbac9 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -4,6 +4,8 @@ pragma experimental ABIEncoderV2; import "./helpers.sol"; import "./events.sol"; +import "hardhat/console.sol"; + abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Deposit ETH/ERC20_Token. @@ -270,16 +272,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isETH = _tokenAddress == ethAddr; address _token = _isETH ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.borrow(_token, _amt, address(this), address(this), max_iteration); + uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, address(this), address(this), max_iteration); - convertWethToEth(_isETH, TokenInterface(_token), _amt); + convertWethToEth(_isETH, TokenInterface(_token), _borrowed); - setUint(_setId, _amt); + setUint(_setId, _borrowed); _eventName = "LogBorrow(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _borrowed, _getId, _setId ); @@ -312,16 +314,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isETH = _tokenAddress == ethAddr; address _token = _isETH ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); + uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); - if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _amt); + if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _borrowed); - setUint(_setId, _amt); + setUint(_setId, _borrowed); _eventName = "LogBorrowOnBehalf(address,uint256,addresss,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _borrowed, _onBehalf, _receiver, _getId, @@ -356,16 +358,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isETH = _tokenAddress == ethAddr; address _token = _isETH ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); + uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); - if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _amt); + if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _borrowed); - setUint(_setId, _amt); + setUint(_setId, _borrowed); _eventName = "LogBorrowWithMaxIterations(address,uint256,addresss,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _borrowed, _receiver, _maxIteration, _getId, @@ -402,16 +404,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isETH = _tokenAddress == ethAddr; address _token = _isETH ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, _maxIteration); + uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, _maxIteration); - if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _amt); + if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _borrowed); - setUint(_setId, _amt); + setUint(_setId, _borrowed); _eventName = "LogBorrowOnBehalfWithMaxIterations(address,uint256,addresss,address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _borrowed, _onBehalf, _receiver, _maxIteration, @@ -443,16 +445,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _isEth? wethAddr : _tokenAddress; // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. - MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), address(this), max_iteration); + uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), address(this), max_iteration); - convertWethToEth(_isEth, TokenInterface(_token), _amt); + convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); - setUint(_setId, _amt); + setUint(_setId, _withdrawn); _eventName = "LogWithdraw(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _withdrawn, _getId, _setId ); @@ -486,16 +488,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _isEth ? wethAddr : _tokenAddress; // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. - MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, max_iteration); + uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, max_iteration); - if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); - setUint(_setId, _amt); + setUint(_setId, _withdrawn); _eventName = "LogWithdrawOnBehalf(address,uint256,address,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _withdrawn, _onBehalf, _receiver, _getId, @@ -533,16 +535,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { address _token = _isEth ? wethAddr : _tokenAddress; // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. - MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, _maxIteration); + uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, _maxIteration); - if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); - setUint(_setId, _amt); + setUint(_setId, _withdrawn); _eventName = "LogWithdrawOnBehalfWithMaxIterations(address,uint256,address,address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _withdrawn, _onBehalf, _receiver, _maxIteration, @@ -576,16 +578,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isEth = _tokenAddress == ethAddr; address _token = _isEth ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), _receiver); + uint256 _withdrawn = MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), _receiver); - if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); - setUint(_setId, _amt); + setUint(_setId, _withdrawn); _eventName = "LogWithdrawCollateral(address,uint256,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _withdrawn, _receiver, _getId, _setId @@ -619,16 +621,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isEth = _tokenAddress == ethAddr; address _token = _isEth ? wethAddr : _tokenAddress; - MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, _onBehalf, _receiver); + uint256 _withdrawn = MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, _onBehalf, _receiver); - if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _amt); + if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); - setUint(_setId, _amt); + setUint(_setId, _withdrawn); _eventName = "LogWithdrawCollateralOnBehalf(address,uint256,address,address,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, - _amt, + _withdrawn, _onBehalf, _receiver, _getId, diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 715df2e4..4ac8a806 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -9,44 +9,34 @@ import { ConnectV2MorphoAaveV3__factory, IERC20Minimal__factory } from "../../.. import { parseEther, parseUnits } from "@ethersproject/units"; import { encodeSpells } from "../../../scripts/tests/encodeSpells"; import { dsaMaxValue, tokens } from "../../../scripts/tests/mainnet/tokens"; +import morpho_ABI from './morpho-abi.json' + const { ethers } = hre; import type { Signer, Contract } from "ethers"; -const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' -const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0' -const Usdc = parseUnits('5000', 6) +const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; +const ACC_USDC = "0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0"; +const Usdc = parseUnits("5000", 6); -const DAI = '0x6b175474e89094c44da98b954eedeac495271d0f' -const ACC_DAI = '0xcd6Eb888e76450eF584E8B51bB73c76ffBa21FF2' -const Dai = parseUnits('1', 18) +const DAI = "0x6b175474e89094c44da98b954eedeac495271d0f"; +const ACC_DAI = "0xcd6Eb888e76450eF584E8B51bB73c76ffBa21FF2"; +const Dai = parseUnits("1", 18); -const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' +const WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; -const user = "0x41bc7d0687e6cea57fa26da78379dfdc5627c56d" +const user = "0x41bc7d0687e6cea57fa26da78379dfdc5627c56d"; -const token_usdc = new ethers.Contract( - USDC, - IERC20Minimal__factory.abi, - ethers.provider, -) +const token_usdc = new ethers.Contract(USDC, IERC20Minimal__factory.abi, ethers.provider); -const token_dai = new ethers.Contract( - DAI, - IERC20Minimal__factory.abi, - ethers.provider, -) +const token_dai = new ethers.Contract(DAI, IERC20Minimal__factory.abi, ethers.provider); -const token_weth = new ethers.Contract( - WETH, - IERC20Minimal__factory.abi, - ethers.provider, -) +const token_weth = new ethers.Contract(WETH, IERC20Minimal__factory.abi, ethers.provider); describe("Morpho-Aave-v3", function () { const connectorName = "MORPHO-AAVE-V3-TEST-A"; let connector: any; - let wallet0: Signer, wallet1:Signer; + let wallet0: Signer, wallet1: Signer; let dsaWallet0: any; let instaConnectorsV2: Contract; let masterSigner: Signer; @@ -59,22 +49,19 @@ describe("Morpho-Aave-v3", function () { forking: { // @ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 17544460, - }, - }, - ], + blockNumber: 17544460 + } + } + ] }); [wallet0, wallet1] = await ethers.getSigners(); masterSigner = await getMasterSigner(); - instaConnectorsV2 = await ethers.getContractAt( - abis.core.connectorsV2, - addresses.core.connectorsV2 - ); + instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); connector = await deployAndEnableConnector({ connectorName, contractArtifact: ConnectV2MorphoAaveV3__factory, signer: masterSigner, - connectors: instaConnectorsV2, + connectors: instaConnectorsV2 }); console.log("Connector address", connector.address); }); @@ -94,33 +81,28 @@ describe("Morpho-Aave-v3", function () { it("Deposit 1000 ETH into DSA wallet", async function () { await wallet0.sendTransaction({ to: dsaWallet0.address, - value: parseEther("1000"), + value: parseEther("1000") }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( - parseEther("1000") - ); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(parseEther("1000")); }); it("Deposit 5000 USDC into DSA wallet", async function () { + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [ACC_USDC] + }); + + const signer_usdc = await ethers.getSigner(ACC_USDC); + await token_usdc.connect(signer_usdc).transfer(wallet0.getAddress(), Usdc); await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [ACC_USDC], - }) - - const signer_usdc = await ethers.getSigner(ACC_USDC) - await token_usdc.connect(signer_usdc).transfer(wallet0.getAddress(), Usdc) - - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [ACC_USDC], - }) + method: "hardhat_stopImpersonatingAccount", + params: [ACC_USDC] + }); await token_usdc.connect(wallet0).transfer(dsaWallet0.address, Usdc); - expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - parseUnits('5000', 6) - ); + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("5000", 6)); }); // it("Deposit 1 DAI into DSA wallet", async function () { @@ -147,304 +129,323 @@ describe("Morpho-Aave-v3", function () { }); describe("Main", function () { + // it("Should deposit 10 ETH", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "deposit", + // args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH + // }, + // ]; - it("Should deposit 10 ETH", async function () { - const spells = [ - { - connector: connectorName, - method: "deposit", - args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // await tx.wait(); + // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + // parseUnits('990', 18)) + // ); + // }) - await tx.wait(); - expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - parseUnits('990', 18)) - ); - }) + // it("Should deposit 1 ETH with MaxIteration", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "depositWithMaxIterations", + // args: [tokens.eth.address, "1000000000000000000", 5, "0", "0"], // 1 ETH + // }, + // ]; - it("Should deposit 1 ETH with MaxIteration", async function () { - const spells = [ - { - connector: connectorName, - method: "depositWithMaxIterations", - args: [tokens.eth.address, "1000000000000000000", 5, "0", "0"], // 1 ETH - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // await tx.wait(); + // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + // parseUnits('989', 18)) + // ); + // }) - await tx.wait(); - expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - parseUnits('989', 18)) - ); - }) + // it("Should deposit 10 ETH on behalf", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "depositOnBehalf", + // args: [tokens.eth.address, "10000000000000000000", user, "0", "0"], // 1 ETH + // }, + // ]; - it("Should deposit 10 ETH on behalf", async function () { - const spells = [ - { - connector: connectorName, - method: "depositOnBehalf", - args: [tokens.eth.address, "10000000000000000000", user, "0", "0"], // 1 ETH - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // await tx.wait(); + // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + // parseUnits('979', 18)) + // ); + // }) - await tx.wait(); - expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - parseUnits('979', 18)) - ); - }) + // it("Should deposit 1 ETH on behalf with MaxIteration", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "depositOnBehalfWithMaxIterations", + // args: [tokens.eth.address, "1000000000000000000", user, 5, "0", "0"], // 1 ETH + // }, + // ]; - it("Should deposit 1 ETH on behalf with MaxIteration", async function () { - const spells = [ - { - connector: connectorName, - method: "depositOnBehalfWithMaxIterations", - args: [tokens.eth.address, "1000000000000000000", user, 5, "0", "0"], // 1 ETH - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // await tx.wait(); + // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + // parseUnits('978', 18)) + // ); + // }) - await tx.wait(); - expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - parseUnits('978', 18)) - ); - }) + // it("Should deposit collateral 2000 USDC", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "depositCollateral", + // args: [tokens.usdc.address, "2000000000", "0", "0"], // 50 USDC + // }, + // ]; - it("Should deposit collateral 2000 USDC", async function () { - const spells = [ - { - connector: connectorName, - method: "depositCollateral", - args: [tokens.usdc.address, "2000000000", "0", "0"], // 50 USDC - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // await tx.wait(); + // expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + // parseUnits('3000', 6) + // ); + // }) - await tx.wait(); - expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('3000', 6) - ); - }) + // it("Should deposit collateral 2000 USDC on behalf with maxValue", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "depositCollateralOnBehalf", + // args: [tokens.usdc.address, dsaMaxValue, user, "0", "0"], // ~3000 USDC + // }, + // ]; - it("Should deposit collateral 2000 USDC on behalf with maxValue", async function () { - const spells = [ - { - connector: connectorName, - method: "depositCollateralOnBehalf", - args: [tokens.usdc.address, dsaMaxValue, user, "0", "0"], // ~3000 USDC - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // await tx.wait(); + // expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + // parseUnits('1', 6) + // ); + // }) - await tx.wait(); - expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - parseUnits('1', 6) - ); - }) + // it("Should withdraw 10 ETH", async function () { + // const spells = [ + // { + // connector: connectorName, + // method: "withdraw", + // args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH + // }, + // ]; - it("Should withdraw 10 ETH", async function () { - const spells = [ - { - connector: connectorName, - method: "withdraw", - args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // await tx.wait(); + // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + // parseUnits('978', 18)) + // ); + // }) - await tx.wait(); - expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( - parseUnits('978', 18)) - ); - }) + // it("Should withdraw on behalf of user with maxValue", async function () { + // let ethBala = await ethers.provider.getBalance(user) + // let wethBala = await token_weth.balanceOf(user) - it("Should withdraw on behalf of user with maxValue", async function () { - let ethBala = await ethers.provider.getBalance(user) - let wethBala = await token_weth.balanceOf(user) + // const spells = [ + // { + // connector: connectorName, + // method: "withdrawOnBehalf", + // args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // Max ETH + // }, + // ]; - const spells = [ - { - connector: connectorName, - method: "withdrawOnBehalf", - args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // Max ETH - }, - ]; + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); - - await tx.wait(); - ethBala = await ethers.provider.getBalance(user) - wethBala = await token_weth.balanceOf(user) + // await tx.wait(); + // ethBala = await ethers.provider.getBalance(user) + // wethBala = await token_weth.balanceOf(user) - }) + // }) - it("Should borrow WETH into DSA", async function () { - const balance = await token_weth.balanceOf(dsaWallet0.address); - const spells = [ - { - connector: connectorName, - method: "borrow", - args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.5 WETH - }, - ]; + // it("Should borrow WETH into DSA", async function () { + // const balance = await token_weth.balanceOf(dsaWallet0.address); + // const spells = [ + // { + // connector: connectorName, + // method: "borrow", + // args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.5 WETH + // }, + // ]; - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - await tx.wait(); - expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) - .to.be.eq(parseUnits('5', 17)); - }) + // await tx.wait(); + // expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) + // .to.be.eq(parseUnits('5', 17)); + // }) - it("Should borrow WETH into user", async function () { - const balance = await token_weth.balanceOf(user); - const spells = [ - { - connector: connectorName, - method: "borrowOnBehalf", - args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH - }, - ]; + // it("Should borrow WETH into user", async function () { + // const balance = await token_weth.balanceOf(user); + // const spells = [ + // { + // connector: connectorName, + // method: "borrowOnBehalf", + // args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH + // }, + // ]; - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - await tx.wait(); - expect((await token_weth.balanceOf(user)).sub(balance)) - .to.be.eq(parseUnits('2', 17)); - }) + // await tx.wait(); + // expect((await token_weth.balanceOf(user)).sub(balance)) + // .to.be.eq(parseUnits('2', 17)); + // }) - it("Should borrow WETH into wallet1 using iteration", async function () { - const balance = await token_weth.balanceOf(dsaWallet0.address); - const spells = [ - { - connector: connectorName, - method: "borrowWithMaxIterations", - args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.02 WETH - }, - ]; + // it("Should borrow WETH into wallet1 using iteration", async function () { + // const balance = await token_weth.balanceOf(dsaWallet0.address); + // const spells = [ + // { + // connector: connectorName, + // method: "borrowWithMaxIterations", + // args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.02 WETH + // }, + // ]; - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - await tx.wait(); - expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) - .to.be.eq(parseUnits('2', 16)); - }) + // await tx.wait(); + // expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) + // .to.be.eq(parseUnits('2', 16)); + // }) - it("Test withdrawCollateral ", async function () { - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [ACC_USDC], - }) + // it("Test withdrawCollateral ", async function () { + // await hre.network.provider.request({ + // method: 'hardhat_impersonateAccount', + // params: [ACC_USDC], + // }) - const signer_usdc = await ethers.getSigner(ACC_USDC) - await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) + // const signer_usdc = await ethers.getSigner(ACC_USDC) + // await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [ACC_USDC], - }) + // await hre.network.provider.request({ + // method: 'hardhat_stopImpersonatingAccount', + // params: [ACC_USDC], + // }) - expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - parseUnits('500', 6) - ); + // expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + // parseUnits('500', 6) + // ); - const balance = await token_usdc.balanceOf(dsaWallet0.address); - console.log('balance: ', balance.toString()); + // const balance = await token_usdc.balanceOf(dsaWallet0.address); + // console.log('balance: ', balance.toString()); - const spells = [ - { - connector: connectorName, - method: "depositCollateral", - args: [tokens.usdc.address, "20000000", "0", "0"], // 20 USDC - }, - { - connector: connectorName, - method: "withdrawCollateral", - args: [tokens.usdc.address, "19000000", dsaWallet0.address, "0", "0"], // 19 USDC - }, - ]; + // const spells = [ + // { + // connector: connectorName, + // method: "depositCollateral", + // args: [tokens.usdc.address, "20000000", "0", "0"], // 20 USDC + // }, + // { + // connector: connectorName, + // method: "withdrawCollateral", + // args: [tokens.usdc.address, "19000000", dsaWallet0.address, "0", "0"], // 19 USDC + // }, + // ]; - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - await tx.wait(); + // await tx.wait(); - }) + // }) it("Test withdrawCollateralOnBehalf with maxValue", async function () { await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [ACC_USDC], - }) + method: "hardhat_impersonateAccount", + params: [ACC_USDC] + }); - const signer_usdc = await ethers.getSigner(ACC_USDC) - await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) + const signer_usdc = await ethers.getSigner(ACC_USDC); + await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits("500", 6)); await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [ACC_USDC], - }) + method: "hardhat_stopImpersonatingAccount", + params: [ACC_USDC] + }); - expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - parseUnits('500', 6) + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [user] + }); + + const signer_user = await ethers.getSigner(user); + + const mophor = new ethers.Contract( + "0x33333aea097c193e66081E930c33020272b33333", + morpho_ABI, + ethers.provider ); + await mophor.connect(signer_user).approveManager(dsaWallet0.address, true) + + await hre.network.provider.request({ + method: "hardhat_stopImpersonatingAccount", + params: [user] + }); + + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("500", 6)); + const balance = await token_usdc.balanceOf(dsaWallet0.address); const spells = [ { connector: connectorName, method: "depositCollateralOnBehalf", - args: [tokens.usdc.address, "20000000", user, "0", "0"], // 20 USDC + args: [tokens.usdc.address, "20000000", user, "0", "0"] // 20 USDC }, + // { + // connector: connectorName, + // method: "approveManager", + // args: [user, true] // 20 USDC + // }, { connector: connectorName, method: "withdrawCollateralOnBehalf", - args: [tokens.usdc.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // 20 USDC - }, + args: [tokens.usdc.address, dsaMaxValue, user, user, "0", "0"] // 20 USDC + } ]; - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - parseUnits('499', 6) - ); - }) + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("499", 6)); + + }); it("Test payback with maxValue", async function () { await hre.network.provider.request({ @@ -452,11 +453,6 @@ describe("Morpho-Aave-v3", function () { params: [ACC_USDC], }) - await hre.network.provider.request({ - method: 'hardhat_setBalance', - params: [dsaWallet0.address, "1000000000000000000"], - }) - const signer_usdc = await ethers.getSigner(ACC_USDC) await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) @@ -500,19 +496,19 @@ describe("Morpho-Aave-v3", function () { ); }) - it("approve manger", async () => { - const spells = [ - { - connector: connectorName, - method: "approveManager", - args: [user, true], - }, - ] - const tx = await dsaWallet0 - .connect(wallet0) - .cast(...encodeSpells(spells), wallet1.getAddress()); + // it("approve manger", async () => { + // const spells = [ + // { + // connector: connectorName, + // method: "approveManager", + // args: [user, true], + // }, + // ] + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); - await tx.wait(); - }) + // await tx.wait(); + // }) }); }); diff --git a/test/mainnet/morpho/morpho-abi.json b/test/mainnet/morpho/morpho-abi.json new file mode 100644 index 00000000..843f6b44 --- /dev/null +++ b/test/mainnet/morpho/morpho-abi.json @@ -0,0 +1,876 @@ +[ + { "inputs": [], "name": "AddressIsZero", "type": "error" }, + { "inputs": [], "name": "AmountIsZero", "type": "error" }, + { "inputs": [], "name": "AssetIsCollateralOnMorpho", "type": "error" }, + { "inputs": [], "name": "AssetNotCollateralOnPool", "type": "error" }, + { "inputs": [], "name": "BorrowNotPaused", "type": "error" }, + { "inputs": [], "name": "ClaimRewardsPaused", "type": "error" }, + { "inputs": [], "name": "ExceedsMaxBasisPoints", "type": "error" }, + { "inputs": [], "name": "InvalidNonce", "type": "error" }, + { "inputs": [], "name": "InvalidSignatory", "type": "error" }, + { "inputs": [], "name": "InvalidValueS", "type": "error" }, + { "inputs": [], "name": "InvalidValueV", "type": "error" }, + { "inputs": [], "name": "MarketAlreadyCreated", "type": "error" }, + { "inputs": [], "name": "MarketIsDeprecated", "type": "error" }, + { "inputs": [], "name": "MarketIsNotListedOnAave", "type": "error" }, + { "inputs": [], "name": "MarketLtTooLow", "type": "error" }, + { "inputs": [], "name": "MarketNotCreated", "type": "error" }, + { "inputs": [], "name": "SetAsCollateralOnPoolButMarketNotCreated", "type": "error" }, + { "inputs": [], "name": "SignatureExpired", "type": "error" }, + { "inputs": [], "name": "SiloedBorrowMarket", "type": "error" }, + { "inputs": [], "name": "UnsafeCast", "type": "error" }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint8", "name": "version", "type": "uint8" }], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "acceptOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "addressesProvider", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "manager", "type": "address" }, + { "internalType": "bool", "name": "isAllowed", "type": "bool" } + ], + "name": "approveManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "delegator", "type": "address" }, + { "internalType": "address", "name": "manager", "type": "address" }, + { "internalType": "bool", "name": "isAllowed", "type": "bool" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { + "components": [ + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct Types.Signature", + "name": "signature", + "type": "tuple" + } + ], + "name": "approveManagerWithSig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "maxIterations", "type": "uint256" } + ], + "name": "borrow", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "borrowBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "assets", "type": "address[]" }, + { "internalType": "address", "name": "onBehalf", "type": "address" } + ], + "name": "claimRewards", + "outputs": [ + { "internalType": "address[]", "name": "rewardTokens", "type": "address[]" }, + { "internalType": "uint256[]", "name": "claimedAmounts", "type": "uint256[]" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "underlyings", "type": "address[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" } + ], + "name": "claimToTreasury", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "collateralBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint16", "name": "reserveFactor", "type": "uint16" }, + { "internalType": "uint16", "name": "p2pIndexCursor", "type": "uint16" } + ], + "name": "createMarket", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "defaultIterations", + "outputs": [ + { + "components": [ + { "internalType": "uint128", "name": "repay", "type": "uint128" }, + { "internalType": "uint128", "name": "withdraw", "type": "uint128" } + ], + "internalType": "struct Types.Iterations", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "eModeCategoryId", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "enum Types.Position", "name": "position", "type": "uint8" } + ], + "name": "getBucketsMask", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "enum Types.Position", "name": "position", "type": "uint8" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "getNext", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "increaseP2PDeltas", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "addressesProvider", "type": "address" }, + { "internalType": "uint8", "name": "eModeCategoryId", "type": "uint8" }, + { "internalType": "address", "name": "positionsManager", "type": "address" }, + { + "components": [ + { "internalType": "uint128", "name": "repay", "type": "uint128" }, + { "internalType": "uint128", "name": "withdraw", "type": "uint128" } + ], + "internalType": "struct Types.Iterations", + "name": "defaultIterations", + "type": "tuple" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "isClaimRewardsPaused", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "delegator", "type": "address" }, + { "internalType": "address", "name": "manager", "type": "address" } + ], + "name": "isManagedBy", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlyingBorrowed", "type": "address" }, + { "internalType": "address", "name": "underlyingCollateral", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "liquidate", + "outputs": [ + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "uint256", "name": "", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "liquidityData", + "outputs": [ + { + "components": [ + { "internalType": "uint256", "name": "borrowable", "type": "uint256" }, + { "internalType": "uint256", "name": "maxDebt", "type": "uint256" }, + { "internalType": "uint256", "name": "debt", "type": "uint256" } + ], + "internalType": "struct Types.LiquidityData", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "underlying", "type": "address" }], + "name": "market", + "outputs": [ + { + "components": [ + { + "components": [ + { + "components": [ + { "internalType": "uint128", "name": "poolIndex", "type": "uint128" }, + { "internalType": "uint128", "name": "p2pIndex", "type": "uint128" } + ], + "internalType": "struct Types.MarketSideIndexes", + "name": "supply", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint128", "name": "poolIndex", "type": "uint128" }, + { "internalType": "uint128", "name": "p2pIndex", "type": "uint128" } + ], + "internalType": "struct Types.MarketSideIndexes", + "name": "borrow", + "type": "tuple" + } + ], + "internalType": "struct Types.Indexes", + "name": "indexes", + "type": "tuple" + }, + { + "components": [ + { + "components": [ + { "internalType": "uint256", "name": "scaledDelta", "type": "uint256" }, + { "internalType": "uint256", "name": "scaledP2PTotal", "type": "uint256" } + ], + "internalType": "struct Types.MarketSideDelta", + "name": "supply", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "scaledDelta", "type": "uint256" }, + { "internalType": "uint256", "name": "scaledP2PTotal", "type": "uint256" } + ], + "internalType": "struct Types.MarketSideDelta", + "name": "borrow", + "type": "tuple" + } + ], + "internalType": "struct Types.Deltas", + "name": "deltas", + "type": "tuple" + }, + { "internalType": "address", "name": "underlying", "type": "address" }, + { + "components": [ + { "internalType": "bool", "name": "isP2PDisabled", "type": "bool" }, + { "internalType": "bool", "name": "isSupplyPaused", "type": "bool" }, + { "internalType": "bool", "name": "isSupplyCollateralPaused", "type": "bool" }, + { "internalType": "bool", "name": "isBorrowPaused", "type": "bool" }, + { "internalType": "bool", "name": "isWithdrawPaused", "type": "bool" }, + { "internalType": "bool", "name": "isWithdrawCollateralPaused", "type": "bool" }, + { "internalType": "bool", "name": "isRepayPaused", "type": "bool" }, + { "internalType": "bool", "name": "isLiquidateCollateralPaused", "type": "bool" }, + { "internalType": "bool", "name": "isLiquidateBorrowPaused", "type": "bool" }, + { "internalType": "bool", "name": "isDeprecated", "type": "bool" } + ], + "internalType": "struct Types.PauseStatuses", + "name": "pauseStatuses", + "type": "tuple" + }, + { "internalType": "bool", "name": "isCollateral", "type": "bool" }, + { "internalType": "address", "name": "variableDebtToken", "type": "address" }, + { "internalType": "uint32", "name": "lastUpdateTimestamp", "type": "uint32" }, + { "internalType": "uint16", "name": "reserveFactor", "type": "uint16" }, + { "internalType": "uint16", "name": "p2pIndexCursor", "type": "uint16" }, + { "internalType": "address", "name": "aToken", "type": "address" }, + { "internalType": "address", "name": "stableDebtToken", "type": "address" }, + { "internalType": "uint256", "name": "idleSupply", "type": "uint256" } + ], + "internalType": "struct Types.Market", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "marketsCreated", + "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pool", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "positionsManager", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" } + ], + "name": "repay", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { + "components": [ + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct Types.Signature", + "name": "signature", + "type": "tuple" + } + ], + "name": "repayWithPermit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "rewardsManager", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "scaledCollateralBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "scaledP2PBorrowBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "scaledP2PSupplyBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "scaledPoolBorrowBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "scaledPoolSupplyBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isCollateral", "type": "bool" } + ], + "name": "setAssetIsCollateral", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isCollateral", "type": "bool" } + ], + "name": "setAssetIsCollateralOnPool", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint128", "name": "repay", "type": "uint128" }, + { "internalType": "uint128", "name": "withdraw", "type": "uint128" } + ], + "internalType": "struct Types.Iterations", + "name": "defaultIterations", + "type": "tuple" + } + ], + "name": "setDefaultIterations", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsBorrowPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bool", "name": "isPaused", "type": "bool" }], + "name": "setIsClaimRewardsPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isDeprecated", "type": "bool" } + ], + "name": "setIsDeprecated", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsLiquidateBorrowPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsLiquidateCollateralPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isP2PDisabled", "type": "bool" } + ], + "name": "setIsP2PDisabled", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bool", "name": "isPaused", "type": "bool" }], + "name": "setIsPausedForAllMarkets", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsRepayPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsSupplyCollateralPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsSupplyPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsWithdrawCollateralPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "bool", "name": "isPaused", "type": "bool" } + ], + "name": "setIsWithdrawPaused", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint16", "name": "p2pIndexCursor", "type": "uint16" } + ], + "name": "setP2PIndexCursor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "positionsManager", "type": "address" }], + "name": "setPositionsManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint16", "name": "newReserveFactor", "type": "uint16" } + ], + "name": "setReserveFactor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "rewardsManager", "type": "address" }], + "name": "setRewardsManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "treasuryVault", "type": "address" }], + "name": "setTreasuryVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" }, + { "internalType": "uint256", "name": "maxIterations", "type": "uint256" } + ], + "name": "supply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "supplyBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" } + ], + "name": "supplyCollateral", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { + "components": [ + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct Types.Signature", + "name": "signature", + "type": "tuple" + } + ], + "name": "supplyCollateralWithPermit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" }, + { "internalType": "uint256", "name": "maxIterations", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { + "components": [ + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct Types.Signature", + "name": "signature", + "type": "tuple" + } + ], + "name": "supplyWithPermit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryVault", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "underlying", "type": "address" }], + "name": "updatedIndexes", + "outputs": [ + { + "components": [ + { + "components": [ + { "internalType": "uint256", "name": "poolIndex", "type": "uint256" }, + { "internalType": "uint256", "name": "p2pIndex", "type": "uint256" } + ], + "internalType": "struct Types.MarketSideIndexes256", + "name": "supply", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "poolIndex", "type": "uint256" }, + { "internalType": "uint256", "name": "p2pIndex", "type": "uint256" } + ], + "internalType": "struct Types.MarketSideIndexes256", + "name": "borrow", + "type": "tuple" + } + ], + "internalType": "struct Types.Indexes256", + "name": "indexes", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "userBorrows", + "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "userCollaterals", + "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "userNonce", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "maxIterations", "type": "uint256" } + ], + "name": "withdraw", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalf", "type": "address" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "withdrawCollateral", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + } +] From c40454f23beac9e1af01d1a521697e7188569183 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Sun, 25 Jun 2023 03:47:23 -0400 Subject: [PATCH 30/34] changed minor --- test/mainnet/morpho/morpho-aave-v3.test.ts | 446 ++++++++++----------- 1 file changed, 223 insertions(+), 223 deletions(-) diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 4ac8a806..06cd3df4 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -129,259 +129,259 @@ describe("Morpho-Aave-v3", function () { }); describe("Main", function () { - // it("Should deposit 10 ETH", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "deposit", - // args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH - // }, - // ]; + it("Should deposit 10 ETH", async function () { + const spells = [ + { + connector: connectorName, + method: "deposit", + args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - // parseUnits('990', 18)) - // ); - // }) + await tx.wait(); + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('990', 18)) + ); + }) - // it("Should deposit 1 ETH with MaxIteration", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "depositWithMaxIterations", - // args: [tokens.eth.address, "1000000000000000000", 5, "0", "0"], // 1 ETH - // }, - // ]; + it("Should deposit 1 ETH with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "depositWithMaxIterations", + args: [tokens.eth.address, "1000000000000000000", 5, "0", "0"], // 1 ETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - // parseUnits('989', 18)) - // ); - // }) + await tx.wait(); + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('989', 18)) + ); + }) - // it("Should deposit 10 ETH on behalf", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "depositOnBehalf", - // args: [tokens.eth.address, "10000000000000000000", user, "0", "0"], // 1 ETH - // }, - // ]; + it("Should deposit 10 ETH on behalf", async function () { + const spells = [ + { + connector: connectorName, + method: "depositOnBehalf", + args: [tokens.eth.address, "10000000000000000000", user, "0", "0"], // 1 ETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - // parseUnits('979', 18)) - // ); - // }) + await tx.wait(); + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('979', 18)) + ); + }) - // it("Should deposit 1 ETH on behalf with MaxIteration", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "depositOnBehalfWithMaxIterations", - // args: [tokens.eth.address, "1000000000000000000", user, 5, "0", "0"], // 1 ETH - // }, - // ]; + it("Should deposit 1 ETH on behalf with MaxIteration", async function () { + const spells = [ + { + connector: connectorName, + method: "depositOnBehalfWithMaxIterations", + args: [tokens.eth.address, "1000000000000000000", user, 5, "0", "0"], // 1 ETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( - // parseUnits('978', 18)) - // ); - // }) + await tx.wait(); + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + parseUnits('978', 18)) + ); + }) - // it("Should deposit collateral 2000 USDC", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "depositCollateral", - // args: [tokens.usdc.address, "2000000000", "0", "0"], // 50 USDC - // }, - // ]; + it("Should deposit collateral 2000 USDC", async function () { + const spells = [ + { + connector: connectorName, + method: "depositCollateral", + args: [tokens.usdc.address, "2000000000", "0", "0"], // 50 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - // parseUnits('3000', 6) - // ); - // }) + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('3000', 6) + ); + }) - // it("Should deposit collateral 2000 USDC on behalf with maxValue", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "depositCollateralOnBehalf", - // args: [tokens.usdc.address, dsaMaxValue, user, "0", "0"], // ~3000 USDC - // }, - // ]; + it("Should deposit collateral 2000 USDC on behalf with maxValue", async function () { + const spells = [ + { + connector: connectorName, + method: "depositCollateralOnBehalf", + args: [tokens.usdc.address, dsaMaxValue, user, "0", "0"], // ~3000 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( - // parseUnits('1', 6) - // ); - // }) + await tx.wait(); + expect(await token_usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte( + parseUnits('1', 6) + ); + }) - // it("Should withdraw 10 ETH", async function () { - // const spells = [ - // { - // connector: connectorName, - // method: "withdraw", - // args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH - // }, - // ]; + it("Should withdraw 10 ETH", async function () { + const spells = [ + { + connector: connectorName, + method: "withdraw", + args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( - // parseUnits('978', 18)) - // ); - // }) + await tx.wait(); + expect(expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + parseUnits('978', 18)) + ); + }) - // it("Should withdraw on behalf of user with maxValue", async function () { - // let ethBala = await ethers.provider.getBalance(user) - // let wethBala = await token_weth.balanceOf(user) + it("Should withdraw on behalf of user with maxValue", async function () { + let ethBala = await ethers.provider.getBalance(user) + let wethBala = await token_weth.balanceOf(user) - // const spells = [ - // { - // connector: connectorName, - // method: "withdrawOnBehalf", - // args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // Max ETH - // }, - // ]; + const spells = [ + { + connector: connectorName, + method: "withdrawOnBehalf", + args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // Max ETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // ethBala = await ethers.provider.getBalance(user) - // wethBala = await token_weth.balanceOf(user) + await tx.wait(); + ethBala = await ethers.provider.getBalance(user) + wethBala = await token_weth.balanceOf(user) - // }) + }) - // it("Should borrow WETH into DSA", async function () { - // const balance = await token_weth.balanceOf(dsaWallet0.address); - // const spells = [ - // { - // connector: connectorName, - // method: "borrow", - // args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.5 WETH - // }, - // ]; + it("Should borrow WETH into DSA", async function () { + const balance = await token_weth.balanceOf(dsaWallet0.address); + const spells = [ + { + connector: connectorName, + method: "borrow", + args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.5 WETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) - // .to.be.eq(parseUnits('5', 17)); - // }) + await tx.wait(); + expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) + .to.be.eq(parseUnits('5', 17)); + }) - // it("Should borrow WETH into user", async function () { - // const balance = await token_weth.balanceOf(user); - // const spells = [ - // { - // connector: connectorName, - // method: "borrowOnBehalf", - // args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH - // }, - // ]; + it("Should borrow WETH into user", async function () { + const balance = await token_weth.balanceOf(user); + const spells = [ + { + connector: connectorName, + method: "borrowOnBehalf", + args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect((await token_weth.balanceOf(user)).sub(balance)) - // .to.be.eq(parseUnits('2', 17)); - // }) + await tx.wait(); + expect((await token_weth.balanceOf(user)).sub(balance)) + .to.be.eq(parseUnits('2', 17)); + }) - // it("Should borrow WETH into wallet1 using iteration", async function () { - // const balance = await token_weth.balanceOf(dsaWallet0.address); - // const spells = [ - // { - // connector: connectorName, - // method: "borrowWithMaxIterations", - // args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.02 WETH - // }, - // ]; + it("Should borrow WETH into wallet1 using iteration", async function () { + const balance = await token_weth.balanceOf(dsaWallet0.address); + const spells = [ + { + connector: connectorName, + method: "borrowWithMaxIterations", + args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.02 WETH + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) - // .to.be.eq(parseUnits('2', 16)); - // }) + await tx.wait(); + expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) + .to.be.eq(parseUnits('2', 16)); + }) - // it("Test withdrawCollateral ", async function () { - // await hre.network.provider.request({ - // method: 'hardhat_impersonateAccount', - // params: [ACC_USDC], - // }) + it("Test withdrawCollateral ", async function () { + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [ACC_USDC], + }) - // const signer_usdc = await ethers.getSigner(ACC_USDC) - // await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) + const signer_usdc = await ethers.getSigner(ACC_USDC) + await token_usdc.connect(signer_usdc).transfer(dsaWallet0.address, parseUnits('500', 6)) - // await hre.network.provider.request({ - // method: 'hardhat_stopImpersonatingAccount', - // params: [ACC_USDC], - // }) + await hre.network.provider.request({ + method: 'hardhat_stopImpersonatingAccount', + params: [ACC_USDC], + }) - // expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('500', 6) - // ); + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('500', 6) + ); - // const balance = await token_usdc.balanceOf(dsaWallet0.address); - // console.log('balance: ', balance.toString()); + const balance = await token_usdc.balanceOf(dsaWallet0.address); + console.log('balance: ', balance.toString()); - // const spells = [ - // { - // connector: connectorName, - // method: "depositCollateral", - // args: [tokens.usdc.address, "20000000", "0", "0"], // 20 USDC - // }, - // { - // connector: connectorName, - // method: "withdrawCollateral", - // args: [tokens.usdc.address, "19000000", dsaWallet0.address, "0", "0"], // 19 USDC - // }, - // ]; + const spells = [ + { + connector: connectorName, + method: "depositCollateral", + args: [tokens.usdc.address, "20000000", "0", "0"], // 20 USDC + }, + { + connector: connectorName, + method: "withdrawCollateral", + args: [tokens.usdc.address, "19000000", dsaWallet0.address, "0", "0"], // 19 USDC + }, + ]; - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); + await tx.wait(); - // }) + }) it("Test withdrawCollateralOnBehalf with maxValue", async function () { await hre.network.provider.request({ @@ -496,19 +496,19 @@ describe("Morpho-Aave-v3", function () { ); }) - // it("approve manger", async () => { - // const spells = [ - // { - // connector: connectorName, - // method: "approveManager", - // args: [user, true], - // }, - // ] - // const tx = await dsaWallet0 - // .connect(wallet0) - // .cast(...encodeSpells(spells), wallet1.getAddress()); + it("approve manger", async () => { + const spells = [ + { + connector: connectorName, + method: "approveManager", + args: [user, true], + }, + ] + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); - // await tx.wait(); - // }) + await tx.wait(); + }) }); }); From 5adf7662d300b328f5ba33a59a1cb0f9c3563dc0 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Sun, 25 Jun 2023 03:48:45 -0400 Subject: [PATCH 31/34] remove console --- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 381cbac9..7fe8679d 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -4,8 +4,6 @@ pragma experimental ABIEncoderV2; import "./helpers.sol"; import "./events.sol"; -import "hardhat/console.sol"; - abstract contract MorphoAaveV3 is Helpers, Events { /** * @dev Deposit ETH/ERC20_Token. From ea0ea85bb87cea4bd514ce5fb092d0b230f899cd Mon Sep 17 00:00:00 2001 From: q1q0 Date: Mon, 26 Jun 2023 02:29:29 -0400 Subject: [PATCH 32/34] update test script --- test/mainnet/morpho/morpho-aave-v3.test.ts | 53 +- test/mainnet/morpho/morpho-abi.json | 876 --------------------- 2 files changed, 23 insertions(+), 906 deletions(-) delete mode 100644 test/mainnet/morpho/morpho-abi.json diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 06cd3df4..64c4e7e2 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -9,7 +9,6 @@ import { ConnectV2MorphoAaveV3__factory, IERC20Minimal__factory } from "../../.. import { parseEther, parseUnits } from "@ethersproject/units"; import { encodeSpells } from "../../../scripts/tests/encodeSpells"; import { dsaMaxValue, tokens } from "../../../scripts/tests/mainnet/tokens"; -import morpho_ABI from './morpho-abi.json' const { ethers } = hre; import type { Signer, Contract } from "ethers"; @@ -38,6 +37,7 @@ describe("Morpho-Aave-v3", function () { let wallet0: Signer, wallet1: Signer; let dsaWallet0: any; + let dsaWallet1: any; let instaConnectorsV2: Contract; let masterSigner: Signer; @@ -76,6 +76,8 @@ describe("Morpho-Aave-v3", function () { it("Should build DSA v2", async function () { dsaWallet0 = await buildDSAv2(wallet0.getAddress()); expect(!!dsaWallet0.address).to.be.true; + dsaWallet1 = await buildDSAv2(wallet0.getAddress()); + expect(!!dsaWallet1.address).to.be.true; }); it("Deposit 1000 ETH into DSA wallet", async function () { @@ -84,6 +86,11 @@ describe("Morpho-Aave-v3", function () { value: parseEther("1000") }); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(parseEther("1000")); + await wallet0.sendTransaction({ + to: dsaWallet1.address, + value: parseEther("1000") + }); + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(parseEther("1000")); }); it("Deposit 5000 USDC into DSA wallet", async function () { @@ -397,49 +404,35 @@ describe("Morpho-Aave-v3", function () { params: [ACC_USDC] }); - await hre.network.provider.request({ - method: "hardhat_impersonateAccount", - params: [user] - }); - - const signer_user = await ethers.getSigner(user); - - const mophor = new ethers.Contract( - "0x33333aea097c193e66081E930c33020272b33333", - morpho_ABI, - ethers.provider - ); - - await mophor.connect(signer_user).approveManager(dsaWallet0.address, true) - - await hre.network.provider.request({ - method: "hardhat_stopImpersonatingAccount", - params: [user] - }); - expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("500", 6)); const balance = await token_usdc.balanceOf(dsaWallet0.address); - const spells = [ + let spells = [ + { + connector: connectorName, + method: "approveManager", + args: [dsaWallet0.address, true] // 20 USDC + }, + ]; + + let tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet1.getAddress()); + await tx.wait(); + + spells = [ { connector: connectorName, method: "depositCollateralOnBehalf", - args: [tokens.usdc.address, "20000000", user, "0", "0"] // 20 USDC + args: [tokens.usdc.address, "20000000", dsaWallet1.address, "0", "0"] // 20 USDC }, - // { - // connector: connectorName, - // method: "approveManager", - // args: [user, true] // 20 USDC - // }, { connector: connectorName, method: "withdrawCollateralOnBehalf", - args: [tokens.usdc.address, dsaMaxValue, user, user, "0", "0"] // 20 USDC + args: [tokens.usdc.address, dsaMaxValue, dsaWallet1.address, user, "0", "0"] // 20 USDC } ]; - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.getAddress()); + tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); diff --git a/test/mainnet/morpho/morpho-abi.json b/test/mainnet/morpho/morpho-abi.json deleted file mode 100644 index 843f6b44..00000000 --- a/test/mainnet/morpho/morpho-abi.json +++ /dev/null @@ -1,876 +0,0 @@ -[ - { "inputs": [], "name": "AddressIsZero", "type": "error" }, - { "inputs": [], "name": "AmountIsZero", "type": "error" }, - { "inputs": [], "name": "AssetIsCollateralOnMorpho", "type": "error" }, - { "inputs": [], "name": "AssetNotCollateralOnPool", "type": "error" }, - { "inputs": [], "name": "BorrowNotPaused", "type": "error" }, - { "inputs": [], "name": "ClaimRewardsPaused", "type": "error" }, - { "inputs": [], "name": "ExceedsMaxBasisPoints", "type": "error" }, - { "inputs": [], "name": "InvalidNonce", "type": "error" }, - { "inputs": [], "name": "InvalidSignatory", "type": "error" }, - { "inputs": [], "name": "InvalidValueS", "type": "error" }, - { "inputs": [], "name": "InvalidValueV", "type": "error" }, - { "inputs": [], "name": "MarketAlreadyCreated", "type": "error" }, - { "inputs": [], "name": "MarketIsDeprecated", "type": "error" }, - { "inputs": [], "name": "MarketIsNotListedOnAave", "type": "error" }, - { "inputs": [], "name": "MarketLtTooLow", "type": "error" }, - { "inputs": [], "name": "MarketNotCreated", "type": "error" }, - { "inputs": [], "name": "SetAsCollateralOnPoolButMarketNotCreated", "type": "error" }, - { "inputs": [], "name": "SignatureExpired", "type": "error" }, - { "inputs": [], "name": "SiloedBorrowMarket", "type": "error" }, - { "inputs": [], "name": "UnsafeCast", "type": "error" }, - { - "anonymous": false, - "inputs": [{ "indexed": false, "internalType": "uint8", "name": "version", "type": "uint8" }], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, - { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } - ], - "name": "OwnershipTransferStarted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, - { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "inputs": [], - "name": "DOMAIN_SEPARATOR", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { "inputs": [], "name": "acceptOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [], - "name": "addressesProvider", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "manager", "type": "address" }, - { "internalType": "bool", "name": "isAllowed", "type": "bool" } - ], - "name": "approveManager", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "delegator", "type": "address" }, - { "internalType": "address", "name": "manager", "type": "address" }, - { "internalType": "bool", "name": "isAllowed", "type": "bool" }, - { "internalType": "uint256", "name": "nonce", "type": "uint256" }, - { "internalType": "uint256", "name": "deadline", "type": "uint256" }, - { - "components": [ - { "internalType": "uint8", "name": "v", "type": "uint8" }, - { "internalType": "bytes32", "name": "r", "type": "bytes32" }, - { "internalType": "bytes32", "name": "s", "type": "bytes32" } - ], - "internalType": "struct Types.Signature", - "name": "signature", - "type": "tuple" - } - ], - "name": "approveManagerWithSig", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" }, - { "internalType": "address", "name": "receiver", "type": "address" }, - { "internalType": "uint256", "name": "maxIterations", "type": "uint256" } - ], - "name": "borrow", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "borrowBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address[]", "name": "assets", "type": "address[]" }, - { "internalType": "address", "name": "onBehalf", "type": "address" } - ], - "name": "claimRewards", - "outputs": [ - { "internalType": "address[]", "name": "rewardTokens", "type": "address[]" }, - { "internalType": "uint256[]", "name": "claimedAmounts", "type": "uint256[]" } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address[]", "name": "underlyings", "type": "address[]" }, - { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" } - ], - "name": "claimToTreasury", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "collateralBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint16", "name": "reserveFactor", "type": "uint16" }, - { "internalType": "uint16", "name": "p2pIndexCursor", "type": "uint16" } - ], - "name": "createMarket", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "defaultIterations", - "outputs": [ - { - "components": [ - { "internalType": "uint128", "name": "repay", "type": "uint128" }, - { "internalType": "uint128", "name": "withdraw", "type": "uint128" } - ], - "internalType": "struct Types.Iterations", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "eModeCategoryId", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "enum Types.Position", "name": "position", "type": "uint8" } - ], - "name": "getBucketsMask", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "enum Types.Position", "name": "position", "type": "uint8" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "getNext", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "increaseP2PDeltas", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "addressesProvider", "type": "address" }, - { "internalType": "uint8", "name": "eModeCategoryId", "type": "uint8" }, - { "internalType": "address", "name": "positionsManager", "type": "address" }, - { - "components": [ - { "internalType": "uint128", "name": "repay", "type": "uint128" }, - { "internalType": "uint128", "name": "withdraw", "type": "uint128" } - ], - "internalType": "struct Types.Iterations", - "name": "defaultIterations", - "type": "tuple" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "isClaimRewardsPaused", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "delegator", "type": "address" }, - { "internalType": "address", "name": "manager", "type": "address" } - ], - "name": "isManagedBy", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlyingBorrowed", "type": "address" }, - { "internalType": "address", "name": "underlyingCollateral", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "liquidate", - "outputs": [ - { "internalType": "uint256", "name": "", "type": "uint256" }, - { "internalType": "uint256", "name": "", "type": "uint256" } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], - "name": "liquidityData", - "outputs": [ - { - "components": [ - { "internalType": "uint256", "name": "borrowable", "type": "uint256" }, - { "internalType": "uint256", "name": "maxDebt", "type": "uint256" }, - { "internalType": "uint256", "name": "debt", "type": "uint256" } - ], - "internalType": "struct Types.LiquidityData", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "underlying", "type": "address" }], - "name": "market", - "outputs": [ - { - "components": [ - { - "components": [ - { - "components": [ - { "internalType": "uint128", "name": "poolIndex", "type": "uint128" }, - { "internalType": "uint128", "name": "p2pIndex", "type": "uint128" } - ], - "internalType": "struct Types.MarketSideIndexes", - "name": "supply", - "type": "tuple" - }, - { - "components": [ - { "internalType": "uint128", "name": "poolIndex", "type": "uint128" }, - { "internalType": "uint128", "name": "p2pIndex", "type": "uint128" } - ], - "internalType": "struct Types.MarketSideIndexes", - "name": "borrow", - "type": "tuple" - } - ], - "internalType": "struct Types.Indexes", - "name": "indexes", - "type": "tuple" - }, - { - "components": [ - { - "components": [ - { "internalType": "uint256", "name": "scaledDelta", "type": "uint256" }, - { "internalType": "uint256", "name": "scaledP2PTotal", "type": "uint256" } - ], - "internalType": "struct Types.MarketSideDelta", - "name": "supply", - "type": "tuple" - }, - { - "components": [ - { "internalType": "uint256", "name": "scaledDelta", "type": "uint256" }, - { "internalType": "uint256", "name": "scaledP2PTotal", "type": "uint256" } - ], - "internalType": "struct Types.MarketSideDelta", - "name": "borrow", - "type": "tuple" - } - ], - "internalType": "struct Types.Deltas", - "name": "deltas", - "type": "tuple" - }, - { "internalType": "address", "name": "underlying", "type": "address" }, - { - "components": [ - { "internalType": "bool", "name": "isP2PDisabled", "type": "bool" }, - { "internalType": "bool", "name": "isSupplyPaused", "type": "bool" }, - { "internalType": "bool", "name": "isSupplyCollateralPaused", "type": "bool" }, - { "internalType": "bool", "name": "isBorrowPaused", "type": "bool" }, - { "internalType": "bool", "name": "isWithdrawPaused", "type": "bool" }, - { "internalType": "bool", "name": "isWithdrawCollateralPaused", "type": "bool" }, - { "internalType": "bool", "name": "isRepayPaused", "type": "bool" }, - { "internalType": "bool", "name": "isLiquidateCollateralPaused", "type": "bool" }, - { "internalType": "bool", "name": "isLiquidateBorrowPaused", "type": "bool" }, - { "internalType": "bool", "name": "isDeprecated", "type": "bool" } - ], - "internalType": "struct Types.PauseStatuses", - "name": "pauseStatuses", - "type": "tuple" - }, - { "internalType": "bool", "name": "isCollateral", "type": "bool" }, - { "internalType": "address", "name": "variableDebtToken", "type": "address" }, - { "internalType": "uint32", "name": "lastUpdateTimestamp", "type": "uint32" }, - { "internalType": "uint16", "name": "reserveFactor", "type": "uint16" }, - { "internalType": "uint16", "name": "p2pIndexCursor", "type": "uint16" }, - { "internalType": "address", "name": "aToken", "type": "address" }, - { "internalType": "address", "name": "stableDebtToken", "type": "address" }, - { "internalType": "uint256", "name": "idleSupply", "type": "uint256" } - ], - "internalType": "struct Types.Market", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "marketsCreated", - "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "owner", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pendingOwner", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pool", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "positionsManager", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" } - ], - "name": "repay", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" }, - { "internalType": "uint256", "name": "deadline", "type": "uint256" }, - { - "components": [ - { "internalType": "uint8", "name": "v", "type": "uint8" }, - { "internalType": "bytes32", "name": "r", "type": "bytes32" }, - { "internalType": "bytes32", "name": "s", "type": "bytes32" } - ], - "internalType": "struct Types.Signature", - "name": "signature", - "type": "tuple" - } - ], - "name": "repayWithPermit", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "rewardsManager", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "scaledCollateralBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "scaledP2PBorrowBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "scaledP2PSupplyBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "scaledPoolBorrowBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "scaledPoolSupplyBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isCollateral", "type": "bool" } - ], - "name": "setAssetIsCollateral", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isCollateral", "type": "bool" } - ], - "name": "setAssetIsCollateralOnPool", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { "internalType": "uint128", "name": "repay", "type": "uint128" }, - { "internalType": "uint128", "name": "withdraw", "type": "uint128" } - ], - "internalType": "struct Types.Iterations", - "name": "defaultIterations", - "type": "tuple" - } - ], - "name": "setDefaultIterations", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsBorrowPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "bool", "name": "isPaused", "type": "bool" }], - "name": "setIsClaimRewardsPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isDeprecated", "type": "bool" } - ], - "name": "setIsDeprecated", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsLiquidateBorrowPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsLiquidateCollateralPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isP2PDisabled", "type": "bool" } - ], - "name": "setIsP2PDisabled", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "bool", "name": "isPaused", "type": "bool" }], - "name": "setIsPausedForAllMarkets", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsRepayPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsSupplyCollateralPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsSupplyPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsWithdrawCollateralPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "bool", "name": "isPaused", "type": "bool" } - ], - "name": "setIsWithdrawPaused", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint16", "name": "p2pIndexCursor", "type": "uint16" } - ], - "name": "setP2PIndexCursor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "positionsManager", "type": "address" }], - "name": "setPositionsManager", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint16", "name": "newReserveFactor", "type": "uint16" } - ], - "name": "setReserveFactor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "rewardsManager", "type": "address" }], - "name": "setRewardsManager", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "treasuryVault", "type": "address" }], - "name": "setTreasuryVault", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" }, - { "internalType": "uint256", "name": "maxIterations", "type": "uint256" } - ], - "name": "supply", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "supplyBalance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" } - ], - "name": "supplyCollateral", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" }, - { "internalType": "uint256", "name": "deadline", "type": "uint256" }, - { - "components": [ - { "internalType": "uint8", "name": "v", "type": "uint8" }, - { "internalType": "bytes32", "name": "r", "type": "bytes32" }, - { "internalType": "bytes32", "name": "s", "type": "bytes32" } - ], - "internalType": "struct Types.Signature", - "name": "signature", - "type": "tuple" - } - ], - "name": "supplyCollateralWithPermit", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" }, - { "internalType": "uint256", "name": "maxIterations", "type": "uint256" }, - { "internalType": "uint256", "name": "deadline", "type": "uint256" }, - { - "components": [ - { "internalType": "uint8", "name": "v", "type": "uint8" }, - { "internalType": "bytes32", "name": "r", "type": "bytes32" }, - { "internalType": "bytes32", "name": "s", "type": "bytes32" } - ], - "internalType": "struct Types.Signature", - "name": "signature", - "type": "tuple" - } - ], - "name": "supplyWithPermit", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "treasuryVault", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "underlying", "type": "address" }], - "name": "updatedIndexes", - "outputs": [ - { - "components": [ - { - "components": [ - { "internalType": "uint256", "name": "poolIndex", "type": "uint256" }, - { "internalType": "uint256", "name": "p2pIndex", "type": "uint256" } - ], - "internalType": "struct Types.MarketSideIndexes256", - "name": "supply", - "type": "tuple" - }, - { - "components": [ - { "internalType": "uint256", "name": "poolIndex", "type": "uint256" }, - { "internalType": "uint256", "name": "p2pIndex", "type": "uint256" } - ], - "internalType": "struct Types.MarketSideIndexes256", - "name": "borrow", - "type": "tuple" - } - ], - "internalType": "struct Types.Indexes256", - "name": "indexes", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], - "name": "userBorrows", - "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], - "name": "userCollaterals", - "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], - "name": "userNonce", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" }, - { "internalType": "address", "name": "receiver", "type": "address" }, - { "internalType": "uint256", "name": "maxIterations", "type": "uint256" } - ], - "name": "withdraw", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "underlying", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "address", "name": "onBehalf", "type": "address" }, - { "internalType": "address", "name": "receiver", "type": "address" } - ], - "name": "withdrawCollateral", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "nonpayable", - "type": "function" - } -] From 0604a0d55d56a03778e7a0e9971f8cde5f8d49c0 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Wed, 28 Jun 2023 15:01:20 +0800 Subject: [PATCH 33/34] update testacse --- test/mainnet/morpho/morpho-aave-v3.test.ts | 37 ++++------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 64c4e7e2..1047e38d 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -111,28 +111,6 @@ describe("Morpho-Aave-v3", function () { expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("5000", 6)); }); - - // it("Deposit 1 DAI into DSA wallet", async function () { - - // await hre.network.provider.request({ - // method: 'hardhat_impersonateAccount', - // params: [ACC_DAI], - // }) - - // const signer_dai = await ethers.getSigner(ACC_DAI) - // await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai) - - // await hre.network.provider.request({ - // method: 'hardhat_stopImpersonatingAccount', - // params: [ACC_DAI], - // }) - - // await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai); - - // expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( - // parseUnits('1', 18) - // ); - // }); }); describe("Main", function () { @@ -291,13 +269,13 @@ describe("Morpho-Aave-v3", function () { }) - it("Should borrow WETH into DSA", async function () { - const balance = await token_weth.balanceOf(dsaWallet0.address); + it("Should borrow ETH into DSA", async function () { + const balanceBefore = await ethers.provider.getBalance(dsaWallet0.address); const spells = [ { connector: connectorName, method: "borrow", - args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.5 WETH + args: [tokens.eth.address, "500000000000000000", "0", "0"], // 0.5 WETH }, ]; @@ -306,17 +284,17 @@ describe("Morpho-Aave-v3", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); - expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance)) - .to.be.eq(parseUnits('5', 17)); + const balanceAfter = await ethers.provider.getBalance(dsaWallet0.address); + expect((balanceAfter).sub(balanceBefore)).to.be.gte(parseUnits('4.9', 17)); }) - it("Should borrow WETH into user", async function () { + it("Should borrow ETH into user", async function () { const balance = await token_weth.balanceOf(user); const spells = [ { connector: connectorName, method: "borrowOnBehalf", - args: [tokens.weth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH + args: [tokens.eth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH }, ]; @@ -367,7 +345,6 @@ describe("Morpho-Aave-v3", function () { ); const balance = await token_usdc.balanceOf(dsaWallet0.address); - console.log('balance: ', balance.toString()); const spells = [ { From 7ba4f9e432dc35b57d6f3d2933b96aa82bf1ac60 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Wed, 28 Jun 2023 15:01:55 +0800 Subject: [PATCH 34/34] Increase space size --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58b5f2ff..754cf2f3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "check": "ts-node status-checks/huskyCheck.ts", "check-husky": "ts-node status-checks/huskyCheck.ts", "deploy": "ts-node scripts/deployConnectorsFromCmd.ts", - "test:runner": "hardhat run scripts/tests/run-tests.ts", + "test:runner": "NODE_OPTIONS='--max-old-space-size=4096' hardhat run scripts/tests/run-tests.ts", "typechain": "hardhat typechain", "compile": "hardhat compile", "deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts",