Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ability to pay tx fees with various tokens #28

Merged
merged 24 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0377b54
txfees proto files with modifications
mtsitrin Nov 29, 2023
3d4e8c0
genereated proto and initial skeleton
mtsitrin Nov 29, 2023
9ffa35c
removed arbitrage handling logic
mtsitrin Dec 3, 2023
6821100
preparing the ante handlers
mtsitrin Dec 3, 2023
667730c
updared feedecorator
mtsitrin Dec 3, 2023
3d7a34e
implemented pool hooks
mtsitrin Dec 3, 2023
f979491
cleanup and fix epoch hooks
mtsitrin Dec 3, 2023
9fcddbd
UT
mtsitrin Dec 3, 2023
f1dcf48
validating epoch identifier on genesis
mtsitrin Dec 4, 2023
5aba2f1
skipping unknown tokens
mtsitrin Dec 4, 2023
400e7af
cli UT
mtsitrin Dec 4, 2023
d9537dc
skip fee check on deliverTx
mtsitrin Dec 5, 2023
ef4c659
reimplemented taker fee to use txfees for swap and burn
mtsitrin Dec 6, 2023
7251143
updated taker fee tests
mtsitrin Dec 6, 2023
9a062e4
fixed gamm events tests
mtsitrin Dec 6, 2023
5190006
added params to the txfees module
mtsitrin Dec 6, 2023
f1e58e3
Merge branch 'txfees' into 27-non-dym-taker-fee-should-be-passed-to-t…
mtsitrin Dec 6, 2023
d071f79
adjusted gas estimation to include the mempool decorator
mtsitrin Dec 6, 2023
cb2b2d4
added missing query params
mtsitrin Dec 6, 2023
3259caa
Merge branch 'txfees' into 27-non-dym-taker-fee-should-be-passed-to-t…
mtsitrin Dec 6, 2023
9740353
fixed PR comments
mtsitrin Dec 7, 2023
6f6dbf8
Merge branch 'txfees' into 27-non-dym-taker-fee-should-be-passed-to-t…
mtsitrin Dec 7, 2023
6ed84ee
simplified code. removed union. extracting first pool for taker fee o…
mtsitrin Dec 7, 2023
5b0d85d
Merge pull request #32 from dymensionxyz/27-non-dym-taker-fee-should-…
mtsitrin Dec 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions proto/osmosis/txfees/v1beta1/feetoken.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";
package osmosis.txfees.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/osmosis-labs/osmosis/v15/x/txfees/types";

// FeeToken is a struct that specifies a coin denom, and pool ID pair.
// This marks the token as eligible for use as a tx fee asset in Osmosis.
// Its price in osmo is derived through looking at the provided pool ID.
// The pool ID must have base denom as one of its assets.
message FeeToken {
option (gogoproto.equal) = true;

string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
uint64 poolID = 2 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}
25 changes: 25 additions & 0 deletions proto/osmosis/txfees/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package osmosis.txfees.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/txfees/v1beta1/feetoken.proto";


option go_package = "github.com/osmosis-labs/osmosis/v15/x/txfees/types";

// GenesisState defines the txfees module's genesis state.
message GenesisState {
// params are all the parameters of the module
Params params = 1 [ (gogoproto.nullable) = false ];
string basedenom = 2;
repeated FeeToken feetokens = 3 [ (gogoproto.nullable) = false ];
}


// Params holds parameters for the incentives module
message Params {
// epoch_identifier is what epoch type swap and burn will be triggered by
// (day, week, etc.)
string epoch_identifier = 1
[ (gogoproto.moretags) = "yaml:\"epoch_identifier\"" ];
}
88 changes: 88 additions & 0 deletions proto/osmosis/txfees/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
syntax = "proto3";
package osmosis.txfees.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/duration.proto";

import "osmosis/txfees/v1beta1/feetoken.proto";
import "osmosis/txfees/v1beta1/genesis.proto";

option go_package = "github.com/osmosis-labs/osmosis/v15/x/txfees/types";

service Query {
// Params returns params.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/osmosis/txfees/v1beta1/params";
}


// FeeTokens returns a list of all the accepted fee tokens and their
// corresponding pools. It does not include the BaseDenom, which has its own
// query endpoint
rpc FeeTokens(QueryFeeTokensRequest) returns (QueryFeeTokensResponse) {
option (google.api.http).get = "/osmosis/txfees/v1beta1/fee_tokens";
}

// DenomSpotPrice returns all spot prices by each registered token denom.
rpc DenomSpotPrice(QueryDenomSpotPriceRequest)
returns (QueryDenomSpotPriceResponse) {
option (google.api.http).get =
"/osmosis/txfees/v1beta1/spot_price_by_denom";
}

