diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt index 3914707cc3..18ce548096 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt @@ -72,7 +72,7 @@ class WalletConnectSdkHelper { } // TODO move fee calculation to SDK getFee() [REDACTED_JIRA] - val gasLimit = getGasLimitFromTx(value, walletManager, transaction) + val gasLimit = getGasLimitFromTx(value, walletManager, transaction, blockchain) val gasPrice = getGasPrice(walletManager, transaction) val feeDecimal = (gasLimit * gasPrice).movePointLeft(decimals) @@ -170,6 +170,7 @@ class WalletConnectSdkHelper { value: BigDecimal, walletManager: WalletManager, transaction: WcEthereumTransaction, + blockchain: Blockchain, ): BigDecimal { return transaction.gas?.hexToBigDecimal() ?: transaction.gasLimit?.hexToBigDecimal() @@ -177,7 +178,7 @@ class WalletConnectSdkHelper { value = value, walletManager = walletManager, transaction = transaction, - ) + ).increaseForMantleIfNeeded(blockchain) } private suspend fun getGasLimitFromBlockchain( @@ -200,6 +201,15 @@ class WalletConnectSdkHelper { } } + // TODO Workaround for Mantle. Remove after [REDACTED_JIRA] + private fun BigDecimal.increaseForMantleIfNeeded(blockchain: Blockchain): BigDecimal { + return if (blockchain == Blockchain.Mantle) { + this.multiply(MANTLE_FEE_ESTIMATE_MULTIPLIER) + } else { + this + } + } + private suspend fun sendTransaction(data: WcTransactionData, cardId: String?): String? { val result = (data.walletManager as TransactionSender).send( transactionData = data.transaction, diff --git a/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt b/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt index 4e8c1bbf82..f42a80725e 100644 --- a/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt +++ b/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt @@ -272,22 +272,24 @@ class TransactionManagerImpl( * @param blockchain */ private fun createMultipleProxyFees(gasPrice: BigInteger, gasLimit: BigInteger, blockchain: Blockchain): ProxyFees { - val gasPriceNormal = gasPrice.increaseBigIntegerByPercents(MULTIPLIER_GAS_PRICE_FOR_NORMAL_FEE) + val patchedGasLimit = gasLimit.toBigDecimal().increaseForMantleIfNeeded(blockchain).toBigInteger() + val gasPriceNormal = gasPrice + .increaseBigIntegerByPercents(MULTIPLIER_GAS_PRICE_FOR_NORMAL_FEE) val gasPricePriority = gasPrice.increaseBigIntegerByPercents(MULTIPLIER_GAS_PRICE_FOR_PRIORITY_FEE) - val feeMin = gasLimit.multiply(gasPrice).toBigDecimal( + val feeMin = patchedGasLimit.multiply(gasPrice).toBigDecimal( scale = blockchain.decimals(), mathContext = MathContext(blockchain.decimals(), RoundingMode.HALF_EVEN), ).increaseForMantleIfNeeded(blockchain) - val feeNormal = gasLimit.multiply(gasPriceNormal).toBigDecimal( + val feeNormal = patchedGasLimit.multiply(gasPriceNormal).toBigDecimal( scale = blockchain.decimals(), mathContext = MathContext(blockchain.decimals(), RoundingMode.HALF_EVEN), ).increaseForMantleIfNeeded(blockchain) - val feePriority = gasLimit.multiply(gasPricePriority).toBigDecimal( + val feePriority = patchedGasLimit.multiply(gasPricePriority).toBigDecimal( scale = blockchain.decimals(), mathContext = MathContext(blockchain.decimals(), RoundingMode.HALF_EVEN), ).increaseForMantleIfNeeded(blockchain) val minFee = ProxyFee.Common( - gasLimit = gasLimit, + gasLimit = patchedGasLimit, fee = ProxyAmount( currencySymbol = blockchain.currency, value = feeMin, @@ -295,7 +297,7 @@ class TransactionManagerImpl( ), ) val normalFee = ProxyFee.Common( - gasLimit = gasLimit, + gasLimit = patchedGasLimit, fee = ProxyAmount( currencySymbol = blockchain.currency, value = feeNormal, @@ -303,7 +305,7 @@ class TransactionManagerImpl( ), ) val priorityFee = ProxyFee.Common( - gasLimit = gasLimit, + gasLimit = patchedGasLimit, fee = ProxyAmount( currencySymbol = blockchain.currency, value = feePriority,