Commit 8caa7677 authored by mattverse's avatar mattverse
Browse files

Add Clien support for proposals, wire it to gov module

parent eb3ea480
Showing with 237 additions and 0 deletions
+237 -0
......@@ -34,6 +34,7 @@ import (
downtimemodule "github.com/osmosis-labs/osmosis/v15/x/downtime-detector/module"
"github.com/osmosis-labs/osmosis/v15/x/epochs"
"github.com/osmosis-labs/osmosis/v15/x/gamm"
gammclient "github.com/osmosis-labs/osmosis/v15/x/gamm/client"
"github.com/osmosis-labs/osmosis/v15/x/ibc-rate-limit/ibcratelimitmodule"
"github.com/osmosis-labs/osmosis/v15/x/incentives"
"github.com/osmosis-labs/osmosis/v15/x/lockup"
......@@ -75,6 +76,8 @@ var AppModuleBasics = []module.AppModuleBasic{
superfluidclient.SetSuperfluidAssetsProposalHandler,
superfluidclient.RemoveSuperfluidAssetsProposalHandler,
superfluidclient.UpdateUnpoolWhitelistProposalHandler,
gammclient.ReplaceMigrationRecordsProposalHandler,
gammclient.UpdateMigrationRecordsProposalHandler,
)...,
),
params.AppModuleBasic{},
......
......@@ -40,6 +40,8 @@ const (
FlagSwapRouteDenoms = "swap-route-denoms"
// FlagScalingFactors represents the flag name for the scaling factors.
FlagScalingFactors = "scaling-factors"
FlagMigrationRecords = "migration-records"
)
type createBalancerPoolInputs struct {
......
......@@ -17,7 +17,10 @@ import (
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
func NewTxCmd() *cobra.Command {
......@@ -178,6 +181,115 @@ func NewStableSwapAdjustScalingFactorsCmd() *cobra.Command {
return cmd
}
// NewCmdSubmitReplaceMigrationRecordsProposal implements a command handler for replace migration records proposal
func NewCmdSubmitReplaceMigrationRecordsProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "replace-migration-records-proposal [flags]",
Args: cobra.ExactArgs(0),
Short: "Submit a replace migration record proposal",
Long: strings.TrimSpace(`Submit a replace migration record proposal.
Passing in poolIds separated by commas would be parsed automatically to pairs of migration record.
Ex) 2,4,1,5 -> [(Balancer 2, CL 4), (Balancer 1, CL 5)]
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
content, err := parseReplaceMigrationRecordsArgsToContent(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().String(FlagMigrationRecords, "", "The migration records array")
return cmd
}
// NewCmdSubmitUpdateMigrationRecordsProposal implements a command handler for replace migration records proposal
func NewCmdSubmitUpdateMigrationRecordsProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "update-migration-records-proposal [flags]",
Args: cobra.ExactArgs(0),
Short: "Submit a update migration record proposal",
Long: strings.TrimSpace(`Submit a update migration record proposal.
Passing in poolIds separated by commas would be parsed automatically to pairs of migration record.
Ex) 2,4,1,5 -> [(Balancer 2, CL 4), (Balancer 1, CL 5)]
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
content, err := parseUpdateMigrationRecordsArgsToContent(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().String(FlagMigrationRecords, "", "The migration 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 {
......@@ -513,3 +625,83 @@ func ParseCoinsNoSort(coinsStr string) (sdk.Coins, error) {
}
return sdk.NormalizeCoins(decCoins), nil
}
func parseMigrationRecords(cmd *cobra.Command) ([]types.BalancerToConcentratedPoolLink, error) {
assetsStr, err := cmd.Flags().GetString(FlagMigrationRecords)
if err != nil {
return nil, err
}
assets := strings.Split(assetsStr, ",")
replaceMigrations := []types.BalancerToConcentratedPoolLink{}
i := 0
for i < len(assets) {
balancerPoolId, err := strconv.Atoi(assets[i])
if err != nil {
return nil, err
}
clPoolId, err := strconv.Atoi(assets[i+1])
if err != nil {
return nil, err
}
replaceMigrations = append(replaceMigrations, types.BalancerToConcentratedPoolLink{
BalancerPoolId: uint64(balancerPoolId),
ClPoolId: uint64(clPoolId),
})
// increase counter by the next 2
i = i + 2
}
return replaceMigrations, nil
}
func parseReplaceMigrationRecordsArgsToContent(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
}
replaceMigrations, err := parseMigrationRecords(cmd)
if err != nil {
return nil, err
}
content := &types.ReplaceMigrationRecordsProposal{
Title: title,
Description: description,
Records: replaceMigrations,
}
return content, nil
}
func parseUpdateMigrationRecordsArgsToContent(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
}
replaceMigrations, err := parseMigrationRecords(cmd)
if err != nil {
return nil, err
}
content := &types.UpdateMigrationRecordsProposal{
Title: title,
Description: description,
Records: replaceMigrations,
}
return content, nil
}
package client
import (
"github.com/osmosis-labs/osmosis/v15/x/gamm/client/cli"
"github.com/osmosis-labs/osmosis/v15/x/gamm/client/rest"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
)
var (
ReplaceMigrationRecordsProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitReplaceMigrationRecordsProposal, rest.ProposalUpdateMigrationRecordsRESTHandler)
UpdateMigrationRecordsProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpdateMigrationRecordsProposal, rest.ProposalUpdateMigrationRecordsRESTHandler)
)
package rest
import (
"net/http"
"github.com/cosmos/cosmos-sdk/client"
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
)
func ProposalReplaceMigrationRecordsRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "replace-migrations-records",
Handler: emptyHandler(clientCtx),
}
}
func ProposalUpdateMigrationRecordsRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "update-migrations-records",
Handler: emptyHandler(clientCtx),
}
}
func emptyHandler(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment