more defensive coding

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-08-15 20:23:51 +02:00
parent da93f1118e
commit 4ee4ab829f
1 changed files with 9 additions and 0 deletions

View File

@ -204,6 +204,15 @@ export class HealthCache {
return ZERO_I80F48;
}
if (
sourceBank.initLiabWeight
.sub(targetBank.initAssetWeight)
.abs()
.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).