abstract-math 0.0.0.15__tar.gz → 0.0.0.17__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_math
3
- Version: 0.0.0.15
3
+ Version: 0.0.0.17
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.15',
7
+ version='0.0.0.17',
8
8
  author='putkoff',
9
9
  author_email='partners@abstractendeavors.com',
10
10
  description="",
@@ -0,0 +1,141 @@
1
+ from decimal import Decimal, getcontext
2
+ from .safe_math import *
3
+
4
+ # Set high precision for decimal operations
5
+ getcontext().prec = 50
6
+
7
+ # Constants for SOL decimal places and lamports conversion
8
+ SOL_DECIMAL_PLACE = 9
9
+ SOL_LAMPORTS = sol_lamports = int(exponential(1, SOL_DECIMAL_PLACE, 1))
10
+
11
+
12
+ def get_proper_args(strings, *args, **kwargs):
13
+ """
14
+ Extracts values from kwargs based on the provided keys (strings). If not present in kwargs,
15
+ falls back to positional args in order.
16
+ """
17
+ properArgs = []
18
+ for key in strings:
19
+ kwarg = kwargs.get(key)
20
+ if kwarg is None and args:
21
+ kwarg = args[0]
22
+ args = [] if len(args) == 1 else args[1:]
23
+ properArgs.append(kwarg)
24
+ return properArgs
25
+
26
+ # Lamports calculations
27
+
28
+ def get_lamports(integer):
29
+ """
30
+ Given an integer representing SOL, returns lamports (10^(digits_in_integer+1)).
31
+ """
32
+ return exp_it(10, len(str(integer)) + 1, 1)
33
+
34
+
35
+ def get_lamport_difference(lamports, virtual_lamports):
36
+ """
37
+ Compares actual lamports to virtual lamports and returns the corresponding exponent-based difference.
38
+ """
39
+ integer = int(virtual_lamports / lamports)
40
+ exp = len(str(integer))
41
+ return int(exponential(1, exp, 1))
42
+
43
+ # Virtual reserves and ratios
44
+
45
+ def get_vitual_reserves(*args, **kwargs):
46
+ return get_proper_args(["virtualSolReserves", "virtualTokenReserves"], *args, **kwargs)
47
+
48
+
49
+ def get_virtual_reserve_ratio(*args, **kwargs):
50
+ sol_res, token_res = get_vitual_reserves(*args, **kwargs)
51
+ return divide_it(sol_res, token_res)
52
+
53
+ # SOL-specific calculations
54
+
55
+ def get_virtual_sol_reservs(*args, **kwargs):
56
+ reserves = get_proper_args(["virtualSolReserves"], *args, **kwargs)
57
+ return reserves[0] if reserves else None
58
+
59
+
60
+ def get_virtual_sol_lamports(*args, **kwargs):
61
+ sol_res = get_virtual_sol_reservs(*args, **kwargs)
62
+ return get_lamports(sol_res)
63
+
64
+
65
+ def get_virtual_sol_lamp_difference(*args, **kwargs):
66
+ v_lam = get_virtual_sol_lamports(*args, **kwargs)
67
+ return get_lamport_difference(SOL_LAMPORTS, v_lam)
68
+
69
+ # SOL amount conversions
70
+
71
+ def get_sol_amount(*args, **kwargs):
72
+ amounts = get_proper_args(["solAmount"], *args, **kwargs)
73
+ return amounts[0] if amounts else None
74
+
75
+
76
+ def getSolAmountUi(*args, **kwargs):
77
+ sol_amt = get_sol_amount(*args, **kwargs)
78
+ return exponential(sol_amt, SOL_DECIMAL_PLACE)
79
+
80
+ # Token-specific calculations
81
+
82
+ def get_virtual_token_reserves(*args, **kwargs):
83
+ reserves = get_proper_args(["virtualTokenReserves"], *args, **kwargs)
84
+ return reserves[0] if reserves else None
85
+
86
+
87
+ def get_virtual_token_lamports(*args, **kwargs):
88
+ token_res = get_virtual_token_reserves(*args, **kwargs)
89
+ return get_lamports(token_res)
90
+
91
+
92
+ def get_token_amount(*args, **kwargs):
93
+ amounts = get_proper_args(["tokenAmount"], *args, **kwargs)
94
+ return amounts[0] if amounts else None
95
+
96
+
97
+ def get_token_amount_ui(*args, **kwargs):
98
+ token_amt = get_token_amount(*args, **kwargs)
99
+ token_decimals = derive_decimals_from_vars(*args, **kwargs)
100
+ return exponential(token_amt, token_decimals)
101
+
102
+
103
+ def derive_token_decimals_from_token_variables(**variables):
104
+ variables["price"] = get_price(**variables)
105
+ variables["tokenDecimals"] = derive_decimals_from_vars(**variables)
106
+ return variables
107
+
108
+
109
+ def get_derived_token_ratio(*args, **kwargs):
110
+ derived_amt = derive_token_amount(*args, **kwargs)
111
+ token_amt = get_token_amount(*args, **kwargs)
112
+ return divide_it(derived_amt, token_amt)
113
+
114
+
115
+ def derive_token_amount(*args, **kwargs):
116
+ token_res = get_virtual_token_reserves(*args, **kwargs)
117
+ price = get_price(*args, **kwargs)
118
+ return divide_it(token_res, price)
119
+
120
+
121
+ def get_price(*args, **kwargs):
122
+ reserve_ratio = get_virtual_reserve_ratio(*args, **kwargs)
123
+ sol_diff = get_virtual_sol_lamp_difference(*args, **kwargs)
124
+ return divide_it(reserve_ratio, sol_diff)
125
+
126
+
127
+ def derive_decimals_from_vars(*args, **kwargs):
128
+ ratio = get_derived_token_ratio(*args, **kwargs)
129
+ decimals = -1
130
+ while abs(ratio - round(ratio)) > 1e-9:
131
+ ratio *= 10
132
+ decimals += 1
133
+ return decimals
134
+
135
+
136
+ def update_token_variables(variables):
137
+ variables['solAmountUi'] = getSolAmountUi(**variables)
138
+ variables['solDecimals'] = SOL_DECIMAL_PLACE
139
+ variables = derive_token_decimals_from_token_variables(**variables)
140
+ variables['tokenAmountUi'] = get_token_amount_ui(**variables)
141
+ return variables
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_math
3
- Version: 0.0.0.15
3
+ Version: 0.0.0.17
4
4
  Author: putkoff
