obligation

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package obligation records this bot's own Solend/Kamino lending obligation state (deposits/borrows, across multimodelv1's pair/ directional/hawkes trade types, since removed) into prefetch.db, the same skip-if-unchanged shape optimizer/prefetch/pnl uses for wallet token balances -- see this package's schema.sql for the real motivation (there was previously no way to see this state without manually deriving each obligation's address and parsing its raw account bytes).

Index

Constants

This section is empty.

Variables

View Source
var KaminoMainMarket = sgo.MustPublicKeyFromBase58("7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF")

KaminoMainMarket is the single lending market every tracked trade type's Kamino obligation lives in -- see catscope-rust-bot's kamino::KAMINO_MAIN_MARKET (src/trader/dex/kamino.rs).

View Source
var Schema string
View Source
var TrackedObligations = []struct {
	TradeType TradeType
	Protocol  Protocol
	ID        uint8
}{
	{TradePair, ProtocolSolend, 1},
	{TradePair, ProtocolKamino, 2},
	{TradeDirectional, ProtocolSolend, 2},
	{TradeDirectional, ProtocolKamino, 3},
	{TradeHawkes, ProtocolSolend, 3},
	{TradeHawkes, ProtocolKamino, 4},
}

TrackedObligation is one (protocol, trade_type) obligation this bot's multimodelv1 mode (since removed) may have bootstrapped -- its id mirrored the exact PAIR_*_OBLIGATION_ID/DIRECTIONAL_*_OBLIGATION_ID/ HAWKES_*_OBLIGATION_ID constants multimodelv1's Rust side used to define. Kept as a fixed table rather than deleted -- any obligation multimodelv1 actually opened on-chain is real and still needs tracking by this exact id regardless of whether the Rust side that opened it still exists.

Functions

func Address

func Address(owner sgo.PublicKey, protocol Protocol, id uint8) (sgo.PublicKey, error)

Address resolves a TrackedObligation entry's real on-chain address for owner.

func KaminoObligationAddress

func KaminoObligationAddress(owner sgo.PublicKey, id uint8) (sgo.PublicKey, error)

KaminoObligationAddress mirrors catscope-rust-bot's kamino:: obligation_pda: seeds `[[0], [id], owner, lending_market, default, default]` (tag=0, standard single-market-slot obligation; seed1/seed2 always the default/all-zero pubkey for every obligation this bot creates -- see obligation_pda's own doc comment in kamino.rs).

func RecordIfChanged

func RecordIfChanged(db *sql.DB, s Snapshot) (bool, error)

RecordIfChanged inserts a new snapshot for (wallet, protocol, trade_type, reserve, kind) only if its amount differs from the most recently recorded one (or none exists yet). Returns whether a row was actually inserted.

func SolendObligationAddress

func SolendObligationAddress(owner sgo.PublicKey, id uint8) (sgo.PublicKey, error)

SolendObligationAddress mirrors solend::obligation_address: a create-with-seed address (not a PDA), deterministic from owner and id.

Types

type CurrentEntry

type CurrentEntry struct {
	Protocol  Protocol
	TradeType TradeType
	Kind      string
	Reserve   sgo.PublicKey
	Amount    uint64
	Time      time.Time
}

CurrentEntry is one (protocol, trade_type, reserve, kind)'s most recently recorded amount -- the "as of now" obligation state.

func Current

func Current(db *sql.DB, wallet sgo.PublicKey) ([]CurrentEntry, error)

Current returns wallet's most recent recorded amount for every (protocol, trade_type, reserve, kind) combination ever seen -- a flat "current obligation state" snapshot, not a timeseries. A reserve whose most recent recorded amount is 0 (fully withdrawn/repaid) is still included; callers that only want real open positions should filter Amount > 0 themselves.

type Entry

type Entry struct {
	Reserve sgo.PublicKey
	// Amount is the raw on-chain unit for this (protocol, kind) --
	// see schema.sql's own doc comment for the exact convention per
	// protocol/kind combination.
	Amount uint64
}

Entry is one deposit or borrow line inside a parsed obligation.

type Parsed

type Parsed struct {
	Deposits []Entry
	Borrows  []Entry
}

Parsed is one obligation account's real deposits/borrows.

func ParseKamino

func ParseKamino(body []byte) (*Parsed, error)

ParseKamino mirrors catscope-rust-bot's kamino::parse_kamino_obligation. Deposits are raw cToken units (NOT yet converted to underlying -- see this package's schema.sql doc comment). Borrows are SF-scaled in the source account; this converts them (/2^60) before returning.

func ParseSolend

func ParseSolend(body []byte) (*Parsed, error)

ParseSolend mirrors catscope-rust-bot's solend::parse_obligation. Deposits are raw underlying-token units (no WAD conversion). Borrows are WAD-scaled in the source account; this converts them (/1e18) before returning, same convention parse_obligation itself uses.

type Protocol

type Protocol string

Protocol is which lending protocol an obligation is on.

const (
	ProtocolSolend Protocol = "solend"
	ProtocolKamino Protocol = "kamino"
)

type Snapshot

type Snapshot struct {
	Time         time.Time
	Wallet       sgo.PublicKey
	Protocol     Protocol
	TradeType    TradeType
	ObligationID uint8
	Kind         string // "deposit" or "borrow"
	Reserve      sgo.PublicKey
	Amount       uint64
}

Snapshot is one (protocol, trade_type, reserve, kind) observation.

type TradeType

type TradeType string

TradeType is which strategy an obligation belongs to -- pair/ directional/hawkes were multimodelv1's trade types (since removed); kept here because a real obligation any of them opened on-chain still needs tracking by its exact id regardless of whether the Rust side that opened it still exists.

const (
	TradePair        TradeType = "pair"
	TradeDirectional TradeType = "directional"
	TradeHawkes      TradeType = "hawkes"
)

Source Files

  • address.go
  • parse.go
  • schema.go
  • store.go

Jump to

Keyboard shortcuts

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