api

package
v0.5.25 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 27 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 DefaultWallet = "Hg2p3cfmg3dratEVy94JArTVM7KzEywgNdmFnrfhroh9"

DefaultWallet is the trading child wallet every WalletTools() query targets by default -- the same real wallet (common.DeriveChildKeyFromIndex(parentKey, 1)) this session's manual scripts (checkob, manualrepay, manualwithdraw, sweeptousdc) all operated on. Override with -wallet to point this harness at a different address without needing the fee-payer keypair at all -- every tool here is read-only, so only the public key is ever needed. Exported so other packages building on this one (e.g. hedgefund's agents) share the same default without duplicating the literal.

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 struct {
	Hash  sgo.Hash
	SendC chan<- catmsg.FixedPair
	RecvC <-chan catmsg.FixedPair
}

type BotCoder added in v0.5.25

type BotCoder interface {
	// Compile the wasm binary. The startingFiles get copied into the base directory of the coding directory in the container compiling the code.
	Compiler(ctx context.Context, startingFiles fs.FS) (BotCompiler, error)
}

type BotCompiler

type BotCompiler interface {
	// FileSystem returns a live view onto the coding container's own
	// filesystem -- every Read/Write/Edit/LsInfo/GrepRaw/GlobInfo call
	// reads or mutates that container directly, not any host-side copy,
	// so an LLM editing through it is editing the same files Compile
	// builds from.
	FileSystem(ctx context.Context) (FilesystemWrapper, error)

	// Compile the code
	Compile(ctx context.Context, binaryPath []string) LogResult

	// Lint the code
	Lint(ctx context.Context) LogResult

	// Format the code in place. paths, when non-empty, are crate-relative
	// file paths passed directly to `rustfmt` (not `cargo fmt -- ...`,
	// which does not actually scope to the given paths - see the real
	// implementation's own doc comment) so only those files are
	// reformatted; an empty paths formats the whole crate (plain
	// `cargo fmt`).
	Format(ctx context.Context, paths []string) error

	// Test the code
	Test(ctx context.Context) LogResult

	// WARNING: generic exec
	Exec(ctx context.Context, command string, args []string, mEnv map[string]string) (stdin io.WriteCloser, stdout io.ReadCloser, stderr io.ReadCloser)
}

type BotRuntime

type BotRuntime interface {
	Status() RuntimeStatusType
	// Deploy uploads the wasm image at pathToWasm and waits for it to
	// complete its handshake (or ctx to end). args becomes the
	// deployed process's own argv on the validator runtime; env is
	// forwarded to it as environment variables -- env["MODE"] in
	// particular selects which behavior the image runs (e.g. "marketwatchv1"),
	// so it must be set for the deployed bot to do anything meaningful.
	Deploy(ctx context.Context, pathToWasm string, args []string, env map[string]string) (Bot, error)
	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 CompileBinary added in v0.5.25

type CompileBinary struct {
	Path string
	Data []byte
}

CompileBinary carries one exported file's bytes, named by the crate-relative path requested via Compile's binaryPath argument -- mirrors machinev1.CompileResponse_Binary's own Path/Data fields one-for-one.

type FileStore

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

type FilesystemWrapper added in v0.5.25

type FilesystemWrapper interface {
	// List file info in a directory
	LsInfo(ctx context.Context, req *filesystem.LsInfoRequest) ([]filesystem.FileInfo, error)

	// Read file content, supports line offset and limit
	Read(ctx context.Context, req *filesystem.ReadRequest) (*filesystem.FileContent, error)

	// batch write file content
	BatchRead(ctx context.Context, listPath []*ReadHeader) []*io.PipeReader

	// Search for matching content in files
	GrepRaw(ctx context.Context, req *filesystem.GrepRequest) ([]filesystem.GrepMatch, error)

	// Match files by glob pattern
	GlobInfo(ctx context.Context, req *filesystem.GlobInfoRequest) ([]filesystem.FileInfo, error)

	// Write file content
	Write(ctx context.Context, req *filesystem.WriteRequest) error

	// batch write file content
	BatchWrite(ctx context.Context, listWrite []*WriteHeader) error

	// Edit file content (string replacement)
	Edit(ctx context.Context, req *filesystem.EditRequest) error
}

type LogResult added in v0.5.25

type LogResult struct {
	LogC   <-chan string
	ErrorC <-chan error
	// BinaryC receives one CompileBinary per file named in Compile's own
	// binaryPath argument, as the server streams it back inline with the
	// log output -- nil for Lint/Format/Test, which never produce binary
	// output. Closed once the underlying stream ends, at the same moment
	// ErrorC receives its final value.
	BinaryC <-chan CompileBinary
}

type ReadHeader added in v0.5.25

type ReadHeader struct {
	Path   string
	Offset int
	Limit  int
}

type RuntimeStatusType added in v0.5.25

type RuntimeStatusType = uint8
const (
	RuntimeStatusTypeOffline   RuntimeStatusType = 0
	RuntimeStatusTypeNonbidder RuntimeStatusType = 1
	RuntimeStatusTypeBidder    RuntimeStatusType = 2
)

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
}

type WriteHeader added in v0.5.25

type WriteHeader struct {
	Path   string
	Size   int
	Reader io.ReadCloser
}

Source Files

  • chainstate.go
  • compiler.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