diff --git a/build.gradle.kts b/build.gradle.kts index 8316b4889..feddc7744 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.13.27" +version = "1.13.28" 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 d04c7f08e..1f9bedb95 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt @@ -114,7 +114,7 @@ object VaultCalculator { } }.filter { entry -> entry.date != null && entry.date >= dataCutoffMs } - val latestEntry = history.first() + val latestEntry = history.firstOrNull() ?: return null val latestTime = latestEntry.date ?: Clock.System.now().toEpochMilliseconds().toDouble() val thirtyDaysAgoTime = latestTime - 30.days.inWholeMilliseconds diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/vault/VaultProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/vault/VaultProcessor.kt index 25855af5a..083d988dc 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/vault/VaultProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/vault/VaultProcessor.kt @@ -2,13 +2,13 @@ package exchange.dydx.abacus.processor.vault import exchange.dydx.abacus.functional.vault.ThirtyDayPnl import exchange.dydx.abacus.functional.vault.VaultCalculator -import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.processor.wallet.account.AssetPositionProcessor import exchange.dydx.abacus.processor.wallet.account.PerpetualPositionProcessor import exchange.dydx.abacus.protocols.LocalizerProtocol import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.state.internalstate.InternalVaultPositionState import exchange.dydx.abacus.state.internalstate.InternalVaultState +import exchange.dydx.abacus.state.manager.V4Environment import indexer.codegen.IndexerMegavaultHistoricalPnlResponse import indexer.codegen.IndexerMegavaultPositionResponse import indexer.codegen.IndexerTransferBetweenResponse @@ -16,9 +16,10 @@ import indexer.codegen.IndexerVaultsHistoricalPnlResponse import indexer.models.chain.OnChainAccountVaultResponse internal class VaultProcessor( - parser: ParserProtocol, + private val parser: ParserProtocol, + private val environment: V4Environment?, localizer: LocalizerProtocol?, -) : BaseProcessor(parser) { +) { private val perpetualPositionProcessor = PerpetualPositionProcessor(parser, localizer) private val assetPositionProcessor = AssetPositionProcessor(parser) @@ -31,7 +32,10 @@ internal class VaultProcessor( return existing } - val newValue = VaultCalculator.calculateVaultSummary(payloads.toTypedArray()) + val newValue = VaultCalculator.calculateVaultSummary( + historicals = payloads.toTypedArray(), + dataCutoffMs = environment?.megavaultHistoryStartDateMs ?: 0.0, + ) return if (newValue != existing?.details) { existing?.copy(details = newValue) ?: InternalVaultState(details = newValue) } else { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt index e50f16fb9..f8dbb496a 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt @@ -430,6 +430,7 @@ class V4Environment( val chainName: String?, val chainLogo: String?, rewardsHistoryStartDateMs: String, + val megavaultHistoryStartDateMs: Double?, val megavaultOperatorName: String, isMainNet: Boolean, endpoints: EnvironmentEndpoints, @@ -471,6 +472,7 @@ class V4Environment( val chainName = parser.asString(data["chainName"]) val chainLogo = parser.asString(data["chainLogo"]) val rewardsHistoryStartDateMs = parser.asString(data["rewardsHistoryStartDateMs"]) ?: ServerTime.now().minus(180.days).toEpochMilliseconds().toString() + val megavaultHistoryStartDateMs = parser.asDouble(data["megavaultHistoryStartDateMs"]) val megavaultOperatorName = parser.asString(data["megavaultOperatorName"]) ?: return null val isMainNet = parser.asBool(data["isMainNet"]) ?: return null val endpoints = @@ -503,6 +505,7 @@ class V4Environment( chainName = chainName, chainLogo = "$deploymentUri$chainLogo", rewardsHistoryStartDateMs = rewardsHistoryStartDateMs, + megavaultHistoryStartDateMs = megavaultHistoryStartDateMs, megavaultOperatorName = megavaultOperatorName, isMainNet = isMainNet, endpoints = endpoints, diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt index cb7435d48..6133d4ca7 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt @@ -121,7 +121,7 @@ open class TradingStateMachine( processor } internal val walletProcessor = WalletProcessor(parser, localizer) - internal val vaultProcessor = VaultProcessor(parser, localizer) + internal val vaultProcessor = VaultProcessor(parser, environment, localizer) internal val configsProcessor = ConfigsProcessor(parser, localizer) internal val routerProcessor = SkipProcessor( parser = parser, diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt index f81d6746a..7aa8815a4 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt @@ -60,6 +60,7 @@ class AbacusMockData { chainName = "dYdX Chain", chainLogo = "dYdX-logo.png", rewardsHistoryStartDateMs = "1704844800000", + megavaultHistoryStartDateMs = 1704844800000.0, megavaultOperatorName = "test", isMainNet = false, endpoints = EnvironmentEndpoints( diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/VaultMocks.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/VaultMocks.kt index 68692179b..115241fca 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/VaultMocks.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/VaultMocks.kt @@ -11,25 +11,28 @@ import indexer.codegen.IndexerPositionSide import indexer.codegen.IndexerVaultHistoricalPnl import indexer.codegen.IndexerVaultPosition import indexer.codegen.IndexerVaultsHistoricalPnlResponse -import kotlinx.datetime.Instant +import kotlinx.datetime.Clock import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import kotlin.time.Duration.Companion.days +import kotlin.time.Duration.Companion.hours internal class VaultMocks { + val now = Clock.System.now() private val megaVaultPnl = IndexerMegavaultHistoricalPnlResponse( megavaultPnl = arrayOf( IndexerPnlTicksResponseObject( equity = "10000.0", totalPnl = "1000.0", netTransfers = "0.0", - createdAt = Instant.fromEpochMilliseconds(1659465600000).toString(), + createdAt = now.minus(1.hours).toString(), ), IndexerPnlTicksResponseObject( equity = "5000.0", totalPnl = "500", netTransfers = "0.0", - createdAt = Instant.fromEpochMilliseconds(1659379200000).toString(), + createdAt = now.minus(1.hours).minus(1.days).toString(), ), ), ) @@ -43,14 +46,14 @@ internal class VaultMocks { equity = "10500.0", totalPnl = "500.0", netTransfers = "0.0", - createdAt = Instant.fromEpochMilliseconds(1659465600000).toString(), + createdAt = now.minus(1.hours).toString(), ), IndexerPnlTicksResponseObject( id = "2", equity = "10000.0", totalPnl = "0.0", netTransfers = "0.0", - createdAt = Instant.fromEpochMilliseconds(1659379200000).toString(), + createdAt = now.minus(1.hours).minus(1.days).toString(), ), ), ) diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 593cc35b8..76cabe338 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.13.27' + spec.version = '1.13.28' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''