Updated on 2026-08-14

This commit is contained in:
Tangem 2026-01-15 20:15:37 +03:00
parent 22a32ec8f1
commit 99cdc003c8
16 changed files with 156 additions and 121 deletions

@ -1 +1 @@
Subproject commit 5ba0959d72f41e49a22f792e9a3d53e5e24e7713
Subproject commit 098662beb5b0123b11f5ee4873d4bd667ac93c73

View file

@ -116,9 +116,6 @@ class DefaultGaslessTransactionRepository(
}
private companion object {
const val TOKEN_RECEIVER_ADDRESS = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
val BASE_GAS_FOR_TRANSACTION: BigInteger = BigInteger("100000")
}
}

View file

@ -1,6 +1,7 @@
package com.tangem.domain.tokens
import arrow.core.Either
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.tokens.model.FeePaidCurrency
@ -16,9 +17,15 @@ class IsAmountSubtractAvailableUseCase(
suspend operator fun invoke(
userWalletId: UserWalletId,
currency: CryptoCurrency,
isGaslessEthTx: Boolean = false,
maybeGaslessFee: Pair<CryptoCurrency.ID, Fee>? = null,
): Either<Throwable, Boolean> = Either.catch {
if (isGaslessEthTx) return@catch true
val maybeTokenCurrency = currency as? CryptoCurrency.Token
if (maybeGaslessFee != null &&
maybeGaslessFee.second is Fee.Ethereum.TokenCurrency &&
maybeGaslessFee.first.contractAddress.equals(maybeTokenCurrency?.contractAddress, true)
) {
return@catch true
}
when (val feeCurrency = currenciesRepository.getFeePaidCurrency(userWalletId, currency.network)) {
is FeePaidCurrency.Coin -> currency is CryptoCurrency.Coin
is FeePaidCurrency.SameCurrency -> true

View file

@ -14,5 +14,6 @@ sealed class GetFeeError {
data object NetworkIsNotSupported : GaslessError()
data object NoSupportedTokensFound : GaslessError()
data object NotEnoughFunds : GaslessError()
data class DataError(val cause: Throwable?) : GaslessError()
}
}

View file

@ -89,7 +89,7 @@ class EstimateFeeForGaslessTxUseCase(
)
},
catch = {
raise(GetFeeError.DataError(it))
raise(GaslessError.DataError(it))
},
)
}

View file

@ -2,6 +2,7 @@ package com.tangem.domain.transaction.usecase.gasless
import arrow.core.Either
import arrow.core.raise.Raise
import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.common.transaction.Fee
@ -17,6 +18,7 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.error.GetFeeError.GaslessError
import com.tangem.domain.transaction.error.mapToFeeError
import com.tangem.domain.transaction.models.TransactionFeeExtended
import com.tangem.domain.transaction.raiseIllegalStateError
@ -45,6 +47,8 @@ class EstimateFeeForTokenUseCase(
amount: BigDecimal,
): Either<GetFeeError, TransactionFeeExtended> {
return either {
catch(
block = {
val token = tokenCurrencyStatus.currency
if (!currencyChecksRepository.isNetworkSupportedForGaslessTx(token.network)) {
raise(GetFeeError.GaslessError.NetworkIsNotSupported)
@ -101,6 +105,11 @@ class EstimateFeeForTokenUseCase(
nativeCurrencyStatus = nativeCurrencyStatus,
initialFee = initialFeeEth,
).bind()
},
catch = {
raise(GaslessError.DataError(it))
},
)
}
}

View file

@ -53,7 +53,7 @@ class GetAvailableFeeTokensUseCase(
}
},
catch = {
raise(GetFeeError.DataError(it))
raise(GetFeeError.GaslessError.DataError(it))
},
)
}

View file

@ -86,7 +86,7 @@ class GetFeeForGaslessUseCase(
)
},
catch = {
raise(GetFeeError.DataError(it))
raise(GaslessError.DataError(it))
},
)
}

View file

