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

fix: use IList in all js types #609

Merged
merged 4 commits into from
Aug 29, 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.9.8"
version = "1.9.9"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import exchange.dydx.abacus.state.internalstate.InternalMarketState
import exchange.dydx.abacus.state.internalstate.InternalMarketSummaryState
import exchange.dydx.abacus.state.internalstate.InternalSubaccountCalculated
import exchange.dydx.abacus.state.internalstate.InternalSubaccountState
import exchange.dydx.abacus.utils.IList
import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.Parser
import kollections.toIList
import kotlinx.datetime.Clock
import kotlinx.serialization.Serializable
import kotlin.js.JsExport
Expand All @@ -22,13 +24,13 @@ import kotlin.time.Duration.Companion.milliseconds
data class VaultDetails(
val totalValue: Double? = null,
val thirtyDayReturnPercent: Double? = null,
val history: List<VaultHistoryEntry>? = null
val history: IList<VaultHistoryEntry>? = null
)

@JsExport
@Serializable
data class VaultPositions(
val positions: List<VaultPosition>? = null,
val positions: IList<VaultPosition>? = null,
)

@JsExport
Expand Down Expand Up @@ -62,7 +64,7 @@ data class CurrentPosition(
data class ThirtyDayPnl(
val percent: Double? = null,
val absolute: Double? = null,
val sparklinePoints: List<Double>? = null
val sparklinePoints: IList<Double>? = null
)

@JsExport
Expand Down Expand Up @@ -125,7 +127,7 @@ object VaultCalculator {
return VaultDetails(
totalValue = totalValue,
thirtyDayReturnPercent = thirtyDayReturnPercent,
history = history,
history = history.toIList(),
)
}

Expand All @@ -140,7 +142,7 @@ object VaultCalculator {

val historiesMap = histories?.vaultsPnl?.associateBy { it.marketId }

return VaultPositions(positions = positions.positions.mapNotNull { calculateVaultPosition(it, historiesMap?.get(it.market), markets?.get(it.market)) })
return VaultPositions(positions = positions.positions.mapNotNull { calculateVaultPosition(it, historiesMap?.get(it.market), markets?.get(it.market)) }.toIList())
}

fun calculateVaultPosition(position: IndexerVaultPosition, history: IndexerVaultHistoricalPnl?, perpetualMarket: PerpetualMarket?): VaultPosition? {
Expand Down Expand Up @@ -225,7 +227,7 @@ object VaultCalculator {
return ThirtyDayPnl(
percent = percentPnl,
absolute = absolutePnl,
sparklinePoints = sparklinePoints,
sparklinePoints = sparklinePoints.toIList(),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.protocols.asTypedObject
import exchange.dydx.abacus.utils.IList
import exchange.dydx.abacus.utils.Parser
import indexer.codegen.IndexerTransferBetweenResponse
import indexer.codegen.IndexerTransferType.DEPOSIT
import indexer.codegen.IndexerTransferType.TRANSFERIN
import indexer.codegen.IndexerTransferType.TRANSFEROUT
import indexer.codegen.IndexerTransferType.WITHDRAWAL
import kollections.toIList
import kotlinx.serialization.Serializable
import kotlin.js.JsExport

Expand All @@ -30,7 +32,7 @@ data class VaultAccount(
val lockedShares: Double?,
val withdrawableUsdc: Double?,
val allTimeReturnUsdc: Double?,
val vaultTransfers: List<VaultTransfer>?,
val vaultTransfers: IList<VaultTransfer>?,
val totalVaultTransfersCount: Int?,
)

Expand Down Expand Up @@ -90,7 +92,7 @@ object VaultAccountCalculator {
},
id = el.id,
)
},
}?.toIList(),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.utils.IList
import kollections.toIList
import kotlinx.serialization.Serializable
import kotlin.js.JsExport

Expand Down Expand Up @@ -92,7 +94,7 @@ data class VaultFormSummaryData(
@JsExport
@Serializable
data class VaultFormValidationResult(
val errors: List<VaultFormValidationError>,
val errors: IList<VaultFormValidationError>,
val submissionData: VaultDepositWithdrawSubmissionData?,
val summaryData: VaultFormSummaryData
)
Expand Down Expand Up @@ -260,7 +262,7 @@ object VaultDepositWithdrawFormValidator {
)

return VaultFormValidationResult(
errors = errors,
errors = errors.toIList(),
submissionData = submissionData,
summaryData = summaryData,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.utils.IList
import indexer.codegen.IndexerAssetPositionResponseObject
import indexer.codegen.IndexerPerpetualPositionResponseObject
import indexer.codegen.IndexerPnlTicksResponseObject
Expand All @@ -9,20 +10,20 @@ import kotlin.js.JsExport
@JsExport
@Serializable
data class IndexerVaultHistoricalPnlResponse(
val vaultOfVaultsPnl: List<IndexerPnlTicksResponseObject>? = null
val vaultOfVaultsPnl: IList<IndexerPnlTicksResponseObject>? = null
)

@JsExport
@Serializable
data class IndexerVaultHistoricalPnl(
val marketId: String? = null,
val historicalPnl: List<IndexerPnlTicksResponseObject>? = null
val historicalPnl: IList<IndexerPnlTicksResponseObject>? = null
)

@JsExport
@Serializable
data class IndexerSubvaultHistoricalPnlResponse(
val vaultsPnl: List<IndexerVaultHistoricalPnl>? = null
val vaultsPnl: IList<IndexerVaultHistoricalPnl>? = null
)

@JsExport
Expand All @@ -37,5 +38,5 @@ data class IndexerVaultPosition(
@JsExport
@Serializable
data class IndexerVaultPositionResponse(
val positions: List<IndexerVaultPosition>? = null
val positions: IList<IndexerVaultPosition>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import exchange.dydx.abacus.functional.vault.VaultAccountCalculator.calculateUse
import indexer.codegen.IndexerTransferBetweenResponse
import indexer.codegen.IndexerTransferResponseObject
import indexer.codegen.IndexerTransferType
import kollections.iListOf
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -48,7 +49,7 @@ class VaultAccountTests {
totalVaultTransfersCount = 2,
balanceShares = 100.0,
lockedShares = 50.0,
vaultTransfers = listOf(
vaultTransfers = iListOf(
VaultTransfer(
timestampMs = 1659465600000.0,
amountUsdc = 6000.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.output.input.ErrorType
import kollections.iListOf
import kollections.toIList
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -41,7 +43,7 @@ class VaultFormTests {

assertEquals(
VaultFormValidationResult(
errors = emptyList(),
errors = listOf<VaultFormValidationError>().toIList(),
submissionData = VaultDepositWithdrawSubmissionData(
deposit = VaultDepositData(
subaccountFrom = "0",
Expand Down Expand Up @@ -88,7 +90,7 @@ class VaultFormTests {

assertEquals(
VaultFormValidationResult(
errors = listOf(
errors = iListOf(
VaultFormValidationError(ErrorType.warning, VaultFormValidationErrorType.SLIPPAGE_TOO_HIGH),
),
submissionData = VaultDepositWithdrawSubmissionData(
Expand Down Expand Up @@ -139,7 +141,7 @@ class VaultFormTests {

assertEquals(
VaultFormValidationResult(
errors = listOf(
errors = iListOf(
VaultFormValidationError(ErrorType.error, VaultFormValidationErrorType.SLIPPAGE_RESPONSE_WRONG_SHARES),
VaultFormValidationError(ErrorType.warning, VaultFormValidationErrorType.SLIPPAGE_TOO_HIGH),
),
Expand Down Expand Up @@ -183,7 +185,7 @@ class VaultFormTests {

assertEquals(
VaultFormValidationResult(
errors = listOf(
errors = iListOf(
VaultFormValidationError(ErrorType.error, VaultFormValidationErrorType.WITHDRAW_TOO_HIGH),
VaultFormValidationError(ErrorType.warning, VaultFormValidationErrorType.SLIPPAGE_TOO_HIGH),
VaultFormValidationError(ErrorType.error, VaultFormValidationErrorType.MUST_ACK_SLIPPAGE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import indexer.codegen.IndexerPerpetualPositionResponseObject
import indexer.codegen.IndexerPerpetualPositionStatus
import indexer.codegen.IndexerPnlTicksResponseObject
import indexer.codegen.IndexerPositionSide
import kollections.iListOf
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand All @@ -19,7 +20,7 @@ class VaultTests {
@Test
fun calculateVaultSummary_basic() {
val historicalPnl = IndexerVaultHistoricalPnlResponse(
vaultOfVaultsPnl = listOf(
vaultOfVaultsPnl = iListOf(
IndexerPnlTicksResponseObject(
equity = "10000.0",
totalPnl = "1000.0",
Expand All @@ -40,7 +41,7 @@ class VaultTests {
val expectedVaultDetails = VaultDetails(
totalValue = 10000.0,
thirtyDayReturnPercent = 0.1,
history = listOf(
history = iListOf(
VaultHistoryEntry(
date = 1659465600000.0,
equity = 10000.0,
Expand All @@ -60,7 +61,7 @@ class VaultTests {
@Test
fun shouldReturnNullForNullOrEmptyHistoricalPnl() {
val nullHistoricalPnl = IndexerVaultHistoricalPnlResponse(vaultOfVaultsPnl = null)
val emptyHistoricalPnl = IndexerVaultHistoricalPnlResponse(vaultOfVaultsPnl = emptyList())
val emptyHistoricalPnl = IndexerVaultHistoricalPnlResponse(vaultOfVaultsPnl = iListOf())

val nullVaultDetails = calculateVaultSummary(nullHistoricalPnl)
val emptyVaultDetails = calculateVaultSummary(emptyHistoricalPnl)
Expand All @@ -77,7 +78,7 @@ class VaultTests {
val twentyNineDaysAgoTimestamp = latestTimestamp - 29.days.inWholeMilliseconds

val historicalPnl = IndexerVaultHistoricalPnlResponse(
vaultOfVaultsPnl = listOf(
vaultOfVaultsPnl = iListOf(
IndexerPnlTicksResponseObject(
equity = "10000.0",
totalPnl = "1000.0",
Expand Down Expand Up @@ -151,7 +152,7 @@ class VaultTests {

val history = IndexerVaultHistoricalPnl(
marketId = "BTC-USD",
historicalPnl = listOf(
historicalPnl = iListOf(
IndexerPnlTicksResponseObject(
id = "1",
equity = "10500.0",
Expand Down Expand Up @@ -196,7 +197,7 @@ class VaultTests {
thirtyDayPnl = ThirtyDayPnl(
percent = 0.05,
absolute = 500.0,
sparklinePoints = listOf(0.0, 500.0),
sparklinePoints = iListOf(0.0, 500.0),
),
)

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.9.8'
spec.version = '1.9.9'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down
Loading