Skip to content

Commit

Permalink
add hash price update from cmc price
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Oct 9, 2024
1 parent e0940d0 commit d06c638
Showing 1 changed file with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import io.ktor.client.request.parameter
import io.provenance.explorer.KTOR_CLIENT_JAVA
import io.provenance.explorer.config.ExplorerProperties
import io.provenance.explorer.config.ExplorerProperties.Companion.UTILITY_TOKEN
import io.provenance.explorer.config.ExplorerProperties.Companion.UTILITY_TOKEN_BASE_DECIMAL_PLACES
import io.provenance.explorer.config.ExplorerProperties.Companion.UTILITY_TOKEN_BASE_MULTIPLIER
import io.provenance.explorer.domain.core.logger
import io.provenance.explorer.domain.entities.AssetPricingRecord
import io.provenance.explorer.domain.entities.MarkerCacheRecord
Expand All @@ -15,6 +17,7 @@ import io.provenance.explorer.domain.extensions.toDateTime
import io.provenance.explorer.domain.models.explorer.AssetPricing
import io.provenance.explorer.grpc.flow.FlowApiGrpcClient
import io.provenance.explorer.model.base.USD_LOWER
import io.provenance.explorer.model.base.USD_UPPER
import io.provenance.marker.v1.MarkerStatus
import kotlinx.coroutines.runBlocking
import org.jetbrains.exposed.dao.id.EntityID
Expand Down Expand Up @@ -59,25 +62,36 @@ class PricingService(
pricingAmount = price.calculateUsdPricePerUnit(),
timestamp = DateTime(price.blockTime * 1000)
)
}
}

val tokenLatest = tokenService.getTokenLatest()
val quote = tokenLatest?.quote?.get(USD_UPPER)
if (quote != null) {
val cmcPrice = quote.price?.let {
val scale = it.scale()
it.setScale(scale + UTILITY_TOKEN_BASE_DECIMAL_PLACES)
.div(UTILITY_TOKEN_BASE_MULTIPLIER)
}

val lastUpdated = quote.last_updated

if (cmcPrice != null && lastUpdated != null) {
val marker = assetService.getAssetRaw(UTILITY_TOKEN)
insertAssetPricing(
marker = marker,
markerDenom = UTILITY_TOKEN,
pricingDenom = USD_LOWER,
pricingAmount = cmcPrice,
timestamp = lastUpdated
)
} else {
// TODO: figure out what this does and finish it in this PR

// val cmcPrice = tokenService.getTokenLatest()?.quote?.get(USD_UPPER)?.price?.let {
// val scale = it.scale()
// it.setScale(scale + UTILITY_TOKEN_BASE_DECIMAL_PLACES)
// .div(UTILITY_TOKEN_BASE_MULTIPLIER)
// }
// val newPriceObj = price.copy(usdPrice = cmcPrice ?: price.usdPrice)
// val marker = assetService.getAssetRaw(price.markerDenom)
// insertAssetPricing(
// marker = marker,
// markerDenom = price.markerDenom,
// pricingDenom = price.priceDenom,
// pricingAmount = newPriceObj.usdPrice!!,
// timestamp = DateTime.now()
// )
logger.warn("CMC Price or Last Updated is null for $UTILITY_TOKEN")
}
} else {
logger.warn("No USD_UPPER price found in tokenLatest for $UTILITY_TOKEN")
}

assetPricinglastRun = now
}

Expand Down

0 comments on commit d06c638

Please sign in to comment.