@@ -28,7 +28,7 @@ import "test_helpers.cdc"
2828// - Focuses on protocol solvency and insurance mechanics
2929//
3030// Interest Rate Configuration:
31- // - MOET: FixedCurve at 4% APY (rate independent of utilization)
31+ // - MOET: FixedCurve at a 4% nominal yearly rate (rate independent of utilization)
3232// - Flow: KinkCurve with Aave v3 Volatile One parameters
3333// (45% optimal utilization, 0% base, 4% slope1, 300% slope2)
3434// =============================================================================
@@ -40,18 +40,19 @@ access(all) var snapshot: UInt64 = 0
4040// Interest Rate Parameters
4141// =============================================================================
4242
43- // MOET: FixedCurve (Spread Model)
43+ // MOET: FixedCurve (Protocol-Fee Spread Model)
4444// -----------------------------------------------------------------------------
45- // In the spread model , the curve defines the DEBIT rate (what borrowers pay).
46- // The CREDIT rate is derived as: creditRate = debitRate - insuranceRate
45+ // In the fixed-curve path , the curve defines the DEBIT rate (what borrowers pay).
46+ // The CREDIT rate is derived from the debit rate after protocol fees.
4747// This ensures lenders always earn less than borrowers pay, with the
48- // difference going to the insurance pool for protocol solvency .
48+ // difference allocated by the configured protocol fee settings .
4949//
50- // Example at 4% debit rate with 0.1% insurance:
51- // - Borrowers pay: 4.0% APY
52- // - Lenders earn: 3.9% APY
53- // - Insurance: 0.1% APY (collected by protocol)
54- access (all ) let moetFixedRate : UFix128 = 0.04 // 4% APY debit rate
50+ // Example at a 4% nominal yearly debit rate:
51+ // - Borrowers pay: 4.0% nominal yearly debit rate
52+ // - Lenders earn: a lower nominal yearly credit rate after protocol fees
53+ // - Protocol Fees are comprised of two parts -
54+ // - Insurance/Stability: configurable fees of accrued debit interest
55+ access (all ) let moetFixedRate : UFix128 = 0.04 // 4% nominal yearly debit rate
5556
5657// FlowToken: KinkCurve (Aave v3 Volatile One Parameters)
5758// -----------------------------------------------------------------------------
@@ -64,10 +65,10 @@ access(all) let moetFixedRate: UFix128 = 0.04 // 4% APY debit rate
6465// - If utilization > optimal: rate = baseRate + slope1 + ((util-optimal)/(1-optimal)) × slope2
6566//
6667// At 40% utilization (below 45% optimal):
67- // - Rate = 0% + (40%/45%) × 4% ≈ 3.56% APY
68+ // - Rate = 0% + (40%/45%) × 4% ≈ 3.56% nominal yearly rate
6869//
6970// At 80% utilization (above 45% optimal):
70- // - Rate = 0% + 4% + ((80%-45%)/(100%-45%)) × 300% ≈ 195% APY
71+ // - Rate = 0% + 4% + ((80%-45%)/(100%-45%)) × 300% ≈ 195% nominal yearly rate
7172access (all ) let flowOptimalUtilization : UFix128 = 0.45 // 45% kink point
7273access (all ) let flowBaseRate : UFix128 = 0.0 // 0% base rate
7374access (all ) let flowSlope1 : UFix128 = 0.04 // 4% slope below kink
@@ -160,15 +161,15 @@ fun test_moet_debit_accrues_interest() {
160161 // -------------------------------------------------------------------------
161162 // STEP 4: Configure MOET Interest Rate
162163 // -------------------------------------------------------------------------
163- // Set MOET to use a FixedCurve at 4% APY .
164+ // Set MOET to use a FixedCurve at a 4% nominal yearly rate .
164165 // This rate is independent of utilization - borrowers always pay 4%.
165166 // Note: Interest curve must be set AFTER LP deposit to ensure credit exists.
166167 setInterestCurveFixed (
167168 signer : PROTOCOL_ACCOUNT ,
168169 tokenTypeIdentifier : MOET_TOKEN_IDENTIFIER ,
169170 yearlyRate : moetFixedRate
170171 )
171- log (" Set MOET interest rate to 4% APY (after LP deposit)" )
172+ log (" Set MOET interest rate to 4% nominal yearly rate (after LP deposit)" )
172173
173174 let res = setInsuranceSwapper (
174175 signer : PROTOCOL_ACCOUNT ,
@@ -305,7 +306,7 @@ fun test_moet_debit_accrues_interest() {
305306 // Expected Growth Calculation
306307 // -------------------------------------------------------------------------
307308 // Per-second compounding: (1 + r / 31_557_600) ^ seconds - 1
308- // At 4% APY for 30 days (2,592,000 seconds):
309+ // At a 4% nominal yearly rate for 30 days (2,592,000 seconds):
309310 // Growth = (1 + 0.04 / 31_557_600) ^ 2_592_000 - 1 ≈ 0.328%
310311 //
311312 // We use a wide tolerance range because:
@@ -337,10 +338,10 @@ fun test_moet_debit_accrues_interest() {
337338// - Time advances 30 days
338339// - Verify: LP credit increased, growth rate is in expected range
339340//
340- // Key Insight (FixedCurve Spread Model ):
341- // - debitRate = 4.0% (what borrowers pay, defined by curve)
342- // - insuranceRate = 0.1% ( protocol reserve)
343- // - creditRate = debitRate - insuranceRate = 3.9% (what lenders earn)
341+ // Key Insight (FixedCurve Protocol-Fee Spread ):
342+ // - debitRate is defined by the curve
343+ // - creditRate is the debit rate after protocol fees
344+ // - creditRate remains below debitRate
344345// =============================================================================
345346access (all )
346347fun test_moet_credit_accrues_interest_with_insurance () {
@@ -394,7 +395,7 @@ fun test_moet_credit_accrues_interest_with_insurance() {
394395 // -------------------------------------------------------------------------
395396 // STEP 4: Configure MOET Interest Rate
396397 // -------------------------------------------------------------------------
397- // Set 4% APY debit rate. Credit rate will be ~3.9% after insurance deduction .
398+ // Set a 4% nominal yearly debit rate. Credit rate will be lower after protocol fees .
398399 setInterestCurveFixed (
399400 signer : PROTOCOL_ACCOUNT ,
400401 tokenTypeIdentifier : MOET_TOKEN_IDENTIFIER ,
@@ -485,9 +486,9 @@ fun test_moet_credit_accrues_interest_with_insurance() {
485486 // -------------------------------------------------------------------------
486487 // Expected Credit Growth Calculation
487488 // -------------------------------------------------------------------------
488- // Debit rate: 4% APY (what borrowers pay)
489- // Insurance: 0.1% APY (protocol reserve)
490- // Credit rate: 4% - 0.1% = 3.9% APY (what LPs earn)
489+ // Debit rate: 4% nominal yearly rate (what borrowers pay)
490+ // Protocol fees: configured insurance plus stability fee fractions
491+ // Credit rate: lower than the debit rate after protocol fees
491492 //
492493 // 30-day credit growth ≈ 3.9% × (30/365) ≈ 0.32%
493494 //
@@ -523,7 +524,7 @@ fun test_moet_credit_accrues_interest_with_insurance() {
523524// Key Insight (KinkCurve):
524525// At 40% utilization (below 45% optimal kink):
525526// - Rate = baseRate + (utilization/optimal) × slope1
526- // - Rate = 0% + (40%/45%) × 4% ≈ 3.56% APY
527+ // - Rate = 0% + (40%/45%) × 4% ≈ 3.56% nominal yearly rate
527528// =============================================================================
528529access (all )
529530fun test_flow_debit_accrues_interest () {
@@ -685,7 +686,7 @@ fun test_flow_debit_accrues_interest() {
685686 // -------------------------------------------------------------------------
686687 // Utilization = 4,000 / 10,000 = 40% (below 45% optimal)
687688 // Rate = baseRate + (util/optimal) × slope1
688- // = 0% + (40%/45%) × 4% ≈ 3.56% APY
689+ // = 0% + (40%/45%) × 4% ≈ 3.56% nominal yearly rate
689690 //
690691 // 30-day growth ≈ 3.56% × (30/365) ≈ 0.29%
691692 let minExpectedDebtGrowth : UFix64 = 0.002 // 0.2%
@@ -891,15 +892,15 @@ fun test_flow_credit_accrues_interest_with_insurance() {
891892// - LP deposits 10,000 MOET
892893// - Borrower deposits 10,000 FLOW and borrows MOET
893894// - Insurance rate set to 1% (higher than default 0.1% for visibility)
894- // - Debit rate set to 10% APY
895+ // - Debit rate set to a 10% nominal yearly rate
895896// - Time advances 1 YEAR
896897// - Verify: Insurance spread ≈ 1% (debit rate - credit rate)
897898//
898- // Key Insight (FixedCurve Spread Model ):
899- // - debitRate = 10% (what borrowers pay)
900- // - insuranceRate = 1% (protocol reserve)
901- // - creditRate = debitRate - insuranceRate = 9% (what LPs earn)
902- // - Spread = debitRate - creditRate = 1%
899+ // Key Insight (FixedCurve Protocol-Fee Spread ):
900+ // - debitRate is set by the fixed curve
901+ // - insurance/stability remain configured fee parameters
902+ // - creditRate is reduced relative to debitRate by those protocol fees
903+ // - the realized spread shows up as a lower lender growth rate than borrower growth rate
903904// =============================================================================
904905access (all )
905906fun test_insurance_deduction_verification () {
@@ -952,7 +953,7 @@ fun test_insurance_deduction_verification() {
952953 //
953954 // Insurance Rate: 1% (vs default 0.1%)
954955 // Debit Rate: 10% (vs default 4%)
955- // Expected Credit Rate: 10% - 1% = 9%
956+ // Expected Credit Rate: lower than 10% after protocol fees
956957 let res = setInsuranceSwapper (
957958 signer : PROTOCOL_ACCOUNT ,
958959 tokenTypeIdentifier : MOET_TOKEN_IDENTIFIER ,
@@ -1012,8 +1013,8 @@ fun test_insurance_deduction_verification() {
10121013 // =========================================================================
10131014 // Using 1 year (31,557,600 seconds for 365.25 days) makes the percentage calculations
10141015 // straightforward. With per-second discrete compounding:
1015- // - 10% APY → (1 + 0.10 / 31_557_600) ^ 31_557_600 - 1 ≈ 10.52% effective rate
1016- // - 9% APY → (1 + 0.09 / 31_557_600) ^ 31_557_600 - 1 ≈ 9.42% effective rate
1016+ // - 10% nominal yearly rate → (1 + 0.10 / 31_557_600) ^ 31_557_600 - 1 ≈ 10.52% effective rate
1017+ // - 9% nominal yearly rate → (1 + 0.09 / 31_557_600) ^ 31_557_600 - 1 ≈ 9.42% effective rate
10171018 // - Spread should be approximately 1%
10181019 Test .moveTime (by : ONE_YEAR )
10191020 Test .commitBlock ()
@@ -1049,9 +1050,10 @@ fun test_insurance_deduction_verification() {
10491050 // =========================================================================
10501051 // ASSERTION: Verify Insurance Spread
10511052 // =========================================================================
1052- // For FixedCurve (spread model):
1053- // - debitRate = creditRate + insuranceRate
1054- // - insuranceSpread = debitRate - creditRate ≈ insuranceRate
1053+ // For FixedCurve:
1054+ // - debitRate is the curve-defined nominal yearly rate
1055+ // - creditRate is the debit rate after protocol fees
1056+ // - insuranceSpread = actualDebtRate - actualCreditRate
10551057 //
10561058 // With 10% debit and 1% insurance, spread should be ~1%
10571059 // (Slight variation due to per-second compounding effects)
@@ -1158,12 +1160,12 @@ fun test_combined_all_interest_scenarios() {
11581160 // -------------------------------------------------------------------------
11591161 // STEP 5: Configure Interest Curves for Both Tokens
11601162 // -------------------------------------------------------------------------
1161- // MOET: FixedCurve at 4% APY ( spread model)
1163+ // MOET: FixedCurve at a 4% nominal yearly rate (fixed-curve spread model)
11621164 // Flow: KinkCurve with Aave v3 Volatile One parameters
11631165 setInterestCurveFixed (
11641166 signer : PROTOCOL_ACCOUNT ,
11651167 tokenTypeIdentifier : MOET_TOKEN_IDENTIFIER ,
1166- yearlyRate : moetFixedRate // 4% APY
1168+ yearlyRate : moetFixedRate // 4% nominal yearly rate
11671169 )
11681170 setInterestCurveKink (
11691171 signer : PROTOCOL_ACCOUNT ,
@@ -1324,14 +1326,14 @@ fun test_combined_all_interest_scenarios() {
13241326 // Assertion Group 2: Health Factor Changes
13251327 // -------------------------------------------------------------------------
13261328 // Borrower1 (Flow collateral, MOET debt):
1327- // - MOET debit rate: 4% APY
1329+ // - MOET debit rate: 4% nominal yearly rate
13281330 // - Flow credit rate: lower than Flow debit rate due to insurance spread
13291331 // - Net effect: Debt grows faster than collateral → Health DECREASES
13301332 Test .assert (b1HealthAfter < b1HealthBefore , message : " Borrower1 health should decrease" )
13311333
13321334 // Borrower2 (MOET collateral, Flow debt):
1333- // - MOET credit rate: ~3.9% APY (4% debit - 0.1% insurance)
1334- // - Flow debit rate: ~2.5% APY (at 28.6% utilization)
1335+ // - MOET credit rate: lower than the MOET debit rate after protocol fees
1336+ // - Flow debit rate: ~2.5% nominal yearly rate (at 28.6% utilization)
13351337 // - Collateral (3,000 MOET) earning more absolute interest than debt (2,000 Flow)
13361338 // - Net effect: Health INCREASES
13371339 Test .assert (b2HealthAfter > b2HealthBefore , message : " Borrower2 health should increase (collateral interest > debt interest)" )
0 commit comments