From 1e31677bd3bfb7e8b3b4ecc5f4922d9fecb22e1d Mon Sep 17 00:00:00 2001 From: Patrick Kim Date: Thu, 3 Aug 2023 12:33:26 -0400 Subject: [PATCH] refactor: move events --- src/Blue.sol | 37 ++++++++++++----------- src/interfaces/IBlue.sol | 57 ++++++++++++++++++++++++++++++++++++ src/libraries/Events.sol | 63 ---------------------------------------- 3 files changed, 75 insertions(+), 82 deletions(-) delete mode 100644 src/libraries/Events.sol diff --git a/src/Blue.sol b/src/Blue.sol index 31291ab20..7c8237969 100644 --- a/src/Blue.sol +++ b/src/Blue.sol @@ -13,7 +13,6 @@ import {IERC20} from "./interfaces/IERC20.sol"; import {IOracle} from "./interfaces/IOracle.sol"; import {Id, Market, Signature, IBlue} from "./interfaces/IBlue.sol"; -import {Events} from "./libraries/Events.sol"; import {Errors} from "./libraries/Errors.sol"; import {SharesMath} from "./libraries/SharesMath.sol"; import {FixedPointMathLib} from "./libraries/FixedPointMathLib.sol"; @@ -93,20 +92,20 @@ contract Blue is IBlue { function setOwner(address newOwner) external onlyOwner { owner = newOwner; - emit Events.SetOwner(newOwner); + emit SetOwner(newOwner); } function enableIrm(address irm) external onlyOwner { isIrmEnabled[irm] = true; - emit Events.EnableIrm(address(irm)); + emit EnableIrm(address(irm)); } function enableLltv(uint256 lltv) external onlyOwner { require(lltv < FixedPointMathLib.WAD, Errors.LLTV_TOO_HIGH); isLltvEnabled[lltv] = true; - emit Events.EnableLltv(lltv); + emit EnableLltv(lltv); } /// @notice It is the owner's responsibility to ensure a fee recipient is set before setting a non-zero fee. @@ -116,13 +115,13 @@ contract Blue is IBlue { require(newFee <= MAX_FEE, Errors.MAX_FEE_EXCEEDED); fee[id] = newFee; - emit Events.SetFee(id, newFee); + emit SetFee(id, newFee); } function setFeeRecipient(address recipient) external onlyOwner { feeRecipient = recipient; - emit Events.SetFeeRecipient(recipient); + emit SetFeeRecipient(recipient); } // Markets management. @@ -133,7 +132,7 @@ contract Blue is IBlue { require(isLltvEnabled[market.lltv], Errors.LLTV_NOT_ENABLED); require(lastUpdate[id] == 0, Errors.MARKET_CREATED); - emit Events.CreateMarket(id, market); + emit CreateMarket(id, market); _accrueInterests(market, id); } @@ -154,7 +153,7 @@ contract Blue is IBlue { totalSupply[id] += amount; - emit Events.Supply(id, msg.sender, onBehalf, amount, shares); + emit Supply(id, msg.sender, onBehalf, amount, shares); if (data.length > 0) IBlueSupplyCallback(msg.sender).onBlueSupply(amount, data); @@ -177,7 +176,7 @@ contract Blue is IBlue { totalSupply[id] -= amount; - emit Events.Withdraw(id, msg.sender, onBehalf, receiver, amount, shares); + emit Withdraw(id, msg.sender, onBehalf, receiver, amount, shares); require(totalBorrow[id] <= totalSupply[id], Errors.INSUFFICIENT_LIQUIDITY); @@ -202,7 +201,7 @@ contract Blue is IBlue { totalBorrow[id] += amount; - emit Events.Borrow(id, msg.sender, onBehalf, receiver, amount, shares); + emit Borrow(id, msg.sender, onBehalf, receiver, amount, shares); require(_isHealthy(market, id, onBehalf), Errors.INSUFFICIENT_COLLATERAL); require(totalBorrow[id] <= totalSupply[id], Errors.INSUFFICIENT_LIQUIDITY); @@ -224,7 +223,7 @@ contract Blue is IBlue { totalBorrow[id] -= amount; - emit Events.Repay(id, msg.sender, onBehalf, amount, shares); + emit Repay(id, msg.sender, onBehalf, amount, shares); if (data.length > 0) IBlueRepayCallback(msg.sender).onBlueRepay(amount, data); @@ -244,7 +243,7 @@ contract Blue is IBlue { collateral[id][onBehalf] += amount; - emit Events.SupplyCollateral(id, msg.sender, onBehalf, amount); + emit SupplyCollateral(id, msg.sender, onBehalf, amount); if (data.length > 0) IBlueSupplyCollateralCallback(msg.sender).onBlueSupplyCollateral(amount, data); @@ -263,7 +262,7 @@ contract Blue is IBlue { collateral[id][onBehalf] -= amount; - emit Events.WithdrawCollateral(id, msg.sender, onBehalf, receiver, amount); + emit WithdrawCollateral(id, msg.sender, onBehalf, receiver, amount); require(_isHealthy(market, id, onBehalf), Errors.INSUFFICIENT_COLLATERAL); @@ -309,7 +308,7 @@ contract Blue is IBlue { IERC20(market.collateralAsset).safeTransfer(msg.sender, seized); - emit Events.Liquidate(id, msg.sender, borrower, repaid, repaidShares, seized, badDebtShares); + emit Liquidate(id, msg.sender, borrower, repaid, repaidShares, seized, badDebtShares); if (data.length > 0) IBlueLiquidateCallback(msg.sender).onBlueLiquidate(seized, repaid, data); @@ -321,7 +320,7 @@ contract Blue is IBlue { function flashLoan(address token, uint256 amount, bytes calldata data) external { IERC20(token).safeTransfer(msg.sender, amount); - emit Events.FlashLoan(msg.sender, token, amount); + emit FlashLoan(msg.sender, token, amount); IBlueFlashLoanCallback(msg.sender).onBlueFlashLoan(token, amount, data); @@ -348,17 +347,17 @@ contract Blue is IBlue { require(signatory != address(0) && authorizer == signatory, Errors.INVALID_SIGNATURE); - emit Events.IncrementNonce(msg.sender, authorizer, usedNonce); + emit IncrementNonce(msg.sender, authorizer, usedNonce); isAuthorized[authorizer][authorized] = newIsAuthorized; - emit Events.SetAuthorization(msg.sender, authorizer, authorized, newIsAuthorized); + emit SetAuthorization(msg.sender, authorizer, authorized, newIsAuthorized); } function setAuthorization(address authorized, bool newIsAuthorized) external { isAuthorized[msg.sender][authorized] = newIsAuthorized; - emit Events.SetAuthorization(msg.sender, msg.sender, authorized, newIsAuthorized); + emit SetAuthorization(msg.sender, msg.sender, authorized, newIsAuthorized); } function _isSenderAuthorized(address user) internal view returns (bool) { @@ -389,7 +388,7 @@ contract Blue is IBlue { totalSupplyShares[id] += feeShares; } - emit Events.AccrueInterests(id, borrowRate, accruedInterests, feeShares); + emit AccrueInterests(id, borrowRate, accruedInterests, feeShares); } lastUpdate[id] = block.timestamp; diff --git a/src/interfaces/IBlue.sol b/src/interfaces/IBlue.sol index 3c5800658..6ad39e8dd 100644 --- a/src/interfaces/IBlue.sol +++ b/src/interfaces/IBlue.sol @@ -22,6 +22,63 @@ struct Signature { } interface IBlue is IFlashLender { + event SupplyCollateral(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount); + event WithdrawCollateral( + Id indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 amount + ); + + event Supply(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount, uint256 shares); + event Withdraw( + Id indexed id, + address caller, + address indexed onBehalf, + address indexed receiver, + uint256 amount, + uint256 shares + ); + + event Borrow( + Id indexed id, + address caller, + address indexed onBehalf, + address indexed receiver, + uint256 amount, + uint256 shares + ); + event Repay(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount, uint256 shares); + + event Liquidate( + Id indexed id, + address indexed caller, + address indexed borrower, + uint256 repaid, + uint256 repaidShares, + uint256 seized, + uint256 badDebtShares + ); + + event FlashLoan(address indexed caller, address indexed token, uint256 amount); + + event SetOwner(address indexed newOwner); + + event SetFee(Id indexed id, uint256 fee); + + event SetFeeRecipient(address indexed feeRecipient); + + event CreateMarket(Id indexed id, Market market); + + event SetAuthorization( + address indexed caller, address indexed authorizer, address indexed authorized, bool isAuthorized + ); + + event IncrementNonce(address indexed caller, address indexed signatory, uint256 usedNonce); + + event EnableIrm(address indexed irm); + + event EnableLltv(uint256 lltv); + + event AccrueInterests(Id indexed id, uint256 borrowRate, uint256 accruedInterests, uint256 feeShares); + function DOMAIN_SEPARATOR() external view returns (bytes32); function owner() external view returns (address); diff --git a/src/libraries/Events.sol b/src/libraries/Events.sol deleted file mode 100644 index 8c078af00..000000000 --- a/src/libraries/Events.sol +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.0; - -import {Id, Market} from "src/libraries/MarketLib.sol"; - -library Events { - event SupplyCollateral(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount); - event WithdrawCollateral( - Id indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 amount - ); - - event Supply(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount, uint256 shares); - event Withdraw( - Id indexed id, - address caller, - address indexed onBehalf, - address indexed receiver, - uint256 amount, - uint256 shares - ); - - event Borrow( - Id indexed id, - address caller, - address indexed onBehalf, - address indexed receiver, - uint256 amount, - uint256 shares - ); - event Repay(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount, uint256 shares); - - event Liquidate( - Id indexed id, - address indexed caller, - address indexed borrower, - uint256 repaid, - uint256 repaidShares, - uint256 seized, - uint256 badDebtShares - ); - - event FlashLoan(address indexed caller, address indexed token, uint256 amount); - - event SetOwner(address indexed newOwner); - - event SetFee(Id indexed id, uint256 fee); - - event SetFeeRecipient(address indexed feeRecipient); - - event CreateMarket(Id indexed id, Market market); - - event SetAuthorization( - address indexed caller, address indexed authorizer, address indexed authorized, bool isAuthorized - ); - - event IncrementNonce(address indexed caller, address indexed signatory, uint256 usedNonce); - - event EnableIrm(address indexed irm); - - event EnableLltv(uint256 lltv); - - event AccrueInterests(Id indexed id, uint256 borrowRate, uint256 accruedInterests, uint256 feeShares); -}