二二複製公排開發規則丨二二複製公排系統開發(開發專案及原始碼)

xiaofufu發表於2023-03-03

  

新零售o2o模式就是o2o模式和零售模式的結合,將零售行業的特點跟網際網路結合起來,實現線上線下的互通。


  The new retail O2O model pays more attention to the combination of online and offline.The online platform increases exposure,leads traffic to offline,completes services online and offline,and gives users a better experience.


  library UniswapV2Library{


  using SafeMath for uint;


  //returns sorted token addresses,used to handle return values from pairs sorted in this order


  //給地址排序,從小到大


  function sortTokens(address tokenA,address tokenB)internal pure returns(address token0,address token1){


  require(tokenA!=tokenB,'UniswapV2Library:IDENTICAL_ADDRESSES');


  (token0,token1)=tokenA<tokenB?(tokenA,tokenB):(tokenB,tokenA);


  require(token0!=address(0),'UniswapV2Library:ZERO_ADDRESS');


  }開發需求及細節:MrsFu123


  //calculates the CREATE2 address for a pair without making any external calls


  //在不進行任何外部呼叫的情況下計算一對的CREATE2地址


  function pairFor(address factory,address tokenA,address tokenB)internal pure returns(address pair){


  (address token0,address token1)=sortTokens(tokenA,tokenB);


  pair=address(uint(keccak256(abi.encodePacked(


  hex'ff',


  factory,


  keccak256(abi.encodePacked(token0,token1)),


  hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'//init code hash


  ))));


  }


  //fetches and sorts the reserves for a pair


  //獲取並排序一對的儲備


  function getReserves(address factory,address tokenA,address tokenB)internal view returns(uint reserveA,uint reserveB){


  (address token0,)=sortTokens(tokenA,tokenB);


  (uint reserve0,uint reserve1,)=IUniswapV2Pair(pairFor(factory,tokenA,tokenB)).getReserves();


  (reserveA,reserveB)=tokenA==token0?(reserve0,reserve1):(reserve1,reserve0);


  }


  //given some amount of an asset and pair reserves,returns an equivalent amount of the other asset


  //給定一定數量的資產和配對準備金,返回等量的其他資產


  //BB/AA=B/A-->BB=AA*(B/A)


  function quote(uint amountA,uint reserveA,uint reserveB)internal pure returns(uint amountB){


  require(amountA>0,'UniswapV2Library:INSUFFICIENT_AMOUNT');


  require(reserveA>0&&reserveB>0,'UniswapV2Library:INSUFFICIENT_LIQUIDITY');


  amountB=amountA.mul(reserveB)/reserveA;


  }


  //給定資產的輸入量和對儲備


  //考慮手續費


  //(x+0.997a)(y-b)=xy


  //b=(0.997ay)/(x+0.997a)


  //b=(997ay)/(1000x+997a)


  function getAmountOut(uint amountIn,uint reserveIn,uint reserveOut)internal pure returns(uint amountOut){


  require(amountIn>0,'UniswapV2Library:INSUFFICIENT_INPUT_AMOUNT');


  require(reserveIn>0&&reserveOut>0,'UniswapV2Library:INSUFFICIENT_LIQUIDITY');


  uint amountInWithFee=amountIn.mul(997);


  uint numerator=amountInWithFee.mul(reserveOut);


  uint denominator=reserveIn.mul(1000).add(amountInWithFee);


  amountOut=numerator/denominator;


  }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2938011/,如需轉載,請註明出處,否則將追究法律責任。

相關文章