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: update the tree #292

Merged
merged 4 commits into from
Aug 14, 2023
Merged
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
66 changes: 45 additions & 21 deletions test/morpho_tests.tree
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
├── it should emit Supply(market.id, msg.sender, onBehalf, assets, shares)
├── if data.length > 0
│ └── it should call sender's onMorphoSupply callback
└── it should transfer assets of the borrowable asset from the sender to Morpho
├── it should transfer assets of the borrowable asset from the sender to Morpho
└── it should return the assets and the shares supplied
.
└── withdraw(Market memory market, uint256 assets, uint256 shares, address onBehalf, address receiver) external
├── when market is not created
Expand All @@ -103,8 +104,10 @@
├── it should remove assets from totalSupply[market.id]
├── it should emit Withdraw(market.id, msg.sender, onBehalf, receiver, assets, shares)
├── it should transfer assets of the borrowable asset to the receiver
└── when totalBorrow[market.id] > totalSupply[market.id]
└── revert with INSUFFICIENT_LIQUIDITY
├── when totalBorrow[market.id] > totalSupply[market.id]
│ └── revert with INSUFFICIENT_LIQUIDITY
└── when totalBorrow[market.id] <= totalSupply[market.id]
└── it should return the assets and the shares withdrawn
.
└── borrow(Market memory market, uint256 assets, uint256 shares, address onBehalf, address receiver) external
├── when market is not created
Expand Down Expand Up @@ -132,8 +135,11 @@
├── when position is not healthy
│ └── revert with INSUFFICIENT_COLLATERAL
└── when position is healthy
└── when totalBorrow[market.id] > totalSupply[market.id]
└── revert with INSUFFICIENT_LIQUIDITY
├── when totalBorrow[market.id] > totalSupply[market.id]
│ └── revert with INSUFFICIENT_LIQUIDITY
└── when totalBorrow[market.id] <= totalSupply[market.id]
└── it should return the assets and the shares borrowed

.
└── repay(Market memory market, uint256 assets, uint256 shares, address onBehalf, bytes calldata data) external
├── when market is not created
Expand All @@ -156,7 +162,8 @@
├── it should emit Repay(market.id, msg.sender, onBehalf, assets, shares)
├── if data.length > 0
│ └── it should call sender's onMorphoRepay callback
└── it should transfer assets of the borrowable asset from the sender to Morpho
├── it should transfer assets of the borrowable asset from the sender to Morpho
└── it should return the assets and the shares repaid
.
└── supplyCollateral(Market memory market, uint256 assets, address onBehalf, bytes calldata data) external
├── when market is not created
Expand Down Expand Up @@ -205,10 +212,10 @@
├── when position is healthy
│ └── revert with HEALTHY_POSITION
└── when the position is not healthy
├── it should compute incentive = WAD + ALPHA.mulWadDown(WAD.divWadDown(market.lltv) - WAD)
├── it should compute repaid = seized.mulDivUp(collateralPrice, priceScale).divWadUp(incentive)
├── it should remove repaid.toSharesDown(totalBorrow[market.id], totalBorrowShares[market.id]) from borrowShares[market.id][borrower]
├── it should remove repaid.toSharesDown(totalBorrow[market.id], totalBorrowShares[market.id]) from totalBorrowShares[market.id]
├── it should compute repaid = seized.mulDivUp(collateralPrice, ORACLE_PRICE_SCALE).wDivUp(incentive)
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
├── it should compute repaidShares = repaid.toSharesDown(totalBorrow[market.id], totalBorrowShares[market.id]);
├── it should remove repaidShares from borrowShares[market.id][borrower]
├── it should remove repaidShares from totalBorrowShares[market.id]
├── it should remove repaid from totalBorrow[market.id]
├── it should remove seized from collateral[market.id][borrower]
├── if after the liquidation the borrower's collateral is 0
Expand All @@ -230,31 +237,48 @@
├── it should emit FlashLoan(msg.sender, token, assets)
└── it should transfer assets of token from the sender to Morpho
.
└── setAuthorizationWithSig(address authorizer, address authorizee, bool newIsAuthorized, uint256 deadline, Signature calldata signature) external
├── when block.timestamp >= deadline
└── setAuthorizationWithSig(Authorization memory authorization, Signature calldata signature) external
├── when block.timestamp >= authorization.deadline
│ └── revert with SIGNATURE_EXPIRED
└── when block.timestamp < deadline
├── when the signature is invalid or not signed by the authorizer
│ └── revert with INVALID_SIGNATURE
└── when the signature is valid and signed by the authorizer
├── it should increment the authorizer's nonce
├── it should emit IncrementNonce(msg.sender, authorizer, usedNonce)
├── it should set isAuthorized[authorizer][authorized] to newIsAuthorized
└── it should emit SetAuthorization(msg.sender, authorizer, authorized, newIsAuthorized)
├── when authorization.nonce != nonce[authorization.authorizer]
│ └── revert with INVALID_NONCE
└── when authorization.nonce == nonce[authorization.authorizer]
├── when the signature is invalid or not signed by authorization.authorizer
│ └── revert with INVALID_SIGNATURE
└── when the signature is valid and signed by authorization.authorizer
├── it should increment authorization.authorizer's nonce
├── it should emit IncrementNonce(msg.sender, authorization.authorizer, authorization.nonce)
├── it should set isAuthorized[authorization.authorizer][authorization.authorized] to authorization.isAuthorized
└── it should emit SetAuthorization(msg.sender, authorization.authorizer, authorization.authorized, authorization.isAuthorized)
.
└── setAuthorization(address authorized, bool newIsAuthorized) external
├── should set isApproved[msg.sender][authorized] to newIsAuthorized
└── it should emit SetAuthorization(msg.sender, msg.sender, authorized, newIsAuthorized)
.
└── accrueInterests(Market memory market) external
├── when market is not created
│ └── revert with MARKET_NOT_CREATED
└── when market is created
└── it should accrue the interests
.
└── _accrueInterests(Market memory market, Id id) internal
└── when interests not already accrued in the block
├── it should set lastUpdate to block.timestamp
└── when marketTotalBorrow is not 0
├── it should compute accruedInterests = marketTotalBorrow.mulWadDown(borrowRate.wTaylorCompounded(elapsed))
├── it should compute accruedInterests = marketTotalBorrow.wMulDown(borrowRate.wTaylorCompounded(elapsed))
├── it should add accruedInterests to totalBorrow
├── it should add accruedInterests to totalSupply
└── when fee[id] != 0
│ ├── it should add accruedInterests.mulWadDown(fee[id]) to feeAmount
│ ├── it should add accruedInterests.wMulDown(fee[id]) to feeAmount
│ ├── it should add feeAmount.mulDivDown(totalSupplyShares[id], totalSupply[id] - feeAmount) to supplyShares[id][feeRecipient]
│ └── it should add feeAmount.mulDivDown(totalSupplyShares[id], totalSupply[id] - feeAmount) to totalSupplyShares[id]
└── it should emit AccrueInterests(id, borrowRate, accruedInterests, feeShares)
.
└── _isHealthy(Market memory market, Id id, address user, uint256 collateralPrice) internal
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
├── it should compute borrowed = borrowShares[id][user].toAssetsUp(totalBorrow[id], totalBorrowShares[id])
├── it should compute maxBorrow = collateral[id][user].mulDivDown(collateralPrice, ORACLE_PRICE_SCALE).wMulDown(market.lltv)
└── it should return maxBorrow >= borrowed
.
└── liquidationIncentiveFactor(uint256 lltv) internal
└── it should return min(MAX_LIQUIDATION_INCENTIVE_FACTOR, WAD.wDivDown(WAD - LIQUIDATION_CURSOR.wMulDown(WAD - lltv)))