Skip to content

Commit

Permalink
Merge pull request #380 from sge-network/release/v1.6.x
Browse files Browse the repository at this point in the history
Release / v1.6.0
  • Loading branch information
3eyedraga authored Apr 8, 2024
2 parents 977c6da + b423944 commit 3ee84c9
Show file tree
Hide file tree
Showing 58 changed files with 6,614 additions and 667 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
v5 "github.com/sge-network/sge/app/upgrades/v5"
v6 "github.com/sge-network/sge/app/upgrades/v6"
v7 "github.com/sge-network/sge/app/upgrades/v7"
v8 "github.com/sge-network/sge/app/upgrades/v8"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -82,6 +83,7 @@ var (
v5.Upgrade,
v6.Upgrade,
v7.Upgrade,
v8.Upgrade,
}
)

Expand Down
19 changes: 19 additions & 0 deletions app/upgrades/v8/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v8

import (
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/sge-network/sge/app/upgrades"
)

// UpgradeName defines the on-chain upgrade name for the v1.6.0 upgrade.
const UpgradeName = "v1.6.0"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}
56 changes: 56 additions & 0 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package v8

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/google/uuid"
"github.com/sge-network/sge/app/keepers"
"github.com/sge-network/sge/x/reward/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
k *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
allCampaigns := k.RewardKeeper.GetAllCampaign(ctx)
promoters := make(map[string]struct{})
for _, c := range allCampaigns {
c.CapCount = 0 // infinite cap for all campaigns
c.Pool.Withdrawn = sdkmath.ZeroInt()
k.RewardKeeper.SetCampaign(ctx, c)
promoters[c.Promoter] = struct{}{}
}

promoterAddresses := []string{}
for addr := range promoters {
promoterAddresses = append(promoterAddresses, addr)
}

if len(promoterAddresses) > 0 {
promoterUID := uuid.NewString()
k.RewardKeeper.SetPromoter(ctx, types.Promoter{
Creator: promoterAddresses[0],
UID: promoterUID,
Addresses: promoterAddresses,
Conf: types.PromoterConf{
CategoryCap: []types.CategoryCap{
{Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1},
},
},
})

for _, addr := range promoterAddresses {
k.RewardKeeper.SetPromoterByAddress(ctx, types.PromoterByAddress{
PromoterUID: promoterUID,
Address: addr,
})
}
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}
2 changes: 2 additions & 0 deletions proto/sge/bet/bet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,6 @@ message MetaData {
sgenetwork.sge.bet.OddsType selected_odds_type = 1;
// selected_odds_value is metadata for bet
string selected_odds_value = 2;
// is_main_market will tell weather the bet placed on the main market or not
bool is_main_market = 3;
}
8 changes: 7 additions & 1 deletion proto/sge/reward/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ message UpdateCampaignAuthorization {

// WithdrawCampaignAuthorization allows the grantee to withdraw remaining
// pool balance of the campaign from the granter's account.
message WithdrawCampaignAuthorization {}
message WithdrawCampaignAuthorization {
// withdraw_limit is the maximum limit of the withdrawal by authorization.
string withdraw_limit = 1 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}
24 changes: 20 additions & 4 deletions proto/sge/reward/campaign.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ message Campaign {
// is_active is the flag to check if the campaign is active or not.
bool is_active = 11;

// claims_per_category is the number of times a user can claim a
// reward for category of this campaign.
uint64 claims_per_category = 12;

// meta is the metadata of the campaign.
// It is a stringified base64 encoded json.
string meta = 13;

// cap_count is the maximum allowed grant for a certain account.
uint64 cap_count = 14;

// constraints is the constrains of a campaign.
CampaignConstraints constraints = 15;
}

// Pool tracks funds assigned and spent to/for a campaign.
Expand All @@ -75,4 +77,18 @@ message Pool {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"spent\""
];
string withdrawn = 3 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"spent\""
];
}

// CampaignConstraints contains campaign constraints and criteria.
message CampaignConstraints {
string max_bet_amount = 1 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max_bet_amount\""
];
}
5 changes: 5 additions & 0 deletions proto/sge/reward/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "gogoproto/gogo.proto";
import "sge/reward/params.proto";
import "sge/reward/campaign.proto";
import "sge/reward/reward.proto";
import "sge/reward/promoter.proto";

option go_package = "github.com/sge-network/sge/x/reward/types";

Expand All @@ -18,4 +19,8 @@ message GenesisState {
[ (gogoproto.nullable) = false ];
repeated RewardByCampaign reward_by_campaign_list = 5
[ (gogoproto.nullable) = false ];
repeated Promoter promoter_list = 6
[ (gogoproto.nullable) = false ];
repeated PromoterByAddress promoter_by_address_list = 7
[ (gogoproto.nullable) = false ];
}
51 changes: 51 additions & 0 deletions proto/sge/reward/promoter.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
syntax = "proto3";
package sgenetwork.sge.reward;

import "gogoproto/gogo.proto";

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.
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 ];
}

// 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 ];
}

