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

[CL]: Deprecate duplicated queries from gamm module #3905

Merged
merged 8 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#3817](https://github.com/osmosis-labs/osmosis/pull/3817) Move osmoassert from `app/apptesting/osmoassert` to `osmoutils/osmoassert`.
* [#3771](https://github.com/osmosis-labs/osmosis/pull/3771) Move osmomath into its own go.mod
* [#3827](https://github.com/osmosis-labs/osmosis/pull/3827) Move osmoutils into its own go.mod
* [#3905](https://github.com/osmosis-labs/osmosis/pull/3905) Deprecate gamm queries `NumPools`, `EstimateSwapExactAmountIn` and `EstimateSwapExactAmountOut`.
* [#3907](https://github.com/osmosis-labs/osmosis/pull/3907) Add `NumPools`, `EstimateSwapExactAmountIn` and `EstimateSwapExactAmountOut` query in swaprouter module to stargate whitelist.




### Bug fixes

* [#3608](https://github.com/osmosis-labs/osmosis/pull/3608) Make it possible to state export from any directory.
Expand Down
16 changes: 12 additions & 4 deletions proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ service Query {
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools";
}

// Deprecated: please use the alternative in x/swaprouter
rpc NumPools(QueryNumPoolsRequest) returns (QueryNumPoolsResponse) {
option deprecated = true;
option (google.api.http).get = "/osmosis/gamm/v1beta1/num_pools";
}

Expand Down Expand Up @@ -85,15 +87,18 @@ service Query {
"/osmosis/gamm/v1beta1/pools/{pool_id}/prices";
}

// Estimate the swap.
// Deprecated: please use the alternative in x/swaprouter
rpc EstimateSwapExactAmountIn(QuerySwapExactAmountInRequest)
returns (QuerySwapExactAmountInResponse) {
option deprecated = true;
option (google.api.http).get =
"/osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_in";
}

// Deprecated: please use the alternative in x/swaprouter
rpc EstimateSwapExactAmountOut(QuerySwapExactAmountOutRequest)
returns (QuerySwapExactAmountOutResponse) {
option deprecated = true;
option (google.api.http).get =
"/osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_out";
}
Expand Down Expand Up @@ -121,8 +126,9 @@ message QueryPoolsResponse {
}

//=============================== NumPools
message QueryNumPoolsRequest {}
message QueryNumPoolsRequest { option deprecated = true; }
message QueryNumPoolsResponse {
option deprecated = true;
uint64 num_pools = 1 [ (gogoproto.moretags) = "yaml:\"num_pools\"" ];
}

Expand Down Expand Up @@ -257,7 +263,7 @@ message QuerySpotPriceResponse {

//=============================== EstimateSwapExactAmountIn
message QuerySwapExactAmountInRequest {
// TODO: CHANGE THIS TO RESERVED IN A PATCH RELEASE
option deprecated = true;
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
uint64 pool_id = 2 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string token_in = 3 [ (gogoproto.moretags) = "yaml:\"token_in\"" ];
Expand All @@ -268,6 +274,7 @@ message QuerySwapExactAmountInRequest {
}

message QuerySwapExactAmountInResponse {
option deprecated = true;
string token_out_amount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"token_out_amount\"",
Expand All @@ -277,7 +284,7 @@ message QuerySwapExactAmountInResponse {

//=============================== EstimateSwapExactAmountOut
message QuerySwapExactAmountOutRequest {
// TODO: CHANGE THIS TO RESERVED IN A PATCH RELEASE
option deprecated = true;
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
uint64 pool_id = 2 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
repeated SwapAmountOutRoute routes = 3 [
Expand All @@ -288,6 +295,7 @@ message QuerySwapExactAmountOutRequest {
}

message QuerySwapExactAmountOutResponse {
option deprecated = true;
string token_in_amount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"token_in_amount\"",
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (n *NodeConfig) CreatePool(poolFile, from string) uint64 {
bz, err := n.QueryGRPCGateway(path)
require.NoError(n.t, err)

//nolint:staticcheck
var numPools gammtypes.QueryNumPoolsResponse
err = util.Cdc.UnmarshalJSON(bz, &numPools)
require.NoError(n.t, err)
Expand Down
1 change: 1 addition & 0 deletions wasmbinding/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
// thread safe sync.Map.
var stargateWhitelist sync.Map

//nolint:staticcheck
func init() {
// cosmos-sdk queries

Expand Down
13 changes: 8 additions & 5 deletions x/concentrated-liquidity/model/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ func (p *Pool) UpdateLiquidityIfActivePosition(ctx sdk.Context, lowerTick, upper
// lower and upper ticks.
// There are 3 possible cases:
// -The position is active ( lowerTick <= p.CurrentTick < upperTick).
// * The provided liqudity is distributed in both tokens.
// * Actual amounts might differ from desired because we recalculate them from liquidity delta and sqrt price.
// the calculations lead to amounts being off. // TODO: confirm logic is correct
// - The provided liqudity is distributed in both tokens.
// - Actual amounts might differ from desired because we recalculate them from liquidity delta and sqrt price.
// the calculations lead to amounts being off. // TODO: confirm logic is correct
//
// - Current tick is below the position ( p.CurrentTick < lowerTick).
// * The provided liquidity is distributed in token0 only.
// - The provided liquidity is distributed in token0 only.
//
// - Current tick is above the position ( p.CurrentTick >= p.upperTick ).
// * The provided liquidity is distributed in token1 only.
// - The provided liquidity is distributed in token1 only.
//
// TODO: add tests.
func (p Pool) CalcActualAmounts(ctx sdk.Context, lowerTick, upperTick int64, sqrtRatioLowerTick, sqrtRatioUpperTick sdk.Dec, liquidityDelta sdk.Dec) (actualAmountDenom0 sdk.Dec, actualAmountDenom1 sdk.Dec) {
if p.isCurrentTickInRange(lowerTick, upperTick) {
Expand Down
5 changes: 5 additions & 0 deletions x/gamm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func GetCmdPools() (*osmocli.QueryDescriptor, *types.QueryPoolsRequest) {
{{.CommandPrefix}} pools`}, &types.QueryPoolsRequest{}
}

// nolint: staticcheck
func GetCmdNumPools() *cobra.Command {
return osmocli.SimpleQueryCmd[*types.QueryNumPoolsRequest](
"num-pools",
Expand Down Expand Up @@ -195,6 +196,7 @@ func GetCmdSpotPrice() (*osmocli.QueryDescriptor, *types.QuerySpotPriceRequest)
}

// GetCmdEstimateSwapExactAmountIn returns estimation of output coin when amount of x token input.
// nolint: staticcheck
func GetCmdEstimateSwapExactAmountIn() (*osmocli.QueryDescriptor, *types.QuerySwapExactAmountInRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-swap-exact-amount-in <poolID> <sender> <tokenIn>",
Expand All @@ -207,6 +209,7 @@ func GetCmdEstimateSwapExactAmountIn() (*osmocli.QueryDescriptor, *types.QuerySw
}

// GetCmdEstimateSwapExactAmountOut returns estimation of input coin to get exact amount of x token output.
// nolint: staticcheck
func GetCmdEstimateSwapExactAmountOut() (*osmocli.QueryDescriptor, *types.QuerySwapExactAmountOutRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-swap-exact-amount-out <poolID> <sender> <tokenOut>",
Expand All @@ -218,6 +221,7 @@ func GetCmdEstimateSwapExactAmountOut() (*osmocli.QueryDescriptor, *types.QueryS
}, &types.QuerySwapExactAmountOutRequest{}
}

// nolint: staticcheck
func EstimateSwapExactAmountInParseArgs(args []string, fs *flag.FlagSet) (proto.Message, error) {
poolID, err := strconv.Atoi(args[0])
if err != nil {
Expand All @@ -237,6 +241,7 @@ func EstimateSwapExactAmountInParseArgs(args []string, fs *flag.FlagSet) (proto.
}, nil
}

// nolint: staticcheck
func EstimateSwapExactAmountOutParseArgs(args []string, fs *flag.FlagSet) (proto.Message, error) {
poolID, err := strconv.Atoi(args[0])
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func (q Querier) Pools(
}, nil
}

// TODO: mark deprecated and move to swaprouter.
// This query has been deprecated and has been moved to swaprouter module.
// nolint: staticcheck
func (q Querier) NumPools(ctx context.Context, _ *types.QueryNumPoolsRequest) (*types.QueryNumPoolsResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

Expand Down Expand Up @@ -410,6 +411,8 @@ func (q Querier) TotalLiquidity(ctx context.Context, _ *types.QueryTotalLiquidit
}

// EstimateSwapExactAmountIn estimates input token amount for a swap.
// This query is deprecated and has been moved to swaprouter module.
// nolint: staticcheck
func (q Querier) EstimateSwapExactAmountIn(ctx context.Context, req *types.QuerySwapExactAmountInRequest) (*types.QuerySwapExactAmountInResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down Expand Up @@ -440,6 +443,8 @@ func (q Querier) EstimateSwapExactAmountIn(ctx context.Context, req *types.Query
}

// EstimateSwapExactAmountOut estimates token output amount for a swap.
// This query is deprecated and has been moved to swaprouter module.
// nolint: staticcheck
func (q Querier) EstimateSwapExactAmountOut(ctx context.Context, req *types.QuerySwapExactAmountOutRequest) (*types.QuerySwapExactAmountOutResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down
Loading