Updated on 2026-08-14

This commit is contained in:
Tangem 2025-09-26 14:54:13 +05:00
parent 660defb213
commit c56b64bc36
4 changed files with 58 additions and 34 deletions

View file

@ -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<ExpressProvider>.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
}
}
}

View file

@ -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(

View file

@ -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(

View file

@ -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<SwapProvider, SwapState>.getLastLoadedSuccessStates(): SuccessLoadedSwapData {