Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse out of gas error #719

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.13.2"
version = "1.13.3"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down Expand Up @@ -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
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand Down