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
18 changes: 0 additions & 18 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,6 @@
}
},
"packages/bridge-controller/src/utils/bridge.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 9
},
"id-denylist": {
"count": 1
}
Expand All @@ -666,11 +663,6 @@
"count": 1
}
},
"packages/bridge-controller/src/utils/metrics/properties.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 5
}
},
"packages/bridge-controller/src/utils/quote-fees.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 1
Expand Down Expand Up @@ -707,11 +699,6 @@
"count": 1
}
},
"packages/bridge-controller/tests/mock-sse.ts": {
"id-length": {
"count": 2
}
},
"packages/bridge-status-controller/src/utils/snaps.ts": {
"no-restricted-syntax": {
"count": 3
Expand Down Expand Up @@ -2248,11 +2235,6 @@
"count": 2
}
},
"packages/transaction-pay-controller/src/strategy/bridge/bridge-submit.ts": {
"no-restricted-syntax": {
"count": 1
}
},
"packages/transaction-pay-controller/src/strategy/relay/hyperliquid-withdraw.ts": {
"no-restricted-syntax": {
"count": 1
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Split up validators into smaller files to prepare for QuoteResponse V2 migration ([#9413](https://github.com/MetaMask/core/pull/9413))
- Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))

## [77.3.2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import {
DEFAULT_BRIDGE_CONTROLLER_STATE,
} from './constants/bridge';
import * as selectors from './selectors';
import { ChainId, RequestStatus, FeatureId } from './types';
import { ChainId, RequestStatus } from './types';
import type { BridgeControllerMessenger } from './types';
import * as balanceUtils from './utils/balance';
import * as featureFlagUtils from './utils/feature-flags';
import * as fetchUtils from './utils/fetch';
import { FeatureId } from './validators/feature-flags';

type RootMessenger = Messenger<
MockAnyNamespace,
Expand Down
66 changes: 34 additions & 32 deletions packages/bridge-controller/src/bridge-controller.sse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import {
DEFAULT_BRIDGE_CONTROLLER_STATE,
ETH_USDT_ADDRESS,
} from './constants/bridge';
import { ChainId, RequestStatus, FeatureId } from './types';
import type { BridgeControllerMessenger, TxData } from './types';
import { ChainId, RequestStatus } from './types';
import type { BridgeControllerMessenger } from './types';
import * as balanceUtils from './utils/balance';
import { formatChainIdToDec } from './utils/caip-formatters';
import * as featureFlagUtils from './utils/feature-flags';
import * as fetchUtils from './utils/fetch';
import {
TokenFeatureType,
QuoteStreamCompleteReason,
} from './utils/validators';
import { FeatureId } from './validators/feature-flags';
import { QuoteStreamCompleteReason } from './validators/quote-stream-complete';
import { TokenFeatureType } from './validators/token-feature';
import type { TxData } from './validators/trade';

type RootMessenger = Messenger<
MockAnyNamespace,
Expand Down Expand Up @@ -1239,18 +1239,20 @@ describe('BridgeController SSE', function () {
[
"Quote validation failed",
[
"lifi|trade",
"lifi|trade.chainId",
"lifi|trade.to",
"lifi|trade.from",
"lifi|trade.value",
"lifi|trade.data",
"lifi|trade.gasLimit",
"lifi|trade.unsignedPsbtBase64",
"lifi|trade.inputsToSign",
"lifi|trade.raw_data_hex",
"lifi|trade.xdrBase64",
"lifi|trade.xdr",
"At path: trade (union) -- Expected the value to satisfy a union of \`type | type | type | union | string\`, but received: [object Object]",
"At path: trade.chainId (union) -- Expected a number, but received: undefined",
"At path: trade.to (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
"At path: trade.from (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
"At path: trade.value (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
"At path: trade.data (union) -- Expected a value of type \`HexString\`, but received: \`undefined\`",
"At path: trade.gasLimit (union) -- Expected a number, but received: undefined",
"At path: trade.unsignedPsbtBase64 (union) -- Expected a string, but received: undefined",
"At path: trade.inputsToSign (union) -- Expected an array value, but received: undefined",
"At path: trade.raw_data_hex (union) -- Expected a string, but received: undefined",
"At path: trade (union) -- Expected the value to satisfy a union of \`type | type\`, but received: [object Object]",
"At path: trade.xdrBase64 (union) -- Expected a string, but received: undefined",
"At path: trade.xdr (union) -- Expected a string, but received: undefined",
"At path: trade (union) -- Expected a string, but received: [object Object]",
],
]
`);
Expand All @@ -1268,21 +1270,21 @@ describe('BridgeController SSE', function () {
);
expect(consoleWarnSpy.mock.calls).toHaveLength(3);
expect(consoleWarnSpy.mock.calls[1]).toMatchInlineSnapshot(`
[
"Quote validation failed",
[
"unknown|unknown",
],
]
`);
[
"Quote validation failed",
[
"At path: <root> (type) -- Expected an object, but received: """,
],
]
`);
expect(consoleWarnSpy.mock.calls[2]).toMatchInlineSnapshot(`
[
"Quote validation failed",
[
"unknown|quote",
],
]
`);
[
"Quote validation failed",
[
"At path: quote (type) -- Expected an object, but received: undefined",
],
]
`);

expect(consoleLogSpy).toHaveBeenCalledTimes(1);
expect(fetchBridgeQuotesSpy).toHaveBeenCalledTimes(5);
Expand Down
16 changes: 4 additions & 12 deletions packages/bridge-controller/src/bridge-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,8 @@ import {
} from './constants/bridge';
import { SWAPS_API_V2_BASE_URL } from './constants/swaps';
import * as selectors from './selectors';
import {
ChainId,
RequestStatus,
SortOrder,
StatusTypes,
FeatureId,
} from './types';
import type {
BridgeControllerMessenger,
QuoteResponseV1,
GenericQuoteRequest,
} from './types';
import { ChainId, RequestStatus, SortOrder, StatusTypes } from './types';
import type { BridgeControllerMessenger, GenericQuoteRequest } from './types';
import * as balanceUtils from './utils/balance';
import { getNativeAssetForChainId, isSolanaChainId } from './utils/bridge';
import {
Expand All @@ -61,6 +51,8 @@ import {
MetricsSwapType,
UnifiedSwapBridgeEventName,
} from './utils/metrics/constants';
import { FeatureId } from './validators/feature-flags';
import type { QuoteResponseV1 } from './validators/quote-response-v1';

const EMPTY_INIT_STATE = DEFAULT_BRIDGE_CONTROLLER_STATE;

Expand Down
5 changes: 3 additions & 2 deletions packages/bridge-controller/src/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import {
ExchangeRateSourcesForLookup,
selectIsAssetExchangeRateInState,
} from './selectors';
import { FeatureId, RequestStatus } from './types';
import { RequestStatus } from './types';
import type {
L1GasFees,
GenericQuoteRequest,
NonEvmFees,
QuoteRequest,
QuoteResponseV1,
BridgeControllerState,
BridgeControllerMessenger,
FetchFunction,
Expand Down Expand Up @@ -94,6 +93,8 @@ import {
} from './utils/quote';
import { appendFeesToQuotes } from './utils/quote-fees';
import { getMinimumBalanceForRentExemptionInLamports } from './utils/snaps';
import type { FeatureId } from './validators/feature-flags';
import type { QuoteResponseV1 } from './validators/quote-response-v1';

const metadata: StateMetadata<BridgeControllerState> = {
quoteRequest: {
Expand Down
69 changes: 34 additions & 35 deletions packages/bridge-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,15 @@ export type {
FeatureFlagResponse,
BridgeAsset,
GenericQuoteRequest,
Protocol,
BatchSellTradesResponse,
GaslessProperties,
SimulatedGasFeeLimits,
TokenAmountValues,
Step,
RefuelData,
Quote,
QuoteResponseV1 as QuoteResponse,
FeeData,
TxData,
Intent,
IntentOrderLike,
BitcoinTradeData,
StellarTradeData,
TronTradeData,
BridgeControllerState,
InputPrimaryDenomination,
BridgeControllerAction,
Expand All @@ -70,6 +63,18 @@ export type {
BridgeControllerMessenger,
FeatureFlagsPlatformConfig,
TxFeeGasLimits,
TokenFeature,
QuoteStreamCompleteData,
BridgeControllerGetStateAction,
BridgeControllerStateChangeEvent,
} from './types';

export {
AssetType,
SortOrder,
ChainId,
RequestStatus,
StatusTypes,
} from './types';

export type {
Expand All @@ -87,30 +92,31 @@ export type {

export { AbortReason } from './utils/metrics/constants';

export { StatusTypes } from './types';

export type {
TxData,
BitcoinTradeData,
TronTradeData,
StellarTradeData,
Trade,
} from './validators/trade';
export {
AssetType,
SortOrder,
ChainId,
RequestStatus,
FeatureId,
type TokenFeature,
type QuoteStreamCompleteData,
type BridgeControllerGetStateAction,
type BridgeControllerStateChangeEvent,
} from './types';

isBitcoinTrade,
isTronTrade,
isEvmTxData,
isStellarTrade,
} from './validators/trade';
export type { QuoteResponseV1 as QuoteResponse } from './validators/quote-response-v1';
export type { Quote } from './validators/quote';
export { FeeType, DiscountType } from './validators/quote';
export { ActionTypes } from './validators/step';
export {
DiscountType,
FeeType,
ActionTypes,
BridgeAssetSchema,
TokenFeatureType,
validateQuoteStreamComplete,
QuoteStreamCompleteReason,
BatchSellTransactionType,
} from './utils/validators';
} from './validators/quote-stream-complete';
export { BatchSellTransactionType } from './validators/batch-sell';
export { TokenFeatureType } from './validators/token-feature';
export { BridgeAssetSchema } from './validators/bridge-asset';
export { FeatureId } from './validators/feature-flags';

export {
ALLOWED_BRIDGE_CHAIN_IDS,
Expand Down Expand Up @@ -187,14 +193,7 @@ export {
formatAddressToAssetId,
} from './utils/caip-formatters';

export {
extractTradeData,
isBitcoinTrade,
isStellarTrade,
isTronTrade,
isEvmTxData,
type Trade,
} from './utils/trade-utils';
export { extractTradeData } from './utils/trade-utils';

export {
selectBridgeQuotes,
Expand Down
6 changes: 3 additions & 3 deletions packages/bridge-controller/src/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
ChainId,
BridgeAsset,
NonEvmFees,
QuoteResponseV1,
} from './types';
import { getNativeAssetForChainId, isNativeAddress } from './utils/bridge';
import {
Expand All @@ -38,8 +37,9 @@ import {
formatChainIdToDec,
formatChainIdToHex,
} from './utils/caip-formatters';
import { validateQuoteResponseV1 } from './utils/validators';
import { BatchSellTransactionType } from './utils/validators';
import { BatchSellTransactionType } from './validators/batch-sell';
import type { QuoteResponseV1 } from './validators/quote-response-v1';
import { validateQuoteResponseV1 } from './validators/quote-response-v1';

const MOCK_USDC_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const MOCK_MUSD_ADDRESS = '0x12345A7890123456789012345678901234567890';
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-controller/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
BridgeControllerState,
ExchangeRate,
QuoteMetadata,
QuoteResponseV1,
TokenAmountValues,
} from './types';
import { RequestStatus, SortOrder } from './types';
Expand Down Expand Up @@ -55,6 +54,7 @@ import {
calcBatchFees,
} from './utils/quote';
import { getDefaultSlippagePercentage } from './utils/slippage';
import type { QuoteResponseV1 } from './validators/quote-response-v1';

/**
* The controller states that provide exchange rates
Expand Down
Loading