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
Savedia_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 type32 (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 sampletimeto 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.verifyPriceto verify DIA’s EIP-712 signature againstoraclePkviacheckSigFromStackand round the 18-decimal price to USD cents. - Rejects any
expiryalready present in the eight slots, incrementsroundby1, shifts previous slots0..6down to1..7, and continues the script, satoshi value, andoracleIdunit 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
32unchanged from input 1 to the spending transaction, and addsreadFeesats 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 payreadFeeout 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 fromadminPk, and an unchanged packet32alongside the satoshi value andoracleIdunit 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
operatorExitDelayafter unrolling onchain and letsadminPkclaim the output alone. - Once the identity unit exits to Bitcoin, offchain consumers that depend on this
oracleIdcan no longer co-spend it.
Output Lifecycle
Every cooperative spend recreates the oracle on output 0 with its identity unit, and onlymigrate changes the script.
Publish a Fixing
Anyone who holds a signed DIAOracleUpdate (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 throughread, which checks no signature so anyone can settle a matured contract. Payouts come from the consumer’s locked collateral minus readFee:
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 changeexpiryLag 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.