fix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
7f2fb0c04c
commit
7321df31be
|
@ -172,6 +172,20 @@ export class HealthCache {
|
|||
return this.findTokenInfoIndex(bank.tokenIndex);
|
||||
}
|
||||
|
||||
private static logHealthCache(debug: string, healthCache: HealthCache) {
|
||||
console.log(debug);
|
||||
for (const token of healthCache.tokenInfos.sort(
|
||||
(a, b) => a.tokenIndex - b.tokenIndex,
|
||||
)) {
|
||||
console.log(`${token.toString()}`);
|
||||
}
|
||||
console.log(
|
||||
`assets ${healthCache.assets(HealthType.init)}, liabs ${healthCache.liabs(
|
||||
HealthType.init,
|
||||
)}, `,
|
||||
);
|
||||
}
|
||||
|
||||
simHealthRatioWithTokenPositionChanges(
|
||||
group: Group,
|
||||
nativeTokenChanges: {
|
||||
|
@ -181,21 +195,15 @@ export class HealthCache {
|
|||
healthType: HealthType = HealthType.init,
|
||||
): I80F48 {
|
||||
const adjustedCache: HealthCache = _.cloneDeep(this);
|
||||
// HealthCache.logHealthCache('beforeChange', adjustedCache);
|
||||
for (const change of nativeTokenChanges) {
|
||||
const bank: Bank = group.getFirstBankByMint(change.mintPk);
|
||||
const changeIndex = adjustedCache.getOrCreateTokenInfoIndex(bank);
|
||||
adjustedCache.tokenInfos[changeIndex].balance = adjustedCache.tokenInfos[
|
||||
changeIndex
|
||||
].balance.add(change.nativeTokenAmount.mul(bank.price));
|
||||
console.log(' ');
|
||||
console.log(`change.mintPk ${change.mintPk.toBase58()}`);
|
||||
console.log(`changeIndex ${changeIndex}`);
|
||||
console.log(
|
||||
`adjustedCache.tokenInfos[changeIndex].balance ${adjustedCache.tokenInfos[
|
||||
changeIndex
|
||||
].balance.toNumber()}`,
|
||||
);
|
||||
}
|
||||
// HealthCache.logHealthCache('afterChange', adjustedCache);
|
||||
return adjustedCache.healthRatio(healthType);
|
||||
}
|
||||
|
||||
|
@ -441,6 +449,10 @@ export class TokenInfo {
|
|||
: this.assetWeight(healthType)
|
||||
).mul(this.balance);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `tokenIndex: ${this.tokenIndex}, balance: ${this.balance}`;
|
||||
}
|
||||
}
|
||||
|
||||
export class Serum3Info {
|
||||
|
|
|
@ -70,7 +70,6 @@ async function debugUser(
|
|||
console.log(group.banksMapByName.get('SOL')[0].mint.toBase58());
|
||||
|
||||
async function getMaxWithdrawWithBorrowForTokenUiWrapper(token) {
|
||||
console.log();
|
||||
console.log(
|
||||
`mangoAccount.getMaxWithdrawWithBorrowForTokenUi(group, ${token}) ` +
|
||||
mangoAccount.getMaxWithdrawWithBorrowForTokenUi(
|
||||
|
@ -78,12 +77,12 @@ async function debugUser(
|
|||
group.banksMapByName.get(token)[0].mint,
|
||||
),
|
||||
);
|
||||
console.log(
|
||||
`group.getTokenVaultBalanceByMintUi ${token} ${await group.getTokenVaultBalanceByMintUi(
|
||||
client,
|
||||
group.banksMapByName.get(token)[0].mint,
|
||||
)}`,
|
||||
);
|
||||
// console.log(
|
||||
// `group.getTokenVaultBalanceByMintUi ${token} ${await group.getTokenVaultBalanceByMintUi(
|
||||
// client,
|
||||
// group.banksMapByName.get(token)[0].mint,
|
||||
// )}`,
|
||||
// );
|
||||
}
|
||||
await getMaxWithdrawWithBorrowForTokenUiWrapper('SOL');
|
||||
await getMaxWithdrawWithBorrowForTokenUiWrapper('MSOL');
|
||||
|
@ -98,42 +97,46 @@ async function debugUser(
|
|||
.toNumber(),
|
||||
);
|
||||
}
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('sol 1 ', {
|
||||
// mintPk: group.banksMapByName.get('SOL')[0].mint,
|
||||
// uiTokenAmount: 1,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('sol -1 ', {
|
||||
// mintPk: group.banksMapByName.get('SOL')[0].mint,
|
||||
// uiTokenAmount: -1,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('msol 1 ', {
|
||||
// mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
||||
// uiTokenAmount: 1,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('msol -1 ', {
|
||||
// mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
||||
// uiTokenAmount: -1,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('usdc 10 ', {
|
||||
// mintPk: group.banksMapByName.get('USDC')[0].mint,
|
||||
// uiTokenAmount: 10,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('usdc -10 ', {
|
||||
// mintPk: group.banksMapByName.get('USDC')[0].mint,
|
||||
// uiTokenAmount: -10,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('btc 0.001 ', {
|
||||
// mintPk: group.banksMapByName.get('BTC')[0].mint,
|
||||
// uiTokenAmount: 0.001,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('btc -0.001 ', {
|
||||
// mintPk: group.banksMapByName.get('BTC')[0].mint,
|
||||
// uiTokenAmount: -0.001,
|
||||
// });
|
||||
// simHealthRatioWithTokenPositionChangesWrapper('soETH -0.001 ', {
|
||||
// mintPk: group.banksMapByName.get('soETH')[0].mint,
|
||||
// uiTokenAmount: -0.001,
|
||||
// });
|
||||
simHealthRatioWithTokenPositionChangesWrapper('sol 1 ', {
|
||||
mintPk: group.banksMapByName.get('SOL')[0].mint,
|
||||
uiTokenAmount: 1,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('sol -1 ', {
|
||||
mintPk: group.banksMapByName.get('SOL')[0].mint,
|
||||
uiTokenAmount: -1,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('msol 1 ', {
|
||||
mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
||||
uiTokenAmount: 1,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('msol -1 ', {
|
||||
mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
||||
uiTokenAmount: -1,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('btc 0.001 ', {
|
||||
mintPk: group.banksMapByName.get('BTC')[0].mint,
|
||||
uiTokenAmount: 0.001,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('btc -0.001 ', {
|
||||
mintPk: group.banksMapByName.get('BTC')[0].mint,
|
||||
uiTokenAmount: -0.001,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('usdc 10 ', {
|
||||
mintPk: group.banksMapByName.get('USDC')[0].mint,
|
||||
uiTokenAmount: 10,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('usdc -10 ', {
|
||||
mintPk: group.banksMapByName.get('USDC')[0].mint,
|
||||
uiTokenAmount: -10,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('soETH 0.001 ', {
|
||||
mintPk: group.banksMapByName.get('soETH')[0].mint,
|
||||
uiTokenAmount: 0.001,
|
||||
});
|
||||
simHealthRatioWithTokenPositionChangesWrapper('soETH -0.001 ', {
|
||||
mintPk: group.banksMapByName.get('soETH')[0].mint,
|
||||
uiTokenAmount: -0.001,
|
||||
});
|
||||
|
||||
function getMaxSourceForTokenSwapWrapper(src, tgt) {
|
||||
console.log(
|
||||
|
|
Loading…
Reference in New Issue