@@ -20,7 +20,6 @@ import {
2020 SingularStakingInfo ,
2121 StakeAmount ,
2222 TiersConfiguration ,
23- TvlAmountType ,
2423} from '../models' ;
2524import axios from 'axios' ;
2625import { inject , injectable } from 'inversify' ;
@@ -38,10 +37,12 @@ import {
3837 PalletDappStakingV3SingularStakingInfo ,
3938 PalletDappStakingV3StakeAmount ,
4039 PalletDappStakingV3TiersConfiguration ,
40+ PalletDappStakingV3TiersConfigurationLegacy ,
41+ PalletDappStakingV3TierThreshold ,
4142 SmartContractAddress ,
4243} from '../interfaces' ;
4344import { IEventAggregator } from 'src/v2/messaging' ;
44- import { Option , StorageKey , u32 , u128 , Bytes } from '@polkadot/types' ;
45+ import { Option , StorageKey , u32 , u128 , Bytes , u16 } from '@polkadot/types' ;
4546import { IDappStakingRepository } from './IDappStakingRepository' ;
4647import { Guard } from 'src/v2/common' ;
4748import { ethers } from 'ethers' ;
@@ -512,26 +513,41 @@ export class DappStakingRepository implements IDappStakingRepository {
512513 }
513514
514515 public async getTiersConfiguration ( ) : Promise < TiersConfiguration > {
516+ const TIER_DERIVATION_PALLET_VERSION = 8 ;
515517 const api = await this . api . getApi ( ) ;
516- const configuration =
517- await api . query . dappStaking . tierConfig < PalletDappStakingV3TiersConfiguration > ( ) ;
518+ const palletVersion = ( await api . query . dappStaking . palletVersion < u16 > ( ) ) . toNumber ( ) ;
519+ let configuration :
520+ | PalletDappStakingV3TiersConfiguration
521+ | PalletDappStakingV3TiersConfigurationLegacy ;
522+
523+ if ( palletVersion >= TIER_DERIVATION_PALLET_VERSION ) {
524+ configuration =
525+ await api . query . dappStaking . tierConfig < PalletDappStakingV3TiersConfiguration > ( ) ;
526+ } else {
527+ configuration =
528+ await api . query . dappStaking . tierConfig < PalletDappStakingV3TiersConfigurationLegacy > ( ) ;
529+ }
518530
519531 return {
520- numberOfSlots : configuration . numberOfSlots . toNumber ( ) ,
532+ numberOfSlots : configuration . slotsPerTier . reduce ( ( acc , val ) => acc + val . toNumber ( ) , 0 ) ,
521533 slotsPerTier : configuration . slotsPerTier . map ( ( slot ) => slot . toNumber ( ) ) ,
522534 rewardPortion : configuration . rewardPortion . map ( ( portion ) => portion . toNumber ( ) / 1_000_000 ) ,
523- tierThresholds : configuration . tierThresholds . map ( ( threshold ) =>
524- threshold . isDynamicTvlAmount
525- ? {
526- type : TvlAmountType . DynamicTvlAmount ,
527- amount : threshold . asDynamicTvlAmount . amount . toBigInt ( ) ,
528- minimumAmount : threshold . asDynamicTvlAmount . minimumAmount . toBigInt ( ) ,
529- }
530- : {
531- type : TvlAmountType . FixedTvlAmount ,
532- amount : threshold . asFixedTvlAmount . amount . toBigInt ( ) ,
533- }
534- ) ,
535+ tierThresholds : configuration . tierThresholds . map ( ( threshold ) => {
536+ // Support both u128 and PalletDappStakingV3TierThreshold.
537+ // If threshold has isUnsigned property it's u128.
538+ // TODO: remove palletVersion check when u128 is used for all thresholds. Most likely in Astar period 003.
539+ if ( palletVersion < TIER_DERIVATION_PALLET_VERSION ) {
540+ const t = < PalletDappStakingV3TierThreshold > threshold ;
541+ if ( t . isDynamicTvlAmount ) {
542+ return t . asDynamicTvlAmount . amount . toBigInt ( ) ;
543+ } else {
544+ return t . asFixedTvlAmount . amount . toBigInt ( ) ;
545+ }
546+ } else {
547+ const t = < u128 > threshold ;
548+ return t . toBigInt ( ) ;
549+ }
550+ } ) ,
535551 } ;
536552 }
537553
0 commit comments