Skip to content

Commit

Permalink
Merge branch 'main' into mconcat/superfluid-governance
Browse files Browse the repository at this point in the history
  • Loading branch information
mattverse committed May 17, 2022
2 parents 35a4b99 + d3af599 commit c3e4d6d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 58 deletions.
71 changes: 71 additions & 0 deletions osmoutils/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package osmoutils

import (
"encoding/json"
"fmt"
"os"

"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
"github.com/spf13/pflag"
)

type Proposal struct {
Title string
Description string
Deposit string
}

var ProposalFlags = []string{
cli.FlagTitle,
cli.FlagDescription,
cli.FlagDeposit,
}

func (p Proposal) validate() error {
if p.Title == "" {
return fmt.Errorf("proposal title is required")
}

if p.Description == "" {
return fmt.Errorf("proposal description is required")
}
return nil
}

func ParseProposalFlags(fs *pflag.FlagSet) (*Proposal, error) {
proposal := &Proposal{}
proposalFile, _ := fs.GetString(cli.FlagProposal)

if proposalFile == "" {
proposal.Title, _ = fs.GetString(cli.FlagTitle)
proposal.Description, _ = fs.GetString(cli.FlagDescription)
proposal.Deposit, _ = fs.GetString(cli.FlagDeposit)
if err := proposal.validate(); err != nil {
return nil, err
}

return proposal, nil
}

for _, flag := range ProposalFlags {
if v, _ := fs.GetString(flag); v != "" {
return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag)
}
}

contents, err := os.ReadFile(proposalFile)
if err != nil {
return nil, err
}

err = json.Unmarshal(contents, proposal)
if err != nil {
return nil, err
}

if err := proposal.validate(); err != nil {
return nil, err
}

return proposal, nil
}
31 changes: 15 additions & 16 deletions x/gamm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/stableswap"
"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
)

Expand All @@ -27,30 +26,30 @@ func NewBalancerMsgServerImpl(keeper *Keeper) balancer.MsgServer {
}
}

func NewStableswapMsgServerImpl(keeper *Keeper) stableswap.MsgServer {
return &msgServer{
keeper: keeper,
}
}
// func NewStableswapMsgServerImpl(keeper *Keeper) stableswap.MsgServer {
// return &msgServer{
// keeper: keeper,
// }
// }

var (
_ types.MsgServer = msgServer{}
_ balancer.MsgServer = msgServer{}
_ stableswap.MsgServer = msgServer{}
_ types.MsgServer = msgServer{}
_ balancer.MsgServer = msgServer{}
// _ stableswap.MsgServer = msgServer{}
)

func (server msgServer) CreateBalancerPool(goCtx context.Context, msg *balancer.MsgCreateBalancerPool) (*balancer.MsgCreateBalancerPoolResponse, error) {
poolId, err := server.CreatePool(goCtx, msg)
return &balancer.MsgCreateBalancerPoolResponse{PoolID: poolId}, err
}

func (server msgServer) CreateStableswapPool(goCtx context.Context, msg *stableswap.MsgCreateStableswapPool) (*stableswap.MsgCreateStableswapPoolResponse, error) {
poolId, err := server.CreatePool(goCtx, msg)
if err != nil {
return nil, err
}
return &stableswap.MsgCreateStableswapPoolResponse{PoolID: poolId}, nil
}
// func (server msgServer) CreateStableswapPool(goCtx context.Context, msg *stableswap.MsgCreateStableswapPool) (*stableswap.MsgCreateStableswapPoolResponse, error) {
// poolId, err := server.CreatePool(goCtx, msg)
// if err != nil {
// return nil, err
// }
// return &stableswap.MsgCreateStableswapPoolResponse{PoolID: poolId}, nil
// }

func (server msgServer) CreatePool(goCtx context.Context, msg types.CreatePoolMsg) (poolId uint64, err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
Expand Down
7 changes: 3 additions & 4 deletions x/gamm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/osmosis-labs/osmosis/v7/x/gamm/client/cli"
"github.com/osmosis-labs/osmosis/v7/x/gamm/keeper"
"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/stableswap"
"github.com/osmosis-labs/osmosis/v7/x/gamm/simulation"
"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
)
Expand All @@ -44,7 +43,7 @@ func (AppModuleBasic) Name() string { return types.ModuleName }
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
balancer.RegisterLegacyAminoCodec(cdc)
stableswap.RegisterLegacyAminoCodec(cdc)
// stableswap.RegisterLegacyAminoCodec(cdc)
}

// DefaultGenesis returns default genesis state as raw bytes for the gamm
Expand Down Expand Up @@ -83,7 +82,7 @@ func (b AppModuleBasic) GetQueryCmd() *cobra.Command {
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
balancer.RegisterInterfaces(registry)
stableswap.RegisterInterfaces(registry)
// stableswap.RegisterInterfaces(registry)
}

type AppModule struct {
Expand All @@ -100,7 +99,7 @@ type AppModule struct {
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper))
balancer.RegisterMsgServer(cfg.MsgServer(), keeper.NewBalancerMsgServerImpl(&am.keeper))
stableswap.RegisterMsgServer(cfg.MsgServer(), keeper.NewStableswapMsgServerImpl(&am.keeper))
// stableswap.RegisterMsgServer(cfg.MsgServer(), keeper.NewStableswapMsgServerImpl(&am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
}

Expand Down
50 changes: 12 additions & 38 deletions x/pool-incentives/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,19 @@ func NewCmdSubmitUpdatePoolIncentivesProposal() *cobra.Command {
})
}

title, err := cmd.Flags().GetString(cli.FlagTitle)
if err != nil {
return err
}

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

from := clientCtx.GetFromAddress()

depositStr, err := cmd.Flags().GetString(cli.FlagDeposit)
proposal, err := osmoutils.ParseProposalFlags(cmd.Flags())
if err != nil {
return err
return fmt.Errorf("failed to parse proposal: %w", err)
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)

deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}

content := types.NewUpdatePoolIncentivesProposal(title, description, records)
content := types.NewUpdatePoolIncentivesProposal(proposal.Title, proposal.Deposit, records)

msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
Expand All @@ -107,11 +98,7 @@ func NewCmdSubmitUpdatePoolIncentivesProposal() *cobra.Command {
},
}

cmd.Flags().String(cli.FlagTitle, "", "title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal")
_ = cmd.MarkFlagRequired(cli.FlagTitle)
_ = cmd.MarkFlagRequired(cli.FlagDescription)
cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")

return cmd
}
Expand Down Expand Up @@ -153,28 +140,19 @@ func NewCmdSubmitReplacePoolIncentivesProposal() *cobra.Command {
})
}

title, err := cmd.Flags().GetString(cli.FlagTitle)
if err != nil {
return err
}

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

from := clientCtx.GetFromAddress()

depositStr, err := cmd.Flags().GetString(cli.FlagDeposit)
proposal, err := osmoutils.ParseProposalFlags(cmd.Flags())
if err != nil {
return err
return fmt.Errorf("failed to parse proposal: %w", err)
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)

deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}

content := types.NewReplacePoolIncentivesProposal(title, description, records)
content := types.NewReplacePoolIncentivesProposal(proposal.Title, proposal.Description, records)

msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
Expand All @@ -189,11 +167,7 @@ func NewCmdSubmitReplacePoolIncentivesProposal() *cobra.Command {
},
}

cmd.Flags().String(cli.FlagTitle, "", "title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal")
_ = cmd.MarkFlagRequired(cli.FlagTitle)
_ = cmd.MarkFlagRequired(cli.FlagDescription)
cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")

return cmd
}

0 comments on commit c3e4d6d

Please sign in to comment.