Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • MangoAccount

Index

Constructors

  • new MangoAccount(publicKey: PublicKey, group: PublicKey, owner: PublicKey, name: number[], delegate: PublicKey, accountNum: number, beingLiquidated: boolean, inHealthRegion: boolean, netDeposits: BN, perpSpotTransfers: BN, healthRegionBeginInitHealth: BN, frozenUntil: BN, buybackFeesAccruedCurrent: BN, buybackFeesAccruedPrevious: BN, buybackFeesExpiryTimestamp: BN, headerVersion: number, tokens: TokenPositionDto[], serum3: Serum3PositionDto[], perps: PerpPositionDto[], perpOpenOrders: PerpOoDto[], serum3OosMapByMarketIndex: Map<number, OpenOrders>): MangoAccount
  • Parameters

    • publicKey: PublicKey
    • group: PublicKey
    • owner: PublicKey
    • name: number[]
    • delegate: PublicKey
    • accountNum: number
    • beingLiquidated: boolean
    • inHealthRegion: boolean
    • netDeposits: BN
    • perpSpotTransfers: BN
    • healthRegionBeginInitHealth: BN
    • frozenUntil: BN
    • buybackFeesAccruedCurrent: BN
    • buybackFeesAccruedPrevious: BN
    • buybackFeesExpiryTimestamp: BN
    • headerVersion: number
    • tokens: TokenPositionDto[]
    • serum3: Serum3PositionDto[]
    • perps: PerpPositionDto[]
    • perpOpenOrders: PerpOoDto[]
    • serum3OosMapByMarketIndex: Map<number, OpenOrders>

    Returns MangoAccount

Properties

accountNum: number
beingLiquidated: boolean
buybackFeesAccruedCurrent: BN
buybackFeesAccruedPrevious: BN
buybackFeesExpiryTimestamp: BN
delegate: PublicKey
frozenUntil: BN
group: PublicKey
headerVersion: number
healthRegionBeginInitHealth: BN
inHealthRegion: boolean
name: string
netDeposits: BN
owner: PublicKey
perpOpenOrders: PerpOo[]
perpSpotTransfers: BN
perps: PerpPosition[]
publicKey: PublicKey
serum3: Serum3Orders[]
serum3OosMapByMarketIndex: Map<number, OpenOrders>
tokens: TokenPosition[]

