@@ -2,12 +2,15 @@ package cli
2
2
3
3
import (
4
4
"fmt"
5
+ "strconv"
5
6
6
7
// "strings"
7
8
8
9
"github.com/spf13/cobra"
9
10
10
11
"github.com/cosmos/cosmos-sdk/client"
12
+ "github.com/cosmos/cosmos-sdk/client/flags"
13
+ sdk "github.com/cosmos/cosmos-sdk/types"
11
14
12
15
"github.com/sideprotocol/side/x/lending/types"
13
16
)
@@ -23,7 +26,175 @@ func GetQueryCmd(_ string) *cobra.Command {
23
26
RunE : client .ValidateCmd ,
24
27
}
25
28
29
+ cmd .AddCommand (CmdQueryParams ())
30
+ cmd .AddCommand (CmdQueryCollateralAddress ())
31
+ cmd .AddCommand (CmdQueryLiquidationEvent ())
32
+ cmd .AddCommand (CmdQueryCETs ())
33
+ cmd .AddCommand (CmdQueryRepaymentTx ())
26
34
// this line is used by starport scaffolding # 1
27
35
28
36
return cmd
29
37
}
38
+
39
+ func CmdQueryParams () * cobra.Command {
40
+ cmd := & cobra.Command {
41
+ Use : "params" ,
42
+ Short : "Query the parameters of the module" ,
43
+ Args : cobra .NoArgs ,
44
+ RunE : func (cmd * cobra.Command , args []string ) error {
45
+ clientCtx , err := client .GetClientQueryContext (cmd )
46
+ if err != nil {
47
+ return err
48
+ }
49
+
50
+ queryClient := types .NewQueryClient (clientCtx )
51
+
52
+ res , err := queryClient .Params (cmd .Context (), & types.QueryParamsRequest {})
53
+ if err != nil {
54
+ return err
55
+ }
56
+
57
+ return clientCtx .PrintProto (res )
58
+ },
59
+ }
60
+
61
+ flags .AddQueryFlagsToCmd (cmd )
62
+
63
+ return cmd
64
+ }
65
+
66
+ func CmdQueryCollateralAddress () * cobra.Command {
67
+ cmd := & cobra.Command {
68
+ Use : "collateral-address [btc public key] [hash of loan secret] [maturity time] [final timeout]" ,
69
+ Short : "Query the collateral address by the specified loan params" ,
70
+ Args : cobra .ExactArgs (4 ),
71
+ RunE : func (cmd * cobra.Command , args []string ) error {
72
+ clientCtx , err := client .GetClientQueryContext (cmd )
73
+ if err != nil {
74
+ return err
75
+ }
76
+
77
+ queryClient := types .NewQueryClient (clientCtx )
78
+
79
+ maturityTime , err := strconv .ParseUint (args [2 ], 10 , 64 )
80
+ if err != nil {
81
+ return err
82
+ }
83
+
84
+ finalTimeout , err := strconv .ParseUint (args [3 ], 10 , 64 )
85
+ if err != nil {
86
+ return err
87
+ }
88
+
89
+ res , err := queryClient .CollateralAddress (cmd .Context (), & types.QueryCollateralAddressRequest {
90
+ BorrowerPubkey : args [0 ],
91
+ HashOfLoanSecret : args [1 ],
92
+ MaturityTime : maturityTime ,
93
+ FinalTimeout : finalTimeout ,
94
+ })
95
+ if err != nil {
96
+ return err
97
+ }
98
+
99
+ return clientCtx .PrintProto (res )
100
+ },
101
+ }
102
+
103
+ flags .AddQueryFlagsToCmd (cmd )
104
+
105
+ return cmd
106
+ }
107
+
108
+ func CmdQueryLiquidationEvent () * cobra.Command {
109
+ cmd := & cobra.Command {
110
+ Use : "liquidation-event [collateral amount] [borrowed amount]" ,
111
+ Short : "Query the corresponding liquidation event according to the collateral amount and borrowed amount" ,
112
+ Args : cobra .ExactArgs (2 ),
113
+ RunE : func (cmd * cobra.Command , args []string ) error {
114
+ clientCtx , err := client .GetClientQueryContext (cmd )
115
+ if err != nil {
116
+ return err
117
+ }
118
+
119
+ queryClient := types .NewQueryClient (clientCtx )
120
+
121
+ collateralAmount , err := sdk .ParseCoinNormalized (args [0 ])
122
+ if err != nil {
123
+ return err
124
+ }
125
+
126
+ borrowedAmount , err := sdk .ParseCoinNormalized (args [1 ])
127
+ if err != nil {
128
+ return err
129
+ }
130
+
131
+ res , err := queryClient .LiquidationEvent (cmd .Context (), & types.QueryLiquidationEventRequest {
132
+ BorrowAmount : & borrowedAmount ,
133
+ CollateralAcmount : & collateralAmount ,
134
+ })
135
+ if err != nil {
136
+ return err
137
+ }
138
+
139
+ return clientCtx .PrintProto (res )
140
+ },
141
+ }
142
+
143
+ flags .AddQueryFlagsToCmd (cmd )
144
+
145
+ return cmd
146
+ }
147
+
148
+ func CmdQueryCETs () * cobra.Command {
149
+ cmd := & cobra.Command {
150
+ Use : "cets [loan id]" ,
151
+ Short : "Query CETs of the given loan" ,
152
+ Args : cobra .ExactArgs (1 ),
153
+ RunE : func (cmd * cobra.Command , args []string ) error {
154
+ clientCtx , err := client .GetClientQueryContext (cmd )
155
+ if err != nil {
156
+ return err
157
+ }
158
+
159
+ queryClient := types .NewQueryClient (clientCtx )
160
+
161
+ res , err := queryClient .LoanCETs (cmd .Context (), & types.QueryLoanCETsRequest {LoanId : args [0 ]})
162
+ if err != nil {
163
+ return err
164
+ }
165
+
166
+ return clientCtx .PrintProto (res )
167
+ },
168
+ }
169
+
170
+ flags .AddQueryFlagsToCmd (cmd )
171
+
172
+ return cmd
173
+ }
174
+
175
+ func CmdQueryRepaymentTx () * cobra.Command {
176
+ cmd := & cobra.Command {
177
+ Use : "repayment-tx [loan id]" ,
178
+ Short : "Query the unsigned btc repayment tx of the repaid loan" ,
179
+ Args : cobra .ExactArgs (1 ),
180
+ RunE : func (cmd * cobra.Command , args []string ) error {
181
+ clientCtx , err := client .GetClientQueryContext (cmd )
182
+ if err != nil {
183
+ return err
184
+ }
185
+
186
+ queryClient := types .NewQueryClient (clientCtx )
187
+
188
+ res , err := queryClient .UnsignedPaymentTx (cmd .Context (), & types.QueryRepaymentTxRequest {LoanId : args [0 ]})
189
+ if err != nil {
190
+ return err
191
+ }
192
+
193
+ return clientCtx .PrintProto (res )
194
+ },
195
+ }
196
+
197
+ flags .AddQueryFlagsToCmd (cmd )
198
+
199
+ return cmd
200
+ }
0 commit comments