diff --git a/contracts/src/BorrowerOperations.sol b/contracts/src/BorrowerOperations.sol index c8bc441d9..32e712d51 100644 --- a/contracts/src/BorrowerOperations.sol +++ b/contracts/src/BorrowerOperations.sol @@ -1160,8 +1160,8 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio function shutdown() external { if (hasBeenShutDown) revert IsShutDown(); - uint256 totalColl = getEntireSystemColl(); - uint256 totalDebt = getEntireSystemDebt(); + uint256 totalColl = getEntireBranchColl(); + uint256 totalDebt = getEntireBranchDebt(); (uint256 price, bool newOracleFailureDetected) = priceFeed.fetchPrice(); // If the oracle failed, the above call to PriceFeed will have shut this branch down if (newOracleFailureDetected) return; @@ -1531,11 +1531,11 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio view returns (uint256 newTCR) { - uint256 totalColl = getEntireSystemColl(); + uint256 totalColl = getEntireBranchColl(); totalColl += _troveChange.collIncrease; totalColl -= _troveChange.collDecrease; - uint256 totalDebt = getEntireSystemDebt(); + uint256 totalDebt = getEntireBranchDebt(); totalDebt += _troveChange.debtIncrease; totalDebt += _troveChange.upfrontFee; totalDebt -= _troveChange.debtDecrease; diff --git a/contracts/src/CollateralRegistry.sol b/contracts/src/CollateralRegistry.sol index 85fb1e995..2c40d1df6 100644 --- a/contracts/src/CollateralRegistry.sol +++ b/contracts/src/CollateralRegistry.sol @@ -133,7 +133,7 @@ contract CollateralRegistry is ICollateralRegistry { ITroveManager troveManager = getTroveManager(index); (,, bool redeemable) = troveManager.getUnbackedPortionPriceAndRedeemability(); if (redeemable) { - uint256 unbackedPortion = troveManager.getEntireSystemDebt(); + uint256 unbackedPortion = troveManager.getEntireBranchDebt(); totals.unbacked += unbackedPortion; unbackedPortions[index] = unbackedPortion; } diff --git a/contracts/src/Dependencies/LiquityBase.sol b/contracts/src/Dependencies/LiquityBase.sol index 18b8e2e11..96cfca84d 100644 --- a/contracts/src/Dependencies/LiquityBase.sol +++ b/contracts/src/Dependencies/LiquityBase.sol @@ -34,14 +34,14 @@ contract LiquityBase is ILiquityBase { } // --- Gas compensation functions --- - function getEntireSystemColl() public view returns (uint256 entireSystemColl) { + function getEntireBranchColl() public view returns (uint256 entireSystemColl) { uint256 activeColl = activePool.getCollBalance(); uint256 liquidatedColl = defaultPool.getCollBalance(); return activeColl + liquidatedColl; } - function getEntireSystemDebt() public view returns (uint256 entireSystemDebt) { + function getEntireBranchDebt() public view returns (uint256 entireSystemDebt) { uint256 activeDebt = activePool.getBoldDebt(); uint256 closedDebt = defaultPool.getBoldDebt(); @@ -49,8 +49,8 @@ contract LiquityBase is ILiquityBase { } function _getTCR(uint256 _price) internal view returns (uint256 TCR) { - uint256 entireSystemColl = getEntireSystemColl(); - uint256 entireSystemDebt = getEntireSystemDebt(); + uint256 entireSystemColl = getEntireBranchColl(); + uint256 entireSystemDebt = getEntireBranchDebt(); TCR = LiquityMath._computeCR(entireSystemColl, entireSystemDebt, _price); diff --git a/contracts/src/Interfaces/ILiquityBase.sol b/contracts/src/Interfaces/ILiquityBase.sol index 6de349b29..c0655b804 100644 --- a/contracts/src/Interfaces/ILiquityBase.sol +++ b/contracts/src/Interfaces/ILiquityBase.sol @@ -8,6 +8,6 @@ import "./IPriceFeed.sol"; interface ILiquityBase { function activePool() external view returns (IActivePool); - function getEntireSystemDebt() external view returns (uint256); - function getEntireSystemColl() external view returns (uint256); + function getEntireBranchDebt() external view returns (uint256); + function getEntireBranchColl() external view returns (uint256); } diff --git a/contracts/src/TroveManager.sol b/contracts/src/TroveManager.sol index eb7efc5aa..ef1785d95 100644 --- a/contracts/src/TroveManager.sol +++ b/contracts/src/TroveManager.sol @@ -1184,7 +1184,7 @@ contract TroveManager is LiquityBase, ITroveManager, ITroveEvents { // --- Trove property getters --- function getUnbackedPortionPriceAndRedeemability() external returns (uint256, uint256, bool) { - uint256 totalDebt = getEntireSystemDebt(); + uint256 totalDebt = getEntireBranchDebt(); uint256 spSize = stabilityPool.getTotalBoldDeposits(); uint256 unbackedPortion = totalDebt > spSize ? totalDebt - spSize : 0; diff --git a/contracts/test/Invariants.t.sol b/contracts/test/Invariants.t.sol index 09da32b07..aa3199000 100644 --- a/contracts/test/Invariants.t.sol +++ b/contracts/test/Invariants.t.sol @@ -265,7 +265,7 @@ contract InvariantsTest is Assertions, Logging, BaseInvariantTest, BaseMultiColl for (uint256 j = 0; j < branches.length; ++j) { ITroveManagerTester troveManager = branches[j].troveManager; uint256 numTroves = troveManager.getTroveIdsCount(); - uint256 systemColl = troveManager.getEntireSystemColl(); + uint256 systemColl = troveManager.getEntireBranchColl(); uint256 trovesColl = 0; for (uint256 i = 0; i < numTroves; ++i) { diff --git a/contracts/test/TestContracts/InvariantsTestHandler.t.sol b/contracts/test/TestContracts/InvariantsTestHandler.t.sol index a6442fd58..a0300d6c8 100644 --- a/contracts/test/TestContracts/InvariantsTestHandler.t.sol +++ b/contracts/test/TestContracts/InvariantsTestHandler.t.sol @@ -541,8 +541,8 @@ contract InvariantsTestHandler is Assertions, BaseHandler, BaseMultiCollateralTe i = _bound(i, 0, branches.length - 1); tcr = _bound(tcr, TCR_MIN, TCR_MAX); - uint256 totalColl = branches[i].troveManager.getEntireSystemColl(); - uint256 totalDebt = branches[i].troveManager.getEntireSystemDebt(); + uint256 totalColl = branches[i].troveManager.getEntireBranchColl(); + uint256 totalDebt = branches[i].troveManager.getEntireBranchDebt(); vm.assume(totalColl > 0); uint256 price = totalDebt * tcr / totalColl; @@ -2376,7 +2376,7 @@ contract InvariantsTestHandler is Assertions, BaseHandler, BaseMultiCollateralTe } function _getTotalDebt(uint256 i) internal view returns (uint256) { - return branches[i].troveManager.getEntireSystemDebt(); + return branches[i].troveManager.getEntireBranchDebt(); } function _getUnbacked(uint256 i) internal view returns (uint256) { @@ -2422,8 +2422,8 @@ contract InvariantsTestHandler is Assertions, BaseHandler, BaseMultiCollateralTe } function _TCR(uint256 i, int256 collDelta, int256 debtDelta, uint256 upfrontFee) internal view returns (uint256) { - uint256 coll = branches[i].troveManager.getEntireSystemColl().add(collDelta); - uint256 debt = branches[i].troveManager.getEntireSystemDebt().add(debtDelta) + upfrontFee; + uint256 coll = branches[i].troveManager.getEntireBranchColl().add(collDelta); + uint256 debt = branches[i].troveManager.getEntireBranchDebt().add(debtDelta) + upfrontFee; return _CR(i, coll, debt); } diff --git a/contracts/test/batchManagementFee.t.sol b/contracts/test/batchManagementFee.t.sol index 6544be7c9..d63b35d06 100644 --- a/contracts/test/batchManagementFee.t.sol +++ b/contracts/test/batchManagementFee.t.sol @@ -504,7 +504,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 10 days); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 entireDebtA = troveManager.getTroveEntireDebt(ATroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA, 2, "Entire debt should be that of trove A"); @@ -513,7 +513,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 5 days); - entireSystemDebt = troveManager.getEntireSystemDebt(); + entireSystemDebt = troveManager.getEntireBranchDebt(); entireDebtA = troveManager.getTroveEntireDebt(ATroveId); uint256 entireDebtC = troveManager.getTroveEntireDebt(CTroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA + entireDebtC, 10, "Entire debt should be A+C"); @@ -533,7 +533,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 5 days); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 entireDebtA = troveManager.getTroveEntireDebt(ATroveId); uint256 entireDebtC = troveManager.getTroveEntireDebt(CTroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA + entireDebtC, 10); @@ -551,7 +551,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 5 days); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 entireDebtA = troveManager.getTroveEntireDebt(ATroveId); uint256 entireDebtC = troveManager.getTroveEntireDebt(CTroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA + entireDebtC, 5); @@ -568,7 +568,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 15 days); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 entireDebtA = troveManager.getTroveEntireDebt(ATroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA, 2); } @@ -590,7 +590,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 5 days); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 entireDebtA = troveManager.getTroveEntireDebt(ATroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA, 4); } @@ -609,7 +609,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 5 days); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 entireDebtA = troveManager.getTroveEntireDebt(ATroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA, 100); } @@ -626,7 +626,7 @@ contract BatchManagementFeeTest is DevTestSetup { vm.warp(block.timestamp + 10 days); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 entireDebtA = troveManager.getTroveEntireDebt(ATroveId); uint256 entireDebtC = troveManager.getTroveEntireDebt(CTroveId); assertApproxEqAbs(entireSystemDebt, entireDebtA + entireDebtC, 10); diff --git a/contracts/test/interestRateAggregate.t.sol b/contracts/test/interestRateAggregate.t.sol index d590e4c7e..9bd46ba33 100644 --- a/contracts/test/interestRateAggregate.t.sol +++ b/contracts/test/interestRateAggregate.t.sol @@ -1414,12 +1414,12 @@ contract InterestRateAggregate is DevTestSetup { // --- getTotalSystemDebt tests --- function testGetEntireSystemDebtReturns0For0TrovesOpen() public { - uint256 entireSystemDebt_1 = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt_1 = troveManager.getEntireBranchDebt(); assertEq(entireSystemDebt_1, 0); vm.warp(block.timestamp + 1 days); - uint256 entireSystemDebt_2 = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt_2 = troveManager.getEntireBranchDebt(); assertEq(entireSystemDebt_2, 0); } @@ -1442,7 +1442,7 @@ contract InterestRateAggregate is DevTestSetup { assertGt(recordedDebt_B, 0); assertGt(recordedDebt_C, 0); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); assertEq(entireSystemDebt, recordedDebt_A + recordedDebt_B + recordedDebt_C); } @@ -1476,7 +1476,7 @@ contract InterestRateAggregate is DevTestSetup { assertGt(accruedInterest_B, 0); assertGt(accruedInterest_C, 0); - uint256 entireSystemDebt = troveManager.getEntireSystemDebt(); + uint256 entireSystemDebt = troveManager.getEntireBranchDebt(); uint256 sumIndividualTroveDebts = recordedDebt_A + accruedInterest_A + recordedDebt_B + accruedInterest_B + recordedDebt_C + accruedInterest_C; diff --git a/contracts/test/multicollateral.t.sol b/contracts/test/multicollateral.t.sol index 13ab72c63..9b305529c 100644 --- a/contracts/test/multicollateral.t.sol +++ b/contracts/test/multicollateral.t.sol @@ -343,10 +343,10 @@ contract MulticollateralTest is DevTestSetup { testValues3.collInitialBalance = contractsArray[2].collToken.balanceOf(A); testValues4.collInitialBalance = contractsArray[3].collToken.balanceOf(A); - testValues1.unbackedPortion = contractsArray[0].troveManager.getEntireSystemDebt() - _spBoldAmount1; - testValues2.unbackedPortion = contractsArray[1].troveManager.getEntireSystemDebt() - _spBoldAmount2; - testValues3.unbackedPortion = contractsArray[2].troveManager.getEntireSystemDebt() - _spBoldAmount3; - testValues4.unbackedPortion = contractsArray[3].troveManager.getEntireSystemDebt() - _spBoldAmount4; + testValues1.unbackedPortion = contractsArray[0].troveManager.getEntireBranchDebt() - _spBoldAmount1; + testValues2.unbackedPortion = contractsArray[1].troveManager.getEntireBranchDebt() - _spBoldAmount2; + testValues3.unbackedPortion = contractsArray[2].troveManager.getEntireBranchDebt() - _spBoldAmount3; + testValues4.unbackedPortion = contractsArray[3].troveManager.getEntireBranchDebt() - _spBoldAmount4; uint256 totalUnbacked = testValues1.unbackedPortion + testValues2.unbackedPortion + testValues3.unbackedPortion + testValues4.unbackedPortion; @@ -455,10 +455,10 @@ contract MulticollateralTest is DevTestSetup { assertGt(expectedFeePct, 0); // Get BOLD debts from each branch - testValues0.branchDebt = contractsArray[0].troveManager.getEntireSystemDebt(); - testValues1.branchDebt = contractsArray[1].troveManager.getEntireSystemDebt(); - testValues2.branchDebt = contractsArray[2].troveManager.getEntireSystemDebt(); - testValues3.branchDebt = contractsArray[3].troveManager.getEntireSystemDebt(); + testValues0.branchDebt = contractsArray[0].troveManager.getEntireBranchDebt(); + testValues1.branchDebt = contractsArray[1].troveManager.getEntireBranchDebt(); + testValues2.branchDebt = contractsArray[2].troveManager.getEntireBranchDebt(); + testValues3.branchDebt = contractsArray[3].troveManager.getEntireBranchDebt(); testValues0.collTokenBalBefore_A = contractsArray[0].collToken.balanceOf(A); testValues1.collTokenBalBefore_A = contractsArray[1].collToken.balanceOf(A); @@ -469,10 +469,10 @@ contract MulticollateralTest is DevTestSetup { redeem(A, redeemAmount); // Check how much BOLD was redeemed from each branch - testValues0.redeemed = testValues0.branchDebt - contractsArray[0].troveManager.getEntireSystemDebt(); - testValues1.redeemed = testValues1.branchDebt - contractsArray[1].troveManager.getEntireSystemDebt(); - testValues2.redeemed = testValues2.branchDebt - contractsArray[2].troveManager.getEntireSystemDebt(); - testValues3.redeemed = testValues3.branchDebt - contractsArray[3].troveManager.getEntireSystemDebt(); + testValues0.redeemed = testValues0.branchDebt - contractsArray[0].troveManager.getEntireBranchDebt(); + testValues1.redeemed = testValues1.branchDebt - contractsArray[1].troveManager.getEntireBranchDebt(); + testValues2.redeemed = testValues2.branchDebt - contractsArray[2].troveManager.getEntireBranchDebt(); + testValues3.redeemed = testValues3.branchDebt - contractsArray[3].troveManager.getEntireBranchDebt(); assertGt(testValues0.redeemed, 0); assertGt(testValues1.redeemed, 0); diff --git a/contracts/test/rebasingBatchShares.t.sol b/contracts/test/rebasingBatchShares.t.sol index c87373254..5734b0ba8 100644 --- a/contracts/test/rebasingBatchShares.t.sol +++ b/contracts/test/rebasingBatchShares.t.sol @@ -102,7 +102,7 @@ contract RebasingBatchShares is DevTestSetup { _logTrovesAndBatch(B, BTroveId); // === 4: Free Loans === // - // uint256 debtB4 = borrowerOperations.getEntireSystemDebt(); + // uint256 debtB4 = borrowerOperations.getEntireBranchDebt(); // We should be able to open a new Trove now //uint256 anotherATroveId = openTroveExpectRevert(A, x + 1, 100 ether, MIN_DEBT, B); //assertEq(anotherATroveId, 0); @@ -122,7 +122,7 @@ contract RebasingBatchShares is DevTestSetup { uint256 balAfter = boldToken.balanceOf(A); // And we can repeat this to get free debt - uint256 debtAfter = borrowerOperations.getEntireSystemDebt(); + uint256 debtAfter = borrowerOperations.getEntireBranchDebt(); assertGt(debtAfter, debtB4, "Debt should have increased"); assertLt(balB4, balAfter, "Something should have benn paid"); diff --git a/frontend/app/src/abi/BorrowerOperations.ts b/frontend/app/src/abi/BorrowerOperations.ts index e490f14bd..5b2510540 100644 --- a/frontend/app/src/abi/BorrowerOperations.ts +++ b/frontend/app/src/abi/BorrowerOperations.ts @@ -123,14 +123,14 @@ export const BorrowerOperations = [ }, { "type": "function", - "name": "getEntireSystemColl", + "name": "getEntireBranchColl", "inputs": [], "outputs": [{ "name": "entireSystemColl", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view", }, { "type": "function", - "name": "getEntireSystemDebt", + "name": "getEntireBranchDebt", "inputs": [], "outputs": [{ "name": "entireSystemDebt", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view", diff --git a/frontend/app/src/abi/PriceFeed.ts b/frontend/app/src/abi/PriceFeed.ts index c0876bb97..93326be03 100644 --- a/frontend/app/src/abi/PriceFeed.ts +++ b/frontend/app/src/abi/PriceFeed.ts @@ -9,7 +9,7 @@ export const PriceFeed = [{ "type": "bool", "internalType": "bool", }], - "stateMutability": "view", + "stateMutability": "nonpayable", }, { "type": "function", "name": "fetchRedemptionPrice", @@ -19,18 +19,12 @@ export const PriceFeed = [{ "type": "bool", "internalType": "bool", }], - "stateMutability": "view", -}, { - "type": "function", - "name": "getEthUsdStalenessThreshold", - "inputs": [], - "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], - "stateMutability": "pure", + "stateMutability": "nonpayable", }, { "type": "function", "name": "getPrice", "inputs": [], - "outputs": [{ "name": "_price", "type": "uint256", "internalType": "uint256" }], + "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view", }, { "type": "function", @@ -47,7 +41,12 @@ export const PriceFeed = [{ }, { "type": "function", "name": "setPrice", - "inputs": [{ "name": "_price", "type": "uint256", "internalType": "uint256" }], - "outputs": [], + "inputs": [{ "name": "price", "type": "uint256", "internalType": "uint256" }], + "outputs": [{ "name": "", "type": "bool", "internalType": "bool" }], "stateMutability": "nonpayable", +}, { + "type": "event", + "name": "LastGoodPriceUpdated", + "inputs": [{ "name": "_lastGoodPrice", "type": "uint256", "indexed": false, "internalType": "uint256" }], + "anonymous": false, }] as const; diff --git a/frontend/app/src/abi/StabilityPool.ts b/frontend/app/src/abi/StabilityPool.ts index 6bf037d9f..de8d260f2 100644 --- a/frontend/app/src/abi/StabilityPool.ts +++ b/frontend/app/src/abi/StabilityPool.ts @@ -142,14 +142,14 @@ export const StabilityPool = [ }, { "type": "function", - "name": "getEntireSystemColl", + "name": "getEntireBranchColl", "inputs": [], "outputs": [{ "name": "entireSystemColl", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view", }, { "type": "function", - "name": "getEntireSystemDebt", + "name": "getEntireBranchDebt", "inputs": [], "outputs": [{ "name": "entireSystemDebt", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view", diff --git a/frontend/app/src/abi/TroveManager.ts b/frontend/app/src/abi/TroveManager.ts index a363f5add..f67e2b535 100644 --- a/frontend/app/src/abi/TroveManager.ts +++ b/frontend/app/src/abi/TroveManager.ts @@ -72,14 +72,14 @@ export const TroveManager = [ }, { "type": "function", - "name": "getEntireSystemColl", + "name": "getEntireBranchColl", "inputs": [], "outputs": [{ "name": "entireSystemColl", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view", }, { "type": "function", - "name": "getEntireSystemDebt", + "name": "getEntireBranchDebt", "inputs": [], "outputs": [{ "name": "entireSystemDebt", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view", diff --git a/frontend/app/src/liquity-utils.ts b/frontend/app/src/liquity-utils.ts index f83f31021..3f995d659 100644 --- a/frontend/app/src/liquity-utils.ts +++ b/frontend/app/src/liquity-utils.ts @@ -601,7 +601,7 @@ export function useBranchDebt(branchId: BranchId) { const BorrowerOperations = getBranchContract(branchId, "BorrowerOperations"); return useReadContract({ ...BorrowerOperations, - functionName: "getEntireSystemDebt", + functionName: "getEntireBranchDebt", query: { refetchInterval: DATA_REFRESH_INTERVAL, select: dnum18,