Does anyone have in-depth experience with DEX development? I have a question regarding the DEX "Pancakeswap Fork". Has anyone tested what happens when the first liquidity provider removes its LPs and Tokens/Coins and wants to add them again? As I know, I can't drain the pool completely because there is always a residue in it. Assuming the first liquidity provider removes it, the reserves are so small that it is annoying because of the calculated small ratio. Or have I misunderstood something? It is not intended to reset or reset the reserves to start at zero. The optimum would be to bring it to the same state as during initialization. I could not find a solution or is this a known problem. (edited)
Good question, I am not familiar with the pancakeswap, but I think it likes the uniswap V2.
yes, you are right, if you add liquidity firstly, you will decide the token exchange rate, and if you remove the liquidity later, cause the uniswap charge some fees, so just like you said, you can't drain the pool completely, so later, if you want to add liquidity again, I think you have got to follow the original exchange rate. Maybe this is one of the reasons that why uniswap updates their protocol to V3, cause in V3, they can add liquidity with a price range that users want.
And in your case, I think if you want to provide liquidity on uniswap, you must the first one, cause you want to set a reasonable exchange rate, and maybe you will leave the liquidity just there, once you want to remove the liquidity, maybe you do not care the token price anymore.
Hi
Try this one on test net
Add Liquidity and then remove it and tell us !!!
NOTE THIS IS A TEST PANCAKE
Ok, at least that's not a problem from my side. I also read somewhere from Uniswap that something has been optimized in that direction. I call it "Penny" pools If you are not the first provider then I think the pools can be spammed.
But the issue comes from this code part:
#_addLiquidity
uint amountBOptimal = ExchangeLibrary.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
require(amountBOptimal >= amountBMin, '_addLiquidity1: INSUFFICIENT_B_AMOUNT');
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint amountAOptimal = ExchangeLibrary.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
require(amountAOptimal >= amountAMin, '_addLiquidity2: INSUFFICIENT_A_AMOUNT');
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
If the reserves are very small it will throw: "'_addLiquidity2: INSUFFICIENT_A_AMOUNT"
I am thinking to check if either the reserves are too small or the amountBOptimal has to be a minimum amount. Then it would be possible to add liquidity on top of the existing one
Or I could just remove the sanity checks:
#_addLiquidity
uint amountBOptimal = ExchangeLibrary.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint amountAOptimal = ExchangeLibrary.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
Did not test it yet but if you see any problem with that then let me know.
Many thanks. I was trying to use it today but the faucet site was not working today. But @Skyge confirmed the issue exists on Uniswap or Pancakeswap (is Uniswap fork). Now, I know I need to customize the code a bit that it works. I am coming from different channels many people are forking and using it but nobody understands the code from very big projects to the smallest projects.
Hi, do you know the init hash from the test pancakeswap? Ihttps://pancake.kiemtienonline360.com/#/pool
It should be within the ExchangeLibrary. Is there any github repo for that?
Hi
i think the hash init is
0xecba335299a6693cb2ebc4782e74669b84290b6378ea3a3873c7231a8d7d1074
Ok, I was trying to use the permit function to migrate the LP from new added LP to https://pancake.kiemtienonline360.com/#/pool
Using the SushiRoll.sol contract and replaced the init with the init you shared with me but getting always Pancake: Invalid Signature
This doesnt work ?
hex'ecba335299a6693cb2ebc4782e74669b84290b6378ea3a3873c7231a8d7d1074'
Yes, it is the correct one. I found it in the explorer as well