Skip to content

Instantly share code, notes, and snippets.

@hrajchert
Created June 21, 2023 18:14
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 hrajchert/4bc8b9eac344f02e718d98c7f52a41db to your computer and use it in GitHub Desktop.
Save hrajchert/4bc8b9eac344f02e718d98c7f52a41db to your computer and use it in GitHub Desktop.
CFD with oracle blockly
{"valueParameterInfo":[["Amount paid by party",{"valueParameterFormat":{"contents":[6,"₳"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount that the _**party**_ will deposit at the beginning of the contract."}],["Amount paid by counterparty",{"valueParameterFormat":{"contents":[6,"₳"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount that the _**counterparty**_ will deposit at the beginning of the contract."}],["Amount of Ada to use as asset",{"valueParameterFormat":{"contents":[6,"₳"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount of Ada whose price in dollars change to monitor."}]],"timeParameterDescriptions":[["Party deposit deadline","The _amount paid by party_ must be deposited by this deadline, otherwise the contract is cancelled."],["Counterparty deposit deadline","The _amount paid by counterparty_ must be deposited by this deadline, otherwise the contract is cancelled and money is refunded."],["First window beginning","The first _**oracle**_ reading must be taken after this."],["First window deadline","The first _**oracle**_ reading must be taken before this, otherwise the contract is cancelled and money is refunded."],["Second window beginning","The second _**oracle**_ reading must be taken after this."],["Second window deadline","The second _**oracle**_ reading must be taken before this, otherwise the contract is cancelled and money is refunded."]],"roleDescriptions":[["Counterparty","The _**counterparty**_ will get the difference in the price of the asset if it increases."],["Party","The _**party**_ will get the difference in the price of the asset if it decreases."],["kraken","The _**oracle**_ provides the price of the asset at the beginning (first window) and at the end (second window) of the contract (in this case the _**oracle**_ provides the conversion rate between Ada and dollars)."]],"contractType":"ContractForDifferences","contractShortDescription":"Contract For Differences with Oracle. Two parties deposit Ada in a contract and after some time the Ada is redistributed among them depending on the change in price of an asset.","contractName":"CFD with Oracle","contractLongDescription":"At the beginning of the contract, _**party**_ and _**counterparty**_ deposit some Ada in the contract. At the end of the contract, all Ada deposited is redistributed depending on the change in price in dollars of an asset (as reported by the _**oracle**_). The asset in this contract is an amount of Ada. If the price in dollars of the asset increases, the difference goes to _**counterparty**_; if it decreases, the difference goes to _**party**_, up to a maximum of the amount deposited at the beginning.","choiceInfo":[["dir-adausd",{"choiceFormat":{"contents":[8,"ADA/USD"],"tag":"DecimalFormat"},"choiceDescription":"Exchange rate ADA/USD in the first window."}],["inv-adausd",{"choiceFormat":{"contents":[8,"USD/ADA"],"tag":"DecimalFormat"},"choiceDescription":"Exchange rate USD/ADA in the second window."}]]}
When
[Case
(Deposit
(Role "Party")
(Role "Party")
(Token "" "")
(ConstantParam "Amount paid by party")
)
(When
[Case
(Deposit
(Role "Counterparty")
(Role "Counterparty")
(Token "" "")
(ConstantParam "Amount paid by counterparty")
)
(When
[]
(TimeParam "First window beginning")
(When
[Case
(Choice
(ChoiceId
"dir-adausd"
(Role "kraken")
)
[Bound 0 100000000000]
)
(When
[]
(TimeParam "Second window beginning")
(When
[Case
(Choice
(ChoiceId
"inv-adausd"
(Role "kraken")
)
[Bound 0 100000000000]
)
(Let
"Price in second window"
(DivValue
(MulValue
(ConstantParam "Amount of Ada to use as asset")
(MulValue
(ChoiceValue
(ChoiceId
"dir-adausd"
(Role "kraken")
))
(ChoiceValue
(ChoiceId
"inv-adausd"
(Role "kraken")
))
)
)
(Constant 10000000000000000)
)
(If
(ValueGT
(ConstantParam "Amount of Ada to use as asset")
(UseValue "Price in second window")
)
(Let
"Decrease in price"
(SubValue
(ConstantParam "Amount of Ada to use as asset")
(UseValue "Price in second window")
)
(Pay
(Role "Counterparty")
(Account (Role "Party"))
(Token "" "")
(Cond
(ValueLT
(UseValue "Decrease in price")
(ConstantParam "Amount paid by counterparty")
)
(UseValue "Decrease in price")
(ConstantParam "Amount paid by counterparty")
)
Close
)
)
(If
(ValueLT
(ConstantParam "Amount of Ada to use as asset")
(UseValue "Price in second window")
)
(Let
"Increase in price"
(SubValue
(UseValue "Price in second window")
(ConstantParam "Amount of Ada to use as asset")
)
(Pay
(Role "Party")
(Account (Role "Counterparty"))
(Token "" "")
(Cond
(ValueLT
(UseValue "Increase in price")
(ConstantParam "Amount paid by party")
)
(UseValue "Increase in price")
(ConstantParam "Amount paid by party")
)
Close
)
)
Close
)
)
)]
(TimeParam "Second window deadline")
Close
)
)]
(TimeParam "First window deadline")
Close
)
)]
(TimeParam "Counterparty deposit deadline")
Close
)]
(TimeParam "Party deposit deadline")
Close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment