Skip to content

Commit

Permalink
Add section to explain how to pay fees with different assets (#6084)
Browse files Browse the repository at this point in the history
* Add  section to explain how to pay fees with different assets

* Fixes

* remove unnecesary sentence

* small fixes to titles

* Apply suggestions from code review

Co-authored-by: Filippo <[email protected]>

---------

Co-authored-by: Filippo <[email protected]>
  • Loading branch information
IkerAlus and filippoweb3 authored Jul 22, 2024
1 parent ba8253b commit df6d237
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/build/build-integrate-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ Note that you can use the same addresses (except
you use on the Relay Chain. The SS58 encodings are the same; only the chain information (genesis
hash, etc.) will change on transaction construction.

#### Paying Transaction Fees in Another Asset
Users in the Asset Hub can pay the fees of their transactions with assets other than DOT. The only requirement is that a liquidity pool of the relevant asset against DOT should already exist as a storage entry of [the Asset Conversion pallet](../learn/learn-asset-conversion-assethub).

Technically speaking, this is enabled by [the `ChargeAssetTxPayment` signed-extension](https://github.com/polkadot-fellows/runtimes/blob/bb52c327360d1098d3b3d36f4eafb40a74636e80/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs#L1016) implemented in the Asset Hub runtime. This signed-extension extends transactions to include an optional `AssetId` that specifies the asset to be used for payment of both the execution fees and the optional tip. It defaults to the native token when it is set to `None`. In case it is given, this `AssetId` has to be an [XCM `Multilocation`](../learn/learn/xcm/fundamentals/multilocation-summary). Once the transaction is executed in the block, it will emit an `AssetTxFeePaid` event, informing of the account paying the fees, the amount in the asset paid as fee, the tip (if any), and the asset ID of the asset paying the fees.

**Handling Pools with Low Liquidity**

Wallets and UIs enabling this functionality should ensure that the user is prompted with the necessary warnings, such that they do not accidentally spend all of their funds to perform a swap on a pool with no or low liquidity.

##### How to Build Transactions Paying Fees with Other Assets

- [This repository](https://github.com/bee344/asset-conversion-example/tree/main) contains the complete workflow on how to create a liquidity pool for a given asset, add liquidity to it and then build a transaction to pays fees with this asset (including fees estimation). It is done with several libraries: Polkadot.js API and Subxt.
- [Example using Asset Transfer API](https://github.com/paritytech/asset-transfer-api/blob/main/examples/polkadot/assetHub/paysWithFeeOriginTransfers/dotToHydrationPaysWithGLMR.ts) to do a cross-chain transfer in Polkadot Asset Hub paying fees with GLMR.
- [A simple script](https://github.com/bee344/asset-hub-examples/blob/main/polkadot-js-example/src/foreignAssetTransferWithFee.ts) using Polkadot.js API to do a local transfer of bridged KSM in Polkadot Asset Hub paying fees with USDT.

### Foreign Assets

Foreign assets are those assets in Asset Hub whose native blockchain is not Asset Hub. These are
Expand Down

0 comments on commit df6d237

Please sign in to comment.