diff --git a/apps/api/src/dao/dao.controller.ts b/apps/api/src/dao/dao.controller.ts index 52c03c5..262cb5a 100644 --- a/apps/api/src/dao/dao.controller.ts +++ b/apps/api/src/dao/dao.controller.ts @@ -7,6 +7,7 @@ import { DaoService, } from '@dao-stats/common'; import { HasDaoContractContext } from '../decorators'; +import { ContractContextPipe } from '../pipes'; @ApiTags('DAOs') @Controller('daos') @@ -21,7 +22,9 @@ export class DaoController { description: 'Bad Request Response based on the query params set', }) @Get() - async daos(@Param() context: ContractContext): Promise { + async daos( + @Param(ContractContextPipe) context: ContractContext, + ): Promise { const { contractId } = context; return this.daoService.find(contractId); @@ -36,7 +39,9 @@ export class DaoController { }) @HasDaoContractContext() @Get('/:dao') - async dao(@Param() context: DaoContractContext): Promise { + async dao( + @Param(ContractContextPipe) context: DaoContractContext, + ): Promise { const { contractId, dao } = context; const daoEntity = await this.daoService.findById(contractId, dao); @@ -57,7 +62,7 @@ export class DaoController { }) @Get('/autocomplete/:input') async autocomplete( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Param('input') input: string, ): Promise { const { contractId } = context; diff --git a/apps/api/src/flow/flow.controller.ts b/apps/api/src/flow/flow.controller.ts index 0544f01..fbedb92 100644 --- a/apps/api/src/flow/flow.controller.ts +++ b/apps/api/src/flow/flow.controller.ts @@ -14,7 +14,7 @@ import { } from './dto'; import { FlowService } from './flow.service'; import { HasDaoContractContext } from '../decorators'; -import { MetricQueryPipe } from '../pipes'; +import { ContractContextPipe, MetricQueryPipe } from '../pipes'; @ApiTags('Flow') @Controller('flow') @@ -29,7 +29,7 @@ export class FlowController { description: 'Bad Request Response based on the query params set', }) @Get('/') - async totals(@Param() context: ContractContext): Promise { + async totals(@Param(ContractContextPipe) context: ContractContext): Promise { return this.flowService.totals(context); } @@ -42,7 +42,7 @@ export class FlowController { }) @Get('/funds') async funds( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.flowService.history(context, FlowMetricType.Fund, metricQuery); @@ -57,7 +57,7 @@ export class FlowController { }) @Get('/funds/leaderboard') async fundsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.flowService.leaderboard(context, FlowMetricType.Fund); } @@ -71,7 +71,7 @@ export class FlowController { }) @Get('/transactions') async transactions( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.flowService.history( @@ -90,7 +90,7 @@ export class FlowController { }) @Get('/transactions/leaderboard') async transactionsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.flowService.leaderboard(context, FlowMetricType.Transaction); } @@ -105,7 +105,7 @@ export class FlowController { @HasDaoContractContext() @Get('/:dao') async daoTotals( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, ): Promise { return this.flowService.totals(context); } @@ -120,7 +120,7 @@ export class FlowController { @HasDaoContractContext() @Get('/:dao/funds') async daoFunds( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.flowService.history(context, FlowMetricType.Fund, metricQuery); @@ -136,7 +136,7 @@ export class FlowController { @HasDaoContractContext() @Get('/:dao/transactions') async daoTransactions( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.flowService.history( diff --git a/apps/api/src/flow/flow.module.ts b/apps/api/src/flow/flow.module.ts index f30bd39..3abbe2b 100644 --- a/apps/api/src/flow/flow.module.ts +++ b/apps/api/src/flow/flow.module.ts @@ -8,7 +8,6 @@ import { TransactionModule } from '@dao-stats/transaction'; import { FlowController } from './flow.controller'; import { FlowService } from './flow.service'; -import { ContractModule } from '../contract/contract.module'; @Module({ imports: [ @@ -18,7 +17,6 @@ import { ContractModule } from '../contract/contract.module'; TypeOrmModule.forFeature([Contract]), TransactionModule, ReceiptModule, - ContractModule, ], providers: [FlowService], controllers: [FlowController], diff --git a/apps/api/src/flow/flow.service.ts b/apps/api/src/flow/flow.service.ts index becc178..7992129 100644 --- a/apps/api/src/flow/flow.service.ts +++ b/apps/api/src/flow/flow.service.ts @@ -18,26 +18,16 @@ import { FlowLeaderboardMetricResponse, } from './dto'; import { convertFunds, getDailyIntervals, getGrowth } from '../utils'; -import { ContractService } from '../contract/contract.service'; @Injectable() export class FlowService { - constructor( - private readonly receiptActionService: ReceiptActionService, - private readonly contractService: ContractService, - ) {} + constructor(private readonly receiptActionService: ReceiptActionService) {} async totals(context: ContractContext): Promise { - const dayAgo = moment().subtract(1, 'days'); - - const contract = await this.contractService.findById(context.contractId); - + const { contract } = context; const { conversionFactor } = contract; - const contractContext = { - ...context, - contract, - }; + const dayAgo = moment().subtract(1, 'days'); const [ txInCount, @@ -50,12 +40,12 @@ export class FlowService { dayAgoTotalOut, ] = await Promise.all([ this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Transaction, TransferType.Incoming, ), this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Transaction, TransferType.Incoming, { @@ -63,12 +53,12 @@ export class FlowService { }, ), this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Transaction, TransferType.Outgoing, ), this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Transaction, TransferType.Outgoing, { @@ -76,12 +66,12 @@ export class FlowService { }, ), this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Fund, TransferType.Incoming, ), this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Fund, TransferType.Incoming, { @@ -89,12 +79,12 @@ export class FlowService { }, ), this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Fund, TransferType.Outgoing, ), this.receiptActionService.getTotals( - contractContext, + context, FlowMetricType.Fund, TransferType.Outgoing, { @@ -128,24 +118,18 @@ export class FlowService { metricType: FlowMetricType, metricQuery?: MetricQuery, ): Promise { - const contract = await this.contractService.findById(context.contractId); - + const { contract } = context; const { conversionFactor } = contract; - const contractContext = { - ...context, - contract, - }; - const [incoming, outgoing] = await Promise.all([ this.receiptActionService.getHistory( - contractContext, + context, metricType, TransferType.Incoming, metricQuery, ), this.receiptActionService.getHistory( - contractContext, + context, metricType, TransferType.Outgoing, metricQuery, @@ -187,17 +171,12 @@ export class FlowService { context: DaoContractContext | ContractContext, metricType: FlowMetricType, ): Promise { + const { contract } = context; + const weekAgo = moment().subtract(7, 'days'); const days = getDailyIntervals(weekAgo.valueOf(), moment().valueOf()); const dayAgo = moment().subtract(1, 'days'); - const contract = await this.contractService.findById(context.contractId); - - const contractContext = { - ...context, - contract, - }; - const [ byDaysIncoming, byDaysOutgoing, @@ -207,7 +186,7 @@ export class FlowService { outgoing, ] = await Promise.all([ this.receiptActionService.getLeaderboard( - contractContext, + context, metricType, TransferType.Incoming, { @@ -217,7 +196,7 @@ export class FlowService { true, ), this.receiptActionService.getLeaderboard( - contractContext, + context, metricType, TransferType.Outgoing, { @@ -227,7 +206,7 @@ export class FlowService { true, ), this.receiptActionService.getLeaderboard( - contractContext, + context, metricType, TransferType.Incoming, { @@ -235,7 +214,7 @@ export class FlowService { }, ), this.receiptActionService.getLeaderboard( - contractContext, + context, metricType, TransferType.Incoming, { @@ -243,7 +222,7 @@ export class FlowService { }, ), this.receiptActionService.getLeaderboard( - contractContext, + context, metricType, TransferType.Outgoing, { @@ -251,7 +230,7 @@ export class FlowService { }, ), this.receiptActionService.getLeaderboard( - contractContext, + context, metricType, TransferType.Outgoing, { diff --git a/apps/api/src/general/general.controller.ts b/apps/api/src/general/general.controller.ts index 61bcc58..fe6834f 100644 --- a/apps/api/src/general/general.controller.ts +++ b/apps/api/src/general/general.controller.ts @@ -10,7 +10,7 @@ import { } from '@dao-stats/common'; import { GeneralTotalResponse } from './dto'; import { GeneralService } from './general.service'; -import { MetricQueryPipe } from '../pipes'; +import { ContractContextPipe, MetricQueryPipe } from '../pipes'; import { HasDaoContractContext } from '../decorators'; @ApiTags('General') @@ -27,7 +27,7 @@ export class GeneralController { }) @Get('/') async totals( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.generalService.totals(context); } @@ -41,7 +41,7 @@ export class GeneralController { }) @Get('/daos') async daos( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.generalService.daos(context, metricQuery); @@ -56,7 +56,7 @@ export class GeneralController { }) @Get('/active') async active( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.generalService.active(context, metricQuery); @@ -71,7 +71,7 @@ export class GeneralController { }) @Get('/active/leaderboard') async activeLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.generalService.activeLeaderboard(context); } @@ -85,7 +85,7 @@ export class GeneralController { }) @Get('/groups') async groups( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.generalService.groups(context, metricQuery); @@ -100,7 +100,7 @@ export class GeneralController { }) @Get('/groups/leaderboard') async groupsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.generalService.groupsLeaderboard(context); } @@ -114,7 +114,7 @@ export class GeneralController { }) @Get('/average-groups') async averageGroups( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.generalService.averageGroups(context, metricQuery); @@ -130,7 +130,7 @@ export class GeneralController { @HasDaoContractContext() @Get('/:dao') async daoTotals( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, ): Promise { return this.generalService.totals(context); } @@ -145,7 +145,7 @@ export class GeneralController { @HasDaoContractContext() @Get('/:dao/activity') async daoActivity( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.generalService.active(context, metricQuery); @@ -161,7 +161,7 @@ export class GeneralController { @HasDaoContractContext() @Get('/:dao/groups') async daoGroups( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.generalService.groups(context, metricQuery); diff --git a/apps/api/src/governance/governance.controller.ts b/apps/api/src/governance/governance.controller.ts index 0d21799..a8f7d7d 100644 --- a/apps/api/src/governance/governance.controller.ts +++ b/apps/api/src/governance/governance.controller.ts @@ -16,7 +16,7 @@ import { VoteRateLeaderboardResponse, } from './dto'; import { GovernanceService } from './governance.service'; -import { MetricQueryPipe } from '../pipes'; +import { ContractContextPipe, MetricQueryPipe } from '../pipes'; import { HasDaoContractContext } from '../decorators'; @ApiTags('Governance') @@ -33,7 +33,7 @@ export class GovernanceController { }) @Get('/') async totals( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.governanceService.totals(context); } @@ -47,7 +47,7 @@ export class GovernanceController { }) @Get('/proposals') async proposals( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.governanceService.proposals(context, metricQuery); @@ -62,7 +62,7 @@ export class GovernanceController { }) @Get('/proposals/leaderboard') async proposalsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.governanceService.proposalsLeaderboard(context); } @@ -76,7 +76,7 @@ export class GovernanceController { }) @Get('/proposals-types') async proposalsTypes( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.governanceService.proposalsTypes(context, metricQuery); @@ -91,7 +91,7 @@ export class GovernanceController { }) @Get('/proposals-types/leaderboard') async proposalsTypesLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.governanceService.proposalsTypesLeaderboard(context); } @@ -105,7 +105,7 @@ export class GovernanceController { }) @Get('/vote-rate') async rate( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.governanceService.voteRate(context, metricQuery); @@ -120,7 +120,7 @@ export class GovernanceController { }) @Get('/vote-rate/leaderboard') async rateLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.governanceService.voteRateLeaderboard(context); } @@ -135,7 +135,7 @@ export class GovernanceController { @HasDaoContractContext() @Get('/:dao') async daoTotals( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, ): Promise { return this.governanceService.totals(context); } @@ -150,7 +150,7 @@ export class GovernanceController { @HasDaoContractContext() @Get('/:dao/proposals') async daoProposals( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.governanceService.proposals(context, metricQuery); @@ -166,7 +166,7 @@ export class GovernanceController { @HasDaoContractContext() @Get('/:dao/proposals-types') async daoProposalsTypes( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.governanceService.proposalsTypes(context, metricQuery); @@ -182,7 +182,7 @@ export class GovernanceController { @HasDaoContractContext() @Get('/:dao/vote-rate') async daoRate( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.governanceService.voteRate(context, metricQuery); diff --git a/apps/api/src/pipes/contract-context.pipe.ts b/apps/api/src/pipes/contract-context.pipe.ts new file mode 100644 index 0000000..1e9f1c5 --- /dev/null +++ b/apps/api/src/pipes/contract-context.pipe.ts @@ -0,0 +1,13 @@ +import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common'; +import { ContractContext } from '@dao-stats/common'; +import { RequestContext } from '@medibloc/nestjs-request-context'; + +@Injectable() +export class ContractContextPipe implements PipeTransform { + async transform(context: ContractContext, metadata: ArgumentMetadata) { + return { + ...context, + ...RequestContext.get(), + }; + } +} diff --git a/apps/api/src/pipes/index.ts b/apps/api/src/pipes/index.ts index f8d3105..69198da 100644 --- a/apps/api/src/pipes/index.ts +++ b/apps/api/src/pipes/index.ts @@ -1 +1,2 @@ export * from './metric-query.pipe'; +export * from './contract-context.pipe'; diff --git a/apps/api/src/tokens/tokens.controller.ts b/apps/api/src/tokens/tokens.controller.ts index 128a942..0906826 100644 --- a/apps/api/src/tokens/tokens.controller.ts +++ b/apps/api/src/tokens/tokens.controller.ts @@ -11,7 +11,7 @@ import { import { TokensTotalResponse } from './dto'; import { TokensService } from './tokens.service'; -import { MetricQueryPipe } from '../pipes'; +import { ContractContextPipe, MetricQueryPipe } from '../pipes'; import { HasDaoContractContext } from '../decorators'; @ApiTags('Tokens') @@ -28,7 +28,7 @@ export class TokensController { }) @Get('/') async totals( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.tokensService.totals(context); } @@ -42,7 +42,7 @@ export class TokensController { }) @Get('/fts') async fts( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tokensService.fts(context, metricQuery); @@ -57,7 +57,7 @@ export class TokensController { }) @Get('/fts/leaderboard') async ftsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.tokensService.ftsLeaderboard(context); } @@ -71,7 +71,7 @@ export class TokensController { }) @Get('/fts-vl') async ftsValueLocked( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tokensService.ftsValueLocked(context, metricQuery); @@ -86,7 +86,7 @@ export class TokensController { }) @Get('/fts-vl/leaderboard') async ftsValueLockedLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.tokensService.ftsValueLockedLeaderboard(context); } @@ -100,7 +100,7 @@ export class TokensController { }) @Get('/nfts') async nfts( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tokensService.nfts(context, metricQuery); @@ -115,7 +115,7 @@ export class TokensController { }) @Get('/nfts/leaderboard') async nftsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.tokensService.nftsLeaderboard(context); } @@ -130,7 +130,7 @@ export class TokensController { @HasDaoContractContext() @Get('/:dao') async daoTotals( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, ): Promise { return this.tokensService.totals(context); } @@ -145,7 +145,7 @@ export class TokensController { @HasDaoContractContext() @Get('/:dao/fts') async daoFts( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tokensService.fts(context, metricQuery); @@ -160,7 +160,7 @@ export class TokensController { }) @Get('/:dao/fts-vl') async daoFtsValueLocked( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tokensService.ftsValueLocked(context, metricQuery); @@ -176,7 +176,7 @@ export class TokensController { @HasDaoContractContext() @Get('/:dao/nfts') async daoNfts( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tokensService.nfts(context, metricQuery); diff --git a/apps/api/src/tvl/tvl.controller.ts b/apps/api/src/tvl/tvl.controller.ts index 8865d7c..1a868b8 100644 --- a/apps/api/src/tvl/tvl.controller.ts +++ b/apps/api/src/tvl/tvl.controller.ts @@ -11,7 +11,7 @@ import { import { TvlTotalResponse, TvlDaoTotalResponse } from './dto'; import { TvlService } from './tvl.service'; -import { MetricQueryPipe } from '../pipes'; +import { ContractContextPipe, MetricQueryPipe } from '../pipes'; import { HasDaoContractContext } from '../decorators'; @ApiTags('TVL') @@ -27,7 +27,9 @@ export class TvlController { description: 'Bad Request Response based on the query params set', }) @Get('/') - async totals(@Param() context: ContractContext): Promise { + async totals( + @Param(ContractContextPipe) context: ContractContext, + ): Promise { return this.tvlService.totals(context); } @@ -40,7 +42,7 @@ export class TvlController { }) @Get('/tvl') async tvl( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tvlService.tvl(context, metricQuery); @@ -55,7 +57,7 @@ export class TvlController { }) @Get('/tvl/leaderboard') async tvlLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.tvlService.tvlLeaderboard(context); } @@ -69,7 +71,7 @@ export class TvlController { }) @Get('/avg-tvl') async avgTvl( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tvlService.avgTvl(context, metricQuery); @@ -84,7 +86,7 @@ export class TvlController { }) @Get('/bounties-and-grants-vl') async bountiesAndGrants( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tvlService.bountiesAndGrantsValueLocked(context, metricQuery); @@ -99,7 +101,7 @@ export class TvlController { }) @Get('/bounties-and-grants-vl/leaderboard') async bountiesAndGrantsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.tvlService.bountiesAndGrantsValueLockedLeaderboard(context); } @@ -114,7 +116,7 @@ export class TvlController { @HasDaoContractContext() @Get('/:dao') async daoTotals( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, ): Promise { return this.tvlService.daoTotals(context); } @@ -129,7 +131,7 @@ export class TvlController { @HasDaoContractContext() @Get('/:dao/bounties/number') async daoBountiesNumber( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tvlService.bountiesNumber(context, metricQuery); @@ -145,7 +147,7 @@ export class TvlController { @HasDaoContractContext() @Get('/:dao/bounties/vl') async daoBountiesValueLocked( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.tvlService.bountiesValueLocked(context, metricQuery); diff --git a/apps/api/src/users/users.controller.ts b/apps/api/src/users/users.controller.ts index 8c8a0af..f5f2377 100644 --- a/apps/api/src/users/users.controller.ts +++ b/apps/api/src/users/users.controller.ts @@ -10,7 +10,7 @@ import { } from '@dao-stats/common'; import { UsersTotalResponse } from './dto'; import { UsersService } from './users.service'; -import { MetricQueryPipe } from '../pipes'; +import { ContractContextPipe, MetricQueryPipe } from '../pipes'; import { HasDaoContractContext } from '../decorators'; @ApiTags('Users') @@ -26,7 +26,9 @@ export class UsersController { description: 'Bad Request Response based on the query params set', }) @Get('/') - async totals(@Param() context: ContractContext): Promise { + async totals( + @Param(ContractContextPipe) context: ContractContext, + ): Promise { return this.usersService.totals(context); } @@ -39,7 +41,7 @@ export class UsersController { }) @Get('/users') async users( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.users(context, metricQuery); @@ -54,7 +56,7 @@ export class UsersController { }) @Get('/users/leaderboard') async usersLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.usersService.usersLeaderboard(context); } @@ -68,7 +70,7 @@ export class UsersController { }) @Get('/members') async members( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.members(context, metricQuery); @@ -83,7 +85,7 @@ export class UsersController { }) @Get('/members/leaderboard') async membersLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.usersService.membersLeaderboard(context); } @@ -97,7 +99,7 @@ export class UsersController { }) @Get('/average-users') async averageUsers( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.averageUsers(context, metricQuery); @@ -112,7 +114,7 @@ export class UsersController { }) @Get('/interactions') async interactions( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.interactions(context, metricQuery); @@ -127,7 +129,7 @@ export class UsersController { }) @Get('/interactions/leaderboard') async interactionsLeaderboard( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, ): Promise { return this.usersService.interactionsLeaderboard(context); } @@ -141,7 +143,7 @@ export class UsersController { }) @Get('/average-interactions') async interactionsAverage( - @Param() context: ContractContext, + @Param(ContractContextPipe) context: ContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.averageInteractions(context, metricQuery); @@ -157,7 +159,7 @@ export class UsersController { @HasDaoContractContext() @Get('/:dao') async daoTotals( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, ): Promise { return this.usersService.totals(context); } @@ -172,7 +174,7 @@ export class UsersController { @HasDaoContractContext() @Get('/:dao/users') async daoUsers( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.users(context, metricQuery); @@ -188,7 +190,7 @@ export class UsersController { @HasDaoContractContext() @Get('/:dao/members') async daoMembers( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.members(context, metricQuery); @@ -204,7 +206,7 @@ export class UsersController { @HasDaoContractContext() @Get('/:dao/interactions') async daoInteractions( - @Param() context: DaoContractContext, + @Param(ContractContextPipe) context: DaoContractContext, @Query(MetricQueryPipe) metricQuery: MetricQuery, ): Promise { return this.usersService.interactions(context, metricQuery); diff --git a/libs/near-indexer/src/near-indexer.service.ts b/libs/near-indexer/src/near-indexer.service.ts index 5e91e42..c619149 100644 --- a/libs/near-indexer/src/near-indexer.service.ts +++ b/libs/near-indexer/src/near-indexer.service.ts @@ -46,10 +46,10 @@ export class NearIndexerService { new Brackets((qb) => qb .where(`receipt_action.receipt_predecessor_account_id LIKE :id`, { - id: `%${accountIds}`, + id: `%.${accountIds}`, }) .orWhere(`receipt_action.receipt_receiver_account_id LIKE :id`, { - id: `%${accountIds}`, + id: `%.${accountIds}`, }), ), ); diff --git a/libs/transaction/src/transaction.service.ts b/libs/transaction/src/transaction.service.ts index 220a697..255bf00 100644 --- a/libs/transaction/src/transaction.service.ts +++ b/libs/transaction/src/transaction.service.ts @@ -212,7 +212,8 @@ export class TransactionService { context: DaoContractContext | ContractContext, metricQuery?: MetricQuery, ): SelectQueryBuilder { - const { contractId, dao } = context as DaoContractContext; + const { contract, dao } = context as DaoContractContext; + const { contractId, contractName } = contract; const { from, to } = metricQuery || {}; const qb = this.transactionRepository.createQueryBuilder(); @@ -221,6 +222,8 @@ export class TransactionService { if (dao) { qb.andWhere('receiver_account_id = :dao', { dao }); + } else { + qb.andWhere('receiver_account_id like :id', { id: `%.${contractName}` }); } if (from) {