zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

交易所开发成品丨交易所系统开发(演示版)丨交易所APP源码设计

App源码系统开发 设计 交易所 成品
2023-06-13 09:17:08 时间

What is the exchange?

An exchange is an information platform for trading certain information and goods. A fixed place is called an exchange. The exchange, with the help of information platform, realizes the sharing of property rights information, long-distance trading, unified coordination, and balance of property rights trading market and various terms.

The blockchain exchange is a matchmaking trading platform, which is compatible with the matching engine of traditional matchmaking rules, and the way of fund custody and delivery is replaced by the blockchain. Such a blockchain exchange can solve the unsolved problems of the blockchain, namely the issue of supply and demand information release and liquidity.

创建交易对

创建交易对的调用流程如下:

用户首先调用 NonfungiblePositionManager 合约的 createAndInitializePoolIfNecessary 方法创建交易对, 传入的参数为交易对的 token0, token1, fee 和初始价格 P−−√P.

NonfungiblePositionManager 合约内部通过调用 UniswapV3Factory 的 createPool 方法完成交易对的创建,然后对交易对进行初始化,初始化的作用就是给交易对设置一个初始的价格。

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