-
-
Notifications
You must be signed in to change notification settings - Fork 256
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!
## Explanation Release for `@metamask/eip-5792-middleware` - Add `auxiliaryFunds` + `requiredAssets` support defined under [ERC-7682](https://eips.ethereum.org/EIPS/eip-7682) ([#6623](#6623)) - Bump `@metamask/transaction-controller` from `^60.2.0` to `^60.4.0` ([#6561](#6561), [#6641](#6641)) - Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](#6588)) <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Fixes https://consensyssoftware.atlassian.net/browse/WAPI-409 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
…dleware` (#6623) ## Explanation This PR integrates the `auxiliaryFunds` and `requiredAssets` capabilities defined under [ERC-7682](https://eips.ethereum.org/EIPS/eip-7682) to enable auxiliary funds flows and improve capability consistency across clients. <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Fixes https://consensyssoftware.atlassian.net/browse/WAPI-409 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
## Explanation Release for `@metamask/eip-5792-middleware` - Add `auxiliaryFunds` + `requiredAssets` support defined under [ERC-7682](https://eips.ethereum.org/EIPS/eip-7682) ([#6623](#6623)) - Bump `@metamask/transaction-controller` from `^60.2.0` to `^60.4.0` ([#6561](#6561), [#6641](#6641)) - Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](#6588)) <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Fixes https://consensyssoftware.atlassian.net/browse/WAPI-409 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
| 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