Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat, test: store and log classic blockNumber #522

Merged
merged 4 commits into from
Feb 10, 2025
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
1 change: 1 addition & 0 deletions lib/entities/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type SharedXOrderEntity = {
settledAmounts?: SettledAmount[]
referencePrice?: string
priceImpact?: number
blockNumber?: number
route?: Route
pair?: string
}
Expand Down
1 change: 1 addition & 0 deletions lib/handlers/get-unimind/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const unimindQueryParamsSchema = Joi.object({
pair: Joi.string().required(),
referencePrice: Joi.string().required(),
priceImpact: Joi.number().required(),
blockNumber: Joi.number().optional(),
route: Joi.string()
.optional()
.custom((value, helpers) => {
Expand Down
1 change: 1 addition & 0 deletions lib/models/PriorityOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class PriorityOrder extends Order {
createdAt: this.createdAt,
referencePrice: quoteMetadata?.referencePrice,
priceImpact: quoteMetadata?.priceImpact,
blockNumber: quoteMetadata?.blockNumber,
route: quoteMetadata?.route,
pair: quoteMetadata?.pair,
}
Expand Down
1 change: 1 addition & 0 deletions lib/repositories/dutch-orders-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class DutchOrdersRepository extends GenericOrdersRepository<string, strin
cosigner: { type: DYNAMODB_TYPES.STRING },
referencePrice: { type: DYNAMODB_TYPES.STRING },
priceImpact: { type: DYNAMODB_TYPES.NUMBER },
blockNumber: { type: DYNAMODB_TYPES.NUMBER },
route: { type: DYNAMODB_TYPES.MAP },
pair: { type: DYNAMODB_TYPES.STRING },

Expand Down
2 changes: 2 additions & 0 deletions lib/repositories/quote-metadata-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface QuoteMetadata {
quoteId: string
referencePrice: string
priceImpact: number
blockNumber: number
route: Route
pair: string
}
Expand Down Expand Up @@ -54,6 +55,7 @@ export class DynamoQuoteMetadataRepository implements QuoteMetadataRepository {
referencePrice: { type: DYNAMODB_TYPES.STRING, required: true },
priceImpact: { type: DYNAMODB_TYPES.NUMBER, required: true },
pair: {type: DYNAMODB_TYPES.STRING, required: true},
blockNumber: {type: DYNAMODB_TYPES.NUMBER, required: false},
route: {type: DYNAMODB_TYPES.MAP, required: false}
},
table,
Expand Down
1 change: 1 addition & 0 deletions lib/services/analytics-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class AnalyticsService implements AnalyticsServiceInterface {
tokenIn: order.input?.token,
tokenOut: order.outputs[0].token,
orderType: orderType,
blockNumber: order?.blockNumber,
route: JSON.stringify(order?.route),
}

Expand Down
26 changes: 25 additions & 1 deletion test/unit/handlers/get-unimind/get-unimind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ describe('Testing get unimind handler', () => {
referencePrice: '4221.21',
priceImpact: 0.01,
pair: 'ETH-USDC',
blockNumber: 1234,
// missing route
}

Expand All @@ -432,4 +433,27 @@ describe('Testing get unimind handler', () => {
expect(mockQuoteMetadataRepo.put).toHaveBeenCalledTimes(1)
expect(mockUnimindParametersRepo.getByPair).toHaveBeenCalledTimes(1)
})
})

it('blockNumber is optional', async () => {
const quoteMetadata = {
quoteId: 'test-quote-id',
referencePrice: '4221.21',
priceImpact: 0.01,
pair: 'ETH-USDC',
// missing blockNumber
route: STRINGIFIED_ROUTE,
}

const response = await getUnimindHandler.handler(
{
queryStringParameters: quoteMetadata,
requestContext: { requestId: 'test-request-id' }
} as any,
EVENT_CONTEXT
)

expect(response.statusCode).toBe(200)
expect(mockQuoteMetadataRepo.put).toHaveBeenCalledTimes(1)
expect(mockUnimindParametersRepo.getByPair).toHaveBeenCalledTimes(1)
})
})
1 change: 1 addition & 0 deletions test/unit/handlers/post-order/post-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const SAMPLE_QUOTE_METADATA = {
referencePrice: '4221.21',
priceImpact: 0.01,
pair: 'ETH-USDC',
blockNumber: 123456,
route: {
quote: '1234',
quote_gas_adjusted: '5678',
Expand Down
1 change: 1 addition & 0 deletions test/unit/repositories/quote-metadata-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('QuoteMetadataRepository', () => {
quoteId: 'test-quote-id',
referencePrice: "21212121",
priceImpact: 0.21,
blockNumber: 123456,
route: {
quote: "1234",
quote_gas_adjusted: "5678",
Expand Down
Loading