Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename misleading getters #844

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/CollateralRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/Dependencies/LiquityBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ 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();

return activeDebt + closedDebt;
}

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);

Expand Down
4 changes: 2 additions & 2 deletions contracts/src/Interfaces/ILiquityBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/Invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions contracts/test/TestContracts/InvariantsTestHandler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions contracts/test/batchManagementFee.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions contracts/test/interestRateAggregate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions contracts/test/multicollateral.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/rebasingBatchShares.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/abi/BorrowerOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 10 additions & 11 deletions frontend/app/src/abi/PriceFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const PriceFeed = [{
"type": "bool",
"internalType": "bool",
}],
"stateMutability": "view",
"stateMutability": "nonpayable",
}, {
"type": "function",
"name": "fetchRedemptionPrice",
Expand All @@ -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",
Expand All @@ -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;
4 changes: 2 additions & 2 deletions frontend/app/src/abi/StabilityPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/abi/TroveManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/liquity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading