Draft, edit, and sign a Plan from the depositor’s app. Every edit runs on your automation service and returns a new Plan. Amounts are bigint in the asset’s smallest unit: 30 USDC is 300_000_000n.

Set up the client

Create three objects once, and import them wherever the app edits or signs a Plan.

Connect to your automation service

Connect the depositor’s wallet

A DepositSigner signs the text depositSigningMessage builds from a Deposit. Return the depositor key’s Ed25519 signature over that text, base64-encoded.
In Node scripts and tests, sign with a secret key instead:
createSecretDepositSigner holds the depositor’s secret key. Never use it in a browser.

Read the pool

A PoolView reads the pool to show progress and find the Deposit that is waiting for a signature.

Compose a draft

Pass each recipient’s Stellar account and amount. The service builds the Initial Deposit, one Payout per recipient, and any intermediate Transfers.
coverFees raises any Step whose fee quote is above its Free tokens, and adds the increase to the Deposit that funds it. Call it after every edit, before the depositor signs.

Check funding

The service refuses to confirm an underfunded Plan. Check it in the app first:
shortfalls lists the Steps their Deposits cannot pay for. funded is true when the Deposits equal the Payouts plus all Free tokens.

Change an interval

An interval belongs to the later of two adjacent Steps. List the Plan’s Steps in order, then replace the interval of the Step after stepIndex:
The interval starts when the earlier Step executes, in the unit of the service clock. The Initial Deposit always has interval 0, and replaceStepInterval throws InitialDepositIntervalError for it.

Add a Deposit

Insert a Deposit between two Rows, then move amount onto it from the Initial Deposit. The new Deposit already holds the Free-token floor.
rowIndex must be greater than 0 and less than the number of Rows. To move tokens between two existing Deposits, pass the earlier one as fromRowIndex.

Add a recipient

Compose again with the new recipient last, then put the draft’s edits back.

Compose with the new recipient

Restore the intermediate Deposits

Insert each intermediate Deposit at its old Row and move its old amount back onto it.

Restore Free tokens and intervals

Copy each Step’s Free tokens and interval onto the Step at the same place, using stepsOf from Change an interval.
Composing again can move a Payout onto a different Transfer. A Step that only exists in the new draft keeps the service defaults.

Sign and confirm the Plan

Sign the Initial Deposit and confirm the Plan. confirm returns the Plan id.
When the service submits to a pool, the invocation also carries authEntries.

Sign the next Deposit

Ask the service which Deposit is waiting, find its Row, and sign it.
invocation is undefined when no Deposit is waiting. progress also tells you which Steps are executed or blocked, so you can show it in the app.