Skip to content

Commit 4daa034

Browse files
committed
fix: remove redundant getMultipleAccounts call in Solana API, streamline rent reserve parsing
1 parent 9f8dbe0 commit 4daa034

3 files changed

Lines changed: 12 additions & 48 deletions

File tree

blockapi/test/v2/api/data/solana/rent_reserve_solana_response.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

blockapi/test/v2/api/test_solana.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def test_use_base_url_in_post(
8282
token_accounts_response,
8383
das_asset_batch_response,
8484
staked_solana_response,
85-
rent_reserve_solana_response,
8685
ban_list_jup_ag_response,
8786
):
8887
test_addr = '5PjMxaijeVVQtuEzxK2NxyJeWwUbpTsi2uXuZ653WoHu'
@@ -95,7 +94,6 @@ def test_use_base_url_in_post(
9594
empty_token_accounts,
9695
das_asset_batch_response,
9796
staked_solana_response,
98-
rent_reserve_solana_response,
9997
]
10098
)
10199

@@ -383,11 +381,6 @@ def staked_solana_response():
383381
return read_file('data/solana/staked_solana_response.json')
384382

385383

386-
@pytest.fixture
387-
def rent_reserve_solana_response():
388-
return read_file('data/solana/rent_reserve_solana_response.json')
389-
390-
391384
@pytest.fixture
392385
def ban_list_jup_ag_response():
393386
return read_file('data/solana/ban-list-jup-ag.csv')

blockapi/v2/api/solana.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,19 @@ def fetch_balances(self, address: str) -> FetchResult:
129129
self._fetch_das_assets(mint_addresses)
130130

131131
raw_staked_sol = self._fetch_staked_sol(address)
132-
raw_rent_reserve = self._fetch_stake_account_balances(raw_staked_sol)
133132

134133
return FetchResult(
135134
data=sol_response,
136135
extra=dict(
137136
raw_token_balances=raw_token_balances,
138137
raw_token2022_balances=raw_token2022_balances,
139138
raw_staked_sol=raw_staked_sol,
140-
raw_rent_reserve=raw_rent_reserve,
141139
),
142140
)
143141

144142
def parse_balances(self, fetch_result: FetchResult) -> ParseResult:
145143
"""Parse fetched data into a list of BalanceItems."""
146144
raw_staked_sol = fetch_result.extra['raw_staked_sol']
147-
raw_rent_reserve = fetch_result.extra['raw_rent_reserve']
148145

149146
balances = []
150147

@@ -154,7 +151,7 @@ def parse_balances(self, fetch_result: FetchResult) -> ParseResult:
154151
if staked_sol_balance := self._parse_staked_balance(raw_staked_sol):
155152
balances.append(staked_sol_balance)
156153
balances.append(
157-
self._parse_rent_reserve(staked_sol_balance, raw_rent_reserve)
154+
self._parse_rent_reserve(staked_sol_balance, raw_staked_sol)
158155
)
159156

160157
all_raw_tokens = (
@@ -273,7 +270,8 @@ def _fetch_das_assets(self, mint_addresses: list[str]) -> None:
273270
chunk = uncached[i : i + self.DAS_BATCH_SIZE]
274271
try:
275272
response = self._request(
276-
'getAssetBatch',
273+
# 'getAssetBatch',
274+
'getAssets',
277275
{'ids': chunk, 'options': {'showFungible': True}},
278276
)
279277
except (ApiException, RequestException) as e:
@@ -345,16 +343,6 @@ def _fetch_staked_sol(self, address: str) -> dict:
345343
],
346344
)
347345

348-
def _fetch_stake_account_balances(self, raw_staked_sol: dict) -> dict:
349-
"""Fetch balances for all stake accounts in a single RPC call."""
350-
stake_accounts = [r['pubkey'] for r in raw_staked_sol.get('result', [])]
351-
if not stake_accounts:
352-
return {'result': {'value': []}}
353-
return self._request(
354-
method='getMultipleAccounts',
355-
params=[stake_accounts],
356-
)
357-
358346
# ── Balance parsing ────────────────────────────────────────
359347

360348
def _parse_sol_balance(self, response: dict) -> Optional[BalanceItem]:
@@ -388,18 +376,21 @@ def _parse_staked_balance(self, response: dict) -> Optional[BalanceItem]:
388376
)
389377

390378
def _parse_rent_reserve(
391-
self, staked_sol: BalanceItem, response: dict
379+
self, staked_sol: BalanceItem, raw_staked_sol: dict
392380
) -> BalanceItem:
393-
"""Parse rent reserve balance from getMultipleAccounts response."""
394-
accounts = response.get('result', {}).get('value', [])
395-
total_raw = sum(a.get('lamports', 0) for a in accounts if a is not None)
396-
available_raw = total_raw - int(staked_sol.balance_raw)
381+
"""Parse rent reserve from getProgramAccounts response.
397382
383+
Uses result[].account.lamports already returned by _fetch_staked_sol,
384+
avoiding a separate getMultipleAccounts call.
385+
"""
386+
accounts = raw_staked_sol.get('result', [])
387+
total_raw = sum(r['account']['lamports'] for r in accounts)
388+
available_raw = total_raw - int(staked_sol.balance_raw)
398389
return BalanceItem.from_api(
399390
balance_raw=available_raw,
400391
coin=self.coin,
401392
asset_type=AssetType.LOCKED,
402-
raw=response,
393+
raw=raw_staked_sol,
403394
)
404395

405396
# ── Infrastructure ─────────────────────────────────────────

0 commit comments

Comments
 (0)