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

简介: 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的更新,以及手续费相关的计算。

相关文章
|
18天前
|
安全 区块链
区块链积分商城系统开发详细指南//需求功能/指南教程/源码流程
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
|
18天前
|
安全 JavaScript 前端开发
区块链钱包系统开发解决方案/需求设计/功能逻辑/案例详细/源码步骤
The development of a blockchain wallet system involves multiple aspects, and the following is the detailed logic for developing a blockchain wallet system:
|
18天前
|
数据采集 监控 算法
区块链量化交易系统开发策略详细丨需求步骤丨案例设计丨规则玩法丨成熟源码
策略:建立数据采集系统,获取各种市场数据,包括交易数据、新闻情报、社交媒体消息等。
|
8天前
|
存储 算法 安全
区块链系统开发技术规则分析
区块链核心技术包括:1) 哈希算法,利用单向函数将任意数据转化为固定长度代码,确保安全验证;2) 非对称加密,使用公钥和私钥一对进行加密解密,保证信息安全;3) 共识机制,如PoW、PoS、DPoS等,实现快速交易验证和确认;4) 智能合约,自动执行的可信代码,一旦编写即不可更改,用于自动化交易;5) 分布式存储,将数据分散存储在网络各处,涵盖结构化、非结构化和半结构化数据。
|
18天前
|
安全 算法 区块链
区块链系统开发|(成熟技术)/区块链系统开发介绍方案
区块链架构自下而上包括数据层、网络层、共识层、激励层、契约层和应用层。数据层涉及底层区块和基础数据;网络层实现节点间的分布式通信;共识层确保去中心化网络中节点对区块有效性的共识;激励层提供参与区块链安全验证的节点奖励;契约层支持智能合约,实现交易模式的编程;应用层则将区块链技术应用于现实生活场景。激励层、契约层和应用层并非所有区块链应用的必要组成部分。
|
18天前
|
测试技术 区块链
swap开发/区块链跨链技术系统开发规则
跨链技术通过验证源链状态和中继交易至目标链实现交互,关键组件是跨链桥,用于通证在不同链间的转移。桥通过智能合约锁定/销毁源链通证并在目标链解锁/铸造。简单的跨链桥仅适用于通证传输,而可编程通证桥支持更复杂交互,如交易中的交换、借贷等。任意数据消息传递协议则提供更通用功能,能构建跨链DApp,如跨链DEX、NFT和游戏。
|
18天前
|
监控 前端开发 安全
区块链积分商城系统开发详细步骤及源码
区块链积分商城系统涉及到多个方面的技术和流程。以下是一般开发流程的简要概述
|
18天前
|
供应链 区块链
区块链DAPP质押合约代币系统开发|模式方案
智能合约是一种数字化的合约,它将合约内容写入区块链中,保证了合约的公开透明
|
18天前
|
安全 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:
|
18天前
|
安全 区块链
区块链游戏系统开发步骤需求丨功能逻辑丨规则玩法丨指南教程丨源码详细
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.