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

feat: total number of v3 stakers #126

Merged
merged 3 commits into from
Jan 26, 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
41 changes: 41 additions & 0 deletions public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,47 @@
}
}
},
"/api/v3/{network}/dapps-staking/stakerscount-total/{period}": {
"get": {
"tags": [
"Dapps Staking"
],
"description": "Retrieves total stakers count for a given network and period.",
"parameters": [
{
"name": "network",
"in": "path",
"required": true,
"type": "string",
"description": "The network name. Supported networks: astar",
"enum": [
"astar",
"shiden",
"shibuya"
]
},
{
"name": "period",
"in": "path",
"required": true,
"type": "string",
"description": "The period type. Supported values: 1 day, 7 days, 30 days, 90 days, 1 year",
"enum": [
"1 day",
"7 days",
"30 days",
"90 days",
"1 year"
]
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v3/{network}/dapps-staking/chaindapps": {
"get": {
"tags": [
Expand Down
27 changes: 27 additions & 0 deletions src/controllers/DappsStakingV3Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ export class DappsStakingV3Controller extends ControllerBase implements IControl
},
);

app.route('/api/v3/:network/dapps-staking/stakerscount-total/:period').get(
async (req: Request, res: Response) => {
/*
#swagger.description = 'Retrieves total stakers count for a given network and period.'
#swagger.tags = ['Dapps Staking']
#swagger.parameters['network'] = {
in: 'path',
description: 'The network name. Supported networks: astar',
required: true,
enum: ['astar', 'shiden', 'shibuya']
}
#swagger.parameters['period'] = {
in: 'path',
description: 'The period type. Supported values: 1 day, 7 days, 30 days, 90 days, 1 year',
required: true,
enum: ['1 day', '7 days', '30 days', '90 days', '1 year']
}
*/
res.json(
await this._dappsStakingEvents.getDappStakingStakersCountTotal(
req.params.network as NetworkType,
req.params.period as PeriodType,
),
);
},
);

app.route('/api/v3/:network/dapps-staking/chaindapps').get(async (req: Request, res: Response) => {
/*
#swagger.description = 'Retrieves list of dapps (basic info) registered for dapps staking'
Expand Down
37 changes: 37 additions & 0 deletions src/services/DappsStakingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IDappsStakingEvents {
getAggregatedData(network: NetworkType, period: PeriodType): Promise<DappStakingAggregatedData[]>;
getDappStakingTvl(network: NetworkType, period: PeriodType): Promise<Pair[]>;
getDappStakingStakersCount(network: NetworkType, contractAddress: string, period: PeriodType): Promise<Pair[]>;
getDappStakingStakersCountTotal(network: NetworkType, period: PeriodType): Promise<Pair[]>;
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[]>;
Expand Down Expand Up @@ -313,6 +314,42 @@ export class DappsStakingEvents extends ServiceBase implements IDappsStakingEven
}
}

public async getDappStakingStakersCountTotal(network: NetworkType, period: PeriodType): Promise<Pair[]> {
if (network !== 'astar' && network !== 'shiden' && network !== 'shibuya') {
return [];
}

const range = this.getDateRange(period);

try {
const result = await axios.post(this.getApiUrl(network), {
query: `query {
stakersCountAggregatedDailies(
orderBy: id_DESC
where: {
id_gte: "${range.start.getTime()}"
id_lte: "${range.end.getTime()}"
}
) {
stakersCount
id
}
}`,
});

const stakersCount = result.data.data.stakersCountAggregatedDailies.map(
(node: { id: string; stakersCount: number }) => {
return [node.id, node.stakersCount];
},
);

return stakersCount;
} catch (e) {
console.error(e);
return [];
}
}

public async getDapps(network: NetworkType): Promise<[]> {
if (network !== 'astar' && network !== 'shiden' && network !== 'shibuya') {
return [];
Expand Down
Loading