BSC幣安鏈盲盒區塊鏈遊戲開發詳情丨BSC幣安鏈盲盒區塊鏈遊戲系統開發技術原理及分析

xiaofufu發表於2023-03-01

  The metauniverse is an immersive digital world created by the combination of virtual reality,augmented reality and the Internet.The connotation and key technologies of the metauniverse require further breaking the space-time limit(5G and the Internet of Things),real immersion(VR),and value transmission(Web 3.0,blockchain).


從技術上來看,元宇宙是基於Web3.0技術體系和運作機制支撐下的可信數字化價值互動網路,是以區塊鏈為核心的Web3.0數字新生態。他總結道,元宇宙是以區塊鏈為核心的Web3.0技術體系支撐下的新場景、新產業和新生態,將會在數字環境下催生大量創新商業模式,形成數字空間新正規化。


  //****LIBRARY FUNCTIONS****


  //以下方法,都是library裡面的方法,代呼叫UniswapV2Library


  function quote(uint amountA,uint reserveA,uint reserveB)public pure virtual override returns(uint amountB){


  return UniswapV2Library.quote(amountA,reserveA,reserveB);


  }


  function getAmountOut(uint amountIn,uint reserveIn,uint reserveOut)


  public


  pure


  virtual


  override


  returns(uint amountOut)


  {


  return UniswapV2Library.getAmountOut(amountIn,reserveIn,reserveOut);


  }


  function getAmountIn(uint amountOut,uint reserveIn,uint reserveOut)


  public


  pure


  virtual


  override


  returns(uint amountIn)


  {


  return UniswapV2Library.getAmountIn(amountOut,reserveIn,reserveOut);


  }


  function getAmountsOut(uint amountIn,address[]memory path)


  public


  view


  virtual


  override


  returns(uint[]memory amounts)


  {案例及設計:MrsFu123


  return UniswapV2Library.getAmountsOut(factory,amountIn,path);


  }


  function getAmountsIn(uint amountOut,address[]memory path)


  public


  view


  virtual


  override


  returns(uint[]memory amounts)


  {


  return UniswapV2Library.getAmountsIn(factory,amountOut,path);


  }


  }


  //a library for performing overflow-safe math,courtesy of DappHub()


  library SafeMath{


  function add(uint x,uint y)internal pure returns(uint z){


  require((z=x+y)>=x,'ds-math-add-overflow');


  }


  function sub(uint x,uint y)internal pure returns(uint z){


  require((z=x-y)<=x,'ds-math-sub-underflow');


  }


  function mul(uint x,uint y)internal pure returns(uint z){


  require(y==0||(z=x*y)/y==x,'ds-math-mul-overflow');


  }


  }


  library UniswapV2Library{


  using SafeMath for uint;


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


  //兩個token排序,address實際也是一個uint160,可以相關轉換,所以可以比大小,排序,小是0,確認在交易對中的token0,token1


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


  }


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


  //透過create2的方式計算交易對的地址,注意initCode,每次部署的時候,可能都不一樣,需要生成


  //用法套格式即可,對應factory中的createPair,要深入的,可以具體去了解下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


  //獲取兩個幣的儲備量,透過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);


  }


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

相關文章