新零售是什么?新零售是通过投资建设门店、电子商务等营销手段,开放线上线下,以满足消费者的多元化需求。
传统零售以生产、零售为主,而新零售则是以消费者体验为中心的数据驱动的泛零售形式,从本质上重构了人、货、场。
新零售的核心特点在于:对传统零售的升级,无论是流通端、销售端甚至消费者都在经历一次升级。这种升级是以云计算、大数据、人工智能等技术发展作为背景支撑的升级。
event Mint(address indexed sender,uint amount0,uint amount1);
event Burn(address indexed sender,uint amount0,uint amount1,address indexed to);
event Swap(address indexed sender,uint amount0In,uint amount1In,uint amount0Out,uint amount1Out,address indexed to);
event Sync(uint112 reserve0,uint112 reserve1);
//部署此合约时将msg.sender设置为factory,后续初始化时会用到这个值
constructor()public{
factory=msg.sender;
}
//called once by the factory at time of deployment
//在UniswapV2Factory.sol的createPair中调用过
function initialize(address _token0,address _token1)external{
require(msg.sender==factory,'UniswapV2:FORBIDDEN');//sufficient check
token0=_token0;
token1=_token1;
}
//update reserves and,on the first call per block,price accumulators
//更新储备,并在每个区块的第一次调用时更新价格累加器
/**
更新变量:
blockTimestampLast
reserve0
reserve1
price0CumulativeLast
price1CumulativeLast
*/
//这个函数是用来更新价格oracle的,计算累计价格
function _update(uint balance0,uint balance1,uint112 _reserve0,uint112 _reserve1)private{
//溢出校验
require(balance0<=uint112(-1)&&balance1<=uint112(-1),'UniswapV2:OVERFLOW');
uint32 blockTimestamp=uint32(block.timestamp%2**32);
uint32 timeElapsed=blockTimestamp-blockTimestampLast;//overflow is desired
//计算时间加权的累计价格,256位中,前112位用来存整数,后112位用来存小数,多的32位用来存溢出的值
if(timeElapsed>0&&_reserve0!=0&&_reserve1!=0){
//*never overflows,and+overflow is desired
price0CumulativeLast+=uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0))*timeElapsed;
price1CumulativeLast+=uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1))*timeElapsed;
}
//更新reserve值
reserve0=uint112(balance0);
reserve1=uint112(balance1);
blockTimestampLast=blockTimestamp;
emit Sync(reserve0,reserve1);
}
//if fee is on,mint liquidity equivalent to 1/6th of the growth in sqrt(k)
//如果收费,增发流动性相当于sqrt(k)增长的1/6
function _mintFee(uint112 _reserve0,uint112 _reserve1)private returns(bool feeOn){
//获取接收手续费的地址
address feeTo=IUniswapV2Factory(factory).feeTo();
//手续费接收者不为0地址
feeOn=feeTo!=address(0);
uint _kLast=kLast;//gas savings
//手续费接收者不为0地址
if(feeOn){
if(_kLast!=0){
uint rootK=Math.sqrt(uint(_reserve0).mul(_reserve1));
uint rootKLast=Math.sqrt(_kLast);
if(rootK>rootKLast){
uint numerator=totalSupply.mul(rootK.sub(rootKLast));
uint denominator=rootK.mul(5).add(rootKLast);
uint liquidity=numerator/denominator;
if(liquidity>0)_mint(feeTo,liquidity);
}
}
}
//手续费接收者为0,并且kLast不为0
else if(_kLast!=0){
kLast=0;
}
}