diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt index 134b3b555..000d44652 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt @@ -562,7 +562,6 @@ data class TransferInput( val errors = parser.asString(route?.get("errors")) val errorMessage: String? = -// prefer route?.get("errorMessage") and default to this if (errors != null) { val errorArray = parser.decodeJsonArray(errors) val firstError = parser.asMap(errorArray?.first()) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessor.kt index d077182d5..3692c7b29 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessor.kt @@ -11,9 +11,6 @@ internal class SkipRouteProcessor(internal val parser: ParserProtocol) { "route.usd_amount_out" to "toAmountUSD", "route.estimated_amount_out" to "toAmount", "swap_price_impact_percent" to "aggregatePriceImpact", -// [Q] we probably need to handle this separately. should return a 4XX error -// "errors" to "errors", - "message" to "errorMessage", // SQUID PARAMS THAT ARE NOW DEPRECATED: // "route.estimate.gasCosts.0.amountUSD" to "gasFee", @@ -65,11 +62,19 @@ internal class SkipRouteProcessor(internal val parser: ParserProtocol) { val payloadProcessor = SkipRoutePayloadProcessor(parser) // TODO: Remove slippage. -// This is just hard coded in our params so we're keeping it to be -// at parity for now. Fast follow squid -> skip migration project to removing max slippage -// because we already show the actual slippage. +// This is just hard coded in our params so we're keeping it to be at parity for now +// Fast follow squid -> skip migration project to removing max slippage +// because we already show the actual price impact. modified.safeSet("slippage", "1") modified.safeSet("requestPayload", payloadProcessor.received(null, payload)) + + val errorCode = parser.value(payload, "code") +// if we have an error code, add the payload as a list of errors +// this allows to match the current errors format. +// TODO: replace errors with errorMessage once we finish migration + if (errorCode != null) { + modified.safeSet("errors", parser.asString(listOf(payload))) + } return modified } } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessorTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessorTests.kt index 9bfbd3ef1..572af180b 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessorTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipRouteProcessorTests.kt @@ -34,4 +34,16 @@ class SkipRouteProcessorTests { ) assertEquals(expected.toString(), result.toString()) } + + @Test + fun testReceivedError() { + val payload = skipRouteMock.payload_error + val result = skipRouteProcessor.received(existing = mapOf(), payload = templateToJson(payload), decimals = 6.0) + val expected = mapOf( + "slippage" to "1", + "requestPayload" to emptyMap(), + "errors" to "[{code=3, message=\"difference in usd value of route input and output is too large. input usd value: 100000.00 output usd value: 98811.81\", details=[{\"@type\":\"type.googleapis.com/google.rpc.ErrorInfo\",\"reason\":\"BAD_PRICE_ERROR\",\"domain\":\"skip.money\",\"metadata\":{}}]}]", + ) + assertEquals(expected.toString(), result.toString()) + } } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipRouteMock.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipRouteMock.kt index 64d79fc32..c430e67fb 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipRouteMock.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/SkipRouteMock.kt @@ -106,5 +106,18 @@ internal class SkipRouteMock { "noble-1" ] } +}""" + internal val payload_error = """ + { + "code": 3, + "message": "difference in usd value of route input and output is too large. input usd value: 100000.00 output usd value: 98811.81", + "details": [ + { + "@type": "type.googleapis.com/google.rpc.ErrorInfo", + "reason": "BAD_PRICE_ERROR", + "domain": "skip.money", + "metadata": {} + } + ] }""" }