Updated on 2026-08-14
This commit is contained in:
parent
c976a39980
commit
ad6e2c1f68
4 changed files with 40 additions and 9 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue