marginpy.account module

class MarginfiAccount(marginfi_account_pk: PublicKey, authority: PublicKey, client: MarginfiClient, group: MarginfiGroup, deposit_record: float, borrow_record: float, mango_utp_data: UtpData, zo_utp_data: UtpData)

Bases: object

Entrypoint to interact with the marginfi contract.

mango: UtpMangoAccount
zo: UtpZoAccount
async classmethod fetch(marginfi_account_pk: PublicKey, client: MarginfiClient) MarginfiAccount

MarginfiAccount network factory.

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

static from_account_data(marginfi_account_pk: PublicKey, client: MarginfiClient, account_data: MarginfiAccountData, marginfi_group: MarginfiGroup) MarginfiAccount

MarginfiAccount local factory (decoded).

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

static from_account_data_raw(marginfi_account_pk: PublicKey, client: MarginfiClient, data: bytes, marginfi_group: MarginfiGroup) MarginfiAccount

MarginfiAccount local factory (encoded).

Instantiates a MarginfiGroup according to the provided encoded data. Check sanity against provided config.

property pubkey: PublicKey
property group: MarginfiGroup
property client: MarginfiClient
property observation_cache: dict[marginpy.types.UtpIndex, marginpy.utp.observation.UtpObservation]
property authority: PublicKey
property all_utps: List[UtpAccount]
property active_utps: List[UtpAccount]
property deposits: float
property borrows: float
static decode(encoded: bytes) MarginfiAccountData

Decodes marginfi account data according to the Anchor IDL.

async static encode(decoded: MarginfiAccountData) bytes

Encodes marginfi account data according to the Anchor IDL.

async reload(observe_utps=False) None

Updates instance data by fetching and storing the latest on-chain state.

Parameters

observe_utps (bool, optional) – flag to request UTP observation as well. Defaults to False.

Raises

Exception – mismatch between the expected group address and the one decoded from the account data

async make_deposit_ix(ui_amount: float) InstructionsWrapper
async deposit(ui_amount: float) TransactionSignature
async make_withdraw_ix(ui_amount: float) InstructionsWrapper
async withdraw(ui_amount: float) TransactionSignature
async make_handle_bankruptcy_ix() InstructionsWrapper
async handle_bankruptcy() TransactionSignature
async get_observation_accounts() List[AccountMeta]

Gets all account metas required for the observation of active UTPs.

async observe_utps() dict[marginpy.types.UtpIndex, marginpy.utp.observation.UtpObservation]

Observes all active UTPs and cache the result.

async load_group_and_account_ai() Tuple[AccountInfo, AccountInfo]

Atomically loads underlying marginfi group and account.

Raises
  • Exception – RPC call errors out

  • Exception – group not found

  • Exception – account not found

Returns

ordered account infos for marginfi group and account

Return type

Tuple[AccountInfo, AccountInfo]

compute_balances(equity_type: EquityType = EquityType.INIT_REQ_ADJUSTED) AccountBalances
compute_margin_requirement(mreq_type: MarginRequirement) float
get_logger()