From 7b17bc9d40fc368bf5390cea106570b8d5e732d6 Mon Sep 17 00:00:00 2001 From: Samyak Jain <34437877+KaymasJain@users.noreply.github.com> Date: Mon, 28 Jun 2021 23:55:24 +0530 Subject: [PATCH] liquity updates done --- .../mainnet/connectors/liquity/events.sol | 6 +- contracts/mainnet/connectors/liquity/main.sol | 70 ++++++++++--------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/contracts/mainnet/connectors/liquity/events.sol b/contracts/mainnet/connectors/liquity/events.sol index 47105414..b8b9bd50 100644 --- a/contracts/mainnet/connectors/liquity/events.sol +++ b/contracts/mainnet/connectors/liquity/events.sol @@ -23,10 +23,8 @@ contract Events { uint withdrawAmount, uint borrowAmount, uint repayAmount, - uint getDepositId, - uint setWithdrawId, - uint getRepayId, - uint setBorrowId + uint[] getIds, + uint[] setIds ); event LogClaimCollateralFromRedemption(address indexed borrower, uint amount, uint setId); diff --git a/contracts/mainnet/connectors/liquity/main.sol b/contracts/mainnet/connectors/liquity/main.sol index efe05d73..0e10f60c 100644 --- a/contracts/mainnet/connectors/liquity/main.sol +++ b/contracts/mainnet/connectors/liquity/main.sol @@ -42,23 +42,23 @@ abstract contract LiquityResolver is Events, Helpers { uint[] setIds ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _depositAmount = getUint(getIds[0], depositAmount); - uint _borrowAmount = getUint(getIds[1], borrowAmount); + depositAmount = getUint(getIds[0], depositAmount); + borrowAmount = getUint(getIds[1], borrowAmount); - _depositAmount = _depositAmount == uint(-1) ? address(this).balance : _depositAmount; + depositAmount = depositAmount == uint(-1) ? address(this).balance : depositAmount; - borrowerOperations.openTrove{value: _depositAmount}( + borrowerOperations.openTrove{value: depositAmount}( maxFeePercentage, - _borrowAmount, + borrowAmount, upperHint, lowerHint ); - setUint(setIds[0], _depositAmount); - setUint(setIds[1], _borrowAmount); + setUint(setIds[0], depositAmount); + setUint(setIds[1], borrowAmount); _eventName = "LogOpen(address,uint256,uint256,uint256,uint256[],uint256[])"; - _eventParam = abi.encode(address(this), maxFeePercentage, _depositAmount, _borrowAmount, getIds, setIds); + _eventParam = abi.encode(address(this), maxFeePercentage, depositAmount, borrowAmount, getIds, setIds); } /** @@ -200,37 +200,40 @@ abstract contract LiquityResolver is Events, Helpers { * @param repayAmount Amount of LUSD to repay * @param upperHint Address of the Trove near the upper bound of where the user's Trove should now sit in the ordered Trove list * @param lowerHint Address of the Trove near the lower bound of where the user's Trove should now sit in the ordered Trove list - * @param getDepositId Optional storage slot to retrieve the ETH to deposit - * @param setWithdrawId Optional storage slot to store the withdrawn ETH to - * @param getRepayId Optional storage slot to retrieve the LUSD to repay - * @param setBorrowId Optional storage slot to store the LUSD borrowed + * @param getIds Optional Get Ids for deposit, withdraw, borrow & repay + * @param setIds Optional Set Ids for deposit, withdraw, borrow & repay */ function adjust( uint maxFeePercentage, - uint withdrawAmount, uint depositAmount, + uint withdrawAmount, uint borrowAmount, uint repayAmount, address upperHint, address lowerHint, - uint getDepositId, - uint setWithdrawId, - uint getRepayId, - uint setBorrowId + uint[] getIds, + uint[] setIds ) external payable returns (string memory _eventName, bytes memory _eventParam) { - if (getDepositId != 0 && depositAmount != 0) { - revert("adjust(): Cannot supply a depositAmount if a non-zero getDepositId is supplied"); - } - if (getRepayId != 0 && repayAmount != 0) { - revert("adjust(): Cannot supply a repayAmount if a non-zero getRepayId is supplied"); - } AdjustTrove memory adjustTrove; adjustTrove.maxFeePercentage = maxFeePercentage; - adjustTrove.withdrawAmount = withdrawAmount; - adjustTrove.depositAmount = getUint(getDepositId, depositAmount); - adjustTrove.borrowAmount = borrowAmount; - adjustTrove.repayAmount = getUint(getRepayId, repayAmount); + + depositAmount = getUint(getIds[0], depositAmount); + adjustTrove.depositAmount = depositAmount == uint(-1) ? address(this).balance : depositAmount; + + withdrawAmount = getUint(getIds[1], withdrawAmount); + adjustTrove.withdrawAmount = withdrawAmount == uint(-1) ? troveManager.getTroveColl(address(this)) : withdrawAmount; + + adjustTrove.borrowAmount = getUint(getIds[2], borrowAmount); + + repayAmount = getUint(getIds[3], repayAmount); + if (repayAmount == uint(-1)) { + uint _lusdBal = lusdToken.balanceOf(address(this)); + uint _totalDebt = troveManager.getTroveDebt(address(this)); + repayAmount = _lusdBal > _totalDebt ? _totalDebt : _lusdBal; + } + adjustTrove.repayAmount = repayAmount; + adjustTrove.isBorrow = borrowAmount > 0; borrowerOperations.adjustTrove{value: adjustTrove.depositAmount}( @@ -242,14 +245,13 @@ abstract contract LiquityResolver is Events, Helpers { lowerHint ); - // Allow other spells to use the withdrawn collateral - setUint(setWithdrawId, withdrawAmount); + setUint(setIds[0], depositAmount); + setUint(setIds[1], withdrawAmount); + setUint(setIds[2], borrowAmount); + setUint(setIds[3], repayAmount); - // Allow other spells to use the borrowed amount - setUint(setBorrowId, borrowAmount); - - _eventName = "LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(address(this), maxFeePercentage, depositAmount, withdrawAmount, borrowAmount, repayAmount, getDepositId, setWithdrawId, getRepayId, setBorrowId); + _eventName = "LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256[],uint256[])"; + _eventParam = abi.encode(address(this), maxFeePercentage, depositAmount, withdrawAmount, borrowAmount, repayAmount, getIds, setIds); } /**