lint code

This commit is contained in:
Richa-iitr 2022-10-29 20:01:30 +05:30
parent 51821bf036
commit 3bd13371ea
4 changed files with 58 additions and 335 deletions

View File

@ -5,9 +5,8 @@ pragma experimental ABIEncoderV2;
contract Events { contract Events {
event LogMorphoCompoundImport( event LogMorphoCompoundImport(
address indexed user, address indexed user,
address[] ctokens, address[] supplyCTokens,
string[] supplyIds, address[] borrowCTokens,
string[] borrowIds,
uint256[] supplyAmts, uint256[] supplyAmts,
uint256[] borrowAmts uint256[] borrowAmts
); );

View File

@ -25,7 +25,8 @@ abstract contract Helpers is DSMath, Basic {
IMorphoLens internal constant morphoLens = IMorphoLens internal constant morphoLens =
IMorphoLens(0x930f1b46e1D081Ec1524efD95752bE3eCe51EF67); IMorphoLens(0x930f1b46e1D081Ec1524efD95752bE3eCe51EF67);
IMorpho internal constant morpho = IMorpho(0x8888882f8f843896699869179fB6E4f7e3B58888) IMorpho internal constant morpho =
IMorpho(0x8888882f8f843896699869179fB6E4f7e3B58888);
struct ImportData { struct ImportData {
uint256[] borrowAmts; uint256[] borrowAmts;
@ -71,8 +72,9 @@ contract MorphoCompoundHelper is Helpers {
address cToken_ = importInputData_.borrowCTokens[i]; address cToken_ = importInputData_.borrowCTokens[i];
CTokenInterface ctoken_ = CTokenInterface(cToken_); CTokenInterface ctoken_ = CTokenInterface(cToken_);
address token_; address token_ = cToken_ == address(cEth)
token_ = cToken_ == address(cEth) ? wethAddr : ctoken_.underlying(); ? wethAddr
: ctoken_.underlying();
require(token_ != address(0), "invalid-ctoken-address"); require(token_ != address(0), "invalid-ctoken-address");
@ -88,7 +90,10 @@ contract MorphoCompoundHelper is Helpers {
// give the morpho approval to spend tokens // give the morpho approval to spend tokens
if (token_ != ethAddr && data.borrowAmts[i] > 0) { if (token_ != ethAddr && data.borrowAmts[i] > 0) {
// will be required when repaying the borrow amount on behalf of the user // will be required when repaying the borrow amount on behalf of the user
TokenInterface(token_).approve(address(morpho), data.borrowAmts[i]); TokenInterface(token_).approve(
address(morpho),
data.borrowAmts[i]
);
} }
} }
} }
@ -117,19 +122,16 @@ contract MorphoCompoundHelper is Helpers {
for (uint256 i; i < _length; i++) { for (uint256 i; i < _length; i++) {
address cToken_ = importInputData_.supplyCTokens[i]; address cToken_ = importInputData_.supplyCTokens[i];
CTokenInterface ctoken_ = CTokenInterface(cToken_); CTokenInterface ctoken_ = CTokenInterface(cToken_);
address token_ ; address token_ = cToken_ == address(cEth)
token_ = cToken_ == address(cEth) ? wethAddr : ctoken_.underlying(); ? wethAddr
: ctoken_.underlying();
require(
token_ != address(0),
"invalid-ctoken-address"
);
require(token_ != address(0), "invalid-ctoken-address");
data.supplyTokens[i] = token_; data.supplyTokens[i] = token_;
data.supplyCtokens[i] = ctoken_; data.supplyCtokens[i] = ctoken_;
data.supplyCtokensAddr[i] = (cToken_); data.supplyCtokensAddr[i] = (cToken_);
data.supplyAmts[i] = morpho.getCurrentSupplyBalanceInOf( (, , data.supplyAmts[i]) = morpho.getCurrentSupplyBalanceInOf(
cToken_, cToken_,
importInputData_.userAccount importInputData_.userAccount
); );
@ -164,7 +166,7 @@ contract MorphoCompoundHelper is Helpers {
* @param _cTokenContracts array containing all interfaces to the cToken contracts in which the user has supply positions * @param _cTokenContracts array containing all interfaces to the cToken contracts in which the user has supply positions
* @param _amts array containing the amount supplied for each token * @param _amts array containing the amount supplied for each token
*/ */
function _transferTokensToDsa( function _transferCTokensToDsa(
address userAccount_, address userAccount_,
CTokenInterface[] memory cTokenContracts_, CTokenInterface[] memory cTokenContracts_,
uint256[] memory supplyAmts_ uint256[] memory supplyAmts_
@ -183,11 +185,11 @@ contract MorphoCompoundHelper is Helpers {
} }
/** /**
* @notice borrows the user's debt positions from Compound via DSA, so that its debt positions get imported to DSA * @notice borrows the user's debt positions from Morpho via DSA, so that its debt positions get imported to DSA
* @dev actually borrow some extra amount than the original position to cover the flash loan fee * @dev borrows some extra amount than the original position to cover the flash loan fee
* @param _cTokenContracts array containing all interfaces to the cToken contracts in which the user has debt positions * @param cTokens_ array containing cToken addresses in which the user has debt positions
* @param _amts array containing the amounts the user had borrowed originally from Compound plus the flash loan fee * @param borrowAmts_ array containing the amounts the user had borrowed originally from Morpho-Compound
* @param _flashLoanFees flash loan fee (in percentage and scaled up to 10**2) * @param flashLoanFees_ flash loan fees.
*/ */
function _borrowDebtPosition( function _borrowDebtPosition(
address[] memory cTokens_, address[] memory cTokens_,
@ -197,6 +199,9 @@ contract MorphoCompoundHelper is Helpers {
uint256 length_ = cTokens_.length; uint256 length_ = cTokens_.length;
for (uint256 i; i < length_; ++i) for (uint256 i; i < length_; ++i)
if (borrowAmts_[i] > 0) if (borrowAmts_[i] > 0)
morpho.borrow(cTokens_[i], add(borrowAmts_[i], flashLoanFees_[i])); morpho.borrow(
cTokens_[i],
add(borrowAmts_[i], flashLoanFees_[i])
);
} }
} }

View File

@ -26,24 +26,6 @@ interface CTokenInterface {
function borrow(uint256 borrowAmount) external returns (uint256); function borrow(uint256 borrowAmount) external returns (uint256);
function repayBorrow(uint256 repayAmount) external returns (uint256);
function repayBorrowBehalf(address borrower, uint256 repayAmount)
external
returns (uint256); // For ERC20
function liquidateBorrow(
address borrower,
uint256 repayAmount,
address cTokenCollateral
) external returns (uint256);
function borrowBalanceCurrent(address account) external returns (uint256);
function redeemUnderlying(uint256 redeemAmount) external returns (uint256);
function exchangeRateCurrent() external returns (uint256);
function balanceOf(address owner) external view returns (uint256 balance); function balanceOf(address owner) external view returns (uint256 balance);
function transferFrom( function transferFrom(
@ -52,211 +34,10 @@ interface CTokenInterface {
uint256 uint256
) external returns (bool); ) external returns (bool);
function allowance(address, address) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool); function approve(address spender, uint256 amount) external returns (bool);
} }
interface IMorphoLens { interface IMorphoLens {
function MAX_BASIS_POINTS() external view returns (uint256);
function WAD() external view returns (uint256);
function morpho() external view returns (IMorpho);
function comptroller() external view returns (IComptroller);
function getTotalSupply()
external
view
returns (
uint256 p2pSupplyAmount,
uint256 poolSupplyAmount,
uint256 totalSupplyAmount
);
function getTotalBorrow()
external
view
returns (
uint256 p2pBorrowAmount,
uint256 poolBorrowAmount,
uint256 totalBorrowAmount
);
function isMarketCreated(address _poolToken) external view returns (bool);
function isMarketCreatedAndNotPaused(address _poolToken)
external
view
returns (bool);
function isMarketCreatedAndNotPausedNorPartiallyPaused(address _poolToken)
external
view
returns (bool);
function getAllMarkets()
external
view
returns (address[] memory marketsCreated_);
function getMainMarketData(address _poolToken)
external
view
returns (
uint256 avgSupplyRatePerBlock,
uint256 avgBorrowRatePerBlock,
uint256 p2pSupplyAmount,
uint256 p2pBorrowAmount,
uint256 poolSupplyAmount,
uint256 poolBorrowAmount
);
function getTotalMarketSupply(address _poolToken)
external
view
returns (uint256 p2pSupplyAmount, uint256 poolSupplyAmount);
function getTotalMarketBorrow(address _poolToken)
external
view
returns (uint256 p2pBorrowAmount, uint256 poolBorrowAmount);
function getCurrentP2PSupplyIndex(address _poolToken)
external
view
returns (uint256);
function getCurrentP2PBorrowIndex(address _poolToken)
external
view
returns (uint256);
function getCurrentPoolIndexes(address _poolToken)
external
view
returns (
uint256 currentPoolSupplyIndex,
uint256 currentPoolBorrowIndex
);
function getIndexes(address _poolToken, bool _computeUpdatedIndexes)
external
view
returns (
uint256 p2pSupplyIndex,
uint256 p2pBorrowIndex,
uint256 poolSupplyIndex,
uint256 poolBorrowIndex
);
function getEnteredMarkets(address _user)
external
view
returns (address[] memory enteredMarkets);
function getUserMaxCapacitiesForAsset(address _user, address _poolToken)
external
view
returns (uint256 withdrawable, uint256 borrowable);
function getUserHypotheticalBalanceStates(
address _user,
address _poolToken,
uint256 _withdrawnAmount,
uint256 _borrowedAmount
) external view returns (uint256 debtValue, uint256 maxDebtValue);
function getUserLiquidityDataForAsset(
address _user,
address _poolToken,
bool _computeUpdatedIndexes,
ICompoundOracle _oracle
) external view returns (AssetLiquidityData memory assetData);
function computeLiquidationRepayAmount(
address _user,
address _poolTokenBorrowed,
address _poolTokenCollateral,
address[] calldata _updatedMarkets
) external view returns (uint256 toRepay);
function getAverageSupplyRatePerBlock(address _poolToken)
external
view
returns (uint256);
function getAverageBorrowRatePerBlock(address _poolToken)
external
view
returns (uint256);
function getNextUserSupplyRatePerBlock(
address _poolToken,
address _user,
uint256 _amount
)
external
view
returns (
uint256 nextSupplyRatePerBlock,
uint256 balanceOnPool,
uint256 balanceInP2P,
uint256 totalBalance
);
function getNextUserBorrowRatePerBlock(
address _poolToken,
address _user,
uint256 _amount
)
external
view
returns (
uint256 nextBorrowRatePerBlock,
uint256 balanceOnPool,
uint256 balanceInP2P,
uint256 totalBalance
);
function getMarketConfiguration(address _poolToken)
external
view
returns (
address underlying,
bool isCreated,
bool p2pDisabled,
bool isPaused,
bool isPartiallyPaused,
uint16 reserveFactor,
uint16 p2pIndexCursor,
uint256 collateralFactor
);
function getRatesPerBlock(address _poolToken)
external
view
returns (
uint256 p2pSupplyRate,
uint256 p2pBorrowRate,
uint256 poolSupplyRate,
uint256 poolBorrowRate
);
function getAdvancedMarketData(address _poolToken)
external
view
returns (
uint256 p2pSupplyIndex,
uint256 p2pBorrowIndex,
uint256 poolSupplyIndex,
uint256 poolBorrowIndex,
uint32 lastUpdateBlockNumber,
uint256 p2pSupplyDelta,
uint256 p2pBorrowDelta
);
function getCurrentSupplyBalanceInOf(address _poolToken, address _user) function getCurrentSupplyBalanceInOf(address _poolToken, address _user)
external external
view view
@ -274,65 +55,6 @@ interface IMorphoLens {
uint256 balanceInP2P, uint256 balanceInP2P,
uint256 totalBalance uint256 totalBalance
); );
function getUserBalanceStates(
address _user,
address[] calldata _updatedMarkets
)
external
view
returns (
uint256 collateralValue,
uint256 debtValue,
uint256 maxDebtValue
);
function getAccruedSupplierComp(
address _supplier,
address _poolToken,
uint256 _balance
) external view returns (uint256);
function getAccruedBorrowerComp(
address _borrower,
address _poolToken,
uint256 _balance
) external view returns (uint256);
function getCurrentCompSupplyIndex(address _poolToken)
external
view
returns (uint256);
function getCurrentCompBorrowIndex(address _poolToken)
external
view
returns (uint256);
function getUserUnclaimedRewards(
address[] calldata _poolTokens,
address _user
) external view returns (uint256 unclaimedRewards);
function isLiquidatable(address _user, address[] memory _updatedMarkets)
external
view
returns (bool);
function getCurrentUserSupplyRatePerBlock(address _poolToken, address _user)
external
view
returns (uint256);
function getCurrentUserBorrowRatePerBlock(address _poolToken, address _user)
external
view
returns (uint256);
function getUserHealthFactor(
address _user,
address[] calldata _updatedMarkets
) external view returns (uint256);
} }
interface CETHInterface { interface CETHInterface {
@ -347,36 +69,33 @@ interface CETHInterface {
payable; payable;
} }
interface ComptrollerInterface { interface IMorpho {
function enterMarkets(address[] calldata cTokens) function supply(
external address _poolTokenAddress,
returns (uint256[] memory); address _onBehalf,
uint256 _amount
) external;
function exitMarket(address cTokenAddress) external returns (uint256); function supply(
address _poolTokenAddress,
address _onBehalf,
uint256 _amount,
uint256 _maxGasForMatching
) external;
function getAssetsIn(address account) function borrow(address _poolTokenAddress, uint256 _amount) external;
external
view
returns (address[] memory);
function getAccountLiquidity(address account) function borrow(
external address _poolTokenAddress,
view uint256 _amount,
returns ( uint256 _maxGasForMatching
uint256, ) external;
uint256,
uint256 function withdraw(address _poolTokenAddress, uint256 _amount) external;
);
} function repay(
address _poolTokenAddress,
interface CompoundMappingInterface { address _onBehalf,
function cTokenMapping(string calldata tokenId) uint256 _amount
external ) external;
view
returns (address);
function getMapping(string calldata tokenId)
external
view
returns (address, address);
} }

View File

@ -34,12 +34,12 @@ contract MorphoCompoundImportResolver is MorphoCompoundHelper {
// pay back user's debt using flash loan funds // pay back user's debt using flash loan funds
_paybackDebt( _paybackDebt(
importInputData_.userAccount, importInputData_.userAccount,
data.borrowCtokens, data.borrowCtokensAddr,
data.borrowAmts data.borrowAmts
); );
// transfer user's tokens to DSA // transfer user's tokens to DSA
_transferTokensToDsa( _transferCTokensToDsa(
importInputData_.userAccount, importInputData_.userAccount,
data.supplyCtokens, data.supplyCtokens,
data.supplyAmts data.supplyAmts
@ -47,12 +47,12 @@ contract MorphoCompoundImportResolver is MorphoCompoundHelper {
// borrow the earlier position from Compound with flash loan fee added // borrow the earlier position from Compound with flash loan fee added
_borrowDebtPosition( _borrowDebtPosition(
data.borrowCtokens, data.borrowCtokensAddr,
data.borrowAmts, data.borrowAmts,
_flashLoanFees importInputData_.flashLoanFees
); );
_eventName = "LogCompoundImport(address,address[],address[],uint256[],uint256[])"; _eventName = "LogMorphoCompoundImport(address,address[],address[],uint256[],uint256[])";
_eventParam = abi.encode( _eventParam = abi.encode(
importInputData_.userAccount, importInputData_.userAccount,
importInputData_.supplyCTokens, importInputData_.supplyCTokens,