BSC链盲盒游戏系统开发(开发详细)丨BSC链盲盒游戏源码开发

简介: New retail refers to a new retail model in which individuals and enterprises,relying on the Internet,upgrade and transform the production,circulation and sales process of goods by using advanced technical means such as big data,artificial intelligence and psychological knowledge,thereby reshaping th

  New retail refers to a new retail model in which individuals and enterprises,relying on the Internet,upgrade and transform the production,circulation and sales process of goods by using advanced technical means such as big data,artificial intelligence and psychological knowledge,thereby reshaping the business structure and ecosystem,and deeply integrate online services,offline experience and modern logistics.

  企业以互联网为依托,通过运用大数据、人工智能等先进技术手段,对商品的生产、流通与销售过程进行升级改造,进而重塑业态结构与生态圈,并对线上服务、线下体验以及现代物流进行深度融合的零售新模式。

  //REMOVE LIQUIDITY

  function removeLiquidity(//移除流动性,该方法需要先将lp代币授权给路由合约,才能代扣lp

  address tokenA,

  address tokenB,

  uint liquidity,//移除lp的数量,转入lp得另外两个币

  uint amountAMin,//A的最小输出量

  uint amountBMin,//B的最小输出量

  address to,//接收两个币的地址

  uint deadline

  )public virtual override ensure(deadline)returns(uint amountA,uint amountB){

  address pair=UniswapV2Library.pairFor(factory,tokenA,tokenB);//获取pair地址

  IUniswapV2Pair(pair).transferFrom(msg.sender,pair,liquidity);//将lp转到pair地址

  //send liquidity to pair

  (uint amount0,uint amount1)=IUniswapV2Pair(pair).burn(to);//调用pair的burn方法,内部会将两个币的数量转给to,返回值就是两个代币的输出数量

  (address token0,)=UniswapV2Library.sortTokens(tokenA,tokenB);//通过排序确认两个amountA/B

  (amountA,amountB)=tokenA==token0?(amount0,amount1):(amount1,amount0);

  //校验A/B的输出量需要小于参数中要求的最小量,否则交易失败

  require(amountA>=amountAMin,'UniswapV2Router:INSUFFICIENT_A_AMOUNT');

  require(amountB>=amountBMin,'UniswapV2Router:INSUFFICIENT_B_AMOUNT');

  }
  function removeLiquidityETH(//移除流动性(其中一个返还币是ETH),该方法需要先将lp代币授权给路由合约,才能代扣lp

  address token,

  uint liquidity,

  uint amountTokenMin,

  uint amountETHMin,//eth最小输出量

  address to,

  uint deadline

  )public virtual override ensure(deadline)returns(uint amountToken,uint amountETH){

  //调用上面的removeLiquidity方法,传入的是WETH

  (amountToken,amountETH)=removeLiquidity(

  token,

  WETH,

  liquidity,

  amountTokenMin,

  amountETHMin,

  address(this),//注意!接收币的地址是路由

  deadline

  );

  //将代币转给to

  TransferHelper.safeTransfer(token,to,amountToken);

  IWETH(WETH).withdraw(amountETH);//将weth转换成eth

  TransferHelper.safeTransferETH(to,amountETH);//将eth转给to

  }

  //WithPermit的方法可以先了解下approveAndCall链接

  /*

  实际使用EIP-712

  链接https://soliditydeveloper.com/erc20-permit

  https://learnblockchain.cn/article/1790

  https://eips.ethereum.org/EIPS/eip-2612

  permit在前端的使用场景,就是移除流动性的时候,有个授权实际没有发送交易,只是要求签名,签名会得到参数中的v/r/s

  在实际调用该移除的方法传进来,内部验签,确认是该用户,就将移除的lp的数量,授权给路由,可以代扣lp

  */

  function removeLiquidityWithPermit(//移除流动性,approve+transferFrom

  address tokenA,

  address tokenB,

  uint liquidity,

  uint amountAMin,

  uint amountBMin,

  address to,

  uint deadline,

  bool approveMax,uint8 v,bytes32 r,bytes32 s//v,r,s验签,通过就授权给路由

  )external virtual override returns(uint amountA,uint amountB){

  /*

  获取到pair,调用pair的permit(内部实际就是授权给路由),

  */

  address pair=UniswapV2Library.pairFor(factory,tokenA,tokenB);

  uint value=approveMax?uint(-1):liquidity;

  IUniswapV2Pair(pair).permit(msg.sender,address(this),value,deadline,v,r,s);

  //最终还是调用上面的removeLiquidity方法!

  (amountA,amountB)=removeLiquidity(tokenA,tokenB,liquidity,amountAMin,amountBMin,to,deadline);

  }

相关文章
|
4月前
|
监控 Unix
BSC丨Solana丨AVAX丨LUNA公链游戏系统开发规则丨链游系统开发(结构模型)
该代码段是用于BSC、Solana、AVAX和LUNA公链游戏系统的开发规则,涉及链游系统开发的结构模型。主要包含三个静态保护函数:`monitorWorkersForWindows`用于监控工作进程,`exitAndClearAll`负责退出并清理所有进程,而`reload`函数执行重载操作。在主进程,`reload`发送信号给可重载的工作进程,并在指定时间后尝试杀死未退出的进程。在子进程中,它触发`onWorkerReload`回调并根据`reloadable`属性停止所有工作进程。
|
JavaScript 前端开发 区块链
NFT链游stepn跑鞋质押模式系统开发(技术原理)|案例搭建
智能合约是在区块链上运行并在web3生态系统中启用去中心化应用程序
|
4月前
|
Python 容器 索引
BRC-20铭文合约NFT铸造交易平台系统开发规则玩法/详细步骤/项目方案/成熟技术/源码功能
有时候,像定义add2()这类简单的函数,用def来正式地写个命名、计算和返回显得稍有点麻烦,Python支持用lambda对简单的功能定义“行内函数”
|
4月前
|
区块链
NFT卡牌链游盲盒系统开发详情规则|技术方案
随着区块链技术的迅猛发展,智能合约逐渐成为人们关注的焦点
|
10月前
|
存储 算法 安全
BSC链质押项目系统开发|DAPP开发案例
区块链属于分布式账本技术的一种,每一条链都相当于一个独立的账本
|
12月前
|
安全 区块链
NFT卡牌链游系统开发详情指南(区块链游戏系统开发源码)丨NFT卡牌链游系统开发运营版/需求步骤/案例逻辑/源码说明
Requirement analysis and planning: Clarify the system's goals and functional requirements. Understand the characteristics and working methods of the NFT card chain game system. Collect user requirements, define system card rules, game modes, and transaction functions.
|
安全 区块链
BSC链盲盒游戏系统开发详情案例丨dapp链上合约盲盒游戏系统开发方案项目/逻辑规则/成熟技术/源码功能
  DApp(去中心化应用程序)盲盒游戏系统的开发涉及到在区块链上构建和运行盲盒游戏。
|
安全 机器人 区块链
pancakeswap去中心化交易所夹子搬砖机器人系统开发玩法及规则/设计案例/方案详细/源码技术
 区块链最重要的功能,就是建立一种价值共识,而这个“共识”,主要基于“价值量化的能力”和“价值安全的过程”两个方面。先是“价值量化能力”:把一件事通过数字化的方式描述清楚,就是一个价值量化的过程。
|
存储 安全 算法
|
存储 前端开发 安全
BSC链盲盒游戏系统开发实现技术原理丨dapp盲盒游戏系统开发案例规则/源码设计/方案项目
  智能合约:它们是存储在区块链上的计算机程序,在满足预定条件时运行,智能合约是用Solidity语言编写的