Skip to content

Commit

Permalink
Merge pull request #1106 from novasamatech/nomination_pool_base
Browse files Browse the repository at this point in the history
Nomination pool base
  • Loading branch information
valentunn authored Sep 11, 2023
2 parents 6eb9cad + 0cbac41 commit 3c5abe1
Show file tree
Hide file tree
Showing 1,078 changed files with 23,452 additions and 4,694 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ android {

kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs = ["-Xcontext-receivers"]
}

applicationVariants.all { variant ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import io.novafoundation.nova.common.di.FeatureUtils
import io.novafoundation.nova.common.utils.withChildScope
import io.novafoundation.nova.runtime.di.RuntimeApi
import io.novafoundation.nova.runtime.di.RuntimeComponent
import io.novafoundation.nova.runtime.ext.Geneses
import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain
import io.novafoundation.nova.runtime.multiNetwork.connection.ChainConnection
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -36,4 +39,8 @@ open class BaseIntegrationTest {
}
}
}

protected suspend fun ChainRegistry.polkadot(): Chain {
return getChain(Chain.Geneses.POLKADOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.novafoundation.nova

import android.util.Log
import io.novafoundation.nova.common.di.FeatureUtils
import io.novafoundation.nova.common.utils.Perbill
import io.novafoundation.nova.feature_staking_api.di.StakingFeatureApi
import io.novafoundation.nova.feature_staking_api.domain.nominationPool.model.PoolId
import io.novafoundation.nova.feature_staking_impl.data.StakingOption
import io.novafoundation.nova.feature_staking_impl.data.StakingSharedState.OptionAdditionalData
import io.novafoundation.nova.feature_staking_impl.di.StakingFeatureComponent
import io.novafoundation.nova.feature_staking_impl.domain.nominationPools.common.rewards.NominationPoolRewardCalculator
import io.novafoundation.nova.runtime.ext.utilityAsset
import io.novafoundation.nova.runtime.multiNetwork.ChainWithAsset
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain.Asset.StakingType
import kotlinx.coroutines.flow.launchIn
import org.junit.Test

class NominationPoolsRewardCalculatorIntegrationTest : BaseIntegrationTest() {

private val stakingFeatureComponent = FeatureUtils.getFeature<StakingFeatureComponent>(context, StakingFeatureApi::class.java)

private val nominationPoolRewardCalculatorFactory = stakingFeatureComponent.nominationPoolRewardCalculatorFactory
private val stakingUpdateSystem = stakingFeatureComponent.stakingUpdateSystem
private val stakingSharedState = stakingFeatureComponent.stakingSharedState

@Test
fun testRewardCalculator() = runTest {
val polkadot = chainRegistry.polkadot()
val stakingOption = StakingOption(
assetWithChain = ChainWithAsset(polkadot, polkadot.utilityAsset),
additional = OptionAdditionalData(StakingType.NOMINATION_POOLS)
)

stakingSharedState.setSelectedOption(stakingOption)

stakingUpdateSystem.start()
.launchIn(this)

val rewardCalculator = nominationPoolRewardCalculatorFactory.create(stakingOption, sharedComputationScope = this)

Log.d("NominationPoolsRewardCalculatorIntegrationTest", "Max APY: ${rewardCalculator.maxAPY}")
Log.d("NominationPoolsRewardCalculatorIntegrationTest", "APY for Nova Pool: ${rewardCalculator.apyFor(54)}")
}

private fun NominationPoolRewardCalculator.apyFor(poolId: Int): Perbill? {
return apyFor(PoolId(poolId))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.novafoundation.nova.app.di.app.navigation.staking

import dagger.Module
import dagger.Provides
import io.novafoundation.nova.app.root.navigation.NavigationHolder
import io.novafoundation.nova.app.root.navigation.Navigator
import io.novafoundation.nova.app.root.navigation.staking.nominationPools.NominationPoolsStakingNavigator
import io.novafoundation.nova.common.di.scope.ApplicationScope
import io.novafoundation.nova.feature_staking_impl.presentation.NominationPoolsRouter

@Module
class NominationPoolsStakingNavigationModule {

@Provides
@ApplicationScope
fun provideRouter(navigationHolder: NavigationHolder, navigator: Navigator): NominationPoolsRouter {
return NominationPoolsStakingNavigator(navigationHolder, navigator)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ class RelayStakingNavigationModule {

@Provides
@ApplicationScope
fun provideRelayStakingNavigator(navigationHolder: NavigationHolder, navigator: Navigator): RelayStakingNavigator {
fun provideRelayStakingRouter(navigationHolder: NavigationHolder, navigator: Navigator): StakingRouter {
return RelayStakingNavigator(navigationHolder, navigator)
}

@Provides
@ApplicationScope
fun provideRelayStakingRouter(relayStakingNavigator: RelayStakingNavigator): StakingRouter = relayStakingNavigator
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
package io.novafoundation.nova.app.di.app.navigation.staking

import dagger.Module
import dagger.Provides
import io.novafoundation.nova.app.root.navigation.NavigationHolder
import io.novafoundation.nova.app.root.navigation.Navigator
import io.novafoundation.nova.app.root.navigation.staking.StakingDashboardNavigator
import io.novafoundation.nova.app.root.navigation.staking.StartMultiStakingNavigator
import io.novafoundation.nova.common.di.scope.ApplicationScope
import io.novafoundation.nova.feature_staking_impl.presentation.StakingDashboardRouter
import io.novafoundation.nova.feature_staking_impl.presentation.StartMultiStakingRouter

@Module(includes = [ParachainStakingNavigationModule::class, RelayStakingNavigationModule::class])
class StakingNavigationModule
@Module(
includes = [
ParachainStakingNavigationModule::class,
RelayStakingNavigationModule::class,
NominationPoolsStakingNavigationModule::class
]
)
class StakingNavigationModule {

@Provides
@ApplicationScope
fun provideStakingDashboardNavigator(navigationHolder: NavigationHolder): StakingDashboardNavigator {
return StakingDashboardNavigator(navigationHolder)
}

@Provides
@ApplicationScope
fun provideStakingDashboardRouter(relayStakingNavigator: StakingDashboardNavigator): StakingDashboardRouter = relayStakingNavigator

@Provides
@ApplicationScope
fun provideStartMultiStakingRouter(
navigationHolder: NavigationHolder,
dashboardRouter: StakingDashboardRouter,
commonNavigationHolder: Navigator
): StartMultiStakingRouter {
return StartMultiStakingNavigator(navigationHolder, dashboardRouter, commonNavigationHolder)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.novafoundation.nova.app.root.di
import dagger.BindsInstance
import dagger.Component
import io.novafoundation.nova.app.root.navigation.NavigationHolder
import io.novafoundation.nova.app.root.navigation.staking.relaychain.RelayStakingNavigator
import io.novafoundation.nova.app.root.navigation.staking.StakingDashboardNavigator
import io.novafoundation.nova.app.root.presentation.RootRouter
import io.novafoundation.nova.app.root.presentation.di.RootActivityComponent
import io.novafoundation.nova.app.root.presentation.main.di.MainFragmentComponent
Expand Down Expand Up @@ -40,7 +40,7 @@ interface RootComponent {
fun create(
@BindsInstance navigationHolder: NavigationHolder,
@BindsInstance rootRouter: RootRouter,
@BindsInstance relayStakingNavigator: RelayStakingNavigator,
@BindsInstance stakingDashboardNavigator: StakingDashboardNavigator,
deps: RootDependencies
): RootComponent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import io.novafoundation.nova.common.utils.coroutines.RootScope
import io.novafoundation.nova.common.utils.sequrity.AutomaticInteractionGate
import io.novafoundation.nova.common.utils.sequrity.BackgroundAccessObserver
import io.novafoundation.nova.common.utils.systemCall.SystemCallExecutor
import io.novafoundation.nova.core.updater.UpdateSystem
import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepository
import io.novafoundation.nova.feature_assets.data.buyToken.BuyTokenRegistry
import io.novafoundation.nova.feature_assets.data.network.BalancesUpdateSystem
import io.novafoundation.nova.feature_crowdloan_api.data.repository.CrowdloanRepository
import io.novafoundation.nova.feature_crowdloan_api.domain.contributions.ContributionsInteractor
import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor
import io.novafoundation.nova.feature_staking_api.domain.api.StakingRepository
import io.novafoundation.nova.feature_versions_api.domain.UpdateNotificationsInteractor
import io.novafoundation.nova.feature_wallet_api.di.Wallet
import io.novafoundation.nova.feature_wallet_api.domain.interfaces.WalletRepository
import io.novafoundation.nova.feature_wallet_connect_api.presentation.WalletConnectService
import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry
Expand Down Expand Up @@ -49,8 +48,7 @@ interface RootDependencies {

fun currencyInteractor(): CurrencyInteractor

@Wallet
fun walletUpdateSystem(): UpdateSystem
val balancesUpdateSystem: BalancesUpdateSystem

fun stakingRepository(): StakingRepository

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.novafoundation.nova.app.root.di

import io.novafoundation.nova.app.root.navigation.NavigationHolder
import io.novafoundation.nova.app.root.navigation.Navigator
import io.novafoundation.nova.app.root.navigation.staking.relaychain.RelayStakingNavigator
import io.novafoundation.nova.app.root.navigation.staking.StakingDashboardNavigator
import io.novafoundation.nova.common.di.FeatureApiHolder
import io.novafoundation.nova.common.di.FeatureContainer
import io.novafoundation.nova.common.di.scope.ApplicationScope
Expand All @@ -22,7 +22,7 @@ import javax.inject.Inject
class RootFeatureHolder @Inject constructor(
private val navigationHolder: NavigationHolder,
private val navigator: Navigator,
private val relayStakingNavigator: RelayStakingNavigator,
private val stakingDashboardNavigator: StakingDashboardNavigator,
featureContainer: FeatureContainer
) : FeatureApiHolder(featureContainer) {

Expand All @@ -42,6 +42,6 @@ class RootFeatureHolder @Inject constructor(
.build()

return DaggerRootComponent.factory()
.create(navigationHolder, navigator, relayStakingNavigator, rootFeatureDependencies)
.create(navigationHolder, navigator, stakingDashboardNavigator, rootFeatureDependencies)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import dagger.Module
import dagger.Provides
import io.novafoundation.nova.app.root.domain.RootInteractor
import io.novafoundation.nova.common.di.scope.FeatureScope
import io.novafoundation.nova.core.updater.UpdateSystem
import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepository
import io.novafoundation.nova.feature_wallet_api.di.Wallet
import io.novafoundation.nova.feature_assets.data.network.BalancesUpdateSystem
import io.novafoundation.nova.feature_wallet_api.domain.interfaces.WalletRepository

@Module
Expand All @@ -16,13 +15,13 @@ class RootFeatureModule {
@FeatureScope
fun provideRootInteractor(
walletRepository: WalletRepository,
@Wallet walletUpdateSystem: UpdateSystem,
accountRepository: AccountRepository
accountRepository: AccountRepository,
balancesUpdateSystem: BalancesUpdateSystem
): RootInteractor {
return RootInteractor(
walletUpdateSystem,
walletRepository,
accountRepository
updateSystem = balancesUpdateSystem,
walletRepository = walletRepository,
accountRepository = accountRepository
)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.novafoundation.nova.app.root.domain

import io.novafoundation.nova.core.updater.UpdateSystem
import io.novafoundation.nova.core.updater.Updater
import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepository
import io.novafoundation.nova.feature_assets.data.buyToken.ExternalProvider
import io.novafoundation.nova.feature_assets.data.network.BalancesUpdateSystem
import io.novafoundation.nova.feature_wallet_api.domain.interfaces.WalletRepository
import kotlinx.coroutines.flow.Flow

class RootInteractor(
private val updateSystem: UpdateSystem,
private val updateSystem: BalancesUpdateSystem,
private val walletRepository: WalletRepository,
private val accountRepository: AccountRepository
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.lifecycle.asFlow
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import io.novafoundation.nova.app.R
import io.novafoundation.nova.app.root.navigation.delayedNavigation.BackDelayedNavigation
import io.novafoundation.nova.app.root.navigation.delayedNavigation.NavComponentDelayedNavigation
import io.novafoundation.nova.app.root.presentation.RootRouter
import io.novafoundation.nova.common.navigation.DelayedNavigation
import io.novafoundation.nova.common.utils.getParcelableCompat
Expand Down Expand Up @@ -50,7 +52,8 @@ import io.novafoundation.nova.feature_assets.presentation.tokens.add.enterInfo.A
import io.novafoundation.nova.feature_assets.presentation.tokens.manage.chain.ManageChainTokensFragment
import io.novafoundation.nova.feature_assets.presentation.tokens.manage.chain.ManageChainTokensPayload
import io.novafoundation.nova.feature_assets.presentation.transaction.detail.extrinsic.ExtrinsicDetailFragment
import io.novafoundation.nova.feature_assets.presentation.transaction.detail.reward.RewardDetailFragment
import io.novafoundation.nova.feature_assets.presentation.transaction.detail.reward.direct.RewardDetailFragment
import io.novafoundation.nova.feature_assets.presentation.transaction.detail.reward.pool.PoolRewardDetailFragment
import io.novafoundation.nova.feature_assets.presentation.transaction.detail.transfer.TransferDetailFragment
import io.novafoundation.nova.feature_assets.presentation.transaction.filter.TransactionHistoryFilterFragment
import io.novafoundation.nova.feature_assets.presentation.transaction.filter.TransactionHistoryFilterPayload
Expand All @@ -69,15 +72,8 @@ import io.novafoundation.nova.feature_onboarding_impl.presentation.welcome.Welco
import io.novafoundation.nova.feature_wallet_connect_impl.WalletConnectRouter
import io.novafoundation.nova.feature_wallet_connect_impl.presentation.sessions.list.WalletConnectSessionsPayload
import io.novafoundation.nova.splash.SplashRouter
import kotlinx.android.parcel.Parcelize
import kotlinx.coroutines.flow.Flow

@Parcelize
class NavComponentDelayedNavigation(val globalActionId: Int, val extras: Bundle? = null) : DelayedNavigation

@Parcelize
object BackDelayedNavigation : DelayedNavigation

class Navigator(
private val navigationHolder: NavigationHolder,
private val walletConnectDelegate: WalletConnectRouter,
Expand Down Expand Up @@ -247,6 +243,12 @@ class Navigator(
navController?.navigate(R.id.open_reward_detail, bundle)
}

override fun openPoolRewardDetail(reward: OperationParcelizeModel.PoolReward) {
val bundle = PoolRewardDetailFragment.getBundle(reward)

navController?.navigate(R.id.open_pool_reward_detail, bundle)
}

override fun openExtrinsicDetail(extrinsic: OperationParcelizeModel.Extrinsic) {
val bundle = ExtrinsicDetailFragment.getBundle(extrinsic)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.novafoundation.nova.app.root.navigation.delayedNavigation

import io.novafoundation.nova.common.navigation.DelayedNavigation
import kotlinx.android.parcel.Parcelize

@Parcelize
object BackDelayedNavigation : DelayedNavigation
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.novafoundation.nova.app.root.navigation.delayedNavigation

import android.os.Bundle
import io.novafoundation.nova.common.navigation.DelayedNavigation
import kotlinx.android.parcel.Parcelize

@Parcelize
class NavComponentDelayedNavigation(val globalActionId: Int, val extras: Bundle? = null) : DelayedNavigation
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.novafoundation.nova.app.root.navigation.staking

import androidx.navigation.NavController
import io.novafoundation.nova.app.R
import io.novafoundation.nova.app.root.navigation.BaseNavigator
import io.novafoundation.nova.app.root.navigation.NavigationHolder
import io.novafoundation.nova.feature_staking_impl.presentation.StakingDashboardRouter

class StakingDashboardNavigator(
navigationHolder: NavigationHolder,
) : BaseNavigator(navigationHolder), StakingDashboardRouter {

private var stakingTabNavController: NavController? = null
private var pendingAction: Int? = null

fun setStakingTabNavController(navController: NavController) {
stakingTabNavController = navController

if (pendingAction != null) {
navController.performNavigation(pendingAction!!)
pendingAction = null
}
}

fun clearStakingTabNavController() {
stakingTabNavController = null
}

override fun openMoreStakingOptions() {
stakingTabNavController?.performNavigation(R.id.action_stakingDashboardFragment_to_moreStakingOptionsFragment)
}

override fun backInStakingTab() {
stakingTabNavController?.popBackStack()
}

override fun returnToStakingTabRoot() {
stakingTabNavController.performNavigationOrDelay(R.id.return_to_staking_dashboard)
}

private fun NavController?.performNavigationOrDelay(actionId: Int) {
val controller = this

if (controller != null) {
controller.performNavigation(actionId)
} else {
pendingAction = actionId
}
}
}
Loading

0 comments on commit 3c5abe1

Please sign in to comment.