Skip to content

Commit

Permalink
Merge pull request #265 from morpho-dao/feat/claim-to-treasury
Browse files Browse the repository at this point in the history
Add claim to treasury function
  • Loading branch information
MerlinEgalite authored Jan 20, 2023
2 parents 58c106e + 0598aed commit 323ff2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/MorphoInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ abstract contract MorphoInternal is MorphoStorage {
emit Events.MarketCreated(underlying, reserveFactor, p2pIndexCursor);
}

function _claimToTreasury(address[] calldata underlyings, uint256[] calldata amounts) internal {
address treasuryVault = _treasuryVault;
if (treasuryVault == address(0)) revert Errors.AddressIsZero();

for (uint256 i; i < underlyings.length; ++i) {
address underlying = underlyings[i];

if (!_market[underlying].isCreated()) continue;

uint256 underlyingBalance = ERC20(underlying).balanceOf(address(this));

if (underlyingBalance == 0) continue;

uint256 claimed = Math.min(amounts[i], underlyingBalance);

ERC20(underlying).safeTransfer(treasuryVault, claimed);
emit Events.ReserveFeeClaimed(underlying, claimed);
}
}

function _increaseP2PDeltas(address underlying, uint256 amount) internal {
Types.Indexes256 memory indexes = _updateIndexes(underlying);

Expand Down
4 changes: 4 additions & 0 deletions src/MorphoSetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ abstract contract MorphoSetters is IMorphoSetters, MorphoInternal {
_createMarket(underlying, reserveFactor, p2pIndexCursor);
}

function claimToTreasury(address[] calldata underlyings, uint256[] calldata amounts) external onlyOwner {
_claimToTreasury(underlyings, amounts);
}

function increaseP2PDeltas(address underlying, uint256 amount) external onlyOwner isMarketCreated(underlying) {
_increaseP2PDeltas(underlying, amount);
}
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ library Events {
uint256 poolSupplyIndex,
uint256 poolBorrowIndex
);

event ReserveFeeClaimed(address indexed underlying, uint256 claimed);
}

0 comments on commit 323ff2a

Please sign in to comment.