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

# Pool TWAP price

> The time-weighted average price over a window, from the pool's own oracle: 1.0001 raised to the mean tick (observe on EVM, rounded as Uniswap's OracleLibrary rounds it; a Raydium CLMM observation ring on Solana), or a Meteora DLMM pair's mean active bin, adjusted for both tokens' decimals.

**Returns:** quote-token units per one base token over the window ending at the pinned block, 18 decimals; the base is token0 unless inverted

- The pool must hold observations as old as the window, or every read fails.

- The price names its quote token. There is no USD conversion.

- The mean tick is OracleLibrary's (rounded toward negative infinity), and the price is 1.0001^tick computed to 36 places with each step rounded down, then rounded to 18: exact to about 24 significant digits for ticks above -400000. It is not bit-identical to OracleLibrary.getQuoteAtTick, which goes through TickMath's Q64.96 square root.

- A price below 1e-18 of the quote token refuses (the source asserts a positive value); use invert.

- Version 1 signed the mean tick itself; dex.pool.twapDeviation still compares ticks.

- Solana: the pool's observation ring is read at its newest slot and the slot k observations earlier (k = window / the sampling interval: 15 s on Raydium CLMM, about 120 s on DLMM), so the span is set by when the pool was traded, not by the window exactly. The source refuses unless the span is between window/2 and 2 x window and the newest slot is no older than the window: quiet pools refuse. The window is at most 99 observations (about 24 minutes on Raydium).

- Solana runs in tolerance mode (int256, median of node reads); the observation account's owner and its pool are asserted. Orca Whirlpools keep no price observations and are refused.

A signed round on the derived source: see the document's description for paying with a session or x402.

Template `dex.pool.twap@2` · DEX · on-chain TWAP and EMA · reads EVM, Solana

