paritytech / asset-transfer-api

Typescript API aiming to provide clear, and simple to use tools for transferring assets across common good parachains.
Apache License 2.0
43 stars 11 forks source link

feat: implement dryRunCall option #433

Closed marshacb closed 5 days ago

marshacb commented 1 week ago

Description

This PR introduces a dryRunCall option to optionally dry run a constructed extrinsic using the XCM DryRunApi. It returns the result of execution along with the expected xcm fees obtained from the XcmPaymentApi for each xcm message.

Changes

Example of using the dryRunCall option:

  const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io');
  const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
  let callInfo: TxResult<'call'>;
  try {
    callInfo = await assetApi.createTransferTransaction(
              '1002',
              '5HBuLJz9LdkUNseUEL6DLeVkx2bqEi6pQr8Ea7fS4bzx7i7E',
              ['wnd'],
              ['10000000000'],
              {
                  format: 'call',
                                  dryRunCall: true,
                                  xcmFeeAsset: 'wnd',
                  sendersAddr: '5EJWF8s4CEoRU8nDhHBYTT6QGFGqMXTmdQdaQJVEFNrG9sKy',
                  xcmVersion: 4,
              },
          );
  } 
console.log(callInfo);

Expected output:

{
    "origin": "westmint",
    "dest": "bridge-hub-westend",
    "direction": "SystemToSystem",
    "xcmVersion": 4,
    "method": "transferAssets",
    "format": "call",
    "tx": "0x1f0b04010100a90f0400010100e2aa84cbfa479f0150bb77eb06756ee2c725ec625e16dd68b2678a0820e8d83404040100000700e40b54020000000000",
    "xcmExecutionResult": {
        "ok": {
            "actualWeight": null,
            "paysFee": "Yes"
        }
    },
    "localXcmFees": [
        {
            "v4": [
                {
                    "withdrawAsset": [
                        {
                            "id": {
                                "parents": 1,
                                "interior": {
                                    "here": null
                                }
                            },
                            "fun": {
                                "fungible": 10000000000
                            }
                        }
                    ]
                },
                {
                    "burnAsset": [
                        {
                            "id": {
                                "parents": 1,
                                "interior": {
                                    "here": null
                                }
                            },
                            "fun": {
                                "fungible": 10000000000
                            }
                        }
                    ]
                }
            ]
        },
        {
            "xcmFee": "3593000000"
        }
    ],
    "forwardedXcmFees": [
        [
            {
                "v3": [
                    {
                        "receiveTeleportedAsset": [
                            {
                                "id": {
                                    "concrete": {
                                        "parents": 1,
                                        "interior": {
                                            "here": null
                                        }
                                    }
                                },
                                "fun": {
                                    "fungible": 10000000000
                                }
                            }
                        ]
                    },
                    {
                        "clearOrigin": null
                    },
                    {
                        "buyExecution": {
                            "fees": {
                                "id": {
                                    "concrete": {
                                        "parents": 1,
                                        "interior": {
                                            "here": null
                                        }
                                    }
                                },
                                "fun": {
                                    "fungible": 10000000000
                                }
                            },
                            "weightLimit": {
                                "unlimited": null
                            }
                        }
                    },
                    {
                        "depositAsset": {
                            "assets": {
                                "wild": {
                                    "allCounted": 1
                                }
                            },
                            "beneficiary": {
                                "parents": 0,
                                "interior": {
                                    "x1": {
                                        "accountId32": {
                                            "network": null,
                                            "id": "0xe2aa84cbfa479f0150bb77eb06756ee2c725ec625e16dd68b2678a0820e8d834"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    {
                        "setTopic": "0x11c9ecffba58cd0387336944af06b229b60ab139fcc3647a69e86ca423bc2026"
                    }
                ]
            },
            {
                "xcmFee": "3593000000"
            }
        ],
        [
            {
                "v3": [
                    {
                        "receiveTeleportedAsset": [
                            {
                                "id": {
                                    "concrete": {
                                        "parents": 1,
                                        "interior": {
                                            "here": null
                                        }
                                    }
                                },
                                "fun": {
                                    "fungible": 10000000000
                                }
                            }
                        ]
                    },
                    {
                        "clearOrigin": null
                    },
                    {
                        "buyExecution": {
                            "fees": {
                                "id": {
                                    "concrete": {
                                        "parents": 1,
                                        "interior": {
                                            "here": null
                                        }
                                    }
                                },
                                "fun": {
                                    "fungible": 10000000000
                                }
                            },
                            "weightLimit": {
                                "unlimited": null
                            }
                        }
                    },
                    {
                        "depositAsset": {
                            "assets": {
                                "wild": {
                                    "allCounted": 1
                                }
                            },
                            "beneficiary": {
                                "parents": 0,
                                "interior": {
                                    "x1": {
                                        "accountId32": {
                                            "network": null,
                                            "id": "0xe2aa84cbfa479f0150bb77eb06756ee2c725ec625e16dd68b2678a0820e8d834"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    {
                        "setTopic": "0x11c9ecffba58cd0387336944af06b229b60ab139fcc3647a69e86ca423bc2026"
                    }
                ]
            },
            {
                "xcmFee": "3593000000"
            }
        ],
        [
            {
                "v3": [
                    {
                        "receiveTeleportedAsset": [
                            {
                                "id": {
                                    "concrete": {
                                        "parents": 1,
                                        "interior": {
                                            "here": null
                                        }
                                    }
                                },
                                "fun": {
                                    "fungible": 10000000000
                                }
                            }
                        ]
                    },
                    {
                        "clearOrigin": null
                    },
                    {
                        "buyExecution": {
                            "fees": {
                                "id": {
                                    "concrete": {
                                        "parents": 1,
                                        "interior": {
                                            "here": null
                                        }
                                    }
                                },
                                "fun": {
                                    "fungible": 10000000000
                                }
                            },
                            "weightLimit": {
                                "unlimited": null
                            }
                        }
                    },
                    {
                        "depositAsset": {
                            "assets": {
                                "wild": {
                                    "allCounted": 1
                                }
                            },
                            "beneficiary": {
                                "parents": 0,
                                "interior": {
                                    "x1": {
                                        "accountId32": {
                                            "network": null,
                                            "id": "0xe2aa84cbfa479f0150bb77eb06756ee2c725ec625e16dd68b2678a0820e8d834"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    {
                        "setTopic": "0x11c9ecffba58cd0387336944af06b229b60ab139fcc3647a69e86ca423bc2026"
                    }
                ]
            },
            {
                "xcmFee": "3593000000"
            }
        ]
    ]
}

The following decoded tx:
 {
    "args": {
        "dest": {
            "V4": {
                "parents": "1",
                "interior": {
                    "X1": [
                        {
                            "Parachain": "1,002"
                        }
                    ]
                }
            }
        },
        "beneficiary": {
            "V4": {
                "parents": "0",
                "interior": {
                    "X1": [
                        {
                            "AccountId32": {
                                "network": null,
                                "id": "0xe2aa84cbfa479f0150bb77eb06756ee2c725ec625e16dd68b2678a0820e8d834"
                            }
                        }
                    ]
                }
            }
        },
        "assets": {
            "V4": [
                {
                    "id": {
                        "parents": "1",
                        "interior": "Here"
                    },
                    "fun": {
                        "Fungible": "10,000,000,000"
                    }
                }
            ]
        },
        "fee_asset_item": "0",
        "weight_limit": "Unlimited"
    },
    "method": "transferAssets",
    "section": "polkadotXcm"
}

closes: #412