Skip to content

Commit

Permalink
transform skip errors into same format as squid err res for now
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed Jun 4, 2024
1 parent 473871c commit a499f76
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any>(),
"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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
]
}"""
}

0 comments on commit a499f76

Please sign in to comment.