marginfi

package
v0.4.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package marginfi preloads marginfi-v2 Bank accounts (global market data only -- MarginfiAccount, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load).

Index

Constants

View Source
const SevenDaysOfSlots = 7 * 24 * 60 * 60 * 25 / 10 // 1,512,000 slots

SevenDaysOfSlots assumes ~400ms/slot (2.5 slots/sec), the same fallback bot/state/clock.go itself uses before real slot-timing data arrives -- see raydium/cpmm's own OldSlot for the established precedent of this convention.

Variables

View Source
var (
	DiscMarginfiGroup = [8]byte{182, 23, 173, 240, 151, 206, 182, 67}
	DiscBank          = [8]byte{142, 49, 166, 242, 50, 66, 97, 188}
)

Discriminators for Anchor account types.

View Source
var (
	ProgramID = sgo.MustPublicKeyFromBase58("MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA")
)
View Source
var Schema string

Functions

func ExportJSON

func ExportJSON(db *sql.DB, path string) error

ExportJSON writes every tracked marginfi bank to path as a JSON array of Bank values (its own existing json tags) -- the same real query loadBanks already runs for in-process use, reused verbatim, so catscope-rust-bot's build.rs can read this file instead of opening prefetch.db directly. build.rs's old 3-tier fallback for pre-oracle- column schemas has no equivalent here -- store.DB always migrates the current schema, so every exported row always has oracle_setup/ oracle_key populated.

Types

type Bank

type Bank struct {
	Pubkey sgo.PublicKey `json:"pubkey"`
	Group  sgo.PublicKey `json:"group"`
	Mint   sgo.PublicKey `json:"mint"`
	// OracleSetup is the raw config.oracle_setup enum ordinal. It is NOT
	// always Pyth -- marginfi supports Pyth (legacy/push), Switchboard,
	// a hardcoded "Fixed" price (no oracle account at all, OracleKey will
	// be blank), and even reading other protocols' (Kamino/Drift/Solend/
	// Juplend) own oracle accounts. See marginfi-v2's OracleSetup enum for
	// the full variant list before assuming which oracle type this is.
	OracleSetup uint8 `json:"oracle_setup"`
	// OracleKey is config.oracle_keys[0], the primary oracle account to
	// read for this bank's price. Only the first of marginfi's 5 possible
	// oracle key slots is captured -- every real bank sampled during
	// verification used at most one.
	OracleKey sgo.PublicKey `json:"oracle_key"`
}

Bank is the parsed state of a marginfi-v2 Bank account.

func (*Bank) String

func (b *Bank) String() string

type MarginFi

type MarginFi struct {
	Banks []*Bank
	// contains filtered or unexported fields
}

MarginFi holds all marginfi-v2 Bank accounts loaded at startup.

func Create

func Create(ctx context.Context, stateClient state.Client, db *sql.DB, force bool) (*MarginFi, error)

Create discovers marginfi-v2 groups and banks via an active, per-node Subscribe/ack chain (program -> group, then group -> bank; see event.go, which mirrors orca.fetchWhirlpool's own config->pool chain) and collects all bank accounts, persisting results to db (marginfi_bank). If db already has banks from a previous run, they're loaded back instead of re-fetching, unless force is true.

func (*MarginFi) Find

func (m *MarginFi) Find(bankID sgo.PublicKey) *Bank

Find looks up a bank by its pubkey.

func (*MarginFi) String

func (m *MarginFi) String() string

Source Files

  • bank.go
  • event.go
  • export.go
  • marginfi.go
  • print.go
  • schema.go
  • store.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL