Skip to content

Commit

Permalink
Merge pull request #383 from liquity/dedaub_info
Browse files Browse the repository at this point in the history
Dedaub Info issues
  • Loading branch information
bingen authored Aug 29, 2024
2 parents 5b32973 + d3b39ea commit 45f8dc4
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 118 deletions.
11 changes: 5 additions & 6 deletions contracts/src/ActivePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ contract ActivePool is IActivePool {
string public constant NAME = "ActivePool";

IERC20 public immutable collToken;
address public borrowerOperationsAddress;
address public troveManagerAddress;
address public defaultPoolAddress;
address public immutable borrowerOperationsAddress;
address public immutable troveManagerAddress;
address public immutable defaultPoolAddress;

IBoldToken boldToken;

Expand Down Expand Up @@ -173,10 +173,9 @@ contract ActivePool is IActivePool {
function sendCollToDefaultPool(uint256 _amount) external override {
_requireCallerIsTroveManager();

address defaultPoolAddressCached = defaultPoolAddress;
_accountForSendColl(defaultPoolAddressCached, _amount);
_accountForSendColl(defaultPoolAddress, _amount);

IDefaultPool(defaultPoolAddressCached).receiveColl(_amount);
IDefaultPool(defaultPoolAddress).receiveColl(_amount);
}

function _accountForSendColl(address _account, uint256 _amount) internal {
Expand Down
17 changes: 3 additions & 14 deletions contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,15 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
error NewOracleFailureDetected();

event TroveManagerAddressChanged(address _newTroveManagerAddress);
event ActivePoolAddressChanged(address _activePoolAddress);
event DefaultPoolAddressChanged(address _defaultPoolAddress);
event GasPoolAddressChanged(address _gasPoolAddress);
event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress);
event PriceFeedAddressChanged(address _newPriceFeedAddress);
event SortedTrovesAddressChanged(address _sortedTrovesAddress);
event BoldTokenAddressChanged(address _boldTokenAddress);

event ShutDown(uint256 _tcr);
event ShutDownFromOracleFailure(address _oracleAddress);

constructor(IAddressesRegistry _addressesRegistry) AddRemoveManagers(_addressesRegistry) {
constructor(IAddressesRegistry _addressesRegistry) AddRemoveManagers(_addressesRegistry) LiquityBase(_addressesRegistry) {
// This makes impossible to open a trove with zero withdrawn Bold
assert(MIN_DEBT > 0);

Expand All @@ -178,20 +175,14 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
MCR = _addressesRegistry.MCR();

troveManager = _addressesRegistry.troveManager();
activePool = _addressesRegistry.activePool();
defaultPool = _addressesRegistry.defaultPool();
gasPoolAddress = _addressesRegistry.gasPoolAddress();
collSurplusPool = _addressesRegistry.collSurplusPool();
priceFeed = _addressesRegistry.priceFeed();
sortedTroves = _addressesRegistry.sortedTroves();
boldToken = _addressesRegistry.boldToken();

emit TroveManagerAddressChanged(address(troveManager));
emit ActivePoolAddressChanged(address(activePool));
emit DefaultPoolAddressChanged(address(defaultPool));
emit GasPoolAddressChanged(gasPoolAddress);
emit CollSurplusPoolAddressChanged(address(collSurplusPool));
emit PriceFeedAddressChanged(address(priceFeed));
emit SortedTrovesAddressChanged(address(sortedTroves));
emit BoldTokenAddressChanged(address(boldToken));

Expand Down Expand Up @@ -684,7 +675,7 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
_moveTokensFromAdjustment(receiver, _troveChange, vars.boldToken, vars.activePool);
}

function closeTrove(uint256 _troveId) external override returns (uint256) {
function closeTrove(uint256 _troveId) external override {
ITroveManager troveManagerCached = troveManager;
IActivePool activePoolCached = activePool;
IBoldToken boldTokenCached = boldToken;
Expand Down Expand Up @@ -751,8 +742,6 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
activePoolCached.sendColl(receiver, trove.entireColl);

_wipeTroveMappings(_troveId);

return trove.entireColl;
}

function applyPendingDebt(uint256 _troveId, uint256 _lowerHint, uint256 _upperHint) public {
Expand Down Expand Up @@ -1428,7 +1417,7 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
}

function _requireDebtRepaymentGeCollWithdrawal(TroveChange memory _troveChange, uint256 _price) internal pure {
if ((_troveChange.debtDecrease < _troveChange.collDecrease * _price / DECIMAL_PRECISION)) {
if ((_troveChange.debtDecrease * DECIMAL_PRECISION < _troveChange.collDecrease * _price)) {
revert RepaymentNotMatchingCollWithdrawal();
}
}
Expand Down
8 changes: 2 additions & 6 deletions contracts/src/CollSurplusPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ contract CollSurplusPool is ICollSurplusPool {
string public constant NAME = "CollSurplusPool";

IERC20 public immutable collToken;
address public borrowerOperationsAddress;
address public troveManagerAddress;
address public activePoolAddress;
address public immutable borrowerOperationsAddress;
address public immutable troveManagerAddress;

// deposited ether tracker
uint256 internal collBalance;
Expand All @@ -26,7 +25,6 @@ contract CollSurplusPool is ICollSurplusPool {

event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
event TroveManagerAddressChanged(address _newTroveManagerAddress);
event ActivePoolAddressChanged(address _newActivePoolAddress);

event CollBalanceUpdated(address indexed _account, uint256 _newBalance);
event CollSent(address _to, uint256 _amount);
Expand All @@ -35,11 +33,9 @@ contract CollSurplusPool is ICollSurplusPool {
collToken = _addressesRegistry.collToken();
borrowerOperationsAddress = address(_addressesRegistry.borrowerOperations());
troveManagerAddress = address(_addressesRegistry.troveManager());
activePoolAddress = address(_addressesRegistry.activePool());

emit BorrowerOperationsAddressChanged(borrowerOperationsAddress);
emit TroveManagerAddressChanged(troveManagerAddress);
emit ActivePoolAddressChanged(activePoolAddress);
}

/* Returns the collBalance state variable
Expand Down
7 changes: 4 additions & 3 deletions contracts/src/CollateralRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.s

import "./Interfaces/ITroveManager.sol";
import "./Interfaces/IBoldToken.sol";
import "./Dependencies/LiquityBase.sol";
import "./Dependencies/Constants.sol";
import "./Dependencies/LiquityMath.sol";

import "./Interfaces/ICollateralRegistry.sol";

// import "forge-std/console2.sol";

contract CollateralRegistry is LiquityBase, ICollateralRegistry {
contract CollateralRegistry is ICollateralRegistry {
// mapping from Collateral token address to the corresponding TroveManagers
//mapping(address => address) troveManagers;
// See: https://github.com/ethereum/solidity/issues/12587
Expand Down Expand Up @@ -258,7 +259,7 @@ contract CollateralRegistry is LiquityBase, ICollateralRegistry {
return _calcRedemptionFee(getRedemptionRateWithDecay(), _ETHDrawn);
}

function getEffectiveRedemptionFeeInBold(uint256 _redeemAmount) public view override returns (uint256) {
function getEffectiveRedemptionFeeInBold(uint256 _redeemAmount) external view override returns (uint256) {
uint256 totalBoldSupply = boldToken.totalSupply();
uint256 newBaseRate = _getUpdatedBaseRateFromRedemption(_redeemAmount, totalBoldSupply);
return _calcRedemptionFee(_calcRedemptionRate(newBaseRate), _redeemAmount);
Expand Down
9 changes: 4 additions & 5 deletions contracts/src/DefaultPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ contract DefaultPool is IDefaultPool {
string public constant NAME = "DefaultPool";

IERC20 public immutable collToken;
address public troveManagerAddress;
address public activePoolAddress;
address public immutable troveManagerAddress;
address public immutable activePoolAddress;
uint256 internal collBalance; // deposited Coll tracker
uint256 internal BoldDebt; // debt

Expand Down Expand Up @@ -67,14 +67,13 @@ contract DefaultPool is IDefaultPool {

function sendCollToActivePool(uint256 _amount) external override {
_requireCallerIsTroveManager();
address activePool = activePoolAddress; // cache to save an SLOAD
uint256 newCollBalance = collBalance - _amount;
collBalance = newCollBalance;
emit DefaultPoolCollBalanceUpdated(newCollBalance);
emit EtherSent(activePool, _amount);
emit EtherSent(activePoolAddress, _amount);

// Send Coll to Active Pool and increase its recorded Coll balance
IActivePool(activePool).receiveColl(_amount);
IActivePool(activePoolAddress).receiveColl(_amount);
}

function receiveColl(uint256 _amount) external {
Expand Down
16 changes: 14 additions & 2 deletions contracts/src/Dependencies/LiquityBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.18;

import "./Constants.sol";
import "./LiquityMath.sol";
import "../Interfaces/IAddressesRegistry.sol";
import "../Interfaces/IActivePool.sol";
import "../Interfaces/IDefaultPool.sol";
import "../Interfaces/IPriceFeed.sol";
Expand All @@ -17,11 +18,22 @@ import "../Interfaces/ILiquityBase.sol";
*/
contract LiquityBase is ILiquityBase {
IActivePool public activePool;

IDefaultPool internal defaultPool;

IPriceFeed internal priceFeed;

event ActivePoolAddressChanged(address _newActivePoolAddress);
event DefaultPoolAddressChanged(address _newDefaultPoolAddress);
event PriceFeedAddressChanged(address _newPriceFeedAddress);

constructor(IAddressesRegistry _addressesRegistry) {
activePool = _addressesRegistry.activePool();
defaultPool = _addressesRegistry.defaultPool();
priceFeed = _addressesRegistry.priceFeed();

emit ActivePoolAddressChanged(address(activePool));
emit DefaultPoolAddressChanged(address(defaultPool));
emit PriceFeedAddressChanged(address(priceFeed));
}
// --- Gas compensation functions ---

function getEntireSystemColl() public view returns (uint256 entireSystemColl) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/GasPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "./Interfaces/ITroveManager.sol";

/**
* The purpose of this contract is to hold WETH tokens for gas compensation:
* https://github.com/liquity/dev#gas-compensation
* https://github.com/liquity/bold/?tab=readme-ov-file#liquidation-gas-compensation
* When a borrower opens a trove, an additional amount of WETH is pulled,
* and sent to this contract.
* When a borrower closes their active trove, this gas compensation is refunded
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/Interfaces/IBorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface IBorrowerOperations is ILiquityBase, IAddRemoveManagers {

function repayBold(uint256 _troveId, uint256 _amount) external;

function closeTrove(uint256 _troveId) external returns (uint256);
function closeTrove(uint256 _troveId) external;

function adjustTrove(
uint256 _troveId,
Expand Down
2 changes: 0 additions & 2 deletions contracts/src/Interfaces/IStabilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.0;

import "./IActivePool.sol";
import "./ILiquityBase.sol";
import "./IBorrowerOperations.sol";
import "./IBoldToken.sol";
import "./ITroveManager.sol";
import "./IBoldRewardsReceiver.sol";
Expand All @@ -30,7 +29,6 @@ import "./IBoldRewardsReceiver.sol";
*
*/
interface IStabilityPool is ILiquityBase, IBoldRewardsReceiver {
function borrowerOperations() external view returns (IBorrowerOperations);
function boldToken() external view returns (IBoldToken);
function troveManager() external view returns (ITroveManager);

Expand Down
1 change: 1 addition & 0 deletions contracts/src/Interfaces/ITroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;

import "./ILiquityBase.sol";
import "./ITroveNFT.sol";
import "./IBorrowerOperations.sol";
import "./IStabilityPool.sol";
import "./IBoldToken.sol";
import "./ISortedTroves.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/SortedTroves.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ contract SortedTroves is ISortedTroves {
event TroveManagerAddressChanged(address _troveManagerAddress);
event BorrowerOperationsAddressChanged(address _borrowerOperationsAddress);

address public borrowerOperationsAddress;
ITroveManager public troveManager;
address public immutable borrowerOperationsAddress;
ITroveManager public immutable troveManager;

// Information for a node in the list
struct Node {
Expand Down
32 changes: 5 additions & 27 deletions contracts/src/StabilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

import "./Interfaces/IStabilityPool.sol";
import "./Interfaces/IAddressesRegistry.sol";
import "./Interfaces/IBorrowerOperations.sol";
import "./Interfaces/IStabilityPoolEvents.sol";
import "./Interfaces/IBorrowerOperations.sol";
import "./Interfaces/ITroveManager.sol";
import "./Interfaces/IBoldToken.sol";
import "./Interfaces/ISortedTroves.sol";
Expand Down Expand Up @@ -136,11 +134,10 @@ contract StabilityPool is LiquityBase, IStabilityPool, IStabilityPoolEvents {
string public constant NAME = "StabilityPool";

IERC20 public immutable collToken;
IBorrowerOperations public borrowerOperations;
ITroveManager public troveManager;
IBoldToken public boldToken;
ITroveManager public immutable troveManager;
IBoldToken public immutable boldToken;
// Needed to check if there are pending liquidations
ISortedTroves public sortedTroves;
ISortedTroves public immutable sortedTroves;

uint256 internal collBalance; // deposited ether tracker

Expand Down Expand Up @@ -206,32 +203,19 @@ contract StabilityPool is LiquityBase, IStabilityPool, IStabilityPoolEvents {

// --- Events ---

event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);
event TroveManagerAddressChanged(address _newTroveManagerAddress);
event ActivePoolAddressChanged(address _newActivePoolAddress);
event DefaultPoolAddressChanged(address _newDefaultPoolAddress);
event BoldTokenAddressChanged(address _newBoldTokenAddress);
event SortedTrovesAddressChanged(address _newSortedTrovesAddress);
event PriceFeedAddressChanged(address _newPriceFeedAddress);

constructor(IAddressesRegistry _addressesRegistry) {
constructor(IAddressesRegistry _addressesRegistry) LiquityBase(_addressesRegistry) {
collToken = _addressesRegistry.collToken();
borrowerOperations = _addressesRegistry.borrowerOperations();
troveManager = _addressesRegistry.troveManager();
activePool = _addressesRegistry.activePool();
boldToken = _addressesRegistry.boldToken();
sortedTroves = _addressesRegistry.sortedTroves();
priceFeed = _addressesRegistry.priceFeed();

emit BorrowerOperationsAddressChanged(address(borrowerOperations));
emit TroveManagerAddressChanged(address(troveManager));
emit ActivePoolAddressChanged(address(activePool));
emit BoldTokenAddressChanged(address(boldToken));
emit SortedTrovesAddressChanged(address(sortedTroves));
emit PriceFeedAddressChanged(address(priceFeed));

// Allow funds movements between Liquity contracts
collToken.approve(address(borrowerOperations), type(uint256).max);
}

// --- Getters for public variables. Required by IPool interface ---
Expand Down Expand Up @@ -539,8 +523,6 @@ contract StabilityPool is LiquityBase, IStabilityPool, IStabilityPoolEvents {
}

function _moveOffsetCollAndDebt(uint256 _collToAdd, uint256 _debtToOffset) internal {
IActivePool activePoolCached = activePool;

// Cancel the liquidated Bold debt with the Bold in the stability pool
_updateTotalBoldDeposits(0, _debtToOffset);

Expand All @@ -552,7 +534,7 @@ contract StabilityPool is LiquityBase, IStabilityPool, IStabilityPoolEvents {
collBalance = newCollBalance;

// Pull Coll from Active Pool
activePoolCached.sendColl(address(this), _collToAdd);
activePool.sendColl(address(this), _collToAdd);

emit StabilityPoolCollBalanceUpdated(newCollBalance);
}
Expand Down Expand Up @@ -810,8 +792,4 @@ contract StabilityPool is LiquityBase, IStabilityPool, IStabilityPoolEvents {
function _requireNonZeroAmount(uint256 _amount) internal pure {
require(_amount > 0, "StabilityPool: Amount must be non-zero");
}

function _requireValidKickbackRate(uint256 _kickbackRate) internal pure {
require(_kickbackRate <= DECIMAL_PRECISION, "StabilityPool: Kickback rate must be in range [0,1]");
}
}
Loading

0 comments on commit 45f8dc4

Please sign in to comment.