diff --git a/build.gradle.kts b/build.gradle.kts index ef118d7f1..e5bbb55f4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.11.17" +version = "1.11.18" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt index c8f48b236..9c791dfd8 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt @@ -99,7 +99,7 @@ object VaultCalculator { val vaultOfVaultsPnl = historical!!.megavaultPnl!!.sortedByDescending { parser.asDouble(it.createdAt) } val history = vaultOfVaultsPnl.mapNotNull { entry -> - parser.asDouble(entry.createdAt)?.let { createdAt -> + parser.asDatetime(entry.createdAt)?.toEpochMilliseconds()?.toDouble()?.let { createdAt -> VaultHistoryEntry( date = createdAt, equity = parser.asDouble(entry.equity) ?: 0.0, @@ -196,13 +196,13 @@ object VaultCalculator { return null } - val sortedPnl = historicalPnl.sortedByDescending { parser.asLong(it.createdAt) } + val sortedPnl = historicalPnl.sortedByDescending { it.createdAt } val latestEntry = sortedPnl.first() - val latestTime = parser.asLong(latestEntry.createdAt) ?: Clock.System.now().toEpochMilliseconds() + val latestTime = parser.asDatetime(latestEntry.createdAt)?.toEpochMilliseconds() ?: Clock.System.now().toEpochMilliseconds() val thirtyDaysAgoTime = latestTime - 30.days.inWholeMilliseconds val thirtyDaysAgoEntry = sortedPnl.find { - (parser.asLong(it.createdAt) ?: Long.MAX_VALUE) <= thirtyDaysAgoTime + (parser.asDatetime(it.createdAt)?.toEpochMilliseconds() ?: Long.MAX_VALUE) <= thirtyDaysAgoTime } ?: sortedPnl.last() val latestTotalPnl = parser.asDouble(latestEntry.totalPnl) ?: 0.0 @@ -217,9 +217,9 @@ object VaultCalculator { } val sparklinePoints = sortedPnl - .takeWhile { (parser.asLong(it.createdAt) ?: Long.MAX_VALUE) >= thirtyDaysAgoTime } + .takeWhile { (parser.asDatetime(it.createdAt)?.toEpochMilliseconds() ?: Long.MAX_VALUE) >= thirtyDaysAgoTime } .groupBy { entry -> - val timestamp = parser.asLong(entry.createdAt) ?: 0L + val timestamp = parser.asDatetime(entry.createdAt)?.toEpochMilliseconds() ?: 0L timestamp.milliseconds.inWholeDays } .mapValues { (_, entries) -> diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt index f0acfe32c..ef16bf8ae 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt @@ -83,7 +83,7 @@ object VaultAccountCalculator { totalVaultTransfersCount = vaultTransfers.totalResults, vaultTransfers = vaultTransfers.transfersSubset?.map { el -> VaultTransfer( - timestampMs = parser.asDouble(el.createdAt), + timestampMs = parser.asDatetime(el.createdAt)?.toEpochMilliseconds()?.toDouble(), amountUsdc = parser.asDouble(el.size), type = when (el.type) { TRANSFEROUT -> VaultTransferType.DEPOSIT diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultAccountTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultAccountTests.kt index 4e17887c2..163d7c675 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultAccountTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultAccountTests.kt @@ -5,6 +5,7 @@ import indexer.codegen.IndexerTransferBetweenResponse import indexer.codegen.IndexerTransferResponseObject import indexer.codegen.IndexerTransferType import kollections.iListOf +import kotlinx.datetime.Instant import kotlin.test.Test import kotlin.test.assertEquals @@ -27,13 +28,13 @@ class VaultAccountTests { transfersSubset = arrayOf( IndexerTransferResponseObject( id = "1", - createdAt = "1659465600000", + createdAt = Instant.fromEpochMilliseconds(1659465600000).toString(), size = "6000.0", type = IndexerTransferType.TRANSFEROUT, ), IndexerTransferResponseObject( id = "2", - createdAt = "1659552000000", + createdAt = Instant.fromEpochMilliseconds(1659552000000).toString(), size = "2000.0", type = IndexerTransferType.TRANSFERIN, ), diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt index 791db74e5..ef5b8c659 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt @@ -13,6 +13,7 @@ import indexer.codegen.IndexerPositionSide import indexer.codegen.IndexerVaultHistoricalPnl import indexer.codegen.IndexerVaultPosition import kollections.iListOf +import kotlinx.datetime.Instant import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -28,13 +29,13 @@ class VaultTests { equity = "10000.0", totalPnl = "1000.0", netTransfers = "0.0", - createdAt = "1659465600000", + createdAt = Instant.fromEpochMilliseconds(1659465600000).toString(), ), IndexerPnlTicksResponseObject( equity = "5000.0", totalPnl = "500", netTransfers = "0.0", - createdAt = "1659379200000", + createdAt = Instant.fromEpochMilliseconds(1659379200000).toString(), ), ), ) @@ -86,31 +87,31 @@ class VaultTests { equity = "10000.0", totalPnl = "1000.0", netTransfers = "0.0", - createdAt = latestTimestamp.toString(), + createdAt = Instant.fromEpochMilliseconds(latestTimestamp).toString(), ), IndexerPnlTicksResponseObject( equity = "9700.0", totalPnl = "700.0", netTransfers = "0.0", - createdAt = twentyNineDaysAgoTimestamp.toString(), + createdAt = Instant.fromEpochMilliseconds(twentyNineDaysAgoTimestamp).toString(), ), IndexerPnlTicksResponseObject( equity = "9500.0", totalPnl = "500.0", netTransfers = "0.0", - createdAt = thirtyDaysAgoTimestamp.toString(), + createdAt = Instant.fromEpochMilliseconds(thirtyDaysAgoTimestamp).toString(), ), IndexerPnlTicksResponseObject( equity = "9300.0", totalPnl = "300.0", netTransfers = "0.0", - createdAt = thirtyOneDaysAgoTimestamp.toString(), + createdAt = Instant.fromEpochMilliseconds(thirtyOneDaysAgoTimestamp).toString(), ), IndexerPnlTicksResponseObject( equity = "9000.0", totalPnl = "0.0", netTransfers = "0.0", - createdAt = (thirtyDaysAgoTimestamp - 7.days.inWholeMilliseconds).toString(), + createdAt = Instant.fromEpochMilliseconds((thirtyDaysAgoTimestamp - 7.days.inWholeMilliseconds)).toString(), ), ), ) @@ -161,14 +162,14 @@ class VaultTests { equity = "10500.0", totalPnl = "500.0", netTransfers = "0.0", - createdAt = "1659465600000", + createdAt = Instant.fromEpochMilliseconds(1659465600000).toString(), ), IndexerPnlTicksResponseObject( id = "2", equity = "10000.0", totalPnl = "0.0", netTransfers = "0.0", - createdAt = "1659379200000", + createdAt = Instant.fromEpochMilliseconds(1659379200000).toString(), ), ), ) diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 1e475ac89..a5554bf97 100644 --- a/v4_abacus.podspec +++ b/v4_abacus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'v4_abacus' - spec.version = '1.11.17' + spec.version = '1.11.18' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''