interlay / interbtc-ui

Kintsugi and Interlay App - BTC DeFi
https://app.interlay.io/
Apache License 2.0
32 stars 30 forks source link

Better transaction fee estimation #1035

Closed gregdhill closed 1 year ago

gregdhill commented 1 year ago

Use https://polkadot.js.org/docs/api/cookbook/tx/#how-do-i-estimate-the-transaction-fees

sander2 commented 1 year ago

Separated into another ticket https://github.com/interlay/interbtc-ui/issues/1240 Related: it'd be a good idea to dry-run in advance to get quick feedback on failing transactions. I made this PoC about a year ago:

    let request_redeem = api.tx.redeem.requestRedeem(2000, {P2WPKHv0: '0x01197bcaf42e278fcca2b55275cd64b25d240e7c'}, vault_id);
    const transactionAPI = new DefaultTransactionAPI(api, userKeyring);

    let myNonce = await api.rpc.system.accountNextIndex(userKeyring.address);
    const signed = request_redeem.sign(userKeyring, { nonce:  myNonce});

    const result = await signed.dryRun(transactionAPI.getAccount()!);

    // A technically valid but failing transaction returns Ok(Err(...))
    const resultOk = result.isOk && result.asOk.isOk;

    console.log("isOk", resultOk);

And you can get the fees with

const paymentInfo = await signed.paymentInfo(transactionAPI.getAccount()!);
console.log("fee", paymentInfo.partialFee.toNumber());
peterslany commented 1 year ago

This ticket's scope was reduced and dry-running should be added separately https://github.com/interlay/interbtc-ui/issues/1240

github-actions[bot] commented 1 year ago

Running Lighthouse audit...