Skip to content

Commit

Permalink
Merge pull request #391 from sge-network/upgrade/promoter-category
Browse files Browse the repository at this point in the history
Upgrade / v1.6.2
  • Loading branch information
3eyedraga authored May 6, 2024
2 parents 18d9aa6 + fd1ab06 commit b7c0eab
Show file tree
Hide file tree
Showing 34 changed files with 159 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@

# ignore visual studio code dev container config
.devcontainer

# ignore build dir
build
4 changes: 3 additions & 1 deletion app/upgrades/v3/consts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package v3

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

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

Expand All @@ -11,7 +13,7 @@ const UpgradeName = "v1.2.0"
// Expedite governance params
var (
// DefaultMinExpeditedDepositTokens is the default minimum deposit required for expedited proposals.
DefaultMinExpeditedDepositTokens = sdk.NewInt(50000000000)
DefaultMinExpeditedDepositTokens = sdkmath.NewInt(50000000000)
// DefaultExpeditedQuorum is the default quorum percentage required for expedited proposals.
DefaultExpeditedQuorum = sdk.NewDecWithPrec(750, 3)
// DefaultExpeditedThreshold is the default voting threshold percentage required for expedited proposals.
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v8/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/sge-network/sge/app/upgrades"
)

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

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
Expand Down
71 changes: 41 additions & 30 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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/sge-network/sge/app/keepers"
"github.com/sge-network/sge/x/reward/types"
)
Expand All @@ -17,42 +18,52 @@ func CreateUpgradeHandler(
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{}{}
}
allPromoters := k.RewardKeeper.GetAllPromoter(ctx)
promoterUID := "f0630627-9e4e-48f3-8cd5-1422b46d2175"
if len(allPromoters) == 0 {
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)
}
sort.Strings(promoterAddresses)

if len(promoterAddresses) > 0 {
promoterUID := "f0630627-9e4e-48f3-8cd5-1422b46d2175"
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},
},
},
})
promoterAddresses := []string{}
for addr := range promoters {
promoterAddresses = append(promoterAddresses, addr)
}
sort.Strings(promoterAddresses)

for _, addr := range promoterAddresses {
k.RewardKeeper.SetPromoterByAddress(ctx, types.PromoterByAddress{
PromoterUID: promoterUID,
Address: addr,
if len(promoterAddresses) > 0 {
promoterUID := promoterUID
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,
})
}
}
}

