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

[TASK] Calculate estimated fee for substrate based transactions #364

Closed
4 tasks
salman01zp opened this issue Mar 9, 2023 · 1 comment · Fixed by #375
Closed
4 tasks

[TASK] Calculate estimated fee for substrate based transactions #364

salman01zp opened this issue Mar 9, 2023 · 1 comment · Fixed by #375
Assignees
Labels
difficulty: medium 🚩 feature ➕ Tasks that are functional additions or enhancements p1 🟠 Issue should be resolved sooner than later task ✔️

Comments

@salman01zp
Copy link
Contributor

salman01zp commented Mar 9, 2023

Overview

Calculate the estimated fee for relaying substrate based transactions/extrinsic. Fees on substrate based chains are calculated based on three parameters

  • Base Fee
  • Length Fee
  • Network congestion

You can read more about fee details here

Here is an open issue on subxt Return fee details for an Extrinsic #527


Task Checklist

Similar to EVM Fees Enpoint, we will need one for Substrate.

  • Add an API endpoint that takes in the (TypedChainId, VAnchorTreeId, estimatedXtFees) and returns the relayer estimated fees.
  • Calculate the estimated fee for relaying transaction (see below for the calculation)
  • Add validation check for fee submitted by a user.
  • Write tests to ensure that the above functionality works correctly

Estimate the Extrinsic fees

There is an RPC method that you can call with the signed extrinsic call and it will return the fees details, this RPC is payment_queryFeeDetails. Here is an example:

  • Request Payload:
{"id":1,"jsonrpc":"2.0","method":"payment_queryInfo","params":["0xad0184008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010124010000000004306d000000"]}
  • Response:
{"jsonrpc":"2.0","result":{"weight":1307595,"class":"normal","partialFee":"1130000000100090506"},"id":1}

On the client side, the user will use this method to estimate the fees so they can send to the relayer.

You will notice the following information in the result:

partialFee = "1130000000100090506";

The final fee is like the following:

// Calculates the fees in how much tokens
fee = parseInt(partialFee) / (10 ** tokenDecimals)

Example:

tokenDecimals = 18; // for tTNT (Tangle Standalone Test Network)
partialFee = "1130000000100090506";
fee = parseInt(partialFee) / (10 ** tokenDecimals) // => 1.1300 tTNT

// The calculated fees above, is the base transaction fees that the relayer will pay for sending this transaction.

If you are using polkadot API, you can see the docs here about estimating the transaction fees.

Wrapped Token to the Native token Conversion

When working on the VAnchors, we are working on wrapped tokens, each VAnchor as an associated assetId that can be later used to get that asset information, for example say we have assetId = 1, by calling assetRegistry.assets we will get the following:

{
  name: webbtTNT
  assetType: PoolShare
  existentialDeposit: 100,000,000,000,000,000
  locked: false
}

You will notice the name is webbtTNT and it is a wrapped token over the native tTNT token, so it should be 1:1 conversion in this case.

Please Notice that since currently there is no way for us to fetch prices of Substrate tokens, we will (for now) hardcode the price of the 1 tTNT = $0.10. That also could change in the future.

@shekohex shekohex added p1 🟠 Issue should be resolved sooner than later feature ➕ Tasks that are functional additions or enhancements task ✔️ difficulty: medium 🚩 labels Mar 9, 2023
@shekohex shekohex moved this to Planning 🗺️ in Webb Universe Mar 9, 2023
@shekohex shekohex moved this from Planning 🗺️ to Not Started 🕧 in Webb Universe Mar 10, 2023
@shekohex
Copy link
Collaborator

Related to tangle-network/tangle#151

@shekohex shekohex moved this from Not Started 🕧 to Planning 🗺️ in Webb Universe Mar 10, 2023
@shekohex shekohex moved this from Planning 🗺️ to Building 🏗️ in Webb Universe Mar 24, 2023
@shekohex shekohex linked a pull request Mar 27, 2023 that will close this issue
2 tasks
@shekohex shekohex mentioned this issue Mar 27, 2023
2 tasks
@Nutomic Nutomic moved this from Building 🏗️ to On Hold 🛑 in Webb Universe Apr 20, 2023
@shekohex shekohex moved this from On Hold 🛑 to Building 🏗️ in Webb Universe May 5, 2023
@github-project-automation github-project-automation bot moved this from Building 🏗️ to Completed ✅ in Webb Universe May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium 🚩 feature ➕ Tasks that are functional additions or enhancements p1 🟠 Issue should be resolved sooner than later task ✔️
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants