From 9f240a1b46831a2a3fcdfe6afbfb00e16ae7fc87 Mon Sep 17 00:00:00 2001 From: Bobo Date: Thu, 18 Jul 2024 09:30:29 +0200 Subject: [PATCH] Fetch stakes from updated indexer (#161) * Fetch stakes from updated indexer * Indexer url update --- src/client/BaseApi.ts | 7 +++++++ src/services/DappsStakingEvents.ts | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client/BaseApi.ts b/src/client/BaseApi.ts index 395aeb5..fb08e80 100644 --- a/src/client/BaseApi.ts +++ b/src/client/BaseApi.ts @@ -93,6 +93,7 @@ export interface IAstarApi { getCurrentEra(): Promise; getApiPromise(): Promise; getStakerInfo(address: string): Promise; + getProtocolState(): Promise; } export class BaseApi implements IAstarApi { @@ -233,6 +234,12 @@ export class BaseApi implements IAstarApi { } } + public async getProtocolState(): Promise { + await this.ensureConnection(); + + return await this._api.query.dappStaking.activeProtocolState(); + } + public async getStakerInfo(address: string): Promise { await this.ensureConnection(); let ss558Address = address; diff --git a/src/services/DappsStakingEvents.ts b/src/services/DappsStakingEvents.ts index 70e9819..269d3ce 100644 --- a/src/services/DappsStakingEvents.ts +++ b/src/services/DappsStakingEvents.ts @@ -314,13 +314,19 @@ export class DappsStakingEvents extends DappStakingV3IndexerBase implements IDap public async getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise { this.GuardNetwork(network); + Guard.ThrowIfUndefined('contractAddress', contractAddress); + + // Fetch current period + const api = this._apiFactory.getApiInstance(network); + const protocolState = await api.getProtocolState(); + const period = protocolState.periodInfo.number.toNumber(); try { const result = await axios.post(this.getApiUrl(network), { query: `query { stakes( where: { - expiredAt_isNull: true, + period_eq: ${period}, dappAddress_eq: "${contractAddress}" } ) {