Options
All
  • Public
  • Public/Protected
  • All
Menu

Wrapper class around a specific marginfi account.

Hierarchy

  • MarginfiAccount

Index

Constructors

Properties

_authority: PublicKey
_lendingBalances: Balance[]
publicKey: PublicKey

Accessors

  • get authority(): PublicKey
  • Marginfi account authority address

    Returns PublicKey

Methods

  • _getHealthComponentsWithoutBias(marginReqType: MarginRequirementType): { assets: BigNumber; liabilities: BigNumber }
  • _loadGroupAndAccountAi(): Promise<AccountInfo<Buffer>[]>
  • borrow(amount: Amount, bank: Bank): Promise<string>
  • Withdraw collateral from the marginfi account.

    Parameters

    • amount: Amount

      Amount to withdraw (UI unit)

    • bank: Bank

      Bank to withdraw from

    Returns Promise<string>

    Transaction signature

  • canBeLiquidated(): boolean
  • computeNetApy(): number
  • deposit(amount: Amount, bank: Bank): Promise<string>
  • Deposit collateral into the marginfi account.

    Parameters

    • amount: Amount

      Amount to deposit (UI unit)

    • bank: Bank

      Bank to deposit to

    Returns Promise<string>

    Transaction signature

  • getBalance(bankPk: PublicKey): Balance
  • getFreeCollateral(): BigNumber
  • getHealthCheckAccounts(mandatoryBanks?: Bank[], excludedBanks?: Bank[]): AccountMeta[]
  • getMaxBorrowForBank(bank: Bank): BigNumber
  • Calculate the maximum amount of asset that can be withdrawn from a bank given existing deposits of the asset and the untied collateral of the margin account.

    fc = free collateral ucb = untied collateral for bank

    q = (min(fc, ucb) / (price_lowest_bias * deposit_weight)) + (fc - min(fc, ucb)) / (price_highest_bias * liab_weight)

    NOTE FOR LIQUIDATORS This function doesn't take into account the collateral received when liquidating an account.

    Parameters

    Returns BigNumber

  • getMaxLiquidatableAssetAmount(assetBank: Bank, liabBank: Bank): BigNumber
  • getMaxWithdrawForBank(bank: Bank): BigNumber
  • Calculate the maximum amount that can be withdrawn form a bank without borrowing.

    Parameters

    Returns BigNumber

  • lendingAccountLiquidate(liquidateeMarginfiAccount: MarginfiAccount, assetBank: Bank, assetQuantityUi: Amount, liabBank: Bank): Promise<string>
  • makeBorrowIx(amount: Amount, bank: Bank): Promise<InstructionsWrapper>
  • Create transaction instruction to withdraw collateral from the marginfi account.

    Parameters

    • amount: Amount

      Amount to withdraw (mint native unit)

    • bank: Bank

      Bank to withdraw from

    Returns Promise<InstructionsWrapper>

    MarginWithdrawCollateral transaction instruction

  • makeDepositIx(amount: Amount, bank: Bank): Promise<InstructionsWrapper>
  • Create transaction instruction to deposit collateral into the marginfi account.

    Parameters

    • amount: Amount

      Amount to deposit (UI unit)

    • bank: Bank

      Bank to deposit to

    Returns Promise<InstructionsWrapper>

    MarginDepositCollateral transaction instruction

  • makeLendingAccountLiquidateIx(liquidateeMarginfiAccount: MarginfiAccount, assetBank: Bank, assetQuantityUi: Amount, liabBank: Bank): Promise<InstructionsWrapper>
  • makeRepayIx(amount: Amount, bank: Bank, repayAll?: boolean): Promise<InstructionsWrapper>
  • Create transaction instruction to deposit collateral into the marginfi account.

    Parameters

    • amount: Amount

      Amount to deposit (UI unit)

    • bank: Bank

      Bank to deposit to

    • repayAll: boolean = false

      (optional) Repay all the liability

    Returns Promise<InstructionsWrapper>

    LendingPool transaction instruction

  • makeUnwrapSolIx(): Promise<TransactionInstruction>
  • makeWithdrawIx(amount: Amount, bank: Bank, withdrawAll?: boolean): Promise<InstructionsWrapper>
  • Create transaction instruction to withdraw collateral from the marginfi account.

    Parameters

    • amount: Amount

      Amount to withdraw (mint native unit)

    • bank: Bank

      Bank to withdraw from

    • withdrawAll: boolean = false

      (optional) Withdraw all the asset

    Returns Promise<InstructionsWrapper>

    MarginWithdrawCollateral transaction instruction

  • makeWrapSolIxs(amount: BigNumber): Promise<TransactionInstruction[]>
  • Parameters

    • amount: BigNumber

    Returns Promise<TransactionInstruction[]>

  • reload(): Promise<void>
  • Update instance data by fetching and storing the latest on-chain state.

    Returns Promise<void>

  • repay(amount: Amount, bank: Bank, repayAll?: boolean): Promise<string>
  • Deposit collateral into the marginfi account.

    Parameters

    • amount: Amount

      Amount to deposit (UI unit)

    • bank: Bank

      Bank to deposit to

    • repayAll: boolean = false

      (optional) Repay all the liability

    Returns Promise<string>

    Transaction signature

  • toString(): string
  • withdraw(amount: Amount, bank: Bank, withdrawAll?: boolean): Promise<string>
  • Withdraw collateral from the marginfi account.

    Parameters

    • amount: Amount

      Amount to withdraw (UI unit)

    • bank: Bank

      Bank to withdraw from

    • withdrawAll: boolean = false

      (optional) Withdraw all the asset

    Returns Promise<string>

    Transaction signature

  • wrapInstructionForWSol(ix: TransactionInstruction, amount?: Amount): Promise<TransactionInstruction[]>
  • Parameters

    • ix: TransactionInstruction
    • amount: Amount = ...

    Returns Promise<TransactionInstruction[]>

  • Fetch marginfi account data. Check sanity against provided config.

    Parameters

    • accountAddress: Address

      account address

    • config: MarginfiConfig

      marginfi config

    • program: MarginfiProgram

      marginfi Anchor program

    • Optional commitment: Commitment

      commitment override

    Returns Promise<MarginfiAccountData>

    Decoded marginfi account data struct

  • Decode marginfi account data according to the Anchor IDL.

    Parameters

    • encoded: Buffer

      Raw data buffer

    Returns MarginfiAccountData

    Decoded marginfi account data struct

  • Decode marginfi account data according to the Anchor IDL.

    Parameters

    Returns Promise<Buffer>

    Raw data buffer

  • MarginfiAccount network factory

    Fetch account data according to the config and instantiate the corresponding MarginfiAccount.

    Parameters

    • marginfiAccountPk: Address

      Address of the target account

    • client: MarginfiClient

      marginfi client

    • Optional commitment: Commitment

      Commitment level override

    Returns Promise<MarginfiAccount>

    MarginfiAccount instance

  • MarginfiAccount local factory (decoded)

    Instantiate a MarginfiAccount according to the provided decoded data. Check sanity against provided config.

    Parameters

    Returns MarginfiAccount

    MarginfiAccount instance

  • MarginfiAccount local factory (encoded)

    Instantiate a MarginfiAccount according to the provided encoded data. Check sanity against provided config.

    Parameters

    • marginfiAccountPk: PublicKey

      Address of the target account

    • client: MarginfiClient

      marginfi client

    • marginfiAccountRawData: Buffer

      Encoded marginfi marginfi account data

    • marginfiGroup: MarginfiGroup

      MarginfiGroup instance

    Returns MarginfiAccount

    MarginfiAccount instance

Generated using TypeDoc