diff --git a/contract/p/gnoswap/int256/conversion_test.gno b/contract/p/gnoswap/int256/conversion_test.gno index 4e87df6e0..5a263d815 100644 --- a/contract/p/gnoswap/int256/conversion_test.gno +++ b/contract/p/gnoswap/int256/conversion_test.gno @@ -142,7 +142,7 @@ func TestSet(t *testing.T) { got := z.ToString() if got != tc.want { - t.Errorf("Set(%s) = %s, want %s", tc.x, got, tc.want) + t.Errorf("set(%s) = %s, want %s", tc.x, got, tc.want) } } } diff --git a/contract/r/gnoswap/gns/_helper_test.gno b/contract/r/gnoswap/gns/_helper_test.gno index 7574ba52e..0fa870e7f 100644 --- a/contract/r/gnoswap/gns/_helper_test.gno +++ b/contract/r/gnoswap/gns/_helper_test.gno @@ -22,8 +22,8 @@ func resetObject(t *testing.T) { func resetGnsTokenObject(t *testing.T) { t.Helper() - Token, privateLedger = grc20.NewToken("Gnoswap", "GNS", 6) - UserTeller = Token.CallerTeller() + token, privateLedger = grc20.NewToken("Gnoswap", "GNS", 6) + UserTeller = token.CallerTeller() owner = ownable.NewWithAddress(consts.ADMIN) privateLedger.Mint(owner.Owner(), INITIAL_MINT_AMOUNT) } diff --git a/contract/r/gnoswap/gns/gns.gno b/contract/r/gnoswap/gns/gns.gno index adfda51df..ea0fe776b 100644 --- a/contract/r/gnoswap/gns/gns.gno +++ b/contract/r/gnoswap/gns/gns.gno @@ -21,7 +21,7 @@ const ( var ( owner *ownable.Ownable - Token *grc20.Token + token *grc20.Token privateLedger *grc20.PrivateLedger UserTeller grc20.Teller @@ -34,11 +34,11 @@ var ( func init() { owner = ownable.NewWithAddress(consts.ADMIN) - Token, privateLedger = grc20.NewToken("Gnoswap", "GNS", 6) - UserTeller = Token.CallerTeller() + token, privateLedger = grc20.NewToken("Gnoswap", "GNS", 6) + UserTeller = token.CallerTeller() privateLedger.Mint(owner.Owner(), INITIAL_MINT_AMOUNT) - getter := func() *grc20.Token { return Token } + getter := func() *grc20.Token { return token } grc20reg.Register(getter, "") // Initial amount set to 900_000_000_000_000 (MAXIMUM_SUPPLY - INITIAL_MINT_AMOUNT). @@ -50,31 +50,31 @@ func init() { } func TotalSupply() uint64 { - return Token.TotalSupply() + return token.TotalSupply() } func GetName() string { - return Token.GetName() + return token.GetName() } func GetSymbol() string { - return Token.GetSymbol() + return token.GetSymbol() } func GetDecimals() uint { - return Token.GetDecimals() + return token.GetDecimals() } func KnownAccounts() int { - return Token.KnownAccounts() + return token.KnownAccounts() } func BalanceOf(owner std.Address) uint64 { - return Token.BalanceOf(owner) + return token.BalanceOf(owner) } func Allowance(owner, spender std.Address) uint64 { - return Token.Allowance(owner, spender) + return token.Allowance(owner, spender) } func MintGns(address std.Address) uint64 { @@ -155,10 +155,10 @@ func Render(path string) string { switch { case path == "": - return Token.RenderHome() + return token.RenderHome() case c == 2 && parts[0] == "balance": owner := std.Address(parts[1]) - balance := Token.BalanceOf(owner) + balance := token.BalanceOf(owner) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/contract/r/gnoswap/gns/halving.gno b/contract/r/gnoswap/gns/halving.gno index 2d5f5c1ca..e736f9593 100644 --- a/contract/r/gnoswap/gns/halving.gno +++ b/contract/r/gnoswap/gns/halving.gno @@ -29,7 +29,7 @@ const ( ) var ( - HALVING_AMOUNTS_PER_YEAR = [HALVING_END_YEAR]uint64{ + halvingAmountsPerYear = [HALVING_END_YEAR]uint64{ 18_750_000_000_000 * 12, // Year 1: 225000000000000 18_750_000_000_000 * 12, // Year 2: 225000000000000 9_375_000_000_000 * 12, // Year 3: 112500000000000 @@ -566,7 +566,7 @@ func setAmountPerBlockPerHalvingYear(year int64, amount uint64) { } func GetHalvingAmountsPerYear(year int64) uint64 { - return HALVING_AMOUNTS_PER_YEAR[year-1] + return halvingAmountsPerYear[year-1] } func GetEndHeight() int64 { diff --git a/contract/r/gnoswap/gov/staker/api_staker_test.gno b/contract/r/gnoswap/gov/staker/api_staker_test.gno index 330d085f9..7adcbaa28 100644 --- a/contract/r/gnoswap/gov/staker/api_staker_test.gno +++ b/contract/r/gnoswap/gov/staker/api_staker_test.gno @@ -73,7 +73,7 @@ func TestGetLockedInfoByAddress_EmptyLocks(t *testing.T) { func TestGetClaimableRewardByAddress(t *testing.T) { addr := testutils.TestAddress("claimable_test") - rewardState.AddStake(uint64(std.GetHeight()), addr, 100, 0, nil) + rewardState.addStake(uint64(std.GetHeight()), addr, 100, 0, nil) currentGNSBalance = 1000 // userEmissionReward.Set(addr.String(), uint64(1000)) diff --git a/contract/r/gnoswap/gov/staker/reward_calculation.gno b/contract/r/gnoswap/gov/staker/reward_calculation.gno index ce14fd476..a2d5d6694 100644 --- a/contract/r/gnoswap/gov/staker/reward_calculation.gno +++ b/contract/r/gnoswap/gov/staker/reward_calculation.gno @@ -174,7 +174,7 @@ func (self *RewardState) deductReward(staker std.Address, currentBalance uint64) return reward64, protocolFeeRewards } -// This function MUST be called as a part of AddStake or RemoveStake +// This function MUST be called as a part of addStake or removeStake // CurrentBalance / StakeChange / IsRemoveStake will be updated in those functions func (self *RewardState) finalize(currentBalance uint64, currentProtocolFeeBalances map[string]uint64) { if self.TotalStake == uint64(0) { @@ -207,7 +207,7 @@ func (self *RewardState) finalize(currentBalance uint64, currentProtocolFeeBalan } } -func (self *RewardState) AddStake(currentHeight uint64, staker std.Address, amount uint64, currentBalance uint64, currentProtocolFeeBalances map[string]uint64) { +func (self *RewardState) addStake(currentHeight uint64, staker std.Address, amount uint64, currentBalance uint64, currentProtocolFeeBalances map[string]uint64) { self.finalize(currentBalance, currentProtocolFeeBalances) self.TotalStake += amount @@ -249,7 +249,7 @@ func (self *RewardState) AddStake(currentHeight uint64, staker std.Address, amou self.info.Set(staker.String(), info) } -func (self *RewardState) Claim(staker std.Address, currentBalance uint64, currentProtocolFeeBalances map[string]uint64) (uint64, map[string]uint64) { +func (self *RewardState) claim(staker std.Address, currentBalance uint64, currentProtocolFeeBalances map[string]uint64) (uint64, map[string]uint64) { if !self.info.Has(staker.String()) { return 0, make(map[string]uint64) } @@ -266,7 +266,7 @@ func (self *RewardState) Claim(staker std.Address, currentBalance uint64, curren return reward, protocolFeeRewards } -func (self *RewardState) RemoveStake(staker std.Address, amount uint64, currentBalance uint64, currentProtocolFeeBalances map[string]uint64) (uint64, map[string]uint64) { +func (self *RewardState) removeStake(staker std.Address, amount uint64, currentBalance uint64, currentProtocolFeeBalances map[string]uint64) (uint64, map[string]uint64) { self.finalize(currentBalance, currentProtocolFeeBalances) reward, protocolFeeRewards := self.deductReward(staker, currentBalance) @@ -316,10 +316,10 @@ func SetAmountByProjectWallet(addr std.Address, amount uint64, add bool) { currentAmount := getAmountByProjectWallet(addr) if add { amountByProjectWallet.Set(addr.String(), currentAmount+amount) - rewardState.AddStake(uint64(std.GetHeight()), caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) + rewardState.addStake(uint64(std.GetHeight()), caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) } else { amountByProjectWallet.Set(addr.String(), currentAmount-amount) - rewardState.RemoveStake(caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) + rewardState.removeStake(caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) } } diff --git a/contract/r/gnoswap/gov/staker/reward_calculation_test.gno b/contract/r/gnoswap/gov/staker/reward_calculation_test.gno index 29ce49e70..059f15b11 100644 --- a/contract/r/gnoswap/gov/staker/reward_calculation_test.gno +++ b/contract/r/gnoswap/gov/staker/reward_calculation_test.gno @@ -10,10 +10,10 @@ func TestRewardCalculation_1_1(t *testing.T) { state := NewRewardState() current := 100 - state.AddStake(10, testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) + state.addStake(10, testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) current += 100 - reward, _ := state.RemoveStake(testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) + reward, _ := state.removeStake(testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) if reward != 100+100 { t.Errorf("expected reward %d, got %d", 100+100, reward) @@ -24,10 +24,10 @@ func TestRewardCalculation_1_2(t *testing.T) { state := NewRewardState() current := 100 - state.AddStake(10, testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) + state.addStake(10, testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) current += 100 - reward, _ := state.RemoveStake(testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) + reward, _ := state.removeStake(testutils.TestAddress("alice"), 100, uint64(current), make(map[string]uint64)) current -= int(reward) if reward != 100+100 { @@ -35,10 +35,10 @@ func TestRewardCalculation_1_2(t *testing.T) { } current += 100 - state.AddStake(12, testutils.TestAddress("bob"), 100, uint64(current), make(map[string]uint64)) + state.addStake(12, testutils.TestAddress("bob"), 100, uint64(current), make(map[string]uint64)) current += 100 - reward, _ = state.RemoveStake(testutils.TestAddress("bob"), 100, uint64(current), make(map[string]uint64)) + reward, _ = state.removeStake(testutils.TestAddress("bob"), 100, uint64(current), make(map[string]uint64)) current -= int(reward) if reward != 100+100 { t.Errorf("expected reward %d, got %d", 100+100, reward) @@ -50,15 +50,15 @@ func TestRewardCalculation_1_3(t *testing.T) { // Alice takes 100 GNS current := 100 - state.AddStake(10, testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) + state.addStake(10, testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) // Alice takes 100 GNS current += 100 - state.AddStake(11, testutils.TestAddress("bob"), 10, uint64(current), make(map[string]uint64)) + state.addStake(11, testutils.TestAddress("bob"), 10, uint64(current), make(map[string]uint64)) // Alice takes 50 GNS, Bob takes 50 GNS current += 100 - reward, _ := state.RemoveStake(testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) + reward, _ := state.removeStake(testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) current -= int(reward) if reward != 100+100+50 { t.Errorf("expected reward %d, got %d", 100+100+50, reward) @@ -66,32 +66,31 @@ func TestRewardCalculation_1_3(t *testing.T) { // Bob takes 100 GNS current += 100 - reward, _ = state.RemoveStake(testutils.TestAddress("bob"), 10, uint64(current), make(map[string]uint64)) + reward, _ = state.removeStake(testutils.TestAddress("bob"), 10, uint64(current), make(map[string]uint64)) current -= int(reward) if reward != 100+50 { t.Errorf("expected reward %d, got %d", 100+50, reward) } } - func TestRewardCalculation_1_4(t *testing.T) { state := NewRewardState() // Alice takes 100 GNS current := 100 - state.AddStake(10, testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) + state.addStake(10, testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) // Alice takes 200GNS current += 200 - state.AddStake(11, testutils.TestAddress("bob"), 30, uint64(current), make(map[string]uint64)) + state.addStake(11, testutils.TestAddress("bob"), 30, uint64(current), make(map[string]uint64)) // Alice 25, Bob 75 current += 100 - state.AddStake(12, testutils.TestAddress("charlie"), 10, uint64(current), make(map[string]uint64)) + state.addStake(12, testutils.TestAddress("charlie"), 10, uint64(current), make(map[string]uint64)) // Alice 20, Bob 60, Charlie 20 current += 100 - reward, _ := state.RemoveStake(testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) + reward, _ := state.removeStake(testutils.TestAddress("alice"), 10, uint64(current), make(map[string]uint64)) current -= int(reward) if reward != 100+200+25+20 { t.Errorf("expected reward %d, got %d", 100+200+25+20, reward) @@ -99,7 +98,7 @@ func TestRewardCalculation_1_4(t *testing.T) { // Bob 75, Charlie 25 current += 100 - reward, _ = state.RemoveStake(testutils.TestAddress("bob"), 30, uint64(current), make(map[string]uint64)) + reward, _ = state.removeStake(testutils.TestAddress("bob"), 30, uint64(current), make(map[string]uint64)) current -= int(reward) if reward != 75+60+75 { t.Errorf("expected reward %d, got %d", 75+60+75, reward) diff --git a/contract/r/gnoswap/gov/staker/staker.gno b/contract/r/gnoswap/gov/staker/staker.gno index 8aa965eff..3b0f0c1f5 100644 --- a/contract/r/gnoswap/gov/staker/staker.gno +++ b/contract/r/gnoswap/gov/staker/staker.gno @@ -80,7 +80,7 @@ func Delegate(to std.Address, amount uint64) { )) } - rewardState.AddStake(uint64(std.GetHeight()), caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) + rewardState.addStake(uint64(std.GetHeight()), caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) // GNS // caller -> GovStaker gns.TransferFrom(caller, std.CurrentRealm().Addr(), amount) @@ -201,7 +201,7 @@ func Undelegate(from std.Address, amount uint64) { )) } - reward, protocolFeeRewards := rewardState.RemoveStake(caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) + reward, protocolFeeRewards := rewardState.removeStake(caller, amount, getCurrentBalance(), getCurrentProtocolFeeBalance()) // burn equivalent amount of xGNS xgns.Burn(caller, amount) @@ -306,7 +306,7 @@ func CollectReward() { prevAddr, prevPkgPath := getPrev() caller := std.PrevRealm().Addr() - reward, protocolFeeRewards := rewardState.Claim(caller, getCurrentBalance(), getCurrentProtocolFeeBalance()) + reward, protocolFeeRewards := rewardState.claim(caller, getCurrentBalance(), getCurrentProtocolFeeBalance()) // XXX (@notJoon): There could be cases where the reward pool is empty, In such case, // it seems appropriate to return 0 and continue processing. @@ -372,7 +372,7 @@ func CollectRewardFromLaunchPad(to std.Address) { prevAddr, prevPkgPath := getPrev() - emissionReward, protocolFeeRewards := rewardState.Claim(to, getCurrentBalance(), getCurrentProtocolFeeBalance()) + emissionReward, protocolFeeRewards := rewardState.claim(to, getCurrentBalance(), getCurrentProtocolFeeBalance()) if emissionReward > 0 { gns.Transfer(to, emissionReward) std.Emit( diff --git a/contract/r/gnoswap/gov/staker/staker_test.gno b/contract/r/gnoswap/gov/staker/staker_test.gno index 615b072d9..516308b11 100644 --- a/contract/r/gnoswap/gov/staker/staker_test.gno +++ b/contract/r/gnoswap/gov/staker/staker_test.gno @@ -483,7 +483,7 @@ func TestCollectReward(t *testing.T) { std.TestSetRealm(user2Realm) user := user2Realm.Addr().String() - rewardState.AddStake(uint64(std.GetHeight()), std.Address(user), 10, 0, make(map[string]uint64)) + rewardState.addStake(uint64(std.GetHeight()), std.Address(user), 10, 0, make(map[string]uint64)) // set a fake emission reward //userEmissionReward.Set(user, uint64(50_000)) diff --git a/contract/r/gnoswap/launchpad/api_deposit.gno b/contract/r/gnoswap/launchpad/api_deposit.gno index 15f3a1417..f587cb4b1 100644 --- a/contract/r/gnoswap/launchpad/api_deposit.gno +++ b/contract/r/gnoswap/launchpad/api_deposit.gno @@ -32,7 +32,7 @@ func ApiGetClaimableDepositByAddress(address std.Address) uint64 { } rwd, _ := rewardStates.Get(deposit.projectId, deposit.tier) - reward := rwd.Claim(depositId, uint64(std.GetHeight())) + reward := rwd.claim(depositId, uint64(std.GetHeight())) gnsToUser += reward } diff --git a/contract/r/gnoswap/launchpad/deposit.gno b/contract/r/gnoswap/launchpad/deposit.gno index 2402fd9fa..ff6bcf5c4 100644 --- a/contract/r/gnoswap/launchpad/deposit.gno +++ b/contract/r/gnoswap/launchpad/deposit.gno @@ -136,7 +136,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string { // update StartHeight, StartTime, TierAmountPerBlockX128 tier.updateStarted(info.CurrentHeight, info.CurrentTime) duration := tier.Ended().height - info.CurrentHeight - tier.SetTierAmountPerBlockX128(calcRewardPerBlockX128(tier.TierAmount(), duration)) + tier.setTierAmountPerBlockX128(calcRewardPerBlockX128(tier.TierAmount(), duration)) prevAddr, prevPkgPath := getPrev() std.Emit( @@ -152,7 +152,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string { ) rewardState := NewRewardState(tier.tierAmountPerBlockX128, tier.started.height, tier.ended.height) - rewardStates.Set(info.Project.id, info.TierType, rewardState) + rewardStates.set(info.Project.id, info.TierType, rewardState) } reward := tier.Reward() @@ -161,7 +161,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string { panic(err.Error()) } reward.addRewardPerDeposit(rewardPerDeposit) - reward.SetLastHeight(currentHeight) + reward.setLastHeight(currentHeight) rewardInfo := NewRewardInfo( reward.AccumRewardPerDeposit(), @@ -172,17 +172,17 @@ func DepositGns(targetProjectTierId string, amount uint64) string { tier.Ended().height, currentHeight) reward.Info().Set(deposit.ID(), rewardInfo) - tier.SetReward(reward) - tier.SetTotalDepositAmount(tier.TotalDepositAmount() + amount) - tier.SetActualDepositAmount(tier.ActualDepositAmount() + amount) - tier.SetTotalParticipant(tier.TotalParticipant() + 1) - tier.SetActualParticipant(tier.ActualParticipant() + 1) + tier.setReward(reward) + tier.setTotalDepositAmount(tier.TotalDepositAmount() + amount) + tier.setActualDepositAmount(tier.ActualDepositAmount() + amount) + tier.setTotalParticipant(tier.TotalParticipant() + 1) + tier.setActualParticipant(tier.ActualParticipant() + 1) project.setTier(convertTierTypeStrToUint64(tierType), tier) - project.Stats().SetTotalDeposit(project.Stats().TotalDeposit() + amount) - project.Stats().SetActualDeposit(project.Stats().ActualDeposit() + amount) - project.Stats().SetTotalParticipant(project.Stats().TotalParticipant() + 1) - project.Stats().SetActualParticipant(project.Stats().ActualParticipant() + 1) + project.Stats().setTotalDeposit(project.Stats().TotalDeposit() + amount) + project.Stats().setActualDeposit(project.Stats().ActualDeposit() + amount) + project.Stats().setTotalParticipant(project.Stats().TotalParticipant() + 1) + project.Stats().setActualParticipant(project.Stats().ActualParticipant() + 1) projects[projectId] = project @@ -191,7 +191,7 @@ func DepositGns(targetProjectTierId string, amount uint64) string { panic(addDetailToError( errInvalidRewardState, err.Error())) } - rewardState.AddStake(uint64(std.GetHeight()), deposit.id, amount) + rewardState.addStake(uint64(std.GetHeight()), deposit.id, amount) // Update gov_staker to calculate project's recipient's reward gs.SetAmountByProjectWallet(project.recipient, amount, true) @@ -783,20 +783,20 @@ func processDepositCollection( continue } - deposit.SetDepositCollectHeight(currentHeight) - deposit.SetDepositCollectTime(now) + deposit.setDepositCollectHeight(currentHeight) + deposit.setDepositCollectTime(now) deposits[deposit.id] = deposit totalAmount += deposit.amount gs.SetAmountByProjectWallet(project.recipient, deposit.amount, false) - tier.SetActualDepositAmount(tier.ActualDepositAmount() - deposit.amount) - tier.SetActualParticipant(tier.ActualParticipant() - 1) + tier.setActualDepositAmount(tier.ActualDepositAmount() - deposit.amount) + tier.setActualParticipant(tier.ActualParticipant() - 1) project.setTier(convertTierTypeStrToUint64(deposit.tier), tier) - project.Stats().SetActualDeposit(project.Stats().actualDeposit - deposit.amount) - project.Stats().SetActualParticipant(project.Stats().actualParticipant - 1) + project.Stats().setActualDeposit(project.Stats().actualDeposit - deposit.amount) + project.Stats().setActualParticipant(project.Stats().actualParticipant - 1) projects[deposit.projectId] = project @@ -899,18 +899,18 @@ func processDeposit(deposit *Deposit, project *Project, height uint64) (uint64, } // Update deposit status - deposit.SetDepositCollectHeight(height) - deposit.SetDepositCollectTime(uint64(time.Now().Unix())) + deposit.setDepositCollectHeight(height) + deposit.setDepositCollectTime(uint64(time.Now().Unix())) deposits[deposit.id] = *deposit // Update project tier - tier.SetActualDepositAmount(tier.ActualDepositAmount() - deposit.amount) - tier.SetActualParticipant(tier.ActualParticipant() - 1) + tier.setActualDepositAmount(tier.ActualDepositAmount() - deposit.amount) + tier.setActualParticipant(tier.ActualParticipant() - 1) // Update project project.setTier(convertTierTypeStrToUint64(deposit.tier), tier) - project.Stats().SetActualDeposit(project.Stats().actualDeposit - deposit.amount) - project.Stats().SetActualParticipant(project.Stats().actualParticipant - 1) + project.Stats().setActualDeposit(project.Stats().actualDeposit - deposit.amount) + project.Stats().setActualParticipant(project.Stats().actualParticipant - 1) projects[deposit.projectId] = *project diff --git a/contract/r/gnoswap/launchpad/launchpad.gno b/contract/r/gnoswap/launchpad/launchpad.gno index 9cfb2754f..11280490c 100644 --- a/contract/r/gnoswap/launchpad/launchpad.gno +++ b/contract/r/gnoswap/launchpad/launchpad.gno @@ -663,7 +663,7 @@ func createTier( } rewardState := NewRewardState(tier.tierAmountPerBlockX128, startHeight, endHeight) - rewardStates.Set(projectId, strconv.FormatUint(duration, 10), rewardState) + rewardStates.set(projectId, strconv.FormatUint(duration, 10), rewardState) projectTiersWithoutDeposit[tierId] = true return tier diff --git a/contract/r/gnoswap/launchpad/launchpad_test.gno b/contract/r/gnoswap/launchpad/launchpad_test.gno index 4fd4a8b6e..0184c0b11 100644 --- a/contract/r/gnoswap/launchpad/launchpad_test.gno +++ b/contract/r/gnoswap/launchpad/launchpad_test.gno @@ -496,21 +496,21 @@ func TestProject_GetSet(t *testing.T) { t.Errorf("NewProject Refund mismatch, got=%d", refund.Amount()) } - p.SetID("pid2") + p.setID("pid2") if p.ID() != "pid2" { - t.Errorf("SetID failed, got=%s", p.ID()) + t.Errorf("setID failed, got=%s", p.ID()) } - p.SetName("MyProject2") + p.setName("MyProject2") if p.Name() != "MyProject2" { - t.Errorf("SetName failed, got=%s", p.Name()) + t.Errorf("setName failed, got=%s", p.Name()) } - p.SetTokenPath("new/tokenPath") + p.setTokenPath("new/tokenPath") if p.TokenPath() != "new/tokenPath" { - t.Errorf("SetTokenPath failed, got=%s", p.TokenPath()) + t.Errorf("setTokenPath failed, got=%s", p.TokenPath()) } - p.SetDepositAmount(2000) + p.setDepositAmount(2000) if p.DepositAmount() != 2000 { - t.Errorf("SetDepositAmount failed, got=%d", p.DepositAmount()) + t.Errorf("setDepositAmount failed, got=%d", p.DepositAmount()) } t.Run("TestProject_isActivated", func(t *testing.T) { now := uint64(1) @@ -583,17 +583,17 @@ func TestTier_GetSet(t *testing.T) { t.Errorf("Tier CalculatedAmount mismatch, got=%d", tr.CalculatedAmount()) } - tr.SetID("tierIdNew") + tr.setID("tierIdNew") if tr.ID() != "tierIdNew" { - t.Errorf("SetID failed, got=%s", tr.ID()) + t.Errorf("setID failed, got=%s", tr.ID()) } - tr.SetTierAmount(999) + tr.setTierAmount(999) if tr.TierAmount() != 999 { - t.Errorf("SetTierAmount failed, got=%d", tr.TierAmount()) + t.Errorf("setTierAmount failed, got=%d", tr.TierAmount()) } - tr.SetActualDepositAmount(777) + tr.setActualDepositAmount(777) if tr.ActualDepositAmount() != 777 { - t.Errorf("SetActualDepositAmount failed, got=%d", tr.ActualDepositAmount()) + t.Errorf("setActualDepositAmount failed, got=%d", tr.ActualDepositAmount()) } } @@ -623,13 +623,13 @@ func TestRewardInfo_GetSet(t *testing.T) { if ri.GetLastHeight() != 777 { t.Errorf("LastHeight mismatch, got=%d", ri.GetLastHeight()) } - ri.SetPriceDebt(u256.NewUint(999)) + ri.setPriceDebt(u256.NewUint(999)) if ri.PriceDebt().ToString() != "999" { - t.Errorf("SetPriceDebt failed, got=%s", ri.PriceDebt().ToString()) + t.Errorf("setPriceDebt failed, got=%s", ri.PriceDebt().ToString()) } - ri.SetRewardAmount(1234) + ri.setRewardAmount(1234) if ri.RewardAmount() != 1234 { - t.Errorf("SetRewardAmount failed, got=%d", ri.RewardAmount()) + t.Errorf("setRewardAmount failed, got=%d", ri.RewardAmount()) } } @@ -643,13 +643,13 @@ func TestTimeInfo_GetSet(t *testing.T) { t.Errorf("Time mismatch, got=%d", ti.Time()) } - ti.SetHeight(100) - ti.SetTime(9999) + ti.setHeight(100) + ti.setTime(9999) if ti.Height() != 100 { - t.Errorf("SetHeight failed, got=%d", ti.Height()) + t.Errorf("setHeight failed, got=%d", ti.Height()) } if ti.Time() != 9999 { - t.Errorf("SetTime failed, got=%d", ti.Time()) + t.Errorf("setTime failed, got=%d", ti.Time()) } } @@ -665,17 +665,17 @@ func TestRefundInfo_GetSet(t *testing.T) { t.Errorf("Time mismatch, got=%d", ri.Time()) } - ri.SetAmount(111) - ri.SetHeight(222) - ri.SetTime(333) + ri.setAmount(111) + ri.setHeight(222) + ri.setTime(333) if ri.Amount() != 111 { - t.Errorf("SetAmount failed, got=%d", ri.Amount()) + t.Errorf("setAmount failed, got=%d", ri.Amount()) } if ri.Height() != 222 { - t.Errorf("SetHeight failed, got=%d", ri.Height()) + t.Errorf("setHeight failed, got=%d", ri.Height()) } if ri.Time() != 333 { - t.Errorf("SetTime failed, got=%d", ri.Time()) + t.Errorf("setTime failed, got=%d", ri.Time()) } } @@ -688,13 +688,13 @@ func TestCondition_GetSet(t *testing.T) { t.Errorf("Condition MinAmount mismatch, got=%d", c.MinAmount()) } - c.SetTokenPath("new/token") + c.setTokenPath("new/token") if c.TokenPath() != "new/token" { - t.Errorf("SetTokenPath failed, got=%s", c.TokenPath()) + t.Errorf("setTokenPath failed, got=%s", c.TokenPath()) } - c.SetMinAmount(2000) + c.setMinAmount(2000) if c.MinAmount() != 2000 { - t.Errorf("SetMinAmount failed, got=%d", c.MinAmount()) + t.Errorf("setMinAmount failed, got=%d", c.MinAmount()) } } @@ -714,13 +714,13 @@ func TestReward_GetSet(t *testing.T) { if r.Info() == nil { t.Errorf("Info mismatch, got=%v, want=not nil", r.Info()) } - r.SetAccumRewardPerDeposit(u256.NewUint(9999)) + r.setAccumRewardPerDeposit(u256.NewUint(9999)) if r.AccumRewardPerDeposit().ToString() != "9999" { - t.Errorf("SetAccumRewardPerDeposit failed, got=%s", r.AccumRewardPerDeposit().ToString()) + t.Errorf("setAccumRewardPerDeposit failed, got=%s", r.AccumRewardPerDeposit().ToString()) } - r.SetLastHeight(111) + r.setLastHeight(111) if r.GetLastHeight() != 111 { - t.Errorf("SetLastHeight failed, got=%d", r.GetLastHeight()) + t.Errorf("setLastHeight failed, got=%d", r.GetLastHeight()) } } diff --git a/contract/r/gnoswap/launchpad/reward.gno b/contract/r/gnoswap/launchpad/reward.gno index f4e29e503..fe7d29ff0 100644 --- a/contract/r/gnoswap/launchpad/reward.gno +++ b/contract/r/gnoswap/launchpad/reward.gno @@ -75,7 +75,7 @@ func CollectRewardByProjectId(projectId string) uint64 { panic(err.Error()) } reward.addRewardPerDeposit(rewardPerDeposit) - reward.SetLastHeight(currentHeight) + reward.setLastHeight(currentHeight) rewardAmount := reward.deductReward(depositId, currentHeight) if rewardAmount == 0 { continue @@ -97,9 +97,9 @@ func CollectRewardByProjectId(projectId string) uint64 { project.setTier(convertTierTypeStrToUint64(deposit.Tier()), tier) // Update deposit - deposit.SetRewardCollected(deposit.RewardCollected() + rewardAmount) - deposit.SetRewardCollectHeight(currentHeight) - deposit.SetRewardCollectTime(uint64(time.Now().Unix())) + deposit.setRewardCollected(deposit.RewardCollected() + rewardAmount) + deposit.setRewardCollectHeight(currentHeight) + deposit.setRewardCollectTime(uint64(time.Now().Unix())) deposits[depositId] = deposit } @@ -151,14 +151,14 @@ func CollectRewardByDepositId(depositId string) uint64 { panic(err.Error()) } reward.addRewardPerDeposit(rewardPerDeposit) - reward.SetLastHeight(currentHeight) + reward.setLastHeight(currentHeight) rewardAmount := reward.deductReward(depositId, currentHeight) if rewardAmount == 0 { panic(addDetailToError(errAlreadyCollected, ufmt.Sprintf("depositId(%s)", depositId))) } - tier.SetReward(reward) + tier.setReward(reward) tier.userCollectedAmount += rewardAmount project.Stats().totalCollected += rewardAmount @@ -174,9 +174,9 @@ func CollectRewardByDepositId(depositId string) uint64 { project.setTier(convertTierTypeStrToUint64(deposit.Tier()), tier) // Update deposit - deposit.SetRewardCollected(deposit.RewardCollected() + rewardAmount) - deposit.SetRewardCollectHeight(currentHeight) - deposit.SetRewardCollectTime(uint64(time.Now().Unix())) + deposit.setRewardCollected(deposit.RewardCollected() + rewardAmount) + deposit.setRewardCollectHeight(currentHeight) + deposit.setRewardCollectTime(uint64(time.Now().Unix())) deposits[depositId] = deposit projects[deposit.projectId] = project diff --git a/contract/r/gnoswap/launchpad/reward_calculation.gno b/contract/r/gnoswap/launchpad/reward_calculation.gno index befe51214..b73d3b72a 100644 --- a/contract/r/gnoswap/launchpad/reward_calculation.gno +++ b/contract/r/gnoswap/launchpad/reward_calculation.gno @@ -75,12 +75,12 @@ func (states RewardStates) Get(projectId string, tierStr string) (*RewardState, return statesI.(*RewardState), nil } -func (states RewardStates) Set(projectId string, tierStr string, state *RewardState) { +func (states RewardStates) set(projectId string, tierStr string, state *RewardState) { key := projectId + ":" + tierStr states.states.Set(key, state) } -func (states RewardStates) DeleteProject(projectId string) uint64 { +func (states RewardStates) deleteProject(projectId string) uint64 { totalLeftover := uint64(0) keys := []string{} states.states.Iterate(projectId+":", projectId+";", func(key string, value interface{}) bool { @@ -154,7 +154,7 @@ func (self *RewardState) deductReward(depositId string, currentHeight uint64) ui return reward64 } -// This function MUST be called as a part of AddStake or RemoveStake +// This function MUST be called as a part of addStake or removeStake // CurrentBalance / StakeChange / IsRemoveStake will be updated in those functions func (self *RewardState) finalize(currentHeight uint64) { if currentHeight <= self.LastHeight { @@ -184,7 +184,7 @@ func (self *RewardState) finalize(currentHeight uint64) { self.LastHeight = currentHeight } -func (self *RewardState) AddStake(currentHeight uint64, depositId string, amount uint64) { +func (self *RewardState) addStake(currentHeight uint64, depositId string, amount uint64) { if self.info.Has(depositId) { panic(addDetailToError( errAlreadyExistDeposit, @@ -215,7 +215,7 @@ func (self *RewardState) AddStake(currentHeight uint64, depositId string, amount self.info.Set(depositId, info) } -func (self *RewardState) Claim(depositId string, currentHeight uint64) uint64 { +func (self *RewardState) claim(depositId string, currentHeight uint64) uint64 { if !self.info.Has(depositId) { panic(addDetailToError( errNotExistDeposit, @@ -229,7 +229,7 @@ func (self *RewardState) Claim(depositId string, currentHeight uint64) uint64 { return reward } -func (self *RewardState) RemoveStake(depositId string, amount uint64, currentHeight uint64) uint64 { +func (self *RewardState) removeStake(depositId string, amount uint64, currentHeight uint64) uint64 { if !self.info.Has(depositId) { panic(addDetailToError( errNotExistDeposit, diff --git a/contract/r/gnoswap/launchpad/reward_calculation_test.gno b/contract/r/gnoswap/launchpad/reward_calculation_test.gno index 4efa1f7d8..04b05903c 100644 --- a/contract/r/gnoswap/launchpad/reward_calculation_test.gno +++ b/contract/r/gnoswap/launchpad/reward_calculation_test.gno @@ -18,16 +18,16 @@ func TestRewardState_BasicFlow(t *testing.T) { currentHeight := uint64(150) depositId := "deposit1" stakeAmount := uint64(500) - state.AddStake(currentHeight, depositId, stakeAmount) + state.addStake(currentHeight, depositId, stakeAmount) uassert.Equal(t, state.TotalStake, stakeAmount, ufmt.Sprintf("TotalStake = %d, want %d", state.TotalStake, stakeAmount)) claimHeight := uint64(200) - reward := state.Claim(depositId, claimHeight) + reward := state.claim(depositId, claimHeight) uassert.NotEqual(t, reward, uint64(0), "Expected non-zero reward") removeHeight := uint64(250) - finalReward := state.RemoveStake(depositId, stakeAmount, removeHeight) + finalReward := state.removeStake(depositId, stakeAmount, removeHeight) uassert.Equal(t, state.TotalStake, uint64(0), ufmt.Sprintf("TotalStake after removal = %d, want 0", state.TotalStake)) } @@ -35,17 +35,17 @@ func TestRewardState_MultipleStakers(t *testing.T) { rewardPerBlock := u256.NewUint(1000).Lsh(u256.NewUint(1000), 128) state := NewRewardState(rewardPerBlock, 100, 1000) - state.AddStake(150, "deposit1", 300) - state.AddStake(160, "deposit2", 200) + state.addStake(150, "deposit1", 300) + state.addStake(160, "deposit2", 200) uassert.Equal(t, state.TotalStake, uint64(500), ufmt.Sprintf("TotalStake = %d, want 500", state.TotalStake)) // check first staker's reward - reward1 := state.Claim("deposit1", 200) + reward1 := state.claim("deposit1", 200) uassert.NotEqual(t, reward1, uint64(0), "Expected non-zero reward for deposit1") // check 2nd staker's reward - reward2 := state.Claim("deposit2", 200) + reward2 := state.claim("deposit2", 200) uassert.NotEqual(t, reward2, uint64(0), "Expected non-zero reward for deposit2") // reward1 must be greater than reward2 @@ -64,7 +64,7 @@ func TestRewardState_EmptyBlocks(t *testing.T) { uassert.Equal(t, state.TotalEmptyBlock, uint64(100), ufmt.Sprintf("TotalEmptyBlock = %d, want 100", state.TotalEmptyBlock)) // block cound must be stopped when staker added - state.AddStake(250, "deposit1", 100) + state.addStake(250, "deposit1", 100) state.finalize(300) uassert.Equal(t, state.TotalEmptyBlock, uint64(150), ufmt.Sprintf("TotalEmptyBlock after staking = %d, want 150", state.TotalEmptyBlock)) @@ -77,13 +77,13 @@ func TestRewardState_EndHeightBehavior(t *testing.T) { state := NewRewardState(rewardPerBlock, startHeight, endHeight) // stake before endHeight - state.AddStake(150, "deposit1", 100) + state.addStake(150, "deposit1", 100) // claim after endHeight - reward := state.Claim("deposit1", 250) + reward := state.claim("deposit1", 250) // must be no additional reward after endHeight - secondReward := state.Claim("deposit1", 300) + secondReward := state.claim("deposit1", 300) uassert.Equal(t, secondReward, uint64(0), ufmt.Sprintf("Got reward after endHeight: %d, want 0", secondReward)) } @@ -92,11 +92,11 @@ func TestRewardState_PartialStakeRemoval(t *testing.T) { rewardPerBlock := u256.NewUint(1000).Lsh(u256.NewUint(1000), 128) state := NewRewardState(rewardPerBlock, 100, 1000) - state.AddStake(150, "deposit1", 500) + state.addStake(150, "deposit1", 500) // checking reward after partial removal - reward1 := state.RemoveStake("deposit1", 200, 200) - reward2 := state.Claim("deposit1", 250) + reward1 := state.removeStake("deposit1", 200, 200) + reward2 := state.claim("deposit1", 250) uassert.Equal(t, state.TotalStake, uint64(300), ufmt.Sprintf("TotalStake after partial removal = %d, want 300", state.TotalStake)) } @@ -106,16 +106,16 @@ func TestRewardState_BoundaryCases(t *testing.T) { state := NewRewardState(rewardPerBlock, 100, 1000) // stake before startHeight - state.AddStake(50, "deposit1", 100) + state.addStake(50, "deposit1", 100) if state.LastHeight != 100 { t.Errorf("LastHeight = %d, want 100", state.LastHeight) } - state.AddStake(150, "deposit2", 1) - state.AddStake(150, "deposit3", ^uint64(0)-1) + state.addStake(150, "deposit2", 1) + state.addStake(150, "deposit3", ^uint64(0)-1) - reward1 := state.Claim("deposit2", 200) - reward2 := state.Claim("deposit2", 200) + reward1 := state.claim("deposit2", 200) + reward2 := state.claim("deposit2", 200) uassert.Equal(t, reward2, uint64(0), ufmt.Sprintf("Second claim at same height should be 0, got %d", reward2)) } @@ -124,11 +124,11 @@ func TestRewardState_MultipleStakesFromSameUser(t *testing.T) { state := NewRewardState(rewardPerBlock, 100, 1000) // stake from the same user at different times - state.AddStake(150, "user1_deposit1", 200) - state.AddStake(200, "user1_deposit2", 300) + state.addStake(150, "user1_deposit1", 200) + state.addStake(200, "user1_deposit2", 300) - reward1 := state.Claim("user1_deposit1", 250) - reward2 := state.Claim("user1_deposit2", 250) + reward1 := state.claim("user1_deposit1", 250) + reward2 := state.claim("user1_deposit2", 250) uassert.NotEqual(t, reward1, uint64(0), "First deposit should have rewards") uassert.NotEqual(t, reward2, uint64(0), "Second deposit should have rewards") @@ -138,11 +138,11 @@ func TestRewardState_RewardCalculationAccuracy(t *testing.T) { rewardPerBlock := u256.NewUint(1000).Lsh(u256.NewUint(1000), 128) state := NewRewardState(rewardPerBlock, 100, 1000) - state.AddStake(150, "deposit1", 100) - state.AddStake(150, "deposit2", 100) + state.addStake(150, "deposit1", 100) + state.addStake(150, "deposit2", 100) - reward1 := state.Claim("deposit1", 200) - reward2 := state.Claim("deposit2", 200) + reward1 := state.claim("deposit1", 200) + reward2 := state.claim("deposit2", 200) // in a same condition, the same reward should be paid uassert.Equal(t, reward1, reward2, "Equal stakes should receive equal rewards") @@ -153,8 +153,8 @@ func TestRewardState_ZeroRewardPerBlock(t *testing.T) { rewardPerBlock := u256.Zero() state := NewRewardState(rewardPerBlock, 100, 1000) - state.AddStake(150, "deposit1", 100) - reward := state.Claim("deposit1", 200) + state.addStake(150, "deposit1", 100) + reward := state.claim("deposit1", 200) uassert.Equal(t, reward, uint64(0), "Expected zero reward when rewardPerBlock is zero") @@ -165,13 +165,13 @@ func TestRewardState_ConsecutiveStakeAndUnstake(t *testing.T) { state := NewRewardState(rewardPerBlock, 100, 1000) // Repeatedly stake and unstake - state.AddStake(150, "deposit1", 100) - state.RemoveStake("deposit1", 100, 160) + state.addStake(150, "deposit1", 100) + state.removeStake("deposit1", 100, 160) - state.AddStake(170, "deposit2", 200) - state.RemoveStake("deposit2", 200, 180) + state.addStake(170, "deposit2", 200) + state.removeStake("deposit2", 200, 180) - state.AddStake(190, "deposit3", 300) + state.addStake(190, "deposit3", 300) uassert.Equal(t, state.TotalStake, uint64(300), "Final stake amount should be correct after multiple stake/unstake operations") @@ -183,13 +183,13 @@ func TestRewardState_ClaimAtEndHeight(t *testing.T) { endHeight := uint64(200) state := NewRewardState(rewardPerBlock, startHeight, endHeight) - state.AddStake(150, "deposit1", 100) + state.addStake(150, "deposit1", 100) - // Claim exactly at endHeight - reward1 := state.Claim("deposit1", endHeight) + // claim exactly at endHeight + reward1 := state.claim("deposit1", endHeight) - // Claim after endHeight - reward2 := state.Claim("deposit1", endHeight+50) + // claim after endHeight + reward2 := state.claim("deposit1", endHeight+50) uassert.NotEqual(t, reward1, uint64(0), "Should receive rewards when claiming at endHeight") @@ -202,16 +202,16 @@ func TestRewardState_StakeChangesDuringRewardPeriod(t *testing.T) { state := NewRewardState(rewardPerBlock, 100, 1000) // First staker - state.AddStake(150, "deposit1", 1000) + state.addStake(150, "deposit1", 1000) // Second staker joins - state.AddStake(160, "deposit2", 1000) + state.addStake(160, "deposit2", 1000) // First staker removes half - reward1 := state.RemoveStake("deposit1", 500, 170) + reward1 := state.removeStake("deposit1", 500, 170) // Second staker claims - reward2 := state.Claim("deposit2", 170) + reward2 := state.claim("deposit2", 170) uassert.Equal(t, reward1, uint64(15000)) uassert.Equal(t, reward2, uint64(5000)) @@ -222,9 +222,9 @@ func TestRewardState_SmallIntervals(t *testing.T) { state := NewRewardState(rewardPerBlock, 100, 1000) // Test with consecutive block heights - state.AddStake(150, "deposit1", 100) - reward1 := state.Claim("deposit1", 151) - reward2 := state.Claim("deposit1", 152) + state.addStake(150, "deposit1", 100) + reward1 := state.claim("deposit1", 151) + reward2 := state.claim("deposit1", 152) uassert.NotEqual(t, reward1, uint64(0), "Should receive rewards for single block interval") diff --git a/contract/r/gnoswap/launchpad/reward_test.gno b/contract/r/gnoswap/launchpad/reward_test.gno index 7cedb3c85..e210f97a3 100644 --- a/contract/r/gnoswap/launchpad/reward_test.gno +++ b/contract/r/gnoswap/launchpad/reward_test.gno @@ -169,7 +169,7 @@ func TestProcessDepositReward(t *testing.T) { t.Run(tt.name, func(t *testing.T) { state := NewRewardState(tt.rewardX128, 1000, 2000) depositId := ufmt.Sprintf("depositId-%d", i) - state.AddStake(1000, depositId, tt.deposit.amount) + state.addStake(1000, depositId, tt.deposit.amount) state.TotalStake = tt.tierAmount // force overriding total stake state.finalize(1001) @@ -360,7 +360,7 @@ func TestCollectRewardByDepositId_OwnerCheck(t *testing.T) { totalDepositAmount: 100, ended: TimeInfo{height: 10000}, } - mockTier.SetReward(*mockReward) + mockTier.setReward(*mockReward) project.setTier(TIER30, *mockTier) amount := CollectRewardByDepositId("depA") diff --git a/contract/r/gnoswap/launchpad/type.gno b/contract/r/gnoswap/launchpad/type.gno index 369ac46cf..4a2037792 100644 --- a/contract/r/gnoswap/launchpad/type.gno +++ b/contract/r/gnoswap/launchpad/type.gno @@ -37,31 +37,31 @@ func NewProjectStats( func (ps *ProjectStats) TotalDeposit() uint64 { return ps.totalDeposit } -func (ps *ProjectStats) SetTotalDeposit(v uint64) { +func (ps *ProjectStats) setTotalDeposit(v uint64) { ps.totalDeposit = v } func (ps *ProjectStats) ActualDeposit() uint64 { return ps.actualDeposit } -func (ps *ProjectStats) SetActualDeposit(v uint64) { +func (ps *ProjectStats) setActualDeposit(v uint64) { ps.actualDeposit = v } func (ps *ProjectStats) TotalParticipant() uint64 { return ps.totalParticipant } -func (ps *ProjectStats) SetTotalParticipant(v uint64) { +func (ps *ProjectStats) setTotalParticipant(v uint64) { ps.totalParticipant = v } func (ps *ProjectStats) ActualParticipant() uint64 { return ps.actualParticipant } -func (ps *ProjectStats) SetActualParticipant(v uint64) { +func (ps *ProjectStats) setActualParticipant(v uint64) { ps.actualParticipant = v } func (ps *ProjectStats) TotalCollected() uint64 { return ps.totalCollected } -func (ps *ProjectStats) SetTotalCollected(v uint64) { +func (ps *ProjectStats) setTotalCollected(v uint64) { ps.totalCollected = v } @@ -113,79 +113,79 @@ func NewProject( func (p *Project) ID() string { return p.id } -func (p *Project) SetID(v string) { +func (p *Project) setID(v string) { p.id = v } func (p *Project) Name() string { return p.name } -func (p *Project) SetName(v string) { +func (p *Project) setName(v string) { p.name = v } func (p *Project) TokenPath() string { return p.tokenPath } -func (p *Project) SetTokenPath(v string) { +func (p *Project) setTokenPath(v string) { p.tokenPath = v } func (p *Project) DepositAmount() uint64 { return p.depositAmount } -func (p *Project) SetDepositAmount(v uint64) { +func (p *Project) setDepositAmount(v uint64) { p.depositAmount = v } func (p *Project) Recipient() std.Address { return p.recipient } -func (p *Project) SetRecipient(v std.Address) { +func (p *Project) setRecipient(v std.Address) { p.recipient = v } func (p *Project) Conditions() map[string]Condition { return p.conditions } -func (p *Project) SetConditions(v map[string]Condition) { +func (p *Project) setConditions(v map[string]Condition) { p.conditions = v } func (p *Project) Tiers() map[uint64]Tier { return p.tiers } -func (p *Project) SetTiers(v map[uint64]Tier) { +func (p *Project) setTiers(v map[uint64]Tier) { p.tiers = v } func (p *Project) TiersRatios() map[uint64]uint64 { return p.tiersRatios } -func (p *Project) SetTiersRatios(v map[uint64]uint64) { +func (p *Project) setTiersRatios(v map[uint64]uint64) { p.tiersRatios = v } func (p *Project) Created() TimeInfo { return p.created } -func (p *Project) SetCreated(v TimeInfo) { +func (p *Project) setCreated(v TimeInfo) { p.created = v } func (p *Project) Started() TimeInfo { return p.started } -func (p *Project) SetStarted(v TimeInfo) { +func (p *Project) setStarted(v TimeInfo) { p.started = v } func (p *Project) Ended() TimeInfo { return p.ended } -func (p *Project) SetEnded(v TimeInfo) { +func (p *Project) setEnded(v TimeInfo) { p.ended = v } func (p *Project) Stats() *ProjectStats { return &p.stats } -func (p *Project) SetStats(v ProjectStats) { +func (p *Project) setStats(v ProjectStats) { p.stats = v } func (p *Project) Refund() RefundInfo { return p.refund } -func (p *Project) SetRefund(v RefundInfo) { +func (p *Project) setRefund(v RefundInfo) { p.refund = v } func (p *Project) Tier(key uint64) (Tier, error) { @@ -280,79 +280,79 @@ func NewTier( func (t *Tier) ID() string { return t.id } -func (t *Tier) SetID(v string) { +func (t *Tier) setID(v string) { t.id = v } func (t *Tier) CollectWaitDuration() uint64 { return t.collectWaitDuration } -func (t *Tier) SetCollectWaitDuration(v uint64) { +func (t *Tier) setCollectWaitDuration(v uint64) { t.collectWaitDuration = v } func (t *Tier) TierAmount() uint64 { return t.tierAmount } -func (t *Tier) SetTierAmount(v uint64) { +func (t *Tier) setTierAmount(v uint64) { t.tierAmount = v } func (t *Tier) TierAmountPerBlockX128() *u256.Uint { return t.tierAmountPerBlockX128 } -func (t *Tier) SetTierAmountPerBlockX128(v *u256.Uint) { +func (t *Tier) setTierAmountPerBlockX128(v *u256.Uint) { t.tierAmountPerBlockX128 = v.Clone() } func (t *Tier) Started() TimeInfo { return t.started } -func (t *Tier) SetStarted(v TimeInfo) { +func (t *Tier) setStarted(v TimeInfo) { t.started = v } func (t *Tier) Ended() TimeInfo { return t.ended } -func (t *Tier) SetEnded(v TimeInfo) { +func (t *Tier) setEnded(v TimeInfo) { t.ended = v } func (t *Tier) TotalDepositAmount() uint64 { return t.totalDepositAmount } -func (t *Tier) SetTotalDepositAmount(v uint64) { +func (t *Tier) setTotalDepositAmount(v uint64) { t.totalDepositAmount = v } func (t *Tier) ActualDepositAmount() uint64 { return t.actualDepositAmount } -func (t *Tier) SetActualDepositAmount(v uint64) { +func (t *Tier) setActualDepositAmount(v uint64) { t.actualDepositAmount = v } func (t *Tier) TotalParticipant() uint64 { return t.totalParticipant } -func (t *Tier) SetTotalParticipant(v uint64) { +func (t *Tier) setTotalParticipant(v uint64) { t.totalParticipant = v } func (t *Tier) ActualParticipant() uint64 { return t.actualParticipant } -func (t *Tier) SetActualParticipant(v uint64) { +func (t *Tier) setActualParticipant(v uint64) { t.actualParticipant = v } func (t *Tier) UserCollectedAmount() uint64 { return t.userCollectedAmount } -func (t *Tier) SetUserCollectedAmount(v uint64) { +func (t *Tier) setUserCollectedAmount(v uint64) { t.userCollectedAmount = v } func (t *Tier) CalculatedAmount() uint64 { return t.calculatedAmount } -func (t *Tier) SetCalculatedAmount(v uint64) { +func (t *Tier) setCalculatedAmount(v uint64) { t.calculatedAmount = v } func (t *Tier) Reward() Reward { return t.reward } -func (t *Tier) SetReward(v Reward) { +func (t *Tier) setReward(v Reward) { t.reward = v } func (t *Tier) isActivated(currentHeight uint64) bool { @@ -362,9 +362,9 @@ func (t *Tier) isFirstDeposit() bool { return t.totalParticipant == 0 } func (t *Tier) updateStarted(height, time uint64) { - t.started.SetHeight(height) - t.started.SetTime(time) - t.reward.SetLastHeight(height) + t.started.setHeight(height) + t.started.setTime(time) + t.reward.setLastHeight(height) } func (t *Tier) rewardPerBlockUint64() uint64 { return u256.Zero().Rsh(t.tierAmountPerBlockX128, 128).Uint64() @@ -405,43 +405,43 @@ func NewRewardInfo( func (r *RewardInfo) PriceDebt() *u256.Uint { return r.priceDebt } -func (r *RewardInfo) SetPriceDebt(v *u256.Uint) { +func (r *RewardInfo) setPriceDebt(v *u256.Uint) { r.priceDebt = v } func (r *RewardInfo) DepositAmount() uint64 { return r.depositAmount } -func (r *RewardInfo) SetDepositAmount(v uint64) { +func (r *RewardInfo) setDepositAmount(v uint64) { r.depositAmount = v } func (r *RewardInfo) RewardAmount() uint64 { return r.rewardAmount } -func (r *RewardInfo) SetRewardAmount(v uint64) { +func (r *RewardInfo) setRewardAmount(v uint64) { r.rewardAmount = v } func (r *RewardInfo) Claimed() uint64 { return r.claimed } -func (r *RewardInfo) SetClaimed(v uint64) { +func (r *RewardInfo) setClaimed(v uint64) { r.claimed = v } func (r *RewardInfo) StartHeight() uint64 { return r.startHeight } -func (r *RewardInfo) SetStartHeight(v uint64) { +func (r *RewardInfo) setStartHeight(v uint64) { r.startHeight = v } func (r *RewardInfo) GetEndHeight() uint64 { return r.EndHeight } -func (r *RewardInfo) SetEndHeight(v uint64) { +func (r *RewardInfo) setEndHeight(v uint64) { r.EndHeight = v } func (r *RewardInfo) GetLastHeight() uint64 { return r.LastHeight } -func (r *RewardInfo) SetLastHeight(v uint64) { +func (r *RewardInfo) setLastHeight(v uint64) { r.LastHeight = v } func (r *RewardInfo) calculateReward(accumRewardPerDeposit *u256.Uint) uint64 { @@ -474,25 +474,25 @@ func NewReward( func (r *Reward) AccumRewardPerDeposit() *u256.Uint { return r.accumRewardPerDeposit } -func (r *Reward) SetAccumRewardPerDeposit(v *u256.Uint) { +func (r *Reward) setAccumRewardPerDeposit(v *u256.Uint) { r.accumRewardPerDeposit = v } func (r *Reward) GetLastHeight() uint64 { return r.LastHeight } -func (r *Reward) SetLastHeight(v uint64) { +func (r *Reward) setLastHeight(v uint64) { r.LastHeight = v } func (r *Reward) GetEndHeight() uint64 { return r.EndHeight } -func (r *Reward) SetEndHeight(v uint64) { +func (r *Reward) setEndHeight(v uint64) { r.EndHeight = v } func (r *Reward) Info() *avl.Tree { return r.info } -func (r *Reward) SetInfo(v *avl.Tree) { +func (r *Reward) setInfo(v *avl.Tree) { r.info = v } func (r *Reward) accumulationRewardUint64() uint64 { @@ -539,7 +539,7 @@ func (r *Reward) addRewardPerDeposit(rewardPerDeposit *u256.Uint) { if rewardPerDeposit.IsZero() { return } - r.SetAccumRewardPerDeposit(u256.Zero().Add(r.AccumRewardPerDeposit(), rewardPerDeposit)) + r.setAccumRewardPerDeposit(u256.Zero().Add(r.AccumRewardPerDeposit(), rewardPerDeposit)) } func (r *Reward) finalize(currentHeight, totalStaked uint64, rewardPerBlock *u256.Uint) (*u256.Uint, error) { @@ -583,7 +583,7 @@ func (r *Reward) deductReward(depositId string, currentHeight uint64) uint64 { if reward64 == 0 { return 0 } - info.SetClaimed(info.Claimed() + reward64) + info.setClaimed(info.Claimed() + reward64) r.info.Set(depositId, info) return reward64 @@ -639,91 +639,91 @@ func NewDeposit( func (d *Deposit) ID() string { return d.id } -func (d *Deposit) SetID(v string) { +func (d *Deposit) setID(v string) { d.id = v } func (d *Deposit) ProjectID() string { return d.projectId } -func (d *Deposit) SetProjectID(v string) { +func (d *Deposit) setProjectID(v string) { d.projectId = v } func (d *Deposit) Tier() string { return d.tier } -func (d *Deposit) SetTier(v string) { +func (d *Deposit) setTier(v string) { d.tier = v } func (d *Deposit) Depositor() std.Address { return d.depositor } -func (d *Deposit) SetDepositor(v std.Address) { +func (d *Deposit) setDepositor(v std.Address) { d.depositor = v } func (d *Deposit) Amount() uint64 { return d.amount } -func (d *Deposit) SetAmount(v uint64) { +func (d *Deposit) setAmount(v uint64) { d.amount = v } func (d *Deposit) DepositHeight() uint64 { return d.depositHeight } -func (d *Deposit) SetDepositHeight(v uint64) { +func (d *Deposit) setDepositHeight(v uint64) { d.depositHeight = v } func (d *Deposit) DepositTime() uint64 { return d.depositTime } -func (d *Deposit) SetDepositTime(v uint64) { +func (d *Deposit) setDepositTime(v uint64) { d.depositTime = v } func (d *Deposit) DepositCollectHeight() uint64 { return d.depositCollectHeight } -func (d *Deposit) SetDepositCollectHeight(v uint64) { +func (d *Deposit) setDepositCollectHeight(v uint64) { d.depositCollectHeight = v } func (d *Deposit) DepositCollectTime() uint64 { return d.depositCollectTime } -func (d *Deposit) SetDepositCollectTime(v uint64) { +func (d *Deposit) setDepositCollectTime(v uint64) { d.depositCollectTime = v } func (d *Deposit) ClaimableHeight() uint64 { return d.claimableHeight } -func (d *Deposit) SetClaimableHeight(v uint64) { +func (d *Deposit) setClaimableHeight(v uint64) { d.claimableHeight = v } func (d *Deposit) ClaimableTime() uint64 { return d.claimableTime } -func (d *Deposit) SetClaimableTime(v uint64) { +func (d *Deposit) setClaimableTime(v uint64) { d.claimableTime = v } func (d *Deposit) RewardAmount() uint64 { return d.rewardAmount } -func (d *Deposit) SetRewardAmount(v uint64) { +func (d *Deposit) setRewardAmount(v uint64) { d.rewardAmount = v } func (d *Deposit) RewardCollected() uint64 { return d.rewardCollected } -func (d *Deposit) SetRewardCollected(v uint64) { +func (d *Deposit) setRewardCollected(v uint64) { d.rewardCollected = v } func (d *Deposit) RewardCollectHeight() uint64 { return d.rewardCollectHeight } -func (d *Deposit) SetRewardCollectHeight(v uint64) { +func (d *Deposit) setRewardCollectHeight(v uint64) { d.rewardCollectHeight = v } func (d *Deposit) RewardCollectTime() uint64 { return d.rewardCollectTime } -func (d *Deposit) SetRewardCollectTime(v uint64) { +func (d *Deposit) setRewardCollectTime(v uint64) { d.rewardCollectTime = v } func (d *Deposit) isClaimable(currentHeight uint64) bool { @@ -746,13 +746,13 @@ func NewTimeInfo(height, t uint64) TimeInfo { func (ti *TimeInfo) Height() uint64 { return ti.height } -func (ti *TimeInfo) SetHeight(v uint64) { +func (ti *TimeInfo) setHeight(v uint64) { ti.height = v } func (ti *TimeInfo) Time() uint64 { return ti.time } -func (ti *TimeInfo) SetTime(v uint64) { +func (ti *TimeInfo) setTime(v uint64) { ti.time = v } @@ -774,19 +774,19 @@ func NewRefundInfo(amount, height, t uint64) RefundInfo { func (ri *RefundInfo) Amount() uint64 { return ri.amount } -func (ri *RefundInfo) SetAmount(v uint64) { +func (ri *RefundInfo) setAmount(v uint64) { ri.amount = v } func (ri *RefundInfo) Height() uint64 { return ri.height } -func (ri *RefundInfo) SetHeight(v uint64) { +func (ri *RefundInfo) setHeight(v uint64) { ri.height = v } func (ri *RefundInfo) Time() uint64 { return ri.time } -func (ri *RefundInfo) SetTime(v uint64) { +func (ri *RefundInfo) setTime(v uint64) { ri.time = v } @@ -806,12 +806,12 @@ func NewCondition(tokenPath string, minAmount uint64) Condition { func (c *Condition) TokenPath() string { return c.tokenPath } -func (c *Condition) SetTokenPath(v string) { +func (c *Condition) setTokenPath(v string) { c.tokenPath = v } func (c *Condition) MinAmount() uint64 { return c.minAmount } -func (c *Condition) SetMinAmount(v uint64) { +func (c *Condition) setMinAmount(v uint64) { c.minAmount = v } diff --git a/contract/r/gnoswap/pool/protocol_fee_withdrawal.gno b/contract/r/gnoswap/pool/protocol_fee_withdrawal.gno index 3e88bfc86..b57a391bd 100644 --- a/contract/r/gnoswap/pool/protocol_fee_withdrawal.gno +++ b/contract/r/gnoswap/pool/protocol_fee_withdrawal.gno @@ -28,9 +28,9 @@ const ( // Input: // - positionId: the id of the LP token // - token0Path: the path of the token0 -// - _amount0: the amount of token0 +// - amount0: the amount of token0 // - token1Path: the path of the token1 -// - _amount1: the amount of token1 +// - amount1: the amount of token1 // - poolPath: the path of the pool // - positionCaller: the original caller of the position contract // Output: diff --git a/contract/r/gnoswap/pool/swap.gno b/contract/r/gnoswap/pool/swap.gno index 0f651fb89..d5ab633e7 100644 --- a/contract/r/gnoswap/pool/swap.gno +++ b/contract/r/gnoswap/pool/swap.gno @@ -367,14 +367,14 @@ func computeSwapStep( // update global fee tracker if newState.liquidity.Gt(u256.Zero()) { update := u256.MulDiv(step.feeAmount, fixedPointQ128, newState.liquidity) - newState.SetFeeGrowthGlobalX128(new(u256.Uint).Add(newState.feeGrowthGlobalX128, update)) + newState.setFeeGrowthGlobalX128(new(u256.Uint).Add(newState.feeGrowthGlobalX128, update)) } // handling tick transitions if newState.sqrtPriceX96.Eq(step.sqrtPriceNextX96) { newState = tickTransition(step, zeroForOne, newState, pool) } else if newState.sqrtPriceX96.Neq(step.sqrtPriceStartX96) { - newState.SetTick(common.TickMathGetTickAtSqrtRatio(newState.sqrtPriceX96)) + newState.setTick(common.TickMathGetTickAtSqrtRatio(newState.sqrtPriceX96)) } return newState, nil @@ -448,7 +448,7 @@ func computeAmounts(state SwapState, sqrtRatioTargetX96 *u256.Uint, pool *Pool, step.amountOut = u256.MustFromDecimal(amountOutStr) step.feeAmount = u256.MustFromDecimal(feeAmountStr) - state.SetSqrtPriceX96(sqrtPriceX96Str) + state.setSqrtPriceX96(sqrtPriceX96Str) return state, step } diff --git a/contract/r/gnoswap/pool/type.gno b/contract/r/gnoswap/pool/type.gno index 439277b9d..78b60ed71 100644 --- a/contract/r/gnoswap/pool/type.gno +++ b/contract/r/gnoswap/pool/type.gno @@ -155,19 +155,19 @@ func newSwapState( } } -func (s *SwapState) SetSqrtPriceX96(sqrtPriceX96 string) { +func (s *SwapState) setSqrtPriceX96(sqrtPriceX96 string) { s.sqrtPriceX96 = u256.MustFromDecimal(sqrtPriceX96) } -func (s *SwapState) SetTick(tick int32) { +func (s *SwapState) setTick(tick int32) { s.tick = tick } -func (s *SwapState) SetFeeGrowthGlobalX128(feeGrowthGlobalX128 *u256.Uint) { +func (s *SwapState) setFeeGrowthGlobalX128(feeGrowthGlobalX128 *u256.Uint) { s.feeGrowthGlobalX128 = feeGrowthGlobalX128 } -func (s *SwapState) SetProtocolFee(fee *u256.Uint) { +func (s *SwapState) setProtocolFee(fee *u256.Uint) { s.protocolFee = fee } diff --git a/contract/r/gnoswap/staker/_helper_test.gno b/contract/r/gnoswap/staker/_helper_test.gno index 073fc7919..57fbd5234 100644 --- a/contract/r/gnoswap/staker/_helper_test.gno +++ b/contract/r/gnoswap/staker/_helper_test.gno @@ -623,7 +623,7 @@ type ApiEmissionDebugPosition struct { func getRewardRatio(t *testing.T, height int64) uint64 { t.Helper() - warmups := InstantiateWarmup(height) + warmups := instantiateWarmup(height) for _, warmup := range warmups { if height < warmup.NextWarmupHeight { diff --git a/contract/r/gnoswap/staker/calculate_pool_position_reward.gno b/contract/r/gnoswap/staker/calculate_pool_position_reward.gno index 1d1164424..94a710241 100644 --- a/contract/r/gnoswap/staker/calculate_pool_position_reward.gno +++ b/contract/r/gnoswap/staker/calculate_pool_position_reward.gno @@ -28,7 +28,7 @@ type Reward struct { // calculate position reward by each warmup func calcPositionRewardByWarmups(currentHeight int64, positionId uint64) []Reward { - rewards := CalcPositionReward(CalcPositionRewardParam{ + rewards := calculatePositionReward(CalcPositionRewardParam{ CurrentHeight: currentHeight, Deposits: deposits, Pools: pools, @@ -41,7 +41,7 @@ func calcPositionRewardByWarmups(currentHeight int64, positionId uint64) []Rewar // calculate total position rewards and penalties func calcPositionReward(currentHeight int64, positionId uint64) Reward { - rewards := CalcPositionReward(CalcPositionRewardParam{ + rewards := calculatePositionReward(CalcPositionRewardParam{ CurrentHeight: currentHeight, Deposits: deposits, Pools: pools, @@ -97,7 +97,7 @@ type CalcPositionRewardParam struct { PositionId uint64 } -func CalcPositionReward(param CalcPositionRewardParam) []Reward { +func calculatePositionReward(param CalcPositionRewardParam) []Reward { // cache per-pool rewards in the internal incentive(tiers) param.PoolTier.cacheReward(param.CurrentHeight, param.Pools) @@ -107,7 +107,7 @@ func CalcPositionReward(param CalcPositionRewardParam) []Reward { pool, ok := param.Pools.Get(poolPath) if !ok { pool = NewPool(poolPath, param.CurrentHeight) - param.Pools.Set(poolPath, pool) + param.Pools.set(poolPath, pool) } lastCollectHeight := deposit.lastCollectHeight @@ -121,7 +121,7 @@ func CalcPositionReward(param CalcPositionRewardParam) []Reward { if param.PoolTier.CurrentTier(poolPath) != 0 { // Internal incentivized pool. // Calculate reward for each warmup - internalRewards, internalPenalties = pool.RewardStateOf(deposit).CalculateInternalReward(lastCollectHeight, param.CurrentHeight) + internalRewards, internalPenalties = pool.RewardStateOf(deposit).calculateInternalReward(lastCollectHeight, param.CurrentHeight) } // All active incentives @@ -135,7 +135,7 @@ func CalcPositionReward(param CalcPositionRewardParam) []Reward { for incentiveId, incentive := range allIncentives { // External incentivized pool. // Calculate reward for each warmup - externalReward, externalPenalty := pool.RewardStateOf(deposit).CalculateExternalReward(int64(lastCollectHeight), int64(param.CurrentHeight), incentive) + externalReward, externalPenalty := pool.RewardStateOf(deposit).calculateExternalReward(int64(lastCollectHeight), int64(param.CurrentHeight), incentive) for i := range externalReward { externalRewards[i][incentiveId] = externalReward[i] @@ -157,7 +157,7 @@ func CalcPositionReward(param CalcPositionRewardParam) []Reward { } // calculates internal unclaimable reward for the pool -func ProcessUnClaimableReward(poolPath string, endHeight int64) uint64 { +func processUnClaimableReward(poolPath string, endHeight int64) uint64 { pool, ok := pools.Get(poolPath) if !ok { return 0 diff --git a/contract/r/gnoswap/staker/protocol_fee_unstaking.gno b/contract/r/gnoswap/staker/protocol_fee_unstaking.gno index c7aac314a..a4b33ceff 100644 --- a/contract/r/gnoswap/staker/protocol_fee_unstaking.gno +++ b/contract/r/gnoswap/staker/protocol_fee_unstaking.gno @@ -104,7 +104,7 @@ func SetUnStakingFeeByAdmin(fee uint64) { panic(err.Error()) } - prevUnStakingFee := getUnStakingFee() + prevUnStakingFee := GetUnstakingFee() setUnStakingFee(fee) @@ -128,7 +128,7 @@ func SetUnStakingFee(fee uint64) { panic(err.Error()) } - prevUnStakingFee := getUnStakingFee() + prevUnStakingFee := GetUnstakingFee() setUnStakingFee(fee) @@ -154,7 +154,3 @@ func setUnStakingFee(fee uint64) { unstakingFee = fee } - -func getUnStakingFee() uint64 { - return unstakingFee -} diff --git a/contract/r/gnoswap/staker/query_test.gno b/contract/r/gnoswap/staker/query_test.gno index 0a8c3ba97..5d24f4371 100644 --- a/contract/r/gnoswap/staker/query_test.gno +++ b/contract/r/gnoswap/staker/query_test.gno @@ -15,7 +15,7 @@ func TestQueryPoolData(t *testing.T) { poolPath := "test_pool" pool := NewPool(poolPath, std.GetHeight()) - pools.Set(poolPath, pool) + pools.set(poolPath, pool) // Add test incentive to pool startTime := time.Now().Unix() @@ -63,7 +63,7 @@ func TestQueryDepositData(t *testing.T) { warmups: make([]Warmup, 2), } - deposits.Set(lpTokenId, deposit) + deposits.set(lpTokenId, deposit) // Test query data, err := QueryDepositData(lpTokenId) @@ -78,5 +78,5 @@ func TestQueryDepositData(t *testing.T) { uassert.Equal(t, data.WarmupCount, 2) // reset - deposits.Remove(lpTokenId) + deposits.remove(lpTokenId) } diff --git a/contract/r/gnoswap/staker/reward_calculation_canonical_env_test.gno b/contract/r/gnoswap/staker/reward_calculation_canonical_env_test.gno index b8055f6e9..0371ed329 100644 --- a/contract/r/gnoswap/staker/reward_calculation_canonical_env_test.gno +++ b/contract/r/gnoswap/staker/reward_calculation_canonical_env_test.gno @@ -134,7 +134,7 @@ func (self *canonicalRewardState) isInRange(deposit *Deposit) bool { } func (self *canonicalRewardState) SetEmissionUpdate(emission uint64) { - self.emissionUpdates.Set(self.CurrentHeight(), emission) + self.emissionUpdates.set(self.CurrentHeight(), emission) self.PerBlockEmission = emission } @@ -203,12 +203,12 @@ func (self *canonicalRewardState) CalculateCanonicalReward() map[uint64]Reward { } warmup := deposit.warmups[deposit.FindWarmup(int64(currentHeight))] - internal, internalPenalty := warmup.Apply(internalRewardPerPool[deposit.targetPoolPath], deposit.liquidity, liquidityPerPool[deposit.targetPoolPath]) + internal, internalPenalty := warmup.apply(internalRewardPerPool[deposit.targetPoolPath], deposit.liquidity, liquidityPerPool[deposit.targetPoolPath]) poolExternals := externalRewardPerPool[deposit.targetPoolPath] externals := make(map[string]uint64) externalPenalties := make(map[string]uint64) for key, value := range poolExternals { - external, externalPenalty := warmup.Apply(value, deposit.liquidity, liquidityPerPool[deposit.targetPoolPath]) + external, externalPenalty := warmup.apply(value, deposit.liquidity, liquidityPerPool[deposit.targetPoolPath]) externals[key] = external externalPenalties[key] = externalPenalty } @@ -278,12 +278,12 @@ func (self *canonicalRewardState) EmulateCalcPositionReward(positionId uint64) ( pool, ok := self.global.pools.Get(poolPath) if !ok { pool = NewPool(poolPath, currentHeight) - self.global.pools.Set(poolPath, pool) + self.global.pools.set(poolPath, pool) } lastCollectHeight := deposit.lastCollectHeight - internalRewards, internalPenalties := pool.RewardStateOf(deposit).CalculateInternalReward(int64(lastCollectHeight), int64(currentHeight)) + internalRewards, internalPenalties := pool.RewardStateOf(deposit).calculateInternalReward(int64(lastCollectHeight), int64(currentHeight)) externalRewards := make([]map[string]uint64, 4) externalPenalties := make([]map[string]uint64, 4) @@ -295,7 +295,7 @@ func (self *canonicalRewardState) EmulateCalcPositionReward(positionId uint64) ( allIncentives := pool.incentives.GetAllInHeights(int64(lastCollectHeight), int64(currentHeight)) for incentiveId, incentive := range allIncentives { - externalReward, externalPenalty := pool.RewardStateOf(deposit).CalculateExternalReward(int64(lastCollectHeight), int64(currentHeight), incentive) + externalReward, externalPenalty := pool.RewardStateOf(deposit).calculateExternalReward(int64(lastCollectHeight), int64(currentHeight), incentive) for i := range externalReward { externalRewards[i][incentive.incentiveId] = externalReward[i] @@ -373,7 +373,7 @@ func (self *canonicalRewardState) StakeToken(positionId uint64, targetPoolPath s tickUpper: tickUpper, liquidity: liquidity, lastCollectHeight: currentHeight, - warmups: InstantiateWarmup(currentHeight), + warmups: instantiateWarmup(currentHeight), } canonicalPool, ok := self.Pool[deposit.targetPoolPath] if !ok { @@ -384,7 +384,7 @@ func (self *canonicalRewardState) StakeToken(positionId uint64, targetPoolPath s } // update global state - self.global.deposits.Set(positionId, deposit) + self.global.deposits.set(positionId, deposit) self.global.poolTier.cacheReward(currentHeight, self.global.pools) @@ -393,7 +393,7 @@ func (self *canonicalRewardState) StakeToken(positionId uint64, targetPoolPath s pool.modifyDeposit(signedLiquidity, currentHeight, canonicalPool.tick) } // historical tick must be set regardless of the deposit's range - pool.historicalTick.Set(currentHeight, canonicalPool.tick) + pool.historicalTick.set(currentHeight, canonicalPool.tick) pool.ticks.Get(deposit.tickLower).modifyDepositLower(currentHeight, canonicalPool.tick, signedLiquidity) pool.ticks.Get(deposit.tickUpper).modifyDepositUpper(currentHeight, canonicalPool.tick, signedLiquidity) @@ -417,7 +417,7 @@ func (self *canonicalRewardState) UnstakeToken(positionId uint64) { // update global state // we will not gonna actually remove the deposit in sake of logic simplicity - self.global.deposits.Remove(positionId) + self.global.deposits.remove(positionId) pool, ok := self.global.pools.Get(deposit.targetPoolPath) if !ok { @@ -501,7 +501,7 @@ func (self *canonicalRewardState) ChangePoolTier(poolPath string, tier uint64) { // update global state if !self.global.pools.Has(poolPath) { - self.global.pools.Set(poolPath, NewPool(poolPath, self.CurrentHeight())) + self.global.pools.set(poolPath, NewPool(poolPath, self.CurrentHeight())) } self.global.poolTier.changeTier(self.CurrentHeight(), self.global.pools, poolPath, tier) } @@ -514,7 +514,7 @@ func (self *canonicalRewardState) CreatePool(poolPath string, initialTier uint64 incentive: make([]*ExternalIncentive, 0), tickCrossHook: self.tickCrossHook, } - self.global.pools.Set(poolPath, NewPool(poolPath, self.CurrentHeight())) + self.global.pools.set(poolPath, NewPool(poolPath, self.CurrentHeight())) self.global.poolTier.changeTier(self.CurrentHeight(), self.global.pools, poolPath, initialTier) } diff --git a/contract/r/gnoswap/staker/reward_calculation_incentives.gno b/contract/r/gnoswap/staker/reward_calculation_incentives.gno index 5dded0ad4..b0a46fd18 100644 --- a/contract/r/gnoswap/staker/reward_calculation_incentives.gno +++ b/contract/r/gnoswap/staker/reward_calculation_incentives.gno @@ -39,7 +39,7 @@ func NewIncentives() Incentives { } // initial unclaimable period starts, as there cannot be any staked positions yet. - result.unclaimablePeriods.Set(std.GetHeight(), int64(0)) + result.unclaimablePeriods.set(std.GetHeight(), int64(0)) return result } @@ -124,7 +124,7 @@ func (self *Incentives) create( // starts incentive unclaimable period for this pool func (self *Incentives) startUnclaimablePeriod(startHeight int64) { - self.unclaimablePeriods.Set(startHeight, int64(0)) + self.unclaimablePeriods.set(startHeight, int64(0)) } // ends incentive unclaimable period for this pool @@ -147,9 +147,9 @@ func (self *Incentives) endUnclaimablePeriod(endHeight int64) { } if startHeight == endHeight { - self.unclaimablePeriods.Remove(startHeight) + self.unclaimablePeriods.remove(startHeight) } else { - self.unclaimablePeriods.Set(startHeight, endHeight) + self.unclaimablePeriods.set(startHeight, endHeight) } } diff --git a/contract/r/gnoswap/staker/reward_calculation_pool.gno b/contract/r/gnoswap/staker/reward_calculation_pool.gno index cbf48c58c..1f36cadf6 100644 --- a/contract/r/gnoswap/staker/reward_calculation_pool.gno +++ b/contract/r/gnoswap/staker/reward_calculation_pool.gno @@ -50,13 +50,13 @@ func (self *Pools) GetOrCreate(poolPath string) *Pool { pool, ok := self.Get(poolPath) if !ok { pool = NewPool(poolPath, std.GetHeight()) - self.Set(poolPath, pool) + self.set(poolPath, pool) } return pool } -// Set sets the pool for the given poolPath -func (self *Pools) Set(poolPath string, pool *Pool) { +// set sets the pool for the given poolPath +func (self *Pools) set(poolPath string, pool *Pool) { self.tree.Set(poolPath, pool) } @@ -144,9 +144,9 @@ func NewPool(poolPath string, currentHeight int64) *Pool { historicalTick: NewUintTree(), } - pool.globalRewardRatioAccumulation.Set(currentHeight, u256.Zero()) - pool.rewardCache.Set(currentHeight, uint64(0)) - pool.stakedLiquidity.Set(currentHeight, u256.Zero()) + pool.globalRewardRatioAccumulation.set(currentHeight, u256.Zero()) + pool.rewardCache.set(currentHeight, uint64(0)) + pool.stakedLiquidity.set(currentHeight, u256.Zero()) return pool } @@ -216,7 +216,7 @@ func (self *Pool) cacheReward(currentHeight int64, currentTierReward uint64) { self.endUnclaimablePeriod(currentHeight) } - self.rewardCache.Set(currentHeight, currentTierReward) + self.rewardCache.set(currentHeight, currentTierReward) if isInUnclaimable { self.startUnclaimablePeriod(currentHeight) @@ -254,7 +254,7 @@ func (self *Pool) calculateGlobalRewardRatioAccumulation(currentHeight int64, cu func (self *Pool) updateGlobalRewardRatioAccumulation(currentHeight int64, currentStakedLiquidity *u256.Uint) *u256.Uint { newAcc := self.calculateGlobalRewardRatioAccumulation(currentHeight, currentStakedLiquidity) - self.globalRewardRatioAccumulation.Set(currentHeight, newAcc) + self.globalRewardRatioAccumulation.set(currentHeight, newAcc) return newAcc } @@ -285,30 +285,30 @@ func (self *Pool) RewardStateOf(deposit *Deposit) *RewardState { return result } -// CalculateInternalReward calculates the internal reward for the deposit. -// It calls RewardPerWarmup for each rewardCache interval, applies warmup, and returns the rewards and penalties. -func (self *RewardState) CalculateInternalReward(startHeight, endHeight int64) ([]uint64, []uint64) { +// calculateInternalReward calculates the internal reward for the deposit. +// It calls rewardPerWarmup for each rewardCache interval, applies warmup, and returns the rewards and penalties. +func (self *RewardState) calculateInternalReward(startHeight, endHeight int64) ([]uint64, []uint64) { currentReward := self.pool.CurrentReward(startHeight) self.pool.rewardCache.Iterate(startHeight, endHeight, func(key int64, value interface{}) bool { // we calculate per-position reward - self.RewardPerWarmup(startHeight, int64(key), currentReward) + self.rewardPerWarmup(startHeight, int64(key), currentReward) currentReward = value.(uint64) startHeight = int64(key) return false }) if startHeight < endHeight { - self.RewardPerWarmup(startHeight, endHeight, currentReward) + self.rewardPerWarmup(startHeight, endHeight, currentReward) } - self.ApplyWarmup() + self.applyWarmup() return self.rewards, self.penalties } -// CalculateExternalReward calculates the external reward for the deposit. -// It calls RewardPerWarmup for startHeight to endHeight(clamped to the incentive period), applies warmup and returns the rewards and penalties. -func (self *RewardState) CalculateExternalReward(startHeight, endHeight int64, incentive *ExternalIncentive) ([]uint64, []uint64) { +// calculateExternalReward calculates the external reward for the deposit. +// It calls rewardPerWarmup for startHeight to endHeight(clamped to the incentive period), applies warmup and returns the rewards and penalties. +func (self *RewardState) calculateExternalReward(startHeight, endHeight int64, incentive *ExternalIncentive) ([]uint64, []uint64) { if startHeight < int64(self.deposit.lastCollectHeight) { // This must not happen, but adding some guards just in case. startHeight = int64(self.deposit.lastCollectHeight) @@ -332,15 +332,15 @@ func (self *RewardState) CalculateExternalReward(startHeight, endHeight int64, i rewardPerBlock := incentive.rewardPerBlock - self.RewardPerWarmup(startHeight, endHeight, rewardPerBlock) + self.rewardPerWarmup(startHeight, endHeight, rewardPerBlock) - self.ApplyWarmup() + self.applyWarmup() return self.rewards, self.penalties } -// ApplyWarmup applies the warmup to the rewards and calculate penalties. -func (self *RewardState) ApplyWarmup() { +// applyWarmup applies the warmup to the rewards and calculate penalties. +func (self *RewardState) applyWarmup() { for i, warmup := range self.deposit.warmups { refactorReward := self.rewards[i] self.rewards[i] = refactorReward * warmup.WarmupRatio / 100 @@ -348,8 +348,8 @@ func (self *RewardState) ApplyWarmup() { } } -// RewardPerWarmup calculates the reward for each warmup, adds to the RewardState's rewards array. -func (self *RewardState) RewardPerWarmup(startHeight, endHeight int64, rewardPerBlock uint64) { +// rewardPerWarmup calculates the reward for each warmup, adds to the RewardState's rewards array. +func (self *RewardState) rewardPerWarmup(startHeight, endHeight int64, rewardPerBlock uint64) { for i, warmup := range self.deposit.warmups { if startHeight >= warmup.NextWarmupHeight { // passed the warmup @@ -389,7 +389,7 @@ func (self *Pool) modifyDeposit(delta *i256.Int, currentHeight int64, nextTick i // historical tick does NOT actually reflect the tick at the blockNumber, but it provides correct ordering for the staked positions // because TickCrossHook is assured to be called for the staked-initialized ticks - self.historicalTick.Set(currentHeight, nextTick) + self.historicalTick.set(currentHeight, nextTick) switch deltaApplied.Sign() { case -1: @@ -408,7 +408,7 @@ func (self *Pool) modifyDeposit(delta *i256.Int, currentHeight int64, nextTick i } } - self.stakedLiquidity.Set(currentHeight, deltaApplied) + self.stakedLiquidity.set(currentHeight, deltaApplied) return result } diff --git a/contract/r/gnoswap/staker/reward_calculation_pool_tier.gno b/contract/r/gnoswap/staker/reward_calculation_pool_tier.gno index 2a7041a83..a4c0f034f 100644 --- a/contract/r/gnoswap/staker/reward_calculation_pool_tier.gno +++ b/contract/r/gnoswap/staker/reward_calculation_pool_tier.gno @@ -125,7 +125,7 @@ func NewPoolTier(pools *Pools, currentHeight int64, initialPoolPath string, getE currentEmission: getEmission(), } - pools.Set(initialPoolPath, NewPool(initialPoolPath, currentHeight+1)) + pools.set(initialPoolPath, NewPool(initialPoolPath, currentHeight+1)) result.changeTier(currentHeight+1, pools, initialPoolPath, 1) return result } diff --git a/contract/r/gnoswap/staker/reward_calculation_tick.gno b/contract/r/gnoswap/staker/reward_calculation_tick.gno index 2fab09994..d422bb10d 100644 --- a/contract/r/gnoswap/staker/reward_calculation_tick.gno +++ b/contract/r/gnoswap/staker/reward_calculation_tick.gno @@ -70,7 +70,7 @@ func (self *Ticks) Get(tickId int32) *Tick { return v.(*Tick) } -func (self *Ticks) Set(tickId int32, tick *Tick) { +func (self *Ticks) set(tickId int32, tick *Tick) { if tick.stakedLiquidityGross.IsZero() { self.tree.Remove(EncodeInt(tickId)) return @@ -140,7 +140,7 @@ func (self *Tick) modifyDepositUpper(currentHeight int64, currentTick int32, liq func (self *Tick) updateCurrentOutsideAccumulation(blockNumber int64, acc *u256.Uint) { currentOutsideAccumulation := self.CurrentOutsideAccumulation(blockNumber) newOutsideAccumulation := u256.Zero().Sub(acc, currentOutsideAccumulation) - self.outsideAccumulation.Set(blockNumber, newOutsideAccumulation) + self.outsideAccumulation.set(blockNumber, newOutsideAccumulation) } // TickCrossHook is a hook that is called when a tick is crossed. diff --git a/contract/r/gnoswap/staker/reward_calculation_tick_test.gno b/contract/r/gnoswap/staker/reward_calculation_tick_test.gno index 354349f60..c0a666881 100644 --- a/contract/r/gnoswap/staker/reward_calculation_tick_test.gno +++ b/contract/r/gnoswap/staker/reward_calculation_tick_test.gno @@ -38,11 +38,11 @@ func TestTicks(t *testing.T) { } tick.stakedLiquidityGross = u256.MustFromDecimal("1") - ticks.Set(100, tick) + ticks.set(100, tick) uassert.True(t, ticks.Has(100)) tick.stakedLiquidityGross = u256.Zero() - ticks.Set(100, tick) + ticks.set(100, tick) uassert.False(t, ticks.Has(100)) } @@ -58,7 +58,7 @@ func TestTicksBasic(t *testing.T) { uassert.True(t, tick100Again.stakedLiquidityGross.IsZero()) uassert.True(t, tick100Again.stakedLiquidityDelta.IsZero()) - ticks.Set(100, tick100) + ticks.set(100, tick100) uassert.False(t, ticks.Has(100)) } diff --git a/contract/r/gnoswap/staker/reward_calculation_types.gno b/contract/r/gnoswap/staker/reward_calculation_types.gno index 14f7cfbb0..a99cee3ef 100644 --- a/contract/r/gnoswap/staker/reward_calculation_types.gno +++ b/contract/r/gnoswap/staker/reward_calculation_types.gno @@ -54,9 +54,9 @@ func DecodeUint(s string) uint64 { // // Methods: // - Get: Retrieves a value associated with a uint64 key. -// - Set: Stores a value with a uint64 key. +// - set: Stores a value with a uint64 key. // - Has: Checks if a uint64 key exists in the tree. -// - Remove: Removes a uint64 key and its associated value. +// - remove: Removes a uint64 key and its associated value. // - Iterate: Iterates over keys and values in a range. // - ReverseIterate: Iterates in reverse order over keys and values in a range. type UintTree struct { @@ -78,7 +78,7 @@ func (self *UintTree) Get(key int64) (interface{}, bool) { return v, true } -func (self *UintTree) Set(key int64, value interface{}) { +func (self *UintTree) set(key int64, value interface{}) { self.tree.Set(EncodeUint(uint64(key)), value) } @@ -86,7 +86,7 @@ func (self *UintTree) Has(key int64) bool { return self.tree.Has(EncodeUint(uint64(key))) } -func (self *UintTree) Remove(key int64) { +func (self *UintTree) remove(key int64) { self.tree.Remove(EncodeUint(uint64(key))) } diff --git a/contract/r/gnoswap/staker/reward_calculation_types_test.gno b/contract/r/gnoswap/staker/reward_calculation_types_test.gno index 7f165820d..26afbb427 100644 --- a/contract/r/gnoswap/staker/reward_calculation_types_test.gno +++ b/contract/r/gnoswap/staker/reward_calculation_types_test.gno @@ -52,8 +52,8 @@ func TestDecodeUint(t *testing.T) { func TestUintTree(t *testing.T) { tree := NewUintTree() - // Test Set and Get - tree.Set(12345, "testValue") + // Test set and Get + tree.set(12345, "testValue") value, ok := tree.Get(12345) if !ok || value != "testValue" { t.Errorf("UintTree.Get(12345) = %v, %v; want testValue, true", value, ok) @@ -64,16 +64,16 @@ func TestUintTree(t *testing.T) { t.Errorf("UintTree.Has(12345) = false; want true") } - // Test Remove - tree.Remove(12345) + // Test remove + tree.remove(12345) if tree.Has(12345) { t.Errorf("UintTree.Has(12345) after Remove = true; want false") } // Test Iterate - tree.Set(100, "a") - tree.Set(200, "b") - tree.Set(300, "c") + tree.set(100, "a") + tree.set(200, "b") + tree.set(300, "c") var keys []uint64 var values []interface{} diff --git a/contract/r/gnoswap/staker/reward_calculation_warmup.gno b/contract/r/gnoswap/staker/reward_calculation_warmup.gno index 46203cade..ef4b76a5f 100644 --- a/contract/r/gnoswap/staker/reward_calculation_warmup.gno +++ b/contract/r/gnoswap/staker/reward_calculation_warmup.gno @@ -64,7 +64,7 @@ func modifyWarmup(index int, blockDuration int64) { warmupTemplate[index].BlockDuration = blockDuration } -func InstantiateWarmup(currentHeight int64) []Warmup { +func instantiateWarmup(currentHeight int64) []Warmup { warmups := make([]Warmup, 0) for _, warmup := range warmupTemplate { nextWarmupHeight := currentHeight + warmup.BlockDuration @@ -83,7 +83,7 @@ func InstantiateWarmup(currentHeight int64) []Warmup { return warmups } -func (warmup *Warmup) Apply(poolReward uint64, positionLiquidity, stakedLiquidity *u256.Uint) (uint64, uint64) { +func (warmup *Warmup) apply(poolReward uint64, positionLiquidity, stakedLiquidity *u256.Uint) (uint64, uint64) { poolRewardUint := u256.NewUint(poolReward) perPositionReward := u256.Zero().Mul(poolRewardUint, positionLiquidity) perPositionReward = u256.Zero().Div(perPositionReward, stakedLiquidity) diff --git a/contract/r/gnoswap/staker/reward_calculation_warmup_test.gno b/contract/r/gnoswap/staker/reward_calculation_warmup_test.gno index 1f26a7619..980e204bf 100644 --- a/contract/r/gnoswap/staker/reward_calculation_warmup_test.gno +++ b/contract/r/gnoswap/staker/reward_calculation_warmup_test.gno @@ -26,7 +26,7 @@ func TestDefaultWarmupTemplate(t *testing.T) { func TestInstantiateWarmup(t *testing.T) { currentHeight := int64(1000) - warmups := InstantiateWarmup(currentHeight) + warmups := instantiateWarmup(currentHeight) uassert.True(t, warmups[0].NextWarmupHeight > currentHeight) uassert.True(t, warmups[1].NextWarmupHeight > warmups[0].NextWarmupHeight) @@ -41,7 +41,7 @@ func TestWarmupApply(t *testing.T) { positionLiquidity := u256.NewUint(100) stakedLiquidity := u256.NewUint(200) - reward, penalty := warmup.Apply(poolReward, positionLiquidity, stakedLiquidity) + reward, penalty := warmup.apply(poolReward, positionLiquidity, stakedLiquidity) uassert.Equal(t, poolReward/2, reward+penalty) uassert.Equal(t, uint64(150), reward) @@ -111,7 +111,7 @@ func TestWarmupApply2(t *testing.T) { WarmupRatio: tt.warmupRatio, } - reward, penalty := warmup.Apply( + reward, penalty := warmup.apply( tt.poolReward, u256.NewUint(tt.position), u256.NewUint(tt.staked), @@ -134,18 +134,18 @@ func TestWarmupBoundaryValues(t *testing.T) { position := u256.NewUint(1) staked := u256.NewUint(1) - reward, penalty := warmup.Apply(maxReward, position, staked) + reward, penalty := warmup.apply(maxReward, position, staked) uassert.Equal(t, maxReward/2, reward) // zero reward - reward, penalty = warmup.Apply(0, position, staked) + reward, penalty = warmup.apply(0, position, staked) uassert.Equal(t, uint64(0), reward) uassert.Equal(t, uint64(0), penalty) } func TestFindWarmup(t *testing.T) { deposit := &Deposit{ - warmups: InstantiateWarmup(1000), + warmups: instantiateWarmup(1000), } // check index of warmup @@ -190,7 +190,7 @@ func TestLiquidityRatios(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - reward, _ := warmup.Apply( + reward, _ := warmup.apply( tt.reward, u256.NewUint(tt.position), u256.NewUint(tt.staked), @@ -203,7 +203,7 @@ func TestLiquidityRatios(t *testing.T) { func TestWarmupTransitions(t *testing.T) { currentHeight := int64(1000) deposit := &Deposit{ - warmups: InstantiateWarmup(currentHeight), + warmups: instantiateWarmup(currentHeight), } transitions := []struct { @@ -234,7 +234,7 @@ func TestModifyWarmup(t *testing.T) { t.Run("modify warmup with negative block duration", func(t *testing.T) { modifyWarmup(0, -1000) - instantiated := InstantiateWarmup(0) + instantiated := instantiateWarmup(0) uassert.Equal(t, int64(math.MaxInt64), instantiated[0].NextWarmupHeight) }) @@ -286,7 +286,7 @@ func TestRewardCalculationPrecision(t *testing.T) { for _, tt := range cases { t.Run(tt.name, func(t *testing.T) { - reward, penalty := warmup.Apply(tt.reward, position, staked) + reward, penalty := warmup.apply(tt.reward, position, staked) uassert.Equal(t, tt.expectedReward, reward) uassert.Equal(t, tt.expectedPenalty, penalty) // consider rounding error @@ -317,7 +317,7 @@ func TestMultipleWarmupPeriods(t *testing.T) { std.TestSkipHeights(startHeight) deposit := &Deposit{ - warmups: InstantiateWarmup(startHeight), + warmups: instantiateWarmup(startHeight), } position := u256.NewUint(1000) @@ -327,7 +327,7 @@ func TestMultipleWarmupPeriods(t *testing.T) { // WarmupRatio30 (30%) 5 days blocks5Days := uint64(5 * blocksInDay) - reward5Days, penalty5Days := deposit.warmups[0].Apply( + reward5Days, penalty5Days := deposit.warmups[0].apply( baseReward*blocks5Days, position, staked, @@ -343,7 +343,7 @@ func TestMultipleWarmupPeriods(t *testing.T) { // WarmupRatio50 (50%) 2 days std.TestSkipHeights(5 * blocksInDay) blocks2Days := uint64(2 * blocksInDay) - reward2Days, penalty2Days := deposit.warmups[1].Apply( + reward2Days, penalty2Days := deposit.warmups[1].apply( baseReward*blocks2Days, position, staked, @@ -378,7 +378,7 @@ func TestMultipleWarmupPeriods(t *testing.T) { std.TestSkipHeights(startHeight) deposit := &Deposit{ - warmups: InstantiateWarmup(startHeight), + warmups: instantiateWarmup(startHeight), } position := u256.NewUint(1000) @@ -399,7 +399,7 @@ func TestMultipleWarmupPeriods(t *testing.T) { for i, period := range periods { blocks := uint64(period.days * blocksInDay) - reward, penalty := deposit.warmups[i].Apply( + reward, penalty := deposit.warmups[i].apply( baseReward*blocks, position, staked, diff --git a/contract/r/gnoswap/staker/reward_pool_store.gno b/contract/r/gnoswap/staker/reward_pool_store.gno index c4ec439f7..78c45a9ef 100644 --- a/contract/r/gnoswap/staker/reward_pool_store.gno +++ b/contract/r/gnoswap/staker/reward_pool_store.gno @@ -33,23 +33,23 @@ func NewRewardPool() *RewardPool { } } -// SetTier : Sets the tier of the pool. -func (r *RewardPool) SetTier(tier uint64) { +// setTier : Sets the tier of the pool. +func (r *RewardPool) setTier(tier uint64) { r.tier = tier } -// SetRewardAmount : Sets the total reward amount for the pool. -func (r *RewardPool) SetRewardAmount(rewardAmount uint64) { +// setRewardAmount : Sets the total reward amount for the pool. +func (r *RewardPool) setRewardAmount(rewardAmount uint64) { r.rewardAmount = rewardAmount } -// SetDistributedAmount : Sets the amount of rewards distributed. -func (r *RewardPool) SetDistributedAmount(distributedAmount uint64) { +// setDistributedAmount : Sets the amount of rewards distributed. +func (r *RewardPool) setDistributedAmount(distributedAmount uint64) { r.distributedAmount = distributedAmount } -// SetLeftAmount : Sets the remaining rewards in the pool. -func (r *RewardPool) SetLeftAmount(leftAmount uint64) { +// setLeftAmount : Sets the remaining rewards in the pool. +func (r *RewardPool) setLeftAmount(leftAmount uint64) { r.leftAmount = leftAmount } @@ -100,44 +100,44 @@ func NewRewardPoolMap() *RewardPoolMap { } } -// SetRewardPoolMap : Replaces the current reward pool map. -func (r *RewardPoolMap) SetRewardPoolMap(rewardPools map[string]*RewardPool) { +// setRewardPoolMap : Replaces the current reward pool map. +func (r *RewardPoolMap) setRewardPoolMap(rewardPools map[string]*RewardPool) { r.rewardPools = rewardPools } -// SetRewardPool : Adds or updates a reward pool for a specific pool path. -func (r *RewardPoolMap) SetRewardPool(poolPath string, rewardPool *RewardPool) { +// setRewardPool : Adds or updates a reward pool for a specific pool path. +func (r *RewardPoolMap) setRewardPool(poolPath string, rewardPool *RewardPool) { r.rewardPools[poolPath] = rewardPool } // SetPoolTier : Sets the tier of a specific pool. -func (r *RewardPoolMap) SetPoolTier(poolPath string, tier uint64) { +func (r *RewardPoolMap) setPoolTier(poolPath string, tier uint64) { if _, exist := r.rewardPools[poolPath]; !exist { r.rewardPools[poolPath] = NewRewardPool() } - r.rewardPools[poolPath].SetTier(tier) + r.rewardPools[poolPath].setTier(tier) } -// SetPoolRewardAmount : Sets the reward amount for a specific pool. -func (r *RewardPoolMap) SetPoolRewardAmount(poolPath string, rewardAmount uint64) { +// setPoolRewardAmount : Sets the reward amount for a specific pool. +func (r *RewardPoolMap) setPoolRewardAmount(poolPath string, rewardAmount uint64) { if _, exist := r.rewardPools[poolPath]; !exist { r.rewardPools[poolPath] = NewRewardPool() } - r.rewardPools[poolPath].SetRewardAmount(rewardAmount) + r.rewardPools[poolPath].setRewardAmount(rewardAmount) } -// SetRewardAmountForTier : Sets the total reward amount for a tier. -func (r *RewardPoolMap) SetRewardAmountForTier(tierIndex int, amount uint64) { +// setRewardAmountForTier : Sets the total reward amount for a tier. +func (r *RewardPoolMap) setRewardAmountForTier(tierIndex int, amount uint64) { r.rewardAmountForTier[tierIndex] = amount } -// SetRewardAmountForTierEachPool : Sets the reward amount per pool for a tier. -func (r *RewardPoolMap) SetRewardAmountForTierEachPool(tierIndex int, amount uint64) { +// setRewardAmountForTierEachPool : Sets the reward amount per pool for a tier. +func (r *RewardPoolMap) setRewardAmountForTierEachPool(tierIndex int, amount uint64) { r.rewardAmountForTierEachPool[tierIndex] = amount } -// SetLeftAmountForTier : Sets the remaining reward amount for a tier. -func (r *RewardPoolMap) SetLeftAmountForTier(tierIndex int, amount uint64) { +// setLeftAmountForTier : Sets the remaining reward amount for a tier. +func (r *RewardPoolMap) setLeftAmountForTier(tierIndex int, amount uint64) { r.leftAmountForTier[tierIndex] = amount } diff --git a/contract/r/gnoswap/staker/reward_pool_store_test.gno b/contract/r/gnoswap/staker/reward_pool_store_test.gno index b371d5a68..628e1ed93 100644 --- a/contract/r/gnoswap/staker/reward_pool_store_test.gno +++ b/contract/r/gnoswap/staker/reward_pool_store_test.gno @@ -20,10 +20,10 @@ func TestRewardPool(t *testing.T) { } // Test setters - pool.SetTier(1) - pool.SetRewardAmount(1000) - pool.SetDistributedAmount(500) - pool.SetLeftAmount(500) + pool.setTier(1) + pool.setRewardAmount(1000) + pool.setDistributedAmount(500) + pool.setLeftAmount(500) // Test getters if pool.GetTier() != 1 { @@ -49,7 +49,7 @@ func TestRewardPoolMap(t *testing.T) { } // Test adding a new pool - rewardMap.SetRewardPool("pool1", &RewardPool{tier: 1, rewardAmount: 1000}) + rewardMap.setRewardPool("pool1", &RewardPool{tier: 1, rewardAmount: 1000}) rewardPool := rewardMap.GetRewardPoolByPoolPath("pool1") if rewardPool.GetTier() != 1 { t.Errorf("Expected tier of pool1 to be 1, got %d", rewardPool.GetTier()) @@ -59,19 +59,19 @@ func TestRewardPoolMap(t *testing.T) { } // Test updating pool tier - rewardMap.SetPoolTier("pool1", 2) + rewardMap.setPoolTier("pool1", 2) if rewardMap.GetPoolTier("pool1") != 2 { t.Errorf("Expected updated tier of pool1 to be 2, got %d", rewardMap.GetPoolTier("pool1")) } // Test setting and getting reward amount for tiers - rewardMap.SetRewardAmountForTier(TIER1_INDEX, 5000) + rewardMap.setRewardAmountForTier(TIER1_INDEX, 5000) if rewardMap.GetRewardAmountForTier(TIER1_INDEX) != 5000 { t.Errorf("Expected rewardAmountForTier[TIER1_INDEX] to be 5000, got %d", rewardMap.GetRewardAmountForTier(TIER1_INDEX)) } // Test setting and getting left amount for tiers - rewardMap.SetLeftAmountForTier(TIER2_INDEX, 3000) + rewardMap.setLeftAmountForTier(TIER2_INDEX, 3000) if rewardMap.GetLeftAmountForTier(TIER2_INDEX) != 3000 { t.Errorf("Expected leftAmountForTier[TIER2_INDEX] to be 3000, got %d", rewardMap.GetLeftAmountForTier(TIER2_INDEX)) } diff --git a/contract/r/gnoswap/staker/staker.gno b/contract/r/gnoswap/staker/staker.gno index 438db4b51..ad20de8eb 100644 --- a/contract/r/gnoswap/staker/staker.gno +++ b/contract/r/gnoswap/staker/staker.gno @@ -44,15 +44,15 @@ func (self *Deposits) Get(positionId uint64) *Deposit { return deposit } -func (self *Deposits) Set(positionId uint64, deposit *Deposit) { - self.tree.Set(EncodeUint(positionId), deposit) +func (self *Deposits) set(positionId uint64, deposit *Deposit) { + self.tree.Set(EncodeUint(tokenId), deposit) } func (self *Deposits) Has(positionId uint64) bool { return self.tree.Has(EncodeUint(positionId)) } -func (self *Deposits) Remove(positionId uint64) { +func (self *Deposits) remove(positionId uint64) { self.tree.Remove(EncodeUint(positionId)) } @@ -89,7 +89,7 @@ func (self *ExternalIncentives) Get(incentiveId string) *ExternalIncentive { return incentive } -func (self *ExternalIncentives) Set(incentiveId string, incentive *ExternalIncentive) { +func (self *ExternalIncentives) set(incentiveId string, incentive *ExternalIncentive) { self.tree.Set(incentiveId, incentive) } @@ -97,7 +97,7 @@ func (self *ExternalIncentives) Has(incentiveId string) bool { return self.tree.Has(incentiveId) } -func (self *ExternalIncentives) Remove(incentiveId string) { +func (self *ExternalIncentives) remove(incentiveId string) { self.tree.Remove(incentiveId) } @@ -127,7 +127,7 @@ func (self *Stakers) IterateAll(address std.Address, fn func(depositId uint64, d }) } -func (self *Stakers) AddDeposit(address std.Address, depositId uint64, deposit *Deposit) { +func (self *Stakers) addDeposit(address std.Address, depositId uint64, deposit *Deposit) { depositTreeI, ok := self.tree.Get(address.String()) if !ok { depositTree := avl.NewTree() @@ -138,7 +138,7 @@ func (self *Stakers) AddDeposit(address std.Address, depositId uint64, deposit * depositTree.Set(EncodeUint(depositId), deposit) } -func (self *Stakers) RemoveDeposit(address std.Address, depositId uint64) { +func (self *Stakers) removeDeposit(address std.Address, depositId uint64) { depositTreeI, ok := self.tree.Get(address.String()) if !ok { return @@ -257,13 +257,13 @@ func StakeToken(positionId uint64) (string, string, string) { tickUpper: tickUpper, liquidity: liquidity, lastCollectHeight: currentHeight, - warmups: InstantiateWarmup(currentHeight), + warmups: instantiateWarmup(currentHeight), } currentTick := pl.PoolGetSlot0Tick(poolPath) - deposits.Set(positionId, deposit) - stakers.AddDeposit(caller, positionId, deposit) + deposits.set(positionId, deposit) + stakers.addDeposit(caller, positionId, deposit) if caller == owner { // if caller is owner, transfer NFT ownership to staker contract if err := transferDeposit(positionId, owner, caller, consts.STAKER_ADDR); err != nil { @@ -284,7 +284,7 @@ func StakeToken(positionId uint64) (string, string, string) { pool.modifyDeposit(signedLiquidity, currentHeight, currentTick) } // historical tick must be set regardless of the deposit's range - pool.historicalTick.Set(currentHeight, currentTick) + pool.historicalTick.set(currentHeight, currentTick) // this could happen because of how position stores the ticks. // ticks are negated if the token1 < token0 @@ -435,7 +435,7 @@ func CollectReward(positionId uint64, unwrapResult bool) (string, string) { )) } incentive.rewardAmount -= amount - externalIncentives.Set(incentiveId, incentive) + externalIncentives.set(incentiveId, incentive) toUser := handleUnStakingFee(rewardToken, amount, false, positionId, incentive.targetPoolPath) @@ -479,7 +479,7 @@ func CollectReward(positionId uint64, unwrapResult bool) (string, string) { gns.Transfer(consts.COMMUNITY_POOL_ADDR, reward.InternalPenalty) } - unClaimableInternal := ProcessUnClaimableReward(deposit.targetPoolPath, currentHeight) + unClaimableInternal := processUnClaimableReward(deposit.targetPoolPath, currentHeight) if unClaimableInternal > 0 { // internal unClaimable to community pool totalEmissionSent += unClaimableInternal @@ -539,7 +539,7 @@ func UnStakeToken(positionId uint64, unwrapResult bool) (string, string, string) deposit := deposits.Get(positionId) poolPath := deposit.targetPoolPath - // Claim All Rewards + // claim All Rewards CollectReward(positionId, unwrapResult) token0Amount, token1Amount := getTokenPairBalanceFromPosition(poolPath, positionId) @@ -589,8 +589,8 @@ func applyUnStake(positionId uint64) { upperTick.modifyDepositUpper(currentHeight, currentTick, signedLiquidity) lowerTick.modifyDepositLower(currentHeight, currentTick, signedLiquidity) - deposits.Remove(positionId) - stakers.RemoveDeposit(deposit.owner, positionId) + deposits.remove(positionId) + stakers.removeDeposit(deposit.owner, positionId) owner := gnft.MustOwnerOf(positionIdFrom(positionId)) caller := getPrevAddr() diff --git a/contract/r/gnoswap/staker/staker_external_incentive.gno b/contract/r/gnoswap/staker/staker_external_incentive.gno index 7e30764fe..00ce32ca0 100644 --- a/contract/r/gnoswap/staker/staker_external_incentive.gno +++ b/contract/r/gnoswap/staker/staker_external_incentive.gno @@ -114,7 +114,7 @@ func CreateExternalIncentive( )) } // store external incentive information for each incentiveId - externalIncentives.Set(incentiveId, incentive) + externalIncentives.set(incentiveId, incentive) // deposit gns amount gns.TransferFrom(caller, consts.STAKER_ADDR, depositGnsAmount) diff --git a/contract/r/gnoswap/staker/tests/full_internal_external_test.gnoA b/contract/r/gnoswap/staker/tests/full_internal_external_test.gnoA index f10f85eaa..b388c5251 100644 --- a/contract/r/gnoswap/staker/tests/full_internal_external_test.gnoA +++ b/contract/r/gnoswap/staker/tests/full_internal_external_test.gnoA @@ -135,7 +135,7 @@ func testCreatePoolWugnotGns3000Tier01(t *testing.T) { gns.Approve(consts.POOL_ADDR, consts.UINT64_MAX) pl.CreatePool(wugnotPath, gnsPath, 3000, common.TickMathGetSqrtRatioAtTick(0).ToString()) // current tick 0 - println("[", std.GetHeight(), "] Already Set PoolTier 1") + println("[", std.GetHeight(), "] Already set PoolTier 1") uassert.Equal(t, uint64(100000000000000), gns.TotalSupply()) uassert.Equal(t, uint64(0), gnsBalance(consts.EMISSION_ADDR)) @@ -199,7 +199,7 @@ func testCreateBarBaz500Tier02(t *testing.T) { gns.Approve(consts.POOL_ADDR, consts.UINT64_MAX) pl.CreatePool(barPath, bazPath, 500, common.TickMathGetSqrtRatioAtTick(0).ToString()) - println("[", std.GetHeight(), "] (gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500) Set PoolTier 2") + println("[", std.GetHeight(), "] (gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500) set PoolTier 2") SetPoolTierByAdmin("gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500", 2) checkGnsBalance(t, 0)