π Lanningham

Djed explored

9 min read Premium

Today, a stablecoin called Djed launched on Cardano1. Djed is based on research that IOG published on safe algorithmic stablecoins. Stablecoins are an important part of the DeFi ecosystem, because they’re designed to maintain a stable price relative to USD (or another underlying asset). How it does this can be confusing, so this post will explain how Djed works, and allow you to explore the protocol before you try it for real.

First, let’s talk a little bit of basic economics. The “value” of an asset is a measure of the real world impact it can have, from buying goods and services, to enabling certain access, to increasing your social status, and all manner of things. This is often hard to exactly quantify, and so an asset also has a “price”. The price is an approximation of what the market believes the value of an asset to be. Sometimes it can be wildly inaccurate, and sometimes it can track the changing value of an asset over time.

Value: 0.75 Price: 1.05

A stablecoin, then, is an asset whose price is stable, because the market has confidence that its value is stable. There are a number of ways to build a stablecoin, and each has some mechanism that tries to build up the markets confidence in their ability to redeem that stablecoin for its advertised value.

Let’s slowly build up our own “stablecoin”, ultimately arriving at a system that works the same as Djed.

Our stablecoin will be called Neigh2.

(If the horse puns get to be too much, you can switch to Djed/Shen instead with the switch below.)

Enable Puns

Version 0.1

Version 0.1 of our Neigh stablecoin is a smart contract: Every time you deposit 1 ADA, you are allowed to mint 1 Neigh, and every time you burn 1 Neigh, you get back 1 ADA.

🐎 Seabiscuit:
Balance: 100 ADA 0 Neigh Value: 100 ADA
🐎 Secretariat:
Balance: 500 ADA 60 Neigh Value: 560 ADA

🎉 Congratulations 🎉, we’ve created a “stablecoin” that always equals 1 ADA.

The interactive widget above lets you spend some ADA to mint Neigh, or redeem it for ADA. The chart on the right shows the reserve of ADA, as well as the debt outstanding.

This… isn’t very useful, since you could have just used ADA. But, in an efficient market, this token should always be worth 1 ADA, because buying it above that amount, or selling it below that amount would be doing so at a loss. Let’s see if we can improve things.

Version 0.5

Since the price of ADA isn’t very stable, our “wrapped” token isn’t very stable. Let’s “peg” the price of our asset to USD, by introducing an “oracle” that tells our smart contract how much Neigh to issue for each ADA.

🐎 Seabiscuit:
Balance: 100 ADA 0 Neigh Value: 105 USD
🐎 Secretariat:
Balance: 500 ADA 60 Neigh Value: 585 USD

Now, if you exchange some ADA for some Neigh, you’ll notice that the total value (in USD) of your portfolio becomes more stable. And this is because I know that, even if I buy 100 Neigh today, and the price of ADA drops, I’ll be able to redeem it for $100 worth of ADA in the future.

We’ve introduced a problem now; Try using the controls under the price chart to mint some Neigh while the price of ADA is high, and then bring the price low.

You’ll notice that the protocol becomes “Insolvent”. This means that, if everyone were to try to redeem their Neigh, we wouldn’t have enough ADA to satisfy everyone’s requests. The protocols debt exceeds our ability to pay that debt. This becomes a self-fulfilling property, because Neigh holders lose confidence in the price, and everyone tries to redeem, exacerbating the problem. This is known as a “bank run”. We saw several very public examples of this in 2022 with LUNA and FTX.

For example, suppose the protocol issues 1000 Neigh at $1 USD, and so it has 1000 ADA in the reserve. If the price of ADA drops to $0.50, then the reserve is only worth $500 USD, with $1000 USD of outstanding debt. In this case, only the first 500 Neigh redeemed would return $1 USD, and the second 500 Neigh would be unredeemable. This creates a panic’d rush to be the first to withdraw, creating a self-perpetuating outcome that spells the death of confidence in the protocol.

Unlike those other protocols, however, while insolvent Neigh will honor redemptions at a fractional percentage. So if the protocol only has 90% of the collateral needed to satisfy it’s debt, then it will allow you to burn Neigh for 90% of it’s original value.

Returning to our example above, the protocol has enough collateral to cover 50% of it’s debt. So, if I burned 100 Neigh, I’d receive $50 USD worth of ADA, or 100 ADA. This reduces the reserve by 100 ADA (to 900 ADA / $450 USD), but also reduces the debt by an equivalent amount, to 900 Neigh. The protocol is still at a 50% collateral ratio.

