Skip to content

Add order reclaim command to the CLI - #206

Open
kaze-cow wants to merge 8 commits into
mainfrom
cli-order-reclaim
Open

kaze-cow wants to merge 8 commits into
mainfrom
cli-order-reclaim

Conversation

@kaze-cow

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

Copy link
Copy Markdown
Contributor

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

Also ships the CLI Docker image workflow and a --version flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread test-cli/src/main.rs

#[derive(Parser)]
#[command(name = "cow", about = "CoW Protocol Solana dev/testing CLI")]
#[command(name = "cow", version, about = "CoW Protocol Solana dev/testing CLI")]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is a minor thing I ended up throwing in: there was no way to query the version of the cow cli. Now its possible with cow -V, just by adding this version, arg to the command. It prints from the cargo metadata the binary name and version like:

cow 0.5.2

very simple.

kaze-cow and others added 3 commits October 19, 2026 14:57
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>
kaze-cow added a commit that referenced this pull request Oct 19, 2026
# Description

Brings the `cow` CLI Docker image and its `CLI image` workflow into
`main`. This is all @glokos's work: it builds
`ghcr.io/cowprotocol/cow-cli` for amd64 and arm64, then merges both into
one manifest tagged with the sha and branch/tag. The image includes the
Solana CLI and `bc` that the buffer-reclaim script needs.

The first three commits are Assem's original commits from #190 and #205,
cherry-picked unchanged. The last one drops the temporary
`cli-reclaim-buffer` push trigger, which #190 said to remove once the
image landed in `main`.

## Motivation

#190 and #205 were merged into the reclaim stack's branches instead of
`main`, so the image work now shows up inside #206/#207/#204 and makes
them harder to review. Landing it here on its own means those PRs only
show CLI changes once they're rebased.

## Considerations

### Credit

Please **rebase-merge** this PR rather than squash it, so that Assem's
commits land on `main` with him as the author. The trigger commit lists
him as co-author too.

### Parity with the stack

`.github/workflows/cli-image.yml` and `test-cli/Dockerfile` on this
branch are byte-for-byte identical to the versions on
`cli-reclaim-buffer` (#204), so rebasing the stack onto `main`
afterwards should drop these files from its diff.

## How to test

This PR should be the same as those already included in the buffer
reclaim changes we eventually expect to merge:

```
git diff origin/cli-reclaim-buffer -- .github/workflows/cli-image.yml test-cli/Dockerfile   # empty
```

**Once merged**, any branch that contains the workflow file can be built
by hand, via Actions → CLI image → Run workflow (pick the branch under
"Use workflow from") or:

```
gh workflow run cli-image.yml --ref <branch>
```

Unfortunately it doesn't seem to be possible to workflow dispatch until
this is actually merged, but an example of this dockerfile generating a
successful build though CI is [already on its actions
page](https://github.com/cowprotocol/solana-programs/actions/workflows/cli-image.yml).

The image is tagged `cow-cli:<branch>` (slashes become `-`) and
`cow-cli:sha-<short>`.

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

---------

Co-authored-by: Assem Hasna <assem@cow.fi>
Co-authored-by: Assem Hasna <210342530+glokos@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
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
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.

1 participant