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 d16b31097..968f5911f 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 @@ -219,7 +219,7 @@ internal class SkipProcessor( } } } - options.sortBy { parser.asString(parser.asNativeMap(it)?.get("stringKey")) } + options.sortBy { parser.asString(it.stringKey) } return options } } 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 index 101e0c071..76563a084 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 @@ -14,7 +14,7 @@ internal class SkipTokenResourceProcessor( address = parser.asString(payload["denom"]), symbol = parser.asString(payload["symbol"]), decimals = parser.asInt(payload["decimals"]), - iconUrl = parser.asString(payload["logo_urk"]), + iconUrl = parser.asString(payload["logo_uri"]), ) } } 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 index c0362a6be..f1d7c1e40 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 @@ -173,8 +173,6 @@ internal class SquidProcessor( override fun updateTokensDefaults(modified: MutableMap, selectedChainId: String?) { val tokenOptions = tokenOptions(selectedChainId) internalState.tokens = tokenOptions - modified.safeSet("transfer.depositOptions.assets", tokenOptions) - modified.safeSet("transfer.withdrawalOptions.assets", tokenOptions) modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId)) internalState.tokenResources = tokenResources(selectedChainId) } 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 49b792b46..4214fb79b 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 @@ -25,10 +25,12 @@ import exchange.dydx.abacus.state.manager.pendingCctpWithdraw import exchange.dydx.abacus.state.model.TradingStateMachine import exchange.dydx.abacus.state.model.TransferInputField import exchange.dydx.abacus.state.model.routerChains +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.squidStatus 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 import exchange.dydx.abacus.utils.Logger diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt index 59bbc0e8a..b4db78f6f 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt @@ -1,6 +1,7 @@ package exchange.dydx.abacus.processor.router.skip import exchange.dydx.abacus.output.input.SelectionOption import exchange.dydx.abacus.output.input.TransferInputChainResource +import exchange.dydx.abacus.output.input.TransferInputTokenResource import exchange.dydx.abacus.state.internalstate.InternalTransferInputState import exchange.dydx.abacus.tests.payloads.SkipChainsMock import exchange.dydx.abacus.tests.payloads.SkipTokensMock @@ -18,7 +19,8 @@ internal fun templateToJson(template: String): Map { class SkipProcessorTests { internal val internalState = InternalTransferInputState() - internal val skipProcessor = SkipProcessor(parser = Parser(), internalState = internalState) + internal val parser = Parser() + internal val skipProcessor = SkipProcessor(parser = parser, internalState = internalState) internal val skipChainsMock = SkipChainsMock() internal val skipTokensMock = SkipTokensMock() internal val selectedChainId = "osmosis-1" @@ -104,7 +106,7 @@ class SkipProcessorTests { addTokens() } -// ///////////////// UNIT TESTS ////////////////////// +// ////////////////// UNIT TESTS ////////////////////// @Test fun testFilteredTokens() { val result = skipProcessor.filteredTokens(chainId = selectedChainId) @@ -137,28 +139,29 @@ class SkipProcessorTests { fun testTokenResources() { val result = skipProcessor.tokenResources(selectedChainId) val expected = mapOf( - selectedTokenAddress to mapOf( - "address" to selectedTokenAddress, - "symbol" to selectedTokenSymbol, - "decimals" to selectedTokenDecimals, - "name" to "some-name", - "iconUrl" to "some-logo-uri", + selectedTokenAddress to TransferInputTokenResource( + address = selectedTokenAddress, + symbol = selectedTokenSymbol, + decimals = parser.asInt(selectedTokenDecimals), + name = "some-name", + iconUrl = "some-logo-uri", ), - "testTokenKeyValue2" to mapOf( - "address" to "testTokenKeyValue2", - "symbol" to "ARB", - "decimals" to 8, - "name" to "some-name-2", - "iconUrl" to "some-logo-uri-2", + "testTokenKeyValue2" to TransferInputTokenResource( + address = "testTokenKeyValue2", + symbol = "ARB", + decimals = 8, + name = "some-name-2", + iconUrl = "some-logo-uri-2", ), - "testTokenKeyValue3" to mapOf( - "address" to "testTokenKeyValue3", - "symbol" to "ETH", - "decimals" to 5, - "name" to "some-name-3", - "iconUrl" to "some-logo-uri-3", + "testTokenKeyValue3" to TransferInputTokenResource( + address = "testTokenKeyValue3", + symbol = "ETH", + decimals = 5, + name = "some-name-3", + iconUrl = "some-logo-uri-3", ), ) + assertEquals(expected, result) } @Test @@ -198,7 +201,6 @@ class SkipProcessorTests { existing = mapOf(), payload = payload, ) - val expectedChains = listOf( SelectionOption(stringKey = "Ethereum", string = "Ethereum", type = "1", iconUrl = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png"), SelectionOption(stringKey = "aura", string = "aura", type = "xstaxy-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/xstaxy/chain.png"), @@ -207,8 +209,6 @@ class SkipProcessorTests { SelectionOption(stringKey = "osmosis", string = "osmosis", type = "osmosis-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/osmosis/chain.png"), SelectionOption(stringKey = "stride", string = "stride", type = "stride-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/stride/chain.png"), ) - assertEquals(expectedChains, internalState.chains) - val expectedChainResources = mapOf( "1" to TransferInputChainResource( chainName = "Ethereum", @@ -216,14 +216,15 @@ class SkipProcessorTests { iconUrl = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png", ), ) - assertEquals(payload["chains"], skipProcessor.chains) - assertEquals(expectedChainResources, internalState.chainResources) - val expectedModified = mapOf( "transfer" to mapOf( "chain" to "1", ), ) + + assertEquals(expectedChains, internalState.chains) + assertEquals(payload["chains"], skipProcessor.chains) + assertEquals(expectedChainResources, internalState.chainResources) assertEquals(expectedModified, modified) } @@ -243,67 +244,62 @@ class SkipProcessorTests { "is_testnet" to false, ), ) - - val result = skipProcessor.receivedTokens( + val modified = skipProcessor.receivedTokens( existing = mapOf(), payload = payload, ) - - val assets = mapOf( - "assets" to listOf( - mapOf( - "stringKey" to "Euro Coin", - "type" to "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c", - "iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg", - ), - mapOf( - "stringKey" to "Real Yield USD", - "type" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", - "iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg", - ), - mapOf( - "stringKey" to "Umee native token", - "type" to "0x923e030f951A2401426a3407a9bcc7EB715d9a0b", - "iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg", - ), - ), - ) - val expected = mapOf( + val expectedModified = mapOf( "transfer" to mapOf( - "depositOptions" to assets.toMap(), - "withdrawalOptions" to assets.toMap(), "token" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", - "resources" to mapOf( - "tokenResources" to mapOf( - "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E" to mapOf( - "name" to "Real Yield USD", - "address" to "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", - "symbol" to "YieldUSD", - "decimals" to 18, - "iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg", - ), - "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c" to mapOf( - "name" to "Euro Coin", - "address" to "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c", - "symbol" to "EUROC", - "decimals" to 6, - "iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg", - ), - "0x923e030f951A2401426a3407a9bcc7EB715d9a0b" to mapOf( - "name" to "Umee native token", - "address" to "0x923e030f951A2401426a3407a9bcc7EB715d9a0b", - "symbol" to "UMEE", - "decimals" to 6, - "iconUrl" to "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg", - ), - ), - ), ), ) -// For some reason jtest fails the test even though the diff checker can't find a difference -// https://dydx-team.slack.com/archives/C06S9ND5T40/p1717014127580439 - assertEquals(expected.keys, result?.keys) - assertEquals(expected.toString(), result?.toString()) + val expectedTokens = listOf( + SelectionOption( + stringKey = "Euro Coin", + string = "Euro Coin", + type = "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c", + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg", + ), + SelectionOption( + stringKey = "Real Yield USD", + string = "Real Yield USD", + type = "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg", + ), + SelectionOption( + stringKey = "Umee native token", + string = "Umee native token", + type = "0x923e030f951A2401426a3407a9bcc7EB715d9a0b", + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg", + ), + ) + val expectedTokenResources = mapOf( + "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E" to TransferInputTokenResource( + name = "Real Yield USD", + address = "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", + symbol = "YieldUSD", + decimals = 18, + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/yieldusd.svg", + ), + "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c" to TransferInputTokenResource( + name = "Euro Coin", + address = "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c", + symbol = "EUROC", + decimals = 6, + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/euroc.svg", + ), + "0x923e030f951A2401426a3407a9bcc7EB715d9a0b" to TransferInputTokenResource( + name = "Umee native token", + address = "0x923e030f951A2401426a3407a9bcc7EB715d9a0b", + symbol = "UMEE", + decimals = 6, + iconUrl = "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/umee.svg", + ), + ) + + assertEquals(expectedModified, modified) assertEquals(payload["chain_to_assets_map"], skipProcessor.skipTokens) + assertEquals(expectedTokens, internalState.tokens) + assertEquals(expectedTokenResources, internalState.tokenResources) } }