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-02-25 04:10:51 -08:00
|
|
|
pub mod state;
|
2022-01-21 10:21:46 -08:00
|
|
|
|
2022-03-14 05:47:34 -07:00
|
|
|
use state::{SerumMarketIndex, TokenIndex};
|
2022-03-11 03:38:10 -08:00
|
|
|
|
2022-01-21 10:21:46 -08:00
|
|
|
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
|
|
|
|
|
|
|
#[program]
|
|
|
|
pub mod mango_v4 {
|
|
|
|
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-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-02-25 09:29:54 -08:00
|
|
|
maint_asset_weight: f32,
|
|
|
|
init_asset_weight: f32,
|
|
|
|
maint_liab_weight: f32,
|
|
|
|
init_liab_weight: f32,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::register_token(
|
|
|
|
ctx,
|
2022-03-14 05:19:50 -07:00
|
|
|
token_index,
|
2022-02-25 09:29:54 -08:00
|
|
|
maint_asset_weight,
|
|
|
|
init_asset_weight,
|
|
|
|
maint_liab_weight,
|
|
|
|
init_liab_weight,
|
|
|
|
)
|
2022-02-22 01:09:09 -08:00
|
|
|
}
|
2022-02-22 04:15:13 -08:00
|
|
|
|
2022-03-03 05:30:44 -08:00
|
|
|
pub fn create_account(ctx: Context<CreateAccount>, account_num: u8) -> Result<()> {
|
|
|
|
instructions::create_account(ctx, account_num)
|
2022-02-22 04:15:13 -08:00
|
|
|
}
|
2022-02-22 05:23:13 -08: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-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
|
|
|
|
|
|
|
pub fn register_serum_market(
|
|
|
|
ctx: Context<RegisterSerumMarket>,
|
2022-03-14 05:47:34 -07:00
|
|
|
market_index: SerumMarketIndex,
|
2022-03-11 03:38:10 -08:00
|
|
|
base_token_index: TokenIndex,
|
|
|
|
quote_token_index: TokenIndex,
|
|
|
|
) -> Result<()> {
|
2022-03-14 05:47:34 -07:00
|
|
|
instructions::register_serum_market(ctx, market_index, base_token_index, quote_token_index)
|
2022-03-11 03:38:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_serum_open_orders(ctx: Context<CreateSerumOpenOrders>) -> Result<()> {
|
|
|
|
instructions::create_serum_open_orders(ctx)
|
|
|
|
}
|
2022-03-14 07:26:26 -07:00
|
|
|
|
|
|
|
pub fn place_serum_order(
|
|
|
|
ctx: Context<PlaceSerumOrder>,
|
|
|
|
order: instructions::NewOrderInstructionData,
|
|
|
|
) -> Result<()> {
|
|
|
|
instructions::place_serum_order(ctx, order)
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
}
|