Skip to content

Commit

Permalink
update calculate pnl function to use IList instead of List (#727)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike <[email protected]>
  • Loading branch information
mike-dydx and mike-dydx authored Oct 23, 2024
1 parent bf79d15 commit c2d9f87
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 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.13.9"
version = "1.13.10"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object VaultCalculator {
return parser.asTypedObject<IndexerMegavaultPositionResponse>(apiResponse)
}

fun calculateVaultSummary(historicals: List<IndexerMegavaultHistoricalPnlResponse>?): VaultDetails? {
fun calculateVaultSummary(historicals: IList<IndexerMegavaultHistoricalPnlResponse>?): VaultDetails? {
val combinedPnls = historicals?.flatMap { it.megavaultPnl?.toList() ?: emptyList() } // Convert Array to List

if (combinedPnls.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class VaultTests {
),
)

val vaultDetails = calculateVaultSummary(listOf(historicalPnl1, historicalPnl2))
val vaultDetails = calculateVaultSummary(iListOf(historicalPnl1, historicalPnl2))

val expectedVaultDetails = VaultDetails(
totalValue = 10000.0,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -147,7 +147,7 @@ class VaultTests {
),
)

val vaultDetails = calculateVaultSummary(listOf(historicalPnl))
val vaultDetails = calculateVaultSummary(iListOf(historicalPnl))

assertNotNull(vaultDetails)
assertEquals(0.6403508771929824, vaultDetails.thirtyDayReturnPercent)
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.13.9'
spec.version = '1.13.10'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit c2d9f87

Please sign in to comment.