diff --git a/build.gradle.kts b/build.gradle.kts index b49e59a7f..00084403b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,7 +51,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.7.33" +version = "1.7.34" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/Configs.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/Configs.kt index 3a5077234..bfcd7e2bd 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/Configs.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/Configs.kt @@ -6,6 +6,7 @@ import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.utils.IList import exchange.dydx.abacus.utils.Logger import kollections.JsExport +import kollections.iListOf import kollections.iMutableListOf import kotlinx.serialization.Serializable @@ -247,6 +248,103 @@ data class FeeTier( } } +@JsExport +@Serializable +data class EquityTiers( + val shortTermOrderEquityTiers: IList, + val statefulOrderEquityTiers: IList, +) { + companion object { + internal fun create( + existing: EquityTiers?, + parser: ParserProtocol, + data: Map<*, *>?, + ): EquityTiers? { + data?.let { + val shortTermOrderEquityTiers = parser.asNativeList(data["shortTermOrderEquityTiers"])?.let { tiers -> + create(existing?.shortTermOrderEquityTiers, parser, tiers) + } ?: iListOf() + + val statefulOrderEquityTiers = parser.asNativeList(data["statefulOrderEquityTiers"])?.let { tiers -> + create(existing?.statefulOrderEquityTiers, parser, tiers) + } ?: iListOf() + + return EquityTiers(shortTermOrderEquityTiers, statefulOrderEquityTiers) + } + + Logger.d { "Equity Tiers not valid" } + return null + } + + internal fun create( + existing: IList?, + parser: ParserProtocol, + data: List<*>? + ): IList? { + data?.let { + val equityTiers = iMutableListOf() + for (i in data.indices) { + val item = data[i] + val nextItem = data.getOrNull(i + 1) + parser.asMap(item)?.let { + val tier = existing?.getOrNull(i) + val nextTierData = parser.asMap(nextItem) + EquityTier.create(tier, parser, it, nextTierData)?.let { equityTier -> + equityTiers.add(equityTier) + } + } + } + return equityTiers + } + Logger.d { "Equity Tiers not valid" } + return null + } + } +} + +@JsExport +@Serializable +data class EquityTier( + val requiredTotalNetCollateralUSD: Double, + val nextLevelRequiredTotalNetCollateralUSD: Double?, + val maxOrders: Int, +) { + companion object { + internal fun create( + existing: EquityTier?, + parser: ParserProtocol, + data: Map<*, *>?, + nextTierData: Map<*, *>? + ): EquityTier? { + data?.let { + val requiredTotalNetCollateralUSD = parser.asDouble(data["requiredTotalNetCollateralUSD"]) + val nextLevelRequiredTotalNetCollateralUSD = nextTierData?.let { + parser.asDouble(nextTierData["requiredTotalNetCollateralUSD"]) + } + val maxOrders = parser.asInt(data["maxOrders"]) + + if (requiredTotalNetCollateralUSD != null && maxOrders != null) { + return if ( + existing?.requiredTotalNetCollateralUSD != requiredTotalNetCollateralUSD || + existing?.nextLevelRequiredTotalNetCollateralUSD != nextLevelRequiredTotalNetCollateralUSD || + existing?.maxOrders != maxOrders + ) { + EquityTier( + requiredTotalNetCollateralUSD, + nextLevelRequiredTotalNetCollateralUSD, + maxOrders, + ) + } else { + existing + } + } + } + Logger.d { "Equity Tier not valid" } + return null + } + } +} + @JsExport @Serializable data class WithdrawalGating( @@ -346,6 +444,7 @@ data class Configs( val network: NetworkConfigs?, val feeTiers: IList?, val feeDiscounts: IList?, + val equityTiers: EquityTiers?, val withdrawalGating: WithdrawalGating?, val withdrawalCapacity: WithdrawalCapacity?, ) { @@ -371,6 +470,11 @@ data class Configs( parser.asList(data["feeDiscounts"]), localizer, ) + val equityTiers = EquityTiers.create( + existing?.equityTiers, + parser, + parser.asMap(data["equityTiers"]), + ) var withdrawalGating = WithdrawalGating.create( existing?.withdrawalGating, parser, @@ -383,12 +487,14 @@ data class Configs( ) return if (existing?.network !== network || existing?.feeTiers != feeTiers || - existing?.feeDiscounts != feeDiscounts + existing?.feeDiscounts != feeDiscounts || + existing?.equityTiers != equityTiers ) { Configs( network, feeTiers, feeDiscounts, + equityTiers, withdrawalGating, withdrawalCapacity, ) @@ -399,6 +505,7 @@ data class Configs( null, null, null, + null, ) } } diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 319a1788b..2e668c1f2 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.7.33' + spec.version = '1.7.34' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''