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), clawback (the creator reclaims the underlying after expiry), and inspect (parse/parse_child) — and reports the exact signatures a caller must produce (required_signatures).

§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
A created option, returned by crate::create so the caller can later exercise or claw it back — both need the option singleton, the underlying terms, and the locked-underlying coin, which only exist once the create spend is confirmed.
OptionSpend
The result of a dig-options builder: the unsigned coin spends it produced, and — for crate::create — the CreatedOption the caller keeps to operate the option 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.
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).
required_signatures
Compute every signature coin_spends requires, given the network’s agg_sig_me additional data (the genesis challenge — mainnet or testnet).
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.