Skip to content

Commit

Permalink
Remove unused code from contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymx95 committed Apr 25, 2024
1 parent e9f7a33 commit 456684a
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 227 deletions.
30 changes: 11 additions & 19 deletions contracts/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr
uint256 price;
uint256 debtTokenFee;
uint256 netDebt;
uint256 compositeDebt;
uint256 ICR;
uint256 NICR;
uint256 stake;
Expand Down Expand Up @@ -89,25 +88,24 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr
}
_requireAtLeastMinNetDebt(vars.asset, vars.netDebt);

// ICR is based on the composite debt, i.e. the requested debt token amount + borrowing fee + gas comp.
vars.compositeDebt = vars.netDebt;
require(vars.compositeDebt != 0, "compositeDebt cannot be 0");
// ICR is based on the composite debt, i.e. the requested debt token amount + borrowing fee.
require(vars.netDebt != 0, "compositeDebt cannot be 0");

vars.ICR = TrinityMath._computeCR(_assetAmount, vars.compositeDebt, vars.price);
vars.NICR = TrinityMath._computeNominalCR(_assetAmount, vars.compositeDebt);
vars.ICR = TrinityMath._computeCR(_assetAmount, vars.netDebt, vars.price);
vars.NICR = TrinityMath._computeNominalCR(_assetAmount, vars.netDebt);

if (isRecoveryMode) {
_requireICRisAboveCCR(vars.asset, vars.ICR);
} else {
_requireICRisAboveMCR(vars.asset, vars.ICR);
uint256 newTCR = _getNewTCRFromVesselChange(vars.asset, _assetAmount, true, vars.compositeDebt, true, vars.price); // bools: coll increase, debt increase
uint256 newTCR = _getNewTCRFromVesselChange(vars.asset, _assetAmount, true, vars.netDebt, true, vars.price); // bools: coll increase, debt increase
_requireNewTCRisAboveCCR(vars.asset, newTCR);
}

// Set the vessel struct's properties
IVesselManager(vesselManager).setVesselStatus(vars.asset, msg.sender, 1); // Vessel Status 1 = Active
IVesselManager(vesselManager).increaseVesselColl(vars.asset, msg.sender, _assetAmount);
IVesselManager(vesselManager).increaseVesselDebt(vars.asset, msg.sender, vars.compositeDebt);
IVesselManager(vesselManager).increaseVesselDebt(vars.asset, msg.sender, vars.netDebt);

IVesselManager(vesselManager).updateVesselRewardSnapshots(vars.asset, msg.sender);
vars.stake = IVesselManager(vesselManager).updateStakeAndTotalStakes(vars.asset, msg.sender);
Expand All @@ -123,7 +121,7 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr
emit VesselUpdated(
vars.asset,
msg.sender,
vars.compositeDebt,
vars.netDebt,
_assetAmount,
vars.stake,
BorrowerOperation.openVessel
Expand Down Expand Up @@ -255,7 +253,7 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr

// When the adjustment is a debt repayment, check it's a valid amount and that the caller has enough debt tokens
if (!_isDebtIncrease && _debtTokenChange != 0) {
_requireAtLeastMinNetDebt(vars.asset, _getNetDebt(vars.asset, vars.debt) - vars.netDebtChange);
_requireAtLeastMinNetDebt(vars.asset, vars.debt - vars.netDebtChange);
_requireValidDebtTokenRepayment(vars.asset, vars.debt, vars.netDebtChange);
_requireSufficientDebtTokenBalance(_borrower, vars.netDebtChange);
}
Expand Down Expand Up @@ -305,9 +303,7 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr
uint256 coll = IVesselManager(vesselManager).getVesselColl(_asset, msg.sender);
uint256 debt = IVesselManager(vesselManager).getVesselDebt(_asset, msg.sender);

uint256 netDebt = debt;

_requireSufficientDebtTokenBalance(msg.sender, netDebt);
_requireSufficientDebtTokenBalance(msg.sender, debt);

uint256 newTCR = _getNewTCRFromVesselChange(_asset, coll, false, debt, false, price);
_requireNewTCRisAboveCCR(_asset, newTCR);
Expand All @@ -317,8 +313,8 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr

emit VesselUpdated(_asset, msg.sender, 0, 0, 0, BorrowerOperation.closeVessel);

// Burn the repaid debt tokens from the user's balance and the gas compensation from the Gas Pool
_repayDebtTokens(_asset, msg.sender, netDebt);
// Burn the repaid debt tokens from the user's balance
_repayDebtTokens(_asset, msg.sender, debt);

// Send the collateral back to the user
IActivePool(activePool).sendAsset(_asset, msg.sender, coll);
Expand Down Expand Up @@ -672,10 +668,6 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr
return newTCR;
}

