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 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]) { if (liqee.inMarginBasket[i]) {
const spotMarket = spotMarkets[i]; const spotMarketConfig = groupIds.spotMarkets[i];
const baseRootBank = rootBanks[i]; const spotMarket = spotMarkets[spotMarketConfig.marketIndex];
const baseRootBank = rootBanks[spotMarketConfig.marketIndex];
const quoteRootBank = rootBanks[QUOTE_INDEX]; const quoteRootBank = rootBanks[QUOTE_INDEX];
if (baseRootBank && quoteRootBank) { if (baseRootBank && quoteRootBank) {
@ -1057,6 +1058,7 @@ async function balanceAccount(
spotMarkets: Market[], spotMarkets: Market[],
perpMarkets: PerpMarket[], perpMarkets: PerpMarket[],
) { ) {
return;
if (Date.now() < lastRebalance + rebalanceInterval) { if (Date.now() < lastRebalance + rebalanceInterval) {
return; return;
} }

View File

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