Skip to content

Commit

Permalink
feat: CreateCLPool & LinkCFMMtoCL pool into one gov-prop
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 committed Jul 26, 2023
1 parent 875b929 commit 957cf62
Show file tree
Hide file tree
Showing 18 changed files with 1,158 additions and 71 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#5534](https://github.com/osmosis-labs/osmosis/pull/5534) fix: fix the account number of x/tokenfactory module account
* [#5750](https://github.com/osmosis-labs/osmosis/pull/5750) feat: add cli commmand for converting proto structs to proto marshalled bytes
* [#5890](https://github.com/osmosis-labs/osmosis/pull/5890) feat: CreateCLPool & LinkCFMMtoCL pool into one gov-prop

### Minor improvements & Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var AppModuleBasics = []module.AppModuleBasic{
superfluidclient.UpdateUnpoolWhitelistProposalHandler,
gammclient.ReplaceMigrationRecordsProposalHandler,
gammclient.UpdateMigrationRecordsProposalHandler,
gammclient.CreateCLPoolAndLinkToCFMMProposalHandler,
clclient.CreateConcentratedLiquidityPoolProposalHandler,
clclient.TickSpacingDecreaseProposalHandler,
cwpoolclient.UploadCodeIdAndWhitelistProposalHandler,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
cosmossdk.io/errors v1.0.0-beta.7
github.com/CosmWasm/wasmd v0.31.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/cosmos-sdk v0.47.4
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-apps/modules/async-icq/v4 v4.0.0-20230524151648-c02fa46c2860
github.com/cosmos/ibc-go/v4 v4.3.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,6 @@ github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:Ylmch
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.20230629191111-f375469de8b6 h1:Kmkx5Rh72+LB8AL6dc6fZA+IVR0INu0YIiMF2ScDhaQ=
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230629191111-f375469de8b6/go.mod h1:JTym95/bqrSnG5MPcXr1YDhv43JdCeo3p+iDbazoX68=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230709024311-81c831b050de h1:W2lMduMgpNA5zheEIIialw08n1pWJ44Y4t2F924tpDU=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230709024311-81c831b050de/go.mod h1:Pl8Nzx6O6ow/+aqfMoMSz4hX+zz6RrnDYsooptECGxM=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230715164027-b45d8bd42434 h1:MXPrA3sDtqOHYUa9zl4HMGMW+IJwGMqUf6+Hl9nhrCA=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230715164027-b45d8bd42434/go.mod h1:Pl8Nzx6O6ow/+aqfMoMSz4hX+zz6RrnDYsooptECGxM=
github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo=
Expand Down
1 change: 1 addition & 0 deletions proto/osmosis/concentrated-liquidity/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package osmosis.concentratedliquidity.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/gamm/v1beta1/shared.proto";

option go_package = "github.com/osmosis-labs/osmosis/v16/x/concentrated-liquidity/types";

Expand Down
39 changes: 39 additions & 0 deletions proto/osmosis/gamm/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,42 @@ message UpdateMigrationRecordsProposal {
repeated BalancerToConcentratedPoolLink records = 3
[ (gogoproto.nullable) = false ];
}

message PoolRecordWithCFMMLink {
option (gogoproto.equal) = true;

string denom0 = 1 [ (gogoproto.moretags) = "yaml:\"denom0\"" ];
string denom1 = 2 [ (gogoproto.moretags) = "yaml:\"denom1\"" ];
uint64 tick_spacing = 3 [ (gogoproto.moretags) = "yaml:\"tick_spacing\"" ];
string exponent_at_price_one = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"exponent_at_price_one\"",
(gogoproto.nullable) = false
];
string spread_factor = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"spread_factor\"",
(gogoproto.nullable) = false
];
uint64 balancer_pool_id = 6
[ (gogoproto.moretags) = "yaml:\"balancer_pool_id\"" ];
}

// CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal is a gov Content type
// for creating concentrated liquidity pools and linking it to a CFMM pool.
message CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (amino.name) =
"osmosis/CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal";
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";

