Skip to content

Commit

Permalink
Merge pull request #373 from scorpioborn/feature/bet-bonus-upgrade-ha…
Browse files Browse the repository at this point in the history
…ndler

Feature/bet bonus upgrade handler
  • Loading branch information
3eyedraga authored Mar 28, 2024
2 parents 55aeec5 + 7a315c3 commit 657f479
Show file tree
Hide file tree
Showing 68 changed files with 2,954 additions and 605 deletions.
4 changes: 4 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import (
v4 "github.com/sge-network/sge/app/upgrades/v4"
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 @@ -80,6 +82,8 @@ var (
v4.Upgrade,
v5.Upgrade,
v6.Upgrade,
v7.Upgrade,
v8.Upgrade,
}
)

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

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.5.3 upgrade.
const UpgradeName = "v1.5.3"

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

import (
"fmt"

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/sge-network/sge/app/keepers"
subaccounttypes "github.com/sge-network/sge/x/subaccount/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) {
allSubaccounts := k.SubaccountKeeper.GetAllSubaccounts(ctx)

for _, sa := range allSubaccounts {
subAccAddr := sdk.MustAccAddressFromBech32(sa.Address)
accSummary, found := k.SubaccountKeeper.GetAccountSummary(ctx, subAccAddr)
if !found {
panic(fmt.Errorf("account summary for the subaccount not found %s", subAccAddr))
}

_, totalBalances := k.SubaccountKeeper.GetBalances(ctx, subAccAddr, subaccounttypes.LockedBalanceStatus_LOCKED_BALANCE_STATUS_UNSPECIFIED)

missingBalance := accSummary.DepositedAmount.Sub(totalBalances)
if missingBalance.GT(sdkmath.ZeroInt()) {
k.SubaccountKeeper.SetLockedBalances(ctx, subAccAddr, []subaccounttypes.LockedBalance{
{
Amount: missingBalance,
UnlockTS: 1710830000,
},
})
}
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}
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{},
},
}
52 changes: 52 additions & 0 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package v8

import (
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
k.RewardKeeper.SetCampaign(ctx, c)
promoters[c.Promoter] = struct{}{}
}

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

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)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/tendermint/tendermint v0.34.29
github.com/tendermint/tm-db v0.6.7
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e
Expand Down Expand Up @@ -261,7 +261,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1379,8 +1379,9 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand All @@ -1391,8 +1392,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
Expand Down
8 changes: 4 additions & 4 deletions proto/sge/orderbook/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ service Query {
}

// Queries list of settled Orderbook Participation items of a certain height.
rpc SettledOrderbookParticipationsOfHeight(
rpc SettledOrderBookParticipationsOfHeight(
QuerySettledOrderBookParticipationsOfHeightRequest)
returns (QuerySettledOrderbookParticipationsOfHeightResponse) {
returns (QuerySettledOrderBookParticipationsOfHeightResponse) {
option (google.api.http).get =
"/sge/orderbook/participations/settled/{block_height}";
}
Expand Down Expand Up @@ -320,9 +320,9 @@ message QuerySettledOrderBookParticipationsOfHeightRequest {
int64 block_height = 2;
}

// QuerySettledOrderbookParticipationsOfHeightResponse is the response type for
// QuerySettledOrderBookParticipationsOfHeightResponse is the response type for
// the settled orderbook participations of a certain height list query.
message QuerySettledOrderbookParticipationsOfHeightResponse {
message QuerySettledOrderBookParticipationsOfHeightResponse {
repeated OrderBookParticipation participations = 1
[ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand Down
34 changes: 34 additions & 0 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 Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions proto/sge/reward/ticket.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ message GrantBetBonusRewardPayload {
];
}

// 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 ];
Expand Down
13 changes: 13 additions & 0 deletions proto/sge/reward/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ option go_package = "github.com/sge-network/sge/x/reward/types";
service Msg {
// SetPromoterConf is a method to set the configurations of a promoter.
rpc SetPromoterConf(MsgSetPromoterConf) returns (MsgSetPromoterConfResponse);
// CreatePromoter is a method to create a promoter
rpc CreatePromoter(MsgCreatePromoter) returns (MsgCreatePromoterResponse);
// CreateCampaign is a method to create a campaign
rpc CreateCampaign(MsgCreateCampaign) returns (MsgCreateCampaignResponse);
// UpdateCampaign is a method to update campaign
Expand All @@ -20,6 +22,17 @@ service Msg {
rpc GrantReward(MsgGrantReward) returns (MsgGrantRewardResponse);
}

// MsgCreatePromoter is msg to create a promoter.
message MsgCreatePromoter {
// creator is the address of message signer account.
string creator = 1;
// ticket is the payload data.
string ticket = 2;
}

// MsgCreatePromoterResponse promoter create message response type.
message MsgCreatePromoterResponse {}

// MsgSetPromoterConf is msg to set promoter configuration.
message MsgSetPromoterConf {
// creator is the address of message signer account.
Expand Down
10 changes: 10 additions & 0 deletions proto/sge/subaccount/balance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ message LockedBalance {
(gogoproto.nullable) = false
];
}

// LockedBalanceStatus type.
enum LockedBalanceStatus {
// the invalid or unknown
LOCKED_BALANCE_STATUS_UNSPECIFIED = 0;
// locked
LOCKED_BALANCE_STATUS_LOCKED = 1;
// unlocked
LOCKED_BALANCE_STATUS_UNLOCKED = 2;
}
6 changes: 6 additions & 0 deletions proto/sge/subaccount/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ message QuerySubaccountResponse {
sge.subaccount.AccountSummary balance = 2 [ (gogoproto.nullable) = false ];
repeated sge.subaccount.LockedBalance locked_balance = 3
[ (gogoproto.nullable) = false ];
repeated sge.subaccount.LockedBalance unlocked_balance = 4
[ (gogoproto.nullable) = false ];
string withdrawable_unlocked_balance = 5 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}
4 changes: 2 additions & 2 deletions x/orderbook/keeper/grpc_query_participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (k Keeper) OrderBookParticipations(
}, nil
}

// SettledOrderbookParticipationsOfHeight returns settled orderbook participations of a certain height
func (k Keeper) SettledOrderbookParticipationsOfHeight(
// SettledOrderBookParticipationsOfHeight returns settled orderbook participations of a certain height
func (k Keeper) SettledOrderBookParticipationsOfHeight(
c context.Context,
req *types.QuerySettledOrderBookParticipationsOfHeightRequest,
) (*types.QuerySettledOrderBookParticipationsOfHeightResponse, error) {
Expand Down
Loading

0 comments on commit 657f479

Please sign in to comment.