From 855d991736f802ce24203a26881fdedfe3edac88 Mon Sep 17 00:00:00 2001 From: Carlton Hanna Date: Fri, 12 Jul 2024 08:24:33 -0600 Subject: [PATCH] Add new required value to osmosis pricing input (#526) * add some temp logging * add another log * add required minimial coin to query * add change log * update logging --- CHANGELOG.md | 1 + .../io/provenance/explorer/service/TokenService.kt | 9 +++++---- .../io/provenance/explorer/service/TokenServiceTest.kt | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 302a6838..66332bed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * Fixed issue with Proto deserialization incorrectly matching `cosmos.upgrade.v1beta1.CancelSoftwareUpgradeProposal` as `cosmos.upgrade.v1beta1.SoftwareUpgradeProposal`, ensuring accurate type URL handling. [#524](https://github.com/provenance-io/explorer-service/pull/524) +* Update osmosis pricing query with new required field `coinMinimalDenom` [#526](https://github.com/provenance-io/explorer-service/pull/526) ## [v5.10.0](https://github.com/provenance-io/explorer-service/releases/tag/v5.10.0) - 2024-06-11 ### Release Name: Fridtjof Nansen diff --git a/service/src/main/kotlin/io/provenance/explorer/service/TokenService.kt b/service/src/main/kotlin/io/provenance/explorer/service/TokenService.kt index 3f85344f..0dabd3cb 100644 --- a/service/src/main/kotlin/io/provenance/explorer/service/TokenService.kt +++ b/service/src/main/kotlin/io/provenance/explorer/service/TokenService.kt @@ -236,6 +236,7 @@ class TokenService(private val accountClient: AccountGrpcClient) { val input = buildInputQuery(fromDate, determineTimeFrame(fromDate)) try { val url = """https://app.osmosis.zone/api/edge-trpc-assets/assets.getAssetHistoricalPrice?input=$input""" + logger.info("Calling $url with fromDate $fromDate") val response: HttpResponse = KTOR_CLIENT_JAVA.get(url) { accept(ContentType.Application.Json) } @@ -246,10 +247,10 @@ class TokenService(private val accountClient: AccountGrpcClient) { val osmosisApiResponse: OsmosisApiResponse = response.body() osmosisApiResponse.result.data.json } catch (e: ResponseException) { - logger.error("Error fetching from Osmosis API: ${e.response}") + logger.error("Error fetching from Osmosis API: ${e.response}", e) emptyList() } catch (e: Exception) { - logger.error("Error fetching from Osmosis API: ${e.message}") + logger.error("Error fetching from Osmosis API: ${e.message}", e) emptyList() } } @@ -269,7 +270,6 @@ class TokenService(private val accountClient: AccountGrpcClient) { fun determineTimeFrame(fromDate: DateTime?): TimeFrame { val now = DateTime.now(DateTimeZone.UTC) val duration = Duration(fromDate, now) - return when { duration.standardDays <= 14 -> TimeFrame.FIVE_MINUTES duration.standardDays <= 60 -> TimeFrame.TWO_HOURS @@ -296,11 +296,12 @@ class TokenService(private val accountClient: AccountGrpcClient) { */ fun buildInputQuery(fromDate: DateTime?, timeFrame: TimeFrame): String { val coinDenom = "ibc/CE5BFF1D9BADA03BB5CCA5F56939392A761B53A10FBD03B37506669C3218D3B2" + val coinMinimalDenom = "ibc/CE5BFF1D9BADA03BB5CCA5F56939392A761B53A10FBD03B37506669C3218D3B2" val now = DateTime.now(DateTimeZone.UTC) val duration = Duration(fromDate, now) val numRecentFrames = (duration.standardMinutes / timeFrame.minutes).toInt() return URLEncoder.encode( - """{"json":{"coinDenom":"$coinDenom","timeFrame":{"custom":{"timeFrame":${timeFrame.minutes},"numRecentFrames":$numRecentFrames}}}}""", + """{"json":{"coinDenom":"$coinDenom","coinMinimalDenom":"$coinMinimalDenom","timeFrame":{"custom":{"timeFrame":${timeFrame.minutes},"numRecentFrames":$numRecentFrames}}}}""", "UTF-8" ) } diff --git a/service/src/test/kotlin/io/provenance/explorer/service/TokenServiceTest.kt b/service/src/test/kotlin/io/provenance/explorer/service/TokenServiceTest.kt index 0613d9df..524c2b9e 100644 --- a/service/src/test/kotlin/io/provenance/explorer/service/TokenServiceTest.kt +++ b/service/src/test/kotlin/io/provenance/explorer/service/TokenServiceTest.kt @@ -7,6 +7,7 @@ import org.joda.time.DateTime import org.joda.time.DateTimeZone import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import java.net.URI @@ -22,6 +23,7 @@ class TokenServiceTest { } @Test + @Disabled("Test was used to manually call the endpoint") fun `test fetchOsmosisData and print results`() = runBlocking { val fromDate = DateTime.parse("2024-05-08") @@ -56,7 +58,7 @@ class TokenServiceTest { val fromDate1 = now.minusDays(10) val timeFrame1 = TokenService.TimeFrame.FIVE_MINUTES val inputQuery1 = tokenService.buildInputQuery(fromDate1, timeFrame1) - val expectedQuery1 = """%7B%22json%22%3A%7B%22coinDenom%22%3A%22ibc%2FCE5BFF1D9BADA03BB5CCA5F56939392A761B53A10FBD03B37506669C3218D3B2%22%2C%22timeFrame%22%3A%7B%22custom%22%3A%7B%22timeFrame%22%3A5%2C%22numRecentFrames%22%3A2880%7D%7D%7D%7D""" + val expectedQuery1 = """%7B%22json%22%3A%7B%22coinDenom%22%3A%22ibc%2FCE5BFF1D9BADA03BB5CCA5F56939392A761B53A10FBD03B37506669C3218D3B2%22%2C%22coinMinimalDenom%22%3A%22ibc%2FCE5BFF1D9BADA03BB5CCA5F56939392A761B53A10FBD03B37506669C3218D3B2%22%2C%22timeFrame%22%3A%7B%22custom%22%3A%7B%22timeFrame%22%3A5%2C%22numRecentFrames%22%3A2880%7D%7D%7D%7D""" assertEquals(expectedQuery1, inputQuery1) } }