区块链交易所开发详细丨区块链交易所系统开发(开发方案)丨区块链交易所源码案例部署

简介: Players or investors can trade directly without the intervention of a third party intermediary,making the transaction more convenient,fast and transparent.Optimize resource allocation.

  What are the characteristics of blockchain exchanges?

  1.Decentralization

  Players or investors can trade directly without the intervention of a third party intermediary,making the transaction more convenient,fast and transparent.Optimize resource allocation.

  2.Good user experience

  The exchange is directly customer-oriented,so it will put user needs first in design,pay more attention to user experience,and also provide customers with more value-added services to ensure user stickiness.

  3.Open platform,information symmetry

  The core of making money in many traditional industries is to make use of the asymmetry of information.On the digital currency trading platform,both parties conduct direct transactions,which is more timely,fair and transparent.

  4.Low transaction cost

  Low transaction cost and fast speed greatly optimize the environment for small-cap investment.

  5.Big data plays a prominent role

  Taking full advantage of the accumulation and mining of Internet technology and data information,the scale of customers in the Internet financial ecosystem has reached a high level and the cost of customer selection is low.

  在NonfungiblePositionManager中回调函数的实现如下:

  struct MintCallbackData{

  PoolAddress.PoolKey poolKey;

  address payer;//支付token的地址

  }

  ///inheritdoc IUniswapV3MintCallback

  function uniswapV3MintCallback(

  uint256 amount0Owed,

  uint256 amount1Owed,

  bytes calldata data

  )external override{

  MintCallbackData memory decoded=abi.decode(data,(MintCallbackData));

  CallbackValidation.verifyCallback(factory,decoded.poolKey);

  //根据传入的参数,使用transferFrom代用户向Pool中支付token

  if(amount0Owed>0)pay(decoded.poolKey.token0,decoded.payer,msg.sender,amount0Owed);

  if(amount1Owed>0)pay(decoded.poolKey.token1,decoded.payer,msg.sender,amount1Owed);

  }

  流动性的添加主要在UniswapV3Pool._modifyPosition中,这个函会先调用_updatePosition来创建或修改一个用户的Position,省略其中的非关键步骤:

  function _updatePosition(
  address owner,

  int24 tickLower,

  int24 tickUpper,

  int128 liquidityDelta,

  int24 tick

  )private returns(Position.Info storage position){

  //获取用户的Postion

  position=positions.get(owner,tickLower,tickUpper);

  ...

  //根据传入的参数修改Position对应的lower/upper tick中

  //的数据,这里可以是增加流动性,也可以是移出流动性

  bool flippedLower;

  bool flippedUpper;

  if(liquidityDelta!=0){

  uint32 blockTimestamp=_blockTimestamp();

  //更新lower tikc和upper tick

  //fippedX变量表示是此tick的引用状态是否发生变化,即

  //被引用->未被引用或

  //未被引用->被引用

  //后续需要根据这个变量的值来更新tick位图

  flippedLower=ticks.update(

  tickLower,

  tick,

  liquidityDelta,

  _feeGrowthGlobal0X128,

  _feeGrowthGlobal1X128,

  false,

  maxLiquidityPerTick

  );

  flippedUpper=ticks.update(

  tickUpper,

  tick,

  liquidityDelta,

  _feeGrowthGlobal0X128,

  _feeGrowthGlobal1X128,

  true,

  maxLiquidityPerTick

  );

  //如果一个tick第一次被引用,或者移除了所有引用

  //那么更新tick位图

  if(flippedLower){

  tickBitmap.flipTick(tickLower,tickSpacing);

  secondsOutside.initialize(tickLower,tick,tickSpacing,blockTimestamp);

  }

  if(flippedUpper){

  tickBitmap.flipTick(tickUpper,tickSpacing);

  secondsOutside.initialize(tickUpper,tick,tickSpacing,blockTimestamp);

  }

  }

  ...

  //更新position中的数据

  position.update(liquidityDelta,feeGrowthInside0X128,feeGrowthInside1X128);

  //如果移除了对tick的引用,那么清除之前记录的元数据

  //这只会发生在移除流动性的操作中

  if(liquidityDelta<0){

  if(flippedLower){

  ticks.clear(tickLower);

  secondsOutside.clear(tickLower,tickSpacing);

  }

  if(flippedUpper){

  ticks.clear(tickUpper);

  secondsOutside.clear(tickUpper,tickSpacing);

  }

  }

  }

  先忽略费率相关的操作,这个函数所做的操作是:

  添加/移除流动性时,先更新这个Positon对应的lower/upper tick中记录的元数据

  更新position

  根据需要更新tick位图

  Postion是以owner,lower tick,uppper tick作为键来存储的,注意这里的owner实际上是NonfungiblePositionManager合约的地址。这样当多个用户在同一个价格区间提供流动性时,在底层的UniswapV3Pool合约中会将他们合并存储。而在NonfungiblePositionManager合约中会按用户来区别每个用户拥有的Position.

  Postion中包含的字段中,除去费率相关的字段,只有一个即流动性LL:

  library Position{

  //info stored for each user's position

  struct Info{

  //此position中包含的流动性大小,即L值

  uint128 liquidity;

  ...

  }

  更新position只需要一行调用:

  position.update(liquidityDelta,feeGrowthInside0X128,feeGrowthInside1X128);

  其中包含了position中流动性LL的更新,以及手续费相关的计算。

相关文章
|
26天前
|
安全 区块链
区块链积分商城系统开发详细指南//需求功能/指南教程/源码流程
Developing a blockchain points mall system involves multiple aspects such as blockchain technology, smart contracts, front-end development, and business logic design. The following is the general process for developing a blockchain points mall system
|
1月前
|
安全 JavaScript 前端开发
区块链钱包系统开发解决方案/需求设计/功能逻辑/案例详细/源码步骤
The development of a blockchain wallet system involves multiple aspects, and the following is the detailed logic for developing a blockchain wallet system:
|
27天前
|
监控 前端开发 安全
区块链积分商城系统开发详细步骤及源码
区块链积分商城系统涉及到多个方面的技术和流程。以下是一般开发流程的简要概述
|
1月前
|
安全 AndFix 区块链
区块链3D元宇宙游戏系统开发规则玩法/步骤指南/源码项目
Developing a blockchain metaverse 3D game system is a complex and innovative process that requires comprehensive consideration of blockchain technology, game design and development, and virtual reality (VR). The following is the general process for developing the system:
|
1月前
|
安全 区块链
区块链游戏系统开发步骤需求丨功能逻辑丨规则玩法丨指南教程丨源码详细
Developing blockchain game systems has been a highly anticipated field in recent years. By combining blockchain technology and game mechanics, players can enjoy a brand new gaming experience and higher game credibility.
|
15天前
|
存储 传感器 监控
未来智能城市中的区块链技术应用
随着城市化进程不断加速,智能城市成为了未来城市发展的主要趋势之一。区块链技术作为一种去中心化、安全可靠的数据传输和存储方式,将在智能城市建设中发挥关键作用。本文将探讨区块链技术在智能城市中的应用场景,并分析其对城市管理、信息共享和安全保障等方面的积极影响。
14 2
|
22天前
|
存储 供应链 区块链
区块链技术在供应链管理中的应用与展望
随着区块链技术的不断发展,其在供应链管理领域的应用愈发广泛。本文将深入探讨区块链技术在供应链管理中的具体应用及未来发展趋势,分析其对供应链透明度、可追溯性和安全性的影响,并展望区块链技术在未来供应链管理中的潜在作用和挑战。
16 0
|
24天前
|
存储 安全 物联网
未来技术纵横谈:区块链、物联网和虚拟现实的革新之路
在科技不断进步的今天,新兴技术正以前所未有的速度改变着我们的生活和工作方式。本文将深入探讨区块链、物联网(IoT)以及虚拟现实(VR)这三项技术的发展趋势与潜在应用场景,揭示它们如何塑造一个更加智能、互联和沉浸式的未来世界。通过对这些技术的综合分析,我们旨在提供一个全面的视角,以理解它们在未来社会结构中的重要性及影响。
22 7
|
25天前
|
存储 人工智能 供应链
区块链技术在供应链管理中的应用
传统的供应链管理系统存在着诸多问题,如信息不对称、数据可信度低等。区块链技术作为一种分布式账本技术,在供应链管理中具有独特优势。本文将探讨区块链技术在供应链管理中的应用,介绍其原理和优势,并分析实际案例以及未来发展趋势。
|
3天前
|
供应链 算法 安全
区块链技术的应用与前景展望
区块链技术的应用与前景展望

热门文章

最新文章