Skip to content

Commit

Permalink
Merge branch 'prod' into feat/stakingv3-stakerstakeamount
Browse files Browse the repository at this point in the history
  • Loading branch information
gluneau authored Jan 26, 2024
2 parents be20e76 + d6458a5 commit b4f53e1
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/firebase-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
channelId: live
projectId: astar-token-api
- name: Deploy Firebase Function
uses: w9jds/firebase-action@master
uses: w9jds/firebase-action@v13.0.3
with:
args: deploy --only functions --debug
env:
Expand Down
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
41 changes: 41 additions & 0 deletions src/services/DappsStakingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IDappsStakingEvents {
getDappStakingTvl(network: NetworkType, period: PeriodType): Promise<Pair[]>;
getDappStakingStakersCount(network: NetworkType, contractAddress: string, period: PeriodType): Promise<Pair[]>;
getParticipantStake(network: NetworkType, address: string): Promise<bigint>;
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 @@ -335,6 +336,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 All @@ -345,6 +382,10 @@ export class DappsStakingEvents extends ServiceBase implements IDappsStakingEven
query: `query {
dapps (orderBy: registeredAt_ASC) {
contractAddress: id
dappId
beneficiary
owner
state
stakersCount
registeredAt
registrationBlockNumber
Expand Down

0 comments on commit b4f53e1

Please sign in to comment.