Money, Dex, Liquidity provider and Stable Coins in 20 minutes

8 min readAug 13, 2021

We will try to answer the following questions in less than 20 minutes. The goal is here is to have a basic understanding of money and its future aka DeFi

Why do we need money ? How is it created ? by who ? Is it all virtual ?

Can we create our own money ? how can we make it stable against $ or € ? What are the possible solution to exchange our money for another type of money ?

apes like money

The three functions of money

It is first important to understand why we need money and what problems it solves.

Money as a Store of value

Money as a Medium of exchange

Money as a Unit of account

How money is created ?

Commercial banks can create money from nothing in return for an IOU

It is not customer deposits that are used to finance other loans. Every bank loan creates an equivalent deposit in the bank. Therefore, credit creation means expansion of bank deposits. The entire structure of banking is based on credit.

It also means that when someone repays the loan, the opposite process happens, and money is actually destroyed. It effectively disappears from the economy entirely.

Note that during the bretton woods agreements until August 1971 currency is freely convertible to gold.

It also means that circulating money corresponds to debt. The more debt we have the more circulating money we have.

more credit means more circulating money

Between 5 and 10% of the euro area money is physical. The rest is virtual and called scriptural money.

let’s sum up

Banks create money under certain conditions (should hold some funds and are influenced by the central bank’s rate).

We destroy the money created when we repay to avoid inflation.

Banks pay themselves on credit interest

Now let’s create our own money !

To do so we will simply create a smart contract that implements a simple interface. That way we will be able to transfer the money get a balance, mint (create) and burn (destroy) our money !

Inside that smart contract we will keep track of who owns what.

Needless to say that even though we have the same functions as what we can find with traditional banking we have incredible benefits from using a public blockchain.

Indeed we can’t be stopped. No one can stop us from transferring our money to anyone. Note that If you want to exchange your money into fiat your fund can be frozen as going through an exchange is no more decentralized.

It is open and transparent all the transactions are there for us to see.

It is cryptographically secure. If you generate a private key following the standards in the industry and don’t lose it there is pretty much 0 chance ( actually more like 1 in 2²⁵⁶)that someone can guess it.

What is worth my token ?

My token is worth what people are willing to pay to have it like pretty much everything else ! The more people there is willing to exchange other money four my token the more liquid it will be. The more extreme the price changes are the more volatile our token is.

How can we peg our token to another asset like euro ?

Non-algorithmic stable coins
We can simply store 1 euro in a vault for every token we create ..this is how tether works for instance.

In the end people will have to trust us for storing euros and we can’t say we are trustless and decentralized no more.

collateralized algorithmic stable coins
We can block some asset and based on this collateral value mint some token. For instance we can block 1 Ether worth 1500 euros and mint 1000 token worth 1000 euros.

We don’t mint 1500 tokens because Ether price can move quickly and we don’t want to have a collateral that is worth less that all the minted token because of a rapid price movement. In this example we expect a minimum collateralization ratio of 150%. We could have more collateral but if you go under 150% we put our collateral at risk of being liquidated. Indeed your Ether will be sold at the market price to cover the minted token value.

Maker DAO is the project behind DAI and the mechanics to mint DAI is very similar to what I described above.

As you can see below the DAI is pretty close to the 1 $ peg.

DAI Price

With this kind of stable coin we rely on a oracle to give us the price of DAI compared to the dollar and this can lead to market manipulation or flash loan attack.

Liquidation triggers market sell of the collateral if the market is not liquid enough we can end up selling the collateral way less than what it is really worth.

Moreover it is not capital efficient as the collateral locked is not used to provide liquidity to other protocols and thus doesn’t bring additional yield to the owner.

algorithmic stable coins
They rely on pure economic incentives to maintain the peg.

Basically when the token is worth less than 1$ we let owners burn there tokens in exchange of debt coupons. They will redeem the coupons with a premium later when the token is worth more than 1$.

When the token is worth more than 1$ we simply mint more tokens !

this is basically how Empty Set Dollar (ESD) and Dynamic Set Dollar (DSD) works.

How can we exchange our token ?

Let’s imagine we have apples that we want to trade for potatoes

peer to peer
We can try to find someone willing to exchange his potato for our apple. Even if we can easily setup a discord server it will be difficult to reach a seller and be sure that he still wants to trade. Moreover as this market is not very liquid we will probably end up paying more that a fair price.

Automated Market Maker
Instead we every people with apples and potatoes that are willing to trade will bring them to a known place. This place is a smart contract that will hold apples and potatoes for people to trade. Let’s call this smart contract patateSwap

Smart contract holding potatoes and apples

We will then be able to trade anytime with a fair price.

Liquidity Provider
At first there is noting inside the Smart Contract but Pierre and Paul both have potatoes and apples they want to trade. They will transfer them to patateSwap and thus provide liquidity to this automated market maker.

To keep track of what the liquidity providers provided they will in exchange get Liquidity Provider tokens. Here below we can see that they will each get 5 LP patateSwap token as they both a provided the same amount of potatoes and apples. So Pierre for instance is entitled to 50% of all the tokens that sit on the patateSwap Smart Contract.

Jack now wants to trade an apple for a potato. He will simply swap and does not provide liquidity.

As there is the same amount of potatoes and apples the price of an apple is exactly one potato.

After the trade there is less potatoes compared to the amount of apples that means that the price of potato has increased ! This way anyone can determine the price of an asset just by looking at the Smart Contract reserves.

multiple swaps

After quite some trades here is the state of our patateSwap Smart Contract

There is 20 apples and 4 potatoes now. What happens if Pierre wants to withdraw his liquidity ?

Well pierre still have 5 LP tokens out of 10 total that means that he can withdraw 50% of what is inside the patateSwap SC. He will then get 2 potatoes and 10 apples.

You noticed that he withdraw less potatoes than provided. It is because now potatoes are worth more !

Pierre also got some fees for each trades that happened in the patateSwap. Nonetheless Pierre would have made more money by not providing liquidity. Indeed as a potato is now worth 5 apples and he begun with 5 potatoes. This is what we call impermanent loss.

to calculate the price of a token inside an AMM we have to make sure that the product of each token is the constant defined by the first time we added liquidity.

tokenA_balance(p) * tokenB_balance(p) = k

We can then derive the price following the curve.

When there is 100 ETH there will be 10000 DAI so 1 ETH is worth 100 DAI.

When there is 80 ETH there will be 12500 DAI so 1 ETH is worth 156,25 DAI


The Evolution of the Constant Function Market Maker

Constant Function Market Makers (CFMMs) are the most popular family of AMMs reaching billions of dollars in traded…

Stake DAO Academy

Everything you need to know to get started in DeFi and Crypto. Find out how to earn more on stablecoins and…