Rename: LiqToken* -> TokenLiq*

This commit is contained in:
Christian Kamm 2022-09-14 13:25:11 +02:00
parent f3bdfec6a6
commit 50be520e99
8 changed files with 64 additions and 41 deletions

View File

@ -857,7 +857,7 @@ impl MangoClient {
program_id: mango_v4::id(), program_id: mango_v4::id(),
accounts: { accounts: {
let mut ams = anchor_lang::ToAccountMetas::to_account_metas( let mut ams = anchor_lang::ToAccountMetas::to_account_metas(
&mango_v4::accounts::LiqTokenWithToken { &mango_v4::accounts::TokenLiqWithToken {
group: self.group(), group: self.group(),
liqee: *liqee.0, liqee: *liqee.0,
liqor: self.mango_account_address, liqor: self.mango_account_address,
@ -869,7 +869,7 @@ impl MangoClient {
ams ams
}, },
data: anchor_lang::InstructionData::data( data: anchor_lang::InstructionData::data(
&mango_v4::instruction::LiqTokenWithToken { &mango_v4::instruction::TokenLiqWithToken {
asset_token_index, asset_token_index,
liab_token_index, liab_token_index,
max_liab_transfer, max_liab_transfer,
@ -918,7 +918,7 @@ impl MangoClient {
program_id: mango_v4::id(), program_id: mango_v4::id(),
accounts: { accounts: {
let mut ams = anchor_lang::ToAccountMetas::to_account_metas( let mut ams = anchor_lang::ToAccountMetas::to_account_metas(
&mango_v4::accounts::LiqTokenBankruptcy { &mango_v4::accounts::TokenLiqBankruptcy {
group: self.group(), group: self.group(),
liqee: *liqee.0, liqee: *liqee.0,
liqor: self.mango_account_address, liqor: self.mango_account_address,
@ -935,7 +935,7 @@ impl MangoClient {
ams ams
}, },
data: anchor_lang::InstructionData::data( data: anchor_lang::InstructionData::data(
&mango_v4::instruction::LiqTokenBankruptcy { max_liab_transfer }, &mango_v4::instruction::TokenLiqBankruptcy { max_liab_transfer },
), ),
}) })
.signer(&self.owner) .signer(&self.owner)

View File

@ -9,8 +9,6 @@ pub use group_close::*;
pub use group_create::*; pub use group_create::*;
pub use group_edit::*; pub use group_edit::*;
pub use health_region::*; pub use health_region::*;
pub use liq_token_bankruptcy::*;
pub use liq_token_with_token::*;
pub use perp_cancel_all_orders::*; pub use perp_cancel_all_orders::*;
pub use perp_cancel_all_orders_by_side::*; pub use perp_cancel_all_orders_by_side::*;
pub use perp_cancel_order::*; pub use perp_cancel_order::*;
@ -42,6 +40,8 @@ pub use token_add_bank::*;
pub use token_deposit::*; pub use token_deposit::*;
pub use token_deregister::*; pub use token_deregister::*;
pub use token_edit::*; pub use token_edit::*;
pub use token_liq_bankruptcy::*;
pub use token_liq_with_token::*;
pub use token_register::*; pub use token_register::*;
pub use token_register_trustless::*; pub use token_register_trustless::*;
pub use token_update_index_and_rate::*; pub use token_update_index_and_rate::*;
@ -58,8 +58,6 @@ mod group_close;
mod group_create; mod group_create;
mod group_edit; mod group_edit;
mod health_region; mod health_region;
mod liq_token_bankruptcy;
mod liq_token_with_token;
mod perp_cancel_all_orders; mod perp_cancel_all_orders;
mod perp_cancel_all_orders_by_side; mod perp_cancel_all_orders_by_side;
mod perp_cancel_order; mod perp_cancel_order;
@ -91,6 +89,8 @@ mod token_add_bank;
mod token_deposit; mod token_deposit;
mod token_deregister; mod token_deregister;
mod token_edit; mod token_edit;
mod token_liq_bankruptcy;
mod token_liq_with_token;
mod token_register; mod token_register;
mod token_register_trustless; mod token_register_trustless;
mod token_update_index_and_rate; mod token_update_index_and_rate;

View File

@ -19,7 +19,7 @@ use crate::logs::{
// - all banks for liab_mint_info (writable) // - all banks for liab_mint_info (writable)
// - merged health accounts for liqor+liqee // - merged health accounts for liqor+liqee
#[derive(Accounts)] #[derive(Accounts)]
pub struct LiqTokenBankruptcy<'info> { pub struct TokenLiqBankruptcy<'info> {
#[account( #[account(
has_one = insurance_vault, has_one = insurance_vault,
)] )]
@ -56,7 +56,7 @@ pub struct LiqTokenBankruptcy<'info> {
pub token_program: Program<'info, Token>, pub token_program: Program<'info, Token>,
} }
impl<'info> LiqTokenBankruptcy<'info> { impl<'info> TokenLiqBankruptcy<'info> {
pub fn transfer_ctx(&self) -> CpiContext<'_, '_, '_, 'info, token::Transfer<'info>> { pub fn transfer_ctx(&self) -> CpiContext<'_, '_, '_, 'info, token::Transfer<'info>> {
let program = self.token_program.to_account_info(); let program = self.token_program.to_account_info();
let accounts = token::Transfer { let accounts = token::Transfer {
@ -68,8 +68,8 @@ impl<'info> LiqTokenBankruptcy<'info> {
} }
} }
pub fn liq_token_bankruptcy( pub fn token_liq_bankruptcy(
ctx: Context<LiqTokenBankruptcy>, ctx: Context<TokenLiqBankruptcy>,
max_liab_transfer: I80F48, max_liab_transfer: I80F48,
) -> Result<()> { ) -> Result<()> {
let group = ctx.accounts.group.load()?; let group = ctx.accounts.group.load()?;

View File

@ -12,7 +12,7 @@ use crate::state::*;
use crate::util::checked_math as cm; use crate::util::checked_math as cm;
#[derive(Accounts)] #[derive(Accounts)]
pub struct LiqTokenWithToken<'info> { pub struct TokenLiqWithToken<'info> {
pub group: AccountLoader<'info, Group>, pub group: AccountLoader<'info, Group>,
#[account( #[account(
@ -30,8 +30,8 @@ pub struct LiqTokenWithToken<'info> {
pub liqee: AccountLoaderDynamic<'info, MangoAccount>, pub liqee: AccountLoaderDynamic<'info, MangoAccount>,
} }
pub fn liq_token_with_token( pub fn token_liq_with_token(
ctx: Context<LiqTokenWithToken>, ctx: Context<TokenLiqWithToken>,
asset_token_index: TokenIndex, asset_token_index: TokenIndex,
liab_token_index: TokenIndex, liab_token_index: TokenIndex,
max_liab_transfer: I80F48, max_liab_transfer: I80F48,

View File

@ -328,13 +328,14 @@ pub mod mango_v4 {
// TODO serum3_cancel_all_spot_orders // TODO serum3_cancel_all_spot_orders
// DEPRECATED: use token_liq_with_token
pub fn liq_token_with_token( pub fn liq_token_with_token(
ctx: Context<LiqTokenWithToken>, ctx: Context<TokenLiqWithToken>,
asset_token_index: TokenIndex, asset_token_index: TokenIndex,
liab_token_index: TokenIndex, liab_token_index: TokenIndex,
max_liab_transfer: I80F48, max_liab_transfer: I80F48,
) -> Result<()> { ) -> Result<()> {
instructions::liq_token_with_token( instructions::token_liq_with_token(
ctx, ctx,
asset_token_index, asset_token_index,
liab_token_index, liab_token_index,
@ -342,11 +343,33 @@ pub mod mango_v4 {
) )
} }
// DEPRECATED: use token_liq_bankruptcy
pub fn liq_token_bankruptcy( pub fn liq_token_bankruptcy(
ctx: Context<LiqTokenBankruptcy>, ctx: Context<TokenLiqBankruptcy>,
max_liab_transfer: I80F48, max_liab_transfer: I80F48,
) -> Result<()> { ) -> Result<()> {
instructions::liq_token_bankruptcy(ctx, max_liab_transfer) instructions::token_liq_bankruptcy(ctx, max_liab_transfer)
}
pub fn token_liq_with_token(
ctx: Context<TokenLiqWithToken>,
asset_token_index: TokenIndex,
liab_token_index: TokenIndex,
max_liab_transfer: I80F48,
) -> Result<()> {
instructions::token_liq_with_token(
ctx,
asset_token_index,
liab_token_index,
max_liab_transfer,
)
}
pub fn token_liq_bankruptcy(
ctx: Context<TokenLiqBankruptcy>,
max_liab_transfer: I80F48,
) -> Result<()> {
instructions::token_liq_bankruptcy(ctx, max_liab_transfer)
} }
/// ///

View File

@ -1941,7 +1941,7 @@ impl ClientInstruction for Serum3LiqForceCancelOrdersInstruction {
} }
} }
pub struct LiqTokenWithTokenInstruction { pub struct TokenLiqWithTokenInstruction {
pub liqee: Pubkey, pub liqee: Pubkey,
pub liqor: Pubkey, pub liqor: Pubkey,
pub liqor_owner: TestKeypair, pub liqor_owner: TestKeypair,
@ -1953,9 +1953,9 @@ pub struct LiqTokenWithTokenInstruction {
pub max_liab_transfer: I80F48, pub max_liab_transfer: I80F48,
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl ClientInstruction for LiqTokenWithTokenInstruction { impl ClientInstruction for TokenLiqWithTokenInstruction {
type Accounts = mango_v4::accounts::LiqTokenWithToken; type Accounts = mango_v4::accounts::TokenLiqWithToken;
type Instruction = mango_v4::instruction::LiqTokenWithToken; type Instruction = mango_v4::instruction::TokenLiqWithToken;
async fn to_instruction( async fn to_instruction(
&self, &self,
account_loader: impl ClientAccountLoader + 'async_trait, account_loader: impl ClientAccountLoader + 'async_trait,
@ -2004,7 +2004,7 @@ impl ClientInstruction for LiqTokenWithTokenInstruction {
} }
} }
pub struct LiqTokenBankruptcyInstruction { pub struct TokenLiqBankruptcyInstruction {
pub liqee: Pubkey, pub liqee: Pubkey,
pub liqor: Pubkey, pub liqor: Pubkey,
pub liqor_owner: TestKeypair, pub liqor_owner: TestKeypair,
@ -2013,9 +2013,9 @@ pub struct LiqTokenBankruptcyInstruction {
pub liab_mint_info: Pubkey, pub liab_mint_info: Pubkey,
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl ClientInstruction for LiqTokenBankruptcyInstruction { impl ClientInstruction for TokenLiqBankruptcyInstruction {
type Accounts = mango_v4::accounts::LiqTokenBankruptcy; type Accounts = mango_v4::accounts::TokenLiqBankruptcy;
type Instruction = mango_v4::instruction::LiqTokenBankruptcy; type Instruction = mango_v4::instruction::TokenLiqBankruptcy;
async fn to_instruction( async fn to_instruction(
&self, &self,
account_loader: impl ClientAccountLoader + 'async_trait, account_loader: impl ClientAccountLoader + 'async_trait,

View File

@ -180,7 +180,7 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> {
// eat collateral1 // eat collateral1
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -204,7 +204,7 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> {
// eat collateral2, leaving the account bankrupt // eat collateral2, leaving the account bankrupt
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -233,7 +233,7 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> {
let vault_before = account_position(solana, vault_account, borrow_token1.bank).await; let vault_before = account_position(solana, vault_account, borrow_token1.bank).await;
send_tx( send_tx(
solana, solana,
LiqTokenBankruptcyInstruction { TokenLiqBankruptcyInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -258,7 +258,7 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> {
send_tx( send_tx(
solana, solana,
LiqTokenBankruptcyInstruction { TokenLiqBankruptcyInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -489,7 +489,7 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> {
// eat collateral1 // eat collateral1
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -509,7 +509,7 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> {
// eat collateral2, leaving the account bankrupt // eat collateral2, leaving the account bankrupt
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -536,7 +536,7 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> {
let liqor_before = account_position(solana, vault_account, borrow_token1.bank).await; let liqor_before = account_position(solana, vault_account, borrow_token1.bank).await;
send_tx( send_tx(
solana, solana,
LiqTokenBankruptcyInstruction { TokenLiqBankruptcyInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -567,7 +567,7 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> {
let liab_transfer: f64 = 500.0 / 20.0; let liab_transfer: f64 = 500.0 / 20.0;
send_tx( send_tx(
solana, solana,
LiqTokenBankruptcyInstruction { TokenLiqBankruptcyInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -600,7 +600,7 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> {
let liqor_before = account_position(solana, vault_account, borrow_token1.bank).await; let liqor_before = account_position(solana, vault_account, borrow_token1.bank).await;
send_tx( send_tx(
solana, solana,
LiqTokenBankruptcyInstruction { TokenLiqBankruptcyInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,

View File

@ -338,7 +338,7 @@ async fn test_liq_tokens_with_token() -> Result<(), TransportError> {
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -367,7 +367,7 @@ async fn test_liq_tokens_with_token() -> Result<(), TransportError> {
// //
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -395,7 +395,7 @@ async fn test_liq_tokens_with_token() -> Result<(), TransportError> {
// //
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -426,7 +426,7 @@ async fn test_liq_tokens_with_token() -> Result<(), TransportError> {
// //
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,
@ -503,7 +503,7 @@ async fn test_liq_tokens_with_token() -> Result<(), TransportError> {
send_tx( send_tx(
solana, solana,
LiqTokenWithTokenInstruction { TokenLiqWithTokenInstruction {
liqee: account, liqee: account,
liqor: vault_account, liqor: vault_account,
liqor_owner: owner, liqor_owner: owner,