Skip to content

Commit 0fcb878

Browse files
committed
Revert "SWAPS-2839 update bridge controllers for bitcoin (#6454)"
This reverts commit 1aae93d.
1 parent b118ce5 commit 0fcb878

24 files changed

+183
-1196
lines changed

packages/bridge-controller/CHANGELOG.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929

3030
### Added
3131

32-
- Add support for Bitcoin bridge transactions ([#6454](https://github.com/MetaMask/core/pull/6454))
33-
- Handle Bitcoin PSBT (Partially Signed Bitcoin Transaction) format in trade data
34-
- Add `BitcoinTradeDataSchema` and `BitcoinQuoteResponseSchema` validators
35-
- Support Bitcoin chain ID (`ChainId.BTC = 20000000000001`) and CAIP format (`bip122:000000000019d6689c085ae165831e93`)
36-
- Export `isNonEvmChainId` utility function to check for non-EVM chains (Solana, Bitcoin) ([#6454](https://github.com/MetaMask/core/pull/6454))
3732
- Add `selectDefaultSlippagePercentage` that returns the default slippage for a chain and token combination ([#6616](https://github.com/MetaMask/core/pull/6616))
3833
- Return `0.5` if requesting a bridge quote
3934
- Return `undefined` (auto) if requesting a Solana swap
@@ -43,26 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4338

4439
### Changed
4540

46-
- **BREAKING:** Rename fee handling for non-EVM chains ([#6454](https://github.com/MetaMask/core/pull/6454))
47-
- Replace `SolanaFees` type with `NonEvmFees` type
48-
- Replace `solanaFeesInLamports` field with `nonEvmFeesInNative` field
49-
- Update `#appendSolanaFees` to `#appendNonEvmFees` to support all non-EVM chains
50-
- The `nonEvmFeesInNative` field stores fees in the smallest units for each chain (lamports for Solana, satoshis for Bitcoin)
51-
- Update Snap methods to use new unified interface for non-EVM chains ([#6454](https://github.com/MetaMask/core/pull/6454))
52-
- Replace `getFeeForTransaction` with `computeFee` method that returns fees in native token units
53-
- Update fee calculation to handle different unit conversions per chain
54-
- Support fee computation for Bitcoin and Solana chains
55-
- Update quote validation to support Bitcoin-specific trade data format ([#6454](https://github.com/MetaMask/core/pull/6454))
56-
- Add separate validation for Bitcoin quotes that include `unsignedPsbtBase64` field
57-
- Update selectors and utilities to use `isNonEvmChainId` instead of `isSolanaChainId` for generic non-EVM handling ([#6454](https://github.com/MetaMask/core/pull/6454))
5841
- Bump `@metamask/controller-utils` from `^11.12.0` to `^11.14.0` ([#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629))
5942
- Bump `@metamask/base-controller` from `^8.3.0` to `^8.4.0` ([#6632](https://github.com/MetaMask/core/pull/6632))
6043

61-
### Removed
62-
63-
- **BREAKING:** Remove deprecated `SolanaFees` type - use `NonEvmFees` type instead ([#6454](https://github.com/MetaMask/core/pull/6454))
64-
- **BREAKING:** Remove `solanaFeesInLamports` field from quotes - use `nonEvmFeesInNative` field instead ([#6454](https://github.com/MetaMask/core/pull/6454))
65-
6644
## [43.0.0]
6745

6846
### Added

packages/bridge-controller/src/__snapshots__/bridge-controller.test.ts.snap

Lines changed: 20 additions & 50 deletions
Large diffs are not rendered by default.

packages/bridge-controller/src/bridge-controller.test.ts

Lines changed: 6 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { Contract } from '@ethersproject/contracts';
44
import { deriveStateFromMetadata } from '@metamask/base-controller';
55
import {
6-
BtcScope,
76
EthAccountType,
87
EthScope,
98
SolAccountType,
@@ -590,26 +589,6 @@ describe('BridgeController', function () {
590589
resolve('5000');
591590
}, 200);
592591
}
593-
if (
594-
(params as { handler: string })?.handler ===
595-
'onClientRequest' &&
596-
(params as { request?: { method: string } })?.request
597-
?.method === 'computeFee'
598-
) {
599-
return setTimeout(() => {
600-
resolve([
601-
{
602-
type: 'base',
603-
asset: {
604-
unit: 'SOL',
605-
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:11111111111111111111111111111111',
606-
amount: '0.000000014', // 14 lamports in SOL
607-
fungible: true,
608-
},
609-
},
610-
]);
611-
}, 100);
612-
}
613592
return setTimeout(() => {
614593
resolve({ value: '14' });
615594
}, 100);
@@ -690,15 +669,9 @@ describe('BridgeController', function () {
690669
minimumBalanceForRentExemptionInLamports: '5000',
691670
quotes: mockBridgeQuotesSolErc20.map((quote) => ({
692671
...quote,
693-
nonEvmFeesInNative: '0.000000014',
672+
solanaFeesInLamports: '14',
694673
})),
695674
quotesLoadingStatus: RequestStatus.FETCHED,
696-
quoteRequest: quoteParams,
697-
quoteFetchError: null,
698-
assetExchangeRates: {},
699-
quotesRefreshCount: 1,
700-
quotesInitialLoadTime: expect.any(Number),
701-
quotesLastFetched: expect.any(Number),
702675
}),
703676
);
704677
expect(consoleErrorSpy).not.toHaveBeenCalled();
@@ -752,15 +725,9 @@ describe('BridgeController', function () {
752725
minimumBalanceForRentExemptionInLamports: '5000',
753726
quotes: mockBridgeQuotesSolErc20.map((quote) => ({
754727
...quote,
755-
nonEvmFeesInNative: '0.000000014',
728+
solanaFeesInLamports: '14',
756729
})),
757730
quotesLoadingStatus: RequestStatus.FETCHED,
758-
quoteRequest: quoteParams,
759-
quoteFetchError: null,
760-
assetExchangeRates: {},
761-
quotesRefreshCount: expect.any(Number),
762-
quotesInitialLoadTime: expect.any(Number),
763-
quotesLastFetched: expect.any(Number),
764731
}),
765732
);
766733
expect(consoleErrorSpy).not.toHaveBeenCalled();
@@ -788,15 +755,9 @@ describe('BridgeController', function () {
788755
minimumBalanceForRentExemptionInLamports: '0',
789756
quotes: mockBridgeQuotesSolErc20.map((quote) => ({
790757
...quote,
791-
nonEvmFeesInNative: '0.000000014',
758+
solanaFeesInLamports: '14',
792759
})),
793760
quotesLoadingStatus: RequestStatus.FETCHED,
794-
quoteRequest: { ...quoteParams, srcTokenAmount: '11111' },
795-
quoteFetchError: null,
796-
assetExchangeRates: {},
797-
quotesRefreshCount: expect.any(Number),
798-
quotesInitialLoadTime: expect.any(Number),
799-
quotesLastFetched: expect.any(Number),
800761
}),
801762
);
802763

@@ -1601,7 +1562,7 @@ describe('BridgeController', function () {
16011562
mockBridgeQuotesSolErc20 as unknown as QuoteResponse[],
16021563
[],
16031564
2,
1604-
'0.000005000', // SOL amount (5000 lamports)
1565+
'5000',
16051566
'300',
16061567
],
16071568
[
@@ -1718,26 +1679,6 @@ describe('BridgeController', function () {
17181679
resolve(expectedMinBalance);
17191680
}, 200);
17201681
}
1721-
if (
1722-
(params as { handler: string })?.handler ===
1723-
'onClientRequest' &&
1724-
(params as { request?: { method: string } })?.request
1725-
?.method === 'computeFee'
1726-
) {
1727-
return setTimeout(() => {
1728-
resolve([
1729-
{
1730-
type: 'base',
1731-
asset: {
1732-
unit: 'SOL',
1733-
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:11111111111111111111111111111111',
1734-
amount: expectedFees || '0',
1735-
fungible: true,
1736-
},
1737-
},
1738-
]);
1739-
}, 100);
1740-
}
17411682
return setTimeout(() => {
17421683
resolve({ value: expectedFees });
17431684
}, 100);
@@ -1811,9 +1752,9 @@ describe('BridgeController', function () {
18111752
}),
18121753
);
18131754

1814-
// Verify non-EVM fees
1755+
// Verify Solana fees
18151756
quotes.forEach((quote) => {
1816-
expect(quote.nonEvmFeesInNative).toBe(
1757+
expect(quote.solanaFeesInLamports).toBe(
18171758
isSolanaChainId(quote.quote.srcChainId) ? expectedFees : undefined,
18181759
);
18191760
});
@@ -1840,121 +1781,6 @@ describe('BridgeController', function () {
18401781
},
18411782
);
18421783

1843-
it('should handle BTC chain fees correctly', async () => {
1844-
jest.useFakeTimers();
1845-
// Use the actual Solana mock which already has string trade type
1846-
const btcQuoteResponse = mockBridgeQuotesSolErc20.map((quote) => ({
1847-
...quote,
1848-
quote: {
1849-
...quote.quote,
1850-
srcChainId: ChainId.BTC,
1851-
},
1852-
})) as unknown as QuoteResponse[];
1853-
1854-
messengerMock.call.mockImplementation(
1855-
(
1856-
...args: Parameters<BridgeControllerMessenger['call']>
1857-
): ReturnType<BridgeControllerMessenger['call']> => {
1858-
const [actionType, params] = args;
1859-
1860-
if (actionType === 'AccountsController:getSelectedMultichainAccount') {
1861-
return {
1862-
type: 'btc:p2wpkh',
1863-
id: 'btc-account-1',
1864-
scopes: [BtcScope.Mainnet],
1865-
methods: [],
1866-
address: 'bc1q...',
1867-
metadata: {
1868-
name: 'BTC Account 1',
1869-
importTime: 1717334400,
1870-
keyring: {
1871-
type: 'Snap Keyring',
1872-
},
1873-
snap: {
1874-
id: 'btc-snap-id',
1875-
name: 'BTC Snap',
1876-
},
1877-
},
1878-
} as never;
1879-
}
1880-
1881-
if (actionType === 'SnapController:handleRequest') {
1882-
return new Promise((resolve) => {
1883-
if (
1884-
(params as { handler: string })?.handler === 'onClientRequest' &&
1885-
(params as { request?: { method: string } })?.request?.method ===
1886-
'computeFee'
1887-
) {
1888-
return setTimeout(() => {
1889-
resolve([
1890-
{
1891-
type: 'base',
1892-
asset: {
1893-
unit: 'BTC',
1894-
type: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
1895-
amount: '0.00005', // BTC fee
1896-
fungible: true,
1897-
},
1898-
},
1899-
]);
1900-
}, 100);
1901-
}
1902-
return setTimeout(() => {
1903-
resolve('5000');
1904-
}, 200);
1905-
});
1906-
}
1907-
1908-
return {
1909-
provider: jest.fn() as never,
1910-
selectedNetworkClientId: 'selectedNetworkClientId',
1911-
} as never;
1912-
},
1913-
);
1914-
1915-
jest.spyOn(fetchUtils, 'fetchBridgeQuotes').mockResolvedValue({
1916-
quotes: btcQuoteResponse,
1917-
validationFailures: [],
1918-
});
1919-
1920-
const quoteParams = {
1921-
srcChainId: ChainId.BTC.toString(),
1922-
destChainId: '1',
1923-
srcTokenAddress: 'NATIVE',
1924-
destTokenAddress: '0x0000000000000000000000000000000000000000',
1925-
srcTokenAmount: '100000', // satoshis
1926-
walletAddress: 'bc1q...',
1927-
destWalletAddress: '0x5342',
1928-
slippage: 0.5,
1929-
};
1930-
1931-
await bridgeController.updateBridgeQuoteRequestParams(
1932-
quoteParams,
1933-
metricsContext,
1934-
);
1935-
1936-
// Wait for polling to start
1937-
jest.advanceTimersByTime(201);
1938-
await flushPromises();
1939-
1940-
// Wait for fetch to trigger
1941-
jest.advanceTimersByTime(295);
1942-
await flushPromises();
1943-
1944-
// Wait for fetch to complete
1945-
jest.advanceTimersByTime(2601);
1946-
await flushPromises();
1947-
1948-
// Final wait for fee calculation
1949-
jest.advanceTimersByTime(100);
1950-
await flushPromises();
1951-
1952-
const { quotes } = bridgeController.state;
1953-
expect(quotes).toHaveLength(2); // mockBridgeQuotesSolErc20 has 2 quotes
1954-
expect(quotes[0].nonEvmFeesInNative).toBe('0.00005'); // BTC fee as-is
1955-
expect(quotes[1].nonEvmFeesInNative).toBe('0.00005'); // BTC fee as-is
1956-
});
1957-
19581784
describe('trackUnifiedSwapBridgeEvent client-side calls', () => {
19591785
beforeEach(() => {
19601786
jest.clearAllMocks();

0 commit comments

Comments
 (0)