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 the contract.The larger the amount of lock-in the contract has,the better financial services can be obtained.Liquidity mining will encourage users to provide LP for the DeFi application,while the newly issued tokens of the product will distribute different amounts of tokens to users according to their contribution to lock-in.
添加流动性
添加流动性需要输入两个token,带ETH的方法,router会帮你转成WETH,最终实际就是该方法
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
)
交换方法
这里主要说明交易的方法
这里主要归纳为3个方法(带ETH的方法,router会帮你转成WETH,最终都是两个ERC20交换)
说明:
交换方法中,不存在买卖的说法,只有in/out;我下面的方法注释写买/卖是为了便于理解
交换方法中所有参数in/out都是相对于路由自己
//方法1需要获取精确的输出,输入不确定金额(也可以理解买,如购买100个UNI TOKEN,需要未知weth)
function swapTokensForExactTokens(
uint amountOut,//期望输出金额
uint amountInMax,//最大输入(如果到你打包的交易时,如果实际需要输入的金额大于该金额,交易失败!)
address[]calldata path,
address to,
uint deadline
)
//方法2通过输入金额,输出不确定金额(也可以理解为卖,如卖掉100个UNI TOKEN,可以获得未知WETH)
function swapExactTokensForTokens(
uint amountIn,//实际输入金额
uint amountOutMin,//最小输出(如果到打包你的交易时,实际输出小于该金额,交易失败!)
address[]calldata path,
address to,
uint deadline
)
//方法3通过输入金额,输出不确定金额
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[]calldata path,
address to,
uint deadline
)