abstract-math 0.0.0.20__tar.gz → 0.0.0.22__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of abstract-math might be problematic. Click here for more details.

Files changed (28) hide show
  1. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/PKG-INFO +1 -1
  2. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/setup.py +1 -1
  3. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/derive_tokens.py +3 -1
  4. abstract_math-0.0.0.22/src/abstract_math/safe_math.py +207 -0
  5. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math.egg-info/PKG-INFO +1 -1
  6. abstract_math-0.0.0.20/src/abstract_math/safe_math.py +0 -165
  7. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/README.md +0 -0
  8. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/pyproject.toml +0 -0
  9. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/setup.cfg +0 -0
  10. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/__init__.py +0 -0
  11. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/flask_scripts/__init__.py +0 -0
  12. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/flask_scripts/flask_utils.py +0 -0
  13. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/__init__.py +0 -0
  14. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/flask_utils.py +0 -0
  15. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/main.py +0 -0
  16. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/__init__.py +0 -0
  17. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/constants/__init__.py +0 -0
  18. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/constants/distance_constants.py +0 -0
  19. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/constants/planet_constants.py +0 -0
  20. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/constants/time_constants.py +0 -0
  21. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/imports.py +0 -0
  22. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/utils/__init__.py +0 -0
  23. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/utils/escape_velocity.py +0 -0
  24. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/utils/geometry_utils.py +0 -0
  25. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math/solar_math/src/utils/velocity_utils.py +0 -0
  26. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math.egg-info/SOURCES.txt +0 -0
  27. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math.egg-info/dependency_links.txt +0 -0
  28. {abstract_math-0.0.0.20 → abstract_math-0.0.0.22}/src/abstract_math.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_math
3
- Version: 0.0.0.20
3
+ Version: 0.0.0.22
4
4
  Author: putkoff
5
5
  Author-email: partners@abstractendeavors.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -4,7 +4,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
4
4
  long_description = fh.read()
