ts: improve liqtest scripts
This commit is contained in:
parent
222358ff14
commit
ad3cee5568
|
@ -61,7 +61,8 @@ async function main() {
|
||||||
console.log(`Creating stub oracle for ${name}...`);
|
console.log(`Creating stub oracle for ${name}...`);
|
||||||
const mintPk = new PublicKey(mint);
|
const mintPk = new PublicKey(mint);
|
||||||
try {
|
try {
|
||||||
await client.stubOracleCreate(group, mintPk, STUB_PRICES[name]);
|
const price = STUB_PRICES.get(name);
|
||||||
|
await client.stubOracleCreate(group, mintPk, price);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +90,7 @@ async function main() {
|
||||||
0.88,
|
0.88,
|
||||||
1.5,
|
1.5,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0001,
|
||||||
0.9,
|
0.9,
|
||||||
0.8,
|
0.8,
|
||||||
1.1,
|
1.1,
|
||||||
|
@ -120,7 +121,7 @@ async function main() {
|
||||||
0.9,
|
0.9,
|
||||||
1.5,
|
1.5,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0001,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
|
@ -151,7 +152,7 @@ async function main() {
|
||||||
0.9,
|
0.9,
|
||||||
1.5,
|
1.5,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0001,
|
||||||
0.9,
|
0.9,
|
||||||
0.8,
|
0.8,
|
||||||
1.1,
|
1.1,
|
||||||
|
|
|
@ -24,9 +24,11 @@ const MAINNET_MINTS = new Map([
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const SCENARIOS: [string, string, number, string, number][] = [
|
const SCENARIOS: [string, string, number, string, number][] = [
|
||||||
['LIQTEST, A: USDC, L: SOL', 'USDC', 1000 * PRICES.SOL, 'SOL', 999],
|
['LIQTEST, LIQOR', 'USDC', 1000000, 'USDC', 0],
|
||||||
//['LIQTEST, A: SOL, L: USDC', 'SOL', 1000, 'USDC', 999 * PRICES.SOL],
|
['LIQTEST, A: USDC, L: SOL', 'USDC', 1000 * PRICES.SOL, 'SOL', 920],
|
||||||
//['LIQTEST, A: BTC, L: SOL', 'BTC', 20, 'SOL', 19 * PRICES.BTC / PRICES.SOL],
|
['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() {
|
async function main() {
|
||||||
|
@ -58,7 +60,6 @@ async function main() {
|
||||||
admin.publicKey,
|
admin.publicKey,
|
||||||
);
|
);
|
||||||
let maxAccountNum = Math.max(...accounts.map((a) => a.accountNum));
|
let maxAccountNum = Math.max(...accounts.map((a) => a.accountNum));
|
||||||
console.log(maxAccountNum);
|
|
||||||
|
|
||||||
for (const scenario of SCENARIOS) {
|
for (const scenario of SCENARIOS) {
|
||||||
const [name, assetName, assetAmount, liabName, liabAmount] = scenario;
|
const [name, assetName, assetAmount, liabName, liabAmount] = scenario;
|
||||||
|
@ -83,20 +84,24 @@ async function main() {
|
||||||
);
|
);
|
||||||
await mangoAccount.reload(client, group);
|
await mangoAccount.reload(client, group);
|
||||||
|
|
||||||
// temporarily drop the borrowed token value, so the borrow goes through
|
if (liabAmount > 0) {
|
||||||
const oracle = group.banksMap.get(liabName).oracle;
|
// temporarily drop the borrowed token value, so the borrow goes through
|
||||||
await client.stubOracleSet(group, oracle, PRICES[liabName] / 2);
|
const oracle = group.banksMap.get(liabName).oracle;
|
||||||
|
try {
|
||||||
|
await client.stubOracleSet(group, oracle, PRICES[liabName] / 2);
|
||||||
|
|
||||||
await client.tokenWithdrawNative(
|
await client.tokenWithdrawNative(
|
||||||
group,
|
group,
|
||||||
mangoAccount,
|
mangoAccount,
|
||||||
liabName,
|
liabName,
|
||||||
liabAmount,
|
liabAmount,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
} finally {
|
||||||
// restore the oracle
|
// restore the oracle
|
||||||
await client.stubOracleSet(group, oracle, PRICES[liabName]);
|
await client.stubOracleSet(group, oracle, PRICES[liabName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
|
|
|
@ -34,10 +34,7 @@ async function main() {
|
||||||
const group = await client.getGroupForCreator(admin.publicKey, GROUP_NUM);
|
const group = await client.getGroupForCreator(admin.publicKey, GROUP_NUM);
|
||||||
console.log(group.toString());
|
console.log(group.toString());
|
||||||
|
|
||||||
let accounts = await client.getMangoAccountsForOwner(
|
let accounts = await client.getMangoAccountsForOwner(group, admin.publicKey);
|
||||||
group,
|
|
||||||
admin.publicKey,
|
|
||||||
);
|
|
||||||
for (let account of accounts) {
|
for (let account of accounts) {
|
||||||
console.log(`settling borrows on account: ${account}`);
|
console.log(`settling borrows on account: ${account}`);
|
||||||
|
|
||||||
|
@ -47,12 +44,7 @@ async function main() {
|
||||||
const amount = token.native(bank).toNumber();
|
const amount = token.native(bank).toNumber();
|
||||||
if (amount < 0) {
|
if (amount < 0) {
|
||||||
try {
|
try {
|
||||||
await client.tokenDepositNative(
|
await client.tokenDepositNative(group, account, bank.name, amount);
|
||||||
group,
|
|
||||||
account,
|
|
||||||
bank.name,
|
|
||||||
amount,
|
|
||||||
);
|
|
||||||
await account.reload(client, group);
|
await account.reload(client, group);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -63,10 +55,7 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accounts = await client.getMangoAccountsForOwner(
|
accounts = await client.getMangoAccountsForOwner(group, admin.publicKey);
|
||||||
group,
|
|
||||||
admin.publicKey,
|
|
||||||
);
|
|
||||||
for (let account of accounts) {
|
for (let account of accounts) {
|
||||||
console.log(`withdrawing deposits of account: ${account}`);
|
console.log(`withdrawing deposits of account: ${account}`);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue