Skip to content

Commit b3333d4

Browse files
committed
GSW-2083 refactor: change setter access permission to private in launchpad
1 parent 67586c8 commit b3333d4

9 files changed

+193
-193
lines changed

Diff for: contract/r/gnoswap/launchpad/api_deposit.gno

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func ApiGetClaimableDepositByAddress(address std.Address) uint64 {
3232
}
3333

3434
rwd, _ := rewardStates.Get(deposit.projectId, deposit.tier)
35-
reward := rwd.Claim(depositId, uint64(std.GetHeight()))
35+
reward := rwd.claim(depositId, uint64(std.GetHeight()))
3636

3737
gnsToUser += reward
3838
}

Diff for: contract/r/gnoswap/launchpad/deposit.gno

+25-25
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string {
136136
// update StartHeight, StartTime, TierAmountPerBlockX128
137137
tier.updateStarted(info.CurrentHeight, info.CurrentTime)
138138
duration := tier.Ended().height - info.CurrentHeight
139-
tier.SetTierAmountPerBlockX128(calcRewardPerBlockX128(tier.TierAmount(), duration))
139+
tier.setTierAmountPerBlockX128(calcRewardPerBlockX128(tier.TierAmount(), duration))
140140

141141
prevAddr, prevPkgPath := getPrev()
142142
std.Emit(
@@ -152,7 +152,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string {
152152
)
153153

154154
rewardState := NewRewardState(tier.tierAmountPerBlockX128, tier.started.height, tier.ended.height)
155-
rewardStates.Set(info.Project.id, info.TierType, rewardState)
155+
rewardStates.set(info.Project.id, info.TierType, rewardState)
156156
}
157157

158158
reward := tier.Reward()
@@ -161,7 +161,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string {
161161
panic(err.Error())
162162
}
163163
reward.addRewardPerDeposit(rewardPerDeposit)
164-
reward.SetLastHeight(currentHeight)
164+
reward.setLastHeight(currentHeight)
165165

166166
rewardInfo := NewRewardInfo(
167167
reward.AccumRewardPerDeposit(),
@@ -172,17 +172,17 @@ func DepositGns(targetProjectTierId string, amount uint64) string {
172172
tier.Ended().height,
173173
currentHeight)
174174
reward.Info().Set(deposit.ID(), rewardInfo)
175-
tier.SetReward(reward)
176-
tier.SetTotalDepositAmount(tier.TotalDepositAmount() + amount)
177-
tier.SetActualDepositAmount(tier.ActualDepositAmount() + amount)
178-
tier.SetTotalParticipant(tier.TotalParticipant() + 1)
179-
tier.SetActualParticipant(tier.ActualParticipant() + 1)
175+
tier.setReward(reward)
176+
tier.setTotalDepositAmount(tier.TotalDepositAmount() + amount)
177+
tier.setActualDepositAmount(tier.ActualDepositAmount() + amount)
178+
tier.setTotalParticipant(tier.TotalParticipant() + 1)
179+
tier.setActualParticipant(tier.ActualParticipant() + 1)
180180

181181
project.setTier(convertTierTypeStrToUint64(tierType), tier)
182-
project.Stats().SetTotalDeposit(project.Stats().TotalDeposit() + amount)
183-
project.Stats().SetActualDeposit(project.Stats().ActualDeposit() + amount)
184-
project.Stats().SetTotalParticipant(project.Stats().TotalParticipant() + 1)
185-
project.Stats().SetActualParticipant(project.Stats().ActualParticipant() + 1)
182+
project.Stats().setTotalDeposit(project.Stats().TotalDeposit() + amount)
183+
project.Stats().setActualDeposit(project.Stats().ActualDeposit() + amount)
184+
project.Stats().setTotalParticipant(project.Stats().TotalParticipant() + 1)
185+
project.Stats().setActualParticipant(project.Stats().ActualParticipant() + 1)
186186

187187
projects[projectId] = project
188188

@@ -191,7 +191,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string {
191191
panic(addDetailToError(
192192
errInvalidRewardState, err.Error()))
193193
}
194-
rewardState.AddStake(uint64(std.GetHeight()), deposit.id, amount)
194+
rewardState.addStake(uint64(std.GetHeight()), deposit.id, amount)
195195

196196
// Update gov_staker to calculate project's recipient's reward
197197
gs.SetAmountByProjectWallet(project.recipient, amount, true)
@@ -783,20 +783,20 @@ func processDepositCollection(
783783
continue
784784
}
785785

786-
deposit.SetDepositCollectHeight(currentHeight)
787-
deposit.SetDepositCollectTime(now)
786+
deposit.setDepositCollectHeight(currentHeight)
787+
deposit.setDepositCollectTime(now)
788788
deposits[deposit.id] = deposit
789789

790790
totalAmount += deposit.amount
791791

792792
gs.SetAmountByProjectWallet(project.recipient, deposit.amount, false)
793793

794-
tier.SetActualDepositAmount(tier.ActualDepositAmount() - deposit.amount)
795-
tier.SetActualParticipant(tier.ActualParticipant() - 1)
794+
tier.setActualDepositAmount(tier.ActualDepositAmount() - deposit.amount)
795+
tier.setActualParticipant(tier.ActualParticipant() - 1)
796796

797797
project.setTier(convertTierTypeStrToUint64(deposit.tier), tier)
798-
project.Stats().SetActualDeposit(project.Stats().actualDeposit - deposit.amount)
799-
project.Stats().SetActualParticipant(project.Stats().actualParticipant - 1)
798+
project.Stats().setActualDeposit(project.Stats().actualDeposit - deposit.amount)
799+
project.Stats().setActualParticipant(project.Stats().actualParticipant - 1)
800800

801801
projects[deposit.projectId] = project
802802

@@ -899,18 +899,18 @@ func processDeposit(deposit *Deposit, project *Project, height uint64) (uint64,
899899
}
900900

901901
// Update deposit status
902-
deposit.SetDepositCollectHeight(height)
903-
deposit.SetDepositCollectTime(uint64(time.Now().Unix()))
902+
deposit.setDepositCollectHeight(height)
903+
deposit.setDepositCollectTime(uint64(time.Now().Unix()))
904904
deposits[deposit.id] = *deposit
905905

906906
// Update project tier
907-
tier.SetActualDepositAmount(tier.ActualDepositAmount() - deposit.amount)
908-
tier.SetActualParticipant(tier.ActualParticipant() - 1)
907+
tier.setActualDepositAmount(tier.ActualDepositAmount() - deposit.amount)
908+
tier.setActualParticipant(tier.ActualParticipant() - 1)
909909

910910
// Update project
911911
project.setTier(convertTierTypeStrToUint64(deposit.tier), tier)
912-
project.Stats().SetActualDeposit(project.Stats().actualDeposit - deposit.amount)
913-
project.Stats().SetActualParticipant(project.Stats().actualParticipant - 1)
912+
project.Stats().setActualDeposit(project.Stats().actualDeposit - deposit.amount)
913+
project.Stats().setActualParticipant(project.Stats().actualParticipant - 1)
914914

915915
projects[deposit.projectId] = *project
916916

Diff for: contract/r/gnoswap/launchpad/launchpad.gno

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ func createTier(
663663
}
664664

665665
rewardState := NewRewardState(tier.tierAmountPerBlockX128, startHeight, endHeight)
666-
rewardStates.Set(projectId, strconv.FormatUint(duration, 10), rewardState)
666+
rewardStates.set(projectId, strconv.FormatUint(duration, 10), rewardState)
667667

668668
projectTiersWithoutDeposit[tierId] = true
669669
return tier

Diff for: contract/r/gnoswap/launchpad/launchpad_test.gno

+36-36
Original file line numberDiff line numberDiff line change
@@ -496,21 +496,21 @@ func TestProject_GetSet(t *testing.T) {
496496
t.Errorf("NewProject Refund mismatch, got=%d", refund.Amount())
497497
}
498498

499-
p.SetID("pid2")
499+
p.setID("pid2")
500500
if p.ID() != "pid2" {
501-
t.Errorf("SetID failed, got=%s", p.ID())
501+
t.Errorf("setID failed, got=%s", p.ID())
502502
}
503-
p.SetName("MyProject2")
503+
p.setName("MyProject2")
504504
if p.Name() != "MyProject2" {
505-
t.Errorf("SetName failed, got=%s", p.Name())
505+
t.Errorf("setName failed, got=%s", p.Name())
506506
}
507-
p.SetTokenPath("new/tokenPath")
507+
p.setTokenPath("new/tokenPath")
508508
if p.TokenPath() != "new/tokenPath" {
509-
t.Errorf("SetTokenPath failed, got=%s", p.TokenPath())
509+
t.Errorf("setTokenPath failed, got=%s", p.TokenPath())
510510
}
511-
p.SetDepositAmount(2000)
511+
p.setDepositAmount(2000)
512512
if p.DepositAmount() != 2000 {
513-
t.Errorf("SetDepositAmount failed, got=%d", p.DepositAmount())
513+
t.Errorf("setDepositAmount failed, got=%d", p.DepositAmount())
514514
}
515515
t.Run("TestProject_isActivated", func(t *testing.T) {
516516
now := uint64(1)
@@ -583,17 +583,17 @@ func TestTier_GetSet(t *testing.T) {
583583
t.Errorf("Tier CalculatedAmount mismatch, got=%d", tr.CalculatedAmount())
584584
}
585585

586-
tr.SetID("tierIdNew")
586+
tr.setID("tierIdNew")
587587
if tr.ID() != "tierIdNew" {
588-
t.Errorf("SetID failed, got=%s", tr.ID())
588+
t.Errorf("setID failed, got=%s", tr.ID())
589589
}
590-
tr.SetTierAmount(999)
590+
tr.setTierAmount(999)
591591
if tr.TierAmount() != 999 {
592-
t.Errorf("SetTierAmount failed, got=%d", tr.TierAmount())
592+
t.Errorf("setTierAmount failed, got=%d", tr.TierAmount())
593593
}
594-
tr.SetActualDepositAmount(777)
594+
tr.setActualDepositAmount(777)
595595
if tr.ActualDepositAmount() != 777 {
596-
t.Errorf("SetActualDepositAmount failed, got=%d", tr.ActualDepositAmount())
596+
t.Errorf("setActualDepositAmount failed, got=%d", tr.ActualDepositAmount())
597597
}
598598
}
599599

@@ -623,13 +623,13 @@ func TestRewardInfo_GetSet(t *testing.T) {
623623
if ri.GetLastHeight() != 777 {
624624
t.Errorf("LastHeight mismatch, got=%d", ri.GetLastHeight())
625625
}
626-
ri.SetPriceDebt(u256.NewUint(999))
626+
ri.setPriceDebt(u256.NewUint(999))
627627
if ri.PriceDebt().ToString() != "999" {
628-
t.Errorf("SetPriceDebt failed, got=%s", ri.PriceDebt().ToString())
628+
t.Errorf("setPriceDebt failed, got=%s", ri.PriceDebt().ToString())
629629
}
630-
ri.SetRewardAmount(1234)
630+
ri.setRewardAmount(1234)
631631
if ri.RewardAmount() != 1234 {
632-
t.Errorf("SetRewardAmount failed, got=%d", ri.RewardAmount())
632+
t.Errorf("setRewardAmount failed, got=%d", ri.RewardAmount())
633633
}
634634
}
635635

@@ -643,13 +643,13 @@ func TestTimeInfo_GetSet(t *testing.T) {
643643
t.Errorf("Time mismatch, got=%d", ti.Time())
644644
}
645645

646-
ti.SetHeight(100)
647-
ti.SetTime(9999)
646+
ti.setHeight(100)
647+
ti.setTime(9999)
648648
if ti.Height() != 100 {
649-
t.Errorf("SetHeight failed, got=%d", ti.Height())
649+
t.Errorf("setHeight failed, got=%d", ti.Height())
650650
}
651651
if ti.Time() != 9999 {
652-
t.Errorf("SetTime failed, got=%d", ti.Time())
652+
t.Errorf("setTime failed, got=%d", ti.Time())
653653
}
654654
}
655655

@@ -665,17 +665,17 @@ func TestRefundInfo_GetSet(t *testing.T) {
665665
t.Errorf("Time mismatch, got=%d", ri.Time())
666666
}
667667

668-
ri.SetAmount(111)
669-
ri.SetHeight(222)
670-
ri.SetTime(333)
668+
ri.setAmount(111)
669+
ri.setHeight(222)
670+
ri.setTime(333)
671671
if ri.Amount() != 111 {
672-
t.Errorf("SetAmount failed, got=%d", ri.Amount())
672+
t.Errorf("setAmount failed, got=%d", ri.Amount())
673673
}
674674
if ri.Height() != 222 {
675-
t.Errorf("SetHeight failed, got=%d", ri.Height())
675+
t.Errorf("setHeight failed, got=%d", ri.Height())
676676
}
677677
if ri.Time() != 333 {
678-
t.Errorf("SetTime failed, got=%d", ri.Time())
678+
t.Errorf("setTime failed, got=%d", ri.Time())
679679
}
680680
}
681681

@@ -688,13 +688,13 @@ func TestCondition_GetSet(t *testing.T) {
688688
t.Errorf("Condition MinAmount mismatch, got=%d", c.MinAmount())
689689
}
690690

691-
c.SetTokenPath("new/token")
691+
c.setTokenPath("new/token")
692692
if c.TokenPath() != "new/token" {
693-
t.Errorf("SetTokenPath failed, got=%s", c.TokenPath())
693+
t.Errorf("setTokenPath failed, got=%s", c.TokenPath())
694694
}
695-
c.SetMinAmount(2000)
695+
c.setMinAmount(2000)
696696
if c.MinAmount() != 2000 {
697-
t.Errorf("SetMinAmount failed, got=%d", c.MinAmount())
697+
t.Errorf("setMinAmount failed, got=%d", c.MinAmount())
698698
}
699699
}
700700

