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

Moves ValidatePermissionlessPoolCreationEnabled out of poolmanager module #6421

Merged
merged 13 commits into from
Sep 24, 2023
Prev Previous commit
Next Next commit
refactored where validate permissionless is checked
  • Loading branch information
sunnya97 committed Sep 17, 2023
commit 2f4701e548de20532ad4785513eb0a3e62baa41a
14 changes: 0 additions & 14 deletions tests/mocks/pool_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions x/concentrated-liquidity/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ func (k *Keeper) SetListeners(listeners types.ConcentratedLiquidityListeners) *K

// ValidatePermissionlessPoolCreationEnabled returns nil if permissionless pool creation in the module is enabled.
// Otherwise, returns an error.
func (k Keeper) ValidatePermissionlessPoolCreationEnabled(ctx sdk.Context) error {
func (k Keeper) ValidatePermissionlessPoolCreationEnabled(ctx sdk.Context) bool {
if !k.GetParams(ctx).IsPermissionlessPoolCreationEnabled {
return types.ErrPermissionlessPoolCreationDisabled
return false
}
return nil
return true
}

// GetAuthorizedQuoteDenoms gets the authorized quote denoms from the poolmanager keeper.
Expand Down
4 changes: 2 additions & 2 deletions x/concentrated-liquidity/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,15 @@ func (s *KeeperTestSuite) AddBlockTime(timeToAdd time.Duration) {
func (s *KeeperTestSuite) TestValidatePermissionlessPoolCreationEnabled() {
// Normally, by default, permissionless pool creation is disabled.
// SetupTest, however, calls SetupConcentratedLiquidityDenomsAndPoolCreation which enables permissionless pool creation.
sunnya97 marked this conversation as resolved.
Show resolved Hide resolved
s.Require().NoError(s.App.ConcentratedLiquidityKeeper.ValidatePermissionlessPoolCreationEnabled(s.Ctx))
s.Require().True(s.App.ConcentratedLiquidityKeeper.ValidatePermissionlessPoolCreationEnabled(s.Ctx))

// Disable permissionless pool creation.
defaultParams := types.DefaultParams()
defaultParams.IsPermissionlessPoolCreationEnabled = false
s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, defaultParams)

// Validate that permissionless pool creation is disabled.
s.Require().Error(s.App.ConcentratedLiquidityKeeper.ValidatePermissionlessPoolCreationEnabled(s.Ctx))
s.Require().False(s.App.ConcentratedLiquidityKeeper.ValidatePermissionlessPoolCreationEnabled(s.Ctx))
}

func (s *KeeperTestSuite) runMultipleAuthorizedUptimes(tests func()) {
Expand Down
4 changes: 4 additions & 0 deletions x/concentrated-liquidity/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (k Keeper) InitializePool(ctx sdk.Context, poolI poolmanagertypes.PoolI, cr
}

if !bypassRestrictions {
if !k.ValidatePermissionlessPoolCreationEnabled(ctx) {
return types.ErrPermissionlessPoolCreationDisabled
}

if !k.validateTickSpacing(params, tickSpacing) {
return types.UnauthorizedTickSpacingError{ProvidedTickSpacing: tickSpacing, AuthorizedTickSpacings: params.AuthorizedTickSpacing}
}
Expand Down
6 changes: 0 additions & 6 deletions x/cosmwasmpool/pool_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,6 @@ func (k Keeper) CalcInAmtGivenOut(
return response.TokenIn, nil
}

// ValidatePermissionlessPoolCreationEnabled returns nil if permissionless pool creation in the module is enabled.
// Otherwise, returns an error.
func (k Keeper) ValidatePermissionlessPoolCreationEnabled(ctx sdk.Context) error {
return nil
}

// GetTotalPoolLiquidity retrieves the total liquidity of a specific pool identified by poolId.
//
// Parameters:
Expand Down
6 changes: 0 additions & 6 deletions x/gamm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ func (k Keeper) setParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}

// ValidatePermissionlessPoolCreationEnabled returns nil if permissionless pool creation in the module is enabled.
// Pools in gamm module have permissionless pool creation enabled, thus always return nil.
func (k Keeper) ValidatePermissionlessPoolCreationEnabled(ctx sdk.Context) error {
return nil
}

// Set the pool incentives keeper.
func (k *Keeper) SetPoolIncentivesKeeper(poolIncentivesKeeper types.PoolIncentivesKeeper) {
k.poolIncentivesKeeper = poolIncentivesKeeper
Expand Down
12 changes: 5 additions & 7 deletions x/poolmanager/create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ func (k Keeper) validateCreatedPool(poolId uint64, pool types.PoolI) error {
// - Minting LP shares to pool creator
// - Setting metadata for the shares
func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, error) {
// Get pool module interface from the pool type.
// Check that the pool type exists
// TODO: see if we can get rid of this check
poolType := msg.GetPoolType()
poolModule, ok := k.routes[poolType]
_, ok := k.routes[poolType]
if !ok {
return 0, types.InvalidPoolTypeError{PoolType: poolType}
}

// Confirm that permissionless pool creation is enabled for the module.
if err := poolModule.ValidatePermissionlessPoolCreationEnabled(ctx); err != nil {
return 0, err
}

// createPoolZeroLiquidityNoCreationFee contains shared pool creation logic between this function (CreatePool) and
// CreateConcentratedPoolAsPoolManager. Despite the name, within this (CreatePool) function, we do charge a creation
// fee and send initial liquidity to the pool's address. createPoolZeroLiquidityNoCreationFee is strictly used to reduce code duplication.
Expand All @@ -57,6 +53,8 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, er
return 0, err
}

// TODO see what happens if this is called for gamm

// Send initial liquidity from pool creator to pool module account.
initialPoolLiquidity := msg.InitialLiquidity()
err = k.bankKeeper.SendCoins(ctx, sender, pool.GetAddress(), initialPoolLiquidity)
Expand Down
4 changes: 0 additions & 4 deletions x/poolmanager/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ type PoolModuleI interface {
// GetTotalPoolLiquidity returns the coins in the pool owned by all LPs
GetTotalPoolLiquidity(ctx sdk.Context, poolId uint64) (sdk.Coins, error)

// ValidatePermissionlessPoolCreationEnabled returns nil if permissionless pool creation in the module is enabled.
// Otherwise, returns an error.
ValidatePermissionlessPoolCreationEnabled(ctx sdk.Context) error

// GetTotalLiquidity returns the total liquidity of all the pools in the module.
GetTotalLiquidity(ctx sdk.Context) (sdk.Coins, error)
}
Expand Down