// CategoryCap is type to define category and its maximum cap.
message CategoryCap {
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;
}
40 changes: 38 additions & 2 deletions proto/sge/reward/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "cosmos/base/query/v1beta1/pagination.proto";
import "sge/reward/params.proto";
import "sge/reward/campaign.proto";
import "sge/reward/reward.proto";
import "sge/reward/promoter.proto";

option go_package = "github.com/sge-network/sge/x/reward/types";

Expand All @@ -19,6 +20,16 @@ service Query {
option (google.api.http).get = "/sge-network/sge/reward/params";
}

// PromoterByAddress queries a certain promoter.
rpc PromoterByAddress(QueryPromoterByAddressRequest) returns (QueryPromoterByAddressResponse) {
option (google.api.http).get = "/sge-network/sge/reward/promoter-by-address/{addr}";
}

// Queries list of all Promoter items.
rpc Promoters(QueryPromotersRequest) returns (QueryPromotersResponse) {
option (google.api.http).get = "/sge-network/sge/reward/promoters";
}

// Queries a specific Campaign item.
rpc Campaign(QueryCampaignRequest) returns (QueryCampaignResponse) {
option (google.api.http).get = "/sge-network/sge/reward/campaign/{uid}";
Expand All @@ -42,15 +53,15 @@ 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/{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
// endpoint.
rpc RewardsByAddressAndCategory(QueryRewardsByAddressAndCategoryRequest)
returns (QueryRewardsByAddressAndCategoryResponse) {
option (google.api.http).get =
"/sge-network/sge/reward/rewards/{address}/{category}";
"/sge-network/sge/reward/rewards/{promoter_uid}/{address}/{category}";
}

// Queries list of all Reward items by campaign endpoint.
Expand All @@ -70,6 +81,29 @@ message QueryParamsResponse {
Params params = 1 [ (gogoproto.nullable) = false ];
}

// 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.
message QueryPromoterByAddressResponse {
// promoter holds the queries promoter.
Promoter promoter = 1 [ (gogoproto.nullable) = false ];
}

// QueryPromotersRequest is request body for the query all promoters endpoint.
message QueryPromotersRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryPromotersResponse is response body of the query all promoters
// endpoint.
message QueryPromotersResponse {
repeated Promoter promoter = 1 [ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryCampaignRequest is request body of the query campaign endpoint.
message QueryCampaignRequest { string uid = 1; }

Expand Down Expand Up @@ -114,6 +148,7 @@ message QueryRewardsResponse {
message QueryRewardsByAddressRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
string address = 2;
string promoter_uid = 3;
}

// QueryRewardsByAddressResponse is response body of the query all rewards by
Expand All @@ -129,6 +164,7 @@ message QueryRewardsByAddressAndCategoryRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
string address = 2;
RewardCategory category = 3;
string promoter_uid = 4;
}

// QueryRewardsByAddressAndCategoryResponse is response body of the query all
Expand Down
42 changes: 38 additions & 4 deletions proto/sge/reward/ticket.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package sgenetwork.sge.reward;

import "gogoproto/gogo.proto";
import "sge/type/kyc.proto";
import "sge/reward/campaign.proto";
import "sge/reward/reward.proto";
import "sge/reward/promoter.proto";

option go_package = "github.com/sge-network/sge/x/reward/types";

Expand Down Expand Up @@ -34,13 +36,15 @@ message CreateCampaignPayload {
// is_active is the flag to check if the campaign is active or not.
bool is_active = 8;

// claims_per_category is the number of times a user can claim a reward for
// category of this campaign.
uint64 claims_per_category = 9;

// meta is the metadata of the campaign.
// It is a stringified base64 encoded json.
string meta = 10;

// cap_count is the maximum allowed grant for a certain account.
uint64 cap_count = 11;

// constraints is the constrains of a campaign.
CampaignConstraints constraints = 12;
}

// UpdateCampaignPayload is the type for campaign update payload.
Expand Down Expand Up @@ -109,4 +113,34 @@ message GrantSignupAffiliatorRewardPayload {
// affiliatee is the address of the account that used this affiliator's
// address as source_uid
string affiliatee = 2;
}

// GrantBetBonusRewardPayload is the type for bet bonus reward
// grant payload.
message GrantBetBonusRewardPayload {
// common is the common properties of a reward
RewardPayloadCommon common = 1 [ (gogoproto.nullable) = false ];

// bet_uid is the list of uids
string bet_uid = 2 [
(gogoproto.customname) = "BetUID",
(gogoproto.jsontag) = "bet_uid",
json_name = "bet_uid"
];
}

// CreatePromoterPayload is the payload for the promoter create.
message CreatePromoterPayload {
// uid is the uid of the promoter to be created
string uid = 1 [
(gogoproto.customname) = "UID",
(gogoproto.jsontag) = "uid",
json_name = "uid"
];
PromoterConf conf = 2 [ (gogoproto.nullable) = false ];
}

// SetPromoterConfPayload is the payload for the promoter configuration change.
message SetPromoterConfPayload {
PromoterConf conf = 1 [ (gogoproto.nullable) = false ];
}
Loading

0 comments on commit 3ee84c9

Please sign in to comment.