5
5
  setuptools.setup(
6
6
  name='abstract_math',
7
- version='0.0.0.20',
7
+ version='0.0.0.22',
8
8
  author='putkoff',
9
9
  author_email='partners@abstractendeavors.com',
10
10
  description="",
@@ -1,5 +1,7 @@
1
1
  from decimal import Decimal, getcontext
2
2
  from .safe_math import *
3
+ def exponentials(value,exp=9,num=-1):
4
+ return multiply_it(value,exp_it(10,exp,num))
3
5
 
4
6
  # High precision for decimal ops
5
7
  getcontext().prec = 50
@@ -7,7 +9,7 @@ getcontext().prec = 50
7
9
  # SOL constants
8
10
  SOL_DECIMAL_PLACE = 9
9
11
  # lamports per SOL = 10**9
10
- SOL_LAMPORTS = sol_lamports = int(exponential(1, exp=SOL_DECIMAL_PLACE, num=1))
12
+ SOL_LAMPORTS = sol_lamports = int(exponentials(1, exp=SOL_DECIMAL_PLACE, num=1))
11
13
 
12
14
 
13
15
  def get_proper_args(strings, *args, **kwargs):
@@ -0,0 +1,207 @@
1
+ from abstract_utilities import *
2
+ import math
3
+ import operator
4
+ from functools import reduce
5
+
6
+ # -------------------------------
7
+ # Core numeric hygiene
8
+ # -------------------------------
9
+ def _is_bad(x):
10
+ return (x is None) or (not is_number(x)) or (str(x).strip().lower() in ('', 'null'))
11
+
12
+ def gather_0(*args):
13
+ """Convert any bad / empty / 'null' to 0.0, keep others as float."""
14
+ out = []
15
+ for a in args:
16
+ out.append(0.0 if _is_bad(a) else float(a))
17
+ return out
18
+
19
+ # -------------------------------
20
+ # Basic ops (single definitions)
21
+ # -------------------------------
22
+ def add_it(*args):
23
+ """Sum all args; bad values become 0."""
24
+ return float(sum(gather_0(*args)))
25
+
26
+ def subtract_it(*args):
27
+ """a0 - a1 - a2 - ... ; bad values become 0."""
28
+ nums = gather_0(*args)
29
+ if not nums:
30
+ return 0.0
31
+ return float(reduce(operator.sub, nums))
32
+
33
+ def multiply_it(*args):
34
+ """Multiply all args; if any becomes 0 (bad or literal zero), result is 0."""
35
+ nums = gather_0(*args)
36
+ if any(n == 0.0 for n in nums):
37
+ return 0.0
38
+ return float(reduce(operator.mul, nums, 1.0))
39
+
40
+ def divide_it(*args):
41
+ """a0 / a1 / a2 / ... ; bad => 0, safe against ZeroDivisionError (returns 0)."""
42
+ nums = gather_0(*args)
43
+ try:
44
+ return float(reduce(operator.truediv, nums))
45
+ except ZeroDivisionError:
46
+ return 0.0
47
+
48
+ def floor_divide_it(*args):
49
+ """a0 // a1 // a2 // ... ; bad => 0, safe against ZeroDivisionError (returns 0)."""
50
+ nums = gather_0(*args)
51
+ try:
52
+ return float(reduce(operator.floordiv, nums))
53
+ except ZeroDivisionError:
54
+ return 0.0
55
+
56
+ # -------------------------------
57
+ # Exponent helpers (deduplicated)
58
+ # -------------------------------
59
+ def exp_it(base, *factors):
60
+ """
61
+ Raise `base` to the power of (product of all `factors`).
62
+ exp_it(10, 2, 3) -> 10 ** (2*3) == 10**6
63
+ If any input is bad or no factors given, returns 0.0 (consistent with other helpers).
64
+ """
65
+ nums = gather_0(base, *factors)
66
+ b, *f = nums
67
+ if not f or any(n == 0.0 for n in nums):
68
+ return 0.0
69
+ exponent = float(reduce(operator.mul, f, 1.0))
70
+ return float(b) ** exponent
71
+
72
+ def pow10(exp):
73
+ """10**exp with float output; bad exp -> 0.0^? -> return 1.0 (neutral for scaling)."""
74
+ if _is_bad(exp):
75
+ return 1.0
76
+ return 10.0 ** float(exp)
77
+
78
+ def scale_pow10(value, exp):
79
+ """Scale value by 10**exp. Neutral if exp is bad."""
80
+ return multiply_it(value, pow10(exp))
81
+
82
+ # Canonical public API for “multiply by 10^…”:
83
+ def exponential(value, *exp_factors):
84
+ """
85
+ Multiply `value` by 10 ** (product(exp_factors)).
86
+ exponential(5, 2, 3) -> 5 * 10**(2*3) == 5e6
87
+ If no exp_factors are given, returns value.
88
+ """
89
+ if not exp_factors:
90
+ return float(value) if not _is_bad(value) else 0.0
91
+ exp_prod = multiply_it(*exp_factors)
92
+ if exp_prod == 0.0 and all(not _is_bad(x) for x in exp_factors):
93
+ # valid inputs produced 0 exponent => scale by 1
94
+ return float(value) if not _is_bad(value) else 0.0
95
+ return scale_pow10(value, exp_prod)
96
+
97
+ # Back-compat alias for legacy callers:
98
+ def exponentials(value, exp=9, num=1):
99
+ """
100
+ Legacy alias: multiply `value` by 10 ** (exp * num).
101
+ Prefer: exponential(value, exp, num) or scale_pow10(value, exp*num).
102
+ """
103
+ return exponential(value, exp, num)
104
+
105
+ # -------------------------------
106
+ # Argument picker
107
+ # -------------------------------
108
+ def get_proper_args(strings, *args, **kwargs):
109
+ """
110
+ Extract values by key order from kwargs first; if missing, consume positional args in order.
111
+ Example: get_proper_args(["a","b"], 1, b=3) -> [1, 3]
112
+ """
113
+ proper = []
114
+ args = list(args)
115
+ for key in strings:
116
+ if key in kwargs:
117
+ proper.append(kwargs[key])
118
+ elif args:
119
+ proper.append(args.pop(0))
120
+ else:
121
+ proper.append(None)
122
+ return proper
123
+
124
+ # -------------------------------
125
+ # Your SOL / token helpers (using the unified expo)
126
+ # -------------------------------
127
+ SOL_DECIMAL_PLACE = 9
128
+ SOL_LAMPORTS = int(pow10(SOL_DECIMAL_PLACE)) # 10**9
129
+
130
+ def get_lamp_difference(*args, **kwargs):
131
+ """
132
+ Keep behavior: compute a lamport “scale” based on digit length of virtualSolReserves.
133
+ """
134
+ sol_lamports = SOL_LAMPORTS
135
+ [virtualSolReserves] = get_proper_args(["virtualSolReserves"], *args, **kwargs)
136
+ if _is_bad(virtualSolReserves):
137
+ return 0
138
+ virtual_len = len(str(int(float(virtualSolReserves))))
139
+ virtual_sol_lamports = int(pow10(virtual_len)) # 10**virtual_len
140
+ scale_len = len(str(int(virtual_sol_lamports / sol_lamports))) if sol_lamports else 0
141
+ return int(pow10(scale_len))
142
+
143
+ def get_price(*args, **kwargs):
144
+ """
145
+ price = virtualSolReserves / virtualTokenReserves / lamp_difference
146
+ """
147
+ virtualSolReserves, virtualTokenReserves = get_proper_args(
148
+ ["virtualSolReserves", "virtualTokenReserves"], *args, **kwargs
149
+ )
150
+ base = divide_it(virtualSolReserves, virtualTokenReserves)
151
+ return divide_it(base, get_lamp_difference(*args, **kwargs))
152
+
153
+ def get_amount_price(*args, **kwargs):
154
+ solAmount, tokenAmount = get_proper_args(["solAmount", "tokenAmount"], *args, **kwargs)
155
+ return divide_it(solAmount, tokenAmount)
156
+
157
+ def getSolAmountUi(*args, **kwargs):
158
+ [solAmount] = get_proper_args(["solAmount"], *args, **kwargs)
159
+ # scale by 10**9
160
+ return exponential(solAmount, SOL_DECIMAL_PLACE)
161
+
162
+ def getTokenAmountUi(*args, **kwargs):
163
+ solAmountUi = getSolAmountUi(*args, **kwargs)
164
+ price = get_price(*args, **kwargs)
165
+ return divide_it(solAmountUi, price)
166
+
167
+ def derive_token_decimals(*args, **kwargs):
168
+ virtualTokenReserves, tokenAmount = get_proper_args(
169
+ ["virtualTokenReserves", "tokenAmount"], *args, **kwargs
170
+ )
171
+ price = get_price(*args, **kwargs)
172
+ if not (virtualTokenReserves and tokenAmount and price) or any(
173
+ float(x) <= 0 for x in [virtualTokenReserves, tokenAmount, price]
174
+ ):
175
+ raise ValueError("All inputs must be positive.")
176
+ derived_token_amount = divide_it(virtualTokenReserves, price)
177
+ ratio = divide_it(derived_token_amount, tokenAmount)
178
+ # count decimal places needed to make ratio an integer (tolerant to fp noise)
179
+ decimals = -1
180
+ while abs(ratio - round(ratio)) > 1e-9:
181
+ ratio *= 10
182
+ decimals += 1
183
+ return decimals
184
+
185
+ def derive_token_decimals_from_token_variables(variables):
186
+ variables["price"] = get_price(**variables)
187
+ derived_token_amount = divide_it(variables["virtualTokenReserves"], variables["price"])
188
+ ratio = divide_it(derived_token_amount, variables["tokenAmount"])
189
+ decimals = -1
190
+ while abs(ratio - round(ratio)) > 1e-9:
191
+ ratio *= 10
192
+ decimals += 1
193
+ variables["tokenDecimals"] = decimals
194
+ return variables
195
+
196
+ def get_token_amount_ui(*args, **kwargs):
197
+ [tokenAmount] = get_proper_args(["tokenAmount"], *args, **kwargs)
198
+ # scale by 10**(-token_decimals)
199
+ dec = derive_token_decimals(*args, **kwargs)
200
+ return exponential(tokenAmount, -dec, 1)
201
+
202
+ def update_token_variables(variables):
203
+ variables['solAmountUi'] = getSolAmountUi(**variables)
204
+ variables['solDecimals'] = SOL_DECIMAL_PLACE
205
+ variables = derive_token_decimals_from_token_variables(variables)
206
+ variables['tokenAmountUi'] = exponential(variables['tokenAmount'], -variables["tokenDecimals"], 1)
207
+ return variables
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_math
3
- Version: 0.0.0.20
3
+ Version: 0.0.0.22
4
4
  Author: putkoff
5
5
  Author-email: partners@abstractendeavors.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,165 +0,0 @@
1
- from abstract_utilities import *
2
- import math
3
- #math functions ------------------------------------------------------------------------------------------------------
4
- def exponential(value,exp=9,num=-1):
5
- return multiply_it(value,exp_it(10,exp,num))
6
-
7
- def add_it(number_1,number_2):
8
- if return_0(number_1,number_2)==float(0):
9
- return float(0)
10
- return float(number_1)+float(number_2)
11
-
12
- def subtract_it(number_1,number_2):
13
- if return_0(number_1,number_2)==float(0):
14
- return float(0)
15
- return float(number_1)-float(number_2)
16
-
17
- def get_percentage(owner_balance,address_balance):
18
- retained_div = divide_it(owner_balance,address_balance)
19
- retained_mul = multiply_it(retained_div,100)
20
- return round(retained_mul,2)
21
-
22
- def return_0(*args):
23
- """Return True if *any* arg is “falsy” (None, non-number, or zero‐like)."""
24
- for arg in args:
25
- if arg is None or not is_number(arg) or str(arg).strip().lower() in ('0', '', 'null'):
26
- return True
27
- return False
28
-
29
- def gather_0(*args):
30
- """Convert any “falsy” arg into float(0), leave others alone."""
31
- cleaned = []
32
- for arg in args:
33
- if arg is None or not is_number(arg) or str(arg).strip().lower() in ('0', '', 'null'):
34
- cleaned.append(0.0)
35
- else:
36
- cleaned.append(float(arg))
37
- return cleaned
38
-
39
- def add_it(*args):
40
- """Sum together any number of args, treating bad values as 0."""
41
- nums = gather_0(*args)
42
- return float(sum(nums))
43
-
44
- def multiply_it(*args):
45
- """Multiply any number of args, but return 0 if any input is ‘bad’ or zero-like."""
46
- nums = gather_0(*args)
47
- if any(n == 0.0 for n in nums):
48
- return 0.0
49
- return float(reduce(operator.mul, nums, 1.0))
50
-
51
- def divide_it(*args):
52
- """
53
- Divide args[0] by args[1] by args[2]…
54
- If any input is bad or you hit a zero‐division, return 0.
55
- """
56
- nums = gather_0(*args)
57
- try:
58
- return float(reduce(operator.truediv, nums))
59
- except ZeroDivisionError:
60
- return 0.0
61
-
62
- def floor_divide_it(*args):
63
- """
64
- Floor‐divide args[0] by args[1] by args[2]…
65
- If any input is bad or you hit a zero‐division, return 0.
66
- """
67
- nums = gather_0(*args)
68
- try:
69
- return float(reduce(operator.floordiv, nums))
70
- except ZeroDivisionError:
71
- return 0.0
72
-
73
- def subtract_it(*args):
74
- """
75
- Subtract all subsequent args from the first:
76
- args[0] - args[1] - args[2] - …
77
- Bad values become 0.
78
- """
79
- nums = gather_0(*args)
80
- if not nums:
81
- return 0.0
82
- return float(reduce(operator.sub, nums))
83
-
84
- def exp_it(base, *factors):
85
- """
86
- Raise `base` to the power of (product of all `factors`).
87
- e.g. exp_it(10, 2, 3) → 10**(2*3) == 10**6
88
- Bad values become 0 (and so the result is 0).
89
- """
90
- nums = gather_0(base, *factors)
91
- b, *f = nums
92
- if return_0(*nums) or not f:
93
- return 0.0
94
- exponent = reduce(operator.mul, f, 1.0)
95
- return float(b) ** exponent
96
-
97
- def exponential(value, *exp_factors):
98
- """
99
- Multiply `value` by 10 to the power of (product of exp_factors).
100
- e.g. exponential(5, 2, 3) → 5 * (10**(2*3)) == 5 * 1_000_000
101
- If you give no exp_factors, it just returns value.
102
- """
103
- power = exp_it(10, *exp_factors) or 1.0
104
- return multiply_it(value, power)
105
-
106
- def get_proper_args(strings,*args,**kwargs):
107
- properArgs = []
108
- for key in strings:
109
- kwarg = kwargs.get(key)
110
- if kwarg == None and args:
111
- kwarg = args[0]
112
- args = [] if len(args) == 1 else args[1:]
113
- properArgs.append(kwarg)
114
- return properArgs
115
- def get_lamp_difference(*args,**kwargs):
116
- sol_lamports =int(exponential(1,exp=9,num=1))
117
- proper_args = get_proper_args(["virtualSolReserves"],*args,**kwargs)
118
- virtualLamports = len(str(proper_args[0]))
119
- virtual_sol_lamports =int(exponential(1,exp=virtualLamports,num=1))
120
- return int(exponential(1,exp=len(str(int(virtual_sol_lamports/sol_lamports))),num=1))
121
- def get_price(*args,**kwargs):
122
- proper_args = get_proper_args(["virtualSolReserves","virtualTokenReserves"],*args,**kwargs)
123
- return divide_it(*proper_args)/get_lamp_difference(*args,**kwargs)
124
- def get_amount_price(*args,**kwargs):
125
- proper_args = get_proper_args(["solAmount","tokenAmount"],*args,**kwargs)
126
- return divide_it(*proper_args)
127
- def getSolAmountUi(*args,**kwargs):
128
- proper_args = get_proper_args(["solAmount"],*args,**kwargs)
129
- return exponential(proper_args[0],9)
130
- def getTokenAmountUi(*args,**kwargs):
131
- solAmountUi = getSolAmountUi(*args,**kwargs)
132
- price = get_price(*args,**kwargs)
133
- return solAmountUi/price
134
- def derive_token_decimals(*args,**kwargs):
135
- proper_args = get_proper_args(["virtualTokenReserves","tokenAmount"],*args,**kwargs)
136
- price = get_price(*args,**kwargs)
137
- if not (proper_args[1] > 0 and proper_args[0] > 0 and price > 0):
138
- raise ValueError("All inputs must be positive.")
139
- derived_token_amount = proper_args[0] / price
140
- ratio = derived_token_amount / proper_args[1]
141
- decimals = -1
142
- while abs(ratio - round(ratio)) > 1e-9:
143
- ratio *= 10
144
- decimals += 1
145
- return decimals
146
- def derive_token_decimals_from_token_variables(variables):
147
- variables["price"] = get_price(**variables)
148
- derived_token_amount = variables["virtualTokenReserves"] / variables["price"]
149
- ratio = derived_token_amount / variables["tokenAmount"]
150
- decimals = -1
151
- while abs(ratio - round(ratio)) > 1e-9:
152
- ratio *= 10
153
- decimals += 1
154
- variables["tokenDecimals"] = decimals
155
- return variables
156
- def get_token_amount_ui(*args,**kwargs):
157
- proper_args = get_proper_args(["tokenAmount"],*args,**kwargs)
158
- return exponential(proper_args[0],exp=-derive_token_decimals(*args,**kwargs),num=1)
159
- def update_token_variables(variables):
160
- variables['solAmountUi'] = getSolAmountUi(**variables)
161
- variables['solDecimals'] = 9
162
- variables = derive_token_decimals_from_token_variables(variables)
163
- variables['tokenAmountUi'] = exponential(variables['tokenAmount'],exp=-variables["tokenDecimals"],num=1)
164
- return variables
165
-