Avatar阿凡達(dá)泰山眾籌商城開發(fā)說明丨Avatar阿凡達(dá)泰山眾籌商城系統(tǒng)開發(fā)(案例及詳細(xì))
The"new retail"model has broken the respective closed state of online and offline.Online and offline can be integrated,complement each other and rely on each other.Online and offline more perform the functions of transaction and payment.Offline is usually used as a platform for screening and experience,while efficient logistics connects online and offline and forms a commercial closed loop with its interaction.
interface IERC20{
event Approval(address indexed owner,address indexed spender,uint value);
event Transfer(address indexed from,address indexed to,uint value);
function name()external view returns(string memory);
function symbol()external view returns(string memory);
function decimals()external view returns(uint8);
function totalSupply()external view returns(uint);
function balanceOf(address owner)external view returns(uint);
function allowance(address owner,address spender)external view returns(uint);
function approve(address spender,uint value)external returns(bool);
function transfer(address to,uint value)external returns(bool);
function transferFrom(address from,address to,uint value)external returns(bool);
}開發(fā)流程I35源碼7O98設(shè)計(jì)O7I8?
function addLiquidity(//添加流動(dòng)性,兩個(gè)代幣
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,//lp接收人,新版的uniswap前端好像不支持設(shè)置這個(gè)了
uint deadline//交易的成交時(shí)間,默認(rèn)是當(dāng)前時(shí)間+20分鐘后的時(shí)間的秒值
)external virtual override ensure(deadline)returns(uint amountA,uint amountB,uint liquidity){
//調(diào)用內(nèi)部方法_addLiquidity獲取到兩個(gè)幣實(shí)際所需要的數(shù)量
(amountA,amountB)=_addLiquidity(tokenA,tokenB,amountADesired,amountBDesired,amountAMin,amountBMin);
address pair=UniswapV2Library.pairFor(factory,tokenA,tokenB);//查找到pair地址
TransferHelper.safeTransferFrom(tokenA,msg.sender,pair,amountA);//給pair轉(zhuǎn)A數(shù)量
TransferHelper.safeTransferFrom(tokenB,msg.sender,pair,amountB);//給pair轉(zhuǎn)B數(shù)量
liquidity=IUniswapV2Pair(pair).mint(to);//調(diào)用pair的mint方法,會(huì)有添加的lp數(shù)量返回
}模式及案例:MrsFu123
function addLiquidityETH(//添加流動(dòng)性,其中一個(gè)幣種是eth
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,//eth最小輸入量;對(duì)應(yīng)的Desired在msg.value
address to,
uint deadline
)external virtual override payable ensure(deadline)returns(uint amountToken,uint amountETH,uint liquidity){
//調(diào)用內(nèi)部方法_addLiquidity獲取到兩個(gè)幣實(shí)際所需要的數(shù)量
//eth使用weth代幣替代
(amountToken,amountETH)=_addLiquidity(
token,
WETH,
amountTokenDesired,
msg.value,//ethDesired
amountTokenMin,
amountETHMin
);
address pair=UniswapV2Library.pairFor(factory,token,WETH);//獲取到pair地址
TransferHelper.safeTransferFrom(token,msg.sender,pair,amountToken);//給pair轉(zhuǎn)代幣數(shù)量
IWETH(WETH).deposit{value:amountETH}();//調(diào)用weth的兌換方法,通過eth換weth
assert(IWETH(WETH).transfer(pair,amountETH));//給pair轉(zhuǎn)weth數(shù)量
liquidity=IUniswapV2Pair(pair).mint(to);//調(diào)用pair的mint方法,會(huì)有添加的lp數(shù)量返回
//refund dust eth,if any
//如果傳入的eth數(shù)量,大于實(shí)際所需的eth數(shù)量,將剩余的eth返還給用戶
if(msg.value>amountETH)TransferHelper.safeTransferETH(msg.sender,msg.value-amountETH);
}