Skip to content

Instantly share code, notes, and snippets.

@MatthewVines
Last active June 24, 2021 18:36
Show Gist options
  • Save MatthewVines/1d2013aa2dcd6cc3a74107c527bc4f4f to your computer and use it in GitHub Desktop.
Save MatthewVines/1d2013aa2dcd6cc3a74107c527bc4f4f to your computer and use it in GitHub Desktop.
AllMarket
{-# LANGUAGE OverloadedStrings #-}
module Example where
import Language.Marlowe.Extended
main :: IO ()
main = print . pretty $ contract
-- Define the parties involved
seller, buyer, arbiter, market :: Party
buyer = Role "Buyer"
seller = Role "Seller"
arbiter = Role "Arbiter"
market = Role "Market"
-- Define the amounts neccessary to operate the contract
price, arbiterFee, arbiterStake, marketFee :: Value
price = ConstantParam "Price"
arbiterFee = ConstantParam "ArbiterFee"
arbiterStake = ConstantParam "ArbiterStake"
marketFee = ConstantParam "MarketFee"
-- price is a Value, not a BigInt, or Number
--marketFee = Constant(price * ".01")
-- Define timeouts used for different phases of the contract
depositTimeout, disputeTimeout, answerTimeout, arbitrageTimeout :: Timeout
depositTimeout = SlotParam "All party's deposit timeout"
disputeTimeout = SlotParam "Buyer's dispute timeout"
answerTimeout = SlotParam "Seller's response timeout"
arbitrageTimeout = SlotParam "Timeout for arbitrage"
choice :: ChoiceName -> Party -> Integer -> Contract -> Case
choice choiceName chooser choiceValue = Case (Choice (ChoiceId choiceName chooser)
[Bound choiceValue choiceValue])
choices :: Timeout -> Party -> Contract -> [(Integer, ChoiceName, Contract)] -> Contract
choices timeout chooser timeoutContinuation list =
When [choice choiceName chooser choiceValue continuation
| (choiceValue, choiceName, continuation) <- list]
timeout
timeoutContinuation
-- Deposit(To:party, From:party, token:token, value:value)
deposit :: Party -> Party -> Value -> Timeout -> Contract -> Contract -> Contract
deposit to from amount timeout timeoutContinuation continuation =
When [Case (Deposit to from ada amount) continuation]
timeout
timeoutContinuation
{- Define a contract, Close is the simplest contract which just ends the contract straight away
-}
contract :: Contract
contract = Close
{"valueParameterDescriptions":[],"slotParameterDescriptions":[],"roleDescriptions":[],"contractType":"O","contractName":"","contractDescription":"","choiceDescriptions":[]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment