Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

getter_utils.gno

1.47 Kb · 81 lines
 1package pool
 2
 3func cloneInt32Slice(src []int32) []int32 {
 4	if src == nil {
 5		return nil
 6	}
 7
 8	cloned := make([]int32, len(src))
 9	copy(cloned, src)
10	return cloned
11}
12
13func cloneInt64Slice(src []int64) []int64 {
14	if src == nil {
15		return nil
16	}
17
18	cloned := make([]int64, len(src))
19	copy(cloned, src)
20	return cloned
21}
22
23func cloneStringSlice(src []string) []string {
24	if src == nil {
25		return nil
26	}
27
28	cloned := make([]string, len(src))
29	copy(cloned, src)
30	return cloned
31}
32
33func cloneUint32Slice(src []uint32) []uint32 {
34	if src == nil {
35		return nil
36	}
37
38	cloned := make([]uint32, len(src))
39	copy(cloned, src)
40	return cloned
41}
42
43func cloneFeeAmountTickSpacings(src map[uint32]int32) map[uint32]int32 {
44	if src == nil {
45		return nil
46	}
47
48	cloned := make(map[uint32]int32, len(src))
49	for fee, spacing := range src {
50		cloned[fee] = spacing
51	}
52
53	return cloned
54}
55
56func cloneStringInt64Map(src map[string]int64) map[string]int64 {
57	if src == nil {
58		return nil
59	}
60
61	cloned := make(map[string]int64, len(src))
62	for k, v := range src {
63		cloned[k] = v
64	}
65
66	return cloned
67}
68
69// NewDefaultPositionInfo returns the zero-accounting position state used for a new pool position.
70//
71// Returns:
72//   - info: Position info with zero liquidity, zero fee-growth checkpoints, and no tokens owed.
73func NewDefaultPositionInfo() PositionInfo {
74	return PositionInfo{
75		liquidity:                "0",
76		feeGrowthInside0LastX128: "0",
77		feeGrowthInside1LastX128: "0",
78		tokensOwed0:              0,
79		tokensOwed1:              0,
80	}
81}