Fix bug where if no insurance fund position was present, ix would err… (#522)

* Fix bug where if no insurance fund position was present, ix would error out

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* prettier

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-04-17 11:30:27 +02:00 committed by GitHub
parent 227aadfc22
commit a40ceedc97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -18,7 +18,7 @@ use itertools::Itertools;
use mango_v4::accounts_ix::{Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side};
use mango_v4::state::{
Bank, Group, MangoAccountValue, PerpMarketIndex, PlaceOrderType, Serum3MarketIndex, Side,
TokenIndex,
TokenIndex, INSURANCE_TOKEN_INDEX,
};
use solana_address_lookup_table_program::state::AddressLookupTable;
@ -305,6 +305,7 @@ impl MangoClient {
pub async fn derive_liquidation_health_check_remaining_account_metas(
&self,
liqee: &MangoAccountValue,
affected_tokens: Vec<u16>,
writable_banks: &[TokenIndex],
) -> anyhow::Result<Vec<AccountMeta>> {
let account = self.mango_account().await?;
@ -312,6 +313,7 @@ impl MangoClient {
.derive_health_check_remaining_account_metas_two_accounts(
&account,
liqee,
&affected_tokens,
writable_banks,
)
}
@ -880,7 +882,12 @@ impl MangoClient {
let health_remaining_ams = self
.context
.derive_health_check_remaining_account_metas_two_accounts(account_a.1, account_b.1, &[])
.derive_health_check_remaining_account_metas_two_accounts(
account_a.1,
account_b.1,
&vec![],
&[],
)
.unwrap();
Ok(Instruction {
@ -963,7 +970,7 @@ impl MangoClient {
let settle_token_info = self.context.token(perp.market.settle_token_index);
let health_remaining_ams = self
.derive_liquidation_health_check_remaining_account_metas(liqee.1, &[])
.derive_liquidation_health_check_remaining_account_metas(liqee.1, vec![], &[])
.await
.unwrap();
@ -1013,7 +1020,11 @@ impl MangoClient {
let settle_token_info = self.context.token(perp.market.settle_token_index);
let health_remaining_ams = self
.derive_liquidation_health_check_remaining_account_metas(liqee.1, &[])
.derive_liquidation_health_check_remaining_account_metas(
liqee.1,
vec![INSURANCE_TOKEN_INDEX],
&[],
)
.await
.unwrap();
@ -1060,6 +1071,7 @@ impl MangoClient {
let health_remaining_ams = self
.derive_liquidation_health_check_remaining_account_metas(
liqee.1,
vec![],
&[asset_token_index, liab_token_index],
)
.await
@ -1110,6 +1122,7 @@ impl MangoClient {
let health_remaining_ams = self
.derive_liquidation_health_check_remaining_account_metas(
liqee.1,
vec![INSURANCE_TOKEN_INDEX],
&[quote_token_index, liab_token_index],
)
.await

View File

@ -280,6 +280,7 @@ impl MangoGroupContext {
&self,
account1: &MangoAccountValue,
account2: &MangoAccountValue,
affected_tokens: &[TokenIndex],
writable_banks: &[TokenIndex],
) -> anyhow::Result<Vec<AccountMeta>> {
// figure out all the banks/oracles that need to be passed for the health check
@ -290,6 +291,7 @@ impl MangoGroupContext {
.active_token_positions()
.chain(account1.active_token_positions())
.map(|ta| ta.token_index)
.chain(affected_tokens.iter().copied())
.unique();
for token_index in token_indexes {

View File

@ -7,10 +7,12 @@ The environment variables required are
- `MB_CLUSTER_URL` - RPC cluster url
Notes:
- Quoting is based off of kraken
- see default.json for quoting rules
Future:
- Hedging perp positions on mango-v4 spot
- Observing fills and reacting earlier
- Quoting off of binance
- Quoting off of binance