// Returns the poolID for a specified denom input.
rpc DenomPoolId(QueryDenomPoolIdRequest) returns (QueryDenomPoolIdResponse) {
option (google.api.http).get =
"/osmosis/txfees/v1beta1/denom_pool_id/{denom}";
}

// Returns a list of all base denom tokens and their corresponding pools.
rpc BaseDenom(QueryBaseDenomRequest) returns (QueryBaseDenomResponse) {
option (google.api.http).get = "/osmosis/txfees/v1beta1/base_denom";
}
}


message QueryParamsRequest {}
message QueryParamsResponse {
Params params = 1 [ (gogoproto.nullable) = false ];
}


message QueryFeeTokensRequest {}
message QueryFeeTokensResponse {
repeated FeeToken fee_tokens = 1 [
(gogoproto.moretags) = "yaml:\"fee_tokens\"",
(gogoproto.nullable) = false
];
}

// QueryDenomSpotPriceRequest defines grpc request structure for querying spot
// price for the specified tx fee denom
message QueryDenomSpotPriceRequest {
string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
}

// QueryDenomSpotPriceRequest defines grpc response structure for querying spot
// price for the specified tx fee denom
message QueryDenomSpotPriceResponse {
uint64 poolID = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string spot_price = 2 [
(gogoproto.moretags) = "yaml:\"spot_price\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message QueryDenomPoolIdRequest {
string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
}
message QueryDenomPoolIdResponse {
uint64 poolID = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}

message QueryBaseDenomRequest {}
message QueryBaseDenomResponse {
string base_denom = 1 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ];
}
2 changes: 0 additions & 2 deletions x/gamm/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ const (
AttributeKeyTokensIn = "tokens_in"
AttributeKeyTokensOut = "tokens_out"
)

//FIXME: Add events for taker fee
56 changes: 56 additions & 0 deletions x/txfees/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Txfees

The txfees modules allows nodes to easily support many tokens for usage as txfees, while letting node operators only specify their tx fee parameters for a single "base" asset.
This is done by having this module maintain an allow-list of token denoms which can be used as tx fees, each with some associated metadata.
Then this metadata is used in tandem with a "Spot Price Calculator" provided to the module, to convert the provided tx fees into their equivalent value in the base denomination.
Currently the only supported metadata & spot price calculator is using a GAMM pool ID & the GAMM keeper.

## State Changes

* Adds a whitelist of tokens that can be used as fees on the chain.
* Any token not on this list cannot be provided as a tx fee.
* Any fee that is paid with a token that is on this list but is
not the base denom will be collected in a separate module
account to be batched and swapped into the base denom at the end
of each epoch.
* Adds a new SDK message for creating governance proposals for adding new TxFee denoms.

## Local Mempool Filters Added

* If you specify a min-tx-fee in the $BASEDENOM then
* Your node will allow any tx w/ tx fee in the whitelist of fees, and a sufficient osmo-equivalent price to enter your mempool
* The osmo-equivalent price for determining sufficiency is rechecked after every block. (During the mempools RecheckTx)
* TODO: further consider if we want to take this tradeoff. Allows someone who manipulates price for one block to flush txs using that asset as fee from most of the networks' mempools.
* The simple alternative is only check fee equivalency at a txs entry into the mempool, which allows someone to manipulate price down to have many txs enter the chain at low cost.
* Another alternative is to use TWAP instead of Spot Price once it is available on-chain
* The former concern isn't very worrisome as long as some nodes have 0 min tx fees.
* A separate min-gas-fee can be set on every node for arbitrage txs. Methods of detecting an arb tx atm
* does start token of a swap = final token of swap (definitionally correct)
* does it have multiple swap messages, with different tx ins. If so, we assume its an arb.
* This has false positives, but is intended to avoid the obvious solution of splitting an arb into multiple messages.
* We record all denoms seen across all swaps, and see if any duplicates. (TODO)
* Contains both JoinPool and ExitPool messages in one tx.
* Has some false positives.
* These false positives seem like they primarily will get hit during batching of many distinct operations, not really in one atomic action.
* A max wanted gas per any tx can be set to filter out attack txes.
* If tx wanted gas > than predefined threshold of 1M, then separate 'min-gas-price-for-high-gas-tx' option used to calculate min gas price.

## Queries

base-denom

- Query the base fee denom

denom-pool-id

- Query the pool id associated with a specific whitelisted fee token

fee-tokens

- Query the list of non-basedenom fee tokens and their associated pool ids

## Future directions

* Want to add in a system to add in general "tx fee credits" for different on-chain usages
* e.g. making 0 fee txs under certain usecases
* If other chains would like to use this, we should brainstorm mechanisms for extending the metadata proto fields
Loading