defi-state-querier 0.0.7__py3-none-any.whl → 0.0.9__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/abis/lending/morpho/__init__.py +0 -0
- defi_services/abis/lending/morpho/morpho_aave_v2_comptroller_abi.py +2301 -0
- defi_services/abis/lending/morpho/morpho_aave_v2_lens_abi.py +1208 -0
- defi_services/abis/lending/morpho/morpho_aave_v3_comptroller_abi.py +2994 -0
- defi_services/abis/lending/morpho/morpho_compound_comptroller_abi.py +2301 -0
- defi_services/abis/lending/morpho/morpho_compound_lens_abi.py +1402 -0
- defi_services/abis/lending/morpho/morpho_compound_reward_manager_abi.py +307 -0
- defi_services/constants/entities/lending_constant.py +6 -1
- defi_services/constants/entities/lending_services.py +7 -1
- defi_services/constants/query_constant.py +1 -0
- defi_services/jobs/processors/substrate_state_processor.py +97 -0
- defi_services/jobs/queriers/substrate_state_querier.py +84 -0
- defi_services/services/lending/aave_v3_services.py +4 -2
- defi_services/services/lending/compound_service.py +20 -2
- defi_services/services/lending/flux_services.py +30 -22
- defi_services/services/lending/iron_bank_service.py +19 -10
- defi_services/services/lending/lending_info/aave_v2_services.py +1 -1
- defi_services/services/lending/lending_info/ethereum/morpho_aave_v2_eth.py +53 -0
- defi_services/services/lending/lending_info/ethereum/morpho_aave_v3_eth.py +51 -0
- defi_services/services/lending/lending_info/ethereum/morpho_compound_eth.py +44 -0
- defi_services/services/lending/morpho_aave_v2_services.py +89 -0
- defi_services/services/lending/morpho_aave_v3_services.py +159 -0
- defi_services/services/lending/morpho_compound_services.py +233 -0
- defi_services/services/lending/onyx_service.py +23 -3
- defi_services/services/lending/strike_service.py +22 -3
- defi_services/services/lending/venus_services.py +19 -0
- defi_services/services/substrate_token_services.py +70 -0
- {defi_state_querier-0.0.7.dist-info → defi_state_querier-0.0.9.dist-info}/METADATA +1 -1
- {defi_state_querier-0.0.7.dist-info → defi_state_querier-0.0.9.dist-info}/RECORD +33 -17
- {defi_state_querier-0.0.7.dist-info → defi_state_querier-0.0.9.dist-info}/LICENSE +0 -0
- {defi_state_querier-0.0.7.dist-info → defi_state_querier-0.0.9.dist-info}/WHEEL +0 -0
- {defi_state_querier-0.0.7.dist-info → defi_state_querier-0.0.9.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,233 @@
|
|
1
|
+
import logging
|
2
|
+
import time
|
3
|
+
|
4
|
+
from web3 import Web3
|
5
|
+
|
6
|
+
from defi_services.abis.lending.cream.cream_comptroller_abi import CREAM_COMPTROLLER_ABI
|
7
|
+
from defi_services.abis.lending.cream.cream_lens_abi import CREAM_LENS_ABI
|
8
|
+
from defi_services.abis.lending.morpho.morpho_compound_comptroller_abi import MORPHO_COMPOUND_COMPTROLLER_ABI
|
9
|
+
from defi_services.abis.lending.morpho.morpho_compound_lens_abi import MORPHO_COMPOUND_LENS_ABI
|
10
|
+
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
11
|
+
from defi_services.constants.chain_constant import Chain
|
12
|
+
from defi_services.constants.entities.lending_constant import Lending
|
13
|
+
from defi_services.constants.query_constant import Query
|
14
|
+
from defi_services.constants.token_constant import ContractAddresses, Token
|
15
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
16
|
+
from defi_services.services.lending.compound_service import CompoundInfo
|
17
|
+
from defi_services.services.lending.lending_info.ethereum.morpho_compound_eth import MORPHO_COMPOUND_ETH
|
18
|
+
from defi_services.services.protocol_services import ProtocolServices
|
19
|
+
|
20
|
+
logger = logging.getLogger("Compound Lending Pool State Service")
|
21
|
+
|
22
|
+
|
23
|
+
class MorphoCompoundInfo:
|
24
|
+
mapping = {
|
25
|
+
Chain.ethereum: MORPHO_COMPOUND_ETH
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
class MorphoCompoundServices(ProtocolServices):
|
30
|
+
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
31
|
+
self.name = f"{chain_id}_{Lending.morpho_compound}"
|
32
|
+
self.chain_id = chain_id
|
33
|
+
self.compound_info = CompoundInfo.mapping.get(chain_id)
|
34
|
+
self.pool_info = MorphoCompoundInfo.mapping.get(chain_id)
|
35
|
+
self.state_service = state_service
|
36
|
+
self.compound_lens_abi = CREAM_LENS_ABI
|
37
|
+
self.compound_comptroller_abi = CREAM_COMPTROLLER_ABI
|
38
|
+
self.lens_abi = MORPHO_COMPOUND_LENS_ABI
|
39
|
+
self.comptroller_abi = MORPHO_COMPOUND_COMPTROLLER_ABI
|
40
|
+
self.market_key = 'cToken'
|
41
|
+
|
42
|
+
# BASIC FUNCTIONS
|
43
|
+
def get_service_info(self):
|
44
|
+
info = {
|
45
|
+
Lending.morpho_compound: {
|
46
|
+
"chain_id": self.chain_id,
|
47
|
+
"type": "lending",
|
48
|
+
"protocol_info": self.pool_info
|
49
|
+
}
|
50
|
+
}
|
51
|
+
return info
|
52
|
+
|
53
|
+
def get_dapp_asset_info(
|
54
|
+
self,
|
55
|
+
block_number: int = "latest"):
|
56
|
+
_w3 = self.state_service.get_w3()
|
57
|
+
comptroller_contract = _w3.eth.contract(
|
58
|
+
address=_w3.toChecksumAddress(self.pool_info.get("comptrollerAddress")), abi=self.comptroller_abi)
|
59
|
+
ctokens = []
|
60
|
+
for token in comptroller_contract.functions.getAllMarkets().call(block_identifier=block_number):
|
61
|
+
if token in [ContractAddresses.LUNA.lower(), ContractAddresses.UST.lower(), ContractAddresses.LUNA,
|
62
|
+
ContractAddresses.UST]:
|
63
|
+
continue
|
64
|
+
ctokens.append(token)
|
65
|
+
|
66
|
+
compound_lens_contract = _w3.eth.contract(
|
67
|
+
address=Web3.toChecksumAddress(self.compound_info.get("lensAddress")), abi=self.compound_lens_abi
|
68
|
+
)
|
69
|
+
tokens = [Web3.toChecksumAddress(i) for i in ctokens]
|
70
|
+
metadata = compound_lens_contract.functions.cTokenMetadataAll(tokens).call(block_identifier=block_number)
|
71
|
+
reserves_info = {}
|
72
|
+
for data in metadata:
|
73
|
+
underlying = data[11].lower()
|
74
|
+
ctoken = data[0].lower()
|
75
|
+
lt = data[10] / 10 ** 18
|
76
|
+
reserves_info[underlying] = {
|
77
|
+
"cToken": ctoken,
|
78
|
+
"liquidationThreshold": lt
|
79
|
+
}
|
80
|
+
|
81
|
+
return reserves_info
|
82
|
+
|
83
|
+
def get_token_list(self):
|
84
|
+
begin = time.time()
|
85
|
+
tokens = [self.pool_info.get('rewardToken'), self.pool_info.get("poolToken")]
|
86
|
+
for token in self.pool_info.get("reservesList"):
|
87
|
+
if token == Token.native_token:
|
88
|
+
tokens.append(Token.wrapped_token.get(self.chain_id))
|
89
|
+
continue
|
90
|
+
tokens.append(token)
|
91
|
+
logger.info(f"Get token list related in {time.time() - begin}s")
|
92
|
+
return tokens
|
93
|
+
|
94
|
+
def get_data(
|
95
|
+
self,
|
96
|
+
query_types: list,
|
97
|
+
wallet: str,
|
98
|
+
decoded_data: dict,
|
99
|
+
block_number: int = 'latest',
|
100
|
+
**kwargs
|
101
|
+
):
|
102
|
+
begin = time.time()
|
103
|
+
reserves_info = kwargs.get("reserves_info", self.pool_info.get("reservesList"))
|
104
|
+
token_prices = kwargs.get("token_prices", {})
|
105
|
+
result = {}
|
106
|
+
if Query.deposit_borrow in query_types and wallet:
|
107
|
+
result.update(self.calculate_wallet_deposit_borrow_balance(
|
108
|
+
wallet, reserves_info, decoded_data, token_prices, block_number
|
109
|
+
))
|
110
|
+
|
111
|
+
if Query.protocol_reward in query_types and wallet:
|
112
|
+
result.update(self.calculate_claimable_rewards_balance(
|
113
|
+
wallet, decoded_data, block_number
|
114
|
+
))
|
115
|
+
logger.info(f"Process protocol data in {time.time() - begin}")
|
116
|
+
return result
|
117
|
+
|
118
|
+
def get_function_info(
|
119
|
+
self,
|
120
|
+
query_types: list,
|
121
|
+
wallet: str = None,
|
122
|
+
block_number: int = "latest",
|
123
|
+
**kwargs
|
124
|
+
):
|
125
|
+
begin = time.time()
|
126
|
+
reserves_info = kwargs.get("reserves_info", {})
|
127
|
+
if not reserves_info:
|
128
|
+
reserves_info = self.pool_info['reservesList']
|
129
|
+
rpc_calls = {}
|
130
|
+
if Query.deposit_borrow in query_types and wallet:
|
131
|
+
rpc_calls.update(self.get_wallet_deposit_borrow_balance_function_info(
|
132
|
+
wallet, reserves_info, block_number
|
133
|
+
))
|
134
|
+
|
135
|
+
if Query.protocol_reward in query_types and wallet:
|
136
|
+
rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
|
137
|
+
|
138
|
+
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
139
|
+
return rpc_calls
|
140
|
+
|
141
|
+
# REWARDS BALANCE
|
142
|
+
def get_claimable_rewards_balance_function_info(
|
143
|
+
self,
|
144
|
+
wallet_address: str,
|
145
|
+
block_number: int = "latest",
|
146
|
+
):
|
147
|
+
reserves_info = self.pool_info.get("reservesList")
|
148
|
+
params = [
|
149
|
+
[Web3.toChecksumAddress(value.get(self.market_key)) for key, value in reserves_info.items()],
|
150
|
+
Web3.toChecksumAddress(wallet_address)
|
151
|
+
]
|
152
|
+
rpc_call = self.get_lens_function_info("getUserUnclaimedRewards", params, block_number)
|
153
|
+
get_reward_id = f"getUserUnclaimedRewards_{self.name}_{wallet_address}_{block_number}".lower()
|
154
|
+
return {get_reward_id: rpc_call}
|
155
|
+
|
156
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
157
|
+
block_number: int = "latest"):
|
158
|
+
get_reward_id = f"getUserUnclaimedRewards_{self.name}_{wallet_address}_{block_number}".lower()
|
159
|
+
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
160
|
+
reward_token = self.pool_info.get("rewardToken")
|
161
|
+
result = {
|
162
|
+
reward_token: {"amount": rewards}
|
163
|
+
}
|
164
|
+
return result
|
165
|
+
|
166
|
+
# WALLET DEPOSIT BORROW BALANCE
|
167
|
+
def get_wallet_deposit_borrow_balance_function_info(
|
168
|
+
self,
|
169
|
+
wallet_address: str,
|
170
|
+
reserves_info: dict,
|
171
|
+
block_number: int = "latest"
|
172
|
+
):
|
173
|
+
|
174
|
+
rpc_calls = {}
|
175
|
+
for token, value in reserves_info.items():
|
176
|
+
underlying = token
|
177
|
+
ctoken = value.get(self.market_key)
|
178
|
+
if token == Token.native_token:
|
179
|
+
underlying = Token.wrapped_token.get(self.chain_id)
|
180
|
+
underlying_borrow_key = f"getCurrentBorrowBalanceInOf_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
181
|
+
underlying_balance_key = f"getCurrentSupplyBalanceInOf_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
182
|
+
underlying_decimals_key = f"decimals_{underlying}_{block_number}".lower()
|
183
|
+
rpc_calls[underlying_borrow_key] = self.get_lens_function_info(
|
184
|
+
"getCurrentBorrowBalanceInOf", [ctoken, wallet_address], block_number)
|
185
|
+
rpc_calls[underlying_balance_key] = self.get_lens_function_info(
|
186
|
+
"getCurrentSupplyBalanceInOf", [ctoken, wallet_address], block_number)
|
187
|
+
rpc_calls[underlying_decimals_key] = self.state_service.get_function_info(
|
188
|
+
underlying, ERC20_ABI, "decimals", [], block_number
|
189
|
+
)
|
190
|
+
|
191
|
+
return rpc_calls
|
192
|
+
|
193
|
+
def calculate_wallet_deposit_borrow_balance(
|
194
|
+
self, wallet_address: str, reserves_info: dict, decoded_data: dict, token_prices: dict = None,
|
195
|
+
block_number: int = "latest"):
|
196
|
+
if token_prices is None:
|
197
|
+
token_prices = {}
|
198
|
+
result = {}
|
199
|
+
for token, value in reserves_info.items():
|
200
|
+
underlying = token
|
201
|
+
ctoken = value.get(self.market_key)
|
202
|
+
if token == Token.native_token:
|
203
|
+
underlying = Token.wrapped_token.get(self.chain_id)
|
204
|
+
get_total_deposit_id = f"getCurrentSupplyBalanceInOf_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
205
|
+
get_total_borrow_id = f"getCurrentBorrowBalanceInOf_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
206
|
+
get_decimals_id = f"decimals_{underlying}_{block_number}".lower()
|
207
|
+
decimals = decoded_data[get_decimals_id]
|
208
|
+
deposit_amount = decoded_data[get_total_deposit_id][-1] / 10 ** decimals
|
209
|
+
borrow_amount = decoded_data[get_total_borrow_id][-1] / 10 ** decimals
|
210
|
+
result[token] = {
|
211
|
+
"borrow_amount": borrow_amount,
|
212
|
+
"deposit_amount": deposit_amount,
|
213
|
+
}
|
214
|
+
if token_prices:
|
215
|
+
token_price = token_prices.get(underlying)
|
216
|
+
else:
|
217
|
+
token_price = None
|
218
|
+
if token_price is not None:
|
219
|
+
deposit_amount_in_usd = deposit_amount * token_price
|
220
|
+
borrow_amount_in_usd = borrow_amount * token_price
|
221
|
+
result[token]['borrow_amount_in_usd'] += borrow_amount_in_usd
|
222
|
+
result[token]['deposit_amount_in_usd'] += deposit_amount_in_usd
|
223
|
+
return result
|
224
|
+
|
225
|
+
def get_lens_function_info(self, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
226
|
+
return self.state_service.get_function_info(
|
227
|
+
self.pool_info['lensAddress'], self.lens_abi, fn_name, fn_paras, block_number
|
228
|
+
)
|
229
|
+
|
230
|
+
def get_comptroller_function_info(self, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
231
|
+
return self.state_service.get_function_info(
|
232
|
+
self.pool_info['comptrollerAddress'], self.comptroller_abi, fn_name, fn_paras, block_number
|
233
|
+
)
|
@@ -105,7 +105,7 @@ class OnyxStateService(ProtocolServices):
|
|
105
105
|
))
|
106
106
|
|
107
107
|
if Query.protocol_reward in query_types and wallet:
|
108
|
-
result.update(self.
|
108
|
+
result.update(self.calculate_claimable_rewards_balance(
|
109
109
|
wallet, decoded_data, block_number
|
110
110
|
))
|
111
111
|
|
@@ -131,12 +131,31 @@ class OnyxStateService(ProtocolServices):
|
|
131
131
|
))
|
132
132
|
|
133
133
|
if Query.protocol_reward in query_types and wallet:
|
134
|
-
rpc_calls.update(self.
|
134
|
+
rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
|
135
135
|
|
136
136
|
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
137
137
|
return rpc_calls
|
138
138
|
|
139
139
|
# REWARDS BALANCE
|
140
|
+
def get_claimable_rewards_balance_function_info(
|
141
|
+
self,
|
142
|
+
wallet_address: str,
|
143
|
+
block_number: int = "latest",
|
144
|
+
):
|
145
|
+
rpc_call = self.get_comptroller_function_info("xcnAccrued", [wallet_address], block_number)
|
146
|
+
get_reward_id = f"xcnAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
147
|
+
return {get_reward_id: rpc_call}
|
148
|
+
|
149
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
150
|
+
block_number: int = "latest"):
|
151
|
+
get_reward_id = f"xcnAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
152
|
+
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
153
|
+
reward_token = self.pool_info.get("rewardToken")
|
154
|
+
result = {
|
155
|
+
reward_token: {"amount": rewards}
|
156
|
+
}
|
157
|
+
return result
|
158
|
+
|
140
159
|
def get_rewards_balance_function_info(
|
141
160
|
self,
|
142
161
|
wallet_address: str,
|
@@ -184,7 +203,8 @@ class OnyxStateService(ProtocolServices):
|
|
184
203
|
underlying, ERC20_ABI, "decimals", [], block_number
|
185
204
|
)
|
186
205
|
key = f"oTokenBalancesAll_{self.name}_{wallet_address}_{block_number}".lower()
|
187
|
-
rpc_calls[key] = self.get_lens_function_info("oTokenBalancesAll",
|
206
|
+
rpc_calls[key] = self.get_lens_function_info("oTokenBalancesAll",
|
207
|
+
[ctokens, Web3.toChecksumAddress(wallet_address)])
|
188
208
|
return rpc_calls
|
189
209
|
|
190
210
|
def calculate_wallet_deposit_borrow_balance(
|
@@ -36,7 +36,7 @@ class StrikeStateService(ProtocolServices):
|
|
36
36
|
# BASIC FUNCTIONS
|
37
37
|
def get_service_info(self):
|
38
38
|
info = {
|
39
|
-
|
39
|
+
Lending.strike: {
|
40
40
|
"chain_id": self.chain_id,
|
41
41
|
"type": "lending",
|
42
42
|
"protocol_info": self.pool_info
|
@@ -105,7 +105,7 @@ class StrikeStateService(ProtocolServices):
|
|
105
105
|
))
|
106
106
|
|
107
107
|
if Query.protocol_reward in query_types and wallet:
|
108
|
-
result.update(self.
|
108
|
+
result.update(self.calculate_claimable_rewards_balance(
|
109
109
|
wallet, decoded_data, block_number
|
110
110
|
))
|
111
111
|
|
@@ -134,12 +134,31 @@ class StrikeStateService(ProtocolServices):
|
|
134
134
|
# rpc_calls.update(self.get_apy_lending_pool_function_info(reserves_info, block_number, is_oracle_price))
|
135
135
|
|
136
136
|
if Query.protocol_reward in query_types and wallet:
|
137
|
-
rpc_calls.update(self.
|
137
|
+
rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
|
138
138
|
|
139
139
|
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
140
140
|
return rpc_calls
|
141
141
|
|
142
142
|
# REWARDS BALANCE
|
143
|
+
def get_claimable_rewards_balance_function_info(
|
144
|
+
self,
|
145
|
+
wallet_address: str,
|
146
|
+
block_number: int = "latest",
|
147
|
+
):
|
148
|
+
rpc_call = self.get_comptroller_function_info("strikeAccrued", [wallet_address], block_number)
|
149
|
+
get_reward_id = f"strikeAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
150
|
+
return {get_reward_id: rpc_call}
|
151
|
+
|
152
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
153
|
+
block_number: int = "latest"):
|
154
|
+
get_reward_id = f"strikeAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
155
|
+
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
156
|
+
reward_token = self.pool_info.get("rewardToken")
|
157
|
+
result = {
|
158
|
+
reward_token: {"amount": rewards}
|
159
|
+
}
|
160
|
+
return result
|
161
|
+
|
143
162
|
def get_rewards_balance_function_info(
|
144
163
|
self,
|
145
164
|
wallet_address: str,
|
@@ -137,6 +137,25 @@ class VenusStateService(CompoundStateService):
|
|
137
137
|
}
|
138
138
|
|
139
139
|
# REWARDS BALANCE
|
140
|
+
def get_claimable_rewards_balance_function_info(
|
141
|
+
self,
|
142
|
+
wallet_address: str,
|
143
|
+
block_number: int = "latest",
|
144
|
+
):
|
145
|
+
rpc_call = self.get_comptroller_function_info("venusAccrued", [wallet_address], block_number)
|
146
|
+
get_reward_id = f"venusAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
147
|
+
return {get_reward_id: rpc_call}
|
148
|
+
|
149
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
150
|
+
block_number: int = "latest"):
|
151
|
+
get_reward_id = f"venusAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
152
|
+
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
153
|
+
reward_token = self.pool_info.get("rewardToken")
|
154
|
+
result = {
|
155
|
+
reward_token: {"amount": rewards}
|
156
|
+
}
|
157
|
+
return result
|
158
|
+
|
140
159
|
def get_rewards_balance_function_info(
|
141
160
|
self,
|
142
161
|
wallet_address: str,
|
@@ -0,0 +1,70 @@
|
|
1
|
+
from defi_services.constants.token_constant import Token
|
2
|
+
from defi_services.jobs.queriers.substrate_state_querier import SubstrateStateQuerier
|
3
|
+
|
4
|
+
|
5
|
+
class SubstrateTokenServices:
|
6
|
+
def __init__(self, state_service: SubstrateStateQuerier, chain_id: str = "polkadot"):
|
7
|
+
self.chain_id = chain_id
|
8
|
+
self.state_service = state_service
|
9
|
+
self.token_info = self.get_assets()
|
10
|
+
|
11
|
+
def get_assets(self):
|
12
|
+
if self.chain_id in ['polkadot']:
|
13
|
+
return {}
|
14
|
+
client_querier = self.state_service.get_client_querier()
|
15
|
+
assets = client_querier.query_map("Assets", "Metadata")
|
16
|
+
result = {}
|
17
|
+
for asset in assets.records:
|
18
|
+
token_id = str(asset[0].value)
|
19
|
+
result[token_id] = asset[1].value_serialized
|
20
|
+
|
21
|
+
return result
|
22
|
+
|
23
|
+
def get_service_info(self):
|
24
|
+
info = {
|
25
|
+
"token": {
|
26
|
+
"chain_id": self.chain_id,
|
27
|
+
"type": "token"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return info
|
31
|
+
|
32
|
+
def get_function_info(self, wallet: str, token: str, block_number: int = "latest"):
|
33
|
+
result = self.get_function_balance_info(wallet, token, block_number)
|
34
|
+
|
35
|
+
return result
|
36
|
+
|
37
|
+
def get_function_balance_info(self, wallet: str, token: str = None, block_number: int = "latest"):
|
38
|
+
if not token or token == Token.native_token:
|
39
|
+
key = f"System_Account_{[wallet]}_{block_number}".lower()
|
40
|
+
rpc_call = self.state_service.get_function_info("System", "Account", [wallet], block_number)
|
41
|
+
else:
|
42
|
+
token = int(token)
|
43
|
+
params = [int(token), wallet]
|
44
|
+
key = f"Assets_Account_{params}_{block_number}".lower()
|
45
|
+
rpc_call = self.state_service.get_function_info("Assets", "Account", params, block_number)
|
46
|
+
|
47
|
+
return {key: rpc_call}
|
48
|
+
|
49
|
+
def get_asset_info(self, token: str):
|
50
|
+
token = int(token)
|
51
|
+
key = f"Assets_Asset_{token}".lower()
|
52
|
+
rpc_call = self.state_service.get_function_info("Assets", "Asset", [token])
|
53
|
+
return {key, rpc_call}
|
54
|
+
|
55
|
+
def get_data(self, wallet: str, token: str = None, decoded_data: dict = None,
|
56
|
+
token_prices: dict = None, block_number: int = "latest"):
|
57
|
+
if not token or token == Token.native_token:
|
58
|
+
key = f"System_Account_{[wallet]}_{block_number}".lower()
|
59
|
+
balance = decoded_data.get(key).get('data').get("free") / 10 ** 10
|
60
|
+
else:
|
61
|
+
if token not in self.token_info:
|
62
|
+
self.token_info = self.get_assets()
|
63
|
+
token_decimals = self.token_info.get(token, {}).get('decimals', 0)
|
64
|
+
token = int(token)
|
65
|
+
params = [int(token), wallet]
|
66
|
+
key = f"Assets_Account_{params}_{block_number}".lower()
|
67
|
+
balance = decoded_data.get(key).get("balance") / 10 ** token_decimals
|
68
|
+
token_price = token_prices.get(token, 1)
|
69
|
+
balance = balance * token_price
|
70
|
+
return balance
|
@@ -1,4 +1,4 @@
|
|
1
|
-
defi_services/__init__.py,sha256=
|
1
|
+
defi_services/__init__.py,sha256=46Yjk3fz9o8aTN8E95McnzpJcjGzVJmHmQqUZ5mXzfc,22
|
2
2
|
defi_services/abis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
defi_services/abis/dex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
defi_services/abis/dex/biswap/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -36,6 +36,13 @@ defi_services/abis/lending/liqee/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRk
|
|
36
36
|
defi_services/abis/lending/liqee/liqee_comptroller_abi.py,sha256=UbMnkWmApWs2oBUHz0t0xgDIpHC-HiP3HKBoZqEZxLs,32288
|
37
37
|
defi_services/abis/lending/liqee/liqee_lending_data_abi.py,sha256=qs7_ynzZxuG0AtKRRU8SAh4zXxKpcoVT7zkuU_sNOrc,17504
|
38
38
|
defi_services/abis/lending/liqee/liqee_token_abi.py,sha256=ApFOMcmdskkX1dPJIxofQTqlguBlDyzrKYcVOGlCEW4,28252
|
39
|
+
defi_services/abis/lending/morpho/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
40
|
+
defi_services/abis/lending/morpho/morpho_aave_v2_comptroller_abi.py,sha256=3ThdzPUy5B_nwVHNCoDpJ9L4y1_EyAbrinu6KGCjNqk,45749
|
41
|
+
defi_services/abis/lending/morpho/morpho_aave_v2_lens_abi.py,sha256=IjNp8W8AU8awn-cwgShNQrsllxk_n2Vze2IG92Qxk38,24940
|
42
|
+
defi_services/abis/lending/morpho/morpho_aave_v3_comptroller_abi.py,sha256=rUK7stLGRAQu-tbcO3n8GZGZObiADxivhHyVU3-wUjk,60734
|
43
|
+
defi_services/abis/lending/morpho/morpho_compound_comptroller_abi.py,sha256=AZc1PbQj3XH9Jqcztt1Lhc_kix5A0_o4ulDGKEf2dSU,44863
|
44
|
+
defi_services/abis/lending/morpho/morpho_compound_lens_abi.py,sha256=NJ6pfIIbBzOBjxaHBJphWOLfjvp6Ig-_sQNzyIvpDWA,28690
|
45
|
+
defi_services/abis/lending/morpho/morpho_compound_reward_manager_abi.py,sha256=QBlnZLXJ5ruMrcCPG3CxBLmPC6jf16E06qtqOfCXfUc,5883
|
39
46
|
defi_services/abis/lending/onyx/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
40
47
|
defi_services/abis/lending/onyx/onyx_comptroller_abi.py,sha256=GSBQSY7Ok50KpIUwroN9QtSqzE8p-qzOn6XTeocxE40,43692
|
41
48
|
defi_services/abis/lending/onyx/onyx_lens_abi.py,sha256=bBJvkOVTX52xiBil2lEveTRMzcC4dRQY9X2Hh4Uw_bI,19043
|
@@ -72,46 +79,52 @@ defi_services/constants/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
72
79
|
defi_services/constants/chain_constant.py,sha256=DcG3U8Nov1eMLGA-2SNqsVpuKDTu8HPgRjrs073pA9c,183
|
73
80
|
defi_services/constants/db_constant.py,sha256=qAPZOrV8dtDf75mmhizquka2unv8Ob-oiC8GeMRxIjg,2534
|
74
81
|
defi_services/constants/mongo_constant.py,sha256=7EjyDPn7lIkjJTRqQ_xeD4zt4zG_Pazc2XKLl8Uhobg,394
|
75
|
-
defi_services/constants/query_constant.py,sha256=
|
82
|
+
defi_services/constants/query_constant.py,sha256=10Dew5MfkDDV6OOZHovQNx9kgdGIv6lmIfu3XATXeko,465
|
76
83
|
defi_services/constants/time_constant.py,sha256=bC-0pYnfIFFR_0iVvkxhfyHfOclWNw9O3DbdO_nh258,181
|
77
84
|
defi_services/constants/token_constant.py,sha256=u1h5zZNEq16UWkh6ZXhto33FG0mRNWIc5amtI8KtwIE,2176
|
78
85
|
defi_services/constants/entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
79
|
-
defi_services/constants/entities/lending_constant.py,sha256=
|
80
|
-
defi_services/constants/entities/lending_services.py,sha256=
|
86
|
+
defi_services/constants/entities/lending_constant.py,sha256=IuTqWSB2UTuibcqGNxr6fw2RSPwx62nUB04ISvi2Hy4,814
|
87
|
+
defi_services/constants/entities/lending_services.py,sha256=0ZNRnUBAh0H6IZ3dzSDW-5nZP3X3KPmUxjuY_9Txn8E,3520
|
81
88
|
defi_services/database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
82
89
|
defi_services/database/mongodb.py,sha256=hygAesHERCJT5qqPhEWNGI0Z1zFMZFip6puwgNOylKo,1170
|
83
90
|
defi_services/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
84
91
|
defi_services/jobs/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
85
92
|
defi_services/jobs/processors/solana_state_processor.py,sha256=PBjqwHtzVLw87cfRuzYI6FxM-AUtuxWRW9mqR2vBz6c,4257
|
86
93
|
defi_services/jobs/processors/state_processor.py,sha256=rGwZC2zQue-pIlodGUxbhQ_XYkmulpnU1u002Ui-0Uk,5992
|
94
|
+
defi_services/jobs/processors/substrate_state_processor.py,sha256=xZm-gbLHCgDMIKffohm9OJGapfqlkD2yzDqRQG0o8Wk,3935
|
87
95
|
defi_services/jobs/queriers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
88
96
|
defi_services/jobs/queriers/solana_state_querier.py,sha256=TQELYo6GUoF8s-LfetqYbclNaH8bakQqC7y2ifACIb8,3239
|
89
97
|
defi_services/jobs/queriers/state_querier.py,sha256=mV9VUPLXnS_zBDF9peQRMwZ1WRqK_He4kPhwHfm4aTw,5756
|
98
|
+
defi_services/jobs/queriers/substrate_state_querier.py,sha256=tQEKndP8zARySIxilnduA5GYgq-h9qYCuLyL-DjDmek,3225
|
90
99
|
defi_services/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
91
100
|
defi_services/services/nft_services.py,sha256=EAp_fOlA-Gee3VM1QqoHRigs4Q2-JIHDSrMMJxZ4PMU,2142
|
92
101
|
defi_services/services/protocol_services.py,sha256=kqhZogkwg26zoKWS3EZuZwYqPtsM_TWbYYnz45qVqQ0,818
|
93
102
|
defi_services/services/solana_token_services.py,sha256=ecFBTOxCLueoyAHSHovvNCWqASIZY7J1C0u4Ca1ewEg,1753
|
103
|
+
defi_services/services/substrate_token_services.py,sha256=HsjceBHo0fxQIcXgDaV0OBANLuggRwXAEPt7ASB0BKk,2904
|
94
104
|
defi_services/services/token_services.py,sha256=mHTvu5tHGB9kfoeYf12sOjSgFm0TyxyFyKX3X7Vm-iA,2766
|
95
105
|
defi_services/services/lending/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
96
106
|
defi_services/services/lending/aave_v2_services.py,sha256=-yUX2PNaMSuo3AgKW1XxtUccQ5jiPYTFjvKRMrjM6cQ,23742
|
97
|
-
defi_services/services/lending/aave_v3_services.py,sha256=
|
98
|
-
defi_services/services/lending/compound_service.py,sha256=
|
107
|
+
defi_services/services/lending/aave_v3_services.py,sha256=9dag6lTzvBYGGEgwjq4fi8TLa2yFDTGnEp11AIXieu8,15506
|
108
|
+
defi_services/services/lending/compound_service.py,sha256=g8B-BNpAkVB_C8feuspjoLWrk36w3USec2IAHYp8R7A,25461
|
99
109
|
defi_services/services/lending/cream_services.py,sha256=aNVeIganORLv7mYtjQw4lw52B6aZbhG9YK-fjlszX6c,1742
|
100
|
-
defi_services/services/lending/flux_services.py,sha256=
|
110
|
+
defi_services/services/lending/flux_services.py,sha256=kEvtrxt9otIdVn-7Ul83P9u_g7uNUVu9ts2vXL0Olgk,16098
|
101
111
|
defi_services/services/lending/geist_services.py,sha256=UI5D-MbMqplrt7D4krSFdpaREKOT81k8boD_XhGGpUQ,1035
|
102
112
|
defi_services/services/lending/granary_v1_services.py,sha256=K54Yzrlyf5A67V9xB43tQIkxwYAmHD7pi1gIpuh79AQ,12435
|
103
|
-
defi_services/services/lending/iron_bank_service.py,sha256=
|
113
|
+
defi_services/services/lending/iron_bank_service.py,sha256=N6wt9KUQITHmFbOn7-aZxZHPOjUplFOIaCUxqtmlZDU,16617
|
104
114
|
defi_services/services/lending/liqee_service.py,sha256=o7Tzt6cpWbwOKqZvhhotbng2y8z27n9aCplKECaWTdQ,13905
|
105
|
-
defi_services/services/lending/
|
115
|
+
defi_services/services/lending/morpho_aave_v2_services.py,sha256=i1UR58XulFyk35PLq6s1Fd3s-JDPtbWStUfg0p2XB6E,3937
|
116
|
+
defi_services/services/lending/morpho_aave_v3_services.py,sha256=OIvyqkcJCKigNfCn9-w3nH-Tw5D9F05Lp0Eu0FLqJ78,7360
|
117
|
+
defi_services/services/lending/morpho_compound_services.py,sha256=96TP8dOSFt4Yz3ds40YZrEwIBBnHjAlxM7SiBb8NUE4,10422
|
118
|
+
defi_services/services/lending/onyx_service.py,sha256=81f8CVyAeDxcw4TX19VGI8Wy_OX1tRBuRoV6MizWqXI,15602
|
106
119
|
defi_services/services/lending/radiant_v2_services.py,sha256=rT7TbSJEOF4oUS9gOE8m2kIvpDP6cCTBwAy9hK89vDg,2182
|
107
|
-
defi_services/services/lending/strike_service.py,sha256=
|
120
|
+
defi_services/services/lending/strike_service.py,sha256=HXdFDk2aVbIML08WTRaMsMoTuBQMPmJz6kShuf8j4lw,17370
|
108
121
|
defi_services/services/lending/trava_services.py,sha256=vCpey07spMB4PyDBX-6U9UMGDGUnFJjIeKNHCNBTZP0,20902
|
109
122
|
defi_services/services/lending/uwu_services.py,sha256=AY-lio6HZLBXIPHh_VTe_DoXnJW4GXy3Z45rbtgObZc,23368
|
110
123
|
defi_services/services/lending/valas_services.py,sha256=vYx8oYY7BY4pRNEFBVVX2T0ca-V3ixcilEwA5i5vnL0,20453
|
111
|
-
defi_services/services/lending/venus_services.py,sha256=
|
124
|
+
defi_services/services/lending/venus_services.py,sha256=WWw6JC_KRjBv391V59FEMutO_CwmiCaxXW6pfTEc8JQ,16812
|
112
125
|
defi_services/services/lending/wepiggy_services.py,sha256=l-YuysxKkLt19DqYYyJGg8eNeyICiBB1qAQUi2qcNuI,24920
|
113
126
|
defi_services/services/lending/lending_info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
114
|
-
defi_services/services/lending/lending_info/aave_v2_services.py,sha256=
|
127
|
+
defi_services/services/lending/lending_info/aave_v2_services.py,sha256=FpWbU6XbPmBZYiuYK0PKo7020_3lD1hdUWiN11_uMT8,22500
|
115
128
|
defi_services/services/lending/lending_info/arbitrum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
116
129
|
defi_services/services/lending/lending_info/arbitrum/aave_v3_arbitrum.py,sha256=8lpLYjXE2bKijTeWjRQH4XUFhG3s7df3J3r5oZEZcjA,3556
|
117
130
|
defi_services/services/lending/lending_info/arbitrum/radiant_arbitrum.py,sha256=1iXoZml8c1iVdshqzZ7YRVcS5lc2RK6A2AnPfO4s49U,2662
|
@@ -132,6 +145,9 @@ defi_services/services/lending/lending_info/ethereum/flux_eth.py,sha256=Iw-hvmFc
|
|
132
145
|
defi_services/services/lending/lending_info/ethereum/granary_v1_eth.py,sha256=iHxSgni9ogXP-4OYtslcEe0XsUYS-_sfa5VfuwMWKFY,2057
|
133
146
|
defi_services/services/lending/lending_info/ethereum/iron_bank_eth.py,sha256=Fx8YZ0j0ylvTVMlJNV_smOoefHuh7qXy0tE1XpBguoI,4680
|
134
147
|
defi_services/services/lending/lending_info/ethereum/liqee_eth.py,sha256=jlotnIFzlxYUQyjkZS4Svp9a-acvZNyg3foQxm9Vrl0,3537
|
148
|
+
defi_services/services/lending/lending_info/ethereum/morpho_aave_v2_eth.py,sha256=OaA1PS2zFuJij9ZdQg0Qfs3uCgKEWYqG9-Bcjhmat9U,2598
|
149
|
+
defi_services/services/lending/lending_info/ethereum/morpho_aave_v3_eth.py,sha256=6H_jutoidmZ7tKlVI6FfAtVVNbPwVXjCg6Rig4b4y4M,2473
|
150
|
+
defi_services/services/lending/lending_info/ethereum/morpho_compound_eth.py,sha256=0TA_hXGpT9RyhaQOdmctsMWG9yECUe-xwJHorDUGVec,1882
|
135
151
|
defi_services/services/lending/lending_info/ethereum/onyx_eth.py,sha256=N2pu-jrDX17R40hvvXWvcSj98w-S2tIAjjW7IcGYJMw,3451
|
136
152
|
defi_services/services/lending/lending_info/ethereum/spark_eth.py,sha256=WDbeBW2i3IytwI92L25hxCXsFaMik32vuHPHg_-SPc8,5681
|
137
153
|
defi_services/services/lending/lending_info/ethereum/strike_eth.py,sha256=tdtisQnjheDC3EO4zHIDOYHHtwABDGGSK-x70gpo2s0,2849
|
@@ -153,8 +169,8 @@ defi_services/utils/init_services.py,sha256=by5TgYBY3Dyl9Fqbf-FCeCYe5FmU28SJNxNW
|
|
153
169
|
defi_services/utils/logger_utils.py,sha256=KxDlmaK9aoMOI1gdroRYjMm383myvFiWqW0iKV0SabY,777
|
154
170
|
defi_services/utils/market_service.py,sha256=imPtPHBkpEx5JnhqeIWYqbCjsIEm8IKBYHNEy6rKjdU,723
|
155
171
|
defi_services/utils/memory_storage.py,sha256=BOT8laB0iVSCGE-oDlpWJQLbSC6X2blKX4zuQbs4inc,851
|
156
|
-
defi_state_querier-0.0.
|
157
|
-
defi_state_querier-0.0.
|
158
|
-
defi_state_querier-0.0.
|
159
|
-
defi_state_querier-0.0.
|
160
|
-
defi_state_querier-0.0.
|
172
|
+
defi_state_querier-0.0.9.dist-info/LICENSE,sha256=6jmfxa8nUIwfKnzZUxAHJSJ_IS7h7mpbJq26cWjoo-o,1063
|
173
|
+
defi_state_querier-0.0.9.dist-info/METADATA,sha256=wNOU-h_u69kGHclZevhbOcgyyXpKhP6N71xq8BN3d6M,3879
|
174
|
+
defi_state_querier-0.0.9.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
175
|
+
defi_state_querier-0.0.9.dist-info/top_level.txt,sha256=C-OTxHK6MknKK-nAbEzCPDUl1M6pktRhgJrmsozdf6g,14
|
176
|
+
defi_state_querier-0.0.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|