Skip to content

Instantly share code, notes, and snippets.

@dgpv
Last active December 21, 2020 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgpv/6ec715a4f38d61cc9058c2619ca44b89 to your computer and use it in GitHub Desktop.
Save dgpv/6ec715a4f38d61cc9058c2619ca44b89 to your computer and use it in GitHub Desktop.
This is the sketch of the bet contract that allows price-dependent outcome without involving an oracle.
Author: Dmitry Petukhov (https://github.com/dgpv/)
Note: the asset prices are chosen for convenience and may not reflect current reality.
Assumes the possibility to use the covenant to enforce the rules,
for example the coventant that was used for the construction of
asset-based loans for Liquid Network: https://ruggedbytes.com/articles/ll/
Bet:
Neutral outcome:
- After 1 month, 1 btc = 10K usdt
Alice wins:
- After 1 month, 1 btc < 10K usdt
Bob wins:
- After 1 month, 1 btc > 10K usdt
Max loss for Alice: 1 btc, max profit for Alice: 10K usdt
Max loss for Bob: 10K usdt, max profit for Bob: 1 btc
Lock:
- Alice locks 1 btc
- Bob locks 10K usdt
After 30 days:
either:
- Alice adds 9 btc
- During day 31, Bob can add 90K usdt and take 10 btc,
and send 100K usdt to Alice
- After day 31, if Bob did not add 90K usdt, Alice takes 10K usdt and 10 btc
or
- Bob adds 90K usdt
- During day 31, Alice can add 9 btc and take 100K usdt,
and send 10 btc to Bob
- After day 31, if Alice did not add 9 btc, Bob takes 1btc and 100K usdt
On day 33, if no one made a move, they can take their deposits back
If the price is 9K:
- Alice has equivalent of 9K usdt locked,
needs to add 9 btc (equivalent of 81K usdt) to excercise the bet,
will get 10K profit (1.1111 btc) because for Bob it is not profitable
to fulfil his part (will get 10 btc that are valued at 90K usdt,
but will give 100K usdt)
- If the price is below 9K, the 9 btc that Alice needs to excersise
the bet will cost less for Alice (if she needs to aquire them)
If the price is 11200:
- Bob has 10K usdt (equivalent of ~0.893 btc) locked,
needs to add 90K usdt (eqivalent of ~ 8.0357 btc) to excercise the bet,
will get 11200 usdt profit (1 btc) because for Alice it is not profitable to
fulfil her part (will get 100K usdt that are valued as ~8.92857 btc,
but will give 10 btc)
- If the price is above 11200, the 90K usdt that Bob needs to excersise
the bet will cost less for Bob (if he needs to sell his btc to get them)
If the price is 10800:
- Bob has 10K usdt (equivalent of ~0.9259 btc) locked,
needs to add 90K usdt (eqivalent of ~8.3333 btc) to excercise the bet,
will get 8000 usdt profit, because Alice will lose less if she fulfils
her part (will get 100K usdt that are valued as ~9.259 btc,
but will give 10 btc, losing ~0.741 btc)
- Would Alice fail to fulfil her part, she would lose 1 btc, so she is
incentivized to fulfil.
If the price is 9200:
- Alice has 1 btc (equivalent of 9200 usdt) locked,
needs to add 9btc (eqivalent of 82800 usdt) to excercise the bet,
will get ~0.87 btc profit, because Bob will lose less if he fulfils
his part (will get 10 btc that are valued as 92000 usdt,
but will give 100000 usdt, losing 8000 usdt)
- Would Bob fail to fulfil his part, he would lose 10000 usdt, so he is
incentivized to fulfil.
In principle, the bets need not be to be made in btc/usdt.
Both parties can place bets in usdt, or both in btc, or even in other assets,
but the profit calculation will become more complex.
@dgpv
Copy link
Author

dgpv commented Dec 9, 2020

In the 1btc/10000usdt example, Alice is still incentivized to execute when the rate is 11100, and Bob takes 11K profit:

rate: 11100.0
Alice locked: 1.00000000 btc, equiv. 11100.0 usdt
Bob locked: 10000.00 usdt, equiv. 0.90090090 btc
exec_price: 111000.00
Bob wins
Bob needs: 90000.00 usdt, equiv. 8.10810811 btc
Alice will execute to limit the loss, will lose 0.99099099 btc, equiv. 11000.00 usdt
Bob's profit: 11000.00 usdt, equiv. 0.99099099 btc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment