Skip to content

Commit

Permalink
made logic to share t1 referrals be triggered automatically when user…
Browse files Browse the repository at this point in the history
… reaches 25 verified t1 referrals as opposed to on user input
  • Loading branch information
ice-ares committed Jul 11, 2024
1 parent c4ee083 commit 1287667
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 54 deletions.
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/ice-blockchain/freezer
go 1.22

require (
github.com/ClickHouse/ch-go v0.61.5
github.com/alitto/pond v1.9.0
github.com/ClickHouse/ch-go v0.62.0
github.com/alitto/pond v1.9.1
github.com/bsm/redislock v0.9.4
github.com/cenkalti/backoff/v4 v4.3.0
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.366.0
github.com/ice-blockchain/eskimo v1.369.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.144.0
github.com/imroc/req/v3 v3.43.7
Expand All @@ -27,12 +27,12 @@ require (

require (
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.6.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.4.0 // indirect
cloud.google.com/go/auth v0.7.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/firestore v1.15.0 // indirect
cloud.google.com/go/iam v1.1.10 // indirect
cloud.google.com/go/longrunning v0.5.9 // indirect
cloud.google.com/go/iam v1.1.11 // indirect
cloud.google.com/go/longrunning v0.5.10 // indirect
cloud.google.com/go/storage v1.43.0 // indirect
cosmossdk.io/math v1.3.0 // indirect
dario.cat/mergo v1.0.0 // indirect
Expand Down Expand Up @@ -209,11 +209,11 @@ require (
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/api v0.187.0 // indirect
google.golang.org/api v0.188.0 // indirect
google.golang.org/appengine/v2 v2.0.6 // indirect
google.golang.org/genproto v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/genproto v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
48 changes: 24 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14=
cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU=
cloud.google.com/go/auth v0.6.1 h1:T0Zw1XM5c1GlpN2HYr2s+m3vr1p2wy+8VN+Z1FKxW38=
cloud.google.com/go/auth v0.6.1/go.mod h1:eFHG7zDzbXHKmjJddFG/rBlcGp6t25SwRUiEQSlO4x4=
cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4=
cloud.google.com/go/auth/oauth2adapt v0.2.2/go.mod h1:wcYjgpZI9+Yu7LyYBg4pqSiaRkfEK3GQcpb7C/uyF1Q=
cloud.google.com/go/compute/metadata v0.4.0 h1:vHzJCWaM4g8XIcm8kopr3XmDA4Gy/lblD3EhhSux05c=
cloud.google.com/go/compute/metadata v0.4.0/go.mod h1:SIQh1Kkb4ZJ8zJ874fqVkslA29PRXuleyj6vOzlbK7M=
cloud.google.com/go/auth v0.7.0 h1:kf/x9B3WTbBUHkC+1VS8wwwli9TzhSt0vSTVBmMR8Ts=
cloud.google.com/go/auth v0.7.0/go.mod h1:D+WqdrpcjmiCgWrXmLLxOVq1GACoE36chW6KXoEvuIw=
cloud.google.com/go/auth/oauth2adapt v0.2.3 h1:MlxF+Pd3OmSudg/b1yZ5lJwoXCEaeedAguodky1PcKI=
cloud.google.com/go/auth/oauth2adapt v0.2.3/go.mod h1:tMQXOfZzFuNuUxOypHlQEXgdfX5cuhwU+ffUuXRJE8I=
cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY=
cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY=
cloud.google.com/go/firestore v1.15.0 h1:/k8ppuWOtNuDHt2tsRV42yI21uaGnKDEQnRFeBpbFF8=
cloud.google.com/go/firestore v1.15.0/go.mod h1:GWOxFXcv8GZUtYpWHw/w6IuYNux/BtmeVTMmjrm4yhk=
cloud.google.com/go/iam v1.1.10 h1:ZSAr64oEhQSClwBL670MsJAW5/RLiC6kfw3Bqmd5ZDI=
cloud.google.com/go/iam v1.1.10/go.mod h1:iEgMq62sg8zx446GCaijmA2Miwg5o3UbO+nI47WHJps=
cloud.google.com/go/longrunning v0.5.9 h1:haH9pAuXdPAMqHvzX0zlWQigXT7B0+CL4/2nXXdBo5k=
cloud.google.com/go/longrunning v0.5.9/go.mod h1:HD+0l9/OOW0za6UWdKJtXoFAX/BGg/3Wj8p10NeWF7c=
cloud.google.com/go/iam v1.1.11 h1:0mQ8UKSfdHLut6pH9FM3bI55KWR46ketn0PuXleDyxw=
cloud.google.com/go/iam v1.1.11/go.mod h1:biXoiLWYIKntto2joP+62sd9uW5EpkZmKIvfNcTWlnQ=
cloud.google.com/go/longrunning v0.5.10 h1:eB/BniENNRKhjz/xgiillrdcH3G74TGSl3BXinGlI7E=
cloud.google.com/go/longrunning v0.5.10/go.mod h1:tljz5guTr5oc/qhlUjBlk7UAIFMOGuPNxkNDZXlLics=
cloud.google.com/go/storage v1.43.0 h1:CcxnSohZwizt4LCzQHWvBf1/kvtHUn7gk9QERXPyXFs=
cloud.google.com/go/storage v1.43.0/go.mod h1:ajvxEa7WmZS1PxvKRq4bq0tFT3vMd502JwstCcYv0Q0=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
Expand All @@ -24,8 +24,8 @@ firebase.google.com/go/v4 v4.14.1/go.mod h1:fgk2XshgNDEKaioKco+AouiegSI9oTWVqRaB
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/ClickHouse/ch-go v0.61.5 h1:zwR8QbYI0tsMiEcze/uIMK+Tz1D3XZXLdNrlaOpeEI4=
github.com/ClickHouse/ch-go v0.61.5/go.mod h1:s1LJW/F/LcFs5HJnuogFMta50kKDO0lf9zzfrbl0RQg=
github.com/ClickHouse/ch-go v0.62.0 h1:eXH0hytXeCEEZHgMvOX9IiW7wqBb4w1MJMp9rArbkrc=
github.com/ClickHouse/ch-go v0.62.0/go.mod h1:uzso52/PD9+gZj7tL6XAo8/EYDrx7CIwNF4c6PnO6S0=
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
Expand All @@ -38,8 +38,8 @@ github.com/Microsoft/hcsshim v0.12.4 h1:Ev7YUMHAHoWNm+aDSPzc5W9s6E2jyL1szpVDJeZ/
github.com/Microsoft/hcsshim v0.12.4/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6CtY2Qg/JVQ=
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
github.com/alitto/pond v1.9.0 h1:B8BrvXyKe97NK9LHuRsQAOmpRnsp6GJ7mCg1Cgitczo=
github.com/alitto/pond v1.9.0/go.mod h1:xQn3P/sHTYcU/1BR3i86IGIrilcrGC2LiS+E2+CJWsI=
github.com/alitto/pond v1.9.1 h1:OfCpIrMyrWJpn34f647DcFmUxjK8+7Nu3eoVN/WTP+o=
github.com/alitto/pond v1.9.1/go.mod h1:xQn3P/sHTYcU/1BR3i86IGIrilcrGC2LiS+E2+CJWsI=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
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.366.0 h1:brqw1rVWXhn7vtYUqzb8HguzjenMc9CSeYxbdidrBwk=
github.com/ice-blockchain/eskimo v1.366.0/go.mod h1:c2Yp7QwFzJvdrcbZSOmM4jY/Li6Wbo1LVnoouJrAe8g=
github.com/ice-blockchain/eskimo v1.369.0 h1:DFguku6xR4rb8G1Ay4LAh0s6qzYPnoKsO28uFJGvAko=
github.com/ice-blockchain/eskimo v1.369.0/go.mod h1:l4MZKGo/Lpq+LFr65HUAGc/SvN4IclA0kpFqXjjQsZ8=
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.144.0 h1:YQE0olkPdSI6AOlw7r/j5jGI6uLciZQrvXFIkN4C4l4=
Expand Down Expand Up @@ -676,21 +676,21 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/api v0.187.0 h1:Mxs7VATVC2v7CY+7Xwm4ndkX71hpElcvx0D1Ji/p1eo=
google.golang.org/api v0.187.0/go.mod h1:KIHlTc4x7N7gKKuVsdmfBXN13yEEWXWFURWY6SBp2gk=
google.golang.org/api v0.188.0 h1:51y8fJ/b1AaaBRJr4yWm96fPcuxSo0JcegXE3DaHQHw=
google.golang.org/api v0.188.0/go.mod h1:VR0d+2SIiWOYG3r/jdm7adPW9hI2aRv9ETOSCQ9Beag=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine/v2 v2.0.6 h1:LvPZLGuchSBslPBp+LAhihBeGSiRh1myRoYK4NtuBIw=
google.golang.org/appengine/v2 v2.0.6/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7Z1JKf3J3wLI=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20240708141625-4ad9e859172b h1:dSTjko30weBaMj3eERKc0ZVXW4GudCswM3m+P++ukU0=
google.golang.org/genproto v0.0.0-20240708141625-4ad9e859172b/go.mod h1:FfBgJBJg9GcpPvKIuHSZ/aE1g2ecGL74upMzGZjiGEY=
google.golang.org/genproto/googleapis/api v0.0.0-20240708141625-4ad9e859172b h1:y/kpOWeX2pWERnbsvh/hF+Zmo69wVmjyZhstreXQQeA=
google.golang.org/genproto/googleapis/api v0.0.0-20240708141625-4ad9e859172b/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b h1:04+jVzTs2XBnOZcPsLnmrTGqltqJbZQ1Ey26hjYdQQ0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/genproto v0.0.0-20240709173604-40e1e62336c5 h1:ORprMx6Xqr56pGwKXMnVEFBI0k7OIcHI0Rx92/rKypo=
google.golang.org/genproto v0.0.0-20240709173604-40e1e62336c5/go.mod h1:FfBgJBJg9GcpPvKIuHSZ/aE1g2ecGL74upMzGZjiGEY=
google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5 h1:a/Z0jgw03aJ2rQnp5PlPpznJqJft0HyvyrcUcxgzPwY=
google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
Expand Down
5 changes: 4 additions & 1 deletion miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ type (
model.LatestDeviceField
UpdatedUser
model.BalanceSoloPendingField
model.BalanceT1WelcomeBonusPendingField
model.BalanceT1PendingField
model.BalanceT2PendingField
model.PreStakingBonusField
model.PreStakingAllocationField
model.ExtraBonusField
model.VerifiedT1ReferralsField
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 All @@ -92,6 +93,7 @@ type (
model.BalanceT2EthereumPendingField
model.KYCQuizDisabledResettableField
model.KYCQuizCompletedResettableField
model.WelcomeBonusV2AppliedField
model.UserIDField
model.DeserializedUsersKey
model.IDT0Field
Expand All @@ -101,6 +103,7 @@ type (
model.BalanceTotalMintedField
model.BalanceTotalSlashedField
model.BalanceSoloPendingAppliedField
model.BalanceT1WelcomeBonusPendingAppliedField
model.BalanceT1PendingAppliedField
model.BalanceT2PendingAppliedField
model.BalanceSoloField
Expand Down
19 changes: 18 additions & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
t1ReferralsToIncrementActiveValue, t2ReferralsToIncrementActiveValue = make(map[int64]int32, batchSize), make(map[int64]int32, batchSize)
t1ReferralsThatStoppedMining, t2ReferralsThatStoppedMining = make(map[int64]uint32, batchSize), make(map[int64]uint32, batchSize)
balanceT1EthereumIncr, balanceT2EthereumIncr = make(map[int64]float64, batchSize), make(map[int64]float64, batchSize)
balanceT1WelcomeBonusIncr = make(map[int64]float64, batchSize)
pendingBalancesForTMinus1, pendingBalancesForT0 = make(map[int64]float64, batchSize), make(map[int64]float64, batchSize)
referralsThatStoppedMining = make([]*referralThatStoppedMining, 0, batchSize)
coinDistributions = make([]*coindistribution.ByEarnerForReview, 0, 4*batchSize)
Expand Down Expand Up @@ -246,6 +247,9 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
for k := range t2ReferralsToIncrementActiveValue {
delete(t2ReferralsToIncrementActiveValue, k)
}
for k := range balanceT1WelcomeBonusIncr {
delete(balanceT1WelcomeBonusIncr, k)
}
for k := range balanceT1EthereumIncr {
delete(balanceT1EthereumIncr, k)
}
Expand Down Expand Up @@ -362,6 +366,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
if isAdvancedTeamDisabled(usr.LatestDevice) {
usr.ActiveT2Referrals = 0
}
beforeWelcomeBonusV2Applied := usr.WelcomeBonusV2Applied == nil || !*usr.WelcomeBonusV2Applied
updatedUser, shouldGenerateHistory, IDT0Changed, pendingAmountForTMinus1, pendingAmountForT0 := mine(now, usr, t0Ref, tMinus1Ref)
if shouldGenerateHistory {
syncQuizUserIDs = append(syncQuizUserIDs, usr.UserID)
Expand Down Expand Up @@ -409,6 +414,13 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
if t0Ref != nil && t0Ref.ID != 0 && pendingAmountForT0 != 0 {
pendingBalancesForT0[t0Ref.ID] += pendingAmountForT0
}
if afterWelcomeBonusV2Applied := updatedUser.WelcomeBonusV2Applied != nil && *usr.WelcomeBonusV2Applied; t0Ref != nil && t0Ref.ID != 0 && !beforeWelcomeBonusV2Applied && afterWelcomeBonusV2Applied {
idT0 := t0Ref.ID
if idT0 < 0 {
idT0 *= -1
}
balanceT1WelcomeBonusIncr[idT0] += tokenomics.WelcomeBonusV2Amount
}
updatedUsers = append(updatedUsers, &updatedUser.UpdatedUser)
} else {
if updUsr := updateT0AndTMinus1ReferralsForUserHasNeverMined(usr); updUsr != nil {
Expand Down Expand Up @@ -553,7 +565,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {

var pipeliner redis.Pipeliner
var transactional bool
if len(pendingBalancesForTMinus1)+len(pendingBalancesForT0)+len(balanceT1EthereumIncr)+len(balanceT2EthereumIncr)+len(t1ReferralsToIncrementActiveValue)+len(t2ReferralsToIncrementActiveValue)+len(referralsCountGuardOnlyUpdatedUsers)+len(t1ReferralsThatStoppedMining)+len(t2ReferralsThatStoppedMining)+len(extraBonusOnlyUpdatedUsers)+len(referralsUpdated)+len(userGlobalRanks) > 0 {
if len(pendingBalancesForTMinus1)+len(pendingBalancesForT0)+len(balanceT1WelcomeBonusIncr)+len(balanceT1EthereumIncr)+len(balanceT2EthereumIncr)+len(t1ReferralsToIncrementActiveValue)+len(t2ReferralsToIncrementActiveValue)+len(referralsCountGuardOnlyUpdatedUsers)+len(t1ReferralsThatStoppedMining)+len(t2ReferralsThatStoppedMining)+len(extraBonusOnlyUpdatedUsers)+len(referralsUpdated)+len(userGlobalRanks) > 0 {
pipeliner = m.db.TxPipeline()
transactional = true
} else {
Expand Down Expand Up @@ -615,6 +627,11 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
return err
}
}
for idT0, amount := range balanceT1WelcomeBonusIncr {
if err := pipeliner.HIncrByFloat(reqCtx, model.SerializedUsersKey(idT0), "balance_t1_welcome_bonus_pending", amount).Err(); err != nil {
return err
}
}
for idT0, amount := range balanceT1EthereumIncr {
if amount == 0 {
continue
Expand Down
23 changes: 22 additions & 1 deletion miner/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package miner
import (
"math"

"github.com/ice-blockchain/freezer/model"
"github.com/ice-blockchain/freezer/tokenomics"
"github.com/ice-blockchain/wintr/time"
)
Expand Down Expand Up @@ -143,7 +144,7 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser *
}
activeT1Referrals := int32(0)
if updatedUser.MiningBoostLevelIndex != nil {
if updatedUser.T1ReferralsSharingEnabled {
if updatedUser.IsVerified() && updatedUser.VerifiedT1Referrals >= 25 {
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 @@ -183,6 +184,19 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser *
}
}

if updatedUser.BalanceT1WelcomeBonusPendingApplied < 25*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)
}
} else {
updatedUser.BalanceT1WelcomeBonusPending = 0
updatedUser.BalanceT1WelcomeBonusPendingApplied = 0
}

slashedAmount := (updatedUser.SlashingRateSolo + updatedUser.SlashingRateT0) * elapsedTimeFraction
updatedUser.BalanceSolo -= updatedUser.SlashingRateSolo * elapsedTimeFraction

Expand Down Expand Up @@ -238,6 +252,13 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser *
if usr.BalanceTotalPreStaking+usr.BalanceTotalStandard == 0 {
slashedAmount = 0
}
if usr.WelcomeBonusV2Applied == nil || !*usr.WelcomeBonusV2Applied {
updatedUser.BalanceSolo += tokenomics.WelcomeBonusV2Amount - 10
trueVal := model.FlexibleBool(true)
usr.WelcomeBonusV2Applied = &trueVal
} else {
usr.WelcomeBonusV2Applied = nil
}

totalAmount := updatedUser.BalanceSolo + updatedUser.BalanceT0 + updatedUser.BalanceT1 + updatedUser.BalanceT2
updatedUser.BalanceTotalStandard, updatedUser.BalanceTotalPreStaking = tokenomics.ApplyPreStaking(totalAmount, updatedUser.PreStakingAllocation, updatedUser.PreStakingBonus)
Expand Down
2 changes: 2 additions & 0 deletions miner/mining_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func newUser() *user {
u.CreatedAt = testTime
u.MiningSessionSoloStartedAt = timeDelta(-stdlibtime.Hour)
u.MiningSessionSoloEndedAt = timeDelta(23 * stdlibtime.Hour)
trueVal := model.FlexibleBool(true)
u.WelcomeBonusV2Applied = &trueVal

return u
}
Expand Down
Loading

0 comments on commit 1287667

Please sign in to comment.