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

## [Unreleased]

### Changed

- Refactor `handleLineaDelay` to `handleApprovalDelay` for improved abstraction and add support for Base chain by using an array and `includes` for chain ID checks ([#6674](https://github.com/MetaMask/core/pull/6674))

## [44.0.0]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,237 @@ Array [
]
`;

exports[`BridgeStatusController submitTx: EVM bridge should delay after submitting base approval 1`] = `
Object {
"chainId": "0xa4b1",
"hash": "0xevmTxHash",
"id": "test-tx-id",
"status": "unapproved",
"time": 1234567890,
"txParams": Object {
"chainId": "0xa4b1",
"data": "0xdata",
"from": "0xaccount1",
"gasLimit": "0x5208",
"to": "0xbridgeContract",
"value": "0x0",
},
"txReceipt": Object {
"effectiveGasPrice": "0x1880a",
"gasUsed": "0x2c92a",
},
"type": "bridge",
}
`;

exports[`BridgeStatusController submitTx: EVM bridge should delay after submitting base approval 2`] = `
Object {
"account": "0xaccount1",
"approvalTxId": "test-approval-tx-id",
"batchId": undefined,
"estimatedProcessingTimeInSeconds": 15,
"hasApprovalTx": true,
"initialDestAssetBalance": undefined,
"isStxEnabled": false,
"pricingData": Object {
"amountSent": "1.234",
"amountSentInUsd": "1.01",
"quotedGasAmount": ".00055",
"quotedGasInUsd": "2.5778",
"quotedReturnInUsd": "0.134214",
},
"quote": Object {
"bridgeId": "lifi",
"bridges": Array [
"across",
],
"destAsset": Object {
"address": "0x0000000000000000000000000000000000000000",
"assetId": "eip155:10/slip44:60",
"chainId": 10,
"coinKey": "ETH",
"decimals": 18,
"icon": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"name": "ETH",
"priceUSD": "2478.63",
"symbol": "ETH",
},
"destChainId": 10,
"destTokenAmount": "990654755978612",
"feeData": Object {
"metabridge": Object {
"amount": "8750000000000",
"asset": Object {
"address": "0x0000000000000000000000000000000000000000",
"assetId": "eip155:42161/slip44:60",
"chainId": 42161,
"coinKey": "ETH",
"decimals": 18,
"icon": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"name": "ETH",
"priceUSD": "2478.7",
"symbol": "ETH",
},
},
},
"minDestTokenAmount": "941000000000000",
"requestId": "197c402f-cb96-4096-9f8c-54aed84ca776",
"srcAsset": Object {
"address": "0x0000000000000000000000000000000000000000",
"assetId": "eip155:42161/slip44:60",
"chainId": 42161,
"coinKey": "ETH",
"decimals": 18,
"icon": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"name": "ETH",
"priceUSD": "2478.7",
"symbol": "ETH",
},
"srcChainId": 8453,
"srcTokenAmount": "991250000000000",
"steps": Array [
Object {
"action": "bridge",
"destAmount": "990654755978612",
"destAsset": Object {
"address": "0x0000000000000000000000000000000000000000",
"assetId": "eip155:10/slip44:60",
"chainId": 10,
"coinKey": "ETH",
"decimals": 18,
"icon": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"name": "ETH",
"priceUSD": "2478.63",
"symbol": "ETH",
},
"destChainId": 10,
"protocol": Object {
"displayName": "Across",
"icon": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/bridges/acrossv2.png",
"name": "across",
},
"srcAmount": "991250000000000",
"srcAsset": Object {
"address": "0x0000000000000000000000000000000000000000",
"assetId": "eip155:42161/slip44:60",
"chainId": 42161,
"coinKey": "ETH",
"decimals": 18,
"icon": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
"name": "ETH",
"priceUSD": "2478.7",
"symbol": "ETH",
},
"srcChainId": 42161,
},
],
},
"slippagePercentage": 0,
"startTime": 1234567890,
"status": Object {
"srcChain": Object {
"chainId": 8453,
"txHash": "0xevmTxHash",
},
"status": "PENDING",
},
"targetContractAddress": undefined,
"txMetaId": "test-tx-id",
}
`;

exports[`BridgeStatusController submitTx: EVM bridge should delay after submitting base approval 3`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getSelectedMultichainAccount",
],
Array [
"BridgeController:trackUnifiedSwapBridgeEvent",
"Unified SwapBridge Submitted",
Object {
"action_type": "swapbridge-v1",
"chain_id_destination": "eip155:10",
"chain_id_source": "eip155:8453",
"custom_slippage": false,
"gas_included": false,
"gas_included_7702": false,
"is_hardware_wallet": false,
"price_impact": 0,
"provider": "lifi_across",
"quoted_time_minutes": 0.25,
"stx_enabled": false,
"swap_type": "crosschain",
"token_symbol_destination": "ETH",
"token_symbol_source": "ETH",
"usd_amount_source": 1.01,
"usd_quoted_gas": 2.5778,
"usd_quoted_return": 0,
},
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
],
Array [
"NetworkController:findNetworkClientIdByChainId",
"0xa4b1",
],
Array [
"GasFeeController:getState",
],
Array [
"TransactionController:getState",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
],
Array [
"NetworkController:findNetworkClientIdByChainId",
"0xa4b1",
],
Array [
"GasFeeController:getState",
],
Array [
"TransactionController:getState",
],
]
`;

exports[`BridgeStatusController submitTx: EVM bridge should delay after submitting base approval 4`] = `
Array [
Array [
Object {
"data": Object {
"srcChainId": "eip155:8453",
"stxEnabled": false,
},
"name": "Bridge Transaction Completed",
},
[Function],
],
Array [
Object {
"data": Object {
"srcChainId": "eip155:8453",
"stxEnabled": false,
},
"name": "Bridge Transaction Approval Completed",
},
[Function],
],
]
`;

exports[`BridgeStatusController submitTx: EVM bridge should delay after submitting linea approval 1`] = `
Object {
"chainId": "0xa4b1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ describe('BridgeStatusController', () => {

it('should delay after submitting linea approval', async () => {
const handleLineaDelaySpy = jest
.spyOn(transactionUtils, 'handleLineaDelay')
.spyOn(transactionUtils, 'handleApprovalDelay')
.mockResolvedValueOnce();
const mockTraceFn = jest
.fn()
Expand Down Expand Up @@ -2502,6 +2502,44 @@ describe('BridgeStatusController', () => {
expect(mockTraceFn.mock.calls).toMatchSnapshot();
});

it('should delay after submitting base approval', async () => {
const handleBaseDelaySpy = jest
.spyOn(transactionUtils, 'handleApprovalDelay')
.mockResolvedValueOnce();
const mockTraceFn = jest
.fn()
.mockImplementation((_p, callback) => callback());

setupEventTrackingMocks(mockMessengerCall);
setupApprovalMocks(mockMessengerCall);
setupBridgeMocks(mockMessengerCall);

const { controller, startPollingForBridgeTxStatusSpy } = getController(
mockMessengerCall,
mockTraceFn,
);

const baseQuoteResponse = {
...mockEvmQuoteResponse,
quote: { ...mockEvmQuoteResponse.quote, srcChainId: 8453 },
trade: {
...(mockEvmQuoteResponse.trade as TxData),
gasLimit: undefined,
} as never,
};

const result = await controller.submitTx(baseQuoteResponse, false);
controller.stopAllPolling();

expect(mockTraceFn).toHaveBeenCalledTimes(2);
expect(handleBaseDelaySpy).toHaveBeenCalledTimes(1);
expect(result).toMatchSnapshot();
expect(startPollingForBridgeTxStatusSpy).toHaveBeenCalledTimes(0);
expect(controller.state.txHistory[result.id]).toMatchSnapshot();
expect(mockMessengerCall.mock.calls).toMatchSnapshot();
expect(mockTraceFn.mock.calls).toMatchSnapshot();
});

it('should call handleMobileHardwareWalletDelay for hardware wallet on mobile', async () => {
const handleMobileHardwareWalletDelaySpy = jest
.spyOn(transactionUtils, 'handleMobileHardwareWalletDelay')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import {
getClientRequest,
getStatusRequestParams,
getUSDTAllowanceResetTx,
handleLineaDelay,
handleApprovalDelay,
handleMobileHardwareWalletDelay,
handleNonEvmTxResponse,
generateActionId,
Expand Down Expand Up @@ -818,7 +818,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
requireApproval,
});

await handleLineaDelay(quoteResponse);
await handleApprovalDelay(quoteResponse);
return approvalTxMeta;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-status-controller/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE: BridgeStatusControllerState

export const BRIDGE_PROD_API_BASE_URL = 'https://bridge.api.cx.metamask.io';

export const LINEA_DELAY_MS = 5000;
export const APPROVAL_DELAY_MS = 5000;

export enum TraceName {
BridgeTransactionApprovalCompleted = 'Bridge Transaction Approval Completed',
Expand Down
Loading
Loading