> ## Documentation Index
> Fetch the complete documentation index at: https://sdk.avantisfi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a signable TWAP cancel intent

> Cancels a pending TWAP by its on-chain twapId, stopping further slices and refunding unused escrowed collateral. POST the signed intent to the twap-app (/twaps/cancel), which submits the transaction itself. Returns an EIP-712 payload to sign (trader or a registered delegate may sign) and hand to the Avantis operator for gasless execution.



## OpenAPI

````yaml https://tx-builder-testnet.avantisfi.com/openapi.json post /v2/intents/twap-cancel
openapi: 3.0.3
info:
  title: Avantis v2 API
  version: 2.0.0
  description: >-
    Calldata builders, EIP-712 intent builders, signed-tx relay, and on-chain
    reads for the Avantis v2 perp protocol.


    **Conventions**

    - Every build/read endpoint accepts both GET (query string) and POST (JSON
    body) with the same fields; POST /v2/relay is POST-only.

    - All amounts are human units: `collateralUsdc: 100` = 100 USDC, `leverage:
    10` = 10x, prices are plain USD decimals. The API does all on-chain scaling.

    - Responses use the `{ ok: true, data }` / `{ ok: false, error: { code,
    message, details } }` envelope.

    - Calldata responses (`to`, `from`, `data`, `value`) are unsigned — the
    caller signs and broadcasts (or submits via POST /v2/relay). `from` is who
    must sign; `value` is hex wei.

    - Intent responses (`domain`, `types`, `primaryType`, `message`) feed
    directly into EIP-712 signTypedData; the Avantis operator executes them
    gas-free for the signer.

    - Trading endpoints are rate-limited per IP.


    Start with GET /v2/meta (addresses, enums, units, defaults) and GET
    /v2/pairs (market catalog).
servers:
  - url: https://tx-builder-testnet.avantisfi.com
security: []
tags:
  - name: meta
    description: Service metadata, pair catalog, health and metrics.
  - name: trading
    description: >-
      Build unsigned transactions for market/limit opens and closes, margin
      changes, and position increases (the direct, self-broadcast route).
  - name: delegate
    description: >-
      Authorize or revoke a delegate key that can trade on behalf of a trader
      (never move funds).
  - name: token
    description: >-
      USDC approval transactions — the one-time prerequisite before trading or
      LP deposits.
  - name: intents
    description: >-
      Build EIP-712 typed-data payloads to sign; the Avantis operator submits
      them on-chain so the signer pays no gas (the relayer route).
  - name: relay
    description: >-
      Submit an already-signed transaction through Avantis-operated RPCs:
      whitelist check, simulation with decoded revert reasons, then broadcast.
  - name: twap
    description: >-
      Time-weighted orders, filled in slices by the operator over a chosen
      duration.
  - name: referral
    description: >-
      Referral code registration, assignment, ownership transfer, and rebate
      claims.
  - name: lp
    description: >-
      Liquidity-provider flows on the Avantis USDC vault (ERC-4626 avUSDC
      tranche).
  - name: misc
    description: Keeper reward claims, vault buffer top-ups, and builder-code registration.
  - name: reads
    description: >-
      On-chain lookups the SDK needs for signing correctness: nonces, positions,
      delegation state, allowances.
