@@ -168,7 +168,7 @@ fun test_extreme_utilization() {
168168}
169169
170170// =============================================================================
171- /// Verifies protocol behavior when a lending pool has liquidity but no borrows .
171+ /// Verifies protocol borrow behavior when a lending pool has no available liquidity .
172172// =============================================================================
173173access (all )
174174fun test_zero_credit_balance () {
@@ -236,7 +236,7 @@ fun test_zero_credit_balance() {
236236 // FLOW debt 30 days growth = (1 + 0/31_557_600)^2_592_000 - 1 = 0
237237 // MOET credit 30 days growth = (1 + 0.03796/31_557_600)^2_592_000 - 1 = 0.0003122730069
238238 let detailsAfterTime = getPositionDetails (pid : pid , beFailed : false )
239- let moetCredit = getCreditBalanceForType (details : detailsAfterTime , vaultType : Type <@MOET.Vault >())
239+ var moetCredit = getCreditBalanceForType (details : detailsAfterTime , vaultType : Type <@MOET.Vault >())
240240 Test .assert (moetCredit > 10000.0 , message : " MOET credit should accrue interest" )
241241
242242 // add FLOW liquidity
@@ -249,6 +249,7 @@ fun test_zero_credit_balance() {
249249 amount : FLOWAmount
250250 )
251251 createPosition (admin : MAINNET_PROTOCOL_ACCOUNT , signer : flowLp , amount : FLOWAmount , vaultStoragePath : FLOW_VAULT_STORAGE_PATH , pushToDrawDownSink : false )
252+ let lpPid = getLastPositionId ()
252253
253254 // borrow FLOW (Flow LP deposited 5000.0 FLOW, liquidity now available)
254255 borrowFromPosition (
@@ -264,6 +265,9 @@ fun test_zero_credit_balance() {
264265 let flowDebt = getDebitBalanceForType (details : details , vaultType : Type <@FlowToken.Vault >())
265266 Test .assertEqual (100.0 , flowDebt )
266267
268+ let lpDetails = getPositionDetails (pid : lpPid , beFailed : false )
269+ let flowCredit = getCreditBalanceForType (details : lpDetails , vaultType : Type <@FlowToken.Vault >())
270+
267271 // FLOW interest rate calculation (KinkInterestCurve)
268272 //
269273 // totalCreditBalance = 5000
@@ -281,9 +285,10 @@ fun test_zero_credit_balance() {
281285 // protocolFeeAmount = debitIncome * (insuranceRate + stabilityFeeRate)
282286 // debitIncome = totalDebitBalance * debitRate
283287 //
284- // debitIncome = 0.0 * 0.0 = 0.0
285- // protocolFeeAmount = 0.0
286- // totalCreditBalance = 0.0 -> creditRate = 0.0
288+ // debitIncome = totalDebitBalance * debitRate = 100 * 0.00177777777 = 0.177777777
289+ // protocolFeeRate = 0.001 + 0.05 = 0.051
290+ // protocolFeeAmount = 0.177777777 * 0.051 = 0.00906666662
291+ // creditRate = (0.177777777 - 0.00906666662) / 5000 = 0.00003374222 (0.003374% APY)
287292
288293 // Advance 1 day to measure exact interest growth
289294 Test .moveTime (by : DAY )
@@ -298,10 +303,17 @@ fun test_zero_credit_balance() {
298303 let flowDebtAfter1Day = getDebitBalanceForType (details : detailsAfter1Day , vaultType : Type <@FlowToken.Vault >())
299304 let flowDebtDailyGrowth = (flowDebtAfter1Day - flowDebt ) / flowDebt
300305 Test .assertEqual (expectedFlowDebtDailyGrowth , flowDebtDailyGrowth )
306+
307+ // FLOW LP credit daily growth = (1 + 0.00003374222 / 31_557_600)^86400 - 1 = 0.00000009232
308+ let expectedFlowCreditDailyGrowth = 0.00000009
309+ let lpDetailsAfter1Day = getPositionDetails (pid : lpPid , beFailed : false )
310+ let flowCreditAfter1Day = getCreditBalanceForType (details : lpDetailsAfter1Day , vaultType : Type <@FlowToken.Vault >())
311+ let flowCreditDailyGrowth = (flowCreditAfter1Day - flowCredit ) / flowCredit
312+ Test .assertEqual (expectedFlowCreditDailyGrowth , flowCreditDailyGrowth )
301313}
302314
303315// =============================================================================
304- /// Verifies protocol behavior when a lending pool has liquidity but no borrows .
316+ /// Verifies protocol behavior when a lending pool has liquidity but no borrowers .
305317// =============================================================================
306318access (all )
307319fun test_empty_pool () {
@@ -486,7 +498,6 @@ fun test_long_time_period_accrual() {
486498 //
487499 // debitRate = baseRate + (slope1 * utilization / optimalUtilization)
488500 // FLOW: debitRate = 0 + 0.04 * (0.2 / 0.45) = 0.01777777777 (1.77% APY)
489- let expectedFLOWDebtRate = 0.01777777
490501
491502 let detailsBefore = getPositionDetails (pid : borrowerPid , beFailed : false )
492503 let FLOWDebtBefore = getDebitBalanceForType (details : detailsBefore , vaultType : Type <@FlowToken.Vault >())
0 commit comments