mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
parent
19d03f06f3
commit
70120e4bcd
|
@ -1,61 +0,0 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract Events {
|
||||
|
||||
event LogSupply(
|
||||
address loanToken,
|
||||
uint256 assets,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
bytes data,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogSupplyCollateral(
|
||||
address loanToken,
|
||||
address poolTokenAddress,
|
||||
uint256 amount,
|
||||
uint256 maxGasForMatching,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogBorrow(
|
||||
address loanToken,
|
||||
uint256 amounts,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogWithdraw(
|
||||
address loanToken,
|
||||
uint256 amounts,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogWithdrawCollateral(
|
||||
address loanToken,
|
||||
uint256 amounts,
|
||||
address onBehalf,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogPayback(
|
||||
address loanToken,
|
||||
uint256 amounts,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
bytes data,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
//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 {
|
||||
|
||||
IMorpho public constant MORPHO_BLUE =
|
||||
IMorpho(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
|
||||
|
||||
|
||||
|
||||
function _performEthToWethConversion(
|
||||
address _tokenAddress,
|
||||
uint256 _amount,
|
||||
uint256 _getId
|
||||
) internal returns (TokenInterface _tokenContract, uint256 _amt, bool _isMax) {
|
||||
_amt = getUint(_getId, _amount);
|
||||
_isMax = _amt == uint256(-1);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
uint256 internal constant MARKET_PARAMS_BYTES_LENGTH = 5 * 32;
|
||||
|
||||
/// @notice Returns the id of the market `marketParams`.
|
||||
function id(MarketParams memory marketParams) internal pure returns (bytes32 marketParamsId) {
|
||||
assembly {
|
||||
marketParamsId := keccak256(marketParams, MARKET_PARAMS_BYTES_LENGTH)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
// type Id is bytes32;
|
||||
|
||||
struct MarketParams {
|
||||
address loanToken;
|
||||
address collateralToken;
|
||||
address oracle;
|
||||
address irm;
|
||||
uint256 lltv;
|
||||
}
|
||||
|
||||
/// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest
|
||||
/// accrual.
|
||||
struct Position {
|
||||
uint256 supplyShares;
|
||||
uint128 borrowShares;
|
||||
uint128 collateral;
|
||||
}
|
||||
|
||||
|
||||
interface IMorpho {
|
||||
function createMarket(MarketParams memory marketParams) external;
|
||||
|
||||
function supply(
|
||||
MarketParams memory marketParams,
|
||||
uint256 assets,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
bytes calldata data
|
||||
) external returns (uint256, uint256);
|
||||
|
||||
function withdraw(
|
||||
MarketParams memory marketParams,
|
||||
uint256 assets,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
address receiver
|
||||
) external returns (uint256, uint256);
|
||||
|
||||
function borrow(
|
||||
MarketParams memory marketParams,
|
||||
uint256 assets,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
address receiver
|
||||
) external returns (uint256, uint256);
|
||||
|
||||
function repay(
|
||||
MarketParams memory marketParams,
|
||||
uint256 assets,
|
||||
uint256 shares,
|
||||
address onBehalf,
|
||||
bytes calldata data
|
||||
) external returns (uint256, uint256);
|
||||
|
||||
function supplyCollateral(MarketParams memory marketParams, uint256 assets, address onBehalf, bytes calldata data) external;
|
||||
|
||||
function withdrawCollateral(MarketParams memory marketParams, uint256 assets, address onBehalf, address receiver) external;
|
||||
|
||||
function position(bytes32 id, address user) external view returns(Position memory);
|
||||
}
|
||||
|
|
@ -1,563 +0,0 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./helpers.sol";
|
||||
import "./events.sol";
|
||||
|
||||
abstract contract MorphoBlue is Helpers, Events {
|
||||
|
||||
/// @notice Creates the market `marketParams`.
|
||||
/// @param marketParams The market to supply assets to.
|
||||
function createMarket(MarketParams memory marketParams) external {
|
||||
MORPHO_BLUE.createMarket(marketParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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 _data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function supply(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
bytes calldata _data,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(
|
||||
TokenInterface _tokenContract,
|
||||
uint256 _amt,
|
||||
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);
|
||||
|
||||
approve(_tokenContract, address(MORPHO_BLUE), _amt);
|
||||
_marketParams.loanToken = address(_tokenContract);
|
||||
|
||||
(_assets, _shares) = MORPHO_BLUE.supply(_marketParams, _assets, _shares, address(this), _data);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogSupply(address,uint256,uint256,address,bytes,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
_shares,
|
||||
address(this),
|
||||
_data,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 _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.
|
||||
* @param _data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function supplyOnBehalf(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
address _onBehalf,
|
||||
bytes calldata _data,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(_getId, _assets);
|
||||
|
||||
approve(TokenInterface(_marketParams.loanToken), address(MORPHO_BLUE), _amt);
|
||||
|
||||
(_assets, _shares) = MORPHO_BLUE.supply(_marketParams, _assets, _shares, _onBehalf, _data);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogSupply(address,uint256,uint256,address,bytes,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
_shares,
|
||||
_onBehalf,
|
||||
_data,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Supplies `assets` of collateral on behalf of `onBehalf`, optionally calling back the caller's `onMorphoSupplyCollateral` function with the given `data`.
|
||||
* @param _marketParams The market to supply assets to.(For ETH of loanToken in _marketParams: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param _assets The amount of assets to supply.
|
||||
* @param _data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function supplyCollateral(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
bytes calldata _data,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(
|
||||
TokenInterface _tokenContract,
|
||||
uint256 _amt,
|
||||
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);
|
||||
|
||||
approve(_tokenContract, address(MORPHO_BLUE), _amt);
|
||||
_marketParams.loanToken = address(_tokenContract);
|
||||
|
||||
MORPHO_BLUE.supplyCollateral(_marketParams, _assets, address(this), _data);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogSupplyCollateral(address,uint256,address,bytes,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
address(this),
|
||||
_data,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 _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.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function supplyCollateralOnBehalf(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
address _onBehalf,
|
||||
bytes calldata _data,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(_getId, _assets);
|
||||
|
||||
approve(TokenInterface(_marketParams.loanToken), address(MORPHO_BLUE), _amt);
|
||||
|
||||
MORPHO_BLUE.supplyCollateral(_marketParams, _assets, _onBehalf, _data);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogSupplyCollateral(address,uint256,address,bytes,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
_onBehalf,
|
||||
_data,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's `onMorphoSupply` function with the given `data`.
|
||||
* @dev Supplying a large amount can revert for overflow.
|
||||
* @dev 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE native token is not allowed in this mode cause of failing in withdraw of WETH.
|
||||
* @param _marketParams The market to supply assets to.
|
||||
* @param _assets The amount of assets to supply.
|
||||
* @param _onBehalf The address that already deposited position.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function withdrawCollateralOnBehalf(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
address _onBehalf,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
|
||||
uint256 _amt = getUint(_getId, _assets);
|
||||
if (_amt == uint256(-1)) {
|
||||
bytes32 _id = id(_marketParams);
|
||||
Position memory _pos = MORPHO_BLUE.position(_id, _onBehalf);
|
||||
_amt = _pos.collateral;
|
||||
}
|
||||
|
||||
MORPHO_BLUE.withdrawCollateral(_marketParams, _amt, _onBehalf, address(this));
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogWithdrawCollateral(address,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_amt,
|
||||
_onBehalf,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's `onMorphoSupply` function with the given `data`.
|
||||
* @dev Supplying a large amount can revert for overflow.
|
||||
* @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.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function withdrawCollateral(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt;
|
||||
(
|
||||
TokenInterface _tokenContract,
|
||||
,
|
||||
bool _isMax
|
||||
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);
|
||||
if (_isMax) {
|
||||
bytes32 _id = id(_marketParams);
|
||||
Position memory _pos = MORPHO_BLUE.position(_id, address(this));
|
||||
_amt = _pos.collateral;
|
||||
}
|
||||
address originToken = _marketParams.loanToken;
|
||||
_marketParams.loanToken = address(_tokenContract);
|
||||
|
||||
MORPHO_BLUE.withdrawCollateral(_marketParams, _amt, address(this), address(this));
|
||||
|
||||
convertWethToEth(originToken == ethAddr, TokenInterface(wethAddr), _amt);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogWithdraw(address,uint256,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_amt,
|
||||
_shares,
|
||||
address(this),
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's `onMorphoSupply` function with the given `data`.
|
||||
* @dev Supplying a large amount can revert for overflow.
|
||||
* @dev 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE native token is not allowed in this mode cause of failing in withdraw of WETH.
|
||||
* @param _marketParams The market to supply assets to.
|
||||
* @param _assets The amount of assets to supply.
|
||||
* @param _shares The amount of shares to mint.
|
||||
* @param _onBehalf The address that already deposited position.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function withdrawOnBehalf(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
address _onBehalf,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
|
||||
uint256 _amt = getUint(_getId, _assets);
|
||||
bool _isMax;
|
||||
if (_amt == uint256(-1)) {
|
||||
_amt = TokenInterface(_marketParams.loanToken).balanceOf(_onBehalf);
|
||||
_isMax = true;
|
||||
}
|
||||
|
||||
MORPHO_BLUE.withdraw(_marketParams, (_isMax ? 0 : _amt), (_isMax ? _amt : _shares), _onBehalf, address(this));
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogWithdraw(address,uint256,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_amt,
|
||||
_shares,
|
||||
_onBehalf,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's `onMorphoSupply` function with the given `data`.
|
||||
* @dev Supplying a large amount can revert for overflow.
|
||||
* @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.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function withdraw(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
|
||||
(
|
||||
TokenInterface _tokenContract,
|
||||
uint256 _amt,
|
||||
bool _isMax
|
||||
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);
|
||||
address originToken = _marketParams.loanToken;
|
||||
_marketParams.loanToken = address(_tokenContract);
|
||||
|
||||
(_assets, _shares) = MORPHO_BLUE.withdraw(_marketParams, (_isMax ? 0 : _amt), (_isMax ? _amt : _shares), address(this), address(this));
|
||||
|
||||
convertWethToEth(originToken == ethAddr, TokenInterface(wethAddr), _amt);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogWithdraw(address,uint256,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_amt,
|
||||
_shares,
|
||||
address(this),
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @param _marketParams The market to supply assets to.
|
||||
* @param _assets The amount of assets to supply.
|
||||
* @param _shares The amount of shares to mint.
|
||||
* @param _onBehalf The address that will own the borrow position.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens borrowed.
|
||||
*/
|
||||
function borrowOnBehalf(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
address _onBehalf,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(_getId, _assets);
|
||||
|
||||
(_assets, _shares) = MORPHO_BLUE.borrow(_marketParams, _amt, _shares, _onBehalf, address(this));
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogBorrow(address,uint256,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
_shares,
|
||||
_onBehalf,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Borrows `assets` or `shares`. receiver should be address(this)
|
||||
* @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.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens borrowed.
|
||||
*/
|
||||
function borrow(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(
|
||||
TokenInterface _tokenContract,
|
||||
uint256 _amt,
|
||||
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);
|
||||
|
||||
address _oldLoanToken = _marketParams.loanToken;
|
||||
_marketParams.loanToken = address(_tokenContract);
|
||||
|
||||
(_assets, _shares) = MORPHO_BLUE.borrow(_marketParams, _amt, _shares, address(this), address(this));
|
||||
|
||||
convertWethToEth(_oldLoanToken == ethAddr, TokenInterface(wethAddr), _amt);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogBorrow(address,uint256,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
_shares,
|
||||
address(this),
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Repays `assets` or `shares`.
|
||||
* @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.
|
||||
* @param _data Arbitrary data to pass to the `onMorphoRepay` callback. Pass empty data if not needed.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens borrowed.
|
||||
*/
|
||||
function repay(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
bytes memory _data,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(
|
||||
TokenInterface _tokenContract,
|
||||
uint256 _amt,
|
||||
bool _isMax
|
||||
) = _performEthToWethConversion(_marketParams.loanToken, _assets, _getId);
|
||||
|
||||
address _oldLoanToken = _marketParams.loanToken;
|
||||
_marketParams.loanToken = address(_tokenContract);
|
||||
|
||||
approve(TokenInterface(_marketParams.loanToken), address(MORPHO_BLUE), _amt);
|
||||
|
||||
(_assets, _shares) = MORPHO_BLUE.repay(_marketParams, (_isMax ? 0 : _amt), (_isMax ? _amt : _shares), address(this), _data);
|
||||
|
||||
convertWethToEth(_oldLoanToken == ethAddr, TokenInterface(wethAddr), _amt);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogPayback(address,uint256,uint256,address,bytes,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
_shares,
|
||||
address(this),
|
||||
_data,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Repays `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's `onMorphoReplay` function with the given `data`.
|
||||
* @dev 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE native token is not allowed in this mode cause of failing in withdraw of WETH.
|
||||
* @param _marketParams The market to supply assets to.
|
||||
* @param _assets The amount of assets to supply.
|
||||
* @param _shares The amount of shares to mint.
|
||||
* @param _onBehalf The address that will own the borrow position.
|
||||
* @param _data Arbitrary data to pass to the `onMorphoRepay` callback. Pass empty data if not needed.
|
||||
* @param _getId ID to retrieve amt.
|
||||
* @param _setId ID stores the amount of tokens borrowed.
|
||||
*/
|
||||
function repayOnBehalf(
|
||||
MarketParams memory _marketParams,
|
||||
uint256 _assets,
|
||||
uint256 _shares,
|
||||
address _onBehalf,
|
||||
bytes memory _data,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(_getId, _assets);
|
||||
bool _isMax;
|
||||
if (_amt == uint256(-1)) {
|
||||
_amt = TokenInterface(_marketParams.loanToken).balanceOf(_onBehalf);
|
||||
_isMax = true;
|
||||
}
|
||||
|
||||
approve(TokenInterface(_marketParams.loanToken), address(MORPHO_BLUE), _amt);
|
||||
|
||||
(_assets, _shares) = MORPHO_BLUE.repay(_marketParams, (_isMax ? 0 : _amt), (_isMax ? _amt : _shares), address(this), _data);
|
||||
|
||||
setUint(_setId, _amt);
|
||||
|
||||
_eventName = "LogPayback(address,uint256,uint256,address,bytes,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_marketParams.loanToken,
|
||||
_assets,
|
||||
_shares,
|
||||
address(this),
|
||||
_data,
|
||||
_getId,
|
||||
_setId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2MorphoBlue is MorphoBlue {
|
||||
string public constant name = "Morpho-Blue-v1.0";
|
||||
}
|
Loading…
Reference in New Issue
Block a user