-
Notifications
You must be signed in to change notification settings - Fork 607
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: x/cosmwasmpool proto and query boilerplate #4764
Changes from 4 commits
b299aa0
46c2206
b2fecd3
dceb80d
2e569db
ce80081
b55dd98
49259ce
4d07910
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
syntax = "proto3"; | ||
package osmosis.cosmwasmpool.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/any.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "google/protobuf/duration.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/types"; | ||
|
||
// Params holds parameters for the cosmwasmpool module | ||
message Params {} | ||
|
||
// GenesisState defines the cosmwasmpool module's genesis state. | ||
message GenesisState { | ||
// params is the container of cosmwasmpool parameters. | ||
Params params = 1 [ (gogoproto.nullable) = false ]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
syntax = "proto3"; | ||
|
||
package osmosis.cosmwasmpool.v1beta1; | ||
|
||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/model"; | ||
|
||
message CosmWasmPool { | ||
option (gogoproto.goproto_getters) = false; | ||
option (gogoproto.goproto_stringer) = false; | ||
option (cosmos_proto.implements_interface) = "PoolI"; | ||
string pool_address = 1 [ (gogoproto.moretags) = "yaml:\"pool_address\"" ]; | ||
string contract_address = 2 | ||
[ (gogoproto.moretags) = "yaml:\"contract_address\"" ]; | ||
uint64 pool_id = 3; | ||
uint64 code_id = 4; | ||
bytes instantiate_msg = 5 | ||
p0mvn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[ (gogoproto.moretags) = "yaml:\"instantiate_msg\"" ]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
package osmosis.cosmwasmpool.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/model"; | ||
|
||
service MsgCreator { | ||
rpc CreateCosmWasmPool(MsgCreateCosmWasmPool) | ||
returns (MsgCreateCosmWasmPoolResponse); | ||
} | ||
|
||
// ===================== MsgCreateCosmwasmPool | ||
message MsgCreateCosmWasmPool { | ||
uint64 code_id = 1 [ (gogoproto.moretags) = "yaml:\"code_id\"" ]; | ||
bytes instantiate_msg = 2 | ||
[ (gogoproto.moretags) = "yaml:\"instantiate_msg\"" ]; | ||
string sender = 3 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; | ||
} | ||
|
||
// Returns a unique poolID to identify the pool with. | ||
message MsgCreateCosmWasmPoolResponse { | ||
uint64 pool_id = 1 [ (gogoproto.customname) = "PoolID" ]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
package osmosis.cosmwasmpool.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "osmosis/cosmwasmpool/v1beta1/genesis.proto"; | ||
import "osmosis/cosmwasmpool/v1beta1/tx.proto"; | ||
|
||
import "cosmos/base/v1beta1/coin.proto"; | ||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "google/api/annotations.proto"; | ||
import "google/protobuf/any.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/client/queryproto"; | ||
|
||
service Query { | ||
rpc Params(ParamsRequest) returns (ParamsResponse) { | ||
option (google.api.http).get = "/osmosis/cosmwasmpool/v1beta1/Params"; | ||
} | ||
} | ||
|
||
//=============================== Params | ||
message ParamsRequest {} | ||
message ParamsResponse { Params params = 1 [ (gogoproto.nullable) = false ]; } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
keeper: | ||
path: "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool" | ||
struct: "Keeper" | ||
client_path: "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/client" | ||
queries: | ||
Params: | ||
proto_wrapper: | ||
query_func: "k.GetParams" | ||
cli: | ||
cmd: "GetParams" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
syntax = "proto3"; | ||
package osmosis.cosmwasmpool.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/types"; | ||
|
||
service Msg {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to reviewer revisit having messages is tracked in: #4765 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,8 @@ service Query { | |
rpc EstimateSinglePoolSwapExactAmountIn( | ||
EstimateSinglePoolSwapExactAmountInRequest) | ||
returns (EstimateSwapExactAmountInResponse) { | ||
option (google.api.http).get = | ||
"/osmosis/poolmanager/v1beta1/{pool_id}/estimate/single_pool_swap_exact_amount_in"; | ||
option (google.api.http).get = "/osmosis/poolmanager/v1beta1/{pool_id}/" | ||
"estimate/single_pool_swap_exact_amount_in"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be one line. The linter splits it, but apparently protobufs don't support that. ref #4549 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this confirmed? Would be really odd if the linter did something that wasn't proto compatible... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also not convinced this is a problem. I searched the repo and there are multiple places where this is happening. If this is indeed an issue, we should investigate fixing the linter IMO as it is almost guaranteed it will get missed in one of the PRs Going to follow-up on Slack There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, not sure. Just going off what Matt said. @mattverse have you confirmed that stuff breaks here? what breaks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I have manually tested, I have came to a conclusion that these multiple liners are not correctly supported when they are getting converted to rest endpoints. On the second look, it might have been just me having effect by other testing variants. Worthwhile re-testing, cannot assure that its 100% not supported |
||
} | ||
|
||
// Estimates swap amount in given out. | ||
|
@@ -45,7 +45,8 @@ service Query { | |
EstimateSinglePoolSwapExactAmountOutRequest) | ||
returns (EstimateSwapExactAmountOutResponse) { | ||
option (google.api.http).get = | ||
"/osmosis/poolmanager/v1beta1/{pool_id}/estimate_out/single_pool_swap_exact_amount_out"; | ||
"/osmosis/poolmanager/v1beta1/{pool_id}/estimate_out/" | ||
p0mvn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"single_pool_swap_exact_amount_out"; | ||
} | ||
|
||
// Returns the total number of pools existing in Osmosis. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package grpc | ||
|
||
// THIS FILE IS GENERATED CODE, DO NOT EDIT | ||
// SOURCE AT `proto/osmosis/cosmwasmpool/v1beta1/query.yml` | ||
|
||
import ( | ||
context "context" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/client" | ||
"github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/client/queryproto" | ||
) | ||
|
||
type Querier struct { | ||
Q client.Querier | ||
} | ||
|
||
var _ queryproto.QueryServer = Querier{} | ||
|
||
func (q Querier) Params(grpcCtx context.Context, | ||
req *queryproto.ParamsRequest, | ||
) (*queryproto.ParamsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "empty request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(grpcCtx) | ||
return q.Q.Params(ctx, *req) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package client | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool" | ||
"github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/client/queryproto" | ||
) | ||
|
||
// This file should evolve to being code gen'd, off of `proto/poolmanager/v1beta/query.yml` | ||
|
||
type Querier struct { | ||
K cosmwasmpool.Keeper | ||
} | ||
|
||
func NewQuerier(k cosmwasmpool.Keeper) Querier { | ||
return Querier{k} | ||
} | ||
|
||
func (q Querier) Params(ctx sdk.Context, | ||
req queryproto.ParamsRequest, | ||
) (*queryproto.ParamsResponse, error) { | ||
params := q.K.GetParams(ctx) | ||
return &queryproto.ParamsResponse{Params: params}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to store the code_id? It can be retrieved from the ContractInfo (using the addr) once the contract is instantiated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't storing it here prevent one more query in the required path though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does.
Also, I think we might want to store the code id for security purposes so that it is impossible to upgrade the contract to something malicious.
We can allow this to be upgradeable via gov prop. WDYT?
Going to make an issue to track this discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking discussion here: #4779
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only when the code id is being used, which is only on instantiation (AFAICT). Not sure when else we would need the code id.
We can make the contract non-upgradable by giving it no admin.
Also if we wanted to enforce this by checking the code id, we would need to query the ContractInfo on every call to see that it matches what is stored.