幣安鏈bsc盲盒游戲開發(fā)正式版丨幣安鏈盲盒游戲源碼案例
The universe is the successor of the mobile internet,and the doors of the virtual world and the real world have been opened.The metauniverse may become the new direction of the development of the Internet,and may also be the next form of the development of the digital economy.The exploration of the universe will promote the deep integration of the real economy and the digital economy,and promote the digital economy to a new stage. //given some amount of an asset and pair reserves,returns an equivalent amount of the other asset //添加流動性的時候,通過該方法查詢輸入A的數(shù)量,需要多少個B function quote(uint amountA,uint reserveA,uint reserveB)internal pure returns(uint amountB){ //判斷數(shù)量,首次添加流動性,隨意定價,不需要查詢該方法 require(amountA>0,'UniswapV2Library:INSUFFICIENT_AMOUNT'); require(reserveA>0&&reserveB>0,'UniswapV2Library:INSUFFICIENT_LIQUIDITY'); //B數(shù)量=預期輸入A的數(shù)量*B的儲備量/A的儲備量;//實際公式就是A/B=reserveA/reserveB,兩個幣的數(shù)量比例一致 amountB=amountA.mul(reserveB)/reserveA; }開發(fā)分析I35模式7O98開發(fā)O7I8 //given an input amount of an asset and pair reserves,returns the maximum output amount of the other asset //通過精確輸入金額,輸入幣的儲備量,輸出幣的儲備量,計算輸出幣的最大輸出量 function getAmountOut(uint amountIn,uint reserveIn,uint reserveOut)internal pure returns(uint amountOut){ require(amountIn>0,'UniswapV2Library:INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn>0&&reserveOut>0,'UniswapV2Library:INSUFFICIENT_LIQUIDITY'); //具體看下面的公式推導,要看該公式,首先要理解uniswap AMM,X*Y=K uint amountInWithFee=amountIn.mul(997);//手續(xù)費都是扣輸入額的千三,所以需要去掉千三后才是實際用于交易的金額 uint numerator=amountInWithFee.mul(reserveOut);//套下面公式理解吧?。? uint denominator=reserveIn.mul(1000).add(amountInWithFee); amountOut=numerator/denominator; /*需求及案例:MrsFu123 *查看下面的由in計算out公式out=in*f*rOut/rIn+in*f *手續(xù)費是千三,扣除手續(xù)費后去交易的金額是輸入額的0.997,公式中的f是0.997內(nèi)部計算用的uint,所以分子分母都*1000 *最終的公式是out=in*997*rOut/((rIn+in*f)*1000) *out=in*997*rOut/(rIn*1000+in*997) */ } /** * * *推導公式 *in輸入金額,out輸出金額 *rIn tokenIn的流動性,rOu
幣安鏈bsc盲盒游戲開發(fā)正式版丨幣安鏈盲盒游戲源碼案例的評論 (共 條)
