Add PerpForceClosePositionLog and TokenForceCloseBorrowsWithTokenLog (#555)

This commit is contained in:
Nicholas Clarke 2023-04-25 04:38:08 -07:00 committed by GitHub
parent 507cb500e9
commit 5d77ba6834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 385 additions and 3 deletions

View File

@ -7185,6 +7185,23 @@
] ]
} }
}, },
{
"name": "CheckLiquidatable",
"type": {
"kind": "enum",
"variants": [
{
"name": "NotLiquidatable"
},
{
"name": "Liquidatable"
},
{
"name": "BecameNotLiquidatable"
}
]
}
},
{ {
"name": "OracleType", "name": "OracleType",
"type": { "type": {
@ -8677,6 +8694,101 @@
"index": false "index": false
} }
] ]
},
{
"name": "PerpForceClosePositionLog",
"fields": [
{
"name": "mangoGroup",
"type": "publicKey",
"index": false
},
{
"name": "perpMarketIndex",
"type": "u16",
"index": false
},
{
"name": "accountA",
"type": "publicKey",
"index": false
},
{
"name": "accountB",
"type": "publicKey",
"index": false
},
{
"name": "baseTransfer",
"type": "i64",
"index": false
},
{
"name": "quoteTransfer",
"type": "i128",
"index": false
},
{
"name": "price",
"type": "i128",
"index": false
}
]
},
{
"name": "TokenForceCloseBorrowsWithTokenLog",
"fields": [
{
"name": "mangoGroup",
"type": "publicKey",
"index": false
},
{
"name": "liqor",
"type": "publicKey",
"index": false
},
{
"name": "liqee",
"type": "publicKey",
"index": false
},
{
"name": "assetTokenIndex",
"type": "u16",
"index": false
},
{
"name": "liabTokenIndex",
"type": "u16",
"index": false
},
{
"name": "assetTransfer",
"type": "i128",
"index": false
},
{
"name": "liabTransfer",
"type": "i128",
"index": false
},
{
"name": "assetPrice",
"type": "i128",
"index": false
},
{
"name": "liabPrice",
"type": "i128",
"index": false
},
{
"name": "feeFactor",
"type": "i128",
"index": false
}
]
} }
], ],
"errors": [ "errors": [

View File

@ -4,7 +4,7 @@ use crate::accounts_ix::*;
use crate::accounts_zerocopy::AccountInfoRef; use crate::accounts_zerocopy::AccountInfoRef;
use crate::error::MangoError; use crate::error::MangoError;
use crate::logs::emit_perp_balances; use crate::logs::{emit_perp_balances, PerpForceClosePositionLog};
use crate::state::*; use crate::state::*;
use fixed::types::I80F48; use fixed::types::I80F48;
@ -56,7 +56,15 @@ pub fn perp_force_close_position(ctx: Context<PerpForceClosePosition>) -> Result
&perp_market, &perp_market,
); );
// TODO force-close trade log emit!(PerpForceClosePositionLog {
mango_group: ctx.accounts.group.key(),
perp_market_index: perp_market.perp_market_index,
account_a: ctx.accounts.account_a.key(),
account_b: ctx.accounts.account_b.key(),
base_transfer: base_transfer,
quote_transfer: quote_transfer.to_bits(),
price: oracle_price.to_bits(),
});
Ok(()) Ok(())
} }

View File

@ -1,7 +1,7 @@
use crate::accounts_ix::*; use crate::accounts_ix::*;
use crate::error::*; use crate::error::*;
use crate::health::*; use crate::health::*;
use crate::logs::TokenBalanceLog; use crate::logs::{TokenBalanceLog, TokenForceCloseBorrowsWithTokenLog};
use crate::state::*; use crate::state::*;
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
use fixed::types::I80F48; use fixed::types::I80F48;
@ -161,6 +161,19 @@ pub fn token_force_close_borrows_with_token(
borrow_index: liab_bank.borrow_index.to_bits(), borrow_index: liab_bank.borrow_index.to_bits(),
}); });
emit!(TokenForceCloseBorrowsWithTokenLog {
mango_group: liqee.fixed.group,
liqee: liqee_key,
liqor: liqor_key,
asset_token_index: asset_token_index,
liab_token_index: liab_token_index,
asset_transfer: asset_transfer.to_bits(),
liab_transfer: liab_transfer.to_bits(),
asset_price: asset_oracle_price.to_bits(),
liab_price: liab_oracle_price.to_bits(),
fee_factor: fee_factor.to_bits(),
});
let liqee_health_cache = new_health_cache(&liqee.borrow(), &mut account_retriever) let liqee_health_cache = new_health_cache(&liqee.borrow(), &mut account_retriever)
.context("create liqee health cache")?; .context("create liqee health cache")?;
let liqee_liq_end_health = liqee_health_cache.health(HealthType::LiquidationEnd); let liqee_liq_end_health = liqee_health_cache.health(HealthType::LiquidationEnd);

