From c56b64bc36dfc68ba2057c4507a41b657b08a209 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 26 Sep 2025 14:54:13 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../data/swap/DefaultSwapRepositoryV2.kt | 15 +++++- .../DefaultTransactionRepository.kt | 46 +++++++++---------- .../DefaultWalletManagersFacade.kt | 21 ++++++--- .../tangem/feature/swap/model/SwapModel.kt | 10 +++- 4 files changed, 58 insertions(+), 34 deletions(-) diff --git a/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt b/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt index 1c07c142a5..343ba4d4bd 100644 --- a/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt +++ b/data/swap/src/main/java/com/tangem/data/swap/DefaultSwapRepositoryV2.kt @@ -96,7 +96,7 @@ internal class DefaultSwapRepositoryV2 @Inject constructor( val mappedProviders = pair.providers.mapNotNull { mappedProviders[it.providerId] - } + }.filterYieldSupplyProvider(statusFrom) if (statusFrom != null && statusTo != null && mappedProviders.isNotEmpty()) { SwapPairModel( @@ -153,7 +153,7 @@ internal class DefaultSwapRepositoryV2 @Inject constructor( val mappedProvider = pair.providers.mapNotNull { mappedProviders[it.providerId] - } + }.filterYieldSupplyProvider(currencyStatusFrom) if (currencyStatusFrom != null && currencyStatusTo != null && mappedProvider.isNotEmpty()) { SwapPairModel( @@ -422,4 +422,15 @@ internal class DefaultSwapRepositoryV2 @Inject constructor( is CryptoCurrency.Coin -> "0" } } + + private fun List.filterYieldSupplyProvider(cryptoCurrencyStatus: CryptoCurrencyStatus?) = + filter { provider -> + // !!!WARNING!!! Filter out dex provider if yield supply is active + val yieldSupplyStatus = cryptoCurrencyStatus?.value?.yieldSupplyStatus + if (yieldSupplyStatus != null && yieldSupplyStatus.isActive) { + provider.type == ExpressProviderType.CEX + } else { + true + } + } } \ No newline at end of file diff --git a/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt b/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt index 437fbe7c78..8054cbd5c0 100644 --- a/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt +++ b/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt @@ -57,6 +57,17 @@ internal class DefaultTransactionRepository( val extras = txExtras ?: getMemoExtras(networkId = network.rawId, memo) + val destination = if (amount.type is AmountType.TokenYieldSupply) { + walletManager.getYieldModuleAddress() + } else { + destination + } + val amount = if (amount.type is AmountType.TokenYieldSupply) { + amount.copy(value = BigDecimal.ZERO) + } else { + amount + } + return@withContext if (fee != null) { walletManager.createTransaction( amount = amount, @@ -86,11 +97,6 @@ internal class DefaultTransactionRepository( nonce: BigInteger?, ): TransactionData.Uncompiled = withContext(dispatchers.io) { val blockchain = network.toBlockchain() - val walletManager = walletManagersFacade.getOrCreateWalletManager( - userWalletId = userWalletId, - blockchain = blockchain, - derivationPath = network.derivationPath.value, - ) ?: error("Wallet manager not found") val callData = SmartContractCallDataProviderFactory.getTokenTransferCallData( destinationAddress = destination, @@ -98,7 +104,7 @@ internal class DefaultTransactionRepository( blockchain = blockchain, ) - val extras = if (amount.type is AmountType.Token && callData != null) { + val extras = if (callData != null) { createTransactionDataExtras( callData = callData, network = network, @@ -109,25 +115,15 @@ internal class DefaultTransactionRepository( null } - return@withContext if (fee != null) { - createTransaction( - amount = amount, - fee = fee, - memo = null, - destination = destination, - userWalletId = userWalletId, - network = network, - txExtras = getMemoExtras(networkId = network.rawId, memo = memo) ?: extras, - ) - } else { - TransactionData.Uncompiled( - amount = amount, - sourceAddress = walletManager.wallet.address, - destinationAddress = destination, - extras = getMemoExtras(networkId = network.rawId, memo = memo) ?: extras, - fee = null, - ) - } + createTransaction( + amount = amount, + fee = fee, + memo = null, + destination = destination, + userWalletId = userWalletId, + network = network, + txExtras = getMemoExtras(networkId = network.rawId, memo = memo) ?: extras, + ) } override suspend fun createApprovalTransaction( diff --git a/data/wallet-manager/src/main/java/com/tangem/data/walletmanager/DefaultWalletManagersFacade.kt b/data/wallet-manager/src/main/java/com/tangem/data/walletmanager/DefaultWalletManagersFacade.kt index acd08ed42d..e8237103f4 100644 --- a/data/wallet-manager/src/main/java/com/tangem/data/walletmanager/DefaultWalletManagersFacade.kt +++ b/data/wallet-manager/src/main/java/com/tangem/data/walletmanager/DefaultWalletManagersFacade.kt @@ -19,6 +19,7 @@ import com.tangem.blockchain.extensions.SimpleResult import com.tangem.blockchain.nft.models.NFTAsset import com.tangem.blockchain.nft.models.NFTCollection import com.tangem.blockchain.transactionhistory.models.TransactionHistoryRequest +import com.tangem.blockchain.yieldsupply.YieldSupplyContractCallDataProviderFactory import com.tangem.blockchainsdk.BlockchainSDKFactory import com.tangem.blockchainsdk.models.UpdateWalletManagerResult import com.tangem.blockchainsdk.utils.toBlockchain @@ -498,18 +499,26 @@ internal class DefaultWalletManagersFacade @Inject constructor( userWalletId = userWalletId, blockchain = blockchain, derivationPath = network.derivationPath.value, - ) + ) ?: error("Wallet manager not found") - val destination = estimationFeeAddressFactory.makeAddress(blockchain) + val destination = when (amount.type) { + is AmountType.Token -> estimationFeeAddressFactory.makeAddress(blockchain) + is AmountType.TokenYieldSupply -> walletManager.getYieldModuleAddress() + else -> return@withContext null + } - val callData = if (amount.type is AmountType.Token) { - SmartContractCallDataProviderFactory.getTokenTransferCallData( + val callData = when (val amountType = amount.type) { + is AmountType.Token -> SmartContractCallDataProviderFactory.getTokenTransferCallData( destinationAddress = destination, amount = amount, blockchain = blockchain, ) - } else { - null + is AmountType.TokenYieldSupply -> YieldSupplyContractCallDataProviderFactory.getSendCallData( + tokenContractAddress = amountType.token.contractAddress, + destinationAddress = estimationFeeAddressFactory.makeAddress(blockchain), + amount = amount, + ) + else -> null } (walletManager as? TransactionSender)?.estimateFee( diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt index 03da8bb772..35ca5f2d43 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt @@ -1263,7 +1263,15 @@ internal class SwapModel @Inject constructor( } return groupToFind.available.find { idToFind == it.currencyStatus.currency.id.value }?.providers - ?: emptyList() + ?.filter { provider -> + // !!!WARNING!!! Filter out dex provider if yield supply is active + val yieldSupplyStatus = fromToken.value.yieldSupplyStatus + if (yieldSupplyStatus != null && yieldSupplyStatus.isActive) { + provider.type == ExchangeProviderType.CEX + } else { + true + } + }.orEmpty() } private fun Map.getLastLoadedSuccessStates(): SuccessLoadedSwapData {