> ## 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.

# Two oracle prices compared

> The deviation between two prices on one chain (Chainlink, Pyth, RedStone, Chronicle or a pool's spot price on EVM; Pragma or an Ekubo pool on Starknet; Pyth or a pool on Solana), refusing a feed older than maxAge; or whether they agree within a bound.

**Returns:** the deviation |a - b| / min(a, b) in basis points, 2 decimals (uint256); with maxDeviationBps, true when within it (bool)

- Both feeds must price the same pair in the same quote; the service shows Chainlink's description, but cannot read what a Pyth id names on chain.

- Pyth prices on EVM are pull-based: a feed nobody updated is refused by maxAge rather than compared.

- A pool leg is a spot price, token1 per token0 unless inverted; it can be pushed by one trade, and its quote is a token, not USD.

- Starknet's final profile lags at least 6 hours, which counts toward maxAge; use finality=fast for a fresh comparison.

- RedStone push feeds speak Chainlink's AggregatorV3 interface and are read like it; a RedStone feed named for an asset ("RedStone Price Feed for ETH") is quoted in USD.

- Chronicle oracles are read-gated: the source calls readWithAge() from address 0, which Chronicle tolls for off-chain reads (checked when the source is derived). If Chronicle stops tolling it, the read reverts and the round fails rather than signing.

- On Solana the comparison signs in tolerance mode: the deviation is an int256 whose nodes agree within agreeBps of the median (an absolute band), and maxDeviationBps (a yes/no) is refused. Every Solana pool leg asserts its owner program.

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

Template `oracle.compare@1` · Oracle · cross-check · reads EVM, Starknet, Solana

| Route | Answer | Cost |
| - | - | - |
| `GET /v1/data/oracle/compare` | 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/oracle/compare/source` | The source and its `sourceId` | Free |
| `GET /v1/data/oracle/compare/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/oracle/compare/source?a=chainlink%3A0x71041dddad3595f9ced3dccfbe3d1f4b0a16bb70&b=pyth%3A0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace&chain=base"

# 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/oracle/compare?a=chainlink%3A0x71041dddad3595f9ced3dccfbe3d1f4b0a16bb70&b=pyth%3A0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace&chain=base"
```


## OpenAPI

````yaml data-openapi.json GET /v1/data/oracle/compare
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/oracle/compare:
    get:
      tags:
        - Oracle
      summary: Two oracle prices compared
      description: >-
        The deviation between two prices on one chain (Chainlink, Pyth,
        RedStone, Chronicle or a pool's spot price on EVM; Pragma or an Ekubo
        pool on Starknet; Pyth or a pool on Solana), refusing a feed older than
        maxAge; or whether they agree within a bound.


        **Returns:** the deviation |a - b| / min(a, b) in basis points, 2
        decimals (uint256); with maxDeviationBps, true when within it (bool)


        - Both feeds must price the same pair in the same quote; the service
        shows Chainlink's description, but cannot read what a Pyth id names on
        chain.


        - Pyth prices on EVM are pull-based: a feed nobody updated is refused by
        maxAge rather than compared.


        - A pool leg is a spot price, token1 per token0 unless inverted; it can
        be pushed by one trade, and its quote is a token, not USD.


        - Starknet's final profile lags at least 6 hours, which counts toward
        maxAge; use finality=fast for a fresh comparison.


        - RedStone push feeds speak Chainlink's AggregatorV3 interface and are
        read like it; a RedStone feed named for an asset ("RedStone Price Feed
        for ETH") is quoted in USD.


        - Chronicle oracles are read-gated: the source calls readWithAge() from
        address 0, which Chronicle tolls for off-chain reads (checked when the
        source is derived). If Chronicle stops tolling it, the read reverts and
        the round fails rather than signing.


        - On Solana the comparison signs in tolerance mode: the deviation is an
        int256 whose nodes agree within agreeBps of the median (an absolute
        band), and maxDeviationBps (a yes/no) is refused. Every Solana pool leg
        asserts its owner program.


        A signed round on the derived source: see the document's description for
        paying with a session or x402.
      operationId: oracle.compare
      parameters:
        - description: CAIP-2 id or alias (EVM, Starknet, Solana chains)
          example: base
          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
              - starknet
              - starknet:SN_MAIN
              - starknet-sepolia
              - starknet:SN_SEPOLIA
            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: >-
            EVM: "chainlink:<aggregator or proxy>", "redstone:<price feed>",
            "chronicle:<oracle>", "pyth:<price feed id>" or "pool:<Uniswap
            v3-style pool>[:invert]"; Starknet: "pragma:<pair id>" (e.g.
            pragma:ETH/USD) or
            "pool:ekubo:<token0>:<token1>:<fee>:<tickSpacing>:<extension>[:invert]";
            Solana: "pyth:<price feed id>" or "pool:<Whirlpool, Raydium CLMM
            pool or DLMM pair>[:invert]"
          example: chainlink:0x71041dddad3595f9ced3dccfbe3d1f4b0a16bb70
          in: query
          name: a
          required: true
          schema:
            type: string
          x-molpha-type: text
        - description: the second price, in the same forms
          example: >-
            pyth:0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace
          in: query
          name: b
          required: true
          schema:
            type: string
          x-molpha-type: text
        - description: >-
            seconds; a feed updated longer ago than this before the round fails
            it (pool legs have no update time)
          in: query
          name: maxAge
          required: false
          schema:
            default: '86400'
            pattern: ^(0|[1-9][0-9]*)$
            type: string
          x-molpha-type: uint
        - description: >-
            set it to sign a yes/no answer (deviation within the bound) instead
            of the deviation (not on Solana)
          in: query
          name: maxDeviationBps
          required: false
          schema:
            pattern: ^(0|[1-9][0-9]*)$
            type: string
          x-molpha-type: uint
        - description: >-
            Solana: nodes whose deviation is within this many bps of the median
            deviation agree (5 when not set)
          in: query
          name: agreeBps
          required: false
          schema:
            pattern: ^(0|[1-9][0-9]*)$
            type: string
          x-molpha-type: uint
        - description: >-
            Pragma legs: the fewest sources the median may aggregate (1 when not
            set)
          in: query
          name: minSources
          required: false
          schema:
            pattern: ^(0|[1-9][0-9]*)$
            type: string
          x-molpha-type: uint
        - 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.