Skip to content

Commit

Permalink
Merge branch 'main' into cosmos-wallet-connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored May 29, 2024
2 parents 73656bb + 33be706 commit 9bd6a27
Show file tree
Hide file tree
Showing 43 changed files with 412 additions and 520 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.36"
version = "1.7.40"

repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ complexity:
LargeClass:
threshold: 1000 # up from 600
LongMethod:
threshold: 100 # up from 60
active: false
TooManyFunctions:
active: false
NestedBlockDepth:
Expand Down
106 changes: 48 additions & 58 deletions integration/iOS/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import exchange.dydx.abacus.calculator.SlippageConstants.STOP_MARKET_ORDER_SLIPP
import exchange.dydx.abacus.calculator.SlippageConstants.STOP_MARKET_ORDER_SLIPPAGE_BUFFER_MAJOR_MARKET
import exchange.dydx.abacus.calculator.SlippageConstants.TAKE_PROFIT_MARKET_ORDER_SLIPPAGE_BUFFER
import exchange.dydx.abacus.calculator.SlippageConstants.TAKE_PROFIT_MARKET_ORDER_SLIPPAGE_BUFFER_MAJOR_MARKET
import exchange.dydx.abacus.output.input.MarginMode
import exchange.dydx.abacus.protocols.ParserProtocol
import exchange.dydx.abacus.state.manager.EnvironmentFeatureFlags
import exchange.dydx.abacus.utils.Numeric
Expand Down Expand Up @@ -363,12 +364,9 @@ internal class TradeInputCalculator(
when (marginMode) {
"ISOLATED" -> {
// TODO: When the collateral of child subaccounts is implemented, return from here. The below code is the CROSS implementation.
val currentNotionalTotal =
parser.asDouble(parser.value(position, "notionalTotal.current"))
val postOrderNotionalTotal =
parser.asDouble(parser.value(position, "notionalTotal.postOrder"))
val mmf =
parser.asDouble(parser.value(market, "configs.maintenanceMarginFraction"))
val currentNotionalTotal = parser.asDouble(parser.value(position, "notionalTotal.current"))
val postOrderNotionalTotal = parser.asDouble(parser.value(position, "notionalTotal.postOrder"))
val mmf = parser.asDouble(parser.value(market, "configs.maintenanceMarginFraction"))
if (currentNotionalTotal != null && mmf != null) {
if (postOrderNotionalTotal != null) {
return postOrderNotionalTotal.times(mmf)
Expand Down Expand Up @@ -874,14 +872,24 @@ internal class TradeInputCalculator(
): List<Any>? {
val type = parser.asString(trade["type"])
return when (type) {
"MARKET" ->
listOf(
sizeField(),
leverageField(),
bracketsField(),
marginModeField(market, account, subaccount),
reduceOnlyField(),
).filterNotNull()
"MARKET" -> {
val marginMode = parser.asString(trade["marginMode"])
return when (MarginMode.invoke(marginMode)) {
MarginMode.isolated -> listOf(
sizeField(),
bracketsField(),
marginModeField(market, account, subaccount),
reduceOnlyField(),
).filterNotNull()
else -> listOf(
sizeField(),
leverageField(),
bracketsField(),
marginModeField(market, account, subaccount),
reduceOnlyField(),
).filterNotNull()
}
}

"LIMIT" -> {
val timeInForce = parser.asString(trade["timeInForce"])
Expand Down
14 changes: 12 additions & 2 deletions src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package exchange.dydx.abacus.output

import exchange.dydx.abacus.output.input.MarginMode
import exchange.dydx.abacus.output.input.OrderSide
import exchange.dydx.abacus.output.input.OrderStatus
import exchange.dydx.abacus.output.input.OrderTimeInForce
Expand Down Expand Up @@ -255,6 +256,7 @@ data class SubaccountPosition(
val marginUsage: TradeStatesWithDoubleValues,
val quoteBalance: TradeStatesWithDoubleValues, // available for isolated market position
val equity: TradeStatesWithDoubleValues, // available for isolated market position
val marginMode: MarginMode?
) {
companion object {
internal fun create(
Expand Down Expand Up @@ -383,6 +385,7 @@ data class SubaccountPosition(
parser,
parser.asMap(data["equity"]),
)
val marginMode = parser.asString(data["marginMode"])?.let { MarginMode.invoke(it) }

return if (existing?.id != id ||
existing.assetId != assetId ||
Expand Down Expand Up @@ -410,7 +413,8 @@ data class SubaccountPosition(
existing.freeCollateral !== freeCollateral ||
existing.marginUsage !== marginUsage ||
existing.quoteBalance !== quoteBalance ||
existing.equity !== equity
existing.equity !== equity ||
existing.marginMode != marginMode
) {
val side = positionSide(size)
SubaccountPosition(
Expand Down Expand Up @@ -442,6 +446,7 @@ data class SubaccountPosition(
marginUsage,
quoteBalance,
equity,
marginMode,
)
} else {
existing
Expand Down Expand Up @@ -662,6 +667,7 @@ data class SubaccountOrder(
val reduceOnly: Boolean,
val cancelReason: String?,
val resources: SubaccountOrderResources,
val marginMode: MarginMode?
) {
companion object {
internal fun create(
Expand Down Expand Up @@ -695,6 +701,7 @@ data class SubaccountOrder(
val resources = parser.asMap(data["resources"])?.let {
SubaccountOrderResources.create(existing?.resources, parser, it, localizer)
}
val marginMode = parser.asString(data["marginMode"])?.let { MarginMode.invoke(it) }
if (id != null && marketId != null && type != null && side != null && status != null && price != null && size != null &&
resources != null
) {
Expand Down Expand Up @@ -744,7 +751,9 @@ data class SubaccountOrder(
existing.postOnly != postOnly ||
existing.reduceOnly != reduceOnly ||
existing.cancelReason != cancelReason ||
existing.resources !== resources
existing.resources !== resources ||
existing.subaccountNumber != subaccountNumber ||
existing.marginMode != marginMode
) {
SubaccountOrder(
subaccountNumber,
Expand Down Expand Up @@ -774,6 +783,7 @@ data class SubaccountOrder(
reduceOnly,
cancelReason,
resources,
marginMode,
)
} else {
existing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exchange.dydx.abacus.output.input

import exchange.dydx.abacus.protocols.ParserProtocol
import exchange.dydx.abacus.state.internalstate.InternalState
import exchange.dydx.abacus.state.manager.V4Environment
import exchange.dydx.abacus.utils.IList
import exchange.dydx.abacus.utils.Logger
Expand Down Expand Up @@ -39,7 +40,8 @@ data class Input(
existing: Input?,
parser: ParserProtocol,
data: Map<*, *>?,
environment: V4Environment?
environment: V4Environment?,
internalState: InternalState?
): Input? {
Logger.d { "creating Input\n" }

Expand All @@ -50,7 +52,7 @@ data class Input(
val closePosition =
ClosePositionInput.create(existing?.closePosition, parser, parser.asMap(data["closePosition"]))
val transfer =
TransferInput.create(existing?.transfer, parser, parser.asMap(data["transfer"]), environment)
TransferInput.create(existing?.transfer, parser, parser.asMap(data["transfer"]), environment, internalState?.transfer)
val triggerOrders =
TriggerOrdersInput.create(existing?.triggerOrders, parser, parser.asMap(data["triggerOrders"]))
val adjustIsolatedMargin =
Expand Down
Loading

0 comments on commit 9bd6a27

Please sign in to comment.