From 20946be7f309cf99736e241ceebb142642475e46 Mon Sep 17 00:00:00 2001 From: Myles <96409608+ice-myles@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:36:32 +0300 Subject: [PATCH] Bonus value and max referrals are made to be configurable. (#78) Bonus value and max referrals are made to be configurable. --- application.yaml | 2 ++ notifications/.testdata/application.yaml | 2 ++ notifications/contract.go | 4 +++- notifications/notification_type_new_referral.go | 10 +++++----- notifications/telegram_notifications.go | 5 ++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/application.yaml b/application.yaml index e0b1f69..507614a 100644 --- a/application.yaml +++ b/application.yaml @@ -72,6 +72,8 @@ news: &news urlUpload: https://storage.bunnycdn.com/ice-staging/news urlDownload: https://ice-staging.b-cdn.net/news notifications: ¬ifications + welcomeBonusV2Amount: 500 + maxReferralsCount: 200 defaultReferralName: sunwaves deeplinkScheme: staging.ice.app pingCooldown: 1m diff --git a/notifications/.testdata/application.yaml b/notifications/.testdata/application.yaml index d2d9e71..918ac6e 100644 --- a/notifications/.testdata/application.yaml +++ b/notifications/.testdata/application.yaml @@ -5,6 +5,8 @@ logger: encoder: console level: info notifications: ¬ifications + welcomeBonusV2Amount: 500 + maxReferralsCount: 200 tenantName: BogusName deeplinkScheme: staging.ice.app pingCooldown: 1m diff --git a/notifications/contract.go b/notifications/contract.go index 2cddcfb..24ab2bc 100644 --- a/notifications/contract.go +++ b/notifications/contract.go @@ -405,6 +405,8 @@ type ( Hour int `yaml:"hour"` Minutes int `yaml:"minutes"` } `yaml:"weeklyStats"` - Development bool `yaml:"development"` + MaxReferralsCount int64 `yaml:"maxReferralsCount" mapstructure:"maxReferralsCount"` + WelcomeBonusV2Amount float64 `yaml:"welcomeBonusV2Amount" mapstructure:"welcomeBonusV2Amount"` + Development bool `yaml:"development"` } ) diff --git a/notifications/notification_type_new_referral.go b/notifications/notification_type_new_referral.go index bb3f144..d3bc550 100644 --- a/notifications/notification_type_new_referral.go +++ b/notifications/notification_type_new_referral.go @@ -191,7 +191,7 @@ func (r *repository) getNewReferralCoinAmount(ctx context.Context, referredBy st if err != nil { log.Error(errors.Wrapf(err, "failed to tokenomics.GetInternalID for referredBy: %v", referredBy)) - return uint64(tokenomics.WelcomeBonusV2Amount) + return uint64(r.cfg.WelcomeBonusV2Amount) } state, err := storagev3.Get[struct { model.UserIDField @@ -204,14 +204,14 @@ func (r *repository) getNewReferralCoinAmount(ctx context.Context, referredBy st } log.Error(errors.Wrapf(err, "failed to get PreStakingBonus for freezerInternalID:%v referredBy:%v", freezerInternalID, referredBy)) - return uint64(tokenomics.WelcomeBonusV2Amount) + return uint64(r.cfg.WelcomeBonusV2Amount) } - if state[0].BalanceT1WelcomeBonusPending >= 200*tokenomics.WelcomeBonusV2Amount { + if state[0].BalanceT1WelcomeBonusPending >= float64(r.cfg.MaxReferralsCount)*r.cfg.WelcomeBonusV2Amount { return 0 } if state[0].PreStakingBonus == 0 { - return uint64(tokenomics.WelcomeBonusV2Amount) + return uint64(r.cfg.WelcomeBonusV2Amount) } - return uint64((state[0].PreStakingBonus + 100.0) * tokenomics.WelcomeBonusV2Amount / 100.0) //nolint:gomnd,mnd // Nope. + return uint64((state[0].PreStakingBonus + 100.0) * r.cfg.WelcomeBonusV2Amount / 100.0) //nolint:gomnd,mnd // Nope. } diff --git a/notifications/telegram_notifications.go b/notifications/telegram_notifications.go index 303e452..065d9f1 100644 --- a/notifications/telegram_notifications.go +++ b/notifications/telegram_notifications.go @@ -18,7 +18,6 @@ import ( "github.com/pkg/errors" "github.com/ice-blockchain/eskimo/users" - "github.com/ice-blockchain/freezer/tokenomics" "github.com/ice-blockchain/wintr/log" "github.com/ice-blockchain/wintr/notifications/telegram" "github.com/ice-blockchain/wintr/time" @@ -271,12 +270,12 @@ func (r *repository) handleTelegramUpdates( } if upd.Message.From.Username == "" && upd.Message.Text == string(StartTelegramCommand) { body = tmpl.getAltBody(users.JSON{ - "WelcomeBonus": tokenomics.WelcomeBonusV2Amount, + "WelcomeBonus": r.cfg.WelcomeBonusV2Amount, }) } else { body = tmpl.getBody(users.JSON{ "Username": upd.Message.From.Username, - "WelcomeBonus": tokenomics.WelcomeBonusV2Amount, + "WelcomeBonus": r.cfg.WelcomeBonusV2Amount, }) } id := strconv.FormatInt(upd.Message.From.ID, 10)