# Local recurring swap plans

BLOCK CLI can keep a durable Jupiter swap plan in the agent's runtime. Each due installment requests one exact-input Metis swap, saves its exact unsigned transaction and waits for independent local review and signing. It never starts a background scheduler, holds funds, signs automatically or broadcasts.

This is an agent-controlled local plan, not a Jupiter Trigger or Recurring protocol order. Jupiter Trigger V1 is deferred. The plan uses the existing Jupiter `build_swap` API and the existing local execution commands.

## Budget and schedule

Create a private JSON plan with these fields:

| Field | Meaning |
| --- | --- |
| `wallet`, `inputMint`, `outputMint` | Exact Solana wallet and differing mint addresses. |
| `amountPerRun` | Positive raw input-token units requested for each installment. |
| `totalInputBudget` | Positive raw input units; must be an exact multiple of `amountPerRun`, funding 1–500 installments. |
| `minimumOutputPerRun` | Positive raw output-token units; every provider quote minimum must meet this floor. |
| `intervalSeconds` | 60 through 31,536,000 seconds between reconciled completion and the next installment. |
| `startAt` | UTC ISO timestamp when the first installment becomes eligible. |
| `slippageBps` | 1–500; default 50. |
| `maxPlatformFeeBps` | 0–100; default 10. |
| `maxNetworkFeeLamports` | Positive preparation-time ceiling for provider-reported signature, priority/tip and rent costs. |
| `priorityFeeLamports` | 1,000–1,000,000; default 10,000. |

All raw token amounts are canonical u64 decimal strings. Input budgets exclude network fees, rent and protocol charges; a wallet must separately cover those costs. Plan files use mode 0600 and a bounded JSON format. Their parent directory must be owned by the current user and not writable by group or others. Keep only one authoritative copy of a plan: copying or manually editing it can defeat local scheduling and allocation accounting.

The local budget limits **requested allocations**. Existing Jupiter swap preparation checks provider quote identity, fee ceilings, unsigned structure and wallet identity. It does not independently decode every routed instruction or verify every CPI effect. The plan repeats the relevant identity and fee checks, but it does not turn provider labels into proof that actual token debits are bounded. Each installment still requires an independent transaction policy review before signing. The response reports `instructionSemanticsVerified: false`.

## Commands and state transitions

```sh
block-cli recurring create --plan ./swap-plan.json --file ./swap-plan-input.json
block-cli recurring status --plan ./swap-plan.json
block-cli recurring prepare --plan ./swap-plan.json --out ./installment-0.json

block-cli tx inspect --chain solana --file ./installment-0.json --out ./installment-0-review.json
# Independently review all resolved accounts and instructions. Set APPROVED_DIGEST
# to the digest actually approved by your policy; do not approve provider labels.
block-cli wallet sign --file ./agent-wallet.json --review ./installment-0-review.json \
  --approve "$APPROVED_DIGEST" --max-fee 50000 --out ./installment-0-signed.json
block-cli recurring bind --plan ./swap-plan.json --file ./installment-0-signed.json \
  --approve "$APPROVED_DIGEST"
block-cli tx submit --file ./installment-0-signed.json
block-cli recurring reconcile --plan ./swap-plan.json
```

`prepare` makes one gateway call for `jupiter.build_swap` when the plan is due and has no pending installment. It persists the reservation before returning any prepared bytes. Repeating `prepare` while pending returns the same bytes and does not request a new quote. If saving `--out` fails after reservation, repeat with a new output filename; the same reserved transaction is recovered.

`bind` verifies the local signature, signer, transaction ID, exact serialized message and independently approved digest against that reservation. It does not submit. The plan retains the signed artifact privately for exact receipt reconciliation; status output omits usable signature bytes.

`reconcile` reads only from the locally configured Solana mainnet RPC. It requires a finalized `getTransaction` result containing the exact signed bytes and a matching finalized signature status, slot and execution error. Missing history, timeouts, mismatched receipts and nonfinal status never advance the plan. An expired blockhash or absent transaction is not evidence that it is safe to replace a pending transaction.

A finalized success or finalized failure consumes the entire installment allocation. Failed installments are never automatically retried, even if their swap state changes were reverted; fees can still be charged. The next due time is the current reconciliation time plus `intervalSeconds`. A delayed agent therefore creates no catch-up burst. Finalized receipts establish execution of the exact signed transaction, not an independently recomputed swap output.

`recurring cancel --plan ./swap-plan.json` stops future installments. It cannot revoke prepared or signed Solana bytes. Pending state and its allocation remain until exact receipt reconciliation. For an unsigned pending preparation that became stale or was abandoned, `recurring skip --plan ./swap-plan.json --approve "$PENDING_DIGEST"` consumes the full allocation as `skipped_unverified`. It records no fabricated transaction ID, receipt or execution result, and delays the next installment by the full interval. Any signature created outside the plan is not revoked. A bound signed artifact cannot be skipped: it requires finalized receipt reconciliation. Skipping a cancelled plan never reactivates it. There is no automatic pending reset or ambiguous-submission retry.

Each mutation uses an exclusive adjacent lock, atomic replacement and filesystem synchronization. Concurrent mutations fail with `RECURRING_PLAN_LOCKED`. A process crash may leave its lock file; inspect the owning process and existing plan before removing a stale lock manually. Never remove a lock while another process may still be operating on that plan.

## Verification

Automated tests cover strict input and budget bounds, exclusive concurrent allocation, crash-compatible pending reuse, canonical private files, immutable exact-message/signature binding, rejected mismatched or nonfinal receipts, finalized failure accounting, cancellation and no catch-up behavior. An integration test drives the actual CLI through the strict API invocation envelope and Jupiter adapter with an in-memory provider fixture. Fixture-only local signatures use public deterministic keys; no live funds were signed or submitted.
