paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.9k stars 697 forks source link

Configure Polkadot <> Kusama Bridge to Use Asset Conversion to Buy Execution #104

Closed joepetrowski closed 1 month ago

joepetrowski commented 1 year ago

At least initially, we expect the Polkadot<>Kusama bridge to maintain some assets on each side with which to buy execution. For example, we'd expect the Kusama Asset Hub (AH) to have some DOT in its sovereign account on Polkadot's AH, and then charge users extra KSM for transacting on Kusama's AH over the bridge to Polkadot's AH, where the XCM program would withdraw some DOT from its sovereign account to pay for execution locally.

This has some flaws, like ensuring that the correct additional amount is withdrawn on the Kusama side, and that it will be sufficient given the current weight-to-fee rate on Polkadot's AH, and the fact that this account would need to be occasionally topped up via governance.

By using asset conversion, the bridge could buy execution (accurately) in any asset it sends over, provided there is a pool for it (e.g. a pKSM <> DOT pair).

acatangiu commented 1 year ago

With https://kusama.subsquare.io/referenda/258 and https://polkadot.subsquare.io/referenda/122 we now have (k)DOT on Kusama AssetHub and (p)KSM on Polkadot AssetHub, both of which are marked as sufficient on their respective side. Meaning that fees and execution can be bought on either side with both DOT and KSM.

So we no longer need to manage (and periodically balance) these sovereign accounts of AHs on each respective side.

But, I believe we still need to use asset conversion (i.e. pKSM <> DOT and kDOT <> KSM pools) to figure out "the exchange rate" at which to spend non-native asset for buying execution on remote chain.

E.g.: Alice transfers 10 DOT from PAH (Polkadot AssetHub) to KAH (Kusama AssetHub) - and specifies that she wants to pay fees from transferred DOT - so Alice pays:

  1. 0.1 DOT for tx_fee on PAH
  2. buys X weight for execution of ExportMessage on PBH (Polkadot BridgeHub) - X weight on Polkadot -> 1 DOT (we have hardcoded exchange rate between weight and DOT on Polkadot)
  3. buys Y weight for XCM execution on target KAH - Y weight on Kusama -> ??? DOT (we know kusama_weight -> KSM conversion, but we don't know how much DOT to charge)

So, my guess is we'd use AssetConversion for #3, but don't know how/if we can hook that up to weight->asset calculator to make it "just work" for everyone.

joepetrowski commented 1 year ago

I think ultimately we will need https://github.com/paritytech/polkadot-sdk/issues/606 to make that work. Asset Conversion can publish recent rates of selected assets (e.g. KSM, USDT, ETH, etc.) and the Bridge Hub could subscribe to those.

acatangiu commented 1 year ago

This is all concerning target AssetHub, not BridgeHub.

I spoke to @bkontur and have more detail/context on what happens at target AH:

On AssetHubs we configure new XCM Trader which uses this multiplier to convert weight->asset_amount based on the asset's Existential Deposit.

I guess this is ok(ish):

but it'd be better if we could use AssetConversion here to do:

that way, all weight "costs" the same in native token, regardless of what is used to pay.

I think ultimately we will need https://github.com/paritytech/polkadot-sdk/issues/606 to make that work. Asset Conversion can publish recent rates of selected assets (e.g. KSM, USDT, ETH, etc.) and the Bridge Hub could subscribe to those.

Right now, we don't charge anything on target BH so we don't need this, but yes, we would use it if we start charging (possibly XCM HRMP delivery fee to target AH).

acatangiu commented 1 year ago

Ok, so we have https://github.com/paritytech/polkadot-sdk/issues/105 exactly for what I described above.

I guess we can close this issue then. 👍

acatangiu commented 1 month ago

close on behalf of https://github.com/paritytech/polkadot-sdk/issues/105