-
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 #1710 from novasamatech/hotfix/moonriver_staking
Hotfix/moonriver staking
- Loading branch information
Showing
8 changed files
with
76 additions
and
47 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
45 changes: 45 additions & 0 deletions
45
...ature_staking_impl/data/parachainStaking/network/bindings/InflationDistributionAccount.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,45 @@ | ||
package io.novafoundation.nova.feature_staking_impl.data.parachainStaking.network.bindings | ||
|
||
import io.novafoundation.nova.common.data.network.runtime.binding.bindAccountId | ||
import io.novafoundation.nova.common.data.network.runtime.binding.bindList | ||
import io.novafoundation.nova.common.data.network.runtime.binding.cast | ||
import io.novafoundation.nova.common.data.network.runtime.binding.castToStruct | ||
import io.novafoundation.nova.common.utils.percentageToFraction | ||
import io.novasama.substrate_sdk_android.runtime.AccountId | ||
import java.math.BigInteger | ||
|
||
typealias Percent = BigInteger | ||
|
||
@JvmInline | ||
value class InflationDistributionConfig(val accounts: List<InflationDistributionAccount>) | ||
|
||
class InflationDistributionAccount( | ||
// Account which receives funds intended for parachain bond | ||
val account: AccountId, | ||
|
||
// Percent of inflation set aside for parachain bond account | ||
// Will be integer number (30%) | ||
val percent: Percent | ||
) | ||
|
||
fun InflationDistributionConfig.totalPercentAsFraction(): Double { | ||
return accounts.sumOf { it.percent }.toDouble().percentageToFraction() | ||
} | ||
|
||
fun bindParachainBondConfig(decoded: Any?): InflationDistributionConfig { | ||
val distributionAccount = bindInflationDistributionAccount(decoded) | ||
return InflationDistributionConfig(listOf(distributionAccount)) | ||
} | ||
|
||
fun bindInflationDistributionConfig(decoded: Any?): InflationDistributionConfig { | ||
return InflationDistributionConfig(bindList(decoded, ::bindInflationDistributionAccount)) | ||
} | ||
|
||
private fun bindInflationDistributionAccount(decoded: Any?): InflationDistributionAccount = decoded.castToStruct().let { | ||
InflationDistributionAccount( | ||
account = bindAccountId(it["account"]), | ||
percent = bindPercent(it["percent"]) | ||
) | ||
} | ||
|
||
private fun bindPercent(dynamicInstance: Any?): Percent = dynamicInstance.cast() |
27 changes: 0 additions & 27 deletions
27
...n/nova/feature_staking_impl/data/parachainStaking/network/bindings/ParachainBondConfig.kt
This file was deleted.
Oops, something went wrong.
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