defi-state-querier 0.5.18__py3-none-any.whl → 0.5.19__py3-none-any.whl
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.
- defi_services/__init__.py +1 -1
- defi_services/jobs/tcv.py +93 -59
- defi_services/services/vault/tcv_vault_services.py +1 -2
- defi_services/services/vault/vault_info/arbitrum/tcv_arb.py +6 -6
- {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.19.dist-info}/METADATA +1 -1
- {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.19.dist-info}/RECORD +9 -9
- {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.19.dist-info}/LICENSE +0 -0
- {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.19.dist-info}/WHEEL +0 -0
- {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.19.dist-info}/top_level.txt +0 -0
defi_services/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.5.
|
1
|
+
__version__ = "0.5.19"
|
defi_services/jobs/tcv.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from collections import defaultdict
|
2
|
+
|
1
3
|
from defi_services.constants.entities.dex_constant import Dex
|
2
4
|
from defi_services.constants.query_constant import Query
|
3
5
|
from defi_services.jobs.processors.state_processor import StateProcessor
|
@@ -13,98 +15,130 @@ class TCV:
|
|
13
15
|
reserves_info,
|
14
16
|
block_number: int = "latest",
|
15
17
|
):
|
18
|
+
lp_token_dict = {information["pool"]: information["poolInfo"] for information in reserves_info.values()}
|
19
|
+
tcv_liquidity_user, dex_lp_info = self.get_tcv_liquidity_user_and_lp_token_info(
|
20
|
+
wallet=address,
|
21
|
+
dex_protocol=Dex.uniswap_v3, lp_token_list=lp_token_dict,
|
22
|
+
block_number=block_number
|
23
|
+
)
|
24
|
+
|
25
|
+
tcv_nfts = {}
|
26
|
+
for vault_address, liquidity_info in tcv_liquidity_user.items():
|
27
|
+
# For optimize
|
28
|
+
liquidity_user = liquidity_info.get('liquidity_user')
|
29
|
+
if not liquidity_user:
|
30
|
+
liquidity_info.update({'tvl': {}})
|
31
|
+
continue
|
32
|
+
|
33
|
+
vault_nft = self.get_user_nft(vault_address, Dex.uniswap_v3, block_number=block_number)
|
34
|
+
tcv_nfts.update(vault_nft)
|
35
|
+
|
36
|
+
nfts_info = self.get_nfts_info(address, Dex.uniswap_v3, tcv_nfts, block_number=block_number)
|
37
|
+
user_balance = self.get_user_token_balance(address, Dex.uniswap_v3, nfts_info, dex_lp_info, block_number=block_number)
|
38
|
+
|
39
|
+
for token_id, info in user_balance.items():
|
40
|
+
pool_address = info['pool_address']
|
41
|
+
addresses = [vault_address_ for vault_address_, info in reserves_info.items() if info['pool'] == pool_address]
|
42
|
+
vault_address = addresses[0] if addresses else None
|
43
|
+
|
44
|
+
if (not vault_address) or (vault_address not in tcv_liquidity_user):
|
45
|
+
continue
|
46
|
+
|
47
|
+
if tcv_liquidity_user[vault_address].get('tvl') is None:
|
48
|
+
tcv_liquidity_user[vault_address]['tvl'] = defaultdict(lambda: 0)
|
49
|
+
|
50
|
+
tcv_liquidity_user[vault_address]['tvl'][info['token0']] += info['token0_amount']
|
51
|
+
tcv_liquidity_user[vault_address]['tvl'][info['token1']] += info['token1_amount']
|
52
|
+
|
53
|
+
return tcv_liquidity_user
|
54
|
+
|
55
|
+
def get_user_nft(self, wallet, dex_protocol, block_number: int = 'latest'):
|
16
56
|
queries = [
|
17
57
|
{
|
18
|
-
|
19
|
-
"entity_id": "tcv-vault",
|
20
|
-
"query_type": Query.staking_reward
|
21
|
-
},
|
22
|
-
]
|
23
|
-
res = self.state_processor.run(address, queries, block_number)
|
24
|
-
result = res[0].get("staking_reward")
|
25
|
-
for token, information in reserves_info.items():
|
26
|
-
pool = information.get("pool")
|
27
|
-
lp_token_dict = {
|
28
|
-
pool: reserves_info[token]["poolInfo"]
|
29
|
-
}
|
30
|
-
dex_lp_info = self.get_lp_token_info(token, Dex.uniswap_v3, lp_token_dict)
|
31
|
-
token_nfts = self.get_user_nft(token, Dex.uniswap_v3)
|
32
|
-
token_info = self.get_user_info(token, Dex.uniswap_v3, token_nfts)
|
33
|
-
token_balance = self.get_user_token_balance(token, Dex.uniswap_v3, token_info, dex_lp_info)
|
34
|
-
tvl = {}
|
35
|
-
for balance_info in token_balance:
|
36
|
-
for token_id, info in balance_info['dex_user_token_balance'].items():
|
37
|
-
if info['token0'] not in tvl:
|
38
|
-
tvl[info['token0']] = 0
|
39
|
-
if info['token1'] not in tvl:
|
40
|
-
tvl[info['token1']] = 0
|
41
|
-
tvl[info['token0']] += info['token0_amount']
|
42
|
-
tvl[info['token1']] += info['token1_amount']
|
43
|
-
result[token].update({"tvl": tvl})
|
44
|
-
return result
|
45
|
-
|
46
|
-
def get_user_nft(self, wallet, dex_protocol):
|
47
|
-
queries = [
|
48
|
-
{
|
49
|
-
'query_id': f'{dex_protocol}_usernft',
|
58
|
+
'query_id': f'{dex_protocol}_{Query.dex_user_nft}',
|
50
59
|
"entity_id": dex_protocol,
|
51
60
|
'query_type': Query.dex_user_nft
|
52
61
|
}
|
53
62
|
]
|
54
63
|
|
55
|
-
res = self.state_processor.run(
|
56
|
-
|
64
|
+
res = self.state_processor.run(
|
65
|
+
wallet, queries, block_number=block_number,
|
66
|
+
batch_size=100, max_workers=8, ignore_error=True
|
67
|
+
)
|
68
|
+
user_nfts = res[0][Query.dex_user_nft]
|
69
|
+
return user_nfts
|
57
70
|
|
58
|
-
def
|
71
|
+
def get_nfts_info(self, wallet, dex_protocol, user_nfts, block_number: int = 'latest'):
|
59
72
|
queries = [
|
60
73
|
{
|
61
|
-
'query_id': f'{dex_protocol}
|
74
|
+
'query_id': f'{dex_protocol}_{Query.dex_user_info}',
|
62
75
|
"entity_id": dex_protocol,
|
63
76
|
'query_type': Query.dex_user_info,
|
64
77
|
'supplied_data': {
|
65
|
-
'user_data': user_nfts
|
78
|
+
'user_data': user_nfts,
|
66
79
|
}
|
67
80
|
}
|
68
81
|
]
|
69
82
|
|
70
|
-
res = self.state_processor.run(
|
71
|
-
|
83
|
+
res = self.state_processor.run(
|
84
|
+
wallet, queries, block_number=block_number,
|
85
|
+
batch_size=100, max_workers=8, ignore_error=True
|
86
|
+
)
|
87
|
+
nfts_info = res[0][Query.dex_user_info]
|
88
|
+
return nfts_info
|
72
89
|
|
73
|
-
def get_user_token_balance(self, wallet, dex_protocol,
|
90
|
+
def get_user_token_balance(self, wallet, dex_protocol, nfts_info, lp_token_info, block_number: int = 'latest'):
|
74
91
|
queries = [
|
75
92
|
{
|
76
|
-
'query_id': f'{dex_protocol}
|
93
|
+
'query_id': f'{dex_protocol}_{Query.dex_user_token_balance}',
|
77
94
|
"entity_id": dex_protocol,
|
78
95
|
'query_type': Query.dex_user_token_balance,
|
79
96
|
'supplied_data': {
|
80
|
-
'user_data':
|
81
|
-
'lp_token_info':
|
82
|
-
|
97
|
+
'user_data': nfts_info,
|
98
|
+
'lp_token_info': lp_token_info
|
83
99
|
}
|
84
100
|
}
|
85
101
|
]
|
86
102
|
|
87
|
-
res = self.state_processor.run(
|
88
|
-
|
103
|
+
res = self.state_processor.run(
|
104
|
+
wallet, queries, block_number=block_number,
|
105
|
+
batch_size=100, max_workers=8, ignore_error=True
|
106
|
+
)
|
107
|
+
user_balance = res[0][Query.dex_user_token_balance]
|
108
|
+
return user_balance
|
89
109
|
|
90
|
-
def
|
110
|
+
def get_tcv_liquidity_user_and_lp_token_info(self, wallet, dex_protocol, lp_token_list, block_number: int = 'latest'):
|
91
111
|
queries = [
|
92
112
|
{
|
93
|
-
|
94
|
-
"entity_id":
|
95
|
-
|
96
|
-
'supplied_data': {
|
97
|
-
'lp_token_info': lp_token_list}
|
113
|
+
"query_id": f"tcv-vault_{Query.staking_reward}",
|
114
|
+
"entity_id": "tcv-vault",
|
115
|
+
"query_type": Query.staking_reward
|
98
116
|
},
|
99
117
|
{
|
100
|
-
'query_id': f'{dex_protocol}
|
118
|
+
'query_id': f'{dex_protocol}_{Query.lp_token_info}',
|
101
119
|
"entity_id": dex_protocol,
|
102
|
-
'query_type': Query.
|
120
|
+
'query_type': Query.lp_token_info,
|
103
121
|
'supplied_data': {
|
104
|
-
'lp_token_info': lp_token_list
|
105
|
-
|
122
|
+
'lp_token_info': lp_token_list
|
123
|
+
}
|
124
|
+
},
|
125
|
+
# {
|
126
|
+
# 'query_id': f'{dex_protocol}_{Query.token_pair_balance}',
|
127
|
+
# "entity_id": dex_protocol,
|
128
|
+
# 'query_type': Query.token_pair_balance,
|
129
|
+
# 'supplied_data': {
|
130
|
+
# 'lp_token_info': lp_token_list
|
131
|
+
# }
|
132
|
+
# }
|
106
133
|
]
|
107
|
-
res = self.state_processor.run(
|
108
|
-
|
109
|
-
|
134
|
+
res = self.state_processor.run(
|
135
|
+
address=wallet, queries=queries,
|
136
|
+
block_number=block_number,
|
137
|
+
batch_size=100, max_workers=8,
|
138
|
+
ignore_error=True
|
139
|
+
)
|
140
|
+
data = {r['query_id']: r for r in res}
|
110
141
|
|
142
|
+
tcv_liquidity_user = data.get(f'tcv-vault_{Query.staking_reward}', {}).get(Query.staking_reward)
|
143
|
+
lp_token_info = data.get(f'{dex_protocol}_{Query.lp_token_info}', {}).get(Query.lp_token_info)
|
144
|
+
return tcv_liquidity_user, lp_token_info
|
@@ -94,7 +94,6 @@ class TCVVaultStateService(ProtocolServices):
|
|
94
94
|
}
|
95
95
|
return result
|
96
96
|
|
97
|
-
|
98
97
|
# REWARDS BALANCE
|
99
98
|
def get_rewards_balance_function_info(
|
100
99
|
self,
|
@@ -106,4 +105,4 @@ class TCVVaultStateService(ProtocolServices):
|
|
106
105
|
|
107
106
|
def calculate_rewards_balance(
|
108
107
|
self, wallet: str, reserves_info: dict, decoded_data: dict, block_number: int = "latest"):
|
109
|
-
pass
|
108
|
+
pass
|
@@ -7,7 +7,7 @@ TCV_VAULT_ARBITRUM = {
|
|
7
7
|
"vaultName": "eth/usdc",
|
8
8
|
"tokenIn": "0xe467db55710cf35e2dc0402104e23221f0e12e66",
|
9
9
|
"pool": '0xc6962004f452be9203591991d15f6b388e09e8d0',
|
10
|
-
"poolInfo":{
|
10
|
+
"poolInfo": {
|
11
11
|
"token0": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
12
12
|
"token1": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
|
13
13
|
"fee": 500
|
@@ -17,7 +17,7 @@ TCV_VAULT_ARBITRUM = {
|
|
17
17
|
"vaultName": "eth/usdt",
|
18
18
|
"tokenIn": "0x9403be93fddedf88a3ed7d11bfb643b13e5cbc27",
|
19
19
|
"pool": '0x641c00a822e8b671738d32a431a4fb6074e5c79d',
|
20
|
-
"poolInfo":{
|
20
|
+
"poolInfo": {
|
21
21
|
"token0": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
22
22
|
"token1": "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
23
23
|
"fee": 500
|
@@ -28,7 +28,7 @@ TCV_VAULT_ARBITRUM = {
|
|
28
28
|
"vaultName": "eth/arb",
|
29
29
|
"tokenIn": "0xae83866e6b48e29b225a10bc236f2665cc4f081e",
|
30
30
|
"pool": '0xc6f780497a95e246eb9449f5e4770916dcd6396a',
|
31
|
-
"poolInfo":{
|
31
|
+
"poolInfo": {
|
32
32
|
"token0": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
33
33
|
"token1": "0x912ce59144191c1204e64559fe8253a0e49e6548",
|
34
34
|
"fee": 500
|
@@ -38,7 +38,7 @@ TCV_VAULT_ARBITRUM = {
|
|
38
38
|
"vaultName": "eth/usdc(bridgeusdc)",
|
39
39
|
"tokenIn": "0xaae3866f0233aec20580c21a3c10791afd38c8c1",
|
40
40
|
"pool": '0xc31e54c7a869b9fcbecc14363cf510d1c41fa443',
|
41
|
-
"poolInfo":{
|
41
|
+
"poolInfo": {
|
42
42
|
"token0": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
43
43
|
"token1": "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",
|
44
44
|
"fee": 500
|
@@ -48,11 +48,11 @@ TCV_VAULT_ARBITRUM = {
|
|
48
48
|
"vaultName": "eth/usdc",
|
49
49
|
"tokenIn": "0xa02d1ecbe8eefaf7d64871ee0ae6404318df9702",
|
50
50
|
"pool": '0xc473e2aee3441bf9240be85eb122abb059a3b57c',
|
51
|
-
"poolInfo":{
|
51
|
+
"poolInfo": {
|
52
52
|
"token0": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
53
53
|
"token1": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
|
54
54
|
"fee": 3000
|
55
55
|
}
|
56
56
|
}
|
57
57
|
}
|
58
|
-
}
|
58
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
defi_services/__init__.py,sha256=
|
1
|
+
defi_services/__init__.py,sha256=InrFJaBUb_cLi70n_bBjGRkMOAWxGUgFDIAObAjB4_M,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
|
@@ -313,7 +313,7 @@ defi_services/constants/entities/lending_services.py,sha256=EeCRUi-K4O3MlB6m5f9Q
|
|
313
313
|
defi_services/constants/entities/vault_constant.py,sha256=XaFp2VpmePfym42Gn-5IeT8qnQBq1JcRNrH7r2_tWxo,122
|
314
314
|
defi_services/constants/entities/vault_services.py,sha256=uwcvxwnyXNU3_3mcI6PGWyvGe40tzHmTrmigotLWeMM,752
|
315
315
|
defi_services/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
316
|
-
defi_services/jobs/tcv.py,sha256=
|
316
|
+
defi_services/jobs/tcv.py,sha256=Ngp6VWcH2n2ZCMTPu0TySxXQn_O6C2FDbvzVltEmH5Y,5707
|
317
317
|
defi_services/jobs/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
318
318
|
defi_services/jobs/processors/call_state_processor.py,sha256=WseX0OaMA5D_ANYofrz7W2BooSMdHlGRay4NuiABmM4,436
|
319
319
|
defi_services/jobs/processors/cosmos_state_processor.py,sha256=eVAs_-dSjlR7ijHAG9ytAysGesiyQYyK-sAMg8rUPYw,1898
|
@@ -450,11 +450,11 @@ defi_services/services/multicall/batch_queries_service.py,sha256=HzgKOdkP6kpjR7g
|
|
450
450
|
defi_services/services/multicall/multicall_v2.py,sha256=5JAqb3Jn5Z-23-Gwz5lMa5DokES-Pf7WtigHMGlG-7k,18695
|
451
451
|
defi_services/services/multicall/state_query_service.py,sha256=1Ob5NX0tXmVUrSB1_mOvFBkOUA8KZJPwH2DMiHwlGhI,23709
|
452
452
|
defi_services/services/vault/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
453
|
-
defi_services/services/vault/tcv_vault_services.py,sha256=
|
453
|
+
defi_services/services/vault/tcv_vault_services.py,sha256=RPqp0jHviH0PY4AC5Eswowza_VL7YSovqADQT3WBzLk,3827
|
454
454
|
defi_services/services/vault/trava_vault_services.py,sha256=9Sj5W6o7o478MKu7ZOUdqkTtPUzT59eS9yBcU8O4UrM,7705
|
455
455
|
defi_services/services/vault/vault_info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
456
456
|
defi_services/services/vault/vault_info/arbitrum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
457
|
-
defi_services/services/vault/vault_info/arbitrum/tcv_arb.py,sha256=
|
457
|
+
defi_services/services/vault/vault_info/arbitrum/tcv_arb.py,sha256=aN3L78Q6sCUvb2oa5RUtqCthCA88qsADVkU13sjtN-g,2473
|
458
458
|
defi_services/services/vault/vault_info/bsc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
459
459
|
defi_services/services/vault/vault_info/bsc/trava_bsc.py,sha256=v1Nv5SmjDYLvCke_H5ZtgdjNXo0_9X-P5OQldezP0XM,1586
|
460
460
|
defi_services/services/vault/vault_info/ethereum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -475,8 +475,8 @@ defi_services/utils/memory_storage.py,sha256=BOT8laB0iVSCGE-oDlpWJQLbSC6X2blKX4z
|
|
475
475
|
defi_services/utils/sqrt_price_math.py,sha256=9lgUeWFT4wjl3Vq3b7-jZ2bGvvZx7dDBSfVnM3lsZ8o,5575
|
476
476
|
defi_services/utils/thread_proxy.py,sha256=5Z8biAyEReUkh3vfJSvEv7GwMe3CsE5M8CbghkQtePw,2951
|
477
477
|
defi_services/utils/ton_decode_address.py,sha256=EWKwmC7KtbXpdKgiNK-5j-5lX7fCr17I4EWYs9b43eU,443
|
478
|
-
defi_state_querier-0.5.
|
479
|
-
defi_state_querier-0.5.
|
480
|
-
defi_state_querier-0.5.
|
481
|
-
defi_state_querier-0.5.
|
482
|
-
defi_state_querier-0.5.
|
478
|
+
defi_state_querier-0.5.19.dist-info/LICENSE,sha256=6jmfxa8nUIwfKnzZUxAHJSJ_IS7h7mpbJq26cWjoo-o,1063
|
479
|
+
defi_state_querier-0.5.19.dist-info/METADATA,sha256=G826RV8D7COoB1D8_oB55GicrBaB4NG7ii-_l0eoTbI,4413
|
480
|
+
defi_state_querier-0.5.19.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
481
|
+
defi_state_querier-0.5.19.dist-info/top_level.txt,sha256=C-OTxHK6MknKK-nAbEzCPDUl1M6pktRhgJrmsozdf6g,14
|
482
|
+
defi_state_querier-0.5.19.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|