-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from comdex-official/refactor-code
refactor market and rewards module
- Loading branch information
Showing
29 changed files
with
300 additions
and
576 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1 @@ | ||
package cli | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
flagLiquidationRatio = "liquidation-ratio" | ||
flagScriptID = "script-id" | ||
flagPacketTimeoutHeight = "packet-timeout-height" | ||
flagFeeLimit = "fee-limit" | ||
) | ||
|
||
func GetLiquidationRatio(cmd *cobra.Command) (sdk.Dec, error) { | ||
s, err := cmd.Flags().GetString(flagLiquidationRatio) | ||
if err != nil { | ||
return sdk.Dec{}, err | ||
} | ||
|
||
return sdk.NewDecFromStr(s) | ||
} | ||
|
||
func GetPacketTimeoutHeight(cmd *cobra.Command) (ibcclienttypes.Height, error) { | ||
s, err := cmd.Flags().GetString(flagPacketTimeoutHeight) | ||
if err != nil { | ||
return ibcclienttypes.Height{}, err | ||
} | ||
|
||
return ibcclienttypes.ParseHeight(s) | ||
} | ||
|
||
func GetFeeLimit(cmd *cobra.Command) (sdk.Coins, error) { | ||
s, err := cmd.Flags().GetString(flagFeeLimit) | ||
if err != nil { | ||
return sdk.Coins{}, err | ||
} | ||
|
||
return sdk.ParseCoinsNormalized(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,162 +1 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/comdex-official/comdex/x/market/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func txAddMarket() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add-market [symbol] [script-id] [asset]", | ||
Short: "Add a market", | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
scriptID, err := strconv.ParseUint(args[1], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
asset, err := strconv.ParseUint(args[2], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var rates uint64 | ||
rates = 0 | ||
|
||
msg := types.NewMsgAddMarketRequest( | ||
ctx.FromAddress, | ||
args[0], | ||
scriptID, | ||
asset, | ||
rates, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func txUpdateMarket() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update-market [symbol]", | ||
Short: "Update a market", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
scriptID, err := cmd.Flags().GetUint64(flagScriptID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//rates, _ := keeper.Keeper.GetPriceForMarket(keeper.Keeper{}, sdk.Context{},args[0]) | ||
var rates uint64 | ||
rates = 40 | ||
msg := types.NewMsgUpdateMarketRequest( | ||
ctx.FromAddress, | ||
args[0], | ||
scriptID, | ||
rates, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
cmd.Flags().Uint64(flagScriptID, 0, "script identity") | ||
|
||
return cmd | ||
} | ||
|
||
/*func txAddMarketForAsset() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add-market-for-asset [asset] [symbol]", | ||
Short: "Add a market for asset", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
asset, err := strconv.ParseUint(args[0], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
msg := types.NewMsgAddMarketForAssetRequest( | ||
ctx.FromAddress, | ||
asset, | ||
args[1], | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg) | ||
}, | ||
} | ||
flags.AddTxFlagsToCmd(cmd) | ||
return cmd | ||
}*/ | ||
|
||
func txRemoveMarketForAsset() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "remove-market-for-asset [asset] [symbol]", | ||
Short: "Remove a market for asset", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
asset, err := strconv.ParseUint(args[0], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgRemoveMarketForAssetRequest( | ||
ctx.FromAddress, | ||
asset, | ||
args[1], | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.