Fix spot order cancellation

This commit is contained in:
Riordan Panayides 2022-05-06 12:59:15 +01:00
parent 3594cc0d8d
commit 14eee32799
2 changed files with 17 additions and 19 deletions

View File

@ -603,10 +603,11 @@ async function liquidateAccount(
}
for (let r = 0; r < 5 && liqee.hasAnySpotOrders(); r++) {
for (let i = 0; i < mangoGroup.spotMarkets.length; i++) {
for (let i = 0; i < groupIds.spotMarkets.length; i++) {
if (liqee.inMarginBasket[i]) {
const spotMarket = spotMarkets[i];
const baseRootBank = rootBanks[i];
const spotMarketConfig = groupIds.spotMarkets[i];
const spotMarket = spotMarkets[spotMarketConfig.marketIndex];
const baseRootBank = rootBanks[spotMarketConfig.marketIndex];
const quoteRootBank = rootBanks[QUOTE_INDEX];
if (baseRootBank && quoteRootBank) {
@ -1057,6 +1058,7 @@ async function balanceAccount(
spotMarkets: Market[],
perpMarkets: PerpMarket[],
) {
return;
if (Date.now() < lastRebalance + rebalanceInterval) {
return;
}

View File

@ -14,11 +14,7 @@ import {
QUOTE_INDEX,
IDS,
} from '@blockworks-foundation/mango-client';
import {
Account,
Commitment,
Connection,
} from '@solana/web3.js';
import { Account, Commitment, Connection, Keypair } from '@solana/web3.js';
import { Market } from '@project-serum/serum';
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
import { spawn } from 'child_process';
@ -28,13 +24,12 @@ async function testPerpLiquidationAndBankruptcy() {
const cluster = (process.env.CLUSTER || 'devnet') as Cluster;
const config = new Config(IDS);
const keypairPath = os.homedir() + '/.config/solana/devnet.json';
const payer = new Account(
JSON.parse(
process.env.KEYPAIR ||
fs.readFileSync(keypairPath, 'utf-8'),
const payer = Keypair.fromSecretKey(
new Uint8Array(
JSON.parse(process.env.KEYPAIR || fs.readFileSync(keypairPath, 'utf-8')),
),
);
const connection = new Connection(
config.cluster_urls[cluster],
'processed' as Commitment,
@ -75,7 +70,7 @@ async function testPerpLiquidationAndBankruptcy() {
env: {
CLUSTER: 'devnet',
GROUP: 'devnet.3',
PATH: process.env.PATH
PATH: process.env.PATH,
},
});
// keeper.stdout.on('data', (data) => {
@ -97,7 +92,7 @@ async function testPerpLiquidationAndBankruptcy() {
env: {
CLUSTER: 'devnet',
GROUP: 'devnet.3',
PATH: process.env.PATH
PATH: process.env.PATH,
},
});
@ -139,21 +134,21 @@ async function testPerpLiquidationAndBankruptcy() {
payer.publicKey,
);
const liqorPk = await client.initMangoAccount(mangoGroup, payer);
const liqorPk = (await client.initMangoAccount(mangoGroup, payer))!;
const liqorAccount = await client.getMangoAccount(
liqorPk,
mangoGroup.dexProgramId,
);
console.log('Created Liqor:', liqorPk.toBase58());
const liqeePk = await client.initMangoAccount(mangoGroup, payer);
const liqeePk = (await client.initMangoAccount(mangoGroup, payer))!;
const liqeeAccount = await client.getMangoAccount(
liqeePk,
mangoGroup.dexProgramId,
);
console.log('Created Liqee:', liqeePk.toBase58());
const makerPk = await client.initMangoAccount(mangoGroup, payer);
const makerPk = (await client.initMangoAccount(mangoGroup, payer))!;
const makerAccount = await client.getMangoAccount(
makerPk,
mangoGroup.dexProgramId,
@ -301,7 +296,8 @@ async function testPerpLiquidationAndBankruptcy() {
GROUP: 'devnet.3',
KEYPAIR: keypairPath,
LIQOR_PK: liqorAccount.publicKey.toBase58(),
PATH: process.env.PATH
ENDPOINT_URL: config.cluster_urls[cluster],
PATH: process.env.PATH,
},
});