新零售的另一个新层次是互联网+技术(大数据、云计算、移动支付等)它可以连接线上和线下,实现全面覆盖,并通过技术提高零售能力。使企业能够更清晰地获得消费者的形象,同时刺激消费者的消费,创造更好的消费者体验。
function getAmountIn(uint amountOut,uint reserveIn,uint reserveOut)internal pure returns(uint amountIn){
require(amountOut>0,'UniswapV2Library:INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn>0&&reserveOut>0,'UniswapV2Library:INSUFFICIENT_LIQUIDITY');
uint numerator=reserveIn.mul(amountOut).mul(1000);
uint denominator=reserveOut.sub(amountOut).mul(997);
//加一是防止数据溢出
amountIn=(numerator/denominator).add(1);
}
//performs chained getAmountOut calculations on any number of pairs
//对任意数量的对执行链式getAmountOut计算
//输入a,得到n
//路径:A->B->C->...N
//数量:a->b->c->...n
//假如N=A,n=a`
//a`>a则存在套利空间,如何实现利润最大化还需考虑
function getAmountsOut(address factory,uint amountIn,address[]memory path)internal view returns(uint[]memory amounts){
require(path.length>=2,'UniswapV2Library:INVALID_PATH');
amounts=new uint[](path.length);
amounts[0]=amountIn;
for(uint i;i<path.length-1;i++){
(uint reserveIn,uint reserveOut)=getReserves(factory,path<i>,path[i+1]);
amounts[i+1]=getAmountOut(amounts<i>,reserveIn,reserveOut);
}
}
//performs chained getAmountIn calculations on any number of pairs
//对任意数量的对执行链式getAmountIn计算
//为了得到n,输入a
//路径:N...C->B->A
//数量:n...c->b->a
//假如N=A,n=a`
//a`>a则存在套利空间,如何实现利润最大化还需考虑
function getAmountsIn(address factory,uint amountOut,address[]memory path)internal view returns(uint[]memory amounts){
require(path.length>=2,'UniswapV2Library:INVALID_PATH');
amounts=new uint[](path.length);
amounts[amounts.length-1]=amountOut;
for(uint i=path.length-1;i>0;i--){
(uint reserveIn,uint reserveOut)=getReserves(factory,path[i-1],path<i>);
amounts[i-1]=getAmountIn(amounts<i>,reserveIn,reserveOut);
}
}
}