Project quickstart - A question?

I am analyzing this project daml new quickstart --template quickstart-java

Here are some doubts, if the Bank grants a balance of 100 euros for Alice, how can it be that Alice can continue issuing 2 promissory notes of 60 euros each that exceed her limit of 100.

This project is just a test of how the templates work and in real life, you should see some control mechanism to not overdraw more than what Alice has which is 100 euros.

In the image, you can see that I have transferred to Bod two promissory notes of 60 euros each, which together give 120 euros, more than what Alice has.

Who should do the balance limit control, the application, or the smart contract that I want to develop?

Thank you for your help.

2 Likes

Hi magzupao

This example is about IOUs and parties are equal in the choices that they can exercise on them. Any party can create a new IOU of any amount and transfer it to any other party. If Bob does not trust Alice but he trusts the EUR_Bank, Alice can split her IOU from the EUR_Bank to 60+40 and transfer the resulting 60 EUR IOU to Bob.

You can control the balance limit by modelling the Bank, Account and Deposit in Daml, you don’t need to create any other application code for it.

2 Likes

Elaborating on @Mate_Varga’s answer:

The two crucial points here are the issuer and more generally signatories. If you look at the code for the Iou template, you can see that it has both the issuer and the owner as signatories. Alice can create an arbitrary number of self-issued Ious where she is both the issuer and the owner and that appears to be what has happened in your example. However, other parties can see that those Ious have been issued by Alice rather than USD_Bank which probably means that they won’t place any value in those Ious.

What Alice cannot do is to turn the 110$ Iou issued by USD_Bank into two Ious also issued by USD_Bank with a combined value that is higher than 110$. That’s prevented by the model. The only choice on Iou that Alice can issue are Iou_Split which preserves value, Iou_Mergewhich preserves value of the two merged Ious andIou_Transfer` which also preserves the value.

1 Like

Hello, could you give an example of how this condition can be fulfilled:

Bank issues 100 → Alice has 100 → Alice transfers to Bob 60.

Where I see that Alice has 40 balance.

Thanks

1 Like

You can see this (Alice transferring 40 to Bob and having 60 left) in the Tests/Iou.daml file of the project if you run the Scripts there (by clicking on “Script results”)

image

The relevant code is:

  -- Alice splits the IOU and transfers part of it to Bob.
  split <- submit alice do
    exerciseCmd iouAliceCid Iou_Split with splitAmount = 40.0
  iouTransferCid <- submit alice do
    exerciseCmd (fst split) Iou_Transfer with newOwner = bob

You can then check off “Show archived” on the Script tab and you’ll be able to see this happened:

image

If you look through you’ll see that old contracts get archived (represented by a strikethrough) and can no longer be used. So when Alice splits her money and sends it to Bob she can no longer access her original 100 USD (id #2:1) as it gets archived during the split. The 40 USD she sends to Bob also gets archived (id #4:1) and when Bob combines his 40 USD (id #6:1) with his existing 30 USD from Acme to that gets archived as well and he has a new IOU for USD from Acme in the amount of 70 USD (id #7:3)

This code does some other things as well but as you can see when “Show archived” is unchecked the ledger still sums correctly with the total balance of the 130 USD issued between Alice and Bob still equaling 130 (note contract id #11:1 here is referring to another test where EUR was issued).

image

2 Likes

Elaborating a little bit more on the meaning behind this code, we need to consider what money is. Let’s take a step back, through history.

At some point, people decided that gold was valuable. (Don’t ask me why.) But transporting it was inconvenient (it’s heavy), so people decided to trust “banks” to hold their gold for them, and when they needed to pay, instead of giving other people nuggets of gold, they would give them signed papers that said “you can go and take gold from my account at this bank”.

As time went by, standardization occurred. Countries decided to create central banks, and commercial banks decided to trust central banks to hold their gold. Over time, people got comfortable with the idea that a note that allows you to take gold from a bank account is pretty much as good as the gold itself, and actually exchanging notes for gold became more and more rare. People just traded the paper notes directly.

Then the central banks decided to get rid of their gold, and nobody noticed. People just kept trading stuff and services for paper notes.

Anyone can take a piece of paper and write “100 USD” on it. But we’ve all agreed that we only trust the US Federal Reserve to print “valid” USD notes. Similarly, we’ve all agreed to trust the European Central Bank to print “valid” Euro notes.

Let’s ignore the possibility of fraud and assume that signatures can easily be checked for validity. If I come to you and give you a note that says “100”, you will give it a different value based on who signed it: if it was signed by the US Federal Reserve, you’ll take it as being worth 100 USD. If it was signed by the European Central Bank, you’ll take it as being worth 100 EUR. If it was signed by me personally, you’ll have to decide for yourself how much trust you put into that. Maybe I have a really good reputation. Maybe you’ve never heard of me.

This concept of “who signed it”, fully separate from “who currently owns it”, is what the “issuer” in that template represents.

In princple, there is nothing special about the US Federal Reserve, and in a Daml system, they would just be another Party. It’s up to Bob to decide which issuers he trusts.

So what’s the value-add from Daml? In this case, the value is that if Bob trusts Acme Bank (the issuer), Bob does not need to trust Alice (the current owner) in any way to be confident that the money he is receiving is valid, has not been double spent, etc.

This is pretty much the same situation as in the real world (except forgery is much harder): you can trust a $100 note not because you trust the person who gives it to you, but because you trust the US Federal Reserve (and the fact that they engineered those notes to be hard to forge).

With this additional context, hopefully it should no longer be surprising that Alice can create as much money as she wants. It’s just that the issuer for that money will be Alice, and presumably not many people will decide to trust her on that.

1 Like