Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coinswap module #4644

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b6aceac
init scaffolding
colin-axner May 30, 2019
fe60ff4
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into co…
colin-axner Jun 4, 2019
d2b7ba5
base files added for uniswap module
colin-axner Jun 5, 2019
7609e05
modifiy module layout to follow standard
colin-axner Jun 6, 2019
9e56eee
added tests for msgs
colin-axner Jun 7, 2019
43f29f0
fixes in keeper
colin-axner Jun 7, 2019
930f5ed
work continued on keeper design
colin-axner Jun 7, 2019
c04b239
added fee params, reflected pr comments
colin-axner Jun 10, 2019
91da176
updated keeper
colin-axner Jun 11, 2019
a8437b0
updating handler
colin-axner Jun 11, 2019
8796822
added querier and basic querier test
colin-axner Jun 14, 2019
5e366fd
update msgs fields to input/output
colin-axner Jun 14, 2019
7cfb8c1
rename exchange to reserve pool, updated handler with err checks
colin-axner Jun 15, 2019
5bb4624
updated params
colin-axner Jun 18, 2019
c7fdc1f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into co…
colin-axner Jun 19, 2019
9e84bf8
reflect pr comments, fix some build issues in keeper/
colin-axner Jun 20, 2019
cacbff3
fixed some more build errors
colin-axner Jun 21, 2019
e827aa9
WIP refactor of naming, handlers and keeper
colin-axner Jun 28, 2019
ca92278
updated keeper/querier
colin-axner Jun 28, 2019
56dc984
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/4443…
colin-axner Jun 28, 2019
af5002a
update fee param to use numerator and denominator
colin-axner Jun 28, 2019
e640d5a
added keeper test and isdoubleswap test
colin-axner Jun 29, 2019
6398e9b
Fix GetInputAmount formula
zhangyelong Jul 22, 2019
cf88b4f
Merge pull request #4756 from zhangyelong/yelong/4443-coinswap
colin-axner Aug 8, 2019
265f431
Add cli commands for the coinswap module. (#4719)
aayushijain23 Sep 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions x/coinswap/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package coinswap

import (
"github.com/cosmos/cosmos-sdk/x/coinswap/internal/keeper"
"github.com/cosmos/cosmos-sdk/x/coinswap/internal/types"
)

type (
Keeper = keeper.Keeper
MsgSwapOrder = types.MsgSwapOrder
MsgAddLiquidity = types.MsgAddLiquidity
MsgRemoveLiquidity = types.MsgRemoveLiquidity
)

var (
ErrInvalidDeadline = types.ErrInvalidDeadline
ErrNotPositive = types.ErrNotPositive
ErrConstraintNotMet = types.ErrConstraintNotMet
)

const (
DefaultCodespace = types.DefaultCodespace
ModuleName = types.ModuleName
)
111 changes: 111 additions & 0 deletions x/coinswap/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package cli

import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/coinswap/internal/types"
)

const (
nativeDenom = "atom"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
coinswapQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the coinswap module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
coinswapQueryCmd.AddCommand(client.GetCommands(
GetCmdQueryLiquidity(queryRoute, cdc),
GetCmdQueryParams(queryRoute, cdc))...)

return coinswapQueryCmd
}

// GetCmdQueryLiquidity implements the liquidity query command
func GetCmdQueryLiquidity(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "liquidity [denom]",
Short: "Query the current liquidity values",
Long: strings.TrimSpace(
fmt.Sprintf(`Query the liquidity of a specific trading pair stored in the reserve pool.

Example:
$ %s query coinswap liquidity btc
`,
version.ClientName,
),
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

// Added a check to ensure that input provided is not a native denom
if strings.Compare(strings.TrimSpace(args[0]), nativeDenom) == 0 {
return fmt.Errorf("%s is not a valid denom, please input a valid denom", args[0])
}

bz, err := cdc.MarshalJSON(types.NewQueryLiquidityParams(args[0]))
if err != nil {
return err
}

route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryLiquidity)
res, _, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return err
}

var liquidity sdk.Coins
if err := cdc.UnmarshalJSON(res, &liquidity); err != nil {
return err
}
return cliCtx.PrintOutput(liquidity)
},
}
}

// GetCmdQueryParams implements the params query command
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "params",
Short: "Query the parameters involved in the coinswap process",
Long: strings.TrimSpace(
fmt.Sprintf(`Query all the parameters for the coinswap process.

Example:
$ %s query coinswap params
`,
version.ClientName,
),
),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryParameters)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}

var params types.Params
if err := cdc.UnmarshalJSON(bz, &params); err != nil {
return err
}
return cliCtx.PrintOutput(params)
},
}
}
Loading