@ -2,6 +2,7 @@ package com.tangem.domain.transaction.usecase.gasless
import arrow.core.Either
import arrow.core.raise.Raise
import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.common.TransactionData
@ -15,6 +16,7 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.CurrencyChecksRepository
import com.tangem.domain.transaction.GaslessTransactionRepository
import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.error.GetFeeError.GaslessError
import com.tangem.domain.transaction.models.TransactionFeeExtended
import com.tangem.domain.transaction.raiseIllegalStateError
import com.tangem.domain.walletmanager.WalletManagersFacade
@ -40,8 +42,10 @@ class GetFeeForTokenUseCase(
transactionData: TransactionData,
): Either<GetFeeError, TransactionFeeExtended> {
return either {
catch(
block = {
if (!currencyChecksRepository.isNetworkSupportedForGaslessTx(token.network)) {
raise(GetFeeError.GaslessError.NetworkIsNotSupported)
raise(GaslessError.NetworkIsNotSupported)
}
val walletManager = prepareWalletManager(userWallet, token.network)
@ -84,6 +88,11 @@ class GetFeeForTokenUseCase(
nativeCurrencyStatus = nativeCurrencyStatus,
initialFee = initialFeeEth,
).bind()
},
catch = {
raise(GaslessError.DataError(it))
},
)
}
}

View file

