Repository navigation
feat(trade): add --dry-run and TTY confirmation (--yes) to trade and bridge execute - #667
Conversation
…cute `trade execute` and `bridge execute` broadcast irreversible on-chain transactions with no way to preview them and no acknowledgement step. --dry-run runs the usual validation, prints the trade or transfer that would be sent, and stops before signing. It is placed before any wallet material is loaded, so a dry run needs no password, cannot sign anything, and leaves the quote reusable. On EVM it also reads the current allowance and runs the pre-broadcast revert simulation when no approval is pending. When stdin is an interactive terminal, both commands now print that plan and ask for confirmation before broadcasting; declining exits 1 with nothing signed. --yes / -y, or NANSEN_YES=1, skips the question. Behaviour is deliberately unchanged when stdin is not a terminal (agents, CI, pipes): the command proceeds without prompting, and --yes is accepted there as a no-op, so existing automation keeps working untouched. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pr-reviewer Summary for #0da13b6✅ No issues found The code review completed successfully with no findings. Review effort: 4/5 (Complex) SummaryThis is a well-executed PR. The
No actionable findings. Token usage: 8,463 input, 7,572 output, 1,411,977 cache read, 71,983 cache write | Usage Guide New pushes are reviewed automatically with a 10-minute cooldown between reviews. To request a review at any time, comment |
|
Merge position: 7 of 9. Merge after #664 and #666. Shares |
|
@nansen-pr-reviewer re-review |
|
@nansen-pr-reviewer re-review |
Summary
nansen trade executeandnansen bridge executemove funds irreversibly, but until now there was no way to preview what they would send and no acknowledgement step before broadcasting. This PR adds both, to each command.--dry-runruns the same sign-free validation a real execute runs, prints the trade or transfer that would be sent, and stops before anything is signed:The gate sits before any signing material is loaded, so a dry run needs no wallet password, cannot sign anything, and leaves the quote reusable. Bridge dry-runs validate and use the public signer address persisted in the cached quote, so they can also render and preflight the plan when no local EVM wallet is configured. On EVM, the preview reads the current token allowance when applicable and runs the sign-free transaction checks. On a multi-step bridge transfer it validates every step and stops before the first broadcast.
Confirmation. When stdin is an interactive terminal, both commands now print that plan and ask
Broadcast this transaction? [y/N]before broadcasting. Anything buty/yesaborts with nothing signed.--yes(-y), orNANSEN_YES=1, skips the question.--yes/NANSEN_YES=1Broadcast this transaction? [y/N]; declining aborts--yesis a no-op)Non-interactive behaviour is deliberately identical to today's, so existing automation keeps working untouched and
--yesis always safe to pass. The plan and prompt are only emitted in dry-run mode or immediately before an interactive prompt. For an interactive confirmation both are emitted to stderr, so redirecting stdout does not hide the plan from the person answering on stdin; dry-run output remains on stdout for automation.Exit codes (
trade execute,bridge execute):01Changes
src/execute-guard.js(new): flag/env resolution, plan rendering, the TTY-gated prompt, and the singleguardExecution()entry point both commands call.src/trading.js:buildTradeExecutionPlan()plus the gate intrade execute, placed after quote selection and before wallet credentials, signing, and the first approval transaction.src/bridge.js: bridge plan builder plus the gate inbridge execute, before signing credentials and the first step. Dry-run validates the persisted quote signer before falling back to local wallet resolution. The fee/nonce override line is rendered once and reused by the plan and the EVM leg.src/cli.js:--yesadded to the valueless-flag list (--dry-runwas already there);tradeandbridgehelp updated; command interactivity explicitly follows stdin while output formatting continues to follow stdout.src/schema.json:dry-runandyesdocumented on bothexecutecommands, with examples.README.mdandskills/nansen-trading/SKILL.mdgain the flags, the TTY/non-TTY table and the exit codes;NANSEN_YESadded to the skill's environment table.src/__tests__/execute-guard.test.jsandsrc/__tests__/bridge-execute-guard.test.jscontain 44 focused tests. Every signing/broadcast seam throws when it must not run (and dry-run fixtures include missing wallet configuration and passwords), so a dry run or declined confirmation that reached signing would fail the suite rather than pass quietly. All network and RPC calls are mocked.minor.Validation
Latest focused validation after merging current
main:Checklist
src/schema.jsonupdated if new commands or flags were addedREADME.mdupdated if new top-level commands or categories were added.changeset/) — only required for user-facing changes (new commands, flags, bug fixes, breaking changes)🤖 Generated with Claude Code