Add Historical Query Support for Zenrock DefiLlama Adapter #16948
+173
−34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds historical query support to the Zenrock DefiLlama adapter, enabling timeseries charts for Bitcoin and Zcash TVL. The implementation uses Cosmos SDK's
x-cosmos-block-heightHTTP header to query historical blockchain state.Changes
Core Implementation
api.diamond.zenrocklabs.ionow support historical queries viax-cosmos-block-heightheaderFiles Modified
projects/zenrock/index.js- Added historical query logic and hybrid block height conversionprojects/helper/bitcoin-book/fetchers.js- Updated zenrock fetcher to accept blockHeight parameterFeatures
timetravel: truefor DefiLlama historical chartsTesting
Verified Endpoints
All API endpoints tested and confirmed working with
x-cosmos-block-heightheader:/dct/supply- Returns historical custodied amounts/zrchain/treasury/zenbtc_wallets- Returns historical wallet addresses/zenbtc/params- Returns historical change address key IDs/zrchain/treasury/key_by_id/{id}/WALLET_TYPE_BTC_MAINNET/- Returns historical wallet dataHistorical Query Accuracy
Tested with different block heights:
custodied_amount = 56,537,756,747Zatoshi (565.38 ZEC)custodied_amount = 44,067,009,310Zatoshi (440.67 ZEC)custodied_amount = 56,937,756,747Zatoshi (569.38 ZEC)✅ Confirmed historical queries return accurate historical data showing TVL growth over time.
Important Limitation
/dct/supply): Launched on 2025-10-31. Historical queries fail with code 13 error for blocks before the module existed or when historical state has been pruned.Queries for unavailable historical blocks will return:
The adapter throws descriptive errors when historical data is unavailable, rather than silently returning empty balances.
Technical Details
Algorithm
Performance
DefiLlama Compliance
timetravel: trueenabledChecklist