Skip to main content
DiaBtcUsdExpiryOracle (dia_btc_usd_expiry_oracle.ark) is a stateful rolling expiry oracle that stores up to eight historical DIA BTC/USD fixings in one output identified by a one-unit asset (Asset as Contract ID). It imports DiaBtcUsdCents from DIA BTC/USD Live Oracle to verify the same DIA Lasernet BTC/USD feed. Instead of verifying a live quote during a consumer spend, it writes settled expiry prices into a 329-byte state packet. Any expiry-based contract, such as Options, futures, or prediction markets, can then settle against a scheduled expiry after that window closes. Each slot pairs an expiry (the Unix timestamp a fixing belongs to) with a fixing (the DIA BTC/USD price in USD cents and its sample timestamp). Once the sample window [expiry, expiry + expiryLag] closes, anyone holding a signed DIA update from that window can publish it into slot 0. Consumers co-spend the output later to read their expiry slot without fetching another signature.

Source

Save dia_btc_usd_expiry_oracle.ark alongside dia_btc_usd_cents.ark from DIA BTC/USD Live Oracle. Compile the exact same source on every party, because any edit changes the derived contract address.
dia_btc_usd_expiry_oracle.ark

Constructor

operatorExitDelay is not a constructor parameter, because the SDK binds it to the operator’s exit delay (CSV delays).

State Packet

State lives in extension packet type 32 (329 bytes). Integers use 8-byte little-endian sign-magnitude encoding (int2bytes(n, 8)). Fund the initial oracle output on output 0 with 1 unit of oracleId and a genesis packet 32 whose version is 0x01, round is 0, and all eight slots are zero. attest checks the size and version of the next packet only, so a short genesis packet fails inside substr instead of with its own message.

Functions

attest, read, and migrate are emulator-enforced paths that the operator checks before cosigning, while unilateral is the consensus-enforceable exit path.

attest

Publishes one settled expiry fixing into slot 0.
  • Runs at input 0 once the operator’s enclave clock passes expiry + expiryLag, requiring the DIA sample time to sit inside [expiry, expiry + expiryLag].
  • Accepts an intent after intentExpiry, so a signed update from that window can still fill its slot once DIA’s one-hour lifetime has passed. DIA BTC/USD Live Oracle rejects an expired intent, because a live quote must still be current.
  • Calls DiaBtcUsdCents.verifyPrice to verify DIA’s EIP-712 signature against oraclePk via checkSigFromStack and round the 18-decimal price to USD cents.
  • Rejects any expiry already present in the eight slots, increments round by 1, shifts previous slots 0..6 down to 1..7, and continues the script, satoshi value, and oracleId unit on output 0.

read

Lets any consumer contract read a stored fixing in its own settlement transaction without a signature.
  • Runs at input 1, copies packet 32 unchanged from input 1 to the spending transaction, and adds readFee sats to output 0.
  • Output 0 carries the oracle’s own script as its continuation. Because one output 0 cannot carry two scripts, pool templates that also continue on output 0 (Lending Pool, Automated Market Maker) cannot share a transaction with read. Contracts that settle without continuing, such as Options, co-spend the oracle directly and pay readFee out of their locked collateral.

migrate

Moves oracleId and the unchanged state packet to a new script without disrupting open consumers.
  • Requires tx.numInputs == 1, a valid transaction signature from adminPk, and an unchanged packet 32 alongside the satoshi value and oracleId unit on output 0.
  • Because checkSig(adminSig, adminPk) signs the spending transaction itself, it binds the replacement output script and current outpoint so a migration signature cannot replay after another spend.

unilateral

Provides the onchain exit if the operator stops cosigning.
  • Waits for operatorExitDelay after unrolling onchain and lets adminPk claim the output alone.
  • Once the identity unit exits to Bitcoin, offchain consumers that depend on this oracleId can no longer co-spend it.

Output Lifecycle

Every cooperative spend recreates the oracle on output 0 with its identity unit, and only migrate changes the script.

Publish a Fixing

Anyone who holds a signed DIA OracleUpdate (BTC/USD) with time inside [expiry, expiry + expiryLag] can publish that slot once expiry + expiryLag has passed. Fetch updates using Live DIA Inputs, then spend the oracle at input 0 with attest:

Consume a Fixing

Consumers co-spend the oracle as input 1 through read, which checks no signature so anyone can settle a matured contract. Payouts come from the consumer’s locked collateral minus readFee:
A consumer checks for the oracleId unit on input 1, reads packet 32 from tx.inputs[1], and scans the eight slots for its expiry. Option.open and Option.price in Options do exactly that, so copy them for your own consumer. Because the operator checks that the previous transaction attached to input 1 hashes to its outpoint, spenders cannot forge an input packet.

Replace the Script

When DIA rotates its signer key, when the operator rotates its server key, or when you want to change expiryLag or readFee, adminPk moves oracleId to a replacement script through migrate. Open consumers keep working without changes, because they check only oracleId and packet 32.

Adapting and Limits