diff --git a/ts/client/src/accounts/healthCache.ts b/ts/client/src/accounts/healthCache.ts index 38452c82f..041723fd8 100644 --- a/ts/client/src/accounts/healthCache.ts +++ b/ts/client/src/accounts/healthCache.ts @@ -196,6 +196,14 @@ export class HealthCache { const sourceBank = group.banksMap.get(sourceTokenName); const targetBank = group.banksMap.get(targetTokenName); + if (sourceTokenName === targetTokenName) { + return ZERO_I80F48; + } + + if (!sourceBank.price || sourceBank.price.lte(ZERO_I80F48)) { + return ZERO_I80F48; + } + // The health_ratio is a nonlinear based on swap amount. // For large swap amounts the slope is guaranteed to be negative, but small amounts // can have positive slope (e.g. using source deposits to pay back target borrows). diff --git a/ts/client/src/accounts/mangoAccount.ts b/ts/client/src/accounts/mangoAccount.ts index cdc1502d2..9043db788 100644 --- a/ts/client/src/accounts/mangoAccount.ts +++ b/ts/client/src/accounts/mangoAccount.ts @@ -234,10 +234,6 @@ export class MangoAccount { targetTokenName: string, slippageAndFeesFactor: number, ): I80F48 { - if (sourceTokenName === targetTokenName) { - return ZERO_I80F48; - } - return this.accountData.healthCache .getMaxSourceForTokenSwap( group,