diff --git a/cadence/contracts/TidalProtocol.cdc b/cadence/contracts/TidalProtocol.cdc index e744adc1..fbc7b157 100644 --- a/cadence/contracts/TidalProtocol.cdc +++ b/cadence/contracts/TidalProtocol.cdc @@ -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 // The amount of the token we can take using that amount of health let availableTokenCount = availableEffectiveValue / self.collateralFactor[withdrawType]! / self.priceOracle.price(ofToken: withdrawType)! diff --git a/cadence/transactions/tidal-protocol/pool-management/repay_and_close_position.cdc b/cadence/transactions/tidal-protocol/pool-management/repay_and_close_position.cdc index 9b79c416..dd0b860e 100644 --- a/cadence/transactions/tidal-protocol/pool-management/repay_and_close_position.cdc +++ b/cadence/transactions/tidal-protocol/pool-management/repay_and_close_position.cdc @@ -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, )