allByCat := k.RewardKeeper.GetAllRewardsOfReceiverByPromoterAndCategory(ctx)
for _, rc := range allByCat {
k.RewardKeeper.RemoveRewardOfReceiverByPromoterAndCategory(ctx, "", rc)
k.RewardKeeper.SetRewardOfReceiverByPromoterAndCategory(ctx, promoterUID, rc)
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0

github.com/cosmos/cosmos-sdk => github.com/sge-network/cosmos-sdk v0.46.17-0.20240223100624-2a2661276cb4
github.com/cosmos/cosmos-sdk => github.com/sge-network/cosmos-sdk v0.46.17-0.20240430064306-1b044d03d56c
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
// use cosmos-compatible protobufs
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,8 @@ github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KR
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240223100624-2a2661276cb4 h1:HaHBgOxHd0mvl9Y07qujdnwtjcRweJsktbNPPy6LlwQ=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240223100624-2a2661276cb4/go.mod h1:05U50tAsOzQ8JOAePshJCbJQw5ib1YJR6IXcqyVI1Xg=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240430064306-1b044d03d56c h1:cnMnb+CR81vB2ula0qQqMIkfYREVUpUTpqHtu34zLGQ=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240430064306-1b044d03d56c/go.mod h1:05U50tAsOzQ8JOAePshJCbJQw5ib1YJR6IXcqyVI1Xg=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
Expand Down
10 changes: 5 additions & 5 deletions x/bet/keeper/settle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
Status: types.Bet_STATUS_SETTLED,
Expand All @@ -73,7 +73,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
},
Expand All @@ -92,7 +92,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
},
Expand All @@ -111,7 +111,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,
},
Expand All @@ -131,7 +131,7 @@ func TestSettleBet(t *testing.T) {
bet: &types.Bet{
MarketUID: testMarketUID,
OddsValue: "10",
Amount: sdk.NewInt(1000000),
Amount: sdkmath.NewInt(1000000),
Creator: testCreator,
OddsUID: testOddsUID1,

Expand Down
5 changes: 2 additions & 3 deletions x/bet/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"gopkg.in/yaml.v2"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

Expand Down Expand Up @@ -134,11 +133,11 @@ func validateConstraints(i interface{}) error {
return fmt.Errorf("%s: %T", ErrTextInvalidParamType, i)
}

if v.MinAmount.LTE(sdk.OneInt()) {
if v.MinAmount.LTE(sdkmath.OneInt()) {
return fmt.Errorf("minimum bet amount must be more than one: %d", v.MinAmount.Int64())
}

if v.Fee.LT(sdk.ZeroInt()) {
if v.Fee.LT(sdkmath.ZeroInt()) {
return fmt.Errorf("minimum bet fee must be positive: %d", v.Fee.Int64())
}

Expand Down
2 changes: 1 addition & 1 deletion x/house/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (k Keeper) Deposit(ctx sdk.Context, creator, depositor string,
marketUID string, amount sdkmath.Int,
) (participationIndex uint64, feeAmount sdkmath.Int, err error) {
// Create the deposit object
deposit := types.NewDeposit(creator, depositor, marketUID, amount, sdk.ZeroInt(), 0)
deposit := types.NewDeposit(creator, depositor, marketUID, amount, sdkmath.ZeroInt(), 0)

feeAmount = deposit.CalcHouseParticipationFeeAmount(k.GetHouseParticipationFee(ctx))

Expand Down
2 changes: 1 addition & 1 deletion x/house/types/deposit_authorizaton.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a DepositAuthorization) ValidateBasic() error {
if a.SpendLimit.IsNil() {
return sdkerrtypes.ErrInvalidCoins.Wrap("spend limit cannot be nil")
}
if a.SpendLimit.LTE(sdk.ZeroInt()) {
if a.SpendLimit.LTE(sdkmath.ZeroInt()) {
return sdkerrtypes.ErrInvalidCoins.Wrap("spend limit cannot be less than or equal to zero")
}
if a.SpendLimit.LT(minDepositGrant) {
Expand Down
5 changes: 2 additions & 3 deletions x/house/types/message_deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/require"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/sge-network/sge/testutil/sample"
Expand Down Expand Up @@ -49,7 +48,7 @@ func TestMsgDepositValidateBasic(t *testing.T) {
msg: types.MsgDeposit{
Creator: sample.AccAddress(),
MarketUID: uuid.NewString(),
Amount: sdk.ZeroInt(),
Amount: sdkmath.ZeroInt(),
Ticket: "Ticket",
},
err: sdkerrtypes.ErrInvalidRequest,
Expand All @@ -76,7 +75,7 @@ func TestNewDeposit(t *testing.T) {
Amount: sdkmath.NewInt(100),
ParticipationIndex: 0,
WithdrawalCount: 0,
TotalWithdrawalAmount: sdk.ZeroInt(),
TotalWithdrawalAmount: sdkmath.ZeroInt(),
}
res := types.NewDeposit(
expected.Creator,
Expand Down
2 changes: 1 addition & 1 deletion x/house/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func validateMinimumDeposit(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.LTE(sdk.OneInt()) {
if v.LTE(sdkmath.OneInt()) {
return fmt.Errorf("minimum deposit must be positive and more than one: %d", v)
}

Expand Down
2 changes: 1 addition & 1 deletion x/house/types/withdraw_authorizaton.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a WithdrawAuthorization) ValidateBasic() error {
if a.WithdrawLimit.IsNil() {
return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be nil")
}
if a.WithdrawLimit.LTE(sdk.ZeroInt()) {
if a.WithdrawLimit.LTE(sdkmath.ZeroInt()) {
return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be less than or equal to zero")
}
if a.WithdrawLimit.GT(maxWithdrawGrant) {
Expand Down
3 changes: 1 addition & 2 deletions x/mint/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

Expand Down Expand Up @@ -57,7 +56,7 @@ func TestRandomizedGenState(t *testing.T) {
require.Equal(
t,
"0.000000000000000000",
mintGenesis.Minter.NextPhaseProvisions(sdk.OneInt(), types.DefaultExcludeAmount, types.NonePhase()).
mintGenesis.Minter.NextPhaseProvisions(sdkmath.OneInt(), types.DefaultExcludeAmount, types.NonePhase()).
String(),
)
require.Equal(t, "0.229787234042553191", params.GetPhaseAtStep(1).Inflation.String())
Expand Down
2 changes: 1 addition & 1 deletion x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func validateExcludeAmount(i interface{}) error {
return fmt.Errorf(ErrTextInvalidParamType, i)
}

if v.LT(sdk.ZeroInt()) {
if v.LT(sdkmath.ZeroInt()) {
return fmt.Errorf(ErrTextExcludeAmountMustBePositive, v)
}

Expand Down
6 changes: 3 additions & 3 deletions x/orderbook/keeper/bet_wager.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (k Keeper) fulfillBetByParticipationQueue(

// the decimal amount that is being lost in the bet amount calculation from payout profit
truncatedBetAmount := sdk.NewDec(0)
requeThreshold := sdk.NewIntFromUint64(k.GetRequeueThreshold(ctx))
requeThreshold := sdkmath.NewIntFromUint64(k.GetRequeueThreshold(ctx))
// continue until updatedFulfillmentQueue gets empty
for fInfo.hasUnfulfilledQueueItem() {
var err error
Expand Down Expand Up @@ -464,7 +464,7 @@ func (fInfo *fulfillmentInfo) checkFullfillmentForOtherOdds(requeThreshold sdkma

// availableLiquidity is the available amount of tokens to be used from the participation exposure
fInfo.secondaryProcessItem.setAvailableLiquidity(betOdd.MaxLossMultiplier)
if fInfo.secondaryProcessItem.isLiquidityLessThanThreshold(requeThreshold, sdk.ZeroInt()) {
if fInfo.secondaryProcessItem.isLiquidityLessThanThreshold(requeThreshold, sdkmath.ZeroInt()) {
fInfo.inProcessItem.setFulfilledSecondary(&fInfo.secondaryProcessItem)
eUpdate = append(eUpdate, fInfo.secondaryProcessItem.participationExposure)
}
Expand Down Expand Up @@ -513,7 +513,7 @@ func (fItem *fulfillmentItem) isLiquidityLessThanThreshold(threshold, adjAmount
}

func (fItem *fulfillmentItem) noLiquidityAvailable() bool {
return fItem.availableLiquidity.LTE(sdk.ZeroInt())
return fItem.availableLiquidity.LTE(sdkmath.ZeroInt())
}

func (fItem *fulfillmentItem) setFulfilled() {
Expand Down
2 changes: 1 addition & 1 deletion x/orderbook/keeper/bet_wager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (ts *testBetSuite) bulkDepositPlaceBetsAndTest() {
OddsUID: ts.market.Odds[1].UID,
OddsValue: "4.415",
Amount: betAmount,
Fee: sdk.ZeroInt(),
Fee: sdkmath.ZeroInt(),
Status: bettypes.Bet_STATUS_PENDING,
Creator: bettorAddr.String(),
CreatedAt: cast.ToInt64(ts.ctx.BlockTime().Unix()),
Expand Down
5 changes: 3 additions & 2 deletions x/orderbook/keeper/exposure_odds.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sge-network/sge/x/orderbook/types"
Expand Down Expand Up @@ -92,8 +93,8 @@ func (k Keeper) initParticipationExposures(
pe := types.NewParticipationExposure(
orderBookUID,
boe.OddsUID,
sdk.ZeroInt(),
sdk.ZeroInt(),
sdkmath.ZeroInt(),
sdkmath.ZeroInt(),
participationIndex,
1,
false,
Expand Down
2 changes: 1 addition & 1 deletion x/orderbook/keeper/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (k Keeper) InitiateOrderBookParticipation(
index, book.UID, addr.String(),
book.OddsCount, // all odds need to be filled in the next steps
liquidity, feeAmount, liquidity, // int the start, liquidity and current round liquidity are the same
sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdkmath.Int{}, "", sdk.ZeroInt(),
sdkmath.ZeroInt(), sdkmath.ZeroInt(), sdkmath.ZeroInt(), sdkmath.Int{}, "", sdkmath.ZeroInt(),
)

// fund order book liquidity pool from participant's account.
Expand Down
4 changes: 2 additions & 2 deletions x/orderbook/keeper/participation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestWithdrawOrderBookParticipation(t *testing.T) {
{
desc: "no participation",
depositorAddr: simapp.TestParamUsers["user1"].Address,
depositAmount: sdk.ZeroInt(),
depositAmount: sdkmath.ZeroInt(),
withdrawMode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL,
err: types.ErrOrderBookParticipationNotFound,
},
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestWithdrawOrderBookParticipation(t *testing.T) {
marketUID,
participationIndex,
tc.withdrawMode,
sdk.ZeroInt(),
sdkmath.ZeroInt(),
tc.depositAmount,
)

Expand Down
Loading

0 comments on commit b7c0eab

Please sign in to comment.