Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iList -> Array #728

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -14,7 +14,6 @@ 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 @@ -26,13 +25,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