diff --git a/proto/sge/reward/genesis.proto b/proto/sge/reward/genesis.proto index 58b8568b..289ccf9f 100644 --- a/proto/sge/reward/genesis.proto +++ b/proto/sge/reward/genesis.proto @@ -19,8 +19,7 @@ message GenesisState { [ (gogoproto.nullable) = false ]; repeated RewardByCampaign reward_by_campaign_list = 5 [ (gogoproto.nullable) = false ]; - repeated Promoter promoter_list = 6 - [ (gogoproto.nullable) = false ]; + repeated Promoter promoter_list = 6 [ (gogoproto.nullable) = false ]; repeated PromoterByAddress promoter_by_address_list = 7 [ (gogoproto.nullable) = false ]; } diff --git a/proto/sge/reward/promoter.proto b/proto/sge/reward/promoter.proto index 3b717c91..d8e0d5e3 100644 --- a/proto/sge/reward/promoter.proto +++ b/proto/sge/reward/promoter.proto @@ -7,45 +7,46 @@ import "sge/reward/reward.proto"; option go_package = "github.com/sge-network/sge/x/reward/types"; -// Promoter is type for defining the reward promoter properties and configuration. +// Promoter is type for defining the reward promoter properties and +// configuration. message Promoter { - // creator is the address of promoter. - string creator = 1; - - // uid is the unique identifier of a promoter. - string uid = 2 [ - (gogoproto.customname) = "UID", - (gogoproto.jsontag) = "uid", - json_name = "uid" - ]; - - // addresses is the list of account addresses of promoter. - repeated string addresses = 3; - - // conf is the configurations of the current promoter for the reward grant. - PromoterConf conf = 4 [ (gogoproto.nullable) = false ]; + // creator is the address of promoter. + string creator = 1; + + // uid is the unique identifier of a promoter. + string uid = 2 [ + (gogoproto.customname) = "UID", + (gogoproto.jsontag) = "uid", + json_name = "uid" + ]; + + // addresses is the list of account addresses of promoter. + repeated string addresses = 3; + + // conf is the configurations of the current promoter for the reward grant. + PromoterConf conf = 4 [ (gogoproto.nullable) = false ]; } // PromoterConf is type for defining the promoter specific configurations. message PromoterConf { - // category_cap is the maximium allowed cap for each category. - repeated CategoryCap category_cap = 1 [ (gogoproto.nullable) = false ]; + // category_cap is the maximium allowed cap for each category. + repeated CategoryCap category_cap = 1 [ (gogoproto.nullable) = false ]; } // CategoryCap is type to define category and its maximum cap. message CategoryCap { - RewardCategory category = 1; - int32 cap_per_acc = 2; + RewardCategory category = 1; + int32 cap_per_acc = 2; } // PromoterByAddress is type for defining the promoter by address. message PromoterByAddress { - // promoter_uid is the unique identifier of a certain promoter. - string promoter_uid = 1 [ - (gogoproto.customname) = "PromoterUID", - (gogoproto.jsontag) = "promoter_uid", - json_name = "promoter_uid" - ]; - // address is the address of the promoter account. - string address = 2; + // promoter_uid is the unique identifier of a certain promoter. + string promoter_uid = 1 [ + (gogoproto.customname) = "PromoterUID", + (gogoproto.jsontag) = "promoter_uid", + json_name = "promoter_uid" + ]; + // address is the address of the promoter account. + string address = 2; } \ No newline at end of file diff --git a/proto/sge/reward/query.proto b/proto/sge/reward/query.proto index f1dcb6fe..a9d30e30 100644 --- a/proto/sge/reward/query.proto +++ b/proto/sge/reward/query.proto @@ -21,8 +21,10 @@ service Query { } // PromoterByAddress queries a certain promoter. - rpc PromoterByAddress(QueryPromoterByAddressRequest) returns (QueryPromoterByAddressResponse) { - option (google.api.http).get = "/sge-network/sge/reward/promoter-by-address/{addr}"; + rpc PromoterByAddress(QueryPromoterByAddressRequest) + returns (QueryPromoterByAddressResponse) { + option (google.api.http).get = + "/sge-network/sge/reward/promoter-by-address/{addr}"; } // Queries list of all Promoter items. @@ -53,7 +55,8 @@ service Query { // Queries list of all Reward items by user address. rpc RewardsByAddress(QueryRewardsByAddressRequest) returns (QueryRewardsByAddressResponse) { - option (google.api.http).get = "/sge-network/sge/reward/rewards/{promoter_uid}/{address}"; + option (google.api.http).get = + "/sge-network/sge/reward/rewards/{promoter_uid}/{address}"; } // Queries list of all Reward items by user address and reward type @@ -81,12 +84,12 @@ message QueryParamsResponse { Params params = 1 [ (gogoproto.nullable) = false ]; } -// QueryPromoterByAddressRequest is request type for the Query/GetPromoterByAddress RPC method. -message QueryPromoterByAddressRequest { - string addr = 1; -} +// QueryPromoterByAddressRequest is request type for the +// Query/GetPromoterByAddress RPC method. +message QueryPromoterByAddressRequest { string addr = 1; } -// QueryPromoterByAddressResponse is response type for the Query/GetPromoterByAddress RPC method. +// QueryPromoterByAddressResponse is response type for the +// Query/GetPromoterByAddress RPC method. message QueryPromoterByAddressResponse { // promoter holds the queries promoter. Promoter promoter = 1 [ (gogoproto.nullable) = false ]; diff --git a/proto/sge/reward/reward.proto b/proto/sge/reward/reward.proto index d635464a..8eb1479b 100644 --- a/proto/sge/reward/reward.proto +++ b/proto/sge/reward/reward.proto @@ -53,14 +53,14 @@ message Reward { // RewardAmount message RewardAmount { - // main_account_reward amount transferred to main account address + // main_account_amount transferred to main account address string main_account_amount = 1 [ (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"main_account_amount\"" ]; - // sub_account reward amount transferred to subaccount address + // subaccount_amount transferred to subaccount address string subaccount_amount = 2 [ (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, @@ -73,6 +73,20 @@ message RewardAmount { (gogoproto.jsontag) = "unlock_period", json_name = "unlock_period" ]; + + // main_account_percentage transferred to main account address + string main_account_percentage = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"main_account_percentage\"" + ]; + + // subaccount_percentage amount transferred to subaccount address + string subaccount_percentage = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"subaccount_percentage\"" + ]; } // RewardByCategory diff --git a/x/reward/client/cli/tx_reward.go b/x/reward/client/cli/tx_reward.go index 5839b72d..629cf57a 100644 --- a/x/reward/client/cli/tx_reward.go +++ b/x/reward/client/cli/tx_reward.go @@ -12,8 +12,9 @@ import ( func CmdGrantReward() *cobra.Command { cmd := &cobra.Command{ - Use: "apply [uid] [campaign uid] [ticket]", - Short: "Apply a new reward", + Use: "grant [uid] [campaign uid] [ticket]", + Short: "Grant a new reward for the campaign", + Long: "Grant a new reward for the campaign with the provided uid", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) (err error) { // Get indexes diff --git a/x/reward/keeper/campaign.go b/x/reward/keeper/campaign.go index ab071f52..2df1281c 100644 --- a/x/reward/keeper/campaign.go +++ b/x/reward/keeper/campaign.go @@ -54,9 +54,8 @@ func (k Keeper) GetAllCampaign(ctx sdk.Context) (list []types.Campaign) { return } +// UpdateCampaignPool updates campaign pool according to the total receiving amount of receiver func (k Keeper) UpdateCampaignPool(ctx sdk.Context, campaign types.Campaign, receiver types.Receiver) { - totalAmount := receiver.SubaccountAmount.Add(receiver.MainAccountAmount) // Fixme: Check if the logic is correct - campaign.Pool.Spend(totalAmount) - + campaign.Pool.Spend(receiver.TotalAmount()) k.SetCampaign(ctx, campaign) } diff --git a/x/reward/keeper/distribution.go b/x/reward/keeper/distribution.go index 9eb020d1..e61d1360 100644 --- a/x/reward/keeper/distribution.go +++ b/x/reward/keeper/distribution.go @@ -12,24 +12,24 @@ import ( // DistributeRewards distributes the rewards according to the input distribution list. func (k Keeper) DistributeRewards(ctx sdk.Context, receiver types.Receiver) (uint64, error) { unlockTS := uint64(0) - if receiver.SubaccountAmount.GT(sdk.ZeroInt()) { + if receiver.RewardAmount.SubaccountAmount.GT(sdk.ZeroInt()) { moduleAccAddr := types.RewardPoolFunder{}.GetModuleAcc() - unlockTS = cast.ToUint64(ctx.BlockTime().Unix()) + receiver.UnlockPeriod + unlockTS = cast.ToUint64(ctx.BlockTime().Unix()) + receiver.RewardAmount.UnlockPeriod if _, err := k.subaccountKeeper.TopUp(ctx, k.accountKeeper.GetModuleAddress(moduleAccAddr).String(), receiver.MainAccountAddr, []subaccounttypes.LockedBalance{ { UnlockTS: unlockTS, - Amount: receiver.SubaccountAmount, + Amount: receiver.RewardAmount.SubaccountAmount, }, }); err != nil { return unlockTS, sdkerrors.Wrapf(types.ErrSubaccountRewardTopUp, "subaccount address %s, %s", receiver.SubaccountAddr, err) } } - if receiver.MainAccountAmount.GT(sdk.ZeroInt()) { + if receiver.RewardAmount.MainAccountAmount.GT(sdk.ZeroInt()) { if err := k.modFunder.Refund( types.RewardPoolFunder{}, ctx, sdk.MustAccAddressFromBech32(receiver.MainAccountAddr), - receiver.MainAccountAmount, + receiver.RewardAmount.MainAccountAmount, ); err != nil { return unlockTS, err } diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index a8b6bcdd..277c0d38 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -55,6 +55,19 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "defined reward amount %s is more than total funds %s", totalRewardAmount, msg.TotalFunds) } + totalRewardPercentage := sdk.ZeroDec() + if !payload.RewardAmount.MainAccountPercentage.IsNil() { + totalRewardPercentage = totalRewardPercentage.Add(payload.RewardAmount.MainAccountPercentage) + } + if !payload.RewardAmount.SubaccountPercentage.IsNil() { + totalRewardPercentage = totalRewardPercentage.Add(payload.RewardAmount.SubaccountPercentage) + } + + // check the sum of percentages, it should not be more than or equal to 1 (100%) + if totalRewardPercentage.GTE(sdk.OneDec()) { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "defined reward percentage is equal or more than 1.0(100 percent), the provided value is %s", totalRewardPercentage) + } + campaign := types.NewCampaign( msg.Creator, payload.Promoter, msg.Uid, payload.StartTs, payload.EndTs, diff --git a/x/reward/keeper/msg_server_reward.go b/x/reward/keeper/msg_server_reward.go index ab488963..55092609 100644 --- a/x/reward/keeper/msg_server_reward.go +++ b/x/reward/keeper/msg_server_reward.go @@ -84,7 +84,7 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) } } - if err := campaign.CheckPoolBalance(factData.Receiver.SubaccountAmount.Add(factData.Receiver.MainAccountAmount)); err != nil { + if err := campaign.CheckPoolBalance(factData.Receiver.TotalAmount()); err != nil { return nil, types.ErrInsufficientPoolBalance } @@ -94,9 +94,10 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) } k.UpdateCampaignPool(ctx, campaign, factData.Receiver) + k.SetReward(ctx, types.NewReward( - msg.Uid, msg.Creator, factData.Receiver.MainAccountAddr, - msg.CampaignUid, campaign.RewardAmount, + msg.Uid, msg.Creator, factData.Receiver, + msg.CampaignUid, factData.Common.SourceUID, factData.Common.Meta, )) @@ -104,7 +105,7 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) k.SetRewardOfReceiverByPromoterAndCategory(ctx, promoter.UID, types.NewRewardByCategory(msg.Uid, factData.Receiver.MainAccountAddr, campaign.RewardCategory)) k.SetRewardByCampaign(ctx, types.NewRewardByCampaign(msg.Uid, campaign.UID)) - msg.EmitEvent(&ctx, msg.CampaignUid, msg.Uid, campaign.Promoter, *campaign.RewardAmount, factData.Receiver, unlockTS) + msg.EmitEvent(&ctx, msg.CampaignUid, msg.Uid, campaign.Promoter, factData.Receiver, unlockTS) return &types.MsgGrantRewardResponse{}, nil } diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index 7a723053..f2e4a398 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -710,8 +710,8 @@ func TestMsgApplyBetBonus(t *testing.T) { betBonusCampClaims["reward_type"] = types.RewardType_REWARD_TYPE_BET_DISCOUNT betBonusCampClaims["reward_amount_type"] = types.RewardAmountType_REWARD_AMOUNT_TYPE_PERCENTAGE betBonusCampClaims["reward_amount"] = types.RewardAmount{ - MainAccountAmount: sdkmath.NewInt(10), - UnlockPeriod: 0, + MainAccountPercentage: sdk.NewDecWithPrec(10, 2), + UnlockPeriod: 0, } betBonusCampClaims["constraints"] = types.CampaignConstraints{ MaxBetAmount: sdkmath.NewInt(300), diff --git a/x/reward/types/messages_reward.go b/x/reward/types/messages_reward.go index 80c3459b..58849780 100644 --- a/x/reward/types/messages_reward.go +++ b/x/reward/types/messages_reward.go @@ -74,15 +74,15 @@ func (msg *MsgGrantReward) ValidateBasic() error { // EmitEvent emits the event for the message success. func (msg *MsgGrantReward) EmitEvent(ctx *sdk.Context, campaignUID string, - rewardUID, promoterAddr string, rewardAmount RewardAmount, receiver Receiver, subAccUnlockTS uint64, + rewardUID, promoterAddr string, receiver Receiver, subAccUnlockTS uint64, ) { mainAmount := sdkmath.ZeroInt() - if !rewardAmount.MainAccountAmount.IsNil() { - mainAmount = rewardAmount.MainAccountAmount + if !receiver.RewardAmount.MainAccountAmount.IsNil() { + mainAmount = receiver.RewardAmount.MainAccountAmount } subAmount := sdkmath.ZeroInt() - if !rewardAmount.SubaccountAmount.IsNil() { - subAmount = rewardAmount.SubaccountAmount + if !receiver.RewardAmount.SubaccountAmount.IsNil() { + subAmount = receiver.RewardAmount.SubaccountAmount } emitter := utils.NewEventEmitter(ctx, attributeValueCategory) diff --git a/x/reward/types/promoter.pb.go b/x/reward/types/promoter.pb.go index 7fd7945a..89bbaade 100644 --- a/x/reward/types/promoter.pb.go +++ b/x/reward/types/promoter.pb.go @@ -23,7 +23,8 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Promoter is type for defining the reward promoter properties and configuration. +// Promoter is type for defining the reward promoter properties and +// configuration. type Promoter struct { // creator is the address of promoter. Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` diff --git a/x/reward/types/query.pb.go b/x/reward/types/query.pb.go index 40424699..ac17bede 100644 --- a/x/reward/types/query.pb.go +++ b/x/reward/types/query.pb.go @@ -113,7 +113,8 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } -// QueryPromoterByAddressRequest is request type for the Query/GetPromoterByAddress RPC method. +// QueryPromoterByAddressRequest is request type for the +// Query/GetPromoterByAddress RPC method. type QueryPromoterByAddressRequest struct { Addr string `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` } @@ -158,7 +159,8 @@ func (m *QueryPromoterByAddressRequest) GetAddr() string { return "" } -// QueryPromoterByAddressResponse is response type for the Query/GetPromoterByAddress RPC method. +// QueryPromoterByAddressResponse is response type for the +// Query/GetPromoterByAddress RPC method. type QueryPromoterByAddressResponse struct { // promoter holds the queries promoter. Promoter Promoter `protobuf:"bytes,1,opt,name=promoter,proto3" json:"promoter"` diff --git a/x/reward/types/reward.go b/x/reward/types/reward.go index f599de45..a07442e6 100644 --- a/x/reward/types/reward.go +++ b/x/reward/types/reward.go @@ -13,11 +13,9 @@ import ( ) type Receiver struct { - SubaccountAddr string - SubaccountAmount sdkmath.Int - UnlockPeriod uint64 - MainAccountAddr string - MainAccountAmount sdkmath.Int + SubaccountAddr string + MainAccountAddr string + RewardAmount RewardAmount } // RewardFactoryKeepers holds the keeper objects usable by reward types methods. @@ -59,18 +57,30 @@ func NewRewardFactoryData(receiver Receiver, common RewardPayloadCommon) RewardF } } +func newRewardAmount(mainAccountAmount, subaccountAmount sdkmath.Int, + mainAccountPercentage, subaccountPercentage sdk.Dec, + unlockPeriod uint64, +) RewardAmount { + return RewardAmount{ + MainAccountAmount: mainAccountAmount, + SubaccountAmount: subaccountAmount, + MainAccountPercentage: mainAccountPercentage, + SubaccountPercentage: subaccountPercentage, + UnlockPeriod: unlockPeriod, + } +} + func NewReward( - uid, creator, receiver string, + uid, creator string, receiver Receiver, campaignUID string, - rewardAmount *RewardAmount, sourceUID, meta string, ) Reward { return Reward{ UID: uid, Creator: creator, - Receiver: receiver, + Receiver: receiver.MainAccountAddr, CampaignUID: campaignUID, - RewardAmount: rewardAmount, + RewardAmount: &receiver.RewardAmount, SourceUID: sourceUID, Meta: sanitize.XSS(meta), } @@ -100,13 +110,21 @@ type IRewardFactory interface { } // NewReceiver creates receiver object. -func NewReceiver(saAddr, maAddr string, saAmount, maAmount sdkmath.Int, unlockPeriod uint64) Receiver { +func NewReceiver(maAddr, saAddr string, + maAmount, saAmount sdkmath.Int, + maPercentage, saPercentage sdk.Dec, + unlockPeriod uint64, +) Receiver { return Receiver{ - SubaccountAddr: saAddr, - SubaccountAmount: saAmount, - UnlockPeriod: unlockPeriod, - MainAccountAddr: maAddr, - MainAccountAmount: maAmount, + SubaccountAddr: saAddr, + MainAccountAddr: maAddr, + RewardAmount: newRewardAmount( + maAmount, + saAmount, + maPercentage, + saPercentage, + unlockPeriod, + ), } } @@ -117,3 +135,7 @@ func (ds Receiver) String() string { } return string(out) } + +func (ds Receiver) TotalAmount() sdkmath.Int { + return ds.RewardAmount.MainAccountAmount.Add(ds.RewardAmount.SubaccountAmount) +} diff --git a/x/reward/types/reward.pb.go b/x/reward/types/reward.pb.go index fe1f5346..3ae560e8 100644 --- a/x/reward/types/reward.pb.go +++ b/x/reward/types/reward.pb.go @@ -6,6 +6,7 @@ package types import ( cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -279,12 +280,16 @@ func (m *Reward) GetMeta() string { // RewardAmount type RewardAmount struct { - // main_account_reward amount transferred to main account address + // main_account_amount transferred to main account address MainAccountAmount cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=main_account_amount,json=mainAccountAmount,proto3,customtype=cosmossdk.io/math.Int" json:"main_account_amount" yaml:"main_account_amount"` - // sub_account reward amount transferred to subaccount address + // subaccount_amount transferred to subaccount address SubaccountAmount cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=subaccount_amount,json=subaccountAmount,proto3,customtype=cosmossdk.io/math.Int" json:"subaccount_amount" yaml:"subaccount_amount"` // unlock_period is the period after which the reward is unlocked. UnlockPeriod uint64 `protobuf:"varint,3,opt,name=unlock_period,proto3" json:"unlock_period"` + // main_account_percentage transferred to main account address + MainAccountPercentage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=main_account_percentage,json=mainAccountPercentage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"main_account_percentage" yaml:"main_account_percentage"` + // subaccount_percentage amount transferred to subaccount address + SubaccountPercentage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=subaccount_percentage,json=subaccountPercentage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"subaccount_percentage" yaml:"subaccount_percentage"` } func (m *RewardAmount) Reset() { *m = RewardAmount{} } @@ -459,58 +464,63 @@ func init() { func init() { proto.RegisterFile("sge/reward/reward.proto", fileDescriptor_3412add70a4f177f) } var fileDescriptor_3412add70a4f177f = []byte{ - // 806 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x4f, 0x8f, 0xdb, 0x54, - 0x10, 0x8f, 0x9d, 0x74, 0xff, 0x4c, 0xb7, 0x8b, 0xf7, 0xd1, 0x6d, 0xdd, 0x6c, 0x6b, 0xa7, 0x46, - 0x48, 0x65, 0x25, 0x1c, 0xa9, 0x9c, 0xa0, 0x27, 0xc7, 0x79, 0x09, 0x96, 0xd2, 0x24, 0x7a, 0x71, - 0x04, 0xe5, 0x12, 0x79, 0x9d, 0x87, 0x1b, 0x65, 0x1d, 0x47, 0xb6, 0x43, 0xc9, 0x17, 0xe0, 0xcc, - 0x05, 0x89, 0x2f, 0xc0, 0x8d, 0x0f, 0xd2, 0x63, 0x8f, 0x88, 0x83, 0x85, 0xb2, 0x9c, 0x7a, 0xe4, - 0x13, 0x20, 0x3f, 0xdb, 0x89, 0x6d, 0x22, 0x58, 0x71, 0x49, 0xde, 0xcc, 0xef, 0x37, 0x6f, 0x66, - 0x7e, 0x6f, 0x46, 0x86, 0x87, 0x81, 0x43, 0x9b, 0x3e, 0x7d, 0x63, 0xf9, 0xd3, 0xf4, 0x4f, 0x5d, - 0xfa, 0x5e, 0xe8, 0xa1, 0xf3, 0xc0, 0xa1, 0x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 0xd8, 0x4e, 0xaf, 0xc3, 0xdc, 0x5b, 0x6d, - 0xc3, 0xb6, 0x5a, 0x1d, 0xa1, 0x73, 0x38, 0xcb, 0xa3, 0x89, 0x4e, 0xc7, 0x97, 0x3f, 0x6d, 0xd7, - 0x28, 0x59, 0x50, 0xa6, 0x96, 0x02, 0x52, 0xca, 0xd5, 0x5e, 0xc6, 0xe1, 0xfb, 0x44, 0xdb, 0x65, - 0xcb, 0x73, 0x3a, 0xc6, 0xd7, 0xb8, 0x5d, 0x98, 0x9b, 0x3c, 0xda, 0x1b, 0x74, 0x0d, 0x5d, 0xe0, - 0xd1, 0x53, 0x78, 0xb2, 0x07, 0x1d, 0x62, 0xa2, 0xe3, 0xbe, 0xa9, 0x75, 0xb1, 0x50, 0x6d, 0xe9, - 0x6f, 0x37, 0x12, 0xf7, 0x6e, 0x23, 0x71, 0x7f, 0x6c, 0x24, 0xee, 0xc7, 0x1b, 0xa9, 0xf2, 0xee, - 0x46, 0xaa, 0xfc, 0x76, 0x23, 0x55, 0xbe, 0xf9, 0xc4, 0x99, 0x85, 0xaf, 0x57, 0x57, 0xaa, 0xed, - 0xb9, 0xcd, 0xc0, 0xa1, 0x9f, 0xa6, 0xfb, 0x19, 0x9f, 0x9b, 0xdf, 0x67, 0x5f, 0xbb, 0x70, 0xbd, - 0xa4, 0xc1, 0xd5, 0x01, 0xfb, 0x80, 0x7d, 0xf6, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xb4, - 0x71, 0xab, 0x08, 0x07, 0x00, 0x00, + // 885 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x4f, 0x8f, 0xdb, 0x44, + 0x14, 0x8f, 0x93, 0xec, 0xbf, 0xd7, 0xed, 0xe2, 0x1d, 0x36, 0x5d, 0x37, 0xbb, 0xb5, 0xb7, 0x46, + 0xa0, 0xb2, 0x52, 0x1d, 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e, 0x96, 0xf8, 0xe3, 0x42, + 0x29, 0x18, 0x4e, 0x59, 0xe8, 0x1a, 0xee, 0xc6, 0x7d, 0x0c, 0xad, 0xa9, 0xbb, 0x98, 0x05, 0xc2, + 0xde, 0x05, 0xf7, 0xe8, 0xce, 0x93, 0x8f, 0x94, 0xdc, 0x66, 0x95, 0xb8, 0x25, 0x95, 0x42, 0xeb, + 0x0f, 0x57, 0xa1, 0x74, 0xc8, 0x7a, 0xde, 0x84, 0x52, 0x7a, 0x37, 0x9c, 0x36, 0xd1, 0x53, 0x00, + 0xdf, 0x5d, 0x78, 0x36, 0xa1, 0x84, 0xf7, 0x29, 0xe1, 0xb3, 0x55, 0x28, 0x1d, 0xf4, 0xa9, 0x37, + 0xa6, 0xcb, 0x40, 0x30, 0xb3, 0x46, 0x08, 0xca, 0x53, 0x12, 0x58, 0xc2, 0x21, 0xd5, 0x81, 0xae, + 0xe5, 0xdf, 0xcb, 0x90, 0x62, 0x80, 0x26, 0xf0, 0xe1, 0xd4, 0x1a, 0xcf, 0x86, 0x96, 0x6d, 0x47, + 0xf6, 0xba, 0xab, 0x58, 0xfc, 0xa7, 0xaf, 0x42, 0xa9, 0xf0, 0x67, 0x28, 0x55, 0x6c, 0xd7, 0x9f, + 0xba, 0xbe, 0x3f, 0x9a, 0x28, 0x63, 0xb7, 0x36, 0xb5, 0x82, 0x17, 0x8a, 0x31, 0x0b, 0xde, 0x86, + 0x52, 0x75, 0x69, 0x4d, 0xaf, 0xbf, 0x90, 0x73, 0x76, 0x90, 0xf1, 0x71, 0xe4, 0x55, 0x63, 0x67, + 0x52, 0xec, 0x5b, 0x38, 0xf6, 0x17, 0x57, 0x99, 0x52, 0xf4, 0x04, 0xeb, 0x9f, 0xff, 0x57, 0x29, + 0x21, 0x2e, 0xf5, 0x4e, 0xbe, 0x8c, 0xf9, 0xad, 0x2f, 0xa9, 0xd3, 0x82, 0xbb, 0x8b, 0xd9, 0xb5, + 0x6b, 0x4f, 0x86, 0x73, 0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a3, + 0xb1, 0x4e, 0x07, 0x97, 0xbf, 0x6c, 0xc6, 0x28, 0x7e, 0xb1, 0xa8, 0x5a, 0x32, 0x88, 0x09, 0x56, + 0x7d, 0x16, 0xa5, 0xe7, 0x89, 0xb6, 0xad, 0xc6, 0x62, 0x9a, 0xc6, 0xd7, 0x7a, 0x23, 0x75, 0x6f, + 0xd8, 0x68, 0xbb, 0xdb, 0x32, 0x34, 0xbe, 0x88, 0x1e, 0xc2, 0x83, 0x9c, 0x68, 0x4f, 0xc7, 0x9a, + 0xde, 0x31, 0xd5, 0x96, 0xce, 0x97, 0xea, 0xda, 0xab, 0x95, 0xc8, 0xbd, 0x5e, 0x89, 0xdc, 0x5f, + 0x2b, 0x91, 0xfb, 0xf9, 0x46, 0x2c, 0xbc, 0xbe, 0x11, 0x0b, 0x7f, 0xdc, 0x88, 0x85, 0x6f, 0x3e, + 0x65, 0x9e, 0x15, 0xdf, 0x21, 0x8f, 0x93, 0xf9, 0x8c, 0xd6, 0xb5, 0xef, 0xd7, 0x9f, 0x7f, 0xfa, + 0xba, 0x5c, 0xed, 0xd2, 0x2f, 0xfa, 0x67, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x1a, 0xd3, 0x8d, + 0x33, 0x19, 0x08, 0x00, 0x00, } func (m *Reward) Marshal() (dAtA []byte, err error) { @@ -610,6 +620,26 @@ func (m *RewardAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.SubaccountPercentage.Size() + i -= size + if _, err := m.SubaccountPercentage.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintReward(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size := m.MainAccountPercentage.Size() + i -= size + if _, err := m.MainAccountPercentage.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintReward(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 if m.UnlockPeriod != 0 { i = encodeVarintReward(dAtA, i, uint64(m.UnlockPeriod)) i-- @@ -778,6 +808,10 @@ func (m *RewardAmount) Size() (n int) { if m.UnlockPeriod != 0 { n += 1 + sovReward(uint64(m.UnlockPeriod)) } + l = m.MainAccountPercentage.Size() + n += 1 + l + sovReward(uint64(l)) + l = m.SubaccountPercentage.Size() + n += 1 + l + sovReward(uint64(l)) return n } @@ -1218,6 +1252,74 @@ func (m *RewardAmount) Unmarshal(dAtA []byte) error { break } } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MainAccountPercentage", 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.MainAccountPercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountPercentage", 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.SubaccountPercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipReward(dAtA[iNdEx:]) diff --git a/x/reward/types/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go index f387dc51..8e162686 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -10,8 +10,6 @@ import ( bettypes "github.com/sge-network/sge/x/bet/types" ) -var percent = sdk.NewInt(100) - // BetBonusReward is the type for bet bonus rewards calculations type BetBonusReward struct{} @@ -23,13 +21,7 @@ func (sur BetBonusReward) ValidateCampaign(campaign Campaign) error { if campaign.RewardCategory != RewardCategory_REWARD_CATEGORY_BET_DISCOUNT { return sdkerrors.Wrapf(ErrWrongRewardCategory, "bet bonus rewards can only have single definition") } - if campaign.RewardAmount.MainAccountAmount.GT(percent) { - return sdkerrors.Wrapf(ErrWrongAmountForType, "bet bonus rewards percent for main account should be between 0 and 100") - } - if campaign.RewardAmount.SubaccountAmount.GT(percent) { - return sdkerrors.Wrapf(ErrWrongAmountForType, "bet bonus rewards percent for sub account should be between 0 and 100") - } - if campaign.RewardAmount.MainAccountAmount.IsZero() && campaign.RewardAmount.SubaccountAmount.IsZero() { + if campaign.RewardAmount.MainAccountPercentage.IsZero() && campaign.RewardAmount.SubaccountPercentage.IsZero() { return sdkerrors.Wrapf(ErrWrongAmountForType, "one of main account and sub account percentage should be higher than zero") } if campaign.RewardAmountType != RewardAmountType_REWARD_AMOUNT_TYPE_PERCENTAGE { @@ -64,7 +56,7 @@ func (sur BetBonusReward) Calculate(goCtx context.Context, ctx sdk.Context, keep return RewardFactoryData{}, ErrReceiverAddrCanNotBeSubaccount } - subAccountAddressString, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) + subaccountAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) if err != nil { return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } @@ -97,19 +89,15 @@ func (sur BetBonusReward) Calculate(goCtx context.Context, ctx sdk.Context, keep } } - mainAmount := effectiveBetAmount.Mul( - sdk.NewDecFromInt(campaign.RewardAmount.MainAccountAmount).QuoInt(percent), - ).TruncateInt() - subAmount := effectiveBetAmount.Mul( - sdk.NewDecFromInt(campaign.RewardAmount.SubaccountAmount).QuoInt(percent), - ).TruncateInt() + mainAmount := effectiveBetAmount.Mul(campaign.RewardAmount.MainAccountPercentage).TruncateInt() + subAmount := effectiveBetAmount.Mul(campaign.RewardAmount.SubaccountPercentage).TruncateInt() return NewRewardFactoryData( NewReceiver( - subAccountAddressString, payload.Common.Receiver, - subAmount, - mainAmount, + subaccountAddrStr, + mainAmount, subAmount, + campaign.RewardAmount.MainAccountPercentage, campaign.RewardAmount.SubaccountPercentage, campaign.RewardAmount.UnlockPeriod, ), payload.Common, diff --git a/x/reward/types/reward_signup.go b/x/reward/types/reward_signup.go index db590acc..fa19fa08 100644 --- a/x/reward/types/reward_signup.go +++ b/x/reward/types/reward_signup.go @@ -52,17 +52,18 @@ func (sur SignUpReward) Calculate(goCtx context.Context, ctx sdk.Context, keeper return RewardFactoryData{}, ErrReceiverAddrCanNotBeSubaccount } - subAccountAddressString, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) + subaccountAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) if err != nil { return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } return NewRewardFactoryData( NewReceiver( - subAccountAddressString, payload.Common.Receiver, - campaign.RewardAmount.SubaccountAmount, + subaccountAddrStr, campaign.RewardAmount.MainAccountAmount, + campaign.RewardAmount.SubaccountAmount, + sdk.ZeroDec(), sdk.ZeroDec(), campaign.RewardAmount.UnlockPeriod, ), payload.Common, diff --git a/x/reward/types/reward_signup_affiliatee.go b/x/reward/types/reward_signup_affiliatee.go index f3772d86..f2afa6cf 100644 --- a/x/reward/types/reward_signup_affiliatee.go +++ b/x/reward/types/reward_signup_affiliatee.go @@ -56,17 +56,18 @@ func (sur SignUpAffiliateeReward) Calculate(goCtx context.Context, ctx sdk.Conte return RewardFactoryData{}, ErrReceiverAddrCanNotBeSubaccount } - subAccAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) + subaccountAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) if err != nil { return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } return NewRewardFactoryData( NewReceiver( - subAccAddrStr, payload.Common.Receiver, - campaign.RewardAmount.SubaccountAmount, + subaccountAddrStr, campaign.RewardAmount.MainAccountAmount, + campaign.RewardAmount.SubaccountAmount, + sdk.ZeroDec(), sdk.ZeroDec(), campaign.RewardAmount.UnlockPeriod, ), payload.Common, diff --git a/x/reward/types/reward_signup_affiliator.go b/x/reward/types/reward_signup_affiliator.go index 54b72f01..75a9f542 100644 --- a/x/reward/types/reward_signup_affiliator.go +++ b/x/reward/types/reward_signup_affiliator.go @@ -64,17 +64,18 @@ func (sur SignUpAffiliatorReward) Calculate(goCtx context.Context, ctx sdk.Conte return RewardFactoryData{}, ErrReceiverAddrCanNotBeSubaccount } - subAccAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) + subaccountAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) if err != nil { return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } return NewRewardFactoryData( NewReceiver( - subAccAddrStr, payload.Common.Receiver, - campaign.RewardAmount.SubaccountAmount, + subaccountAddrStr, campaign.RewardAmount.MainAccountAmount, + campaign.RewardAmount.SubaccountAmount, + sdk.ZeroDec(), sdk.ZeroDec(), campaign.RewardAmount.UnlockPeriod, ), payload.Common, diff --git a/x/reward/types/reward_signup_referee.go b/x/reward/types/reward_signup_referee.go index 6c014f39..ecde0865 100644 --- a/x/reward/types/reward_signup_referee.go +++ b/x/reward/types/reward_signup_referee.go @@ -56,17 +56,18 @@ func (sur SignUpRefereelReward) Calculate(goCtx context.Context, ctx sdk.Context return RewardFactoryData{}, ErrReceiverAddrCanNotBeSubaccount } - subAccAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) + subaccountAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) if err != nil { return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } return NewRewardFactoryData( NewReceiver( - subAccAddrStr, payload.Common.Receiver, - campaign.RewardAmount.SubaccountAmount, + subaccountAddrStr, campaign.RewardAmount.MainAccountAmount, + campaign.RewardAmount.SubaccountAmount, + sdk.ZeroDec(), sdk.ZeroDec(), campaign.RewardAmount.UnlockPeriod, ), payload.Common, diff --git a/x/reward/types/reward_signup_referrer.go b/x/reward/types/reward_signup_referrer.go index fdce94e4..b1481a21 100644 --- a/x/reward/types/reward_signup_referrer.go +++ b/x/reward/types/reward_signup_referrer.go @@ -61,17 +61,18 @@ func (sur SignUpReferrerReward) Calculate(goCtx context.Context, ctx sdk.Context return RewardFactoryData{}, ErrReceiverAddrCanNotBeSubaccount } - subAccAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) + subaccountAddrStr, err := keepers.getSubaccountAddr(ctx, creator, payload.Common.Receiver) if err != nil { return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } return NewRewardFactoryData( NewReceiver( - subAccAddrStr, payload.Common.Receiver, - campaign.RewardAmount.SubaccountAmount, + subaccountAddrStr, campaign.RewardAmount.MainAccountAmount, + campaign.RewardAmount.SubaccountAmount, + sdk.ZeroDec(), sdk.ZeroDec(), campaign.RewardAmount.UnlockPeriod, ), payload.Common, diff --git a/x/reward/types/ticket.go b/x/reward/types/ticket.go index c4b18f37..91abf72e 100644 --- a/x/reward/types/ticket.go +++ b/x/reward/types/ticket.go @@ -30,14 +30,41 @@ func (payload *CreateCampaignPayload) Validate(blockTime uint64) error { return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, err.Error()) } - if (payload.RewardAmount.MainAccountAmount.IsNil() || - payload.RewardAmount.MainAccountAmount.Equal(sdkmath.ZeroInt())) && - (payload.RewardAmount.SubaccountAmount.IsNil() || - payload.RewardAmount.SubaccountAmount.Equal(sdkmath.ZeroInt())) { - return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "reward amount should be set for atleast one of main account or subaccount") + switch payload.RewardAmountType { + case RewardAmountType_REWARD_AMOUNT_TYPE_FIXED: + if (!payload.RewardAmount.MainAccountPercentage.IsNil() && + payload.RewardAmount.MainAccountPercentage.GT(sdk.ZeroDec())) || + (!payload.RewardAmount.SubaccountPercentage.IsNil() && + payload.RewardAmount.SubaccountPercentage.GT(sdk.ZeroDec())) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "reward percentage is not allowed for fixed amount campaign") + } + if (payload.RewardAmount.MainAccountAmount.IsNil() || + payload.RewardAmount.MainAccountAmount.LTE(sdkmath.ZeroInt())) && + (payload.RewardAmount.SubaccountAmount.IsNil() || + payload.RewardAmount.SubaccountAmount.LTE(sdkmath.ZeroInt())) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "reward amount should be set for at least one of main account or subaccount") + } + case RewardAmountType_REWARD_AMOUNT_TYPE_PERCENTAGE: + if (!payload.RewardAmount.MainAccountAmount.IsNil() && + payload.RewardAmount.MainAccountAmount.GT(sdkmath.ZeroInt())) || + (!payload.RewardAmount.SubaccountAmount.IsNil() && + payload.RewardAmount.SubaccountAmount.GT(sdkmath.ZeroInt())) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "reward amount is not allowed for percentage campaign") + } + if (payload.RewardAmount.MainAccountPercentage.IsNil() || + payload.RewardAmount.MainAccountPercentage.LTE(sdk.ZeroDec())) && + (payload.RewardAmount.SubaccountPercentage.IsNil() || + payload.RewardAmount.SubaccountPercentage.LTE(sdk.ZeroDec())) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "reward percentage should be set for at least one of main account or subaccount") + } + default: + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "unsupported reward amount type") } - if payload.RewardAmount.SubaccountAmount.GT(sdkmath.ZeroInt()) && + if ((!payload.RewardAmount.SubaccountAmount.IsNil() && + payload.RewardAmount.SubaccountAmount.GT(sdkmath.ZeroInt())) || + (!payload.RewardAmount.SubaccountPercentage.IsNil() && + payload.RewardAmount.SubaccountPercentage.GT(sdk.ZeroDec()))) && payload.RewardAmount.UnlockPeriod == 0 { return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "sub account should have unlock period") }