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-01-21 10:21:46 -08:00
|
|
|
extern crate static_assertions;
|
|
|
|
|
|
|
|
use anchor_lang::prelude::*;
|
|
|
|
|
2022-02-28 02:07:04 -08:00
|
|
|
use instructions::*;
|
|
|
|
|
2022-06-08 04:43:12 -07:00
|
|
|
pub mod accounts_zerocopy;
|
2022-03-01 04:56:24 -08:00
|
|
|
pub mod address_lookup_table;
|
2022-03-02 21:15:28 -08:00
|
|
|
pub mod error;
|
2022-07-04 03:29:35 -07:00
|
|
|
pub mod events;
|
2022-03-02 21:15:28 -08:00
|
|
|
pub mod instructions;
|
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
|
|
|
|
2022-08-07 05:16:06 -07:00
|
|
|
use state::{OracleConfig, OrderType, PerpMarketIndex, Serum3MarketIndex, Side, TokenIndex};
|
2022-03-11 03:38:10 -08:00
|
|
|
|
2022-03-30 08:16:32 -07:00
|
|
|
declare_id!("m43thNJ58XCjL798ZSq6JGAG1BnWskhdq5or6kcnfsD");
|
2022-01-21 10:21:46 -08:00
|
|
|
|
|
|
|
#[program]
|
|
|
|
pub mod mango_v4 {
|
2022-03-18 23:28:37 -07:00
|
|
|
|
2022-08-07 05:16:06 -07:00
|
|
|
use crate::state::OracleConfig;
|
2022-06-18 07:38:46 -07:00
|
|
|
|
2022-01-21 10:21:46 -08:00
|
|
|
use super::*;
|
|
|
|
|
2022-08-01 03:56:29 -07:00
|
|
|
pub fn group_create(
|
|
|
|
ctx: Context<GroupCreate>,
|
|
|
|
group_num: u32,
|
|
|
|
testing: u8,
|
|
|
|
version: u8,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::group_create(ctx, group_num, testing, version)
|
2022-06-09 09:27:31 -07:00
|
|
|
}
|
|
|
|
|
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>,
|
|
|
|
testing_opt: Option<u8>,
|
|
|
|
version_opt: Option<u8>,
|
2022-07-31 00:28:16 -07:00
|
|
|
) -> Result<()> {
|
2022-08-13 10:54:58 -07:00
|
|
|
instructions::group_edit(
|
|
|
|
ctx,
|
|
|
|
admin_opt,
|
|
|
|
fast_listing_admin_opt,
|
|
|
|
testing_opt,
|
|
|
|
version_opt,
|
|
|
|
)
|
2022-07-31 00:28:16 -07:00
|
|
|
}
|
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn group_close(ctx: Context<GroupClose>) -> Result<()> {
|
|
|
|
instructions::group_close(ctx)
|
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-06-18 07:38:46 -07:00
|
|
|
oracle_config: OracleConfig,
|
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-02-25 09:29:54 -08:00
|
|
|
) -> Result<()> {
|
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-02-25 09:29:54 -08:00
|
|
|
)
|
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<()> {
|
2022-08-03 04:50:49 -07:00
|
|
|
instructions::token_register_trustless(ctx, token_index, name)
|
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>,
|
|
|
|
bank_num: u64,
|
|
|
|
oracle_opt: Option<Pubkey>,
|
|
|
|
oracle_config_opt: Option<OracleConfig>,
|
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>,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::token_edit(
|
|
|
|
ctx,
|
|
|
|
bank_num,
|
|
|
|
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-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<()> {
|
|
|
|
instructions::token_add_bank(ctx, token_index, bank_num)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn token_deregister<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>,
|
|
|
|
token_index: TokenIndex,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::token_deregister(ctx, token_index)
|
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<()> {
|
|
|
|
instructions::token_update_index_and_rate(ctx)
|
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<()> {
|
2022-08-07 05:16:06 -07:00
|
|
|
instructions::account_create(
|
|
|
|
ctx,
|
|
|
|
account_num,
|
|
|
|
token_count,
|
|
|
|
serum3_count,
|
|
|
|
perp_count,
|
|
|
|
perp_oo_count,
|
|
|
|
name,
|
|
|
|
)
|
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<()> {
|
|
|
|
instructions::account_expand(ctx, token_count, serum3_count, perp_count, perp_oo_count)
|
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<()> {
|
2022-07-06 05:51:15 -07:00
|
|
|
instructions::account_edit(ctx, name_opt, delegate_opt)
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
2022-05-16 01:34:22 -07:00
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn account_close(ctx: Context<AccountClose>) -> Result<()> {
|
|
|
|
instructions::account_close(ctx)
|
2022-03-31 08:22:56 -07:00
|
|
|
}
|
|
|
|
|
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<()> {
|
|
|
|
instructions::stub_oracle_create(ctx, price)
|
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<()> {
|
|
|
|
instructions::stub_oracle_close(ctx)
|
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<()> {
|
|
|
|
instructions::stub_oracle_set(ctx, price)
|
2022-02-28 03:37:07 -08:00
|
|
|
}
|
|
|
|
|
2022-07-11 08:08:32 -07:00
|
|
|
// NOTE: keep disc synced in token_update_index_and_rate ix
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn token_deposit(ctx: Context<TokenDeposit>, amount: u64) -> Result<()> {
|
|
|
|
instructions::token_deposit(ctx, amount)
|
2022-02-22 05:23:13 -08:00
|
|
|
}
|
2022-02-25 06:14:15 -08:00
|
|
|
|
2022-07-11 08:08:32 -07:00
|
|
|
// NOTE: keep disc synced in token_update_index_and_rate ix
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn token_withdraw(
|
|
|
|
ctx: Context<TokenWithdraw>,
|
|
|
|
amount: u64,
|
|
|
|
allow_borrow: bool,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::token_withdraw(ctx, amount, allow_borrow)
|
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<()> {
|
2022-08-01 07:55:17 -07:00
|
|
|
instructions::flash_loan_begin(ctx, loan_amounts)
|
2022-06-27 04:42:27 -07:00
|
|
|
}
|
|
|
|
|
2022-08-01 07:55:17 -07:00
|
|
|
// NOTE: keep disc synced in flash_loan.rs
|
|
|
|
pub fn flash_loan_end<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoanEnd<'info>>,
|
2022-06-27 04:42:27 -07:00
|
|
|
) -> Result<()> {
|
2022-08-01 07:55:17 -07:00
|
|
|
instructions::flash_loan_end(ctx)
|
2022-06-27 04:42:27 -07:00
|
|
|
}
|
|
|
|
|
2022-03-20 02:11:36 -07:00
|
|
|
///
|
|
|
|
/// Serum
|
|
|
|
///
|
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
// TODO deposit/withdraw msrm
|
|
|
|
|
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<()> {
|
2022-04-12 07:19:58 -07:00
|
|
|
instructions::serum3_register_market(ctx, market_index, name)
|
2022-03-11 03:38:10 -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<()> {
|
|
|
|
instructions::serum3_deregister_market(ctx)
|
|
|
|
}
|
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
// TODO serum3_change_spot_market_params
|
|
|
|
|
2022-03-18 05:42:20 -07:00
|
|
|
pub fn serum3_create_open_orders(ctx: Context<Serum3CreateOpenOrders>) -> Result<()> {
|
|
|
|
instructions::serum3_create_open_orders(ctx)
|
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<()> {
|
|
|
|
instructions::serum3_close_open_orders(ctx)
|
|
|
|
}
|
|
|
|
|
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<()> {
|
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,
|
|
|
|
)
|
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<()> {
|
2022-04-01 23:59:07 -07:00
|
|
|
instructions::serum3_cancel_order(ctx, side, order_id)
|
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<()> {
|
|
|
|
instructions::serum3_cancel_all_orders(ctx, limit)
|
|
|
|
}
|
|
|
|
|
2022-03-18 07:58:39 -07:00
|
|
|
pub fn serum3_settle_funds(ctx: Context<Serum3SettleFunds>) -> Result<()> {
|
|
|
|
instructions::serum3_settle_funds(ctx)
|
|
|
|
}
|
|
|
|
|
2022-03-21 04:55:05 -07:00
|
|
|
pub fn serum3_liq_force_cancel_orders(
|
|
|
|
ctx: Context<Serum3LiqForceCancelOrders>,
|
|
|
|
limit: u8,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::serum3_liq_force_cancel_orders(ctx, limit)
|
|
|
|
}
|
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
// TODO serum3_cancel_all_spot_orders
|
|
|
|
|
2022-03-29 02:49:26 -07:00
|
|
|
pub fn liq_token_with_token(
|
|
|
|
ctx: Context<LiqTokenWithToken>,
|
|
|
|
asset_token_index: TokenIndex,
|
|
|
|
liab_token_index: TokenIndex,
|
|
|
|
max_liab_transfer: I80F48,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::liq_token_with_token(
|
|
|
|
ctx,
|
|
|
|
asset_token_index,
|
|
|
|
liab_token_index,
|
|
|
|
max_liab_transfer,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-29 02:18:59 -07:00
|
|
|
pub fn liq_token_bankruptcy(
|
|
|
|
ctx: Context<LiqTokenBankruptcy>,
|
|
|
|
liab_token_index: TokenIndex,
|
2022-07-04 04:13:11 -07:00
|
|
|
max_liab_transfer: I80F48,
|
2022-06-29 02:18:59 -07:00
|
|
|
) -> Result<()> {
|
2022-07-04 04:13:11 -07:00
|
|
|
instructions::liq_token_bankruptcy(ctx, liab_token_index, max_liab_transfer)
|
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-06-18 07:38:46 -07:00
|
|
|
oracle_config: OracleConfig,
|
2022-03-18 23:28:37 -07:00
|
|
|
base_token_index_opt: Option<TokenIndex>,
|
2022-06-02 01:36:04 -07:00
|
|
|
base_token_decimals: u8,
|
2022-03-18 02:08:53 -07:00
|
|
|
quote_lot_size: i64,
|
|
|
|
base_lot_size: i64,
|
2022-03-24 11:15:46 -07:00
|
|
|
maint_asset_weight: f32,
|
|
|
|
init_asset_weight: f32,
|
|
|
|
maint_liab_weight: f32,
|
|
|
|
init_liab_weight: f32,
|
2022-03-24 09:29:30 -07:00
|
|
|
liquidation_fee: f32,
|
|
|
|
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-03-18 02:08:53 -07:00
|
|
|
) -> Result<()> {
|
2022-03-31 23:01:56 -07:00
|
|
|
instructions::perp_create_market(
|
2022-03-18 23:28:37 -07:00
|
|
|
ctx,
|
|
|
|
perp_market_index,
|
2022-05-06 05:19:49 -07:00
|
|
|
name,
|
2022-06-18 07:38:46 -07:00
|
|
|
oracle_config,
|
2022-03-18 23:28:37 -07:00
|
|
|
base_token_index_opt,
|
2022-06-02 01:36:04 -07:00
|
|
|
base_token_decimals,
|
2022-03-18 23:28:37 -07:00
|
|
|
quote_lot_size,
|
|
|
|
base_lot_size,
|
2022-03-24 11:15:46 -07:00
|
|
|
maint_asset_weight,
|
|
|
|
init_asset_weight,
|
|
|
|
maint_liab_weight,
|
|
|
|
init_liab_weight,
|
2022-03-24 09:29:30 -07:00
|
|
|
liquidation_fee,
|
|
|
|
maker_fee,
|
|
|
|
taker_fee,
|
2022-05-17 01:07:24 -07:00
|
|
|
max_funding,
|
|
|
|
min_funding,
|
|
|
|
impact_quantity,
|
2022-03-18 23:28:37 -07:00
|
|
|
)
|
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>,
|
|
|
|
oracle_config_opt: Option<OracleConfig>,
|
|
|
|
base_token_index_opt: Option<TokenIndex>,
|
|
|
|
base_token_decimals_opt: Option<u8>,
|
|
|
|
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>,
|
|
|
|
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>,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::perp_edit_market(
|
|
|
|
ctx,
|
|
|
|
oracle_opt,
|
|
|
|
oracle_config_opt,
|
|
|
|
base_token_index_opt,
|
|
|
|
base_token_decimals_opt,
|
|
|
|
maint_asset_weight_opt,
|
|
|
|
init_asset_weight_opt,
|
|
|
|
maint_liab_weight_opt,
|
|
|
|
init_liab_weight_opt,
|
|
|
|
liquidation_fee_opt,
|
|
|
|
maker_fee_opt,
|
|
|
|
taker_fee_opt,
|
|
|
|
min_funding_opt,
|
|
|
|
max_funding_opt,
|
|
|
|
impact_quantity_opt,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-09 09:27:31 -07:00
|
|
|
pub fn perp_close_market(ctx: Context<PerpCloseMarket>) -> Result<()> {
|
|
|
|
instructions::perp_close_market(ctx)
|
|
|
|
}
|
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
// TODO perp_change_perp_market_params
|
|
|
|
|
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-04-01 06:47:12 -07:00
|
|
|
price_lots: i64,
|
|
|
|
max_base_lots: i64,
|
|
|
|
max_quote_lots: i64,
|
2022-03-21 12:29:28 -07:00
|
|
|
client_order_id: u64,
|
|
|
|
order_type: OrderType,
|
|
|
|
expiry_timestamp: u64,
|
|
|
|
limit: u8,
|
|
|
|
) -> Result<()> {
|
2022-03-31 23:01:56 -07:00
|
|
|
instructions::perp_place_order(
|
2022-03-21 12:29:28 -07:00
|
|
|
ctx,
|
2022-03-26 09:06:55 -07:00
|
|
|
side,
|
2022-04-01 06:47:12 -07:00
|
|
|
price_lots,
|
|
|
|
max_base_lots,
|
|
|
|
max_quote_lots,
|
2022-03-21 12:29:28 -07:00
|
|
|
client_order_id,
|
|
|
|
order_type,
|
2022-03-21 23:09:49 -07:00
|
|
|
expiry_timestamp,
|
2022-03-21 12:29:28 -07:00
|
|
|
limit,
|
|
|
|
)
|
2022-03-20 02:11:36 -07:00
|
|
|
}
|
2022-03-25 22:16:52 -07:00
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
pub fn perp_cancel_order(ctx: Context<PerpCancelOrder>, order_id: i128) -> Result<()> {
|
|
|
|
instructions::perp_cancel_order(ctx, order_id)
|
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<()> {
|
|
|
|
instructions::perp_cancel_order_by_client_order_id(ctx, client_order_id)
|
|
|
|
}
|
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<()> {
|
|
|
|
instructions::perp_cancel_all_orders(ctx, limit)
|
|
|
|
}
|
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<()> {
|
|
|
|
instructions::perp_cancel_all_orders_by_side(ctx, side_option, limit)
|
|
|
|
}
|
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<()> {
|
|
|
|
instructions::perp_consume_events(ctx, limit)
|
|
|
|
}
|
|
|
|
|
2022-05-17 06:59:47 -07:00
|
|
|
pub fn perp_update_funding(ctx: Context<PerpUpdateFunding>) -> Result<()> {
|
|
|
|
instructions::perp_update_funding(ctx)
|
|
|
|
}
|
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
// TODO
|
2022-05-03 09:07:31 -07:00
|
|
|
|
|
|
|
// perp_force_cancel_order
|
2022-05-03 09:17:58 -07:00
|
|
|
|
2022-05-03 09:07:31 -07:00
|
|
|
// liquidate_token_and_perp
|
|
|
|
// liquidate_perp_and_perp
|
|
|
|
|
|
|
|
// settle_* - settle_funds, settle_pnl, settle_fees
|
|
|
|
|
|
|
|
// resolve_banktruptcy
|
|
|
|
|
2022-07-04 03:29:35 -07:00
|
|
|
pub fn compute_account_data(ctx: Context<ComputeAccountData>) -> Result<()> {
|
|
|
|
instructions::compute_account_data(ctx)
|
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<()> {
|
|
|
|
instructions::benchmark(ctx)
|
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
|
|
|
|
}
|
|
|
|
}
|