-
-
Notifications
You must be signed in to change notification settings - Fork 268
feat: add auxiliaryFunds + requiredAssets support to eip5792-middleware
#6623
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
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
auxiliaryFunds + requiredAssets support to eip5792-middleware + initial client integrationauxiliaryFunds + requiredAssets support to eip5792-middleware
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| if (!isAuxiliaryFundsSupported(chainId)) { | ||
| throw new JsonRpcError( | ||
| EIP7682ErrorCode.UnsupportedChain, | ||
| `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`, | |
| `The wallet does not support the auxiliary funds capability on the requested chain: ${chainId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see this was what was specified in the ERC https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7682.md#error-codes
🤔 Ok ignore this for now I guess, but I feel like we should change it in the ERC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ticket for it here https://consensyssoftware.atlassian.net/browse/WAPI-725
| if (!isSupportedAccount) { | ||
| throw new JsonRpcError( | ||
| EIP5792ErrorCode.UnsupportedNonOptionalCapability, | ||
| `Unsupported non-optional capabilities: ${SupportedCapabilities.AuxiliaryFunds}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `Unsupported non-optional capabilities: ${SupportedCapabilities.AuxiliaryFunds}`, | |
| `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is actually wrong according to the spec: https://eips.ethereum.org/EIPS/eip-5792#error-codes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export enum EIP7682ErrorCode { | ||
| UnsupportedAsset = 5771, | ||
| UnsupportedChain = 5772, | ||
| MalformedRequiredAssets = 5773, | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| return { | ||
| ...group[0], | ||
| amount: add0x(totalAmount.toString(16)) as Hex, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm do we not have a toHex helper that would also get the typing right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually add0x already returns an Hex, so we don't need to typecast or use toHex at all.
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| expect(result).toBeDefined(); | ||
| expect(payload.capabilities?.auxiliaryFunds?.requiredAssets?.length).toBe( | ||
| 1, | ||
| ); | ||
| expect( | ||
| payload.capabilities?.auxiliaryFunds?.requiredAssets?.[0].amount, | ||
| ).toBe('0x5'); | ||
| expect( | ||
| payload.capabilities?.auxiliaryFunds?.requiredAssets?.[0].address, | ||
| ).toBe('0x123'); | ||
| expect( | ||
| payload.capabilities?.auxiliaryFunds?.requiredAssets?.[0].standard, | ||
| ).toBe('erc20'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total nit:
| expect(result).toBeDefined(); | |
| expect(payload.capabilities?.auxiliaryFunds?.requiredAssets?.length).toBe( | |
| 1, | |
| ); | |
| expect( | |
| payload.capabilities?.auxiliaryFunds?.requiredAssets?.[0].amount, | |
| ).toBe('0x5'); | |
| expect( | |
| payload.capabilities?.auxiliaryFunds?.requiredAssets?.[0].address, | |
| ).toBe('0x123'); | |
| expect( | |
| payload.capabilities?.auxiliaryFunds?.requiredAssets?.[0].standard, | |
| ).toBe('erc20'); | |
| expect(result).toBeDefined(); | |
| const requiredAssets = payload.capabilities?.auxiliaryFunds?.requiredAssets; | |
| expect(requiredAssets).toHaveLength(1); | |
| const [asset] = requiredAssets ?? []; | |
| expect(asset).toMatchObject({ | |
| amount: '0x5', | |
| address: '0x123', | |
| standard: 'erc20', | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
|
|
||
| for (const asset of auxiliaryFunds.requiredAssets) { | ||
| if (asset.standard !== 'erc20') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a tokenStandard enum we could use here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a few competing ones around various modules/repos 🤔
Ok this is fine for now
|
|
||
| const totalAmount = group.reduce((sum, asset) => { | ||
| return sum + BigInt(asset.amount); | ||
| }, 0n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL -> I haven't used BigInt before!
adonesky1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| chainIds: Hex[], | ||
| ) => Promise<Record<string, boolean>>; | ||
| /** Function to validate if auxiliary funds capability is supported. */ | ||
| isAuxiliaryFundsSupported: (chainId: Hex) => boolean; |
There was a problem hiding this comment.
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
Explanation
This PR integrates the
auxiliaryFundsandrequiredAssetscapabilities defined under ERC-7682 to enable auxiliary funds flows and improve capability consistency across clients.References
Checklist