Execution Overview

Bitcoin Cash has all the properties needed to satisfy the requirements of AnyHedge.

  • UTXO (Unspent Transaction Output) design reduces systemic risk common to other solutions
  • P2SH (Pay to Script Hash) significantly increases privacy and security of contracts
  • CDSV (Check Data Sig Verify) allows AnyHedge to work with Oracle data and enforce contract rules
  • Other OpCodes necessary for timing and value calculations such as OP_CAT, OP_OR, OP_DIV, OP_MOD, OP_SPLIT, OP_NUM2BIN,and OP_BIN2NUM.

We also document 17. Supplement A detailed example execution of AnyHedge on Bitcoin Cash. Here we describe a high level execution of AnyHedge in four steps with the US Dollar (USD) as the external asset.

  1. Intent
  2. Contract parameters
  3. Funding
  4. Redemption

1) Intent

The intent of the contract can be described with a few settings.

  • hedge_value Fixed Value that Hedge wants to preserve until Maturity.
  • start_price_bch_per_unit The start price for the contract.
  • largest_allowed_price_rise A percentage specifying how far the external asset price can rise from the start price before liquidation. This determines the size of the Volatility Pool collateral that Short must provide. When the allowed rise is small, Short provides less BCH than Hedge, the impact of price changes is amplified for Short, and the contract has less resistance to volatility. When the allowed rise increases to 100%, Short and Hedge provide the same amount of BCH, the impact of price changes becomes comparable for both, and the contract has more resistance to volatility. When the allowed rise is larger than 100%, Short provides more BCH than Hedge, the impact of price changes is reduced for Short, and the contract has strong resistance to volatility.
  • maturity_date The contract can be redeemed on or after this date.
  • trusted_price_oracle Hedge and Short must identify an oracle that they trust to provide reliable price data.

Hedge and Short agree on the following intent.

hedge_value =                 10.00 USD

start_price_bch_per_unit =    0.0045 BCH per USD;
                              (222.22 USD per BCH)

largest_allowed_price_rise =  33%

maturity_date =               +1 week from today

trusted_price_oracle =        For example, a well-
                              established exchange

redemption_addresses =        Addresses provided by Hedge
                              and Short to receive funds
                              at redemption.

2) Contract parameters

More detailed contract parameters are derived from the intent.

  • liq_price_high_bch_per_unit When the external asset price increases, this is the earliest price that triggers liquidation.
  • liq_price_low_bch_per_unit When the external asset price decreases, this is the earliest price that triggers liquidation. At the extreme, a price decrease consumes Hedge’s BCH until 1 satoshi covers the entire hedge value. Any value above zero can be selected. However here we use a fixed large decrease (90%) that effectively avoids liquidation due to price decreases, but also ensures that liquidation will work in such an extreme case.
  • total_satoshis This is the combined pool of BCH that the contract splits between Hedge and Short when the contract is redeemed. The size of the pool is calculated so that there is enough BCH to cover Hedge’s value at the highest allowed price.

Hedge and Short calculate and agree on the following contract parameters.

liq_price_high_bch_per_unit 
  = start_price_bch_per_unit * (1 + largest_allowed_price_rise)
  = 0.005985 BCH per USD; (167.08 USD per BCH)

liq_price_low_bch_per_unit
  = start_price_bch_per_unit * (1 - 0.90);
    i.e. static 90% price drop
  = 0.00045 BCH per USD; (2,222.22 USD per BCH)

total_satoshis
  = hedge_value * 1e8 sats_per_bch * liq_price_high_bch_per_unit
  = 5,985,000 satoshis

3) Funding

Hedge and Short pay into the AnyHedge contract as follows.

hedge_satoshis_in
  = hedge_value * 1e8 sats_per_bch * start_price_bch_per_unit
  = 4,500,000 satoshis;
    (equivalent to hedge_value of 10.00 USD
    at start of contract)

short_satoshis_in
  = total_satoshis - hedge_satoshis_in
  = 1,485,000 satoshis;
    (equivalent to 3.30 USD at start of contract)

Due to bearish market conditions for USD relative to BCH at the time of contract creation, Short also agrees to pay a premium to Hedge as part of the funding transaction.

4.1) Redemption under Maturity conditions

After funding the contract, there are 3 different types of redemption that Hedge and Short can do. First we describe redemption at Maturity, the standard outcome.

After 1 week, the contract reaches Maturity and can be redeemed. trusted_price_oracle provides a signed message with a price and time stamp, and the contract verifies that the signature is valid. In order to ensure a valid calculation of payout for Hedge’s Fixed Value, the contract creates a new value end_price_bch_per_usd which is clamped within the allowed boundaries of liq_price_low_bch_per_unit and liq_price_high_bch_per_unit. The price in the message is 0.004 BCH per USD; (250.00 USD per BCH) and is already within the allowed boundaries. Therefore end_price_bch_per_usd is equal to the message price.

In order to ensure that the contract is redeemed with the price at Maturity, the contract verifies that the time stamp in the message is for the maturity date.

The contract performs payout calculations as follows.

end_price_bch_per_usd = 0.004 BCH per USD; (250.00 USD per BCH)

hedge_satoshis_out
  = hedge_value * 1e8 satoshis_per_BCH * end_price_bch_per_usd
  = 4,000,000 satoshis;
    (equivalent to 10.00 USD, the original hedge_value)

short_satoshis_out
  = total_satoshis - hedge_satoshis_out
  = 1,985,000 satoshis; (equivalent to 4.96 USD)

The contract then sends hedge_satoshis_out and short_satoshis_out to the respective addresses in redemption_addresses. Hedge receives BCH worth exactly their original hedge_value in USD and Short receives more BCH than their original collateral due to the decrease in price of USD during the contract period.

4.2) Redemption under liquidation conditions

Another possible outcome after funding is liquidation. In this case, there is unexpectedly high price volatility that consumes Short’s Volatility Pool collateral.

After 4 days, before the contract reaches Maturity, trusted_price_oracle provides a signed message and the contract validates it as above. Also as above, the contract creates a new value end_price_bch_per_usd and clamps it within the allowed price range. The price in the message is 0.006024 BCH per USD; (166.00 USD per BCH) which is slightly higher than the boundary, liquidation_price_high_bch_per_unit. Therefore end_price_bch_per_usd is clamped to the boundary price, and liquidation becomes possible because the end price is at the boundary. In order to ensure that the contract is redeemed with a price that occurred before Maturity, the contract verifies that the time stamp in the message is after creation date and before the maturity date.

The contract performs payout calculations as follows.

end_price_bch_per_usd = 0.005985 BCH per USD;
                        (167.08 USD per BCH)

hedge_satoshis_out
  = hedge_value * 1e8 satoshis_per_BCH * end_price_bch_per_usd
  = 5,985,000 satoshis;
    (equivalent to 10.00 USD, the original hedge_value)

short_satoshis_out
  = total_satoshis - hedge_satoshis_out
  = 0 satoshis;
    (all satoshis used to satisfy hedge_value at this extreme price)

4.3) Mutual redemption

The last redemption available to AnyHedge is a failsafe mechanism. Hedge and Short can pay out all funds in the contract in any way they want as long as they both agree.

After 2 days, Hedge would like to exit the contract early and agrees on a split and a fee with Short. In a single trustless transaction, they submit their signatures, split payout_satoshis, and Hedge pays the agreed fee to Short.

Third party audit of mathematical soundness.

We take the reliability of our protocols very seriously, so we had a third party do a mathematical analysis of the AnyHedge protocol.

Read the results