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