Updated on 2026-08-14
This commit is contained in:
parent
dcbe3fefb3
commit
c1f5c70791
7 changed files with 179 additions and 71 deletions
|
|
@ -30,6 +30,7 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
override suspend fun createEnterTransactions(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
maxNetworkFee: BigDecimal,
|
||||
): List<TransactionData.Uncompiled> {
|
||||
val cryptoCurrency = cryptoCurrencyStatus.currency
|
||||
|
||||
|
|
@ -62,6 +63,7 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
existingYieldContractAddress = existingYieldContractAddress,
|
||||
calculatedYieldContractAddress = calculatedYieldContractAddress,
|
||||
yieldTokenStatus = yieldTokenStatus,
|
||||
maxNetworkFee = maxNetworkFee,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -93,12 +95,14 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
)
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
private fun buildEnterTransactions(
|
||||
walletManager: WalletManager,
|
||||
cryptoCurrency: CryptoCurrency.Token,
|
||||
existingYieldContractAddress: String?,
|
||||
calculatedYieldContractAddress: String,
|
||||
yieldTokenStatus: YieldSupplyStatus?,
|
||||
maxNetworkFee: BigDecimal,
|
||||
): MutableList<TransactionData.Uncompiled> {
|
||||
val enterTransactions = mutableListOf<TransactionData.Uncompiled>()
|
||||
|
||||
|
|
@ -108,6 +112,7 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
createDeployTransaction(
|
||||
walletManager = walletManager,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
maxNetworkFee = maxNetworkFee,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -118,6 +123,7 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
cryptoCurrency = cryptoCurrency,
|
||||
yieldSupplyStatus = yieldTokenStatus,
|
||||
yieldContractAddress = calculatedYieldContractAddress,
|
||||
maxNetworkFee = maxNetworkFee,
|
||||
),
|
||||
)
|
||||
!yieldTokenStatus.isActive -> enterTransactions.add(
|
||||
|
|
@ -126,6 +132,7 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
cryptoCurrency = cryptoCurrency,
|
||||
yieldSupplyStatus = yieldTokenStatus,
|
||||
yieldContractAddress = calculatedYieldContractAddress,
|
||||
maxNetworkFee = maxNetworkFee,
|
||||
),
|
||||
)
|
||||
else -> Unit
|
||||
|
|
@ -202,6 +209,7 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
isActive = sdkSupplyStatus?.isActive == true,
|
||||
isInitialized = sdkSupplyStatus?.isInitialized == true,
|
||||
isAllowedToSpend = isAllowedToSpend,
|
||||
// maxNetworkFee = sdkSupplyStatus?.maxNetworkFee,
|
||||
)
|
||||
}.onFailure(Timber::e).getOrNull()
|
||||
}
|
||||
|
|
@ -209,11 +217,12 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
private fun createDeployTransaction(
|
||||
walletManager: WalletManager,
|
||||
cryptoCurrency: CryptoCurrency.Token,
|
||||
maxNetworkFee: BigDecimal,
|
||||
): TransactionData.Uncompiled {
|
||||
val callData = YieldSupplyContractCallDataProviderFactory.getDeployCallData(
|
||||
tokenContractAddress = cryptoCurrency.contractAddress,
|
||||
walletAddress = walletManager.wallet.address,
|
||||
maxNetworkFee = MAX_NETWORK_FEE.convertToSdkAmount(cryptoCurrency),
|
||||
maxNetworkFee = maxNetworkFee.convertToSdkAmount(cryptoCurrency),
|
||||
)
|
||||
|
||||
val factoryContractAddress = walletManager.getYieldSupplyContractAddresses()?.factoryContractAddress
|
||||
|
|
@ -234,10 +243,11 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
cryptoCurrency: CryptoCurrency.Token,
|
||||
yieldContractAddress: String,
|
||||
yieldSupplyStatus: YieldSupplyStatus,
|
||||
maxNetworkFee: BigDecimal,
|
||||
): TransactionData.Uncompiled {
|
||||
val callData = YieldSupplyContractCallDataProviderFactory.getInitTokenCallData(
|
||||
tokenContractAddress = cryptoCurrency.contractAddress,
|
||||
maxNetworkFee = MAX_NETWORK_FEE.convertToSdkAmount(cryptoCurrency),
|
||||
maxNetworkFee = maxNetworkFee.convertToSdkAmount(cryptoCurrency),
|
||||
)
|
||||
|
||||
return createTransaction(
|
||||
|
|
@ -255,10 +265,11 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
cryptoCurrency: CryptoCurrency.Token,
|
||||
yieldContractAddress: String,
|
||||
yieldSupplyStatus: YieldSupplyStatus,
|
||||
maxNetworkFee: BigDecimal,
|
||||
): TransactionData.Uncompiled {
|
||||
val callData = YieldSupplyContractCallDataProviderFactory.getReactivateTokenCallData(
|
||||
tokenContractAddress = cryptoCurrency.contractAddress,
|
||||
maxNetworkFee = MAX_NETWORK_FEE.convertToSdkAmount(cryptoCurrency),
|
||||
maxNetworkFee = maxNetworkFee.convertToSdkAmount(cryptoCurrency),
|
||||
)
|
||||
|
||||
return createTransaction(
|
||||
|
|
@ -364,8 +375,4 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
isAllowedToSpend = yieldSupplyStatus?.isAllowedToSpend ?: false,
|
||||
),
|
||||
)
|
||||
|
||||
private companion object {
|
||||
val MAX_NETWORK_FEE: BigDecimal = BigDecimal.TEN // TODO for TESTNET only
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@ import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
|||
import com.tangem.domain.utils.convertToSdkAmount
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
|
||||
import com.tangem.blockchain.yieldsupply.providers.YieldSupplyStatus as SDKYieldSupplyStatus
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
|
|
@ -26,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach
|
|||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.math.BigDecimal
|
||||
import com.tangem.blockchain.yieldsupply.providers.YieldSupplyStatus as SDKYieldSupplyStatus
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class DefaultYieldSupplyTransactionRepositoryTest {
|
||||
|
|
@ -74,7 +74,11 @@ class DefaultYieldSupplyTransactionRepositoryTest {
|
|||
coEvery { walletManager.isAllowedToSpend(any()) } returns false
|
||||
coEvery { walletManager.calculateYieldContract() } returns yieldContractAddress
|
||||
|
||||
val result = repository.createEnterTransactions(userWalletId, cryptoCurrencyStatus)
|
||||
val result = repository.createEnterTransactions(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
maxNetworkFee = BigDecimal.TEN,
|
||||
)
|
||||
|
||||
// Assert that 3 transactions are returned: deploy, approve, enter
|
||||
Truth.assertThat(result).isNotNull()
|
||||
|
|
@ -117,13 +121,18 @@ class DefaultYieldSupplyTransactionRepositoryTest {
|
|||
fun `createEnterTransactions returns init-approve-enter transactions`() = runTest {
|
||||
coEvery { walletManager.getYieldContract() } returns yieldContractAddress
|
||||
coEvery { walletManager.calculateYieldContract() } returns yieldContractAddress
|
||||
coEvery { walletManager.isAllowedToSpend(any()) } returns false
|
||||
coEvery { walletManager.getYieldSupplyStatus(any()) } returns SDKYieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = false,
|
||||
maxNetworkFee = BigDecimal.TEN,
|
||||
)
|
||||
|
||||
val result = repository.createEnterTransactions(userWalletId, cryptoCurrencyStatus)
|
||||
val result = repository.createEnterTransactions(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
maxNetworkFee = BigDecimal.TEN,
|
||||
)
|
||||
|
||||
// Assert that 3 transactions are returned: init token, approve, enter
|
||||
Truth.assertThat(result).isNotNull()
|
||||
|
|
@ -165,13 +174,18 @@ class DefaultYieldSupplyTransactionRepositoryTest {
|
|||
fun `createEnterTransactions returns reactivate-approve-enter transactions`() = runTest {
|
||||
coEvery { walletManager.getYieldContract() } returns yieldContractAddress
|
||||
coEvery { walletManager.calculateYieldContract() } returns yieldContractAddress
|
||||
coEvery { walletManager.isAllowedToSpend(any()) } returns false
|
||||
coEvery { walletManager.getYieldSupplyStatus(any()) } returns SDKYieldSupplyStatus(
|
||||
isActive = false,
|
||||
isInitialized = true,
|
||||
maxNetworkFee = BigDecimal.TEN,
|
||||
)
|
||||
|
||||
val result = repository.createEnterTransactions(userWalletId, cryptoCurrencyStatus)
|
||||
val result = repository.createEnterTransactions(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
maxNetworkFee = BigDecimal.TEN,
|
||||
)
|
||||
|
||||
// Assert that 3 transactions are returned: reactivate token, approve, enter
|
||||
Truth.assertThat(result).isNotNull()
|
||||
|
|
@ -220,7 +234,11 @@ class DefaultYieldSupplyTransactionRepositoryTest {
|
|||
)
|
||||
coEvery { walletManager.isAllowedToSpend(any()) } returns true
|
||||
|
||||
val result = repository.createEnterTransactions(userWalletId, cryptoCurrencyStatus)
|
||||
val result = repository.createEnterTransactions(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
maxNetworkFee = BigDecimal.TEN,
|
||||
)
|
||||
|
||||
// Assert that 2 transactions are returned: approve, enter
|
||||
Truth.assertThat(result).isNotNull()
|
||||
|
|
@ -257,7 +275,11 @@ class DefaultYieldSupplyTransactionRepositoryTest {
|
|||
)
|
||||
coEvery { walletManager.isAllowedToSpend(any()) } returns true
|
||||
|
||||
val result = repository.createEnterTransactions(userWalletId, cryptoCurrencyStatus)
|
||||
val result = repository.createEnterTransactions(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
maxNetworkFee = BigDecimal.TEN,
|
||||
)
|
||||
|
||||
// Assert that transaction is returned: enter
|
||||
Truth.assertThat(result).isNotNull()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue