# Long pool trading

BLOCK CLI prepares Long token purchases and sales on Robinhood Chain, chain ID **4663**, through the pool's original Robinhood stock quote token. The supported route is an existing, locked Long Doppler pool using the verified custom hook and Uniswap v4. Native ETH routes, multi-pool aggregation, migrated pools and arbitrary ERC-20 quote assets are outside this integration.

The API returns unsigned EIP-1559 bytes. Keys stay in the agent's encrypted local wallet. Preparation and inspection never send a transaction.

## Actions

All actions require `token` and `launchTransactionHash`. Obtain the successful creation transaction from Long discovery. The adapter verifies its receipt, canonical block inclusion, launcher event and token identity rather than accepting any pool with a matching ticker.

| Action | Additional inputs |
| --- | --- |
| `quote` | `side` (`buy` or `sell`), raw `amount`, optional `slippageBps` (0–1000, default 100). |
| `build_swap` | Quote inputs plus `wallet`, explicit `minOutputAmount`, `deadline` and `maxFeeWei`. |
| `build_buy` | Same build inputs, with the side fixed to buy. |
| `build_sell` | Same build inputs, with the side fixed to sell. |
| `prepare_approval` | `wallet`, `side`, exact raw `amount`, `stage`, `maxFeeWei`; `expiration` only for the `permit2` stage. |

Buy input is the original stock quote token; sell input is the Long token. Amounts are positive decimal strings, limited to `2^127−1`. Both assets must use the reviewed 18-decimal deployments.

**Use raw ERC-20 units, not displayed shares.** Robinhood stock tokens have a changing UI multiplier. The response includes `quoteAsset.uiMultiplier` and its source token; the adapter never silently applies it to balances, quotes, allowances or swap amounts.

## Quote and build

The adapter checks the current deployment code hashes, token clone, issuer beacon implementation, active issuer asset registry, Airlock provenance and pool state. The official deployed v4 quoter computes the output at a canonical block, including the custom hook's fees.

```sh
block-cli call long quote --params \
  '{"token":"<LONG_TOKEN>","launchTransactionHash":"<CREATION_TX_HASH>","side":"buy","amount":"1000000000000000","slippageBps":100}'

block-cli call long build_buy --params \
  '{"wallet":"<EVM_ADDRESS>","token":"<LONG_TOKEN>","launchTransactionHash":"<CREATION_TX_HASH>","amount":"1000000000000000","slippageBps":100,"minOutputAmount":"<REVIEWED_RAW_MINIMUM>","deadline":"<CHAIN_TIMESTAMP_PLUS_120>","maxFeeWei":"1000000000000000"}' \
  > long-buy.json
```

The builder refreshes the quote. The explicit minimum must be between the fresh slippage floor and quoted output. A stale quote or preparation taking over 30 seconds is rejected. The deadline must be 30–300 seconds after the current chain timestamp. These are example budgets; choose amounts and limits using the agent's own spending policy.

The current Universal Router **2.1.2** transaction contains one `V4_SWAP` command with exactly three actions: exact-input single-pool swap, settle the input up to the approved maximum, and take output at or above the approved minimum. The wallet is the output recipient. The router enforces the deadline on chain.

A price boundary may cause less than the maximum input to be consumed. The encoded absolute output minimum still applies. The adapter does not add an independent on-chain ceiling for each hook fee; output protection comes from the minimum received.

## Separate approvals

An ERC-20-to-Permit2 allowance and a Permit2-to-router allowance must both already cover the input. The latter must remain valid through the swap deadline. Missing balances or allowances stop swap preparation.

`prepare_approval` produces one separately reviewed transaction per stage:

| Stage | Encoded effect |
| --- | --- |
| `token_reset` | Set input-token allowance to Permit2 to zero. |
| `token` | Set input-token allowance to Permit2 to the exact amount. |
| `permit2` | Authorize the pinned router for that exact input token and amount until explicit `expiration`. |
| `revoke_permit2` | Set that Permit2 router allowance to zero. |

