Add stellar token approve subcommand - #2714
Conversation
There was a problem hiding this comment.
Pull request overview
Adds stellar token approve for setting SEP-41 allowances and returning JSON transaction receipts.
Changes:
- Implements approval invocation, validation, signing, and structured errors.
- Registers command routing and updates help documentation.
- Adds integration coverage for approval behavior and failures.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
FULL_HELP_DOCS.md |
Documents the command and options. |
cmd/soroban-cli/src/commands/token/mod.rs |
Registers and dispatches approve. |
cmd/soroban-cli/src/commands/token/approve.rs |
Implements approvals; muxed-source coverage is missing and its guard explanation is inaccurate. |
cmd/soroban-cli/src/cli.rs |
Enables JSON error formatting. |
cmd/crates/soroban-test/tests/it/integration/token/mod.rs |
Registers approval integration tests. |
cmd/crates/soroban-test/tests/it/integration/token/approve.rs |
Tests approval behavior and key failures. |
Suppressed comments (1)
cmd/soroban-cli/src/commands/token/approve.rs:158
- This explanation contradicts #2645: positional parsing and simulation accept the muxed address; the failure occurs later when the sequence-number lookup passes the M… strkey to a G-only account parser. Please keep the guard but describe the actual failure point so future work on #2645 does not remove or relocate it for the wrong reason.
// The invoke pipeline can't source a transaction from a muxed account
// yet (see #2645), and a muxed strkey in the `from` arg is rejected
// mid-simulation with an opaque host error; reject it up front with a
// clear message instead.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| #[arg(long, value_parser = parse_nonneg_i128)] | ||
| pub amount: i128, | ||
|
|
||
| /// Ledger sequence after which the allowance expires. Must be at or beyond |
There was a problem hiding this comment.
The CLI validates --amount is non-negative (via parse_nonneg_i128, see the Error::Args/args::Error layer) to avoid an opaque HostError, but this doc comment states the same trap condition applies to --expiration-ledger — a positive amount with an expiration ledger already in the past — yet there's no equivalent validation.
|
|
||
| /// The machine-readable receipt of a token approval. | ||
| #[derive(Debug, serde::Serialize)] | ||
| struct Receipt { |
There was a problem hiding this comment.
Fwiw receipt is not a common term in the Stellar vocab. I'd call this Result rather than introduce a new concept. It's not a blocker though, as it appears to just be a term being used internal to the cli.
What
Adds
stellar token approve, a write subcommand that sets a SEP-41 allowance.--fromgrants and authorizes the allowance,--spenderis the delegate,--amountis the allowance in smallest units, and--expiration-ledgeris the ledger after which it expires. Returns a JSON receipt with the tx hash.Why
Part of #2620 (typed SEP-41 + SAC client), first of the write commands after the read-metadata group. A thin wrapper over
contract invokereusingargs::invoke_by_positionandargs::not_deployed_error, mirroringtransfer. Landingapprovebeforeallowancelets the allowance command's tests do a clean approve→read round-trip.Known limitations
Muxed (
M…) source accounts are rejected with a clear error (same constraint astransfer, see #2645).