Skip to content

Comments

Kan/fix available balance calculation#18

Merged
kgrgpg merged 2 commits intocadence-testing-patterns-forkfrom
kan/fix-available-balance-calculation
Jun 20, 2025
Merged

Kan/fix available balance calculation#18
kgrgpg merged 2 commits intocadence-testing-patterns-forkfrom
kan/fix-available-balance-calculation

Conversation

@Kay-Zee
Copy link
Member

@Kay-Zee Kay-Zee commented Jun 19, 2025

This handles the case where the effective debt is zero (i.e. we can pay off the entire debt), therefore the entire collateral should be available for withrdaw

let availableEffectiveValue = availableHealth * effectiveDebtAfterDeposit

// If there is no debt, then we can just use the entire collateral amount
let availableEffectiveValue = effectiveDebtAfterDeposit == 0.0 ? effectiveCollateralAfterDeposit : availableHealth * effectiveDebtAfterDeposit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently just using effectiveCollateralAfterDeposit for the case where effectiveDebtAfterDeposit is 0.0, due to this causing issues with the equation if we actually use 0 in the equation below.

kgrgpg added a commit that referenced this pull request Jun 20, 2025
- Tests that when a position has no debt, availableBalance() returns full collateral amount
- Regression test for the bug where zero debt positions couldn't withdraw (availableBalance returned 0)
- Verifies the conditional logic: when effectiveDebtAfterDeposit == 0.0, use effectiveCollateralAfterDeposit
@kgrgpg kgrgpg merged commit 68b0c09 into cadence-testing-patterns-fork Jun 20, 2025
1 check passed
@kgrgpg kgrgpg deleted the kan/fix-available-balance-calculation branch June 20, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants