pub struct MangoClient {
    pub client: Client,
    pub account_fetcher: Arc<dyn AccountFetcher>,
    pub authority: Arc<Keypair>,
    pub mango_account_address: Pubkey,
    pub context: MangoGroupContext,
    pub http_client: Client,
}

Fields§

§client: Client§account_fetcher: Arc<dyn AccountFetcher>§authority: Arc<Keypair>§mango_account_address: Pubkey§context: MangoGroupContext§http_client: Client

Implementations§

source§

impl MangoClient

source

pub fn group_for_admin(admin: Pubkey, num: u32) -> Pubkey

source

pub async fn find_accounts( client: &Client, group: Pubkey, owner: &Keypair ) -> Result<Vec<(Pubkey, MangoAccountValue)>>

source

pub async fn find_or_create_account( client: &Client, group: Pubkey, owner: Arc<Keypair>, payer: Arc<Keypair>, mango_account_name: &str ) -> Result<Pubkey>

source

pub async fn create_account( client: &Client, group: Pubkey, owner: Arc<Keypair>, payer: Arc<Keypair>, account_num: u32, mango_account_name: &str ) -> Result<(Pubkey, Signature)>

source

pub async fn new_for_existing_account( client: Client, account: Pubkey, authority: Arc<Keypair> ) -> Result<Self>

Conveniently creates a RPC based client

source

pub fn new_detail( client: Client, account: Pubkey, authority: Arc<Keypair>, group_context: MangoGroupContext, account_fetcher: Arc<dyn AccountFetcher> ) -> Result<Self>

Allows control of AccountFetcher and externally created MangoGroupContext

source

pub fn authority(&self) -> Pubkey

source

pub fn group(&self) -> Pubkey

source

pub async fn mango_account(&self) -> Result<MangoAccountValue>

source

pub async fn first_bank(&self, token_index: TokenIndex) -> Result<Bank>

source

pub async fn derive_health_check_remaining_account_metas( &self, account: &MangoAccountValue, affected_tokens: Vec<TokenIndex>, writable_banks: Vec<TokenIndex>, affected_perp_markets: Vec<PerpMarketIndex> ) -> Result<(Vec<AccountMeta>, u32)>

source

pub async fn derive_health_check_remaining_account_metas_two_accounts( &self, account_1: &MangoAccountValue, account_2: &MangoAccountValue, affected_tokens: &[TokenIndex], writable_banks: &[TokenIndex] ) -> Result<(Vec<AccountMeta>, u32)>

source

pub async fn health_cache( &self, mango_account: &MangoAccountValue ) -> Result<HealthCache>

source

pub async fn token_deposit( &self, mint: Pubkey, amount: u64, reduce_only: bool ) -> Result<Signature>

source

pub async fn health_check_instruction( &self, account: &MangoAccountValue, min_health_value: f64, affected_tokens: Vec<TokenIndex>, affected_perp_markets: Vec<PerpMarketIndex>, check_kind: HealthCheckKind ) -> Result<PreparedInstructions>

Assert that health of account is > N

source

pub async fn sequence_check_instruction( &self, mango_account_address: &Pubkey, mango_account: &MangoAccountValue ) -> Result<PreparedInstructions>

Avoid executing same instruction multiple time

source

pub async fn token_withdraw_instructions( &self, account: &MangoAccountValue, mint: Pubkey, amount: u64, allow_borrow: bool ) -> Result<PreparedInstructions>

Creates token withdraw instructions for the MangoClient’s account/owner. The account state is passed in separately so changes during the tx can be accounted for when deriving health accounts.

source

pub async fn token_withdraw( &self, mint: Pubkey, amount: u64, allow_borrow: bool ) -> Result<Signature>

source

pub async fn bank_oracle_price(&self, token_index: TokenIndex) -> Result<I80F48>

source

pub async fn perp_oracle_price( &self, perp_market_index: PerpMarketIndex ) -> Result<I80F48>

source

pub fn serum3_close_open_orders_instruction( &self, market_index: Serum3MarketIndex ) -> PreparedInstructions

source

