Gas Fees & DFK Chain

Everything you wanted to know about gas

DeFi Kingdoms
DeFi Kingdoms Official
7 min readJun 21, 2023

--

Gas fees on DFK Chain have been a hot topic in recent weeks. Read on to learn more about how gas fees work, the relationship between fees and validators, and what has been impacting gas prices.

What are gas fees, and how are they calculated?

Gas fees are the costs associated with performing transactions or executing smart contracts on a blockchain. Gas fees are based on two factors: Gas Price and Gas Limit.

Gas Price

The Gas Price represents the amount of JEWEL a user is willing to pay for each unit of gas consumed during a transaction. It is measured in gwei (1 gwei = 0.000000001 JEWEL). Users set the gas price to incentivize miners to include their transactions in the next block.

On DFK Chain, the base fee is currently set to 3 gwei, which is the minimum amount a user needs to pay in order to submit a transaction. Higher gas prices increase the likelihood of faster transaction confirmation but come at a higher cost. The gas price is typically determined by market supply and demand dynamics.

Gas Limit

The Gas Limit refers to the maximum amount of gas that can be consumed by a transaction or a smart contract execution. It serves as a safety measure to prevent infinite loops in smart contract code or excessive resource consumption.

Each transaction on DFK Chain consumes a specific amount of gas during its execution, and the gas limit caps the total gas cost of a transaction.

Gas Fee

The final Gas Fee of a transaction is a multiplier of these two factors:

Gas Fee = Gas Price (in gwei) * Gas Limit

For example, if the gas price is set at 20 gwei and the gas limit is 100,000, the total gas fee would be 20 gwei * 100,000 = 2,000,000 gwei (or 0.002 JEWEL).

During times of high demand, gas fees tend to increase as users compete for limited block space. To increase the priority of the transaction in the mempool (the pool of all pending transactions on the chain ), users can optionally choose to pay an extra amount of JEWEL to have their transaction be prioritized, called a Priority Fee.

Similar to an auction, validators select the transactions in the mempool with the highest priority fees to be included in the next block, adding transactions to the block up to the block gas limit.

Metamask advanced gas fee settings menu

What is DFK Chain’s block gas limit, and why does it matter?

The block gas limit refers to the maximum size or capacity of each block in terms of gas units. It is currently set to 25,000,000 on DFK Chain.

The block gas limit matters for several reasons and can be adjusted if necessary by continually assessing and evaluating the optimal block gas limit based on the conditions of the network and its throughput needs.

If the block gas limit is too low, it may hinder the network’s ability to handle the growing demand for transactions and smart contract operations. If the block gas limit is too high however, it can drastically increase the amount of computational resources required to validate a block, reducing the probability that validator nodes can finalize blocks in a timely manner. If blocks are too large, it can result in increased strain on the validator nodes in the network, increasing the chances of network forks and decreasing the overall network stability and security.

The block gas limit also plays an important role in influencing the dynamic gas price.

How do dynamic gas fees work?

In order to protect the network from malicious actors, the base gas price will adjust dynamically based on the supply and demand of the blockchain. This is influenced by a parameter called Target Gas, which is currently set to 75,000,000 gas units on DFK Chain.

The network will automatically increase the base gas price if more than 75M gas units have been used in the last 5 blocks (~10s), and automatically decrease if less than 75M units have been used in the last 5 blocks.

The block explorers of most networks support detailed insights into the gas block usage. For DFK Chain, you can see this information here: https://subnets.avax.network/defi-kingdoms/blocks.

Example of a dynamic gas fee decrease, 49M gas units used within the last 5 blocks
Example of dynamic gas price increase, more than 75M gas units used within the last 5 blocks

The number of transactions per second is irrelevant for calculating the dynamic gas prices, as only the actual gas used matters. 100 transactions using 100k gas units each are the same to the network as 1 transaction using 10M gas units.

Some transactions, like swapping items at the Trader, use significantly less gas than, for example, a transaction starting or completing multiple Quests, which can use up to the maximum gas units set by the block limit (25M).

