From f7e6d6469f2e55ec5f1b1fe5c4d039108a636492 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 10 May 2023 11:18:46 +0200 Subject: [PATCH] Increase iterations for max swap to fix some edge case, fix debug script since fees are already accounted for Signed-off-by: microwavedcola1 --- ts/client/scripts/archive/debug-user.ts | 11 ++++------- ts/client/src/accounts/healthCache.ts | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/ts/client/scripts/archive/debug-user.ts b/ts/client/scripts/archive/debug-user.ts index cdc21d1ed..dd3f6d490 100644 --- a/ts/client/scripts/archive/debug-user.ts +++ b/ts/client/scripts/archive/debug-user.ts @@ -111,22 +111,19 @@ async function debugUser( console.log(`Error for ${src}->${tgt}, ` + error.toString()); } - const maxSourceWoFees = - -maxSourceUi * - (1 + group.banksMapByName.get(src)![0].loanOriginationFeeRate.toNumber()); - const maxTargetWoFees = - -maxSourceWoFees * + const maxTargetUi = + maxSourceUi * (group.banksMapByName.get(src)![0].uiPrice / group.banksMapByName.get(tgt)![0].uiPrice); const sim = mangoAccount.simHealthRatioWithTokenPositionUiChanges(group, [ { mintPk: group.banksMapByName.get(src)![0].mint, - uiTokenAmount: maxSourceWoFees, + uiTokenAmount: -maxSourceUi, }, { mintPk: group.banksMapByName.get(tgt)![0].mint, - uiTokenAmount: maxTargetWoFees, + uiTokenAmount: maxTargetUi, }, ]); console.log( diff --git a/ts/client/src/accounts/healthCache.ts b/ts/client/src/accounts/healthCache.ts index 885717970..59fb553ca 100644 --- a/ts/client/src/accounts/healthCache.ts +++ b/ts/client/src/accounts/healthCache.ts @@ -559,7 +559,7 @@ export class HealthCache { target: I80F48, fun: (amount: I80F48) => I80F48, ): I80F48 { - const maxIterations = 20; + const maxIterations = 50; let current = start; // console.log(`scanRightUntilLessThan, start ${start.toLocaleString()}`); for (const key of Array(maxIterations).fill(0).keys()) {