-
Notifications
You must be signed in to change notification settings - Fork 581
/
common.go
73 lines (62 loc) · 1.84 KB
/
common.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
package cli
import (
"errors"
"strconv"
"strings"
flag "github.com/spf13/pflag"
"github.com/osmosis-labs/osmosis/v24/x/poolmanager/types"
)
func swapAmountInRoutes(fs *flag.FlagSet) ([]types.SwapAmountInRoute, error) {
swapRoutePoolIds, err := fs.GetString(FlagSwapRoutePoolIds)
swapRoutePoolIdsArray := strings.Split(swapRoutePoolIds, ",")
if err != nil {
return nil, err
}
swapRouteDenoms, err := fs.GetString(FlagSwapRouteDenoms)
swapRouteDenomsArray := strings.Split(swapRouteDenoms, ",")
if err != nil {
return nil, err
}
if len(swapRoutePoolIdsArray) != len(swapRouteDenomsArray) {
return nil, errors.New("swap route pool ids and denoms mismatch")
}
routes := []types.SwapAmountInRoute{}
for index, poolIDStr := range swapRoutePoolIdsArray {
pID, err := strconv.Atoi(poolIDStr)
if err != nil {
return nil, err
}
routes = append(routes, types.SwapAmountInRoute{
PoolId: uint64(pID),
TokenOutDenom: swapRouteDenomsArray[index],
})
}
return routes, nil
}
func swapAmountOutRoutes(fs *flag.FlagSet) ([]types.SwapAmountOutRoute, error) {
swapRoutePoolIds, err := fs.GetString(FlagSwapRoutePoolIds)
swapRoutePoolIdsArray := strings.Split(swapRoutePoolIds, ",")
if err != nil {
return nil, err
}
swapRouteDenoms, err := fs.GetString(FlagSwapRouteDenoms)
swapRouteDenomsArray := strings.Split(swapRouteDenoms, ",")
if err != nil {
return nil, err
}
if len(swapRoutePoolIdsArray) != len(swapRouteDenomsArray) {
return nil, errors.New("swap route pool ids and denoms mismatch")
}
routes := []types.SwapAmountOutRoute{}
for index, poolIDStr := range swapRoutePoolIdsArray {
pID, err := strconv.Atoi(poolIDStr)
if err != nil {
return nil, err
}
routes = append(routes, types.SwapAmountOutRoute{
PoolId: uint64(pID),
TokenInDenom: swapRouteDenomsArray[index],
})
}
return routes, nil
}