defi-state-querier 0.5.9__py3-none-any.whl → 0.5.10__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- defi_services/__init__.py +1 -1
- defi_services/constants/network_constants.py +24 -12
- defi_services/constants/ton_decimals_constant.py +1039 -0
- defi_services/jobs/processors/cosmos_state_processor.py +3 -0
- defi_services/jobs/processors/ton_state_processor.py +54 -0
- defi_services/jobs/queriers/ton_state_querier.py +34 -0
- defi_services/utils/ton_decode_address.py +11 -0
- {defi_state_querier-0.5.9.dist-info → defi_state_querier-0.5.10.dist-info}/METADATA +1 -1
- {defi_state_querier-0.5.9.dist-info → defi_state_querier-0.5.10.dist-info}/RECORD +12 -8
- {defi_state_querier-0.5.9.dist-info → defi_state_querier-0.5.10.dist-info}/WHEEL +1 -1
- {defi_state_querier-0.5.9.dist-info → defi_state_querier-0.5.10.dist-info}/LICENSE +0 -0
- {defi_state_querier-0.5.9.dist-info → defi_state_querier-0.5.10.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,10 @@
|
|
1
|
+
import logging
|
2
|
+
|
1
3
|
from defi_services.constants.cosmos_decimals_constant import Denoms, MulticallContract
|
2
4
|
from defi_services.constants.network_constants import Chains
|
3
5
|
from defi_services.services.cosmos_token_services import CosmosTokenServices
|
4
6
|
|
7
|
+
logger = logging.getLogger("CosmosStateProcessor")
|
5
8
|
|
6
9
|
class CosmosStateProcessor:
|
7
10
|
def __init__(self, lcd: str, rest_uri: str = None, chain_id: str = Chains.oraichain):
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
from src.defi_services.constants.ton_decimals_constant import TonTokens
|
4
|
+
from defi_services.constants.network_constants import Chains, NATIVE_TOKEN, NATIVE_TOKENS
|
5
|
+
from defi_services.jobs.queriers.ton_state_querier import TonStateQuerier
|
6
|
+
|
7
|
+
logger = logging.getLogger("CosmosStateProcessor")
|
8
|
+
|
9
|
+
class TonStateProcessor:
|
10
|
+
def __init__(self, provider_uri: str, chain_id: str = Chains.ton):
|
11
|
+
self.chain_id = chain_id
|
12
|
+
self.provider_uri = provider_uri
|
13
|
+
self.state_querier = TonStateQuerier(self.provider_uri)
|
14
|
+
|
15
|
+
|
16
|
+
def get_token_balance(self, address, tokens):
|
17
|
+
result = {}
|
18
|
+
if NATIVE_TOKENS[self.chain_id] in tokens:
|
19
|
+
native_response = self.state_querier.query_ton_coin_balances(address)
|
20
|
+
native_balance = native_response.get("result", 0)
|
21
|
+
result[NATIVE_TOKENS[self.chain_id]] = float(native_balance) / 10**9
|
22
|
+
|
23
|
+
response = self.state_querier.query_jetton_coin_balances(address)
|
24
|
+
for token_balance in response:
|
25
|
+
jetton = token_balance.get('jetton').lower()[2:]
|
26
|
+
if jetton not in TonTokens.mapping:
|
27
|
+
continue
|
28
|
+
token_address = TonTokens.mapping.get(jetton).get("address")
|
29
|
+
if token_address not in tokens:
|
30
|
+
continue
|
31
|
+
decimals = TonTokens.mapping.get(jetton).get("decimals")
|
32
|
+
balance = token_balance.get('balance', 0)
|
33
|
+
result[token_address] = float(balance) / 10**decimals
|
34
|
+
|
35
|
+
return result
|
36
|
+
|
37
|
+
def run(self, address: str, queries: list, *args, **kwargs):
|
38
|
+
result = []
|
39
|
+
tokens = [query.get('entity_id') for query in queries if query.get('query_type') == 'token_balance']
|
40
|
+
token_balances = self.get_token_balance(address, tokens)
|
41
|
+
for query in queries:
|
42
|
+
query_id = query.get("query_id")
|
43
|
+
entity_id = query.get("entity_id")
|
44
|
+
query_type = query.get("query_type")
|
45
|
+
if query_type != "token_balance":
|
46
|
+
continue
|
47
|
+
|
48
|
+
result.append(
|
49
|
+
{"query_id": query_id,
|
50
|
+
"query_type": query_type,
|
51
|
+
"entity_id": entity_id,
|
52
|
+
"token_balance": token_balances.get(entity_id, 0)
|
53
|
+
})
|
54
|
+
return result
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import json
|
2
|
+
import logging
|
3
|
+
import requests
|
4
|
+
|
5
|
+
logger = logging.getLogger("TonStateQuerier")
|
6
|
+
|
7
|
+
|
8
|
+
class TonStateQuerier:
|
9
|
+
def __init__(self, provider_uri):
|
10
|
+
self.provider_uri = provider_uri
|
11
|
+
if provider_uri[-1] != '/':
|
12
|
+
self.provider_uri +='/'
|
13
|
+
|
14
|
+
def query_jetton_coin_balances(self, address: str, limit: int = 256, offset: int = 0, pages: int = None):
|
15
|
+
responses = []
|
16
|
+
while True:
|
17
|
+
endpoint = f"{self.provider_uri}v3/jetton/wallets?owner_address={address}&limit={limit}&offset={offset}"
|
18
|
+
response = requests.get(endpoint).content
|
19
|
+
results = json.loads(response)
|
20
|
+
if results.get('jetton_wallets'):
|
21
|
+
responses += results.get('jetton_wallets')
|
22
|
+
offset += 1
|
23
|
+
if pages and offset == pages:
|
24
|
+
break
|
25
|
+
else:
|
26
|
+
break
|
27
|
+
|
28
|
+
return responses
|
29
|
+
|
30
|
+
def query_ton_coin_balances(self, address: str):
|
31
|
+
endpoint = f"{self.provider_uri}v2/getAddressBalance?address={address}"
|
32
|
+
response = requests.get(endpoint).content
|
33
|
+
result = json.loads(response)
|
34
|
+
return result
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import base64
|
2
|
+
import binascii
|
3
|
+
# Base64 URL-safe string
|
4
|
+
def decode_base64_url_safe_to_hex(base64_url_safe):
|
5
|
+
# Step 1: Convert Base64 URL-safe to Base64
|
6
|
+
base64_standard = base64_url_safe.replace('-', '+').replace('_', '/')
|
7
|
+
# Step 2: Decode Base64 to Bytes
|
8
|
+
bytes_data = base64.b64decode(base64_standard)
|
9
|
+
# Step 3: Convert Bytes to Hexadecimal
|
10
|
+
hex_string = binascii.hexlify(bytes_data).decode('utf-8')
|
11
|
+
return hex_string
|
@@ -1,4 +1,4 @@
|
|
1
|
-
defi_services/__init__.py,sha256=
|
1
|
+
defi_services/__init__.py,sha256=1nlPInsRzDbcDPveZ3ghSJ6v6KveN9n6gnj-twW4DkI,23
|
2
2
|
defi_services/abis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
defi_services/abis/multicall_v3_abi.py,sha256=0aPxjrJJFU17fODjvYFRDn5Y5J1yi_AJKc8v1uohNGY,12352
|
4
4
|
defi_services/abis/dex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -298,10 +298,11 @@ defi_services/constants/chain_constant.py,sha256=llTCq697jtt64a_6QRxZK71Q3SMeoIy
|
|
298
298
|
defi_services/constants/cosmos_decimals_constant.py,sha256=SjFkFbkvxVAk0jtok_1EaBh69ZE8S1fFAbVn6bdJO4s,13635
|
299
299
|
defi_services/constants/db_constant.py,sha256=gDMFFjhPOgQHuS9sPOTFbsfSdIfdWQEE4tGlxHQhNsE,2566
|
300
300
|
defi_services/constants/mongo_constant.py,sha256=qsDIq2Gg5MkBGaEOh4Fd9y6fOOidF4gGPnQwtaPon3E,398
|
301
|
-
defi_services/constants/network_constants.py,sha256=
|
301
|
+
defi_services/constants/network_constants.py,sha256=auU5xbj7fzRurcyOqJxjeTL8XiIO0wf15Yzyzc_IxNQ,14016
|
302
302
|
defi_services/constants/query_constant.py,sha256=6HSK5IToUQpKLqmTeCgKf0npwmog7GWFUmQpz_mbkgY,1088
|
303
303
|
defi_services/constants/time_constant.py,sha256=bC-0pYnfIFFR_0iVvkxhfyHfOclWNw9O3DbdO_nh258,181
|
304
304
|
defi_services/constants/token_constant.py,sha256=dGO_i-L_LLx4mSA0wIG4FoaL-OWOAd5bp6k7VucUjUQ,4965
|
305
|
+
defi_services/constants/ton_decimals_constant.py,sha256=zMbbiIi2a9ZQSHEt8tLY0FnQtMi1qybkXMeFkKeEw3g,50657
|
305
306
|
defi_services/constants/entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
306
307
|
defi_services/constants/entities/dex_constant.py,sha256=oCt8RS-0KjFW5zR5IU1Ys49nYCCAraY8pTivOpXoyvs,343
|
307
308
|
defi_services/constants/entities/dex_info_constant.py,sha256=6sLHxCmRz_6HW8WRe27FkOS-FGR-zC354iCTcEIjp78,1604
|
@@ -313,17 +314,19 @@ defi_services/constants/entities/vault_services.py,sha256=IMmQc15wS1KA7EuQqM_Ara
|
|
313
314
|
defi_services/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
314
315
|
defi_services/jobs/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
315
316
|
defi_services/jobs/processors/call_state_processor.py,sha256=WseX0OaMA5D_ANYofrz7W2BooSMdHlGRay4NuiABmM4,436
|
316
|
-
defi_services/jobs/processors/cosmos_state_processor.py,sha256=
|
317
|
+
defi_services/jobs/processors/cosmos_state_processor.py,sha256=eVAs_-dSjlR7ijHAG9ytAysGesiyQYyK-sAMg8rUPYw,1898
|
317
318
|
defi_services/jobs/processors/multi_call_state_processor.py,sha256=AksswGMSyStbnvkQcBVb0Y2tdpkUgc1CWoeSiMpGy8U,462
|
318
319
|
defi_services/jobs/processors/multi_state_processor.py,sha256=Od7Y8zPz7xj0L-_0YuK4wg_94fX8Q1PquuKUUYteIJU,5731
|
319
320
|
defi_services/jobs/processors/solana_state_processor.py,sha256=szsBYrkEV8kBzuA_iaSVescnwKJ2MHoTbut5kORbWTs,4065
|
320
321
|
defi_services/jobs/processors/state_processor.py,sha256=Ze_5isU_l_APB262E-VV_4KZwEG6W0XE6PikJZIcAoM,7291
|
321
322
|
defi_services/jobs/processors/substrate_state_processor.py,sha256=KkiY1NkaxnizNJBTfn4twB-zuQo3fT3akOlbie8VF5g,3940
|
323
|
+
defi_services/jobs/processors/ton_state_processor.py,sha256=suVoMEM0L5Wai3KWaNl-A4DU8Nq25Jhr5_7VcmsIfaY,2251
|
322
324
|
defi_services/jobs/queriers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
323
325
|
defi_services/jobs/queriers/call_state_querier.py,sha256=sxKXNpI6pOHAqHZ0jaLuxDX6Izka6IqBSWpbtu_o5FY,4820
|
324
326
|
defi_services/jobs/queriers/solana_state_querier.py,sha256=TQELYo6GUoF8s-LfetqYbclNaH8bakQqC7y2ifACIb8,3239
|
325
327
|
defi_services/jobs/queriers/state_querier.py,sha256=q7cAW395urZjcWTpqw8m_nDunLyyTuAXJ3DRx_1HOxo,7384
|
326
328
|
defi_services/jobs/queriers/substrate_state_querier.py,sha256=_T0Dk06sP_uBKaxgj2J_EBtJDoq-hi8jU7Np4iuO0LA,3858
|
329
|
+
defi_services/jobs/queriers/ton_state_querier.py,sha256=IkCMGwFgERcX7M_DzBxHxD-nKzbwSWrg8gxuKSERiJw,1148
|
327
330
|
defi_services/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
328
331
|
defi_services/services/cosmos_token_services.py,sha256=pRw_rEhoofd6V1-KwU74ZHjhg6PsXSznK6eD1ASyROA,5108
|
329
332
|
defi_services/services/dex_protocol_services.py,sha256=J93P7kwy1v98aeA95ErT7jDCCOAelFuCNiTXl3PVFFo,6656
|
@@ -464,8 +467,9 @@ defi_services/utils/market_service.py,sha256=imPtPHBkpEx5JnhqeIWYqbCjsIEm8IKBYHN
|
|
464
467
|
defi_services/utils/memory_storage.py,sha256=BOT8laB0iVSCGE-oDlpWJQLbSC6X2blKX4zuQbs4inc,851
|
465
468
|
defi_services/utils/sqrt_price_math.py,sha256=9lgUeWFT4wjl3Vq3b7-jZ2bGvvZx7dDBSfVnM3lsZ8o,5575
|
466
469
|
defi_services/utils/thread_proxy.py,sha256=5Z8biAyEReUkh3vfJSvEv7GwMe3CsE5M8CbghkQtePw,2951
|
467
|
-
|
468
|
-
defi_state_querier-0.5.
|
469
|
-
defi_state_querier-0.5.
|
470
|
-
defi_state_querier-0.5.
|
471
|
-
defi_state_querier-0.5.
|
470
|
+
defi_services/utils/ton_decode_address.py,sha256=EWKwmC7KtbXpdKgiNK-5j-5lX7fCr17I4EWYs9b43eU,443
|
471
|
+
defi_state_querier-0.5.10.dist-info/LICENSE,sha256=6jmfxa8nUIwfKnzZUxAHJSJ_IS7h7mpbJq26cWjoo-o,1063
|
472
|
+
defi_state_querier-0.5.10.dist-info/METADATA,sha256=UY7ClRm9Pkxzmc1EdJfZYFhrfD0hYRpakwKcw-iycx8,4413
|
473
|
+
defi_state_querier-0.5.10.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
474
|
+
defi_state_querier-0.5.10.dist-info/top_level.txt,sha256=C-OTxHK6MknKK-nAbEzCPDUl1M6pktRhgJrmsozdf6g,14
|
475
|
+
defi_state_querier-0.5.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|