-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add zenrock DefiLlama TVL adapter #16860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add zenrock DefiLlama TVL adapter #16860
Conversation
- Tracks native Bitcoin locked by zrchain protocol across Ethereum and Solana - Reports proportional Bitcoin distribution per chain from zrchain API - Uses DefiLlama SDK helpers for both chains (Solana getTokenSupplies, Ethereum api.call) - Implements promise-based caching to prevent redundant fetches with concurrent calls - Derives Solana mint address from program ID using PDA with "wrapped_mint" seed - Tested with live mainnet data: ~74 BTC across chains Methodology: TVL represents total native Bitcoin locked by the protocol, with zenBTC as wrapped representations on each chain. Each zenBTC is backed by at least 1 BTC in custody, with yield mechanisms coming soon that will increase the backing ratio above 1:1.
|
The adapter at projects/zenrock exports TVL: |
|
The adapter at projects/zenrock exports TVL: |
|
Here we should count the collateral BTC held at bitcoin addresses on the bitcoin network |
|
@waynebruce0x it's possible to query zrchain to get all the BTC addresses. Let me try this out and push to this PR. query all BTC addresses-> fetch balance for each. It will be a lot of addresses |
|
We can do this by paginating these addresses |
- Implement paginated fetching of Bitcoin mainnet addresses from zrchain treasury (297 addresses total) - Replace custodied BTC API endpoint with actual on-chain balance queries using Bitcoin helper - Add change address (bc1qngthd4lgz6pjkf24d2cesltlnd7nd0pjguuvqu) to treasury wallet list - TVL now calculated from verified Bitcoin address balances (~74.05 BTC) - Maintains proportional distribution across Ethereum and Solana zenBTC supplies This provides transparent, on-chain verified TVL instead of relying on API-reported custodied amounts.
|
The adapter at projects/zenrock exports TVL: |
- Replace hardcoded change address with dynamic fetching from zenbtc params API
- Implement getChangeAddresses() function that:
- Fetches changeAddressKeyIDs from /zenbtc/params
- Queries /zrchain/treasury/key_by_id/{keyID}/WALLET_TYPE_BTC_MAINNET/ for each key
- Extracts addresses from wallet data
- Fetch treasury and change addresses in parallel for efficiency
- Update logging to show breakdown (296 treasury + 1 change = 297 total addresses)
This makes the adapter dynamic and resilient to future changes in the zenbtc configuration.
|
The adapter at projects/zenrock exports TVL: |
|
@waynebruce0x now fetching TVL via the BTC addresses. Fetching via the zrchain API. |
…ation The tvl() function now fetches both treasury and change addresses in parallel, combining them to calculate the total Bitcoin TVL. This ensures accurate accounting of all custodied Bitcoin across both wallet types. Test results: 297 total addresses (296 treasury + 1 change) = 74.05 BTC TVL 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
The adapter at projects/zenrock exports TVL: |
|
@waynebruce0x I moved the TVL to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Peyton-Spencer thanks for the PR, can you move the address fetcher logic here: https://github.com/DefiLlama/DefiLlama-Adapters/blob/main/projects/helper/bitcoin-book/fetchers.js
Move treasury and change address fetching logic into the centralized bitcoin-book/fetchers.js module. This allows code reuse across Bitcoin adapters and better follows DefiLlama's organization patterns. The zenrock fetcher uses getConfig for caching and returns all 297 addresses (296 treasury + 1 change) for the adapter to use with the Bitcoin sumTokens helper. Changes: - Added zenrock fetcher to bitcoin-book/fetchers.js with getConfig caching - Updated zenrock/index.js to use the new zenrock fetcher - Simplified adapter to single tvl function that calls the fetcher
|
The adapter at projects/zenrock exports TVL: |
|
@g1nt0ki I moved the address fetching logic, thanks for your review |
|
converting to draft due to adding zcash TVL, then will reopen |
|
The adapter at projects/zenrock exports TVL: |
|
I updated the PR to include our zcash TVL for our new zenZEC token. I used the supply-based approach by querying zrchain for the custodied ZEC amount: We plan to export TVL using the address-based approach. Monday I will look into our wallet list for zcash, but for now the supply based approach is exporting accurate ZEC TVL. |
Address PR review feedback: 1. Removed all try-catch blocks that swallow errors - allow hard failures for monitoring 2. Removed console.log/console.error statements, rely on sdk.log 3. Cleaned up zcash.js: - Removed unused address-based balance functions - Removed fallback API endpoints (zcha.in, zcashnetwork.io) - Removed getBalanceNow and getBalance functions - Kept only cache API call functions - Changed cache delay from 3 hours to 1 hour 4. Removed zenrockDCT import from zenrock adapter (not currently used) 5. Removed commented-out address-based zcash TVL function 6. Simplified adapter code Test results: Adapter exports 303 total addresses (bitcoin + zcash): - Bitcoin: 8.00 M from 296 treasury + 1 change address - Zcash: 188.07k (supply-based approach)
|
The adapter at projects/zenrock exports TVL: |
|
The adapter at projects/zenrock exports TVL: |
|
The adapter at projects/zenrock exports TVL: |
|
The adapter at projects/zenrock exports TVL: |
|
Hi @waynebruce0x I have removed all try/catch and removed the I went with the "supply method" for zcash TVL. We have this API endpoint for returning all the zcash addresses custodied by our protocol: However, I was timing out when I tried to sum up all the balances in these addresses. So, this PR is using our endpoint for total ZEC custodied: This allows for a single making the TVL return quicker. So, for BTC we are summing the balances in all addresses while ZEC we are multiplying custodied assets * price of ZEC. Let me know if you need any changes, thanks! |
|
Hey @Peyton-Spencer thanks for the PR! Please also fill out the listing_template details: Name (to be shown on DefiLlama): |
|
Hey @realdealshaman should I open up a new PR with these additions since this one has been merged? |
Summary
This adapter calculates the Bitcoin TVL for zrchain by querying actual Bitcoin addresses from the zrchain treasury and change addresses, then summing their Bitcoin balances using DefiLlama's Bitcoin helper.
Key Implementation Details
/zenbtc_walletsendpoint, filtered forWALLET_TYPE_BTC_MAINNET/zenbtc/paramsendpoint, then queried via/key_by_idAPI for each key IDsumBitcoinTokens()helper fromhelper/chain/bitcoin.jsto query actual BTC balances from Bitcoin blockchainMethodology
zrchain locks native Bitcoin through its decentralized MPC network. zenBTC, Zenrock's flagship product, is a yield-bearing wrapped Bitcoin issued on Solana and EVM chains. TVL represents the total Bitcoin locked in zrchain treasury addresses. All zenBTC is fully backed by native Bitcoin, with the price of zenBTC anticipated to increase as yield payments are made continuously.
References
Test Plan
🤖 Generated with Claude Code