Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-26 17:56:10 +05:00
parent 132924c8c7
commit c3740a70c0
3 changed files with 269 additions and 5 deletions

View file

@ -39,6 +39,22 @@ object BlockchainFeeUtils {
}
}
fun TransactionFee.patchIntegratedApprovalPriorityFee(increaseBy: Int): TransactionFee {
val patchedFee = when (this) {
is TransactionFee.Choosable -> {
copy(
normal = normal.increaseGasPrice(increaseBy),
minimum = minimum.increaseGasPrice(increaseBy),
priority = priority.increaseGasPrice(increaseBy),
)
}
is TransactionFee.Single -> copy(
normal = normal.increaseGasPrice(increaseBy),
)
}
return patchedFee
}
private fun Fee.increaseEthGasLimitInNeeded(increaseBy: Int): Fee {
return when (this) {
is Fee.Ethereum.TokenCurrency -> error("handle in [REDACTED_TASK_KEY]")
@ -81,4 +97,40 @@ object BlockchainFeeUtils {
is Fee.Ethereum.TokenCurrency -> error("handle in [REDACTED_TASK_KEY]")
}
}
/**
* Increase gasPrice/maxFeePerGas for Fee.Ethereum
*/
private fun Fee.increaseGasPrice(percent: Int): Fee {
if (this !is Fee.Ethereum) return this
return when (this) {
is Fee.Ethereum.EIP1559 -> {
val increasedGasPrice = maxFeePerGas.multiply(percent.toBigInteger()).divide(HUNDRED_PERCENT)
val increasedAmount = amount.copy(
value = gasLimit.toBigDecimal()
.multiply(increasedGasPrice.toBigDecimal())
.movePointLeft(amount.decimals),
)
copy(
amount = increasedAmount,
maxFeePerGas = increasedGasPrice,
priorityFee = priorityFee.multiply(percent.toBigInteger()).divide(HUNDRED_PERCENT),
)
}
is Fee.Ethereum.Legacy -> {
val increasedGasPrice = gasPrice.multiply(percent.toBigInteger()).divide(HUNDRED_PERCENT)
val increasedAmount = amount.copy(
value = gasLimit.toBigDecimal()
.multiply(increasedGasPrice.toBigDecimal())
.movePointLeft(amount.decimals),
)
copy(
amount = increasedAmount,
gasPrice = increasedGasPrice,
)
}
is Fee.Ethereum.TokenCurrency -> error("handle in [REDACTED_TASK_KEY]")
}
}
}