-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from scorpioborn/feature/bet-bonus-upgrade-ha…
…ndler Feature/bet bonus upgrade handler
- Loading branch information
Showing
68 changed files
with
2,954 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.