币安链bsc盲盒游戏开发正式版丨币安链盲盒游戏源码案例
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的数量,需要多少个B function quote(uint amountA,uint reserveA,uint reserveB)internal pure returns(uint amountB){ //判断数量,首次添加流动性,随意定价,不需要查询该方法 require(amountA>0,'UniswapV2Library:INSUFFICIENT_AMOUNT'); require(reserveA>0&&reserveB>0,'UniswapV2Library:INSUFFICIENT_LIQUIDITY'); //B数量=预期输入A的数量*B的储备量/A的储备量;//实际公式就是A/B=reserveA/reserveB,两个币的数量比例一致 amountB=amountA.mul(reserveB)/reserveA; }开发分析I35模式7O98开发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);//手续费都是扣输入额的千三,所以需要去掉千三后才是实际用于交易的金额 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 *手续费是千三,扣除手续费后去交易的金额是输入额的0.997,公式中的f是0.997内部计算用的uint,所以分子分母都*1000 *最终的公式是out=in*997*rOut/((rIn+in*f)*1000) *out=in*997*rOut/(rIn*1000+in*997) */ } /** * * *推导公式 *in输入金额,out输出金额 *rIn tokenIn的流动性,rOu