Created
September 20, 2022 23:14
-
-
Save sergioceron/56f571c08309e3bc7b303a9be538a784 to your computer and use it in GitHub Desktop.
PBG Minting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Swap where | |
import Language.Marlowe.Extended.V1 | |
main :: IO () | |
main = printJSON $ contract | |
-- We can set explicitRefunds True to run Close refund analysis | |
-- but we get a shorter contract if we set it to False | |
explicitRefunds :: Bool | |
explicitRefunds = False | |
lovelacePerAda, amountOfAda, amountOfLovelace, amountOfDollars :: Value | |
lovelacePerAda = Constant 1000000 | |
amountOfAda = ConstantParam "Amount of Ada" | |
amountOfLovelace = MulValue lovelacePerAda amountOfAda | |
amountOfDollars = ConstantParam "Amount of dollars" | |
adaDepositTimeout, dollarDepositTimeout :: Timeout | |
adaDepositTimeout = TimeParam "Timeout for Ada deposit" | |
dollarDepositTimeout = TimeParam "Timeout for dollar deposit" | |
dollars :: Token | |
dollars = Token "85bb65" "dollar" | |
data SwapParty = SwapParty { party :: Party | |
, currency :: Token | |
, amount :: Value | |
} | |
adaProvider, dollarProvider :: SwapParty | |
adaProvider = SwapParty { party = Role "Ada provider" | |
, currency = ada | |
, amount = amountOfLovelace | |
} | |
dollarProvider = SwapParty { party = Role "Dollar provider" | |
, currency = dollars | |
, amount = amountOfDollars | |
} | |
makeDeposit :: SwapParty -> Timeout -> Contract -> Contract -> Contract | |
makeDeposit src timeout timeoutContinuation continuation = | |
When [ Case (Deposit (party src) (party src) (currency src) (amount src)) | |
continuation | |
] timeout | |
timeoutContinuation | |
refundSwapParty :: SwapParty -> Contract | |
refundSwapParty swapParty | |
| explicitRefunds = Pay (party swapParty) (Party (party swapParty)) (currency swapParty) (amount swapParty) Close | |
| otherwise = Close | |
makePayment :: SwapParty -> SwapParty -> Contract -> Contract | |
makePayment src dest = | |
Pay (party src) (Party $ party dest) (currency src) (amount src) | |
contract :: Contract | |
contract = makeDeposit adaProvider adaDepositTimeout Close | |
$ makeDeposit dollarProvider dollarDepositTimeout (refundSwapParty adaProvider) | |
$ makePayment adaProvider dollarProvider | |
$ makePayment dollarProvider adaProvider | |
Close |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"valueParameterInfo":[["Amount of Ada",{"valueParameterFormat":{"contents":[0,"₳"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount of Ada to be exchanged for dollars."}],["Amount of dollars",{"valueParameterFormat":{"contents":[0,"$"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount of dollar tokens to be exchanged for Ada."}]],"timeParameterDescriptions":[["Timeout for Ada deposit","Deadline by which Ada must be deposited."],["Timeout for dollar deposit","Deadline by which dollar tokens must be deposited (must be after the deadline for Ada deposit)."]],"roleDescriptions":[["Ada provider","The party that provides the Ada."],["Dollar provider","The party that provides the dollar tokens."]],"contractType":"Swap","contractShortDescription":"Atomically exchange of Ada and dollar tokens.","contractName":"Swap of Ada and dollar tokens","contractLongDescription":"Waits until one party deposits Ada and the other party deposits dollar tokens. If both parties collaborate it carries the exchange atomically, otherwise parties are refunded.","choiceInfo":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment