如何在 liquidswap 上添加自己的交易对

xiang
发布于 阅读 467

场景:自己部署了一个 SunCoin,想让它能跟 AptosCoin 进行兑换。

大致步骤:

  1. 按照官方教程部署自定义的 Coin,并 mint 一些币作为测试。
  2. 部署一个 liquid pool 合约,这个合约非常简单,只有三行代码
  3. 调用 liquidswap script 合约,注册 LP,并添加一些流动性。
  4. https://liquidswap.com/#/ 上添加自己部署的 pool 信息即可

Coin 合约:

module SunCoin::sun_coin {
    struct SunCoin {}

    fun init_module(sender: &signer) {
        aptos_framework::managed_coin::initialize<SunCoin>(
            sender,
            b"Sun Coin",
            b"SUN",
            6,
            false,
        );
    }
}

lp 合约:

module liquidswap_lp::lp {
    struct LP<phantom X, phantom Y> {}
}

部署 SunCoin 合约,并注册领取代币:

# publish module
aptos move publish --named-addresses SunCoin=<your address>

# register coin type for your account
aptos move run \
    --function-id=0x1::managed_coin::register \
    --type-args '<your address>::sun_coin::SunCoin'

# mint some test coin to your account
aptos move run \
    --function-id=0x1::managed_coin::mint \
    --type-args '<your address>::sun_coin::SunCoin' \
    --args 'address:<mint to address>' 'u64:10000000'

部署 lp 合约

# publish module
aptos move publish --named-addresses liquidswap_lp=<your address>

创建池子并添加流动性。这里需要保证 symbolA 的长度 <= symbolB 的长度。相同长度时保证 symbolA < symbolB:

  • APT, BTC ok
  • APT, OP fail
  • SUN, MOON ok
# register pool and add liquidity
aptos move run \
    --function-id=0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::scripts::register_pool_and_add_liquidity \
    --type-args '<CoinA Type>' '<CoinB Type>' '<your address>::lp::LP<CoinAType,CoinBType>' \
    --args 'u8:2' 'u64:1000000' 'u64:1000000' 'u64:1000000' 'u64:1000000'

最后在 https://liquidswap.com/#/ 网站添加你的池子即可。

详细的步骤及代码可以从这个仓库查看:https://github.com/xiang-xx/liquidswap-pool-example

标签: Aptos #Aptos
评论