Skip to content

Commit

Permalink
Merge branch 'main' into feature/trade_9
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Aug 31, 2024
2 parents 68218c4 + ab649af commit ce24534
Show file tree
Hide file tree
Showing 23 changed files with 238 additions and 40 deletions.
22 changes: 11 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
}
}

plugins {
kotlin("multiplatform") version "1.9.24"
kotlin("native.cocoapods") version "1.9.24"
kotlin("plugin.serialization") version "1.9.24"
kotlin("multiplatform") version "2.0.20"
kotlin("native.cocoapods") version "2.0.20"
kotlin("plugin.serialization") version "2.0.20"
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")
id("com.google.devtools.ksp") version "1.9.24-1.0.20" // needs to be in-sync with Kotlin version. Version before the dash is the compatible Kotlin version.
id("com.google.devtools.ksp") version "2.0.20-1.0.24" // needs to be in-sync with Kotlin version. Version before the dash is the compatible Kotlin version.
}

allprojects {
Expand Down Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.9.9"
version = "1.9.11"

repositories {
google()
Expand Down Expand Up @@ -118,7 +118,7 @@ kotlin {
implementation("io.ktor:ktor-http:$ktorVersion")
implementation("com.ionspin.kotlin:bignum:0.3.8")
implementation("tz.co.asoft:kollections-interoperable:2.0.16")
implementation("me.tatarka.inject:kotlin-inject-runtime:0.6.3")
implementation("me.tatarka.inject:kotlin-inject-runtime:0.7.1")
}
}
val commonTest by getting {
Expand Down Expand Up @@ -146,10 +146,10 @@ kotlin {
// KSP will eventually have better multiplatform support and we'll be able to simply have
// `ksp libs.kotlinInject.compiler` in the dependencies block of each source set
// https://github.com/google/ksp/pull/1021
add("kspJvm", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.6.3")
add("kspJs", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.6.3")
add("kspIosArm64", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.6.3")
add("kspIosSimulatorArm64", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.6.3")
add("kspJvm", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.1")
add("kspJs", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.1")
add("kspIosArm64", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.1")
add("kspIosSimulatorArm64", "me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.1")
}

tasks.wrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import exchange.dydx.abacus.state.internalstate.InternalMarketState
import exchange.dydx.abacus.state.internalstate.InternalMarketSummaryState
import exchange.dydx.abacus.state.internalstate.InternalSubaccountCalculated
import exchange.dydx.abacus.state.internalstate.InternalSubaccountState
import exchange.dydx.abacus.utils.IList
import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.Parser
import kollections.toIList
import kotlinx.datetime.Clock
import kotlinx.serialization.Serializable
import kotlin.js.JsExport
Expand All @@ -22,13 +24,13 @@ import kotlin.time.Duration.Companion.milliseconds
data class VaultDetails(
val totalValue: Double? = null,
val thirtyDayReturnPercent: Double? = null,
val history: List<VaultHistoryEntry>? = null
val history: IList<VaultHistoryEntry>? = null
)

@JsExport
@Serializable
data class VaultPositions(
val positions: List<VaultPosition>? = null,
val positions: IList<VaultPosition>? = null,
)

@JsExport
Expand Down Expand Up @@ -62,7 +64,7 @@ data class CurrentPosition(
data class ThirtyDayPnl(
val percent: Double? = null,
val absolute: Double? = null,
val sparklinePoints: List<Double>? = null
val sparklinePoints: IList<Double>? = null
)

@JsExport
Expand Down Expand Up @@ -125,7 +127,7 @@ object VaultCalculator {
return VaultDetails(
totalValue = totalValue,
thirtyDayReturnPercent = thirtyDayReturnPercent,
history = history,
history = history.toIList(),
)
}

Expand All @@ -140,7 +142,7 @@ object VaultCalculator {

val historiesMap = histories?.vaultsPnl?.associateBy { it.marketId }

return VaultPositions(positions = positions.positions.mapNotNull { calculateVaultPosition(it, historiesMap?.get(it.market), markets?.get(it.market)) })
return VaultPositions(positions = positions.positions.mapNotNull { calculateVaultPosition(it, historiesMap?.get(it.market), markets?.get(it.market)) }.toIList())
}

fun calculateVaultPosition(position: IndexerVaultPosition, history: IndexerVaultHistoricalPnl?, perpetualMarket: PerpetualMarket?): VaultPosition? {
Expand Down Expand Up @@ -225,7 +227,7 @@ object VaultCalculator {
return ThirtyDayPnl(
percent = percentPnl,
absolute = absolutePnl,
sparklinePoints = sparklinePoints,
sparklinePoints = sparklinePoints.toIList(),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.protocols.asTypedObject
import exchange.dydx.abacus.utils.IList
import exchange.dydx.abacus.utils.Parser
import indexer.codegen.IndexerTransferBetweenResponse
import indexer.codegen.IndexerTransferType.DEPOSIT
import indexer.codegen.IndexerTransferType.TRANSFERIN
import indexer.codegen.IndexerTransferType.TRANSFEROUT
import indexer.codegen.IndexerTransferType.WITHDRAWAL
import kollections.toIList
import kotlinx.serialization.Serializable
import kotlin.js.JsExport

Expand All @@ -30,7 +32,7 @@ data class VaultAccount(
val lockedShares: Double?,
val withdrawableUsdc: Double?,
val allTimeReturnUsdc: Double?,
val vaultTransfers: List<VaultTransfer>?,
val vaultTransfers: IList<VaultTransfer>?,
val totalVaultTransfersCount: Int?,
)

Expand Down Expand Up @@ -90,7 +92,7 @@ object VaultAccountCalculator {
},
id = el.id,
)
},
}?.toIList(),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.utils.IList
import kollections.toIList
import kotlinx.serialization.Serializable
import kotlin.js.JsExport

Expand Down Expand Up @@ -92,7 +94,7 @@ data class VaultFormSummaryData(
@JsExport
@Serializable
data class VaultFormValidationResult(
val errors: List<VaultFormValidationError>,
val errors: IList<VaultFormValidationError>,
val submissionData: VaultDepositWithdrawSubmissionData?,
val summaryData: VaultFormSummaryData
)
Expand Down Expand Up @@ -260,7 +262,7 @@ object VaultDepositWithdrawFormValidator {
)

return VaultFormValidationResult(
errors = errors,
errors = errors.toIList(),
submissionData = submissionData,
summaryData = summaryData,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.utils.IList
import indexer.codegen.IndexerAssetPositionResponseObject
import indexer.codegen.IndexerPerpetualPositionResponseObject
import indexer.codegen.IndexerPnlTicksResponseObject
Expand All @@ -9,20 +10,20 @@ import kotlin.js.JsExport
@JsExport
@Serializable
data class IndexerVaultHistoricalPnlResponse(
val vaultOfVaultsPnl: List<IndexerPnlTicksResponseObject>? = null
val vaultOfVaultsPnl: IList<IndexerPnlTicksResponseObject>? = null
)

@JsExport
@Serializable
data class IndexerVaultHistoricalPnl(
val marketId: String? = null,
val historicalPnl: List<IndexerPnlTicksResponseObject>? = null
val historicalPnl: IList<IndexerPnlTicksResponseObject>? = null
)

@JsExport
@Serializable
data class IndexerSubvaultHistoricalPnlResponse(
val vaultsPnl: List<IndexerVaultHistoricalPnl>? = null
val vaultsPnl: IList<IndexerVaultHistoricalPnl>? = null
)

@JsExport
Expand All @@ -37,5 +38,5 @@ data class IndexerVaultPosition(
@JsExport
@Serializable
data class IndexerVaultPositionResponse(
val positions: List<IndexerVaultPosition>? = null
val positions: IList<IndexerVaultPosition>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ enum class AnalyticsEvent {
// Trade
TradePlaceOrderClick,
TradeCancelOrderClick,
TradeCancelAllOrdersClick,
TradePlaceOrder,
TradeCancelOrder,
TradePlaceOrderSubmissionConfirmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface AsyncAbacusStateManagerProtocol {
fun closePositionPayload(): HumanReadablePlaceOrderPayload?
fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload?
fun cancelOrderPayload(orderId: String): HumanReadableCancelOrderPayload?
fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload?
fun depositPayload(): HumanReadableDepositPayload?
fun withdrawPayload(): HumanReadableWithdrawPayload?
fun subaccountTransferPayload(): HumanReadableSubaccountTransferPayload?
Expand All @@ -80,6 +81,7 @@ interface AsyncAbacusStateManagerProtocol {
// Commit changes with params
fun faucet(amount: Double, callback: TransactionCallback)
fun cancelOrder(orderId: String, callback: TransactionCallback)
fun cancelAllOrders(marketId: String?, callback: TransactionCallback)

// Bridge functions.
// If client is not using cancelOrder function, it should call orderCanceled function with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ class V4StateManagerConfigs(

private val includeSvmChains: String
get() {
return if (environment.isMainNet) "" else "&include_svm=true"
return "&include_svm=true"
}
private val includeSvmAssets: String
get() {
return if (environment.isMainNet) "" else "&include_svm_assets=true"
return "&include_svm_assets=true"
}

private val onlyTestnets: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ data class HumanReadableCancelOrderPayload(
val goodTilBlockTime: Int?,
)

@JsExport
@Serializable
data class HumanReadableCancelAllOrdersPayload(
val marketId: String?,
val payloads: IList<HumanReadableCancelOrderPayload>,
)

@JsExport
@Serializable
data class HumanReadableTriggerOrdersPayload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import exchange.dydx.abacus.state.manager.ConfigFile
import exchange.dydx.abacus.state.manager.GasToken
import exchange.dydx.abacus.state.manager.HistoricalPnlPeriod
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -503,6 +504,10 @@ class AsyncAbacusStateManagerV2(
return adaptor?.cancelOrderPayload(orderId)
}

override fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload? {
return adaptor?.cancelAllOrdersPayload(marketId)
}

override fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload? {
return adaptor?.triggerOrdersPayload()
}
Expand Down Expand Up @@ -603,6 +608,15 @@ class AsyncAbacusStateManagerV2(
}
}

override fun cancelAllOrders(marketId: String?, callback: TransactionCallback) {
try {
adaptor?.cancelAllOrders(marketId, callback)
} catch (e: Exception) {
val error = V4TransactionErrors.error(null, e.toString())
callback(false, error, null)
}
}

override fun triggerCompliance(action: ComplianceAction, callback: TransactionCallback) {
try {
adaptor?.triggerCompliance(action, callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.GasToken
import exchange.dydx.abacus.state.manager.HistoricalPnlPeriod
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -56,6 +57,8 @@ import exchange.dydx.abacus.state.v2.supervisor.accountAddress
import exchange.dydx.abacus.state.v2.supervisor.addressRestriction
import exchange.dydx.abacus.state.v2.supervisor.adjustIsolatedMargin
import exchange.dydx.abacus.state.v2.supervisor.adjustIsolatedMarginPayload
import exchange.dydx.abacus.state.v2.supervisor.cancelAllOrders
import exchange.dydx.abacus.state.v2.supervisor.cancelAllOrdersPayload
import exchange.dydx.abacus.state.v2.supervisor.cancelOrder
import exchange.dydx.abacus.state.v2.supervisor.cancelOrderPayload
import exchange.dydx.abacus.state.v2.supervisor.closePosition
Expand Down Expand Up @@ -538,6 +541,10 @@ internal class StateManagerAdaptorV2(
return accounts.cancelOrderPayload(orderId)
}

internal fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload? {
return accounts.cancelAllOrdersPayload(marketId)
}

internal fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload? {
return accounts.triggerOrdersPayload(currentHeight)
}
Expand Down Expand Up @@ -596,6 +603,10 @@ internal class StateManagerAdaptorV2(
accounts.cancelOrder(orderId, callback)
}

internal fun cancelAllOrders(marketId: String?, callback: TransactionCallback) {
accounts.cancelAllOrders(marketId, callback)
}

internal fun orderCanceled(orderId: String) {
accounts.orderCanceled(orderId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import exchange.dydx.abacus.state.changes.StateChanges
import exchange.dydx.abacus.state.manager.ApiData
import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -1180,6 +1181,10 @@ internal fun AccountSupervisor.cancelOrderPayload(
return subaccount?.cancelOrderPayload(orderId)
}

internal fun AccountSupervisor.cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload? {
return subaccount?.cancelAllOrdersPayload(marketId)
}

internal fun AccountSupervisor.depositPayload(): HumanReadableDepositPayload? {
return subaccount?.depositPayload()
}
Expand Down Expand Up @@ -1231,6 +1236,10 @@ internal fun AccountSupervisor.cancelOrder(orderId: String, callback: Transactio
subaccount?.cancelOrder(orderId = orderId, callback = callback)
}

internal fun AccountSupervisor.cancelAllOrders(marketId: String?, callback: TransactionCallback) {
subaccount?.cancelAllOrders(marketId, callback)
}

internal fun AccountSupervisor.orderCanceled(orderId: String) {
subaccount?.orderCanceled(orderId)
}
Expand Down
Loading

0 comments on commit ce24534

Please sign in to comment.