Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-28 18:20:17 +03:00
parent f1c53a4016
commit 345b96066d
2 changed files with 21 additions and 9 deletions

View file

@ -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,

View file

@ -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,