From c2d9f87744a2a11d0dfaafdf1f05d726d20b8d64 Mon Sep 17 00:00:00 2001 From: mike-dydx <149746839+mike-dydx@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:08:42 -0400 Subject: [PATCH] update calculate pnl function to use `IList` instead of `List` (#727) Co-authored-by: Mike --- build.gradle.kts | 2 +- .../kotlin/exchange.dydx.abacus/functional/vault/Vault.kt | 2 +- .../processor/vault/VaultProcessor.kt | 3 ++- .../exchange.dydx.abacus/functional/vault/VaultTests.kt | 8 ++++---- v4_abacus.podspec | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index fd0b0a58d..3a49e1f16 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.13.9" +version = "1.13.10" 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 1bfc66ecb..fa027b0ea 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt @@ -94,7 +94,7 @@ object VaultCalculator { return parser.asTypedObject(apiResponse) } - fun calculateVaultSummary(historicals: List?): VaultDetails? { + fun calculateVaultSummary(historicals: IList?): VaultDetails? { val combinedPnls = historicals?.flatMap { it.megavaultPnl?.toList() ?: emptyList() } // Convert Array to List if (combinedPnls.isNullOrEmpty()) { 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 79a55536e..97770c71c 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/vault/VaultProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/vault/VaultProcessor.kt @@ -14,6 +14,7 @@ import indexer.codegen.IndexerMegavaultPositionResponse import indexer.codegen.IndexerTransferBetweenResponse import indexer.codegen.IndexerVaultsHistoricalPnlResponse import indexer.models.chain.OnChainAccountVaultResponse +import kollections.toIList internal class VaultProcessor( parser: ParserProtocol, @@ -31,7 +32,7 @@ internal class VaultProcessor( return existing } - val newValue = VaultCalculator.calculateVaultSummary(payload) + val newValue = VaultCalculator.calculateVaultSummary(payload.toIList()) return if (newValue != existing?.details) { existing?.copy(details = newValue) ?: InternalVaultState(details = newValue) } else { 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 ca48d2e94..5981e455e 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt @@ -61,7 +61,7 @@ class VaultTests { ), ) - val vaultDetails = calculateVaultSummary(listOf(historicalPnl1, historicalPnl2)) + val vaultDetails = calculateVaultSummary(iListOf(historicalPnl1, historicalPnl2)) val expectedVaultDetails = VaultDetails( totalValue = 10000.0, @@ -98,8 +98,8 @@ class VaultTests { val nullHistoricalPnl = IndexerMegavaultHistoricalPnlResponse(megavaultPnl = null) val emptyHistoricalPnl = IndexerMegavaultHistoricalPnlResponse(megavaultPnl = arrayOf()) - val nullVaultDetails = calculateVaultSummary(listOf(nullHistoricalPnl)) - val emptyVaultDetails = calculateVaultSummary(listOf(emptyHistoricalPnl)) + val nullVaultDetails = calculateVaultSummary(iListOf(nullHistoricalPnl)) + val emptyVaultDetails = calculateVaultSummary(iListOf(emptyHistoricalPnl)) assertEquals(null, nullVaultDetails) assertEquals(null, emptyVaultDetails) @@ -147,7 +147,7 @@ class VaultTests { ), ) - val vaultDetails = calculateVaultSummary(listOf(historicalPnl)) + val vaultDetails = calculateVaultSummary(iListOf(historicalPnl)) assertNotNull(vaultDetails) assertEquals(0.6403508771929824, vaultDetails.thirtyDayReturnPercent) diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 1ea87fda7..16564ee29 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.9' + spec.version = '1.13.10' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''