From ad3cee556805e45e18ce1f255dcbec13b3c6e95b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 9 Aug 2022 10:57:03 +0200 Subject: [PATCH] ts: improve liqtest scripts --- .../src/scripts/mb-liqtest-create-group.ts | 9 +++-- .../src/scripts/mb-liqtest-make-candidates.ts | 39 +++++++++++-------- .../mb-liqtest-settle-and-close-all.ts | 17 ++------ 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/ts/client/src/scripts/mb-liqtest-create-group.ts b/ts/client/src/scripts/mb-liqtest-create-group.ts index 5339f797b..e37ad7a42 100644 --- a/ts/client/src/scripts/mb-liqtest-create-group.ts +++ b/ts/client/src/scripts/mb-liqtest-create-group.ts @@ -61,7 +61,8 @@ async function main() { console.log(`Creating stub oracle for ${name}...`); const mintPk = new PublicKey(mint); try { - await client.stubOracleCreate(group, mintPk, STUB_PRICES[name]); + const price = STUB_PRICES.get(name); + await client.stubOracleCreate(group, mintPk, price); } catch (error) { console.log(error); } @@ -89,7 +90,7 @@ async function main() { 0.88, 1.5, 0.0, - 0.0, + 0.0001, 0.9, 0.8, 1.1, @@ -120,7 +121,7 @@ async function main() { 0.9, 1.5, 0.0, - 0.0, + 0.0001, 1, 1, 1, @@ -151,7 +152,7 @@ async function main() { 0.9, 1.5, 0.0, - 0.0, + 0.0001, 0.9, 0.8, 1.1, diff --git a/ts/client/src/scripts/mb-liqtest-make-candidates.ts b/ts/client/src/scripts/mb-liqtest-make-candidates.ts index f58a627a8..8e51758cd 100644 --- a/ts/client/src/scripts/mb-liqtest-make-candidates.ts +++ b/ts/client/src/scripts/mb-liqtest-make-candidates.ts @@ -24,9 +24,11 @@ const MAINNET_MINTS = new Map([ ]); const SCENARIOS: [string, string, number, string, number][] = [ - ['LIQTEST, A: USDC, L: SOL', 'USDC', 1000 * PRICES.SOL, 'SOL', 999], - //['LIQTEST, A: SOL, L: USDC', 'SOL', 1000, 'USDC', 999 * PRICES.SOL], - //['LIQTEST, A: BTC, L: SOL', 'BTC', 20, 'SOL', 19 * PRICES.BTC / PRICES.SOL], + ['LIQTEST, LIQOR', 'USDC', 1000000, 'USDC', 0], + ['LIQTEST, A: USDC, L: SOL', 'USDC', 1000 * PRICES.SOL, 'SOL', 920], + ['LIQTEST, A: SOL, L: USDC', 'SOL', 1000, 'USDC', 920 * PRICES.SOL], + // TODO: needs the fix on liq+dust to go live + //['LIQTEST, A: BTC, L: SOL', 'BTC', 20, 'SOL', 18 * PRICES.BTC / PRICES.SOL], ]; async function main() { @@ -58,7 +60,6 @@ async function main() { admin.publicKey, ); let maxAccountNum = Math.max(...accounts.map((a) => a.accountNum)); - console.log(maxAccountNum); for (const scenario of SCENARIOS) { const [name, assetName, assetAmount, liabName, liabAmount] = scenario; @@ -83,20 +84,24 @@ async function main() { ); await mangoAccount.reload(client, group); - // temporarily drop the borrowed token value, so the borrow goes through - const oracle = group.banksMap.get(liabName).oracle; - await client.stubOracleSet(group, oracle, PRICES[liabName] / 2); + if (liabAmount > 0) { + // temporarily drop the borrowed token value, so the borrow goes through + const oracle = group.banksMap.get(liabName).oracle; + try { + await client.stubOracleSet(group, oracle, PRICES[liabName] / 2); - await client.tokenWithdrawNative( - group, - mangoAccount, - liabName, - liabAmount, - true, - ); - - // restore the oracle - await client.stubOracleSet(group, oracle, PRICES[liabName]); + await client.tokenWithdrawNative( + group, + mangoAccount, + liabName, + liabAmount, + true, + ); + } finally { + // restore the oracle + await client.stubOracleSet(group, oracle, PRICES[liabName]); + } + } } process.exit(); diff --git a/ts/client/src/scripts/mb-liqtest-settle-and-close-all.ts b/ts/client/src/scripts/mb-liqtest-settle-and-close-all.ts index 2c8ca10fc..427a70a21 100644 --- a/ts/client/src/scripts/mb-liqtest-settle-and-close-all.ts +++ b/ts/client/src/scripts/mb-liqtest-settle-and-close-all.ts @@ -34,10 +34,7 @@ async function main() { const group = await client.getGroupForCreator(admin.publicKey, GROUP_NUM); console.log(group.toString()); - let accounts = await client.getMangoAccountsForOwner( - group, - admin.publicKey, - ); + let accounts = await client.getMangoAccountsForOwner(group, admin.publicKey); for (let account of accounts) { console.log(`settling borrows on account: ${account}`); @@ -47,12 +44,7 @@ async function main() { const amount = token.native(bank).toNumber(); if (amount < 0) { try { - await client.tokenDepositNative( - group, - account, - bank.name, - amount, - ); + await client.tokenDepositNative(group, account, bank.name, amount); await account.reload(client, group); } catch (error) { console.log( @@ -63,10 +55,7 @@ async function main() { } } - accounts = await client.getMangoAccountsForOwner( - group, - admin.publicKey, - ); + accounts = await client.getMangoAccountsForOwner(group, admin.publicKey); for (let account of accounts) { console.log(`withdrawing deposits of account: ${account}`);