Skip to content

Commit

Permalink
feat: CL permissionless pool creation param (#4952)
Browse files Browse the repository at this point in the history
* feat: CL permissionless pool creation param and gov prop

* create pool

* expose query for getting balancer and cl link

* fix e2e test to update the new param

* basic e2e test for canonical pool

* updates

* doc update

* typos in e2e

* updates

* fix

* updates

* Update tests/e2e/e2e_test.go

Co-authored-by: Adam Tucker <[email protected]>

* rename to ValidatePermissionlessPoolCreationEnabled

* updates

* Update x/gamm/keeper/keeper.go

Co-authored-by: Matt, Park <[email protected]>

* updates

* update localosmosis

---------

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Matt, Park <[email protected]>
  • Loading branch information
3 people authored Apr 24, 2023
1 parent 44cfb22 commit d6e800e
Show file tree
Hide file tree
Showing 28 changed files with 1,003 additions and 259 deletions.
6 changes: 4 additions & 2 deletions app/apptesting/concentrated_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ func (s *KeeperTestHelper) WithdrawFullRangePosition(pool types.ConcentratedPool
s.Require().NoError(err)
}

// SetupDefaultConcentratedLiquidityAuthorizedQuoteDenoms sets up the default authorized quote denoms.
// SetupConcentratedLiquidityDenomsAndPoolCreation sets up the default authorized quote denoms.
// Additionally, enables permissionless pool creation.
// This is to overwrite the default params set in concentrated liquidity genesis to account for the test cases that
// used various denoms before the authorized quote denoms were introduced.
func (s *KeeperTestHelper) SetupDefaultConcentratedLiquidityAuthorizedQuoteDenoms() {
func (s *KeeperTestHelper) SetupConcentratedLiquidityDenomsAndPoolCreation() {
// modify authorized quote denoms to include test denoms.
defaultParams := types.DefaultParams()
defaultParams.IsPermissionlessPoolCreationEnabled = true
defaultParams.AuthorizedQuoteDenoms = append(defaultParams.AuthorizedQuoteDenoms, ETH, USDC, BAR, BAZ, FOO, UOSMO, STAKE)
s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, defaultParams)
}
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *KeeperTestHelper) Setup() {

s.SetEpochStartTime()
s.TestAccs = CreateRandomAccounts(3)
s.SetupDefaultConcentratedLiquidityAuthorizedQuoteDenoms()
s.SetupConcentratedLiquidityDenomsAndPoolCreation()
}

