mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
update connector
This commit is contained in:
parent
7482153adb
commit
0624c0a4ca
|
@ -35,19 +35,6 @@ contract Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogDepositWithPermit(
|
|
||||||
address tokenAddress,
|
|
||||||
uint256 amount,
|
|
||||||
address onBehalf,
|
|
||||||
uint256 maxIteration,
|
|
||||||
uint256 time,
|
|
||||||
uint8 v,
|
|
||||||
bytes32 r,
|
|
||||||
bytes32 s,
|
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
|
||||||
);
|
|
||||||
|
|
||||||
event LogDepositCollateral(
|
event LogDepositCollateral(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
|
@ -63,22 +50,18 @@ contract Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogDepositCollateralWithPermit(
|
event LogBorrow(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
address onBehalf,
|
address receiver,
|
||||||
uint256 maxIteration,
|
|
||||||
uint256 time,
|
|
||||||
uint8 v,
|
|
||||||
bytes32 r,
|
|
||||||
bytes32 s,
|
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogBorrow(
|
event LogBorrowOnBehalf(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
|
address onBehalf,
|
||||||
address receiver,
|
address receiver,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -96,8 +79,8 @@ contract Events {
|
||||||
event LogBorrowOnBehalfWithMaxIterations(
|
event LogBorrowOnBehalfWithMaxIterations(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
address receiver,
|
|
||||||
address onBehalf,
|
address onBehalf,
|
||||||
|
address receiver,
|
||||||
uint256 maxIteration,
|
uint256 maxIteration,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -105,15 +88,49 @@ contract Events {
|
||||||
|
|
||||||
event LogWithdraw(
|
event LogWithdraw(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
|
address receiver,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdrawOnBehalf(
|
||||||
|
address tokenAddress,
|
||||||
|
uint256 amount,
|
||||||
|
address onBehalf,
|
||||||
|
address receiver,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdrawWithMaxIterations(
|
||||||
|
address tokenAddress,
|
||||||
|
uint256 amount,
|
||||||
|
address receiver,
|
||||||
|
uint256 maxIteration,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdrawCollateral(
|
||||||
|
address tokenAddress,
|
||||||
|
uint256 amount,
|
||||||
|
address receiver,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdrawCollateralOnBehalf(
|
||||||
|
address tokenAddress,
|
||||||
|
uint256 amount,
|
||||||
|
address onBehalf,
|
||||||
|
address receiver,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogPayback(
|
event LogPayback(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -121,9 +138,8 @@ contract Events {
|
||||||
|
|
||||||
event LogPaybackOnBehalf(
|
event LogPaybackOnBehalf(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
address poolTokenAddress,
|
|
||||||
address onBehalf,
|
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
|
address onBehalf,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,12 +5,13 @@ import "./interface.sol";
|
||||||
import "../../common/stores.sol";
|
import "../../common/stores.sol";
|
||||||
import "../../common/basic.sol";
|
import "../../common/basic.sol";
|
||||||
import "../../common/interfaces.sol";
|
import "../../common/interfaces.sol";
|
||||||
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
|
|
||||||
abstract contract Helpers is Stores, Basic {
|
abstract contract Helpers is Stores, Basic, Ownable {
|
||||||
IMorphoCore public constant MORPHO_AAVE_V3 =
|
IMorphoCore public constant MORPHO_AAVE_V3 =
|
||||||
IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
|
IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
|
||||||
|
|
||||||
uint256 public constant MAX_ITERATION = 10;
|
uint256 public max_iteration = 10;
|
||||||
|
|
||||||
IMorphoAaveLens public constant MORPHO_AAVE_LENS =
|
IMorphoAaveLens public constant MORPHO_AAVE_LENS =
|
||||||
IMorphoAaveLens(0x507fA343d0A90786d86C7cd885f5C49263A91FF4);
|
IMorphoAaveLens(0x507fA343d0A90786d86C7cd885f5C49263A91FF4);
|
||||||
|
@ -31,4 +32,8 @@ abstract contract Helpers is Stores, Basic {
|
||||||
if (_amt == uint256(-1)) _amt = _tokenContract.balanceOf(address(this));
|
if (_amt == uint256(-1)) _amt = _tokenContract.balanceOf(address(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setMaxIteration(uint256 _iter) external onlyOwner {
|
||||||
|
max_iteration = _iter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,34 +3,6 @@ pragma solidity ^0.7.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
interface IMorphoCore {
|
interface IMorphoCore {
|
||||||
// function supply(
|
|
||||||
// address _poolTokenAddress,
|
|
||||||
// address _onBehalf,
|
|
||||||
// uint256 _amount
|
|
||||||
// ) external;
|
|
||||||
|
|
||||||
// function supply(
|
|
||||||
// address _poolToken,
|
|
||||||
// address _onBehalf,
|
|
||||||
// uint256 _amount,
|
|
||||||
// uint256 _maxGasForMatching
|
|
||||||
// ) external;
|
|
||||||
|
|
||||||
// function borrow(address _poolTokenAddress, uint256 _amount) external;
|
|
||||||
|
|
||||||
// function borrow(
|
|
||||||
// address _poolToken,
|
|
||||||
// uint256 _amount,
|
|
||||||
// uint256 _maxGasForMatching
|
|
||||||
// ) external;
|
|
||||||
|
|
||||||
// function withdraw(address _poolTokenAddress, uint256 _amount) external;
|
|
||||||
|
|
||||||
// function repay(
|
|
||||||
// address _poolTokenAddress,
|
|
||||||
// address _onBehalf,
|
|
||||||
// uint256 _amount
|
|
||||||
// ) external;
|
|
||||||
struct Signature {
|
struct Signature {
|
||||||
uint8 v;
|
uint8 v;
|
||||||
bytes32 r;
|
bytes32 r;
|
||||||
|
@ -84,23 +56,3 @@ interface IMorphoCore {
|
||||||
external
|
external
|
||||||
returns (uint256 withdrawn);
|
returns (uint256 withdrawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IMorphoAaveLens {
|
|
||||||
function getCurrentBorrowBalanceInOf(address _poolToken, address _user)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (
|
|
||||||
uint256 balanceInP2P,
|
|
||||||
uint256 balanceOnPool,
|
|
||||||
uint256 totalBalance
|
|
||||||
);
|
|
||||||
|
|
||||||
function getCurrentSupplyBalanceInOf(address _poolToken, address _user)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (
|
|
||||||
uint256 balanceInP2P,
|
|
||||||
uint256 balanceOnPool,
|
|
||||||
uint256 totalBalance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
|
|
||||||
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
||||||
|
|
||||||
MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), MAX_ITERATION);
|
MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), max_iteration);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
@ -48,14 +48,14 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
* @notice Deposit a token to Morpho Aave for lending / collaterization.
|
* @notice Deposit a token to Morpho Aave for lending / collaterization.
|
||||||
* @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @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 _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`)
|
||||||
* @param _onBehalf The address of user on behalf to deposit.
|
* @param _maxIteration The maximum number of iterations allowed during the matching process.
|
||||||
* @param _getId ID to retrieve amt.
|
* @param _getId ID to retrieve amt.
|
||||||
* @param _setId ID stores the amount of tokens deposited.
|
* @param _setId ID stores the amount of tokens deposited.
|
||||||
*/
|
*/
|
||||||
function depositWithMaxIterations(
|
function depositWithMaxIterations(
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
address _onBehalf,
|
address _maxIteration,
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
)
|
)
|
||||||
|
@ -70,15 +70,15 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
|
|
||||||
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
||||||
|
|
||||||
MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION);
|
MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), _maxIteration);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogDepositWithMaxIterations(address,uint256,address,uint256,uint256)";
|
_eventName = "LogDepositWithMaxIterations(address,uint256,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
_onBehalf,
|
_maxIteration,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
);
|
);
|
||||||
|
@ -111,7 +111,7 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
|
|
||||||
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
||||||
|
|
||||||
MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION);
|
MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, max_iteration);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
* @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param _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 _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`)
|
||||||
* @param _onBehalf The address of user on behalf to deposit.
|
* @param _onBehalf The address of user on behalf to deposit.
|
||||||
* @param _onBehalf The address of user on behalf to deposit.
|
* @param _maxIteration The maximum number of iterations allowed during the matching process.
|
||||||
* @param _getId ID to retrieve amt.
|
* @param _getId ID to retrieve amt.
|
||||||
* @param _setId ID stores the amount of tokens deposited.
|
* @param _setId ID stores the amount of tokens deposited.
|
||||||
*/
|
*/
|
||||||
|
@ -169,55 +169,6 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx.
|
|
||||||
// * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
|
||||||
// * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`)
|
|
||||||
// * @param _onBehalf The address of user on behalf to deposit.
|
|
||||||
// * @param _maxIterations The maximum number of iterations allowed during the matching process.
|
|
||||||
// * @param _signature The permit2 signature.
|
|
||||||
// * @param _getId ID to retrieve amt.
|
|
||||||
// * @param _setId ID stores the amount of tokens deposited.
|
|
||||||
// */
|
|
||||||
// function depositWithPermit(
|
|
||||||
// address _tokenAddress,
|
|
||||||
// uint256 _amount,
|
|
||||||
// address _onBehalf,
|
|
||||||
// uint256 _maxIterations,
|
|
||||||
// Signature calldata _signature,
|
|
||||||
// uint256 _getId,
|
|
||||||
// uint256 _setId
|
|
||||||
// )
|
|
||||||
// external
|
|
||||||
// payable
|
|
||||||
// returns (string memory _eventName, bytes memory _eventParam)
|
|
||||||
// {
|
|
||||||
// (
|
|
||||||
// TokenInterface _tokenContract,
|
|
||||||
// uint256 _amt
|
|
||||||
// ) = _performEthToWethConversion(_tokenAddress, _amount, _getId);
|
|
||||||
|
|
||||||
// approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
|
||||||
|
|
||||||
// MORPHO_AAVE_V3.supplyWithPermit(_tokenContract, _amt, _onBehalf, _maxIterations, block.timestamp, _signature);
|
|
||||||
|
|
||||||
// setUint(_setId, _amt);
|
|
||||||
|
|
||||||
// _eventName = "LogDepositWithPermit(address,uint256,address,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)";
|
|
||||||
// _eventParam = abi.encode(
|
|
||||||
// _tokenAddress,
|
|
||||||
// _amt,
|
|
||||||
// _onBehalf,
|
|
||||||
// _maxIterations,
|
|
||||||
// block.timestamp,
|
|
||||||
// _signature.v,
|
|
||||||
// _signature.r,
|
|
||||||
// _signature.s,
|
|
||||||
// _getId,
|
|
||||||
// _setId
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Deposit ETH/ERC20_Token on behalf of a user.
|
* @dev Deposit ETH/ERC20_Token on behalf of a user.
|
||||||
* @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user.
|
* @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user.
|
||||||
|
@ -297,52 +248,6 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx.
|
|
||||||
// * @param _tokenAddress The address of underlying token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
|
||||||
// * @param _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`)
|
|
||||||
// * @param _onBehalf The address of user on behalf to deposit.
|
|
||||||
// * @param _signature The permit2 signature.
|
|
||||||
// * @param _getId ID to retrieve amt.
|
|
||||||
// * @param _setId ID stores the amount of tokens deposited.
|
|
||||||
// */
|
|
||||||
// function depositCollateralWithPermit(
|
|
||||||
// address _tokenAddress,
|
|
||||||
// uint256 _amount,
|
|
||||||
// address _onBehalf,
|
|
||||||
// Signature calldata _signature,
|
|
||||||
// uint256 _getId,
|
|
||||||
// uint256 _setId
|
|
||||||
// )
|
|
||||||
// external
|
|
||||||
// payable
|
|
||||||
// returns (string memory _eventName, bytes memory _eventParam)
|
|
||||||
// {
|
|
||||||
// (
|
|
||||||
// TokenInterface _tokenContract,
|
|
||||||
// uint256 _amt
|
|
||||||
// ) = _performEthToWethConversion(_tokenAddress, _amount, _getId);
|
|
||||||
|
|
||||||
// approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
|
||||||
|
|
||||||
// MORPHO_AAVE_V3.supplyCollateralWithPermit(_tokenContract, _amt, _onBehalf, block.timestamp, _signature);
|
|
||||||
|
|
||||||
// setUint(_setId, _amt);
|
|
||||||
|
|
||||||
// _eventName = "LogDepositCollateralWithPermit(address,uint256,address,uint256,uint8,bytes32,bytes32,uint256,uint256)";
|
|
||||||
// _eventParam = abi.encode(
|
|
||||||
// _tokenAddress,
|
|
||||||
// _amt,
|
|
||||||
// _onBehalf,
|
|
||||||
// block.timestamp,
|
|
||||||
// _signature.v,
|
|
||||||
// _signature.r,
|
|
||||||
// _signature.s,
|
|
||||||
// _getId,
|
|
||||||
// _setId
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Borrow ETH/ERC20_Token.
|
* @dev Borrow ETH/ERC20_Token.
|
||||||
* @notice Borrow a token from Morpho Aave.
|
* @notice Borrow a token from Morpho Aave.
|
||||||
|
@ -364,7 +269,7 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
{
|
{
|
||||||
uint256 _amt = getUint(_getId, _amount);
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
|
||||||
MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION);
|
MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, max_iteration);
|
||||||
|
|
||||||
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
|
@ -391,8 +296,8 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
function borrowOnBehalf(
|
function borrowOnBehalf(
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
address _receiver,
|
|
||||||
address _onBehalf,
|
address _onBehalf,
|
||||||
|
address _receiver,
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
)
|
)
|
||||||
|
@ -402,16 +307,17 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
{
|
{
|
||||||
uint256 _amt = getUint(_getId, _amount);
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
|
||||||
MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION);
|
MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, max_iteration);
|
||||||
|
|
||||||
convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt);
|
convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogBorrowOnBehalf(address,uint256,addresss,uint256,uint256)";
|
_eventName = "LogBorrowOnBehalf(address,uint256,addresss,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
|
_onBehalf,
|
||||||
_receiver,
|
_receiver,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
|
@ -490,6 +396,7 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_amt,
|
_amt,
|
||||||
|
_onBehalf,
|
||||||
_receiver,
|
_receiver,
|
||||||
_maxIteration,
|
_maxIteration,
|
||||||
_getId,
|
_getId,
|
||||||
|
@ -497,60 +404,18 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @dev Borrow ETH/ERC20_Token with max gas.
|
|
||||||
// * @notice Borrow a token from Morpho Aave with max gas.
|
|
||||||
// * @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE).
|
|
||||||
// * @param _poolTokenAddress The address of aToken to borrow.(For ETH: aWETH address).
|
|
||||||
// * @param _amount The amount of the token (in underlying) to borrow.
|
|
||||||
// * @param _maxGasForMatching The maximum amount of gas to consume within a matching engine loop.
|
|
||||||
// * @param _getId ID to retrieve amt.
|
|
||||||
// * @param _setId ID stores the amount of tokens borrowed.
|
|
||||||
// */
|
|
||||||
// function borrowWithMaxGas(
|
|
||||||
// address _tokenAddress,
|
|
||||||
// address _poolTokenAddress,
|
|
||||||
// uint256 _amount,
|
|
||||||
// uint256 _maxGasForMatching,
|
|
||||||
// uint256 _getId,
|
|
||||||
// uint256 _setId
|
|
||||||
// )
|
|
||||||
// external
|
|
||||||
// payable
|
|
||||||
// returns (string memory _eventName, bytes memory _eventParam)
|
|
||||||
// {
|
|
||||||
// uint256 _amt = getUint(_getId, _amount);
|
|
||||||
|
|
||||||
// MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt, _maxGasForMatching);
|
|
||||||
|
|
||||||
// convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
|
||||||
|
|
||||||
// setUint(_setId, _amt);
|
|
||||||
|
|
||||||
// _eventName = "LogBorrowWithMaxGas(address,address,uint256,uint256,uint256,uint256)";
|
|
||||||
// _eventParam = abi.encode(
|
|
||||||
// _tokenAddress,
|
|
||||||
// _poolTokenAddress,
|
|
||||||
// _amt,
|
|
||||||
// _maxGasForMatching,
|
|
||||||
// _getId,
|
|
||||||
// _setId
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Withdraw ETH/ERC20_Token.
|
* @dev Withdraw ETH/ERC20_Token.
|
||||||
* @notice Withdraw a token from Morpho Aave.
|
* @notice Withdraw a token from Morpho Aave.
|
||||||
* @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param _poolTokenAddress The address of aToken to withdraw.(For ETH: aWETH address)
|
|
||||||
* @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`)
|
* @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`)
|
||||||
* @param _getId ID to retrieve amt.
|
* @param _getId ID to retrieve amt.
|
||||||
* @param _setId ID stores the amount of tokens withdrawed.
|
* @param _setId ID stores the amount of tokens withdrawed.
|
||||||
*/
|
*/
|
||||||
function withdraw(
|
function withdraw(
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
address _poolTokenAddress,
|
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
|
address _receiver,
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
)
|
)
|
||||||
|
@ -559,23 +424,153 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt = getUint(_getId, _amount);
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
if (_amt == uint256(-1))
|
MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, address(this), _receiver, max_iteration);
|
||||||
(, , _amt) = MORPHO_AAVE_LENS.getCurrentSupplyBalanceInOf(
|
|
||||||
_poolTokenAddress,
|
|
||||||
address(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
MORPHO_AAVE_V3.withdraw(_poolTokenAddress, _amt);
|
|
||||||
|
|
||||||
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogWithdraw(address,address,uint256,uint256,uint256)";
|
_eventName = "LogWithdraw(address,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
|
||||||
_amt,
|
_amt,
|
||||||
|
_receiver,
|
||||||
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw ETH/ERC20_Token.
|
||||||
|
* @notice Withdraw a token from Morpho Aave.
|
||||||
|
* @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`)
|
||||||
|
* @param _getId ID to retrieve amt.
|
||||||
|
* @param _setId ID stores the amount of tokens withdrawed.
|
||||||
|
*/
|
||||||
|
function withdrawOnBehalf(
|
||||||
|
address _tokenAddress,
|
||||||
|
uint256 _amount,
|
||||||
|
address _onBehalf,
|
||||||
|
address _receiver,
|
||||||
|
uint256 _getId,
|
||||||
|
uint256 _setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, _onBehalf, _receiver, max_iteration);
|
||||||
|
|
||||||
|
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawOnBehalf(address,uint256,address,address,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_amt,
|
||||||
|
_onBehalf,
|
||||||
|
_receiver,
|
||||||
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw ETH/ERC20_Token.
|
||||||
|
* @notice Withdraw a token from Morpho Aave.
|
||||||
|
* @param _tokenAddress The address of underlying token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param _amount The amount of the token (in underlying) to withdraw. (For max: `uint256(-1)`)
|
||||||
|
* @param _getId ID to retrieve amt.
|
||||||
|
* @param _setId ID stores the amount of tokens withdrawed.
|
||||||
|
*/
|
||||||
|
function withdrawWithMaxIterations(
|
||||||
|
address _tokenAddress,
|
||||||
|
uint256 _amount,
|
||||||
|
address _onBehalf,
|
||||||
|
address _receiver,
|
||||||
|
uint256 _maxIteration,
|
||||||
|
uint256 _getId,
|
||||||
|
uint256 _setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
|
||||||
|
MORPHO_AAVE_V3.withdraw(_tokenAddress, _amt, _onBehalf, _receiver, _maxIteration);
|
||||||
|
|
||||||
|
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawWithMaxIterations(address,uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_amt,
|
||||||
|
_receiver,
|
||||||
|
_maxIteration,
|
||||||
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdrawCollateral(
|
||||||
|
address _tokenAddress,
|
||||||
|
uint256 _amount,
|
||||||
|
address _receiver,
|
||||||
|
uint256 _getId,
|
||||||
|
uint256 _setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
|
||||||
|
MORPHO_AAVE_V3.withdrawCollateral(_tokenAddress, _amt, address(this), _receiver);
|
||||||
|
|
||||||
|
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawCollateral(address,uint256,address,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_amt,
|
||||||
|
_receiver,
|
||||||
|
_getId,
|
||||||
|
_setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdrawCollateralOnBehalf(
|
||||||
|
address _tokenAddress,
|
||||||
|
uint256 _amount,
|
||||||
|
address _onBehalf,
|
||||||
|
address _receiver,
|
||||||
|
uint256 _getId,
|
||||||
|
uint256 _setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(_getId, _amount);
|
||||||
|
MORPHO_AAVE_V3.withdrawCollateral(_tokenAddress, _amt, _onBehalf, _receiver);
|
||||||
|
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
|
||||||
|
|
||||||
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawCollateralOnBehalf(address,uint256,address,address,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
_tokenAddress,
|
||||||
|
_amt,
|
||||||
|
_onBehalf,
|
||||||
|
_receiver,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
);
|
);
|
||||||
|
@ -585,14 +580,12 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
* @dev Payback ETH/ERC20_Token.
|
* @dev Payback ETH/ERC20_Token.
|
||||||
* @notice Payback a token to Morpho Aave.
|
* @notice Payback a token to Morpho Aave.
|
||||||
* @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param _poolTokenAddress The address of aToken to payback.(For ETH: aWETH address)
|
|
||||||
* @param _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`)
|
* @param _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`)
|
||||||
* @param _getId ID to retrieve amt.
|
* @param _getId ID to retrieve amt.
|
||||||
* @param _setId ID stores the amount of tokens paid back.
|
* @param _setId ID stores the amount of tokens paid back.
|
||||||
*/
|
*/
|
||||||
function payback(
|
function payback(
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
address _poolTokenAddress,
|
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
uint256 _setId
|
uint256 _setId
|
||||||
|
@ -609,28 +602,22 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
: TokenInterface(_tokenAddress);
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
if (_amt == uint256(-1)) {
|
if (_amt == uint256(-1)) {
|
||||||
uint256 _amtDSA = _isETH
|
_amt = _isETH
|
||||||
? address(this).balance
|
? address(this).balance
|
||||||
: _tokenContract.balanceOf(address(this));
|
: _tokenContract.balanceOf(address(this));
|
||||||
|
|
||||||
(, , uint256 _amtDebt) = MORPHO_AAVE_LENS
|
|
||||||
.getCurrentBorrowBalanceInOf(_poolTokenAddress, address(this));
|
|
||||||
|
|
||||||
_amt = _amtDSA < _amtDebt ? _amtDSA : _amtDebt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
convertEthToWeth(_isETH, _tokenContract, _amt);
|
convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
||||||
|
|
||||||
MORPHO_AAVE_V3.repay(_poolTokenAddress, address(this), _amt);
|
MORPHO_AAVE_V3.repay(_tokenAddress, _amt, address(this));
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogPayback(address,address,uint256,uint256,uint256)";
|
_eventName = "LogPayback(address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
|
||||||
_amt,
|
_amt,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
|
@ -641,7 +628,6 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
* @dev Payback ETH/ERC20_Token.
|
* @dev Payback ETH/ERC20_Token.
|
||||||
* @notice Payback a token to Morpho Aave.
|
* @notice Payback a token to Morpho Aave.
|
||||||
* @param _tokenAddress The address of underlying token to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @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 _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 _amount The amount of the token (in underlying) to payback. (For max: `uint256(-1)`)
|
||||||
* @param _getId ID to retrieve amt.
|
* @param _getId ID to retrieve amt.
|
||||||
|
@ -649,7 +635,6 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
*/
|
*/
|
||||||
function paybackOnBehalf(
|
function paybackOnBehalf(
|
||||||
address _tokenAddress,
|
address _tokenAddress,
|
||||||
address _poolTokenAddress,
|
|
||||||
address _onBehalf,
|
address _onBehalf,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
|
@ -667,30 +652,24 @@ abstract contract MorphoAaveV3 is Helpers, Events {
|
||||||
: TokenInterface(_tokenAddress);
|
: TokenInterface(_tokenAddress);
|
||||||
|
|
||||||
if (_amt == uint256(-1)) {
|
if (_amt == uint256(-1)) {
|
||||||
uint256 _amtDSA = _isETH
|
_amt = _isETH
|
||||||
? address(this).balance
|
? address(this).balance
|
||||||
: _tokenContract.balanceOf(address(this));
|
: _tokenContract.balanceOf(address(this));
|
||||||
|
|
||||||
(, , uint256 _amtDebt) = MORPHO_AAVE_LENS
|
|
||||||
.getCurrentBorrowBalanceInOf(_poolTokenAddress, _onBehalf);
|
|
||||||
|
|
||||||
_amt = _amtDSA < _amtDebt ? _amtDSA : _amtDebt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
convertEthToWeth(_isETH, _tokenContract, _amt);
|
convertEthToWeth(_isETH, _tokenContract, _amt);
|
||||||
|
|
||||||
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
|
||||||
|
|
||||||
MORPHO_AAVE_V3.repay(_poolTokenAddress, _onBehalf, _amt);
|
MORPHO_AAVE_V3.repay(_tokenAddress, _amt, _onBehalf);
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)";
|
_eventName = "LogPaybackOnBehalf(address,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_tokenAddress,
|
_tokenAddress,
|
||||||
_poolTokenAddress,
|
|
||||||
_onBehalf,
|
|
||||||
_amt,
|
_amt,
|
||||||
|
_onBehalf,
|
||||||
_getId,
|
_getId,
|
||||||
_setId
|
_setId
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user