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
10 changes: 0 additions & 10 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,6 @@
"count": 1
}
},
"packages/bridge-controller/src/utils/bridge.ts": {
"id-denylist": {
"count": 1
}
},
"packages/bridge-controller/src/utils/feature-flags.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 3
Expand Down Expand Up @@ -684,11 +679,6 @@
"count": 2
}
},
"packages/bridge-controller/src/utils/quote.ts": {
"no-restricted-syntax": {
"count": 2
}
},
"packages/bridge-controller/src/utils/slippage.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 1
Expand Down
6 changes: 6 additions & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **BREAKING:** Make `QuoteMetadata` fields optional and remove unused values
- Remove falsy (`0` and `null`) fallbacks; missing values are now `undefined`
- Replace `gasFee.effective`, `gasFee.max`, and `totalMaxNetworkFee` usages with `gasFee.total` and `totalNetworkFee`.
- Extract quote-metadata calculation into `utils/quote-metadata/` ([#9507](https://github.com/MetaMask/core/pull/9507))
- Implement `mergeQuoteMetadata` util which appends QuoteMetadata to QuoteResponse
- Return `priceImpact` and `relayerFee` as part of `QuoteMetadata`
- Bump `@metamask/transaction-controller` from `^69.0.0` to `^69.1.0` ([#9568](https://github.com/MetaMask/core/pull/9568))
- Bump `@metamask/assets-controller` from `^11.0.0` to `^11.1.0` ([#9579](https://github.com/MetaMask/core/pull/9579))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
},
{
"destChainId": "137",
"destTokenAddress": "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
"destTokenAddress": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"destWalletAddress": "SolanaWalletAddres1234",
"insufficientBal": false,
"resetApproval": false,
Expand Down Expand Up @@ -61,7 +61,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
}
`;

exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes should trigger quote polling if request is valid 2`] = `
exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes should trigger quote polling if request is valid 3`] = `
[
[
"Unified SwapBridge Input Changed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
});

it('should trigger quote polling if request is valid', async function () {
const consoleWarnSpy = jest.spyOn(console, 'warn');
await withController(
async ({
controller: bridgeController,
Expand All @@ -227,7 +228,10 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
mockFetchFn.mockImplementationOnce(async () => {
return mockSseBatchSellEventSource([
mockBridgeQuotesNativeErc20V1,
mockBridgeQuotesErc20Erc20V1,
mockBridgeQuotesErc20Erc20V1.map((quote) => ({
...quote,
quoteRequestIndex: 1,
})),
]);
});
hasSufficientBalanceSpy.mockResolvedValue(true);
Expand Down Expand Up @@ -399,6 +403,7 @@ describe('BridgeController BatchSell (multiple quote requests) SSE', function ()
// After first fetch
jest.advanceTimersByTime(5000);
await flushPromises();
expect(consoleWarnSpy.mock.calls).toMatchInlineSnapshot(`[]`);
expect(fetchAssetPricesSpy).toHaveBeenCalledTimes(1);
expect(bridgeController.state).toStrictEqual({
...expectedState,
Expand Down
113 changes: 92 additions & 21 deletions packages/bridge-controller/src/bridge-controller.sse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
MockAnyNamespace,
} from '@metamask/messenger';
import { abiERC20 } from '@metamask/metamask-eth-abis';
import { merge } from 'lodash';

import { flushPromises } from '../../../tests/helpers';
import { mockBridgeQuotesErc20Erc20V1 } from '../tests/mock-quotes-erc20-erc20';
Expand All @@ -32,10 +33,14 @@ import {
import { ChainId, RequestStatus } from './types';
import type { BridgeControllerMessenger } from './types';
import * as balanceUtils from './utils/balance';
import { formatChainIdToDec } from './utils/caip-formatters';
import {
formatChainIdToCaip,
formatChainIdToDec,
} from './utils/caip-formatters';
import * as featureFlagUtils from './utils/feature-flags';
import * as fetchUtils from './utils/fetch';
import { FeatureId } from './validators/feature-flags';
import { validateQuoteResponseV1 } from './validators/quote-response-v1';
import { QuoteStreamCompleteReason } from './validators/quote-stream-complete';
import { TokenFeatureType } from './validators/token-feature';
import type { TxData } from './validators/trade';
Expand Down Expand Up @@ -377,9 +382,23 @@ describe('BridgeController SSE', function () {
...quote,
quote: {
...quote.quote,
srcTokenAddress,
srcAsset: {
address: ETH_USDT_ADDRESS,
assetId:
`${formatChainIdToCaip(1)}/erc20:${srcTokenAddress}` as const,
symbol: 'USDT',
name: 'Tether USD',
decimals: 6,
chainId: 1,
iconUrl: 'https://media.socket.tech/tokens/all/USDT',
},
srcChainId: 1,
destChainId: formatChainIdToDec(destChainId),
destAsset: {
...quote.quote.destAsset,
assetId:
`${formatChainIdToCaip(destChainId)}/erc20:${quote.quote.destAsset.address}` as const,
},
},
}),
);
Expand Down Expand Up @@ -488,16 +507,39 @@ describe('BridgeController SSE', function () {
resetApproval,
},
],
quotes: mockUSDTQuoteResponse.map((quote) => ({
...quote,
featureId: FeatureId.UNIFIED_SWAP_BRIDGE,
resetApproval: tradeData
? {
...quote.approval,
data: tradeData,
}
: undefined,
})),
quotes: mockBridgeQuotesErc20Erc20V1
.map((quote) =>
merge({}, quote, {
quote: {
srcAsset: {
address: ETH_USDT_ADDRESS,
assetId: `eip155:1/erc20:${ETH_USDT_ADDRESS}`,
symbol: 'USDT',
name: 'Tether USD',
decimals: 6,
chainId: 1,
iconUrl: 'https://media.socket.tech/tokens/all/USDT',
},
srcChainId: 1,
destAsset: {
...quote.quote.destAsset,
assetId:
`${formatChainIdToCaip(destChainId)}/erc20:${quote.quote.destAsset.address}` as const,
},
destChainId: formatChainIdToDec(destChainId),
},
}),
)
.map((quote) => ({
...quote,
featureId: FeatureId.UNIFIED_SWAP_BRIDGE,
resetApproval: tradeData
? {
...quote.approval,
data: tradeData,
}
: undefined,
})),
quotesRefreshCount: 1,
quotesLoadingStatus: 1,
quotesLastFetched: t1,
Expand Down Expand Up @@ -541,11 +583,23 @@ describe('BridgeController SSE', function () {
...quote,
quote: {
...quote.quote,
srcTokenAddress: ETH_USDT_ADDRESS,
srcAsset: {
address: ETH_USDT_ADDRESS,
assetId: `eip155:1/erc20:${ETH_USDT_ADDRESS}` as const,
chainId: 1,
symbol: 'USDT',
name: 'Tether USD',
decimals: 6,
iconUrl: 'https://media.socket.tech/tokens/all/USDT',
},
srcChainId: 1,
},
}),
);
mockUSDTQuoteResponse.forEach((quote) =>
validateQuoteResponseV1(quote),
);

mockFetchFn.mockImplementationOnce(async () => {
return mockSseEventSource(mockUSDTQuoteResponse);
});
Expand Down Expand Up @@ -647,14 +701,31 @@ describe('BridgeController SSE', function () {
resetApproval: true,
},
],
quotes: mockUSDTQuoteResponse.map((quote) => ({
...quote,
featureId: FeatureId.UNIFIED_SWAP_BRIDGE,
resetApproval: {
...quote.approval,
data: '0x095ea7b30000000000000000000000000439e60f02a8900a951603950d8d4527f400c3f10000000000000000000000000000000000000000000000000000000000000000',
},
})),
quotes: mockBridgeQuotesErc20Erc20V1
.map((quote) =>
merge({}, quote, {
quote: {
srcAsset: {
address: ETH_USDT_ADDRESS,
assetId: `eip155:1/erc20:${ETH_USDT_ADDRESS}`,
name: 'Tether USD',
decimals: 6,
symbol: 'USDT',
chainId: 1,
iconUrl: 'https://media.socket.tech/tokens/all/USDT',
},
srcChainId: 1,
},
}),
)
.map((quote) => ({
...quote,
featureId: FeatureId.UNIFIED_SWAP_BRIDGE,
resetApproval: {
...quote.approval,
data: '0x095ea7b30000000000000000000000000439e60f02a8900a951603950d8d4527f400c3f10000000000000000000000000000000000000000000000000000000000000000',
},
})),
quotesRefreshCount: 1,
quotesLoadingStatus: 1,
quotesLastFetched: t1,
Expand Down
Loading