-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update inflation calculation for Polkadot
- Loading branch information
Showing
13 changed files
with
162 additions
and
29 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
46 changes: 46 additions & 0 deletions
46
...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,46 @@ | ||
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.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 | ||
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
11 changes: 0 additions & 11 deletions
11
runtime/src/main/java/io/novafoundation/nova/runtime/network/rpc/StateCallRequest.kt
This file was deleted.
Oops, something went wrong.