-
Notifications
You must be signed in to change notification settings - Fork 571
/
route.go
95 lines (76 loc) · 1.94 KB
/
route.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v25/x/poolmanager/types"
)
type SwapAmountInRoutes []poolmanagertypes.SwapAmountInRoute
func (routes SwapAmountInRoutes) Validate() error {
if len(routes) == 0 {
return ErrEmptyRoutes
}
for _, route := range routes {
err := sdk.ValidateDenom(route.TokenOutDenom)
if err != nil {
return err
}
}
return nil
}
func (routes SwapAmountInRoutes) IntermediateDenoms() []string {
if len(routes) < 2 {
return nil
}
intermediateDenoms := make([]string, 0, len(routes)-1)
for _, route := range routes[:len(routes)-1] {
intermediateDenoms = append(intermediateDenoms, route.TokenOutDenom)
}
return intermediateDenoms
}
func (routes SwapAmountInRoutes) PoolIds() []uint64 {
poolIds := make([]uint64, 0, len(routes))
for _, route := range routes {
poolIds = append(poolIds, route.PoolId)
}
return poolIds
}
func (routes SwapAmountInRoutes) Length() int {
return len(routes)
}
type SwapAmountOutRoutes []poolmanagertypes.SwapAmountOutRoute
func (routes SwapAmountOutRoutes) Validate() error {
if len(routes) == 0 {
return ErrEmptyRoutes
}
for _, route := range routes {
err := sdk.ValidateDenom(route.TokenInDenom)
if err != nil {
return err
}
}
return nil
}
func (routes SwapAmountOutRoutes) IntermediateDenoms() []string {
if len(routes) < 2 {
return nil
}
intermediateDenoms := make([]string, 0, len(routes)-1)
for _, route := range routes[1:] {
intermediateDenoms = append(intermediateDenoms, route.TokenInDenom)
}
return intermediateDenoms
}
func (routes SwapAmountOutRoutes) PoolIds() []uint64 {
poolIds := make([]uint64, 0, len(routes))
for _, route := range routes {
poolIds = append(poolIds, route.PoolId)
}
return poolIds
}
func (routes SwapAmountOutRoutes) Length() int {
return len(routes)
}
type MultihopRoute interface {
Length() int
PoolIds() []uint64
IntermediateDenoms() []string
}