From 4a2ae6efea0d61bfcfb21cca51121fac25c968f9 Mon Sep 17 00:00:00 2001 From: Bobo Date: Mon, 11 Nov 2024 09:35:35 +0100 Subject: [PATCH] Provide EVM address on stakers list --- src/services/DappStakingV3IndexerBase.ts | 2 +- src/services/DappsStakingEvents.ts | 38 ++++++++++++++---------- src/services/ServiceBase.ts | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/services/DappStakingV3IndexerBase.ts b/src/services/DappStakingV3IndexerBase.ts index a6ff9ff..5b1142a 100644 --- a/src/services/DappStakingV3IndexerBase.ts +++ b/src/services/DappStakingV3IndexerBase.ts @@ -12,6 +12,6 @@ export class DappStakingV3IndexerBase extends ServiceBase { protected getApiUrl(network: NetworkType): string { // For local development: `http://localhost:4350/graphql`; - return `https://astar-network.squids.live/dapps-staking-indexer-${network}/graphql`; + return `https://astar-network.squids.live/dapps-staking-indexer-${network}/v/v14/graphql`; } } diff --git a/src/services/DappsStakingEvents.ts b/src/services/DappsStakingEvents.ts index 269d3ce..35e3966 100644 --- a/src/services/DappsStakingEvents.ts +++ b/src/services/DappsStakingEvents.ts @@ -1,12 +1,12 @@ import { injectable, inject } from 'inversify'; import axios from 'axios'; import { formatEther } from 'ethers'; -import { NetworkType } from '../networks'; +import type { NetworkType } from '../networks'; import { Guard } from '../guard'; -import { TotalAmountCount, Triplet, Pair, PeriodType, List } from './ServiceBase'; -import { IApiFactory } from '../client/ApiFactory'; +import type { TotalAmountCount, Triplet, Pair, PeriodType, StakerAmount } from './ServiceBase'; +import type { IApiFactory } from '../client/ApiFactory'; import { ContainerTypes } from '../containertypes'; -import { +import type { DappStakingEventData, DappStakingEventResponse, DappStakingAggregatedData, @@ -15,7 +15,7 @@ import { StakerPeriodDataResponse, StakerPeriodTotalResponse, } from './DappStaking/ResponseData'; -import { IStatsIndexerService } from './StatsIndexerService'; +import type { IStatsIndexerService } from './StatsIndexerService'; import { DappStakingV3IndexerBase } from './DappStakingV3IndexerBase'; export interface IDappsStakingEvents { @@ -38,7 +38,7 @@ export interface IDappsStakingEvents { getDappStakingLockersAndStakersTotal(network: NetworkType, period: PeriodType): Promise; getDappStakingRewards(network: NetworkType, period: PeriodType, transaction: RewardEventType): Promise; getDappStakingRewardsAggregated(network: NetworkType, address: string, period: PeriodType): Promise; - getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise; + getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise; getAggregatedPeriodData(network: NetworkType, period: number): Promise; getAggregatedStakerData(network: NetworkType, stakerAddress: string): Promise; getTotalAggregatedStakerData(network: NetworkType, stakerAddress: string): Promise; @@ -312,7 +312,7 @@ export class DappsStakingEvents extends DappStakingV3IndexerBase implements IDap } } - public async getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise { + public async getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise { this.GuardNetwork(network); Guard.ThrowIfUndefined('contractAddress', contractAddress); @@ -331,25 +331,31 @@ export class DappsStakingEvents extends DappStakingV3IndexerBase implements IDap } ) { stakerAddress + stakerAddressEvm amount } }`, }); - const sumsByStaker: { [key: string]: bigint } = result.data.data.stakes.reduce( - (acc: { [key: string]: bigint }, { stakerAddress, amount }: List) => { - acc[stakerAddress] = (acc[stakerAddress] || BigInt(0)) + BigInt(amount); + const sumsByStaker: { + [key: string]: { amount: bigint; stakerAddress: string; stakerAddressEvm?: string }; + } = result.data.data.stakes.reduce( + ( + acc: { [key: string]: { amount: bigint; stakerAddress: string; stakerAddressEvm?: string } }, + { stakerAddress, stakerAddressEvm, amount }: StakerAmount, + ) => { + if (!acc[stakerAddress]) { + acc[stakerAddress] = { amount: BigInt(0), stakerAddress, stakerAddressEvm }; + } + acc[stakerAddress].amount += BigInt(amount); return acc; }, {}, ); - const stakersList: List[] = Object.entries(sumsByStaker) - .map(([stakerAddress, amount]) => ({ - stakerAddress, - amount, - })) - .filter((staker) => staker.amount !== BigInt(0)); + const stakersList: StakerAmount[] = Object.entries(sumsByStaker) + .map(([_, stake]) => stake) + .filter((s) => s.amount !== BigInt(0)); return stakersList; } catch (e) { diff --git a/src/services/ServiceBase.ts b/src/services/ServiceBase.ts index 4f23199..350689d 100644 --- a/src/services/ServiceBase.ts +++ b/src/services/ServiceBase.ts @@ -4,7 +4,7 @@ export type PeriodType = '1 day' | '7 days' | '30 days' | '90 days' | '1 year'; export type PeriodTypeEra = '7 eras' | '30 eras' | '90 eras' | 'all'; export type Pair = { date: number; value: number }; export type Triplet = { date: string; count: number; amount: number }; -export type List = { stakerAddress: string; amount: bigint }; +export type StakerAmount = { stakerAddress: string; amount: bigint; stakerAddressEvm?: string }; export type DateRange = { start: Date; end: Date }; export type TotalAmountCount = { date: string;