Skip to content

Commit

Permalink
feat: add eta to state [OTE-832] (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam authored Sep 26, 2024
1 parent 4ccc333 commit 3bc1820
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
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.11.24"
version = "1.12.0"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ internal class TransferInputCalculator(val parser: ParserProtocol) {
val exchangeRate = parser.asDouble(parser.value(transfer, "route.exchangeRate"))
summary.safeSet("exchangeRate", exchangeRate)

val estimatedRouteDuration =
parser.asDouble(parser.value(transfer, "route.estimatedRouteDuration"))
summary.safeSet("estimatedRouteDuration", estimatedRouteDuration)
val estimatedRouteDurationSeconds =
parser.asDouble(parser.value(transfer, "route.estimatedRouteDurationSeconds"))
summary.safeSet("estimatedRouteDurationSeconds", estimatedRouteDurationSeconds)

if (usdcSize != null) {
summary.safeSet("usdcSize", usdcSize)
Expand Down Expand Up @@ -204,9 +204,9 @@ internal class TransferInputCalculator(val parser: ParserProtocol) {
val exchangeRate = parser.asDouble(parser.value(transfer, "route.exchangeRate"))
summary.safeSet("exchangeRate", exchangeRate)

val estimatedRouteDuration =
parser.asDouble(parser.value(transfer, "route.estimatedRouteDuration"))
summary.safeSet("estimatedRouteDuration", estimatedRouteDuration)
val estimatedRouteDurationSeconds =
parser.asDouble(parser.value(transfer, "route.estimatedRouteDurationSeconds"))
summary.safeSet("estimatedRouteDurationSeconds", estimatedRouteDurationSeconds)

val bridgeFee = parser.asDouble(parser.value(transfer, "route.bridgeFee"))
summary.safeSet("bridgeFee", bridgeFee)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class TransferInputCalculatorV2(

val slippage = parser.asDouble(parser.value(route, "slippage"))
val exchangeRate = parser.asDouble(parser.value(route, "exchangeRate"))
val estimatedRouteDuration = parser.asDouble(parser.value(route, "estimatedRouteDuration"))
val estimatedRouteDurationSeconds = parser.asDouble(parser.value(route, "estimatedRouteDurationSeconds"))
val bridgeFee = parser.asDouble(parser.value(route, "bridgeFee"))
val gasFee = parser.asDouble(parser.value(route, "gasFee"))
val toAmount = parser.asDouble(parser.value(route, "toAmount"))
Expand All @@ -74,7 +74,7 @@ internal class TransferInputCalculatorV2(
fee = fee,
slippage = slippage,
exchangeRate = exchangeRate,
estimatedRouteDuration = estimatedRouteDuration,
estimatedRouteDurationSeconds = estimatedRouteDurationSeconds,
usdcSize = usdcSize,
bridgeFee = bridgeFee,
gasFee = gasFee,
Expand All @@ -94,7 +94,7 @@ internal class TransferInputCalculatorV2(

val slippage = parser.asDouble(parser.value(route, "slippage"))
val exchangeRate = parser.asDouble(parser.value(route, "exchangeRate"))
val estimatedRouteDuration = parser.asDouble(parser.value(route, "estimatedRouteDuration"))
val estimatedRouteDurationSeconds = parser.asDouble(parser.value(route, "estimatedRouteDurationSeconds"))
val bridgeFee = parser.asDouble(parser.value(route, "bridgeFee"))
val gasFee = parser.asDouble(parser.value(route, "gasFee"))
val toAmount = parser.asDouble(parser.value(route, "toAmount"))
Expand All @@ -109,7 +109,7 @@ internal class TransferInputCalculatorV2(
fee = fee,
slippage = slippage,
exchangeRate = exchangeRate,
estimatedRouteDuration = estimatedRouteDuration,
estimatedRouteDurationSeconds = estimatedRouteDurationSeconds,
usdcSize = usdcSize,
bridgeFee = bridgeFee,
gasFee = gasFee,
Expand All @@ -131,7 +131,7 @@ internal class TransferInputCalculatorV2(
fee = null,
slippage = null,
exchangeRate = null,
estimatedRouteDuration = null,
estimatedRouteDurationSeconds = null,
bridgeFee = null,
toAmount = null,
toAmountMin = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ data class TransferInputSummary(
val filled: Boolean,
val slippage: Double?,
val exchangeRate: Double?,
val estimatedRouteDuration: Double?,
val estimatedRouteDurationSeconds: Double?,
val bridgeFee: Double?,
val gasFee: Double?,
val toAmount: Double?,
Expand All @@ -377,7 +377,7 @@ data class TransferInputSummary(
val filled = parser.asBool(data["filled"]) ?: false
val slippage = parser.asDouble(data["slippage"])
val exchangeRate = parser.asDouble(data["exchangeRate"])
val estimatedRouteDuration = parser.asDouble(data["estimatedRouteDuration"])
val estimatedRouteDurationSeconds = parser.asDouble(data["estimatedRouteDurationSeconds"])
val bridgeFee = parser.asDouble(data["bridgeFee"])
val gasFee = parser.asDouble(data["gasFee"])
val toAmount = parser.asDouble(data["toAmount"])
Expand All @@ -391,7 +391,7 @@ data class TransferInputSummary(
existing?.filled != filled ||
existing.slippage != slippage ||
existing.exchangeRate != exchangeRate ||
existing.estimatedRouteDuration != estimatedRouteDuration ||
existing.estimatedRouteDurationSeconds != estimatedRouteDurationSeconds ||
existing.bridgeFee != bridgeFee ||
existing.gasFee != gasFee ||
existing.toAmount != toAmount ||
Expand All @@ -406,7 +406,7 @@ data class TransferInputSummary(
filled,
slippage,
exchangeRate,
estimatedRouteDuration,
estimatedRouteDurationSeconds,
bridgeFee,
gasFee,
toAmount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class SkipRouteProcessor(internal val parser: ParserProtocol) {
"route.estimated_amount_out" to "toAmount",
"route.swap_price_impact_percent" to "aggregatePriceImpact",
"route.warning" to "warning",

"route.estimated_route_duration_seconds" to "estimatedRouteDurationSeconds",
// SQUID PARAMS THAT ARE NOW DEPRECATED:
// "route.estimate.gasCosts.0.amountUSD" to "gasFee",
// "route.estimate.exchangeRate" to "exchangeRate",
Expand Down Expand Up @@ -72,6 +72,8 @@ internal class SkipRouteProcessor(internal val parser: ParserProtocol) {
): Map<String, Any> {
val modified = BaseProcessor(parser).transform(existing, payload, keyMap)

modified.safeSet("estimatedRouteDurationSeconds", parser.value(payload, "route.estimated_route_duration_seconds"))

var bridgeFees = findFee(payload, "BRIDGE") ?: 0.0
// TODO: update web UI to show smart relay fees
// For now we're just bundling it with the bridge fees
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal fun TransferInputSummary.Companion.safeCreate(existing: TransferInputSu
filled = false,
slippage = null,
exchangeRate = null,
estimatedRouteDuration = null,
estimatedRouteDurationSeconds = null,
bridgeFee = null,
gasFee = null,
toAmount = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import exchange.dydx.abacus.utils.DEFAULT_GAS_PRICE
import exchange.dydx.abacus.utils.JsonEncoder
import exchange.dydx.abacus.utils.Parser
import exchange.dydx.abacus.utils.toJsonArray
import exchange.dydx.abacus.utils.toJsonElement
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -54,17 +55,20 @@ class SkipRouteProcessorTests {
val expected = mapOf(
"toAmountUSD" to 1498.18,
"toAmount" to 1499.8,
"estimatedRouteDurationSeconds" to 25,
"bridgeFee" to .2,
"slippage" to "1",
"requestPayload" to mapOf(
"data" to "mock-encoded-solana-tx",
"fromChainId" to "solana",
"fromAddress" to "98bVPZQCHZmCt9v3ni9kwtjKgLuzHBpstQkdPyAucBNx",
"toChainId" to "noble-1",
"toAddress" to "uusdc",
"data" to "mock-encoded-solana-tx",
),
)
assertEquals(expected, result)
// Sometimes assertEquals behaves strangely where it insists on comparing the memory address.
// When this happens I need to serialize the objects first. This behavior appear to be non-deterministic.
assertEquals(expected.toJsonElement(), result.toJsonElement())
}

/**
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.11.24'
spec.version = '1.12.0'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 3bc1820

Please sign in to comment.