Skip to content

Commit

Permalink
Add NextLockId Query for lockup module (#4490) (#4493)
Browse files Browse the repository at this point in the history
* Add next-lock-id query

* Update x/lockup/client/cli/query.go

* Fix ICQ test vector

---------

Co-authored-by: Dev Ojha <dojha@berkeley.edu>
(cherry picked from commit 4f99d4f)

Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com>
  • Loading branch information
mergify[bot] and mattverse authored Mar 3, 2023
1 parent 3cbbb3f commit 7a0f7ee
Show file tree
Hide file tree
Showing 9 changed files with 545 additions and 110 deletions.
2 changes: 1 addition & 1 deletion app/upgrades/v15/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (suite *UpgradeTestSuite) TestSetICQParams() {
v15.SetICQParams(suite.Ctx, suite.App.ICQKeeper)

suite.Require().True(suite.App.ICQKeeper.IsHostEnabled(suite.Ctx))
suite.Require().Len(suite.App.ICQKeeper.GetAllowQueries(suite.Ctx), 63)
suite.Require().Len(suite.App.ICQKeeper.GetAllowQueries(suite.Ctx), 64)
}

func (suite *UpgradeTestSuite) TestSetRateLimits() {
Expand Down
8 changes: 8 additions & 0 deletions proto/osmosis/lockup/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ service Query {
"/osmosis/lockup/v1beta1/locked_by_id/{lock_id}";
}

// Returns next lock ID
rpc NextLockID(NextLockIDRequest) returns (NextLockIDResponse) {
option (google.api.http).get = "/osmosis/lockup/v1beta1/next_lock_id";
}

// Returns synthetic lockups by native lockup id
rpc SyntheticLockupsByLockupID(SyntheticLockupsByLockupIDRequest)
returns (SyntheticLockupsByLockupIDResponse) {
Expand Down Expand Up @@ -239,6 +244,9 @@ message LockedDenomResponse {
message LockedRequest { uint64 lock_id = 1; };
message LockedResponse { PeriodLock lock = 1; };

message NextLockIDRequest {};
message NextLockIDResponse { uint64 lock_id = 1; };

message SyntheticLockupsByLockupIDRequest { uint64 lock_id = 1; }
message SyntheticLockupsByLockupIDResponse {
repeated SyntheticLock synthetic_locks = 1 [ (gogoproto.nullable) = false ];
Expand Down
6 changes: 4 additions & 2 deletions proto/osmosis/protorev/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ message QueryGetProtoRevPoolWeightsRequest {}
// Query/GetProtoRevPoolWeights RPC method.
message QueryGetProtoRevPoolWeightsResponse {
// pool_weights is a list of all of the pool weights
PoolWeights pool_weights = 1
[ (gogoproto.moretags) = "yaml:\"pool_weights\"", (gogoproto.nullable) = false ];
PoolWeights pool_weights = 1 [
(gogoproto.moretags) = "yaml:\"pool_weights\"",
(gogoproto.nullable) = false
];
}

// QueryGetProtoRevMaxPoolPointsPerBlockRequest is request type for the
Expand Down
1 change: 1 addition & 0 deletions wasmbinding/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func init() {
setWhitelistedQuery("/osmosis.lockup.Query/AccountUnlockingCoins", &lockuptypes.AccountUnlockingCoinsResponse{})
setWhitelistedQuery("/osmosis.lockup.Query/LockedDenom", &lockuptypes.LockedDenomResponse{})
setWhitelistedQuery("/osmosis.lockup.Query/LockedByID", &lockuptypes.LockedResponse{})
setWhitelistedQuery("/osmosis.lockup.Query/NextLockID", &lockuptypes.NextLockIDResponse{})

// mint
setWhitelistedQuery("/osmosis.mint.v1beta1.Query/EpochProvisions", &minttypes.QueryEpochProvisionsResponse{})
Expand Down
9 changes: 9 additions & 0 deletions x/lockup/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdOutputLocksJson(),
GetCmdSyntheticLockupsByLockupID(),
GetCmdAccountLockedDuration(),
GetCmdNextLockID(),
osmocli.GetParams[*types.QueryParamsRequest](
types.ModuleName, types.NewQueryClient),
)
Expand Down Expand Up @@ -185,6 +186,14 @@ func GetCmdLockedByID() *cobra.Command {
return osmocli.BuildQueryCli[*types.LockedRequest](&q, types.NewQueryClient)
}

// GetCmdNextLockID returns next lock id to be created.
func GetCmdNextLockID() *cobra.Command {
return osmocli.SimpleQueryCmd[*types.NextLockIDRequest](
"next-lock-id",
"Query next lock id to be created",
`{{.Short}}`, types.ModuleName, types.NewQueryClient)
}

// GetCmdSyntheticLockupsByLockupID returns synthetic lockups by lockup id.
func GetCmdSyntheticLockupsByLockupID() *cobra.Command {
return osmocli.SimpleQueryCmd[*types.SyntheticLockupsByLockupIDRequest](
Expand Down
13 changes: 13 additions & 0 deletions x/lockup/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ func (q Querier) LockedByID(goCtx context.Context, req *types.LockedRequest) (*t
return &types.LockedResponse{Lock: lock}, err
}

// NextLockID returns next lock ID to be created.
func (q Querier) NextLockID(goCtx context.Context, req *types.NextLockIDRequest) (*types.NextLockIDResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
lastLockID := q.Keeper.GetLastLockID(ctx)
nextLockID := lastLockID + 1

return &types.NextLockIDResponse{LockId: nextLockID}, nil
}

// SyntheticLockupsByLockupID returns synthetic lockups by native lockup id.
func (q Querier) SyntheticLockupsByLockupID(goCtx context.Context, req *types.SyntheticLockupsByLockupIDRequest) (*types.SyntheticLockupsByLockupIDResponse, error) {
if req == nil {
Expand Down
23 changes: 23 additions & 0 deletions x/lockup/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,29 @@ func (suite *KeeperTestSuite) TestLockedByID() {
suite.Require().Equal(res.Lock.IsUnlocking(), false)
}

func (suite *KeeperTestSuite) TestNextLockID() {
suite.SetupTest()
addr1 := sdk.AccAddress([]byte("addr1---------------"))

// lock coins
coins := sdk.Coins{sdk.NewInt64Coin("stake", 10)}
suite.LockTokens(addr1, coins, time.Second)

// lock by available available id check
res, err := suite.querier.NextLockID(sdk.WrapSDKContext(suite.Ctx), &types.NextLockIDRequest{})
suite.Require().NoError(err)
suite.Require().Equal(res.LockId, uint64(2))

// create 2 more locks
coins = sdk.Coins{sdk.NewInt64Coin("stake", 10)}
suite.LockTokens(addr1, coins, time.Second)
coins = sdk.Coins{sdk.NewInt64Coin("stake", 10)}
suite.LockTokens(addr1, coins, time.Second)
res, err = suite.querier.NextLockID(sdk.WrapSDKContext(suite.Ctx), &types.NextLockIDRequest{})
suite.Require().NoError(err)
suite.Require().Equal(res.LockId, uint64(4))
}

func (suite *KeeperTestSuite) TestAccountLockedLongerDuration() {
suite.SetupTest()
addr1 := sdk.AccAddress([]byte("addr1---------------"))
Expand Down
Loading

0 comments on commit 7a0f7ee

Please sign in to comment.