defensive code

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-08-15 20:19:09 +02:00
parent 20c915f0ee
commit da93f1118e
2 changed files with 8 additions and 4 deletions

View File

@ -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).

View File

@ -234,10 +234,6 @@ export class MangoAccount {
targetTokenName: string,
slippageAndFeesFactor: number,
): I80F48 {
if (sourceTokenName === targetTokenName) {
return ZERO_I80F48;
}
return this.accountData.healthCache
.getMaxSourceForTokenSwap(
group,