blockapi 2.11.4__tar.gz → 2.11.6__tar.gz

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 (103) hide show
  1. {blockapi-2.11.4 → blockapi-2.11.6}/PKG-INFO +1 -1
  2. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_solana.py +105 -15
  3. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/debank.py +7 -2
  4. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/debank_maps.py +9 -1
  5. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/solana.py +56 -14
  6. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi.egg-info/PKG-INFO +1 -1
  7. {blockapi-2.11.4 → blockapi-2.11.6}/setup.py +1 -1
  8. {blockapi-2.11.4 → blockapi-2.11.6}/LICENSE.md +0 -0
  9. {blockapi-2.11.4 → blockapi-2.11.6}/README.md +0 -0
  10. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/__init__.py +0 -0
  11. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/services.py +0 -0
  12. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/__init__.py +0 -0
  13. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/test_blockapi.py +0 -0
  14. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/test_num.py +0 -0
  15. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/test_random_user_agent.py +0 -0
  16. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/__init__.py +0 -0
  17. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/__init__.py +0 -0
  18. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/conftest.py +0 -0
  19. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/covalenth/__init__.py +0 -0
  20. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/covalenth/test_ethereum.py +0 -0
  21. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/fake_sleep_provider.py +0 -0
  22. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/nft/__init__.py +0 -0
  23. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/nft/test_magic_eden.py +0 -0
  24. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/nft/test_opensea.py +0 -0
  25. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/nft/test_simple_hash.py +0 -0
  26. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/nft/test_unisat.py +0 -0
  27. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_bitaps_ltc.py +0 -0
  28. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_blockchain_info.py +0 -0
  29. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_blockchainos.py +0 -0
  30. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_blockchair_btc.py +0 -0
  31. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_blockchair_doge.py +0 -0
  32. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_blockchair_ltc.py +0 -0
  33. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_cosmos.py +0 -0
  34. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_ethplorer.py +0 -0
  35. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_haskoin.py +0 -0
  36. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_litecoinspace.py +0 -0
  37. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_multisources.py +0 -0
  38. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_optimistic_etherscan.py +0 -0
  39. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_subscan_polkadot.py +0 -0
  40. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_sui.py +0 -0
  41. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_terra.py +0 -0
  42. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_trezor_btc.py +0 -0
  43. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/api/test_trezor_zec.py +0 -0
  44. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/test_base.py +0 -0
  45. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/test_blockchain_api.py +0 -0
  46. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/test_blockchain_mapping.py +0 -0
  47. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/test_data.py +0 -0
  48. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/test_enumerate_classes.py +0 -0
  49. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/test_generic.py +0 -0
  50. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test/v2/test_models.py +0 -0
  51. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/test_data.py +0 -0
  52. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/utils/__init__.py +0 -0
  53. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/utils/address.py +0 -0
  54. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/utils/datetime.py +0 -0
  55. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/utils/num.py +0 -0
  56. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/utils/user_agent.py +0 -0
  57. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/__init__.py +0 -0
  58. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/__init__.py +0 -0
  59. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/bitaps.py +0 -0
  60. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/blockchain_info.py +0 -0
  61. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/blockchainos.py +0 -0
  62. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/blockchair.py +0 -0
  63. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/cosmos.py +0 -0
  64. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/__init__.py +0 -0
  65. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/arbitrum.py +0 -0
  66. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/astar.py +0 -0
  67. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/avalanche.py +0 -0
  68. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/axie.py +0 -0
  69. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/base.py +0 -0
  70. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/binance_smart_chain.py +0 -0
  71. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/ethereum.py +0 -0
  72. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/fantom.py +0 -0
  73. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/heco.py +0 -0
  74. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/iotex.py +0 -0
  75. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/klaytn.py +0 -0
  76. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/moonbeam.py +0 -0
  77. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/palm.py +0 -0
  78. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/polygon.py +0 -0
  79. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/covalenth/rsk.py +0 -0
  80. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/ethplorer.py +0 -0
  81. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/haskoin.py +0 -0
  82. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/litecoinspace.py +0 -0
  83. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/nft/__init__.py +0 -0
  84. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/nft/magic_eden.py +0 -0
  85. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/nft/opensea.py +0 -0
  86. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/nft/simple_hash.py +0 -0
  87. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/nft/unisat.py +0 -0
  88. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/optimistic_etherscan.py +0 -0
  89. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/subscan.py +0 -0
  90. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/sui.py +0 -0
  91. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/terra.py +0 -0
  92. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/api/trezor.py +0 -0
  93. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/base.py +0 -0
  94. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/blockchain_mapping.py +0 -0
  95. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/coin_mapping.py +0 -0
  96. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/coins.py +0 -0
  97. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi/v2/models.py +0 -0
  98. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi.egg-info/SOURCES.txt +0 -0
  99. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi.egg-info/dependency_links.txt +0 -0
  100. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi.egg-info/requires.txt +0 -0
  101. {blockapi-2.11.4 → blockapi-2.11.6}/blockapi.egg-info/top_level.txt +0 -0
  102. {blockapi-2.11.4 → blockapi-2.11.6}/pyproject.toml +0 -0
  103. {blockapi-2.11.4 → blockapi-2.11.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blockapi
3
- Version: 2.11.4
3
+ Version: 2.11.6
4
4
  Summary: BlockAPI library
5
5
  Home-page: https://github.com/crypkit/blockapi
6
6
  Author: Devmons s.r.o.
@@ -3,7 +3,7 @@ from decimal import Decimal
3
3
  from unittest.mock import call, patch
4
4
 
5
5
  import pytest
6
- from requests_mock import ANY, Mocker
6
+ from requests_mock import Mocker
7
7
 
8
8
  from blockapi.test.v2.api.conftest import read_file
9
9
  from blockapi.v2.api import SolanaApi, SolscanApi
@@ -77,10 +77,41 @@ def test_use_base_url():
77
77
 
78
78
 
79
79
  @pytest.mark.parametrize(
80
- ('rpc_url', 'uses_v2_staking'),
80
+ ('rpc_url', 'status', 'retry_after'),
81
81
  [
82
- ('https://mainnet.helius-rpc.com/', True),
83
- ('https://proxy/solana/', False),
82
+ ('https://proxy/solana/', 429, None),
83
+ ('https://not-helius-rpc.com/', 429, None),
84
+ ('https://helius-rpc.com.example.org/', 429, None),
85
+ ('https://mainnet.helius-rpc.com/', 400, None),
86
+ ('https://mainnet.helius-rpc.com/', 500, None),
87
+ ('https://mainnet.helius-rpc.com/', 429, '5'),
88
+ ('https://mainnet.helius-rpc.com/', 429, 'Fri, 31 Dec 9999 23:59:59 GMT'),
89
+ ('https://mainnet.helius-rpc.com/', 429, 'invalid'),
90
+ ],
91
+ )
92
+ def test_fetch_does_not_retry_other_errors_or_long_cooldowns(
93
+ rpc_url, status, retry_after
94
+ ):
95
+ headers = {'Retry-After': retry_after} if retry_after is not None else {}
96
+ with Mocker() as m, patch('time.sleep') as sleep:
97
+ m.post(rpc_url, status_code=status, headers=headers)
98
+ with pytest.raises(ApiException):
99
+ SolanaApi(base_url=rpc_url).fetch_balances('address')
100
+
101
+ assert len(m.request_history) == 1
102
+ sleep.assert_not_called()
103
+
104
+
105
+ @pytest.mark.parametrize(
106
+ ('rpc_url', 'uses_v2_staking', 'retry_index', 'retry_after'),
107
+ [
108
+ ('https://mainnet.helius-rpc.com/', True, None, None),
109
+ ('https://proxy/solana/', False, None, None),
110
+ ('https://mainnet.helius-rpc.com/', True, 0, None),
111
+ ('https://mainnet.helius-rpc.com/', True, 1, '0'),
112
+ ('https://mainnet.helius-rpc.com/', True, 2, '1'),
113
+ ('https://mainnet.helius-rpc.com/', True, 3, None),
114
+ ('https://mainnet.helius-rpc.com/', True, 5, None),
84
115
  ],
85
116
  )
86
117
  def test_get_balance_supports_helius_and_legacy_staking_responses(
@@ -90,6 +121,8 @@ def test_get_balance_supports_helius_and_legacy_staking_responses(
90
121
  staked_solana_response,
91
122
  rpc_url,
92
123
  uses_v2_staking,
124
+ retry_index,
125
+ retry_after,
93
126
  ):
94
127
  test_addr = '5PjMxaijeVVQtuEzxK2NxyJeWwUbpTsi2uXuZ653WoHu'
95
128
  empty_token_accounts = '{"jsonrpc":"2.0","result":{"context":{"apiVersion":"1.17.34","slot":268207149},"value":[]},"id":1}'
@@ -97,26 +130,39 @@ def test_get_balance_supports_helius_and_legacy_staking_responses(
97
130
  if not uses_v2_staking:
98
131
  staking_response['result'] = staking_response['result']['accounts']
99
132
 
100
- iterator = iter(
101
- [
133
+ responses = [
134
+ {'text': data}
135
+ for data in [
102
136
  sol_balance_response,
103
137
  token_accounts_response,
104
138
  empty_token_accounts,
105
139
  das_asset_batch_response,
106
140
  json.dumps(staking_response),
107
141
  ]
108
- )
109
-
110
- def get_text(*args, **kwargs):
111
- assert args[0].url == rpc_url
112
- data = next(iterator)
113
- return data
114
-
115
- with Mocker() as m:
116
- m.post(ANY, text=get_text)
142
+ ]
143
+ if uses_v2_staking:
144
+ responses.insert(
145
+ 4, {'json': {'result': {'accounts': [], 'paginationKey': 'next-page'}}}
146
+ )
147
+ if retry_index is not None:
148
+ headers = {'Retry-After': retry_after} if retry_after is not None else {}
149
+ responses.insert(retry_index, {'status_code': 429, 'headers': headers})
150
+
151
+ with Mocker() as m, patch('time.sleep') as sleep:
152
+ m.post(rpc_url, responses)
117
153
  api = SolanaApi(base_url=rpc_url)
118
154
  balances = api.get_balance(test_addr)
119
155
 
156
+ if retry_index is not None:
157
+ sleep.assert_called_once_with(1.1)
158
+ assert len(m.request_history) == len(responses)
159
+ assert (
160
+ m.request_history[retry_index].body
161
+ == m.request_history[retry_index + 1].body
162
+ )
163
+ else:
164
+ sleep.assert_not_called()
165
+
120
166
  staking_balances = {
121
167
  balance.asset_type: balance.balance_raw
122
168
  for balance in balances
@@ -128,6 +174,47 @@ def test_get_balance_supports_helius_and_legacy_staking_responses(
128
174
  }
129
175
 
130
176
 
177
+ @pytest.mark.parametrize('fail_on_same_rpc', [True, False])
178
+ def test_retry_is_shared_across_fetch_and_resets_for_next_fetch(
179
+ token_accounts_response, fail_on_same_rpc
180
+ ):
181
+ api = SolanaApi(base_url='https://mainnet.helius-rpc.com/')
182
+ responses = [{'status_code': 429}]
183
+ if not fail_on_same_rpc:
184
+ responses += [
185
+ {'json': {'result': {'value': 0}}},
186
+ {'text': token_accounts_response},
187
+ {'json': {'result': {'value': []}}},
188
+ {'status_code': 429}, # Optional DAS metadata may fail.
189
+ {'json': {'result': {'accounts': [], 'paginationKey': 'next-page'}}},
190
+ ]
191
+ responses.append({'status_code': 429})
192
+
193
+ with Mocker() as m, patch('time.sleep') as sleep:
194
+ for attempt in range(2):
195
+ m.post(api.base_url, responses)
196
+ with pytest.raises(ApiException):
197
+ api.fetch_balances('address')
198
+ assert len(m.request_history) == (attempt + 1) * len(responses)
199
+ if not fail_on_same_rpc:
200
+ assert (
201
+ m.last_request.json()['params'][1]['paginationKey'] == 'next-page'
202
+ )
203
+
204
+ assert sleep.call_args_list == [call(1.1), call(1.1)]
205
+
206
+
207
+ def test_get_coin_retries_helius_metadata_once():
208
+ api = SolanaApi(base_url='https://mainnet.helius-rpc.com/')
209
+ with Mocker() as m, patch('time.sleep') as sleep:
210
+ m.post(api.base_url, [{'status_code': 429}, {'json': {'result': []}}])
211
+ coin = api.get_coin(('mint', 6))
212
+
213
+ assert coin.address == 'mint'
214
+ assert len(m.request_history) == 2
215
+ sleep.assert_called_once_with(1.1)
216
+
217
+
131
218
  def test_build_coin_from_das_asset():
132
219
  api = SolanaApi()
133
220
  asset = {
@@ -317,6 +404,7 @@ def test_fetch_staked_sol_uses_v2_pagination():
317
404
  call(
318
405
  method='getProgramAccountsV2',
319
406
  params=[api.STAKE_PROGRAM_ID, config],
407
+ retry=None,
320
408
  ),
321
409
  call(
322
410
  method='getProgramAccountsV2',
@@ -324,6 +412,7 @@ def test_fetch_staked_sol_uses_v2_pagination():
324
412
  api.STAKE_PROGRAM_ID,
325
413
  {**config, 'paginationKey': 'next-page'},
326
414
  ],
415
+ retry=None,
327
416
  ),
328
417
  call(
329
418
  method='getProgramAccountsV2',
@@ -331,6 +420,7 @@ def test_fetch_staked_sol_uses_v2_pagination():
331
420
  api.STAKE_PROGRAM_ID,
332
421
  {**config, 'paginationKey': 'last-page'},
333
422
  ],
423
+ retry=None,
334
424
  ),
335
425
  ]
336
426
  assert response == {
@@ -14,6 +14,7 @@ from blockapi.v2.api.debank_maps import (
14
14
  COINGECKO_IDS_BY_CONTRACTS,
15
15
  DEBANK_APP_CHAIN_MAP,
16
16
  DEBANK_ASSET_TYPES,
17
+ DEBANK_BORROW_ASSET_TYPES,
17
18
  NATIVE_COIN_MAP,
18
19
  REWARD_ASSET_TYPE_MAP,
19
20
  )
@@ -486,7 +487,7 @@ class DebankPortfolioParser:
486
487
 
487
488
  def _parse_balances(self, detail, item, pool_info) -> Iterable[BalanceItem]:
488
489
  asset_type = self._parse_asset_type(item.name)
489
- borrow_type = self._get_borrow_asset_type(asset_type)
490
+ borrow_type = self._get_borrow_asset_type(item.name, asset_type)
490
491
  reward_type = self._get_reward_asset_type(asset_type)
491
492
  exclude = set()
492
493
 
@@ -585,7 +586,11 @@ class DebankPortfolioParser:
585
586
  return AssetType.LOCKED
586
587
 
587
588
  @staticmethod
588
- def _get_borrow_asset_type(asset_type):
589
+ def _get_borrow_asset_type(debank_type: str, asset_type: AssetType):
590
+ mapped_type = DEBANK_BORROW_ASSET_TYPES.get(debank_type.lower())
591
+ if mapped_type:
592
+ return mapped_type
593
+
589
594
  if asset_type == AssetType.LENDING:
590
595
  return AssetType.LENDING_BORROW
591
596
 
@@ -9,9 +9,17 @@ from blockapi.v2.models import (
9
9
  )
10
10
 
11
11
  DEBANK_ASSET_TYPES = {
12
+ 'airdrop': AssetType.CLAIMABLE,
12
13
  'deposit': AssetType.DEPOSITED,
13
- 'vested': AssetType.VESTING,
14
+ 'leveraged farming': AssetType.FARMING,
14
15
  'liquidity pool': AssetType.LIQUIDITY_POOL,
16
+ 'nft fraction': AssetType.LOCKED,
17
+ 'nft staked': AssetType.STAKED,
18
+ 'vested': AssetType.VESTING,
19
+ }
20
+
21
+ DEBANK_BORROW_ASSET_TYPES = {
22
+ 'leveraged farming': AssetType.DEBT,
15
23
  }
16
24
 
17
25
  REWARD_ASSET_TYPE_MAP = {
@@ -1,5 +1,7 @@
1
1
  import json
2
2
  import logging
3
+ import time
4
+ from dataclasses import dataclass
3
5
  from typing import Optional, Union
4
6
  from urllib.parse import urlparse
5
7
 
@@ -32,6 +34,11 @@ from blockapi.v2.models import (
32
34
  logger = logging.getLogger(__name__)
33
35
 
34
36
 
37
+ @dataclass
38
+ class _HeliusRetry:
39
+ used: bool = False
40
+
41
+
35
42
  class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
36
43
  """Solana JSON-RPC client with DAS metadata integration.
37
44
 
@@ -67,7 +74,7 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
67
74
  api_options = ApiOptions(
68
75
  blockchain=Blockchain.SOLANA,
69
76
  base_url='https://api.mainnet-beta.solana.com/',
70
- rate_limit=1,
77
+ rate_limit=2,
71
78
  start_offset=0,
72
79
  max_items_per_page=1000,
73
80
  page_offset_step=1,
@@ -81,6 +88,7 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
81
88
  STAKE_PROGRAM_ID = 'Stake11111111111111111111111111111111111111'
82
89
  STAKE_AUTHORITY_OFFSET = 44
83
90
  HELIUS_RPC_DOMAIN = 'helius-rpc.com'
91
+ HELIUS_RETRY_DELAY = 1.1
84
92
  HELIUS_PROGRAM_ACCOUNTS_PAGE_SIZE = 5000
85
93
  DAS_BATCH_SIZE = 1000
86
94
  _JSONRPC_INVALID_PARAMS = -32602
@@ -104,7 +112,8 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
104
112
 
105
113
  def fetch_balances(self, address: str) -> FetchResult:
106
114
  """Fetch native SOL, token accounts, DAS metadata, and staking data."""
107
- sol_response = self._request('getBalance', [address])
115
+ retry = _HeliusRetry()
116
+ sol_response = self._request('getBalance', [address], retry=retry)
108
117
 
109
118
  raw_token_balances = self._request(
110
119
  'getTokenAccountsByOwner',
@@ -113,6 +122,7 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
113
122
  {'programId': self.TOKEN_PROGRAM_ID},
114
123
  {'encoding': 'jsonParsed'},
115
124
  ],
125
+ retry=retry,
116
126
  )
117
127
  raw_token2022_balances = self._request(
118
128
  'getTokenAccountsByOwner',
@@ -121,14 +131,15 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
121
131
  {'programId': self.TOKEN_2022_PROGRAM_ID},
122
132
  {'encoding': 'jsonParsed'},
123
133
  ],
134
+ retry=retry,
124
135
  )
125
136
 
126
137
  mint_addresses = self._collect_mint_addresses(
127
138
  raw_token_balances, raw_token2022_balances
128
139
  )
129
- self._fetch_das_assets(mint_addresses)
140
+ self._fetch_das_assets(mint_addresses, retry=retry)
130
141
 
131
- raw_staked_sol = self._fetch_staked_sol(address)
142
+ raw_staked_sol = self._fetch_staked_sol(address, retry=retry)
132
143
 
133
144
  return FetchResult(
134
145
  data=sol_response,
@@ -172,7 +183,7 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
172
183
  def get_coin(self, fetch_params: tuple[str, int]) -> Coin:
173
184
  """Fetch and build a Coin for a given contract address and decimals."""
174
185
  contract, decimals = fetch_params
175
- self._fetch_das_assets([contract])
186
+ self._fetch_das_assets([contract], retry=_HeliusRetry())
176
187
  return self._resolve_coin(contract, decimals)
177
188
 
178
189
  @staticmethod
@@ -248,7 +259,9 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
248
259
 
249
260
  # ── DAS integration ────────────────────────────────────────
250
261
 
251
- def _fetch_das_assets(self, mint_addresses: list[str]) -> None:
262
+ def _fetch_das_assets(
263
+ self, mint_addresses: list[str], retry: Optional[_HeliusRetry] = None
264
+ ) -> None:
252
265
  """Batch-fetch token metadata via DAS and populate cache."""
253
266
  uncached = list(
254
267
  dict.fromkeys(m for m in mint_addresses if m not in self._das_cache)
@@ -262,6 +275,7 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
262
275
  response = self._request(
263
276
  'getAssetBatch',
264
277
  {'ids': chunk, 'options': {'showFungible': True}},
278
+ retry=retry,
265
279
  )
266
280
  except (ApiException, RequestException) as e:
267
281
  logger.warning('DAS getAssetBatch failed: %s', e)
@@ -315,7 +329,9 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
315
329
 
316
330
  # ── Staking ────────────────────────────────────────────────
317
331
 
318
- def _fetch_staked_sol(self, address: str) -> dict:
332
+ def _fetch_staked_sol(
333
+ self, address: str, retry: Optional[_HeliusRetry] = None
334
+ ) -> dict:
319
335
  """Fetch staked SOL accounts for a given address."""
320
336
  config = {
321
337
  'filters': [
@@ -331,11 +347,7 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
331
347
  'commitment': 'finalized',
332
348
  }
333
349
 
334
- hostname = urlparse(self.base_url).hostname or ''
335
- is_helius_rpc = hostname == self.HELIUS_RPC_DOMAIN or hostname.endswith(
336
- f'.{self.HELIUS_RPC_DOMAIN}'
337
- )
338
- if not is_helius_rpc:
350
+ if not self._is_helius_rpc():
339
351
  return self._request(
340
352
  method='getProgramAccounts',
341
353
  params=[self.STAKE_PROGRAM_ID, config],
@@ -349,6 +361,7 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
349
361
  response = self._request(
350
362
  method='getProgramAccountsV2',
351
363
  params=[self.STAKE_PROGRAM_ID, config],
364
+ retry=retry,
352
365
  )
353
366
  page = response['result']
354
367
  accounts.extend(page['accounts'])
@@ -419,7 +432,12 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
419
432
 
420
433
  # ── Infrastructure ─────────────────────────────────────────
421
434
 
422
- def _request(self, method: str, params: Union[list, dict]) -> dict:
435
+ def _request(
436
+ self,
437
+ method: str,
438
+ params: Union[list, dict],
439
+ retry: Optional[_HeliusRetry] = None,
440
+ ) -> dict:
423
441
  """Send a JSON-RPC request to the Solana RPC endpoint."""
424
442
  self._request_id += 1
425
443
  body = json.dumps(
@@ -430,7 +448,31 @@ class SolanaApi(CustomizableBlockchainApi, BalanceMixin):
430
448
  'params': params,
431
449
  }
432
450
  )
433
- return self.post(body=body, headers={'Content-Type': 'application/json'})
451
+ headers = {'Content-Type': 'application/json'}
452
+ if not self._is_helius_rpc():
453
+ return self.post(body=body, headers=headers)
454
+
455
+ response = self._session.post(self.base_url, data=body, headers=headers)
456
+ if (
457
+ response.status_code == 429
458
+ and retry is not None
459
+ and not retry.used
460
+ and response.headers.get('Retry-After', '0').strip() in ('0', '1')
461
+ ):
462
+ retry.used = True
463
+ response.close()
464
+ logger.warning(
465
+ f'Helius {method} rate limited; retrying in {self.HELIUS_RETRY_DELAY}s'
466
+ )
467
+ time.sleep(self.HELIUS_RETRY_DELAY)
468
+ response = self._session.post(self.base_url, data=body, headers=headers)
469
+ return self._check_and_get_from_response(response)
470
+
471
+ def _is_helius_rpc(self) -> bool:
472
+ hostname = urlparse(self.base_url).hostname or ''
473
+ return hostname == self.HELIUS_RPC_DOMAIN or hostname.endswith(
474
+ f'.{self.HELIUS_RPC_DOMAIN}'
475
+ )
434
476
 
435
477
  def _opt_raise_on_other_error(self, response: Response) -> None:
436
478
  """Raise ApiException or InvalidAddressException on RPC errors."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blockapi
3
- Version: 2.11.4
3
+ Version: 2.11.6
4
4
  Summary: BlockAPI library
5
5
  Home-page: https://github.com/crypkit/blockapi
6
6
  Author: Devmons s.r.o.
@@ -6,7 +6,7 @@ with open("README.md", "r") as f:
6
6
 
7
7
  PACKAGES = find_packages(where='.')
8
8
 
9
- __version__ = "2.11.4"
9
+ __version__ = "2.11.6"
10
10
 
11
11
  setuptools.setup(
12
12
  name='blockapi',
File without changes
File without changes
File without changes
File without changes
File without changes