From ab9af66a7ba9cd84909dcbbe62be309509353218 Mon Sep 17 00:00:00 2001 From: jeremy lee Date: Mon, 17 Jun 2024 11:54:06 -0400 Subject: [PATCH] feat: enable testnet --- .../processor/router/IRouterProcessor.kt | 1 + .../processor/router/skip/SkipProcessor.kt | 22 ++++++++++++++----- .../manager/configs/V4StateManagerConfigs.kt | 17 ++++++++++---- .../v2/supervisor/OnboardingSupervisor.kt | 11 +++++----- .../exchange.dydx.abacus/utils/Constants.kt | 3 +++ 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/IRouterProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/IRouterProcessor.kt index 3bfe6c026..ae3d12265 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/IRouterProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/IRouterProcessor.kt @@ -8,6 +8,7 @@ interface IRouterProcessor { var tokens: List? var chains: List? var exchangeDestinationChainId: String? + fun receivedChains( existing: Map?, payload: Map 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 index 857074614..0903d6474 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 @@ -10,6 +10,7 @@ import exchange.dydx.abacus.processor.router.squid.SquidStatusProcessor import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.state.internalstate.InternalTransferInputState import exchange.dydx.abacus.state.manager.CctpConfig.cctpChainIds +import exchange.dydx.abacus.utils.NATIVE_TOKEN_DEFAULT_ADDRESS import exchange.dydx.abacus.utils.mutable import exchange.dydx.abacus.utils.safeSet @@ -47,9 +48,12 @@ internal class SkipProcessor( modified = it.mutable() } val chainOptions = chainOptions() - internalState.chains = chainOptions val selectedChainId = defaultChainId() +// We diff based on map values in order to determine whether to return new state +// Until we diff on `internalState` changes we need to update old map state as well + modified.safeSet("transfer.depositOptions.chains", chainOptions) + modified.safeSet("transfer.withdrawOptions.chains", chainOptions) modified.safeSet("transfer.chain", selectedChainId) selectedChainId?.let { internalState.chainResources = chainResources(chainId = selectedChainId) @@ -118,7 +122,6 @@ internal class SkipProcessor( return receivedRoute(existing, payload, requestId) } -// TODO: deduplicate this from squid override fun usdcAmount(data: Map): Double? { var toAmountUSD = parser.asString(parser.value(data, "transfer.route.toAmountUSD")) toAmountUSD = toAmountUSD?.replace(",", "") @@ -141,12 +144,19 @@ internal class SkipProcessor( override fun updateTokensDefaults(modified: MutableMap, selectedChainId: String?) { val tokenOptions = tokenOptions(selectedChainId) internalState.tokens = tokenOptions - modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId)) + modified.safeSet("transfer.token ", defaultTokenAddress(selectedChainId)) + modified.safeSet("transfer.depositOptions.tokens", tokenOptions) + modified.safeSet("transfer.withdrawalOptions.tokens", tokenOptions) internalState.tokenResources = tokenResources(selectedChainId) } + private fun getChainById(chainId: String): Map? { + return parser.asNativeMap(this.chains?.find { parser.asString(parser.asNativeMap(it)?.get("chain_id")) == chainId }) + } + override fun defaultChainId(): String? { - val selectedChain = parser.asNativeMap(this.chains?.find { parser.asString(parser.asNativeMap(it)?.get("chain_id")) == "1" }) +// eth mainnet chainId is 1 + val selectedChain = getChainById("1") ?: parser.asNativeMap(this.chains?.firstOrNull()) return parser.asString(selectedChain?.get("chain_id")) } @@ -181,7 +191,7 @@ internal class SkipProcessor( val assetsMapForChainId = parser.asNativeMap(this.skipTokens?.get(chainIdToUse)) val assetsForChainId = parser.asNativeList(assetsMapForChainId?.get("assets")) // coinbase exchange chainId is noble-1. we only allow usdc withdrawals from it - if (chainId === "noble-1") { + if (chainId === exchangeDestinationChainId) { return assetsForChainId?.filter { parser.asString(parser.asNativeMap(it)?.get("denom")) == "uusdc" } @@ -198,7 +208,7 @@ internal class SkipProcessor( val denom = parser.asString(token["denom"]) if (denom?.endsWith("native") == true) { token["skipDenom"] = denom - token["denom"] = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" + token["denom"] = NATIVE_TOKEN_DEFAULT_ADDRESS } filteredTokens.add(token.toMap()) } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/configs/V4StateManagerConfigs.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/configs/V4StateManagerConfigs.kt index 9936755c0..7489cb3bc 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/configs/V4StateManagerConfigs.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/configs/V4StateManagerConfigs.kt @@ -103,16 +103,20 @@ class V4StateManagerConfigs( return if (environment.isMainNet) "noble-1" else "grand-1" } - fun osmosisChainId(): String? { - return if (environment.isMainNet) "osmosis-1" else "osmosis-5" + fun osmosisChainId(): String { + return if (environment.isMainNet) "osmosis-1" else "osmo-test-5" + } + + fun neutronChainId(): String { + return if (environment.isMainNet) "neutron-1" else "pion-1" } fun skipV1Chains(): String { - return "$skipHost/v1/info/chains?include_evm=true" + return "$skipHost/v1/info/chains?include_evm=true$onlyTestnets" } fun skipV1Assets(): String { - return "$skipHost/v1/fungible/assets?include_evm_assets=true" + return "$skipHost/v1/fungible/assets?include_evm_assets=true$onlyTestnets" } fun skipV2MsgsDirect(): String { @@ -121,6 +125,11 @@ class V4StateManagerConfigs( val nobleDenom = "uusdc" + private val onlyTestnets: String + get() { + return if (environment.isMainNet) "" else "&only_testnets=true" + } + private val skipHost: String get() { return "https://api.skip.money" diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt index a7e9735d6..0afa24c9f 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt @@ -1018,10 +1018,9 @@ internal class OnboardingSupervisor( return } if (fromAmount <= 0) return - val osmosisAddress = accountAddress.toOsmosisAddress() ?: return - val nobleAddress = accountAddress.toNobleAddress() ?: return - val osmosisChainId = helper.configs.osmosisChainId() ?: return + val osmosisChainId = helper.configs.osmosisChainId() val nobleChainId = helper.configs.nobleChainId() + val neutronChainId = helper.configs.neutronChainId() val fromChain = helper.environment.dydxChainId ?: return val fromToken = helper.environment.tokens["usdc"]?.denom ?: return val fromAmountString = helper.parser.asString(fromAmount) ?: return @@ -1034,9 +1033,9 @@ internal class OnboardingSupervisor( "dest_asset_chain_id" to toChain, "chain_ids_to_addresses" to mapOf( fromChain to accountAddress, - osmosisChainId to osmosisAddress, - nobleChainId to nobleAddress, - "neutron-1" to accountAddress.toNeutronAddress(), + osmosisChainId to accountAddress.toOsmosisAddress(), + nobleChainId to accountAddress.toNobleAddress(), + neutronChainId to accountAddress.toNeutronAddress(), toChain to toAddress, ), "allow_multi_tx" to true, diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt b/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt index c455791de..c4c0864b1 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt @@ -17,3 +17,6 @@ internal const val MAX_LEVERAGE_BUFFER_PERCENT = 0.98 // Order flags internal const val SHORT_TERM_ORDER_FLAGS = 0 internal const val CONDITIONAL_ORDER_FLAGS = 32 + +// Asset Constants +internal const val NATIVE_TOKEN_DEFAULT_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"