mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
feat: optimise
This commit is contained in:
parent
1e4a1d9574
commit
aa0dedc52c
|
|
@ -1,10 +1,10 @@
|
||||||
//SPDX-License-Identifier: MIT
|
//SPDX-License-Identifier: MIT
|
||||||
pragma solidity ^0.8.2;
|
pragma solidity ^0.8.2;
|
||||||
import {MarketParams} from "./interfaces/IMorpho.sol";
|
import {Id, MarketParams} from "./interfaces/IMorpho.sol";
|
||||||
|
|
||||||
contract Events {
|
contract Events {
|
||||||
event LogSupplyAssets(
|
event LogSupplyAssets(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 assets,
|
uint256 assets,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
|
@ -12,7 +12,7 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogSupplyOnBehalf(
|
event LogSupplyOnBehalf(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 assets,
|
uint256 assets,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address onBehalf,
|
||||||
|
|
@ -21,14 +21,14 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogSupplyCollateral(
|
event LogSupplyCollateral(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 assets,
|
uint256 assets,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogSupplyCollateralOnBehalf(
|
event LogSupplyCollateralOnBehalf(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 assets,
|
uint256 assets,
|
||||||
address onBehalf,
|
address onBehalf,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
|
@ -36,7 +36,7 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogBorrow(
|
event LogBorrow(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
|
@ -44,7 +44,7 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogBorrowOnBehalf(
|
event LogBorrowOnBehalf(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address onBehalf,
|
||||||
|
|
@ -54,7 +54,7 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogWithdraw(
|
event LogWithdraw(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
|
@ -62,7 +62,7 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogWithdrawOnBehalf(
|
event LogWithdrawOnBehalf(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address onBehalf,
|
||||||
|
|
@ -71,14 +71,14 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogWithdrawCollateral(
|
event LogWithdrawCollateral(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogWithdrawCollateralOnBehalf(
|
event LogWithdrawCollateralOnBehalf(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
address onBehalf,
|
address onBehalf,
|
||||||
address receiver,
|
address receiver,
|
||||||
|
|
@ -87,7 +87,7 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogRepay(
|
event LogRepay(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
|
@ -95,7 +95,7 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogRepayOnBehalf(
|
event LogRepayOnBehalf(
|
||||||
MarketParams marketParams,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address onBehalf,
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,13 @@ import "../../common/interfaces.sol";
|
||||||
import {MorphoBalancesLib} from "./libraries/periphery/MorphoBalancesLib.sol";
|
import {MorphoBalancesLib} from "./libraries/periphery/MorphoBalancesLib.sol";
|
||||||
import {UtilsLib} from "./libraries/UtilsLib.sol";
|
import {UtilsLib} from "./libraries/UtilsLib.sol";
|
||||||
import {MarketParamsLib} from "./libraries/MarketParamsLib.sol";
|
import {MarketParamsLib} from "./libraries/MarketParamsLib.sol";
|
||||||
|
import {SharesMathLib} from "./libraries/SharesMathLib.sol";
|
||||||
|
|
||||||
abstract contract Helpers is Stores, Basic {
|
abstract contract Helpers is Stores, Basic {
|
||||||
using MorphoBalancesLib for IMorpho;
|
using MorphoBalancesLib for IMorpho;
|
||||||
using MarketParamsLib for MarketParams;
|
using MarketParamsLib for MarketParams;
|
||||||
using UtilsLib for uint256;
|
using UtilsLib for uint256;
|
||||||
|
using SharesMathLib for uint256;
|
||||||
|
|
||||||
IMorpho public constant MORPHO_BLUE =
|
IMorpho public constant MORPHO_BLUE =
|
||||||
IMorpho(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); // TODO: Update
|
IMorpho(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); // TODO: Update
|
||||||
|
|
@ -40,7 +42,7 @@ abstract contract Helpers is Stores, Basic {
|
||||||
address _onBehalf,
|
address _onBehalf,
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
Mode _mode
|
Mode _mode
|
||||||
) internal returns (MarketParams memory, uint256 _amt) {
|
) internal returns (Id _id, MarketParams memory, uint256 _amt) {
|
||||||
_amt = getUint(_getId, _assets);
|
_amt = getUint(_getId, _assets);
|
||||||
|
|
||||||
bool _isEth = _mode == Mode.Collateral
|
bool _isEth = _mode == Mode.Collateral
|
||||||
|
|
@ -49,6 +51,8 @@ abstract contract Helpers is Stores, Basic {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
_id = _marketParams.id();
|
||||||
|
|
||||||
// Check for max value
|
// Check for max value
|
||||||
if (_assets == type(uint256).max) {
|
if (_assets == type(uint256).max) {
|
||||||
uint256 _maxAvailable = _isEth
|
uint256 _maxAvailable = _isEth
|
||||||
|
|
@ -57,8 +61,8 @@ abstract contract Helpers is Stores, Basic {
|
||||||
address(this)
|
address(this)
|
||||||
);
|
);
|
||||||
if (_mode == Mode.Repay) {
|
if (_mode == Mode.Repay) {
|
||||||
uint256 _amtDebt = getPaybackBalance(_marketParams, _onBehalf);
|
uint256 _amtDebt = getPaybackBalance(_id, _marketParams, _onBehalf);
|
||||||
_amt = _maxAvailable.min(_amtDebt); // TODO: Ask
|
_amt = UtilsLib.min(_maxAvailable, _amtDebt);
|
||||||
} else {
|
} else {
|
||||||
_amt = _maxAvailable;
|
_amt = _maxAvailable;
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +71,7 @@ abstract contract Helpers is Stores, Basic {
|
||||||
// Perform conversion if necessary
|
// Perform conversion if necessary
|
||||||
convertEthToWeth(true, TokenInterface(_marketParams.loanToken), _amt);
|
convertEthToWeth(true, TokenInterface(_marketParams.loanToken), _amt);
|
||||||
|
|
||||||
return (_marketParams, _amt);
|
return (_id, _marketParams, _amt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Handles Eth to Weth conversion if shares are provided.
|
/// @notice Handles Eth to Weth conversion if shares are provided.
|
||||||
|
|
@ -77,12 +81,14 @@ abstract contract Helpers is Stores, Basic {
|
||||||
address _onBehalf,
|
address _onBehalf,
|
||||||
uint256 _getId,
|
uint256 _getId,
|
||||||
bool _isRepay
|
bool _isRepay
|
||||||
) internal returns (MarketParams memory, uint256 _assets) {
|
) internal returns (Id _id, MarketParams memory, uint256 _assets) {
|
||||||
uint256 _shareAmt = getUint(_getId, _shares);
|
uint256 _shareAmt = getUint(_getId, _shares);
|
||||||
bool _isEth = _marketParams.loanToken == ethAddr;
|
bool _isEth = _marketParams.loanToken == ethAddr;
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
_id = _marketParams.id();
|
||||||
|
|
||||||
// Handle the max share case
|
// Handle the max share case
|
||||||
if (_shares == type(uint256).max) {
|
if (_shares == type(uint256).max) {
|
||||||
uint256 _maxAvailable = _isEth
|
uint256 _maxAvailable = _isEth
|
||||||
|
|
@ -93,9 +99,7 @@ abstract contract Helpers is Stores, Basic {
|
||||||
|
|
||||||
// If it's repay calculate the min of balance available and debt to repay
|
// If it's repay calculate the min of balance available and debt to repay
|
||||||
if (_isRepay) {
|
if (_isRepay) {
|
||||||
_assets = _maxAvailable.min(
|
_assets = UtilsLib.min(_maxAvailable, getPaybackBalance(_id, _marketParams, _onBehalf));
|
||||||
getPaybackBalance(_marketParams, _onBehalf) // TODO: Ask
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
_assets = _maxAvailable;
|
_assets = _maxAvailable;
|
||||||
}
|
}
|
||||||
|
|
@ -107,11 +111,7 @@ abstract contract Helpers is Stores, Basic {
|
||||||
|
|
||||||
) = MORPHO_BLUE.expectedMarketBalances(_marketParams);
|
) = MORPHO_BLUE.expectedMarketBalances(_marketParams);
|
||||||
|
|
||||||
_assets = _toAssetsUp(
|
_assets = _shareAmt.toAssetsUp(totalSupplyAssets, totalSupplyShares);
|
||||||
_shareAmt,
|
|
||||||
totalSupplyAssets,
|
|
||||||
totalSupplyShares
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform ETH to WETH conversion if necessary
|
// Perform ETH to WETH conversion if necessary
|
||||||
|
|
@ -121,45 +121,21 @@ abstract contract Helpers is Stores, Basic {
|
||||||
_assets
|
_assets
|
||||||
);
|
);
|
||||||
|
|
||||||
return (_marketParams, _assets);
|
return (_id, _marketParams, _assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Returns the payback balance in assets.
|
/// @notice Returns the payback balance in assets.
|
||||||
function getPaybackBalance(
|
function getPaybackBalance(
|
||||||
|
Id _id,
|
||||||
MarketParams memory _marketParams,
|
MarketParams memory _marketParams,
|
||||||
address _onBehalf
|
address _onBehalf
|
||||||
) internal view returns (uint256 _assets) {
|
) internal view returns (uint256 _assets) {
|
||||||
Id _id = _marketParams.id();
|
|
||||||
|
|
||||||
uint256 _shareAmt = MORPHO_BLUE.position(_id, _onBehalf).supplyShares;
|
uint256 _shareAmt = MORPHO_BLUE.position(_id, _onBehalf).supplyShares;
|
||||||
|
|
||||||
(uint256 totalSupplyAssets, uint256 totalSupplyShares, , ) = MORPHO_BLUE
|
(uint256 totalSupplyAssets, uint256 totalSupplyShares, , ) = MORPHO_BLUE
|
||||||
.expectedMarketBalances(_marketParams);
|
.expectedMarketBalances(_marketParams);
|
||||||
|
|
||||||
_assets = _toAssetsUp(_shareAmt, totalSupplyAssets, totalSupplyShares);
|
_assets = _shareAmt.toAssetsUp(totalSupplyAssets, totalSupplyShares);
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Calculates the value of `shares` quoted in assets, rounding up.
|
|
||||||
function _toAssetsUp(
|
|
||||||
uint256 _shares,
|
|
||||||
uint256 _totalAssets,
|
|
||||||
uint256 _totalShares
|
|
||||||
) internal pure returns (uint256) {
|
|
||||||
return
|
|
||||||
_mulDivUp(
|
|
||||||
_shares,
|
|
||||||
_totalAssets + VIRTUAL_ASSETS,
|
|
||||||
_totalShares + VIRTUAL_SHARES
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Returns (`x` * `y`) / `d` rounded up.
|
|
||||||
function _mulDivUp(
|
|
||||||
uint256 x,
|
|
||||||
uint256 y,
|
|
||||||
uint256 d
|
|
||||||
) internal pure returns (uint256) {
|
|
||||||
return (x * y + (d - 1)) / d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTokenAddresses(
|
function updateTokenAddresses(
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt;
|
uint256 _amt;
|
||||||
|
Id _id;
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_amt
|
_amt
|
||||||
) = _performEthToWethConversion(
|
) = _performEthToWethConversion(
|
||||||
|
|
@ -55,9 +57,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogSupplyAssets((address,address,address,address,unit256),unit256,unit256,unit256,unit256)";
|
_eventName = "LogSupplyAssets(bytes32,unit256,unit256,unit256,unit256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_getId,
|
_getId,
|
||||||
|
|
@ -86,7 +88,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt;
|
uint256 _amt;
|
||||||
|
Id _id;
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_amt
|
_amt
|
||||||
) = _performEthToWethConversion(
|
) = _performEthToWethConversion(
|
||||||
|
|
@ -114,9 +118,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogSupplyOnBehalf((address,address,address,address,unit256),uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogSupplyOnBehalf(bytes32,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
@ -146,7 +150,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt;
|
uint256 _amt;
|
||||||
|
Id _id;
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_amt // Shares amount converted to assets
|
_amt // Shares amount converted to assets
|
||||||
) = _performEthToWethSharesConversion(
|
) = _performEthToWethSharesConversion(
|
||||||
|
|
@ -163,19 +169,20 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
_amt
|
_amt
|
||||||
);
|
);
|
||||||
|
|
||||||
(uint256 _assets, ) = MORPHO_BLUE.supply(
|
uint256 _assets;
|
||||||
|
(_assets, _shares) = MORPHO_BLUE.supply(
|
||||||
_marketParams,
|
_marketParams,
|
||||||
_amt,
|
_amt,
|
||||||
_shares,
|
0,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
new bytes(0)
|
new bytes(0)
|
||||||
);
|
);
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogSupplyOnBehalf((address,address,address,address,unit256),uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogSupplyOnBehalf(bytes32,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
@ -202,7 +209,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt;
|
uint256 _amt;
|
||||||
|
Id _id;
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_amt
|
_amt
|
||||||
) = _performEthToWethConversion(
|
) = _performEthToWethConversion(
|
||||||
|
|
@ -229,8 +238,8 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogSupplyCollateral((address,address,address,address,unit256),uint256,uint256,uint256)";
|
_eventName = "LogSupplyCollateral(bytes32,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(_marketParams, _assets, _getId, _setId);
|
_eventParam = abi.encode(_id, _assets, _getId, _setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -253,8 +262,10 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt;
|
uint256 _amt;
|
||||||
|
Id _id;
|
||||||
// Final assets amount and token contract
|
// Final assets amount and token contract
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_amt
|
_amt
|
||||||
) = _performEthToWethConversion(
|
) = _performEthToWethConversion(
|
||||||
|
|
@ -281,9 +292,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogSupplyCollateralOnBehalf((address,address,address,address,unit256),uint256,address,uint256,uint256)";
|
_eventName = "LogSupplyCollateralOnBehalf(bytes32,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
_getId,
|
_getId,
|
||||||
|
|
@ -313,9 +324,10 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
// If amount is max, fetch collateral value from Morpho's contract
|
// If amount is max, fetch collateral value from Morpho's contract
|
||||||
if (_amt == type(uint256).max) {
|
if (_amt == type(uint256).max) {
|
||||||
Id _id = _marketParams.id();
|
|
||||||
Position memory _pos = MORPHO_BLUE.position(_id, address(this));
|
Position memory _pos = MORPHO_BLUE.position(_id, address(this));
|
||||||
_amt = _pos.collateral;
|
_amt = _pos.collateral;
|
||||||
}
|
}
|
||||||
|
|
@ -335,8 +347,8 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogWithdrawCollateral((address,address,address,address,unit256),uint256,uint256,uint256)";
|
_eventName = "LogWithdrawCollateral(bytes32,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(_marketParams, _amt, _getId, _setId);
|
_eventParam = abi.encode(_id, _amt, _getId, _setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -364,9 +376,10 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
// If amount is max, fetch collateral value from Morpho's contract
|
// If amount is max, fetch collateral value from Morpho's contract
|
||||||
if (_amt == type(uint256).max) {
|
if (_amt == type(uint256).max) {
|
||||||
Id _id = _marketParams.id();
|
|
||||||
Position memory _pos = MORPHO_BLUE.position(_id, _onBehalf);
|
Position memory _pos = MORPHO_BLUE.position(_id, _onBehalf);
|
||||||
_amt = _pos.collateral;
|
_amt = _pos.collateral;
|
||||||
}
|
}
|
||||||
|
|
@ -387,9 +400,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogWithdrawCollateralOnBehalf((address,address,address,address,unit256),uint256,address,address,uint256,uint256)";
|
_eventName = "LogWithdrawCollateralOnBehalf(bytes32,uint256,address,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_amt,
|
_amt,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
_receiver,
|
_receiver,
|
||||||
|
|
@ -419,12 +432,13 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
uint256 _amt = getUint(_getId, _assets);
|
uint256 _amt = getUint(_getId, _assets);
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
uint256 _shares = 0;
|
uint256 _shares = 0;
|
||||||
|
|
||||||
// Using shares for max amounts to make sure no dust is left on the contract
|
// Using shares for max amounts to make sure no dust is left on the contract
|
||||||
if (_amt == type(uint256).max) {
|
if (_amt == type(uint256).max) {
|
||||||
Id _id = _marketParams.id();
|
|
||||||
Position memory _pos = MORPHO_BLUE.position(_id, address(this));
|
Position memory _pos = MORPHO_BLUE.position(_id, address(this));
|
||||||
_shares = _pos.supplyShares;
|
_shares = _pos.supplyShares;
|
||||||
_amt = 0;
|
_amt = 0;
|
||||||
|
|
@ -447,9 +461,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogWithdraw((address,address,address,address,unit256),uint256,uint256,uint256,uint256)";
|
_eventName = "LogWithdraw(bytes32,uint256,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_getId,
|
_getId,
|
||||||
|
|
@ -482,10 +496,11 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
uint256 _shares = 0;
|
uint256 _shares = 0;
|
||||||
// Using shares for max amounts to make sure no dust is left on the contract
|
// Using shares for max amounts to make sure no dust is left on the contract
|
||||||
if (_amt == type(uint256).max) {
|
if (_amt == type(uint256).max) {
|
||||||
Id _id = _marketParams.id();
|
|
||||||
Position memory _pos = MORPHO_BLUE.position(_id, _onBehalf);
|
Position memory _pos = MORPHO_BLUE.position(_id, _onBehalf);
|
||||||
_shares = _pos.supplyShares;
|
_shares = _pos.supplyShares;
|
||||||
_amt = 0;
|
_amt = 0;
|
||||||
|
|
@ -508,9 +523,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogWithdrawOnBehalf((address,address,address,address,unit256),uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogWithdrawOnBehalf(bytes32,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
@ -544,8 +559,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
if (_shareAmt == type(uint256).max) {
|
if (_shareAmt == type(uint256).max) {
|
||||||
Id _id = _marketParams.id();
|
|
||||||
Position memory _pos = MORPHO_BLUE.position(_id, _onBehalf);
|
Position memory _pos = MORPHO_BLUE.position(_id, _onBehalf);
|
||||||
_shareAmt = _pos.supplyShares;
|
_shareAmt = _pos.supplyShares;
|
||||||
}
|
}
|
||||||
|
|
@ -567,9 +583,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogWithdrawOnBehalf((address,address,address,address,unit256),uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogWithdrawOnBehalf(bytes32,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shareAmt,
|
_shareAmt,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
@ -600,6 +616,8 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
(, uint256 _shares) = MORPHO_BLUE.borrow(
|
(, uint256 _shares) = MORPHO_BLUE.borrow(
|
||||||
_marketParams,
|
_marketParams,
|
||||||
_amt,
|
_amt,
|
||||||
|
|
@ -616,8 +634,8 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogBorrow((address,address,address,address,unit256),uint256,uint256,uint256,uint256)";
|
_eventName = "LogBorrow(bytes32,uint256,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(_marketParams, _amt, _shares, _getId, _setId);
|
_eventParam = abi.encode(_id, _amt, _shares, _getId, _setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -646,6 +664,8 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
(, uint256 _shares) = MORPHO_BLUE.borrow(
|
(, uint256 _shares) = MORPHO_BLUE.borrow(
|
||||||
_marketParams,
|
_marketParams,
|
||||||
_amt,
|
_amt,
|
||||||
|
|
@ -663,9 +683,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _amt);
|
setUint(_setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogBorrowOnBehalf((address,address,address,address,unit256),uint256,uint256,address,address,uint256,uint256)";
|
_eventName = "LogBorrowOnBehalf(bytes32,uint256,uint256,address,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_amt,
|
_amt,
|
||||||
_shares,
|
_shares,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
@ -701,6 +721,8 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
_marketParams = updateTokenAddresses(_marketParams);
|
_marketParams = updateTokenAddresses(_marketParams);
|
||||||
|
|
||||||
|
Id _id = _marketParams.id();
|
||||||
|
|
||||||
(uint256 _assets, ) = MORPHO_BLUE.borrow(
|
(uint256 _assets, ) = MORPHO_BLUE.borrow(
|
||||||
_marketParams,
|
_marketParams,
|
||||||
0,
|
0,
|
||||||
|
|
@ -718,9 +740,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogBorrowOnBehalf((address,address,address,address,unit256),uint256,uint256,address,address,uint256,uint256)";
|
_eventName = "LogBorrowOnBehalf(bytes32,uint256,uint256,address,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shareAmt,
|
_shareAmt,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
@ -749,7 +771,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt;
|
uint256 _amt;
|
||||||
|
Id _id;
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_amt // Assets final amount to repay
|
_amt // Assets final amount to repay
|
||||||
) = _performEthToWethConversion(
|
) = _performEthToWethConversion(
|
||||||
|
|
@ -778,9 +802,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogRepay((address,address,address,address,unit256),uint256,uint256,uint256,uint256)";
|
_eventName = "LogRepay(bytes32,uint256,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_getId,
|
_getId,
|
||||||
|
|
@ -809,7 +833,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt;
|
uint256 _amt;
|
||||||
|
Id _id;
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_amt // Assets final amount to repay
|
_amt // Assets final amount to repay
|
||||||
) = _performEthToWethConversion(
|
) = _performEthToWethConversion(
|
||||||
|
|
@ -838,9 +864,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogRepayOnBehalf((address,address,address,address,unit256),uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogRepayOnBehalf(bytes32,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
@ -870,7 +896,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _assetsAmt;
|
uint256 _assetsAmt;
|
||||||
|
Id _id;
|
||||||
(
|
(
|
||||||
|
_id,
|
||||||
_marketParams, // Updated token contracts in case of Eth
|
_marketParams, // Updated token contracts in case of Eth
|
||||||
_assetsAmt // Assets final amount to repay
|
_assetsAmt // Assets final amount to repay
|
||||||
) = _performEthToWethSharesConversion(
|
) = _performEthToWethSharesConversion(
|
||||||
|
|
@ -897,9 +925,9 @@ abstract contract MorphoBlue is Helpers, Events {
|
||||||
|
|
||||||
setUint(_setId, _assets);
|
setUint(_setId, _assets);
|
||||||
|
|
||||||
_eventName = "LogRepayOnBehalf((address,address,address,address,unit256),uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogRepayOnBehalf(bytes32,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_marketParams,
|
_id,
|
||||||
_assets,
|
_assets,
|
||||||
_shares,
|
_shares,
|
||||||
_onBehalf,
|
_onBehalf,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user