@@ -714,13 +714,13 @@ func TestReward_GetSet(t *testing.T) {
714714
if r.Info() == nil {
715715
t.Errorf("Info mismatch, got=%v, want=not nil", r.Info())
716716
}
717-
r.SetAccumRewardPerDeposit(u256.NewUint(9999))
717+
r.setAccumRewardPerDeposit(u256.NewUint(9999))
718718
if r.AccumRewardPerDeposit().ToString() != "9999" {
719-
t.Errorf("SetAccumRewardPerDeposit failed, got=%s", r.AccumRewardPerDeposit().ToString())
719+
t.Errorf("setAccumRewardPerDeposit failed, got=%s", r.AccumRewardPerDeposit().ToString())
720720
}
721-
r.SetLastHeight(111)
721+
r.setLastHeight(111)
722722
if r.GetLastHeight() != 111 {
723-
t.Errorf("SetLastHeight failed, got=%d", r.GetLastHeight())
723+
t.Errorf("setLastHeight failed, got=%d", r.GetLastHeight())
724724
}
725725
}
726726

Diff for: contract/r/gnoswap/launchpad/reward.gno

+9-9
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func CollectRewardByProjectId(projectId string) uint64 {
7575
panic(err.Error())
7676
}
7777
reward.addRewardPerDeposit(rewardPerDeposit)
78-
reward.SetLastHeight(currentHeight)
78+
reward.setLastHeight(currentHeight)
7979
rewardAmount := reward.deductReward(depositId, currentHeight)
8080
if rewardAmount == 0 {
8181
continue
@@ -97,9 +97,9 @@ func CollectRewardByProjectId(projectId string) uint64 {
9797
project.setTier(convertTierTypeStrToUint64(deposit.Tier()), tier)
9898

9999
// Update deposit
100-
deposit.SetRewardCollected(deposit.RewardCollected() + rewardAmount)
101-
deposit.SetRewardCollectHeight(currentHeight)
102-
deposit.SetRewardCollectTime(uint64(time.Now().Unix()))
100+
deposit.setRewardCollected(deposit.RewardCollected() + rewardAmount)
101+
deposit.setRewardCollectHeight(currentHeight)
102+
deposit.setRewardCollectTime(uint64(time.Now().Unix()))
103103
deposits[depositId] = deposit
104104
}
105105

@@ -151,14 +151,14 @@ func CollectRewardByDepositId(depositId string) uint64 {
151151
panic(err.Error())
152152
}
153153
reward.addRewardPerDeposit(rewardPerDeposit)
154-
reward.SetLastHeight(currentHeight)
154+
reward.setLastHeight(currentHeight)
155155

156156
rewardAmount := reward.deductReward(depositId, currentHeight)
157157
if rewardAmount == 0 {
158158
panic(addDetailToError(errAlreadyCollected, ufmt.Sprintf("depositId(%s)", depositId)))
159159
}
160160

161-
tier.SetReward(reward)
161+
tier.setReward(reward)
162162
tier.userCollectedAmount += rewardAmount
163163
project.Stats().totalCollected += rewardAmount
164164

@@ -174,9 +174,9 @@ func CollectRewardByDepositId(depositId string) uint64 {
174174
project.setTier(convertTierTypeStrToUint64(deposit.Tier()), tier)
175175

176176
// Update deposit
177-
deposit.SetRewardCollected(deposit.RewardCollected() + rewardAmount)
178-
deposit.SetRewardCollectHeight(currentHeight)
179-
deposit.SetRewardCollectTime(uint64(time.Now().Unix()))
177+
deposit.setRewardCollected(deposit.RewardCollected() + rewardAmount)
178+
deposit.setRewardCollectHeight(currentHeight)
179+
deposit.setRewardCollectTime(uint64(time.Now().Unix()))
180180
deposits[depositId] = deposit
181181

182182
projects[deposit.projectId] = project

Diff for: contract/r/gnoswap/launchpad/reward_calculation.gno

+6-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ func (states RewardStates) Get(projectId string, tierStr string) (*RewardState,
7575
return statesI.(*RewardState), nil
7676
}
7777

78-
func (states RewardStates) Set(projectId string, tierStr string, state *RewardState) {
78+
func (states RewardStates) set(projectId string, tierStr string, state *RewardState) {
7979
key := projectId + ":" + tierStr
8080
states.states.Set(key, state)
8181
}
8282

83-
func (states RewardStates) DeleteProject(projectId string) uint64 {
83+
func (states RewardStates) deleteProject(projectId string) uint64 {
8484
totalLeftover := uint64(0)
8585
keys := []string{}
8686
states.states.Iterate(projectId+":", projectId+";", func(key string, value interface{}) bool {
@@ -154,7 +154,7 @@ func (self *RewardState) deductReward(depositId string, currentHeight uint64) ui
154154
return reward64
155155
}
156156

157-
// This function MUST be called as a part of AddStake or RemoveStake
157+
// This function MUST be called as a part of addStake or removeStake
158158
// CurrentBalance / StakeChange / IsRemoveStake will be updated in those functions
159159
func (self *RewardState) finalize(currentHeight uint64) {
160160
if currentHeight <= self.LastHeight {
@@ -184,7 +184,7 @@ func (self *RewardState) finalize(currentHeight uint64) {
184184
self.LastHeight = currentHeight
185185
}
186186

187-
func (self *RewardState) AddStake(currentHeight uint64, depositId string, amount uint64) {
187+
func (self *RewardState) addStake(currentHeight uint64, depositId string, amount uint64) {
188188
if self.info.Has(depositId) {
189189
panic(addDetailToError(
190190
errAlreadyExistDeposit,
@@ -215,7 +215,7 @@ func (self *RewardState) AddStake(currentHeight uint64, depositId string, amount
215215
self.info.Set(depositId, info)
216216
}
217217

218-
func (self *RewardState) Claim(depositId string, currentHeight uint64) uint64 {
218+
func (self *RewardState) claim(depositId string, currentHeight uint64) uint64 {
219219
if !self.info.Has(depositId) {
220220
panic(addDetailToError(
221221
errNotExistDeposit,
@@ -229,7 +229,7 @@ func (self *RewardState) Claim(depositId string, currentHeight uint64) uint64 {
229229
return reward
230230
}
231231

232-
func (self *RewardState) RemoveStake(depositId string, amount uint64, currentHeight uint64) uint64 {
232+
func (self *RewardState) removeStake(depositId string, amount uint64, currentHeight uint64) uint64 {
233233
if !self.info.Has(depositId) {
234234
panic(addDetailToError(
235235
errNotExistDeposit,

0 commit comments

Comments
 (0)