@ -26,6 +26,7 @@ import com.tangem.domain.transaction.raiseIllegalStateError
import com.tangem.domain.utils.convertToSdkAmount
import com.tangem.domain.walletmanager.WalletManagersFacade
import java.math.BigDecimal
import java.math.BigInteger
import java.math.RoundingMode
internal class TokenFeeCalculator(
@ -51,7 +52,7 @@ internal class TokenFeeCalculator(
val maybeFee = when (val result = transactionSender.getFee(transactionData = transactionData)) {
is Result.Success -> result.data
is Result.Failure -> raise(result.mapToFeeError())
is Result.Failure -> raise(GaslessError.DataError(result.error))
}
maybeFee
}
@ -115,7 +116,7 @@ internal class TokenFeeCalculator(
val feeTransferGasLimit = when (feeTransferGasLimitResult) {
is Result.Failure -> raise(GetFeeError.DataError(feeTransferGasLimitResult.error))
is Result.Success -> feeTransferGasLimitResult.data
}
}.increaseByPercent(PERCENT_TO_INCREASE_TRANSFER_GASLIMIT)
val baseGas = gaslessTransactionRepository.getBaseGasForTransaction()
@ -197,6 +198,7 @@ internal class TokenFeeCalculator(
/** Gas price safety multiplier for fee calculation */
const val GAS_PRICE_MULTIPLIER = 2
const val PERCENT_TO_INCREASE_TOKEN_PRICE = 1
const val PERCENT_TO_INCREASE_TRANSFER_GASLIMIT = 10
/**
* Increases BigDecimal value by specified percentage.
@ -216,5 +218,11 @@ internal class TokenFeeCalculator(
val multiplier = BigDecimal.ONE.add(BigDecimal(percent).divide(BigDecimal("100")))
return this.multiply(multiplier)
}
private fun BigInteger.increaseByPercent(percent: Int): BigInteger {
require(percent >= 0) { "Percent must be non-negative" }
val multiplier = BigDecimal.ONE.add(BigDecimal(percent).divide(BigDecimal("100")))
return BigDecimal(this).multiply(multiplier).toBigInteger()
}
}
}

View file

@ -110,7 +110,7 @@ class TokenFeeCalculatorTest {
// Then
assertTrue(result.isLeft())
result.onLeft { error ->
assertTrue(error is GetFeeError.DataError)
assertTrue(error is GetFeeError.GaslessError)
}
}
@ -363,7 +363,7 @@ class TokenFeeCalculatorTest {
// Expected
val expectedAmount = Amount(
value = BigDecimal("36.200000000000000000000000000000000000"),
value = BigDecimal("37.400000000000000000000000000000000000"),
token = Token(
name = "USDC",
symbol = "USDC",
@ -371,9 +371,9 @@ class TokenFeeCalculatorTest {
decimals = 6,
)
)
val expectedGasLimit = "181000".toBigInteger()
val expectedGasLimit = "187000".toBigInteger()
val expectedCoinPriceInToken = BigInteger("2020000000") // 2000 * 1.01 * 10^6
val expectedFeeTransferLimit = "60000".toBigInteger()
val expectedFeeTransferLimit = "66000".toBigInteger()
val expectedBaseGas = "21000".toBigInteger()
// Given

View file

@ -628,13 +628,13 @@ internal class SendConfirmModel @Inject constructor(
private fun updateAmountSubtractAvailability() {
modelScope.launch {
val isGaslessEthTx =
feeUMV2?.feeExtraInfo?.transactionFeeExtended?.transactionFee?.normal is Fee.Ethereum.TokenCurrency
isAmountSubtractAvailable =
isAmountSubtractAvailableUseCase(
val fee = feeUMV2?.feeExtraInfo?.transactionFeeExtended?.transactionFee?.normal
// we assume if feeExtraInfo is empty then pay fee in the main currency
val feeTokenId = feeUMV2?.feeExtraInfo?.transactionFeeExtended?.feeTokenId ?: cryptoCurrency.id
isAmountSubtractAvailable = isAmountSubtractAvailableUseCase(
userWalletId = userWallet.walletId,
currency = cryptoCurrency,
isGaslessEthTx = isGaslessEthTx,
maybeGaslessFee = fee?.let { feeTokenId to fee },
).getOrElse { false }
}
}

View file

@ -106,10 +106,12 @@ internal class NotificationsModel @Inject constructor(
}
private suspend fun checkIfSubtractAvailable() {
val feeCurrencyId = notificationData.feeCryptoCurrencyStatus.currency.id
val fee = notificationData.fee
isAmountSubtractAvailable = isAmountSubtractAvailableUseCase(
userWalletId = userWalletId,
currency = currency,
isGaslessEthTx = notificationData.fee is Fee.Ethereum.TokenCurrency,
maybeGaslessFee = fee?.let { feeCurrencyId to fee },
).getOrElse { false }
}

View file

@ -1439,8 +1439,10 @@ internal class StakingModel @Inject constructor(
}
private suspend fun checkIfSubtractAvailable() {
isAmountSubtractAvailable = isAmountSubtractAvailableUseCase(userWalletId, cryptoCurrencyStatus.currency)
.getOrElse { false }
isAmountSubtractAvailable = isAmountSubtractAvailableUseCase(
userWalletId = userWalletId,
currency = cryptoCurrencyStatus.currency,
).getOrElse { false }
}
private fun isTopHeatupCase(): Boolean {

View file

@ -3,7 +3,6 @@ package com.tangem.features.swap.v2.impl.sendviaswap.confirm.model
import arrow.core.Either
import arrow.core.getOrElse
import arrow.core.left
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.common.routing.AppRouter
import com.tangem.common.ui.amountScreen.converters.AmountReduceByTransformer
@ -349,13 +348,14 @@ internal class SendWithSwapConfirmModel @Inject constructor(
private fun updateAmountSubtractAvailability() {
modelScope.launch {
val isGaslessEthTx =
feeUMV2?.feeExtraInfo?.transactionFeeExtended?.transactionFee?.normal is Fee.Ethereum.TokenCurrency
val fee = feeUMV2?.feeExtraInfo?.transactionFeeExtended?.transactionFee?.normal
val feeTokenId =
feeUMV2?.feeExtraInfo?.transactionFeeExtended?.feeTokenId ?: primaryCurrencyStatus.currency.id
isAmountSubtractAvailable =
isAmountSubtractAvailableUseCase(
userWalletId = params.userWallet.walletId,
currency = primaryCurrencyStatus.currency,
isGaslessEthTx = isGaslessEthTx,
maybeGaslessFee = fee?.let { feeTokenId to fee },
).getOrElse { false }
}
}

View file

@ -5,7 +5,7 @@
# https://github.com/tangem/tangem-sdk-android/
# https://github.com/tangem/vico
tangemBlockchainSdk = "develop-1364"
tangemBlockchainSdk = "develop-1365"
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
tangemCardSdk = "develop-573"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^