Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion cadence/contracts/TidalProtocol.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,9 @@ access(all) contract TidalProtocol {
// We will hit the health target before using up all of the withdraw token credit. We can easily
// compute how many units of the token would bring the position down to the target health.
let availableHealth = healthAfterDeposit - targetHealth
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.


// The amount of the token we can take using that amount of health
let availableTokenCount = availableEffectiveValue / self.collateralFactor[withdrawType]! / self.priceOracle.price(ofToken: withdrawType)!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ transaction(positionWrapperPath: StoragePath) {

let withdrawnVault <- positionRef.withdrawAndPull(
type: Type<@FlowToken.Vault>(),
amount: 1000.0, // should be using `positionRef.availableBalance(type: Type<@FlowToken.Vault>(), pullFromTopUpSource: true), but this for some reason returns 0
amount: positionRef.availableBalance(type: Type<@FlowToken.Vault>(), pullFromTopUpSource: true),
pullFromTopUpSource: true,
)

Expand Down