From 706343b670eed7125156e9830dd7414c695ba109 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Tue, 14 May 2024 13:55:43 +0100 Subject: [PATCH] remove old ics code that is unused --- .../keeper/rewards_holdings.go | 37 +------- .../keeper/rewards_holdings_test.go | 92 ++----------------- 2 files changed, 11 insertions(+), 118 deletions(-) diff --git a/x/participationrewards/keeper/rewards_holdings.go b/x/participationrewards/keeper/rewards_holdings.go index 819bce798..41bd591f4 100644 --- a/x/participationrewards/keeper/rewards_holdings.go +++ b/x/participationrewards/keeper/rewards_holdings.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/quicksilver-zone/quicksilver/utils" - "github.com/quicksilver-zone/quicksilver/utils/addressutils" airdroptypes "github.com/quicksilver-zone/quicksilver/x/airdrop/types" cmtypes "github.com/quicksilver-zone/quicksilver/x/claimsmanager/types" icstypes "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types" @@ -17,7 +16,7 @@ func (k Keeper) AllocateHoldingsRewards(ctx sdk.Context) error { // obtain and iterate all claim records for each zone k.icsKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { k.Logger(ctx).Info("zones", "zone", zone.ChainId) - userAllocations, remaining, _ := k.CalcUserHoldingsAllocations(ctx, zone) + userAllocations, remaining := k.CalcUserHoldingsAllocations(ctx, zone) if err := k.DistributeToUsersFromModule(ctx, userAllocations); err != nil { k.Logger(ctx).Error("failed to distribute to users", "ua", userAllocations, "err", err) @@ -41,19 +40,16 @@ func (k Keeper) AllocateHoldingsRewards(ctx sdk.Context) error { } // CalcUserHoldingsAllocations calculates allocations per user for a given zone, based upon claims submitted and zone. -func (k Keeper) CalcUserHoldingsAllocations(ctx sdk.Context, zone *icstypes.Zone) ([]types.UserAllocation, math.Int, []types.UserAllocation) { +func (k Keeper) CalcUserHoldingsAllocations(ctx sdk.Context, zone *icstypes.Zone) ([]types.UserAllocation, math.Int) { k.Logger(ctx).Info("CalcUserHoldingsAllocations", "zone", zone.ChainId, "allocations", zone.HoldingsAllocation) userAllocations := make([]types.UserAllocation, 0) - icsRewardsAllocations := make([]types.UserAllocation, 0) - icsRewardsBalance := sdk.NewCoins() - icsRewardsPerAsset := make(map[string]sdk.Dec, 0) supply := k.bankKeeper.GetSupply(ctx, zone.LocalDenom) if zone.HoldingsAllocation == 0 || !supply.Amount.IsPositive() { k.Logger(ctx).Info("holdings allocation is zero, nothing to allocate") - return userAllocations, math.NewIntFromUint64(zone.HoldingsAllocation), icsRewardsAllocations + return userAllocations, math.NewIntFromUint64(zone.HoldingsAllocation) } // calculate user totals and zone total (held assets) @@ -83,26 +79,12 @@ func (k Keeper) CalcUserHoldingsAllocations(ctx sdk.Context, zone *icstypes.Zone if !zoneAmount.IsPositive() { k.Logger(ctx).Info("zero claims for zone", "zone", zone.ChainId) - return userAllocations, math.NewIntFromUint64(zone.HoldingsAllocation), icsRewardsAllocations + return userAllocations, math.NewIntFromUint64(zone.HoldingsAllocation) } zoneAllocation := math.NewIntFromUint64(zone.HoldingsAllocation) tokensPerAsset := sdk.NewDecFromInt(zoneAllocation).Quo(sdk.NewDecFromInt(supply.Amount)) - if zone.WithdrawalAddress != nil { - // determine ics rewards to be distributed per token. - icsRewardsAddr, err := addressutils.AddressFromBech32(zone.WithdrawalAddress.Address, zone.AccountPrefix) - if err != nil { - panic("unable to unmarshal withdrawal address") - } - icsRewardsBalance = k.bankKeeper.GetAllBalances(ctx, icsRewardsAddr) - icsRewardsPerAsset = make(map[string]sdk.Dec, len(icsRewardsBalance)) - for _, rewardsAsset := range icsRewardsBalance { - icsRewardsPerAsset[rewardsAsset.Denom] = sdk.NewDecFromInt(rewardsAsset.Amount).Quo(sdk.NewDecFromInt(supply.Amount)) - } - - k.Logger(ctx).Info("ics rewards per asset", "zone", zone.ChainId, "icsrpa", icsRewardsPerAsset) - } k.Logger(ctx).Info("tokens per asset", "zone", zone.ChainId, "tpa", tokensPerAsset) for _, address := range utils.Keys(userAmountsMap) { @@ -118,16 +100,7 @@ func (k Keeper) CalcUserHoldingsAllocations(ctx sdk.Context, zone *icstypes.Zone panic("user allocation overflow") } - // allocate ics rewards - for _, rewardsAsset := range icsRewardsBalance { - icsRewardsAllocation := types.UserAllocation{ - Address: address, - Amount: sdk.NewCoin(rewardsAsset.Denom, sdk.NewDecFromInt(amount).Mul(icsRewardsPerAsset[rewardsAsset.Denom]).TruncateInt()), - } - icsRewardsAllocations = append(icsRewardsAllocations, icsRewardsAllocation) - } - } - return userAllocations, zoneAllocation, icsRewardsAllocations + return userAllocations, zoneAllocation } diff --git a/x/participationrewards/keeper/rewards_holdings_test.go b/x/participationrewards/keeper/rewards_holdings_test.go index 6deb6e2a1..6f8e7cfec 100644 --- a/x/participationrewards/keeper/rewards_holdings_test.go +++ b/x/participationrewards/keeper/rewards_holdings_test.go @@ -18,13 +18,11 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { ctx := suite.chainA.GetContext() bondDenom := appA.StakingKeeper.BondDenom(ctx) tests := []struct { - name string - malleate func(ctx sdk.Context, appA *app.Quicksilver) - want []types.UserAllocation - icsWant []types.UserAllocation - remainder math.Int - icsRemainder sdk.Coins - wantErr string + name string + malleate func(ctx sdk.Context, appA *app.Quicksilver) + want []types.UserAllocation + remainder math.Int + wantErr string }{ { "zero claims; no allocation", @@ -34,9 +32,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { appA.InterchainstakingKeeper.SetZone(ctx, &zone) }, []types.UserAllocation{}, - []types.UserAllocation{}, sdk.ZeroInt(), - sdk.NewCoins(), "", }, { @@ -49,9 +45,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { appA.ClaimsManagerKeeper.SetLastEpochClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: math.NewInt(1000)}) }, []types.UserAllocation{}, - []types.UserAllocation{}, sdk.NewInt(64000), - sdk.NewCoins(), "", }, { @@ -75,9 +69,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { Amount: sdk.NewCoin(bondDenom, sdk.NewInt(2500)), }, }, - []types.UserAllocation{}, sdk.ZeroInt(), - sdk.NewCoins(), "", }, { @@ -101,9 +93,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { Amount: sdk.NewCoin(bondDenom, sdk.NewInt(2000)), // 1000 / 2500 (0.4) * 5000 = 2000 }, }, - []types.UserAllocation{}, sdk.NewInt(2000), - sdk.NewCoins(), "", }, { @@ -127,9 +117,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { Amount: sdk.NewCoin(bondDenom, sdk.NewInt(3333)), // 1000/1500 (0.66666) * 5000 = 3333 }, }, - []types.UserAllocation{}, sdk.OneInt(), - sdk.NewCoins(), "", }, { @@ -155,18 +143,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { Amount: sdk.NewCoin(bondDenom, sdk.NewInt(3333)), // 1000/1500 (0.66666) * 5000 = 3333 }, }, - []types.UserAllocation{ - { - Address: user1.String(), - Amount: sdk.NewCoin("testcoin", sdk.NewInt(300)), // 500/1500 (0.33333) * 900 == 300 - }, - { - Address: user2.String(), - Amount: sdk.NewCoin("testcoin", sdk.NewInt(600)), // 1000/1500 (0.66666) * 900 = 600 - }, - }, sdk.OneInt(), - sdk.NewCoins(), "", }, { @@ -197,34 +174,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { Amount: sdk.NewCoin(bondDenom, sdk.NewInt(3333)), // 1000/1500 (0.66666) * 5000 = 3333 }, }, - []types.UserAllocation{ - { - Address: user1.String(), - Amount: sdk.NewCoin("testcoin", sdk.NewInt(300)), // 500/1500 (0.33333) * 900 == 300 - }, - { - Address: user2.String(), - Amount: sdk.NewCoin("testcoin", sdk.NewInt(600)), // 1000/1500 (0.66666) * 900 = 600 - }, - { - Address: user1.String(), - Amount: sdk.NewCoin("testcoin2", sdk.NewInt(6000)), // 500/1500 (0.33333) * 18k == 6k - }, - { - Address: user2.String(), - Amount: sdk.NewCoin("testcoin2", sdk.NewInt(12001)), // 1000/1500 (0.66666) * 18k = 12k - }, - { - Address: user1.String(), - Amount: sdk.NewCoin("testcoin3", sdk.NewInt(50)), // 500/1500 (0.33333) * 150 == 50 - }, - { - Address: user2.String(), - Amount: sdk.NewCoin("testcoin3", sdk.NewInt(100)), // 1000/1500 (0.66666) * 150 = 100 - }, - }, sdk.OneInt(), - sdk.NewCoins(sdk.NewCoin("testcoin2", sdk.NewIntFromUint64(1))), "", }, @@ -254,29 +204,7 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { Amount: sdk.NewCoin(bondDenom, sdk.NewInt(2000)), // 1000 / 2500 (0.4) * 5000 = 2000 }, }, - []types.UserAllocation{ - { - Address: user1.String(), - Amount: sdk.NewCoin("testcoin", sdk.NewInt(180)), // 500/1500 (0.33333) * 900 == 300 - }, - { - Address: user2.String(), - Amount: sdk.NewCoin("testcoin", sdk.NewInt(360)), // 1000/1500 (0.66666) * 900 = 600 - }, - { - Address: user1.String(), - Amount: sdk.NewCoin("testcoin2", sdk.NewInt(3600)), // 500/1500 (0.33333) * 18k == 6k - }, - { - Address: user2.String(), - Amount: sdk.NewCoin("testcoin2", sdk.NewInt(7200)), // 1000/1500 (0.66666) * 18k = 12k - }, - }, sdk.NewInt(2000), - sdk.NewCoins( - sdk.NewCoin("testcoin", sdk.NewInt(360)), - sdk.NewCoin("testcoin2", sdk.NewInt(7202)), - ), "", }, } @@ -301,17 +229,9 @@ func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { suite.NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) suite.NoError(appA.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) - allocations, remainder, icsRewardsAllocations := appA.ParticipationRewardsKeeper.CalcUserHoldingsAllocations(ctx, &zone) + allocations, remainder := appA.ParticipationRewardsKeeper.CalcUserHoldingsAllocations(ctx, &zone) suite.ElementsMatch(tt.want, allocations) - suite.ElementsMatch(tt.icsWant, icsRewardsAllocations) suite.True(tt.remainder.Equal(remainder)) - - // distribute assets to users; check remainder (to be distributed next time!) - err := appA.ParticipationRewardsKeeper.DistributeToUsersFromAddress(ctx, icsRewardsAllocations, zone.WithdrawalAddress.Address) - suite.NoError(err) - icsAddress, _ := addressutils.AddressFromBech32(zone.WithdrawalAddress.Address, "") - icsBalance := appA.BankKeeper.GetAllBalances(ctx, icsAddress) - suite.ElementsMatch(tt.icsRemainder, icsBalance) }) } }