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
@@ -28,7 +28,7 @@ class FluxStateService(ProtocolServices):
|
|
28
28
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
29
29
|
self.name = f"{chain_id}_{Lending.flux}"
|
30
30
|
self.chain_id = chain_id
|
31
|
-
self.
|
31
|
+
self.pool_info = FluxInfo.mapping.get(chain_id)
|
32
32
|
self.state_service = state_service
|
33
33
|
self.lens_abi = CREAM_LENS_ABI
|
34
34
|
self.comptroller_abi = CREAM_COMPTROLLER_ABI
|
@@ -39,7 +39,7 @@ class FluxStateService(ProtocolServices):
|
|
39
39
|
Lending.flux: {
|
40
40
|
"chain_id": self.chain_id,
|
41
41
|
"type": "lending",
|
42
|
-
"protocol_info": self.
|
42
|
+
"protocol_info": self.pool_info
|
43
43
|
}
|
44
44
|
}
|
45
45
|
return info
|
@@ -49,7 +49,7 @@ class FluxStateService(ProtocolServices):
|
|
49
49
|
block_number: int = "latest"):
|
50
50
|
_w3 = self.state_service.get_w3()
|
51
51
|
comptroller_contract = _w3.eth.contract(
|
52
|
-
address=_w3.toChecksumAddress(self.
|
52
|
+
address=_w3.toChecksumAddress(self.pool_info.get("comptrollerAddress")), abi=self.comptroller_abi)
|
53
53
|
ctokens = []
|
54
54
|
for token in comptroller_contract.functions.getAllMarkets().call(block_identifier=block_number):
|
55
55
|
if token in [ContractAddresses.LUNA.lower(), ContractAddresses.UST.lower(), ContractAddresses.LUNA,
|
@@ -58,7 +58,7 @@ class FluxStateService(ProtocolServices):
|
|
58
58
|
ctokens.append(token)
|
59
59
|
|
60
60
|
lens_contract = _w3.eth.contract(
|
61
|
-
address=Web3.toChecksumAddress(self.
|
61
|
+
address=Web3.toChecksumAddress(self.pool_info.get("lensAddress")), abi=self.lens_abi
|
62
62
|
)
|
63
63
|
tokens = [Web3.toChecksumAddress(i) for i in ctokens]
|
64
64
|
metadata = lens_contract.functions.cTokenMetadataAll(tokens).call(block_identifier=block_number)
|
@@ -75,8 +75,8 @@ class FluxStateService(ProtocolServices):
|
|
75
75
|
|
76
76
|
def get_token_list(self):
|
77
77
|
begin = time.time()
|
78
|
-
tokens = [self.
|
79
|
-
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"):
|
80
80
|
if token == Token.native_token:
|
81
81
|
tokens.append(Token.wrapped_token.get(self.chain_id))
|
82
82
|
continue
|
@@ -93,7 +93,7 @@ class FluxStateService(ProtocolServices):
|
|
93
93
|
**kwargs
|
94
94
|
):
|
95
95
|
begin = time.time()
|
96
|
-
reserves_info = kwargs.get("reserves_info", self.
|
96
|
+
reserves_info = kwargs.get("reserves_info", self.pool_info.get("reservesList"))
|
97
97
|
token_prices = kwargs.get("token_prices", {})
|
98
98
|
wrapped_native_token_price = token_prices.get(Token.wrapped_token.get(self.chain_id), 1)
|
99
99
|
pool_decimals = kwargs.get("pool_decimals", 18)
|
@@ -104,7 +104,7 @@ class FluxStateService(ProtocolServices):
|
|
104
104
|
))
|
105
105
|
|
106
106
|
if Query.protocol_reward in query_types and wallet:
|
107
|
-
result.update(self.
|
107
|
+
result.update(self.calculate_claimable_rewards_balance(
|
108
108
|
wallet, decoded_data, block_number
|
109
109
|
))
|
110
110
|
|
@@ -122,7 +122,7 @@ class FluxStateService(ProtocolServices):
|
|
122
122
|
reserves_info = kwargs.get("reserves_info", {})
|
123
123
|
is_oracle_price = kwargs.get("is_oracle_price", False) # get price by oracle
|
124
124
|
if not reserves_info:
|
125
|
-
reserves_info = self.
|
125
|
+
reserves_info = self.pool_info['reservesList']
|
126
126
|
rpc_calls = {}
|
127
127
|
if Query.deposit_borrow in query_types and wallet:
|
128
128
|
rpc_calls.update(self.get_wallet_deposit_borrow_balance_function_info(
|
@@ -130,21 +130,30 @@ class FluxStateService(ProtocolServices):
|
|
130
130
|
))
|
131
131
|
|
132
132
|
if Query.protocol_reward in query_types and wallet:
|
133
|
-
rpc_calls.update(self.
|
133
|
+
rpc_calls.update(self.get_claimable_rewards_balance_function_info(wallet, block_number))
|
134
134
|
|
135
135
|
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
136
136
|
return rpc_calls
|
137
137
|
|
138
138
|
# REWARDS BALANCE
|
139
|
-
def
|
139
|
+
def get_claimable_rewards_balance_function_info(
|
140
140
|
self,
|
141
141
|
wallet_address: str,
|
142
142
|
block_number: int = "latest",
|
143
143
|
):
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
148
157
|
|
149
158
|
# WALLET DEPOSIT BORROW BALANCE
|
150
159
|
def get_wallet_deposit_borrow_balance_function_info(
|
@@ -291,15 +300,14 @@ class FluxStateService(ProtocolServices):
|
|
291
300
|
result[token]['deposit_amount_in_usd'] += deposit_amount_in_usd
|
292
301
|
return result
|
293
302
|
|
294
|
-
|
295
303
|
def get_lens_function_info(self, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
296
304
|
return self.state_service.get_function_info(
|
297
|
-
self.
|
305
|
+
self.pool_info['lensAddress'], self.lens_abi, fn_name, fn_paras, block_number
|
298
306
|
)
|
299
307
|
|
300
308
|
def get_comptroller_function_info(self, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
301
309
|
return self.state_service.get_function_info(
|
302
|
-
self.
|
310
|
+
self.pool_info['comptrollerAddress'], self.comptroller_abi, fn_name, fn_paras, block_number
|
303
311
|
)
|
304
312
|
|
305
313
|
def get_ctoken_function_info(self, ctoken: str, fn_name: str, fn_paras: list, block_number: int = "latest"):
|
@@ -313,7 +321,7 @@ class FluxStateService(ProtocolServices):
|
|
313
321
|
block_number: int = "latest"
|
314
322
|
):
|
315
323
|
tokens = [Web3.toChecksumAddress(value['cToken']) for key, value in reserves_info.items()]
|
316
|
-
key = f"cTokenMetadataAll_{self.
|
324
|
+
key = f"cTokenMetadataAll_{self.pool_info.get('lensAddress')}_{block_number}".lower()
|
317
325
|
return {
|
318
326
|
key: self.get_lens_function_info("cTokenMetadataAll", tokens, block_number)
|
319
327
|
}
|
@@ -321,14 +329,14 @@ class FluxStateService(ProtocolServices):
|
|
321
329
|
def ctoken_underlying_price_all(
|
322
330
|
self, reserves_info, block_number: int = 'latest'):
|
323
331
|
tokens = [Web3.toChecksumAddress(value['cToken']) for key, value in reserves_info.items()]
|
324
|
-
key = f"cTokenUnderlyingPriceAll_{self.
|
332
|
+
key = f"cTokenUnderlyingPriceAll_{self.pool_info.get('lensAddress')}_{block_number}".lower()
|
325
333
|
return {
|
326
334
|
key: self.get_lens_function_info("cTokenUnderlyingPriceAll", tokens, block_number)
|
327
335
|
}
|
328
336
|
|
329
337
|
def get_all_markets(
|
330
338
|
self, block_number: int = 'latest'):
|
331
|
-
key = f"getAllMarkets_{self.
|
339
|
+
key = f"getAllMarkets_{self.pool_info.get('comptrollerAddress')}_{block_number}".lower()
|
332
340
|
return {
|
333
341
|
key: self.get_comptroller_function_info("getAllMarkets", [], block_number)
|
334
|
-
}
|
342
|
+
}
|
@@ -8,6 +8,7 @@ from defi_services.abis.lending.iron_bank.iron_lens_abi import IRON_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.entities.lending_constant import Lending
|
11
12
|
from defi_services.constants.query_constant import Query
|
12
13
|
from defi_services.constants.token_constant import ContractAddresses, Token
|
13
14
|
from defi_services.jobs.queriers.state_querier import StateQuerier
|
@@ -25,7 +26,7 @@ class IronBankInfo:
|
|
25
26
|
|
26
27
|
class IronBankStateService(ProtocolServices):
|
27
28
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
28
|
-
self.name = f"{chain_id}
|
29
|
+
self.name = f"{chain_id}_{Lending.iron_bank}"
|
29
30
|
self.chain_id = chain_id
|
30
31
|
self.iron_bank_info = IronBankInfo.mapping.get(chain_id)
|
31
32
|
self.state_service = state_service
|
@@ -35,7 +36,7 @@ class IronBankStateService(ProtocolServices):
|
|
35
36
|
# BASIC FUNCTIONS
|
36
37
|
def get_service_info(self):
|
37
38
|
info = {
|
38
|
-
|
39
|
+
Lending.iron_bank: {
|
39
40
|
"chain_id": self.chain_id,
|
40
41
|
"type": "lending",
|
41
42
|
"protocol_info": self.iron_bank_info
|
@@ -105,7 +106,7 @@ class IronBankStateService(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,22 +139,30 @@ class IronBankStateService(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
|
145
146
|
|
146
147
|
# REWARDS BALANCE
|
147
|
-
def
|
148
|
+
def get_claimable_rewards_balance_function_info(
|
148
149
|
self,
|
149
150
|
wallet_address: str,
|
150
|
-
reserves_info: dict,
|
151
151
|
block_number: int = "latest",
|
152
152
|
):
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
157
166
|
|
158
167
|
# WALLET DEPOSIT BORROW BALANCE
|
159
168
|
def get_wallet_deposit_borrow_balance_function_info(
|
@@ -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
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
MORPHO_AAVE_V3_ETH = {
|
2
|
+
"name": "Compound Lending Pool",
|
3
|
+
"comptrollerAddress": "0x33333aea097c193e66081e930c33020272b33333",
|
4
|
+
"poolToken": "0x9994e35db50125e0df82e4c2dde62496ce330999",
|
5
|
+
"type": "LENDING_POOL",
|
6
|
+
"forked": "morpho-aave-v3",
|
7
|
+
"reservesList": {
|
8
|
+
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": {
|
9
|
+
"tToken": "0x4d5f47fa6a74757f35c14fd3a6ef8e3c9bc514e8",
|
10
|
+
"sdToken": "0x102633152313c81cd80419b6ecf66d14ad68949a",
|
11
|
+
"dToken": "0xea51d7853eefb32b6ee06b1c12e6dcca88be0ffe",
|
12
|
+
"liquidationThreshold": 0.83
|
13
|
+
},
|
14
|
+
"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0": {
|
15
|
+
"tToken": "0x0b925ed163218f6662a35e0f0371ac234f9e9371",
|
16
|
+
"sdToken": "0x39739943199c0fbfe9e5f1b5b160cd73a64cb85d",
|
17
|
+
"dToken": "0xc96113eed8cab59cd8a66813bcb0ceb29f06d2e4",
|
18
|
+
"liquidationThreshold": 0.8
|
19
|
+
},
|
20
|
+
"0x6b175474e89094c44da98b954eedeac495271d0f": {
|
21
|
+
"tToken": "0x018008bfb33d285247a21d44e50697654f754e63",
|
22
|
+
"sdToken": "0x413adac9e2ef8683adf5ddaece8f19613d60d1bb",
|
23
|
+
"dToken": "0xcf8d0c70c850859266f5c338b38f9d663181c314",
|
24
|
+
"liquidationThreshold": 0.8
|
25
|
+
},
|
26
|
+
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": {
|
27
|
+
"tToken": "0x98c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5c",
|
28
|
+
"sdToken": "0xb0fe3d292f4bd50de902ba5bdf120ad66e9d7a39",
|
29
|
+
"dToken": "0x72e95b8931767c79ba4eee721354d6e99a61d004",
|
30
|
+
"liquidationThreshold": 0.8
|
31
|
+
},
|
32
|
+
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": {
|
33
|
+
"tToken": "0x5ee5bf7ae06d1be5997a1a72006fe6c607ec6de8",
|
34
|
+
"sdToken": "0xa1773f1ccf6db192ad8fe826d15fe1d328b03284",
|
35
|
+
"dToken": "0x40aabef1aa8f0eec637e0e7d92fbffb2f26a8b7b",
|
36
|
+
"liquidationThreshold": 0.78
|
37
|
+
},
|
38
|
+
"0xae78736cd615f374d3085123a210448e74fc6393": {
|
39
|
+
"tToken": "0xcc9ee9483f662091a1de4795249e24ac0ac2630f",
|
40
|
+
"sdToken": "0x1d1906f909cae494c7441604dafdddbd0485a925",
|
41
|
+
"dToken": "0xae8593dd575fe29a9745056aa91c4b746eee62c8",
|
42
|
+
"liquidationThreshold": 0.74
|
43
|
+
},
|
44
|
+
"0xbe9895146f7af43049ca1c1ae358b0541ea49704": {
|
45
|
+
"tToken": "0x977b6fc5de62598b08c85ac8cf2b745874e8b78c",
|
46
|
+
"sdToken": "0x82be6012cea6d147b968ebaea5ceecf6a5b4f493",
|
47
|
+
"dToken": "0x0c91bca95b5fe69164ce583a2ec9429a569798ed",
|
48
|
+
"liquidationThreshold": 0.74
|
49
|
+
},
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
MORPHO_COMPOUND_ETH = {
|
2
|
+
"name": "Compound Lending Pool",
|
3
|
+
"rewardToken": "0xc00e94cb662c3520282e6f5717214004a7f26888",
|
4
|
+
"comptrollerAddress": "0x8888882f8f843896699869179fb6e4f7e3b58888",
|
5
|
+
"lensAddress": "0x930f1b46e1d081ec1524efd95752be3ece51ef67",
|
6
|
+
"rewardManager": '0x78681e63b6f3ad81ecd64aecc404d765b529c80d',
|
7
|
+
"poolToken": "0x9994e35db50125e0df82e4c2dde62496ce330999",
|
8
|
+
"type": "LENDING_POOL",
|
9
|
+
"forked": "morpho",
|
10
|
+
"reservesList": {
|
11
|
+
"0x6b175474e89094c44da98b954eedeac495271d0f": {
|
12
|
+
"cToken": "0x5d3a536e4d6dbd6114cc1ead35777bab948e3643",
|
13
|
+
"liquidationThreshold": 0.835
|
14
|
+
},
|
15
|
+
"0xc00e94cb662c3520282e6f5717214004a7f26888": {
|
16
|
+
"cToken": "0x70e36f6bf80a52b3b46b3af8e106cc0ed743e8e4",
|
17
|
+
"liquidationThreshold": 0.6
|
18
|
+
},
|
19
|
+
"0x0000000000000000000000000000000000000000": {
|
20
|
+
"cToken": "0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5",
|
21
|
+
"liquidationThreshold": 0.825
|
22
|
+
},
|
23
|
+
"0x956f47f50a910163d8bf957cf5846d573e7f87ca": {
|
24
|
+
"cToken": "0x7713dd9ca933848f6819f38b8352d9a15ea73f67",
|
25
|
+
"liquidationThreshold": 0.0
|
26
|
+
},
|
27
|
+
"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984": {
|
28
|
+
"cToken": "0x35a18000230da775cac24873d00ff85bccded550",
|
29
|
+
"liquidationThreshold": 0.75
|
30
|
+
},
|
31
|
+
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": {
|
32
|
+
"cToken": "0x39aa39c021dfbae8fac545936693ac917d5e7563",
|
33
|
+
"liquidationThreshold": 0.855
|
34
|
+
},
|
35
|
+
"0xdac17f958d2ee523a2206206994597c13d831ec7": {
|
36
|
+
"cToken": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9",
|
37
|
+
"liquidationThreshold": 0.0
|
38
|
+
},
|
39
|
+
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": {
|
40
|
+
"cToken": "0xccf4429db6322d5c611ee964527d42e5d685dd6a",
|
41
|
+
"liquidationThreshold": 0.7
|
42
|
+
},
|
43
|
+
}
|
44
|
+
}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import logging
|
2
|
+
import time
|
3
|
+
|
4
|
+
from web3 import Web3
|
5
|
+
|
6
|
+
from defi_services.abis.lending.aave_v2_and_forlks.aave_v2_incentives_abi import AAVE_V2_INCENTIVES_ABI
|
7
|
+
from defi_services.abis.lending.aave_v2_and_forlks.lending_pool_abi import LENDING_POOL_ABI
|
8
|
+
from defi_services.abis.lending.aave_v2_and_forlks.oracle_abi import ORACLE_ABI
|
9
|
+
from defi_services.abis.lending.morpho.morpho_aave_v2_comptroller_abi import MORPHO_AAVE_V2_COMPTROLLER
|
10
|
+
from defi_services.abis.lending.morpho.morpho_aave_v2_lens_abi import MORPHO_AAVE_V2_LENS_ABI
|
11
|
+
from defi_services.constants.chain_constant import Chain
|
12
|
+
from defi_services.constants.entities.lending_constant import Lending
|
13
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
14
|
+
from defi_services.services.lending.lending_info.aave_v2_services import AaveInfo
|
15
|
+
from defi_services.services.lending.lending_info.ethereum.morpho_aave_v2_eth import MORPHO_AAVE_V2_ETH
|
16
|
+
from defi_services.services.lending.morpho_compound_services import MorphoCompoundServices
|
17
|
+
|
18
|
+
logger = logging.getLogger("Compound Lending Pool State Service")
|
19
|
+
|
20
|
+
|
21
|
+
class MorphoAaveV2Info:
|
22
|
+
mapping = {
|
23
|
+
Chain.ethereum: MORPHO_AAVE_V2_ETH
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
class MorphoAaveV2Services(MorphoCompoundServices):
|
28
|
+
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
29
|
+
super().__init__(state_service, chain_id)
|
30
|
+
self.name = f"{chain_id}_{Lending.morpho_aave_v2}"
|
31
|
+
self.chain_id = chain_id
|
32
|
+
self.compound_info = AaveInfo.mapping.get(chain_id)
|
33
|
+
self.pool_info = MorphoAaveV2Info.mapping.get(chain_id)
|
34
|
+
self.state_service = state_service
|
35
|
+
self.lending_abi = LENDING_POOL_ABI
|
36
|
+
self.incentive_abi = AAVE_V2_INCENTIVES_ABI
|
37
|
+
self.oracle_abi = ORACLE_ABI
|
38
|
+
self.lens_abi = MORPHO_AAVE_V2_LENS_ABI
|
39
|
+
self.comptroller_abi = MORPHO_AAVE_V2_COMPTROLLER
|
40
|
+
self.market_key = 'tToken'
|
41
|
+
|
42
|
+
# BASIC FUNCTIONS
|
43
|
+
def get_service_info(self):
|
44
|
+
info = {
|
45
|
+
Lending.morpho_aave_v2: {
|
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
|
+
begin = time.time()
|
57
|
+
_w3 = self.state_service.get_w3()
|
58
|
+
pool_address = Web3.toChecksumAddress(self.pool_info['address'])
|
59
|
+
contract = _w3.eth.contract(address=pool_address, abi=self.lending_abi)
|
60
|
+
comptroller_contract = _w3.eth.contract(
|
61
|
+
address=_w3.toChecksumAddress(self.pool_info.get("comptrollerAddress")), abi=self.comptroller_abi)
|
62
|
+
markets = comptroller_contract.functions.getAllMarkets().call(block_identifier=block_number)
|
63
|
+
reserves_list = contract.functions.getReservesList().call(block_identifier=block_number)
|
64
|
+
reserves_info = {}
|
65
|
+
for token in reserves_list:
|
66
|
+
value = contract.functions.getReserveData(token).call(block_identifier=block_number)
|
67
|
+
key = token.lower()
|
68
|
+
ttoken = value[7]
|
69
|
+
if ttoken in markets:
|
70
|
+
reserves_info[key] = {}
|
71
|
+
reserves_info[key]["tToken"] = ttoken.lower()
|
72
|
+
reserves_info[key]["dToken"] = value[9].lower()
|
73
|
+
reserves_info[key]["sdToken"] = value[8].lower()
|
74
|
+
risk_param = bin(value[0][0])[2:]
|
75
|
+
reserves_info[key]["liquidationThreshold"] = int(risk_param[-31:-16], 2) / 10 ** 4
|
76
|
+
logger.info(f"Get reserves information in {time.time() - begin}s")
|
77
|
+
return reserves_info
|
78
|
+
|
79
|
+
# REWARDS BALANCE
|
80
|
+
def get_claimable_rewards_balance_function_info(
|
81
|
+
self,
|
82
|
+
wallet_address: str,
|
83
|
+
block_number: int = "latest",
|
84
|
+
):
|
85
|
+
return {}
|
86
|
+
|
87
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
88
|
+
block_number: int = "latest"):
|
89
|
+
return {}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import logging
|
2
|
+
import time
|
3
|
+
|
4
|
+
from web3 import Web3
|
5
|
+
|
6
|
+
from defi_services.abis.lending.aave_v2_and_forlks.aave_v2_incentives_abi import AAVE_V2_INCENTIVES_ABI
|
7
|
+
from defi_services.abis.lending.aave_v2_and_forlks.lending_pool_abi import LENDING_POOL_ABI
|
8
|
+
from defi_services.abis.lending.aave_v2_and_forlks.oracle_abi import ORACLE_ABI
|
9
|
+
from defi_services.abis.lending.morpho.morpho_aave_v3_comptroller_abi import MORPHO_AAVE_V3_COMPTROLLER_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.token_constant import Token
|
14
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
15
|
+
from defi_services.services.lending.aave_v3_services import AaveV3Info
|
16
|
+
from defi_services.services.lending.lending_info.ethereum.morpho_aave_v3_eth import MORPHO_AAVE_V3_ETH
|
17
|
+
from defi_services.services.lending.morpho_compound_services import MorphoCompoundServices
|
18
|
+
|
19
|
+
logger = logging.getLogger("Compound Lending Pool State Service")
|
20
|
+
|
21
|
+
|
22
|
+
class MorphoAaveV3Info:
|
23
|
+
mapping = {
|
24
|
+
Chain.ethereum: MORPHO_AAVE_V3_ETH
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
class MorphoAaveV3Services(MorphoCompoundServices):
|
29
|
+
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
30
|
+
super().__init__(state_service, chain_id)
|
31
|
+
self.name = f"{chain_id}_{Lending.morpho_aave_v3}"
|
32
|
+
self.chain_id = chain_id
|
33
|
+
self.aave_info = AaveV3Info.mapping.get(chain_id)
|
34
|
+
self.pool_info = MorphoAaveV3Info.mapping.get(chain_id)
|
35
|
+
self.state_service = state_service
|
36
|
+
self.lending_abi = LENDING_POOL_ABI
|
37
|
+
self.incentive_abi = AAVE_V2_INCENTIVES_ABI
|
38
|
+
self.oracle_abi = ORACLE_ABI
|
39
|
+
self.comptroller_abi = MORPHO_AAVE_V3_COMPTROLLER_ABI
|
40
|
+
self.market_key = 'tToken'
|
41
|
+
|
42
|
+
# BASIC FUNCTIONS
|
43
|
+
def get_service_info(self):
|
44
|
+
info = {
|
45
|
+
Lending.morpho_aave_v3: {
|
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
|
+
begin = time.time()
|
57
|
+
_w3 = self.state_service.get_w3()
|
58
|
+
pool_address = Web3.toChecksumAddress(self.aave_info['address'])
|
59
|
+
contract = _w3.eth.contract(address=pool_address, abi=self.lending_abi)
|
60
|
+
comptroller_contract = _w3.eth.contract(
|
61
|
+
address=_w3.toChecksumAddress(self.pool_info.get("comptrollerAddress")), abi=self.comptroller_abi)
|
62
|
+
markets = comptroller_contract.functions.getAllMarkets().call(block_identifier=block_number)
|
63
|
+
markets = [i.lower() for i in markets]
|
64
|
+
reserves_list = contract.functions.getReservesList().call(block_identifier=block_number)
|
65
|
+
reserves_info = {}
|
66
|
+
for token in reserves_list:
|
67
|
+
value = contract.functions.getReserveData(token).call(block_identifier=block_number)
|
68
|
+
key = token.lower()
|
69
|
+
if token in markets:
|
70
|
+
reserves_info[key] = {}
|
71
|
+
reserves_info[key]["tToken"] = value[8].lower()
|
72
|
+
reserves_info[key]["dToken"] = value[9].lower()
|
73
|
+
reserves_info[key]["sdToken"] = value[10].lower()
|
74
|
+
risk_param = bin(value[0][0])[2:]
|
75
|
+
reserves_info[key]["liquidationThreshold"] = int(risk_param[-31:-16], 2) / 10 ** 4
|
76
|
+
logger.info(f"Get reserves information in {time.time() - begin}s")
|
77
|
+
return reserves_info
|
78
|
+
|
79
|
+
def get_token_list(self):
|
80
|
+
begin = time.time()
|
81
|
+
tokens = [self.aave_info.get("poolToken")]
|
82
|
+
for token in self.aave_info.get("reservesList"):
|
83
|
+
if token == Token.native_token:
|
84
|
+
tokens.append(Token.wrapped_token.get(self.chain_id))
|
85
|
+
continue
|
86
|
+
tokens.append(token)
|
87
|
+
logger.info(f"Get token list related in {time.time()-begin}s")
|
88
|
+
return tokens
|
89
|
+
|
90
|
+
# REWARDS BALANCE
|
91
|
+
def get_claimable_rewards_balance_function_info(
|
92
|
+
self,
|
93
|
+
wallet_address: str,
|
94
|
+
block_number: int = "latest",
|
95
|
+
):
|
96
|
+
return {}
|
97
|
+
|
98
|
+
def calculate_claimable_rewards_balance(self, wallet_address: str, decoded_data: dict,
|
99
|
+
block_number: int = "latest"):
|
100
|
+
return {}
|
101
|
+
|
102
|
+
# WALLET DEPOSIT BORROW BALANCE
|
103
|
+
def get_wallet_deposit_borrow_balance_function_info(
|
104
|
+
self,
|
105
|
+
wallet_address: str,
|
106
|
+
reserves_info: dict,
|
107
|
+
block_number: int = "latest"
|
108
|
+
):
|
109
|
+
|
110
|
+
rpc_calls = {}
|
111
|
+
for token, value in reserves_info.items():
|
112
|
+
underlying = token
|
113
|
+
ctoken = value.get(self.market_key)
|
114
|
+
if token == Token.native_token:
|
115
|
+
underlying = Token.wrapped_token.get(self.chain_id)
|
116
|
+
underlying_borrow_key = f"borrowBalance_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
117
|
+
underlying_balance_key = f"collateralBalance_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
118
|
+
underlying_decimals_key = f"decimals_{underlying}_{block_number}".lower()
|
119
|
+
rpc_calls[underlying_borrow_key] = self.get_comptroller_function_info(
|
120
|
+
"borrowBalance", [token, wallet_address], block_number)
|
121
|
+
rpc_calls[underlying_balance_key] = self.get_comptroller_function_info(
|
122
|
+
"collateralBalance", [token, wallet_address], block_number)
|
123
|
+
rpc_calls[underlying_decimals_key] = self.state_service.get_function_info(
|
124
|
+
underlying, ERC20_ABI, "decimals", [], block_number
|
125
|
+
)
|
126
|
+
|
127
|
+
return rpc_calls
|
128
|
+
|
129
|
+
def calculate_wallet_deposit_borrow_balance(
|
130
|
+
self, wallet_address: str, reserves_info: dict, decoded_data: dict, token_prices: dict = None,
|
131
|
+
block_number: int = "latest"):
|
132
|
+
if token_prices is None:
|
133
|
+
token_prices = {}
|
134
|
+
result = {}
|
135
|
+
for token, value in reserves_info.items():
|
136
|
+
underlying = token
|
137
|
+
ctoken = value.get(self.market_key)
|
138
|
+
if token == Token.native_token:
|
139
|
+
underlying = Token.wrapped_token.get(self.chain_id)
|
140
|
+
get_total_deposit_id = f"collateralBalance_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
141
|
+
get_total_borrow_id = f"borrowBalance_{self.name}_{ctoken}_{wallet_address}_{block_number}".lower()
|
142
|
+
get_decimals_id = f"decimals_{underlying}_{block_number}".lower()
|
143
|
+
decimals = decoded_data[get_decimals_id]
|
144
|
+
deposit_amount = decoded_data[get_total_deposit_id] / 10 ** decimals
|
145
|
+
borrow_amount = decoded_data[get_total_borrow_id] / 10 ** decimals
|
146
|
+
result[token] = {
|
147
|
+
"borrow_amount": borrow_amount,
|
148
|
+
"deposit_amount": deposit_amount,
|
149
|
+
}
|
150
|
+
if token_prices:
|
151
|
+
token_price = token_prices.get(underlying)
|
152
|
+
else:
|
153
|
+
token_price = None
|
154
|
+
if token_price is not None:
|
155
|
+
deposit_amount_in_usd = deposit_amount * token_price
|
156
|
+
borrow_amount_in_usd = borrow_amount * token_price
|
157
|
+
result[token]['borrow_amount_in_usd'] += borrow_amount_in_usd
|
158
|
+
result[token]['deposit_amount_in_usd'] += deposit_amount_in_usd
|
159
|
+
return result
|