Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export type PerpsControllerGetWithdrawalRoutesAction = {
};

/**
* Set the transient UTM / discovery attribution context (TAT-3133, TAT-3140).
* Set the transient UTM / discovery attribution context.
* Replaces any previously set context. Held in-memory only — not persisted.
*
* @param context - The attribution context (UTM fields) to store.
Expand All @@ -558,7 +558,7 @@ export type PerpsControllerSetAttributionContextAction = {
};

/**
* Get a copy of the current attribution context (TAT-3133, TAT-3140).
* Get a copy of the current attribution context.
*
* @returns A shallow copy of the stored attribution context.
*/
Expand All @@ -568,7 +568,7 @@ export type PerpsControllerGetAttributionContextAction = {
};

/**
* Clear the stored attribution context (TAT-3133, TAT-3140).
* Clear the stored attribution context.
*/
export type PerpsControllerClearAttributionContextAction = {
type: `PerpsController:clearAttributionContext`;
Expand Down
10 changes: 5 additions & 5 deletions packages/perps-controller/src/PerpsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ export class PerpsController extends BaseController<
readonly #priceDeviationLimit?: number;

/**
* Transient UTM / discovery attribution context (TAT-3133, TAT-3140).
* Transient UTM / discovery attribution context.
* Held in-memory only (never persisted in PerpsControllerState) and merged
* into analytics event properties via {@link mergeAttributionContext}.
*/
Expand Down Expand Up @@ -3865,7 +3865,7 @@ export class PerpsController extends BaseController<
}

/**
* Set the transient UTM / discovery attribution context (TAT-3133, TAT-3140).
* Set the transient UTM / discovery attribution context.
* Replaces any previously set context. Held in-memory only — not persisted.
*
* @param context - The attribution context (UTM fields) to store.
Expand All @@ -3875,7 +3875,7 @@ export class PerpsController extends BaseController<
}

/**
* Get a copy of the current attribution context (TAT-3133, TAT-3140).
* Get a copy of the current attribution context.
*
* @returns A shallow copy of the stored attribution context.
*/
Expand All @@ -3884,15 +3884,15 @@ export class PerpsController extends BaseController<
}

/**
* Clear the stored attribution context (TAT-3133, TAT-3140).
* Clear the stored attribution context.
*/
clearAttributionContext(): void {
this.#attributionContext = {};
}

