Skip to content

Commit

Permalink
Merge branch 'main' into adam/special3
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki committed Aug 2, 2023
2 parents 93a0ed5 + 1db033a commit 48b5d88
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 145 deletions.
54 changes: 27 additions & 27 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ func New(

app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper)

app.UGovKeeperB = ugovkeeper.NewKeeperBuilder(appCodec, keys[ugov.ModuleName])

app.OracleKeeper = oraclekeeper.NewKeeper(
appCodec,
keys[oracletypes.ModuleName],
Expand Down Expand Up @@ -487,7 +489,13 @@ func New(
)
app.LeverageKeeper.SetBondHooks(app.IncentiveKeeper.BondHooks())

app.UGovKeeperB = ugovkeeper.NewKeeperBuilder(appCodec, keys[ugov.ModuleName])
app.MetokenKeeperB = metokenkeeper.NewKeeperBuilder(
appCodec,
keys[metoken.StoreKey],
app.BankKeeper,
app.LeverageKeeper,
app.OracleKeeper,
)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down Expand Up @@ -526,48 +534,40 @@ func New(

// UIbcQuotaKeeper implements ibcporttypes.ICS4Wrapper
app.UIbcQuotaKeeperB = uibcquotakeeper.NewKeeperBuilder(
appCodec,
keys[uibc.StoreKey],
app.IBCKeeper.ChannelKeeper, app.LeverageKeeper, uibcoracle.FromUmeeAvgPriceOracle(app.OracleKeeper),
appCodec, keys[uibc.StoreKey],
app.LeverageKeeper, uibcoracle.FromUmeeAvgPriceOracle(app.OracleKeeper),
)

// Middleware Stacks
/**********
* ICS20 (Transfer) Middleware Stacks
* SendPacket, originates from the application to an IBC channel:
transferKeeper.SendPacket -> uibcquota.SendPacket -> channel.SendPacket
* RecvPacket, message that originates from an IBC channel and goes down to app, the flow is the other way
channel.RecvPacket -> uibcquota.OnRecvPacket -> transfer.OnRecvPacket
* transfer stack contains (from top to bottom):
- Umee IBC Transfer
- IBC Rate Limit Middleware
**********/

quotaICS4 := uibcquota.NewICS4(app.IBCKeeper.ChannelKeeper, app.UIbcQuotaKeeperB)

// Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper
// since fee middleware will wrap the IBCKeeper for underlying application.
app.IBCTransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.UIbcQuotaKeeperB, // ISC4 Wrapper: fee IBC middleware
quotaICS4, // ISC4 Wrapper: fee IBC middleware
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, app.ScopedTransferKeeper,
)

app.MetokenKeeperB = metokenkeeper.NewKeeperBuilder(
appCodec,
keys[metoken.StoreKey],
app.BankKeeper,
app.LeverageKeeper,
app.OracleKeeper,
)

// Create Transfer Stack
// SendPacket, originates from the application to an IBC channel:
// transferKeeper.SendPacket -> uibcquota.SendPacket -> channel.SendPacket

// RecvPacket, message that originates from an IBC channel and goes down to app, the flow is the other way
// channel.RecvPacket -> uibcquota.OnRecvPacket -> transfer.OnRecvPacket

// transfer stack contains (from top to bottom):
// - Umee IBC Transfer
// - IBC Rate Limit Middleware

// create IBC module from bottom to top of stack
var transferStack ibcporttypes.IBCModule
transferStack = ibctransfer.NewIBCModule(app.IBCTransferKeeper)
// transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
transferStack = uibcquota.NewICS20Middleware(transferStack, app.UIbcQuotaKeeperB, appCodec)
transferStack = uibcquota.NewICS20Module(transferStack, app.UIbcQuotaKeeperB, appCodec)

// Create Interchain Accounts Stack
// Create Interchain Accounts Controller Stack
// SendPacket, since it is originating from the application to core IBC:
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket

Expand Down
19 changes: 19 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/umee-network/umee/v5/x/incentive"
leveragekeeper "github.com/umee-network/umee/v5/x/leverage/keeper"
leveragetypes "github.com/umee-network/umee/v5/x/leverage/types"

oraclekeeper "github.com/umee-network/umee/v5/x/oracle/keeper"
oracletypes "github.com/umee-network/umee/v5/x/oracle/types"
"github.com/umee-network/umee/v5/x/ugov"
Expand Down Expand Up @@ -55,8 +56,26 @@ func (app UmeeApp) RegisterUpgradeHandlers(bool) {
app.registerUpgrade("v5.0", upgradeInfo, ugov.ModuleName, wasm.ModuleName)
app.registerUpgrade5_1(upgradeInfo)
app.registerUpgrade6(upgradeInfo)
// app.registerNewTokenEmissionUpgrade(upgradeInfo)
}

// TODO: this upgrade registration is just for testing purpose, once we finalize the release for new token emission
// then we need to change planName and storeUpgrades
// func (app *UmeeApp) registerNewTokenEmissionUpgrade(upgradeInfo upgradetypes.Plan) {
// // TODO:finalize the name
// planName := "token_emission"
// app.UpgradeKeeper.SetUpgradeHandler(planName,
// func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// return app.mm.RunMigrations(ctx, app.configurator, fromVM)
// },
// )

// app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{
// Added: []string{metoken.ModuleName},
// Deleted: []string{"gravity"},
// })
// }

func (app *UmeeApp) registerUpgrade6(upgradeInfo upgradetypes.Plan) {
planName := "v6.0"
gravityModuleName := "gravity" // hardcoded to avoid dependency on GB module
Expand Down
2 changes: 1 addition & 1 deletion x/ugov/inflation_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func DefaultInflationParams() InflationParams {
return InflationParams{
MaxSupply: coin.New(appparams.BondDenom, 21_000000000_000000), // 21 Billion Maximum
InflationCycle: time.Hour * 24 * 365, // 2 years for default inflation cycle
InflationCycle: time.Hour * 24 * 365 * 2, // 2 years for default inflation cycle
InflationReductionRate: bpmath.FixedBP(2500), // 25% reduction rate for inflation cyle
}
}
Expand Down
9 changes: 0 additions & 9 deletions x/ugov/keeper/keys.go

This file was deleted.

24 changes: 24 additions & 0 deletions x/ugov/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

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

v2 "github.com/umee-network/umee/v5/x/ugov/migrations/v2"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
kb Builder
}

// NewMigrator returns a new Migrator instance.
func NewMigrator(kb Builder) Migrator {
return Migrator{
kb: kb,
}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.kb.storeKey)
}
18 changes: 9 additions & 9 deletions x/ugov/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,44 @@ import (
)

func (k Keeper) SetMinGasPrice(p sdk.DecCoin) error {
return store.SetValue(k.store, keyMinGasPrice, &p, "gas_price")
return store.SetValue(k.store, ugov.KeyMinGasPrice, &p, "gas_price")
}

func (k Keeper) MinGasPrice() sdk.DecCoin {
gp := store.GetValue[*sdk.DecCoin](k.store, keyMinGasPrice, "gas_price")
gp := store.GetValue[*sdk.DecCoin](k.store, ugov.KeyMinGasPrice, "gas_price")
if gp == nil {
return coin.Umee0dec
}
return *gp
}

func (k Keeper) SetEmergencyGroup(p sdk.AccAddress) {
store.SetAddress(k.store, keyEmergencyGroup, p)
store.SetAddress(k.store, ugov.KeyEmergencyGroup, p)
}

func (k Keeper) EmergencyGroup() sdk.AccAddress {
return store.GetAddress(k.store, keyEmergencyGroup)
return store.GetAddress(k.store, ugov.KeyEmergencyGroup)
}

func (k Keeper) SetInflationParams(ip ugov.InflationParams) error {
return store.SetValue(k.store, keyInflationParams, &ip, "inflation_params")
return store.SetValue(k.store, ugov.KeyInflationParams, &ip, "inflation_params")
}

func (k Keeper) InflationParams() ugov.InflationParams {
ip := store.GetValue[*ugov.InflationParams](k.store, keyInflationParams, "inflation_params")
ip := store.GetValue[*ugov.InflationParams](k.store, ugov.KeyInflationParams, "inflation_params")
if ip == nil {
return ugov.InflationParams{}
}
return *ip
}

