Skip to content

Commit

Permalink
feat(iro): add tradable only filter to IRO plans (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Oct 30, 2024
1 parent 43db5fd commit 632c277
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 63 deletions.
5 changes: 4 additions & 1 deletion proto/dymensionxyz/dymension/iro/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ message QueryParamsResponse {
}

// QueryPlanRequest is the request type for the Query/QueryPlan RPC method.
message QueryPlansRequest {}
message QueryPlansRequest {
// tradable_only is an optional flag to filter out plans that have not started yet, and that are not settled.
bool tradable_only = 1;
}

// QueryPlanResponse is the response type for the Query/QueryPlan RPC method.
message QueryPlansResponse {
Expand Down
1 change: 1 addition & 0 deletions x/iro/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
FlagBondingCurve = "curve"
FlagIncentivesStartDurationAfterSettlement = "incentives-start"
FlagIncentivesEpochs = "incentives-epochs"
FlagTradableOnly = "tradable-only"
)

var (
Expand Down
10 changes: 9 additions & 1 deletion x/iro/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ func CmdQueryPlans() *cobra.Command {
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.QueryPlans(cmd.Context(), &types.QueryPlansRequest{})
tradableOnly, err := cmd.Flags().GetBool(FlagTradableOnly)
if err != nil {
return err
}

res, err := queryClient.QueryPlans(cmd.Context(), &types.QueryPlansRequest{
TradableOnly: tradableOnly,
})
if err != nil {
return err
}
Expand All @@ -56,6 +63,7 @@ func CmdQueryPlans() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
cmd.Flags().BoolP(FlagTradableOnly, "t", false, "Query only tradable plans")
return cmd
}

Expand Down
2 changes: 1 addition & 1 deletion x/iro/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.GenesisState{}
genesis.Params = k.GetParams(ctx)
genesis.Plans = append(genesis.Plans, k.GetAllPlans(ctx)...)
genesis.Plans = append(genesis.Plans, k.GetAllPlans(ctx, false)...)

return &genesis
}
2 changes: 1 addition & 1 deletion x/iro/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGenesis(t *testing.T) {
iro.InitGenesis(ctx, *k, genesisState)

// assertions
require.Len(t, k.GetAllPlans(ctx), 2)
require.Len(t, k.GetAllPlans(ctx, false), 2)
_, found := k.GetPlanByRollapp(ctx, "rollapp1")
require.True(t, found)
lastPlanId := k.GetLastPlanId(ctx)
Expand Down
2 changes: 1 addition & 1 deletion x/iro/keeper/create_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *KeeperTestSuite) TestCreatePlan() {
s.Require().Equal(planId2, fmt.Sprintf("%d", plan.Id))

// test get all plans
plans := k.GetAllPlans(s.Ctx)
plans := k.GetAllPlans(s.Ctx, false)
s.Require().Len(plans, 2)

ok := s.App.AccountKeeper.HasAccount(s.Ctx, plan.GetAddress())
Expand Down
5 changes: 4 additions & 1 deletion x/iro/keeper/iro.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (k Keeper) MustGetPlanByRollapp(ctx sdk.Context, rollappId string) types.Pl
}

// GetAllPlans returns all plans
func (k Keeper) GetAllPlans(ctx sdk.Context) (list []types.Plan) {
func (k Keeper) GetAllPlans(ctx sdk.Context, tradableOnly bool) (list []types.Plan) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PlanKeyPrefix)
iterator := sdk.KVStorePrefixIterator(store, []byte{})

Expand All @@ -74,6 +74,9 @@ func (k Keeper) GetAllPlans(ctx sdk.Context) (list []types.Plan) {
for ; iterator.Valid(); iterator.Next() {
var val types.Plan
k.cdc.MustUnmarshal(iterator.Value(), &val)
if tradableOnly && !val.IsSettled() && !val.StartTime.After(ctx.BlockTime()) {
continue
}
list = append(list, val)
}

Expand Down
2 changes: 1 addition & 1 deletion x/iro/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (k Keeper) QueryPlans(goCtx context.Context, req *types.QueryPlansRequest)
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.QueryPlansResponse{Plans: k.GetAllPlans(ctx)}, nil
return &types.QueryPlansResponse{Plans: k.GetAllPlans(ctx, req.TradableOnly)}, nil
}

// QuerySpotPrice implements types.QueryServer.
Expand Down
155 changes: 99 additions & 56 deletions x/iro/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions x/iro/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 632c277

Please sign in to comment.