abstract-math 0.0.0.10__tar.gz → 0.0.0.12__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.
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/PKG-INFO +8 -2
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/setup.py +1 -1
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/src/abstract_math/derive_tokens.py +12 -1
- abstract_math-0.0.0.12/src/abstract_math/safe_math.py +101 -0
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/src/abstract_math.egg-info/PKG-INFO +8 -2
- abstract_math-0.0.0.10/src/abstract_math/safe_math.py +0 -209
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/README.md +0 -0
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/pyproject.toml +0 -0
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/setup.cfg +0 -0
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/src/abstract_math/__init__.py +0 -0
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/src/abstract_math.egg-info/SOURCES.txt +0 -0
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/src/abstract_math.egg-info/dependency_links.txt +0 -0
- {abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/src/abstract_math.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: abstract_math
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.12
|
|
4
4
|
Author: putkoff
|
|
5
5
|
Author-email: partners@abstractendeavors.com
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -10,5 +10,11 @@ Classifier: Programming Language :: Python :: 3
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.11
|
|
11
11
|
Requires-Python: >=3.6
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: author-email
|
|
15
|
+
Dynamic: classifier
|
|
16
|
+
Dynamic: description
|
|
17
|
+
Dynamic: description-content-type
|
|
18
|
+
Dynamic: requires-python
|
|
13
19
|
|
|
14
20
|
Safe math for delicate Processes, paralell in use case to SafeMath For SmartContracts in that it is designed to circumvent fatal errors for low level MDAS.
|
|
@@ -59,7 +59,7 @@ def get_token_amount(*args,**kwargs):
|
|
|
59
59
|
return proper_args[0] if proper_args else proper_args
|
|
60
60
|
def get_token_amount_ui(*args,**kwargs):
|
|
61
61
|
token_amount = get_token_amount(*args,**kwargs)
|
|
62
|
-
token_decimals =
|
|
62
|
+
token_decimals = derive_decimals_from_vars(*args,**kwargs)
|
|
63
63
|
return exponential(token_amount,exp=token_decimals)
|
|
64
64
|
#token derivision
|
|
65
65
|
def derive_token_decimals_from_token_variables(**variables):
|
|
@@ -94,4 +94,15 @@ def update_token_variables(variables):
|
|
|
94
94
|
variables = derive_token_decimals_from_token_variables(**variables)
|
|
95
95
|
variables['tokenAmountUi'] = get_token_amount_ui(**variables)
|
|
96
96
|
return variables
|
|
97
|
+
# get the liquidity and sqrt of price
|
|
98
|
+
pool_contract = web3.eth.contract(address=pool_address, abi=v3_pool_abi)
|
|
99
|
+
slot0 = pool_contract.functions.slot0().call()
|
|
100
|
+
sqrt_price_x96 = slot0[0]
|
|
101
|
+
liquidity = pool_contract.functions.liquidity().call()
|
|
97
102
|
|
|
103
|
+
# compute the virtual reserves
|
|
104
|
+
Q96 = 2 ** 96
|
|
105
|
+
Q192 = 2 ** 192
|
|
106
|
+
reserve0_x96 = liquidity * Q192 / sqrt_price_x96
|
|
107
|
+
reserve1_x96 = liquidity * sqrt_price_x96
|
|
108
|
+
token_decimals = math.log10((int(data['virtualTokenReserves']["data"]) * (10**int(9) / (int(data['virtualSolReserves']["data"])) * (int(data['tokenAmount']["data"]) / int(data['solAmount']["data"])))))
|
|
@@ -0,0 +1,101 @@
|
|
|
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 return_0(*args):
|
|
8
|
+
for arg in args:
|
|
9
|
+
if arg == None or not is_number(arg) or arg in [0,'0','','null',' ']:
|
|
10
|
+
return float(0)
|
|
11
|
+
|
|
12
|
+
def exp_it(number,integer,mul):
|
|
13
|
+
if return_0(number,integer,mul)==float(0):
|
|
14
|
+
return float(0)
|
|
15
|
+
return float(number)**float(float(integer)*int(mul))
|
|
16
|
+
|
|
17
|
+
def divide_it(number_1,number_2):
|
|
18
|
+
if return_0(number_1,number_2)==float(0):
|
|
19
|
+
return float(0)
|
|
20
|
+
return float(number_1)/float(number_2)
|
|
21
|
+
|
|
22
|
+
def multiply_it(number_1,number_2):
|
|
23
|
+
if return_0(number_1,number_2)==float(0):
|
|
24
|
+
return float(0)
|
|
25
|
+
return float(number_1)*float(number_2)
|
|
26
|
+
|
|
27
|
+
def add_it(number_1,number_2):
|
|
28
|
+
if return_0(number_1,number_2)==float(0):
|
|
29
|
+
return float(0)
|
|
30
|
+
return float(number_1)+float(number_2)
|
|
31
|
+
|
|
32
|
+
def subtract_it(number_1,number_2):
|
|
33
|
+
if return_0(number_1,number_2)==float(0):
|
|
34
|
+
return float(0)
|
|
35
|
+
return float(number_1)-float(number_2)
|
|
36
|
+
|
|
37
|
+
def get_percentage(owner_balance,address_balance):
|
|
38
|
+
retained_div = divide_it(owner_balance,address_balance)
|
|
39
|
+
retained_mul = multiply_it(retained_div,100)
|
|
40
|
+
return round(retained_mul,2)
|
|
41
|
+
|
|
42
|
+
def get_proper_args(strings,*args,**kwargs):
|
|
43
|
+
properArgs = []
|
|
44
|
+
for key in strings:
|
|
45
|
+
kwarg = kwargs.get(key)
|
|
46
|
+
if kwarg == None and args:
|
|
47
|
+
kwarg = args[0]
|
|
48
|
+
args = [] if len(args) == 1 else args[1:]
|
|
49
|
+
properArgs.append(kwarg)
|
|
50
|
+
return properArgs
|
|
51
|
+
def get_lamp_difference(*args,**kwargs):
|
|
52
|
+
sol_lamports =int(exponential(1,exp=9,num=1))
|
|
53
|
+
proper_args = get_proper_args(["virtualSolReserves"],*args,**kwargs)
|
|
54
|
+
virtualLamports = len(str(proper_args[0]))
|
|
55
|
+
virtual_sol_lamports =int(exponential(1,exp=virtualLamports,num=1))
|
|
56
|
+
return int(exponential(1,exp=len(str(int(virtual_sol_lamports/sol_lamports))),num=1))
|
|
57
|
+
def get_price(*args,**kwargs):
|
|
58
|
+
proper_args = get_proper_args(["virtualSolReserves","virtualTokenReserves"],*args,**kwargs)
|
|
59
|
+
return divide_it(*proper_args)/get_lamp_difference(*args,**kwargs)
|
|
60
|
+
def get_amount_price(*args,**kwargs):
|
|
61
|
+
proper_args = get_proper_args(["solAmount","tokenAmount"],*args,**kwargs)
|
|
62
|
+
return divide_it(*proper_args)
|
|
63
|
+
def getSolAmountUi(*args,**kwargs):
|
|
64
|
+
proper_args = get_proper_args(["solAmount"],*args,**kwargs)
|
|
65
|
+
return exponential(proper_args[0],9)
|
|
66
|
+
def getTokenAmountUi(*args,**kwargs):
|
|
67
|
+
solAmountUi = getSolAmountUi(*args,**kwargs)
|
|
68
|
+
price = get_price(*args,**kwargs)
|
|
69
|
+
return solAmountUi/price
|
|
70
|
+
def derive_token_decimals(*args,**kwargs):
|
|
71
|
+
proper_args = get_proper_args(["virtualTokenReserves","tokenAmount"],*args,**kwargs)
|
|
72
|
+
price = get_price(*args,**kwargs)
|
|
73
|
+
if not (proper_args[1] > 0 and proper_args[0] > 0 and price > 0):
|
|
74
|
+
raise ValueError("All inputs must be positive.")
|
|
75
|
+
derived_token_amount = proper_args[0] / price
|
|
76
|
+
ratio = derived_token_amount / proper_args[1]
|
|
77
|
+
decimals = -1
|
|
78
|
+
while abs(ratio - round(ratio)) > 1e-9:
|
|
79
|
+
ratio *= 10
|
|
80
|
+
decimals += 1
|
|
81
|
+
return decimals
|
|
82
|
+
def derive_token_decimals_from_token_variables(variables):
|
|
83
|
+
variables["price"] = get_price(**variables)
|
|
84
|
+
derived_token_amount = variables["virtualTokenReserves"] / variables["price"]
|
|
85
|
+
ratio = derived_token_amount / variables["tokenAmount"]
|
|
86
|
+
decimals = -1
|
|
87
|
+
while abs(ratio - round(ratio)) > 1e-9:
|
|
88
|
+
ratio *= 10
|
|
89
|
+
decimals += 1
|
|
90
|
+
variables["tokenDecimals"] = decimals
|
|
91
|
+
return variables
|
|
92
|
+
def get_token_amount_ui(*args,**kwargs):
|
|
93
|
+
proper_args = get_proper_args(["tokenAmount"],*args,**kwargs)
|
|
94
|
+
return exponential(proper_args[0],exp=-derive_token_decimals(*args,**kwargs),num=1)
|
|
95
|
+
def update_token_variables(variables):
|
|
96
|
+
variables['solAmountUi'] = getSolAmountUi(**variables)
|
|
97
|
+
variables['solDecimals'] = 9
|
|
98
|
+
variables = derive_token_decimals_from_token_variables(variables)
|
|
99
|
+
variables['tokenAmountUi'] = exponential(variables['tokenAmount'],exp=-variables["tokenDecimals"],num=1)
|
|
100
|
+
return variables
|
|
101
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: abstract_math
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.12
|
|
4
4
|
Author: putkoff
|
|
5
5
|
Author-email: partners@abstractendeavors.com
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -10,5 +10,11 @@ Classifier: Programming Language :: Python :: 3
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.11
|
|
11
11
|
Requires-Python: >=3.6
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: author-email
|
|
15
|
+
Dynamic: classifier
|
|
16
|
+
Dynamic: description
|
|
17
|
+
Dynamic: description-content-type
|
|
18
|
+
Dynamic: requires-python
|
|
13
19
|
|
|
14
20
|
Safe math for delicate Processes, paralell in use case to SafeMath For SmartContracts in that it is designed to circumvent fatal errors for low level MDAS.
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
#abstract_bots.py
|
|
2
|
-
import os
|
|
3
|
-
import re
|
|
4
|
-
import json
|
|
5
|
-
import shutil
|
|
6
|
-
import logging
|
|
7
|
-
logging.basicConfig(level=logging.INFO)
|
|
8
|
-
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s - %(levelname)s - %(message)s')
|
|
9
|
-
logger = logging.getLogger(__name__)
|
|
10
|
-
from abstract_utilities import (safe_dump_to_file,
|
|
11
|
-
safe_read_from_json,
|
|
12
|
-
get_any_value,
|
|
13
|
-
make_list,
|
|
14
|
-
eatAll)
|
|
15
|
-
#json functions-----------------------------------------------------------------------------------------------------------------------------------------
|
|
16
|
-
def safe_json_loads(data):
|
|
17
|
-
if not isinstance(data, (dict, str)):
|
|
18
|
-
data = str(data)
|
|
19
|
-
if not isinstance(data, dict):
|
|
20
|
-
try:
|
|
21
|
-
data = json.loads(data)
|
|
22
|
-
except json.JSONDecodeError:
|
|
23
|
-
logger.error("Error parsing data with json, data might not be in correct format.")
|
|
24
|
-
data = None
|
|
25
|
-
return data
|
|
26
|
-
|
|
27
|
-
def load_json_data(file_path):
|
|
28
|
-
try:
|
|
29
|
-
with file_path.open('r') as file:
|
|
30
|
-
return json.load(file)
|
|
31
|
-
except json.JSONDecodeError as e:
|
|
32
|
-
logger.error(f"Error reading JSON file: {e}")
|
|
33
|
-
return None
|
|
34
|
-
|
|
35
|
-
def safe_list(obj,keys):
|
|
36
|
-
keys = make_list(keys)
|
|
37
|
-
for key in keys:
|
|
38
|
-
if obj and isinstance(obj,list) and is_number(key) and len(obj)>key:
|
|
39
|
-
obj = obj[int(key)]
|
|
40
|
-
else:
|
|
41
|
-
return obj
|
|
42
|
-
return obj
|
|
43
|
-
|
|
44
|
-
def safe_get(obj,keys):
|
|
45
|
-
keys = make_list(keys)
|
|
46
|
-
new_obj = obj
|
|
47
|
-
for i,key in enumerate(keys):
|
|
48
|
-
if isinstance(new_obj,dict):
|
|
49
|
-
new_obj = new_obj.get(key,None if len(keys)-1 == i else {})
|
|
50
|
-
elif isinstance(new_obj,list):
|
|
51
|
-
new_obj = safe_list(new_obj,key)
|
|
52
|
-
else:
|
|
53
|
-
return new_obj
|
|
54
|
-
return new_obj
|
|
55
|
-
|
|
56
|
-
def get_all_keys(dict_data,keys=[]):
|
|
57
|
-
if isinstance(dict_data,dict):
|
|
58
|
-
for key,value in dict_data.items():
|
|
59
|
-
keys.append(key)
|
|
60
|
-
keys = get_all_keys(value,keys=keys)
|
|
61
|
-
return keys
|
|
62
|
-
#address sanitation-----------------------------------------------------------------------------------------------
|
|
63
|
-
def get_data(file_path):
|
|
64
|
-
if os.path.isfile(file_path):
|
|
65
|
-
return safe_read_from_json(file_path)
|
|
66
|
-
|
|
67
|
-
#directory functions --------------------------------------------------------------------------------------------
|
|
68
|
-
def move_file(src_path,dst_file_path):
|
|
69
|
-
shutil.move(str(src_path), str(dst_file_path))
|
|
70
|
-
logger.info(f"Moved {src_path.name} to errored messages directory.")
|
|
71
|
-
|
|
72
|
-
def secure_delete(file_path):
|
|
73
|
-
try:
|
|
74
|
-
if os.path.exists(file_path):
|
|
75
|
-
os.remove(file_path)
|
|
76
|
-
logger.info(f"File {file_path} has been deleted.")
|
|
77
|
-
else:
|
|
78
|
-
logger.warning(f"File {file_path} does not exist.")
|
|
79
|
-
except OSError as e:
|
|
80
|
-
logger.error(f"Error deleting file {file_path}: {e.strerror}")
|
|
81
|
-
|
|
82
|
-
def make_directory(file_path):
|
|
83
|
-
os.makedirs(file_path, exist_ok=True)
|
|
84
|
-
return file_path
|
|
85
|
-
|
|
86
|
-
def get_create_data(file_path,data={}):
|
|
87
|
-
if not os.path.isfile(file_path):
|
|
88
|
-
safe_dump_to_file(data=data,file_path=file_path)
|
|
89
|
-
return safe_read_from_json(file_path)
|
|
90
|
-
|
|
91
|
-
#type functions --------------------------------------------------------------------------------------------------
|
|
92
|
-
def get_args_send_args(function, *args):
|
|
93
|
-
if not args:
|
|
94
|
-
return args
|
|
95
|
-
input_type = type(args[0])
|
|
96
|
-
flattened_args = []
|
|
97
|
-
for arg in args:
|
|
98
|
-
if isinstance(arg, (list, set, tuple)):
|
|
99
|
-
flattened_args.extend(arg)
|
|
100
|
-
else:
|
|
101
|
-
flattened_args.append(arg)
|
|
102
|
-
processed_items = [function(item) for item in flattened_args]
|
|
103
|
-
if input_type is list:
|
|
104
|
-
return processed_items
|
|
105
|
-
elif input_type is set:
|
|
106
|
-
return set(processed_items)
|
|
107
|
-
elif input_type is tuple:
|
|
108
|
-
return tuple(processed_items)
|
|
109
|
-
else:
|
|
110
|
-
# Assuming if_single_obj is a function that handles single objects
|
|
111
|
-
return if_single_obj(processed_items)
|
|
112
|
-
|
|
113
|
-
def list_set(obj):
|
|
114
|
-
obj = obj or []
|
|
115
|
-
return list(set(obj))
|
|
116
|
-
|
|
117
|
-
def get_symetric_difference(obj_1,obj_2):
|
|
118
|
-
set1 = set(obj_1)
|
|
119
|
-
set2 = set(obj_2)
|
|
120
|
-
# Find elements that are unique to each list
|
|
121
|
-
unique_elements = set1.symmetric_difference(set2)
|
|
122
|
-
# Convert the set back to a list, if needed
|
|
123
|
-
return list(unique_elements)
|
|
124
|
-
|
|
125
|
-
def if_single_obj(list_obj):
|
|
126
|
-
if list_obj and isinstance(list_obj,list) and len(list_obj)==1:
|
|
127
|
-
list_obj = list_obj[0]
|
|
128
|
-
return list_obj
|
|
129
|
-
|
|
130
|
-
def list_set(obj):
|
|
131
|
-
try:
|
|
132
|
-
obj = list(set(obj))
|
|
133
|
-
except Exception as e:
|
|
134
|
-
print(f"{e}")
|
|
135
|
-
return obj
|
|
136
|
-
|
|
137
|
-
def str_lower(obj):
|
|
138
|
-
try:
|
|
139
|
-
obj=str(obj).lower()
|
|
140
|
-
except Exception as e:
|
|
141
|
-
print(f"{e}")
|
|
142
|
-
return obj
|
|
143
|
-
|
|
144
|
-
def is_number(obj):
|
|
145
|
-
try:
|
|
146
|
-
float(obj)
|
|
147
|
-
return True
|
|
148
|
-
except (ValueError, TypeError):
|
|
149
|
-
return False
|
|
150
|
-
#address functions-------------------------------------------------------------------------------------------------
|
|
151
|
-
def normalize_address(address):
|
|
152
|
-
address =str(address).lower()
|
|
153
|
-
if address.startswith('0x'):
|
|
154
|
-
address = address[2:]
|
|
155
|
-
return address
|
|
156
|
-
|
|
157
|
-
def normalize_all_addresses(*args):
|
|
158
|
-
return get_args_send_args(normalize_address,*args)
|
|
159
|
-
|
|
160
|
-
def serialize_all_addresses(*args):
|
|
161
|
-
return get_args_send_args(check_and_reserialize_solana_address, *args)
|
|
162
|
-
|
|
163
|
-
def make_directory(data_path):
|
|
164
|
-
os.makedirs(data_path, exist_ok=True)
|
|
165
|
-
return data_path
|
|
166
|
-
|
|
167
|
-
def get_amount_dict(amount,decimals=9):
|
|
168
|
-
if amount!= None:
|
|
169
|
-
if isinstance(amount,dict):
|
|
170
|
-
amount_dict = get_any_value(amount,'uiTokenAmount')
|
|
171
|
-
amount = get_any_value(amount_dict,'amount')
|
|
172
|
-
decimals = get_any_value(amount_dict,'decimals')
|
|
173
|
-
return exponential(amount,decimals,-1)
|
|
174
|
-
#math functions ------------------------------------------------------------------------------------------------------
|
|
175
|
-
def exponential(value,exp=9,num=-1):
|
|
176
|
-
return multiply_it(value,exp_it(10,exp,num))
|
|
177
|
-
|
|
178
|
-
def return_0(*args):
|
|
179
|
-
for arg in args:
|
|
180
|
-
if arg == None or not is_number(arg) or arg in [0,'0','','null',' ']:
|
|
181
|
-
return float(0)
|
|
182
|
-
|
|
183
|
-
def exp_it(number,integer,mul):
|
|
184
|
-
if return_0(number,integer,mul)==float(0):
|
|
185
|
-
return float(0)
|
|
186
|
-
return float(number)**float(float(integer)*int(mul))
|
|
187
|
-
|
|
188
|
-
def divide_it(number_1,number_2):
|
|
189
|
-
if return_0(number_1,number_2)==float(0):
|
|
190
|
-
return float(0)
|
|
191
|
-
return float(number_1)/float(number_2)
|
|
192
|
-
|
|
193
|
-
def multiply_it(number_1,number_2):
|
|
194
|
-
if return_0(number_1,number_2)==float(0):
|
|
195
|
-
return float(0)
|
|
196
|
-
return float(number_1)*float(number_2)
|
|
197
|
-
|
|
198
|
-
def add_it(number_1,number_2):
|
|
199
|
-
if return_0(number_1,number_2)==float(0):
|
|
200
|
-
return float(0)
|
|
201
|
-
return float(number_1)+float(number_2)
|
|
202
|
-
|
|
203
|
-
def get_percentage(owner_balance,address_balance):
|
|
204
|
-
retained_div = divide_it(owner_balance,address_balance)
|
|
205
|
-
retained_mul = multiply_it(retained_div,100)
|
|
206
|
-
return round(retained_mul,2)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abstract_math-0.0.0.10 → abstract_math-0.0.0.12}/src/abstract_math.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|