2023-02-14 23:42:07 -08:00
|
|
|
#![allow(unused_variables)]
|
|
|
|
|
2022-02-28 03:37:07 -08:00
|
|
|
use fixed::types::I80F48;
|
|
|
|
|
2022-03-04 05:30:53 -08:00
|
|
|
#[macro_use]
|
|
|
|
pub mod util;
|
|
|
|
|
2022-11-08 06:27:56 -08:00
|
|
|
extern crate core;
|
2022-01-21 10:21:46 -08:00
|
|
|
extern crate static_assertions;
|
|
|
|
|
|
|
|
use anchor_lang::prelude::*;
|
|
|
|
|
2023-02-14 23:42:07 -08:00
|
|
|
use accounts_ix::*;
|
2022-02-28 02:07:04 -08:00
|
|
|
|
2023-02-14 23:42:07 -08:00
|
|
|
pub mod accounts_ix;
|
2022-06-08 04:43:12 -07:00
|
|
|
pub mod accounts_zerocopy;
|
2022-09-14 01:55:24 -07:00
|
|
|
pub mod address_lookup_table_program;
|
2022-03-02 21:15:28 -08:00
|
|
|
pub mod error;
|
2022-07-04 03:29:35 -07:00
|
|
|
pub mod events;
|
2022-12-08 04:12:43 -08:00
|
|
|
pub mod health;
|
2022-11-24 02:59:00 -08:00
|
|
|
pub mod i80f48;
|
2022-06-30 05:35:05 -07:00
|
|
|
pub mod logs;
|
2022-07-25 07:07:53 -07:00
|
|
|
pub mod serum3_cpi;
|
2022-02-25 04:10:51 -08:00
|
|
|
pub mod state;
|
2022-03-31 00:10:06 -07:00
|
|
|
pub mod types;
|
2022-01-21 10:21:46 -08:00
|
|
|
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
pub mod instructions;
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "no-entrypoint"), not(feature = "enable-gpl")))]
|
|
|
|
compile_error!("compiling the program entrypoint without 'enable-gpl' makes no sense, enable it or use the 'cpi' or 'client' features");
|
|
|
|
|
2022-11-09 04:25:53 -08:00
|
|
|
use state::{
|
2023-05-15 01:40:41 -07:00
|
|
|
OracleConfigParams, PerpMarketIndex, PlaceOrderType, SelfTradeBehavior, Serum3MarketIndex,
|
|
|
|
Side, TokenIndex,
|
2022-11-09 04:25:53 -08:00
|
|
|
};
|
2022-03-11 03:38:10 -08:00
|
|
|
|
2022-12-08 01:23:12 -08:00
|
|
|
declare_id!("4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg");
|
2022-01-21 10:21:46 -08:00
|
|
|
|
|
|
|
#[program]
|
|
|
|
pub mod mango_v4 {
|
2023-05-15 01:40:41 -07:00
|
|
|
|
2022-01-21 10:21:46 -08:00
|
|
|
use super::*;
|
2023-04-14 06:18:02 -07:00
|
|
|
use error::*;
|
2022-01-21 10:21:46 -08:00
|
|
|
|
2022-08-01 03:56:29 -07:00
|
|
|
pub fn group_create(
|
|
|
|
ctx: Context<GroupCreate>,
|
|
|
|
group_num: u32,
|
|
|
|
testing: u8,
|
|
|
|
version: u8,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::group_create(ctx, group_num, testing, version)?;
|
|
|
|
Ok(())
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
2023-02-25 11:34:16 -08:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2022-07-31 00:28:16 -07:00
|
|
|
pub fn group_edit(
|
|
|
|
ctx: Context<GroupEdit>,
|
2022-08-13 10:54:58 -07:00
|
|
|
admin_opt: Option<Pubkey>,
|
|
|
|
fast_listing_admin_opt: Option<Pubkey>,
|
2023-01-12 00:12:55 -08:00
|
|
|
security_admin_opt: Option<Pubkey>,
|
2022-08-13 10:54:58 -07:00
|
|
|
testing_opt: Option<u8>,
|
|
|
|
version_opt: Option<u8>,
|
2023-01-23 05:58:03 -08:00
|
|
|
deposit_limit_quote_opt: Option<u64>,
|
2023-02-25 11:34:16 -08:00
|
|
|
buyback_fees_opt: Option<bool>,
|
|
|
|
buyback_fees_bonus_factor_opt: Option<f32>,
|
|
|
|
buyback_fees_swap_mango_account_opt: Option<Pubkey>,
|
|
|
|
mngo_token_index_opt: Option<TokenIndex>,
|
2023-02-27 07:36:27 -08:00
|
|
|
buyback_fees_expiry_interval_opt: Option<u64>,
|
2022-07-31 00:28:16 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-08-13 10:54:58 -07:00
|
|
|
instructions::group_edit(
|
|
|
|
ctx,
|
|
|
|
admin_opt,
|
|
|
|
fast_listing_admin_opt,
|
2023-01-12 00:12:55 -08:00
|
|
|
security_admin_opt,
|
2022-08-13 10:54:58 -07:00
|
|
|
testing_opt,
|
|
|
|
version_opt,
|
2023-01-23 05:58:03 -08:00
|
|
|
deposit_limit_quote_opt,
|
2023-02-25 11:34:16 -08:00
|
|
|
buyback_fees_opt,
|
|
|
|
buyback_fees_bonus_factor_opt,
|
|
|
|
buyback_fees_swap_mango_account_opt,
|
|
|
|
mngo_token_index_opt,
|
2023-02-27 07:36:27 -08:00
|
|
|
buyback_fees_expiry_interval_opt,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-07-31 00:28:16 -07:00
|
|
|
}
|
|
|
|
|
2023-04-25 00:20:44 -07:00
|
|
|
pub fn group_withdraw_insurance_fund(
|
|
|
|
ctx: Context<GroupWithdrawInsuranceFund>,
|
|
|
|
amount: u64,
|
|
|
|
) -> Result<()> {
|
|
|
|
#[cfg(feature = "enable-gpl")]
|
2023-04-25 04:38:48 -07:00
|
|
|
instructions::group_withdraw_insurance_fund(ctx, amount)?;
|
|
|
|
Ok(())
|
2023-04-25 00:20:44 -07:00
|
|
|
}
|
|
|
|
|
2023-01-26 11:27:39 -08:00
|
|
|
pub fn ix_gate_set(ctx: Context<IxGateSet>, ix_gate: u128) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::ix_gate_set(ctx, ix_gate)?;
|
|
|
|
Ok(())
|
2023-01-12 00:12:55 -08:00
|
|
|
}
|
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn group_close(ctx: Context<GroupClose>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::group_close(ctx)?;
|
|
|
|
Ok(())
|
2022-01-21 10:21:46 -08:00
|
|
|
}
|
2022-02-22 01:09:09 -08:00
|
|
|
|
2022-04-09 07:53:30 -07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn token_register(
|
|
|
|
ctx: Context<TokenRegister>,
|
2022-03-14 05:19:50 -07:00
|
|
|
token_index: TokenIndex,
|
2022-04-12 07:19:58 -07:00
|
|
|
name: String,
|
2022-11-09 04:25:53 -08:00
|
|
|
oracle_config: OracleConfigParams,
|
2022-04-12 07:53:45 -07:00
|
|
|
interest_rate_params: InterestRateParams,
|
2022-05-09 02:14:50 -07:00
|
|
|
loan_fee_rate: f32,
|
|
|
|
loan_origination_fee_rate: f32,
|
2022-02-25 09:29:54 -08:00
|
|
|
maint_asset_weight: f32,
|
|
|
|
init_asset_weight: f32,
|
|
|
|
maint_liab_weight: f32,
|
|
|
|
init_liab_weight: f32,
|
2022-03-26 11:34:44 -07:00
|
|
|
liquidation_fee: f32,
|
2022-11-25 04:45:17 -08:00
|
|
|
min_vault_to_deposits_ratio: f64,
|
2022-12-06 00:34:02 -08:00
|
|
|
net_borrow_limit_window_size_ts: u64,
|
|
|
|
net_borrow_limit_per_window_quote: i64,
|
2022-02-25 09:29:54 -08:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-06-09 09:27:31 -07:00
|
|
|
instructions::token_register(
|
2022-02-25 09:29:54 -08:00
|
|
|
ctx,
|
2022-03-14 05:19:50 -07:00
|
|
|
token_index,
|
2022-04-12 07:19:58 -07:00
|
|
|
name,
|
2022-06-18 07:38:46 -07:00
|
|
|
oracle_config,
|
2022-04-12 07:53:45 -07:00
|
|
|
interest_rate_params,
|
2022-05-09 02:14:50 -07:00
|
|
|
loan_fee_rate,
|
|
|
|
loan_origination_fee_rate,
|
2022-02-25 09:29:54 -08:00
|
|
|
maint_asset_weight,
|
|
|
|
init_asset_weight,
|
|
|
|
maint_liab_weight,
|
|
|
|
init_liab_weight,
|
2022-03-26 11:34:44 -07:00
|
|
|
liquidation_fee,
|
2022-11-25 04:45:17 -08:00
|
|
|
min_vault_to_deposits_ratio,
|
2022-12-06 00:34:02 -08:00
|
|
|
net_borrow_limit_window_size_ts,
|
|
|
|
net_borrow_limit_per_window_quote,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-02-22 01:09:09 -08:00
|
|
|
}
|
2022-02-22 04:15:13 -08:00
|
|
|
|
2022-08-03 01:25:09 -07:00
|
|
|
pub fn token_register_trustless(
|
|
|
|
ctx: Context<TokenRegisterTrustless>,
|
|
|
|
token_index: TokenIndex,
|
|
|
|
name: String,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_register_trustless(ctx, token_index, name)?;
|
|
|
|
Ok(())
|
2022-08-03 01:25:09 -07:00
|
|
|
}
|
|
|
|
|
2022-07-05 10:31:47 -07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn token_edit(
|
|
|
|
ctx: Context<TokenEdit>,
|
|
|
|
oracle_opt: Option<Pubkey>,
|
2022-11-09 04:25:53 -08:00
|
|
|
oracle_config_opt: Option<OracleConfigParams>,
|
2022-08-07 05:16:23 -07:00
|
|
|
group_insurance_fund_opt: Option<bool>,
|
2022-07-05 10:31:47 -07:00
|
|
|
interest_rate_params_opt: Option<InterestRateParams>,
|
|
|
|
loan_fee_rate_opt: Option<f32>,
|
|
|
|
loan_origination_fee_rate_opt: Option<f32>,
|
|
|
|
maint_asset_weight_opt: Option<f32>,
|
|
|
|
init_asset_weight_opt: Option<f32>,
|
|
|
|
maint_liab_weight_opt: Option<f32>,
|
|
|
|
init_liab_weight_opt: Option<f32>,
|
|
|
|
liquidation_fee_opt: Option<f32>,
|
2022-11-24 02:55:22 -08:00
|
|
|
stable_price_delay_interval_seconds_opt: Option<u32>,
|
|
|
|
stable_price_delay_growth_limit_opt: Option<f32>,
|
|
|
|
stable_price_growth_limit_opt: Option<f32>,
|
2022-11-25 04:45:17 -08:00
|
|
|
min_vault_to_deposits_ratio_opt: Option<f64>,
|
2022-12-06 00:34:02 -08:00
|
|
|
net_borrow_limit_per_window_quote_opt: Option<i64>,
|
|
|
|
net_borrow_limit_window_size_ts_opt: Option<u64>,
|
|
|
|
borrow_weight_scale_start_quote_opt: Option<f64>,
|
|
|
|
deposit_weight_scale_start_quote_opt: Option<f64>,
|
2022-12-02 03:24:11 -08:00
|
|
|
reset_stable_price: bool,
|
|
|
|
reset_net_borrow_limit: bool,
|
2023-04-13 03:44:12 -07:00
|
|
|
reduce_only_opt: Option<u8>,
|
2023-03-03 01:05:12 -08:00
|
|
|
name_opt: Option<String>,
|
2023-04-13 03:44:12 -07:00
|
|
|
force_close_opt: Option<bool>,
|
2022-07-05 10:31:47 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-07-05 10:31:47 -07:00
|
|
|
instructions::token_edit(
|
|
|
|
ctx,
|
|
|
|
oracle_opt,
|
|
|
|
oracle_config_opt,
|
2022-08-07 05:16:23 -07:00
|
|
|
group_insurance_fund_opt,
|
2022-07-05 10:31:47 -07:00
|
|
|
interest_rate_params_opt,
|
|
|
|
loan_fee_rate_opt,
|
|
|
|
loan_origination_fee_rate_opt,
|
|
|
|
maint_asset_weight_opt,
|
|
|
|
init_asset_weight_opt,
|
|
|
|
maint_liab_weight_opt,
|
|
|
|
init_liab_weight_opt,
|
|
|
|
liquidation_fee_opt,
|
2022-11-24 02:55:22 -08:00
|
|
|
stable_price_delay_interval_seconds_opt,
|
|
|
|
stable_price_delay_growth_limit_opt,
|
|
|
|
stable_price_growth_limit_opt,
|
2022-11-25 04:45:17 -08:00
|
|
|
min_vault_to_deposits_ratio_opt,
|
2022-12-06 00:34:02 -08:00
|
|
|
net_borrow_limit_per_window_quote_opt,
|
|
|
|
net_borrow_limit_window_size_ts_opt,
|
|
|
|
borrow_weight_scale_start_quote_opt,
|
|
|
|
deposit_weight_scale_start_quote_opt,
|
2022-12-02 03:24:11 -08:00
|
|
|
reset_stable_price,
|
|
|
|
reset_net_borrow_limit,
|
2023-01-04 00:24:40 -08:00
|
|
|
reduce_only_opt,
|
2023-03-03 01:05:12 -08:00
|
|
|
name_opt,
|
2023-04-13 03:44:12 -07:00
|
|
|
force_close_opt,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
2022-06-27 02:27:17 -07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn token_add_bank(
|
|
|
|
ctx: Context<TokenAddBank>,
|
|
|
|
token_index: TokenIndex,
|
2022-08-01 09:46:45 -07:00
|
|
|
bank_num: u32,
|
2022-06-27 02:27:17 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_add_bank(ctx, token_index, bank_num)?;
|
|
|
|
Ok(())
|
2022-06-27 02:27:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn token_deregister<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_deregister(ctx)?;
|
|
|
|
Ok(())
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
2022-07-11 08:08:32 -07:00
|
|
|
pub fn token_update_index_and_rate(ctx: Context<TokenUpdateIndexAndRate>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_update_index_and_rate(ctx)?;
|
|
|
|
Ok(())
|
2022-04-09 07:53:30 -07:00
|
|
|
}
|
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn account_create(
|
|
|
|
ctx: Context<AccountCreate>,
|
2022-08-01 09:46:45 -07:00
|
|
|
account_num: u32,
|
2022-08-07 05:16:06 -07:00
|
|
|
token_count: u8,
|
|
|
|
serum3_count: u8,
|
|
|
|
perp_count: u8,
|
|
|
|
perp_oo_count: u8,
|
2022-04-12 07:19:58 -07:00
|
|
|
name: String,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-08-07 05:16:06 -07:00
|
|
|
instructions::account_create(
|
|
|
|
ctx,
|
|
|
|
account_num,
|
|
|
|
token_count,
|
|
|
|
serum3_count,
|
|
|
|
perp_count,
|
|
|
|
perp_oo_count,
|
|
|
|
name,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-07-25 07:07:53 -07:00
|
|
|
}
|
|
|
|
|
2022-08-07 05:16:06 -07:00
|
|
|
pub fn account_expand(
|
|
|
|
ctx: Context<AccountExpand>,
|
|
|
|
token_count: u8,
|
|
|
|
serum3_count: u8,
|
|
|
|
perp_count: u8,
|
|
|
|
perp_oo_count: u8,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::account_expand(ctx, token_count, serum3_count, perp_count, perp_oo_count)?;
|
|
|
|
Ok(())
|
2022-02-22 04:15:13 -08:00
|
|
|
}
|
2022-02-22 05:23:13 -08:00
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn account_edit(
|
|
|
|
ctx: Context<AccountEdit>,
|
2022-07-05 10:31:47 -07:00
|
|
|
name_opt: Option<String>,
|
|
|
|
delegate_opt: Option<Pubkey>,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::account_edit(ctx, name_opt, delegate_opt)?;
|
|
|
|
Ok(())
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
2023-01-12 04:08:10 -08:00
|
|
|
|
2023-01-12 11:39:46 -08:00
|
|
|
pub fn account_toggle_freeze(ctx: Context<AccountToggleFreeze>, freeze: bool) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::account_toggle_freeze(ctx, freeze)?;
|
|
|
|
Ok(())
|
2023-01-12 04:08:10 -08:00
|
|
|
}
|
2022-05-16 01:34:22 -07:00
|
|
|
|
2022-12-15 12:10:56 -08:00
|
|
|
pub fn account_close(ctx: Context<AccountClose>, force_close: bool) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::account_close(ctx, force_close)?;
|
|
|
|
Ok(())
|
2022-03-31 08:22:56 -07:00
|
|
|
}
|
|
|
|
|
2023-02-25 11:34:16 -08:00
|
|
|
pub fn account_buyback_fees_with_mngo(
|
|
|
|
ctx: Context<AccountBuybackFeesWithMngo>,
|
2023-03-20 03:18:11 -07:00
|
|
|
max_buyback_usd: u64,
|
2023-02-25 11:34:16 -08:00
|
|
|
) -> Result<()> {
|
|
|
|
#[cfg(feature = "enable-gpl")]
|
2023-03-20 03:18:11 -07:00
|
|
|
instructions::account_buyback_fees_with_mngo(ctx, max_buyback_usd)?;
|
2023-02-25 11:34:16 -08:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-02-28 03:37:07 -08:00
|
|
|
// todo:
|
|
|
|
// ckamm: generally, using an I80F48 arg will make it harder to call
|
|
|
|
// because generic anchor clients won't know how to deal with it
|
|
|
|
// and it's tricky to use in typescript generally
|
|
|
|
// lets do an interface pass later
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn stub_oracle_create(ctx: Context<StubOracleCreate>, price: I80F48) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::stub_oracle_create(ctx, price)?;
|
|
|
|
Ok(())
|
2022-02-28 03:37:07 -08:00
|
|
|
}
|
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn stub_oracle_close(ctx: Context<StubOracleClose>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::stub_oracle_close(ctx)?;
|
|
|
|
Ok(())
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn stub_oracle_set(ctx: Context<StubOracleSet>, price: I80F48) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::stub_oracle_set(ctx, price)?;
|
|
|
|
Ok(())
|
2022-02-28 03:37:07 -08:00
|
|
|
}
|
|
|
|
|
2023-01-04 00:24:40 -08:00
|
|
|
pub fn token_deposit(ctx: Context<TokenDeposit>, amount: u64, reduce_only: bool) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_deposit(ctx, amount, reduce_only)?;
|
|
|
|
Ok(())
|
2022-02-22 05:23:13 -08:00
|
|
|
}
|
2022-02-25 06:14:15 -08:00
|
|
|
|
2022-09-30 04:21:01 -07:00
|
|
|
pub fn token_deposit_into_existing(
|
|
|
|
ctx: Context<TokenDepositIntoExisting>,
|
|
|
|
amount: u64,
|
2023-01-04 00:24:40 -08:00
|
|
|
reduce_only: bool,
|
2022-09-30 04:21:01 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_deposit_into_existing(ctx, amount, reduce_only)?;
|
|
|
|
Ok(())
|
2022-09-30 04:21:01 -07:00
|
|
|
}
|
|
|
|
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn token_withdraw(
|
|
|
|
ctx: Context<TokenWithdraw>,
|
|
|
|
amount: u64,
|
|
|
|
allow_borrow: bool,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_withdraw(ctx, amount, allow_borrow)?;
|
|
|
|
Ok(())
|
2022-02-25 06:14:15 -08:00
|
|
|
}
|
2022-03-02 21:15:28 -08:00
|
|
|
|
2022-08-01 07:55:17 -07:00
|
|
|
pub fn flash_loan_begin<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoanBegin<'info>>,
|
2022-06-27 04:42:27 -07:00
|
|
|
loan_amounts: Vec<u64>,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::flash_loan_begin(ctx, loan_amounts)?;
|
|
|
|
Ok(())
|
2022-06-27 04:42:27 -07:00
|
|
|
}
|
|
|
|
|
2022-08-01 07:55:17 -07:00
|
|
|
pub fn flash_loan_end<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoanEnd<'info>>,
|
2022-08-17 03:36:55 -07:00
|
|
|
flash_loan_type: FlashLoanType,
|
2023-04-14 06:18:02 -07:00
|
|
|
) -> Result<()> {
|
|
|
|
Err(error_msg!("FlashLoanEnd was replaced by FlashLoanEndV2"))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn flash_loan_end_v2<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoanEnd<'info>>,
|
|
|
|
num_loans: u8,
|
|
|
|
flash_loan_type: FlashLoanType,
|
2022-06-27 04:42:27 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2023-04-14 06:18:02 -07:00
|
|
|
instructions::flash_loan_end(ctx, num_loans, flash_loan_type)?;
|
2023-02-14 23:42:07 -08:00
|
|
|
Ok(())
|
2022-06-27 04:42:27 -07:00
|
|
|
}
|
|
|
|
|
2022-08-22 02:02:01 -07:00
|
|
|
pub fn health_region_begin<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, HealthRegionBegin<'info>>,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::health_region_begin(ctx)?;
|
|
|
|
Ok(())
|
2022-08-22 02:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn health_region_end<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, HealthRegionEnd<'info>>,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::health_region_end(ctx)?;
|
|
|
|
Ok(())
|
2022-08-22 02:02:01 -07:00
|
|
|
}
|
|
|
|
|
2022-03-20 02:11:36 -07:00
|
|
|
///
|
|
|
|
/// Serum
|
|
|
|
///
|
|
|
|
|
2022-03-18 05:42:20 -07:00
|
|
|
pub fn serum3_register_market(
|
|
|
|
ctx: Context<Serum3RegisterMarket>,
|
|
|
|
market_index: Serum3MarketIndex,
|
2022-04-12 07:19:58 -07:00
|
|
|
name: String,
|
2022-03-11 03:38:10 -08:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_register_market(ctx, market_index, name)?;
|
|
|
|
Ok(())
|
2022-03-11 03:38:10 -08:00
|
|
|
}
|
|
|
|
|
2023-01-04 00:24:40 -08:00
|
|
|
pub fn serum3_edit_market(
|
|
|
|
ctx: Context<Serum3EditMarket>,
|
|
|
|
reduce_only_opt: Option<bool>,
|
2023-04-20 01:19:23 -07:00
|
|
|
force_close_opt: Option<bool>,
|
2023-01-04 00:24:40 -08:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2023-04-20 01:19:23 -07:00
|
|
|
instructions::serum3_edit_market(ctx, reduce_only_opt, force_close_opt)?;
|
2023-02-14 23:42:07 -08:00
|
|
|
Ok(())
|
2023-01-04 00:24:40 -08:00
|
|
|
}
|
|
|
|
|
2022-07-05 10:31:47 -07:00
|
|
|
// note:
|
|
|
|
// pub fn serum3_edit_market - doesn't exist since a mango serum3 market only contains the properties
|
|
|
|
// registered base and quote token pairs, and serum3 external market its pointing to, and none of them
|
|
|
|
// should be edited once set on creation
|
|
|
|
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn serum3_deregister_market(ctx: Context<Serum3DeregisterMarket>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_deregister_market(ctx)?;
|
|
|
|
Ok(())
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
2022-03-18 05:42:20 -07:00
|
|
|
pub fn serum3_create_open_orders(ctx: Context<Serum3CreateOpenOrders>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_create_open_orders(ctx)?;
|
|
|
|
Ok(())
|
2022-03-11 03:38:10 -08:00
|
|
|
}
|
2022-03-14 07:26:26 -07:00
|
|
|
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn serum3_close_open_orders(ctx: Context<Serum3CloseOpenOrders>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_close_open_orders(ctx)?;
|
|
|
|
Ok(())
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
2022-04-01 23:59:07 -07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2022-03-18 05:42:20 -07:00
|
|
|
pub fn serum3_place_order(
|
|
|
|
ctx: Context<Serum3PlaceOrder>,
|
2022-04-01 23:59:07 -07:00
|
|
|
side: Serum3Side,
|
|
|
|
limit_price: u64,
|
|
|
|
max_base_qty: u64,
|
|
|
|
max_native_quote_qty_including_fees: u64,
|
|
|
|
self_trade_behavior: Serum3SelfTradeBehavior,
|
|
|
|
order_type: Serum3OrderType,
|
|
|
|
client_order_id: u64,
|
|
|
|
limit: u16,
|
2022-03-14 07:26:26 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-04-01 23:59:07 -07:00
|
|
|
instructions::serum3_place_order(
|
|
|
|
ctx,
|
|
|
|
side,
|
|
|
|
limit_price,
|
|
|
|
max_base_qty,
|
|
|
|
max_native_quote_qty_including_fees,
|
|
|
|
self_trade_behavior,
|
|
|
|
order_type,
|
|
|
|
client_order_id,
|
|
|
|
limit,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-03-14 07:26:26 -07:00
|
|
|
}
|
2022-03-18 02:08:53 -07:00
|
|
|
|
2022-03-19 04:11:56 -07:00
|
|
|
pub fn serum3_cancel_order(
|
|
|
|
ctx: Context<Serum3CancelOrder>,
|
2022-04-01 23:59:07 -07:00
|
|
|
side: Serum3Side,
|
|
|
|
order_id: u128,
|
2022-03-19 04:11:56 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_cancel_order(ctx, side, order_id)?;
|
|
|
|
Ok(())
|
2022-03-19 04:11:56 -07:00
|
|
|
}
|
|
|
|
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn serum3_cancel_all_orders(ctx: Context<Serum3CancelAllOrders>, limit: u8) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_cancel_all_orders(ctx, limit)?;
|
|
|
|
Ok(())
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
2023-03-03 05:04:45 -08:00
|
|
|
/// Settles all free funds from the OpenOrders account into the MangoAccount.
|
|
|
|
///
|
|
|
|
/// Any serum "referrer rebates" (ui fees) are considered Mango fees.
|
2022-03-18 07:58:39 -07:00
|
|
|
pub fn serum3_settle_funds(ctx: Context<Serum3SettleFunds>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2023-03-03 05:04:45 -08:00
|
|
|
instructions::serum3_settle_funds(ctx.accounts, None, true)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Like Serum3SettleFunds, but `fees_to_dao` determines if referrer rebates are considered fees
|
|
|
|
/// or are credited to the MangoAccount.
|
|
|
|
pub fn serum3_settle_funds_v2(
|
|
|
|
ctx: Context<Serum3SettleFundsV2>,
|
|
|
|
fees_to_dao: bool,
|
|
|
|
) -> Result<()> {
|
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_settle_funds(
|
|
|
|
&mut ctx.accounts.v1,
|
|
|
|
Some(&mut ctx.accounts.v2),
|
|
|
|
fees_to_dao,
|
|
|
|
)?;
|
2023-02-14 23:42:07 -08:00
|
|
|
Ok(())
|
2022-03-18 07:58:39 -07:00
|
|
|
}
|
|
|
|
|
2022-03-21 04:55:05 -07:00
|
|
|
pub fn serum3_liq_force_cancel_orders(
|
|
|
|
ctx: Context<Serum3LiqForceCancelOrders>,
|
|
|
|
limit: u8,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::serum3_liq_force_cancel_orders(ctx, limit)?;
|
|
|
|
Ok(())
|
2022-03-21 04:55:05 -07:00
|
|
|
}
|
|
|
|
|
2022-09-14 04:25:11 -07:00
|
|
|
// DEPRECATED: use token_liq_with_token
|
2022-03-29 02:49:26 -07:00
|
|
|
pub fn liq_token_with_token(
|
2022-09-14 04:25:11 -07:00
|
|
|
ctx: Context<TokenLiqWithToken>,
|
2022-03-29 02:49:26 -07:00
|
|
|
asset_token_index: TokenIndex,
|
|
|
|
liab_token_index: TokenIndex,
|
|
|
|
max_liab_transfer: I80F48,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-09-14 04:25:11 -07:00
|
|
|
instructions::token_liq_with_token(
|
2022-03-29 02:49:26 -07:00
|
|
|
ctx,
|
|
|
|
asset_token_index,
|
|
|
|
liab_token_index,
|
|
|
|
max_liab_transfer,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-03-29 02:49:26 -07:00
|
|
|
}
|
|
|
|
|
2022-09-14 04:25:11 -07:00
|
|
|
// DEPRECATED: use token_liq_bankruptcy
|
2022-06-29 02:18:59 -07:00
|
|
|
pub fn liq_token_bankruptcy(
|
2022-09-14 04:25:11 -07:00
|
|
|
ctx: Context<TokenLiqBankruptcy>,
|
2022-07-04 04:13:11 -07:00
|
|
|
max_liab_transfer: I80F48,
|
2022-06-29 02:18:59 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_liq_bankruptcy(ctx, max_liab_transfer)?;
|
|
|
|
Ok(())
|
2022-09-14 04:25:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn token_liq_with_token(
|
|
|
|
ctx: Context<TokenLiqWithToken>,
|
|
|
|
asset_token_index: TokenIndex,
|
|
|
|
liab_token_index: TokenIndex,
|
|
|
|
max_liab_transfer: I80F48,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-09-14 04:25:11 -07:00
|
|
|
instructions::token_liq_with_token(
|
|
|
|
ctx,
|
|
|
|
asset_token_index,
|
|
|
|
liab_token_index,
|
|
|
|
max_liab_transfer,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-09-14 04:25:11 -07:00
|
|
|
}
|
|
|
|
|
2023-04-13 03:44:12 -07:00
|
|
|
pub fn token_force_close_borrows_with_token(
|
|
|
|
ctx: Context<TokenForceCloseBorrowsWithToken>,
|
|
|
|
asset_token_index: TokenIndex,
|
|
|
|
liab_token_index: TokenIndex,
|
|
|
|
max_liab_transfer: u64,
|
|
|
|
) -> Result<()> {
|
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_force_close_borrows_with_token(
|
|
|
|
ctx,
|
|
|
|
asset_token_index,
|
|
|
|
liab_token_index,
|
|
|
|
max_liab_transfer,
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-09-14 04:25:11 -07:00
|
|
|
pub fn token_liq_bankruptcy(
|
|
|
|
ctx: Context<TokenLiqBankruptcy>,
|
|
|
|
max_liab_transfer: I80F48,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::token_liq_bankruptcy(ctx, max_liab_transfer)?;
|
|
|
|
Ok(())
|
2022-06-29 02:18:59 -07:00
|
|
|
}
|
|
|
|
|
2022-03-20 02:11:36 -07:00
|
|
|
///
|
|
|
|
/// Perps
|
|
|
|
///
|
|
|
|
|
2022-03-24 09:29:30 -07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2022-03-31 23:01:56 -07:00
|
|
|
pub fn perp_create_market(
|
|
|
|
ctx: Context<PerpCreateMarket>,
|
2022-03-18 23:28:37 -07:00
|
|
|
perp_market_index: PerpMarketIndex,
|
2022-05-06 05:19:49 -07:00
|
|
|
name: String,
|
2022-11-09 04:25:53 -08:00
|
|
|
oracle_config: OracleConfigParams,
|
2022-09-21 00:42:45 -07:00
|
|
|
base_decimals: u8,
|
2022-03-18 02:08:53 -07:00
|
|
|
quote_lot_size: i64,
|
|
|
|
base_lot_size: i64,
|
2023-01-16 07:49:09 -08:00
|
|
|
maint_base_asset_weight: f32,
|
|
|
|
init_base_asset_weight: f32,
|
|
|
|
maint_base_liab_weight: f32,
|
|
|
|
init_base_liab_weight: f32,
|
2023-02-01 07:15:45 -08:00
|
|
|
maint_overall_asset_weight: f32,
|
|
|
|
init_overall_asset_weight: f32,
|
2023-02-02 00:00:37 -08:00
|
|
|
base_liquidation_fee: f32,
|
2022-03-24 09:29:30 -07:00
|
|
|
maker_fee: f32,
|
|
|
|
taker_fee: f32,
|
2022-05-17 01:07:24 -07:00
|
|
|
min_funding: f32,
|
2022-05-17 06:06:29 -07:00
|
|
|
max_funding: f32,
|
2022-05-17 01:07:24 -07:00
|
|
|
impact_quantity: i64,
|
2022-09-12 06:25:50 -07:00
|
|
|
group_insurance_fund: bool,
|
2022-09-22 09:55:12 -07:00
|
|
|
fee_penalty: f32,
|
2022-09-29 03:59:55 -07:00
|
|
|
settle_fee_flat: f32,
|
|
|
|
settle_fee_amount_threshold: f32,
|
|
|
|
settle_fee_fraction_low_health: f32,
|
2022-09-29 05:13:28 -07:00
|
|
|
settle_token_index: TokenIndex,
|
2022-11-30 04:20:19 -08:00
|
|
|
settle_pnl_limit_factor: f32,
|
2022-12-02 03:24:11 -08:00
|
|
|
settle_pnl_limit_window_size_ts: u64,
|
2023-02-02 00:00:37 -08:00
|
|
|
positive_pnl_liquidation_fee: f32,
|
2022-03-18 02:08:53 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-03-31 23:01:56 -07:00
|
|
|
instructions::perp_create_market(
|
2022-03-18 23:28:37 -07:00
|
|
|
ctx,
|
|
|
|
perp_market_index,
|
2023-01-19 00:31:03 -08:00
|
|
|
settle_token_index,
|
2022-05-06 05:19:49 -07:00
|
|
|
name,
|
2022-06-18 07:38:46 -07:00
|
|
|
oracle_config,
|
2022-09-21 00:42:45 -07:00
|
|
|
base_decimals,
|
2022-03-18 23:28:37 -07:00
|
|
|
quote_lot_size,
|
|
|
|
base_lot_size,
|
2023-01-16 07:49:09 -08:00
|
|
|
maint_base_asset_weight,
|
|
|
|
init_base_asset_weight,
|
|
|
|
maint_base_liab_weight,
|
|
|
|
init_base_liab_weight,
|
2023-02-01 07:15:45 -08:00
|
|
|
maint_overall_asset_weight,
|
|
|
|
init_overall_asset_weight,
|
2023-02-02 00:00:37 -08:00
|
|
|
base_liquidation_fee,
|
2022-03-24 09:29:30 -07:00
|
|
|
maker_fee,
|
|
|
|
taker_fee,
|
2022-05-17 01:07:24 -07:00
|
|
|
min_funding,
|
2022-09-29 03:59:55 -07:00
|
|
|
max_funding,
|
2022-05-17 01:07:24 -07:00
|
|
|
impact_quantity,
|
2022-09-12 06:25:50 -07:00
|
|
|
group_insurance_fund,
|
2022-09-22 09:55:12 -07:00
|
|
|
fee_penalty,
|
2022-09-29 03:59:55 -07:00
|
|
|
settle_fee_flat,
|
|
|
|
settle_fee_amount_threshold,
|
|
|
|
settle_fee_fraction_low_health,
|
2022-11-30 04:20:19 -08:00
|
|
|
settle_pnl_limit_factor,
|
2022-12-02 03:24:11 -08:00
|
|
|
settle_pnl_limit_window_size_ts,
|
2023-02-02 00:00:37 -08:00
|
|
|
positive_pnl_liquidation_fee,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-03-18 02:08:53 -07:00
|
|
|
}
|
2022-03-20 02:11:36 -07:00
|
|
|
|
2022-07-05 10:31:47 -07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn perp_edit_market(
|
|
|
|
ctx: Context<PerpEditMarket>,
|
|
|
|
oracle_opt: Option<Pubkey>,
|
2022-11-09 04:25:53 -08:00
|
|
|
oracle_config_opt: Option<OracleConfigParams>,
|
2022-09-21 00:42:45 -07:00
|
|
|
base_decimals_opt: Option<u8>,
|
2023-01-16 07:49:09 -08:00
|
|
|
maint_base_asset_weight_opt: Option<f32>,
|
|
|
|
init_base_asset_weight_opt: Option<f32>,
|
|
|
|
maint_base_liab_weight_opt: Option<f32>,
|
|
|
|
init_base_liab_weight_opt: Option<f32>,
|
2023-02-01 07:15:45 -08:00
|
|
|
maint_overall_asset_weight_opt: Option<f32>,
|
|
|
|
init_overall_asset_weight_opt: Option<f32>,
|
2023-02-02 00:00:37 -08:00
|
|
|
base_liquidation_fee_opt: Option<f32>,
|
2022-07-05 10:31:47 -07:00
|
|
|
maker_fee_opt: Option<f32>,
|
|
|
|
taker_fee_opt: Option<f32>,
|
|
|
|
min_funding_opt: Option<f32>,
|
|
|
|
max_funding_opt: Option<f32>,
|
|
|
|
impact_quantity_opt: Option<i64>,
|
2022-09-12 06:25:50 -07:00
|
|
|
group_insurance_fund_opt: Option<bool>,
|
2022-09-22 09:55:12 -07:00
|
|
|
fee_penalty_opt: Option<f32>,
|
2022-09-29 03:59:55 -07:00
|
|
|
settle_fee_flat_opt: Option<f32>,
|
|
|
|
settle_fee_amount_threshold_opt: Option<f32>,
|
|
|
|
settle_fee_fraction_low_health_opt: Option<f32>,
|
2022-11-24 02:55:22 -08:00
|
|
|
stable_price_delay_interval_seconds_opt: Option<u32>,
|
|
|
|
stable_price_delay_growth_limit_opt: Option<f32>,
|
|
|
|
stable_price_growth_limit_opt: Option<f32>,
|
2022-11-30 04:20:19 -08:00
|
|
|
settle_pnl_limit_factor_opt: Option<f32>,
|
2023-02-02 00:00:37 -08:00
|
|
|
settle_pnl_limit_window_size_ts_opt: Option<u64>,
|
2023-01-04 00:24:40 -08:00
|
|
|
reduce_only_opt: Option<bool>,
|
2023-01-18 04:27:45 -08:00
|
|
|
reset_stable_price: bool,
|
2023-02-02 00:00:37 -08:00
|
|
|
positive_pnl_liquidation_fee_opt: Option<f32>,
|
2023-03-03 01:05:12 -08:00
|
|
|
name_opt: Option<String>,
|
2023-04-19 08:42:01 -07:00
|
|
|
force_close_opt: Option<bool>,
|
2022-07-05 10:31:47 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
2022-07-05 10:31:47 -07:00
|
|
|
instructions::perp_edit_market(
|
|
|
|
ctx,
|
|
|
|
oracle_opt,
|
|
|
|
oracle_config_opt,
|
2022-09-21 00:42:45 -07:00
|
|
|
base_decimals_opt,
|
2023-01-16 07:49:09 -08:00
|
|
|
maint_base_asset_weight_opt,
|
|
|
|
init_base_asset_weight_opt,
|
|
|
|
maint_base_liab_weight_opt,
|
|
|
|
init_base_liab_weight_opt,
|
2023-02-01 07:15:45 -08:00
|
|
|
maint_overall_asset_weight_opt,
|
|
|
|
init_overall_asset_weight_opt,
|
2023-02-02 00:00:37 -08:00
|
|
|
base_liquidation_fee_opt,
|
2022-07-05 10:31:47 -07:00
|
|
|
maker_fee_opt,
|
|
|
|
taker_fee_opt,
|
|
|
|
min_funding_opt,
|
|
|
|
max_funding_opt,
|
|
|
|
impact_quantity_opt,
|
2022-09-12 06:25:50 -07:00
|
|
|
group_insurance_fund_opt,
|
2022-09-22 09:55:12 -07:00
|
|
|
fee_penalty_opt,
|
2022-09-29 03:59:55 -07:00
|
|
|
settle_fee_flat_opt,
|
|
|
|
settle_fee_amount_threshold_opt,
|
|
|
|
settle_fee_fraction_low_health_opt,
|
2022-11-24 02:55:22 -08:00
|
|
|
stable_price_delay_interval_seconds_opt,
|
|
|
|
stable_price_delay_growth_limit_opt,
|
|
|
|
stable_price_growth_limit_opt,
|
2022-11-30 04:20:19 -08:00
|
|
|
settle_pnl_limit_factor_opt,
|
2023-02-02 00:00:37 -08:00
|
|
|
settle_pnl_limit_window_size_ts_opt,
|
2023-01-04 00:24:40 -08:00
|
|
|
reduce_only_opt,
|
2023-01-18 04:27:45 -08:00
|
|
|
reset_stable_price,
|
2023-02-02 00:00:37 -08:00
|
|
|
positive_pnl_liquidation_fee_opt,
|
2023-03-03 01:05:12 -08:00
|
|
|
name_opt,
|
2023-04-19 08:42:01 -07:00
|
|
|
force_close_opt,
|
2023-02-14 23:42:07 -08:00
|
|
|
)?;
|
|
|
|
Ok(())
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn perp_close_market(ctx: Context<PerpCloseMarket>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_close_market(ctx)?;
|
|
|
|
Ok(())
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
2022-09-09 01:50:09 -07:00
|
|
|
pub fn perp_deactivate_position(ctx: Context<PerpDeactivatePosition>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_deactivate_position(ctx)?;
|
|
|
|
Ok(())
|
2022-09-09 01:50:09 -07:00
|
|
|
}
|
|
|
|
|
2022-03-23 01:33:51 -07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2022-03-31 23:01:56 -07:00
|
|
|
pub fn perp_place_order(
|
|
|
|
ctx: Context<PerpPlaceOrder>,
|
2022-03-26 09:06:55 -07:00
|
|
|
side: Side,
|
2022-11-08 06:27:56 -08:00
|
|
|
|
|
|
|
// The price in lots (quote lots per base lots)
|
|
|
|
// - fill orders on the book up to this price or
|
|
|
|
// - place an order on the book at this price.
|
|
|
|
// - ignored for Market orders and potentially adjusted for PostOnlySlide orders.
|
2022-04-01 06:47:12 -07:00
|
|
|
price_lots: i64,
|
2022-11-08 06:27:56 -08:00
|
|
|
|
2022-04-01 06:47:12 -07:00
|
|
|
max_base_lots: i64,
|
|
|
|
max_quote_lots: i64,
|
2022-03-21 12:29:28 -07:00
|
|
|
client_order_id: u64,
|
2022-11-08 06:27:56 -08:00
|
|
|
order_type: PlaceOrderType,
|
2022-11-09 00:59:34 -08:00
|
|
|
reduce_only: bool,
|
2022-11-08 06:27:56 -08:00
|
|
|
|
|
|
|
// Timestamp of when order expires
|
|
|
|
//
|
|
|
|
// Send 0 if you want the order to never expire.
|
|
|
|
// Timestamps in the past mean the instruction is skipped.
|
2022-12-05 06:21:24 -08:00
|
|
|
// Timestamps in the future are reduced to now + 65535s.
|
2022-03-21 12:29:28 -07:00
|
|
|
expiry_timestamp: u64,
|
2022-11-08 06:27:56 -08:00
|
|
|
|
|
|
|
// Maximum number of orders from the book to fill.
|
|
|
|
//
|
|
|
|
// Use this to limit compute used during order matching.
|
|
|
|
// When the limit is reached, processing stops and the instruction succeeds.
|
2022-03-21 12:29:28 -07:00
|
|
|
limit: u8,
|
2023-01-25 00:03:35 -08:00
|
|
|
) -> Result<Option<u128>> {
|
2022-11-08 06:27:56 -08:00
|
|
|
require_gte!(price_lots, 0);
|
|
|
|
|
|
|
|
use crate::state::{Order, OrderParams};
|
|
|
|
let time_in_force = match Order::tif_from_expiry(expiry_timestamp) {
|
|
|
|
Some(t) => t,
|
|
|
|
None => {
|
|
|
|
msg!("Order is already expired");
|
2023-01-25 00:03:35 -08:00
|
|
|
return Ok(None);
|
2022-11-08 06:27:56 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
let order = Order {
|
2022-03-26 09:06:55 -07:00
|
|
|
side,
|
2022-04-01 06:47:12 -07:00
|
|
|
max_base_lots,
|
|
|
|
max_quote_lots,
|
2022-03-21 12:29:28 -07:00
|
|
|
client_order_id,
|
2022-11-09 00:59:34 -08:00
|
|
|
reduce_only,
|
2022-11-08 06:27:56 -08:00
|
|
|
time_in_force,
|
2023-05-15 01:40:41 -07:00
|
|
|
self_trade_behavior: SelfTradeBehavior::default(),
|
2022-11-08 06:27:56 -08:00
|
|
|
params: match order_type {
|
2023-05-15 01:40:41 -07:00
|
|
|
PlaceOrderType::Market => OrderParams::Market {},
|
|
|
|
PlaceOrderType::ImmediateOrCancel => OrderParams::ImmediateOrCancel { price_lots },
|
|
|
|
_ => OrderParams::Fixed {
|
|
|
|
price_lots,
|
|
|
|
order_type: order_type.to_post_order_type()?,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
return instructions::perp_place_order(ctx, order, limit);
|
|
|
|
|
|
|
|
#[cfg(not(feature = "enable-gpl"))]
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn perp_place_order_v2(
|
|
|
|
ctx: Context<PerpPlaceOrder>,
|
|
|
|
side: Side,
|
|
|
|
|
|
|
|
// The price in lots (quote lots per base lots)
|
|
|
|
// - fill orders on the book up to this price or
|
|
|
|
// - place an order on the book at this price.
|
|
|
|
// - ignored for Market orders and potentially adjusted for PostOnlySlide orders.
|
|
|
|
price_lots: i64,
|
|
|
|
|
|
|
|
max_base_lots: i64,
|
|
|
|
max_quote_lots: i64,
|
|
|
|
client_order_id: u64,
|
|
|
|
order_type: PlaceOrderType,
|
|
|
|
self_trade_behavior: SelfTradeBehavior,
|
|
|
|
reduce_only: bool,
|
|
|
|
|
|
|
|
// Timestamp of when order expires
|
|
|
|
//
|
|
|
|
// Send 0 if you want the order to never expire.
|
|
|
|
// Timestamps in the past mean the instruction is skipped.
|
|
|
|
// Timestamps in the future are reduced to now + 65535s.
|
|
|
|
expiry_timestamp: u64,
|
|
|
|
|
|
|
|
// Maximum number of orders from the book to fill.
|
|
|
|
//
|
|
|
|
// Use this to limit compute used during order matching.
|
|
|
|
// When the limit is reached, processing stops and the instruction succeeds.
|
|
|
|
limit: u8,
|
|
|
|
) -> Result<Option<u128>> {
|
|
|
|
require_gte!(price_lots, 0);
|
|
|
|
|
|
|
|
use crate::state::{Order, OrderParams};
|
|
|
|
let time_in_force = match Order::tif_from_expiry(expiry_timestamp) {
|
|
|
|
Some(t) => t,
|
|
|
|
None => {
|
|
|
|
msg!("Order is already expired");
|
|
|
|
return Ok(None);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let order = Order {
|
|
|
|
side,
|
|
|
|
max_base_lots,
|
|
|
|
max_quote_lots,
|
|
|
|
client_order_id,
|
|
|
|
reduce_only,
|
|
|
|
time_in_force,
|
|
|
|
self_trade_behavior,
|
|
|
|
params: match order_type {
|
|
|
|
PlaceOrderType::Market => OrderParams::Market {},
|
2022-11-08 06:27:56 -08:00
|
|
|
PlaceOrderType::ImmediateOrCancel => OrderParams::ImmediateOrCancel { price_lots },
|
|
|
|
_ => OrderParams::Fixed {
|
|
|
|
price_lots,
|
|
|
|
order_type: order_type.to_post_order_type()?,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
return instructions::perp_place_order(ctx, order, limit);
|
|
|
|
|
|
|
|
#[cfg(not(feature = "enable-gpl"))]
|
|
|
|
Ok(None)
|
2022-11-08 06:27:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn perp_place_order_pegged(
|
|
|
|
ctx: Context<PerpPlaceOrder>,
|
|
|
|
side: Side,
|
|
|
|
|
|
|
|
// The adjustment from the oracle price, in lots (quote lots per base lots).
|
|
|
|
// Orders on the book may be filled at oracle + adjustment (depends on order type).
|
|
|
|
price_offset_lots: i64,
|
|
|
|
|
|
|
|
// The limit at which the pegged order shall expire.
|
|
|
|
// May be -1 to denote no peg limit.
|
|
|
|
//
|
|
|
|
// Example: An bid pegged to -20 with peg_limit 100 would expire if the oracle hits 121.
|
|
|
|
peg_limit: i64,
|
|
|
|
|
|
|
|
max_base_lots: i64,
|
|
|
|
max_quote_lots: i64,
|
|
|
|
client_order_id: u64,
|
|
|
|
order_type: PlaceOrderType,
|
2022-11-09 00:59:34 -08:00
|
|
|
reduce_only: bool,
|
2022-11-08 06:27:56 -08:00
|
|
|
|
|
|
|
// Timestamp of when order expires
|
|
|
|
//
|
|
|
|
// Send 0 if you want the order to never expire.
|
|
|
|
// Timestamps in the past mean the instruction is skipped.
|
2022-12-05 06:21:24 -08:00
|
|
|
// Timestamps in the future are reduced to now + 65535s.
|
2022-11-08 06:27:56 -08:00
|
|
|
expiry_timestamp: u64,
|
|
|
|
|
|
|
|
// Maximum number of orders from the book to fill.
|
|
|
|
//
|
|
|
|
// Use this to limit compute used during order matching.
|
|
|
|
// When the limit is reached, processing stops and the instruction succeeds.
|
|
|
|
limit: u8,
|
2022-12-01 01:43:47 -08:00
|
|
|
|
|
|
|
// Oracle staleness limit, in slots. Set to -1 to disable.
|
|
|
|
//
|
|
|
|
// WARNING: Not currently implemented.
|
|
|
|
max_oracle_staleness_slots: i32,
|
2023-01-25 00:03:35 -08:00
|
|
|
) -> Result<Option<u128>> {
|
2022-11-08 06:27:56 -08:00
|
|
|
require_gte!(peg_limit, -1);
|
2022-12-01 01:43:47 -08:00
|
|
|
require_eq!(max_oracle_staleness_slots, -1); // unimplemented
|
2022-11-08 06:27:56 -08:00
|
|
|
|
|
|
|
use crate::state::{Order, OrderParams};
|
|
|
|
let time_in_force = match Order::tif_from_expiry(expiry_timestamp) {
|
|
|
|
Some(t) => t,
|
|
|
|
None => {
|
|
|
|
msg!("Order is already expired");
|
2023-01-25 00:03:35 -08:00
|
|
|
return Ok(None);
|
2022-11-08 06:27:56 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
let order = Order {
|
|
|
|
side,
|
|
|
|
max_base_lots,
|
|
|
|
max_quote_lots,
|
|
|
|
client_order_id,
|
2022-11-09 00:59:34 -08:00
|
|
|
reduce_only,
|
2022-11-08 06:27:56 -08:00
|
|
|
time_in_force,
|
2023-05-15 01:40:41 -07:00
|
|
|
self_trade_behavior: SelfTradeBehavior::DecrementTake,
|
|
|
|
params: OrderParams::OraclePegged {
|
|
|
|
price_offset_lots,
|
|
|
|
order_type: order_type.to_post_order_type()?,
|
|
|
|
peg_limit,
|
|
|
|
max_oracle_staleness_slots,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
return instructions::perp_place_order(ctx, order, limit);
|
|
|
|
|
|
|
|
#[cfg(not(feature = "enable-gpl"))]
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn perp_place_order_pegged_v2(
|
|
|
|
ctx: Context<PerpPlaceOrder>,
|
|
|
|
side: Side,
|
|
|
|
|
|
|
|
// The adjustment from the oracle price, in lots (quote lots per base lots).
|
|
|
|
// Orders on the book may be filled at oracle + adjustment (depends on order type).
|
|
|
|
price_offset_lots: i64,
|
|
|
|
|
|
|
|
// The limit at which the pegged order shall expire.
|
|
|
|
// May be -1 to denote no peg limit.
|
|
|
|
//
|
|
|
|
// Example: An bid pegged to -20 with peg_limit 100 would expire if the oracle hits 121.
|
|
|
|
peg_limit: i64,
|
|
|
|
|
|
|
|
max_base_lots: i64,
|
|
|
|
max_quote_lots: i64,
|
|
|
|
client_order_id: u64,
|
|
|
|
order_type: PlaceOrderType,
|
|
|
|
self_trade_behavior: SelfTradeBehavior,
|
|
|
|
reduce_only: bool,
|
|
|
|
|
|
|
|
// Timestamp of when order expires
|
|
|
|
//
|
|
|
|
// Send 0 if you want the order to never expire.
|
|
|
|
// Timestamps in the past mean the instruction is skipped.
|
|
|
|
// Timestamps in the future are reduced to now + 65535s.
|
|
|
|
expiry_timestamp: u64,
|
|
|
|
|
|
|
|
// Maximum number of orders from the book to fill.
|
|
|
|
//
|
|
|
|
// Use this to limit compute used during order matching.
|
|
|
|
// When the limit is reached, processing stops and the instruction succeeds.
|
|
|
|
limit: u8,
|
|
|
|
|
|
|
|
// Oracle staleness limit, in slots. Set to -1 to disable.
|
|
|
|
//
|
|
|
|
// WARNING: Not currently implemented.
|
|
|
|
max_oracle_staleness_slots: i32,
|
|
|
|
) -> Result<Option<u128>> {
|
|
|
|
require_gte!(peg_limit, -1);
|
|
|
|
require_eq!(max_oracle_staleness_slots, -1); // unimplemented
|
|
|
|
|
|
|
|
use crate::state::{Order, OrderParams};
|
|
|
|
let time_in_force = match Order::tif_from_expiry(expiry_timestamp) {
|
|
|
|
Some(t) => t,
|
|
|
|
None => {
|
|
|
|
msg!("Order is already expired");
|
|
|
|
return Ok(None);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let order = Order {
|
|
|
|
side,
|
|
|
|
max_base_lots,
|
|
|
|
max_quote_lots,
|
|
|
|
client_order_id,
|
|
|
|
reduce_only,
|
|
|
|
time_in_force,
|
|
|
|
self_trade_behavior,
|
2022-11-08 06:27:56 -08:00
|
|
|
params: OrderParams::OraclePegged {
|
|
|
|
price_offset_lots,
|
|
|
|
order_type: order_type.to_post_order_type()?,
|
|
|
|
peg_limit,
|
2022-12-01 01:43:47 -08:00
|
|
|
max_oracle_staleness_slots,
|
2022-11-08 06:27:56 -08:00
|
|
|
},
|
|
|
|
};
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
return instructions::perp_place_order(ctx, order, limit);
|
|
|
|
|
|
|
|
#[cfg(not(feature = "enable-gpl"))]
|
|
|
|
Ok(None)
|
2022-03-20 02:11:36 -07:00
|
|
|
}
|
2022-03-25 22:16:52 -07:00
|
|
|
|
2022-11-08 06:27:56 -08:00
|
|
|
pub fn perp_cancel_order(ctx: Context<PerpCancelOrder>, order_id: u128) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_cancel_order(ctx, order_id)?;
|
|
|
|
Ok(())
|
2022-03-28 12:13:16 -07:00
|
|
|
}
|
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
pub fn perp_cancel_order_by_client_order_id(
|
|
|
|
ctx: Context<PerpCancelOrderByClientOrderId>,
|
|
|
|
client_order_id: u64,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_cancel_order_by_client_order_id(ctx, client_order_id)?;
|
|
|
|
Ok(())
|
2022-05-16 01:34:22 -07:00
|
|
|
}
|
2022-05-03 09:07:31 -07:00
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
pub fn perp_cancel_all_orders(ctx: Context<PerpCancelAllOrders>, limit: u8) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_cancel_all_orders(ctx, limit)?;
|
|
|
|
Ok(())
|
2022-05-16 01:34:22 -07:00
|
|
|
}
|
2022-05-03 09:07:31 -07:00
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
pub fn perp_cancel_all_orders_by_side(
|
|
|
|
ctx: Context<PerpCancelAllOrdersBySide>,
|
|
|
|
side_option: Option<Side>,
|
|
|
|
limit: u8,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_cancel_all_orders_by_side(ctx, side_option, limit)?;
|
|
|
|
Ok(())
|
2022-05-16 01:34:22 -07:00
|
|
|
}
|
2022-05-03 09:07:31 -07:00
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
pub fn perp_consume_events(ctx: Context<PerpConsumeEvents>, limit: usize) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_consume_events(ctx, limit)?;
|
|
|
|
Ok(())
|
2022-05-16 01:34:22 -07:00
|
|
|
}
|
|
|
|
|
2022-05-17 06:59:47 -07:00
|
|
|
pub fn perp_update_funding(ctx: Context<PerpUpdateFunding>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_update_funding(ctx)?;
|
|
|
|
Ok(())
|
2022-05-17 06:59:47 -07:00
|
|
|
}
|
|
|
|
|
2022-09-29 03:59:55 -07:00
|
|
|
pub fn perp_settle_pnl(ctx: Context<PerpSettlePnl>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_settle_pnl(ctx)?;
|
|
|
|
Ok(())
|
2022-09-01 09:07:57 -07:00
|
|
|
}
|
2022-09-05 07:18:40 -07:00
|
|
|
|
2023-04-19 08:42:01 -07:00
|
|
|
pub fn perp_force_close_position(ctx: Context<PerpForceClosePosition>) -> Result<()> {
|
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_force_close_position(ctx)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-09-09 03:29:02 -07:00
|
|
|
pub fn perp_settle_fees(ctx: Context<PerpSettleFees>, max_settle_amount: u64) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_settle_fees(ctx, max_settle_amount)?;
|
|
|
|
Ok(())
|
2022-09-05 07:18:40 -07:00
|
|
|
}
|
2022-09-07 07:10:49 -07:00
|
|
|
|
2023-02-02 00:00:37 -08:00
|
|
|
pub fn perp_liq_base_or_positive_pnl(
|
|
|
|
ctx: Context<PerpLiqBaseOrPositivePnl>,
|
2022-09-07 07:10:49 -07:00
|
|
|
max_base_transfer: i64,
|
2023-02-02 00:00:37 -08:00
|
|
|
max_pnl_transfer: u64,
|
2022-09-07 07:10:49 -07:00
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_liq_base_or_positive_pnl(ctx, max_base_transfer, max_pnl_transfer)?;
|
|
|
|
Ok(())
|
2022-09-07 07:10:49 -07:00
|
|
|
}
|
|
|
|
|
2022-09-08 04:10:24 -07:00
|
|
|
pub fn perp_liq_force_cancel_orders(
|
|
|
|
ctx: Context<PerpLiqForceCancelOrders>,
|
|
|
|
limit: u8,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_liq_force_cancel_orders(ctx, limit)?;
|
|
|
|
Ok(())
|
2022-09-08 03:19:03 -07:00
|
|
|
}
|
|
|
|
|
2023-02-02 00:00:37 -08:00
|
|
|
pub fn perp_liq_negative_pnl_or_bankruptcy(
|
|
|
|
ctx: Context<PerpLiqNegativePnlOrBankruptcy>,
|
2022-09-12 06:25:50 -07:00
|
|
|
max_liab_transfer: u64,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::perp_liq_negative_pnl_or_bankruptcy(ctx, max_liab_transfer)?;
|
|
|
|
Ok(())
|
2022-09-12 06:25:50 -07:00
|
|
|
}
|
2022-05-03 09:07:31 -07:00
|
|
|
|
2022-09-14 01:55:24 -07:00
|
|
|
pub fn alt_set(ctx: Context<AltSet>, index: u8) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::alt_set(ctx, index)?;
|
|
|
|
Ok(())
|
2022-09-14 01:55:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn alt_extend(
|
|
|
|
ctx: Context<AltExtend>,
|
|
|
|
index: u8,
|
|
|
|
new_addresses: Vec<Pubkey>,
|
|
|
|
) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::alt_extend(ctx, index, new_addresses)?;
|
|
|
|
Ok(())
|
2022-09-14 01:55:24 -07:00
|
|
|
}
|
|
|
|
|
2022-07-04 03:29:35 -07:00
|
|
|
pub fn compute_account_data(ctx: Context<ComputeAccountData>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::compute_account_data(ctx)?;
|
|
|
|
Ok(())
|
2022-06-20 08:55:30 -07:00
|
|
|
}
|
|
|
|
|
2022-03-25 22:16:52 -07:00
|
|
|
///
|
|
|
|
/// benchmark
|
|
|
|
///
|
2022-05-16 01:34:22 -07:00
|
|
|
|
2022-05-03 09:17:58 -07:00
|
|
|
pub fn benchmark(ctx: Context<Benchmark>) -> Result<()> {
|
2023-02-14 23:42:07 -08:00
|
|
|
#[cfg(feature = "enable-gpl")]
|
|
|
|
instructions::benchmark(ctx)?;
|
|
|
|
Ok(())
|
2022-03-25 22:16:52 -07:00
|
|
|
}
|
2022-01-21 10:21:46 -08:00
|
|
|
}
|
2022-02-02 02:55:44 -08:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Mango;
|
|
|
|
|
|
|
|
impl anchor_lang::Id for Mango {
|
|
|
|
fn id() -> Pubkey {
|
|
|
|
ID
|
|
|
|
}
|
|
|
|
}
|
2023-01-04 10:13:29 -08:00
|
|
|
|
|
|
|
#[cfg(not(feature = "no-entrypoint"))]
|
|
|
|
use {default_env::default_env, solana_security_txt::security_txt};
|
|
|
|
#[cfg(not(feature = "no-entrypoint"))]
|
|
|
|
security_txt! {
|
|
|
|
name: "Mango v4",
|
|
|
|
project_url: "https://mango.markets",
|
|
|
|
contacts: "email:hello@blockworks.foundation,link:https://docs.mango.markets/mango-markets/bug-bounty,discord:https://discord.gg/mangomarkets",
|
|
|
|
policy: "https://github.com/blockworks-foundation/mango-v4/blob/main/SECURITY.md",
|
|
|
|
preferred_languages: "en",
|
|
|
|
source_code: "https://github.com/blockworks-foundation/mango-v4",
|
|
|
|
source_revision: default_env!("GITHUB_SHA", "Unknown source revision"),
|
|
|
|
source_release: default_env!("GITHUB_REF_NAME", "Unknown source release")
|
|
|
|
}
|