Skip to content

Commit

Permalink
Merge branch 'main' into mulan-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed Apr 22, 2024
2 parents 4095ce2 + 5525080 commit 58bc0e3
Show file tree
Hide file tree
Showing 15 changed files with 1,624 additions and 147 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/SpotlessCheck.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
pull_request:
paths:
- '**/*.kt'

jobs:
spotless:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: spotless
run: |
./gradlew spotlessCheck
detekt:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: detekt
run: |
./gradlew detektMetadataMain
10 changes: 9 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ plugins {
id("maven-publish")
id("dev.petuska.npm.publish") version "3.4.2"
id("com.diffplug.spotless") version "6.25.0"
id("io.gitlab.arturbosch.detekt") version("1.23.3")
}

allprojects {
Expand Down Expand Up @@ -48,7 +49,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.6.41"
version = "1.6.42"

repositories {
google()
Expand Down Expand Up @@ -174,6 +175,13 @@ kotlin {
}
}

detekt {
toolVersion = "1.23.3"
config.setFrom(file("detekt.yml"))
baseline = file("detekt-baseline.xml")
buildUponDefaultConfig = true
}

npmPublish {
organization.set("dydxprotocol")
readme.set(rootDir.resolve("README.md"))
Expand Down
1,424 changes: 1,424 additions & 0 deletions detekt-baseline.xml

Large diffs are not rendered by default.

Empty file added detekt.yml
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class AccountTransformer() {
market: Map<String, Any>?,
parser: ParserProtocol,
period: String,
usePessimisticCollateralCheck: Boolean
usePessimisticCollateralCheck: Boolean,
useOptimisticCollateralCheck: Boolean
): Map<String, Any>? {
val modified = account?.mutable() ?: return null
val subaccount = if (subaccountNumber != null) {
Expand All @@ -27,7 +28,15 @@ class AccountTransformer() {
null
}
val modifiedSubaccount =
subaccountTransformer.applyTradeToSubaccount(subaccount, trade, market, parser, period, usePessimisticCollateralCheck)
subaccountTransformer.applyTradeToSubaccount(
subaccount,
trade,
market,
parser,
period,
usePessimisticCollateralCheck,
useOptimisticCollateralCheck,
)
modified.safeSet("subaccounts.$subaccountNumber", modifiedSubaccount)
return modified
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ internal class SubaccountTransformer {
limitPrice: Double?,
isBuying: Boolean,
usePessimisticPrice: Boolean,
useOptimisticPrice: Boolean,
): Double? {
if (usePessimisticPrice) {
oraclePrice?.let { oraclePrice ->
limitPrice?.let { limitPrice ->
oraclePrice?.let { oraclePrice ->
limitPrice?.let { limitPrice ->
if (usePessimisticPrice) {
return if (isBuying) {
max(oraclePrice, limitPrice)
} else {
min(oraclePrice, limitPrice)
}
} else if (useOptimisticPrice) {
return if (isBuying) {
min(oraclePrice, limitPrice)
} else {
max(oraclePrice, limitPrice)
}
}
}
}
Expand All @@ -49,6 +56,7 @@ internal class SubaccountTransformer {
trade: Map<String, Any>,
market: Map<String, Any>?,
usePessimisticCollateralCheck: Boolean,
useOptimisticCollateralCheck: Boolean,
): Map<String, Any>? {
val marketId = parser.asString(trade["marketId"])
val side = parser.asString(trade["side"])
Expand All @@ -64,6 +72,7 @@ internal class SubaccountTransformer {
originalPrice,
side == "BUY",
usePessimisticCollateralCheck,
useOptimisticCollateralCheck,
)
} ?: originalPrice
val size = (
Expand Down Expand Up @@ -196,10 +205,17 @@ internal class SubaccountTransformer {
market: Map<String, Any>?,
parser: ParserProtocol,
period: String,
usePessimisticCollateralCheck: Boolean
usePessimisticCollateralCheck: Boolean,
useOptimisticCollateralCheck: Boolean,
): Map<String, Any>? {
if (subaccount != null) {
val delta = deltaFromTrade(parser, trade, market, usePessimisticCollateralCheck)
val delta = deltaFromTrade(
parser,
trade,
market,
usePessimisticCollateralCheck,
useOptimisticCollateralCheck,
)
return applyDeltaToSubaccount(subaccount, delta, parser, period)
}
return subaccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ internal class TradeInputCalculator(
parser,
"postOrder",
featureFlags.usePessimisticCollateralCheck,
featureFlags.useOptimisticCollateralCheck,
),
)
modified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ data class EnvironmentLinks(
data class EnvironmentFeatureFlags(
val reduceOnlySupported: Boolean,
val usePessimisticCollateralCheck: Boolean,
val useOptimisticCollateralCheck: Boolean,
val withdrawalSafetyEnabled: Boolean,
) {
companion object {
Expand All @@ -112,11 +113,13 @@ data class EnvironmentFeatureFlags(
): EnvironmentFeatureFlags {
val reduceOnlySupported = parser.asBool(data?.get("reduceOnlySupported")) ?: false
val usePessimisticCollateralCheck = parser.asBool(data?.get("usePessimisticCollateralCheck")) ?: false
val useOptimisticCollateralCheck = parser.asBool(data?.get("useOptimisticCollateralCheck")) ?: false
val withdrawalSafetyEnabled = parser.asBool(data?.get("withdrawalSafetyEnabled")) ?: false

return EnvironmentFeatureFlags(
reduceOnlySupported,
usePessimisticCollateralCheck,
useOptimisticCollateralCheck,
withdrawalSafetyEnabled,
)
}
Expand Down
Loading

0 comments on commit 58bc0e3

Please sign in to comment.