diff --git a/build.gradle b/build.gradle index 73b09e8b85..4b7b97de2e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,8 @@ apply plugin: "org.sonarqube" buildscript { ext { // App version - versionName = '3.1.1' - versionCode = 136 + versionName = '3.1.2' + versionCode = 137 // SDK and tools compileSdkVersion = 34 @@ -84,7 +84,7 @@ buildscript { minifyRelease = true beaconVersion = "3.2.4" - sharedFeaturesVersion = "1.1.1.16-FLW" + sharedFeaturesVersion = "1.1.1.17-FLW" coilDep = "io.coil-kt:coil:$coilVersion" coilSvg = "io.coil-kt:coil-svg:$coilVersion" diff --git a/feature-staking-impl/src/main/java/jp/co/soramitsu/staking/impl/domain/rewards/ManualRewardCalculator.kt b/feature-staking-impl/src/main/java/jp/co/soramitsu/staking/impl/domain/rewards/ManualRewardCalculator.kt index 496368cb9e..3367496128 100644 --- a/feature-staking-impl/src/main/java/jp/co/soramitsu/staking/impl/domain/rewards/ManualRewardCalculator.kt +++ b/feature-staking-impl/src/main/java/jp/co/soramitsu/staking/impl/domain/rewards/ManualRewardCalculator.kt @@ -4,6 +4,7 @@ import java.math.BigDecimal import java.math.BigInteger import jp.co.soramitsu.common.utils.fractionToPercentage import jp.co.soramitsu.common.utils.median +import jp.co.soramitsu.common.utils.orZero import jp.co.soramitsu.common.utils.sumByBigInteger import jp.co.soramitsu.runtime.multiNetwork.chain.model.ChainId import jp.co.soramitsu.shared_utils.extensions.toHexString @@ -29,7 +30,8 @@ open class ManualRewardCalculator( val totalIssuance: BigInteger ) : RewardCalculator { - private val totalStaked = validators.sumByBigInteger(RewardCalculationTarget::totalStake).toDouble() + private val totalStaked = + validators.sumByBigInteger(RewardCalculationTarget::totalStake).toDouble() private val stakedPortion = totalStaked / totalIssuance.toDouble() @@ -58,7 +60,8 @@ open class ManualRewardCalculator( } private fun calculateValidatorAPY(validator: RewardCalculationTarget): Double { - val yearlyRewardPercentage = averageValidatorRewardPercentage * averageValidatorStake / validator.totalStake.toDouble() + val yearlyRewardPercentage = + averageValidatorRewardPercentage * averageValidatorStake / validator.totalStake.toDouble() return yearlyRewardPercentage * (1 - validator.commission.toDouble()) } @@ -80,7 +83,10 @@ open class ManualRewardCalculator( chainId = chainId ).gainPercentage - override suspend fun calculateAvgAPY() = expectedAPY.toBigDecimal().fractionToPercentage() + override suspend fun calculateAvgAPY(): BigDecimal { + return runCatching { expectedAPY.toBigDecimal().fractionToPercentage() }.getOrNull() + .orZero() + } override suspend fun getApyFor(targetId: ByteArray): BigDecimal { val apy = apyByValidator[targetId.toHexString()] ?: expectedAPY @@ -136,11 +142,20 @@ open class ManualRewardCalculator( ) } - private fun calculateSimpleReward(amount: Double, days: Int, dailyPercentage: Double): BigDecimal { + private fun calculateSimpleReward( + amount: Double, + days: Int, + dailyPercentage: Double + ): BigDecimal { return amount.toBigDecimal() * dailyPercentage.toBigDecimal() * days.toBigDecimal() } - private fun calculateCompoundReward(amount: Double, days: Int, dailyPercentage: Double): BigDecimal { - return amount.toBigDecimal() * ((1 + dailyPercentage).toBigDecimal().pow(days)) - amount.toBigDecimal() + private fun calculateCompoundReward( + amount: Double, + days: Int, + dailyPercentage: Double + ): BigDecimal { + return amount.toBigDecimal() * ((1 + dailyPercentage).toBigDecimal() + .pow(days)) - amount.toBigDecimal() } } diff --git a/feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/XcmInteractor.kt b/feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/XcmInteractor.kt index 0b405f45fd..954bdbccb1 100644 --- a/feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/XcmInteractor.kt +++ b/feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/XcmInteractor.kt @@ -25,6 +25,9 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import java.math.BigDecimal import java.math.BigInteger +import java.math.MathContext +import java.math.RoundingMode +import jp.co.soramitsu.runtime.multiNetwork.chain.model.soraMainChainId import jp.co.soramitsu.core.models.Asset as CoreAsset class XcmInteractor( @@ -96,13 +99,24 @@ class XcmInteractor( val originChain = chainRegistry.getChain(transfer.originChainId) val destinationChain = chainRegistry.getChain(transfer.destinationChainId) val selfAddress = currentAccountAddress(originChain.id) ?: throw IllegalStateException("No self address") + + val ksmInSoraMainnetCurrencyId = "0x00117b0fa73c4672e03a7d9d774e3b3f91beb893e93d9a8d0430295f44225db8" + // todo remove this sora ksm check when https://github.com/sora-xor/sora2-network/issues/845 will be fixed + // if we transfer ksm asset from sora network - we have to convert precision 18 to 12 + val roundedAmountInPlanks = if(transfer.originChainId == soraMainChainId && transfer.chainAsset.currencyId == ksmInSoraMainnetCurrencyId) { + val roundedAmount = transfer.amount.round(MathContext(12, RoundingMode.HALF_EVEN)) + transfer.chainAsset.planksFromAmount(roundedAmount) + } else { + transfer.fullAmountInPlanks + } + xcmService.transfer( originChain = originChain, destinationChain = destinationChain, asset = transfer.chainAsset, senderAccountId = originChain.accountIdOf(selfAddress), address = transfer.recipient, - amount = transfer.fullAmountInPlanks + amount = roundedAmountInPlanks ) } }