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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/core-monorepo",
"version": "596.0.0",
"version": "598.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/account-tree-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-api": "^21.0.0",
"@metamask/keyring-controller": "^23.1.0",
"@metamask/multichain-account-service": "^1.4.0",
"@metamask/multichain-account-service": "^1.5.0",
"@metamask/profile-sync-controller": "^25.1.0",
"@metamask/providers": "^22.1.0",
"@metamask/snaps-controllers": "^14.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@
"@metamask/keyring-controller": "^23.1.0",
"@metamask/keyring-internal-api": "^9.0.0",
"@metamask/keyring-snap-client": "^8.0.0",
"@metamask/multichain-account-service": "^1.4.0",
"@metamask/multichain-account-service": "^1.5.0",
"@metamask/network-controller": "^24.2.0",
"@metamask/permission-controller": "^11.0.6",
"@metamask/phishing-controller": "^14.0.0",
"@metamask/preferences-controller": "^20.0.1",
"@metamask/providers": "^22.1.0",
"@metamask/snaps-controllers": "^14.0.1",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
"@types/node": "^16.18.54",
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@metamask/remote-feature-flag-controller": "^1.7.0",
"@metamask/snaps-controllers": "^14.0.1",
"@metamask/superstruct": "^3.1.0",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-status-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@metamask/gas-fee-controller": "^24.0.0",
"@metamask/network-controller": "^24.2.0",
"@metamask/snaps-controllers": "^14.0.1",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/earn-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@metamask/account-tree-controller": "^1.4.0",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/network-controller": "^24.2.0",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/eip-5792-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Bump `@metamask/utils` from `^11.8.0` to `^11.8.1` ([#6708](https://github.com/MetaMask/core/pull/6708))
- Bump `@metamask/transaction-controller` from `^60.4.0` to `^60.5.0` ([#6708](https://github.com/MetaMask/core/pull/6733))
- Bump `@metamask/transaction-controller` from `^60.4.0` to `^60.6.0` ([#6708](https://github.com/MetaMask/core/pull/6733), [#6771](https://github.com/MetaMask/core/pull/6771))

## [1.2.0]

Expand Down
2 changes: 1 addition & 1 deletion packages/eip-5792-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@metamask/eth-json-rpc-middleware": "^17.0.1",
"@metamask/superstruct": "^3.1.0",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@metamask/utils": "^11.8.1",
"lodash": "^4.17.21",
"uuid": "^8.3.2"
Expand Down
10 changes: 9 additions & 1 deletion packages/multichain-account-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.5.0]

### Added

- Add an optional `options` parameter to `MultichainAccountWallet.createMultichainAccountGroup()` ([#6759](https://github.com/MetaMask/core/pull/6759))
- Introduces `options.waitForAllProvidersToFinishCreatingAccounts`, that will make `createMultichainAccountGroup` await either only the EVM provider or all the providers to have created their accounts depending on the value. Defaults to `false` (only awaits for EVM accounts creation by default).

## [1.4.0]

### Changed
Expand Down Expand Up @@ -208,7 +215,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `MultichainAccountService` ([#6141](https://github.com/MetaMask/core/pull/6141)), ([#6165](https://github.com/MetaMask/core/pull/6165))
- This service manages multichain accounts/wallets.

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@1.4.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@1.5.0...HEAD
[1.5.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@1.4.0...@metamask/multichain-account-service@1.5.0
[1.4.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@1.3.0...@metamask/multichain-account-service@1.4.0
[1.3.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@1.2.0...@metamask/multichain-account-service@1.3.0
[1.2.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-account-service@1.1.0...@metamask/multichain-account-service@1.2.0
Expand Down
2 changes: 1 addition & 1 deletion packages/multichain-account-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/multichain-account-service",
"version": "1.4.0",
"version": "1.5.0",
"description": "Service to manage multichain accounts",
"keywords": [
"MetaMask",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,32 @@ describe('MultichainAccountWallet', () => {
expect(
await wallet.createMultichainAccountGroup(groupIndex),
).toBeDefined();
await new Promise(process.nextTick);
expect(mockSolProviderError).toHaveBeenCalled();
});

it('fails to create an account group if any of the provider fails to create its account and waitForAllProvidersToFinishCreatingAccounts is true', async () => {
const groupIndex = 1;

const mockEvmAccount = MockAccountBuilder.from(MOCK_HD_ACCOUNT_1)
.withEntropySource(MOCK_HD_KEYRING_1.metadata.id)
.withGroupIndex(0)
.get();
const { wallet, providers } = setup({
accounts: [[mockEvmAccount]], // 1 provider
});
const [provider] = providers;
provider.createAccounts.mockRejectedValueOnce(
new Error('Unable to create accounts'),
);

await expect(
wallet.createMultichainAccountGroup(groupIndex, {
waitForAllProvidersToFinishCreatingAccounts: true,
}),
).rejects.toThrow(
'Unable to create multichain account group for index: 1',
);
});
});

describe('createNextMultichainAccountGroup', () => {
Expand Down
108 changes: 76 additions & 32 deletions packages/multichain-account-service/src/MultichainAccountWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,22 @@ export class MultichainAccountWallet<
* NOTE: This operation WILL lock the wallet's mutex.
*
* @param groupIndex - The group index to use.
* @throws If any of the account providers fails to create their accounts.
* @param options - Options to configure the account creation.
* @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all
* account providers to finish creating their accounts before returning. If `false`, only
* the EVM provider will be awaited, while all other providers will create their accounts
* in the background. Defaults to `false`.
* @throws If any of the account providers fails to create their accounts and
* the `waitForAllProvidersToFinishCreatingAccounts` option is set to `true`. If `false`,
* errors from non-EVM providers will be logged but ignored, and only errors from the
* EVM provider will be thrown.
* @returns The multichain account group for this group index.
*/
async createMultichainAccountGroup(
groupIndex: number,
options: {
waitForAllProvidersToFinishCreatingAccounts?: boolean;
} = { waitForAllProvidersToFinishCreatingAccounts: false },
): Promise<MultichainAccountGroup<Account>> {
return await this.#withLock('in-progress:create-accounts', async () => {
const nextGroupIndex = this.getNextGroupIndex();
Expand All @@ -324,41 +335,72 @@ export class MultichainAccountWallet<

this.#log(`Creating new group for index ${groupIndex}...`);

// Extract the EVM provider from the list of providers.
// We will only await the EVM provider to create its accounts, while
// all other providers will be started in the background.
const [evmProvider, ...otherProviders] = this.#providers;
assert(
evmProvider instanceof EvmAccountProvider,
'EVM account provider must be first',
);
if (options?.waitForAllProvidersToFinishCreatingAccounts) {
// Create account with all providers and await them.
const results = await Promise.allSettled(
this.#providers.map((provider) =>
provider.createAccounts({
entropySource: this.#entropySource,
groupIndex,
}),
),
);

// Create account with the EVM provider first and await it.
// If it fails, we don't start creating accounts with other providers.
try {
await evmProvider.createAccounts({
entropySource: this.#entropySource,
groupIndex,
});
} catch (error) {
const errorMessage = `Unable to create multichain account group for index: ${groupIndex} with provider "${evmProvider.getName()}". Error: ${(error as Error).message}`;
this.#log(`${ERROR_PREFIX} ${errorMessage}:`, error);
throw new Error(errorMessage);
}
// If any of the provider failed to create their accounts, then we consider the
// multichain account group to have failed too.
if (results.some((result) => result.status === 'rejected')) {
// NOTE: Some accounts might still have been created on other account providers. We
// don't rollback them.
const error = `Unable to create multichain account group for index: ${groupIndex}`;

let message = `${error}:`;
for (const result of results) {
if (result.status === 'rejected') {
message += `\n- ${result.reason}`;
}
}
this.#log(`${WARNING_PREFIX} ${message}`);
console.warn(message);

throw new Error(error);
}
} else {
// Extract the EVM provider from the list of providers.
// We will only await the EVM provider to create its accounts, while
// all other providers will be started in the background.
const [evmProvider, ...otherProviders] = this.#providers;
assert(
evmProvider instanceof EvmAccountProvider,
'EVM account provider must be first',
);

// Create account with other providers in the background
otherProviders.forEach((provider) => {
provider
.createAccounts({
// Create account with the EVM provider first and await it.
// If it fails, we don't start creating accounts with other providers.
try {
await evmProvider.createAccounts({
entropySource: this.#entropySource,
groupIndex,
})
.catch((error) => {
// Log errors from background providers but don't fail the operation
const errorMessage = `Could not to create account with provider "${provider.getName()}" for multichain account group index: ${groupIndex}`;
this.#log(`${WARNING_PREFIX} ${errorMessage}:`, error);
});
});
} catch (error) {
const errorMessage = `Unable to create multichain account group for index: ${groupIndex} with provider "${evmProvider.getName()}". Error: ${(error as Error).message}`;
this.#log(`${ERROR_PREFIX} ${errorMessage}:`, error);
throw new Error(errorMessage);
}

// Create account with other providers in the background
otherProviders.forEach((provider) => {
provider
.createAccounts({
entropySource: this.#entropySource,
groupIndex,
})
.catch((error) => {
// Log errors from background providers but don't fail the operation
const errorMessage = `Could not to create account with provider "${provider.getName()}" for multichain account group index: ${groupIndex}`;
this.#log(`${WARNING_PREFIX} ${errorMessage}:`, error);
});
});
}

// --------------------------------------------------------------------------------
// READ THIS CAREFULLY:
Expand Down Expand Up @@ -419,7 +461,9 @@ export class MultichainAccountWallet<
async createNextMultichainAccountGroup(): Promise<
MultichainAccountGroup<Account>
> {
return this.createMultichainAccountGroup(this.getNextGroupIndex());
return this.createMultichainAccountGroup(this.getNextGroupIndex(), {
waitForAllProvidersToFinishCreatingAccounts: true,
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/network-enablement-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@metamask/auto-changelog": "^3.4.4",
"@metamask/multichain-network-controller": "^1.0.0",
"@metamask/network-controller": "^24.2.0",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/phishing-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/shield-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/signature-controller": "^34.0.0",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@ts-bridge/cli": "^0.6.1",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [60.6.0]

### Added

- Expose `addTransaction` and `addTransactionBatch` methods through the messenger ([#6749](https://github.com/MetaMask/core/pull/6749))
Expand Down Expand Up @@ -1841,7 +1843,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

All changes listed after this point were applied to this package following the monorepo conversion.

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@60.5.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@60.6.0...HEAD
[60.6.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@60.5.0...@metamask/transaction-controller@60.6.0
[60.5.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@60.4.0...@metamask/transaction-controller@60.5.0
[60.4.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@60.3.0...@metamask/transaction-controller@60.4.0
[60.3.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@60.2.0...@metamask/transaction-controller@60.3.0
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/transaction-controller",
"version": "60.5.0",
"version": "60.6.0",
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
"keywords": [
"MetaMask",
Expand Down
2 changes: 1 addition & 1 deletion packages/user-operation-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@metamask/gas-fee-controller": "^24.0.0",
"@metamask/keyring-controller": "^23.1.0",
"@metamask/network-controller": "^24.2.0",
"@metamask/transaction-controller": "^60.5.0",
"@metamask/transaction-controller": "^60.6.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
Loading