Updated on 2026-08-14

This commit is contained in:
Tangem 2025-03-28 14:22:23 +05:00
parent 8adc79a8c3
commit f4bb2bbc2d
21 changed files with 327 additions and 236 deletions

View file

@ -30,6 +30,15 @@ internal object TransactionDomainModule {
)
}
@Provides
@Singleton
fun provideTransferGetFeeUseCase(walletManagersFacade: WalletManagersFacade): GetTransferFeeUseCase {
return GetTransferFeeUseCase(
walletManagersFacade = walletManagersFacade,
demoConfig = DemoConfig(),
)
}
@Provides
@Singleton
fun provideSendTransactionUseCase(
@ -148,6 +157,14 @@ internal object TransactionDomainModule {
return GetAllowanceUseCase(transactionRepository)
}
@Provides
@Singleton
fun provideCreateTransferTransactionUseCase(
transactionRepository: TransactionRepository,
): CreateTransferTransactionUseCase {
return CreateTransferTransactionUseCase(transactionRepository)
}
@Provides
@Singleton
fun providePrepareForSendUseCase(

View file

@ -5,6 +5,7 @@ import com.tangem.blockchain.blockchains.ethereum.EthereumGasLoader
import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras
import com.tangem.blockchain.blockchains.ethereum.EthereumUtils
import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.smartcontract.CompiledSmartContractCallData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.extensions.*
import com.tangem.blockchainsdk.utils.fromNetworkId
@ -101,7 +102,7 @@ class WalletConnectSdkHelper {
sourceAddress = transaction.from,
destinationAddress = destinationAddress,
extras = EthereumTransactionExtras(
data = transaction.data.removePrefix(HEX_PREFIX).hexToBytes(),
callData = CompiledSmartContractCallData(transaction.data.removePrefix(HEX_PREFIX).hexToBytes()),
gasLimit = gasLimit.toBigInteger(),
nonce = transaction.nonce?.hexToBigDecimal()?.toBigInteger(),
),
@ -191,7 +192,7 @@ class WalletConnectSdkHelper {
val gasLimitResult = (walletManager as? EthereumGasLoader)?.getGasLimit(
amount = Amount(value, walletManager.wallet.blockchain),
destination = transaction.to ?: "",
data = transaction.data,
callData = CompiledSmartContractCallData(transaction.data.hexToBytes()),
)
return when (gasLimitResult) {
is Result.Success -> gasLimitResult.data.toBigDecimal().multiply(BigDecimal("1.2"))

View file

@ -3,6 +3,7 @@ package com.tangem.tap.proxy
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
import com.tangem.blockchain.blockchains.optimism.EthereumOptimisticRollupWalletManager
import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.smartcontract.SmartContractCallData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.blockchain.extensions.Result
@ -43,7 +44,7 @@ class TransactionManagerImpl(
currencyToSend: Currency,
destinationAddress: String,
increaseBy: Int?,
data: String?,
callData: SmartContractCallData?,
derivationPath: String?,
): ProxyFees {
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
@ -54,7 +55,7 @@ class TransactionManagerImpl(
walletManager = walletManager,
amount = amountToSend,
destinationAddress = destinationAddress,
data = data,
callData = callData,
)
}
return getFeeForEthereumBlockchain(
@ -62,7 +63,7 @@ class TransactionManagerImpl(
blockchain = blockchain,
amountToSend = amountToSend,
destinationAddress = destinationAddress,
data = data,
callData = callData,
increaseBy = increaseBy,
)
} else {
@ -160,14 +161,14 @@ class TransactionManagerImpl(
blockchain: Blockchain,
amountToSend: Amount,
destinationAddress: String,
data: String?,
callData: SmartContractCallData?,
increaseBy: Int?,
): ProxyFees {
val gasLimit = getGasLimit(
evmWalletManager = walletManager,
amount = amountToSend,
destinationAddress = destinationAddress,
data = data,
callData = callData,
).increaseBigIntegerByPercents(increaseBy)
return when (val gasPrice = walletManager.getGasPrice()) {
is Result.Success -> {
@ -183,16 +184,16 @@ class TransactionManagerImpl(
walletManager: EthereumOptimisticRollupWalletManager,
amount: Amount,
destinationAddress: String,
data: String?,
callData: SmartContractCallData?,
): ProxyFees {
val fee = if (data.isNullOrEmpty()) {
val fee = if (callData == null) {
walletManager.getFee(amount, destinationAddress)
} else {
walletManager.getFee(amount, destinationAddress, data)
walletManager.getFee(amount, destinationAddress, callData)
}
return when (fee) {
is Result.Success -> {
val choosableFee = fee.data
val choosableFee = fee.data as? TransactionFee.Choosable ?: error("Incorrect fee type")
val minProxyFee = ProxyFee.Common(
gasLimit = (choosableFee.minimum as Fee.Ethereum).gasLimit,
@ -223,9 +224,9 @@ class TransactionManagerImpl(
evmWalletManager: EthereumWalletManager,
amount: Amount,
destinationAddress: String,
data: String?,
callData: SmartContractCallData?,
): BigInteger {
val result = if (data.isNullOrEmpty()) {
val result = if (callData == null) {
evmWalletManager.getGasLimit(
amount = amount,
destination = destinationAddress,
@ -234,7 +235,7 @@ class TransactionManagerImpl(
evmWalletManager.getGasLimit(
amount = amount,
destination = destinationAddress,
data = data,
callData = callData,
)
}
when (result) {