Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

agentvault source pure

Package agentvault is the reusable spend-cap library behind the AgentVault realm: the first wallet an AI agent cannot...

Overview

Package agentvault is the reusable spend-cap library behind the AgentVault realm: the first wallet an AI agent cannot drain.

It is pure: no realm state, no chain calls, no imports from any realm. Every function takes explicit inputs (including the current unix time for day rollovers) so the logic is unit-testable without a chain. The vault realm in gno.land/r/g16740fm9kd28luuktn3g42jfq3r998fm35chclv/agentvault stores AgentBudget values and calls these functions; any other realm can import this package and get the same caps.

Constants 2

const DaySeconds

1const DaySeconds = int64(86400)
source

DaySeconds is the length of one daily budget window, in seconds. Days are wall-clock UTC days counted from the Unix epoch.

Functions 9

func ApplySpend

1func ApplySpend(b *AgentBudget, amount int64)
source

ApplySpend records a spend that already passed CheckSpend.

func CheckSpend

1func CheckSpend(b AgentBudget, amount int64) (bool, string)
source

CheckSpend reports whether amount may be spent under this budget. It does not mutate the budget; call RefreshDay first, then ApplySpend after a successful check. The order of the checks is deliberate: the cheapest, most specific rejection comes first so the logged reason tells the agent exactly which limit it hit.

func DayIndex

1func DayIndex(nowUnix int64) int64
source

DayIndex returns the unix day for a unix timestamp.

func EscrowRefundable

1func EscrowRefundable(e Escrow, height int64) bool
source

EscrowRefundable reports whether a held escrow may be refunded: the deadline block has passed and it is still held. A released or already-refunded escrow is never refundable again.

func EscrowStatusString

1func EscrowStatusString(s EscrowStatus) string
source

EscrowStatusString renders an escrow status for the log and the Render page.

func RefreshDay

1func RefreshDay(b *AgentBudget, nowUnix int64)
source

RefreshDay resets SpentToday when the day has rolled over. Call it before CheckSpend so a stale day never blocks a new day's spend. It only ever moves the day forward and clears the spent amount; it never restores spent funds.

func RemainingToday

1func RemainingToday(b AgentBudget, nowUnix int64) int64
source

RemainingToday returns how much of the daily cap is left.

func ValidateCaps

1func ValidateCaps(perTxCap, dailyCap int64) string
source

ValidateCaps reports "" when a cap pair is usable, otherwise the reason it is not. Both caps must be positive and the per-transaction cap must not exceed the daily cap (a per-tx cap above the daily cap could never be spent in full).

func NewBudget

1func NewBudget(perTxCap, dailyCap int64) AgentBudget
source

NewBudget builds a budget. Callers must validate first with ValidateCaps; an invalid pair panics rather than silently installing a budget that can never be spent.

Types 4

type AgentBudget

struct
1type AgentBudget struct {
2	PerTxCap   int64 // max ugnot in a single spend
3	DailyCap   int64 // max ugnot per day
4	SpentToday int64 // ugnot already spent in DayIndex
5	DayIndex   int64 // unix day (nowUnix / DaySeconds) SpentToday belongs to
6}
source

AgentBudget is one agent's spend limit. It is a plain value type: the owning realm stores it and passes it back in. SpentToday and DayIndex are bookkeeping the realm must not forge; RefreshDay is the only function that moves them, and only forward in time.

type Attempt

struct
 1type Attempt struct {
 2	ID      int64
 3	Kind    string // "spend", "escrow", "release", "refund", "fund"
 4	Agent   address
 5	Name    string // resolved agent name, if the attempt named one
 6	Amount  int64
 7	Purpose string
 8	Allowed bool
 9	Reason  string
10	Day     int64 // unix day of the attempt
11}
source

Attempt is one entry in a vault's append-only spend log. Allowed false means the guard stopped the spend; Reason names why, so the blocked attempt is evidence, not just a failed transaction.

type Escrow

struct
1type Escrow struct {
2	ID             int64
3	Payer          address
4	RecipientName  string
5	Recipient      address
6	Amount         int64
7	DeadlineHeight int64
8	Status         EscrowStatus
9}
source

Escrow is one name payment held by the vault until the named recipient confirms delivery (release) or the owner refunds it after the deadline block (refund). The coins never leave the vault while held; release sends them, refund only flips the status.

type EscrowStatus

ident
1type EscrowStatus int
source

EscrowStatus is the lifecycle state of a name payment held in escrow.

Dependencies

Imports 0

Imports nothing.

/p/g16740fm9kd28luuktn3g42jfq3r998fm35chclv/agentvault

Imported by indexer

Source Files 3