Skip to content

Commit

Permalink
Merge pull request #1370 from multiversx/SERVICES-2457-previous-24-h-…
Browse files Browse the repository at this point in the history
…data-for-pairs-liquidity-fees-and-volume

[SERVICES-2457] Extra fields on Pair model for previous 24h data (fees, volume, liquidity)
  • Loading branch information
mad2sm0key committed Jun 18, 2024
2 parents c9e5a40 + 57de8f3 commit 11dd10b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/modules/pair/models/pair.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class PairModel {
@Field()
lockedValueUSD: string;

@Field()
previous24hLockedValueUSD: string;

@Field()
firstTokenVolume24h: string;

Expand All @@ -88,9 +91,15 @@ export class PairModel {
@Field()
volumeUSD24h: string;

@Field()
previous24hVolumeUSD: string;

@Field()
feesUSD24h: string;

@Field()
previous24hFeesUSD: string;

@Field()
feesAPR: string;

Expand Down
17 changes: 17 additions & 0 deletions src/modules/pair/pair.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export class PairResolver {
return this.pairCompute.lockedValueUSD(parent.address);
}

@ResolveField()
async previous24hLockedValueUSD(
@Parent() parent: PairModel,
): Promise<string> {
return this.pairCompute.previous24hLockedValueUSD(parent.address);
}

@ResolveField()
async firstTokenVolume24h(@Parent() parent: PairModel): Promise<string> {
return this.pairCompute.firstTokenVolume(parent.address, '24h');
Expand All @@ -113,11 +120,21 @@ export class PairResolver {
return this.pairCompute.volumeUSD(parent.address, '24h');
}

@ResolveField()
async previous24hVolumeUSD(@Parent() parent: PairModel): Promise<string> {
return this.pairCompute.previous24hVolumeUSD(parent.address);
}

@ResolveField()
async feesUSD24h(@Parent() parent: PairModel): Promise<string> {
return this.pairCompute.feesUSD(parent.address, '24h');
}

@ResolveField()
async previous24hFeesUSD(@Parent() parent: PairModel): Promise<string> {
return this.pairCompute.previous24hFeesUSD(parent.address);
}

@ResolveField()
async feesAPR(@Parent() parent: PairModel): Promise<string> {
return this.pairCompute.feesAPR(parent.address);
Expand Down
63 changes: 63 additions & 0 deletions src/modules/pair/services/pair.compute.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,29 @@ export class PairComputeService implements IPairComputeService {
);
}

@ErrorLoggerAsync({
logArgs: true,
})
@GetOrSetCache({
baseKey: 'pair',
remoteTtl: CacheTtlInfo.ContractInfo.remoteTtl,
localTtl: CacheTtlInfo.ContractInfo.localTtl,
})
async previous24hLockedValueUSD(pairAddress: string): Promise<string> {
return await this.computePrevious24hLockedValueUSD(pairAddress);
}

async computePrevious24hLockedValueUSD(
pairAddress: string,
): Promise<string> {
const values24h = await this.analyticsQuery.getValues24h({
series: pairAddress,
metric: 'lockedValueUSD',
});

return values24h[0]?.value ?? undefined;
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand Down Expand Up @@ -413,6 +436,26 @@ export class PairComputeService implements IPairComputeService {
});
}

@ErrorLoggerAsync({
logArgs: true,
})
@GetOrSetCache({
baseKey: 'pair',
remoteTtl: CacheTtlInfo.Analytics.remoteTtl,
localTtl: CacheTtlInfo.Analytics.localTtl,
})
async previous24hVolumeUSD(pairAddress: string): Promise<string> {
return await this.computePrevious24hVolumeUSD(pairAddress);
}

async computePrevious24hVolumeUSD(pairAddress: string): Promise<string> {
const [volume24h, volume48h] = await Promise.all([
this.volumeUSD(pairAddress, '24h'),
this.volumeUSD(pairAddress, '48h'),
]);
return new BigNumber(volume48h).minus(volume24h).toFixed();
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand All @@ -437,6 +480,26 @@ export class PairComputeService implements IPairComputeService {
});
}

@ErrorLoggerAsync({
logArgs: true,
})
@GetOrSetCache({
baseKey: 'pair',
remoteTtl: CacheTtlInfo.Analytics.remoteTtl,
localTtl: CacheTtlInfo.Analytics.localTtl,
})
async previous24hFeesUSD(pairAddress: string): Promise<string> {
return await this.computePrevious24hFeesUSD(pairAddress);
}

async computePrevious24hFeesUSD(pairAddress: string): Promise<string> {
const [fees24h, fees48h] = await Promise.all([
this.feesUSD(pairAddress, '24h'),
this.feesUSD(pairAddress, '48h'),
]);
return new BigNumber(fees48h).minus(fees24h).toFixed();
}

@ErrorLoggerAsync({
logArgs: true,
})
Expand Down

0 comments on commit 11dd10b

Please sign in to comment.