Options
All
  • Public
  • Public/Protected
  • All
Menu

A class for interacting with the Mango V3 Program

param connection

A solana web.js Connection object

param programId

The PublicKey of the Mango V3 Program

param opts

An object used to configure the MangoClient. Accepts a postSendTxCallback

Hierarchy

  • MangoClient

Index

Constructors

Properties

Methods

Constructors

constructor

  • new MangoClient(connection: Connection, programId: PublicKey, opts?: { blockhashCommitment?: Commitment; maxStoredBlockhashes?: number; sendConnection?: Connection; timeout?: number; postSendTxCallback?: any }): MangoClient
  • Parameters

    • connection: Connection
    • programId: PublicKey
    • opts: { blockhashCommitment?: Commitment; maxStoredBlockhashes?: number; sendConnection?: Connection; timeout?: number; postSendTxCallback?: any } = {}
      • Optional blockhashCommitment?: Commitment
      • Optional maxStoredBlockhashes?: number
      • Optional sendConnection?: Connection
      • Optional timeout?: number
      • postSendTxCallback?:function
        • postSendTxCallback(__namedParameters: { txid: string }): void
        • Parameters

          • __namedParameters: { txid: string }
            • txid: string

          Returns void

    Returns MangoClient

Properties

blockhashCommitment

blockhashCommitment: Commitment

connection

connection: Connection

lastSlot

lastSlot: number

lastValidBlockHeight

lastValidBlockHeight: number

maxStoredBlockhashes

maxStoredBlockhashes: number

Optional postSendTxCallback

postSendTxCallback?: (__namedParameters: Object) => void

Type declaration

    • (__namedParameters: Object): void
    • Parameters

      • __namedParameters: Object

      Returns void

programId

programId: PublicKey

recentBlockhash

recentBlockhash: string

recentBlockhashTime

recentBlockhashTime: number

Optional sendConnection

sendConnection?: Connection

timeout

timeout: null | number

Methods

addMangoAccountInfo

addOracle

addPerpMarket

  • addPerpMarket(mangoGroup: MangoGroup, oraclePk: PublicKey, mngoMintPk: PublicKey, admin: Keypair, maintLeverage: number, initLeverage: number, liquidationFee: number, makerFee: number, takerFee: number, baseLotSize: number, quoteLotSize: number, maxNumEvents: number, rate: number, maxDepthBps: number, targetPeriodLength: number, mngoPerPeriod: number, exp: number): Promise<string>
  • Parameters

    • mangoGroup: MangoGroup
    • oraclePk: PublicKey
    • mngoMintPk: PublicKey
    • admin: Keypair
    • maintLeverage: number
    • initLeverage: number
    • liquidationFee: number
    • makerFee: number
    • takerFee: number
    • baseLotSize: number
    • quoteLotSize: number
    • maxNumEvents: number
    • rate: number
    • maxDepthBps: number
    • targetPeriodLength: number
    • mngoPerPeriod: number
    • exp: number

    Returns Promise<string>

addPerpTriggerOrder

  • addPerpTriggerOrder(mangoGroup: MangoGroup, mangoAccount: MangoAccount, perpMarket: PerpMarket, owner: Payer, orderType: PerpOrderType, side: "buy" | "sell", price: number, quantity: number, triggerCondition: "above" | "below", triggerPrice: number, reduceOnly: boolean, clientOrderId?: number): Promise<undefined | string>

addSpotMarket

  • addSpotMarket(mangoGroup: MangoGroup, oracle: PublicKey, spotMarket: PublicKey, mint: PublicKey, admin: Keypair, maintLeverage: number, initLeverage: number, liquidationFee: number, optimalUtil: number, optimalRate: number, maxRate: number): Promise<string>

addStubOracle

  • addStubOracle(mangoGroupPk: PublicKey, admin: Keypair): Promise<string>

awaitTransactionSignatureConfirmation

  • awaitTransactionSignatureConfirmation(txid: string, timeout: number, confirmLevel: TransactionConfirmationStatus, signedAtBlock?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>): Promise<unknown>
  • Parameters

    • txid: string
    • timeout: number
    • confirmLevel: TransactionConfirmationStatus
    • Optional signedAtBlock: Readonly<{ blockhash: string; lastValidBlockHeight: number }>

    Returns Promise<unknown>

cachePerpMarkets

cachePrices

cacheRootBanks

cancelAllPerpOrders

cancelPerpOrder

cancelPerpOrderSide

