跨链流动网络BancorX

BancorX提供了不同区块链之间BNT代币的流动,目前打通的区块链只有ETH跟EOS,即ETH跟EOS之间的BNT代币可以自由转换,打开https://x.bancor.network/网站,就可以实现EOS跟ETH之间的BNT的转换。在上一篇 EOS Bancor Network剖析已经讲到了bancor网络在eos上的实现,给出的智能合约代码中其实已经包含BancorX在eos上的实现,baocor网络在EOS上实现的智能合约代码:https://github.com/bancorprotocol/contracts_eos

下面举例说明跨链转换BNT的过程,从EOS转1BNT到ETH地址,vergilvergil===》0x6a77cFA8e9c6Be6e033E634FbaeDe9756a4fAD14,流程如下:


跨链流动网络BancorX_第1张图片

1)在eos网络中从vergilvergi转账1BNT到bancorxoneos并带上留言MEMO: 1.1,ethereum,0x6a77cFA8e9c6Be6e033E634FbaeDe9756a4fAD14,这个留言是关键表明这是跨链转换目标是eth的0x6a77cFA8e9c6Be6e033E634FbaeDe9756a4fAD14地址
2)bancorxoneos账号的BancorX合约中检测到上述留言会产生一个内联action用来销毁刚刚接收到的1BNT,代码如下

void BancorX::xtransfer(string blockchain, name from, string target, asset quantity) {
    settings settings_table(_self, _self.value);
    auto st = settings_table.get();

    eosio_assert(st.xt_enabled, "x transfers are disabled");

    uint64_t prev_destroy_limit = st.prev_destroy_limit;
    uint64_t prev_destroy_time = st.prev_destroy_time;
    uint64_t limit_inc = st.limit_inc;

    uint64_t timestamp = current_time() / 500000;

    uint64_t current_delta = 0;
    if (timestamp > prev_destroy_time)
        current_delta = timestamp - prev_destroy_time;

    uint64_t current_limit = std::min(prev_destroy_limit + limit_inc * current_delta, st.max_destroy_limit);

    eosio_assert(quantity.amount >= st.min_limit, "below min limit");
    eosio_assert(quantity.amount <= current_limit, "above max limit");

  // 销毁刚刚收到的BNT
    action(
        permission_level{ _self, "active"_n },
        st.x_token_name, "retire"_n,
        std::make_tuple(quantity,std::string("destroy on x transfer"))
    ).send();

    st.prev_destroy_limit = current_limit - quantity.amount;
    st.prev_destroy_time  = timestamp;
    settings_table.set(st, _self);

    EMIT_DESTROY_EVENT(from, quantity);
    EMIT_X_TRANSFER_EVENT(blockchain, target, quantity);
}

3)链下Bancor团队检测到在eos上的上述交易,然后在ETH上通过合约0x98a741591049b6a92d7266a0668a26aaf61a1b5e在目标地址转相应的BNT,这个过程在链下完成,不过我们可以在链上验证,如下就是这笔在ETH对于的trx https://etherscan.io/tx/0x5def8cacf0b4930a4f8be63fad6d50904b66b6682cad174fd45961fe2f39c814

通过上述1),2),3)过程就完成从eos网络转BNT到eth,这里1),2)过程都是链上智能合约完成,3)过程是链下完成,不过我们可以在链上验证,从eth转BNT到eos过程类似,最终通过BancorX合约reporttx动作issue相应的bnt到指定eos账号

你可能感兴趣的:(跨链流动网络BancorX)