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-03-01 04:56:24 -08:00
|
|
|
pub mod address_lookup_table;
|
2022-03-02 21:15:28 -08:00
|
|
|
pub mod error;
|
|
|
|
pub mod instructions;
|
2022-03-18 07:58:39 -07:00
|
|
|
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-03-26 09:06:55 -07:00
|
|
|
use state::{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-01-21 10:21:46 -08:00
|
|
|
use super::*;
|
|
|
|
|
2022-02-22 00:49:02 -08:00
|
|
|
pub fn create_group(ctx: Context<CreateGroup>) -> Result<()> {
|
|
|
|
instructions::create_group(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-02-25 09:29:54 -08:00
|
|
|
pub fn register_token(
|
|
|
|
ctx: Context<RegisterToken>,
|
2022-03-14 05:19:50 -07:00
|
|
|
token_index: TokenIndex,
|
2022-04-12 07:19:58 -07:00
|
|
|
name: String,
|
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<()> {
|
|
|
|
instructions::register_token(
|
|
|
|
ctx,
|
2022-03-14 05:19:50 -07:00
|
|
|
token_index,
|
2022-04-12 07:19:58 -07:00
|
|
|
name,
|
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-04-09 07:53:30 -07:00
|
|
|
pub fn update_index(ctx: Context<UpdateIndex>) -> Result<()> {
|
|
|
|
instructions::update_index(ctx)
|
|
|
|
}
|
|
|
|
|
2022-04-12 07:19:58 -07:00
|
|
|
pub fn create_account(
|
|
|
|
ctx: Context<CreateAccount>,
|
|
|
|
account_num: u8,
|
|
|
|
name: String,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::create_account(ctx, account_num, name)
|
2022-02-22 04:15:13 -08:00
|
|
|
}
|
2022-02-22 05:23:13 -08:00
|
|
|
|
2022-05-16 01:34:22 -07:00
|
|
|
// TODO set delegate
|
|
|
|
|
2022-03-31 08:22:56 -07:00
|
|
|
pub fn close_account(ctx: Context<CloseAccount>) -> Result<()> {
|
|
|
|
instructions::close_account(ctx)
|
|
|
|
}
|
|
|
|
|
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-02-28 08:17:01 -08:00
|
|
|
pub fn create_stub_oracle(ctx: Context<CreateStubOracle>, price: I80F48) -> Result<()> {
|
|
|
|
instructions::create_stub_oracle(ctx, price)
|
2022-02-28 03:37:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_stub_oracle(ctx: Context<SetStubOracle>, price: I80F48) -> Result<()> {
|
|
|
|
instructions::set_stub_oracle(ctx, price)
|
|
|
|
}
|
|
|
|
|
2022-02-22 05:23:13 -08:00
|
|
|
pub fn deposit(ctx: Context<Deposit>, amount: u64) -> Result<()> {
|
|
|
|
instructions::deposit(ctx, amount)
|
|
|
|
}
|
2022-02-25 06:14:15 -08:00
|
|
|
|
|
|
|
pub fn withdraw(ctx: Context<Withdraw>, amount: u64, allow_borrow: bool) -> Result<()> {
|
|
|
|
instructions::withdraw(ctx, amount, allow_borrow)
|
|
|
|
}
|
2022-03-02 21:15:28 -08:00
|
|
|
|
2022-03-04 05:30:53 -08:00
|
|
|
pub fn margin_trade<'key, 'accounts, 'remaining, 'info>(
|
|
|
|
ctx: Context<'key, 'accounts, 'remaining, 'info, MarginTrade<'info>>,
|
2022-03-08 01:23:58 -08:00
|
|
|
banks_len: usize,
|
2022-03-04 05:30:53 -08:00
|
|
|
cpi_data: Vec<u8>,
|
|
|
|
) -> Result<()> {
|
2022-03-08 01:23:58 -08:00
|
|
|
instructions::margin_trade(ctx, banks_len, cpi_data)
|
2022-03-02 21:15:28 -08:00
|
|
|
}
|
2022-03-11 03:38:10 -08: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-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-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-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-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-03-18 23:28:37 -07:00
|
|
|
base_token_index_opt: Option<TokenIndex>,
|
|
|
|
quote_token_index: TokenIndex,
|
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-03-18 23:28:37 -07:00
|
|
|
base_token_index_opt,
|
|
|
|
quote_token_index,
|
|
|
|
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-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-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
|
|
|
|
}
|
|
|
|
}
|