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

### Changed

- **BREAKING:** Make `QuoteMetadata` fields optional, remove `0` and `null` amount fallbacks ([#9507](https://github.com/MetaMask/core/pull/9507))
- Return priceImpact and relayerFee
- Remove gasFee max and effective, totalMaxNetworkFee
- Refactor quoteMetadata calculation and data access to prepare for metadata migration ([#9507](https://github.com/MetaMask/core/pull/9507))
- Extract `QuoteMetadata` type and calculation to a new file
- Implement `mergeQuoteMetadata` util which appends QuoteMetadata to QuoteResponse
- Bump `@metamask/assets-controller` from `^10.2.1` to `^11.0.0` ([#9485](https://github.com/MetaMask/core/pull/9485))

### Fixed
Expand All @@ -39,6 +45,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Phase 1 of migration, in which `QuoteResponseV2 & QuoteMetadata` are returned, but still uses v1 metadata
- Migration utilities

- toQuoteResponseV1, toQuoteResponseV2
- migrationMerge
- mergeQuoteMetadata, extractQuoteMetadata (test util)

- 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))
- Bump `@metamask/assets-controller` from `^10.0.1` to `^10.2.0` ([#9411](https://github.com/MetaMask/core/pull/9411), [#9450](https://github.com/MetaMask/core/pull/9450))
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
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
96 changes: 76 additions & 20 deletions packages/bridge-controller/src/bridge-controller.sse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ 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';
import { merge } from 'lodash';
import { validateQuoteResponseV1 } from './validators/quote-response-v1';

type RootMessenger = Messenger<
MockAnyNamespace,
Expand Down Expand Up @@ -377,7 +379,15 @@ describe('BridgeController SSE', function () {
...quote,
quote: {
...quote.quote,
srcTokenAddress,
srcAsset: {
address: ETH_USDT_ADDRESS,
assetId: `eip155:1/erc20:${ETH_USDT_ADDRESS}` as const,
symbol: 'USDT',
name: 'Tether USD',
decimals: 6,
chainId: 1,
iconUrl: 'https://media.socket.tech/tokens/all/USDT',
},
srcChainId: 1,
destChainId: formatChainIdToDec(destChainId),
},
Expand Down Expand Up @@ -488,16 +498,33 @@ 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,
},
}),
)
.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 +568,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 +686,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
Loading