From 14eee32799a7e88ce285d31559df48972b7809cd Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Fri, 6 May 2022 12:59:15 +0100 Subject: [PATCH] Fix spot order cancellation --- src/liquidator.ts | 8 +++++--- test/liquidator.test.ts | 28 ++++++++++++---------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/liquidator.ts b/src/liquidator.ts index 31f51b4..3f84a50 100644 --- a/src/liquidator.ts +++ b/src/liquidator.ts @@ -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; } diff --git a/test/liquidator.test.ts b/test/liquidator.test.ts index 6b58942..53dd3cb 100644 --- a/test/liquidator.test.ts +++ b/test/liquidator.test.ts @@ -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, }, });