Skip to content

Commit

Permalink
updated the logic for comparing the max mining boost level MaxT1Refer…
Browse files Browse the repository at this point in the history
…rals from a hardcoded 25 value to a config based one
  • Loading branch information
ice-ares committed Aug 1, 2024
1 parent ffc62d2 commit e695409
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions miner/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser *
}

baseMiningRate := updatedUser.baseMiningRate(now)
maxT1Referrals := (*cfg.miningBoostLevels.Load())[len(*cfg.miningBoostLevels.Load())-1].MaxT1Referrals
if updatedUser.MiningSessionSoloEndedAt.After(*now.Time) {
if !updatedUser.ExtraBonusStartedAt.IsNil() && now.Before(updatedUser.ExtraBonusStartedAt.Add(cfg.ExtraBonuses.Duration)) {
rate := (100 + float64(updatedUser.ExtraBonus)) * baseMiningRate * elapsedTimeFraction / 100.
Expand Down Expand Up @@ -158,7 +159,7 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser *
}
activeT1Referrals := int32(0)
if updatedUser.MiningBoostLevelIndex != nil {
if updatedUser.IsVerified() && updatedUser.VerifiedT1Referrals >= 25 {
if updatedUser.IsVerified() && updatedUser.VerifiedT1Referrals >= maxT1Referrals {
activeT1Referrals = int32((*cfg.miningBoostLevels.Load())[int(*updatedUser.MiningBoostLevelIndex)].MaxT1Referrals)
} else {
activeT1Referrals = int32(math.Min(float64((*cfg.miningBoostLevels.Load())[int(*updatedUser.MiningBoostLevelIndex)].MaxT1Referrals), float64(updatedUser.ActiveT1Referrals)))
Expand Down Expand Up @@ -198,13 +199,13 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser *
}
}

if updatedUser.BalanceT1WelcomeBonusPendingApplied < 25*tokenomics.WelcomeBonusV2Amount {
if updatedUser.BalanceT1WelcomeBonusPendingApplied < float64(maxT1Referrals)*tokenomics.WelcomeBonusV2Amount {
if unAppliedT1WelcomeBonusPending := updatedUser.BalanceT1WelcomeBonusPending - updatedUser.BalanceT1WelcomeBonusPendingApplied; unAppliedT1WelcomeBonusPending == 0 {
updatedUser.BalanceT1WelcomeBonusPending = 0
updatedUser.BalanceT1WelcomeBonusPendingApplied = 0
} else {
unAppliedT1Pending += min(unAppliedT1WelcomeBonusPending, 25*tokenomics.WelcomeBonusV2Amount-updatedUser.BalanceT1WelcomeBonusPendingApplied)
updatedUser.BalanceT1WelcomeBonusPendingApplied = min(updatedUser.BalanceT1WelcomeBonusPending, 25*tokenomics.WelcomeBonusV2Amount)
unAppliedT1Pending += min(unAppliedT1WelcomeBonusPending, float64(maxT1Referrals)*tokenomics.WelcomeBonusV2Amount-updatedUser.BalanceT1WelcomeBonusPendingApplied)
updatedUser.BalanceT1WelcomeBonusPendingApplied = min(updatedUser.BalanceT1WelcomeBonusPending, float64(maxT1Referrals)*tokenomics.WelcomeBonusV2Amount)
}
} else {
updatedUser.BalanceT1WelcomeBonusPending = 0
Expand Down
2 changes: 1 addition & 1 deletion tokenomics/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ type (
MiningBoostLevel struct {
ICEPrice string `json:"icePrice" example:"1234.1234" mapstructure:"-"`
icePrice float64 `json:"-" example:"1234.1234" mapstructure:"-"`
MaxT1Referrals uint64 `json:"maxT1Referrals" example:"5" mapstructure:"maxT1Referrals"`
MiningSessionLengthSeconds uint32 `json:"miningSessionLengthSeconds" example:"86400" mapstructure:"miningSessionLengthSeconds"`
MiningRateBonus uint16 `json:"miningRateBonus" example:"100" mapstructure:"miningRateBonus"`
MaxT1Referrals uint8 `json:"maxT1Referrals" example:"5" mapstructure:"maxT1Referrals"`
SlashingDisabled bool `json:"slashingDisabled" example:"false" mapstructure:"slashingDisabled"`
}
MiningBoostSummary struct {
Expand Down
2 changes: 1 addition & 1 deletion tokenomics/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (r *repository) GetMiningSummary(ctx context.Context, userID string) (*Mini
maxMiningSessionDuration := r.cfg.maxMiningSessionDuration(ms[0].MiningBoostLevelIndexField)
activeT1Referrals := int32(0)
if ms[0].MiningBoostLevelIndex != nil {
if ms[0].IsVerified() && ms[0].VerifiedT1Referrals >= 25 {
if ms[0].IsVerified() && ms[0].VerifiedT1Referrals >= (*r.cfg.MiningBoost.levels.Load())[len(*r.cfg.MiningBoost.levels.Load())-1].MaxT1Referrals {
activeT1Referrals = int32((*r.cfg.MiningBoost.levels.Load())[int(*ms[0].MiningBoostLevelIndex)].MaxT1Referrals)
} else {
activeT1Referrals = int32(math.Min(float64((*r.cfg.MiningBoost.levels.Load())[int(*ms[0].MiningBoostLevelIndex)].MaxT1Referrals), float64(ms[0].ActiveT1Referrals)))
Expand Down

0 comments on commit e695409

Please sign in to comment.