在 moonbase 平行链上创建一个基于中继链 rococo 上原生代币 DOT 的外部 XC-20

参考资料:

  1. 注册 foreignAsset

    1. Extrinsic hex-encoded data: 0x04001f00000100147863444f54147863444f540c000100000000000000000000000000000001

    Trick of hex-encoded data

    1. Sudo 调用 assetManager.registerForeignAsset

      1. XcmV1MultiLocation 表明目标相对当前链的位置
        1. https://hackmd.io/S4TZc1uTQH-vxEWv-QFapg
        2. Parents=1: Parents refer to how many "hops" in the upwards direction you have to do if you are going through the relay chain. 向上跨链传输消息的次数为1
        3. Interior=here: 从平行链的视角,中继链上的原生代币DOT等价于中继链的位置,也就是向上跨链一次即可,因此Interior=here
      2. 其余参数含义与创建可铸造 XC-20 时一样
        1. Decimals: 12 这样才能与中继链一致

      Untitled

  2. assetManager.setAssetUnitsPerSecond:

    1. Extrinsic hex-encoded data: 0x04001f010001000000000000000000000000000000000000000000
    2. XcmV1MultiLocation 与上一步相同
    3. unitsPerSecond: 设置XCM手续费,以xcDOT为单位,可设置为0
    4. numAssetsWeightHint: 每调用一次该接口,就要给此数加1
      1. 用于计算extrinsic的weight,指storage中有多少个foreign asset
      2. thats a weight hint, in order to accurately calculate how much weight the extrinsic consumes, we need to know how many items there are in storage. But we cannot do that unless we do a db read, which is something we dont wanna do in the weight calculation. So the way it works is: the user provides that number, we calculate the weight with that number, and then we verify the user-provided input matches what we have in db
  3. 最终得到的 外部 XC-20 信息

    1. 计算预编译合约地址:
    2. https://docs.moonbeam.network/builders/xcm/xc20/xc20/#calculate-xc20-address
    3. address = "0xFFFFFFFF..." + DecimalToHex(AssetId)
    Local Asset Id: 42,259,045,809,535,163,221,576,417,993,425,387,648
    42259045809535163221576417993425387648
    Name: xcDOT
    Symbol: xcDOT
    Contract Address: 0xFFFFFFFF1FCACBD218EDC0EBA20FC2308C778080
    
  4. 使用Remix交互(与 可铸造 XC-20 中类似)

    1. ERC-20 Interface — as described in the XC-20 overview page
    2. Permit Interface (EIP-712 compliant) — as described in the XC-20 overview page
    3. 也可以将其导入到MetaMask的代币中