v18038319724的个人空间 https://www.eechina.com/space-uid-170931.html [收藏] [复制] [RSS]

博客

智能合约互助公排流动性质押挖矿系统开发(详情开发及源码)

已有 227 次阅读2023-4-17 17:38

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系统开发180.3831.9724,

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;

  }

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

 


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
返回顶部