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: move events #220

Merged
merged 2 commits into from
Aug 7, 2023
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
37 changes: 18 additions & 19 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -134,7 +133,7 @@ contract Blue is IBlue {
require(lastUpdate[id] == 0, Errors.MARKET_CREATED);
lastUpdate[id] = block.timestamp;

emit Events.CreateMarket(id, market);
emit CreateMarket(id, market);
}

// Supply management.
Expand All @@ -153,7 +152,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);

Expand All @@ -176,7 +175,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);

Expand All @@ -201,7 +200,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);
Expand All @@ -223,7 +222,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);

Expand All @@ -243,7 +242,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);

Expand All @@ -262,7 +261,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);

Expand Down Expand Up @@ -308,7 +307,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);

Expand All @@ -320,7 +319,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);

Expand All @@ -347,17 +346,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) {
Expand Down Expand Up @@ -388,7 +387,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;
Expand Down
57 changes: 57 additions & 0 deletions src/interfaces/IBlue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 0 additions & 63 deletions src/libraries/Events.sol

This file was deleted.