defi-state-querier 0.5.18__py3-none-any.whl → 0.5.20__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.
Files changed (29) hide show
  1. defi_services/__init__.py +1 -1
  2. defi_services/constants/chain_constant.py +6 -1
  3. defi_services/constants/network_constants.py +20 -361
  4. defi_services/constants/token_constant.py +3 -1
  5. defi_services/jobs/processors/cosmos_state_processor.py +3 -2
  6. defi_services/jobs/processors/ton_state_processor.py +4 -3
  7. defi_services/jobs/tcv.py +93 -59
  8. defi_services/services/lending/aave_v2_services.py +3 -3
  9. defi_services/services/lending/granary_services.py +3 -3
  10. defi_services/services/lending/morpho_aave_v2_services.py +3 -3
  11. defi_services/services/lending/morpho_aave_v3_services.py +2 -2
  12. defi_services/services/lending/trava_services.py +2 -2
  13. defi_services/services/lending/uwu_services.py +3 -3
  14. defi_services/services/lending/valas_services.py +2 -2
  15. defi_services/services/multicall/multicall_v2.py +0 -317
  16. defi_services/services/vault/tcv_vault_services.py +1 -2
  17. defi_services/services/vault/vault_info/arbitrum/tcv_arb.py +6 -6
  18. {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.20.dist-info}/METADATA +1 -1
  19. {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.20.dist-info}/RECORD +29 -29
  20. /defi_services/abis/lending/{aave_v2_and_forlks → aave_v2_and_forks}/__init__.py +0 -0
  21. /defi_services/abis/lending/{aave_v2_and_forlks → aave_v2_and_forks}/aave_v2_event_abi.py +0 -0
  22. /defi_services/abis/lending/{aave_v2_and_forlks → aave_v2_and_forks}/aave_v2_incentives_abi.py +0 -0
  23. /defi_services/abis/lending/{aave_v2_and_forlks → aave_v2_and_forks}/lending_pool_abi.py +0 -0
  24. /defi_services/abis/lending/{aave_v2_and_forlks → aave_v2_and_forks}/oracle_abi.py +0 -0
  25. /defi_services/abis/lending/{aave_v2_and_forlks → aave_v2_and_forks}/staked_incentives_abi.py +0 -0
  26. /defi_services/abis/lending/{aave_v2_and_forlks → aave_v2_and_forks}/uwu_incentives_abi.py +0 -0
  27. {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.20.dist-info}/LICENSE +0 -0
  28. {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.20.dist-info}/WHEEL +0 -0
  29. {defi_state_querier-0.5.18.dist-info → defi_state_querier-0.5.20.dist-info}/top_level.txt +0 -0
defi_services/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.5.18"
1
+ __version__ = "0.5.20"
@@ -30,7 +30,12 @@ class Chain:
30
30
  moonriver = '0x505'
31
31
  blast = '0xee'
32
32
  oasis_sapphire = '0x5afe'
33
- zeta = '0x1b58'
33
+ zetachain = '0x1b58'
34
+ zksync = '0x144'
35
+ oraichain = 'orai'
36
+ bitcoin = 'bitcoin'
37
+ cosmos = 'cosmos'
38
+ ton = 'ton'
34
39
 