func (k Keeper) SetInflationCycleEnd(startTime time.Time) error {
store.SetTimeMs(k.store, keyInflationCycleEnd, startTime)
func (k Keeper) SetInflationCycleEnd(cycleEnd time.Time) error {
store.SetTimeMs(k.store, ugov.KeyInflationCycleEnd, cycleEnd)
return nil
}

// Returns zero unix time if the inflation cycle was not set.
func (k Keeper) GetInflationCycleEnd() time.Time {
t, _ := store.GetTimeMs(k.store, keyInflationCycleEnd)
t, _ := store.GetTimeMs(k.store, ugov.KeyInflationCycleEnd)
return t
}
8 changes: 8 additions & 0 deletions x/ugov/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ const (
// StoreKey defines the primary module store key
StoreKey = ModuleName
)

// store key prefixes
var (
KeyMinGasPrice = []byte{0x01}
KeyEmergencyGroup = []byte{0x02}
KeyInflationParams = []byte{0x03}
KeyInflationCycleEnd = []byte{0x04}
)
23 changes: 23 additions & 0 deletions x/ugov/migrations/v2/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v2

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/umee-network/umee/v5/util/store"
"github.com/umee-network/umee/v5/x/ugov"
)

// MigrateStore performs in-place store migrations from 1 to 2
func MigrateStore(ctx sdk.Context, key storetypes.StoreKey) error {
kvStore := ctx.KVStore(key)

ip := ugov.DefaultInflationParams()
if err := store.SetValue(kvStore, ugov.KeyInflationParams, &ip, "inflation_params"); err != nil {
return err
}

cycleEnd := ctx.BlockTime().Add(ip.InflationCycle)
store.SetTimeMs(kvStore, ugov.KeyInflationCycleEnd, cycleEnd)

return nil
}
44 changes: 44 additions & 0 deletions x/ugov/migrations/v2/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package v2_test

import (
"testing"
"time"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
"gotest.tools/v3/assert"

"github.com/umee-network/umee/v5/tests/tsdk"
"github.com/umee-network/umee/v5/util/store"
"github.com/umee-network/umee/v5/x/ugov"
v2 "github.com/umee-network/umee/v5/x/ugov/migrations/v2"
)

func TestMigrateStore(t *testing.T) {
storeKey := storetypes.NewKVStoreKey(ugov.ModuleName)
sdkContext, _ := tsdk.NewCtx(t, []storetypes.StoreKey{storeKey}, []storetypes.StoreKey{})
kvStore := sdkContext.KVStore(storeKey)

getInflationParams := func() *ugov.InflationParams {
return store.GetValue[*ugov.InflationParams](kvStore, ugov.KeyInflationParams, "ip")
}

getInflationCycleEnd := func() (time.Time, bool) {
return store.GetTimeMs(kvStore, ugov.KeyInflationCycleEnd)
}

// before migration
_, ok := getInflationCycleEnd()
assert.Equal(t, ok, false)
ip := getInflationParams()
assert.DeepEqual(t, 0, ip.Size())

// after migration
err := v2.MigrateStore(sdkContext, storeKey)
assert.NilError(t, err)
ip = getInflationParams()
assert.DeepEqual(t, ugov.DefaultInflationParams(), *ip)

cycleEnd, ok := getInflationCycleEnd()
assert.Equal(t, ok, true)
assert.DeepEqual(t, sdkContext.BlockTime().Add(ip.InflationCycle), cycleEnd)
}
11 changes: 10 additions & 1 deletion x/ugov/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"github.com/umee-network/umee/v5/x/ugov/keeper"
)

const (
consensusVersion uint64 = 2
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
Expand Down Expand Up @@ -111,7 +115,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.

// ConsensusVersion implements module.AppModule
func (AppModule) ConsensusVersion() uint64 {
return 1
return consensusVersion
}

// RegisterInvariants implements module.AppModule
Expand All @@ -121,6 +125,11 @@ func (AppModule) RegisterInvariants(sdk.InvariantRegistry) {}
func (am AppModule) RegisterServices(cfg module.Configurator) {
ugov.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(am.kb))
ugov.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.kb))

m := keeper.NewMigrator(am.kb)
if err := cfg.RegisterMigration(ugov.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", ugov.ModuleName, err))
}
}

// BeginBlock executes all ABCI BeginBlock logic respective to the x/uibc module.
Expand Down
Loading

0 comments on commit 48b5d88

Please sign in to comment.