-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
209 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Gas Price Queries for Integrations | ||
|
||
Because `x/feemarket` uses a dynamic fee, end-users will need to query the module for the current `gasPrice` to use when building a transaction. | ||
|
||
A summary for the flow to query this information is as follows: | ||
|
||
* Create an RPC connection with the chain | ||
* Create a `feemarket` client | ||
* Submit the `GasPrice` query | ||
* Use the `gasPrice` to populate the Tx fee field. | ||
|
||
Extensive querying information can be seen in the module [spec](./README.md#query). | ||
|
||
The specific query for `GasPrices` can be found [here](./README.md#gas-prices). | ||
|
||
## Code Snippet | ||
|
||
Wallet, relayers, and other users will want to add programmatic ways to query this before building their transactions. Below is an example of how a user could implement this lightweight query in Go: | ||
|
||
### Create A gRPC Connection | ||
|
||
First, a base connection to the chain you are querying must be created. | ||
|
||
A chain gRPC (below) or CometBFT ABCI RPC connection can be created: | ||
|
||
```go | ||
// Set up gRPC connection to chain | ||
cc, err := grpc.NewClient(endpoint, insecure.NewCredentials()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer cc.Close() | ||
``` | ||
|
||
### Create a FeeMarket Query Client | ||
|
||
An `x/feemarket` query client can then be created using the created gRPC connection. | ||
|
||
This client exposes all [queries](./README.md#query) that the `x/feemarket` module exposes. | ||
|
||
```go | ||
// Create FeeMarketClient with underlying gRPC connection | ||
feeMarketClient := feemarkettypes.NewQueryClient(cc) | ||
``` | ||
|
||
### Query Gas Prices | ||
|
||
The `gas price` (as an `sdk.DecCoin`) can be queried using the `GasPrice` query. This query requires the desired coin denomination for the fee to be paid with. | ||
|
||
The query will return an error if the given denomination is not supported. | ||
|
||
```go | ||
gasPrice, err := feeMarketClient.GasPrice(ctx, &feemarkettypes.GasPriceRequest{ | ||
Denom: denom, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
``` | ||
|
||
### Using `gasPrice` to construct a transaction | ||
|
||
There are two ways to construct a transaction with `gasPrice`: | ||
|
||
1. Provide the minimum fee: `feeAmount = gasPrice * gasLimit` (`gasLimit` gives the maximum amount of gas a transaction can consume. You can obtain appropriate `gasLimit` by simulating a transaction to see how much gas it consumes under normal conditions). | ||
2. Provide a "tip" in addition to the minimum fee: `feeAmount=gasPrice * gasLimit + tip` This will be paid to the block proposer and result in your transaction being placed ahead of others with lower tips (or being included in the block instead of others when the block is full) | ||
|
||
### Understanding Fee Deducted | ||
|
||
The actual amount of fee deducted from the fee payer is based on gas consumed, not `gasLimit`. | ||
|
||
The amount consumed is equal to the `inferredTip + gasPrice * gasConsumed`, where `inferredTip = feeAmount - gasLimit * gasPrice` (This may be different than the tip you specified when building the transaction because the `gasPrice` on chain may have changed since when you queried it.) | ||
|
||
## Examples of Other EIP-1559 Integrations | ||
|
||
The [Osmosis](https://github.com/osmosis-labs/osmosis) Blockchain has a similar EIP-1559 feemarket that has been integrated by wallets and relayers. Below are some examples as to how different projects query the dynamic fee for transactions: | ||
|
||
* [Keplr Wallet EIP-1559 BaseFee Query](https://github.com/chainapsis/keplr-wallet/blob/b0a96c2c713d8163ce840fcd5abbac4eb612607c/packages/stores/src/query/osmosis/base-fee/index.ts#L18) | ||
* [Cosmos-Relayer EIP-1559 BaseFee Query](https://github.com/cosmos/relayer/blob/9b140b664fe6b10161af1093ccd26627b942742e/relayer/chains/cosmos/fee_market.go#L13) | ||
* [Hermes Relayer EIP-1559 Fee Query](https://github.com/informalsystems/hermes/blob/fc8376ba98e4b595e446b366b736a0c046d6026a/crates/relayer/src/chain/cosmos/eip_base_fee.rs#L15) | ||
* Note: Hermes also already implements a query `x/feemarket` seen [here](https://github.com/informalsystems/hermes/blob/fc8376ba98e4b595e446b366b736a0c046d6026a/crates/relayer/src/chain/cosmos/eip_base_fee.rs#L33) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Upgrading Your Chain to Use FeeMarket | ||
|
||
## Code Changes | ||
|
||
To integrate your chain with `x/feemarket`, the following steps should be performed: | ||
|
||
### Add the Module to Your App | ||
|
||
* The `FeeMarketKeeper` must be added to your application as seen [here](https://github.com/skip-mev/feemarket/blob/0f83e172c92a02db45f83bf89065fd9543967729/tests/app/app.go#L163). | ||
* A `DenomResolver` (if desired) must be set in your application as seen [here](https://github.com/skip-mev/feemarket/blob/0f83e172c92a02db45f83bf89065fd9543967729/tests/app/app.go#L509). | ||
* `Ante` and `Post` handlers must be configured and set with the application `FeeMarketKeeper` as seen [here](https://github.com/skip-mev/feemarket/blob/0f83e172c92a02db45f83bf89065fd9543967729/tests/app/app.go#L513). | ||
|
||
### Determine Parameters | ||
|
||
We provide sensible default parameters for running either the [EIP-1559](https://github.com/skip-mev/feemarket/blob/0f83e172c92a02db45f83bf89065fd9543967729/x/feemarket/types/eip1559.go#L56) or [AIMD EIP-1559](https://github.com/skip-mev/feemarket/blob/0f83e172c92a02db45f83bf89065fd9543967729/x/feemarket/types/eip1559_aimd.go#L65) feemarkets. | ||
|
||
> **Note** | ||
> | ||
> The default parameters use the default Cosmos SDK bond denomination. The should be modified to your chain's fee denomination. | ||
## Changes for End-Users | ||
|
||
With the addition of `x/feemarket`, there are some important changes that end-users must be aware of. | ||
|
||
1. A non-zero fee is _always required_ for all transactions. | ||
1. Pre-`x/feemarket` validators were able to set their `MinGasPrice` field locally, meaning it was possibly for some to have no required fees. This is no longer true as there is always a non-zero global fee for transactions. | ||
2. Fees are no longer static. | ||
1. The `gas price` will change with market activity, so to ensure that transactions will be included, wallets, relayers, etc. will need to query `x/feemarket` for the current fee state. See the [Querying Gas Price](#querying-gas-price-) section below. | ||
3. Fees _must_ always be a single coin denomination. | ||
1. Example `--fees skip` is valid while `--fees 10stake,10skip` is invalid | ||
|
||
> **Note** | ||
> | ||
> Fees are still paid using the `fees` [field](https://github.com/cosmos/cosmos-sdk/blob/d1aab15790570bff77aa0b8652288a276205efb0/proto/cosmos/tx/v1beta1/tx.proto#L214) of a Cosmos SDK Transaction as they were before. | ||
### Querying Gas Price | ||
|
||
Information on how to query and use dynamic gas prices can be found [here](./INTEGRATIONS.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.