Put simply, the more complicated the smart contract interaction, the more gas units will be used.

What happens to the gas fees paid by the user?

The gas fees paid for transactions are currently distributed as follows:

  • 50% of the gas fees are burned
  • 25% are sent to the DFK Chain Quest Fund to reward active players
  • 25% are sent to the validator operators to cover running costs

Details about those numbers can be found on our validator dashboard at: https://validators.dfkchain.com/

Current all-time gas fee distribution

What are validators and how do they work?

Validators play a critical role in maintaining the network’s security through a proof-of-stake (PoS) consensus mechanism. Each time a block is proposed, all validators are polled for their preference for the latest block in the chain.

DFK Chain is currently run by 8 validator nodes with a 75% alpha value for the network, meaning each block needs to be confirmed by a quorum of at least 75% of validators’ worth of staking weight in order for all nodes to adopt that option as their preference. Validator nodes are constantly being monitored and updated with the latest releases of AvalancheGo and subnet-evm from Ava Labs.

For the first year since the genesis block of DFK Chain, all validators nodes have been run by Kingdom Studios in order to ensure the network’s stability and consensus as the first ever Subnet powered by Avalanche. DeFi Kingdoms is now looking to gradually open up DFK Chain to external validators to support decentralization while ensuring the stability of the network.

In the context of the DFK Chain Subnet, it is important to note that all validators are required to validate Avalanche C-Chain as well if they are looking to validate on DFK Chain. On top of network infrastructure costs, the requirements to validate on C-Chain are 2000 AVAX per validator node. Additionally, for validating DFK Chain, the requirements originally were 10,000 xJEWEL, which will be replaced by a to-be-decided amount of cJEWEL as we open up applications for external validators.

The full list of validators can be found at: https://validators.dfkchain.com/.

More details about Avalanche Consensus can be found at https://docs.avax.network/learn/avalanche/avalanche-consensus.

Why has the base gas fee increased recently, and what can be done about it?

Every additional on-chain feature that is added to DeFi Kingdoms spends additional gas units. Most notably, the recent Hero’s Best Friend patch introduced equipment that allows the bonding of Pets to Heroes as well as additional upgrades to the QuestCore contract. The additional logic added to account for Pets and the presence of Pet bonuses has resulted in the startQuest and completeQuest transactions using more gas units than previously.

These additional costs, while only marginally increasing the total gas units spent, have led to a more frequent crossing of the Target Gas threshold, thus triggering a dynamic base gas price increase. It is important to note that while the addition of Pet Utility causes the base gas fee to increase more frequently, it is not the main cause, nor is any particular feature.

DeFi Kingdoms is aware of the recent gas developments and is continuously monitoring on-chain activity. There are several angles to address high gas prices from a development perspective, for example:

  • Gas usage optimization: By constantly refactoring smart contracts to increase efficiency and logic, the overall gas units spent can be decreased to various degrees depending on the smart contract.
  • Minimizing transactions: Bundling transactions can lead to gas optimizations when the same events are called repeatedly (just reducing the transaction count or calling them in order will not decrease the gas spent).
  • Decrease Hero population inflation: As a major driver of on-chain activity, we are constantly looking at incentivizing Hero burn (the recent Dark Summoning event) or potentially restricting summoning (the Gen0 summoning cooldown increase RFC) to decrease population or slow down its increase.

Depending on the extent of the refactoring, rewriting contracts to utilize less gas can be a delicate undertaking that requires thorough testing and can take several weeks before deployment.

There are also other, more drastic measures that can be taken which we have alluded to on several occasions, such as utilizing an additional subnet to outsource some transactions.

However, we strongly believe that optimizing both gas and transaction logic will lead to significant improvements while also requiring fewer development resources and being less impactful to other items on our roadmap.

We will continue to update the community as we plan and make additional improvements.

--

--

DeFi Kingdoms
DeFi Kingdoms Official

A game, a DEX, a liquidity pool opportunity, a market of rare utility driven NFTs in the incredibly nostalgic form of fantasy pixel art.