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

feat: fix update public plan proposal & disable codecov patch #133

Merged
65 changes: 44 additions & 21 deletions x/farming/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP
if err := types.ValidateName(plans); err != nil {
return err
}

if err := types.ValidateTotalEpochRatio(plans); err != nil {
return err
}
Expand All @@ -45,12 +46,13 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq
if err != nil {
return err
}

terminationAcc, err := sdk.AccAddressFromBech32(p.GetTerminationAddress())
if err != nil {
return err
}

if !p.EpochAmount.IsZero() && !p.EpochAmount.IsAnyNegative() {
if p.EpochAmount.IsAllPositive() {
msg := types.NewMsgCreateFixedAmountPlan(
p.GetName(),
farmingPoolAddrAcc,
Expand All @@ -68,7 +70,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq
logger := k.Logger(ctx)
logger.Info("created public fixed amount plan", "fixed_amount_plan", plan)

} else if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNegative() && !p.EpochRatio.IsNil() {
} else if p.EpochRatio.IsPositive() {
msg := types.NewMsgCreateRatioPlan(
p.GetName(),
farmingPoolAddrAcc,
Expand Down Expand Up @@ -103,8 +105,13 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId())
}

switch plan := plan.(type) {
case *types.FixedAmountPlan:
if p.EpochAmount.IsAllPositive() {
jaybxyz marked this conversation as resolved.
Show resolved Hide resolved
if p.GetName() != "" {
if err := plan.SetName(p.GetName()); err != nil {
jaybxyz marked this conversation as resolved.
Show resolved Hide resolved
return err
}
}

if p.GetFarmingPoolAddress() != "" {
farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress())
if err != nil {
Expand Down Expand Up @@ -143,22 +150,32 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd
}
}

if p.GetName() != "" {
plan.Name = p.GetName()
}

if p.GetEpochAmount() != nil {
plan.EpochAmount = p.GetEpochAmount()
// change the plan to fixed amount plan if an epoch amount exists
if p.GetEpochAmount().IsAllPositive() {
jaybxyz marked this conversation as resolved.
Show resolved Hide resolved
basePlan := types.NewBasePlan(
plan.GetId(),
plan.GetName(),
plan.GetType(),
plan.GetFarmingPoolAddress().String(),
plan.GetTerminationAddress().String(),
plan.GetStakingCoinWeights(),
plan.GetStartTime(),
plan.GetEndTime(),
)

plan = types.NewFixedAmountPlan(basePlan, p.GetEpochAmount())
}

k.SetPlan(ctx, plan)

logger := k.Logger(ctx)
logger.Info("updated public fixed amount plan", "fixed_amount_plan", plan)

case *types.RatioPlan:
if err := plan.Validate(); err != nil {
return err
} else if p.EpochRatio.IsPositive() {
if p.GetName() != "" {
if err := plan.SetName(p.GetName()); err != nil {
jaybxyz marked this conversation as resolved.
Show resolved Hide resolved
return err
}
}

if p.GetFarmingPoolAddress() != "" {
Expand Down Expand Up @@ -199,21 +216,27 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd
}
}

if p.GetName() != "" {
plan.Name = p.GetName()
}

if !p.EpochRatio.IsZero() {
plan.EpochRatio = p.EpochRatio
// change the plan to ratio plan if an epoch ratio exists
if p.EpochRatio.IsPositive() {
basePlan := types.NewBasePlan(
plan.GetId(),
plan.GetName(),
plan.GetType(),
plan.GetFarmingPoolAddress().String(),
plan.GetTerminationAddress().String(),
plan.GetStakingCoinWeights(),
plan.GetStartTime(),
plan.GetEndTime(),
)

plan = types.NewRatioPlan(basePlan, p.EpochRatio)
}

k.SetPlan(ctx, plan)

logger := k.Logger(ctx)
logger.Info("updated public ratio plan", "ratio_plan", plan)

default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized plan type: %T", p)
}
}

Expand Down
Loading