Skip to content

Commit

Permalink
Add new required value to osmosis pricing input (#526)
Browse files Browse the repository at this point in the history
* add some temp logging

* add another log

* add required minimial coin to query

* add change log

* update logging
  • Loading branch information
nullpointer0x00 authored Jul 12, 2024
1 parent 00a099f commit 855d991
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()
}
}
Expand All @@ -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
Expand All @@ -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"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")

Expand Down Expand Up @@ -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)
}
}

0 comments on commit 855d991

Please sign in to comment.