consts.gno
2.27 Kb · 72 lines
1package consts
2
3import (
4 i256 "gno.land/p/gnoswap/int256"
5 u256 "gno.land/p/gnoswap/uint256"
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.
12func MaxUint256() *u256.Uint {
13 return &u256.Uint{18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615}
14}
15
16// MaxUint128 returns 2^128 - 1, the maximum uint128 value.
17func MaxUint128() *u256.Uint {
18 return &u256.Uint{18446744073709551615, 18446744073709551615, 0, 0}
19}
20
21// MaxInt256 returns 2^255 - 1, the maximum int256 value, as an unsigned u256.
22func MaxInt256() *u256.Uint {
23 return &u256.Uint{18446744073709551615, 18446744073709551615, 18446744073709551615, 9223372036854775807}
24}
25
26// Q96 returns 2^96, the Q64.96 fixed-point scaling factor.
27func Q96() *u256.Uint {
28 return &u256.Uint{0, 4294967296, 0, 0}
29}
30
31// Q128 returns 2^128, the Q128.128 fixed-point scaling factor.
32func Q128() *u256.Uint {
33 return &u256.Uint{0, 0, 1, 0}
34}
35
36// Q192 returns 2^192.
37func Q192() *u256.Uint {
38 return &u256.Uint{0, 0, 0, 1}
39}
40
41// Max160 returns 2^160 - 1, the maximum value representable in 160 bits.
42func Max160() *u256.Uint {
43 return &u256.Uint{18446744073709551615, 18446744073709551615, 4294967295, 0}
44}
45
46// MinSqrtRatio returns the minimum valid sqrt price ratio (4295128739),
47// equal to TickMathGetSqrtRatioAtTick(minTick).
48func MinSqrtRatio() *u256.Uint {
49 return &u256.Uint{4295128739, 0, 0, 0}
50}
51
52// MaxSqrtRatio returns the maximum valid sqrt price ratio
53// (1461446703485210103287273052203988822378723970342),
54// equal to TickMathGetSqrtRatioAtTick(maxTick).
55func MaxSqrtRatio() *u256.Uint {
56 return &u256.Uint{6743328256752651558, 17280870778742802505, 4294805859, 0}
57}
58
59// MaxInt128I256 returns 2^127 - 1, the maximum int128 value, as a signed i256.
60func MaxInt128I256() *i256.Int {
61 return &i256.Int{18446744073709551615, 9223372036854775807, 0, 0}
62}
63
64// MaxInt64I256 returns 2^63 - 1, the maximum int64 value, as a signed i256.
65func MaxInt64I256() *i256.Int {
66 return &i256.Int{9223372036854775807, 0, 0, 0}
67}
68
69// MinInt64I256 returns -2^63, the minimum int64 value, as a signed i256.
70func MinInt64I256() *i256.Int {
71 return &i256.Int{9223372036854775808, 18446744073709551615, 18446744073709551615, 18446744073709551615}
72}