前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >交易所开发成品丨交易所系统开发(演示版)丨交易所APP源码设计

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

原创
作者头像
系统_I8O28578624
发布2023-02-21 15:26:07
3570
发布2023-02-21 15:26:07
举报
文章被收录于专栏:YYDSYYDS

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 如下:

代码语言:javascript
复制
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);
        }
    }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
区块链
云链聚未来,协同无边界。腾讯云区块链作为中国领先的区块链服务平台和技术提供商,致力于构建技术、数据、价值、产业互联互通的区块链基础设施,引领区块链底层技术及行业应用创新,助力传统产业转型升级,推动实体经济与数字经济深度融合。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档