liftedinit / ghostcloud-frontend

Frontend for the CosmosSDK-based Ghostcloud Decentralized Web Hosting platform
0 stars 3 forks source link

feat: flexible pricing #25

Closed fmorency closed 9 months ago

fmorency commented 9 months ago

The PR adds support for a flexible pricing scheme based on a fixed gas price provided by the validators. The total fees are calculated following

fees = gasPrice * gasConsumption

where gasPrice is a fixed price provided by the validators and gasConsumption is the total gas consumed by the transaction. Since the gasConsumption component is unknown before executing the transaction, the following strategy is used to determine the fees

  1. Retrieve an estimated gasConsumption' value using cosmjs client simulate() function.
  2. Calculate the final fees using cosmjs calculateFee(GAS_LIMIT, gasPrice) function, where GAS_LIMIT is gasConsumption' * LIMIT_MULTIPLIER, where LIMIT_MULTIPLIER is a pre-defined adjustment factor to allow some wiggle room as it is not rare that the gas estimation gasConsumption' is under-estimated.

The resulting behavior is that it will consume more tokens the bigger the deployment unless the gasPrice is set to 0.

E.g., deploying a 4.8MB compressed website resulting in a 23token fee, while deploying a 600kB compressed website results in a 1token fee.

The gas price and limit multiplier can be configured in the .env* files, e.g.,

...
NEXT_PUBLIC_GHOSTCLOUD_GAS_PRICE=0.000000025
NEXT_PUBLIC_GHOSTCLOUD_GAS_LIMIT_MULTIPLIER=1.5
...

Relates #10 Relates https://github.com/liftedinit/ghostcloud-cosmos/pull/33