Skip to content

Commit

Permalink
update ETHToWETH in supplyonBehaf and repayOnBehaf
Browse files Browse the repository at this point in the history
  • Loading branch information
q1q0 committed Nov 20, 2023
1 parent 9b1c70e commit 84f395b
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions contracts/mainnet/connectors/morpho-blue/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract contract MorphoBlue is Helpers, Events {
/**
* @dev Supplying a large amount can revert for overflow.
* @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's `onMorphoSupply` function with the given `data`.
* @param _marketParams 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE native token is not allowed in this mode cause of failing in withdraw of WETH.
* @param _marketParams The market to supply assets to.(For ETH of loanToken in _marketParams: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _assets The amount of assets to supply.
* @param _shares The amount of shares to mint.
* @param _onBehalf The address that will own the increased supply position.
Expand All @@ -85,11 +85,15 @@ abstract contract MorphoBlue is Helpers, Events {
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(_getId, _assets);
(
TokenInterface _tokenContract,
uint256 _amt,
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);

bytes32 _id = id(_marketParams);
uint256 _approveAmount = _getApproveAmount(_id, _amt, _shares);
approve(TokenInterface(_marketParams.loanToken), address(MORPHO_BLUE), _approveAmount);
approve(_tokenContract, address(MORPHO_BLUE), _approveAmount);
_marketParams.loanToken = address(_tokenContract);

(_assets, _shares) = MORPHO_BLUE.supply(_marketParams, _amt, _shares, _onBehalf, _data);

Expand Down Expand Up @@ -151,7 +155,7 @@ abstract contract MorphoBlue is Helpers, Events {

/**
* @notice Supplies `assets` of collateral on behalf of `onBehalf`, optionally calling back the caller's `onMorphoSupplyCollateral` function with the given `data`.
* @param _marketParams 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE native token is not allowed in this mode cause of failing in withdraw of WETH.
* @param _marketParams The market to supply assets to.(For ETH of loanToken in _marketParams: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _assets The amount of assets to supply.
* @param _onBehalf The address that will own the increased supply position.
* @param _data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed.
Expand All @@ -170,9 +174,13 @@ abstract contract MorphoBlue is Helpers, Events {
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(_getId, _assets);
(
TokenInterface _tokenContract,
uint256 _amt,
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);

approve(TokenInterface(_marketParams.loanToken), address(MORPHO_BLUE), _amt);
approve(_tokenContract, address(MORPHO_BLUE), _amt);
_marketParams.loanToken = address(_tokenContract);

MORPHO_BLUE.supplyCollateral(_marketParams, _amt, _onBehalf, _data);

Expand Down Expand Up @@ -379,7 +387,7 @@ abstract contract MorphoBlue is Helpers, Events {

/**
* @notice Borrows `assets` or `shares` on behalf of `onBehalf` to `receiver`. receiver should be address(this)
* @dev 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE native token is not allowed in this mode cause of failing in withdraw of WETH.
* @dev The market to supply assets to.(For ETH of loanToken in _marketParams: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _marketParams The market to supply assets to.
* @param _assets The amount of assets to supply.
* @param _shares The amount of shares to mint.
Expand All @@ -399,7 +407,12 @@ abstract contract MorphoBlue is Helpers, Events {
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(_getId, _assets);
(
TokenInterface _tokenContract,
uint256 _amt,
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);

_marketParams.loanToken = address(_tokenContract);

(_assets, _shares) = MORPHO_BLUE.borrow(_marketParams, _amt, _shares, _onBehalf, address(this));

Expand Down Expand Up @@ -554,8 +567,12 @@ abstract contract MorphoBlue is Helpers, Events {
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(_getId, _assets);
bool _isMax;
(
TokenInterface _tokenContract,
uint256 _amt,
bool _isMax
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);
_marketParams.loanToken = address(_tokenContract);
if (_amt == uint256(-1)) {
_amt = TokenInterface(_marketParams.loanToken).balanceOf(_onBehalf);
_isMax = true;
Expand Down

0 comments on commit 84f395b

Please sign in to comment.