-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1724 from novasamatech/hotfix/9.0.2
Hotfix/9.0.2
- Loading branch information
Showing
17 changed files
with
187 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...n/java/io/novafoundation/nova/feature_staking_api/domain/model/InflationPredictionInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.novafoundation.nova.feature_staking_api.domain.model | ||
|
||
import io.novafoundation.nova.common.data.network.runtime.binding.bindNumber | ||
import io.novafoundation.nova.common.data.network.runtime.binding.castToList | ||
import io.novafoundation.nova.common.data.network.runtime.binding.castToStruct | ||
import io.novafoundation.nova.common.utils.divideToDecimal | ||
import io.novafoundation.nova.feature_wallet_api.data.network.blockhain.types.Balance | ||
import kotlin.math.roundToInt | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.days | ||
|
||
class InflationPredictionInfo( | ||
val nextMint: NextMint | ||
) { | ||
|
||
class NextMint( | ||
val toStakers: Balance, | ||
val toTreasury: Balance | ||
) | ||
|
||
companion object { | ||
|
||
fun fromDecoded(decoded: Any?): InflationPredictionInfo { | ||
val asStruct = decoded.castToStruct() | ||
|
||
return InflationPredictionInfo( | ||
nextMint = bindNextMint(asStruct["nextMint"]) | ||
) | ||
} | ||
|
||
private fun bindNextMint(decoded: Any?): NextMint { | ||
val (toStakersRaw, toTreasuryRaw) = decoded.castToList() | ||
|
||
return NextMint( | ||
toStakers = bindNumber(toStakersRaw), | ||
toTreasury = bindNumber(toTreasuryRaw) | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun InflationPredictionInfo.calculateStakersInflation(totalIssuance: Balance, eraDuration: Duration): Double { | ||
val periodsInYear = (365.days / eraDuration).roundToInt() | ||
val inflationPerMint = nextMint.toStakers.divideToDecimal(totalIssuance) | ||
|
||
return inflationPerMint.toDouble() * periodsInYear | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...afoundation/nova/feature_staking_impl/domain/rewards/InflationPredictionInfoCalculator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.novafoundation.nova.feature_staking_impl.domain.rewards | ||
|
||
import io.novafoundation.nova.feature_staking_api.domain.model.InflationPredictionInfo | ||
import io.novafoundation.nova.feature_staking_api.domain.model.calculateStakersInflation | ||
import io.novafoundation.nova.feature_wallet_api.data.network.blockhain.types.Balance | ||
import kotlin.time.Duration | ||
|
||
class InflationPredictionInfoCalculator( | ||
private val inflationPredictionInfo: InflationPredictionInfo, | ||
private val eraDuration: Duration, | ||
private val totalIssuance: Balance, | ||
validators: List<RewardCalculationTarget> | ||
) : InflationBasedRewardCalculator(validators, totalIssuance) { | ||
|
||
override fun calculateYearlyInflation(stakedPortion: Double): Double { | ||
return inflationPredictionInfo.calculateStakersInflation(totalIssuance, eraDuration) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.