Skip to content

Commit

Permalink
[CL Simulator] Fix existing simulator and test simulator flow for Col…
Browse files Browse the repository at this point in the history
…lectFees, CollectIncentives (#4832)

* refactored gethighestliquiditypool

* [CL Incentives] Implement incentives wiring from governance-triggered emissions

* adams comments

* adams comments

* nit

* added position id and pool id mapping

* wip

* fixed test

* more cleanup

* fix

* adam comment nits

* fixed test

* nit

* removed math/rand

* rebased

* reabsed
  • Loading branch information
stackman27 authored Apr 25, 2023
1 parent e871bed commit 465f8ef
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 176 deletions.
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appCodec, appKeepers.keys[protorevtypes.StoreKey],
appKeepers.GetSubspace(protorevtypes.ModuleName),
appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.GAMMKeeper, appKeepers.EpochsKeeper, appKeepers.PoolManagerKeeper)

appKeepers.ProtoRevKeeper = &protorevKeeper

txFeesKeeper := txfeeskeeper.NewKeeper(
Expand Down
4 changes: 4 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func (app *OsmosisApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.AppKeepers.ScopedIBCKeeper
}

func (app *OsmosisApp) GetPoolManagerKeeper() simtypes.PoolManagerKeeper {
return app.AppKeepers.PoolManagerKeeper
}

func (app *OsmosisApp) GetTxConfig() client.TxConfig {
return MakeEncodingConfig().TxConfig
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,6 @@ github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230326212251-7a2cf2993434 h1:RetE
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230326212251-7a2cf2993434/go.mod h1:ss3tUfPTwaa6NsoPZrCR7xOqLqCK0LwoNbc2Q8Zs5/Y=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI=
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e4304 h1:iSSlHl+SoewNpP/2N8JaUEHhOQRmJAnS8zaJ11yWslY=
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e4304/go.mod h1:/h3CZIo25kMrM4Ojm7qBgMxKofTVwOycVWSa4rhEsaM=
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230425121701-4d427b673864 h1:UhkJ67kx4NP7FEEQ+ybpDLIiS0Rl8vX8G55FKZux98I=
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230425121701-4d427b673864/go.mod h1:Hu4OHAvKtnCaqA4GlodNf89JZ+2TFtH7IDNxNi6Vue8=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230411200859-ae3065d0ca05 h1:fqVGxZPgUWuYWxVcMxHz5vrDV/aoxGJ7Kt0J4Vu/bsY=
Expand Down
1 change: 1 addition & 0 deletions proto/osmosis/concentrated-liquidity/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ service Msg {
rpc CollectFees(MsgCollectFees) returns (MsgCollectFeesResponse);
rpc CollectIncentives(MsgCollectIncentives)
returns (MsgCollectIncentivesResponse);
rpc CreateIncentive(MsgCreateIncentive) returns (MsgCreateIncentiveResponse);
rpc FungifyChargedPositions(MsgFungifyChargedPositions)
returns (MsgFungifyChargedPositionsResponse);
}
Expand Down
7 changes: 7 additions & 0 deletions simulation/simtypes/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
)

type AppCreator = func(homepath string, legacyInvariantPeriod uint, baseappOptions ...func(*baseapp.BaseApp)) App
Expand All @@ -18,6 +20,7 @@ type App interface {
GetBankKeeper() BankKeeper
GetStakingKeeper() stakingkeeper.Keeper
ModuleManager() module.Manager
GetPoolManagerKeeper() PoolManagerKeeper
}

type AccountKeeper interface {
Expand All @@ -31,3 +34,7 @@ type BankKeeper interface {
// TODO: Revisit
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
}

type PoolManagerKeeper interface {
CreatePool(ctx sdk.Context, msg poolmanagertypes.CreatePoolMsg) (uint64, error)
}
4 changes: 4 additions & 0 deletions simulation/simtypes/simctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (sim SimCtx) StakingKeeper() stakingkeeper.Keeper {
return sim.app.GetStakingKeeper()
}

func (sim SimCtx) PoolManagerKeeper() PoolManagerKeeper {
return sim.app.GetPoolManagerKeeper()
}

// randManager is built to give API's for randomness access
// which allow the caller to avoid "butterfly effects".
// e.g. in the Simulator, I don't want adding one new rand call to a message
Expand Down
14 changes: 7 additions & 7 deletions x/concentrated-liquidity/clmodule/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/client/cli"
"github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/client/queryproto"
clmodel "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/model"
"github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/simulation"

clkeeper "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity"
clclient "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/client"
Expand Down Expand Up @@ -156,12 +157,11 @@ func (am AppModule) GenerateGenesisState(simState *module.SimulationState, s *si

func (am AppModule) Actions() []simtypes.Action {
return []simtypes.Action{
// simtypes.NewMsgBasedAction("CreateConcentratedPool", am.keeper, simulation.RandomMsgCreateConcentratedPool),
// simtypes.NewMsgBasedAction("CreatePosition", am.keeper, simulation.RandMsgCreatePosition),
// simtypes.NewMsgBasedAction("CLSwapExactAmountIn", am.keeper, simulation.RandomSwapExactAmountIn),
// simtypes.NewMsgBasedAction("CLSwapExactAmountOut", am.keeper, simulation.RandomSwapExactAmountOut),
// simtypes.NewMsgBasedAction("WithdrawPosition", am.keeper, simulation.RandMsgWithdrawPosition),
// simtypes.NewMsgBasedAction("CollectFees", am.keeper, simulation.RandMsgCollectFees),
// simtypes.NewMsgBasedAction("CollectIncentives", am.keeper, simulation.RandMsgCollectIncentives),
simtypes.NewMsgBasedAction("CreateConcentratedPool", am.keeper, simulation.RandomMsgCreateConcentratedPool),
simtypes.NewMsgBasedAction("CreatePosition", am.keeper, simulation.RandMsgCreatePosition),
simtypes.NewMsgBasedAction("WithdrawPosition", am.keeper, simulation.RandMsgWithdrawPosition),
simtypes.NewMsgBasedAction("CollectFees", am.keeper, simulation.RandMsgCollectFees),
simtypes.NewMsgBasedAction("CollectIncentives", am.keeper, simulation.RandMsgCollectIncentives),
simtypes.NewMsgBasedAction("CreateIncentives", am.keeper, simulation.RandMsgCreateIncentives),
}
}
9 changes: 9 additions & 0 deletions x/concentrated-liquidity/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ func (k Keeper) isPositionOwner(ctx sdk.Context, sender sdk.AccAddress, poolId u
return isOwner, nil
}

// GetAllPositionsForPoolId gets all the position for a specific poolId.
func (k Keeper) GetAllPositionIdsForPoolId(ctx sdk.Context, poolId uint64) ([]uint64, error) {
parse := func(bz []byte) (uint64, error) {
return sdk.BigEndianToUint64(bz), nil
}

return osmoutils.GatherValuesFromStorePrefix(ctx.KVStore(k.storeKey), types.KeyPoolPosition(poolId), parse)
}

// GetPositionLiquidity checks if the provided positionId exists. Returns position liquidity if found. Error otherwise.
func (k Keeper) GetPositionLiquidity(ctx sdk.Context, positionId uint64) (sdk.Dec, error) {
position, err := k.GetPosition(ctx, positionId)
Expand Down
31 changes: 31 additions & 0 deletions x/concentrated-liquidity/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1335,3 +1335,34 @@ func (s *KeeperTestSuite) TestGetAndUpdateFullRangeLiquidity() {
s.Require().Equal(expectedFullRangeLiquidity.Add(tc.updateLiquidity), actualFullRangeLiquidity)
}
}

func (s *KeeperTestSuite) TestGetAllPositionIdsForPoolId() {
s.SetupTest()
clKeeper := s.App.ConcentratedLiquidityKeeper
s.Ctx = s.Ctx.WithBlockTime(defaultStartTime)

// Set up test pool
clPoolOne := s.PrepareConcentratedPool()

s.SetupDefaultPositionAcc(clPoolOne.GetId(), s.TestAccs[0])
s.SetupDefaultPositionAcc(clPoolOne.GetId(), s.TestAccs[1])
s.SetupDefaultPositionAcc(clPoolOne.GetId(), s.TestAccs[2])

clPooltwo := s.PrepareConcentratedPool()

s.SetupDefaultPositionAcc(clPooltwo.GetId(), s.TestAccs[0])
s.SetupDefaultPositionAcc(clPooltwo.GetId(), s.TestAccs[1])
s.SetupDefaultPositionAcc(clPooltwo.GetId(), s.TestAccs[2])

expectedPositionOneIds := []uint64{1, 2, 3}
expectedPositionTwoIds := []uint64{4, 5, 6}

positionOne, err := clKeeper.GetAllPositionIdsForPoolId(s.Ctx, clPoolOne.GetId())
s.Require().NoError(err)

positionTwo, err := clKeeper.GetAllPositionIdsForPoolId(s.Ctx, clPooltwo.GetId())
s.Require().NoError(err)

s.Require().Equal(expectedPositionOneIds, positionOne)
s.Require().Equal(expectedPositionTwoIds, positionTwo)
}
Loading

0 comments on commit 465f8ef

Please sign in to comment.