Skip to content

Commit

Permalink
refactor(iro): update usage of preLaunchTime (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Oct 7, 2024
1 parent d3c31fd commit dec340f
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 163 deletions.
7 changes: 4 additions & 3 deletions proto/dymensionxyz/dymension/iro/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "dymensionxyz/dymension/iro/iro.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";

Expand Down Expand Up @@ -64,9 +65,9 @@ message MsgCreatePlan {
google.protobuf.Timestamp start_time = 5
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];

// The time before which the rollapp cannot be started.
google.protobuf.Timestamp pre_launch_time = 6
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
// The duration of the plan.
google.protobuf.Duration iro_plan_duration = 6
[ (gogoproto.stdduration) = true, (gogoproto.nullable) = false ];

// The incentive plan parameters for the tokens left after the plan is settled.
IncentivePlanParams incentive_plan_params = 7 [ (gogoproto.nullable) = false ];
Expand Down
3 changes: 1 addition & 2 deletions proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ message Rollapp {
// pre_launch_time is the timestamp indicating the time before which the
// rollapp cannot be started.
// Set when creating IRO plan for the rollapp
google.protobuf.Timestamp pre_launch_time = 16
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
google.protobuf.Timestamp pre_launch_time = 16 [ (gogoproto.stdtime) = true];
// LivenessEventHeight is the height of an upcoming liveness event (slash or
// jail) 0 means not set
int64 liveness_event_height = 17;
Expand Down
29 changes: 12 additions & 17 deletions x/iro/cli/tx_create_iro.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (

func CmdCreateIRO() *cobra.Command {
cmd := &cobra.Command{
Use: "create-iro [rollapp-id] [allocation] [pre-launch-time]",
Use: "create-iro [rollapp-id] [allocation] [duration]",
Short: "Create a new Initial RollApp Offering (IRO) plan",
Long: `Create a new Initial RollApp Offering (IRO) plan for a specific RollApp.
Parameters:
[rollapp-id] : The unique identifier of the RollApp for which the IRO is being created.
[allocation] : The total amount of tokens to be allocated for the IRO.
[pre-launch-time] : The time before which the IRO cannot be launched. Can be in Unix timestamp or RFC3339 format.
[rollapp-id] : The unique identifier of the RollApp for which the IRO is being created.
[allocation] : The total amount of tokens to be allocated for the IRO.
[duration] : The duration of the IRO plan in seconds.
Required Flags:
--curve : The bonding curve parameters in the format "M,N,C" where the curve is defined as p(x) = M * x^N + C.
Expand All @@ -37,29 +37,24 @@ Optional Flags:
--incentives-epochs: The number of epochs over which incentives will be distributed. (1 minute epoch)
Examples:
dymd tx iro create-iro myrollapp1 1000000000 1630000000 --curve "1.2,0.4,0" --from mykey
dymd tx iro create-iro myrollapp2 500000000 "2023-09-15T14:00:00Z" --curve "1.5,0.5,100" --start-time "2023-10-01T00:00:00Z" --incentives-start 24h --incentives-epochs 3000 --from mykey
dymd tx iro create-iro myrollapp1 1000000000 24h --curve "1.2,0.4,0" --from mykey
dymd tx iro create-iro myrollapp2 500000000 30m --curve "1.5,0.5,100" --start-time "2023-10-01T00:00:00Z" --incentives-start 24h --incentives-epochs 3000 --from mykey
`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argRollappId := args[0]
argAllocation := args[1]
argPreLaunchTimeStr := args[2]
argDurationStr := args[2]

allocationAmt, ok := math.NewIntFromString(argAllocation)
if !ok {
return fmt.Errorf("invalid allocation amount: %s", argAllocation)
}

var preLaunchTime time.Time
if argPreLaunchTimeStr == "" {
return errors.New("pre-launch time cannot be empty")
} else if timeUnix, err := strconv.ParseInt(argPreLaunchTimeStr, 10, 64); err == nil { // unix time
preLaunchTime = time.Unix(timeUnix, 0)
} else if timeRFC, err := time.Parse(time.RFC3339, argPreLaunchTimeStr); err == nil { // RFC time
preLaunchTime = timeRFC
} else { // invalid input
return errors.New("invalid start time format")
// Parse the string into a time.Duration
planDuration, err := time.ParseDuration(argDurationStr)
if err != nil {
return err
}

// Parse curve flag
Expand Down Expand Up @@ -109,7 +104,7 @@ Examples:
AllocatedAmount: allocationAmt,
BondingCurve: curve,
StartTime: startTime,
PreLaunchTime: preLaunchTime,
IroPlanDuration: planDuration,
IncentivePlanParams: types.IncentivePlanParams{
StartTimeAfterSettlement: incentivesStart,
NumEpochsPaidOver: incentivesEpochs,
Expand Down
5 changes: 3 additions & 2 deletions x/iro/keeper/create_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ func (m msgServer) CreatePlan(goCtx context.Context, req *types.MsgCreatePlan) (
startTime = ctx.BlockTime()
}
// check minimal duration
if startTime.Add(m.Keeper.GetParams(ctx).MinPlanDuration).After(req.PreLaunchTime) {
if req.IroPlanDuration < m.Keeper.GetParams(ctx).MinPlanDuration {
return nil, errors.Join(gerrc.ErrFailedPrecondition, types.ErrInvalidEndTime)
}
preLaunchTime := startTime.Add(req.IroPlanDuration)

// validate incentive plan params
params := m.Keeper.GetParams(ctx)
Expand All @@ -64,7 +65,7 @@ func (m msgServer) CreatePlan(goCtx context.Context, req *types.MsgCreatePlan) (
return nil, errors.Join(gerrc.ErrFailedPrecondition, types.ErrPlanExists)
}

planId, err := m.Keeper.CreatePlan(ctx, req.AllocatedAmount, startTime, req.PreLaunchTime, rollapp, req.BondingCurve, req.IncentivePlanParams)
planId, err := m.Keeper.CreatePlan(ctx, req.AllocatedAmount, startTime, preLaunchTime, rollapp, req.BondingCurve, req.IncentivePlanParams)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion x/iro/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"errors"

"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -38,7 +39,7 @@ func (m *MsgCreatePlan) ValidateBasic() error {
return ErrInvalidAllocation
}

if m.PreLaunchTime.Before(m.StartTime) {
if m.IroPlanDuration < 0 {
return ErrInvalidEndTime
}

Expand Down
2 changes: 1 addition & 1 deletion x/iro/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var (
DefaultTakerFee = "0.02" // 2%
DefaultCreationFee = math.NewInt(10).MulRaw(1e18) /* 10 DYM */
DefaultMinPlanDuration = 7 * 24 * time.Hour // 7 days
DefaultMinPlanDuration = 0 * time.Hour // no enforced minimum by default
DefaultIncentivePlanMinimumNumEpochsPaidOver = uint64(10_080) // default: min 7 days (based on 1 minute distribution epoch)
DefaultIncentivePlanMinimumStartTimeAfterSettlement = 60 * time.Minute // default: min 1 hour after settlement
)
Expand Down
Loading

0 comments on commit dec340f

Please sign in to comment.