Skip to content

Commit

Permalink
iList->Array
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Oct 23, 2024
1 parent c2d9f87 commit 94b3805
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 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.10"
version = "1.13.11"

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: IList<IndexerMegavaultHistoricalPnlResponse>?): VaultDetails? {
fun calculateVaultSummary(historicals: Array<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 @@ -26,13 +26,13 @@ internal class VaultProcessor(

fun processMegaVaultsHistoricalPnl(
existing: InternalVaultState?,
payload: List<IndexerMegavaultHistoricalPnlResponse>?,
payloads: List<IndexerMegavaultHistoricalPnlResponse>?,
): InternalVaultState? {
if (payload == null) {
if (payloads == null) {
return existing
}

val newValue = VaultCalculator.calculateVaultSummary(payload.toIList())
val newValue = VaultCalculator.calculateVaultSummary(payloads.toTypedArray())
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 @@ -13,7 +13,7 @@ import indexer.models.chain.OnChainAccountVaultResponse
import kollections.iListOf

internal fun TradingStateMachine.onMegaVaultPnl(
payloads: List<String>
payloads: Array<String>
): StateChanges {
val responses = payloads.mapNotNull { parser.asTypedObject<IndexerMegavaultHistoricalPnlResponse>(it) }
val newState = vaultProcessor.processMegaVaultsHistoricalPnl(internalState.vault, responses)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal class VaultSupervisor(
val hourlyResponse = deferredHourly.await()

if (dailyResponse.response != null || hourlyResponse.response != null) {
stateMachine.onMegaVaultPnl(listOfNotNull(dailyResponse.response, hourlyResponse.response))
stateMachine.onMegaVaultPnl(listOfNotNull(dailyResponse.response, hourlyResponse.response).toTypedArray())
} else if (dailyResponse.error != null) {
Logger.e {
"Failed to retrieve day mega vault pnl: ${dailyResponse.error}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class VaultTests {
),
)

val vaultDetails = calculateVaultSummary(iListOf(historicalPnl1, historicalPnl2))
val vaultDetails = calculateVaultSummary(arrayOf(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(iListOf(nullHistoricalPnl))
val emptyVaultDetails = calculateVaultSummary(iListOf(emptyHistoricalPnl))
val nullVaultDetails = calculateVaultSummary(arrayOf(nullHistoricalPnl))
val emptyVaultDetails = calculateVaultSummary(arrayOf(emptyHistoricalPnl))

assertEquals(null, nullVaultDetails)
assertEquals(null, emptyVaultDetails)
Expand Down Expand Up @@ -147,7 +147,7 @@ class VaultTests {
),
)

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

assertNotNull(vaultDetails)
assertEquals(0.6403508771929824, vaultDetails.thirtyDayReturnPercent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ fun TradingStateMachine.rest(
}

"/v4/vault/v1/megavault/historicalPnl" -> {
changes = onMegaVaultPnl(listOf(payload))
changes = onMegaVaultPnl(arrayOf(payload))
}

"/v4/vault/v1/megavault/positions" -> {
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.10'
spec.version = '1.13.11'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 94b3805

Please sign in to comment.