Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Bump @metamask/smart-transactions-controller from 11.0.0 to ^13.0.0 #11140

Merged
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d233289
Bump `@metamask/base-controller` from `^6.0.0` to `^7.0.0`
MajorLift Sep 13, 2024
779ee0b
Add temporary `ts-expect-error` directives for base-controller versio…
MajorLift Sep 13, 2024
609b95e
Replace all `ts-ignore` base-controller version mismatch directives w…
MajorLift Sep 13, 2024
3e57a5e
Add `ts-expect-error` directive for `SelectedNetworkController`
MajorLift Sep 13, 2024
cbd428d
Bump `@metamask/smart-transactions-controller` from `11.0.0` to `^13.…
MajorLift Sep 10, 2024
40cb9c3
Fix breaking changes in `SmartTransactionsController` instantiation
MajorLift Sep 13, 2024
8cf9b25
Add `SmartTransactions{Actions,Events}` to `Global{Actions,Events}` a…
MajorLift Sep 13, 2024
3bb1539
Define restricted messenger for `SmartTransactionsController` and pas…
MajorLift Sep 12, 2024
7cfc9b4
fix: unit tests
cryptodev-2s Sep 18, 2024
b683806
Merge remote-tracking branch 'origin/main' into jongsun/chore/bump/sm…
cryptodev-2s Sep 18, 2024
714caf6
fix: engine
cryptodev-2s Sep 18, 2024
8de46f5
fix: engine unit tests
cryptodev-2s Sep 18, 2024
efb07fd
fix: initial background state for smart transactions controller
cryptodev-2s Sep 18, 2024
c88b9a9
fix: remove useless messenger
cryptodev-2s Sep 18, 2024
9d0334d
Merge branch 'main' into jongsun/chore/bump/smart-transactions-contro…
cryptodev-2s Sep 18, 2024
f0fee2b
Merge branch 'main' into jongsun/chore/bump/smart-transactions-contro…
legobeat Sep 19, 2024
61be06f
Merge branch 'main' into jongsun/chore/bump/smart-transactions-contro…
cryptodev-2s Sep 19, 2024
1105984
Merge branch 'main' into jongsun/chore/bump/smart-transactions-contro…
cryptodev-2s Sep 19, 2024
6b2fd98
fix: engine state change listener
cryptodev-2s Sep 19, 2024
9be130a
fix: remove forgotten console log
cryptodev-2s Sep 19, 2024
44b108d
Merge remote-tracking branch 'origin/main' into jongsun/chore/bump/sm…
cryptodev-2s Sep 20, 2024
f45252c
Merge remote-tracking branch 'origin/main' into jongsun/chore/bump/sm…
cryptodev-2s Sep 20, 2024
ef72a30
Merge branch 'main' into jongsun/chore/bump/smart-transactions-contro…
cryptodev-2s Sep 20, 2024
cc44b52
Merge remote-tracking branch 'origin/main' into jongsun/chore/bump/sm…
cryptodev-2s Sep 20, 2024
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
34 changes: 1 addition & 33 deletions app/core/Engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,7 @@ describe('Engine', () => {
const engine = Engine.init({});
const initialBackgroundState = engine.datamodel.state;

expect(initialBackgroundState).toStrictEqual({
...backgroundState,

// JSON cannot store the value undefined, so we append it here
SmartTransactionsController: {
smartTransactionsState: {
fees: {
approvalTxFees: undefined,
tradeTxFees: undefined,
},
feesByChainId: {
'0x1': {
approvalTxFees: undefined,
tradeTxFees: undefined,
},
'0xaa36a7': {
approvalTxFees: undefined,
tradeTxFees: undefined,
},
},
liveness: true,
livenessByChainId: {
'0x1': true,
'0xaa36a7': true,
},
smartTransactions: {
'0x1': [],
},
userOptIn: undefined,
userOptInV2: undefined,
},
},
});
expect(initialBackgroundState).toStrictEqual(backgroundState);
});

it('setSelectedAccount throws an error if no account exists for the given address', () => {
Expand Down
98 changes: 54 additions & 44 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,30 @@ import {
networkIdUpdated,
networkIdWillUpdate,
} from '../core/redux/slices/inpageProvider';
import SmartTransactionsController from '@metamask/smart-transactions-controller';
import SmartTransactionsController, {
type SmartTransactionsControllerActions,
type SmartTransactionsControllerEvents,
type SmartTransactionsControllerState,
} from '@metamask/smart-transactions-controller';
import { getAllowedSmartTransactionsChainIds } from '../../app/constants/smartTransactions';
import { selectShouldUseSmartTransaction } from '../selectors/smartTransactionsController';
import { selectSwapsChainFeatureFlags } from '../reducers/swaps';
import { SmartTransactionStatuses } from '@metamask/smart-transactions-controller/dist/types';
import { submitSmartTransactionHook } from '../util/smart-transactions/smart-publish-hook';
import { SmartTransactionsControllerState } from '@metamask/smart-transactions-controller/dist/SmartTransactionsController';
import { zeroAddress } from 'ethereumjs-util';
import { toChecksumHexAddress } from '@metamask/controller-utils';
import { ExtendedControllerMessenger } from './ExtendedControllerMessenger';
import EthQuery from '@metamask/eth-query';
import { TransactionControllerOptions } from '@metamask/transaction-controller/dist/types/TransactionController';
import DomainProxyMap from '../lib/DomainProxyMap/DomainProxyMap';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '@metamask/smart-transactions-controller/dist/constants';
import {
getSmartTransactionMetricsProperties,
getSmartTransactionMetricsSensitiveProperties,
} from '@metamask/smart-transactions-controller/dist/utils';

const NON_EMPTY = 'NON_EMPTY';

Expand Down Expand Up @@ -290,7 +301,8 @@ type GlobalActions =
| PreferencesControllerActions
| TokensControllerActions
| TokenListControllerActions
| SelectedNetworkControllerActions;
| SelectedNetworkControllerActions
| SmartTransactionsControllerActions;

type GlobalEvents =
| AddressBookControllerEvents
Expand All @@ -312,7 +324,8 @@ type GlobalEvents =
| TokensControllerEvents
| TokenListControllerEvents
| TransactionControllerEvents
| SelectedNetworkControllerEvents;
| SelectedNetworkControllerEvents
| SmartTransactionsControllerEvents;

type PermissionsByRpcMethod = ReturnType<typeof getPermissionSpecifications>;
type Permissions = PermissionsByRpcMethod[keyof PermissionsByRpcMethod];
Expand Down Expand Up @@ -1222,6 +1235,8 @@ class Engine {
smartTransactionsController: this.smartTransactionsController,
shouldUseSmartTransaction,
approvalController,
// @ts-expect-error TODO: Resolve mismatch between base-controller versions.
controllerMessenger: this.controllerMessenger,
featureFlags: selectSwapsChainFeatureFlags(store.getState()),
}) as Promise<{ transactionHash: string }>;
},
Expand Down Expand Up @@ -1273,13 +1288,20 @@ class Engine {

const codefiTokenApiV2 = new CodefiTokenPricesServiceV2();

const smartTransactionsControllerTrackMetaMetricsEvent = (params: {
event: string;
category: string;
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sensitiveProperties: any;
}) => {
const smartTransactionsControllerTrackMetaMetricsEvent = (
params: {
event: MetaMetricsEventName;
category: MetaMetricsEventCategory;
properties?: ReturnType<typeof getSmartTransactionMetricsProperties>;
sensitiveProperties?: ReturnType<
typeof getSmartTransactionMetricsSensitiveProperties
>;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: {
metaMetricsId?: string;
},
) => {
const { event, category, ...restParams } = params;

MetaMetrics.getInstance().trackEvent(
Expand All @@ -1292,41 +1314,29 @@ class Engine {
restParams,
);
};
this.smartTransactionsController = new SmartTransactionsController(
{
confirmExternalTransaction:
this.transactionController.confirmExternalTransaction.bind(
this.transactionController,
),

getNetworkClientById:
networkController.getNetworkClientById.bind(networkController),
getNonceLock: this.transactionController.getNonceLock.bind(
this.transactionController,
),
getTransactions: this.transactionController.getTransactions.bind(
this.smartTransactionsController = new SmartTransactionsController({
// @ts-expect-error TODO: resolve types
supportedChainIds: getAllowedSmartTransactionsChainIds(),
getNonceLock: this.transactionController.getNonceLock.bind(
this.transactionController,
),
confirmExternalTransaction:
this.transactionController.confirmExternalTransaction.bind(
this.transactionController,
),
onNetworkStateChange: (listener) =>
this.controllerMessenger.subscribe(
AppConstants.NETWORK_STATE_CHANGE_EVENT,
listener,
),

// TODO: Replace "any" with type
provider:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
networkController.getProviderAndBlockTracker().provider as any,

trackMetaMetricsEvent: smartTransactionsControllerTrackMetaMetricsEvent,
getMetaMetricsProps: () => Promise.resolve({}), // Return MetaMetrics props once we enable HW wallets for smart transactions.
},
{
// @ts-expect-error TODO: resolve types
supportedChainIds: getAllowedSmartTransactionsChainIds(),
},
initialState.SmartTransactionsController,
);
trackMetaMetricsEvent: smartTransactionsControllerTrackMetaMetricsEvent,
state: initialState.SmartTransactionsController,
// @ts-expect-error TODO: Resolve mismatch between base-controller versions.
messenger: this.controllerMessenger.getRestricted({
name: 'SmartTransactionsController',
allowedActions: ['NetworkController:getNetworkClientById'],
allowedEvents: ['NetworkController:stateChange'],
}),
getTransactions: this.transactionController.getTransactions.bind(
this.transactionController,
),
getMetaMetricsProps: () => Promise.resolve({}), // Return MetaMetrics props once we enable HW wallets for smart transactions.
});

const controllers: Controllers[keyof Controllers][] = [
keyringController,
Expand Down
5 changes: 4 additions & 1 deletion app/core/EngineService/EngineService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ class EngineService {
name: 'TransactionController',
key: `${engine.context.TransactionController.name}:stateChange`,
},
{ name: 'SmartTransactionsController' },
{
name: 'SmartTransactionsController',
key: `${engine.context.SmartTransactionsController.name}:stateChange`,
},
{ name: 'SwapsController' },
{
name: 'TokenListController',
Expand Down
Loading
Loading