fcl-js icon indicating copy to clipboard operation
fcl-js copied to clipboard

Add API for handling fee calculations.

Open pgebheim opened this issue 4 years ago • 0 comments

Overview

With the segmented transaction fees work which is going into the April 6 spork, as described by FLIP-660 and FLIP-753, transaction fees will need to be calculated via a few simple parameters instead of being a fixed rate. In order to do this clients need access to the latest fee rates stored on the FlowFees smart contract.

Issue To Be Solved

  • Create a stored interaction + FCL api which makes it easy for users to fetch the feeParameters member of the FlowFees smart contract. The exact call needed is here in FlowFees.cdc.
  • Ideally these numbers would be returned in a format suitable to do math on to compute the transaction total fee.
  • Fee Parameters should be cached for the lifetime of the FCL object.
  • An additional API should be added which will compute for an application the fee for a transaction given an arbitrary executionEffort and inclusionEffort

Desired API:

interface FeeParameters {
  surgeFactor: number;
  inclusionEffortCost: number;
  executionEffortCost: number;
}
function getFlowFeeParameters() => Promise<FeeParameters>;
function calculateTotalFees(exectionEffort: number, inclusionEffort: number): Promise<number>;

However, if this doesn't fit with the FCL zeitgeist, then perhaps just a stored interact to get the data, plus a helper to do the compute:

function calculateTotalFees(feeParams: FeeParameters, executionEffort: number, inclusionEffort: number): number {
    return (
        inclusionEffort * feeParams.inclusionEffortCost +
        executionEffort * feeParams.executionEffortCost
    ) * feeParams.surgeFactor;
}

Notes:

  • inclusionEffort is currently a static 1

pgebheim avatar Apr 04 '22 23:04 pgebheim