From 13baefeab3a81fe3528b4b2a32c00589ddd4f958 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Tue, 19 Sep 2023 19:21:19 +0530 Subject: [PATCH 1/7] feat: update --- .../connectors/morpho-aave-v3/events.sol | 21 +--- .../connectors/morpho-aave-v3/main.sol | 102 ++---------------- 2 files changed, 12 insertions(+), 111 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol index 404eb789..391f490c 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/events.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -18,14 +18,6 @@ contract Events { uint256 setId ); - event LogDepositOnBehalf( - address tokenAddress, - uint256 amount, - address onBehalf, - uint256 getId, - uint256 setId - ); - event LogDepositOnBehalfWithMaxIterations( address tokenAddress, uint256 amount, @@ -57,15 +49,6 @@ contract Events { uint256 setId ); - event LogBorrowOnBehalf( - address tokenAddress, - uint256 amount, - address onBehalf, - address receiver, - uint256 getId, - uint256 setId - ); - event LogBorrowWithMaxIterations( address tokenAddress, uint256 amount, @@ -92,11 +75,11 @@ contract Events { uint256 setId ); - event LogWithdrawOnBehalf( + event LogWithdrawWithMaxIterations( address tokenAddress, uint256 amount, - address onBehalf, address receiver, + uint256 maxIteration, uint256 getId, uint256 setId ); diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index 7fe8679d..71b1379d 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -84,47 +84,6 @@ 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 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. - * @param _getId ID to retrieve amt. - * @param _setId ID stores the amount of tokens deposited. - */ - function depositOnBehalf( - 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(address(_tokenContract), _amt, _onBehalf, max_iteration); - - setUint(_setId, _amt); - - _eventName = "LogDepositOnBehalf(address,uint256,address,uint256,uint256)"; - _eventParam = abi.encode( - _tokenAddress, - _amt, - _onBehalf, - _getId, - _setId - ); - } - /** * @dev Deposit ETH/ERC20_Token on behalf of a user. * @notice Deposit a token to Morpho Aave for lending on behalf of a user with max iterations. @@ -285,50 +244,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { ); } - /** - * @dev Borrow ETH/ERC20_Token. - * @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. - 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. - */ - function borrowOnBehalf( - 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); - bool _isETH = _tokenAddress == ethAddr; - address _token = _isETH ? wethAddr : _tokenAddress; - - uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, _onBehalf, _receiver, max_iteration); - - if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _borrowed); - - setUint(_setId, _borrowed); - - _eventName = "LogBorrowOnBehalf(address,uint256,addresss,address,uint256,uint256)"; - _eventParam = abi.encode( - _tokenAddress, - _borrowed, - _onBehalf, - _receiver, - _getId, - _setId - ); - } - /** * @dev Borrow ETH/ERC20_Token. * @notice Borrow a token from Morpho Aave. @@ -356,6 +271,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isETH = _tokenAddress == ethAddr; address _token = _isETH ? wethAddr : _tokenAddress; + if (_receiver == address(0)) _receiver = address(this); + uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _borrowed); @@ -463,17 +380,16 @@ 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. - 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 withdrawOnBehalf( + function withdrawWithMaxIterations( address _tokenAddress, uint256 _amount, - address _onBehalf, address _receiver, + uint256 _maxIteration, uint256 _getId, uint256 _setId ) @@ -485,19 +401,21 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isEth = _tokenAddress == ethAddr; address _token = _isEth ? wethAddr : _tokenAddress; + if(_receiver == address(0)) _receiver == address(this); + // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. - uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, _onBehalf, _receiver, max_iteration); + uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), address(this), _maxIteration); if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); setUint(_setId, _withdrawn); - _eventName = "LogWithdrawOnBehalf(address,uint256,address,address,uint256,uint256)"; + _eventName = "LogWithdrawWithMaxIterations(address,uint256,address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _withdrawn, - _onBehalf, _receiver, + _maxIteration, _getId, _setId ); From 0b4f8e5b6a03f4df8c12b7874bf4cecf1a6e2bf2 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Tue, 19 Sep 2023 19:36:38 +0530 Subject: [PATCH 2/7] feat: update tests --- test/mainnet/morpho/morpho-aave-v3.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index 1047e38d..a045a220 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -156,8 +156,8 @@ describe("Morpho-Aave-v3", function () { const spells = [ { connector: connectorName, - method: "depositOnBehalf", - args: [tokens.eth.address, "10000000000000000000", user, "0", "0"], // 1 ETH + method: "depositOnBehalfWithMaxIterations", + args: [tokens.eth.address, "10000000000000000000", user, 4, "0", "0"], // 1 ETH }, ]; @@ -254,8 +254,8 @@ describe("Morpho-Aave-v3", function () { const spells = [ { connector: connectorName, - method: "withdrawOnBehalf", - args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, user, "0", "0"], // Max ETH + method: "withdrawOnBehalfWithMaxIterations", + args: [tokens.eth.address, dsaMaxValue, dsaWallet0.address, user, 4, "0", "0"], // Max ETH }, ]; @@ -293,8 +293,8 @@ describe("Morpho-Aave-v3", function () { const spells = [ { connector: connectorName, - method: "borrowOnBehalf", - args: [tokens.eth.address, "200000000000000000", dsaWallet0.address, user, "0", "0"], // 0.7 WETH + method: "borrowOnBehalfWithMaxIterations", + args: [tokens.eth.address, "200000000000000000", dsaWallet0.address, user, 4, "0", "0"], // 0.7 WETH }, ]; From 6438aa18d74721e23942475d84634926c8ecc145 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Tue, 19 Sep 2023 19:45:03 +0530 Subject: [PATCH 3/7] feat: make variable constant --- contracts/mainnet/connectors/morpho-aave-v3/helpers.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index 6afd0997..ba739a86 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -10,7 +10,7 @@ abstract contract Helpers is Stores, Basic { IMorphoCore public constant MORPHO_AAVE_V3 = IMorphoCore(0x33333aea097c193e66081E930c33020272b33333); - uint256 public max_iteration = 4; + uint256 public constant max_iteration = 4; function _performEthToWethConversion( address _tokenAddress, From 03d18acf03b8334df73e30c5da93f17a0de16ad6 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Tue, 19 Sep 2023 19:52:31 +0530 Subject: [PATCH 4/7] feat: update --- .../mainnet/connectors/morpho-aave-v3/helpers.sol | 2 +- contracts/mainnet/connectors/morpho-aave-v3/main.sol | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol index ba739a86..13f88941 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/helpers.sol @@ -10,7 +10,7 @@ abstract contract Helpers is Stores, Basic { IMorphoCore public constant MORPHO_AAVE_V3 = IMorphoCore(0x33333aea097c193e66081E930c33020272b33333); - uint256 public constant max_iteration = 4; + uint256 public constant MAX_ITERATIONS = 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 71b1379d..c51e88be 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(address(_tokenContract), _amt, address(this), max_iteration); + MORPHO_AAVE_V3.supply(address(_tokenContract), _amt, address(this), MAX_ITERATIONS); setUint(_setId, _amt); @@ -229,7 +229,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isETH = _tokenAddress == ethAddr; address _token = _isETH ? wethAddr : _tokenAddress; - uint256 _borrowed = 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_ITERATIONS); convertWethToEth(_isETH, TokenInterface(_token), _borrowed); @@ -360,7 +360,7 @@ 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. - uint256 _withdrawn = 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_ITERATIONS); convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); @@ -655,13 +655,13 @@ abstract contract MorphoAaveV3 is Helpers, Events { external returns (string memory _eventName, bytes memory _eventParam) { - uint256 _oldIterations = max_iteration; - max_iteration = _iterations; + uint256 _oldIterations = MAX_ITERATIONS; + MAX_ITERATIONS = _iterations; _eventName = "LogUpdateMaxIterations(uint256,uint256)"; _eventParam = abi.encode( _oldIterations, - max_iteration + MAX_ITERATIONS ); } } From ed0c40eceb251c3006741593c32b92f6b7aa263e Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Tue, 19 Sep 2023 19:53:01 +0530 Subject: [PATCH 5/7] feat: remove MaxIterations --- .../mainnet/connectors/morpho-aave-v3/main.sol | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/main.sol b/contracts/mainnet/connectors/morpho-aave-v3/main.sol index c51e88be..65fdbd13 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -648,22 +648,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { _isAllowed ); } - - /// @notice Updates the max iterations for a `repay` or a `withdraw`. - /// @param _iterations New iteration count. - function updateMaxIterations(uint256 _iterations) - external - returns (string memory _eventName, bytes memory _eventParam) - { - uint256 _oldIterations = MAX_ITERATIONS; - MAX_ITERATIONS = _iterations; - - _eventName = "LogUpdateMaxIterations(uint256,uint256)"; - _eventParam = abi.encode( - _oldIterations, - MAX_ITERATIONS - ); - } } contract ConnectV2MorphoAaveV3 is MorphoAaveV3 { From e4431e844c475378692141555cee16b683950645 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Tue, 19 Sep 2023 19:57:37 +0530 Subject: [PATCH 6/7] feat: update --- 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 65fdbd13..2ae8fcf8 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -404,7 +404,7 @@ abstract contract MorphoAaveV3 is Helpers, Events { if(_receiver == address(0)) _receiver == address(this); // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. - uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), address(this), _maxIteration); + uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), _receiver, _maxIteration); if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); From d87279c371826aa6fd2d6bdf2305d4cef2ceac47 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Wed, 20 Sep 2023 19:23:30 +0530 Subject: [PATCH 7/7] feat: remove receiver --- .../connectors/morpho-aave-v3/events.sol | 8 -- .../connectors/morpho-aave-v3/main.sol | 95 ++++++++----------- test/mainnet/morpho/morpho-aave-v3.test.ts | 4 +- 3 files changed, 42 insertions(+), 65 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-aave-v3/events.sol b/contracts/mainnet/connectors/morpho-aave-v3/events.sol index 391f490c..0857bace 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/events.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/events.sol @@ -52,7 +52,6 @@ contract Events { event LogBorrowWithMaxIterations( address tokenAddress, uint256 amount, - address receiver, uint256 maxIteration, uint256 getId, uint256 setId @@ -78,7 +77,6 @@ contract Events { event LogWithdrawWithMaxIterations( address tokenAddress, uint256 amount, - address receiver, uint256 maxIteration, uint256 getId, uint256 setId @@ -97,7 +95,6 @@ contract Events { event LogWithdrawCollateral( address tokenAddress, uint256 amount, - address receiver, uint256 getId, uint256 setId ); @@ -127,9 +124,4 @@ 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 2ae8fcf8..9e4025b0 100644 --- a/contracts/mainnet/connectors/morpho-aave-v3/main.sol +++ b/contracts/mainnet/connectors/morpho-aave-v3/main.sol @@ -6,8 +6,8 @@ import "./events.sol"; abstract contract MorphoAaveV3 is Helpers, Events { /** - * @dev Deposit ETH/ERC20_Token. - * @notice Deposit a token to Morpho Aave for lending. + * @dev Supply ETH/ERC20 Token for lending. + * @notice Supply ETH/ERC20 Token to Morpho Aave for lending. It will be elible for P2P matching but will not have nay borrowing power. * @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. @@ -44,8 +44,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Deposit ETH/ERC20_Token. - * @notice Deposit a token to Morpho Aave for lending. + * @dev Supply ETH/ERC20 Token for lending with max iterations. + * @notice Supply ETH/ERC20 Token to Morpho Aave for lending with max iterations. It will be elible for P2P matching but will not have nay borrowing power. * @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. @@ -85,8 +85,8 @@ 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 on behalf of a user with max iterations. + * @dev Supply ETH/ERC20 Token on Behalf for lending with max iterations. + * @notice Supply ETH/ERC20 Token on behalf to Morpho Aave for lending with max iterations. It will be elible for P2P matching but will not have nay borrowing power. * @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. @@ -129,8 +129,8 @@ 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. + * @dev Deposit ETH/ERC20 Token for collateralization. + * @notice Deposit a token to Morpho Aave for collaterization. It will not be eligible for P2P matching. * @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. @@ -167,8 +167,8 @@ 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. + * @dev Deposit ETH/ERC20 Token on behalf for collateralization. + * @notice Deposit a token on behalf to Morpho Aave for collaterization. It will not be eligible for P2P matching. * @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. @@ -208,8 +208,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Borrow ETH/ERC20_Token. - * @notice Borrow a token from Morpho Aave. + * @dev Borrow ETH/ERC20 Token. + * @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. @@ -245,12 +245,10 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Borrow ETH/ERC20_Token. - * @notice Borrow a token from Morpho Aave. + * @dev Borrow ETH/ERC20 Token. + * @notice Borrow a token from Morpho Aave V3 with max iterations. * @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. @@ -258,7 +256,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { function borrowWithMaxIterations( address _tokenAddress, uint256 _amount, - address _receiver, uint256 _maxIteration, uint256 _getId, uint256 _setId @@ -271,19 +268,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isETH = _tokenAddress == ethAddr; address _token = _isETH ? wethAddr : _tokenAddress; - if (_receiver == address(0)) _receiver = address(this); + uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, address(this), address(this), _maxIteration); - uint256 _borrowed = MORPHO_AAVE_V3.borrow(_token, _amt, address(this), _receiver, _maxIteration); - - if(_receiver == address(this)) convertWethToEth(_isETH, TokenInterface(_token), _borrowed); + convertWethToEth(_isETH, TokenInterface(_token), _borrowed); setUint(_setId, _borrowed); - _eventName = "LogBorrowWithMaxIterations(address,uint256,addresss,uint256,uint256,uint256)"; + _eventName = "LogBorrowWithMaxIterations(address,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _borrowed, - _receiver, _maxIteration, _getId, _setId @@ -291,8 +285,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Borrow ETH/ERC20_Token. - * @notice Borrow a token from Morpho Aave. + * @dev Borrow ETH/ERC20 Token. + * @notice Borrow a token from Morpho Aave V3 on behalf with max iterations. * @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. @@ -338,8 +332,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Withdraw ETH/ERC20_Token. - * @notice Withdraw a token from Morpho Aave. + * @dev Withdraw ETH/ERC20 "Supplied" Token. + * @notice Withdraw a supplied token from Morpho Aave V3. * @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. @@ -376,11 +370,10 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Withdraw ETH/ERC20_Token. - * @notice Withdraw a token from Morpho Aave. + * @dev Withdraw ETH/ERC20 "Supplied" Token. + * @notice Withdraw a supplied token from Morpho Aave V3 with max iterations. * @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 _maxIteration Max number of iterations to run. * @param _getId ID to retrieve amt. * @param _setId ID stores the amount of tokens withdrawed. @@ -388,7 +381,6 @@ abstract contract MorphoAaveV3 is Helpers, Events { function withdrawWithMaxIterations( address _tokenAddress, uint256 _amount, - address _receiver, uint256 _maxIteration, uint256 _getId, uint256 _setId @@ -401,20 +393,17 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isEth = _tokenAddress == ethAddr; address _token = _isEth ? wethAddr : _tokenAddress; - if(_receiver == address(0)) _receiver == address(this); - // Morpho will internally handle max amount conversion by taking the minimum of amount or supplied collateral. - uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), _receiver, _maxIteration); + uint256 _withdrawn = MORPHO_AAVE_V3.withdraw(_token, _amt, address(this), address(this), _maxIteration); - if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); + convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); setUint(_setId, _withdrawn); - _eventName = "LogWithdrawWithMaxIterations(address,uint256,address,uint256,uint256,uint256)"; + _eventName = "LogWithdrawWithMaxIterations(address,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _withdrawn, - _receiver, _maxIteration, _getId, _setId @@ -422,8 +411,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Withdraw ETH/ERC20_Token. - * @notice Withdraw a token from Morpho Aave. + * @dev Withdraw ETH/ERC20 "Supplied" Token. + * @notice Withdraw a supplied token from Morpho Aave V3 on behalf with max iterations. * @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. @@ -470,19 +459,16 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Withdraw ETH/ERC20 collateral token. - * @notice Withdraw a token from Morpho Aave. + * @dev Withdraw ETH/ERC20 "collateral" token. + * @notice Withdraw a collateral token from Morpho Aave V3. * @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. */ function withdrawCollateral( address _tokenAddress, uint256 _amount, - address _receiver, uint256 _getId, uint256 _setId ) @@ -494,25 +480,24 @@ abstract contract MorphoAaveV3 is Helpers, Events { bool _isEth = _tokenAddress == ethAddr; address _token = _isEth ? wethAddr : _tokenAddress; - uint256 _withdrawn = MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), _receiver); + uint256 _withdrawn = MORPHO_AAVE_V3.withdrawCollateral(_token, _amt, address(this), address(this)); - if(_receiver == address(this)) convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); + convertWethToEth(_isEth, TokenInterface(_token), _withdrawn); setUint(_setId, _withdrawn); - _eventName = "LogWithdrawCollateral(address,uint256,address,uint256,uint256)"; + _eventName = "LogWithdrawCollateral(address,uint256,uint256,uint256)"; _eventParam = abi.encode( _tokenAddress, _withdrawn, - _receiver, _getId, _setId ); } /** - * @dev Withdraw ETH/ERC20 collateral token. - * @notice Withdraw a token from Morpho Aave. + * @dev Withdraw ETH/ERC20 "collateral" token on behalf. + * @notice Withdraw a collateral token on behalf from Morpho Aave V3. * @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. @@ -555,8 +540,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Payback ETH/ERC20_Token. - * @notice Payback a token to Morpho Aave. + * @dev Payback ETH/ERC20 Token. + * @notice Payback borrowed token to Morpho Aave V3. * @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`) * @param _getId ID to retrieve amt. @@ -593,8 +578,8 @@ abstract contract MorphoAaveV3 is Helpers, Events { } /** - * @dev Payback ETH/ERC20_Token. - * @notice Payback a token to Morpho Aave. + * @dev Payback ETH/ERC20 Token on behalf. + * @notice Payback borrowed token on bahelf to Morpho Aave V3. * @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @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)`) @@ -651,5 +636,5 @@ abstract contract MorphoAaveV3 is Helpers, Events { } contract ConnectV2MorphoAaveV3 is MorphoAaveV3 { - string public constant name = "Morpho-AaveV3-v1.0"; + string public constant name = "Morpho-AaveV3-v1.1"; } diff --git a/test/mainnet/morpho/morpho-aave-v3.test.ts b/test/mainnet/morpho/morpho-aave-v3.test.ts index a045a220..eb9bd94f 100644 --- a/test/mainnet/morpho/morpho-aave-v3.test.ts +++ b/test/mainnet/morpho/morpho-aave-v3.test.ts @@ -313,7 +313,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "borrowWithMaxIterations", - args: [tokens.weth.address, "20000000000000000", dsaWallet0.address, 10, "0", "0"], // 0.02 WETH + args: [tokens.weth.address, "20000000000000000", 10, "0", "0"], // 0.02 WETH }, ]; @@ -355,7 +355,7 @@ describe("Morpho-Aave-v3", function () { { connector: connectorName, method: "withdrawCollateral", - args: [tokens.usdc.address, "19000000", dsaWallet0.address, "0", "0"], // 19 USDC + args: [tokens.usdc.address, "19000000", "0", "0"], // 19 USDC }, ];