Skip to content

Instantly share code, notes, and snippets.

@simonjohnthompson
Created April 1, 2021 09:59
Show Gist options
  • Save simonjohnthompson/3c486fc7aa587572d2eb6ce9090f087b to your computer and use it in GitHub Desktop.
Save simonjohnthompson/3c486fc7aa587572d2eb6ce9090f087b to your computer and use it in GitHub Desktop.
Contract for difference - SJT revised (NB difference singular).
{"valueParameterDescriptions":[],"slotParameterDescriptions":[],"roleDescriptions":[["Counterparty","Party that gets the difference in trade price if it increases."],["Oracle","Party that provides the trade price in real time."],["Party","Party that gets the difference in trade price if it decreases."]],"contractType":"CD","contractName":"Contract for Difference","contractDescription":"\"Party\" and \"Counterparty\" deposit 100 Ada and after 60 slots is redistributed depending on the change in a given trade price reported by \"Oracle\". If the price increases, the difference goes to \"Counterparty\"; if it decreases, the difference goes to \"Party\", up to a maximum of 100 Ada.","choiceDescriptions":[["Price at beginning","Trade price at the beginning of the contract."],["Price at end","Trade price at the end of the contract."]]}
When
[Case
(Deposit
(Role "Party")
(Role "Party")
(Token "" "")
(Constant 100000000)
)
(When
[Case
(Deposit
(Role "Counterparty")
(Role "Counterparty")
(Token "" "")
(Constant 100000000)
)
(When
[Case
(Choice
(ChoiceId
"Price at beginning"
(Role "Oracle")
)
[Bound 0 1000000000]
)
(When
[]
150
(When
[Case
(Choice
(ChoiceId
"Price at end"
(Role "Oracle")
)
[Bound 0 1000000000]
)
(If
(ValueGT
(ChoiceValue
(ChoiceId
"Price at beginning"
(Role "Oracle")
))
(ChoiceValue
(ChoiceId
"Price at end"
(Role "Oracle")
))
)
(Let
"Decrease in price"
(SubValue
(ChoiceValue
(ChoiceId
"Price at beginning"
(Role "Oracle")
))
(ChoiceValue
(ChoiceId
"Price at end"
(Role "Oracle")
))
)
(Pay
(Role "Counterparty")
(Account (Role "Party"))
(Token "" "")
(Cond
(ValueLT
(UseValue "Decrease in price")
(Constant 100000000)
)
(UseValue "Decrease in price")
(Constant 100000000)
)
Close
)
)
(If
(ValueLT
(ChoiceValue
(ChoiceId
"Price at beginning"
(Role "Oracle")
))
(ChoiceValue
(ChoiceId
"Price at end"
(Role "Oracle")
))
)
(Let
"Increase in price"
(SubValue
(ChoiceValue
(ChoiceId
"Price at end"
(Role "Oracle")
))
(ChoiceValue
(ChoiceId
"Price at beginning"
(Role "Oracle")
))
)
(Pay
(Role "Party")
(Account (Role "Counterparty"))
(Token "" "")
(Cond
(ValueLT
(UseValue "Increase in price")
(Constant 100000000)
)
(UseValue "Increase in price")
(Constant 100000000)
)
Close
)
)
Close
)
)]
180 Close
)
)]
90 Close
)]
60 Close
)]
30 Close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment