-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
204 lines (179 loc) · 8.06 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package cli
import (
"strconv"
"github.com/gogo/protobuf/proto"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/osmosis-labs/osmosis/osmoutils/osmocli"
"github.com/fury-labs/furya/v20/x/poolmanager/client/queryproto"
"github.com/fury-labs/furya/v20/x/poolmanager/types"
)
var customRouterFlagOverride = map[string]string{
"router": FlagSwapRouteDenoms,
}
// GetQueryCmd returns the cli query commands for this module.
func GetQueryCmd() *cobra.Command {
cmd := osmocli.QueryIndexCmd(types.ModuleName)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdNumPools)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateSwapExactAmountIn)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateSwapExactAmountOut)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateSinglePoolSwapExactAmountIn)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateSinglePoolSwapExactAmountOut)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdSpotPrice)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTotalPoolLiquidity)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdAllPools)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdPool)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTotalVolumeForPool)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTradingPairTakerFee)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateTradeBasedOnPriceImpact)
cmd.AddCommand(
osmocli.GetParams[*queryproto.ParamsRequest](
types.ModuleName, queryproto.NewQueryClient),
)
return cmd
}
// GetCmdEstimateSwapExactAmountIn returns estimation of output coin when amount of x token input.
func GetCmdEstimateSwapExactAmountIn() (*osmocli.QueryDescriptor, *queryproto.EstimateSwapExactAmountInRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-swap-exact-amount-in",
Short: "Query estimate-swap-exact-amount-in",
Long: `Query estimate-swap-exact-amount-in.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-swap-exact-amount-in 1 1000stake --swap-route-pool-ids=2 --swap-route-pool-ids=3`,
ParseQuery: EstimateSwapExactAmountInParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
QueryFnName: "EstimateSwapExactAmountIn",
CustomFlagOverrides: customRouterFlagOverride,
}, &queryproto.EstimateSwapExactAmountInRequest{}
}
// GetCmdEstimateSwapExactAmountOut returns estimation of input coin to get exact amount of x token output.
func GetCmdEstimateSwapExactAmountOut() (*osmocli.QueryDescriptor, *queryproto.EstimateSwapExactAmountOutRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-swap-exact-amount-out",
Short: "Query estimate-swap-exact-amount-out",
Long: `Query estimate-swap-exact-amount-out.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-swap-exact-amount-out 1 1000stake --swap-route-pool-ids=2 --swap-route-pool-ids=3`,
ParseQuery: EstimateSwapExactAmountOutParseArgs,
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetMultihopSwapRoutes()}},
QueryFnName: "EstimateSwapExactAmountOut",
CustomFlagOverrides: customRouterFlagOverride,
}, &queryproto.EstimateSwapExactAmountOutRequest{}
}
// GetCmdNumPools return number of pools available.
func GetCmdNumPools() (*osmocli.QueryDescriptor, *queryproto.NumPoolsRequest) {
return &osmocli.QueryDescriptor{
Use: "num-pools",
Short: "Query number of pools",
Long: "{{.Short}}",
}, &queryproto.NumPoolsRequest{}
}
// GetCmdAllPools return all pools available across Furya modules.
func GetCmdAllPools() (*osmocli.QueryDescriptor, *queryproto.AllPoolsRequest) {
return &osmocli.QueryDescriptor{
Use: "all-pools",
Short: "Query all pools on the Furya chain",
Long: "{{.Short}}",
}, &queryproto.AllPoolsRequest{}
}
// GetCmdPool returns pool information.
func GetCmdPool() (*osmocli.QueryDescriptor, *queryproto.PoolRequest) {
return &osmocli.QueryDescriptor{
Use: "pool",
Short: "Query pool",
Long: `{{.Short}}{{.ExampleHeader}}
{{.CommandPrefix}} pool 1`,
}, &queryproto.PoolRequest{}
}
func GetCmdSpotPrice() (*osmocli.QueryDescriptor, *queryproto.SpotPriceRequest) {
return &osmocli.QueryDescriptor{
Use: "spot-price",
Short: "Query spot-price",
Long: `Query spot-price
{{.CommandPrefix}} spot-price 1 ufury ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2
`,
}, &queryproto.SpotPriceRequest{}
}
func EstimateSwapExactAmountInParseArgs(args []string, fs *flag.FlagSet) (proto.Message, error) {
poolID, err := strconv.Atoi(args[0])
if err != nil {
return nil, err
}
routes, err := swapAmountInRoutes(fs)
if err != nil {
return nil, err
}
return &queryproto.EstimateSwapExactAmountInRequest{
PoolId: uint64(poolID), // TODO: is this poolId used?
TokenIn: args[1],
Routes: routes,
}, nil
}
func EstimateSwapExactAmountOutParseArgs(args []string, fs *flag.FlagSet) (proto.Message, error) {
poolID, err := strconv.Atoi(args[0])
if err != nil {
return nil, err
}
routes, err := swapAmountOutRoutes(fs)
if err != nil {
return nil, err
}
return &queryproto.EstimateSwapExactAmountOutRequest{
PoolId: uint64(poolID), // TODO: is this poolId used?
Routes: routes,
TokenOut: args[1],
}, nil
}
// GetCmdEstimateSinglePoolSwapExactAmountIn returns estimation of output coin when amount of x token input.
func GetCmdEstimateSinglePoolSwapExactAmountIn() (*osmocli.QueryDescriptor, *queryproto.EstimateSinglePoolSwapExactAmountInRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-single-pool-swap-exact-amount-in",
Short: "Query estimate-single-pool-swap-exact-amount-in",
Long: `Query estimate-single-pool-swap-exact-amount-in.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-single-pool-swap-exact-amount-in 1 1000stake ufury`,
QueryFnName: "EstimateSinglePoolSwapExactAmountIn",
}, &queryproto.EstimateSinglePoolSwapExactAmountInRequest{}
}
// GetCmdEstimateSinglePoolSwapExactAmountOut returns estimation of input coin to get exact amount of x token output.
func GetCmdEstimateSinglePoolSwapExactAmountOut() (*osmocli.QueryDescriptor, *queryproto.EstimateSinglePoolSwapExactAmountOutRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-single-pool-swap-exact-amount-out",
Short: "Query estimate-single-pool-swap-exact-amount-out",
Long: `Query estimate-single-pool-swap-exact-amount-out.{{.ExampleHeader}}
{{.CommandPrefix}} estimate-single-pool-swap-exact-amount-out 1 ufury 1000stake`,
QueryFnName: "EstimateSinglePoolSwapExactAmountOut",
}, &queryproto.EstimateSinglePoolSwapExactAmountOutRequest{}
}
func GetCmdTotalPoolLiquidity() (*osmocli.QueryDescriptor, *queryproto.TotalPoolLiquidityRequest) {
return &osmocli.QueryDescriptor{
Use: "total-pool-liquidity",
Short: "Query total-pool-liquidity",
Long: `{{.Short}}
{{.CommandPrefix}} total-pool-liquidity 1`,
}, &queryproto.TotalPoolLiquidityRequest{}
}
func GetCmdTotalVolumeForPool() (*osmocli.QueryDescriptor, *queryproto.TotalVolumeForPoolRequest) {
return &osmocli.QueryDescriptor{
Use: "total-volume-for-pool",
Short: "Query total-volume-for-pool",
Long: `{{.Short}}
{{.CommandPrefix}} total-volume-for-pool 1`,
}, &queryproto.TotalVolumeForPoolRequest{}
}
func GetCmdTradingPairTakerFee() (*osmocli.QueryDescriptor, *queryproto.TradingPairTakerFeeRequest) {
return &osmocli.QueryDescriptor{
Use: "trading-pair-taker-fee",
Short: "Query trading pair taker fee",
Long: `{{.Short}}
{{.CommandPrefix}} trading-pair-taker-fee ufury uatom`,
}, &queryproto.TradingPairTakerFeeRequest{}
}
func GetCmdEstimateTradeBasedOnPriceImpact() (
*osmocli.QueryDescriptor, *queryproto.EstimateTradeBasedOnPriceImpactRequest,
) {
return &osmocli.QueryDescriptor{
Use: "estimate-trade-based-on-price-impact <fromCoin> <toCoinDenom> <poolId> <maxPriceImpact> <externalPrice>",
Short: "Query estimate-trade-based-on-price-impact",
Long: `{{.Short}}
{{.CommandPrefix}} estimate-trade-based-on-price-impact 100ufury stosmo 833 0.001 1.00`,
QueryFnName: "EstimateTradeBasedOnPriceImpact",
}, &queryproto.EstimateTradeBasedOnPriceImpactRequest{}
}