An existing nonzero ERC-20 allowance that differs from the desired amount requires a confirmed reset first. Permit2 expiration must be 30–3600 seconds after the current chain timestamp. No unlimited approval or externally supplied spender is accepted.

```sh
block-cli call long prepare_approval --params \
  '{"wallet":"<EVM_ADDRESS>","token":"<LONG_TOKEN>","launchTransactionHash":"<CREATION_TX_HASH>","side":"buy","amount":"1000000000000000","stage":"token","maxFeeWei":"1000000000000000"}' \
  > long-token-approval.json

# After reviewing, signing, submitting and confirming that approval:
block-cli call long prepare_approval --params \
  '{"wallet":"<EVM_ADDRESS>","token":"<LONG_TOKEN>","launchTransactionHash":"<CREATION_TX_HASH>","side":"buy","amount":"1000000000000000","stage":"permit2","expiration":"<CHAIN_TIMESTAMP_PLUS_1800>","maxFeeWei":"1000000000000000"}' \
  > long-router-approval.json
```

Confirm each transaction, then prepare the next one using the current nonce and state. Do not sign several preparations with the same nonce. ERC-20 approval has no expiry; use `token_reset` when it is no longer needed. Existing wider allowances are reported, not automatically changed.

## Local execution

```sh
block-cli tx inspect --chain robinhood --file long-buy.json --out long-review.json

block-cli wallet sign --file agent-wallet.json --review long-review.json \
  --approve <REVIEW_APPROVAL_DIGEST> --max-fee 1000000000000000 \
  --out long-signed.json

block-cli tx submit --file long-signed.json
```

The generic EVM signer verifies exact chain, wallet, serialized bytes and recovered signature. It reruns nonce, balance, fee, gas and exact-transaction simulation checks. It reports `protocolSemanticsVerified:false`: full calldata and the Long limits still need independent review before approving the digest. The signer does not interpret the router deadline; that deadline is enforced by the encoded router call. Approval transactions do not have a router execution deadline.

Preparations use a 20% gas buffer, zero priority tip and a per-gas ceiling twice the observed gas price. `gasLimit × maxFeePerGas` must fit `maxFeeWei`. Pending state reads are not atomic; balances, allowances, hook fees, issuer pause/blocklist rules and implementation code can change before inclusion. Simulation does not guarantee execution or L1 settlement finality.

## Verification and sources

`test/long-trading.test.ts` covers live-derived provenance and bytecode fixtures, canonical reads, amounts, slippage, router action encoding, deadline and approval bounds, missing balances, changed code/issuer/pool identity, failed simulation and fee ceilings. Actual buy, sell and all four approval builders pass generic local inspection, disposable-fixture signing, signature recovery and exact-byte mock submission.

`long-trading-live-v0.12.0.json` records exact public inputs and results. Both quote directions and unsigned approval preparation were exercised against the public Robinhood RPC. Its public fixture wallet does not own the input tokens, so live swap builds correctly reject insufficient balance. A funded live swap has not been signed or submitted, and a successful live swap build is not claimed.

Primary references:

- [Official Doppler quote and swap documentation](https://github.com/whetstoneresearch/doppler-sdk/blob/main/docs/quotes-and-swaps.md)
- [Official Uniswap deployments on chain 4663](https://github.com/Uniswap/contracts/blob/main/deployments/4663.md)
- [Universal Router 2.1.2 source](https://github.com/Uniswap/universal-router/tree/2.1.2)
- [The router's pinned v4 interface](https://github.com/Uniswap/v4-periphery/blob/545a5d2a87228167edde48f3b9eda122d1e3c4d6/src/interfaces/IV4Router.sol)
- [Robinhood's public stock-token registry](https://api.robinhood.com/rhj/assets)
- [Verified stock implementation](https://robinhoodchain.blockscout.com/address/0xb35490d6f9163DE4F80d88dc75c3516eb64C5aE2?tab=contract_source_code)

Current Long launcher pausing does not imply its previously created pool is paused. Pool quotes and trading are checked independently. The adapter still rejects unreviewed deployments, unsupported quote assets and pools outside the supported locked phase.
