@metamask/eip-5792-middleware 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -1
- package/dist/constants.cjs +12 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +8 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +8 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +11 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/hooks/getCapabilities.cjs +10 -4
- package/dist/hooks/getCapabilities.cjs.map +1 -1
- package/dist/hooks/getCapabilities.d.cts +2 -0
- package/dist/hooks/getCapabilities.d.cts.map +1 -1
- package/dist/hooks/getCapabilities.d.mts +2 -0
- package/dist/hooks/getCapabilities.d.mts.map +1 -1
- package/dist/hooks/getCapabilities.mjs +10 -4
- package/dist/hooks/getCapabilities.mjs.map +1 -1
- package/dist/hooks/processSendCalls.cjs +104 -13
- package/dist/hooks/processSendCalls.cjs.map +1 -1
- package/dist/hooks/processSendCalls.d.cts +2 -0
- package/dist/hooks/processSendCalls.d.cts.map +1 -1
- package/dist/hooks/processSendCalls.d.mts +2 -0
- package/dist/hooks/processSendCalls.d.mts.map +1 -1
- package/dist/hooks/processSendCalls.mjs +107 -15
- package/dist/hooks/processSendCalls.mjs.map +1 -1
- package/dist/types.cjs +6 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +25 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +25 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +6 -0
- package/dist/types.mjs.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Add `auxiliaryFunds` + `requiredAssets` support defined under [ERC-7682](https://eips.ethereum.org/EIPS/eip-7682) ([#6623](https://github.com/MetaMask/core/pull/6623))
|
|
15
|
+
- 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))
|
|
16
|
+
- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
|
|
17
|
+
|
|
10
18
|
## [1.1.0]
|
|
11
19
|
|
|
12
20
|
### Added
|
|
@@ -19,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
19
27
|
|
|
20
28
|
- Initial release ([#6458](https://github.com/MetaMask/core/pull/6458))
|
|
21
29
|
|
|
22
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/eip-5792-middleware@1.
|
|
30
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/eip-5792-middleware@1.2.0...HEAD
|
|
31
|
+
[1.2.0]: https://github.com/MetaMask/core/compare/@metamask/eip-5792-middleware@1.1.0...@metamask/eip-5792-middleware@1.2.0
|
|
23
32
|
[1.1.0]: https://github.com/MetaMask/core/compare/@metamask/eip-5792-middleware@1.0.0...@metamask/eip-5792-middleware@1.1.0
|
|
24
33
|
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/eip-5792-middleware@1.0.0
|
package/dist/constants.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetCallsStatusCode = exports.EIP5792ErrorCode = exports.MessageType = exports.KEYRING_TYPES_SUPPORTING_7702 = exports.VERSION = void 0;
|
|
3
|
+
exports.GetCallsStatusCode = exports.EIP7682ErrorCode = exports.EIP5792ErrorCode = exports.SupportedCapabilities = exports.MessageType = exports.KEYRING_TYPES_SUPPORTING_7702 = exports.VERSION = void 0;
|
|
4
4
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
5
5
|
exports.VERSION = '2.0.0';
|
|
6
6
|
exports.KEYRING_TYPES_SUPPORTING_7702 = [
|
|
@@ -11,6 +11,10 @@ var MessageType;
|
|
|
11
11
|
(function (MessageType) {
|
|
12
12
|
MessageType["SendTransaction"] = "eth_sendTransaction";
|
|
13
13
|
})(MessageType || (exports.MessageType = MessageType = {}));
|
|
14
|
+
var SupportedCapabilities;
|
|
15
|
+
(function (SupportedCapabilities) {
|
|
16
|
+
SupportedCapabilities["AuxiliaryFunds"] = "auxiliaryFunds";
|
|
17
|
+
})(SupportedCapabilities || (exports.SupportedCapabilities = SupportedCapabilities = {}));
|
|
14
18
|
// To be moved to @metamask/rpc-errors in future.
|
|
15
19
|
var EIP5792ErrorCode;
|
|
16
20
|
(function (EIP5792ErrorCode) {
|
|
@@ -19,6 +23,13 @@ var EIP5792ErrorCode;
|
|
|
19
23
|
EIP5792ErrorCode[EIP5792ErrorCode["UnknownBundleId"] = 5730] = "UnknownBundleId";
|
|
20
24
|
EIP5792ErrorCode[EIP5792ErrorCode["RejectedUpgrade"] = 5750] = "RejectedUpgrade";
|
|
21
25
|
})(EIP5792ErrorCode || (exports.EIP5792ErrorCode = EIP5792ErrorCode = {}));
|
|
26
|
+
// To be moved to @metamask/rpc-errors in future.
|
|
27
|
+
var EIP7682ErrorCode;
|
|
28
|
+
(function (EIP7682ErrorCode) {
|
|
29
|
+
EIP7682ErrorCode[EIP7682ErrorCode["UnsupportedAsset"] = 5771] = "UnsupportedAsset";
|
|
30
|
+
EIP7682ErrorCode[EIP7682ErrorCode["UnsupportedChain"] = 5772] = "UnsupportedChain";
|
|
31
|
+
EIP7682ErrorCode[EIP7682ErrorCode["MalformedRequiredAssets"] = 5773] = "MalformedRequiredAssets";
|
|
32
|
+
})(EIP7682ErrorCode || (exports.EIP7682ErrorCode = EIP7682ErrorCode = {}));
|
|
22
33
|
// wallet_getCallStatus
|
|
23
34
|
var GetCallsStatusCode;
|
|
24
35
|
(function (GetCallsStatusCode) {
|
package/dist/constants.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAE/C,QAAA,OAAO,GAAG,OAAO,CAAC;AAElB,QAAA,6BAA6B,GAAG;IAC3C,iCAAY,CAAC,EAAE;IACf,iCAAY,CAAC,MAAM;CACpB,CAAC;AAEF,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,sDAAuC,CAAA;AACzC,CAAC,EAFW,WAAW,2BAAX,WAAW,QAEtB;AAED,iDAAiD;AACjD,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,kHAAuC,CAAA;IACvC,sFAAyB,CAAA;IACzB,gFAAsB,CAAA;IACtB,gFAAsB,CAAA;AACxB,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAED,uBAAuB;AACvB,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,mEAAa,CAAA;IACb,uEAAe,CAAA;IACf,mFAAqB,CAAA;IACrB,qEAAc,CAAA;IACd,qFAAsB,CAAA;AACxB,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\n\nexport const VERSION = '2.0.0';\n\nexport const KEYRING_TYPES_SUPPORTING_7702 = [\n KeyringTypes.hd,\n KeyringTypes.simple,\n];\n\nexport enum MessageType {\n SendTransaction = 'eth_sendTransaction',\n}\n\n// To be moved to @metamask/rpc-errors in future.\nexport enum EIP5792ErrorCode {\n UnsupportedNonOptionalCapability = 5700,\n UnsupportedChainId = 5710,\n UnknownBundleId = 5730,\n RejectedUpgrade = 5750,\n}\n\n// wallet_getCallStatus\nexport enum GetCallsStatusCode {\n PENDING = 100,\n CONFIRMED = 200,\n FAILED_OFFCHAIN = 400,\n REVERTED = 500,\n REVERTED_PARTIAL = 600,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAE/C,QAAA,OAAO,GAAG,OAAO,CAAC;AAElB,QAAA,6BAA6B,GAAG;IAC3C,iCAAY,CAAC,EAAE;IACf,iCAAY,CAAC,MAAM;CACpB,CAAC;AAEF,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,sDAAuC,CAAA;AACzC,CAAC,EAFW,WAAW,2BAAX,WAAW,QAEtB;AAED,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC/B,0DAAiC,CAAA;AACnC,CAAC,EAFW,qBAAqB,qCAArB,qBAAqB,QAEhC;AAED,iDAAiD;AACjD,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,kHAAuC,CAAA;IACvC,sFAAyB,CAAA;IACzB,gFAAsB,CAAA;IACtB,gFAAsB,CAAA;AACxB,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAED,iDAAiD;AACjD,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,kFAAuB,CAAA;IACvB,kFAAuB,CAAA;IACvB,gGAA8B,CAAA;AAChC,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B;AAED,uBAAuB;AACvB,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,mEAAa,CAAA;IACb,uEAAe,CAAA;IACf,mFAAqB,CAAA;IACrB,qEAAc,CAAA;IACd,qFAAsB,CAAA;AACxB,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\n\nexport const VERSION = '2.0.0';\n\nexport const KEYRING_TYPES_SUPPORTING_7702 = [\n KeyringTypes.hd,\n KeyringTypes.simple,\n];\n\nexport enum MessageType {\n SendTransaction = 'eth_sendTransaction',\n}\n\nexport enum SupportedCapabilities {\n AuxiliaryFunds = 'auxiliaryFunds',\n}\n\n// To be moved to @metamask/rpc-errors in future.\nexport enum EIP5792ErrorCode {\n UnsupportedNonOptionalCapability = 5700,\n UnsupportedChainId = 5710,\n UnknownBundleId = 5730,\n RejectedUpgrade = 5750,\n}\n\n// To be moved to @metamask/rpc-errors in future.\nexport enum EIP7682ErrorCode {\n UnsupportedAsset = 5771,\n UnsupportedChain = 5772,\n MalformedRequiredAssets = 5773,\n}\n\n// wallet_getCallStatus\nexport enum GetCallsStatusCode {\n PENDING = 100,\n CONFIRMED = 200,\n FAILED_OFFCHAIN = 400,\n REVERTED = 500,\n REVERTED_PARTIAL = 600,\n}\n"]}
|
package/dist/constants.d.cts
CHANGED
|
@@ -4,12 +4,20 @@ export declare const KEYRING_TYPES_SUPPORTING_7702: KeyringTypes[];
|
|
|
4
4
|
export declare enum MessageType {
|
|
5
5
|
SendTransaction = "eth_sendTransaction"
|
|
6
6
|
}
|
|
7
|
+
export declare enum SupportedCapabilities {
|
|
8
|
+
AuxiliaryFunds = "auxiliaryFunds"
|
|
9
|
+
}
|
|
7
10
|
export declare enum EIP5792ErrorCode {
|
|
8
11
|
UnsupportedNonOptionalCapability = 5700,
|
|
9
12
|
UnsupportedChainId = 5710,
|
|
10
13
|
UnknownBundleId = 5730,
|
|
11
14
|
RejectedUpgrade = 5750
|
|
12
15
|
}
|
|
16
|
+
export declare enum EIP7682ErrorCode {
|
|
17
|
+
UnsupportedAsset = 5771,
|
|
18
|
+
UnsupportedChain = 5772,
|
|
19
|
+
MalformedRequiredAssets = 5773
|
|
20
|
+
}
|
|
13
21
|
export declare enum GetCallsStatusCode {
|
|
14
22
|
PENDING = 100,
|
|
15
23
|
CONFIRMED = 200,
|
package/dist/constants.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,eAAO,MAAM,6BAA6B,gBAGzC,CAAC;AAEF,oBAAY,WAAW;IACrB,eAAe,wBAAwB;CACxC;AAGD,oBAAY,gBAAgB;IAC1B,gCAAgC,OAAO;IACvC,kBAAkB,OAAO;IACzB,eAAe,OAAO;IACtB,eAAe,OAAO;CACvB;AAGD,oBAAY,kBAAkB;IAC5B,OAAO,MAAM;IACb,SAAS,MAAM;IACf,eAAe,MAAM;IACrB,QAAQ,MAAM;IACd,gBAAgB,MAAM;CACvB"}
|
|
1
|
+
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,eAAO,MAAM,6BAA6B,gBAGzC,CAAC;AAEF,oBAAY,WAAW;IACrB,eAAe,wBAAwB;CACxC;AAED,oBAAY,qBAAqB;IAC/B,cAAc,mBAAmB;CAClC;AAGD,oBAAY,gBAAgB;IAC1B,gCAAgC,OAAO;IACvC,kBAAkB,OAAO;IACzB,eAAe,OAAO;IACtB,eAAe,OAAO;CACvB;AAGD,oBAAY,gBAAgB;IAC1B,gBAAgB,OAAO;IACvB,gBAAgB,OAAO;IACvB,uBAAuB,OAAO;CAC/B;AAGD,oBAAY,kBAAkB;IAC5B,OAAO,MAAM;IACb,SAAS,MAAM;IACf,eAAe,MAAM;IACrB,QAAQ,MAAM;IACd,gBAAgB,MAAM;CACvB"}
|
package/dist/constants.d.mts
CHANGED
|
@@ -4,12 +4,20 @@ export declare const KEYRING_TYPES_SUPPORTING_7702: KeyringTypes[];
|
|
|
4
4
|
export declare enum MessageType {
|
|
5
5
|
SendTransaction = "eth_sendTransaction"
|
|
6
6
|
}
|
|
7
|
+
export declare enum SupportedCapabilities {
|
|
8
|
+
AuxiliaryFunds = "auxiliaryFunds"
|
|
9
|
+
}
|
|
7
10
|
export declare enum EIP5792ErrorCode {
|
|
8
11
|
UnsupportedNonOptionalCapability = 5700,
|
|
9
12
|
UnsupportedChainId = 5710,
|
|
10
13
|
UnknownBundleId = 5730,
|
|
11
14
|
RejectedUpgrade = 5750
|
|
12
15
|
}
|
|
16
|
+
export declare enum EIP7682ErrorCode {
|
|
17
|
+
UnsupportedAsset = 5771,
|
|
18
|
+
UnsupportedChain = 5772,
|
|
19
|
+
MalformedRequiredAssets = 5773
|
|
20
|
+
}
|
|
13
21
|
export declare enum GetCallsStatusCode {
|
|
14
22
|
PENDING = 100,
|
|
15
23
|
CONFIRMED = 200,
|
package/dist/constants.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,eAAO,MAAM,6BAA6B,gBAGzC,CAAC;AAEF,oBAAY,WAAW;IACrB,eAAe,wBAAwB;CACxC;AAGD,oBAAY,gBAAgB;IAC1B,gCAAgC,OAAO;IACvC,kBAAkB,OAAO;IACzB,eAAe,OAAO;IACtB,eAAe,OAAO;CACvB;AAGD,oBAAY,kBAAkB;IAC5B,OAAO,MAAM;IACb,SAAS,MAAM;IACf,eAAe,MAAM;IACrB,QAAQ,MAAM;IACd,gBAAgB,MAAM;CACvB"}
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,eAAO,MAAM,6BAA6B,gBAGzC,CAAC;AAEF,oBAAY,WAAW;IACrB,eAAe,wBAAwB;CACxC;AAED,oBAAY,qBAAqB;IAC/B,cAAc,mBAAmB;CAClC;AAGD,oBAAY,gBAAgB;IAC1B,gCAAgC,OAAO;IACvC,kBAAkB,OAAO;IACzB,eAAe,OAAO;IACtB,eAAe,OAAO;CACvB;AAGD,oBAAY,gBAAgB;IAC1B,gBAAgB,OAAO;IACvB,gBAAgB,OAAO;IACvB,uBAAuB,OAAO;CAC/B;AAGD,oBAAY,kBAAkB;IAC5B,OAAO,MAAM;IACb,SAAS,MAAM;IACf,eAAe,MAAM;IACrB,QAAQ,MAAM;IACd,gBAAgB,MAAM;CACvB"}
|
package/dist/constants.mjs
CHANGED
|
@@ -8,6 +8,10 @@ export var MessageType;
|
|
|
8
8
|
(function (MessageType) {
|
|
9
9
|
MessageType["SendTransaction"] = "eth_sendTransaction";
|
|
10
10
|
})(MessageType || (MessageType = {}));
|
|
11
|
+
export var SupportedCapabilities;
|
|
12
|
+
(function (SupportedCapabilities) {
|
|
13
|
+
SupportedCapabilities["AuxiliaryFunds"] = "auxiliaryFunds";
|
|
14
|
+
})(SupportedCapabilities || (SupportedCapabilities = {}));
|
|
11
15
|
// To be moved to @metamask/rpc-errors in future.
|
|
12
16
|
export var EIP5792ErrorCode;
|
|
13
17
|
(function (EIP5792ErrorCode) {
|
|
@@ -16,6 +20,13 @@ export var EIP5792ErrorCode;
|
|
|
16
20
|
EIP5792ErrorCode[EIP5792ErrorCode["UnknownBundleId"] = 5730] = "UnknownBundleId";
|
|
17
21
|
EIP5792ErrorCode[EIP5792ErrorCode["RejectedUpgrade"] = 5750] = "RejectedUpgrade";
|
|
18
22
|
})(EIP5792ErrorCode || (EIP5792ErrorCode = {}));
|
|
23
|
+
// To be moved to @metamask/rpc-errors in future.
|
|
24
|
+
export var EIP7682ErrorCode;
|
|
25
|
+
(function (EIP7682ErrorCode) {
|
|
26
|
+
EIP7682ErrorCode[EIP7682ErrorCode["UnsupportedAsset"] = 5771] = "UnsupportedAsset";
|
|
27
|
+
EIP7682ErrorCode[EIP7682ErrorCode["UnsupportedChain"] = 5772] = "UnsupportedChain";
|
|
28
|
+
EIP7682ErrorCode[EIP7682ErrorCode["MalformedRequiredAssets"] = 5773] = "MalformedRequiredAssets";
|
|
29
|
+
})(EIP7682ErrorCode || (EIP7682ErrorCode = {}));
|
|
19
30
|
// wallet_getCallStatus
|
|
20
31
|
export var GetCallsStatusCode;
|
|
21
32
|
(function (GetCallsStatusCode) {
|
package/dist/constants.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,YAAY,CAAC,EAAE;IACf,YAAY,CAAC,MAAM;CACpB,CAAC;AAEF,MAAM,CAAN,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,sDAAuC,CAAA;AACzC,CAAC,EAFW,WAAW,KAAX,WAAW,QAEtB;AAED,iDAAiD;AACjD,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,kHAAuC,CAAA;IACvC,sFAAyB,CAAA;IACzB,gFAAsB,CAAA;IACtB,gFAAsB,CAAA;AACxB,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAED,uBAAuB;AACvB,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,mEAAa,CAAA;IACb,uEAAe,CAAA;IACf,mFAAqB,CAAA;IACrB,qEAAc,CAAA;IACd,qFAAsB,CAAA;AACxB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\n\nexport const VERSION = '2.0.0';\n\nexport const KEYRING_TYPES_SUPPORTING_7702 = [\n KeyringTypes.hd,\n KeyringTypes.simple,\n];\n\nexport enum MessageType {\n SendTransaction = 'eth_sendTransaction',\n}\n\n// To be moved to @metamask/rpc-errors in future.\nexport enum EIP5792ErrorCode {\n UnsupportedNonOptionalCapability = 5700,\n UnsupportedChainId = 5710,\n UnknownBundleId = 5730,\n RejectedUpgrade = 5750,\n}\n\n// wallet_getCallStatus\nexport enum GetCallsStatusCode {\n PENDING = 100,\n CONFIRMED = 200,\n FAILED_OFFCHAIN = 400,\n REVERTED = 500,\n REVERTED_PARTIAL = 600,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,YAAY,CAAC,EAAE;IACf,YAAY,CAAC,MAAM;CACpB,CAAC;AAEF,MAAM,CAAN,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,sDAAuC,CAAA;AACzC,CAAC,EAFW,WAAW,KAAX,WAAW,QAEtB;AAED,MAAM,CAAN,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC/B,0DAAiC,CAAA;AACnC,CAAC,EAFW,qBAAqB,KAArB,qBAAqB,QAEhC;AAED,iDAAiD;AACjD,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,kHAAuC,CAAA;IACvC,sFAAyB,CAAA;IACzB,gFAAsB,CAAA;IACtB,gFAAsB,CAAA;AACxB,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAED,iDAAiD;AACjD,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,kFAAuB,CAAA;IACvB,kFAAuB,CAAA;IACvB,gGAA8B,CAAA;AAChC,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B;AAED,uBAAuB;AACvB,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,mEAAa,CAAA;IACb,uEAAe,CAAA;IACf,mFAAqB,CAAA;IACrB,qEAAc,CAAA;IACd,qFAAsB,CAAA;AACxB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\n\nexport const VERSION = '2.0.0';\n\nexport const KEYRING_TYPES_SUPPORTING_7702 = [\n KeyringTypes.hd,\n KeyringTypes.simple,\n];\n\nexport enum MessageType {\n SendTransaction = 'eth_sendTransaction',\n}\n\nexport enum SupportedCapabilities {\n AuxiliaryFunds = 'auxiliaryFunds',\n}\n\n// To be moved to @metamask/rpc-errors in future.\nexport enum EIP5792ErrorCode {\n UnsupportedNonOptionalCapability = 5700,\n UnsupportedChainId = 5710,\n UnknownBundleId = 5730,\n RejectedUpgrade = 5750,\n}\n\n// To be moved to @metamask/rpc-errors in future.\nexport enum EIP7682ErrorCode {\n UnsupportedAsset = 5771,\n UnsupportedChain = 5772,\n MalformedRequiredAssets = 5773,\n}\n\n// wallet_getCallStatus\nexport enum GetCallsStatusCode {\n PENDING = 100,\n CONFIRMED = 200,\n FAILED_OFFCHAIN = 400,\n REVERTED = 500,\n REVERTED_PARTIAL = 600,\n}\n"]}
|
|
@@ -13,7 +13,7 @@ const utils_1 = require("../utils.cjs");
|
|
|
13
13
|
* @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.
|
|
14
14
|
*/
|
|
15
15
|
async function getCapabilities(hooks, messenger, address, chainIds) {
|
|
16
|
-
const { getDismissSmartAccountSuggestionEnabled, getIsSmartTransaction, isAtomicBatchSupported, isRelaySupported, getSendBundleSupportedChains, } = hooks;
|
|
16
|
+
const { getDismissSmartAccountSuggestionEnabled, getIsSmartTransaction, isAtomicBatchSupported, isRelaySupported, getSendBundleSupportedChains, isAuxiliaryFundsSupported, } = hooks;
|
|
17
17
|
let chainIdsNormalized = chainIds?.map((chainId) => chainId.toLowerCase());
|
|
18
18
|
if (!chainIdsNormalized?.length) {
|
|
19
19
|
const networkConfigurations = messenger.call('NetworkController:getState').networkConfigurationsByChainId;
|
|
@@ -44,12 +44,18 @@ async function getCapabilities(hooks, messenger, address, chainIds) {
|
|
|
44
44
|
return acc;
|
|
45
45
|
}
|
|
46
46
|
const status = isSupported ? 'supported' : 'ready';
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const hexChainId = chainId;
|
|
48
|
+
if (acc[hexChainId] === undefined) {
|
|
49
|
+
acc[hexChainId] = {};
|
|
49
50
|
}
|
|
50
|
-
acc[
|
|
51
|
+
acc[hexChainId].atomic = {
|
|
51
52
|
status,
|
|
52
53
|
};
|
|
54
|
+
if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {
|
|
55
|
+
acc[hexChainId].auxiliaryFunds = {
|
|
56
|
+
supported: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
53
59
|
return acc;
|
|
54
60
|
}, alternateGasFeesAcc);
|
|
55
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCapabilities.cjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":";;;AAOA,gDAA6D;AAE7D,wCAAiD;
|
|
1
|
+
{"version":3,"file":"getCapabilities.cjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":";;;AAOA,gDAA6D;AAE7D,wCAAiD;AAsBjD;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CACnC,KAA2B,EAC3B,SAA2B,EAC3B,OAAY,EACZ,QAA2B;IAE3B,MAAM,EACJ,uCAAuC,EACvC,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,yBAAyB,GAC1B,GAAG,KAAK,CAAC;IAEV,IAAI,kBAAkB,GAAG,QAAQ,EAAE,GAAG,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,EAAS,CAC1C,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE,MAAM,EAAE;QAC/B,MAAM,qBAAqB,GAAG,SAAS,CAAC,IAAI,CAC1C,4BAA4B,CAC7B,CAAC,8BAA8B,CAAC;QACjC,kBAAkB,GAAG,MAAM,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E,EAAE,CAAC,YAAY,KAAK,OAAO,CACxD,IAAI,EAAE,CAEN,CAAC;QAEF,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,sBAAsB,EAAE,GAAG,iBAAiB,CAAC;QAE1E,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;QAE1E,MAAM,gBAAgB,GACpB,iBAAiB;YACjB,CAAC,CAAC,kBAAkB,IAAI,qBAAqB,CAAC;gBAC5C,CAAC,WAAW,IAAI,sBAAsB,CAAC,CAAC,CAAC;QAE7C,IAAI,gBAAgB,EAAE;YACpB,GAAG,CAAC,OAAc,CAAC,GAAG;gBACpB,gBAAgB,EAAE;oBAChB,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;SACH;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type {\n IsAtomicBatchSupportedResult,\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { KEYRING_TYPES_SUPPORTING_7702 } from '../constants';\nimport type { EIP5792Messenger, GetCapabilitiesResult } from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link getCapabilities}\n */\nexport type GetCapabilitiesHooks = {\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if a chain supports smart transactions */\n getIsSmartTransaction: (chainId: Hex) => boolean;\n /** Function to check if atomic batching is supported */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to check if relay is supported on a chain */\n isRelaySupported: (chainId: Hex) => Promise<boolean>;\n /** Function to get chains that support send bundle */\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * Retrieves the capabilities for atomic transactions on specified chains.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param address - The account address to check capabilities for.\n * @param chainIds - Array of chain IDs to check capabilities for (if undefined, checks all configured networks).\n * @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.\n */\nexport async function getCapabilities(\n hooks: GetCapabilitiesHooks,\n messenger: EIP5792Messenger,\n address: Hex,\n chainIds: Hex[] | undefined,\n) {\n const {\n getDismissSmartAccountSuggestionEnabled,\n getIsSmartTransaction,\n isAtomicBatchSupported,\n isRelaySupported,\n getSendBundleSupportedChains,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n let chainIdsNormalized = chainIds?.map(\n (chainId) => chainId.toLowerCase() as Hex,\n );\n\n if (!chainIdsNormalized?.length) {\n const networkConfigurations = messenger.call(\n 'NetworkController:getState',\n ).networkConfigurationsByChainId;\n chainIdsNormalized = Object.keys(networkConfigurations) as Hex[];\n }\n\n const batchSupport = await isAtomicBatchSupported({\n address,\n chainIds: chainIdsNormalized,\n });\n\n const alternateGasFeesAcc = await getAlternateGasFeesCapability(\n chainIdsNormalized,\n batchSupport,\n getIsSmartTransaction,\n isRelaySupported,\n getSendBundleSupportedChains,\n messenger,\n );\n\n return chainIdsNormalized.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (batchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n isRelaySupported: boolean;\n };\n\n const { delegationAddress, isSupported, upgradeContractAddress } =\n chainBatchSupport;\n\n const isUpgradeDisabled = getDismissSmartAccountSuggestionEnabled();\n let isSupportedAccount = false;\n\n try {\n const keyringType = getAccountKeyringType(address, messenger);\n isSupportedAccount = KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n } catch {\n // Intentionally empty\n }\n\n const canUpgrade =\n !isUpgradeDisabled &&\n upgradeContractAddress &&\n !delegationAddress &&\n isSupportedAccount;\n\n if (!isSupported && !canUpgrade) {\n return acc;\n }\n\n const status = isSupported ? 'supported' : 'ready';\n const hexChainId = chainId as Hex;\n\n if (acc[hexChainId] === undefined) {\n acc[hexChainId] = {};\n }\n\n acc[hexChainId].atomic = {\n status,\n };\n\n if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {\n acc[hexChainId].auxiliaryFunds = {\n supported: true,\n };\n }\n\n return acc;\n }, alternateGasFeesAcc);\n}\n\n/**\n * Determines alternate gas fees capability for the specified chains.\n *\n * @param chainIds - Array of chain IDs to check for alternate gas fees support.\n * @param batchSupport - Information about atomic batch support for each chain.\n * @param getIsSmartTransaction - Function to check if a chain supports smart transactions.\n * @param isRelaySupported - Function to check if relay is supported on a chain.\n * @param getSendBundleSupportedChains - Function to get chains that support send bundle.\n * @param messenger - Messenger instance for controller communication.\n * @returns Promise resolving to GetCapabilitiesResult with alternate gas fees information.\n */\nasync function getAlternateGasFeesCapability(\n chainIds: Hex[],\n batchSupport: IsAtomicBatchSupportedResult,\n getIsSmartTransaction: (chainId: Hex) => boolean,\n isRelaySupported: (chainId: Hex) => Promise<boolean>,\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>,\n messenger: EIP5792Messenger,\n) {\n const simulationEnabled = messenger.call(\n 'PreferencesController:getState',\n ).useTransactionSimulations;\n\n const relaySupportedChains = await Promise.all(\n batchSupport\n .map(({ chainId }) => chainId)\n .map((chainId) => isRelaySupported(chainId)),\n );\n\n const sendBundleSupportedChains =\n await getSendBundleSupportedChains(chainIds);\n\n const updatedBatchSupport = batchSupport.map((support, index) => ({\n ...support,\n relaySupportedForChain: relaySupportedChains[index],\n }));\n\n return chainIds.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (updatedBatchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n relaySupportedForChain: boolean;\n };\n\n const { isSupported = false, relaySupportedForChain } = chainBatchSupport;\n\n const isSmartTransaction = getIsSmartTransaction(chainId);\n const isSendBundleSupported = sendBundleSupportedChains[chainId] ?? false;\n\n const alternateGasFees =\n simulationEnabled &&\n ((isSmartTransaction && isSendBundleSupported) ||\n (isSupported && relaySupportedForChain));\n\n if (alternateGasFees) {\n acc[chainId as Hex] = {\n alternateGasFees: {\n supported: true,\n },\n };\n }\n\n return acc;\n }, {});\n}\n"]}
|
|
@@ -15,6 +15,8 @@ export type GetCapabilitiesHooks = {
|
|
|
15
15
|
isRelaySupported: (chainId: Hex) => Promise<boolean>;
|
|
16
16
|
/** Function to get chains that support send bundle */
|
|
17
17
|
getSendBundleSupportedChains: (chainIds: Hex[]) => Promise<Record<string, boolean>>;
|
|
18
|
+
/** Function to validate if auxiliary funds capability is supported. */
|
|
19
|
+
isAuxiliaryFundsSupported: (chainId: Hex) => boolean;
|
|
18
20
|
};
|
|
19
21
|
/**
|
|
20
22
|
* Retrieves the capabilities for atomic transactions on specified chains.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCapabilities.d.cts","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,qBAAiB;AAGxE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,kEAAkE;IAClE,uCAAuC,EAAE,MAAM,OAAO,CAAC;IACvD,+DAA+D;IAC/D,qBAAqB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;IACjD,wDAAwD;IACxD,sBAAsB,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,CAAC;IACxE,yDAAyD;IACzD,gBAAgB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,sDAAsD;IACtD,4BAA4B,EAAE,CAC5B,QAAQ,EAAE,GAAG,EAAE,KACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"getCapabilities.d.cts","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,qBAAiB;AAGxE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,kEAAkE;IAClE,uCAAuC,EAAE,MAAM,OAAO,CAAC;IACvD,+DAA+D;IAC/D,qBAAqB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;IACjD,wDAAwD;IACxD,sBAAsB,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,CAAC;IACxE,yDAAyD;IACzD,gBAAgB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,sDAAsD;IACtD,4BAA4B,EAAE,CAC5B,QAAQ,EAAE,GAAG,EAAE,KACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtC,uEAAuE;IACvE,yBAAyB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;CACtD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,oBAAoB,EAC3B,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,GAAG,EAAE,GAAG,SAAS,kCAqF5B"}
|
|
@@ -15,6 +15,8 @@ export type GetCapabilitiesHooks = {
|
|
|
15
15
|
isRelaySupported: (chainId: Hex) => Promise<boolean>;
|
|
16
16
|
/** Function to get chains that support send bundle */
|
|
17
17
|
getSendBundleSupportedChains: (chainIds: Hex[]) => Promise<Record<string, boolean>>;
|
|
18
|
+
/** Function to validate if auxiliary funds capability is supported. */
|
|
19
|
+
isAuxiliaryFundsSupported: (chainId: Hex) => boolean;
|
|
18
20
|
};
|
|
19
21
|
/**
|
|
20
22
|
* Retrieves the capabilities for atomic transactions on specified chains.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCapabilities.d.mts","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,qBAAiB;AAGxE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,kEAAkE;IAClE,uCAAuC,EAAE,MAAM,OAAO,CAAC;IACvD,+DAA+D;IAC/D,qBAAqB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;IACjD,wDAAwD;IACxD,sBAAsB,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,CAAC;IACxE,yDAAyD;IACzD,gBAAgB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,sDAAsD;IACtD,4BAA4B,EAAE,CAC5B,QAAQ,EAAE,GAAG,EAAE,KACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"getCapabilities.d.mts","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,qBAAiB;AAGxE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,kEAAkE;IAClE,uCAAuC,EAAE,MAAM,OAAO,CAAC;IACvD,+DAA+D;IAC/D,qBAAqB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;IACjD,wDAAwD;IACxD,sBAAsB,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,CAAC;IACxE,yDAAyD;IACzD,gBAAgB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,sDAAsD;IACtD,4BAA4B,EAAE,CAC5B,QAAQ,EAAE,GAAG,EAAE,KACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtC,uEAAuE;IACvE,yBAAyB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;CACtD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,oBAAoB,EAC3B,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,GAAG,EAAE,GAAG,SAAS,kCAqF5B"}
|
|
@@ -10,7 +10,7 @@ import { getAccountKeyringType } from "../utils.mjs";
|
|
|
10
10
|
* @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.
|
|
11
11
|
*/
|
|
12
12
|
export async function getCapabilities(hooks, messenger, address, chainIds) {
|
|
13
|
-
const { getDismissSmartAccountSuggestionEnabled, getIsSmartTransaction, isAtomicBatchSupported, isRelaySupported, getSendBundleSupportedChains, } = hooks;
|
|
13
|
+
const { getDismissSmartAccountSuggestionEnabled, getIsSmartTransaction, isAtomicBatchSupported, isRelaySupported, getSendBundleSupportedChains, isAuxiliaryFundsSupported, } = hooks;
|
|
14
14
|
let chainIdsNormalized = chainIds?.map((chainId) => chainId.toLowerCase());
|
|
15
15
|
if (!chainIdsNormalized?.length) {
|
|
16
16
|
const networkConfigurations = messenger.call('NetworkController:getState').networkConfigurationsByChainId;
|
|
@@ -41,12 +41,18 @@ export async function getCapabilities(hooks, messenger, address, chainIds) {
|
|
|
41
41
|
return acc;
|
|
42
42
|
}
|
|
43
43
|
const status = isSupported ? 'supported' : 'ready';
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const hexChainId = chainId;
|
|
45
|
+
if (acc[hexChainId] === undefined) {
|
|
46
|
+
acc[hexChainId] = {};
|
|
46
47
|
}
|
|
47
|
-
acc[
|
|
48
|
+
acc[hexChainId].atomic = {
|
|
48
49
|
status,
|
|
49
50
|
};
|
|
51
|
+
if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {
|
|
52
|
+
acc[hexChainId].auxiliaryFunds = {
|
|
53
|
+
supported: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
50
56
|
return acc;
|
|
51
57
|
}, alternateGasFeesAcc);
|
|
52
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCapabilities.mjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,6BAA6B,EAAE,yBAAqB;AAE7D,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;
|
|
1
|
+
{"version":3,"file":"getCapabilities.mjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,6BAA6B,EAAE,yBAAqB;AAE7D,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAsBjD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAA2B,EAC3B,SAA2B,EAC3B,OAAY,EACZ,QAA2B;IAE3B,MAAM,EACJ,uCAAuC,EACvC,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,yBAAyB,GAC1B,GAAG,KAAK,CAAC;IAEV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,OAAO;QACV,sBAAsB,EAAE,oBAAoB,CAAC,KAAK,CAAC;KACpD,CAAC,CAAC,CAAC;IAEJ,OAAO,QAAQ,CAAC,MAAM,CAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,iBAAiB,GAAG,CAAC,mBAAmB,CAAC,IAAI,CACjD,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,KAAK,OAAO,CACxD,IAAI,EAAE,CAEN,CAAC;QAEF,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,sBAAsB,EAAE,GAAG,iBAAiB,CAAC;QAE1E,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;QAE1E,MAAM,gBAAgB,GACpB,iBAAiB;YACjB,CAAC,CAAC,kBAAkB,IAAI,qBAAqB,CAAC;gBAC5C,CAAC,WAAW,IAAI,sBAAsB,CAAC,CAAC,CAAC;QAE7C,IAAI,gBAAgB,EAAE;YACpB,GAAG,CAAC,OAAc,CAAC,GAAG;gBACpB,gBAAgB,EAAE;oBAChB,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;SACH;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type {\n IsAtomicBatchSupportedResult,\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { KEYRING_TYPES_SUPPORTING_7702 } from '../constants';\nimport type { EIP5792Messenger, GetCapabilitiesResult } from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link getCapabilities}\n */\nexport type GetCapabilitiesHooks = {\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if a chain supports smart transactions */\n getIsSmartTransaction: (chainId: Hex) => boolean;\n /** Function to check if atomic batching is supported */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to check if relay is supported on a chain */\n isRelaySupported: (chainId: Hex) => Promise<boolean>;\n /** Function to get chains that support send bundle */\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * Retrieves the capabilities for atomic transactions on specified chains.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param address - The account address to check capabilities for.\n * @param chainIds - Array of chain IDs to check capabilities for (if undefined, checks all configured networks).\n * @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.\n */\nexport async function getCapabilities(\n hooks: GetCapabilitiesHooks,\n messenger: EIP5792Messenger,\n address: Hex,\n chainIds: Hex[] | undefined,\n) {\n const {\n getDismissSmartAccountSuggestionEnabled,\n getIsSmartTransaction,\n isAtomicBatchSupported,\n isRelaySupported,\n getSendBundleSupportedChains,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n let chainIdsNormalized = chainIds?.map(\n (chainId) => chainId.toLowerCase() as Hex,\n );\n\n if (!chainIdsNormalized?.length) {\n const networkConfigurations = messenger.call(\n 'NetworkController:getState',\n ).networkConfigurationsByChainId;\n chainIdsNormalized = Object.keys(networkConfigurations) as Hex[];\n }\n\n const batchSupport = await isAtomicBatchSupported({\n address,\n chainIds: chainIdsNormalized,\n });\n\n const alternateGasFeesAcc = await getAlternateGasFeesCapability(\n chainIdsNormalized,\n batchSupport,\n getIsSmartTransaction,\n isRelaySupported,\n getSendBundleSupportedChains,\n messenger,\n );\n\n return chainIdsNormalized.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (batchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n isRelaySupported: boolean;\n };\n\n const { delegationAddress, isSupported, upgradeContractAddress } =\n chainBatchSupport;\n\n const isUpgradeDisabled = getDismissSmartAccountSuggestionEnabled();\n let isSupportedAccount = false;\n\n try {\n const keyringType = getAccountKeyringType(address, messenger);\n isSupportedAccount = KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n } catch {\n // Intentionally empty\n }\n\n const canUpgrade =\n !isUpgradeDisabled &&\n upgradeContractAddress &&\n !delegationAddress &&\n isSupportedAccount;\n\n if (!isSupported && !canUpgrade) {\n return acc;\n }\n\n const status = isSupported ? 'supported' : 'ready';\n const hexChainId = chainId as Hex;\n\n if (acc[hexChainId] === undefined) {\n acc[hexChainId] = {};\n }\n\n acc[hexChainId].atomic = {\n status,\n };\n\n if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {\n acc[hexChainId].auxiliaryFunds = {\n supported: true,\n };\n }\n\n return acc;\n }, alternateGasFeesAcc);\n}\n\n/**\n * Determines alternate gas fees capability for the specified chains.\n *\n * @param chainIds - Array of chain IDs to check for alternate gas fees support.\n * @param batchSupport - Information about atomic batch support for each chain.\n * @param getIsSmartTransaction - Function to check if a chain supports smart transactions.\n * @param isRelaySupported - Function to check if relay is supported on a chain.\n * @param getSendBundleSupportedChains - Function to get chains that support send bundle.\n * @param messenger - Messenger instance for controller communication.\n * @returns Promise resolving to GetCapabilitiesResult with alternate gas fees information.\n */\nasync function getAlternateGasFeesCapability(\n chainIds: Hex[],\n batchSupport: IsAtomicBatchSupportedResult,\n getIsSmartTransaction: (chainId: Hex) => boolean,\n isRelaySupported: (chainId: Hex) => Promise<boolean>,\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>,\n messenger: EIP5792Messenger,\n) {\n const simulationEnabled = messenger.call(\n 'PreferencesController:getState',\n ).useTransactionSimulations;\n\n const relaySupportedChains = await Promise.all(\n batchSupport\n .map(({ chainId }) => chainId)\n .map((chainId) => isRelaySupported(chainId)),\n );\n\n const sendBundleSupportedChains =\n await getSendBundleSupportedChains(chainIds);\n\n const updatedBatchSupport = batchSupport.map((support, index) => ({\n ...support,\n relaySupportedForChain: relaySupportedChains[index],\n }));\n\n return chainIds.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (updatedBatchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n relaySupportedForChain: boolean;\n };\n\n const { isSupported = false, relaySupportedForChain } = chainBatchSupport;\n\n const isSmartTransaction = getIsSmartTransaction(chainId);\n const isSendBundleSupported = sendBundleSupportedChains[chainId] ?? false;\n\n const alternateGasFees =\n simulationEnabled &&\n ((isSmartTransaction && isSendBundleSupported) ||\n (isSupported && relaySupportedForChain));\n\n if (alternateGasFees) {\n acc[chainId as Hex] = {\n alternateGasFees: {\n supported: true,\n },\n };\n }\n\n return acc;\n }, {});\n}\n"]}
|
|
@@ -4,6 +4,7 @@ exports.processSendCalls = void 0;
|
|
|
4
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
5
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
6
6
|
const utils_1 = require("@metamask/utils");
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
7
8
|
const uuid_1 = require("uuid");
|
|
8
9
|
const constants_1 = require("../constants.cjs");
|
|
9
10
|
const utils_2 = require("../utils.cjs");
|
|
@@ -17,7 +18,7 @@ const utils_2 = require("../utils.cjs");
|
|
|
17
18
|
* @returns Promise resolving to a SendCallsResult containing the batch ID.
|
|
18
19
|
*/
|
|
19
20
|
async function processSendCalls(hooks, messenger, params, req) {
|
|
20
|
-
const { addTransactionBatch, addTransaction, getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported, validateSecurity: validateSecurityHook, } = hooks;
|
|
21
|
+
const { addTransactionBatch, addTransaction, getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported, validateSecurity: validateSecurityHook, isAuxiliaryFundsSupported, } = hooks;
|
|
21
22
|
const { calls, from: paramFrom } = params;
|
|
22
23
|
const { networkClientId, origin } = req;
|
|
23
24
|
const transactions = calls.map((call) => ({ params: call }));
|
|
@@ -32,12 +33,14 @@ async function processSendCalls(hooks, messenger, params, req) {
|
|
|
32
33
|
addTransaction,
|
|
33
34
|
chainId,
|
|
34
35
|
from,
|
|
36
|
+
messenger,
|
|
35
37
|
networkClientId,
|
|
36
38
|
origin,
|
|
37
39
|
securityAlertId,
|
|
38
40
|
sendCalls: params,
|
|
39
41
|
transactions,
|
|
40
42
|
validateSecurity,
|
|
43
|
+
isAuxiliaryFundsSupported,
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
else {
|
|
@@ -54,6 +57,7 @@ async function processSendCalls(hooks, messenger, params, req) {
|
|
|
54
57
|
securityAlertId,
|
|
55
58
|
transactions,
|
|
56
59
|
validateSecurity,
|
|
60
|
+
isAuxiliaryFundsSupported,
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
63
|
return { id: batchId };
|
|
@@ -66,16 +70,19 @@ exports.processSendCalls = processSendCalls;
|
|
|
66
70
|
* @param params.addTransaction - Function to add a single transaction.
|
|
67
71
|
* @param params.chainId - The chain ID for the transaction.
|
|
68
72
|
* @param params.from - The sender address.
|
|
73
|
+
* @param params.messenger - Messenger instance for controller communication.
|
|
69
74
|
* @param params.networkClientId - The network client ID.
|
|
70
75
|
* @param params.origin - The origin of the request (optional).
|
|
71
76
|
* @param params.securityAlertId - The security alert ID for this transaction.
|
|
72
77
|
* @param params.sendCalls - The original sendCalls request.
|
|
73
78
|
* @param params.transactions - Array containing the single transaction.
|
|
74
79
|
* @param params.validateSecurity - Function to validate security for the transaction.
|
|
80
|
+
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
75
81
|
* @returns Promise resolving to the generated batch ID for the transaction.
|
|
76
82
|
*/
|
|
77
|
-
async function processSingleTransaction({ addTransaction, chainId, from, networkClientId, origin, securityAlertId, sendCalls, transactions, validateSecurity, }) {
|
|
78
|
-
|
|
83
|
+
async function processSingleTransaction({ addTransaction, chainId, from, messenger, networkClientId, origin, securityAlertId, sendCalls, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
84
|
+
const keyringType = (0, utils_2.getAccountKeyringType)(from, messenger);
|
|
85
|
+
validateSingleSendCall(sendCalls, chainId, keyringType, isAuxiliaryFundsSupported);
|
|
79
86
|
const txParams = {
|
|
80
87
|
from,
|
|
81
88
|
...transactions[0].params,
|
|
@@ -87,6 +94,7 @@ async function processSingleTransaction({ addTransaction, chainId, from, network
|
|
|
87
94
|
origin,
|
|
88
95
|
};
|
|
89
96
|
validateSecurity(securityRequest, chainId);
|
|
97
|
+
dedupeAuxiliaryFundsRequiredAssets(sendCalls);
|
|
90
98
|
const batchId = generateBatchId();
|
|
91
99
|
await addTransaction(txParams, {
|
|
92
100
|
networkClientId,
|
|
@@ -112,9 +120,10 @@ async function processSingleTransaction({ addTransaction, chainId, from, network
|
|
|
112
120
|
* @param params.securityAlertId - The security alert ID for this batch.
|
|
113
121
|
* @param params.transactions - Array of transactions to process.
|
|
114
122
|
* @param params.validateSecurity - Function to validate security for the transactions.
|
|
123
|
+
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
115
124
|
* @returns Promise resolving to the generated batch ID for the transaction batch.
|
|
116
125
|
*/
|
|
117
|
-
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin, sendCalls, securityAlertId, transactions, validateSecurity, }) {
|
|
126
|
+
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin, sendCalls, securityAlertId, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
118
127
|
const batchSupport = await isAtomicBatchSupported({
|
|
119
128
|
address: from,
|
|
120
129
|
chainIds: [chainId],
|
|
@@ -122,7 +131,8 @@ async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSu
|
|
|
122
131
|
const chainBatchSupport = batchSupport?.[0];
|
|
123
132
|
const keyringType = (0, utils_2.getAccountKeyringType)(from, messenger);
|
|
124
133
|
const dismissSmartAccountSuggestionEnabled = getDismissSmartAccountSuggestionEnabled();
|
|
125
|
-
validateSendCalls(sendCalls, chainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType);
|
|
134
|
+
validateSendCalls(sendCalls, chainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType, isAuxiliaryFundsSupported);
|
|
135
|
+
dedupeAuxiliaryFundsRequiredAssets(sendCalls);
|
|
126
136
|
const result = await addTransactionBatch({
|
|
127
137
|
from,
|
|
128
138
|
networkClientId,
|
|
@@ -148,10 +158,12 @@ function generateBatchId() {
|
|
|
148
158
|
*
|
|
149
159
|
* @param sendCalls - The sendCalls request to validate.
|
|
150
160
|
* @param dappChainId - The chain ID that the dApp is connected to.
|
|
161
|
+
* @param keyringType - The type of keyring associated with the account.
|
|
162
|
+
* @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
151
163
|
*/
|
|
152
|
-
function validateSingleSendCall(sendCalls, dappChainId) {
|
|
164
|
+
function validateSingleSendCall(sendCalls, dappChainId, keyringType, isAuxiliaryFundsSupported) {
|
|
153
165
|
validateSendCallsVersion(sendCalls);
|
|
154
|
-
validateCapabilities(sendCalls);
|
|
166
|
+
validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);
|
|
155
167
|
validateDappChainId(sendCalls, dappChainId);
|
|
156
168
|
}
|
|
157
169
|
/**
|
|
@@ -162,11 +174,12 @@ function validateSingleSendCall(sendCalls, dappChainId) {
|
|
|
162
174
|
* @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.
|
|
163
175
|
* @param chainBatchSupport - Information about atomic batch support for the chain.
|
|
164
176
|
* @param keyringType - The type of keyring associated with the account.
|
|
177
|
+
* @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
165
178
|
*/
|
|
166
|
-
function validateSendCalls(sendCalls, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType) {
|
|
179
|
+
function validateSendCalls(sendCalls, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType, isAuxiliaryFundsSupported) {
|
|
167
180
|
validateSendCallsVersion(sendCalls);
|
|
168
181
|
validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);
|
|
169
|
-
validateCapabilities(sendCalls);
|
|
182
|
+
validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);
|
|
170
183
|
validateUpgrade(dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType);
|
|
171
184
|
}
|
|
172
185
|
/**
|
|
@@ -213,12 +226,19 @@ function validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport) {
|
|
|
213
226
|
* Validates that all required capabilities in the sendCalls request are supported.
|
|
214
227
|
*
|
|
215
228
|
* @param sendCalls - The sendCalls request to validate.
|
|
229
|
+
* @param keyringType - The type of keyring associated with the account.
|
|
230
|
+
* @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
231
|
+
*
|
|
216
232
|
* @throws JsonRpcError if unsupported non-optional capabilities are requested.
|
|
217
233
|
*/
|
|
218
|
-
function validateCapabilities(sendCalls) {
|
|
219
|
-
const { calls, capabilities } = sendCalls;
|
|
220
|
-
const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter((name) =>
|
|
221
|
-
|
|
234
|
+
function validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported) {
|
|
235
|
+
const { calls, capabilities, chainId } = sendCalls;
|
|
236
|
+
const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter((name) =>
|
|
237
|
+
// Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet
|
|
238
|
+
name !== constants_1.SupportedCapabilities.AuxiliaryFunds.toString() &&
|
|
239
|
+
capabilities?.[name].optional !== true);
|
|
240
|
+
const requiredCallCapabilities = calls.flatMap((call) => Object.keys(call.capabilities ?? {}).filter((name) => name !== constants_1.SupportedCapabilities.AuxiliaryFunds.toString() &&
|
|
241
|
+
call.capabilities?.[name].optional !== true));
|
|
222
242
|
const requiredCapabilities = [
|
|
223
243
|
...requiredTopLevelCapabilities,
|
|
224
244
|
...requiredCallCapabilities,
|
|
@@ -226,6 +246,50 @@ function validateCapabilities(sendCalls) {
|
|
|
226
246
|
if (requiredCapabilities?.length) {
|
|
227
247
|
throw new rpc_errors_1.JsonRpcError(constants_1.EIP5792ErrorCode.UnsupportedNonOptionalCapability, `Unsupported non-optional capabilities: ${requiredCapabilities.join(', ')}`);
|
|
228
248
|
}
|
|
249
|
+
if (capabilities?.auxiliaryFunds) {
|
|
250
|
+
validateAuxFundsSupportAndRequiredAssets({
|
|
251
|
+
auxiliaryFunds: capabilities.auxiliaryFunds,
|
|
252
|
+
chainId,
|
|
253
|
+
keyringType,
|
|
254
|
+
isAuxiliaryFundsSupported,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.
|
|
260
|
+
*
|
|
261
|
+
* docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}
|
|
262
|
+
*
|
|
263
|
+
* @param param - The parameter object.
|
|
264
|
+
* @param param.auxiliaryFunds - The auxiliaryFunds param to validate.
|
|
265
|
+
* @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.
|
|
266
|
+
* @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.
|
|
267
|
+
* @param param.chainId - The chain ID of the incoming request.
|
|
268
|
+
* @param param.keyringType - The type of keyring associated with the account.
|
|
269
|
+
* @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
270
|
+
* @throws JsonRpcError if auxiliary funds capability is not supported.
|
|
271
|
+
*/
|
|
272
|
+
function validateAuxFundsSupportAndRequiredAssets({ auxiliaryFunds, chainId, keyringType, isAuxiliaryFundsSupported, }) {
|
|
273
|
+
// If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability
|
|
274
|
+
// so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.
|
|
275
|
+
if (auxiliaryFunds.optional) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const isSupportedAccount = constants_1.KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);
|
|
279
|
+
if (!isSupportedAccount) {
|
|
280
|
+
throw new rpc_errors_1.JsonRpcError(constants_1.EIP5792ErrorCode.UnsupportedNonOptionalCapability, `Unsupported non-optional capability: ${constants_1.SupportedCapabilities.AuxiliaryFunds}`);
|
|
281
|
+
}
|
|
282
|
+
if (!isAuxiliaryFundsSupported(chainId)) {
|
|
283
|
+
throw new rpc_errors_1.JsonRpcError(constants_1.EIP7682ErrorCode.UnsupportedChain, `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`);
|
|
284
|
+
}
|
|
285
|
+
if (!auxiliaryFunds?.requiredAssets) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
for (const asset of auxiliaryFunds.requiredAssets) {
|
|
289
|
+
if (asset.standard !== 'erc20') {
|
|
290
|
+
throw new rpc_errors_1.JsonRpcError(constants_1.EIP7682ErrorCode.UnsupportedAsset, `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
229
293
|
}
|
|
230
294
|
/**
|
|
231
295
|
* Validates whether an EIP-7702 upgrade is allowed for the given parameters.
|
|
@@ -246,4 +310,31 @@ function validateUpgrade(dismissSmartAccountSuggestionEnabled, chainBatchSupport
|
|
|
246
310
|
throw new rpc_errors_1.JsonRpcError(constants_1.EIP5792ErrorCode.RejectedUpgrade, 'EIP-7702 upgrade not supported on account');
|
|
247
311
|
}
|
|
248
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.
|
|
315
|
+
* Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.
|
|
316
|
+
*
|
|
317
|
+
* @param sendCalls - The original sendCalls request.
|
|
318
|
+
*/
|
|
319
|
+
function dedupeAuxiliaryFundsRequiredAssets(sendCalls) {
|
|
320
|
+
if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {
|
|
321
|
+
const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;
|
|
322
|
+
// Group assets by their address (lowercased) and standard
|
|
323
|
+
const grouped = (0, lodash_1.groupBy)(requiredAssets, (asset) => `${asset.address.toLowerCase()}-${asset.standard}`);
|
|
324
|
+
// For each group, sum the amounts and return a single asset
|
|
325
|
+
const deduplicatedAssets = Object.values(grouped).map((group) => {
|
|
326
|
+
if (group.length === 1) {
|
|
327
|
+
return group[0];
|
|
328
|
+
}
|
|
329
|
+
const totalAmount = group.reduce((sum, asset) => {
|
|
330
|
+
return sum + BigInt(asset.amount);
|
|
331
|
+
}, 0n);
|
|
332
|
+
return {
|
|
333
|
+
...group[0],
|
|
334
|
+
amount: (0, utils_1.add0x)(totalAmount.toString(16)),
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
249
340
|
//# sourceMappingURL=processSendCalls.cjs.map
|