Skip to content

Commit 0192225

Browse files
impelcryptobobo-k2
andauthored
hotfix: merge the latest hotfix branch to main (#1383)
* dApps loading error fix for Shibuya (#1377) * Tier thresholds derivation support (#1376) * Tier thresholds derivation support * Additional comments * Pallet version check * Fix: estimated realized inflation not showing (#1379) * Re-try fetch from cbridge (#1382) --------- Co-authored-by: Bobo <bobo.kovacevic@gmail.com>
1 parent 8ece1cf commit 0192225

10 files changed

Lines changed: 102 additions & 73 deletions

File tree

src/hooks/useChainInfo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ export function useChainInfo(api: ApiPromise) {
5353
const specName: string = api.runtimeVersion.specName.toString();
5454
const systemChain: string = ((await api.rpc.system.chain()) || '<unknown>').toString();
5555
let info = createInfo(api, systemChain, specName);
56+
chainInfo.value = info;
57+
5658
const metadata = await api.call.metadata.metadataAtVersion(15);
5759
info.rawMetadata = metadata.toHex();
58-
5960
chainInfo.value = info;
6061
});
6162

src/staking-v3/components/data/DataList.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
</template>
128128

129129
<script lang="ts">
130-
import { defineComponent, computed } from 'vue';
130+
import { defineComponent, computed, onMounted } from 'vue';
131131
import { useDataCalculations } from 'src/staking-v3/hooks';
132132
import DataCard from './DataCard.vue';
133133
import { useDappStaking, useDapps, usePeriod } from 'src/staking-v3/hooks';
@@ -154,7 +154,8 @@ export default defineComponent({
154154
numberOfStakersAndLockers,
155155
tokensToBeBurned,
156156
} = useDataCalculations();
157-
const { activeInflationConfiguration, estimatedInflation } = useInflation();
157+
const { activeInflationConfiguration, estimatedInflation, estimateRealizedInflation } =
158+
useInflation();
158159
159160
const totalDapps = computed<number>(() => registeredDapps.value?.length ?? 0);
160161
const tvl = computed<string>(() => (currentEraInfo.value?.totalLocked ?? BigInt(0)).toString());
@@ -182,6 +183,10 @@ export default defineComponent({
182183
estimatedInflation.value ? `${estimatedInflation.value.toFixed(2)} %` : '--'
183184
);
184185
186+
onMounted(() => {
187+
estimateRealizedInflation();
188+
});
189+
185190
return {
186191
protocolState,
187192
periodName,

src/staking-v3/components/leaderboard/Tier.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="text--reward">{{ $t('stakingV3.threshold') }}</div>
1414
<div class="text--amount">
1515
<token-balance-native
16-
:balance="tiersConfiguration?.tierThresholds[tier - 1]?.amount?.toString() ?? '0'"
16+
:balance="tiersConfiguration?.tierThresholds[tier - 1]?.toString() ?? '0'"
1717
:decimals="0"
1818
/>
1919
</div>

src/staking-v3/hooks/useDapps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function useDapps() {
4545

4646
try {
4747
aggregator.publish(new BusyMessage(true));
48-
const dApps = await service.getDapps();
48+
const dApps = await service.getDapps(currentNetworkName.value.toLowerCase());
4949
store.commit('stakingV3/addDapps', dApps.fullInfo);
5050
store.commit('stakingV3/addNewDapps', dApps.chainInfo);
5151
// Memo: this can a heavy operations since we are querying all dapps stakes for a chain.

src/staking-v3/logic/interfaces/DappStakingV3.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Balance } from '@astar-network/metamask-astar-types';
2-
import { AccountId32, Permill } from '@polkadot/types/interfaces';
2+
import { AccountId32, Perbill, Permill } from '@polkadot/types/interfaces';
33
import {
44
BTreeMap,
55
Compact,
@@ -126,14 +126,19 @@ export interface PalletDappStakingV3ContractStakeAmount extends Struct {
126126
readonly tierLabel: Option<PalletDappStakingV3TierLabel>;
127127
}
128128

129-
export interface PalletDappStakingV3TiersConfiguration extends Struct {
130-
readonly numberOfSlots: Compact<u16>;
129+
export interface PalletDappStakingV3TiersConfigurationLegacy extends Struct {
131130
readonly slotsPerTier: Vec<u16>;
132131
readonly rewardPortion: Vec<Permill>;
133132
readonly tierThresholds: Vec<PalletDappStakingV3TierThreshold>;
134133
}
135134

136-
interface PalletDappStakingV3TierThreshold extends Enum {
135+
export interface PalletDappStakingV3TiersConfiguration extends Struct {
136+
readonly slotsPerTier: Vec<u16>;
137+
readonly rewardPortion: Vec<Perbill>;
138+
readonly tierThresholds: Vec<u128>;
139+
}
140+
141+
export interface PalletDappStakingV3TierThreshold extends Enum {
137142
readonly isFixedTvlAmount: boolean;
138143
readonly asFixedTvlAmount: {
139144
readonly amount: u128;

src/staking-v3/logic/models/DappStaking.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,7 @@ export interface TiersConfiguration {
172172
readonly numberOfSlots: number;
173173
readonly slotsPerTier: number[];
174174
readonly rewardPortion: number[];
175-
readonly tierThresholds: TierThreshold[];
176-
}
177-
178-
interface TierThreshold {
179-
readonly amount: BigInt;
180-
readonly minimumAmount?: BigInt;
181-
readonly type: TvlAmountType;
175+
readonly tierThresholds: bigint[];
182176
}
183177

184178
export interface InflationParam {

src/staking-v3/logic/repositories/DappStakingRepository.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
SingularStakingInfo,
2121
StakeAmount,
2222
TiersConfiguration,
23-
TvlAmountType,
2423
} from '../models';
2524
import axios from 'axios';
2625
import { inject, injectable } from 'inversify';
@@ -38,10 +37,12 @@ import {
3837
PalletDappStakingV3SingularStakingInfo,
3938
PalletDappStakingV3StakeAmount,
4039
PalletDappStakingV3TiersConfiguration,
40+
PalletDappStakingV3TiersConfigurationLegacy,
41+
PalletDappStakingV3TierThreshold,
4142
SmartContractAddress,
4243
} from '../interfaces';
4344
import { 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';
4546
import { IDappStakingRepository } from './IDappStakingRepository';
4647
import { Guard } from 'src/v2/common';
4748
import { 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

src/staking-v3/logic/services/DappStakingService.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ export class DappStakingService extends SignerService implements IDappStakingSer
4848
}
4949

5050
// @inheritdoc
51-
public async getDapps(): Promise<{ fullInfo: CombinedDappInfo[]; chainInfo: DappInfo[] }> {
52-
const metadata = await this.metadataRepository.getChainMetadata();
53-
const chain = metadata.chain.toLowerCase();
51+
public async getDapps(
52+
network: string
53+
): Promise<{ fullInfo: CombinedDappInfo[]; chainInfo: DappInfo[] }> {
54+
Guard.ThrowIfUndefined('network', network);
55+
5456
const [storeDapps, chainDapps, tokenApiDapps] = await Promise.all([
55-
this.dappStakingRepository.getDapps(chain),
57+
this.dappStakingRepository.getDapps(network.toLowerCase()),
5658
this.dappStakingRepository.getChainDapps(),
57-
this.tokenApiRepository.getDapps(chain),
59+
this.tokenApiRepository.getDapps(network.toLowerCase()),
5860
]);
5961

6062
// Map on chain and in store dApps (registered only)

src/staking-v3/logic/services/IDappStakingService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface IDappStakingService {
1717
* Gets the dapps for the given network.
1818
* @returns A map containing full dapps info (chain and firebase data) and chain info (only for new dapps not stored in firebase yet).
1919
*/
20-
getDapps(): Promise<{ fullInfo: CombinedDappInfo[]; chainInfo: DappInfo[] }>;
20+
getDapps(network: string): Promise<{ fullInfo: CombinedDappInfo[]; chainInfo: DappInfo[] }>;
2121

2222
/**
2323
* Invokes claim staker rewards, unstake and unlock calls.

src/v2/repositories/implementations/EvmAssetsRepository.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class EvmAssetsRepository implements IEvmAssetsRepository {
5656
isFetchUsd: boolean;
5757
}): Promise<Erc20Token[]> {
5858
Guard.ThrowIfUndefined('currentAccount', currentAccount);
59+
const numberOfRetries = 2;
5960

6061
if (
6162
String(srcChainId) === providerEndpoints[endpointKey.SHIBUYA].evmChainId ||
@@ -67,43 +68,48 @@ export class EvmAssetsRepository implements IEvmAssetsRepository {
6768
return [];
6869
}
6970

70-
const data = await getTransferConfigs(currentNetworkIdx);
71-
if (!data || !data.tokens) {
72-
throw Error('Cannot fetch from cBridge API');
73-
}
74-
const seen = new Set();
75-
// Todo: use srcChain and destChainID to re-define token information for bridging (ex: PKEX)
71+
for (let i = 0; i < numberOfRetries; i++) {
72+
const data = await getTransferConfigs(currentNetworkIdx);
73+
if (!data || !data.tokens) {
74+
continue;
75+
}
7676

77-
const tokens = (await Promise.all(
78-
objToArray(data.tokens[srcChainId as EvmChain])
79-
.flat()
80-
.map(async (token: CbridgeToken) => {
81-
const t = getSelectedToken({ srcChainId, token });
82-
if (!t) return undefined;
83-
const formattedToken = castCbridgeToErc20({ srcChainId, token: t });
84-
const isDuplicated = seen.has(formattedToken.address);
85-
seen.add(formattedToken.address);
86-
// Memo: Remove the duplicated contract address (ex: PKEX)
87-
if (isDuplicated) return undefined;
77+
const seen = new Set();
78+
// Todo: use srcChain and destChainID to re-define token information for bridging (ex: PKEX)
8879

89-
const { balUsd, userBalance } = await this.updateTokenBalanceHandler({
90-
userAddress: currentAccount,
91-
token: formattedToken,
92-
isFetchUsd,
93-
srcChainId,
94-
});
95-
const tokenWithBalance = {
96-
...formattedToken,
97-
userBalance,
98-
userBalanceUsd: String(balUsd),
99-
};
100-
return castCbridgeTokenData(tokenWithBalance);
101-
})
102-
)) as Erc20Token[];
80+
const tokens = (await Promise.all(
81+
objToArray(data.tokens[srcChainId as EvmChain])
82+
.flat()
83+
.map(async (token: CbridgeToken) => {
84+
const t = getSelectedToken({ srcChainId, token });
85+
if (!t) return undefined;
86+
const formattedToken = castCbridgeToErc20({ srcChainId, token: t });
87+
const isDuplicated = seen.has(formattedToken.address);
88+
seen.add(formattedToken.address);
89+
// Memo: Remove the duplicated contract address (ex: PKEX)
90+
if (isDuplicated) return undefined;
10391

104-
return tokens.filter((token) => {
105-
return token !== undefined;
106-
});
92+
const { balUsd, userBalance } = await this.updateTokenBalanceHandler({
93+
userAddress: currentAccount,
94+
token: formattedToken,
95+
isFetchUsd,
96+
srcChainId,
97+
});
98+
const tokenWithBalance = {
99+
...formattedToken,
100+
userBalance,
101+
userBalanceUsd: String(balUsd),
102+
};
103+
return castCbridgeTokenData(tokenWithBalance);
104+
})
105+
)) as Erc20Token[];
106+
107+
return tokens.filter((token) => {
108+
return token !== undefined;
109+
});
110+
}
111+
112+
throw Error('Cannot fetch from cBridge API');
107113
}
108114

109115
public async fetchRegisteredAssets({

0 commit comments

Comments
 (0)