finished adding instructions in rust

This commit is contained in:
dd 2021-04-04 16:23:41 -04:00
parent 31f8a54125
commit e2bde96d1c
1 changed files with 80 additions and 26 deletions

View File

@ -301,35 +301,48 @@ pub enum MangoInstruction {
PlaceAndSettle {
order: serum_dex::instruction::NewOrderInstructionV3
},
/// Allow a liquidator to cancel open orders to recoup funds for liquidation incentive
/// Allow a liquidator to cancel open orders and settle to recoup funds for partial liquidation
///
/// Accounts expected by this instruction (16 + 2 * NUM_MARKETS):
///
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
/// 1. `[signer]` liqor_acc - liquidator's solana account
/// 2. `[writable]` liqee_margin_account_acc - MarginAccount of liquidatee
/// 3. `[writable]` base_vault_acc - mango vault for base currency
/// 4. `[writable]` quote_vault_acc - mango vault for quote currency
/// 5. `[writable]` spot_market_acc - serum dex MarketState
/// 6. `[writable]` bids_acc - serum dex bids for this market
/// 7. `[writable]` asks_acc - serum dex asks for this market
/// 8. `[]` signer_acc - mango signer key
/// 9. `[writable]` dex_event_queue - serum dex event queue for this market
/// 10. `[writable]` dex_base_acc - serum dex market's vault for base (coin) currency
/// 11. `[writable]` dex_quote_acc - serum dex market's vault for quote (pc) currency
/// 12. `[]` dex_signer_acc - signer for serum dex MarketState
/// 13. `[]` token_prog_acc - SPL token program
/// 14. `[]` dex_prog_acc - Serum dex program id
/// 15. `[]` clock_acc - Clock sysvar account
/// 16..16+NUM_MARKETS `[writable]` open_orders_accs - open orders for each of the spot market
/// 16+NUM_MARKETS..16+2*NUM_MARKETS `[]`
/// oracle_accs - flux aggregator feed accounts
ForceCancelOrders,
/// Take over a MarginAccount that is below init_coll_ratio by depositing funds
///
/// Accounts expected by this instruction (15 + 2 * NUM_MARKETS + NUM_TOKENS):
/// Accounts expected by this instruction (9 + 2 * NUM_MARKETS):
///
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
/// 1. `[signer]` liqor_acc - liquidator's solana account
/// 2. `[writable]` liqor_in_token_acc - liquidator's token account to deposit
/// 3. `[writable]` liqor_out_token_acc - liquidator's token account to withdraw into
/// 4. `[writable]` liqee_margin_account_acc - MarginAccount of liquidatee
/// 5. `[writable]` spot_market_acc
/// 6. `[writable]` bids_acc
/// 7. `[writable]` asks_acc
/// 8. `[]` signer_acc
/// 9. `[writable]` dex_event_queue_acc
/// 10. `[writable]` dex_base_acc
/// 11. `[writable]` dex_quote_acc
/// 12. `[]` dex_signer_acc
/// 13. `[]` token_prog_acc - SPL token program id
/// 14. `[]` clock_acc - Clock sysvar account
/// 15..15+NUM_MARKETS `[writable]` open_orders_accs - open orders for each of the spot market
/// 15+NUM_MARKETS..15+2*NUM_MARKETS `[]`
/// 5. `[writable]` in_vault_acc - Mango vault of in_token
/// 6. `[writable]` out_vault_acc - Mango vault of out_token
/// 7. `[]` signer_acc
/// 8. `[]` clock_acc - Clock sysvar account
/// 9..9+NUM_MARKETS `[]` open_orders_accs - open orders for each of the spot market
/// 9+NUM_MARKETS..9+2*NUM_MARKETS `[]`
/// oracle_accs - flux aggregator feed accounts
/// 15+2*NUM_MARKETS..15+2*NUM_MARKETS+NUM_TOKENS `[writable]`
/// vault_accs - MangoGroup vaults
PartialLiquidate {
/// Quantity of the token being deposited to repay borrows
max_deposit: u64
@ -1081,13 +1094,13 @@ pub fn change_borrow_limit(
})
}
pub fn partial_liquidate(
pub fn force_cancel_orders(
program_id: &Pubkey,
mango_group_pk: &Pubkey,
liqor_pk: &Pubkey,
liqor_in_token_pk: &Pubkey,
liqor_out_token_pk: &Pubkey,
liqee_margin_account_acc: &Pubkey,
base_vault_pk: &Pubkey,
quote_vault_pk: &Pubkey,
spot_market_pk: &Pubkey,
bids_pk: &Pubkey,
asks_pk: &Pubkey,
@ -1096,18 +1109,17 @@ pub fn partial_liquidate(
dex_base_pk: &Pubkey,
dex_quote_pk: &Pubkey,
dex_signer_pk: &Pubkey,
dex_prog_id: &Pubkey,
open_orders_pks: &[Pubkey],
oracle_pks: &[Pubkey],
vault_pks: &[Pubkey],
max_deposit: u64
oracle_pks: &[Pubkey]
) -> Result<Instruction, ProgramError> {
let mut accounts = vec![
AccountMeta::new(*mango_group_pk, false),
AccountMeta::new_readonly(*liqor_pk, true),
AccountMeta::new(*liqor_in_token_pk, false),
AccountMeta::new(*liqor_out_token_pk, false),
AccountMeta::new(*liqee_margin_account_acc, false),
AccountMeta::new(*base_vault_pk, false),
AccountMeta::new(*quote_vault_pk, false),
AccountMeta::new(*spot_market_pk, false),
AccountMeta::new(*bids_pk, false),
AccountMeta::new(*asks_pk, false),
@ -1117,6 +1129,7 @@ pub fn partial_liquidate(
AccountMeta::new(*dex_quote_pk, false),
AccountMeta::new_readonly(*dex_signer_pk, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(*dex_prog_id, false),
AccountMeta::new_readonly(solana_program::sysvar::clock::ID, false),
];
@ -1126,8 +1139,49 @@ pub fn partial_liquidate(
accounts.extend(oracle_pks.iter().map(
|pk| AccountMeta::new_readonly(*pk, false))
);
accounts.extend(vault_pks.iter().map(
|pk| AccountMeta::new(*pk, false))
let instr = MangoInstruction::ForceCancelOrders;
let data = instr.pack();
Ok(Instruction {
program_id: *program_id,
accounts,
data
})
}
pub fn partial_liquidate(
program_id: &Pubkey,
mango_group_pk: &Pubkey,
liqor_pk: &Pubkey,
liqor_in_token_pk: &Pubkey,
liqor_out_token_pk: &Pubkey,
liqee_margin_account_acc: &Pubkey,
in_vault_pk: &Pubkey,
out_vault_pk: &Pubkey,
signer_pk: &Pubkey,
open_orders_pks: &[Pubkey],
oracle_pks: &[Pubkey],
max_deposit: u64
) -> Result<Instruction, ProgramError> {
let mut accounts = vec![
AccountMeta::new(*mango_group_pk, false),
AccountMeta::new_readonly(*liqor_pk, true),
AccountMeta::new(*liqor_in_token_pk, false),
AccountMeta::new(*liqor_out_token_pk, false),
AccountMeta::new(*liqee_margin_account_acc, false),
AccountMeta::new(*in_vault_pk, false),
AccountMeta::new(*out_vault_pk, false),
AccountMeta::new_readonly(*signer_pk, false),
AccountMeta::new_readonly(solana_program::sysvar::clock::ID, false),
];
accounts.extend(open_orders_pks.iter().map(
|pk| AccountMeta::new_readonly(*pk, false))
);
accounts.extend(oracle_pks.iter().map(
|pk| AccountMeta::new_readonly(*pk, false))
);
let instr = MangoInstruction::PartialLiquidate { max_deposit };