Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-26 15:48:05 +04:00
parent 7e94a484a0
commit 80e33b892a
51 changed files with 2975 additions and 445 deletions

View file

@ -24,6 +24,7 @@ dependencies {
implementation(projects.core.analytics)
/** Domain */
implementation(projects.domain.transaction)
implementation(projects.domain.yieldSupply)
implementation(projects.domain.yieldSupply.models)
implementation(projects.domain.walletManager)

View file

@ -8,6 +8,7 @@ import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.smartcontract.SmartContractCallData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.yieldsupply.YieldSupplyContractCallDataProviderFactory
import com.tangem.blockchain.yieldsupply.providers.YieldModuleVersionStatus
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
@ -238,6 +239,37 @@ internal class DefaultYieldSupplyTransactionRepository(
YieldSupplyContractCallDataProviderFactory.wrapWithUpgradeIfNeeded(versionStatus, callData)
}
override suspend fun getYieldModuleVersionStatus(
userWalletId: UserWalletId,
network: Network,
): YieldModuleVersionStatus = withContext(dispatchers.io) {
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = network.toBlockchain(),
derivationPath = network.derivationPath.value,
) ?: error("Wallet manager not found for $network")
walletManager.checkModuleVersionStatus()
}
override suspend fun createPartialWithdrawCallData(
userWalletId: UserWalletId,
cryptoCurrency: CryptoCurrency,
amount: Amount,
): SmartContractCallData = withContext(dispatchers.io) {
require(cryptoCurrency is CryptoCurrency.Token)
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = cryptoCurrency.network.toBlockchain(),
derivationPath = cryptoCurrency.network.derivationPath.value,
) ?: error("Wallet manager not found")
val withdrawCallData = YieldSupplyContractCallDataProviderFactory.getWithdrawCallData(
tokenContractAddress = cryptoCurrency.contractAddress,
amount = amount,
)
val versionStatus = walletManager.checkModuleVersionStatus()
YieldSupplyContractCallDataProviderFactory.wrapWithUpgradeIfNeeded(versionStatus, withdrawCallData)
}
private suspend fun getYieldTokenStatus(
walletManager: WalletManager,
cryptoCurrency: CryptoCurrency.Token,

View file

@ -12,6 +12,7 @@ import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.yieldsupply.YieldMarketsStore
import com.tangem.datasource.local.yieldsupply.promo.YieldBoostPromoStore
import com.tangem.datasource.local.yieldsupply.promo.YieldBoostStatusStore
import com.tangem.domain.transaction.GaslessYieldRepository
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.yield.supply.YieldModuleAddressProvider
import com.tangem.domain.yield.supply.YieldSupplyRepository
@ -41,6 +42,14 @@ internal object YieldSupplyDataModule {
)
}
@Provides
@Singleton
fun provideGaslessYieldRepository(
yieldSupplyTransactionRepository: YieldSupplyTransactionRepository,
): GaslessYieldRepository {
return yieldSupplyTransactionRepository
}
@Provides
@Singleton
fun provideYieldSupplyMarketRepository(

View file

@ -3,11 +3,14 @@ package com.tangem.data.yield.supply
import com.google.common.truth.Truth
import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras
import com.tangem.blockchain.blockchains.ethereum.EthereumUtils
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Token
import com.tangem.blockchain.common.WalletManager
import com.tangem.blockchain.common.smartcontract.SmartContractCallDataProviderFactory
import com.tangem.blockchain.yieldsupply.YieldSupplyContractCallDataProviderFactory
import com.tangem.blockchain.yieldsupply.providers.YieldModuleVersionStatus
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.Network
@ -306,4 +309,35 @@ class DefaultYieldSupplyTransactionRepositoryTest {
Truth.assertThat(result.extras).isInstanceOf(EthereumTransactionExtras::class.java)
Truth.assertThat((result.extras as EthereumTransactionExtras).callData?.data).isEqualTo(expectedCallData.data)
}
@Test
fun `createPartialWithdrawCallData returns withdraw call data when module is up to date`() = runTest {
coEvery { walletManager.checkModuleVersionStatus() } returns YieldModuleVersionStatus.UpToDate
val token = mockk<CryptoCurrency.Token>(relaxed = true) {
every { contractAddress } returns mockedContractAddress
every { decimals } returns 6
}
val amount = Amount(
currencySymbol = "USDC",
value = BigDecimal("1.5"),
decimals = 6,
type = AmountType.Token(
token = Token(
symbol = "USDC",
contractAddress = mockedContractAddress,
decimals = 6,
),
),
)
val result = repository.createPartialWithdrawCallData(
userWalletId = userWalletId,
cryptoCurrency = token,
amount = amount,
)
Truth.assertThat(result).isNotNull()
Truth.assertThat(result.methodId).isEqualTo("0xf3fef3a3")
}
}