Skip to content
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
7,030 changes: 1,147 additions & 5,883 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
"typescript-eslint": "^8.20.0",
"winston": "^3.19.0"
},
"jest": {
"moduleFileExtensions": [
Expand Down
22 changes: 11 additions & 11 deletions src/analytics/analytics.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AnalyticsService } from './analytics.service';
import { AnalyticsData } from './entities/analytics-data.entity';
import { AnalyticsData, AnalyticsType, AggregationPeriod } from './entities/analytics-data.entity';
import { ReportParamsDto } from './dto/report-params.dto';
import { TradingVolumeReport } from './reports/trading-volume.report';
import { PriceTrendsReport } from './reports/price-trends.report';
Expand Down Expand Up @@ -82,8 +82,8 @@ describe('AnalyticsService', () => {
describe('generateTradingVolumeReport', () => {
it('should generate trading volume report', async () => {
const params: ReportParamsDto = {
type: 'trading_volume',
period: 'daily',
type: AnalyticsType.TRADING_VOLUME,
period: AggregationPeriod.DAILY,
};

const expectedReport = {
Expand Down Expand Up @@ -116,8 +116,8 @@ describe('AnalyticsService', () => {
describe('generatePriceTrendsReport', () => {
it('should generate price trends report', async () => {
const params: ReportParamsDto = {
type: 'price_trend',
period: 'daily',
type: AnalyticsType.PRICE_TREND,
period: AggregationPeriod.DAILY,
};

const expectedReport = {
Expand Down Expand Up @@ -151,8 +151,8 @@ describe('AnalyticsService', () => {
describe('generateUserPerformanceReport', () => {
it('should generate user performance report', async () => {
const params: ReportParamsDto = {
type: 'user_performance',
period: 'daily',
type: AnalyticsType.USER_PERFORMANCE,
period: AggregationPeriod.DAILY,
userId: 'user-123',
};

Expand Down Expand Up @@ -194,8 +194,8 @@ describe('AnalyticsService', () => {
describe('generateMarketEfficiencyReport', () => {
it('should generate market efficiency report', async () => {
const params: ReportParamsDto = {
type: 'market_efficiency',
period: 'daily',
type: AnalyticsType.MARKET_EFFICIENCY,
period: AggregationPeriod.DAILY,
};

const expectedReport = {
Expand Down Expand Up @@ -227,8 +227,8 @@ describe('AnalyticsService', () => {
describe('storeAnalyticsData', () => {
it('should store analytics data', async () => {
const analyticsData = {
type: 'trading_volume',
period: 'daily',
type: AnalyticsType.TRADING_VOLUME,
period: AggregationPeriod.DAILY,
timestamp: new Date(),
data: { volume: 100, value: 5000 },
};
Expand Down
28 changes: 14 additions & 14 deletions src/gas/dto/gas-estimate.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ export class BatchEstimateRequestDto {
maxBatchSize?: number = 10;
}

export class BatchingRecommendationDto {
@ApiProperty({ description: 'Whether batching is recommended' })
recommended: boolean;

@ApiProperty({ description: 'Estimated savings in stroops when batching' })
estimatedSavingsStroops: number;

@ApiProperty({ description: 'Savings percentage versus individual txns' })
savingsPercentage: number;

@ApiProperty({ description: 'Recommended batch size' })
recommendedBatchSize: number;
}

export class GasEstimateResponseDto {
@ApiProperty({ description: 'Stellar network this estimate applies to' })
network: ContractNetwork;
Expand Down Expand Up @@ -119,20 +133,6 @@ export class GasEstimateResponseDto {
batchingRecommendation?: BatchingRecommendationDto;
}

export class BatchingRecommendationDto {
@ApiProperty({ description: 'Whether batching is recommended' })
recommended: boolean;

@ApiProperty({ description: 'Estimated savings in stroops when batching' })
estimatedSavingsStroops: number;

@ApiProperty({ description: 'Savings percentage versus individual txns' })
savingsPercentage: number;

@ApiProperty({ description: 'Recommended batch size' })
recommendedBatchSize: number;
}

export class GasAnalyticsResponseDto {
@ApiProperty({ description: 'Network queried' })
network: ContractNetwork;
Expand Down
20 changes: 13 additions & 7 deletions src/location/algorithms/zone-mapping.algorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ export class ZoneMappingAlgorithm {
*/
static calculateZoneCentroid(zone: GridZone): Coordinates {
const coordinates = zone.boundaries.coordinates;

if (zone.boundaries.type === 'Polygon') {
return this.calculatePolygonCentroid(coordinates[0]);
const polygonCoordinates = coordinates as number[][][];
return this.calculatePolygonCentroid(polygonCoordinates[0]);
} else if (zone.boundaries.type === 'MultiPolygon') {
// For MultiPolygon, calculate the centroid of the first polygon
// In a real implementation, you might want to calculate the centroid
// of all polygons weighted by area
return this.calculatePolygonCentroid(coordinates[0][0]);
const multipolygonCoordinates = coordinates as number[][][][];
return this.calculatePolygonCentroid(multipolygonCoordinates[0][0]);
}

throw new Error('Unsupported boundary type');
Expand All @@ -93,9 +95,11 @@ export class ZoneMappingAlgorithm {
let totalArea = 0;

if (zone.boundaries.type === 'Polygon') {
totalArea = this.calculatePolygonArea(coordinates[0]);
const polygonCoordinates = coordinates as number[][][];
totalArea = this.calculatePolygonArea(polygonCoordinates[0]);
} else if (zone.boundaries.type === 'MultiPolygon') {
for (const polygon of coordinates) {
const multipolygonCoordinates = coordinates as number[][][][];
for (const polygon of multipolygonCoordinates) {
totalArea += this.calculatePolygonArea(polygon[0]);
}
}
Expand All @@ -110,10 +114,12 @@ export class ZoneMappingAlgorithm {
const coordinates = zone.boundaries.coordinates;

if (zone.boundaries.type === 'Polygon') {
return DistanceAlgorithm.isPointInPolygon(coordinate, coordinates[0]);
const polygonCoordinates = coordinates as number[][][];
return DistanceAlgorithm.isPointInPolygon(coordinate, polygonCoordinates[0]);
} else if (zone.boundaries.type === 'MultiPolygon') {
const multipolygonCoordinates = coordinates as number[][][][];
// Check if point is in any of the polygons
for (const polygon of coordinates) {
for (const polygon of multipolygonCoordinates) {
if (DistanceAlgorithm.isPointInPolygon(coordinate, polygon[0])) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/location/location.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class LocationService {

queryBuilder.skip(skip).take(limit);

const [locations, total] = await queryBuilder.getMany();
const [locations, total] = await queryBuilder.getManyAndCount();

return {
locations,
Expand Down
2 changes: 1 addition & 1 deletion src/pricing/algorithms/location-adjustment.algorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface LocationData {

@Injectable()
export class LocationAdjustmentAlgorithm {
private readonly logger = new Logger(LocationAdjustmentAlgorithm.class.name);
private readonly logger = new Logger(LocationAdjustmentAlgorithm.name);

private readonly locationDatabase: Map<string, LocationData> = new Map([
{
Expand Down
9 changes: 8 additions & 1 deletion src/webhooks/webhook.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ describe('WebhookService', () => {
generateSignature: jest.fn(),
verifySignature: jest.fn(),
signWebhook: jest.fn(),
generateTimestamp: jest.fn(() => Date.now()),
verifyTimestamp: jest.fn(() => true),
};

const mockEventFilterService = {
matchesFilters: jest.fn(),
matchesFilter: jest.fn(),
matchesObjectFilter: jest.fn(),
filterByEventType: jest.fn(),
filterByTimeRange: jest.fn(),
filterByAmount: jest.fn(),
};

beforeEach(async () => {
Expand Down Expand Up @@ -172,7 +179,7 @@ describe('WebhookService', () => {
mockWebhookRepository as any,
mockDeliveryRepository as any,
mockHmacAuthService,
mockEventFilterService,
mockEventFilterService as unknown as EventFilterService,
null as any,
);

Expand Down
3 changes: 2 additions & 1 deletion test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export const createClassMockProvider = <T>(
* Get service from testing module
*/
export const getService = <T>(module: any, token: any): T => {
return module.get<T>(token);
const service = module.get(token);
return service as T;
};

/**
Expand Down
Loading