Skip to content

Commit

Permalink
fix dates
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Sep 24, 2024
1 parent d0c900c commit 73ce96b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.11.17"
version = "1.11.18"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
),
),
)
Expand Down Expand Up @@ -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(),
),
),
)
Expand Down Expand Up @@ -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(),
),
),
)
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand Down

0 comments on commit 73ce96b

Please sign in to comment.