diff --git a/proto/buf.lock b/proto/buf.lock index e8cab8f5..07312228 100644 --- a/proto/buf.lock +++ b/proto/buf.lock @@ -4,8 +4,8 @@ deps: - remote: buf.build owner: cosmos repository: cosmos-proto - commit: 1935555c206d4afb9e94615dfd0fad31 - digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 + commit: 04467658e59e44bbb22fe568206e1f70 + digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466 - remote: buf.build owner: cosmos repository: cosmos-sdk diff --git a/proto/sgenetwork/sge/reward/reward.proto b/proto/sgenetwork/sge/reward/reward.proto index d635464a..8eb1479b 100644 --- a/proto/sgenetwork/sge/reward/reward.proto +++ b/proto/sgenetwork/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 6acbeb28..3010401e 100644 --- a/x/reward/keeper/distribution.go +++ b/x/reward/keeper/distribution.go @@ -13,24 +13,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(sdkmath.ZeroInt()) { + if receiver.RewardAmount.SubaccountAmount.GT(sdkmath.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(sdkmath.ZeroInt()) { + if receiver.RewardAmount.MainAccountAmount.GT(sdkmath.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 b79aeefe..36630b4a 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/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 4309928c..913da46f 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/cosmos/gogoproto/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{} } @@ -461,58 +466,63 @@ func init() { } var fileDescriptor_31e6858ad0a3d6b8 = []byte{ - // 805 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x41, 0x8f, 0xdb, 0x44, - 0x14, 0x8e, 0x9d, 0x34, 0xd9, 0x7d, 0xdd, 0x06, 0xef, 0xd0, 0x14, 0x37, 0xdb, 0xda, 0xa9, 0x11, - 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e, 0x6a, 0x2f, 0x82, 0x57, 0x9b, 0x2b, - 0xd9, 0x74, 0x9d, 0xe8, 0x7d, 0xfb, 0x2c, 0xfb, 0xd6, 0xfd, 0x90, 0xbe, 0x76, 0xc1, 0x76, 0x6d, - 0xf9, 0x57, 0x55, 0xfa, 0x80, 0x7d, 0xfe, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x56, 0x43, 0x53, - 0x4e, 0x13, 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, 0xad, 0x9b, 0xdd, 0xda, 0x5b, 0x23, + 0x50, 0x59, 0xa9, 0x8e, 0x54, 0x4e, 0xd0, 0x93, 0xe3, 0x38, 0xc1, 0xd2, 0x36, 0x89, 0x26, 0x8e, + 0xa0, 0x5c, 0x22, 0xaf, 0x33, 0xb8, 0x51, 0x36, 0x71, 0x64, 0x3b, 0x94, 0x9c, 0x91, 0x10, 0x47, + 0x2e, 0x48, 0x7c, 0x01, 0x3e, 0x06, 0xf7, 0x1e, 0x7b, 0x44, 0x1c, 0x2c, 0x94, 0xe5, 0xd4, 0x63, + 0x3f, 0x01, 0xf2, 0x8c, 0x93, 0x8c, 0xdd, 0x08, 0x4a, 0x2f, 0xc9, 0xbc, 0xf7, 0x7e, 0xef, 0xbd, + 0xdf, 0xfb, 0xcd, 0x1f, 0x83, 0x1a, 0x7a, 0x64, 0x4a, 0xa2, 0x17, 0x7e, 0x30, 0xae, 0x85, 0x1e, + 0xa9, 0x05, 0xe4, 0x85, 0x13, 0x0c, 0xd3, 0x3f, 0x6d, 0x16, 0xf8, 0x91, 0x8f, 0x2a, 0x1b, 0x8c, + 0x16, 0x7a, 0x44, 0x63, 0xc1, 0xea, 0x89, 0xe7, 0x7b, 0x3e, 0x45, 0xd4, 0x92, 0x15, 0x03, 0xab, + 0x7f, 0x17, 0x61, 0x17, 0x53, 0x00, 0x3a, 0x87, 0xd2, 0x7c, 0x34, 0x94, 0x84, 0x73, 0xe1, 0xe1, + 0x41, 0xfd, 0x68, 0x19, 0x2b, 0xa5, 0xbe, 0xd5, 0x78, 0x1d, 0x2b, 0x89, 0x17, 0x27, 0x3f, 0x48, + 0x82, 0x3d, 0x37, 0x20, 0x4e, 0xe4, 0x07, 0x52, 0x31, 0x41, 0xe1, 0x95, 0x89, 0xaa, 0xb0, 0x1f, + 0x10, 0x97, 0x8c, 0xbe, 0x23, 0x81, 0x54, 0xa2, 0xa1, 0xb5, 0x8d, 0x0c, 0x38, 0x74, 0x9d, 0xc9, + 0xcc, 0x19, 0x79, 0xd3, 0x41, 0xd2, 0xa0, 0x4c, 0x1b, 0x28, 0xcb, 0x58, 0xb9, 0x65, 0xa4, 0x7e, + 0xd6, 0x28, 0x03, 0xc3, 0x19, 0x0b, 0x5d, 0xc3, 0x6d, 0x36, 0xc7, 0xc0, 0x99, 0xf8, 0xf3, 0x69, + 0x24, 0xed, 0x9d, 0x0b, 0x0f, 0x6f, 0x3d, 0xfe, 0x48, 0xdb, 0x3a, 0xac, 0xc6, 0x46, 0xd2, 0x29, + 0xb4, 0xfe, 0x60, 0x19, 0x2b, 0x87, 0xbc, 0xe7, 0x75, 0xac, 0x64, 0xab, 0xe1, 0xac, 0x89, 0x9e, + 0x00, 0x84, 0xfe, 0x3c, 0x70, 0x09, 0x25, 0xbc, 0x4f, 0x09, 0x9f, 0x2e, 0x63, 0xe5, 0xa0, 0x47, + 0xbd, 0x8c, 0x2e, 0x07, 0xc1, 0xdc, 0x1a, 0x21, 0x28, 0x4f, 0x48, 0xe4, 0x48, 0x87, 0x54, 0x07, + 0xba, 0x56, 0x7f, 0x2f, 0x43, 0x86, 0x01, 0x1a, 0xc3, 0x87, 0x13, 0x67, 0x34, 0x1d, 0x38, 0x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, 0x9f, 0xbe, + 0x2e, 0x57, 0xbb, 0xf4, 0x8b, 0xfe, 0xd9, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa4, 0x14, 0x46, + 0xcc, 0x24, 0x08, 0x00, 0x00, } func (m *Reward) Marshal() (dAtA []byte, err error) { @@ -612,6 +622,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-- @@ -780,6 +810,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 } @@ -1220,6 +1254,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 48ed0161..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 = sdkmath.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") }