
Blockchain for Enterprise
People tend to overestimate how easy it is to create a blockchain. Just because you were able to deploy a network doesn’t make you an expert on blockchain. As a matter of fact, even an intern can do it in minutes. Here, try it. You know what else is easy to deploy? A webpage. Creating a blockchain is easy, and you can do it at zero cost and effort for as long as you don’t care about the design and spec of your network. Understanding the engineering constraints to design a secure and functiona...

ZK Proofs Part II: ZK Maths
Standing before Danki today are ghosts of the audit reports I haven’t read and dat job hunt I’ve been meaning to do for weeks now… but in the name of mighty procrastination, let’s write something totally fun but completely unrelated to everything I needed to do: ZK maths frens. If you have no idea what this is all about and why danki is so happy as my hooves type dis post, then check out Part I. But if you’re too lazy to click… ZKP or Zero Knowledge Proofs is a cryptographic mechanism that al...

Demystifying the Quantum Threat
In da past two weeks, I have encountered at least 3 people who talk about quantum menace as if it will be the end of all existing blockchains today. So here are some facts: -Majority of the hashing functions used to generate private keys for blockchain addresses are using Elliptic Curve Cryptography which is NOT quantum safe. It means digital signatures may be forged to make transactions on behalf of an account. This is probably where they’re coming from. -Hashing algorithms like Keccak256 ar...
Crypto things



Blockchain for Enterprise
People tend to overestimate how easy it is to create a blockchain. Just because you were able to deploy a network doesn’t make you an expert on blockchain. As a matter of fact, even an intern can do it in minutes. Here, try it. You know what else is easy to deploy? A webpage. Creating a blockchain is easy, and you can do it at zero cost and effort for as long as you don’t care about the design and spec of your network. Understanding the engineering constraints to design a secure and functiona...

ZK Proofs Part II: ZK Maths
Standing before Danki today are ghosts of the audit reports I haven’t read and dat job hunt I’ve been meaning to do for weeks now… but in the name of mighty procrastination, let’s write something totally fun but completely unrelated to everything I needed to do: ZK maths frens. If you have no idea what this is all about and why danki is so happy as my hooves type dis post, then check out Part I. But if you’re too lazy to click… ZKP or Zero Knowledge Proofs is a cryptographic mechanism that al...

Demystifying the Quantum Threat
In da past two weeks, I have encountered at least 3 people who talk about quantum menace as if it will be the end of all existing blockchains today. So here are some facts: -Majority of the hashing functions used to generate private keys for blockchain addresses are using Elliptic Curve Cryptography which is NOT quantum safe. It means digital signatures may be forged to make transactions on behalf of an account. This is probably where they’re coming from. -Hashing algorithms like Keccak256 ar...
Crypto things
Share Dialog
Share Dialog

Subscribe to Danki

Subscribe to Danki
<100 subscribers
<100 subscribers
I took a vacation.
Well, not really. I was reading codebases everyday and practically lost track of the days. And the further I went, the harder it was to explain what the hekk iz Danki up to. I was already deep into Curve’s Stableswap Equation when I realized that almost a week has already passed.
So here I am frens, doing my best attempt to catch you up.
Now the story. It all started with Constant Product Market Makers…
If you’re swapping your USDT for ETH on say, Uniswap v1, then USDT doesn’t magically transform into ETH tokens through some wizard program. No na no… instead da ETH is already stored somewhere, as well as the USDT you just deposited. And that ‘somewhere’ is called a liquidity pool.
In the USDT-ETH example, a liquidity pool works like this:
Somebody initially supplies two tokens in the pool, in equal value
As users like you start swapping their tokens in the pool, the ratio of the two tokens change
But the total liquidity remains the same, just the ratio is different
The price of one token is computed by the ratio of its supply with the other token.
…And this liquidity is expressed in the famous Constant Product MM equation:
x * y = kWhere x is the amount of token1, y is the amount of token2, and k is the liquidity of the pool.
So the price of each token changes as people swap because the ratio in the liquidity pool changes.
Say, somebody initially supplied 10,000 USDT and and 5 ETH in the pool:

