Skip to content

Commit

Permalink
fix(x/airdrop/keeper): hoist out sdk.Dec from constant strings (quick…
Browse files Browse the repository at this point in the history
…silver-zone#1677)

There is no need to unnecessarily recompute and recreate
sdk.Dec values from the tier* constant values.

Fixes quicksilver-zone#1676
  • Loading branch information
odeke-em authored Jun 28, 2024
1 parent 30b6d33 commit 5fd3a24
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions x/airdrop/keeper/claim_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ var (
tier5 = "0.30"
)

var (
decTier1 = sdk.MustNewDecFromStr(tier1)
decTier2 = sdk.MustNewDecFromStr(tier2)
decTier3 = sdk.MustNewDecFromStr(tier3)
decTier4 = sdk.MustNewDecFromStr(tier4)
decTier5 = sdk.MustNewDecFromStr(tier5)
)

func (k *Keeper) HandleClaim(ctx sdk.Context, cr types.ClaimRecord, action types.Action, proofs []*cmtypes.Proof) (uint64, error) {
// action already completed, nothing to claim
if _, exists := cr.ActionsCompleted[int32(action)]; exists {
Expand All @@ -34,15 +42,15 @@ func (k *Keeper) HandleClaim(ctx sdk.Context, cr types.ClaimRecord, action types
case types.ActionInitialClaim:
return k.handleInitial(ctx, &cr, action)
case types.ActionDepositT1:
return k.handleDeposit(ctx, &cr, action, sdk.MustNewDecFromStr(tier1))
return k.handleDeposit(ctx, &cr, action, decTier1)
case types.ActionDepositT2:
return k.handleDeposit(ctx, &cr, action, sdk.MustNewDecFromStr(tier2))
return k.handleDeposit(ctx, &cr, action, decTier2)
case types.ActionDepositT3:
return k.handleDeposit(ctx, &cr, action, sdk.MustNewDecFromStr(tier3))
return k.handleDeposit(ctx, &cr, action, decTier3)
case types.ActionDepositT4:
return k.handleDeposit(ctx, &cr, action, sdk.MustNewDecFromStr(tier4))
return k.handleDeposit(ctx, &cr, action, decTier4)
case types.ActionDepositT5:
return k.handleDeposit(ctx, &cr, action, sdk.MustNewDecFromStr(tier5))
return k.handleDeposit(ctx, &cr, action, decTier5)
case types.ActionStakeQCK:
return k.handleBondedDelegation(ctx, &cr, action)
case types.ActionSignalIntent:
Expand Down Expand Up @@ -284,7 +292,7 @@ func (k *Keeper) verifyOsmosisLP(ctx sdk.Context, proofs []*cmtypes.Proof, cr ty
}

// calculate target amount
dThreshold := sdk.MustNewDecFromStr(tier4)
dThreshold := decTier4
if err := k.verifyDeposit(ctx, cr, dThreshold); err != nil {
return fmt.Errorf("%w, must reach at least %s of %d", err, tier4, cr.BaseValue)
}
Expand Down

0 comments on commit 5fd3a24

Please sign in to comment.