diff --git a/build.gradle.kts b/build.gradle.kts index 746474421..5d5ea70b3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.12.10" +version = "1.12.11" 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 661ce3360..69b1b208b 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/Vault.kt @@ -126,6 +126,11 @@ object VaultCalculator { val thirtyDaysAgoTotalPnl = thirtyDaysAgoEntry.totalPnl ?: 0.0 val pnlDifference = latestTotalPnl - thirtyDaysAgoTotalPnl + val timeDifferenceMs = if (latestEntry.date != null && thirtyDaysAgoEntry.date != null) { + latestEntry.date - thirtyDaysAgoEntry.date + } else { + 0.0 + } val thirtyDaysAgoEquity = thirtyDaysAgoEntry.equity ?: 0.0 val thirtyDayReturnPercent = if (thirtyDaysAgoEquity != 0.0) { (pnlDifference / thirtyDaysAgoEquity) @@ -135,7 +140,7 @@ object VaultCalculator { return VaultDetails( totalValue = totalValue, - thirtyDayReturnPercent = thirtyDayReturnPercent, + thirtyDayReturnPercent = if (timeDifferenceMs > 0) thirtyDayReturnPercent * 365.days.inWholeMilliseconds / timeDifferenceMs else 0.0, history = history.toIList(), ) } 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 ef5b8c659..5f33c374a 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultTests.kt @@ -44,7 +44,7 @@ class VaultTests { val expectedVaultDetails = VaultDetails( totalValue = 10000.0, - thirtyDayReturnPercent = 0.1, + thirtyDayReturnPercent = 0.1 * 365, history = iListOf( VaultHistoryEntry( date = 1659465600000.0, @@ -119,7 +119,7 @@ class VaultTests { val vaultDetails = calculateVaultSummary(historicalPnl) assertNotNull(vaultDetails) - assertEquals(0.05263157894736842, vaultDetails.thirtyDayReturnPercent) + assertEquals(0.6403508771929824, vaultDetails.thirtyDayReturnPercent) } @Test diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4VaultTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4VaultTests.kt index 62312615b..36a91fe5f 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4VaultTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4VaultTests.kt @@ -27,7 +27,7 @@ class V4VaultTests : V4BaseTests() { val vaultDetails = vault?.details assertEquals(10000.0, vaultDetails?.totalValue) - assertEquals(0.1, vaultDetails?.thirtyDayReturnPercent) + assertEquals(0.1 * 365, vaultDetails?.thirtyDayReturnPercent) assertEquals(2, vaultDetails?.history?.size) assertEquals(1000.0, vaultDetails?.history?.get(0)?.totalPnl) assertEquals(500.0, vaultDetails?.history?.get(1)?.totalPnl) @@ -50,7 +50,7 @@ class V4VaultTests : V4BaseTests() { val vault = perp.internalState.vault assertEquals(10000.0, vault?.details?.totalValue) - assertEquals(0.1, vault?.details?.thirtyDayReturnPercent) + assertEquals(0.1 * 365, vault?.details?.thirtyDayReturnPercent) assertEquals(2, vault?.details?.history?.size) assertEquals(1000.0, vault?.details?.history?.get(0)?.totalPnl) assertEquals(500.0, vault?.details?.history?.get(1)?.totalPnl) diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 2cf16a374..bd8bb2d0e 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.12.10' + spec.version = '1.12.11' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''