From 5b3248609543a6be25fcad5bf4ba42de22e0b488 Mon Sep 17 00:00:00 2001 From: aleka Date: Fri, 20 Sep 2024 16:40:43 -0400 Subject: [PATCH] close all positions: return payload (#668) --- build.gradle.kts | 2 +- .../state/manager/AsyncAbacusStateManagerProtocol.kt | 2 +- .../state/v2/manager/AsyncAbacusStateManagerV2.kt | 5 +++-- .../state/v2/manager/StateManagerAdaptorV2.kt | 4 ++-- .../state/v2/supervisor/AccountSupervisor.kt | 4 ++-- .../state/v2/supervisor/AccountsSupervisor.kt | 4 ++-- v4_abacus.podspec | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4fb39184d..783150911 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.11.13" +version = "1.11.14" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt index 76ae9413f..b3cc627ff 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt @@ -88,7 +88,7 @@ interface AsyncAbacusStateManagerProtocol { fun faucet(amount: Double, callback: TransactionCallback) fun cancelOrder(orderId: String, callback: TransactionCallback) fun cancelAllOrders(marketId: String?, callback: TransactionCallback) - fun closeAllPositions(callback: TransactionCallback) + fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? // Bridge functions. // If client is not using cancelOrder function, it should call orderCanceled function with diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt index fbc414c2a..a8b5123be 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt @@ -630,12 +630,13 @@ class AsyncAbacusStateManagerV2( } } - override fun closeAllPositions(callback: TransactionCallback) { - try { + override fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return try { adaptor?.closeAllPositions(callback) } catch (e: Exception) { val error = V4TransactionErrors.error(null, e.toString()) callback(false, error, null) + null } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt index 0c78bcd25..d8782dc35 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt @@ -615,8 +615,8 @@ internal class StateManagerAdaptorV2( accounts.cancelAllOrders(marketId, callback) } - internal fun closeAllPositions(callback: TransactionCallback) { - accounts.closeAllPositions(currentHeight, callback) + internal fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return accounts.closeAllPositions(currentHeight, callback) } internal fun orderCanceled(orderId: String) { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt index 9118726ab..1a3dcec02 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt @@ -1214,8 +1214,8 @@ internal fun AccountSupervisor.cancelAllOrders(marketId: String?, callback: Tran subaccount?.cancelAllOrders(marketId, callback) } -internal fun AccountSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback) { - subaccount?.closeAllPositions(currentHeight, callback) +internal fun AccountSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return subaccount?.closeAllPositions(currentHeight, callback) } internal fun AccountSupervisor.orderCanceled(orderId: String) { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt index 9b33a07e9..0fb8da7b0 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt @@ -366,8 +366,8 @@ internal fun AccountsSupervisor.cancelAllOrders(marketId: String?, callback: Tra account?.cancelAllOrders(marketId, callback) } -internal fun AccountsSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback) { - account?.closeAllPositions(currentHeight, callback) +internal fun AccountsSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return account?.closeAllPositions(currentHeight, callback) } internal fun AccountsSupervisor.orderCanceled(orderId: String) { diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 7c5b99946..fdffb2e79 100644 --- a/v4_abacus.podspec +++ b/v4_abacus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'v4_abacus' - spec.version = '1.11.13' + spec.version = '1.11.14' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''