This creates a smooth ride to the bottom, and removes the incentive to rush to exit if you believe the price of ADA will recover. And if it does recover, you’re back to a $1 USD peg.

Still, the goal should be to make this an extremely rare event. The key, then, is to incentivize the protocol to over-collateralize, maintaining a reserve that is larger than what is strictly needed to cover the protocols debt. Here’s where the magic happens: We can introduce a second, complementary coin (called Whinny) to incentivize the protocol to maintain a very large reserve.

Version 0.8

In the version below, you can mint a new token, Whinny. Whinny represents some fractional ownership of the surplus ADA in the protocol. If you’re familiar with how a DEX operates, it’s very similar to the token you get when you provide liquidity to a pool.

🐎 Seabiscuit:
Balance: 100 ADA 0 Neigh 0 Whinny Value: 105 USD
🐎 Secretariat:
Balance: 500 ADA 60 Neigh 100 Whinny Value: 945 USD

Let’s think through what happens in various scenarios. Feel free to play with the controls above to see this happen for yourself!

We’ll assume the price of ADA is $1 USD, the protocol has issued 400 Neigh, and currently has 900 ADA in the reserve. There are 500 Whinny in circulation.

Then, you deposit 100 ADA, bringing the reserve to 1000 ADA. The protocol has a 400 USD debt to honor, leaving 600 ADA as equity. Since you deposited 1/6th of that, you’ll be issued 100 Whinny tokens, bringing the total circulation to 600 Whinny.

If you were to burn those Whinny, you’d get back 1/6th of the reserve: 100 ADA. We’ll ignore the minting and burning fees for the sake of clarity.

If, instead, you were to hold the Whinny, and the ADA price rose to $2 USD. The protocol still has a $400 USD debt to honor, but this can now be paid with 200 ADA, instead of 400 ADA. The protocol still has a total of 1000 ADA in the reserve, so the equity is now 800 ADA.

You still have 1/6th of the supply, so if you redeem your Whinny tokens now you’ll receive around 133 ADA.

Not only did you benefit from the rise of the price from $1 USD to $2 USD (taking your 100 ADA from $100 USD to $200 USD), but you also increased the amount of ADA you hold, from 100 ADA to 133 ADA. Your total USD value went from $100 USD to $266 USD.

Conversely, if we assume instead that the price of ADA drops from $1 USD to $0.5. The protocol’s $400 USD debt now needs 800 ADA to satisfy it, leaving 200 ADA as equity.

Your 1/6th of the supply is around 33 ADA. Your total USD value dropped from $100 USD to around $15 USD.

Minting Whinny comes with large potential upside, but also significant risks. Still, it creates an economic incentive to over-collateralize the protocol, creating an opportunity for leverage on the underlying asset for speculators.

The protocol above is already much harder to make insolvent, but it’s still possible by pushing it just to the limit, and waiting for the price to dip down.

The final step is to provide some safeguards to ensure the protocol doesn’t get over or under collateralized.

Version 1.0

Those safeguards disable or enable minting or burning of Neigh or Whinny depending on how collateralized the protocol is.

  • If the debt is more than 1/4th of the reserve, you are no longer able to mint Neigh (increasing the debt) or burn Whinny (decreasing the surplus). This prevents insolvency.
  • If the debt is less than 1/8th of the reserve, you are no longer able to mint Whinny. This prevents diluting the incentive of holding Whinny too much.
🐎 Seabiscuit:
Balance: 100 ADA 0 Neigh 0 Whinny Value: 105 USD
🐎 Secretariat:
Balance: 500 ADA 60 Neigh 100 Whinny Value: 945 USD

Other than minting and burning fees, which provide additional yield to Whinny holders, and a few other small details, the protocol above is the minimal Djed stablecoin. Neigh is called “Djed”, and Whinny is called “Shen”.

With strong confidence in the ability to redeem Djed for the appropriate value of ADA, Djed’s price is also stabilized at one USD.

Hopefully this helped you develop a deeper understanding of how Djed works, where it derives its price from, and what the potential upsides and risks are.


  1. Technically, what’s launching and what is described here is “Minimal Djed”; Keep an eye out for a part two that talks about Extended Djed, and what the differences are.
  2. Hay, apologies for saddling you with that foal pun. It behooves me to let you know that its just a bit, I promise.

π Lanningham

I’m π, a mathematician by passion, and a software engineer by trade. I'm most well known for my role as CTO at SundaeSwap Labs, and for my passion for educating people. I run a Cardano Stake pool, known as 314pool. I've also written a few blog posts on topics that I feel I can explain well, which you'll find below.