From dbf13c1b202de2b82a8674c0cb612dbb9a1caf8a Mon Sep 17 00:00:00 2001 From: bin Date: Thu, 8 Feb 2024 22:07:38 +0800 Subject: [PATCH] Add invariant_Tranche_K --- test/invariant/BaseInvariants.sol | 10 +++++++++- test/invariant/LiquidityInvariants.t.sol | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/invariant/BaseInvariants.sol b/test/invariant/BaseInvariants.sol index 7aa99fb2..09ef2b07 100644 --- a/test/invariant/BaseInvariants.sol +++ b/test/invariant/BaseInvariants.sol @@ -5,7 +5,7 @@ import {BaseTest} from "./BaseTest.sol"; import {EpochManager} from "contracts/liquidity/EpochManager.sol"; import {PayPeriodDuration} from "contracts/common/SharedDefs.sol"; import {PoolSettings, LPConfig, FrontLoadingFeesStructure, FeeStructure, FirstLossCoverConfig} from "contracts/common/PoolConfig.sol"; -import {BORROWER_LOSS_COVER_INDEX, ADMIN_LOSS_COVER_INDEX, SENIOR_TRANCHE, JUNIOR_TRANCHE} from "contracts/common/SharedDefs.sol"; +import {BORROWER_LOSS_COVER_INDEX, ADMIN_LOSS_COVER_INDEX, SENIOR_TRANCHE, JUNIOR_TRANCHE, HUNDRED_PERCENT_IN_BPS} from "contracts/common/SharedDefs.sol"; import {CreditRecord, CreditConfig, CreditState, DueDetail} from "contracts/credit/CreditStructs.sol"; import "forge-std/console.sol"; @@ -398,6 +398,14 @@ contract BaseInvariants is BaseTest { ); } + function _assert_Tranche_K() internal { + assertGe( + juniorTranche.totalAssets() * poolConfig.getLPConfig().maxSeniorJuniorRatio, + seniorTranche.totalAssets(), + "Tranche Invariant K" + ); + } + function _assert_EpochManager_A() internal { EpochManager.CurrentEpoch memory epoch = epochManager.currentEpoch(); assertGt(epoch.endTime, block.timestamp, "EpochManager Invariant A"); diff --git a/test/invariant/LiquidityInvariants.t.sol b/test/invariant/LiquidityInvariants.t.sol index 423cdb60..5e47f100 100644 --- a/test/invariant/LiquidityInvariants.t.sol +++ b/test/invariant/LiquidityInvariants.t.sol @@ -100,6 +100,10 @@ contract LiquidityInvariants is BaseInvariants { _assert_Tranche_J(); } + function invariant_Tranche_K() public { + _assert_Tranche_K(); + } + function invariant_EpochManager_A() public { _assert_EpochManager_A(); } @@ -147,6 +151,7 @@ contract LiquidityInvariants is BaseInvariants { _assert_Tranche_G(); _assert_Tranche_H_I(); _assert_Tranche_J(); + _assert_Tranche_K(); } function test_EpochManager_invariants() public {