From 4ee4ab829fe1f48909b78a79ec0a2d52b2f90002 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Mon, 15 Aug 2022 20:23:51 +0200 Subject: [PATCH] more defensive coding Signed-off-by: microwavedcola1 --- ts/client/src/accounts/healthCache.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ts/client/src/accounts/healthCache.ts b/ts/client/src/accounts/healthCache.ts index 041723fd8..766d4b9f6 100644 --- a/ts/client/src/accounts/healthCache.ts +++ b/ts/client/src/accounts/healthCache.ts @@ -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).