marginfi v2 Protocol Documentation
On this page, we’ll explore all the details of the marginfi-v2 protocol. he marginfi-v2 Protocol is a full open-sourced, overcollateralized lending protocol on Solana.
The marginfi-v2 program is deployed on mainnet-beta, and can be referenced by this address: MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA.
Instructions
lending_account_borrow
- Definition: This endpoint allows a user to borrow a specified amount from a lending account, transferring funds from the bank's liquidity vault to the user's token account, while ensuring the account remains in a healthy state and emitting a borrow event.
- Parameters:
ctx: Context<LendingAccountBorrow>
: A context struct containing various accounts required for the operationmarginfi_account
: The user's MarginfiAccount, which must belong to the specified MarginfiGroupmarginfi_group
: The MarginfiGroup accountsigner
: The signer account, which must match the authority of the marginfi_accountbank
: The Bank account, which must belong to the specified MarginfiGroupdestination_token_account
: The user's token account to receive the borrowed fundsbank_liquidity_vault_authority
: The authority account for the bank's liquidity vaultbank_liquidity_vault
: The bank's liquidity vault token accounttoken_program
: The SPL Token program account
amount: u64
: The amount to be borrowed
lending_account_close_balance
- Definition: This endpoint allows a user to close the balance of their lending account by accruing interest on the bank account, finding the user's bank account, and closing the balance.
- Parameters:
ctx: Context<LendingAccountCloseBalance>
: A context struct containing various accounts required for the operationmarginfi_group
: The MarginfiGroup accountmarginfi_account
: The user's MarginfiAccount, which must belong to the specified MarginfiGroupsigner
: The signer account, which must match the authority of the marginfi_accountbank
: The Bank account, which must belong to the specified MarginfiGroup
lending_account_deposit
- Definition: This endpoint allows a user to deposit a specified amount into their lending account, transferring funds from the user's token account to the bank's liquidity vault, while ensuring the account remains in a healthy state and emitting a deposit event.
- Parameters:
ctx: Context<LendingAccountDeposit>
: A context struct containing various accounts required for the operationmarginfi_group
: The MarginfiGroup accountmarginfi_account
: The user's MarginfiAccount, which must belong to the specified MarginfiGroupsigner
: The signer account, which must match the authority of the marginfi_accountbank
: The Bank account, which must belong to the specified MarginfiGroupsigner_token_account
: The user's token account to transfer funds frombank_liquidity_vault
: The bank's liquidity vault token accounttoken_program
: The SPL Token program account
amount: u64
: The amount to be deposited
lending_account_withdraw_emissions
- Definition: This endpoint allows a user to withdraw their settled emissions from their lending account by transferring the emissions tokens from the bank's emissions vault to the user's specified token account.
- Parameters:
ctx: Context<LendingAccountWithdrawEmissions>
: A context struct containing various accounts required for the operationmarginfi_group
: The MarginfiGroup accountmarginfi_account
: The user's MarginfiAccount, which must belong to the specified MarginfiGroupsigner
: The signer account, which must match the authority of the marginfi_accountbank
: The Bank account, which must belong to the specified MarginfiGroupemissions_mint
: The mint account for the emissions tokenemissions_auth
: The authority account for the emissions vault, derived from a PDA seedemissions_vault
: The emissions vault token account, derived from a PDA seeddestination_account
: The user's token account to receive the withdrawn emissionstoken_program
: The SPL Token program account
lending_account_settle_emissions
- Definition: This endpoint allows a user to permissionlessly settle their unclaimed emissions by finding their bank account balance and claiming the emissions.
- Parameters:
ctx: Context<LendingAccountSettleEmissions>
: A context struct containing two accountsmarginfi_account
: The user's MarginfiAccount, which must belong to the same group as the Bankbank
: The Bank account
lending_account_start_flashloan
- Definition: This function starts a flashloan by checking if the flashloan can be initiated based on various conditions, and if so, sets the
IN_FLASHLOAN_FLAG
on the user's MarginfiAccount. - Parameters:
ctx: Context<LendingAccountStartFlashloan>
: A context struct containing the following accounts:marginfi_account
: The user's MarginfiAccount accountsigner
: The signer account, which must match the authority of the marginfi_accountixs_sysvar
: The instructions sysvar account
end_index: u64
: The index of the instruction where the flashloan should end
check_flashloan_can_start
- Definition: This function checks if a flashloan can be initiated by verifying various conditions, such as the account not being disabled, the end_flashloan instruction existing and being valid, and the account not already being in a flashloan.
- Parameters:
marginfi_account: &AccountLoader<MarginfiAccount>
: A reference to the user's MarginfiAccount accountsysvar_ixs: &AccountInfo
: A reference to the instructions sysvar accountend_fl_idx: usize
: The index of the instruction where the flashloan should end
lending_account_end_flashloan
- Definition: This function ends a flashloan by checking that the instruction is not in a CPI, unsets the
IN_FLASHLOAN_FLAG
on the user's MarginfiAccount, and verifies the account's health after the flashloan. - Parameters:
ctx: Context<LendingAccountEndFlashloan>
: A context struct containing the following accounts:marginfi_account
: The user's MarginfiAccount accountsigner
: The signer account, which must match the authority of the marginfi_account
initialize_account
- Definition: This endpoint initializes a new MarginfiAccount for the specified authority and MarginfiGroup, emitting a MarginfiAccountCreateEvent with details about the new account.
- Parameters:
ctx: Context<MarginfiAccountInitialize>
: A context struct containing various accounts required for the operationmarginfi_group
: The MarginfiGroup accountmarginfi_account
: The new MarginfiAccount account to be initializedauthority
: The signer account, which will be set as the authority of the new MarginfiAccountfee_payer
: The fee payer account, which must be a signer and will pay for the account creationsystem_program
: The System program account
lending_account_liquidate
- Definition: This endpoint allows a liquidator to liquidate an unhealthy position owned by a margin account. The liquidator purchases discounted collateral from the unhealthy account in exchange for paying off its debt. The function handles the transfer of assets and liabilities between the accounts, charges liquidation and insurance fees, and verifies that the liquidated account's health has improved and the liquidator's account remains healthy after the operation. It also emits a LendingAccountLiquidateEvent with details about the liquidation.
- Parameters:
ctx: Context<LendingAccountLiquidate>
: A context struct containing various accounts required for the operationmarginfi_group
: The MarginfiGroup accountasset_bank
: The Bank account for the asset token being liquidatedliab_bank
: The Bank account for the liability tokenliquidator_marginfi_account
: The MarginfiAccount of the liquidatorsigner
: The signer account, which must match the authority of the liquidator_marginfi_accountliquidatee_marginfi_account
: The MarginfiAccount of the account being liquidatedbank_liquidity_vault_authority
: The authority account for the bank's liquidity vault (derived from a PDA seed)bank_liquidity_vault
: The bank's liquidity vault token account (derived from a PDA seed)bank_insurance_vault
: The bank's insurance vault token account (derived from a PDA seed)token_program
: The SPL Token program account
asset_amount: u64
: The amount of the asset token to be liquidated
lending_account_repay
- Definition: This endpoint allows a user to repay a specified amount or the entire liability of their lending account by transferring funds from the user's token account to the bank's liquidity vault, updating the liability balance in the user's bank account, accruing interest on the bank account, and emitting a LendingAccountRepayEvent with details about the repayment.
- Parameters:
ctx: Context<LendingAccountRepay>
: A context struct containing various accounts required for the operationmarginfi_group
: The MarginfiGroup accountmarginfi_account
: The user's MarginfiAccount, which must belong to the specified MarginfiGroupsigner
: The signer account, which must match the authority of the marginfi_accountbank
: The Bank account, which must belong to the specified MarginfiGroupsigner_token_account
: The user's token account to transfer funds frombank_liquidity_vault
: The bank's liquidity vault token account (derived from a PDA seed)token_program
: The SPL Token program account
amount: u64
: The amount to be repaidrepay_all: Option<bool>
: A flag to indicate if the entire liability should be repaid
set_account_transfer_authority
- Definition: This endpoint allows the current authority of a MarginfiAccount to set a new authority for that account. It loads the marginfi_account, verifies that the signer is the current authority, and calls the
set_new_account_authority_checked
method on the marginfi_account to set the new authority. Note that it currently does not emit any events due to memory constraints. - Parameters:
ctx: Context<MarginfiAccountSetAccountAuthority>
: A context struct containing various accounts required for the operationmarginfi_account
: The user's MarginfiAccount accountmarginfi_group
: The MarginfiGroup account, which is verified by the address stored in the marginfi_accountsigner
: The signer account, which must match the current authority of the marginfi_accountnew_authority
: The account that will be set as the new authority for the marginfi_accountfee_payer
: The fee payer account, which must be a signer
lending_account_withdraw
- Definition: This endpoint allows a user to withdraw a specified amount or the entire asset from their lending account by transferring funds from the bank's liquidity vault to the user's token account, updating the asset balance in the user's bank account, accruing interest on the bank account, and emitting a LendingAccountWithdrawEvent with details about the withdrawal. It also verifies that the user's account remains in a healthy state after the withdrawal.
- Parameters:
ctx: Context<LendingAccountWithdraw>
: A context struct containing various accounts required for the operationmarginfi_group
: The MarginfiGroup accountmarginfi_account
: The user's MarginfiAccount, which must belong to the specified MarginfiGroupsigner
: The signer account, which must match the authority of the marginfi_accountbank
: The Bank account, which must belong to the specified MarginfiGroupdestination_token_account
: The user's token account to receive the withdrawn fundsbank_liquidity_vault_authority
: The authority account for the bank's liquidity vault (derived from a PDA seed)bank_liquidity_vault
: The bank's liquidity vault token account (derived from a PDA seed)token_program
: The SPL Token program account
amount: u64
: The amount to be withdrawnwithdraw_all: Option<bool>
: A flag to indicate if the entire asset should be withdrawn
lending_pool_accrue_bank_interest
- Definition: This endpoint allows accruing interest on a specific Bank account by loading the Bank account, getting the current timestamp from the Clock sysvar, and calling the
accrue_interest
method on the Bank account. This function is likely used to update the interest rates and balances of the Bank account based on the elapsed time since the last interest accrual. - Parameters:
ctx: Context<LendingPoolAccrueBankInterest>
: A context struct containing two accountsmarginfi_group
: The MarginfiGroup accountbank
: The Bank account, which must belong to the specified MarginfiGroup
lending_pool_add_bank
- Definition: Adds a new bank to the lending pool. This function can only be called by the admin.
- Parameters:
ctx: Context<LendingPoolAddBank>
: The context struct containing the accounts required for the operation.marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account.admin: Signer<'info>
: The admin account authorized to perform this operation.fee_payer: Signer<'info>
: The account responsible for paying the transaction fees.bank_mint: Box<Account<'info, Mint>>
: The mint account for the bank's token.bank: AccountLoader<'info, Bank>
: The account loader for the new Bank account being initialized.liquidity_vault_authority: AccountInfo<'info>
: The authority account for the liquidity vault.liquidity_vault: Box<Account<'info, TokenAccount>>
: The token account for the liquidity vault.insurance_vault_authority: AccountInfo<'info>
: The authority account for the insurance vault.insurance_vault: Box<Account<'info, TokenAccount>>
: The token account for the insurance vault.fee_vault_authority: AccountInfo<'info>
: The authority account for the fee vault.fee_vault: Box<Account<'info, TokenAccount>>
: The token account for the fee vault.rent: Sysvar<'info, Rent>
: The Rent sysvar account.token_program: Program<'info, Token>
: The Token program account.system_program: Program<'info, System>
: The System program account.
bank_config: BankConfig
: The configuration settings for the new bank.
lending_pool_add_bank_with_seed
- Definition: Similar to
lending_pool_add_bank
, but includes an additional seed parameter that is used to generate a Program Derived Address (PDA) for the new Bank account. This PDA can be used to securely sign transactions related to the new bank. - Parameters:
ctx: Context<LendingPoolAddBankWithSeed>
: The context struct containing the accounts required for the operation (similar toLendingPoolAddBank
).marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account.admin: Signer<'info>
: The admin account authorized to perform this operation.fee_payer: Signer<'info>
: The account responsible for paying the transaction fees.bank_mint: Box<Account<'info, Mint>>
: The mint account for the bank's token.bank: AccountLoader<'info, Bank>
: The account loader for the new Bank account being initialized (as a PDA).liquidity_vault_authority: AccountInfo<'info>
: The authority account for the liquidity vault.liquidity_vault: Box<Account<'info, TokenAccount>>
: The token account for the liquidity vault.insurance_vault_authority: AccountInfo<'info>
: The authority account for the insurance vault.insurance_vault: Box<Account<'info, TokenAccount>>
: The token account for the insurance vault.fee_vault_authority: AccountInfo<'info>
: The authority account for the fee vault.fee_vault: Box<Account<'info, TokenAccount>>
: The token account for the fee vault.rent: Sysvar<'info, Rent>
: The Rent sysvar account.token_program: Program<'info, Token>
: The Token program account.system_program: Program<'info, System>
: The System program account.
bank_config: BankConfig
: The configuration settings for the new bank.bank_seed: u64
: The seed value used to generate the PDA for the new Bank account.
lending_pool_collect_bank_fees
- Definition: Collects the outstanding insurance and group fees from the liquidity vault of a bank and transfers them to the insurance and fee vaults, respectively.
- Parameters:
ctx: Context<LendingPoolCollectBankFees>
: The context struct containing the accounts required for the operation.marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account.bank: AccountLoader<'info, Bank>
: The Bank account from which to collect fees.liquidity_vault_authority: AccountInfo<'info>
: The authority account for the liquidity vault.liquidity_vault: Account<'info, TokenAccount>
: The token account for the liquidity vault.insurance_vault: AccountInfo<'info>
: The token account for the insurance vault.fee_vault: AccountInfo<'info>
: The token account for the fee vault.token_program: Program<'info, Token>
: The Token program account.
lending_pool_withdraw_fees
- Definition: Withdraws a specified amount of tokens from the fee vault of a bank to a destination token account.
- Parameters:
ctx: Context<LendingPoolWithdrawFees>
: The context struct containing the accounts required for the operation.marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account.bank: AccountLoader<'info, Bank>
: The Bank account from which to withdraw fees.admin: Signer<'info>
: The admin account authorized to perform this operation.fee_vault: AccountInfo<'info>
: The token account for the fee vault.fee_vault_authority: AccountInfo<'info>
: The authority account for the fee vault.dst_token_account: AccountInfo<'info>
: The destination token account to receive the withdrawn tokens.token_program: Program<'info, Token>
: The Token program account.
amount: u64
: The amount of tokens to withdraw from the fee vault.
lending_pool_withdraw_insurance
- Definition: Withdraws a specified amount of tokens from the insurance vault of a bank to a destination token account.
- Parameters:
ctx: Context<LendingPoolWithdrawInsurance>
: The context struct containing the accounts required for the operation.marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account.bank: AccountLoader<'info, Bank>
: The Bank account from which to withdraw insurance funds.admin: Signer<'info>
: The admin account authorized to perform this operation.insurance_vault: AccountInfo<'info>
: The token account for the insurance vault.insurance_vault_authority: AccountInfo<'info>
: The authority account for the insurance vault.dst_token_account: AccountInfo<'info>
: The destination token account to receive the withdrawn tokens.token_program: Program<'info, Token>
: The Token program account.
amount: u64
: The amount of tokens to withdraw from the insurance vault.
lending_pool_update_emissions_parameters
- Definition: Updates the emissions parameters for a Bank, including setting up the initial emissions configuration, updating the emissions flags and rate, and funding additional emissions tokens.
- Parameters:
ctx: Context<LendingPoolUpdateEmissionsParameters>
: The context struct containing the accounts required for the operation.marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account that contains the Bank.admin: Signer<'info>
: The admin account authorized to perform this operation.bank: AccountLoader<'info, Bank>
: The Bank account for which to update emissions parameters.emissions_mint: Account<'info, Mint>
: The mint account for the emissions token.emissions_token_account: Box<Account<'info, TokenAccount>>
: The token account holding the emissions tokens.emissions_funding_account: AccountInfo<'info>
: The account used to fund additional emissions tokens.token_program: Program<'info, Token>
: The Token program account.
emissions_flags: Option<u64>
: The new flags to set for the emissions configuration (if provided).emissions_rate: Option<u64>
: The new rate at which emissions should be distributed (if provided).additional_emissions: Option<u64>
: The additional amount of emissions tokens to be funded (if provided).
lending_pool_handle_bankruptcy
- Definition: Handles the bankruptcy of a MarginfiAccount by covering the bad debt using the insurance fund and socializing any remaining loss among depositors.
- Parameters:
ctx: Context<LendingPoolHandleBankruptcy>
: The context struct containing the accounts required for the operation.marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account.signer: Signer<'info>
: The account authorized to initiate the bankruptcy process (either the admin or a special flag is enabled for permissionless operation).bank: AccountLoader<'info, Bank>
: The Bank account associated with the bankrupt MarginfiAccount.marginfi_account: AccountLoader<'info, MarginfiAccount>
: The bankrupt MarginfiAccount.liquidity_vault: AccountInfo<'info>
: The token account representing the liquidity vault, from which bad debt can be covered.insurance_vault: Box<Account<'info, TokenAccount>>
: The token account representing the insurance vault, which holds funds to cover bad debt.insurance_vault_authority: AccountInfo<'info>
: The authority account for the insurance vault.token_program: Program<'info, Token>
: The Token program account.
initialize_group
- Definition: Initializes a new MarginfiGroup and sets its initial configuration, including the admin account. Finally, it emits an event to indicate the successful creation of the MarginfiGroup.
- Parameters:
ctx: Context<MarginfiGroupInitialize>
: The context struct containing the accounts required for the operation.marginfi_group: AccountLoader<'info, MarginfiGroup>
: The MarginfiGroup account to be initialized.admin: Signer<'info>
: The admin account responsible for initializing the MarginfiGroup.system_program: Program<'info, System>
: The System program account.
Errors
Errors
- Name
InternalLogicError
- Type
- 6000
- Description
Internal Marginfi logic error. Indicates an unexpected internal failure.
- Name
BankNotFound
- Type
- 6001
- Description
Invalid bank index. The specified bank index is not recognized.
- Name
LendingAccountBalanceNotFound
- Type
- 6002
- Description
Lending account balance not found. Ensure the account is properly initialized.
- Name
BankAssetCapacityExceeded
- Type
- 6003
- Description
Bank deposit capacity exceeded. The deposit surpasses the allowed limit.
- Name
InvalidTransfer
- Type
- 6004
- Description
Invalid transfer. Verify ownership and transfer parameters.
- Name
MissingPythOrBankAccount
- Type
- 6005
- Description
Missing Oracle, Bank, LST mint, or Sol Pool. Required accounts not provided.
- Name
MissingPythAccount
- Type
- 6006
- Description
Missing Pyth account. Provide a valid oracle feed.
- Name
MissingBankAccount
- Type
- 6007
- Description
Missing Bank account. Required for the operation.
- Name
InvalidBankAccount
- Type
- 6008
- Description
Invalid Bank account. Ensure it's correct and initialized.
- Name
RiskEngineInitRejected
- Type
- 6009
- Description
Rejected due to bad health or stale oracles. Check account health and data freshness.
- Name
LendingAccountBalanceSlotsFull
- Type
- 6010
- Description
Lending balance slots full. Free up space before proceeding.
- Name
BankAlreadyExists
- Type
- 6011
- Description
Bank already exists. Use a different identifier.
- Name
ZeroLiquidationAmount
- Type
- 6012
- Description
Liquidation amount must be positive. Adjust your input value.
- Name
AccountNotBankrupt
- Type
- 6013
- Description
Account is not bankrupt. Check criteria before proceeding.
- Name
BalanceNotBadDebt
- Type
- 6014
- Description
Balance not bad debt. Operation only valid for bad debt.
- Name
InvalidConfig
- Type
- 6015
- Description
Invalid group config. Verify configuration parameters.
- Name
BankPaused
- Type
- 6016
- Description
Bank paused. Operation temporarily disabled.
- Name
BankReduceOnly
- Type
- 6017
- Description
Bank in reduce-only mode. Only reduction actions allowed.
- Name
BankAccountNotFound
- Type
- 6018
- Description
Bank is missing. Ensure the account exists.
- Name
OperationDepositOnly
- Type
- 6019
- Description
Deposit-only operation. Other operations not permitted.
- Name
OperationWithdrawOnly
- Type
- 6020
- Description
Withdraw-only operation. Only withdrawals are allowed.
- Name
OperationBorrowOnly
- Type
- 6021
- Description
Borrow-only operation. Restriction in place for borrowing.
- Name
OperationRepayOnly
- Type
- 6022
- Description
Repay-only operation. Action must be a repayment.
- Name
NoAssetFound
- Type
- 6023
- Description
No asset found. Ensure the referenced asset exists.
- Name
NoLiabilityFound
- Type
- 6024
- Description
No liability found. Ensure the liability is initialized.
- Name
InvalidOracleSetup
- Type
- 6025
- Description
Invalid oracle setup. Configuration parameters are incorrect.
- Name
IllegalUtilizationRatio
- Type
- 6026
- Description
Invalid bank utilization ratio. Check bounds and limits.
- Name
BankLiabilityCapacityExceeded
- Type
- 6027
- Description
Bank borrow cap exceeded. Reduce borrow amount.
- Name
InvalidPrice
- Type
- 6028
- Description
Invalid price. Ensure price value is within range.
- Name
IsolatedAccountIllegalState
- Type
- 6029
- Description
Illegal isolated account state. Only one liability allowed.
- Name
EmissionsAlreadySetup
- Type
- 6030
- Description
Emissions already setup. Cannot repeat setup.
- Name
OracleNotSetup
- Type
- 6031
- Description
Oracle not set up. Initialize before use.
- Name
InvalidSwitchboardDecimalConversion
- Type
- 6032
- Description
Invalid Switchboard decimal conversion. Check conversion values.
- Name
CannotCloseOutstandingEmissions
- Type
- 6033
- Description
Outstanding emissions prevent balance closure. Settle emissions first.
- Name
EmissionsUpdateError
- Type
- 6034
- Description
Error during emissions update. Review parameters.
- Name
AccountDisabled
- Type
- 6035
- Description
Account is disabled. Reactivate to continue.
- Name
AccountTempActiveBalanceLimitExceeded
- Type
- 6036
- Description
Temporary active balance limit exceeded. Close existing balances.
- Name
AccountInFlashloan
- Type
- 6037
- Description
Account in flashloan. Wait or validate state.
- Name
IllegalFlashloan
- Type
- 6038
- Description
Illegal flashloan. Check parameters and permissions.
- Name
IllegalFlag
- Type
- 6039
- Description
Illegal flag. Value is not permitted.
- Name
IllegalBalanceState
- Type
- 6040
- Description
Illegal balance state. Confirm state validity.
- Name
IllegalAccountAuthorityTransfer
- Type
- 6041
- Description
Illegal authority transfer. Validate permission and setup.
- Name
Unauthorized
- Type
- 6042
- Description
Unauthorized. Missing necessary permissions.
- Name
IllegalAction
- Type
- 6043
- Description
Invalid account authority. Not authorized for this action.
- Name
T22MintRequired
- Type
- 6044
- Description
Missing mint account for Token22 bank. Provide it as the first remaining account.
- Name
InvalidFeeAta
- Type
- 6045
- Description
Invalid ATA for global fee account. Must match expected account.
- Name
AddedStakedPoolManually
- Type
- 6046
- Description
Manual pool addition not allowed. Use permissionless add method.
- Name
AssetTagMismatch
- Type
- 6047
- Description
Staked SOL accounts restricted to staking assets and borrowing SOL.
- Name
StakePoolValidationFailed
- Type
- 6048
- Description
Stake pool validation failed. Check stake pool, mint, and sol pool setup.
- Name
SwitchboardStalePrice
- Type
- 6049
- Description
Stale price from Switchboard oracle. Refresh the feed.
- Name
PythPushStalePrice
- Type
- 6050
- Description
Stale price from Pyth Push oracle. Update required.
- Name
WrongNumberOfOracleAccounts
- Type
- 6051
- Description
Incorrect number of oracle accounts. Review account list.
- Name
WrongOracleAccountKeys
- Type
- 6052
- Description
Incorrect oracle account keys. Ensure the keys are valid.
- Name
PythPushWrongAccountOwner
- Type
- 6053
- Description
Wrong account owner for Pyth Push oracle. Check account ownership.
- Name
StakedPythPushWrongAccountOwner
- Type
- 6054
- Description
Wrong owner for Staked Pyth Push oracle account. Check setup.
- Name
PythPushMismatchedFeedId
- Type
- 6055
- Description
Mismatched feed ID in Pyth Push oracle. Must match expected value.
- Name
PythPushInsufficientVerificationLevel
- Type
- 6056
- Description
Insufficient verification level in Pyth Push oracle.
- Name
PythPushFeedIdMustBe32Bytes
- Type
- 6057
- Description
Feed ID must be 32 bytes for Pyth Push oracle.
- Name
PythPushFeedIdNonHexCharacter
- Type
- 6058
- Description
Feed ID contains non-hex characters in Pyth Push oracle.
- Name
SwitchboardWrongAccountOwner
- Type
- 6059
- Description
Wrong account owner for Switchboard oracle.
- Name
PythPushInvalidAccount
- Type
- 6060
- Description
Invalid account for Pyth Push oracle.
- Name
SwitchboardInvalidAccount
- Type
- 6061
- Description
Invalid account for Switchboard oracle.
- Name
MathError
- Type
- 6062
- Description
Math error. Check for overflows or invalid operations.
- Name
InvalidEmissionsDestinationAccount
- Type
- 6063
- Description
Invalid emissions destination account. Ensure it's correctly configured.
- Name
SameAssetAndLiabilityBanks
- Type
- 6064
- Description
Asset and liability banks must differ.
- Name
OverliquidationAttempt
- Type
- 6065
- Description
Withdrawal exceeds available assets. Reduce withdrawal amount.
- Name
NoLiabilitiesInLiabilityBank
- Type
- 6066
- Description
No liabilities exist in liability bank.
- Name
AssetsInLiabilityBank
- Type
- 6067
- Description
Liability bank contains assets. Invalid configuration.
- Name
HealthyAccount
- Type
- 6068
- Description
Account is healthy. Cannot proceed with liquidation.
- Name
ExhaustedLiability
- Type
- 6069
- Description
Liability payoff too severe. No more liability remains.
- Name
TooSeverePayoff
- Type
- 6070
- Description
Liability balance has assets. Payoff is overly aggressive.
- Name
TooSevereLiquidation
- Type
- 6071
- Description
Liquidation exceeds requirements. Account above maintenance.
- Name
WorseHealthPostLiquidation
- Type
- 6072
- Description
Liquidation worsens account health. Not allowed.
- Name
ArenaBankLimit
- Type
- 6073
- Description
Arena groups support max two banks. Reduce bank count.
- Name
ArenaSettingCannotChange
- Type
- 6074
- Description
Arena groups cannot revert to non-arena. Setting is immutable.
Constants
- Name
LIQUIDITY_VAULT_AUTHORITY_SEED
- Type
- &str
- Description
Seed used to derive the authority for the liquidity vault.
- Name
INSURANCE_VAULT_AUTHORITY_SEED
- Type
- &str
- Description
Seed used to derive the authority for the insurance vault.
- Name
FEE_VAULT_AUTHORITY_SEED
- Type
- &str
- Description
Seed used to derive the authority for the fee vault.
- Name
LIQUIDITY_VAULT_SEED
- Type
- &str
- Description
Seed used to derive the address of the liquidity vault.
- Name
INSURANCE_VAULT_SEED
- Type
- &str
- Description
Seed used to derive the address of the insurance vault.
- Name
FEE_VAULT_SEED
- Type
- &str
- Description
Seed used to derive the address of the fee vault.
- Name
EMISSIONS_AUTH_SEED
- Type
- &str
- Description
Seed used to derive the authority for emissions.
- Name
EMISSIONS_TOKEN_ACCOUNT_SEED
- Type
- &str
- Description
Seed used to derive the address of the emissions token account.
- Name
PYTH_ID
- Type
- Pubkey
- Description
The public key of the Pyth program ID, used for price feeds.
- Name
LIQUIDATION_LIQUIDATOR_FEE
- Type
- I80F48
- Description
The fee charged to the liquidator during a liquidation event.
- Name
LIQUIDATION_INSURANCE_FEE
- Type
- I80F48
- Description
The fee charged to the insurance fund during a liquidation event.
- Name
SECONDS_PER_YEAR
- Type
- I80F48
- Description
The number of seconds in a year (used for interest rate calculations).
- Name
MAX_PRICE_AGE_SEC
- Type
- u64
- Description
The maximum age (in seconds) allowed for a price feed before it is considered stale.
- Name
CONF_INTERVAL_MULTIPLE
- Type
- I80F48
- Description
A multiplier used to calculate the confidence interval for price feeds.
- Name
STD_DEV_MULTIPLE
- Type
- I80F48
- Description
A multiplier used to calculate the standard deviation for price feeds.
- Name
MAX_CONF_INTERVAL
- Type
- I80F48
- Description
The maximum allowed confidence interval for price feeds.
- Name
USDC_EXPONENT
- Type
- i32
- Description
The exponent used for USDC (as it has 6 decimal places).
- Name
MAX_ORACLE_KEYS
- Type
- usize
- Description
The maximum number of oracle keys allowed.
- Name
EMPTY_BALANCE_THRESHOLD
- Type
- I80F48
- Description
The threshold below which a balance is considered empty (to account for arithmetic artifacts).
- Name
BANKRUPT_THRESHOLD
- Type
- I80F48
- Description
The threshold below which an account is considered bankrupt (in USD).
- Name
ZERO_AMOUNT_THRESHOLD
- Type
- I80F48
- Description
A threshold used to account for arithmetic artifacts when comparing amounts.
- Name
EMISSIONS_FLAG_BORROW_ACTIVE
- Type
- u64
- Description
A flag indicating that borrowing is active for emissions.
- Name
EMISSIONS_FLAG_LENDING_ACTIVE
- Type
- u64
- Description
A flag indicating that lending is active for emissions.
- Name
PERMISSIONLESS_BAD_DEBT_SETTLEMENT_FLAG
- Type
- u64
- Description
A flag indicating that permissionless bad debt settlement is enabled.
- Name
EMISSION_FLAGS
- Type
- u64
- Description
A combination of emission flags (borrowing and lending).
- Name
GROUP_FLAGS
- Type
- u64
- Description
A combination of group flags (permissionless bad debt settlement).
- Name
MIN_EMISSIONS_START_TIME
- Type
- u64
- Description
The minimum timestamp used for calculating emissions (any balance updates before this time are ignored).
- Name
MAX_EXP_10_I80F48
- Type
- usize
- Description
The maximum exponent for the
EXP_10_I80F48
array.
- Name
EXP_10_I80F48
- Type
- [I80F48; MAX_EXP_10_I80F48]
- Description
An array of
I80F48
values representing powers of 10 (up to 10^23).
- Name
MAX_EXP_10
- Type
- usize
- Description
The maximum exponent for the
EXP_10
array.
- Name
EXP_10
- Type
- [i128; MAX_EXP_10]
- Description
An array of
i128
values representing powers of 10 (up to 10^20).
- Name
TOTAL_ASSET_VALUE_INIT_LIMIT_INACTIVE
- Type
- u64
- Description
The value at which the total asset value initialization limit is considered inactive.
Security
Audits
marginfi v2 has been rigorously audited both internally and by Ottersec. Audits can be found here.
Fuzz Tests
marginfi v2 fuzz tests are open source and can be found here.
Verification
Anyone can assert that a specific commit is currently deployed to the marginfi-v2 program, using the solana-verify.
Prerequisites:
- Git
- Docker
- Rust
- Solana CLI
- solana-verify
- Identify the commit you want to check
- Clone the marginfi-v2 repo locally
- Checkout that commit
- Generate the verifiable program binary:
solana-verify build --library-name marginfi -- --features mainnet-beta
- Compute the hash of the program binary generated at the previous step:
solana-verify get-executable-hash target/deploy/marginfi.so
- Compute the hash of the program binary currently deployed on-chain:
solana-verify get-program-hash MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA
, or alternatively compute the hash of the buffer you are checkingsolana-verify get-buffer-hash <buffer address>
- Ensure they match