Skip to content

Commit

Permalink
Add Taker Fee Query (#6680)
Browse files Browse the repository at this point in the history
* Add trader fee query

* Generated protofile changes

* Add Taker fee

* Add querier logic

* Generated protofile changes

* Add grpc guery.go

* Generated protofile changes

* Update proto/osmosis/poolmanager/v1beta1/query.proto

Co-authored-by: Adam Tucker <[email protected]>

* Update proto/osmosis/poolmanager/v1beta1/query.proto

Co-authored-by: Adam Tucker <[email protected]>

* Add cli

* Generated protofile changes

* register query in query server

---------

Co-authored-by: github-actions <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
  • Loading branch information
4 people authored and pysel committed Oct 17, 2023
1 parent c8bd842 commit 452841b
Show file tree
Hide file tree
Showing 10 changed files with 695 additions and 118 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#6421](https://github.com/osmosis-labs/osmosis/pull/6421) Moves ValidatePermissionlessPoolCreationEnabled out of poolmanager module
* [#6627](https://github.com/osmosis-labs/osmosis/pull/6627) Limit pow iterations in osmomath.
* [#6586](https://github.com/osmosis-labs/osmosis/pull/6586) add auth.moduleaccounts to the stargate whitelist
* [#6680](https://github.com/osmosis-labs/osmosis/pull/6680) Add Taker Fee query and add it to stargate whitelist

### Bug Fixes
* [#6644](https://github.com/osmosis-labs/osmosis/pull/6644) fix: genesis bug in pool incentives linking NoLock gauges and PoolIDs
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdv
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
Expand Down Expand Up @@ -964,6 +965,7 @@ github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231011004221-fd24b80f8366 h1
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231011004221-fd24b80f8366/go.mod h1:YEMUPuI9gBUATC4tp2MiW0oWRlShli0K95JqgNKJh9c=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231011004221-fd24b80f8366 h1:EJDJ88w2Yv5LnlaJw5x53C0k/dp/fnEYOfBYOQiMsTc=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231011004221-fd24b80f8366/go.mod h1:Zmyx5zMUBN2KV94booSFn2v8KQcUKeCHqyWpKZ4PRMo=
github.com/osmosis-labs/osmosis/v19 v19.0.0 h1:gqcas/XfxtEuZXsWGTO9vNMHiY78Qs09FBQw73djIVM=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231011004221-fd24b80f8366 h1:E6H0V3MKbSNwo1iXE9Kzatd2M02MgZpS5AiJ6CKK5us=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231011004221-fd24b80f8366/go.mod h1:vU0IHK5W38dqMeux3MkSaT3MZU6whAkx7vNuxv1IzeU=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231012010556-df85839cab74 h1:zgv48lalsD2PX/4TiFep/xJBvwXXAr8emnQOL5i6zcc=
Expand Down
20 changes: 20 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ service Query {
"/osmosis/poolmanager/v1beta1/pools/{pool_id}/total_volume";
}

// TradingPairTakerFee returns the taker fee for a given set of denoms
rpc TradingPairTakerFee(TradingPairTakerFeeRequest)
returns (TradingPairTakerFeeResponse) {
option (google.api.http).get =
"/osmosis/poolmanager/v1beta1/pools/trading_pair_takerfee";
}

// EstimateTradeBasedOnPriceImpact returns an estimated trade based on price
// impact, if a trade cannot be estimated a 0 input and 0 output would be
// returned.
Expand Down Expand Up @@ -281,6 +288,19 @@ message TotalVolumeForPoolResponse {
];
}

//=============================== TradingPairTakerFee
message TradingPairTakerFeeRequest {
string denom_0 = 1 [ (gogoproto.moretags) = "yaml:\"denom_0\"" ];
string denom_1 = 2 [ (gogoproto.moretags) = "yaml:\"denom_1\"" ];
}

message TradingPairTakerFeeResponse {
string taker_fee = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

//=============================== EstimateTradeBasedOnPriceImpact

// EstimateTradeBasedOnPriceImpactRequest represents a request to estimate a
Expand Down
5 changes: 5 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/query.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ queries:
response: "*queryproto.EstimateTradeBasedOnPriceImpactResponse"
cli:
cmd: "EstimateTradeBasedOnPriceImpact"
TradingPairTakerFee:
proto_wrapper:
query_func: "k.GetTradingPairTakerFee"
cli:
cmd: "TradingPairTakerFee"
1 change: 1 addition & 0 deletions wasmbinding/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func init() {
setWhitelistedQuery("/osmosis.poolmanager.v1beta1.Query/SpotPrice", &poolmanagerqueryproto.SpotPriceResponse{})
setWhitelistedQuery("/osmosis.poolmanager.v1beta1.Query/TotalPoolLiquidity", &poolmanagerqueryproto.TotalPoolLiquidityResponse{})
setWhitelistedQuery("/osmosis.poolmanager.v1beta1.Query/Params", &poolmanagerqueryproto.ParamsResponse{})
setWhitelistedQuery("/osmosis.poolmanager.v1beta1.Query/TradingPairTakerFee", &poolmanagerqueryproto.TradingPairTakerFeeResponse{})

// txfees
setWhitelistedQuery("/osmosis.txfees.v1beta1.Query/FeeTokens", &txfeestypes.QueryFeeTokensResponse{})
Expand Down
10 changes: 10 additions & 0 deletions x/poolmanager/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetQueryCmd() *cobra.Command {
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdAllPools)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdPool)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTotalVolumeForPool)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTradingPairTakerFee)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateTradeBasedOnPriceImpact)
cmd.AddCommand(
osmocli.GetParams[*queryproto.ParamsRequest](
Expand Down Expand Up @@ -181,6 +182,15 @@ func GetCmdTotalVolumeForPool() (*osmocli.QueryDescriptor, *queryproto.TotalVolu
}, &queryproto.TotalVolumeForPoolRequest{}
}

func GetCmdTradingPairTakerFee() (*osmocli.QueryDescriptor, *queryproto.TradingPairTakerFeeRequest) {
return &osmocli.QueryDescriptor{
Use: "trading-pair-taker-fee",
Short: "Query trading pair taker fee",
Long: `{{.Short}}
{{.CommandPrefix}} trading-pair-taker-fee uosmo uatom`,
}, &queryproto.TradingPairTakerFeeRequest{}
}

func GetCmdEstimateTradeBasedOnPriceImpact() (
*osmocli.QueryDescriptor, *queryproto.EstimateTradeBasedOnPriceImpactRequest,
) {
Expand Down
10 changes: 10 additions & 0 deletions x/poolmanager/client/grpc/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ type Querier struct {

var _ queryproto.QueryServer = Querier{}

func (q Querier) TradingPairTakerFee(grpcCtx context.Context,
req *queryproto.TradingPairTakerFeeRequest,
) (*queryproto.TradingPairTakerFeeResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(grpcCtx)
return q.Q.TradingPairTakerFee(ctx, *req)
}

func (q Querier) TotalVolumeForPool(grpcCtx context.Context,
req *queryproto.TotalVolumeForPoolRequest,
) (*queryproto.TotalVolumeForPoolResponse, error) {
Expand Down
12 changes: 12 additions & 0 deletions x/poolmanager/client/query_proto_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ func (q Querier) TotalVolumeForPool(ctx sdk.Context, req queryproto.TotalVolumeF
}, nil
}

// TradingPairTakerFee returns the taker fee for the given trading pair
func (q Querier) TradingPairTakerFee(ctx sdk.Context, req queryproto.TradingPairTakerFeeRequest) (*queryproto.TradingPairTakerFeeResponse, error) {
tradingPairTakerFee, err := q.K.GetTradingPairTakerFee(ctx, req.Denom_0, req.Denom_1)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &queryproto.TradingPairTakerFeeResponse{
TakerFee: tradingPairTakerFee,
}, nil
}

// EstimateTradeBasedOnPriceImpact returns the input and output amount of coins for a pool trade
// based on external price and maximum price impact.
func (q Querier) EstimateTradeBasedOnPriceImpact(
Expand Down
Loading

0 comments on commit 452841b

Please sign in to comment.