ts: improve liqtest scripts

This commit is contained in:
Christian Kamm 2022-08-09 10:57:03 +02:00
parent 222358ff14
commit ad3cee5568
3 changed files with 30 additions and 35 deletions

View File

@ -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,

View File

@ -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();

View File

@ -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}`);