Skip to content

WIP: Change TVL calcs for HASH#669

Draft
jforseth-figure wants to merge 2 commits into
mainfrom
jforseth/hash-tvl-changes
Draft

WIP: Change TVL calcs for HASH#669
jforseth-figure wants to merge 2 commits into
mainfrom
jforseth/hash-tvl-changes

Conversation

@jforseth-figure

@jforseth-figure jforseth-figure commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit and integration
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PassportHashService and 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 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants