From 27fcf3dd05302fafce7cc6299c1a6a5890905208 Mon Sep 17 00:00:00 2001 From: jeremy lee Date: Mon, 27 May 2024 20:09:08 -0400 Subject: [PATCH] refactor: move squid to new dir --- .../Squid/SquidRoutePayloadProcessor.kt | 31 -- .../router/Squid/SquidStatusProcessor.kt | 23 -- .../router/Squid/SquidTokenProcessor.kt | 21 -- .../Squid/SquidTokenResourceProcessor.kt | 23 -- .../{Skip => skip}/SkipChainProcessor.kt | 2 +- .../SkipChainResourceProcessor.kt | 2 +- .../router/{Skip => skip}/SkipProcessor.kt | 9 +- .../{Skip => skip}/SkipTokenProcessor.kt | 2 +- .../SkipTokenResourceProcessor.kt | 2 +- .../{Squid => squid}/SquidChainProcessor.kt | 2 +- .../SquidChainResourceProcessor.kt | 2 +- .../router/{Squid => squid}/SquidProcessor.kt | 13 +- .../squid/SquidRoutePayloadProcessor.kt | 2 +- .../{Squid => squid}/SquidRouteProcessor.kt | 2 +- .../SquidRouteV2PayloadProcessor.kt | 2 +- .../{Squid => squid}/SquidRouteV2Processor.kt | 2 +- .../squid/SquidStatusProcessor.kt | 2 +- .../{ => router}/squid/SquidTokenProcessor.kt | 2 +- .../squid/SquidTokenResourceProcessor.kt | 2 +- .../processor/squid/SquidChainProcessor.kt | 22 -- .../squid/SquidChainResourceProcessor.kt | 23 -- .../processor/squid/SquidProcessor.kt | 296 ------------------ .../processor/squid/SquidRouteProcessor.kt | 61 ---- .../squid/SquidRouteV2PayloadProcessor.kt | 34 -- .../processor/squid/SquidRouteV2Processor.kt | 64 ---- .../state/model/TradingStateMachine.kt | 2 +- 26 files changed, 21 insertions(+), 627 deletions(-) delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRoutePayloadProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidStatusProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenResourceProcessor.kt rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Skip => skip}/SkipChainProcessor.kt (92%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Skip => skip}/SkipChainResourceProcessor.kt (92%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Skip => skip}/SkipProcessor.kt (86%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Skip => skip}/SkipTokenProcessor.kt (91%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Skip => skip}/SkipTokenResourceProcessor.kt (92%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Squid => squid}/SquidChainProcessor.kt (92%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Squid => squid}/SquidChainResourceProcessor.kt (92%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Squid => squid}/SquidProcessor.kt (96%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/{ => router}/squid/SquidRoutePayloadProcessor.kt (96%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Squid => squid}/SquidRouteProcessor.kt (97%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Squid => squid}/SquidRouteV2PayloadProcessor.kt (96%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/router/{Squid => squid}/SquidRouteV2Processor.kt (98%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/{ => router}/squid/SquidStatusProcessor.kt (92%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/{ => router}/squid/SquidTokenProcessor.kt (91%) rename src/commonMain/kotlin/exchange.dydx.abacus/processor/{ => router}/squid/SquidTokenResourceProcessor.kt (92%) delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainResourceProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2PayloadProcessor.kt delete mode 100644 src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2Processor.kt diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRoutePayloadProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRoutePayloadProcessor.kt deleted file mode 100644 index 9b99a1578..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRoutePayloadProcessor.kt +++ /dev/null @@ -1,31 +0,0 @@ -package exchange.dydx.abacus.processor.router.Squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol - -internal class SquidRoutePayloadProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - // Transaction request payload - "route.transactionRequest.routeType" to "routeType", - "route.transactionRequest.targetAddress" to "targetAddress", - "route.transactionRequest.data" to "data", - "route.transactionRequest.value" to "value", - "route.transactionRequest.gasPrice" to "gasPrice", - "route.transactionRequest.gasLimit" to "gasLimit", - "route.transactionRequest.maxFeePerGas" to "maxFeePerGas", - "route.transactionRequest.maxPriorityFeePerGas" to "maxPriorityFeePerGas", - "route.params.fromToken.chainId" to "fromChainId", - "route.params.fromToken.address" to "fromAddress", - "route.params.toToken.chainId" to "toChainId", - "route.params.toToken.address" to "toAddress", - ), - ) - - override fun received( - existing: Map?, - payload: Map - ): Map { - return transform(existing, payload, keyMap) - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidStatusProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidStatusProcessor.kt deleted file mode 100644 index dab758bba..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidStatusProcessor.kt +++ /dev/null @@ -1,23 +0,0 @@ -package exchange.dydx.abacus.processor.router.Squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol -import exchange.dydx.abacus.utils.mutable - -internal class SquidStatusProcessor( - parser: ParserProtocol, - private val transactionId: String?, -) : BaseProcessor(parser) { - - override fun received( - existing: Map?, - payload: Map, - ): Map { - val modified = existing?.mutable() ?: mutableMapOf() - val hash = transactionId ?: parser.asString(parser.value(payload, "fromChain.transactionId")) - if (hash != null) { - modified[hash] = payload - } - return modified - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenProcessor.kt deleted file mode 100644 index f9768a26b..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenProcessor.kt +++ /dev/null @@ -1,21 +0,0 @@ -package exchange.dydx.abacus.processor.router.Squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol - -internal class SquidTokenProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - "name" to "stringKey", - "address" to "type", - "logoURI" to "iconUrl", - ), - ) - - override fun received( - existing: Map?, - payload: Map - ): Map { - return transform(existing, payload, keyMap) - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenResourceProcessor.kt deleted file mode 100644 index 71ab6fcc2..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidTokenResourceProcessor.kt +++ /dev/null @@ -1,23 +0,0 @@ -package exchange.dydx.abacus.processor.router.Squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol - -internal class SquidTokenResourceProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - "name" to "name", - "address" to "address", - "symbol" to "symbol", - "decimals" to "decimals", - "logoURI" to "iconUrl", - ), - ) - - override fun received( - existing: Map?, - payload: Map - ): Map { - return transform(existing, payload, keyMap) - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipChainProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt similarity index 92% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipChainProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt index d6592ca74..d9967c7d3 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipChainProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Skip +package exchange.dydx.abacus.processor.router.skip import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipChainResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt similarity index 92% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipChainResourceProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt index 4df698ceb..d4906869d 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipChainResourceProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Skip +package exchange.dydx.abacus.processor.router.skip import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt similarity index 86% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt index 29bd273e6..8faf4d285 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt @@ -2,14 +2,7 @@ package exchange.dydx.abacus.processor.router.Squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.processor.router.* -import exchange.dydx.abacus.processor.router.Skip.SkipChainProcessor -import exchange.dydx.abacus.processor.router.Skip.SkipChainResourceProcessor -import exchange.dydx.abacus.processor.router.Skip.SkipTokenProcessor -import exchange.dydx.abacus.processor.router.Skip.SkipTokenResourceProcessor import exchange.dydx.abacus.protocols.ParserProtocol -import exchange.dydx.abacus.state.manager.CctpConfig.cctpChainIds -import exchange.dydx.abacus.utils.Logger -import exchange.dydx.abacus.utils.mutable import exchange.dydx.abacus.utils.safeSet internal class SkipProcessor(parser: ParserProtocol) : BaseProcessor(parser), IRouterProcessor { @@ -83,7 +76,7 @@ internal class SkipProcessor(parser: ParserProtocol) : BaseProcessor(parser), IR throw Error("Not Implemented!") } - override fun selectedTokenDecimals(tokenAddress: String?, selectedChainId: String?): String? { + override fun selectedTokenDecimals(tokenAddress: String?): String? { throw Error("Not Implemented!") } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipTokenProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenProcessor.kt similarity index 91% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipTokenProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenProcessor.kt index 603a6a39a..59623ca27 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipTokenProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Skip +package exchange.dydx.abacus.processor.router.skip import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipTokenResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenResourceProcessor.kt similarity index 92% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipTokenResourceProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenResourceProcessor.kt index 5ab7cf071..e5b202a4a 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Skip/SkipTokenResourceProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipTokenResourceProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Skip +package exchange.dydx.abacus.processor.router.skip import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidChainProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidChainProcessor.kt similarity index 92% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidChainProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidChainProcessor.kt index da1cc0a59..5b4a9212c 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidChainProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidChainProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidChainResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidChainResourceProcessor.kt similarity index 92% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidChainResourceProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidChainResourceProcessor.kt index 88a8808a2..34d942b89 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidChainResourceProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidChainResourceProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidProcessor.kt similarity index 96% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidProcessor.kt index 76b9f5d6f..f0d0292a4 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidProcessor.kt @@ -1,10 +1,9 @@ -package exchange.dydx.abacus.processor.router.Squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.processor.router.* +import exchange.dydx.abacus.processor.router.IRouterProcessor import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.state.manager.CctpConfig.cctpChainIds -import exchange.dydx.abacus.utils.Logger import exchange.dydx.abacus.utils.mutable import exchange.dydx.abacus.utils.safeSet @@ -165,7 +164,7 @@ internal class SquidProcessor(parser: ParserProtocol) : BaseProcessor(parser), I } override fun updateTokensDefaults(modified: MutableMap, selectedChainId: String?) { - val tokenOptions = this.tokenOptions(selectedChainId) + val tokenOptions = tokenOptions(selectedChainId) modified.safeSet("transfer.depositOptions.assets", tokenOptions) modified.safeSet("transfer.withdrawalOptions.assets", tokenOptions) modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId)) @@ -174,7 +173,7 @@ internal class SquidProcessor(parser: ParserProtocol) : BaseProcessor(parser), I override fun defaultChainId(): String? { val selectedChain = parser.asNativeMap(this.chains?.firstOrNull()) - return parser.asString(selectedChain?.get("chain_id")) + return parser.asString(selectedChain?.get("chainId")) } override fun selectedTokenSymbol(tokenAddress: String?): String? { @@ -186,7 +185,7 @@ internal class SquidProcessor(parser: ParserProtocol) : BaseProcessor(parser), I return null } - override fun selectedTokenDecimals(tokenAddress: String?, selectedChainId: String?): String? { + override fun selectedTokenDecimals(tokenAddress: String?): String? { this.tokens?.find { parser.asString(parser.asNativeMap(it)?.get("address")) == tokenAddress }?.let { @@ -282,6 +281,7 @@ internal class SquidProcessor(parser: ParserProtocol) : BaseProcessor(parser), I val selectedChainId = chainId ?: defaultChainId() selectedChainId?.let { + selectedChainId this.tokens?.let { for (token in it) { parser.asNativeMap(token)?.let { token -> @@ -296,5 +296,4 @@ internal class SquidProcessor(parser: ParserProtocol) : BaseProcessor(parser), I options.sortBy { parser.asString(parser.asNativeMap(it)?.get("stringKey")) } return options } - } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRoutePayloadProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRoutePayloadProcessor.kt similarity index 96% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRoutePayloadProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRoutePayloadProcessor.kt index 8c32ab806..1879d4b3b 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRoutePayloadProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRoutePayloadProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteProcessor.kt similarity index 97% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteProcessor.kt index ec8823830..4cec8b9f3 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteV2PayloadProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteV2PayloadProcessor.kt similarity index 96% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteV2PayloadProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteV2PayloadProcessor.kt index 0d7a4348c..438cc5a78 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteV2PayloadProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteV2PayloadProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteV2Processor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteV2Processor.kt similarity index 98% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteV2Processor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteV2Processor.kt index 6c5a748b2..025727d79 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/Squid/SquidRouteV2Processor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidRouteV2Processor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.router.Squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidStatusProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidStatusProcessor.kt similarity index 92% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidStatusProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidStatusProcessor.kt index 910998c9b..6e5c5215c 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidStatusProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidStatusProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidTokenProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidTokenProcessor.kt similarity index 91% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidTokenProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidTokenProcessor.kt index 217e769c0..afca07327 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidTokenProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidTokenProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidTokenResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidTokenResourceProcessor.kt similarity index 92% rename from src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidTokenResourceProcessor.kt rename to src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidTokenResourceProcessor.kt index 26f389a1c..e75f4407c 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidTokenResourceProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/squid/SquidTokenResourceProcessor.kt @@ -1,4 +1,4 @@ -package exchange.dydx.abacus.processor.squid +package exchange.dydx.abacus.processor.router.squid import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainProcessor.kt deleted file mode 100644 index 684b9b6a8..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainProcessor.kt +++ /dev/null @@ -1,22 +0,0 @@ -package exchange.dydx.abacus.processor.squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol - -internal class SquidChainProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - "chainName" to "stringKey", - "networkIdentifier" to "stringKey", - "chainId" to "type", - "chainIconURI" to "iconUrl", - ), - ) - - override fun received( - existing: Map?, - payload: Map - ): Map { - return transform(existing, payload, keyMap) - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainResourceProcessor.kt deleted file mode 100644 index b090e0593..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidChainResourceProcessor.kt +++ /dev/null @@ -1,23 +0,0 @@ -package exchange.dydx.abacus.processor.squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol - -internal class SquidChainResourceProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - "chainName" to "chainName", - "rpc" to "rpc", - "networkName" to "networkName", - "chainId" to "chainId", - "chainIconURI" to "iconUrl", - ), - ) - - override fun received( - existing: Map?, - payload: Map - ): Map { - return transform(existing, payload, keyMap) - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidProcessor.kt deleted file mode 100644 index 327d6dafe..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidProcessor.kt +++ /dev/null @@ -1,296 +0,0 @@ -package exchange.dydx.abacus.processor.squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol -import exchange.dydx.abacus.state.manager.CctpConfig.cctpChainIds -import exchange.dydx.abacus.utils.mutable -import exchange.dydx.abacus.utils.safeSet - -internal class SquidProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private var chains: List? = null - private var tokens: List? = null - var exchangeDestinationChainId: String? = null - - internal fun receivedChains( - existing: Map?, - payload: Map - ): Map? { - if (this.chains != null) { - return existing - } - this.chains = parser.asNativeList(payload.get("chains")) - - var modified = mutableMapOf() - existing?.let { - modified = it.mutable() - } - val chainOptions = chainOptions() - - modified.safeSet("transfer.depositOptions.chains", chainOptions) - modified.safeSet("transfer.withdrawalOptions.chains", chainOptions) - val selectedChainId = defaultChainId() - modified.safeSet("transfer.chain", selectedChainId) - selectedChainId?.let { - modified.safeSet("transfer.resources.chainResources", chainResources(selectedChainId)) - } - - updateTokensDefaults(modified, selectedChainId) - - return modified - } - - internal fun receivedTokens( - existing: Map?, - payload: Map - ): Map? { - if (this.tokens != null) { - return existing - } - this.tokens = parser.asNativeList(payload.get("tokens")) as List>? - - var modified = mutableMapOf() - existing?.let { - modified = it.mutable() - } - - val selectedChainId = defaultChainId() - updateTokensDefaults(modified, selectedChainId) - - return modified - } - - internal fun receivedV2SdkInfo( - existing: Map?, - payload: Map - ): Map? { - if (this.chains != null && this.tokens != null) { - return existing - } - this.chains = parser.asNativeList(payload["chains"]) - this.tokens = parser.asNativeList(payload["tokens"]) - - var modified = mutableMapOf() - existing?.let { - modified = it.mutable() - } - val chainOptions = chainOptions() - - modified.safeSet("transfer.depositOptions.chains", chainOptions) - modified.safeSet("transfer.withdrawalOptions.chains", chainOptions) - val selectedChainId = defaultChainId() - modified.safeSet("transfer.chain", selectedChainId) - selectedChainId?.let { - modified.safeSet("transfer.resources.chainResources", chainResources(selectedChainId)) - } - - updateTokensDefaults(modified, selectedChainId) - - return modified - } - - internal fun receivedRoute( - existing: Map?, - payload: Map, - requestId: String?, - ): Map? { - var modified = mutableMapOf() - existing?.let { - modified = it.mutable() - } - - val processor = SquidRouteProcessor(parser) - modified.safeSet( - "transfer.route", - processor.received(null, payload) as MutableMap, - ) - if (requestId != null) { - modified.safeSet("transfer.route.requestPayload.requestId", requestId) - } - if (parser.asNativeMap(existing?.get("transfer"))?.get("type") == "DEPOSIT") { - val value = usdcAmount(modified) - modified.safeSet("transfer.size.usdcSize", value) - } - - return modified - } - - internal fun receivedRouteV2( - existing: Map?, - payload: Map, - requestId: String? - ): Map? { - var modified = mutableMapOf() - existing?.let { - modified = it.mutable() - } - - val processor = SquidRouteV2Processor(parser) - modified.safeSet( - "transfer.route", - processor.received(null, payload) as MutableMap, - ) - if (requestId != null) { - modified.safeSet("transfer.route.requestPayload.requestId", requestId) - } - if (parser.asNativeMap(existing?.get("transfer"))?.get("type") == "DEPOSIT") { - val value = usdcAmount(modified) - modified.safeSet("transfer.size.usdcSize", value) - } - - return modified - } - - private fun usdcAmount(data: Map): 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( - existing: Map?, - payload: Map, - transactionId: String?, - ): Map? { - var modified = mutableMapOf() - existing?.let { - modified = it.mutable() - } - - val processor = SquidStatusProcessor(parser, transactionId) - return processor.received(existing, payload) - } - - private fun updateTokensDefaults(modified: MutableMap, 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)) - } - - internal fun defaultChainId(): String? { - val selectedChain = parser.asNativeMap(this.chains?.firstOrNull()) - return parser.asString(selectedChain?.get("chainId")) - } - - internal fun selectedTokenSymbol(tokenAddress: String?): String? { - this.tokens?.find { - parser.asString(parser.asNativeMap(it)?.get("address")) == tokenAddress - }?.let { - return parser.asString(parser.asNativeMap(it)?.get("symbol")) - } - return null - } - - internal fun selectedTokenDecimals(tokenAddress: String?): String? { - this.tokens?.find { - parser.asString(parser.asNativeMap(it)?.get("address")) == tokenAddress - }?.let { - return parser.asString(parser.asNativeMap(it)?.get("decimals")) - } - return null - } - - private fun filteredTokens(chainId: String?): List? { - chainId?.let { - val filteredTokens = mutableListOf>() - this.tokens?.let { - for (token in it) { - parser.asNativeMap(token)?.let { token -> - if (parser.asString(token.get("chainId")) == chainId) { - filteredTokens.add(token) - } - } - } - } - return filteredTokens - } - return tokens - } - - internal 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 { - parser.asString(parser.asNativeMap(it)?.get("address")) - }.orEmpty() - - // Find a matching CctpChainTokenInfo and check if its tokenAddress is in the filtered tokens - cctpChainIds?.firstOrNull { it.chainId == cid && filteredTokens.contains(it.tokenAddress) }?.tokenAddress - ?: run { - // Fallback to the first token's address from the filtered list if no CctpChainTokenInfo match is found - filteredTokens.firstOrNull() - } - } - } - - internal fun chainResources(chainId: String?): Map? { - val chainResources = mutableMapOf() - chainId?.let { - this.chains?.find { - parser.asString(parser.asNativeMap(it)?.get("chainId")) == chainId - }?.let { - val processor = SquidChainResourceProcessor(parser) - parser.asNativeMap(it)?.let { payload -> - chainResources[chainId] = processor.received(null, payload) - } - } - } - return chainResources - } - - internal fun tokenResources(chainId: String?): Map? { - val tokenResources = mutableMapOf() - filteredTokens(chainId)?.forEach { - parser.asString(parser.asNativeMap(it)?.get("address"))?.let { key -> - val processor = SquidTokenResourceProcessor(parser) - parser.asNativeMap(it)?.let { payload -> - tokenResources[key] = processor.received(null, payload) - } - } - } - return tokenResources - } - - private fun chainOptions(): List { - val chainProcessor = SquidChainProcessor(parser) - val options = mutableListOf() - - this.chains?.let { it -> - for (chain in it) { - parser.asNativeMap(chain)?.let { chain -> - if (parser.asString(chain.get("chainType")) != "cosmos") { - options.add(chainProcessor.received(null, chain)) - } - } - } - } - - options.sortBy { parser.asString(parser.asNativeMap(it)?.get("stringKey")) } - return options - } - - internal fun tokenOptions(chainId: String?): List { - val processor = SquidTokenProcessor(parser) - val options = mutableListOf() - - val selectedChainId = chainId ?: defaultChainId() - selectedChainId?.let { - selectedChainId - this.tokens?.let { - for (token in it) { - parser.asNativeMap(token)?.let { token -> - if (parser.asString(token.get("chainId")) == selectedChainId) { - options.add(processor.received(null, token)) - } - } - } - } - } - - options.sortBy { parser.asString(parser.asNativeMap(it)?.get("stringKey")) } - return options - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteProcessor.kt deleted file mode 100644 index 9abef1715..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteProcessor.kt +++ /dev/null @@ -1,61 +0,0 @@ -package exchange.dydx.abacus.processor.squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol -import exchange.dydx.abacus.utils.safeSet -import kotlin.math.pow - -internal class SquidRouteProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - "route.estimate.gasCosts.0.amountUSD" to "gasFee", - "route.params.slippage" to "slippage", - "route.estimate.exchangeRate" to "exchangeRate", - "route.estimate.toAmountUSD" to "toAmountUSD", - "route.estimate.toAmount" to "toAmount", - "route.estimate.estimatedRouteDuration" to "estimatedRouteDuration", - "route.estimate.toAmountMin" to "toAmountMin", - "route.estimate.aggregatePriceImpact" to "aggregatePriceImpact", - "errors" to "errors", - ), - ) - - override fun received( - existing: Map?, - payload: Map - ): Map { - var bridgeFees = 0.0 - parser.asList(parser.value(payload, "route.estimate.feeCosts"))?.map { - val feeCost = parser.asNativeMap(it) - if (feeCost !== null) { - val amountUsd = parser.asDouble(feeCost["amountUSD"]) - if (amountUsd !== null) { - bridgeFees += amountUsd - } - } - } - - val modified = transform(existing, payload, keyMap) - - val decimals = parser.asDouble(parser.value(payload, "route.params.toToken.decimals")) - val toAmount = parser.asLong(parser.value(payload, "route.estimate.toAmount")) - if (toAmount != null && decimals != null) { - modified.safeSet("toAmount", toAmount / 10.0.pow(decimals)) - } - val toAmountMin = parser.asLong(parser.value(payload, "route.estimate.toAmountMin")) - if (toAmountMin != null && decimals != null) { - modified.safeSet("toAmountMin", toAmountMin / 10.0.pow(decimals)) - } - - val toAmountUSD = parser.asLong(parser.value(payload, "route.estimate.toAmountUSD")) - val udscDecimals = 6 - if (toAmountUSD != null) { - modified.safeSet("toAmountUSD", toAmountUSD / 10.0.pow(udscDecimals.toDouble())) - } - - val payloadProcessor = SquidRoutePayloadProcessor(parser) - modified.safeSet("requestPayload", payloadProcessor.received(null, payload)) - modified.safeSet("bridgeFee", bridgeFees) - return modified - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2PayloadProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2PayloadProcessor.kt deleted file mode 100644 index 46949bfb2..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2PayloadProcessor.kt +++ /dev/null @@ -1,34 +0,0 @@ -package exchange.dydx.abacus.processor.squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol -import exchange.dydx.abacus.utils.safeSet - -internal class SquidRouteV2PayloadProcessor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - // Transaction request payload - "route.transactionRequest.routeType" to "routeType", - "route.transactionRequest.target" to "targetAddress", - "route.transactionRequest.data" to "data", - "route.transactionRequest.value" to "value", - "route.transactionRequest.gasPrice" to "gasPrice", - "route.transactionRequest.gasLimit" to "gasLimit", - "route.transactionRequest.maxFeePerGas" to "maxFeePerGas", - "route.transactionRequest.maxPriorityFeePerGas" to "maxPriorityFeePerGas", - "route.estimate.fromToken.chainId" to "fromChainId", - "route.estimate.fromToken.address" to "fromAddress", - "route.estimate.toToken.chainId" to "toChainId", - "route.estimate.toToken.address" to "toAddress", - ), - ) - - override fun received( - existing: Map?, - payload: Map - ): Map { - var state = transform(existing, payload, keyMap) - state.safeSet("isV2Route", true) - return state - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2Processor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2Processor.kt deleted file mode 100644 index a70f7e39e..000000000 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/squid/SquidRouteV2Processor.kt +++ /dev/null @@ -1,64 +0,0 @@ -package exchange.dydx.abacus.processor.squid - -import exchange.dydx.abacus.processor.base.BaseProcessor -import exchange.dydx.abacus.protocols.ParserProtocol -import exchange.dydx.abacus.utils.QUANTUM_MULTIPLIER -import exchange.dydx.abacus.utils.safeSet -import kotlin.math.pow - -internal class SquidRouteV2Processor(parser: ParserProtocol) : BaseProcessor(parser) { - private val keyMap = mapOf( - "string" to mapOf( - "route.estimate.gasCosts.0.amountUsd" to "gasFee", - "route.estimate.feeCosts.0.amountUSD" to "bridgeFee", - "route.estimate.gasCosts.0.amount" to "gasFeeAmount", - "route.estimate.feeCosts.0.amount" to "bridgeFeeAmount", - "route.estimate.aggregateSlippage" to "slippage", - "route.estimate.exchangeRate" to "exchangeRate", - "route.estimate.estimatedRouteDuration" to "estimatedRouteDuration", - "route.estimate.toAmount" to "toAmount", - "route.estimate.toAmountMin" to "toAmountMin", - "route.estimate.toAmountUSDC" to "toAmountUSDC", - "route.estimate.aggregatePriceImpact" to "aggregatePriceImpact", - "errors" to "errors", - ), - ) - - override fun received( - existing: Map?, - payload: Map, - ): Map { - val modified = transform(existing, payload, keyMap) - val payloadProcessor = SquidRouteV2PayloadProcessor(parser) - modified.safeSet("requestPayload", payloadProcessor.received(null, payload)) - - val decimals = parser.asLong(parser.value(payload, "route.estimate.toToken.decimals")) - val toAmount = parser.asLong(parser.value(payload, "route.estimate.toAmount")) - if (toAmount != null && decimals != null) { - modified.safeSet("toAmount", toAmount / 10.0.pow(decimals.toDouble())) - } - val toAmountMin = parser.asLong(parser.value(payload, "route.estimate.toAmountMin")) - if (toAmountMin != null && decimals != null) { - modified.safeSet("toAmountMin", toAmountMin / 10.0.pow(decimals.toDouble())) - } - - val toAmountUSD = parser.asLong(parser.value(payload, "route.estimate.toAmountUSD")) - val udscDecimals = 6 - if (toAmountUSD != null) { - modified.safeSet("toAmountUSD", toAmountUSD / 10.0.pow(udscDecimals.toDouble())) - } - - val gasFee = parser.asDouble(parser.value(modified, "gasFee")) - val gasFeeAmount = parser.asDouble(parser.value(modified, "gasFeeAmount")) - if (gasFee == null && gasFeeAmount != null) { - modified.safeSet("gasFee", gasFeeAmount / QUANTUM_MULTIPLIER) - } - - val bridgeFee = parser.asDouble(parser.value(modified, "bridgeFee")) - val bridgeFeeAmount = parser.asDouble(parser.value(modified, "bridgeFeeAmount")) - if (bridgeFee == null && bridgeFeeAmount != null) { - modified.safeSet("bridgeFee", bridgeFeeAmount / QUANTUM_MULTIPLIER) - } - return modified - } -} diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt index e0cd84253..a522c5ec5 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt @@ -32,7 +32,7 @@ import exchange.dydx.abacus.processor.assets.AssetsProcessor import exchange.dydx.abacus.processor.configs.ConfigsProcessor import exchange.dydx.abacus.processor.launchIncentive.LaunchIncentiveProcessor import exchange.dydx.abacus.processor.markets.MarketsSummaryProcessor -import exchange.dydx.abacus.processor.squid.SquidProcessor +import exchange.dydx.abacus.processor.router.squid.SquidProcessor import exchange.dydx.abacus.processor.wallet.WalletProcessor import exchange.dydx.abacus.protocols.LocalizerProtocol import exchange.dydx.abacus.protocols.ParserProtocol