/**
* Merge the stored UTM attribution context into a set of analytics event
* properties (TAT-3133, TAT-3140). Only defined UTM fields are added, mapped
* properties. Only defined UTM fields are added, mapped
* to their canonical PERPS_EVENT_PROPERTY keys. Provided properties take
* precedence and are never overwritten.
*
Expand Down
34 changes: 17 additions & 17 deletions packages/perps-controller/src/constants/eventNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const PERPS_EVENT_PROPERTY = {

// A/B testing properties (flat per test for multiple concurrent tests)
// Only include AB test properties when test is enabled (event not sent when disabled)
// Button color test (TAT-1937)
// Button color test
AB_TEST_BUTTON_COLOR: 'ab_test_button_color',
// Future tests: add as AB_TEST_{TEST_NAME} (no _ENABLED property needed)

Expand Down Expand Up @@ -179,31 +179,31 @@ export const PERPS_EVENT_PROPERTY = {
ABSTRACTION_MODE: 'abstraction_mode',
PREVIOUS_ABSTRACTION_MODE: 'previous_abstraction_mode',

// Entry point / discovery attribution (TAT-3080)
// Entry point / discovery attribution
ENTRY_POINT: 'entry_point',
DISCOVERY_SOURCE: 'discovery_source',
PERP_DISCOVERY_SOURCE: 'perp_discovery_source',

// UTM attribution context (TAT-3133, TAT-3140)
// UTM attribution context
UTM_SOURCE: 'utm_source',
UTM_MEDIUM: 'utm_medium',
UTM_CAMPAIGN: 'utm_campaign',
UTM_CONTENT: 'utm_content',
UTM_TERM: 'utm_term',

// Watchlist membership at event time (TAT-3148)
// Watchlist membership at event time
WATCHLISTED: 'watchlisted',

// HyperLiquid protocol fee rate on trade + close (TAT-3149)
// HyperLiquid protocol fee rate on trade + close
HL_FEE_RATE: 'hl_fee_rate',

// Bulk action correlation id for batch close/cancel (TAT-3150)
// Bulk action correlation id for batch close/cancel
BULK_ACTION_ID: 'bulk_action_id',

// Client environment (Extension supplies value) (TAT-3335)
// Client environment (Extension supplies value)
ENVIRONMENT_TYPE: 'environment_type',

// Order funnel / consideration + quote properties (TAT-3084)
// Order funnel / consideration + quote properties
ORDER_CONTEXT: 'order_context',
ORDER_SIZE_PERCENT: 'order_size_percent',
LIMIT_PRICE_INPUT_TYPE: 'limit_price_input_type',
Expand All @@ -224,19 +224,19 @@ export const PERPS_EVENT_PROPERTY = {
TO_TOKEN: 'to_token',
TO_CHAIN: 'to_chain',

// Search / discovery query properties (TAT-3144, TAT-3202, TAT-3151)
// Search / discovery query properties
SEARCH_QUERY: 'search_query',
RESULTS_COUNT: 'results_count',
RESULT_RANK: 'result_rank',
MODE: 'mode',
CURRENT_TOKEN: 'current_token',

// Sort / filter properties (TAT-3142)
// Sort / filter properties
SORT_FIELD: 'sort_field',
SORT_DIRECTION: 'sort_direction',
FILTER_CATEGORY: 'filter_category',

// Time-on-screen for abandon tracking (TAT-3136)
// Time-on-screen for abandon tracking
TIME_ON_SCREEN_MS: 'time_on_screen_ms',
} as const;

Expand Down Expand Up @@ -456,14 +456,14 @@ export const PERPS_EVENT_VALUE = {
SLIPPAGE_LIMIT_BLOCKED_ORDER: 'slippage_limit_blocked_order',
// Discovery analytics
MARKET_LIST_FILTER: 'market_list_filter',
// Sort / filter interactions (TAT-3142)
// Sort / filter interactions
SORT_APPLIED: 'sort_applied',
FILTER_APPLIED: 'filter_applied',
// Search interactions (TAT-3144, TAT-3202)
// Search interactions
SEARCH_RESULT_TAPPED: 'search_result_tapped',
SEARCH_CHIP_TAPPED: 'search_chip_tapped',
SEARCH_SIGNAL_TILE_TAPPED: 'search_signal_tile_tapped',
// Pay-with token selector dismissed (TAT-3151)
// Pay-with token selector dismissed
PAYMENT_TOKEN_SELECTOR_DISMISSED: 'payment_token_selector_dismissed',
},
MAX_SLIPPAGE_SOURCE: {
Expand Down Expand Up @@ -549,7 +549,7 @@ export const PERPS_EVENT_VALUE = {
COMPLIANCE_BLOCK_NOTIF: 'compliance_block_notif',
// Deposit + order (pay-with token) cancel toast
CANCEL_TRADE_WITH_TOKEN_TOAST: 'cancel_trade_with_token_toast',
// Search result screen states (TAT-3144)
// Search result screen states
SEARCH_RESULTS_SHOWN: 'search_results_shown',
SEARCH_NO_RESULTS: 'search_no_results',
},
Expand Down Expand Up @@ -584,7 +584,7 @@ export const PERPS_EVENT_VALUE = {
// Flip position actions with direction specificity
FLIP_LONG_TO_SHORT: 'flip_long_to_short',
FLIP_SHORT_TO_LONG: 'flip_short_to_long',
// Order funnel abandonment (TAT-3136)
// Order funnel abandonment
ABANDON_ORDER: 'abandon_order',
},
// Risk management sources
Expand Down Expand Up @@ -629,7 +629,7 @@ export const PERPS_EVENT_VALUE = {
WATCHLIST: 'watchlist',
TOP_MOVERS: 'top_movers',
WHATS_HAPPENING: 'whats_happening',
// Order + position management CTAs (TAT-3135, TAT-3141)
// Order + position management CTAs
PLACE_ORDER: 'place_order',
CLOSE: 'close',
REDUCE_EXPOSURE: 'reduce_exposure',
Expand Down
40 changes: 20 additions & 20 deletions packages/perps-controller/src/services/TradingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type TradingServiceControllerDeps = {

/**
* Subset of tracking data carrying discovery attribution + hl_fee_rate that is
* shared across trade/close/cancel/risk events (TAT-3080, TAT-3149). Both
* shared across trade/close/cancel/risk events. Both
* {@link TrackingData} and {@link TPSLTrackingData} satisfy this shape.
*/
type AttributionTrackingData = Pick<
Expand Down Expand Up @@ -115,7 +115,7 @@ export class TradingService {

/**
* Build discovery/attribution properties shared across trade/close/cancel/risk
* events (TAT-3080, TAT-3149). Each property is only included when present so
* events. Each property is only included when present so
* that, in particular, hl_fee_rate is omitted entirely when unavailable.
*
* @param trackingData - Optional tracking data carried on the operation params.
Expand Down Expand Up @@ -143,8 +143,8 @@ export class TradingService {
}

/**
* Emit a transaction event with status=submitted before the provider round-trip
* (TAT-3134). Fired for trade, close, cancel and risk-management operations.
* Emit a transaction event with status=submitted before the provider round-trip.
* Fired for trade, close, cancel and risk-management operations.
*
* @param event - The analytics event name to emit.
* @param properties - Additional event properties (asset, attribution, etc.).
Expand Down Expand Up @@ -299,7 +299,7 @@ export class TradingService {
properties[PERPS_EVENT_PROPERTY.AB_TESTS] = params.trackingData.abTests;
}

// Propagate discovery attribution + hl_fee_rate (TAT-3080, TAT-3149)
// Propagate discovery attribution + hl_fee_rate
Object.assign(
properties,
this.#buildAttributionProperties(params.trackingData),
Expand Down Expand Up @@ -513,7 +513,7 @@ export class TradingService {
},
);

// Emit submitted event before the provider round-trip (TAT-3134)
// Emit submitted event before the provider round-trip
this.#trackSubmitted(PerpsAnalyticsEvent.TradeTransaction, {
[PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
[PERPS_EVENT_PROPERTY.DIRECTION]: params.isBuy
Expand Down Expand Up @@ -836,11 +836,11 @@ export class TradingService {
...(params.trackingData?.vipDiscount !== undefined && {
[PERPS_EVENT_PROPERTY.VIP_DISCOUNT]: params.trackingData.vipDiscount,
}),
// Leverage on close events (TAT-3147)
// Leverage on close events
...(position.leverage?.value !== undefined && {
[PERPS_EVENT_PROPERTY.LEVERAGE]: position.leverage.value,
}),
// Discovery attribution + hl_fee_rate (TAT-3080, TAT-3149)
// Discovery attribution + hl_fee_rate
...this.#buildAttributionProperties(params.trackingData),
};

Expand Down Expand Up @@ -884,7 +884,7 @@ export class TradingService {
* @param options.params - The operation parameters.
* @param options.context - The service context for dependencies.
* @param options.duration - Optional time duration.
* @param options.bulkActionId - Optional batch correlation id (TAT-3150).
* @param options.bulkActionId - Optional batch correlation id.
*/
#trackPositionCloseResult(options: {
position: Position | undefined;
Expand All @@ -897,7 +897,7 @@ export class TradingService {
}): void {
const { position, result, error, params, duration, bulkActionId } = options;

// Bulk action correlation id for batch close events (TAT-3150)
// Bulk action correlation id for batch close events
const bulkActionProps: PerpsAnalyticsProperties = bulkActionId
? { [PERPS_EVENT_PROPERTY.BULK_ACTION_ID]: bulkActionId }
: {};
Expand Down Expand Up @@ -1248,7 +1248,7 @@ export class TradingService {
* @param options.provider - The perps provider instance.
* @param options.params - The operation parameters.
* @param options.context - The service context for dependencies.
* @param options.bulkActionId - Optional batch correlation id (TAT-3150).
* @param options.bulkActionId - Optional batch correlation id.
* @returns The result of the operation.
*/
async cancelOrder(options: {
Expand All @@ -1264,7 +1264,7 @@ export class TradingService {
| { success: boolean; error?: string; orderId?: string }
| undefined;

// Shared attribution + bulk correlation props (TAT-3080, TAT-3150)
// Shared attribution + bulk correlation props
const cancelExtraProps: PerpsAnalyticsProperties = {
...this.#buildAttributionProperties(params.trackingData),
...(bulkActionId && {
Expand All @@ -1288,7 +1288,7 @@ export class TradingService {
},
});

// Emit submitted event before the provider round-trip (TAT-3134)
// Emit submitted event before the provider round-trip
this.#trackSubmitted(PerpsAnalyticsEvent.OrderCancelTransaction, {
[PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
...cancelExtraProps,
Expand Down Expand Up @@ -1402,7 +1402,7 @@ export class TradingService {
}): Promise<CancelOrdersResult> {
const { provider, params, context, withStreamPause } = options;
const traceId = uuidv4();
// Correlation id linking every per-item event to the batch summary (TAT-3150)
// Correlation id linking every per-item event to the batch summary
const bulkActionId = uuidv4();
const startTime = this.#deps.performance.now();
let operationResult: CancelOrdersResult | null = null;
Expand Down Expand Up @@ -1591,7 +1591,7 @@ export class TradingService {
* @param options.params - The operation parameters.
* @param options.context - The service context for dependencies.
* @param options.reportOrderToDataLake - The report order to data lake value.
* @param options.bulkActionId - Optional batch correlation id (TAT-3150).
* @param options.bulkActionId - Optional batch correlation id.
* @returns The result of the operation.
*/
async closePosition(options: {
Expand Down Expand Up @@ -1633,7 +1633,7 @@ export class TradingService {
context,
});

// Emit submitted event before the provider round-trip (TAT-3134)
// Emit submitted event before the provider round-trip
this.#trackSubmitted(PerpsAnalyticsEvent.PositionCloseTransaction, {
[PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
[PERPS_EVENT_PROPERTY.ORDER_TYPE]:
Expand Down Expand Up @@ -1764,7 +1764,7 @@ export class TradingService {
}): Promise<ClosePositionsResult> {
const { provider, params, context } = options;
const traceId = uuidv4();
// Correlation id linking every per-item event to the batch summary (TAT-3150)
// Correlation id linking every per-item event to the batch summary
const bulkActionId = uuidv4();
const startTime = this.#deps.performance.now();
let operationResult: ClosePositionsResult | null = null;
Expand Down Expand Up @@ -1996,7 +1996,7 @@ export class TradingService {
},
});

// Emit submitted event before the provider round-trip (TAT-3134)
// Emit submitted event before the provider round-trip
this.#trackSubmitted(PerpsAnalyticsEvent.RiskManagement, {
[PERPS_EVENT_PROPERTY.ASSET]: params.symbol,
[PERPS_EVENT_PROPERTY.SOURCE]: source,
Expand Down Expand Up @@ -2105,7 +2105,7 @@ export class TradingService {
...(errorMessage && {
[PERPS_EVENT_PROPERTY.ERROR_MESSAGE]: errorMessage,
}),
// Discovery attribution (TAT-3080)
// Discovery attribution
...this.#buildAttributionProperties(params.trackingData),
};

Expand Down Expand Up @@ -2328,7 +2328,7 @@ export class TradingService {
[PERPS_EVENT_PROPERTY.COMPLETION_DURATION]: completionDuration,
[PERPS_EVENT_PROPERTY.ACTION]: flipAction,
[PERPS_EVENT_PROPERTY.ORDER_VALUE]: positionSize * executedPrice,
// MetaMask fee on flip trades (TAT-3146)
// MetaMask fee on flip trades
...(trackingData?.metamaskFee !== undefined && {
[PERPS_EVENT_PROPERTY.METAMASK_FEE]: trackingData.metamaskFee,
}),
Expand Down
Loading
Loading