Skip to content

Commit

Permalink
feat: DappsStaking V3 graphql endpoints (#110)
Browse files Browse the repository at this point in the history
* working v3 endpoint for raw staking events
* aggregated endpoint
* contract address, dates and limits
* swagger details
  • Loading branch information
gluneau authored Oct 24, 2023
1 parent a02afb9 commit 7374fd5
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typings/
dist
build
lib
out

# Gatsby files
.cache/
Expand Down
134 changes: 133 additions & 1 deletion public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,35 @@
"tags": [
"Dapps Staking"
],
"description": "Retrieves list of dapps registered for dapps staking",
"description": "Retrieves list of dapps (full model) registered for dapps staking",
"parameters": [
{
"name": "network",
"in": "path",
"required": true,
"type": "string",
"description": "The network name. Supported networks: astar, shiden, shibuya, rocstar, development",
"enum": [
"astar",
"shiden",
"shibuya",
"rocstar"
]
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/{network}/dapps-staking/dappssimple": {
"get": {
"tags": [
"Dapps Staking"
],
"description": "Retrieves list of dapps (basic info) registered for dapps staking",
"parameters": [
{
"name": "network",
Expand Down Expand Up @@ -589,6 +617,110 @@
}
}
},
"/api/v3/{network}/dapps-staking/stats/dapp/{contractAddress}": {
"get": {
"tags": [
"Dapps Staking"
],
"description": "Retrieves raw stats of dapps staking events with types for a given smart contract address.",
"parameters": [
{
"name": "network",
"in": "path",
"required": true,
"type": "string",
"description": "The network name. Supported networks: astar",
"enum": [
"astar"
]
},
{
"name": "contractAddress",
"in": "path",
"required": true,
"type": "string",
"description": "Smart Contract address to get stats for"
},
{
"name": "startDate",
"in": "query",
"description": "Start date for filtering the staking events (inclusive). Format: YYYY-MM-DD",
"required": false,
"type": "string",
"format": "date"
},
{
"name": "endDate",
"in": "query",
"description": "End date for filtering the staking events (inclusive). Format: YYYY-MM-DD",
"required": false,
"type": "string",
"format": "date"
},
{
"name": "limit",
"in": "query",
"description": "Number of records to retrieve per page. Defaults to 100 if not provided.",
"required": false,
"type": "integer",
"format": "int32",
"default": 10
},
{
"name": "offset",
"in": "query",
"description": "Number of records to skip for pagination. Defaults to 0 if not provided.",
"required": false,
"type": "integer",
"format": "int32",
"default": 0
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v3/{network}/dapps-staking/stats/aggregated/{period}": {
"get": {
"tags": [
"Dapps Staking"
],
"description": "Retrieves aggregated stats of dapps staking events for a given period.",
"parameters": [
{
"name": "network",
"in": "path",
"required": true,
"type": "string",
"description": "The network name. Supported networks: astar",
"enum": [
"astar"
]
},
{
"name": "period",
"in": "path",
"required": true,
"type": "string",
"description": "The period type. Supported values: 7 days 30 days, 90 days, 1 year",
"enum": [
"7 days",
"30 days",
"90 days",
"1 year"
]
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/{network}/node/tx-perblock/total": {
"get": {
"tags": [
Expand Down
3 changes: 3 additions & 0 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DiaDataPriceProvider } from './services/DiaDataPriceProvider';
import { CoinGeckoPriceProvider } from './services/CoinGeckoPriceProvider';
import { PriceProviderWithFailover } from './services/PriceProviderWithFailover';
import { DappsStakingService2 } from './services/DappsStakingService2';
import { DappsStakingEvents, IDappsStakingEvents } from './services/DappsStakingEvents';
import { IMonthlyActiveWalletsService, MonthlyActiveWalletsService } from './services/MonthlyActiveWalletsService';
import { MonthlyActiveWalletsController } from './controllers/MonthlyActiveWalletsController';
import { DappsStakingStatsService, IDappsStakingStatsService } from './services/DappsStakingStatsService';
Expand Down Expand Up @@ -71,6 +72,8 @@ container.bind<IApiFactory>(ContainerTypes.ApiFactory).to(ApiFactory).inSingleto
// services registration
container.bind<IStatsService>(ContainerTypes.StatsService).to(StatsService).inSingletonScope();

container.bind<IDappsStakingEvents>(ContainerTypes.DappsStakingEvents).to(DappsStakingEvents).inSingletonScope();

container
.bind<IDappsStakingService>(ContainerTypes.DappsStakingService)
.to(DappsStakingService2)
Expand Down
1 change: 1 addition & 0 deletions src/containertypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const ContainerTypes = {
StatsService: 'StatsService',
Api: 'Api',
ApiFactory: 'ApiFactory',
DappsStakingEvents: 'DappsStakingEvents',
DappsStakingService: 'DappsStakingService',
StatsIndexerService: 'StatsIndexerService',
FirebaseService: 'FirebaseService',
Expand Down
102 changes: 102 additions & 0 deletions src/controllers/DappsStakingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { IStatsIndexerService } from '../services/StatsIndexerService';
import { ControllerBase } from './ControllerBase';
import { IControllerBase } from './IControllerBase';
import { IGiantSquidService } from '../services/GiantSquidService';
import { IDappsStakingEvents } from '../services/DappsStakingEvents';

@injectable()
export class DappsStakingController extends ControllerBase implements IControllerBase {
Expand All @@ -23,6 +24,7 @@ export class DappsStakingController extends ControllerBase implements IControlle
@inject(ContainerTypes.DappsStakingStatsService) private _statsService: IDappsStakingStatsService,
@inject(ContainerTypes.DappRadarService) private _dappRadarService: IDappRadarService,
@inject(ContainerTypes.GiantSquidService) private _giantSquidService: IGiantSquidService,
@inject(ContainerTypes.DappsStakingEvents) private _dappsStakingEvents: IDappsStakingEvents,
) {
super();
}
Expand Down Expand Up @@ -334,6 +336,106 @@ export class DappsStakingController extends ControllerBase implements IControlle
},
);

app.route('/api/v3/:network/dapps-staking/stats/dapp/:contractAddress').get(
async (req: Request, res: Response) => {
/*
#swagger.description = 'Retrieves raw stats of dapps staking events with types for a given smart contract address.'
#swagger.tags = ['Dapps Staking']
#swagger.parameters['network'] = {
in: 'path',
description: 'The network name. Supported networks: astar',
required: true,
enum: ['astar']
}
#swagger.parameters['contractAddress'] = {
in: 'path',
description: 'Smart Contract address to get stats for',
required: true
}
#swagger.parameters['startDate'] = {
in: 'query',
description: 'Start date for filtering the staking events (inclusive). Format: YYYY-MM-DD',
required: true,
type: 'string',
format: 'date'
}
#swagger.parameters['endDate'] = {
in: 'query',
description: 'End date for filtering the staking events (inclusive). Format: YYYY-MM-DD',
required: true,
type: 'string',
format: 'date'
}
#swagger.parameters['limit'] = {
in: 'query',
description: 'Number of records to retrieve per page. Defaults to 100 if not provided.',
required: false,
type: 'integer',
format: 'int32',
default: 100
}
#swagger.parameters['offset'] = {
in: 'query',
description: 'Number of records to skip for pagination. Defaults to 0 if not provided.',
required: false,
type: 'integer',
format: 'int32',
default: 0
}
*/
const startDate = req.query.startDate;
const endDate = req.query.endDate;
const limit = parseInt(req.query.limit as string, 10) || 100; // Default to 100 if not provided
const offset = parseInt(req.query.offset as string, 10) || 0; // Default to 0 if not provided

try {
res.json(
await this._dappsStakingEvents.getStakingEvents(
req.params.network as NetworkType,
req.params.contractAddress,
startDate as string,
endDate as string,
limit as number,
offset as number,
),
);
} catch (err) {
this.handleError(res, err as Error);
}
},
);

app.route('/api/v3/:network/dapps-staking/stats/aggregated/:period').get(
async (req: Request, res: Response) => {
/*
#swagger.description = 'Retrieves aggregated stats of dapps staking events for a given period.'
#swagger.tags = ['Dapps Staking']
#swagger.parameters['network'] = {
in: 'path',
description: 'The network name. Supported networks: astar',
required: true,
enum: ['astar']
}
#swagger.parameters['period'] = {
in: 'path',
description: 'The period type. Supported values: 7 days 30 days, 90 days, 1 year',
required: true,
enum: ['7 days', '30 days', '90 days', '1 year']
}
*/
try {
res.json(
await this._dappsStakingEvents.getAggregatedData(
req.params.network as NetworkType,
req.params.period as PeriodType,
),
);
} catch (err) {
this.handleError(res, err as Error);
}
},
);

app.route('/api/v1/:network/dapps-staking/stats/transactions').get(async (req: Request, res: Response) => {
/*
#swagger.ignore = true
Expand Down
36 changes: 36 additions & 0 deletions src/services/DappStaking/ResponseData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export interface DappStakingEventResponse {
data: {
stakingEvents: DappStakingEventData[];
};
}

export interface DappStakingAggregatedResponse {
data: {
groupedStakingEvents: DappStakingAggregatedData[];
};
}

export enum UserTransactionType {
BondAndStake = 'BondAndStake',
UnbondAndUnstake = 'UnbondAndUnstake',
Withdraw = 'Withdraw',
WithdrawFromUnregistered = 'WithdrawFromUnregistered',
NominationTransfer = 'NominationTransfer',
}

export interface DappStakingEventData {
id: string;
userAddress: string;
transaction: UserTransactionType;
contractAddress: string;
amount: bigint;
timestamp: bigint;
blockNumber: bigint;
}

export interface DappStakingAggregatedData {
id: string;
transaction: UserTransactionType;
amount: bigint;
timestamp: bigint;
}
1 change: 1 addition & 0 deletions src/services/DappStaking/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ResponseData';
Loading

0 comments on commit 7374fd5

Please sign in to comment.