From b673f2f3cd76542155bbf0658b8ca34bfad017c0 Mon Sep 17 00:00:00 2001 From: codinghistorian Date: Thu, 21 Dec 2023 11:12:11 +0400 Subject: [PATCH 1/6] FXD-72 '23 Dec 21 adding comment to setDecentralizedStatesStatus fn setDecentralizedStatesStatus fn emits the event before the fn routine finishes. The reason is to show old state from storage and the new state from call data. Comments are added to setDecentralizedStatesStatus in FlashMintModule and StableSwapModule. --- contracts/main/flash-mint/FlashMintModule.sol | 2 +- contracts/main/stablecoin-core/StableSwapModule.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/main/flash-mint/FlashMintModule.sol b/contracts/main/flash-mint/FlashMintModule.sol index 28f8e79f..022a8e73 100644 --- a/contracts/main/flash-mint/FlashMintModule.sol +++ b/contracts/main/flash-mint/FlashMintModule.sol @@ -123,7 +123,7 @@ contract FlashMintModule is CommonMath, PausableUpgradeable, IERC3156FlashLender feeRate = _data; emit LogSetFeeRate(_data); } - + // To show old state from storage and the new state from call data, emits before changing state function setDecentralizedStatesStatus(bool _status) external onlyOwner { emit LogDecentralizedStateStatus(isDecentralizedState, _status); isDecentralizedState = _status; diff --git a/contracts/main/stablecoin-core/StableSwapModule.sol b/contracts/main/stablecoin-core/StableSwapModule.sol index 4a5bb8a5..aa76cc28 100644 --- a/contracts/main/stablecoin-core/StableSwapModule.sol +++ b/contracts/main/stablecoin-core/StableSwapModule.sol @@ -197,7 +197,7 @@ contract StableSwapModule is PausableUpgradeable, ReentrancyGuardUpgradeable, IS feeOut = _feeOut; emit LogSetFeeOut(msg.sender, _feeOut); } - + // To show old state from storage and the new state from call data, emits before changing state function setDecentralizedStatesStatus(bool _status) external onlyOwner { emit LogDecentralizedStateStatus(isDecentralizedState, _status); isDecentralizedState = _status; From a0a3a62455dadd903f1f997f212a8321f7261497 Mon Sep 17 00:00:00 2001 From: codinghistorian Date: Thu, 21 Dec 2023 12:07:48 +0400 Subject: [PATCH 2/6] FXD-72 '23 Dec 21 adding event to setAccessControlConfig fns 0)events for setAccessControlConfig fns were missing before. Therefore, added in this commit. 1)prettier 2)solhint --- contracts/main/flash-mint/FlashMintModule.sol | 1 + contracts/main/interfaces/IDelayPriceFeed.sol | 2 ++ .../interfaces/IFathomCentralizedOracle.sol | 2 ++ .../main/price-feeders/DelayPriceFeedBase.sol | 1 + .../main/price-oracles/FathomPriceOracle.sol | 1 + .../main/price-oracles/PluginPriceOracle.sol | 1 + contracts/main/stablecoin-core/BookKeeper.sol | 20 ++++++------- .../main/stablecoin-core/StableSwapModule.sol | 1 + .../config/CollateralPoolConfig.sol | 29 ++++++++++--------- .../mocks/ParanoidDexOraclePriceFeed.sol | 2 ++ .../CentralizedOraclePriceFeed.test.js | 6 ++-- 11 files changed, 39 insertions(+), 27 deletions(-) diff --git a/contracts/main/flash-mint/FlashMintModule.sol b/contracts/main/flash-mint/FlashMintModule.sol index 022a8e73..bf0da502 100644 --- a/contracts/main/flash-mint/FlashMintModule.sol +++ b/contracts/main/flash-mint/FlashMintModule.sol @@ -123,6 +123,7 @@ contract FlashMintModule is CommonMath, PausableUpgradeable, IERC3156FlashLender feeRate = _data; emit LogSetFeeRate(_data); } + // To show old state from storage and the new state from call data, emits before changing state function setDecentralizedStatesStatus(bool _status) external onlyOwner { emit LogDecentralizedStateStatus(isDecentralizedState, _status); diff --git a/contracts/main/interfaces/IDelayPriceFeed.sol b/contracts/main/interfaces/IDelayPriceFeed.sol index 1adf56fd..42cdc5ca 100644 --- a/contracts/main/interfaces/IDelayPriceFeed.sol +++ b/contracts/main/interfaces/IDelayPriceFeed.sol @@ -13,6 +13,8 @@ interface IDelayPriceFeed is IPriceFeed { event LogPeekPriceFailed(address indexed _caller, string _reason); + event LogSetAccessControlConfig(address indexed _caller, address _accessControlConfig); + function setTimeDelay(uint256 _second) external; function timeDelay() external view returns (uint256); diff --git a/contracts/main/interfaces/IFathomCentralizedOracle.sol b/contracts/main/interfaces/IFathomCentralizedOracle.sol index 3b4d5139..19e859b1 100644 --- a/contracts/main/interfaces/IFathomCentralizedOracle.sol +++ b/contracts/main/interfaces/IFathomCentralizedOracle.sol @@ -2,5 +2,7 @@ pragma solidity 0.8.17; interface IFathomCentralizedOracle { + event LogSetAccessControlConfig(address indexed _caller, address _accessControlConfig); + function getPrice() external view returns (uint256 price, uint256 lastUpdate); } diff --git a/contracts/main/price-feeders/DelayPriceFeedBase.sol b/contracts/main/price-feeders/DelayPriceFeedBase.sol index 50330565..aba94a25 100644 --- a/contracts/main/price-feeders/DelayPriceFeedBase.sol +++ b/contracts/main/price-feeders/DelayPriceFeedBase.sol @@ -36,6 +36,7 @@ abstract contract DelayPriceFeedBase is PausableUpgradeable, IDelayPriceFeed { "DelayPriceFeed/msgsender-not-owner" ); accessControlConfig = IAccessControlConfig(_accessControlConfig); + emit LogSetAccessControlConfig(msg.sender, _accessControlConfig); } function setPriceLife(uint256 _second) external onlyOwner { diff --git a/contracts/main/price-oracles/FathomPriceOracle.sol b/contracts/main/price-oracles/FathomPriceOracle.sol index e4eddd12..a2209164 100644 --- a/contracts/main/price-oracles/FathomPriceOracle.sol +++ b/contracts/main/price-oracles/FathomPriceOracle.sol @@ -31,6 +31,7 @@ contract FathomPriceOracle is Initializable, IFathomCentralizedOracle { "FathomPriceOracle/msgsender-not-owner" ); accessControlConfig = IAccessControlConfig(_accessControlConfig); + emit LogSetAccessControlConfig(msg.sender, _accessControlConfig); } function setOracle(address _oracle) external onlyOwner { diff --git a/contracts/main/price-oracles/PluginPriceOracle.sol b/contracts/main/price-oracles/PluginPriceOracle.sol index b50431ff..f19decba 100644 --- a/contracts/main/price-oracles/PluginPriceOracle.sol +++ b/contracts/main/price-oracles/PluginPriceOracle.sol @@ -31,6 +31,7 @@ contract PluginPriceOracle is Initializable, IFathomCentralizedOracle { "PluginPriceOracle/msgsender-not-owner" ); accessControlConfig = IAccessControlConfig(_accessControlConfig); + emit LogSetAccessControlConfig(msg.sender, _accessControlConfig); } function setOracle(address _oracle) external onlyOwner { diff --git a/contracts/main/stablecoin-core/BookKeeper.sol b/contracts/main/stablecoin-core/BookKeeper.sol index 3fea36b0..95618b6b 100644 --- a/contracts/main/stablecoin-core/BookKeeper.sol +++ b/contracts/main/stablecoin-core/BookKeeper.sol @@ -156,7 +156,6 @@ contract BookKeeper is IBookKeeper, ICagable, IPausable, CommonMath, PausableUpg IAccessControlConfig(_accessControlConfig).hasRole(IAccessControlConfig(_accessControlConfig).OWNER_ROLE(), msg.sender), "BookKeeper/msgsender-not-owner" ); - accessControlConfig = _accessControlConfig; emit LogSetAccessControlConfig(msg.sender, _accessControlConfig); } @@ -224,7 +223,8 @@ contract BookKeeper is IBookKeeper, ICagable, IPausable, CommonMath, PausableUpg /// @notice Moves collateral tokens from one address (often a position address) to another in a specified collateral pool. /// @dev This function can only be called by an entity with the Collateral Manager role when the BookKeeper contract is not paused. - /// @dev It also requires that the entity making the call has the authority to adjust the position (or any address that holds collateralToken), as determined by `_requireAllowedPositionAdjustment`. + /// @dev It also requires that the entity making the call has the authority to adjust the position (or any address that holds collateralToken), + /// as determined by `_requireAllowedPositionAdjustment`. /// @param _collateralPoolId The ID of the collateral pool from which the collateral tokens are being moved. /// @param _src The address from which collateral tokens are being moved. /// @param _dst The address to which collateral tokens are being moved. @@ -416,14 +416,14 @@ contract BookKeeper is IBookKeeper, ICagable, IPausable, CommonMath, PausableUpg totalUnbackedStablecoin = sub(totalUnbackedStablecoin, _debtValue); } - /// @notice Settles the system's bad debt of the caller. - /// @dev This function can be called by the SystemDebtEngine, which incurs the system debt. The BookKeeper contract must not be paused. - /// @dev Even though the function has no modifier that restricts access exclusively to SystemDebtEngine, - /// the action of the function—reducing the systemBadDebt of msg.sender—effectively limits the function callers to SystemDebtEngine. - /// @dev To execute this function, the SystemDebtEngine must have enough stablecoin, which typically comes from the protocol's surplus. - /// @dev A successful execution of this function removes the bad debt from the system. - /// @param _value The amount of bad debt to be settled. - //// + /// @notice Settles the system's bad debt of the caller. + /// @dev This function can be called by the SystemDebtEngine, which incurs the system debt. The BookKeeper contract must not be paused. + /// @dev Even though the function has no modifier that restricts access exclusively to SystemDebtEngine, + /// the action of the function—reducing the systemBadDebt of msg.sender—effectively limits the function callers to SystemDebtEngine. + /// @dev To execute this function, the SystemDebtEngine must have enough stablecoin, which typically comes from the protocol's surplus. + /// @dev A successful execution of this function removes the bad debt from the system. + /// @param _value The amount of bad debt to be settled. + //// function settleSystemBadDebt(uint256 _value) external override nonReentrant whenNotPaused { systemBadDebt[msg.sender] -= _value; stablecoin[msg.sender] -= _value; diff --git a/contracts/main/stablecoin-core/StableSwapModule.sol b/contracts/main/stablecoin-core/StableSwapModule.sol index aa76cc28..3999e8b9 100644 --- a/contracts/main/stablecoin-core/StableSwapModule.sol +++ b/contracts/main/stablecoin-core/StableSwapModule.sol @@ -197,6 +197,7 @@ contract StableSwapModule is PausableUpgradeable, ReentrancyGuardUpgradeable, IS feeOut = _feeOut; emit LogSetFeeOut(msg.sender, _feeOut); } + // To show old state from storage and the new state from call data, emits before changing state function setDecentralizedStatesStatus(bool _status) external onlyOwner { emit LogDecentralizedStateStatus(isDecentralizedState, _status); diff --git a/contracts/main/stablecoin-core/config/CollateralPoolConfig.sol b/contracts/main/stablecoin-core/config/CollateralPoolConfig.sol index e23c9ab4..8a703e1c 100644 --- a/contracts/main/stablecoin-core/config/CollateralPoolConfig.sol +++ b/contracts/main/stablecoin-core/config/CollateralPoolConfig.sol @@ -147,20 +147,21 @@ contract CollateralPoolConfig is Initializable, ICollateralPoolConfig { _collateralPools[_poolId].liquidationRatio = _liquidationRatio; emit LogSetLiquidationRatio(msg.sender, _poolId, _liquidationRatio); } -/// @dev Set the stability fee rate of the collateral pool. -/// The rate to be set here is the `r` in: -/// r^N = APR -/// Where: -/// r = stability fee rate -/// N = Accumulation frequency which is per-second in this case; the value will be 60*60*24*365 = 31536000 to signify the number of seconds within a year. -/// APR = the annual percentage rate -/// For example, to achieve 0.5% APR for stability fee rate: -/// r^31536000 = 1.005 -/// Find the 31536000th root of 1.005 and we will get: -/// r = 1.000000000158153903837946258002097... -/// The rate is in [ray] format, so the actual value of `stabilityFeeRate` will be: -/// stabilityFeeRate = 1000000000158153903837946258 -/// The above `stabilityFeeRate` will be the value we will use in this contract. + + /// @dev Set the stability fee rate of the collateral pool. + /// The rate to be set here is the `r` in: + /// r^N = APR + /// Where: + /// r = stability fee rate + /// N = Accumulation frequency which is per-second in this case; the value will be 60*60*24*365 = 31536000 to signify the number of seconds within a year. + /// APR = the annual percentage rate + /// For example, to achieve 0.5% APR for stability fee rate: + /// r^31536000 = 1.005 + /// Find the 31536000th root of 1.005 and we will get: + /// r = 1.000000000158153903837946258002097... + /// The rate is in [ray] format, so the actual value of `stabilityFeeRate` will be: + /// stabilityFeeRate = 1000000000158153903837946258 + /// The above `stabilityFeeRate` will be the value we will use in this contract. function setStabilityFeeRate(bytes32 _collateralPool, uint256 _stabilityFeeRate) external onlyOwner { require(_stabilityFeeRate >= RAY, "CollateralPoolConfig/invalid-stability-fee-rate"); // Maximum stability fee rate is 50% yearly diff --git a/contracts/tests/mocks/ParanoidDexOraclePriceFeed.sol b/contracts/tests/mocks/ParanoidDexOraclePriceFeed.sol index a4839db0..72c42cb9 100644 --- a/contracts/tests/mocks/ParanoidDexOraclePriceFeed.sol +++ b/contracts/tests/mocks/ParanoidDexOraclePriceFeed.sol @@ -28,6 +28,7 @@ contract ParanoidDexOraclePriceFeed is PausableUpgradeable, IPriceFeed { address[] public verificationFeeds; event LogSetTimeDelay(address indexed _caller, uint256 _second); + event LogSetAccessControlConfig(address indexed _caller, address _accessControlConfig); modifier onlyOwner() { require(accessControlConfig.hasRole(accessControlConfig.OWNER_ROLE(), msg.sender), "!ownerRole"); @@ -83,6 +84,7 @@ contract ParanoidDexOraclePriceFeed is PausableUpgradeable, IPriceFeed { "FathomOraclePriceFeed/msgsender-not-owner" ); accessControlConfig = IAccessControlConfig(_accessControlConfig); + emit LogSetAccessControlConfig(msg.sender, _accessControlConfig); } function addVerificationFeed(address _priceFeed) external onlyOwner { diff --git a/scripts/tests/unit/price-feeds/CentralizedOraclePriceFeed.test.js b/scripts/tests/unit/price-feeds/CentralizedOraclePriceFeed.test.js index 87965882..04293cc7 100644 --- a/scripts/tests/unit/price-feeds/CentralizedOraclePriceFeed.test.js +++ b/scripts/tests/unit/price-feeds/CentralizedOraclePriceFeed.test.js @@ -6,7 +6,7 @@ chai.use(solidity); const { ethers } = require("ethers"); const { WeiPerWad } = require("../../helper/unit"); -const { DeployerAddress, AddressZero} = require("../../helper/address"); +const { DeployerAddress, AddressZero } = require("../../helper/address"); const { getContract, createMock } = require("../../helper/contracts"); const { increase, latest } = require('../../helper/time'); const { formatBytes32String } = ethers.utils @@ -40,7 +40,7 @@ describe("CentralizedOraclePriceFeed", () => { }) }) - context("sender isn't ownerfor the new accessc ontrol", async () => { + context("sender isn't owner for the new accessc ontrol", async () => { it("should revert", async () => { await mockedAccessControlConfig.mock.hasRole.returns(true); const mockedAccessControlConfig2 = await createMock("AccessControlConfig"); @@ -195,7 +195,7 @@ describe("CentralizedOraclePriceFeed", () => { await increase(900); await mockedCentralizedPriceOracle.mock.getPrice.returns(WeiPerWad.mul(4), await latest()); await centralizedOraclePriceFeed.peekPrice(); -; + ; expect(await centralizedOraclePriceFeed.readPrice()).to.be.equal(WeiPerWad.mul(3)); expect((await centralizedOraclePriceFeed.delayedPrice()).lastUpdate).to.be.equal(expectedTS); }) From 2ac77bfb9b1d3e3627792fa353b0eed212a8cd9c Mon Sep 17 00:00:00 2001 From: codinghistorian Date: Thu, 21 Dec 2023 13:42:59 +0400 Subject: [PATCH 3/6] FXD-72 '23 Dec 21 adding event to WL, setBookKeeper fns 0)LogSetBookKeeper event added 1)LogAddToWhitelist, LogRemoveFromWhitelist events added 2)LogNewDebtAccumulatedRate event added --- contracts/main/stablecoin-core/BookKeeper.sol | 5 ++++- contracts/main/stablecoin-core/LiquidationEngine.sol | 6 ++++++ contracts/main/stablecoin-core/PriceOracle.sol | 2 ++ contracts/main/stablecoin-core/StabilityFeeCollector.sol | 2 ++ .../CollateralTokenAdapter/CollateralTokenAdapter.sol | 7 ++++--- .../FixedSpreadLiquidationStrategy.sol | 2 ++ contracts/tests/mocks/MockCollateralTokenAdapter.sol | 4 ++++ 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/contracts/main/stablecoin-core/BookKeeper.sol b/contracts/main/stablecoin-core/BookKeeper.sol index 95618b6b..e4c2b47a 100644 --- a/contracts/main/stablecoin-core/BookKeeper.sol +++ b/contracts/main/stablecoin-core/BookKeeper.sol @@ -58,7 +58,8 @@ contract BookKeeper is IBookKeeper, ICagable, IPausable, CommonMath, PausableUpg event LogAddCollateral(address indexed _caller, address indexed _usr, int256 _amount); event LogMoveCollateral(address indexed _caller, bytes32 indexed _collateralPoolId, address _src, address indexed _dst, uint256 _amount); event LogMoveStablecoin(address indexed _caller, address _src, address indexed _dst, uint256 _amount); - + event LogAddToWhitelist(address indexed _user); + event LogRemoveFromWhitelist(address indexed _user); event StablecoinIssuedAmount(uint256 _totalStablecoinIssued, bytes32 indexed _collateralPoolId, uint256 _poolStablecoinIssued); modifier onlyOwner() { @@ -196,6 +197,7 @@ contract BookKeeper is IBookKeeper, ICagable, IPausable, CommonMath, PausableUpg /// @dev Emits no events. function addToWhitelist(address _toBeWhitelistedAddress) external override whenNotPaused { positionWhitelist[msg.sender][_toBeWhitelistedAddress] = 1; + emit LogAddToWhitelist(_toBeWhitelistedAddress); } /// @dev Revokes the allowance from the `toBeRemovedAddress` to adjust the position address of the caller. @@ -204,6 +206,7 @@ contract BookKeeper is IBookKeeper, ICagable, IPausable, CommonMath, PausableUpg /// @dev Emits no events. function removeFromWhitelist(address _toBeRemovedAddress) external override whenNotPaused { positionWhitelist[msg.sender][_toBeRemovedAddress] = 0; + emit LogRemoveFromWhitelist(_toBeRemovedAddress); } // --- Core Logic --- diff --git a/contracts/main/stablecoin-core/LiquidationEngine.sol b/contracts/main/stablecoin-core/LiquidationEngine.sol index 5d3c8211..6b96c022 100644 --- a/contracts/main/stablecoin-core/LiquidationEngine.sol +++ b/contracts/main/stablecoin-core/LiquidationEngine.sol @@ -46,6 +46,9 @@ contract LiquidationEngine is PausableUpgradeable, ReentrancyGuardUpgradeable, I mapping(address => bool) public liquidatorsWhitelist; event LiquidationFail(bytes32 _collateralPoolIds, address _positionAddresses, address _liquidator, string reason); + event LogSetBookKeeper(address indexed _newAddress); + event LogAddToWhitelist(address indexed _user); + event LogRemoveFromWhitelist(address indexed _user); modifier onlyOwnerOrShowStopper() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig()); @@ -105,6 +108,7 @@ contract LiquidationEngine is PausableUpgradeable, ReentrancyGuardUpgradeable, I function addToWhitelist(address _toBeWhitelisted) external onlyOwnerOrGov { require(_toBeWhitelisted != address(0), "LiquidationEngine/whitelist-invalidAddress"); liquidatorsWhitelist[_toBeWhitelisted] = true; + emit LogAddToWhitelist(_toBeWhitelisted); } /// @notice Remove a liquidator from the whitelist @@ -112,6 +116,7 @@ contract LiquidationEngine is PausableUpgradeable, ReentrancyGuardUpgradeable, I /// @dev Can only be called by the contract owner or the governance system function removeFromWhitelist(address _toBeRemoved) external onlyOwnerOrGov { liquidatorsWhitelist[_toBeRemoved] = false; + emit LogRemoveFromWhitelist(_toBeRemoved); } /// @notice Batch liquidate multiple positions @@ -208,6 +213,7 @@ contract LiquidationEngine is PausableUpgradeable, ReentrancyGuardUpgradeable, I function setBookKeeper(address _bookKeeper) external onlyOwner isLive { require(IBookKeeper(_bookKeeper).totalStablecoinIssued() >= 0, "LiquidationEngine/invalid-bookKeeper"); // Sanity Check Call bookKeeper = IBookKeeper(_bookKeeper); + emit LogSetBookKeeper(_bookKeeper); } // --- Cage --- diff --git a/contracts/main/stablecoin-core/PriceOracle.sol b/contracts/main/stablecoin-core/PriceOracle.sol index 93cc0217..2996be3c 100644 --- a/contracts/main/stablecoin-core/PriceOracle.sol +++ b/contracts/main/stablecoin-core/PriceOracle.sol @@ -39,6 +39,7 @@ contract PriceOracle is CommonMath, PausableUpgradeable, IPriceOracle, ICagable, ); event LogSetStableCoinReferencePrice(address indexed _caller, uint256 _data); + event LogSetBookKeeper(address indexed _newAddress); modifier onlyOwner() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig()); @@ -82,6 +83,7 @@ contract PriceOracle is CommonMath, PausableUpgradeable, IPriceOracle, ICagable, function setBookKeeper(address _bookKeeper) external onlyOwner isLive { require(IBookKeeper(_bookKeeper).totalStablecoinIssued() >= 0, "ShowStopper/invalid-bookKeeper"); // Sanity Check Call bookKeeper = IBookKeeper(_bookKeeper); + emit LogSetBookKeeper(_bookKeeper); } function setStableCoinReferencePrice(uint256 _referencePrice) external onlyOwner isLive { diff --git a/contracts/main/stablecoin-core/StabilityFeeCollector.sol b/contracts/main/stablecoin-core/StabilityFeeCollector.sol index 2b52dd62..9a45dca6 100644 --- a/contracts/main/stablecoin-core/StabilityFeeCollector.sol +++ b/contracts/main/stablecoin-core/StabilityFeeCollector.sol @@ -27,6 +27,7 @@ contract StabilityFeeCollector is CommonMath, PausableUpgradeable, ReentrancyGua address public systemDebtEngine; event LogSetSystemDebtEngine(address indexed _caller, address _data); + event LogNewDebtAccumulatedRate(uint256 _newDebtAccumulatedRate); modifier onlyOwner() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig()); @@ -79,6 +80,7 @@ contract StabilityFeeCollector is CommonMath, PausableUpgradeable, ReentrancyGua /// @return _debtAccumulatedRate Updated debtAccumulatedRate for the specified collateral pool. function collect(bytes32 _collateralPool) external override whenNotPaused nonReentrant returns (uint256 _debtAccumulatedRate) { _debtAccumulatedRate = _collect(_collateralPool); + emit LogNewDebtAccumulatedRate(_debtAccumulatedRate); } /// @dev Internal function to collect the stability fee of the specified collateral pool. diff --git a/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol b/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol index 36d2b4aa..2c45919a 100644 --- a/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol +++ b/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol @@ -41,7 +41,8 @@ contract CollateralTokenAdapter is CommonMath, ICollateralAdapter, PausableUpgra event LogDeposit(uint256 _val); event LogWithdraw(uint256 _val); - event LogWhitelisted(address indexed _user, bool _isWhitelisted); + event LogAddToWhitelist(address indexed _user); + event LogRemoveFromWhitelist(address indexed _user); event LogEmergencyWithdraw(address indexed _caller, address _to); modifier onlyOwner() { @@ -89,7 +90,7 @@ contract CollateralTokenAdapter is CommonMath, ICollateralAdapter, PausableUpgra function addToWhitelist(address _toBeWhitelisted) external onlyOwnerOrGov { require(_toBeWhitelisted != address(0), "CollateralTokenAdapter/whitelist-invalidAdds"); whiteListed[_toBeWhitelisted] = true; - emit LogWhitelisted(_toBeWhitelisted, true); + emit LogAddToWhitelist(_toBeWhitelisted); } /// @notice Removes an address from the whitelist @@ -98,7 +99,7 @@ contract CollateralTokenAdapter is CommonMath, ICollateralAdapter, PausableUpgra function removeFromWhitelist(address _toBeRemoved) external onlyOwnerOrGov { require(_toBeRemoved != address(0), "CollateralTokenAdapter/removeFromWL-invalidAdds"); whiteListed[_toBeRemoved] = false; - emit LogWhitelisted(_toBeRemoved, false); + emit LogRemoveFromWhitelist(_toBeRemoved); } /// @dev The `cage` function permanently halts the `collateralTokenAdapter` contract. diff --git a/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol b/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol index 0c3f6f42..5e95d1c5 100644 --- a/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol +++ b/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol @@ -72,6 +72,7 @@ contract FixedSpreadLiquidationStrategy is CommonMath, PausableUpgradeable, Reen uint256 _treasuryFees ); event LogSetFlashLendingEnabled(address indexed _caller, uint256 _flashLendingEnabled); + event LogSetBookKeeper(address indexed _newAddress); modifier onlyOwnerOrGov() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig()); @@ -256,6 +257,7 @@ contract FixedSpreadLiquidationStrategy is CommonMath, PausableUpgradeable, Reen function setBookKeeper(address _bookKeeper) external onlyOwner { require(IBookKeeper(_bookKeeper).totalStablecoinIssued() >= 0, "FixedSpreadLiquidationStrategy/invalid-bookKeeper"); // Sanity Check Call bookKeeper = IBookKeeper(_bookKeeper); + emit LogSetBookKeeper(_bookKeeper); } function setLiquidationEngine(address _liquidationEngine) external onlyOwner { diff --git a/contracts/tests/mocks/MockCollateralTokenAdapter.sol b/contracts/tests/mocks/MockCollateralTokenAdapter.sol index 5685d513..688ca95f 100644 --- a/contracts/tests/mocks/MockCollateralTokenAdapter.sol +++ b/contracts/tests/mocks/MockCollateralTokenAdapter.sol @@ -88,6 +88,8 @@ contract MockCollateralTokenAdapter is MockCollateralTokenAdapterMath, ICollater event LogDeposit(uint256 _val); event LogWithdraw(uint256 _val); event LogEmergencyWithdraw(address indexed _caller, address _to); + event LogAddToWhitelist(address indexed _user); + event LogRemoveFromWhitelist(address indexed _user); modifier onlyOwner() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig()); @@ -135,11 +137,13 @@ contract MockCollateralTokenAdapter is MockCollateralTokenAdapterMath, ICollater function addToWhitelist(address _toBeWhitelisted) external onlyOwnerOrGov { require(_toBeWhitelisted != address(0), "AnkrColadapter/whitelist-invalidAdds"); whiteListed[_toBeWhitelisted] = true; + emit LogAddToWhitelist(_toBeWhitelisted); } function removeFromWhitelist(address _toBeRemoved) external onlyOwnerOrGov { require(_toBeRemoved != address(0), "CollateralTokenAdapter/removeFromWL-invalidAdds"); whiteListed[_toBeRemoved] = false; + emit LogRemoveFromWhitelist(_toBeRemoved); } /// @dev Cage function halts MockCollateralTokenAdapter contract for good. From 73d263de852593fb03947550e8c7041221edee2e Mon Sep 17 00:00:00 2001 From: codinghistorian Date: Thu, 21 Dec 2023 13:44:02 +0400 Subject: [PATCH 4/6] FXD-72 '23 Dec 21 remove deprecated storage slots --- contracts/main/stablecoin-core/LiquidationEngine.sol | 2 -- .../CollateralTokenAdapter/CollateralTokenAdapter.sol | 5 ----- contracts/tests/mocks/MockCollateralTokenAdapter.sol | 3 --- 3 files changed, 10 deletions(-) diff --git a/contracts/main/stablecoin-core/LiquidationEngine.sol b/contracts/main/stablecoin-core/LiquidationEngine.sol index 6b96c022..beaccc8e 100644 --- a/contracts/main/stablecoin-core/LiquidationEngine.sol +++ b/contracts/main/stablecoin-core/LiquidationEngine.sol @@ -38,8 +38,6 @@ contract LiquidationEngine is PausableUpgradeable, ReentrancyGuardUpgradeable, I // --- Math --- uint256 internal constant WAD = 10 ** 18; - bytes32 internal deprecated; - IBookKeeper public bookKeeper; // CDP Engine ISystemDebtEngine public systemDebtEngine; // Debt Engine uint256 public override live; // Active Flag diff --git a/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol b/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol index 2c45919a..0f408abb 100644 --- a/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol +++ b/contracts/main/stablecoin-core/adapters/CollateralTokenAdapter/CollateralTokenAdapter.sol @@ -27,16 +27,11 @@ contract CollateralTokenAdapter is CommonMath, ICollateralAdapter, PausableUpgra IVault public vault; - /// @dev deprecated but needs to be kept to minimize storage layout confusion - bytes32 internal deprecated2; IProxyRegistry public proxyWalletFactory; /// @dev Total CollateralTokens that has been staked in WAD uint256 public totalShare; - /// @dev deprecated but needs to be kept to minimize storage layout confusion - bytes32 internal deprecated; - mapping(address => bool) public whiteListed; event LogDeposit(uint256 _val); diff --git a/contracts/tests/mocks/MockCollateralTokenAdapter.sol b/contracts/tests/mocks/MockCollateralTokenAdapter.sol index 688ca95f..da478144 100644 --- a/contracts/tests/mocks/MockCollateralTokenAdapter.sol +++ b/contracts/tests/mocks/MockCollateralTokenAdapter.sol @@ -80,9 +80,6 @@ contract MockCollateralTokenAdapter is MockCollateralTokenAdapterMath, ICollater /// @dev Total CollateralTokens that has been staked in WAD uint256 public totalShare; - /// @dev deprecated but needs to be kept to minimize storage layout confusion - bytes32 deprecated; - mapping(address => bool) public whiteListed; event LogDeposit(uint256 _val); From a1b35a528f50e89183758a402df9df4344784cdc Mon Sep 17 00:00:00 2001 From: codinghistorian Date: Thu, 21 Dec 2023 14:11:39 +0400 Subject: [PATCH 5/6] FXD-72 '23 Dec 21 clean comments on test script --- scripts/tests/integration/CollateralTokenAdapter.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/tests/integration/CollateralTokenAdapter.test.js b/scripts/tests/integration/CollateralTokenAdapter.test.js index 85e45f5f..ee2dbcd7 100644 --- a/scripts/tests/integration/CollateralTokenAdapter.test.js +++ b/scripts/tests/integration/CollateralTokenAdapter.test.js @@ -158,7 +158,6 @@ describe("CollateralTokenAdapter", () => { expect(await collateralTokenAdapter.totalShare()).to.be.eq(ethers.utils.parseEther("1")) - // expect(await bookKeeper.collateralToken(COLLATERAL_POOL_ID, AliceAddress).to.be.eq(ethers.utils.parseEther("1"))) expect(await bookKeeper.collateralToken(collateralPoolIdFromAdapter, AliceAddress)).to.be.eq(ethers.utils.parseEther("1")) @@ -177,7 +176,6 @@ describe("CollateralTokenAdapter", () => { expect(await collateralTokenAdapter.totalShare()).to.be.eq(ethers.utils.parseEther("5")) expect(await bookKeeper.collateralToken(collateralPoolIdFromAdapter, AliceAddress)).to.be.eq(ethers.utils.parseEther("1")) - // expect(await bookKeeper.collateralToken(COLLATERAL_POOL_ID, BobAddress).to.be.eq(ethers.utils.parseEther("4"))) expect(await bookKeeper.collateralToken(collateralPoolIdFromAdapter, BobAddress)).to.be.eq(ethers.utils.parseEther("4")) From 8bf900b0c670a28d1b88ae5b13ea9db3c80ed316 Mon Sep 17 00:00:00 2001 From: codinghistorian Date: Thu, 21 Dec 2023 16:22:51 +0400 Subject: [PATCH 6/6] FXD-72 '23 Dec 21 clean indexed event param changes 0)no need to index core smart contract addresses that are switched as the number will not be a lot and no need to search for. 1)adding indexed keywords to LogProxyWalletCreation event since owner and proxy wallet information is important. --- .../main/proxy-wallet/ProxyWalletRegistry.sol | 2 +- contracts/main/stablecoin-core/AdminControls.sol | 14 +++++++------- .../main/stablecoin-core/LiquidationEngine.sol | 2 +- contracts/main/stablecoin-core/PriceOracle.sol | 2 +- .../FixedSpreadLiquidationStrategy.sol | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/contracts/main/proxy-wallet/ProxyWalletRegistry.sol b/contracts/main/proxy-wallet/ProxyWalletRegistry.sol index 76c7b32b..3a52bef9 100644 --- a/contracts/main/proxy-wallet/ProxyWalletRegistry.sol +++ b/contracts/main/proxy-wallet/ProxyWalletRegistry.sol @@ -18,7 +18,7 @@ contract ProxyWalletRegistry is PausableUpgradeable, IPausable { event LogAddToWhitelist(address indexed _user); event LogRemoveFromWhitelist(address indexed _user); event LogSetDecentralizedMode(bool _newValue); - event LogProxyWalletCreation(address _owner, address _proxyWallet); + event LogProxyWalletCreation(address indexed _owner, address indexed _proxyWallet); modifier onlyOwnerOrGov() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig()); diff --git a/contracts/main/stablecoin-core/AdminControls.sol b/contracts/main/stablecoin-core/AdminControls.sol index 9ed9c14a..a4695563 100644 --- a/contracts/main/stablecoin-core/AdminControls.sol +++ b/contracts/main/stablecoin-core/AdminControls.sol @@ -20,13 +20,13 @@ contract AdminControls is Initializable { event LogPauseProtocol(); event LogUnpauseProtocol(); - event LogSetBookKeeper(address indexed _newAddress); - event LogSetPositionManager(address indexed _newAddress); - event LogSetLiquidationEngine(address indexed _newAddress); - event LogSetSystemDebtEngine(address indexed _newAddress); - event LogSetFlashMintModule(address indexed _newAddress); - event LogSetPriceOracle(address indexed _newAddress); - event LogSetStablecoinAdapter(address indexed _newAddress); + event LogSetBookKeeper(address _newAddress); + event LogSetPositionManager(address _newAddress); + event LogSetLiquidationEngine(address _newAddress); + event LogSetSystemDebtEngine(address _newAddress); + event LogSetFlashMintModule(address _newAddress); + event LogSetPriceOracle(address _newAddress); + event LogSetStablecoinAdapter(address _newAddress); modifier onlyOwnerOrGov() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(IBookKeeper(bookKeeper).accessControlConfig()); diff --git a/contracts/main/stablecoin-core/LiquidationEngine.sol b/contracts/main/stablecoin-core/LiquidationEngine.sol index beaccc8e..ebcda7a0 100644 --- a/contracts/main/stablecoin-core/LiquidationEngine.sol +++ b/contracts/main/stablecoin-core/LiquidationEngine.sol @@ -44,7 +44,7 @@ contract LiquidationEngine is PausableUpgradeable, ReentrancyGuardUpgradeable, I mapping(address => bool) public liquidatorsWhitelist; event LiquidationFail(bytes32 _collateralPoolIds, address _positionAddresses, address _liquidator, string reason); - event LogSetBookKeeper(address indexed _newAddress); + event LogSetBookKeeper(address _newAddress); event LogAddToWhitelist(address indexed _user); event LogRemoveFromWhitelist(address indexed _user); diff --git a/contracts/main/stablecoin-core/PriceOracle.sol b/contracts/main/stablecoin-core/PriceOracle.sol index 2996be3c..35b44e32 100644 --- a/contracts/main/stablecoin-core/PriceOracle.sol +++ b/contracts/main/stablecoin-core/PriceOracle.sol @@ -39,7 +39,7 @@ contract PriceOracle is CommonMath, PausableUpgradeable, IPriceOracle, ICagable, ); event LogSetStableCoinReferencePrice(address indexed _caller, uint256 _data); - event LogSetBookKeeper(address indexed _newAddress); + event LogSetBookKeeper(address _newAddress); modifier onlyOwner() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig()); diff --git a/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol b/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol index 5e95d1c5..7fbec6ea 100644 --- a/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol +++ b/contracts/main/stablecoin-core/liquidation-strategies/FixedSpreadLiquidationStrategy.sol @@ -72,7 +72,7 @@ contract FixedSpreadLiquidationStrategy is CommonMath, PausableUpgradeable, Reen uint256 _treasuryFees ); event LogSetFlashLendingEnabled(address indexed _caller, uint256 _flashLendingEnabled); - event LogSetBookKeeper(address indexed _newAddress); + event LogSetBookKeeper(address _newAddress); modifier onlyOwnerOrGov() { IAccessControlConfig _accessControlConfig = IAccessControlConfig(bookKeeper.accessControlConfig());