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

简介: 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

  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;

  }

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

 

相关文章
|
5月前
|
传感器 搜索推荐 数据挖掘
可穿戴设备如何驱动心理健康监测的变革:科技护航心理健康的未来
可穿戴设备如何驱动心理健康监测的变革:科技护航心理健康的未来
131 15
|
10月前
|
SQL
LEFT JOIN
【11月更文挑战第07天】
278 3
|
11月前
|
存储 缓存 数据库
缓存技术有哪些应用场景呢
【10月更文挑战第19天】缓存技术有哪些应用场景呢
|
数据挖掘
【数据挖掘】Lasso回归原理讲解及实战应用(超详细 附源码)
【数据挖掘】Lasso回归原理讲解及实战应用(超详细 附源码)
1310 0
|
Java 应用服务中间件 Android开发
eclipse项目导入到idea
eclipse项目导入到idea
395 0
|
机器学习/深度学习 开发工具 计算机视觉
YOLOv8 目标检测 | 自定义数据集
YOLOv8 目标检测 | 自定义数据集
|
Web App开发 JSON JavaScript
浏览器书签bookmark转json格式
一直使用谷歌浏览器,因为某些原因登录谷歌账号不方便,所以公司和家里的浏览器上收藏的好多书签也不能同步,以前都是直接导出来,然后自己手动导入同步
|
Go 数据库 微服务
Go语言微服务框架 - 1.搭建gRPC+HTTP的双重网关服务
大家好,我是六月天天。如题所述,从今天开始,我将和大家一起逐步完成一个微服务框架。
326 1
|
JSON 数据格式 C++
C++ Json和结构体或类的转换
C++ Json和结构体或类的转换
600 0
|
数据可视化 C++
QCustomplot基本使用(一)
QCustomplot基本使用(一)
623 0