Skip to main content

Crate dig_options

Crate dig_options 

Source
Expand description

§dig-options — the DIG Network canonical Chia option-contract expert crate

dig-options is a pure, key-free, network-free CoinSpend-builder for Chia covered options (the CHIP-0042 option primitive). It constructs the exact CoinSpends for the option lifecycle — create (lock an XCH underlying, mint the option singleton), exercise (pay the strike, unlock the underlying to the holder), transfer (move the option ticket to a new owner), clawback (the creator reclaims the underlying after expiry), and inspect (parse/parse_child) — and reports the exact signatures a caller must produce (required_signatures).

It also rehydrates a previously-minted option: parse recovers only an option’s identity fields, so rehydrate reconstructs the full operable CreatedOption from caller-observed terms + the launcher metadata (parse_metadata) and VERIFIES it against the option’s on-chain commitments, letting a caller exercise/transfer/claw back an option it did not mint in the same session.

§The custody model (HARD invariants)

dig-options never holds a secret key, never signs, and never touches the network. Every builder takes only public inputs (an Owner carrying a public key or a caller-supplied inner spender, plain Bytes32 puzzle hashes, coins the caller already fetched) and appends unsigned coin spends to a caller-owned SpendContext. The consumer signs the messages reported by required_signatures, assembles the SpendBundle, and broadcasts. Signing — and the secret key — stay entirely on the caller’s side of the identity boundary (#908).

§Scope (v0.1.0)

The underlying is XCH, and the strike is XCH-only: create REJECTS a non-XCH strike up front so create and exercise have symmetric support envelopes (no holder can acquire an option it could never exercise). exercise builds BOTH settlement legs for an XCH strike — the underlying is claimed to the holder and the strike is paid to the creator, in one bundle — and keeps its non-XCH guard as defense-in-depth. clawback and inspection work for any strike type curried into an existing option. CAT/revocable-CAT/NFT underlyings and strike are a future extension. See SPEC.md for the normative contract.

Structs§

CreatedOption
The operable handle for a live option: the option singleton, the underlying terms, and the locked-underlying coin needed to exercise, transfer, or claw it back.
OptionMetadata
OptionSpend
The result of a dig-options builder: the unsigned coin spends it produced, and — for the builders that yield an operable option — the CreatedOption handle the caller keeps to operate it later.
OptionTerms
The terms of a covered option: who created it, who owns (may exercise) it, how much XCH it locks as the underlying, what strike the holder must pay, and when it expires.
OptionUnderlying
ParsedOption
A reconstructed option plus the identity fields recoverable from its coin spend.
RehydratedTerms
The terms a caller supplies to rehydrate a previously-minted option.
SpendContext
A wrapper around Allocator that caches puzzles and keeps track of a list of CoinSpend. It’s used to construct spend bundles in an easy and efficient way.
StrikePayment
The strike payment funding a exercise: the caller-supplied XCH coin the holder spends to pay the strike into the settlement puzzle.

Enums§

Error
Everything that can go wrong while building an option coin spend or reporting the signatures a coin spend requires.
OptionType
Owner
The p2 (owner) layer that authorizes an option’s inner spend, expressed WITHOUT any secret.
RequiredSignature

Traits§

SpendWithConditions

Functions§

clawback
Build the unsigned coin spends that CLAW BACK created’s locked XCH underlying to its creator, authorized by creator.
create
Build the unsigned coin spends that CREATE an option per terms, funded from funding_coin and authorized by creator.
exercise
Build the unsigned coin spends that EXERCISE created by its holder, paying strike.
parse
Decode an option directly from its own coin spend (its coin, serialized puzzle reveal, and solution). Returns Ok(None) when the puzzle is not an option contract.
parse_child
Reconstruct the option child created by spending parent_coin, given that parent’s serialized puzzle reveal and solution (both fetched by the caller).
parse_metadata
Recover an option’s OptionMetadata (expiry seconds + strike type) from the launcher coin’s solution, which the caller fetched from a node/indexer.
rehydrate
Reconstruct a full CreatedOption from a parsed option, caller-supplied terms, and the fetched underlying_coin, verifying every reconstructed field against the option’s on-chain commitments.
required_signatures
Compute every signature coin_spends requires, given the network’s agg_sig_me additional data (the genesis challenge — mainnet or testnet).
transfer
Build the unsigned coin spend that TRANSFERS created’s option singleton to new_owner_puzzle_hash, authorized by its current owner.
version
The crate’s semantic version, surfaced so a consumer can record which builder version produced a spend.

Type Aliases§

OptionContract
Result
The result of a dig-options operation.