pub async fn serum3_close_open_orders(&self, name: &str) -> Result<Signature>

source

pub fn serum3_create_open_orders_instruction( &self, market_index: Serum3MarketIndex ) -> Instruction

source

pub async fn serum3_create_open_orders(&self, name: &str) -> Result<Signature>

source

pub async fn serum3_place_order_instruction( &self, account: &MangoAccountValue, market_index: Serum3MarketIndex, 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 ) -> Result<PreparedInstructions>

source

pub async fn serum3_create_or_replace_account_instruction( &self, account: &mut MangoAccountValue, market_index: Serum3MarketIndex, side: Serum3Side ) -> Result<PreparedInstructions>

source

pub async fn serum3_place_order( &self, name: &str, 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 ) -> Result<Signature>

source

pub async fn serum3_settle_funds(&self, name: &str) -> Result<Signature>

source

pub fn serum3_settle_funds_instruction( &self, s3: &Serum3MarketContext, base: &TokenContext, quote: &TokenContext, open_orders: Pubkey ) -> PreparedInstructions

source

pub fn serum3_cancel_all_orders_instruction( &self, account: &MangoAccountValue, market_index: Serum3MarketIndex, limit: u8 ) -> Result<PreparedInstructions>

source

pub async fn serum3_cancel_all_orders( &self, market_name: &str ) -> Result<Vec<u128>, Error>

source

pub async fn serum3_liq_force_cancel_orders_instruction( &self, liqee: (&Pubkey, &MangoAccountValue), market_index: Serum3MarketIndex, open_orders: &Pubkey ) -> Result<PreparedInstructions>

source

pub async fn openbook_v2_liq_force_cancel_orders_instruction( &self, liqee: (&Pubkey, &MangoAccountValue), market_index: OpenbookV2MarketIndex, open_orders: &Pubkey ) -> Result<PreparedInstructions>

source

pub async fn serum3_liq_force_cancel_orders( &self, liqee: (&Pubkey, &MangoAccountValue), market_index: Serum3MarketIndex, open_orders: &Pubkey ) -> Result<Signature>

source

pub async fn serum3_cancel_order( &self, market_name: &str, side: Serum3Side, order_id: u128 ) -> Result<Signature>

source

pub async fn perp_place_order_instruction( &self, account: &MangoAccountValue, market_index: PerpMarketIndex, side: Side, price_lots: i64, max_base_lots: i64, max_quote_lots: i64, client_order_id: u64, order_type: PlaceOrderType, reduce_only: bool, expiry_timestamp: u64, limit: u8, self_trade_behavior: SelfTradeBehavior ) -> Result<PreparedInstructions>

source

pub async fn perp_place_order( &self, market_index: PerpMarketIndex, side: Side, price_lots: i64, max_base_lots: i64, max_quote_lots: i64, client_order_id: u64, order_type: PlaceOrderType, reduce_only: bool, expiry_timestamp: u64, limit: u8, self_trade_behavior: SelfTradeBehavior ) -> Result<Signature>

source

pub fn perp_cancel_all_orders_instruction( &self, market_index: PerpMarketIndex, limit: u8 ) -> Result<PreparedInstructions>

source

pub async fn perp_deactivate_position( &self, market_index: PerpMarketIndex ) -> Result<Signature>

source

pub async fn perp_settle_pnl_instruction( &self, market_index: PerpMarketIndex, account_a: (&Pubkey, &MangoAccountValue), account_b: (&Pubkey, &MangoAccountValue) ) -> Result<PreparedInstructions>

source

pub async fn perp_settle_pnl( &self, market_index: PerpMarketIndex, account_a: (&Pubkey, &MangoAccountValue), account_b: (&Pubkey, &MangoAccountValue) ) -> Result<Signature>

source

pub async fn perp_liq_force_cancel_orders( &self, liqee: (&Pubkey, &MangoAccountValue), market_index: PerpMarketIndex ) -> Result<Signature>

source

pub async fn perp_liq_base_or_positive_pnl_instruction( &self, liqee: (&Pubkey, &MangoAccountValue), market_index: PerpMarketIndex, max_base_transfer: i64, max_pnl_transfer: u64 ) -> Result<PreparedInstructions>

