utils.gno
0.90 Kb · 37 lines
1package staker
2
3import (
4 "errors"
5 "strconv"
6 "strings"
7
8 "gno.land/p/gnoswap/deps/grc721"
9)
10
11// poolPathDivide splits a pool path into token addresses and fee tier.
12func poolPathDivide(poolPath string) (string, string, string) {
13 res := strings.Split(poolPath, ":")
14 if len(res) != 3 {
15 panic(errors.New(errInvalidPoolPath))
16 }
17
18 pToken0, pToken1, fee := res[0], res[1], res[2]
19 return pToken0, pToken1, fee
20}
21
22// positionIdFrom converts a uint64 position ID to grc721.TokenID.
23func positionIdFrom(positionId uint64) grc721.TokenID {
24 return grc721.TokenID(strconv.FormatUint(positionId, 10))
25}
26
27// contains checks if a string exists in a slice.
28func contains(slice []string, item string) bool {
29 // We can use strings.EqualFold here, but this function should be case-sensitive.
30 // So, it is better to compare strings directly.
31 for _, element := range slice {
32 if element == item {
33 return true
34 }
35 }
36 return false
37}