Add better error handling for missing openOrders accounts, make readme more helpful
This commit is contained in:
parent
ffa4b39091
commit
caba812668
|
@ -1,6 +1,14 @@
|
|||
# Mango Liquidator
|
||||
|
||||
## Setup Partial Liquidator
|
||||
### Prerequisites
|
||||
To run the liquidator you will need:
|
||||
* A Solana account with some SOL deposited to cover transaction fees
|
||||
* Token accounts for each currency in the Mango Group (e.g. BTC, ETH, USDT)
|
||||
* Roughly equal deposits for each token. You will need base currencies to liquidate shorts, and quote currency to liquidate longs.
|
||||
* Serum Dex OpenOrders accounts associated with your account. This is required for balance wallets functionality.
|
||||
* The easiest way to set these up is by placing an order on Serum Dex for each currency pair then immediately cancelling it.
|
||||
### Setup
|
||||
Make sure to edit the .env file to look something like this:
|
||||
```
|
||||
export CLUSTER="mainnet-beta"
|
||||
|
|
|
@ -164,7 +164,15 @@ async function runPartialLiquidator() {
|
|||
|
||||
for (let i = 0; i < NUM_MARKETS; i++) {
|
||||
let openOrdersAccounts: OpenOrders[] = await markets[i].findOpenOrdersAccountsForOwner(connection, payer.publicKey)
|
||||
if(openOrdersAccounts.length) {
|
||||
liqorOpenOrdersKeys.push(openOrdersAccounts[0].publicKey)
|
||||
} else {
|
||||
console.log(`No OpenOrders account found for market ${markets[i].publicKey.toBase58()}`)
|
||||
}
|
||||
}
|
||||
|
||||
if(liqorOpenOrdersKeys.length != NUM_MARKETS) {
|
||||
console.log('Warning: Missing OpenOrders accounts. Wallet balancing has been disabled.')
|
||||
}
|
||||
|
||||
const cancelLimit = 5
|
||||
|
@ -345,7 +353,11 @@ async function runPartialLiquidator() {
|
|||
const maxBorrAccPk = maxBorrAcc ? maxBorrAcc.publicKey.toBase58() : ""
|
||||
const maxBorrAccCr = maxBorrAcc ? maxBorrAcc.getCollateralRatio(mangoGroup, prices) : 0
|
||||
console.log(`Max Borrow Account: ${maxBorrAccPk} | Max Borrow Val: ${maxBorrVal} | CR: ${maxBorrAccCr}`)
|
||||
if(liqorOpenOrdersKeys.length == NUM_MARKETS) {
|
||||
await balanceWallets(connection, mangoGroup, prices, markets, payer, tokenWallets, liqorTokenUi, liqorOpenOrdersKeys, targets)
|
||||
} else {
|
||||
console.log('Could not balance wallets due to missing OpenOrders account')
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
notify(`unknown error: ${e}`);
|
||||
|
|
Loading…
Reference in New Issue