source

pub async fn perp_liq_negative_pnl_or_bankruptcy_instruction( &self, liqee: (&Pubkey, &MangoAccountValue), market_index: PerpMarketIndex, max_liab_transfer: u64 ) -> Result<PreparedInstructions>

source

pub async fn token_charge_collateral_fees_instruction( &self, account: (&Pubkey, &MangoAccountValue) ) -> Result<PreparedInstructions>

source

pub async fn token_liq_with_token_instruction( &self, liqee: (&Pubkey, &MangoAccountValue), asset_token_index: TokenIndex, liab_token_index: TokenIndex, max_liab_transfer: I80F48 ) -> Result<PreparedInstructions>

source

pub async fn token_liq_bankruptcy_instruction( &self, liqee: (&Pubkey, &MangoAccountValue), liab_token_index: TokenIndex, max_liab_transfer: I80F48 ) -> Result<PreparedInstructions>

source

pub async fn token_conditional_swap_trigger_instruction( &self, liqee: (&Pubkey, &MangoAccountValue), token_conditional_swap_id: u64, max_buy_token_to_liqee: u64, max_sell_token_to_liqor: u64, min_buy_token: u64, min_taker_price: f32, extra_affected_tokens: &[TokenIndex] ) -> Result<PreparedInstructions>

source

pub async fn token_conditional_swap_start_instruction( &self, account: (&Pubkey, &MangoAccountValue), token_conditional_swap_id: u64 ) -> Result<PreparedInstructions>

source

pub async fn health_region_begin_instruction( &self, account: &MangoAccountValue, affected_tokens: Vec<TokenIndex>, writable_banks: Vec<TokenIndex>, affected_perp_markets: Vec<PerpMarketIndex> ) -> Result<PreparedInstructions>

source

pub async fn health_region_end_instruction( &self, account: &MangoAccountValue, affected_tokens: Vec<TokenIndex>, writable_banks: Vec<TokenIndex>, affected_perp_markets: Vec<PerpMarketIndex> ) -> Result<PreparedInstructions>

source

pub fn swap(&self) -> Swap<'_>

source

pub fn jupiter_v6(&self) -> JupiterV6<'_>

source

pub fn sanctum(&self) -> Sanctum<'_>

source

pub async fn fetch_address_lookup_table( &self, address: Pubkey ) -> Result<AddressLookupTableAccount>

source

pub async fn fetch_address_lookup_tables( &self, alts: impl Iterator<Item = &Pubkey> ) -> Result<Vec<AddressLookupTableAccount>>

source

pub async fn mango_address_lookup_tables( &self ) -> Result<Vec<AddressLookupTableAccount>>

source

pub async fn send_and_confirm_authority_tx( &self, instructions: Vec<Instruction> ) -> Result<Signature>

source

pub async fn send_and_confirm_permissionless_tx( &self, instructions: Vec<Instruction> ) -> Result<Signature>

source

pub async fn transaction_builder(&self) -> Result<TransactionBuilder>

source

pub async fn simulate( &self, instructions: Vec<Instruction> ) -> Result<SimulateTransactionResponse>

source

pub async fn loop_check_for_context_changes_and_abort( mango_client: Arc<MangoClient>, interval: Duration )

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> DerefOrBorrow<T> for Twhere T: ?Sized,

source§

impl<T> DerefOrBorrowMut<T> for Twhere T: ?Sized,

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TupleTree<T, ()> for T

§

const SIZE: Size = Size{ degree: 0, descendants: 0,}

§

fn descendants(_indirect_level: usize) -> usize

§

fn height() -> usize

§

fn preorder(self, f: &mut impl FnMut(Visit<T>))

§

fn preorder_with_size_hint(self, f: &mut impl FnMut(Visit<T>, Size))

§

fn postorder(self, f: &mut impl FnMut(Visit<T>))

§

fn postorder_with_size_hint(self, f: &mut impl FnMut(Visit<T>, Size))

§

impl<T> Typeable for Twhere T: Any,

§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.