35
40
  native_decimals = {
36
41
  tron: 6,
@@ -1,8 +1,5 @@
1
- import os
2
1
 
3
- import dotenv
4
-
5
- dotenv.load_dotenv()
2
+ from defi_services.constants.chain_constant import Chain
6
3
 
7
4
  POLYGON_AAVE_ADDRESS = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf'
8
5
  ETHEREUM_AAVE_ADDRESS = '0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'
@@ -21,353 +18,18 @@ FTM_GEIST_ADDRESS = '0x9fad24f572045c7869117160a571b2e50b10d068'
21
18
  ETH_COMPOUND_ADDRESS = '0x3d9819210a31b4961b30ef54be2aed79b9c9cd3b'
22
19
  ETH_CREAM_ADDRESS = ''
23
20
 
24
-
25
- class Chains:
26
- bsc = '0x38'
27
- ethereum = '0x1'
28
- fantom = '0xfa'
29
- polygon = '0x89'
30
- arbitrum = '0xa4b1'
31
- optimism = '0xa'
32
- avalanche = '0xa86a'
33
- tron = '0x2b6653dc'
34
- cronos = '0x19'
35
- solana = 'solana'
36
- polkadot = 'polkadot'
37
- bitcoin = 'bitcoin'
38
- cosmos = 'cosmos'
39
- base = '0x2105'
40
- kava = '0x8ae'
41
- gnosis = '0x64'
42
- klaytn = '0x2019'
43
- mantle = '0x1388'
44
- celo = '0xa4ec'
45
- moonbeam = '0x504'
46
- manta = '0xa9'
47
- pulse = '0x171'
48
- rootstock = '0x1e'
49
- astar = '0x250'
50
- metis = '0x440'
51
- canto = '0x1e14'
52
- heco = '0x80'
53
- linea = '0xe708'
54
- okc = '0x42'
55
- aurora = '0x4e454152'
56
- moonriver = '0x505'
57
- oasis_sapphire = '0x5afe'
58
- oasis_sapphire_testnet = '0x5aff'
59
- blast = '0xee'
60
- oraichain = 'orai'
61
- ton = 'ton'
62
-
63
- none_wrapped_token = [arbitrum, fantom, optimism]
64
- all = [
65
- bsc, ethereum, fantom, polygon, arbitrum, optimism,
66
- avalanche, tron, cronos, solana, polkadot, bitcoin, cosmos,
67
- oraichain, ton
68
- ]
69
-
70
- mapping = {
71
- 'bsc': bsc,
72
- 'ethereum': ethereum,
73
- 'fantom': fantom,
74
- 'polygon': polygon,
75
- 'arbitrum': arbitrum,
76
- 'optimism': optimism,
77
- 'avalanche': avalanche,
78
- 'tron': tron,
79
- 'cronos': cronos,
80
- 'solana': solana,
81
- 'polkadot': polkadot,
82
- 'oasis_sapphire': oasis_sapphire,
83
- 'oasis_sapphire_testnet': oasis_sapphire_testnet,
84
- 'ton': ton
85
- }
86
-
87
- names = {
88
- bsc: 'bsc',
89
- ethereum: "ethereum",
90
- fantom: 'fantom',
91
- polygon: 'polygon',
92
- arbitrum: 'arbitrum',
93
- optimism: 'optimism',
94
- avalanche: 'avalanche',
95
- tron: 'tron',
96
- cronos: 'cronos',
97
- solana: 'solana',
98
- polkadot: 'polkadot',
99
- oasis_sapphire: 'oasis_sapphire',
100
- oasis_sapphire_testnet: 'oasis_sapphire_testnet',
101
- ton: 'ton'
102
- }
103
-
104
- abi_mapping = {
105
- bsc: 'bep20_abi',
106
- ethereum: 'erc20_abi',
107
- fantom: 'erc20_abi',
108
- polygon: 'erc20_abi',
109
- arbitrum: 'erc20_abi',
110
- optimism: 'erc20_abi',
111
- avalanche: 'erc20_abi',
112
- tron: 'trc20_abi',
113
- cronos: 'crc20_abi'
114
- }
115
-
116
- block_time = {
117
- bsc: 3,
118
- ethereum: 12,
119
- fantom: 1,
120
- polygon: 2,
121
- arbitrum: 0.3,
122
- avalanche: 2,
123
- ton: 3
124
- }
125
- wrapped_native_token = {
126
- bsc: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
127
- ethereum: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
128
- polygon: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
129
- fantom: "0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83",
130
- arbitrum: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
131
- optimism: "0x4200000000000000000000000000000000000006",
132
- avalanche: "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
133
- tron: "0x891cdb91d149f23b1a45d9c5ca78a88d0cb44c18",
134
- cronos: "0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23",
135
- }
136
-
137
- evm = {
138
- ethereum: True, bsc: True, polygon: True, fantom: True,
139
- arbitrum: True, optimism: True, avalanche: True, tron: True, cronos: True,
140
- base: True, kava: True, gnosis: True, klaytn: True, mantle: True, celo: True, moonbeam: True, manta: True,
141
- pulse: True, rootstock: True, astar: True, metis: True, canto: True, heco: True, linea: True, okc: True,
142
- aurora: True, moonriver: True, oasis_sapphire: True, blast: True
143
- }
144
-
145
- def get_abi_name(self, chain_id):
146
- """Map chain_id with the corresponding abi key
147
- e.g.: '0x38' -> 'bep20_abi' or '0x1' -> 'erc20_abi'
148
- """
149
- return self.abi_mapping.get(chain_id, '')
150
-
151
-
152
- class ChainsAnkr:
153
- """Chain name for Ankr API"""
154
- bsc = '0x38'
155
- eth = '0x1'
156
- fantom = '0xfa'
157
- polygon = '0x89'
158
-
159
- reversed_mapping = {
160
- bsc: 'bsc',
161
- eth: 'eth',
162
- fantom: 'fantom',
163
- polygon: 'polygon',
164
- }
165
-
166
- def get_chain_name(self, chain_id):
167
- return self.reversed_mapping.get(chain_id)
168
-
169
-
170
- class Scans:
171
- mapping = {
172
- 'bscscan': Chains.bsc,
173
- 'etherscan': Chains.ethereum,
174
- 'ftmscan': Chains.fantom,
175
- 'polygonscan': Chains.polygon,
176
- 'arbiscan': Chains.arbitrum,
177
- 'optimistic': Chains.optimism,
178
- 'snowtrace': Chains.avalanche,
179
- 'cronoscan': Chains.cronos
180
- }
181
-
182
- api_keys = {
183
- Chains.bsc: 'GKRVTEQHSGWX335P21994DKNSTJVDYYXJ1',
184
- Chains.ethereum: 'YQVXQAJAYNS7AC48ZXS1NT45RKYRPY7P7E',
185
- Chains.fantom: 'Y85XY5DDDN4Z7C7Z4ZX8N62M5WET7D8NYC',
186
- Chains.polygon: 'EYADI5Q4VK4VF99KFEJURMVE9CNE54YEYW',
187
- Chains.arbitrum: 'BU5VN8872FE119RDX898MS5EZHE11FPZSC',
188
- Chains.optimism: '1JW9PDV2HZZI3WRFQRVGWUDD2T1RV8GWX3',
189
- Chains.avalanche: 'JWNM6Y5UA1499PWVA2T55MEH3TZDGAKJWJ',
190
- Chains.cronos: 'F5J6423D42PM21CDP61SUD6H7DE4FXH2DE'
191
- }
192
-
193
- api_bases = {
194
- Chains.bsc: 'https://api.bscscan.com/api',
195
- Chains.ethereum: 'https://api.etherscan.io/api',
196
- Chains.fantom: 'https://api.ftmscan.com/api',
197
- Chains.polygon: 'https://api.polygonscan.com/api',
198
- Chains.arbitrum: 'https://api.arbiscan.io/api',
199
- Chains.optimism: 'https://api-optimistic.etherscan.io/api',
200
- Chains.avalanche: 'https://api.snowtrace.io/api',
201
- Chains.cronos: 'https://cronoscan.com/api',
202
- Chains.ton: 'https://toncenter.com/api/'
203
- }
204
-
205
- scan_base_urls = {
206
- Chains.ethereum: 'https://etherscan.io/',
207
- Chains.bsc: 'https://bscscan.com/',
208
- Chains.fantom: 'https://ftmscan.com/',
209
- Chains.polygon: 'https://polygonscan.com/',
210
- Chains.arbitrum: 'https://arbiscan.io/',
211
- Chains.optimism: 'https://optimistic.etherscan.io/',
212
- Chains.avalanche: 'https://snowtrace.io/',
213
- Chains.cronos: 'https://cronoscan.com/',
214
- Chains.ton: 'https://toncenter.com/api/'
215
- }
216
-
217
- all_base_urls = {
218
- Chains.bsc: [
219
- 'https://bscscan.com/token',
220
- 'https://bscscan-com.translate.goog/token'
221
- ],
222
- Chains.polygon: [
223
- 'https://polygonscan.com/token',
224
- 'https://polygonscan-com.translate.goog/token'
225
- ],
226
- Chains.ethereum: [
227
- 'https://etherscan.io/token',
228
- 'https://etherscan-io.translate.goog/token',
229
- ],
230
- Chains.fantom: [
231
- 'https://ftmscan.com/token',
232
- 'https://ftmscan-com.translate.goog/token'
233
- ],
234
- Chains.arbitrum: [
235
- # 'https://arbiscan-io.translate.goog/token',
236
- 'https://arbiscan.io/token'
237
- ],
238
- Chains.optimism: [
239
- # 'https://optimistic-etherscan-io.translate.goog/token',
240
- 'https://optimistic.etherscan.io/token'
241
- ],
242
- # Chains.avalanche: [
243
- # 'https://snowtrace.io/token'
244
- # ],
245
- Chains.cronos: ['https://cronoscan.com/token']
246
- }
247
-
248
- gg_translate_suffix = '?_x_tr_sl=vi&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp'
249
-
250
-
251
- class Networks:
252
- bsc = 'bsc'
253
- ethereum = 'ethereum'
254
- fantom = 'fantom'
255
- polygon = 'polygon'
256
- arbitrum = 'arbitrum'
257
- optimism = 'optimism'
258
- avalanche = 'avalanche'
259
- tron = 'tron'
260
- cronos = 'cronos'
261
- solana = 'solana'
262
- polkadot = 'polkadot'
263
- oasis_sapphire = 'oasis_sapphire'
264
- oasis_sapphire_testnet = 'oasis_sapphire_testnet'
265
- cosmos = 'cosmos'
266
- oraichain = 'oraichain'
267
- ton = 'ton'
268
-
269
- providers = {
270
- bsc: os.getenv('BSC_PROVIDER_URI', 'https://bsc-dataseed1.binance.org/'),
271
- ethereum: os.getenv('ETHEREUM_PROVIDER_URI', 'https://rpc.ankr.com/eth'),
272
- fantom: os.getenv('FANTOM_PROVIDER_URI', 'https://rpc.ftm.tools/'),
273
- polygon: os.getenv('POLYGON_PROVIDER_URI', 'https://polygon-rpc.com'),
274
- arbitrum: os.getenv('ARBITRUM_PROVIDER_URI', 'https://endpoints.omniatech.io/v1/arbitrum/one/public'),
275
- optimism: os.getenv('OPTIMISM_PROVIDER_URI', 'https://rpc.ankr.com/optimism'),
276
- avalanche: os.getenv('AVALANCHE_PROVIDER_URI', 'https://rpc.ankr.com/avalanche'),
277
- tron: os.getenv('TRON_PROVIDER_URI', 'https://rpc.ankr.com/tron_jsonrpc'),
278
- cronos: os.getenv('CRONOS_PROVIDER_URI', 'https://evm.cronos.org/'),
279
- solana: os.getenv('SOLANA_PROVIDER_URI', 'https://crimson-multi-putty.solana-mainnet.quiknode.pro/997174ce6ab5cc9d42cb037e931d18ae1a98346a/'),
280
- polkadot: os.getenv('POLKADOT_PROVIDER_URI', 'https://late-yolo-diagram.dot-mainnet.quiknode.pro/51a1aaf2372854dfd211fca3ab375e5451222be4/'),
281
- oasis_sapphire: os.getenv('OASIS_SAPPHIRE_PROVIDER_URI'),
282
- oasis_sapphire_testnet: os.getenv('OASIS_SAPPHIRE_PROVIDER_URI'),
283
- ton: os.getenv('TON_PROVIDER_URI')
284
- }
285
-
286
- archive_node = {
287
- bsc: os.getenv('BSC_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/bsc'),
288
- ethereum: os.getenv('ETHEREUM_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/eth'),
289
- fantom: os.getenv('FANTOM_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/fantom'),
290
- polygon: os.getenv('POLYGON_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/polygon'),
291
- arbitrum: os.getenv('ARBITRUM_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/arbitrum'),
292
- optimism: os.getenv('OPTIMISM_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/optimism'),
293
- avalanche: os.getenv('AVALANCHE_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/avalanche'),
294
- tron: os.getenv('TRON_PROVIDER_ARCHIVE_URI', 'https://rpc.ankr.com/tron_jsonrpc'),
295
- cronos: os.getenv('CRONOS_PROVIDER_ARCHIVE_URI'),
296
- solana: os.getenv('SOLANA_PROVIDER_ARCHIVE_URI'),
297
- polkadot: os.getenv('POLKADOT_PROVIDER_ARCHIVE_URI'),
298
- oasis_sapphire: os.getenv('OASIS_SAPPHIRE_PROVIDER_ARCHIVE_URI'),
299
- oasis_sapphire_testnet: os.getenv('OASIS_SAPPHIRE_PROVIDER_ARCHIVE_URI'),
300
- ton: os.getenv('TON_PROVIDER_ARCHIVE_URI', 'https://toncenter.com/api/')
301
- }
302
-
303
-
304
- class DefiLlama:
305
- chains = {
306
- 'Binance': Chains.bsc,
307
- 'Ethereum': Chains.ethereum,
308
- 'Fantom': Chains.fantom,
309
- 'Polygon': Chains.polygon,
310
- 'Arbitrum': Chains.arbitrum,
311
- 'Optimism': Chains.optimism,
312
- 'Avalanche': Chains.avalanche,
313
- 'Tron': Chains.tron,
314
- 'Cronos': Chains.cronos,
315
- 'Solana': Chains.solana,
316
- 'Polkadot': Chains.polkadot,
317
- 'Base': Chains.base,
318
- 'Kava': Chains.kava,
319
- 'xDai': Chains.gnosis,
320
- 'Klaytn': Chains.klaytn,
321
- 'Mantle': Chains.mantle,
322
- 'Celo': Chains.celo,
323
- 'Moonbeam': Chains.moonbeam,
324
- 'Manta': Chains.manta,
325
- 'Pulse': Chains.pulse,
326
- 'RSK': Chains.rootstock,
327
- 'Astar': Chains.astar,
328
- 'Metis': Chains.metis,
329
- 'Canto': Chains.canto,
330
- 'Heco': Chains.heco,
331
- 'Linea': Chains.linea,
332
- 'OKExChain': Chains.okc,
333
- 'Aurora': Chains.aurora,
334
- 'Moonriver': Chains.moonriver,
335
- 'Oasis Sapphire': Chains.oasis_sapphire,
336
- 'Blast': Chains.blast,
337
- 'Oraichain': Chains.oraichain,
338
- 'Ton': Chains.ton
339
- }
340
-
341
-
342
- class Opensea:
343
- chains = {
344
- Chains.bsc: 'BSC',
345
- Chains.ethereum: 'ETHEREUM',
346
- Chains.polygon: 'MATIC',
347
- Chains.fantom: 'FANTOM',
348
- Chains.arbitrum: 'ARBITRUM',
349
- Chains.optimism: 'OPTIMISM',
350
- Chains.avalanche: 'AVALANCHE',
351
- Chains.tron: 'TRON',
352
- Chains.solana: 'SOLANA',
353
- Chains.base: 'BASE',
354
- Chains.klaytn: 'KLAYTN',
355
- Chains.ton: 'TON'
356
- }
357
-
358
-
359
21
  NATIVE_TOKEN = '0x0000000000000000000000000000000000000000'
360
22
 
361
23
  NATIVE_TOKENS = {
362
- Chains.bsc: '0x0000000000000000000000000000000000000000',
363
- Chains.ethereum: '0x0000000000000000000000000000000000000000',
364
- Chains.fantom: '0x0000000000000000000000000000000000000000',
365
- Chains.polygon: '0x0000000000000000000000000000000000000000',
366
- Chains.arbitrum: '0x0000000000000000000000000000000000000000',
367
- Chains.optimism: '0x0000000000000000000000000000000000000000',
368
- Chains.avalanche: '0x0000000000000000000000000000000000000000',
369
- Chains.tron: '0x0000000000000000000000000000000000000000',
370
- Chains.ton: 'EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'
24
+ Chain.bsc: '0x0000000000000000000000000000000000000000',
25
+ Chain.ethereum: '0x0000000000000000000000000000000000000000',
26
+ Chain.fantom: '0x0000000000000000000000000000000000000000',
27
+ Chain.polygon: '0x0000000000000000000000000000000000000000',
28
+ Chain.arbitrum: '0x0000000000000000000000000000000000000000',
29
+ Chain.optimism: '0x0000000000000000000000000000000000000000',
30
+ Chain.avalanche: '0x0000000000000000000000000000000000000000',
31
+ Chain.tron: '0x0000000000000000000000000000000000000000',
32
+ Chain.ton: 'EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'
371
33
  }
372
34
 
373
35
 
@@ -377,16 +39,16 @@ class MulticallContract:
377
39
  """
378
40
 
379
41
  on_chains_v3 = {
380
- Chains.ethereum: '0xca11bde05977b3631167028862be2a173976ca11',
381
- Chains.bsc: '0xca11bde05977b3631167028862be2a173976ca11',
382
- Chains.polygon: '0xca11bde05977b3631167028862be2a173976ca11',
383
- Chains.avalanche: '0xca11bde05977b3631167028862be2a173976ca11',
384
- Chains.fantom: '0xca11bde05977b3631167028862be2a173976ca11',
385
- Chains.arbitrum: '0xca11bde05977b3631167028862be2a173976ca11',
386
- Chains.optimism: '0xca11bde05977b3631167028862be2a173976ca11',
387
- Chains.tron: '0x32a4f47a74a6810bd0bf861cabab99656a75de9e',
388
- Chains.oasis_sapphire: '0xca11bde05977b3631167028862be2a173976ca11',
389
- Chains.oasis_sapphire_testnet: '0xca11bde05977b3631167028862be2a173976ca11'
42
+ Chain.ethereum: '0xca11bde05977b3631167028862be2a173976ca11',
43
+ Chain.bsc: '0xca11bde05977b3631167028862be2a173976ca11',
44
+ Chain.polygon: '0xca11bde05977b3631167028862be2a173976ca11',
45
+ Chain.avalanche: '0xca11bde05977b3631167028862be2a173976ca11',
46
+ Chain.fantom: '0xca11bde05977b3631167028862be2a173976ca11',
47
+ Chain.arbitrum: '0xca11bde05977b3631167028862be2a173976ca11',
48
+ Chain.optimism: '0xca11bde05977b3631167028862be2a173976ca11',
49
+ Chain.tron: '0x32a4f47a74a6810bd0bf861cabab99656a75de9e',
50
+ Chain.oasis_sapphire: '0xca11bde05977b3631167028862be2a173976ca11',
51
+ Chain.zksync: '0xf9cda624fbc7e059355ce98a31693d299facd963'
390
52
  }
391
53
 
392
54
  default_address = '0xca11bde05977b3631167028862be2a173976ca11'
@@ -394,6 +56,3 @@ class MulticallContract:
394
56
  @classmethod
395
57
  def get_multicall_contract(cls, chain_id):
396
58
  return cls.on_chains_v3.get(chain_id, cls.default_address)
397
-
398
-
399
- EMPTY_TOKEN_IMG = 'https://firebasestorage.googleapis.com/v0/b/token-c515a.appspot.com/o/tokens_v2%2Fempty-token.png?alt=media&token=2f9dfcc1-88a0-472c-a51f-4babc0c583f0'
@@ -45,7 +45,9 @@ class Token:
45
45
  Chain.aurora: '0xc9bdeed33cd01541e1eed10f90519d2c06fe3feb',
46
46
  Chain.moonriver: '0x98878b06940ae243284ca214f92bb71a2b032b8a',
47
47
  Chain.blast: '0x4300000000000000000000000000000000000004',
48
- Chain.oasis_sapphire: '0x8bc2b030b299964eefb5e1e0b36991352e56d2d3'
48
+ Chain.oasis_sapphire: '0x8bc2b030b299964eefb5e1e0b36991352e56d2d3',
49
+ Chain.zetachain: '0x5f0b1a82749cb4e2278ec87f8bf6b618dc71a8bf',
50
+ Chain.zksync: '0xf00dad97284d0c6f06dc4db3c32454d4292c6813'
49
51
  }
50
52
 
51
53
 
@@ -1,13 +1,14 @@
1
1
  import logging
2
2
 
3
+ from defi_services.constants.chain_constant import Chain
3
4
  from defi_services.constants.cosmos_decimals_constant import Denoms, MulticallContract
4
- from defi_services.constants.network_constants import Chains
5
5
  from defi_services.services.cosmos_token_services import CosmosTokenServices
6
6
 
7
7
  logger = logging.getLogger("CosmosStateProcessor")
8
8
 
9
+
9
10
  class CosmosStateProcessor:
10
- def __init__(self, lcd: str, rest_uri: str = None, chain_id: str = Chains.oraichain):
11
+ def __init__(self, lcd: str, rest_uri: str = None, chain_id: str = Chain.oraichain):
11
12
  self.chain_id = chain_id
12
13
  self.lcd = lcd
13
14
  self.rest_uri = rest_uri
@@ -1,18 +1,19 @@
1
1
  import logging
2
2
 
3
+ from defi_services.constants.chain_constant import Chain
3
4
  from defi_services.constants.ton_decimals_constant import TonTokens
4
- from defi_services.constants.network_constants import Chains, NATIVE_TOKENS
5
+ from defi_services.constants.network_constants import NATIVE_TOKENS
5
6
  from defi_services.jobs.queriers.ton_state_querier import TonStateQuerier
6
7
 
7
8
  logger = logging.getLogger("CosmosStateProcessor")
8
9
 
10
+
9
11
  class TonStateProcessor:
10
- def __init__(self, provider_uri: str, chain_id: str = Chains.ton):
12
+ def __init__(self, provider_uri: str, chain_id: str = Chain.ton):
11
13
  self.chain_id = chain_id
12
14
  self.provider_uri = provider_uri
13
15
  self.state_querier = TonStateQuerier(self.provider_uri)
14
16
 
15
-
16
17
  def get_token_balance(self, address, tokens):
17
18
  result = {}
18
19
  if NATIVE_TOKENS[self.chain_id] in tokens:
defi_services/jobs/tcv.py CHANGED
@@ -1,3 +1,5 @@
1
+ from collections import defaultdict
2
+
1
3
  from defi_services.constants.entities.dex_constant import Dex
2
4
  from defi_services.constants.query_constant import Query
3
5
  from defi_services.jobs.processors.state_processor import StateProcessor
@@ -13,98 +15,130 @@ class TCV:
13
15
  reserves_info,
14
16
  block_number: int = "latest",
15
17
  ):
18
+ lp_token_dict = {information["pool"]: information["poolInfo"] for information in reserves_info.values()}
19
+ tcv_liquidity_user, dex_lp_info = self.get_tcv_liquidity_user_and_lp_token_info(
20
+ wallet=address,
21
+ dex_protocol=Dex.uniswap_v3, lp_token_list=lp_token_dict,
22
+ block_number=block_number
23
+ )
24
+
25
+ tcv_nfts = {}
26
+ for vault_address, liquidity_info in tcv_liquidity_user.items():
27
+ # For optimize
28
+ liquidity_user = liquidity_info.get('liquidity_user')
29
+ if not liquidity_user:
30
+ liquidity_info.update({'tvl': {}})
31
+ continue
32
+
33
+ vault_nft = self.get_user_nft(vault_address, Dex.uniswap_v3, block_number=block_number)
34
+ tcv_nfts.update(vault_nft)
35
+
36
+ nfts_info = self.get_nfts_info(address, Dex.uniswap_v3, tcv_nfts, block_number=block_number)
37
+ user_balance = self.get_user_token_balance(address, Dex.uniswap_v3, nfts_info, dex_lp_info, block_number=block_number)
38
+
39
+ for token_id, info in user_balance.items():
40
+ pool_address = info['pool_address']
41
+ addresses = [vault_address_ for vault_address_, info in reserves_info.items() if info['pool'] == pool_address]
42
+ vault_address = addresses[0] if addresses else None
43
+
44
+ if (not vault_address) or (vault_address not in tcv_liquidity_user):
45
+ continue
46
+
47
+ if tcv_liquidity_user[vault_address].get('tvl') is None:
48
+ tcv_liquidity_user[vault_address]['tvl'] = defaultdict(lambda: 0)
49
+
50
+ tcv_liquidity_user[vault_address]['tvl'][info['token0']] += info['token0_amount']
51
+ tcv_liquidity_user[vault_address]['tvl'][info['token1']] += info['token1_amount']
52
+
53
+ return tcv_liquidity_user
54
+
55
+ def get_user_nft(self, wallet, dex_protocol, block_number: int = 'latest'):
16
56
  queries = [
17
57
  {
18
- "query_id": "tcv-vault",
19
- "entity_id": "tcv-vault",
20
- "query_type": Query.staking_reward
21
- },
22
- ]
23
- res = self.state_processor.run(address, queries, block_number)
24
- result = res[0].get("staking_reward")
25
- for token, information in reserves_info.items():
26
- pool = information.get("pool")
27
- lp_token_dict = {
28
- pool: reserves_info[token]["poolInfo"]
29
- }
30
- dex_lp_info = self.get_lp_token_info(token, Dex.uniswap_v3, lp_token_dict)
31
- token_nfts = self.get_user_nft(token, Dex.uniswap_v3)
32
- token_info = self.get_user_info(token, Dex.uniswap_v3, token_nfts)
33
- token_balance = self.get_user_token_balance(token, Dex.uniswap_v3, token_info, dex_lp_info)
34
- tvl = {}
35
- for balance_info in token_balance:
36
- for token_id, info in balance_info['dex_user_token_balance'].items():
37
- if info['token0'] not in tvl:
38
- tvl[info['token0']] = 0
39
- if info['token1'] not in tvl:
40
- tvl[info['token1']] = 0
41
- tvl[info['token0']] += info['token0_amount']
42
- tvl[info['token1']] += info['token1_amount']
43
- result[token].update({"tvl": tvl})
44
- return result
45
-
46
- def get_user_nft(self, wallet, dex_protocol):
47
- queries = [
48
- {
49
- 'query_id': f'{dex_protocol}_usernft',
58
+ 'query_id': f'{dex_protocol}_{Query.dex_user_nft}',
50
59
  "entity_id": dex_protocol,
51
60
  'query_type': Query.dex_user_nft
52
61
  }
53
62
  ]
54
63
 
55
- res = self.state_processor.run(wallet, queries, batch_size=100, max_workers=8, ignore_error=True)
56
- return res
64
+ res = self.state_processor.run(
65
+ wallet, queries, block_number=block_number,
66
+ batch_size=100, max_workers=8, ignore_error=True
67
+ )
68
+ user_nfts = res[0][Query.dex_user_nft]
69
+ return user_nfts
57
70
 
58
- def get_user_info(self, wallet, dex_protocol, user_nfts):
71
+ def get_nfts_info(self, wallet, dex_protocol, user_nfts, block_number: int = 'latest'):
59
72
  queries = [
60
73
  {
61
- 'query_id': f'{dex_protocol}_userinfo',
74
+ 'query_id': f'{dex_protocol}_{Query.dex_user_info}',
62
75
  "entity_id": dex_protocol,
63
76
  'query_type': Query.dex_user_info,
64
77
  'supplied_data': {
65
- 'user_data': user_nfts[0][Query.dex_user_nft],
78
+ 'user_data': user_nfts,
66
79
  }
67
80
  }
68
81
  ]
69
82
 
70
- res = self.state_processor.run(wallet, queries, batch_size=100, max_workers=8, ignore_error=True)
71
- return res
83
+ res = self.state_processor.run(
84
+ wallet, queries, block_number=block_number,
85
+ batch_size=100, max_workers=8, ignore_error=True
86
+ )
87
+ nfts_info = res[0][Query.dex_user_info]
88
+ return nfts_info
72
89
 
73
- def get_user_token_balance(self, wallet, dex_protocol, user_info, dex_lp_info):
90
+ def get_user_token_balance(self, wallet, dex_protocol, nfts_info, lp_token_info, block_number: int = 'latest'):
74
91
  queries = [
75
92
  {
76
- 'query_id': f'{dex_protocol}_usertokenbalance',
93
+ 'query_id': f'{dex_protocol}_{Query.dex_user_token_balance}',
77
94
  "entity_id": dex_protocol,
78
95
  'query_type': Query.dex_user_token_balance,
79
96
  'supplied_data': {
80
- 'user_data': user_info[0][Query.dex_user_info],
81
- 'lp_token_info': dex_lp_info[0][Query.lp_token_info]
82
-
97
+ 'user_data': nfts_info,
98
+ 'lp_token_info': lp_token_info
83
99
  }
84
100
  }
85
101
  ]
86
102
 
87
- res = self.state_processor.run(wallet, queries, batch_size=100, max_workers=8, ignore_error=True)
88
- return res
103
+ res = self.state_processor.run(
104
+ wallet, queries, block_number=block_number,
105
+ batch_size=100, max_workers=8, ignore_error=True
106
+ )
107
+ user_balance = res[0][Query.dex_user_token_balance]
108
+ return user_balance
89
109
 
90
- def get_lp_token_info(self, wallet, dex_protocol, lp_token_list):
110
+ def get_tcv_liquidity_user_and_lp_token_info(self, wallet, dex_protocol, lp_token_list, block_number: int = 'latest'):
91
111
  queries = [
92
112
  {
93
- 'query_id': f'{dex_protocol}_lptokeninfo',
94
- "entity_id": dex_protocol,
95
- 'query_type': Query.lp_token_info,
96
- 'supplied_data': {
97
- 'lp_token_info': lp_token_list}
113
+ "query_id": f"tcv-vault_{Query.staking_reward}",
114
+ "entity_id": "tcv-vault",
115
+ "query_type": Query.staking_reward
98
116
  },
99
117
  {
100
- 'query_id': f'{dex_protocol}_lptokenbalance',
118
+ 'query_id': f'{dex_protocol}_{Query.lp_token_info}',
101
119
  "entity_id": dex_protocol,
102
- 'query_type': Query.token_pair_balance,
120
+ 'query_type': Query.lp_token_info,
103
121
  'supplied_data': {
104
- 'lp_token_info': lp_token_list}
105
- }
122
+ 'lp_token_info': lp_token_list
123
+ }
124
+ },
125
+ # {
126
+ # 'query_id': f'{dex_protocol}_{Query.token_pair_balance}',
127
+ # "entity_id": dex_protocol,
128
+ # 'query_type': Query.token_pair_balance,
129
+ # 'supplied_data': {
130
+ # 'lp_token_info': lp_token_list
131
+ # }
132
+ # }
106
133
  ]
107
- res = self.state_processor.run(wallet, queries, batch_size=100, max_workers=8, ignore_error=True)
108
- return res
109
-
134
+ res = self.state_processor.run(
135
+ address=wallet, queries=queries,
136
+ block_number=block_number,
137
+ batch_size=100, max_workers=8,
138
+ ignore_error=True
139
+ )
140
+ data = {r['query_id']: r for r in res}
110
141
 
142
+ tcv_liquidity_user = data.get(f'tcv-vault_{Query.staking_reward}', {}).get(Query.staking_reward)
143
+ lp_token_info = data.get(f'{dex_protocol}_{Query.lp_token_info}', {}).get(Query.lp_token_info)
144
+ return tcv_liquidity_user, lp_token_info