Created
March 12, 2024 06:19
-
-
Save mrtnetwork/0c07a3b0b9d48e8b418d4607e471e0b0 to your computer and use it in GitHub Desktop.
New Project
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 CouponBondGuaranteed where | |
import Language.Marlowe.Extended.V1 | |
main :: IO () | |
main = printJSON cbg | |
-- 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 | |
guarantor, investor, issuer :: Party | |
guarantor = Role "Guarantor" | |
investor = Role "Lender" | |
issuer = Role "Borrower" | |
principal, instalment :: Value | |
principal = ConstantParam "Principal" | |
instalment = ConstantParam "Interest instalment" | |
guaranteedAmount :: Integer -> Value | |
guaranteedAmount instalments = AddValue (MulValue (Constant instalments) instalment) principal | |
lastInstalment :: Value | |
lastInstalment = AddValue instalment principal | |
deposit :: Value -> Party -> Party -> Timeout -> Contract -> Contract -> Contract | |
deposit amount by toAccount timeout timeoutContinuation continuation = | |
When [Case (Deposit toAccount by ada amount) continuation] | |
timeout | |
timeoutContinuation | |
refundGuarantor :: Value -> Contract -> Contract | |
refundGuarantor = Pay investor (Party guarantor) ada | |
transfer :: Value -> Party -> Party -> Timeout -> Contract -> Contract -> Contract | |
transfer amount from to timeout timeoutContinuation continuation = | |
deposit amount from to timeout timeoutContinuation | |
$ Pay to (Party to) ada amount | |
continuation | |
giveCollateralToLender :: Value -> Contract | |
giveCollateralToLender amount | |
| explicitRefunds = Pay investor (Party investor) ada amount Close | |
| otherwise = Close | |
cbg :: Contract | |
cbg = deposit (guaranteedAmount 3) guarantor investor | |
300 Close | |
$ transfer principal investor issuer | |
600 (refundGuarantor (guaranteedAmount 3) Close) | |
$ transfer instalment issuer investor | |
900 (giveCollateralToLender $ guaranteedAmount 3) | |
$ refundGuarantor instalment | |
$ transfer instalment issuer investor | |
1200 (giveCollateralToLender $ guaranteedAmount 2) | |
$ refundGuarantor instalment | |
$ transfer lastInstalment issuer investor | |
1500 (giveCollateralToLender $ guaranteedAmount 1) | |
$ refundGuarantor lastInstalment | |
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":[["Interest instalment",{"valueParameterFormat":{"contents":[6,"₳"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount of Lovelace that will be paid by the _**Borrower**_ every 30 slots for 3 iterations."}],["Principal",{"valueParameterFormat":{"contents":[6,"₳"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount of Lovelace that will be borrowed by the _**Borrower**_."}]],"timeParameterDescriptions":[],"roleDescriptions":[["Borrower","Borrows the money provided by the _**Lender**_ and returns it together with three _**Interest instalment**_s."],["Guarantor","Provides a collateral in case the _**Borrower**_ defaults."],["Lender","Provides the money that the _**Borrower**_ borrows."]],"contractType":"CouponBondGuaranteed","contractShortDescription":"Debt agreement between an _**Lender**_ and an _**Borrower**_ that must be repaid in 3 instalments.","contractName":"Coupon Bond Guaranteed","contractLongDescription":"_**Lender**_ will advance the _**Principal**_ amount at the beginning of the contract, and the _**Borrower**_ will pay back _**Interest instalment**_ every 30 slots and the _**Principal**_ amount by the end of 3 instalments. The debt is backed by a collateral provided by the _**Guarantor**_ which will be refunded as long as the _**Borrower**_ pays back on time.","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