Increase iterations for max swap to fix some edge case, fix debug script since fees are already accounted for

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-05-10 11:18:46 +02:00
parent 566a369ffc
commit f7e6d6469f
2 changed files with 5 additions and 8 deletions

View File

@ -111,22 +111,19 @@ async function debugUser(
console.log(`Error for ${src}->${tgt}, ` + error.toString()); console.log(`Error for ${src}->${tgt}, ` + error.toString());
} }
const maxSourceWoFees = const maxTargetUi =
-maxSourceUi * maxSourceUi *
(1 + group.banksMapByName.get(src)![0].loanOriginationFeeRate.toNumber());
const maxTargetWoFees =
-maxSourceWoFees *
(group.banksMapByName.get(src)![0].uiPrice / (group.banksMapByName.get(src)![0].uiPrice /
group.banksMapByName.get(tgt)![0].uiPrice); group.banksMapByName.get(tgt)![0].uiPrice);
const sim = mangoAccount.simHealthRatioWithTokenPositionUiChanges(group, [ const sim = mangoAccount.simHealthRatioWithTokenPositionUiChanges(group, [
{ {
mintPk: group.banksMapByName.get(src)![0].mint, mintPk: group.banksMapByName.get(src)![0].mint,
uiTokenAmount: maxSourceWoFees, uiTokenAmount: -maxSourceUi,
}, },
{ {
mintPk: group.banksMapByName.get(tgt)![0].mint, mintPk: group.banksMapByName.get(tgt)![0].mint,
uiTokenAmount: maxTargetWoFees, uiTokenAmount: maxTargetUi,
}, },
]); ]);
console.log( console.log(

View File

@ -559,7 +559,7 @@ export class HealthCache {
target: I80F48, target: I80F48,
fun: (amount: I80F48) => I80F48, fun: (amount: I80F48) => I80F48,
): I80F48 { ): I80F48 {
const maxIterations = 20; const maxIterations = 50;
let current = start; let current = start;
// console.log(`scanRightUntilLessThan, start ${start.toLocaleString()}`); // console.log(`scanRightUntilLessThan, start ${start.toLocaleString()}`);
for (const key of Array(maxIterations).fill(0).keys()) { for (const key of Array(maxIterations).fill(0).keys()) {