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

fix l5 #220

Merged
merged 1 commit into from
Dec 18, 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
2 changes: 2 additions & 0 deletions src/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ contract Manager is IManager, Ownable {
tkn.approve(vault, 1);
IVault(vault).deposit(1, address(this));

emit VaultCreated(token, vault);

return vault;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ contract Vault is IVault, ERC4626, ERC20Permit {
latestRepay = block.timestamp;
feeUnlockTime = _feeUnlockTime;

emit DegradationCoefficientWasUpdated(feeUnlockTime);
emit FeeUnlockTimeWasUpdated(feeUnlockTime);
}

function sweep(address to, address token) external onlyOwner {
assert(token != asset());

IERC20 spuriousToken = IERC20(token);
spuriousToken.safeTransfer(to, spuriousToken.balanceOf(address(this)));
uint256 amount = spuriousToken.balanceOf(address(this));
spuriousToken.safeTransfer(to, amount);

emit TokenSwept(to, token, amount);
}

function getFeeStatus() external view override returns (uint256, uint256, uint256, uint256) {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/IManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface IManager {
event SpreadWasUpdated(address indexed service, address indexed token, uint256 spread);
event CapWasUpdated(address indexed service, address indexed token, uint256 percentageCap, uint256 absoluteCap);
event TokenWasRemovedFromService(address indexed service, address indexed token);
event VaultCreated(address indexed token, address indexed vault);

error VaultAlreadyExists();
error VaultMissing();
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ interface IVault is IERC4626 {
function isLocked() external view returns (bool);

// Events
event DegradationCoefficientWasUpdated(uint256 degradationCoefficient);
event Borrowed(address indexed receiver, uint256 assets);
event Repaid(address indexed repayer, uint256 amount, uint256 debt);
event LockToggled(bool isLocked);
event FeeUnlockTimeWasUpdated(uint256 feeUnlockTime);
event TokenSwept(address indexed to, address indexed token, uint256 amount);

error InsufficientLiquidity();
error InsufficientFreeLiquidity();
Expand Down
13 changes: 8 additions & 5 deletions src/irmodels/AuctionRateModel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import { BaseRiskModel } from "../services/BaseRiskModel.sol";
/// Rate model in which baseIR is based on a Dutch auction
/// 1e18 corresponds to 1, i.e. an interest rate of 100%
abstract contract AuctionRateModel is Ownable, BaseRiskModel {
error InvalidInitParams();
error InterestRateOverflow();
error AboveRiskThreshold();
error ZeroMarginLoan();

/**
* @dev gas saving trick
* latest is a timestamp and base < 1e18, they all fit in uint256
Expand All @@ -24,11 +19,19 @@ abstract contract AuctionRateModel is Ownable, BaseRiskModel {
mapping(address => uint256) public riskSpreads;
mapping(address => uint256) public latestAndBase;

event RiskParamsUpdated(address indexed token, uint256 riskSpread, uint256 baseRate, uint256 halfTime);
error InvalidInitParams();
error InterestRateOverflow();
error AboveRiskThreshold();
error ZeroMarginLoan();

function setRiskParams(address token, uint256 riskSpread, uint256 baseRate, uint256 halfTime) external onlyOwner {
if (token == address(0) || baseRate > 1e18 || riskSpread > 1e18 || halfTime == 0) revert InvalidInitParams();
riskSpreads[token] = riskSpread;
latestAndBase[token] = (block.timestamp << 128) + baseRate;
halvingTime[token] = halfTime;

emit RiskParamsUpdated(token, riskSpread, baseRate, halfTime);
}

/// @dev Defaults to riskSpread = baseRiskSpread * amount / margin
Expand Down
6 changes: 6 additions & 0 deletions src/services/DebitService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ abstract contract DebitService is Service, BaseRiskModel {
address public liquidator;

event LiquidationTriggered(uint256 indexed id, address token, address indexed liquidator, uint256 payoff);
event MinMarginUpdated(address indexed token, uint256 margin);
event LiquidatorUpdated(address indexed liquidator);

error MarginTooLow();
error OnlyLiquidator();
error LossByArbitraryAddress();

function setMinMargin(address token, uint256 margin) external onlyOwner {
minMargin[token] = margin;

emit MinMarginUpdated(token, margin);
}

function setLiquidator(address _liquidator) external onlyOwner {
liquidator = _liquidator;

emit LiquidatorUpdated(_liquidator);
}

/// @dev Defaults to amount + margin * (ir + riskSpread) / 1e18
Expand Down
7 changes: 7 additions & 0 deletions src/services/credit/CallOption.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ contract CallOption is CreditService {
uint64[] internal _rewards;
address internal immutable _vaultAddress;

event IthilTokenAllocated(uint256 amount);
event IthilTokenSwept(uint256 amount);

error ZeroAmount();
error LockPeriodStillActive();
error MaxLockExceeded();
Expand Down Expand Up @@ -231,6 +234,8 @@ contract CallOption is CreditService {
function allocateIthil(uint256 amount) external {
totalAllocation += amount;
ithil.safeTransferFrom(msg.sender, address(this), amount);

emit IthilTokenAllocated(amount);
}

function sweepIthil() external onlyOwner {
Expand All @@ -239,5 +244,7 @@ contract CallOption is CreditService {
uint256 initialAllocation = totalAllocation;
totalAllocation = 0;
ithil.safeTransfer(msg.sender, initialAllocation);

emit IthilTokenSwept(initialAllocation);
}
}
Loading