string title = 1;
string description = 2;

repeated PoolRecordWithCFMMLink pool_records_with_cfmm_link = 3 [
(gogoproto.moretags) = "yaml:\"create_cl_pool_and_link_to_cfmm\"",
(gogoproto.nullable) = false
];
}
1 change: 1 addition & 0 deletions x/concentrated-liquidity/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

clmodel "github.com/osmosis-labs/osmosis/v16/x/concentrated-liquidity/model"
"github.com/osmosis-labs/osmosis/v16/x/concentrated-liquidity/types"

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

Expand Down
78 changes: 40 additions & 38 deletions x/concentrated-liquidity/types/gov.pb.go

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

2 changes: 2 additions & 0 deletions x/gamm/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
FlagScalingFactors = "scaling-factors"

FlagMigrationRecords = "migration-records"

FlagPoolRecords = "pool-records"
)

type createBalancerPoolInputs struct {
Expand Down
134 changes: 134 additions & 0 deletions x/gamm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,59 @@ Ex) 2,4,1,5 -> [(Balancer 2, CL 4), (Balancer 1, CL 5)]
return cmd
}

// NewCmdSubmitUpdateMigrationRecordsProposal implements a command handler for update migration records proposal
func NewCmdSubmitCreateCLPoolAndLinkToCFMMProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "create-cl-pool-and-cfmm-link [flags]",
Args: cobra.ExactArgs(0),
Short: "Submit a create clpool and link to cfmm proposal",
Long: strings.TrimSpace(`Submit a update migration record proposal.
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
content, err := parseCreateConcentratedLiquidityPoolArgsToContent(cmd)
if err != nil {
return err
}

from := clientCtx.GetFromAddress()

depositStr, err := cmd.Flags().GetString(govcli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)
if err != nil {
return err
}

msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}

if err = msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

cmd.Flags().String(govcli.FlagTitle, "", "title of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal")
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal")
cmd.Flags().Bool(govcli.FlagIsExpedited, false, "If true, makes the proposal an expedited one")
cmd.Flags().String(govcli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")
cmd.Flags().String(FlagPoolRecords, "", "The pool records array")

return cmd
}

func BuildCreatePoolCmd(clientCtx client.Context, args []string, fs *flag.FlagSet) (sdk.Msg, error) {
poolType, err := fs.GetString(FlagPoolType)
if err != nil {
Expand Down Expand Up @@ -714,3 +767,84 @@ func parseUpdateMigrationRecordsArgsToContent(cmd *cobra.Command) (govtypes.Cont
}
return content, nil
}

func parseCreateConcentratedLiquidityPoolArgsToContent(cmd *cobra.Command) (govtypes.Content, error) {
title, err := cmd.Flags().GetString(govcli.FlagTitle)
if err != nil {
return nil, err
}

description, err := cmd.Flags().GetString(govcli.FlagDescription)
if err != nil {
return nil, err
}

poolRecordsWithCFMMLink, err := parsePoolRecordsWithCFMMLink(cmd)
if err != nil {
return nil, err
}

content := &types.CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal{
Title: title,
Description: description,
PoolRecordsWithCfmmLink: poolRecordsWithCFMMLink,
}

return content, nil
}

func parsePoolRecordsWithCFMMLink(cmd *cobra.Command) ([]types.PoolRecordWithCFMMLink, error) {
poolRecordsStr, err := cmd.Flags().GetString(FlagPoolRecords)
if err != nil {
return nil, err
}

poolRecordsWithCFMMLink := strings.Split(poolRecordsStr, ",")

if len(poolRecordsWithCFMMLink)%6 != 0 {
return nil, fmt.Errorf("poolRecordswithCFMMLink must be a list of denom0, denom1, tickSpacing, exponentAtPriceOne, spreadFactor and balancerPoolId")
}

finalPoolRecords := []types.PoolRecordWithCFMMLink{}
i := 0
for i < len(poolRecordsWithCFMMLink) {
denom0 := poolRecordsWithCFMMLink[i]
denom1 := poolRecordsWithCFMMLink[i+1]

tickSpacing, err := strconv.Atoi(poolRecordsWithCFMMLink[i+2])
if err != nil {
return nil, err
}

exponentAtPriceOneStr := poolRecordsWithCFMMLink[i+3]
exponentAtPriceOne, ok := sdk.NewIntFromString(exponentAtPriceOneStr)
if !ok {
return nil, fmt.Errorf("invalid exponentAtPriceOne: %s", exponentAtPriceOneStr)
}

spreadFactorStr := poolRecordsWithCFMMLink[i+4]
spreadFactor, err := sdk.NewDecFromStr(spreadFactorStr)
if err != nil {
return nil, err
}

balancerPoolId, err := strconv.Atoi(poolRecordsWithCFMMLink[i+5])
if err != nil {
return nil, err
}

finalPoolRecords = append(finalPoolRecords, types.PoolRecordWithCFMMLink{
Denom0: denom0,
Denom1: denom1,
TickSpacing: uint64(tickSpacing),
ExponentAtPriceOne: exponentAtPriceOne,
SpreadFactor: spreadFactor,
BalancerPoolId: uint64(balancerPoolId),
})

// increase counter by the next 6
i = i + 6
}

return finalPoolRecords, nil
}
5 changes: 3 additions & 2 deletions x/gamm/client/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

var (
ReplaceMigrationRecordsProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitReplaceMigrationRecordsProposal, rest.ProposalReplaceMigrationRecordsRESTHandler)
UpdateMigrationRecordsProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpdateMigrationRecordsProposal, rest.ProposalUpdateMigrationRecordsRESTHandler)
ReplaceMigrationRecordsProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitReplaceMigrationRecordsProposal, rest.ProposalReplaceMigrationRecordsRESTHandler)
UpdateMigrationRecordsProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpdateMigrationRecordsProposal, rest.ProposalUpdateMigrationRecordsRESTHandler)
CreateCLPoolAndLinkToCFMMProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitCreateCLPoolAndLinkToCFMMProposal, rest.ProposalCreateConcentratedLiquidityPoolAndLinkToCFMMHandler)
)
7 changes: 7 additions & 0 deletions x/gamm/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func ProposalUpdateMigrationRecordsRESTHandler(clientCtx client.Context) govrest
}
}

func ProposalCreateConcentratedLiquidityPoolAndLinkToCFMMHandler(clientCtx client.Context) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "create-cl-pool-and-cfmm-link",
Handler: emptyHandler(clientCtx),
}
}

func emptyHandler(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
Expand Down
6 changes: 6 additions & 0 deletions x/gamm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func NewMigrationRecordHandler(k keeper.Keeper) govtypes.Handler {
return handleUpdateMigrationRecordsProposal(ctx, k, c)
case *types.ReplaceMigrationRecordsProposal:
return handleReplaceMigrationRecordsProposal(ctx, k, c)
case *types.CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal:
return handleCreatingCLPoolAndLinkToCFMMProposal(ctx, k, c)

default:
return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized migration record proposal content type: %T", c)
Expand All @@ -35,3 +37,7 @@ func handleReplaceMigrationRecordsProposal(ctx sdk.Context, k keeper.Keeper, p *
func handleUpdateMigrationRecordsProposal(ctx sdk.Context, k keeper.Keeper, p *types.UpdateMigrationRecordsProposal) error {
return k.HandleUpdateMigrationRecordsProposal(ctx, p)
}

func handleCreatingCLPoolAndLinkToCFMMProposal(ctx sdk.Context, k keeper.Keeper, p *types.CreateConcentratedLiquidityPoolsAndLinktoCFMMProposal) error {
return k.HandleCreatingCLPoolAndLinkToCFMMProposal(ctx, p)
}
Loading

0 comments on commit 957cf62

Please sign in to comment.