function getCompositeDebt(address _asset, uint256 _debt) external view override returns (uint256) {
return _getCompositeDebt(_asset, _debt);
}

function authorizeUpgrade(address newImplementation) public {
_authorizeUpgrade(newImplementation);
}
Expand Down
11 changes: 0 additions & 11 deletions contracts/Dependencies/TrinityBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ import "../Addresses.sol";
* common functions.
*/
abstract contract TrinityBase is ITrinityBase, BaseMath, OwnableUpgradeable, Addresses {
// --- Gas compensation functions ---

// Returns the composite debt (drawn debt + gas compensation) of a vessel, for the purpose of ICR calculation
function _getCompositeDebt(address _asset, uint256 _debt) internal view returns (uint256) {
return _debt;
}

function _getNetDebt(address _asset, uint256 _debt) internal view returns (uint256) {
return _debt;
}

function getEntireSystemColl(address _asset) public view returns (uint256 entireSystemColl) {
uint256 activeColl = IActivePool(activePool).getAssetBalance(_asset);
uint256 liquidatedColl = IDefaultPool(defaultPool).getAssetBalance(_asset);
Expand Down
2 changes: 0 additions & 2 deletions contracts/Interfaces/IBorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ interface IBorrowerOperations {

function claimCollateral(address _asset) external;

function getCompositeDebt(address _asset, uint256 _debt) external view returns (uint256);

function collectVesselFee(
address _asset,
address _borrower
Expand Down
7 changes: 0 additions & 7 deletions contracts/Interfaces/IVesselManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,4 @@ interface IVesselManager is ITrinityBase {
) external;

function isVesselActive(address _asset, address _borrower) external view returns (bool);

function sendGasCompensation(
address _asset,
address _liquidator,
uint256 _debtTokenAmount,
uint256 _assetAmount
) external;
}
3 changes: 0 additions & 3 deletions contracts/Interfaces/IVesselManagerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ interface IVesselManagerOperations is ITrinityBase {
struct LiquidationTotals {
uint256 totalCollInSequence;
uint256 totalDebtInSequence;
uint256 totalCollGasCompensation;
uint256 totalDebtTokenGasCompensation;
uint256 totalDebtToOffset;
uint256 totalCollToSendToSP;
uint256 totalDebtToRedistribute;
Expand All @@ -85,7 +83,6 @@ interface IVesselManagerOperations is ITrinityBase {
struct LiquidationValues {
uint256 entireVesselDebt;
uint256 entireVesselColl;
uint256 collGasCompensation;
uint256 debtTokenGasCompensation;
uint256 debtToOffset;
uint256 collToSendToSP;
Expand Down
8 changes: 0 additions & 8 deletions contracts/TestContracts/VesselManagerTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ contract VesselManagerTester is VesselManager {
return TrinityMath._computeCR(_coll, _debt, _price);
}

function getCompositeDebt(address _asset, uint256 _debt) external view returns (uint256) {
return _getCompositeDebt(_asset, _debt);
}

function unprotectedDecayBaseRateFromBorrowing(address _asset) external returns (uint256) {
baseRate[_asset] = _calcDecayedBaseRate(_asset);
assert(baseRate[_asset] >= 0 && baseRate[_asset] <= DECIMAL_PRECISION);
Expand All @@ -39,10 +35,6 @@ contract VesselManagerTester is VesselManager {
return getRedemptionFee(_asset, _ETHDrawn);
}

function getActualDebtFromComposite(address _asset, uint256 _debtVal) external view returns (uint256) {
return _getNetDebt(_asset, _debtVal);
}

function callInternalRemoveVesselOwner(address _asset, address _vesselOwner) external {
uint256 vesselOwnersArrayLength = VesselOwners[_asset].length;
_removeVesselOwner(_asset, _vesselOwner, vesselOwnersArrayLength);
Expand Down
14 changes: 0 additions & 14 deletions contracts/VesselManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,6 @@ contract VesselManager is IVesselManager, UUPSUpgradeable, ReentrancyGuardUpgrad
emit VesselUpdated(_asset, _borrower, 0, 0, 0, VesselManagerOperation.liquidateInNormalMode);
}

function sendGasCompensation(
address _asset,
address _liquidator,
uint256 _debtTokenAmount,
uint256 _assetAmount
) external nonReentrant onlyVesselManagerOperations {
if (_debtTokenAmount != 0) {
IDebtToken(debtToken).returnFromPool(gasPoolAddress, _liquidator, _debtTokenAmount);
}
if (_assetAmount != 0) {
IActivePool(activePool).sendAsset(_asset, _liquidator, _assetAmount);
}
}

// Internal functions ---------------------------------------------------------------------------------------------

function _redeemCloseVessel(
Expand Down
46 changes: 12 additions & 34 deletions contracts/VesselManagerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,16 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
IActivePool(activePool).sendAsset(_asset, collSurplusPool, totals.totalCollSurplus);
}

IVesselManager(vesselManager).updateSystemSnapshots_excludeCollRemainder(_asset, totals.totalCollGasCompensation);
IVesselManager(vesselManager).updateSystemSnapshots_excludeCollRemainder(_asset, 0);

vars.liquidatedDebt = totals.totalDebtInSequence;
vars.liquidatedColl = totals.totalCollInSequence - totals.totalCollGasCompensation - totals.totalCollSurplus;
vars.liquidatedColl = totals.totalCollInSequence - totals.totalCollSurplus;
emit Liquidation(
_asset,
vars.liquidatedDebt,
vars.liquidatedColl,
totals.totalCollGasCompensation,
totals.totalDebtTokenGasCompensation
);
IVesselManager(vesselManager).sendGasCompensation(
_asset,
msg.sender,
totals.totalDebtTokenGasCompensation,
totals.totalCollGasCompensation
0,
0
);
}

Expand Down Expand Up @@ -144,22 +138,16 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
}

// Update system snapshots
IVesselManager(vesselManager).updateSystemSnapshots_excludeCollRemainder(_asset, totals.totalCollGasCompensation);
IVesselManager(vesselManager).updateSystemSnapshots_excludeCollRemainder(_asset, 0);

vars.liquidatedDebt = totals.totalDebtInSequence;
vars.liquidatedColl = totals.totalCollInSequence - totals.totalCollGasCompensation - totals.totalCollSurplus;
vars.liquidatedColl = totals.totalCollInSequence - totals.totalCollSurplus;
emit Liquidation(
_asset,
vars.liquidatedDebt,
vars.liquidatedColl,
totals.totalCollGasCompensation,
totals.totalDebtTokenGasCompensation
);
IVesselManager(vesselManager).sendGasCompensation(
_asset,
msg.sender,
totals.totalDebtTokenGasCompensation,
totals.totalCollGasCompensation
0,
0
);
}

Expand Down Expand Up @@ -308,11 +296,8 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
}

while (currentVesselBorrower != address(0) && remainingDebt != 0 && vars.maxIterations-- != 0) {
uint256 currentVesselNetDebt = _getNetDebt(
vars.asset,
IVesselManager(vesselManager).getVesselDebt(vars.asset, currentVesselBorrower) +
IVesselManager(vesselManager).getPendingDebtTokenReward(vars.asset, currentVesselBorrower)
);
uint256 currentVesselNetDebt = IVesselManager(vesselManager).getVesselDebt(vars.asset, currentVesselBorrower) +
IVesselManager(vesselManager).getPendingDebtTokenReward(vars.asset, currentVesselBorrower);

if (currentVesselNetDebt <= remainingDebt) {
remainingDebt = remainingDebt - currentVesselNetDebt;
Expand All @@ -331,9 +316,8 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
collLot = (collLot * redemptionSofteningParam) / PERCENTAGE_PRECISION;
uint256 newColl = currentVesselColl - collLot;
uint256 newDebt = currentVesselNetDebt - maxRedeemableDebt;
uint256 compositeDebt = _getCompositeDebt(vars.asset, newDebt);

partialRedemptionHintNewICR = TrinityMath._computeNominalCR(newColl, compositeDebt);
partialRedemptionHintNewICR = TrinityMath._computeNominalCR(newColl, newDebt);
remainingDebt = remainingDebt - maxRedeemableDebt;
}

Expand Down Expand Up @@ -450,7 +434,6 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
vars.entireSystemColl =
vars.entireSystemColl -
singleLiquidation.collToSendToSP -
singleLiquidation.collGasCompensation -
singleLiquidation.collSurplus;

// Add liquidation values to their respective running totals
Expand Down Expand Up @@ -508,10 +491,6 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
LiquidationValues memory singleLiquidation
) internal pure returns (LiquidationTotals memory newTotals) {
// Tally all the values with their respective running totals
newTotals.totalCollGasCompensation = oldTotals.totalCollGasCompensation + singleLiquidation.collGasCompensation;
newTotals.totalDebtTokenGasCompensation =
oldTotals.totalDebtTokenGasCompensation +
singleLiquidation.debtTokenGasCompensation;
newTotals.totalDebtInSequence = oldTotals.totalDebtInSequence + singleLiquidation.entireVesselDebt;
newTotals.totalCollInSequence = oldTotals.totalCollInSequence + singleLiquidation.entireVesselColl;
newTotals.totalDebtToOffset = oldTotals.totalDebtToOffset + singleLiquidation.debtToOffset;
Expand Down Expand Up @@ -761,7 +740,6 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
vars.entireSystemColl =
vars.entireSystemColl -
singleLiquidation.collToSendToSP -
singleLiquidation.collGasCompensation -
singleLiquidation.collSurplus;

// Add liquidation values to their respective running totals
Expand Down Expand Up @@ -927,7 +905,7 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
*/
if (
newNICR != _partialRedemptionHintNICR ||
_getNetDebt(_asset, newDebt) < IAdminContract(adminContract).getMinNetDebt(_asset)
newDebt < IAdminContract(adminContract).getMinNetDebt(_asset)
) {
singleRedemption.cancelledPartial = true;
return singleRedemption;
Expand Down
1 change: 0 additions & 1 deletion test/liquity/ProxyBorrowerWrappersScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
// let VUSD_GAS_COMPENSATION

// const getOpenVesselVUSDAmount = async (asset, totalDebt) => th.getOpenVesselVUSDAmount(contracts, totalDebt, asset)
// const getActualDebtFromComposite = async (compositeDebt) => th.getActualDebtFromComposite(compositeDebt, contracts)
// const getNetBorrowingAmount = async (asset, debtWithFee) => th.getNetBorrowingAmount(contracts, debtWithFee, asset)
// const openVessel = async (params) => th.openVessel(contracts, params)

Expand Down
8 changes: 0 additions & 8 deletions test/trinity/BorrowerOperationsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6576,14 +6576,6 @@ contract("BorrowerOperations", async accounts => {
})
})

// --- getCompositeDebt ---

it("getCompositeDebt(): returns debt + gas comp", async () => {
assert.equal(await borrowerOperations.getCompositeDebt(erc20.address, "0"), 0)
th.assertIsApproximatelyEqual(await borrowerOperations.getCompositeDebt(erc20.address, dec(90, 18)),toBN(dec(90, 18)))
th.assertIsApproximatelyEqual(await borrowerOperations.getCompositeDebt(erc20.address, dec(24423422357345049, 12)),toBN(dec(24423422357345049, 12)))
})

// --- getNewTCRFromVesselChange - (external wrapper in Tester contract calls internal function) ---

describe("getNewTCRFromVesselChange() returns the correct TCR", async () => {
Expand Down
Loading

0 comments on commit 456684a

Please sign in to comment.