Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gamm keeper delete obsolete files #2160

Merged
merged 12 commits into from
Aug 2, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Golang API breaks

* [#2160](https://github.com/osmosis-labs/osmosis/pull/2160) Clean up GAMM keeper (move `x/gamm/keeper/params.go` contents into `x/gamm/keeper/keeper.go`, replace all uses of `PoolNumber` with `PoolId`, move `SetStableSwapScalingFactors` to stableswap package, and delete marshal_bench_test.go and grpc_query_internal_test.go)
* [#1987](https://github.com/osmosis-labs/osmosis/pull/1987) Remove `GammKeeper.GetNextPoolNumberAndIncrement` in favor of the non-mutative `GammKeeper.GetNextPoolNumber`.
* [#1937](https://github.com/osmosis-labs/osmosis/pull/1937) Change `lockupKeeper.ExtendLock` to take in lockID instead of the direct lock struct.
* [#1893](https://github.com/osmosis-labs/osmosis/pull/1893) Change `EpochsKeeper.SetEpochInfo` to `AddEpochInfo`, which has more safety checks with it. (Makes it suitable to be called within upgrades)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/CosmWasm/wasmd v0.24.0
github.com/cosmos/cosmos-proto v1.0.0-alpha7
github.com/cosmos/cosmos-sdk v0.45.6
github.com/cosmos/cosmos-sdk v0.46.0
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v0.17.3
github.com/cosmos/ibc-go/v3 v3.0.0
Expand Down
1 change: 1 addition & 0 deletions proto/osmosis/gamm/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option go_package = "github.com/osmosis-labs/osmosis/v10/x/gamm/types";
message GenesisState {
repeated google.protobuf.Any pools = 1
[ (cosmos_proto.accepts_interface) = "PoolI" ];
// will be renamed to next_pool_id in an upcoming version
uint64 next_pool_number = 2;
Params params = 3 [ (gogoproto.nullable) = false ];
}
6 changes: 3 additions & 3 deletions x/gamm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

// InitGenesis initializes the x/gamm module's state from a provided genesis
// state, which includes the current live pools, global pool parameters (e.g. pool creation fee), next pool number etc.
// state, which includes the current live pools, global pool parameters (e.g. pool creation fee), next pool id etc.
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState, unpacker codectypes.AnyUnpacker) {
k.setParams(ctx, genState.Params)
k.setNextPoolNumber(ctx, genState.NextPoolNumber)
k.setNextPoolId(ctx, genState.NextPoolNumber)

// Sums up the liquidity in all genesis state pools to find the total liquidity across all pools.
// Also adds each genesis state pool to the x/gamm module's state
Expand Down Expand Up @@ -51,7 +51,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
poolAnys = append(poolAnys, any)
}
return &types.GenesisState{
NextPoolNumber: k.GetNextPoolNumber(ctx),
NextPoolNumber: k.GetNextPoolId(ctx),
Pools: poolAnys,
Params: k.GetParams(ctx),
}
Expand Down
6 changes: 3 additions & 3 deletions x/gamm/keeper/genesis_test
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func TestGammInitGenesis(t *testing.T) {

gamm.InitGenesis(ctx, *app.GAMMKeeper, types.GenesisState{
Pools: []*codectypes.Any{any},
NextPoolNumber: 2,
NextPoolId: 2,
Params: types.Params{
PoolCreationFee: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000_000_000)},
},
}, app.AppCodec())

require.Equal(t, app.GAMMKeeper.GetNextPoolNumberAndIncrement(ctx), uint64(2))
require.Equal(t, app.GAMMKeeper.GetNextPoolIdAndIncrement(ctx), uint64(2))
poolStored, err := app.GAMMKeeper.GetPoolAndPoke(ctx, 1)
require.NoError(t, err)
require.Equal(t, balancerPool.GetId(), poolStored.GetId())
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestGammExportGenesis(t *testing.T) {
require.NoError(t, err)

genesis := gamm.ExportGenesis(ctx, *app.GAMMKeeper)
require.Equal(t, genesis.NextPoolNumber, uint64(3))
require.Equal(t, genesis.NextPoolId, uint64(3))
require.Len(t, genesis.Pools, 2)
}

Expand Down
2 changes: 1 addition & 1 deletion x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (q Querier) NumPools(ctx context.Context, _ *types.QueryNumPoolsRequest) (*
sdkCtx := sdk.UnwrapSDKContext(ctx)

return &types.QueryNumPoolsResponse{
NumPools: q.Keeper.GetNextPoolNumber(sdkCtx) - 1,
NumPools: q.Keeper.GetNextPoolId(sdkCtx) - 1,
}, nil
}

Expand Down
15 changes: 0 additions & 15 deletions x/gamm/keeper/grpc_query_internal_test.go

This file was deleted.

11 changes: 11 additions & 0 deletions x/gamm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ func (k *Keeper) SetHooks(gh types.GammHooks) *Keeper {

return k
}

// GetParams returns the total set params.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, &params)
return params
}

// SetParams sets the total set of params.
func (k Keeper) setParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}
85 changes: 0 additions & 85 deletions x/gamm/keeper/marshal_bench_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions x/gamm/keeper/params.go

