diff --git a/mango_v4.json b/mango_v4.json index 48e992ceb..9b6f7f89f 100644 --- a/mango_v4.json +++ b/mango_v4.json @@ -7185,6 +7185,23 @@ ] } }, + { + "name": "CheckLiquidatable", + "type": { + "kind": "enum", + "variants": [ + { + "name": "NotLiquidatable" + }, + { + "name": "Liquidatable" + }, + { + "name": "BecameNotLiquidatable" + } + ] + } + }, { "name": "OracleType", "type": { @@ -8677,6 +8694,101 @@ "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": [ diff --git a/programs/mango-v4/src/instructions/perp_force_close_position.rs b/programs/mango-v4/src/instructions/perp_force_close_position.rs index f2ffb23b9..9e3b04d4f 100644 --- a/programs/mango-v4/src/instructions/perp_force_close_position.rs +++ b/programs/mango-v4/src/instructions/perp_force_close_position.rs @@ -4,7 +4,7 @@ use crate::accounts_ix::*; use crate::accounts_zerocopy::AccountInfoRef; use crate::error::MangoError; -use crate::logs::emit_perp_balances; +use crate::logs::{emit_perp_balances, PerpForceClosePositionLog}; use crate::state::*; use fixed::types::I80F48; @@ -56,7 +56,15 @@ pub fn perp_force_close_position(ctx: Context) -> Result &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(()) } diff --git a/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs b/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs index 60fac9a49..27e85cc3c 100644 --- a/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs +++ b/programs/mango-v4/src/instructions/token_force_close_borrows_with_token.rs @@ -1,7 +1,7 @@ use crate::accounts_ix::*; use crate::error::*; use crate::health::*; -use crate::logs::TokenBalanceLog; +use crate::logs::{TokenBalanceLog, TokenForceCloseBorrowsWithTokenLog}; use crate::state::*; use anchor_lang::prelude::*; use fixed::types::I80F48; @@ -161,6 +161,19 @@ pub fn token_force_close_borrows_with_token( 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) .context("create liqee health cache")?; let liqee_liq_end_health = liqee_health_cache.health(HealthType::LiquidationEnd); diff --git a/programs/mango-v4/src/logs.rs b/programs/mango-v4/src/logs.rs index b2ba33977..7218f6f68 100644 --- a/programs/mango-v4/src/logs.rs +++ b/programs/mango-v4/src/logs.rs @@ -379,3 +379,28 @@ pub struct FilledPerpOrderLog { pub perp_market_index: u16, 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, +} diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index bbbc6c74c..c477dc940 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -7185,6 +7185,23 @@ export type MangoV4 = { ] } }, + { + "name": "CheckLiquidatable", + "type": { + "kind": "enum", + "variants": [ + { + "name": "NotLiquidatable" + }, + { + "name": "Liquidatable" + }, + { + "name": "BecameNotLiquidatable" + } + ] + } + }, { "name": "OracleType", "type": { @@ -8677,6 +8694,101 @@ export type MangoV4 = { "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": [ @@ -16105,6 +16217,23 @@ export const IDL: MangoV4 = { ] } }, + { + "name": "CheckLiquidatable", + "type": { + "kind": "enum", + "variants": [ + { + "name": "NotLiquidatable" + }, + { + "name": "Liquidatable" + }, + { + "name": "BecameNotLiquidatable" + } + ] + } + }, { "name": "OracleType", "type": { @@ -17597,6 +17726,101 @@ export const IDL: MangoV4 = { "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": [