From 17c7339c828c81b933b11c0ecef04bd21a5991d1 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 17 Sep 2023 01:29:10 +0800 Subject: [PATCH 01/12] in progress --- .../concentrated-liquidity/params.proto | 7 + x/concentrated-liquidity/types/constants.go | 3 +- x/concentrated-liquidity/types/params.go | 28 ++++ x/concentrated-liquidity/types/params.pb.go | 134 +++++++++++++----- 4 files changed, 135 insertions(+), 37 deletions(-) diff --git a/proto/osmosis/concentrated-liquidity/params.proto b/proto/osmosis/concentrated-liquidity/params.proto index 355b9942825..e4d31c071c7 100644 --- a/proto/osmosis/concentrated-liquidity/params.proto +++ b/proto/osmosis/concentrated-liquidity/params.proto @@ -56,4 +56,11 @@ message Params { bool is_permissionless_pool_creation_enabled = 6 [ (gogoproto.moretags) = "yaml:\"is_permissionless_pool_creation_enabled\"" ]; + + // unrestricted_pool_creator_whitelist is a list of addresses that are + // allowed to bypass restrictions on permissionless supercharged pool + // creation, like pool_creation_enabled, restricted quote assets, no + // double creation of pools, etc. + repeated string unrestricted_pool_creator_whitelist = 7 + [ (gogoproto.moretags) = "yaml:\"unrestricted_pool_creator_whitelist\"" ]; } diff --git a/x/concentrated-liquidity/types/constants.go b/x/concentrated-liquidity/types/constants.go index 011cc57ab4e..d48c0ebbf40 100644 --- a/x/concentrated-liquidity/types/constants.go +++ b/x/concentrated-liquidity/types/constants.go @@ -56,5 +56,6 @@ var ( } DefaultBalancerSharesDiscount = osmomath.MustNewDecFromStr("0.05") // By default, we only authorize one nanosecond (one block) uptime as an option - DefaultAuthorizedUptimes = []time.Duration{time.Nanosecond} + DefaultAuthorizedUptimes = []time.Duration{time.Nanosecond} + DefaultUnrestrictedPoolCreatorWhitelist = []string{} ) diff --git a/x/concentrated-liquidity/types/params.go b/x/concentrated-liquidity/types/params.go index bc375ad34ce..bb989278de5 100644 --- a/x/concentrated-liquidity/types/params.go +++ b/x/concentrated-liquidity/types/params.go @@ -52,6 +52,7 @@ func DefaultParams() Params { BalancerSharesRewardDiscount: DefaultBalancerSharesDiscount, AuthorizedUptimes: DefaultAuthorizedUptimes, IsPermissionlessPoolCreationEnabled: false, + UnrestrictedPoolCreatorWhitelist: DefaultUnrestrictedPoolCreatorWhitelist, } } @@ -75,6 +76,9 @@ func (p Params) Validate() error { if err := validateAuthorizedUptimes(p.AuthorizedUptimes); err != nil { return err } + if err := validateUnrestrictedPoolCreatorWhitelist(p.UnrestrictedPoolCreatorWhitelist); err != nil { + return err + } return nil } @@ -235,3 +239,27 @@ func validateAuthorizedUptimes(i interface{}) error { return nil } + +// validateUnrestrictedPoolCreatorWhitelist validates a slice of addresses +// that are allowed to bypass the restrictions on permissionless pool creation +// +// Parameters: +// - i: The parameter to validate. +// +// Returns: +// - An error if any of the strings are not addresses +func validateUnrestrictedPoolCreatorWhitelist(i interface{}) error { + whitelist, ok := i.([]string) + + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + for _, a := range whitelist { + if _, err := sdk.AccAddressFromBech32(a); err != nil { + return fmt.Errorf("invalid address") + } + } + + return nil +} diff --git a/x/concentrated-liquidity/types/params.pb.go b/x/concentrated-liquidity/types/params.pb.go index a69d99a2303..c94463f0486 100644 --- a/x/concentrated-liquidity/types/params.pb.go +++ b/x/concentrated-liquidity/types/params.pb.go @@ -58,6 +58,11 @@ type Params struct { // allowing permissionless pool creation by switching this flag to true // with a governance proposal. IsPermissionlessPoolCreationEnabled bool `protobuf:"varint,6,opt,name=is_permissionless_pool_creation_enabled,json=isPermissionlessPoolCreationEnabled,proto3" json:"is_permissionless_pool_creation_enabled,omitempty" yaml:"is_permissionless_pool_creation_enabled"` + // unrestricted_pool_creator_whitelist is a list of addresses that are + // allowed to bypass restrictions on permissionless supercharged pool + // creation, like pool_creation_enabled, restricted quote assets, no + // double creation of pools, etc. + UnrestrictedPoolCreatorWhitelist []string `protobuf:"bytes,7,rep,name=unrestricted_pool_creator_whitelist,json=unrestrictedPoolCreatorWhitelist,proto3" json:"unrestricted_pool_creator_whitelist,omitempty" yaml:"unrestricted_pool_creator_whitelist"` } func (m *Params) Reset() { *m = Params{} } @@ -121,6 +126,13 @@ func (m *Params) GetIsPermissionlessPoolCreationEnabled() bool { return false } +func (m *Params) GetUnrestrictedPoolCreatorWhitelist() []string { + if m != nil { + return m.UnrestrictedPoolCreatorWhitelist + } + return nil +} + func init() { proto.RegisterType((*Params)(nil), "osmosis.concentratedliquidity.Params") } @@ -130,42 +142,45 @@ func init() { } var fileDescriptor_cd3784445b6f6ba7 = []byte{ - // 552 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xb1, 0x6f, 0xd3, 0x4e, - 0x14, 0xc7, 0xe3, 0x5f, 0xda, 0xe8, 0x57, 0x33, 0x61, 0x81, 0x70, 0x0a, 0xd8, 0x96, 0x91, 0x20, - 0x12, 0xd4, 0x16, 0x65, 0x02, 0x36, 0x13, 0x60, 0x01, 0x29, 0x38, 0xb0, 0x54, 0x48, 0xa7, 0xf3, - 0xf9, 0xea, 0x9c, 0x62, 0xfb, 0xb9, 0x77, 0x67, 0x20, 0xac, 0x08, 0x89, 0x91, 0x81, 0x81, 0x3f, - 0xa9, 0x63, 0x47, 0xc4, 0x60, 0x50, 0xb2, 0x31, 0xa1, 0xfc, 0x05, 0x28, 0x3e, 0x87, 0x26, 0x94, - 0x8a, 0x6e, 0xf7, 0xde, 0xf7, 0xf3, 0xde, 0xbd, 0xfb, 0xea, 0x9d, 0x7e, 0x13, 0x44, 0x06, 0x82, - 0x09, 0x9f, 0x40, 0x4e, 0x68, 0x2e, 0x39, 0x96, 0x34, 0xde, 0x49, 0xd9, 0x41, 0xc9, 0x62, 0x26, - 0x27, 0x7e, 0x81, 0x39, 0xce, 0x84, 0x57, 0x70, 0x90, 0x60, 0x5c, 0x6d, 0x60, 0x6f, 0x15, 0xfe, - 0xcd, 0x6e, 0x5f, 0x48, 0x20, 0x81, 0x9a, 0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 0xcb, 0xcc, 0x6a, 0xed, 0x05, 0x09, 0x93, 0xa3, 0x32, 0xf2, 0x08, 0x64, - 0x7e, 0xf3, 0x0f, 0x77, 0x52, 0x1c, 0x89, 0x65, 0xe0, 0xbf, 0xba, 0x7d, 0xd7, 0x7f, 0x73, 0xda, - 0x3f, 0x96, 0x93, 0x82, 0x8a, 0xa8, 0x53, 0x7b, 0x79, 0xe7, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x2d, 0x6c, 0x62, 0xc6, 0xf6, 0x03, 0x00, 0x00, + // 599 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0x41, 0x6b, 0xd4, 0x4e, + 0x18, 0xc6, 0x37, 0xff, 0xed, 0x7f, 0xb5, 0xf1, 0x64, 0x50, 0xcc, 0x56, 0x4d, 0x42, 0x0a, 0xba, + 0xa8, 0x4d, 0xb0, 0x9e, 0xd4, 0x5b, 0x5c, 0xf5, 0xa2, 0x50, 0x53, 0x45, 0x28, 0xc2, 0x30, 0x3b, + 0x99, 0x66, 0x87, 0x26, 0x79, 0xd3, 0x99, 0x89, 0x75, 0x05, 0x4f, 0x22, 0x78, 0xf4, 0xe0, 0xc1, + 0x8f, 0xd4, 0x63, 0x8f, 0xe2, 0x21, 0x4a, 0x7b, 0xf3, 0x22, 0xec, 0x27, 0x90, 0xce, 0x64, 0xdb, + 0xd4, 0x5a, 0xec, 0x2d, 0x33, 0xcf, 0xef, 0x7d, 0xe7, 0x99, 0x27, 0x2f, 0x63, 0xde, 0x04, 0x91, + 0x83, 0x60, 0x22, 0x24, 0x50, 0x10, 0x5a, 0x48, 0x8e, 0x25, 0x4d, 0x96, 0x32, 0xb6, 0x59, 0xb1, + 0x84, 0xc9, 0x49, 0x58, 0x62, 0x8e, 0x73, 0x11, 0x94, 0x1c, 0x24, 0x58, 0x57, 0x1b, 0x38, 0x68, + 0xc3, 0x07, 0xec, 0xc2, 0x85, 0x14, 0x52, 0x50, 0x64, 0xb8, 0xff, 0xa5, 0x8b, 0x16, 0xfa, 0x44, + 0x55, 0x21, 0x2d, 0xe8, 0x45, 0x23, 0x39, 0x29, 0x40, 0x9a, 0xd1, 0x50, 0xad, 0x46, 0xd5, 0x7a, + 0x98, 0x54, 0x1c, 0x4b, 0x06, 0x85, 0xd6, 0xfd, 0x5f, 0x3d, 0xb3, 0xb7, 0xa2, 0x0c, 0x58, 0x6b, + 0xe6, 0x25, 0x5c, 0xc9, 0x31, 0x70, 0xf6, 0x96, 0x26, 0x48, 0x32, 0xb2, 0x81, 0x44, 0x89, 0x09, + 0x2b, 0x52, 0xdb, 0xf0, 0xba, 0x83, 0xb9, 0xc8, 0x9f, 0xd6, 0xae, 0x33, 0xc1, 0x79, 0x76, 0xcf, + 0x3f, 0x01, 0xf4, 0xe3, 0x8b, 0x87, 0xca, 0x73, 0x46, 0x36, 0x56, 0xf5, 0xbe, 0xf5, 0xde, 0x30, + 0xfb, 0xad, 0x1a, 0x51, 0x72, 0x8a, 0x13, 0xb4, 0x8e, 0x89, 0x04, 0x2e, 0xec, 0xff, 0xbc, 0xee, + 0x60, 0x3e, 0x7a, 0xbc, 0x5d, 0xbb, 0x9d, 0x6f, 0xb5, 0x7b, 0x59, 0x5f, 0x40, 0x24, 0x1b, 0x01, + 0x83, 0x30, 0xc7, 0x72, 0x1c, 0x3c, 0xa1, 0x29, 0x26, 0x93, 0x21, 0x25, 0xd3, 0xda, 0xf5, 0x8e, + 0x39, 0x38, 0xda, 0xcd, 0x8f, 0x5b, 0xd7, 0x58, 0x55, 0xd2, 0x23, 0xad, 0x58, 0x9f, 0x0d, 0xd3, + 0x1d, 0xe1, 0x0c, 0x17, 0x84, 0x72, 0x24, 0xc6, 0x98, 0x53, 0x81, 0x38, 0xdd, 0xc2, 0x3c, 0x41, + 0x09, 0x13, 0x04, 0xaa, 0x42, 0xda, 0x5d, 0xcf, 0x18, 0xcc, 0x47, 0x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x35, 0x66, 0x92, 0x66, 0x4c, 0x48, 0xfb, 0x8c, 0x8a, 0x3e, 0x98, 0xd6, 0xee, 0x0d, + 0xed, 0xe2, 0x14, 0x45, 0x7e, 0xec, 0xb5, 0xa9, 0x83, 0xd3, 0x81, 0xbf, 0x9c, 0x21, 0xd1, 0xab, + 0xed, 0x5d, 0xc7, 0xd8, 0xd9, 0x75, 0x8c, 0x1f, 0xbb, 0x8e, 0xf1, 0x69, 0xcf, 0xe9, 0xec, 0xec, + 0x39, 0x9d, 0xaf, 0x7b, 0x4e, 0x67, 0x2d, 0x4a, 0x99, 0x1c, 0x57, 0xa3, 0x80, 0x40, 0x1e, 0x36, + 0xcf, 0xc0, 0x52, 0x86, 0x47, 0x62, 0xb6, 0x08, 0x5f, 0xdf, 0xbe, 0x1b, 0xbe, 0x39, 0xe9, 0x19, + 0x91, 0x93, 0x92, 0x8a, 0x51, 0x4f, 0xfd, 0xca, 0x3b, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x60, + 0x04, 0x89, 0xb4, 0x75, 0x04, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -188,6 +203,15 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.UnrestrictedPoolCreatorWhitelist) > 0 { + for iNdEx := len(m.UnrestrictedPoolCreatorWhitelist) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.UnrestrictedPoolCreatorWhitelist[iNdEx]) + copy(dAtA[i:], m.UnrestrictedPoolCreatorWhitelist[iNdEx]) + i = encodeVarintParams(dAtA, i, uint64(len(m.UnrestrictedPoolCreatorWhitelist[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } if m.IsPermissionlessPoolCreationEnabled { i-- if m.IsPermissionlessPoolCreationEnabled { @@ -311,6 +335,12 @@ func (m *Params) Size() (n int) { if m.IsPermissionlessPoolCreationEnabled { n += 2 } + if len(m.UnrestrictedPoolCreatorWhitelist) > 0 { + for _, s := range m.UnrestrictedPoolCreatorWhitelist { + l = len(s) + n += 1 + l + sovParams(uint64(l)) + } + } return n } @@ -581,6 +611,38 @@ func (m *Params) Unmarshal(dAtA []byte) error { } } m.IsPermissionlessPoolCreationEnabled = bool(v != 0) + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UnrestrictedPoolCreatorWhitelist", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UnrestrictedPoolCreatorWhitelist = append(m.UnrestrictedPoolCreatorWhitelist, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) From c2493177d95e91aec6f0d9a188f9270bdf014a77 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 17 Sep 2023 13:48:45 +0800 Subject: [PATCH 02/12] fix params setting --- x/concentrated-liquidity/pool.go | 33 +++++++++++++++---- x/concentrated-liquidity/pool_test.go | 40 +++++++++++++++++++++--- x/concentrated-liquidity/types/params.go | 2 ++ 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index 9deb9af1705..e944c53ee89 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -44,16 +44,37 @@ func (k Keeper) InitializePool(ctx sdk.Context, poolI poolmanagertypes.PoolI, cr quoteAsset := concentratedPool.GetToken1() poolManagerParams := k.poolmanagerKeeper.GetParams(ctx) - if !k.validateTickSpacing(params, tickSpacing) { - return types.UnauthorizedTickSpacingError{ProvidedTickSpacing: tickSpacing, AuthorizedTickSpacings: params.AuthorizedTickSpacing} + bypassRestrictions := false + + poolmanagerModuleAcc := k.accountKeeper.GetModuleAccount(ctx, poolmanagertypes.ModuleName).GetAddress() + + // allow pool mananger module account to bypass restrictions (i.e. gov prop) + if creatorAddress.Equals(poolmanagerModuleAcc) { + bypassRestrictions = true } - if !k.validateSpreadFactor(params, spreadFactor) { - return types.UnauthorizedSpreadFactorError{ProvidedSpreadFactor: spreadFactor, AuthorizedSpreadFactors: params.AuthorizedSpreadFactors} + // allow whitelisted pool creators to bypass restrictions + if !bypassRestrictions { + for _, addr := range params.UnrestrictedPoolCreatorWhitelist { + // okay to use MustAccAddressFromBech32 because already validated in params + if sdk.MustAccAddressFromBech32(addr).Equals(creatorAddress) { + bypassRestrictions = true + } + } } - if !validateAuthorizedQuoteDenoms(quoteAsset, poolManagerParams.AuthorizedQuoteDenoms) { - return types.UnauthorizedQuoteDenomError{ProvidedQuoteDenom: quoteAsset, AuthorizedQuoteDenoms: poolManagerParams.AuthorizedQuoteDenoms} + if !bypassRestrictions { + if !k.validateTickSpacing(params, tickSpacing) { + return types.UnauthorizedTickSpacingError{ProvidedTickSpacing: tickSpacing, AuthorizedTickSpacings: params.AuthorizedTickSpacing} + } + + if !k.validateSpreadFactor(params, spreadFactor) { + return types.UnauthorizedSpreadFactorError{ProvidedSpreadFactor: spreadFactor, AuthorizedSpreadFactors: params.AuthorizedSpreadFactors} + } + + if !validateAuthorizedQuoteDenoms(quoteAsset, poolManagerParams.AuthorizedQuoteDenoms) { + return types.UnauthorizedQuoteDenomError{ProvidedQuoteDenom: quoteAsset, AuthorizedQuoteDenoms: poolManagerParams.AuthorizedQuoteDenoms} + } } if err := k.createSpreadRewardAccumulator(ctx, poolId); err != nil { diff --git a/x/concentrated-liquidity/pool_test.go b/x/concentrated-liquidity/pool_test.go index 80cd46917a4..706012db5e8 100644 --- a/x/concentrated-liquidity/pool_test.go +++ b/x/concentrated-liquidity/pool_test.go @@ -40,12 +40,15 @@ func (s *KeeperTestSuite) TestInitializePool() { validCreatorAddress := s.TestAccs[0] + poolmanagerModuleAccount := s.App.AccountKeeper.GetModuleAccount(s.Ctx, poolmanagertypes.ModuleName).GetAddress() + tests := []struct { - name string - poolI poolmanagertypes.PoolI - authorizedDenomsOverwrite []string - creatorAddress sdk.AccAddress - expectedErr error + name string + poolI poolmanagertypes.PoolI + authorizedDenomsOverwrite []string + unrestrictedPoolCreatorWhitelist []string + creatorAddress sdk.AccAddress + expectedErr error }{ { name: "Happy path", @@ -79,6 +82,23 @@ func (s *KeeperTestSuite) TestInitializePool() { creatorAddress: validCreatorAddress, expectedErr: types.UnauthorizedQuoteDenomError{ProvidedQuoteDenom: USDC, AuthorizedQuoteDenoms: []string{"otherDenom"}}, }, + { + name: "bypass check because poolmanager module account", + poolI: validPoolI, + authorizedDenomsOverwrite: []string{"otherDenom"}, + // despite the quote denom not being authorized, will still + // pass because its coming from the poolmanager module account + creatorAddress: poolmanagerModuleAccount, + }, + { + name: "bypass check because of whitelisted bypass", + poolI: validPoolI, + authorizedDenomsOverwrite: []string{"otherDenom"}, + // despite the quote denom not being authorized, will still + // pass because its coming from a whitelisted pool creator + unrestrictedPoolCreatorWhitelist: []string{validCreatorAddress.String()}, + creatorAddress: validCreatorAddress, + }, } for _, test := range tests { @@ -91,6 +111,16 @@ func (s *KeeperTestSuite) TestInitializePool() { s.App.PoolManagerKeeper.SetParams(s.Ctx, params) } + if len(test.unrestrictedPoolCreatorWhitelist) > 0 { + params := s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx) + params.UnrestrictedPoolCreatorWhitelist = test.unrestrictedPoolCreatorWhitelist + fmt.Println("setting") + fmt.Println(params.UnrestrictedPoolCreatorWhitelist) + s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, params) + fmt.Println("getting") + fmt.Println(s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx).UnrestrictedPoolCreatorWhitelist) + } + s.setListenerMockOnConcentratedLiquidityKeeper() // Method under test. diff --git a/x/concentrated-liquidity/types/params.go b/x/concentrated-liquidity/types/params.go index bb989278de5..9b6b666d072 100644 --- a/x/concentrated-liquidity/types/params.go +++ b/x/concentrated-liquidity/types/params.go @@ -18,6 +18,7 @@ var ( KeyAuthorizedQuoteDenoms = []byte("AuthorizedQuoteDenoms") KeyAuthorizedUptimes = []byte("AuthorizedUptimes") KeyIsPermisionlessPoolCreationEnabled = []byte("IsPermisionlessPoolCreationEnabled") + KeyUnrestrictedPoolCreatorWhitelist = []byte("UnrestrictedPoolCreatorWhitelist") _ paramtypes.ParamSet = &Params{} ) @@ -91,6 +92,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(KeyIsPermisionlessPoolCreationEnabled, &p.IsPermissionlessPoolCreationEnabled, validateIsPermissionLessPoolCreationEnabled), paramtypes.NewParamSetPair(KeyDiscountRate, &p.BalancerSharesRewardDiscount, validateBalancerSharesDiscount), paramtypes.NewParamSetPair(KeyAuthorizedUptimes, &p.AuthorizedUptimes, validateAuthorizedUptimes), + paramtypes.NewParamSetPair(KeyUnrestrictedPoolCreatorWhitelist, &p.UnrestrictedPoolCreatorWhitelist, validateUnrestrictedPoolCreatorWhitelist), } } From c59a19181cb62697f68e825f262d88d1a047d216 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 17 Sep 2023 16:57:18 +0800 Subject: [PATCH 03/12] add param to newParams function --- x/concentrated-liquidity/types/params.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/concentrated-liquidity/types/params.go b/x/concentrated-liquidity/types/params.go index 9b6b666d072..c21e88f2f5c 100644 --- a/x/concentrated-liquidity/types/params.go +++ b/x/concentrated-liquidity/types/params.go @@ -28,7 +28,7 @@ func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } -func NewParams(authorizedTickSpacing []uint64, authorizedSpreadFactors []osmomath.Dec, discountRate osmomath.Dec, authorizedQuoteDenoms []string, authorizedUptimes []time.Duration, isPermissionlessPoolCreationEnabled bool) Params { +func NewParams(authorizedTickSpacing []uint64, authorizedSpreadFactors []osmomath.Dec, discountRate osmomath.Dec, authorizedQuoteDenoms []string, authorizedUptimes []time.Duration, isPermissionlessPoolCreationEnabled bool, unrestrictedPoolCreatorWhitelist []string) Params { return Params{ AuthorizedTickSpacing: authorizedTickSpacing, AuthorizedSpreadFactors: authorizedSpreadFactors, @@ -36,6 +36,7 @@ func NewParams(authorizedTickSpacing []uint64, authorizedSpreadFactors []osmomat BalancerSharesRewardDiscount: discountRate, AuthorizedUptimes: authorizedUptimes, IsPermissionlessPoolCreationEnabled: isPermissionlessPoolCreationEnabled, + UnrestrictedPoolCreatorWhitelist: unrestrictedPoolCreatorWhitelist, } } From 2f4701e548de20532ad4785513eb0a3e62baa41a Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 17 Sep 2023 19:04:19 +0800 Subject: [PATCH 04/12] refactored where validate permissionless is checked --- tests/mocks/pool_module.go | 14 -------------- x/concentrated-liquidity/keeper.go | 6 +++--- x/concentrated-liquidity/keeper_test.go | 4 ++-- x/concentrated-liquidity/pool.go | 4 ++++ x/cosmwasmpool/pool_module.go | 6 ------ x/gamm/keeper/keeper.go | 6 ------ x/poolmanager/create_pool.go | 12 +++++------- x/poolmanager/types/expected_keepers.go | 4 ---- 8 files changed, 14 insertions(+), 42 deletions(-) diff --git a/tests/mocks/pool_module.go b/tests/mocks/pool_module.go index 7822b08077d..1eb50a9f949 100644 --- a/tests/mocks/pool_module.go +++ b/tests/mocks/pool_module.go @@ -393,20 +393,6 @@ func (mr *MockPoolModuleIMockRecorder) SwapExactAmountOut(ctx, sender, pool, tok return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SwapExactAmountOut", reflect.TypeOf((*MockPoolModuleI)(nil).SwapExactAmountOut), ctx, sender, pool, tokenInDenom, tokenInMaxAmount, tokenOut, spreadFactor) } -// ValidatePermissionlessPoolCreationEnabled mocks base method. -func (m *MockPoolModuleI) ValidatePermissionlessPoolCreationEnabled(ctx types.Context) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ValidatePermissionlessPoolCreationEnabled", ctx) - ret0, _ := ret[0].(error) - return ret0 -} - -// ValidatePermissionlessPoolCreationEnabled indicates an expected call of ValidatePermissionlessPoolCreationEnabled. -func (mr *MockPoolModuleIMockRecorder) ValidatePermissionlessPoolCreationEnabled(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatePermissionlessPoolCreationEnabled", reflect.TypeOf((*MockPoolModuleI)(nil).ValidatePermissionlessPoolCreationEnabled), ctx) -} - // MockPoolIncentivesKeeperI is a mock of PoolIncentivesKeeperI interface. type MockPoolIncentivesKeeperI struct { ctrl *gomock.Controller diff --git a/x/concentrated-liquidity/keeper.go b/x/concentrated-liquidity/keeper.go index ba80b6094d7..eb721d56a75 100644 --- a/x/concentrated-liquidity/keeper.go +++ b/x/concentrated-liquidity/keeper.go @@ -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. diff --git a/x/concentrated-liquidity/keeper_test.go b/x/concentrated-liquidity/keeper_test.go index 7e67b5253e8..471a68bcf7b 100644 --- a/x/concentrated-liquidity/keeper_test.go +++ b/x/concentrated-liquidity/keeper_test.go @@ -433,7 +433,7 @@ 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. - 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() @@ -441,7 +441,7 @@ func (s *KeeperTestSuite) TestValidatePermissionlessPoolCreationEnabled() { 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()) { diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index e944c53ee89..9588bf4c196 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -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} } diff --git a/x/cosmwasmpool/pool_module.go b/x/cosmwasmpool/pool_module.go index 52d05c381fa..7c492cc8f7e 100644 --- a/x/cosmwasmpool/pool_module.go +++ b/x/cosmwasmpool/pool_module.go @@ -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: diff --git a/x/gamm/keeper/keeper.go b/x/gamm/keeper/keeper.go index ad3b1d8c3d7..6ebf75434f0 100644 --- a/x/gamm/keeper/keeper.go +++ b/x/gamm/keeper/keeper.go @@ -93,12 +93,6 @@ func (k Keeper) setParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } -// 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 diff --git a/x/poolmanager/create_pool.go b/x/poolmanager/create_pool.go index 0dfd0c00114..70e1615641c 100644 --- a/x/poolmanager/create_pool.go +++ b/x/poolmanager/create_pool.go @@ -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. @@ -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) diff --git a/x/poolmanager/types/expected_keepers.go b/x/poolmanager/types/expected_keepers.go index d182992888b..72d54b999bc 100644 --- a/x/poolmanager/types/expected_keepers.go +++ b/x/poolmanager/types/expected_keepers.go @@ -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) } From 3fb7fa036c85cdc417cccbe31391b2432b573060 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 17 Sep 2023 23:54:03 +0900 Subject: [PATCH 05/12] add tests --- x/concentrated-liquidity/pool_test.go | 47 ++++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/x/concentrated-liquidity/pool_test.go b/x/concentrated-liquidity/pool_test.go index 706012db5e8..2779eb65b0d 100644 --- a/x/concentrated-liquidity/pool_test.go +++ b/x/concentrated-liquidity/pool_test.go @@ -43,18 +43,39 @@ func (s *KeeperTestSuite) TestInitializePool() { poolmanagerModuleAccount := s.App.AccountKeeper.GetModuleAccount(s.Ctx, poolmanagertypes.ModuleName).GetAddress() tests := []struct { - name string - poolI poolmanagertypes.PoolI - authorizedDenomsOverwrite []string - unrestrictedPoolCreatorWhitelist []string - creatorAddress sdk.AccAddress - expectedErr error + name string + poolI poolmanagertypes.PoolI + authorizedDenomsOverwrite []string + unrestrictedPoolCreatorWhitelist []string + permissionlessPoolCreationDisabled bool + creatorAddress sdk.AccAddress + expectedErr error }{ { name: "Happy path", poolI: validPoolI, creatorAddress: validCreatorAddress, }, + { + name: "Permissionless pool creation disabled", + poolI: validPoolI, + permissionlessPoolCreationDisabled: true, + creatorAddress: validCreatorAddress, + expectedErr: types.ErrPermissionlessPoolCreationDisabled, + }, + { + name: "bypass disabled permissionless pool creation check because poolmanager module account", + poolI: validPoolI, + permissionlessPoolCreationDisabled: true, + creatorAddress: poolmanagerModuleAccount, + }, + { + name: "bypass disabled permissionless pool creation check because of whitelisted bypass", + poolI: validPoolI, + permissionlessPoolCreationDisabled: true, + creatorAddress: validCreatorAddress, + unrestrictedPoolCreatorWhitelist: []string{validCreatorAddress.String()}, + }, { name: "Wrong pool type: empty pool interface that doesn't implement ConcentratedPoolExtension", poolI: invalidPoolI, @@ -83,7 +104,7 @@ func (s *KeeperTestSuite) TestInitializePool() { expectedErr: types.UnauthorizedQuoteDenomError{ProvidedQuoteDenom: USDC, AuthorizedQuoteDenoms: []string{"otherDenom"}}, }, { - name: "bypass check because poolmanager module account", + name: "bypass unauthorized quote denom check because poolmanager module account", poolI: validPoolI, authorizedDenomsOverwrite: []string{"otherDenom"}, // despite the quote denom not being authorized, will still @@ -91,7 +112,7 @@ func (s *KeeperTestSuite) TestInitializePool() { creatorAddress: poolmanagerModuleAccount, }, { - name: "bypass check because of whitelisted bypass", + name: "bypass unauthorized quote denom check because of whitelisted bypass", poolI: validPoolI, authorizedDenomsOverwrite: []string{"otherDenom"}, // despite the quote denom not being authorized, will still @@ -105,6 +126,12 @@ func (s *KeeperTestSuite) TestInitializePool() { s.Run(test.name, func() { s.SetupTest() + if test.permissionlessPoolCreationDisabled { + params := s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx) + params.IsPermissionlessPoolCreationEnabled = false + s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, params) + } + if len(test.authorizedDenomsOverwrite) > 0 { params := s.App.PoolManagerKeeper.GetParams(s.Ctx) params.AuthorizedQuoteDenoms = test.authorizedDenomsOverwrite @@ -114,11 +141,7 @@ func (s *KeeperTestSuite) TestInitializePool() { if len(test.unrestrictedPoolCreatorWhitelist) > 0 { params := s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx) params.UnrestrictedPoolCreatorWhitelist = test.unrestrictedPoolCreatorWhitelist - fmt.Println("setting") - fmt.Println(params.UnrestrictedPoolCreatorWhitelist) s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, params) - fmt.Println("getting") - fmt.Println(s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx).UnrestrictedPoolCreatorWhitelist) } s.setListenerMockOnConcentratedLiquidityKeeper() From 0ff556ff32e6c49988f8c7daa5a21e491008e8a8 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Mon, 18 Sep 2023 00:04:25 +0900 Subject: [PATCH 06/12] remove todos --- x/poolmanager/create_pool.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/poolmanager/create_pool.go b/x/poolmanager/create_pool.go index 70e1615641c..fa5e128d138 100644 --- a/x/poolmanager/create_pool.go +++ b/x/poolmanager/create_pool.go @@ -31,7 +31,6 @@ func (k Keeper) validateCreatedPool(poolId uint64, pool types.PoolI) error { // - Setting metadata for the shares func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, error) { // Check that the pool type exists - // TODO: see if we can get rid of this check poolType := msg.GetPoolType() _, ok := k.routes[poolType] if !ok { @@ -53,8 +52,6 @@ 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) From 3d35de563fcf0b9b56348280044fe5881f3fd868 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Mon, 18 Sep 2023 00:58:12 +0900 Subject: [PATCH 07/12] lint --- x/concentrated-liquidity/keeper.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x/concentrated-liquidity/keeper.go b/x/concentrated-liquidity/keeper.go index eb721d56a75..efc2a8dfdec 100644 --- a/x/concentrated-liquidity/keeper.go +++ b/x/concentrated-liquidity/keeper.go @@ -121,10 +121,7 @@ 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) bool { - if !k.GetParams(ctx).IsPermissionlessPoolCreationEnabled { - return false - } - return true + return !k.GetParams(ctx).IsPermissionlessPoolCreationEnabled } // GetAuthorizedQuoteDenoms gets the authorized quote denoms from the poolmanager keeper. From 1a18bf67b42390ab5bfcff73e064b2f62955caab Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Mon, 18 Sep 2023 05:55:05 +0900 Subject: [PATCH 08/12] Apply suggestions from code review Co-authored-by: Roman --- x/concentrated-liquidity/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/concentrated-liquidity/keeper.go b/x/concentrated-liquidity/keeper.go index efc2a8dfdec..e8c7361c819 100644 --- a/x/concentrated-liquidity/keeper.go +++ b/x/concentrated-liquidity/keeper.go @@ -120,8 +120,8 @@ 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) bool { - return !k.GetParams(ctx).IsPermissionlessPoolCreationEnabled +func (k Keeper) IsPermissionlessPoolCreationEnabled(ctx sdk.Context) bool { + return k.GetParams(ctx).IsPermissionlessPoolCreationEnabled } // GetAuthorizedQuoteDenoms gets the authorized quote denoms from the poolmanager keeper. From 9382028fd94144ff5e2317cd8de52e80a1f575be Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Mon, 18 Sep 2023 05:56:21 +0900 Subject: [PATCH 09/12] fix tests --- x/concentrated-liquidity/keeper.go | 2 +- x/concentrated-liquidity/keeper_test.go | 6 +++--- x/concentrated-liquidity/pool.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/concentrated-liquidity/keeper.go b/x/concentrated-liquidity/keeper.go index e8c7361c819..39a508c5ad2 100644 --- a/x/concentrated-liquidity/keeper.go +++ b/x/concentrated-liquidity/keeper.go @@ -118,7 +118,7 @@ func (k *Keeper) SetListeners(listeners types.ConcentratedLiquidityListeners) *K return k } -// ValidatePermissionlessPoolCreationEnabled returns nil if permissionless pool creation in the module is enabled. +// IsPermissionlessPoolCreationEnabled returns nil if permissionless pool creation in the module is enabled. // Otherwise, returns an error. func (k Keeper) IsPermissionlessPoolCreationEnabled(ctx sdk.Context) bool { return k.GetParams(ctx).IsPermissionlessPoolCreationEnabled diff --git a/x/concentrated-liquidity/keeper_test.go b/x/concentrated-liquidity/keeper_test.go index 471a68bcf7b..c007d895708 100644 --- a/x/concentrated-liquidity/keeper_test.go +++ b/x/concentrated-liquidity/keeper_test.go @@ -430,10 +430,10 @@ func (s *KeeperTestSuite) AddBlockTime(timeToAdd time.Duration) { s.Ctx = s.Ctx.WithBlockTime(s.Ctx.BlockTime().Add(timeToAdd)) } -func (s *KeeperTestSuite) TestValidatePermissionlessPoolCreationEnabled() { +func (s *KeeperTestSuite) TestIsPermissionlessPoolCreationEnabled() { // Normally, by default, permissionless pool creation is disabled. // SetupTest, however, calls SetupConcentratedLiquidityDenomsAndPoolCreation which enables permissionless pool creation. - s.Require().True(s.App.ConcentratedLiquidityKeeper.ValidatePermissionlessPoolCreationEnabled(s.Ctx)) + s.Require().True(s.App.ConcentratedLiquidityKeeper.IsPermissionlessPoolCreationEnabled(s.Ctx)) // Disable permissionless pool creation. defaultParams := types.DefaultParams() @@ -441,7 +441,7 @@ func (s *KeeperTestSuite) TestValidatePermissionlessPoolCreationEnabled() { s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, defaultParams) // Validate that permissionless pool creation is disabled. - s.Require().False(s.App.ConcentratedLiquidityKeeper.ValidatePermissionlessPoolCreationEnabled(s.Ctx)) + s.Require().False(s.App.ConcentratedLiquidityKeeper.IsPermissionlessPoolCreationEnabled(s.Ctx)) } func (s *KeeperTestSuite) runMultipleAuthorizedUptimes(tests func()) { diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index 9588bf4c196..da046a09fd6 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -64,7 +64,7 @@ func (k Keeper) InitializePool(ctx sdk.Context, poolI poolmanagertypes.PoolI, cr } if !bypassRestrictions { - if !k.ValidatePermissionlessPoolCreationEnabled(ctx) { + if !k.IsPermissionlessPoolCreationEnabled(ctx) { return types.ErrPermissionlessPoolCreationDisabled } From 20cc46cd41c821ceb021b9ce5ba2c5aed28ac6dd Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Fri, 22 Sep 2023 19:34:17 +0900 Subject: [PATCH 10/12] Update x/concentrated-liquidity/keeper.go Co-authored-by: Roman --- x/concentrated-liquidity/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/concentrated-liquidity/keeper.go b/x/concentrated-liquidity/keeper.go index 39a508c5ad2..5d8b7aaf8e8 100644 --- a/x/concentrated-liquidity/keeper.go +++ b/x/concentrated-liquidity/keeper.go @@ -118,8 +118,8 @@ func (k *Keeper) SetListeners(listeners types.ConcentratedLiquidityListeners) *K return k } -// IsPermissionlessPoolCreationEnabled returns nil if permissionless pool creation in the module is enabled. -// Otherwise, returns an error. +// IsPermissionlessPoolCreationEnabled returns true if permissionless pool creation in the module is enabled. +// Otherwise, returns false func (k Keeper) IsPermissionlessPoolCreationEnabled(ctx sdk.Context) bool { return k.GetParams(ctx).IsPermissionlessPoolCreationEnabled } From 98c32c334a47e634f7fad6604f5d3994b1fa2f4a Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 24 Sep 2023 06:14:23 -0400 Subject: [PATCH 11/12] Apply suggestions from code review --- x/concentrated-liquidity/keeper_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/concentrated-liquidity/keeper_test.go b/x/concentrated-liquidity/keeper_test.go index c007d895708..9917c771649 100644 --- a/x/concentrated-liquidity/keeper_test.go +++ b/x/concentrated-liquidity/keeper_test.go @@ -431,8 +431,7 @@ func (s *KeeperTestSuite) AddBlockTime(timeToAdd time.Duration) { } func (s *KeeperTestSuite) TestIsPermissionlessPoolCreationEnabled() { - // Normally, by default, permissionless pool creation is disabled. - // SetupTest, however, calls SetupConcentratedLiquidityDenomsAndPoolCreation which enables permissionless pool creation. + // Permissionless pool creation is enabled in tests by default s.Require().True(s.App.ConcentratedLiquidityKeeper.IsPermissionlessPoolCreationEnabled(s.Ctx)) // Disable permissionless pool creation. From fa1080929376316e493382bd9b7ce441661b5142 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 24 Sep 2023 06:28:30 -0400 Subject: [PATCH 12/12] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db93b1bfa4a..71293bad0b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#6309](https://github.com/osmosis-labs/osmosis/pull/6309) Add Cosmwasm Pool Queries to Stargate Query * [#6476](https://github.com/osmosis-labs/osmosis/pull/6476) band-aid state export fix for cwpool gauges * [#6493](https://github.com/osmosis-labs/osmosis/pull/6493) Add PoolManager Params query to Stargate Whitelist +* [#6421](https://github.com/osmosis-labs/osmosis/pull/6421) Moves ValidatePermissionlessPoolCreationEnabled out of poolmanager module ### Features