Updated on 2026-08-14

This commit is contained in:
Tangem 2026-05-29 17:48:29 +04:00
parent 7f2e5650e2
commit 16c7de9054
27 changed files with 796 additions and 70 deletions

View file

@ -30,4 +30,6 @@ data class SwapCurrencyStatus(
get() = status.currency
val userWalletId: UserWalletId
get() = userWallet.walletId
val isYieldSupplyActive: Boolean
get() = status.value.yieldSupplyStatus?.isActive == true
}

View file

@ -46,7 +46,7 @@ class GetEthSpecificFeeUseCase(
val minimalFee = getEthLegacyFee(
gasPrice = gasPriceResult,
gasLimit = gasLimit,
decimals = cryptoCurrency.decimals,
decimals = blockchain.decimals(),
blockchain = blockchain,
)
@ -54,7 +54,7 @@ class GetEthSpecificFeeUseCase(
val normalFee = getEthLegacyFee(
gasPrice = normalGasPrice,
gasLimit = gasLimit,
decimals = cryptoCurrency.decimals,
decimals = blockchain.decimals(),
blockchain = blockchain,
)
@ -64,7 +64,7 @@ class GetEthSpecificFeeUseCase(
val priorityFee = getEthLegacyFee(
gasPrice = priorityGasPrice,
gasLimit = gasLimit,
decimals = cryptoCurrency.decimals,
decimals = blockchain.decimals(),
blockchain = blockchain,
)

View file

@ -0,0 +1,25 @@
package com.tangem.domain.yield.supply
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWalletId
/**
* Resolves the yield-module proxy address for a `(wallet, network)` pair and caches the result.
*
* The address is derived from on-chain state (factory contract + user's wallet) and is stable
* for the lifetime of the wallet, so caching the result avoids redundant blockchain calls.
*
* Call [invalidate] when the wallet's yield-module state may have changed (e.g. after a
* successful upgrade or removal of yield-supply).
*/
interface YieldModuleAddressProvider {
/**
* Returns the yield-module proxy address, or `null` if the address is currently unavailable
* (e.g. RPC failure inside the SDK).
*/
suspend fun getOrFetch(userWalletId: UserWalletId, network: Network): String?
/** Drops cached entries for [userWalletId], or the entire cache when [userWalletId] is `null`. */
fun invalidate(userWalletId: UserWalletId? = null)
}

View file

@ -1,9 +1,11 @@
package com.tangem.domain.yield.supply
import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.smartcontract.SmartContractCallData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWalletId
import java.math.BigDecimal
@ -24,4 +26,14 @@ interface YieldSupplyTransactionRepository {
suspend fun getYieldContractAddress(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): String?
suspend fun getEffectiveProtocolBalance(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): BigDecimal?
/**
* Checks the version status of the user's yield-module contract and wraps [callData] with an
* upgrade transaction if the deployed version is out of date.
*/
suspend fun wrapYieldSwapCallDataWithUpgradeIfNeeded(
userWalletId: UserWalletId,
network: Network,
callData: SmartContractCallData,
): SmartContractCallData
}

View file

@ -0,0 +1,25 @@
package com.tangem.domain.yield.supply.usecase
import com.tangem.blockchain.common.smartcontract.SmartContractCallData
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.yield.supply.YieldSupplyTransactionRepository
/**
* Wraps a yield-swap call data with a yield-module upgrade transaction when the user's deployed
* yield-module contract version is out of date.
*/
class WrapYieldSwapCallDataWithUpgradeUseCase(
private val yieldSupplyTransactionRepository: YieldSupplyTransactionRepository,
) {
suspend operator fun invoke(
userWalletId: UserWalletId,
network: Network,
callData: SmartContractCallData,
): SmartContractCallData = yieldSupplyTransactionRepository.wrapYieldSwapCallDataWithUpgradeIfNeeded(
userWalletId = userWalletId,
network = network,
callData = callData,
)
}