Skip to content

Commit 3745cbb

Browse files
authored
Clean up output data structure (#806)
1 parent ee3aa46 commit 3745cbb

33 files changed

+514
-4687
lines changed

src/commonMain/kotlin/exchange.dydx.abacus/calculator/MarginCalculator.kt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,6 @@ internal object MarginCalculator {
406406
return iListOf(subaccountNumber)
407407
}
408408

409-
fun getChangedSubaccountNumbersDeprecated(
410-
parser: ParserProtocol,
411-
account: Map<String, Any>?,
412-
subaccountNumber: Int,
413-
tradeInput: Map<String, Any>?
414-
): IList<Int> {
415-
val childSubaccountNumber = getChildSubaccountNumberForIsolatedMarginTradeDeprecated(parser, account, subaccountNumber, tradeInput)
416-
if (childSubaccountNumber != null && subaccountNumber != childSubaccountNumber) {
417-
return iListOf(subaccountNumber, childSubaccountNumber)
418-
}
419-
420-
return iListOf(subaccountNumber)
421-
}
422-
423409
fun getChildSubaccountNumberForIsolatedMarginClosePosition(
424410
account: InternalAccountState?,
425411
subaccountNumber: Int,
@@ -430,17 +416,6 @@ internal object MarginCalculator {
430416
return position?.subaccountNumber ?: subaccountNumber
431417
}
432418

433-
fun getChildSubaccountNumberForIsolatedMarginClosePositionDeprecated(
434-
parser: ParserProtocol,
435-
account: Map<String, Any>?,
436-
subaccountNumber: Int,
437-
tradeInput: Map<String, Any>?
438-
): Int {
439-
val marketId = parser.asString(tradeInput?.get("marketId")) ?: return subaccountNumber
440-
val position = findExistingPositionDeprecated(parser, account, marketId, subaccountNumber)
441-
return parser.asInt(position?.get("subaccountNumber")) ?: subaccountNumber
442-
}
443-
444419
/**
445420
* @description Calculate the amount of collateral to transfer into child subaccount for an isolated margin trade.
446421
*/

src/commonMain/kotlin/exchange.dydx.abacus/output/Asset.kt

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package exchange.dydx.abacus.output
22

3-
import exchange.dydx.abacus.protocols.LocalizerProtocol
4-
import exchange.dydx.abacus.protocols.ParserProtocol
53
import exchange.dydx.abacus.utils.IList
6-
import exchange.dydx.abacus.utils.Logger
74
import kollections.JsExport
85
import kotlinx.serialization.Serializable
96

@@ -18,51 +15,7 @@ data class AssetResources(
1815
val secondaryDescription: String?,
1916
val primaryDescriptionKey: String?,
2017
val secondaryDescriptionKey: String?
21-
) {
22-
companion object {
23-
internal fun create(
24-
existing: AssetResources?,
25-
parser: ParserProtocol,
26-
data: Map<*, *>?,
27-
localizer: LocalizerProtocol?,
28-
): AssetResources? {
29-
data?.let {
30-
val websiteLink = parser.asString(data["websiteLink"])
31-
val whitepaperLink = parser.asString(data["whitepaperLink"])
32-
val coinMarketCapsLink = parser.asString(data["coinMarketCapsLink"])
33-
val imageUrl = parser.asString(data["imageUrl"])
34-
val primaryDescriptionKey = parser.asString(data["primaryDescriptionKey"])
35-
val secondaryDescriptionKey = parser.asString(data["secondaryDescriptionKey"])
36-
return if (existing?.websiteLink != websiteLink ||
37-
existing?.whitepaperLink != whitepaperLink ||
38-
existing?.coinMarketCapsLink != coinMarketCapsLink ||
39-
existing?.imageUrl != imageUrl ||
40-
existing?.primaryDescriptionKey != primaryDescriptionKey ||
41-
existing?.secondaryDescriptionKey != secondaryDescriptionKey
42-
) {
43-
val primaryDescription =
44-
if (primaryDescriptionKey != null) localizer?.localize(primaryDescriptionKey) else null
45-
val secondaryDescription =
46-
if (secondaryDescriptionKey != null) localizer?.localize(secondaryDescriptionKey) else null
47-
AssetResources(
48-
websiteLink,
49-
whitepaperLink,
50-
coinMarketCapsLink,
51-
imageUrl,
52-
primaryDescription,
53-
secondaryDescription,
54-
primaryDescriptionKey,
55-
secondaryDescriptionKey,
56-
)
57-
} else {
58-
existing
59-
}
60-
}
61-
Logger.d { "Asset Resources not valid" }
62-
return null
63-
}
64-
}
65-
}
18+
)
6619

6720
@JsExport
6821
@Serializable
@@ -72,42 +25,6 @@ data class Asset(
7225
val tags: IList<String>?,
7326
val resources: AssetResources?
7427
) {
75-
companion object {
76-
internal fun create(
77-
existing: Asset?,
78-
parser: ParserProtocol,
79-
data: Map<*, *>?,
80-
localizer: LocalizerProtocol?,
81-
): Asset? {
82-
data?.let {
83-
val id = parser.asString(data["id"])
84-
val resourcesData = parser.asMap(data["resources"])
85-
if (id != null) {
86-
val resources = AssetResources.create(
87-
existing?.resources,
88-
parser,
89-
resourcesData,
90-
localizer,
91-
)
92-
val name = parser.asString(data["name"])
93-
val tags = parser.asStrings(data["tags"])
94-
95-
return if (existing?.id != id ||
96-
existing.name != name ||
97-
existing.tags != tags ||
98-
existing.resources !== resources
99-
) {
100-
Asset(id, name, tags, resources)
101-
} else {
102-
existing
103-
}
104-
}
105-
}
106-
Logger.d { "Asset not valid" }
107-
return null
108-
}
109-
}
110-
11128
val displayableAssetId: String get() {
11229
return id.split(",").firstOrNull() ?: ""
11330
}

0 commit comments

Comments
 (0)