func (s *KeeperTestHelper) SetupTestForInitGenesis() {
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v16/concentrated_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func createConcentratedPoolFromCFMM(ctx sdk.Context, cfmmPoolIdToLinkWith uint64

swapFee := cfmmPool.GetSwapFee(ctx)

createPoolMsg := clmodel.NewMsgCreateConcentratedPool(poolCreatorAddress, desiredDenom0, denom1, tickSpacing, swapFee)
createPoolMsg := clmodel.NewMsgCreateConcentratedPool(poolCreatorAddress, desiredDenom0, denom1, TickSpacing, swapFee)
concentratedPool, err := poolmanagerKeeper.CreateConcentratedPoolAsPoolManager(ctx, createPoolMsg)
if err != nil {
return nil, err
Expand Down
5 changes: 0 additions & 5 deletions app/upgrades/v16/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
)

const (
DaiOsmoPoolId = daiOsmoPoolId
DesiredDenom0 = desiredDenom0
)

var (
AuthorizedQuoteDenoms = authorizedQuoteDenoms
)
Expand Down
16 changes: 12 additions & 4 deletions app/upgrades/v16/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ const (
// https://app.osmosis.zone/pool/674
// Note, new concentrated liquidity pool
// swap fee is initialized to be the same as the balancers pool swap fee of 0.2%.
daiOsmoPoolId = uint64(674)
DaiOsmoPoolId = uint64(674)
// Denom0 translates to a base asset while denom1 to a quote asset
// We want quote asset to be DAI so that when the limit orders on ticks
// are implemented, we have tick spacing in terms of DAI as the quote.
desiredDenom0 = "uosmo"
DesiredDenom0 = "uosmo"
// TODO: confirm pre-launch.
tickSpacing = 1
TickSpacing = 1

// isPermissionlessPoolCreationEnabledCL is a boolean that determines if
// concentrated liquidity pools can be created via message. At launch,
// we consider allowing only governance to create pools, and then later
// allowing permissionless pool creation by switching this flag to true
// with a governance proposal.
IsPermissionlessPoolCreationEnabledCL = false
)

var (
Expand Down Expand Up @@ -57,9 +64,10 @@ func CreateUpgradeHandler(
// for visibility of the final configuration.
defaultConcentratedLiquidityParams := keepers.ConcentratedLiquidityKeeper.GetParams(ctx)
defaultConcentratedLiquidityParams.AuthorizedQuoteDenoms = authorizedQuoteDenoms
defaultConcentratedLiquidityParams.IsPermissionlessPoolCreationEnabled = IsPermissionlessPoolCreationEnabledCL
keepers.ConcentratedLiquidityKeeper.SetParams(ctx, defaultConcentratedLiquidityParams)

if err := createCanonicalConcentratedLiquidityPoolAndMigrationLink(ctx, daiOsmoPoolId, desiredDenom0, keepers); err != nil {
if err := createCanonicalConcentratedLiquidityPoolAndMigrationLink(ctx, DaiOsmoPoolId, DesiredDenom0, keepers); err != nil {
return nil, err
}

Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v16/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
// Check authorized denoms are set correctly.
params := suite.App.ConcentratedLiquidityKeeper.GetParams(suite.Ctx)
suite.Require().EqualValues(params.AuthorizedQuoteDenoms, v16.AuthorizedQuoteDenoms)

// Permissionless pool creation is disabled.
suite.Require().False(params.IsPermissionlessPoolCreationEnabled)
},
func() {
},
Expand Down
9 changes: 9 additions & 0 deletions proto/osmosis/concentrated-liquidity/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ message Params {
// prices in terms of token1 (quote asset) that are easy to reason about.
repeated string authorized_quote_denoms = 4
[ (gogoproto.moretags) = "yaml:\"authorized_quote_denoms\"" ];

// is_permissionless_pool_creation_enabled is a boolean that determines if
// concentrated liquidity pools can be created via message. At launch,
// we consider allowing only governance to create pools, and then later
// allowing permissionless pool creation by switching this flag to true
// with a governance proposal.
bool is_permissionless_pool_creation_enabled = 5
[ (gogoproto.moretags) =
"yaml:\"is_permissionless_pool_creation_enabled\"" ];
}
18 changes: 18 additions & 0 deletions proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ service Query {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_out";
}

// ConcentratedPoolIdLinkFromBalancer returns the pool id of the concentrated
// pool that is linked with the given CFMM pool.
rpc ConcentratedPoolIdLinkFromCFMM(QueryConcentratedPoolIdLinkFromCFMMRequest)
returns (QueryConcentratedPoolIdLinkFromCFMMResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/concentrated_pool_id_link_from_cfmm/"
"{cfmm_pool_id}";
}
}

//=============================== Pool
Expand Down Expand Up @@ -318,3 +327,12 @@ message QueryTotalLiquidityResponse {
(gogoproto.nullable) = false
];
}

//=============================== QueryConcentratedPoolIdLinkFromCFMM
message QueryConcentratedPoolIdLinkFromCFMMRequest {
uint64 cfmm_pool_id = 1 [ (gogoproto.moretags) = "yaml:\"cfmm_pool_id\"" ];
}

message QueryConcentratedPoolIdLinkFromCFMMResponse {
uint64 concentrated_pool_id = 1;
}
2 changes: 1 addition & 1 deletion tests/cl-genesis-positions/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/cosmos/cosmos-sdk v0.47.1
github.com/ignite/cli v0.23.0
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e4304
github.com/osmosis-labs/osmosis/v15 v15.0.0-20230421191321-d8c055983934
github.com/osmosis-labs/osmosis/v15 v15.0.0-20230424012707-075958555f2f
github.com/tendermint/tendermint v0.34.26
)

Expand Down
4 changes: 2 additions & 2 deletions tests/cl-genesis-positions/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e430
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e4304/go.mod h1:/h3CZIo25kMrM4Ojm7qBgMxKofTVwOycVWSa4rhEsaM=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230411200859-ae3065d0ca05 h1:fqVGxZPgUWuYWxVcMxHz5vrDV/aoxGJ7Kt0J4Vu/bsY=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230411200859-ae3065d0ca05/go.mod h1:zyBrzl2rsZWGbOU+/1hzA+xoQlCshzZuHe/5mzdb/zo=
github.com/osmosis-labs/osmosis/v15 v15.0.0-20230421191321-d8c055983934 h1:wfL4T0LZ4cFezim6L/NsOjD892pKwC09peCo7+Ub30g=
github.com/osmosis-labs/osmosis/v15 v15.0.0-20230421191321-d8c055983934/go.mod h1:qME1XII3skASTWVguqUbkTUiQw4R5Mr6r1NvZeA59H8=
github.com/osmosis-labs/osmosis/v15 v15.0.0-20230424012707-075958555f2f h1:4/JA+dnV06Lytpar7Bc6QB3q/F52pJIDNjLwqIGlX+o=
github.com/osmosis-labs/osmosis/v15 v15.0.0-20230424012707-075958555f2f/go.mod h1:DuLI8JcQ1zy2gImOve1G+HjHiqQmfbSM4qDg93aUM5Y=
github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo=
github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304/go.mod h1:yPWoJTj5RKrXKUChAicp+G/4Ni/uVEpp27mi/FF/L9c=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 h1:A0SwZgp4bmJFbivYJc8mmVhMjrr3EdUZluBYFke11+w=
Expand Down
8 changes: 5 additions & 3 deletions tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ func (n *NodeConfig) CollectFees(from, positionIds string) {

// CreateConcentratedPool creates a concentrated pool.
// Returns pool id of newly created pool on success
func (n *NodeConfig) CreateConcentratedPool(from, denom1, denom2 string, tickSpacing uint64, swapFee string) uint64 {
func (n *NodeConfig) CreateConcentratedPool(from, denom1, denom2 string, tickSpacing uint64, swapFee string) (uint64, error) {
n.LogActionF("creating concentrated pool")

cmd := []string{"osmosisd", "tx", "concentratedliquidity", "create-concentrated-pool", denom1, denom2, fmt.Sprintf("%d", tickSpacing), swapFee, fmt.Sprintf("--from=%s", from)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
if err != nil {
return 0, err
}

poolID := n.QueryNumPools()
n.LogActionF("successfully created concentrated pool with ID %d", poolID)
return poolID
return poolID, nil
}

// CreateConcentratedPosition creates a concentrated position from [lowerTick; upperTick] in pool with id of poolId
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/configurer/chain/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,19 @@ func (n *NodeConfig) QueryCurrentEpoch(identifier string) int64 {
return response.CurrentEpoch
}

func (n *NodeConfig) QueryConcentratedPooIdLinkFromCFMM(cfmmPoolId uint64) uint64 {
path := fmt.Sprintf("/osmosis/gamm/v1beta1/concentrated_pool_id_link_from_cfmm/%d", cfmmPoolId)

bz, err := n.QueryGRPCGateway(path)
require.NoError(n.t, err)

//nolint:staticcheck
var response gammtypes.QueryConcentratedPoolIdLinkFromCFMMResponse
err = util.Cdc.UnmarshalJSON(bz, &response)
require.NoError(n.t, err)
return response.ConcentratedPoolId
}

func (n *NodeConfig) QueryArithmeticTwapToNow(poolId uint64, baseAsset, quoteAsset string, startTime time.Time) (sdk.Dec, error) {
path := "osmosis/twap/v1beta1/ArithmeticTwapToNow"

Expand Down
Loading

0 comments on commit d6e800e

Please sign in to comment.