Improve scripts for making a liquidation candidate

This commit is contained in:
Christian Kamm 2022-07-14 14:37:47 +02:00
parent 50f9eb6913
commit 45f3e26386
3 changed files with 39 additions and 37 deletions

View File

@ -210,7 +210,7 @@ export class MangoAccount {
const inUsdcUnits = MangoAccount.getEquivalentNativeUsdcPosition(
bank,
this.findToken(bank.tokenIndex),
);
).max(ZERO_I80F48);
const newInitHealth = initHealth.sub(inUsdcUnits.mul(bank.initAssetWeight));
return MangoAccount.getEquivalentNativeTokenPosition(
bank,

View File

@ -83,7 +83,7 @@ async function main() {
0.9,
0.88,
0.0005,
1.5,
0.0005,
0.8,
0.6,
1.2,
@ -122,7 +122,7 @@ async function main() {
0.9,
1.5,
0.0005,
1.5,
0.0005,
0.8,
0.6,
1.2,
@ -151,7 +151,7 @@ async function main() {
0.9,
0.63,
0.0005,
1.5,
0.0005,
0.8,
0.6,
1.2,
@ -182,7 +182,7 @@ async function main() {
0.9,
0.63,
0.0005,
1.5,
0.0005,
0.8,
0.6,
1.2,
@ -306,11 +306,11 @@ async function main() {
0.9,
1.5,
0.0005,
1.5,
0.8,
0.6,
1.2,
1.4,
0.0005,
1.0,
1.0,
1.0,
1.0,
0.02,
);
console.log(`https://explorer.solana.com/tx/${sig}?cluster=devnet`);

View File

@ -76,33 +76,9 @@ async function main() {
);
console.log(`...mangoAccount2 ${user2MangoAccount.publicKey}`);
/// user2 deposits some collateral and borrows BTC
console.log(`Depositing...${300} 'USDC'`);
await user2Client.tokenDeposit(group, user2MangoAccount, 'USDC', 300);
await user2MangoAccount.reload(user2Client, group);
console.log(`${user2MangoAccount.toString(group)}`);
amount = amount / 10;
while (true) {
try {
console.log(`Withdrawing...${amount} 'BTC'`);
await user2Client.tokenWithdraw(
group,
user2MangoAccount,
token,
amount,
true,
);
} catch (error) {
console.log(error);
break;
}
}
await user2MangoAccount.reload(user2Client, group);
console.log(`${user2MangoAccount.toString(group)}`);
/// Reduce usdc price
/// Increase usdc price temporarily to allow lots of borrows
console.log(
`Setting USDC price to 0.9, to reduce health contribution of USDC collateral for user`,
`Setting USDC price to 1.5, to allow the user to borrow lots of btc`,
);
const adminWallet = new Wallet(admin);
console.log(`Admin ${adminWallet.publicKey.toBase58()}`);
@ -112,7 +88,33 @@ async function main() {
'devnet',
MANGO_V4_ID['devnet'],
);
await client.stubOracleSet(group, group.banksMap.get('USDC')?.oracle!, 0.5);
await client.stubOracleSet(group, group.banksMap.get('USDC')?.oracle!, 1.5);
/// user2 deposits some collateral and borrows BTC
amount = 1;
console.log(`Depositing...${amount} 'USDC'`);
await user2Client.tokenDeposit(group, user2MangoAccount, 'USDC', amount);
await user2MangoAccount.reload(user2Client, group);
console.log(`${user2MangoAccount.toString(group)}`);
const maxNative = await (await user2MangoAccount.getMaxWithdrawWithBorrowForToken(group, token)).toNumber();
amount = 0.9 * maxNative;
console.log(`Withdrawing...${amount} native BTC'`);
await user2Client.tokenWithdraw2(
group,
user2MangoAccount,
token,
amount,
true,
);
await user2MangoAccount.reload(user2Client, group);
console.log(`${user2MangoAccount.toString(group)}`);
/// Reduce usdc price to normal again
console.log(
`Setting USDC price back to 1.0, decreasing the user's collateral size`,
);
await client.stubOracleSet(group, group.banksMap.get('USDC')?.oracle!, 1.0);
process.exit();
}