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

Improvement/aura fed to base fed #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
43 changes: 40 additions & 3 deletions src/BaseFed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ abstract contract BaseFed {
address public pendingGov;
//Chair address allowed to perform expansions and contractions
address public chair;
//Address of contract that is allowed to call the migrate functions
address public migrator;

constructor(address _DOLA, address _gov, address _chair){
require(gov != address(0), "Gov set to 0");
require(_gov != address(0), "Gov set to 0");
require(_DOLA != address(0), "Must be correct DOLA address");
require(block.chainid == 1, "Must mint DOLA on Mainnet");
gov = _gov;
chair = _chair;
DOLA = IERC20(_DOLA);
Expand All @@ -38,6 +39,11 @@ abstract contract BaseFed {
_;
}

modifier onlyMigrator(){
require(msg.sender == migrator, "ONLY MIGRATOR");
_;
}

/**
* @notice Sets the pendingGov, which can claim gov role.
* @dev Only callable by gov
Expand Down Expand Up @@ -67,6 +73,15 @@ abstract contract BaseFed {
emit NewChair(newChair);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small observation: Most role update functions have events except for ResignChair and SetMigrator.

}

/**
* @notice Sets the migrator of the Fed
* @dev Should only be set if it's desired to migrate claims and debts to another fed
* @param newMigrator Address of the contract to migrate to
*/
function setMigrator(address newMigrator) onlyGov external {
migrator = newMigrator;
}

/**
* @notice Resigns from the Fed role
* @dev Useful in case of key compromise or multi-sig compromise
Expand Down Expand Up @@ -128,14 +143,36 @@ abstract contract BaseFed {
function takeProfit(uint flag) external virtual;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion. Can try a pattern like this which enforces events are always implemented without relying on developer to remember.

function takeProfit(uint flag) external {
    (address token, uint amount) = _takeProfit(flag);
    Profit(token, amount);
}

function _takeProfit() external virtual returns(address token, uint amount);


/**
* @notice Function for withdrawing underlying of Fed in emergency.
* @notice Withdraws claims from Fed in case of an emergency.
Can be useful in case of Fed accounting errors, hacks of underlying market or accidents.
* @dev Will likely destroy all contract accounting. Use carefully. Should send withdrawn tokens to gov.
*/
function emergencyWithdraw() onlyGov external virtual{
revert("NOT IMPLEMENTED");
}

/**
* @notice Migrates both claims and debt to another fed from this one
* @dev Must send claims tokens to the new fed. This can be LP tokens, cTokens etc.
* @dev Must make sure accounting is correct, with the total number of claims and debt between feds staying the same after migration
* @param claimsToMigrate The number of claims to migrate to the other fed
* @return debtToMigrate The debt associated with the transfered claims
*/
function migrateTo(uint claimsToMigrate) onlyMigrator external virtual returns(uint debtToMigrate){
revert("NOT IMPLEMENTED");
}

/**
* @notice Migrates both claims and debt from another fed to this one
* @dev Must call the migraTo function of the target fed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

* @dev Must increment both claims and debt
* @param fed The address of the fed to migrate from
* @param claimsToMigrate The amount of claims to migrate from the target fed
*/
function migrateFrom(address fed, uint claimsToMigrate) onlyChair external virtual {
revert("NOT IMPLEMENTED");
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweep function below won't hand non-compliant tokens like USDT which have a non-standard interface.

// **********************
// * Standard Functions *
// **********************
Expand Down
64 changes: 64 additions & 0 deletions src/LossyFed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
pragma solidity ^0.8.13;

import "src/MintingFed.sol";

abstract contract LossyFed is MintingFed {
uint public maxLossExpansionBps;
uint public maxLossContractionBps;
uint public maxLossTakeProfitBps;
uint public maxLossSetableByGuardian = 500;
address public guardian;
constructor(address _DOLA,
address _gov,
address _chair,
address _guardian,
uint _maxLossExpansionBps,
uint _maxLossContractionBps,
uint _maxLossTakeProfitBps
) MintingFed(_DOLA, _gov, _chair)
{
require(_maxLossExpansionBps < 10000, "Expansion max loss too high");
require(_maxLossContractionBps < 10000, "Contraction max loss too high");
require(_maxLossTakeProfitBps < 10000, "TakeProfit max loss too high");
guardian = _guardian;
maxLossExpansionBps = _maxLossExpansionBps;
maxLossContractionBps = _maxLossContractionBps;
maxLossTakeProfitBps = _maxLossTakeProfitBps;
}

modifier onlyGuardian {
require(msg.sender == guardian || msg.sender == gov, "ONLY GOV OR GUARDIAN");
_;
}

function setMaxLossExpansionBps(uint newMaxLossExpansionBps) onlyGov external {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating max loss on Expansions and TakeProfit are gov only, but Contractions can be guardian as well. Is the difference due to one being more sensitive than the other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, idea is that an emergency contraction may need to happen in short order, due to a hack of an underlying protocol. We saw that play out during the Euler hack, where fast contractions were instrumental in avoiding as much bad debt as possible.

require(newMaxLossExpansionBps <= 10000, "Max loss above 100%");
maxLossExpansionBps = newMaxLossExpansionBps;
}

function setMaxLossContractionBps(uint newMaxLossContractionBps) onlyGuardian external{
if(msg.sender == guardian){
//We limit the max loss a guardian can set, as we only want governance to be able to set a very high maxloss
require(newMaxLossContractionBps <= maxLossSetableByGuardian, "Above allowed maxloss for chair");
}
require(newMaxLossContractionBps <= 10000, "Max loss above 100%");
maxLossContractionBps = newMaxLossContractionBps;
}

function setMaxLossTakeProfitBps(uint newMaxLossTakeProfitBps) onlyGov external {
require(newMaxLossTakeProfitBps <= 10000, "Max loss above 100%");
maxLossTakeProfitBps = newMaxLossTakeProfitBps;
}

function setMaxLossSetableByGuardian(uint newMaxLossSetableByGuardian) onlyGov external {
require(newMaxLossSetableByGuardian < 10000, "Max loss above 100%");
maxLossSetableByGuardian = newMaxLossSetableByGuardian;
}

function setGuardian(address newGuardian) onlyGov external {
guardian = newGuardian;
emit NewGuardian(newGuardian);
}

event NewGuardian(address);
}
19 changes: 17 additions & 2 deletions src/MintingFed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ abstract contract MintingFed is BaseFed{
*/
function takeProfit(uint flag) override external virtual;

/**
* @notice Function for calculating actual supply of claims, which may differ from the claims variable for a variety of reasons.
* @return claims The number of claims the address owns.
*/
function claimsSupply() public view virtual returns(uint claims);


/**
* @notice Function for withdrawing underlying of Fed in emergency.
Can be useful in case of Fed accounting errors, hacks of underlying market or accidents.
Expand Down Expand Up @@ -103,7 +110,11 @@ abstract contract MintingFed is BaseFed{
*/
function contraction(uint amount) onlyChair override external {
(uint claimsUsed, uint dolaReceived) = _withdraw(amount);
claims -= claimsUsed;
if(claimsUsed > claims){
claims = 0;
} else {
claims -= claimsUsed;
}
_repayDebt(dolaReceived);
}

Expand All @@ -113,7 +124,11 @@ abstract contract MintingFed is BaseFed{
*/
function contractAll() onlyChair override external {
(uint claimsUsed, uint dolaReceived) = _withdrawAll();
claims -= claimsUsed;
if(claimsUsed > claims){
claims = 0;
} else {
claims -= claimsUsed;
}
_repayDebt(dolaReceived);
}
}
Loading