| Route | Answer | Cost |
| - | - | - |
| `GET /v1/data/dex/pool/twap` | The threshold-signed value ([Signed reads](https://docs.molpha.io/data/signed-reads.md)) | One round: x402 or one unit of your plan |
| `GET /v1/data/dex/pool/twap/source` | The source and its `sourceId` | Free |
| `GET /v1/data/dex/pool/twap/dry-run` | A status-only run on one node, no value | Free |

```bash theme={null}
# The source these parameters build, and its sourceId (free)
curl "https://gateway.molpha.io/v1/data/dex/pool/twap/source?chain=ethereum&pool=0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"

# The signed value with a sign-in session (without one, the answer is the x402 quote)
curl -H "Authorization: Bearer $MOLPHA_SESSION" "https://gateway.molpha.io/v1/data/dex/pool/twap?chain=ethereum&pool=0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
```


## OpenAPI

````yaml data-openapi.json GET /v1/data/dex/pool/twap
openapi: 3.1.0
info:
  description: >-
    Every Molpha Data template has its own routes on the gateway. `GET
    /v1/data/<template>` (the template ID with each dot a slash, e.g.
    `token.supply` is `/v1/data/token/supply`) returns the threshold-signed
    value: the template's parameters are query parameters, the gateway derives
    the source and runs a round on it. Pay with a sign-in session
    (`Authorization: Bearer`, one unit of your plan's quota) or with x402:
    without a session the first answer is `402` with the quote in
    `PAYMENT-REQUIRED`; send the same request again with `PAYMENT-SIGNATURE`.
    The value's answer is the execute routes' own (`AttestationResponse`, errors
    as `{status, error}`); failures before the round (a wrong parameter, an
    unknown chain) use the data error body. `/source` and `/dry-run` under each
    template are free and rate-limited per address. To sign with RequestAuth
    instead of a session, take the source from `/source` and post it to `POST
    /v1/round/execute`.
  title: Molpha Data
  version: '1'
servers:
  - url: https://gateway.molpha.io
    description: Molpha gateway (Solana devnet release)
security: []
tags:
  - name: Catalog and sources
  - name: Wallet
  - name: Chain
  - name: DEX
  - name: Derived
  - name: Reference data
  - name: Yield
  - name: Raw state
  - name: Lending
  - name: Oracle
  - name: Perps
  - name: Position
  - name: Token
paths:
  /v1/data/dex/pool/twap:
    get:
      tags:
        - DEX
      summary: Pool TWAP price
      description: >-
        The time-weighted average price over a window, from the pool's own
        oracle: 1.0001 raised to the mean tick (observe on EVM, rounded as
        Uniswap's OracleLibrary rounds it; a Raydium CLMM observation ring on
        Solana), or a Meteora DLMM pair's mean active bin, adjusted for both
        tokens' decimals.


        **Returns:** quote-token units per one base token over the window ending
        at the pinned block, 18 decimals; the base is token0 unless inverted


        - The pool must hold observations as old as the window, or every read
        fails.


        - The price names its quote token. There is no USD conversion.


        - The mean tick is OracleLibrary's (rounded toward negative infinity),
        and the price is 1.0001^tick computed to 36 places with each step
        rounded down, then rounded to 18: exact to about 24 significant digits
        for ticks above -400000. It is not bit-identical to
        OracleLibrary.getQuoteAtTick, which goes through TickMath's Q64.96
        square root.


        - A price below 1e-18 of the quote token refuses (the source asserts a
        positive value); use invert.


        - Version 1 signed the mean tick itself; dex.pool.twapDeviation still
        compares ticks.


        - Solana: the pool's observation ring is read at its newest slot and the
        slot k observations earlier (k = window / the sampling interval: 15 s on
        Raydium CLMM, about 120 s on DLMM), so the span is set by when the pool
        was traded, not by the window exactly. The source refuses unless the
        span is between window/2 and 2 x window and the newest slot is no older
        than the window: quiet pools refuse. The window is at most 99
        observations (about 24 minutes on Raydium).


        - Solana runs in tolerance mode (int256, median of node reads); the
        observation account's owner and its pool are asserted. Orca Whirlpools
        keep no price observations and are refused.


        A signed round on the derived source: see the document's description for
        paying with a session or x402.
      operationId: dex.pool.twap
      parameters:
        - description: CAIP-2 id or alias (EVM, Solana chains)
          example: ethereum
          in: query
          name: chain
          required: true
          schema:
            enum:
              - ethereum
              - eip155:1
              - sepolia
              - eip155:11155111
              - eip155:137
              - eip155:143
              - arbitrum
              - eip155:42161
              - bnb
              - eip155:56
              - base
              - eip155:8453
              - base-sepolia
              - eip155:84532
              - hyperevm
              - eip155:999
              - solana
              - solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp
              - solana-devnet
              - solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1
            type: string
          x-molpha-type: chain
        - description: >-
            "final" or "fast", or a raw mode: "finalized", "safe",
            "confirmations:<n>" (EVM, Starknet), "confirmed" (Solana)
          in: query
          name: finality
          required: false
          schema:
            default: final
            type: string
          x-molpha-type: finality
        - description: >-
            a Uniswap v3-style pool with an observation buffer (EVM), a Raydium
            CLMM pool or a Meteora DLMM pair (Solana)
          example: '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640'
          in: query
          name: pool
          required: true
          schema:
            type: string
          x-molpha-type: address
        - description: seconds, 1 to 86400
          in: query
          name: window
          required: false
          schema:
            default: '1800'
            pattern: ^(0|[1-9][0-9]*)$
            type: string
          x-molpha-type: uint
        - description: 'false: token1 per token0; true: the inverse'
          in: query
          name: invert
          required: false
          schema:
            default: 'false'
            enum:
              - 'false'
              - 'true'
            type: string
          x-molpha-type: enum
        - description: >-
            Signatures the round needs (default 3). Tolerance-mode sources need
            at least 3; the gateway bounds it by the protocol minimum, your plan
            and the live nodes.
          in: query
          name: signaturesRequired
          required: false
          schema:
            default: 3
            maximum: 255
            minimum: 1
            type: integer
      responses:
        '200':
          $ref: '#/components/responses/ValueOK'
        '400':
          $ref: '#/components/responses/Value400'
        '401':
          $ref: '#/components/responses/Value401'
        '402':
          $ref: '#/components/responses/Value402'
        '403':
          $ref: '#/components/responses/Value403'
        '409':
          $ref: '#/components/responses/Value409'
        '422':
          $ref: '#/components/responses/Value422'
        '429':
          $ref: '#/components/responses/Value429'
        '503':
          $ref: '#/components/responses/Value503'
        default:
          $ref: '#/components/responses/ValueDefault'
      security:
        - BearerAuth: []
        - X402Payment: []
components:
  responses:
    ValueOK:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AttestationResponse'
      description: >-
        The threshold-signed value (`data.attestation`) and its rendering
        (`data.value`); `Molpha-Source-Id` names the derived source.
    Value400:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
      description: >-
        The round request was refused (for example `signaturesRequired` below
        the protocol minimum); a malformed query is the data error body
    Value401:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
      description: The session token is unknown, expired or revoked
    Value402:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/payment.Required'
      description: >-
        No session and no payment: the x402 quote. Pay it and send the same
        request with `PAYMENT-SIGNATURE`
      headers:
        PAYMENT-REQUIRED:
          description: Base64 x402 v2 payment requirements
          schema:
            type: string
    Value403:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
      description: >-
        The subscription is inactive, the delegate is not authorized, or the
        term's quota is spent
    Value409:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
      description: >-
        You already have a round for this source and quorum in this 100 ms tick;
        retry one tick later
    Value422:
      description: A parameter is wrong, or the chain shows it names something else
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/DataErrorResponse'
    Value429:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/DataErrorResponse'
      description: >-
        Too many new derivations from this address, or too many rounds for this
        consumer; retry after Retry-After
    Value503:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
      description: >-
        No quorum could form now, the gateway is at capacity, or a fact could
        not be read; retry after Retry-After
    ValueDefault:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/DataErrorResponse'
      description: Data error body
  schemas:
    AttestationResponse:
      properties:
        data:
          $ref: '#/components/schemas/AttestationData'
        status:
          example: completed
          type: string
      type: object
    ErrorResponse:
      properties:
        error:
          example: validation failed
          type: string
      type: object
    payment.Required:
      properties:
        accepts:
          items:
            $ref: '#/components/schemas/payment.Requirements'
          type: array
        error:
          type: string
        extensions:
          allOf:
            - $ref: '#/components/schemas/payment.Extensions'
          description: |-
            Extensions carries non-Molpha payment terms, currently the relayed
            upstream-source quote. It never affects the accepted-requirements
            byte comparison performed by Decode.
        resource:
          $ref: '#/components/schemas/payment.Resource'
        x402Version:
          type: integer
      type: object
    DataErrorResponse:
      properties:
        error:
          properties:
            code:
              example: PARAM_INVALID
              type: string
            input:
              type: string
            message:
              type: string
            stage:
              type: string
          type: object
      type: object
    AttestationData:
      properties:
        attestation:
          $ref: '#/components/schemas/Attestation'
        fresh:
          example: true
          type: boolean
        outcome:
          description: >-
            Outcome is present for a source with a policy (node-client
            docs/policy.md): conclusive, the

            value is the source's result; or fallback, the policy concluded
            INCONCLUSIVE (reason) and the

            value is its declared fallback. Both are signed under the source's
            ID. The label is the nodes'

            word: what a consumer can rely on is the signed value compared with
            the declared fallback.
          example: fallback
          type: string
        reason:
          example: '0x01'
          type: string
        roundId:
          description: >-
            RoundID is the round's ID: requests for one feed in one 100 ms tick
            share it. The read service

            serves the round's archive record, and for a source with a policy
            each node's receipt, under it

            (GET /v1/rounds/{roundId}).
          example: 5f1c...
          type: string
        value:
          description: >-
            Value is the decimal rendering of payload.value (trailing zeros
            trimmed), not signed.
          example: '42150125000000'
          type: string
        valuePreimage:
          description: >-
            ValuePreimage is the 0x-prefixed hex of the bytes the source's
            keccak256 output hashed to

            payload.value. It is present only for such a source, and the
            response is its only copy: the

            signed value is the hash. Hash it to check, and pass it as the raw
            value when submitting the

            attestation to Solana.
          example: '0x68656c6c6f'
          type: string
      type: object
    payment.Requirements:
      properties:
        amount:
          type: string
        asset:
          type: string
        extra:
          additionalProperties:
            type: string
          type: object
        maxTimeoutSeconds:
          type: integer
        network:
          type: string
        payTo:
          type: string
        scheme:
          type: string
      type: object
    payment.Extensions:
      properties:
        upstream:
          $ref: '#/components/schemas/payment.UpstreamQuote'
      type: object
    payment.Resource:
      properties:
        description:
          type: string
        mimeType:
          type: string
        url:
          type: string
      type: object
    Attestation:
      properties:
        payload:
          $ref: '#/components/schemas/AttestationPayload'
        signature:
          $ref: '#/components/schemas/SchnorrSignature'
      type: object
    payment.UpstreamQuote:
      properties:
        eligibleSetSize:
          type: integer
        error:
          type: string
        nodeCount:
          type: integer
        provider:
          description: >-
            Provider names the integrated provider whose paid host this is, when
            it is one.
          type: string
        redundancyBuffer:
          type: integer
        resource:
          type: string
        signaturesRequired:
          type: integer
        supportedX402Versions:
          items:
            type: integer
          type: array
      type: object
    AttestationPayload:
      properties:
        registryVersion:
          example: 42
          type: integer
        signaturesRequired:
          example: 18
          type: integer
        sourceId:
          example: 0xabc123...
          type: string
        timestamp:
          description: >-
            Gateway-assigned round time in unix milliseconds: the start of the
            round's 100 ms tick.
          example: 1700100000000
          type: integer
        value:
          description: >-
            Value is the fixed 32-byte packed attestation value (exact uint256
            or tolerance int256).
          example: 42150125000000...
          type: string
      type: object
    SchnorrSignature:
      properties:
        commitment:
          example: 02...
          type: string
        signature:
          example: 01...
          type: string
        signersBitmap:
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      description: >-
        Session token from `POST /v1/session` (sign in with the subscription
        owner's or a delegate's wallet). Each value uses one round of the plan's
        quota.
      scheme: bearer
      type: http
    X402Payment:
      description: >-
        Base64 x402 v2 payment payload for the quote a request without it
        receives (`402`, `PAYMENT-REQUIRED`).
      in: header
      name: PAYMENT-SIGNATURE
      type: apiKey

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.