WIP: Change TVL calcs for HASH#669
Draft
jforseth-figure wants to merge 2 commits into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Pulse TVL and supporting metric calculations to incorporate HASH held by “passport” (KYC) accounts, and improves a few supporting pricing/range calculations used by Pulse metrics.
Changes:
- Add
PassportHashServiceand new Pulse cache metrics to compute passport-account HASH balance and its USD TVL contribution. - Improve asset USD price resolution by falling back to $1 parity denoms and the pricing engine when exchange-derived pricing is unavailable.
- Adjust range-over-range span logic to use complete UTC calendar-day windows (excluding “today”), and add supporting gRPC helpers for height-based queries.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| service/src/main/resources/application-development.properties | Adds config for the passport attribute name used to discover passport accounts. |
| service/src/main/resources/application-container.properties | Adds container/env-config for the passport attribute name. |
| service/src/main/kotlin/io/provenance/explorer/service/PulseMetricService.kt | Integrates passport HASH TVL into Pulse TVL, adds USD parity pricing fallback, and updates complete-day range window logic. |
| service/src/main/kotlin/io/provenance/explorer/service/PassportHashService.kt | New service to fetch passport accounts and sum HASH holdings (bank + delegated + rewards), with caching and concurrency limiting. |
| service/src/main/kotlin/io/provenance/explorer/grpc/v1/AttributeGrpcClient.kt | Adds query to list accounts for a given attribute with pagination. |
| service/src/main/kotlin/io/provenance/explorer/grpc/v1/AccountGrpcClient.kt | Adds height-aware staking delegations and rewards queries. |
| service/src/main/kotlin/io/provenance/explorer/domain/models/explorer/pulse/Enums.kt | Adds new PulseCacheType entries for passport HASH balance/TVL metrics. |
| service/src/main/kotlin/io/provenance/explorer/config/pulse/PulseProperties.kt | Adds a new passportAttributeName configuration property. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
387
to
+398
| var giveUp = 1L | ||
| while (giveUp++ < 15L) { | ||
| val amt = fromPulseMetricCache( | ||
| atDate.minusDays(giveUp), | ||
| PulseCacheType.PULSE_ASSET_PRICE_SUMMARY_METRIC, denom | ||
| )?.amount | ||
| if (amt != null && amt > BigDecimal.ZERO) { | ||
| return@let amt | ||
| } | ||
| } | ||
| logger.warn("Failed to find price for $denom on $atDate looking back $giveUp days") | ||
| return@let BigDecimal.ZERO | ||
| return@let resolvePulseAssetUsdPrice(denom, BigDecimal.ZERO) |
Comment on lines
+56
to
+64
| return runBlocking { | ||
| accounts.map { address -> | ||
| async { | ||
| semaphore.withPermit { | ||
| sumHashForAccount(address, height) | ||
| } | ||
| } | ||
| }.awaitAll().sumOf { it } | ||
| } |
Comment on lines
+521
to
+523
| val accounts = passportHashService.getPassportAccounts() | ||
| val totalNhash = passportHashService.sumHashHoldings(accounts, atDateTime) | ||
| .divide(UTILITY_TOKEN_BASE_MULTIPLIER) |
Comment on lines
+49
to
+64
| fun sumHashHoldings(accounts: Set<String>, atDateTime: LocalDateTime? = null): BigDecimal { | ||
| if (accounts.isEmpty()) { | ||
| return BigDecimal.ZERO | ||
| } | ||
|
|
||
| val height = atDateTime?.let { BlockCacheRecord.getLastBlockBeforeTime(it) } | ||
|
|
||
| return runBlocking { | ||
| accounts.map { address -> | ||
| async { | ||
| semaphore.withPermit { | ||
| sumHashForAccount(address, height) | ||
| } | ||
| } | ||
| }.awaitAll().sumOf { it } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
I'm still trying to wrap my head around what's required here, and how to do it. This code is heavy vibed, and I don't know enough to steer it in the right direction yet.
closes: #517312
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Unreleasedsection inCHANGELOG.mdFiles changedin the Github PR explorerCodecov Reportin the comment section below once CI passes