defi-state-querier 0.0.9__py3-none-any.whl → 0.1.1__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/apeswape/__init__.py +0 -0
- defi_services/abis/lending/apeswape/apeswap_comptroller_abi.py +2235 -0
- defi_services/abis/lending/apeswape/apeswap_lens_abi.py +747 -0
- defi_services/abis/lending/apeswape/apswap_ctoken_abi.py +1485 -0
- defi_services/abis/lending/wepiggy/wepiggy_comptroller_abi.py +1684 -0
- defi_services/abis/lending/wepiggy/wepiggy_distribution_abi.py +959 -1041
- defi_services/abis/lending/wepiggy/wepiggy_lens_abi.py +1098 -0
- defi_services/constants/entities/lending_constant.py +3 -1
- defi_services/constants/entities/lending_services.py +28 -13
- defi_services/services/lending/apeswap_services.py +88 -0
- defi_services/services/lending/compound_service.py +1 -0
- defi_services/services/lending/{granary_v1_services.py → granary_services.py} +38 -18
- defi_services/services/lending/iron_bank_service.py +5 -1
- defi_services/services/lending/lending_info/arbitrum/granary_arbitrum.py +67 -0
- defi_services/services/lending/lending_info/arbitrum/wepiggy_arbitrum.py +36 -0
- defi_services/services/lending/lending_info/avalanche/granary_avalanche.py +55 -0
- defi_services/services/lending/lending_info/avalanche/iron_bank_avalanche.py +55 -0
- defi_services/services/lending/lending_info/bsc/apeswap_bsc.py +52 -0
- defi_services/services/lending/lending_info/bsc/granary_bsc.py +49 -0
- defi_services/services/lending/lending_info/bsc/liqee_bsc.py +85 -0
- defi_services/services/lending/lending_info/bsc/wepiggy_bsc.py +76 -0
- defi_services/services/lending/lending_info/ethereum/{granary_v1_eth.py → granary_eth.py} +1 -1
- defi_services/services/lending/lending_info/ethereum/iron_bank_eth.py +0 -1
- defi_services/services/lending/lending_info/ethereum/spark_eth.py +41 -94
- defi_services/services/lending/lending_info/ethereum/wepiggy_eth.py +18 -7
- defi_services/services/lending/lending_info/fantom/granary_ftm.py +67 -0
- defi_services/services/lending/lending_info/optimism/granary_optimism.py +84 -0
- defi_services/services/lending/lending_info/optimism/iron_bank_optimism.py +43 -0
- defi_services/services/lending/lending_info/optimism/wepiggy_optimism.py +40 -0
- defi_services/services/lending/lending_info/polygon/wepiggy_polygon.py +52 -0
- defi_services/services/lending/liqee_service.py +5 -3
- defi_services/services/lending/morpho_aave_v2_services.py +2 -2
- defi_services/services/lending/morpho_aave_v3_services.py +2 -2
- defi_services/services/lending/morpho_compound_services.py +1 -1
- defi_services/services/lending/spark_services.py +32 -0
- defi_services/services/lending/wepiggy_services.py +26 -237
- {defi_state_querier-0.0.9.dist-info → defi_state_querier-0.1.1.dist-info}/METADATA +1 -1
- {defi_state_querier-0.0.9.dist-info → defi_state_querier-0.1.1.dist-info}/RECORD +42 -21
- {defi_state_querier-0.0.9.dist-info → defi_state_querier-0.1.1.dist-info}/LICENSE +0 -0
- {defi_state_querier-0.0.9.dist-info → defi_state_querier-0.1.1.dist-info}/WHEEL +0 -0
- {defi_state_querier-0.0.9.dist-info → defi_state_querier-0.1.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
WEPIGGY_POLYGON = {
|
2
|
+
"name": "Wepiggy Lending Pool",
|
3
|
+
"rewardToken": "0x6f620ec89b8479e97a6985792d0c64f237566746",
|
4
|
+
"comptrollerAddress": "0xffceacfd39117030314a07b2c86da36e51787948",
|
5
|
+
"lensAddress": "0x82413f75f0da101e0fe7f6ff6cba3461f7e04f29",
|
6
|
+
"distributionAddress": "0x16b321c99ab31a84d565ea484f035693718c3e71",
|
7
|
+
"poolToken": "0x6f620ec89b8479e97a6985792d0c64f237566746",
|
8
|
+
"type": "LENDING_POOL",
|
9
|
+
"forked": "compound",
|
10
|
+
"reservesList": {
|
11
|
+
"0x0000000000000000000000000000000000000000": {
|
12
|
+
"cToken": "0xc1b02e52e9512519edf99671931772e452fb4399",
|
13
|
+
"liquidationThreshold": 0.6
|
14
|
+
},
|
15
|
+
"0x2791bca1f2de4661ed88a30c99a7a9449aa84174": {
|
16
|
+
"cToken": "0x12d803497d1e58dd4d4a4f455d754f1d0f937c8b",
|
17
|
+
"liquidationThreshold": 0.9
|
18
|
+
},
|
19
|
+
"0xc2132d05d31c914a87c6611c10748aeb04b58e8f": {
|
20
|
+
"cToken": "0x0c8c1ab017c3c0c8a48dd9f1db2f59022d190f0b",
|
21
|
+
"liquidationThreshold": 0.9
|
22
|
+
},
|
23
|
+
"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063": {
|
24
|
+
"cToken": "0x5cfad792c4df1323188180778aec58e00eace32a",
|
25
|
+
"liquidationThreshold": 0.9
|
26
|
+
},
|
27
|
+
"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619": {
|
28
|
+
"cToken": "0xf4b6d5d432f1c7a9efc9e0b04acde479f9fd1f72",
|
29
|
+
"liquidationThreshold": 0.8
|
30
|
+
},
|
31
|
+
"0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6": {
|
32
|
+
"cToken": "0xf19200b30a0416322d58e6b6b1d6b5f832936729",
|
33
|
+
"liquidationThreshold": 0.8
|
34
|
+
},
|
35
|
+
"0x53e0bca35ec356bd5dddfebbd1fc0fd03fabad39": {
|
36
|
+
"cToken": "0x3a9cad689a510a7c410ee1be17929cdf78efac8c",
|
37
|
+
"liquidationThreshold": 0.6
|
38
|
+
},
|
39
|
+
"0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a": {
|
40
|
+
"cToken": "0x1b1cd0fdb6592fe482026b8e47706eac1ee94a7c",
|
41
|
+
"liquidationThreshold": 0.0
|
42
|
+
},
|
43
|
+
"0x172370d5cd63279efa6d502dab29171933a610af": {
|
44
|
+
"cToken": "0xc28e11040c529a6828c20a641f8f75b7c0ea92e3",
|
45
|
+
"liquidationThreshold": 0.6
|
46
|
+
},
|
47
|
+
"0xf28164a485b0b2c90639e47b0f377b4a438a16b1": {
|
48
|
+
"cToken": "0xd0199ba93031ba37aa4e17c885a47edeeb23ae04",
|
49
|
+
"liquidationThreshold": 0.0
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
@@ -13,6 +13,7 @@ from defi_services.constants.entities.lending_constant import Lending
|
|
13
13
|
from defi_services.constants.query_constant import Query
|
14
14
|
from defi_services.constants.token_constant import Token
|
15
15
|
from defi_services.jobs.queriers.state_querier import StateQuerier
|
16
|
+
from defi_services.services.lending.lending_info.bsc.liqee_bsc import LIQEE_BSC
|
16
17
|
from defi_services.services.lending.lending_info.ethereum.liqee_eth import LIQEE_ETH
|
17
18
|
from defi_services.services.protocol_services import ProtocolServices
|
18
19
|
|
@@ -21,7 +22,8 @@ logger = logging.getLogger("Liqee Lending Pool State Service")
|
|
21
22
|
|
22
23
|
class LiqeeInfo:
|
23
24
|
mapping = {
|
24
|
-
Chain.ethereum: LIQEE_ETH
|
25
|
+
Chain.ethereum: LIQEE_ETH,
|
26
|
+
Chain.bsc: LIQEE_BSC
|
25
27
|
}
|
26
28
|
|
27
29
|
|
@@ -145,11 +147,11 @@ class LiqeeStateService(ProtocolServices):
|
|
145
147
|
):
|
146
148
|
fn_paras = [Web3.toChecksumAddress(wallet_address)]
|
147
149
|
rpc_call = self.get_lending_function_info("getAccountRewardAmount", fn_paras, block_number)
|
148
|
-
get_reward_id = f"getAccountRewardAmount_{wallet_address}_{block_number}".lower()
|
150
|
+
get_reward_id = f"getAccountRewardAmount_{self.name}_{wallet_address}_{block_number}".lower()
|
149
151
|
return {get_reward_id: rpc_call}
|
150
152
|
|
151
153
|
def calculate_rewards_balance(self, wallet_address: str, decoded_data: dict, block_number: int = "latest"):
|
152
|
-
get_reward_id = f"getAccountRewardAmount_{wallet_address}_{block_number}".lower()
|
154
|
+
get_reward_id = f"getAccountRewardAmount_{self.name}_{wallet_address}_{block_number}".lower()
|
153
155
|
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
154
156
|
reward_token = self.pool_info.get("rewardToken")
|
155
157
|
result = {
|
@@ -13,7 +13,7 @@ from defi_services.constants.entities.lending_constant import Lending
|
|
13
13
|
from defi_services.jobs.queriers.state_querier import StateQuerier
|
14
14
|
from defi_services.services.lending.lending_info.aave_v2_services import AaveInfo
|
15
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
|
16
|
+
from defi_services.services.lending.morpho_compound_services import MorphoCompoundStateService
|
17
17
|
|
18
18
|
logger = logging.getLogger("Compound Lending Pool State Service")
|
19
19
|
|
@@ -24,7 +24,7 @@ class MorphoAaveV2Info:
|
|
24
24
|
}
|
25
25
|
|
26
26
|
|
27
|
-
class
|
27
|
+
class MorphoAaveV2StateService(MorphoCompoundStateService):
|
28
28
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
29
29
|
super().__init__(state_service, chain_id)
|
30
30
|
self.name = f"{chain_id}_{Lending.morpho_aave_v2}"
|
@@ -14,7 +14,7 @@ from defi_services.constants.token_constant import Token
|
|
14
14
|
from defi_services.jobs.queriers.state_querier import StateQuerier
|
15
15
|
from defi_services.services.lending.aave_v3_services import AaveV3Info
|
16
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
|
17
|
+
from defi_services.services.lending.morpho_compound_services import MorphoCompoundStateService
|
18
18
|
|
19
19
|
logger = logging.getLogger("Compound Lending Pool State Service")
|
20
20
|
|
@@ -25,7 +25,7 @@ class MorphoAaveV3Info:
|
|
25
25
|
}
|
26
26
|
|
27
27
|
|
28
|
-
class
|
28
|
+
class MorphoAaveV3StateService(MorphoCompoundStateService):
|
29
29
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
30
30
|
super().__init__(state_service, chain_id)
|
31
31
|
self.name = f"{chain_id}_{Lending.morpho_aave_v3}"
|
@@ -26,7 +26,7 @@ class MorphoCompoundInfo:
|
|
26
26
|
}
|
27
27
|
|
28
28
|
|
29
|
-
class
|
29
|
+
class MorphoCompoundStateService(ProtocolServices):
|
30
30
|
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
31
31
|
self.name = f"{chain_id}_{Lending.morpho_compound}"
|
32
32
|
self.chain_id = chain_id
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
from defi_services.constants.chain_constant import Chain
|
4
|
+
from defi_services.constants.entities.lending_constant import Lending
|
5
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
6
|
+
from defi_services.services.lending.aave_v3_services import AaveV3StateService
|
7
|
+
from defi_services.services.lending.lending_info.ethereum.spark_eth import SPARK_ETH
|
8
|
+
|
9
|
+
logger = logging.getLogger("Spark Lending Pool State Service")
|
10
|
+
|
11
|
+
|
12
|
+
class SparkInfo:
|
13
|
+
mapping = {
|
14
|
+
Chain.ethereum: SPARK_ETH
|
15
|
+
}
|
16
|
+
|
17
|
+
|
18
|
+
class SparkStateService(AaveV3StateService):
|
19
|
+
def __init__(self, state_service: StateQuerier, chain_id: str = "0x1"):
|
20
|
+
super().__init__(state_service, chain_id)
|
21
|
+
self.name = f"{chain_id}_{Lending.spark}"
|
22
|
+
self.pool_info = SparkInfo.mapping.get(chain_id)
|
23
|
+
|
24
|
+
def get_service_info(self):
|
25
|
+
info = {
|
26
|
+
Lending.spark: {
|
27
|
+
"chain_id": self.chain_id,
|
28
|
+
"type": "lending",
|
29
|
+
"protocol_info": self.pool_info
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return info
|
@@ -3,18 +3,21 @@ import time
|
|
3
3
|
|
4
4
|
from web3 import Web3
|
5
5
|
|
6
|
-
from defi_services.abis.lending.
|
7
|
-
from defi_services.abis.lending.cream.cream_lens_abi import CREAM_LENS_ABI
|
6
|
+
from defi_services.abis.lending.wepiggy.wepiggy_comptroller_abi import WEPIGGY_COMPTROLLER_ABI
|
8
7
|
from defi_services.abis.lending.wepiggy.wepiggy_distribution_abi import WEPIGGY_DISTRIBUTION_ABI
|
8
|
+
from defi_services.abis.lending.wepiggy.wepiggy_lens_abi import WEPIGGY_LENS_ABI
|
9
9
|
from defi_services.abis.token.ctoken_abi import CTOKEN_ABI
|
10
10
|
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
11
11
|
from defi_services.constants.chain_constant import Chain
|
12
|
-
from defi_services.constants.db_constant import DBConst
|
13
12
|
from defi_services.constants.entities.lending_constant import Lending
|
14
13
|
from defi_services.constants.query_constant import Query
|
15
14
|
from defi_services.constants.token_constant import ContractAddresses, Token
|
16
15
|
from defi_services.jobs.queriers.state_querier import StateQuerier
|
16
|
+
from defi_services.services.lending.lending_info.arbitrum.wepiggy_arbitrum import WEPIGGY_ARB
|
17
|
+
from defi_services.services.lending.lending_info.bsc.wepiggy_bsc import WEPIGGY_BSC
|
17
18
|
from defi_services.services.lending.lending_info.ethereum.wepiggy_eth import WEPIGGY_ETH
|
19
|
+
from defi_services.services.lending.lending_info.optimism.wepiggy_optimism import WEPIGGY_OPTIMISM
|
20
|
+
from defi_services.services.lending.lending_info.polygon.wepiggy_polygon import WEPIGGY_POLYGON
|
18
21
|
from defi_services.services.protocol_services import ProtocolServices
|
19
22
|
|
20
23
|
logger = logging.getLogger("Compound Lending Pool State Service")
|
@@ -22,7 +25,11 @@ logger = logging.getLogger("Compound Lending Pool State Service")
|
|
22
25
|
|
23
26
|
class WepiggyInfo:
|
24
27
|
mapping = {
|
25
|
-
Chain.ethereum: WEPIGGY_ETH
|
28
|
+
Chain.ethereum: WEPIGGY_ETH,
|
29
|
+
Chain.bsc: WEPIGGY_BSC,
|
30
|
+
Chain.arbitrum: WEPIGGY_ARB,
|
31
|
+
Chain.polygon: WEPIGGY_POLYGON,
|
32
|
+
Chain.optimism: WEPIGGY_OPTIMISM
|
26
33
|
}
|
27
34
|
|
28
35
|
|
@@ -32,9 +39,9 @@ class WepiggyStateService(ProtocolServices):
|
|
32
39
|
self.chain_id = chain_id
|
33
40
|
self.pool_info = WepiggyInfo.mapping.get(chain_id)
|
34
41
|
self.state_service = state_service
|
35
|
-
self.lens_abi =
|
42
|
+
self.lens_abi = WEPIGGY_LENS_ABI
|
36
43
|
self.distribution_abi = WEPIGGY_DISTRIBUTION_ABI
|
37
|
-
self.comptroller_abi =
|
44
|
+
self.comptroller_abi = WEPIGGY_COMPTROLLER_ABI
|
38
45
|
|
39
46
|
def get_service_info(self):
|
40
47
|
info = {
|
@@ -63,10 +70,10 @@ class WepiggyStateService(ProtocolServices):
|
|
63
70
|
address=Web3.toChecksumAddress(self.pool_info.get("lensAddress")), abi=self.lens_abi
|
64
71
|
)
|
65
72
|
tokens = [Web3.toChecksumAddress(i) for i in ctokens]
|
66
|
-
metadata = lens_contract.functions.
|
73
|
+
metadata = lens_contract.functions.pTokenMetadataAll(tokens).call(block_identifier=block_number)
|
67
74
|
reserves_info = {}
|
68
75
|
for data in metadata:
|
69
|
-
underlying = data[
|
76
|
+
underlying = data[2].lower()
|
70
77
|
ctoken = data[0].lower()
|
71
78
|
lt = data[10] / 10 ** 18
|
72
79
|
reserves_info[underlying] = {
|
@@ -98,12 +105,10 @@ class WepiggyStateService(ProtocolServices):
|
|
98
105
|
begin = time.time()
|
99
106
|
reserves_info = kwargs.get("reserves_info", self.pool_info.get("reservesList"))
|
100
107
|
token_prices = kwargs.get("token_prices", {})
|
101
|
-
wrapped_native_token_price = token_prices.get(Token.wrapped_token.get(self.chain_id), 1)
|
102
|
-
pool_decimals = kwargs.get("pool_decimals", 18)
|
103
108
|
result = {}
|
104
109
|
if Query.deposit_borrow in query_types and wallet:
|
105
110
|
result.update(self.calculate_wallet_deposit_borrow_balance(
|
106
|
-
wallet, reserves_info, decoded_data, token_prices,
|
111
|
+
wallet, reserves_info, decoded_data, token_prices, block_number
|
107
112
|
))
|
108
113
|
|
109
114
|
if Query.protocol_reward in query_types and wallet:
|
@@ -111,10 +116,6 @@ class WepiggyStateService(ProtocolServices):
|
|
111
116
|
wallet, decoded_data, block_number
|
112
117
|
))
|
113
118
|
|
114
|
-
if Query.protocol_apy in query_types and wallet:
|
115
|
-
result.update(self.calculate_apy_lending_pool_function_call(
|
116
|
-
reserves_info, decoded_data, token_prices, pool_decimals, block_number
|
117
|
-
))
|
118
119
|
logger.info(f"Process protocol data in {time.time() - begin}")
|
119
120
|
return result
|
120
121
|
|
@@ -127,199 +128,32 @@ class WepiggyStateService(ProtocolServices):
|
|
127
128
|
):
|
128
129
|
begin = time.time()
|
129
130
|
reserves_info = kwargs.get("reserves_info", {})
|
130
|
-
is_oracle_price = kwargs.get("is_oracle_price", False) # get price by oracle
|
131
131
|
if not reserves_info:
|
132
132
|
reserves_info = self.pool_info['reservesList']
|
133
133
|
rpc_calls = {}
|
134
134
|
if Query.deposit_borrow in query_types and wallet:
|
135
135
|
rpc_calls.update(self.get_wallet_deposit_borrow_balance_function_info(
|
136
|
-
wallet, reserves_info, block_number
|
136
|
+
wallet, reserves_info, block_number
|
137
137
|
))
|
138
138
|
|
139
|
-
if Query.protocol_apy in query_types:
|
140
|
-
rpc_calls.update(self.get_apy_lending_pool_function_info(reserves_info, block_number, is_oracle_price))
|
141
|
-
|
142
139
|
if Query.protocol_reward in query_types and wallet:
|
143
140
|
rpc_calls.update(self.get_rewards_balance_function_info(wallet, block_number))
|
144
141
|
|
145
142
|
logger.info(f"Get encoded rpc calls in {time.time() - begin}s")
|
146
143
|
return rpc_calls
|
147
144
|
|
148
|
-
# CALCULATE APY LENDING POOL
|
149
|
-
def get_apy_lending_pool_function_info(
|
150
|
-
self,
|
151
|
-
reserves_info: dict,
|
152
|
-
block_number: int = "latest",
|
153
|
-
is_price_oracle: bool = False
|
154
|
-
):
|
155
|
-
rpc_calls = {}
|
156
|
-
for token, value in reserves_info.items():
|
157
|
-
ctoken = value.get("ctoken")
|
158
|
-
speed_key = f"compSpeeds_{ctoken}_{block_number}".lower()
|
159
|
-
mint_key = f"mintGuardianPaused_{ctoken}_{block_number}".lower()
|
160
|
-
borrow_key = f"borrowGuardianPaused_{token}_{block_number}".lower()
|
161
|
-
metadata_key = f"cTokenMetadata_{ctoken}_{block_number}".lower()
|
162
|
-
if is_price_oracle:
|
163
|
-
price_key = f"cTokenUnderlyingPrice_{ctoken}_{block_number}".lower()
|
164
|
-
rpc_calls[price_key] = self.get_comptroller_function_info('cTokenUnderlyingPrice', [ctoken],
|
165
|
-
block_number)
|
166
|
-
rpc_calls[speed_key] = self.get_comptroller_function_info('compSpeeds', [ctoken], block_number)
|
167
|
-
rpc_calls[mint_key] = self.get_comptroller_function_info('mintGuardianPaused', [ctoken], block_number)
|
168
|
-
rpc_calls[borrow_key] = self.get_comptroller_function_info('borrowGuardianPaused', [ctoken], block_number)
|
169
|
-
rpc_calls[metadata_key] = self.get_comptroller_function_info('cTokenMetadata', [ctoken], block_number)
|
170
|
-
|
171
|
-
return rpc_calls
|
172
|
-
|
173
|
-
@staticmethod
|
174
|
-
def get_apy_lending_pool(
|
175
|
-
decoded_data: dict,
|
176
|
-
reserves_info: dict,
|
177
|
-
block_number: int = "latest",
|
178
|
-
wrapped_native_token_price: float = 310,
|
179
|
-
underlying_price: dict = None,
|
180
|
-
is_oracle_price: bool = False
|
181
|
-
):
|
182
|
-
underlying_prices, underlying_decimals, reserve_tokens_info = {}, {}, []
|
183
|
-
ctoken_speeds, borrow_paused_tokens, mint_paused_tokens = {}, {}, {}
|
184
|
-
for token, value in reserves_info.items():
|
185
|
-
ctoken = value.get('cToken')
|
186
|
-
speeds_call_id = f'compSpeeds_{ctoken}_{block_number}'.lower()
|
187
|
-
borrow_guardian_paused_call_id = f'borrowGuardianPaused_{ctoken}_{block_number}'.lower()
|
188
|
-
mint_guardian_paused_call_id = f'mintGuardianPaused_{ctoken}_{block_number}'.lower()
|
189
|
-
ctoken_speeds[ctoken] = decoded_data.get(speeds_call_id)
|
190
|
-
borrow_paused_tokens[ctoken] = decoded_data.get(borrow_guardian_paused_call_id)
|
191
|
-
mint_paused_tokens[ctoken] = decoded_data.get(mint_guardian_paused_call_id)
|
192
|
-
metadata_id = f"cTokenMetadata_{ctoken}_{block_number}".lower()
|
193
|
-
reserve_tokens_info.append(decoded_data.get(metadata_id))
|
194
|
-
if is_oracle_price:
|
195
|
-
underlying_id = f"cTokenUnderlyingPrice_{ctoken}_{block_number}".lower()
|
196
|
-
price_token = decoded_data.get(underlying_id)
|
197
|
-
price_token = price_token[1] * wrapped_native_token_price
|
198
|
-
else:
|
199
|
-
price_token = underlying_price.get(token)
|
200
|
-
|
201
|
-
underlying_decimals[ctoken] = decoded_data.get(metadata_id)[-1]
|
202
|
-
underlying_prices[ctoken] = price_token
|
203
|
-
return {
|
204
|
-
"reserve_tokens_info": reserve_tokens_info,
|
205
|
-
"ctoken_speeds": ctoken_speeds,
|
206
|
-
"borrow_paused_tokens": borrow_paused_tokens,
|
207
|
-
"mint_paused_tokens": mint_paused_tokens,
|
208
|
-
"underlying_prices": underlying_prices,
|
209
|
-
"underlying_decimals": underlying_decimals
|
210
|
-
}
|
211
|
-
|
212
|
-
def calculate_apy_lending_pool_function_call(
|
213
|
-
self,
|
214
|
-
reserves_info: dict,
|
215
|
-
decoded_data: dict,
|
216
|
-
token_prices: dict,
|
217
|
-
pool_decimals: int = 18,
|
218
|
-
block_number: int = "latest",
|
219
|
-
is_oracle_price: bool = False,
|
220
|
-
):
|
221
|
-
wrapped_native_token_price = token_prices.get(Token.wrapped_token.get(self.chain_id))
|
222
|
-
pool_token_price = token_prices.get(self.pool_info.get("poolToken"))
|
223
|
-
tokens_interest_rates = dict()
|
224
|
-
decode_data = self.get_apy_lending_pool(
|
225
|
-
decoded_data, reserves_info, block_number,
|
226
|
-
wrapped_native_token_price, token_prices, is_oracle_price)
|
227
|
-
|
228
|
-
mint_paused_tokens = decode_data["mint_paused_tokens"]
|
229
|
-
borrow_paused_tokens = decode_data["borrow_paused_tokens"]
|
230
|
-
reserve_tokens_info = decode_data["reserve_tokens_info"]
|
231
|
-
ctoken_speeds = decode_data["ctoken_speeds"]
|
232
|
-
for data in reserve_tokens_info:
|
233
|
-
address = data[0].lower()
|
234
|
-
underlying_token_price = float(decode_data["underlying_prices"][address])
|
235
|
-
if is_oracle_price:
|
236
|
-
underlying_token_price = underlying_token_price / 10 ** int(data[13])
|
237
|
-
|
238
|
-
token_info = {
|
239
|
-
"token": address,
|
240
|
-
"token_decimals": data[12],
|
241
|
-
"borrow_rate": data[3],
|
242
|
-
"supply_rate": data[2],
|
243
|
-
"supply": data[7],
|
244
|
-
"borrow": data[5],
|
245
|
-
"exchange_rate": data[1],
|
246
|
-
"underlying": data[11].lower(),
|
247
|
-
"underlying_price": underlying_token_price,
|
248
|
-
"underlying_decimals": data[13],
|
249
|
-
"speed": ctoken_speeds[address]
|
250
|
-
}
|
251
|
-
underlying_token = token_info['underlying']
|
252
|
-
token_info["mint_paused"] = mint_paused_tokens[address]
|
253
|
-
token_info["borrow_paused"] = borrow_paused_tokens[address]
|
254
|
-
tokens_interest_rates[underlying_token] = self._calculate_interest_rates(
|
255
|
-
token_info, pool_decimals, pool_token_price)
|
256
|
-
|
257
|
-
return tokens_interest_rates
|
258
|
-
|
259
|
-
@staticmethod
|
260
|
-
def _calculate_interest_rates(token_info: dict, pool_decimals: int, pool_price: float,
|
261
|
-
is_oracle_price: bool = False):
|
262
|
-
apx_block_speed_in_seconds = 3
|
263
|
-
exchange_rate = float(token_info["exchange_rate"]) / 10 ** (18 - 8 + token_info["underlying_decimals"])
|
264
|
-
block_per_day = int(60 * 60 * 24 / apx_block_speed_in_seconds)
|
265
|
-
venus_per_day = token_info["speed"] * block_per_day / 10 ** pool_decimals
|
266
|
-
underlying_price = float(token_info["underlying_price"])
|
267
|
-
if is_oracle_price:
|
268
|
-
underlying_price /= 10 ** (36 - int(token_info["underlying_decimals"]))
|
269
|
-
total_borrow = float(token_info["borrow"]) / 10 ** int(token_info["underlying_decimals"])
|
270
|
-
total_supply = float(token_info["supply"]) * exchange_rate / 10 ** int(token_info["underlying_decimals"])
|
271
|
-
total_borrow_usd = total_borrow * underlying_price
|
272
|
-
total_supply_usd = total_supply * underlying_price
|
273
|
-
|
274
|
-
if total_borrow_usd == 0:
|
275
|
-
borrow_apr = 0
|
276
|
-
else:
|
277
|
-
borrow_apr = (1 + (pool_price * venus_per_day / total_borrow_usd)) ** 365 - 1
|
278
|
-
|
279
|
-
if total_supply_usd == 0:
|
280
|
-
supply_apr = 0
|
281
|
-
else:
|
282
|
-
supply_apr = (1 + (pool_price * venus_per_day / total_supply_usd)) ** 365 - 1
|
283
|
-
|
284
|
-
supply_apy = ((token_info["supply_rate"] / 10 ** pool_decimals) * block_per_day + 1) ** 365 - 1
|
285
|
-
borrow_apy = ((token_info["borrow_rate"] / 10 ** pool_decimals) * block_per_day + 1) ** 365 - 1
|
286
|
-
|
287
|
-
liquidity_log = {
|
288
|
-
DBConst.total_borrow: {
|
289
|
-
DBConst.amount: total_borrow,
|
290
|
-
DBConst.value_in_usd: total_borrow_usd
|
291
|
-
},
|
292
|
-
DBConst.total_deposit: {
|
293
|
-
DBConst.amount: total_supply,
|
294
|
-
DBConst.value_in_usd: total_supply_usd
|
295
|
-
}
|
296
|
-
}
|
297
|
-
return {
|
298
|
-
DBConst.reward_borrow_apy: borrow_apr,
|
299
|
-
DBConst.reward_deposit_apy: supply_apr,
|
300
|
-
DBConst.deposit_apy: supply_apy,
|
301
|
-
DBConst.borrow_apy: borrow_apy,
|
302
|
-
DBConst.liquidity_change_logs: liquidity_log,
|
303
|
-
DBConst.mint_paused: token_info[DBConst.mint_paused],
|
304
|
-
DBConst.borrow_paused: token_info[DBConst.borrow_paused]
|
305
|
-
}
|
306
|
-
|
307
145
|
# REWARDS BALANCE
|
308
146
|
def get_rewards_balance_function_info(
|
309
147
|
self,
|
310
148
|
wallet_address: str,
|
311
149
|
block_number: int = "latest",
|
312
150
|
):
|
313
|
-
|
314
|
-
|
315
|
-
False,
|
316
|
-
True]
|
317
|
-
rpc_call = self.get_distribution_function_info("pendingWpcAccrued", fn_paras, block_number)
|
318
|
-
get_reward_id = f"pendingWpcAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
151
|
+
rpc_call = self.get_distribution_function_info("wpcAccrued", [wallet_address], block_number)
|
152
|
+
get_reward_id = f"wpcAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
319
153
|
return {get_reward_id: rpc_call}
|
320
154
|
|
321
155
|
def calculate_rewards_balance(self, wallet_address: str, decoded_data: dict, block_number: int = "latest"):
|
322
|
-
get_reward_id = f"
|
156
|
+
get_reward_id = f"wpcAccrued_{self.name}_{wallet_address}_{block_number}".lower()
|
323
157
|
rewards = decoded_data.get(get_reward_id) / 10 ** 18
|
324
158
|
reward_token = self.pool_info.get("rewardToken")
|
325
159
|
result = {
|
@@ -332,8 +166,7 @@ class WepiggyStateService(ProtocolServices):
|
|
332
166
|
self,
|
333
167
|
wallet_address: str,
|
334
168
|
reserves_info: dict,
|
335
|
-
block_number: int = "latest"
|
336
|
-
is_oracle_price: bool = False
|
169
|
+
block_number: int = "latest"
|
337
170
|
):
|
338
171
|
|
339
172
|
rpc_calls = {}
|
@@ -342,13 +175,9 @@ class WepiggyStateService(ProtocolServices):
|
|
342
175
|
ctoken = value.get('cToken')
|
343
176
|
if token == Token.native_token:
|
344
177
|
underlying = Token.wrapped_token.get(self.chain_id)
|
345
|
-
underlying_price_key = f"cTokenUnderlyingPrice_{ctoken}_{block_number}".lower()
|
346
178
|
underlying_borrow_key = f"borrowBalanceCurrent_{ctoken}_{wallet_address}_{block_number}".lower()
|
347
179
|
underlying_balance_key = f"balanceOfUnderlying_{ctoken}_{wallet_address}_{block_number}".lower()
|
348
180
|
underlying_decimals_key = f"decimals_{underlying}_{block_number}".lower()
|
349
|
-
if is_oracle_price:
|
350
|
-
rpc_calls[underlying_price_key] = self.get_lens_function_info(
|
351
|
-
"cTokenUnderlyingPrice", [ctoken], block_number)
|
352
181
|
rpc_calls[underlying_borrow_key] = self.get_ctoken_function_info(
|
353
182
|
ctoken, "borrowBalanceCurrent", [wallet_address], block_number)
|
354
183
|
rpc_calls[underlying_balance_key] = self.get_ctoken_function_info(
|
@@ -361,7 +190,7 @@ class WepiggyStateService(ProtocolServices):
|
|
361
190
|
|
362
191
|
def calculate_wallet_deposit_borrow_balance(
|
363
192
|
self, wallet_address: str, reserves_info: dict, decoded_data: dict, token_prices: dict = None,
|
364
|
-
|
193
|
+
block_number: int = "latest"):
|
365
194
|
if token_prices is None:
|
366
195
|
token_prices = {}
|
367
196
|
result = {}
|
@@ -380,11 +209,7 @@ class WepiggyStateService(ProtocolServices):
|
|
380
209
|
"borrow_amount": borrow_amount,
|
381
210
|
"deposit_amount": deposit_amount,
|
382
211
|
}
|
383
|
-
if
|
384
|
-
get_underlying_token_price = f"cTokenUnderlyingPrice_{ctoken}_{block_number}".lower()
|
385
|
-
token_price = decoded_data.get(get_underlying_token_price)[
|
386
|
-
1] * wrapped_native_token_price / 10 ** decimals
|
387
|
-
elif token_prices:
|
212
|
+
if token_prices:
|
388
213
|
token_price = token_prices.get(underlying)
|
389
214
|
else:
|
390
215
|
token_price = None
|
@@ -399,8 +224,7 @@ class WepiggyStateService(ProtocolServices):
|
|
399
224
|
def get_token_deposit_borrow_balance_function_info(
|
400
225
|
self,
|
401
226
|
reserves_info: dict,
|
402
|
-
block_number: int = "latest"
|
403
|
-
is_oracle_price: bool = False
|
227
|
+
block_number: int = "latest"
|
404
228
|
):
|
405
229
|
rpc_calls = {}
|
406
230
|
for token, value in reserves_info.items():
|
@@ -408,15 +232,11 @@ class WepiggyStateService(ProtocolServices):
|
|
408
232
|
if token == Token.native_token:
|
409
233
|
underlying = Token.wrapped_token.get(self.chain_id)
|
410
234
|
ctoken = value.get('cToken')
|
411
|
-
underlying_price_key = f"cTokenUnderlyingPrice_{ctoken}_{block_number}".lower()
|
412
235
|
underlying_borrow_key = f"totalBorrows_{ctoken}_{block_number}".lower()
|
413
236
|
underlying_balance_key = f"totalSupply_{ctoken}_{block_number}".lower()
|
414
237
|
underlying_decimals_key = f"decimals_{underlying}_{block_number}".lower()
|
415
238
|
ctoken_decimals_key = f"decimals_{ctoken}_{block_number}".lower()
|
416
239
|
exchange_rate_key = f"exchangeRateCurrent_{ctoken}_{block_number}".lower()
|
417
|
-
if is_oracle_price:
|
418
|
-
rpc_calls[underlying_price_key] = self.get_lens_function_info(
|
419
|
-
"cTokenUnderlyingPrice", [ctoken], block_number)
|
420
240
|
rpc_calls[underlying_borrow_key] = self.get_ctoken_function_info(
|
421
241
|
ctoken, "totalBorrows", [], block_number)
|
422
242
|
rpc_calls[underlying_balance_key] = self.get_ctoken_function_info(
|
@@ -434,7 +254,7 @@ class WepiggyStateService(ProtocolServices):
|
|
434
254
|
|
435
255
|
def calculate_token_deposit_borrow_balance(
|
436
256
|
self, decoded_data: dict, reserves_info: dict, token_prices: dict = None,
|
437
|
-
block_number: int = "latest"
|
257
|
+
block_number: int = "latest"
|
438
258
|
):
|
439
259
|
result = {}
|
440
260
|
for token, value in reserves_info.items():
|
@@ -456,12 +276,7 @@ class WepiggyStateService(ProtocolServices):
|
|
456
276
|
"borrow_amount": borrow_amount,
|
457
277
|
"deposit_amount": deposit_amount
|
458
278
|
}
|
459
|
-
if
|
460
|
-
get_underlying_token_price = f"cTokenUnderlyingPrice_{ctoken}_{block_number}".lower()
|
461
|
-
token_price = decoded_data.get(get_underlying_token_price)[1] / 10 ** (36 - decimals)
|
462
|
-
if wrapped_native_token_price:
|
463
|
-
token_price *= wrapped_native_token_price
|
464
|
-
elif token_prices:
|
279
|
+
if token_prices:
|
465
280
|
token_price = token_prices.get(underlying)
|
466
281
|
else:
|
467
282
|
token_price = None
|
@@ -491,29 +306,3 @@ class WepiggyStateService(ProtocolServices):
|
|
491
306
|
return self.state_service.get_function_info(
|
492
307
|
ctoken, CTOKEN_ABI, fn_name, fn_paras, block_number
|
493
308
|
)
|
494
|
-
|
495
|
-
def get_ctoken_metadata_all(
|
496
|
-
self,
|
497
|
-
reserves_info: dict = None,
|
498
|
-
block_number: int = "latest"
|
499
|
-
):
|
500
|
-
tokens = [Web3.toChecksumAddress(value['cToken']) for key, value in reserves_info.items()]
|
501
|
-
key = f"cTokenMetadataAll_{self.pool_info.get('lensAddress')}_{block_number}".lower()
|
502
|
-
return {
|
503
|
-
key: self.get_lens_function_info("cTokenMetadataAll", tokens, block_number)
|
504
|
-
}
|
505
|
-
|
506
|
-
def ctoken_underlying_price_all(
|
507
|
-
self, reserves_info, block_number: int = 'latest'):
|
508
|
-
tokens = [Web3.toChecksumAddress(value['cToken']) for key, value in reserves_info.items()]
|
509
|
-
key = f"cTokenUnderlyingPriceAll_{self.pool_info.get('lensAddress')}_{block_number}".lower()
|
510
|
-
return {
|
511
|
-
key: self.get_lens_function_info("cTokenUnderlyingPriceAll", tokens, block_number)
|
512
|
-
}
|
513
|
-
|
514
|
-
def get_all_markets(
|
515
|
-
self, block_number: int = 'latest'):
|
516
|
-
key = f"getAllMarkets_{self.pool_info.get('comptrollerAddress')}_{block_number}".lower()
|
517
|
-
return {
|
518
|
-
key: self.get_comptroller_function_info("getAllMarkets", [], block_number)
|
519
|
-
}
|