cancelSpotOrder

  • cancelSpotOrder(mangoGroup: MangoGroup, mangoAccount: MangoAccount, owner: Payer, spotMarket: Market, order: Order): Promise<undefined | string>

changePerpMarketParams

  • changePerpMarketParams(mangoGroup: MangoGroup, perpMarket: PerpMarket, admin: Payer, maintLeverage: undefined | number, initLeverage: undefined | number, liquidationFee: undefined | number, makerFee: undefined | number, takerFee: undefined | number, rate: undefined | number, maxDepthBps: undefined | number, targetPeriodLength: undefined | number, mngoPerPeriod: undefined | number, exp: undefined | number): Promise<undefined | string>
  • Parameters

    • mangoGroup: MangoGroup
    • perpMarket: PerpMarket
    • admin: Payer
    • maintLeverage: undefined | number
    • initLeverage: undefined | number
    • liquidationFee: undefined | number
    • makerFee: undefined | number
    • takerFee: undefined | number
    • rate: undefined | number
    • maxDepthBps: undefined | number
    • targetPeriodLength: undefined | number
    • mngoPerPeriod: undefined | number
    • exp: undefined | number

    Returns Promise<undefined | string>

changePerpMarketParams2

  • changePerpMarketParams2(mangoGroup: MangoGroup, perpMarket: PerpMarket, admin: Payer, maintLeverage: undefined | number, initLeverage: undefined | number, liquidationFee: undefined | number, makerFee: undefined | number, takerFee: undefined | number, rate: undefined | number, maxDepthBps: undefined | number, targetPeriodLength: undefined | number, mngoPerPeriod: undefined | number, exp: undefined | number, version: undefined | number, lmSizeShift: undefined | number): Promise<undefined | string>
  • Parameters

    • mangoGroup: MangoGroup
    • perpMarket: PerpMarket
    • admin: Payer
    • maintLeverage: undefined | number
    • initLeverage: undefined | number
    • liquidationFee: undefined | number
    • makerFee: undefined | number
    • takerFee: undefined | number
    • rate: undefined | number
    • maxDepthBps: undefined | number
    • targetPeriodLength: undefined | number
    • mngoPerPeriod: undefined | number
    • exp: undefined | number
    • version: undefined | number
    • lmSizeShift: undefined | number

    Returns Promise<undefined | string>

changeReferralFeeParams

  • changeReferralFeeParams(mangoGroup: MangoGroup, admin: Payer, refSurcharge: number, refShare: number, refMngoRequired: number): Promise<undefined | string>
  • Change the referral fee params

    Parameters

    • mangoGroup: MangoGroup
    • admin: Payer
    • refSurcharge: number

      normal units 0.0001 -> 1 basis point

    • refShare: number
    • refMngoRequired: number

      ui units -> 1 -> 1_000_000 MNGO

    Returns Promise<undefined | string>

changeSpotMarketParams

  • changeSpotMarketParams(mangoGroup: MangoGroup, spotMarket: Market, rootBank: RootBank, admin: Payer, maintLeverage: undefined | number, initLeverage: undefined | number, liquidationFee: undefined | number, optimalUtil: undefined | number, optimalRate: undefined | number, maxRate: undefined | number, version: undefined | number): Promise<undefined | string>
  • Parameters

    • mangoGroup: MangoGroup
    • spotMarket: Market
    • rootBank: RootBank
    • admin: Payer
    • maintLeverage: undefined | number
    • initLeverage: undefined | number
    • liquidationFee: undefined | number
    • optimalUtil: undefined | number
    • optimalRate: undefined | number
    • maxRate: undefined | number
    • version: undefined | number

    Returns Promise<undefined | string>

closeAdvancedOrders

closeMangoAccount

closeSpotOpenOrders

  • closeSpotOpenOrders(mangoGroup: MangoGroup, mangoAccount: MangoAccount, payer: Payer, marketIndex: number): Promise<undefined | string>

consumeEvents

createDustAccount

  • createDustAccount(mangoGroup: MangoGroup, payer: Payer): Promise<undefined | string>

createMangoAccount

createMangoAccountAndDeposit

  • Create a new Mango Account (PDA) and deposit some tokens in a single transaction

    Parameters

    • mangoGroup: MangoGroup
    • owner: Payer
    • rootBank: PublicKey

      The RootBank for the deposit currency

    • nodeBank: PublicKey

      The NodeBank asociated with the RootBank

    • vault: PublicKey

      The token account asociated with the NodeBank

    • tokenAcc: PublicKey

      The token account to transfer from

    • quantity: number
    • accountNum: number
    • Optional info: string

      An optional UI name for the account

    • Optional referrerPk: PublicKey
    • Optional payerPk: PublicKey

    Returns Promise<undefined | [string, string]>

