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

- **BREAKING** Use CrossChain API instead of the intent manager package for intent order submission ([#6963](https://github.com/MetaMask/core/pull/6963))

## [52.0.0]

### Changed
Expand Down
63 changes: 24 additions & 39 deletions packages/bridge-status-controller/src/bridge-status-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ import {
} from '@metamask/bridge-controller';
import type { TraceCallback } from '@metamask/controller-utils';
import { toHex } from '@metamask/controller-utils';
import type {
IntentOrder,
IntentSubmissionParams,
} from '@metamask/intent-manager';
import { IntentManager } from '@metamask/intent-manager';
import { IntentOrderStatus } from '@metamask/intent-manager';
import { StaticIntervalPollingController } from '@metamask/polling-controller';
import type {
TransactionController,
Expand Down Expand Up @@ -54,6 +48,9 @@ import type {
} from './types';
import { type BridgeStatusControllerMessenger } from './types';
import { BridgeClientId } from './types';
import { IntentApiImpl } from './intent-api';
import { IntentOrderStatus } from './intent-order-status';
import type { IntentOrder } from './intent-order';
import {
fetchBridgeTxStatus,
getStatusRequestWithSrcTxHash,
Expand Down Expand Up @@ -121,8 +118,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid

readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;

#intentManager?: IntentManager;

readonly #estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;

readonly #trace: TraceCallback;
Expand Down Expand Up @@ -205,7 +200,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
this.getBridgeHistoryItemByTxMetaId.bind(this),
);

this.#intentManager = new IntentManager();
// Set interval
this.setIntervalLength(REFRESH_INTERVAL_MS);

Expand Down Expand Up @@ -294,15 +288,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
});
};

/**
* Set the intent manager instance for handling intent operations
*
* @param intentManager - The intent manager instance
*/
setIntentManager(intentManager: IntentManager): void {
this.#intentManager = intentManager;
}

wipeBridgeStatus = ({
address,
ignoreNetwork,
Expand Down Expand Up @@ -710,11 +695,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
readonly #fetchIntentOrderStatus = async ({
bridgeTxMetaId,
}: FetchBridgeTxStatusArgs) => {
if (!this.#intentManager) {
console.warn('Intent manager not available for status polling');
return;
}

const { txHistory } = this.state;
const historyItem = txHistory[bridgeTxMetaId];
if (!historyItem) {
Expand All @@ -727,16 +707,20 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
}

try {
const orderUid = bridgeTxMetaId.replace(/^intent:/u, '');
const orderId = bridgeTxMetaId.replace(/^intent:/u, '');
const { srcChainId } = historyItem.quote;

// Extract provider name from order metadata or default to empty and let intent manager throw error
// Extract provider name from order metadata or default to empty
const providerName = historyItem.quote.intent?.protocol || '';

const intentOrder = await this.#intentManager.getOrderStatus(
orderUid,
const intentApi = new IntentApiImpl(
this.#config.customBridgeApiBaseUrl,
this.#fetchFn,
);
const intentOrder = await intentApi.getOrderStatus(
orderId,
providerName,
srcChainId,
srcChainId.toString(),
);

// Update bridge history with intent order status
Expand Down Expand Up @@ -1511,10 +1495,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
}): Promise<Pick<TransactionMeta, 'id' | 'chainId' | 'type' | 'status'>> => {
const { quoteResponse, signature, accountAddress } = params;

if (!this.#intentManager) {
throw new Error('Intent manager not initialized');
}

// Build pre-confirmation properties for error tracking parity with submitTx
const account = this.messagingSystem.call(
'AccountsController:getAccountByAddress',
Expand Down Expand Up @@ -1576,16 +1556,21 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
intent,
);

// Submit intent order using the intent manager
const chainId = quoteResponse.quote.srcChainId;

const submissionParams = {
quote: intentQuote,
chainId: chainId.toString(),
quoteId: intentQuote.id,
signature,
order: intentQuote.metadata.order,
userAddress: accountAddress,
} as IntentSubmissionParams;
const intentOrder =
await this.#intentManager.submitIntent(submissionParams);
};
const intentApi = new IntentApiImpl(
this.#config.customBridgeApiBaseUrl,
this.#fetchFn,
);
const intentOrder = await intentApi.submitIntent(submissionParams);

const chainId = quoteResponse.quote.srcChainId;
const orderUid = intentOrder.id;

// Determine transaction type: swap for same-chain, bridge for cross-chain
Expand Down Expand Up @@ -1673,7 +1658,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid

// Record in bridge history with actual transaction metadata
try {
// Use intent: prefix for intent transactions to route to intent manager
// Use 'intent:' prefix for intent transactions
const bridgeHistoryKey = `intent:${orderUid}`;

// Create a bridge transaction metadata that includes the original txId
Expand Down
51 changes: 51 additions & 0 deletions packages/bridge-status-controller/src/intent-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { FetchFunction } from './types';

export interface IntentSubmissionParams {
chainId: string;
quoteId: string;
signature: string;
order: any;
userAddress: string;
}

export interface IntentApi {
submitIntent(params: IntentSubmissionParams): Promise<any>;
}

export class IntentApiImpl implements IntentApi {
private baseUrl: string;
private fetchFn: FetchFunction;

constructor(baseUrl: string, fetchFn: FetchFunction) {
this.baseUrl = baseUrl;
this.fetchFn = fetchFn;
}

async submitIntent(params: IntentSubmissionParams): Promise<any> {
const endpoint = `${this.baseUrl}/submitOrder`;
const response = (await this.fetchFn(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params),
})) as Response;
if (!response.ok) {
throw new Error(`Failed to submit intent: ${response.statusText}`);
}
return response.json();
}

async getOrderStatus(
orderId: string,
aggregatorId: string,
chainId: string,
): Promise<any> {
const endpoint = `${this.baseUrl}/getOrderStatus?orderId=${orderId}&aggregatorId=${encodeURIComponent(aggregatorId)}&chainId=${chainId}`;
const response = (await this.fetchFn(endpoint, {
method: 'GET',
})) as Response;
if (!response.ok) {
throw new Error(`Failed to get order status: ${response.statusText}`);
}
return response.json();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum IntentOrderStatus {
PENDING = 'pending',
SUBMITTED = 'submitted',
CONFIRMED = 'confirmed',
COMPLETED = 'completed',
FAILED = 'failed',
CANCELLED = 'cancelled',
EXPIRED = 'expired',
}
10 changes: 10 additions & 0 deletions packages/bridge-status-controller/src/intent-order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IntentOrderStatus } from './intent-order-status';

export interface IntentOrder {
id: string;
status: IntentOrderStatus;
txHash?: string;
metadata: {
txHashes?: string[] | string;
};
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3822,25 +3822,25 @@ __metadata:

"@metamask/intent-manager@file:../Intent-manager::locator=%40metamask%2Fbridge-controller%40workspace%3Apackages%2Fbridge-controller":
version: 1.0.0
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=d3eeb0&locator=%40metamask%2Fbridge-controller%40workspace%3Apackages%2Fbridge-controller"
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=bf88dd&locator=%40metamask%2Fbridge-controller%40workspace%3Apackages%2Fbridge-controller"
dependencies:
"@metamask/base-controller": "npm:^8.3.0"
"@metamask/controller-utils": "npm:^11.12.0"
"@metamask/superstruct": "npm:^3.1.0"
"@metamask/utils": "npm:^11.4.2"
checksum: 10/e2b4bc4c21e3ec29c5db997e6255eab08beb5c4f2180423842acc9268b45ac3906e3fee2b418ec737033ccbe2de6ba52551352111ac55edf526614e8a734cce9
checksum: 10/45f9c1dcf7da910d866f675473313fdce5d9e1e67008861c43912345d2e0903a44a8167763b74c7a86c89fe9d818d06c3d99788d102f81893104b23773a94acd
languageName: node
linkType: hard

"@metamask/intent-manager@file:../Intent-manager::locator=%40metamask%2Fbridge-status-controller%40workspace%3Apackages%2Fbridge-status-controller":
version: 1.0.0
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=d3eeb0&locator=%40metamask%2Fbridge-status-controller%40workspace%3Apackages%2Fbridge-status-controller"
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=bf88dd&locator=%40metamask%2Fbridge-status-controller%40workspace%3Apackages%2Fbridge-status-controller"
dependencies:
"@metamask/base-controller": "npm:^8.3.0"
"@metamask/controller-utils": "npm:^11.12.0"
"@metamask/superstruct": "npm:^3.1.0"
"@metamask/utils": "npm:^11.4.2"
checksum: 10/e2b4bc4c21e3ec29c5db997e6255eab08beb5c4f2180423842acc9268b45ac3906e3fee2b418ec737033ccbe2de6ba52551352111ac55edf526614e8a734cce9
checksum: 10/45f9c1dcf7da910d866f675473313fdce5d9e1e67008861c43912345d2e0903a44a8167763b74c7a86c89fe9d818d06c3d99788d102f81893104b23773a94acd
languageName: node
linkType: hard

Expand Down
Loading