add temp result

This commit is contained in:
q1q0 2023-02-23 20:21:01 -05:00
parent 2ca7b19ab5
commit 7482153adb
3 changed files with 302 additions and 123 deletions

View File

@ -4,6 +4,13 @@ pragma experimental ABIEncoderV2;
contract Events {
event LogDeposit(
address tokenAddress,
uint256 amount,
uint256 getId,
uint256 setId
);
event LogDepositWithMaxIterations(
address tokenAddress,
uint256 amount,
uint256 maxIteration,
@ -11,16 +18,15 @@ contract Events {
uint256 setId
);
event LogDepositWithMaxGas(
event LogDepositOnBehalf(
address tokenAddress,
address poolTokenAddress,
uint256 amount,
uint256 maxGasForMatching,
address onBehalf,
uint256 getId,
uint256 setId
);
event LogDepositOnBehalf(
event LogDepositOnBehalfWithMaxIterations(
address tokenAddress,
uint256 amount,
address onBehalf,
@ -72,17 +78,27 @@ contract Events {
event LogBorrow(
address tokenAddress,
address poolTokenAddress,
uint256 amount,
address receiver,
uint256 getId,
uint256 setId
);
event LogBorrowWithMaxGas(
event LogBorrowWithMaxIterations(
address tokenAddress,
address poolTokenAddress,
uint256 amount,
uint256 maxGasForMatching,
address receiver,
uint256 maxIteration,
uint256 getId,
uint256 setId
);
event LogBorrowOnBehalfWithMaxIterations(
address tokenAddress,
uint256 amount,
address receiver,
address onBehalf,
uint256 maxIteration,
uint256 getId,
uint256 setId
);

View File

@ -9,6 +9,8 @@ import "../../common/interfaces.sol";
abstract contract Helpers is Stores, Basic {
IMorphoCore public constant MORPHO_AAVE_V3 =
IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
uint256 public constant MAX_ITERATION = 10;
IMorphoAaveLens public constant MORPHO_AAVE_LENS =
IMorphoAaveLens(0x507fA343d0A90786d86C7cd885f5C49263A91FF4);

View File

@ -10,14 +10,12 @@ abstract contract MorphoAaveV3 is Helpers, Events {
* @notice Deposit a token to Morpho Aave for lending / collaterization.
* @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 _maxIterations The maximum number of iterations allowed during the matching process.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens deposited.
*/
function deposit(
address _tokenAddress,
uint256 _amount,
uint256 _maxIterations,
uint256 _getId,
uint256 _setId
)
@ -32,15 +30,55 @@ abstract contract MorphoAaveV3 is Helpers, Events {
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), _maxIterations);
MORPHO_AAVE_V3.supply(_tokenContract, _amt, address(this), MAX_ITERATION);
setUint(_setId, _amt);
_eventName = "LogDeposit(address,uint256,uint256,uint256,uint256)";
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
_maxIterations,
_getId,
_setId
);
}
/**
* @dev Deposit ETH/ERC20_Token.
* @notice Deposit a token to Morpho Aave for lending / collaterization.
* @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 _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens deposited.
*/
function depositWithMaxIterations(
address _tokenAddress,
uint256 _amount,
address _onBehalf,
uint256 _getId,
uint256 _setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
(
TokenInterface _tokenContract,
uint256 _amt
) = _performEthToWethConversion(_tokenAddress, _amount, _getId);
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION);
setUint(_setId, _amt);
_eventName = "LogDepositWithMaxIterations(address,uint256,address,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
_onBehalf,
_getId,
_setId
);
@ -51,7 +89,6 @@ abstract contract MorphoAaveV3 is Helpers, Events {
* @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 _amount The amount of the token (in underlying) to deposit. (For max: `uint256(-1)`)
* @param _maxIterations The maximum number of iterations allowed during the matching process.
* @param _onBehalf The address of user on behalf to deposit.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens deposited.
@ -60,7 +97,6 @@ abstract contract MorphoAaveV3 is Helpers, Events {
address _tokenAddress,
uint256 _amount,
address _onBehalf,
uint256 _maxIterations,
uint256 _getId,
uint256 _setId
)
@ -75,37 +111,35 @@ abstract contract MorphoAaveV3 is Helpers, Events {
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, _maxIterations);
MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, MAX_ITERATION);
setUint(_setId, _amt);
_eventName = "LogDepositOnBehalf(address,uint256,address,uint256,uint256,uint256)";
_eventName = "LogDepositOnBehalf(address,uint256,address,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
_onBehalf,
_maxIterations,
_getId,
_setId
);
}
/**
* @notice Supplies `amount` of `underlying` of `onBehalf` using permit2 in a single tx.
* @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 _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 _onBehalf The address of user on behalf to deposit.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens deposited.
*/
function depositWithPermit(
function depositOnBehalfWithMaxIterations (
address _tokenAddress,
uint256 _amount,
address _onBehalf,
uint256 _maxIterations,
Signature calldata _signature,
uint256 _maxIteration,
uint256 _getId,
uint256 _setId
)
@ -120,25 +154,70 @@ abstract contract MorphoAaveV3 is Helpers, Events {
approve(_tokenContract, address(MORPHO_AAVE_V3), _amt);
MORPHO_AAVE_V3.supplyWithPermit(_tokenContract, _amt, _onBehalf, _maxIterations, block.timestamp, _signature);
MORPHO_AAVE_V3.supply(_tokenContract, _amt, _onBehalf, _maxIteration);
setUint(_setId, _amt);
_eventName = "LogDepositWithPermit(address,uint256,address,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)";
_eventName = "LogDepositOnBehalfWithMaxIterations(address,uint256,address,uint256,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
_onBehalf,
_maxIterations,
block.timestamp,
_signature.v,
_signature.r,
_signature.s,
_maxIteration,
_getId,
_setId
);
}
// /**
// * @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.
* @notice Deposit a token to Morpho Aave for lending / collaterization on behalf of a user.
@ -168,7 +247,7 @@ abstract contract MorphoAaveV3 is Helpers, Events {
setUint(_setId, _amt);
_eventName = "LogDepositCollateral(address,uint256,address,uint256,uint256)";
_eventName = "LogDepositCollateral(address,uint256,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
@ -218,63 +297,180 @@ 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
// );
// }
/**
* @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.
* @dev Borrow ETH/ERC20_Token.
* @notice Borrow a token from Morpho Aave.
* @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _amount The amount of the token (in underlying) to borrow.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens deposited.
* @param _setId ID stores the amount of tokens borrowed.
*/
function depositCollateralWithPermit(
function borrow(
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.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION);
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
setUint(_setId, _amt);
_eventName = "LogBorrow(address,uint256,address,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
_receiver,
_getId,
_setId
);
}
/**
* @dev Borrow ETH/ERC20_Token.
* @notice Borrow a token from Morpho Aave.
* @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _amount The amount of the token (in underlying) to borrow.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens borrowed.
*/
function borrowOnBehalf(
address _tokenAddress,
uint256 _amount,
address _receiver,
address _onBehalf,
uint256 _getId,
uint256 _setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(_getId, _amount);
MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, address(this), _receiver, MAX_ITERATION);
convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt);
setUint(_setId, _amt);
_eventName = "LogBorrowOnBehalf(address,uint256,addresss,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
_receiver,
_getId,
_setId
);
}
/**
* @dev Borrow ETH/ERC20_Token.
* @notice Borrow a token from Morpho Aave.
* @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _amount The amount of the token (in underlying) to borrow.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens borrowed.
*/
function borrowWithMaxIterations(
address _tokenAddress,
uint256 _amount,
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.borrow(_tokenAddress, _amt, address(this), _receiver, _maxIteration);
convertWethToEth(_tokenAddress == ethAddr, address(this), _amt);
setUint(_setId, _amt);
_eventName = "LogBorrowWithMaxIterations(address,uint256,addresss,uint256,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_amt,
_receiver,
_maxIteration,
_getId,
_setId
);
}
/**
* @dev Borrow ETH/ERC20_Token.
* @notice Borrow a token from Morpho Aave.
* @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _amount The amount of the token (in underlying) to borrow.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens borrowed.
*/
function borrowOnBehalfWithMaxIterations (
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.
* @notice Borrow a token from Morpho Aave.
* @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _amount The amount of the token (in underlying) to borrow.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens borrowed.
*/
function borrow(
address _tokenAddress,
uint256 _amount,
address _receiver,
uint256 _maxIteration,
uint256 _getId,
uint256 _setId
)
@ -284,53 +480,18 @@ abstract contract MorphoAaveV3 is Helpers, Events {
{
uint256 _amt = getUint(_getId, _amount);
MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt);
MORPHO_AAVE_V3.borrow(_tokenAddress, _amt, _onBehalf, _receiver, _maxIteration);
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
convertWethToEth(_tokenAddress == ethAddr, _onBehalf, _amt);
setUint(_setId, _amt);
_eventName = "LogBorrow(address,address,uint256,uint256,uint256)";
_eventName = "LogBorrowOnBehalfWithMaxIterations(address,uint256,addresss,address,uint256,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_poolTokenAddress,
_amt,
_getId,
_setId
);
}
/**
* @dev Borrow ETH/ERC20_Token.
* @notice Borrow a token from Morpho Aave.
* @param _tokenAddress The address of underlying token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param _amount The amount of the token (in underlying) to borrow.
* @param _getId ID to retrieve amt.
* @param _setId ID stores the amount of tokens borrowed.
*/
function borrow(
address _tokenAddress,
uint256 _amount,
uint256 _getId,
uint256 _setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(_getId, _amount);
MORPHO_AAVE_V3.borrow(_poolTokenAddress, _amt);
convertWethToEth(_tokenAddress == ethAddr, TokenInterface(wethAddr), _amt);
setUint(_setId, _amt);
_eventName = "LogBorrow(address,address,uint256,uint256,uint256)";
_eventParam = abi.encode(
_tokenAddress,
_poolTokenAddress,
_amt,
_receiver,
_maxIteration,
_getId,
_setId
);