Skip to content
Closed
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
5 changes: 5 additions & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `has_gas_included_quote` property to `QuoteFetchData` type and compute it in `QuotesReceived` event to indicate if any received quote has gas included
- Add optional `usd_balance_source` property to `QuotesReceived` event and `getQuotesReceivedProperties` utility to allow clients to pass the source token balance in USD

### Changed

- Bump `@metamask/controller-utils` from `^11.17.0` to `^11.18.0` ([#7583](https://github.com/MetaMask/core/pull/7583))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Array [
"error_message": "error_message",
"gas_included": false,
"gas_included_7702": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 0,
"is_hardware_wallet": false,
"price_impact": 0,
Expand Down Expand Up @@ -141,6 +142,7 @@ Array [
"error_message": "Failed to submit tx",
"gas_included": false,
"gas_included_7702": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 0,
"is_hardware_wallet": false,
"price_impact": 12,
Expand Down Expand Up @@ -219,6 +221,7 @@ Array [
"chain_id_source": "eip155:1",
"custom_slippage": false,
"gas_included": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 0,
"is_hardware_wallet": false,
"price_impact": 6,
Expand Down Expand Up @@ -248,6 +251,7 @@ Array [
"chain_id_source": "eip155:1",
"custom_slippage": false,
"gas_included": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 0,
"is_hardware_wallet": false,
"price_impact": 6,
Expand Down Expand Up @@ -349,6 +353,7 @@ Array [
"custom_slippage": false,
"gas_included": false,
"gas_included_7702": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 0,
"is_best_quote": true,
"is_hardware_wallet": false,
Expand Down Expand Up @@ -390,6 +395,7 @@ Array [
"custom_slippage": false,
"gas_included": false,
"gas_included_7702": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 0,
"is_hardware_wallet": false,
"price_impact": 0,
Expand All @@ -402,6 +408,7 @@ Array [
"swap_type": "crosschain",
"token_address_destination": null,
"token_address_source": "eip155:1/slip44:60",
"usd_balance_source": 0,
"usd_quoted_gas": 0,
"usd_quoted_return": 100,
"warnings": Array [
Expand Down Expand Up @@ -478,6 +485,7 @@ Array [
"custom_slippage": true,
"gas_included": false,
"gas_included_7702": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 11000,
"is_hardware_wallet": false,
"price_impact": 0,
Expand All @@ -493,6 +501,7 @@ Array [
"swap_type": "crosschain",
"token_address_destination": "eip155:10/erc20:0x123",
"token_address_source": "eip155:1/slip44:60",
"usd_balance_source": 0,
"usd_quoted_gas": 0,
"usd_quoted_return": 100,
"warnings": Array [
Expand Down
3 changes: 3 additions & 0 deletions packages/bridge-controller/src/bridge-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ describe('BridgeController', function () {
provider: 'provider_bridge',
best_quote_provider: 'provider_bridge2',
can_submit: true,
usd_balance_source: 0,
},
);

Expand Down Expand Up @@ -2366,6 +2367,7 @@ describe('BridgeController', function () {
provider: 'provider_bridge',
best_quote_provider: 'provider_bridge2',
can_submit: true,
usd_balance_source: 0,
},
);
expect(messengerMock.call.mock.calls).toMatchSnapshot();
Expand Down Expand Up @@ -2669,6 +2671,7 @@ describe('BridgeController', function () {
provider: 'provider_bridge',
best_quote_provider: 'provider_bridge2',
can_submit: true,
usd_balance_source: 0,
},
);
expect(trackMetaMetricsFn).toHaveBeenCalledTimes(0);
Expand Down
3 changes: 3 additions & 0 deletions packages/bridge-controller/src/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
formatProviderLabel(quote),
),
initial_load_time_all_quotes: this.state.quotesInitialLoadTime ?? 0,
has_gas_included_quote: this.state.quotes.some(
({ quote }) => quote.gasIncluded,
),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ describe('properties', () => {
"price_impact": 0,
"provider": "bridge1_bridge1",
"quoted_time_minutes": 1,
"usd_balance_source": 0,
"usd_quoted_gas": 0,
"usd_quoted_return": 0,
"warnings": Array [],
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge-controller/src/utils/metrics/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const getQuotesReceivedProperties = (
warnings: QuoteWarning[] = [],
isSubmittable: boolean = true,
recommendedQuote?: null | (QuoteResponse & Partial<QuoteMetadata>),
usdBalanceSource?: number,
) => {
const provider = activeQuote ? formatProviderLabel(activeQuote.quote) : '_';
return {
Expand All @@ -138,6 +139,7 @@ export const getQuotesReceivedProperties = (
: 0,
usd_quoted_gas: Number(activeQuote?.gasFee?.effective?.usd ?? 0),
usd_quoted_return: Number(activeQuote?.toTokenAmount?.usd ?? 0),
usd_balance_source: usdBalanceSource ?? 0,
best_quote_provider: recommendedQuote
? formatProviderLabel(recommendedQuote.quote)
: provider,
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge-controller/src/utils/metrics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
* These properties map to properties required by the segment-schema. For example: https://github.com/Consensys/segment-schema/blob/main/libraries/properties/cross-chain-swaps-action.yaml
*/
export type RequestParams = {
chain_id_source: CaipChainId;

Check failure on line 15 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `chain_id_source` must match one of the following formats: camelCase
chain_id_destination: CaipChainId | null;

Check failure on line 16 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `chain_id_destination` must match one of the following formats: camelCase
token_symbol_source: string;

Check failure on line 17 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `token_symbol_source` must match one of the following formats: camelCase
token_symbol_destination: string | null;

Check failure on line 18 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `token_symbol_destination` must match one of the following formats: camelCase
token_address_source: CaipAssetType;

Check failure on line 19 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `token_address_source` must match one of the following formats: camelCase
token_address_destination: CaipAssetType | null;

Check failure on line 20 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `token_address_destination` must match one of the following formats: camelCase
};

export type RequestMetadata = {
slippage_limit?: number; // undefined === auto

Check failure on line 24 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `slippage_limit` must match one of the following formats: camelCase
custom_slippage: boolean;

Check failure on line 25 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `custom_slippage` must match one of the following formats: camelCase
usd_amount_source: number; // Use quoteResponse when available

Check failure on line 26 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `usd_amount_source` must match one of the following formats: camelCase
stx_enabled: boolean;

Check failure on line 27 in packages/bridge-controller/src/utils/metrics/types.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Type Property name `stx_enabled` must match one of the following formats: camelCase
is_hardware_wallet: boolean;
swap_type: MetricsSwapType;
security_warnings: string[];
Expand All @@ -37,6 +37,7 @@
quotes_list: `${string}_${string}`[];
initial_load_time_all_quotes: number;
price_impact: number;
has_gas_included_quote: boolean;
};

export type TradeData = {
Expand Down Expand Up @@ -117,6 +118,7 @@
best_quote_provider: QuoteFetchData['best_quote_provider'];
price_impact: QuoteFetchData['price_impact'];
can_submit: QuoteFetchData['can_submit'];
usd_balance_source?: number;
};
[UnifiedSwapBridgeEventName.QuotesError]: Pick<
RequestMetadata,
Expand Down
Loading