Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1f07924
feat: add isAuxiliaryFundsSupported hook to getCapabilities
ffmcgee725 Sep 16, 2025
fcd8531
feat: filter out unsupported hardware wallet accounts
ffmcgee725 Sep 16, 2025
e85a685
debug: log
ffmcgee725 Sep 16, 2025
0351f46
feat: add guards for eip-7682 requiredAssets optional param
ffmcgee725 Sep 16, 2025
c896a02
Merge branch 'main' into jc/WAPI-409
ffmcgee725 Sep 16, 2025
0b55763
test: bump test coverage
ffmcgee725 Sep 16, 2025
b06a708
docs: update CHANGELOG.md
ffmcgee725 Sep 16, 2025
ef2ad99
Merge branch 'main' into jc/WAPI-409
ffmcgee725 Sep 16, 2025
6301d16
refactor: minor adjustments and documentation update
ffmcgee725 Sep 17, 2025
887747d
test: update processSendCalls.test.ts
ffmcgee725 Sep 17, 2025
7e8f0b7
fix: deduplicate requiredAssets & adjust auxFunds validation
ffmcgee725 Sep 17, 2025
3fc5fab
yarn
ffmcgee725 Sep 17, 2025
0c2c114
jest
ffmcgee725 Sep 17, 2025
2b1cfc6
test: bump up stmts test cov for processSendCAlls.test.ts
ffmcgee725 Sep 17, 2025
057fd98
Merge branch 'main' into jc/WAPI-409
ffmcgee725 Sep 17, 2025
5443291
refactor: extract auxiliaryFunds string into enum
ffmcgee725 Sep 17, 2025
c823199
refactor: rename function
ffmcgee725 Sep 17, 2025
53db0c9
merge main fix conflicts
ffmcgee725 Sep 17, 2025
c22188f
Merge branch 'main' into jc/WAPI-409
ffmcgee725 Sep 17, 2025
80eba8b
refactor: address code review issues
ffmcgee725 Sep 18, 2025
cb2adae
Merge branch 'main' into jc/WAPI-409
ffmcgee725 Sep 18, 2025
f2955b4
test: update
ffmcgee725 Sep 18, 2025
6b2341f
chore: update CHANGELOG.md
ffmcgee725 Sep 18, 2025
67be6a9
test: address nit
ffmcgee725 Sep 18, 2025
20b3c3d
Merge branch 'main' into jc/WAPI-409
adonesky1 Sep 18, 2025
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
1 change: 1 addition & 0 deletions packages/eip-5792-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Add `auxiliaryFunds` + `requiredAssets` support defined under [ERC-7682](https://eips.ethereum.org/EIPS/eip-7682) ([#6623](https://github.com/MetaMask/core/pull/6623))
- Bump `@metamask/transaction-controller` from `^60.2.0` to `^60.4.0` ([#6561](https://github.com/MetaMask/core/pull/6561), [#6641](https://github.com/MetaMask/core/pull/6641))
- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))

Expand Down
1 change: 1 addition & 0 deletions packages/eip-5792-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@metamask/superstruct": "^3.1.0",
"@metamask/transaction-controller": "^60.4.0",
"@metamask/utils": "^11.8.0",
"lodash": "^4.17.21",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions packages/eip-5792-middleware/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export enum MessageType {
SendTransaction = 'eth_sendTransaction',
}

export enum SupportedCapabilities {
AuxiliaryFunds = 'auxiliaryFunds',
}

// To be moved to @metamask/rpc-errors in future.
export enum EIP5792ErrorCode {
UnsupportedNonOptionalCapability = 5700,
Expand All @@ -19,6 +23,13 @@ export enum EIP5792ErrorCode {
RejectedUpgrade = 5750,
}

// To be moved to @metamask/rpc-errors in future.
export enum EIP7682ErrorCode {
UnsupportedAsset = 5771,
UnsupportedChain = 5772,
MalformedRequiredAssets = 5773,
}
Comment on lines +27 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make this an object with both codes and messages?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you're following the pattern above with EIP5792ErrorCode...

Weird pattern to decouple message + code IMO

Up to you we could change it here or just do that in the future

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝🏾 exactly, following what was previously established. I'm good with refactoring this in a tech debt issue which makes sense when these are moved to @metamask/rpc-errors package. Should I put an issue on our board for moving these out of here and making these objects with both code and messages ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes lets create a ticket for this 🙏

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// wallet_getCallStatus
export enum GetCallsStatusCode {
PENDING = 100,
Expand Down
117 changes: 117 additions & 0 deletions packages/eip-5792-middleware/src/hooks/getCapabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe('EIP-5792', () => {
PreferencesControllerGetStateAction['handler']
> = jest.fn();

const isAuxiliaryFundsSupportedMock: jest.Mock = jest.fn();

let messenger: EIP5792Messenger;

const getCapabilitiesHooks = {
Expand All @@ -53,6 +55,7 @@ describe('EIP-5792', () => {
getIsSmartTransaction: getIsSmartTransactionMock,
isRelaySupported: isRelaySupportedMock,
getSendBundleSupportedChains: getSendBundleSupportedChainsMock,
isAuxiliaryFundsSupported: isAuxiliaryFundsSupportedMock,
};

beforeEach(() => {
Expand Down Expand Up @@ -425,5 +428,119 @@ describe('EIP-5792', () => {
},
});
});

it('fetches all network configurations when chainIds is undefined', async () => {
const networkConfigurationsMock = {
'0x1': { chainId: '0x1' },
'0x89': { chainId: '0x89' },
};

messenger.registerActionHandler(
'NetworkController:getState',
jest.fn().mockReturnValue({
networkConfigurationsByChainId: networkConfigurationsMock,
}),
);

isAtomicBatchSupportedMock.mockResolvedValueOnce([
{
chainId: '0x1',
delegationAddress: DELEGATION_ADDRESS_MOCK,
isSupported: true,
},
{
chainId: '0x89',
delegationAddress: undefined,
isSupported: false,
upgradeContractAddress: DELEGATION_ADDRESS_MOCK,
},
]);

const capabilities = await getCapabilities(
getCapabilitiesHooks,
messenger,
FROM_MOCK,
undefined,
);

expect(capabilities).toStrictEqual({
'0x1': {
atomic: {
status: 'supported',
},
alternateGasFees: {
supported: true,
},
},
'0x89': {
atomic: {
status: 'ready',
},
},
});
});

it('includes auxiliary funds capability when supported', async () => {
isAtomicBatchSupportedMock.mockResolvedValueOnce([
{
chainId: CHAIN_ID_MOCK,
delegationAddress: DELEGATION_ADDRESS_MOCK,
isSupported: true,
},
]);

isAuxiliaryFundsSupportedMock.mockReturnValue(true);

const capabilities = await getCapabilities(
getCapabilitiesHooks,
messenger,
FROM_MOCK,
[CHAIN_ID_MOCK],
);

expect(capabilities).toStrictEqual({
[CHAIN_ID_MOCK]: {
atomic: {
status: 'supported',
},
alternateGasFees: {
supported: true,
},
auxiliaryFunds: {
supported: true,
},
},
});
});

it('does not include auxiliary funds capability when not supported', async () => {
isAtomicBatchSupportedMock.mockResolvedValueOnce([
{
chainId: CHAIN_ID_MOCK,
delegationAddress: DELEGATION_ADDRESS_MOCK,
isSupported: true,
},
]);

isAuxiliaryFundsSupportedMock.mockReturnValue(false);

const capabilities = await getCapabilities(
getCapabilitiesHooks,
messenger,
FROM_MOCK,
[CHAIN_ID_MOCK],
);

expect(capabilities).toStrictEqual({
[CHAIN_ID_MOCK]: {
atomic: {
status: 'supported',
},
alternateGasFees: {
supported: true,
},
},
});
});
});
});
16 changes: 13 additions & 3 deletions packages/eip-5792-middleware/src/hooks/getCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type GetCapabilitiesHooks = {
getSendBundleSupportedChains: (
chainIds: Hex[],
) => Promise<Record<string, boolean>>;
/** Function to validate if auxiliary funds capability is supported. */
isAuxiliaryFundsSupported: (chainId: Hex) => boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been documented as a breaking change

};

/**
Expand All @@ -48,6 +50,7 @@ export async function getCapabilities(
isAtomicBatchSupported,
isRelaySupported,
getSendBundleSupportedChains,
isAuxiliaryFundsSupported,
} = hooks;

let chainIdsNormalized = chainIds?.map(
Expand Down Expand Up @@ -106,15 +109,22 @@ export async function getCapabilities(
}

const status = isSupported ? 'supported' : 'ready';
const hexChainId = chainId as Hex;

if (acc[chainId as Hex] === undefined) {
acc[chainId as Hex] = {};
if (acc[hexChainId] === undefined) {
acc[hexChainId] = {};
}

acc[chainId as Hex].atomic = {
acc[hexChainId].atomic = {
status,
};

if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {
acc[hexChainId].auxiliaryFunds = {
supported: true,
};
}

return acc;
}, alternateGasFeesAcc);
}
Expand Down
Loading