Skip to content

Commit

Permalink
Improve TWAP order mapping with activeOrderUid (#1785)
Browse files Browse the repository at this point in the history
Adds a new `activeOrderUid` to the `TwapOrderTransactionInfo`, calculating the status from it:

- Add `activeOrderUid` to `TwapOrderTransactionInfo`.
- Fetch status relative to `activeOrderUid`.
- Add appropriate test coverage.
  • Loading branch information
iamacook authored Jul 30, 2024
1 parent b6d4e44 commit 1519f67
Show file tree
Hide file tree
Showing 5 changed files with 985 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
@ApiProperty({ enum: OrderClass })
class: OrderClass.Limit;

@ApiProperty({
description:
'The order UID of the active order, null as it is not an active order',
})
activeOrderUid: null;

@ApiProperty({ description: 'The timestamp when the TWAP expires' })
validUntil: number;

Expand Down Expand Up @@ -278,6 +284,7 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
status: OrderStatus;
kind: OrderKind.Sell;
class: OrderClass.Limit;
activeOrderUid: null;
validUntil: number;
sellAmount: string;
buyAmount: string;
Expand All @@ -301,6 +308,7 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
this.status = args.status;
this.kind = args.kind;
this.class = args.class;
this.activeOrderUid = args.activeOrderUid;
this.validUntil = args.validUntil;
this.sellAmount = args.sellAmount;
this.buyAmount = args.buyAmount;
Expand Down
11 changes: 10 additions & 1 deletion src/routes/transactions/entities/swaps/twap-order-info.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type StartTime =
export type TwapOrderInfo = {
status: OrderStatus;
kind: OrderKind.Sell;
activeOrderUid: `0x${string}` | null;
class: OrderClass.Limit;
validUntil: number;
sellAmount: string;
Expand Down Expand Up @@ -71,9 +72,15 @@ export class TwapOrderTransactionInfo
@ApiProperty({ enum: OrderKind })
kind: OrderKind.Sell;

@ApiProperty({ enum: OrderClass })
@ApiPropertyOptional({ enum: OrderClass })
class: OrderClass.Limit;

@ApiProperty({
nullable: true,
description: 'The order UID of the active order, or null if none is active',
})
activeOrderUid: `0x${string}` | null;

@ApiProperty({ description: 'The timestamp when the TWAP expires' })
validUntil: number;

Expand Down Expand Up @@ -164,6 +171,7 @@ export class TwapOrderTransactionInfo
constructor(args: {
status: OrderStatus;
kind: OrderKind.Sell;
activeOrderUid: `0x${string}` | null;
class: OrderClass.Limit;
validUntil: number;
sellAmount: string;
Expand All @@ -187,6 +195,7 @@ export class TwapOrderTransactionInfo
this.status = args.status;
this.kind = args.kind;
this.class = args.class;
this.activeOrderUid = args.activeOrderUid;
this.validUntil = args.validUntil;
this.sellAmount = args.sellAmount;
this.buyAmount = args.buyAmount;
Expand Down
Loading

0 comments on commit 1519f67

Please sign in to comment.