5
5
  Author-email: partners@abstractendeavors.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,96 +0,0 @@
1
- from decimal import Decimal, getcontext
2
- from .safe_math import *
3
- getcontext().prec = 50 # High precision for accuracy
4
- SOL_DECIMAL_PLACE = 9
5
- SOL_LAMPORTS = sol_lamports =int(exponential(1,exp=SOL_DECIMAL_PLACE,num=1))
6
- def get_proper_args(strings,*args,**kwargs):
7
- properArgs = []
8
- for key in strings:
9
- kwarg = kwargs.get(key)
10
- if kwarg == None and args:
11
- kwarg = args[0]
12
- args = [] if len(args) == 1 else args[1:]
13
- properArgs.append(kwarg)
14
- return properArgs
15
-
16
- #lamports
17
- def get_lamports(integer):
18
- return exp_it(10,len(str(integer))+1,1)
19
- def get_lamport_difference(lamports,virtual_lamports):
20
- integer = int(virtual_lamports/lamports)
21
- exp = len(str(integer))
22
- return int(exponential(1,exp=exp,num=1))
23
- #virtual reserves
24
- def get_vitual_reserves(*args,**kwargs):
25
- proper_args = get_proper_args(["virtualSolReserves","virtualTokenReserves"],*args,**kwargs)
26
- return proper_args
27
- def get_virtual_reserve_ratio(*args,**kwargs):
28
- proper_args = get_vitual_reserves(*args,**kwargs)
29
- return divide_it(*proper_args)
30
- #sol reserves
31
- def get_virtual_sol_reservs(*args,**kwargs):
32
- proper_args = get_proper_args(["virtualSolReserves"],*args,**kwargs)
33
- return proper_args[0] if proper_args else proper_args
34
- def get_virtual_sol_lamports(*args,**kwargs):
35
- virtual_sol_reserves = get_virtual_sol_reservs(*args,**kwargs)
36
- virtual_sol_lamports = get_lamports(virtual_sol_reserves)
37
- return virtual_sol_lamports
38
- def get_virtual_sol_lamp_difference(*args,**kwargs):
39
- virtual_sol_lamports = get_virtual_sol_lamports(*args,**kwargs)
40
- return get_lamport_difference(SOL_LAMPORTS,virtual_sol_lamports)
41
- #sol Amount
42
- def get_sol_amount(*args,**kwargs):
43
- proper_args = get_proper_args(["solAmount"],*args,**kwargs)
44
- return proper_args[0] if proper_args else proper_args
45
- def getSolAmountUi(*args,**kwargs):
46
- sol_amount = get_sol_amount(*args,**kwargs)
47
- return exponential(sol_amount,SOL_DECIMAL_PLACE)
48
- #token reserves
49
- def get_virtual_token_reserves(*args,**kwargs):
50
- proper_args = get_proper_args(["virtualTokenReserves"],*args,**kwargs)
51
- return proper_args[0] if proper_args else proper_args
52
- def get_virtual_token_lamports(*args,**kwargs):
53
- virtual_token_reserves = get_virtual_token_reserves(*args,**kwargs)
54
- virtual_token_lamports = get_lamports(virtual_token_reserves)
55
- return virtual_token_lamports
56
- #token amount
57
- def get_token_amount(*args,**kwargs):
58
- proper_args = get_proper_args(["tokenAmount"],*args,**kwargs)
59
- return proper_args[0] if proper_args else proper_args
60
- def get_token_amount_ui(*args,**kwargs):
61
- token_amount = get_token_amount(*args,**kwargs)
62
- token_decimals = derive_decimals_from_vars(*args,**kwargs)
63
- return exponential(token_amount,exp=token_decimals)
64
- #token derivision
65
- def derive_token_decimals_from_token_variables(**variables):
66
- variables["price"] = get_price(**variables)
67
- variables["tokenDecimals"] = derive_decimals_from_vars(**variables)
68
- return variables
69
- def get_derived_token_ratio(*args,**kwargs):
70
- derived_token_amount = derive_token_amount(*args,**kwargs)
71
- token_amount = get_token_amount(*args,**kwargs)
72
- ratio = divide_it(derived_token_amount,token_amount)
73
- return ratio
74
- def derive_token_amount(*args,**kwargs):
75
- virtual_token_reserves = get_virtual_token_reserves(*args,**kwargs)
76
- price = get_price(*args,**kwargs)
77
- derived_token_amount = divide_it(virtual_token_reserves,price)
78
- return derived_token_amount
79
- #derive variables
80
- def get_price(*args,**kwargs):
81
- reserve_ratios = get_virtual_reserve_ratio(*args,**kwargs)
82
- virtual_sol_lamp_difference = get_virtual_sol_lamp_difference(*args,**kwargs)
83
- return reserve_ratios/virtual_sol_lamp_difference
84
- def derive_decimals_from_vars(*args,**kwargs):
85
- ratio = get_derived_token_ratio(*args,**kwargs)
86
- decimals = -1
87
- while abs(ratio - round(ratio)) > 1e-9:
88
- ratio *= 10
89
- decimals += 1
90
- return decimals
91
- def update_token_variables(variables):
92
- variables['solAmountUi'] = getSolAmountUi(**variables)
93
- variables['solDecimals'] = 9
94
- variables = derive_token_decimals_from_token_variables(**variables)
95
- variables['tokenAmountUi'] = get_token_amount_ui(**variables)
96
- return variables