Skip to content

Commit

Permalink
Merge pull request #292 from morpho-labs/fix/btt
Browse files Browse the repository at this point in the history
fix: update the tree
  • Loading branch information
MathisGD committed Aug 14, 2023
2 parents 25f50cc + 3078e23 commit db42423
Showing 1 changed file with 45 additions and 21 deletions.
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)
β”œβ”€β”€ 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
β”œβ”€β”€ 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)))

0 comments on commit db42423

Please sign in to comment.