Skip to content

Commit

Permalink
added pending unlock to genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
faneaatiku committed Mar 19, 2024
1 parent 8538a8d commit 28b7083
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 72 deletions.
1 change: 1 addition & 0 deletions proto/rewards/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ message GenesisState {

repeated TradingReward trading_reward_list = 5 [(gogoproto.nullable) = false];
repeated StakingRewardParticipant staking_reward_participant_list = 6 [(gogoproto.nullable) = false];
repeated PendingUnlockParticipant pending_unlock_participant_list = 7 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
}
64 changes: 32 additions & 32 deletions vue/src/store/generated/bze-alphateam/bze/bze.v1.rewards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,18 @@ export default {
},


async sendMsgCreateStakingReward({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgJoinStaking({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgCreateStakingReward(value)
const msg = await txClient.msgJoinStaking(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgCreateStakingReward:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgJoinStaking:Init Could not initialize signing client. Wallet is required.')
}else{
throw new Error('TxClient:MsgCreateStakingReward:Send Could not broadcast Tx: '+ e.message)
throw new Error('TxClient:MsgJoinStaking:Send Could not broadcast Tx: '+ e.message)
}
}
},
Expand All @@ -363,18 +363,18 @@ export default {
}
}
},
async sendMsgClaimStakingRewards({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgUpdateStakingReward({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgClaimStakingRewards(value)
const msg = await txClient.msgUpdateStakingReward(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgClaimStakingRewards:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgUpdateStakingReward:Init Could not initialize signing client. Wallet is required.')
}else{
throw new Error('TxClient:MsgClaimStakingRewards:Send Could not broadcast Tx: '+ e.message)
throw new Error('TxClient:MsgUpdateStakingReward:Send Could not broadcast Tx: '+ e.message)
}
}
},
Expand All @@ -393,47 +393,47 @@ export default {
}
}
},
async sendMsgJoinStaking({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgCreateStakingReward({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgJoinStaking(value)
const msg = await txClient.msgCreateStakingReward(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgJoinStaking:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgCreateStakingReward:Init Could not initialize signing client. Wallet is required.')
}else{
throw new Error('TxClient:MsgJoinStaking:Send Could not broadcast Tx: '+ e.message)
throw new Error('TxClient:MsgCreateStakingReward:Send Could not broadcast Tx: '+ e.message)
}
}
},
async sendMsgUpdateStakingReward({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgClaimStakingRewards({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgUpdateStakingReward(value)
const msg = await txClient.msgClaimStakingRewards(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgUpdateStakingReward:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgClaimStakingRewards:Init Could not initialize signing client. Wallet is required.')
}else{
throw new Error('TxClient:MsgUpdateStakingReward:Send Could not broadcast Tx: '+ e.message)
throw new Error('TxClient:MsgClaimStakingRewards:Send Could not broadcast Tx: '+ e.message)
}
}
},

async MsgCreateStakingReward({ rootGetters }, { value }) {
async MsgJoinStaking({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgCreateStakingReward(value)
const msg = await txClient.msgJoinStaking(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgCreateStakingReward:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgJoinStaking:Init Could not initialize signing client. Wallet is required.')
} else{
throw new Error('TxClient:MsgCreateStakingReward:Create Could not create message: ' + e.message)
throw new Error('TxClient:MsgJoinStaking:Create Could not create message: ' + e.message)
}
}
},
Expand All @@ -450,16 +450,16 @@ export default {
}
}
},
async MsgClaimStakingRewards({ rootGetters }, { value }) {
async MsgUpdateStakingReward({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgClaimStakingRewards(value)
const msg = await txClient.msgUpdateStakingReward(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgClaimStakingRewards:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgUpdateStakingReward:Init Could not initialize signing client. Wallet is required.')
} else{
throw new Error('TxClient:MsgClaimStakingRewards:Create Could not create message: ' + e.message)
throw new Error('TxClient:MsgUpdateStakingReward:Create Could not create message: ' + e.message)
}
}
},
Expand All @@ -476,29 +476,29 @@ export default {
}
}
},
async MsgJoinStaking({ rootGetters }, { value }) {
async MsgCreateStakingReward({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgJoinStaking(value)
const msg = await txClient.msgCreateStakingReward(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgJoinStaking:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgCreateStakingReward:Init Could not initialize signing client. Wallet is required.')
} else{
throw new Error('TxClient:MsgJoinStaking:Create Could not create message: ' + e.message)
throw new Error('TxClient:MsgCreateStakingReward:Create Could not create message: ' + e.message)
}
}
},
async MsgUpdateStakingReward({ rootGetters }, { value }) {
async MsgClaimStakingRewards({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgUpdateStakingReward(value)
const msg = await txClient.msgClaimStakingRewards(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgUpdateStakingReward:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgClaimStakingRewards:Init Could not initialize signing client. Wallet is required.')
} else{
throw new Error('TxClient:MsgUpdateStakingReward:Create Could not create message: ' + e.message)
throw new Error('TxClient:MsgClaimStakingRewards:Create Could not create message: ' + e.message)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { StdFee } from "@cosmjs/launchpad";
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgCreateStakingReward } from "./types/rewards/tx";
import { MsgExitStaking } from "./types/rewards/tx";
import { MsgClaimStakingRewards } from "./types/rewards/tx";
import { MsgCreateTradingReward } from "./types/rewards/tx";
import { MsgJoinStaking } from "./types/rewards/tx";
import { MsgExitStaking } from "./types/rewards/tx";
import { MsgUpdateStakingReward } from "./types/rewards/tx";
import { MsgCreateTradingReward } from "./types/rewards/tx";
import { MsgCreateStakingReward } from "./types/rewards/tx";
import { MsgClaimStakingRewards } from "./types/rewards/tx";


const types = [
["/bze.v1.rewards.MsgCreateStakingReward", MsgCreateStakingReward],
["/bze.v1.rewards.MsgExitStaking", MsgExitStaking],
["/bze.v1.rewards.MsgClaimStakingRewards", MsgClaimStakingRewards],
["/bze.v1.rewards.MsgCreateTradingReward", MsgCreateTradingReward],
["/bze.v1.rewards.MsgJoinStaking", MsgJoinStaking],
["/bze.v1.rewards.MsgExitStaking", MsgExitStaking],
["/bze.v1.rewards.MsgUpdateStakingReward", MsgUpdateStakingReward],
["/bze.v1.rewards.MsgCreateTradingReward", MsgCreateTradingReward],
["/bze.v1.rewards.MsgCreateStakingReward", MsgCreateStakingReward],
["/bze.v1.rewards.MsgClaimStakingRewards", MsgClaimStakingRewards],

];
export const MissingWalletError = new Error("wallet is required");
Expand Down Expand Up @@ -51,12 +51,12 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =

return {
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo),
msgCreateStakingReward: (data: MsgCreateStakingReward): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgCreateStakingReward", value: MsgCreateStakingReward.fromPartial( data ) }),
msgExitStaking: (data: MsgExitStaking): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgExitStaking", value: MsgExitStaking.fromPartial( data ) }),
msgClaimStakingRewards: (data: MsgClaimStakingRewards): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgClaimStakingRewards", value: MsgClaimStakingRewards.fromPartial( data ) }),
msgCreateTradingReward: (data: MsgCreateTradingReward): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgCreateTradingReward", value: MsgCreateTradingReward.fromPartial( data ) }),
msgJoinStaking: (data: MsgJoinStaking): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgJoinStaking", value: MsgJoinStaking.fromPartial( data ) }),
msgExitStaking: (data: MsgExitStaking): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgExitStaking", value: MsgExitStaking.fromPartial( data ) }),
msgUpdateStakingReward: (data: MsgUpdateStakingReward): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgUpdateStakingReward", value: MsgUpdateStakingReward.fromPartial( data ) }),
msgCreateTradingReward: (data: MsgCreateTradingReward): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgCreateTradingReward", value: MsgCreateTradingReward.fromPartial( data ) }),
msgCreateStakingReward: (data: MsgCreateStakingReward): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgCreateStakingReward", value: MsgCreateStakingReward.fromPartial( data ) }),
msgClaimStakingRewards: (data: MsgClaimStakingRewards): EncodeObject => ({ typeUrl: "/bze.v1.rewards.MsgClaimStakingRewards", value: MsgClaimStakingRewards.fromPartial( data ) }),

};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { util, configure, Writer, Reader } from "protobufjs/minimal";
import { Params } from "../rewards/params";
import { StakingReward } from "../rewards/staking_reward";
import { TradingReward } from "../rewards/trading_reward";
import { StakingRewardParticipant } from "../rewards/staking_reward_participant";
import {
StakingRewardParticipant,
PendingUnlockParticipant,
} from "../rewards/staking_reward_participant";

export const protobufPackage = "bze.v1.rewards";

Expand All @@ -15,8 +18,9 @@ export interface GenesisState {
staking_rewards_counter: number;
trading_rewards_counter: number;
trading_reward_list: TradingReward[];
/** this line is used by starport scaffolding # genesis/proto/state */
staking_reward_participant_list: StakingRewardParticipant[];
/** this line is used by starport scaffolding # genesis/proto/state */
pending_unlock_participant_list: PendingUnlockParticipant[];
}

const baseGenesisState: object = {
Expand Down Expand Up @@ -44,6 +48,9 @@ export const GenesisState = {
for (const v of message.staking_reward_participant_list) {
StakingRewardParticipant.encode(v!, writer.uint32(50).fork()).ldelim();
}
for (const v of message.pending_unlock_participant_list) {
PendingUnlockParticipant.encode(v!, writer.uint32(58).fork()).ldelim();
}
return writer;
},

Expand All @@ -54,6 +61,7 @@ export const GenesisState = {
message.staking_reward_list = [];
message.trading_reward_list = [];
message.staking_reward_participant_list = [];
message.pending_unlock_participant_list = [];
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
Expand Down Expand Up @@ -85,6 +93,11 @@ export const GenesisState = {
StakingRewardParticipant.decode(reader, reader.uint32())
);
break;
case 7:
message.pending_unlock_participant_list.push(
PendingUnlockParticipant.decode(reader, reader.uint32())
);
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -98,6 +111,7 @@ export const GenesisState = {
message.staking_reward_list = [];
message.trading_reward_list = [];
message.staking_reward_participant_list = [];
message.pending_unlock_participant_list = [];
if (object.params !== undefined && object.params !== null) {
message.params = Params.fromJSON(object.params);
} else {
Expand Down Expand Up @@ -145,6 +159,16 @@ export const GenesisState = {
);
}
}
if (
object.pending_unlock_participant_list !== undefined &&
object.pending_unlock_participant_list !== null
) {
for (const e of object.pending_unlock_participant_list) {
message.pending_unlock_participant_list.push(
PendingUnlockParticipant.fromJSON(e)
);
}
}
return message;
},

Expand Down Expand Up @@ -177,6 +201,13 @@ export const GenesisState = {
} else {
obj.staking_reward_participant_list = [];
}
if (message.pending_unlock_participant_list) {
obj.pending_unlock_participant_list = message.pending_unlock_participant_list.map(
(e) => (e ? PendingUnlockParticipant.toJSON(e) : undefined)
);
} else {
obj.pending_unlock_participant_list = [];
}
return obj;
},

Expand All @@ -185,6 +216,7 @@ export const GenesisState = {
message.staking_reward_list = [];
message.trading_reward_list = [];
message.staking_reward_participant_list = [];
message.pending_unlock_participant_list = [];
if (object.params !== undefined && object.params !== null) {
message.params = Params.fromPartial(object.params);
} else {
Expand Down Expand Up @@ -232,6 +264,16 @@ export const GenesisState = {
);
}
}
if (
object.pending_unlock_participant_list !== undefined &&
object.pending_unlock_participant_list !== null
) {
for (const e of object.pending_unlock_participant_list) {
message.pending_unlock_participant_list.push(
PendingUnlockParticipant.fromPartial(e)
);
}
}
return message;
},
};
Expand Down
7 changes: 7 additions & 0 deletions x/rewards/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
for _, elem := range genState.StakingRewardParticipantList {
k.SetStakingRewardParticipant(ctx, elem)
}

// Set all the stakingRewardParticipant
for _, elem := range genState.PendingUnlockParticipantList {
k.SetPendingUnlockParticipant(ctx, elem)
}

// this line is used by starport scaffolding # genesis/module/init
k.SetParams(ctx, genState.Params)
k.SetTradingRewardsCounter(ctx, genState.TradingRewardsCounter)
Expand All @@ -38,6 +44,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis.TradingRewardsCounter = k.GetTradingRewardsCounter(ctx)
genesis.TradingRewardList = k.GetAllTradingReward(ctx)
genesis.StakingRewardParticipantList = k.GetAllStakingRewardParticipant(ctx)
genesis.PendingUnlockParticipantList = k.GetAllPendingUnlockParticipant(ctx)
// this line is used by starport scaffolding # genesis/module/export

return genesis
Expand Down
4 changes: 2 additions & 2 deletions x/rewards/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func (k Keeper) GetDistributeAllStakingRewardsHook() types.EpochHook {
hookName := "distribution_hook"
return types.NewBeforeEpochHook(hookName, func(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
return types.NewAfterEpochHook(hookName, func(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
if epochIdentifier != distributionEpoch {
return nil
}
Expand All @@ -24,7 +24,7 @@ func (k Keeper) GetDistributeAllStakingRewardsHook() types.EpochHook {

func (k Keeper) GetUnlockPendingUnlockParticipantsHook() types.EpochHook {
hookName := "pending_unlock_hook"
return types.NewBeforeEpochHook(hookName, func(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
return types.NewAfterEpochHook(hookName, func(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
if epochIdentifier != distributionEpoch {
return nil
}
Expand Down
16 changes: 16 additions & 0 deletions x/rewards/keeper/pending_unlock_participant.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ func (k Keeper) GetAllEpochPendingUnlockParticipant(ctx sdk.Context, epoch int64

return
}

// GetAllPendingUnlockParticipant returns all types.PendingUnlockParticipant
func (k Keeper) GetAllPendingUnlockParticipant(ctx sdk.Context) (list []types.PendingUnlockParticipant) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PendingUnlockParticipantKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.PendingUnlockParticipant
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}
Loading

0 comments on commit 28b7083

Please sign in to comment.