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

Set asset as collateral #569

Merged
merged 45 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fac6976
feat: draft asset as collateral
MerlinEgalite Feb 22, 2023
18656f1
feat: add isCollateral check
MerlinEgalite Feb 22, 2023
b3c60d7
feat: add revert case and mirror behavior
MerlinEgalite Feb 23, 2023
f2c637c
feat: add correct check
MerlinEgalite Feb 23, 2023
4afe5f2
fix: add missing negation
MerlinEgalite Feb 23, 2023
546a14b
test: add first tests
MerlinEgalite Feb 23, 2023
ad47ae3
feat: add functions to interface + small reorder of logic
MerlinEgalite Feb 23, 2023
be28d1d
test: add missing tests
MerlinEgalite Feb 23, 2023
aa89550
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Feb 23, 2023
bf5516d
test: fix test setup
MerlinEgalite Feb 23, 2023
394124a
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Feb 23, 2023
7af52d8
test: fix test after merge
MerlinEgalite Feb 23, 2023
ba87cab
docs: improve comments
MerlinEgalite Feb 24, 2023
5ad3712
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Feb 27, 2023
57b4a3b
refactor: apply error renaming suggestion
MerlinEgalite Feb 27, 2023
073ff49
test: set true for expectEmit
MerlinEgalite Feb 27, 2023
027079d
refactor: remove check collateral
MerlinEgalite Feb 27, 2023
9eb4672
docs: add comment about sending assets with LTV = 0
MerlinEgalite Feb 28, 2023
4ca4957
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Feb 28, 2023
57a57b0
docs: apply doc suggestion
MerlinEgalite Mar 1, 2023
d67a71d
refactor: revert when is collateral on morpho
MerlinEgalite Mar 2, 2023
a1b0590
test: just remove the test
MerlinEgalite Mar 2, 2023
6d68260
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Mar 2, 2023
993b0a5
refactor: revert if asset not collateral on pool
MerlinEgalite Mar 2, 2023
3909682
refactor: remove useless code
MerlinEgalite Mar 2, 2023
6ef27f0
refactor: check first
MerlinEgalite Mar 3, 2023
4166835
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Mar 6, 2023
aa7aaa3
docs: remove outdated comment
MerlinEgalite Mar 6, 2023
0bc1a47
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Mar 7, 2023
f93f8fe
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Mar 10, 2023
bca5964
fix: miss merge conflicts fixes
MerlinEgalite Mar 10, 2023
f35cf44
refactor: correct formatting
MerlinEgalite Mar 13, 2023
482a46f
test: remove useless test
MerlinEgalite Mar 13, 2023
638e2c2
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Mar 13, 2023
a4225cc
Merge branch 'dev' of github.com:morpho-dao/morpho-aave-v3 into feat/…
MerlinEgalite Mar 14, 2023
3df3587
docs: apply comment suggestions
MerlinEgalite Mar 14, 2023
f11b3f2
refactor: revert earlier if isCollateral = false too
MerlinEgalite Mar 14, 2023
a51ce76
refactor: more explicit errors
MerlinEgalite Mar 14, 2023
c65e0f6
refactor: scope to created market for setAssetIsCollateralOnPool
MerlinEgalite Mar 14, 2023
b3de2fb
refactor: remove useless check + add invariant tests
MerlinEgalite Mar 15, 2023
ad29aa5
refactor: remove useless check
MerlinEgalite Mar 15, 2023
0847c12
Merge branch 'feat/asset-as-collateral' of github.com:morpho-dao/morp…
MerlinEgalite Mar 15, 2023
a57a7c0
docs: improve doc
MerlinEgalite Mar 15, 2023
be26bbc
Merge branch 'feat/asset-as-collateral' of github.com:morpho-dao/morp…
MerlinEgalite Mar 15, 2023
84ab598
Merge pull request #680 from morpho-dao/refactor/collateral-setters
MerlinEgalite Mar 16, 2023
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/MorphoInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ abstract contract MorphoInternal is MorphoStorage {
view
returns (uint256 borrowable, uint256 maxDebt)
{
if (!_market[underlying].isCollateral) return (0, 0);

(uint256 underlyingPrice, uint256 ltv, uint256 liquidationThreshold, uint256 tokenUnit) =
_assetLiquidityData(underlying, vars);

Expand Down
20 changes: 20 additions & 0 deletions src/MorphoSetters.sol
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ abstract contract MorphoSetters is IMorphoSetters, MorphoInternal {
emit Events.TreasuryVaultSet(treasuryVault);
}

/// @notice Sets the `underlying` asset as collateral or not on the pool.
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
/// @dev Note that it is possible to set an asset as collateral whose market is not created yet on the protocol.
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
function setAssetIsCollateralOnPool(address underlying, bool isCollateral) external onlyOwner {
if (isCollateral && !_market[underlying].isCreated()) revert Errors.MarketNotCreated();
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
if (!isCollateral && _market[underlying].isCreated()) _market[underlying].setAssetIsCollateral(isCollateral);
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved

_POOL.setUserUseReserveAsCollateral(underlying, isCollateral);
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
}

/// @notice Sets the `underlying` asset as collateral or not on Morpho.
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
/// @dev If the asset is set as collateral, the behavior is propagated to the pool.
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
function setAssetIsCollateral(address underlying, bool isCollateral)
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
external
onlyOwner
isMarketCreated(underlying)
{
_market[underlying].setAssetIsCollateral(isCollateral);
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
if (isCollateral) _POOL.setUserUseReserveAsCollateral(underlying, isCollateral);
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
}

/// @notice Sets the `underlying`'s reserve factor to `newReserveFactor` (in bps).
function setReserveFactor(address underlying, uint16 newReserveFactor)
external
Expand Down
11 changes: 11 additions & 0 deletions src/PositionsManagerInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {LogarithmicBuckets} from "@morpho-data-structures/LogarithmicBuckets.sol
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol";
import {UserConfiguration} from "@aave-v3-core/protocol/libraries/configuration/UserConfiguration.sol";
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
import {ReserveConfiguration} from "@aave-v3-core/protocol/libraries/configuration/ReserveConfiguration.sol";

import {ERC20} from "@solmate/tokens/ERC20.sol";
Expand All @@ -43,6 +44,7 @@ abstract contract PositionsManagerInternal is MatchingEngine {
using EnumerableSet for EnumerableSet.AddressSet;
using LogarithmicBuckets for LogarithmicBuckets.Buckets;

using UserConfiguration for DataTypes.UserConfigurationMap;
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;

/// @dev Validates the manager's permission.
Expand Down Expand Up @@ -90,6 +92,7 @@ abstract contract PositionsManagerInternal is MatchingEngine {
function _validateSupplyCollateral(address underlying, uint256 amount, address user) internal view {
Types.Market storage market = _validateInput(underlying, amount, user);
if (market.isSupplyCollateralPaused()) revert Errors.SupplyCollateralIsPaused();
if (!market.isCollateral) revert Errors.AssetNotUsedAsCollateral();
}

/// @dev Validates a borrow action.
Expand Down Expand Up @@ -168,6 +171,14 @@ abstract contract PositionsManagerInternal is MatchingEngine {
if (!borrowMarket.isCreated() || !collateralMarket.isCreated()) revert Errors.MarketNotCreated();
if (collateralMarket.isLiquidateCollateralPaused()) revert Errors.LiquidateCollateralIsPaused();
if (borrowMarket.isLiquidateBorrowPaused()) revert Errors.LiquidateBorrowIsPaused();

// Revert only if the collateral is not enabled as collateral on Morpho AND on the pool.
// This way Morpho can disable an asset as collateral on Morpho side only and still be able to liquidate unhealthy positions using this asset as collateral.
// This can be helpful in case the pool sets an asset's LTV to 0.
if (
!collateralMarket.isCollateral
&& !_POOL.getUserConfiguration(address(this)).isUsingAsCollateral(_POOL.getReserveData(underlyingCollateral).id)
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
) revert Errors.AssetNotUsedAsCollateral();
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
}

/// @dev Authorizes a liquidate action.
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/IMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ interface IMorphoSetters {
function setP2PIndexCursor(address underlying, uint16 p2pIndexCursor) external;
function setReserveFactor(address underlying, uint16 newReserveFactor) external;

function setAssetIsCollateralOnPool(address underlying, bool isCollateral) external;
function setAssetIsCollateral(address underlying, bool isCollateral) external;
function setIsP2PDisabled(address underlying, bool isP2PDisabled) external;
function setIsPaused(address underlying, bool isPaused) external;
function setIsPausedForAllMarkets(bool isPaused) external;
Expand Down
1 change: 1 addition & 0 deletions src/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ library Errors {

error UnauthorizedWithdraw();
error UnauthorizedLiquidate();
error AssetNotUsedAsCollateral();
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved

error ExceedsMaxBasisPoints();

Expand Down
2 changes: 2 additions & 0 deletions src/libraries/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ library Events {
address indexed claimer, address indexed onBehalf, address indexed rewardToken, uint256 amountClaimed
);

event IsCollateralSet(address indexed underlying, bool isCollateral);

event IsSupplyPausedSet(address indexed underlying, bool isPaused);

event IsSupplyCollateralPausedSet(address indexed underlying, bool isPaused);
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/MarketLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ library MarketLib {
return market.pauseStatuses.isP2PDisabled;
}

function setAssetIsCollateral(Types.Market storage market, bool isCollateral) internal {
market.isCollateral = isCollateral;

emit Events.IsCollateralSet(market.underlying, isCollateral);
}

function setIsSupplyPaused(Types.Market storage market, bool isPaused) internal {
market.pauseStatuses.isSupplyPaused = isPaused;

Expand Down
1 change: 1 addition & 0 deletions src/libraries/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ library Types {
// SLOT 6
address underlying; // 160 bits
PauseStatuses pauseStatuses; // 80 bits
bool isCollateral; // 8 bits
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
// SLOT 7
address variableDebtToken; // 160 bits
uint32 lastUpdateTimestamp; // 32 bits
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/ForkTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ contract ForkTest is BaseTest {
weth = config.getAddress("WETH");
wNative = config.getWrappedNative();

allUnderlyings = pool.getReservesList();
allUnderlyings = [dai, usdc, aave, wbtc, weth];
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
}

function _label() internal virtual {
Expand Down
25 changes: 21 additions & 4 deletions test/helpers/IntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ contract IntegrationTest is ForkTest {
_createMarket(allUnderlyings[i], 0, 33_33);
}

// Supply dust to make UserConfigurationMap.isUsingAsCollateralOne() always return true.
_deposit(testMarkets[weth], 1e12, address(morpho));
_deposit(testMarkets[dai], 1e12, address(morpho));
_setAllAssetsAsCollateral();
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved

_forward(1); // All markets are outdated in Morpho's storage.

Expand Down Expand Up @@ -152,6 +150,18 @@ contract IntegrationTest is ForkTest {
morpho.createMarket(market.underlying, market.reserveFactor, market.p2pIndexCursor);
}

function _setAllAssetsAsCollateral() internal {
for (uint256 i; i < allUnderlyings.length; ++i) {
_setAssetAsCollateral(testMarkets[allUnderlyings[i]]);
}
}

function _setAssetAsCollateral(TestMarket storage market) internal {
// Supply dust to make UserConfigurationMap.isUsingAsCollateralOne() return true.
_deposit(market, (10 ** market.decimals) / 1e6, address(morpho));
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
morpho.setAssetIsCollateral(market.underlying, true);
}

/// @dev Returns the total supply used towards the supply cap.
function _totalSupplyToCap(TestMarket storage market) internal view returns (uint256) {
return (IAToken(market.aToken).scaledTotalSupply() + _accruedToTreasury(market.underlying)).rayMul(
Expand Down Expand Up @@ -212,11 +222,18 @@ contract IntegrationTest is ForkTest {
internal
bypassSupplyCap(market, amount)
{
deal(market.underlying, address(this), amount);
deal(market.underlying, address(this), type(uint256).max);
ERC20(market.underlying).approve(address(pool), amount);
pool.deposit(market.underlying, amount, onBehalf, 0);
}

/// @dev Deposits the given amount of tokens on behalf of the given address, on AaveV3.
function _depositSimple(address underlying, uint256 amount, address onBehalf) internal {
deal(underlying, address(this), amount);
ERC20(underlying).approve(address(pool), amount);
pool.deposit(underlying, amount, onBehalf, 0);
}
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved

/// @dev Bounds the input supply cap of AaveV3 so that it is exceeded after having deposited a given amount
function _boundSupplyCapExceeded(TestMarket storage market, uint256 amount, uint256 supplyCap)
internal
Expand Down
154 changes: 154 additions & 0 deletions test/integration/TestIntegrationAssetAsCollateral.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

import {IMorpho} from "src/interfaces/IMorpho.sol";

import {Errors} from "src/libraries/Errors.sol";
import {UserConfiguration} from "@aave-v3-core/protocol/libraries/configuration/UserConfiguration.sol";

import {Morpho} from "src/Morpho.sol";

import "test/helpers/IntegrationTest.sol";

contract TestIntegrationAssetAsCollateral is IntegrationTest {
using UserConfiguration for DataTypes.UserConfigurationMap;

function setUp() public override {
super.setUp();

// Deposit LINK dust so that setting LINK as collateral does not revert on the pool.
_depositSimple(link, 1e12, address(morpho));

morpho.setAssetIsCollateral(dai, false);
morpho.setAssetIsCollateral(usdc, false);
morpho.setAssetIsCollateral(aave, false);
morpho.setAssetIsCollateral(wbtc, false);
morpho.setAssetIsCollateral(weth, false);

vm.startPrank(address(morpho));
pool.setUserUseReserveAsCollateral(dai, false);
pool.setUserUseReserveAsCollateral(usdc, false);
pool.setUserUseReserveAsCollateral(aave, false);
pool.setUserUseReserveAsCollateral(wbtc, false);
pool.setUserUseReserveAsCollateral(weth, false);
pool.setUserUseReserveAsCollateral(link, false);
vm.stopPrank();
}

function testSetAssetIsCollateralShouldRevertWhenMarketNotCreated(address underlying) public {
vm.expectRevert(Errors.MarketNotCreated.selector);
morpho.setAssetIsCollateral(underlying, true);
}

function testSetAssetIsCollateral() public {
assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), false);

morpho.setAssetIsCollateral(dai, true);

assertEq(morpho.market(dai).isCollateral, true);
assertEq(_isUsingAsCollateral(dai), true);
}

function testSetAssetIsNotCollateral() public {
vm.prank(address(morpho));
pool.setUserUseReserveAsCollateral(dai, true);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), true);

morpho.setAssetIsCollateral(dai, false);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), true);
}

function testSetAssetIsCollateralOnPoolShouldRevertWhenMarketIsNotCreated() public {
assertEq(morpho.market(link).isCollateral, false);
assertEq(pool.getUserConfiguration(address(morpho)).isUsingAsCollateral(pool.getReserveData(link).id), false);

vm.expectRevert(Errors.MarketNotCreated.selector);
morpho.setAssetIsCollateralOnPool(link, true);
}

function testSetAssetIsCollateralOnPoolWhenMarketIsCreatedAndIsCollateralOnMorphoAndOnPool() public {
vm.prank(address(morpho));
pool.setUserUseReserveAsCollateral(dai, true);
morpho.setAssetIsCollateral(dai, true);

assertEq(morpho.market(dai).isCollateral, true);
assertEq(_isUsingAsCollateral(dai), true);

morpho.setAssetIsCollateralOnPool(dai, true);

assertEq(morpho.market(dai).isCollateral, true);
assertEq(_isUsingAsCollateral(dai), true);
}

function testSetAssetIsCollateralOnPoolWhenMarketIsCreatedAndIsNotCollateralOnMorphoOnly() public {
vm.prank(address(morpho));
pool.setUserUseReserveAsCollateral(dai, true);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), true);

morpho.setAssetIsCollateralOnPool(dai, true);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), true);
}

function testSetAssetIsCollateralOnPoolWhenMarketIsCreatedAndIsNotCollateral() public {
assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), false);

morpho.setAssetIsCollateralOnPool(dai, true);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), true);
}