createPerpMarket

  • createPerpMarket(mangoGroup: MangoGroup, oraclePk: PublicKey, mngoMintPk: PublicKey, admin: Payer, maintLeverage: number, initLeverage: number, liquidationFee: number, makerFee: number, takerFee: number, baseLotSize: number, quoteLotSize: number, maxNumEvents: number, rate: number, maxDepthBps: number, targetPeriodLength: number, mngoPerPeriod: number, exp: number, version: number, lmSizeShift: number, baseDecimals: number): Promise<undefined | string>
  • Parameters

    • mangoGroup: MangoGroup
    • oraclePk: PublicKey
    • mngoMintPk: PublicKey
    • admin: Payer
    • maintLeverage: number
    • initLeverage: number
    • liquidationFee: number
    • makerFee: number
    • takerFee: number
    • baseLotSize: number
    • quoteLotSize: number
    • maxNumEvents: number
    • rate: number
    • maxDepthBps: number
    • targetPeriodLength: number
    • mngoPerPeriod: number
    • exp: number
    • version: number
    • lmSizeShift: number
    • baseDecimals: number

    Returns Promise<undefined | string>

deposit

  • Deposit tokens in a Mango Account

    Parameters

    Returns Promise<undefined | string>

depositMsrm

emptyAndCloseMangoAccount

executePerpTriggerOrder

fetchTopPnlAccountsFromDB

  • fetchTopPnlAccountsFromDB(mangoGroup: MangoGroup, perpMarket: PerpMarket, sign: number): Promise<AccountWithPnl[]>

fetchTopPnlAccountsFromRPC

forceCancelAllPerpOrdersInMarket

forceCancelPerpOrders

forceCancelSpotOrders

getAllMangoAccounts

  • getAllMangoAccounts(mangoGroup: MangoGroup, filters?: any[], includeOpenOrders?: boolean): Promise<MangoAccount[]>

getCurrentBlockhash

  • getCurrentBlockhash(): Promise<Readonly<{ blockhash: string; lastValidBlockHeight: number }>>
  • Returns Promise<Readonly<{ blockhash: string; lastValidBlockHeight: number }>>

getMangoAccount

getMangoAccountsForDelegate

getMangoAccountsForOwner

getMangoGroup

getPerpMarket

  • getPerpMarket(perpMarketPk: PublicKey, baseDecimal: number, quoteDecimal: number): Promise<PerpMarket>

getReferrerIdsForMangoAccount

  • getReferrerIdsForMangoAccount(mangoAccount: MangoAccount): Promise<ReferrerIdRecord[]>

getReferrerPda

  • getReferrerPda(mangoGroup: MangoGroup, referrerId: string): Promise<{ encodedReferrerId: Buffer; referrerPda: PublicKey }>

initMangoAccount

initMangoAccountAndDeposit

  • Create a new Mango Account and deposit some tokens in a single transaction

    Parameters

    • mangoGroup: MangoGroup
    • owner: Payer
    • rootBank: PublicKey

      The RootBank for the deposit currency

    • nodeBank: PublicKey

      The NodeBank asociated with the RootBank

    • vault: PublicKey

      The token account asociated with the NodeBank

    • tokenAcc: PublicKey

      The token account to transfer from

    • quantity: number
    • Optional info: string

      An optional UI name for the account

    Returns Promise<undefined | string>

initMangoGroup

liquidatePerpMarket

liquidateTokenAndPerp

liquidateTokenAndToken

maintainTimeouts

  • maintainTimeouts(): Promise<void>

modifyPerpOrder

modifySpotOrder

  • modifySpotOrder(mangoGroup: MangoGroup, mangoAccount: MangoAccount, mangoCache: PublicKey, spotMarket: Market, owner: Payer, order: Order, side: "buy" | "sell", price: number, size: number, orderType?: "limit" | "ioc" | "postOnly"): Promise<undefined | string>
  • Add allowance for orders to be cancelled and replaced in a single transaction

    Parameters

    • mangoGroup: MangoGroup
    • mangoAccount: MangoAccount
    • mangoCache: PublicKey
    • spotMarket: Market
    • owner: Payer
    • order: Order
    • side: "buy" | "sell"
    • price: number
    • size: number
    • Optional orderType: "limit" | "ioc" | "postOnly"

    Returns Promise<undefined | string>

