Marlowe Pioneer
 
w1202_notify
20220614

Revisited

STUB


TO BE EXPANDED

w0708a_setup
20220727

Useful

Setting up the env

On a linux machine using /u01/marlowe as the root directory of my marlowe installation.

Nix

Setup nix (see https://nix.dev/tutorials/install-nix), and then ensure the nix cache is setup with /etc/nix/nix.conf having these lines:

substituters        = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

(after the change, you may need to restart, if you have a multi-user nix: sudo systemctl restart nix-daemon)

Clone marlowe-cardano from github

Do this only once.

cd /u01/marlowe
git clone https://github.com/input-output-hk/marlowe-cardano.git
cd marlowe-cardano
git checkout marlowe-pioneers
nix-shell

If env already setup

Startup up one terminal for the cardano-node, and (at least) one terminal to execute commands.

Startup the node in one terminal window

cd /u01/marlowe/marlowe-cardano
nix-shell
start-cardano-node 

Startup another terminal to do work in

ssh your_linux_vm 
cd /u01/marlowe/marlowe-cardano
nix-shell

# .. and then 'cd' to your work directory, like this one: 
cd /u01/marlowe/20220727_708_backend
w0708c_notify
20220806

Running a simple Marlowe contract (without the backend)

This page describes the execution on marlowe testnet of the same contract as in Brian W Bush’s lecture 5 (see: github.com .. lectures/05-marlowe-cli-pab.ipynb) but then without using the backend, just using marlowe-cli and cardano-cli.

Cli commands used (in alphabetical order):

cardano-cli address build 
cardano-cli key convert-cardano-address-key 
cardano-cli key verification-key 
cardano-cli query utxo 

marlowe-cli run execute 
marlowe-cli run initialize 
marlowe-cli run prepare --deposit-..
marlowe-cli run prepare --notify 
marlowe-cli run withdraw 
marlowe-cli util mint 

Setting up the env

A cardano node needs to be running in the background: start-cardano-node in a nix shell, for detailed info see w0708a, with these environment variables:

export CARDANO_NODE_SOCKET_PATH=/tmp/node.socket
export CARDANO_TESTNET_MAGIC=1567

Overview

A summary of the steps taken:

  • prepare (create key, mint tokens, create contract)
  • tx: initialize the contract
  • tx: fund the contract
  • tx: notify
  • tx: withdraw

There is only one role, and that is the ‘actor’, with role AC (hex: 41 43).

Scripts

The scripts: scripts_708c.zip, my ref: daedtest:/u01/marlowe/20220802_redo_notify.

Filenames starting with an even number are the scripts, odd filenames are the inputs/outputs of the scripts.

00_setenv.sh

02_create_keys.sh
04_fund_actor.sh
06_mint_tokens.sh
        07_out.txt
08_create_contract.sh
        09_contract.json
        09_state.json
10_prepare_initialization.sh
        11_marlowe.json
12_execute_initialization.sh
        13_raw.json
14_prepare_fund.sh
        15_marlowe.json
16_execute_fund.sh
        17_raw.json
18_prepare_notify.sh
        19_marlowe.json
20_execute_notify.sh
        21_raw.json
22_withdraw.sh
        23_raw.json

Script 00_setenv.sh must be adapted by the executor along the way (eg enter POLICY_ID, CONTRACT_ADDRESS, PAYOUT_ADDRESS), and will be executed by every script (not shown in the text here).

00 Environment variables

Script: 00_setenv.sh

02 Create actor keys/address and fund it

Actor address (and keys) are created using script 02_create_keys.sh. Put some ADA (eg 100) into it.


    addr_test1vpe789twz302sgyat5jvmhgtxmtzj27ejdjpgtt6rkwz2usyyrwyc
    

    battle absorb easy cousin ability pave fence cousin orbit sense impact scale helmet .. rest omitted ..
    

    {
        "type": "PaymentExtendedSigningKeyShelley_ed25519_bip32",
        "description": "",
        "cborHex": "5880287226c6069313a3dab7d8983236⋯⋯₂₆₀⋯⋯2c86b4c665969213e5519072b1434dbb"
    }
        

    {
        "type": "PaymentExtendedVerificationKeyShelley_ed25519_bip32",
        "description": "",
        "cborHex": "58401e8fbc5c48e356152f6a42034495⋯⋯₁₃₂⋯⋯2c86b4c665969213e5519072b1434dbb"
    }
        

Balance:

Sat Aug  6 07:30:50 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                       
--------------------------------------------------------------------------------------
f261⋯d997  1     100.00 ADA + TxOutDatumNone  

:   LEGEND
:   f261⋯d997  → f2617fb1e0555ca5dc5905d18521fdd19ff3d3d52459a882408e1e970488d997

06 Mint the tokens

Script: 06_mint_tokens.sh

Output. Put this ID in 00_setenv.sh

PolicyID "82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88"

Out-file: 07_out.txt

Balance:

Sat Aug  6 07:35:36 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  0     89.83 ADA + TxOutDatumNone                     
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88

08 Create the contract

Script: 08_create_contract.sh

Two files created:

  • 09_contract.json
  • 09_state.json

10 Prepare the initialization

Script 10_prepare_initialization.sh

marlowe-cli run initialize --roles-currency "$POLICY_ID"    \
                           --contract-file 09_contract.json \
                           --state-file    09_state.json    \
                           --out-file      11_marlowe.json  \
                           --print-stats

Output:

Validator size: 12415
Base-validator cost: ExBudget {exBudgetCPU = ExCPU 24652144, exBudgetMemory = ExMemory 82900}

This produces the contract in file 11_marlowe.json, from which we pick up the contract address (marloweValidator) and payout address (rolesValidator):

Edit the 00_setenv.sh script, and put the following values for variables CONTRACT_ADDRESS and PAYOUT_ADDRESS respectively:

jq -r '.marloweValidator.address' 11_marlowe.json
jq -r '.rolesValidator.address' 11_marlowe.json

12 Execute initialization

Balance:

Sat Aug  6 07:58:36 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  0     89.83 ADA + TxOutDatumNone                     
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  

:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88

Script 12_execute_initialization.sh:

marlowe-cli run execute --tx-in "0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f#0" \
                        --change-address "$ACTOR_ADDRESS"                                            \
                        --required-signer actor.skey                                                 \
                        --marlowe-out-file 11_marlowe.json                                           \
                        --out-file 13_raw.json                                                       \
                        --print-stats                                                                \
                        --submit=600

Output:

Fee: Lovelace 181605
Size: 353 / 32768 = 1%
Execution units:
  Memory: 0 / 30000000 = 0%
  Steps: 0 / 10000000000 = 0%
TxId "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68"

Balance:

Sat Aug  6 07:59:45 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  
1ff7⋯bc68  0     87.65 ADA + TxOutDatumNone                     


--- CONTRACT ---
TxHash     TxIx  Amount                                                       
--------------------------------------------------------------------------------------
1ff7⋯bc68  1     2.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "b4d1⋯3458"  


--- PAYOUT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------



:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   1ff7⋯bc68  → 1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68
:   b4d1⋯3458  → b4d11d73a97a90b99c62dad772a1048dffb7fd9eacf67d10d5b10f6c530f3458

14 Prepare fund

Script 14_prepare_fund.sh

marlowe-cli run prepare --marlowe-file 11_marlowe.json \
                        --deposit-account "Role=AC" \
                        --deposit-party "Role=AC"    \
                        --deposit-amount "$AMT"             \
                        --invalid-before "$NOW"               \
                        --invalid-hereafter "$((NOW+2*HOUR))" \
                        --out-file 15_marlowe.json \
                        --print-stats

Output:

Datum size: 75

16 Execute fund

Balance before:

Sat Aug  6 08:16:30 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  
1ff7⋯bc68  0     87.65 ADA + TxOutDatumNone                     


--- CONTRACT ---
TxHash     TxIx  Amount                                                       
--------------------------------------------------------------------------------------
1ff7⋯bc68  1     2.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "b4d1⋯3458"  


:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   1ff7⋯bc68  → 1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68
:   b4d1⋯3458  → b4d11d73a97a90b99c62dad772a1048dffb7fd9eacf67d10d5b10f6c530f3458

Script 16_execute_fund.sh

marlowe-cli run execute --marlowe-in-file 11_marlowe.json                                                       \
                        --marlowe-out-file 15_marlowe.json                                                      \
                        --required-signer actor.skey                                                            \
                        --tx-in-marlowe "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68#1"    \
                        --tx-in-collateral "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68#0" \
                        --tx-in "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68#0"            \
                        --tx-in "0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f#1"            \
                        --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"                                   \
                        --change-address "$ACTOR_ADDRESS"                                                       \
                        --out-file 17_raw.json                                                                  \
                        --print-stats                                                                           \
                        --submit=600

Output:

Fee: Lovelace 1163485
Size: 13091 / 32768 = 39%
Execution units:
  Memory: 5025830 / 30000000 = 16%
  Steps: 1698217004 / 10000000000 = 16%
TxId "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417"

Balance after:

Sat Aug  6 08:33:15 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                        
--------------------------------------------------------------------------------------
b0d8⋯d417  0     79.48 ADA + TxOutDatumNone                    
b0d8⋯d417  2     2.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


--- CONTRACT ---
TxHash     TxIx  Amount                                                        
--------------------------------------------------------------------------------------
b0d8⋯d417  1     17.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "8c41⋯ac92"  


:   LEGEND
:   b0d8⋯d417  → b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   8c41⋯ac92  → 8c41853425fc656af21606df26098e9439d6da12ed574773e2629313ac5cac92

18 Prepare notify

Script 18_prepare_notify.sh

marlowe-cli run prepare --marlowe-file 15_marlowe.json        \
                        --notify                              \
                        --invalid-before "$NOW"               \
                        --invalid-hereafter "$((NOW+3*HOUR))" \
                        --out-file 19_marlowe.json            \
                        --print-stats

Output:

Datum size: 23
Payment 1
  Acccount: "AC"
  Payee: Party "AC"
  Ada: 17.000000

20 Execute notify

bash 20_execute_notify.sh

marlowe-cli run execute --marlowe-in-file 15_marlowe.json                                                       \
                        --marlowe-out-file 19_marlowe.json                                                      \
                        --tx-in-marlowe "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#1"    \
                        --tx-in-collateral "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#0" \
                        --tx-in "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#0"            \
                        --tx-in "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#2"            \
                        --required-signer actor.skey                                                            \
                        --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"                                   \
                        --change-address "$ACTOR_ADDRESS"                                                       \
                        --out-file 21_raw.json                                                                  \
                        --print-stats                                                                           \
                        --submit=600

Output:

Fee: Lovelace 933056
Size: 12946 / 32768 = 39%
Execution units:
  Memory: 2242078 / 30000000 = 7%
  Steps: 818511856 / 10000000000 = 8%
TxId "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3"

Balance after execution:

Sat Aug  6 09:24:41 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                        
--------------------------------------------------------------------------------------
46ed⋯5bc3  0     78.55 ADA + TxOutDatumNone                    
46ed⋯5bc3  2     2.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


--- CONTRACT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------


--- PAYOUT ---
TxHash     TxIx  Amount                                                        
--------------------------------------------------------------------------------------
46ed⋯5bc3  1     17.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "8b60⋯68ee"  


:   LEGEND
:   46ed⋯5bc3  → 46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   8b60⋯68ee  → 8b604460b567ff3433b5ad7c74cf317c7b6b4d1152f3c4b0f6a025b3f6d768ee

22 Withdraw

Script 22_withdraw.sh

marlowe-cli run withdraw --marlowe-file 19_marlowe.json                                                          \
                         --role-name "$ACTOR_ROLE"                                                               \
                         --tx-in-collateral "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#0" \
                         --tx-in "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#2"            \
                         --tx-in "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#1"            \
                         --tx-in "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#0"            \
                         --required-signer actor.skey                                                            \
                         --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"                                   \
                         --change-address "$ACTOR_ADDRESS"                                                       \
                         --out-file 23_raw.json                                                                  \
                         --print-stats                                                                           \
                         --submit=600

Output:

Fee: Lovelace 431007
Size: 2885 / 32768 = 8%
Execution units:
  Memory: 1461810 / 30000000 = 4%
  Steps: 557930172 / 10000000000 = 5%
TxId "8f87b5548db95a3ef3238199e20c5768d74b902645d8e242de7a839f33052a9c"

Balance:

Sat Aug  6 09:31:32 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                        
--------------------------------------------------------------------------------------
8f87⋯2a9c  0     78.12 ADA + TxOutDatumNone                    
8f87⋯2a9c  1     17.00 ADA + TxOutDatumNone                    
8f87⋯2a9c  2     2.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


--- CONTRACT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------


--- PAYOUT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------

:   LEGEND
:   8f87⋯2a9c  → 8f87b5548db95a3ef3238199e20c5768d74b902645d8e242de7a839f33052a9c
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88

Bottom line

The contract and payout address are empty now, everything is back on the actor’s address.

Total money in the pocket = 78.12 + 17.00 + 2.0 = 97.12. Since we started out with 100 ADA, running this contract cost us 2.88 ADA.

Post scriptum

This is the way the contract looks in blockly:

.. and in marlowe:

w0800_fan_out fund asnap
20220821

Fund Fan out and in

This page describes using the asnap utility to generate cardano-cli/marlowe-cli scripts. More about asnap can be found on it’s gitlab repo: gitlab.com/wmoco/asnap

The scripts described here are the following:

    1. Fund fan out using cardano-cli
    1. Fund fan out using marlowe-cli
    1. Fund fan in using cardano-cli

Note: fan-out = from 1 to many, fan-in = from many to 1

1. Fund fan out using cardano-cli

Suppose you need to fund 5 address with 50 ADA each, all sent from one ‘fund’ address.

Execute

You’ve created the addresses, and put the following files together in a directory:

 fund.address  fund.seed  fund.skey  fund.vkey  
 x01.address  x02.address  x03.address  x04.address  x05.address 

This is the balance at the start:

Run the fund-fan-out script:

After the script has been run the balance will be this:

That’s it.

Digging a bit deeper.

The core of the template actions are these two snippets:

Snippet #1 :

«range .Alias2AddressMap.fund.TxixList»«if .FlagGreatestPureAda»    --tx-in-collateral «.Txix» \
    --tx-in «.Txix» \
«end»«end»    

Snippet #2:

    --change-address «.Alias2AddressMap.fund.Address» \

When you run the first snippet like this:

$ echo "«range .Alias2AddressMap.fund.TxixList»«if .FlagGreatestPureAda»    --tx-in-collateral «.Txix» \
    --tx-in «.Txix» \
«end»«end»" | asnap - fund.address 

You get this output:

    --tx-in-collateral 31a8a0eb1885768364eff4dd580078219b7500e301ad04f98e3163cdd7275577#0     
    --tx-in 31a8a0eb1885768364eff4dd580078219b7500e301ad04f98e3163cdd7275577#0 

And for the second one:

$ echo "--change-address «.Alias2AddressMap.fund.Address» " | asnap - fund 

.. you get:

--change-address addr_test1vr0sqeu2knafkesjhvjmzvqwz07gwqsvtprxvt2s3as3kzgtdzsmj 

And then put together and run with the rest of the script, the output will be :

cardano-cli transaction build --testnet-magic 1567     
    --tx-in-collateral f61f38bca59200aace1a20fd2447935a2906baafad470186e48e838c73926bfe#0     
    --tx-in f61f38bca59200aace1a20fd2447935a2906baafad470186e48e838c73926bfe#0 
    --tx-out "addr_test1vq6szstpj6fywjqgq66mqe405283ldyptdkxqqc2yg0t9dccq80ze + 50000000 lovelace" 
    --change-address addr_test1vr0sqeu2knafkesjhvjmzvqwz07gwqsvtprxvt2s3as3kzgtdzsmj 
    --protocol-params-file protocol-parameters.json
    --out-file unsigned.json

cardano-cli transaction sign --testnet-magic 1567     
    --tx-body-file unsigned.json     
    --signing-key-file fund.skey     
    --out-file signed.json

cardano-cli transaction submit --testnet-magic 1567 --tx-file signed.json

(the above script has been redacted for legibility: line-breaks and spacing was added)

2. Fund fan out using marlowe-cli

The downside of the first method is that you have 3 separate transactions. It can also be done in one, when using marlowe-cli transaction simple.

Here’s the script (side-note: to easily differentiate theses tx’s we just transfer 49 ADA instead of 50)

The instantiated command looked like this:

Resulting in this output ..

TxId "a47c70ad38c2f9b58213a8f798ff11bfbac3c369d69391ad1b1dd4856cf219db"

.. and this balance:

3. Fund fan in using cardano-cli

What happened? I accidentally executed a fan-out twice, from fund to mediator, buyer, seller. And now I want to put half (ie. 100 ADA each) back into the fund.

Before situation

The script

After situation

w0708d_notify asnap
20220824

Running a simple Marlowe contract (without the backend)

This page describes how to use the asnap utility to generate cardano-cli / marlowe-cli scripts. More about asnap can be found on its gitlab repo: gitlab.com/wmoco/asnap

The execution of contract here is close to the one described on w0708c_notify, but it is fully automated, and will keep on running (creating a new contract, initializing, funding… etc.) until the balance drops below a certain value.

Only the noteworthy changes are mentioned.

The new script 50_loop.sh iterates over the other scripts like this:

forever  
do
    08_create_contract.sh

    10_prepare_initialization.sh
    12_execute_initialization.sh

    14_prepare_fund.sh
    16_execute_fund.sh

    18_prepare_notify.sh
    20_execute_notify.sh

    22_withdraw.sh

    BALANCE=`echo '«printf "%.f" .AggregateAda»' | asnap - actor.address`

    .. exit if BALANCE < x ADA .. 
done

The scripts

All scripts can be found in this zip-file: scripts_708d.zip. You also find the log file ‘example_tx.log’ of a run of 181 iterations, to show that it doesn’t just break after 3 iterations.

00 Set env

Changes:

  • environment variable POLICY_ID is read from file ‘policy_id.txt’ (file created in step 06_mint_tokens.sh)
  • same for CONTRACT_ADDRESS and PAYOUT_ADDRESS (files contract.address and payout.address are created in step 10_prepare_initialization.sh)

06 Mint the tokens

Script: 06_mint_tokens.sh is mostly the same, except for how the policy_id gets looked up, it’s now a query via asnap:

10 Prepare the initialization

Different way of picking up the contract and payout address, using jq :

12 Execute initialization

Pick up the actor’s transaction which has the greatest amount of pure ADA (no token nor datumhash):

16 Execute fund

Asnap template used to list the parameters for –tx-in-collateral, –tx-in-marlowe and –tx-in

Note ‘EOTX’ is in single quotes, so that the dollar-variables don’t get expanded in this here-document.

The «range ..» loops are pretty self-explanatory except maybe the --tx-in-marlowe which could do with a bit more explanation. Here is that bit of template code put separately:

«range .Alias2AddressMap.actor.TxixList»
    «$actorTx := .Tx»
    «range $.Alias2AddressMap.contract.TxixList»
        «if .DatumHash»«if eq $actorTx .Tx»   --tx-in-marlowe «.Txix» \
    «end»
«end»
«end»

To make sure that we talk about the same thing:

  • a Txix is this “104a836fe33a3d6d44d1328b8ec1f8edf6c8bda2bb915c1b4e6ffc761966fc57#2”
  • its Tx is “104a836fe33a3d6d44d1328b8ec1f8edf6c8bda2bb915c1b4e6ffc761966fc57”
  • its Ix is “2”

To find the marlowe-txix we loop over the actor.txix’s, and in a nested loop go over the contract’s txix’s to find the common .tx. Extra condition: the contract’s txix must have a datumhash.

18 Prepare notify

No change.

20 Execute notify

cat <<'EOTX' | asnap - actor.address  contract.address > execute_tx.sh
. ./00_setenv.sh

marlowe-cli run execute --submit=600 \
  --marlowe-in-file 15_marlowe.json                                                       \
  --marlowe-out-file 19_marlowe.json                                                      \
  --required-signer actor.skey       \
«range .Alias2AddressMap.actor.TxixList»«if .FlagGreatestPureAda»  --tx-in-collateral «.Txix» \
«end»«end»«range .Alias2AddressMap.actor.TxixList»«if gt .AggregateTokenQuantity 0»«$actorTx := .Tx»«range $.Alias2AddressMap.contract.TxixList»«if .DatumHash»«if eq $actorTx .Tx»  --tx-in-marlowe «.Txix» \
«end»«end»«end»«end»«end»«range .Alias2AddressMap.actor.TxixList»  --tx-in «.Txix» \
«end»  --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"  \
  --change-address "$ACTOR_ADDRESS"  \
  --out-file 21_raw.json \
  --print-stats  
EOTX

22 Withdraw

cat <<EOTX | asnap - actor.address payout.address > execute_tx.sh
. ./00_setenv.sh

marlowe-cli run withdraw --submit=600 \
  --marlowe-file 19_marlowe.json     \
  --role-name "$ACTOR_ROLE"          \
  --required-signer actor.skey       \
«range .Alias2AddressMap.actor.TxixList»«if .FlagGreatestPureAda»  --tx-in-collateral «.Txix» \
«end»«end»«range .Alias2AddressMap.payout.TxixList»  --tx-in «.Txix» \
«end»«range .Alias2AddressMap.actor.TxixList»  --tx-in «.Txix» \
«end»  --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"  \
  --change-address "$ACTOR_ADDRESS"  \
  --out-file 23_raw.json \
  --print-stats  
EOTX

50 The loop

A new script is this loop, as mentioned at the beginning of this page.

#!/bin/bash 

rm contract.address payout.address amount.txt

for (( i=1; i <= 1000 ; i=i+1 ))
do
    echo >> tx.log
    echo "Start of iteration : $i ---- `date '+%Y%m%d-%Hh%M'`"  | tee -a tx.log

    echo "--- 08_create_contract.sh -------------------------------------------" | tee -a tx.log
    bash 08_create_contract.sh

    echo "--- 10_prepare_initialization.sh ------------------------------------" | tee -a tx.log
    bash 10_prepare_initialization.sh
    asnap actor.address contract.address payout.address | tee -a tx.log

    echo "--- 12_execute_initialization.sh ------------------------------------" | tee -a tx.log
    bash 12_execute_initialization.sh
    sleep 60
    asnap actor.address contract.address payout.address | tee -a tx.log

    echo "--- 14_prepare_fund.sh ----------------------------------------------" | tee -a tx.log
    bash 14_prepare_fund.sh

    echo "--- 16_execute_fund.sh ----------------------------------------------" | tee -a tx.log
    bash 16_execute_fund.sh
    sleep 60
    asnap actor.address contract.address payout.address | tee -a tx.log

    echo "--- 18_prepare_notify.sh --------------------------------------------" | tee -a tx.log
    bash 18_prepare_notify.sh

    echo "--- 20_execute_notify.sh --------------------------------------------" | tee -a tx.log
    bash 20_execute_notify.sh
    sleep 60
    asnap actor.address contract.address payout.address | tee -a tx.log

    echo "--- 22_withdraw.sh --------------------------------------------------" | tee -a tx.log
    bash 22_withdraw.sh
    sleep 60
    asnap actor.address contract.address payout.address | tee -a tx.log

    BALANCE=`echo '«printf "%.f" .AggregateAda»' | asnap - actor.address`
    echo "End of iteration $i ---- `date '+%Y%m%d-%Hh%M'` -- balance=$BALANCE " | tee -a tx.log
    echo >> tx.log

    if [ $BALANCE -lt 20 ]
    then
        echo "Bailing out after $i iterations, balance = $BALANCE"
        exit 0
    fi

    # next amount to use is a third of the balance (just for reasons of variety)
    echo $(( $BALANCE / 3 ))"000000" > amount.txt
done
w0801_escrow asnap
20220831

The escrow contract

This page is a report on the scripted implementation of the marlowe escrow contract. The first section is for reading, the rest (the sources of all scripts) are for reference.

Every transition from one state to the next corresponds to the execution of one or more scripts. Eg. when the seller disputes the problem, this corresponds to executing script: 404_seller_disputes.sh

Each and every flow is implemented except for flow 100 -> 270, where the buyer doesn’t deposit, and the mediator tries to get his funds back after the deadline passed: I’ll look later if I can get it to work.

Scripts

  • Here is a zip with the scripts and other data: scripts_801.zip.
  • Look at the files in the ‘core’ directory in the zip-file. These scripts are also documented in the 2nd half of this page.

Notes

  • The price of the item bought/sold is 100 ADA.
  • Short deadlines: to be able to test the ‘deadline passed’ flows, the deadlines are set at 15 .. 18 minutes in the future. The ‘red’ squares in above diagram all have a deadline in their flow. (these take long to execute, because of waiting 20min for the deadlines to pass).
  • A release request is the transaction that moves the funds from the contract to the payout address after deadline expiry
  • In case you want to execute the scripts: at the starting point the buyer, mediator, and seller addresses are expected to have been created, the tokens (BUY, MED,and SEL) minted and distributed. Those scripts are not included.
  • A python script (which uses pandas) is used for computing the balance (install on linux with: apt-get install python3-pandas), but this is not needed for core execution.
  • The tool used for querying the blockchain is asnap, this is its gitlab repo: gitlab.com/wmoco/asnap (also see: usage and advanced_usage ). If you want to execute the scripts, you’ll need at least version v0.1.2 of asnap. Install it like this: go install gitlab.com/wmoco/asnap@v0.1.2.

Report

  • Following is a generated report, which details the scripts that are executed in each flow, and what the before/after balance difference (ADA) is for buyer, seller, mediator after execution.
  • The most expensive flow (highest cost) is flow550.sh which costs 6.26 ADA.
  • The flows are numbered according to the end-state, eg. Flow 550 is from “100-start” to “550-end”.

flow330.sh

102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
302_buyer_approves.sh
322_seller_withdraws.sh
324_mediator_withdraws.sh

Difference before/after execution

    ALIAS        DIFF
    buyer -102.532313
 mediator   -0.657771
   seller   99.579051
    TOTAL   -3.611033

flow430.sh

102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
402_seller_confirms.sh
422_buyer_withdraws.sh
424_mediator_withdraws.sh

Difference before/after execution

    ALIAS      DIFF
    buyer -3.083517
 mediator -0.653429
   seller -1.195388
    TOTAL -4.932334

flow530.sh

102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
404_seller_disputes.sh
502_mediator_confirms.sh
522_buyer_withdraws.sh
524_mediator_withdraws.sh

Difference before/after execution

    ALIAS      DIFF
    buyer -3.079175
 mediator -1.808434
   seller -1.301125
    TOTAL -6.188734

flow550.sh

102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
404_seller_disputes.sh
504_mediator_dismisses.sh
542_seller_withdraws.sh
544_mediator_withdraws.sh

Difference before/after execution

    ALIAS        DIFF
    buyer -102.709091
 mediator   -1.892715
   seller   98.341982
    TOTAL   -6.259824

flow370_deadline.sh

102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
# BUYER DEPOSITS, BUT DOESN'T EVALUATE. SLEEP UNTIL PAYMENT DEADLINE PASSED  -> 20min 
echo "Sleeping for 20 minutes, until deadlines have passed"
sleep 1200
echo "Awake again ... at `date "+%a %Hh%M"` " 
306_seller_requests_release.sh  
362_seller_withdraws.sh  
364_mediator_withdraws.sh

Difference before/after execution

    ALIAS        DIFF
    buyer -101.349774
 mediator   -0.653429
   seller   98.478028
    TOTAL   -3.525175

flow470_deadline.sh

102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
# SELLER DOESN'T CONFIRM NOR DISPUTE , SLEEP UNTIL PAYMENT DEADLINE PASSED  -> 20min 
echo "Sleeping for 20 minutes, until deadlines have passed"
sleep 1200
echo "Awake again ... at `date "+%a %Hh%M"` " 
406_buyer_requests_release.sh 
462_buyer_withdraws.sh  
464_mediator_withdraws.sh 

Difference before/after execution

    ALIAS      DIFF
    buyer -4.143685
 mediator -0.657771
   seller  0.000000
    TOTAL -4.801456

flow570_deadline.sh

102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
404_seller_disputes.sh
# MEDIATOR DOESN'T DISMISS NOR CONFIRMS, SLEEP UNTIL PAYMENT DEADLINE PASSED  -> 20min 
echo "Sleeping for 20 minutes, until deadlines have passed"
sleep 1200
echo "Awake again ... at `date "+%a %Hh%M"` " 
506_buyer_requests_release.sh  
562_buyer_withdraws.sh  
564_mediator_withdraws.sh

# Note: I tried first to run seller withdraw, but that didn't work, it should be the buyer withdrawing
# The 562_seller_withdraws.sh  gave this error: 
# TxBodyErrorMinUTxONotMet (TxOutInAnyEra AlonzoEra (TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEraAlonzo) 
# (ShelleyAddress Testnet (KeyHashObj (KeyHash "d70c3139e3c5f4c90c52f78829c57b0044dd3566f753b62e0509f75a")) StakeRefNull)) 
# (TxOutValue MultiAssetInAlonzoEra (valueFromList [])) TxOutDatumNone)) (Lovelace 999978)

Difference before/after execution

    ALIAS      DIFF
    buyer -4.190786
 mediator -0.647625
   seller -1.301125
    TOTAL -6.139536

All the scripts

000_setenv.sh

#!/bin/bash 

#----------------------------------------------------------------------
# --- general ---
export MINIMUM_ADA=2000000              # the minimum lovelace to be included with native token ouptut.
export INITIAL_LOVELACE=3000000         # the creation transaction will deposit 3₳.
export PRICE=100000000                  # the price of the item is 100₳.

# time to sleep AFTER the tx, before querying the blockchain 
export SLEEPTIME=15

#----------------------------------------------------------------------
# --- the mediator, buyer and seller ---
if [ ! -e mediator.address ]; then
    echo "mediator.address doesn't exist"
    exit 1
fi
export MEDIATOR_ADDRESS=$(cat mediator.address)

if [ ! -e buyer.address ]; then
    echo "buyer.address doesn't exist"
    exit 1
fi
export BUYER_ADDRESS=$(cat buyer.address)

if [ ! -e seller.address ]; then
    echo "seller.address doesn't exist"
    exit 1
fi
export SELLER_ADDRESS=$(cat seller.address)

export MEDIATOR_ROLE='MED'
export BUYER_ROLE='BUY'
export SELLER_ROLE='SEL'

# Token in HEX:
# MED = 4D 45 44
# BUY = 42 55 59
# SEL= 53 45 4C

#----------------------------------------------------------------------
# --- policy aka currency ---
export POLICY_ID=""
export MEDIATOR_TOKEN=""
export BUYER_TOKEN=""
export SELLER_TOKEN=""

if [ -f policy_id.txt ] 
then 
    export POLICY_ID=$(cat policy_id.txt)
    export MEDIATOR_TOKEN="${POLICY_ID}.${MEDIATOR_ROLE}"
    export BUYER_TOKEN="${POLICY_ID}.${BUYER_ROLE}"
    export SELLER_TOKEN="${POLICY_ID}.${SELLER_ROLE}"
fi

#----------------------------------------------------------------------
# --- contract and payout addressess and tx'es ---
export CONTRACT_ADDRESS=""
if [ -f contract.address ] ; then 
    export CONTRACT_ADDRESS=$(cat contract.address)
fi

export PAYOUT_ADDRESS=""
if [ -f payout.address ];  then 
    export PAYOUT_ADDRESS=$(cat payout.address)
fi

# watchout: tx without the ix!!
export CONTRACT_TX=""
if [ -f contract_tx.txt ] ; then 
    export CONTRACT_TX=$(cat contract_tx.txt)
fi

# watchout: tx without the ix!!
export PAYOUT_TX=""
if [ -f payout_tx.txt ] ; then 
    export PAYOUT_TX=$(cat payout_tx.txt)
fi

010_clean_for_collateral.sh

102_create_escrow_contract.sh

#!/bin/bash 
echo 
echo "--- `date "+%a %Hh%M"`: $0 ----------------------------------------------------------------------"
. ./000_setenv.sh

# first instantiate the deadlines, then load the envir variables via the ./00_setenv.sh
export NOW=$(($(date -u +%s)*1000))         # The current time in POSIX milliseconds.
export HOUR=$((60*60*1000))                 # One hour, in POSIX milliseconds.
export QUARTER=$((15*60*1000))              # One hour, in POSIX milliseconds.
export MINUTE=$((60*1000))              # One hour, in POSIX milliseconds.

# short deadline!
export PAYMENT_DEADLINE=$((NOW+QUARTER)) 
export COMPLAINT_DEADLINE=$((NOW+QUARTER+MINUTE)) 
export DISPUTE_DEADLINE=$((NOW+QUARTER+2*MINUTE)) 
export MEDIATION_DEADLINE=$((NOW+QUARTER+3*MINUTE))

marlowe-cli template escrow --minimum-ada "$INITIAL_LOVELACE"          \
                            --price "$PRICE"                           \
                            --seller "Role=$SELLER_ROLE"               \
                            --buyer "Role=$BUYER_ROLE"                 \
                            --mediator "Role=$MEDIATOR_ROLE"           \
                            --payment-deadline "$PAYMENT_DEADLINE"     \
                            --complaint-deadline "$COMPLAINT_DEADLINE" \
                            --dispute-deadline "$DISPUTE_DEADLINE"     \
                            --mediation-deadline "$MEDIATION_DEADLINE" \
                            --out-contract-file 103_contract.json   \
                            --out-state-file    103_state.json 


# from the contract and state file, produce a marlowe file
marlowe-cli run initialize --roles-currency "$POLICY_ID"     \
                           --contract-file 103_contract.json     \
                           --state-file    103_state.json     \
                           --out-file      103_marlowe.json   \
                           --print-stats

jq -r '.marloweValidator.address' 103_marlowe.json > contract.address
jq -r '.rolesValidator.address' 103_marlowe.json > payout.address


asnap -t dev mediator.address buyer.address seller.address contract.address payout.address > 103_snap.txt  

104_mediator_funds_contract.sh

202_buyer_deposits.sh

206_mediator_requests_release.sh

262_mediator_withdraws.sh

302_buyer_approves.sh

304_buyer_objects.sh

306_seller_requests_release.sh

322_seller_withdraws.sh

324_mediator_withdraws.sh

362_seller_withdraws.sh

364_mediator_withdraws.sh

402_seller_confirms.sh

404_seller_disputes.sh

406_buyer_requests_release.sh

422_buyer_withdraws.sh

424_mediator_withdraws.sh

462_buyer_withdraws.sh

464_mediator_withdraws.sh

502_mediator_confirms.sh

504_mediator_dismisses.sh

506_buyer_requests_release.sh

522_buyer_withdraws.sh

524_mediator_withdraws.sh

542_seller_withdraws.sh

544_mediator_withdraws.sh

562_buyer_withdraws.sh

564_mediator_withdraws.sh

w0802f_cbg
20220924

The Coupon Bond Guaranteed contract as-is

The run that fails

This is the run with the unmodified contract (or original contract), as described on w0802_cbg

My ref: output of a run of the scripts in daedtest:~/work/20220923_marlowe_gcb_take4

export FUND_CONTRACT=3000000                    # the amount to fund the contract with 
export MINIMUM_ADA=2000000                      # the minimum lovelace to be included with native token output.

export PRINCIPAL_AMOUNT=50000000                # the principal is 50₳
export INTEREST_INSTALLMENT=4000000             # the interest is 4₳

The overall result, comparing before/after run:

======================================
     ALIAS    START   CHANGE      END
    lender   100.00   -47.56    52.44
  borrower   100.00    38.37   138.37
 guarantor   100.00   -56.27    43.73
  contract             57.00    57.00
    payout                           
     TOTAL   300.00    -8.47   291.53
======================================

Note: the run failed in step 402, and there is a balance remaining in the contract.

The details

104_lender_funds_contract.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender    -3.21    96.79
  borrower            100.00
 guarantor            100.00
  contract     3.00     3.00
    payout                  
     TOTAL    -0.21   299.79
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    96.79 |
* 4a2ead9b75abba50f177dc3c71d4319b23c7ec953d2bfb1a96c87c523240d490#1    | +     2.00 | [ "Lender"×1 ]
* 5fa298efbcc819217eb984df7ecc878e74e075647697e5dc4f072a82c5f97095#0    | +    92.60 | Greatest Pure Ada
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   100.00 |
* 72e37e37f34f00b51f811c7f79c4a5aa6439e48369a5be61cda5f509f16f830f#0    | +    95.81 | Greatest Pure Ada
* 72e37e37f34f00b51f811c7f79c4a5aa6439e48369a5be61cda5f509f16f830f#1    | +     2.00 | [ "Borrower"×1 ]
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =   100.00 |
* 7c7bbd8fd032eb600c3e676297b9373a40f18b41be0be87c34aa892de20956f8#0    | +    95.81 | Greatest Pure Ada
* 7c7bbd8fd032eb600c3e676297b9373a40f18b41be0be87c34aa892de20956f8#1    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =     3.00 |
* 5fa298efbcc819217eb984df7ecc878e74e075647697e5dc4f072a82c5f97095#1    | +     3.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

106_guarantor_deposit.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             96.79
  borrower            100.00
 guarantor   -63.42    36.58
  contract    62.00    65.00
    payout                  
     TOTAL    -1.42   298.36
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    96.79 |
* 4a2ead9b75abba50f177dc3c71d4319b23c7ec953d2bfb1a96c87c523240d490#1    | +     2.00 | [ "Lender"×1 ]
* 5fa298efbcc819217eb984df7ecc878e74e075647697e5dc4f072a82c5f97095#0    | +    92.60 | Greatest Pure Ada
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   100.00 |
* 72e37e37f34f00b51f811c7f79c4a5aa6439e48369a5be61cda5f509f16f830f#0    | +    95.81 | Greatest Pure Ada
* 72e37e37f34f00b51f811c7f79c4a5aa6439e48369a5be61cda5f509f16f830f#1    | +     2.00 | [ "Borrower"×1 ]
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.58 |
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#0    | +    32.39 | Greatest Pure Ada
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    65.00 |
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                65000000
            ]
        ],
        "minTime": 1664092732000 [[2022-09-25 07:58:52 +0000 UTC]]
    },
    "payments": [],
    "contract": {
        "timeout": 1664136515000 [[2022-09-25 20:08:35 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "timeout": 1664140115000 [[2022-09-25 21:08:35 +0000 UTC]],
                        "when": [
                            {
                                "then": {
                                    "then": {
                                        "then": {
                                            "timeout": 1664143715000 [[2022-09-25 22:08:35 +0000 UTC]],
                                            "when": [
                                                {
                                                    "then": {
                                                        "then": {
                                                            "then": {
                                                                "timeout": 1664147315000 [[2022-09-25 23:08:35 +0000 UTC]],
                                                                "when": [
                                                                    {
                                                                        "then": {
                                                                            "then": {
                                                                                "then": "close",
                                                                                "to": {
                                                                                    "party": {
                                                                                        "role_token": "Guarantor"
                                                                                    }
                                                                                },
                                                                                "from_account": {
                                                                                    "role_token": "Lender"
                                                                                },
                                                                                "pay": {
                                                                                    "and": 50000000,
                                                                                    "add": 4000000
                                                                                },
                                                                                "token": {
                                                                                    "currency_symbol": "",
                                                                                    "token_name": ""
                                                                                }
                                                                            },
                                                                            "to": {
                                                                                "party": {
                                                                                    "role_token": "Lender"
                                                                                }
                                                                            },
                                                                            "from_account": {
                                                                                "role_token": "Lender"
                                                                            },
                                                                            "pay": {
                                                                                "and": 50000000,
                                                                                "add": 4000000
                                                                            },
                                                                            "token": {
                                                                                "currency_symbol": "",
                                                                                "token_name": ""
                                                                            }
                                                                        },
                                                                        "case": {
                                                                            "deposits": {
                                                                                "and": 50000000,
                                                                                "add": 4000000
                                                                            },
                                                                            "into_account": {
                                                                                "role_token": "Lender"
                                                                            },
                                                                            "of_token": {
                                                                                "currency_symbol": "",
                                                                                "token_name": ""
                                                                            },
                                                                            "party": {
                                                                                "role_token": "Borrower"
                                                                            }
                                                                        }
                                                                    }
                                                                ],
                                                                "timeout_continuation": "close"
                                                            },
                                                            "to": {
                                                                "party": {
                                                                    "role_token": "Guarantor"
                                                                }
                                                            },
                                                            "from_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "pay": 4000000,
                                                            "token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            }
                                                        },
                                                        "to": {
                                                            "party": {
                                                                "role_token": "Lender"
                                                            }
                                                        },
                                                        "from_account": {
                                                            "role_token": "Lender"
                                                        },
                                                        "pay": 4000000,
                                                        "token": {
                                                            "currency_symbol": "",
                                                            "token_name": ""
                                                        }
                                                    },
                                                    "case": {
                                                        "deposits": 4000000,
                                                        "into_account": {
                                                            "role_token": "Lender"
                                                        },
                                                        "of_token": {
                                                            "currency_symbol": "",
                                                            "token_name": ""
                                                        },
                                                        "party": {
                                                            "role_token": "Borrower"
                                                        }
                                                    }
                                                }
                                            ],
                                            "timeout_continuation": "close"
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Guarantor"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": 4000000,
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "to": {
                                        "party": {
                                            "role_token": "Lender"
                                        }
                                    },
                                    "from_account": {
                                        "role_token": "Lender"
                                    },
                                    "pay": 4000000,
                                    "token": {
                                        "currency_symbol": "",
                                        "token_name": ""
                                    }
                                },
                                "case": {
                                    "deposits": 4000000,
                                    "into_account": {
                                        "role_token": "Lender"
                                    },
                                    "of_token": {
                                        "currency_symbol": "",
                                        "token_name": ""
                                    },
                                    "party": {
                                        "role_token": "Borrower"
                                    }
                                }
                            }
                        ],
                        "timeout_continuation": "close"
                    },
                    "to": {
                        "party": {
                            "role_token": "Borrower"
                        }
                    },
                    "from_account": {
                        "role_token": "Borrower"
                    },
                    "pay": 50000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 50000000,
                    "into_account": {
                        "role_token": "Borrower"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Lender"
                    }
                }
            }
        ],
        "timeout_continuation": {
            "then": "close",
            "to": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "from_account": {
                "role_token": "Lender"
            },
            "pay": {
                "and": 50000000,
                "add": {
                    "multiply": 3,
                    "times": 4000000
                }
            },
            "token": {
                "currency_symbol": "",
                "token_name": ""
            }
        }
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14143101,
        14147301
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Guarantor"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 62000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

108_lender_deposit.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender   -51.50    45.28
  borrower            100.00
 guarantor             36.58
  contract             65.00
    payout    50.00    50.00
     TOTAL    -1.50   296.86
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    45.28 |
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#0    | +    41.10 | Greatest Pure Ada
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#3    | +     2.00 | [ "Lender"×1 ]
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   100.00 |
* 72e37e37f34f00b51f811c7f79c4a5aa6439e48369a5be61cda5f509f16f830f#0    | +    95.81 | Greatest Pure Ada
* 72e37e37f34f00b51f811c7f79c4a5aa6439e48369a5be61cda5f509f16f830f#1    | +     2.00 | [ "Borrower"×1 ]
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.58 |
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#0    | +    32.39 | Greatest Pure Ada
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    65.00 |
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =    50.00 |
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#2    | +    50.00 | GreatestByTxHavingDatum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                65000000
            ]
        ],
        "minTime": 1664092813000 [[2022-09-25 08:00:13 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Borrower"
                }
            },
            "accountId": {
                "role_token": "Borrower"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                50000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664140115000 [[2022-09-25 21:08:35 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": {
                            "timeout": 1664143715000 [[2022-09-25 22:08:35 +0000 UTC]],
                            "when": [
                                {
                                    "then": {
                                        "then": {
                                            "then": {
                                                "timeout": 1664147315000 [[2022-09-25 23:08:35 +0000 UTC]],
                                                "when": [
                                                    {
                                                        "then": {
                                                            "then": {
                                                                "then": "close",
                                                                "to": {
                                                                    "party": {
                                                                        "role_token": "Guarantor"
                                                                    }
                                                                },
                                                                "from_account": {
                                                                    "role_token": "Lender"
                                                                },
                                                                "pay": {
                                                                    "and": 50000000,
                                                                    "add": 4000000
                                                                },
                                                                "token": {
                                                                    "currency_symbol": "",
                                                                    "token_name": ""
                                                                }
                                                            },
                                                            "to": {
                                                                "party": {
                                                                    "role_token": "Lender"
                                                                }
                                                            },
                                                            "from_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "pay": {
                                                                "and": 50000000,
                                                                "add": 4000000
                                                            },
                                                            "token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            }
                                                        },
                                                        "case": {
                                                            "deposits": {
                                                                "and": 50000000,
                                                                "add": 4000000
                                                            },
                                                            "into_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "of_token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            },
                                                            "party": {
                                                                "role_token": "Borrower"
                                                            }
                                                        }
                                                    }
                                                ],
                                                "timeout_continuation": "close"
                                            },
                                            "to": {
                                                "party": {
                                                    "role_token": "Guarantor"
                                                }
                                            },
                                            "from_account": {
                                                "role_token": "Lender"
                                            },
                                            "pay": 4000000,
                                            "token": {
                                                "currency_symbol": "",
                                                "token_name": ""
                                            }
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Lender"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": 4000000,
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "case": {
                                        "deposits": 4000000,
                                        "into_account": {
                                            "role_token": "Lender"
                                        },
                                        "of_token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        },
                                        "party": {
                                            "role_token": "Borrower"
                                        }
                                    }
                                }
                            ],
                            "timeout_continuation": "close"
                        },
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": 4000000,
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": 4000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 4000000,
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14143182,
        14147382
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Lender"
            },
            "into_account": {
                "role_token": "Borrower"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 50000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

110_borrower_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             45.28
  borrower    49.58   149.58
 guarantor             36.58
  contract             65.00
    payout   -50.00         
     TOTAL    -0.42   296.44
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    45.28 |
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#0    | +    41.10 | Greatest Pure Ada
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#3    | +     2.00 | [ "Lender"×1 ]
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   149.58 |
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#0    | +    95.39 | Greatest Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#2    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.58 |
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#0    | +    32.39 | Greatest Pure Ada
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    65.00 |
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

202_borrower_pays_installment1.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             45.28
  borrower    -5.62   143.95
 guarantor             36.58
  contract    -4.00    61.00
    payout     8.00     8.00
     TOTAL    -1.62   294.81
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    45.28 |
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#0    | +    41.10 | Greatest Pure Ada
* 96ad72bd861ec36067082d98c6f8d87bad5b01644a349aa4c4abb5606bf5eff7#3    | +     2.00 | [ "Lender"×1 ]
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   143.95 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#0    | +    89.77 | Greatest Pure Ada
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#4    | +     2.00 | [ "Borrower"×1 ]
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.58 |
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#0    | +    32.39 | Greatest Pure Ada
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    61.00 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     8.00 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#2    | +     4.00 | GreatestByTxHavingDatum
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#3    | +     4.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                61000000
            ]
        ],
        "minTime": 1664092935000 [[2022-09-25 08:02:15 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664143715000 [[2022-09-25 22:08:35 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": {
                            "timeout": 1664147315000 [[2022-09-25 23:08:35 +0000 UTC]],
                            "when": [
                                {
                                    "then": {
                                        "then": {
                                            "then": "close",
                                            "to": {
                                                "party": {
                                                    "role_token": "Guarantor"
                                                }
                                            },
                                            "from_account": {
                                                "role_token": "Lender"
                                            },
                                            "pay": {
                                                "and": 50000000,
                                                "add": 4000000
                                            },
                                            "token": {
                                                "currency_symbol": "",
                                                "token_name": ""
                                            }
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Lender"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": {
                                            "and": 50000000,
                                            "add": 4000000
                                        },
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "case": {
                                        "deposits": {
                                            "and": 50000000,
                                            "add": 4000000
                                        },
                                        "into_account": {
                                            "role_token": "Lender"
                                        },
                                        "of_token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        },
                                        "party": {
                                            "role_token": "Borrower"
                                        }
                                    }
                                }
                            ],
                            "timeout_continuation": "close"
                        },
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": 4000000,
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": 4000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 4000000,
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14143304,
        14147504
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 4000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

204_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender     3.57    48.86
  borrower            143.95
 guarantor             36.58
  contract             61.00
    payout    -4.00     4.00
     TOTAL    -0.43   294.39
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    48.86 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#0    | +    40.67 | Greatest Pure Ada
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#2    | +     2.00 | [ "Lender"×1 ]
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   143.95 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#0    | +    89.77 | Greatest Pure Ada
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#4    | +     2.00 | [ "Borrower"×1 ]
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.58 |
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#0    | +    32.39 | Greatest Pure Ada
* a357d131b9bced4fd21a12276ae9dd3f8c24254da0f494bfa0fe651d613e15d4#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    61.00 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     4.00 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#3    | +     4.00 | GreatestByTxHavingDatum

206_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             48.86
  borrower            143.95
 guarantor     3.57    40.15
  contract             61.00
    payout    -4.00         
     TOTAL    -0.43   293.96
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    48.86 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#0    | +    40.67 | Greatest Pure Ada
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#2    | +     2.00 | [ "Lender"×1 ]
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   143.95 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#0    | +    89.77 | Greatest Pure Ada
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#4    | +     2.00 | [ "Borrower"×1 ]
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    40.15 |
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#0    | +    31.96 | Greatest Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#1    | +     4.00 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    61.00 |
* 6198db3c3ae4ce6f9abc373704a2d90f93bce4907064d8c7a0887207bed3f933#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

302_borrower_pays_installment2.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             48.86
  borrower    -5.58   138.37
 guarantor             40.15
  contract    -4.00    57.00
    payout     8.00     8.00
     TOTAL    -1.58   292.38
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    48.86 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#0    | +    40.67 | Greatest Pure Ada
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#2    | +     2.00 | [ "Lender"×1 ]
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.37 |
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#0    | +    84.18 | Greatest Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    40.15 |
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#0    | +    31.96 | Greatest Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#1    | +     4.00 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     8.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#2    | +     4.00 | GreatestByTxHavingDatum
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#3    | +     4.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                57000000
            ]
        ],
        "minTime": 1664093134000 [[2022-09-25 08:05:34 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664147315000 [[2022-09-25 23:08:35 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": "close",
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": {
                            "and": 50000000,
                            "add": 4000000
                        },
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": {
                        "and": 50000000,
                        "add": 4000000
                    },
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": {
                        "and": 50000000,
                        "add": 4000000
                    },
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14143503,
        14147703
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 4000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

304_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender     3.58    52.44
  borrower            138.37
 guarantor             40.15
  contract             57.00
    payout    -4.00     4.00
     TOTAL    -0.42   291.96
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.44 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#0    | +    40.25 | Greatest Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#1    | +     4.00 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.37 |
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#0    | +    84.18 | Greatest Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    40.15 |
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#0    | +    31.96 | Greatest Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#1    | +     4.00 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     4.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#3    | +     4.00 | GreatestByTxHavingDatum

306_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             52.44
  borrower            138.37
 guarantor     3.58    43.73
  contract             57.00
    payout    -4.00         
     TOTAL    -0.42   291.53
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.44 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#0    | +    40.25 | Greatest Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#1    | +     4.00 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.37 |
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#0    | +    84.18 | Greatest Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    43.73 |
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#0    | +    31.54 | Greatest Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#1    | +     4.00 | Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

402_borrower_pays_installment3.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS CHANGE  BALANCE
    lender           52.44
  borrower          138.37
 guarantor           43.73
  contract           57.00
    payout                
     TOTAL          291.53
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.44 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#0    | +    40.25 | Greatest Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#1    | +     4.00 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.37 |
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#0    | +    84.18 | Greatest Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    43.73 |
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#0    | +    31.54 | Greatest Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#1    | +     4.00 | Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [],
        "minTime": 1664093252000 [[2022-09-25 08:07:32 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                54000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                54000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                3000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": "close",
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14143621,
        14147821
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 54000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

404_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS CHANGE  BALANCE
    lender           52.44
  borrower          138.37
 guarantor           43.73
  contract           57.00
    payout                
     TOTAL          291.53
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.44 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#0    | +    40.25 | Greatest Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#1    | +     4.00 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.37 |
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#0    | +    84.18 | Greatest Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    43.73 |
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#0    | +    31.54 | Greatest Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#1    | +     4.00 | Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

406_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS CHANGE  BALANCE
    lender           52.44
  borrower          138.37
 guarantor           43.73
  contract           57.00
    payout                
     TOTAL          291.53
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.44 |
* 47ce23d37f84dc316da1a883ab86a8590fbb6a53856f899d5108b2a050f49056#1    | +     4.00 | Pure Ada
* c924b52ab95f6fd1027d5adafb4c77680321174ab2d6794fdf730ce04602827a#1    | +     2.19 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#0    | +    40.25 | Greatest Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#1    | +     4.00 | Pure Ada
* f89a73cab8e95f7689c3923f5328dec169f2e1ed3e24f17be15c4c2c29e4d1cc#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.37 |
* 7b0dcb9622720572cfe4919727aabb977a5cdcdfc622c3efc6674f9006d9f8f0#1    | +     2.19 | Pure Ada
* d7a2af0eb80fc72c56574be7efcbc53a6a0b03c21be98037d6fc9578d30ea896#1    | +    50.00 | Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#0    | +    84.18 | Greatest Pure Ada
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    43.73 |
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#0    | +    31.54 | Greatest Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#1    | +     4.00 | Pure Ada
* a1e84aeb927841e1ed9ea9f0db79c059830ffcee0ecb24099fd5e5a9f75be74b#2    | +     2.00 | [ "Guarantor"×1 ]
* c665aefffe5dfffb00d38852aaf218c1df50642aead8c138348afa63989e5932#1    | +     2.19 | Pure Ada
* d0b3028854f8965c88288a431e373cc5d22e6a1eb9bb9444873d7613c8c6ef53#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* fd903facfb5dbf7744112c4d4c089de4aa846a715ec87cb42f3f4e076e576a54#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |
w0802s_cbg
20220924

The Coupon Bond Guaranteed contract, modified

The run that succeeds

This is the run with the modified contract, as described on w0802_cbg

My ref: output of a run of the scripts in daedtest:~/work/20220923_marlowe_gcb_take4

export FUND_CONTRACT=3000000                    # the amount to fund the contract with 
export MINIMUM_ADA=2000000                      # the minimum lovelace to be included with native token output.

export PRINCIPAL_AMOUNT=50000000                # the principal is 50₳
export INTEREST_INSTALLMENT=4000000             # the interest is 4₳

The overall result, comparing before/after run:

======================================
     ALIAS    START   CHANGE      END
    lender   100.00     9.00   109.00
  borrower   100.00   -16.99    83.01
 guarantor   100.00    -2.71    97.29
  contract                           
    payout                           
     TOTAL   300.00   -10.70   289.30
======================================

104_lender_funds_contract.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender    -3.21    96.79
  borrower            100.00
 guarantor            100.00
  contract     3.00     3.00
    payout                  
     TOTAL    -0.21   299.79
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    96.79 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* 664dfcc1c292799eb4893d683d73782cb69e9f358dcb47927e4eaaecbc5ba21b#1    | +     2.00 | [ "Lender"×1 ]
* da4cabbcdb664e1e25f0b76bf27317c31e55421391b6ecb2283fe24ed4c65c29#0    | +    92.61 | Greatest Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   100.00 |
* 3745050644634d83a7514c68c05d40fac9af52f2c2c776fd490f6e78c56c5ae2#0    | +    95.82 | Greatest Pure Ada
* 3745050644634d83a7514c68c05d40fac9af52f2c2c776fd490f6e78c56c5ae2#1    | +     2.00 | [ "Borrower"×1 ]
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =   100.00 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 7903a8a9fa15cbb1104d5746e05bafe731940849de4e04a58c9231edd0a46e3a#0    | +    95.82 | Greatest Pure Ada
* 7903a8a9fa15cbb1104d5746e05bafe731940849de4e04a58c9231edd0a46e3a#1    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =     3.00 |
* da4cabbcdb664e1e25f0b76bf27317c31e55421391b6ecb2283fe24ed4c65c29#1    | +     3.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

106_guarantor_deposit.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             96.79
  borrower            100.00
 guarantor   -63.43    36.57
  contract    62.00    65.00
    payout                  
     TOTAL    -1.43   298.36
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    96.79 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* 664dfcc1c292799eb4893d683d73782cb69e9f358dcb47927e4eaaecbc5ba21b#1    | +     2.00 | [ "Lender"×1 ]
* da4cabbcdb664e1e25f0b76bf27317c31e55421391b6ecb2283fe24ed4c65c29#0    | +    92.61 | Greatest Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   100.00 |
* 3745050644634d83a7514c68c05d40fac9af52f2c2c776fd490f6e78c56c5ae2#0    | +    95.82 | Greatest Pure Ada
* 3745050644634d83a7514c68c05d40fac9af52f2c2c776fd490f6e78c56c5ae2#1    | +     2.00 | [ "Borrower"×1 ]
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.57 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#0    | +    32.39 | Greatest Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    65.00 |
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                65000000
            ]
        ],
        "minTime": 1664089598000 [[2022-09-25 07:06:38 +0000 UTC]]
    },
    "payments": [],
    "contract": {
        "timeout": 1664133376000 [[2022-09-25 19:16:16 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "timeout": 1664136976000 [[2022-09-25 20:16:16 +0000 UTC]],
                        "when": [
                            {
                                "then": {
                                    "then": {
                                        "then": {
                                            "timeout": 1664140576000 [[2022-09-25 21:16:16 +0000 UTC]],
                                            "when": [
                                                {
                                                    "then": {
                                                        "then": {
                                                            "then": {
                                                                "timeout": 1664144176000 [[2022-09-25 22:16:16 +0000 UTC]],
                                                                "when": [
                                                                    {
                                                                        "then": {
                                                                            "then": {
                                                                                "then": "close",
                                                                                "to": {
                                                                                    "party": {
                                                                                        "role_token": "Guarantor"
                                                                                    }
                                                                                },
                                                                                "from_account": {
                                                                                    "role_token": "Lender"
                                                                                },
                                                                                "pay": {
                                                                                    "and": 50000000,
                                                                                    "add": 4000000
                                                                                },
                                                                                "token": {
                                                                                    "currency_symbol": "",
                                                                                    "token_name": ""
                                                                                }
                                                                            },
                                                                            "to": {
                                                                                "party": {
                                                                                    "role_token": "Lender"
                                                                                }
                                                                            },
                                                                            "from_account": {
                                                                                "role_token": "Lender"
                                                                            },
                                                                            "pay": {
                                                                                "and": 3000000,
                                                                                "add": {
                                                                                    "and": 50000000,
                                                                                    "add": 4000000
                                                                                }
                                                                            },
                                                                            "token": {
                                                                                "currency_symbol": "",
                                                                                "token_name": ""
                                                                            }
                                                                        },
                                                                        "case": {
                                                                            "deposits": {
                                                                                "and": 50000000,
                                                                                "add": 4000000
                                                                            },
                                                                            "into_account": {
                                                                                "role_token": "Lender"
                                                                            },
                                                                            "of_token": {
                                                                                "currency_symbol": "",
                                                                                "token_name": ""
                                                                            },
                                                                            "party": {
                                                                                "role_token": "Borrower"
                                                                            }
                                                                        }
                                                                    }
                                                                ],
                                                                "timeout_continuation": "close"
                                                            },
                                                            "to": {
                                                                "party": {
                                                                    "role_token": "Guarantor"
                                                                }
                                                            },
                                                            "from_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "pay": 4000000,
                                                            "token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            }
                                                        },
                                                        "to": {
                                                            "party": {
                                                                "role_token": "Lender"
                                                            }
                                                        },
                                                        "from_account": {
                                                            "role_token": "Lender"
                                                        },
                                                        "pay": 4000000,
                                                        "token": {
                                                            "currency_symbol": "",
                                                            "token_name": ""
                                                        }
                                                    },
                                                    "case": {
                                                        "deposits": 4000000,
                                                        "into_account": {
                                                            "role_token": "Lender"
                                                        },
                                                        "of_token": {
                                                            "currency_symbol": "",
                                                            "token_name": ""
                                                        },
                                                        "party": {
                                                            "role_token": "Borrower"
                                                        }
                                                    }
                                                }
                                            ],
                                            "timeout_continuation": "close"
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Guarantor"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": 4000000,
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "to": {
                                        "party": {
                                            "role_token": "Lender"
                                        }
                                    },
                                    "from_account": {
                                        "role_token": "Lender"
                                    },
                                    "pay": 4000000,
                                    "token": {
                                        "currency_symbol": "",
                                        "token_name": ""
                                    }
                                },
                                "case": {
                                    "deposits": 4000000,
                                    "into_account": {
                                        "role_token": "Lender"
                                    },
                                    "of_token": {
                                        "currency_symbol": "",
                                        "token_name": ""
                                    },
                                    "party": {
                                        "role_token": "Borrower"
                                    }
                                }
                            }
                        ],
                        "timeout_continuation": "close"
                    },
                    "to": {
                        "party": {
                            "role_token": "Borrower"
                        }
                    },
                    "from_account": {
                        "role_token": "Borrower"
                    },
                    "pay": 50000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 50000000,
                    "into_account": {
                        "role_token": "Borrower"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Lender"
                    }
                }
            }
        ],
        "timeout_continuation": {
            "then": "close",
            "to": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "from_account": {
                "role_token": "Lender"
            },
            "pay": {
                "and": 50000000,
                "add": {
                    "multiply": 3,
                    "times": 4000000
                }
            },
            "token": {
                "currency_symbol": "",
                "token_name": ""
            }
        }
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14139967,
        14144167
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Guarantor"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 62000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

108_lender_deposit.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender   -51.51    45.28
  borrower            100.00
 guarantor             36.57
  contract             65.00
    payout    50.00    50.00
     TOTAL    -1.51   296.85
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    45.28 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#0    | +    41.09 | Greatest Pure Ada
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#3    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   100.00 |
* 3745050644634d83a7514c68c05d40fac9af52f2c2c776fd490f6e78c56c5ae2#0    | +    95.82 | Greatest Pure Ada
* 3745050644634d83a7514c68c05d40fac9af52f2c2c776fd490f6e78c56c5ae2#1    | +     2.00 | [ "Borrower"×1 ]
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.57 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#0    | +    32.39 | Greatest Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    65.00 |
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =    50.00 |
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#2    | +    50.00 | GreatestByTxHavingDatum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                65000000
            ]
        ],
        "minTime": 1664089655000 [[2022-09-25 07:07:35 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Borrower"
                }
            },
            "accountId": {
                "role_token": "Borrower"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                50000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664136976000 [[2022-09-25 20:16:16 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": {
                            "timeout": 1664140576000 [[2022-09-25 21:16:16 +0000 UTC]],
                            "when": [
                                {
                                    "then": {
                                        "then": {
                                            "then": {
                                                "timeout": 1664144176000 [[2022-09-25 22:16:16 +0000 UTC]],
                                                "when": [
                                                    {
                                                        "then": {
                                                            "then": {
                                                                "then": "close",
                                                                "to": {
                                                                    "party": {
                                                                        "role_token": "Guarantor"
                                                                    }
                                                                },
                                                                "from_account": {
                                                                    "role_token": "Lender"
                                                                },
                                                                "pay": {
                                                                    "and": 50000000,
                                                                    "add": 4000000
                                                                },
                                                                "token": {
                                                                    "currency_symbol": "",
                                                                    "token_name": ""
                                                                }
                                                            },
                                                            "to": {
                                                                "party": {
                                                                    "role_token": "Lender"
                                                                }
                                                            },
                                                            "from_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "pay": {
                                                                "and": 3000000,
                                                                "add": {
                                                                    "and": 50000000,
                                                                    "add": 4000000
                                                                }
                                                            },
                                                            "token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            }
                                                        },
                                                        "case": {
                                                            "deposits": {
                                                                "and": 50000000,
                                                                "add": 4000000
                                                            },
                                                            "into_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "of_token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            },
                                                            "party": {
                                                                "role_token": "Borrower"
                                                            }
                                                        }
                                                    }
                                                ],
                                                "timeout_continuation": "close"
                                            },
                                            "to": {
                                                "party": {
                                                    "role_token": "Guarantor"
                                                }
                                            },
                                            "from_account": {
                                                "role_token": "Lender"
                                            },
                                            "pay": 4000000,
                                            "token": {
                                                "currency_symbol": "",
                                                "token_name": ""
                                            }
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Lender"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": 4000000,
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "case": {
                                        "deposits": 4000000,
                                        "into_account": {
                                            "role_token": "Lender"
                                        },
                                        "of_token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        },
                                        "party": {
                                            "role_token": "Borrower"
                                        }
                                    }
                                }
                            ],
                            "timeout_continuation": "close"
                        },
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": 4000000,
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": 4000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 4000000,
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14140024,
        14144224
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Lender"
            },
            "into_account": {
                "role_token": "Borrower"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 50000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

110_borrower_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             45.28
  borrower    49.58   149.58
 guarantor             36.57
  contract             65.00
    payout   -50.00         
     TOTAL    -0.42   296.42
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    45.28 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#0    | +    41.09 | Greatest Pure Ada
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#3    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   149.58 |
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#0    | +    95.40 | Greatest Pure Ada
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#1    | +    50.00 | Pure Ada
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#2    | +     2.00 | [ "Borrower"×1 ]
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.57 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#0    | +    32.39 | Greatest Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    65.00 |
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

202_borrower_pays_installment1.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             45.28
  borrower    -5.63   143.95
 guarantor             36.57
  contract    -4.00    61.00
    payout     8.00     8.00
     TOTAL    -1.63   294.80
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    45.28 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#0    | +    41.09 | Greatest Pure Ada
* 7339c6a0e4e2c6c948ab16a29ee52f31873d4c2b2bfcf67617dc193caf12f72d#3    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   143.95 |
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#1    | +    50.00 | Pure Ada
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#0    | +    89.77 | Greatest Pure Ada
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.57 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#0    | +    32.39 | Greatest Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    61.00 |
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     8.00 |
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#2    | +     4.00 | GreatestByTxHavingDatum
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#3    | +     4.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                61000000
            ]
        ],
        "minTime": 1664089707000 [[2022-09-25 07:08:27 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664140576000 [[2022-09-25 21:16:16 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": {
                            "timeout": 1664144176000 [[2022-09-25 22:16:16 +0000 UTC]],
                            "when": [
                                {
                                    "then": {
                                        "then": {
                                            "then": "close",
                                            "to": {
                                                "party": {
                                                    "role_token": "Guarantor"
                                                }
                                            },
                                            "from_account": {
                                                "role_token": "Lender"
                                            },
                                            "pay": {
                                                "and": 50000000,
                                                "add": 4000000
                                            },
                                            "token": {
                                                "currency_symbol": "",
                                                "token_name": ""
                                            }
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Lender"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": {
                                            "and": 3000000,
                                            "add": {
                                                "and": 50000000,
                                                "add": 4000000
                                            }
                                        },
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "case": {
                                        "deposits": {
                                            "and": 50000000,
                                            "add": 4000000
                                        },
                                        "into_account": {
                                            "role_token": "Lender"
                                        },
                                        "of_token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        },
                                        "party": {
                                            "role_token": "Borrower"
                                        }
                                    }
                                }
                            ],
                            "timeout_continuation": "close"
                        },
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": 4000000,
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": 4000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 4000000,
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14140076,
        14144276
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 4000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

204_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender     3.58    48.85
  borrower            143.95
 guarantor             36.57
  contract             61.00
    payout    -4.00     4.00
     TOTAL    -0.42   294.37
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    48.85 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#0    | +    40.67 | Greatest Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   143.95 |
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#1    | +    50.00 | Pure Ada
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#0    | +    89.77 | Greatest Pure Ada
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    36.57 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#0    | +    32.39 | Greatest Pure Ada
* cec22297e4c9b0ad82bb65cc847ceb1d9c3b8b94dcf1a895500152f20c6e424d#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    61.00 |
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     4.00 |
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#3    | +     4.00 | GreatestByTxHavingDatum

206_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             48.85
  borrower            143.95
 guarantor     3.58    40.15
  contract             61.00
    payout    -4.00         
     TOTAL    -0.42   293.95
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    48.85 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#0    | +    40.67 | Greatest Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   143.95 |
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#1    | +    50.00 | Pure Ada
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#0    | +    89.77 | Greatest Pure Ada
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    40.15 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#0    | +    31.97 | Greatest Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#1    | +     4.00 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    61.00 |
* e059c7aa3c61380e791e877e4ec3ebf44465ce2331937a9473cc4c3cd1a79ef1#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

302_borrower_pays_installment2.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             48.85
  borrower    -5.59   138.36
 guarantor             40.15
  contract    -4.00    57.00
    payout     8.00     8.00
     TOTAL    -1.59   292.36
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    48.85 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#0    | +    40.67 | Greatest Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.36 |
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#1    | +    50.00 | Pure Ada
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#0    | +    84.18 | Greatest Pure Ada
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#4    | +     2.00 | [ "Borrower"×1 ]
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    40.15 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#0    | +    31.97 | Greatest Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#1    | +     4.00 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     8.00 |
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#2    | +     4.00 | GreatestByTxHavingDatum
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#3    | +     4.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                57000000
            ]
        ],
        "minTime": 1664089815000 [[2022-09-25 07:10:15 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664144176000 [[2022-09-25 22:16:16 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": "close",
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": {
                            "and": 50000000,
                            "add": 4000000
                        },
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": {
                        "and": 3000000,
                        "add": {
                            "and": 50000000,
                            "add": 4000000
                        }
                    },
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": {
                        "and": 50000000,
                        "add": 4000000
                    },
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14140184,
        14144384
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 4000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

304_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender     3.57    52.43
  borrower            138.36
 guarantor             40.15
  contract             57.00
    payout    -4.00     4.00
     TOTAL    -0.43   291.93
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.43 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#0    | +    40.25 | Greatest Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.36 |
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#1    | +    50.00 | Pure Ada
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#0    | +    84.18 | Greatest Pure Ada
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#4    | +     2.00 | [ "Borrower"×1 ]
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    40.15 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#0    | +    31.97 | Greatest Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#1    | +     4.00 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     4.00 |
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#3    | +     4.00 | GreatestByTxHavingDatum

306_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             52.43
  borrower            138.36
 guarantor     3.57    43.72
  contract             57.00
    payout    -4.00         
     TOTAL    -0.43   291.51
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.43 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#0    | +    40.25 | Greatest Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =   138.36 |
* 4127eef11fd4407477ecb5e72faf9f77d8a01bb06e4c8bb8f9a8e591fa53f47b#1    | +    50.00 | Pure Ada
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#0    | +    84.18 | Greatest Pure Ada
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#4    | +     2.00 | [ "Borrower"×1 ]
* c4b0d0d06f41230971089a608ffdc25b0791245840fe2b51d341ae81008eabf9#1    | +     2.18 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    43.72 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#1    | +     4.00 | Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#0    | +    31.54 | Greatest Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#1    | +     4.00 | Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =    57.00 |
* 42429375117c9ceea5d53cf6bb5daeab0c9f2b681d949d68aa4bf0b631fb1c04#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |

402_borrower_pays_installment3.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender             52.43
  borrower   -55.35    83.01
 guarantor             43.72
  contract   -57.00         
    payout   111.00   111.00
     TOTAL    -1.35   290.16
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =    52.43 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#0    | +    40.25 | Greatest Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#2    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =    83.01 |
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#0    | +    81.01 | Greatest Pure Ada
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#3    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    43.72 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#1    | +     4.00 | Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#0    | +    31.54 | Greatest Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#1    | +     4.00 | Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =     0.00 |
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =   111.00 |
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#1    | +    57.00 | GreatestByTxHavingDatum
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#2    | +    54.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [],
        "minTime": 1664089933000 [[2022-09-25 07:12:13 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                57000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                54000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": "close",
    "rolesValidator": {
        "hash": "9a9794917d8e831be5110e3a5897bf474b7f8bc1830dbb420da538c2",
        "size": 2469,
        "address": "addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯49576c1dcc7b7c90fef20aa870860001",
            "description": ""
        }
    },
    "range": [
        14140302,
        14144502
    ],
    "marloweValidator": {
        "hash": "c81da42bfdf3f0b0bc2e335f3b8d06580c855a29164b92d0407491c3",
        "size": 12415,
        "address": "addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯f20aa870860022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 54000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "10e1ba7f0c7dfe42ed6736da9c3749576c1dcc7b7c90fef20aa87086"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

404_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender    56.57   109.00
  borrower             83.01
 guarantor             43.72
  contract                  
    payout   -57.00    54.00
     TOTAL    -0.43   289.73
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =   109.00 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* 600822aee63d3fe581a568d44ad4ab0fe2132e3f412ffc1c7e9a7156649e1860#0    | +    39.82 | Pure Ada
* 600822aee63d3fe581a568d44ad4ab0fe2132e3f412ffc1c7e9a7156649e1860#1    | +    57.00 | Greatest Pure Ada
* 600822aee63d3fe581a568d44ad4ab0fe2132e3f412ffc1c7e9a7156649e1860#2    | +     2.00 | [ "Lender"×1 ]
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#1    | +     4.00 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =    83.01 |
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#0    | +    81.01 | Greatest Pure Ada
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#3    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    43.72 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#1    | +     4.00 | Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#0    | +    31.54 | Greatest Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#1    | +     4.00 | Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =     0.00 |
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =    54.00 |
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#2    | +    54.00 | GreatestByTxHavingDatum

406_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    lender            109.00
  borrower             83.01
 guarantor    53.57    97.29
  contract                  
    payout   -54.00         
     TOTAL    -0.43   289.30
==============================

Snapshot taken after the script run:


--- lender       -----------------------------------------------------------------------------------------------
addr_test1vr5cvgswyma5s53k76rpf7uzcuq3u3d0hvcc86lr3wyvy9qze26h0         | =   109.00 |
* 0c3de9c7483461fa58d5f352113ec0664dcd3468b4fcfaf0c8550e5e3b6a8a45#1    | +     2.18 | Pure Ada
* 600822aee63d3fe581a568d44ad4ab0fe2132e3f412ffc1c7e9a7156649e1860#0    | +    39.82 | Pure Ada
* 600822aee63d3fe581a568d44ad4ab0fe2132e3f412ffc1c7e9a7156649e1860#1    | +    57.00 | Greatest Pure Ada
* 600822aee63d3fe581a568d44ad4ab0fe2132e3f412ffc1c7e9a7156649e1860#2    | +     2.00 | [ "Lender"×1 ]
* a196600a12f9b075187f028691b156fd060afd64d1f9f993769b0f2deccaaa52#1    | +     4.00 | Pure Ada
* e802c647b767e82c2a9fdd265d1611b4da6e74629db73dff1607c1c0311a360b#1    | +     4.00 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vz0at5gehvrkektqx0vv2ylthqkzazzjvc5e5y2wh7md8hcffsn35         | =    83.01 |
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#0    | +    81.01 | Greatest Pure Ada
* 6345c833db7153e3540512ccec9d3a9a8fd45af5da20377f6e5560b0c3f2d4e9#3    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vp4cfg7trshc4rcrs6l67azqws05c8u4x9w6ggpqzg4893s7m3qsk         | =    97.29 |
* 73a3382fd68654ace9d3ed7b740bff549c237f7e2d55fb1e7fb1fcbef07f71c1#1    | +     2.18 | Pure Ada
* 80701578b1a908070c3e30ad3589724e3a97eb95ca987f7858f6cba6bb38d5ab#0    | +    31.11 | Pure Ada
* 80701578b1a908070c3e30ad3589724e3a97eb95ca987f7858f6cba6bb38d5ab#1    | +    54.00 | Greatest Pure Ada
* 80701578b1a908070c3e30ad3589724e3a97eb95ca987f7858f6cba6bb38d5ab#2    | +     2.00 | [ "Guarantor"×1 ]
* 995a9f762d0b2f7d3637b3648327071b04f1b2829aa30c42c7313ee150468b61#1    | +     4.00 | Pure Ada
* e05d08d44135a00937d7e739efb911865b1861c00412f797b3c12f2895d8bf72#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wrypmfptlhelpv9u9ce47wudqevqep269ytyhyksgp6frscvpnejt         | =     0.00 |
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wzdf09y30k8gxxl9zy8r5kyhhar5klutcxpsmw6zpkjn3ssnkal7t         | =     0.00 |
w0802t_cbg
20220925

The Coupon Bond Guaranteed contract as-is

The run that succeeds

This is the run with the unmodified contract (or original contract), as described on w0802_cbg

This one succeeds because the contract is NOT funded by the lender, but by another party, the patron. My ref: output of a run of the scripts in daedtest:~/work/20220925_cbg_take5

export FUND_CONTRACT=3000000                    # the amount to fund the contract with 
export MINIMUM_ADA=2000000                      # the minimum lovelace to be included with native token output.

export PRINCIPAL_AMOUNT=50000000                # the principal is 50₳
export INTEREST_INSTALLMENT=4000000             # the interest is 4₳

The overall result, comparing before/after run:

======================================
     ALIAS    START   CHANGE      END
    patron   100.00    -0.63    99.37
    lender   100.00     9.16   109.16
  borrower   100.00   -17.24    82.76
 guarantor   100.00    -2.70    97.30
  contract                           
    payout                           
     TOTAL   400.00   -11.40   388.60
======================================

104b_patron_funds_contract.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron    -3.21    96.79
    lender            100.00
  borrower            100.00
 guarantor            100.00
  contract     3.00     3.00
    payout                  
     TOTAL    -0.21   399.79
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =   100.00 |
* 60e01c24abcb2f7a89b09231a4bae27368e06e32abba2fb93ce3bc0e992c1869#0    | +    95.64 | Greatest Pure Ada
* 60e01c24abcb2f7a89b09231a4bae27368e06e32abba2fb93ce3bc0e992c1869#1    | +     2.00 | [ "Lender"×1 ]
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   100.00 |
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* b279357b7974447c35fca9a54b8d5800ff6a34722d9ccd1ad3713544599d6b60#0    | +    95.82 | Greatest Pure Ada
* b279357b7974447c35fca9a54b8d5800ff6a34722d9ccd1ad3713544599d6b60#1    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =   100.00 |
* 683ac37cb56eb59ad1e8f3eccea1e6bf916d9771d23816c06920e2e9b8d88cdc#0    | +    95.80 | Greatest Pure Ada
* 683ac37cb56eb59ad1e8f3eccea1e6bf916d9771d23816c06920e2e9b8d88cdc#1    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =     3.00 |
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#1    | +     3.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     0.00 |

106_guarantor_deposit.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender            100.00
  borrower            100.00
 guarantor   -63.42    36.58
  contract    62.00    65.00
    payout                  
     TOTAL    -1.42   398.36
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =   100.00 |
* 60e01c24abcb2f7a89b09231a4bae27368e06e32abba2fb93ce3bc0e992c1869#0    | +    95.64 | Greatest Pure Ada
* 60e01c24abcb2f7a89b09231a4bae27368e06e32abba2fb93ce3bc0e992c1869#1    | +     2.00 | [ "Lender"×1 ]
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   100.00 |
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* b279357b7974447c35fca9a54b8d5800ff6a34722d9ccd1ad3713544599d6b60#0    | +    95.82 | Greatest Pure Ada
* b279357b7974447c35fca9a54b8d5800ff6a34722d9ccd1ad3713544599d6b60#1    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    36.58 |
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#0    | +    32.38 | Greatest Pure Ada
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    65.00 |
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     0.00 |

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Patron"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                3000000
            ],
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                62000000
            ]
        ],
        "minTime": 1664125136000 [[2022-09-25 16:58:56 +0000 UTC]]
    },
    "payments": [],
    "contract": {
        "timeout": 1664168914000 [[2022-09-26 05:08:34 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "timeout": 1664172514000 [[2022-09-26 06:08:34 +0000 UTC]],
                        "when": [
                            {
                                "then": {
                                    "then": {
                                        "then": {
                                            "timeout": 1664176114000 [[2022-09-26 07:08:34 +0000 UTC]],
                                            "when": [
                                                {
                                                    "then": {
                                                        "then": {
                                                            "then": {
                                                                "timeout": 1664179714000 [[2022-09-26 08:08:34 +0000 UTC]],
                                                                "when": [
                                                                    {
                                                                        "then": {
                                                                            "then": {
                                                                                "then": "close",
                                                                                "to": {
                                                                                    "party": {
                                                                                        "role_token": "Guarantor"
                                                                                    }
                                                                                },
                                                                                "from_account": {
                                                                                    "role_token": "Lender"
                                                                                },
                                                                                "pay": {
                                                                                    "and": 50000000,
                                                                                    "add": 4000000
                                                                                },
                                                                                "token": {
                                                                                    "currency_symbol": "",
                                                                                    "token_name": ""
                                                                                }
                                                                            },
                                                                            "to": {
                                                                                "party": {
                                                                                    "role_token": "Lender"
                                                                                }
                                                                            },
                                                                            "from_account": {
                                                                                "role_token": "Lender"
                                                                            },
                                                                            "pay": {
                                                                                "and": 50000000,
                                                                                "add": 4000000
                                                                            },
                                                                            "token": {
                                                                                "currency_symbol": "",
                                                                                "token_name": ""
                                                                            }
                                                                        },
                                                                        "case": {
                                                                            "deposits": {
                                                                                "and": 50000000,
                                                                                "add": 4000000
                                                                            },
                                                                            "into_account": {
                                                                                "role_token": "Lender"
                                                                            },
                                                                            "of_token": {
                                                                                "currency_symbol": "",
                                                                                "token_name": ""
                                                                            },
                                                                            "party": {
                                                                                "role_token": "Borrower"
                                                                            }
                                                                        }
                                                                    }
                                                                ],
                                                                "timeout_continuation": "close"
                                                            },
                                                            "to": {
                                                                "party": {
                                                                    "role_token": "Guarantor"
                                                                }
                                                            },
                                                            "from_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "pay": 4000000,
                                                            "token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            }
                                                        },
                                                        "to": {
                                                            "party": {
                                                                "role_token": "Lender"
                                                            }
                                                        },
                                                        "from_account": {
                                                            "role_token": "Lender"
                                                        },
                                                        "pay": 4000000,
                                                        "token": {
                                                            "currency_symbol": "",
                                                            "token_name": ""
                                                        }
                                                    },
                                                    "case": {
                                                        "deposits": 4000000,
                                                        "into_account": {
                                                            "role_token": "Lender"
                                                        },
                                                        "of_token": {
                                                            "currency_symbol": "",
                                                            "token_name": ""
                                                        },
                                                        "party": {
                                                            "role_token": "Borrower"
                                                        }
                                                    }
                                                }
                                            ],
                                            "timeout_continuation": "close"
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Guarantor"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": 4000000,
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "to": {
                                        "party": {
                                            "role_token": "Lender"
                                        }
                                    },
                                    "from_account": {
                                        "role_token": "Lender"
                                    },
                                    "pay": 4000000,
                                    "token": {
                                        "currency_symbol": "",
                                        "token_name": ""
                                    }
                                },
                                "case": {
                                    "deposits": 4000000,
                                    "into_account": {
                                        "role_token": "Lender"
                                    },
                                    "of_token": {
                                        "currency_symbol": "",
                                        "token_name": ""
                                    },
                                    "party": {
                                        "role_token": "Borrower"
                                    }
                                }
                            }
                        ],
                        "timeout_continuation": "close"
                    },
                    "to": {
                        "party": {
                            "role_token": "Borrower"
                        }
                    },
                    "from_account": {
                        "role_token": "Borrower"
                    },
                    "pay": 50000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 50000000,
                    "into_account": {
                        "role_token": "Borrower"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Lender"
                    }
                }
            }
        ],
        "timeout_continuation": {
            "then": "close",
            "to": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "from_account": {
                "role_token": "Lender"
            },
            "pay": {
                "and": 50000000,
                "add": {
                    "multiply": 3,
                    "times": 4000000
                }
            },
            "token": {
                "currency_symbol": "",
                "token_name": ""
            }
        }
    },
    "rolesValidator": {
        "hash": "362efa127d235b77e6c8014d2fef75ca0966a9bf24a17dd7ae605bab",
        "size": 2469,
        "address": "addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯4811f12d41fada930241e4b8dae90001",
            "description": ""
        }
    },
    "range": [
        14175505,
        14179705
    ],
    "marloweValidator": {
        "hash": "17ba2636fc5becd051e0f9f5e2933f178e6d3a8e526751587ccb6789",
        "size": 12415,
        "address": "addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯41e4b8dae90022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Guarantor"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 62000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "4828cdeadb9049570aa0210824894811f12d41fada930241e4b8dae9"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

108_lender_deposit.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender   -51.56    48.44
  borrower            100.00
 guarantor             36.58
  contract             65.00
    payout    50.00    50.00
     TOTAL    -1.56   396.80
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    48.44 |
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#0    | +    44.08 | Greatest Pure Ada
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#3    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   100.00 |
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* b279357b7974447c35fca9a54b8d5800ff6a34722d9ccd1ad3713544599d6b60#0    | +    95.82 | Greatest Pure Ada
* b279357b7974447c35fca9a54b8d5800ff6a34722d9ccd1ad3713544599d6b60#1    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    36.58 |
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#0    | +    32.38 | Greatest Pure Ada
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    65.00 |
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =    50.00 |
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#2    | +    50.00 | GreatestByTxHavingDatum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Patron"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                3000000
            ],
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                62000000
            ]
        ],
        "minTime": 1664125153000 [[2022-09-25 16:59:13 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Borrower"
                }
            },
            "accountId": {
                "role_token": "Borrower"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                50000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664172514000 [[2022-09-26 06:08:34 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": {
                            "timeout": 1664176114000 [[2022-09-26 07:08:34 +0000 UTC]],
                            "when": [
                                {
                                    "then": {
                                        "then": {
                                            "then": {
                                                "timeout": 1664179714000 [[2022-09-26 08:08:34 +0000 UTC]],
                                                "when": [
                                                    {
                                                        "then": {
                                                            "then": {
                                                                "then": "close",
                                                                "to": {
                                                                    "party": {
                                                                        "role_token": "Guarantor"
                                                                    }
                                                                },
                                                                "from_account": {
                                                                    "role_token": "Lender"
                                                                },
                                                                "pay": {
                                                                    "and": 50000000,
                                                                    "add": 4000000
                                                                },
                                                                "token": {
                                                                    "currency_symbol": "",
                                                                    "token_name": ""
                                                                }
                                                            },
                                                            "to": {
                                                                "party": {
                                                                    "role_token": "Lender"
                                                                }
                                                            },
                                                            "from_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "pay": {
                                                                "and": 50000000,
                                                                "add": 4000000
                                                            },
                                                            "token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            }
                                                        },
                                                        "case": {
                                                            "deposits": {
                                                                "and": 50000000,
                                                                "add": 4000000
                                                            },
                                                            "into_account": {
                                                                "role_token": "Lender"
                                                            },
                                                            "of_token": {
                                                                "currency_symbol": "",
                                                                "token_name": ""
                                                            },
                                                            "party": {
                                                                "role_token": "Borrower"
                                                            }
                                                        }
                                                    }
                                                ],
                                                "timeout_continuation": "close"
                                            },
                                            "to": {
                                                "party": {
                                                    "role_token": "Guarantor"
                                                }
                                            },
                                            "from_account": {
                                                "role_token": "Lender"
                                            },
                                            "pay": 4000000,
                                            "token": {
                                                "currency_symbol": "",
                                                "token_name": ""
                                            }
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Lender"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": 4000000,
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "case": {
                                        "deposits": 4000000,
                                        "into_account": {
                                            "role_token": "Lender"
                                        },
                                        "of_token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        },
                                        "party": {
                                            "role_token": "Borrower"
                                        }
                                    }
                                }
                            ],
                            "timeout_continuation": "close"
                        },
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": 4000000,
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": 4000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 4000000,
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "362efa127d235b77e6c8014d2fef75ca0966a9bf24a17dd7ae605bab",
        "size": 2469,
        "address": "addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯4811f12d41fada930241e4b8dae90001",
            "description": ""
        }
    },
    "range": [
        14175522,
        14179722
    ],
    "marloweValidator": {
        "hash": "17ba2636fc5becd051e0f9f5e2933f178e6d3a8e526751587ccb6789",
        "size": 12415,
        "address": "addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯41e4b8dae90022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Lender"
            },
            "into_account": {
                "role_token": "Borrower"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 50000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "4828cdeadb9049570aa0210824894811f12d41fada930241e4b8dae9"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

110_borrower_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender             48.44
  borrower    49.57   149.57
 guarantor             36.58
  contract             65.00
    payout   -50.00         
     TOTAL    -0.43   396.37
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    48.44 |
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#0    | +    44.08 | Greatest Pure Ada
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#3    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   149.57 |
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#0    | +    95.39 | Greatest Pure Ada
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#1    | +    50.00 | Pure Ada
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#2    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    36.58 |
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#0    | +    32.38 | Greatest Pure Ada
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    65.00 |
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#1    | +    65.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     0.00 |

202_borrower_pays_installment1.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender             48.44
  borrower    -5.69   143.89
 guarantor             36.58
  contract    -4.00    61.00
    payout     8.00     8.00
     TOTAL    -1.69   394.69
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    48.44 |
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#0    | +    44.08 | Greatest Pure Ada
* a05e3473b89c41e853d4223442fe3e5a32b161a4ca36f76900dba98fbe5bbccd#3    | +     2.00 | [ "Lender"×1 ]
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   143.89 |
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#0    | +    89.70 | Greatest Pure Ada
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#4    | +     2.00 | [ "Borrower"×1 ]
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    36.58 |
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#0    | +    32.38 | Greatest Pure Ada
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    61.00 |
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     8.00 |
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#2    | +     4.00 | GreatestByTxHavingDatum
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#3    | +     4.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Patron"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                3000000
            ],
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                58000000
            ]
        ],
        "minTime": 1664125245000 [[2022-09-25 17:00:45 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664176114000 [[2022-09-26 07:08:34 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": {
                            "timeout": 1664179714000 [[2022-09-26 08:08:34 +0000 UTC]],
                            "when": [
                                {
                                    "then": {
                                        "then": {
                                            "then": "close",
                                            "to": {
                                                "party": {
                                                    "role_token": "Guarantor"
                                                }
                                            },
                                            "from_account": {
                                                "role_token": "Lender"
                                            },
                                            "pay": {
                                                "and": 50000000,
                                                "add": 4000000
                                            },
                                            "token": {
                                                "currency_symbol": "",
                                                "token_name": ""
                                            }
                                        },
                                        "to": {
                                            "party": {
                                                "role_token": "Lender"
                                            }
                                        },
                                        "from_account": {
                                            "role_token": "Lender"
                                        },
                                        "pay": {
                                            "and": 50000000,
                                            "add": 4000000
                                        },
                                        "token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        }
                                    },
                                    "case": {
                                        "deposits": {
                                            "and": 50000000,
                                            "add": 4000000
                                        },
                                        "into_account": {
                                            "role_token": "Lender"
                                        },
                                        "of_token": {
                                            "currency_symbol": "",
                                            "token_name": ""
                                        },
                                        "party": {
                                            "role_token": "Borrower"
                                        }
                                    }
                                }
                            ],
                            "timeout_continuation": "close"
                        },
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": 4000000,
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": 4000000,
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": 4000000,
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "362efa127d235b77e6c8014d2fef75ca0966a9bf24a17dd7ae605bab",
        "size": 2469,
        "address": "addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯4811f12d41fada930241e4b8dae90001",
            "description": ""
        }
    },
    "range": [
        14175614,
        14179814
    ],
    "marloweValidator": {
        "hash": "17ba2636fc5becd051e0f9f5e2933f178e6d3a8e526751587ccb6789",
        "size": 12415,
        "address": "addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯41e4b8dae90022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 4000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "4828cdeadb9049570aa0210824894811f12d41fada930241e4b8dae9"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

204_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender     3.57    52.01
  borrower            143.89
 guarantor             36.58
  contract             61.00
    payout    -4.00     4.00
     TOTAL    -0.43   394.26
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    52.01 |
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#0    | +    43.65 | Greatest Pure Ada
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#2    | +     2.00 | [ "Lender"×1 ]
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   143.89 |
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#0    | +    89.70 | Greatest Pure Ada
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#4    | +     2.00 | [ "Borrower"×1 ]
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    36.58 |
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#0    | +    32.38 | Greatest Pure Ada
* 4ae99facb1984fbb928102cadd1954db1f6c82c927a3a6c7d097d9933dfbf6b0#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    61.00 |
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     4.00 |
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#3    | +     4.00 | GreatestByTxHavingDatum

206_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender             52.01
  borrower            143.89
 guarantor     3.58    40.15
  contract             61.00
    payout    -4.00         
     TOTAL    -0.42   393.84
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    52.01 |
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#0    | +    43.65 | Greatest Pure Ada
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#2    | +     2.00 | [ "Lender"×1 ]
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   143.89 |
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#0    | +    89.70 | Greatest Pure Ada
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#4    | +     2.00 | [ "Borrower"×1 ]
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    40.15 |
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#0    | +    31.95 | Greatest Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    61.00 |
* 708423dca7a87a81a07e3be9dc0c3e8eb27753019a1efa1e2ec5f25d46179740#1    | +    61.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     0.00 |

302_borrower_pays_installment2.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender             52.01
  borrower    -5.65   138.24
 guarantor             40.15
  contract    -4.00    57.00
    payout     8.00     8.00
     TOTAL    -1.65   392.19
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    52.01 |
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#0    | +    43.65 | Greatest Pure Ada
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#2    | +     2.00 | [ "Lender"×1 ]
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   138.24 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#0    | +    84.06 | Greatest Pure Ada
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#4    | +     2.00 | [ "Borrower"×1 ]
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    40.15 |
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#0    | +    31.95 | Greatest Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    57.00 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     8.00 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#2    | +     4.00 | GreatestByTxHavingDatum
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#3    | +     4.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [
            [
                [
                    {
                        "role_token": "Patron"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                3000000
            ],
            [
                [
                    {
                        "role_token": "Lender"
                    },
                    {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                ],
                54000000
            ]
        ],
        "minTime": 1664125414000 [[2022-09-25 17:03:34 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                4000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": {
        "timeout": 1664179714000 [[2022-09-26 08:08:34 +0000 UTC]],
        "when": [
            {
                "then": {
                    "then": {
                        "then": "close",
                        "to": {
                            "party": {
                                "role_token": "Guarantor"
                            }
                        },
                        "from_account": {
                            "role_token": "Lender"
                        },
                        "pay": {
                            "and": 50000000,
                            "add": 4000000
                        },
                        "token": {
                            "currency_symbol": "",
                            "token_name": ""
                        }
                    },
                    "to": {
                        "party": {
                            "role_token": "Lender"
                        }
                    },
                    "from_account": {
                        "role_token": "Lender"
                    },
                    "pay": {
                        "and": 50000000,
                        "add": 4000000
                    },
                    "token": {
                        "currency_symbol": "",
                        "token_name": ""
                    }
                },
                "case": {
                    "deposits": {
                        "and": 50000000,
                        "add": 4000000
                    },
                    "into_account": {
                        "role_token": "Lender"
                    },
                    "of_token": {
                        "currency_symbol": "",
                        "token_name": ""
                    },
                    "party": {
                        "role_token": "Borrower"
                    }
                }
            }
        ],
        "timeout_continuation": "close"
    },
    "rolesValidator": {
        "hash": "362efa127d235b77e6c8014d2fef75ca0966a9bf24a17dd7ae605bab",
        "size": 2469,
        "address": "addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯4811f12d41fada930241e4b8dae90001",
            "description": ""
        }
    },
    "range": [
        14175783,
        14179983
    ],
    "marloweValidator": {
        "hash": "17ba2636fc5becd051e0f9f5e2933f178e6d3a8e526751587ccb6789",
        "size": 12415,
        "address": "addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯41e4b8dae90022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 4000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "4828cdeadb9049570aa0210824894811f12d41fada930241e4b8dae9"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

304_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender     3.57    55.58
  borrower            138.24
 guarantor             40.15
  contract             57.00
    payout    -4.00     4.00
     TOTAL    -0.43   391.76
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    55.58 |
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#0    | +    43.22 | Greatest Pure Ada
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#1    | +     4.00 | Pure Ada
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#2    | +     2.00 | [ "Lender"×1 ]
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   138.24 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#0    | +    84.06 | Greatest Pure Ada
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#4    | +     2.00 | [ "Borrower"×1 ]
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    40.15 |
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#0    | +    31.95 | Greatest Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#2    | +     2.00 | [ "Guarantor"×1 ]
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    57.00 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     4.00 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#3    | +     4.00 | GreatestByTxHavingDatum

306_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender             55.58
  borrower            138.24
 guarantor     3.57    43.73
  contract             57.00
    payout    -4.00         
     TOTAL    -0.43   391.34
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    55.58 |
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#0    | +    43.22 | Greatest Pure Ada
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#1    | +     4.00 | Pure Ada
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#2    | +     2.00 | [ "Lender"×1 ]
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =   138.24 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#0    | +    84.06 | Greatest Pure Ada
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#4    | +     2.00 | [ "Borrower"×1 ]
* 68b4d6f5ebd4d449c9288ffd6e3e7e6bd9415b19064672931a381b4ecb7d3908#1    | +     2.18 | Pure Ada
* 96bb4966f5000fe0849e2f583002893e156323060fa5a14ee5ec11f10308265f#1    | +    50.00 | Pure Ada
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    43.73 |
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#0    | +    31.53 | Greatest Pure Ada
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#1    | +     4.00 | Pure Ada
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =    57.00 |
* 1f522c10d3fb9ad708c899c68fc476313864cef82ab261a0d7dcab770d82b1cc#1    | +    57.00 | GreatestByTxHavingDatum
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     0.00 |

402_borrower_pays_installment3.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender             55.58
  borrower   -55.48    82.76
 guarantor             43.73
  contract   -57.00         
    payout   111.00   111.00
     TOTAL    -1.48   389.86
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =    55.58 |
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#0    | +    43.22 | Greatest Pure Ada
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#1    | +     4.00 | Pure Ada
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#2    | +     2.00 | [ "Lender"×1 ]
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =    82.76 |
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#0    | +    80.76 | Greatest Pure Ada
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    43.73 |
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#0    | +    31.53 | Greatest Pure Ada
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#1    | +     4.00 | Pure Ada
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =     0.00 |
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =   111.00 |
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#1    | +    54.00 | GreatestByTxHavingDatum
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#2    | +    54.00 | Datum
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#3    | +     3.00 | Datum

The marlowe file produced by executing the script.
Note: annotated json (shortened hex-strings, translated posix-time).

{
    "state": {
        "choices": [],
        "boundValues": [],
        "accounts": [],
        "minTime": 1664125572000 [[2022-09-25 17:06:12 +0000 UTC]]
    },
    "payments": [
        {
            "payee": {
                "party": {
                    "role_token": "Lender"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                54000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Guarantor"
                }
            },
            "accountId": {
                "role_token": "Lender"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                54000000
                            ]
                        ]
                    ]
                ]
            }
        },
        {
            "payee": {
                "party": {
                    "role_token": "Patron"
                }
            },
            "accountId": {
                "role_token": "Patron"
            },
            "money": {
                "getValue": [
                    [
                        {
                            "unCurrencySymbol": ""
                        },
                        [
                            [
                                {
                                    "unTokenName": ""
                                },
                                3000000
                            ]
                        ]
                    ]
                ]
            }
        }
    ],
    "contract": "close",
    "rolesValidator": {
        "hash": "362efa127d235b77e6c8014d2fef75ca0966a9bf24a17dd7ae605bab",
        "size": 2469,
        "address": "addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk",
        "cost": {
            "exBudgetMemory": 14600,
            "exBudgetCPU": 4317185
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "5909a55909a201000033232332232323⋯⋯₄₉₄₄⋯⋯4811f12d41fada930241e4b8dae90001",
            "description": ""
        }
    },
    "range": [
        14175941,
        14180141
    ],
    "marloweValidator": {
        "hash": "17ba2636fc5becd051e0f9f5e2933f178e6d3a8e526751587ccb6789",
        "size": 12415,
        "address": "addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z",
        "cost": {
            "exBudgetMemory": 82900,
            "exBudgetCPU": 24652144
        },
        "script": {
            "type": "PlutusScriptV1",
            "cborHex": "59307f59307c01000033232323322323⋯⋯₂₄₈₃₆⋯⋯41e4b8dae90022123300100300220011",
            "description": ""
        }
    },
    "inputs": [
        {
            "input_from_party": {
                "role_token": "Borrower"
            },
            "into_account": {
                "role_token": "Lender"
            },
            "of_token": {
                "currency_symbol": "",
                "token_name": ""
            },
            "that_deposits": 54000000
        }
    ],
    "roles": {
        "unCurrencySymbol": "4828cdeadb9049570aa0210824894811f12d41fada930241e4b8dae9"
    },
    "slotConfig": {
        "scSlotLength": 1000,
        "scSlotZeroTime": 1649949631000 [[2022-04-14 15:20:31 +0000 UTC]]
    }
}

404_lender_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender    53.58   109.16
  borrower             82.76
 guarantor             43.73
  contract                  
    payout   -54.00    57.00
     TOTAL    -0.42   389.44
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =   109.16 |
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#1    | +     4.00 | Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#0    | +    42.80 | Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#1    | +    54.00 | Greatest Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#2    | +     2.00 | [ "Lender"×1 ]
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =    82.76 |
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#0    | +    80.76 | Greatest Pure Ada
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    43.73 |
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#0    | +    31.53 | Greatest Pure Ada
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#1    | +     4.00 | Pure Ada
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#2    | +     2.00 | [ "Guarantor"×1 ]
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =     0.00 |
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =    57.00 |
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#2    | +    54.00 | GreatestByTxHavingDatum
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#3    | +     3.00 | Datum

406_guarantor_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron             96.79
    lender            109.16
  borrower             82.76
 guarantor    53.58    97.30
  contract                  
    payout   -54.00     3.00
     TOTAL    -0.42   389.01
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    96.79 |
* 321739a651fd05ee74d9586698c441543c2abbac00e3fe80855de60872d88955#1    | +     2.00 | [ "Patron"×1 ]
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* f268ad03c96e5f48a942e5053dfb3a88f828976381a8c58777797b1f73419862#0    | +    92.69 | Greatest Pure Ada
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =   109.16 |
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#1    | +     4.00 | Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#0    | +    42.80 | Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#1    | +    54.00 | Greatest Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#2    | +     2.00 | [ "Lender"×1 ]
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =    82.76 |
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#0    | +    80.76 | Greatest Pure Ada
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    97.30 |
* 78dc5bfbc7d1005d4355ba23d313a102513cbd7ad36de8f90203f43d2626589e#0    | +    31.10 | Pure Ada
* 78dc5bfbc7d1005d4355ba23d313a102513cbd7ad36de8f90203f43d2626589e#1    | +    54.00 | Greatest Pure Ada
* 78dc5bfbc7d1005d4355ba23d313a102513cbd7ad36de8f90203f43d2626589e#2    | +     2.00 | [ "Guarantor"×1 ]
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#1    | +     4.00 | Pure Ada
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =     0.00 |
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     3.00 |
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#3    | +     3.00 | GreatestByTxHavingDatum

408_patron_withdraws.sh

Output of the script:

The balance after the script run:


==============================
     ALIAS   CHANGE  BALANCE
    patron     2.58    99.37
    lender            109.16
  borrower             82.76
 guarantor             97.30
  contract                  
    payout    -3.00         
     TOTAL    -0.42   388.60
==============================

Snapshot taken after the script run:


--- patron       -----------------------------------------------------------------------------------------------
addr_test1vzynpzgnuws0ghj3n5rwpr8jwd352ralu28pqaglccvatnc0rpe69         | =    99.37 |
* 38ddae21df5d7ab3995254956d0b9ad86fd38f41dc597c415a84c0e07e718237#1    | +     2.10 | Pure Ada
* 8984969342e4d96ba7138feac510953a2206ebf5f580440ecb06bdc23c491f02#0    | +    92.27 | Greatest Pure Ada
* 8984969342e4d96ba7138feac510953a2206ebf5f580440ecb06bdc23c491f02#1    | +     3.00 | Pure Ada
* 8984969342e4d96ba7138feac510953a2206ebf5f580440ecb06bdc23c491f02#2    | +     2.00 | [ "Patron"×1 ]
--- lender       -----------------------------------------------------------------------------------------------
addr_test1vpup4jzflgrml95vlq39ajczpgt30a3aa8q039vg7g82uyc3ajcls         | =   109.16 |
* 1f62ab87a269b060b9e667d125f483ee6cad0a6db5e8262921e751c4d5a36bc4#1    | +     4.00 | Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#0    | +    42.80 | Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#1    | +    54.00 | Greatest Pure Ada
* 5a56af71544e7231e3ebdd6ad25dbabab3c1c8e2660f390f1c4533121910857c#2    | +     2.00 | [ "Lender"×1 ]
* 62a6ea0549dd8f92f8e825b87f5643f2da4a5c9fcc4962c78afe093e14ff1be3#1    | +     4.00 | Pure Ada
* 95c5190b1e9c4a796ccefc562be9f762c2e9572c39d1828f91a1242e0e1ebccb#1    | +     2.36 | Pure Ada
--- borrower     -----------------------------------------------------------------------------------------------
addr_test1vqt83wtgcxpx3sje6uf5m9ydv4nw9fep8358axj769ca0aq4qg082         | =    82.76 |
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#0    | +    80.76 | Greatest Pure Ada
* c4608e0a1c067270956941e4843b6510b1beeb651e0aa7d883a661addf2a1b1b#4    | +     2.00 | [ "Borrower"×1 ]
--- guarantor    -----------------------------------------------------------------------------------------------
addr_test1vzxlp4nzmnj7408jlx7dkpr36cg5aaynccrhan5c6cks2rsautf9z         | =    97.30 |
* 78dc5bfbc7d1005d4355ba23d313a102513cbd7ad36de8f90203f43d2626589e#0    | +    31.10 | Pure Ada
* 78dc5bfbc7d1005d4355ba23d313a102513cbd7ad36de8f90203f43d2626589e#1    | +    54.00 | Greatest Pure Ada
* 78dc5bfbc7d1005d4355ba23d313a102513cbd7ad36de8f90203f43d2626589e#2    | +     2.00 | [ "Guarantor"×1 ]
* 9ead2a35bd2ba59002dc0b5b357d5e8646d3df95943669600f37146842e9849f#1    | +     4.00 | Pure Ada
* a449195b936d2681702af2a6b47bc41dd76e9e18de89e7cc21350bb7a5400d1f#1    | +     2.20 | Pure Ada
* c77f3c54f9cf48f443a73605d197f9bef9378b75860e0b35a9515f67f66c7322#1    | +     4.00 | Pure Ada
--- contract     -----------------------------------------------------------------------------------------------
addr_test1wqtm5f3kl3d7e5z3urultc5n8utcumf63efxw52c0n9k0zggzqx9z         | =     0.00 |
--- payout       -----------------------------------------------------------------------------------------------
addr_test1wqmza7sj0534kalxeqq56tl0wh9qje4fhuj2zlwh4es9h2c5gu5vk         | =     0.00 |
w0802_cbg
220220924

Issue, as posted on discord under the title “Coupon Bond Guaranteed”

Has anybody tried to implement the example “Coupon Bond Guaranteed” on the testnet ? (how to get this example contract: open blockly in the marlowe playground -> open example -> choose “Coupon Bond Guaranteed” as “blockly”)

I’ve tried to implement it using marlowe-cli and cardano-cli on the 1567 testnet, and I kept on failing on the step where the last installment is paid, which is script 402 in following list:

    102_create_contract.sh
    104_lender_funds_contract.sh
    106_guarantor_deposit.sh
    108_lender_deposit.sh
    110_borrower_withdraws.sh
    202_borrower_pays_installment1.sh
    204_lender_withdraws.sh
    206_guarantor_withdraws.sh
    302_borrower_pays_installment2.sh
    304_lender_withdraws.sh
    306_guarantor_withdraws.sh
!!  402_borrower_pays_installment3.sh --> FAILS EVERY TIME !!!
    404_lender_withdraws.sh
    406_guarantor_withdraws.sh 

The error I kept running into: TxBodyScriptExecutionError [(ScriptWitnessIndexTxIn 0,ScriptErrorEvaluationFailed (CekError An error has occurred: User error: The provided Plutus code called ‘error’.) [“R”,“PT5”])]

The problem in step 402 is that 2 separate payments are made to the lender: the principal+instalment AND the minimum_ada (the latter is the amount used to fund the contract).

After lots of experimentation I managed to change the contract such that it succeeds, but I don’t know if this is a desired modification. The included screenshot explains best what I did to get it to work (note: the screenshot only shows the relevant part of the contract).

For ref: cardano-cli 1.34.1 | marlowe-cli 0.0.4.4 | MAGIC=1567

End of message posted on discord

Transcript of both runs

  • For transcript of the run with the modified contract, see w0802s_cbg, this is the one that succeeded.
  • For transcript of the run with the original contract, see w0802f_cbg, this is the one that failed.

Note: the amounts (principal, installment, fund_amount) for the above have been changed, ie. the amounts in the above diagram do not reflect the transcripts.

Update: add another role

Later on in the weekend I discovered that the original contract can be successfully run when introducing another party/role, eg ‘patron’ that funds the contract.

  • The transcript of this run (with the original contract), is here: w0802t_cbg. To confirm: yes this one succeeds.
 
Notes by wmoco. Generated on momo:/home/willem/sync/20220806_wmoco_pubcoms/20220806_marlowe_pioneer at 2023-06-14 18:32