I am trying to calculate the cost of a transaction, post-hoc, from the response to calling the entrypoint. This is for the purposes of a testing tool I am building that I need accurate costs for.
As an example, I have the following information about the call I have just made from a call response:
res: {
operation_hash: 'op36m7td8UXUvCCUpZ72Xy3XLbU6pFf1VLF5y7cE6Rmb5qe7LNs',
storage_size: 24698,
consumed_gas: 15045.615,
paid_storage_size_diff: 96,
events: [],
}
I found a guide for calcuating cost from fees and burn. It includes this formula which seems fairly straightforward:
total_cost = burn + fees + amount of tez
burn = storage_difference * MINIMAL_FEE_PER_STORAGE_BYTE_MUTEZ
fees >= MINIMAL_FEE_MUTEZ +
MINIMAL_FEE_PER_BYTE_MUTEZ * size +
MINIMAL_FEE_PER_GAS_MUTEZ * gas
in practice:
fees in mutez >= 100 +
1 * size +
0.1 * gas
However, when I calculate the cost with the following formula:
function get_cost(
storage_difference: number = res.paid_storage_size_diff,
gas_use: number = res.consumed_gas,
bytes_size: number = res.storage_size,
) : BigNumber {
const fees = bytes_size + (gas_used*0.1)
const burn = storage_difference*1000
return new BigNumber(fees + burn)
}
Plugging in the response output from above, I get a cost of 114292.6447 mutez (the decimal places are another issue, as I believe mutez should be an integer. I guess I'm just meant to round them?)
However, I know from looking at the actual delta that true cost of calling this entrypoint in mockup mode is only 26028 mutez.
Please help me to understand what is wrong with my approach, and how (if) I can calculate the cost from the information I have.
Help greatly appreciated
EDIT
Thanks to @Groxan I now have the following formula:
function get_cost(
storage_difference: number = res.paid_storage_size_diff,
gas_used: number = res.consumed_gas,
bytes_size: number = res.storage_size,
) : BigNumber {
const fees = 100 + bytes_size + (gas_used*0.1)
const burn = storage_difference*250
return new BigNumber(fees + burn).integerValue(BigNumber.ROUND_UP)
}
This is much closer, but it is still giving me an answer that is a bit over twice the observable cost. This function predicts the cost should have been 50203 mutez. (vs the observed 26028)
Is there a different calculation or set of constants in use for the mockup mode?
Any ideas? Thanks all