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.
Files changed (61) hide show
  1. defi_services/__init__.py +1 -1
  2. defi_services/abis/lending/morpho/__init__.py +0 -0
  3. defi_services/abis/lending/morpho/morpho_aave_v2_comptroller_abi.py +2301 -0
  4. defi_services/abis/lending/morpho/morpho_aave_v2_lens_abi.py +1208 -0
  5. defi_services/abis/lending/morpho/morpho_aave_v3_comptroller_abi.py +2994 -0
  6. defi_services/abis/lending/morpho/morpho_compound_comptroller_abi.py +2301 -0
  7. defi_services/abis/lending/morpho/morpho_compound_lens_abi.py +1402 -0
  8. defi_services/abis/lending/morpho/morpho_compound_reward_manager_abi.py +307 -0
  9. defi_services/abis/lending/radiant_v2/__init__.py +0 -0
  10. defi_services/abis/lending/radiant_v2/radiant_v2_incentive_abi.py +1016 -0
  11. defi_services/abis/lending/wepiggy/__init__.py +0 -0
  12. defi_services/abis/lending/wepiggy/wepiggy_distribution_abi.py +1047 -0
  13. defi_services/constants/chain_constant.py +1 -0
  14. defi_services/constants/entities/lending_constant.py +26 -0
  15. defi_services/constants/entities/lending_services.py +85 -0
  16. defi_services/constants/query_constant.py +1 -0
  17. defi_services/constants/token_constant.py +2 -0
  18. defi_services/jobs/processors/__init__.py +0 -0
  19. defi_services/jobs/processors/solana_state_processor.py +101 -0
  20. defi_services/jobs/{state_processor.py → processors/state_processor.py} +9 -4
  21. defi_services/jobs/processors/substrate_state_processor.py +97 -0
  22. defi_services/jobs/queriers/__init__.py +0 -0
  23. defi_services/jobs/queriers/solana_state_querier.py +83 -0
  24. defi_services/jobs/{state_querier.py → queriers/state_querier.py} +3 -2
  25. defi_services/jobs/queriers/substrate_state_querier.py +84 -0
  26. defi_services/services/lending/aave_v2_services.py +8 -7
  27. defi_services/services/lending/aave_v3_services.py +12 -9
  28. defi_services/services/lending/compound_service.py +29 -10
  29. defi_services/services/lending/cream_services.py +5 -4
  30. defi_services/services/lending/flux_services.py +34 -27
  31. defi_services/services/lending/geist_services.py +4 -3
  32. defi_services/services/lending/granary_v1_services.py +6 -7
  33. defi_services/services/lending/iron_bank_service.py +20 -13
  34. defi_services/services/lending/lending_info/aave_v2_services.py +2 -2
  35. defi_services/services/lending/lending_info/ethereum/morpho_aave_v2_eth.py +53 -0
  36. defi_services/services/lending/lending_info/ethereum/morpho_aave_v3_eth.py +51 -0
  37. defi_services/services/lending/lending_info/ethereum/morpho_compound_eth.py +44 -0
  38. defi_services/services/lending/lending_info/ethereum/wepiggy_eth.py +41 -0
  39. defi_services/services/lending/liqee_service.py +5 -26
  40. defi_services/services/lending/morpho_aave_v2_services.py +89 -0
  41. defi_services/services/lending/morpho_aave_v3_services.py +159 -0
  42. defi_services/services/lending/morpho_compound_services.py +233 -0
  43. defi_services/services/lending/onyx_service.py +32 -13
  44. defi_services/services/lending/radiant_v2_services.py +30 -3
  45. defi_services/services/lending/strike_service.py +29 -10
  46. defi_services/services/lending/trava_services.py +8 -7
  47. defi_services/services/lending/uwu_services.py +8 -7
  48. defi_services/services/lending/valas_services.py +6 -5
  49. defi_services/services/lending/venus_services.py +28 -8
  50. defi_services/services/lending/wepiggy_services.py +519 -0
  51. defi_services/services/nft_services.py +1 -1
  52. defi_services/services/solana_token_services.py +46 -0
  53. defi_services/services/substrate_token_services.py +70 -0
  54. defi_services/services/token_services.py +1 -3
  55. defi_services/utils/init_services.py +3 -3
  56. {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/METADATA +3 -3
  57. {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/RECORD +60 -32
  58. defi_services/constants/entities/lending.py +0 -97
  59. {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/LICENSE +0 -0
  60. {defi_state_querier-0.0.6.dist-info → defi_state_querier-0.0.9.dist-info}/WHEEL +0 -0
  61. {defi_state_querier-0.0.6.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
+ )
@@ -3,17 +3,16 @@ import time
3
3
 
4
4
  from web3 import Web3
5
5
 
6
+ from defi_services.abis.lending.onyx.onyx_comptroller_abi import ONYX_COMPTROLLER_ABI
6
7
  from defi_services.abis.lending.onyx.onyx_lens_abi import ONYX_LENS_ABI
7
8
  from defi_services.abis.lending.onyx.onyx_token_abi import ONYX_TOKEN_ABI
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.db_constant import DBConst
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.onyx_eth import ONYX_ETH
16
- from defi_services.abis.lending.onyx.onyx_comptroller_abi import ONYX_COMPTROLLER_ABI
17
16
  from defi_services.services.protocol_services import ProtocolServices
18
17
 
19
18
  logger = logging.getLogger("Onyx Lending Pool State Service")
@@ -27,7 +26,7 @@ class OnyxInfo:
27
26
 
28
27
  class OnyxStateService(ProtocolServices):
29
28
  def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
30
- self.name = f"{chain_id}_onyx-protocol"
29
+ self.name = f"{chain_id}_{Lending.onyx}"
31
30
  self.chain_id = chain_id
32
31
  self.pool_info = OnyxInfo.mapping.get(chain_id)
33
32
  self.state_service = state_service
@@ -38,7 +37,7 @@ class OnyxStateService(ProtocolServices):
38
37
  # BASIC FUNCTIONS
39
38
  def get_service_info(self):
40
39
  info = {
41
- "onyx-protocol": {
40
+ Lending.onyx: {
42
41
  "chain_id": self.chain_id,
43
42
  "type": "lending",
44
43
  "protocol_info": self.pool_info
@@ -106,7 +105,7 @@ class OnyxStateService(ProtocolServices):
106
105
  ))
107
106
 
108
107
  if Query.protocol_reward in query_types and wallet:
109
- result.update(self.calculate_rewards_balance(
108
+ result.update(self.calculate_claimable_rewards_balance(
110
109
  wallet, decoded_data, block_number
111
110
  ))
112
111
 
@@ -132,12 +131,31 @@ class OnyxStateService(ProtocolServices):
132
131
  ))
133
132
 
134
133
  if Query.protocol_reward in query_types and wallet:
135
- rpc_calls.update(self.get_rewards_balance_function_info(wallet, block_number))
134
+ rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
136
135
 
137
136
  logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
138
137
  return rpc_calls
139
138
 
140
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
+
141
159
  def get_rewards_balance_function_info(
142
160
  self,
143
161
  wallet_address: str,
@@ -148,11 +166,11 @@ class OnyxStateService(ProtocolServices):
148
166
  Web3.toChecksumAddress(self.pool_info.get("comptrollerAddress")),
149
167
  Web3.toChecksumAddress(wallet_address)]
150
168
  rpc_call = self.get_lens_function_info("getXcnBalanceMetadataExt", fn_paras, block_number)
151
- get_reward_id = f"getXcnBalanceMetadataExt_{wallet_address}_{block_number}".lower()
169
+ get_reward_id = f"getXcnBalanceMetadataExt_{self.name}_{wallet_address}_{block_number}".lower()
152
170
  return {get_reward_id: rpc_call}
153
171
 
154
172
  def calculate_rewards_balance(self, wallet_address: str, decoded_data: dict, block_number: int = "latest"):
155
- get_reward_id = f"getXcnBalanceMetadataExt_{wallet_address}_{block_number}".lower()
173
+ get_reward_id = f"getXcnBalanceMetadataExt_{self.name}_{wallet_address}_{block_number}".lower()
156
174
  rewards = decoded_data.get(get_reward_id)[-1] / 10 ** 18
157
175
  reward_token = self.pool_info.get("rewardToken")
158
176
  result = {
@@ -184,8 +202,9 @@ class OnyxStateService(ProtocolServices):
184
202
  rpc_calls[underlying_decimals_key] = self.state_service.get_function_info(
185
203
  underlying, ERC20_ABI, "decimals", [], block_number
186
204
  )
187
- key = f"oTokenBalancesAll_{wallet_address}_{block_number}".lower()
188
- rpc_calls[key] = self.get_lens_function_info("oTokenBalancesAll", [ctokens, Web3.toChecksumAddress(wallet_address)])
205
+ key = f"oTokenBalancesAll_{self.name}_{wallet_address}_{block_number}".lower()
206
+ rpc_calls[key] = self.get_lens_function_info("oTokenBalancesAll",
207
+ [ctokens, Web3.toChecksumAddress(wallet_address)])
189
208
  return rpc_calls
190
209
 
191
210
  def calculate_wallet_deposit_borrow_balance(
@@ -194,7 +213,7 @@ class OnyxStateService(ProtocolServices):
194
213
  if token_prices is None:
195
214
  token_prices = {}
196
215
  result = {}
197
- key = f"oTokenBalancesAll_{wallet_address}_{block_number}".lower()
216
+ key = f"oTokenBalancesAll_{self.name}_{wallet_address}_{block_number}".lower()
198
217
  ctoken_balance = {}
199
218
  for item in decoded_data.get(key):
200
219
  ctoken_balance[item[0]] = {
@@ -1,7 +1,9 @@
1
1
  import logging
2
2
 
3
+ from defi_services.abis.lending.radiant_v2.radiant_v2_incentive_abi import RADIANT_V2_INCENTIVE_ABI
3
4
  from defi_services.constants.chain_constant import Chain
4
- from defi_services.jobs.state_querier import StateQuerier
5
+ from defi_services.constants.entities.lending_constant import Lending
6
+ from defi_services.jobs.queriers.state_querier import StateQuerier
5
7
  from defi_services.services.lending.lending_info.arbitrum.radiant_arbitrum import RADIANT_ARB
6
8
  from defi_services.services.lending.lending_info.bsc.radiant_bsc import RADIANT_BSC
7
9
  from defi_services.services.lending.valas_services import ValasStateService
@@ -19,15 +21,40 @@ class RadiantInfo:
19
21
  class RadiantStateService(ValasStateService):
20
22
  def __init__(self, state_service: StateQuerier, chain_id: str = "0xa4b1"):
21
23
  super().__init__(state_service, chain_id)
22
- self.name = f"{chain_id}_radiant-v2"
24
+ self.name = f"{chain_id}_{Lending.radiant_v2}"
23
25
  self.pool_info = RadiantInfo.mapping.get(chain_id)
26
+ self.incentive_abi = RADIANT_V2_INCENTIVE_ABI
24
27
 
25
28
  def get_service_info(self):
26
29
  info = {
27
- "radiant-v2": {
30
+ Lending.radiant_v2: {
28
31
  "chain_id": self.chain_id,
29
32
  "type": "lending",
30
33
  "protocol_info": self.pool_info
31
34
  }
32
35
  }
33
36
  return info
37
+
38
+ # REWARDS BALANCE
39
+ def get_all_rewards_balance_function_info(
40
+ self,
41
+ wallet_address,
42
+ block_number: int = "latest"
43
+ ):
44
+ rpc_calls = {}
45
+ key = f"allPendingRewards_{self.name}_{wallet_address}_{block_number}".lower()
46
+ rpc_calls[key] = self.get_function_incentive_info(
47
+ "allPendingRewards", [wallet_address], block_number)
48
+
49
+ return rpc_calls
50
+
51
+ def calculate_all_rewards_balance(
52
+ self, decoded_data: dict, wallet_address: str, block_number: int = "latest"):
53
+ reward_token = self.pool_info['rewardToken']
54
+ key = f"allPendingRewards_{self.name}_{wallet_address}_{block_number}".lower()
55
+ rewards = decoded_data.get(key) / 10 ** 18
56
+ result = {
57
+ reward_token: {"amount": rewards}
58
+ }
59
+
60
+ return result
@@ -8,10 +8,10 @@ from defi_services.abis.lending.strike.strike_lens_abi import STRIKE_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.db_constant import DBConst
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.strike_eth import STRIKE_ETH
16
16
  from defi_services.services.protocol_services import ProtocolServices
17
17
 
@@ -26,7 +26,7 @@ class StrikeInfo:
26
26
 
27
27
  class StrikeStateService(ProtocolServices):
28
28
  def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
29
- self.name = f"{chain_id}_strike"
29
+ self.name = f"{chain_id}_{Lending.strike}"
30
30
  self.chain_id = chain_id
31
31
  self.pool_info = StrikeInfo.mapping.get(chain_id)
32
32
  self.state_service = state_service
@@ -36,7 +36,7 @@ class StrikeStateService(ProtocolServices):
36
36
  # BASIC FUNCTIONS
37
37
  def get_service_info(self):
38
38
  info = {
39
- "strike": {
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.calculate_rewards_balance(
108
+ result.update(self.calculate_claimable_rewards_balance(
109
109
  wallet, decoded_data, block_number
110
110
  ))
111
111
 
@@ -130,16 +130,35 @@ class StrikeStateService(ProtocolServices):
130
130
  wallet, reserves_info, block_number, is_oracle_price
131
131
  ))
132
132
 
133
- if Query.protocol_apy in query_types:
134
- rpc_calls.update(self.get_apy_lending_pool_function_info(reserves_info, block_number, is_oracle_price))
133
+ # if Query.protocol_apy in query_types:
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.get_rewards_balance_function_info(wallet, block_number))
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,
@@ -150,11 +169,11 @@ class StrikeStateService(ProtocolServices):
150
169
  Web3.toChecksumAddress(self.pool_info.get("comptrollerAddress")),
151
170
  Web3.toChecksumAddress(wallet_address)]
152
171
  rpc_call = self.get_lens_function_info("getStrikeBalanceMetadataExt", fn_paras, block_number)
153
- get_reward_id = f"getStrikeBalanceMetadataExt_{wallet_address}_{block_number}".lower()
172
+ get_reward_id = f"getStrikeBalanceMetadataExt_{self.name}_{wallet_address}_{block_number}".lower()
154
173
  return {get_reward_id: rpc_call}
155
174
 
156
175
  def calculate_rewards_balance(self, wallet_address: str, decoded_data: dict, block_number: int = "latest"):
157
- get_reward_id = f"getStrikeBalanceMetadataExt_{wallet_address}_{block_number}".lower()
176
+ get_reward_id = f"getStrikeBalanceMetadataExt_{self.name}_{wallet_address}_{block_number}".lower()
158
177
  rewards = decoded_data.get(get_reward_id)[-1] / 10 ** 18
159
178
  reward_token = self.pool_info.get("rewardToken")
160
179
  result = {
@@ -9,10 +9,11 @@ from defi_services.abis.lending.trava.trava_lending_pool_abi import TRAVA_LENDIN
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.time_constant import TimeConstants
14
15
  from defi_services.constants.token_constant import Token
15
- from defi_services.jobs.state_querier import StateQuerier
16
+ from defi_services.jobs.queriers.state_querier import StateQuerier
16
17
  from defi_services.services.lending.lending_info.bsc.trava_bsc import TRAVA_BSC
17
18
  from defi_services.services.lending.lending_info.ethereum.trava_eth import TRAVA_ETH
18
19
  from defi_services.services.lending.lending_info.fantom.trava_ftm import TRAVA_FTM
@@ -31,7 +32,7 @@ class TravaInfo:
31
32
 
32
33
  class TravaStateService(ProtocolServices):
33
34
  def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
34
- self.name = f"{chain_id}_trava-finance"
35
+ self.name = f"{chain_id}_{Lending.trava}"
35
36
  self.chain_id = chain_id
36
37
  self.pool_info = TravaInfo.mapping.get(chain_id)
37
38
  self.lending_abi = TRAVA_LENDING_POOL_ABI
@@ -42,7 +43,7 @@ class TravaStateService(ProtocolServices):
42
43
  # BASIC FUNCTION
43
44
  def get_service_info(self):
44
45
  info = {
45
- "trava-finance": {
46
+ Lending.trava: {
46
47
  "chain_id": self.chain_id,
47
48
  "type": "lending",
48
49
  "protocol_info": self.pool_info
@@ -150,7 +151,7 @@ class TravaStateService(ProtocolServices):
150
151
  "getAssetsPrices", list(reserves_info.keys()), block_number)
151
152
 
152
153
  for token_address, value in reserves_info.items():
153
- reserve_key = f"getReserveData_{token_address}_{block_number}".lower()
154
+ reserve_key = f"getReserveData_{self.name}_{token_address}_{block_number}".lower()
154
155
  atoken_assets_key = f"assets_{value['tToken']}_{block_number}".lower()
155
156
  debt_token_assets_key = f"assets_{value['dToken']}_{block_number}".lower()
156
157
  atoken_total_supply_key = f'totalSupply_{value["tToken"]}_{block_number}'.lower()
@@ -236,7 +237,7 @@ class TravaStateService(ProtocolServices):
236
237
  ):
237
238
  reserves_data = {}
238
239
  for token in reserves_info:
239
- get_reserve_data_call_id = f'getReserveData_{token}_{block_number}'.lower()
240
+ get_reserve_data_call_id = f'getReserveData_{self.name}_{token}_{block_number}'.lower()
240
241
  reserves_data[token.lower()] = decoded_data.get(get_reserve_data_call_id)
241
242
 
242
243
  interest_rate, atokens, debt_tokens, decimals, asset_data_tokens = {}, {}, {}, {}, {}
@@ -378,7 +379,7 @@ class TravaStateService(ProtocolServices):
378
379
  for token, value in reserves_info.items():
379
380
  atoken, debt_token = Web3.toChecksumAddress(value['tToken']), Web3.toChecksumAddress(value['dToken'])
380
381
  tokens += [atoken, debt_token]
381
- key = f"getRewardsBalance_{wallet_address}_{block_number}".lower()
382
+ key = f"getRewardsBalance_{self.name}_{wallet_address}_{block_number}".lower()
382
383
  rpc_calls[key] = self.get_function_incentive_info(
383
384
  "getRewardsBalance", [tokens, wallet_address], block_number)
384
385
 
@@ -387,7 +388,7 @@ class TravaStateService(ProtocolServices):
387
388
  def calculate_all_rewards_balance(
388
389
  self, decoded_data: dict, wallet_address: str, block_number: int = "latest"):
389
390
  reward_token = self.pool_info['rewardToken']
390
- key = f"getRewardsBalance_{wallet_address}_{block_number}".lower()
391
+ key = f"getRewardsBalance_{self.name}_{wallet_address}_{block_number}".lower()
391
392
  rewards = decoded_data.get(key) / 10 ** 18
392
393
  result = {
393
394
  reward_token: {"amount": rewards}
@@ -8,10 +8,11 @@ from defi_services.abis.lending.aave_v2_and_forlks.oracle_abi import ORACLE_ABI
8
8
  from defi_services.abis.token.erc20_abi import ERC20_ABI
9
9
  from defi_services.constants.chain_constant import Chain
10
10
  from defi_services.constants.db_constant import DBConst
11
+ from defi_services.constants.entities.lending_constant import Lending
11
12
  from defi_services.constants.query_constant import Query
12
13
  from defi_services.constants.time_constant import TimeConstants
13
14
  from defi_services.constants.token_constant import 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.uwu_eth import UWU_ETH
16
17
  from defi_services.services.protocol_services import ProtocolServices
17
18
 
@@ -26,7 +27,7 @@ class UwuInfo:
26
27
 
27
28
  class UwuStateService(ProtocolServices):
28
29
  def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
29
- self.name = f"{chain_id}_uwu-lend"
30
+ self.name = f"{chain_id}_{Lending.uwu}"
30
31
  self.chain_id = chain_id
31
32
  self.uwu_info = UwuInfo.mapping.get(chain_id)
32
33
  self.lending_abi = LENDING_POOL_ABI
@@ -37,7 +38,7 @@ class UwuStateService(ProtocolServices):
37
38
  # BASIC FUNCTION
38
39
  def get_service_info(self):
39
40
  info = {
40
- "uwu-lend": {
41
+ Lending.uwu: {
41
42
  "chain_id": self.chain_id,
42
43
  "type": "lending",
43
44
  "protocol_info": self.uwu_info
@@ -150,7 +151,7 @@ class UwuStateService(ProtocolServices):
150
151
  "getAssetsPrices", list(reserves_info.keys()), block_number)
151
152
 
152
153
  for token_address, value in reserves_info.items():
153
- reserve_key = f"getReserveData_{token_address}_{block_number}".lower()
154
+ reserve_key = f"getReserveData_{self.name}_{token_address}_{block_number}".lower()
154
155
  atoken_assets_key = f"assets_{value['tToken']}_{block_number}".lower()
155
156
  debt_token_assets_key = f"assets_{value['dToken']}_{block_number}".lower()
156
157
  # sdebt_token_assets_key = f"assets_{value['sdToken']}_{block_number}".lower()
@@ -250,7 +251,7 @@ class UwuStateService(ProtocolServices):
250
251
  ):
251
252
  reserves_data = {}
252
253
  for token in reserves_info:
253
- get_reserve_data_call_id = f'getReserveData_{token}_{block_number}'.lower()
254
+ get_reserve_data_call_id = f'getReserveData_{self.name}_{token}_{block_number}'.lower()
254
255
  reserves_data[token.lower()] = decoded_data.get(get_reserve_data_call_id)
255
256
 
256
257
  interest_rate, atokens, debt_tokens, sdebt_tokens, decimals, asset_data_tokens = {}, {}, {}, {}, {}, {}
@@ -412,7 +413,7 @@ class UwuStateService(ProtocolServices):
412
413
  for token, value in reserves_info.items():
413
414
  atoken, debt_token = Web3.toChecksumAddress(value['tToken']), Web3.toChecksumAddress(value['dToken'])
414
415
  tokens += [atoken, debt_token]
415
- key = f"claimableReward_{wallet_address}_{block_number}".lower()
416
+ key = f"claimableReward_{self.name}_{wallet_address}_{block_number}".lower()
416
417
  rpc_calls[key] = self.get_function_incentive_info(
417
418
  "claimableReward", [wallet_address, tokens], block_number)
418
419
 
@@ -421,7 +422,7 @@ class UwuStateService(ProtocolServices):
421
422
  def calculate_all_rewards_balance(
422
423
  self, decoded_data: dict, wallet_address: str, block_number: int = "latest"):
423
424
  reward_token = self.uwu_info['rewardToken']
424
- key = f"claimableReward_{wallet_address}_{block_number}".lower()
425
+ key = f"claimableReward_{self.name}_{wallet_address}_{block_number}".lower()
425
426
  rewards = sum(decoded_data.get(key))/ 10 ** 18
426
427
  result = {
427
428
  reward_token: {"amount": rewards}