defi-state-querier 0.0.6__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/abis/lending/radiant_v2/__init__.py +0 -0
- defi_services/abis/lending/radiant_v2/radiant_v2_incentive_abi.py +1016 -0
- defi_services/abis/lending/wepiggy/__init__.py +0 -0
- defi_services/abis/lending/wepiggy/wepiggy_distribution_abi.py +1047 -0
- defi_services/constants/chain_constant.py +1 -0
- defi_services/constants/entities/lending_constant.py +26 -0
- defi_services/constants/entities/lending_services.py +85 -0
- defi_services/constants/query_constant.py +1 -0
- defi_services/constants/token_constant.py +2 -0
- defi_services/jobs/processors/__init__.py +0 -0
- defi_services/jobs/processors/solana_state_processor.py +101 -0
- defi_services/jobs/{state_processor.py → processors/state_processor.py} +9 -4
- defi_services/jobs/processors/substrate_state_processor.py +97 -0
- defi_services/jobs/queriers/__init__.py +0 -0
- defi_services/jobs/queriers/solana_state_querier.py +83 -0
- defi_services/jobs/{state_querier.py → queriers/state_querier.py} +3 -2
- defi_services/jobs/queriers/substrate_state_querier.py +84 -0
- defi_services/services/lending/aave_v2_services.py +8 -7
- defi_services/services/lending/aave_v3_services.py +12 -9
- defi_services/services/lending/compound_service.py +29 -10
- defi_services/services/lending/cream_services.py +5 -4
- defi_services/services/lending/flux_services.py +34 -27
- defi_services/services/lending/geist_services.py +4 -3
- defi_services/services/lending/granary_v1_services.py +6 -7
- defi_services/services/lending/iron_bank_service.py +20 -13
- defi_services/services/lending/lending_info/aave_v2_services.py +2 -2
- 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/lending_info/ethereum/wepiggy_eth.py +41 -0
- defi_services/services/lending/liqee_service.py +5 -26
- 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 +32 -13
- defi_services/services/lending/radiant_v2_services.py +30 -3
- defi_services/services/lending/strike_service.py +29 -10
- defi_services/services/lending/trava_services.py +8 -7
- defi_services/services/lending/uwu_services.py +8 -7
- defi_services/services/lending/valas_services.py +6 -5
- defi_services/services/lending/venus_services.py +28 -8
- defi_services/services/lending/wepiggy_services.py +519 -0
- defi_services/services/nft_services.py +1 -1
- defi_services/services/solana_token_services.py +46 -0
- defi_services/services/substrate_token_services.py +70 -0
- defi_services/services/token_services.py +1 -3
- defi_services/utils/init_services.py +3 -3
- {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/METADATA +3 -3
- {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/RECORD +60 -32
- defi_services/constants/entities/lending.py +0 -97
- {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/LICENSE +0 -0
- {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/WHEEL +0 -0
- {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/top_level.txt +0 -0
@@ -5,11 +5,13 @@ from web3 import Web3
|
|
5
5
|
from defi_services.abis.lending.aave_v3.aave_v3_incentives_abi import AAVE_V3_INCENTIVES_ABI
|
6
6
|
from defi_services.abis.lending.aave_v3.aave_v3_lending_pool_abi import AAVE_V3_LENDING_POOL_ABI
|
7
7
|
from defi_services.abis.lending.aave_v3.aave_v3_oracle_abi import AAVE_V3_ORACLE_ABI
|
8
|
+
from defi_services.abis.lending.morpho.morpho_aave_v3_comptroller_abi import MORPHO_AAVE_V3_COMPTROLLER_ABI
|
8
9
|
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
9
10
|
from defi_services.constants.chain_constant import Chain
|
10
11
|
from defi_services.constants.db_constant import DBConst
|
12
|
+
from defi_services.constants.entities.lending_constant import Lending
|
11
13
|
from defi_services.constants.time_constant import TimeConstants
|
12
|
-
from defi_services.jobs.state_querier import StateQuerier
|
14
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
13
15
|
from defi_services.services.lending.aave_v2_services import AaveV2StateService
|
14
16
|
from defi_services.services.lending.lending_info.arbitrum.aave_v3_arbitrum import AAVE_V3_ARB
|
15
17
|
from defi_services.services.lending.lending_info.avalanche.aave_v3_avalanche import AAVE_V3_AVALANCHE
|
@@ -21,7 +23,7 @@ from defi_services.services.lending.lending_info.polygon.aave_v3_polygon import
|
|
21
23
|
logger = logging.getLogger("Aave V3 Lending Pool State Service")
|
22
24
|
|
23
25
|
|
24
|
-
class
|
26
|
+
class AaveV3Info:
|
25
27
|
mapping = {
|
26
28
|
Chain.ethereum: AAVE_V3_ETH,
|
27
29
|
Chain.polygon: AAVE_V3_POLYGON,
|
@@ -35,17 +37,18 @@ class AaveInfo:
|
|
35
37
|
class AaveV3StateService(AaveV2StateService):
|
36
38
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
37
39
|
super().__init__(state_service, chain_id)
|
38
|
-
self.name = f"{chain_id}
|
40
|
+
self.name = f"{chain_id}_{Lending.aave_v3}"
|
39
41
|
self.chain_id = chain_id
|
40
|
-
self.pool_info =
|
42
|
+
self.pool_info = AaveV3Info.mapping.get(chain_id)
|
41
43
|
self.lending_abi = AAVE_V3_LENDING_POOL_ABI
|
42
44
|
self.incentive_abi = AAVE_V3_INCENTIVES_ABI
|
43
45
|
self.oracle_abi = AAVE_V3_ORACLE_ABI
|
46
|
+
self.comptroller_abi = MORPHO_AAVE_V3_COMPTROLLER_ABI
|
44
47
|
self.state_service = state_service
|
45
48
|
|
46
49
|
def get_service_info(self):
|
47
50
|
info = {
|
48
|
-
|
51
|
+
Lending.aave_v3: {
|
49
52
|
"chain_id": self.chain_id,
|
50
53
|
"type": "lending",
|
51
54
|
"protocol_info": self.pool_info
|
@@ -89,7 +92,7 @@ class AaveV3StateService(AaveV2StateService):
|
|
89
92
|
"getAssetsPrices", list(reserves_info.keys()), block_number)
|
90
93
|
reward_tokens = self.pool_info.get("rewardTokensList")
|
91
94
|
for token_address, value in reserves_info.items():
|
92
|
-
reserve_key = f"getReserveData_{token_address}_{block_number}".lower()
|
95
|
+
reserve_key = f"getReserveData_{self.name}_{token_address}_{block_number}".lower()
|
93
96
|
atoken_total_supply_key = f'totalSupply_{value["tToken"]}_{block_number}'.lower()
|
94
97
|
debt_token_total_supply_key = f'totalSupply_{value["dToken"]}_{block_number}'.lower()
|
95
98
|
sdebt_token_total_supply_key = f'totalSupply_{value["sdToken"]}_{block_number}'.lower()
|
@@ -200,7 +203,7 @@ class AaveV3StateService(AaveV2StateService):
|
|
200
203
|
):
|
201
204
|
reserves_data = {}
|
202
205
|
for token in reserves_info:
|
203
|
-
get_reserve_data_call_id = f'getReserveData_{token}_{block_number}'.lower()
|
206
|
+
get_reserve_data_call_id = f'getReserveData_{self.name}_{token}_{block_number}'.lower()
|
204
207
|
reserves_data[token.lower()] = decoded_data.get(get_reserve_data_call_id)
|
205
208
|
reward_tokens = self.pool_info.get("rewardTokensList")
|
206
209
|
interest_rate, atokens, debt_tokens, sdebt_tokens, decimals, asset_data_tokens = {}, {}, {}, {}, {}, {}
|
@@ -270,13 +273,13 @@ class AaveV3StateService(AaveV2StateService):
|
|
270
273
|
tokens = []
|
271
274
|
for key, value in reserves_info.items():
|
272
275
|
tokens += [Web3.toChecksumAddress(value["tToken"]), Web3.toChecksumAddress(value["dToken"])]
|
273
|
-
key = f"getAllUserRewards_{wallet_address}_{block_number}".lower()
|
276
|
+
key = f"getAllUserRewards_{self.name}_{wallet_address}_{block_number}".lower()
|
274
277
|
rpc_calls[key] = self.get_function_incentive_info("getAllUserRewards", [tokens, Web3.toChecksumAddress(wallet_address)], block_number)
|
275
278
|
return rpc_calls
|
276
279
|
|
277
280
|
def calculate_all_rewards_balance(
|
278
281
|
self, decoded_data: dict, wallet_address: str, block_number: int = "latest"):
|
279
|
-
key = f"getAllUserRewards_{wallet_address}_{block_number}".lower()
|
282
|
+
key = f"getAllUserRewards_{self.name}_{wallet_address}_{block_number}".lower()
|
280
283
|
rewards = decoded_data.get(key)
|
281
284
|
result = dict(zip(*rewards))
|
282
285
|
for key, value in result.items():
|
@@ -9,9 +9,10 @@ from defi_services.abis.token.ctoken_abi import CTOKEN_ABI
|
|
9
9
|
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
10
10
|
from defi_services.constants.chain_constant import Chain
|
11
11
|
from defi_services.constants.db_constant import DBConst
|
12
|
+
from defi_services.constants.entities.lending_constant import Lending
|
12
13
|
from defi_services.constants.query_constant import Query
|
13
14
|
from defi_services.constants.token_constant import ContractAddresses, Token
|
14
|
-
from defi_services.jobs.state_querier import StateQuerier
|
15
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
15
16
|
from defi_services.services.lending.lending_info.ethereum.compound_eth import COMPOUND_ETH
|
16
17
|
from defi_services.services.protocol_services import ProtocolServices
|
17
18
|
|
@@ -26,7 +27,7 @@ class CompoundInfo:
|
|
26
27
|
|
27
28
|
class CompoundStateService(ProtocolServices):
|
28
29
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
29
|
-
self.name = f"{chain_id}
|
30
|
+
self.name = f"{chain_id}_{Lending.compound}"
|
30
31
|
self.chain_id = chain_id
|
31
32
|
self.pool_info = CompoundInfo.mapping.get(chain_id)
|
32
33
|
self.state_service = state_service
|
@@ -36,7 +37,7 @@ class CompoundStateService(ProtocolServices):
|
|
36
37
|
# BASIC FUNCTIONS
|
37
38
|
def get_service_info(self):
|
38
39
|
info = {
|
39
|
-
|
40
|
+
Lending.compound: {
|
40
41
|
"chain_id": self.chain_id,
|
41
42
|
"type": "lending",
|
42
43
|
"protocol_info": self.pool_info
|
@@ -105,7 +106,7 @@ class CompoundStateService(ProtocolServices):
|
|
105
106
|
))
|
106
107
|
|
107
108
|
if Query.protocol_reward in query_types and wallet:
|
108
|
-
result.update(self.
|
109
|
+
result.update(self.calculate_claimable_rewards_balance(
|
109
110
|
wallet, decoded_data, block_number
|
110
111
|
))
|
111
112
|
|
@@ -138,7 +139,7 @@ class CompoundStateService(ProtocolServices):
|
|
138
139
|
rpc_calls.update(self.get_apy_lending_pool_function_info(reserves_info, block_number, is_oracle_price))
|
139
140
|
|
140
141
|
if Query.protocol_reward in query_types and wallet:
|
141
|
-
rpc_calls.update(self.
|
142
|
+
rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
|
142
143
|
|
143
144
|
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
144
145
|
return rpc_calls
|
@@ -155,10 +156,10 @@ class CompoundStateService(ProtocolServices):
|
|
155
156
|
ctoken = value.get("ctoken")
|
156
157
|
speed_key = f"compSpeeds_{ctoken}_{block_number}".lower()
|
157
158
|
mint_key = f"mintGuardianPaused_{ctoken}_{block_number}".lower()
|
158
|
-
borrow_key = f"borrowGuardianPaused_{
|
159
|
-
metadata_key = f"cTokenMetadata_{
|
159
|
+
borrow_key = f"borrowGuardianPaused_{ctoken}_{block_number}".lower()
|
160
|
+
metadata_key = f"cTokenMetadata_{ctoken}_{block_number}".lower()
|
160
161
|
if is_price_oracle:
|
161
|
-
price_key = f"cTokenUnderlyingPrice_{
|
162
|
+
price_key = f"cTokenUnderlyingPrice_{ctoken}_{block_number}".lower()
|
162
163
|
rpc_calls[price_key] = self.get_comptroller_function_info('cTokenUnderlyingPrice', [ctoken],
|
163
164
|
block_number)
|
164
165
|
rpc_calls[speed_key] = self.get_comptroller_function_info('compSpeeds', [ctoken], block_number)
|
@@ -303,6 +304,24 @@ class CompoundStateService(ProtocolServices):
|
|
303
304
|
}
|
304
305
|
|
305
306
|
# REWARDS BALANCE
|
307
|
+
def get_claimable_rewards_balance_function_info(
|
308
|
+
self,
|
309
|
+
wallet_address: str,
|
310
|
+
block_number: int = "latest",
|
311
|
+
):
|
312
|
+
rpc_call = self.get_comptroller_function_info("compAccrued", [wallet_address], block_number)
|
313
|
+
get_reward_id = f"compAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
314
|
+
return {get_reward_id: rpc_call}
|
315
|
+
|
316
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict, block_number: int = "latest"):
|
317
|
+
get_reward_id = f"compAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
318
|
+
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
319
|
+
reward_token = self.pool_info.get("rewardToken")
|
320
|
+
result = {
|
321
|
+
reward_token: {"amount": rewards}
|
322
|
+
}
|
323
|
+
return result
|
324
|
+
|
306
325
|
def get_rewards_balance_function_info(
|
307
326
|
self,
|
308
327
|
wallet_address: str,
|
@@ -313,11 +332,11 @@ class CompoundStateService(ProtocolServices):
|
|
313
332
|
Web3.toChecksumAddress(self.pool_info.get("comptrollerAddress")),
|
314
333
|
Web3.toChecksumAddress(wallet_address)]
|
315
334
|
rpc_call = self.get_lens_function_info("getCompBalanceMetadataExt", fn_paras, block_number)
|
316
|
-
get_reward_id = f"getCompBalanceMetadataExt_{wallet_address}_{block_number}".lower()
|
335
|
+
get_reward_id = f"getCompBalanceMetadataExt_{self.name}_{wallet_address}_{block_number}".lower()
|
317
336
|
return {get_reward_id: rpc_call}
|
318
337
|
|
319
338
|
def calculate_rewards_balance(self, wallet_address: str, decoded_data: dict, block_number: int = "latest"):
|
320
|
-
get_reward_id = f"getCompBalanceMetadataExt_{wallet_address}_{block_number}".lower()
|
339
|
+
get_reward_id = f"getCompBalanceMetadataExt_{self.name}_{wallet_address}_{block_number}".lower()
|
321
340
|
rewards = decoded_data.get(get_reward_id)[-1] / 10 ** 18
|
322
341
|
reward_token = self.pool_info.get("rewardToken")
|
323
342
|
result = {
|
@@ -3,7 +3,8 @@ import logging
|
|
3
3
|
from web3 import Web3
|
4
4
|
|
5
5
|
from defi_services.constants.chain_constant import Chain
|
6
|
-
from defi_services.
|
6
|
+
from defi_services.constants.entities.lending_constant import Lending
|
7
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
7
8
|
from defi_services.services.lending.compound_service import CompoundStateService
|
8
9
|
from defi_services.services.lending.lending_info.bsc.cream_bsc import CREAM_BSC
|
9
10
|
|
@@ -19,13 +20,13 @@ class CreamInfo:
|
|
19
20
|
class CreamStateService(CompoundStateService):
|
20
21
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
21
22
|
super().__init__(state_service, chain_id)
|
22
|
-
self.name = f"{chain_id}
|
23
|
+
self.name = f"{chain_id}_{Lending.cream}"
|
23
24
|
self.chain_id = chain_id
|
24
25
|
self.pool_info = CreamInfo.mapping.get(chain_id)
|
25
26
|
|
26
27
|
def get_service_info(self):
|
27
28
|
info = {
|
28
|
-
|
29
|
+
Lending.cream: {
|
29
30
|
"chain_id": self.chain_id,
|
30
31
|
"type": "lending",
|
31
32
|
"protocol_info": self.pool_info
|
@@ -43,6 +44,6 @@ class CreamStateService(CompoundStateService):
|
|
43
44
|
Web3.toChecksumAddress(self.pool_info.get("comptrollerImplementationAddress")),
|
44
45
|
Web3.toChecksumAddress(wallet_address)]
|
45
46
|
rpc_call = self.get_lens_function_info("getCompBalanceMetadataExt", fn_paras, block_number)
|
46
|
-
get_reward_id = f"getCompBalanceMetadataExt_{wallet_address}_{block_number}".lower()
|
47
|
+
get_reward_id = f"getCompBalanceMetadataExt_{self.name}_{wallet_address}_{block_number}".lower()
|
47
48
|
return {get_reward_id: rpc_call}
|
48
49
|
|
@@ -8,10 +8,10 @@ from defi_services.abis.lending.cream.cream_lens_abi import CREAM_LENS_ABI
|
|
8
8
|
from defi_services.abis.token.ctoken_abi import CTOKEN_ABI
|
9
9
|
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
10
10
|
from defi_services.constants.chain_constant import Chain
|
11
|
-
from defi_services.constants.
|
11
|
+
from defi_services.constants.entities.lending_constant import Lending
|
12
12
|
from defi_services.constants.query_constant import Query
|
13
13
|
from defi_services.constants.token_constant import ContractAddresses, Token
|
14
|
-
from defi_services.jobs.state_querier import StateQuerier
|
14
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
15
15
|
from defi_services.services.lending.lending_info.ethereum.flux_eth import FLUX_ETH
|
16
16
|
from defi_services.services.protocol_services import ProtocolServices
|
17
17
|
|
@@ -26,10 +26,9 @@ class FluxInfo:
|
|
26
26
|
|
27
27
|
class FluxStateService(ProtocolServices):
|
28
28
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
29
|
-
self.name = f"{chain_id}
|
30
|
-
self.name = f"{chain_id}_flux"
|
29
|
+
self.name = f"{chain_id}_{Lending.flux}"
|
31
30
|
self.chain_id = chain_id
|
32
|
-
self.
|
31
|
+
self.pool_info = FluxInfo.mapping.get(chain_id)
|
33
32
|
self.state_service = state_service
|
34
33
|
self.lens_abi = CREAM_LENS_ABI
|
35
34
|
self.comptroller_abi = CREAM_COMPTROLLER_ABI
|
@@ -37,10 +36,10 @@ class FluxStateService(ProtocolServices):
|
|
37
36
|
# BASIC FUNCTIONS
|
38
37
|
def get_service_info(self):
|
39
38
|
info = {
|
40
|
-
|
39
|
+
Lending.flux: {
|
41
40
|
"chain_id": self.chain_id,
|
42
41
|
"type": "lending",
|
43
|
-
"protocol_info": self.
|
42
|
+
"protocol_info": self.pool_info
|
44
43
|
}
|
45
44
|
}
|
46
45
|
return info
|
@@ -50,7 +49,7 @@ class FluxStateService(ProtocolServices):
|
|
50
49
|
block_number: int = "latest"):
|
51
50
|
_w3 = self.state_service.get_w3()
|
52
51
|
comptroller_contract = _w3.eth.contract(
|
53
|
-
address=_w3.toChecksumAddress(self.
|
52
|
+
address=_w3.toChecksumAddress(self.pool_info.get("comptrollerAddress")), abi=self.comptroller_abi)
|
54
53
|
ctokens = []
|
55
54
|
for token in comptroller_contract.functions.getAllMarkets().call(block_identifier=block_number):
|
56
55
|
if token in [ContractAddresses.LUNA.lower(), ContractAddresses.UST.lower(), ContractAddresses.LUNA,
|
@@ -59,7 +58,7 @@ class FluxStateService(ProtocolServices):
|
|
59
58
|
ctokens.append(token)
|
60
59
|
|
61
60
|
lens_contract = _w3.eth.contract(
|
62
|
-
address=Web3.toChecksumAddress(self.
|
61
|
+
address=Web3.toChecksumAddress(self.pool_info.get("lensAddress")), abi=self.lens_abi
|
63
62
|
)
|
64
63
|
tokens = [Web3.toChecksumAddress(i) for i in ctokens]
|
65
64
|
metadata = lens_contract.functions.cTokenMetadataAll(tokens).call(block_identifier=block_number)
|
@@ -76,8 +75,8 @@ class FluxStateService(ProtocolServices):
|
|
76
75
|
|
77
76
|
def get_token_list(self):
|
78
77
|
begin = time.time()
|
79
|
-
tokens = [self.
|
80
|
-
for token in self.
|
78
|
+
tokens = [self.pool_info.get('rewardToken'), self.pool_info.get("poolToken")]
|
79
|
+
for token in self.pool_info.get("reservesList"):
|
81
80
|
if token == Token.native_token:
|
82
81
|
tokens.append(Token.wrapped_token.get(self.chain_id))
|
83
82
|
continue
|
@@ -94,7 +93,7 @@ class FluxStateService(ProtocolServices):
|
|
94
93
|
**kwargs
|
95
94
|
):
|
96
95
|
begin = time.time()
|
97
|
-
reserves_info = kwargs.get("reserves_info", self.
|
96
|
+
reserves_info = kwargs.get("reserves_info", self.pool_info.get("reservesList"))
|
98
97
|
token_prices = kwargs.get("token_prices", {})
|
99
98
|
wrapped_native_token_price = token_prices.get(Token.wrapped_token.get(self.chain_id), 1)
|
100
99
|
pool_decimals = kwargs.get("pool_decimals", 18)
|
@@ -105,7 +104,7 @@ class FluxStateService(ProtocolServices):
|
|
105
104
|
))
|
106
105
|
|
107
106
|
if Query.protocol_reward in query_types and wallet:
|
108
|
-
result.update(self.
|
107
|
+
result.update(self.calculate_claimable_rewards_balance(
|
109
108
|
wallet, decoded_data, block_number
|
110
109
|
))
|
111
110
|
|
@@ -123,7 +122,7 @@ class FluxStateService(ProtocolServices):
|
|
123
122
|
reserves_info = kwargs.get("reserves_info", {})
|
124
123
|
is_oracle_price = kwargs.get("is_oracle_price", False) # get price by oracle
|
125
124
|
if not reserves_info:
|
126
|
-
reserves_info = self.
|
125
|
+
reserves_info = self.pool_info['reservesList']
|
127
126
|
rpc_calls = {}
|
128
127
|
if Query.deposit_borrow in query_types and wallet:
|
129
128
|
rpc_calls.update(self.get_wallet_deposit_borrow_balance_function_info(
|
@@ -131,21 +130,30 @@ class FluxStateService(ProtocolServices):
|
|
131
130
|
))
|
132
131
|
|
133
132
|
if Query.protocol_reward in query_types and wallet:
|
134
|
-
rpc_calls.update(self.
|
133
|
+
rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
|
135
134
|
|
136
135
|
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
137
136
|
return rpc_calls
|
138
137
|
|
139
138
|
# REWARDS BALANCE
|
140
|
-
def
|
139
|
+
def get_claimable_rewards_balance_function_info(
|
141
140
|
self,
|
142
141
|
wallet_address: str,
|
143
142
|
block_number: int = "latest",
|
144
143
|
):
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
rpc_call = self.get_comptroller_function_info("compAccrued", [wallet_address], block_number)
|
145
|
+
get_reward_id = f"compAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
146
|
+
return {get_reward_id: rpc_call}
|
147
|
+
|
148
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
149
|
+
block_number: int = "latest"):
|
150
|
+
get_reward_id = f"compAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
151
|
+
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
152
|
+
reward_token = self.pool_info.get("rewardToken")
|
153
|
+
result = {
|
154
|
+
reward_token: {"amount": rewards}
|
155
|
+
}
|
156
|
+
return result
|
149
157
|
|
150
158
|
# WALLET DEPOSIT BORROW BALANCE
|
151
159
|
def get_wallet_deposit_borrow_balance_function_info(
|
@@ -292,15 +300,14 @@ class FluxStateService(ProtocolServices):
|
|
292
300
|
result[token]['deposit_amount_in_usd'] += deposit_amount_in_usd
|
293
301
|
return result
|
294
302
|
|
295
|
-
|
296
303
|
def get_lens_function_info(self, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
297
304
|
return self.state_service.get_function_info(
|
298
|
-
self.
|
305
|
+
self.pool_info['lensAddress'], self.lens_abi, fn_name, fn_paras, block_number
|
299
306
|
)
|
300
307
|
|
301
308
|
def get_comptroller_function_info(self, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
302
309
|
return self.state_service.get_function_info(
|
303
|
-
self.
|
310
|
+
self.pool_info['comptrollerAddress'], self.comptroller_abi, fn_name, fn_paras, block_number
|
304
311
|
)
|
305
312
|
|
306
313
|
def get_ctoken_function_info(self, ctoken: str, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
@@ -314,7 +321,7 @@ class FluxStateService(ProtocolServices):
|
|
314
321
|
block_number: int = "latest"
|
315
322
|
):
|
316
323
|
tokens = [Web3.toChecksumAddress(value['cToken']) for key, value in reserves_info.items()]
|
317
|
-
key = f"cTokenMetadataAll_{self.
|
324
|
+
key = f"cTokenMetadataAll_{self.pool_info.get('lensAddress')}_{block_number}".lower()
|
318
325
|
return {
|
319
326
|
key: self.get_lens_function_info("cTokenMetadataAll", tokens, block_number)
|
320
327
|
}
|
@@ -322,14 +329,14 @@ class FluxStateService(ProtocolServices):
|
|
322
329
|
def ctoken_underlying_price_all(
|
323
330
|
self, reserves_info, block_number: int = 'latest'):
|
324
331
|
tokens = [Web3.toChecksumAddress(value['cToken']) for key, value in reserves_info.items()]
|
325
|
-
key = f"cTokenUnderlyingPriceAll_{self.
|
332
|
+
key = f"cTokenUnderlyingPriceAll_{self.pool_info.get('lensAddress')}_{block_number}".lower()
|
326
333
|
return {
|
327
334
|
key: self.get_lens_function_info("cTokenUnderlyingPriceAll", tokens, block_number)
|
328
335
|
}
|
329
336
|
|
330
337
|
def get_all_markets(
|
331
338
|
self, block_number: int = 'latest'):
|
332
|
-
key = f"getAllMarkets_{self.
|
339
|
+
key = f"getAllMarkets_{self.pool_info.get('comptrollerAddress')}_{block_number}".lower()
|
333
340
|
return {
|
334
341
|
key: self.get_comptroller_function_info("getAllMarkets", [], block_number)
|
335
|
-
}
|
342
|
+
}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import logging
|
2
2
|
|
3
3
|
from defi_services.constants.chain_constant import Chain
|
4
|
-
from defi_services.
|
4
|
+
from defi_services.constants.entities.lending_constant import Lending
|
5
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
5
6
|
from defi_services.services.lending.lending_info.fantom.geist_ftm import GEIST_ETH
|
6
7
|
from defi_services.services.lending.valas_services import ValasStateService
|
7
8
|
|
@@ -17,12 +18,12 @@ class GeistInfo:
|
|
17
18
|
class GeistStateService(ValasStateService):
|
18
19
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0xfa"):
|
19
20
|
super().__init__(state_service, chain_id)
|
20
|
-
self.name = f"{chain_id}
|
21
|
+
self.name = f"{chain_id}_{Lending.geist}"
|
21
22
|
self.pool_info = GeistInfo.mapping.get(chain_id)
|
22
23
|
|
23
24
|
def get_service_info(self):
|
24
25
|
info = {
|
25
|
-
|
26
|
+
Lending.geist: {
|
26
27
|
"chain_id": self.chain_id,
|
27
28
|
"type": "lending",
|
28
29
|
"protocol_info": self.pool_info
|
@@ -8,11 +8,10 @@ from defi_services.abis.lending.aave_v2_and_forlks.oracle_abi import ORACLE_ABI
|
|
8
8
|
from defi_services.abis.lending.granary.granary_rewarder_abi import GRANARY_REWARDER_ABI
|
9
9
|
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
10
10
|
from defi_services.constants.chain_constant import Chain
|
11
|
-
from defi_services.constants.
|
11
|
+
from defi_services.constants.entities.lending_constant import Lending
|
12
12
|
from defi_services.constants.query_constant import Query
|
13
|
-
from defi_services.constants.time_constant import TimeConstants
|
14
13
|
from defi_services.constants.token_constant import Token
|
15
|
-
from defi_services.jobs.state_querier import StateQuerier
|
14
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
16
15
|
from defi_services.services.lending.lending_info.ethereum.granary_v1_eth import GRANARY_V1_ETH
|
17
16
|
from defi_services.services.protocol_services import ProtocolServices
|
18
17
|
|
@@ -27,7 +26,7 @@ class GranaryV1Info:
|
|
27
26
|
|
28
27
|
class GranaryV1StateService(ProtocolServices):
|
29
28
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
30
|
-
self.name = f"{chain_id}
|
29
|
+
self.name = f"{chain_id}_{Lending.granary}"
|
31
30
|
self.chain_id = chain_id
|
32
31
|
self.pool_info = GranaryV1Info.mapping.get(chain_id)
|
33
32
|
self.lending_abi = LENDING_POOL_ABI
|
@@ -39,7 +38,7 @@ class GranaryV1StateService(ProtocolServices):
|
|
39
38
|
# BASIC FUNCTION
|
40
39
|
def get_service_info(self):
|
41
40
|
info = {
|
42
|
-
|
41
|
+
Lending.granary: {
|
43
42
|
"chain_id": self.chain_id,
|
44
43
|
"type": "lending",
|
45
44
|
"protocol_info": self.pool_info
|
@@ -244,7 +243,7 @@ class GranaryV1StateService(ProtocolServices):
|
|
244
243
|
for token, value in reserves_info.items():
|
245
244
|
atoken, debt_token = Web3.toChecksumAddress(value['tToken']), Web3.toChecksumAddress(value['dToken'])
|
246
245
|
tokens += [atoken, debt_token]
|
247
|
-
key = f"getAllUserRewardsBalance_{wallet_address}_{block_number}".lower()
|
246
|
+
key = f"getAllUserRewardsBalance_{self.name}_{wallet_address}_{block_number}".lower()
|
248
247
|
rpc_calls[key] = self.get_function_rewarder_info(
|
249
248
|
"getAllUserRewardsBalance", [tokens, wallet_address], block_number)
|
250
249
|
|
@@ -253,7 +252,7 @@ class GranaryV1StateService(ProtocolServices):
|
|
253
252
|
def calculate_all_rewards_balance(
|
254
253
|
self, decoded_data: dict, wallet_address: str, block_number: int = "latest"):
|
255
254
|
|
256
|
-
key = f"getAllUserRewardsBalance_{wallet_address}_{block_number}".lower()
|
255
|
+
key = f"getAllUserRewardsBalance_{self.name}_{wallet_address}_{block_number}".lower()
|
257
256
|
reward_token = decoded_data.get(key)[0][0]
|
258
257
|
rewards = decoded_data.get(key)[-1][0] / 10 ** 18
|
259
258
|
result = {
|
@@ -4,15 +4,14 @@ import time
|
|
4
4
|
from web3 import Web3
|
5
5
|
|
6
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
7
|
from defi_services.abis.lending.iron_bank.iron_lens_abi import IRON_LENS_ABI
|
9
8
|
from defi_services.abis.token.ctoken_abi import CTOKEN_ABI
|
10
9
|
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
11
10
|
from defi_services.constants.chain_constant import Chain
|
12
|
-
from defi_services.constants.
|
11
|
+
from defi_services.constants.entities.lending_constant import Lending
|
13
12
|
from defi_services.constants.query_constant import Query
|
14
13
|
from defi_services.constants.token_constant import ContractAddresses, Token
|
15
|
-
from defi_services.jobs.state_querier import StateQuerier
|
14
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
16
15
|
from defi_services.services.lending.lending_info.ethereum.iron_bank_eth import IRON_BANK_ETH
|
17
16
|
from defi_services.services.protocol_services import ProtocolServices
|
18
17
|
|
@@ -27,7 +26,7 @@ class IronBankInfo:
|
|
27
26
|
|
28
27
|
class IronBankStateService(ProtocolServices):
|
29
28
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
30
|
-
self.name = f"{chain_id}
|
29
|
+
self.name = f"{chain_id}_{Lending.iron_bank}"
|
31
30
|
self.chain_id = chain_id
|
32
31
|
self.iron_bank_info = IronBankInfo.mapping.get(chain_id)
|
33
32
|
self.state_service = state_service
|
@@ -37,7 +36,7 @@ class IronBankStateService(ProtocolServices):
|
|
37
36
|
# BASIC FUNCTIONS
|
38
37
|
def get_service_info(self):
|
39
38
|
info = {
|
40
|
-
|
39
|
+
Lending.iron_bank: {
|
41
40
|
"chain_id": self.chain_id,
|
42
41
|
"type": "lending",
|
43
42
|
"protocol_info": self.iron_bank_info
|
@@ -107,7 +106,7 @@ class IronBankStateService(ProtocolServices):
|
|
107
106
|
))
|
108
107
|
|
109
108
|
if Query.protocol_reward in query_types and wallet:
|
110
|
-
result.update(self.
|
109
|
+
result.update(self.calculate_claimable_rewards_balance(
|
111
110
|
wallet, decoded_data, block_number
|
112
111
|
))
|
113
112
|
|
@@ -140,22 +139,30 @@ class IronBankStateService(ProtocolServices):
|
|
140
139
|
# rpc_calls.update(self.get_apy_lending_pool_function_info(reserves_info, block_number, is_oracle_price))
|
141
140
|
|
142
141
|
if Query.protocol_reward in query_types and wallet:
|
143
|
-
rpc_calls.update(self.
|
142
|
+
rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
|
144
143
|
|
145
144
|
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
146
145
|
return rpc_calls
|
147
146
|
|
148
147
|
# REWARDS BALANCE
|
149
|
-
def
|
148
|
+
def get_claimable_rewards_balance_function_info(
|
150
149
|
self,
|
151
150
|
wallet_address: str,
|
152
|
-
reserves_info: dict,
|
153
151
|
block_number: int = "latest",
|
154
152
|
):
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
153
|
+
rpc_call = self.get_comptroller_function_info("compAccrued", [wallet_address], block_number)
|
154
|
+
get_reward_id = f"compAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
155
|
+
return {get_reward_id: rpc_call}
|
156
|
+
|
157
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
158
|
+
block_number: int = "latest"):
|
159
|
+
get_reward_id = f"compAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
160
|
+
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
161
|
+
reward_token = self.iron_bank_info.get("rewardToken")
|
162
|
+
result = {
|
163
|
+
reward_token: {"amount": rewards}
|
164
|
+
}
|
165
|
+
return result
|
159
166
|
|
160
167
|
# WALLET DEPOSIT BORROW BALANCE
|
161
168
|
def get_wallet_deposit_borrow_balance_function_info(
|
@@ -11,7 +11,7 @@ from defi_services.constants.db_constant import DBConst
|
|
11
11
|
from defi_services.constants.query_constant import Query
|
12
12
|
from defi_services.constants.time_constant import TimeConstants
|
13
13
|
from defi_services.constants.token_constant import Token
|
14
|
-
from defi_services.jobs.state_querier import StateQuerier
|
14
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
15
15
|
from defi_services.services.lending.lending_info.ethereum.aave_v2_eth import AAVE_V2_ETH
|
16
16
|
from defi_services.services.lending.lending_info.polygon.aave_v2_polygon import AAVE_V2_POLYGON
|
17
17
|
from defi_services.services.protocol_services import ProtocolServices
|
@@ -75,7 +75,7 @@ class AaveV2StateService(ProtocolServices):
|
|
75
75
|
logger.info(f"Get token list related in {time.time()-begin}s")
|
76
76
|
return tokens
|
77
77
|
|
78
|
-
def
|
78
|
+
def get_data(
|
79
79
|
self,
|
80
80
|
query_types: list,
|
81
81
|
wallet: str,
|
@@ -0,0 +1,53 @@
|
|
1
|
+
MORPHO_AAVE_V2_ETH = {
|
2
|
+
"name": "Compound Lending Pool",
|
3
|
+
"rewardToken": "0x4da27a545c0c5b758a6ba100e3a049001de870f5",
|
4
|
+
"comptrollerAddress": "0x777777c9898d384f785ee44acfe945efdff5f3e0",
|
5
|
+
"lensAddress": "0x507fa343d0a90786d86c7cd885f5c49263a91ff4",
|
6
|
+
"poolToken": "0x9994e35db50125e0df82e4c2dde62496ce330999",
|
7
|
+
"type": "LENDING_POOL",
|
8
|
+
"forked": "morpho",
|
9
|
+
"reservesList": {
|
10
|
+
"0x6b175474e89094c44da98b954eedeac495271d0f": {
|
11
|
+
"tToken": "0x028171bca77440897b824ca71d1c56cac55b68a3",
|
12
|
+
"dToken": "0x6c3c78838c761c6ac7be9f59fe808ea2a6e4379d",
|
13
|
+
"sdToken": "0x778a13d3eeb110a4f7bb6529f99c000119a08e92",
|
14
|
+
"liquidationThreshold": 0.87
|
15
|
+
},
|
16
|
+
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": {
|
17
|
+
"tToken": "0x030ba81f1c18d280636f32af80b9aad02cf0854e",
|
18
|
+
"dToken": "0xf63b34710400cad3e044cffdcab00a0f32e33ecf",
|
19
|
+
"sdToken": "0x4e977830ba4bd783c0bb7f15d3e243f73ff57121",
|
20
|
+
"liquidationThreshold": 0.86
|
21
|
+
},
|
22
|
+
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": {
|
23
|
+
"tToken": "0xbcca60bb61934080951369a648fb03df4f96263c",
|
24
|
+
"dToken": "0x619beb58998ed2278e08620f97007e1116d5d25b",
|
25
|
+
"sdToken": "0xe4922afab0bbadd8ab2a88e0c79d884ad337fca6",
|
26
|
+
"liquidationThreshold": 0.875
|
27
|
+
},
|
28
|
+
"0xdac17f958d2ee523a2206206994597c13d831ec7": {
|
29
|
+
"tToken": "0x3ed3b47dd13ec9a98b44e6204a523e766b225811",
|
30
|
+
"dToken": "0x531842cebbdd378f8ee36d171d6cc9c4fcf475ec",
|
31
|
+
"sdToken": "0xe91d55ab2240594855abd11b3faae801fd4c4687",
|
32
|
+
"liquidationThreshold": 0.0
|
33
|
+
},
|
34
|
+
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": {
|
35
|
+
"tToken": "0x9ff58f4ffb29fa2266ab25e75e2a8b3503311656",
|
36
|
+
"dToken": "0x9c39809dec7f95f5e0713634a4d0701329b3b4d2",
|
37
|
+
"sdToken": "0x51b039b9afe64b78758f8ef091211b5387ea717c",
|
38
|
+
"liquidationThreshold": 0.82
|
39
|
+
},
|
40
|
+
"0xae7ab96520de3a18e5e111b5eaab095312d7fe84": {
|
41
|
+
"tToken": "0x1982b2f5814301d4e9a8b0201555376e62f82428",
|
42
|
+
"dToken": "0xa9deac9f00dc4310c35603fcd9d34d1a750f81db",
|
43
|
+
"sdToken": "0x66457616dd8489df5d0afd8678f4a260088aaf55",
|
44
|
+
"liquidationThreshold": 0.83
|
45
|
+
},
|
46
|
+
"0xd533a949740bb3306d119cc777fa900ba034cd52": {
|
47
|
+
"tToken": "0x8dae6cb04688c62d939ed9b68d32bc62e49970b1",
|
48
|
+
"dToken": "0x00ad8ebf64f141f1c81e9f8f792d3d1631c6c684",
|
49
|
+
"sdToken": "0x9288059a74f589c919c7cf1db433251cdfeb874b",
|
50
|
+
"liquidationThreshold": 0.58
|
51
|
+
},
|
52
|
+
}
|
53
|
+
}
|