Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement dryRunCall option #433

Merged
merged 10 commits into from
Sep 24, 2024
Merged

Conversation

marshacb
Copy link
Contributor

@marshacb marshacb commented Sep 21, 2024

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

  • adds dryRunCall method to the AssetTransferApi.
  • Adds unit tests for dryRunCall
  • Adds error validation for dryRunCall option

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

@marshacb marshacb requested review from TarikGul and bee344 September 21, 2024 03:15
Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marshacb marshacb merged commit 9ea6e20 into main Sep 24, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add possibility of dry running XCM messages, calls, extrinsics
2 participants