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);
|
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(
|
simHealthRatioWithTokenPositionChanges(
|
||||||
group: Group,
|
group: Group,
|
||||||
nativeTokenChanges: {
|
nativeTokenChanges: {
|
||||||
|
@ -181,21 +195,15 @@ export class HealthCache {
|
||||||
healthType: HealthType = HealthType.init,
|
healthType: HealthType = HealthType.init,
|
||||||
): I80F48 {
|
): I80F48 {
|
||||||
const adjustedCache: HealthCache = _.cloneDeep(this);
|
const adjustedCache: HealthCache = _.cloneDeep(this);
|
||||||
|
// HealthCache.logHealthCache('beforeChange', adjustedCache);
|
||||||
for (const change of nativeTokenChanges) {
|
for (const change of nativeTokenChanges) {
|
||||||
const bank: Bank = group.getFirstBankByMint(change.mintPk);
|
const bank: Bank = group.getFirstBankByMint(change.mintPk);
|
||||||
const changeIndex = adjustedCache.getOrCreateTokenInfoIndex(bank);
|
const changeIndex = adjustedCache.getOrCreateTokenInfoIndex(bank);
|
||||||
adjustedCache.tokenInfos[changeIndex].balance = adjustedCache.tokenInfos[
|
adjustedCache.tokenInfos[changeIndex].balance = adjustedCache.tokenInfos[
|
||||||
changeIndex
|
changeIndex
|
||||||
].balance.add(change.nativeTokenAmount.mul(bank.price));
|
].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);
|
return adjustedCache.healthRatio(healthType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,6 +449,10 @@ export class TokenInfo {
|
||||||
: this.assetWeight(healthType)
|
: this.assetWeight(healthType)
|
||||||
).mul(this.balance);
|
).mul(this.balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return `tokenIndex: ${this.tokenIndex}, balance: ${this.balance}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Serum3Info {
|
export class Serum3Info {
|
||||||
|
|
|
@ -70,7 +70,6 @@ async function debugUser(
|
||||||
console.log(group.banksMapByName.get('SOL')[0].mint.toBase58());
|
console.log(group.banksMapByName.get('SOL')[0].mint.toBase58());
|
||||||
|
|
||||||
async function getMaxWithdrawWithBorrowForTokenUiWrapper(token) {
|
async function getMaxWithdrawWithBorrowForTokenUiWrapper(token) {
|
||||||
console.log();
|
|
||||||
console.log(
|
console.log(
|
||||||
`mangoAccount.getMaxWithdrawWithBorrowForTokenUi(group, ${token}) ` +
|
`mangoAccount.getMaxWithdrawWithBorrowForTokenUi(group, ${token}) ` +
|
||||||
mangoAccount.getMaxWithdrawWithBorrowForTokenUi(
|
mangoAccount.getMaxWithdrawWithBorrowForTokenUi(
|
||||||
|
@ -78,12 +77,12 @@ async function debugUser(
|
||||||
group.banksMapByName.get(token)[0].mint,
|
group.banksMapByName.get(token)[0].mint,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
console.log(
|
// console.log(
|
||||||
`group.getTokenVaultBalanceByMintUi ${token} ${await group.getTokenVaultBalanceByMintUi(
|
// `group.getTokenVaultBalanceByMintUi ${token} ${await group.getTokenVaultBalanceByMintUi(
|
||||||
client,
|
// client,
|
||||||
group.banksMapByName.get(token)[0].mint,
|
// group.banksMapByName.get(token)[0].mint,
|
||||||
)}`,
|
// )}`,
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
await getMaxWithdrawWithBorrowForTokenUiWrapper('SOL');
|
await getMaxWithdrawWithBorrowForTokenUiWrapper('SOL');
|
||||||
await getMaxWithdrawWithBorrowForTokenUiWrapper('MSOL');
|
await getMaxWithdrawWithBorrowForTokenUiWrapper('MSOL');
|
||||||
|
@ -98,42 +97,46 @@ async function debugUser(
|
||||||
.toNumber(),
|
.toNumber(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('sol 1 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('sol 1 ', {
|
||||||
// mintPk: group.banksMapByName.get('SOL')[0].mint,
|
mintPk: group.banksMapByName.get('SOL')[0].mint,
|
||||||
// uiTokenAmount: 1,
|
uiTokenAmount: 1,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('sol -1 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('sol -1 ', {
|
||||||
// mintPk: group.banksMapByName.get('SOL')[0].mint,
|
mintPk: group.banksMapByName.get('SOL')[0].mint,
|
||||||
// uiTokenAmount: -1,
|
uiTokenAmount: -1,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('msol 1 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('msol 1 ', {
|
||||||
// mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
||||||
// uiTokenAmount: 1,
|
uiTokenAmount: 1,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('msol -1 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('msol -1 ', {
|
||||||
// mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
mintPk: group.banksMapByName.get('MSOL')[0].mint,
|
||||||
// uiTokenAmount: -1,
|
uiTokenAmount: -1,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('usdc 10 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('btc 0.001 ', {
|
||||||
// mintPk: group.banksMapByName.get('USDC')[0].mint,
|
mintPk: group.banksMapByName.get('BTC')[0].mint,
|
||||||
// uiTokenAmount: 10,
|
uiTokenAmount: 0.001,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('usdc -10 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('btc -0.001 ', {
|
||||||
// mintPk: group.banksMapByName.get('USDC')[0].mint,
|
mintPk: group.banksMapByName.get('BTC')[0].mint,
|
||||||
// uiTokenAmount: -10,
|
uiTokenAmount: -0.001,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('btc 0.001 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('usdc 10 ', {
|
||||||
// mintPk: group.banksMapByName.get('BTC')[0].mint,
|
mintPk: group.banksMapByName.get('USDC')[0].mint,
|
||||||
// uiTokenAmount: 0.001,
|
uiTokenAmount: 10,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('btc -0.001 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('usdc -10 ', {
|
||||||
// mintPk: group.banksMapByName.get('BTC')[0].mint,
|
mintPk: group.banksMapByName.get('USDC')[0].mint,
|
||||||
// uiTokenAmount: -0.001,
|
uiTokenAmount: -10,
|
||||||
// });
|
});
|
||||||
// simHealthRatioWithTokenPositionChangesWrapper('soETH -0.001 ', {
|
simHealthRatioWithTokenPositionChangesWrapper('soETH 0.001 ', {
|
||||||
// mintPk: group.banksMapByName.get('soETH')[0].mint,
|
mintPk: group.banksMapByName.get('soETH')[0].mint,
|
||||||
// uiTokenAmount: -0.001,
|
uiTokenAmount: 0.001,
|
||||||
// });
|
});
|
||||||
|
simHealthRatioWithTokenPositionChangesWrapper('soETH -0.001 ', {
|
||||||
|
mintPk: group.banksMapByName.get('soETH')[0].mint,
|
||||||
|
uiTokenAmount: -0.001,
|
||||||
|
});
|
||||||
|
|
||||||
function getMaxSourceForTokenSwapWrapper(src, tgt) {
|
function getMaxSourceForTokenSwapWrapper(src, tgt) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|
Loading…
Reference in New Issue