Skip to content

Add buffer reclaim command to the CLI - #204

Merged
kaze-cow merged 44 commits into
mainfrom
cli-reclaim-buffer
Oct 23, 2026
Merged

kaze-cow merged 44 commits into
mainfrom
cli-reclaim-buffer

Conversation

@kaze-cow

@kaze-cow kaze-cow commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds cow buffer reclaim <target> <buffer>[:<max burn>]..., which closes up to 11 buffer PDAs in one transaction, burns whatever they hold up to a per-buffer limit, and sends their rent to target. The CLI image also gets the Solana CLI and bc (#205), which the devops buffer-reclaim script uses.

Motivation

This is used by the reclaim scripts on the devops side. It's the last of the three PRs split out of the original version of this one, stacked on #207 (buffer create), which is stacked on #206 (order reclaim).

Considerations

Older deployments

Buffer and state PDAs are seeded with the <major>.<minor> release, so --settlement-version lets the CLI derive them for a deployment of an older release (e.g. 0.4). The interface gains settlement_seed_for_version for this, and the CLI wraps it in SettlementSeed, which validates the version string.

Burn limits

A buffer holding more than its burn limit is left open and listed instead of failing the batch, since the program would skip it anyway. Any other bad buffer (wrong owner, not at its mint's PDA, not a token account) aborts the whole batch before anything is sent.

Batch size

MAX_BUFFERS = 11 is the worst case: both token programs, and a reclaim authority signing separately from the payer.

Refactor for Keypair Arg

Its possible to have a key that only signs the transaction without actually holding any SOL. To allow for this. capability, a new KeypairArg parsable thing was added to clap and it allows for a file input which can then be resolved once the signer is needed.

How to test

cargo test -p cow-test-cli -p cow-settlement-interface
cargo run -p cow-test-cli -- buffer reclaim --help

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

SC-431

kaze-cow and others added 4 commits October 16, 2026 14:48
Also ships the CLI Docker image workflow and a --version flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reclaim-buffers derives PDAs with the solana cli and prices dust with
bc. Adds both
to the cow-cli image (solana v4.0.3, amd64-only since agave has no arm64
linux build) so
  buffer reclaim runs in-cluster.
@kaze-cow kaze-cow changed the title reclaimability in CLI Add buffer reclaim command to the CLI Oct 16, 2026
@kaze-cow
kaze-cow changed the base branch from main to cli-buffer-create October 16, 2026 05:51
kaze-cow and others added 17 commits October 16, 2026 17:06
Malformed order PDAs/UIDs are now rejected at argument parsing, before
any keypair load or RPC call. The PDA is derived from the UID afterwards,
since a value parser can't see `--program-id`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	test-cli/src/cmd/buffer/create.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaze-cow
kaze-cow marked this pull request as ready for review October 19, 2026 06:29
@kaze-cow
kaze-cow requested a review from a team as a code owner October 19, 2026 06:29
Comment thread test-cli/Dockerfile Outdated
kaze-cow and others added 6 commits October 19, 2026 17:25
the problem is TryFrom sort of implies that, if the `TryFrom` succeeds,
it was a valid settlement error. but if the error was emitted by an
unrelated program, this may be misleading. So use an explicit function
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kaze-cow added a commit that referenced this pull request Oct 21, 2026
# Description

Adds `cow reclaim <order>...`, which closes up to 15 order PDAs in one
transaction and refunds each one's rent to the order's `created_by`. It
also ships the CLI Docker image workflow (from #190, now triggered on
`main` and tags only) and a `cow --version` flag.

## Motivation

The devops reclaim scripts need to sweep closed orders from the CLI
image. This is the first of three PRs split out of #204: order reclaim
here, then buffer create, then buffer reclaim.

## Considerations

### All or nothing

Every input is resolved and checked (it has to be an order owned by the
program) before anything is sent. If one fails, the CLI lists the
offending inputs and sends nothing. If the transaction fails on-chain,
the failing instruction index is mapped back to its input and the
`SettlementError` is decoded.

### Batch size

`MAX_ORDERS = 15` is the worst case where every order has a distinct
creator. `max_orders_is_the_most_that_always_fit` pins that against the
1232-byte packet limit, which is why `bincode` comes in as a
dev-dependency.

### `From<InstructionError> for SettlementError` function

Interestingly, there doesn't seems to be a good way to convert from a
`InstructionError` to a `SettlementError`. So I added this to the
interface!

## How to test

```
cargo test -p cow-test-cli
cargo run -p cow-test-cli -- reclaim --help
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
kaze-cow and others added 6 commits October 21, 2026 17:25
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kaze-cow added a commit that referenced this pull request Oct 23, 2026
# Description

Adds the `cow buffer` subcommand group with its shared `send` helper,
and `cow buffer create <mint>...`, which creates the missing buffer PDAs
of up to 14 mints in one transaction. Mints whose buffer already exists
are skipped and reported.

## Motivation

Second of the three PRs split out of #204, stacked on #206. This lays
the groundwork that `buffer reclaim` (#204) builds on.

## Considerations

### One instruction per token program

`CreateBuffers` serves a single token program, so mints are grouped and
get one instruction per program. `MAX_MINTS = 14` is the worst case,
where the mints span both programs.
`max_mints_is_the_most_that_always_fit` pins it.

### Validation

As with order reclaim, every mint is checked first: it has to exist, be
owned by a supported token program and decode as a mint. If any fail,
nothing is sent.

## How to test

```
cargo test -p cow-test-cli
cargo run -p cow-test-cli -- buffer create --help
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Base automatically changed from cli-buffer-create to main October 23, 2026 01:40
Comment thread test-cli/src/cmd/buffer/reclaim.rs Outdated
Comment thread test-cli/src/cmd/buffer/reclaim.rs Outdated
Comment thread test-cli/src/cmd/buffer/reclaim.rs Outdated
so much better
also swtich terminology/naming of target -> receiver
and <max burn> -> <max burn in atoms>
@kaze-cow
kaze-cow requested a review from fedgiac October 23, 2026 08:19

@fedgiac fedgiac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last remaining comments.

Comment thread test-cli/src/cmd/buffer/reclaim.rs
Comment thread test-cli/src/cmd/buffer/reclaim.rs Outdated
Comment thread test-cli/src/utils/parsing.rs Outdated
Comment thread test-cli/src/cmd/buffer/reclaim.rs
kaze-cow and others added 3 commits October 23, 2026 20:15
clap rejected non-UTF-8 keypair paths before they reached KeypairArg,
since it was parsed through FromStr.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaze-cow
kaze-cow requested a review from fedgiac October 23, 2026 11:21

@fedgiac fedgiac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@kaze-cow
kaze-cow merged commit be19a37 into main Oct 23, 2026
20 checks passed
@kaze-cow
kaze-cow deleted the cli-reclaim-buffer branch October 23, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants