Liquidity mining,in short,is a token incentive plan designed to attract liquidity providers(LPs)to provide liquidity for specific transaction pairs/pools on AMM.
Synthetix is the first to distribute bonus tokens to LPs in its sETH Uniswap pool.To be more specific,in order to obtain rewards,LP needs to first provide liquidity for the sETH pool on Uniswap,and then pledge its Uniswap liquidity token into the pledge reward contract created in 2019.The reward tokens will be distributed to the LP fairly according to the percentage of the liquidity tokens pledged by the LP relative to the total pledge tokens of the LP.
CREATE2:
创建交易对,就是创建一个新的合约,作为流动池来提供交易功能。创建合约的步骤是:
pool=address(new UniswapV3Pool{salt:keccak256(abi.encode(token0,token1,fee))}());
这里先通过keccak256(abi.encode(token0,token1,fee)将token0,token1,fee作为输入,得到一个哈希值,并将其作为salt来创建合约。因为指定了salt,solidity会使用EVM的CREATE2指令来创建合约。使用CREATE2指令的好处是,只要合约的bytecode及salt不变,那么创建出来的地址也将不变。
使用CREATE2的好处是:
可以在链下计算出已经创建的交易池的地址
其他合约不必通过UniswapV3Factory中的接口来查询交易池的地址,可以节省gas
合约地址不会因为reorg而改变
不需要通过UniswapV3Factory的接口来计算交易池合约地址的方法,可以看这段代码。
新交易对合约的构造函数中会反向查询UniswapV3Factory中的parameters值来进行初始变量的赋值:
constructor(){
int24 _tickSpacing;
(factory,token0,token1,fee,_tickSpacing)=IUniswapV3PoolDeployer(msg.sender).parameters();
tickSpacing=_tickSpacing;
maxLiquidityPerTick=Tick.tickSpacingToMaxLiquidityPerTick(_tickSpacing);
}
为什么不直接使用参数传递来对新合约的状态变量赋值呢。这是因为CREATE2会将合约的initcode和salt一起用来计算创建出的合约地址。而initcode是包含contructor code和其参数的,如果合约的constructor函数包含了参数,那么其initcode将因为其传入参数不同而不同。在off-chain计算合约地址时,也需要通过这些参数来查询对应的initcode。为了让合约地址的计算更简单,这里的constructor不包含参数(这样合约的initcode将时唯一的),而是使用动态call的方式来获取其创建参数。
最后,对创建的交易对合约进行初始化:
function initialize(uint160 sqrtPriceX96)external override{
require(slot0.sqrtPriceX96==0,'AI');
int24 tick=TickMath.getTickAtSqrtRatio(sqrtPriceX96);
(uint16 cardinality,uint16 cardinalityNext)=observations.initialize(_blockTimestamp());
slot0=Slot0({
sqrtPriceX96:sqrtPriceX96,
tick:tick,
observationIndex:0,
observationCardinality:cardinality,
observationCardinalityNext:cardinalityNext,
feeProtocol:0,
unlocked:true
});
emit Initialize(sqrtPriceX96,tick);
}
初始化主要是设置了交易池的初始价格(注意,此时池子中还没有流动性),以及费率,tick等相关变量的初始化。完成之后一个交易池就创建好了。
From the perspective of token economics incentive design,the liquidity mining method pioneered by Synthetix is to allocate reward tokens according to the size of the liquidity position.We can define this method as liquidity mining 1.0(LM1).As a result,such incentive plan has helped Synthetix achieve the goal of attracting more users and casting more sETH.
LM1 has become the de facto design and implementation scheme of mobile mining.It enables many projects to be solved to some extent