placePerpOrder

  • placePerpOrder(mangoGroup: MangoGroup, mangoAccount: MangoAccount, mangoCache: PublicKey, perpMarket: PerpMarket, owner: Payer, side: "buy" | "sell", price: number, quantity: number, orderType?: PerpOrderType, clientOrderId?: number, bookSideInfo?: AccountInfo<Buffer>, reduceOnly?: boolean, referrerMangoAccountPk?: PublicKey): Promise<undefined | string>
  • Place an order on a perp market

    Parameters

    • mangoGroup: MangoGroup
    • mangoAccount: MangoAccount
    • mangoCache: PublicKey
    • perpMarket: PerpMarket
    • owner: Payer
    • side: "buy" | "sell"
    • price: number
    • quantity: number
    • Optional orderType: PerpOrderType
    • clientOrderId: number = 0

      An optional id that can be used to correlate events related to your order

    • Optional bookSideInfo: AccountInfo<Buffer>

      Account info for asks if side === bid, bids if side === ask. If this is given, crank instruction is added

    • Optional reduceOnly: boolean
    • Optional referrerMangoAccountPk: PublicKey

    Returns Promise<undefined | string>

placePerpOrder2

  • placePerpOrder2(mangoGroup: MangoGroup, mangoAccount: MangoAccount, perpMarket: PerpMarket, owner: Payer, side: "buy" | "sell", price: number, quantity: number, options?: { bookSideInfo?: AccountInfo<Buffer>; clientOrderId?: number; expiryTimestamp?: number; limit?: number; maxQuoteQuantity?: number; orderType?: PerpOrderType; reduceOnly?: boolean; referrerMangoAccountPk?: PublicKey }): Promise<undefined | string>
  • Place an order on a perp market

    Parameters

    • mangoGroup: MangoGroup
    • mangoAccount: MangoAccount
    • perpMarket: PerpMarket
    • owner: Payer
    • side: "buy" | "sell"
    • price: number
    • quantity: number
    • Optional options: { bookSideInfo?: AccountInfo<Buffer>; clientOrderId?: number; expiryTimestamp?: number; limit?: number; maxQuoteQuantity?: number; orderType?: PerpOrderType; reduceOnly?: boolean; referrerMangoAccountPk?: PublicKey }
      • Optional bookSideInfo?: AccountInfo<Buffer>
      • Optional clientOrderId?: number
      • Optional expiryTimestamp?: number
      • Optional limit?: number
      • Optional maxQuoteQuantity?: number
      • Optional orderType?: PerpOrderType
      • Optional reduceOnly?: boolean
      • Optional referrerMangoAccountPk?: PublicKey

    Returns Promise<undefined | string>

placeSpotOrder

  • placeSpotOrder(mangoGroup: MangoGroup, mangoAccount: MangoAccount, mangoCache: PublicKey, spotMarket: Market, owner: Payer, side: "buy" | "sell", price: number, size: number, orderType?: "limit" | "ioc" | "postOnly", clientId?: BN): Promise<undefined | string>
  • Make sure mangoAccount has recent and valid inMarginBasket and spotOpenOrders

    Parameters

    • mangoGroup: MangoGroup
    • mangoAccount: MangoAccount
    • mangoCache: PublicKey
    • spotMarket: Market
    • owner: Payer
    • side: "buy" | "sell"
    • price: number
    • size: number
    • Optional orderType: "limit" | "ioc" | "postOnly"
    • Optional clientId: BN

    Returns Promise<undefined | string>

placeSpotOrder2

  • placeSpotOrder2(mangoGroup: MangoGroup, mangoAccount: MangoAccount, spotMarket: Market, owner: Payer, side: "buy" | "sell", price: number, size: number, orderType?: "limit" | "ioc" | "postOnly", clientOrderId?: BN, useMsrmVault?: boolean): Promise<undefined | string[]>
  • Make sure mangoAccount has recent and valid inMarginBasket and spotOpenOrders

    Parameters

    • mangoGroup: MangoGroup
    • mangoAccount: MangoAccount
    • spotMarket: Market
    • owner: Payer
    • side: "buy" | "sell"
    • price: number
    • size: number
    • Optional orderType: "limit" | "ioc" | "postOnly"
    • Optional clientOrderId: BN
    • Optional useMsrmVault: boolean

    Returns Promise<undefined | string[]>

