consts.gno
3.19 Kb · 109 lines
1package consts
2
3import (
4 i256 "gno.land/p/gnoswap/int256/v1"
5 u256 "gno.land/p/gnoswap/uint256/v1"
6)
7
8// u256.Uint and i256.Int are little-endian [4]uint64:
9// {arr[0]=least significant, arr[1], arr[2], arr[3]=most significant}.
10
11// MaxUint256 returns 2^256 - 1.
12//
13// Returns:
14// - value: a fresh Uint equal to 2^256-1
15func MaxUint256() *u256.Uint {
16 return &u256.Uint{18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615}
17}
18
19// MaxUint128 returns 2^128 - 1, the maximum uint128 value.
20//
21// Returns:
22// - value: a fresh Uint equal to 2^128-1
23func MaxUint128() *u256.Uint {
24 return &u256.Uint{18446744073709551615, 18446744073709551615, 0, 0}
25}
26
27// MaxInt256 returns 2^255 - 1, the maximum int256 value, as an unsigned u256.
28//
29// Returns:
30// - value: a fresh Uint equal to 2^255-1
31func MaxInt256() *u256.Uint {
32 return &u256.Uint{18446744073709551615, 18446744073709551615, 18446744073709551615, 9223372036854775807}
33}
34
35// Q96 returns 2^96, the Q64.96 fixed-point scaling factor.
36//
37// Returns:
38// - value: a fresh Uint equal to 2^96, the Q64.96 scale
39func Q96() *u256.Uint {
40 return &u256.Uint{0, 4294967296, 0, 0}
41}
42
43// Q128 returns 2^128, the Q128.128 fixed-point scaling factor.
44//
45// Returns:
46// - value: a fresh Uint equal to 2^128, the Q128.128 scale
47func Q128() *u256.Uint {
48 return &u256.Uint{0, 0, 1, 0}
49}
50
51// Q192 returns 2^192.
52//
53// Returns:
54// - value: a fresh Uint equal to 2^192
55func Q192() *u256.Uint {
56 return &u256.Uint{0, 0, 0, 1}
57}
58
59// Max160 returns 2^160 - 1, the maximum value representable in 160 bits.
60//
61// Returns:
62// - value: a fresh Uint equal to 2^160-1
63func Max160() *u256.Uint {
64 return &u256.Uint{18446744073709551615, 18446744073709551615, 4294967295, 0}
65}
66
67// MinSqrtRatio returns the minimum valid sqrt price ratio (4295128739),
68// equal to TickMathGetSqrtRatioAtTick(minTick).
69//
70// Returns:
71// - value: a fresh Uint equal to the minimum valid sqrt-price ratio
72func MinSqrtRatio() *u256.Uint {
73 return &u256.Uint{4295128739, 0, 0, 0}
74}
75
76// MaxSqrtRatio returns the upper bound of the valid sqrt price range
77// (1461446703485210103287273052203988822378723970342), equal to
78// TickMathGetSqrtRatioAtTick(maxTick). TickMathGetTickAtSqrtRatio treats this
79// boundary as exclusive and accepts values in [MinSqrtRatio, MaxSqrtRatio).
80//
81// Returns:
82// - value: a fresh Uint equal to the exclusive upper sqrt-price boundary
83func MaxSqrtRatio() *u256.Uint {
84 return &u256.Uint{6743328256752651558, 17280870778742802505, 4294805859, 0}
85}
86
87// MaxInt128I256 returns 2^127 - 1, the maximum int128 value, as a signed i256.
88//
89// Returns:
90// - value: a fresh signed Int equal to 2^127-1
91func MaxInt128I256() *i256.Int {
92 return &i256.Int{18446744073709551615, 9223372036854775807, 0, 0}
93}
94
95// MaxInt64I256 returns 2^63 - 1, the maximum int64 value, as a signed i256.
96//
97// Returns:
98// - value: a fresh signed Int equal to 2^63-1
99func MaxInt64I256() *i256.Int {
100 return &i256.Int{9223372036854775807, 0, 0, 0}
101}
102
103// MinInt64I256 returns -2^63, the minimum int64 value, as a signed i256.
104//
105// Returns:
106// - value: a fresh signed Int equal to -2^63
107func MinInt64I256() *i256.Int {
108 return &i256.Int{9223372036854775808, 18446744073709551615, 18446744073709551615, 18446744073709551615}
109}