From 532581a8776b9cff3ceee3d443db4ef3939ccbf0 Mon Sep 17 00:00:00 2001 From: Jeremy Lee <37092291+yogurtandjam@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:16:38 -0400 Subject: [PATCH] chore: cleanup squid code [OTE-365] [1/n] (#647) --- build.gradle.kts | 2 +- .../calculator/ReceiptCalculator.kt | 30 +- .../state/manager/Environment.kt | 3 +- .../state/model/TradingStateMachine.kt | 44 +- .../state/v2/supervisor/AccountSupervisor.kt | 64 +- .../v2/supervisor/OnboardingSupervisor.kt | 715 +----------------- .../app/manager/v2/V4ForegroundCycleTests.kt | 89 +-- .../payload/v4/V4SquidTests.kt | 289 ------- .../state/model/TradingStateMachineTests.kt | 19 +- v4_abacus.podspec | 2 +- 10 files changed, 100 insertions(+), 1157 deletions(-) delete mode 100644 src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4SquidTests.kt diff --git a/build.gradle.kts b/build.gradle.kts index 58eaf22ce..8ac8883fa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.11.0" +version = "1.11.1" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/ReceiptCalculator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/ReceiptCalculator.kt index 63b0318b7..3a9e60596 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/ReceiptCalculator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/ReceiptCalculator.kt @@ -5,7 +5,6 @@ import exchange.dydx.abacus.output.input.OrderType import exchange.dydx.abacus.output.input.ReceiptLine import exchange.dydx.abacus.output.input.TransferType import exchange.dydx.abacus.state.internalstate.InternalInputState -import exchange.dydx.abacus.state.manager.StatsigConfig internal class ReceiptCalculator { fun calculate( @@ -52,30 +51,17 @@ internal class ReceiptCalculator { InputType.TRANSFER -> { when (input.transfer.type) { TransferType.deposit, TransferType.withdrawal -> { - if (StatsigConfig.useSkip) { - listOf( - ReceiptLine.Equity, - ReceiptLine.BuyingPower, - ReceiptLine.BridgeFee, - // add these back when supported by Skip + listOf( + ReceiptLine.Equity, + ReceiptLine.BuyingPower, + ReceiptLine.BridgeFee, + // add these back when supported by Skip // ReceiptLine.ExchangeRate, // ReceiptLine.ExchangeReceived, // ReceiptLine.Fee, - ReceiptLine.Slippage, - ReceiptLine.TransferRouteEstimatedDuration, - ) - } else { - listOf( - ReceiptLine.Equity, - ReceiptLine.BuyingPower, - ReceiptLine.ExchangeRate, - ReceiptLine.ExchangeReceived, - ReceiptLine.Fee, -// ReceiptLine.BridgeFee, - ReceiptLine.Slippage, - ReceiptLine.TransferRouteEstimatedDuration, - ) - } + ReceiptLine.Slippage, + ReceiptLine.TransferRouteEstimatedDuration, + ) } TransferType.transferOut -> { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt index f25b699b1..258c16c65 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Environment.kt @@ -547,8 +547,7 @@ class V4Environment( @JsExport @Suppress("PropertyName") data object StatsigConfig { - var useSkip: Boolean = false - var ff_enable_evm_swaps: Boolean = false + var ff_enable_evm_swaps: Boolean = true var dc_max_safe_bridge_fees: Float = Float.POSITIVE_INFINITY var ff_enable_limit_close: Boolean = false } 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 9d90afbd3..b2cdb8f7e 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt @@ -44,9 +44,7 @@ import exchange.dydx.abacus.processor.input.ClosePositionInputProcessor import exchange.dydx.abacus.processor.input.TradeInputProcessor import exchange.dydx.abacus.processor.launchIncentive.LaunchIncentiveProcessor import exchange.dydx.abacus.processor.markets.MarketsSummaryProcessor -import exchange.dydx.abacus.processor.router.IRouterProcessor import exchange.dydx.abacus.processor.router.skip.SkipProcessor -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 @@ -65,7 +63,6 @@ import exchange.dydx.abacus.state.internalstate.InternalAccountState import exchange.dydx.abacus.state.internalstate.InternalState import exchange.dydx.abacus.state.manager.BlockAndTime import exchange.dydx.abacus.state.manager.EnvironmentFeatureFlags -import exchange.dydx.abacus.state.manager.StatsigConfig import exchange.dydx.abacus.state.manager.TokenInfo import exchange.dydx.abacus.state.manager.V4Environment import exchange.dydx.abacus.utils.IList @@ -125,21 +122,11 @@ open class TradingStateMachine( } internal val walletProcessor = WalletProcessor(parser, localizer) internal val configsProcessor = ConfigsProcessor(parser, localizer) - private val skipProcessor = SkipProcessor( + internal val routerProcessor = SkipProcessor( parser = parser, internalState = internalState.input.transfer, staticTyping = staticTyping, ) - private val squidProcessor = SquidProcessor( - parser = parser, - internalState = internalState.input.transfer, - staticTyping = staticTyping, - ) - internal val routerProcessor: IRouterProcessor - get() { - if (StatsigConfig.useSkip) return skipProcessor - return squidProcessor - } internal val rewardsProcessor = RewardsParamsProcessor(parser) internal val launchIncentiveProcessor = LaunchIncentiveProcessor(parser) internal val tradeInputProcessor = TradeInputProcessor(parser) @@ -1182,30 +1169,17 @@ open class TradingStateMachine( val type = parser.asString(transfer["type"]) ?: return null return when (type) { "DEPOSIT", "WITHDRAWAL" -> { - if (StatsigConfig.useSkip) { - listOf( - ReceiptLine.Equity.rawValue, - ReceiptLine.BuyingPower.rawValue, - ReceiptLine.BridgeFee.rawValue, - // add these back when supported by Skip + listOf( + ReceiptLine.Equity.rawValue, + ReceiptLine.BuyingPower.rawValue, + ReceiptLine.BridgeFee.rawValue, + // add these back when supported by Skip // ReceiptLine.ExchangeRate.rawValue, // ReceiptLine.ExchangeReceived.rawValue, // ReceiptLine.Fee.rawValue, - ReceiptLine.Slippage.rawValue, - ReceiptLine.TransferRouteEstimatedDuration.rawValue, - ) - } else { - listOf( - ReceiptLine.Equity.rawValue, - ReceiptLine.BuyingPower.rawValue, - ReceiptLine.ExchangeRate.rawValue, - ReceiptLine.ExchangeReceived.rawValue, - ReceiptLine.Fee.rawValue, -// ReceiptLine.BridgeFee.rawValue, - ReceiptLine.Slippage.rawValue, - ReceiptLine.TransferRouteEstimatedDuration.rawValue, - ) - } + ReceiptLine.Slippage.rawValue, + ReceiptLine.TransferRouteEstimatedDuration.rawValue, + ) } "TRANSFER_OUT" -> { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt index 2315f6b85..206088d0f 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt @@ -28,7 +28,6 @@ import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload import exchange.dydx.abacus.state.manager.HumanReadableSubaccountTransferPayload import exchange.dydx.abacus.state.manager.HumanReadableTriggerOrdersPayload import exchange.dydx.abacus.state.manager.HumanReadableWithdrawPayload -import exchange.dydx.abacus.state.manager.StatsigConfig import exchange.dydx.abacus.state.manager.pendingCctpWithdraw import exchange.dydx.abacus.state.manager.processingCctpWithdraw import exchange.dydx.abacus.state.manager.utils.Address @@ -600,68 +599,7 @@ internal open class AccountSupervisor( } private fun sweepNobleBalanceToDydx(amount: BigDecimal) { - if (StatsigConfig.useSkip) { - sweepNobleBalanceToDydxSkip(amount = amount) - } else { - sweepNobleBalanceToDydxSquid(amount = amount) - } - } - - private fun sweepNobleBalanceToDydxSquid(amount: BigDecimal) { - val url = helper.configs.squidRoute() - val fromChain = helper.configs.nobleChainId() - val fromToken = helper.configs.nobleDenom - val nobleAddress = accountAddress.toNobleAddress() - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val dydxTokenDemon = helper.environment.tokens["usdc"]?.denom - if (url != null && - fromChain != null && - fromToken != null && - nobleAddress != null && - chainId != null && - dydxTokenDemon != null && - squidIntegratorId != null - ) { - val params: Map = - mapOf( - "fromChain" to fromChain, - "fromToken" to fromToken, - "fromAddress" to nobleAddress, - "fromAmount" to amount.toPlainString(), - "toChain" to chainId, - "toToken" to dydxTokenDemon, - "toAddress" to accountAddress.toString(), - "slippage" to "1", - "enableForecall" to "false", - ) - val header = - iMapOf( - "x-integrator-id" to squidIntegratorId, - ) - helper.get(url, params, header) { _, response, code, _ -> - if (response != null) { - val json = helper.parser.decodeJsonObject(response) - val ibcPayload = - helper.parser.asString( - helper.parser.value( - json, - "route.transactionRequest.data", - ), - ) - if (ibcPayload != null) { - helper.transaction(TransactionType.SendNobleIBC, ibcPayload) { - val error = helper.parseTransactionResponse(it) - if (error != null) { - Logger.e { "sweepNobleBalanceToDydxSquid error: $error" } - } - } - } - } else { - Logger.e { "sweepNobleBalanceToDydxSquid error, code: $code" } - } - } - } + sweepNobleBalanceToDydxSkip(amount = amount) } private fun sweepNobleBalanceToDydxSkip(amount: BigDecimal) { 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 272505d20..35d89d275 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 @@ -20,7 +20,6 @@ import exchange.dydx.abacus.state.manager.CctpWithdrawState import exchange.dydx.abacus.state.manager.ExchangeConfig import exchange.dydx.abacus.state.manager.ExchangeInfo import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload -import exchange.dydx.abacus.state.manager.HumanReadableFaucetPayload import exchange.dydx.abacus.state.manager.HumanReadableSubaccountTransferPayload import exchange.dydx.abacus.state.manager.HumanReadableTransferPayload import exchange.dydx.abacus.state.manager.HumanReadableWithdrawPayload @@ -37,8 +36,6 @@ import exchange.dydx.abacus.state.model.routerStatus import exchange.dydx.abacus.state.model.routerTokens import exchange.dydx.abacus.state.model.routerTrack import exchange.dydx.abacus.state.model.squidRoute -import exchange.dydx.abacus.state.model.squidRouteV2 -import exchange.dydx.abacus.state.model.squidV2SdkInfo import exchange.dydx.abacus.state.model.transfer import exchange.dydx.abacus.utils.AnalyticsUtils import exchange.dydx.abacus.utils.IMap @@ -113,16 +110,12 @@ internal class OnboardingSupervisor( } private fun retrieveAssetsFromRouter() { - if (StatsigConfig.useSkip) { - CoroutineScope(Dispatchers.Unconfined).launch { - retrieveSkipTransferChains() - } - retrieveSkipTransferTokens() - if (StatsigConfig.ff_enable_evm_swaps) { - retrieveSkipEvmSwapVenues() - } - } else { - retrieveTransferAssets() + CoroutineScope(Dispatchers.Unconfined).launch { + retrieveSkipTransferChains() + } + retrieveSkipTransferTokens() + if (StatsigConfig.ff_enable_evm_swaps) { + retrieveSkipEvmSwapVenues() } retrieveCctpChainIds() } @@ -171,20 +164,6 @@ internal class OnboardingSupervisor( } } - private fun retrieveTransferAssets() { - val oldState = stateMachine.state - val url = helper.configs.squidV2Assets() - val squidIntegratorId = helper.environment.squidIntegratorId - if (url != null && squidIntegratorId != null) { - val header = iMapOf("x-integrator-id" to squidIntegratorId) - helper.get(url, null, header) { _, response, httpCode, _ -> - if (helper.success(httpCode) && response != null) { - update(stateMachine.squidV2SdkInfo(response), oldState) - } - } - } - } - private fun retrieveCctpChainIds() { val url = "${helper.deploymentUri}/configs/cctp.json" helper.get(url) { _, response, _, _ -> @@ -236,49 +215,22 @@ internal class OnboardingSupervisor( subaccountNumber: Int?, ) { val isCctp = state?.input?.transfer?.isCctp ?: false - if (StatsigConfig.useSkip) { - if (isCctp) { - retrieveSkipDepositRouteCCTP( - state = state, - accountAddress = accountAddress, - sourceAddress = sourceAddress, - subaccountNumber = subaccountNumber, - ) - } else { - retrieveSkipDepositRouteNonCCTP( - state, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } - return - } - when (configs.squidVersion) { - OnboardingConfigs.SquidVersion.V2WithdrawalOnly -> retrieveDepositRouteV1( + if (isCctp) { + retrieveSkipDepositRouteCCTP( + state = state, + accountAddress = accountAddress, + sourceAddress = sourceAddress, + subaccountNumber = subaccountNumber, + ) + } else { + retrieveSkipDepositRouteNonCCTP( state, accountAddress, sourceAddress, subaccountNumber, ) - - OnboardingConfigs.SquidVersion.V2, OnboardingConfigs.SquidVersion.V2DepositOnly -> - if (isCctp) { - retrieveDepositRouteV2( - state, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } else { - retrieveDepositRouteV1( - state, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } } + return } private fun retrieveSkipDepositRouteNonCCTP( @@ -433,140 +385,6 @@ internal class OnboardingSupervisor( } } - private fun retrieveDepositRouteV1( - state: PerpetualState?, - accountAddress: String, - sourceAddress: String, - subaccountNumber: Int?, - ) { - val fromChain = state?.input?.transfer?.chain - val fromToken = state?.input?.transfer?.token - val fromAmount = helper.parser.asDecimal(state?.input?.transfer?.size?.size)?.let { - val decimals = - helper.parser.asInt(stateMachine.routerProcessor.selectedTokenDecimals(tokenAddress = fromToken, selectedChainId = fromChain)) - if (decimals != null) { - (it * Numeric.decimal.TEN.pow(decimals)).toBigInteger() - } else { - null - } - } - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val nativeChainUSDCDenom = helper.environment.tokens["usdc"]?.denom - val fromAmountString = helper.parser.asString(fromAmount) - val url = helper.configs.squidRoute() - if (fromChain != null && - fromToken != null && - fromAmount != null && fromAmount > 0 && - fromAmountString != null && - chainId != null && - nativeChainUSDCDenom != null && - url != null && - squidIntegratorId != null - ) { - val params: IMap = iMapOf( - "fromChain" to fromChain, - "fromToken" to fromToken, - "fromAmount" to fromAmountString, - "toChain" to chainId, - "toToken" to nativeChainUSDCDenom, - "toAddress" to accountAddress, - "slippage" to "1", - "enableForecall" to "false", - "fromAddress" to sourceAddress, - ) - - val oldState = stateMachine.state - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, - ) - helper.get(url, params, header) { _, response, code, headers -> - if (response != null) { - val currentFromAmount = stateMachine.state?.input?.transfer?.size?.size - val oldFromAmount = oldState?.input?.transfer?.size?.size - val requestId = helper.parser.asString(headers?.get("x-request-id")) - if (currentFromAmount == oldFromAmount) { - update(stateMachine.squidRoute(response, subaccountNumber ?: 0, requestId), oldState) - } - } else { - Logger.e { "retrieveDepositRouteV1 error, code: $code" } - } - } - } - } - - private fun retrieveDepositRouteV2( - state: PerpetualState?, - accountAddress: String, - sourceAddress: String, - subaccountNumber: Int?, - ) { - val fromChain = state?.input?.transfer?.chain - val fromToken = state?.input?.transfer?.token - val fromAmount = helper.parser.asDecimal(state?.input?.transfer?.size?.size)?.let { - val decimals = - helper.parser.asInt(stateMachine.routerProcessor.selectedTokenDecimals(tokenAddress = fromToken, selectedChainId = fromChain)) - if (decimals != null) { - (it * Numeric.decimal.TEN.pow(decimals)).toBigInteger() - } else { - null - } - } - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val nativeChainUSDCDenom = helper.environment.tokens["usdc"]?.denom - val fromAmountString = helper.parser.asString(fromAmount) - val nobleAddress = accountAddress.toNobleAddress() - val url = helper.configs.squidV2Route() - val toChain = helper.configs.nobleChainId() - val toToken = helper.configs.nobleDenom - if (fromChain != null && - fromToken != null && - fromAmount != null && fromAmount > 0 && - fromAmountString != null && - nobleAddress != null && - chainId != null && - nativeChainUSDCDenom != null && - url != null && - squidIntegratorId != null && - toChain != null && - toToken != null - ) { - val body: Map = mapOf( - "fromChain" to fromChain, - "fromToken" to fromToken, - "fromAddress" to sourceAddress, - "fromAmount" to fromAmountString, - "toChain" to toChain, - "toToken" to toToken, - "toAddress" to nobleAddress, - "quoteOnly" to false, - "enableBoost" to false, - "slippage" to 1, - "slippageConfig" to iMapOf( - "autoMode" to 1, - ), - ) - val oldState = stateMachine.state - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, - "Content-Type" to "application/json", - ) - helper.post(url, header, body.toJsonPrettyPrint()) { _, response, code, headers -> - if (response != null) { - val currentFromAmount = stateMachine.state?.input?.transfer?.size?.size - val oldFromAmount = oldState?.input?.transfer?.size?.size - val requestId = helper.parser.asString(headers?.get("x-request-id")) - if (currentFromAmount == oldFromAmount) { - update(stateMachine.squidRouteV2(response, subaccountNumber ?: 0, requestId), oldState) - } - } else { - Logger.e { "retrieveDepositRouteV2 error, code: $code" } - } - } - } - } - internal fun transfer( data: String?, type: TransferInputField?, @@ -689,11 +507,7 @@ internal class OnboardingSupervisor( isCctp: Boolean, requestId: String?, ) { - if (StatsigConfig.useSkip) { - fetchTransferStatusSkip(hash, fromChainId) - } else { - fetchTransferStatus(hash, fromChainId, toChainId, isCctp) - } + fetchTransferStatusSkip(hash, fromChainId) } private fun simulateWithdrawal( @@ -769,39 +583,8 @@ internal class OnboardingSupervisor( val isCctp = CctpConfig.cctpChainIds?.any { it.isCctpEnabled(state?.input?.transfer) } ?: false val isExchange = state?.input?.transfer?.exchange != null - if (StatsigConfig.useSkip) { - if (isCctp) { - retrieveSkipWithdrawalRouteCCTP( - state, - decimals, - gas, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } else if (isExchange) { - retrieveSkipWithdrawalRouteExchange( - state, - decimals, - gas, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } else { - retrieveSkipWithdrawalRouteNonCCTP( - state, - decimals, - gas, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } - return - } - when (configs.squidVersion) { - OnboardingConfigs.SquidVersion.V2DepositOnly -> retrieveWithdrawalRouteV1( + if (isCctp) { + retrieveSkipWithdrawalRouteCCTP( state, decimals, gas, @@ -809,231 +592,24 @@ internal class OnboardingSupervisor( sourceAddress, subaccountNumber, ) - - OnboardingConfigs.SquidVersion.V2, OnboardingConfigs.SquidVersion.V2WithdrawalOnly -> - if (isCctp) { - retrieveWithdrawalRouteV2( - state, - decimals, - gas, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } else if (isExchange) { - retrieveWithdrawalRouteNoble( - state, - decimals, - gas, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } else { - retrieveWithdrawalRouteV1( - state, - decimals, - gas, - accountAddress, - sourceAddress, - subaccountNumber, - ) - } - } - } - - private fun retrieveWithdrawalRouteNoble( - state: PerpetualState?, - decimals: Int, - gas: BigDecimal, - accountAddress: String, - sourceAddress: String, - subaccountNumber: Int?, - ) { - val nobleChain = helper.configs.nobleChainId() - val nobleToken = helper.configs.nobleDenom - val toAddress = state?.input?.transfer?.address - val usdcSize = helper.parser.asDecimal(state?.input?.transfer?.size?.usdcSize) - val fromAmount = if (usdcSize != null && usdcSize > gas) { - ((usdcSize - gas) * Numeric.decimal.TEN.pow(decimals)).toBigInteger() - } else { - null - } - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val nativeChainUSDCDenom = helper.environment.tokens["usdc"]?.denom - val fromAmountString = helper.parser.asString(fromAmount) - val url = helper.configs.squidRoute() - val fromAddress = accountAddress - if (nobleChain != null && - nobleToken != null && - toAddress != null && - fromAmount != null && - fromAmount > 0 && - fromAmountString != null && - chainId != null && - nativeChainUSDCDenom != null && - url != null && - squidIntegratorId != null - ) { - val params: IMap = iMapOf( - "fromChain" to chainId, - "fromToken" to nativeChainUSDCDenom, - "fromAmount" to fromAmountString, - "fromAddress" to fromAddress, - "toChain" to nobleChain, - "toToken" to nobleToken, - "toAddress" to toAddress, - "slippage" to "1", - "enableForecall" to "false", - ) - - val oldState = stateMachine.state - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, - ) - helper.get(url, params, header) { _, response, _, headers -> - if (response != null) { - val requestId = helper.parser.asString(headers?.get("x-request-id")) - update(stateMachine.squidRoute(response, subaccountNumber ?: 0, requestId), oldState) - } - } - } - } - - private fun retrieveWithdrawalRouteV1( - state: PerpetualState?, - decimals: Int, - gas: BigDecimal, - accountAddress: String, - sourceAddress: String, - subaccountNumber: Int?, - ) { - val toChain = state?.input?.transfer?.chain - val toToken = state?.input?.transfer?.token - val toAddress = state?.input?.transfer?.address - val usdcSize = helper.parser.asDecimal(state?.input?.transfer?.size?.usdcSize) - val fromAmount = if (usdcSize != null && usdcSize > gas) { - ((usdcSize - gas) * Numeric.decimal.TEN.pow(decimals)).toBigInteger() - } else { - null - } - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val nativeChainUSDCDenom = helper.environment.tokens["usdc"]?.denom - val fromAmountString = helper.parser.asString(fromAmount) - val url = helper.configs.squidRoute() - val fromAddress = accountAddress - if (toChain != null && - toToken != null && - toAddress != null && - fromAmount != null && - fromAmount > 0 && - fromAmountString != null && - chainId != null && - nativeChainUSDCDenom != null && - url != null && - squidIntegratorId != null - ) { - val params: IMap = iMapOf( - "fromChain" to chainId, - "fromToken" to nativeChainUSDCDenom, - "fromAmount" to fromAmountString, - "fromAddress" to fromAddress, - "toChain" to toChain, - "toToken" to toToken, - "toAddress" to toAddress, - "slippage" to "1", - "enableForecall" to "false", - "cosmosSignerAddress" to accountAddress.toString(), - ) - - val oldState = stateMachine.state - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, + } else if (isExchange) { + retrieveSkipWithdrawalRouteExchange( + state, + decimals, + gas, + accountAddress, + sourceAddress, + subaccountNumber, ) - helper.get(url, params, header) { _, response, _, headers -> - if (response != null) { - val requestId = helper.parser.asString(headers?.get("x-request-id")) - update(stateMachine.squidRoute(response, subaccountNumber ?: 0, requestId), oldState) - } - } - } - } - - private fun retrieveWithdrawalRouteV2( - state: PerpetualState?, - decimals: Int, - gas: BigDecimal, - accountAddress: String, - sourceAddress: String, - subaccountNumber: Int?, - ) { - val toChain = state?.input?.transfer?.chain - val toToken = state?.input?.transfer?.token - val toAddress = state?.input?.transfer?.address - val usdcSize = helper.parser.asDecimal(state?.input?.transfer?.size?.usdcSize) - val fromAmount = if (usdcSize != null && usdcSize > gas) { - ((usdcSize - gas) * Numeric.decimal.TEN.pow(decimals)).toBigInteger() } else { - null - } - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val nativeChainUSDCDenom = helper.environment.tokens["usdc"]?.denom - val fromAmountString = helper.parser.asString(fromAmount) - val url = helper.configs.squidV2Route() - val fromAddress = accountAddress.toNobleAddress() - val fromChain = helper.configs.nobleChainId() - val fromToken = helper.configs.nobleDenom - if (toChain != null && - toToken != null && - toAddress != null && - fromAmount != null && - fromAmount > 0 && - fromAmountString != null && - chainId != null && - nativeChainUSDCDenom != null && - url != null && - fromAddress != null && - squidIntegratorId != null && - fromChain != null && - fromToken != null - ) { - val body: IMap = iMapOf( - "fromChain" to fromChain, - "fromToken" to fromToken, - "fromAmount" to fromAmountString, - "fromAddress" to fromAddress, - "toChain" to toChain, - "toToken" to toToken, - "toAddress" to toAddress, - "quoteOnly" to false, - "enableBoost" to false, - "slippage" to 1, - "slippageConfig" to iMapOf( - "autoMode" to 1, - ), - // "enableForecall" to "false", - // "cosmosSignerAddress" to accountAddress.toString(), - ) - val oldState = stateMachine.state - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, - "Content-Type" to "application/json", + retrieveSkipWithdrawalRouteNonCCTP( + state, + decimals, + gas, + accountAddress, + sourceAddress, + subaccountNumber, ) - helper.post(url, header, body.toJsonPrettyPrint()) { url, response, code, headers -> - if (response != null) { - val currentFromAmount = stateMachine.state?.input?.transfer?.size?.size - val oldFromAmount = oldState?.input?.transfer?.size?.size - val requestId = helper.parser.asString(headers?.get("x-request-id")) - if (currentFromAmount == oldFromAmount) { - update(stateMachine.squidRouteV2(response, subaccountNumber ?: 0, requestId), oldState) - } - } else { - Logger.e { "retrieveWithdrawalRouteV2 error, code: $code" } - } - } } } @@ -1221,35 +797,6 @@ internal class OnboardingSupervisor( } } - private fun fetchTransferStatus( - hash: String, - fromChainId: String?, - toChainId: String?, - isCctp: Boolean, - ) { - val params: IMap = iMapOf( - "transactionId" to hash, - "fromChainId" to fromChainId, - "toChainId" to toChainId, - "bridgeType" to if (isCctp) "cctp" else null, - ).filterNotNull() - val url = if (isCctp) helper.configs.squidV2Status() else helper.configs.squidStatus() - val squidIntegratorId = helper.environment.squidIntegratorId - if (url != null && squidIntegratorId != null) { - val oldState = stateMachine.state - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, - ) - helper.get(url, params, header) { _, response, httpCode, _ -> - if (response != null) { - update(stateMachine.routerStatus(response, hash), oldState) - } else { - Logger.e { "fetchTransferStatus error, code: $httpCode" } - } - } - } - } - private fun fetchTransferStatusSkip( hash: String, fromChainId: String?, @@ -1303,61 +850,6 @@ internal class OnboardingSupervisor( } } - private fun transferNobleBalance(accountAddress: String, amount: BigDecimal) { - val url = helper.configs.squidRoute() - val fromChain = helper.configs.nobleChainId() - val fromToken = helper.configs.nobleDenom - val nobleAddress = accountAddress.toNobleAddress() - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val nativeChainUSDCDenom = helper.environment.tokens["usdc"]?.denom - if (url != null && - fromChain != null && - fromToken != null && - nobleAddress != null && - chainId != null && - nativeChainUSDCDenom != null && - squidIntegratorId != null - ) { - val params: Map = mapOf( - "fromChain" to fromChain, - "fromToken" to fromToken, - "fromAddress" to nobleAddress, - "fromAmount" to amount.toPlainString(), - "toChain" to chainId, - "toToken" to nativeChainUSDCDenom, - "toAddress" to accountAddress.toString(), - "slippage" to "1", - "enableForecall" to "false", - ) - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, - ) - helper.get(url, params, header) { _, response, code, _ -> - if (response != null) { - val json = helper.parser.decodeJsonObject(response) - val ibcPayload = - helper.parser.asString( - helper.parser.value( - json, - "route.transactionRequest.data", - ), - ) - if (ibcPayload != null) { - helper.transaction(TransactionType.SendNobleIBC, ibcPayload) { - val error = helper.parseTransactionResponse(it) - if (error != null) { - Logger.e { "transferNobleBalance error: $error" } - } - } - } - } else { - Logger.e { "transferNobleBalance error, code: $code" } - } - } - } - } - @Throws(Exception::class) fun depositPayload(subaccountNumber: Int?): HumanReadableDepositPayload { val transfer = stateMachine.state?.input?.transfer ?: throw Exception("Transfer is null") @@ -1420,14 +912,6 @@ internal class OnboardingSupervisor( ) } - fun faucetPayload(subaccountNumber: Int, amount: Double): HumanReadableFaucetPayload { - return HumanReadableFaucetPayload(subaccountNumber, amount) - } - - fun subaccountTransferPayloadJson(subaccountNumber: Int?): String { - return Json.encodeToString(subaccountTransferPayload(subaccountNumber)) - } - internal fun commitTransfer(subaccountNumber: Int?, callback: TransactionCallback) { val type = stateMachine.state?.input?.transfer?.type when (type) { @@ -1532,129 +1016,14 @@ internal class OnboardingSupervisor( subaccountNumber: Int?, callback: TransactionCallback ) { - if (StatsigConfig.useSkip) { - cctpToNobleSkip( - state, - decimals, - gas, - accountAddress, - subaccountNumber, - callback, - ) - } else { - cctpToNobleSquid( - state, - decimals, - gas, - accountAddress, - subaccountNumber, - callback, - ) - } - } - - private fun cctpToNobleSquid( - state: PerpetualState?, - decimals: Int, - gas: BigDecimal, - accountAddress: String, - subaccountNumber: Int?, - callback: TransactionCallback - ) { - val url = helper.configs.squidRoute() - val nobleChain = helper.configs.nobleChainId() - val nobleToken = helper.configs.nobleDenom - val nobleAddress = accountAddress.toNobleAddress() - val chainId = helper.environment.dydxChainId - val squidIntegratorId = helper.environment.squidIntegratorId - val nativeChainUSDCDenom = helper.environment.tokens["usdc"]?.denom - val usdcSize = helper.parser.asDecimal(state?.input?.transfer?.size?.usdcSize) - val fromAmount = if (usdcSize != null && usdcSize > gas) { - ((usdcSize - gas) * Numeric.decimal.TEN.pow(decimals)).toBigInteger() - } else { - null - } - val fromAmountString = helper.parser.asString(fromAmount) - - if (url != null && - nobleChain != null && - nobleToken != null && - nobleAddress != null && - chainId != null && - nativeChainUSDCDenom != null && - squidIntegratorId != null && - fromAmountString != null && fromAmount != null && fromAmount > 0 - ) { - val params: Map = mapOf( - "toChain" to nobleChain, - "toToken" to nobleToken, - "toAddress" to nobleAddress, - "fromAmount" to fromAmountString, - "fromChain" to chainId, - "fromToken" to nativeChainUSDCDenom, - "fromAddress" to accountAddress, - "slippage" to "1", - "enableForecall" to "false", - ) - val header = iMapOf( - "x-integrator-id" to squidIntegratorId, - ) - helper.get(url, params, header) { _, response, code, _ -> - if (response != null) { - val json = helper.parser.decodeJsonObject(response) - val ibcPayload = - helper.parser.asString( - helper.parser.value( - json, - "route.transactionRequest.data", - ), - ) - if (ibcPayload != null) { - val payload = helper.jsonEncoder.encode( - mapOf( - "subaccountNumber" to (subaccountNumber ?: 0), - "amount" to state?.input?.transfer?.size?.usdcSize, - "ibcPayload" to ibcPayload.encodeBase64(), - ), - ) - helper.transaction(TransactionType.WithdrawToNobleIBC, payload) { - val error = parseTransactionResponse(it) - if (error != null) { - Logger.e { "withdrawToNobleIBC error: $error" } - helper.send(error, callback) - } else { - pendingCctpWithdraw = CctpWithdrawState( -// we use skip state with squid route - singleMessagePayload = state?.input?.transfer?.requestPayload?.data, - callback = callback, - multiMessagePayload = null, - ) - } - } - } else { - Logger.e { "cctpToNobleSquid error, code: $code" } - val error = ParsingError( - ParsingErrorType.MissingContent, - "Missing squid response", - ) - helper.send(error, callback) - } - } else { - Logger.e { "cctpToNobleSquid error, code: $code" } - val error = ParsingError( - ParsingErrorType.MissingContent, - "Missing squid response", - ) - helper.send(error, callback) - } - } - } else { - val error = ParsingError( - ParsingErrorType.MissingRequiredData, - "Missing required data for cctp withdraw", - ) - helper.send(error, callback) - } + cctpToNobleSkip( + state, + decimals, + gas, + accountAddress, + subaccountNumber, + callback, + ) } private fun cctpToNobleSkip( diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/app/manager/v2/V4ForegroundCycleTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/app/manager/v2/V4ForegroundCycleTests.kt index 31b5e9871..cbf863ebc 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/app/manager/v2/V4ForegroundCycleTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/app/manager/v2/V4ForegroundCycleTests.kt @@ -98,18 +98,6 @@ class V4ForegroundCycleTests : NetworkTests() { ) compareExpectedRequests( -// """ -// [ -// "https://api.examples.com/configs/documentation.json", -// "https://indexer.v4staging.dydx.exchange/v4/time", -// "https://api.examples.com/configs/markets.json", -// "https://testnet.v2.api.squidrouter.com/v2/sdk-info", -// "https://api.examples.com/configs/cctp.json", -// "https://api.examples.com/configs/exchanges.json", -// "https://indexer.v4staging.dydx.exchange/v4/height", -// "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals" -// ] -// """.trimIndent(), """ [ "https://api.examples.com/configs/documentation.json", @@ -117,7 +105,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo" @@ -200,7 +191,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", + "https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", @@ -246,23 +240,6 @@ class V4ForegroundCycleTests : NetworkTests() { ) compareExpectedRequests( -// """ -// [ -// "https://api.examples.com/configs/documentation.json", -// "https://indexer.v4staging.dydx.exchange/v4/time", -// "https://api.examples.com/configs/markets.json", -// "https://testnet.v2.api.squidrouter.com/v2/sdk-info", -// "https://api.examples.com/configs/cctp.json", -// "https://api.examples.com/configs/exchanges.json", -// "https://indexer.v4staging.dydx.exchange/v4/height", -// "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", -// "https://indexer.v4staging.dydx.exchange/v4/sparklines?timePeriod=ONE_DAY", -// "https://indexer.v4staging.dydx.exchange/v4/historicalFunding/ETH-USD", -// "https://indexer.v4staging.dydx.exchange/v4/candles/perpetualMarkets/ETH-USD?resolution=1DAY", -// "https://indexer.v4staging.dydx.exchange/v4/historicalFunding/BTC-USD", -// "https://indexer.v4staging.dydx.exchange/v4/candles/perpetualMarkets/BTC-USD?resolution=1DAY" -// ] -// """.trimIndent(), """ [ "https://api.examples.com/configs/documentation.json", @@ -270,7 +247,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", @@ -304,21 +284,6 @@ class V4ForegroundCycleTests : NetworkTests() { /* Only getting historical funding rate once for now */ compareExpectedRequests( -// """ -// [ -// "https://api.examples.com/configs/documentation.json", -// "https://indexer.v4staging.dydx.exchange/v4/time", -// "https://api.examples.com/configs/markets.json", -// "https://testnet.v2.api.squidrouter.com/v2/sdk-info", -// "https://api.examples.com/configs/cctp.json", -// "https://api.examples.com/configs/exchanges.json", -// "https://indexer.v4staging.dydx.exchange/v4/height", -// "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", -// "https://indexer.v4staging.dydx.exchange/v4/sparklines?timePeriod=ONE_DAY", -// "https://indexer.v4staging.dydx.exchange/v4/historicalFunding/ETH-USD", -// "https://indexer.v4staging.dydx.exchange/v4/candles/perpetualMarkets/ETH-USD?resolution=1DAY" -// ] -// """.trimIndent(), """ [ "https://api.examples.com/configs/documentation.json", @@ -326,7 +291,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", @@ -391,7 +359,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", @@ -446,7 +417,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", @@ -557,7 +531,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", @@ -605,7 +582,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", @@ -690,7 +670,10 @@ class V4ForegroundCycleTests : NetworkTests() { "https://indexer.v4staging.dydx.exchange/v4/height", "https://api.examples.com/configs/markets.json", "https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals", - "https://testnet.v2.api.squidrouter.com/v2/sdk-info", +"https://api.skip.money/v2/info/chains?include_evm=true&include_svm=true&only_testnets=true", + "https://api.examples.com/configs/rpc.json", + "https://api.skip.money/v2/fungible/assets?include_evm_assets=true&include_svm_assets=true&only_testnets=true", + "https://api.skip.money/v2/fungible/venues", "https://api.examples.com/configs/cctp.json", "https://api.examples.com/configs/exchanges.json", "https://api.dydx.exchange/v4/geo", diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4SquidTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4SquidTests.kt deleted file mode 100644 index 8519fab0a..000000000 --- a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4SquidTests.kt +++ /dev/null @@ -1,289 +0,0 @@ -package exchange.dydx.abacus.payload.v4 - -import exchange.dydx.abacus.state.model.TransferInputField -import exchange.dydx.abacus.state.model.routerChains -import exchange.dydx.abacus.state.model.routerStatus -import exchange.dydx.abacus.state.model.routerTokens -import exchange.dydx.abacus.state.model.squidRoute -import exchange.dydx.abacus.state.model.squidRouteV2 -import exchange.dydx.abacus.state.model.squidV2SdkInfo -import exchange.dydx.abacus.state.model.transfer -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull -import kotlin.test.assertTrue - -class V4SquidTests : V4BaseTests() { - @Test - fun testDepositChains() { - // Due to the JIT compiler nature for JVM (and Kotlin) and JS, Android/web would ran slow the first round. Second round give more accurate result - setup() - - val stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - test({ - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - val chains = it.state?.input?.transfer?.depositOptions?.chains!! - assertTrue(chains.size > 0) - val chain = chains[0] - assertTrue(chain.type.isNotEmpty()) - assertTrue(chain.iconUrl!!.isNotEmpty()) - assertTrue(chain.stringKey != null || chain.string != null) - assertTrue(it.state?.input?.transfer?.resources?.chainResources != null) - }) - - test({ - perp.transfer(null, TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - assertTrue(it.state?.input?.transfer?.depositOptions == null) - }) - } - - @Test - fun testDepositTokens() { - // Due to the JIT compiler nature for JVM (and Kotlin) and JS, Android/web would ran slow the first round. Second round give more accurate result - setup() - - var stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - test({ - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - val assets = it.state?.input?.transfer?.depositOptions?.assets!! - assertTrue(assets.size > 0) - val token = assets[0] - assertTrue(token.type.isNotEmpty()) - assertTrue(token.iconUrl!!.isNotEmpty()) - assertTrue(token.stringKey != null || token.string != null) - assertTrue(it.state?.input?.transfer?.resources?.tokenResources != null) - assertTrue(it.state?.input?.transfer?.token != null) - }) - - test({ - perp.transfer(null, TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - assertTrue(it.state?.input?.transfer?.depositOptions == null) - }) - } - - @Test - fun testSquidRouteV2() { - setup() - - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - - var stateChange = perp.squidV2SdkInfo(mock.squidV2AssetsMock.payload) - assertNotNull(stateChange) - - stateChange = perp.squidRouteV2(mock.squidV2RouteMock.payload, 0, null) - assertNotNull(stateChange) - - test({ - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - val summary = - if (perp.staticTyping) { - perp.internalState.input.transfer.summary - } else { - it.state?.input?.transfer?.summary!! - } - assertNotNull(summary) - assertTrue { summary.slippage!!.toInt() == 0 } - assertTrue { summary.exchangeRate!! > 0 } - assertTrue { summary.estimatedRouteDuration!! > 0 } - assertTrue { summary.gasFee!! > 0 } - // assertTrue { summary.bridgeFee!! > 0 } - if (perp.staticTyping) { - val route = perp.internalState.input.transfer.route - val requestPayload = parser.asNativeMap(parser.value(route, "requestPayload")) - assertNotNull(requestPayload) - assertNotNull(perp.internalState.input.transfer.size?.usdcSize) - } else { - assertNotNull(it.state?.input?.transfer?.requestPayload) - assertNotNull(it.state?.input?.transfer?.size?.usdcSize) - } - }) - - test({ - perp.transfer("0", TransferInputField.size, 0, environment = mock.v4Environment) - }, null, { - if (perp.staticTyping) { - val route = perp.internalState.input.transfer.route - val requestPayload = parser.asNativeMap(parser.value(route, "requestPayload")) - assertNull(requestPayload) - } else { - assertNull(it.state?.input?.transfer?.requestPayload) - } - }) - } - - @Test - fun testSquidRoute() { - setup() - - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - - var stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - stateChange = perp.squidRoute(mock.squidRouteMock.payload, 0, null) - assertNotNull(stateChange) - - test({ - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - val summary = it.state?.input?.transfer?.summary!! - assertNotNull(summary) - assertTrue { summary.slippage!! > 0 } - assertTrue { summary.exchangeRate!! > 0 } - assertTrue { summary.estimatedRouteDuration!! > 0 } - assertTrue { summary.gasFee!! > 0 } - assertTrue { summary.bridgeFee!! > 0 } - assertNotNull(it.state?.input?.transfer?.requestPayload) - assertNotNull(it.state?.input?.transfer?.size?.usdcSize) - }) - - test({ - perp.transfer("0", TransferInputField.size, 0, environment = mock.v4Environment) - }, null, { - assertNull(it.state?.input?.transfer?.requestPayload) - }) - } - - @Test - fun testSquidRoute_error() { - setup() - - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - - var stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - stateChange = perp.squidRoute(mock.squidRouteMock.errors_payload, 0, null) - assertNotNull(stateChange) - - test({ - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - val errors = it.state?.input?.transfer?.errors!! - assertNotNull(errors) - - assertEquals( - it.state?.input?.transfer?.errorMessage, - "toChain: dydxprotocol-testnet-1 unsupported chain id", - ) - }) - } - - @Test - fun testSquidStatus() { - setup() - - val stateChange = perp.routerStatus(mock.squidStatusMock.payload, null) - assertNotNull(stateChange) - assertNotNull(perp.data?.get("transferStatuses")) - - perp.updateStateChanges(stateChange) - - test({ - perp.transfer("DEPOSIT", TransferInputField.type, 0, environment = mock.v4Environment) - }, null, { - val transferStatuses = it.state?.transferStatuses - assertNotNull(transferStatuses) - val status = transferStatuses.values.first() - assertEquals(status.status, "destination_executed") - assertEquals(status.gasStatus, "gas_paid_enough_gas") - assertNotNull(status.axelarTransactionUrl) - assertEquals(status.routeStatuses?.first()?.status, "success") - assertEquals(status.routeStatuses?.last()?.status, "success") - assertNotNull(status.squidTransactionStatus) - }) - } - - @Test - fun testSelectedTokenSymbol() { - setup() - - val stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - assertTrue(perp.routerProcessor.selectedTokenSymbol("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "should_not_matter") == "ETH") - } - - @Test - fun testSelectedTokenDecimals() { - setup() - - val stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - assertTrue(perp.routerProcessor.selectedTokenDecimals("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "should_not_matter") == "18") - } - - @Test - fun testDefaultTokenAddress() { - setup() - - var stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - assertTrue(perp.routerProcessor.defaultTokenAddress("1") == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") - } - - @Test - fun testChainResources() { - setup() - - val stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - val result = perp.routerProcessor.chainResources("1") - val resource = result?.get("1") - assertTrue(resource?.chainId == 1) // Ethereum - assertTrue(resource?.chainName == "Ethereum") // Ethereum - } - - @Test - fun testTokenResources() { - setup() - - var stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - val result = perp.routerProcessor.tokenResources("1") - assertTrue((result?.keys?.size ?: 0) > 0) - } - - @Test - fun testTokenOptions() { - setup() - - var stateChange = perp.routerChains(mock.squidChainsMock.payload) - assertNotNull(stateChange) - - stateChange = perp.routerTokens(mock.squidTokensMock.payload) - assertNotNull(stateChange) - - val result = perp.routerProcessor.tokenOptions("1") - assertTrue(result.size > 0) - } -} diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/state/model/TradingStateMachineTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/state/model/TradingStateMachineTests.kt index 125cad948..780911f6a 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/state/model/TradingStateMachineTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/state/model/TradingStateMachineTests.kt @@ -1,14 +1,12 @@ package exchange.dydx.abacus.state.model import exchange.dydx.abacus.processor.router.skip.SkipProcessor -import exchange.dydx.abacus.processor.router.squid.SquidProcessor -import exchange.dydx.abacus.state.manager.StatsigConfig import kotlin.test.Test import kotlin.test.assertTrue class TradingStateMachineTests { @Test - fun testConstructRouterProcessorSkip() { + fun testConstructRouterProcessor() { val tradingStateMachine = TradingStateMachine( environment = null, localizer = null, @@ -17,21 +15,6 @@ class TradingStateMachineTests { useParentSubaccount = false, trackingProtocol = null, ) - StatsigConfig.useSkip = true assertTrue(tradingStateMachine.routerProcessor is SkipProcessor) } - - @Test - fun testConstructRouterProcessorSquid() { - val tradingStateMachine = TradingStateMachine( - environment = null, - localizer = null, - formatter = null, - maxSubaccountNumber = 1, - useParentSubaccount = false, - trackingProtocol = null, - ) - StatsigConfig.useSkip = false - assertTrue(tradingStateMachine.routerProcessor is SquidProcessor) - } } diff --git a/v4_abacus.podspec b/v4_abacus.podspec index b3c4f5eb1..89e27a464 100644 --- a/v4_abacus.podspec +++ b/v4_abacus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'v4_abacus' - spec.version = '1.11.0' + spec.version = '1.11.1' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''