diff --git a/app/app.go b/app/app.go index 97be31f7fa..2055653c43 100644 --- a/app/app.go +++ b/app/app.go @@ -172,9 +172,6 @@ import ( oraclekeeper "github.com/provenance-io/provenance/x/oracle/keeper" oraclemodule "github.com/provenance-io/provenance/x/oracle/module" oracletypes "github.com/provenance-io/provenance/x/oracle/types" - rewardkeeper "github.com/provenance-io/provenance/x/reward/keeper" - rewardmodule "github.com/provenance-io/provenance/x/reward/module" - rewardtypes "github.com/provenance-io/provenance/x/reward/types" triggerkeeper "github.com/provenance-io/provenance/x/trigger/keeper" triggermodule "github.com/provenance-io/provenance/x/trigger/module" triggertypes "github.com/provenance-io/provenance/x/trigger/types" @@ -232,7 +229,6 @@ var ( metadata.AppModuleBasic{}, wasm.AppModuleBasic{}, msgfeesmodule.AppModuleBasic{}, - rewardmodule.AppModuleBasic{}, triggermodule.AppModuleBasic{}, oraclemodule.AppModuleBasic{}, holdmodule.AppModuleBasic{}, @@ -255,7 +251,6 @@ var ( attributetypes.ModuleName: nil, markertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, wasmtypes.ModuleName: {authtypes.Burner}, - rewardtypes.ModuleName: nil, triggertypes.ModuleName: nil, oracletypes.ModuleName: nil, } @@ -311,7 +306,6 @@ type App struct { EvidenceKeeper evidencekeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper MsgFeesKeeper msgfeeskeeper.Keeper - RewardKeeper rewardkeeper.Keeper // QuarantineKeeper quarantinekeeper.Keeper // TODO[1760]: quarantine // SanctionKeeper sanctionkeeper.Keeper // TODO[1760]: sanction TriggerKeeper triggerkeeper.Keeper @@ -410,7 +404,6 @@ func New( nametypes.StoreKey, msgfeestypes.StoreKey, wasmtypes.StoreKey, - rewardtypes.StoreKey, // quarantine.StoreKey, // TODO[1760]: quarantine // sanction.StoreKey, // TODO[1760]: sanction triggertypes.StoreKey, @@ -517,8 +510,6 @@ func New( stakingtypes.NewMultiStakingHooks(restrictHooks, app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.RewardKeeper = rewardkeeper.NewKeeper(appCodec, keys[rewardtypes.StoreKey], app.StakingKeeper, &app.GovKeeper, app.BankKeeper, app.AccountKeeper) - app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.BaseApp.MsgServiceRouter(), app.AccountKeeper) app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.BaseApp.MsgServiceRouter(), app.AccountKeeper, group.DefaultConfig()) @@ -583,7 +574,6 @@ func New( markerReqAttrBypassAddrs := []sdk.AccAddress{ authtypes.NewModuleAddress(authtypes.FeeCollectorName), // Allow collecting fees in restricted coins. - authtypes.NewModuleAddress(rewardtypes.ModuleName), // Allow rewards to hold onto restricted coins. // authtypes.NewModuleAddress(quarantine.ModuleName), // Allow quarantine to hold onto restricted coins. // TODO[1760]: quarantine authtypes.NewModuleAddress(govtypes.ModuleName), // Allow restricted coins in deposits. authtypes.NewModuleAddress(distrtypes.ModuleName), // Allow fee denoms to be restricted coins. @@ -802,7 +792,6 @@ func New( attribute.NewAppModule(appCodec, app.AttributeKeeper, app.AccountKeeper, app.BankKeeper, app.NameKeeper), msgfeesmodule.NewAppModule(appCodec, app.MsgFeesKeeper, app.interfaceRegistry), wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil, app.GetSubspace(wasmtypes.ModuleName)), // TODO[1760]: Need to pass message router instead of nil - rewardmodule.NewAppModule(appCodec, app.RewardKeeper, app.AccountKeeper, app.BankKeeper), triggermodule.NewAppModule(appCodec, app.TriggerKeeper, app.AccountKeeper, app.BankKeeper), oracleModule, holdmodule.NewAppModule(appCodec, app.HoldKeeper), @@ -857,7 +846,6 @@ func New( markertypes.ModuleName, icatypes.ModuleName, attributetypes.ModuleName, - rewardtypes.ModuleName, triggertypes.ModuleName, // no-ops @@ -894,7 +882,6 @@ func New( authtypes.ModuleName, icatypes.ModuleName, group.ModuleName, - rewardtypes.ModuleName, triggertypes.ModuleName, // no-ops @@ -968,7 +955,6 @@ func New( ibchookstypes.ModuleName, // wasm after ibc transfer wasmtypes.ModuleName, - rewardtypes.ModuleName, triggertypes.ModuleName, oracletypes.ModuleName, @@ -1015,7 +1001,6 @@ func New( msgfeestypes.ModuleName, metadatatypes.ModuleName, nametypes.ModuleName, - rewardtypes.ModuleName, triggertypes.ModuleName, oracletypes.ModuleName, @@ -1049,7 +1034,6 @@ func New( name.NewAppModule(appCodec, app.NameKeeper, app.AccountKeeper, app.BankKeeper), attribute.NewAppModule(appCodec, app.AttributeKeeper, app.AccountKeeper, app.BankKeeper, app.NameKeeper), msgfeesmodule.NewAppModule(appCodec, app.MsgFeesKeeper, app.interfaceRegistry), - rewardmodule.NewAppModule(appCodec, app.RewardKeeper, app.AccountKeeper, app.BankKeeper), triggermodule.NewAppModule(appCodec, app.TriggerKeeper, app.AccountKeeper, app.BankKeeper), oraclemodule.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper, app.IBCKeeper.ChannelKeeper), holdmodule.NewAppModule(appCodec, app.HoldKeeper), @@ -1423,7 +1407,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(attributetypes.ModuleName) // TODO[1760]: params: Migrate attribute params. paramsKeeper.Subspace(msgfeestypes.ModuleName) // TODO[1760]: params: Migrate msgFees params. paramsKeeper.Subspace(wasmtypes.ModuleName) - paramsKeeper.Subspace(rewardtypes.ModuleName) // TODO[1760]: params: Migrate reward params. paramsKeeper.Subspace(triggertypes.ModuleName) // TODO[1760]: params: Migrate trigger params. // register the key tables for legacy param subspaces diff --git a/app/test_helpers.go b/app/test_helpers.go index 84b40f8d12..658ce0bea3 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -43,7 +43,6 @@ import ( "github.com/provenance-io/provenance/app/params" "github.com/provenance-io/provenance/internal" "github.com/provenance-io/provenance/internal/pioconfig" - rewardtypes "github.com/provenance-io/provenance/x/reward/types" ) // DefaultConsensusParams defines the default Tendermint consensus params used in @@ -516,64 +515,3 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) { } return &ed25519.PubKey{Key: pkBytes} } - -// SetupWithGenesisRewardsProgram initializes a new SimApp with the provided -// rewards programs, genesis accounts, validators, and balances. -func SetupWithGenesisRewardsProgram(t *testing.T, nextRewardProgramID uint64, genesisRewards []rewardtypes.RewardProgram, genAccs []authtypes.GenesisAccount, valSet *cmttypes.ValidatorSet, balances ...banktypes.Balance) *App { - t.Helper() - - // Make sure there's a validator set with at least one validator in it. - if valSet == nil || len(valSet.Validators) == 0 { - privVal := mock.NewPV() - pubKey, err := privVal.GetPubKey() - require.NoError(t, err) - validator := cmttypes.NewValidator(pubKey, 1) - if valSet == nil { - valSet = cmttypes.NewValidatorSet([]*cmttypes.Validator{validator}) - } else { - require.NoError(t, valSet.UpdateWithChangeSet([]*cmttypes.Validator{validator})) - } - } - - app, genesisState := setup(t, true, 0, "") - genesisState = genesisStateWithValSet(t, app, genesisState, valSet, genAccs, balances...) - genesisState = genesisStateWithRewards(t, app, genesisState, nextRewardProgramID, genesisRewards) - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err, "marshaling genesis state to json") - - _, err = app.InitChain( - &abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: DefaultConsensusParams, - AppStateBytes: stateBytes, - }, - ) - require.NoError(t, err, "InitChain") - - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - NextValidatorsHash: valSet.Hash(), - Time: time.Now().UTC(), - }) - require.NoError(t, err, "FinalizeBlock") - - return app -} - -func genesisStateWithRewards(t *testing.T, - app *App, genesisState GenesisState, - nextRewardProgramID uint64, genesisRewards []rewardtypes.RewardProgram, -) GenesisState { - rewardGenesisState := rewardtypes.NewGenesisState( - nextRewardProgramID, - genesisRewards, - []rewardtypes.ClaimPeriodRewardDistribution{}, - []rewardtypes.RewardAccountState{}, - ) - var err error - genesisState[rewardtypes.ModuleName], err = app.AppCodec().MarshalJSON(rewardGenesisState) - require.NoError(t, err, "marshaling reward genesis state JSON") - return genesisState -} diff --git a/internal/handlers/msg_service_router_test.go b/internal/handlers/msg_service_router_test.go index f3a52e5cb7..c20c7f8bc0 100644 --- a/internal/handlers/msg_service_router_test.go +++ b/internal/handlers/msg_service_router_test.go @@ -14,7 +14,6 @@ import ( cmttypes "github.com/cometbft/cometbft/types" "cosmossdk.io/log" - sdkmath "cosmossdk.io/math" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" @@ -33,7 +32,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" piosimapp "github.com/provenance-io/provenance/app" "github.com/provenance-io/provenance/internal/antewrapper" @@ -41,7 +39,6 @@ import ( "github.com/provenance-io/provenance/internal/pioconfig" "github.com/provenance-io/provenance/x/msgfees/types" msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types" - rewardtypes "github.com/provenance-io/provenance/x/reward/types" ) func stopIfFailed(t *testing.T) { @@ -987,2325 +984,6 @@ func TestMsgServiceAssessMsgFeeNoRecipient(tt *testing.T) { }) } -func TestRewardsProgramStartError(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin("hotdog", 1000), sdk.NewInt64Coin("atom", 1000), - sdk.NewInt64Coin(NHash, 1_190_500_000), - ) - app := piosimapp.SetupWithGenesisAccounts(t, "", - []authtypes.GenesisAccount{acct1}, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - blockTime := ctx.BlockTime() - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(NHash, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - rewardProgram := *rewardtypes.NewMsgCreateRewardProgramRequest( - "title", - "description", - acct1.Address, - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - blockTime, - 0, - 3, - 3, - uint64(blockTime.Day()), - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - - txBytes, err := SignTxAndGetBytes(ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - &rewardProgram, - ) - require.NoError(t, err, "SignTxAndGetBytes") - blockRes, err := app.FinalizeBlock( - &abci.RequestFinalizeBlock{ - Height: ctx.BlockHeight() + 1, - Txs: [][]byte{txBytes}, - }, - ) - assert.Equal(t, uint32(0x1), blockRes.TxResults[0].Code, "claims period error") - assert.NoError(t, err, "FinalizeBlock") -} - -func TestRewardsProgramStart(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - pioconfig.SetProvenanceConfig("nhash", 0) - priv, _, addr := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin("hotdog", 1000), - sdk.NewInt64Coin("atom", 1000), - sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000), - ) - app := piosimapp.SetupWithGenesisAccounts(t, "", - []authtypes.GenesisAccount{acct1}, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now()}) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - rewardProgram := *rewardtypes.NewMsgCreateRewardProgramRequest( - "title", - "description", - acct1.Address, - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time.Now().Add(time.Duration(1)*time.Second), - 9, - 3, - 3, - 10, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - - txReward, err := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - &rewardProgram, - ) - require.NoError(t, err, "SignTxAndGetBytes") - - blockRes, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: ctx.BlockHeight() + 1, - Time: time.Now().UTC(), - Txs: [][]byte{txReward}, - }, - ) - assert.NoError(t, err, "FinalizeBlock expected no error") - - expEvents := []abci.Event{ - NewEvent(rewardtypes.EventTypeRewardProgramCreated, - NewAttribute(rewardtypes.AttributeKeyRewardProgramID, "1")), - NewEvent(sdk.EventTypeMessage, - NewAttribute(sdk.AttributeKeyAction, sdk.MsgTypeURL(&rewardtypes.MsgCreateRewardProgramRequest{}))), - } - assertEventsContains(t, blockRes.TxResults[0].Events, expEvents) -} - -func TestRewardsProgramStartPerformQualifyingActions(t *testing.T) { - pioconfig.SetProvenanceConfig("nhash", 0) - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - _, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin("hotdog", 10000000000), - sdk.NewInt64Coin("atom", 10000000), - sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000), - ) - app := piosimapp.SetupWithGenesisAccounts(t, "", - []authtypes.GenesisAccount{acct1}, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - rewardProgram := *rewardtypes.NewMsgCreateRewardProgramRequest( - "title", - "description", - acct1.Address, - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time.Now().Add(time.Duration(100)*time.Millisecond), - 9, - 3, - 3, - 10, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - txReward, err := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - &rewardProgram, - ) - require.NoError(t, err, "SignTxAndGetBytes") - - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: ctx.BlockHeight() + 1, - Time: time.Now().UTC(), - Txs: [][]byte{txReward}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - - time.Sleep(110 * time.Millisecond) - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - for height := int64(2); height <= int64(99); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Len(t, claimPeriodDistributions, 1, "claimPeriodDistributions") - assert.Equal(t, 10, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.NotEqual(t, "0nhash", claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 98, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 10, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unspecified") - canCheck := assert.NotNil(t, byAddress, "byAddress unspecified") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unspecified") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 1, "RewardAccountState unspecified") - assert.Equal(t, "100nhash", byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unspecified") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unspecified") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unclaimable") - canCheck = assert.NotNil(t, byAddress, "byAddress unclaimable") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unclaimable") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 1, "RewardAccountState unclaimable") - assert.Equal(t, "100nhash", byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unclaimable") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unclaimable") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress claimable") - assert.Empty(t, byAddress.RewardAccountState, "RewardAccountState claimable") -} - -func TestRewardsProgramStartPerformQualifyingActionsRecordedRewardsUnclaimable(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - _, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 1) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(50*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, nil, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - // get past the reward start time ( test that reward program starts up after 50ms) - time.Sleep(55 * time.Millisecond) - - for height := int64(1); height < int64(21); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Len(t, claimPeriodDistributions, 1, "claimPeriodDistributions") - assert.Equal(t, 10, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("nhash", 100_000_000_000).String(), - claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 20, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 10, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unspecified") - canCheck := assert.NotNil(t, byAddress, "byAddress unspecified") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unspecified") - if canCheck { - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unspecified") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unspecified") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unclaimable") - canCheck = assert.NotNil(t, byAddress, "byAddress unclaimable") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unclaimable") - if canCheck { - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unclaimable") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unclaimable") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress claimable") - if assert.NotNil(t, byAddress, "byAddress claimable") { - assert.Empty(t, byAddress.RewardAccountState, "RewardAccountState claimable") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress claimed") - if assert.NotNil(t, byAddress, "byAddress claimed") { - assert.Empty(t, byAddress.RewardAccountState, "RewardAccountState claimed") - } -} - -func TestRewardsProgramStartPerformQualifyingActionsSomePeriodsClaimableModuleAccountFunded(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - _, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 1) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - // fund th =e deterministic rewards account, since genesis won't do that work - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, nil, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - banktypes.Balance{Address: "cosmos1w6t0l7z0yerj49ehnqwqaayxqpe3u7e23edgma", Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(150 * time.Millisecond) - - //go through 5 blocks, but take a long time to cut blocks. - for height := int64(1); height < int64(6); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - // wait for claim period to end (claim period is 1s) - time.Sleep(1500 * time.Millisecond) - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Equal(t, 1, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, true, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000), claimPeriodDistributions[0].RewardsPool, "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 1, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 1, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unspecified") - canCheck := assert.NotNil(t, byAddress, "byAddress unspecified") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unspecified") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 5, "RewardAccountState unspecified") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unspecified") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unspecified") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress claimable") - canCheck = assert.NotNil(t, byAddress, "byAddress claimable") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState claimable") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 4, "RewardAccountState claimable") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim claimable") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus claimable") - } - - // get the accoutn balances of acct1 - balance := app.BankKeeper.GetAllBalances(ctx, acct1.GetAddress()) - // claim rewards for the address - msgClaim := rewardtypes.NewMsgClaimAllRewardsRequest(acct1.Address) - require.NoError(t, acct1.SetSequence(seq), "SetSequence(%d)", seq) - txClaim, errClaim := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - fees, - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - msgClaim, - ) - require.NoError(t, errClaim, "SignTxAndGetBytes") - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 6, - Time: time.Now().UTC(), - Txs: [][]byte{txClaim}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - - // unmarshal the TxMsgData - var protoResult sdk.TxMsgData - - require.NoError(t, app.AppCodec().Unmarshal(res.TxResults[0].Data, &protoResult), "unmarshalling protoResult") - require.Len(t, protoResult.MsgResponses, 1, "protoResult.MsgResponses") - require.Equal(t, protoResult.MsgResponses[0].GetTypeUrl(), "/provenance.reward.v1.MsgClaimAllRewardsResponse", - "protoResult.MsgResponses[0].GetTypeUrl()") - claimResponse := rewardtypes.MsgClaimAllRewardsResponse{} - require.NoError(t, claimResponse.Unmarshal(protoResult.MsgResponses[0].Value), "unmarshalling claimResponse") - assert.Equal(t, sdk.NewInt64Coin("nhash", 50_000_000_000).String(), claimResponse.TotalRewardClaim[0].String(), - "TotalRewardClaim") - if assert.Len(t, claimResponse.ClaimDetails, 1, "ClaimDetails") { - assert.Equal(t, 1, int(claimResponse.ClaimDetails[0].RewardProgramId), "RewardProgramId") - assert.Equal(t, sdk.NewInt64Coin("nhash", 50_000_000_000).String(), - claimResponse.ClaimDetails[0].TotalRewardClaim.String(), "ClaimDetails TotalRewardClaim") - if assert.Len(t, claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails, 5, "ClaimedRewardPeriodDetails") { - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails[0].ClaimPeriodReward.String(), "ClaimPeriodReward") - } - } - balanceLater := app.BankKeeper.GetAllBalances(ctx, acct1.GetAddress()) - // make sure account balance has the tokens - balanceChange := balanceLater.AmountOf(pioconfig.GetProvenanceConfig().FeeDenom).Sub(balance.AmountOf(pioconfig.GetProvenanceConfig().FeeDenom)) - assert.Equal(t, sdkmath.NewInt(50_000_000_000).String(), balanceChange.String(), "balance change") -} - -func TestRewardsProgramStartPerformQualifyingActionsSomePeriodsClaimableModuleAccountFundedDifferentDenom(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - _, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin("hotdog", 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("hotdog", 1000_000_000_000), - sdk.NewInt64Coin("hotdog", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - // fund th =e deterministic rewards account, since genesis won't do that work - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, nil, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - banktypes.Balance{Address: "cosmos1w6t0l7z0yerj49ehnqwqaayxqpe3u7e23edgma", Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(150 * time.Millisecond) - - //go through 5 blocks, but take a long time to cut blocks. - for height := int64(1); height < int64(6); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - // wait for claim period to end (claim period is 1s) - time.Sleep(1500 * time.Millisecond) - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Equal(t, 1, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, true, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCount := int(rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer)) - assert.Equal(t, 1, actionCount, "ActionCounter transfer") - assert.Equal(t, 1, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unspecified") - canCheck := assert.NotNil(t, byAddress, "byAddress unspecified") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unspecified") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 5, "RewardAccountState unspecified") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unspecified") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unspecified") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress claimable") - canCheck = assert.NotNil(t, byAddress, "byAddress claimable") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState claimable") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 4, "claimable rewards should be 4 for this address.") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim claimable") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus claimable") - } - - // get the accoutn balances of acct1 - balance := app.BankKeeper.GetAllBalances(ctx, acct1.GetAddress()) - // claim rewards for the address - msgClaim := rewardtypes.NewMsgClaimAllRewardsRequest(acct1.Address) - require.NoError(t, acct1.SetSequence(seq), "SetSequence(%d)", seq) - txClaim, errClaim := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - fees, - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - msgClaim, - ) - require.NoError(t, errClaim, "SignTxAndGetBytes") - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 6, - Time: time.Now().UTC(), - Txs: [][]byte{txClaim}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - - // unmarshal the TxMsgData - var protoResult sdk.TxMsgData - require.NoError(t, app.AppCodec().Unmarshal(res.TxResults[0].Data, &protoResult), "unmarshalling protoResult") - require.Len(t, protoResult.MsgResponses, 1, "protoResult.MsgResponses") - require.Equal(t, protoResult.MsgResponses[0].GetTypeUrl(), "/provenance.reward.v1.MsgClaimAllRewardsResponse", - "protoResult.MsgResponses[0].GetTypeUrl()") - claimResponse := rewardtypes.MsgClaimAllRewardsResponse{} - require.NoError(t, claimResponse.Unmarshal(protoResult.MsgResponses[0].Value), "unmarshalling claimResponse") - if assert.NotEmpty(t, claimResponse.TotalRewardClaim, "TotalRewardClaim") { - assert.Equal(t, sdk.NewInt64Coin("hotdog", 50_000_000_000).String(), - claimResponse.TotalRewardClaim[0].String(), "TotalRewardClaim") - } - if assert.NotEmpty(t, claimResponse.ClaimDetails, "ClaimDetails") { - assert.Len(t, claimResponse.ClaimDetails, 1, "ClaimDetails") - assert.Equal(t, 1, int(claimResponse.ClaimDetails[0].RewardProgramId), "RewardProgramId") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 50_000_000_000).String(), - claimResponse.ClaimDetails[0].TotalRewardClaim.String(), "ClaimDetails TotalRewardClaim") - if assert.NotEmpty(t, claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails, "ClaimedRewardPeriodDetails") { - assert.Len(t, claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails, 5, "ClaimedRewardPeriodDetails") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails[0].ClaimPeriodReward.String(), "ClaimPeriodReward") - } - } - - app.Commit() - balanceLater := app.BankKeeper.GetAllBalances(ctx, acct1.GetAddress()) - balanceChange := balanceLater.AmountOf("hotdog").Sub(balance.AmountOf("hotdog")) - // make sure account balance has the tokens - assert.Equal(t, sdkmath.NewInt(50_000_000_000).String(), balanceChange.String(), "balance change") -} - -func TestRewardsProgramStartPerformQualifyingActionsSomePeriodsClaimableModuleAccountFundedDifferentDenomClaimedTogether(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - _, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin("atom", 10000000), - sdk.NewInt64Coin("hotdog", 1000000_000_000_000), - sdk.NewInt64Coin("nhash", 1000000_000_000_000), - ) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("hotdog", 1000_000_000_000), - sdk.NewInt64Coin("hotdog", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - - secondRewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 2, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - // fund th =e deterministic rewards account, since genesis won't do that work - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(3), []rewardtypes.RewardProgram{rewardProgram, secondRewardProgram}, - []authtypes.GenesisAccount{acct1}, nil, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - banktypes.Balance{Address: "cosmos1w6t0l7z0yerj49ehnqwqaayxqpe3u7e23edgma", Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(150 * time.Millisecond) - - //go through 5 blocks, but take a long time to cut blocks. - for height := int64(1); height < int64(6); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - - // wait for claim period to end (claim period is 1s) - time.Sleep(1500 * time.Millisecond) - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Equal(t, 1, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, true, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 1, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 1, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unspecified") - canCheck := assert.NotNil(t, byAddress, "byAddress unspecified") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unspecified") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 10, "RewardAccountState unspecified") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unspecified") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unspecified") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress claimable") - canCheck = assert.NotNil(t, byAddress, "byAddress claimable") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState claimable") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 8, "RewardAccountState claimable") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim claimable") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus claimable") - } - - // get the accoutn balances of acct1 - balance := app.BankKeeper.GetAllBalances(ctx, acct1.GetAddress()) - // claim rewards for the address - - msgClaim := rewardtypes.NewMsgClaimAllRewardsRequest(acct1.Address) - require.NoError(t, acct1.SetSequence(seq), "SetSequence(%d)", seq) - // needs extra gas - txClaim, errClaim := SignTxAndGetBytes(ctx, 300000, fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msgClaim) - require.NoError(t, errClaim, "SignTxAndGetBytes") - - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 6, - Time: time.Now().UTC(), - Txs: [][]byte{txClaim}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - - // unmarshal the TxMsgData - var protoResult sdk.TxMsgData - require.NoError(t, app.AppCodec().Unmarshal(res.TxResults[0].Data, &protoResult), "unmarshalling protoResult") - require.Len(t, protoResult.MsgResponses, 1, "protoResult.MsgResponses") - require.Equal(t, protoResult.MsgResponses[0].GetTypeUrl(), "/provenance.reward.v1.MsgClaimAllRewardsResponse", - "protoResult.MsgResponses[0].GetTypeUrl()") - claimResponse := rewardtypes.MsgClaimAllRewardsResponse{} - require.NoError(t, claimResponse.Unmarshal(protoResult.MsgResponses[0].Value), "unmarshalling claimResponse") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 50_000_000_000).String(), - claimResponse.TotalRewardClaim[0].String(), "TotalRewardClaim") - if assert.NotEmpty(t, claimResponse.ClaimDetails, "ClaimDetails") { - assert.Len(t, claimResponse.ClaimDetails, 2) - - assert.Equal(t, 1, int(claimResponse.ClaimDetails[0].RewardProgramId), "[0].RewardProgramId") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 50_000_000_000).String(), - claimResponse.ClaimDetails[0].TotalRewardClaim.String(), "[0].TotalRewardClaim") - if assert.NotEmpty(t, claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails, "[0].ClaimedRewardPeriodDetails") { - assert.Len(t, claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails, 5, "[0].ClaimedRewardPeriodDetails") - assert.Equal(t, sdk.NewInt64Coin("hotdog", 10_000_000_000).String(), - claimResponse.ClaimDetails[0].ClaimedRewardPeriodDetails[0].ClaimPeriodReward.String(), "[0].[0].ClaimPeriodReward") - } - - assert.Equal(t, 2, int(claimResponse.ClaimDetails[1].RewardProgramId), "[1].RewardProgramId") - assert.Equal(t, sdk.NewInt64Coin("nhash", 50_000_000_000).String(), - claimResponse.ClaimDetails[1].TotalRewardClaim.String(), "[1].TotalRewardClaim") - if assert.NotEmpty(t, claimResponse.ClaimDetails[1].ClaimedRewardPeriodDetails, "[1].ClaimedRewardPeriodDetails") { - assert.Len(t, claimResponse.ClaimDetails[1].ClaimedRewardPeriodDetails, 5, "[1].ClaimedRewardPeriodDetails") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - claimResponse.ClaimDetails[1].ClaimedRewardPeriodDetails[0].ClaimPeriodReward.String(), "[1].[0].ClaimPeriodReward") - } - } - - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 7, - Time: time.Now().UTC(), - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - - balanceLater := app.BankKeeper.GetAllBalances(ctx, acct1.GetAddress()) - // make sure account balance has the tokens - balanceChangeHotDog := balanceLater.AmountOf("hotdog").Sub(balance.AmountOf("hotdog")) - assert.Equal(t, sdkmath.NewInt(50_000_000_000).String(), balanceChangeHotDog.String(), "balance change hotdog") - - balanceLater = app.BankKeeper.GetAllBalances(ctx, acct1.GetAddress()) - // make sure account balance has the tokens - balanceChangeNHash := balanceLater.AmountOf("nhash").Sub(balance.AmountOf("nhash")) - assert.Equal(t, sdkmath.NewInt(50_000_000_000).String(), balanceChangeNHash.String(), "balance change nhash") -} - -func TestRewardsProgramStartPerformQualifyingActionsSomePeriodsClaimableModuleAccountNotFunded(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - _, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - // do not fund the deterministic rewards account - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, nil, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(150 * time.Millisecond) - - //go through 5 blocks, but take a long time to cut blocks. - for height := int64(1); height < int64(6); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - - time.Sleep(1500 * time.Millisecond) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Equal(t, 1, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, true, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 1, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 1, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress unspecified") - canCheck := assert.NotNil(t, byAddress, "byAddress unspecified") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState unspecified") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 5, "RewardAccountState unspecified") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim unspecified") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus unspecified") - } - - byAddress, err = app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress claimable") - canCheck = assert.NotNil(t, byAddress, "byAddress claimable") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState claimable") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 4, "RewardAccountState claimable") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim claimable") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus claimable") - } - - // claim rewards for the address - msgClaim := rewardtypes.NewMsgClaimAllRewardsRequest(acct1.Address) - require.NoError(t, acct1.SetSequence(seq), "SetSequence(%d)", seq) - txClaim, errClaim := SignTxAndGetBytes(ctx, - NewTestRewardsGasLimit(), - fees, - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - msgClaim, - ) - require.NoError(t, errClaim, "SignTxAndGetBytes") - - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 6, - Time: time.Now().UTC(), - Txs: [][]byte{txClaim}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() -} - -// Checks to see if delegation are met for a Qualifying action in this case Transfer -// this tests has transfers from an account which DOES NOT have the minimum delegation -// amount needed to get a share -func TestRewardsProgramStartPerformQualifyingActionsCriteriaNotMet(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - _, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.Coin{ - Denom: "nhash", - Amount: sdkmath.NewInt(10_000_000_000)}, - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, nil, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(110 * time.Millisecond) - - //go through 5 blocks, but take a long time to cut blocks. - for height := int64(1); height < int64(6); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - time.Sleep(1100 * time.Millisecond) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Equal(t, 0, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, true, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 0, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 0, int(accountState.SharesEarned), "SharesEarned") -} - -// Checks to see if delegation are met for a Qualifying action in this case, Transfer, create an address with delegations -// transfers which map to QualifyingAction map to the delegated address -// delegation threshold is met -func TestRewardsProgramStartPerformQualifyingActionsTransferAndDelegationsPresent(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, pubKey, addr := testdata.KeyTestPubAddr() - _, pubKey2, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.Coin{ - Denom: "nhash", - Amount: sdkmath.NewInt(100)}, - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, createValSet(t, pubKey, pubKey2), - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - // wait for program to start - time.Sleep(150 * time.Millisecond) - - //go through 5 blocks, but take a time to cut blocks > claim period time interval. - for height := int64(1); height < int64(6); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - time.Sleep(1100 * time.Millisecond) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Equal(t, 1, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, true, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 1, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 1, int(accountState.SharesEarned), "account state incorrect") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress") - canCheck := assert.NotNil(t, byAddress, "byAddress unspecified") - canCheck = canCheck && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState") - if canCheck { - assert.Len(t, byAddress.RewardAccountState, 5, "RewardAccountState") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus") - } -} - -// Checks to see if delegation are met for a Qualifying action in this case Transfer, create an address with delegations -// transfers which map to QualifyingAction map to the delegated address -// delegation threshold is *not* met -func TestRewardsProgramStartPerformQualifyingActionsThreshHoldNotMet(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, pubKey, addr := testdata.KeyTestPubAddr() - _, pubKey2, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(1), - 100, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Transfer{ - Transfer: &rewardtypes.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.Coin{ - Denom: "nhash", - Amount: sdkmath.NewInt(100_000_000)}, - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, createValSet(t, pubKey, pubKey2), - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - - // tx with a fee associated with msg type and account has funds - msg := banktypes.NewMsgSend(addr, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 50))) - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(1 * time.Second) - - //go through 5 blocks, but take a long time to cut blocks. - for height := int64(1); height < int64(6); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - time.Sleep(1100 * time.Millisecond) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Equal(t, 0, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, true, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeTransfer) - assert.Equal(t, 0, int(actionCounter), "ActionCounter transfer") - assert.Equal(t, 0, int(accountState.SharesEarned), "SharesEarned") -} - -func TestRewardsProgramStartPerformQualifyingActions_Vote(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, _, addr := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000000), - sdk.NewInt64Coin("atom", 10000000), - sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000), - ) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Vote{ - Vote: &rewardtypes.ActionVote{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, nil, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - coinsPos := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000)) - msg, err := govtypesv1beta1.NewMsgSubmitProposal( - ContentFromProposalType("title", "description", govtypesv1beta1.ProposalTypeText), - coinsPos, - addr, - ) - require.NoError(t, err, "NewMsgSubmitProposal expected to create msg") - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - - txGov, err := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - msg, - ) - require.NoError(t, err, "SignTxAndGetBytes") - time.Sleep(200 * time.Millisecond) - - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 1, - Time: time.Now().UTC(), - Txs: [][]byte{txGov}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - app.Commit() - - seq = seq + 1 - proposal := getLastProposal(t, ctx, app) - - // tx with a fee associated with msg type and account has funds - vote1 := govtypesv1beta1.NewMsgVote(addr, proposal.Id, govtypesv1beta1.OptionYes) - - for height := int64(2); height < int64(22); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), vote1) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Len(t, claimPeriodDistributions, 1, "claimPeriodDistributions") - assert.Equal(t, 10, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.NotEqual(t, "0nhash", claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeVote) - assert.Equal(t, 20, int(actionCounter), "ActionCounter vote") - assert.Equal(t, 10, int(accountState.SharesEarned), "SharesEarned") -} - -func TestRewardsProgramStartPerformQualifyingActions_Vote_InvalidDelegations(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv1, pubKey1, addr1 := testdata.KeyTestPubAddr() - priv2, _, addr2 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr1, priv1.PubKey(), 0, 0) - acct2 := authtypes.NewBaseAccount(addr2, priv2.PubKey(), 1, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acctBalance := sdk.NewCoins( - sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000000), - sdk.NewInt64Coin("atom", 10000000), - sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000), - ) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Vote{ - Vote: &rewardtypes.ActionVote{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 1000), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1, acct2}, createValSet(t, pubKey1), - banktypes.Balance{Address: addr1.String(), Coins: acctBalance}, - banktypes.Balance{Address: addr2.String(), Coins: acctBalance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct2.GetAddress(), fundCoins), - "funding acct2 with 290500010nhash") - coinsPos := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000)) - msg, err := govtypesv1beta1.NewMsgSubmitProposal( - ContentFromProposalType("title", "description", govtypesv1beta1.ProposalTypeText), - coinsPos, - addr1, - ) - require.NoError(t, err, "NewMsgSubmitProposal expected to create msg") - - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - time.Sleep(200 * time.Millisecond) - - txGov, err := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv1.PubKey(), priv1, *acct1, ctx.ChainID(), - msg, - ) - require.NoError(t, err, "SignTxAndGetBytes") - - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 1, - Time: time.Now().UTC(), - Txs: [][]byte{txGov}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - - proposal := getLastProposal(t, ctx, app) - - // tx with a fee associated with msg type and account has funds - vote2 := govtypesv1beta1.NewMsgVote(addr2, proposal.Id, govtypesv1beta1.OptionYes) - acct2 = app.AccountKeeper.GetAccount(ctx, acct2.GetAddress()).(*authtypes.BaseAccount) - seq := acct2.Sequence - - for height := int64(2); height < int64(4); height++ { - require.NoError(t, acct2.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv2.PubKey(), priv2, *acct2, ctx.ChainID(), vote2) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Len(t, claimPeriodDistributions, 1, "claimPeriodDistributions") - assert.Equal(t, 0, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.Equal(t, "100000000000nhash", claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct2.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeVote) - assert.Equal(t, 0, int(actionCounter), "ActionCounter vote") - assert.Equal(t, 0, int(accountState.SharesEarned), "SharesEarned") - - byAddress1, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress acct1") - assert.Empty(t, byAddress1.RewardAccountState, "RewardAccountState acct1") - - byAddress2, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct2.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress acct2") - assert.Empty(t, byAddress2.RewardAccountState, "RewardAccountState acct2") -} - -func TestRewardsProgramStartPerformQualifyingActions_Vote_ValidDelegations(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, pubKey, addr := testdata.KeyTestPubAddr() - _, pubKey2, _ := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000000), - sdk.NewInt64Coin("atom", 10000000), - sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000), - ) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Vote{ - Vote: &rewardtypes.ActionVote{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 1000), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, createValSet(t, pubKey, pubKey2), - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - coinsPos := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000)) - msg, err := govtypesv1beta1.NewMsgSubmitProposal( - ContentFromProposalType("title", "description", govtypesv1beta1.ProposalTypeText), - coinsPos, - addr, - ) - require.NoError(t, err, "NewMsgSubmitProposal expected to create msg") - - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(200 * time.Millisecond) - - txGov, err := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - msg, - ) - require.NoError(t, err, "SignTxAndGetBytes") - - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 1, - Time: time.Now().UTC(), - Txs: [][]byte{txGov}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - - seq = seq + 1 - proposal := getLastProposal(t, ctx, app) - - // tx with a fee associated with msg type and account has funds - vote1 := govtypesv1beta1.NewMsgVote(addr, proposal.Id, govtypesv1beta1.OptionYes) - - // threshold will be met after 10 actions - for height := int64(2); height < int64(22); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), vote1) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Len(t, claimPeriodDistributions, 1, "claimPeriodDistributions") - assert.Equal(t, 10, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.NotEqual(t, "0nhash", claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeVote) - assert.Equal(t, 20, int(actionCounter), "ActionCounter vote") - assert.Equal(t, 10, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress") - if assert.NotNil(t, byAddress, "byAddress") && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState") { - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus") - } -} - -// checks to see that votes are coming from an address that has delegated enough coins and is a validator, and gets the multiplier applied -func TestRewardsProgramStartPerformQualifyingActions_Vote_ValidDelegations_Multiplier_Present(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, pubKey, addr := testdata.KeyTestPubAddr() - _, pubKey2, _ := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000000), sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin("nhash", 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Vote{ - Vote: &rewardtypes.ActionVote{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 1000), - ValidatorMultiplier: 10, - }, - }, - }, - }, - ) - - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - //err, bondedVal1, bondedVal2 := createTestValidators(pubKey, pubKey2, addr, addr2) - app := piosimapp.SetupWithGenesisRewardsProgram(t, uint64(2), []rewardtypes.RewardProgram{rewardProgram}, []authtypes.GenesisAccount{acct1}, createValSet(t, pubKey, pubKey2), banktypes.Balance{Address: addr.String(), Coins: acct1Balance}) - - ctx := app.BaseApp.NewContext(false) - ctx.WithBlockTime(time.Now()) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin("nhash", 290_500_010)))) - coinsPos := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000)) - msg, err := govtypesv1beta1.NewMsgSubmitProposal( - ContentFromProposalType("title", "description", govtypesv1beta1.ProposalTypeText), - coinsPos, - addr, - ) - require.NoError(t, err, "NewMsgSubmitProposal expected to create msg") - - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - ctx.WithBlockTime(time.Now()) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - ctx.WithBlockTime(time.Now()) - time.Sleep(200 * time.Millisecond) - - txGov, err := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin("nhash", 1_190_500_000)), encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), msg) - require.NoError(t, err, "SignTxAndGetBytes") - - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 1, - Time: time.Now().UTC(), - Txs: [][]byte{txGov}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - - seq = seq + 1 - proposal := getLastProposal(t, ctx, app) - - // tx with a fee associated with msg type and account has funds - vote1 := govtypesv1beta1.NewMsgVote(addr, proposal.Id, govtypesv1beta1.OptionYes) - - assert.NotEmpty(t, res.GetEvents(), "should have emitted an event.") - - // threshold will be met after 10 actions - for height := int64(2); height < int64(22); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), vote1) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - app.Commit() - seq = seq + 1 - } - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err) - assert.Len(t, claimPeriodDistributions, 1, "claim period reward distributions should exist") - assert.Equal(t, int64(100), claimPeriodDistributions[0].TotalShares, "shares should have accumulated to value of 100 ( 10 action * multiplier (10) shares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "claim period has not ended.") - assert.Equal(t, false, claimPeriodDistributions[0].RewardsPool.Equal(sdk.Coin{ - Denom: "nhash", - Amount: sdkmath.ZeroInt(), - }), "claim period has not ended so rewards still haven't been calculated(hence 0 coins)") - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err) - assert.Equal(t, uint64(20), rewardtypes.GetActionCount(accountState.ActionCounter, "ActionVote"), "account state incorrect") - assert.Equal(t, 100, int(accountState.SharesEarned), "account state incorrect") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }) - require.NoError(t, err) - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), byAddress.RewardAccountState[0].TotalRewardClaim.String(), "RewardDistributionsByAddress incorrect") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, byAddress.RewardAccountState[0].ClaimStatus, "claim status incorrect") -} - -// checks to see that votes are coming from an address that has delegated enough coins but is not a validator, hence does not get the multiplier applied -func TestRewardsProgramStartPerformQualifyingActions_Vote_ValidDelegations_Multiplier_Present_But_NotValidatorVotes(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, pubKey, addr := testdata.KeyTestPubAddr() - _, pubKey2, _ := testdata.KeyTestPubAddr() - // an address which is not a validator - priv3, _, addr3 := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - acct3 := authtypes.NewBaseAccount(addr3, priv3.PubKey(), 0, 0) - acct1Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000000), sdk.NewInt64Coin("atom", 10000000), sdk.NewInt64Coin("nhash", 1000000_000_000_000)) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Vote{ - Vote: &rewardtypes.ActionVote{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 1000), - ValidatorMultiplier: 10, - }, - }, - }, - }, - ) - - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - app := piosimapp.SetupWithGenesisRewardsProgram(t, uint64(2), []rewardtypes.RewardProgram{rewardProgram}, []authtypes.GenesisAccount{acct3}, createValSet(t, pubKey, pubKey2), banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, banktypes.Balance{Address: addr3.String(), Coins: acct1Balance}) - - ctx := app.BaseApp.NewContext(false) - ctx.WithBlockTime(time.Now()) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin("nhash", 290_500_010)))) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct3.GetAddress(), sdk.NewCoins(sdk.NewInt64Coin("nhash", 290_500_010)))) - coinsPos := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000)) - msg, err := govtypesv1beta1.NewMsgSubmitProposal( - ContentFromProposalType("title", "description", govtypesv1beta1.ProposalTypeText), - coinsPos, - addr3, - ) - require.NoError(t, err, "NewMsgSubmitProposal expected to create msg") - - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - ctx.WithBlockTime(time.Now()) - acct3 = app.AccountKeeper.GetAccount(ctx, acct3.GetAddress()).(*authtypes.BaseAccount) - seq := acct3.Sequence - ctx.WithBlockTime(time.Now()) - time.Sleep(200 * time.Millisecond) - - txGov, err := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin("nhash", 1_190_500_000)), encCfg, priv3.PubKey(), priv3, *acct3, ctx.ChainID(), msg) - require.NoError(t, err, "SignTxAndGetBytes") - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 1, - Time: time.Now().UTC(), - Txs: [][]byte{txGov}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - - seq = seq + 1 - proposal := getLastProposal(t, ctx, app) - - // vote with an account which is not a validator - vote := govtypesv1beta1.NewMsgVote(addr3, proposal.Id, govtypesv1beta1.OptionYes) - - assert.NotEmpty(t, res.GetEvents(), "should have emitted an event.") - - // threshold will be met after 10 actions - for height := int64(2); height < int64(22); height++ { - require.NoError(t, acct3.SetSequence(seq)) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv3.PubKey(), priv3, *acct3, ctx.ChainID(), vote) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - app.Commit() - seq = seq + 1 - } - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err) - assert.Len(t, claimPeriodDistributions, 1, "claim period reward distributions should exist") - assert.Equal(t, int64(10), claimPeriodDistributions[0].TotalShares, "shares should have accumulated to value of 10, ( 10 action leading to 1 share each) (no multiplier is applied) ") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "claim period has not ended.") - assert.Equal(t, false, claimPeriodDistributions[0].RewardsPool.Equal(sdk.Coin{ - Denom: "nhash", - Amount: sdkmath.ZeroInt(), - }), "claim period has not ended so rewards still haven't been calculated(hence 0 coins)") - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct3.Address) - require.NoError(t, err) - assert.Equal(t, uint64(20), rewardtypes.GetActionCount(accountState.ActionCounter, "ActionVote"), "account state incorrect") - assert.Equal(t, 10, int(accountState.SharesEarned), "account state incorrect") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct3.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }) - require.NoError(t, err) - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), byAddress.RewardAccountState[0].TotalRewardClaim.String(), "RewardDistributionsByAddress incorrect") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, byAddress.RewardAccountState[0].ClaimStatus, "claim status incorrect") -} - -func TestRewardsProgramStartPerformQualifyingActions_Delegate_NoQualifyingActions(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, pubKey, addr := testdata.KeyTestPubAddr() - _, pubKey2, _ := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000000), - sdk.NewInt64Coin("atom", 10000000), - sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000), - ) - - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Delegate{ - Delegate: &rewardtypes.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: nil, - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, createValSet(t, pubKey, pubKey2), - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - coinsPos := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000)) - msg, err := govtypesv1beta1.NewMsgSubmitProposal( - ContentFromProposalType("title", "description", govtypesv1beta1.ProposalTypeText), - coinsPos, - addr, - ) - require.NoError(t, err, "NewMsgSubmitProposal expected to create msg") - - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(110 * time.Millisecond) - - txGov, err := SignTxAndGetBytes( - ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - msg, - ) - require.NoError(t, err, "SignTxAndGetBytes") - - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 1, - Time: time.Now().UTC(), - Txs: [][]byte{txGov}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - - seq = seq + 1 - proposal := getLastProposal(t, ctx, app) - - // tx with a fee associated with msg type and account has funds - vote1 := govtypesv1beta1.NewMsgVote(addr, proposal.Id, govtypesv1beta1.OptionYes) - - for height := int64(2); height < int64(14); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), vote1) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Len(t, claimPeriodDistributions, 1, "claimPeriodDistributions") - assert.Equal(t, 0, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.NotEqual(t, "0nhash", claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeVote) - assert.Equal(t, 0, int(actionCounter), "ActionCounter vote") - assert.Equal(t, 0, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress") - if assert.NotNil(t, byAddress, "byAddress") { - assert.Empty(t, byAddress.RewardAccountState, "RewardAccountState") - } -} - -func TestRewardsProgramStartPerformQualifyingActions_Delegate_QualifyingActionsPresent(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig() - priv, pubKey, addr := testdata.KeyTestPubAddr() - _, pubKey2, _ := testdata.KeyTestPubAddr() - acct1 := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) - pioconfig.SetProvenanceConfig("nhash", 0) - acct1Balance := sdk.NewCoins( - sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000000), - sdk.NewInt64Coin("atom", 10000000), - sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1000000_000_000_000), - ) - minDelegation := sdk.NewInt64Coin("nhash", 4) - maxDelegation := sdk.NewInt64Coin("nhash", 2001000) - rewardProgram := rewardtypes.NewRewardProgram( - "title", - "description", - 1, - acct1.Address, - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []rewardtypes.QualifyingAction{ - { - Type: &rewardtypes.QualifyingAction_Delegate{ - Delegate: &rewardtypes.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(100, 0), - }, - }, - }, - }, - ) - rewardProgram.State = rewardtypes.RewardProgram_STATE_PENDING - - valSet := createValSet(t, pubKey, pubKey2) - app := piosimapp.SetupWithGenesisRewardsProgram(t, - uint64(2), []rewardtypes.RewardProgram{rewardProgram}, - []authtypes.GenesisAccount{acct1}, valSet, - banktypes.Balance{Address: addr.String(), Coins: acct1Balance}, - ) - - ctx := app.BaseApp.NewContext(false) - require.NoError(t, app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()), "Setting default account params") - fundCoins := sdk.NewCoins(sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 290_500_010)) - require.NoError(t, testutil.FundAccount(ctx, app.BankKeeper, acct1.GetAddress(), fundCoins), - "funding acct1 with 290500010nhash") - coinsPos := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100000000)) - msg, err := govtypesv1beta1.NewMsgSubmitProposal( - ContentFromProposalType("title", "description", govtypesv1beta1.ProposalTypeText), - coinsPos, - addr, - ) - require.NoError(t, err, "NewMsgSubmitProposal expected to create msg") - - fees := sdk.NewCoins(sdk.NewInt64Coin("atom", 150)) - acct1 = app.AccountKeeper.GetAccount(ctx, acct1.GetAddress()).(*authtypes.BaseAccount) - seq := acct1.Sequence - time.Sleep(200 * time.Millisecond) - - txGov, err := SignTxAndGetBytes(ctx, - NewTestRewardsGasLimit(), - sdk.NewCoins(sdk.NewInt64Coin("atom", 150), sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().FeeDenom, 1_190_500_000)), - encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), - msg, - ) - require.NoError(t, err, "SignTxAndGetBytes") - - res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: 1, - Time: time.Now().UTC(), - Txs: [][]byte{txGov}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - - app.Commit() - - seq = seq + 1 - _ = getLastProposal(t, ctx, app) // Just making sure it exists. - - // tx with a fee associated with msg type and account has funds - delAddr, _ := valSet.GetByIndex(0) - delegation := stakingtypes.NewMsgDelegate(addr.String(), sdk.ValAddress(delAddr).String(), sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000)) - - for height := int64(2); height < int64(22); height++ { - require.NoError(t, acct1.SetSequence(seq), "[%d]: SetSequence(%d)", height, seq) - tx1, err1 := SignTxAndGetBytes(ctx, NewTestRewardsGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct1, ctx.ChainID(), delegation) - require.NoError(t, err1, "[%d]: SignTxAndGetBytes", height) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: height, - Time: time.Now().UTC(), - Txs: [][]byte{tx1}, - }, - ) - require.NoError(t, err, "FinalizeBlock expected no error") - require.Len(t, res.TxResults, 1, "TxResults expected length not met") - require.Equal(t, uint32(0), res.TxResults[0].Code, "TxResults tx unexpected result code "+res.TxResults[0].Log) - time.Sleep(100 * time.Millisecond) - - app.Commit() - seq = seq + 1 - } - - claimPeriodDistributions, err := app.RewardKeeper.GetAllClaimPeriodRewardDistributions(ctx) - require.NoError(t, err, "GetAllClaimPeriodRewardDistributions") - if assert.NotEmpty(t, claimPeriodDistributions, "claimPeriodDistributions") { - assert.Len(t, claimPeriodDistributions, 1, "claimPeriodDistributions") - assert.Equal(t, 10, int(claimPeriodDistributions[0].TotalShares), "TotalShares") - assert.Equal(t, false, claimPeriodDistributions[0].ClaimPeriodEnded, "ClaimPeriodEnded") - assert.NotEqual(t, "0nhash", claimPeriodDistributions[0].RewardsPool.String(), "RewardsPool") - } - - accountState, err := app.RewardKeeper.GetRewardAccountState(ctx, uint64(1), uint64(1), acct1.Address) - require.NoError(t, err, "GetRewardAccountState") - actionCounter := rewardtypes.GetActionCount(accountState.ActionCounter, rewardtypes.ActionTypeDelegate) - assert.Equal(t, 20, int(actionCounter), "ActionCounter delegate") - assert.Equal(t, 10, int(accountState.SharesEarned), "SharesEarned") - - byAddress, err := app.RewardKeeper.RewardDistributionsByAddress(sdk.WrapSDKContext(ctx), - &rewardtypes.QueryRewardDistributionsByAddressRequest{ - Address: acct1.Address, - ClaimStatus: rewardtypes.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - }, - ) - require.NoError(t, err, "RewardDistributionsByAddress") - if assert.NotNil(t, byAddress, "byAddress") && assert.NotEmpty(t, byAddress.RewardAccountState, "RewardAccountState") { - assert.Equal(t, sdk.NewInt64Coin("nhash", 10_000_000_000).String(), - byAddress.RewardAccountState[0].TotalRewardClaim.String(), "TotalRewardClaim") - assert.Equal(t, rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - byAddress.RewardAccountState[0].ClaimStatus, "ClaimStatus") - } -} - // ContentFromProposalType returns a Content object based on the proposal type. func ContentFromProposalType(title, desc, ty string) govtypesv1beta1.Content { switch ty { @@ -3433,10 +1111,6 @@ func NewTestGasLimit() uint64 { return 150000 } -func NewTestRewardsGasLimit() uint64 { - return 200000 -} - // CreateSendCoinEvents creates the sequence of events that are created on bankkeeper.SendCoins func CreateSendCoinEvents(fromAddress, toAddress string, amt sdk.Coins) []abci.Event { events := sdk.NewEventManager().Events() diff --git a/internal/provwasm/stargate_whitelist.go b/internal/provwasm/stargate_whitelist.go index 185b8b1c23..f03b4859e9 100644 --- a/internal/provwasm/stargate_whitelist.go +++ b/internal/provwasm/stargate_whitelist.go @@ -22,7 +22,6 @@ import ( metadatatypes "github.com/provenance-io/provenance/x/metadata/types" msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types" nametypes "github.com/provenance-io/provenance/x/name/types" - rewardtypes "github.com/provenance-io/provenance/x/reward/types" triggertypes "github.com/provenance-io/provenance/x/trigger/types" ) @@ -135,13 +134,6 @@ func init() { setWhitelistedQuery("/provenance.name.v1.Query/Resolve", &nametypes.QueryResolveResponse{}) setWhitelistedQuery("/provenance.name.v1.Query/ReverseLookup", &nametypes.QueryReverseLookupResponse{}) - // reward - setWhitelistedQuery("/provenance.reward.v1.Query/RewardProgramByID", &rewardtypes.QueryRewardProgramByIDResponse{}) - setWhitelistedQuery("/provenance.reward.v1.Query/RewardPrograms", &rewardtypes.QueryRewardProgramsResponse{}) - setWhitelistedQuery("/provenance.reward.v1.Query/ClaimPeriodRewardDistributions", &rewardtypes.QueryClaimPeriodRewardDistributionsResponse{}) - setWhitelistedQuery("/provenance.reward.v1.Query/ClaimPeriodRewardDistributionsByID", &rewardtypes.QueryClaimPeriodRewardDistributionsByIDResponse{}) - setWhitelistedQuery("/provenance.reward.v1.Query/RewardDistributionsByAddress", &rewardtypes.QueryRewardDistributionsByAddressResponse{}) - // trigger setWhitelistedQuery("/provenance.trigger.v1.Query/TriggerByID", &triggertypes.QueryTriggerByIDResponse{}) setWhitelistedQuery("/provenance.trigger.v1.Query/Triggers", &triggertypes.QueryTriggersResponse{}) diff --git a/proto/provenance/name/v1/name.proto b/proto/provenance/name/v1/name.proto index 8e7068b05a..561f0b8aec 100644 --- a/proto/provenance/name/v1/name.proto +++ b/proto/provenance/name/v1/name.proto @@ -31,7 +31,8 @@ message NameRecord { // the bound name string name = 1; // the address the name resolved to - string address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];; + string address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + ; // whether owner signature is required to add sub-names bool restricted = 3; } diff --git a/proto/provenance/reward/v1/genesis.proto b/proto/provenance/reward/v1/genesis.proto deleted file mode 100644 index 52bf12a12f..0000000000 --- a/proto/provenance/reward/v1/genesis.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; -package provenance.reward.v1; - -import "gogoproto/gogo.proto"; -import "provenance/reward/v1/reward.proto"; - -option go_package = "github.com/provenance-io/provenance/x/reward/types"; -option java_package = "io.provenance.reward.v1"; -option java_multiple_files = true; - -// GenesisState defines the reward module's genesis state. -message GenesisState { - option (gogoproto.equal) = false; - option (gogoproto.goproto_getters) = false; - - // Reward program id is the next auto incremented id to be assigned to the next created reward program - uint64 reward_program_id = 1; - // Reward programs to initially start with. - repeated RewardProgram reward_programs = 2 [(gogoproto.nullable) = false]; - // Claim period reward distributions to initially start with. - repeated ClaimPeriodRewardDistribution claim_period_reward_distributions = 3 [(gogoproto.nullable) = false]; - // Reward account states to initially start with. - repeated RewardAccountState reward_account_states = 4 [(gogoproto.nullable) = false]; -} diff --git a/proto/provenance/reward/v1/query.proto b/proto/provenance/reward/v1/query.proto deleted file mode 100644 index 38e905c494..0000000000 --- a/proto/provenance/reward/v1/query.proto +++ /dev/null @@ -1,152 +0,0 @@ -syntax = "proto3"; -package provenance.reward.v1; - -import "gogoproto/gogo.proto"; -import "google/api/annotations.proto"; -import "cosmos/base/v1beta1/coin.proto"; -import "cosmos/base/query/v1beta1/pagination.proto"; -import "provenance/reward/v1/reward.proto"; - -option go_package = "github.com/provenance-io/provenance/x/reward/types"; -option java_package = "io.provenance.reward.v1"; -option java_multiple_files = true; - -// Query defines the gRPC querier service for reward module. -service Query { - - // RewardProgramByID returns a reward program matching the ID. - rpc RewardProgramByID(QueryRewardProgramByIDRequest) returns (QueryRewardProgramByIDResponse) { - option (google.api.http).get = "/provenance/rewards/v1/reward_programs/{id}"; - } - // RewardPrograms returns a list of reward programs matching the query type. - rpc RewardPrograms(QueryRewardProgramsRequest) returns (QueryRewardProgramsResponse) { - option (google.api.http).get = "/provenance/rewards/v1/reward_programs"; - } - - // ClaimPeriodRewardDistributions returns a list of claim period reward distributions matching the claim_status. - rpc ClaimPeriodRewardDistributions(QueryClaimPeriodRewardDistributionsRequest) - returns (QueryClaimPeriodRewardDistributionsResponse) { - option (google.api.http).get = "/provenance/rewards/v1/claim_period_reward_distributions"; - } - - // ClaimPeriodRewardDistributionsByID returns a claim period reward distribution matching the ID. - rpc ClaimPeriodRewardDistributionsByID(QueryClaimPeriodRewardDistributionsByIDRequest) - returns (QueryClaimPeriodRewardDistributionsByIDResponse) { - option (google.api.http).get = - "/provenance/rewards/v1/claim_period_reward_distributions/{reward_id}/claim_periods/{claim_period_id}"; - } - - // RewardDistributionsByAddress returns a list of reward claims belonging to the account and matching the claim - // status. - rpc RewardDistributionsByAddress(QueryRewardDistributionsByAddressRequest) - returns (QueryRewardDistributionsByAddressResponse) { - option (google.api.http).get = "/provenance/rewards/v1/reward_claims/{address}"; - } -} - -// QueryRewardProgramByIDRequest queries for the Reward Program with an identifier of id -message QueryRewardProgramByIDRequest { - // The id of the reward program to query. - uint64 id = 1; -} - -// QueryRewardProgramByIDResponse contains the requested RewardProgram -message QueryRewardProgramByIDResponse { - // The reward program object that was queried for. - RewardProgram reward_program = 1; -} - -// QueryRewardProgramsRequest queries for all reward programs matching the query_type -message QueryRewardProgramsRequest { - // QueryType is the state of reward program to query - enum QueryType { - // unspecified type - QUERY_TYPE_UNSPECIFIED = 0; - // all reward programs states - QUERY_TYPE_ALL = 1; - // pending reward program state= - QUERY_TYPE_PENDING = 2; - // active reward program state - QUERY_TYPE_ACTIVE = 3; - // pending and active reward program states - QUERY_TYPE_OUTSTANDING = 4; - // finished reward program state - QUERY_TYPE_FINISHED = 5; - } - // A filter on the types of reward programs. - QueryType query_type = 1; - // pagination defines an optional pagination for the request. - cosmos.base.query.v1beta1.PageRequest pagination = 99; -} - -// QueryRewardProgramsResponse contains the list of RewardPrograms matching the query -message QueryRewardProgramsResponse { - // List of RewardProgram objects matching the query_type. - repeated RewardProgram reward_programs = 1 [(gogoproto.nullable) = false]; - // pagination defines an optional pagination for the response. - cosmos.base.query.v1beta1.PageResponse pagination = 99; -} - -// QueryClaimPeriodRewardDistributionsRequest queries for all the ClaimPeriodRewardDistributions with pagination. -message QueryClaimPeriodRewardDistributionsRequest { - // pagination defines an optional pagination for the request. - cosmos.base.query.v1beta1.PageRequest pagination = 99; -} - -// QueryClaimPeriodRewardDistributionsResponse returns the list of paginated ClaimPeriodRewardDistributions -message QueryClaimPeriodRewardDistributionsResponse { - // List of all ClaimPeriodRewardDistribution objects queried for. - repeated ClaimPeriodRewardDistribution claim_period_reward_distributions = 1 [(gogoproto.nullable) = false]; - // pagination defines an optional pagination for the response. - cosmos.base.query.v1beta1.PageResponse pagination = 99; -} - -// QueryClaimPeriodRewardDistributionsByIDRequest queries for a single ClaimPeriodRewardDistribution -message QueryClaimPeriodRewardDistributionsByIDRequest { - // The reward program that the claim period reward distribution belongs to. - uint64 reward_id = 1; - // The claim period that the claim period reward distribution was created for. - uint64 claim_period_id = 2; -} - -// QueryClaimPeriodRewardDistributionsByIDResponse returns the requested ClaimPeriodRewardDistribution -message QueryClaimPeriodRewardDistributionsByIDResponse { - // The ClaimPeriodRewardDistribution object that was queried for. - ClaimPeriodRewardDistribution claim_period_reward_distribution = 1; -} - -// QueryRewardDistributionsByAddressRequest queries for reward claims by address that match the claim_status. -message QueryRewardDistributionsByAddressRequest { - // The address that the claim belongs to. - string address = 1; - // The status that the reward account must have. - RewardAccountState.ClaimStatus claim_status = 2; - // pagination defines an optional pagination for the request. - cosmos.base.query.v1beta1.PageRequest pagination = 99; -} - -// QueryRewardDistributionsByAddressResponse returns the reward claims for an address that match the claim_status. -message QueryRewardDistributionsByAddressResponse { - // The address that the reward account belongs to. - string address = 1; - // List of RewardAccounts queried for. - repeated RewardAccountResponse reward_account_state = 2 [(gogoproto.nullable) = false]; - // pagination defines an optional pagination for the response. - cosmos.base.query.v1beta1.PageResponse pagination = 99; -} - -// RewardAccountResponse is an address' reward claim for a reward program's claim period. -message RewardAccountResponse { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // The id of the reward program that this claim belongs to. - uint64 reward_program_id = 1; - - // total rewards claimed for all eligible claim periods in program. - cosmos.base.v1beta1.Coin total_reward_claim = 2 [(gogoproto.nullable) = false]; - // The status of the claim. - RewardAccountState.ClaimStatus claim_status = 3; - // The claim period that the claim belongs to. - uint64 claim_id = 4; -} diff --git a/proto/provenance/reward/v1/reward.proto b/proto/provenance/reward/v1/reward.proto deleted file mode 100644 index 494b3e5579..0000000000 --- a/proto/provenance/reward/v1/reward.proto +++ /dev/null @@ -1,210 +0,0 @@ -syntax = "proto3"; -package provenance.reward.v1; - -import "gogoproto/gogo.proto"; -import "google/protobuf/timestamp.proto"; -import "cosmos/base/v1beta1/coin.proto"; -import "cosmos_proto/cosmos.proto"; - -option go_package = "github.com/provenance-io/provenance/x/reward/types"; -option java_package = "io.provenance.reward.v1"; -option java_multiple_files = true; - -// RewardProgram -message RewardProgram { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - // State is the state of the reward program - enum State { - // undefined program state - STATE_UNSPECIFIED = 0; - // pending state of reward program - STATE_PENDING = 1; - // started state of reward program - STATE_STARTED = 2; - // finished state of reward program - STATE_FINISHED = 3; - // expired state of reward program - STATE_EXPIRED = 4; - } - - // An integer to uniquely identify the reward program. - uint64 id = 1; - // Name to help identify the Reward Program.(MaxTitleLength=140) - string title = 2; - // Short summary describing the Reward Program.(MaxDescriptionLength=10000) - string description = 3; - // address that provides funds for the total reward pool. - string distribute_from_address = 4; - // The total amount of funding given to the RewardProgram. - cosmos.base.v1beta1.Coin total_reward_pool = 5 [(gogoproto.nullable) = false]; - // The remaining funds available to distribute after n claim periods have passed. - cosmos.base.v1beta1.Coin remaining_pool_balance = 6 [(gogoproto.nullable) = false]; - // The total amount of all funds claimed by participants for all past claim periods. - cosmos.base.v1beta1.Coin claimed_amount = 7 [(gogoproto.nullable) = false]; - // Maximum reward per claim period per address. - cosmos.base.v1beta1.Coin max_reward_by_address = 8 [(gogoproto.nullable) = false]; - // Minimum amount of coins for a program to rollover. - cosmos.base.v1beta1.Coin minimum_rollover_amount = 9 [(gogoproto.nullable) = false]; - // Number of seconds that a claim period lasts. - uint64 claim_period_seconds = 10; - // Time that a RewardProgram should start and switch to STARTED state. - google.protobuf.Timestamp program_start_time = 11 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - // Time that a RewardProgram is expected to end, based on data when it was setup. - google.protobuf.Timestamp expected_program_end_time = 12 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - // Time that a RewardProgram MUST end. - google.protobuf.Timestamp program_end_time_max = 13 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - // Used internally to calculate and track the current claim period's ending time. - google.protobuf.Timestamp claim_period_end_time = 14 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - // Time the RewardProgram switched to FINISHED state. Initially set as empty. - google.protobuf.Timestamp actual_program_end_time = 15 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - // Number of claim periods this program will run for. - uint64 claim_periods = 16; - // Current claim period of the RewardProgram. Uses 1-based indexing. - uint64 current_claim_period = 17; - // maximum number of claim periods a reward program can rollover. - uint64 max_rollover_claim_periods = 18; - // Current state of the RewardProgram. - State state = 19; - // Grace period after a RewardProgram FINISHED. It is the number of seconds until a RewardProgram enters the EXPIRED - // state. - uint64 expiration_offset = 20; - // Actions that count towards the reward. - repeated QualifyingAction qualifying_actions = 21 [(gogoproto.nullable) = false]; -} - -// ClaimPeriodRewardDistribution, this is updated at the end of every claim period. -message ClaimPeriodRewardDistribution { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // The claim period id. - uint64 claim_period_id = 1; - // The id of the reward program that this reward belongs to. - uint64 reward_program_id = 2; - // The sum of all the granted rewards for this claim period. - cosmos.base.v1beta1.Coin total_rewards_pool_for_claim_period = 3 [(gogoproto.nullable) = false]; - // The final allocated rewards for this claim period. - cosmos.base.v1beta1.Coin rewards_pool = 4 [(gogoproto.nullable) = false]; - // The total number of granted shares for this claim period. - int64 total_shares = 5; - // A flag representing if the claim period for this reward has ended. - bool claim_period_ended = 6; -} - -// RewardAccountState contains state at the claim period level for a specific address. -message RewardAccountState { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - // ClaimStatus is the state a claim is in - enum ClaimStatus { - // undefined state - CLAIM_STATUS_UNSPECIFIED = 0; - // unclaimable status - CLAIM_STATUS_UNCLAIMABLE = 1; - // unclaimable claimable - CLAIM_STATUS_CLAIMABLE = 2; - // unclaimable claimed - CLAIM_STATUS_CLAIMED = 3; - // unclaimable expired - CLAIM_STATUS_EXPIRED = 4; - } - // The id of the reward program that this share belongs to. - uint64 reward_program_id = 1; - // The id of the claim period that the share belongs to. - uint64 claim_period_id = 2; - // Owner of the reward account state. - string address = 3; - // The number of actions performed by this account, mapped by action type. - repeated ActionCounter action_counter = 4; - // The amount of granted shares for the address in the reward program's claim period. - uint64 shares_earned = 5; - // The status of the claim. - ClaimStatus claim_status = 6; -} - -// QualifyingAction can be one of many action types. -message QualifyingAction { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - // type of action to process - oneof type { - ActionDelegate delegate = 1; - ActionTransfer transfer = 2; - ActionVote vote = 3; - } -} - -// QualifyingActions contains a list of QualifyingActions. -message QualifyingActions { - // The actions that count towards the reward. - repeated QualifyingAction qualifying_actions = 1 [(gogoproto.nullable) = false]; -} - -// ActionDelegate represents the delegate action and its required eligibility criteria. -message ActionDelegate { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // Minimum number of successful delegates. - uint64 minimum_actions = 1; - // Maximum number of successful delegates. - uint64 maximum_actions = 2; - // Minimum amount that the user must have currently delegated on the validator. - cosmos.base.v1beta1.Coin minimum_delegation_amount = 3; - // Maximum amount that the user must have currently delegated on the validator. - cosmos.base.v1beta1.Coin maximum_delegation_amount = 4; - // Minimum percentile that can be below the validator's power ranking. - string minimum_active_stake_percentile = 5 [ - (cosmos_proto.scalar) = "cosmos.Dec", - (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", - (gogoproto.nullable) = false - ]; - // Maximum percentile that can be below the validator's power ranking. - string maximum_active_stake_percentile = 6 [ - (cosmos_proto.scalar) = "cosmos.Dec", - (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", - (gogoproto.nullable) = false - ]; -} - -// ActionTransfer represents the transfer action and its required eligibility criteria. -message ActionTransfer { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // Minimum number of successful transfers. - uint64 minimum_actions = 1; - // Maximum number of successful transfers. - uint64 maximum_actions = 2; - // Minimum delegation amount the account must have across all validators, for the transfer action to be counted. - cosmos.base.v1beta1.Coin minimum_delegation_amount = 3 [(gogoproto.nullable) = false]; -} - -// ActionVote represents the voting action and its required eligibility criteria. -message ActionVote { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // Minimum number of successful votes. - uint64 minimum_actions = 1; - // Maximum number of successful votes. - uint64 maximum_actions = 2; - // Minimum delegation amount the account must have across all validators, for the vote action to be counted. - cosmos.base.v1beta1.Coin minimum_delegation_amount = 3 [(gogoproto.nullable) = false]; - // Positive multiplier that is applied to the shares awarded by the vote action when conditions - // are met(for now the only condition is the current vote is a validator vote). A value of zero will behave the same - // as one - uint64 validator_multiplier = 4; -} - -// ActionCounter is a key-value pair that maps action type to the number of times it was performed. -message ActionCounter { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // The type of action performed. - string action_type = 1; - // The number of times this action has been performed - uint64 number_of_actions = 2; -} \ No newline at end of file diff --git a/proto/provenance/reward/v1/tx.proto b/proto/provenance/reward/v1/tx.proto deleted file mode 100644 index 9664c799b4..0000000000 --- a/proto/provenance/reward/v1/tx.proto +++ /dev/null @@ -1,143 +0,0 @@ -syntax = "proto3"; -package provenance.reward.v1; - -import "gogoproto/gogo.proto"; -import "google/protobuf/timestamp.proto"; -import "cosmos/base/v1beta1/coin.proto"; -import "provenance/reward/v1/reward.proto"; -import "cosmos/msg/v1/msg.proto"; - -option go_package = "github.com/provenance-io/provenance/x/reward/types"; -option java_package = "io.provenance.reward.v1"; -option java_multiple_files = true; - -// Msg -service Msg { - - // CreateRewardProgram is the RPC endpoint for creating a rewards program - rpc CreateRewardProgram(MsgCreateRewardProgramRequest) returns (MsgCreateRewardProgramResponse); - - // EndRewardProgram is the RPC endpoint for ending a rewards program - rpc EndRewardProgram(MsgEndRewardProgramRequest) returns (MsgEndRewardProgramResponse); - - // ClaimRewards is the RPC endpoint for claiming rewards belonging to completed claim periods of a reward program - rpc ClaimRewards(MsgClaimRewardsRequest) returns (MsgClaimRewardsResponse); - - // ClaimAllRewards is the RPC endpoint for claiming rewards for completed claim periods of every reward program for - // the signer of the tx. - rpc ClaimAllRewards(MsgClaimAllRewardsRequest) returns (MsgClaimAllRewardsResponse); -} - -// MsgCreateRewardProgramRequest is the request type for creating a reward program RPC -message MsgCreateRewardProgramRequest { - option (cosmos.msg.v1.signer) = "distribute_from_address"; - - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // title for the reward program. - string title = 1; - // description for the reward program. - string description = 2; - // provider address for the reward program funds and signer of message. - string distribute_from_address = 3; - // total reward pool for the reward program. - cosmos.base.v1beta1.Coin total_reward_pool = 4 [(gogoproto.nullable) = false]; - // maximum amount of funds an address can be rewarded per claim period. - cosmos.base.v1beta1.Coin max_reward_per_claim_address = 5 [(gogoproto.nullable) = false]; - // start time of the reward program. - google.protobuf.Timestamp program_start_time = 6 [ - (gogoproto.stdtime) = true, - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "program_start_time,omitempty", - (gogoproto.moretags) = "yaml:\"program_start_time,omitempty\"" - ]; - // number of claim periods the reward program runs for. - uint64 claim_periods = 7; - // number of days a claim period will exist. - uint64 claim_period_days = 8; - // maximum number of claim periods a reward program can rollover. - uint64 max_rollover_claim_periods = 9; - // number of days before a reward program will expire after it has ended. - uint64 expire_days = 10; - // actions that count towards the reward. - repeated QualifyingAction qualifying_actions = 11 [(gogoproto.nullable) = false]; -} - -// MsgCreateRewardProgramResponse is the response type for creating a reward program RPC -message MsgCreateRewardProgramResponse { - // reward program id that is generated on creation. - uint64 id = 1; -} - -// MsgEndRewardProgramRequest is the request type for ending a reward program RPC -message MsgEndRewardProgramRequest { - option (cosmos.msg.v1.signer) = "program_owner_address"; - - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // reward program id to end. - uint64 reward_program_id = 1; - // owner of the reward program that funds were distributed from. - string program_owner_address = 2; -} - -// MsgEndRewardProgramResponse is the response type for ending a reward program RPC -message MsgEndRewardProgramResponse {} - -// MsgClaimRewardsRequest is the request type for claiming reward from reward program RPC -message MsgClaimRewardsRequest { - option (cosmos.msg.v1.signer) = "reward_address"; - - // reward program id to claim rewards. - uint64 reward_program_id = 1; - // reward address and signer of msg to send claimed rewards to. - string reward_address = 2; -} - -// MsgClaimRewardsResponse is the response type for claiming reward from reward program RPC -message MsgClaimRewardsResponse { - option (gogoproto.equal) = true; - // details about acquired rewards from reward program. - RewardProgramClaimDetail claim_details = 1 [(gogoproto.nullable) = false]; -} - -// MsgClaimRewardsResponse is the request type for claiming rewards from all reward programs RPC -message MsgClaimAllRewardsRequest { - option (cosmos.msg.v1.signer) = "reward_address"; - - // reward address and signer of msg to send claimed rewards to. - string reward_address = 1; -} - -// MsgClaimRewardsResponse is the response type for claiming rewards from all reward programs RPC -message MsgClaimAllRewardsResponse { - option (gogoproto.equal) = true; - // total rewards claimed for all eligible claim periods in all programs. - repeated cosmos.base.v1beta1.Coin total_reward_claim = 1 [(gogoproto.nullable) = false]; - // details about acquired rewards from a reward program. - repeated RewardProgramClaimDetail claim_details = 2; -} - -// ClaimedRewardPeriodDetail is information regarding an addresses' shares and reward for a claim period. -message ClaimedRewardPeriodDetail { - option (gogoproto.equal) = true; - // claim period id - uint64 claim_period_id = 1; - // total shares accumulated for claim period - uint64 total_shares = 2; - // total rewards for claim period - cosmos.base.v1beta1.Coin claim_period_reward = 3 [(gogoproto.nullable) = false]; -} - -// RewardProgramClaimDetail is the response object regarding an address's shares and reward for a reward program. -message RewardProgramClaimDetail { - option (gogoproto.equal) = true; - // reward program id. - uint64 reward_program_id = 1; - // total rewards claimed for all eligible claim periods in program. - cosmos.base.v1beta1.Coin total_reward_claim = 2 [(gogoproto.nullable) = false]; - // claim period details. - repeated ClaimedRewardPeriodDetail claimed_reward_period_details = 3; -} \ No newline at end of file diff --git a/third_party/proto/cosmos/authz/v1beta1/authz.proto b/third_party/proto/cosmos/authz/v1beta1/authz.proto index 3fee736436..f10e819e4b 100644 --- a/third_party/proto/cosmos/authz/v1beta1/authz.proto +++ b/third_party/proto/cosmos/authz/v1beta1/authz.proto @@ -21,6 +21,19 @@ message GenericAuthorization { string msg = 1; } +// CountAuthorization gives the grantee unrestricted permissions to execute +// the provided method on behalf of the granter's account up to the allowed authorizations count. +message CountAuthorization { + option (amino.name) = "cosmos-sdk/CountAuthorization"; + option (cosmos_proto.implements_interface) = "cosmos.authz.v1beta1.Authorization"; + + // Msg, identified by it's type URL, to grant unrestricted permissions to execute + string msg = 1; + + // Allowed number of authorizations assigned to grantee + int32 allowed_authorizations = 2; +} + // Grant gives permissions to execute // the provide method with expiration time. message Grant { diff --git a/third_party/proto/cosmos/bank/v1beta1/tx.proto b/third_party/proto/cosmos/bank/v1beta1/tx.proto index a4e8fae41f..49660b7fa7 100644 --- a/third_party/proto/cosmos/bank/v1beta1/tx.proto +++ b/third_party/proto/cosmos/bank/v1beta1/tx.proto @@ -33,6 +33,9 @@ service Msg { // // Since: cosmos-sdk 0.47 rpc SetSendEnabled(MsgSetSendEnabled) returns (MsgSetSendEnabledResponse); + + // UpdateDenomMetadata defines a method for updating the denom metadata. Only usable in x/gov proposal. + rpc UpdateDenomMetadata(MsgUpdateDenomMetadata) returns (MsgUpdateDenomMetadataResponse); } // MsgSend represents a message to send coins from one account to another. @@ -122,3 +125,19 @@ message MsgSetSendEnabled { // // Since: cosmos-sdk 0.47 message MsgSetSendEnabledResponse {} + +// MsgUpdateDenomMetadata defines the Msg/UpdateDenomMetadata request type. +message MsgUpdateDenomMetadata { + option (cosmos.msg.v1.signer) = "from_address"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string from_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string title = 2; + string description = 3; + Metadata metadata = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +// MsgUpdateDenomMetadataResponse defines the Msg/UpdateDenomMetadata response type. +message MsgUpdateDenomMetadataResponse {} \ No newline at end of file diff --git a/x/marker/keeper/keeper_test.go b/x/marker/keeper/keeper_test.go index 59dd7ff480..48f5e513ce 100644 --- a/x/marker/keeper/keeper_test.go +++ b/x/marker/keeper/keeper_test.go @@ -34,7 +34,6 @@ import ( "github.com/provenance-io/provenance/x/exchange" markerkeeper "github.com/provenance-io/provenance/x/marker/keeper" "github.com/provenance-io/provenance/x/marker/types" - rewardtypes "github.com/provenance-io/provenance/x/reward/types" ) func TestAccountMapperGetSet(t *testing.T) { @@ -2886,7 +2885,6 @@ func TestReqAttrBypassAddrs(t *testing.T) { // Tests both GetReqAttrBypassAddrs and IsReqAttrBypassAddr. expectedNames := []string{ authtypes.FeeCollectorName, - rewardtypes.ModuleName, // quarantine.ModuleName, // TODO[1760]: quarantine govtypes.ModuleName, distrtypes.ModuleName, diff --git a/x/reward/abci.go b/x/reward/abci.go deleted file mode 100644 index 0cc956dcb1..0000000000 --- a/x/reward/abci.go +++ /dev/null @@ -1,27 +0,0 @@ -package reward - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/keeper" -) - -// BeginBlocker processes rewards module updates -func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { - defer func() { - if r := recover(); r != nil { - ctx.Logger().Error("reward BeginBlocker recovered from panic:", "r", r) - } - }() - k.UpdateUnexpiredRewardsProgram(ctx) -} - -// EndBlocker processes events for reward programs -func EndBlocker(ctx sdk.Context, k keeper.Keeper) { - defer func() { - if r := recover(); r != nil { - ctx.Logger().Error("reward EndBlocker recovered from panic:", "r", r) - } - }() - k.ProcessTransactions(ctx) -} diff --git a/x/reward/abci_test.go b/x/reward/abci_test.go deleted file mode 100644 index aa71190fca..0000000000 --- a/x/reward/abci_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package reward_test - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - - sdk "github.com/cosmos/cosmos-sdk/types" - - simapp "github.com/provenance-io/provenance/app" - "github.com/provenance-io/provenance/x/reward" -) - -func TestEndBlockWithNoActiveRewards(t *testing.T) { - var app *simapp.App - var ctx sdk.Context - - now := time.Now() - - app = simapp.Setup(t) - ctx = app.BaseApp.NewContext(false) - ctx = ctx.WithBlockHeight(1).WithBlockTime(now) - - ctx = ctx.WithBlockHeight(2) - require.NotPanics(t, func() { - reward.EndBlocker(ctx, app.RewardKeeper) - }) -} - -func TestBeginBlockWithNoActiveRewards(t *testing.T) { - var app *simapp.App - var ctx sdk.Context - - now := time.Now() - - app = simapp.Setup(t) - ctx = app.BaseApp.NewContext(false) - ctx = ctx.WithBlockHeight(1).WithBlockTime(now) - - ctx = ctx.WithBlockHeight(2) - require.NotPanics(t, func() { - reward.BeginBlocker(ctx, app.RewardKeeper) - }) -} diff --git a/x/reward/client/cli/cli_test.go b/x/reward/client/cli/cli_test.go deleted file mode 100644 index 06447885d1..0000000000 --- a/x/reward/client/cli/cli_test.go +++ /dev/null @@ -1,937 +0,0 @@ -package cli_test - -import ( - "fmt" - "testing" - "time" - - "github.com/stretchr/testify/suite" - - cmtcli "github.com/cometbft/cometbft/libs/cli" - - sdkmath "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/testutil/network" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - "github.com/provenance-io/provenance/internal/antewrapper" - "github.com/provenance-io/provenance/internal/pioconfig" - "github.com/provenance-io/provenance/testutil" - rewardcli "github.com/provenance-io/provenance/x/reward/client/cli" - "github.com/provenance-io/provenance/x/reward/types" - rewardtypes "github.com/provenance-io/provenance/x/reward/types" -) - -type IntegrationTestSuite struct { - suite.Suite - - cfg network.Config - network *network.Network - keyring keyring.Keyring - keyringDir string - - accountAddr sdk.AccAddress - accountKey *secp256k1.PrivKey - accountAddresses []sdk.AccAddress - - activeRewardProgram types.RewardProgram - pendingRewardProgram types.RewardProgram - finishedRewardProgram types.RewardProgram - expiredRewardProgram types.RewardProgram - qualifyingActions []types.QualifyingAction -} - -func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) -} - -func (s *IntegrationTestSuite) SetupSuite() { - s.T().Log("setting up integration test suite") - pioconfig.SetProvenanceConfig("", 0) - s.accountKey = secp256k1.GenPrivKeyFromSecret([]byte("acc2")) - addr, err := sdk.AccAddressFromHexUnsafe(s.accountKey.PubKey().Address().String()) - s.Require().NoError(err) - s.accountAddr = addr - - s.cfg = testutil.DefaultTestNetworkConfig() - genesisState := s.cfg.GenesisState - - s.cfg.NumValidators = 1 - s.GenerateAccountsWithKeyrings(2) - - var genBalances []banktypes.Balance - for i := range s.accountAddresses { - genBalances = append(genBalances, banktypes.Balance{Address: s.accountAddresses[i].String(), Coins: sdk.NewCoins( - sdk.NewInt64Coin("nhash", 100_000_000), sdk.NewInt64Coin(s.cfg.BondDenom, 100_000_000), - ).Sort()}) - } - genBalances = append(genBalances, banktypes.Balance{Address: "cosmos1w6t0l7z0yerj49ehnqwqaayxqpe3u7e23edgma", Coins: sdk.NewCoins( - sdk.NewInt64Coin("nhash", 100_000_000), sdk.NewInt64Coin(s.cfg.BondDenom, 100_000_000)).Sort()}) - var bankGenState banktypes.GenesisState - bankGenState.Params = banktypes.DefaultParams() - bankGenState.Balances = genBalances - bankDataBz, err := s.cfg.Codec.MarshalJSON(&bankGenState) - s.Require().NoError(err) - genesisState[banktypes.ModuleName] = bankDataBz - - var authData authtypes.GenesisState - var genAccounts []authtypes.GenesisAccount - authData.Params = authtypes.DefaultParams() - genAccounts = append(genAccounts, authtypes.NewBaseAccount(s.accountAddresses[0], nil, 3, 0)) - genAccounts = append(genAccounts, authtypes.NewBaseAccount(s.accountAddresses[1], nil, 4, 0)) - accounts, err := authtypes.PackAccounts(genAccounts) - s.Require().NoError(err) - authData.Accounts = accounts - authDataBz, err := s.cfg.Codec.MarshalJSON(&authData) - s.Require().NoError(err) - genesisState[authtypes.ModuleName] = authDataBz - - now := time.Now().UTC() - minimumDelegation := sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 0) - maximumDelegation := sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 10) - s.qualifyingActions = []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - } - - s.activeRewardProgram = types.NewRewardProgram( - "active title", - "active description", - 1, - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - now, - 60*60, - 3, - 0, - 0, - s.qualifyingActions, - ) - s.activeRewardProgram.State = types.RewardProgram_STATE_STARTED - - s.finishedRewardProgram = types.NewRewardProgram( - "finished title", - "finished description", - 2, - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - now.Add(-60*60*time.Second), - 60*60, - 3, - 0, - 60*60*24, - s.qualifyingActions, - ) - s.finishedRewardProgram.ActualProgramEndTime = now - s.finishedRewardProgram.State = types.RewardProgram_STATE_FINISHED - - s.pendingRewardProgram = types.NewRewardProgram( - "pending title", - "pending description", - 3, - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - now.Add(60*60*time.Second), - 60*60, - 3, - 0, - 0, - s.qualifyingActions, - ) - s.pendingRewardProgram.State = types.RewardProgram_STATE_PENDING - - s.expiredRewardProgram = types.NewRewardProgram( - "expired title", - "expired description", - 4, - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - now.Add(-60*60*time.Second), - 60*60, - 3, - 0, - 0, - s.qualifyingActions, - ) - s.expiredRewardProgram.State = types.RewardProgram_STATE_EXPIRED - - claimPeriodRewardDistributions := make([]rewardtypes.ClaimPeriodRewardDistribution, 101) - for i := 0; i < 101; i++ { - claimPeriodRewardDistributions[i] = rewardtypes.NewClaimPeriodRewardDistribution(uint64(i+1), 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 10), int64(i), false) - } - - rewardAccountState := make([]rewardtypes.RewardAccountState, 101) - for i := 0; i < 101; i++ { - rewardAccountState[i] = rewardtypes.NewRewardAccountState(1, uint64(i+1), s.accountAddr.String(), 10, []*types.ActionCounter{}) - switch i % 4 { - case 0: - rewardAccountState[i].ClaimStatus = rewardtypes.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE - case 1: - rewardAccountState[i].ClaimStatus = rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMABLE - case 2: - rewardAccountState[i].ClaimStatus = rewardtypes.RewardAccountState_CLAIM_STATUS_CLAIMED - case 3: - rewardAccountState[i].ClaimStatus = rewardtypes.RewardAccountState_CLAIM_STATUS_EXPIRED - } - } - - rewardData := rewardtypes.NewGenesisState( - uint64(5), - []rewardtypes.RewardProgram{ - s.activeRewardProgram, s.pendingRewardProgram, s.finishedRewardProgram, s.expiredRewardProgram, - }, - claimPeriodRewardDistributions, - rewardAccountState, - ) - - rewardDataBz, err := s.cfg.Codec.MarshalJSON(rewardData) - s.Require().NoError(err) - genesisState[rewardtypes.ModuleName] = rewardDataBz - - s.cfg.GenesisState = genesisState - - s.cfg.ChainID = antewrapper.SimAppChainID - s.cfg.TimeoutCommit = 500 * time.Millisecond - - s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) - s.Require().NoError(err, "network.New") - - _, err = s.network.WaitForHeight(1) - s.Require().NoError(err, "WaitForHeight") -} - -func (s *IntegrationTestSuite) TearDownSuite() { - s.Require().NoError(s.network.WaitForNextBlock()) - s.T().Log("tearing down integration test suite") - s.network.Cleanup() -} - -func (s *IntegrationTestSuite) GenerateAccountsWithKeyrings(number int) { - path := hd.CreateHDPath(118, 0, 0).String() - s.keyringDir = s.T().TempDir() - kr, err := keyring.New(s.T().Name(), "test", s.keyringDir, nil, s.cfg.Codec) - s.Require().NoError(err) - s.keyring = kr - for i := 0; i < number; i++ { - keyId := fmt.Sprintf("test_key%v", i) - info, _, err := kr.NewMnemonic(keyId, keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1) - s.Require().NoError(err) - addr, err := info.GetAddress() - if err != nil { - panic(err) - } - s.accountAddresses = append(s.accountAddresses, addr) - } -} - -func (s *IntegrationTestSuite) TestQueryRewardPrograms() { - testCases := []struct { - name string - queryTypeArg string - byId bool - expectErrMsg string - expectedCode uint32 - expectedIds []uint64 - }{ - {"query all reward programs", - "all", - false, - "", - 0, - []uint64{1, 2, 3, 4, 5}, - }, - {"query active reward programs", - "active", - false, - "", - 0, - []uint64{1}, - }, - {"query pending reward programs", - "pending", - false, - "", - 0, - []uint64{3, 5}, - }, - {"query completed reward programs", - "completed", - false, - "", - 0, - []uint64{2, 4}, - }, - {"query outstanding reward programs", - "outstanding", - false, - "", - 0, - []uint64{1, 3, 5}, - }, - {"query by id reward programs", - "2", - true, - "", - 0, - []uint64{2}, - }, - {"query by id reward programs", - "99", - true, - "failed to query reward program 99: rpc error: code = Unknown desc = rpc error: code = Internal desc = unable to query for reward program by ID: reward program not found: unknown request", - 0, - []uint64{2}, - }, - {"query invalid query type", - "invalid", - true, - "invalid argument arg : invalid", - 0, - []uint64{}, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - clientCtx := s.network.Validators[0].ClientCtx - out, err := clitestutil.ExecTestCLICmd(clientCtx, rewardcli.GetRewardProgramCmd(), []string{tc.queryTypeArg, fmt.Sprintf("--%s=json", cmtcli.OutputFlag)}) - if len(tc.expectErrMsg) > 0 { - s.Assert().EqualError(err, tc.expectErrMsg) - } else if tc.byId { - var response types.QueryRewardProgramByIDResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(err) - s.Assert().Equal(tc.expectedIds[0], response.RewardProgram.Id) - } else { - var response types.QueryRewardProgramsResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(err) - var rewardProgramIds []uint64 - for _, rp := range response.RewardPrograms { - rewardProgramIds = append(rewardProgramIds, rp.Id) - } - s.Assert().ElementsMatch(tc.expectedIds, rewardProgramIds, "should have all expected reward program ids") - } - }) - } -} - -func (s *IntegrationTestSuite) TestQueryClaimPeriodRewardDistributionAll() { - defaultMaxQueryIds := make([]uint64, 100) - for i := 0; i < 100; i++ { - defaultMaxQueryIds[i] = uint64(i + 1) - } - testCases := []struct { - name string - args []string - byId bool - expectErrMsg string - expectedCode uint32 - expectedIds []uint64 - }{ - {"query all reward programs get default page size of 100", - []string{ - "all", - }, - false, - "", - 0, - defaultMaxQueryIds, - }, - {"query all reward programs max out to default page size", - []string{ - "all", - "--limit", - "100", - }, - false, - "", - 0, - defaultMaxQueryIds, - }, - {"query all reward programs first page with 5 results", - []string{ - "all", - "--limit", - "5", - }, - false, - "", - 0, - []uint64{1, 2, 3, 4, 5}, - }, - {"query all reward programs second page with 5 results", - []string{ - "all", - "--limit", - "5", - "--page", - "2", - }, - false, - "", - 0, - []uint64{6, 7, 8, 9, 10}, - }, - {"query by program id and claim period", - []string{ - "1", - "2", - }, - true, - "", - 0, - []uint64{1, 2}, - }, - { - "query without claim period", - []string{ - "1", - }, - true, - "a reward_program_id and an claim_period_id are required", - 0, - []uint64{}, - }, - { - "query with invalid reward program id format", - []string{ - "1", - "a", - }, - true, - "strconv.Atoi: parsing \"a\": invalid syntax", - 0, - []uint64{}, - }, - { - "query with invalid reward program id format", - []string{ - "a", - "1", - }, - true, - "strconv.Atoi: parsing \"a\": invalid syntax", - 0, - []uint64{}, - }, - { - "query with invalid reward program id format", - []string{ - "100", - "100", - }, - true, - "reward does not exist for reward-id: 100 claim-id 100", - 0, - []uint64{}, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - clientCtx := s.network.Validators[0].ClientCtx - out, err := clitestutil.ExecTestCLICmd(clientCtx, rewardcli.GetClaimPeriodRewardDistributionCmd(), append(tc.args, []string{fmt.Sprintf("--%s=json", cmtcli.OutputFlag)}...)) - if len(tc.expectErrMsg) > 0 { - s.Assert().EqualError(err, tc.expectErrMsg) - } else if tc.byId { - var response types.QueryClaimPeriodRewardDistributionsByIDResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(err) - s.Assert().Equal(tc.expectedIds[0], response.ClaimPeriodRewardDistribution.RewardProgramId) - s.Assert().Equal(tc.expectedIds[1], response.ClaimPeriodRewardDistribution.ClaimPeriodId) - } else { - var response types.QueryClaimPeriodRewardDistributionsResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(err) - var claimPeriodRewardDistIds []uint64 - for _, cprd := range response.ClaimPeriodRewardDistributions { - claimPeriodRewardDistIds = append(claimPeriodRewardDistIds, cprd.ClaimPeriodId) - } - s.Assert().ElementsMatch(tc.expectedIds, claimPeriodRewardDistIds, "should have all expected claim period ids") - } - }) - } -} - -func (s *IntegrationTestSuite) TestGetCmdRewardProgramAdd() { - actions := "{\"qualifying_actions\":[{\"delegate\":{\"minimum_actions\":\"0\",\"maximum_actions\":\"1\",\"minimum_delegation_amount\":{\"denom\":\"nhash\",\"amount\":\"0\"},\"maximum_delegation_amount\":{\"denom\":\"nhash\",\"amount\":\"100\"},\"minimum_active_stake_percentile\":\"0.000000000000000000\",\"maximum_active_stake_percentile\":\"1.000000000000000000\"}}]}" - soon := time.Now().Add(time.Hour * 24) - - testCases := []struct { - name string - args []string - expectErrMsg string - expectedCode uint32 - }{ - {"add reward program tx - valid", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52364", - "--claim-period-days=7", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", actions), - }, - "", - 0, - }, - {"add reward program tx - invalid total-reward-pool", - []string{ - "test add reward program", - "description", - "--total-reward-pool=invalid", - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", actions), - }, - "invalid decimal coin expression: invalid", - 0, - }, - {"add reward program tx - invalid max-reward-by-address", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - "--max-reward-by-address=invalid", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", actions), - }, - "invalid decimal coin expression: invalid", - 0, - }, - {"add reward program tx - invalid claim period days", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=-1", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", actions), - }, - "invalid argument \"-1\" for \"--claim-period-days\" flag: strconv.ParseUint: parsing \"-1\": invalid syntax", - 0, - }, - {"add reward program tx - invalid expire days", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=-1", - fmt.Sprintf("--qualifying-actions=%s", actions), - }, - "invalid argument \"-1\" for \"--expire-days\" flag: strconv.ParseUint: parsing \"-1\": invalid syntax", - 0, - }, - {"add reward program tx - invalid reward period days", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=-52", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=1", - fmt.Sprintf("--qualifying-actions=%s", actions), - }, - "invalid argument \"-52\" for \"--claim-periods\" flag: strconv.ParseUint: parsing \"-52\": invalid syntax", - 0, - }, - {"add reward program tx - invalid start time", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=10", - "--start-time=invalid", - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", actions), - }, - "unable to parse time (invalid) required format is RFC3339 (2006-01-02T15:04:05Z07:00) , parsing time \"invalid\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"invalid\" as \"2006\"", - 0, - }, - {"add reward program tx - invalid ec", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", "actions"), - }, - "invalid character 'a' looking for beginning of value", - 0, - }, - {"add reward program tx - invalid type for claim periods", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=abc", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", "actions"), - }, - "invalid argument \"abc\" for \"--claim-periods\" flag: strconv.ParseUint: parsing \"abc\": invalid syntax", - 0, - }, - {"add reward program tx - invalid type for claim period days", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=abc", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - fmt.Sprintf("--qualifying-actions=%s", "actions"), - }, - "invalid argument \"abc\" for \"--claim-period-days\" flag: strconv.ParseUint: parsing \"abc\": invalid syntax", - 0, - }, - {"add reward program tx - invalid type for claim period days", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=abc", - fmt.Sprintf("--qualifying-actions=%s", "actions"), - }, - "invalid argument \"abc\" for \"--expire-days\" flag: strconv.ParseUint: parsing \"abc\": invalid syntax", - 0, - }, - {"add reward program tx - invalid type for claim period days", - []string{ - "test add reward program", - "description", - fmt.Sprintf("--total-reward-pool=580%s", s.cfg.BondDenom), - fmt.Sprintf("--max-reward-by-address=100%s", s.cfg.BondDenom), - "--claim-periods=52", - "--claim-period-days=10", - fmt.Sprintf("--start-time=%s", soon.Format(time.RFC3339)), - "--expire-days=14", - "--max-rollover-periods=abc", - fmt.Sprintf("--qualifying-actions=%s", "actions"), - }, - "invalid argument \"abc\" for \"--max-rollover-periods\" flag: strconv.ParseUint: parsing \"abc\": invalid syntax", - 0, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - clientCtx := s.network.Validators[0].ClientCtx - args := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, s.network.Validators[0].Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), // TODO[1760]: broadcast - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String()), - } - tc.args = append(tc.args, args...) - - out, err := clitestutil.ExecTestCLICmd(clientCtx, rewardcli.GetCmdRewardProgramAdd(), append(tc.args, []string{fmt.Sprintf("--%s=json", cmtcli.OutputFlag)}...)) - var response sdk.TxResponse - marshalErr := clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response) - if len(tc.expectErrMsg) > 0 { - s.Assert().EqualError(err, tc.expectErrMsg) - } else { - s.Assert().NoError(err) - s.Assert().NoError(marshalErr, out.String()) - } - }) - } -} - -func (s *IntegrationTestSuite) TestTxClaimReward() { - testCases := []struct { - name string - claimRewardArg string - expectErrMsg string - expectedCode uint32 - }{ - {"claim rewards tx - valid", - "1", - "", - 0, - }, - {"claim rewards tx - all", - "all", - "", - 0, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - clientCtx := s.network.Validators[0].ClientCtx - args := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, s.network.Validators[0].Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), // TODO[1760]: broadcast - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String()), - } - args = append(args, tc.claimRewardArg) - out, err := clitestutil.ExecTestCLICmd(clientCtx, rewardcli.GetCmdClaimReward(), args) - if len(tc.expectErrMsg) > 0 { - s.Assert().EqualError(err, tc.expectErrMsg) - } else { - var response sdk.TxResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - marshalErr := clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(marshalErr) - s.Assert().Equal(tc.expectedCode, response.Code) - } - }) - } -} - -func (s *IntegrationTestSuite) TestTxEndRewardProgram() { - testCases := []struct { - name string - endRewardProgramId string - expectErrMsg string - expectedCode uint32 - signer string - }{ - { - name: "end reward program - valid", - endRewardProgramId: "1", - expectErrMsg: "", - expectedCode: 0, - signer: s.accountAddresses[0].String(), - }, - { - name: "end reward program - invalid id", - endRewardProgramId: "999", - expectErrMsg: "", - expectedCode: 3, - signer: s.accountAddresses[0].String(), - }, - { - name: "end reward program - invalid state", - endRewardProgramId: "2", - expectErrMsg: "", - expectedCode: 5, - signer: s.accountAddresses[0].String(), - }, - { - name: "end reward program - not authorized", - endRewardProgramId: "1", - expectErrMsg: "", - expectedCode: 4, - signer: s.accountAddresses[1].String(), - }, - { - name: "end reward program - invalid id format", - endRewardProgramId: "abc", - expectErrMsg: "invalid argument : abc", - expectedCode: 0, - signer: s.accountAddresses[0].String(), - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - clientCtx := s.network.Validators[0].ClientCtx.WithKeyringDir(s.keyringDir).WithKeyring(s.keyring) - args := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, tc.signer), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), // TODO[1760]: broadcast - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String()), - } - args = append(args, tc.endRewardProgramId) - out, err := clitestutil.ExecTestCLICmd(clientCtx, rewardcli.GetCmdEndRewardProgram(), args) - if len(tc.expectErrMsg) > 0 { - s.Assert().EqualError(err, tc.expectErrMsg) - } else { - var response sdk.TxResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - marshalErr := clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(marshalErr) - s.Assert().Equal(tc.expectedCode, response.Code) - } - }) - } -} - -func (s *IntegrationTestSuite) TestQueryAllRewardsPerAddress() { - testCases := []struct { - name string - addressArg string - stateArg string - byId bool - expectErrMsg string - expectedCode uint32 - expectedIds []uint64 - expectedLength int64 - }{ - { - name: "query all reward by address", - addressArg: s.accountAddr.String(), - stateArg: "all", - byId: false, - expectErrMsg: "", - expectedCode: 0, - expectedIds: []uint64{1, 2, 3, 4}, - expectedLength: 100, - }, - { - name: "query unclaimable reward by address", - addressArg: s.accountAddr.String(), - stateArg: "unclaimable", - byId: false, - expectErrMsg: "", - expectedCode: 0, - expectedIds: []uint64{1, 5}, - expectedLength: 26, - }, - { - name: "query claimable reward by address", - addressArg: s.accountAddr.String(), - stateArg: "claimable", - byId: false, - expectErrMsg: "", - expectedCode: 0, - expectedIds: []uint64{2, 6}, - expectedLength: 25, - }, - { - name: "query claimed reward by address", - addressArg: s.accountAddr.String(), - stateArg: "claimed", - byId: false, - expectErrMsg: "", - expectedCode: 0, - expectedIds: []uint64{3, 7}, - expectedLength: 25, - }, - { - name: "query expired reward by address", - addressArg: s.accountAddr.String(), - stateArg: "expired", - byId: false, - expectErrMsg: "", - expectedCode: 0, - expectedIds: []uint64{4, 8}, - expectedLength: 25, - }, - { - name: "query reward by address", - addressArg: s.accountAddr.String(), - stateArg: "invalid", - byId: false, - expectErrMsg: "failed to query reward distributions. invalid is not a valid query param", - expectedCode: 0, - expectedIds: []uint64{}, - expectedLength: 0, - }, - { - name: "query reward by invalid address", - addressArg: "invalid address", - stateArg: "expired", - byId: false, - expectErrMsg: "failed to query reward distributions: rpc error: code = Unknown desc = decoding bech32 failed: invalid character in string: ' ': invalid address: unknown request", - expectedCode: 0, - expectedIds: []uint64{}, - expectedLength: 0, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - clientCtx := s.network.Validators[0].ClientCtx - args := []string{tc.addressArg, tc.stateArg, fmt.Sprintf("--%s=json", cmtcli.OutputFlag)} - out, err := clitestutil.ExecTestCLICmd(clientCtx, rewardcli.GetRewardsByAddressCmd(), args) - if len(tc.expectErrMsg) > 0 { - s.Assert().EqualError(err, tc.expectErrMsg) - } else if tc.byId { - var response types.QueryRewardDistributionsByAddressResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(err) - } else { - var response types.QueryRewardDistributionsByAddressResponse - s.Assert().NoError(err) - err = s.cfg.Codec.UnmarshalJSON(out.Bytes(), &response) - s.Assert().NoError(err) - var actualClaimIds []uint64 - for _, ras := range response.RewardAccountState { - if ras.RewardProgramId == 1 { - actualClaimIds = append(actualClaimIds, ras.ClaimId) - } - } - for _, eId := range tc.expectedIds { - s.Assert().Contains(actualClaimIds, eId, fmt.Sprintf("missing claim id %d for reward id 1", eId)) - } - s.Assert().Equal(int(tc.expectedLength), len(response.RewardAccountState), "length of results does not match") - } - }) - } -} diff --git a/x/reward/client/cli/query.go b/x/reward/client/cli/query.go deleted file mode 100644 index 76ec2212ae..0000000000 --- a/x/reward/client/cli/query.go +++ /dev/null @@ -1,265 +0,0 @@ -package cli - -import ( - "context" - "fmt" - "strconv" - "strings" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/version" - - "github.com/provenance-io/provenance/x/reward/types" -) - -var cmdStart = fmt.Sprintf("%s query reward", version.AppName) - -func GetQueryCmd() *cobra.Command { - queryCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the rewards module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - queryCmd.AddCommand( - GetRewardProgramCmd(), - GetClaimPeriodRewardDistributionCmd(), - GetRewardsByAddressCmd(), - ) - return queryCmd -} - -func GetRewardProgramCmd() *cobra.Command { - const all = "all" - const pending = "pending" - const active = "active" - const completed = "completed" - const outstanding = "outstanding" - cmd := &cobra.Command{ - Use: "reward-program {reward_program_id|\"all\"|\"pending\"|\"active\"\"completed\"|\"outstanding\"}", - Aliases: []string{"rp", "rewardprogram"}, - Short: "Query the current reward programs", - Long: fmt.Sprintf(`%[1]s reward-program {reward_program_id} - gets the reward program for a given id. -%[1]s reward-program all - gets all the reward programs -%[1]s reward-program active - gets all the active reward programs`, cmdStart), - Args: cobra.ExactArgs(1), - Example: fmt.Sprintf(`%[1]s reward-program 1 -%[1]s reward-program all -%[1]s reward-program pending -%[1]s reward-program active -%[1]s reward-program outstanding -%[1]s reward-program completed`, cmdStart), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - - var request types.QueryRewardProgramsRequest - arg0 := strings.TrimSpace(args[0]) - switch arg0 { - case all: - request.QueryType = types.QueryRewardProgramsRequest_QUERY_TYPE_ALL - case pending: - request.QueryType = types.QueryRewardProgramsRequest_QUERY_TYPE_PENDING - case active: - request.QueryType = types.QueryRewardProgramsRequest_QUERY_TYPE_ACTIVE - case completed: - request.QueryType = types.QueryRewardProgramsRequest_QUERY_TYPE_FINISHED - case outstanding: - request.QueryType = types.QueryRewardProgramsRequest_QUERY_TYPE_OUTSTANDING - default: - return outputRewardProgramByID(clientCtx, queryClient, arg0) - } - - var response *types.QueryRewardProgramsResponse - if response, err = queryClient.RewardPrograms( - context.Background(), - &request, - ); err != nil { - return fmt.Errorf("failed to query reward programs: %w", err) - } - - return clientCtx.PrintProto(response) - }, - } - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "all") - return cmd -} - -func outputRewardProgramByID(client client.Context, queryClient types.QueryClient, arg string) error { - programID, err := strconv.Atoi(arg) - if err != nil { - return fmt.Errorf("invalid argument arg : %s", arg) - } - - var response *types.QueryRewardProgramByIDResponse - if response, err = queryClient.RewardProgramByID( - context.Background(), - &types.QueryRewardProgramByIDRequest{Id: uint64(programID)}, - ); err != nil { - return fmt.Errorf("failed to query reward program %d: %w", programID, err) - } - - if response.GetRewardProgram() == nil { - return fmt.Errorf("reward program %d does not exist", programID) - } - - return client.PrintProto(response) -} - -func GetClaimPeriodRewardDistributionCmd() *cobra.Command { - const all = "all" - - cmd := &cobra.Command{ - Use: "claim-period-reward-distribution {\"all\"} | {reward_program_id} {claim_period_id}", - Aliases: []string{"cprd", "reward-distribution", "rd", "claim-periods"}, - Short: "Query the current claim period reward distributions", - Long: fmt.Sprintf(`%[1]s claim-period-reward-distribution {reward_program_id} {claim_period_id} - gets the reward program for the given reward_program_id and claim_period_id -%[1]s reward-distribution all - gets all the claim period reward distributions`, cmdStart), - Args: cobra.RangeArgs(1, 2), - Example: fmt.Sprintf(`%[1]s claim-period-reward-distribution 1 1 -%[1]s reward-distribution all`, cmdStart), - RunE: func(cmd *cobra.Command, args []string) error { - arg0 := strings.TrimSpace(args[0]) - if arg0 == all { - return outputClaimPeriodRewardDistributionAll(cmd) - } - - if len(args) != 2 { - return fmt.Errorf("a reward_program_id and an claim_period_id are required") - } - arg1 := args[1] - - return outputClaimPeriodRewardDistributionByID(cmd, arg0, arg1) - }, - } - flags.AddPaginationFlagsToCmd(cmd, "all") - flags.AddQueryFlagsToCmd(cmd) - return cmd -} - -func GetRewardsByAddressCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "reward-by-address {address} {\"all\"|\"unclaimable\"|\"claimable\"|\"claimed\"|\"expired\"}", - Aliases: []string{"rpa", "reward-per-address"}, - Short: "Query all the reward distributions for an address", - Long: fmt.Sprintf(`%[1]s reward-by-address {address} {query-type} - gets the reward amount for the given address based on the filter values`, cmdStart), - Args: cobra.ExactArgs(2), - Example: fmt.Sprintf(`%[1]s reward-by-address pb1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk all -%[1]s reward-by-address pb1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk unclaimable -%[1]s reward-by-address pb1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk claimable -%[1]s reward-by-address pb1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk claimed -%[1]s reward-by-address pb1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk expired`, cmdStart), - RunE: func(cmd *cobra.Command, args []string) error { - arg0 := strings.TrimSpace(args[0]) - arg1 := args[1] - - return queryRewardDistributionByAddress(cmd, arg0, arg1) - }, - } - flags.AddQueryFlagsToCmd(cmd) - return cmd -} - -// Query for all ClaimPeriodRewardDistributions -func outputClaimPeriodRewardDistributionAll(cmd *cobra.Command) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - pageReq, err := client.ReadPageRequest(cmd.Flags()) // TODO[1760]: cli: ReadPageRequestWithPageKeyDecoded - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - var response *types.QueryClaimPeriodRewardDistributionsResponse - if response, err = queryClient.ClaimPeriodRewardDistributions( - context.Background(), - &types.QueryClaimPeriodRewardDistributionsRequest{Pagination: pageReq}, - ); err != nil { - return fmt.Errorf("failed to query reward programs: %w", err) - } - - return clientCtx.PrintProto(response) -} - -// Query for a ClaimPeriodRewardDistribution by Id -func outputClaimPeriodRewardDistributionByID(cmd *cobra.Command, rewardID, claimPeriodID string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - id, err := strconv.Atoi(rewardID) - if err != nil { - return err - } - claimID, err := strconv.Atoi(claimPeriodID) - if err != nil { - return err - } - var response *types.QueryClaimPeriodRewardDistributionsByIDResponse - if response, err = queryClient.ClaimPeriodRewardDistributionsByID( - context.Background(), - &types.QueryClaimPeriodRewardDistributionsByIDRequest{ - RewardId: uint64(id), - ClaimPeriodId: uint64(claimID), - }, - ); err != nil { - return fmt.Errorf("failed to query reward claim %d: %w", id, err) - } - - if response.GetClaimPeriodRewardDistribution() == nil { - return fmt.Errorf("reward does not exist for reward-id: %s claim-id %s", rewardID, claimPeriodID) - } - - return clientCtx.PrintProto(response) -} - -// Query for RewardAccountByAddress depending on claim status -func queryRewardDistributionByAddress(cmd *cobra.Command, address string, queryType string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - var claimStatus types.RewardAccountState_ClaimStatus - switch queryType { - case "all": - claimStatus = types.RewardAccountState_CLAIM_STATUS_UNSPECIFIED - case "unclaimable": - claimStatus = types.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE - case "claimable": - claimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - case "claimed": - claimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMED - case "expired": - claimStatus = types.RewardAccountState_CLAIM_STATUS_EXPIRED - default: - return fmt.Errorf("failed to query reward distributions. %s is not a valid query param", queryType) - } - - queryClient := types.NewQueryClient(clientCtx) - - var response *types.QueryRewardDistributionsByAddressResponse - if response, err = queryClient.RewardDistributionsByAddress( - context.Background(), - &types.QueryRewardDistributionsByAddressRequest{ - Address: address, - ClaimStatus: claimStatus, - }, - ); err != nil { - return fmt.Errorf("failed to query reward distributions: %w", err) - } - - return clientCtx.PrintProto(response) -} diff --git a/x/reward/client/cli/tx.go b/x/reward/client/cli/tx.go deleted file mode 100644 index f40406677d..0000000000 --- a/x/reward/client/cli/tx.go +++ /dev/null @@ -1,225 +0,0 @@ -package cli - -import ( - "fmt" - "strconv" - "strings" - "time" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/version" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// Flag names and values -const ( - FlagTotalRewardPool = "total-reward-pool" - FlagMaxRewardByAddress = "max-reward-by-address" - FlagStartTime = "start-time" - FlagClaimPeriods = "claim-periods" - FlagClaimPeriodDays = "claim-period-days" - FlagExpireDays = "expire-days" - FlagQualifyingActions = "qualifying-actions" - FlagMaxRolloverClaimPeriods = "max-rollover-periods" -) - -func NewTxCmd() *cobra.Command { - txCmd := &cobra.Command{ - Use: types.ModuleName, - Aliases: []string{"r"}, - Short: "Transaction commands for the reward module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - txCmd.AddCommand( - GetCmdRewardProgramAdd(), - GetCmdEndRewardProgram(), - GetCmdClaimReward(), - ) - - return txCmd -} - -func GetCmdRewardProgramAdd() *cobra.Command { - cmd := &cobra.Command{ - Use: "add-reward-program [title] [description]", - Args: cobra.ExactArgs(2), - Aliases: []string{"arp"}, - Short: "Add a reward program", - Long: strings.TrimSpace(`Add a reward program`), - Example: fmt.Sprintf(`$ %[1]s tx reward add-reward-program "Program Title" "A short description" \ - --total-reward-pool 580nhash \ - --max-reward-by-address 10nhash \ - --start-time '2050-01-15T00:00:00Z' \ - --claim-periods 52 \ - --max-rollover-periods 4 \ - --claim-period-days 7 \ - --expire-days 14 \ - --qualifying-actions '{"qualifying_actions":[{"delegate":{"minimum_actions":"0","maximum_actions":"1","minimum_delegation_amount":{"denom":"nhash","amount":"0"},"maximum_delegation_amount":{"denom":"nhash","amount":"100"},"minimum_active_stake_percentile":"0.000000000000000000","maximum_active_stake_percentile":"1.000000000000000000"}}]}' - `, version.AppName), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - coinStr, err := cmd.Flags().GetString(FlagTotalRewardPool) - if err != nil { - return err - } - coin, err := sdk.ParseCoinNormalized(coinStr) - if err != nil { - return err - } - maxCoinStr, err := cmd.Flags().GetString(FlagMaxRewardByAddress) - if err != nil { - return err - } - maxCoin, err := sdk.ParseCoinNormalized(maxCoinStr) - if err != nil { - return err - } - startTimeStr, err := cmd.Flags().GetString(FlagStartTime) - if err != nil || len(startTimeStr) == 0 { - return err - } - startTime, err := time.Parse(time.RFC3339, startTimeStr) - if err != nil { - return fmt.Errorf("unable to parse time (%v) required format is RFC3339 (%v) , %w", startTimeStr, time.RFC3339, err) - } - rewardProgramDays, err := cmd.Flags().GetUint64(FlagClaimPeriods) - if err != nil { - return err - } - claimPeriodDays, err := cmd.Flags().GetUint64(FlagClaimPeriodDays) - if err != nil { - return err - } - expireDays, err := cmd.Flags().GetUint64(FlagExpireDays) - if err != nil { - return err - } - contents, err := cmd.Flags().GetString(FlagQualifyingActions) - if err != nil { - return err - } - maxRolloverPeriods, err := cmd.Flags().GetUint64(FlagMaxRolloverClaimPeriods) - if err != nil { - return err - } - var actions types.QualifyingActions - err = clientCtx.Codec.UnmarshalJSON([]byte(contents), &actions) - if err != nil { - return err - } - callerAddr := clientCtx.GetFromAddress() - msg := types.NewMsgCreateRewardProgramRequest( - args[0], - args[1], - callerAddr.String(), - coin, - maxCoin, - startTime, - rewardProgramDays, - claimPeriodDays, - maxRolloverPeriods, - expireDays, - actions.QualifyingActions, - ) - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - flags.AddTxFlagsToCmd(cmd) - cmd.Flags().String(FlagTotalRewardPool, "", "coins for reward program") - cmd.Flags().String(FlagMaxRewardByAddress, "", "max amount of coins a single address can claim in rewards") - cmd.Flags().String(FlagStartTime, "", "time to start the rewards program, this must be a time in the future or within the first epoch of format YYYY-MM-DDTHH:MM:SSZ00:00 (2012-11-01T22:08:41+07:00)") - cmd.Flags().Uint64(FlagClaimPeriods, 52, "number of claim periods the reward program runs") - cmd.Flags().Uint64(FlagClaimPeriodDays, 7, "number of days for a claim period interval") - cmd.Flags().Uint64(FlagExpireDays, 7, "number of days to expire program after it has ended") - cmd.Flags().String(FlagQualifyingActions, "", "json representation of qualifying actions") - cmd.Flags().Uint64(FlagMaxRolloverClaimPeriods, 0, "max number of rollover claim periods") - return cmd -} - -func GetCmdEndRewardProgram() *cobra.Command { - cmd := &cobra.Command{ - Use: "end-reward-program [reward-program-id]", - Args: cobra.ExactArgs(1), - Aliases: []string{"erp", "end", "er"}, - Short: "End a reward program", - Long: strings.TrimSpace(`End a reward program. This will trigger the reward program to end after the current claim period`), - Example: fmt.Sprintf(`$ %[1]s tx reward end-reward-program 1`, version.AppName), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - callerAddr := clientCtx.GetFromAddress() - programID, err := strconv.Atoi(args[0]) - if err != nil { - return fmt.Errorf("invalid argument : %s", args[0]) - } - - msg := types.NewMsgEndRewardProgramRequest( - uint64(programID), - callerAddr.String(), - ) - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - flags.AddTxFlagsToCmd(cmd) - return cmd -} - -func GetCmdClaimReward() *cobra.Command { - const all = "all" - cmd := &cobra.Command{ - Use: "claim-reward [reward-program-id|all]", - Args: cobra.ExactArgs(1), - Aliases: []string{"cr", "claim"}, - Short: "Claim reward for specified reward program or all programs", - Long: strings.TrimSpace(`Claim reward for a specified reward program or all programs. This will transfer all unclaimed rewards for outstanding claim periods to signers address.`), - Example: fmt.Sprintf(`$ %[1]s tx reward claim-reward 1 --from mykey -$ %[1]s tx reward claim-reward all --from mykey`, version.AppName), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - arg0 := strings.TrimSpace(args[0]) - if arg0 != all { - return claimRewardProgramByID(clientCtx, arg0, cmd) - } - - callerAddr := clientCtx.GetFromAddress() - msg := types.NewMsgClaimAllRewardsRequest( - callerAddr.String(), - ) - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - flags.AddTxFlagsToCmd(cmd) - return cmd -} - -func claimRewardProgramByID(client client.Context, arg string, cmd *cobra.Command) error { - programID, err := strconv.Atoi(arg) - if err != nil { - return fmt.Errorf("invalid argument arg : %s", arg) - } - callerAddr := client.GetFromAddress() - - msg := types.NewMsgClaimRewardsRequest( - uint64(programID), - callerAddr.String(), - ) - return tx.GenerateOrBroadcastTxCLI(client, cmd.Flags(), msg) -} diff --git a/x/reward/handler.go b/x/reward/handler.go deleted file mode 100644 index 592198df94..0000000000 --- a/x/reward/handler.go +++ /dev/null @@ -1,36 +0,0 @@ -package reward - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/provenance-io/provenance/x/reward/keeper" - "github.com/provenance-io/provenance/x/reward/types" -) - -// NewHandler returns a handler for reward messages. -// TODO[1760]: reward: Delete the reward NewHandler. -func NewHandler(k keeper.Keeper) func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - msgServer := keeper.NewMsgServerImpl(k) - - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - - switch msg := msg.(type) { - case *types.MsgCreateRewardProgramRequest: - res, err := msgServer.CreateRewardProgram(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgEndRewardProgramRequest: - res, err := msgServer.EndRewardProgram(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgClaimRewardsRequest: - res, err := msgServer.ClaimRewards(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgClaimAllRewardsRequest: - res, err := msgServer.ClaimAllRewards(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - default: - return nil, sdkerrors.ErrUnknownRequest.Wrapf("unrecognized %s message type: %T", types.ModuleName, msg) - } - } -} diff --git a/x/reward/keeper/claim_reward_distribution.go b/x/reward/keeper/claim_reward_distribution.go deleted file mode 100644 index cfd88596e5..0000000000 --- a/x/reward/keeper/claim_reward_distribution.go +++ /dev/null @@ -1,70 +0,0 @@ -package keeper - -import ( - storetypes "cosmossdk.io/store/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// SetClaimPeriodRewardDistribution sets the ClaimPeriodRewardDistribution in the keeper -func (k Keeper) SetClaimPeriodRewardDistribution(ctx sdk.Context, claimPeriodRewardDistribution types.ClaimPeriodRewardDistribution) { - store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&claimPeriodRewardDistribution) - store.Set(types.GetClaimPeriodRewardDistributionKey(claimPeriodRewardDistribution.ClaimPeriodId, claimPeriodRewardDistribution.RewardProgramId), bz) -} - -// GetClaimPeriodRewardDistribution returns a ClaimPeriodRewardDistribution by epoch id and reward id -func (k Keeper) GetClaimPeriodRewardDistribution(ctx sdk.Context, claimPeriodID uint64, rewardID uint64) (claimPeriodRewardDistribution types.ClaimPeriodRewardDistribution, err error) { - store := ctx.KVStore(k.storeKey) - key := types.GetClaimPeriodRewardDistributionKey(claimPeriodID, rewardID) - bz := store.Get(key) - if len(bz) == 0 { - return claimPeriodRewardDistribution, nil - } - err = k.cdc.Unmarshal(bz, &claimPeriodRewardDistribution) - return claimPeriodRewardDistribution, err -} - -// IterateClaimPeriodRewardDistributions iterates all epoch reward distributions with the given handler function. -func (k Keeper) IterateClaimPeriodRewardDistributions(ctx sdk.Context, handle func(ClaimPeriodRewardDistribution types.ClaimPeriodRewardDistribution) (stop bool)) error { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.ClaimPeriodRewardDistributionKeyPrefix) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - record := types.ClaimPeriodRewardDistribution{} - if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil { - return err - } - if handle(record) { - break - } - } - return nil -} - -// GetAllClaimPeriodRewardDistributions Gets all the Epoch Reward Distributions -func (k Keeper) GetAllClaimPeriodRewardDistributions(sdkCtx sdk.Context) ([]types.ClaimPeriodRewardDistribution, error) { - var rewardDistributions []types.ClaimPeriodRewardDistribution - err := k.IterateClaimPeriodRewardDistributions(sdkCtx, func(rewardDistribution types.ClaimPeriodRewardDistribution) (stop bool) { - rewardDistributions = append(rewardDistributions, rewardDistribution) - return false - }) - if err != nil { - return nil, err - } - return rewardDistributions, nil -} - -// RemoveClaimPeriodRewardDistribution Removes an ClaimPeriodRewardDistribution -func (k Keeper) RemoveClaimPeriodRewardDistribution(ctx sdk.Context, claimPeriodID uint64, rewardID uint64) bool { - store := ctx.KVStore(k.storeKey) - key := types.GetClaimPeriodRewardDistributionKey(claimPeriodID, rewardID) - keyExists := store.Has(key) - if keyExists { - store.Delete(key) - } - return keyExists -} diff --git a/x/reward/keeper/claim_reward_distribution_test.go b/x/reward/keeper/claim_reward_distribution_test.go deleted file mode 100644 index 969bf1dbd2..0000000000 --- a/x/reward/keeper/claim_reward_distribution_test.go +++ /dev/null @@ -1,172 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - - "github.com/provenance-io/provenance/x/reward/types" -) - -func (s *KeeperTestSuite) TestGetSetClaimPeriodRewardDistribution() { - rewardDistribution := types.NewClaimPeriodRewardDistribution( - 1, - 2, - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 200000), - 3, - true, - ) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, rewardDistribution) - retrieved, err := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 2) - s.Assert().NoError(err) - s.Assert().Equal(rewardDistribution.ClaimPeriodId, retrieved.ClaimPeriodId, "claim period id must match") - s.Assert().Equal(rewardDistribution.RewardProgramId, retrieved.RewardProgramId, "reward program id must match") - s.Assert().Equal(rewardDistribution.RewardsPool, retrieved.RewardsPool, "rewards pool must match") - s.Assert().Equal(rewardDistribution.TotalRewardsPoolForClaimPeriod, retrieved.TotalRewardsPoolForClaimPeriod, "total rewards pool must match") - s.Assert().Equal(rewardDistribution.TotalShares, retrieved.TotalShares, "total shares must match") - s.Assert().Equal(rewardDistribution.ClaimPeriodEnded, retrieved.ClaimPeriodEnded, "claim period ended must match") - - retrieved, err = s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 99) - s.Assert().NoError(err) - s.Assert().Equal(uint64(0), retrieved.RewardProgramId, "reward program id must be invalid") -} - -func (s *KeeperTestSuite) TestIterateClaimPeriodRewardDistributions() { - tests := []struct { - name string - distributions []types.ClaimPeriodRewardDistribution - halt bool - counter int - }{ - { - "valid - can handle empty distributions", - []types.ClaimPeriodRewardDistribution{}, - false, - 0, - }, - { - "valid - can handle one distribution", - []types.ClaimPeriodRewardDistribution{ - types.NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - }, - false, - 1, - }, - { - "valid - can handle multiple distributions", - []types.ClaimPeriodRewardDistribution{ - types.NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - types.NewClaimPeriodRewardDistribution(1, 2, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - types.NewClaimPeriodRewardDistribution(1, 3, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - }, - false, - 3, - }, - { - "valid - can handle halting", - []types.ClaimPeriodRewardDistribution{ - types.NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - types.NewClaimPeriodRewardDistribution(1, 2, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - types.NewClaimPeriodRewardDistribution(1, 3, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - }, - true, - 1, - }, - } - - for _, tc := range tests { - s.T().Run(tc.name, func(t *testing.T) { - counter := 0 - for _, distribution := range tc.distributions { - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - err := s.app.RewardKeeper.IterateClaimPeriodRewardDistributions(s.ctx, func(ClaimPeriodRewardDistribution types.ClaimPeriodRewardDistribution) (stop bool) { - counter += 1 - return tc.halt - }) - assert.NoError(t, err, "No error is thrown") - assert.Equal(t, tc.counter, counter, "iterated the correct number of times") - }) - } -} - -func (s *KeeperTestSuite) TestGetAllClaimPeriodRewardDistributions() { - tests := []struct { - name string - distributions []types.ClaimPeriodRewardDistribution - expected int - }{ - { - "valid - can handle empty distributions", - []types.ClaimPeriodRewardDistribution{}, - 0, - }, - { - "valid - can handle one distribution", - []types.ClaimPeriodRewardDistribution{ - types.NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - }, - 1, - }, - { - "valid - can handle multiple distributions", - []types.ClaimPeriodRewardDistribution{ - types.NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - types.NewClaimPeriodRewardDistribution(1, 2, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - types.NewClaimPeriodRewardDistribution(1, 3, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - }, - 3, - }, - } - - for _, tc := range tests { - s.T().Run(tc.name, func(t *testing.T) { - for _, distribution := range tc.distributions { - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - results, err := s.app.RewardKeeper.GetAllClaimPeriodRewardDistributions(s.ctx) - assert.NoError(t, err, "No error is thrown") - assert.Equal(t, tc.expected, len(results), "returned the correct number of claim period reward distributions") - }) - } -} - -func (s *KeeperTestSuite) TestRemoveClaimPeriodRewardDistribution() { - tests := []struct { - name string - distributions []types.ClaimPeriodRewardDistribution - expected int - removed bool - }{ - { - "valid - can handle removal of invalid claim period", - []types.ClaimPeriodRewardDistribution{}, - 0, - false, - }, - { - "valid - can handle valid removal", - []types.ClaimPeriodRewardDistribution{ - types.NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - types.NewClaimPeriodRewardDistribution(2, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false), - }, - 1, - true, - }, - } - - for _, tc := range tests { - s.T().Run(tc.name, func(t *testing.T) { - for _, distribution := range tc.distributions { - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - removed := s.app.RewardKeeper.RemoveClaimPeriodRewardDistribution(s.ctx, 1, 1) - results, err := s.app.RewardKeeper.GetAllClaimPeriodRewardDistributions(s.ctx) - assert.Equal(t, tc.removed, removed, "removal status does not match expectation") - assert.NoError(t, err, "No error is thrown") - assert.Equal(t, tc.expected, len(results), "returned the correct number of claim period reward distributions") - }) - } -} diff --git a/x/reward/keeper/genesis.go b/x/reward/keeper/genesis.go deleted file mode 100644 index ca902b0de0..0000000000 --- a/x/reward/keeper/genesis.go +++ /dev/null @@ -1,72 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// ExportGenesis returns a GenesisState for a given context. -func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - rewardProgramID, err := k.GetRewardProgramID(ctx) - if err != nil { - panic(err) - } - - rewardPrograms := make([]types.RewardProgram, 0) - rewardProgramRecords := func(rewardProgram types.RewardProgram) (bool, error) { - rewardPrograms = append(rewardPrograms, rewardProgram) - return false, nil - } - if err := k.IterateRewardPrograms(ctx, rewardProgramRecords); err != nil { - panic(err) - } - - claimPeriodRewardDistributions := make([]types.ClaimPeriodRewardDistribution, 0) - claimPeriodRewardDistributionRecords := func(ClaimPeriodRewardDistribution types.ClaimPeriodRewardDistribution) bool { - claimPeriodRewardDistributions = append(claimPeriodRewardDistributions, ClaimPeriodRewardDistribution) - return false - } - if err := k.IterateClaimPeriodRewardDistributions(ctx, claimPeriodRewardDistributionRecords); err != nil { - panic(err) - } - - rewardAccountStates := make([]types.RewardAccountState, 0) - rewardAccountStateRecords := func(RewardAccountState types.RewardAccountState) bool { - rewardAccountStates = append(rewardAccountStates, RewardAccountState) - return false - } - - for _, claim := range claimPeriodRewardDistributions { - if err := k.IterateRewardAccountStates(ctx, claim.RewardProgramId, claim.ClaimPeriodId, rewardAccountStateRecords); err != nil { - panic(err) - } - } - - return types.NewGenesisState( - rewardProgramID, - rewardPrograms, - claimPeriodRewardDistributions, - rewardAccountStates, - ) -} - -// InitGenesis new reward genesis -func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { - if err := data.Validate(); err != nil { - panic(err) - } - k.setRewardProgramID(ctx, data.RewardProgramId) - - for _, rewardProgram := range data.RewardPrograms { - k.SetRewardProgram(ctx, rewardProgram) - } - - for _, ClaimPeriodRewardDistributions := range data.ClaimPeriodRewardDistributions { - k.SetClaimPeriodRewardDistribution(ctx, ClaimPeriodRewardDistributions) - } - - for _, RewardAccountStates := range data.RewardAccountStates { - k.SetRewardAccountState(ctx, RewardAccountStates) - } -} diff --git a/x/reward/keeper/keeper.go b/x/reward/keeper/keeper.go deleted file mode 100644 index 6f77f57b4b..0000000000 --- a/x/reward/keeper/keeper.go +++ /dev/null @@ -1,40 +0,0 @@ -package keeper - -import ( - "github.com/cosmos/cosmos-sdk/codec" - storetypes "cosmossdk.io/store/types" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - - "github.com/provenance-io/provenance/x/reward/types" -) - -const StoreKey = types.ModuleName - -type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec - stakingKeeper types.StakingKeeper - govKeeper *govkeeper.Keeper - bankKeeper bankkeeper.Keeper - authkeeper authkeeper.AccountKeeper -} - -func NewKeeper( - cdc codec.BinaryCodec, - key storetypes.StoreKey, - stakingKeeper types.StakingKeeper, - govKeeper *govkeeper.Keeper, - bankKeeper bankkeeper.Keeper, - authKeeper authkeeper.AccountKeeper, -) Keeper { - return Keeper{ - storeKey: key, - cdc: cdc, - stakingKeeper: stakingKeeper, - govKeeper: govKeeper, - bankKeeper: bankKeeper, - authkeeper: authKeeper, - } -} diff --git a/x/reward/keeper/keeper_test.go b/x/reward/keeper/keeper_test.go deleted file mode 100644 index c45701612e..0000000000 --- a/x/reward/keeper/keeper_test.go +++ /dev/null @@ -1,806 +0,0 @@ -package keeper_test - -import ( - "fmt" - "testing" - "time" - - "github.com/stretchr/testify/suite" - - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - - sdkmath "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" - - "github.com/provenance-io/provenance/app" - simapp "github.com/provenance-io/provenance/app" - "github.com/provenance-io/provenance/x/reward" - "github.com/provenance-io/provenance/x/reward/types" -) - -var ( - PKs = simapp.CreateTestPubKeys(500) -) - -type KeeperTestSuite struct { - suite.Suite - - app *simapp.App - ctx sdk.Context - queryClient types.QueryClient - // TODO[1760]: reward: Get rid of this reward handler and call the desired keeper endpoints directly in these tests. - handler func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) - - accountAddr sdk.AccAddress - accountKey *secp256k1.PrivKey - keyring keyring.Keyring - keyringDir string - accountAddresses []sdk.AccAddress -} - -func (s *KeeperTestSuite) CreateAccounts(number int) { - for i := 0; i < number; i++ { - accountKey := secp256k1.GenPrivKeyFromSecret([]byte(fmt.Sprintf("acc%d", i+2))) - addr, err := sdk.AccAddressFromHexUnsafe(accountKey.PubKey().Address().String()) - s.Require().NoError(err) - s.accountAddr = addr - s.accountAddresses = append(s.accountAddresses, addr) - } -} - -func (s *KeeperTestSuite) SetupTest() { - s.app = app.Setup(s.T()) - s.CreateAccounts(4) - s.handler = reward.NewHandler(s.app.RewardKeeper) - s.ctx = s.app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now().UTC()}) - s.createTestValidators(10) - s.Require().NoError(testutil.FundModuleAccount(s.ctx, s.app.BankKeeper, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("nhash", 10000000000000))), "funding module") - - queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, s.app.RewardKeeper) - s.queryClient = types.NewQueryClient(queryHelper) -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) -} - -// Test no reward programs. Nothing should happen -func (s *KeeperTestSuite) TestDelegateAgainstNoRewardPrograms() { - SetupEventHistoryWithDelegates(s) - - // Advance one day - s.ctx = s.ctx.WithBlockHeight(s.ctx.BlockHeight() + (24 * 60 * 60)) - s.Assert().NotPanics(func() { - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - }) - - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += 1 - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no shares should be created") -} - -// Test against inactive reward programs. They should not be updated -func (s *KeeperTestSuite) TestDelegateAgainstInactiveRewardPrograms() { - SetupEventHistoryWithDelegates(s) - - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no shares are granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += 1 - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no shares should be created") - - programs, err := s.app.RewardKeeper.GetAllRewardPrograms(s.ctx) - s.Assert().Equal(1, len(programs)) - s.Assert().NoError(err, "get all reward programs should not throw error") - - activePrograms, err := s.app.RewardKeeper.GetAllActiveRewardPrograms(s.ctx) - s.Assert().NoError(err, "get all active reward programs should not throw error") - s.Assert().Equal(0, len(activePrograms)) -} - -// Test against delegate reward program. No delegate happens. -func (s *KeeperTestSuite) TestNonDelegateAgainstRewardProgram() { - setupEventHistory(s) - - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_STARTED - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no shares are granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += 1 - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no shares should be created") - - programs, err := s.app.RewardKeeper.GetAllRewardPrograms(s.ctx) - s.Assert().Equal(1, len(programs)) - s.Assert().NoError(err, "get all reward programs should not throw error") - - activePrograms, err := s.app.RewardKeeper.GetAllActiveRewardPrograms(s.ctx) - s.Assert().NoError(err, "get all active reward programs should not throw error") - s.Assert().Equal(1, len(activePrograms)) -} - -func (s *KeeperTestSuite) createDelegateEvents(validator, amount, sender, shares string) sdk.Events { - attributes2 := []sdk.Attribute{ - sdk.NewAttribute("module", "staking"), - sdk.NewAttribute("sender", sender), - } - attributes1 := []sdk.Attribute{ - sdk.NewAttribute("validator", validator), - sdk.NewAttribute("amount", amount), - sdk.NewAttribute("new_shares", shares), - } - event1 := sdk.NewEvent("delegate", attributes1...) - event2 := sdk.NewEvent("message", attributes2...) - events := sdk.Events{ - event1, - event2, - } - return events -} - -func (s *KeeperTestSuite) createValidatorEvent(validator, amount, sender string) sdk.Events { - attributes1 := []sdk.Attribute{ - sdk.NewAttribute("validator", validator), - sdk.NewAttribute("amount", amount), - } - attributes2 := []sdk.Attribute{ - sdk.NewAttribute("module", "staking"), - sdk.NewAttribute("sender", sender), - } - event1 := sdk.NewEvent("create_validator", attributes1...) - event2 := sdk.NewEvent("message", attributes2...) - events := sdk.Events{ - event1, - event2, - } - return events -} - -// Test against delegate reward program. Grant 1 share -func (s *KeeperTestSuite) TestSingleDelegate() { - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 100) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure one share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(1, count, "1 share should be created") -} - -// Test against delegate reward program. Grant 2 share -func (s *KeeperTestSuite) TestMultipleDelegate() { - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 100) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - delegates = delegates.AppendEvents(s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000")) - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure one share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(2, count, "2 shares should be created") -} - -// Test against delegate reward program. Not enough actions -func (s *KeeperTestSuite) TestDelegateBelowMinimumActions() { - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 100) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 10, - MaximumActions: 20, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(7, 1), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - delegates = delegates.AppendEvents(s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000")) - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no share should be created when below minimum actions") -} - -// Test against delegate reward program. Too many actions -func (s *KeeperTestSuite) TestDelegateAboveMaximumActions() { - - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 100) - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 0, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - delegates = delegates.AppendEvents(s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000")) - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no share should be created when above maximum actions") -} - -// Test against delegate reward program. Below delegation amount -func (s *KeeperTestSuite) TestDelegateBelowMinimumDelegation() { - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - minimumDelegation := sdk.NewInt64Coin("nhash", 100) - maximumDelegation := sdk.NewInt64Coin("nhash", 200) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - delegates = delegates.AppendEvents(s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000")) - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no share should be created when below minimum delegation amount") -} - -// Test against delegate reward program. Above delegation amount -func (s *KeeperTestSuite) TestDelegateAboveMaximumDelegation() { - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 50) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - delegates = delegates.AppendEvents(s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000")) - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no share should be created when above maximum delegation amount") -} - -// Test against delegate reward program. Below percentile -func (s *KeeperTestSuite) TestDelegateBelowMinimumPercentile() { - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 100) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(7, 1), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - delegates = delegates.AppendEvents(s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000")) - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no share should be created when below minimum delegation percentage") -} - -// Test against delegate reward program. Above percentile -func (s *KeeperTestSuite) TestDelegateAboveMaximumPercentile() { - // Create inactive reward program - action := types.NewActionDelegate() - action.MaximumActions = 10 - action.MinimumActions = 1 - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(0, 0) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 100) - action.MinimumDelegationAmount = &minimumDelegation - action.MaximumDelegationAmount = &maximumDelegation - - coin := sdk.NewInt64Coin("hotdog", 10000) - maxCoin := sdk.NewInt64Coin("hotdog", 100) - - now := time.Now().UTC() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - coin, - maxCoin, - now, - 60*60, - 3, - 0, - 2, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(2, 1), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.StartRewardProgram(s.ctx, &rewardProgram), "StartRewardProgram") - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - // We want to set the events here - validators := getTestValidators(6, 6) - delegates := s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000") - delegates = delegates.AppendEvents(s.createDelegateEvents(validators[0].OperatorAddress, "1000000000nhash", "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5cgxwpuzvh", "50000000000000.000000000000000000")) - SetupEventHistory(s, delegates) - reward.EndBlocker(s.ctx, s.app.RewardKeeper) - - // Ensure no share is granted - count := 0 - err := s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 { - count += int(state.GetSharesEarned()) - return true - } - return false - }) - s.Assert().NoError(err, "iterate should not throw error") - s.Assert().Equal(0, count, "no share should be created when above maximum delegation percentage") -} diff --git a/x/reward/keeper/msg_server.go b/x/reward/keeper/msg_server.go deleted file mode 100644 index 730217734d..0000000000 --- a/x/reward/keeper/msg_server.go +++ /dev/null @@ -1,148 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/types" -) - -type msgServer struct { - Keeper -} - -// NewMsgServerImpl returns an implementation of the account MsgServer interface -// for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} -} - -var _ types.MsgServer = msgServer{} - -// CreateRewardProgram creates new reward program from msg -func (s msgServer) CreateRewardProgram(goCtx context.Context, msg *types.MsgCreateRewardProgramRequest) (*types.MsgCreateRewardProgramResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - rewardProgramID, err := s.Keeper.GetNextRewardProgramID(ctx) - if err != nil { - return &types.MsgCreateRewardProgramResponse{}, err - } - - claimPeriodDaysInSeconds := uint64(types.DayInSeconds) * msg.GetClaimPeriodDays() - expirationOffsetInSeconds := uint64(types.DayInSeconds) * msg.GetExpireDays() - - rewardProgram := types.NewRewardProgram( - msg.Title, - msg.Description, - rewardProgramID, - msg.DistributeFromAddress, - msg.TotalRewardPool, - msg.MaxRewardPerClaimAddress, - msg.ProgramStartTime.UTC(), - claimPeriodDaysInSeconds, - msg.ClaimPeriods, - msg.MaxRolloverClaimPeriods, - expirationOffsetInSeconds, - msg.QualifyingActions, - ) - err = s.Keeper.CreateRewardProgram(ctx, rewardProgram) - if err != nil { - return &types.MsgCreateRewardProgramResponse{}, err - } - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeRewardProgramCreated, - sdk.NewAttribute(types.AttributeKeyRewardProgramID, fmt.Sprintf("%d", rewardProgramID)), - ), - ) - - return &types.MsgCreateRewardProgramResponse{Id: rewardProgramID}, nil -} - -// EndRewardProgram ends reward program from msg -func (s msgServer) EndRewardProgram(goCtx context.Context, msg *types.MsgEndRewardProgramRequest) (*types.MsgEndRewardProgramResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - rewardProgram, err := s.Keeper.GetRewardProgram(ctx, msg.RewardProgramId) - if err != nil { - return &types.MsgEndRewardProgramResponse{}, err - } - if rewardProgram.DistributeFromAddress != msg.ProgramOwnerAddress { - return &types.MsgEndRewardProgramResponse{}, types.ErrEndRewardProgramNotAuthorized - } - if rewardProgram.State != types.RewardProgram_STATE_PENDING && rewardProgram.State != types.RewardProgram_STATE_STARTED { - return &types.MsgEndRewardProgramResponse{}, types.ErrEndrewardProgramIncorrectState - } - - s.Keeper.EndingRewardProgram(ctx, rewardProgram) - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeRewardProgramEnded, - sdk.NewAttribute(types.AttributeKeyRewardProgramID, fmt.Sprintf("%d", rewardProgram.Id)), - ), - ) - - return &types.MsgEndRewardProgramResponse{}, nil -} - -// ClaimRewards claims specific rewards for a user. -func (s msgServer) ClaimRewards(goCtx context.Context, req *types.MsgClaimRewardsRequest) (*types.MsgClaimRewardsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - details, reward, err := s.Keeper.ClaimRewards(ctx, req.GetRewardProgramId(), req.GetRewardAddress()) - if err != nil { - return nil, err - } - - if len(details) > 0 { - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeClaimRewards, - sdk.NewAttribute(types.AttributeKeyRewardProgramID, fmt.Sprintf("%d", req.RewardProgramId)), - sdk.NewAttribute(types.AttributeKeyRewardsClaimAddress, req.GetRewardAddress()), - ), - ) - } - - return &types.MsgClaimRewardsResponse{ - ClaimDetails: types.RewardProgramClaimDetail{ - RewardProgramId: req.GetRewardProgramId(), - TotalRewardClaim: reward, - ClaimedRewardPeriodDetails: details, - }, - }, nil -} - -// ClaimAllRewards claims all rewards for a user. -func (s msgServer) ClaimAllRewards(goCtx context.Context, req *types.MsgClaimAllRewardsRequest) (*types.MsgClaimAllRewardsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - details, reward, err := s.Keeper.ClaimAllRewards(ctx, req.GetRewardAddress()) - if err != nil { - return nil, err - } - - programIDs := make([]uint64, 0, len(details)) - for _, detail := range details { - programIDs = append(programIDs, detail.GetRewardProgramId()) - } - - if len(details) > 0 { - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeClaimAllRewards, - sdk.NewAttribute(types.AttributeKeyRewardProgramIDs, fmt.Sprintf("%v", programIDs)), - sdk.NewAttribute(types.AttributeKeyRewardsClaimAddress, req.GetRewardAddress()), - ), - ) - } - - return &types.MsgClaimAllRewardsResponse{ - TotalRewardClaim: reward, - ClaimDetails: details, - }, nil -} diff --git a/x/reward/keeper/msg_server_test.go b/x/reward/keeper/msg_server_test.go deleted file mode 100644 index 8381f5b949..0000000000 --- a/x/reward/keeper/msg_server_test.go +++ /dev/null @@ -1,553 +0,0 @@ -package keeper_test - -import ( - "time" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" - - "github.com/provenance-io/provenance/x/reward/types" -) - -func (s *KeeperTestSuite) TestCreateRewardProgramTransaction() { - - minimumDelegation := sdk.NewInt64Coin("nhash", 100) - maximumDelegation := sdk.NewInt64Coin("nhash", 200) - s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, s.accountAddresses[0], sdk.NewCoins(sdk.NewInt64Coin("nhash", 100000))), "funding account") - - msg := types.NewMsgCreateRewardProgramRequest( - "title", - "description", - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time.Now(), - 4, - 2, - 1, - 4, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - s.Assert().NoError(err, "msg server should handle a new valid reward program") - s.Assert().Less(0, len(result.GetEvents()), "should have emitted events") - s.Assert().Equal(result.Events[len(result.Events)-1].Type, "reward_program_created", "emitted event should have correct event type") - s.Assert().Equal(1, len(result.Events[len(result.Events)-1].Attributes), "emitted event should have correct event number of attributes") - s.Assert().Equal(result.Events[len(result.Events)-1].Attributes[0].Key, "reward_program_id", "should have correct key") - s.Assert().Equal(result.Events[len(result.Events)-1].Attributes[0].Value, "1", "should have correct value") - - program, err := s.app.RewardKeeper.GetRewardProgram(s.ctx, 1) - s.Assert().NoError(err, "No error should be returned") - s.Assert().Nil(program.Validate(), "should not have a validation error") -} - -func (s *KeeperTestSuite) TestCreateRewardProgramFailedTransaction() { - - minimumDelegation := sdk.NewInt64Coin("nhash", 100) - maximumDelegation := sdk.NewInt64Coin("nhash", 200) - - msg := types.NewMsgCreateRewardProgramRequest( - "title", - "description", - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time.Now(), - 4, - 2, - 1, - 4, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - s.Assert().Error(err, "msg server should throw error for invalid creation") - s.Assert().Nil(result, "result should be nil and have no events") - - program, err := s.app.RewardKeeper.GetRewardProgram(s.ctx, 1) - s.Assert().Error(err, "error should be returned") - s.Assert().NotNil(program.Validate(), "should have validation issue for invalid program") -} - -func (s *KeeperTestSuite) TestRewardClaimTransaction() { - - now := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 3, - 0, - uint64(now.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for i := 1; i <= int(rewardProgram.GetClaimPeriods()); i++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(i), s.accountAddresses[0].String(), 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(i), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - - msg := types.NewMsgClaimRewardsRequest(1, s.accountAddresses[0].String()) - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - - s.Assert().NoError(err, "msg server should handle valid reward claim") - s.Assert().NotNil(result, "msg server should emit events") - s.Assert().Less(0, len(result.GetEvents()), "should have emitted events") - s.Assert().Equal(result.Events[len(result.Events)-1].Type, "claim_rewards", "emitted event should have correct event type") - s.Assert().Equal(2, len(result.Events[len(result.Events)-1].Attributes), "emitted event should have correct number of attributes") - s.Assert().Equal(result.Events[len(result.Events)-1].Attributes[0].Key, "reward_program_id", "should have correct key") - s.Assert().Equal(result.Events[len(result.Events)-1].Attributes[0].Value, "1", "should have correct program id") - s.Assert().Equal(result.Events[len(result.Events)-1].Attributes[1].Key, "rewards_claim_address", "should have correct key") - s.Assert().Equal(result.Events[len(result.Events)-1].Attributes[1].Value, s.accountAddresses[0].String(), "should have correct address value") -} - -func (s *KeeperTestSuite) TestRewardClaimInvalidTransaction() { - - msg := types.NewMsgClaimRewardsRequest(1, "invalid address") - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - - s.Assert().Error(err, "msg server should handle an invalid reward claim") - s.Assert().Nil(result, "should have no emitted events") -} - -func (s *KeeperTestSuite) TestRewardClaimTransactionInvalidClaimer() { - - now := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 3, - 0, - uint64(now.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for i := 1; i <= int(rewardProgram.GetClaimPeriods()); i++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(i), s.accountAddresses[0].String(), 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(i), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - - msg := types.NewMsgClaimRewardsRequest(1, s.accountAddresses[1].String()) - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - s.Assert().NoError(err, "msg server should handle valid reward claim") - s.Assert().NotNil(result, "msg server should emit events") - - var response types.MsgClaimRewardsResponse - response.Unmarshal(result.Data) - s.Assert().Equal(uint64(1), response.GetClaimDetails().RewardProgramId, "should have correct reward program id") - s.Assert().Equal(0, len(response.GetClaimDetails().ClaimedRewardPeriodDetails), "should have no details") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), response.GetClaimDetails().TotalRewardClaim, "should have no reward claim") -} - -func (s *KeeperTestSuite) TestClaimAllRewardsTransaction() { - now := s.ctx.BlockTime() - - for i := 0; i < 3; i++ { - rewardProgram := types.NewRewardProgram( - "title", - "description", - uint64(i+1), - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 3, - 0, - uint64(now.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for j := 1; j <= int(rewardProgram.GetClaimPeriods()); j++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(j), s.accountAddresses[0].String(), 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(j), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - } - - msg := types.NewMsgClaimAllRewardsRequest(s.accountAddresses[0].String()) - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - s.Assert().NoError(err, "msg server should handle valid reward claim") - s.Assert().NotNil(result, "msg server should emit events") - - var response types.MsgClaimAllRewardsResponse - response.Unmarshal(result.Data) - details := response.ClaimDetails - s.Assert().Equal(sdk.NewInt64Coin("nhash", 900), response.TotalRewardClaim[0], "should total up the rewards from the periods") - s.Assert().Equal(3, len(details), "should have every reward program") - for i := 0; i < len(details); i++ { - s.Assert().Equal(3, len(details[i].ClaimedRewardPeriodDetails), "should have claims from every period") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 300), details[i].TotalRewardClaim, "should total up the rewards from the periods") - s.Assert().Equal(uint64(i+1), details[i].RewardProgramId, "should have the correct id") - } -} - -func (s *KeeperTestSuite) TestClaimAllRewardsNoProgramsTransaction() { - msg := types.NewMsgClaimAllRewardsRequest(s.accountAddresses[0].String()) - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - s.Assert().NoError(err, "no error should be returned in a valid call") - - var response types.MsgClaimAllRewardsResponse - response.Unmarshal(result.Data) - details := response.ClaimDetails - - s.Assert().Equal(0, len(response.TotalRewardClaim), "should have no nhash") - s.Assert().Equal(0, len(details), "should have no reward program") -} - -func (s *KeeperTestSuite) TestRewardClaimAllRewardsInvalidAddressTransaction() { - now := s.ctx.BlockTime() - - for i := 0; i < 3; i++ { - rewardProgram := types.NewRewardProgram( - "title", - "description", - uint64(i+1), - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 3, - 0, - uint64(now.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for j := 1; j <= int(rewardProgram.GetClaimPeriods()); j++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(j), s.accountAddresses[0].String(), 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(j), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - } - - msg := types.NewMsgClaimAllRewardsRequest("invalid address") - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - s.Assert().Error(err, "error should be returned else state store will commit") - s.Assert().Nil(result) -} - -func (s *KeeperTestSuite) TestClaimAllRewardsExpiredTransaction() { - now := s.ctx.BlockTime() - - for i := 0; i < 3; i++ { - rewardProgram := types.NewRewardProgram( - "title", - "description", - uint64(i+1), - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 3, - 0, - uint64(now.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for j := 1; j <= int(rewardProgram.GetClaimPeriods()); j++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(j), s.accountAddresses[0].String(), 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_EXPIRED - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(j), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - } - - msg := types.NewMsgClaimAllRewardsRequest(s.accountAddresses[0].String()) - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - s.Assert().NoError(err, "no error should be returned in a valid call") - - var response types.MsgClaimAllRewardsResponse - response.Unmarshal(result.Data) - details := response.ClaimDetails - - s.Assert().Equal(0, len(response.TotalRewardClaim), "should have no nhash") - s.Assert().Equal(0, len(details), "should have no reward program") -} - -func (s *KeeperTestSuite) TestEndRewardProgramRequest() { - testCases := []struct { - name string - id uint64 - address string - expectErr bool - expectErrMsg string - }{ - {"end reward program request - invalid reward program id", - 88, - s.accountAddresses[0].String(), - true, - "reward program not found", - }, - {"end reward program request - invalid executor", - 1, - s.accountAddresses[1].String(), - true, - "not authorized to end the reward program", - }, - {"end reward program request - invalid state for reward program", - 3, - s.accountAddresses[0].String(), - true, - "unable to end a reward program that is finished or expired", - }, - {"end reward program request - valid request in pending state", - 1, - s.accountAddresses[0].String(), - false, - "", - }, - {"end reward program request - valid requested in started state", - 2, - s.accountAddresses[0].String(), - false, - "", - }, - } - - now := s.ctx.BlockTime() - for i := 0; i < 3; i++ { - rewardProgram := types.NewRewardProgram( - "title", - "description", - uint64(i+1), - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 3, - 0, - uint64(now.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - }, - ) - switch i + 1 { - case 1: - rewardProgram.State = types.RewardProgram_STATE_PENDING - case 2: - rewardProgram.State = types.RewardProgram_STATE_STARTED - rewardProgram.CurrentClaimPeriod = 1 - case 3: - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - } - - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - msg := types.NewMsgEndRewardProgramRequest(tc.id, tc.address) - s.ctx = s.ctx.WithEventManager(sdk.NewEventManager()) - result, err := s.handler(s.ctx, msg) - if tc.expectErr { - s.Assert().Error(err) - s.Assert().Equal(tc.expectErrMsg, err.Error()) - } else { - s.Assert().NoError(err) - var response types.MsgEndRewardProgramResponse - err = response.Unmarshal(result.Data) - s.Assert().NoError(err) - } - }) - } - -} diff --git a/x/reward/keeper/query_server.go b/x/reward/keeper/query_server.go deleted file mode 100644 index 1c18ccb98f..0000000000 --- a/x/reward/keeper/query_server.go +++ /dev/null @@ -1,205 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - "cosmossdk.io/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/query" - - "github.com/provenance-io/provenance/x/reward/types" -) - -var _ types.QueryServer = Keeper{} - -// RewardPrograms returns a list of reward programs matching the query type. -func (k Keeper) RewardPrograms(ctx context.Context, req *types.QueryRewardProgramsRequest) (*types.QueryRewardProgramsResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - sdkCtx := sdk.UnwrapSDKContext(ctx) - var err error - - rewardProgramStates := []types.RewardProgram_State{} - switch req.QueryType { - case types.QueryRewardProgramsRequest_QUERY_TYPE_PENDING: - rewardProgramStates = []types.RewardProgram_State{types.RewardProgram_STATE_PENDING} - case types.QueryRewardProgramsRequest_QUERY_TYPE_ACTIVE: - rewardProgramStates = []types.RewardProgram_State{types.RewardProgram_STATE_STARTED} - case types.QueryRewardProgramsRequest_QUERY_TYPE_FINISHED: - rewardProgramStates = []types.RewardProgram_State{types.RewardProgram_STATE_FINISHED, types.RewardProgram_STATE_EXPIRED} - case types.QueryRewardProgramsRequest_QUERY_TYPE_OUTSTANDING: - rewardProgramStates = []types.RewardProgram_State{types.RewardProgram_STATE_PENDING, types.RewardProgram_STATE_STARTED} - } - - response := types.QueryRewardProgramsResponse{} - kvStore := sdkCtx.KVStore(k.storeKey) - prefixStore := prefix.NewStore(kvStore, types.RewardProgramKeyPrefix) - pageResponse, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { - var rewardProgram types.RewardProgram - vErr := rewardProgram.Unmarshal(value) - - if vErr != nil { - return false, vErr - } - - matched := rewardProgram.MatchesState(rewardProgramStates) - if accumulate && matched { - response.RewardPrograms = append(response.RewardPrograms, rewardProgram) - } - - return matched, nil - }) - - if err != nil { - return nil, status.Errorf(codes.Internal, fmt.Sprintf("unable to query all reward programs: %v", err)) - } - response.Pagination = pageResponse - return &response, nil -} - -// RewardProgramByID returns a reward program matching the ID. -func (k Keeper) RewardProgramByID(ctx context.Context, req *types.QueryRewardProgramByIDRequest) (*types.QueryRewardProgramByIDResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - sdkCtx := sdk.UnwrapSDKContext(ctx) - rewardProgram, err := k.GetRewardProgram(sdkCtx, req.GetId()) - if err != nil { - return &types.QueryRewardProgramByIDResponse{}, status.Errorf(codes.Internal, fmt.Sprintf("unable to query for reward program by ID: %v", err)) - } - return &types.QueryRewardProgramByIDResponse{RewardProgram: &rewardProgram}, nil -} - -// ClaimPeriodRewardDistributions returns a list of claim period reward distributions matching the claim_status. -func (k Keeper) ClaimPeriodRewardDistributions(ctx context.Context, req *types.QueryClaimPeriodRewardDistributionsRequest) (*types.QueryClaimPeriodRewardDistributionsResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - response := types.QueryClaimPeriodRewardDistributionsResponse{} - sdkCtx := sdk.UnwrapSDKContext(ctx) - kvStore := sdkCtx.KVStore(k.storeKey) - prefixStore := prefix.NewStore(kvStore, types.ClaimPeriodRewardDistributionKeyPrefix) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { - var claimPeriodRewardDist types.ClaimPeriodRewardDistribution - vErr := claimPeriodRewardDist.Unmarshal(value) - - if vErr != nil { - return false, vErr - } - - if accumulate { - response.ClaimPeriodRewardDistributions = append(response.ClaimPeriodRewardDistributions, claimPeriodRewardDist) - } - - return true, nil - }) - if err != nil { - return &response, status.Error(codes.Unavailable, err.Error()) - } - response.Pagination = pageRes - return &response, nil -} - -// ClaimPeriodRewardDistributionsByID returns a claim period reward distribution matching the ID. -func (k Keeper) ClaimPeriodRewardDistributionsByID(ctx context.Context, req *types.QueryClaimPeriodRewardDistributionsByIDRequest) (*types.QueryClaimPeriodRewardDistributionsByIDResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - response := types.QueryClaimPeriodRewardDistributionsByIDResponse{} - sdkCtx := sdk.UnwrapSDKContext(ctx) - - ClaimPeriodReward, err := k.GetClaimPeriodRewardDistribution(sdkCtx, req.GetClaimPeriodId(), req.GetRewardId()) - if err != nil { - return nil, status.Errorf(codes.NotFound, fmt.Sprintf("unable to query claim period reward distributions by ID: %v", err)) - } - - if ClaimPeriodReward.Validate() == nil { - response.ClaimPeriodRewardDistribution = &ClaimPeriodReward - } - - return &response, nil -} - -// RewardDistributionsByAddress returns a list of reward claims belonging to the account and matching the claim status. -func (k Keeper) RewardDistributionsByAddress(ctx context.Context, request *types.QueryRewardDistributionsByAddressRequest) (*types.QueryRewardDistributionsByAddressResponse, error) { - if request == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - address, err := sdk.AccAddressFromBech32(request.Address) - if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) - } - sdkCtx := sdk.UnwrapSDKContext(ctx) - var states []types.RewardAccountState - getAllRewardAccountStore := prefix.NewStore(sdk.UnwrapSDKContext(ctx).KVStore(k.storeKey), types.GetAllRewardAccountByAddressPartialKey(address)) - - pageRes, err := query.FilteredPaginate(getAllRewardAccountStore, request.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { - lookupVal, errFromParsingKey := types.ParseFilterLookUpKey(key, address) - - if errFromParsingKey != nil { - return false, err - } - result, errFromGetRewardAccount := k.GetRewardAccountState(sdkCtx, lookupVal.RewardID, lookupVal.ClaimID, lookupVal.Addr.String()) - // think ignoring the error maybe ok here since it's just another lookup - if errFromGetRewardAccount != nil { - return false, errFromGetRewardAccount - } - if result.GetSharesEarned() == 0 || (request.ClaimStatus != result.ClaimStatus && request.ClaimStatus != types.RewardAccountState_CLAIM_STATUS_UNSPECIFIED) { - return false, nil - } - - if accumulate { - states = append(states, result) - } - - return true, nil - }) - - if err != nil { - return nil, types.ErrIterateAllRewardAccountStates.Wrap(err.Error()) - } - - rewardAccountResponses := k.convertRewardAccountStateToRewardAccountResponse(sdkCtx, states) - rewardAccountByAddressResponse := types.QueryRewardDistributionsByAddressResponse{ - Address: request.Address, - RewardAccountState: rewardAccountResponses, - Pagination: pageRes, - } - - return &rewardAccountByAddressResponse, nil -} - -func (k Keeper) convertRewardAccountStateToRewardAccountResponse(ctx sdk.Context, states []types.RewardAccountState) []types.RewardAccountResponse { - rewardAccountResponse := make([]types.RewardAccountResponse, 0) - for _, state := range states { - rewardProgram, err := k.GetRewardProgram(ctx, state.GetRewardProgramId()) - if err != nil { - continue - } - distribution, err := k.GetClaimPeriodRewardDistribution(ctx, state.ClaimPeriodId, state.RewardProgramId) - if err != nil { - continue - } - - participantReward := k.CalculateParticipantReward(ctx, int64(state.GetSharesEarned()), distribution.GetTotalShares(), distribution.GetRewardsPool(), rewardProgram.MaxRewardByAddress) - accountResponse := types.RewardAccountResponse{ - RewardProgramId: state.RewardProgramId, - TotalRewardClaim: participantReward, - ClaimStatus: state.ClaimStatus, - ClaimId: state.ClaimPeriodId, - } - rewardAccountResponse = append(rewardAccountResponse, accountResponse) - } - - return rewardAccountResponse -} diff --git a/x/reward/keeper/query_server_test.go b/x/reward/keeper/query_server_test.go deleted file mode 100644 index e1abae2da7..0000000000 --- a/x/reward/keeper/query_server_test.go +++ /dev/null @@ -1,209 +0,0 @@ -package keeper_test - -import ( - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" - - "github.com/provenance-io/provenance/x/reward/types" -) - -func (s *KeeperTestSuite) TestQueryRewardPrograms() { - queryClient := s.queryClient - - response, err := queryClient.RewardPrograms(s.ctx.Context(), &types.QueryRewardProgramsRequest{}) - s.Assert().Nil(err, "query should not error") - s.Assert().Equal(len(response.RewardPrograms), 0, "response should contain empty list") - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - s.accountAddr.String(), - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Transfer{ - Transfer: &types.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - rewardProgram.Id = 2 - rewardProgram.State = types.RewardProgram_STATE_STARTED - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - rewardProgram.Id = 3 - rewardProgram.State = types.RewardProgram_STATE_FINISHED - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - rewardProgram.Id = 4 - rewardProgram.State = types.RewardProgram_STATE_EXPIRED - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - response, err = queryClient.RewardPrograms(s.ctx.Context(), &types.QueryRewardProgramsRequest{QueryType: types.QueryRewardProgramsRequest_QUERY_TYPE_ALL}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(len(response.RewardPrograms), 4, "response should contain the added element") - - response, err = queryClient.RewardPrograms(s.ctx.Context(), &types.QueryRewardProgramsRequest{QueryType: types.QueryRewardProgramsRequest_QUERY_TYPE_PENDING}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(len(response.RewardPrograms), 1, "response should contain the added element") - s.Assert().Equal(uint64(1), response.RewardPrograms[0].Id, "response should contain pending program") - - response, err = queryClient.RewardPrograms(s.ctx.Context(), &types.QueryRewardProgramsRequest{QueryType: types.QueryRewardProgramsRequest_QUERY_TYPE_ACTIVE}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(len(response.RewardPrograms), 1, "response should contain the added element") - s.Assert().Equal(uint64(2), response.RewardPrograms[0].Id, "response should contain active program") - - response, err = queryClient.RewardPrograms(s.ctx.Context(), &types.QueryRewardProgramsRequest{QueryType: types.QueryRewardProgramsRequest_QUERY_TYPE_OUTSTANDING}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(len(response.RewardPrograms), 2, "response should contain the added element") - s.Assert().Equal(uint64(1), response.RewardPrograms[0].Id, "response should contain the pending program") - s.Assert().Equal(uint64(2), response.RewardPrograms[1].Id, "response should contain the active program") - - response, err = queryClient.RewardPrograms(s.ctx.Context(), &types.QueryRewardProgramsRequest{QueryType: types.QueryRewardProgramsRequest_QUERY_TYPE_FINISHED}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(len(response.RewardPrograms), 2, "response should contain the added element") - s.Assert().Equal(uint64(3), response.RewardPrograms[0].Id, "response should contain the finished program") - s.Assert().Equal(uint64(4), response.RewardPrograms[1].Id, "response should contain the expired program") - - responseId, err := queryClient.RewardProgramByID(s.ctx.Context(), &types.QueryRewardProgramByIDRequest{Id: uint64(4)}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(uint64(4), responseId.RewardProgram.Id, "response should contain the reward program with id 4") - - responseId, err = queryClient.RewardProgramByID(s.ctx.Context(), &types.QueryRewardProgramByIDRequest{Id: uint64(1000)}) - s.Assert().Error(err, "query should not error") - s.Assert().Equal(true, responseId == nil, "response should be nil, since program doesn't exist") -} - -func (s *KeeperTestSuite) TestClaimPeriodRewardDistributions() { - - queryClient := s.queryClient - for i := 0; i < 101; i++ { - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, types.NewClaimPeriodRewardDistribution(uint64(i+1), 1, sdk.NewInt64Coin("jackthecat", 100), sdk.NewInt64Coin("jackthecat", 10), int64(i), false)) - } - pageRequest := &query.PageRequest{} - pageRequest.Limit = 100 - pageRequest.CountTotal = true - response, err := queryClient.ClaimPeriodRewardDistributions(s.ctx.Context(), &types.QueryClaimPeriodRewardDistributionsRequest{pageRequest}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(response.Pagination.Total, uint64(101)) - s.Assert().Equal(100, len(response.ClaimPeriodRewardDistributions)) - - response, err = queryClient.ClaimPeriodRewardDistributions(s.ctx.Context(), &types.QueryClaimPeriodRewardDistributionsRequest{Pagination: &query.PageRequest{Limit: 10000}}) - s.Assert().NoError(err, "query should not error") - // 0 since pageRequest.CountTotal = false by default - s.Assert().Equal(response.Pagination.Total, uint64(0), "should only return 100") - s.Assert().Equal(101, len(response.ClaimPeriodRewardDistributions), "should only return 100 (max allowed per page)") - - response, err = queryClient.ClaimPeriodRewardDistributions(s.ctx.Context(), &types.QueryClaimPeriodRewardDistributionsRequest{Pagination: &query.PageRequest{Limit: 1, Offset: 9}}) - s.Assert().NoError(err, "query should not error") - // 0 since pageRequest.CountTotal = false by default - s.Assert().Equal(response.Pagination.Total, uint64(0), "should only return 100") - s.Assert().Equal(1, len(response.ClaimPeriodRewardDistributions), "should only return 1") - s.Assert().Equal(uint64(10), response.ClaimPeriodRewardDistributions[0].ClaimPeriodId) -} - -func (s *KeeperTestSuite) TestClaimPeriodRewardDistributionByID() { - - queryClient := s.queryClient - for i := 0; i < 101; i++ { - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, types.NewClaimPeriodRewardDistribution(uint64(i+1), 1, sdk.NewInt64Coin("jackthecat", 100), sdk.NewInt64Coin("jackthecat", 10), int64(i), false)) - } - response, err := queryClient.ClaimPeriodRewardDistributionsByID(s.ctx.Context(), &types.QueryClaimPeriodRewardDistributionsByIDRequest{RewardId: uint64(1), ClaimPeriodId: uint64(612)}) - s.Assert().NoError(err, "query should not error") - s.Assert().Nil(response.ClaimPeriodRewardDistribution, "ClaimPeriodRewardDistribution should not be found") - - response, err = queryClient.ClaimPeriodRewardDistributionsByID(s.ctx.Context(), &types.QueryClaimPeriodRewardDistributionsByIDRequest{RewardId: uint64(1), ClaimPeriodId: uint64(99)}) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(response.ClaimPeriodRewardDistribution.RewardProgramId, uint64(1)) - s.Assert().Equal(response.ClaimPeriodRewardDistribution.ClaimPeriodId, uint64(99)) -} - -func (s *KeeperTestSuite) TestRewardDistributionsByAddress() { - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - s.accountAddr.String(), - sdk.NewInt64Coin("nhash", 1000_000_000_000), - sdk.NewInt64Coin("nhash", 10_000_000_000), - time.Now().Add(100*time.Millisecond), - uint64(30), - 10, - 10, - 3, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Transfer{ - Transfer: &types.ActionTransfer{ - MinimumActions: 0, - MaximumActions: 10, - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 0), - }, - }, - }, - }, - ) - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - queryClient := s.queryClient - for i := 0; i < 402; i++ { - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, types.NewClaimPeriodRewardDistribution(uint64(i+1), 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 10), int64(i), false)) - } - - for i := 0; i < 201; i++ { - s.app.RewardKeeper.SetRewardAccountState(s.ctx, types.NewRewardAccountState(1, uint64(i+1), s.accountAddr.String(), 10, []*types.ActionCounter{})) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, types.NewRewardAccountState(1, uint64(i+1), s.accountAddresses[2].String(), 10, []*types.ActionCounter{})) - } - s.Assert().NotEqual(s.accountAddr.String(), s.accountAddresses[2].String()) - pageRequest := &query.PageRequest{} - pageRequest.Limit = 100 - pageRequest.CountTotal = true - response, err := queryClient.RewardDistributionsByAddress(s.ctx.Context(), &types.QueryRewardDistributionsByAddressRequest{ - Address: s.accountAddr.String(), - ClaimStatus: types.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - Pagination: pageRequest, - }) - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(100, len(response.RewardAccountState)) - s.Assert().Equal(uint64(201), response.Pagination.Total) - pageRequest1 := &query.PageRequest{} - pageRequest1.Limit = 100 - pageRequest1.CountTotal = true - s.Assert().NotNil(response.Pagination.NextKey) - pageRequest1.Key = response.Pagination.NextKey - response1, err := queryClient.RewardDistributionsByAddress(s.ctx.Context(), &types.QueryRewardDistributionsByAddressRequest{ - Address: s.accountAddr.String(), - ClaimStatus: types.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - Pagination: pageRequest1, - }) - - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(100, len(response1.RewardAccountState)) - pageRequest2 := &query.PageRequest{} - pageRequest2.Limit = 100 - pageRequest2.CountTotal = true - s.Assert().NotNil(response1.Pagination.NextKey) - pageRequest2.Key = response1.Pagination.NextKey - response2, err := queryClient.RewardDistributionsByAddress(s.ctx.Context(), &types.QueryRewardDistributionsByAddressRequest{ - Address: s.accountAddr.String(), - ClaimStatus: types.RewardAccountState_CLAIM_STATUS_UNSPECIFIED, - Pagination: pageRequest2, - }) - - s.Assert().NoError(err, "query should not error") - s.Assert().Equal(1, len(response2.RewardAccountState)) - -} diff --git a/x/reward/keeper/reward_account_state.go b/x/reward/keeper/reward_account_state.go deleted file mode 100644 index 3a52d4a806..0000000000 --- a/x/reward/keeper/reward_account_state.go +++ /dev/null @@ -1,166 +0,0 @@ -package keeper - -import ( - storetypes "cosmossdk.io/store/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// GetRewardAccountState gets a RewardAccountState. -// If the desired RewardAccountState doesn't exist, an empty RewardAccountState is returned (without error). -func (k Keeper) GetRewardAccountState(ctx sdk.Context, rewardProgramID, rewardClaimPeriodID uint64, addr string) (state types.RewardAccountState, err error) { - store := ctx.KVStore(k.storeKey) - key := types.GetRewardAccountStateKey(rewardProgramID, rewardClaimPeriodID, types.MustAccAddressFromBech32(addr)) - bz := store.Get(key) - if len(bz) == 0 { - return state, nil - } - err = k.cdc.Unmarshal(bz, &state) - - return state, err -} - -// SetRewardAccountState stores the provided RewardAccountState in the state store and indexes it. -func (k Keeper) SetRewardAccountState(ctx sdk.Context, state types.RewardAccountState) { - store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&state) - key := types.GetRewardAccountStateKey(state.GetRewardProgramId(), state.GetClaimPeriodId(), types.MustAccAddressFromBech32(state.GetAddress())) - store.Set(key, bz) - // since there is a significant use case of looking up this via address create a secondary index - // [0x8] :: [addr-bytes::reward program id bytes]::[claim period id bytes] {} - addressLookupKey := types.GetRewardAccountStateAddressLookupKey(types.MustAccAddressFromBech32(state.GetAddress()), state.GetRewardProgramId(), state.GetClaimPeriodId()) - // no need for a value a key can derive all the info needed - store.Set(addressLookupKey, []byte{}) -} - -// IterateRewardAccountStates Iterates over the account states for a reward program's claim period -func (k Keeper) IterateRewardAccountStates(ctx sdk.Context, rewardProgramID, rewardClaimPeriodID uint64, handle func(state types.RewardAccountState) (stop bool)) error { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.GetRewardAccountStateClaimPeriodKey(rewardProgramID, rewardClaimPeriodID)) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - record := types.RewardAccountState{} - if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil { - return err - } - if handle(record) { - break - } - } - return nil -} - -// IterateRewardAccountStatesByAddress Iterates over the account states by address iterator -func (k Keeper) IterateRewardAccountStatesByAddress(ctx sdk.Context, addr sdk.AccAddress, handle func(state types.RewardAccountState) (stop bool)) error { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.GetAllRewardAccountByAddressPartialKey(types.MustAccAddressFromBech32(addr.String()))) - return k.IterateRewardAccountStatesByLookUpIndex(ctx, addr, iterator, handle) -} - -// IterateRewardAccountStatesByAddressAndRewardsID Iterates over the account states by address iterator and reward id -func (k Keeper) IterateRewardAccountStatesByAddressAndRewardsID(ctx sdk.Context, addr sdk.AccAddress, rewardsID uint64, handle func(state types.RewardAccountState) (stop bool)) error { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.GetAllRewardAccountByAddressAndRewardsIDPartialKey(addr, rewardsID)) - return k.IterateRewardAccountStatesByLookUpIndex(ctx, addr, iterator, handle) -} - -// IterateRewardAccountStatesByLookUpIndex iterates reward account states by secondary index // [0x8] :: [addr-bytes::reward program id bytes]::[claim period id bytes] {} -func (k Keeper) IterateRewardAccountStatesByLookUpIndex(ctx sdk.Context, addr sdk.AccAddress, iterator storetypes.Iterator, handle func(state types.RewardAccountState) (stop bool)) error { - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - keyParsed, err := types.ParseRewardAccountLookUpKey(iterator.Key(), addr) - if err != nil { - return err - } - record, err := k.GetRewardAccountState(ctx, keyParsed.RewardID, keyParsed.ClaimID, addr.String()) - if err != nil { - return err - } - if handle(record) { - break - } - } - return nil -} - -// IterateAllRewardAccountStates Iterates over the account states for every reward program -func (k Keeper) IterateAllRewardAccountStates(ctx sdk.Context, handle func(state types.RewardAccountState) (stop bool)) error { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.GetAllRewardAccountStateKey()) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - record := types.RewardAccountState{} - if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil { - return err - } - if handle(record) { - break - } - } - return nil -} - -// IterateRewardAccountStatesForRewardProgram Iterates over the account states for a reward program -func (k Keeper) IterateRewardAccountStatesForRewardProgram(ctx sdk.Context, rewardProgramID uint64, handle func(state types.RewardAccountState) (stop bool)) error { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.GetRewardProgramRewardAccountStateKey(rewardProgramID)) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - record := types.RewardAccountState{} - if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil { - return err - } - if handle(record) { - break - } - } - return nil -} - -// Returns a list of account states for the reward program's claim period -func (k Keeper) GetRewardAccountStatesForClaimPeriod(ctx sdk.Context, rewardProgramID, claimPeriodID uint64) ([]types.RewardAccountState, error) { - states := []types.RewardAccountState{} - err := k.IterateRewardAccountStates(ctx, rewardProgramID, claimPeriodID, func(state types.RewardAccountState) (stop bool) { - states = append(states, state) - return false - }) - return states, err -} - -// Returns a list of account states for the reward program -func (k Keeper) GetRewardAccountStatesForRewardProgram(ctx sdk.Context, rewardProgramID uint64) ([]types.RewardAccountState, error) { - states := []types.RewardAccountState{} - err := k.IterateRewardAccountStatesForRewardProgram(ctx, rewardProgramID, func(state types.RewardAccountState) (stop bool) { - states = append(states, state) - return false - }) - return states, err -} - -// Changes the state for all account states in a reward program's claim period to be claimable -func (k Keeper) MakeRewardClaimsClaimableForPeriod(ctx sdk.Context, rewardProgramID, claimPeriodID uint64) error { - states, err := k.GetRewardAccountStatesForClaimPeriod(ctx, rewardProgramID, claimPeriodID) - for _, state := range states { - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - k.SetRewardAccountState(ctx, state) - } - return err -} - -// Changes the state for all account states in a reward program to be expired if they are not claimed -func (k Keeper) ExpireRewardClaimsForRewardProgram(ctx sdk.Context, rewardProgramID uint64) error { - states, err := k.GetRewardAccountStatesForRewardProgram(ctx, rewardProgramID) - for _, state := range states { - if state.ClaimStatus == types.RewardAccountState_CLAIM_STATUS_CLAIMED { - continue - } - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_EXPIRED - k.SetRewardAccountState(ctx, state) - } - return err -} diff --git a/x/reward/keeper/reward_account_state_test.go b/x/reward/keeper/reward_account_state_test.go deleted file mode 100644 index b0dccb4b69..0000000000 --- a/x/reward/keeper/reward_account_state_test.go +++ /dev/null @@ -1,381 +0,0 @@ -package keeper_test - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cometbft/cometbft/crypto/secp256k1" - - "github.com/provenance-io/provenance/x/reward/types" -) - -func (s *KeeperTestSuite) TestNewRewardAccountState() { - accountState := types.NewRewardAccountState( - 1, - 2, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - 3, - []*types.ActionCounter{}) - - s.Assert().Equal(uint64(1), accountState.GetRewardProgramId(), "reward program id must match") - s.Assert().Equal(uint64(2), accountState.GetClaimPeriodId(), "reward claim period id must match") - s.Assert().Equal(uint64(3), accountState.GetSharesEarned(), "earned shares must match") - s.Assert().Equal("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", accountState.GetAddress(), "address must match") - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, accountState.GetClaimStatus(), "should be set to unclaimable initially") - s.Assert().Equal([]*types.ActionCounter{}, accountState.GetActionCounter(), "action counter must match") -} - -func (s *KeeperTestSuite) TestGetSetRewardAccountState() { - expectedState := types.NewRewardAccountState( - 1, - 2, - "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", - 3, - nil, - ) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, expectedState) - actualState, err := s.app.RewardKeeper.GetRewardAccountState(s.ctx, - expectedState.GetRewardProgramId(), - expectedState.GetClaimPeriodId(), - expectedState.GetAddress()) - - s.Assert().Nil(err, "must not have error") - s.Assert().Equal(expectedState.GetRewardProgramId(), actualState.GetRewardProgramId(), "reward program id must match") - s.Assert().Equal(expectedState.GetClaimPeriodId(), actualState.GetClaimPeriodId(), "reward claim period id must match") - s.Assert().Equal(expectedState.GetAddress(), actualState.GetAddress(), "address must match") - s.Assert().Equal(expectedState.GetSharesEarned(), actualState.GetSharesEarned(), "shares earned must match") - s.Assert().Equal(expectedState.GetClaimStatus(), actualState.GetClaimStatus(), "should be set to unclaimed initially") - s.Assert().Equal(expectedState.GetActionCounter(), actualState.GetActionCounter(), "action counter must match") -} - -func (s *KeeperTestSuite) TestGetInvalidAccountState() { - actualState, err := s.app.RewardKeeper.GetRewardAccountState(s.ctx, - 99, - 99, - "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - - s.Assert().Nil(err, "must not have error") - s.Assert().Error(actualState.Validate(), "account state validate basic must return error") -} - -func (s *KeeperTestSuite) TestIterateAccountStates() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateRewardAccountStates(s.ctx, 2, 2, func(state types.RewardAccountState) bool { - counter += 1 - return false - })) - - s.Assert().Equal(2, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestIterateAccountStatesByAddress() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - addr, err := sdk.AccAddressFromBech32("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - s.Assert().NoError(err, "no error should be thrown") - s.Assert().NoError(s.app.RewardKeeper.IterateRewardAccountStatesByAddress(s.ctx, addr, func(state types.RewardAccountState) bool { - counter += 1 - return false - })) - - s.Assert().Equal(4, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestEmptyIterateAccountStates() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateRewardAccountStates(s.ctx, 1, 4, func(state types.RewardAccountState) bool { - counter += 1 - return false - })) - - s.Assert().Equal(0, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestIterateAccountStatesHalt() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateRewardAccountStates(s.ctx, 1, 2, func(state types.RewardAccountState) bool { - counter += 1 - return counter == 1 - })) - - s.Assert().Equal(1, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestIterateAllAccountStates() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - counter += 1 - return false - })) - - s.Assert().Equal(5, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestEmptyIterateAllAccountStates() { - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - counter += 1 - return false - })) - - s.Assert().Equal(0, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestIterateAllAccountStatesHalt() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateAllRewardAccountStates(s.ctx, func(state types.RewardAccountState) bool { - counter += 1 - return counter == 1 - })) - - s.Assert().Equal(1, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestIterateRewardAccountStatesForRewardProgram() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateRewardAccountStatesForRewardProgram(s.ctx, 2, func(state types.RewardAccountState) bool { - counter += 1 - return false - })) - - s.Assert().Equal(3, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestEmptyIterateRewardAccountStatesForRewardProgram() { - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateRewardAccountStatesForRewardProgram(s.ctx, 1, func(state types.RewardAccountState) bool { - counter += 1 - return false - })) - - s.Assert().Equal(0, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestIterateRewardAccountStatesForRewardProgramHalt() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - counter := 0 - s.Assert().NoError(s.app.RewardKeeper.IterateRewardAccountStatesForRewardProgram(s.ctx, 2, func(state types.RewardAccountState) bool { - counter += 1 - return counter == 1 - })) - - s.Assert().Equal(1, counter, "should have correct number of iterations") -} - -func (s *KeeperTestSuite) TestGetRewardAccountStatesForClaimPeriod() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - states, err := s.app.RewardKeeper.GetRewardAccountStatesForClaimPeriod(s.ctx, 2, 2) - s.Assert().NoError(err, "no error should be thrown when there are account states.") - s.Assert().Equal(2, len(states), "should have correct number of account states") -} - -func (s *KeeperTestSuite) TestGetRewardAccountStatesForClaimPeriodHandlesEmpty() { - states, err := s.app.RewardKeeper.GetRewardAccountStatesForClaimPeriod(s.ctx, 1, 1) - s.Assert().NoError(err, "no error should be thrown when there are no account states.") - s.Assert().Equal(0, len(states), "should have no account states") -} - -func (s *KeeperTestSuite) TestGetRewardAccountStatesForRewardProgram() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - states, err := s.app.RewardKeeper.GetRewardAccountStatesForRewardProgram(s.ctx, 2) - s.Assert().NoError(err, "no error should be thrown when there are account states.") - s.Assert().Equal(3, len(states), "should have correct number of account states") -} - -func (s *KeeperTestSuite) TestGetRewardAccountStatesForRewardProgramHandlesEmpty() { - states, err := s.app.RewardKeeper.GetRewardAccountStatesForClaimPeriod(s.ctx, 1, 1) - s.Assert().NoError(err, "no error should be thrown when there are no account states.") - s.Assert().Equal(0, len(states), "should have no account states") -} - -func (s *KeeperTestSuite) TestMakeRewardClaimsClaimableForPeriod() { - state1 := types.NewRewardAccountState(1, 2, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 3, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(2, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(2, 2, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 0, []*types.ActionCounter{}) - state5 := types.NewRewardAccountState(2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state5) - - err := s.app.RewardKeeper.MakeRewardClaimsClaimableForPeriod(s.ctx, 2, 2) - s.Assert().NoError(err, "no error should be thrown when there are account states.") - - state1, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 2, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - state2, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 3, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - state3, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 2, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - state4, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 2, 2, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - state5, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 2, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - - s.Assert().NotEqual(types.RewardAccountState_CLAIM_STATUS_CLAIMABLE, state1.GetClaimStatus(), "account state should not be updated to be claimable") - s.Assert().NotEqual(types.RewardAccountState_CLAIM_STATUS_CLAIMABLE, state2.GetClaimStatus(), "account state should not be updated to be claimable") - s.Assert().NotEqual(types.RewardAccountState_CLAIM_STATUS_CLAIMABLE, state3.GetClaimStatus(), "account state should not be updated to be claimable") - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_CLAIMABLE, state4.GetClaimStatus(), "account state should not be updated to be claimable") - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_CLAIMABLE, state5.GetClaimStatus(), "account state should not be updated to be claimable") -} - -func (s *KeeperTestSuite) TestMakeRewardClaimsClaimableForPeriodHandlesEmpty() { - err := s.app.RewardKeeper.MakeRewardClaimsClaimableForPeriod(s.ctx, 1, 1) - s.Assert().NoError(err, "no error should be thrown when there are no account states.") -} - -func (s *KeeperTestSuite) TestExpireRewardClaimsForRewardProgram() { - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 0, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(1, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 0, []*types.ActionCounter{}) - state4 := types.NewRewardAccountState(1, 2, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 0, []*types.ActionCounter{}) - state4.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMED - - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state4) - - err := s.app.RewardKeeper.ExpireRewardClaimsForRewardProgram(s.ctx, 1) - s.Assert().NoError(err, "no error should be thrown when there are account states.") - - state1, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - state2, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - state3, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 2, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - state4, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 2, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_EXPIRED, state1.GetClaimStatus(), "account state should be updated to expired") - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_EXPIRED, state2.GetClaimStatus(), "account state should be updated to expired") - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_EXPIRED, state3.GetClaimStatus(), "account state should be updated to expired") - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_CLAIMED, state4.GetClaimStatus(), "account state should not be updated to expired if claimed") -} - -func (s *KeeperTestSuite) TestExpireRewardClaimsForRewardProgramHandlesEmpty() { - err := s.app.RewardKeeper.ExpireRewardClaimsForRewardProgram(s.ctx, 1) - s.Assert().NoError(err, "no error should be thrown when there are no account states.") -} - -func (s *KeeperTestSuite) TestParseRewardAccountLookUpKey() { - addressFromSec256k1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - rewardProgramId := uint64(123456) - claimPeriodId := uint64(7891011) - accountStateAddressLookupKey := types.GetRewardAccountStateAddressLookupKey(addressFromSec256k1, rewardProgramId, claimPeriodId) - lookup, err := types.ParseRewardAccountLookUpKey(accountStateAddressLookupKey, addressFromSec256k1) - s.Assert().NoError(err, "no error expected for parsing GetRewardAccountStateAddressLookupKey.") - s.Assert().Equal(addressFromSec256k1, lookup.Addr) - s.Assert().Equal(rewardProgramId, lookup.RewardID) - s.Assert().Equal(claimPeriodId, lookup.ClaimID) -} diff --git a/x/reward/keeper/reward_claim.go b/x/reward/keeper/reward_claim.go deleted file mode 100644 index 011aa5c53c..0000000000 --- a/x/reward/keeper/reward_claim.go +++ /dev/null @@ -1,169 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// ClaimRewards for a given address and a given reward program id -func (k Keeper) ClaimRewards(ctx sdk.Context, rewardProgramID uint64, addr string) ([]*types.ClaimedRewardPeriodDetail, sdk.Coin, error) { - rewardProgram, err := k.GetRewardProgram(ctx, rewardProgramID) - if err != nil || rewardProgram.Validate() != nil { - return nil, sdk.Coin{}, fmt.Errorf("reward program %d does not exist", rewardProgramID) - } - - if rewardProgram.State == types.RewardProgram_STATE_EXPIRED { - return nil, sdk.Coin{}, fmt.Errorf("reward program %d has expired", rewardProgramID) - } - - rewards, err := k.claimRewardsForProgram(ctx, rewardProgram, addr) - if err != nil { - return nil, sdk.Coin{}, err - } - sent, err := k.sendRewards(ctx, rewards, addr, rewardProgram.GetTotalRewardPool().Denom) - if err != nil { - return nil, sdk.Coin{}, err - } - rewardProgram.ClaimedAmount = rewardProgram.ClaimedAmount.Add(sent) - k.SetRewardProgram(ctx, rewardProgram) - - return rewards, sent, nil -} - -// claimRewardsForProgram internal method used by ClaimRewards, which iterates over all the reward account states that the -// address is eligible for, and then claim them. -func (k Keeper) claimRewardsForProgram(ctx sdk.Context, rewardProgram types.RewardProgram, addr string) ([]*types.ClaimedRewardPeriodDetail, error) { - var states []types.RewardAccountState - address, err := sdk.AccAddressFromBech32(addr) - if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) - } - err = k.IterateRewardAccountStatesByAddressAndRewardsID(ctx, address, rewardProgram.GetId(), func(state types.RewardAccountState) bool { - if state.GetSharesEarned() > 0 && state.Address == address.String() { - states = append(states, state) - } - return false - }) - if err != nil { - return nil, err - } - - rewards := make([]*types.ClaimedRewardPeriodDetail, 0, len(states)) - for _, account := range states { - reward, found := k.claimRewardForPeriod(ctx, rewardProgram, account.ClaimPeriodId, addr) - if !found { - continue - } - rewards = append(rewards, &reward) - } - return rewards, nil -} - -// claimRewardForPeriod internal method to actually claim rewards for a period. -func (k Keeper) claimRewardForPeriod(ctx sdk.Context, rewardProgram types.RewardProgram, period uint64, addr string) (reward types.ClaimedRewardPeriodDetail, found bool) { - state, err := k.GetRewardAccountState(ctx, rewardProgram.GetId(), period, addr) - if err != nil { - return reward, false - } - if state.GetClaimStatus() != types.RewardAccountState_CLAIM_STATUS_CLAIMABLE { - return reward, false - } - - distribution, err := k.GetClaimPeriodRewardDistribution(ctx, period, rewardProgram.GetId()) - if err != nil { - return reward, false - } - - participantReward := k.CalculateParticipantReward(ctx, int64(state.GetSharesEarned()), distribution.GetTotalShares(), distribution.GetRewardsPool(), rewardProgram.MaxRewardByAddress) - reward = types.ClaimedRewardPeriodDetail{ - ClaimPeriodId: period, - TotalShares: state.GetSharesEarned(), - ClaimPeriodReward: participantReward, - } - - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMED - k.SetRewardAccountState(ctx, state) - - return reward, true -} - -// sendRewards internal method called with ClaimedRewardPeriodDetail of a single reward program -func (k Keeper) sendRewards(ctx sdk.Context, rewards []*types.ClaimedRewardPeriodDetail, addr string, rewardProgramDenom string) (sdk.Coin, error) { - amount := sdk.NewInt64Coin(rewardProgramDenom, 0) - - if len(rewards) == 0 { - return amount, nil - } - - for _, reward := range rewards { - amount.Denom = reward.GetClaimPeriodReward().Denom - amount = amount.Add(reward.GetClaimPeriodReward()) - } - - return k.sendCoinsToAccount(ctx, amount, addr) -} - -// sendCoinsToAccount internal wrapper method, to mainly do `SendCoinsFromModuleToAccount` -func (k Keeper) sendCoinsToAccount(ctx sdk.Context, amount sdk.Coin, addr string) (sdk.Coin, error) { - if amount.IsZero() { - return sdk.NewInt64Coin(amount.GetDenom(), 0), nil - } - - acc, err := sdk.AccAddressFromBech32(addr) - if err != nil { - return sdk.NewInt64Coin(amount.Denom, 0), err - } - - err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, acc, sdk.NewCoins(amount)) - if err != nil { - return sdk.NewInt64Coin(amount.Denom, 0), err - } - - return amount, nil -} - -// RefundRewardClaims refund all unclaimed rewards to the reward program creator -func (k Keeper) RefundRewardClaims(ctx sdk.Context, rewardProgram types.RewardProgram) error { - amount := rewardProgram.TotalRewardPool.Sub(rewardProgram.RemainingPoolBalance).Sub(rewardProgram.ClaimedAmount) - _, err := k.sendCoinsToAccount(ctx, amount, rewardProgram.GetDistributeFromAddress()) - return err -} - -// ClaimAllRewards calls ClaimRewards, however differs from ClaimRewards in that it claims all the rewards that the address -// is eligible for across all reward programs. -func (k Keeper) ClaimAllRewards(ctx sdk.Context, addr string) ([]*types.RewardProgramClaimDetail, sdk.Coins, error) { - allProgramDetails := []*types.RewardProgramClaimDetail{} - allRewards := sdk.Coins{} - - programs, err := k.GetAllUnexpiredRewardPrograms(ctx) - if err != nil { - return nil, sdk.Coins{}, err - } - - for _, rewardProgram := range programs { - details, reward, err := k.ClaimRewards(ctx, rewardProgram.GetId(), addr) - // err needs to propagated up, else tx will commit - if err != nil { - ctx.Logger().Error(fmt.Sprintf("Unable to claim reward program %d. Error: %v ", rewardProgram.GetId(), err)) - return nil, sdk.Coins{}, err - } - if reward.IsZero() { - ctx.Logger().Info(fmt.Sprintf("Skipping reward program %d. It has no rewards.", rewardProgram.GetId())) - continue - } - - programDetails := types.RewardProgramClaimDetail{ - RewardProgramId: rewardProgram.GetId(), - TotalRewardClaim: reward, - ClaimedRewardPeriodDetails: details, - } - allProgramDetails = append(allProgramDetails, &programDetails) - allRewards = allRewards.Add(reward) - } - - return allProgramDetails, allRewards, nil -} diff --git a/x/reward/keeper/reward_claim_test.go b/x/reward/keeper/reward_claim_test.go deleted file mode 100644 index aadd5170e1..0000000000 --- a/x/reward/keeper/reward_claim_test.go +++ /dev/null @@ -1,311 +0,0 @@ -package keeper_test - -import ( - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/types" -) - -var ( - minDelegation = sdk.NewInt64Coin("nhash", 4) - maxDelegation = sdk.NewInt64Coin("nhash", 40) -) - -func (s *KeeperTestSuite) TestClaimRewards() { - time := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time, - 10, - 3, - 0, - uint64(time.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for i := 1; i <= int(rewardProgram.GetClaimPeriods()); i++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(i), "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(i), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - - details, reward, err := s.app.RewardKeeper.ClaimRewards(s.ctx, rewardProgram.GetId(), "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - s.Assert().NoError(err, "should throw no error") - - rewardProgram, err = s.app.RewardKeeper.GetRewardProgram(s.ctx, rewardProgram.GetId()) - s.Assert().NoError(err, "should throw no error") - s.Assert().Equal(3, len(details), "should have rewards from every period") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 300), reward, "should total up the rewards from the periods") -} - -func (s *KeeperTestSuite) TestClaimRewardsHandlesInvalidProgram() { - time := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time, - 10, - 5, - 0, - uint64(time.Day()), - []types.QualifyingAction{}, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = 5 - - details, reward, err := s.app.RewardKeeper.ClaimRewards(s.ctx, rewardProgram.GetId(), "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - s.Assert().Nil(details, "should have no reward details") - s.Assert().Equal(sdk.Coin{}, reward, "should have no reward") - s.Assert().Error(err, "should throw error") -} - -func (s *KeeperTestSuite) TestClaimRewardsHandlesExpiredProgram() { - time := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time, - 10, - 5, - 0, - uint64(time.Day()), - []types.QualifyingAction{}, - ) - rewardProgram.State = types.RewardProgram_STATE_EXPIRED - rewardProgram.CurrentClaimPeriod = 5 - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - details, reward, err := s.app.RewardKeeper.ClaimRewards(s.ctx, rewardProgram.GetId(), "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - s.Assert().Nil(details, "should have no reward details") - s.Assert().Equal(sdk.Coin{}, reward, "should have no reward") - s.Assert().Error(err, "should throw error") -} - -func (s *KeeperTestSuite) TestRefundRewardClaims() { - time := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time, - 10, - 5, - 0, - uint64(time.Day()), - []types.QualifyingAction{}, - ) - rewardProgram.RemainingPoolBalance = sdk.NewInt64Coin("nhash", 0) - rewardProgram.ClaimedAmount = sdk.NewInt64Coin("nhash", 0) - - addr, _ := sdk.AccAddressFromBech32("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - beforeBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - err := s.app.RewardKeeper.RefundRewardClaims(s.ctx, rewardProgram) - afterBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - - s.Assert().NoError(err, "no error should be thrown") - s.Assert().Equal(beforeBalance.Add(rewardProgram.TotalRewardPool), afterBalance, "unclaimed balance should be refunded") -} - -func (s *KeeperTestSuite) TestRefundRewardClaimsEmpty() { - time := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time, - 10, - 5, - 0, - uint64(time.Day()), - []types.QualifyingAction{}, - ) - rewardProgram.RemainingPoolBalance = rewardProgram.GetTotalRewardPool() - rewardProgram.ClaimedAmount = sdk.NewInt64Coin("nhash", 0) - - addr, _ := sdk.AccAddressFromBech32("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - beforeBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - err := s.app.RewardKeeper.RefundRewardClaims(s.ctx, rewardProgram) - afterBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - - s.Assert().NoError(err, "no error should be thrown") - s.Assert().Equal(beforeBalance, afterBalance, "balance should stay same since all claims are taken") -} - -func (s *KeeperTestSuite) TestClaimAllRewards() { - time := s.ctx.BlockTime() - - for i := 0; i < 3; i++ { - rewardProgram := types.NewRewardProgram( - "title", - "description", - uint64(i+1), - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time, - 10, - 3, - 0, - uint64(time.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for j := 1; j <= int(rewardProgram.GetClaimPeriods()); j++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(j), "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_CLAIMABLE - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(j), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - } - - details, reward, err := s.app.RewardKeeper.ClaimAllRewards(s.ctx, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - s.Assert().NoError(err, "should throw no error") - s.Assert().Equal(3, len(details), "should have rewards from every program") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 900), reward[0], "should total up the rewards from the periods") - - for i := 0; i < len(details); i++ { - s.Assert().Equal(3, len(details[i].ClaimedRewardPeriodDetails), "should have claims from every period") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 300), details[i].TotalRewardClaim, "should total up the rewards from the periods") - s.Assert().Equal(uint64(i+1), details[i].RewardProgramId, "should have the correct id") - } -} - -func (s *KeeperTestSuite) TestClaimAllRewardsExpired() { - time := s.ctx.BlockTime() - - for i := 0; i < 3; i++ { - rewardProgram := types.NewRewardProgram( - "title", - "description", - uint64(i+1), - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - time, - 10, - 3, - 0, - uint64(time.Day()), - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.State = types.RewardProgram_STATE_EXPIRED - rewardProgram.CurrentClaimPeriod = rewardProgram.GetClaimPeriods() - s.app.RewardKeeper.SetRewardProgram(s.ctx, rewardProgram) - - for j := 1; j <= int(rewardProgram.GetClaimPeriods()); j++ { - state := types.NewRewardAccountState(rewardProgram.GetId(), uint64(j), "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 1, []*types.ActionCounter{}) - state.ClaimStatus = types.RewardAccountState_CLAIM_STATUS_EXPIRED - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - distribution := types.NewClaimPeriodRewardDistribution(uint64(j), rewardProgram.GetId(), sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, true) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, distribution) - } - } - - details, reward, err := s.app.RewardKeeper.ClaimAllRewards(s.ctx, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - s.Assert().NoError(err, "should throw no error") - s.Assert().Equal(0, len(details), "should have rewards from every program") - s.Assert().Equal(0, len(reward), "should total up the rewards from the periods") -} - -func (s *KeeperTestSuite) TestClaimAllRewardsNoPrograms() { - details, reward, err := s.app.RewardKeeper.ClaimAllRewards(s.ctx, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - s.Assert().NoError(err, "should throw no error") - s.Assert().Equal(0, len(details), "should have rewards from every program") - s.Assert().Equal(0, len(reward), "should total up the rewards from the periods") -} diff --git a/x/reward/keeper/reward_program.go b/x/reward/keeper/reward_program.go deleted file mode 100644 index 80eaf9e510..0000000000 --- a/x/reward/keeper/reward_program.go +++ /dev/null @@ -1,196 +0,0 @@ -package keeper - -import ( - "fmt" - - storetypes "cosmossdk.io/store/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// CreateRewardProgram with the rewards creator funding the creation of the program. -func (k Keeper) CreateRewardProgram(ctx sdk.Context, rewardProgram types.RewardProgram) (err error) { - err = rewardProgram.Validate() - if err != nil { - return err - } - - blockTime := ctx.BlockTime().UTC() - proposedStartTime := rewardProgram.ProgramStartTime.UTC() - if !types.TimeOnOrAfter(blockTime, proposedStartTime) { - return fmt.Errorf("start time is before current block time %v : %v ", blockTime, proposedStartTime) - } - // error check done in reward Validate() - acc, _ := sdk.AccAddressFromBech32(rewardProgram.DistributeFromAddress) - err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, acc, types.ModuleName, sdk.NewCoins(rewardProgram.TotalRewardPool)) - if err != nil { - return fmt.Errorf("unable to send coin to module reward pool : %w", err) - } - k.SetRewardProgram(ctx, rewardProgram) - return nil -} - -// EndingRewardProgram end reward program preemptively, can only be done by reward program creator. -func (k Keeper) EndingRewardProgram(ctx sdk.Context, rewardProgram types.RewardProgram) { - if rewardProgram.State == types.RewardProgram_STATE_STARTED { - rewardProgram.ClaimPeriods = rewardProgram.CurrentClaimPeriod - rewardProgram.MaxRolloverClaimPeriods = 0 - rewardProgram.ExpectedProgramEndTime = rewardProgram.ClaimPeriodEndTime - rewardProgram.ProgramEndTimeMax = rewardProgram.ClaimPeriodEndTime - k.SetRewardProgram(ctx, rewardProgram) - } else if rewardProgram.State == types.RewardProgram_STATE_PENDING { - k.RemoveRewardProgram(ctx, rewardProgram.Id) - } -} - -// SetRewardProgram sets the reward program in the keeper -func (k Keeper) SetRewardProgram(ctx sdk.Context, rewardProgram types.RewardProgram) { - store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&rewardProgram) - store.Set(types.GetRewardProgramKey(rewardProgram.Id), bz) -} - -// RemoveRewardProgram Removes a reward program in the keeper -func (k Keeper) RemoveRewardProgram(ctx sdk.Context, id uint64) bool { - store := ctx.KVStore(k.storeKey) - key := types.GetRewardProgramKey(id) - keyExists := store.Has(key) - if keyExists { - store.Delete(key) - } - return keyExists -} - -// GetRewardProgram returns a RewardProgram by id -func (k Keeper) GetRewardProgram(ctx sdk.Context, id uint64) (rewardProgram types.RewardProgram, err error) { - store := ctx.KVStore(k.storeKey) - key := types.GetRewardProgramKey(id) - bz := store.Get(key) - if len(bz) == 0 { - return rewardProgram, types.ErrRewardProgramNotFound - } - err = k.cdc.Unmarshal(bz, &rewardProgram) - return rewardProgram, err -} - -// IterateRewardPrograms iterates all reward programs with the given handler function. -func (k Keeper) IterateRewardPrograms(ctx sdk.Context, handle func(rewardProgram types.RewardProgram) (stop bool, err error)) error { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.RewardProgramKeyPrefix) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - record := types.RewardProgram{} - if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil { - return err - } - stop, err := handle(record) - if err != nil { - return err - } - if stop { - break - } - } - return nil -} - -// GetAllOutstandingRewardPrograms Gets all RewardPrograms that have not expired -func (k Keeper) GetAllOutstandingRewardPrograms(ctx sdk.Context) ([]types.RewardProgram, error) { - return k.getRewardProgramByState(ctx, types.RewardProgram_STATE_PENDING, types.RewardProgram_STATE_STARTED) -} - -// GetAllActiveRewardPrograms gets all RewardPrograms that have started -func (k Keeper) GetAllActiveRewardPrograms(ctx sdk.Context) ([]types.RewardProgram, error) { - return k.getRewardProgramByState(ctx, types.RewardProgram_STATE_STARTED) -} - -// GetAllCompletedRewardPrograms gets all completed the RewardPrograms -func (k Keeper) GetAllCompletedRewardPrograms(ctx sdk.Context) ([]types.RewardProgram, error) { - return k.getRewardProgramByState(ctx, types.RewardProgram_STATE_FINISHED, types.RewardProgram_STATE_EXPIRED) -} - -// GetAllPendingRewardPrograms gets all pending the RewardPrograms -func (k Keeper) GetAllPendingRewardPrograms(ctx sdk.Context) ([]types.RewardProgram, error) { - return k.getRewardProgramByState(ctx, types.RewardProgram_STATE_PENDING) -} - -// GetAllExpiredRewardPrograms gets all expired RewardPrograms -func (k Keeper) GetAllExpiredRewardPrograms(ctx sdk.Context) ([]types.RewardProgram, error) { - return k.getRewardProgramByState(ctx, types.RewardProgram_STATE_EXPIRED) -} - -// GetAllUnexpiredRewardPrograms gets all RewardPrograms that are not expired -func (k Keeper) GetAllUnexpiredRewardPrograms(ctx sdk.Context) ([]types.RewardProgram, error) { - return k.getRewardProgramByState(ctx, types.RewardProgram_STATE_PENDING, types.RewardProgram_STATE_STARTED, types.RewardProgram_STATE_FINISHED) -} - -// getRewardProgramByState gets rewards based on state -func (k Keeper) getRewardProgramByState(ctx sdk.Context, states ...types.RewardProgram_State) ([]types.RewardProgram, error) { - var rewardPrograms []types.RewardProgram - // get all the rewards programs by state - err := k.IterateRewardPrograms(ctx, func(rewardProgram types.RewardProgram) (stop bool, err error) { - for _, state := range states { - if rewardProgram.GetState() == state { - rewardPrograms = append(rewardPrograms, rewardProgram) - break - } - } - - return false, nil - }) - return rewardPrograms, err -} - -// GetAllRewardPrograms Gets all the RewardPrograms -func (k Keeper) GetAllRewardPrograms(ctx sdk.Context) ([]types.RewardProgram, error) { - var rewardPrograms []types.RewardProgram - err := k.IterateRewardPrograms(ctx, func(rewardProgram types.RewardProgram) (stop bool, err error) { - rewardPrograms = append(rewardPrograms, rewardProgram) - return false, nil - }) - if err != nil { - return nil, err - } - return rewardPrograms, nil -} - -// GetRewardProgramID gets the highest rewardprogram ID -func (k Keeper) GetRewardProgramID(ctx sdk.Context) (rewardprogramID uint64, err error) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.RewardProgramIDKey) - if bz == nil { - return 1, nil - } - - rewardprogramID = types.GetRewardProgramIDFromBytes(bz) - return rewardprogramID, nil -} - -// setRewardProgramID sets the new rewardprogram ID to the store -func (k Keeper) setRewardProgramID(ctx sdk.Context, rewardprogramID uint64) { - store := ctx.KVStore(k.storeKey) - store.Set(types.RewardProgramIDKey, types.GetRewardProgramIDBytes(rewardprogramID)) -} - -// GetNextRewardProgramID returns the next available reward program ID and increments keeper with next reward program ID -func (k Keeper) GetNextRewardProgramID(ctx sdk.Context) (rewardProgramID uint64, err error) { - rewardProgramID, err = k.GetRewardProgramID(ctx) - if err == nil { - k.setRewardProgramID(ctx, rewardProgramID+1) - } - return rewardProgramID, err -} - -// RefundRemainingBalance returns the remaining pool balance to the reward program creator -func (k Keeper) RefundRemainingBalance(ctx sdk.Context, rewardProgram *types.RewardProgram) error { - _, err := k.sendCoinsToAccount(ctx, rewardProgram.GetRemainingPoolBalance(), rewardProgram.GetDistributeFromAddress()) - if err != nil { - return err - } - - rewardProgram.RemainingPoolBalance = sdk.NewInt64Coin(rewardProgram.RemainingPoolBalance.GetDenom(), 0) - return nil -} diff --git a/x/reward/keeper/reward_program_test.go b/x/reward/keeper/reward_program_test.go deleted file mode 100644 index 5440d5f2a3..0000000000 --- a/x/reward/keeper/reward_program_test.go +++ /dev/null @@ -1,869 +0,0 @@ -package keeper_test - -import ( - "strings" - "time" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" - - "github.com/provenance-io/provenance/x/reward/types" -) - -func (s *KeeperTestSuite) TestNewRewardProgram() { - now := time.Now().UTC() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - - s.Assert().Equal("title", program.GetTitle(), "title should match input") - s.Assert().Equal("description", program.GetDescription(), "description should match input") - s.Assert().Equal(uint64(1), program.GetId(), "id should match input") - s.Assert().Equal("insert address", program.GetDistributeFromAddress(), "address should match input") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 100000), program.GetTotalRewardPool(), "coin should match input") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 1000), program.GetMaxRewardByAddress(), "max reward by address should match") - s.Assert().Equal(now.UTC(), program.GetProgramStartTime(), "program start time should match input") - s.Assert().Equal(uint64(60*60), program.GetClaimPeriodSeconds(), "claim period seconds should match input") - s.Assert().Equal(uint64(3), program.GetClaimPeriods(), "claim periods should match input") - s.Assert().Equal(0, len(program.GetQualifyingActions()), "qualifying actions should match input") -} - -func (s *KeeperTestSuite) TestGetSetRewardProgram() { - now := time.Now().Local().UTC() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program) - program2, err := s.app.RewardKeeper.GetRewardProgram(s.ctx, 1) - - s.Assert().NoError(err, "no error should be returned when getting reward program") - - s.Assert().Equal(program.GetTitle(), program2.GetTitle(), "title should match") - s.Assert().Equal(program.GetDescription(), program2.GetDescription(), "description should match") - s.Assert().Equal(program.GetId(), program2.GetId(), "id should match") - s.Assert().Equal(program.GetDistributeFromAddress(), program2.GetDistributeFromAddress(), "address should match") - s.Assert().Equal(program.GetTotalRewardPool(), program2.GetTotalRewardPool(), "coin should match") - s.Assert().Equal(program.GetMaxRewardByAddress(), program2.GetMaxRewardByAddress(), "max reward by address should") - s.Assert().Equal(program.GetProgramStartTime(), program2.GetProgramStartTime(), "program start time should match") - s.Assert().Equal(program.GetClaimPeriodSeconds(), program2.GetClaimPeriodSeconds(), "claim period seconds should match") - s.Assert().Equal(program.GetClaimPeriods(), program2.GetClaimPeriods(), "number of claim periods should match") - s.Assert().Equal(len(program.GetQualifyingActions()), len(program2.GetQualifyingActions()), "qualifying actions should match") -} - -func (s *KeeperTestSuite) TestEndingRewardProgram() { - now := time.Now() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 3, - 0, - []types.QualifyingAction{}, - ) - program.State = types.RewardProgram_STATE_STARTED - program.Id = 10 - - program.CurrentClaimPeriod = 2 - program.ClaimPeriodEndTime = now - s.app.RewardKeeper.SetRewardProgram(s.ctx, program) - s.app.RewardKeeper.EndingRewardProgram(s.ctx, program) - - endingRewardProgram, err := s.app.RewardKeeper.GetRewardProgram(s.ctx, 10) - s.Assert().NoError(err) - s.Assert().Equal(uint64(2), endingRewardProgram.ClaimPeriods) - s.Assert().Equal(uint64(0), endingRewardProgram.MaxRolloverClaimPeriods) - s.Assert().Equal(now.UTC(), endingRewardProgram.ExpectedProgramEndTime) - s.Assert().Equal(now.UTC(), endingRewardProgram.ProgramEndTimeMax) - - program.State = types.RewardProgram_STATE_PENDING - program.Id = 20 - s.app.RewardKeeper.SetRewardProgram(s.ctx, program) - endingRewardProgram, err = s.app.RewardKeeper.GetRewardProgram(s.ctx, 20) - s.Assert().NoError(err) - s.Assert().Equal(uint64(20), endingRewardProgram.Id) - - s.app.RewardKeeper.EndingRewardProgram(s.ctx, program) - endingRewardProgram, err = s.app.RewardKeeper.GetRewardProgram(s.ctx, 20) - s.Assert().Error(err) - s.Assert().Equal(uint64(0), endingRewardProgram.Id) -} - -func (s *KeeperTestSuite) TestRemoveValidRewardProgram() { - now := time.Now() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program) - removed := s.app.RewardKeeper.RemoveRewardProgram(s.ctx, 1) - s.Assert().True(removed, "remove should succeed") - - invalidProgram, err := s.app.RewardKeeper.GetRewardProgram(s.ctx, 1) - s.Assert().Error(err) - s.Assert().Equal(uint64(0), invalidProgram.Id) -} - -func (s *KeeperTestSuite) TestRemoveInvalidRewardProgram() { - invalidProgram, err := s.app.RewardKeeper.GetRewardProgram(s.ctx, 1) - s.Assert().Error(err) - s.Assert().Equal(uint64(0), invalidProgram.Id) -} - -func (s *KeeperTestSuite) TestIterateRewardPrograms() { - now := time.Now() - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - - counter := 0 - err := s.app.RewardKeeper.IterateRewardPrograms(s.ctx, func(rewardProgram types.RewardProgram) (stop bool, err error) { - counter += 1 - return false, nil - }) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(3, counter, "should iterate through each reward program") -} - -func (s *KeeperTestSuite) TestIterateRewardProgramsHalt() { - now := time.Now() - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - - counter := 0 - err := s.app.RewardKeeper.IterateRewardPrograms(s.ctx, func(rewardProgram types.RewardProgram) (stop bool, err error) { - counter += 1 - return true, nil - }) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(1, counter, "should stop when iteration is instructed to stop") -} - -func (s *KeeperTestSuite) TestIterateRewardProgramsEmpty() { - counter := 0 - err := s.app.RewardKeeper.IterateRewardPrograms(s.ctx, func(rewardProgram types.RewardProgram) (stop bool, err error) { - counter += 1 - return true, nil - }) - - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(0, counter, "should stop when iteration is instructed to stop") -} - -func (s *KeeperTestSuite) TestGetAllOutstandingRewardPrograms() { - now := time.Now() - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2.State = types.RewardProgram_STATE_STARTED - program3.State = types.RewardProgram_STATE_FINISHED - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - - programs, err := s.app.RewardKeeper.GetAllOutstandingRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(2, len(programs), "should have all outstanding programs") - s.Assert().Equal(uint64(1), programs[0].GetId(), "should have program 1") - s.Assert().Equal(uint64(2), programs[1].GetId(), "should have program 2") -} - -func (s *KeeperTestSuite) TestGetAllOutstandingRewardProgramsEmpty() { - programs, err := s.app.RewardKeeper.GetAllOutstandingRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(0, len(programs), "should have no outstanding programs") -} - -func (s *KeeperTestSuite) TestGetAllExpiredRewardPrograms() { - now := time.Now() - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program4 := types.NewRewardProgram( - "title", - "description", - 4, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program5 := types.NewRewardProgram( - "title", - "description", - 5, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2.State = types.RewardProgram_STATE_STARTED - program3.State = types.RewardProgram_STATE_FINISHED - program4.State = types.RewardProgram_STATE_EXPIRED - program5.State = types.RewardProgram_STATE_EXPIRED - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program4) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program5) - - programs, err := s.app.RewardKeeper.GetAllExpiredRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(2, len(programs), "should have all outstanding programs") - s.Assert().Equal(uint64(4), programs[0].GetId(), "should have program 4") - s.Assert().Equal(uint64(5), programs[1].GetId(), "should have program 5") -} - -func (s *KeeperTestSuite) TestGetAllExpiredRewardProgramsEmpty() { - programs, err := s.app.RewardKeeper.GetAllExpiredRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(0, len(programs), "should have no expired programs") -} - -func (s *KeeperTestSuite) TestGetAllUnexpiredRewardPrograms() { - now := time.Now() - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program4 := types.NewRewardProgram( - "title", - "description", - 4, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program5 := types.NewRewardProgram( - "title", - "description", - 5, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2.State = types.RewardProgram_STATE_STARTED - program3.State = types.RewardProgram_STATE_FINISHED - program4.State = types.RewardProgram_STATE_EXPIRED - program5.State = types.RewardProgram_STATE_EXPIRED - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program4) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program5) - - programs, err := s.app.RewardKeeper.GetAllUnexpiredRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(3, len(programs), "should have all unexpired programs") - s.Assert().Equal(uint64(1), programs[0].GetId(), "should have program 1") - s.Assert().Equal(uint64(2), programs[1].GetId(), "should have program 2") - s.Assert().Equal(uint64(3), programs[2].GetId(), "should have program 3") -} - -func (s *KeeperTestSuite) TestGetAllUnexpiredRewardProgramsEmpty() { - programs, err := s.app.RewardKeeper.GetAllUnexpiredRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(0, len(programs), "should have no expired programs") -} - -func (s *KeeperTestSuite) TestGetAllActiveRewardPrograms() { - now := time.Now() - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2.State = types.RewardProgram_STATE_STARTED - program3.State = types.RewardProgram_STATE_FINISHED - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - - programs, err := s.app.RewardKeeper.GetAllActiveRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(1, len(programs), "should have all active programs") - s.Assert().Equal(uint64(2), programs[0].GetId(), "should have program 2") -} - -func (s *KeeperTestSuite) TestGetAllActiveRewardProgramsEmpty() { - programs, err := s.app.RewardKeeper.GetAllActiveRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(0, len(programs), "should have no active programs") -} - -func (s *KeeperTestSuite) TestGetAllRewardPrograms() { - now := time.Now() - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2.State = types.RewardProgram_STATE_STARTED - program3.State = types.RewardProgram_STATE_FINISHED - - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - - programs, err := s.app.RewardKeeper.GetAllRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(3, len(programs), "should have all active programs") - s.Assert().Equal(uint64(1), programs[0].GetId(), "should have program 1") - s.Assert().Equal(uint64(2), programs[1].GetId(), "should have program 2") - s.Assert().Equal(uint64(3), programs[2].GetId(), "should have program 3") -} - -func (s *KeeperTestSuite) TestGetAllRewardProgramsEmpty() { - programs, err := s.app.RewardKeeper.GetAllRewardPrograms(s.ctx) - s.Assert().NoError(err, "no error should be returned") - s.Assert().Equal(0, len(programs), "should have no active programs") -} - -func (s *KeeperTestSuite) TestCreateRewardProgram() { - testutil.FundAccount(s.ctx, s.app.BankKeeper, s.accountAddresses[0], sdk.NewCoins(sdk.NewInt64Coin("nhash", 1000000000000))) - - err := s.app.RewardKeeper.CreateRewardProgram(s.ctx, types.RewardProgram{}) - s.Assert().Error(err) - - now := time.Now() - validProgram := types.NewRewardProgram( - "title", - "description", - 1, - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - err = s.app.RewardKeeper.CreateRewardProgram(s.ctx, validProgram) - s.Assert().NoError(err) - actualProgram, err := s.app.RewardKeeper.GetRewardProgram(s.ctx, uint64(1)) - s.Assert().NoError(err) - s.Equal(uint64(1), actualProgram.Id) - lastYear := now.Add(-60 * 60 * 365 * time.Second) - inValidProgramStartTime := types.NewRewardProgram( - "title", - "description", - 2, - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - lastYear, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - err = s.app.RewardKeeper.CreateRewardProgram(s.ctx, inValidProgramStartTime) - s.Assert().Error(err) - s.Assert().True(strings.Contains(err.Error(), "start time is before current block time")) - - minDelegation := sdk.NewInt64Coin("nhash", 4) - maxDelegation := sdk.NewInt64Coin("nhash", 40) - - invalidAmount := types.NewRewardProgram( - "title", - "description", - 2, - s.accountAddresses[0].String(), - sdk.NewInt64Coin("nhash", 10000000000000), - sdk.NewInt64Coin("nhash", 1000), - now, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - err = s.app.RewardKeeper.CreateRewardProgram(s.ctx, invalidAmount) - s.Assert().ErrorContains(err, "unable to send coin to module reward pool : spendable balance 999999900000nhash is smaller than 10000000000000nhash: insufficient funds") -} - -func (s *KeeperTestSuite) TestRefundRemainingBalance() { - now := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 5, - 0, - uint64(now.Day()), - []types.QualifyingAction{}, - ) - remainingBalance := rewardProgram.GetTotalRewardPool() - rewardProgram.RemainingPoolBalance = remainingBalance - rewardProgram.ClaimedAmount = sdk.NewInt64Coin("nhash", 0) - - addr, _ := sdk.AccAddressFromBech32("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - beforeBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - err := s.app.RewardKeeper.RefundRemainingBalance(s.ctx, &rewardProgram) - afterBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - - s.Assert().NoError(err, "no error should be thrown") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), rewardProgram.GetRemainingPoolBalance(), "no remaining balance should be left") - s.Assert().Equal(beforeBalance.Add(remainingBalance), afterBalance, "balance should be given remaining pool balance") -} - -func (s *KeeperTestSuite) TestRefundRemainingBalanceEmpty() { - now := s.ctx.BlockTime() - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 100), - now, - 10, - 5, - 0, - uint64(now.Day()), - []types.QualifyingAction{}, - ) - rewardProgram.RemainingPoolBalance = sdk.NewInt64Coin("nhash", 0) - rewardProgram.ClaimedAmount = sdk.NewInt64Coin("nhash", 0) - - addr, _ := sdk.AccAddressFromBech32("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - beforeBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - err := s.app.RewardKeeper.RefundRemainingBalance(s.ctx, &rewardProgram) - afterBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - - s.Assert().NoError(err, "no error should be thrown") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), rewardProgram.GetRemainingPoolBalance(), "no remaining balance should be left") - s.Assert().Equal(beforeBalance, afterBalance, "balance should remain same because there is no remaining pool balance") -} - -func (s *KeeperTestSuite) TestGetRewardProgramID() { - id, err := s.app.RewardKeeper.GetRewardProgramID(s.ctx) - s.Assert().NoError(err, "no error should be thrown") - s.Assert().Equal(uint64(1), id, "id should match") - - next, err := s.app.RewardKeeper.GetNextRewardProgramID(s.ctx) - s.Assert().NoError(err, "no error should be thrown") - s.Assert().Equal(uint64(1), next, "id should match") - - id, err = s.app.RewardKeeper.GetRewardProgramID(s.ctx) - s.Assert().NoError(err, "no error should be thrown") - s.Assert().Equal(uint64(2), id, "id should match") -} diff --git a/x/reward/keeper/rules.go b/x/reward/keeper/rules.go deleted file mode 100644 index 5c16732baa..0000000000 --- a/x/reward/keeper/rules.go +++ /dev/null @@ -1,279 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// CacheContextWithHistory returns a new Context with the multi-store cached and a new -// EventManager with existing history. The cached context is written to the context when writeCache -// is called. Note, events are automatically emitted on the parent context's -// EventManager when the caller executes the write. -// -// This is similar to the ctx.CacheContext() function, but this keeps the history so we can act on it. -func CacheContextWithHistory(ctx sdk.Context) (cc sdk.Context, writeCache func()) { - cms := ctx.MultiStore().CacheMultiStore() - cc = ctx.WithMultiStore(cms) - abciEventHistory, ok := ctx.EventManager().(sdk.EventManagerWithHistoryI) - if !ok { - panic("event manager does not implement EventManagerWithHistoryI") - } - cc = cc.WithEventManager(sdk.NewEventManagerWithHistory(abciEventHistory.GetABCIEventHistory())) - - writeCache = func() { - ctx.EventManager().EmitEvents(cc.EventManager().Events()) - cms.Write() - } - - return cc, writeCache -} - -// ProcessTransactions in the endblock -func (k Keeper) ProcessTransactions(origCtx sdk.Context) { - // Get all Active Reward Programs - rewardPrograms, err := k.GetAllActiveRewardPrograms(origCtx) - if err != nil { - origCtx.Logger().Error(err.Error()) - return - } - - // Grant shares for qualifying actions - for index := range rewardPrograms { - // Because this is designed for the EndBlocker, we don't always have auto-rollback. - // We don't partial state recorded if an error is encountered in the middle. - // So use a cache context and only write it if there wasn't an error. - ctx, writeCtx := CacheContextWithHistory(origCtx) - // Go through all the reward programs - actions, err := k.DetectQualifyingActions(ctx, &rewardPrograms[index]) - if err != nil { - ctx.Logger().Error(err.Error()) - continue - } - - // Record any results - err = k.RewardShares(ctx, &rewardPrograms[index], actions) - if err != nil { - ctx.Logger().Error(err.Error()) - continue - } - - writeCtx() - } -} - -// DetectQualifyingActions takes in the RewardProgram and checks if any of the qualifying actions is found in the event history -func (k Keeper) DetectQualifyingActions(ctx sdk.Context, program *types.RewardProgram) ([]types.EvaluationResult, error) { - ctx.Logger().Info(fmt.Sprintf("EvaluateRules for RewardProgram: %d", program.GetId())) - results := []types.EvaluationResult(nil) - - // Check if any of the transactions are qualifying actions - for _, supportedAction := range program.GetQualifyingActions() { - // Get the appropriate RewardAction - // If it's not supported we skip it - action, err := supportedAction.GetRewardAction(ctx) - if err != nil { - ctx.Logger().Info(err.Error()) - continue - } - - // Build all the qualifying actions from the abci events - actions, err := k.FindQualifyingActions(ctx, action) - if err != nil { - return nil, err - } - - // Process actions and get the results - actions = k.ProcessQualifyingActions(ctx, program, action, actions) - results = append(results, actions...) - } - - return results, nil -} - -// ProcessQualifyingActions process the detected qualifying actions. -func (k Keeper) ProcessQualifyingActions(ctx sdk.Context, program *types.RewardProgram, processor types.RewardAction, actions []types.EvaluationResult) []types.EvaluationResult { - successfulActions := []types.EvaluationResult(nil) - if program == nil || processor == nil || actions == nil { - return successfulActions - } - - for _, action := range actions { - state, err := k.GetRewardAccountState(ctx, program.GetId(), program.GetCurrentClaimPeriod(), action.Address.String()) - if err != nil { - continue - } - if state.Validate() != nil { - state = types.NewRewardAccountState(program.GetId(), program.GetCurrentClaimPeriod(), action.Address.String(), 0, []*types.ActionCounter{}) - } - - if !processor.PreEvaluate(ctx, k, state) { - k.SetRewardAccountState(ctx, state) - continue - } - if !processor.Evaluate(ctx, k, state, action) { - k.SetRewardAccountState(ctx, state) - continue - } - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, processor.ActionType()) - postEvalRes, evaluationResultFromPostEval := processor.PostEvaluate(ctx, k, state, action) - if !postEvalRes { - k.SetRewardAccountState(ctx, state) - continue - } - - successfulActions = append(successfulActions, evaluationResultFromPostEval) - k.SetRewardAccountState(ctx, state) - } - - return successfulActions -} - -// RewardShares Sets shares for an account(i.e address) based on EvaluationResult -func (k Keeper) RewardShares(ctx sdk.Context, rewardProgram *types.RewardProgram, evaluateRes []types.EvaluationResult) error { - ctx.Logger().Info(fmt.Sprintf("Recording shares for for rewardProgramId=%d, claimPeriod=%d", - rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod())) - - if rewardProgram == nil { - return sdkerrors.ErrNotFound.Wrap("reward program cannot be nil") - } - - // get the ClaimPeriodRewardDistribution - claimPeriodRewardDistribution, err := k.GetClaimPeriodRewardDistribution(ctx, rewardProgram.GetCurrentClaimPeriod(), rewardProgram.GetId()) - - if err != nil { - return err - } - - if claimPeriodRewardDistribution.Validate() != nil { - return sdkerrors.ErrNotFound.Wrap("invalid claim period reward distribution") - } - - for _, res := range evaluateRes { - state, err := k.GetRewardAccountState(ctx, rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), res.Address.String()) - if state.Validate() != nil { - ctx.Logger().Error(fmt.Sprintf("Account state does not exist for RewardProgram: %d, ClaimPeriod: %d, Address: %s. Skipping...", - rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), res.Address.String())) - continue - } - if err != nil { - return err - } - - state.SharesEarned += uint64(res.Shares) - k.SetRewardAccountState(ctx, state) - // we know the rewards, so update the claim period reward - claimPeriodRewardDistribution.TotalShares += res.Shares - } - - // set total claim period rewards distribution. - k.SetClaimPeriodRewardDistribution(ctx, claimPeriodRewardDistribution) - - return nil -} - -// IterateABCIEvents Iterates through all the ABCIEvents that match the eventCriteria. -// Nil criteria means to iterate over everything. -func (k Keeper) IterateABCIEvents(ctx sdk.Context, criteria *types.EventCriteria, action func(string, *map[string][]byte) error) error { - abciEventHistory, ok := ctx.EventManager().(sdk.EventManagerWithHistoryI) - if !ok { - panic("event manager does not implement EventManagerWithHistoryI") - } - - for _, event := range abciEventHistory.GetABCIEventHistory() { - event := event - - // Event type must match the criteria - // nil criteria is considered to match everything - if criteria != nil && !criteria.MatchesEvent(event.Type) { - continue - } - - // Convert the attributes into a map - attributes := make(map[string][]byte) - for _, attribute := range event.Attributes { - attributes[string(attribute.Key)] = []byte(attribute.Value) - } - - valid := true - if criteria != nil { - // Ensure each attribute matches the required criteria - // If a single attribute does not match then we don't continue with the event - eventCriteria := criteria.Events[event.Type] - for key := range eventCriteria.Attributes { - valid = eventCriteria.MatchesAttribute(key, attributes[key]) - if !valid { - break - } - } - } - if !valid { - continue - } - - err := action(event.Type, &attributes) - if err != nil { - return err - } - } - return nil -} - -// FindQualifyingActions iterates event history and applies the RewardAction to them, adds them to the result if they qualify. -func (k Keeper) FindQualifyingActions(ctx sdk.Context, action types.RewardAction) ([]types.EvaluationResult, error) { - result := ([]types.EvaluationResult)(nil) - builder := action.GetBuilder() - - err := k.IterateABCIEvents(ctx, builder.GetEventCriteria(), func(eventType string, attributes *map[string][]byte) error { - // Add the event to the builder - err := builder.AddEvent(eventType, attributes) - if err != nil { - return err - } - - // Not finished building skip attempting to build - if !builder.CanBuild() { - return nil - } - - // Attempt to build - action, err := builder.BuildAction() - if err != nil { - return err - } - result = append(result, action) - - builder.Reset() - - return nil - }) - if err != nil { - return nil, err - } - - return result, nil -} - -// GetAccountKeeper gets this Keeper's AccountKeeper. -func (k Keeper) GetAccountKeeper() types.AccountKeeper { - return k.authkeeper -} - -// GetStakingKeeper gets this Keeper's StakingKeeper. -func (k Keeper) GetStakingKeeper() types.StakingKeeper { - return k.stakingKeeper -} - -// SetStakingKeeper only used in tests -func (k *Keeper) SetStakingKeeper(newKeeper types.StakingKeeper) { - k.stakingKeeper = newKeeper -} - -// SetAccountKeeper only used in tests -func (k *Keeper) SetAccountKeeper(newKeeper authkeeper.AccountKeeper) { - k.authkeeper = newKeeper -} diff --git a/x/reward/keeper/rules_test.go b/x/reward/keeper/rules_test.go deleted file mode 100644 index a4fa5381af..0000000000 --- a/x/reward/keeper/rules_test.go +++ /dev/null @@ -1,1513 +0,0 @@ -package keeper_test - -import ( - "context" - "errors" - "fmt" - "time" - - sdkmath "cosmossdk.io/math" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/cosmos-sdk/x/staking/keeper" - teststaking "github.com/cosmos/cosmos-sdk/x/staking/testutil" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - simapp "github.com/provenance-io/provenance/app" - "github.com/provenance-io/provenance/x/reward/types" -) - -const delegatorAddr = "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h" - -var ( - testValidators = []stakingtypes.Validator{} -) - -func setupEventHistory(s *KeeperTestSuite) { - attributes1 := []sdk.Attribute{ - sdk.NewAttribute("key1", "value1"), - sdk.NewAttribute("key2", "value2"), - sdk.NewAttribute("key3", "value3"), - } - attributes2 := []sdk.Attribute{ - sdk.NewAttribute("key1", "value1"), - sdk.NewAttribute("key3", "value2"), - sdk.NewAttribute("key4", "value3"), - } - event1 := sdk.NewEvent("event1", attributes1...) - event2 := sdk.NewEvent("event2", attributes2...) - event3 := sdk.NewEvent("event1", attributes1...) - loggedEvents := sdk.Events{ - event1, - event2, - event3, - } - SetupEventHistory(s, loggedEvents) -} - -func SetupEventHistory(s *KeeperTestSuite, events sdk.Events) { - eventManagerStub := sdk.NewEventManagerWithHistory(events.ToABCIEvents()) - s.ctx = s.ctx.WithEventManager(eventManagerStub) -} - -// with delegate -func SetupEventHistoryWithDelegates(s *KeeperTestSuite) { - attributes1 := []sdk.Attribute{ - sdk.NewAttribute("validator", "cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun"), - sdk.NewAttribute("amount", "1000000000000000nhash"), - } - attributes2 := []sdk.Attribute{ - sdk.NewAttribute("module", "staking"), - sdk.NewAttribute("sender", delegatorAddr), - } - attributes3 := []sdk.Attribute{ - sdk.NewAttribute("validator", "cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun"), - sdk.NewAttribute("amount", "50000000000000nhash"), - sdk.NewAttribute("new_shares", "50000000000000.000000000000000000"), - } - event1 := sdk.NewEvent("create_validator", attributes1...) - event2 := sdk.NewEvent("message", attributes2...) - event3 := sdk.NewEvent("delegate", attributes3...) - event4 := sdk.NewEvent("message", attributes2...) - loggedEvents := sdk.Events{ - event1, - event2, - event3, - event4, - } - SetupEventHistory(s, loggedEvents) -} - -func (s *KeeperTestSuite) TestProcessTransactions() { - now := time.Unix(1681964400, 0) // roughly Provenance Blockchain's 2-year anniversary. - curHeader := s.ctx.BlockHeader() - curHeader.Time = now - s.ctx = s.ctx.WithBlockHeader(curHeader) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - - // Create a reward program - s.Require().NoError(testutil.FundAccount(s.ctx, s.app.BankKeeper, s.accountAddr, - sdk.NewCoins(sdk.NewInt64Coin("nhash", 1000000))), "funding accountAddr") - minDel := sdk.NewInt64Coin("nhash", 1) - maxDel := sdk.NewInt64Coin("nhash", 40) - program := types.NewRewardProgram( - "title", - "description", - 1, - s.accountAddr.String(), - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - now.Add(1*time.Second), - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDel, - MaximumDelegationAmount: &maxDel, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - s.Require().NoError(s.app.RewardKeeper.CreateRewardProgram(s.ctx, program), "CreateRewardProgram") - - // Start the reward program. - curHeader = s.ctx.BlockHeader() - curHeader.Time = program.ProgramStartTime.Add(1 * time.Second) - s.ctx = s.ctx.WithBlockHeader(curHeader) - s.app.RewardKeeper.UpdateUnexpiredRewardsProgram(s.ctx) - - // make sure the reward program has started. - var err error - program, err = s.app.RewardKeeper.GetRewardProgram(s.ctx, program.GetId()) - s.Require().NoError(err, "GetRewardProgram") - s.Require().Equal(types.RewardProgram_STATE_STARTED.String(), program.State.String(), "program state") - - // Fake some events and process them. - SetupEventHistoryWithDelegates(s) - s.Require().NotPanics(func() { - s.app.RewardKeeper.ProcessTransactions(s.ctx) - }, "ProcessTransactions") - - // Make sure the share was recorded in both the reward account state for the delegator and claim period distribution. - state, err := s.app.RewardKeeper.GetRewardAccountState(s.ctx, program.GetId(), program.GetCurrentClaimPeriod(), delegatorAddr) - s.Require().NoError(err, "GetRewardAccountState") - s.Assert().Equal(1, int(state.SharesEarned), "state.SharesEarned") - claimPeriodRewardDistribution, err := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, program.GetCurrentClaimPeriod(), program.GetId()) - s.Require().NoError(err, "GetClaimPeriodRewardDistribution") - s.Assert().Equal(1, int(claimPeriodRewardDistribution.GetTotalShares()), "claimPeriodRewardDistribution.GetTotalShares()") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsWildcard() { - setupEventHistory(s) - var events []types.ABCIEvent - criteria := types.NewEventCriteria(events) - counter := 0 - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return nil - }) - s.Assert().NoError(err, "IterateABCIEvents") - s.Assert().Equal(3, counter, "should iterate for each event") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsByEventType() { - setupEventHistory(s) - counter := 0 - events := []types.ABCIEvent{ - { - Type: "event1", - }, - } - criteria := types.NewEventCriteria(events) - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return nil - }) - s.Assert().NoError(err, "IterateABCIEvents") - s.Assert().Equal(2, counter, "should iterate only for specified event types") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsByEventTypeAndAttributeName() { - setupEventHistory(s) - counter := 0 - events := []types.ABCIEvent{ - { - Type: "event1", - Attributes: map[string][]byte{ - "key1": nil, - }, - }, - } - criteria := types.NewEventCriteria(events) - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return nil - }) - s.Assert().NoError(err, "IterateABCIEvents") - s.Assert().Equal(2, counter, "should iterate only for specified event types with matching attributes") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsByEventTypeAndAttributeNameAndValue() { - setupEventHistory(s) - counter := 0 - events := []types.ABCIEvent{ - { - Type: "event1", - Attributes: map[string][]byte{ - "key1": []byte("value1"), - }, - }, - } - criteria := types.NewEventCriteria(events) - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return nil - }) - s.Assert().NoError(err, "IterateABCIEvents") - s.Assert().Equal(2, counter, "should iterate only for specified event types with matching attributes") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsNonExistantEventType() { - setupEventHistory(s) - counter := 0 - events := []types.ABCIEvent{ - { - Type: "event5", - Attributes: map[string][]byte{}, - }, - } - criteria := types.NewEventCriteria(events) - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return nil - }) - s.Assert().NoError(err, "IterateABCIEvents") - s.Assert().Equal(0, counter, "should not iterate if event doesn't exist") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsNonExistantAttributeName() { - setupEventHistory(s) - counter := 0 - events := []types.ABCIEvent{ - { - Type: "event1", - Attributes: map[string][]byte{ - "blah": []byte("value5"), - }, - }, - } - criteria := types.NewEventCriteria(events) - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return nil - }) - s.Assert().NoError(err, "IterateABCIEvents") - s.Assert().Equal(0, counter, "should not iterate if attribute doesn't match") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsNonAttributeValueMatch() { - setupEventHistory(s) - counter := 0 - events := []types.ABCIEvent{ - { - Type: "event1", - Attributes: map[string][]byte{ - "key1": []byte("value5"), - }, - }, - } - criteria := types.NewEventCriteria(events) - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return nil - }) - s.Assert().NoError(err, "IterateABCIEvents") - s.Assert().Equal(0, counter, "should not iterate if attribute doesn't match") -} - -func (s *KeeperTestSuite) TestIterateABCIEventsHandlesError() { - setupEventHistory(s) - counter := 0 - events := []types.ABCIEvent{ - { - Type: "event1", - Attributes: map[string][]byte{ - "key1": []byte("value1"), - }, - }, - } - criteria := types.NewEventCriteria(events) - err := s.app.RewardKeeper.IterateABCIEvents(s.ctx, criteria, func(name string, attributes *map[string][]byte) error { - counter += 1 - return errors.New("error") - }) - s.Assert().Error(err, "should throw error when internal function errors") -} - -func (s *KeeperTestSuite) TestFindQualifyingActionsWithDelegates() { - SetupEventHistoryWithDelegates(s) - criteria := types.NewEventCriteria([]types.ABCIEvent{ - { - Type: "message", - Attributes: map[string][]byte{ - "module": []byte("staking"), - }, - }, - { - Type: "delegate", - Attributes: map[string][]byte{}, - }, - { - Type: "create_validator", - Attributes: map[string][]byte{}, - }, - }) - - action := MockAction{Criteria: criteria, Builder: &types.DelegateActionBuilder{}} - events, err := s.app.RewardKeeper.FindQualifyingActions(s.ctx, action) - s.Assert().NoError(err, "should throw no error when handling no events") - s.Assert().Equal(2, len(events), "should find the two delegate events") - for _, event := range events { - s.Assert().Equal(event.Shares, int64(1), "shares must be 1") - s.Assert().Equal(event.Delegator.String(), "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", "delegator address must be correct") - s.Assert().Equal(event.Validator.String(), "cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun", "validator address must be correct") - } -} - -func (s *KeeperTestSuite) TestFindQualifyingActionsWithoutDelegates() { - criteria := types.NewEventCriteria([]types.ABCIEvent{ - { - Type: "message", - Attributes: map[string][]byte{ - "module": []byte("staking"), - }, - }, - { - Type: "delegate", - Attributes: map[string][]byte{}, - }, - { - Type: "create_validator", - Attributes: map[string][]byte{}, - }, - }) - action := MockAction{Criteria: criteria, Builder: &types.DelegateActionBuilder{}} - events, err := s.app.RewardKeeper.FindQualifyingActions(s.ctx, action) - s.Assert().NoError(err, "should throw no error when handling no events") - s.Assert().Equal(0, len(events), "should have no events when no delegates are made") -} - -// FindQualifyingActions - -type MockAction struct { - PassEvaluate bool - Criteria *types.EventCriteria - Builder types.ActionBuilder -} - -func (m MockAction) ActionType() string { - return "" -} - -func (m MockAction) Evaluate(ctx sdk.Context, provider types.KeeperProvider, state types.RewardAccountState, event types.EvaluationResult) bool { - return m.PassEvaluate -} - -func (m MockAction) GetEventCriteria() *types.EventCriteria { - return m.Criteria -} - -func (m MockAction) GetBuilder() types.ActionBuilder { - return m.Builder -} - -func (m MockAction) PreEvaluate(ctx sdk.Context, provider types.KeeperProvider, state types.RewardAccountState) bool { - return true - // Any action specific thing that we need to do before evaluation -} - -func (m MockAction) PostEvaluate(ctx sdk.Context, provider types.KeeperProvider, state types.RewardAccountState, evaluationResult types.EvaluationResult) (bool, types.EvaluationResult) { - return true, evaluationResult - // Any action specific thing that we need to do after evaluation -} - -func (s *KeeperTestSuite) TestProcessQualifyingActionsWithNoAbciEvents() { - program := types.RewardProgram{Id: 1, CurrentClaimPeriod: 1} - action := MockAction{PassEvaluate: false} - results := s.app.RewardKeeper.ProcessQualifyingActions(s.ctx, &program, action, []types.EvaluationResult{}) - s.Assert().Equal(0, len(results), "should have no results for empty list of abci events") -} - -func (s *KeeperTestSuite) TestProcessQualifyingActionsCreatesState() { - program := types.RewardProgram{Id: 1, CurrentClaimPeriod: 1} - action := MockAction{PassEvaluate: true} - address1, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - s.app.RewardKeeper.ProcessQualifyingActions(s.ctx, &program, action, []types.EvaluationResult{ - { - Address: address1, - }, - }) - state, _ := s.app.RewardKeeper.GetRewardAccountState(s.ctx, program.GetId(), program.GetCurrentClaimPeriod(), address1.String()) - s.Assert().Equal(program.GetId(), state.RewardProgramId, "claim period should be created when missing") -} - -func (s *KeeperTestSuite) TestProcessQualifyingActionsWithNoMatchingResults() { - program := types.RewardProgram{Id: 1, CurrentClaimPeriod: 1} - action := MockAction{PassEvaluate: false} - results := s.app.RewardKeeper.ProcessQualifyingActions(s.ctx, &program, action, []types.EvaluationResult{ - {Address: types.MustAccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h")}, - {Address: types.MustAccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h")}, - }) - s.Assert().Equal(0, len(results), "should have empty lists when no results match the evaluation") -} - -func (s *KeeperTestSuite) TestProcessQualifyingActionsWithMatchingResults() { - program := types.RewardProgram{Id: 1, CurrentClaimPeriod: 1} - action := MockAction{PassEvaluate: true} - results := s.app.RewardKeeper.ProcessQualifyingActions(s.ctx, &program, action, []types.EvaluationResult{ - {Address: types.MustAccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h")}, - {Address: types.MustAccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h")}, - }) - s.Assert().Equal(2, len(results), "should have all results that evaluate to true") -} - -func (s *KeeperTestSuite) TestFindQualifyingActionsWithNil() { - results := s.app.RewardKeeper.ProcessQualifyingActions(s.ctx, nil, nil, nil) - s.Assert().Equal(0, len(results), "should handle nil input") -} - -// Test ActionDelegate Evaluate - -type MockKeeperProvider struct { -} - -func (m MockKeeperProvider) GetStakingKeeper() types.StakingKeeper { - return MockStakingKeeper{} -} - -func (m MockKeeperProvider) GetAccountKeeper() types.AccountKeeper { - return MockAccountKeeper{} -} - -type MockStakingKeeper struct { -} - -type MockAccountKeeper struct { -} - -func (m MockAccountKeeper) GetModuleAddress(moduleName string) sdk.AccAddress { - return nil -} - -func (m MockStakingKeeper) GetAllDelegatorDelegations(ctx context.Context, delegator sdk.AccAddress) ([]stakingtypes.Delegation, error) { - if delegator.String() == "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h" || delegator.String() == getOperatorBech32AddressForTestValidator().String() { - return []stakingtypes.Delegation{ - { - DelegatorAddress: "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - ValidatorAddress: "cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun", - Shares: sdkmath.LegacyNewDec(3), - }, - }, nil - } - return []stakingtypes.Delegation{ - {}, - }, fmt.Errorf("mock error: delegator %s not found", delegator) -} - -func (m MockStakingKeeper) GetDelegation(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation stakingtypes.Delegation, err error) { - if delAddr.String() != "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h" || valAddr.String() != "cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun" { - return stakingtypes.Delegation{}, fmt.Errorf("mock error: delegator %s not found for %s", delAddr, valAddr) - } - - return stakingtypes.Delegation{ - DelegatorAddress: "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - ValidatorAddress: "cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun", - Shares: sdkmath.LegacyNewDec(3), - }, nil -} - -func (m MockStakingKeeper) GetLastValidatorPower(ctx context.Context, operator sdk.ValAddress) (power int64, err error) { - validators, _ := m.GetBondedValidatorsByPower(ctx) - for i, v := range validators { - power := int64(len(validators) - i) - if v.GetOperator() == operator.String() { - return power, nil - } - } - return 0, fmt.Errorf("mock error: operator not found %s", operator) -} - -func (s *KeeperTestSuite) createTestValidators(amount int) { - addrDels := simapp.AddTestAddrsIncremental(s.app, s.ctx, amount, sdkmath.NewInt(10000)) - valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels) - - bondDenom, err := s.app.StakingKeeper.BondDenom(s.ctx) - s.Require().NoError(err, "app.StakingKeeper.BondDenom(ctx)") - - totalSupply := sdk.NewCoins(sdk.NewInt64Coin(bondDenom, 1_000_000_000)) - notBondedPool := s.app.StakingKeeper.GetNotBondedPool(s.ctx) - s.app.AccountKeeper.SetModuleAccount(s.ctx, notBondedPool) - - s.Require().NoError(testutil.FundModuleAccount(s.ctx, s.app.BankKeeper, notBondedPool.GetName(), totalSupply), - "funding %s with %s", notBondedPool.GetName(), totalSupply) - - var validators []stakingtypes.Validator - for i := 0; i < amount; i++ { - validator := teststaking.NewValidator(s.T(), valAddrs[i], PKs[i]) - tokens := s.app.StakingKeeper.TokensFromConsensusPower(s.ctx, int64(1+amount-i)) - validator, _ = validator.AddTokensFromDel(tokens) - validator = keeper.TestingUpdateValidator(s.app.StakingKeeper, s.ctx, validator, true) - validators = append(validators, validator) - - // Create the delegations - bond := stakingtypes.NewDelegation(addrDels[i].String(), valAddrs[i].String(), sdkmath.LegacyNewDec(int64((i+1)*10))) - err = s.app.StakingKeeper.SetDelegation(s.ctx, bond) - s.Require().NoError(err, "SetDelegation %s", bond) - - // We want even validators to be bonded - if i%2 == 0 { - _, err := s.app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(s.ctx) - s.Require().NoError(err, "ApplyAndReturnValidatorSetUpdates") - validator.ABCIValidatorUpdate(s.app.StakingKeeper.PowerReduction(s.ctx)) - } - } - - _, err = s.app.StakingKeeper.EndBlocker(s.ctx) - s.Require().NoError(err, "staking end blocker") - - testValidators = validators -} - -func getTestValidators(start, end int) []stakingtypes.Validator { - var validators []stakingtypes.Validator - for i := start; i <= end; i++ { - validators = append(validators, testValidators[i]) - } - return validators -} - -func (m MockStakingKeeper) GetBondedValidatorsByPower(ctx context.Context) ([]stakingtypes.Validator, error) { - validatorAddress, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - validator, _ := stakingtypes.NewValidator( - validatorAddress.String(), - PKs[100], - stakingtypes.Description{}, - ) - validators := getTestValidators(1, 3) - validators = append(validators, validator) - validators = append(validators, getTestValidators(4, 6)...) - - return validators, nil -} - -func (m MockStakingKeeper) GetValidator(ctx context.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, err error) { - validators := getTestValidators(0, 9) - addrStr := addr.String() - - for _, v := range validators { - if addrStr == v.GetOperator() { - return v, nil - } - } - - return stakingtypes.Validator{}, fmt.Errorf("mock error: validator not fount %s", addr) -} - -func (s *KeeperTestSuite) TestActionDelegateEvaluatePasses() { - action := types.NewActionDelegate() - action.MinimumActions = 1 - action.MaximumActions = 2 - - minDelegation := sdk.NewInt64Coin("nhash", 2) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minDelegation - action.MaximumDelegationAmount = &maxDelegation - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(4, 1) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - keeperProvider := MockKeeperProvider{} - state := types.NewRewardAccountState(0, 0, "", 0, []*types.ActionCounter{}) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - event := types.EvaluationResult{ - Validator: validator, - Delegator: delegator, - } - - passed := action.Evaluate(s.ctx, keeperProvider, state, event) - s.Assert().True(passed, "evaluate should pass when criteria are met") -} - -func (s *KeeperTestSuite) TestActionDelegateEvaluateFailsWhenMinimumActionsNotMet() { - action := types.NewActionDelegate() - action.MinimumActions = 1 - action.MaximumActions = 2 - minDelegation := sdk.NewInt64Coin("nhash", 2) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minDelegation - action.MaximumDelegationAmount = &maxDelegation - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(5, 1) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - keeperProvider := MockKeeperProvider{} - state := types.NewRewardAccountState(0, 0, "", 0, []*types.ActionCounter{}) - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - event := types.EvaluationResult{ - Validator: validator, - Delegator: delegator, - } - - passed := action.Evaluate(s.ctx, keeperProvider, state, event) - s.Assert().False(passed, "test should fail when minimum actions not met") -} - -func (s *KeeperTestSuite) TestActionDelegateEvaluateFailsWhenMaximumActionsNotMet() { - action := types.NewActionDelegate() - action.MinimumActions = 1 - action.MaximumActions = 2 - minDelegation := sdk.NewInt64Coin("nhash", 2) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minDelegation - action.MaximumDelegationAmount = &maxDelegation - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(5, 1) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - keeperProvider := MockKeeperProvider{} - state := types.NewRewardAccountState(0, 0, "", 0, []*types.ActionCounter{}) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - event := types.EvaluationResult{ - Validator: validator, - Delegator: delegator, - } - - passed := action.Evaluate(s.ctx, keeperProvider, state, event) - s.Assert().False(passed, "test should fail when maximum actions not met") -} - -func (s *KeeperTestSuite) TestActionDelegateEvaluateFailsWhenMaximumDelegationAmountNotMet() { - action := types.NewActionDelegate() - action.MinimumActions = 1 - action.MaximumActions = 2 - minDelegation := sdk.NewInt64Coin("nhash", 1) - maxDelegation := sdk.NewInt64Coin("nhash", 1) - action.MinimumDelegationAmount = &minDelegation - action.MaximumDelegationAmount = &maxDelegation - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(5, 1) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - keeperProvider := MockKeeperProvider{} - state := types.NewRewardAccountState(0, 0, "", 0, []*types.ActionCounter{}) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - event := types.EvaluationResult{ - Validator: validator, - Delegator: delegator, - } - - passed := action.Evaluate(s.ctx, keeperProvider, state, event) - s.Assert().False(passed, "test should fail when maximum delegation amount not met") -} - -func (s *KeeperTestSuite) TestActionDelegateEvaluateFailsWhenMinimumDelegationAmountNotMet() { - action := types.NewActionDelegate() - action.MinimumActions = 1 - action.MaximumActions = 2 - minDelegation := sdk.NewInt64Coin("nhash", 5) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minDelegation - action.MaximumDelegationAmount = &maxDelegation - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(5, 1) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - keeperProvider := MockKeeperProvider{} - state := types.NewRewardAccountState(0, 0, "", 0, []*types.ActionCounter{}) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - event := types.EvaluationResult{ - Validator: validator, - Delegator: delegator, - } - - passed := action.Evaluate(s.ctx, keeperProvider, state, event) - s.Assert().False(passed, "test should fail when minimum delegation amount not met") -} - -func (s *KeeperTestSuite) TestActionDelegateEvaluateFailsWhenMinimumActiveStakePercentileNotMet() { - action := types.NewActionDelegate() - action.MinimumActions = 1 - action.MaximumActions = 2 - minDelegation := sdk.NewInt64Coin("nhash", 1) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minDelegation - action.MaximumDelegationAmount = &maxDelegation - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(11, 1) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - keeperProvider := MockKeeperProvider{} - state := types.NewRewardAccountState(0, 0, "", 0, []*types.ActionCounter{}) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - event := types.EvaluationResult{ - Validator: validator, - Delegator: delegator, - } - - passed := action.Evaluate(s.ctx, keeperProvider, state, event) - s.Assert().False(passed, "test should fail when minimum delegation percentage not met") -} - -func (s *KeeperTestSuite) TestActionDelegateEvaluateFailsWhenMaximumDelegationPercentageNotMet() { - action := types.NewActionDelegate() - action.MinimumActions = 1 - action.MaximumActions = 2 - minDelegation := sdk.NewInt64Coin("nhash", 1) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - action.MinimumDelegationAmount = &minDelegation - action.MaximumDelegationAmount = &maxDelegation - action.MinimumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(5, 1) - action.MaximumActiveStakePercentile = sdkmath.LegacyNewDecWithPrec(1, 0) - - keeperProvider := MockKeeperProvider{} - state := types.NewRewardAccountState(0, 0, "", 0, []*types.ActionCounter{}) - state.ActionCounter = types.IncrementActionCount(state.ActionCounter, action.ActionType()) - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - event := types.EvaluationResult{ - Validator: validator, - Delegator: delegator, - } - - passed := action.Evaluate(s.ctx, keeperProvider, state, event) - s.Assert().False(passed, "test should fail when maximum delegation percentage not met") -} - -// Test GetRewardAction - -func (s *KeeperTestSuite) TestGetRewardActionHandlesUnsupportedActions() { - qa := types.QualifyingAction{} - _, err := qa.GetRewardAction(s.ctx) - s.Assert().Error(err, "should throw error when an action is not supported") -} - -func (s *KeeperTestSuite) TestGetRewardActionHandlesActionDelegate() { - delegate := types.QualifyingAction_Delegate{} - qa := types.QualifyingAction{ - Type: &delegate, - } - action, err := qa.GetRewardAction(s.ctx) - s.Assert().NoError(err, "should not throw error when action is supported") - s.Assert().Equal(types.ActionTypeDelegate, action.ActionType(), "should return the correct action type") -} - -// Test DetectQualifyingActions -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1QualifyingAction() { - SetupEventHistoryWithDelegates(s) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 0) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(1, len(qualifyingActions), "must find one qualifying actions") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith2QualifyingAction() { - SetupEventHistoryWithDelegates(s) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 0) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 4, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 4, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(4, len(qualifyingActions), "must find four qualifying actions") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWithNoQualifyingAction() { - SetupEventHistoryWithDelegates(s) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{}, - ) - rewardProgram.CurrentClaimPeriod = 1 - - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(0, len(qualifyingActions), "must find no qualifying actions") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWithNoMatchingQualifyingAction() { - SetupEventHistoryWithDelegates(s) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 0) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 1000, - MaximumActions: 1000, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(0, len(qualifyingActions), "must find no qualifying actions") -} - -// Test RewardShares -func (s *KeeperTestSuite) TestRewardSharesSingle() { - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{}, - ) - rewardProgram.CurrentClaimPeriod = 1 - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - results := []types.EvaluationResult{ - { - EventTypeToSearch: "delegate", - AttributeKey: "attribute", - Shares: 1, - Address: delegator, - Validator: validator, - Delegator: delegator, - }, - } - - state := types.NewRewardAccountState(rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), delegator.String(), 0, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - claimPeriodRewardDistribution := types.NewClaimPeriodRewardDistribution(rewardProgram.GetCurrentClaimPeriod(), - rewardProgram.GetId(), - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - 0, - false, - ) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, claimPeriodRewardDistribution) - - err := s.app.RewardKeeper.RewardShares(s.ctx, &rewardProgram, results) - - state, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), delegator.String()) - claimPeriodRewardDistribution, _ = s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, rewardProgram.GetCurrentClaimPeriod(), rewardProgram.GetId()) - s.Assert().NoError(err, "should return no error on success") - s.Assert().Equal(uint64(1), state.GetSharesEarned(), "share amount should increment") - s.Assert().Equal(int64(1), claimPeriodRewardDistribution.GetTotalShares(), "total share amount should increment") - s.Assert().Equal(rewardProgram.GetId(), state.GetRewardProgramId(), "reward program id should match") - s.Assert().Equal(rewardProgram.GetCurrentClaimPeriod(), state.GetClaimPeriodId(), "reward claim period id should match") - s.Assert().Equal(delegator.String(), state.GetAddress(), "address should match delegator") -} - -func (s *KeeperTestSuite) TestRewardSharesInvalidClaimPeriodRewardDistribution() { - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{}, - ) - rewardProgram.CurrentClaimPeriod = 1 - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - results := []types.EvaluationResult{ - { - EventTypeToSearch: "delegate", - AttributeKey: "attribute", - Shares: 1, - Address: delegator, - Validator: validator, - Delegator: delegator, - }, - } - - state := types.NewRewardAccountState(rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), delegator.String(), 0, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - claimPeriodRewardDistribution := types.NewClaimPeriodRewardDistribution(rewardProgram.GetCurrentClaimPeriod(), - rewardProgram.GetId(), - sdk.NewInt64Coin("nhash", 0), - sdk.NewInt64Coin("nhash", 0), - 0, - false, - ) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, claimPeriodRewardDistribution) - - err := s.app.RewardKeeper.RewardShares(s.ctx, &rewardProgram, results) - s.Assert().Error(err, "should return an error on invalid claim period reward distribution") -} - -func (s *KeeperTestSuite) TestRewardSharesMultiple() { - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{}, - ) - rewardProgram.CurrentClaimPeriod = 1 - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - results := []types.EvaluationResult{ - { - EventTypeToSearch: "delegate", - AttributeKey: "attribute", - Shares: 1, - Address: delegator, - Validator: validator, - Delegator: delegator, - }, - { - EventTypeToSearch: "delegate", - AttributeKey: "attribute", - Shares: 1, - Address: delegator, - Validator: validator, - Delegator: delegator, - }, - } - - state := types.NewRewardAccountState(rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), delegator.String(), 0, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state) - claimPeriodRewardDistribution := types.NewClaimPeriodRewardDistribution(rewardProgram.GetCurrentClaimPeriod(), - rewardProgram.GetId(), - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - 0, - false, - ) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, claimPeriodRewardDistribution) - - err := s.app.RewardKeeper.RewardShares(s.ctx, &rewardProgram, results) - - claimPeriodRewardDistribution, _ = s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, rewardProgram.GetCurrentClaimPeriod(), rewardProgram.GetId()) - state, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), delegator.String()) - s.Assert().NoError(err, "should return no error on success") - s.Assert().Equal(uint64(2), state.GetSharesEarned(), "share amount should increment") - s.Assert().Equal(int64(2), claimPeriodRewardDistribution.GetTotalShares(), "total share amount should increment") - s.Assert().Equal(rewardProgram.GetId(), state.GetRewardProgramId(), "reward program id should match") - s.Assert().Equal(rewardProgram.GetCurrentClaimPeriod(), state.GetClaimPeriodId(), "reward claim period id should match") - s.Assert().Equal(delegator.String(), state.GetAddress(), "address should match delegator") -} - -func (s *KeeperTestSuite) TestRewardSharesInvalidRewardProgram() { - rewardProgram := types.NewRewardProgram( - "title", - "description", - 0, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{}, - ) - rewardProgram.CurrentClaimPeriod = 1 - - validator, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - delegator, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - results := []types.EvaluationResult{ - { - EventTypeToSearch: "delegate", - AttributeKey: "attribute", - Shares: 1, - Address: delegator, - Validator: validator, - Delegator: delegator, - }, - } - claimPeriodRewardDistribution := types.NewClaimPeriodRewardDistribution(rewardProgram.GetCurrentClaimPeriod(), - rewardProgram.GetId(), - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - 0, - false, - ) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, claimPeriodRewardDistribution) - - err := s.app.RewardKeeper.RewardShares(s.ctx, nil, results) - state, _ := s.app.RewardKeeper.GetRewardAccountState(s.ctx, rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod(), delegator.String()) - - s.Assert().Error(err, "should return an error on invalid program") - s.Assert().Equal(uint64(0), state.GetSharesEarned(), "share amount should increment") -} - -// with transfer -func SetupEventHistoryWithTransfers(s *KeeperTestSuite) { - sender := "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h" - recipient := "cosmos1tnh2q55v8wyygtt9srz5safamzdengsnqeycj3" - attributes1 := []sdk.Attribute{ - sdk.NewAttribute("sender", sender), - sdk.NewAttribute("recipient", recipient), - sdk.NewAttribute("amount", "1000000000000000nhash"), - } - attributes2 := []sdk.Attribute{ - sdk.NewAttribute("module", "bank"), - sdk.NewAttribute("sender", sender), - sdk.NewAttribute("action", "/cosmos.bank.v1beta1.MsgSend"), - } - - event1 := sdk.NewEvent("transfer", attributes1...) - event2 := sdk.NewEvent("message", attributes2...) - loggedEvents := sdk.Events{ - event1, - event2, - } - SetupEventHistory(s, loggedEvents) -} - -// with vote -func SetupEventHistoryWithVotes(s *KeeperTestSuite, sender string) { - attributes1 := []sdk.Attribute{ - sdk.NewAttribute("action", "/cosmos.gov.v1beta1.MsgVote"), - } - attributes2 := []sdk.Attribute{ - sdk.NewAttribute("option", "{\"option\":1,\"weight\":\"1.000000000000000000\"}"), - sdk.NewAttribute("proposal_id", "1"), - } - attributes3 := []sdk.Attribute{ - sdk.NewAttribute("module", "governance"), - sdk.NewAttribute("sender", sender), - } - - event1 := sdk.NewEvent("message", attributes1...) - event2 := sdk.NewEvent("proposal_vote", attributes2...) - event3 := sdk.NewEvent("message", attributes3...) - loggedEvents := sdk.Events{ - event1, - event2, - event3, - } - newEvents := loggedEvents.ToABCIEvents() - eventManager, _ := s.ctx.EventManager().(sdk.EventManagerWithHistoryI) - - newEvents = append(newEvents, eventManager.GetABCIEventHistory()...) - eventManagerStub := sdk.NewEventManagerWithHistory(newEvents) - s.ctx = s.ctx.WithEventManager(eventManagerStub) -} - -// transfer -func (s *KeeperTestSuite) TestFindQualifyingActionsWithTransfers() { - SetupEventHistoryWithTransfers(s) - criteria := types.NewEventCriteria([]types.ABCIEvent{ - { - Type: banktypes.EventTypeTransfer, - Attributes: map[string][]byte{}, - }, - }) - - action := MockAction{Criteria: criteria, Builder: &types.TransferActionBuilder{}} - events, err := s.app.RewardKeeper.FindQualifyingActions(s.ctx, action) - s.Assert().NoError(err, "should throw no error when handling no events") - s.Assert().Equal(1, len(events), "should find the one transfer event") - for _, event := range events { - s.Assert().Equal(event.Shares, int64(1), "shares must be 1") - s.Assert().Equal(event.Address.String(), "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", "address must be correct") - } -} - -// vote -func (s *KeeperTestSuite) TestFindQualifyingActionsWithVotes() { - SetupEventHistoryWithVotes(s, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - criteria := types.NewEventCriteria([]types.ABCIEvent{ - { - Type: sdk.EventTypeMessage, - Attributes: map[string][]byte{sdk.AttributeKeyModule: []byte("governance")}, // TODO[1760]: reward: Ensure "governance" is still correct here. - }, - }) - - action := MockAction{Criteria: criteria, Builder: &types.VoteActionBuilder{}} - events, err := s.app.RewardKeeper.FindQualifyingActions(s.ctx, action) - s.Assert().NoError(err, "should throw no error when handling no events") - s.Assert().Equal(1, len(events), "should find the one transfer event") - for _, event := range events { - s.Assert().Equal(event.Shares, int64(1), "shares must be 1") - s.Assert().Equal(event.Address.String(), "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", "address must be correct") - } -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1VotingQualifyingAction() { - SetupEventHistoryWithVotes(s, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 3) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(1, len(qualifyingActions), "must find one qualifying actions") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1VotingQualifyingActionMultiplierPresent() { - s.SetupTest() - SetupEventHistoryWithVotes(s, getOperatorBech32AddressForTestValidator().String()) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 0) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - ValidatorMultiplier: 10, - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(1, len(qualifyingActions), "must find one qualifying actions") - s.Assert().Equal(int64(10), qualifyingActions[0].Shares, "shares should be 10") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1VotingQualifyingActionMultiplierPresentAndDelegationRequired() { - s.SetupTest() - SetupEventHistoryWithVotes(s, getOperatorBech32AddressForTestValidator().String()) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 3) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - ValidatorMultiplier: 10, - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(1, len(qualifyingActions), "must find one qualifying actions") - s.Assert().Equal(int64(10), qualifyingActions[0].Shares, "shares should be 10") -} - -func getOperatorBech32AddressForTestValidator() sdk.AccAddress { - validatorAddress, _ := sdk.ValAddressFromBech32(getTestValidators(0, 1)[0].OperatorAddress) - bz, err := sdk.GetFromBech32(validatorAddress.String(), sdk.GetConfig().GetBech32ValidatorAddrPrefix()) - if err != nil { - panic(err) - } - accountAddr := sdk.AccAddress(bz) - return accountAddr -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1VotingQualifyingActionDelegationNotMet() { - SetupEventHistoryWithVotes(s, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 4) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(0, len(qualifyingActions), "must find zero qualifying actions") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1VotingNoQualifyingAction() { - SetupEventHistoryWithDelegates(s) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 0) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(0, len(qualifyingActions), "must find one qualifying actions") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1VotingDelegateQualifyingAction() { - SetupEventHistoryWithDelegates(s) - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 0) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(1, len(qualifyingActions), "must find one qualifying actions") -} - -func (s *KeeperTestSuite) TestDetectQualifyingActionsWith1Voting1DelegateQualifyingAction() { - SetupEventHistoryWithDelegates(s) - SetupEventHistoryWithVotes(s, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - s.app.RewardKeeper.SetStakingKeeper(MockStakingKeeper{}) - minDelegation := sdk.NewInt64Coin("nhash", 0) - maxDelegation := sdk.NewInt64Coin("nhash", 10) - - rewardProgram := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("hotdog", 10000), - sdk.NewInt64Coin("hotdog", 10000), - time.Now(), - 5, - 5, - 0, - 0, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &types.QualifyingAction_Delegate{ - Delegate: &types.ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ) - rewardProgram.CurrentClaimPeriod = 1 - qualifyingActions, err := s.app.RewardKeeper.DetectQualifyingActions(s.ctx, &rewardProgram) - s.Assert().NoError(err, "must not error") - s.Assert().Equal(2, len(qualifyingActions), "must find one qualifying actions") -} - -func (s *KeeperTestSuite) TestGetAccountKeeper() { - s.Assert().NotNil(s.app.RewardKeeper.GetAccountKeeper()) -} diff --git a/x/reward/keeper/time_management.go b/x/reward/keeper/time_management.go deleted file mode 100644 index 7cdfb91095..0000000000 --- a/x/reward/keeper/time_management.go +++ /dev/null @@ -1,263 +0,0 @@ -package keeper - -import ( - "fmt" - "time" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// UpdateUnexpiredRewardsProgram called from begin blocker, starts/ends or expires rewards programs. -func (k Keeper) UpdateUnexpiredRewardsProgram(origCtx sdk.Context) { - rewardPrograms, err := k.GetAllUnexpiredRewardPrograms(origCtx) - if err != nil { - origCtx.Logger().Error(fmt.Sprintf("error iterating reward programs: %v ", err)) - // called from the beginblocker, not much we can do here but return - return - } - - for index := range rewardPrograms { - // Because this is designed for the BeginBlocker, we don't always have auto-rollback. - // We don't partial state recorded if an error is encountered in the middle. - // So use a cache context and only write it if there wasn't an error. - ctx, writeCtx := origCtx.CacheContext() - switch { - case rewardPrograms[index].IsStarting(ctx): - err = k.StartRewardProgram(ctx, &rewardPrograms[index]) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("cannot start program because of error %v ", err)) - continue - } - case rewardPrograms[index].IsEndingClaimPeriod(ctx): - err = k.EndRewardProgramClaimPeriod(ctx, &rewardPrograms[index]) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("cannot end reward program claim period because of error %v ", err)) - continue - } - case rewardPrograms[index].IsExpiring(ctx): - err = k.ExpireRewardProgram(ctx, &rewardPrograms[index]) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("cannot expire reward program because of error %v ", err)) - continue - } - } - k.SetRewardProgram(ctx, rewardPrograms[index]) - writeCtx() - } -} - -// StartRewardProgram transition reward program to STARTED -func (k Keeper) StartRewardProgram(ctx sdk.Context, rewardProgram *types.RewardProgram) error { - if rewardProgram == nil { - ctx.Logger().Error("Attempting to start nil reward program") - return fmt.Errorf("unable to start nil reward program") - } - - if rewardProgram.GetTotalRewardPool().IsZero() { - ctx.Logger().Error("Attempting to start reward program with no balance") - return fmt.Errorf("unable to start reward program with no balance") - } - - ctx.Logger().Info(fmt.Sprintf("Starting reward program: %v ", rewardProgram)) - rewardProgram.State = types.RewardProgram_STATE_STARTED - err := k.StartRewardProgramClaimPeriod(ctx, rewardProgram) - if err != nil { - return err - } - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeRewardProgramStarted, - sdk.NewAttribute(types.AttributeKeyRewardProgramID, fmt.Sprintf("%d", rewardProgram.GetId())), - ), - ) - - return nil -} - -// StartRewardProgramClaimPeriod Start ClaimPeriod on a given reward program. -func (k Keeper) StartRewardProgramClaimPeriod(ctx sdk.Context, rewardProgram *types.RewardProgram) error { - if rewardProgram == nil { - ctx.Logger().Error("Attempting to start reward program claim for nil reward program") - return fmt.Errorf("unable to start reward program claim for nil reward program") - } - - if rewardProgram.GetClaimPeriods() == 0 { - ctx.Logger().Error("Attempting to start reward program claim with non positive claim periods") - return fmt.Errorf("claim periods must be positive") - } - - blockTime := ctx.BlockTime() - rewardProgram.ClaimPeriodEndTime = blockTime.Add(time.Duration(rewardProgram.ClaimPeriodSeconds) * time.Second) - rewardProgram.CurrentClaimPeriod++ - if rewardProgram.CurrentClaimPeriod > rewardProgram.ClaimPeriods { - rewardProgram.ExpectedProgramEndTime = rewardProgram.ExpectedProgramEndTime.Add(time.Duration(rewardProgram.ClaimPeriodSeconds) * time.Second) - } - - // Get the Claim Period Reward. It should not exceed program balance - claimPeriodAmount := rewardProgram.GetTotalRewardPool().Amount.Quo(sdkmath.NewInt(int64(rewardProgram.GetClaimPeriods()))) - claimPeriodPool := sdk.NewCoin(rewardProgram.GetTotalRewardPool().Denom, claimPeriodAmount) - if rewardProgram.RemainingPoolBalance.IsLT(claimPeriodPool) { - claimPeriodPool = rewardProgram.RemainingPoolBalance - } - - claimPeriodReward := types.NewClaimPeriodRewardDistribution( - rewardProgram.GetCurrentClaimPeriod(), - rewardProgram.GetId(), - claimPeriodPool, - sdk.NewInt64Coin(claimPeriodPool.Denom, 0), - 0, - false, - ) - k.SetClaimPeriodRewardDistribution(ctx, claimPeriodReward) - return nil -} - -// EndRewardProgramClaimPeriod end the claim period of a given reward program. -func (k Keeper) EndRewardProgramClaimPeriod(ctx sdk.Context, rewardProgram *types.RewardProgram) error { - ctx.Logger().Info(fmt.Sprintf("BeginBlocker - Claim period end hit for reward program %v ", rewardProgram)) - - if rewardProgram == nil { - ctx.Logger().Error("EndRewardProgramClaimPeriod RewardProgram is nil") - return fmt.Errorf("unable to end reward program claim period for nil reward program") - } - - claimPeriodReward, err := k.GetClaimPeriodRewardDistribution(ctx, rewardProgram.GetCurrentClaimPeriod(), rewardProgram.GetId()) - if err != nil || claimPeriodReward.GetClaimPeriodId() == 0 { - ctx.Logger().Error(fmt.Sprintf("Missing ClaimPeriodRewardDistribution for RewardProgram %d ", rewardProgram.GetId())) - return fmt.Errorf("a ClaimPeriodRewardDistribution does not exist for RewardProgram %d with claim period %d", rewardProgram.GetId(), rewardProgram.GetId()) - } - - totalClaimPeriodRewards, err := k.CalculateRewardClaimPeriodRewards(ctx, rewardProgram.GetMaxRewardByAddress(), claimPeriodReward) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("Unable to calculate claim period rewards for RewardProgram %d ", rewardProgram.GetId()), "err", err) - return err - } - - err = k.MakeRewardClaimsClaimableForPeriod(ctx, rewardProgram.GetId(), rewardProgram.GetCurrentClaimPeriod()) - if err != nil { - return err - } - // Update balances - claimPeriodReward.TotalRewardsPoolForClaimPeriod = claimPeriodReward.TotalRewardsPoolForClaimPeriod.Add(totalClaimPeriodRewards) - claimPeriodReward.ClaimPeriodEnded = true - rewardProgram.RemainingPoolBalance = rewardProgram.RemainingPoolBalance.Sub(totalClaimPeriodRewards) - k.SetClaimPeriodRewardDistribution(ctx, claimPeriodReward) - k.SetRewardProgram(ctx, *rewardProgram) - - if rewardProgram.IsEnding(ctx, rewardProgram.RemainingPoolBalance) { - err = k.EndRewardProgram(ctx, rewardProgram) - if err != nil { - return err - } - } else { - err = k.StartRewardProgramClaimPeriod(ctx, rewardProgram) - if err != nil { - return err - } - } - - return nil -} - -// EndRewardProgram ActualProgramEndTime is updated and program ENDED -func (k Keeper) EndRewardProgram(ctx sdk.Context, rewardProgram *types.RewardProgram) error { - if rewardProgram == nil { - ctx.Logger().Error("Attempting to end reward program for nil reward program") - return fmt.Errorf("unable to end reward program for nil reward program") - } - - ctx.Logger().Info(fmt.Sprintf("BeginBlocker - Ending reward program %v ", rewardProgram)) - blockTime := ctx.BlockTime() - rewardProgram.State = types.RewardProgram_STATE_FINISHED - rewardProgram.ActualProgramEndTime = blockTime - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeRewardProgramFinished, - sdk.NewAttribute(types.AttributeKeyRewardProgramID, fmt.Sprintf("%d", rewardProgram.GetId())), - ), - ) - - return nil -} - -// ExpireRewardProgram return unclaimed rewards to reward creator, and expire the reward program. -func (k Keeper) ExpireRewardProgram(ctx sdk.Context, rewardProgram *types.RewardProgram) error { - if rewardProgram == nil { - ctx.Logger().Error("Attempting to expire reward program for nil reward program") - return fmt.Errorf("unable to expire reward program for nil reward program") - } - ctx.Logger().Info(fmt.Sprintf("BeginBlocker - Expiring reward program %v ", rewardProgram)) - - rewardProgram.State = types.RewardProgram_STATE_EXPIRED - err := k.ExpireRewardClaimsForRewardProgram(ctx, rewardProgram.GetId()) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("Failed to expire reward claims for reward program. %v", err)) - } - err = k.RefundRewardClaims(ctx, *rewardProgram) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("Failed to refund reward claims. %v", err)) - } - err = k.RefundRemainingBalance(ctx, rewardProgram) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("Failed to refund remaining balance. %v", err)) - } - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeRewardProgramExpired, - sdk.NewAttribute(types.AttributeKeyRewardProgramID, fmt.Sprintf("%d", rewardProgram.GetId())), - ), - ) - - return err -} - -// CalculateRewardClaimPeriodRewards calculate reward accrued for a claim period for each participant. -func (k Keeper) CalculateRewardClaimPeriodRewards(ctx sdk.Context, maxReward sdk.Coin, claimPeriodReward types.ClaimPeriodRewardDistribution) (sum sdk.Coin, err error) { - sum = sdk.NewInt64Coin(claimPeriodReward.GetRewardsPool().Denom, 0) - - if maxReward.Denom != claimPeriodReward.RewardsPool.GetDenom() { - ctx.Logger().Error(fmt.Sprintf("CalculateRewardClaimPeriodRewards denoms don't match %s %s", maxReward.Denom, claimPeriodReward.RewardsPool.GetDenom())) - return sum, fmt.Errorf("ProgramBalance, MaxReward, and ClaimPeriodReward denoms must match") - } - - participants, err := k.GetRewardAccountStatesForClaimPeriod(ctx, claimPeriodReward.GetRewardProgramId(), claimPeriodReward.GetClaimPeriodId()) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("Unable to get shares for reward program %d's claim period %d ", claimPeriodReward.GetRewardProgramId(), claimPeriodReward.GetClaimPeriodId())) - return sum, fmt.Errorf("unable to get reward claim period shares for reward program %d and claim period %d", claimPeriodReward.GetRewardProgramId(), claimPeriodReward.GetClaimPeriodId()) - } - - for _, participant := range participants { - reward := k.CalculateParticipantReward(ctx, int64(participant.GetSharesEarned()), claimPeriodReward.GetTotalShares(), claimPeriodReward.GetRewardsPool(), maxReward) - - sum = sum.Add(reward) - } - - return sum, nil -} - -// CalculateParticipantReward for each address/participant -func (k Keeper) CalculateParticipantReward(_ sdk.Context, shares int64, totalShares int64, claimRewardPool sdk.Coin, maxReward sdk.Coin) sdk.Coin { - numerator := sdkmath.LegacyNewDec(shares) - denom := sdkmath.LegacyNewDec(totalShares) - - percentage := sdkmath.LegacyNewDec(0) - if totalShares > 0 { - percentage = numerator.Quo(denom) - } - - pool := sdkmath.LegacyNewDec(claimRewardPool.Amount.Int64()) - reward := sdk.NewInt64Coin(claimRewardPool.Denom, pool.Mul(percentage).TruncateInt64()) - - if maxReward.IsLT(reward) { - reward = maxReward - } - - return reward -} diff --git a/x/reward/keeper/time_management_test.go b/x/reward/keeper/time_management_test.go deleted file mode 100644 index 5d7b6ebdc9..0000000000 --- a/x/reward/keeper/time_management_test.go +++ /dev/null @@ -1,1011 +0,0 @@ -package keeper_test - -import ( - "fmt" - "time" - - abci "github.com/cometbft/cometbft/abci/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/provenance-io/provenance/x/reward/types" -) - -func (s *KeeperTestSuite) TestStartRewardProgram() { - currentTime := time.Now() - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - - s.Assert().Equal(program.State, types.RewardProgram_STATE_STARTED, "reward program should be in started state") - s.Assert().Equal(uint64(1), program.CurrentClaimPeriod, "current claim period should be set to 1") - s.Assert().Equal(blockTime.Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ClaimPeriodEndTime, "claim period end time should be set") - - claimPeriodAmount := program.GetTotalRewardPool().Amount.QuoRaw(int64(program.GetClaimPeriods())) - claimPeriodPool := sdk.NewCoin(program.GetTotalRewardPool().Denom, claimPeriodAmount) - reward, err := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - s.Assert().NoError(err) - s.Assert().Equal(uint64(1), reward.GetRewardProgramId()) - s.Assert().Equal(uint64(1), reward.GetClaimPeriodId()) - s.Assert().Equal(claimPeriodPool, reward.GetRewardsPool()) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward.GetTotalRewardsPoolForClaimPeriod()) - - events := s.ctx.EventManager().ABCIEvents() - newEvent := events[len(events)-1] - s.Assert().Equal("reward_program_started", newEvent.GetType(), "should emit the correct event type") - s.Assert().Equal([]byte("reward_program_id"), newEvent.GetAttributes()[0].GetKey(), "should emit the correct attribute name") - s.Assert().Equal([]byte("1"), newEvent.GetAttributes()[0].GetValue(), "should emit the correct attribute value") -} - -func (s *KeeperTestSuite) TestStartRewardProgramNoBalance() { - currentTime := time.Now() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 0), - sdk.NewInt64Coin("nhash", 0), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - err := s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - s.Assert().Error(err, "an error should be thrown when there is no balance") - s.Assert().Equal(program.State, types.RewardProgram_STATE_PENDING, "reward program should be in pending state") - s.Assert().Equal(uint64(0), program.CurrentClaimPeriod, "current claim period should be set to 0") -} - -func (s *KeeperTestSuite) TestStartNilRewardProgram() { - err := s.app.RewardKeeper.StartRewardProgram(s.ctx, nil) - s.Assert().Error(err, "must throw error for nil case") -} - -func (s *KeeperTestSuite) TestStartRewardProgramClaimPeriodWithNil() { - err := s.app.RewardKeeper.StartRewardProgramClaimPeriod(s.ctx, nil) - s.Assert().Error(err, "should throw error") -} - -func (s *KeeperTestSuite) TestStartRewardProgramClaimPeriodWithNoPeriods() { - currentTime := time.Now() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - currentTime, - 60*60, - 0, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - - err := s.app.RewardKeeper.StartRewardProgramClaimPeriod(s.ctx, &program) - s.Assert().Error(err, "should throw error") -} - -func (s *KeeperTestSuite) TestStartRewardProgramClaimPeriod() { - currentTime := time.Now() - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.ExpectedProgramEndTime = s.ctx.BlockTime() - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - s.app.RewardKeeper.StartRewardProgramClaimPeriod(s.ctx, &program) - s.Assert().Equal(uint64(1), program.CurrentClaimPeriod, "current claim period should incremented") - s.Assert().Equal(blockTime.Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ClaimPeriodEndTime, "claim period end time should be set") - - claimPeriodAmount := program.GetTotalRewardPool().Amount.QuoRaw(int64(program.GetClaimPeriods())) - claimPeriodPool := sdk.NewCoin(program.GetTotalRewardPool().Denom, claimPeriodAmount) - reward, err := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - s.Assert().NoError(err) - s.Assert().Equal(uint64(1), reward.GetRewardProgramId()) - s.Assert().Equal(uint64(1), reward.GetClaimPeriodId()) - s.Assert().Equal(claimPeriodPool, reward.GetRewardsPool()) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward.GetTotalRewardsPoolForClaimPeriod()) - s.Assert().Equal(s.ctx.BlockTime(), program.ExpectedProgramEndTime, "expected program end time should not be updated.") -} - -func (s *KeeperTestSuite) TestStartRewardProgramClaimPeriodUpdatesExpectedEndTime() { - currentTime := time.Now() - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.CurrentClaimPeriod = program.GetClaimPeriods() - program.ExpectedProgramEndTime = s.ctx.BlockTime() - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - s.app.RewardKeeper.StartRewardProgramClaimPeriod(s.ctx, &program) - s.Assert().Equal(uint64(4), program.CurrentClaimPeriod, "current claim period should incremented") - s.Assert().Equal(blockTime.Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ClaimPeriodEndTime, "claim period end time should be set") - - claimPeriodAmount := program.GetTotalRewardPool().Amount.QuoRaw(int64(program.GetClaimPeriods())) - claimPeriodPool := sdk.NewCoin(program.GetTotalRewardPool().Denom, claimPeriodAmount) - reward, err := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 4, 1) - s.Assert().NoError(err) - s.Assert().Equal(uint64(1), reward.GetRewardProgramId()) - s.Assert().Equal(uint64(4), reward.GetClaimPeriodId()) - s.Assert().Equal(claimPeriodPool, reward.GetRewardsPool()) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward.GetTotalRewardsPoolForClaimPeriod()) - s.Assert().Equal(s.ctx.BlockTime().Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ExpectedProgramEndTime, "expected program end time should be updated for rollover.") -} - -func (s *KeeperTestSuite) TestStartRewardProgramClaimPeriodDoesNotExceedBalance() { - currentTime := time.Now() - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - currentTime, - 60*60, - 4, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = sdk.NewInt64Coin("nhash", 20) - - s.app.RewardKeeper.StartRewardProgramClaimPeriod(s.ctx, &program) - s.Assert().Equal(uint64(1), program.CurrentClaimPeriod, "current claim period should incremented") - s.Assert().Equal(blockTime.Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ClaimPeriodEndTime, "claim period end time should be set") - - reward, err := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - s.Assert().NoError(err) - s.Assert().Equal(uint64(1), reward.GetRewardProgramId()) - s.Assert().Equal(uint64(1), reward.GetClaimPeriodId()) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 20), reward.GetRewardsPool()) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward.GetTotalRewardsPoolForClaimPeriod()) -} - -func (s *KeeperTestSuite) TestEndRewardProgram() { - currentTime := time.Now() - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - - s.app.RewardKeeper.EndRewardProgram(s.ctx, &program) - - events := s.ctx.EventManager().ABCIEvents() - newEvent := events[len(events)-1] - s.Assert().Equal("reward_program_finished", newEvent.GetType(), "should emit the correct event type") - s.Assert().Equal([]byte("reward_program_id"), newEvent.GetAttributes()[0].GetKey(), "should emit the correct attribute name") - s.Assert().Equal([]byte("1"), newEvent.GetAttributes()[0].GetValue(), "should emit the correct attribute value") - s.Assert().Equal(program.State, types.RewardProgram_STATE_FINISHED, "reward program should be in finished state") - s.Assert().Equal(blockTime, program.ActualProgramEndTime, "actual program end time should be set") -} - -func (s *KeeperTestSuite) TestEndRewardProgramNil() { - err := s.app.RewardKeeper.EndRewardProgram(s.ctx, nil) - s.Assert().Error(err, "should throw an error for nil") -} - -func (s *KeeperTestSuite) TestExpireRewardProgram() { - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - time.Now(), - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - - s.app.RewardKeeper.ExpireRewardProgram(s.ctx, &program) - s.Assert().Equal(program.State, types.RewardProgram_STATE_EXPIRED, "reward program should be in expired state") - events := s.ctx.EventManager().ABCIEvents() - newEvent := events[len(events)-1] - s.Assert().Equal("reward_program_expired", newEvent.GetType(), "should emit the correct event type") - s.Assert().Equal([]byte("reward_program_id"), newEvent.GetAttributes()[0].GetKey(), "should emit the correct attribute name") - s.Assert().Equal([]byte("1"), newEvent.GetAttributes()[0].GetValue(), "should emit the correct attribute value") -} - -func (s *KeeperTestSuite) TestExpireRewardProgramNil() { - err := s.app.RewardKeeper.ExpireRewardProgram(s.ctx, nil) - s.Assert().Error(err, "should throw an error for nil") -} - -func (s *KeeperTestSuite) TestExpireRewardProgramRefunds() { - program := types.NewRewardProgram( - "title", - "description", - 1, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - time.Now(), - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = sdk.NewInt64Coin("nhash", 80000) - program.ClaimedAmount = sdk.NewInt64Coin("nhash", 10000) - - addr, _ := sdk.AccAddressFromBech32("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - beforeBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - - s.app.RewardKeeper.ExpireRewardProgram(s.ctx, &program) - - afterBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - - s.Assert().Equal(beforeBalance.Add(sdk.NewInt64Coin("nhash", 90000)), afterBalance, "account should get remaining balance and claims") - s.Assert().Equal(program.State, types.RewardProgram_STATE_EXPIRED, "reward program should be in expired state") -} - -func (s *KeeperTestSuite) TestCalculateRewardClaimPeriodRewardsNonMatchingDenoms() { - notMatching := types.NewClaimPeriodRewardDistribution( - 1, - 1, - sdk.NewInt64Coin("hotdog", 0), - sdk.NewInt64Coin("hotdog", 0), - 1, - false, - ) - - _, err := s.app.RewardKeeper.CalculateRewardClaimPeriodRewards(s.ctx, sdk.NewInt64Coin("nhash", 0), notMatching) - s.Assert().Error(err, "error should be thrown when claim period reward distribution doesn't match the others") -} - -func (s *KeeperTestSuite) TestCalculateRewardClaimPeriodRewardsNoSharesForPeriod() { - matching := types.NewClaimPeriodRewardDistribution( - 1, - 1, - sdk.NewInt64Coin("nhash", 0), - sdk.NewInt64Coin("nhash", 0), - 0, - false, - ) - - reward, err := s.app.RewardKeeper.CalculateRewardClaimPeriodRewards(s.ctx, sdk.NewInt64Coin("nhash", 0), matching) - s.Assert().NoError(err, "No error should be thrown when there are no claimed shares") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward, "should be 0 of the input denom") -} - -func (s *KeeperTestSuite) TestCalculateRewardClaimPeriodRewardsEvenDistributionNoRemainder() { - distribution := types.NewClaimPeriodRewardDistribution( - 1, - 1, - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 0), - 2, - false, - ) - - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - - reward, err := s.app.RewardKeeper.CalculateRewardClaimPeriodRewards(s.ctx, sdk.NewInt64Coin("nhash", 100), distribution) - s.Assert().NoError(err, "should return no error") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 100), reward, "should distribute all the funds") -} - -func (s *KeeperTestSuite) TestCalculateRewardClaimPeriodRewardsEvenDistributionWithRemainder() { - distribution := types.NewClaimPeriodRewardDistribution( - 1, - 1, - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 0), - 3, - false, - ) - - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 1, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(1, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - - reward, err := s.app.RewardKeeper.CalculateRewardClaimPeriodRewards(s.ctx, sdk.NewInt64Coin("nhash", 100), distribution) - s.Assert().NoError(err, "should return no error") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 99), reward, "should distribute all the funds except for the remainder") -} - -func (s *KeeperTestSuite) TestCalculateRewardClaimPeriodRewardsUnevenDistribution() { - distribution := types.NewClaimPeriodRewardDistribution( - 1, - 1, - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 0), - 4, - false, - ) - - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 2, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 1, []*types.ActionCounter{}) - state3 := types.NewRewardAccountState(1, 1, "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state3) - - reward, err := s.app.RewardKeeper.CalculateRewardClaimPeriodRewards(s.ctx, sdk.NewInt64Coin("nhash", 100), distribution) - s.Assert().NoError(err, "should return no error") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 100), reward, "should distribute all the funds") -} - -func (s *KeeperTestSuite) TestCalculateRewardClaimPeriodRewardsUsesMaxReward() { - distribution := types.NewClaimPeriodRewardDistribution( - 1, - 1, - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 0), - 2, - false, - ) - - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - - reward, err := s.app.RewardKeeper.CalculateRewardClaimPeriodRewards(s.ctx, sdk.NewInt64Coin("nhash", 20), distribution) - s.Assert().NoError(err, "should return no error") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 40), reward, "should distribute only up to the maximum reward for each participant") -} - -func (s *KeeperTestSuite) TestCalculateParticipantReward() { - reward := s.app.RewardKeeper.CalculateParticipantReward(s.ctx, 1, 2, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100)) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 50), reward, "should get correct cut of pool") -} - -func (s *KeeperTestSuite) TestCalculateParticipantRewardLimitsToMaximum() { - reward := s.app.RewardKeeper.CalculateParticipantReward(s.ctx, 1, 2, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 10)) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 10), reward, "should get correct cut of pool") -} - -func (s *KeeperTestSuite) TestCalculateParticipantRewardCanHandleZeroTotalShares() { - reward := s.app.RewardKeeper.CalculateParticipantReward(s.ctx, 1, 0, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100)) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward, "should have no reward") -} - -func (s *KeeperTestSuite) TestCalculateParticipantRewardCanHandleZeroEarnedShares() { - reward := s.app.RewardKeeper.CalculateParticipantReward(s.ctx, 0, 10, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100)) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward, "should have no reward") -} - -func (s *KeeperTestSuite) TestCalculateParticipantRewardCanHandleZeroRewardPool() { - reward := s.app.RewardKeeper.CalculateParticipantReward(s.ctx, 1, 1, sdk.NewInt64Coin("nhash", 0), sdk.NewInt64Coin("nhash", 100)) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 0), reward, "should have no reward") -} - -func (s *KeeperTestSuite) TestCalculateParticipantRewardTruncates() { - reward := s.app.RewardKeeper.CalculateParticipantReward(s.ctx, 1, 3, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100)) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 33), reward, "reward should truncate when < .5") - - reward = s.app.RewardKeeper.CalculateParticipantReward(s.ctx, 2, 3, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100)) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 66), reward, "reward should truncate when >= .5") -} - -func (s *KeeperTestSuite) TestEndRewardProgramClaimPeriodHandlesInvalidLookups() { - currentTime := time.Now() - s.ctx = s.ctx.WithBlockTime(currentTime) - - program1 := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 0), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program2 := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 0), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program3 := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 0), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program1.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program2.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program3.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program2.RemainingPoolBalance = program2.GetTotalRewardPool() - program3.RemainingPoolBalance = sdk.NewInt64Coin("jackthecat", 100) - rewardDistribution := types.NewClaimPeriodRewardDistribution(0, 3, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 1, false) - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, rewardDistribution) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program1) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program2) - s.app.RewardKeeper.SetRewardProgram(s.ctx, program3) - - err := s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program1) - s.Assert().Error(err, "an error should be thrown if there is no program balance for the program") - err = s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program2) - s.Assert().Error(err, "an error should be thrown if there is no claim period reward distribution for the program") - err = s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program3) - s.Assert().Error(err, "an error should be thrown if reward claim calculation fails") -} - -func (s *KeeperTestSuite) TestEndRewardProgramClaimPeriodHandlesNilRewardProgram() { - err := s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, nil) - s.Assert().Error(err, "error should be returned for nil reward program") -} - -func (s *KeeperTestSuite) TestRewardProgramClaimPeriodEnd() { - currentTime := time.Now() - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 100000), - currentTime, - 60*60, - 2, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - - // Update the distribution to replicate that a share was actually granted. - rewardDistribution, _ := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - rewardDistribution.TotalShares = 1 - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, rewardDistribution) - - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - - reward, _ := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - - s.Assert().Equal(sdk.NewInt64Coin("nhash", 50000), program.RemainingPoolBalance, "balance should subtract the claim period reward") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 50000), reward.TotalRewardsPoolForClaimPeriod, "total claim should be increased by the amount rewarded") - s.Assert().Equal(program.State, types.RewardProgram_STATE_STARTED, "reward program should be in started state") - s.Assert().Equal(uint64(2), program.CurrentClaimPeriod, "current claim period should be updated") - s.Assert().Equal(blockTime.Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ClaimPeriodEndTime, "claim period end time should be set") -} - -func (s *KeeperTestSuite) TestRewardProgramClaimPeriodEndTransition() { - currentTime := time.Now() - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 100000), - currentTime, - 60*60, - 2, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - state2 := types.NewRewardAccountState(1, 2, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - reward, _ := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - reward.TotalShares = 1 - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, reward) - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - reward, _ = s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 2, 1) - reward.TotalShares = 1 - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, reward) - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - - s.Assert().Equal(program.State, types.RewardProgram_STATE_FINISHED, "reward program should be in finished state") - s.Assert().Equal(uint64(2), program.CurrentClaimPeriod, "current claim period should not be updated") - s.Assert().Equal(blockTime.Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ClaimPeriodEndTime, "claim period end time should be set") - s.Assert().Equal(blockTime, program.ActualProgramEndTime, "claim period end time should be set") -} - -func (s *KeeperTestSuite) TestRewardProgramClaimPeriodEndTransitionExpired() { - currentTime := time.Now() - s.ctx = s.ctx.WithBlockTime(currentTime) - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - // Normally you would need an additional claim period. However, it should end because the expected time is set. - program.ProgramEndTimeMax = currentTime - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - - s.Assert().Equal(types.RewardProgram_STATE_FINISHED, program.State, "reward program should be in finished state") - s.Assert().Equal(uint64(2), program.CurrentClaimPeriod, "current claim period should not be updated") - s.Assert().Equal(blockTime.Add(time.Duration(program.ClaimPeriodSeconds)*time.Second), program.ClaimPeriodEndTime, "claim period end time should be set") - s.Assert().Equal(blockTime, program.ActualProgramEndTime, "claim period end time should be set") -} - -func (s *KeeperTestSuite) TestRewardProgramClaimPeriodEndNoBalance() { - currentTime := time.Now() - s.ctx = s.ctx.WithBlockTime(currentTime) - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = sdk.NewInt64Coin("nhash", 0) - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - - s.Assert().Equal(types.RewardProgram_STATE_FINISHED, program.State, "reward program should be in finished state") - s.Assert().Equal(uint64(1), program.CurrentClaimPeriod, "current claim period should not be updated") - s.Assert().Equal(program.ClaimPeriodEndTime, program.ClaimPeriodEndTime, "claim period end time should not be updated") - s.Assert().Equal(blockTime, program.ActualProgramEndTime, "actual end time should be set") -} - -func (s *KeeperTestSuite) TestEndRewardProgramClaimPeriodUpdatesClaimStatus() { - currentTime := time.Now() - s.ctx = s.ctx.WithBlockTime(currentTime) - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 400), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - state1 := types.NewRewardAccountState(1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - state2 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state2) - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - reward, _ := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - reward.TotalShares = 1 - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, reward) - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - - state1, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 1, "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27") - state2, _ = s.app.RewardKeeper.GetRewardAccountState(s.ctx, 1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - - // Adjusted after ending period - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_CLAIMABLE, state1.GetClaimStatus(), "first claim status should be updated to claimable") - s.Assert().Equal(types.RewardAccountState_CLAIM_STATUS_CLAIMABLE, state2.GetClaimStatus(), "second claim status should be updated to claimable") -} - -func (s *KeeperTestSuite) TestEndRewardProgramClaimPeriodUpdatesBalances() { - currentTime := time.Now() - s.ctx = s.ctx.WithBlockTime(currentTime) - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 400), - sdk.NewInt64Coin("nhash", 1000), - currentTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - reward, _ := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - reward.TotalShares = 1 - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, reward) - claimAmount, _ := s.app.RewardKeeper.CalculateRewardClaimPeriodRewards(s.ctx, program.GetMaxRewardByAddress(), reward) - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - - // Adjusted after ending period - reward, _ = s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - expectedProgramBalance := program.GetTotalRewardPool().Sub(claimAmount) - s.Assert().Equal(claimAmount, reward.GetTotalRewardsPoolForClaimPeriod(), "the reward for the claim period should be added to total reward") - s.Assert().Equal(expectedProgramBalance, program.GetRemainingPoolBalance(), "the reward for the claim period should be subtracted out of the program balance") - s.Assert().Equal(types.RewardProgram_STATE_STARTED, program.State, "reward program should be in started state") - s.Assert().Equal(uint64(2), program.CurrentClaimPeriod, "next iteration should start") - s.Assert().Equal(true, reward.ClaimPeriodEnded, "claim period should be marked as ended") -} - -func (s *KeeperTestSuite) TestEndRewardProgramClaimPeriodHandlesMinimumRolloverAmount() { - currentTime := time.Now() - s.ctx = s.ctx.WithBlockTime(currentTime) - blockTime := s.ctx.BlockTime() - program := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 1000), - sdk.NewInt64Coin("nhash", 500), - currentTime, - 60*60, - 2, - 0, - 0, - []types.QualifyingAction{}, - ) - program.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 501) - program.RemainingPoolBalance = program.GetTotalRewardPool() - - s.app.RewardKeeper.StartRewardProgram(s.ctx, &program) - - // Create the shares - state1 := types.NewRewardAccountState(1, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - reward, _ := s.app.RewardKeeper.GetClaimPeriodRewardDistribution(s.ctx, 1, 1) - reward.TotalShares = 1 - s.app.RewardKeeper.SetClaimPeriodRewardDistribution(s.ctx, reward) - - // Should end because the balance should be below 501 - s.app.RewardKeeper.EndRewardProgramClaimPeriod(s.ctx, &program) - - s.Assert().Equal(types.RewardProgram_STATE_FINISHED, program.State, "reward program should be in finished state") - s.Assert().Equal(uint64(1), program.CurrentClaimPeriod, "current claim period should not be updated") - s.Assert().Equal(program.ClaimPeriodEndTime, program.ClaimPeriodEndTime, "claim period end time should not be updated") - s.Assert().Equal(blockTime, program.ActualProgramEndTime, "actual end time should be set") - s.Assert().Equal(sdk.NewInt64Coin("nhash", 500), program.GetRemainingPoolBalance(), "balance should be updated") -} - -func (s *KeeperTestSuite) TestUpdate() { - // Reward Program that has not started - currentTime := time.Now() - s.ctx = s.ctx.WithBlockTime(currentTime) - blockTime := s.ctx.BlockTime() - - notStarted := types.NewRewardProgram( - "title", - "description", - 1, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - blockTime.Add(time.Duration(time.Hour)), - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - notStarted.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - notStarted.RemainingPoolBalance = notStarted.GetTotalRewardPool() - - // Reward Program that is starting - starting := types.NewRewardProgram( - "title", - "description", - 2, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - blockTime, - 60*60, - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - starting.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - starting.RemainingPoolBalance = starting.GetTotalRewardPool() - - // Reward Program that is ready to move onto next claim period - nextClaimPeriod := types.NewRewardProgram( - "title", - "description", - 3, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 1000), - blockTime, - uint64(time.Hour), - 3, - 0, - 0, - []types.QualifyingAction{}, - ) - nextClaimPeriod.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - nextClaimPeriod.RemainingPoolBalance = nextClaimPeriod.GetTotalRewardPool() - s.app.RewardKeeper.StartRewardProgram(s.ctx, &nextClaimPeriod) - nextClaimPeriod.ClaimPeriodEndTime = blockTime - - // Reward program that runs out of funds - ending := types.NewRewardProgram( - "title", - "description", - 4, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 100000), - blockTime, - uint64(time.Hour), - 1, - 0, - 0, - []types.QualifyingAction{}, - ) - ending.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - ending.RemainingPoolBalance = sdk.NewInt64Coin("nhash", 0) - state1 := types.NewRewardAccountState(4, 1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", 1, []*types.ActionCounter{}) - s.app.RewardKeeper.SetRewardAccountState(s.ctx, state1) - s.app.RewardKeeper.StartRewardProgram(s.ctx, &ending) - ending.ClaimPeriodEndTime = blockTime - - // Reward program that times out - timeout := types.NewRewardProgram( - "title", - "description", - 5, - "insert address", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 100000), - blockTime, - 0, - 1, - 0, - 0, - []types.QualifyingAction{}, - ) - timeout.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - timeout.ClaimPeriodEndTime = blockTime - timeout.ProgramEndTimeMax = blockTime - timeout.RemainingPoolBalance = timeout.GetTotalRewardPool() - s.app.RewardKeeper.StartRewardProgram(s.ctx, &timeout) - - // Reward program that times out - expiring := types.NewRewardProgram( - "title", - "description", - 6, - "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv", - sdk.NewInt64Coin("nhash", 100000), - sdk.NewInt64Coin("nhash", 100000), - blockTime, - 0, - 1, - 0, - 0, - []types.QualifyingAction{}, - ) - remainingBalance := expiring.GetTotalRewardPool() - expiring.ActualProgramEndTime = blockTime - expiring.MinimumRolloverAmount = sdk.NewInt64Coin("nhash", 1) - expiring.State = types.RewardProgram_STATE_FINISHED - expiring.RemainingPoolBalance = remainingBalance - - s.app.RewardKeeper.SetRewardProgram(s.ctx, notStarted) - s.app.RewardKeeper.SetRewardProgram(s.ctx, starting) - s.app.RewardKeeper.SetRewardProgram(s.ctx, nextClaimPeriod) - s.app.RewardKeeper.SetRewardProgram(s.ctx, ending) - s.app.RewardKeeper.SetRewardProgram(s.ctx, timeout) - s.app.RewardKeeper.SetRewardProgram(s.ctx, expiring) - - addr, _ := sdk.AccAddressFromBech32("cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv") - beforeBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - - // We call update - em := sdk.NewEventManager() - s.app.RewardKeeper.UpdateUnexpiredRewardsProgram(s.ctx.WithEventManager(em)) - - afterBalance := s.app.BankKeeper.GetBalance(s.ctx, addr, "nhash") - notStarted, _ = s.app.RewardKeeper.GetRewardProgram(s.ctx, notStarted.Id) - starting, _ = s.app.RewardKeeper.GetRewardProgram(s.ctx, starting.Id) - nextClaimPeriod, _ = s.app.RewardKeeper.GetRewardProgram(s.ctx, nextClaimPeriod.Id) - ending, _ = s.app.RewardKeeper.GetRewardProgram(s.ctx, ending.Id) - timeout, _ = s.app.RewardKeeper.GetRewardProgram(s.ctx, timeout.Id) - expiring, _ = s.app.RewardKeeper.GetRewardProgram(s.ctx, expiring.Id) - - s.Assert().Equal(uint64(0), notStarted.CurrentClaimPeriod, "claim period should be 0 for a program that is not started") - s.Assert().Equal(notStarted.State, types.RewardProgram_STATE_PENDING, "should be in pending state") - - s.Assert().Equal(uint64(1), starting.CurrentClaimPeriod, "claim period should be 1 for a program that just started") - s.Assert().Equal(starting.State, types.RewardProgram_STATE_STARTED, "should be in started state") - - s.Assert().Equal(uint64(2), nextClaimPeriod.CurrentClaimPeriod, "claim period should be 2 for a program that went to next claim period") - s.Assert().Equal(nextClaimPeriod.State, types.RewardProgram_STATE_STARTED, "should be in started state") - - s.Assert().Equal(uint64(1), ending.CurrentClaimPeriod, "claim period should not increment") - s.Assert().Equal(ending.State, types.RewardProgram_STATE_FINISHED, "should be in finished state") - - s.Assert().Equal(uint64(1), timeout.CurrentClaimPeriod, "claim period should not increment") - s.Assert().Equal(timeout.State, types.RewardProgram_STATE_FINISHED, "should be in finished state") - - s.Assert().Equal(expiring.State, types.RewardProgram_STATE_EXPIRED, "should be in expired state") - s.Assert().Equal(beforeBalance.Add(remainingBalance), afterBalance, "balance should be refunded") - - attr := func(key, value string) abci.EventAttribute { - return abci.EventAttribute{ - Key: key, - Value: value, - } - } - newEvent := func(typeName string, attributes ...abci.EventAttribute) sdk.Event { - return sdk.Event{ - Type: typeName, - Attributes: attributes, - } - } - iStr := func(i uint64) string { - return fmt.Sprintf("%d", i) - } - - moduleAddr := authtypes.NewModuleAddress(types.ModuleName).String() - expAddr := expiring.DistributeFromAddress - amount := "100000nhash" - expectedEvents := sdk.Events{ - newEvent("reward_program_started", attr("reward_program_id", iStr(starting.Id))), - newEvent("reward_program_finished", attr("reward_program_id", iStr(ending.Id))), - newEvent("reward_program_finished", attr("reward_program_id", iStr(timeout.Id))), - newEvent("coin_spent", attr("spender", moduleAddr), attr("amount", amount)), - newEvent("coin_received", attr("receiver", expAddr), attr("amount", amount)), - newEvent("transfer", attr("recipient", expAddr), attr("sender", moduleAddr), attr("amount", amount)), - newEvent("message", attr("sender", moduleAddr)), - newEvent("reward_program_expired", attr("reward_program_id", iStr(expiring.Id))), - } - expectedEventsStrs := EventsStrings(expectedEvents) - - actualEvents := em.Events() - actualEventsStrs := EventsStrings(actualEvents) - if !s.Assert().Equal(expectedEventsStrs, actualEventsStrs, "events emitted during UpdateUnexpiredRewardsProgram") { - s.T().Logf("Expected Events:\n%s", expectedEventsStrs) - s.T().Logf("Actual Events:\n%s", actualEventsStrs) - } -} - -// EventsStrings converts the events into a slice of strings; one string per attribute. -// These are handy for comparing actual/expected events using .Equals. The failure messages are easier to understand. -func EventsStrings(events sdk.Events) []string { - rv := []string{} - for i, event := range events { - for j, attr := range event.Attributes { - indexed := "" - if attr.Index { - indexed = " (indexed)" - } - rv = append(rv, fmt.Sprintf("[%d]%s[%d]: %q = %q%s", i, event.Type, j, attr.Key, attr.Value, indexed)) - } - } - return rv -} diff --git a/x/reward/module/module.go b/x/reward/module/module.go deleted file mode 100644 index a427f916f6..0000000000 --- a/x/reward/module/module.go +++ /dev/null @@ -1,193 +0,0 @@ -package reward - -import ( - "context" - "encoding/json" - "math/rand" - - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - - abci "github.com/cometbft/cometbft/abci/types" - - cerrs "cosmossdk.io/errors" - - sdkclient "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - - rewardModule "github.com/provenance-io/provenance/x/reward" - cli "github.com/provenance-io/provenance/x/reward/client/cli" - "github.com/provenance-io/provenance/x/reward/keeper" - simulation "github.com/provenance-io/provenance/x/reward/simulation" - "github.com/provenance-io/provenance/x/reward/types" -) - -var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} - // TODO[1760]: app-module: Add more assertions for the new types and clean up stuff no longer needed. -) - -// AppModuleBasic defines the basic application module used by the reward module. -type AppModuleBasic struct { - cdc codec.Codec -} - -// Name returns the reward module's name. -func (AppModuleBasic) Name() string { - return types.ModuleName -} - -// RegisterServices registers a gRPC query service to respond to the -// module-specific gRPC queries. -func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) -} - -// RegisterLegacyAminoCodec registers the reward module's types for the given codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) { -} - -// RegisterInterfaces registers the reward module's interface types -func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - types.RegisterInterfaces(registry) -} - -// DefaultGenesis returns default genesis state as raw bytes for the reward -// module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesis()) -} - -// ValidateGenesis performs genesis state validation for the reward module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage) error { - var data types.GenesisState - if err := cdc.UnmarshalJSON(bz, &data); err != nil { - return cerrs.Wrapf(err, "failed to unmarshal %q genesis state", types.ModuleName) - } - - return data.Validate() -} - -// RegisterRESTRoutes registers the REST routes for the reward module. -// Deprecated: RegisterRESTRoutes is deprecated. -func (AppModuleBasic) RegisterRESTRoutes(_ sdkclient.Context, _ *mux.Router) {} - -// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the reward module. -func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { - if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { - panic(err) - } -} - -// GetQueryCmd returns the cli query commands for the reward module -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - -// GetTxCmd returns the transaction commands for the reward module -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.NewTxCmd() -} - -// AppModule implements the sdk.AppModule interface -type AppModule struct { - AppModuleBasic - keeper keeper.Keeper - accountKeeper authkeeper.AccountKeeper - bankKeeper bankkeeper.Keeper -} - -// NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper) AppModule { - return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc}, - keeper: keeper, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, - } -} - -// IsOnePerModuleType is a dummy function that satisfies the OnePerModuleType interface (needed by AppModule). -func (AppModule) IsOnePerModuleType() {} - -// IsAppModule is a dummy function that satisfies the AppModule interface. -func (AppModule) IsAppModule() {} - -// GenerateGenesisState creates a randomized GenState of the rewards module. -func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { - simulation.RandomizedGenState(simState) -} - -// ProposalContents returns content functions used to simulate governance proposals. -func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { - // currently no gov proposals exist - return nil -} - -// RandomizedParams returns randomized module parameters for param change proposals. -func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.LegacyParamChange { - // currently no module params exist - return nil -} - -// RegisterStoreDecoder registers a func to decode each module's defined types from their corresponding store key -func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { - sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc) -} - -// WeightedOperations returns simulation operations (i.e msgs) with their respective weight -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - return simulation.WeightedOperations( - simState.AppParams, simState.Cdc, am.keeper, am.accountKeeper, am.bankKeeper, - ) -} - -// Name returns the reward module's name. -func (AppModule) Name() string { - return types.ModuleName -} - -// RegisterInvariants does nothing, there are no invariants to enforce -func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} - -// InitGenesis performs genesis initialization for the reward module. It returns -// no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - am.keeper.InitGenesis(ctx, &genesisState) - return []abci.ValidatorUpdate{} -} - -// ExportGenesis returns the exported genesis state as raw bytes for the reward -// module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) -} - -// ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } - -// BeginBlock is the `BeginBlocker` function run at the beginning of each block to -// process rewards module updates. -func (am AppModule) BeginBlock(ctx context.Context) error { - rewardModule.BeginBlocker(sdk.UnwrapSDKContext(ctx), am.keeper) - return nil -} - -// EndBlock The `EndBlocker` abci call is ran at the end of each block. The `EventManager` is monitored -// and `Qualifying Actions` are deduced from newly created events and prior internal state. -func (am AppModule) EndBlock(ctx context.Context) error { - rewardModule.EndBlocker(sdk.UnwrapSDKContext(ctx), am.keeper) - return nil -} diff --git a/x/reward/simulation/decoder.go b/x/reward/simulation/decoder.go deleted file mode 100644 index 5e44828ce9..0000000000 --- a/x/reward/simulation/decoder.go +++ /dev/null @@ -1,44 +0,0 @@ -package simulation - -import ( - "bytes" - "fmt" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/types/kv" - - "github.com/provenance-io/provenance/x/reward/types" -) - -// NewDecodeStore returns a decoder function closure that unmarshalls the KVPair's -// Value -func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { - return func(kvA, kvB kv.Pair) string { - switch { - case bytes.Equal(kvA.Key[:1], types.RewardProgramKeyPrefix): - var attribA, attribB types.RewardProgram - - cdc.MustUnmarshal(kvA.Value, &attribA) - cdc.MustUnmarshal(kvB.Value, &attribB) - - return fmt.Sprintf("%v\n%v", attribA, attribB) - - case bytes.Equal(kvA.Key[:1], types.ClaimPeriodRewardDistributionKeyPrefix): - var attribA, attribB types.ClaimPeriodRewardDistribution - - cdc.MustUnmarshal(kvA.Value, &attribA) - cdc.MustUnmarshal(kvB.Value, &attribB) - - return fmt.Sprintf("%v\n%v", attribA, attribB) - case bytes.Equal(kvA.Key[:1], types.AccountStateKeyPrefix): - var attribA, attribB types.RewardAccountState - - cdc.MustUnmarshal(kvA.Value, &attribA) - cdc.MustUnmarshal(kvB.Value, &attribB) - - return fmt.Sprintf("%v\n%v", attribA, attribB) - default: - panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key)) - } - } -} diff --git a/x/reward/simulation/genesis.go b/x/reward/simulation/genesis.go deleted file mode 100644 index 5f56a2bd10..0000000000 --- a/x/reward/simulation/genesis.go +++ /dev/null @@ -1,130 +0,0 @@ -package simulation - -// DONTCOVER - -import ( - "encoding/json" - "fmt" - "math/rand" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/provenance-io/provenance/internal/pioconfig" - "github.com/provenance-io/provenance/x/reward/types" -) - -// Simulation parameter constants -const ( - MaxActions = "max_actions" - MinActions = "min_actions" - TotalRewardsPool = "total_rewards_pool" - MaxRewardByAddress = "max_reward_by_address" -) - -// GenTotalRewardsPool randomized TotalRewardsPool -func GenTotalRewardsPool(r *rand.Rand) sdk.Coin { - return sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, int64(randIntBetween(r, 1000, 10000000000))) -} - -// GenMaxRewardsByAddress randomized MaxRewardByAddress -func GenMaxRewardsByAddress(r *rand.Rand) sdk.Coin { - return sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, int64(randIntBetween(r, 1, 999))) -} - -// MaxActionsFn randomized MaxActions -func MaxActionsFn(r *rand.Rand) uint64 { - return uint64(randIntBetween(r, 100, 100000000)) -} - -// MinActionsFn randomized MinActions -func MinActionsFn(r *rand.Rand) uint64 { - return uint64(r.Intn(101)) -} - -// RandomizedGenState generates a random GenesisState for distribution -func RandomizedGenState(simState *module.SimulationState) { - var totalRewardsPool sdk.Coin - simState.AppParams.GetOrGenerate( - TotalRewardsPool, &totalRewardsPool, simState.Rand, - func(r *rand.Rand) { totalRewardsPool = GenTotalRewardsPool(r) }, - ) - var maxRewardsByAddress sdk.Coin - simState.AppParams.GetOrGenerate( - MaxRewardByAddress, &maxRewardsByAddress, simState.Rand, - func(r *rand.Rand) { maxRewardsByAddress = GenMaxRewardsByAddress(r) }, - ) - - var maxActions uint64 - simState.AppParams.GetOrGenerate( - MaxActions, &maxActions, simState.Rand, - func(r *rand.Rand) { maxActions = MaxActionsFn(r) }, - ) - - var minActions uint64 - simState.AppParams.GetOrGenerate( - MinActions, &minActions, simState.Rand, - func(r *rand.Rand) { minActions = MinActionsFn(r) }, - ) - - minDelegation := sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, int64(minActions)) - - now := simState.GenTimestamp - claimPeriodSeconds := uint64(simState.Rand.Intn(100000)) - claimPeriods := uint64(simState.Rand.Intn(100)) + 1 - maxRolloverPeriods := uint64(simState.Rand.Intn(10)) - expireClaimPeriods := uint64(simState.Rand.Intn(100000)) - expectedProgramEndTime := types.CalculateExpectedEndTime(now, claimPeriodSeconds, claimPeriods) - programEndTimeMax := types.CalculateEndTimeMax(now, claimPeriodSeconds, claimPeriods, maxRolloverPeriods) - rewardProgram := types.RewardProgram{ - Title: "title", - Description: "description", - Id: uint64(simState.Rand.Intn(100000)), - DistributeFromAddress: simState.Accounts[0].Address.String(), - TotalRewardPool: totalRewardsPool, - RemainingPoolBalance: totalRewardsPool, - ClaimedAmount: sdk.NewInt64Coin(totalRewardsPool.Denom, 0), - MaxRewardByAddress: maxRewardsByAddress, - ProgramStartTime: now.UTC(), - ExpectedProgramEndTime: expectedProgramEndTime.UTC(), - ProgramEndTimeMax: programEndTimeMax.UTC(), - ClaimPeriodSeconds: claimPeriodSeconds, - ClaimPeriods: claimPeriods, - MaxRolloverClaimPeriods: maxRolloverPeriods, - ExpirationOffset: expireClaimPeriods, - State: types.RewardProgram_STATE_PENDING, - QualifyingActions: []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: minActions, - MaximumActions: maxActions, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - }, - MinimumRolloverAmount: sdk.NewInt64Coin(totalRewardsPool.Denom, 100_000_000_000), - } - - rewards := types.NewGenesisState( - uint64(100001), - []types.RewardProgram{ - rewardProgram, - }, - []types.ClaimPeriodRewardDistribution{}, - []types.RewardAccountState{}, - ) - - bz, err := json.MarshalIndent(&rewards, "", " ") - if err != nil { - panic(err) - } - fmt.Printf("Selected randomly generated reward programs:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(rewards) -} - -// randIntBetween generates a random number between min and max inclusive. -func randIntBetween(r *rand.Rand, min, max int) int { - return r.Intn(max-min+1) + min -} diff --git a/x/reward/simulation/operations.go b/x/reward/simulation/operations.go deleted file mode 100644 index ce0b1e2db8..0000000000 --- a/x/reward/simulation/operations.go +++ /dev/null @@ -1,205 +0,0 @@ -package simulation - -// DONTCOVER - -import ( - "math/rand" - "time" - - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - - sdkmath "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" - "github.com/cosmos/cosmos-sdk/x/simulation" - - simappparams "github.com/provenance-io/provenance/app/params" - "github.com/provenance-io/provenance/internal/pioconfig" - "github.com/provenance-io/provenance/x/reward/keeper" - "github.com/provenance-io/provenance/x/reward/types" -) - -// Simulation operation weights constants -const ( - OpWeightSubmitCreateRewardsProposal = "op_weight_submit_create_rewards_proposal" - OpWeightEndRewardsProposal = "op_weight_submit_end_reward_proposal" -) - -// WeightedOperations returns all the operations from the module with their respective weights -func WeightedOperations( - appParams simtypes.AppParams, cdc codec.JSONCodec, k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper, -) simulation.WeightedOperations { - var ( - weightMsgAddRewardsProgram int - weightMsgEndRewardProgram int - ) - - appParams.GetOrGenerate(OpWeightSubmitCreateRewardsProposal, &weightMsgAddRewardsProgram, nil, - func(_ *rand.Rand) { - weightMsgAddRewardsProgram = simappparams.DefaultWeightSubmitCreateRewards - }, - ) - appParams.GetOrGenerate(OpWeightEndRewardsProposal, &weightMsgEndRewardProgram, nil, - func(_ *rand.Rand) { - weightMsgEndRewardProgram = simappparams.DefaultWeightSubmitEndRewards - }, - ) - - return simulation.WeightedOperations{ - simulation.NewWeightedOperation( - weightMsgAddRewardsProgram, - SimulateMsgCreateRewardsProgram(k, ak, bk), - ), - simulation.NewWeightedOperation( - weightMsgEndRewardProgram, - SimulateMsgEndRewardsProgram(k, ak, bk), - ), - } -} - -// SimulateMsgCreateRewardsProgram sends of a MsgCreateRewardProgramRequest. -func SimulateMsgCreateRewardsProgram(_ keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation { - return func( - r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, - ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - simAccount, _ := simtypes.RandomAcc(r, accs) - var totalRewardsPool = GenTotalRewardsPool(r) - var maxRewardsByAddress = GenMaxRewardsByAddress(r) - var maxActions = MaxActionsFn(r) - - var minActions = MinActionsFn(r) - - minDelegation := sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, int64(minActions)) - - now := time.Now() - claimPeriods := uint64(r.Intn(100)) - maxRolloverPeriods := uint64(r.Intn(10)) - expireClaimPeriods := uint64(r.Intn(100)) - - msg := types.NewMsgCreateRewardProgramRequest("title", - "description", - simAccount.Address.String(), - totalRewardsPool, - maxRewardsByAddress, - now.Add(5*time.Second), - claimPeriods, - 1, - maxRolloverPeriods, - expireClaimPeriods, - []types.QualifyingAction{ - { - Type: &types.QualifyingAction_Vote{ - Vote: &types.ActionVote{ - MinimumActions: minActions, - MaximumActions: maxActions, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - }) - return Dispatch(r, app, ctx, ak, bk, simAccount, chainID, msg, nil) - } -} - -// Dispatch sends an operation to the chain using a given account/funds on account for fees. Failures on the server side -// are handled as no-op msg operations with the error string as the status/response. -func Dispatch( - r *rand.Rand, - app *baseapp.BaseApp, - ctx sdk.Context, - ak authkeeper.AccountKeeperI, - bk bankkeeper.Keeper, - from simtypes.Account, - chainID string, - msg sdk.Msg, - futures []simtypes.FutureOperation, -) ( - simtypes.OperationMsg, - []simtypes.FutureOperation, - error, -) { - account := ak.GetAccount(ctx, from.Address) - spendable := bk.SpendableCoins(ctx, account.GetAddress()) - - fees, err := simtypes.RandomFees(r, ctx, spendable) - if err != nil { - return simtypes.NoOpMsg(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err - } - err = testutil.FundAccount(ctx, bk, account.GetAddress(), sdk.NewCoins(sdk.Coin{ - Denom: pioconfig.GetProvenanceConfig().BondDenom, - Amount: sdkmath.NewInt(1_000_000_000_000_000), - })) - if err != nil { - return simtypes.NoOpMsg(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), "unable to fund account"), nil, err - } - txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := simtestutil.GenSignedMockTx( - r, - txGen, - []sdk.Msg{msg}, - fees, - simtestutil.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - from.PrivKey, - ) - if err != nil { - return simtypes.NoOpMsg(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err - } - - _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) - if err != nil { - return simtypes.NoOpMsg(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), err.Error()), nil, nil - } - - return simtypes.NewOperationMsg(msg, true, ""), futures, nil -} - -// SimulateMsgEndRewardsProgram sends a MsgEndRewardProgramRequest for a random existing reward program. -func SimulateMsgEndRewardsProgram(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation { - return func( - r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, - ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - rewardProgram := randomRewardProgram(r, ctx, k) - if rewardProgram == nil { - return simtypes.NoOpMsg(sdk.MsgTypeURL(&types.MsgEndRewardProgramRequest{}), sdk.MsgTypeURL(&types.MsgEndRewardProgramRequest{}), "unable to find a valid reward program"), nil, nil - } - var simAccount simtypes.Account - var found bool - addr, err := sdk.AccAddressFromBech32(rewardProgram.DistributeFromAddress) - if err != nil { - // should just noit be possible and panic on the test - panic(err) - } - simAccount, found = simtypes.FindAccount(accs, addr) - if !found { - return simtypes.NoOpMsg(sdk.MsgTypeURL(&types.MsgEndRewardProgramRequest{}), sdk.MsgTypeURL(&types.MsgEndRewardProgramRequest{}), "creator of rewards program account does not exist"), nil, nil - } - msg := types.NewMsgEndRewardProgramRequest(rewardProgram.Id, rewardProgram.DistributeFromAddress) - return Dispatch(r, app, ctx, ak, bk, simAccount, chainID, msg, nil) - } -} - -func randomRewardProgram(r *rand.Rand, ctx sdk.Context, k keeper.Keeper) *types.RewardProgram { - var rewardPrograms []types.RewardProgram - err := k.IterateRewardPrograms(ctx, func(rewardProgram types.RewardProgram) (stop bool, err error) { - rewardPrograms = append(rewardPrograms, rewardProgram) - return false, nil - }) - if err != nil { - // sim tests should fail if iterator errors - panic(err) - } - if len(rewardPrograms) == 0 { - return nil - } - idx := r.Intn(len(rewardPrograms)) - return &rewardPrograms[idx] -} diff --git a/x/reward/simulation/operations_test.go b/x/reward/simulation/operations_test.go deleted file mode 100644 index 92d6f0f495..0000000000 --- a/x/reward/simulation/operations_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/suite" - - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/bank/testutil" - - "github.com/provenance-io/provenance/app" - simappparams "github.com/provenance-io/provenance/app/params" - "github.com/provenance-io/provenance/x/reward/simulation" - "github.com/provenance-io/provenance/x/reward/types" -) - -type SimTestSuite struct { - suite.Suite - - ctx sdk.Context - app *app.App -} - -func (s *SimTestSuite) SetupTest() { - s.app = app.Setup(s.T()) - s.ctx = s.app.BaseApp.NewContext(false) -} - -func (s *SimTestSuite) TestWeightedOperations() { - cdc := s.app.AppCodec() - appParams := make(simtypes.AppParams) - - weightedOps := simulation.WeightedOperations(appParams, cdc, s.app.RewardKeeper, - s.app.AccountKeeper, s.app.BankKeeper, - ) - - // setup 3 accounts - source := rand.NewSource(1) - r := rand.New(source) - accs := s.getTestingAccounts(r, 3) - - expected := []struct { - weight int - opMsgRoute string - opMsgName string - }{ - {weight: simappparams.DefaultWeightSubmitCreateRewards, opMsgRoute: types.RouterKey, opMsgName: sdk.MsgTypeURL(&types.MsgCreateRewardProgramRequest{})}, - {weight: simappparams.DefaultWeightSubmitEndRewards, opMsgRoute: types.RouterKey, opMsgName: sdk.MsgTypeURL(&types.MsgEndRewardProgramRequest{})}, - } - - for i, w := range weightedOps { - operationMsg, _, _ := w.Op()(r, s.app.BaseApp, s.ctx, accs, "") - // the following checks are very much dependent from the ordering of the output given - // by WeightedOperations. if the ordering in WeightedOperations changes some tests - // will fail - s.Require().Equal(expected[i].weight, w.Weight(), "weight should be the same") - s.Require().Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") - s.Require().Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") - } -} - -func (s *SimTestSuite) TestSimulateMsgAddRewards() { - - // setup 3 accounts - source := rand.NewSource(1) - r := rand.New(source) - accounts := s.getTestingAccounts(r, 3) - - // execute operation - op := simulation.SimulateMsgCreateRewardsProgram(s.app.RewardKeeper, s.app.AccountKeeper, s.app.BankKeeper) - operationMsg, futureOperations, err := op(r, s.app.BaseApp, s.ctx, accounts, "") - s.Require().NoError(err) - - var msg types.MsgCreateRewardProgramRequest - types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg) - - s.Require().True(operationMsg.OK, operationMsg.String()) - s.Require().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name) - s.Require().Equal(types.RouterKey, operationMsg.Route) - s.Require().Len(futureOperations, 0) -} - -func TestSimTestSuite(t *testing.T) { - suite.Run(t, new(SimTestSuite)) -} - -func (s *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { - accounts := simtypes.RandomAccounts(r, n) - - initAmt := sdk.TokensFromConsensusPower(1000000, sdk.DefaultPowerReduction) - initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) - - // add coins to the accounts - for _, account := range accounts { - acc := s.app.AccountKeeper.NewAccountWithAddress(s.ctx, account.Address) - s.app.AccountKeeper.SetAccount(s.ctx, acc) - err := testutil.FundAccount(s.ctx, s.app.BankKeeper, account.Address, initCoins) - s.Require().NoError(err) - } - - return accounts -} diff --git a/x/reward/spec/01_concepts.md b/x/reward/spec/01_concepts.md deleted file mode 100644 index 6456bf62da..0000000000 --- a/x/reward/spec/01_concepts.md +++ /dev/null @@ -1,35 +0,0 @@ - - -# Concepts - - - - [Reward Program](#reward-program) - - [Qualifying Actions and Eligibility Criteria](#qualifying-actions-and-eligibility-criteria) - - [Claim Period](#claim-period) - - [Reward Claim](#reward-claim) - - [Rollover](#rollover) - - [Refunding](#refunding) - -## Reward Program -Reward Programs are configurable campaigns that encourage users to participate in the Provenance Blockchain. Entities interested in creating a Reward Program will supply their new program with funds, set the duration of their program, and provide the participation requirements. - -## Qualifying Actions and Eligibility Criteria -A `Qualifying Action` is one or more transactions that a user performs on the Provenance Blockchain that has been listed within the `Reward Program`. These actions are then evaluated against a set of criteria that are also defined within the `Reward Program` known as `Eligiblity Criteria`. Users become participants in the Reward Program by performing a `Qualifying Action` and meeting all conditions specified by its `Eligiblity Criteria`. - -## Claim Period -A `Reward Program` is split into one or more time intervals known as `Claim Periods`. Each of these `Claim Periods` gets an equal portion of the `Reward Program Reward Pool` known as the `Claim Period Reward Pool`. Users can participate within these `Claim Periods` and are rewarded for their actions. - -## Reward Claim -When a user participates in a `Reward Program` they are granted one or more shares of the `Claim Period Reward Pool`. Once the`Claim Period` ends, the participant will be able to claim their reward by performing a claim transaction. The participant's reward is proportional to their activity compared to everyone else within a `Claim Period`. Users must claim their rewards before the `Reward Program` expires. Additionally, users will be limited to `max_reward_per_address` of the `Claim Period Reward Pool`. - -**Reward For Claim Period** - -$$\left( ClaimPeriodRewardPool \right) \times \left( EarnedShares \over ClaimPeriodShares \right) $$ - -## Rollover -It is possible that not all of the `Claim Period Reward Pool` will be distributed. This can happen when there is not enough activity, and participants are gated by the `max_reward_per_address`. The `Reward Program` will attempt to move these funds into a `Rollover Claim Period`. A `Rollover Claim Period` behaves exactly like any other `Claim Period`, but it is not guaranteed to have an equal portion of the original `Reward Program Reward Pool`. A `Reward Program` may run up to `max_rollover_claim_periods`, but is not guaranteed to run any of them. This is dependent on user activity, `program_end_time_max` field, and the `minimum_rollover_amount` field. Currently, the `minimum_rollover_amount` is set to 10% of the `Claim Period Reward Pool`. - -## Refunding -When a `Reward Program` ends it gives all participants `expiration_offset` seconds to claim their rewards. After `expiration_offset` seconds the `Reward Program` expires and prevents participants from claiming. The unclaimed rewards and any funds still remaining within the `Reward Program Reward Pool` will be given back to the creator. diff --git a/x/reward/spec/02_state.md b/x/reward/spec/02_state.md deleted file mode 100644 index be3d433fb8..0000000000 --- a/x/reward/spec/02_state.md +++ /dev/null @@ -1,83 +0,0 @@ - - -# State - -The rewards module manages the state of every reward program and each of its participants. - - - - [Reward Program](#reward-program) - - [Claim Period Reward Distribution](#claim-period-reward-distribution) - - [Reward Account State](#reward-account-state) - - [Action Counter](#action-counter) - - [Qualifying Actions](#qualifying-actions) - - [Action Delegate](#action-delegate) - - [Action Transfer](#action-transfer) - - [Action Vote](#action-vote) - ---- -## Reward Program - -A `RewardProgram` is the main data structure used by the Active Participation and Engagement (APE) module. It keeps track of the state, balances, qualifying actions, timers, and counters for a single Reward Program. Every Reward Program gets its own unique identifier that we track within the store. - -* Reward Program: `0x01 | RewardProgram ID (8 bytes) -> ProtocolBuffers(RewardProgram)` -* Reward Program ID: `0x02 -> uint64(RewardProgramID)` - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L12-L73 - ---- -## Claim Period Reward Distribution - -A `ClaimPeriodRewardDistribution` is created for each claim period of every `RewardProgram`. Its purpose is to track live claim period specific information. Examples of this include the total number of granted shares in the claim period, sum of of all its rewards given out as claims, and the amount of reward allocated to it from the `RewardProgram`. - -* Claim Period Reward Distribution: `0x03 | Reward Program ID (8 bytes) | Claim Period ID (8 bytes) -> ProtocolBuffers(ClaimPeriodRewardDistribution)` - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L75-L92 - ---- -## Reward Account State - -The purpose of `RewardAccountState` is to track state at the address level of a claim period. It counts the number of claim period shares the user obtained, the status of their `RewardClaim`, and other stateful information that assists the system in properly granting rewards. - -* AccountStateAddressLookupKeyPrefix: `0x04 | Account Address (n bytes, with the address length being stored in the first byte {int64(address[1:2][0])}) | Reward Program ID (8 bytes) | Claim Period ID (8 bytes) -> ProtocolBuffers(RewardAccountState)` -* AccountStateKeyPrefix: `0x05 | Reward Program ID (8 bytes) | Claim Period ID (8 bytes) | Account Address (n bytes, with the address length being stored in the first byte {int64(address[1:2][0])}) -> ProtocolBuffers(RewardAccountState)` - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L94-L123 - -### Action Counter - -`ActionCounter` tracks the number of times an action has been performed. - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L190-L199 - ---- -## Qualifying Actions - -A list of one or more actions that a user can perform to attempt to participate in a `RewardProgram`. In order to be considered a participant and granted a share then all the `EligiblityCriteria` on the action must be met. Each action has its own `EligiblityCriteria`, which is independently evaluated against system state and `RewardAccountState` for that user. Each `Qualifying Action` is evaluated independently, thus it is possible for a user to earn more than one reward for a single action. - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L125-L141 - -### Action Delegate - -`ActionDelegate` is when a user performs a delegate. - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L143-L162 - -The triggering account must have a total delegation amount within the bands of [`minimum_delegation_amount`,`maximum_delegation_amount`]. Additionally, the validator they are staking to must be within the [`minimum_active_stake_percentile`,`maximum_active_stake_percentile`] power percentile. If both of these criteria are met then the delegate is considered successful. The `minimum_actions` and `maximum_actions` fields are the number of successful delegate that must be performed. Once all these conditions are met then the user will receive a share. - -### Action Transfer - -`ActionTransfer` is when a user transfers coins. - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L164-L175 - -If the triggering account has delegated at least the `minimum_delegation_amount`, then the transfer action will be considered successful. The `minimum_actions` and `maximum_actions` fields are the number of successful transfer that must be performed. When all these conditions are met, then the user will receive a share. - -### Action Vote - -`ActionVote` is when a user votes on a proposal. - -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/reward.proto#L177-L188 - -If the triggering account has delegated at least the `minimum_delegation_amount`, then the vote action will be considered successful. The `minimum_actions` and `maximum_actions` fields are the number of successful votes that must be performed. When all these conditions are met, then the user will receive a share. diff --git a/x/reward/spec/03_state_transitions.md b/x/reward/spec/03_state_transitions.md deleted file mode 100644 index 429bdf1c62..0000000000 --- a/x/reward/spec/03_state_transitions.md +++ /dev/null @@ -1,72 +0,0 @@ - - -# State Transitions - -This document describes the state transition operations involved in the rewards module. - - - - [Reward Programs](#reward-programs) - - [Pending](#pending) - - [Started](#started) - - [Finished](#finished) - - [Expired](#expired) - - [Reward Claims](#reward-claims) - - [Unclaimable](#unclaimable) - - [Claimable](#claimable) - - [Claimed](#claimed) - - [Expired](#expired) - - - -## Reward Programs -State transition for Reward Programs happen on `BeginBlock` and make use of the `BlockTime` attribute. - -A Reward Program can be `Pending`, `Started`, `Finished`, or `Expired`. A Reward Program will move through all these states, and will initially be in the `Pending` state. - -#### Note -A Reward Program creator may end a Reward Program early while it's in `Pending` or `Started` state. A Reward Program in the `Pending` state will be deleted and not progress through all the states. Any program that is ended after it's in the `Started` state will transition to the `Finished` state on the next `BeginBlock`. - -### Pending -Reward program has *not* started. - -#### Note -A user may force a Reward Program in this state to end with the `end-reward-program` transaction. In this case the Reward Program will be deleted and not progress. - -### Started -The Reward Program has started, and users can participate by performing qualifying actions. Participants can claim their rewards at the end of the claim period that the qualifying action was performed in. - -#### Note -A user may force a Reward Program in this state to end with the `end-reward-program` transaction. The Reward Program will transition to the `Finished` state on the next `BeginBlock`. - -### Finished -The Reward Program has ended, and participants can no longer make qualifying actions. Participants have a limited amount of time to collect their remaining rewards. - -### Expired -Reward program has passed its expiration date, and participants can no longer claim rewards. The remaining balance and any unclaimed rewards will be returned to the creator. - -

- -

- -## Reward Claims -State transitions for a Reward Claim happen on `BeginBlock` and on claim transactions. - -A Reward Claim can be `Unclaimable`, `Claimable`, `Claimed`, or `Expired`. A Reward Claim will always start as `Unclaimable` and eventually become `Claimable`. If a participant claims their reward then the Reward Claim will become `Claimed`, otherwise it will timeout and enter the `Expired` state where they can no longer claim it. - -### Unclaimable -The reward has been granted to a participant, but it cannot be claimed until the current claim period ends. - -### Claimable -The reward has been granted to the participant, and it's claimable by the participant via a transaction. If the reward is not claimed it will eventually expire. - -### Claimed -The reward has been granted and received by the participant. A reward cannot be claimed more than once. - -### Expired -The reward has been cleaned up and the participant can no longer claim it. The funds attached to the reward claim are refunded back to the program creator. - -

- -

diff --git a/x/reward/spec/04_messages.md b/x/reward/spec/04_messages.md deleted file mode 100644 index 4420e004fd..0000000000 --- a/x/reward/spec/04_messages.md +++ /dev/null @@ -1,79 +0,0 @@ - - -# Messages - -In this section we describe the processing of the reward messages and the corresponding updates to the state. - - - - [Msg/CreateRewardProgramRequest](#msgcreaterewardprogramrequest) - - [Msg/EndRewardProgramRequest](#msgendrewardprogramrequest) - - [Msg/ClaimRewardRequest](#msgclaimrewardrequest) - - [Msg/ClaimAllRewardsRequest](#msgclaimallrewardsrequest) - - -## Msg/CreateRewardProgramRequest - -Creates a Reward Program that users can participate in. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L40-L72 - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L74-L78 - -The message will fail under the following conditions: -* The program start time is at the current block time or after -* The requester is unable to send the reward pool amount to module -* The title is empty or greater than 140 characters -* The description is empty or greater than 10000 characters -* The distribute from address is an invalid bech32 address -* The total reward pool amount is not positive -* The claim periods field is set to less than 1 -* The denominations are not in nhash -* There are no qualifying actions -* The qualifying actions are not valid - -## Msg/EndRewardProgramRequest - -Ends a Reward Program that is in either the PENDING or STARTED state. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L80-L89 - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L91-L92 - -The message will fail under the following conditions: -* The Reward Program does not end -* The Reward Program is not in PENDING or STARTED state -* The Reward Program owner does not match the specified address - -## Msg/ClaimRewardRequest - -Allows a participant to claim all their rewards for all past claim periods on a reward program. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L94-L100 - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L102-L107 - -The message will fail under the following conditions: -* The Reward Program does not exist -* The Reward Program is expired -* The Reward Address does not exist - -## Msg/ClaimAllRewardsRequest - -Allows a participant to claim all their rewards for all past claim periods on all reward programs. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L109-L113 - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/tx.proto#L115-L122 - -The message will fail under the following conditions: -* The Reward Address does not exist diff --git a/x/reward/spec/05_queries.md b/x/reward/spec/05_queries.md deleted file mode 100644 index 17ea017789..0000000000 --- a/x/reward/spec/05_queries.md +++ /dev/null @@ -1,88 +0,0 @@ - - -# Rewards Queries -In this section we describe the queries available for looking up rewards information. - - - - [Query Reward Program By ID](#query-reward-program-by-id) - - [Query Reward Programs](#query-reward-programs) - - [Query Claim Period Reward Distribution By ID](#query-claim-period-reward-distribution-by-id) - - [Query Claim Period Reward Distributions](#query-claim-period-reward-distributions) - - [Query Rewards By Address](#query-rewards-by-address) - - ---- -## Query Reward Program By ID -The `QueryRewardProgramByID` query is used to obtain the content of a specific Reward Program. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L47-L51 - -The `id` is the unique identifier for the Reward Program. - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L53-L57 - - ---- -## Query Reward Programs -The `QueryRewardPrograms` query is used to obtain the content of all Reward Programs matching the supplied `query_type`. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L59-L80 - -The `query_type` is used to filter on the Reward Program state. The following are a list of `query_types`. -* ALL - All Reward Programs will be returned. -* PENDING - All Reward Programs that are in the `PENDING` state will be returned. -* ACTIVE - All Reward Programs that are in the `STARTED` state will be returned. -* OUTSTANDING - All Reward Programs that are either in the `PENDING` or `STARTED` state will be returned. -* FINISHED - All Reward Programs that are in the `FINISHED` or `EXPIRED` state will be returned. - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L82-L88 - - ---- -## Query Claim Period Reward Distribution By ID -The `QueryClaimPeriodRewardDistributionByID` query is used to obtain the content of a specific `Claim Period Reward Distribution`. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L104-L110 - -The `reward_id` is a unique identifier for the Reward Program and the `claim_id` is a unique identifier for the Reward Program's Claim Period. - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L112-L116 - - ---- -## Query Claim Period Reward Distributions -The `QueryClaimPeriodRewardDistributions` query is used to obtain the content of all `Claim Period Reward Distributions` matching the supplied `query_type`. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L90-L94 - -The `pagination` field is used to help limit the number of results. - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L96-L102 - - ---- -## Query Rewards By Address -The `QueryRewardsByAddress` query is used to obtain the status of the address' Reward Claims. - -### Request -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L118-L126 - -The `address` field is the bech32 address of the user to list Reward Claims for. The `claim_status` is used to filter on the Reward Claim. The following are a list of `claim_status`. -* ALL - All Reward Claims are returned. -* UNCLAIMABLE - All Reward Claims that are not yet eligible to be claimed. -* CLAIMABLE - All Reward Claims that are still eligible to be claimed. -* CLAIMED - All Reward Claims that have been claimed. -* EXPIRED - All Reward Claims that have expired. - -### Response -+++ https://github.com/provenance-io/provenance/blob/243a89c76378bb5af8a8017e099ee04ac22e99ce/proto/provenance/reward/v1/query.proto#L128-L136 diff --git a/x/reward/spec/06_events.md b/x/reward/spec/06_events.md deleted file mode 100644 index 3190cb00b0..0000000000 --- a/x/reward/spec/06_events.md +++ /dev/null @@ -1,87 +0,0 @@ - - -# Events - -The rewards module emits the following events: - - - - [Reward Program Created](#reward-program-created) - - [Reward Program Started](#reward-program-started) - - [Reward Program Finished](#reward-program-finished) - - [Reward Program Expired](#reward-program-expired) - - [Reward Program Ended](#reward-program-ended) - - [Claim Rewards](#claim-rewards) - - [Claim All Rewards](#claim-all-rewards) - - ---- -## Reward Program Created - -Fires when a reward program is created with the Create Reward Program Msg. - -| Type | Attribute Key | Attribute Value | -| ---------------------- | --------------------- | ------------------------- | -| RewardProgramCreated | reward_program_created| \{ID string\} | - ---- -## Reward Program Started - -Fires when a reward program transitions to the STARTED state. - -| Type | Attribute Key | Attribute Value | -| ---------------------- | --------------------- | ------------------------- | -| RewardProgramStarted | reward_program_id | \{ID string\} | - ---- -## Reward Program Finished - -Fires when a reward program transitions to the FINISHED state. - -| Type | Attribute Key | Attribute Value | -| ---------------------- | --------------------- | ------------------------- | -| RewardProgramFinished | reward_program_id | \{ID string\} | - ---- -## Reward Program Expired - -Fires when a reward program transitions to the EXPIRED state. - -| Type | Attribute Key | Attribute Value | -| ---------------------- | --------------------- | ------------------------- | -| RewardProgramExpired | reward_program_id | \{ID string\} | - ---- -## Reward Program Ended - -Fires when a reward program is ended with the End Reward Program Msg. - -| Type | Attribute Key | Attribute Value | -| ---------------------- | --------------------- | ------------------------- | -| RewardProgramEnded | reward_program_id | \{ID string\} | - ---- -## Claim Rewards - -Fires when a participant claims a reward claim with Claim Reward Msg. - -| Type | Attribute Key | Attribute Value | -| ---------------------- | --------------------- | ------------------------- | -| ClaimRewards | reward_program_id | \{ID string\} | -| ClaimRewards | rewards_claim_address | \{bech32address string\} | - -This event will not fire if the user has no claims or if they have already claimed all their rewards. - ---- -## Claim All Rewards - -Fires when a participant claims all their reward claims with Claim Reward Msg. - -| Type | Attribute Key | Attribute Value | -| ---------------------- | --------------------- | ------------------------- | -| ClaimAllRewards | rewards_claim_address | \{bech32address string\} | - -This event will not fire if the user has no claims or if they have already claimed all their rewards. - ---- diff --git a/x/reward/spec/07_begin_and_end_blocker.md b/x/reward/spec/07_begin_and_end_blocker.md deleted file mode 100644 index 4764d3f829..0000000000 --- a/x/reward/spec/07_begin_and_end_blocker.md +++ /dev/null @@ -1,30 +0,0 @@ - - -# Begin Blocker -The `BeginBlocker` abci call is invoked on the beginning of each block. The newly created block's `BlockTime` field is used to update the `Reward Programs` and `Reward Claims`. - -## State Machine Update -The following conditional logic is evaluated to help a `Reward Program` transition between states: -1. Starts a `Reward Program` if the `BlockTime` >= `program_start_time`. -2. Evaluates if `BlockTime` >= `claim_period_end_time`, and if it evaluates to true the `Reward Program` will *attempt* to progress to the next claim period. -3. The Reward Program will successfully progress to the next claim period, if all of the following criteria are true: - 1. `remaining_pool_balance` >= `minimum_rollover_amount` - 2. `BlockTime` < `program_end_time_max` -4. If either of the previously mentioned criteria is not met, then the `Reward Program` will end. -5. A completed `Reward Program` will then expire after `reward_claim_expiration_offset` seconds from its completion time. -6. All expired `Reward Program` will return any unused funds to the reward creator and expire any unclaimed rewards. - -# End Blocker -The `EndBlocker` abci call is ran at the end of each block. The `EventManager` is monitored and `Qualifying Actions` are deduced from newly created events and prior internal state. - -## Qualifying Action Detection -The following is logic is used to detect `Qualifying Actions` and grant shares: -1. The `EventManager` is utilized to traverse the events from the newly created block. -2. Using the `QualifyingAction` types defined in each active `RewardProgram`, the module attempts to build actions using the event and any prior events. -3. Each detected action will then be evaluated and only deemed a `QualifyingAction` if it matches the `Evaluation Criteria`. -4. One or more shares will be granted to the participant performing the `QualifyingAction`. -5. Participants can then claim these shares once the claim period that they were earned in completes. -6. Detects qualifying events based on events in EventManager for reward programs currently running. -7. Gives out shares for a running rewards program for that claim period for a given address performing qualifying events. diff --git a/x/reward/spec/08_genesis.md b/x/reward/spec/08_genesis.md deleted file mode 100644 index 7b6c97e8c7..0000000000 --- a/x/reward/spec/08_genesis.md +++ /dev/null @@ -1,13 +0,0 @@ - - -# Reward Genesis - -In this section we describe the processing of the reward messages and the corresponding updates to the state. - - -## Msg/GenesisState -GenesisState contains a list of reward programs, claim period reward distributions, and reward account states. These are exported and later imported from/to the store. - -+++ https://github.com/provenance-io/provenance/blob/ccaef3a7024f0ccd73d175465e91577373127858/proto/provenance/reward/v1/genesis.proto#L13-L22 diff --git a/x/reward/spec/README.md b/x/reward/spec/README.md deleted file mode 100644 index 9a69632a36..0000000000 --- a/x/reward/spec/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# `x/rewards` - -## Overview - -The purpose of the rewards module, also known as 'Active Participation and Engagement (APE) module', is to engage and reward users for Provenance Blockchain activity. The Provenance Blockchain Foundation, or any other interested party, can create and customize their own campaigns known as Reward Programs. Provenance Blockchain users can then participate in these programs by performing the actions defined on the Reward Program. Participants will be granted shares for each qualifying action and can claim them for the respective Reward Program's reward. - -## Contents - -1. **[Concepts](01_concepts.md)** -2. **[State](02_state.md)** -3. **[State transitions](03_state_transitions.md)** -4. **[Messages](04_messages.md)** -5. **[Queries](05_queries.md)** -6. **[Events](06_events.md)** -7. **[Begin and End Blocker](07_begin_and_end_blocker.md)** -8. **[Genesis](08_genesis.md)** \ No newline at end of file diff --git a/x/reward/spec/diagrams/reward-claim/RewardClaim.png b/x/reward/spec/diagrams/reward-claim/RewardClaim.png deleted file mode 100644 index 2d946467d0..0000000000 Binary files a/x/reward/spec/diagrams/reward-claim/RewardClaim.png and /dev/null differ diff --git a/x/reward/spec/diagrams/reward-claim/reward-claim.plantuml b/x/reward/spec/diagrams/reward-claim/reward-claim.plantuml deleted file mode 100644 index 659aca0d64..0000000000 --- a/x/reward/spec/diagrams/reward-claim/reward-claim.plantuml +++ /dev/null @@ -1,22 +0,0 @@ -@startuml RewardClaim - -skinparam linetype ortho -skinparam SequenceMessageAlign center -hide empty description -state c <> -state Unclaimable -state Claimable -state Claimed -state Expired - -[*] -down-> Unclaimable : [Participant engages in qualifying action] -Unclaimable -down-> Claimable : [Claim period ends] -Claimable -down-> c -c -down-> Expired : [End time + Offset <= Block Time] -c -down-> Claimed : [Participant claims transaction] - -@enduml \ No newline at end of file diff --git a/x/reward/spec/diagrams/reward-program/RewardProgram.png b/x/reward/spec/diagrams/reward-program/RewardProgram.png deleted file mode 100644 index 3e5d7ae598..0000000000 Binary files a/x/reward/spec/diagrams/reward-program/RewardProgram.png and /dev/null differ diff --git a/x/reward/spec/diagrams/reward-program/reward-program.plantuml b/x/reward/spec/diagrams/reward-program/reward-program.plantuml deleted file mode 100644 index 7dcfb549f5..0000000000 --- a/x/reward/spec/diagrams/reward-program/reward-program.plantuml +++ /dev/null @@ -1,21 +0,0 @@ -@startuml RewardProgram - -skinparam linetype ortho -skinparam SequenceMessageAlign center -hide empty description - -state Pending -state Started -state Finished -state Expired - -[*] -down-> Pending -Finished -down-> Expired : [End Time + Offset time <= Block Time] -Pending -down-> Started : [Start Time <= Block Time] -Started -down-> Finished : [End Time <= Block Time OR\nRemaining Balance <= Minimum Rollover] - -@enduml \ No newline at end of file diff --git a/x/reward/types/action_builder.go b/x/reward/types/action_builder.go deleted file mode 100644 index e1c09407ba..0000000000 --- a/x/reward/types/action_builder.go +++ /dev/null @@ -1,273 +0,0 @@ -package types - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -var ( - _ ActionBuilder = &TransferActionBuilder{} - _ ActionBuilder = &DelegateActionBuilder{} - _ ActionBuilder = &VoteActionBuilder{} -) - -// ActionBuilder defines functions used to collect events to check against specific actions. -type ActionBuilder interface { - // GetEventCriteria returns the event criteria for this action. - GetEventCriteria() *EventCriteria - // AddEvent adds an event to this builder in preparation for checking events against the criteria. - AddEvent(eventType string, attributes *map[string][]byte) error - // CanBuild returns true if this builder has enough event information for an evaluation result. - CanBuild() bool - // BuildAction builds the action and returns an EvaluationResult. - // This should only be called when CanBuild returns true. - // This should return an error if CanBuild is false or some other error is encountered. - BuildAction() (EvaluationResult, error) - // Reset clears out any previous event data, returning the builder to it's initial state. - Reset() -} - -type TransferActionBuilder struct { - Sender sdk.AccAddress - Action string - Recipient sdk.AccAddress -} - -func (b *TransferActionBuilder) GetEventCriteria() *EventCriteria { - return NewEventCriteria([]ABCIEvent{ - { - Type: sdk.EventTypeMessage, - Attributes: map[string][]byte{ - sdk.AttributeKeyAction: []byte(sdk.MsgTypeURL(&banktypes.MsgSend{})), - }, - }, - { - Type: banktypes.EventTypeTransfer, - Attributes: map[string][]byte{}, - }, - }) -} - -func (b *TransferActionBuilder) AddEvent(eventType string, attributes *map[string][]byte) error { - switch eventType { - case sdk.EventTypeMessage: - // Update the result with the senders address - address := (*attributes)[banktypes.AttributeKeySender] - action := (*attributes)[sdk.AttributeKeyAction] - if address != nil { - address, err := sdk.AccAddressFromBech32(string(address)) - if err != nil { - return err - } - b.Sender = address - } - - if action != nil { - b.Action = string(action) - } - case banktypes.EventTypeTransfer: - // Update the result with the senders address - address := (*attributes)[banktypes.AttributeKeySender] - addressSenderAddr, err := sdk.AccAddressFromBech32(string(address)) - if err != nil { - return err - } - b.Sender = addressSenderAddr - - addressRecipient := (*attributes)[banktypes.AttributeKeyRecipient] - addressRecipientAddr, errFromParsingRecipientAddress := sdk.AccAddressFromBech32(string(addressRecipient)) - if errFromParsingRecipientAddress != nil { - return errFromParsingRecipientAddress - } - b.Recipient = addressRecipientAddr - } - return nil -} - -func (b *TransferActionBuilder) CanBuild() bool { - return !b.Sender.Empty() && !(len(b.Action) == 0) && !b.Recipient.Empty() -} - -func (b *TransferActionBuilder) BuildAction() (EvaluationResult, error) { - if !b.CanBuild() { - return EvaluationResult{}, fmt.Errorf("missing sender or recipient or action from transfer action") - } - - result := EvaluationResult{ - Shares: 1, - Address: b.Sender, - Recipient: b.Recipient, - } - - return result, nil -} - -func (b *TransferActionBuilder) Reset() { - b.Sender = sdk.AccAddress{} -} - -type DelegateActionBuilder struct { - Validator sdk.ValAddress - Delegator sdk.AccAddress -} - -func (b *DelegateActionBuilder) GetEventCriteria() *EventCriteria { - return NewEventCriteria([]ABCIEvent{ - { - Type: sdk.EventTypeMessage, - Attributes: map[string][]byte{ - sdk.AttributeKeyModule: []byte(stakingtypes.ModuleName), - }, - }, - { - Type: stakingtypes.EventTypeDelegate, - Attributes: map[string][]byte{}, - }, - { - Type: stakingtypes.EventTypeCreateValidator, - Attributes: map[string][]byte{}, - }, - }) -} - -func (b *DelegateActionBuilder) AddEvent(eventType string, attributes *map[string][]byte) error { - switch eventType { - case stakingtypes.EventTypeDelegate: - address := (*attributes)[stakingtypes.AttributeKeyValidator] - validator, err := sdk.ValAddressFromBech32(string(address)) - if err != nil { - return err - } - b.Validator = validator - case stakingtypes.EventTypeCreateValidator: - address := (*attributes)[stakingtypes.AttributeKeyValidator] - validator, err := sdk.ValAddressFromBech32(string(address)) - if err != nil { - return err - } - b.Validator = validator - case sdk.EventTypeMessage: - // Update the last result to have the delegator's address - address := (*attributes)[banktypes.AttributeKeySender] - address, err := sdk.AccAddressFromBech32(string(address)) - if err != nil { - return err - } - b.Delegator = address - } - - return nil -} - -func (b *DelegateActionBuilder) CanBuild() bool { - return !b.Validator.Empty() && !b.Delegator.Empty() -} - -func (b *DelegateActionBuilder) BuildAction() (EvaluationResult, error) { - if !b.CanBuild() { - return EvaluationResult{}, fmt.Errorf("missing delegator or validator from delegate action") - } - - result := EvaluationResult{ - Shares: 1, - Address: b.Delegator, - Delegator: b.Delegator, - Validator: b.Validator, - } - - return result, nil -} - -func (b *DelegateActionBuilder) Reset() { - b.Validator = sdk.ValAddress{} - b.Delegator = sdk.AccAddress{} -} - -type VoteActionBuilder struct { - Voter sdk.AccAddress - Voted bool -} - -func (v *VoteActionBuilder) CanBuild() bool { - return !v.Voter.Empty() && v.Voted -} - -func (v *VoteActionBuilder) BuildAction() (EvaluationResult, error) { - if !v.CanBuild() { - return EvaluationResult{}, fmt.Errorf("missing voter address from vote action") - } - - result := EvaluationResult{ - Shares: 1, - Address: v.Voter, - } - - return result, nil -} - -func (v *VoteActionBuilder) Reset() { - v.Voter = sdk.AccAddress{} - v.Voted = false -} - -func (v *VoteActionBuilder) GetEventCriteria() *EventCriteria { - return NewEventCriteria([]ABCIEvent{ - { - Type: sdk.EventTypeMessage, - Attributes: map[string][]byte{sdk.AttributeKeyModule: []byte("governance")}, // TODO[1760]: reward: Ensure "governance" is still correct here. - }, - { - Type: sdk.EventTypeMessage, - Attributes: map[string][]byte{sdk.AttributeKeyAction: nil}, - }, - }) -} - -// govVoteMsgURLs the MsgURLs of all the governance module's vote messages. -// Use getGovVoteMsgURLs() instead of using this variable directly. -var govVoteMsgURLs []string - -// getGovVoteMsgURLs returns govVoteMsgURLs, but first sets it if it hasn't yet been set. -func getGovVoteMsgURLs() []string { - // Checking for nil here (as opposed to len == 0) because we only want to set it - // if it hasn't been set yet. - if govVoteMsgURLs == nil { - // sdk.MsgTypeURL sometimes uses reflection and/or proto registration. - // So govVoteMsgURLs is only set when it's finally needed in the hopes - // that everything's wired up as needed by then. - govVoteMsgURLs = []string{ - sdk.MsgTypeURL(&govtypesv1.MsgVote{}), - sdk.MsgTypeURL(&govtypesv1.MsgVoteWeighted{}), - sdk.MsgTypeURL(&govtypesv1beta1.MsgVote{}), - sdk.MsgTypeURL(&govtypesv1beta1.MsgVoteWeighted{}), - } - } - return govVoteMsgURLs -} - -func (v *VoteActionBuilder) AddEvent(_ string, attributes *map[string][]byte) error { - if _, ok := (*attributes)[sdk.AttributeKeyModule]; ok { - address := (*attributes)[banktypes.AttributeKeySender] - address, err := sdk.AccAddressFromBech32(string(address)) - if err != nil { - return err - } - v.Voter = address - } - if action, ok := (*attributes)[sdk.AttributeKeyAction]; ok { - a := string(action) - for _, m := range getGovVoteMsgURLs() { - if a == m { - v.Voted = true - break - } - } - } - - return nil -} diff --git a/x/reward/types/action_builder_test.go b/x/reward/types/action_builder_test.go deleted file mode 100644 index 6fea63d785..0000000000 --- a/x/reward/types/action_builder_test.go +++ /dev/null @@ -1,133 +0,0 @@ -package types - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" -) - -type ActionBuilderTestSuite struct { - suite.Suite -} - -func TestActionBuilderTestSuite(t *testing.T) { - suite.Run(t, new(ActionBuilderTestSuite)) -} - -func (s *ActionBuilderTestSuite) SetupSuite() { - s.T().Parallel() -} - -func (s *ActionBuilderTestSuite) TestDelegateActionGetEventCriteria() { - builder := DelegateActionBuilder{} - criteria := builder.GetEventCriteria() - - s.Assert().Contains(criteria.Events, "message", "must contain message event") - s.Assert().Contains(criteria.Events["message"].Attributes, "module", "must contain module attribute") - s.Assert().Contains(criteria.Events, "delegate", "must contain delegate event") - s.Assert().Contains(criteria.Events, "create_validator", "must contain create_validator event") -} - -func (s *ActionBuilderTestSuite) TestDelegateActionAddEventDelegate() { - builder := DelegateActionBuilder{} - - err := builder.AddEvent("delegate", &map[string][]byte{ - "validator": []byte("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun"), - }) - s.Assert().NoError(err, "add event should not return an error") - validator_address, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - s.Assert().Equal(validator_address, builder.Validator, "validator address should be set") - - err = builder.AddEvent("delegate", &map[string][]byte{ - "validator": []byte("blah"), - }) - s.Assert().Error(err, "add event should return error on invalid validator address") -} - -func (s *ActionBuilderTestSuite) TestDelegateActionAddEventCreateValidator() { - builder := DelegateActionBuilder{} - - err := builder.AddEvent("create_validator", &map[string][]byte{ - "validator": []byte("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun"), - }) - s.Assert().NoError(err, "add event should not return an error") - validator_address, _ := sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - s.Assert().Equal(validator_address, builder.Validator, "validator address should be set") - - err = builder.AddEvent("create_validator", &map[string][]byte{ - "validator": []byte("blah"), - }) - s.Assert().Error(err, "add event should return error on invalid validator address") -} - -func (s *ActionBuilderTestSuite) TestDelegateActionAddEventMessage() { - builder := DelegateActionBuilder{} - - err := builder.AddEvent("message", &map[string][]byte{ - "sender": []byte("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h"), - }) - s.Assert().NoError(err, "add event should not return an error") - delegator_address, _ := sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - s.Assert().Equal(delegator_address, builder.Delegator, "delegator address should be set") - - err = builder.AddEvent("message", &map[string][]byte{ - "sender": []byte("blah"), - }) - s.Assert().Error(err, "add event should return error on invalid delegator address") -} - -func (s *ActionBuilderTestSuite) TestDelegateActionAddEventInvalid() { - builder := DelegateActionBuilder{} - - err := builder.AddEvent("blah", &map[string][]byte{}) - s.Assert().NoError(err, "add event should not return an error") - s.Assert().True(builder.Delegator.Empty(), "delegator should not be set") - s.Assert().True(builder.Validator.Empty(), "validator should not be set") -} - -func (s *ActionBuilderTestSuite) TestReset() { - builder := DelegateActionBuilder{} - builder.Delegator, _ = sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - builder.Validator, _ = sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - builder.Reset() - s.Assert().True(builder.Delegator.Empty(), "reset should remove delegator address") - s.Assert().True(builder.Validator.Empty(), "reset should remove validator address") -} - -func (s *ActionBuilderTestSuite) TestCanBuildSuccess() { - builder := DelegateActionBuilder{} - builder.Delegator, _ = sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - builder.Validator, _ = sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - s.Assert().True(builder.CanBuild()) -} - -func (s *ActionBuilderTestSuite) TestCanBuildFailure() { - builder := DelegateActionBuilder{} - s.Assert().False(builder.CanBuild()) - - builder.Validator, _ = sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - s.Assert().False(builder.CanBuild()) - - builder.Reset() - builder.Delegator, _ = sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - s.Assert().False(builder.CanBuild()) -} - -func (s *ActionBuilderTestSuite) TestBuildActionValid() { - builder := DelegateActionBuilder{} - builder.Delegator, _ = sdk.AccAddressFromBech32("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") - builder.Validator, _ = sdk.ValAddressFromBech32("cosmosvaloper15ky9du8a2wlstz6fpx3p4mqpjyrm5cgqh6tjun") - result, err := builder.BuildAction() - s.Assert().NoError(err, "builder should not return an error on successful build") - s.Assert().Equal(int64(1), result.Shares, "1 share should be returned") - s.Assert().Equal(builder.Delegator, result.Address, "address should be set to delegator address") - s.Assert().Equal(builder.Delegator, result.Delegator, "delegator should be set to delegator address") - s.Assert().Equal(builder.Validator, result.Validator, "validator should be set to validator address") -} - -func (s *ActionBuilderTestSuite) TestBuildActionInvalid() { - builder := DelegateActionBuilder{} - _, err := builder.BuildAction() - s.Assert().Error(err, "builder should return error on unsuccessful build") -} diff --git a/x/reward/types/codec.go b/x/reward/types/codec.go deleted file mode 100644 index eff5a4ee75..0000000000 --- a/x/reward/types/codec.go +++ /dev/null @@ -1,32 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// ignoring RegisterLegacyAminoCodec registers all the necessary types and interfaces for the -// double check -func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - registry.RegisterImplementations( - (*RewardAction)(nil), - &ActionTransfer{}, - &ActionDelegate{}, - &ActionVote{}, - ) - - registry.RegisterImplementations( - (*sdk.Msg)(nil), - &MsgCreateRewardProgramRequest{}, - &MsgEndRewardProgramRequest{}, - &MsgClaimRewardsRequest{}, - &MsgClaimAllRewardsRequest{}, - ) -} - -var ( - // moving to protoCodec since this is a new module and should not use the - // amino codec..someone to double verify - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) diff --git a/x/reward/types/errors.go b/x/reward/types/errors.go deleted file mode 100644 index 69a4fbcb19..0000000000 --- a/x/reward/types/errors.go +++ /dev/null @@ -1,13 +0,0 @@ -package types - -import ( - cerrs "cosmossdk.io/errors" -) - -// x/rewards module errors -var ( - ErrIterateAllRewardAccountStates = cerrs.Register(ModuleName, 2, "error iterating all reward account states") - ErrRewardProgramNotFound = cerrs.Register(ModuleName, 3, "reward program not found") - ErrEndRewardProgramNotAuthorized = cerrs.Register(ModuleName, 4, "not authorized to end the reward program") - ErrEndrewardProgramIncorrectState = cerrs.Register(ModuleName, 5, "unable to end a reward program that is finished or expired") -) diff --git a/x/reward/types/events.go b/x/reward/types/events.go deleted file mode 100644 index bce4755994..0000000000 --- a/x/reward/types/events.go +++ /dev/null @@ -1,22 +0,0 @@ -package types - -const ( - // The type of event generated when a reward program is created - EventTypeRewardProgramCreated string = "reward_program_created" - // The type of event generated when a reward program is started - EventTypeRewardProgramStarted string = "reward_program_started" - // The type of event generated when a reward program is ended - EventTypeRewardProgramFinished string = "reward_program_finished" - // The type of event generated when a reward program is started - EventTypeRewardProgramExpired string = "reward_program_expired" - // The type of event generated when a reward program is ended - EventTypeRewardProgramEnded string = "reward_program_ended" - // The type of event generated when a address claims rewards - EventTypeClaimRewards string = "claim_rewards" - // The type of event generated when a address claims all their rewards - EventTypeClaimAllRewards string = "claim_all_rewards" - - AttributeKeyRewardProgramID string = "reward_program_id" - AttributeKeyRewardProgramIDs string = "reward_program_ids" - AttributeKeyRewardsClaimAddress string = "rewards_claim_address" -) diff --git a/x/reward/types/expected_keepers.go b/x/reward/types/expected_keepers.go deleted file mode 100644 index c0ec4e6314..0000000000 --- a/x/reward/types/expected_keepers.go +++ /dev/null @@ -1,28 +0,0 @@ -package types - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// StakingKeeper defines a subset of methods implemented by the cosmos-sdk staking keeper -type StakingKeeper interface { - GetAllDelegatorDelegations(ctx context.Context, delegator sdk.AccAddress) ([]stakingtypes.Delegation, error) - GetBondedValidatorsByPower(ctx context.Context) ([]stakingtypes.Validator, error) - GetLastValidatorPower(ctx context.Context, operator sdk.ValAddress) (power int64, err error) - GetValidator(ctx context.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, err error) - GetDelegation(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation stakingtypes.Delegation, err error) -} - -// AccountKeeper defines the contract needed for AccountKeeper related APIs. -// Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators. -type AccountKeeper interface { - GetModuleAddress(moduleName string) sdk.AccAddress -} - -type KeeperProvider interface { - GetStakingKeeper() StakingKeeper - GetAccountKeeper() AccountKeeper -} diff --git a/x/reward/types/genesis.go b/x/reward/types/genesis.go deleted file mode 100644 index dd12be8fb7..0000000000 --- a/x/reward/types/genesis.go +++ /dev/null @@ -1,54 +0,0 @@ -package types - -import "fmt" - -func NewGenesisState( - rewardProgramID uint64, - rewardProgram []RewardProgram, - claimPeriodRewardDistributions []ClaimPeriodRewardDistribution, - rewardAccountStates []RewardAccountState, -) *GenesisState { - return &GenesisState{ - RewardProgramId: rewardProgramID, - RewardPrograms: rewardProgram, - ClaimPeriodRewardDistributions: claimPeriodRewardDistributions, - RewardAccountStates: rewardAccountStates, - } -} - -// DefaultGenesis returns the default reward genesis state -func DefaultGenesis() *GenesisState { - return NewGenesisState( - uint64(1), - []RewardProgram{}, - []ClaimPeriodRewardDistribution{}, - []RewardAccountState{}, - ) -} - -// Validate performs basic genesis state validation returning an error upon any -// failure. -func (gs GenesisState) Validate() error { - for _, rewardProgram := range gs.RewardPrograms { - if rewardProgram.Id >= gs.RewardProgramId { - return fmt.Errorf("reward program id (%v) must not equal or be less than a current reward program id (%v)", gs.RewardProgramId, rewardProgram.Id) - } - if err := rewardProgram.Validate(); err != nil { - return err - } - } - - for _, claimPeriodRewardDistributions := range gs.ClaimPeriodRewardDistributions { - if err := claimPeriodRewardDistributions.Validate(); err != nil { - return err - } - } - - for _, rewardsAccountStates := range gs.RewardAccountStates { - if err := rewardsAccountStates.Validate(); err != nil { - return err - } - } - - return nil -} diff --git a/x/reward/types/genesis.pb.go b/x/reward/types/genesis.pb.go deleted file mode 100644 index 745d97d365..0000000000 --- a/x/reward/types/genesis.pb.go +++ /dev/null @@ -1,476 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: provenance/reward/v1/genesis.proto - -package types - -import ( - fmt "fmt" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// GenesisState defines the reward module's genesis state. -type GenesisState struct { - // Reward program id is the next auto incremented id to be assigned to the next created reward program - RewardProgramId uint64 `protobuf:"varint,1,opt,name=reward_program_id,json=rewardProgramId,proto3" json:"reward_program_id,omitempty"` - // Reward programs to initially start with. - RewardPrograms []RewardProgram `protobuf:"bytes,2,rep,name=reward_programs,json=rewardPrograms,proto3" json:"reward_programs"` - // Claim period reward distributions to initially start with. - ClaimPeriodRewardDistributions []ClaimPeriodRewardDistribution `protobuf:"bytes,3,rep,name=claim_period_reward_distributions,json=claimPeriodRewardDistributions,proto3" json:"claim_period_reward_distributions"` - // Reward account states to initially start with. - RewardAccountStates []RewardAccountState `protobuf:"bytes,4,rep,name=reward_account_states,json=rewardAccountStates,proto3" json:"reward_account_states"` -} - -func (m *GenesisState) Reset() { *m = GenesisState{} } -func (m *GenesisState) String() string { return proto.CompactTextString(m) } -func (*GenesisState) ProtoMessage() {} -func (*GenesisState) Descriptor() ([]byte, []int) { - return fileDescriptor_1a6ae988552967a2, []int{0} -} -func (m *GenesisState) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *GenesisState) XXX_Merge(src proto.Message) { - xxx_messageInfo_GenesisState.Merge(m, src) -} -func (m *GenesisState) XXX_Size() int { - return m.Size() -} -func (m *GenesisState) XXX_DiscardUnknown() { - xxx_messageInfo_GenesisState.DiscardUnknown(m) -} - -var xxx_messageInfo_GenesisState proto.InternalMessageInfo - -func init() { - proto.RegisterType((*GenesisState)(nil), "provenance.reward.v1.GenesisState") -} - -func init() { - proto.RegisterFile("provenance/reward/v1/genesis.proto", fileDescriptor_1a6ae988552967a2) -} - -var fileDescriptor_1a6ae988552967a2 = []byte{ - // 347 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xbd, 0x4e, 0xf3, 0x30, - 0x14, 0x86, 0xe3, 0xaf, 0xd5, 0x27, 0x64, 0x10, 0x15, 0xa1, 0x88, 0xa8, 0x83, 0xfb, 0xc3, 0x52, - 0x21, 0x91, 0xa8, 0xed, 0xc6, 0x46, 0x41, 0x42, 0x6c, 0x55, 0xd8, 0x58, 0xa2, 0xfc, 0x58, 0xc6, - 0x12, 0xcd, 0x89, 0x6c, 0xb7, 0xc0, 0x0c, 0x03, 0x23, 0x97, 0xd0, 0xcb, 0xe9, 0xd8, 0x91, 0x09, - 0xa1, 0x76, 0xe1, 0x32, 0x50, 0xed, 0xa0, 0xb6, 0x22, 0xea, 0x96, 0xf8, 0x3c, 0xef, 0x79, 0xec, - 0x73, 0x70, 0x2b, 0x13, 0x30, 0xa6, 0x69, 0x98, 0xc6, 0xd4, 0x13, 0xf4, 0x31, 0x14, 0x89, 0x37, - 0xee, 0x78, 0x8c, 0xa6, 0x54, 0x72, 0xe9, 0x66, 0x02, 0x14, 0xd8, 0xd5, 0x15, 0xe3, 0x1a, 0xc6, - 0x1d, 0x77, 0x6a, 0x55, 0x06, 0x0c, 0x34, 0xe0, 0x2d, 0xbf, 0x0c, 0x5b, 0x6b, 0x16, 0xf6, 0xcb, - 0x53, 0x1a, 0x69, 0xbd, 0x94, 0xf0, 0xde, 0xb5, 0x11, 0xdc, 0xaa, 0x50, 0x51, 0xfb, 0x14, 0x1f, - 0x18, 0x20, 0xc8, 0x04, 0x30, 0x11, 0x0e, 0x03, 0x9e, 0x38, 0xa8, 0x81, 0xda, 0x65, 0xbf, 0x62, - 0x0a, 0x03, 0x73, 0x7e, 0x93, 0xd8, 0x3e, 0xae, 0x6c, 0xb2, 0xd2, 0xf9, 0xd7, 0x28, 0xb5, 0x77, - 0xbb, 0x27, 0x6e, 0xd1, 0x2d, 0x5d, 0x7f, 0x3d, 0xdf, 0x2f, 0x4f, 0x3f, 0xeb, 0x96, 0xbf, 0xbf, - 0xd1, 0x54, 0xda, 0xaf, 0x08, 0x37, 0xe3, 0x87, 0x90, 0x0f, 0x83, 0x8c, 0x0a, 0x0e, 0x49, 0x90, - 0x1b, 0x12, 0x2e, 0x95, 0xe0, 0xd1, 0x48, 0x71, 0x48, 0xa5, 0x53, 0xd2, 0x9a, 0x5e, 0xb1, 0xe6, - 0x72, 0x19, 0x1f, 0xe8, 0xb4, 0x31, 0x5e, 0xad, 0x65, 0x73, 0x2d, 0x89, 0xb7, 0x41, 0xd2, 0x8e, - 0xf0, 0x51, 0x2e, 0x0e, 0xe3, 0x18, 0x46, 0xa9, 0x0a, 0xe4, 0x72, 0x3c, 0xd2, 0x29, 0x6b, 0x73, - 0x7b, 0xdb, 0x03, 0x2f, 0x4c, 0x42, 0xcf, 0x33, 0xd7, 0x1d, 0x8a, 0x3f, 0x15, 0x79, 0xbe, 0xf3, - 0x36, 0xa9, 0x5b, 0xdf, 0x93, 0xba, 0xd5, 0x67, 0xd3, 0x39, 0x41, 0xb3, 0x39, 0x41, 0x5f, 0x73, - 0x82, 0xde, 0x17, 0xc4, 0x9a, 0x2d, 0x88, 0xf5, 0xb1, 0x20, 0x16, 0x3e, 0xe6, 0x50, 0xa8, 0x1a, - 0xa0, 0xbb, 0x2e, 0xe3, 0xea, 0x7e, 0x14, 0xb9, 0x31, 0x0c, 0xbd, 0x15, 0x72, 0xc6, 0x61, 0xed, - 0xcf, 0x7b, 0xfa, 0x5d, 0xbc, 0x7a, 0xce, 0xa8, 0x8c, 0xfe, 0xeb, 0xad, 0xf7, 0x7e, 0x02, 0x00, - 0x00, 0xff, 0xff, 0x7f, 0xc3, 0x5a, 0x03, 0x6a, 0x02, 0x00, 0x00, -} - -func (m *GenesisState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.RewardAccountStates) > 0 { - for iNdEx := len(m.RewardAccountStates) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.RewardAccountStates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } - if len(m.ClaimPeriodRewardDistributions) > 0 { - for iNdEx := len(m.ClaimPeriodRewardDistributions) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ClaimPeriodRewardDistributions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if len(m.RewardPrograms) > 0 { - for iNdEx := len(m.RewardPrograms) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.RewardPrograms[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - if m.RewardProgramId != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.RewardProgramId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { - offset -= sovGenesis(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *GenesisState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardProgramId != 0 { - n += 1 + sovGenesis(uint64(m.RewardProgramId)) - } - if len(m.RewardPrograms) > 0 { - for _, e := range m.RewardPrograms { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.ClaimPeriodRewardDistributions) > 0 { - for _, e := range m.ClaimPeriodRewardDistributions { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.RewardAccountStates) > 0 { - for _, e := range m.RewardAccountStates { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - return n -} - -func sovGenesis(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGenesis(x uint64) (n int) { - return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *GenesisState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgramId", wireType) - } - m.RewardProgramId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardProgramId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardPrograms", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardPrograms = append(m.RewardPrograms, RewardProgram{}) - if err := m.RewardPrograms[len(m.RewardPrograms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodRewardDistributions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClaimPeriodRewardDistributions = append(m.ClaimPeriodRewardDistributions, ClaimPeriodRewardDistribution{}) - if err := m.ClaimPeriodRewardDistributions[len(m.ClaimPeriodRewardDistributions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardAccountStates", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardAccountStates = append(m.RewardAccountStates, RewardAccountState{}) - if err := m.RewardAccountStates[len(m.RewardAccountStates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipGenesis(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthGenesis - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupGenesis - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthGenesis - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/reward/types/genesis_test.go b/x/reward/types/genesis_test.go deleted file mode 100644 index 17b1848d3e..0000000000 --- a/x/reward/types/genesis_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package types - -import ( - "testing" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" -) - -type RewardGenesisTypesTestSuite struct { - suite.Suite -} - -func TestRewardGenesisTypesTestSuite(t *testing.T) { - suite.Run(t, new(RewardGenesisTypesTestSuite)) -} - -func (s *RewardGenesisTypesTestSuite) SetupSuite() { - s.T().Parallel() -} - -func (s *RewardGenesisTypesTestSuite) TestGenesisValidate() { - now := time.Now() - claimPeriodSeconds := uint64(1000) - claimPeriods := uint64(100) - maxRolloverPeriods := uint64(10) - expireClaimPeriods := uint64(100000) - - rewardProgram := NewRewardProgram( - "title", - "description", - 1, - "", - sdk.NewInt64Coin("nhash", 100), - sdk.NewInt64Coin("nhash", 100), - now, - claimPeriodSeconds, - claimPeriods, - maxRolloverPeriods, - expireClaimPeriods, - []QualifyingAction{ - { - Type: &QualifyingAction_Vote{ - Vote: &ActionVote{ - MinimumActions: uint64(1), - MaximumActions: uint64(10), - MinimumDelegationAmount: sdk.NewInt64Coin("nhash", 100), - }, - }, - }, - }, - ) - s.Assert().Error(NewGenesisState(10, []RewardProgram{rewardProgram}, []ClaimPeriodRewardDistribution{}, []RewardAccountState{}).Validate(), "should fail on validation of reward program") - - // make reward program valid - rewardProgram.DistributeFromAddress = "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h" - s.Assert().Error(NewGenesisState(1, []RewardProgram{rewardProgram}, []ClaimPeriodRewardDistribution{}, []RewardAccountState{}).Validate(), "should fail on validation of reward program id") - - invalidClaimPeriod := NewClaimPeriodRewardDistribution(0, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 0, false) - s.Assert().Error(NewGenesisState(10, []RewardProgram{rewardProgram}, []ClaimPeriodRewardDistribution{invalidClaimPeriod}, []RewardAccountState{}).Validate(), "should fail on validation on claim period") - - validClaimPeriod := NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 1), sdk.NewInt64Coin("nhash", 1), 0, false) - invalidRewardState := NewRewardAccountState( - 1, - 2, - "test", - 0, - []*ActionCounter{}, - ) - s.Assert().Error(NewGenesisState(10, []RewardProgram{rewardProgram}, []ClaimPeriodRewardDistribution{validClaimPeriod}, []RewardAccountState{invalidRewardState}).Validate(), "should fail on validation on reward state") - - validRewardState := NewRewardAccountState( - 1, - 2, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - 0, - []*ActionCounter{}, - ) - s.Assert().NoError(NewGenesisState(10, []RewardProgram{rewardProgram}, []ClaimPeriodRewardDistribution{validClaimPeriod}, []RewardAccountState{validRewardState}).Validate(), "should pass all validations") - -} diff --git a/x/reward/types/keys.go b/x/reward/types/keys.go deleted file mode 100644 index 4a721aa2fd..0000000000 --- a/x/reward/types/keys.go +++ /dev/null @@ -1,175 +0,0 @@ -package types - -import ( - "encoding/binary" - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" -) - -const ( - // ModuleName defines the module name - ModuleName = "reward" - - // StoreKey defines the primary module store key - StoreKey = ModuleName - - // RouterKey is the message route for slashing - RouterKey = ModuleName - - RewardIDKeyLength = 8 - ClaimPeriodIDLength = 8 -) - -var ( - RewardProgramKeyPrefix = []byte{0x01} - RewardProgramIDKey = []byte{0x02} - ClaimPeriodRewardDistributionKeyPrefix = []byte{0x03} - AccountStateAddressLookupKeyPrefix = []byte{0x04} - AccountStateKeyPrefix = []byte{0x05} -) - -// GetRewardProgramKey converts a name into key format. -func GetRewardProgramKey(id uint64) []byte { - rewardIDBytes := make([]byte, RewardIDKeyLength) - binary.BigEndian.PutUint64(rewardIDBytes, id) - return append(RewardProgramKeyPrefix, rewardIDBytes...) -} - -// GetRewardAccountStateKey converts a reward program id, claim period id, and address into an AccountStateKey -func GetRewardAccountStateKey(rewardID uint64, rewardClaimPeriodID uint64, addr sdk.AccAddress) []byte { - key := AccountStateKeyPrefix - rewardBytes := make([]byte, RewardIDKeyLength) - claimPeriodBytes := make([]byte, ClaimPeriodIDLength) - binary.BigEndian.PutUint64(rewardBytes, rewardID) - binary.BigEndian.PutUint64(claimPeriodBytes, rewardClaimPeriodID) - key = append(key, rewardBytes...) - key = append(key, claimPeriodBytes...) - key = append(key, address.MustLengthPrefix(addr)...) - return key -} - -// GetRewardAccountStateAddressLookupKey facilitates lookup of AccountState via address -func GetRewardAccountStateAddressLookupKey(addr sdk.AccAddress, rewardID uint64, rewardClaimPeriodID uint64) []byte { - key := AccountStateAddressLookupKeyPrefix - rewardBytes := make([]byte, RewardIDKeyLength) - claimPeriodBytes := make([]byte, ClaimPeriodIDLength) - binary.BigEndian.PutUint64(rewardBytes, rewardID) - binary.BigEndian.PutUint64(claimPeriodBytes, rewardClaimPeriodID) - key = append(key, address.MustLengthPrefix(addr)...) - key = append(key, rewardBytes...) - key = append(key, claimPeriodBytes...) - return key -} - -// GetRewardAccountStateClaimPeriodKey converts a reward program id and claim period into a prefix for iterating -func GetRewardAccountStateClaimPeriodKey(rewardID uint64, rewardClaimPeriodID uint64) []byte { - key := AccountStateKeyPrefix - rewardBytes := make([]byte, RewardIDKeyLength) - claimPeriodBytes := make([]byte, ClaimPeriodIDLength) - binary.BigEndian.PutUint64(rewardBytes, rewardID) - binary.BigEndian.PutUint64(claimPeriodBytes, rewardClaimPeriodID) - key = append(key, rewardBytes...) - key = append(key, claimPeriodBytes...) - return key -} - -// GetRewardProgramRewardAccountStateKey returns the key to iterate over all RewardAccountStates for a RewardProgram -func GetRewardProgramRewardAccountStateKey(rewardID uint64) []byte { - key := AccountStateKeyPrefix - rewardBytes := make([]byte, RewardIDKeyLength) - binary.BigEndian.PutUint64(rewardBytes, rewardID) - key = append(key, rewardBytes...) - return key -} - -// GetAllRewardAccountStateKey returns the key to iterate over all AccountStates -func GetAllRewardAccountStateKey() []byte { - key := AccountStateKeyPrefix - return key -} - -// GetRewardProgramIDBytes returns the byte representation of the rewardprogramID -func GetRewardProgramIDBytes(rewardprogramID uint64) (rewardprogramIDBz []byte) { - rewardprogramIDBz = make([]byte, RewardIDKeyLength) - binary.BigEndian.PutUint64(rewardprogramIDBz, rewardprogramID) - return -} - -// GetRewardProgramIDFromBytes returns rewardprogramID in uint64 format from a byte array -func GetRewardProgramIDFromBytes(bz []byte) (rewardprogramID uint64) { - return binary.BigEndian.Uint64(bz) -} - -// GetClaimPeriodRewardDistributionKey returns claim period reward distribution key -func GetClaimPeriodRewardDistributionKey(claimID uint64, rewardID uint64) []byte { - claimBytes := make([]byte, 8) - rewardBytes := make([]byte, 8) - key := ClaimPeriodRewardDistributionKeyPrefix - binary.BigEndian.PutUint64(rewardBytes, rewardID) - binary.BigEndian.PutUint64(claimBytes, claimID) - key = append(key, rewardBytes...) - return append(key, claimBytes...) -} - -// GetAllRewardAccountByAddressPartialKey returns the key to iterate over all AccountStateAddressLookup by address -func GetAllRewardAccountByAddressPartialKey(addr sdk.AccAddress) []byte { - key := AccountStateAddressLookupKeyPrefix - key = append(key, address.MustLengthPrefix(addr)...) - return key -} - -// GetAllRewardAccountByAddressAndRewardsIDPartialKey returns the key to iterate over all AccountStateAddressLookup by address and rewards id -func GetAllRewardAccountByAddressAndRewardsIDPartialKey(addr sdk.AccAddress, rewardID uint64) []byte { - key := AccountStateAddressLookupKeyPrefix - rewardBytes := make([]byte, RewardIDKeyLength) - binary.BigEndian.PutUint64(rewardBytes, rewardID) - key = append(key, address.MustLengthPrefix(addr.Bytes())...) - key = append(key, rewardBytes...) - return key -} - -// MustAccAddressFromBech32 converts a Bech32 address to sdk.AccAddress -// Panics on error -func MustAccAddressFromBech32(s string) sdk.AccAddress { - accAddress, err := sdk.AccAddressFromBech32(s) - if err != nil { - panic(err) - } - return accAddress -} - -// ParseFilterLookUpKey splits the provided key into a reward id and claim id and returns them in a RewardAccountLookup along with the provided address. -func ParseFilterLookUpKey(accountStateAddressLookupKey []byte, addr sdk.AccAddress) (RewardAccountLookup, error) { - rewardID := binary.BigEndian.Uint64(accountStateAddressLookupKey[0:8]) - claimID := binary.BigEndian.Uint64(accountStateAddressLookupKey[8:16]) - return RewardAccountLookup{ - Addr: addr, - RewardID: rewardID, - ClaimID: claimID, - }, nil -} - -// ParseRewardAccountLookUpKey parse key generated like via GetRewardAccountStateAddressLookupKey(address, rewardProgramId, claimPeriodId) -func ParseRewardAccountLookUpKey(accountStateAddressLookupKey []byte, addr sdk.AccAddress) (RewardAccountLookup, error) { - // address length is stored in first byte - lengthOfAddress := int64(accountStateAddressLookupKey[1:2][0]) - address := sdk.AccAddress(accountStateAddressLookupKey[2 : lengthOfAddress+2]) - if !addr.Equals(address) { - return RewardAccountLookup{}, fmt.Errorf("addresses do not match up") - } - rewardID := binary.BigEndian.Uint64(accountStateAddressLookupKey[lengthOfAddress+2 : lengthOfAddress+2+RewardIDKeyLength]) - claimID := binary.BigEndian.Uint64(accountStateAddressLookupKey[lengthOfAddress+2+RewardIDKeyLength : lengthOfAddress+2+RewardIDKeyLength+ClaimPeriodIDLength]) - return RewardAccountLookup{ - Addr: addr, - RewardID: rewardID, - ClaimID: claimID, - }, nil -} - -type RewardAccountLookup struct { - Addr sdk.Address - RewardID uint64 - ClaimID uint64 -} diff --git a/x/reward/types/keys_test.go b/x/reward/types/keys_test.go deleted file mode 100644 index 3c9404dcfe..0000000000 --- a/x/reward/types/keys_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package types - -import ( - "encoding/binary" - "testing" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/cosmos-sdk/types/address" - "github.com/stretchr/testify/assert" -) - -func TestRewardModuleTypeKeys(t *testing.T) { - addressFromSec256k1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - rewardProgramId := uint64(123456) - claimPeriodId := uint64(7891011) - - rewardProgramKey := GetRewardProgramKey(rewardProgramId) - assert.EqualValues(t, RewardProgramKeyPrefix, rewardProgramKey[0:1]) - assert.EqualValues(t, rewardProgramId, uint64(binary.BigEndian.Uint64(rewardProgramKey[1:9]))) - - accountStateKey := GetRewardAccountStateKey(rewardProgramId, claimPeriodId, addressFromSec256k1) - assert.EqualValues(t, AccountStateKeyPrefix, accountStateKey[0:1]) - assert.EqualValues(t, rewardProgramId, uint64(binary.BigEndian.Uint64(accountStateKey[1:9]))) - assert.EqualValues(t, claimPeriodId, uint64(binary.BigEndian.Uint64(accountStateKey[9:17]))) - assert.EqualValues(t, address.MustLengthPrefix(addressFromSec256k1), accountStateKey[17:]) - - rewardAccountStateKey := GetRewardAccountStateClaimPeriodKey(rewardProgramId, claimPeriodId) - assert.EqualValues(t, AccountStateKeyPrefix, rewardAccountStateKey[0:1]) - assert.EqualValues(t, rewardProgramId, binary.BigEndian.Uint64(rewardAccountStateKey[1:9])) - assert.EqualValues(t, claimPeriodId, binary.BigEndian.Uint64(rewardAccountStateKey[9:17])) - - rewardProgramRewardAccountStateKey := GetRewardProgramRewardAccountStateKey(rewardProgramId) - assert.EqualValues(t, AccountStateKeyPrefix, rewardProgramRewardAccountStateKey[0:1]) - assert.EqualValues(t, rewardProgramId, binary.BigEndian.Uint64(rewardProgramRewardAccountStateKey[1:9])) - - allRewardAccountStateKey := GetAllRewardAccountStateKey() - assert.EqualValues(t, AccountStateKeyPrefix, allRewardAccountStateKey[0:1]) - - rewardProgramIdBytes := GetRewardProgramIDBytes(rewardProgramId) - assert.EqualValues(t, []uint8([]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0xe2, 0x40}), rewardProgramIdBytes) - - rewardIdResult := GetRewardProgramIDFromBytes([]uint8([]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0xe2, 0x40})) - assert.EqualValues(t, rewardProgramId, rewardIdResult) - - claimPeriodRewardDistributionKey := GetClaimPeriodRewardDistributionKey(claimPeriodId, rewardProgramId) - assert.EqualValues(t, ClaimPeriodRewardDistributionKeyPrefix, claimPeriodRewardDistributionKey[0:1]) - assert.EqualValues(t, rewardProgramId, binary.BigEndian.Uint64(claimPeriodRewardDistributionKey[1:9])) - assert.EqualValues(t, claimPeriodId, binary.BigEndian.Uint64(claimPeriodRewardDistributionKey[9:17])) - - accountStateAddressLookupKey := GetRewardAccountStateAddressLookupKey(addressFromSec256k1, rewardProgramId, claimPeriodId) - assert.EqualValues(t, AccountStateAddressLookupKeyPrefix, accountStateAddressLookupKey[0:1]) - - assert.Equal(t, byte(20), accountStateAddressLookupKey[1:2][0], "should be the length of key 20 for secp256k1") - assert.EqualValues(t, addressFromSec256k1.Bytes(), accountStateAddressLookupKey[2:22]) - assert.EqualValues(t, rewardProgramId, binary.BigEndian.Uint64(accountStateAddressLookupKey[22:30])) - assert.EqualValues(t, claimPeriodId, uint64(binary.BigEndian.Uint64(accountStateAddressLookupKey[30:38]))) - - rewardAccountByAddressPartial := GetAllRewardAccountByAddressPartialKey(addressFromSec256k1) - assert.Equal(t, byte(20), rewardAccountByAddressPartial[1:2][0], "should be the length of key 20 for secp256k1") - assert.EqualValues(t, AccountStateAddressLookupKeyPrefix, rewardAccountByAddressPartial[0:1]) - assert.EqualValues(t, addressFromSec256k1.Bytes(), rewardAccountByAddressPartial[2:22]) - - rewardAccountByAddressAndRewardsIDPartialKey := GetAllRewardAccountByAddressAndRewardsIDPartialKey(addressFromSec256k1, rewardProgramId) - assert.Equal(t, byte(20), rewardAccountByAddressAndRewardsIDPartialKey[1:2][0], "should be the length of key 20 for secp256k1") - assert.EqualValues(t, AccountStateAddressLookupKeyPrefix, rewardAccountByAddressAndRewardsIDPartialKey[0:1]) - assert.EqualValues(t, addressFromSec256k1.Bytes(), rewardAccountByAddressAndRewardsIDPartialKey[2:22]) - assert.EqualValues(t, rewardProgramId, binary.BigEndian.Uint64(rewardAccountByAddressAndRewardsIDPartialKey[22:30])) - -} diff --git a/x/reward/types/msgs.go b/x/reward/types/msgs.go deleted file mode 100644 index b1ef2d8fff..0000000000 --- a/x/reward/types/msgs.go +++ /dev/null @@ -1,186 +0,0 @@ -package types - -import ( - "errors" - fmt "fmt" - "strings" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// Compile time interface checks. -var _ sdk.Msg = &MsgCreateRewardProgramRequest{} -var _ sdk.Msg = &MsgEndRewardProgramRequest{} -var _ sdk.Msg = &MsgClaimRewardsRequest{} -var _ sdk.Msg = &MsgClaimAllRewardsRequest{} - -// NewMsgCreateRewardProgramRequest creates a new create reward program request -func NewMsgCreateRewardProgramRequest( - title string, - description string, - distributeFromAddress string, - totalRewardPool sdk.Coin, - maxRewardPerClaimAddress sdk.Coin, - programStartTime time.Time, - claimPeriods uint64, - claimPeriodDays uint64, - maxRolloverClaimPeriods uint64, - expireDays uint64, - qualifyingAction []QualifyingAction, -) *MsgCreateRewardProgramRequest { - return &MsgCreateRewardProgramRequest{ - Title: title, - Description: description, - DistributeFromAddress: distributeFromAddress, - TotalRewardPool: totalRewardPool, - MaxRewardPerClaimAddress: maxRewardPerClaimAddress, - ProgramStartTime: programStartTime, - ClaimPeriods: claimPeriods, - ClaimPeriodDays: claimPeriodDays, - MaxRolloverClaimPeriods: maxRolloverClaimPeriods, - ExpireDays: expireDays, - QualifyingActions: qualifyingAction, - } -} - -// ValidateBasic runs stateless validation checks on the message. -func (msg MsgCreateRewardProgramRequest) ValidateBasic() error { - title := msg.GetTitle() - if len(strings.TrimSpace(title)) == 0 { - return errors.New("reward program title cannot be blank") - } - if len(title) > MaxTitleLength { - return fmt.Errorf("reward program title is longer than max length of %d", MaxTitleLength) - } - description := msg.GetDescription() - if len(description) == 0 { - return errors.New("reward program description cannot be blank") - } - if len(description) > MaxDescriptionLength { - return fmt.Errorf("reward program description is longer than max length of %d", MaxDescriptionLength) - } - if _, err := sdk.AccAddressFromBech32(msg.DistributeFromAddress); err != nil { - return fmt.Errorf("invalid address for rewards program distribution from address: %w", err) - } - if !msg.TotalRewardPool.IsPositive() { - return fmt.Errorf("reward program requires total reward pool to be positive: %v", msg.TotalRewardPool) - } - if !msg.MaxRewardPerClaimAddress.IsPositive() { - return fmt.Errorf("reward program requires positive max reward by address: %v", msg.MaxRewardPerClaimAddress) - } - if msg.TotalRewardPool.Denom != msg.MaxRewardPerClaimAddress.Denom { - return fmt.Errorf("coin denoms differ %v : %v", msg.TotalRewardPool.Denom, msg.MaxRewardPerClaimAddress.Denom) - } - if msg.MaxRewardPerClaimAddress.Amount.GT(msg.TotalRewardPool.Amount) { - return fmt.Errorf("max claims per address cannot be larger than pool %v : %v", msg.MaxRewardPerClaimAddress.Amount, msg.TotalRewardPool.Amount) - } - if msg.ClaimPeriods < 1 || msg.ClaimPeriodDays < 1 || msg.ExpireDays < 1 { - return fmt.Errorf("claim periods (%v), claim period days (%v), and expire days (%v) must be larger than 0", msg.ClaimPeriods, msg.ClaimPeriodDays, msg.ExpireDays) - } - if len(msg.QualifyingActions) == 0 { - return fmt.Errorf("reward program must contain qualifying actions") - } - for _, action := range msg.QualifyingActions { - if err := action.Validate(); err != nil { - return err - } - } - return nil -} - -// GetSigners indicates that the message must have been signed by the parent. -func (msg MsgCreateRewardProgramRequest) GetSigners() []sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(msg.DistributeFromAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{addr} -} - -// NewMsgEndRewardProgramRequest ends a reward program request -func NewMsgEndRewardProgramRequest( - rewardProgramID uint64, - programOwnerAddress string) *MsgEndRewardProgramRequest { - return &MsgEndRewardProgramRequest{ - RewardProgramId: rewardProgramID, - ProgramOwnerAddress: programOwnerAddress, - } -} - -// ValidateBasic runs stateless validation checks on the message. -func (msg MsgEndRewardProgramRequest) ValidateBasic() error { - if msg.RewardProgramId < 1 { - return fmt.Errorf("invalid reward program id: %v", msg.RewardProgramId) - } - if _, err := sdk.AccAddressFromBech32(msg.ProgramOwnerAddress); err != nil { - return fmt.Errorf("invalid address for rewards program distribution from address: %w", err) - } - return nil -} - -// GetSigners indicates that the message must have been signed by the parent. -func (msg MsgEndRewardProgramRequest) GetSigners() []sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(msg.ProgramOwnerAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{addr} -} - -// NewMsgClaimRewardsRequest creates a new reward claim request -func NewMsgClaimRewardsRequest( - rewardProgramID uint64, - rewardAddress string, -) *MsgClaimRewardsRequest { - return &MsgClaimRewardsRequest{ - RewardProgramId: rewardProgramID, - RewardAddress: rewardAddress, - } -} - -// ValidateBasic runs stateless validation checks on the message. -func (msg MsgClaimRewardsRequest) ValidateBasic() error { - if msg.RewardProgramId < 1 { - return fmt.Errorf("invalid rewards program id : %d", msg.RewardProgramId) - } - if _, err := sdk.AccAddressFromBech32(msg.RewardAddress); err != nil { - return fmt.Errorf("invalid reward address : %w", err) - } - return nil -} - -// GetSigners indicates that the message must have been signed by the parent. -func (msg MsgClaimRewardsRequest) GetSigners() []sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(msg.RewardAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{addr} -} - -// NewMsgClaimRewardsRequest creates a new claim all request -func NewMsgClaimAllRewardsRequest( - rewardAddress string, -) *MsgClaimAllRewardsRequest { - return &MsgClaimAllRewardsRequest{ - RewardAddress: rewardAddress, - } -} - -// ValidateBasic runs stateless validation checks on the message. -func (msg MsgClaimAllRewardsRequest) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.RewardAddress); err != nil { - return fmt.Errorf("invalid reward address : %w", err) - } - return nil -} - -// GetSigners indicates that the message must have been signed by the parent. -func (msg MsgClaimAllRewardsRequest) GetSigners() []sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(msg.RewardAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{addr} -} diff --git a/x/reward/types/msgs_test.go b/x/reward/types/msgs_test.go deleted file mode 100644 index a56421f617..0000000000 --- a/x/reward/types/msgs_test.go +++ /dev/null @@ -1,434 +0,0 @@ -package types - -import ( - "testing" - time "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type RewardMsgTypesTestSuite struct { - suite.Suite -} - -func TestRewardMsgTypesTestSuite(t *testing.T) { - suite.Run(t, new(RewardMsgTypesTestSuite)) -} - -func (s *RewardMsgTypesTestSuite) SetupSuite() { - s.T().Parallel() -} - -func (s *RewardMsgTypesTestSuite) TestMsgCreateRewardProgramRequestValidateBasic() { - dateTime := time.Date(2024, 12, 2, 0, 0, 0, 0, time.UTC) - lTitle := make([]byte, MaxTitleLength+1) - longTitle := string(lTitle) - lDescription := make([]byte, MaxDescriptionLength+1) - longDescription := string(lDescription) - minimumDelegation := sdk.NewInt64Coin("nhash", 0) - maximumDelegation := sdk.NewInt64Coin("nhash", 100) - qualifyingActions := []QualifyingAction{ - { - Type: &QualifyingAction_Delegate{ - Delegate: &ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - } - tests := []struct { - name string - msgCreateRewardProgramRequest MsgCreateRewardProgramRequest - want string - }{ - { - "valid", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "", - }, - { - "invalid - blank title", - *NewMsgCreateRewardProgramRequest( - "", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "reward program title cannot be blank", - }, - { - "invalid - title too long", - *NewMsgCreateRewardProgramRequest( - longTitle, - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "reward program title is longer than max length of 140", - }, - { - "invalid - description is blank", - *NewMsgCreateRewardProgramRequest( - "title", - "", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "reward program description cannot be blank", - }, - { - "invalid - title is too long", - *NewMsgCreateRewardProgramRequest( - "title", - longDescription, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "reward program description is longer than max length of 10000", - }, - { - "invalid - address is incorrect", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "invalid", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "invalid address for rewards program distribution from address: decoding bech32 failed: invalid bech32 string length 7", - }, - { - "invalid - coin is not positive", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 0), - sdk.NewInt64Coin("jackthecat", 2), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "reward program requires total reward pool to be positive: 0jackthecat", - }, - { - "invalid - max coin per address is invalid", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 0), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "reward program requires positive max reward by address: 0jackthecat", - }, - { - "invalid - denoms differ", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("hotdog", 1), - dateTime, - 1, - 1, - 1, - 1, - qualifyingActions, - ), - "coin denoms differ jackthecat : hotdog", - }, - { - "invalid - reward per address is greater than pool", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 2), - dateTime, - 0, - 1, - 1, - 1, - qualifyingActions, - ), - "max claims per address cannot be larger than pool 2 : 1", - }, - { - "invalid - number of claim periods is 0", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 0, - 1, - 1, - qualifyingActions, - ), - "claim periods (1), claim period days (0), and expire days (1) must be larger than 0", - }, - { - "invalid - number of claim periods is 0", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 1, - 1, - 1, - 0, - qualifyingActions, - ), - "claim periods (1), claim period days (1), and expire days (0) must be larger than 0", - }, - { - "invalid - reward has no qualifying actions", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 4, - 4, - 1, - 1, - []QualifyingAction{}, - ), - "reward program must contain qualifying actions", - }, - { - "invalid - invalid qualifying action validate basic", - *NewMsgCreateRewardProgramRequest( - "title", - "description", - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("jackthecat", 1), - sdk.NewInt64Coin("jackthecat", 1), - dateTime, - 4, - 4, - 1, - 1, - []QualifyingAction{ - { - Type: &QualifyingAction_Delegate{ - Delegate: &ActionDelegate{ - MinimumActions: 0, - MaximumActions: 0, - MinimumDelegationAmount: &minimumDelegation, - MaximumDelegationAmount: &maximumDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ), - "maximum action must be greater than 0 actions", - }, - } - for _, tt := range tests { - tt := tt - s.T().Run(tt.name, func(t *testing.T) { - err := tt.msgCreateRewardProgramRequest.ValidateBasic() - if err != nil { - assert.Equal(t, tt.want, err.Error()) - } else if len(tt.want) > 0 { - t.Errorf("MsgCreateRewardProgramRequest ValidateBasic error = nil, expected: %s", tt.want) - } - }) - } -} - -func (s *RewardMsgTypesTestSuite) TestMsgEndRewardProgramRequestValidateBasic() { - tests := []struct { - name string - msgCreateRewardProgramRequest MsgEndRewardProgramRequest - want string - }{ - { - "valid", - *NewMsgEndRewardProgramRequest( - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - ), - "", - }, - { - "invalid program id", - *NewMsgEndRewardProgramRequest( - 0, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - ), - "invalid reward program id: 0", - }, - { - "valid program owner address", - *NewMsgEndRewardProgramRequest( - 1, - "invalid-address", - ), - "invalid address for rewards program distribution from address: decoding bech32 failed: invalid separator index -1", - }, - } - for _, tt := range tests { - tt := tt - s.T().Run(tt.name, func(t *testing.T) { - err := tt.msgCreateRewardProgramRequest.ValidateBasic() - if err != nil { - assert.Equal(t, tt.want, err.Error()) - } else if len(tt.want) > 0 { - t.Errorf("MsgEndRewardProgramRequest ValidateBasic error = nil, expected: %s", tt.want) - } - }) - } -} - -func (s *RewardMsgTypesTestSuite) TestMsgClaimRewardValidateBasic() { - tests := []struct { - name string - MsgClaimRewardsRequest MsgClaimRewardsRequest - want string - }{ - { - "valid", - *NewMsgClaimRewardsRequest(1, "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h"), - "", - }, - { - "invalid - address incorrect", - *NewMsgClaimRewardsRequest( - 1, - "invalid", - ), - "invalid reward address : decoding bech32 failed: invalid bech32 string length 7", - }, - { - "invalid - incorrect reward id", - *NewMsgClaimRewardsRequest( - 0, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - ), - "invalid rewards program id : 0", - }, - } - for _, tt := range tests { - tt := tt - s.T().Run(tt.name, func(t *testing.T) { - err := tt.MsgClaimRewardsRequest.ValidateBasic() - if err != nil { - assert.Equal(t, tt.want, err.Error()) - } else if len(tt.want) > 0 { - t.Errorf("MsgClaimRewardsRequest ValidateBasic error = nil, expected: %s", tt.want) - } - }) - } -} - -func (s *RewardMsgTypesTestSuite) TestMsgClaimAllRewardsRequestValidateBasic() { - tests := []struct { - name string - request MsgClaimAllRewardsRequest - want string - }{ - { - "valid", - *NewMsgClaimAllRewardsRequest("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h"), - "", - }, - { - "invalid - address incorrect", - *NewMsgClaimAllRewardsRequest( - "invalid", - ), - "invalid reward address : decoding bech32 failed: invalid bech32 string length 7", - }, - } - for _, tt := range tests { - tt := tt - s.T().Run(tt.name, func(t *testing.T) { - err := tt.request.ValidateBasic() - if err != nil { - assert.Equal(t, tt.want, err.Error()) - } else if len(tt.want) > 0 { - t.Errorf("MsgClaimAllRewardsRequest ValidateBasic error = nil, expected: %s", tt.want) - } - }) - } -} diff --git a/x/reward/types/query.pb.go b/x/reward/types/query.pb.go deleted file mode 100644 index 2ff42c21b4..0000000000 --- a/x/reward/types/query.pb.go +++ /dev/null @@ -1,3001 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: provenance/reward/v1/query.proto - -package types - -import ( - context "context" - fmt "fmt" - types "github.com/cosmos/cosmos-sdk/types" - query "github.com/cosmos/cosmos-sdk/types/query" - _ "github.com/cosmos/gogoproto/gogoproto" - grpc1 "github.com/cosmos/gogoproto/grpc" - proto "github.com/cosmos/gogoproto/proto" - _ "google.golang.org/genproto/googleapis/api/annotations" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// QueryType is the state of reward program to query -type QueryRewardProgramsRequest_QueryType int32 - -const ( - // unspecified type - QueryRewardProgramsRequest_QUERY_TYPE_UNSPECIFIED QueryRewardProgramsRequest_QueryType = 0 - // all reward programs states - QueryRewardProgramsRequest_QUERY_TYPE_ALL QueryRewardProgramsRequest_QueryType = 1 - // pending reward program state= - QueryRewardProgramsRequest_QUERY_TYPE_PENDING QueryRewardProgramsRequest_QueryType = 2 - // active reward program state - QueryRewardProgramsRequest_QUERY_TYPE_ACTIVE QueryRewardProgramsRequest_QueryType = 3 - // pending and active reward program states - QueryRewardProgramsRequest_QUERY_TYPE_OUTSTANDING QueryRewardProgramsRequest_QueryType = 4 - // finished reward program state - QueryRewardProgramsRequest_QUERY_TYPE_FINISHED QueryRewardProgramsRequest_QueryType = 5 -) - -var QueryRewardProgramsRequest_QueryType_name = map[int32]string{ - 0: "QUERY_TYPE_UNSPECIFIED", - 1: "QUERY_TYPE_ALL", - 2: "QUERY_TYPE_PENDING", - 3: "QUERY_TYPE_ACTIVE", - 4: "QUERY_TYPE_OUTSTANDING", - 5: "QUERY_TYPE_FINISHED", -} - -var QueryRewardProgramsRequest_QueryType_value = map[string]int32{ - "QUERY_TYPE_UNSPECIFIED": 0, - "QUERY_TYPE_ALL": 1, - "QUERY_TYPE_PENDING": 2, - "QUERY_TYPE_ACTIVE": 3, - "QUERY_TYPE_OUTSTANDING": 4, - "QUERY_TYPE_FINISHED": 5, -} - -func (x QueryRewardProgramsRequest_QueryType) String() string { - return proto.EnumName(QueryRewardProgramsRequest_QueryType_name, int32(x)) -} - -func (QueryRewardProgramsRequest_QueryType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{2, 0} -} - -// QueryRewardProgramByIDRequest queries for the Reward Program with an identifier of id -type QueryRewardProgramByIDRequest struct { - // The id of the reward program to query. - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (m *QueryRewardProgramByIDRequest) Reset() { *m = QueryRewardProgramByIDRequest{} } -func (m *QueryRewardProgramByIDRequest) String() string { return proto.CompactTextString(m) } -func (*QueryRewardProgramByIDRequest) ProtoMessage() {} -func (*QueryRewardProgramByIDRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{0} -} -func (m *QueryRewardProgramByIDRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardProgramByIDRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardProgramByIDRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryRewardProgramByIDRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardProgramByIDRequest.Merge(m, src) -} -func (m *QueryRewardProgramByIDRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardProgramByIDRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardProgramByIDRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardProgramByIDRequest proto.InternalMessageInfo - -func (m *QueryRewardProgramByIDRequest) GetId() uint64 { - if m != nil { - return m.Id - } - return 0 -} - -// QueryRewardProgramByIDResponse contains the requested RewardProgram -type QueryRewardProgramByIDResponse struct { - // The reward program object that was queried for. - RewardProgram *RewardProgram `protobuf:"bytes,1,opt,name=reward_program,json=rewardProgram,proto3" json:"reward_program,omitempty"` -} - -func (m *QueryRewardProgramByIDResponse) Reset() { *m = QueryRewardProgramByIDResponse{} } -func (m *QueryRewardProgramByIDResponse) String() string { return proto.CompactTextString(m) } -func (*QueryRewardProgramByIDResponse) ProtoMessage() {} -func (*QueryRewardProgramByIDResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{1} -} -func (m *QueryRewardProgramByIDResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardProgramByIDResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardProgramByIDResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryRewardProgramByIDResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardProgramByIDResponse.Merge(m, src) -} -func (m *QueryRewardProgramByIDResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardProgramByIDResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardProgramByIDResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardProgramByIDResponse proto.InternalMessageInfo - -func (m *QueryRewardProgramByIDResponse) GetRewardProgram() *RewardProgram { - if m != nil { - return m.RewardProgram - } - return nil -} - -// QueryRewardProgramsRequest queries for all reward programs matching the query_type -type QueryRewardProgramsRequest struct { - // A filter on the types of reward programs. - QueryType QueryRewardProgramsRequest_QueryType `protobuf:"varint,1,opt,name=query_type,json=queryType,proto3,enum=provenance.reward.v1.QueryRewardProgramsRequest_QueryType" json:"query_type,omitempty"` - // pagination defines an optional pagination for the request. - Pagination *query.PageRequest `protobuf:"bytes,99,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryRewardProgramsRequest) Reset() { *m = QueryRewardProgramsRequest{} } -func (m *QueryRewardProgramsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryRewardProgramsRequest) ProtoMessage() {} -func (*QueryRewardProgramsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{2} -} -func (m *QueryRewardProgramsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardProgramsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardProgramsRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryRewardProgramsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardProgramsRequest.Merge(m, src) -} -func (m *QueryRewardProgramsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardProgramsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardProgramsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardProgramsRequest proto.InternalMessageInfo - -func (m *QueryRewardProgramsRequest) GetQueryType() QueryRewardProgramsRequest_QueryType { - if m != nil { - return m.QueryType - } - return QueryRewardProgramsRequest_QUERY_TYPE_UNSPECIFIED -} - -func (m *QueryRewardProgramsRequest) GetPagination() *query.PageRequest { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryRewardProgramsResponse contains the list of RewardPrograms matching the query -type QueryRewardProgramsResponse struct { - // List of RewardProgram objects matching the query_type. - RewardPrograms []RewardProgram `protobuf:"bytes,1,rep,name=reward_programs,json=rewardPrograms,proto3" json:"reward_programs"` - // pagination defines an optional pagination for the response. - Pagination *query.PageResponse `protobuf:"bytes,99,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryRewardProgramsResponse) Reset() { *m = QueryRewardProgramsResponse{} } -func (m *QueryRewardProgramsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryRewardProgramsResponse) ProtoMessage() {} -func (*QueryRewardProgramsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{3} -} -func (m *QueryRewardProgramsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardProgramsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardProgramsResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryRewardProgramsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardProgramsResponse.Merge(m, src) -} -func (m *QueryRewardProgramsResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardProgramsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardProgramsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardProgramsResponse proto.InternalMessageInfo - -func (m *QueryRewardProgramsResponse) GetRewardPrograms() []RewardProgram { - if m != nil { - return m.RewardPrograms - } - return nil -} - -func (m *QueryRewardProgramsResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryClaimPeriodRewardDistributionsRequest queries for all the ClaimPeriodRewardDistributions with pagination. -type QueryClaimPeriodRewardDistributionsRequest struct { - // pagination defines an optional pagination for the request. - Pagination *query.PageRequest `protobuf:"bytes,99,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryClaimPeriodRewardDistributionsRequest) Reset() { - *m = QueryClaimPeriodRewardDistributionsRequest{} -} -func (m *QueryClaimPeriodRewardDistributionsRequest) String() string { - return proto.CompactTextString(m) -} -func (*QueryClaimPeriodRewardDistributionsRequest) ProtoMessage() {} -func (*QueryClaimPeriodRewardDistributionsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{4} -} -func (m *QueryClaimPeriodRewardDistributionsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryClaimPeriodRewardDistributionsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryClaimPeriodRewardDistributionsRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryClaimPeriodRewardDistributionsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsRequest.Merge(m, src) -} -func (m *QueryClaimPeriodRewardDistributionsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryClaimPeriodRewardDistributionsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryClaimPeriodRewardDistributionsRequest proto.InternalMessageInfo - -func (m *QueryClaimPeriodRewardDistributionsRequest) GetPagination() *query.PageRequest { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryClaimPeriodRewardDistributionsResponse returns the list of paginated ClaimPeriodRewardDistributions -type QueryClaimPeriodRewardDistributionsResponse struct { - // List of all ClaimPeriodRewardDistribution objects queried for. - ClaimPeriodRewardDistributions []ClaimPeriodRewardDistribution `protobuf:"bytes,1,rep,name=claim_period_reward_distributions,json=claimPeriodRewardDistributions,proto3" json:"claim_period_reward_distributions"` - // pagination defines an optional pagination for the response. - Pagination *query.PageResponse `protobuf:"bytes,99,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryClaimPeriodRewardDistributionsResponse) Reset() { - *m = QueryClaimPeriodRewardDistributionsResponse{} -} -func (m *QueryClaimPeriodRewardDistributionsResponse) String() string { - return proto.CompactTextString(m) -} -func (*QueryClaimPeriodRewardDistributionsResponse) ProtoMessage() {} -func (*QueryClaimPeriodRewardDistributionsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{5} -} -func (m *QueryClaimPeriodRewardDistributionsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryClaimPeriodRewardDistributionsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryClaimPeriodRewardDistributionsResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryClaimPeriodRewardDistributionsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsResponse.Merge(m, src) -} -func (m *QueryClaimPeriodRewardDistributionsResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryClaimPeriodRewardDistributionsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryClaimPeriodRewardDistributionsResponse proto.InternalMessageInfo - -func (m *QueryClaimPeriodRewardDistributionsResponse) GetClaimPeriodRewardDistributions() []ClaimPeriodRewardDistribution { - if m != nil { - return m.ClaimPeriodRewardDistributions - } - return nil -} - -func (m *QueryClaimPeriodRewardDistributionsResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryClaimPeriodRewardDistributionsByIDRequest queries for a single ClaimPeriodRewardDistribution -type QueryClaimPeriodRewardDistributionsByIDRequest struct { - // The reward program that the claim period reward distribution belongs to. - RewardId uint64 `protobuf:"varint,1,opt,name=reward_id,json=rewardId,proto3" json:"reward_id,omitempty"` - // The claim period that the claim period reward distribution was created for. - ClaimPeriodId uint64 `protobuf:"varint,2,opt,name=claim_period_id,json=claimPeriodId,proto3" json:"claim_period_id,omitempty"` -} - -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) Reset() { - *m = QueryClaimPeriodRewardDistributionsByIDRequest{} -} -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) String() string { - return proto.CompactTextString(m) -} -func (*QueryClaimPeriodRewardDistributionsByIDRequest) ProtoMessage() {} -func (*QueryClaimPeriodRewardDistributionsByIDRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{6} -} -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDRequest.Merge(m, src) -} -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDRequest proto.InternalMessageInfo - -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) GetRewardId() uint64 { - if m != nil { - return m.RewardId - } - return 0 -} - -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) GetClaimPeriodId() uint64 { - if m != nil { - return m.ClaimPeriodId - } - return 0 -} - -// QueryClaimPeriodRewardDistributionsByIDResponse returns the requested ClaimPeriodRewardDistribution -type QueryClaimPeriodRewardDistributionsByIDResponse struct { - // The ClaimPeriodRewardDistribution object that was queried for. - ClaimPeriodRewardDistribution *ClaimPeriodRewardDistribution `protobuf:"bytes,1,opt,name=claim_period_reward_distribution,json=claimPeriodRewardDistribution,proto3" json:"claim_period_reward_distribution,omitempty"` -} - -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) Reset() { - *m = QueryClaimPeriodRewardDistributionsByIDResponse{} -} -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) String() string { - return proto.CompactTextString(m) -} -func (*QueryClaimPeriodRewardDistributionsByIDResponse) ProtoMessage() {} -func (*QueryClaimPeriodRewardDistributionsByIDResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{7} -} -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDResponse.Merge(m, src) -} -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryClaimPeriodRewardDistributionsByIDResponse proto.InternalMessageInfo - -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) GetClaimPeriodRewardDistribution() *ClaimPeriodRewardDistribution { - if m != nil { - return m.ClaimPeriodRewardDistribution - } - return nil -} - -// QueryRewardDistributionsByAddressRequest queries for reward claims by address that match the claim_status. -type QueryRewardDistributionsByAddressRequest struct { - // The address that the claim belongs to. - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // The status that the reward account must have. - ClaimStatus RewardAccountState_ClaimStatus `protobuf:"varint,2,opt,name=claim_status,json=claimStatus,proto3,enum=provenance.reward.v1.RewardAccountState_ClaimStatus" json:"claim_status,omitempty"` - // pagination defines an optional pagination for the request. - Pagination *query.PageRequest `protobuf:"bytes,99,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryRewardDistributionsByAddressRequest) Reset() { - *m = QueryRewardDistributionsByAddressRequest{} -} -func (m *QueryRewardDistributionsByAddressRequest) String() string { return proto.CompactTextString(m) } -func (*QueryRewardDistributionsByAddressRequest) ProtoMessage() {} -func (*QueryRewardDistributionsByAddressRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{8} -} -func (m *QueryRewardDistributionsByAddressRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardDistributionsByAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardDistributionsByAddressRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryRewardDistributionsByAddressRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardDistributionsByAddressRequest.Merge(m, src) -} -func (m *QueryRewardDistributionsByAddressRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardDistributionsByAddressRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardDistributionsByAddressRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardDistributionsByAddressRequest proto.InternalMessageInfo - -func (m *QueryRewardDistributionsByAddressRequest) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - -func (m *QueryRewardDistributionsByAddressRequest) GetClaimStatus() RewardAccountState_ClaimStatus { - if m != nil { - return m.ClaimStatus - } - return RewardAccountState_CLAIM_STATUS_UNSPECIFIED -} - -func (m *QueryRewardDistributionsByAddressRequest) GetPagination() *query.PageRequest { - if m != nil { - return m.Pagination - } - return nil -} - -// QueryRewardDistributionsByAddressResponse returns the reward claims for an address that match the claim_status. -type QueryRewardDistributionsByAddressResponse struct { - // The address that the reward account belongs to. - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // List of RewardAccounts queried for. - RewardAccountState []RewardAccountResponse `protobuf:"bytes,2,rep,name=reward_account_state,json=rewardAccountState,proto3" json:"reward_account_state"` - // pagination defines an optional pagination for the response. - Pagination *query.PageResponse `protobuf:"bytes,99,opt,name=pagination,proto3" json:"pagination,omitempty"` -} - -func (m *QueryRewardDistributionsByAddressResponse) Reset() { - *m = QueryRewardDistributionsByAddressResponse{} -} -func (m *QueryRewardDistributionsByAddressResponse) String() string { - return proto.CompactTextString(m) -} -func (*QueryRewardDistributionsByAddressResponse) ProtoMessage() {} -func (*QueryRewardDistributionsByAddressResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{9} -} -func (m *QueryRewardDistributionsByAddressResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryRewardDistributionsByAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryRewardDistributionsByAddressResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryRewardDistributionsByAddressResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryRewardDistributionsByAddressResponse.Merge(m, src) -} -func (m *QueryRewardDistributionsByAddressResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryRewardDistributionsByAddressResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryRewardDistributionsByAddressResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryRewardDistributionsByAddressResponse proto.InternalMessageInfo - -func (m *QueryRewardDistributionsByAddressResponse) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - -func (m *QueryRewardDistributionsByAddressResponse) GetRewardAccountState() []RewardAccountResponse { - if m != nil { - return m.RewardAccountState - } - return nil -} - -func (m *QueryRewardDistributionsByAddressResponse) GetPagination() *query.PageResponse { - if m != nil { - return m.Pagination - } - return nil -} - -// RewardAccountResponse is an address' reward claim for a reward program's claim period. -type RewardAccountResponse struct { - // The id of the reward program that this claim belongs to. - RewardProgramId uint64 `protobuf:"varint,1,opt,name=reward_program_id,json=rewardProgramId,proto3" json:"reward_program_id,omitempty"` - // total rewards claimed for all eligible claim periods in program. - TotalRewardClaim types.Coin `protobuf:"bytes,2,opt,name=total_reward_claim,json=totalRewardClaim,proto3" json:"total_reward_claim"` - // The status of the claim. - ClaimStatus RewardAccountState_ClaimStatus `protobuf:"varint,3,opt,name=claim_status,json=claimStatus,proto3,enum=provenance.reward.v1.RewardAccountState_ClaimStatus" json:"claim_status,omitempty"` - // The claim period that the claim belongs to. - ClaimId uint64 `protobuf:"varint,4,opt,name=claim_id,json=claimId,proto3" json:"claim_id,omitempty"` -} - -func (m *RewardAccountResponse) Reset() { *m = RewardAccountResponse{} } -func (m *RewardAccountResponse) String() string { return proto.CompactTextString(m) } -func (*RewardAccountResponse) ProtoMessage() {} -func (*RewardAccountResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_89e47dd1c3e4febf, []int{10} -} -func (m *RewardAccountResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *RewardAccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_RewardAccountResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *RewardAccountResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_RewardAccountResponse.Merge(m, src) -} -func (m *RewardAccountResponse) XXX_Size() int { - return m.Size() -} -func (m *RewardAccountResponse) XXX_DiscardUnknown() { - xxx_messageInfo_RewardAccountResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_RewardAccountResponse proto.InternalMessageInfo - -func (m *RewardAccountResponse) GetRewardProgramId() uint64 { - if m != nil { - return m.RewardProgramId - } - return 0 -} - -func (m *RewardAccountResponse) GetTotalRewardClaim() types.Coin { - if m != nil { - return m.TotalRewardClaim - } - return types.Coin{} -} - -func (m *RewardAccountResponse) GetClaimStatus() RewardAccountState_ClaimStatus { - if m != nil { - return m.ClaimStatus - } - return RewardAccountState_CLAIM_STATUS_UNSPECIFIED -} - -func (m *RewardAccountResponse) GetClaimId() uint64 { - if m != nil { - return m.ClaimId - } - return 0 -} - -func init() { - proto.RegisterEnum("provenance.reward.v1.QueryRewardProgramsRequest_QueryType", QueryRewardProgramsRequest_QueryType_name, QueryRewardProgramsRequest_QueryType_value) - proto.RegisterType((*QueryRewardProgramByIDRequest)(nil), "provenance.reward.v1.QueryRewardProgramByIDRequest") - proto.RegisterType((*QueryRewardProgramByIDResponse)(nil), "provenance.reward.v1.QueryRewardProgramByIDResponse") - proto.RegisterType((*QueryRewardProgramsRequest)(nil), "provenance.reward.v1.QueryRewardProgramsRequest") - proto.RegisterType((*QueryRewardProgramsResponse)(nil), "provenance.reward.v1.QueryRewardProgramsResponse") - proto.RegisterType((*QueryClaimPeriodRewardDistributionsRequest)(nil), "provenance.reward.v1.QueryClaimPeriodRewardDistributionsRequest") - proto.RegisterType((*QueryClaimPeriodRewardDistributionsResponse)(nil), "provenance.reward.v1.QueryClaimPeriodRewardDistributionsResponse") - proto.RegisterType((*QueryClaimPeriodRewardDistributionsByIDRequest)(nil), "provenance.reward.v1.QueryClaimPeriodRewardDistributionsByIDRequest") - proto.RegisterType((*QueryClaimPeriodRewardDistributionsByIDResponse)(nil), "provenance.reward.v1.QueryClaimPeriodRewardDistributionsByIDResponse") - proto.RegisterType((*QueryRewardDistributionsByAddressRequest)(nil), "provenance.reward.v1.QueryRewardDistributionsByAddressRequest") - proto.RegisterType((*QueryRewardDistributionsByAddressResponse)(nil), "provenance.reward.v1.QueryRewardDistributionsByAddressResponse") - proto.RegisterType((*RewardAccountResponse)(nil), "provenance.reward.v1.RewardAccountResponse") -} - -func init() { proto.RegisterFile("provenance/reward/v1/query.proto", fileDescriptor_89e47dd1c3e4febf) } - -var fileDescriptor_89e47dd1c3e4febf = []byte{ - // 1042 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xcf, 0x6f, 0x1b, 0x45, - 0x14, 0xce, 0x38, 0x29, 0x4d, 0x5e, 0xa8, 0xe3, 0x0c, 0x69, 0xeb, 0xba, 0xed, 0x26, 0x35, 0x52, - 0x08, 0x89, 0xba, 0x5b, 0x3b, 0x15, 0x42, 0x39, 0x40, 0x9d, 0xd8, 0x29, 0x8b, 0x4a, 0x70, 0xd7, - 0x0e, 0x28, 0x5c, 0xac, 0xf5, 0xee, 0x62, 0x56, 0x72, 0x3c, 0x9b, 0x9d, 0x75, 0x20, 0x0a, 0xb9, - 0x20, 0xfe, 0x80, 0x4a, 0x5c, 0xb8, 0xb5, 0x17, 0xce, 0x1c, 0xb8, 0xf1, 0x17, 0x54, 0xe2, 0x52, - 0x89, 0x03, 0x9c, 0x10, 0x24, 0x20, 0xb8, 0x73, 0x46, 0x42, 0x9e, 0x99, 0xb5, 0x77, 0x63, 0x67, - 0xbd, 0x49, 0x7d, 0xf3, 0xee, 0xbc, 0x1f, 0xdf, 0xf7, 0xbd, 0x37, 0xef, 0xad, 0x61, 0xc1, 0x71, - 0xc9, 0xbe, 0xd5, 0xd2, 0x5b, 0x86, 0xa5, 0xb8, 0xd6, 0xe7, 0xba, 0x6b, 0x2a, 0xfb, 0x39, 0x65, - 0xaf, 0x6d, 0xb9, 0x07, 0xb2, 0xe3, 0x12, 0x8f, 0xe0, 0xb9, 0x9e, 0x85, 0xcc, 0x2d, 0xe4, 0xfd, - 0x5c, 0x66, 0xae, 0x41, 0x1a, 0x84, 0x19, 0x28, 0x9d, 0x5f, 0xdc, 0x36, 0x73, 0xab, 0x41, 0x48, - 0xa3, 0x69, 0x29, 0xba, 0x63, 0x2b, 0x7a, 0xab, 0x45, 0x3c, 0xdd, 0xb3, 0x49, 0x8b, 0x8a, 0x53, - 0xc9, 0x20, 0x74, 0x97, 0x50, 0xa5, 0xae, 0x53, 0x4b, 0xd9, 0xcf, 0xd5, 0x2d, 0x4f, 0xcf, 0x29, - 0x06, 0xb1, 0x5b, 0xe2, 0x7c, 0x39, 0x78, 0xce, 0x20, 0x74, 0xad, 0x1c, 0xbd, 0x61, 0xb7, 0x58, - 0x30, 0x61, 0x7b, 0x67, 0x20, 0x6e, 0x81, 0x8f, 0x99, 0x64, 0x15, 0xb8, 0xfd, 0xb8, 0x13, 0x44, - 0x63, 0x2f, 0xcb, 0x2e, 0x69, 0xb8, 0xfa, 0xee, 0xfa, 0x81, 0x5a, 0xd4, 0xac, 0xbd, 0xb6, 0x45, - 0x3d, 0x9c, 0x84, 0x84, 0x6d, 0xa6, 0xd1, 0x02, 0x5a, 0x9a, 0xd0, 0x12, 0xb6, 0x99, 0x6d, 0x82, - 0x74, 0x96, 0x03, 0x75, 0x48, 0x8b, 0x5a, 0xf8, 0x7d, 0x48, 0xf2, 0x14, 0x35, 0x87, 0x9f, 0x32, - 0xef, 0xe9, 0xfc, 0xeb, 0xf2, 0x20, 0x91, 0xe4, 0x50, 0x20, 0xed, 0x8a, 0x1b, 0x7c, 0xcc, 0xfe, - 0x91, 0x80, 0x4c, 0x7f, 0x3a, 0xea, 0x83, 0xdb, 0x01, 0x60, 0x12, 0xd4, 0xbc, 0x03, 0xc7, 0x62, - 0x69, 0x92, 0xf9, 0xb5, 0xc1, 0x69, 0xce, 0x8e, 0xc2, 0x8f, 0xaa, 0x07, 0x8e, 0xa5, 0x4d, 0xed, - 0xf9, 0x3f, 0xf1, 0x26, 0x40, 0x4f, 0xcf, 0xb4, 0xc1, 0x18, 0x2c, 0xca, 0x5c, 0x7c, 0xb9, 0x23, - 0xbe, 0xcc, 0xeb, 0x2f, 0xc4, 0x97, 0xcb, 0x7a, 0xc3, 0x12, 0x01, 0xb5, 0x80, 0x67, 0xf6, 0x29, - 0x82, 0xa9, 0x6e, 0x02, 0x9c, 0x81, 0x6b, 0x8f, 0xb7, 0x4b, 0xda, 0x4e, 0xad, 0xba, 0x53, 0x2e, - 0xd5, 0xb6, 0xb7, 0x2a, 0xe5, 0xd2, 0x86, 0xba, 0xa9, 0x96, 0x8a, 0xa9, 0x31, 0x8c, 0x21, 0x19, - 0x38, 0x2b, 0x3c, 0x7a, 0x94, 0x42, 0xf8, 0x1a, 0xe0, 0xc0, 0xbb, 0x72, 0x69, 0xab, 0xa8, 0x6e, - 0x3d, 0x4c, 0x25, 0xf0, 0x55, 0x98, 0x0d, 0xda, 0x6e, 0x54, 0xd5, 0x8f, 0x4a, 0xa9, 0xf1, 0x53, - 0xe1, 0x3f, 0xdc, 0xae, 0x56, 0xaa, 0x05, 0xee, 0x32, 0x81, 0xaf, 0xc3, 0x6b, 0x81, 0xb3, 0x4d, - 0x75, 0x4b, 0xad, 0xbc, 0x57, 0x2a, 0xa6, 0x2e, 0x65, 0x7f, 0x44, 0x70, 0x73, 0xa0, 0x3a, 0xa2, - 0x9e, 0x1a, 0xcc, 0x84, 0xeb, 0x49, 0xd3, 0x68, 0x61, 0x3c, 0x66, 0x41, 0xd7, 0x27, 0x9e, 0xff, - 0x36, 0x3f, 0xa6, 0x25, 0x43, 0x65, 0xa5, 0xf8, 0xe1, 0x00, 0x75, 0xdf, 0x18, 0xaa, 0x2e, 0x07, - 0x14, 0x92, 0xd7, 0x83, 0x65, 0x86, 0x7d, 0xa3, 0xa9, 0xdb, 0xbb, 0x65, 0xcb, 0xb5, 0x89, 0xc9, - 0xf3, 0x17, 0x6d, 0xea, 0xb9, 0x76, 0xbd, 0xcd, 0xee, 0x96, 0xdf, 0x2f, 0xa3, 0x2a, 0xea, 0x7f, - 0x08, 0x56, 0x62, 0xa5, 0x15, 0x12, 0x7e, 0x8d, 0xe0, 0x8e, 0xd1, 0x31, 0xad, 0x39, 0xcc, 0xb6, - 0x26, 0x04, 0x35, 0x83, 0xd6, 0x42, 0xd5, 0xd5, 0xc1, 0xaa, 0x46, 0x66, 0x12, 0x2a, 0x4b, 0x46, - 0x24, 0x9c, 0xd1, 0xa9, 0xde, 0x06, 0x39, 0x06, 0xfd, 0xe0, 0x18, 0xb9, 0x09, 0x53, 0x82, 0x73, - 0x77, 0x9a, 0x4c, 0xf2, 0x17, 0xaa, 0x89, 0x17, 0x61, 0x26, 0xa4, 0x8e, 0x6d, 0xa6, 0x13, 0xcc, - 0xe4, 0x4a, 0x80, 0x90, 0x6a, 0x66, 0xbf, 0x47, 0xa0, 0xc4, 0xce, 0x2b, 0xa4, 0xff, 0x12, 0x16, - 0x86, 0x29, 0x2f, 0xe6, 0xd3, 0x45, 0x84, 0xd7, 0x6e, 0x47, 0x4a, 0x9e, 0xfd, 0x0b, 0xc1, 0x52, - 0xe0, 0x6e, 0x9d, 0x82, 0x59, 0x30, 0x4d, 0xd7, 0xa2, 0xdd, 0xee, 0x4c, 0xc3, 0x65, 0x9d, 0xbf, - 0x61, 0x88, 0xa6, 0x34, 0xff, 0x11, 0x7f, 0x0c, 0xaf, 0x72, 0x12, 0xd4, 0xd3, 0xbd, 0x36, 0x65, - 0xea, 0x24, 0xf3, 0xf7, 0xa3, 0xee, 0x5f, 0xc1, 0x30, 0x48, 0xbb, 0xe5, 0x55, 0x3c, 0xdd, 0xb3, - 0x38, 0x87, 0x0a, 0xf3, 0xd5, 0xa6, 0x8d, 0xde, 0xc3, 0xc8, 0x2e, 0xc4, 0xbf, 0x08, 0xde, 0x8c, - 0xc1, 0x53, 0xd4, 0xe4, 0x6c, 0xa2, 0x06, 0xcc, 0x89, 0x02, 0xe9, 0x1c, 0x3f, 0x63, 0x6c, 0xa5, - 0x13, 0xec, 0x6a, 0xac, 0xc4, 0x20, 0xec, 0x27, 0x11, 0x57, 0x02, 0xbb, 0x7d, 0x6a, 0x8c, 0xee, - 0x1a, 0x3c, 0x49, 0xc0, 0xd5, 0x81, 0xc9, 0xf1, 0x32, 0xcc, 0x86, 0x67, 0x66, 0xaf, 0xed, 0x67, - 0x42, 0xa3, 0x50, 0x35, 0xf1, 0x07, 0x80, 0x3d, 0xe2, 0xe9, 0x4d, 0xbf, 0x35, 0x59, 0x7d, 0x58, - 0x89, 0xa7, 0xf3, 0x37, 0x42, 0xb0, 0x7c, 0x40, 0x1b, 0xc4, 0xf6, 0xaf, 0x7c, 0x8a, 0xb9, 0x72, - 0x10, 0xac, 0xca, 0x7d, 0xbd, 0x32, 0x3e, 0xaa, 0x5e, 0xb9, 0x01, 0x93, 0x3c, 0xb0, 0x6d, 0xa6, - 0x27, 0x18, 0x95, 0xcb, 0xec, 0x59, 0x35, 0xd7, 0x26, 0xbf, 0x7d, 0x36, 0x8f, 0xfe, 0x79, 0x36, - 0x8f, 0xf2, 0x3f, 0x4d, 0xc2, 0x25, 0xd6, 0x08, 0xf8, 0x07, 0x04, 0xb3, 0x7d, 0x1f, 0x09, 0x78, - 0x35, 0xee, 0x76, 0x0e, 0x0c, 0x8f, 0xcc, 0xfd, 0xf3, 0x39, 0xf1, 0x1a, 0x64, 0x57, 0xbf, 0xfa, - 0xf9, 0xcf, 0x6f, 0x12, 0x77, 0xf1, 0x8a, 0xd2, 0xf7, 0x19, 0x44, 0x7b, 0xdf, 0x41, 0xdd, 0xa5, - 0xa6, 0x1c, 0xda, 0xe6, 0x11, 0xfe, 0x0e, 0x41, 0x32, 0xbc, 0x07, 0xf1, 0xbd, 0xf3, 0x7e, 0x50, - 0x64, 0x72, 0xe7, 0xf0, 0x10, 0x60, 0x65, 0x06, 0x76, 0x09, 0x2f, 0xc6, 0x03, 0x8b, 0xff, 0x46, - 0x20, 0x45, 0x4f, 0x41, 0xfc, 0x20, 0x02, 0x45, 0xac, 0x75, 0x99, 0x29, 0xbc, 0x44, 0x04, 0xc1, - 0xeb, 0x01, 0xe3, 0xb5, 0x86, 0xdf, 0x3e, 0x83, 0xd7, 0xd0, 0xad, 0x88, 0x9f, 0x26, 0x20, 0x3b, - 0x7c, 0xde, 0xe3, 0xe2, 0x85, 0xb1, 0x06, 0x3b, 0xad, 0xf4, 0x92, 0x51, 0x04, 0xeb, 0x26, 0x63, - 0xfd, 0x29, 0x36, 0x2f, 0xca, 0x5a, 0x39, 0xec, 0x6e, 0xcb, 0xa3, 0x90, 0x35, 0x55, 0x0e, 0x4f, - 0xad, 0xca, 0x23, 0xfc, 0x0b, 0x82, 0x5b, 0x51, 0x73, 0x17, 0xbf, 0x33, 0xb4, 0x1f, 0x23, 0x17, - 0x53, 0xe6, 0xdd, 0x0b, 0xfb, 0x0b, 0x3d, 0xde, 0x62, 0x7a, 0xdc, 0xc3, 0x72, 0x74, 0x77, 0x33, - 0x66, 0x54, 0x39, 0x14, 0xdb, 0xe0, 0x68, 0xbd, 0xf1, 0xfc, 0x58, 0x42, 0x2f, 0x8e, 0x25, 0xf4, - 0xfb, 0xb1, 0x84, 0x9e, 0x9c, 0x48, 0x63, 0x2f, 0x4e, 0xa4, 0xb1, 0x5f, 0x4f, 0xa4, 0x31, 0xb8, - 0x6e, 0x93, 0x81, 0xa0, 0xca, 0xe8, 0x93, 0x7c, 0xc3, 0xf6, 0x3e, 0x6b, 0xd7, 0x65, 0x83, 0xec, - 0x06, 0xd2, 0xdd, 0xb5, 0x49, 0x30, 0xf9, 0x17, 0xfe, 0x1f, 0xa2, 0xce, 0x3f, 0x07, 0x5a, 0x7f, - 0x85, 0xfd, 0x1b, 0x5a, 0xfd, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xed, 0x8c, 0x3b, 0xfc, 0xea, 0x0d, - 0x00, 0x00, -} - -func (this *RewardAccountResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*RewardAccountResponse) - if !ok { - that2, ok := that.(RewardAccountResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.RewardProgramId != that1.RewardProgramId { - return false - } - if !this.TotalRewardClaim.Equal(&that1.TotalRewardClaim) { - return false - } - if this.ClaimStatus != that1.ClaimStatus { - return false - } - if this.ClaimId != that1.ClaimId { - return false - } - return true -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// QueryClient is the client API for Query service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type QueryClient interface { - // RewardProgramByID returns a reward program matching the ID. - RewardProgramByID(ctx context.Context, in *QueryRewardProgramByIDRequest, opts ...grpc.CallOption) (*QueryRewardProgramByIDResponse, error) - // RewardPrograms returns a list of reward programs matching the query type. - RewardPrograms(ctx context.Context, in *QueryRewardProgramsRequest, opts ...grpc.CallOption) (*QueryRewardProgramsResponse, error) - // ClaimPeriodRewardDistributions returns a list of claim period reward distributions matching the claim_status. - ClaimPeriodRewardDistributions(ctx context.Context, in *QueryClaimPeriodRewardDistributionsRequest, opts ...grpc.CallOption) (*QueryClaimPeriodRewardDistributionsResponse, error) - // ClaimPeriodRewardDistributionsByID returns a claim period reward distribution matching the ID. - ClaimPeriodRewardDistributionsByID(ctx context.Context, in *QueryClaimPeriodRewardDistributionsByIDRequest, opts ...grpc.CallOption) (*QueryClaimPeriodRewardDistributionsByIDResponse, error) - // RewardDistributionsByAddress returns a list of reward claims belonging to the account and matching the claim - // status. - RewardDistributionsByAddress(ctx context.Context, in *QueryRewardDistributionsByAddressRequest, opts ...grpc.CallOption) (*QueryRewardDistributionsByAddressResponse, error) -} - -type queryClient struct { - cc grpc1.ClientConn -} - -func NewQueryClient(cc grpc1.ClientConn) QueryClient { - return &queryClient{cc} -} - -func (c *queryClient) RewardProgramByID(ctx context.Context, in *QueryRewardProgramByIDRequest, opts ...grpc.CallOption) (*QueryRewardProgramByIDResponse, error) { - out := new(QueryRewardProgramByIDResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Query/RewardProgramByID", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) RewardPrograms(ctx context.Context, in *QueryRewardProgramsRequest, opts ...grpc.CallOption) (*QueryRewardProgramsResponse, error) { - out := new(QueryRewardProgramsResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Query/RewardPrograms", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) ClaimPeriodRewardDistributions(ctx context.Context, in *QueryClaimPeriodRewardDistributionsRequest, opts ...grpc.CallOption) (*QueryClaimPeriodRewardDistributionsResponse, error) { - out := new(QueryClaimPeriodRewardDistributionsResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Query/ClaimPeriodRewardDistributions", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) ClaimPeriodRewardDistributionsByID(ctx context.Context, in *QueryClaimPeriodRewardDistributionsByIDRequest, opts ...grpc.CallOption) (*QueryClaimPeriodRewardDistributionsByIDResponse, error) { - out := new(QueryClaimPeriodRewardDistributionsByIDResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Query/ClaimPeriodRewardDistributionsByID", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) RewardDistributionsByAddress(ctx context.Context, in *QueryRewardDistributionsByAddressRequest, opts ...grpc.CallOption) (*QueryRewardDistributionsByAddressResponse, error) { - out := new(QueryRewardDistributionsByAddressResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Query/RewardDistributionsByAddress", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// QueryServer is the server API for Query service. -type QueryServer interface { - // RewardProgramByID returns a reward program matching the ID. - RewardProgramByID(context.Context, *QueryRewardProgramByIDRequest) (*QueryRewardProgramByIDResponse, error) - // RewardPrograms returns a list of reward programs matching the query type. - RewardPrograms(context.Context, *QueryRewardProgramsRequest) (*QueryRewardProgramsResponse, error) - // ClaimPeriodRewardDistributions returns a list of claim period reward distributions matching the claim_status. - ClaimPeriodRewardDistributions(context.Context, *QueryClaimPeriodRewardDistributionsRequest) (*QueryClaimPeriodRewardDistributionsResponse, error) - // ClaimPeriodRewardDistributionsByID returns a claim period reward distribution matching the ID. - ClaimPeriodRewardDistributionsByID(context.Context, *QueryClaimPeriodRewardDistributionsByIDRequest) (*QueryClaimPeriodRewardDistributionsByIDResponse, error) - // RewardDistributionsByAddress returns a list of reward claims belonging to the account and matching the claim - // status. - RewardDistributionsByAddress(context.Context, *QueryRewardDistributionsByAddressRequest) (*QueryRewardDistributionsByAddressResponse, error) -} - -// UnimplementedQueryServer can be embedded to have forward compatible implementations. -type UnimplementedQueryServer struct { -} - -func (*UnimplementedQueryServer) RewardProgramByID(ctx context.Context, req *QueryRewardProgramByIDRequest) (*QueryRewardProgramByIDResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method RewardProgramByID not implemented") -} -func (*UnimplementedQueryServer) RewardPrograms(ctx context.Context, req *QueryRewardProgramsRequest) (*QueryRewardProgramsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method RewardPrograms not implemented") -} -func (*UnimplementedQueryServer) ClaimPeriodRewardDistributions(ctx context.Context, req *QueryClaimPeriodRewardDistributionsRequest) (*QueryClaimPeriodRewardDistributionsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ClaimPeriodRewardDistributions not implemented") -} -func (*UnimplementedQueryServer) ClaimPeriodRewardDistributionsByID(ctx context.Context, req *QueryClaimPeriodRewardDistributionsByIDRequest) (*QueryClaimPeriodRewardDistributionsByIDResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ClaimPeriodRewardDistributionsByID not implemented") -} -func (*UnimplementedQueryServer) RewardDistributionsByAddress(ctx context.Context, req *QueryRewardDistributionsByAddressRequest) (*QueryRewardDistributionsByAddressResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method RewardDistributionsByAddress not implemented") -} - -func RegisterQueryServer(s grpc1.Server, srv QueryServer) { - s.RegisterService(&_Query_serviceDesc, srv) -} - -func _Query_RewardProgramByID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryRewardProgramByIDRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).RewardProgramByID(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Query/RewardProgramByID", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).RewardProgramByID(ctx, req.(*QueryRewardProgramByIDRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_RewardPrograms_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryRewardProgramsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).RewardPrograms(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Query/RewardPrograms", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).RewardPrograms(ctx, req.(*QueryRewardProgramsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_ClaimPeriodRewardDistributions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryClaimPeriodRewardDistributionsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).ClaimPeriodRewardDistributions(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Query/ClaimPeriodRewardDistributions", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).ClaimPeriodRewardDistributions(ctx, req.(*QueryClaimPeriodRewardDistributionsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_ClaimPeriodRewardDistributionsByID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryClaimPeriodRewardDistributionsByIDRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).ClaimPeriodRewardDistributionsByID(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Query/ClaimPeriodRewardDistributionsByID", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).ClaimPeriodRewardDistributionsByID(ctx, req.(*QueryClaimPeriodRewardDistributionsByIDRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_RewardDistributionsByAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryRewardDistributionsByAddressRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).RewardDistributionsByAddress(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Query/RewardDistributionsByAddress", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).RewardDistributionsByAddress(ctx, req.(*QueryRewardDistributionsByAddressRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "provenance.reward.v1.Query", - HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "RewardProgramByID", - Handler: _Query_RewardProgramByID_Handler, - }, - { - MethodName: "RewardPrograms", - Handler: _Query_RewardPrograms_Handler, - }, - { - MethodName: "ClaimPeriodRewardDistributions", - Handler: _Query_ClaimPeriodRewardDistributions_Handler, - }, - { - MethodName: "ClaimPeriodRewardDistributionsByID", - Handler: _Query_ClaimPeriodRewardDistributionsByID_Handler, - }, - { - MethodName: "RewardDistributionsByAddress", - Handler: _Query_RewardDistributionsByAddress_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "provenance/reward/v1/query.proto", -} - -func (m *QueryRewardProgramByIDRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryRewardProgramByIDRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardProgramByIDRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Id != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryRewardProgramByIDResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryRewardProgramByIDResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardProgramByIDResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.RewardProgram != nil { - { - size, err := m.RewardProgram.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryRewardProgramsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryRewardProgramsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardProgramsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x6 - i-- - dAtA[i] = 0x9a - } - if m.QueryType != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.QueryType)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryRewardProgramsResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryRewardProgramsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardProgramsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x6 - i-- - dAtA[i] = 0x9a - } - if len(m.RewardPrograms) > 0 { - for iNdEx := len(m.RewardPrograms) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.RewardPrograms[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *QueryClaimPeriodRewardDistributionsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryClaimPeriodRewardDistributionsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryClaimPeriodRewardDistributionsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x6 - i-- - dAtA[i] = 0x9a - } - return len(dAtA) - i, nil -} - -func (m *QueryClaimPeriodRewardDistributionsResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryClaimPeriodRewardDistributionsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryClaimPeriodRewardDistributionsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x6 - i-- - dAtA[i] = 0x9a - } - if len(m.ClaimPeriodRewardDistributions) > 0 { - for iNdEx := len(m.ClaimPeriodRewardDistributions) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ClaimPeriodRewardDistributions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ClaimPeriodId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ClaimPeriodId)) - i-- - dAtA[i] = 0x10 - } - if m.RewardId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.RewardId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ClaimPeriodRewardDistribution != nil { - { - size, err := m.ClaimPeriodRewardDistribution.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryRewardDistributionsByAddressRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryRewardDistributionsByAddressRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardDistributionsByAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x6 - i-- - dAtA[i] = 0x9a - } - if m.ClaimStatus != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ClaimStatus)) - i-- - dAtA[i] = 0x10 - } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QueryRewardDistributionsByAddressResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryRewardDistributionsByAddressResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRewardDistributionsByAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Pagination != nil { - { - size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x6 - i-- - dAtA[i] = 0x9a - } - if len(m.RewardAccountState) > 0 { - for iNdEx := len(m.RewardAccountState) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.RewardAccountState[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *RewardAccountResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RewardAccountResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *RewardAccountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ClaimId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ClaimId)) - i-- - dAtA[i] = 0x20 - } - if m.ClaimStatus != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.ClaimStatus)) - i-- - dAtA[i] = 0x18 - } - { - size, err := m.TotalRewardClaim.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if m.RewardProgramId != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.RewardProgramId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { - offset -= sovQuery(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *QueryRewardProgramByIDRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Id != 0 { - n += 1 + sovQuery(uint64(m.Id)) - } - return n -} - -func (m *QueryRewardProgramByIDResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardProgram != nil { - l = m.RewardProgram.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryRewardProgramsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.QueryType != 0 { - n += 1 + sovQuery(uint64(m.QueryType)) - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 2 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryRewardProgramsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.RewardPrograms) > 0 { - for _, e := range m.RewardPrograms { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 2 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryClaimPeriodRewardDistributionsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Pagination != nil { - l = m.Pagination.Size() - n += 2 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryClaimPeriodRewardDistributionsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.ClaimPeriodRewardDistributions) > 0 { - for _, e := range m.ClaimPeriodRewardDistributions { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 2 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardId != 0 { - n += 1 + sovQuery(uint64(m.RewardId)) - } - if m.ClaimPeriodId != 0 { - n += 1 + sovQuery(uint64(m.ClaimPeriodId)) - } - return n -} - -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ClaimPeriodRewardDistribution != nil { - l = m.ClaimPeriodRewardDistribution.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryRewardDistributionsByAddressRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Address) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.ClaimStatus != 0 { - n += 1 + sovQuery(uint64(m.ClaimStatus)) - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 2 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryRewardDistributionsByAddressResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Address) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if len(m.RewardAccountState) > 0 { - for _, e := range m.RewardAccountState { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - if m.Pagination != nil { - l = m.Pagination.Size() - n += 2 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *RewardAccountResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardProgramId != 0 { - n += 1 + sovQuery(uint64(m.RewardProgramId)) - } - l = m.TotalRewardClaim.Size() - n += 1 + l + sovQuery(uint64(l)) - if m.ClaimStatus != 0 { - n += 1 + sovQuery(uint64(m.ClaimStatus)) - } - if m.ClaimId != 0 { - n += 1 + sovQuery(uint64(m.ClaimId)) - } - return n -} - -func sovQuery(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozQuery(x uint64) (n int) { - return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *QueryRewardProgramByIDRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryRewardProgramByIDRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardProgramByIDRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryRewardProgramByIDResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryRewardProgramByIDResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardProgramByIDResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgram", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.RewardProgram == nil { - m.RewardProgram = &RewardProgram{} - } - if err := m.RewardProgram.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryRewardProgramsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryRewardProgramsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardProgramsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field QueryType", wireType) - } - m.QueryType = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.QueryType |= QueryRewardProgramsRequest_QueryType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 99: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryRewardProgramsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryRewardProgramsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardProgramsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardPrograms", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardPrograms = append(m.RewardPrograms, RewardProgram{}) - if err := m.RewardPrograms[len(m.RewardPrograms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 99: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryClaimPeriodRewardDistributionsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 99: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryClaimPeriodRewardDistributionsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodRewardDistributions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClaimPeriodRewardDistributions = append(m.ClaimPeriodRewardDistributions, ClaimPeriodRewardDistribution{}) - if err := m.ClaimPeriodRewardDistributions[len(m.ClaimPeriodRewardDistributions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 99: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryClaimPeriodRewardDistributionsByIDRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsByIDRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsByIDRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardId", wireType) - } - m.RewardId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodId", wireType) - } - m.ClaimPeriodId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriodId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryClaimPeriodRewardDistributionsByIDResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsByIDResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryClaimPeriodRewardDistributionsByIDResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodRewardDistribution", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.ClaimPeriodRewardDistribution == nil { - m.ClaimPeriodRewardDistribution = &ClaimPeriodRewardDistribution{} - } - if err := m.ClaimPeriodRewardDistribution.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryRewardDistributionsByAddressRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryRewardDistributionsByAddressRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardDistributionsByAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimStatus", wireType) - } - m.ClaimStatus = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimStatus |= RewardAccountState_ClaimStatus(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 99: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageRequest{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryRewardDistributionsByAddressResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryRewardDistributionsByAddressResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryRewardDistributionsByAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardAccountState", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardAccountState = append(m.RewardAccountState, RewardAccountResponse{}) - if err := m.RewardAccountState[len(m.RewardAccountState)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 99: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Pagination == nil { - m.Pagination = &query.PageResponse{} - } - if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RewardAccountResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RewardAccountResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RewardAccountResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgramId", wireType) - } - m.RewardProgramId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardProgramId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalRewardClaim", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.TotalRewardClaim.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimStatus", wireType) - } - m.ClaimStatus = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimStatus |= RewardAccountState_ClaimStatus(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimId", wireType) - } - m.ClaimId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipQuery(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthQuery - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupQuery - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthQuery - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/reward/types/query.pb.gw.go b/x/reward/types/query.pb.gw.go deleted file mode 100644 index b4df807957..0000000000 --- a/x/reward/types/query.pb.gw.go +++ /dev/null @@ -1,597 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: provenance/reward/v1/query.proto - -/* -Package types is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package types - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage -var _ = metadata.Join - -func request_Query_RewardProgramByID_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardProgramByIDRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := client.RewardProgramByID(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_RewardProgramByID_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardProgramByIDRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := server.RewardProgramByID(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Query_RewardPrograms_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_RewardPrograms_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardProgramsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RewardPrograms_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RewardPrograms(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_RewardPrograms_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardProgramsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RewardPrograms_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RewardPrograms(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Query_ClaimPeriodRewardDistributions_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_ClaimPeriodRewardDistributions_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryClaimPeriodRewardDistributionsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ClaimPeriodRewardDistributions_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.ClaimPeriodRewardDistributions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_ClaimPeriodRewardDistributions_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryClaimPeriodRewardDistributionsRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ClaimPeriodRewardDistributions_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.ClaimPeriodRewardDistributions(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_ClaimPeriodRewardDistributionsByID_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryClaimPeriodRewardDistributionsByIDRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["reward_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "reward_id") - } - - protoReq.RewardId, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "reward_id", err) - } - - val, ok = pathParams["claim_period_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "claim_period_id") - } - - protoReq.ClaimPeriodId, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "claim_period_id", err) - } - - msg, err := client.ClaimPeriodRewardDistributionsByID(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_ClaimPeriodRewardDistributionsByID_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryClaimPeriodRewardDistributionsByIDRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["reward_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "reward_id") - } - - protoReq.RewardId, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "reward_id", err) - } - - val, ok = pathParams["claim_period_id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "claim_period_id") - } - - protoReq.ClaimPeriodId, err = runtime.Uint64(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "claim_period_id", err) - } - - msg, err := server.ClaimPeriodRewardDistributionsByID(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Query_RewardDistributionsByAddress_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} -) - -func request_Query_RewardDistributionsByAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardDistributionsByAddressRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["address"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") - } - - protoReq.Address, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RewardDistributionsByAddress_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RewardDistributionsByAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_RewardDistributionsByAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryRewardDistributionsByAddressRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["address"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") - } - - protoReq.Address, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RewardDistributionsByAddress_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RewardDistributionsByAddress(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". -// UnaryRPC :call QueryServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. -func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - - mux.Handle("GET", pattern_Query_RewardProgramByID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_RewardProgramByID_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_RewardProgramByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_RewardPrograms_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_RewardPrograms_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_RewardPrograms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_ClaimPeriodRewardDistributions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_ClaimPeriodRewardDistributions_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_ClaimPeriodRewardDistributions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_ClaimPeriodRewardDistributionsByID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_ClaimPeriodRewardDistributionsByID_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_ClaimPeriodRewardDistributionsByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_RewardDistributionsByAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_RewardDistributionsByAddress_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_RewardDistributionsByAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterQueryHandler(ctx, mux, conn) -} - -// RegisterQueryHandler registers the http handlers for service Query to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) -} - -// RegisterQueryHandlerClient registers the http handlers for service Query -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "QueryClient" to call the correct interceptors. -func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - - mux.Handle("GET", pattern_Query_RewardProgramByID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_RewardProgramByID_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_RewardProgramByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_RewardPrograms_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_RewardPrograms_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_RewardPrograms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_ClaimPeriodRewardDistributions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_ClaimPeriodRewardDistributions_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_ClaimPeriodRewardDistributions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_ClaimPeriodRewardDistributionsByID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_ClaimPeriodRewardDistributionsByID_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_ClaimPeriodRewardDistributionsByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_RewardDistributionsByAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_RewardDistributionsByAddress_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_RewardDistributionsByAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Query_RewardProgramByID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"provenance", "rewards", "v1", "reward_programs", "id"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_RewardPrograms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"provenance", "rewards", "v1", "reward_programs"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_ClaimPeriodRewardDistributions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"provenance", "rewards", "v1", "claim_period_reward_distributions"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_ClaimPeriodRewardDistributionsByID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5, 1, 0, 4, 1, 5, 6}, []string{"provenance", "rewards", "v1", "claim_period_reward_distributions", "reward_id", "claim_periods", "claim_period_id"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_RewardDistributionsByAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"provenance", "rewards", "v1", "reward_claims", "address"}, "", runtime.AssumeColonVerbOpt(false))) -) - -var ( - forward_Query_RewardProgramByID_0 = runtime.ForwardResponseMessage - - forward_Query_RewardPrograms_0 = runtime.ForwardResponseMessage - - forward_Query_ClaimPeriodRewardDistributions_0 = runtime.ForwardResponseMessage - - forward_Query_ClaimPeriodRewardDistributionsByID_0 = runtime.ForwardResponseMessage - - forward_Query_RewardDistributionsByAddress_0 = runtime.ForwardResponseMessage -) diff --git a/x/reward/types/reward.go b/x/reward/types/reward.go deleted file mode 100644 index 205676f41b..0000000000 --- a/x/reward/types/reward.go +++ /dev/null @@ -1,669 +0,0 @@ -package types - -import ( - "errors" - fmt "fmt" - "reflect" - "strings" - time "time" - - sdkmath "cosmossdk.io/math" - "github.com/provenance-io/provenance/internal/helpers" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - "github.com/provenance-io/provenance/internal/pioconfig" -) - -// DefaultStartingRewardProgramID is 1 -const DefaultStartingRewardProgramID uint64 = 1 - -// Constants pertaining to a RewardProgram object -const ( - MaxDescriptionLength int = 10000 - MaxTitleLength int = 140 - DayInSeconds int = 60 * 60 * 24 -) - -var ( - _ RewardAction = &ActionDelegate{} - _ RewardAction = &ActionTransfer{} - _ RewardAction = &ActionVote{} -) - -const ( - ActionTypeDelegate = "ActionDelegate" - ActionTypeTransfer = "ActionTransfer" - ActionTypeVote = "ActionVote" -) - -// RewardAction defines the interface that actions need to implement -type RewardAction interface { - // ActionType returns a string identifying this action type. - ActionType() string - // Evaluate returns true if this reward action satisfies the provided state and event. - Evaluate(ctx sdk.Context, provider KeeperProvider, state RewardAccountState, evaluationResult EvaluationResult) bool - // PreEvaluate returns true if this reward action is in a state that's ready for evaluation. - PreEvaluate(ctx sdk.Context, provider KeeperProvider, state RewardAccountState) bool - // PostEvaluate returns true if the all the action's post evaluation checks are met and allows the action to update the evaluation result as needed by the Action. - PostEvaluate(ctx sdk.Context, provider KeeperProvider, state RewardAccountState, evaluationResult EvaluationResult) (bool, EvaluationResult) - // GetBuilder returns a new ActionBuilder for this reward action. - GetBuilder() ActionBuilder -} - -// ============ Shared structs ============ - -type ABCIEvent struct { - Type string - Attributes map[string][]byte // TODO[1760]: reward: Use strings here since attributes switched to strings. -} - -type EventCriteria struct { - Events map[string]ABCIEvent -} - -// NewEventCriteria Performs a shallow copy of the map -// We are assuming this takes ownership of events -func NewEventCriteria(events []ABCIEvent) *EventCriteria { - criteria := EventCriteria{} - if len(events) == 0 { - return &criteria - } - criteria.Events = make(map[string]ABCIEvent) - for _, event := range events { - criteria.Events[event.Type] = event - } - return &criteria -} - -// MatchesEvent returns true if this EventCriteria's events contains the -// provided event type or if this EventCriteria's doesn't have any events. -func (ec *EventCriteria) MatchesEvent(eventType string) bool { - // If we have no Events then we match everything - if ec.Events == nil { - return true - } - - // If we don't have the event then we don't match it - _, exists := ec.Events[eventType] - return exists -} - -// MatchesAttribute returns true if this ABCIEvent has an attribute that matches the provided key and value. -// The value is only compared if this ABCIEvent's attribute has a value. -func (ec *ABCIEvent) MatchesAttribute(name string, value []byte) bool { - attribute, exists := ec.Attributes[name] - if !exists { - return false - } - // for dynamic properties like sender we will never know the value, hence a zero byte check will return true too - return attribute == nil || reflect.DeepEqual(attribute, value) -} - -type EvaluationResult struct { - EventTypeToSearch string - AttributeKey string - Shares int64 - Address sdk.AccAddress // shares to attribute to this address - Validator sdk.ValAddress // Address of the validator - Delegator sdk.AccAddress // Address of the delegator - Recipient sdk.AccAddress // Address of the recipient of the Action, specifically Transfer -} - -// ============ Reward Program ============ - -func NewRewardProgram( - title string, - description string, - id uint64, - distributeFromAddress string, - totalRewardPool sdk.Coin, - maxRewardByAddress sdk.Coin, - programStartTime time.Time, - claimPeriodSeconds uint64, - claimPeriods uint64, - maxRolloverClaimPeriods uint64, - rewardClaimExpirationOffset uint64, - qualifyingActions []QualifyingAction, -) RewardProgram { - expectedProgramEndTime := CalculateExpectedEndTime(programStartTime.UTC(), claimPeriodSeconds, claimPeriods).UTC() - programEndTimeMax := CalculateEndTimeMax(programStartTime.UTC(), claimPeriodSeconds, claimPeriods, maxRolloverClaimPeriods).UTC() - var minimumRolloverAmount sdk.Coin - if claimPeriods >= 1 { - minimumRolloverAmount = sdk.NewInt64Coin(totalRewardPool.Denom, Percent(10, totalRewardPool.Amount.QuoRaw(int64(claimPeriods)).Int64())) - } - - return RewardProgram{ - Title: title, - Description: description, - Id: id, - DistributeFromAddress: distributeFromAddress, - TotalRewardPool: totalRewardPool, - RemainingPoolBalance: totalRewardPool, - ClaimedAmount: sdk.NewInt64Coin(totalRewardPool.Denom, 0), - MaxRewardByAddress: maxRewardByAddress, - ProgramStartTime: programStartTime.UTC(), - ExpectedProgramEndTime: expectedProgramEndTime.UTC(), - ProgramEndTimeMax: programEndTimeMax.UTC(), - ClaimPeriodSeconds: claimPeriodSeconds, - ClaimPeriods: claimPeriods, - MaxRolloverClaimPeriods: maxRolloverClaimPeriods, - ExpirationOffset: rewardClaimExpirationOffset, - State: RewardProgram_STATE_PENDING, - QualifyingActions: qualifyingActions, - // Hard coded to 10% of distribution amount by claim period - // claim periods cannot be 0, if validate is run in RewardProgram object - MinimumRolloverAmount: minimumRolloverAmount, - } -} - -// IsStarting checks the state of the reward program and determines if it has started -func (rp *RewardProgram) IsStarting(ctx sdk.Context) bool { - blockTime := ctx.BlockTime() - return rp.State == RewardProgram_STATE_PENDING && (blockTime.After(rp.ProgramStartTime) || blockTime.Equal(rp.ProgramStartTime)) -} - -// IsEndingClaimPeriod returns if claim period has ended for a running reward program -func (rp *RewardProgram) IsEndingClaimPeriod(ctx sdk.Context) bool { - blockTime := ctx.BlockTime() - return rp.State == RewardProgram_STATE_STARTED && (blockTime.After(rp.ClaimPeriodEndTime) || blockTime.Equal(rp.ClaimPeriodEndTime)) -} - -// IsExpiring returns if reward program has expired for a finished reward program -func (rp *RewardProgram) IsExpiring(ctx sdk.Context) bool { - blockTime := ctx.BlockTime() - expireTime := rp.ActualProgramEndTime.Add(time.Second * time.Duration(rp.ExpirationOffset)) - return rp.State == RewardProgram_STATE_FINISHED && (blockTime.After(expireTime) || blockTime.Equal(expireTime)) -} - -// IsEnding returns if a reward program has ended for a running program -func (rp *RewardProgram) IsEnding(ctx sdk.Context, programBalance sdk.Coin) bool { - blockTime := ctx.BlockTime() - isProgramEnding := !rp.GetProgramEndTimeMax().IsZero() && (blockTime.After(rp.ProgramEndTimeMax) || blockTime.Equal(rp.ProgramEndTimeMax)) - canRollover := programBalance.IsGTE(rp.GetMinimumRolloverAmount()) - return rp.State == RewardProgram_STATE_STARTED && (isProgramEnding || !canRollover) -} - -// MatchesState returns if a reward program is in one of the passed in states. It will return true if states is empty. -func (rp *RewardProgram) MatchesState(states []RewardProgram_State) bool { - if len(states) == 0 { - return true - } - - for _, state := range states { - if rp.State == state { - return true - } - } - return false -} - -// Percent calculate percentage but take off any decimal points -func Percent(percent int64, all int64) int64 { - return (all * percent) / 100 -} - -func (rp *RewardProgram) Validate() error { - title := rp.GetTitle() - if len(strings.TrimSpace(title)) == 0 { - return errors.New("reward program title cannot be blank") - } - if len(title) > MaxTitleLength { - return fmt.Errorf("reward program title is longer than max length of %d", MaxTitleLength) - } - description := rp.GetDescription() - if len(description) == 0 { - return errors.New("reward program description cannot be blank") - } - if len(description) > MaxDescriptionLength { - return fmt.Errorf("reward program description is longer than max length of %d", MaxDescriptionLength) - } - if rp.Id < 1 { - return errors.New("reward program id must be larger than 0") - } - if _, err := sdk.AccAddressFromBech32(rp.DistributeFromAddress); err != nil { - return fmt.Errorf("invalid address for rewards program distribution from address: %w", err) - } - if !rp.TotalRewardPool.IsPositive() { - return fmt.Errorf("reward program requires coins: %v", rp.TotalRewardPool) - } - if !rp.MaxRewardByAddress.IsPositive() { - return fmt.Errorf("reward program requires positive max reward by address: %v", rp.MaxRewardByAddress) - } - if rp.ClaimPeriods < 1 { - return errors.New("reward program number of claim periods must be larger than 0") - } - if rp.TotalRewardPool.Denom != rp.RemainingPoolBalance.Denom && rp.RemainingPoolBalance.Denom != rp.MaxRewardByAddress.Denom { - return fmt.Errorf("all denoms must be same for total reward pool (%s) remaining reward pool (%s) and max reward by address (%s)", rp.TotalRewardPool.Denom, rp.RemainingPoolBalance.Denom, rp.MaxRewardByAddress.Denom) - } - if len(rp.QualifyingActions) == 0 { - return errors.New("reward program must have at least one qualifying action") - } - for _, qa := range rp.QualifyingActions { - if err := qa.Validate(); err != nil { - return err - } - } - return nil -} - -// ============ Account State ============ - -func NewRewardAccountState(rewardProgramID, rewardClaimPeriodID uint64, address string, shares uint64, actionCounter []*ActionCounter) RewardAccountState { - return RewardAccountState{ - RewardProgramId: rewardProgramID, - ClaimPeriodId: rewardClaimPeriodID, - Address: address, - ActionCounter: actionCounter, - SharesEarned: shares, - ClaimStatus: RewardAccountState_CLAIM_STATUS_UNCLAIMABLE, - } -} - -func (s *RewardAccountState) Validate() error { - if _, err := sdk.AccAddressFromBech32(s.Address); err != nil { - return fmt.Errorf("invalid address for share address: %w", err) - } - if id := s.GetRewardProgramId(); id == 0 { - return fmt.Errorf("reward program id must be greater than 0") - } - if claimID := s.GetClaimPeriodId(); claimID == 0 { - return fmt.Errorf("claim period id must be greater than 0") - } - - return nil -} - -// CalculateExpectedEndTime returns the expected end time (in UTC). -// expected end time = programStartTime + claimPeriodSeconds * numberOfClaimPeriods. -func CalculateExpectedEndTime(programStartTime time.Time, claimPeriodSeconds, numberOfClaimPeriods uint64) time.Time { - return programStartTime.Add(time.Duration(claimPeriodSeconds*numberOfClaimPeriods) * time.Second).UTC() -} - -// CalculateEndTimeMax returns the latest time that a program can end (in UTC). -// end time max = programStartTime + claimPeriodSeconds * (numberOfClaimPeriods + maxRolloverPeriods). -func CalculateEndTimeMax(programStartTime time.Time, claimPeriodSeconds, numberOfClaimPeriods uint64, maxRolloverPeriods uint64) time.Time { - return programStartTime.Add(time.Duration(claimPeriodSeconds*(numberOfClaimPeriods+maxRolloverPeriods)) * time.Second).UTC() -} - -// TimeOnOrAfter compares day1 with day2 and returns true if the time of day2 is on or after the time of day1 ignoring time part. -func TimeOnOrAfter(day1 time.Time, day2 time.Time) bool { - return day1.Before(day2) || day1.Equal(day2) -} - -// ============ Claim Period Reward Distribution ============ - -func NewClaimPeriodRewardDistribution(claimPeriodID uint64, rewardProgramID uint64, rewardsPool, totalRewardsPoolForClaimPeriod sdk.Coin, totalShares int64, claimPeriodEnded bool) ClaimPeriodRewardDistribution { - return ClaimPeriodRewardDistribution{ - ClaimPeriodId: claimPeriodID, - RewardProgramId: rewardProgramID, - RewardsPool: rewardsPool, - TotalRewardsPoolForClaimPeriod: totalRewardsPoolForClaimPeriod, - TotalShares: totalShares, - ClaimPeriodEnded: claimPeriodEnded, - } -} - -func (erd *ClaimPeriodRewardDistribution) Validate() error { - if erd.ClaimPeriodId <= 0 { - return errors.New("claim reward distribution has invalid claim id") - } - if erd.RewardProgramId < 1 { - return errors.New("claim reward distribution must have a valid reward program id") - } - if !erd.TotalRewardsPoolForClaimPeriod.IsPositive() && !erd.TotalRewardsPoolForClaimPeriod.IsZero() { - return errors.New("claim reward distribution must have a total reward pool") - } - if !erd.RewardsPool.IsPositive() { - return errors.New("claim reward distribution must have a reward pool which is positive") - } - return nil -} - -// ============ Action Delegate ============ - -func NewActionDelegate() ActionDelegate { - return ActionDelegate{} -} - -func (ad *ActionDelegate) Validate() error { - if ad.MinimumActions > ad.MaximumActions { - return errors.New("minimum action cannot be greater than maximum actions") - } - if ad.MaximumActions < 1 { - return errors.New("maximum action must be greater than 0 actions") - } - if ad.MinimumDelegationAmount != nil && ad.MaximumDelegationAmount != nil && ad.MaximumDelegationAmount.IsLT(*ad.MinimumDelegationAmount) { - return errors.New("maximum delegation amount cannot be less than minimum delegation amount") - } - - if ad.MaximumActiveStakePercentile.LT(ad.MinimumActiveStakePercentile) { - return errors.New("maximum active stake percentile cannot be less than minimum active stake percentile") - } - return nil -} - -func (ad *ActionDelegate) ActionType() string { - return ActionTypeDelegate -} - -func (ad *ActionDelegate) GetBuilder() ActionBuilder { - return &DelegateActionBuilder{} -} - -func (ad *ActionDelegate) getTokensFromValidator(ctx sdk.Context, provider KeeperProvider, validatorAddr sdk.ValAddress, delegator sdk.AccAddress) (sdkmath.LegacyDec, bool) { - stakingKeeper := provider.GetStakingKeeper() - delegation, err := stakingKeeper.GetDelegation(ctx, delegator, validatorAddr) - if err != nil { - return sdkmath.LegacyNewDec(0), false - } - validator, err := stakingKeeper.GetValidator(ctx, validatorAddr) - if err != nil { - return sdkmath.LegacyNewDec(0), false - } - tokens := validator.TokensFromShares(delegation.GetShares()) - return tokens, true -} - -// The percentile is dictated by the powers of the validators -// If there are 5 validators and the first validator matches then that validator is in the 80th percentile -// If there is 1 validator then that validator is in the 0 percentile. -func (ad *ActionDelegate) getValidatorRankPercentile(ctx sdk.Context, provider KeeperProvider, validator sdk.ValAddress) sdkmath.LegacyDec { - validators, err := provider.GetStakingKeeper().GetBondedValidatorsByPower(ctx) - if err != nil { - return sdkmath.LegacyNewDec(0) - } - ourPower, err := provider.GetStakingKeeper().GetLastValidatorPower(ctx, validator) - if err != nil { - return sdkmath.LegacyNewDec(0) - } - var numBelow int64 - numValidators := int64(len(validators)) - for i := int64(0); i < numValidators; i++ { - v := validators[i] - vAddr, err := helpers.GetOperatorAddr(v) - if err != nil { - numBelow++ - continue - } - power, err := provider.GetStakingKeeper().GetLastValidatorPower(ctx, vAddr) - if err != nil || power < ourPower { - numBelow++ - } - } - placement := sdkmath.LegacyNewDec(numBelow) - vals := sdkmath.LegacyNewDec(numValidators) - percentile := placement.Quo(vals) - - return percentile -} - -func (ad *ActionDelegate) Evaluate(ctx sdk.Context, provider KeeperProvider, _ RewardAccountState, event EvaluationResult) bool { - validator := event.Validator - delegator := event.Delegator - - tokens, found := ad.getTokensFromValidator(ctx, provider, validator, delegator) - if !found { - return false - } - percentile := ad.getValidatorRankPercentile(ctx, provider, validator) - - delegatedHash := sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, tokens.TruncateInt64()) - minDelegation := ad.GetMinimumDelegationAmount() - maxDelegation := ad.GetMaximumDelegationAmount() - minPercentile := ad.GetMinimumActiveStakePercentile() - maxPercentile := ad.GetMaximumActiveStakePercentile() - - hasValidDelegationAmount := delegatedHash.IsGTE(*minDelegation) && (delegatedHash.IsLT(*maxDelegation) || delegatedHash.Equal(*maxDelegation)) - hasValidActivePercentile := percentile.GTE(minPercentile) && percentile.LTE(maxPercentile) - - return hasValidDelegationAmount && hasValidActivePercentile -} - -// GetMinimumActiveStakePercentile returns this action's minimum active stake percentile or zero if not defined. -func (ad *ActionDelegate) GetMinimumActiveStakePercentile() sdkmath.LegacyDec { - if ad != nil { - return ad.MinimumActiveStakePercentile - } - return sdkmath.LegacyNewDec(0) -} - -// GetMaximumActiveStakePercentile returns this action's maximum active stake percentile or zero if not defined. -func (ad *ActionDelegate) GetMaximumActiveStakePercentile() sdkmath.LegacyDec { - if ad != nil { - return ad.MaximumActiveStakePercentile - } - return sdkmath.LegacyNewDec(0) -} - -func (ad *ActionDelegate) PreEvaluate(_ sdk.Context, _ KeeperProvider, _ RewardAccountState) bool { - return true -} - -func (ad *ActionDelegate) PostEvaluate(_ sdk.Context, _ KeeperProvider, state RewardAccountState, event EvaluationResult) (bool, EvaluationResult) { - actionCounter := GetActionCount(state.ActionCounter, ad.ActionType()) - hasValidActionCount := actionCounter >= ad.GetMinimumActions() && actionCounter <= ad.GetMaximumActions() - return hasValidActionCount, event -} - -// ============ Action Transfer Delegations ============ - -func NewActionTransfer() ActionTransfer { - return ActionTransfer{} -} - -func (at *ActionTransfer) Validate() error { - if at.MinimumActions > at.MaximumActions { - return errors.New("minimum action cannot be greater than maximum actions") - } - if at.MaximumActions < 1 { - return errors.New("maximum action must be greater than 0 actions") - } - return nil -} - -func (at *ActionTransfer) GetBuilder() ActionBuilder { - return &TransferActionBuilder{} -} - -func (at *ActionTransfer) ActionType() string { - return ActionTypeTransfer -} - -func (at *ActionTransfer) Evaluate(ctx sdk.Context, provider KeeperProvider, _ RewardAccountState, event EvaluationResult) bool { - // get the address that is performing the send - addressSender := event.Address - if addressSender == nil { - return false - } - if provider.GetAccountKeeper().GetModuleAddress(authtypes.FeeCollectorName).Equals(event.Recipient) { - return false - } - // check delegations if and only if mandated by the Action - if sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 0).IsLT(at.MinimumDelegationAmount) { - // now check if it has any delegations - totalDelegations, found := getAllDelegations(ctx, provider, addressSender) - if !found { - return false - } - if totalDelegations.IsGTE(at.MinimumDelegationAmount) { - return true - } - return false - } - return true -} - -func (at *ActionTransfer) PreEvaluate(_ sdk.Context, _ KeeperProvider, _ RewardAccountState) bool { - return true -} - -func (at *ActionTransfer) PostEvaluate(_ sdk.Context, _ KeeperProvider, state RewardAccountState, evaluationResult EvaluationResult) (bool, EvaluationResult) { - actionCounter := GetActionCount(state.ActionCounter, at.ActionType()) - hasValidActionCount := actionCounter >= at.GetMinimumActions() && actionCounter <= at.GetMaximumActions() - return hasValidActionCount, evaluationResult -} - -// ============ Action Vote ============ - -func NewActionVote() ActionVote { - return ActionVote{} -} - -func (atd *ActionVote) Validate() error { - if atd.MinimumActions > atd.MaximumActions { - return errors.New("minimum action cannot be greater than maximum actions") - } - if atd.MaximumActions < 1 { - return errors.New("maximum action must be greater than 0 actions") - } - return nil -} - -func (atd *ActionVote) GetBuilder() ActionBuilder { - return &VoteActionBuilder{} -} - -func (atd *ActionVote) ActionType() string { - return ActionTypeVote -} - -func (atd *ActionVote) Evaluate(ctx sdk.Context, provider KeeperProvider, _ RewardAccountState, event EvaluationResult) bool { - // get the address that voted - addressVoting := event.Address - if !sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 0).IsGTE(atd.MinimumDelegationAmount) { - // now check if it has any delegations - totalDelegations, found := getAllDelegations(ctx, provider, addressVoting) - if !found { - return false - } - if totalDelegations.IsGTE(atd.MinimumDelegationAmount) { - return true - } - return false - } - return true -} - -func (atd *ActionVote) PreEvaluate(_ sdk.Context, _ KeeperProvider, _ RewardAccountState) bool { - return true -} - -func (atd *ActionVote) PostEvaluate(ctx sdk.Context, provider KeeperProvider, state RewardAccountState, evaluationResult EvaluationResult) (bool, EvaluationResult) { - actionCounter := GetActionCount(state.ActionCounter, atd.ActionType()) - hasValidActionCount := actionCounter >= atd.GetMinimumActions() && actionCounter <= atd.GetMaximumActions() - // get the address that voted, and see if the multiplier needs to be applied if the vote came from a validator. - addressVoting := evaluationResult.Address - valAddrStr := sdk.ValAddress(addressVoting) - _, err := provider.GetStakingKeeper().GetValidator(ctx, valAddrStr) - if err == nil && atd.ValidatorMultiplier > 0 { - // shares can be negative, as per requirements, and this may lead to negative shares with multiplier. - evaluationResult.Shares *= int64(atd.ValidatorMultiplier) - } - - return hasValidActionCount, evaluationResult -} - -// ============ Qualifying Action ============ - -func (qa *QualifyingAction) Validate() (isValid error) { - switch actionType := qa.GetType().(type) { - case *QualifyingAction_Delegate: - isValid = qa.GetDelegate().Validate() - case *QualifyingAction_Transfer: - isValid = qa.GetTransfer().Validate() - case *QualifyingAction_Vote: - isValid = qa.GetVote().Validate() - default: - // Skip any unsupported actions - message := fmt.Sprintf("The Action type %s is not supported", actionType) - isValid = errors.New(message) - } - return isValid -} - -// GetRewardAction returns the reward action for this qualifying action. -// An error is returned if the action is of an unexpected type. -func (qa *QualifyingAction) GetRewardAction(ctx sdk.Context) (RewardAction, error) { - var action RewardAction - - switch actionType := qa.GetType().(type) { - case *QualifyingAction_Delegate: - action = qa.GetDelegate() - case *QualifyingAction_Transfer: - action = qa.GetTransfer() - case *QualifyingAction_Vote: - action = qa.GetVote() - default: - // Skip any unsupported actions - message := fmt.Sprintf("The Action type %s is not supported", actionType) - return nil, errors.New(message) - } - - ctx.Logger().Info(fmt.Sprintf("The Action type is %s", action.ActionType())) - - return action, nil -} - -// getAllDelegations pure functions to get delegated coins for an address -// return total coin delegated and boolean to indicate if any delegations are at all present. -func getAllDelegations(ctx sdk.Context, provider KeeperProvider, delegator sdk.AccAddress) (sdk.Coin, bool) { - stakingKeeper := provider.GetStakingKeeper() - delegations, err := stakingKeeper.GetAllDelegatorDelegations(ctx, delegator) - // if no delegations then return not found - if err != nil || len(delegations) == 0 { - return sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 0), false - } - - sum := sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 0) - - for _, delegation := range delegations { - valAddr, err := sdk.ValAddressFromBech32(delegation.GetValidatorAddr()) - if err != nil { - continue - } - val, err := stakingKeeper.GetValidator(ctx, valAddr) - if err == nil { - tokens := val.TokensFromShares(delegation.GetShares()).TruncateInt() - sum = sum.Add(sdk.NewCoin(pioconfig.GetProvenanceConfig().BondDenom, tokens)) - } - } - - if sum.Amount.Equal(sdkmath.ZeroInt()) { - return sum, false - } - return sum, true -} - -// GetActionCount convenience method to find NumberOfActions for a given action type from a ActionCounter Slice -func GetActionCount(actionCounter []*ActionCounter, actionType string) uint64 { - // nil slices are automatically checked for by golang range, so no need to check for nil explicitly https://go.dev/play/p/BwaVSIHclPm - for i := range actionCounter { - if actionCounter[i].ActionType == actionType { - // Found return counter - return actionCounter[i].GetNumberOfActions() - } - } - return 0 -} - -// IncrementActionCount convenience method to increment NumberOfActions for a given action type by 1(for now) and return an ActionCounter Slice -// if action type not found will create one and append to slice and return slice. -func IncrementActionCount(actionCounter []*ActionCounter, actionType string) []*ActionCounter { - // nil slices are automatically checked for by golang range, so no need to check for nil explicitly https://go.dev/play/p/BwaVSIHclPm - for i := range actionCounter { - // if found increment counter - if actionCounter[i].ActionType == actionType { - // Found return counter - actionCounter[i].NumberOfActions = actionCounter[i].GetNumberOfActions() + 1 - return actionCounter - } - } - // if not found create one and add - actionCounter = append(actionCounter, &ActionCounter{ - ActionType: actionType, - NumberOfActions: 1, - }) - return actionCounter -} diff --git a/x/reward/types/reward.pb.go b/x/reward/types/reward.pb.go deleted file mode 100644 index 667f4cac2a..0000000000 --- a/x/reward/types/reward.pb.go +++ /dev/null @@ -1,4344 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: provenance/reward/v1/reward.proto - -package types - -import ( - cosmossdk_io_math "cosmossdk.io/math" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" - github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" - _ "google.golang.org/protobuf/types/known/timestamppb" - io "io" - math "math" - math_bits "math/bits" - time "time" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf -var _ = time.Kitchen - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// State is the state of the reward program -type RewardProgram_State int32 - -const ( - // undefined program state - RewardProgram_STATE_UNSPECIFIED RewardProgram_State = 0 - // pending state of reward program - RewardProgram_STATE_PENDING RewardProgram_State = 1 - // started state of reward program - RewardProgram_STATE_STARTED RewardProgram_State = 2 - // finished state of reward program - RewardProgram_STATE_FINISHED RewardProgram_State = 3 - // expired state of reward program - RewardProgram_STATE_EXPIRED RewardProgram_State = 4 -) - -var RewardProgram_State_name = map[int32]string{ - 0: "STATE_UNSPECIFIED", - 1: "STATE_PENDING", - 2: "STATE_STARTED", - 3: "STATE_FINISHED", - 4: "STATE_EXPIRED", -} - -var RewardProgram_State_value = map[string]int32{ - "STATE_UNSPECIFIED": 0, - "STATE_PENDING": 1, - "STATE_STARTED": 2, - "STATE_FINISHED": 3, - "STATE_EXPIRED": 4, -} - -func (x RewardProgram_State) String() string { - return proto.EnumName(RewardProgram_State_name, int32(x)) -} - -func (RewardProgram_State) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{0, 0} -} - -// ClaimStatus is the state a claim is in -type RewardAccountState_ClaimStatus int32 - -const ( - // undefined state - RewardAccountState_CLAIM_STATUS_UNSPECIFIED RewardAccountState_ClaimStatus = 0 - // unclaimable status - RewardAccountState_CLAIM_STATUS_UNCLAIMABLE RewardAccountState_ClaimStatus = 1 - // unclaimable claimable - RewardAccountState_CLAIM_STATUS_CLAIMABLE RewardAccountState_ClaimStatus = 2 - // unclaimable claimed - RewardAccountState_CLAIM_STATUS_CLAIMED RewardAccountState_ClaimStatus = 3 - // unclaimable expired - RewardAccountState_CLAIM_STATUS_EXPIRED RewardAccountState_ClaimStatus = 4 -) - -var RewardAccountState_ClaimStatus_name = map[int32]string{ - 0: "CLAIM_STATUS_UNSPECIFIED", - 1: "CLAIM_STATUS_UNCLAIMABLE", - 2: "CLAIM_STATUS_CLAIMABLE", - 3: "CLAIM_STATUS_CLAIMED", - 4: "CLAIM_STATUS_EXPIRED", -} - -var RewardAccountState_ClaimStatus_value = map[string]int32{ - "CLAIM_STATUS_UNSPECIFIED": 0, - "CLAIM_STATUS_UNCLAIMABLE": 1, - "CLAIM_STATUS_CLAIMABLE": 2, - "CLAIM_STATUS_CLAIMED": 3, - "CLAIM_STATUS_EXPIRED": 4, -} - -func (x RewardAccountState_ClaimStatus) String() string { - return proto.EnumName(RewardAccountState_ClaimStatus_name, int32(x)) -} - -func (RewardAccountState_ClaimStatus) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{2, 0} -} - -// RewardProgram -type RewardProgram struct { - // An integer to uniquely identify the reward program. - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - // Name to help identify the Reward Program.(MaxTitleLength=140) - Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` - // Short summary describing the Reward Program.(MaxDescriptionLength=10000) - Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` - // address that provides funds for the total reward pool. - DistributeFromAddress string `protobuf:"bytes,4,opt,name=distribute_from_address,json=distributeFromAddress,proto3" json:"distribute_from_address,omitempty"` - // The total amount of funding given to the RewardProgram. - TotalRewardPool types.Coin `protobuf:"bytes,5,opt,name=total_reward_pool,json=totalRewardPool,proto3" json:"total_reward_pool"` - // The remaining funds available to distribute after n claim periods have passed. - RemainingPoolBalance types.Coin `protobuf:"bytes,6,opt,name=remaining_pool_balance,json=remainingPoolBalance,proto3" json:"remaining_pool_balance"` - // The total amount of all funds claimed by participants for all past claim periods. - ClaimedAmount types.Coin `protobuf:"bytes,7,opt,name=claimed_amount,json=claimedAmount,proto3" json:"claimed_amount"` - // Maximum reward per claim period per address. - MaxRewardByAddress types.Coin `protobuf:"bytes,8,opt,name=max_reward_by_address,json=maxRewardByAddress,proto3" json:"max_reward_by_address"` - // Minimum amount of coins for a program to rollover. - MinimumRolloverAmount types.Coin `protobuf:"bytes,9,opt,name=minimum_rollover_amount,json=minimumRolloverAmount,proto3" json:"minimum_rollover_amount"` - // Number of seconds that a claim period lasts. - ClaimPeriodSeconds uint64 `protobuf:"varint,10,opt,name=claim_period_seconds,json=claimPeriodSeconds,proto3" json:"claim_period_seconds,omitempty"` - // Time that a RewardProgram should start and switch to STARTED state. - ProgramStartTime time.Time `protobuf:"bytes,11,opt,name=program_start_time,json=programStartTime,proto3,stdtime" json:"program_start_time"` - // Time that a RewardProgram is expected to end, based on data when it was setup. - ExpectedProgramEndTime time.Time `protobuf:"bytes,12,opt,name=expected_program_end_time,json=expectedProgramEndTime,proto3,stdtime" json:"expected_program_end_time"` - // Time that a RewardProgram MUST end. - ProgramEndTimeMax time.Time `protobuf:"bytes,13,opt,name=program_end_time_max,json=programEndTimeMax,proto3,stdtime" json:"program_end_time_max"` - // Used internally to calculate and track the current claim period's ending time. - ClaimPeriodEndTime time.Time `protobuf:"bytes,14,opt,name=claim_period_end_time,json=claimPeriodEndTime,proto3,stdtime" json:"claim_period_end_time"` - // Time the RewardProgram switched to FINISHED state. Initially set as empty. - ActualProgramEndTime time.Time `protobuf:"bytes,15,opt,name=actual_program_end_time,json=actualProgramEndTime,proto3,stdtime" json:"actual_program_end_time"` - // Number of claim periods this program will run for. - ClaimPeriods uint64 `protobuf:"varint,16,opt,name=claim_periods,json=claimPeriods,proto3" json:"claim_periods,omitempty"` - // Current claim period of the RewardProgram. Uses 1-based indexing. - CurrentClaimPeriod uint64 `protobuf:"varint,17,opt,name=current_claim_period,json=currentClaimPeriod,proto3" json:"current_claim_period,omitempty"` - // maximum number of claim periods a reward program can rollover. - MaxRolloverClaimPeriods uint64 `protobuf:"varint,18,opt,name=max_rollover_claim_periods,json=maxRolloverClaimPeriods,proto3" json:"max_rollover_claim_periods,omitempty"` - // Current state of the RewardProgram. - State RewardProgram_State `protobuf:"varint,19,opt,name=state,proto3,enum=provenance.reward.v1.RewardProgram_State" json:"state,omitempty"` - // Grace period after a RewardProgram FINISHED. It is the number of seconds until a RewardProgram enters the EXPIRED - // state. - ExpirationOffset uint64 `protobuf:"varint,20,opt,name=expiration_offset,json=expirationOffset,proto3" json:"expiration_offset,omitempty"` - // Actions that count towards the reward. - QualifyingActions []QualifyingAction `protobuf:"bytes,21,rep,name=qualifying_actions,json=qualifyingActions,proto3" json:"qualifying_actions"` -} - -func (m *RewardProgram) Reset() { *m = RewardProgram{} } -func (m *RewardProgram) String() string { return proto.CompactTextString(m) } -func (*RewardProgram) ProtoMessage() {} -func (*RewardProgram) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{0} -} -func (m *RewardProgram) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *RewardProgram) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_RewardProgram.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *RewardProgram) XXX_Merge(src proto.Message) { - xxx_messageInfo_RewardProgram.Merge(m, src) -} -func (m *RewardProgram) XXX_Size() int { - return m.Size() -} -func (m *RewardProgram) XXX_DiscardUnknown() { - xxx_messageInfo_RewardProgram.DiscardUnknown(m) -} - -var xxx_messageInfo_RewardProgram proto.InternalMessageInfo - -func (m *RewardProgram) GetId() uint64 { - if m != nil { - return m.Id - } - return 0 -} - -func (m *RewardProgram) GetTitle() string { - if m != nil { - return m.Title - } - return "" -} - -func (m *RewardProgram) GetDescription() string { - if m != nil { - return m.Description - } - return "" -} - -func (m *RewardProgram) GetDistributeFromAddress() string { - if m != nil { - return m.DistributeFromAddress - } - return "" -} - -func (m *RewardProgram) GetTotalRewardPool() types.Coin { - if m != nil { - return m.TotalRewardPool - } - return types.Coin{} -} - -func (m *RewardProgram) GetRemainingPoolBalance() types.Coin { - if m != nil { - return m.RemainingPoolBalance - } - return types.Coin{} -} - -func (m *RewardProgram) GetClaimedAmount() types.Coin { - if m != nil { - return m.ClaimedAmount - } - return types.Coin{} -} - -func (m *RewardProgram) GetMaxRewardByAddress() types.Coin { - if m != nil { - return m.MaxRewardByAddress - } - return types.Coin{} -} - -func (m *RewardProgram) GetMinimumRolloverAmount() types.Coin { - if m != nil { - return m.MinimumRolloverAmount - } - return types.Coin{} -} - -func (m *RewardProgram) GetClaimPeriodSeconds() uint64 { - if m != nil { - return m.ClaimPeriodSeconds - } - return 0 -} - -func (m *RewardProgram) GetProgramStartTime() time.Time { - if m != nil { - return m.ProgramStartTime - } - return time.Time{} -} - -func (m *RewardProgram) GetExpectedProgramEndTime() time.Time { - if m != nil { - return m.ExpectedProgramEndTime - } - return time.Time{} -} - -func (m *RewardProgram) GetProgramEndTimeMax() time.Time { - if m != nil { - return m.ProgramEndTimeMax - } - return time.Time{} -} - -func (m *RewardProgram) GetClaimPeriodEndTime() time.Time { - if m != nil { - return m.ClaimPeriodEndTime - } - return time.Time{} -} - -func (m *RewardProgram) GetActualProgramEndTime() time.Time { - if m != nil { - return m.ActualProgramEndTime - } - return time.Time{} -} - -func (m *RewardProgram) GetClaimPeriods() uint64 { - if m != nil { - return m.ClaimPeriods - } - return 0 -} - -func (m *RewardProgram) GetCurrentClaimPeriod() uint64 { - if m != nil { - return m.CurrentClaimPeriod - } - return 0 -} - -func (m *RewardProgram) GetMaxRolloverClaimPeriods() uint64 { - if m != nil { - return m.MaxRolloverClaimPeriods - } - return 0 -} - -func (m *RewardProgram) GetState() RewardProgram_State { - if m != nil { - return m.State - } - return RewardProgram_STATE_UNSPECIFIED -} - -func (m *RewardProgram) GetExpirationOffset() uint64 { - if m != nil { - return m.ExpirationOffset - } - return 0 -} - -func (m *RewardProgram) GetQualifyingActions() []QualifyingAction { - if m != nil { - return m.QualifyingActions - } - return nil -} - -// ClaimPeriodRewardDistribution, this is updated at the end of every claim period. -type ClaimPeriodRewardDistribution struct { - // The claim period id. - ClaimPeriodId uint64 `protobuf:"varint,1,opt,name=claim_period_id,json=claimPeriodId,proto3" json:"claim_period_id,omitempty"` - // The id of the reward program that this reward belongs to. - RewardProgramId uint64 `protobuf:"varint,2,opt,name=reward_program_id,json=rewardProgramId,proto3" json:"reward_program_id,omitempty"` - // The sum of all the granted rewards for this claim period. - TotalRewardsPoolForClaimPeriod types.Coin `protobuf:"bytes,3,opt,name=total_rewards_pool_for_claim_period,json=totalRewardsPoolForClaimPeriod,proto3" json:"total_rewards_pool_for_claim_period"` - // The final allocated rewards for this claim period. - RewardsPool types.Coin `protobuf:"bytes,4,opt,name=rewards_pool,json=rewardsPool,proto3" json:"rewards_pool"` - // The total number of granted shares for this claim period. - TotalShares int64 `protobuf:"varint,5,opt,name=total_shares,json=totalShares,proto3" json:"total_shares,omitempty"` - // A flag representing if the claim period for this reward has ended. - ClaimPeriodEnded bool `protobuf:"varint,6,opt,name=claim_period_ended,json=claimPeriodEnded,proto3" json:"claim_period_ended,omitempty"` -} - -func (m *ClaimPeriodRewardDistribution) Reset() { *m = ClaimPeriodRewardDistribution{} } -func (m *ClaimPeriodRewardDistribution) String() string { return proto.CompactTextString(m) } -func (*ClaimPeriodRewardDistribution) ProtoMessage() {} -func (*ClaimPeriodRewardDistribution) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{1} -} -func (m *ClaimPeriodRewardDistribution) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ClaimPeriodRewardDistribution) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ClaimPeriodRewardDistribution.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ClaimPeriodRewardDistribution) XXX_Merge(src proto.Message) { - xxx_messageInfo_ClaimPeriodRewardDistribution.Merge(m, src) -} -func (m *ClaimPeriodRewardDistribution) XXX_Size() int { - return m.Size() -} -func (m *ClaimPeriodRewardDistribution) XXX_DiscardUnknown() { - xxx_messageInfo_ClaimPeriodRewardDistribution.DiscardUnknown(m) -} - -var xxx_messageInfo_ClaimPeriodRewardDistribution proto.InternalMessageInfo - -func (m *ClaimPeriodRewardDistribution) GetClaimPeriodId() uint64 { - if m != nil { - return m.ClaimPeriodId - } - return 0 -} - -func (m *ClaimPeriodRewardDistribution) GetRewardProgramId() uint64 { - if m != nil { - return m.RewardProgramId - } - return 0 -} - -func (m *ClaimPeriodRewardDistribution) GetTotalRewardsPoolForClaimPeriod() types.Coin { - if m != nil { - return m.TotalRewardsPoolForClaimPeriod - } - return types.Coin{} -} - -func (m *ClaimPeriodRewardDistribution) GetRewardsPool() types.Coin { - if m != nil { - return m.RewardsPool - } - return types.Coin{} -} - -func (m *ClaimPeriodRewardDistribution) GetTotalShares() int64 { - if m != nil { - return m.TotalShares - } - return 0 -} - -func (m *ClaimPeriodRewardDistribution) GetClaimPeriodEnded() bool { - if m != nil { - return m.ClaimPeriodEnded - } - return false -} - -// RewardAccountState contains state at the claim period level for a specific address. -type RewardAccountState struct { - // The id of the reward program that this share belongs to. - RewardProgramId uint64 `protobuf:"varint,1,opt,name=reward_program_id,json=rewardProgramId,proto3" json:"reward_program_id,omitempty"` - // The id of the claim period that the share belongs to. - ClaimPeriodId uint64 `protobuf:"varint,2,opt,name=claim_period_id,json=claimPeriodId,proto3" json:"claim_period_id,omitempty"` - // Owner of the reward account state. - Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` - // The number of actions performed by this account, mapped by action type. - ActionCounter []*ActionCounter `protobuf:"bytes,4,rep,name=action_counter,json=actionCounter,proto3" json:"action_counter,omitempty"` - // The amount of granted shares for the address in the reward program's claim period. - SharesEarned uint64 `protobuf:"varint,5,opt,name=shares_earned,json=sharesEarned,proto3" json:"shares_earned,omitempty"` - // The status of the claim. - ClaimStatus RewardAccountState_ClaimStatus `protobuf:"varint,6,opt,name=claim_status,json=claimStatus,proto3,enum=provenance.reward.v1.RewardAccountState_ClaimStatus" json:"claim_status,omitempty"` -} - -func (m *RewardAccountState) Reset() { *m = RewardAccountState{} } -func (m *RewardAccountState) String() string { return proto.CompactTextString(m) } -func (*RewardAccountState) ProtoMessage() {} -func (*RewardAccountState) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{2} -} -func (m *RewardAccountState) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *RewardAccountState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_RewardAccountState.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *RewardAccountState) XXX_Merge(src proto.Message) { - xxx_messageInfo_RewardAccountState.Merge(m, src) -} -func (m *RewardAccountState) XXX_Size() int { - return m.Size() -} -func (m *RewardAccountState) XXX_DiscardUnknown() { - xxx_messageInfo_RewardAccountState.DiscardUnknown(m) -} - -var xxx_messageInfo_RewardAccountState proto.InternalMessageInfo - -func (m *RewardAccountState) GetRewardProgramId() uint64 { - if m != nil { - return m.RewardProgramId - } - return 0 -} - -func (m *RewardAccountState) GetClaimPeriodId() uint64 { - if m != nil { - return m.ClaimPeriodId - } - return 0 -} - -func (m *RewardAccountState) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - -func (m *RewardAccountState) GetActionCounter() []*ActionCounter { - if m != nil { - return m.ActionCounter - } - return nil -} - -func (m *RewardAccountState) GetSharesEarned() uint64 { - if m != nil { - return m.SharesEarned - } - return 0 -} - -func (m *RewardAccountState) GetClaimStatus() RewardAccountState_ClaimStatus { - if m != nil { - return m.ClaimStatus - } - return RewardAccountState_CLAIM_STATUS_UNSPECIFIED -} - -// QualifyingAction can be one of many action types. -type QualifyingAction struct { - // type of action to process - // - // Types that are valid to be assigned to Type: - // - // *QualifyingAction_Delegate - // *QualifyingAction_Transfer - // *QualifyingAction_Vote - Type isQualifyingAction_Type `protobuf_oneof:"type"` -} - -func (m *QualifyingAction) Reset() { *m = QualifyingAction{} } -func (m *QualifyingAction) String() string { return proto.CompactTextString(m) } -func (*QualifyingAction) ProtoMessage() {} -func (*QualifyingAction) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{3} -} -func (m *QualifyingAction) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QualifyingAction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QualifyingAction.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QualifyingAction) XXX_Merge(src proto.Message) { - xxx_messageInfo_QualifyingAction.Merge(m, src) -} -func (m *QualifyingAction) XXX_Size() int { - return m.Size() -} -func (m *QualifyingAction) XXX_DiscardUnknown() { - xxx_messageInfo_QualifyingAction.DiscardUnknown(m) -} - -var xxx_messageInfo_QualifyingAction proto.InternalMessageInfo - -type isQualifyingAction_Type interface { - isQualifyingAction_Type() - Equal(interface{}) bool - MarshalTo([]byte) (int, error) - Size() int -} - -type QualifyingAction_Delegate struct { - Delegate *ActionDelegate `protobuf:"bytes,1,opt,name=delegate,proto3,oneof" json:"delegate,omitempty"` -} -type QualifyingAction_Transfer struct { - Transfer *ActionTransfer `protobuf:"bytes,2,opt,name=transfer,proto3,oneof" json:"transfer,omitempty"` -} -type QualifyingAction_Vote struct { - Vote *ActionVote `protobuf:"bytes,3,opt,name=vote,proto3,oneof" json:"vote,omitempty"` -} - -func (*QualifyingAction_Delegate) isQualifyingAction_Type() {} -func (*QualifyingAction_Transfer) isQualifyingAction_Type() {} -func (*QualifyingAction_Vote) isQualifyingAction_Type() {} - -func (m *QualifyingAction) GetType() isQualifyingAction_Type { - if m != nil { - return m.Type - } - return nil -} - -func (m *QualifyingAction) GetDelegate() *ActionDelegate { - if x, ok := m.GetType().(*QualifyingAction_Delegate); ok { - return x.Delegate - } - return nil -} - -func (m *QualifyingAction) GetTransfer() *ActionTransfer { - if x, ok := m.GetType().(*QualifyingAction_Transfer); ok { - return x.Transfer - } - return nil -} - -func (m *QualifyingAction) GetVote() *ActionVote { - if x, ok := m.GetType().(*QualifyingAction_Vote); ok { - return x.Vote - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*QualifyingAction) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*QualifyingAction_Delegate)(nil), - (*QualifyingAction_Transfer)(nil), - (*QualifyingAction_Vote)(nil), - } -} - -// QualifyingActions contains a list of QualifyingActions. -type QualifyingActions struct { - // The actions that count towards the reward. - QualifyingActions []QualifyingAction `protobuf:"bytes,1,rep,name=qualifying_actions,json=qualifyingActions,proto3" json:"qualifying_actions"` -} - -func (m *QualifyingActions) Reset() { *m = QualifyingActions{} } -func (m *QualifyingActions) String() string { return proto.CompactTextString(m) } -func (*QualifyingActions) ProtoMessage() {} -func (*QualifyingActions) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{4} -} -func (m *QualifyingActions) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QualifyingActions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QualifyingActions.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QualifyingActions) XXX_Merge(src proto.Message) { - xxx_messageInfo_QualifyingActions.Merge(m, src) -} -func (m *QualifyingActions) XXX_Size() int { - return m.Size() -} -func (m *QualifyingActions) XXX_DiscardUnknown() { - xxx_messageInfo_QualifyingActions.DiscardUnknown(m) -} - -var xxx_messageInfo_QualifyingActions proto.InternalMessageInfo - -func (m *QualifyingActions) GetQualifyingActions() []QualifyingAction { - if m != nil { - return m.QualifyingActions - } - return nil -} - -// ActionDelegate represents the delegate action and its required eligibility criteria. -type ActionDelegate struct { - // Minimum number of successful delegates. - MinimumActions uint64 `protobuf:"varint,1,opt,name=minimum_actions,json=minimumActions,proto3" json:"minimum_actions,omitempty"` - // Maximum number of successful delegates. - MaximumActions uint64 `protobuf:"varint,2,opt,name=maximum_actions,json=maximumActions,proto3" json:"maximum_actions,omitempty"` - // Minimum amount that the user must have currently delegated on the validator. - MinimumDelegationAmount *types.Coin `protobuf:"bytes,3,opt,name=minimum_delegation_amount,json=minimumDelegationAmount,proto3" json:"minimum_delegation_amount,omitempty"` - // Maximum amount that the user must have currently delegated on the validator. - MaximumDelegationAmount *types.Coin `protobuf:"bytes,4,opt,name=maximum_delegation_amount,json=maximumDelegationAmount,proto3" json:"maximum_delegation_amount,omitempty"` - // Minimum percentile that can be below the validator's power ranking. - MinimumActiveStakePercentile cosmossdk_io_math.LegacyDec `protobuf:"bytes,5,opt,name=minimum_active_stake_percentile,json=minimumActiveStakePercentile,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"minimum_active_stake_percentile"` - // Maximum percentile that can be below the validator's power ranking. - MaximumActiveStakePercentile cosmossdk_io_math.LegacyDec `protobuf:"bytes,6,opt,name=maximum_active_stake_percentile,json=maximumActiveStakePercentile,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"maximum_active_stake_percentile"` -} - -func (m *ActionDelegate) Reset() { *m = ActionDelegate{} } -func (m *ActionDelegate) String() string { return proto.CompactTextString(m) } -func (*ActionDelegate) ProtoMessage() {} -func (*ActionDelegate) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{5} -} -func (m *ActionDelegate) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ActionDelegate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ActionDelegate.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ActionDelegate) XXX_Merge(src proto.Message) { - xxx_messageInfo_ActionDelegate.Merge(m, src) -} -func (m *ActionDelegate) XXX_Size() int { - return m.Size() -} -func (m *ActionDelegate) XXX_DiscardUnknown() { - xxx_messageInfo_ActionDelegate.DiscardUnknown(m) -} - -var xxx_messageInfo_ActionDelegate proto.InternalMessageInfo - -func (m *ActionDelegate) GetMinimumActions() uint64 { - if m != nil { - return m.MinimumActions - } - return 0 -} - -func (m *ActionDelegate) GetMaximumActions() uint64 { - if m != nil { - return m.MaximumActions - } - return 0 -} - -func (m *ActionDelegate) GetMinimumDelegationAmount() *types.Coin { - if m != nil { - return m.MinimumDelegationAmount - } - return nil -} - -func (m *ActionDelegate) GetMaximumDelegationAmount() *types.Coin { - if m != nil { - return m.MaximumDelegationAmount - } - return nil -} - -// ActionTransfer represents the transfer action and its required eligibility criteria. -type ActionTransfer struct { - // Minimum number of successful transfers. - MinimumActions uint64 `protobuf:"varint,1,opt,name=minimum_actions,json=minimumActions,proto3" json:"minimum_actions,omitempty"` - // Maximum number of successful transfers. - MaximumActions uint64 `protobuf:"varint,2,opt,name=maximum_actions,json=maximumActions,proto3" json:"maximum_actions,omitempty"` - // Minimum delegation amount the account must have across all validators, for the transfer action to be counted. - MinimumDelegationAmount types.Coin `protobuf:"bytes,3,opt,name=minimum_delegation_amount,json=minimumDelegationAmount,proto3" json:"minimum_delegation_amount"` -} - -func (m *ActionTransfer) Reset() { *m = ActionTransfer{} } -func (m *ActionTransfer) String() string { return proto.CompactTextString(m) } -func (*ActionTransfer) ProtoMessage() {} -func (*ActionTransfer) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{6} -} -func (m *ActionTransfer) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ActionTransfer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ActionTransfer.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ActionTransfer) XXX_Merge(src proto.Message) { - xxx_messageInfo_ActionTransfer.Merge(m, src) -} -func (m *ActionTransfer) XXX_Size() int { - return m.Size() -} -func (m *ActionTransfer) XXX_DiscardUnknown() { - xxx_messageInfo_ActionTransfer.DiscardUnknown(m) -} - -var xxx_messageInfo_ActionTransfer proto.InternalMessageInfo - -func (m *ActionTransfer) GetMinimumActions() uint64 { - if m != nil { - return m.MinimumActions - } - return 0 -} - -func (m *ActionTransfer) GetMaximumActions() uint64 { - if m != nil { - return m.MaximumActions - } - return 0 -} - -func (m *ActionTransfer) GetMinimumDelegationAmount() types.Coin { - if m != nil { - return m.MinimumDelegationAmount - } - return types.Coin{} -} - -// ActionVote represents the voting action and its required eligibility criteria. -type ActionVote struct { - // Minimum number of successful votes. - MinimumActions uint64 `protobuf:"varint,1,opt,name=minimum_actions,json=minimumActions,proto3" json:"minimum_actions,omitempty"` - // Maximum number of successful votes. - MaximumActions uint64 `protobuf:"varint,2,opt,name=maximum_actions,json=maximumActions,proto3" json:"maximum_actions,omitempty"` - // Minimum delegation amount the account must have across all validators, for the vote action to be counted. - MinimumDelegationAmount types.Coin `protobuf:"bytes,3,opt,name=minimum_delegation_amount,json=minimumDelegationAmount,proto3" json:"minimum_delegation_amount"` - // Positive multiplier that is applied to the shares awarded by the vote action when conditions - // are met(for now the only condition is the current vote is a validator vote). A value of zero will behave the same - // as one - ValidatorMultiplier uint64 `protobuf:"varint,4,opt,name=validator_multiplier,json=validatorMultiplier,proto3" json:"validator_multiplier,omitempty"` -} - -func (m *ActionVote) Reset() { *m = ActionVote{} } -func (m *ActionVote) String() string { return proto.CompactTextString(m) } -func (*ActionVote) ProtoMessage() {} -func (*ActionVote) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{7} -} -func (m *ActionVote) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ActionVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ActionVote.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ActionVote) XXX_Merge(src proto.Message) { - xxx_messageInfo_ActionVote.Merge(m, src) -} -func (m *ActionVote) XXX_Size() int { - return m.Size() -} -func (m *ActionVote) XXX_DiscardUnknown() { - xxx_messageInfo_ActionVote.DiscardUnknown(m) -} - -var xxx_messageInfo_ActionVote proto.InternalMessageInfo - -func (m *ActionVote) GetMinimumActions() uint64 { - if m != nil { - return m.MinimumActions - } - return 0 -} - -func (m *ActionVote) GetMaximumActions() uint64 { - if m != nil { - return m.MaximumActions - } - return 0 -} - -func (m *ActionVote) GetMinimumDelegationAmount() types.Coin { - if m != nil { - return m.MinimumDelegationAmount - } - return types.Coin{} -} - -func (m *ActionVote) GetValidatorMultiplier() uint64 { - if m != nil { - return m.ValidatorMultiplier - } - return 0 -} - -// ActionCounter is a key-value pair that maps action type to the number of times it was performed. -type ActionCounter struct { - // The type of action performed. - ActionType string `protobuf:"bytes,1,opt,name=action_type,json=actionType,proto3" json:"action_type,omitempty"` - // The number of times this action has been performed - NumberOfActions uint64 `protobuf:"varint,2,opt,name=number_of_actions,json=numberOfActions,proto3" json:"number_of_actions,omitempty"` -} - -func (m *ActionCounter) Reset() { *m = ActionCounter{} } -func (m *ActionCounter) String() string { return proto.CompactTextString(m) } -func (*ActionCounter) ProtoMessage() {} -func (*ActionCounter) Descriptor() ([]byte, []int) { - return fileDescriptor_0c3894741a216575, []int{8} -} -func (m *ActionCounter) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ActionCounter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ActionCounter.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ActionCounter) XXX_Merge(src proto.Message) { - xxx_messageInfo_ActionCounter.Merge(m, src) -} -func (m *ActionCounter) XXX_Size() int { - return m.Size() -} -func (m *ActionCounter) XXX_DiscardUnknown() { - xxx_messageInfo_ActionCounter.DiscardUnknown(m) -} - -var xxx_messageInfo_ActionCounter proto.InternalMessageInfo - -func (m *ActionCounter) GetActionType() string { - if m != nil { - return m.ActionType - } - return "" -} - -func (m *ActionCounter) GetNumberOfActions() uint64 { - if m != nil { - return m.NumberOfActions - } - return 0 -} - -func init() { - proto.RegisterEnum("provenance.reward.v1.RewardProgram_State", RewardProgram_State_name, RewardProgram_State_value) - proto.RegisterEnum("provenance.reward.v1.RewardAccountState_ClaimStatus", RewardAccountState_ClaimStatus_name, RewardAccountState_ClaimStatus_value) - proto.RegisterType((*RewardProgram)(nil), "provenance.reward.v1.RewardProgram") - proto.RegisterType((*ClaimPeriodRewardDistribution)(nil), "provenance.reward.v1.ClaimPeriodRewardDistribution") - proto.RegisterType((*RewardAccountState)(nil), "provenance.reward.v1.RewardAccountState") - proto.RegisterType((*QualifyingAction)(nil), "provenance.reward.v1.QualifyingAction") - proto.RegisterType((*QualifyingActions)(nil), "provenance.reward.v1.QualifyingActions") - proto.RegisterType((*ActionDelegate)(nil), "provenance.reward.v1.ActionDelegate") - proto.RegisterType((*ActionTransfer)(nil), "provenance.reward.v1.ActionTransfer") - proto.RegisterType((*ActionVote)(nil), "provenance.reward.v1.ActionVote") - proto.RegisterType((*ActionCounter)(nil), "provenance.reward.v1.ActionCounter") -} - -func init() { proto.RegisterFile("provenance/reward/v1/reward.proto", fileDescriptor_0c3894741a216575) } - -var fileDescriptor_0c3894741a216575 = []byte{ - // 1479 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x58, 0x4b, 0x73, 0x1b, 0x45, - 0x10, 0xf6, 0xda, 0xb2, 0x63, 0xb7, 0x2c, 0x59, 0x9a, 0xc8, 0xf1, 0xda, 0x04, 0xc9, 0x71, 0xa8, - 0x60, 0x1e, 0x91, 0xb0, 0xa1, 0x72, 0x80, 0x03, 0x25, 0x59, 0x32, 0x11, 0x24, 0x8e, 0x59, 0xc9, - 0x84, 0x22, 0x87, 0xad, 0xd1, 0xee, 0x48, 0xd9, 0xca, 0xee, 0x8e, 0xb2, 0x3b, 0x12, 0xf2, 0x8d, - 0x5f, 0x40, 0xe5, 0x08, 0xb7, 0xfc, 0x08, 0x7e, 0x44, 0xb8, 0xa5, 0x38, 0x51, 0x1c, 0x02, 0x95, - 0x70, 0xe0, 0x9c, 0x13, 0x47, 0x6a, 0x1e, 0x2b, 0xad, 0x64, 0x25, 0xb1, 0x79, 0x1c, 0xb8, 0x69, - 0xa6, 0xbb, 0xbf, 0x7e, 0xcc, 0xd7, 0xdd, 0x5b, 0x82, 0x4b, 0xdd, 0x80, 0xf6, 0x89, 0x8f, 0x7d, - 0x8b, 0x94, 0x02, 0xf2, 0x35, 0x0e, 0xec, 0x52, 0x7f, 0x47, 0xfd, 0x2a, 0x76, 0x03, 0xca, 0x28, - 0xca, 0x8d, 0x54, 0x8a, 0x4a, 0xd0, 0xdf, 0xd9, 0xc8, 0x75, 0x68, 0x87, 0x0a, 0x85, 0x12, 0xff, - 0x25, 0x75, 0x37, 0x0a, 0x1d, 0x4a, 0x3b, 0x2e, 0x29, 0x89, 0x53, 0xab, 0xd7, 0x2e, 0x31, 0xc7, - 0x23, 0x21, 0xc3, 0x5e, 0x57, 0x29, 0xe4, 0x2d, 0x1a, 0x7a, 0x34, 0x2c, 0xb5, 0x70, 0x48, 0x4a, - 0xfd, 0x9d, 0x16, 0x61, 0x78, 0xa7, 0x64, 0x51, 0xc7, 0x57, 0xf2, 0x75, 0x29, 0x37, 0x25, 0xb2, - 0x3c, 0x48, 0xd1, 0xd6, 0xf3, 0x24, 0xa4, 0x0c, 0xe1, 0xff, 0x30, 0xa0, 0x9d, 0x00, 0x7b, 0x28, - 0x0d, 0xb3, 0x8e, 0xad, 0x6b, 0x9b, 0xda, 0x76, 0xc2, 0x98, 0x75, 0x6c, 0x94, 0x83, 0x79, 0xe6, - 0x30, 0x97, 0xe8, 0xb3, 0x9b, 0xda, 0xf6, 0x92, 0x21, 0x0f, 0x68, 0x13, 0x92, 0x36, 0x09, 0xad, - 0xc0, 0xe9, 0x32, 0x87, 0xfa, 0xfa, 0x9c, 0x90, 0xc5, 0xaf, 0xd0, 0x35, 0x58, 0xb3, 0x9d, 0x90, - 0x05, 0x4e, 0xab, 0xc7, 0x88, 0xd9, 0x0e, 0xa8, 0x67, 0x62, 0xdb, 0x0e, 0x48, 0x18, 0xea, 0x09, - 0xa1, 0xbd, 0x3a, 0x12, 0xef, 0x07, 0xd4, 0x2b, 0x4b, 0x21, 0xfa, 0x0c, 0xb2, 0x8c, 0x32, 0xec, - 0x9a, 0xb2, 0x2c, 0x66, 0x97, 0x52, 0x57, 0x9f, 0xdf, 0xd4, 0xb6, 0x93, 0xbb, 0xeb, 0x45, 0x15, - 0x3b, 0x4f, 0xb4, 0xa8, 0x12, 0x2d, 0xee, 0x51, 0xc7, 0xaf, 0x24, 0x1e, 0x3d, 0x29, 0xcc, 0x18, - 0x2b, 0xc2, 0x52, 0xe5, 0x43, 0xa9, 0x8b, 0x8e, 0xe0, 0x42, 0x40, 0x3c, 0xec, 0xf8, 0x8e, 0xdf, - 0x11, 0x48, 0x66, 0x0b, 0xbb, 0xbc, 0xe8, 0xfa, 0xc2, 0xe9, 0x10, 0x73, 0x43, 0x73, 0x8e, 0x57, - 0x91, 0xc6, 0x68, 0x1f, 0xd2, 0x96, 0x8b, 0x1d, 0x8f, 0xd8, 0x26, 0xf6, 0x68, 0xcf, 0x67, 0xfa, - 0xb9, 0xd3, 0xc1, 0xa5, 0x94, 0x59, 0x59, 0x58, 0x21, 0x03, 0x56, 0x3d, 0x3c, 0x88, 0x32, 0x6d, - 0x1d, 0x0f, 0x2b, 0xb4, 0x78, 0x3a, 0x38, 0xe4, 0xe1, 0x81, 0xcc, 0xb6, 0x72, 0x1c, 0xd5, 0xef, - 0x36, 0xac, 0x79, 0x8e, 0xef, 0x78, 0x3d, 0xcf, 0x0c, 0xa8, 0xeb, 0xd2, 0x3e, 0x09, 0xa2, 0x20, - 0x97, 0x4e, 0x87, 0xba, 0xaa, 0xec, 0x0d, 0x65, 0xae, 0x82, 0x7d, 0x0f, 0x72, 0x22, 0x7a, 0xb3, - 0x4b, 0x02, 0x87, 0xda, 0x66, 0x48, 0x2c, 0xea, 0xdb, 0xa1, 0x0e, 0x82, 0x2a, 0x48, 0xc8, 0x0e, - 0x85, 0xa8, 0x21, 0x25, 0xc8, 0x00, 0xd4, 0x95, 0xac, 0x32, 0x43, 0x86, 0x03, 0x66, 0x72, 0xe2, - 0xea, 0x49, 0x11, 0xc5, 0x46, 0x51, 0xb2, 0xba, 0x18, 0xb1, 0xba, 0xd8, 0x8c, 0x58, 0x5d, 0x59, - 0xe4, 0x61, 0x3c, 0xf8, 0xb5, 0xa0, 0x19, 0x19, 0x65, 0xdf, 0xe0, 0xe6, 0x5c, 0x01, 0x99, 0xb0, - 0x4e, 0x06, 0x5d, 0x62, 0x31, 0x62, 0x9b, 0x11, 0x38, 0xf1, 0x6d, 0x09, 0xbd, 0x7c, 0x06, 0xe8, - 0x0b, 0x11, 0x8c, 0x22, 0x7e, 0xcd, 0xb7, 0x85, 0x83, 0x23, 0xc8, 0x4d, 0xe2, 0x9a, 0x1e, 0x1e, - 0xe8, 0xa9, 0x33, 0x60, 0x67, 0xbb, 0x63, 0x98, 0x37, 0xf1, 0x00, 0xdd, 0x86, 0xd5, 0xb1, 0xea, - 0x0d, 0x63, 0x4e, 0x9f, 0x01, 0x37, 0x5e, 0xe4, 0x28, 0xde, 0x3b, 0xb0, 0x86, 0x2d, 0xd6, 0xc3, - 0xee, 0xc9, 0x72, 0xac, 0x9c, 0x01, 0x3a, 0x27, 0x41, 0x26, 0x8a, 0x71, 0x19, 0x52, 0xf1, 0xa8, - 0x43, 0x3d, 0x23, 0x1e, 0x7b, 0x39, 0x16, 0x47, 0x28, 0x88, 0xd1, 0x0b, 0x02, 0xe2, 0x33, 0x33, - 0xae, 0xac, 0x67, 0x15, 0x31, 0xa4, 0x6c, 0x6f, 0x64, 0x82, 0x3e, 0x82, 0x0d, 0xc1, 0xfb, 0x88, - 0x9f, 0xe3, 0x3e, 0x90, 0xb0, 0x5b, 0xe3, 0xdc, 0x56, 0x0a, 0x7b, 0x71, 0x77, 0x1f, 0xc3, 0x7c, - 0xc8, 0x30, 0x23, 0xfa, 0xf9, 0x4d, 0x6d, 0x3b, 0xbd, 0xfb, 0x56, 0x71, 0xda, 0x28, 0x2d, 0x8e, - 0x0d, 0xb5, 0x62, 0x83, 0x1b, 0x18, 0xd2, 0x0e, 0xbd, 0x03, 0x59, 0x32, 0xe8, 0x3a, 0x01, 0xe6, - 0x73, 0xca, 0xa4, 0xed, 0x76, 0x48, 0x98, 0x9e, 0x13, 0x4e, 0x33, 0x23, 0xc1, 0x2d, 0x71, 0x8f, - 0xee, 0x00, 0xba, 0xdf, 0xc3, 0xae, 0xd3, 0x3e, 0xe6, 0x23, 0x04, 0x5b, 0x5c, 0x14, 0xea, 0xab, - 0x9b, 0x73, 0xdb, 0xc9, 0xdd, 0x2b, 0xd3, 0x5d, 0x7f, 0x3e, 0xd4, 0x2f, 0x0b, 0x75, 0xd5, 0x56, - 0xd9, 0xfb, 0x13, 0xf7, 0xe1, 0xd6, 0x3d, 0x98, 0x17, 0x91, 0xa1, 0x55, 0xc8, 0x36, 0x9a, 0xe5, - 0x66, 0xcd, 0x3c, 0x3a, 0x68, 0x1c, 0xd6, 0xf6, 0xea, 0xfb, 0xf5, 0x5a, 0x35, 0x33, 0x83, 0xb2, - 0x90, 0x92, 0xd7, 0x87, 0xb5, 0x83, 0x6a, 0xfd, 0xe0, 0x93, 0x8c, 0x36, 0xba, 0x6a, 0x34, 0xcb, - 0x46, 0xb3, 0x56, 0xcd, 0xcc, 0x22, 0x04, 0x69, 0x79, 0xb5, 0x5f, 0x3f, 0xa8, 0x37, 0xae, 0xd7, - 0xaa, 0x99, 0xb9, 0x91, 0x5a, 0xed, 0xcb, 0xc3, 0xba, 0x51, 0xab, 0x66, 0x12, 0x1f, 0x2e, 0x7e, - 0xf7, 0xb0, 0xa0, 0xfd, 0xf1, 0xb0, 0xa0, 0x6d, 0x7d, 0x33, 0x07, 0xaf, 0xc7, 0x4a, 0x2a, 0x4b, - 0x55, 0x8d, 0xa6, 0x31, 0x1f, 0xde, 0x57, 0x60, 0x65, 0x8c, 0xad, 0xc3, 0x8d, 0x90, 0x8a, 0xbd, - 0x7c, 0xdd, 0x46, 0x6f, 0x43, 0x36, 0x1a, 0xd3, 0x8a, 0x7c, 0x8e, 0x2d, 0x16, 0x45, 0xc2, 0x58, - 0x09, 0xe2, 0x2f, 0x50, 0xb7, 0x91, 0x0b, 0x97, 0xe3, 0x83, 0x3d, 0x94, 0xf3, 0xb8, 0x4d, 0xc7, - 0x9f, 0x5f, 0xac, 0x92, 0x53, 0x0c, 0xa9, 0x7c, 0x6c, 0xd4, 0x87, 0x7c, 0x36, 0xef, 0xd3, 0x38, - 0x4d, 0x50, 0x05, 0x96, 0xe3, 0x7e, 0xc4, 0xce, 0x39, 0x05, 0x6c, 0x32, 0x18, 0x21, 0xa2, 0x4b, - 0xb0, 0x2c, 0x23, 0x0e, 0xef, 0xe2, 0x80, 0x84, 0x62, 0x0b, 0xcd, 0x19, 0x49, 0x71, 0xd7, 0x10, - 0x57, 0xe8, 0x5d, 0x40, 0x93, 0x6d, 0x4d, 0x6c, 0xb1, 0x5c, 0x16, 0x8d, 0xcc, 0x78, 0xb7, 0x12, - 0x3b, 0xf6, 0x04, 0xcf, 0xe7, 0x00, 0xc9, 0xe0, 0xcb, 0x96, 0xc5, 0xc7, 0xab, 0xe4, 0xc1, 0xd4, - 0x7a, 0x6a, 0xd3, 0xeb, 0x39, 0xe5, 0x8d, 0x66, 0xa7, 0xbd, 0x91, 0x0e, 0xe7, 0xa2, 0xb5, 0x22, - 0xd7, 0x74, 0x74, 0x44, 0x9f, 0x42, 0x5a, 0x12, 0xda, 0x14, 0x21, 0x90, 0x40, 0x4f, 0x08, 0x5e, - 0x5f, 0x9e, 0xce, 0x6b, 0xc9, 0xda, 0x3d, 0xa9, 0x6a, 0xa4, 0x70, 0xfc, 0xc8, 0x27, 0x85, 0xac, - 0x92, 0x49, 0x70, 0xe0, 0x13, 0x5b, 0x14, 0x2b, 0x61, 0x2c, 0xcb, 0xcb, 0x9a, 0xb8, 0x43, 0xb7, - 0x41, 0x4e, 0x0e, 0xbe, 0x0e, 0x58, 0x2f, 0x14, 0x75, 0x4a, 0xef, 0x7e, 0xf0, 0xb2, 0x0e, 0x8e, - 0x97, 0xa7, 0x28, 0x1e, 0xb8, 0x21, 0x6c, 0x8d, 0xa4, 0x35, 0x3a, 0x6c, 0x7d, 0xaf, 0x41, 0x32, - 0x26, 0x44, 0x17, 0x41, 0xdf, 0xbb, 0x51, 0xae, 0xdf, 0xe4, 0x5d, 0xd2, 0x3c, 0x6a, 0x4c, 0xb4, - 0xd5, 0x49, 0xa9, 0x38, 0x96, 0x2b, 0x37, 0x6a, 0x19, 0x0d, 0x6d, 0xc0, 0x85, 0x31, 0xe9, 0x48, - 0x36, 0x8b, 0x74, 0xc8, 0x9d, 0x94, 0x89, 0x86, 0x9b, 0x94, 0x4c, 0xeb, 0xbb, 0xdf, 0x35, 0xc8, - 0x4c, 0x0e, 0x07, 0x54, 0x81, 0x45, 0x9b, 0xb8, 0xa4, 0xc3, 0x27, 0x9a, 0x26, 0x48, 0xfa, 0xc6, - 0xcb, 0xca, 0x5f, 0x55, 0xba, 0xd7, 0x67, 0x8c, 0xa1, 0x1d, 0xc7, 0x60, 0x01, 0xf6, 0xc3, 0x36, - 0x09, 0x04, 0x07, 0x5e, 0x81, 0xd1, 0x54, 0xba, 0x1c, 0x23, 0xb2, 0x43, 0xd7, 0x20, 0xd1, 0xa7, - 0x8c, 0xa8, 0xfe, 0xdb, 0x7c, 0x99, 0xfd, 0x17, 0x54, 0xf8, 0x17, 0xfa, 0xa3, 0xf4, 0x2a, 0x0b, - 0x90, 0x60, 0xc7, 0x5d, 0xb2, 0xd5, 0x85, 0xec, 0x64, 0x96, 0xe1, 0x0b, 0xe6, 0xa8, 0xf6, 0xef, - 0xcc, 0xd1, 0x6f, 0x13, 0x90, 0x1e, 0x2f, 0x0f, 0x7a, 0x13, 0x56, 0xa2, 0xcf, 0xa0, 0x91, 0x33, - 0xce, 0xc8, 0xb4, 0xba, 0x8e, 0x02, 0xe3, 0x8a, 0x78, 0x30, 0xa6, 0x38, 0xab, 0x14, 0xe5, 0x75, - 0xa4, 0x78, 0x04, 0xeb, 0x11, 0xa2, 0x2a, 0x3c, 0xef, 0x1c, 0xf5, 0x69, 0xf5, 0xaa, 0xa9, 0x65, - 0x44, 0x1f, 0x65, 0xd5, 0xa1, 0xa9, 0xfa, 0xac, 0xe2, 0xb0, 0xca, 0xff, 0x49, 0xd8, 0xc4, 0xab, - 0x61, 0xa5, 0xed, 0x09, 0xd8, 0x01, 0x14, 0xe2, 0xf9, 0xf7, 0x09, 0xef, 0xb9, 0x7b, 0x84, 0x0f, - 0x0b, 0x8b, 0xf8, 0xcc, 0x71, 0x89, 0xe8, 0xd0, 0xa5, 0xca, 0x0e, 0x2f, 0xea, 0x2f, 0x4f, 0x0a, - 0xaf, 0x49, 0x1f, 0xa1, 0x7d, 0xaf, 0xe8, 0xd0, 0x92, 0x87, 0xd9, 0xdd, 0xe2, 0x0d, 0xd2, 0xc1, - 0xd6, 0x71, 0x95, 0x58, 0x3f, 0xfd, 0x70, 0x15, 0x54, 0x08, 0x55, 0x62, 0x19, 0x17, 0x63, 0x25, - 0xec, 0x93, 0x06, 0xc7, 0x3d, 0x1c, 0xc2, 0x0a, 0xcf, 0xb1, 0x82, 0x4e, 0xf3, 0xbc, 0xf0, 0xf7, - 0x3d, 0x8f, 0xde, 0xe4, 0x84, 0xe7, 0x58, 0xa7, 0xfd, 0xa8, 0x45, 0x84, 0x88, 0xb8, 0xfe, 0x1f, - 0x10, 0xe2, 0xce, 0x3f, 0x21, 0x84, 0x22, 0xf3, 0x8b, 0x68, 0x11, 0xcb, 0xe5, 0x4f, 0x0d, 0x60, - 0xd4, 0x77, 0xff, 0xb3, 0x3c, 0xd0, 0x0e, 0xe4, 0xfa, 0xd8, 0x75, 0x6c, 0xcc, 0x68, 0x60, 0x7a, - 0x3d, 0x97, 0x39, 0x5d, 0xd7, 0x11, 0x9b, 0x86, 0x87, 0x72, 0x7e, 0x28, 0xbb, 0x39, 0x14, 0xc5, - 0x52, 0x6f, 0x43, 0x6a, 0x6c, 0xe9, 0xa0, 0x02, 0x24, 0xd5, 0xc6, 0xe2, 0x93, 0x46, 0x24, 0xbe, - 0x64, 0x80, 0xbc, 0x6a, 0x1e, 0x77, 0xc5, 0x02, 0xf5, 0x7b, 0x5e, 0x8b, 0x04, 0x26, 0x6d, 0x4f, - 0xa4, 0xbd, 0x22, 0x05, 0xb7, 0xda, 0x2a, 0xef, 0xd8, 0xe4, 0xea, 0x3c, 0x7a, 0x9a, 0xd7, 0x1e, - 0x3f, 0xcd, 0x6b, 0xbf, 0x3d, 0xcd, 0x6b, 0x0f, 0x9e, 0xe5, 0x67, 0x1e, 0x3f, 0xcb, 0xcf, 0xfc, - 0xfc, 0x2c, 0x3f, 0x03, 0x6b, 0x0e, 0x9d, 0x3a, 0x9c, 0x0e, 0xb5, 0xaf, 0x76, 0x3b, 0x0e, 0xbb, - 0xdb, 0x6b, 0x15, 0x2d, 0xea, 0x95, 0x46, 0x2a, 0x57, 0x1d, 0x1a, 0x3b, 0x95, 0x06, 0xd1, 0x1f, - 0x00, 0x3c, 0xde, 0xb0, 0xb5, 0x20, 0xbe, 0xc1, 0xdf, 0xff, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x3b, - 0xe0, 0x83, 0x17, 0x22, 0x10, 0x00, 0x00, -} - -func (this *RewardProgram) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*RewardProgram) - if !ok { - that2, ok := that.(RewardProgram) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Id != that1.Id { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.DistributeFromAddress != that1.DistributeFromAddress { - return false - } - if !this.TotalRewardPool.Equal(&that1.TotalRewardPool) { - return false - } - if !this.RemainingPoolBalance.Equal(&that1.RemainingPoolBalance) { - return false - } - if !this.ClaimedAmount.Equal(&that1.ClaimedAmount) { - return false - } - if !this.MaxRewardByAddress.Equal(&that1.MaxRewardByAddress) { - return false - } - if !this.MinimumRolloverAmount.Equal(&that1.MinimumRolloverAmount) { - return false - } - if this.ClaimPeriodSeconds != that1.ClaimPeriodSeconds { - return false - } - if !this.ProgramStartTime.Equal(that1.ProgramStartTime) { - return false - } - if !this.ExpectedProgramEndTime.Equal(that1.ExpectedProgramEndTime) { - return false - } - if !this.ProgramEndTimeMax.Equal(that1.ProgramEndTimeMax) { - return false - } - if !this.ClaimPeriodEndTime.Equal(that1.ClaimPeriodEndTime) { - return false - } - if !this.ActualProgramEndTime.Equal(that1.ActualProgramEndTime) { - return false - } - if this.ClaimPeriods != that1.ClaimPeriods { - return false - } - if this.CurrentClaimPeriod != that1.CurrentClaimPeriod { - return false - } - if this.MaxRolloverClaimPeriods != that1.MaxRolloverClaimPeriods { - return false - } - if this.State != that1.State { - return false - } - if this.ExpirationOffset != that1.ExpirationOffset { - return false - } - if len(this.QualifyingActions) != len(that1.QualifyingActions) { - return false - } - for i := range this.QualifyingActions { - if !this.QualifyingActions[i].Equal(&that1.QualifyingActions[i]) { - return false - } - } - return true -} -func (this *ClaimPeriodRewardDistribution) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ClaimPeriodRewardDistribution) - if !ok { - that2, ok := that.(ClaimPeriodRewardDistribution) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.ClaimPeriodId != that1.ClaimPeriodId { - return false - } - if this.RewardProgramId != that1.RewardProgramId { - return false - } - if !this.TotalRewardsPoolForClaimPeriod.Equal(&that1.TotalRewardsPoolForClaimPeriod) { - return false - } - if !this.RewardsPool.Equal(&that1.RewardsPool) { - return false - } - if this.TotalShares != that1.TotalShares { - return false - } - if this.ClaimPeriodEnded != that1.ClaimPeriodEnded { - return false - } - return true -} -func (this *RewardAccountState) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*RewardAccountState) - if !ok { - that2, ok := that.(RewardAccountState) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.RewardProgramId != that1.RewardProgramId { - return false - } - if this.ClaimPeriodId != that1.ClaimPeriodId { - return false - } - if this.Address != that1.Address { - return false - } - if len(this.ActionCounter) != len(that1.ActionCounter) { - return false - } - for i := range this.ActionCounter { - if !this.ActionCounter[i].Equal(that1.ActionCounter[i]) { - return false - } - } - if this.SharesEarned != that1.SharesEarned { - return false - } - if this.ClaimStatus != that1.ClaimStatus { - return false - } - return true -} -func (this *QualifyingAction) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QualifyingAction) - if !ok { - that2, ok := that.(QualifyingAction) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if that1.Type == nil { - if this.Type != nil { - return false - } - } else if this.Type == nil { - return false - } else if !this.Type.Equal(that1.Type) { - return false - } - return true -} -func (this *QualifyingAction_Delegate) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QualifyingAction_Delegate) - if !ok { - that2, ok := that.(QualifyingAction_Delegate) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.Delegate.Equal(that1.Delegate) { - return false - } - return true -} -func (this *QualifyingAction_Transfer) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QualifyingAction_Transfer) - if !ok { - that2, ok := that.(QualifyingAction_Transfer) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.Transfer.Equal(that1.Transfer) { - return false - } - return true -} -func (this *QualifyingAction_Vote) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QualifyingAction_Vote) - if !ok { - that2, ok := that.(QualifyingAction_Vote) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.Vote.Equal(that1.Vote) { - return false - } - return true -} -func (this *ActionDelegate) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ActionDelegate) - if !ok { - that2, ok := that.(ActionDelegate) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.MinimumActions != that1.MinimumActions { - return false - } - if this.MaximumActions != that1.MaximumActions { - return false - } - if !this.MinimumDelegationAmount.Equal(that1.MinimumDelegationAmount) { - return false - } - if !this.MaximumDelegationAmount.Equal(that1.MaximumDelegationAmount) { - return false - } - if !this.MinimumActiveStakePercentile.Equal(that1.MinimumActiveStakePercentile) { - return false - } - if !this.MaximumActiveStakePercentile.Equal(that1.MaximumActiveStakePercentile) { - return false - } - return true -} -func (this *ActionTransfer) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ActionTransfer) - if !ok { - that2, ok := that.(ActionTransfer) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.MinimumActions != that1.MinimumActions { - return false - } - if this.MaximumActions != that1.MaximumActions { - return false - } - if !this.MinimumDelegationAmount.Equal(&that1.MinimumDelegationAmount) { - return false - } - return true -} -func (this *ActionVote) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ActionVote) - if !ok { - that2, ok := that.(ActionVote) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.MinimumActions != that1.MinimumActions { - return false - } - if this.MaximumActions != that1.MaximumActions { - return false - } - if !this.MinimumDelegationAmount.Equal(&that1.MinimumDelegationAmount) { - return false - } - if this.ValidatorMultiplier != that1.ValidatorMultiplier { - return false - } - return true -} -func (this *ActionCounter) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ActionCounter) - if !ok { - that2, ok := that.(ActionCounter) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.ActionType != that1.ActionType { - return false - } - if this.NumberOfActions != that1.NumberOfActions { - return false - } - return true -} -func (m *RewardProgram) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RewardProgram) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *RewardProgram) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.QualifyingActions) > 0 { - for iNdEx := len(m.QualifyingActions) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.QualifyingActions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xaa - } - } - if m.ExpirationOffset != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.ExpirationOffset)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xa0 - } - if m.State != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.State)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x98 - } - if m.MaxRolloverClaimPeriods != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.MaxRolloverClaimPeriods)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x90 - } - if m.CurrentClaimPeriod != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.CurrentClaimPeriod)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x88 - } - if m.ClaimPeriods != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.ClaimPeriods)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x80 - } - n1, err1 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.ActualProgramEndTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ActualProgramEndTime):]) - if err1 != nil { - return 0, err1 - } - i -= n1 - i = encodeVarintReward(dAtA, i, uint64(n1)) - i-- - dAtA[i] = 0x7a - n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.ClaimPeriodEndTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ClaimPeriodEndTime):]) - if err2 != nil { - return 0, err2 - } - i -= n2 - i = encodeVarintReward(dAtA, i, uint64(n2)) - i-- - dAtA[i] = 0x72 - n3, err3 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.ProgramEndTimeMax, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ProgramEndTimeMax):]) - if err3 != nil { - return 0, err3 - } - i -= n3 - i = encodeVarintReward(dAtA, i, uint64(n3)) - i-- - dAtA[i] = 0x6a - n4, err4 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.ExpectedProgramEndTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ExpectedProgramEndTime):]) - if err4 != nil { - return 0, err4 - } - i -= n4 - i = encodeVarintReward(dAtA, i, uint64(n4)) - i-- - dAtA[i] = 0x62 - n5, err5 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.ProgramStartTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ProgramStartTime):]) - if err5 != nil { - return 0, err5 - } - i -= n5 - i = encodeVarintReward(dAtA, i, uint64(n5)) - i-- - dAtA[i] = 0x5a - if m.ClaimPeriodSeconds != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.ClaimPeriodSeconds)) - i-- - dAtA[i] = 0x50 - } - { - size, err := m.MinimumRolloverAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x4a - { - size, err := m.MaxRewardByAddress.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x42 - { - size, err := m.ClaimedAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3a - { - size, err := m.RemainingPoolBalance.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x32 - { - size, err := m.TotalRewardPool.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - if len(m.DistributeFromAddress) > 0 { - i -= len(m.DistributeFromAddress) - copy(dAtA[i:], m.DistributeFromAddress) - i = encodeVarintReward(dAtA, i, uint64(len(m.DistributeFromAddress))) - i-- - dAtA[i] = 0x22 - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintReward(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x1a - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintReward(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0x12 - } - if m.Id != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *ClaimPeriodRewardDistribution) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ClaimPeriodRewardDistribution) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ClaimPeriodRewardDistribution) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ClaimPeriodEnded { - i-- - if m.ClaimPeriodEnded { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x30 - } - if m.TotalShares != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.TotalShares)) - i-- - dAtA[i] = 0x28 - } - { - size, err := m.RewardsPool.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - { - size, err := m.TotalRewardsPoolForClaimPeriod.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - if m.RewardProgramId != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.RewardProgramId)) - i-- - dAtA[i] = 0x10 - } - if m.ClaimPeriodId != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.ClaimPeriodId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *RewardAccountState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RewardAccountState) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *RewardAccountState) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ClaimStatus != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.ClaimStatus)) - i-- - dAtA[i] = 0x30 - } - if m.SharesEarned != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.SharesEarned)) - i-- - dAtA[i] = 0x28 - } - if len(m.ActionCounter) > 0 { - for iNdEx := len(m.ActionCounter) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ActionCounter[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintReward(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0x1a - } - if m.ClaimPeriodId != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.ClaimPeriodId)) - i-- - dAtA[i] = 0x10 - } - if m.RewardProgramId != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.RewardProgramId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QualifyingAction) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QualifyingAction) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QualifyingAction) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Type != nil { - { - size := m.Type.Size() - i -= size - if _, err := m.Type.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - } - } - return len(dAtA) - i, nil -} - -func (m *QualifyingAction_Delegate) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QualifyingAction_Delegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.Delegate != nil { - { - size, err := m.Delegate.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} -func (m *QualifyingAction_Transfer) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QualifyingAction_Transfer) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.Transfer != nil { - { - size, err := m.Transfer.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - return len(dAtA) - i, nil -} -func (m *QualifyingAction_Vote) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QualifyingAction_Vote) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.Vote != nil { - { - size, err := m.Vote.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - return len(dAtA) - i, nil -} -func (m *QualifyingActions) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QualifyingActions) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QualifyingActions) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.QualifyingActions) > 0 { - for iNdEx := len(m.QualifyingActions) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.QualifyingActions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *ActionDelegate) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ActionDelegate) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ActionDelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.MaximumActiveStakePercentile.Size() - i -= size - if _, err := m.MaximumActiveStakePercentile.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x32 - { - size := m.MinimumActiveStakePercentile.Size() - i -= size - if _, err := m.MinimumActiveStakePercentile.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - if m.MaximumDelegationAmount != nil { - { - size, err := m.MaximumDelegationAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - if m.MinimumDelegationAmount != nil { - { - size, err := m.MinimumDelegationAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if m.MaximumActions != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.MaximumActions)) - i-- - dAtA[i] = 0x10 - } - if m.MinimumActions != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.MinimumActions)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *ActionTransfer) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ActionTransfer) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ActionTransfer) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.MinimumDelegationAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - if m.MaximumActions != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.MaximumActions)) - i-- - dAtA[i] = 0x10 - } - if m.MinimumActions != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.MinimumActions)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *ActionVote) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ActionVote) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ActionVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ValidatorMultiplier != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.ValidatorMultiplier)) - i-- - dAtA[i] = 0x20 - } - { - size, err := m.MinimumDelegationAmount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintReward(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - if m.MaximumActions != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.MaximumActions)) - i-- - dAtA[i] = 0x10 - } - if m.MinimumActions != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.MinimumActions)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *ActionCounter) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ActionCounter) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ActionCounter) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.NumberOfActions != 0 { - i = encodeVarintReward(dAtA, i, uint64(m.NumberOfActions)) - i-- - dAtA[i] = 0x10 - } - if len(m.ActionType) > 0 { - i -= len(m.ActionType) - copy(dAtA[i:], m.ActionType) - i = encodeVarintReward(dAtA, i, uint64(len(m.ActionType))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintReward(dAtA []byte, offset int, v uint64) int { - offset -= sovReward(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *RewardProgram) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Id != 0 { - n += 1 + sovReward(uint64(m.Id)) - } - l = len(m.Title) - if l > 0 { - n += 1 + l + sovReward(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovReward(uint64(l)) - } - l = len(m.DistributeFromAddress) - if l > 0 { - n += 1 + l + sovReward(uint64(l)) - } - l = m.TotalRewardPool.Size() - n += 1 + l + sovReward(uint64(l)) - l = m.RemainingPoolBalance.Size() - n += 1 + l + sovReward(uint64(l)) - l = m.ClaimedAmount.Size() - n += 1 + l + sovReward(uint64(l)) - l = m.MaxRewardByAddress.Size() - n += 1 + l + sovReward(uint64(l)) - l = m.MinimumRolloverAmount.Size() - n += 1 + l + sovReward(uint64(l)) - if m.ClaimPeriodSeconds != 0 { - n += 1 + sovReward(uint64(m.ClaimPeriodSeconds)) - } - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ProgramStartTime) - n += 1 + l + sovReward(uint64(l)) - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ExpectedProgramEndTime) - n += 1 + l + sovReward(uint64(l)) - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ProgramEndTimeMax) - n += 1 + l + sovReward(uint64(l)) - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ClaimPeriodEndTime) - n += 1 + l + sovReward(uint64(l)) - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ActualProgramEndTime) - n += 1 + l + sovReward(uint64(l)) - if m.ClaimPeriods != 0 { - n += 2 + sovReward(uint64(m.ClaimPeriods)) - } - if m.CurrentClaimPeriod != 0 { - n += 2 + sovReward(uint64(m.CurrentClaimPeriod)) - } - if m.MaxRolloverClaimPeriods != 0 { - n += 2 + sovReward(uint64(m.MaxRolloverClaimPeriods)) - } - if m.State != 0 { - n += 2 + sovReward(uint64(m.State)) - } - if m.ExpirationOffset != 0 { - n += 2 + sovReward(uint64(m.ExpirationOffset)) - } - if len(m.QualifyingActions) > 0 { - for _, e := range m.QualifyingActions { - l = e.Size() - n += 2 + l + sovReward(uint64(l)) - } - } - return n -} - -func (m *ClaimPeriodRewardDistribution) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ClaimPeriodId != 0 { - n += 1 + sovReward(uint64(m.ClaimPeriodId)) - } - if m.RewardProgramId != 0 { - n += 1 + sovReward(uint64(m.RewardProgramId)) - } - l = m.TotalRewardsPoolForClaimPeriod.Size() - n += 1 + l + sovReward(uint64(l)) - l = m.RewardsPool.Size() - n += 1 + l + sovReward(uint64(l)) - if m.TotalShares != 0 { - n += 1 + sovReward(uint64(m.TotalShares)) - } - if m.ClaimPeriodEnded { - n += 2 - } - return n -} - -func (m *RewardAccountState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardProgramId != 0 { - n += 1 + sovReward(uint64(m.RewardProgramId)) - } - if m.ClaimPeriodId != 0 { - n += 1 + sovReward(uint64(m.ClaimPeriodId)) - } - l = len(m.Address) - if l > 0 { - n += 1 + l + sovReward(uint64(l)) - } - if len(m.ActionCounter) > 0 { - for _, e := range m.ActionCounter { - l = e.Size() - n += 1 + l + sovReward(uint64(l)) - } - } - if m.SharesEarned != 0 { - n += 1 + sovReward(uint64(m.SharesEarned)) - } - if m.ClaimStatus != 0 { - n += 1 + sovReward(uint64(m.ClaimStatus)) - } - return n -} - -func (m *QualifyingAction) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Type != nil { - n += m.Type.Size() - } - return n -} - -func (m *QualifyingAction_Delegate) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Delegate != nil { - l = m.Delegate.Size() - n += 1 + l + sovReward(uint64(l)) - } - return n -} -func (m *QualifyingAction_Transfer) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Transfer != nil { - l = m.Transfer.Size() - n += 1 + l + sovReward(uint64(l)) - } - return n -} -func (m *QualifyingAction_Vote) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Vote != nil { - l = m.Vote.Size() - n += 1 + l + sovReward(uint64(l)) - } - return n -} -func (m *QualifyingActions) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.QualifyingActions) > 0 { - for _, e := range m.QualifyingActions { - l = e.Size() - n += 1 + l + sovReward(uint64(l)) - } - } - return n -} - -func (m *ActionDelegate) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MinimumActions != 0 { - n += 1 + sovReward(uint64(m.MinimumActions)) - } - if m.MaximumActions != 0 { - n += 1 + sovReward(uint64(m.MaximumActions)) - } - if m.MinimumDelegationAmount != nil { - l = m.MinimumDelegationAmount.Size() - n += 1 + l + sovReward(uint64(l)) - } - if m.MaximumDelegationAmount != nil { - l = m.MaximumDelegationAmount.Size() - n += 1 + l + sovReward(uint64(l)) - } - l = m.MinimumActiveStakePercentile.Size() - n += 1 + l + sovReward(uint64(l)) - l = m.MaximumActiveStakePercentile.Size() - n += 1 + l + sovReward(uint64(l)) - return n -} - -func (m *ActionTransfer) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MinimumActions != 0 { - n += 1 + sovReward(uint64(m.MinimumActions)) - } - if m.MaximumActions != 0 { - n += 1 + sovReward(uint64(m.MaximumActions)) - } - l = m.MinimumDelegationAmount.Size() - n += 1 + l + sovReward(uint64(l)) - return n -} - -func (m *ActionVote) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MinimumActions != 0 { - n += 1 + sovReward(uint64(m.MinimumActions)) - } - if m.MaximumActions != 0 { - n += 1 + sovReward(uint64(m.MaximumActions)) - } - l = m.MinimumDelegationAmount.Size() - n += 1 + l + sovReward(uint64(l)) - if m.ValidatorMultiplier != 0 { - n += 1 + sovReward(uint64(m.ValidatorMultiplier)) - } - return n -} - -func (m *ActionCounter) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ActionType) - if l > 0 { - n += 1 + l + sovReward(uint64(l)) - } - if m.NumberOfActions != 0 { - n += 1 + sovReward(uint64(m.NumberOfActions)) - } - return n -} - -func sovReward(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozReward(x uint64) (n int) { - return sovReward(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *RewardProgram) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RewardProgram: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RewardProgram: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DistributeFromAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.DistributeFromAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalRewardPool", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.TotalRewardPool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RemainingPoolBalance", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.RemainingPoolBalance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimedAmount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ClaimedAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxRewardByAddress", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MaxRewardByAddress.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumRolloverAmount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MinimumRolloverAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodSeconds", wireType) - } - m.ClaimPeriodSeconds = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriodSeconds |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProgramStartTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.ProgramStartTime, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExpectedProgramEndTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.ExpectedProgramEndTime, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 13: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProgramEndTimeMax", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.ProgramEndTimeMax, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 14: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodEndTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.ClaimPeriodEndTime, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 15: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ActualProgramEndTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.ActualProgramEndTime, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 16: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriods", wireType) - } - m.ClaimPeriods = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriods |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 17: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentClaimPeriod", wireType) - } - m.CurrentClaimPeriod = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CurrentClaimPeriod |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 18: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxRolloverClaimPeriods", wireType) - } - m.MaxRolloverClaimPeriods = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxRolloverClaimPeriods |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 19: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) - } - m.State = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.State |= RewardProgram_State(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 20: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExpirationOffset", wireType) - } - m.ExpirationOffset = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ExpirationOffset |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 21: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field QualifyingActions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.QualifyingActions = append(m.QualifyingActions, QualifyingAction{}) - if err := m.QualifyingActions[len(m.QualifyingActions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ClaimPeriodRewardDistribution) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ClaimPeriodRewardDistribution: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ClaimPeriodRewardDistribution: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodId", wireType) - } - m.ClaimPeriodId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriodId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgramId", wireType) - } - m.RewardProgramId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardProgramId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalRewardsPoolForClaimPeriod", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.TotalRewardsPoolForClaimPeriod.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardsPool", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.RewardsPool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalShares", wireType) - } - m.TotalShares = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TotalShares |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodEnded", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.ClaimPeriodEnded = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RewardAccountState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RewardAccountState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RewardAccountState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgramId", wireType) - } - m.RewardProgramId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardProgramId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodId", wireType) - } - m.ClaimPeriodId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriodId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ActionCounter", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ActionCounter = append(m.ActionCounter, &ActionCounter{}) - if err := m.ActionCounter[len(m.ActionCounter)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SharesEarned", wireType) - } - m.SharesEarned = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SharesEarned |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimStatus", wireType) - } - m.ClaimStatus = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimStatus |= RewardAccountState_ClaimStatus(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QualifyingAction) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QualifyingAction: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QualifyingAction: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Delegate", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &ActionDelegate{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Type = &QualifyingAction_Delegate{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Transfer", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &ActionTransfer{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Type = &QualifyingAction_Transfer{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &ActionVote{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Type = &QualifyingAction_Vote{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QualifyingActions) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QualifyingActions: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QualifyingActions: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field QualifyingActions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.QualifyingActions = append(m.QualifyingActions, QualifyingAction{}) - if err := m.QualifyingActions[len(m.QualifyingActions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ActionDelegate) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ActionDelegate: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ActionDelegate: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumActions", wireType) - } - m.MinimumActions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MinimumActions |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaximumActions", wireType) - } - m.MaximumActions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaximumActions |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumDelegationAmount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.MinimumDelegationAmount == nil { - m.MinimumDelegationAmount = &types.Coin{} - } - if err := m.MinimumDelegationAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MaximumDelegationAmount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.MaximumDelegationAmount == nil { - m.MaximumDelegationAmount = &types.Coin{} - } - if err := m.MaximumDelegationAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumActiveStakePercentile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MinimumActiveStakePercentile.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MaximumActiveStakePercentile", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MaximumActiveStakePercentile.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ActionTransfer) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ActionTransfer: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ActionTransfer: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumActions", wireType) - } - m.MinimumActions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MinimumActions |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaximumActions", wireType) - } - m.MaximumActions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaximumActions |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumDelegationAmount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MinimumDelegationAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ActionVote) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ActionVote: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ActionVote: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumActions", wireType) - } - m.MinimumActions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MinimumActions |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaximumActions", wireType) - } - m.MaximumActions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaximumActions |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumDelegationAmount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MinimumDelegationAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorMultiplier", wireType) - } - m.ValidatorMultiplier = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ValidatorMultiplier |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ActionCounter) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ActionCounter: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ActionCounter: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ActionType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthReward - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthReward - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ActionType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NumberOfActions", wireType) - } - m.NumberOfActions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowReward - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NumberOfActions |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipReward(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthReward - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipReward(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowReward - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowReward - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowReward - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthReward - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupReward - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthReward - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthReward = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowReward = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupReward = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/reward/types/reward_test.go b/x/reward/types/reward_test.go deleted file mode 100644 index 74f03089ec..0000000000 --- a/x/reward/types/reward_test.go +++ /dev/null @@ -1,750 +0,0 @@ -package types - -import ( - "testing" - time "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type RewardTypesTestSuite struct { - suite.Suite - ctx sdk.Context -} - -func TestRewardTypesTestSuite(t *testing.T) { - suite.Run(t, new(RewardTypesTestSuite)) -} - -func (s *RewardTypesTestSuite) SetupSuite() { - s.T().Parallel() -} - -func (s *RewardTypesTestSuite) TestRewardProgramValidate() { - now := time.Now().UTC() - lTitle := make([]byte, MaxTitleLength+1) - longTitle := string(lTitle) - lDescription := make([]byte, MaxDescriptionLength+1) - longDescription := string(lDescription) - minDelegation := sdk.NewInt64Coin("nhash", 4) - maxDelegation := sdk.NewInt64Coin("nhash", 40) - tests := []struct { - name string - rewardProgram RewardProgram - want string - }{ - { - "valid", - NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{ - { - Type: &QualifyingAction_Vote{ - Vote: &ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - }, - }, - }, - { - Type: &QualifyingAction_Delegate{ - Delegate: &ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - }, - }, - }, - }, - ), - "", - }, - { - "invalid - title is blank", - NewRewardProgram( - "", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "reward program title cannot be blank", - }, - { - "invalid - title is too long", - NewRewardProgram( - longTitle, - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "reward program title is longer than max length of 140", - }, - { - "invalid - description is blank", - NewRewardProgram( - "title", - "", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "reward program description cannot be blank", - }, - { - "invalid - description is too long", - NewRewardProgram( - "title", - longDescription, - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "reward program description is longer than max length of 10000", - }, - { - "invalid - reward id must be greater than 0", - NewRewardProgram( - "title", - "description", - 0, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "reward program id must be larger than 0", - }, - { - "invalid - invalid address", - NewRewardProgram( - "title", - "description", - 1, - "invalid", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "invalid address for rewards program distribution from address: decoding bech32 failed: invalid bech32 string length 7", - }, - { - "invalid - coin must be positive", - NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 0), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "reward program requires coins: 0nhash", - }, - { - "invalid - max reward must be positive", - NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 0), - now, - 1, - 1, - 0, - 1, - []QualifyingAction{}, - ), - "reward program requires positive max reward by address: 0nhash", - }, - { - "invalid - number of claim periods must be larger than 0", - NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 1, - 0, - 0, - 1, - []QualifyingAction{}, - ), - "reward program number of claim periods must be larger than 0", - }, - } - - for _, tt := range tests { - tt := tt - s.T().Run(tt.name, func(t *testing.T) { - err := tt.rewardProgram.Validate() - if err != nil { - assert.Equal(t, tt.want, err.Error()) - } else if len(tt.want) > 0 { - t.Errorf("RewardProgram Validate error = nil, expected: %s", tt.want) - } - }) - } -} - -func (s *RewardTypesTestSuite) TestEpochRewardDistributionValidate() { - tests := []struct { - name string - rewardProgram ClaimPeriodRewardDistribution - want string - }{ - { - "invalid - claim period id", - NewClaimPeriodRewardDistribution(0, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 0, false), - "claim reward distribution has invalid claim id", - }, - { - "invalid - reward program id", - NewClaimPeriodRewardDistribution(1, 0, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 100), 0, false), - "claim reward distribution must have a valid reward program id", - }, - { - "invalid - total rewards needs to be positive", - NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 100), sdk.NewInt64Coin("nhash", 0), 0, false), - "", - }, - { - "invalid - total rewards needs to be positive", - NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 0), sdk.NewInt64Coin("nhash", 100), 0, false), - "claim reward distribution must have a reward pool which is positive", - }, - { - "should succeed validate basic", - NewClaimPeriodRewardDistribution(1, 1, sdk.NewInt64Coin("nhash", 1), sdk.NewInt64Coin("nhash", 1), 0, false), - "", - }, - } - - for _, tt := range tests { - tt := tt - s.T().Run(tt.name, func(t *testing.T) { - err := tt.rewardProgram.Validate() - if err != nil { - assert.Equal(t, tt.want, err.Error()) - } else if len(tt.want) > 0 { - t.Errorf("EpochRewardDistribution Validate error = nil, expected: %s", tt.want) - } - }) - } -} - -func (s *RewardTypesTestSuite) TesRewardAccountStateValidate() { - tests := []struct { - name string - RewardAccountState RewardAccountState - want string - }{ - { - "valid", - NewRewardAccountState( - 1, - 2, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - 0, - []*ActionCounter{}, - ), - "", - }, - { - "invalid reward id", - NewRewardAccountState( - 0, - 2, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - 0, - []*ActionCounter{}, - ), - "reward program id must be greater than 0", - }, - { - "invalid - address is incorrect", - NewRewardAccountState( - 1, - 2, - "test", - 0, - []*ActionCounter{}, - ), - "invalid address for reward program balance: decoding bech32 failed: invalid bech32 string length 7", - }, - } - - for _, tt := range tests { - tt := tt - s.T().Run(tt.name, func(t *testing.T) { - err := tt.RewardAccountState.Validate() - if err != nil { - assert.Equal(t, tt.want, err.Error()) - } else if len(tt.want) > 0 { - t.Errorf("RewardAccountState Validate error = nil, expected: %s", tt.want) - } - }) - } -} - -func (s *RewardTypesTestSuite) TestActionDelegateCreation() { - minDelegation := sdk.NewInt64Coin("nhash", 4) - maxDelegation := sdk.NewInt64Coin("nhash", 40) - - action := ActionDelegate{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: &minDelegation, - MaximumDelegationAmount: &maxDelegation, - MinimumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(0, 0), - MaximumActiveStakePercentile: sdkmath.LegacyNewDecWithPrec(1, 0), - } - s.Assert().Nil(action.Validate(), "validate basic must have no error") - s.Assert().Equal("ActionDelegate", action.ActionType(), "must have appropriate action type") - s.Assert().Equal(true, action.GetBuilder() != nil, "must have appropriate builder") -} - -func (s *RewardTypesTestSuite) TestActionVoteCreation() { - minDelegation := sdk.NewInt64Coin("nhash", 4) - - action := ActionVote{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - } - s.Assert().Nil(action.Validate(), "validate basic must have no error") - s.Assert().Equal("ActionVote", action.ActionType(), "must have appropriate action type") - s.Assert().Equal(true, action.GetBuilder() != nil, "must have appropriate builder") -} - -func (s *RewardTypesTestSuite) TestActionTransferCreation() { - minDelegation := sdk.NewInt64Coin("nhash", 4) - - action := ActionTransfer{ - MinimumActions: 0, - MaximumActions: 1, - MinimumDelegationAmount: minDelegation, - } - s.Assert().Nil(action.Validate(), "validate basic must have no error") - s.Assert().Equal("ActionTransfer", action.ActionType(), "must have appropriate action type") - s.Assert().Equal(true, action.GetBuilder() != nil, "must have appropriate builder") -} - -func (s *RewardTypesTestSuite) TestNewEventCriteria() { - event1 := ABCIEvent{ - Type: "type1", - Attributes: map[string][]byte{ - "attribute1": []byte("value1"), - }, - } - event2 := ABCIEvent{ - Type: "type2", - Attributes: map[string][]byte{ - "attribute3": []byte("value3"), - "attribute4": []byte("value4"), - }, - } - events := []ABCIEvent{event1, event2} - - criteria := NewEventCriteria(events) - s.Assert().Equal(criteria.Events["type1"].Type, "type1", "element must exist and type must match") - s.Assert().Equal(criteria.Events["type1"].Attributes["attribute1"], []byte("value1"), "the attribute should still exist and contain the correct value") - s.Assert().Equal(criteria.Events["type2"].Type, "type2", "element must exist and type must match") - s.Assert().Equal(criteria.Events["type2"].Attributes["attribute3"], []byte("value3"), "the attribute should still exist and contain the correct value") - s.Assert().Equal(criteria.Events["type2"].Attributes["attribute4"], []byte("value4"), "the attribute should still exist and contain the correct value") - - nilCriteria := NewEventCriteria(nil) - s.Assert().Nil(nilCriteria.Events, "events should be nil") -} - -func (s *RewardTypesTestSuite) TestMatchesAttribute() { - event := ABCIEvent{ - Type: "type1", - Attributes: map[string][]byte{ - "attribute1": []byte("value1"), - "attribute3": nil, - }, - } - s.Assert().True(event.MatchesAttribute("attribute1", []byte("value1")), "attribute and value must match") - s.Assert().True(event.MatchesAttribute("attribute3", []byte("blah")), "only attribute needs to match") - s.Assert().False(event.MatchesAttribute("attribute2", []byte("blah")), "must fail when attribute doesn't exist") - s.Assert().False(event.MatchesAttribute("attribute1", []byte("value2")), "must fail when attribute's value doesn't match") -} - -func (s *RewardTypesTestSuite) TestMatchesEvent() { - event1 := ABCIEvent{ - Type: "type1", - Attributes: map[string][]byte{ - "attribute1": []byte("value1"), - }, - } - event2 := ABCIEvent{ - Type: "type2", - Attributes: map[string][]byte{ - "attribute3": []byte("value3"), - "attribute4": []byte("value4"), - }, - } - - nilCriteria := NewEventCriteria(nil) - s.Assert().True(nilCriteria.MatchesEvent("blah"), "a nil criteria must match everything") - - events := []ABCIEvent{} - criteria := NewEventCriteria(events) - s.Assert().True(criteria.MatchesEvent("blah"), "a empty criteria must match everything") - - events = []ABCIEvent{event1, event2} - criteria = NewEventCriteria(events) - - s.Assert().True(criteria.MatchesEvent("type1"), "criteria must match against valid event type") - s.Assert().False(criteria.MatchesEvent("blah"), "criteria must fail against invalid event type") -} - -func (s *RewardTypesTestSuite) TestDateOnOrAfter() { - // compareConstant's use case is blockTime - compareConstant, err := time.Parse(time.RFC3339, "2022-07-21T13:00:10Z") - s.Require().NoError(err) - - past, err := time.Parse(time.RFC3339, "2022-07-21T13:00:09Z") - s.Require().NoError(err) - future, err := time.Parse(time.RFC3339, "2022-07-21T13:00:11Z") - s.Require().NoError(err) - - s.Assert().False(TimeOnOrAfter(compareConstant, past)) - s.Assert().True(TimeOnOrAfter(compareConstant, future)) - s.Assert().True(TimeOnOrAfter(compareConstant, compareConstant)) -} - -func (s *RewardTypesTestSuite) TestCalculateExpectedEndTime() { - compareConstant, err := time.Parse(time.RFC3339, "2022-01-21T15:00:00Z") - s.Require().NoError(err) - - result := CalculateExpectedEndTime(compareConstant, uint64(DayInSeconds), 7) - expected, err := time.Parse(time.RFC3339, "2022-01-28T15:00:00Z") - s.Require().NoError(err) - s.Assert().True(result.Equal(expected)) - - result = CalculateExpectedEndTime(compareConstant, uint64(DayInSeconds), 0) - s.Require().NoError(err) - s.Assert().True(result.Equal(compareConstant)) - -} - -func (s *RewardTypesTestSuite) TestCalculateEndTimeMax() { - compareConstant, err := time.Parse(time.RFC3339, "2022-01-21T15:00:00Z") - s.Require().NoError(err) - - result := CalculateEndTimeMax(compareConstant, uint64(DayInSeconds), 7, 0) - expected, err := time.Parse(time.RFC3339, "2022-01-28T15:00:00Z") - s.Require().NoError(err) - s.Assert().True(result.Equal(expected)) - - result = CalculateEndTimeMax(compareConstant, uint64(DayInSeconds), 7, 1) - expected, err = time.Parse(time.RFC3339, "2022-01-29T15:00:00Z") - s.Require().NoError(err) - s.Assert().True(result.Equal(expected)) - - result = CalculateEndTimeMax(compareConstant, uint64(DayInSeconds), 0, 0) - s.Require().NoError(err) - s.Assert().True(result.Equal(compareConstant)) - -} - -func (s *RewardTypesTestSuite) TestIsStarting() { - now := time.Now().UTC() - program := NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 1, - 0, - 1, - []QualifyingAction{}, - ) - s.ctx = s.ctx.WithBlockTime(now.Add(-1000)) - s.Assert().False(program.IsStarting(s.ctx)) - - s.ctx = s.ctx.WithBlockTime(now.Add(2010)) - s.Assert().True(program.IsStarting(s.ctx)) - -} - -func (s *RewardTypesTestSuite) TestIsExpiring() { - now := time.Now().UTC() - program := NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 1, - 0, - 100, - []QualifyingAction{}, - ) - - s.ctx = s.ctx.WithBlockTime(now) - s.Assert().False(program.IsExpiring(s.ctx)) - - program.ActualProgramEndTime = now - program.State = RewardProgram_STATE_FINISHED - s.Assert().False(program.IsExpiring(s.ctx)) - - program.ExpirationOffset = 0 - s.Assert().True(program.IsExpiring(s.ctx)) - -} - -func (s *RewardTypesTestSuite) TestIsEnding() { - now := time.Now().UTC() - program := NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 10_000_000_000), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 1, - 1, - 100, - []QualifyingAction{}, - ) - - s.ctx = s.ctx.WithBlockTime(now) - //s.Assert().False(program.IsEnding(s.ctx, sdk.NewInt64Coin("nhash", 100_000_000_001))) - - program.State = RewardProgram_STATE_STARTED - program.ProgramEndTimeMax = now.Add(100000) - s.Assert().False(program.IsEnding(s.ctx, sdk.NewInt64Coin("nhash", 100_000_000_000))) - s.Assert().False(program.IsEnding(s.ctx, sdk.NewInt64Coin("nhash", 100_000_000_001))) - // GetMinimumRolloverAmount is 10% of total rewards program i.e 1 hash - s.Assert().True(program.IsEnding(s.ctx, sdk.NewInt64Coin("nhash", 999_000_000))) - - program.ProgramEndTimeMax = now.Add(-100000) - s.Assert().True(program.IsEnding(s.ctx, sdk.NewInt64Coin("nhash", 100_000_000_001))) -} - -func (s *RewardTypesTestSuite) TestMatchesState() { - now := time.Now().UTC() - program := NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 10_000_000_000), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 1, - 1, - 100, - []QualifyingAction{}, - ) - program.State = RewardProgram_STATE_STARTED - - s.Assert().True(program.MatchesState([]RewardProgram_State{})) - s.Assert().True(program.MatchesState([]RewardProgram_State{RewardProgram_STATE_STARTED})) - s.Assert().True(program.MatchesState([]RewardProgram_State{RewardProgram_STATE_PENDING, RewardProgram_STATE_STARTED})) - s.Assert().False(program.MatchesState([]RewardProgram_State{RewardProgram_STATE_PENDING})) -} - -func (s *RewardTypesTestSuite) TestMinimumRolloverAmount() { - now := time.Now().UTC() - program := NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 10_000_000_000), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 6, - 1, - 100, - []QualifyingAction{}, - ) - - s.Assert().Equal(sdk.NewInt64Coin("nhash", 1_66_666_666), program.MinimumRolloverAmount) - - program = NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 11_000_000_000), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 6, - 1, - 100, - []QualifyingAction{}, - ) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 1_83_333_333), program.MinimumRolloverAmount) - - program = NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 20_000_000_000), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 5, - 1, - 100, - []QualifyingAction{}, - ) - s.Assert().Equal(sdk.NewInt64Coin("nhash", 4_00_000_000), program.MinimumRolloverAmount) -} - -func (s *RewardTypesTestSuite) TestIsEndingClaimPeriod() { - now := time.Now().UTC() - program := NewRewardProgram( - "title", - "description", - 1, - "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", - sdk.NewInt64Coin("nhash", 1), - sdk.NewInt64Coin("nhash", 2), - now, - 3600, - 1, - 0, - 1, - []QualifyingAction{}, - ) - s.ctx = s.ctx.WithBlockTime(now.Add(100000)) - - // RewardProgram_PENDING and blockTime after ClaimPeriodEndTime - program.State = RewardProgram_STATE_PENDING - s.Assert().False(program.IsEndingClaimPeriod(s.ctx)) - - s.ctx = s.ctx.WithBlockTime(now.Add(-100000)) - // RewardProgram_STARTED and blockTime after ClaimPeriodEndTime - program.State = RewardProgram_STATE_STARTED - s.Assert().True(program.IsEndingClaimPeriod(s.ctx)) - - // RewardProgram_FINISHED and blockTime after ClaimPeriodEndTime - program.State = RewardProgram_STATE_FINISHED - s.Assert().False(program.IsEndingClaimPeriod(s.ctx)) - - // RewardProgram_EXPIRED and blockTime after ClaimPeriodEndTime - program.State = RewardProgram_STATE_EXPIRED - s.Assert().False(program.IsEndingClaimPeriod(s.ctx)) - -} - -func (s *RewardTypesTestSuite) TestActionCounterIncrement() { - var actionCounterArray []*ActionCounter - actionCounter := ActionCounter{ActionType: ActionTypeDelegate, NumberOfActions: 10} - actionCounterArray = append(actionCounterArray, &actionCounter) - res := IncrementActionCount(actionCounterArray, ActionTypeTransfer) - - s.Assert().NotNil(res, "Incrementing ActionCounter should result in not nil object") - s.Assert().Equal(uint64(10), GetActionCount(res, ActionTypeDelegate), "Delegate Action types should not have changed.") - s.Assert().Equal(uint64(1), GetActionCount(res, ActionTypeTransfer), "Transfer Action types should have changed, to 1.") -} - -func (s *RewardTypesTestSuite) TestActionCounterIncrementTypeAlreadyPresent() { - var actionCounterArray []*ActionCounter - actionCounter := ActionCounter{ActionType: ActionTypeDelegate, NumberOfActions: 10} - actionCounterArray = append(actionCounterArray, &actionCounter) - actionCount := IncrementActionCount(actionCounterArray, ActionTypeDelegate) - - s.Assert().NotNil(actionCount, "Incrementing ActionCounter should result in not nil object") - s.Assert().Equal(uint64(11), GetActionCount(actionCount, ActionTypeDelegate), "Delegate Action types should not have changed.") - s.Assert().Equal(uint64(0), GetActionCount(actionCount, ActionTypeTransfer), "Transfer Action types should not be found.") -} - -func (s *RewardTypesTestSuite) TestActionCounterSearchNilArray() { - var actionCounterArray []*ActionCounter - s.Assert().Equal(uint64(0), GetActionCount(actionCounterArray, ActionTypeDelegate), "Delegate Action types should not be found.") - s.Assert().Equal(uint64(0), GetActionCount(actionCounterArray, ActionTypeTransfer), "Transfer Action types should not be found.") -} - -func (s *RewardTypesTestSuite) TestActionCounterIncrementNilArray() { - var actionCounterArray []*ActionCounter = nil - actionCount := IncrementActionCount(actionCounterArray, ActionTypeDelegate) - s.Assert().Equal(uint64(1), GetActionCount(actionCount, ActionTypeDelegate), "Delegate Action types should not have changed.") -} diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go deleted file mode 100644 index 0e4287a7c7..0000000000 --- a/x/reward/types/tx.pb.go +++ /dev/null @@ -1,3068 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: provenance/reward/v1/tx.proto - -package types - -import ( - context "context" - fmt "fmt" - types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/cosmos-sdk/types/msgservice" - _ "github.com/cosmos/gogoproto/gogoproto" - grpc1 "github.com/cosmos/gogoproto/grpc" - proto "github.com/cosmos/gogoproto/proto" - github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - _ "google.golang.org/protobuf/types/known/timestamppb" - io "io" - math "math" - math_bits "math/bits" - time "time" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf -var _ = time.Kitchen - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// MsgCreateRewardProgramRequest is the request type for creating a reward program RPC -type MsgCreateRewardProgramRequest struct { - // title for the reward program. - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // description for the reward program. - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // provider address for the reward program funds and signer of message. - DistributeFromAddress string `protobuf:"bytes,3,opt,name=distribute_from_address,json=distributeFromAddress,proto3" json:"distribute_from_address,omitempty"` - // total reward pool for the reward program. - TotalRewardPool types.Coin `protobuf:"bytes,4,opt,name=total_reward_pool,json=totalRewardPool,proto3" json:"total_reward_pool"` - // maximum amount of funds an address can be rewarded per claim period. - MaxRewardPerClaimAddress types.Coin `protobuf:"bytes,5,opt,name=max_reward_per_claim_address,json=maxRewardPerClaimAddress,proto3" json:"max_reward_per_claim_address"` - // start time of the reward program. - ProgramStartTime time.Time `protobuf:"bytes,6,opt,name=program_start_time,json=programStartTime,proto3,stdtime" json:"program_start_time,omitempty" yaml:"program_start_time,omitempty"` - // number of claim periods the reward program runs for. - ClaimPeriods uint64 `protobuf:"varint,7,opt,name=claim_periods,json=claimPeriods,proto3" json:"claim_periods,omitempty"` - // number of days a claim period will exist. - ClaimPeriodDays uint64 `protobuf:"varint,8,opt,name=claim_period_days,json=claimPeriodDays,proto3" json:"claim_period_days,omitempty"` - // maximum number of claim periods a reward program can rollover. - MaxRolloverClaimPeriods uint64 `protobuf:"varint,9,opt,name=max_rollover_claim_periods,json=maxRolloverClaimPeriods,proto3" json:"max_rollover_claim_periods,omitempty"` - // number of days before a reward program will expire after it has ended. - ExpireDays uint64 `protobuf:"varint,10,opt,name=expire_days,json=expireDays,proto3" json:"expire_days,omitempty"` - // actions that count towards the reward. - QualifyingActions []QualifyingAction `protobuf:"bytes,11,rep,name=qualifying_actions,json=qualifyingActions,proto3" json:"qualifying_actions"` -} - -func (m *MsgCreateRewardProgramRequest) Reset() { *m = MsgCreateRewardProgramRequest{} } -func (m *MsgCreateRewardProgramRequest) String() string { return proto.CompactTextString(m) } -func (*MsgCreateRewardProgramRequest) ProtoMessage() {} -func (*MsgCreateRewardProgramRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{0} -} -func (m *MsgCreateRewardProgramRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCreateRewardProgramRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCreateRewardProgramRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgCreateRewardProgramRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateRewardProgramRequest.Merge(m, src) -} -func (m *MsgCreateRewardProgramRequest) XXX_Size() int { - return m.Size() -} -func (m *MsgCreateRewardProgramRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateRewardProgramRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCreateRewardProgramRequest proto.InternalMessageInfo - -func (m *MsgCreateRewardProgramRequest) GetTitle() string { - if m != nil { - return m.Title - } - return "" -} - -func (m *MsgCreateRewardProgramRequest) GetDescription() string { - if m != nil { - return m.Description - } - return "" -} - -func (m *MsgCreateRewardProgramRequest) GetDistributeFromAddress() string { - if m != nil { - return m.DistributeFromAddress - } - return "" -} - -func (m *MsgCreateRewardProgramRequest) GetTotalRewardPool() types.Coin { - if m != nil { - return m.TotalRewardPool - } - return types.Coin{} -} - -func (m *MsgCreateRewardProgramRequest) GetMaxRewardPerClaimAddress() types.Coin { - if m != nil { - return m.MaxRewardPerClaimAddress - } - return types.Coin{} -} - -func (m *MsgCreateRewardProgramRequest) GetProgramStartTime() time.Time { - if m != nil { - return m.ProgramStartTime - } - return time.Time{} -} - -func (m *MsgCreateRewardProgramRequest) GetClaimPeriods() uint64 { - if m != nil { - return m.ClaimPeriods - } - return 0 -} - -func (m *MsgCreateRewardProgramRequest) GetClaimPeriodDays() uint64 { - if m != nil { - return m.ClaimPeriodDays - } - return 0 -} - -func (m *MsgCreateRewardProgramRequest) GetMaxRolloverClaimPeriods() uint64 { - if m != nil { - return m.MaxRolloverClaimPeriods - } - return 0 -} - -func (m *MsgCreateRewardProgramRequest) GetExpireDays() uint64 { - if m != nil { - return m.ExpireDays - } - return 0 -} - -func (m *MsgCreateRewardProgramRequest) GetQualifyingActions() []QualifyingAction { - if m != nil { - return m.QualifyingActions - } - return nil -} - -// MsgCreateRewardProgramResponse is the response type for creating a reward program RPC -type MsgCreateRewardProgramResponse struct { - // reward program id that is generated on creation. - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (m *MsgCreateRewardProgramResponse) Reset() { *m = MsgCreateRewardProgramResponse{} } -func (m *MsgCreateRewardProgramResponse) String() string { return proto.CompactTextString(m) } -func (*MsgCreateRewardProgramResponse) ProtoMessage() {} -func (*MsgCreateRewardProgramResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{1} -} -func (m *MsgCreateRewardProgramResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCreateRewardProgramResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCreateRewardProgramResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgCreateRewardProgramResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateRewardProgramResponse.Merge(m, src) -} -func (m *MsgCreateRewardProgramResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgCreateRewardProgramResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateRewardProgramResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCreateRewardProgramResponse proto.InternalMessageInfo - -func (m *MsgCreateRewardProgramResponse) GetId() uint64 { - if m != nil { - return m.Id - } - return 0 -} - -// MsgEndRewardProgramRequest is the request type for ending a reward program RPC -type MsgEndRewardProgramRequest struct { - // reward program id to end. - RewardProgramId uint64 `protobuf:"varint,1,opt,name=reward_program_id,json=rewardProgramId,proto3" json:"reward_program_id,omitempty"` - // owner of the reward program that funds were distributed from. - ProgramOwnerAddress string `protobuf:"bytes,2,opt,name=program_owner_address,json=programOwnerAddress,proto3" json:"program_owner_address,omitempty"` -} - -func (m *MsgEndRewardProgramRequest) Reset() { *m = MsgEndRewardProgramRequest{} } -func (m *MsgEndRewardProgramRequest) String() string { return proto.CompactTextString(m) } -func (*MsgEndRewardProgramRequest) ProtoMessage() {} -func (*MsgEndRewardProgramRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{2} -} -func (m *MsgEndRewardProgramRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgEndRewardProgramRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgEndRewardProgramRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgEndRewardProgramRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgEndRewardProgramRequest.Merge(m, src) -} -func (m *MsgEndRewardProgramRequest) XXX_Size() int { - return m.Size() -} -func (m *MsgEndRewardProgramRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgEndRewardProgramRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgEndRewardProgramRequest proto.InternalMessageInfo - -func (m *MsgEndRewardProgramRequest) GetRewardProgramId() uint64 { - if m != nil { - return m.RewardProgramId - } - return 0 -} - -func (m *MsgEndRewardProgramRequest) GetProgramOwnerAddress() string { - if m != nil { - return m.ProgramOwnerAddress - } - return "" -} - -// MsgEndRewardProgramResponse is the response type for ending a reward program RPC -type MsgEndRewardProgramResponse struct { -} - -func (m *MsgEndRewardProgramResponse) Reset() { *m = MsgEndRewardProgramResponse{} } -func (m *MsgEndRewardProgramResponse) String() string { return proto.CompactTextString(m) } -func (*MsgEndRewardProgramResponse) ProtoMessage() {} -func (*MsgEndRewardProgramResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{3} -} -func (m *MsgEndRewardProgramResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgEndRewardProgramResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgEndRewardProgramResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgEndRewardProgramResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgEndRewardProgramResponse.Merge(m, src) -} -func (m *MsgEndRewardProgramResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgEndRewardProgramResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgEndRewardProgramResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgEndRewardProgramResponse proto.InternalMessageInfo - -// MsgClaimRewardsRequest is the request type for claiming reward from reward program RPC -type MsgClaimRewardsRequest struct { - // reward program id to claim rewards. - RewardProgramId uint64 `protobuf:"varint,1,opt,name=reward_program_id,json=rewardProgramId,proto3" json:"reward_program_id,omitempty"` - // reward address and signer of msg to send claimed rewards to. - RewardAddress string `protobuf:"bytes,2,opt,name=reward_address,json=rewardAddress,proto3" json:"reward_address,omitempty"` -} - -func (m *MsgClaimRewardsRequest) Reset() { *m = MsgClaimRewardsRequest{} } -func (m *MsgClaimRewardsRequest) String() string { return proto.CompactTextString(m) } -func (*MsgClaimRewardsRequest) ProtoMessage() {} -func (*MsgClaimRewardsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{4} -} -func (m *MsgClaimRewardsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgClaimRewardsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgClaimRewardsRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgClaimRewardsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgClaimRewardsRequest.Merge(m, src) -} -func (m *MsgClaimRewardsRequest) XXX_Size() int { - return m.Size() -} -func (m *MsgClaimRewardsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgClaimRewardsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgClaimRewardsRequest proto.InternalMessageInfo - -func (m *MsgClaimRewardsRequest) GetRewardProgramId() uint64 { - if m != nil { - return m.RewardProgramId - } - return 0 -} - -func (m *MsgClaimRewardsRequest) GetRewardAddress() string { - if m != nil { - return m.RewardAddress - } - return "" -} - -// MsgClaimRewardsResponse is the response type for claiming reward from reward program RPC -type MsgClaimRewardsResponse struct { - // details about acquired rewards from reward program. - ClaimDetails RewardProgramClaimDetail `protobuf:"bytes,1,opt,name=claim_details,json=claimDetails,proto3" json:"claim_details"` -} - -func (m *MsgClaimRewardsResponse) Reset() { *m = MsgClaimRewardsResponse{} } -func (m *MsgClaimRewardsResponse) String() string { return proto.CompactTextString(m) } -func (*MsgClaimRewardsResponse) ProtoMessage() {} -func (*MsgClaimRewardsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{5} -} -func (m *MsgClaimRewardsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgClaimRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgClaimRewardsResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgClaimRewardsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgClaimRewardsResponse.Merge(m, src) -} -func (m *MsgClaimRewardsResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgClaimRewardsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgClaimRewardsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgClaimRewardsResponse proto.InternalMessageInfo - -func (m *MsgClaimRewardsResponse) GetClaimDetails() RewardProgramClaimDetail { - if m != nil { - return m.ClaimDetails - } - return RewardProgramClaimDetail{} -} - -// MsgClaimRewardsResponse is the request type for claiming rewards from all reward programs RPC -type MsgClaimAllRewardsRequest struct { - // reward address and signer of msg to send claimed rewards to. - RewardAddress string `protobuf:"bytes,1,opt,name=reward_address,json=rewardAddress,proto3" json:"reward_address,omitempty"` -} - -func (m *MsgClaimAllRewardsRequest) Reset() { *m = MsgClaimAllRewardsRequest{} } -func (m *MsgClaimAllRewardsRequest) String() string { return proto.CompactTextString(m) } -func (*MsgClaimAllRewardsRequest) ProtoMessage() {} -func (*MsgClaimAllRewardsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{6} -} -func (m *MsgClaimAllRewardsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgClaimAllRewardsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgClaimAllRewardsRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgClaimAllRewardsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgClaimAllRewardsRequest.Merge(m, src) -} -func (m *MsgClaimAllRewardsRequest) XXX_Size() int { - return m.Size() -} -func (m *MsgClaimAllRewardsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgClaimAllRewardsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgClaimAllRewardsRequest proto.InternalMessageInfo - -func (m *MsgClaimAllRewardsRequest) GetRewardAddress() string { - if m != nil { - return m.RewardAddress - } - return "" -} - -// MsgClaimRewardsResponse is the response type for claiming rewards from all reward programs RPC -type MsgClaimAllRewardsResponse struct { - // total rewards claimed for all eligible claim periods in all programs. - TotalRewardClaim []types.Coin `protobuf:"bytes,1,rep,name=total_reward_claim,json=totalRewardClaim,proto3" json:"total_reward_claim"` - // details about acquired rewards from a reward program. - ClaimDetails []*RewardProgramClaimDetail `protobuf:"bytes,2,rep,name=claim_details,json=claimDetails,proto3" json:"claim_details,omitempty"` -} - -func (m *MsgClaimAllRewardsResponse) Reset() { *m = MsgClaimAllRewardsResponse{} } -func (m *MsgClaimAllRewardsResponse) String() string { return proto.CompactTextString(m) } -func (*MsgClaimAllRewardsResponse) ProtoMessage() {} -func (*MsgClaimAllRewardsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{7} -} -func (m *MsgClaimAllRewardsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgClaimAllRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgClaimAllRewardsResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgClaimAllRewardsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgClaimAllRewardsResponse.Merge(m, src) -} -func (m *MsgClaimAllRewardsResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgClaimAllRewardsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgClaimAllRewardsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgClaimAllRewardsResponse proto.InternalMessageInfo - -func (m *MsgClaimAllRewardsResponse) GetTotalRewardClaim() []types.Coin { - if m != nil { - return m.TotalRewardClaim - } - return nil -} - -func (m *MsgClaimAllRewardsResponse) GetClaimDetails() []*RewardProgramClaimDetail { - if m != nil { - return m.ClaimDetails - } - return nil -} - -// ClaimedRewardPeriodDetail is information regarding an addresses' shares and reward for a claim period. -type ClaimedRewardPeriodDetail struct { - // claim period id - ClaimPeriodId uint64 `protobuf:"varint,1,opt,name=claim_period_id,json=claimPeriodId,proto3" json:"claim_period_id,omitempty"` - // total shares accumulated for claim period - TotalShares uint64 `protobuf:"varint,2,opt,name=total_shares,json=totalShares,proto3" json:"total_shares,omitempty"` - // total rewards for claim period - ClaimPeriodReward types.Coin `protobuf:"bytes,3,opt,name=claim_period_reward,json=claimPeriodReward,proto3" json:"claim_period_reward"` -} - -func (m *ClaimedRewardPeriodDetail) Reset() { *m = ClaimedRewardPeriodDetail{} } -func (m *ClaimedRewardPeriodDetail) String() string { return proto.CompactTextString(m) } -func (*ClaimedRewardPeriodDetail) ProtoMessage() {} -func (*ClaimedRewardPeriodDetail) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{8} -} -func (m *ClaimedRewardPeriodDetail) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ClaimedRewardPeriodDetail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ClaimedRewardPeriodDetail.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ClaimedRewardPeriodDetail) XXX_Merge(src proto.Message) { - xxx_messageInfo_ClaimedRewardPeriodDetail.Merge(m, src) -} -func (m *ClaimedRewardPeriodDetail) XXX_Size() int { - return m.Size() -} -func (m *ClaimedRewardPeriodDetail) XXX_DiscardUnknown() { - xxx_messageInfo_ClaimedRewardPeriodDetail.DiscardUnknown(m) -} - -var xxx_messageInfo_ClaimedRewardPeriodDetail proto.InternalMessageInfo - -func (m *ClaimedRewardPeriodDetail) GetClaimPeriodId() uint64 { - if m != nil { - return m.ClaimPeriodId - } - return 0 -} - -func (m *ClaimedRewardPeriodDetail) GetTotalShares() uint64 { - if m != nil { - return m.TotalShares - } - return 0 -} - -func (m *ClaimedRewardPeriodDetail) GetClaimPeriodReward() types.Coin { - if m != nil { - return m.ClaimPeriodReward - } - return types.Coin{} -} - -// RewardProgramClaimDetail is the response object regarding an address's shares and reward for a reward program. -type RewardProgramClaimDetail struct { - // reward program id. - RewardProgramId uint64 `protobuf:"varint,1,opt,name=reward_program_id,json=rewardProgramId,proto3" json:"reward_program_id,omitempty"` - // total rewards claimed for all eligible claim periods in program. - TotalRewardClaim types.Coin `protobuf:"bytes,2,opt,name=total_reward_claim,json=totalRewardClaim,proto3" json:"total_reward_claim"` - // claim period details. - ClaimedRewardPeriodDetails []*ClaimedRewardPeriodDetail `protobuf:"bytes,3,rep,name=claimed_reward_period_details,json=claimedRewardPeriodDetails,proto3" json:"claimed_reward_period_details,omitempty"` -} - -func (m *RewardProgramClaimDetail) Reset() { *m = RewardProgramClaimDetail{} } -func (m *RewardProgramClaimDetail) String() string { return proto.CompactTextString(m) } -func (*RewardProgramClaimDetail) ProtoMessage() {} -func (*RewardProgramClaimDetail) Descriptor() ([]byte, []int) { - return fileDescriptor_6a1c90eb8246d229, []int{9} -} -func (m *RewardProgramClaimDetail) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *RewardProgramClaimDetail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_RewardProgramClaimDetail.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *RewardProgramClaimDetail) XXX_Merge(src proto.Message) { - xxx_messageInfo_RewardProgramClaimDetail.Merge(m, src) -} -func (m *RewardProgramClaimDetail) XXX_Size() int { - return m.Size() -} -func (m *RewardProgramClaimDetail) XXX_DiscardUnknown() { - xxx_messageInfo_RewardProgramClaimDetail.DiscardUnknown(m) -} - -var xxx_messageInfo_RewardProgramClaimDetail proto.InternalMessageInfo - -func (m *RewardProgramClaimDetail) GetRewardProgramId() uint64 { - if m != nil { - return m.RewardProgramId - } - return 0 -} - -func (m *RewardProgramClaimDetail) GetTotalRewardClaim() types.Coin { - if m != nil { - return m.TotalRewardClaim - } - return types.Coin{} -} - -func (m *RewardProgramClaimDetail) GetClaimedRewardPeriodDetails() []*ClaimedRewardPeriodDetail { - if m != nil { - return m.ClaimedRewardPeriodDetails - } - return nil -} - -func init() { - proto.RegisterType((*MsgCreateRewardProgramRequest)(nil), "provenance.reward.v1.MsgCreateRewardProgramRequest") - proto.RegisterType((*MsgCreateRewardProgramResponse)(nil), "provenance.reward.v1.MsgCreateRewardProgramResponse") - proto.RegisterType((*MsgEndRewardProgramRequest)(nil), "provenance.reward.v1.MsgEndRewardProgramRequest") - proto.RegisterType((*MsgEndRewardProgramResponse)(nil), "provenance.reward.v1.MsgEndRewardProgramResponse") - proto.RegisterType((*MsgClaimRewardsRequest)(nil), "provenance.reward.v1.MsgClaimRewardsRequest") - proto.RegisterType((*MsgClaimRewardsResponse)(nil), "provenance.reward.v1.MsgClaimRewardsResponse") - proto.RegisterType((*MsgClaimAllRewardsRequest)(nil), "provenance.reward.v1.MsgClaimAllRewardsRequest") - proto.RegisterType((*MsgClaimAllRewardsResponse)(nil), "provenance.reward.v1.MsgClaimAllRewardsResponse") - proto.RegisterType((*ClaimedRewardPeriodDetail)(nil), "provenance.reward.v1.ClaimedRewardPeriodDetail") - proto.RegisterType((*RewardProgramClaimDetail)(nil), "provenance.reward.v1.RewardProgramClaimDetail") -} - -func init() { proto.RegisterFile("provenance/reward/v1/tx.proto", fileDescriptor_6a1c90eb8246d229) } - -var fileDescriptor_6a1c90eb8246d229 = []byte{ - // 1026 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xcf, 0x3a, 0x6e, 0xa0, 0xe3, 0xa4, 0x49, 0x26, 0x29, 0xd9, 0x2c, 0x8d, 0x9d, 0x6e, 0xa1, - 0x8a, 0xa2, 0x76, 0x37, 0x76, 0x11, 0x87, 0x70, 0x4a, 0x52, 0x90, 0x2a, 0x14, 0x25, 0x38, 0x48, - 0x08, 0x38, 0xac, 0xc6, 0xde, 0xc9, 0x76, 0xc4, 0xae, 0x67, 0x33, 0x33, 0x76, 0x6c, 0x4e, 0x15, - 0x57, 0x0e, 0xf4, 0x08, 0xb7, 0x7c, 0x04, 0xbe, 0x00, 0x57, 0xd4, 0x63, 0x8f, 0x9c, 0x02, 0x4a, - 0x90, 0x40, 0x1c, 0xf9, 0x04, 0x68, 0x67, 0x66, 0x9d, 0xb5, 0xbd, 0x0e, 0x4e, 0x6f, 0xf1, 0x7b, - 0xbf, 0xf7, 0x7b, 0x7f, 0xe7, 0x97, 0x05, 0x6b, 0x31, 0xa3, 0x1d, 0xdc, 0x42, 0xad, 0x26, 0x76, - 0x19, 0x3e, 0x45, 0xcc, 0x77, 0x3b, 0x55, 0x57, 0x74, 0x9d, 0x98, 0x51, 0x41, 0xe1, 0xf2, 0x95, - 0xdb, 0x51, 0x6e, 0xa7, 0x53, 0xb5, 0x96, 0x03, 0x1a, 0x50, 0x09, 0x70, 0x93, 0xbf, 0x14, 0xd6, - 0xaa, 0x04, 0x94, 0x06, 0x21, 0x76, 0xe5, 0xaf, 0x46, 0xfb, 0xd8, 0x15, 0x24, 0xc2, 0x5c, 0xa0, - 0x28, 0xd6, 0x80, 0x72, 0x93, 0xf2, 0x88, 0x72, 0xb7, 0x81, 0x38, 0x76, 0x3b, 0xd5, 0x06, 0x16, - 0xa8, 0xea, 0x36, 0x29, 0x69, 0x69, 0xff, 0xfd, 0xdc, 0x5a, 0x74, 0x5a, 0x05, 0x59, 0xd1, 0x14, - 0x11, 0x0f, 0x12, 0x5f, 0xc4, 0x03, 0xe5, 0xb0, 0xbf, 0x9f, 0x01, 0x6b, 0xfb, 0x3c, 0xd8, 0x63, - 0x18, 0x09, 0x5c, 0x97, 0x21, 0x87, 0x8c, 0x06, 0x0c, 0x45, 0x75, 0x7c, 0xd2, 0xc6, 0x5c, 0xc0, - 0x65, 0x70, 0x4b, 0x10, 0x11, 0x62, 0xd3, 0x58, 0x37, 0x36, 0x6e, 0xd7, 0xd5, 0x0f, 0xb8, 0x0e, - 0x4a, 0x3e, 0xe6, 0x4d, 0x46, 0x62, 0x41, 0x68, 0xcb, 0x2c, 0x48, 0x5f, 0xd6, 0x04, 0x3f, 0x04, - 0x2b, 0x3e, 0xe1, 0x82, 0x91, 0x46, 0x5b, 0x60, 0xef, 0x98, 0xd1, 0xc8, 0x43, 0xbe, 0xcf, 0x30, - 0xe7, 0xe6, 0xb4, 0x44, 0xdf, 0xbd, 0x72, 0x7f, 0xc2, 0x68, 0xb4, 0xa3, 0x9c, 0xf0, 0x53, 0xb0, - 0x28, 0xa8, 0x40, 0xa1, 0xa7, 0x1a, 0xf0, 0x62, 0x4a, 0x43, 0xb3, 0xb8, 0x6e, 0x6c, 0x94, 0x6a, - 0xab, 0x8e, 0x6a, 0xc3, 0x49, 0x26, 0xe1, 0xe8, 0x49, 0x38, 0x7b, 0x94, 0xb4, 0x76, 0x8b, 0xaf, - 0xce, 0x2b, 0x53, 0xf5, 0x79, 0x19, 0xa9, 0xdb, 0xa0, 0x34, 0x84, 0x1e, 0xb8, 0x17, 0xa1, 0x6e, - 0x9f, 0x0a, 0x33, 0xaf, 0x19, 0x22, 0x72, 0x55, 0xc9, 0xad, 0xc9, 0x78, 0xcd, 0x08, 0x75, 0x35, - 0x2b, 0x66, 0x7b, 0x09, 0x43, 0x5a, 0xed, 0x4f, 0x06, 0x80, 0xb1, 0x1a, 0x98, 0xc7, 0x05, 0x62, - 0xc2, 0x4b, 0xb6, 0x67, 0xce, 0x48, 0x5e, 0xcb, 0x51, 0xab, 0x75, 0xd2, 0xd5, 0x3a, 0x9f, 0xa7, - 0xab, 0xdd, 0x3d, 0x48, 0x88, 0xff, 0x39, 0xaf, 0xdc, 0x1b, 0x8d, 0x7e, 0x44, 0x23, 0x22, 0x70, - 0x14, 0x8b, 0xde, 0xbf, 0xe7, 0x95, 0x07, 0x3d, 0x14, 0x85, 0xdb, 0xf6, 0x75, 0x28, 0xfb, 0xe5, - 0xef, 0x15, 0xa3, 0xbe, 0xa0, 0x21, 0x47, 0x09, 0x22, 0xc9, 0x03, 0x1f, 0x80, 0x39, 0xd5, 0x6d, - 0x8c, 0x19, 0xa1, 0x3e, 0x37, 0xdf, 0x5a, 0x37, 0x36, 0x8a, 0xf5, 0x59, 0x69, 0x3c, 0x54, 0x36, - 0xb8, 0x09, 0x16, 0xb3, 0x20, 0xcf, 0x47, 0x3d, 0x6e, 0xbe, 0x2d, 0x81, 0xf3, 0x19, 0xe0, 0x53, - 0xd4, 0xe3, 0xf0, 0x23, 0x60, 0xc9, 0x69, 0xd2, 0x30, 0xa4, 0x9d, 0xfe, 0x2c, 0x53, 0xf6, 0xdb, - 0x32, 0x68, 0x25, 0x19, 0x95, 0x06, 0xec, 0x65, 0x13, 0x55, 0x40, 0x09, 0x77, 0x63, 0xc2, 0xb0, - 0x4a, 0x01, 0x24, 0x1a, 0x28, 0x93, 0x64, 0xff, 0x1a, 0xc0, 0x93, 0x36, 0x0a, 0xc9, 0x71, 0x8f, - 0xb4, 0x02, 0x0f, 0x35, 0x93, 0x2b, 0xe2, 0x66, 0x69, 0x7d, 0x7a, 0xa3, 0x54, 0x7b, 0xe8, 0xe4, - 0x3d, 0x28, 0xe7, 0xb3, 0x3e, 0x7e, 0x47, 0xc2, 0xf5, 0xba, 0x16, 0x4f, 0x86, 0xec, 0x7c, 0xfb, - 0xbd, 0x1f, 0xcf, 0x2a, 0xc6, 0xdf, 0x67, 0x15, 0xe3, 0xbb, 0xbf, 0x7e, 0xde, 0x1c, 0x77, 0x98, - 0xf6, 0x16, 0x28, 0x8f, 0x7b, 0x0c, 0x3c, 0xa6, 0x2d, 0x8e, 0xe1, 0x1d, 0x50, 0x20, 0xbe, 0x7c, - 0x0a, 0xc5, 0x7a, 0x81, 0xf8, 0xf6, 0x99, 0x01, 0xac, 0x7d, 0x1e, 0x7c, 0xdc, 0xf2, 0x73, 0x1f, - 0xcf, 0x26, 0x58, 0x4c, 0x6f, 0x4f, 0x2f, 0xb0, 0x1f, 0x3d, 0xcf, 0xb2, 0x01, 0xcf, 0x7c, 0x58, - 0x03, 0x77, 0x53, 0x10, 0x3d, 0x6d, 0x61, 0xd6, 0x3f, 0x52, 0xf5, 0xb8, 0x96, 0xb4, 0xf3, 0x20, - 0xf1, 0xe9, 0xf3, 0xdb, 0xb6, 0xb3, 0x6d, 0xe5, 0x87, 0xdb, 0x6b, 0xe0, 0xdd, 0xdc, 0x0a, 0x55, - 0x47, 0xf6, 0x0b, 0x03, 0xbc, 0x93, 0x34, 0x9d, 0xec, 0x4a, 0x21, 0xf8, 0x9b, 0x54, 0xff, 0x3e, - 0xb8, 0xa3, 0xb1, 0x83, 0x65, 0xcf, 0x29, 0x6b, 0x5a, 0xf0, 0x52, 0x52, 0xe8, 0x10, 0xd2, 0xfe, - 0x16, 0xac, 0x8c, 0x54, 0xa0, 0xe7, 0xfd, 0x65, 0x7a, 0xc3, 0x3e, 0x16, 0x88, 0x84, 0x5c, 0xa6, - 0x2f, 0xd5, 0x9c, 0xfc, 0x7b, 0x18, 0xe8, 0x50, 0xf2, 0x3d, 0x95, 0x61, 0xfa, 0x2e, 0xd4, 0xe5, - 0x2b, 0x13, 0xdf, 0x2e, 0x26, 0x73, 0xb3, 0xbf, 0x00, 0xab, 0x69, 0xee, 0x9d, 0x30, 0x1c, 0x1a, - 0xc0, 0x68, 0x53, 0xc6, 0xc4, 0x4d, 0xfd, 0xaa, 0x2e, 0x63, 0x84, 0x59, 0x37, 0xb6, 0x0f, 0xe0, - 0x80, 0xcc, 0xc9, 0xd2, 0x4c, 0x43, 0x5e, 0xfb, 0xff, 0xea, 0xd1, 0x42, 0x46, 0xe7, 0x64, 0x02, - 0x78, 0x34, 0x3c, 0xa7, 0x82, 0x64, 0xba, 0xe1, 0x9c, 0x72, 0x27, 0xf4, 0x8b, 0x01, 0x56, 0x25, - 0x06, 0xfb, 0x7d, 0x0d, 0x4c, 0x14, 0x41, 0x82, 0xe0, 0x43, 0x30, 0x3f, 0xa0, 0x1f, 0xfd, 0x0b, - 0x99, 0xcb, 0xa8, 0xc7, 0x33, 0x1f, 0xde, 0x07, 0xb3, 0xaa, 0x5f, 0xfe, 0x1c, 0x31, 0xac, 0xae, - 0xa3, 0x58, 0x2f, 0x49, 0xdb, 0x91, 0x34, 0xc1, 0x03, 0xb0, 0x34, 0x40, 0xa5, 0xea, 0x95, 0xff, - 0x2d, 0x26, 0x98, 0xc9, 0x62, 0x26, 0x9f, 0xaa, 0x53, 0xd7, 0xff, 0x43, 0x01, 0x98, 0xe3, 0x1a, - 0xbe, 0xd1, 0x89, 0xe7, 0xaf, 0xac, 0x30, 0x59, 0x79, 0xa3, 0x2b, 0x63, 0x60, 0xad, 0xa9, 0xc6, - 0x9a, 0xf9, 0xff, 0x24, 0x25, 0x58, 0xaf, 0x70, 0x5a, 0xae, 0xd0, 0xcd, 0x5f, 0xe1, 0xd8, 0x8d, - 0xd4, 0xad, 0xe6, 0x38, 0x97, 0xde, 0x68, 0xed, 0xcf, 0x69, 0x30, 0xbd, 0xcf, 0x03, 0xf8, 0xc2, - 0x00, 0x4b, 0x39, 0x62, 0x07, 0x9f, 0xe4, 0xa7, 0xbc, 0xf6, 0x3b, 0xc1, 0xfa, 0xe0, 0x66, 0x41, - 0xfa, 0x19, 0x9c, 0x82, 0x85, 0x61, 0x65, 0x82, 0x5b, 0x63, 0x99, 0xc6, 0xc8, 0xac, 0x55, 0xbd, - 0x41, 0x84, 0x4e, 0xfc, 0x0d, 0x98, 0xcd, 0x0a, 0x0e, 0x7c, 0x34, 0xbe, 0xfc, 0x51, 0x65, 0xb4, - 0x1e, 0x4f, 0x88, 0xd6, 0xc9, 0x04, 0x98, 0x1f, 0xd2, 0x01, 0xe8, 0x5e, 0xcf, 0x30, 0xa2, 0x45, - 0xd6, 0xd6, 0xe4, 0x01, 0x2a, 0xeb, 0x6e, 0xf0, 0xea, 0xa2, 0x6c, 0xbc, 0xbe, 0x28, 0x1b, 0x7f, - 0x5c, 0x94, 0x8d, 0x97, 0x97, 0xe5, 0xa9, 0xd7, 0x97, 0xe5, 0xa9, 0xdf, 0x2e, 0xcb, 0x53, 0x60, - 0x85, 0xd0, 0x5c, 0xb6, 0x43, 0xe3, 0xab, 0x5a, 0x40, 0xc4, 0xf3, 0x76, 0xc3, 0x69, 0xd2, 0xc8, - 0xbd, 0x82, 0x3c, 0x26, 0x34, 0xf3, 0xcb, 0xed, 0xa6, 0xdf, 0x99, 0xa2, 0x17, 0x63, 0xde, 0x98, - 0x91, 0xdf, 0x37, 0x4f, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x37, 0xfb, 0xc1, 0xcf, 0x15, 0x0b, - 0x00, 0x00, -} - -func (this *MsgCreateRewardProgramRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*MsgCreateRewardProgramRequest) - if !ok { - that2, ok := that.(MsgCreateRewardProgramRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.DistributeFromAddress != that1.DistributeFromAddress { - return false - } - if !this.TotalRewardPool.Equal(&that1.TotalRewardPool) { - return false - } - if !this.MaxRewardPerClaimAddress.Equal(&that1.MaxRewardPerClaimAddress) { - return false - } - if !this.ProgramStartTime.Equal(that1.ProgramStartTime) { - return false - } - if this.ClaimPeriods != that1.ClaimPeriods { - return false - } - if this.ClaimPeriodDays != that1.ClaimPeriodDays { - return false - } - if this.MaxRolloverClaimPeriods != that1.MaxRolloverClaimPeriods { - return false - } - if this.ExpireDays != that1.ExpireDays { - return false - } - if len(this.QualifyingActions) != len(that1.QualifyingActions) { - return false - } - for i := range this.QualifyingActions { - if !this.QualifyingActions[i].Equal(&that1.QualifyingActions[i]) { - return false - } - } - return true -} -func (this *MsgEndRewardProgramRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*MsgEndRewardProgramRequest) - if !ok { - that2, ok := that.(MsgEndRewardProgramRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.RewardProgramId != that1.RewardProgramId { - return false - } - if this.ProgramOwnerAddress != that1.ProgramOwnerAddress { - return false - } - return true -} -func (this *MsgClaimRewardsResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*MsgClaimRewardsResponse) - if !ok { - that2, ok := that.(MsgClaimRewardsResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.ClaimDetails.Equal(&that1.ClaimDetails) { - return false - } - return true -} -func (this *MsgClaimAllRewardsResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*MsgClaimAllRewardsResponse) - if !ok { - that2, ok := that.(MsgClaimAllRewardsResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.TotalRewardClaim) != len(that1.TotalRewardClaim) { - return false - } - for i := range this.TotalRewardClaim { - if !this.TotalRewardClaim[i].Equal(&that1.TotalRewardClaim[i]) { - return false - } - } - if len(this.ClaimDetails) != len(that1.ClaimDetails) { - return false - } - for i := range this.ClaimDetails { - if !this.ClaimDetails[i].Equal(that1.ClaimDetails[i]) { - return false - } - } - return true -} -func (this *ClaimedRewardPeriodDetail) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ClaimedRewardPeriodDetail) - if !ok { - that2, ok := that.(ClaimedRewardPeriodDetail) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.ClaimPeriodId != that1.ClaimPeriodId { - return false - } - if this.TotalShares != that1.TotalShares { - return false - } - if !this.ClaimPeriodReward.Equal(&that1.ClaimPeriodReward) { - return false - } - return true -} -func (this *RewardProgramClaimDetail) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*RewardProgramClaimDetail) - if !ok { - that2, ok := that.(RewardProgramClaimDetail) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.RewardProgramId != that1.RewardProgramId { - return false - } - if !this.TotalRewardClaim.Equal(&that1.TotalRewardClaim) { - return false - } - if len(this.ClaimedRewardPeriodDetails) != len(that1.ClaimedRewardPeriodDetails) { - return false - } - for i := range this.ClaimedRewardPeriodDetails { - if !this.ClaimedRewardPeriodDetails[i].Equal(that1.ClaimedRewardPeriodDetails[i]) { - return false - } - } - return true -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// MsgClient is the client API for Msg service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type MsgClient interface { - // CreateRewardProgram is the RPC endpoint for creating a rewards program - CreateRewardProgram(ctx context.Context, in *MsgCreateRewardProgramRequest, opts ...grpc.CallOption) (*MsgCreateRewardProgramResponse, error) - // EndRewardProgram is the RPC endpoint for ending a rewards program - EndRewardProgram(ctx context.Context, in *MsgEndRewardProgramRequest, opts ...grpc.CallOption) (*MsgEndRewardProgramResponse, error) - // ClaimRewards is the RPC endpoint for claiming rewards belonging to completed claim periods of a reward program - ClaimRewards(ctx context.Context, in *MsgClaimRewardsRequest, opts ...grpc.CallOption) (*MsgClaimRewardsResponse, error) - // ClaimAllRewards is the RPC endpoint for claiming rewards for completed claim periods of every reward program for - // the signer of the tx. - ClaimAllRewards(ctx context.Context, in *MsgClaimAllRewardsRequest, opts ...grpc.CallOption) (*MsgClaimAllRewardsResponse, error) -} - -type msgClient struct { - cc grpc1.ClientConn -} - -func NewMsgClient(cc grpc1.ClientConn) MsgClient { - return &msgClient{cc} -} - -func (c *msgClient) CreateRewardProgram(ctx context.Context, in *MsgCreateRewardProgramRequest, opts ...grpc.CallOption) (*MsgCreateRewardProgramResponse, error) { - out := new(MsgCreateRewardProgramResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Msg/CreateRewardProgram", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *msgClient) EndRewardProgram(ctx context.Context, in *MsgEndRewardProgramRequest, opts ...grpc.CallOption) (*MsgEndRewardProgramResponse, error) { - out := new(MsgEndRewardProgramResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Msg/EndRewardProgram", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *msgClient) ClaimRewards(ctx context.Context, in *MsgClaimRewardsRequest, opts ...grpc.CallOption) (*MsgClaimRewardsResponse, error) { - out := new(MsgClaimRewardsResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Msg/ClaimRewards", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *msgClient) ClaimAllRewards(ctx context.Context, in *MsgClaimAllRewardsRequest, opts ...grpc.CallOption) (*MsgClaimAllRewardsResponse, error) { - out := new(MsgClaimAllRewardsResponse) - err := c.cc.Invoke(ctx, "/provenance.reward.v1.Msg/ClaimAllRewards", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MsgServer is the server API for Msg service. -type MsgServer interface { - // CreateRewardProgram is the RPC endpoint for creating a rewards program - CreateRewardProgram(context.Context, *MsgCreateRewardProgramRequest) (*MsgCreateRewardProgramResponse, error) - // EndRewardProgram is the RPC endpoint for ending a rewards program - EndRewardProgram(context.Context, *MsgEndRewardProgramRequest) (*MsgEndRewardProgramResponse, error) - // ClaimRewards is the RPC endpoint for claiming rewards belonging to completed claim periods of a reward program - ClaimRewards(context.Context, *MsgClaimRewardsRequest) (*MsgClaimRewardsResponse, error) - // ClaimAllRewards is the RPC endpoint for claiming rewards for completed claim periods of every reward program for - // the signer of the tx. - ClaimAllRewards(context.Context, *MsgClaimAllRewardsRequest) (*MsgClaimAllRewardsResponse, error) -} - -// UnimplementedMsgServer can be embedded to have forward compatible implementations. -type UnimplementedMsgServer struct { -} - -func (*UnimplementedMsgServer) CreateRewardProgram(ctx context.Context, req *MsgCreateRewardProgramRequest) (*MsgCreateRewardProgramResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateRewardProgram not implemented") -} -func (*UnimplementedMsgServer) EndRewardProgram(ctx context.Context, req *MsgEndRewardProgramRequest) (*MsgEndRewardProgramResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method EndRewardProgram not implemented") -} -func (*UnimplementedMsgServer) ClaimRewards(ctx context.Context, req *MsgClaimRewardsRequest) (*MsgClaimRewardsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ClaimRewards not implemented") -} -func (*UnimplementedMsgServer) ClaimAllRewards(ctx context.Context, req *MsgClaimAllRewardsRequest) (*MsgClaimAllRewardsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ClaimAllRewards not implemented") -} - -func RegisterMsgServer(s grpc1.Server, srv MsgServer) { - s.RegisterService(&_Msg_serviceDesc, srv) -} - -func _Msg_CreateRewardProgram_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCreateRewardProgramRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).CreateRewardProgram(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Msg/CreateRewardProgram", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CreateRewardProgram(ctx, req.(*MsgCreateRewardProgramRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Msg_EndRewardProgram_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgEndRewardProgramRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).EndRewardProgram(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Msg/EndRewardProgram", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).EndRewardProgram(ctx, req.(*MsgEndRewardProgramRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Msg_ClaimRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgClaimRewardsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).ClaimRewards(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Msg/ClaimRewards", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).ClaimRewards(ctx, req.(*MsgClaimRewardsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Msg_ClaimAllRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgClaimAllRewardsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).ClaimAllRewards(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/provenance.reward.v1.Msg/ClaimAllRewards", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).ClaimAllRewards(ctx, req.(*MsgClaimAllRewardsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "provenance.reward.v1.Msg", - HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateRewardProgram", - Handler: _Msg_CreateRewardProgram_Handler, - }, - { - MethodName: "EndRewardProgram", - Handler: _Msg_EndRewardProgram_Handler, - }, - { - MethodName: "ClaimRewards", - Handler: _Msg_ClaimRewards_Handler, - }, - { - MethodName: "ClaimAllRewards", - Handler: _Msg_ClaimAllRewards_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "provenance/reward/v1/tx.proto", -} - -func (m *MsgCreateRewardProgramRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgCreateRewardProgramRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgCreateRewardProgramRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.QualifyingActions) > 0 { - for iNdEx := len(m.QualifyingActions) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.QualifyingActions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x5a - } - } - if m.ExpireDays != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.ExpireDays)) - i-- - dAtA[i] = 0x50 - } - if m.MaxRolloverClaimPeriods != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.MaxRolloverClaimPeriods)) - i-- - dAtA[i] = 0x48 - } - if m.ClaimPeriodDays != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.ClaimPeriodDays)) - i-- - dAtA[i] = 0x40 - } - if m.ClaimPeriods != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.ClaimPeriods)) - i-- - dAtA[i] = 0x38 - } - n1, err1 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.ProgramStartTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ProgramStartTime):]) - if err1 != nil { - return 0, err1 - } - i -= n1 - i = encodeVarintTx(dAtA, i, uint64(n1)) - i-- - dAtA[i] = 0x32 - { - size, err := m.MaxRewardPerClaimAddress.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - { - size, err := m.TotalRewardPool.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - if len(m.DistributeFromAddress) > 0 { - i -= len(m.DistributeFromAddress) - copy(dAtA[i:], m.DistributeFromAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.DistributeFromAddress))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintTx(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintTx(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgCreateRewardProgramResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgCreateRewardProgramResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgCreateRewardProgramResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Id != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *MsgEndRewardProgramRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgEndRewardProgramRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgEndRewardProgramRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ProgramOwnerAddress) > 0 { - i -= len(m.ProgramOwnerAddress) - copy(dAtA[i:], m.ProgramOwnerAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.ProgramOwnerAddress))) - i-- - dAtA[i] = 0x12 - } - if m.RewardProgramId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.RewardProgramId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *MsgEndRewardProgramResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgEndRewardProgramResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgEndRewardProgramResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *MsgClaimRewardsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgClaimRewardsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgClaimRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.RewardAddress) > 0 { - i -= len(m.RewardAddress) - copy(dAtA[i:], m.RewardAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.RewardAddress))) - i-- - dAtA[i] = 0x12 - } - if m.RewardProgramId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.RewardProgramId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *MsgClaimRewardsResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgClaimRewardsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgClaimRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.ClaimDetails.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *MsgClaimAllRewardsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgClaimAllRewardsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgClaimAllRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.RewardAddress) > 0 { - i -= len(m.RewardAddress) - copy(dAtA[i:], m.RewardAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.RewardAddress))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgClaimAllRewardsResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgClaimAllRewardsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgClaimAllRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ClaimDetails) > 0 { - for iNdEx := len(m.ClaimDetails) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ClaimDetails[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - if len(m.TotalRewardClaim) > 0 { - for iNdEx := len(m.TotalRewardClaim) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.TotalRewardClaim[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *ClaimedRewardPeriodDetail) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ClaimedRewardPeriodDetail) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ClaimedRewardPeriodDetail) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.ClaimPeriodReward.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - if m.TotalShares != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.TotalShares)) - i-- - dAtA[i] = 0x10 - } - if m.ClaimPeriodId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.ClaimPeriodId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *RewardProgramClaimDetail) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RewardProgramClaimDetail) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *RewardProgramClaimDetail) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ClaimedRewardPeriodDetails) > 0 { - for iNdEx := len(m.ClaimedRewardPeriodDetails) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ClaimedRewardPeriodDetails[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - { - size, err := m.TotalRewardClaim.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if m.RewardProgramId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.RewardProgramId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *MsgCreateRewardProgramRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.DistributeFromAddress) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = m.TotalRewardPool.Size() - n += 1 + l + sovTx(uint64(l)) - l = m.MaxRewardPerClaimAddress.Size() - n += 1 + l + sovTx(uint64(l)) - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.ProgramStartTime) - n += 1 + l + sovTx(uint64(l)) - if m.ClaimPeriods != 0 { - n += 1 + sovTx(uint64(m.ClaimPeriods)) - } - if m.ClaimPeriodDays != 0 { - n += 1 + sovTx(uint64(m.ClaimPeriodDays)) - } - if m.MaxRolloverClaimPeriods != 0 { - n += 1 + sovTx(uint64(m.MaxRolloverClaimPeriods)) - } - if m.ExpireDays != 0 { - n += 1 + sovTx(uint64(m.ExpireDays)) - } - if len(m.QualifyingActions) > 0 { - for _, e := range m.QualifyingActions { - l = e.Size() - n += 1 + l + sovTx(uint64(l)) - } - } - return n -} - -func (m *MsgCreateRewardProgramResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Id != 0 { - n += 1 + sovTx(uint64(m.Id)) - } - return n -} - -func (m *MsgEndRewardProgramRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardProgramId != 0 { - n += 1 + sovTx(uint64(m.RewardProgramId)) - } - l = len(m.ProgramOwnerAddress) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgEndRewardProgramResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *MsgClaimRewardsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardProgramId != 0 { - n += 1 + sovTx(uint64(m.RewardProgramId)) - } - l = len(m.RewardAddress) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgClaimRewardsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.ClaimDetails.Size() - n += 1 + l + sovTx(uint64(l)) - return n -} - -func (m *MsgClaimAllRewardsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.RewardAddress) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgClaimAllRewardsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.TotalRewardClaim) > 0 { - for _, e := range m.TotalRewardClaim { - l = e.Size() - n += 1 + l + sovTx(uint64(l)) - } - } - if len(m.ClaimDetails) > 0 { - for _, e := range m.ClaimDetails { - l = e.Size() - n += 1 + l + sovTx(uint64(l)) - } - } - return n -} - -func (m *ClaimedRewardPeriodDetail) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ClaimPeriodId != 0 { - n += 1 + sovTx(uint64(m.ClaimPeriodId)) - } - if m.TotalShares != 0 { - n += 1 + sovTx(uint64(m.TotalShares)) - } - l = m.ClaimPeriodReward.Size() - n += 1 + l + sovTx(uint64(l)) - return n -} - -func (m *RewardProgramClaimDetail) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.RewardProgramId != 0 { - n += 1 + sovTx(uint64(m.RewardProgramId)) - } - l = m.TotalRewardClaim.Size() - n += 1 + l + sovTx(uint64(l)) - if len(m.ClaimedRewardPeriodDetails) > 0 { - for _, e := range m.ClaimedRewardPeriodDetails { - l = e.Size() - n += 1 + l + sovTx(uint64(l)) - } - } - return n -} - -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTx(x uint64) (n int) { - return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *MsgCreateRewardProgramRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgCreateRewardProgramRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateRewardProgramRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DistributeFromAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.DistributeFromAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalRewardPool", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.TotalRewardPool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxRewardPerClaimAddress", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MaxRewardPerClaimAddress.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProgramStartTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.ProgramStartTime, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriods", wireType) - } - m.ClaimPeriods = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriods |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodDays", wireType) - } - m.ClaimPeriodDays = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriodDays |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxRolloverClaimPeriods", wireType) - } - m.MaxRolloverClaimPeriods = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxRolloverClaimPeriods |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExpireDays", wireType) - } - m.ExpireDays = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ExpireDays |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field QualifyingActions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.QualifyingActions = append(m.QualifyingActions, QualifyingAction{}) - if err := m.QualifyingActions[len(m.QualifyingActions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgCreateRewardProgramResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgCreateRewardProgramResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateRewardProgramResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgEndRewardProgramRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgEndRewardProgramRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgEndRewardProgramRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgramId", wireType) - } - m.RewardProgramId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardProgramId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProgramOwnerAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ProgramOwnerAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgEndRewardProgramResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgEndRewardProgramResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgEndRewardProgramResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgClaimRewardsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgClaimRewardsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgClaimRewardsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgramId", wireType) - } - m.RewardProgramId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardProgramId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgClaimRewardsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgClaimRewardsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgClaimRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimDetails", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ClaimDetails.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgClaimAllRewardsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgClaimAllRewardsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgClaimAllRewardsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RewardAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgClaimAllRewardsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgClaimAllRewardsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgClaimAllRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalRewardClaim", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TotalRewardClaim = append(m.TotalRewardClaim, types.Coin{}) - if err := m.TotalRewardClaim[len(m.TotalRewardClaim)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimDetails", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClaimDetails = append(m.ClaimDetails, &RewardProgramClaimDetail{}) - if err := m.ClaimDetails[len(m.ClaimDetails)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ClaimedRewardPeriodDetail) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ClaimedRewardPeriodDetail: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ClaimedRewardPeriodDetail: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodId", wireType) - } - m.ClaimPeriodId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimPeriodId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalShares", wireType) - } - m.TotalShares = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TotalShares |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimPeriodReward", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ClaimPeriodReward.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RewardProgramClaimDetail) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RewardProgramClaimDetail: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RewardProgramClaimDetail: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardProgramId", wireType) - } - m.RewardProgramId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardProgramId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalRewardClaim", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.TotalRewardClaim.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimedRewardPeriodDetails", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClaimedRewardPeriodDetails = append(m.ClaimedRewardPeriodDetails, &ClaimedRewardPeriodDetail{}) - if err := m.ClaimedRewardPeriodDetails[len(m.ClaimedRewardPeriodDetails)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTx(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthTx - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTx - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTx - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") -)