From ad6e2c1f683493d26f41700fb5e525f12a6ae75a Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 4 Nov 2025 17:25:11 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../domain/yield/supply/FeeExtensions.kt | 24 +++++++++++++++++++ .../YieldSupplyEstimateEnterFeeUseCase.kt | 9 +++++-- .../YieldSupplyEstimateEnterFeeUseCaseTest.kt | 12 +++++----- .../model/YieldSupplyStopEarningModel.kt | 4 +++- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt index 4032d39149..799506d8f2 100644 --- a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt +++ b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt @@ -3,6 +3,10 @@ package com.tangem.domain.yield.supply import com.tangem.blockchain.common.transaction.Fee import com.tangem.domain.models.currency.CryptoCurrency import java.math.BigInteger +import java.math.RoundingMode + +private val HUNDRED_PERCENT = 100.toBigInteger() // base 100% +val INCREASE_GAS_LIMIT_FOR_SUPPLY = 112.toBigInteger() // 12% increase fun Fee.fixFee(cryptoCurrency: CryptoCurrency, gasLimit: BigInteger): Fee = when (this) { is Fee.Ethereum.Legacy -> copy( @@ -20,4 +24,24 @@ fun Fee.fixFee(cryptoCurrency: CryptoCurrency, gasLimit: BigInteger): Fee = when ), ) else -> this +} + +/** + * Increase gasLimit for Fee.Ethereum + */ +fun Fee.increaseGasLimitBy(percent: BigInteger): 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(percent) + .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) + } } \ No newline at end of file diff --git a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyEstimateEnterFeeUseCase.kt b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyEstimateEnterFeeUseCase.kt index 58f1a8476f..e3b24f7f96 100644 --- a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyEstimateEnterFeeUseCase.kt +++ b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/usecase/YieldSupplyEstimateEnterFeeUseCase.kt @@ -6,11 +6,13 @@ import com.tangem.blockchain.common.TransactionData import com.tangem.blockchain.yieldsupply.providers.ethereum.yield.EthereumYieldSupplyEnterCallData import com.tangem.domain.blockaid.BlockAidGasEstimate import com.tangem.domain.models.currency.CryptoCurrency -import com.tangem.domain.yield.supply.fixFee import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.transaction.FeeRepository import com.tangem.domain.transaction.error.FeeErrorResolver import com.tangem.domain.transaction.error.GetFeeError +import com.tangem.domain.yield.supply.INCREASE_GAS_LIMIT_FOR_SUPPLY +import com.tangem.domain.yield.supply.fixFee +import com.tangem.domain.yield.supply.increaseGasLimitBy import com.tangem.utils.extensions.isSingleItem import timber.log.Timber @@ -73,7 +75,10 @@ class YieldSupplyEstimateEnterFeeUseCase( ) return transactionDataList.zip(estimatedFees.estimatedGasList) { transaction, estimatedGas -> - transaction.copy(fee = fee.fixFee(cryptoCurrency, estimatedGas)) + transaction.copy( + fee = fee.fixFee(cryptoCurrency, estimatedGas) + .increaseGasLimitBy(INCREASE_GAS_LIMIT_FOR_SUPPLY), + ) } } diff --git a/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt b/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt index 8a2cc75aae..20c7619b9e 100644 --- a/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt +++ b/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt @@ -314,9 +314,9 @@ class YieldSupplyEstimateEnterFeeUseCaseTest { val deployFee = txs.first().fee as Fee.Ethereum.EIP1559 val approveFee = txs[1].fee as Fee.Ethereum.EIP1559 val enterFee = txs.last().fee as Fee.Ethereum.EIP1559 - Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_000)) - Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_000)) - Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_000)) + Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_120)) + Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_240)) + Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_360)) } @Test @@ -353,9 +353,9 @@ class YieldSupplyEstimateEnterFeeUseCaseTest { val deployFee = txs.first().fee as Fee.Ethereum.Legacy val approveFee = txs[1].fee as Fee.Ethereum.Legacy val enterFee = txs.last().fee as Fee.Ethereum.Legacy - Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_000)) - Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_000)) - Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_000)) + Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_120)) + Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_240)) + Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_360)) } private fun getDeployTx() = uncompiled( diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt index 73cfd703d0..5173d8c6cf 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt @@ -16,7 +16,9 @@ import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.tokens.GetFeePaidCryptoCurrencyStatusSyncUseCase import com.tangem.domain.transaction.usecase.GetFeeUseCase import com.tangem.domain.transaction.usecase.SendTransactionUseCase +import com.tangem.domain.yield.supply.INCREASE_GAS_LIMIT_FOR_SUPPLY import com.tangem.domain.yield.supply.YieldSupplyRepository +import com.tangem.domain.yield.supply.increaseGasLimitBy import com.tangem.domain.yield.supply.models.YieldSupplyEnterStatus import com.tangem.domain.yield.supply.usecase.YieldSupplyDeactivateUseCase import com.tangem.domain.yield.supply.usecase.YieldSupplyStopEarningUseCase @@ -223,7 +225,7 @@ internal class YieldSupplyStopEarningModel @Inject constructor( } }, ifRight = { fee -> - val fee = fee.normal + val fee = fee.normal.increaseGasLimitBy(INCREASE_GAS_LIMIT_FOR_SUPPLY) val feeCryptoValue = fee.amount.value.orZero() uiState.update(