Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide EVM address on stakers list #164

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/DappStakingV3IndexerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Copy link
Member

@gtg7784 gtg7784 Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the v14 to prod in sqd cloud and revert this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because of
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay

}
}
38 changes: 22 additions & 16 deletions src/services/DappsStakingEvents.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand All @@ -38,7 +38,7 @@ export interface IDappsStakingEvents {
getDappStakingLockersAndStakersTotal(network: NetworkType, period: PeriodType): Promise<TotalAmountCount[]>;
getDappStakingRewards(network: NetworkType, period: PeriodType, transaction: RewardEventType): Promise<Pair[]>;
getDappStakingRewardsAggregated(network: NetworkType, address: string, period: PeriodType): Promise<Pair[]>;
getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise<List[]>;
getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise<StakerAmount[]>;
getAggregatedPeriodData(network: NetworkType, period: number): Promise<PeriodDataResponse[]>;
getAggregatedStakerData(network: NetworkType, stakerAddress: string): Promise<StakerPeriodDataResponse[]>;
getTotalAggregatedStakerData(network: NetworkType, stakerAddress: string): Promise<StakerPeriodTotalResponse>;
Expand Down Expand Up @@ -312,7 +312,7 @@ export class DappsStakingEvents extends DappStakingV3IndexerBase implements IDap
}
}

public async getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise<List[]> {
public async getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise<StakerAmount[]> {
this.GuardNetwork(network);
Guard.ThrowIfUndefined('contractAddress', contractAddress);

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/ServiceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading