Liquidity mining refers to a method of obtaining rewards by pledging one's digital assets.
Liquidity mining is an incentive mechanism to promote the use of DeFi and a new decentralized token distribution mechanism. Most DeFi applications require users to lock tokens into contracts, and the larger the amount of lock in the contract, the better financial services can be obtained. Liquidity mining will incentivize users to provide LP for DeFi applications, while the newly issued tokens of the product will distribute different amounts of tokens to users based on their lock-in contribution.
Liquidity mining encourages users to pledge tokens and pledge vouchers to liquidity mining contracts. For users, using DeFi not only earns the original profits, but also provides liquidity mining rewards. Under the incentive of liquidity mining, it has promoted users to become the LP of DeFi and promoted its rapid growth.
Liquidity mining usually requires the pledge of loan vouchers or LP vouchers. That is to say, users do not pledge their native tokens to receive liquidity mining rewards, but they need to first pledge their native tokens in DeFi, obtain vouchers, and then pledge the vouchers to a designated contract to receive liquidity mining rewards.
...
{
// 如果 tokenA,tokenB 的流动池不存在,就创建流动池
if (IUniswapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) {
IUniswapV2Factory(factory).createPair(tokenA, tokenB);
}
// 获取 tokenA,tokenB 的目前库存数量
(uint reserveA, uint reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB);
if (reserveA == 0 && reserveB == 0) {
// 如果库存数量为0,也就是新建 tokenA,tokenB 的流动池,那么实际添加的amountA, amountB 就是 amountADesired 和 amountBDesired
(amountA, amountB) = (amountADesired, amountBDesired);
} else {
// reserveAreserveB/amountADesired,算出实际要添加的 tokenB 数量 amountBOptimal
uint amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
// 如果 amountBMin <= amountBOptimal <= amountBDesired,amountA 和 amountB 就是 amountADesired 和 amountBOptimal
require(amountBOptimal >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT');
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
// reserveAreserveB/amountBDesired,算出实际要添加的 tokenA 数量 amountAOptimal
uint amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA);
// 如果 amountAMin <= amountAOptimal <= amountADesired,amountA 和 amountB 就是 amountAOptimal 和 amountBDesired
assert(amountAOptimal <= amountADesired);
require(amountAOptimal >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT');
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
}
}