From 54020120641e0cc4400700c17b5f4e3e19a98dda Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Thu, 11 Aug 2022 17:59:49 +0200 Subject: [PATCH] apply loan origination fee buffer Signed-off-by: microwavedcola1 --- ts/client/src/accounts/healthCache.ts | 9 ++++++++- ts/client/src/accounts/mangoAccount.ts | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ts/client/src/accounts/healthCache.ts b/ts/client/src/accounts/healthCache.ts index dd763ee58..1c15650e5 100644 --- a/ts/client/src/accounts/healthCache.ts +++ b/ts/client/src/accounts/healthCache.ts @@ -5,6 +5,7 @@ import { I80F48, I80F48Dto, MAX_I80F48, + ONE_I80F48, ZERO_I80F48, } from './I80F48'; import { HealthType } from './mangoAccount'; @@ -312,7 +313,13 @@ export class HealthCache { ); } - return amount.div(source.oraclePrice); + return amount + .div(source.oraclePrice) + .mul( + ONE_I80F48.sub( + group.banksMap.get(sourceTokenName).loanOriginationFeeRate, + ), + ); } } diff --git a/ts/client/src/accounts/mangoAccount.ts b/ts/client/src/accounts/mangoAccount.ts index ade05e7e9..e4552d16e 100644 --- a/ts/client/src/accounts/mangoAccount.ts +++ b/ts/client/src/accounts/mangoAccount.ts @@ -218,9 +218,10 @@ export class MangoAccount { } /** - * The amount of given source native token you can swap to a target token considering all existing assets as collateral. - * note: slippageAndFeesFactor is a normalized number, <1, e.g. a slippage of 5% and some fees which are 1%, then slippageAndFeesFactor = 0.94 - * the factor is used to compute how much target can be obtained by swapping source TODO: loan origination fees + * The max amount of given source native token you can swap to a target token. + * note: slippageAndFeesFactor is a normalized number, <1, + * e.g. a slippage of 5% and some fees which are 1%, then slippageAndFeesFactor = 0.94 + * the factor is used to compute how much target can be obtained by swapping source */ getMaxSourceForTokenSwap( group: Group,