Avatar阿凡達泰山眾籌開發案例版丨Avatar阿凡達泰山眾籌系統開發(開發邏輯及方案)

xiaofufu發表於2023-03-01

  New retail is a new retail model in which enterprises,relying on the Internet,upgrade and transform the production,circulation and sales process of goods by using advanced technology such as big data and artificial intelligence,and then reshape the business structure and ecosystem,and deeply integrate online services,offline experience and modern logistics.


  function removeLiquidityETHWithPermit(//WithPermit,移除時,其中一個返回eth


  address token,


  uint liquidity,


  uint amountTokenMin,


  uint amountETHMin,


  address to,


  uint deadline,


  bool approveMax,uint8 v,bytes32 r,bytes32 s


  )external virtual override returns(uint amountToken,uint amountETH){


  /*


  獲取到pair,呼叫pair的permit(內部實際就是授權給路由),


  */


  address pair=UniswapV2Library.pairFor(factory,token,WETH);


  uint value=approveMax?uint(-1):liquidity;模式及功能I35方案7O98開發O7I8


  IUniswapV2Pair(pair).permit(msg.sender,address(this),value,deadline,v,r,s);


  //最終還是呼叫上面的removeLiquidityETH方法!


  (amountToken,amountETH)=removeLiquidityETH(token,liquidity,amountTokenMin,amountETHMin,to,deadline);


  }


  //****REMOVE LIQUIDITY(supporting fee-on-transfer tokens)****


  //移除流動性(需要先授權),支援轉賬會扣手續費的代幣s


  function removeLiquidityETHSupportingFeeOnTransferTokens(


  address token,


  uint liquidity,


  uint amountTokenMin,


  uint amountETHMin,


  address to,


  uint deadline


  )public virtual override ensure(deadline)returns(uint amountETH){


  //實際還是呼叫removeLiquidity,傳入的是weth,


  (,amountETH)=removeLiquidity(


  token,


  WETH,


  liquidity,


  amountTokenMin,//實際就是這兩個值,填很小,就可以成功


  amountETHMin,//實際就是這兩個值,填很小,就可以成功


  address(this),


  deadline


  );詳情及分析:MrsFu123


  //removeLiquidity返回的第一個引數是代幣數量,由於代幣轉賬會扣手續費,所以,實際到達路由的代幣數量並沒有這麼多!直接取餘額轉出


  TransferHelper.safeTransfer(token,to,IERC20(token).balanceOf(address(this)));//如果轉賬扣兩次手續費..這裡相當於扣兩次,pair->router,router->to


  //將weth轉換eth,再轉給to,


  IWETH(WETH).withdraw(amountETH);


  TransferHelper.safeTransferETH(to,amountETH);


  }


  //同上,先驗籤授權,再呼叫上面的removeLiquidityETHSupportingFeeOnTransferTokens


  function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(


  address token,


  uint liquidity,


  uint amountTokenMin,


  uint amountETHMin,


  address to,


  uint deadline,


  bool approveMax,uint8 v,bytes32 r,bytes32 s


  )external virtual override returns(uint amountETH){


  address pair=UniswapV2Library.pairFor(factory,token,WETH);


  uint value=approveMax?uint(-1):liquidity;


  IUniswapV2Pair(pair).permit(msg.sender,address(this),value,deadline,v,r,s);


  amountETH=removeLiquidityETHSupportingFeeOnTransferTokens(


  token,liquidity,amountTokenMin,amountETHMin,to,deadline


  );


  }


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

相關文章