Let's use this transaction as an example:
https://bscscan.com/tx/0xdd38b435d9840062db9106e23712873fa2da44c366fa737b17f7fc6d111ef076#eventlog
Here 172054109197
Zombie tokens were transferred to Zombie / BUSD LP in exchange for 6357581284196624466
BUSD tokens.
Here is the Swap event:
amount0In: 172054109197
amount1In: 0
amount0Out: 0
amount1Out: 6357581284196624466
If we look at both (Zombie, BUSD) contracts, they both use 18 decimals
, i.e. we can think of these values as:
0.000000172
Zombie traded for 6.3575
BUSD
To understand the price impact, we need to look at the Zombie / BUSD LP reserves before and after the transaction.
Before:
reserve0: 1203765031
reserve1: 6402195517789394391
After:
reserve0: 173257874228
reserve1: 44614233592769925
We know (by looking at the LP contract) that reserve0
represents Zombie token and reserve1
represents BUSD token.
As we traded Zombie for BUSD, we have to add the amount being traded in to the first reserve and deduct the amount being traded for from the second reserve, i.e.
reserve0: 1203765031+172054109197=173257874228
reserve1: 6402195517789394391+6357581284196624466=44614233592769925
This is how the Swap affected the reserves and therefore the price ratio.
You will lose money. Here's why - Since most liquidity pools do not have external oracles to tell them the price ratio between two assets, they rely on participants providing the correct ratio. If you were to, as you say in your example, deposit 1 USDT and 1 ETH into a ETH/USDT pool, you would effectively be stating that you value 1 ETH to be worth 1 USDT. This is obviously not the case, and an external arbitrageur would quickly provide 1 USDT to the pool in exchange for your 1 ETH (Or something close to this, in reality the external arbitrageur would not be able to trade for your full 1 ETH, as the USDT/ETH ratio and therefore price increases asymptotically as the amount of ETH in the pool goes toward 0).
So to answer your question - You'd put in 1 ETH and 1 USDT and a few seconds later you'd be left with a tiny amount of ETH and a couple USDT.
Edit: I initially read your question as starting a pool with this ratio, however the same logic goes if you contribute this ratio to an already existing pool. You wouldn't be lowering the price per ETH to 1 USDT in that pool, but would still be lowering it by some amount inversely proportional to the size of the pool nonetheless and be making some arbitrageur very happy.
Best Answer
(It would be great if someone can verify if this answer is correct)
As per the constant product formula,
where
x
andy
is the quantity of two different tokens in the pool.When we trade
a
amount of the first token forb
amount of the second token, the constant product formula must be maintained, therefore:The instantaneous price
p
of a pair is defined as the ratio of the two assets in the pool, i.e.With some rearrangements, we get:
We can then substitute this into the constant product formula:
Of course
k
is just equal tox * y
, therefore:Using symbolab we find out:
as long as
a
is not zero.TL;DR:
where
p
is the target price to be maintained andx
andy
are the quantities of the two tokens in the pool before the trade takes place.(I should still verify that I didn't make any mistakes here).
TEST CASE
X = 100 ETH, Y = 200,000 USD, P = 1950
a = sqrt(1950*100*200,000)/1950 - 100
=> a = ~1.274
This seems right, because it is roughly half of this similar question's answer.
Calculating this in solidity
It is awkward to calculate this in solidity.
Here is some sample code (please test this code before use in production, and also make sure it suits your needs):