Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-21 18:34:38 +03:00
commit 438126dc82
665 changed files with 16174 additions and 6245 deletions

View file

@ -0,0 +1,81 @@
package com.tangem.lib.crypto
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import java.math.BigInteger
import java.math.RoundingMode
/**
* !!!IMPORTANT!!!
* Methods for tuning transaction fee of different blockchains
*
* Temporary solution for domain specific logic for Blockchain.
* Instead of creating repositories and unnecessary and overkill use cases
*/
object BlockchainFeeUtils {
private val HUNDRED_PERCENT = BigInteger("100")
/**
* We need to increase gasLimit for Ethereum fees for 2 cases
*
* DEX: for dex calculated gasLimit for given data might be changed when transaction processing
* for that case dex providers recommend to increase gasLimit for few percents to ensure transaction completes
*
* CEX: for that case we calculate fee for random generated address and gasLimit might be different for it
* and result address to send. That's why we should increase gasLimit a little
*
*/
fun TransactionFee.patchTransactionFeeForSwap(increaseBy: Int): TransactionFee {
return when (this) {
is TransactionFee.Choosable -> {
this.copy(
minimum = this.minimum.increaseEthGasLimitInNeeded(increaseBy),
normal = this.normal.increaseEthGasLimitInNeeded(increaseBy),
priority = this.priority.increaseEthGasLimitInNeeded(increaseBy),
)
}
is TransactionFee.Single -> this.copy(normal = this.normal.increaseEthGasLimitInNeeded(increaseBy))
}
}
private fun Fee.increaseEthGasLimitInNeeded(increaseBy: Int): Fee {
return when (this) {
is Fee.Ethereum.EIP1559,
is Fee.Ethereum.Legacy,
-> this.increaseGasLimitBy(increaseBy)
is Fee.Alephium,
is Fee.Aptos,
is Fee.Bitcoin,
is Fee.CardanoToken,
is Fee.Common,
is Fee.Filecoin,
is Fee.Hedera,
is Fee.Kaspa,
is Fee.Sui,
is Fee.Tron,
is Fee.VeChain,
-> this
}
}
/**
* Increase gasLimit for Fee.Ethereum
*/
private fun Fee.increaseGasLimitBy(percentage: Int): Fee {
if (this !is Fee.Ethereum) return this
val gasLimit = this.gasLimit
val increasedGasPrice = this.amount.value?.movePointRight(this.amount.decimals)
?.divide(gasLimit.toBigDecimal(), RoundingMode.HALF_UP)
val increasedGasLimit = gasLimit
.multiply(percentage.toBigInteger())
.divide(HUNDRED_PERCENT)
val increasedAmount = this.amount.copy(
value = increasedGasLimit.toBigDecimal().multiply(increasedGasPrice).movePointLeft(this.amount.decimals),
)
return when (this) {
is Fee.Ethereum.EIP1559 -> copy(amount = increasedAmount, gasLimit = increasedGasLimit)
is Fee.Ethereum.Legacy -> copy(amount = increasedAmount, gasLimit = increasedGasLimit)
}
}
}

View file

@ -3,7 +3,6 @@ package com.tangem.sdk.api.di
import android.content.Context
import com.tangem.domain.card.repository.CardSdkConfigRepository
import com.tangem.operations.attestation.CardArtworksProvider
import com.tangem.operations.attestation.OnlineCardVerifier
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@ -16,10 +15,6 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
internal object CardSdkModule {
@Provides
@Singleton
fun provideOnlineCardVerifier(): OnlineCardVerifier = OnlineCardVerifier()
@Provides
@Singleton
fun provideCardArtworksProvider(
@ -27,7 +22,7 @@ internal object CardSdkModule {
@ApplicationContext context: Context,
): CardArtworksProvider {
return CardArtworksProvider(
isTangemAttestationProdEnv = sdkRepository.sdk.config.isTangemAttestationProdEnv,
tangemApiBaseUrlProvider = { sdkRepository.sdk.config.tangemApiBaseUrl },
artworksDirectory = File(
context.getExternalFilesDir(null) ?: context.filesDir,
"card_artworks",

View file

@ -5,9 +5,4 @@ package com.tangem.sdk.api.featuretoggles
*
[REDACTED_AUTHOR]
*/
interface CardSdkFeatureToggles {
val isNewAttestationEnabled: Boolean
val isNewArtworkLoadingEnabled: Boolean
}
interface CardSdkFeatureToggles

View file

@ -4,12 +4,5 @@ import com.tangem.core.configtoggle.feature.FeatureTogglesManager
import javax.inject.Inject
internal class DefaultCardSdkFeatureToggles @Inject constructor(
private val featureTogglesManager: FeatureTogglesManager,
) : CardSdkFeatureToggles {
override val isNewAttestationEnabled: Boolean
get() = featureTogglesManager.isFeatureEnabled(name = "NEW_ATTESTATION_ENABLED")
override val isNewArtworkLoadingEnabled: Boolean
get() = featureTogglesManager.isFeatureEnabled(name = "NEW_ARTWORK_LOADING")
}
@Suppress("UnusedPrivateMember") private val featureTogglesManager: FeatureTogglesManager,
) : CardSdkFeatureToggles