mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
new functions added for Avae and Compound
This commit is contained in:
parent
0674be8823
commit
cc8e7b71b0
|
@ -11,26 +11,62 @@ contract Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event LogDepositWithMaxGas(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 maxGasForMatching,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogDepositOnBehalf(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
address onBehalf,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
event LogBorrow(
|
event LogBorrow(
|
||||||
bool isETH,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
address poolTokenAddress,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogWithdraw(
|
event LogBorrowWithMaxGas(
|
||||||
bool isETH,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
address poolTokenAddress,
|
||||||
uint256 amt,
|
uint256 amount,
|
||||||
|
uint256 maxGasForMatching,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdraw(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
uint256 amount,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogPayback(
|
event LogPayback(
|
||||||
bool isETH,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
address poolTokenAddress,
|
||||||
uint256 amt,
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogPaybackOnBehalf(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
address onBehalf,
|
||||||
|
uint256 amount,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,8 +9,21 @@ interface IMorphoCore {
|
||||||
uint256 _amount
|
uint256 _amount
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
|
function supply(
|
||||||
|
address _poolToken,
|
||||||
|
address _onBehalf,
|
||||||
|
uint256 _amount,
|
||||||
|
uint256 _maxGasForMatching
|
||||||
|
) external;
|
||||||
|
|
||||||
function borrow(address _poolTokenAddress, uint256 _amount) 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 withdraw(address _poolTokenAddress, uint256 _amount) external;
|
||||||
|
|
||||||
function repay(
|
function repay(
|
||||||
|
@ -19,13 +32,6 @@ interface IMorphoCore {
|
||||||
uint256 _amount
|
uint256 _amount
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
function liquidate(
|
|
||||||
address _poolTokenBorrowedAddress,
|
|
||||||
address _poolTokenCollateralAddress,
|
|
||||||
address _borrower,
|
|
||||||
uint256 _amount
|
|
||||||
) external;
|
|
||||||
|
|
||||||
function claimRewards(
|
function claimRewards(
|
||||||
address[] calldata _tokenAddresses,
|
address[] calldata _tokenAddresses,
|
||||||
bool _tradeForMorphoToken
|
bool _tradeForMorphoToken
|
||||||
|
|
|
@ -18,7 +18,6 @@ abstract contract MorphoAave is Helpers, Events {
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
address _poolTokenAddress,
|
address _poolTokenAddress,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
// uint256 _maxGasForMatching, // optional
|
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
)
|
)
|
||||||
|
@ -53,7 +52,121 @@ abstract contract MorphoAave is Helpers, Events {
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
// _maxGasForMatching,
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit ETH/ERC20_Token with Max Gas.
|
||||||
|
* @notice Deposit a token to Morpho Aave for lending / collaterization with max gas.
|
||||||
|
* @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE).
|
||||||
|
* @param _poolTokenAddress The address of aToken to deposit.(For ETH: aWETH address).
|
||||||
|
* @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`).
|
||||||
|
* @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 deposited.
|
||||||
|
*/
|
||||||
|
function depositWithMaxGas(
|
||||||
|
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);
|
||||||
|
|
||||||
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
|
|
||||||
|
TokenInterface _tokenContract = _isETH
|
||||||
|
? TokenInterface(wethAddr)
|
||||||
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
|
if (_amt == uint256(-1)) {
|
||||||
|
_amt = _isETH
|
||||||
|
? address(this).balance
|
||||||
|
: _tokenContract.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
|
approve(_tokenContract, address(morphoAave), _amt);
|
||||||
|
|
||||||
|
morphoAave.supply(
|
||||||
|
_poolTokenAddress,
|
||||||
|
address(this),
|
||||||
|
_amt,
|
||||||
|
_maxGasForMatching
|
||||||
|
);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogDepositWithMaxGas(address,address,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_amt,
|
||||||
|
_maxGasForMatching,
|
||||||
|
_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 _poolTokenAddress The address of aToken to deposit.(For ETH: aWETH address)
|
||||||
|
* @param _onBehalf The address of user on behalf to deposit.
|
||||||
|
* @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 depositOnBehalf(
|
||||||
|
address _tokenAddress,
|
||||||
|
address _poolTokenAddress,
|
||||||
|
address _onBehalf,
|
||||||
|
uint256 _amount,
|
||||||
|
uint256 _getId,
|
||||||
|
uint256 _setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
|
||||||
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
|
|
||||||
|
TokenInterface _tokenContract = _isETH
|
||||||
|
? TokenInterface(wethAddr)
|
||||||
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
|
if (_amt == uint256(-1)) {
|
||||||
|
_amt = _isETH
|
||||||
|
? address(this).balance
|
||||||
|
: _tokenContract.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
|
approve(_tokenContract, address(morphoAave), _amt);
|
||||||
|
|
||||||
|
morphoAave.supply(_poolTokenAddress, _onBehalf, _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogDepositOnBehalf(address,address,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_onBehalf,
|
||||||
|
_amt,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
);
|
);
|
||||||
|
@ -72,7 +185,6 @@ abstract contract MorphoAave is Helpers, Events {
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
address _poolTokenAddress,
|
address _poolTokenAddress,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
// uint256 _maxGasForMatching,
|
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
)
|
)
|
||||||
|
@ -90,12 +202,54 @@ abstract contract MorphoAave is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogBorrow(bool,address,uint256,uint256,uint256)";
|
_eventName = "LogBorrow(address,address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_isETH,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
// _maxGasForMatching,
|
_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);
|
||||||
|
|
||||||
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
|
|
||||||
|
morphoAave.borrow(_poolTokenAddress, _amt, _maxGasForMatching);
|
||||||
|
|
||||||
|
if (_isETH) convertWethToEth(_isETH, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogBorrowWithMaxGas(address,address,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_amt,
|
||||||
|
_maxGasForMatching,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
);
|
);
|
||||||
|
@ -137,9 +291,9 @@ abstract contract MorphoAave is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogWithdraw(bool,address,uint256,uint256,uint256)";
|
_eventName = "LogWithdraw(address,address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_isETH,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
_getId,
|
_getId,
|
||||||
|
@ -169,26 +323,33 @@ abstract contract MorphoAave is Helpers, Events {
|
||||||
{
|
{
|
||||||
bool _isETH = _tokenAddress == ethAddr;
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
uint256 _amt = getUint(_getId, _amount);
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
address _token = _isETH ? wethAddr : _tokenAddress;
|
|
||||||
|
TokenInterface _tokenContract = _isETH
|
||||||
|
? TokenInterface(wethAddr)
|
||||||
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
if (_amt == uint256(-1)) {
|
if (_amt == uint256(-1)) {
|
||||||
(, , , _amt) = morphoAaveLens._getCurrentBorrowBalanceInOf(
|
uint256 _amtDSA = _isETH
|
||||||
_poolTokenAddress,
|
? address(this).balance
|
||||||
address(this)
|
: _tokenContract.balanceOf(address(this));
|
||||||
);
|
|
||||||
|
(, , , uint256 _amtDebt) = morphoAaveLens
|
||||||
|
._getCurrentBorrowBalanceInOf(_poolTokenAddress, address(this));
|
||||||
|
|
||||||
|
_amt = _amtDSA <= _amtDebt ? _amtDSA : _amtDebt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_isETH) convertEthToWeth(_isETH, TokenInterface(_token), _amt);
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
approve(TokenInterface(_token), address(morphoAave), _amt);
|
approve(_tokenContract, address(morphoAave), _amt);
|
||||||
|
|
||||||
morphoAave.repay(_poolTokenAddress, address(this), _amt);
|
morphoAave.repay(_poolTokenAddress, address(this), _amt);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogPayback(bool,address,uint256,uint256,uint256)";
|
_eventName = "LogPayback(address,address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_isETH,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
_getId,
|
_getId,
|
||||||
|
@ -196,6 +357,65 @@ abstract contract MorphoAave 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.
|
||||||
|
* @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) = morphoAaveLens
|
||||||
|
._getCurrentBorrowBalanceInOf(_poolTokenAddress, _onBehalf);
|
||||||
|
|
||||||
|
_amt = _amtDSA <= _amtDebt ? _amtDSA : _amtDebt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
|
approve(_tokenContract, address(morphoAave), _amt);
|
||||||
|
|
||||||
|
morphoAave.repay(_poolTokenAddress, _onBehalf, _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_onBehalf,
|
||||||
|
_amt,
|
||||||
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Claim rewards.
|
* @dev Claim rewards.
|
||||||
* @notice Claim rewards for the given assets from underlying protocol.
|
* @notice Claim rewards for the given assets from underlying protocol.
|
||||||
|
@ -203,7 +423,7 @@ abstract contract MorphoAave is Helpers, Events {
|
||||||
* @param _tradeForMorphoToken Whether or not to trade reward tokens for MORPHO tokens.
|
* @param _tradeForMorphoToken Whether or not to trade reward tokens for MORPHO tokens.
|
||||||
*/
|
*/
|
||||||
function claim(
|
function claim(
|
||||||
address[] calldata _poolTokenAddresses, //todo: eth will be claimed as weth currently?
|
address[] calldata _poolTokenAddresses,
|
||||||
bool _tradeForMorphoToken
|
bool _tradeForMorphoToken
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
|
|
|
@ -11,16 +11,43 @@ contract Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event LogDepositWithMaxGas(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 maxGasForMatching,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogDepositOnBehalf(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
address onBehalf,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
event LogBorrow(
|
event LogBorrow(
|
||||||
bool isETH,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
address poolTokenAddress,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event LogBorrowWithMaxGas(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 maxGasForMatching,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
event LogWithdraw(
|
event LogWithdraw(
|
||||||
bool isETH,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
address poolTokenAddress,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
@ -28,12 +55,21 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogPayback(
|
event LogPayback(
|
||||||
bool isETH,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
address poolTokenAddress,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event LogPaybackOnBehalf(
|
||||||
|
address tokenAddress,
|
||||||
|
address poolTokenAddress,
|
||||||
|
address onBehalf,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
event LogClaimed(address[] tokenAddresses, bool tradeForMorphoToken);
|
event LogClaimed(address[] tokenAddresses, bool tradeForMorphoToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,21 @@ interface IMorphoCore {
|
||||||
uint256 _amount
|
uint256 _amount
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
|
function supply(
|
||||||
|
address _poolTokenAddress,
|
||||||
|
address _onBehalf,
|
||||||
|
uint256 _amount,
|
||||||
|
uint256 _maxGasForMatching
|
||||||
|
) external;
|
||||||
|
|
||||||
function borrow(address _poolTokenAddress, uint256 _amount) external;
|
function borrow(address _poolTokenAddress, uint256 _amount) external;
|
||||||
|
|
||||||
|
function borrow(
|
||||||
|
address _poolTokenAddress,
|
||||||
|
uint256 _amount,
|
||||||
|
uint256 _maxGasForMatching
|
||||||
|
) external;
|
||||||
|
|
||||||
function withdraw(address _poolTokenAddress, uint256 _amount) external;
|
function withdraw(address _poolTokenAddress, uint256 _amount) external;
|
||||||
|
|
||||||
function repay(
|
function repay(
|
||||||
|
@ -19,14 +32,6 @@ interface IMorphoCore {
|
||||||
uint256 _amount
|
uint256 _amount
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
function liquidate(
|
|
||||||
address _poolTokenBorrowedAddress,
|
|
||||||
address _poolTokenCollateralAddress,
|
|
||||||
address _borrower,
|
|
||||||
uint256 _amount
|
|
||||||
) external;
|
|
||||||
|
|
||||||
// (For AAVEV2: (aToken or variable debt token), COMPOUNDV2: cToken addresses)
|
|
||||||
function claimRewards(
|
function claimRewards(
|
||||||
address[] calldata _tokenAddresses,
|
address[] calldata _tokenAddresses,
|
||||||
bool _tradeForMorphoToken
|
bool _tradeForMorphoToken
|
||||||
|
|
|
@ -18,7 +18,6 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
address _poolTokenAddress,
|
address _poolTokenAddress,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
// uint256 _maxGasForMatching, // optional
|
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
)
|
)
|
||||||
|
@ -52,7 +51,119 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
// _maxGasForMatching,
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit ETH/ERC20_Token.
|
||||||
|
* @notice Deposit a token to Morpho Compound for lending / collaterization with max gas.
|
||||||
|
* @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param _poolTokenAddress The address of cToken to deposit.(For ETH: cWETH address).
|
||||||
|
* @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`).
|
||||||
|
* @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 deposited.
|
||||||
|
*/
|
||||||
|
function depositWithMaxGas(
|
||||||
|
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);
|
||||||
|
|
||||||
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
|
|
||||||
|
TokenInterface _tokenContract = _isETH
|
||||||
|
? TokenInterface(wethAddr)
|
||||||
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
|
if (_amt == uint256(-1)) {
|
||||||
|
_amt = _isETH
|
||||||
|
? address(this).balance
|
||||||
|
: _tokenContract.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
|
approve(_tokenContract, address(morphoCompound), _amt);
|
||||||
|
morphoCompound.supply(
|
||||||
|
_poolTokenAddress,
|
||||||
|
address(this),
|
||||||
|
_amt,
|
||||||
|
_maxGasForMatching
|
||||||
|
);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "depositWithMaxGas(address,address,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_amt,
|
||||||
|
_maxGasForMatching,
|
||||||
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit ETH/ERC20_Token.
|
||||||
|
* @notice Deposit a token to Morpho Compound for lending / collaterization on behalf of a user.
|
||||||
|
* @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param _poolTokenAddress The address of cToken to deposit.(For ETH: cWETH address)
|
||||||
|
* @param _onBehalf The address of user on behalf to deposit.
|
||||||
|
* @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 depositOnBehalf(
|
||||||
|
address _tokenAddress,
|
||||||
|
address _poolTokenAddress,
|
||||||
|
address _onBehalf,
|
||||||
|
uint256 _amount,
|
||||||
|
uint256 _getId,
|
||||||
|
uint256 _setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
|
||||||
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
|
|
||||||
|
TokenInterface _tokenContract = _isETH
|
||||||
|
? TokenInterface(wethAddr)
|
||||||
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
|
if (_amt == uint256(-1)) {
|
||||||
|
_amt = _isETH
|
||||||
|
? address(this).balance
|
||||||
|
: _tokenContract.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
|
approve(_tokenContract, address(morphoCompound), _amt);
|
||||||
|
morphoCompound.supply(_poolTokenAddress, _onBehalf, _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogDeposit(address,address,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_onBehalf,
|
||||||
|
_amt,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
);
|
);
|
||||||
|
@ -71,7 +182,6 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
address _poolTokenAddress,
|
address _poolTokenAddress,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
// uint256 _maxGasForMatching,
|
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
)
|
)
|
||||||
|
@ -89,12 +199,54 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogBorrow(bool,address,uint256,uint256,uint256)";
|
_eventName = "LogBorrow(address,address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_isETH,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
// _maxGasForMatching,
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Borrow ETH/ERC20_Token.
|
||||||
|
* @notice Borrow a token from Morpho Compound with max gas.
|
||||||
|
* @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param _poolTokenAddress The address of cToken to borrow.(For ETH: cWETH 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);
|
||||||
|
|
||||||
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
|
|
||||||
|
morphoCompound.borrow(_poolTokenAddress, _amt, _maxGasForMatching);
|
||||||
|
|
||||||
|
if (_isETH) convertWethToEth(_isETH, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogBorrowWithMaxGas(address,address,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_amt,
|
||||||
|
_maxGasForMatching,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
);
|
);
|
||||||
|
@ -124,11 +276,12 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
bool _isETH = _tokenAddress == ethAddr;
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
address _token = _isETH ? wethAddr : _tokenAddress;
|
address _token = _isETH ? wethAddr : _tokenAddress;
|
||||||
|
|
||||||
if (_amt == uint256(-1))
|
if (_amt == uint256(-1)) {
|
||||||
(, , _amt) = morphoCompoundLens.getCurrentSupplyBalanceInOf(
|
(, , _amt) = morphoCompoundLens.getCurrentSupplyBalanceInOf(
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
address(this)
|
address(this)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
morphoCompound.withdraw(_poolTokenAddress, _amt);
|
morphoCompound.withdraw(_poolTokenAddress, _amt);
|
||||||
|
|
||||||
|
@ -136,9 +289,9 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogWithdraw(bool,address,uint256,uint256,uint256)";
|
_eventName = "LogWithdraw(address,address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_isETH,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
_getId,
|
_getId,
|
||||||
|
@ -168,26 +321,33 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
{
|
{
|
||||||
bool _isETH = _tokenAddress == ethAddr;
|
bool _isETH = _tokenAddress == ethAddr;
|
||||||
uint256 _amt = getUint(_getId, _amount);
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
address _token = _isETH ? wethAddr : _tokenAddress;
|
|
||||||
|
TokenInterface _tokenContract = _isETH
|
||||||
|
? TokenInterface(wethAddr)
|
||||||
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
if (_amt == uint256(-1)) {
|
if (_amt == uint256(-1)) {
|
||||||
(, , _amt) = morphoCompoundLens.getCurrentBorrowBalanceInOf(
|
uint256 _amtDSA = _isETH
|
||||||
_poolTokenAddress,
|
? address(this).balance
|
||||||
address(this)
|
: _tokenContract.balanceOf(address(this));
|
||||||
);
|
|
||||||
|
(, , uint256 _amtDebt) = morphoCompoundLens
|
||||||
|
.getCurrentBorrowBalanceInOf(_poolTokenAddress, address(this));
|
||||||
|
|
||||||
|
_amt = _amtDSA <= _amtDebt ? _amtDSA : _amtDebt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_isETH) convertEthToWeth(_isETH, TokenInterface(_token), _amt);
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
approve(TokenInterface(_token), address(morphoCompound), _amt);
|
approve(_tokenContract, address(morphoCompound), _amt);
|
||||||
|
|
||||||
morphoCompound.repay(_poolTokenAddress, address(this), _amt);
|
morphoCompound.repay(_poolTokenAddress, address(this), _amt);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogPayback(bool,address,uint256,uint256,uint256)";
|
_eventName = "LogPayback(address,address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_isETH,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
_poolTokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
_getId,
|
_getId,
|
||||||
|
@ -195,6 +355,65 @@ abstract contract MorphoCompound is Helpers, Events {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Payback ETH/ERC20_Token.
|
||||||
|
* @notice Payback a token to Morpho Compound on behalf of a user.
|
||||||
|
* @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param _poolTokenAddress The address of cToken to payback.(For ETH: cWETH 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) = morphoCompoundLens
|
||||||
|
.getCurrentBorrowBalanceInOf(_poolTokenAddress, _onBehalf);
|
||||||
|
|
||||||
|
_amt = _amtDSA <= _amtDebt ? _amtDSA : _amtDebt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isETH) convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
|
approve(_tokenContract, address(morphoCompound), _amt);
|
||||||
|
|
||||||
|
morphoCompound.repay(_poolTokenAddress, _onBehalf, _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_poolTokenAddress,
|
||||||
|
_onBehalf,
|
||||||
|
_amt,
|
||||||
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Claim rewards.
|
* @dev Claim rewards.
|
||||||
* @notice Claim rewards for the given assets from underlying protocol.
|
* @notice Claim rewards for the given assets from underlying protocol.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user