Methods

  • getBuybackFeesAccrued(): BN
  • getBuybackFeesAccruedUi(): number
  • getCumulativeInterest(bank: Bank): number
  • Parameters

    Returns number

    token cumulative interest, in native token units. Sum of deposit and borrow interest. Caveat: This will only return cumulative interest since the tokenPosition was last opened. If the tokenPosition was closed and reopened multiple times it is necessary to add this result to cumulative interest at each of the prior tokenPosition closings (from mango API) to get the all time cumulative interest.

  • Sum of all the assets i.e. token deposits, borrows, total assets in spot open orders, and perps positions.

    Parameters

    Returns I80F48

    equity, in native quote

  • Health ratio, which is computed so 100 * (assets-liabs)/liabs Note: health ratio is technically ∞ if liabs are 0

    Parameters

    Returns I80F48

    health ratio, in percentage form

  • TODO: also think about limit orders

    The max ui base you can place a market/ioc ask on the market, price is the ui price at which you think the order would materialiase.

    Parameters

    Returns number

    max ui base ask

  • getMaxBaseForSerum3AskUi(group: Group, externalMarketPk: PublicKey): number
  • TODO REWORK, know to break in binary search, also make work for limit orders

    Parameters

    • group: Group
    • externalMarketPk: PublicKey

    Returns number

    maximum ui base which can be traded at oracle price for quote token given current health

  • getMaxFeesBuyback(group: Group): BN
  • getMaxFeesBuybackUi(group: Group): number
  • TODO: also think about limit orders

    The max ui quote you can place a market/ioc bid on the market, price is the ui price at which you think the order would materialiase.

    Parameters

    Returns number

    maximum ui quote which can be traded at oracle price for quote token given current health

  • getMaxQuoteForSerum3BidUi(group: Group, externalMarketPk: PublicKey): number
  • TODO REWORK, know to break in binary search, also make work for limit orders

    Parameters

    • group: Group
    • externalMarketPk: PublicKey

    Returns number

    maximum ui quote which can be traded at oracle price for base token given current health

  • getMaxSourceUiForTokenSwap(group: Group, sourceMintPk: PublicKey, targetMintPk: PublicKey, slippageAndFeesFactor?: number): number
  • The max amount of given source ui token you can swap to a target token.

    Parameters

    • group: Group
    • sourceMintPk: PublicKey
    • targetMintPk: PublicKey
    • slippageAndFeesFactor: number = 1

    Returns number

    max amount of given source ui token you can swap to a target token, in ui token

  • getMaxWithdrawWithBorrowForToken(group: Group, mintPk: PublicKey): I80F48
  • The amount of given native token you can withdraw including borrows, considering all existing assets as collateral.

    Parameters

    • group: Group
    • mintPk: PublicKey

    Returns I80F48

    amount of given native token you can borrow, considering all existing assets as collateral, in native token

    TODO: take into account net_borrow_limit and min_vault_to_deposits_ratio

  • getMaxWithdrawWithBorrowForTokenUi(group: Group, mintPk: PublicKey): number
  • Parameters

    Returns I80F48

    Overall PNL, in native quote PNL is defined here as spot value + serum3 open orders value + perp value - net deposits value (evaluated at native quote price at the time of the deposit/withdraw) spot value + serum3 open orders value + perp value is returned by getEquity (open orders values are added to spot token values implicitly)

  • getSerum3Account(marketIndex: MarketIndex): undefined | Serum3Orders
  • getSerum3OoAccount(marketIndex: MarketIndex): OpenOrders
  • getTokenBalanceUi(bank: Bank): number
  • getTokenBorrowsUi(bank: Bank): number
  • getTokenDepositsUi(bank: Bank): number
  • isOperational(): boolean
  • loadSerum3OpenOrdersAccounts(client: MangoClient): Promise<OpenOrders[]>
  • loadSerum3OpenOrdersForMarket(client: MangoClient, group: Group, externalMarketPk: PublicKey): Promise<Order[]>
  • perpOrderExistsForMarket(perpMarket: PerpMarket): boolean
  • perpPositionExistsForMarket(perpMarket: PerpMarket): boolean
  • serum3CancelAllOrdersForAllMarkets(client: MangoClient, group: Group): Promise<string[]>
  • serum3SettleFundsForAllMarkets(client: MangoClient, group: Group): Promise<string[]>
  • simHealthRatioWithPerpAskUiChanges(group: Group, perpMarketIndex: PerpMarketIndex, size: number): number
  • simHealthRatioWithPerpBidUiChanges(group: Group, perpMarketIndex: PerpMarketIndex, size: number): number
  • simHealthRatioWithSerum3AskUiChanges(group: Group, uiBaseAmount: number, externalMarketPk: PublicKey, healthType?: HealthType): number
  • Parameters

    • group: Group
    • uiBaseAmount: number
    • externalMarketPk: PublicKey
    • healthType: HealthType = HealthType.init

    Returns number

    health ratio after an ask with uiBaseAmount is placed

  • simHealthRatioWithSerum3BidUiChanges(group: Group, uiQuoteAmount: number, externalMarketPk: PublicKey, healthType?: HealthType): number
  • Parameters

    • group: Group
    • uiQuoteAmount: number
    • externalMarketPk: PublicKey
    • healthType: HealthType = HealthType.init

    Returns number

    health ratio after a bid with uiQuoteAmount is placed

  • simHealthRatioWithTokenPositionUiChanges(group: Group, uiTokenChanges: { mintPk: PublicKey; uiTokenAmount: number }[], healthType?: HealthType): number
  • Simulates new health ratio after applying tokenChanges to the token positions. Note: token changes are expected in ui amounts

    e.g. useful to simulate health after a potential swap. Note: health ratio is technically ∞ if liabs are 0

    Parameters

    • group: Group
    • uiTokenChanges: { mintPk: PublicKey; uiTokenAmount: number }[]
    • healthType: HealthType = HealthType.init

    Returns number

    health ratio, in percentage form

  • toString(group?: Group, onlyTokens?: boolean): string
  • from(publicKey: PublicKey, obj: { accountNum: number; beingLiquidated: number; buybackFeesAccruedCurrent: BN; buybackFeesAccruedPrevious: BN; buybackFeesExpiryTimestamp: BN; delegate: PublicKey; frozenUntil: BN; group: PublicKey; headerVersion: number; healthRegionBeginInitHealth: BN; inHealthRegion: number; name: number[]; netDeposits: BN; owner: PublicKey; perpOpenOrders: unknown; perpSpotTransfers: BN; perps: unknown; serum3: unknown; tokens: unknown }): MangoAccount
  • Parameters

    • publicKey: PublicKey
    • obj: { accountNum: number; beingLiquidated: number; buybackFeesAccruedCurrent: BN; buybackFeesAccruedPrevious: BN; buybackFeesExpiryTimestamp: BN; delegate: PublicKey; frozenUntil: BN; group: PublicKey; headerVersion: number; healthRegionBeginInitHealth: BN; inHealthRegion: number; name: number[]; netDeposits: BN; owner: PublicKey; perpOpenOrders: unknown; perpSpotTransfers: BN; perps: unknown; serum3: unknown; tokens: unknown }
      • accountNum: number
      • beingLiquidated: number
      • buybackFeesAccruedCurrent: BN
      • buybackFeesAccruedPrevious: BN
      • buybackFeesExpiryTimestamp: BN
      • delegate: PublicKey
      • frozenUntil: BN
      • group: PublicKey
      • headerVersion: number
      • healthRegionBeginInitHealth: BN
      • inHealthRegion: number
      • name: number[]
      • netDeposits: BN
      • owner: PublicKey
      • perpOpenOrders: unknown
      • perpSpotTransfers: BN
      • perps: unknown
      • serum3: unknown
      • tokens: unknown

    Returns MangoAccount

Generated using TypeDoc