At this point, if we use x y = k, then k = 10,000 * 5 (which is 50,000). And the ratio will be 2,000 USDT per 1 ETH
Now, enter you, and you wanna swap your 2000 USDT for ETH. Let’s ignore fees for now. How will this affect the pool and at what price will you get your ETH?
Well, you are practically adding 2000 USDT in the pool which should correspond to a change in the amount of ETH. ETH will decrease in order for k to stay constant.

Then, the market maker will solve for the amount of ETH it will give you:
k = 50,000 = (10,000 + 2,000) * (5 + dx)
dx = -0.833333 ETH
ETH supply in the pool will decreased by 0.833333, which is the amount they’ll give you for the 2000 USDT you deposited
“But why 0.8333333, I thought the price is at 2000 USDT per 1 ETH!”
Were you cheated? Not really, because the ratio of USDT per ETH was going up as you were adding more USDT to the pool, bringing the price of ETH higher than what was initially shown… And dat, frends, is called the price impact of your trade.
And because price is computed by the two token’s ratio in the pool, the lower the k value or liquidity, the bigger the price impact of each swap.
In traditional finance, you can also recognize the same phenomenon where the low-volume assets are more volatile. In their case, instead of an algorithm, the market makers are the hedge funds (except the hedgies got alpha but that’s for another story lol).
Anyway, the amount of tokens in the pool is not only affected by swaps. Liquidity in the pool can also be removed or added.
When somebody provides liquidity to a protocol, they get minted what is called an LP Token. The LP token represents the percentage of liquidity that the user owns in the pool. This keeps track of how much of the pool they can withdraw and the share of rewards they get from the collected fees.
Ok, let’s see this in action.
Say, your good frend Marites supplied 5 more ETH and 10,000 USDT to the pool at the current rate of 2000 USDT per 1 ETH.
The pool had 5 ETH and 10,000 USDT before and had minted 10 LP tokens to its providers, and now that Marites added to it, it has 10 ETH and 20,000 USDT. Rich frend Marites now owns 50% of the pool, and she gets minted 10 LP tokens for that. Now she owns 10 out of the 20 LP tokens.
If Marites wanted to withdraw her share of the pool, she will burn the 10 LP tokens.
But will Marites get the exact same 5 ETH and 10,000 USDT she deposited?
99% of the time, she will not. Instead she will get her two tokens in whatever ratio the pool currently has after users have swapped tokens in it. This could result to impermanent loss.
I wanna talk about impermanent loss, but das a long topic that I reserve for investors, traders, and degens in DeFi Philippines. If you wanna know more about the benefits and risks of providing liquidity to a Constant Product AMM, wait for my post in there!
It might sound amazing on paper, but the reality iz Constant Product MMs are very inefficient in managing liquidity.
Most of the liquidity in the pool will fall on the extreme ends of the curve where they aren’t utilized. Meanwhile, price impact is still huge in the middle range where most of the trades happen. So the newer dexes and protocols use a different model to remedy this inefficiency… and that’s what I actually wanna talk about. haha
But at least now you understand how the most basic form of AMM works, and we can move on to the real exciting part. We’re gonna talk modern market maker models in the next posts! 🐎✨
I took a vacation.
Well, not really. I was reading codebases everyday and practically lost track of the days. And the further I went, the harder it was to explain what the hekk iz Danki up to. I was already deep into Curve’s Stableswap Equation when I realized that almost a week has already passed.
So here I am frens, doing my best attempt to catch you up.
Now the story. It all started with Constant Product Market Makers…
If you’re swapping your USDT for ETH on say, Uniswap v1, then USDT doesn’t magically transform into ETH tokens through some wizard program. No na no… instead da ETH is already stored somewhere, as well as the USDT you just deposited. And that ‘somewhere’ is called a liquidity pool.
In the USDT-ETH example, a liquidity pool works like this:
Somebody initially supplies two tokens in the pool, in equal value
As users like you start swapping their tokens in the pool, the ratio of the two tokens change
But the total liquidity remains the same, just the ratio is different
The price of one token is computed by the ratio of its supply with the other token.
…And this liquidity is expressed in the famous Constant Product MM equation:
x * y = kWhere x is the amount of token1, y is the amount of token2, and k is the liquidity of the pool.
So the price of each token changes as people swap because the ratio in the liquidity pool changes.
Say, somebody initially supplied 10,000 USDT and and 5 ETH in the pool:

