Skip to content

Commit

Permalink
Merge pull request #1058 from soramitsu/staging
Browse files Browse the repository at this point in the history
staging
  • Loading branch information
PankraSerg authored Dec 13, 2023
2 parents cffdbb4 + cb4c0c3 commit 9ec4002
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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())
}
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
}
}
Expand Down

0 comments on commit 9ec4002

Please sign in to comment.