diff --git a/CHANGELOG.md b/CHANGELOG.md index 89b3e0ed7eb..7bed8dce1df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### golang API breaks -* [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface +* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Remove methods that constitute AppModuleSimulation APIs for several modules' AppModules, which implemented no-ops +* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Add hourly epochs to `x/epochs` DefaultGenesis. +* [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface, instead use simapp.App * [#1630](https://github.com/osmosis-labs/osmosis/pull/1630) Delete the v043_temp module, now that we're on an updated SDK version. @@ -56,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1230] Stableswap CFMM equations * [#1429] solver for multi-asset CFMM + ## [v9.0.0 - Nitrogen](https://github.com/osmosis-labs/osmosis/releases/tag/v9.0.0) The Nitrogen release brings with it a number of features enabling further cosmwasm development work in Osmosis. diff --git a/app/modules.go b/app/modules.go index ff1775f2927..bc225ce0793 100644 --- a/app/modules.go +++ b/app/modules.go @@ -242,8 +242,6 @@ func simulationModules( bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper), authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - gamm.NewAppModule(appCodec, *app.GAMMKeeper, app.AccountKeeper, app.BankKeeper), - txfees.NewAppModule(appCodec, *app.TxFeesKeeper), gov.NewAppModule(appCodec, *app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper, app.BankKeeper), slashing.NewAppModule(appCodec, *app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), @@ -256,7 +254,6 @@ func simulationModules( incentives.NewAppModule(appCodec, *app.IncentivesKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper), lockup.NewAppModule(appCodec, *app.LockupKeeper, app.AccountKeeper, app.BankKeeper), poolincentives.NewAppModule(appCodec, *app.PoolIncentivesKeeper), - epochs.NewAppModule(appCodec, *app.EpochsKeeper), superfluid.NewAppModule( appCodec, *app.SuperfluidKeeper, @@ -267,7 +264,6 @@ func simulationModules( app.GAMMKeeper, app.EpochsKeeper, ), - tokenfactory.NewAppModule(appCodec, *app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), app.TransferModule, } } diff --git a/x/epochs/keeper/epoch_test.go b/x/epochs/keeper/epoch_test.go index b1f33068aeb..5b20cbf3143 100644 --- a/x/epochs/keeper/epoch_test.go +++ b/x/epochs/keeper/epoch_test.go @@ -9,21 +9,15 @@ import ( func (suite *KeeperTestSuite) TestEpochLifeCycle() { suite.SetupTest() - epochInfo := types.EpochInfo{ - Identifier: "monthly", - StartTime: time.Time{}, - Duration: time.Hour * 24 * 30, - CurrentEpoch: 0, - CurrentEpochStartTime: time.Time{}, - EpochCountingStarted: false, - } + epochInfo := types.NewGenesisEpochInfo("monthly", time.Hour*24*30) suite.App.EpochsKeeper.SetEpochInfo(suite.Ctx, epochInfo) epochInfoSaved := suite.App.EpochsKeeper.GetEpochInfo(suite.Ctx, "monthly") suite.Require().Equal(epochInfo, epochInfoSaved) allEpochs := suite.App.EpochsKeeper.AllEpochInfos(suite.Ctx) - suite.Require().Len(allEpochs, 3) + suite.Require().Len(allEpochs, 4) suite.Require().Equal(allEpochs[0].Identifier, "day") // alphabetical order - suite.Require().Equal(allEpochs[1].Identifier, "monthly") - suite.Require().Equal(allEpochs[2].Identifier, "week") + suite.Require().Equal(allEpochs[1].Identifier, "hour") + suite.Require().Equal(allEpochs[2].Identifier, "monthly") + suite.Require().Equal(allEpochs[3].Identifier, "week") } diff --git a/x/epochs/keeper/genesis_test.go b/x/epochs/keeper/genesis_test.go index 09d5843a205..36390df34c7 100644 --- a/x/epochs/keeper/genesis_test.go +++ b/x/epochs/keeper/genesis_test.go @@ -20,22 +20,14 @@ func TestEpochsExportGenesis(t *testing.T) { chainStartHeight := ctx.BlockHeight() genesis := app.EpochsKeeper.ExportGenesis(ctx) - require.Len(t, genesis.Epochs, 2) + require.Len(t, genesis.Epochs, 3) - require.Equal(t, genesis.Epochs[0].Identifier, "day") - require.Equal(t, genesis.Epochs[0].StartTime, chainStartTime) - require.Equal(t, genesis.Epochs[0].Duration, time.Hour*24) - require.Equal(t, genesis.Epochs[0].CurrentEpoch, int64(0)) - require.Equal(t, genesis.Epochs[0].CurrentEpochStartHeight, chainStartHeight) - require.Equal(t, genesis.Epochs[0].CurrentEpochStartTime, chainStartTime) - require.Equal(t, genesis.Epochs[0].EpochCountingStarted, false) - require.Equal(t, genesis.Epochs[1].Identifier, "week") - require.Equal(t, genesis.Epochs[1].StartTime, chainStartTime) - require.Equal(t, genesis.Epochs[1].Duration, time.Hour*24*7) - require.Equal(t, genesis.Epochs[1].CurrentEpoch, int64(0)) - require.Equal(t, genesis.Epochs[1].CurrentEpochStartHeight, chainStartHeight) - require.Equal(t, genesis.Epochs[1].CurrentEpochStartTime, chainStartTime) - require.Equal(t, genesis.Epochs[1].EpochCountingStarted, false) + expectedEpochs := types.DefaultGenesis().Epochs + for i := 0; i < len(expectedEpochs); i++ { + expectedEpochs[i].CurrentEpochStartHeight = chainStartHeight + expectedEpochs[i].CurrentEpochStartTime = chainStartTime + } + require.Equal(t, expectedEpochs, genesis.Epochs) } func TestEpochsInitGenesis(t *testing.T) { diff --git a/x/epochs/keeper/grpc_query_test.go b/x/epochs/keeper/grpc_query_test.go index 5c30b2d3064..d97b4fc9153 100644 --- a/x/epochs/keeper/grpc_query_test.go +++ b/x/epochs/keeper/grpc_query_test.go @@ -2,7 +2,6 @@ package keeper_test import ( gocontext "context" - "time" "github.com/osmosis-labs/osmosis/v7/x/epochs/types" ) @@ -11,42 +10,10 @@ func (suite *KeeperTestSuite) TestQueryEpochInfos() { suite.SetupTest() queryClient := suite.queryClient - chainStartTime := suite.Ctx.BlockHeader().Time - epochInfo := types.EpochInfo{ - Identifier: "day", - StartTime: chainStartTime, - Duration: time.Hour * 24, - CurrentEpoch: 0, - CurrentEpochStartTime: chainStartTime, - EpochCountingStarted: false, - } - suite.App.EpochsKeeper.SetEpochInfo(suite.Ctx, epochInfo) - epochInfo = types.EpochInfo{ - Identifier: "week", - StartTime: chainStartTime, - Duration: time.Hour * 24 * 7, - CurrentEpoch: 0, - CurrentEpochStartTime: chainStartTime, - EpochCountingStarted: false, - } - suite.App.EpochsKeeper.SetEpochInfo(suite.Ctx, epochInfo) - - // Invalid param + // Check that querying epoch infos on default genesis returns the default genesis epoch infos epochInfosResponse, err := queryClient.EpochInfos(gocontext.Background(), &types.QueryEpochsInfoRequest{}) suite.Require().NoError(err) - suite.Require().Len(epochInfosResponse.Epochs, 2) - - // check if EpochInfos are correct - suite.Require().Equal(epochInfosResponse.Epochs[0].Identifier, "day") - suite.Require().Equal(epochInfosResponse.Epochs[0].StartTime, chainStartTime) - suite.Require().Equal(epochInfosResponse.Epochs[0].Duration, time.Hour*24) - suite.Require().Equal(epochInfosResponse.Epochs[0].CurrentEpoch, int64(0)) - suite.Require().Equal(epochInfosResponse.Epochs[0].CurrentEpochStartTime, chainStartTime) - suite.Require().Equal(epochInfosResponse.Epochs[0].EpochCountingStarted, false) - suite.Require().Equal(epochInfosResponse.Epochs[1].Identifier, "week") - suite.Require().Equal(epochInfosResponse.Epochs[1].StartTime, chainStartTime) - suite.Require().Equal(epochInfosResponse.Epochs[1].Duration, time.Hour*24*7) - suite.Require().Equal(epochInfosResponse.Epochs[1].CurrentEpoch, int64(0)) - suite.Require().Equal(epochInfosResponse.Epochs[1].CurrentEpochStartTime, chainStartTime) - suite.Require().Equal(epochInfosResponse.Epochs[1].EpochCountingStarted, false) + suite.Require().Len(epochInfosResponse.Epochs, 3) + expectedEpochs := types.DefaultGenesis().Epochs + suite.Require().Equal(expectedEpochs, epochInfosResponse.Epochs) } diff --git a/x/epochs/module.go b/x/epochs/module.go index a837bbc6d7d..eb3b3ab1582 100644 --- a/x/epochs/module.go +++ b/x/epochs/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -16,11 +15,9 @@ import ( cdctypes "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" "github.com/osmosis-labs/osmosis/v7/x/epochs/client/cli" "github.com/osmosis-labs/osmosis/v7/x/epochs/keeper" - "github.com/osmosis-labs/osmosis/v7/x/epochs/simulation" "github.com/osmosis-labs/osmosis/v7/x/epochs/types" "github.com/osmosis-labs/osmosis/v7/x/mint/client/rest" ) @@ -163,33 +160,5 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val return []abci.ValidatorUpdate{} } -// ___________________________________________________________________________ - -// AppModuleSimulation functions - -// GenerateGenesisState creates a randomized GenState of the pool-incentives module. -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - simulation.RandomizedGenState(simState) -} - -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil -} - -// RandomizedParams creates randomized pool-incentives param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - -// RegisterStoreDecoder registers a decoder for supply module's types. -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { -} - -// WeightedOperations returns the all the gov module operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - return nil // TODO -} - // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/epochs/simulation/genesis.go b/x/epochs/simulation/genesis.go deleted file mode 100644 index a477cbe0e74..00000000000 --- a/x/epochs/simulation/genesis.go +++ /dev/null @@ -1,56 +0,0 @@ -package simulation - -// DONTCOVER - -import ( - "encoding/json" - "fmt" - "time" - - "github.com/osmosis-labs/osmosis/v7/x/epochs/types" - - "github.com/cosmos/cosmos-sdk/types/module" -) - -// RandomizedGenState generates a random GenesisState for mint. -func RandomizedGenState(simState *module.SimulationState) { - epochs := []types.EpochInfo{ - { - Identifier: "day", - StartTime: time.Time{}, - Duration: time.Hour * 24, - CurrentEpoch: 0, - CurrentEpochStartHeight: 0, - CurrentEpochStartTime: time.Time{}, - EpochCountingStarted: false, - }, - { - Identifier: "hour", - StartTime: time.Time{}, - Duration: time.Hour, - CurrentEpoch: 0, - CurrentEpochStartHeight: 0, - CurrentEpochStartTime: time.Time{}, - EpochCountingStarted: false, - }, - { - Identifier: "second", - StartTime: time.Time{}, - Duration: time.Second, - CurrentEpoch: 0, - CurrentEpochStartHeight: 0, - CurrentEpochStartTime: time.Time{}, - EpochCountingStarted: false, - }, - } - epochGenesis := types.NewGenesisState(epochs) - - bz, err := json.MarshalIndent(&epochGenesis, "", " ") - if err != nil { - panic(err) - } - - // TODO: Do some randomization later - fmt.Printf("Selected deterministically generated epoch parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(epochGenesis) -} diff --git a/x/epochs/types/genesis.go b/x/epochs/types/genesis.go index ccce0d6f85c..19ad167ca27 100644 --- a/x/epochs/types/genesis.go +++ b/x/epochs/types/genesis.go @@ -15,8 +15,9 @@ func NewGenesisState(epochs []EpochInfo) *GenesisState { // DefaultGenesis returns the default Capability genesis state. func DefaultGenesis() *GenesisState { epochs := []EpochInfo{ + NewGenesisEpochInfo("day", time.Hour*24), // alphabetical order + NewGenesisEpochInfo("hour", time.Hour), NewGenesisEpochInfo("week", time.Hour*24*7), - NewGenesisEpochInfo("day", time.Hour*24), } return NewGenesisState(epochs) } diff --git a/x/gamm/module.go b/x/gamm/module.go index 9cce8c527f2..f09fac85d30 100644 --- a/x/gamm/module.go +++ b/x/gamm/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -16,20 +15,17 @@ import ( 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" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/osmosis-labs/osmosis/v7/x/gamm/client/cli" "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper" "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer" - "github.com/osmosis-labs/osmosis/v7/x/gamm/simulation" "github.com/osmosis-labs/osmosis/v7/x/gamm/types" ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} - _ module.AppModuleSimulation = AppModule{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} ) type AppModuleBasic struct { @@ -160,36 +156,5 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val return []abci.ValidatorUpdate{} } -// ___________________________________________________________________________ - -// AppModuleSimulation functions - -// GenerateGenesisState creates a randomized GenState of the gamm module. -// However, at launch the gamm module has no state, hence this is a no-op. -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - // simulation.RandomizedGenState(simState) -} - -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil -} - -// RandomizedParams creates randomized gamm param changes for the simulator. -// There are no params that we view as sensible to randomize at the moment. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil - // return simulation.ParamChanges(r) -} - -// RegisterStoreDecoder registers a decoder for supply module's types. -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { -} - -// WeightedOperations returns all the simulation operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - return simulation.WeightedOperations(simState.AppParams, simState.Cdc, am.ak, am.bk, am.keeper) -} - // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/gamm/simulation/operations.go b/x/gamm/simulation/operations.go deleted file mode 100644 index ce53a37b330..00000000000 --- a/x/gamm/simulation/operations.go +++ /dev/null @@ -1,280 +0,0 @@ -//nolint:gosec // nolint because this file contains strings for testing -package simulation - -import ( - "math/rand" - "time" - - osmo_simulation "github.com/osmosis-labs/osmosis/v7/x/simulation" - - "github.com/cosmos/cosmos-sdk/baseapp" - - "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper" - "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer" - "github.com/osmosis-labs/osmosis/v7/x/gamm/types" - - "github.com/cosmos/cosmos-sdk/codec" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/simulation" - stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// Simulation operation weights constants. -const ( - OpWeightMsgCreatePool = "op_weight_create_pool" - OpWeightMsgSwapExactAmountIn = "op_weight_swap_exact_amount_in" - OpWeightMsgSwapExactAmountOut = "op_weight_swap_exact_amount_out" - OpWeightMsgJoinPool = "op_weight_join_pool" - OpWeightMsgExitPool = "op_weight_exit_pool" - OpWeightMsgJoinSwapExternAmountIn = "op_weight_join_swap_extern_amount_in" - OpWeightMsgJoinSwapShareAmountOut = "op_weight_join_swap_share_amount_out" - OpWeightMsgExitSwapExternAmountOut = "op_weight_exit_swap_extern_amount_out" - OpWeightMsgExitSwapShareAmountIn = "op_weight_exit_swap_share_amount_in" - - DefaultWeightMsgCreatePool int = 10 - DefaultWeightMsgSwapExactAmountIn int = 25 - DefaultWeightMsgSwapExactAmountOut int = 10 - DefaultWeightMsgJoinPool int = 10 - DefaultWeightMsgExitPool int = 10 - DefaultWeightMsgJoinSwapExternAmountIn int = 10 - DefaultWeightMsgJoinSwapShareAmountOut int = 10 - DefaultWeightMsgExitSwapExternAmountOut int = 10 - DefaultWeightMsgExitSwapShareAmountIn int = 10 -) - -// WeightedOperations returns all the operations from the module with their respective weights. -func WeightedOperations( - appParams simtypes.AppParams, cdc codec.JSONCodec, ak stakingTypes.AccountKeeper, - bk stakingTypes.BankKeeper, k keeper.Keeper, -) simulation.WeightedOperations { - // var ( - // weightMsgCreatePool int - // weightMsgSwapExactAmountIn int - // ) - - // appParams.GetOrGenerate(cdc, OpWeightMsgCreatePool, &weightMsgCreatePool, nil, - // func(_ *rand.Rand) { - // weightMsgCreatePool = simappparams.DefaultWeightMsgCreateValidator - // weightMsgSwapExactAmountIn = simappparams.DefaultWeightMsgCreateValidator - // }, - // ) - - return simulation.WeightedOperations{ - // simulation.NewWeightedOperation( - // weightMsgCreatePool, - // SimulateMsgCreateBalancerPool(ak, bk, k), - // ), - // simulation.NewWeightedOperation( - // weightMsgSwapExactAmountIn, - // SimulateMsgSwapExactAmountIn(ak, bk, k), - // ), - } -} - -func genFuturePoolGovernor(r *rand.Rand, addr sdk.Address, tokenList []string) string { - choice := r.Int31n(4) - if choice == 0 { // No governor - return "" - } else if choice == 1 { // Single address governor - return addr.String() - } else if choice == 2 { // LP token governor - return "1d" - } else { // Other token governor - token := tokenList[r.Intn(len(tokenList))] - return token + ",1d" - } -} - -func genPoolAssets(r *rand.Rand, acct simtypes.Account, coins sdk.Coins) []balancer.PoolAsset { - // selecting random number between [2, Min(coins.Len, 6)] - numCoins := 2 + r.Intn(Min(coins.Len(), 6)-1) - denomIndices := r.Perm(coins.Len()) - assets := []balancer.PoolAsset{} - for _, denomIndex := range denomIndices[:numCoins] { - denom := coins[denomIndex].Denom - amt, _ := simtypes.RandPositiveInt(r, coins[denomIndex].Amount.QuoRaw(100)) - reserveAmt := sdk.NewCoin(denom, amt) - weight := sdk.NewInt(r.Int63n(9) + 1) - assets = append(assets, balancer.PoolAsset{Token: reserveAmt, Weight: weight}) - } - - return assets -} - -func genBalancerPoolParams(r *rand.Rand, blockTime time.Time, assets []balancer.PoolAsset) balancer.PoolParams { - // swapFeeInt := int64(r.Intn(1e5)) - // swapFee := sdk.NewDecWithPrec(swapFeeInt, 6) - - exitFeeInt := int64(r.Intn(1e5)) - exitFee := sdk.NewDecWithPrec(exitFeeInt, 6) - - // TODO: Randomly generate LBP params - return balancer.PoolParams{ - // SwapFee: swapFee, - SwapFee: sdk.ZeroDec(), - ExitFee: exitFee, - } -} - -func Min(x, y int) int { - if x < y { - return x - } - return y -} - -func Max(x, y int) int { - if x > y { - return x - } - return y -} - -// SimulateMsgCreateBalancerPool generates a MsgCreatePool with random values. -func SimulateMsgCreateBalancerPool(ak stakingTypes.AccountKeeper, bk stakingTypes.BankKeeper, k keeper.Keeper) simtypes.Operation { - return func( - r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, - ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - simAccount, _ := simtypes.RandomAcc(r, accs) - simCoins := bk.SpendableCoins(ctx, simAccount.Address) - if simCoins.Len() <= 1 { - return simtypes.NoOpMsg( - types.ModuleName, balancer.TypeMsgCreateBalancerPool, "Account doesn't have 2 different coin types"), nil, nil - } - - poolAssets := genPoolAssets(r, simAccount, simCoins) - poolParams := genBalancerPoolParams(r, ctx.BlockTime(), poolAssets) - - // Commented out as genFuturePoolGovernor() panics on empty denom slice. - // TODO: fix and provide proper denom types. - // TODO: Replace []string{} with all token types on chain. - // futurePoolGovernor := genFuturePoolGovernor(r, simAccount.Address, []string{}) - - balances := bk.GetAllBalances(ctx, simAccount.Address) - denoms := make([]string, len(balances)) - for i := range balances { - denoms[i] = balances[i].Denom - } - - // set the pool params to set the pool creation fee to dust amount of denom - k.SetParams(ctx, types.Params{ - PoolCreationFee: sdk.Coins{sdk.NewInt64Coin(denoms[0], 1)}, - }) - - msg := &balancer.MsgCreateBalancerPool{ - Sender: simAccount.Address.String(), - PoolParams: &poolParams, - PoolAssets: poolAssets, - FuturePoolGovernor: "", - } - - spentCoins := balancer.PoolAssetsCoins(poolAssets) - - txGen := simappparams.MakeTestEncodingConfig().TxConfig - return osmo_simulation.GenAndDeliverTxWithRandFees( - r, app, txGen, msg, spentCoins, ctx, simAccount, ak, bk, types.ModuleName) - } -} - -// SimulateMsgSwapExactAmountIn generates a MsgSwapExactAmountIn with random values -// TODO: Change to use expected keepers -// func SimulateMsgSwapExactAmountIn(ak stakingTypes.AccountKeeper, bk stakingTypes.BankKeeper, k keeper.Keeper) simtypes.Operation { -// return func( -// r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, -// ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { -// simAccount, _ := simtypes.RandomAcc(r, accs) -// simCoins := bk.SpendableCoins(ctx, simAccount.Address) -// if simCoins.Len() <= 0 { -// return simtypes.NoOpMsg( -// types.ModuleName, types.TypeMsgSwapExactAmountIn, "Account have no coin"), nil, nil -// } - -// coin := simCoins[r.Intn(len(simCoins))] -// // Use under 0.5% of the account balance -// // TODO: Make like a 33% probability of using a ton of balance -// amt, _ := simtypes.RandPositiveInt(r, coin.Amount.QuoRaw(200)) - -// tokenIn := sdk.Coin{ -// Denom: coin.Denom, -// Amount: amt, -// } - -// routes, _ := RandomExactAmountInRoute(ctx, r, k, tokenIn) -// if len(routes) == 0 { -// return simtypes.NoOpMsg( -// types.ModuleName, types.TypeMsgSwapExactAmountIn, "No pool exist"), nil, nil -// } - -// msg := types.MsgSwapExactAmountIn{ -// Sender: simAccount.Address.String(), -// Routes: routes, -// TokenIn: tokenIn, -// TokenOutMinAmount: sdk.OneInt(), -// // TokenOutMinAmount: tokenOutMin.QuoRaw(2), -// } - -// txGen := simappparams.MakeTestEncodingConfig().TxConfig -// return osmo_simulation.GenAndDeliverTxWithRandFees( -// r, app, txGen, &msg, sdk.Coins{tokenIn}, ctx, simAccount, ak, bk, types.ModuleName) -// } -// } - -// func RandomExactAmountInRoute(ctx sdk.Context, r *rand.Rand, k keeper.Keeper, tokenIn sdk.Coin) (res []types.SwapAmountInRoute, tokenOut sdk.Coin) { -// routeLen := r.Intn(1) + 1 - -// allpools, err := k.GetPools(ctx) -// if err != nil { -// panic(err) -// } - -// pools := []types.PoolI{} -// for _, pool := range allpools { -// if pool.IsActive(ctx.BlockTime()) { -// pools = append(pools, pool) -// } -// } - -// if len(pools) == 0 { -// return -// } - -// res = []types.SwapAmountInRoute{} -// for i := 0; i < routeLen; i++ { -// // randomly selected pool might not include the source token, retry -// for retry := 0; retry < 10; retry++ { -// pool := pools[r.Intn(len(pools))] -// inAsset, err := pool.GetPoolAsset(tokenIn.Denom) -// if err != nil { -// continue -// } -// if inAsset.Token.Amount.LT(tokenIn.Amount) { -// continue -// } -// for _, asset := range pool.GetAllPoolAssets() { -// if asset.Token.Denom == tokenIn.Denom { -// continue -// } -// res = append(res, types.SwapAmountInRoute{ -// PoolId: pool.GetId(), -// TokenOutDenom: asset.Token.Denom, -// }) -// sp, err := k.CalculateSpotPriceWithSwapFee(ctx, pool.GetId(), tokenIn.Denom, asset.Token.Denom) -// if err != nil { -// panic(err) -// } -// amt := tokenIn.Amount.ToDec().Quo(sp).RoundInt() -// tokenIn = sdk.Coin{ -// Denom: asset.Token.Denom, -// Amount: amt, -// } -// break -// } -// break -// } -// } - -// tokenOut = tokenIn -// return -// } diff --git a/x/mint/module.go b/x/mint/module.go index 1cc38029a3f..8cb8d6c2f1f 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -178,7 +178,7 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We // RandomizedParams creates randomized mint param changes for the simulator. func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return simulation.ParamChanges(r) + return nil } // RegisterStoreDecoder registers a decoder for mint module's types. diff --git a/x/mint/simulation/params.go b/x/mint/simulation/params.go deleted file mode 100644 index c86471bdd08..00000000000 --- a/x/mint/simulation/params.go +++ /dev/null @@ -1,34 +0,0 @@ -package simulation - -// DONTCOVER - -import ( - "math/rand" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" -) - -// const ( -// keyMaxRewardPerEpoch = "MaxRewardPerEpoch" -// keyMinRewardPerEpoch = "MinRewardPerEpoch" -// ) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation. -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - // simulation.NewSimParamChange(types.ModuleName, keyMaxRewardPerEpoch, - // func(r *rand.Rand) string { - // return fmt.Sprintf("\"%s\"", GenMaxRewardPerEpoch(r)) - // }, - // ), - // simulation.NewSimParamChange(types.ModuleName, keyMinRewardPerEpoch, - // func(r *rand.Rand) string { - // return fmt.Sprintf("\"%s\"", GenMinRewardPerEpoch(r)) - // }, - // ), - // Leaving as sample code - - // TODO: Simulate changing new params - } -} diff --git a/x/mint/simulation/params_test.go b/x/mint/simulation/params_test.go deleted file mode 100644 index deea672b5cb..00000000000 --- a/x/mint/simulation/params_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/osmosis-labs/osmosis/v7/x/mint/simulation" -) - -func TestParamChanges(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - // {"mint/MaxRewardPerEpoch", "MaxRewardPerEpoch", "\"0.200000000000000000\"", "mint"}, - // {"mint/MinRewardPerEpoch", "MinRewardPerEpoch", "\"0.070000000000000000\"", "mint"}, - // Leaving as sample code - - // TODO: Test proper ParamChanges - } - - paramChanges := simulation.ParamChanges(r) - // require.Len(t, paramChanges, 2) - - for i, p := range paramChanges { - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} diff --git a/x/tokenfactory/module.go b/x/tokenfactory/module.go index 9e8afe33b08..c2b7d691e33 100644 --- a/x/tokenfactory/module.go +++ b/x/tokenfactory/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -17,7 +16,6 @@ import ( cdctypes "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" "github.com/osmosis-labs/osmosis/v7/x/tokenfactory/client/cli" "github.com/osmosis-labs/osmosis/v7/x/tokenfactory/keeper" @@ -168,31 +166,3 @@ func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } - -// ___________________________________________________________________________ - -// AppModuleSimulation functions - -// GenerateGenesisState creates a randomized GenState of the tokenfactory module. -func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(types.DefaultGenesis()) -} - -// ProposalContents doesn't return any content functions for governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil -} - -// RandomizedParams creates randomized txfees param changes for the simulator. -func (am AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - -// RegisterStoreDecoder registers a decoder for tokenfactory module's types -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { -} - -// WeightedOperations returns simulator module operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - return nil // TODO -} diff --git a/x/txfees/module.go b/x/txfees/module.go index e86ac407aa5..5949982b711 100644 --- a/x/txfees/module.go +++ b/x/txfees/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -16,7 +15,6 @@ import ( cdctypes "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" "github.com/osmosis-labs/osmosis/v7/x/txfees/client/cli" "github.com/osmosis-labs/osmosis/v7/x/txfees/keeper" @@ -167,35 +165,5 @@ func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.Valid return []abci.ValidatorUpdate{} } -// ___________________________________________________________________________ - -// AppModuleSimulation functions - -// GenerateGenesisState creates a randomized GenState of the pool-incentives module. -func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { - // gen := types.DefaultGenesis() - // gen.Basedenom = sdk.DefaultBondDenom - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(types.DefaultGenesis()) -} - -// ProposalContents doesn't return any content functions for governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil -} - -// RandomizedParams creates randomized txfees param changes for the simulator. -func (am AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - -// RegisterStoreDecoder registers a decoder for supply module's types. -func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { -} - -// WeightedOperations returns the all the gov module operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - return nil // TODO -} - // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 }