Skip to content

Commit

Permalink
Merge branch 'main' into features/mintscanBase
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed May 22, 2024
2 parents 08ab353 + 3dd9c42 commit 8729364
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.7.26"
version = "1.7.27"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal class MarketProcessor(parser: ParserProtocol, private val calculateSpar

private val configsKeyMap = mapOf(
"string" to mapOf(
"perpetualMarketType" to "perpetualMarketType",
"marketType" to "perpetualMarketType",
),
"double" to mapOf(
"maintenanceMarginFraction" to "maintenanceMarginFraction",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ internal fun TradingStateMachine.updateTradeInputFromMarket(
val marketId = parser.asString(trade["marketId"])
if (marketId != null && account != null) {
val existingMarginMode = findExistingMarginMode(account, marketId, subaccountNumber)
?: findMarketMarginMode(this.marketsSummary, marketId)
if (existingMarginMode != null) {
modified["marginMode"] = existingMarginMode
if (existingMarginMode == "ISOLATED" && parser.asDouble(trade["targetLeverage"]) == null) {
Expand Down Expand Up @@ -154,12 +155,14 @@ private fun TradingStateMachine.findExistingMarginMode(
parser.asString(parser.value(it, "marketId")) == marketId
}
if (order != null) {
return if (parser.asInt(
parser.value(
order,
"subaccountNumber",
),
) ?: subaccountNumber != subaccountNumber
return if ((
parser.asInt(
parser.value(
order,
"subaccountNumber",
),
) ?: subaccountNumber
) != subaccountNumber
) {
"ISOLATED"
} else {
Expand All @@ -169,6 +172,14 @@ private fun TradingStateMachine.findExistingMarginMode(
return null
}

private fun TradingStateMachine.findMarketMarginMode(
marketsSummary: Map<String, Any>?,
marketId: String
): String? {
val marginMode = parser.asString(parser.value(marketsSummary, "markets.$marketId.configs.perpetualMarketType"))
return marginMode ?: "CROSS"
}

internal fun TradingStateMachine.initiateTrade(
marketId: String?,
subaccountNumber: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,38 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
}
""".trimIndent(),
)

test(
{
perp.tradeInMarket("AVAX-USD", 0)
},
"""
{
"input": {
"current": "trade",
"trade": {
"marginMode": "ISOLATED"
}
}
}
""".trimIndent(),
)

test(
{
perp.tradeInMarket("LINK-USD", 0)
},
"""
{
"input": {
"current": "trade",
"trade": {
"marginMode": "CROSS"
}
}
}
""".trimIndent(),
)
}

private fun testSubaccountChannelData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ internal class MarketsChannelMock {
"atomicResolution":-10,
"quantumConversionExponent":-9,
"stepBaseQuantums":1000000,
"subticksPerTick":100000
"subticksPerTick":100000,
"marketType":"ISOLATED"
},
"SUSHI-USD": {
"market": "SUSHI-USD",
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.7.26'
spec.version = '1.7.27'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 8729364

Please sign in to comment.