區塊鏈眾籌商城系統開發實現技術方案丨區塊鏈眾籌商城開發原始碼部署

xiaofufu發表於2023-02-25

  新零售是什麼?新零售是透過投資建設門店、電子商務等營銷手段,開放線上線下,以滿足消費者的多元化需求。


  傳統零售以生產、零售為主,而新零售則是以消費者體驗為中心的資料驅動的泛零售形式,從本質上重構了人、貨、場。


  新零售的核心特點在於:對傳統零售的升級,無論是流通端、銷售端甚至消費者都在經歷一次升級。這種升級是以雲端計算、大資料、人工智慧等技術發展作為背景支撐的升級。


  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;


  }


  }


 


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

相關文章