Skip to content

Commit

Permalink
feat: skip processor base [OTE-345] (#387)
Browse files Browse the repository at this point in the history
Co-authored-by: mobile-build-bot-git <[email protected]>
  • Loading branch information
yogurtandjam and mobile-build-bot authored May 30, 2024
1 parent 33be706 commit f62aca4
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.7.40"
version = "1.7.41"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package exchange.dydx.abacus.processor.router

import exchange.dydx.abacus.protocols.ParserProtocol

class SharedRouterProcessor(val parser: ParserProtocol)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipChainProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
private val keyMap = mapOf(
"string" to mapOf(
"chain_name" to "stringKey",
"networkIdentifier" to "stringKey",
"chain_id" to "type",
"logo_uri" to "iconUrl",
),
)

override fun received(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any> {
return transform(existing, payload, keyMap)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipChainResourceProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
private val keyMap = mapOf(
"string" to mapOf(
"chain_name" to "chainName",
"rpc" to "rpc",
"networkName" to "networkName",
"chain_id" to "chainId",
"logo_uri" to "iconUrl",
),
)

override fun received(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any> {
return transform(existing, payload, keyMap)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.processor.router.IRouterProcessor
import exchange.dydx.abacus.processor.router.SharedRouterProcessor
import exchange.dydx.abacus.protocols.ParserProtocol
import exchange.dydx.abacus.utils.safeSet

@Suppress("NotImplementedDeclaration")
internal class SkipProcessor(parser: ParserProtocol) : BaseProcessor(parser), IRouterProcessor {
override var chains: List<Any>? = null

// possibly want to use a different variable so we aren't stuck with this bad type
// actual type of the tokens payload is Map<str, Map<str, List<Map<str, Any>>>>
override var tokens: List<Any>? = null
override var exchangeDestinationChainId: String? = null
val sharedRouterProcessor = SharedRouterProcessor(parser)

override fun receivedV2SdkInfo(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any>? {
throw NotImplementedError("receivedV2SdkInfo is not implemented in SkipProcessor!")
}
override fun receivedChains(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any>? {
throw NotImplementedError("receivedChains is not implemented in SkipProcessor!")
}
override fun receivedTokens(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any>? {
throw NotImplementedError("receivedTokens is not implemented in SkipProcessor!")
}

override fun receivedRoute(
existing: Map<String, Any>?,
payload: Map<String, Any>,
requestId: String?,
): Map<String, Any>? {
throw NotImplementedError("receivedRoute is not implemented in SkipProcessor!")
}

override fun receivedRouteV2(
existing: Map<String, Any>?,
payload: Map<String, Any>,
requestId: String?
): Map<String, Any>? {
throw NotImplementedError("receivedRouteV2 is not implemented in SkipProcessor!")
}

override fun usdcAmount(data: Map<String, Any>): Double? {
throw NotImplementedError("usdcAmount is not implemented in SkipProcessor!")
}

override fun receivedStatus(
existing: Map<String, Any>?,
payload: Map<String, Any>,
transactionId: String?,
): Map<String, Any>? {
throw NotImplementedError("receivedStatus is not implemented in SkipProcessor!")
}

override fun updateTokensDefaults(modified: MutableMap<String, Any>, selectedChainId: String?) {
val tokenOptions = tokenOptions(selectedChainId)
modified.safeSet("transfer.depositOptions.assets", tokenOptions)
modified.safeSet("transfer.withdrawalOptions.assets", tokenOptions)
modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId))
modified.safeSet("transfer.resources.tokenResources", tokenResources(selectedChainId))
}

override fun defaultChainId(): String? {
throw NotImplementedError("defaultChainId is not implemented in SkipProcessor!")
}

override fun selectedTokenSymbol(tokenAddress: String?): String? {
throw NotImplementedError("selectedTokenSymbol is not implemented in SkipProcessor!")
}

override fun selectedTokenDecimals(tokenAddress: String?): String? {
throw NotImplementedError("selectedTokenDecimals is not implemented in SkipProcessor!")
}

override fun filteredTokens(chainId: String?): List<Any>? {
throw NotImplementedError("filteredTokens is not implemented in SkipProcessor!")
}

override fun defaultTokenAddress(chainId: String?): String? {
throw NotImplementedError("defaultTokenAddress is not implemented in SkipProcessor!")
}

override fun chainResources(chainId: String?): Map<String, Any>? {
throw NotImplementedError("chainResources is not implemented in SkipProcessor!")
}

override fun tokenResources(chainId: String?): Map<String, Any>? {
throw NotImplementedError("tokenResources is not implemented in SkipProcessor!")
}

override fun chainOptions(): List<Any> {
throw NotImplementedError("chainOptions is not implemented in SkipProcessor!")
}

override fun tokenOptions(chainId: String?): List<Any> {
throw NotImplementedError("tokenOptions is not implemented in SkipProcessor!")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipTokenProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
private val keyMap = mapOf(
"string" to mapOf(
"name" to "stringKey",
"denom" to "type",
"logo_uri" to "iconUrl",
),
)

override fun received(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any> {
return transform(existing, payload, keyMap)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipTokenResourceProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
private val keyMap = mapOf(
"string" to mapOf(
"name" to "name",
"denom" to "address",
"symbol" to "symbol",
"decimals" to "decimals",
"logo_uri" to "iconUrl",
),
)

override fun received(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any> {
return transform(existing, payload, keyMap)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exchange.dydx.abacus.processor.squid
package exchange.dydx.abacus.processor.router.squid

import exchange.dydx.abacus.output.input.SelectionOption
import exchange.dydx.abacus.protocols.ParserProtocol
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exchange.dydx.abacus.processor.squid
package exchange.dydx.abacus.processor.router.squid

import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.protocols.ParserProtocol
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package exchange.dydx.abacus.processor.squid
package exchange.dydx.abacus.processor.router.squid

import exchange.dydx.abacus.output.input.SelectionOption
import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.output.input.TransferInputTokenResource
import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.processor.router.IRouterProcessor
import exchange.dydx.abacus.protocols.ParserProtocol
import exchange.dydx.abacus.state.internalstate.InternalTransferInputState
import exchange.dydx.abacus.state.manager.CctpConfig.cctpChainIds
Expand All @@ -13,12 +14,12 @@ import exchange.dydx.abacus.utils.safeSet
internal class SquidProcessor(
parser: ParserProtocol,
private val internalState: InternalTransferInputState,
) : BaseProcessor(parser) {
private var chains: List<Any>? = null
private var tokens: List<Any>? = null
var exchangeDestinationChainId: String? = null
) : BaseProcessor(parser), IRouterProcessor {
override var chains: List<Any>? = null
override var tokens: List<Any>? = null
override var exchangeDestinationChainId: String? = null

internal fun receivedChains(
override fun receivedChains(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any>? {
Expand Down Expand Up @@ -46,7 +47,7 @@ internal class SquidProcessor(
return modified
}

internal fun receivedTokens(
override fun receivedTokens(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any>? {
Expand All @@ -66,7 +67,7 @@ internal class SquidProcessor(
return modified
}

internal fun receivedV2SdkInfo(
override fun receivedV2SdkInfo(
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any>? {
Expand Down Expand Up @@ -95,7 +96,7 @@ internal class SquidProcessor(
return modified
}

internal fun receivedRoute(
override fun receivedRoute(
existing: Map<String, Any>?,
payload: Map<String, Any>,
requestId: String?,
Expand All @@ -121,7 +122,7 @@ internal class SquidProcessor(
return modified
}

internal fun receivedRouteV2(
override fun receivedRouteV2(
existing: Map<String, Any>?,
payload: Map<String, Any>,
requestId: String?
Expand All @@ -147,15 +148,15 @@ internal class SquidProcessor(
return modified
}

private fun usdcAmount(data: Map<String, Any>): Double? {
override fun usdcAmount(data: Map<String, Any>): Double? {
var toAmountUSD = parser.asString(parser.value(data, "transfer.route.toAmountUSD"))
toAmountUSD = toAmountUSD?.replace(",", "")
var toAmount = parser.asString(parser.value(data, "transfer.route.toAmount"))
toAmount = toAmount?.replace(",", "")
return parser.asDouble(toAmountUSD) ?: parser.asDouble(toAmount)
}

internal fun receivedStatus(
override fun receivedStatus(
existing: Map<String, Any>?,
payload: Map<String, Any>,
transactionId: String?,
Expand All @@ -169,19 +170,19 @@ internal class SquidProcessor(
return processor.received(existing, payload)
}

private fun updateTokensDefaults(modified: MutableMap<String, Any>, selectedChainId: String?) {
override fun updateTokensDefaults(modified: MutableMap<String, Any>, selectedChainId: String?) {
val tokenOptions = tokenOptions(selectedChainId)
internalState.tokens = tokenOptions
modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId))
internalState.tokenResources = tokenResources(selectedChainId)
}

internal fun defaultChainId(): String? {
override fun defaultChainId(): String? {
val selectedChain = parser.asNativeMap(this.chains?.firstOrNull())
return parser.asString(selectedChain?.get("chainId"))
}

internal fun selectedTokenSymbol(tokenAddress: String?): String? {
override fun selectedTokenSymbol(tokenAddress: String?): String? {
this.tokens?.find {
parser.asString(parser.asNativeMap(it)?.get("address")) == tokenAddress
}?.let {
Expand All @@ -190,7 +191,7 @@ internal class SquidProcessor(
return null
}

internal fun selectedTokenDecimals(tokenAddress: String?): String? {
override fun selectedTokenDecimals(tokenAddress: String?): String? {
this.tokens?.find {
parser.asString(parser.asNativeMap(it)?.get("address")) == tokenAddress
}?.let {
Expand All @@ -199,7 +200,7 @@ internal class SquidProcessor(
return null
}

private fun filteredTokens(chainId: String?): List<Any>? {
override fun filteredTokens(chainId: String?): List<Any>? {
chainId?.let {
val filteredTokens = mutableListOf<Map<String, Any>>()
this.tokens?.let {
Expand All @@ -216,7 +217,7 @@ internal class SquidProcessor(
return tokens
}

internal fun defaultTokenAddress(chainId: String?): String? {
override fun defaultTokenAddress(chainId: String?): String? {
return chainId?.let { cid ->
// Retrieve the list of filtered tokens for the given chainId
val filteredTokens = this.filteredTokens(cid)?.mapNotNull {
Expand All @@ -232,7 +233,7 @@ internal class SquidProcessor(
}
}

internal fun chainResources(chainId: String?): Map<String, TransferInputChainResource>? {
override fun chainResources(chainId: String?): Map<String, TransferInputChainResource>? {
val chainResources = mutableMapOf<String, TransferInputChainResource>()
chainId?.let {
this.chains?.find {
Expand All @@ -247,7 +248,7 @@ internal class SquidProcessor(
return chainResources
}

internal fun tokenResources(chainId: String?): Map<String, TransferInputTokenResource>? {
override fun tokenResources(chainId: String?): Map<String, TransferInputTokenResource>? {
val tokenResources = mutableMapOf<String, TransferInputTokenResource>()
filteredTokens(chainId)?.forEach {
parser.asString(parser.asNativeMap(it)?.get("address"))?.let { key ->
Expand All @@ -260,7 +261,7 @@ internal class SquidProcessor(
return tokenResources
}

private fun chainOptions(): List<SelectionOption> {
override fun chainOptions(): List<SelectionOption> {
val chainProcessor = SquidChainProcessor(parser)
val options = mutableListOf<SelectionOption>()

Expand All @@ -278,7 +279,7 @@ internal class SquidProcessor(
return options
}

internal fun tokenOptions(chainId: String?): List<SelectionOption> {
override fun tokenOptions(chainId: String?): List<SelectionOption> {
val processor = SquidTokenProcessor(parser)
val options = mutableListOf<SelectionOption>()

Expand Down
Loading

0 comments on commit f62aca4

Please sign in to comment.