function testSetAssetIsNotCollateralOnPoolWhenMarketIsNotCreated() public {
vm.prank(address(morpho));
pool.setUserUseReserveAsCollateral(link, true);

assertEq(morpho.market(link).isCollateral, false);
assertEq(pool.getUserConfiguration(address(morpho)).isUsingAsCollateral(pool.getReserveData(link).id), true);

morpho.setAssetIsCollateralOnPool(link, false);

assertEq(morpho.market(link).isCollateral, false);
assertEq(pool.getUserConfiguration(address(morpho)).isUsingAsCollateral(pool.getReserveData(link).id), false);
}

function testSetAssetIsNotCollateralOnPoolWhenMarketIsCreatedAndIsCollateralOnMorphoAndOnPool() public {
vm.prank(address(morpho));
pool.setUserUseReserveAsCollateral(dai, true);
morpho.setAssetIsCollateral(dai, true);

assertEq(morpho.market(dai).isCollateral, true);
assertEq(_isUsingAsCollateral(dai), true);

morpho.setAssetIsCollateralOnPool(dai, false);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), false);
}

function testSetAssetIsNotCollateralOnPoolWhenMarketIsCreatedAndIsNotCollateralOnMorphoOnly() public {
vm.prank(address(morpho));
pool.setUserUseReserveAsCollateral(dai, true);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), true);

