defi-state-querier 0.5.29__py3-none-any.whl → 0.5.31__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- defi_services/__init__.py +1 -1
- defi_services/abis/lending/kinza/__init__.py +0 -0
- defi_services/abis/lending/kinza/kinza_incentive.py +928 -0
- defi_services/abis/lending/kinza/kinza_lending_pool.py +1791 -0
- defi_services/abis/lending/seamless/__init__.py +0 -0
- defi_services/abis/lending/seamless/seamless_incentive.py +1049 -0
- defi_services/abis/lending/seamless/seamless_lending_pool.py +1738 -0
- defi_services/abis/lending/seamless/seamless_oracle.py +233 -0
- defi_services/constants/entities/lending_constant.py +6 -3
- defi_services/constants/entities/lending_services.py +14 -4
- defi_services/services/lending/avalon_services.py +34 -0
- defi_services/services/lending/kinza_services.py +315 -0
- defi_services/services/lending/lending_info/base/seamless_base.py +145 -0
- defi_services/services/lending/lending_info/base/xlend_base.py +91 -0
- defi_services/services/lending/lending_info/bsc/avalon_bsc.py +75 -0
- defi_services/services/lending/lending_info/bsc/kinza_bsc.py +182 -0
- defi_services/services/lending/lending_info/ethereum/kinza_eth.py +119 -0
- defi_services/services/lending/lending_info/optimism/xlend_optimism.py +112 -0
- defi_services/services/lending/liqee_service.py +2 -2
- defi_services/services/lending/onyx_service.py +2 -1
- defi_services/services/lending/seamless_services.py +313 -0
- defi_services/services/lending/xlend_services.py +325 -0
- {defi_state_querier-0.5.29.dist-info → defi_state_querier-0.5.31.dist-info}/METADATA +1 -1
- {defi_state_querier-0.5.29.dist-info → defi_state_querier-0.5.31.dist-info}/RECORD +27 -10
- {defi_state_querier-0.5.29.dist-info → defi_state_querier-0.5.31.dist-info}/WHEEL +0 -0
- {defi_state_querier-0.5.29.dist-info → defi_state_querier-0.5.31.dist-info}/licenses/LICENSE +0 -0
- {defi_state_querier-0.5.29.dist-info → defi_state_querier-0.5.31.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
XLEND_OPTIMISM = {
|
2
|
+
"address": "0x345d2827f36621b02b783f7d5004b4a2fec00186",
|
3
|
+
"name": "Xlend Lending Pool",
|
4
|
+
"addressProvider": "0xa98cc6031ba6908d73dc5615ca82b607096d721d",
|
5
|
+
"dataProvider": "0xcc61e9470b5f0ce21a3f6255c73032b47aaea9c0",
|
6
|
+
"stakedIncentiveAddress": '0x3bbf68f18a792d34a288407f34734d16829b457e',
|
7
|
+
"rewardTokensList": ["0x2dad3a13ef0c6366220f989157009e501e7938f8"],
|
8
|
+
"oracleAddress": "0x1bc889345c912d5462b71e019f9dccba33d83db4",
|
9
|
+
"type": "LENDING_POOL",
|
10
|
+
"poolToken": "0x2dad3a13ef0c6366220f989157009e501e7938f8",
|
11
|
+
"forked": "aave-v3",
|
12
|
+
"reservesList": {
|
13
|
+
"0xda10009cbd5d07dd0cecc66161fc93d7c9000da1": {
|
14
|
+
"tToken": "0x82e64f49ed5ec1bc6e43dad4fc8af9bb3a2312ee",
|
15
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
16
|
+
"dToken": "0x8619d80fb0141ba7f184cbf22fd724116d9f7ffc",
|
17
|
+
"loanToValue": 0.63,
|
18
|
+
"liquidationThreshold": 0.77
|
19
|
+
},
|
20
|
+
"0x350a791bfc2c21f9ed5d10980dad2e2638ffa7f6": {
|
21
|
+
"tToken": "0x191c10aa4af7c30e871e70c95db0e4eb77237530",
|
22
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
23
|
+
"dToken": "0x953a573793604af8d41f306feb8274190db4ae0e",
|
24
|
+
"loanToValue": 0.66,
|
25
|
+
"liquidationThreshold": 0.71
|
26
|
+
},
|
27
|
+
"0x7f5c764cbc14f9669b88837ca1490cca17c31607": {
|
28
|
+
"tToken": "0x625e7708f30ca75bfd92586e17077590c60eb4cd",
|
29
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
30
|
+
"dToken": "0xfccf3cabbe80101232d343252614b6a3ee81c989",
|
31
|
+
"loanToValue": 0.75,
|
32
|
+
"liquidationThreshold": 0.785
|
33
|
+
},
|
34
|
+
"0x68f180fcce6836688e9084f035309e29bf0a2095": {
|
35
|
+
"tToken": "0x078f358208685046a11c85e8ad32895ded33a249",
|
36
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
37
|
+
"dToken": "0x92b42c66840c7ad907b4bf74879ff3ef7c529473",
|
38
|
+
"loanToValue": 0.73,
|
39
|
+
"liquidationThreshold": 0.78
|
40
|
+
},
|
41
|
+
"0x4200000000000000000000000000000000000006": {
|
42
|
+
"tToken": "0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8",
|
43
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
44
|
+
"dToken": "0x0c84331e39d6658cd6e6b9ba04736cc4c4734351",
|
45
|
+
"loanToValue": 0.8,
|
46
|
+
"liquidationThreshold": 0.83
|
47
|
+
},
|
48
|
+
"0x94b008aa00579c1307b0ef2c499ad98a8ce58e58": {
|
49
|
+
"tToken": "0x6ab707aca953edaefbc4fd23ba73294241490620",
|
50
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
51
|
+
"dToken": "0xfb00ac187a8eb5afae4eace434f493eb62672df7",
|
52
|
+
"loanToValue": 0.75,
|
53
|
+
"liquidationThreshold": 0.78
|
54
|
+
},
|
55
|
+
"0x76fb31fb4af56892a25e32cfc43de717950c9278": {
|
56
|
+
"tToken": "0xf329e36c7bf6e5e86ce2150875a84ce77f477375",
|
57
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
58
|
+
"dToken": "0xe80761ea617f66f96274ea5e8c37f03960ecc679",
|
59
|
+
"loanToValue": 0.63,
|
60
|
+
"liquidationThreshold": 0.7
|
61
|
+
},
|
62
|
+
"0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9": {
|
63
|
+
"tToken": "0x6d80113e533a2c0fe82eabd35f1875dcea89ea97",
|
64
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
65
|
+
"dToken": "0x4a1c3ad6ed28a636ee1751c69071f6be75deb8b8",
|
66
|
+
"loanToValue": 0.0,
|
67
|
+
"liquidationThreshold": 0.7
|
68
|
+
},
|
69
|
+
"0x4200000000000000000000000000000000000042": {
|
70
|
+
"tToken": "0x513c7e3a9c69ca3e22550ef58ac1c0088e918fff",
|
71
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
72
|
+
"dToken": "0x77ca01483f379e58174739308945f044e1a764dc",
|
73
|
+
"loanToValue": 0.58,
|
74
|
+
"liquidationThreshold": 0.63
|
75
|
+
},
|
76
|
+
"0x1f32b1c2345538c0c6f582fcb022739c4a194ebb": {
|
77
|
+
"tToken": "0xc45a479877e1e9dfe9fcd4056c699575a1045daa",
|
78
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
79
|
+
"dToken": "0x34e2ed44ef7466d5f9e0b782b5c08b57475e7907",
|
80
|
+
"loanToValue": 0.75,
|
81
|
+
"liquidationThreshold": 0.79
|
82
|
+
},
|
83
|
+
"0xc40f949f8a4e094d1b49a23ea9241d289b7b2819": {
|
84
|
+
"tToken": "0x8eb270e296023e9d92081fdf967ddd7878724424",
|
85
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
86
|
+
"dToken": "0xce186f6cccb0c955445bb9d10c59cae488fea559",
|
87
|
+
"loanToValue": 0.0,
|
88
|
+
"liquidationThreshold": 0.0
|
89
|
+
},
|
90
|
+
"0xdfa46478f9e5ea86d57387849598dbfb2e964b02": {
|
91
|
+
"tToken": "0x8ffdf2de812095b1d19cb146e4c004587c0a0692",
|
92
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
93
|
+
"dToken": "0xa8669021776bc142dfca87c21b4a52595bcbb40a",
|
94
|
+
"loanToValue": 0.0,
|
95
|
+
"liquidationThreshold": 0.01
|
96
|
+
},
|
97
|
+
"0x9bcef72be871e61ed4fbbc7630889bee758eb81d": {
|
98
|
+
"tToken": "0x724dc807b04555b71ed48a6896b6f41593b8c637",
|
99
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
100
|
+
"dToken": "0xf611aeb5013fd2c0511c9cd55c7dc5c1140741a6",
|
101
|
+
"loanToValue": 0.69,
|
102
|
+
"liquidationThreshold": 0.74
|
103
|
+
},
|
104
|
+
"0x0b2c639c533813f4aa9d7837caf62653d097ff85": {
|
105
|
+
"tToken": "0x38d693ce1df5aadf7bc62595a37d667ad57922e5",
|
106
|
+
"sdToken": "0xd94112b5b62d53c9402e7a60289c6810def1dc9b",
|
107
|
+
"dToken": "0x5d557b07776d12967914379c71a1310e917c7555",
|
108
|
+
"loanToValue": 0.75,
|
109
|
+
"liquidationThreshold": 0.78
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
@@ -35,7 +35,7 @@ class LiqeeStateService(CompoundStateService):
|
|
35
35
|
self.state_service = state_service
|
36
36
|
self.lending_data_abi = LIQEE_LENDING_DATA_ABI
|
37
37
|
self.controller_abi = LIQEE_CONTROLLER_ABI
|
38
|
-
self.
|
38
|
+
self.liqee_token_abi = LIQEE_TOKEN_ABI
|
39
39
|
|
40
40
|
# BASIC FUNCTIONS
|
41
41
|
def get_service_info(self):
|
@@ -60,7 +60,7 @@ class LiqeeStateService(CompoundStateService):
|
|
60
60
|
reserves_info = {}
|
61
61
|
for token in ctokens:
|
62
62
|
address = _w3.to_checksum_address(token)
|
63
|
-
contract = _w3.eth.contract(address=address, abi=self.
|
63
|
+
contract = _w3.eth.contract(address=address, abi=self.liqee_token_abi)
|
64
64
|
underlying = contract.functions.underlying().call(block_identifier=block_number)
|
65
65
|
liquidation_threshold = comptroller_contract.functions.markets(address).call(block_identifier=block_number)
|
66
66
|
liquidation_threshold = liquidation_threshold[0] / 10 ** 18
|
@@ -55,6 +55,8 @@ class OnyxStateService(CompoundStateService):
|
|
55
55
|
# if token in [ContractAddresses.LUNA.lower(), ContractAddresses.UST.lower(), ContractAddresses.LUNA,
|
56
56
|
# ContractAddresses.UST]:
|
57
57
|
# continue
|
58
|
+
if token == '0x1933f1183c421d44d531ed40a5d2445f6a91646d':
|
59
|
+
continue
|
58
60
|
ctokens.append(token)
|
59
61
|
|
60
62
|
lens_contract = _w3.eth.contract(
|
@@ -78,7 +80,6 @@ class OnyxStateService(CompoundStateService):
|
|
78
80
|
"liquidationThreshold": lt,
|
79
81
|
"loanToValue": ltv
|
80
82
|
}
|
81
|
-
|
82
83
|
return reserves_info
|
83
84
|
|
84
85
|
# PROTOCOL APY
|
@@ -0,0 +1,313 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
from web3 import Web3
|
4
|
+
|
5
|
+
from defi_services.abis.lending.seamless.seamless_incentive import SEAMLESS_INCENTIVE_ABI
|
6
|
+
from defi_services.abis.lending.seamless.seamless_lending_pool import SEAMLESS_LENDING_POOL_ABI
|
7
|
+
from defi_services.abis.lending.seamless.seamless_oracle import SEAMLESS_ORACLE_ABI
|
8
|
+
from defi_services.abis.token.erc20_abi import ERC20_ABI
|
9
|
+
from defi_services.constants.chain_constant import Chain
|
10
|
+
from defi_services.constants.db_constant import DBConst
|
11
|
+
from defi_services.constants.entities.lending_constant import Lending
|
12
|
+
from defi_services.constants.network_constants import NATIVE_TOKEN
|
13
|
+
from defi_services.constants.time_constant import TimeConstants
|
14
|
+
from defi_services.jobs.queriers.state_querier import StateQuerier
|
15
|
+
from defi_services.services.lending.aave_v2_services import AaveV2StateService
|
16
|
+
from defi_services.services.lending.lending_info.base.seamless_base import SEAMLESS_BASE
|
17
|
+
|
18
|
+
logger = logging.getLogger("Seamless Lending Pool State Service")
|
19
|
+
|
20
|
+
|
21
|
+
class SeamlessInfo:
|
22
|
+
mapping = {
|
23
|
+
Chain.base: SEAMLESS_BASE
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
class SeamlessStateService(AaveV2StateService):
|
28
|
+
def __init__(self, state_service: StateQuerier, chain_id: str = Chain.base):
|
29
|
+
super().__init__(state_service, chain_id)
|
30
|
+
self.name = f"{chain_id}_{Lending.seamless}"
|
31
|
+
self.chain_id = chain_id
|
32
|
+
self.pool_info = SeamlessInfo.mapping.get(chain_id)
|
33
|
+
self.lending_abi = SEAMLESS_LENDING_POOL_ABI
|
34
|
+
self.incentive_abi = SEAMLESS_INCENTIVE_ABI
|
35
|
+
self.oracle_abi = SEAMLESS_ORACLE_ABI
|
36
|
+
self.state_service = state_service
|
37
|
+
|
38
|
+
def get_service_info(self):
|
39
|
+
info = {
|
40
|
+
Lending.seamless: {
|
41
|
+
"chain_id": self.chain_id,
|
42
|
+
"type": "lending",
|
43
|
+
"protocol_info": self.pool_info
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return info
|
47
|
+
|
48
|
+
def get_dapp_asset_info(self, block_number: int = 'latest'):
|
49
|
+
_w3 = self.state_service.get_w3()
|
50
|
+
pool_address = self.pool_info.get("address")
|
51
|
+
pool_contract = _w3.eth.contract(address=_w3.to_checksum_address(pool_address), abi=self.lending_abi)
|
52
|
+
reserve_list = pool_contract.functions.getReservesList().call(block_identifier=block_number)
|
53
|
+
reserves_info = {}
|
54
|
+
for token in reserve_list:
|
55
|
+
token = token.lower()
|
56
|
+
reserve_data = pool_contract.functions.getReserveData(
|
57
|
+
_w3.to_checksum_address(token)).call(block_identifier=block_number)
|
58
|
+
reserves_info[token] = {}
|
59
|
+
reserves_info[token]["tToken"] = reserve_data[8].lower()
|
60
|
+
reserves_info[token]["sdToken"] = reserve_data[9].lower()
|
61
|
+
reserves_info[token]["dToken"] = reserve_data[10].lower()
|
62
|
+
|
63
|
+
risk_param = bin(reserve_data[0][0])[2:]
|
64
|
+
reserves_info[token]["loanToValue"] = int(risk_param[-15:], 2) / 10 ** 4
|
65
|
+
reserves_info[token]["liquidationThreshold"] = int(risk_param[-31:-16], 2) / 10 ** 4
|
66
|
+
|
67
|
+
return reserves_info
|
68
|
+
|
69
|
+
# CALCULATE APY LENDING POOL
|
70
|
+
def get_reserve_tokens_metadata(
|
71
|
+
self,
|
72
|
+
decoded_data: dict,
|
73
|
+
reserves_info: dict,
|
74
|
+
block_number: int = "latest"
|
75
|
+
):
|
76
|
+
reserve_tokens_info = []
|
77
|
+
for token_address, reserve_info in reserves_info.items():
|
78
|
+
get_reserve_data_call_id = f'getReserveData_{self.name}_{token_address}_{block_number}'.lower()
|
79
|
+
reserve_data = decoded_data.get(get_reserve_data_call_id)
|
80
|
+
atoken = reserve_data[8].lower()
|
81
|
+
debt_token = reserve_data[10].lower()
|
82
|
+
decimals_call_id = f"decimals_{token_address}_{block_number}".lower()
|
83
|
+
atoken_total_supply_key = f'totalSupply_{atoken}_{block_number}'.lower()
|
84
|
+
debt_token_total_supply_key = f'totalSupply_{debt_token}_{block_number}'.lower()
|
85
|
+
sdebt_token = reserve_data[9].lower()
|
86
|
+
|
87
|
+
|
88
|
+
data = {
|
89
|
+
'underlying': token_address,
|
90
|
+
'underlying_decimals': decoded_data.get(decimals_call_id),
|
91
|
+
'a_token_supply': decoded_data.get(atoken_total_supply_key),
|
92
|
+
'd_token_supply': decoded_data.get(debt_token_total_supply_key),
|
93
|
+
|
94
|
+
'supply_apy': reserve_data[2],
|
95
|
+
'borrow_apy': reserve_data[4],
|
96
|
+
|
97
|
+
}
|
98
|
+
if sdebt_token != NATIVE_TOKEN:
|
99
|
+
sdebt_token_total_supply_key = f'totalSupply_{sdebt_token}_{block_number}'.lower()
|
100
|
+
data['sd_token_supply'] = decoded_data.get(sdebt_token_total_supply_key)
|
101
|
+
data['stable_borrow_apy'] = reserve_data[5]
|
102
|
+
else:
|
103
|
+
data['sd_token_supply'] = 0
|
104
|
+
data['stable_borrow_apy'] = 0
|
105
|
+
|
106
|
+
reserve_tokens_info.append(data)
|
107
|
+
|
108
|
+
return reserve_tokens_info
|
109
|
+
|
110
|
+
def get_apy_lending_pool_function_info_deprecated(
|
111
|
+
self,
|
112
|
+
reserves_info: dict,
|
113
|
+
block_number: int = "latest",
|
114
|
+
):
|
115
|
+
rpc_calls = {}
|
116
|
+
reward_tokens = self.pool_info.get("rewardTokensList")
|
117
|
+
for token_address, value in reserves_info.items():
|
118
|
+
reserve_key = f"getReserveData_{self.name}_{token_address}_{block_number}".lower()
|
119
|
+
atoken_total_supply_key = f'totalSupply_{value["tToken"]}_{block_number}'.lower()
|
120
|
+
debt_token_total_supply_key = f'totalSupply_{value["dToken"]}_{block_number}'.lower()
|
121
|
+
decimals_key = f"decimals_{token_address}_{block_number}".lower()
|
122
|
+
for reward_token in reward_tokens:
|
123
|
+
atoken_assets_key = f"getRewardsData_{value['tToken']}_{reward_token}_{block_number}".lower()
|
124
|
+
debt_token_assets_key = f"getRewardsData_{value['dToken']}_{reward_token}_{block_number}".lower()
|
125
|
+
rpc_calls[atoken_assets_key] = self.get_function_incentive_info(
|
126
|
+
"getRewardsData", [value['tToken'], reward_token], block_number)
|
127
|
+
rpc_calls[debt_token_assets_key] = self.get_function_incentive_info(
|
128
|
+
"getRewardsData", [value['dToken'], reward_token], block_number)
|
129
|
+
if value['sdToken'] != NATIVE_TOKEN:
|
130
|
+
sdebt_token_assets_key = f"getRewardsData_{value['sdToken']}_{reward_token}_{block_number}".lower()
|
131
|
+
rpc_calls[sdebt_token_assets_key] = self.get_function_incentive_info(
|
132
|
+
"getRewardsData", [value['sdToken'], reward_token], block_number)
|
133
|
+
|
134
|
+
rpc_calls[reserve_key] = self.get_function_lending_pool_info("getReserveData", [token_address])
|
135
|
+
rpc_calls[atoken_total_supply_key] = self.state_service.get_function_info(
|
136
|
+
value["tToken"], ERC20_ABI, "totalSupply", block_number=block_number)
|
137
|
+
rpc_calls[debt_token_total_supply_key] = self.state_service.get_function_info(
|
138
|
+
value["dToken"], ERC20_ABI, "totalSupply", block_number=block_number)
|
139
|
+
rpc_calls[decimals_key] = self.state_service.get_function_info(
|
140
|
+
token_address, ERC20_ABI, "decimals", block_number=block_number)
|
141
|
+
|
142
|
+
if value['sdToken'] != NATIVE_TOKEN:
|
143
|
+
sdebt_token_total_supply_key = f'totalSupply_{value["sdToken"]}_{block_number}'.lower()
|
144
|
+
rpc_calls[sdebt_token_total_supply_key] = self.state_service.get_function_info(
|
145
|
+
value["sdToken"], ERC20_ABI, "totalSupply", block_number=block_number)
|
146
|
+
|
147
|
+
return rpc_calls
|
148
|
+
|
149
|
+
def get_apy_lending_pool_deprecated(
|
150
|
+
self,
|
151
|
+
atokens: dict,
|
152
|
+
debt_tokens: dict,
|
153
|
+
decimals: dict,
|
154
|
+
reserves_info: dict,
|
155
|
+
asset_data_tokens: dict,
|
156
|
+
total_supply_tokens: dict,
|
157
|
+
interest_rate: dict,
|
158
|
+
token_prices: dict,
|
159
|
+
pool_token_price: float,
|
160
|
+
pool_decimals: int = 18,
|
161
|
+
):
|
162
|
+
reward_tokens = self.pool_info.get("rewardTokensList")
|
163
|
+
for token_address in reserves_info:
|
164
|
+
atoken = atokens.get(token_address)
|
165
|
+
debt_token = debt_tokens.get(token_address)
|
166
|
+
decimal = decimals.get(token_address)
|
167
|
+
total_supply_t = total_supply_tokens.get(atoken, 0)
|
168
|
+
total_supply_d = total_supply_tokens.get(debt_token, 0)
|
169
|
+
# update deposit, borrow apy
|
170
|
+
total_supply_t = total_supply_t / 10 ** decimal
|
171
|
+
total_supply_d = total_supply_d / 10 ** decimal
|
172
|
+
token_price = token_prices.get(token_address)
|
173
|
+
interest_rate[token_address].update({
|
174
|
+
"utilization": total_supply_d / total_supply_t,
|
175
|
+
})
|
176
|
+
total_supply_t_in_usd = total_supply_t * token_price
|
177
|
+
total_supply_d_in_usd = total_supply_d * token_price
|
178
|
+
if reward_tokens:
|
179
|
+
interest_rate[token_address][DBConst.reward_deposit_apy] = {}
|
180
|
+
interest_rate[token_address][DBConst.reward_borrow_apy] = {}
|
181
|
+
asset_data_t = asset_data_tokens.get(atoken)
|
182
|
+
asset_data_d = asset_data_tokens.get(debt_token)
|
183
|
+
# update deposit, borrow apy
|
184
|
+
for reward_address in reward_tokens:
|
185
|
+
eps_t = asset_data_t[reward_address][1] / 10 ** 18
|
186
|
+
eps_d = asset_data_d[reward_address][1] / 10 ** 18
|
187
|
+
if total_supply_t:
|
188
|
+
deposit_apr = eps_t * TimeConstants.A_YEAR * pool_token_price / (
|
189
|
+
total_supply_t * token_price)
|
190
|
+
else:
|
191
|
+
deposit_apr = 0
|
192
|
+
if total_supply_d:
|
193
|
+
borrow_apr = eps_d * TimeConstants.A_YEAR * pool_token_price / (
|
194
|
+
total_supply_d * token_price)
|
195
|
+
else:
|
196
|
+
borrow_apr = 0
|
197
|
+
interest_rate[token_address][DBConst.reward_deposit_apy].update({
|
198
|
+
DBConst.reward_borrow_apy: deposit_apr}
|
199
|
+
)
|
200
|
+
interest_rate[token_address][DBConst.reward_borrow_apy].update({
|
201
|
+
reward_address: borrow_apr}
|
202
|
+
)
|
203
|
+
# update liquidity
|
204
|
+
liquidity_log = {
|
205
|
+
'total_borrow': {
|
206
|
+
DBConst.amount: total_supply_d,
|
207
|
+
DBConst.value_in_usd: total_supply_d_in_usd},
|
208
|
+
'total_deposit': {
|
209
|
+
DBConst.amount: total_supply_t,
|
210
|
+
DBConst.value_in_usd: total_supply_t_in_usd}
|
211
|
+
}
|
212
|
+
interest_rate[token_address].update({DBConst.liquidity_change_logs: liquidity_log})
|
213
|
+
|
214
|
+
return interest_rate
|
215
|
+
|
216
|
+
def calculate_apy_lending_pool_function_call_deprecated(
|
217
|
+
self,
|
218
|
+
reserves_info: dict,
|
219
|
+
decoded_data: dict,
|
220
|
+
token_prices: dict,
|
221
|
+
pool_token_price: float,
|
222
|
+
pool_decimals: int = 18,
|
223
|
+
block_number: int = 'latest',
|
224
|
+
):
|
225
|
+
reserves_data = {}
|
226
|
+
for token in reserves_info:
|
227
|
+
get_reserve_data_call_id = f'getReserveData_{self.name}_{token}_{block_number}'.lower()
|
228
|
+
reserves_data[token.lower()] = decoded_data.get(get_reserve_data_call_id)
|
229
|
+
reward_tokens = self.pool_info.get("rewardTokensList")
|
230
|
+
interest_rate, atokens, debt_tokens, sdebt_tokens, decimals, asset_data_tokens = {}, {}, {}, {}, {}, {}
|
231
|
+
total_supply_tokens = {}
|
232
|
+
for token_address in reserves_info:
|
233
|
+
lower_address = token_address.lower()
|
234
|
+
reserve_data = reserves_data[lower_address]
|
235
|
+
interest_rate[lower_address] = {
|
236
|
+
'deposit_apy': float(reserve_data[3]) / 10 ** 27,
|
237
|
+
'borrow_apy': float(reserve_data[4]) / 10 ** 27,
|
238
|
+
'stable_borrow_apy': float(reserve_data[5]) / 10 ** 27}
|
239
|
+
atoken = reserve_data[7].lower()
|
240
|
+
sdebt_token = reserve_data[8].lower()
|
241
|
+
debt_token = reserve_data[9].lower()
|
242
|
+
decimals_call_id = f"decimals_{token_address}_{block_number}".lower()
|
243
|
+
atoken_total_supply_key = f'totalSupply_{atoken}_{block_number}'.lower()
|
244
|
+
debt_token_total_supply_key = f'totalSupply_{debt_token}_{block_number}'.lower()
|
245
|
+
asset_data_tokens[atoken] = {}
|
246
|
+
asset_data_tokens[debt_token] = {}
|
247
|
+
if sdebt_token != NATIVE_TOKEN:
|
248
|
+
asset_data_tokens[sdebt_token] = {}
|
249
|
+
|
250
|
+
total_supply_tokens[atoken] = {}
|
251
|
+
for reward_token in reward_tokens:
|
252
|
+
atoken_assets_key = f"getRewardsData_{atoken}_{reward_token}_{block_number}".lower()
|
253
|
+
debt_token_assets_key = f"getRewardsData_{debt_token}_{reward_token}_{block_number}".lower()
|
254
|
+
asset_data_tokens[atoken][reward_token] = decoded_data.get(atoken_assets_key)
|
255
|
+
asset_data_tokens[debt_token][reward_token] = decoded_data.get(debt_token_assets_key)
|
256
|
+
total_supply_tokens[atoken][reward_token] = decoded_data.get(atoken_total_supply_key)
|
257
|
+
if sdebt_token != NATIVE_TOKEN:
|
258
|
+
sdebt_token_assets_key = f"getRewardsData_{sdebt_tokens}_{reward_token}_{block_number}".lower()
|
259
|
+
asset_data_tokens[sdebt_token][reward_token] = decoded_data.get(sdebt_token_assets_key)
|
260
|
+
|
261
|
+
atokens[lower_address] = atoken
|
262
|
+
debt_tokens[lower_address] = debt_token
|
263
|
+
sdebt_tokens[lower_address] = sdebt_token
|
264
|
+
decimals[lower_address] = decoded_data.get(decimals_call_id)
|
265
|
+
total_supply_tokens[debt_token] = decoded_data.get(debt_token_total_supply_key)
|
266
|
+
if sdebt_token != NATIVE_TOKEN:
|
267
|
+
sdebt_token_total_supply_key = f'totalSupply_{sdebt_token}_{block_number}'.lower()
|
268
|
+
total_supply_tokens[sdebt_token] = decoded_data.get(sdebt_token_total_supply_key)
|
269
|
+
|
270
|
+
asset_price_key = f"getAssetsPrices_{self.name}_{block_number}".lower()
|
271
|
+
if not token_prices and asset_price_key in decoded_data:
|
272
|
+
token_prices = {}
|
273
|
+
prices = decoded_data.get(asset_price_key)
|
274
|
+
for pos in range(len(reserves_info.keys())):
|
275
|
+
token_prices[reserves_info[pos].lower()] = prices[pos] / 10 ** pool_decimals
|
276
|
+
|
277
|
+
data = self.get_apy_lending_pool_deprecated(
|
278
|
+
atokens, debt_tokens, decimals, reserves_info, asset_data_tokens, total_supply_tokens, interest_rate,
|
279
|
+
token_prices, pool_token_price, pool_decimals
|
280
|
+
)
|
281
|
+
|
282
|
+
return data
|
283
|
+
|
284
|
+
# REWARDS BALANCE
|
285
|
+
def get_rewards_balance_function_info(
|
286
|
+
self,
|
287
|
+
wallet,
|
288
|
+
reserves_info: dict = None,
|
289
|
+
block_number: int = "latest"
|
290
|
+
):
|
291
|
+
rpc_calls = {}
|
292
|
+
reward_tokens = self.pool_info.get("rewardTokensList")
|
293
|
+
for reward_token in reward_tokens:
|
294
|
+
decimals_call_id = f"decimals_{reward_token}_{block_number}".lower()
|
295
|
+
rpc_calls[decimals_call_id] = self.state_service.get_function_info(
|
296
|
+
reward_token, ERC20_ABI, "decimals", block_number=block_number)
|
297
|
+
tokens = []
|
298
|
+
for key, value in reserves_info.items():
|
299
|
+
tokens += [Web3.to_checksum_address(value["tToken"]), Web3.to_checksum_address(value["dToken"])]
|
300
|
+
key = f"getAllUserRewards_{self.name}_{wallet}_{block_number}".lower()
|
301
|
+
rpc_calls[key] = self.get_function_incentive_info("getAllUserRewards", [tokens, Web3.to_checksum_address(wallet)], block_number)
|
302
|
+
return rpc_calls
|
303
|
+
|
304
|
+
def calculate_rewards_balance(
|
305
|
+
self, wallet: str, reserves_info: dict, decoded_data: dict, block_number: int = "latest"):
|
306
|
+
key = f"getAllUserRewards_{self.name}_{wallet}_{block_number}".lower()
|
307
|
+
rewards = decoded_data.get(key)
|
308
|
+
result = dict(zip(*rewards))
|
309
|
+
for key, value in result.items():
|
310
|
+
decimals_call_id = f"decimals_{key}_{block_number}".lower()
|
311
|
+
value /= 10 ** decoded_data.get(decimals_call_id, 18)
|
312
|
+
result[key] = {"amount": value}
|
313
|
+
return result
|