View File

@ -379,3 +379,28 @@ pub struct FilledPerpOrderLog {
pub perp_market_index: u16, pub perp_market_index: u16,
pub seq_num: u64, pub seq_num: u64,
} }
#[event]
pub struct PerpForceClosePositionLog {
pub mango_group: Pubkey,
pub perp_market_index: u16,
pub account_a: Pubkey,
pub account_b: Pubkey,
pub base_transfer: i64,
pub quote_transfer: i128,
pub price: i128,
}
#[event]
pub struct TokenForceCloseBorrowsWithTokenLog {
pub mango_group: Pubkey,
pub liqor: Pubkey,
pub liqee: Pubkey,
pub asset_token_index: u16,
pub liab_token_index: u16,
pub asset_transfer: i128,
pub liab_transfer: i128,
pub asset_price: i128,
pub liab_price: i128,
pub fee_factor: i128,
}

View File

@ -7185,6 +7185,23 @@ export type MangoV4 = {
] ]
} }
}, },
{
"name": "CheckLiquidatable",
"type": {
"kind": "enum",
"variants": [
{
"name": "NotLiquidatable"
},
{
"name": "Liquidatable"
},
{
"name": "BecameNotLiquidatable"
}
]
}
},
{ {
"name": "OracleType", "name": "OracleType",
"type": { "type": {
@ -8677,6 +8694,101 @@ export type MangoV4 = {
"index": false "index": false
} }
] ]
},
{
"name": "PerpForceClosePositionLog",
"fields": [
{
"name": "mangoGroup",
"type": "publicKey",
"index": false
},
{
"name": "perpMarketIndex",
"type": "u16",
"index": false
},
{
"name": "accountA",
"type": "publicKey",
"index": false
},
{
"name": "accountB",
"type": "publicKey",
"index": false
},
{
"name": "baseTransfer",
"type": "i64",
"index": false
},
{
"name": "quoteTransfer",
"type": "i128",
"index": false
},
{
"name": "price",
"type": "i128",
"index": false
}
]
},
{
"name": "TokenForceCloseBorrowsWithTokenLog",
"fields": [
{
"name": "mangoGroup",
"type": "publicKey",
"index": false
},
{
"name": "liqor",
"type": "publicKey",
"index": false
},
{
"name": "liqee",
"type": "publicKey",
"index": false
},
{
"name": "assetTokenIndex",
"type": "u16",
"index": false
},
{
"name": "liabTokenIndex",
"type": "u16",
"index": false
},
{
"name": "assetTransfer",
"type": "i128",
"index": false
},
{
"name": "liabTransfer",
"type": "i128",
"index": false
},
{
"name": "assetPrice",
"type": "i128",
"index": false
},
{
"name": "liabPrice",
"type": "i128",
"index": false
},
{
"name": "feeFactor",
"type": "i128",
"index": false
}
]
} }
], ],
"errors": [ "errors": [
@ -16105,6 +16217,23 @@ export const IDL: MangoV4 = {
] ]
} }
}, },
{
"name": "CheckLiquidatable",
"type": {
"kind": "enum",
"variants": [
{
"name": "NotLiquidatable"
},
{
"name": "Liquidatable"
},
{
"name": "BecameNotLiquidatable"
}
]
}
},
{ {
"name": "OracleType", "name": "OracleType",
"type": { "type": {
@ -17597,6 +17726,101 @@ export const IDL: MangoV4 = {
"index": false "index": false
} }
] ]
},
{
"name": "PerpForceClosePositionLog",
"fields": [
{
"name": "mangoGroup",
"type": "publicKey",
"index": false
},
{
"name": "perpMarketIndex",
"type": "u16",
"index": false
},
{
"name": "accountA",
"type": "publicKey",
"index": false
},
{
"name": "accountB",
"type": "publicKey",
"index": false
},
{
"name": "baseTransfer",
"type": "i64",
"index": false
},
{
"name": "quoteTransfer",
"type": "i128",
"index": false
},
{
"name": "price",
"type": "i128",
"index": false
}
]
},
{
"name": "TokenForceCloseBorrowsWithTokenLog",
"fields": [
{
"name": "mangoGroup",
"type": "publicKey",
"index": false
},
{
"name": "liqor",
"type": "publicKey",
"index": false
},
{
"name": "liqee",
"type": "publicKey",
"index": false
},
{
"name": "assetTokenIndex",
"type": "u16",
"index": false
},
{
"name": "liabTokenIndex",
"type": "u16",
"index": false
},
{
"name": "assetTransfer",
"type": "i128",
"index": false
},
{
"name": "liabTransfer",
"type": "i128",
"index": false
},
{
"name": "assetPrice",
"type": "i128",
"index": false
},
{
"name": "liabPrice",
"type": "i128",
"index": false
},
{
"name": "feeFactor",
"type": "i128",
"index": false
}
]
} }
], ],
"errors": [ "errors": [