defi丨dapp丨nft丨lp流动性质押挖矿分红开发详细,defi丨dapp丨nft丨lp流动性质押挖矿分红系统开发(源码版)

简介:  Liquidity mining encourages users to pledge tokens and pledge vouchers to liquidity mining contracts. For users, using DeFi will not only gain the original profits, but also obtain liquidity mining rewards. Inspired by liquidity mining, it has promoted users to become the LP of DeFi and promoted th

  Liquidity mining encourages users to pledge tokens and pledge vouchers to liquidity mining contracts. For users, using DeFi will not only gain the original profits, but also obtain liquidity mining rewards. Inspired by liquidity mining, it has promoted users to become the LP of DeFi and promoted the rapid growth of DeFi.

首先调用UniswapV3Factory.getPool方法查看交易对是否已经创建,getPool函数是solidity自动为UniswapV3Factory合约中的状态变量getPool生成的外部函数,getPool的数据类型为:

  contract UniswapV3Factory is IUniswapV3Factory,UniswapV3PoolDeployer,NoDelegateCall{

  ...

  mapping(address=>mapping(address=>mapping(uint24=>address)))public override getPool;

  ...

  }

  使用3个map说明了v3版本使用(tokenA,tokenB,fee)来作为一个交易对的键,即相同代币,不同费率之间的流动池不一样。另外对于给定的tokenA和tokenB,会先将其地址排序,将地址值更小的放在前,这样方便后续交易池的查询和计算。

  再来看UniswapV3Factory创建交易对的过程,实际上它是调用deploy函数完成交易对的创建:

  function deploy(

  address factory,

  address token0,

  address token1,

  uint24 fee,

  int24 tickSpacing

  )internal returns(address pool){

  parameters=Parameters({factory:factory,token0:token0,token1:token1,fee:fee,tickSpacing:tickSpacing});

  pool=address(new UniswapV3Pool{salt:keccak256(abi.encode(token0,token1,fee))}());

  delete parameters;

  }

  createAndInitializePoolIfNecessary如下:

  function createAndInitializePoolIfNecessary(

  address tokenA,

  address tokenB,

  uint24 fee,

  uint160 sqrtPriceX96

  )external payable returns(address pool){

  pool=IUniswapV3Factory(factory).getPool(tokenA,tokenB,fee);

  if(pool==address(0)){

  pool=IUniswapV3Factory(factory).createPool(tokenA,tokenB,fee);

  IUniswapV3Pool(pool).initialize(sqrtPriceX96);

  }else{

  (uint160 sqrtPriceX96Existing,,,,,,)=IUniswapV3Pool(pool).slot0();

  if(sqrtPriceX96Existing==0){

  IUniswapV3Pool(pool).initialize(sqrtPriceX96);

  }

  }

相关文章
分享82个Html经典模板,总有一款适合您
分享82个Html经典模板,总有一款适合您
289 0
|
存储 缓存 安全
【面试题精讲】String 为什么是不可变的?
【面试题精讲】String 为什么是不可变的?
|
JavaScript NoSQL Java
高并发架构系列:Redis为什么是单线程、及高并发快的3大原因详解
Redis的高并发和快速原因 1.redis是基于内存的,内存的读写速度非常快;2.redis是单线程的,省去了很多上下文切换线程的时间;3.redis使用多路复用技术,可以处理并发的连接。非阻塞IO 内部实现采用epoll,采用了epoll+自己实现的简单的事件框架。
5005 0
|
数据处理 Python
熵值法计算权重
熵值法计算权重是一种基于信息论的方法,用于多指标综合评价。通过计算各指标的信息熵,反映指标的变异程度,从而确定其在综合评价中的权重。熵值越小,表示信息量越大,指标的重要性越高。该方法适用于样本数据较少的情形,能有效避免主观因素的影响。文中详细介绍了熵值法的原理、计算步骤及Python实现代码。
2604 1
|
机器学习/深度学习 人工智能 数据挖掘
【AI 现况分析】AI大模型在欺诈检测中具体的应用
【1月更文挑战第26天】【AI 现况分析】AI大模型在欺诈检测中具体的应用
|
前端开发
基于jeecgboot的flowable流程任务excel导出功能
基于jeecgboot的flowable流程任务excel导出功能
349 1
|
供应链 JavaScript API
简化数据迁移:API接口的应用
在现代商业环境中,数据迁移已经成为企业运营中不可或缺的一部分。随着技术的进步和市场的变化,企业需要将商品数据从一个系统迁移到另一个更高效或更具成本效益的系统。这一过程可以借助应用程序编程接口(API)来简化。以下是如何通过使用API接口来简化商品数据迁移过程的详细步骤。
|
机器学习/深度学习 数据采集 人工智能
|
算法 计算机视觉
【图像处理】基于双目视觉的物体体积测量算法研究(Matlab代码实现)
【图像处理】基于双目视觉的物体体积测量算法研究(Matlab代码实现)
345 0