leveragedloopv1

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: 23 Imported by: 0

Documentation

Overview

Package leveragedloopv1 is the Go-side orchestrator for leveragedloopv1 -- Phase 2 of catscope-rust-bot's leveraged_yield_farming_plan.md: a single, conservative jitoSOL-collateral/USDC-debt leverage loop on Kamino, manual/explicit trigger only. A direct copy of package testperpv1's orchestration shape (same allocation/upload/handshake/ wallet-init flow, only MODE=leveragedloopv1 selected at upload time), minus the target-allocation plumbing testperpv1 carries for the basis-trade strategy -- this mode has no use for it.

It implements the brain.Brain interface and is responsible for:

  • Allocating a slot on a Catscope/Solpipe validator pipeline (bid = 0, free tier).
  • Uploading a WASM bot image to the validator with MODE=leveragedloopv1.
  • Completing the handshake with the running bot instance.
  • Sending a child keypair to the bot via stdin -- this mode's Rust side (catscope-rust-bot/src/brain/leveragedloopv1) signs the real Kamino deposit/borrow/withdraw/repay transactions its evaluate() state machine builds.
  • Sending TriggerOpen/TriggerClose to the running bot on request (see eval.go's SendTriggerOpen/SendTriggerClose) -- nothing opens or closes a real position without one of these being called explicitly.

Deliberately a **separate bot mode and Kamino obligation** from testperpv1 -- see catscope-rust-bot's src/brain/leveragedloopv1/mod.rs doc comment for why.

Index

Constants

View Source
const (
	KeyFlagEchoRequest                   uint8 = 1
	KeyFlagEchoResponse                  uint8 = 2
	KeyFlagWallet                        uint8 = 3
	KeyFlagTriggerOpen                   uint8 = 4
	KeyFlagTriggerClose                  uint8 = 5
	KeyFlagTriggerRecoverToken           uint8 = 6
	KeyFlagTriggerRedepositUsdc          uint8 = 7
	KeyFlagTriggerTestBundler            uint8 = 8
	KeyFlagTriggerTestBatch              uint8 = 9
	KeyFlagLstApy                        uint8 = 10
	KeyFlagTriggerOpenAuto               uint8 = 11
	KeyFlagTriggerEnableBasisTrading     uint8 = 12
	KeyFlagTriggerCloseAllBasisPositions uint8 = 13
	// KeyFlagCommonAccountUsage is shared across every brain/* package
	// (not just this one) -- see the doc comment above.
	KeyFlagCommonAccountUsage uint8 = 200
)

Variables

View Source
var ErrBotNotConnectedYet = errors.New("leveragedloopv1: bot not connected yet")

ErrBotNotConnectedYet is returned by the Send* trigger methods below when `hs.instance` hasn't been set yet -- see their shared doc comment on `nilInstance` for why this check exists and how callers should react to it.

Functions

func DoEchoRequest

func DoEchoRequest(payload string) catmsg.FixedPair

func DoLstApy

func DoLstApy(mint sgo.PublicKey, stakingApy float64) catmsg.FixedPair

DoLstApy builds the wire message for a real annualized LST staking-yield update (fraction, e.g. 0.073 for 7.3%/yr) for one liquid-staking-token, keyed by its real mint pubkey rather than a symbol -- see KeyFlagLstApy's doc comment above for why.

func DoTriggerClose

func DoTriggerClose() catmsg.FixedPair

DoTriggerClose builds the wire message requesting the bot deleverage and close its current position.

func DoTriggerCloseAllBasisPositions

func DoTriggerCloseAllBasisPositions() catmsg.FixedPair

DoTriggerCloseAllBasisPositions builds the wire message force-closing every currently-open basis-trade position, independent of the cycle's own logic -- see KeyFlagTriggerCloseAllBasisPositions's doc comment above.

func DoTriggerEnableBasisTrading

func DoTriggerEnableBasisTrading() catmsg.FixedPair

DoTriggerEnableBasisTrading builds the wire message opting into the real Phoenix-perp-funding-vs-Kamino-rate basis trade -- a one-time enable, see KeyFlagTriggerEnableBasisTrading's doc comment above.

func DoTriggerOpen

func DoTriggerOpen(notionalUSD float64) catmsg.FixedPair

DoTriggerOpen builds the wire message requesting the bot open a real leveraged position, sized at notionalUSD.

func DoTriggerOpenAuto

func DoTriggerOpenAuto(notionalUSD float64) catmsg.FixedPair

DoTriggerOpenAuto builds the wire message for a real TriggerOpenAuto -- same notional-USD payload as DoTriggerOpen, but the bot picks the LST candidate itself via its own Time-Expanded DAG.

func DoTriggerRecoverToken

func DoTriggerRecoverToken(mint sgo.PublicKey) catmsg.FixedPair

DoTriggerRecoverToken builds the wire message requesting the bot swap its entire real balance of mint back to USDC, independent of the loop's phase.

func DoTriggerRedepositUsdc

func DoTriggerRedepositUsdc(notionalUSD float64) catmsg.FixedPair

DoTriggerRedepositUsdc builds the wire message requesting the bot swap notionalUSD of USDC to jitoSOL and deposit it as additional Kamino collateral, independent of the loop's phase.

func DoTriggerTestBatch

func DoTriggerTestBatch() catmsg.FixedPair

DoTriggerTestBatch builds the wire message requesting the bot send two separate, real, deliberately inert transactions via the generic transactionprocessor::batch host import (not send_bundler_pair's durable-nonce pair).

func DoTriggerTestBundler

func DoTriggerTestBundler() catmsg.FixedPair

DoTriggerTestBundler builds the wire message requesting the bot send a trivial, real Astralane dual-transaction bundle -- proves the pipeline end-to-end without risking a real trading operation on it.

func DoWallet

func DoWallet(key sgo.PrivateKey) catmsg.FixedPair

Types

type Configuration

type Configuration struct {
	BotImage string
}

type Hook

type Hook interface {
	brain.Brain
	SendTriggerOpen(notionalUSD float64) error
	SendTriggerOpenAuto(notionalUSD float64) error
	SendTriggerEnableBasisTrading() error
	SendTriggerCloseAllBasisPositions() error
	SendTriggerClose() error
	SendTriggerRecoverToken(mint sgo.PublicKey) error
	SendTriggerRedepositUsdc(notionalUSD float64) error
	SendTriggerTestBundler() error
	SendTriggerTestBatch() error
	SendBundlerTipUpdate(update bundler.TipUpdate) error
}

Hook is brain.Brain plus this mode's own explicit trigger senders -- returned instead of a bare brain.Brain so cmd/leveragedloop.go can call SendTriggerOpen/SendTriggerClose on the same instance it hands to mothership.Create (a Hook value is itself a valid brain.Brain, since this interface embeds it).

func Create

func Create(ctx context.Context, cancel context.CancelCauseFunc, parentKey sgo.PrivateKey, config *Configuration, db *sql.DB) (Hook, error)

Create creates a leveragedloopv1 gRPC event hook. db is the already-open prefetch.db connection (see store.DB.Raw()) -- unused by this mode's Go side today (no persistence needed for a one-shot trigger, unlike testperpv1's target allocation), kept for signature parity with every other bot mode's Create.

Source Files

  • eval.go
  • init.go
  • instance.go
  • leveragedloopv1.go
  • message.go

Jump to

Keyboard shortcuts

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