redeemAllMngo

redeemMngo

registerReferrerId

  • registerReferrerId(mangoGroup: MangoGroup, referrerMangoAccount: MangoAccount, payer: Payer, referrerId: string): Promise<undefined | string>

removeAdvancedOrder

resolveAllDust

resolveDust

resolvePerpBankruptcy

resolveTokenBankruptcy

sendSignedTransaction

  • sendSignedTransaction(__namedParameters: { confirmLevel?: TransactionConfirmationStatus; signedAtBlock?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>; signedTransaction: Transaction; timeout?: null | number }): Promise<string>
  • Parameters

    • __namedParameters: { confirmLevel?: TransactionConfirmationStatus; signedAtBlock?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>; signedTransaction: Transaction; timeout?: null | number }
      • Optional confirmLevel?: TransactionConfirmationStatus
      • Optional signedAtBlock?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>
      • signedTransaction: Transaction
      • Optional timeout?: null | number

    Returns Promise<string>

sendTransaction

  • sendTransaction(transaction: Transaction, payer: Payer, additionalSigners: Keypair[], timeout?: null | number, confirmLevel?: TransactionConfirmationStatus): Promise<string>
  • Send a transaction using the Solana Web3.js connection on the mango client

    Parameters

    • transaction: Transaction
    • payer: Payer
    • additionalSigners: Keypair[]
    • timeout: null | number = ...

      Retries sending the transaction and trying to confirm it until the given timeout. Passing null will disable the transaction confirmation check and always return success.

    • confirmLevel: TransactionConfirmationStatus = 'processed'

    Returns Promise<string>

sendTransactions

  • sendTransactions(transactions: Transaction[], payer: Payer, additionalSigners: Keypair[], timeout?: null | number, confirmLevel?: TransactionConfirmationStatus): Promise<string[]>
  • Parameters

    • transactions: Transaction[]
    • payer: Payer
    • additionalSigners: Keypair[]
    • timeout: null | number = ...
    • confirmLevel: TransactionConfirmationStatus = 'confirmed'

    Returns Promise<string[]>

setDelegate

setGroupAdmin

setOracle

setReferrerMemory

setStubOracle

  • setStubOracle(mangoGroupPk: PublicKey, oraclePk: PublicKey, admin: Keypair, price: number): Promise<string>

settleAll

settleAllPerpPnl

settleFees

settleFunds

settlePnl

settlePosPnl

signTransaction

  • signTransaction(__namedParameters: { currentBlockhash?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>; payer: any; signers: Keypair[]; transaction: Transaction }): Promise<any>
  • Parameters

    • __namedParameters: { currentBlockhash?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>; payer: any; signers: Keypair[]; transaction: Transaction }
      • Optional currentBlockhash?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>
      • payer: any
      • signers: Keypair[]
      • transaction: Transaction

    Returns Promise<any>

signTransactions

  • signTransactions(__namedParameters: { currentBlockhash?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>; payer: Payer; transactionsAndSigners: { signers?: Keypair[]; transaction: Transaction }[] }): Promise<undefined | Transaction[]>
  • Parameters

    • __namedParameters: { currentBlockhash?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>; payer: Payer; transactionsAndSigners: { signers?: Keypair[]; transaction: Transaction }[] }
      • Optional currentBlockhash?: Readonly<{ blockhash: string; lastValidBlockHeight: number }>
      • payer: Payer
      • transactionsAndSigners: { signers?: Keypair[]; transaction: Transaction }[]

    Returns Promise<undefined | Transaction[]>

updateFunding

updateMarginBasket

updateRecentBlockhash

  • updateRecentBlockhash(blockhashTimes: BlockhashTimes[]): Promise<void>

updateRootBank

upgradeMangoAccountV0V1

withdraw

  • Withdraw tokens from a Mango Account

    Parameters

    • mangoGroup: MangoGroup
    • mangoAccount: MangoAccount
    • owner: Payer
    • rootBank: PublicKey

      The RootBank for the withdrawn currency

    • nodeBank: PublicKey

      The NodeBank asociated with the RootBank

    • vault: PublicKey

      The token account asociated with the NodeBank

    • quantity: number
    • allowBorrow: boolean

      Whether to borrow tokens if there are not enough deposits for the withdrawal

    Returns Promise<undefined | string>

withdrawAll

withdrawMsrm

Generated using TypeDoc