This file was deleted.

52 changes: 11 additions & 41 deletions x/gamm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/osmosis-labs/osmosis/v10/osmoutils"
"github.com/osmosis-labs/osmosis/v10/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v10/x/gamm/pool-models/stableswap"
"github.com/osmosis-labs/osmosis/v10/x/gamm/types"
)

Expand Down Expand Up @@ -210,20 +209,19 @@ func (k Keeper) GetPoolDenoms(ctx sdk.Context, poolId uint64) ([]string, error)
return denoms, err
}

// setNextPoolNumber sets next pool number.
func (k Keeper) setNextPoolNumber(ctx sdk.Context, poolNumber uint64) {
// setNextPoolId sets next pool Id.
func (k Keeper) setNextPoolId(ctx sdk.Context, poolId uint64) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: poolNumber})
store.Set(types.KeyNextGlobalPoolNumber, bz)
bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: poolId})
store.Set(types.KeyNextGlobalPoolId, bz)
}

// GetNextPoolNumber returns the next pool number.
// TODO: Rename NextPoolNumber to NextPoolId
func (k Keeper) GetNextPoolNumber(ctx sdk.Context) uint64 {
// GetNextPoolId returns the next pool Id.
func (k Keeper) GetNextPoolId(ctx sdk.Context) uint64 {
var nextPoolId uint64
store := ctx.KVStore(k.storeKey)

bz := store.Get(types.KeyNextGlobalPoolNumber)
bz := store.Get(types.KeyNextGlobalPoolId)
if bz == nil {
panic(fmt.Errorf("pool has not been initialized -- Should have been done in InitGenesis"))
} else {
Expand All @@ -239,37 +237,9 @@ func (k Keeper) GetNextPoolNumber(ctx sdk.Context) uint64 {
return nextPoolId
}

// getNextPoolNumberAndIncrement returns the next pool number, and increments the corresponding state entry.
func (k Keeper) getNextPoolNumberAndIncrement(ctx sdk.Context) uint64 {
nextPoolId := k.GetNextPoolNumber(ctx)
k.setNextPoolNumber(ctx, nextPoolId+1)
// getNextPoolIdAndIncrement returns the next pool Id, and increments the corresponding state entry.
func (k Keeper) getNextPoolIdAndIncrement(ctx sdk.Context) uint64 {
nextPoolId := k.GetNextPoolId(ctx)
k.setNextPoolId(ctx, nextPoolId+1)
return nextPoolId
}

// set ScalingFactors in stable stableswap pools
func (k *Keeper) SetStableSwapScalingFactors(ctx sdk.Context, scalingFactors []uint64, poolId uint64, scalingFactorGovernor string) error {
poolI, err := k.GetPoolAndPoke(ctx, poolId)
if err != nil {
return err
}

stableswapPool, ok := poolI.(*stableswap.Pool)
if !ok {
return types.ErrNotStableSwapPool
}

if scalingFactorGovernor != stableswapPool.ScalingFactorGovernor {
return types.ErrNotScalingFactorGovernor
}

if len(scalingFactors) != stableswapPool.PoolLiquidity.Len() {
return types.ErrInvalidStableswapScalingFactors
}

stableswapPool.ScalingFactor = scalingFactors

if err = k.setPool(ctx, stableswapPool); err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion x/gamm/keeper/pool_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, er
return 0, err
}

poolId := k.getNextPoolNumberAndIncrement(ctx)
poolId := k.getNextPoolIdAndIncrement(ctx)
pool, err := msg.CreatePool(ctx, poolId)
if err != nil {
return 0, err
Expand Down
10 changes: 5 additions & 5 deletions x/gamm/pool-models/balancer/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ func TestBalancerPoolPokeTokenWeights(t *testing.T) {
return updatedCases
}

for poolNum, tc := range tests {
for poolId, tc := range tests {
paramsCopy := tc.params
// First we create the initial pool assets we will use
initialPoolAssets := make([]balancer.PoolAsset, len(paramsCopy.InitialPoolWeights))
Expand All @@ -1162,12 +1162,12 @@ func TestBalancerPoolPokeTokenWeights(t *testing.T) {
initialPoolAssets[i] = assetCopy
}
// Initialize the pool
pacc, err := balancer.NewBalancerPool(uint64(poolNum), balancer.PoolParams{
pacc, err := balancer.NewBalancerPool(uint64(poolId), balancer.PoolParams{
SwapFee: defaultSwapFee,
ExitFee: defaultExitFee,
SmoothWeightChangeParams: &tc.params,
}, initialPoolAssets, defaultFutureGovernor, defaultCurBlockTime)
require.NoError(t, err, "poolNumber %v", poolNum)
require.NoError(t, err, "poolId %v", poolId)

// Consistency check that SmoothWeightChangeParams params are set
require.NotNil(t, pacc.PoolParams.SmoothWeightChangeParams)
Expand All @@ -1180,8 +1180,8 @@ func TestBalancerPoolPokeTokenWeights(t *testing.T) {

for assetNum, asset := range pacc.GetAllPoolAssets() {
require.Equal(t, testCase.expectedWeights[assetNum], asset.Weight,
"Didn't get the expected weights, poolNumber %v, caseNumber %v, assetNumber %v",
poolNum, caseNum, assetNum)
"Didn't get the expected weights, poolId %v, caseNumber %v, assetNumber %v",
poolId, caseNum, assetNum)

totalWeight = totalWeight.Add(asset.Weight)
}
Expand Down
17 changes: 17 additions & 0 deletions x/gamm/pool-models/stableswap/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,20 @@ func (p Pool) CalcExitPoolCoinsFromShares(ctx sdk.Context, exitingShares sdk.Int

// no-op for stableswap
func (p *Pool) PokePool(blockTime time.Time) {}

// SetStableSwapScalingFactors sets scaling factors for pool to the given amount
// It should only be able to be successfully called by the pool's ScalingFactorGovernor
// TODO: move commented test for this function from x/gamm/keeper/pool_service_test.go once a pool_test.go file has been created for stableswap
func (p *Pool) SetStableSwapScalingFactors(ctx sdk.Context, scalingFactors []uint64, scalingFactorGovernor string) error {
if scalingFactorGovernor != p.ScalingFactorGovernor {
return types.ErrNotScalingFactorGovernor
}

if len(scalingFactors) != p.PoolLiquidity.Len() {
return types.ErrInvalidStableswapScalingFactors
}

p.ScalingFactor = scalingFactors

return nil
}
8 changes: 3 additions & 5 deletions x/gamm/simulation/sim_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import (
"github.com/osmosis-labs/osmosis/v10/x/gamm/types"
)

var (
PoolCreationFee = sdk.NewInt64Coin("stake", 10_000_000)
)
var PoolCreationFee = sdk.NewInt64Coin("stake", 10_000_000)

// RandomJoinPoolMsg pseudo-randomly selects an existing pool ID, attempts to find an account with the
// respective underlying token denoms, and attempts to execute a join pool transaction
func RandomJoinPoolMsg(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) (*types.MsgJoinPool, error) {
// get random pool
pool_id := simtypes.RandLTBound(sim, k.GetNextPoolNumber(ctx))
pool_id := simtypes.RandLTBound(sim, k.GetNextPoolId(ctx))
pool, err := k.GetPoolAndPoke(ctx, pool_id)
if err != nil {
return &types.MsgJoinPool{}, err
Expand Down Expand Up @@ -99,7 +97,7 @@ func deriveRealMinShareOutAmt(ctx sdk.Context, tokenIn sdk.Coins, pool types.Poo
// respective unbonded gamm shares, and attempts to execute an exit pool transaction
func RandomExitPoolMsg(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) (*types.MsgExitPool, error) {
// select a pseudo-random pool ID, max bound by the upcoming pool ID
pool_id := simtypes.RandLTBound(sim, k.GetNextPoolNumber(ctx))
pool_id := simtypes.RandLTBound(sim, k.GetNextPoolId(ctx))
pool, err := k.GetPoolAndPoke(ctx, pool_id)
if err != nil {
return &types.MsgExitPool{}, err
Expand Down
Loading