paths:
  /v2/intents/twap-cancel:
    post:
      tags:
        - intents
      summary: Build a signable TWAP cancel intent
      description: >-
        Cancels a pending TWAP by its on-chain twapId, stopping further slices
        and refunding unused escrowed collateral. POST the signed intent to the
        twap-app (/twaps/cancel), which submits the transaction itself. Returns
        an EIP-712 payload to sign (trader or a registered delegate may sign)
        and hand to the Avantis operator for gasless execution.
      operationId: postV2IntentsTwapCancel
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                nonce:
                  anyOf:
                    - type: string
                    - type: number
                  description: >-
                    Replay-protection nonce (uint256; unordered Permit2-style
                    bitmap, not sequential). A random one is generated when
                    omitted — only pass a value to pre-reserve or
                    deterministically retry an intent. Check availability via
                    GET /v2/nonce.
                deadlineMs:
                  anyOf:
                    - type: string
                    - type: number
                  description: >-
                    Intent expiry as a unix timestamp in MILLISECONDS (not
                    seconds). Defaults to now + the service value shown in
                    /v2/meta → defaults.intentDeadlineMs.
                trader:
                  type: string
                  description: >-
                    The trader (position owner). USDC collateral is pulled from
                    and paid out to this address.
                twapId:
                  type: integer
                  minimum: 0
                  description: >-
                    The TWAP order id returned when the TWAP was opened (also in
                    on-chain events).
              required:
                - trader
                - twapId
              additionalProperties: false
      responses:
        '200':
          description: >-
            Success envelope: `ok` is `true` and `data` carries the payload
            documented below.
          content:
            application/json:
              schema:
                type: object
                required:
                  - ok
                  - data
                properties:
                  ok:
                    type: boolean
                    enum:
                      - true
                    description: Always `true` on success.
                  data:
                    type: object
                    description: >-
                      A ready-to-sign EIP-712 payload. Sign `{domain, types,
                      primaryType, message}` with `signTypedData` (trader or a
                      registered delegate, per `signerRule`) and hand the
                      65-byte r||s||v signature to the Avantis service that
                      executes this intent kind.
                    properties:
                      intent:
                        type: string
                        description: >-
                          The intent kind. Always `TwapCancelReq` for this
                          endpoint.
                        enum:
                          - TwapCancelReq
                      signerRule:
                        type: string
                        description: >-
                          Who may sign: `trader-or-delegate` for most intents,
                          `trader-only` where a delegate must not act (e.g.
                          delegate registration).
                        enum:
                          - trader-only
                          - trader-or-delegate
                      domain:
                        type: object
                        description: >-
                          EIP-712 signing domain. `verifyingContract` is the
                          TradingRouter proxy for trading intents and the
                          Referral contract for referral intents (which also has
                          its own nonce space).
                        properties:
                          name:
                            type: string
                            description: Domain name.
                            enum:
                              - AvantisTrading
                          version:
                            type: string
                            description: Domain version.
                            enum:
                              - '1'
                          chainId:
                            type: integer
                            description: Chain id the signature is valid on.
                          verifyingContract:
                            type: string
                            description: Contract that verifies the signature.
                            example: '0x0000000000000000000000000000000000000000'
                        required:
                          - name
                          - version
                          - chainId
                          - verifyingContract
                      primaryType:
                        type: string
                        description: Same as `intent`; pass to `signTypedData`.
                        enum:
                          - TwapCancelReq
                      types:
                        type: object
                        description: >-
                          EIP-712 type definitions keyed by struct name; pass to
                          `signTypedData` unchanged.
                        properties: {}
                        additionalProperties: true
                      message:
                        type: object
                        description: >-
                          The struct to sign. Field names mirror the on-chain
                          Solidity structs verbatim (see the glossary in GET
                          /v2/meta); all uint values are decimal strings. Pass
                          `domain` / `types` / `primaryType` / `message` to
                          `signTypedData` unchanged.
                        properties:
                          trader:
                            type: string
                            description: The trader (position owner).
                            example: '0x0000000000000000000000000000000000000000'
                          twapId:
                            type: string
                            description: >-
                              On-chain id of the TWAP order being cancelled.
                              Decimal string (JSON-safe uint).
                          nonce:
                            type: string
                            description: >-
                              Signer-chosen 256-bit nonce on a Permit2-style
                              unordered bitmap — any unused value works, no
                              sequencing. Decimal string (JSON-safe uint).
                          deadline:
                            type: string
                            description: >-
                              Intent expiry in unix MILLISECONDS (the contract
                              checks `deadline / 1000 >= block.timestamp`).
                              Decimal string (JSON-safe uint).
                        required:
                          - trader
                          - twapId
                          - nonce
                          - deadline
                      digest:
                        type: string
                        description: >-
                          The EIP-712 typed-data hash. Recompute it locally and
                          compare before signing — a mismatch means your signer
                          would produce an invalid signature.
                      encodedIntent:
                        type: string
                        description: >-
                          The abi.encode of the struct — the `userIntent` bytes
                          the Avantis operator entry point consumes. Useful for
                          self-submission or debugging.
                      meta:
                        type: object
                        description: >-
                          Echo of the resolved request (pair resolution, live
                          prices, validation). Informational only — not part of
                          what is signed.
                        properties:
                          twapId:
                            type: integer
                            description: The on-chain TWAP id the cancel is scoped to.
                    required:
                      - intent
                      - signerRule
                      - domain
                      - primaryType
                      - types
                      - message
                      - digest
                      - encodedIntent
        '400':
          description: >-
            Invalid input (failed schema validation or pre-trade checks like
            liquidity, leverage bounds, min position size, or market hours).
          content:
            application/json:
              schema:
                type: object
                required:
                  - ok
                  - error
                properties:
                  ok:
                    type: boolean
                    enum:
                      - false
                    description: Always `false` on errors.
                  error:
                    type: object
                    required:
                      - code
                      - message
                    description: Machine-readable error.
                    properties:
                      code:
                        type: string
                        enum:
                          - BAD_REQUEST
                        description: Stable error code for programmatic handling.
                      message:
                        type: string
                        description: Human-readable explanation of what went wrong.
                      details:
                        description: >-
                          Optional structured context — e.g. Zod validation
                          issues on BAD_REQUEST, or `{ target, revertData,
                          decodedError }` on SIMULATION_FAILED.

````