Fungible tokens 101
✏ 2022-08-05 ✂ 2022-08-05Introduction
I am currently involved in the effort to deliver the ICRC-1 fungible token standard for the Internet Computer.
The two topics the Ledger & Tokenization working group discussed most heatedly are the use of subaccounts and the core payment flow for smart contracts (in particular, the approve
/transferFrom
flow popularized by the ERC-20 token standard).
At first glance, these issues seemed unrelated, but surprising connections revealed themselves under closer scrutiny, begging for analysis and exploration.
This article is a gentle introduction to fungible tokens and ledgers. We shall frame the concept of the ledger and options available when designing a practical accounting system, laying the ground for more subtle technical topics that will come in future articles.
Fungible tokens
Gold is gold everywhere, fungible and indifferent. But when a disk of gold is stamped by a coiner with certain pompous words and the picture of a King, it takes on added value—seigneurage. It has that value only in that people believe that it does—it is a shared phant’sy.
The concept of fungible tokens is ancient and intimately familiar to us, though we rarely use this learned term of latin origin in everyday life. Fungible tokens are interchangeable items you can trade, such as coins of equal value or gold pieces of identical form, weight, and purity.
When you bought ice cream as a kid, you traded one fungible token (fiat money) for another (ice cream). The salesperson at the store did not care where your coins came from. Maybe your aunt gave you some to buy a treat, or perhaps you saved some from your lunch money. You did not care which instance of the desired sort of ice creamMy absolute favorite is Plombières. you would get.
Asset ledgers
The most prominent examples of fungible tokens in the digital world are digital assets such as Bitcoin, Ether, and ICP utility tokens. An asset ledger is a concept lying at the heart of these systems. Ledgers are journals of transactions the system executed; they keep track of fund movements between accounts. Each purchase you make using bitcoin becomes a record in the Bitcoin ledger packed into a block in the blockchain.
My nerdy ex-colleagues from Yandex used to use a simple ledger to keep track of tip money. I will use and evolve their scheme to demonstrate the concept of a ledger and its variations.
Geneviève works in a small accounting firm.
One day she goes into a small restaurant with two of her colleagues, Allen and Meriam.
They get a fantastic meal and decide to tip $20.
Unfortunately, Allen and Meriam do not have $6.66 to share the burden equally.
So they get a notebook, write Ledger
on the cover, and split the first page into three columns.
Then Allen and Meriam transfer Geneviève imaginary money on that ledger.
From | To | Amount |
---|---|---|
Allen Brook | Geneviève Bardot | $6.66 |
Meriam Bone | Geneviève Bardot | $6.66 |
Now Allen and Meriam have -$6.66 on their accounts
, and Geneviève has $13.32.
The next day, they go to a coffee shop and tip $15.
This time Allen pays for everyone, and Geneviève and Meriam add new entries to the ledger.
From | To | Amount |
---|---|---|
Allen Brook | Geneviève Bardot | $6.66 |
Meriam Bone | Geneviève Bardot | $6.66 |
Geneviève Bardot | Allen Brook | $5.00 |
Meriam Bone | Allen Brook | $5.00 |
Now Allen has $3.34 on his account, Geneviève has $8.32, and Meriam has -$11.66 To compute a person’s balance, go over all the records in the log from top to bottom. If the person appears in the from column, subtract the amount from their balance; if the person appears in the to column, add the amount to their balance. . This ledger has an interesting property: the sum of all balances is always zero because we started with no funds, and each record only moves funds.
This simple scheme describes a fully functional and practical ledger that helps balance the financial burden of tipping. The person with the lowest balance on the ledger pays for the whole company when they go out.
The tip ledger is unusual because it allows negative balances like credit cards. This setup works well when all the participants know and trust one another. Digital ledgers such as Bitcoin are like debit cards: you must have enough tokens on your account before transferring them. But how do the first tokens get into the system?
Minting and burning
All ledgers have a way to produce, or mintDid you know that Sir Isaac Newton worked at the Royal Mint for three decades?, tokens out of thin air. Bitcoin network mints tokens as a reward for participants that help the ledger grow. The IC mints ICP utility tokens to reward participants in the network governance and node providers.
Another popular scheme is wrapped tokens, where the ledger mints tokens as proxies for other assets. Let us extend the tip ledger example to make it operate on wrapped dollars.
Imagine now that Geneviève does not trust the folks she hangs out with, but she wants to continue enjoying the convenience of virtual money. Whenever someone transfers her virtual tokens on a piece of paper, she wants to be sure she can claim her buck back.
One way to approach the issue is to set up a piggy bank at the office. Anyone who puts $1 into the bank gets a wrapped $1 on the ledger. The transaction converting a physical bill into a virtual token is a mint transaction.
One day Geneviève, Allen, and Meriam put $10 each into the piggy and mint their wrapped money on the ledger.
From | To | Amount | Piggy bank |
---|---|---|---|
— | Geneviève Bardot | $10.00 | $10.00 |
— | Allen Brook | $10.00 | $20.00 |
— | Meriam Bone | $10.00 | $30.00 |
Then they all go to a coffee shop where Geneviève tips $6 for the group. Allen and Meriam transfer their shares to Geneviève on the ledger.
From | To | Amount | Piggy bank |
---|---|---|---|
— | Geneviève Bardot | $10.00 | $10.00 |
— | Allen Brook | $10.00 | $20.00 |
— | Meriam Bone | $10.00 | $30.00 |
Allen Brook | Geneviève Bardot | $ 2.00 | $30.00 |
Meriam Bone | Geneviève Bardot | $ 2.00 | $30.00 |
The main difference with the original scheme is that now Geneviève can exit the group and get her money back at any point. All she needs is to open the piggy under a supervision of a trusted party, get her $14, and record a burn transaction on the ledger by sending her tokens to the void (sometimes called the minting account). The sum of all balances on the ledger is always equal to the amount of money in the piggy bank.
From | To | Amount | Piggy bank |
---|---|---|---|
— | Geneviève Bardot | $10.00 | $10.00 |
— | Allen Brook | $10.00 | $20.00 |
— | Meriam Bone | $10.00 | $30.00 |
Allen Brook | Geneviève Bardot | $ 2.00 | $30.00 |
Meriam Bone | Geneviève Bardot | $ 2.00 | $30.00 |
Geneviève Bardot | — | $14.00 | $16.00 |
Wrapped tokens are not a recent invention: the U.S. dollar was a wrapped token for 1.50463 grams of gold in 1873.
Subaccounts
Geneviève and her colleagues have a tradition: when someone has a birthday, other colleagues raise funds to buy a little present. Next week Allen turns thirty-three, so the department asked Geneviève to buy something nice for him. This time they decided to use the piggy bank ledger discussed in the previous section to transfer funds for the present. However, there is one little issue: if everyone transfers gift money to Geneviève directly, how will she separate her money from the gift money?
Our clever office folks decided to add a new feature to the ledger to address the fund separation problem. Everyone can hold multiple disjoint accounts on the ledger and move funds from any of those accounts. A subaccount will be a label demarcating independent accounts belonging to the same person.
Geneviève asks colleagues to transfer funds to her NYYRA OVEGUQNL
Geneviève applied advanced cryptography to hide the purpose of the subaccount from Allen. subaccount until the end of the day.
She burns the tokens on her NYYRA OVEGUQNL
subaccount and withdraws $42.00 from the piggy bank right before leaving the office.
From | Subaccount | To | Subaccount | Amount | |
---|---|---|---|---|---|
⋯ | |||||
Geneviève Bardot | — | Geneviève Bardot | NYYRA OVEGUQNL | $15.00 | |
Meriam Bone | — | Geneviève Bardot | NYYRA OVEGUQNL | $15.00 | |
Rüdiger Bachmann | — | Geneviève Bardot | NYYRA OVEGUQNL | $12.00 | |
Geneviève Bardot | NYYRA OVEGUQNL | — | — | $42.00 |
Geneviève heads to the book store and buys the latest edition of The Goal by Eliyahu M. Goldratt. What a great birthday present!
Overall, subaccounts are a helpful feature allowing you not to put all your tokens in a single basket. Your bank likely opened more than one account for you, such as a salary and a savings account.
Approvals
One day Geneviève’s nephew, Alex, comes to visit her at work. Geneviève has an important call with a customer and could not take Alex out for lunch. Her colleagues were happy to go out with Alex, but there was a little problem: Alex did not have money.
Luckily, Geneviève accumulated quite some balance on the ledger, so someone could pay for Alex and get her ledger money back in exchange. All that was left is to formalize this arrangement on the ledger.
Geneviève could transfer some budget to Alex before he goes out, and he could transfer her the leftover when he is back. That solves the problem, but Geneviève cannot use the locked funds herself during that time because, technically, they belong to Alex.
Another approach popularized by the Ethereum community is to introduce the notion of approvals. The ledger could have another table with spending allowances between two people.
From | To | Allowance |
---|---|---|
Geneviève Bardot | Alex Schiller | $25.00 |
With this record, Alex can transfer money on behalf of Geneviève up to the allowance.
Alex had a lot of fun with Geneviève’s colleagues and spent $16.00 at a coffee shop. Allen paid for Alex, and Alex transferred some of Geneviève’s tokens to Allen in return. This arrangement resulted in two updates to the ledger. The first update is the new transaction in the log. Note that we need a new column in the table, on behalf of, to indicate that Alex initiated the transaction, but Geneviève is the effective payer.
From | On behalf of | To | Amount | |
---|---|---|---|---|
⋯ | ||||
Alex Schiller | Geneviève Bardot | Allen Brook | $16.00 |
The second update lowers the allowance in the approval table by the amount Alex spent.
From | To | Allowance |
---|---|---|
Geneviève Bardot | Alex Schiller | $25.00 |
Geneviève Bardot | Alex Schiller | $ 9.00 |
Fees
Peppy was a lovely five-year-old girl who came to the office space to see how her mother, Meriam, spends her days. Peppy loved numbers, could write her name, and was unusually rational for her age. Her favorite game was finding holes in ad-hoc rules that grown-ups invent all day. Her eyes caught a little devilish fire when she saw how her mother used the ledger notebook.
How much can I send you, Mom?
asked Peppy.
No more than you have on your account,
replied Meriam.
I don’t have anything yet. Can I send nothing?
Ahm… Well, there are no rules prohibiting that, I suppose.
Peppy grabbed a pen and started filling the lines with blocky letters.
From | To | Amount | |
---|---|---|---|
⋯ | |||
PEPPY | MOM | $0 | |
PEPPY | MR ALLEN | $0 | |
PEPPY | MOM | $0 |
OK, Peppy, stop. There is a new rule: you cannot transfer nothing. Only a positive amount.
Peppy stopped. A few wrinkles appeared on her forehead, and then her lips curled into a smile. She opened her little backpack with tiger stripes and fetched a nickel she found on the street a few days ago. She put the nickel into the piggy bank and recorded a mint. She did not stop there, however.
From | To | Amount | |
---|---|---|---|
⋯ | |||
— | PEPPY | $0.05 | |
PEPPY | PEPPY | $0.05 | |
PEPPY | PEPPY | $0.05 |
OK, Peppy, a new rule: you can’t transfer to yourself. There is no reason to do that!
Peppy knit her brows, struggling to come up with a counter-action. Ten seconds later, she was scribbling again. She was so focused that the tip of her tongue stuck from her mouth.
From | To | Amount | |
---|---|---|---|
⋯ | |||
PEPPY | MOM | $0.0001 | |
PEPPY | MR ALLEN | $0.0001 |
It’s not funny, Peppy. From now on, every record will cost the sender a penny.
Peppy pursed her lips, wrote four more records to the notebook, and visited Mrs. Geneviève, who had a chocolate bar in her upper drawer.
Fees are an essential instrument in ledger design. The bitcoin network uses fees to protect the system against spam transactions and incentivize the nodes to include transactions into blocks. The higher the fee the transaction sender is willing to pay, the more likely the nodes to process the transaction. The ICP ledger also uses fees as a mechanism for spam prevention.
Summary
We have seen that fungible tokens are an essential part of our daily life. We learned that ledger is a robust accounting mechanism that we can adapt to the task at hand by adopting various features: mints, subaccounts, approvals, and transfer fees. In the following article, we will discuss protocols allowing clients to exchange tokens for service, known as payment flows.