api

package
v0.4.19 Latest Latest
Warning

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

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

Documentation

Overview

Command harness is a minimal tool-calling agent, built the same way as go-wiki/examples/eino-ollama-agent/main.go (github.com/cloudwego/eino's prebuilt ReAct agent: call the model -> if it asked for a tool, run the tool and feed the result back -> repeat until the model answers without a tool call), but with walletTools() (see tools.go) in place of that example's demoTools().

walletTools() gives the agent read-only visibility into this repo's real trading wallet: its Solend/Kamino lending obligations, its raw token balances, live Jupiter USD prices, and total portfolio value -- the exact queries run by hand, script by script, over the course of a live session unwinding real positions in this wallet. It does not expose any of that session's mutating actions (repay/withdraw/sweep); see walletTools' own doc comment for why.

Usage:

go run . -prompt "What obligations are currently open, and what's the wallet worth right now?"

Index

Constants

View Source
const SolDelta graph.Lamports = sgo.LAMPORTS_PER_SOL >> 3

Variables

This section is empty.

Functions

func NewStateClient

func NewStateClient(ctx context.Context, stateURL string) (state.Client, error)

NewStateClient dials the same internal state.Client/gRPC graph endpoint every other read in this codebase uses (see cmd/multimodel.go's identical stateAddr/DefaultDialer construction), given a raw -state-url flag value. Exported so other standalone entrypoints building on this package (e.g. optimizer/hedgefund's CLI) can dial the same way without duplicating this parsing.

func WalletTools

func WalletTools(stateClient state.Client, owner sgo.PublicKey) ([]tool.BaseTool, error)

WalletTools builds the read-only wallet-inspection toolkit this harness exposes to the agent, distilled directly from the ad hoc Go scripts run by hand during this session's live unwind of a real Solana trading wallet (checkob/main.go, the balance checks around the sweep-to-USDC step, and the portfolio-value computation) -- see demoTools() in go-wiki/examples/eino-ollama-agent/main.go for the shape this mirrors (utils.InferTool + a plain Go function per tool).

Every tool here is READ-ONLY: it queries live on-chain/off-chain state and never signs or sends anything. The real manual-repair actions from that session (hand-built Kamino/Solend repay/withdraw instructions, sweeping dust tokens to USDC via Jupiter) are deliberately NOT exposed as callable tools here -- those move real money, and in the session they were only ever run after an explicit, per-action human go-ahead in conversation ("go ahead and build it", "go ahead and send it"). Wiring them into a freely-callable agent tool would remove that human gate entirely; this harness intentionally stops at "let the model see what a human would see," not "let the model act."

Types

type Base

type Base interface {
	Ctx() context.Context
	CloseSignal() <-chan error
	Close() error
}

type BookKeeping

type BookKeeping interface {
	// take a snapshot of all token positions and market into an accounting book
	Snapshot(Treasury) error
	// Profit and Loss for a wallet
	ProfitChild(start time.Time, finish time.Time, valuationMint sgo.PublicKey, childID sgo.PublicKey) (child float64, err error)
	// Profit and Loss for the parent and aggregate the net income from child wallets
	ProfitParent(start time.Time, finish time.Time, valuationMint sgo.PublicKey) (parentOnly float64, overall float64, err error)
}

type Bot

type Bot interface {
	Hash() sgo.Hash
	Stderr() io.ReadCloser
	Send() chan<- catmsg.FixedPair
	Recv() <-chan catmsg.FixedPair
}

type BotCompiler

type BotCompiler interface {
	// Compile the wasm binary.
	Compile(ctx context.Context, sourceDir string) (io.ReadCloser, error)
}

type BotRuntime

type BotRuntime interface {
	Status() StatusType
	// set the budget in raw units of the Solpipe market mint over some slot count
	Budget(amount uint64, slot graph.Slot)
	BotList() []Bot
}

type BotRuntimeManager

type BotRuntimeManager interface {
	// Connect to a remote Bot runtime
	Connect(ctx context.Context, pipelineID sgo.PublicKey) (BotRuntime, error)
}

BotRuntimeManager manages endpoints to Catscope WASM runtimes via Bot Solpipe market place.

type Budget

type Budget interface {
	ID() sgo.PublicKey
	Pubkey() sgo.PublicKey
	// if the target falls below SolDelta, top up the account
	SetSOL(budget graph.Lamports)
	// send money to a wallet
	Fund(mint sgo.PublicKey, amount uint64)
	// sweep token funds, leave minAmount in account
	Sweep(mint sgo.PublicKey, minAmount uint64)
	// Close all token accounts, close all protocol positions; sweep funds back to parent; Use Jupiter to power sweeps.
	Close() error
	// SetPositionCloser registers the callback Close() invokes first, to
	// unwind whatever protocol-specific positions (lending deposits,
	// perps, LP, etc.) this child wallet holds, before its resulting
	// SOL/SPL token balances get swept back to the parent. The treasury
	// package has no protocol-specific knowledge of its own -- these
	// positions live entirely in each running bot instance's own
	// on-chain state -- so whoever owns that context (typically the
	// brain module driving this child's bot instance) must supply it.
	// Close only sweeps SOL/token balances, skipping this step entirely,
	// if nothing has been registered.
	SetPositionCloser(closer func(ctx context.Context) error)
}

type ChainState

type ChainState interface {
	Base
	// Database accesses the underlying database
	Database() *store.DB
	// Access an account
	Account(sgo.PublicKey) graph.Account
}

ChainState maintains pool, dex data relevant for compiling static information into trading bots.

type FileStore

type FileStore interface {
	Read(ctx context.Context, path string) (io.ReadCloser, error)
	Write(ctx context.Context, path string) (io.WriteCloser, error)
}

type StatusType

type StatusType = uint8
const (
	StatusTypeOffline   StatusType = 0
	StatusTypeNonbidder StatusType = 1
	StatusTypeBidder    StatusType = 1
)

type TokenBalance

type TokenBalance = map[sgo.PublicKey]uint64

type Treasury

type Treasury interface {
	// Parent public key that distributes funds
	Parent() Wallet
	Children() []sgo.PublicKey
	// Child derives a child key; this is for observing the current balances
	Child(childID sgo.PublicKey) Wallet
	// SOLBalance returns the current SOL balance in lamports
	SOLBalance() uint64
	// TokenBalance returns the current balance of tokens
	TokenBalance() map[sgo.PublicKey]uint64
	// manage funds via budget
	Budget(childID sgo.PublicKey) Budget
}

type Valuation

type Valuation struct {
	Valuation float64
	Token     TokenBalance
}

type Wallet

type Wallet interface {
	ID() sgo.PublicKey
	PublicKey() sgo.PublicKey
	// SOLBalance returns the current SOL balance in lamports
	SOLBalance() uint64
	// TokenBalance returns the current balance of tokens
	TokenBalance() TokenBalance
}

Source Files

  • bot.go
  • chainstate.go
  • file.go
  • harness.go
  • tools.go
  • treasury.go

Jump to

Keyboard shortcuts

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