From 314df05f8c2ddde447de396985da035335dfc140 Mon Sep 17 00:00:00 2001 From: aforaleka Date: Fri, 18 Oct 2024 15:05:34 -0400 Subject: [PATCH] parse out of gas error --- build.gradle.kts | 2 +- .../state/app/adaptors/V4TransactionErrors.kt | 12 ++++++++++++ .../state/v2/supervisor/NetworkHelper.kt | 4 ++++ v4_abacus.podspec | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a81f4c759..b45c19f49 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.13.2" +version = "1.13.3" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/app/adaptors/V4TransactionErrors.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/app/adaptors/V4TransactionErrors.kt index ba63696ae..bcfc3fa4c 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/app/adaptors/V4TransactionErrors.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/app/adaptors/V4TransactionErrors.kt @@ -6,6 +6,7 @@ import exchange.dydx.abacus.responses.ParsingErrorType class V4TransactionErrors { companion object { private const val QUERY_RESULT_ERROR_PREFIX = "Query failed" + private const val OUT_OF_GAS_ERROR_RAW_LOG_PREFIX = "out of gas" private val FAILED_SUBACCOUNT_UPDATE_RESULT_PATTERN = Regex("""Subaccount with id \{[^}]+\} failed with UpdateResult:\s*([A-Za-z]+):""") fun error(code: Int?, message: String?, codespace: String? = null): ParsingError? { @@ -43,6 +44,17 @@ class V4TransactionErrors { ) } } + + fun parseErrorFromRawLog(rawLog: String): ParsingError? { + return if (rawLog.startsWith(OUT_OF_GAS_ERROR_RAW_LOG_PREFIX)) { + return ParsingError( + ParsingErrorType.BackendError, + "Out of gas: inaccurate gas estimation for transaction", + ) + } else { + null + } + } } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt index 7864ebf5f..997ffd3b4 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkHelper.kt @@ -533,11 +533,15 @@ class NetworkHelper( val result = parser.decodeJsonObject(response) if (result != null) { val error = parser.asMap(result["error"]) + val rawLog = parser.asString(result["rawLog"]) if (error != null) { val message = parser.asString(error["message"]) val code = parser.asInt(error["code"]) val codespace = parser.asString(error["codespace"]) return V4TransactionErrors.error(code, message, codespace) + } else if (rawLog != null) { + // certain tx results (e.g. out of gas) are not error but should still be treated as one + return V4TransactionErrors.parseErrorFromRawLog(rawLog) } else { null } diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 63934d6a3..2c23e4b45 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.13.2' + spec.version = '1.13.3' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''