Skip to content

Commit

Permalink
feat(t1 referrals sharing):
Browse files Browse the repository at this point in the history
When an user reaches max verified t1 referrals for his specific mining boost level (for now we only allow that for mining boost level 5 -- logic done only by the client apps --), that user will be forced to make a choice between 2 options:
1. Accept
2. Reject -- this means nothing changes for the user; everything would behave exactly like before

If user accepts, 2 things will happen:

1. every new user registered in our app, that inputs that specific user as their referral (via referred_by) will be redirected automatically to a different, random user as their referred_by, that has to verify 3 conditions (has to be verified, has to not have any mining boost level enabled and has to have <3 verified t1 referrals)
2. the user that accepted, will now always have the max t1 referrals of that mining boost level counted as active, even if none of the t1 referrals are mining at all. I.E. for mining boost level 5, max t1 referrals is 25, this means that user will always have +625% (25*25) bonus on their mining rate even if 0 of his 25 verified t1 referrals are mining/active

related eskimo commit: ice-blockchain/eskimo@cc17d4a
  • Loading branch information
ice-ares committed Jul 3, 2024
1 parent 7cc79aa commit 9b5a872
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 23 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ethereum/go-ethereum v1.14.6
github.com/goccy/go-json v0.10.3
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/eskimo v1.351.0
github.com/ice-blockchain/eskimo v1.353.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.143.0
github.com/imroc/req/v3 v3.43.7
Expand Down Expand Up @@ -99,7 +99,7 @@ require (
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/goccy/go-reflect v1.2.0 // indirect
github.com/gofrs/flock v0.11.0 // indirect
github.com/gofrs/flock v0.12.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
Expand Down Expand Up @@ -190,11 +190,11 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
github.com/goccy/go-reflect v1.2.0 h1:O0T8rZCuNmGXewnATuKYnkL0xm6o8UNOJZd/gOkb9ms=
github.com/goccy/go-reflect v1.2.0/go.mod h1:n0oYZn8VcV2CkWTxi8B9QjkCoq6GTtCEdfmR66YhFtE=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/flock v0.11.0 h1:AGFQxrpWd8ezw60AvLWIPbxMydNfF8564pwH3FCty0g=
github.com/gofrs/flock v0.11.0/go.mod h1:FirDy1Ing0mI2+kB6wk+vyyAH+e6xiE+EYA0jnzV9jc=
github.com/gofrs/flock v0.12.0 h1:xHW8t8GPAiGtqz7KxiSqfOEXwpOaqhpYZrTE2MQBgXY=
github.com/gofrs/flock v0.12.0/go.mod h1:FirDy1Ing0mI2+kB6wk+vyyAH+e6xiE+EYA0jnzV9jc=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
Expand Down Expand Up @@ -300,8 +300,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ice-blockchain/eskimo v1.351.0 h1:igc4PZwU0enDBAG+QX5WmSvfM8BZ55mh1cGZc2YHbdY=
github.com/ice-blockchain/eskimo v1.351.0/go.mod h1:ODsZC4RYZQc8dOXW8JzwK9SBzDXxFYEauYpBMiTlBoo=
github.com/ice-blockchain/eskimo v1.353.0 h1:D+4xxO5HLrLMxuPTbIAvdtQqrplyo5UnOJUBNH67I/w=
github.com/ice-blockchain/eskimo v1.353.0/go.mod h1:Zwf7tnSRDPmuO1hBj7mFA5KjDgc0mLNDsq+tudGxwj0=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8=
github.com/ice-blockchain/wintr v1.143.0 h1:KID/M01KN1jl7mlDF+VnIBScR7uT277mJtebYtemSF0=
Expand Down Expand Up @@ -543,18 +543,18 @@ github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 h1:vS1Ao/R55RNV4O7TA2Qopok8yN+X0LIP6RVWLFkprck=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0/go.mod h1:BMsdeOxN04K0L5FNUBfjFdvwWGNe/rkmSwH4Aelu/X0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 h1:9l89oX4ba9kHbBol3Xin3leYJ+252h0zszDtBwyKe2A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0/go.mod h1:XLZfZboOJWHNKUv7eH0inh0E9VV6eWDFB/9yJyTLPp0=
go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg=
go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ=
go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik=
go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 h1:9G6E0TXzGFVfTnawRzrPl83iHOAV7L8NJiR8RSGYV1g=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0/go.mod h1:azvtTADFQJA8mX80jIH/akaE7h+dbm/sVuaHqN13w74=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw=
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down
1 change: 1 addition & 0 deletions miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type (
model.ExtraBonusField
model.ActiveT1ReferralsField
model.ActiveT2ReferralsField
model.T1ReferralsSharingEnabledField
}

UpdatedUser struct { // This is public only because we have to embed it, and it has to be if so.
Expand Down
6 changes: 5 additions & 1 deletion miner/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser *
}
activeT1Referrals := int32(0)
if updatedUser.MiningBoostLevelIndex != nil {
activeT1Referrals = int32(math.Min(float64((*cfg.miningBoostLevels.Load())[int(*updatedUser.MiningBoostLevelIndex)].MaxT1Referrals), float64(updatedUser.ActiveT1Referrals)))
if updatedUser.T1ReferralsSharingEnabled {
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)))
}
}
t1Rate := (25 * float64(activeT1Referrals)) * baseMiningRate * elapsedTimeFraction / 100
t2Rate := (5 * float64(updatedUser.ActiveT2Referrals)) * baseMiningRate * elapsedTimeFraction / 100
Expand Down
3 changes: 3 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ type (
HideRankingField struct {
HideRanking bool `redis:"hide_ranking" json:"-"`
}
T1ReferralsSharingEnabledField struct {
T1ReferralsSharingEnabled bool `json:"t1ReferralsSharingEnabled" redis:"t1_referrals_sharing_enabled"`
}
CreatedAtField struct {
CreatedAt *time.Time `json:"-" redis:"created_at"`
}
Expand Down
1 change: 1 addition & 0 deletions tokenomics/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ type (
UserID *string `json:"userId,omitempty" swaggerignore:"true" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"`
Extension stdlibtime.Duration `json:"extension,omitempty" swaggerignore:"true" example:"24h"`
MiningStreak uint64 `json:"miningStreak,omitempty" swaggerignore:"true" example:"11"`
MiningBoostLevel uint8 `json:"miningBoostLevel,omitempty" swaggerignore:"true" example:"1"`
}
ExtraBonusSummary struct {
UserID string `json:"userId,omitempty" swaggerignore:"true" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"`
Expand Down
1 change: 1 addition & 0 deletions tokenomics/kyc.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ func (r *repository) overrideKYCStateWithEskimoKYCState(ctx context.Context, use
model.KYCState
model.DeserializedUsersKey
model.HideRankingField
model.T1ReferralsSharingEnabledField
KycFaceAvailable bool `json:"kycFaceAvailable" redis:"-"`
}
if err3 := json.Unmarshal(data, &usr); err3 != nil {
Expand Down
7 changes: 6 additions & 1 deletion tokenomics/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (r *repository) GetMiningSummary(ctx context.Context, userID string) (*Mini
model.ExtraBonusDaysClaimNotAvailableResettableField
model.NewsSeenField
model.KYCStepBlockedField
model.T1ReferralsSharingEnabledField
}](ctx, r.db, model.SerializedUsersKey(id))
if err != nil || len(ms) == 0 {
if err == nil {
Expand All @@ -220,7 +221,11 @@ 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 {
activeT1Referrals = int32(math.Min(float64((*r.cfg.MiningBoost.levels.Load())[int(*ms[0].MiningBoostLevelIndex)].MaxT1Referrals), float64(ms[0].ActiveT1Referrals)))
if ms[0].T1ReferralsSharingEnabled {
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)))
}
}

return &MiningSummary{
Expand Down
5 changes: 5 additions & 0 deletions tokenomics/mining_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (r *repository) StartNewMiningSession( //nolint:funlen,gocognit // A lot of

return errors.Wrapf(err, "failed to get miningSummary for id:%v", id)
}
var miningBoostLevel uint8
if old[0].MiningBoostLevelIndex != nil {
miningBoostLevel = uint8(*old[0].MiningBoostLevelIndex) + 1
}
maxMiningSessionDuration := r.cfg.maxMiningSessionDuration(old[0].MiningBoostLevelIndexField)
if !old[0].MiningSessionSoloEndedAt.IsNil() &&
!old[0].MiningSessionSoloLastStartedAt.IsNil() &&
Expand Down Expand Up @@ -126,6 +130,7 @@ func (r *repository) StartNewMiningSession( //nolint:funlen,gocognit // A lot of
UserID: &userID,
ResettableStartingAt: time.New(newMS.MiningSessionSoloLastStartedAt.Add(r.cfg.MiningSessionDuration.Min)),
WarnAboutExpirationStartingAt: time.New(newMS.MiningSessionSoloLastStartedAt.Add(maxMiningSessionDuration - r.cfg.MiningSessionDuration.Max).Add(r.cfg.MiningSessionDuration.WarnAboutExpirationAfter)),
MiningBoostLevel: miningBoostLevel,
}
if err = r.sendMiningSessionMessage(ctx, sess); err != nil {
return errors.Wrapf(err, "failed to sendMiningSessionMessage:%#v", sess)
Expand Down
5 changes: 5 additions & 0 deletions tokenomics/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (s *usersTableSource) replaceUser(ctx context.Context, usr *users.User) err
model.KYCStepPassedField
model.KYCStepBlockedField
model.HideRankingField
model.T1ReferralsSharingEnabledField
}
readOnlyUser struct {
LocalUser
Expand Down Expand Up @@ -218,12 +219,16 @@ func (s *usersTableSource) replaceUser(ctx context.Context, usr *users.User) err
newPartialState.KYCStepsCreatedAt = &val
}
newPartialState.HideRanking = buildHideRanking(usr.HiddenProfileElements)
if usr.T1ReferralsSharingEnabled != nil {
newPartialState.T1ReferralsSharingEnabled = *usr.T1ReferralsSharingEnabled
}
if newPartialState.ProfilePictureName != dbUser[0].ProfilePictureName ||
newPartialState.Username != dbUser[0].Username ||
!strings.EqualFold(newPartialState.Country, dbUser[0].Country) ||
newPartialState.MiningBlockchainAccountAddress != dbUser[0].MiningBlockchainAccountAddress ||
newPartialState.BlockchainAccountAddress != dbUser[0].BlockchainAccountAddress ||
newPartialState.HideRanking != dbUser[0].HideRanking ||
newPartialState.T1ReferralsSharingEnabled != dbUser[0].T1ReferralsSharingEnabled ||
(dbUser[0].CreatedAt.IsNil() || !newPartialState.CreatedAt.Equal(*dbUser[0].CreatedAt.Time)) ||
!newPartialState.KYCStepsCreatedAt.Equals(dbUser[0].KYCStepsCreatedAt) ||
!newPartialState.KYCStepsLastUpdatedAt.Equals(dbUser[0].KYCStepsLastUpdatedAt) ||
Expand Down

0 comments on commit 9b5a872

Please sign in to comment.