当前位置:网站首页>Uniswapv2 peripheral contract learning (IX) -- examplecombinedswapadddremoveliquidity sol

Uniswapv2 peripheral contract learning (IX) -- examplecombinedswapadddremoveliquidity sol

2022-06-09 14:02:00 MateZero

I remember a sentence from my circle of friends , If Defi It is the crown of Ethereum , that Uniswap It is the Pearl in this crown .Uniswap So far V2 edition , relative V1, Its functions are more comprehensive and optimized , However, the contract source code is not complicated . This article is for personal learning UniswapV2 Source code of a series of record articles .

One 、 Single asset liquidity supply

We know ,Uniswap When providing liquidity, both assets in the transaction pair must be injected proportionally at the same time , Then get the liquidity token . Two assets are required at the same time , This virtually raises the threshold for users . If the user has only one ( Or just focus on one ) What about assets ? Can you provide liquidity supply ? The answer is OK .

stay Router The contract provides an interface for liquidity management , It also provides an interface for asset transactions . Then we can combine these two functions in the same function , Trading assets before providing liquidity , Or remove liquidity before trading assets .

If a single asset provides liquidity , First, a part of the assets provided should be traded , Get another asset , So there are two kinds of assets . Then call Router The increased liquidity interface of the contract injects assets to provide liquidity . How many assets will be distributed for trading to ensure that all assets are injected ( The proportion at the time of injection is the same as that in the post transaction transaction pair ), Is the core of this operation , You need to use a formula to calculate .

If you remove liquidity and get a single asset , This is relatively simple . First remove the liquidity and get two kinds of assets , Then exchange one of these assets for another . The asset thus obtained is the amount of withdrawal plus the amount of transaction .

You can see , Yes Uniswap Speaking of , The essence of single asset liquidity supply here is double asset injection ( Determined by its underlying implementation ), It just converts a single asset into a dual asset in advance .

notes : There are other types of single asset liquidity supply , for example BancorV

原网站

版权声明
本文为[MateZero]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091245531380.html