morpho.setAssetIsCollateralOnPool(dai, false);

assertEq(morpho.market(dai).isCollateral, false);
assertEq(_isUsingAsCollateral(dai), false);
}

function _isUsingAsCollateral(address underlying) internal view returns (bool) {
return pool.getUserConfiguration(address(morpho)).isUsingAsCollateral(pool.getReserveData(underlying).id);
}
}
3 changes: 2 additions & 1 deletion test/integration/TestIntegrationLiquidate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,10 @@ contract TestIntegrationLiquidate is IntegrationTest {
1,
"borrow balance"
);
assertEq(
assertApproxEqAbs(
morpho.collateralBalance(collateralMarket.underlying, borrower),
formerCollateralBalance - expectedSeized,
1,
"collateral balance"
);
}
Expand Down
17 changes: 10 additions & 7 deletions test/integration/TestIntegrationWithdraw.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract TestIntegrationWithdraw is IntegrationTest {
assertApproxLeAbs(test.withdrawn, amount, 1, "withdrawn != amount");
assertApproxLeAbs(p2pSupply, promoted, 2, "p2pSupply != promoted");

assertApproxLeAbs(morpho.supplyBalance(market.underlying, onBehalf), remaining, 1, "supply != remaining");
assertApproxLeAbs(morpho.supplyBalance(market.underlying, onBehalf), remaining, 2, "supply != remaining");
assertEq(morpho.collateralBalance(market.underlying, onBehalf), 0, "collateral != 0");

// Assert Morpho's position on pool.
Expand Down Expand Up @@ -145,15 +145,18 @@ contract TestIntegrationWithdraw is IntegrationTest {
assertEq(test.scaledPoolSupply, 0, "scaledPoolSupply != 0");
assertEq(test.scaledCollateral, 0, "scaledCollateral != 0");
assertApproxEqAbs(test.withdrawn, test.supplied, 3, "withdrawn != supplied");
assertEq(
morpho.scaledP2PBorrowBalance(market.underlying, address(promoter1)), 0, "promoterScaledP2PBorrow != 0"
assertApproxEqAbs(
morpho.scaledP2PBorrowBalance(market.underlying, address(promoter1)),
0,
2,
"promoterScaledP2PBorrow != 0"
);

// Assert Morpho getters.
assertEq(morpho.supplyBalance(market.underlying, onBehalf), 0, "supply != 0");
assertEq(morpho.collateralBalance(market.underlying, onBehalf), 0, "collateral != 0");
assertApproxGeAbs(
morpho.borrowBalance(market.underlying, address(promoter1)), promoted, 3, "promoterBorrow != promoted"
assertApproxEqAbs(
morpho.borrowBalance(market.underlying, address(promoter1)), promoted, 2, "promoterBorrow != promoted"
);

// Assert Morpho's position on pool.
Expand All @@ -173,9 +176,9 @@ contract TestIntegrationWithdraw is IntegrationTest {

// Assert Morpho's market state.
assertEq(test.morphoMarket.deltas.supply.scaledDelta, 0, "scaledSupplyDelta != 0");
assertApproxEqAbs(test.morphoMarket.deltas.supply.scaledP2PTotal, 0, 1, "scaledTotalSupplyP2P != 0");
assertApproxEqAbs(test.morphoMarket.deltas.supply.scaledP2PTotal, 0, 2, "scaledTotalSupplyP2P != 0");
assertEq(test.morphoMarket.deltas.borrow.scaledDelta, 0, "scaledBorrowDelta != 0");
assertApproxEqAbs(test.morphoMarket.deltas.borrow.scaledP2PTotal, 0, 1, "scaledTotalBorrowP2P != 0");
assertApproxEqAbs(test.morphoMarket.deltas.borrow.scaledP2PTotal, 0, 2, "scaledTotalBorrowP2P != 0");
assertEq(test.morphoMarket.idleSupply, 0, "idleSupply != 0");
}
}
Expand Down
Loading