At this point, if we use x y = k, then k = 10,000 * 5 (which is 50,000). And the ratio will be 2,000 USDT per 1 ETH
Now, enter you, and you wanna swap your 2000 USDT for ETH. Let’s ignore fees for now. How will this affect the pool and at what price will you get your ETH?
Well, you are practically adding 2000 USDT in the pool which should correspond to a change in the amount of ETH. ETH will decrease in order for k to stay constant.

Then, the market maker will solve for the amount of ETH it will give you:
k = 50,000 = (10,000 + 2,000) * (5 + dx)
dx = -0.833333 ETH
ETH supply in the pool will decreased by 0.833333, which is the amount they’ll give you for the 2000 USDT you deposited
“But why 0.8333333, I thought the price is at 2000 USDT per 1 ETH!”
Were you cheated? Not really, because the ratio of USDT per ETH was going up as you were adding more USDT to the pool, bringing the price of ETH higher than what was initially shown… And dat, frends, is called the price impact of your trade.
And because price is computed by the two token’s ratio in the pool, the lower the k value or liquidity, the bigger the price impact of each swap.
In traditional finance, you can also recognize the same phenomenon where the low-volume assets are more volatile. In their case, instead of an algorithm, the market makers are the hedge funds (except the hedgies got alpha but that’s for another story lol).
Anyway, the amount of tokens in the pool is not only affected by swaps. Liquidity in the pool can also be removed or added.
When somebody provides liquidity to a protocol, they get minted what is called an LP Token. The LP token represents the percentage of liquidity that the user owns in the pool. This keeps track of how much of the pool they can withdraw and the share of rewards they get from the collected fees.
Ok, let’s see this in action.
Say, your good frend Marites supplied 5 more ETH and 10,000 USDT to the pool at the current rate of 2000 USDT per 1 ETH.
The pool had 5 ETH and 10,000 USDT before and had minted 10 LP tokens to its providers, and now that Marites added to it, it has 10 ETH and 20,000 USDT. Rich frend Marites now owns 50% of the pool, and she gets minted 10 LP tokens for that. Now she owns 10 out of the 20 LP tokens.
If Marites wanted to withdraw her share of the pool, she will burn the 10 LP tokens.
But will Marites get the exact same 5 ETH and 10,000 USDT she deposited?
99% of the time, she will not. Instead she will get her two tokens in whatever ratio the pool currently has after users have swapped tokens in it. This could result to impermanent loss.
I wanna talk about impermanent loss, but das a long topic that I reserve for investors, traders, and degens in DeFi Philippines. If you wanna know more about the benefits and risks of providing liquidity to a Constant Product AMM, wait for my post in there!
It might sound amazing on paper, but the reality iz Constant Product MMs are very inefficient in managing liquidity.
Most of the liquidity in the pool will fall on the extreme ends of the curve where they aren’t utilized. Meanwhile, price impact is still huge in the middle range where most of the trades happen. So the newer dexes and protocols use a different model to remedy this inefficiency… and that’s what I actually wanna talk about. haha
But at least now you understand how the most basic form of AMM works, and we can move on to the real exciting part. We’re gonna talk modern market maker models in the next posts! 🐎✨
No activity yet