公排開發原始碼版丨公排系統開發(技術方案)丨公排系統開發(開發專案)

xiaofufu發表於2023-03-03

  新零售的另一個新層次是網際網路+技術(大資料、雲端計算、移動支付等)它可以連線線上和線下,實現全面覆蓋,並透過技術提高零售能力。使企業能夠更清晰地獲得消費者的形象,同時刺激消費者的消費,創造更好的消費者體驗。


  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` 開發案例:MrsFu123


   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`


 


  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);


  }


  }


  }


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

相關文章