欢迎光临散文网 会员登陆 & 注册

单双币/子母币/多币质押挖矿系统开发(开发规则)及详细源码

2023-03-17 17:40 作者:bili_33032327742  | 我要投稿

  Metaverse is a virtual world constructed by humans using digital technology,mapped or transcended by the real world,and can interact with the real world.It is a digital living space with a new social system.


  The"meta universe"itself is not a new technology,but rather integrates a large number of existing technologies,including 5G,cloud computing,artificial intelligence,virtual reality,blockchain,the Internet of Things,human-computer interaction,and so on.


  For users,it is mainly about experiencing various meta universe application scenarios,such as meta universe e-commerce,meta universe social networking,meta universe entertainment,and meta universe office.All real-world scenarios can be presented in the meta universe through digital technology,so it can also be understood as a digital city,and more importantly,a digital earth.


  swap是普通用户进行代币交易的操作。普通用户通过swap操作实现两种token之间的交易。


  function swapExactTokensForTokens(


  uint amountIn,


  uint amountOutMin,


  address[]calldata path,


  开发案例I59源码2OO7详细3O69


  address to,


  uint deadline


  )external virtual override ensure(deadline)returns(uint[]memory amounts){


  关于区块链项目技术开发唯:yy625019,代币发行、dapp智能合约开发、链游开发、多链钱包开发


  交易所开发、量化合约开发、互助游戏开发、Nft数字藏品开发、众筹互助开发、元宇宙开发、swap开发、


  链上合约开发、ido开发、商城开发等,开发过各种各样的系统模式,更有多种模式、制度、案例、后台等,成熟技术团队,欢迎实体参考。


  Uniswap支持多种代币的交换。具体的含义是,Uniswap提供了多级交易池的路由功能。举个例子,已有两个交易对TokenA-TokenB,以及TokenB-TokenC,通过swap接口,可以实现TokenA-TokenC的交换,其中经过的TokenA-TokenB,TokenB-TokenC,称为路径(path)。amountIn是路径中的第一个代币的数量,amountOutMin是期望的交换后的最少的数量。


  amounts=UniswapV2Library.getAmountsOut(factory,amountIn,path);


  require(amounts[amounts.length-1]>=amountOutMin,‘UniswapV2Router:INSUFFICIENT_OUTPUT_AMOUNT’);


  amounts是每个路径上的交换后的数量。amounts[amounts.length-1]也就是最后一条路径的输出数量。注意,UniswapV2Library.getAmountsOut的实现(在获取每个交易对的reserve信息后,调用getAmountOut函数):


  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');


  uint amountInWithFee=amountIn.mul(997);


  uint numerator=amountInWithFee.mul(reserveOut);


  uint denominator=reserveIn.mul(1000).add(amountInWithFee);


  amountOut=numerator/denominator;


  }


  注意,其中的997/1000的系数。在进入每个交易池之前,进入的金额先扣除了0.3%的本金。这个就是交易费。注意的是,路径上的交易池,每个池子都收。有点像高速收费站,一段段的收。


  TransferHelper.safeTransferFrom(


  path[0],msg.sender,UniswapV2Library.pairFor(factory,path[0],path[1]),amounts[0]


  );


  将代币path[0],转入到交易对,数量为amounts[0]。转入代币后,进行真正的swap操作:


  function _swap(uint[]memory amounts,address[]memory path,address _to)internal virtual{


  for(uint i;i<path.length-1;i++){


  (address input,address output)=(path<i>,path[i+1]);


  (address token0,)=UniswapV2Library.sortTokens(input,output);


  uint amountOut=amounts[i+1];


  (uint amount0Out,uint amount1Out)=input==token0?(uint(0),amountOut):(amountOut,uint(0));


  address to=i<path.length-2?UniswapV2Library.pairFor(factory,output,path[i+2]):_to;


  IUniswapV2Pair(UniswapV2Library.pairFor(factory,input,output)).swap(


  amount0Out,amount1Out,to,new bytes(0)


  );


  }


  }


单双币/子母币/多币质押挖矿系统开发(开发规则)及详细源码的评论 (共 条)

分享到微博请遵守国家法律