@metamask/assets-controllers 56.0.0 → 57.0.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/README.md +1 -0
  3. package/dist/DeFiPositionsController/DeFiPositionsController.cjs +126 -0
  4. package/dist/DeFiPositionsController/DeFiPositionsController.cjs.map +1 -0
  5. package/dist/DeFiPositionsController/DeFiPositionsController.d.cts +72 -0
  6. package/dist/DeFiPositionsController/DeFiPositionsController.d.cts.map +1 -0
  7. package/dist/DeFiPositionsController/DeFiPositionsController.d.mts +72 -0
  8. package/dist/DeFiPositionsController/DeFiPositionsController.d.mts.map +1 -0
  9. package/dist/DeFiPositionsController/DeFiPositionsController.mjs +121 -0
  10. package/dist/DeFiPositionsController/DeFiPositionsController.mjs.map +1 -0
  11. package/dist/DeFiPositionsController/fetch-positions.cjs +21 -0
  12. package/dist/DeFiPositionsController/fetch-positions.cjs.map +1 -0
  13. package/dist/DeFiPositionsController/fetch-positions.d.cts +59 -0
  14. package/dist/DeFiPositionsController/fetch-positions.d.cts.map +1 -0
  15. package/dist/DeFiPositionsController/fetch-positions.d.mts +59 -0
  16. package/dist/DeFiPositionsController/fetch-positions.d.mts.map +1 -0
  17. package/dist/DeFiPositionsController/fetch-positions.mjs +17 -0
  18. package/dist/DeFiPositionsController/fetch-positions.mjs.map +1 -0
  19. package/dist/DeFiPositionsController/group-defi-positions.cjs +96 -0
  20. package/dist/DeFiPositionsController/group-defi-positions.cjs.map +1 -0
  21. package/dist/DeFiPositionsController/group-defi-positions.d.cts +36 -0
  22. package/dist/DeFiPositionsController/group-defi-positions.d.cts.map +1 -0
  23. package/dist/DeFiPositionsController/group-defi-positions.d.mts +36 -0
  24. package/dist/DeFiPositionsController/group-defi-positions.d.mts.map +1 -0
  25. package/dist/DeFiPositionsController/group-defi-positions.mjs +92 -0
  26. package/dist/DeFiPositionsController/group-defi-positions.mjs.map +1 -0
  27. package/dist/index.cjs +3 -1
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +3 -0
  30. package/dist/index.d.cts.map +1 -1
  31. package/dist/index.d.mts +3 -0
  32. package/dist/index.d.mts.map +1 -1
  33. package/dist/index.mjs +1 -0
  34. package/dist/index.mjs.map +1 -1
  35. package/package.json +4 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [57.0.0]
11
+
12
+ ### Added
13
+
14
+ - Add a new `DeFiPositionsController` that maintains an updated list of DeFi positions for EVM accounts ([#5400](https://github.com/MetaMask/core/pull/5400))
15
+ - Export `DeFiPositionsController`
16
+ - Export the following types
17
+ - `DeFiPositionsControllerState`
18
+ - `DeFiPositionsControllerActions`
19
+ - `DeFiPositionsControllerEvents`
20
+ - `DeFiPositionsControllerGetStateAction`
21
+ - `DeFiPositionsControllerStateChangeEvent`
22
+ - `DeFiPositionsControllerMessenger`
23
+ - `GroupedDeFiPositions`
24
+
25
+ ### Changed
26
+
27
+ - **BREAKING** Add `@metamask/transaction-controller` as a peer dependency at `^54.0.0` ([#5400](https://github.com/MetaMask/core/pull/5400))
28
+
10
29
  ## [56.0.0]
11
30
 
12
31
  ### Changed
@@ -1520,7 +1539,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1520
1539
 
1521
1540
  - Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
1522
1541
 
1523
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@56.0.0...HEAD
1542
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@57.0.0...HEAD
1543
+ [57.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@56.0.0...@metamask/assets-controllers@57.0.0
1524
1544
  [56.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@55.0.1...@metamask/assets-controllers@56.0.0
1525
1545
  [55.0.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@55.0.0...@metamask/assets-controllers@55.0.1
1526
1546
  [55.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@54.0.0...@metamask/assets-controllers@55.0.0
package/README.md CHANGED
@@ -19,6 +19,7 @@ This package features the following controllers:
19
19
  - [**CollectibleDetectionController**](src/CollectibleDetectionController.ts) keeps a periodically updated list of ERC-721 tokens assigned to the currently selected address.
20
20
  - [**CollectiblesController**](src/CollectiblesController.ts) tracks ERC-721 and ERC-1155 tokens assigned to the currently selected address, using OpenSea to retrieve token information.
21
21
  - [**CurrencyRateController**](src/CurrencyRateController.ts) keeps a periodically updated value of the exchange rate from the currently selected "native" currency to another (handling testnet tokens specially).
22
+ - [**DeFiPositionsController**](src/DeFiPositionsController/DeFiPositionsController.ts.ts) keeps a periodically updated value of the DeFi positions for the owner EVM addresses.
22
23
  - [**RatesController**](src/RatesController/RatesController.ts) keeps a periodically updated value for the exchange rates for different cryptocurrencies. The difference between the `RatesController` and `CurrencyRateController` is that the second one is coupled to the `NetworksController` and is EVM specific, whilst the first one can handle different blockchain currencies like BTC and SOL.
23
24
  - [**TokenBalancesController**](src/TokenBalancesController.ts) keeps a periodically updated set of balances for the current set of ERC-20 tokens.
24
25
  - [**TokenDetectionController**](src/TokenDetectionController.ts) keeps a periodically updated list of ERC-20 tokens assigned to the currently selected address.
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _DeFiPositionsController_instances, _DeFiPositionsController_fetchPositions, _DeFiPositionsController_isEnabled, _DeFiPositionsController_updateAccountPositions, _DeFiPositionsController_fetchAccountPositions;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DeFiPositionsController = exports.getDefaultDefiPositionsControllerState = void 0;
16
+ const polling_controller_1 = require("@metamask/polling-controller");
17
+ const fetch_positions_1 = require("./fetch-positions.cjs");
18
+ const group_defi_positions_1 = require("./group-defi-positions.cjs");
19
+ const assetsUtil_1 = require("../assetsUtil.cjs");
20
+ const TEN_MINUTES_IN_MS = 60000;
21
+ const FETCH_POSITIONS_BATCH_SIZE = 10;
22
+ const controllerName = 'DeFiPositionsController';
23
+ const controllerMetadata = {
24
+ allDeFiPositions: {
25
+ persist: false,
26
+ anonymous: false,
27
+ },
28
+ };
29
+ const getDefaultDefiPositionsControllerState = () => {
30
+ return {
31
+ allDeFiPositions: {},
32
+ };
33
+ };
34
+ exports.getDefaultDefiPositionsControllerState = getDefaultDefiPositionsControllerState;
35
+ /**
36
+ * Controller that stores assets and exposes convenience methods
37
+ */
38
+ class DeFiPositionsController extends (0, polling_controller_1.StaticIntervalPollingController)() {
39
+ /**
40
+ * DeFiPositionsController constuctor
41
+ *
42
+ * @param options - Constructor options.
43
+ * @param options.messenger - The controller messenger.
44
+ * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)
45
+ */
46
+ constructor({ messenger, isEnabled = () => true, }) {
47
+ super({
48
+ name: controllerName,
49
+ metadata: controllerMetadata,
50
+ messenger,
51
+ state: (0, exports.getDefaultDefiPositionsControllerState)(),
52
+ });
53
+ _DeFiPositionsController_instances.add(this);
54
+ _DeFiPositionsController_fetchPositions.set(this, void 0);
55
+ _DeFiPositionsController_isEnabled.set(this, void 0);
56
+ this.setIntervalLength(TEN_MINUTES_IN_MS);
57
+ __classPrivateFieldSet(this, _DeFiPositionsController_fetchPositions, (0, fetch_positions_1.buildPositionFetcher)(), "f");
58
+ __classPrivateFieldSet(this, _DeFiPositionsController_isEnabled, isEnabled, "f");
59
+ this.messagingSystem.subscribe('KeyringController:unlock', () => {
60
+ this.startPolling(null);
61
+ });
62
+ this.messagingSystem.subscribe('KeyringController:lock', () => {
63
+ this.stopAllPolling();
64
+ });
65
+ this.messagingSystem.subscribe('TransactionController:transactionConfirmed', async (transactionMeta) => {
66
+ if (!__classPrivateFieldGet(this, _DeFiPositionsController_isEnabled, "f").call(this)) {
67
+ return;
68
+ }
69
+ await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_updateAccountPositions).call(this, transactionMeta.txParams.from);
70
+ });
71
+ this.messagingSystem.subscribe('AccountsController:accountAdded', async (account) => {
72
+ if (!__classPrivateFieldGet(this, _DeFiPositionsController_isEnabled, "f").call(this) || !account.type.startsWith('eip155:')) {
73
+ return;
74
+ }
75
+ await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_updateAccountPositions).call(this, account.address);
76
+ });
77
+ }
78
+ async _executePoll() {
79
+ if (!__classPrivateFieldGet(this, _DeFiPositionsController_isEnabled, "f").call(this)) {
80
+ return;
81
+ }
82
+ const accounts = this.messagingSystem.call('AccountsController:listAccounts');
83
+ const initialResult = [];
84
+ const results = await (0, assetsUtil_1.reduceInBatchesSerially)({
85
+ initialResult,
86
+ values: accounts,
87
+ batchSize: FETCH_POSITIONS_BATCH_SIZE,
88
+ eachBatch: async (workingResult, batch) => {
89
+ const batchResults = (await Promise.all(batch.map(async ({ address: accountAddress, type }) => {
90
+ if (type.startsWith('eip155:')) {
91
+ const positions = await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_fetchAccountPositions).call(this, accountAddress);
92
+ return {
93
+ accountAddress,
94
+ positions,
95
+ };
96
+ }
97
+ return undefined;
98
+ }))).filter(Boolean);
99
+ return [...workingResult, ...batchResults];
100
+ },
101
+ });
102
+ const allDefiPositions = results.reduce((acc, { accountAddress, positions }) => {
103
+ acc[accountAddress] = positions;
104
+ return acc;
105
+ }, {});
106
+ this.update((state) => {
107
+ state.allDeFiPositions = allDefiPositions;
108
+ });
109
+ }
110
+ }
111
+ exports.DeFiPositionsController = DeFiPositionsController;
112
+ _DeFiPositionsController_fetchPositions = new WeakMap(), _DeFiPositionsController_isEnabled = new WeakMap(), _DeFiPositionsController_instances = new WeakSet(), _DeFiPositionsController_updateAccountPositions = async function _DeFiPositionsController_updateAccountPositions(accountAddress) {
113
+ const accountPositionsPerChain = await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_fetchAccountPositions).call(this, accountAddress);
114
+ this.update((state) => {
115
+ state.allDeFiPositions[accountAddress] = accountPositionsPerChain;
116
+ });
117
+ }, _DeFiPositionsController_fetchAccountPositions = async function _DeFiPositionsController_fetchAccountPositions(accountAddress) {
118
+ try {
119
+ const defiPositionsResponse = await __classPrivateFieldGet(this, _DeFiPositionsController_fetchPositions, "f").call(this, accountAddress);
120
+ return (0, group_defi_positions_1.groupDeFiPositions)(defiPositionsResponse);
121
+ }
122
+ catch {
123
+ return null;
124
+ }
125
+ };
126
+ //# sourceMappingURL=DeFiPositionsController.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeFiPositionsController.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAYA,qEAA+E;AAK/E,2DAAyD;AACzD,qEAGgC;AAChC,kDAAwD;AAExD,MAAM,iBAAiB,GAAG,KAAM,CAAC;AAEjC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAEtC,MAAM,cAAc,GAAG,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M,CAAC,OAAO,CAGb,CAAC;gBAEJ,OAAO,CAAC,GAAG,aAAa,EAAE,GAAG,YAAY,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC,CAAC;QAEH,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CACrC,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,EAAE;YACrC,GAAG,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;YAChC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAsD,CACvD,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CAsBF;AAjJD,0DAiJC;mNApBC,KAAK,0DAAyB,cAAsB;IAClD,MAAM,wBAAwB,GAC5B,MAAM,uBAAA,IAAI,0FAAuB,MAA3B,IAAI,EAAwB,cAAc,CAAC,CAAC;IAEpD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,gBAAgB,CAAC,cAAc,CAAC,GAAG,wBAAwB,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,mDAED,KAAK,yDACH,cAAsB;IAEtB,IAAI;QACF,MAAM,qBAAqB,GAAG,MAAM,uBAAA,IAAI,+CAAgB,MAApB,IAAI,EAAiB,cAAc,CAAC,CAAC;QAEzE,OAAO,IAAA,yCAAkB,EAAC,qBAAqB,CAAC,CAAC;KAClD;IAAC,MAAM;QACN,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerListAccountsAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { KeyringControllerUnlockEvent } from '@metamask/keyring-controller';\nimport type { KeyringControllerLockEvent } from '@metamask/keyring-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionControllerTransactionConfirmedEvent } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { DefiPositionResponse } from './fetch-positions';\nimport { buildPositionFetcher } from './fetch-positions';\nimport {\n groupDeFiPositions,\n type GroupedDeFiPositions,\n} from './group-defi-positions';\nimport { reduceInBatchesSerially } from '../assetsUtil';\n\nconst TEN_MINUTES_IN_MS = 60_000;\n\nconst FETCH_POSITIONS_BATCH_SIZE = 10;\n\nconst controllerName = 'DeFiPositionsController';\n\ntype GroupedDeFiPositionsPerChain = {\n [chain: Hex]: GroupedDeFiPositions;\n};\n\nexport type DeFiPositionsControllerState = {\n /**\n * Object containing DeFi positions per account and network\n */\n allDeFiPositions: {\n [accountAddress: string]: GroupedDeFiPositionsPerChain | null;\n };\n};\n\nconst controllerMetadata: StateMetadata<DeFiPositionsControllerState> = {\n allDeFiPositions: {\n persist: false,\n anonymous: false,\n },\n};\n\nexport const getDefaultDefiPositionsControllerState =\n (): DeFiPositionsControllerState => {\n return {\n allDeFiPositions: {},\n };\n };\n\nexport type DeFiPositionsControllerActions =\n DeFiPositionsControllerGetStateAction;\n\nexport type DeFiPositionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DeFiPositionsControllerState\n>;\n\nexport type DeFiPositionsControllerEvents =\n DeFiPositionsControllerStateChangeEvent;\n\nexport type DeFiPositionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n DeFiPositionsControllerState\n >;\n\n/**\n * The external actions available to the {@link DeFiPositionsController}.\n */\nexport type AllowedActions = AccountsControllerListAccountsAction;\n\n/**\n * The external events available to the {@link DeFiPositionsController}.\n */\nexport type AllowedEvents =\n | KeyringControllerUnlockEvent\n | KeyringControllerLockEvent\n | TransactionControllerTransactionConfirmedEvent\n | AccountsControllerAccountAddedEvent;\n\n/**\n * The messenger of the {@link DeFiPositionsController}.\n */\nexport type DeFiPositionsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DeFiPositionsControllerActions | AllowedActions,\n DeFiPositionsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that stores assets and exposes convenience methods\n */\nexport class DeFiPositionsController extends StaticIntervalPollingController()<\n typeof controllerName,\n DeFiPositionsControllerState,\n DeFiPositionsControllerMessenger\n> {\n readonly #fetchPositions: (\n accountAddress: string,\n ) => Promise<DefiPositionResponse[]>;\n\n readonly #isEnabled: () => boolean;\n\n /**\n * DeFiPositionsController constuctor\n *\n * @param options - Constructor options.\n * @param options.messenger - The controller messenger.\n * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)\n */\n constructor({\n messenger,\n isEnabled = () => true,\n }: {\n messenger: DeFiPositionsControllerMessenger;\n isEnabled?: () => boolean;\n }) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n messenger,\n state: getDefaultDefiPositionsControllerState(),\n });\n\n this.setIntervalLength(TEN_MINUTES_IN_MS);\n\n this.#fetchPositions = buildPositionFetcher();\n this.#isEnabled = isEnabled;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.startPolling(null);\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.stopAllPolling();\n });\n\n this.messagingSystem.subscribe(\n 'TransactionController:transactionConfirmed',\n async (transactionMeta) => {\n if (!this.#isEnabled()) {\n return;\n }\n\n await this.#updateAccountPositions(transactionMeta.txParams.from);\n },\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n async (account) => {\n if (!this.#isEnabled() || !account.type.startsWith('eip155:')) {\n return;\n }\n\n await this.#updateAccountPositions(account.address);\n },\n );\n }\n\n async _executePoll(): Promise<void> {\n if (!this.#isEnabled()) {\n return;\n }\n\n const accounts = this.messagingSystem.call(\n 'AccountsController:listAccounts',\n );\n\n const initialResult: {\n accountAddress: string;\n positions: GroupedDeFiPositionsPerChain | null;\n }[] = [];\n\n const results = await reduceInBatchesSerially({\n initialResult,\n values: accounts,\n batchSize: FETCH_POSITIONS_BATCH_SIZE,\n eachBatch: async (workingResult, batch) => {\n const batchResults = (\n await Promise.all(\n batch.map(async ({ address: accountAddress, type }) => {\n if (type.startsWith('eip155:')) {\n const positions =\n await this.#fetchAccountPositions(accountAddress);\n\n return {\n accountAddress,\n positions,\n };\n }\n\n return undefined;\n }),\n )\n ).filter(Boolean) as {\n accountAddress: string;\n positions: GroupedDeFiPositionsPerChain | null;\n }[];\n\n return [...workingResult, ...batchResults];\n },\n });\n\n const allDefiPositions = results.reduce(\n (acc, { accountAddress, positions }) => {\n acc[accountAddress] = positions;\n return acc;\n },\n {} as DeFiPositionsControllerState['allDeFiPositions'],\n );\n\n this.update((state) => {\n state.allDeFiPositions = allDefiPositions;\n });\n }\n\n async #updateAccountPositions(accountAddress: string): Promise<void> {\n const accountPositionsPerChain =\n await this.#fetchAccountPositions(accountAddress);\n\n this.update((state) => {\n state.allDeFiPositions[accountAddress] = accountPositionsPerChain;\n });\n }\n\n async #fetchAccountPositions(\n accountAddress: string,\n ): Promise<GroupedDeFiPositionsPerChain | null> {\n try {\n const defiPositionsResponse = await this.#fetchPositions(accountAddress);\n\n return groupDeFiPositions(defiPositionsResponse);\n } catch {\n return null;\n }\n }\n}\n"]}
@@ -0,0 +1,72 @@
1
+ /// <reference types="node" />
2
+ import type { AccountsControllerAccountAddedEvent, AccountsControllerListAccountsAction } from "@metamask/accounts-controller";
3
+ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
4
+ import type { KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
5
+ import type { KeyringControllerLockEvent } from "@metamask/keyring-controller";
6
+ import type { TransactionControllerTransactionConfirmedEvent } from "@metamask/transaction-controller";
7
+ import type { Hex } from "@metamask/utils";
8
+ import { type GroupedDeFiPositions } from "./group-defi-positions.cjs";
9
+ declare const controllerName = "DeFiPositionsController";
10
+ type GroupedDeFiPositionsPerChain = {
11
+ [chain: Hex]: GroupedDeFiPositions;
12
+ };
13
+ export type DeFiPositionsControllerState = {
14
+ /**
15
+ * Object containing DeFi positions per account and network
16
+ */
17
+ allDeFiPositions: {
18
+ [accountAddress: string]: GroupedDeFiPositionsPerChain | null;
19
+ };
20
+ };
21
+ export declare const getDefaultDefiPositionsControllerState: () => DeFiPositionsControllerState;
22
+ export type DeFiPositionsControllerActions = DeFiPositionsControllerGetStateAction;
23
+ export type DeFiPositionsControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DeFiPositionsControllerState>;
24
+ export type DeFiPositionsControllerEvents = DeFiPositionsControllerStateChangeEvent;
25
+ export type DeFiPositionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DeFiPositionsControllerState>;
26
+ /**
27
+ * The external actions available to the {@link DeFiPositionsController}.
28
+ */
29
+ export type AllowedActions = AccountsControllerListAccountsAction;
30
+ /**
31
+ * The external events available to the {@link DeFiPositionsController}.
32
+ */
33
+ export type AllowedEvents = KeyringControllerUnlockEvent | KeyringControllerLockEvent | TransactionControllerTransactionConfirmedEvent | AccountsControllerAccountAddedEvent;
34
+ /**
35
+ * The messenger of the {@link DeFiPositionsController}.
36
+ */
37
+ export type DeFiPositionsControllerMessenger = RestrictedMessenger<typeof controllerName, DeFiPositionsControllerActions | AllowedActions, DeFiPositionsControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
38
+ declare const DeFiPositionsController_base: (abstract new (...args: any[]) => {
39
+ readonly "__#14@#intervalIds": Record<string, NodeJS.Timeout>;
40
+ "__#14@#intervalLength": number | undefined;
41
+ setIntervalLength(intervalLength: number): void;
42
+ getIntervalLength(): number | undefined;
43
+ _startPolling(input: import("@metamask/utils").Json): void;
44
+ _stopPollingByPollingTokenSetId(key: string): void;
45
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
46
+ "__#3@#callbacks": Map<string, Set<(input: import("@metamask/utils").Json) => void>>;
47
+ _executePoll(input: import("@metamask/utils").Json): Promise<void>;
48
+ startPolling(input: import("@metamask/utils").Json): string;
49
+ stopAllPolling(): void;
50
+ stopPollingByPollingToken(pollingToken: string): void;
51
+ onPollingComplete(input: import("@metamask/utils").Json, callback: (input: import("@metamask/utils").Json) => void): void;
52
+ }) & typeof import("@metamask/base-controller").BaseController;
53
+ /**
54
+ * Controller that stores assets and exposes convenience methods
55
+ */
56
+ export declare class DeFiPositionsController extends DeFiPositionsController_base<typeof controllerName, DeFiPositionsControllerState, DeFiPositionsControllerMessenger> {
57
+ #private;
58
+ /**
59
+ * DeFiPositionsController constuctor
60
+ *
61
+ * @param options - Constructor options.
62
+ * @param options.messenger - The controller messenger.
63
+ * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)
64
+ */
65
+ constructor({ messenger, isEnabled, }: {
66
+ messenger: DeFiPositionsControllerMessenger;
67
+ isEnabled?: () => boolean;
68
+ });
69
+ _executePoll(): Promise<void>;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=DeFiPositionsController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeFiPositionsController.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,oCAAoC,EACrC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,KAAK,EAAE,4BAA4B,EAAE,qCAAqC;AACjF,OAAO,KAAK,EAAE,0BAA0B,EAAE,qCAAqC;AAE/E,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,EAEL,KAAK,oBAAoB,EAC1B,mCAA+B;AAOhC,QAAA,MAAM,cAAc,4BAA4B,CAAC;AAEjD,KAAK,4BAA4B,GAAG;IAClC,CAAC,KAAK,EAAE,GAAG,GAAG,o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ccountsControllerListAccountsAction } from "@metamask/accounts-controller";
3
+ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
4
+ import type { KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
5
+ import type { KeyringControllerLockEvent } from "@metamask/keyring-controller";
6
+ import type { TransactionControllerTransactionConfirmedEvent } from "@metamask/transaction-controller";
7
+ import type { Hex } from "@metamask/utils";
8
+ import { type GroupedDeFiPositions } from "./group-defi-positions.mjs";
9
+ declare const controllerName = "DeFiPositionsController";
10
+ type GroupedDeFiPositionsPerChain = {
11
+ [chain: Hex]: GroupedDeFiPositions;
12
+ };
13
+ export type DeFiPositionsControllerState = {
14
+ /**
15
+ * Object containing DeFi positions per account and network
16
+ */
17
+ allDeFiPositions: {
18
+ [accountAddress: string]: GroupedDeFiPositionsPerChain | null;
19
+ };
20
+ };
21
+ export declare const getDefaultDefiPositionsControllerState: () => DeFiPositionsControllerState;
22
+ export type DeFiPositionsControllerActions = DeFiPositionsControllerGetStateAction;
23
+ export type DeFiPositionsControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DeFiPositionsControllerState>;
24
+ export type DeFiPositionsControllerEvents = DeFiPositionsControllerStateChangeEvent;
25
+ export type DeFiPositionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DeFiPositionsControllerState>;
26
+ /**
27
+ * The external actions available to the {@link DeFiPositionsController}.
28
+ */
29
+ export type AllowedActions = AccountsControllerListAccountsAction;
30
+ /**
31
+ * The external events available to the {@link DeFiPositionsController}.
32
+ */
33
+ export type AllowedEvents = KeyringControllerUnlockEvent | KeyringControllerLockEvent | TransactionControllerTransactionConfirmedEvent | AccountsControllerAccountAddedEvent;
34
+ /**
35
+ * The messenger of the {@link DeFiPositionsController}.
36
+ */
37
+ export type DeFiPositionsControllerMessenger = RestrictedMessenger<typeof controllerName, DeFiPositionsControllerActions | AllowedActions, DeFiPositionsControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
38
+ declare const DeFiPositionsController_base: (abstract new (...args: any[]) => {
39
+ readonly "__#14@#intervalIds": Record<string, NodeJS.Timeout>;
40
+ "__#14@#intervalLength": number | undefined;
41
+ setIntervalLength(intervalLength: number): void;
42
+ getIntervalLength(): number | undefined;
43
+ _startPolling(input: import("@metamask/utils").Json): void;
44
+ _stopPollingByPollingTokenSetId(key: string): void;
45
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
46
+ "__#3@#callbacks": Map<string, Set<(input: import("@metamask/utils").Json) => void>>;
47
+ _executePoll(input: import("@metamask/utils").Json): Promise<void>;
48
+ startPolling(input: import("@metamask/utils").Json): string;
49
+ stopAllPolling(): void;
50
+ stopPollingByPollingToken(pollingToken: string): void;
51
+ onPollingComplete(input: import("@metamask/utils").Json, callback: (input: import("@metamask/utils").Json) => void): void;
52
+ }) & typeof import("@metamask/base-controller").BaseController;
53
+ /**
54
+ * Controller that stores assets and exposes convenience methods
55
+ */
56
+ export declare class DeFiPositionsController extends DeFiPositionsController_base<typeof controllerName, DeFiPositionsControllerState, DeFiPositionsControllerMessenger> {
57
+ #private;
58
+ /**
59
+ * DeFiPositionsController constuctor
60
+ *
61
+ * @param options - Constructor options.
62
+ * @param options.messenger - The controller messenger.
63
+ * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)
64
+ */
65
+ constructor({ messenger, isEnabled, }: {
66
+ messenger: DeFiPositionsControllerMessenger;
67
+ isEnabled?: () => boolean;
68
+ });
69
+ _executePoll(): Promise<void>;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=DeFiPositionsController.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeFiPositionsController.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,oCAAoC,EACrC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,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;AACH,qBAAa,uBAAwB,SAAQ,6BAC3C,OAAO,cAAc,EACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IAOC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,SAAsB,GACvB,EAAE;QACD,SAAS,EAAE,gCAAgC,CAAC;QAC5C,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;KAC3B;IA4CK,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CA6EpC"}
@@ -0,0 +1,121 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _DeFiPositionsController_instances, _DeFiPositionsController_fetchPositions, _DeFiPositionsController_isEnabled, _DeFiPositionsController_updateAccountPositions, _DeFiPositionsController_fetchAccountPositions;
13
+ import { StaticIntervalPollingController } from "@metamask/polling-controller";
14
+ import { buildPositionFetcher } from "./fetch-positions.mjs";
15
+ import { groupDeFiPositions } from "./group-defi-positions.mjs";
16
+ import { reduceInBatchesSerially } from "../assetsUtil.mjs";
17
+ const TEN_MINUTES_IN_MS = 60000;
18
+ const FETCH_POSITIONS_BATCH_SIZE = 10;
19
+ const controllerName = 'DeFiPositionsController';
20
+ const controllerMetadata = {
21
+ allDeFiPositions: {
22
+ persist: false,
23
+ anonymous: false,
24
+ },
25
+ };
26
+ export const getDefaultDefiPositionsControllerState = () => {
27
+ return {
28
+ allDeFiPositions: {},
29
+ };
30
+ };
31
+ /**
32
+ * Controller that stores assets and exposes convenience methods
33
+ */
34
+ export class DeFiPositionsController extends StaticIntervalPollingController() {
35
+ /**
36
+ * DeFiPositionsController constuctor
37
+ *
38
+ * @param options - Constructor options.
39
+ * @param options.messenger - The controller messenger.
40
+ * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)
41
+ */
42
+ constructor({ messenger, isEnabled = () => true, }) {
43
+ super({
44
+ name: controllerName,
45
+ metadata: controllerMetadata,
46
+ messenger,
47
+ state: getDefaultDefiPositionsControllerState(),
48
+ });
49
+ _DeFiPositionsController_instances.add(this);
50
+ _DeFiPositionsController_fetchPositions.set(this, void 0);
51
+ _DeFiPositionsController_isEnabled.set(this, void 0);
52
+ this.setIntervalLength(TEN_MINUTES_IN_MS);
53
+ __classPrivateFieldSet(this, _DeFiPositionsController_fetchPositions, buildPositionFetcher(), "f");
54
+ __classPrivateFieldSet(this, _DeFiPositionsController_isEnabled, isEnabled, "f");
55
+ this.messagingSystem.subscribe('KeyringController:unlock', () => {
56
+ this.startPolling(null);
57
+ });
58
+ this.messagingSystem.subscribe('KeyringController:lock', () => {
59
+ this.stopAllPolling();
60
+ });
61
+ this.messagingSystem.subscribe('TransactionController:transactionConfirmed', async (transactionMeta) => {
62
+ if (!__classPrivateFieldGet(this, _DeFiPositionsController_isEnabled, "f").call(this)) {
63
+ return;
64
+ }
65
+ await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_updateAccountPositions).call(this, transactionMeta.txParams.from);
66
+ });
67
+ this.messagingSystem.subscribe('AccountsController:accountAdded', async (account) => {
68
+ if (!__classPrivateFieldGet(this, _DeFiPositionsController_isEnabled, "f").call(this) || !account.type.startsWith('eip155:')) {
69
+ return;
70
+ }
71
+ await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_updateAccountPositions).call(this, account.address);
72
+ });
73
+ }
74
+ async _executePoll() {
75
+ if (!__classPrivateFieldGet(this, _DeFiPositionsController_isEnabled, "f").call(this)) {
76
+ return;
77
+ }
78
+ const accounts = this.messagingSystem.call('AccountsController:listAccounts');
79
+ const initialResult = [];
80
+ const results = await reduceInBatchesSerially({
81
+ initialResult,
82
+ values: accounts,
83
+ batchSize: FETCH_POSITIONS_BATCH_SIZE,
84
+ eachBatch: async (workingResult, batch) => {
85
+ const batchResults = (await Promise.all(batch.map(async ({ address: accountAddress, type }) => {
86
+ if (type.startsWith('eip155:')) {
87
+ const positions = await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_fetchAccountPositions).call(this, accountAddress);
88
+ return {
89
+ accountAddress,
90
+ positions,
91
+ };
92
+ }
93
+ return undefined;
94
+ }))).filter(Boolean);
95
+ return [...workingResult, ...batchResults];
96
+ },
97
+ });
98
+ const allDefiPositions = results.reduce((acc, { accountAddress, positions }) => {
99
+ acc[accountAddress] = positions;
100
+ return acc;
101
+ }, {});
102
+ this.update((state) => {
103
+ state.allDeFiPositions = allDefiPositions;
104
+ });
105
+ }
106
+ }
107
+ _DeFiPositionsController_fetchPositions = new WeakMap(), _DeFiPositionsController_isEnabled = new WeakMap(), _DeFiPositionsController_instances = new WeakSet(), _DeFiPositionsController_updateAccountPositions = async function _DeFiPositionsController_updateAccountPositions(accountAddress) {
108
+ const accountPositionsPerChain = await __classPrivateFieldGet(this, _DeFiPositionsController_instances, "m", _DeFiPositionsController_fetchAccountPositions).call(this, accountAddress);
109
+ this.update((state) => {
110
+ state.allDeFiPositions[accountAddress] = accountPositionsPerChain;
111
+ });
112
+ }, _DeFiPositionsController_fetchAccountPositions = async function _DeFiPositionsController_fetchAccountPositions(accountAddress) {
113
+ try {
114
+ const defiPositionsResponse = await __classPrivateFieldGet(this, _DeFiPositionsController_fetchPositions, "f").call(this, accountAddress);
115
+ return groupDeFiPositions(defiPositionsResponse);
116
+ }
117
+ catch {
118
+ return null;
119
+ }
120
+ };
121
+ //# sourceMappingURL=DeFiPositionsController.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeFiPositionsController.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAYA,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAK/E,OAAO,EAAE,oBAAoB,EAAE,8BAA0B;AACzD,OAAO,EACL,kBAAkB,EAEnB,mCAA+B;AAChC,OAAO,EAAE,uBAAuB,EAAE,0BAAsB;AAExD,MAAM,iBAAiB,GAAG,KAAM,CAAC;AAEjC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAEtC,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAejD,MAAM,kBAAkB,GAAgD;IACtE,gBAAgB,EAAE;QAChB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,sCAAsC,GACjD,GAAiC,EAAE;IACjC,OAAO;QACL,gBAAgB,EAAE,EAAE;KACrB,CAAC;AACJ,CAAC,CAAC;AA4CJ;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,+BAA+B,EAI3E;IAOC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,SAAS,GAAG,GAAG,EAAE,CAAC,IAAI,GAIvB;QACC,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,kBAAkB;YAC5B,SAAS;YACT,KAAK,EAAE,sCAAsC,EAAE;SAChD,CAAC,CAAC;;QAzBI,0DAE4B;QAE5B,qDAA0B;QAuBjC,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;QAE1C,uBAAA,IAAI,2CAAmB,oBAAoB,EAAE,MAAA,CAAC;QAC9C,uBAAA,IAAI,sCAAc,SAAS,MAAA,CAAC;QAE5B,IAAI,CAAC,eAAe,C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cAAsB;IAEtB,IAAI;QACF,MAAM,qBAAqB,GAAG,MAAM,uBAAA,IAAI,+CAAgB,MAApB,IAAI,EAAiB,cAAc,CAAC,CAAC;QAEzE,OAAO,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;KAClD;IAAC,MAAM;QACN,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerListAccountsAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { KeyringControllerUnlockEvent } from '@metamask/keyring-controller';\nimport type { KeyringControllerLockEvent } from '@metamask/keyring-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionControllerTransactionConfirmedEvent } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { DefiPositionResponse } from './fetch-positions';\nimport { buildPositionFetcher } from './fetch-positions';\nimport {\n groupDeFiPositions,\n type GroupedDeFiPositions,\n} from './group-defi-positions';\nimport { reduceInBatchesSerially } from '../assetsUtil';\n\nconst TEN_MINUTES_IN_MS = 60_000;\n\nconst FETCH_POSITIONS_BATCH_SIZE = 10;\n\nconst controllerName = 'DeFiPositionsController';\n\ntype GroupedDeFiPositionsPerChain = {\n [chain: Hex]: GroupedDeFiPositions;\n};\n\nexport type DeFiPositionsControllerState = {\n /**\n * Object containing DeFi positions per account and network\n */\n allDeFiPositions: {\n [accountAddress: string]: GroupedDeFiPositionsPerChain | null;\n };\n};\n\nconst controllerMetadata: StateMetadata<DeFiPositionsControllerState> = {\n allDeFiPositions: {\n persist: false,\n anonymous: false,\n },\n};\n\nexport const getDefaultDefiPositionsControllerState =\n (): DeFiPositionsControllerState => {\n return {\n allDeFiPositions: {},\n };\n };\n\nexport type DeFiPositionsControllerActions =\n DeFiPositionsControllerGetStateAction;\n\nexport type DeFiPositionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DeFiPositionsControllerState\n>;\n\nexport type DeFiPositionsControllerEvents =\n DeFiPositionsControllerStateChangeEvent;\n\nexport type DeFiPositionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n DeFiPositionsControllerState\n >;\n\n/**\n * The external actions available to the {@link DeFiPositionsController}.\n */\nexport type AllowedActions = AccountsControllerListAccountsAction;\n\n/**\n * The external events available to the {@link DeFiPositionsController}.\n */\nexport type AllowedEvents =\n | KeyringControllerUnlockEvent\n | KeyringControllerLockEvent\n | TransactionControllerTransactionConfirmedEvent\n | AccountsControllerAccountAddedEvent;\n\n/**\n * The messenger of the {@link DeFiPositionsController}.\n */\nexport type DeFiPositionsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DeFiPositionsControllerActions | AllowedActions,\n DeFiPositionsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that stores assets and exposes convenience methods\n */\nexport class DeFiPositionsController extends StaticIntervalPollingController()<\n typeof controllerName,\n DeFiPositionsControllerState,\n DeFiPositionsControllerMessenger\n> {\n readonly #fetchPositions: (\n accountAddress: string,\n ) => Promise<DefiPositionResponse[]>;\n\n readonly #isEnabled: () => boolean;\n\n /**\n * DeFiPositionsController constuctor\n *\n * @param options - Constructor options.\n * @param options.messenger - The controller messenger.\n * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)\n */\n constructor({\n messenger,\n isEnabled = () => true,\n }: {\n messenger: DeFiPositionsControllerMessenger;\n isEnabled?: () => boolean;\n }) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n messenger,\n state: getDefaultDefiPositionsControllerState(),\n });\n\n this.setIntervalLength(TEN_MINUTES_IN_MS);\n\n this.#fetchPositions = buildPositionFetcher();\n this.#isEnabled = isEnabled;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.startPolling(null);\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.stopAllPolling();\n });\n\n this.messagingSystem.subscribe(\n 'TransactionController:transactionConfirmed',\n async (transactionMeta) => {\n if (!this.#isEnabled()) {\n return;\n }\n\n await this.#updateAccountPositions(transactionMeta.txParams.from);\n },\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n async (account) => {\n if (!this.#isEnabled() || !account.type.startsWith('eip155:')) {\n return;\n }\n\n await this.#updateAccountPositions(account.address);\n },\n );\n }\n\n async _executePoll(): Promise<void> {\n if (!this.#isEnabled()) {\n return;\n }\n\n const accounts = this.messagingSystem.call(\n 'AccountsController:listAccounts',\n );\n\n const initialResult: {\n accountAddress: string;\n positions: GroupedDeFiPositionsPerChain | null;\n }[] = [];\n\n const results = await reduceInBatchesSerially({\n initialResult,\n values: accounts,\n batchSize: FETCH_POSITIONS_BATCH_SIZE,\n eachBatch: async (workingResult, batch) => {\n const batchResults = (\n await Promise.all(\n batch.map(async ({ address: accountAddress, type }) => {\n if (type.startsWith('eip155:')) {\n const positions =\n await this.#fetchAccountPositions(accountAddress);\n\n return {\n accountAddress,\n positions,\n };\n }\n\n return undefined;\n }),\n )\n ).filter(Boolean) as {\n accountAddress: string;\n positions: GroupedDeFiPositionsPerChain | null;\n }[];\n\n return [...workingResult, ...batchResults];\n },\n });\n\n const allDefiPositions = results.reduce(\n (acc, { accountAddress, positions }) => {\n acc[accountAddress] = positions;\n return acc;\n },\n {} as DeFiPositionsControllerState['allDeFiPositions'],\n );\n\n this.update((state) => {\n state.allDeFiPositions = allDefiPositions;\n });\n }\n\n async #updateAccountPositions(accountAddress: string): Promise<void> {\n const accountPositionsPerChain =\n await this.#fetchAccountPositions(accountAddress);\n\n this.update((state) => {\n state.allDeFiPositions[accountAddress] = accountPositionsPerChain;\n });\n }\n\n async #fetchAccountPositions(\n accountAddress: string,\n ): Promise<GroupedDeFiPositionsPerChain | null> {\n try {\n const defiPositionsResponse = await this.#fetchPositions(accountAddress);\n\n return groupDeFiPositions(defiPositionsResponse);\n } catch {\n return null;\n }\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPositionFetcher = exports.DEFI_POSITIONS_API_URL = void 0;
4
+ // TODO: Update with prod API URL when available
5
+ exports.DEFI_POSITIONS_API_URL = 'https://defiadapters.dev-api.cx.metamask.io';
6
+ /**
7
+ * Builds a function that fetches DeFi positions for a given account address
8
+ *
9
+ * @returns A function that fetches DeFi positions for a given account address
10
+ */
11
+ function buildPositionFetcher() {
12
+ return async (accountAddress) => {
13
+ const defiPositionsResponse = await fetch(`${exports.DEFI_POSITIONS_API_URL}/positions/${accountAddress}`);
14
+ if (defiPositionsResponse.status !== 200) {
15
+ throw new Error(`Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`);
16
+ }
17
+ return (await defiPositionsResponse.json()).data;
18
+ };
19
+ }
20
+ exports.buildPositionFetcher = buildPositionFetcher;
21
+ //# sourceMappingURL=fetch-positions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":";;;AAyDA,gDAAgD;AACnC,QAAA,sBAAsB,GACjC,6CAA6C,CAAC;AAEhD;;;;GAIG;AACH,SAAgB,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,KAAK,CACvC,GAAG,8BAAsB,cAAc,cAAc,EAAE,CACxD,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE;YACxC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;SACH;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC;AAdD,oDAcC","sourcesContent":["export type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL =\n 'https://defiadapters.dev-api.cx.metamask.io';\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await fetch(\n `${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
@@ -0,0 +1,59 @@
1
+ export type DefiPositionResponse = AdapterResponse<{
2
+ tokens: ProtocolToken[];
3
+ }>;
4
+ type ProtocolDetails = {
5
+ chainId: number;
6
+ protocolId: string;
7
+ productId: string;
8
+ protocolDisplayName: string;
9
+ name: string;
10
+ description: string;
11
+ iconUrl: string;
12
+ siteUrl: string;
13
+ positionType: PositionType;
14
+ metadata?: {
15
+ groupPositions?: boolean;
16
+ };
17
+ };
18
+ type AdapterResponse<ProtocolResponse> = (ProtocolDetails & {
19
+ chainName: string;
20
+ } & ((ProtocolResponse & {
21
+ success: true;
22
+ }) | (AdapterErrorResponse & {
23
+ success: false;
24
+ }))) | (AdapterErrorResponse & {
25
+ success: false;
26
+ });
27
+ type AdapterErrorResponse = {
28
+ error: {
29
+ message: string;
30
+ };
31
+ };
32
+ export type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';
33
+ export type ProtocolToken = Balance & {
34
+ type: 'protocol';
35
+ tokenId?: string;
36
+ };
37
+ export type Underlying = Balance & {
38
+ type: 'underlying' | 'underlying-claimable';
39
+ iconUrl: string;
40
+ };
41
+ export type Balance = {
42
+ address: string;
43
+ name: string;
44
+ symbol: string;
45
+ decimals: number;
46
+ balanceRaw: string;
47
+ balance: number;
48
+ price?: number;
49
+ tokens?: Underlying[];
50
+ };
51
+ export declare const DEFI_POSITIONS_API_URL = "https://defiadapters.dev-api.cx.metamask.io";
52
+ /**
53
+ * Builds a function that fetches DeFi positions for a given account address
54
+ *
55
+ * @returns A function that fetches DeFi positions for a given account address
56
+ */
57
+ export declare function buildPositionFetcher(): (accountAddress: string) => Promise<DefiPositionResponse[]>;
58
+ export {};
59
+ //# sourceMappingURL=fetch-positions.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-positions.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,eAAe,CAAC;IACjD,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC,CAAC;AAEH,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAA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AGF,eAAO,MAAM,sBAAsB,gDACY,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,oBAAoB,qBACJ,MAAM,KAAG,QAAQ,oBAAoB,EAAE,CAAC,CAavE"}
@@ -0,0 +1,59 @@
1
+ export type DefiPositionResponse = AdapterResponse<{
2
+ tokens: ProtocolToken[];
3
+ }>;
4
+ type ProtocolDetails = {
5
+ chainId: number;
6
+ protocolId: string;
7
+ productId: string;
8
+ protocolDisplayName: string;
9
+ name: string;
10
+ description: string;
11
+ iconUrl: string;
12
+ siteUrl: string;
13
+ positionType: PositionType;
14
+ metadata?: {
15
+ groupPositions?: boolean;
16
+ };
17
+ };
18
+ type AdapterResponse<ProtocolResponse> = (ProtocolDetails & {
19
+ chainName: string;
20
+ } & ((ProtocolResponse & {
21
+ success: true;
22
+ }) | (AdapterErrorResponse & {
23
+ success: false;
24
+ }))) | (AdapterErrorResponse & {
25
+ success: false;
26
+ });
27
+ type AdapterErrorResponse = {
28
+ error: {
29
+ message: string;
30
+ };
31
+ };
32
+ export type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';
33
+ export type ProtocolToken = Balance & {
34
+ type: 'protocol';
35
+ tokenId?: string;
36
+ };
37
+ export type Underlying = Balance & {
38
+ type: 'underlying' | 'underlying-claimable';
39
+ iconUrl: string;
40
+ };
41
+ export type Balance = {
42
+ address: string;
43
+ name: string;
44
+ symbol: string;
45
+ decimals: number;
46
+ balanceRaw: string;
47
+ balance: number;
48
+ price?: number;
49
+ tokens?: Underlying[];
50
+ };
51
+ export declare const DEFI_POSITIONS_API_URL = "https://defiadapters.dev-api.cx.metamask.io";
52
+ /**
53
+ * Builds a function that fetches DeFi positions for a given account address
54
+ *
55
+ * @returns A function that fetches DeFi positions for a given account address
56
+ */
57
+ export declare function buildPositionFetcher(): (accountAddress: string) => Promise<DefiPositionResponse[]>;
58
+ export {};
59
+ //# sourceMappingURL=fetch-positions.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-positions.d.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Y,GAAG,sBAAsB,CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AAGF,eAAO,MAAM,sBAAsB,gDACY,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,oBAAoB,qBACJ,MAAM,KAAG,QAAQ,oBAAoB,EAAE,CAAC,CAavE"}
@@ -0,0 +1,17 @@
1
+ // TODO: Update with prod API URL when available
2
+ export const DEFI_POSITIONS_API_URL = 'https://defiadapters.dev-api.cx.metamask.io';
3
+ /**
4
+ * Builds a function that fetches DeFi positions for a given account address
5
+ *
6
+ * @returns A function that fetches DeFi positions for a given account address
7
+ */
8
+ export function buildPositionFetcher() {
9
+ return async (accountAddress) => {
10
+ const defiPositionsResponse = await fetch(`${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`);
11
+ if (defiPositionsResponse.status !== 200) {
12
+ throw new Error(`Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`);
13
+ }
14
+ return (await defiPositionsResponse.json()).data;
15
+ };
16
+ }
17
+ //# sourceMappingURL=fetch-positions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":"AAyDA,gDAAgD;AAChD,MAAM,CAAC,MAAM,sBAAsB,GACjC,6CAA6C,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,KAAK,CACvC,GAAG,sBAAsB,cAAc,cAAc,EAAE,CACxD,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE;YACxC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;SACH;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["export type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL =\n 'https://defiadapters.dev-api.cx.metamask.io';\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await fetch(\n `${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupDeFiPositions = void 0;
4
+ const controller_utils_1 = require("@metamask/controller-utils");
5
+ /**
6
+ *
7
+ * @param defiPositionsResponse - The response from the defi positions API
8
+ * @returns The grouped positions that get assigned to the state
9
+ */
10
+ function groupDeFiPositions(defiPositionsResponse) {
11
+ const groupedDeFiPositions = {};
12
+ for (const position of defiPositionsResponse) {
13
+ if (!position.success) {
14
+ continue;
15
+ }
16
+ const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } = position;
17
+ const chain = (0, controller_utils_1.toHex)(chainId);
18
+ if (!groupedDeFiPositions[chain]) {
19
+ groupedDeFiPositions[chain] = {
20
+ aggregatedMarketValue: 0,
21
+ protocols: {},
22
+ };
23
+ }
24
+ const chainData = groupedDeFiPositions[chain];
25
+ if (!chainData.protocols[protocolId]) {
26
+ chainData.protocols[protocolId] = {
27
+ protocolDetails: {
28
+ name: protocolDisplayName,
29
+ iconUrl,
30
+ },
31
+ aggregatedMarketValue: 0,
32
+ positionTypes: {},
33
+ };
34
+ }
35
+ const protocolData = chainData.protocols[protocolId];
36
+ let positionTypeData = protocolData.positionTypes[positionType];
37
+ if (!positionTypeData) {
38
+ positionTypeData = {
39
+ aggregatedMarketValue: 0,
40
+ positions: [],
41
+ };
42
+ protocolData.positionTypes[positionType] = positionTypeData;
43
+ }
44
+ for (const protocolToken of position.tokens) {
45
+ const token = processToken(protocolToken);
46
+ // If groupPositions is true, we group all positions of the same type
47
+ if (position.metadata?.groupPositions) {
48
+ if (positionTypeData.positions.length === 0) {
49
+ positionTypeData.positions.push([token]);
50
+ }
51
+ else {
52
+ positionTypeData.positions[0].push(token);
53
+ }
54
+ }
55
+ else {
56
+ positionTypeData.positions.push([token]);
57
+ }
58
+ if (token.marketValue) {
59
+ const multiplier = position.positionType === 'borrow' ? -1 : 1;
60
+ positionTypeData.aggregatedMarketValue += token.marketValue;
61
+ protocolData.aggregatedMarketValue += token.marketValue * multiplier;
62
+ chainData.aggregatedMarketValue += token.marketValue * multiplier;
63
+ }
64
+ }
65
+ }
66
+ return groupedDeFiPositions;
67
+ }
68
+ exports.groupDeFiPositions = groupDeFiPositions;
69
+ /**
70
+ *
71
+ * @param tokenBalance - The token balance that is going to be processed
72
+ * @returns The processed token balance
73
+ */
74
+ function processToken(tokenBalance) {
75
+ if (!tokenBalance.tokens) {
76
+ return {
77
+ ...tokenBalance,
78
+ marketValue: tokenBalance.price
79
+ ? tokenBalance.balance * tokenBalance.price
80
+ : undefined,
81
+ };
82
+ }
83
+ const processedTokens = tokenBalance.tokens.map((t) => {
84
+ const { tokens, ...tokenWithoutUnderlyings } = processToken(t);
85
+ return tokenWithoutUnderlyings;
86
+ });
87
+ const marketValue = processedTokens.reduce((acc, t) => acc === undefined || t.marketValue === undefined
88
+ ? undefined
89
+ : acc + t.marketValue, 0);
90
+ return {
91
+ ...tokenBalance,
92
+ marketValue,
93
+ tokens: processedTokens,
94
+ };
95
+ }
96
+ //# sourceMappingURL=group-defi-positions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-defi-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAoCnD;;;;GAIG;AACH,SAAgB,kBAAkB,CAChC,qBAA6C;IAI7C,MAAM,oBAAoB,GAAyC,EAAE,CAAC;IAEtE,KAAK,MAAM,QAAQ,IAAI,qBAAqB,EAAE;QAC5C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACrB,SAAS;SACV;QAED,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,GACvE,QAAQ,CAAC;QAEX,MAAM,KAAK,GAAG,IA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AC;IAEF,OAAO;QACL,GAAG,YAAY;QACf,WAAW;QACX,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n DefiPositionResponse,\n PositionType,\n ProtocolToken,\n Underlying,\n Balance,\n} from './fetch-positions';\n\nexport type GroupedDeFiPositions = {\n aggregatedMarketValue: number;\n protocols: {\n [protocolId: string]: {\n protocolDetails: { name: string; iconUrl: string };\n aggregatedMarketValue: number;\n positionTypes: {\n [key in PositionType]?: {\n aggregatedMarketValue: number;\n positions: ProtocolTokenWithMarketValue[][];\n };\n };\n };\n };\n};\n\nexport type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {\n marketValue?: number;\n tokens: UnderlyingWithMarketValue[];\n};\n\nexport type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {\n marketValue?: number;\n};\n\n/**\n *\n * @param defiPositionsResponse - The response from the defi positions API\n * @returns The grouped positions that get assigned to the state\n */\nexport function groupDeFiPositions(\n defiPositionsResponse: DefiPositionResponse[],\n): {\n [key: Hex]: GroupedDeFiPositions;\n} {\n const groupedDeFiPositions: { [key: Hex]: GroupedDeFiPositions } = {};\n\n for (const position of defiPositionsResponse) {\n if (!position.success) {\n continue;\n }\n\n const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } =\n position;\n\n const chain = toHex(chainId);\n\n if (!groupedDeFiPositions[chain]) {\n groupedDeFiPositions[chain] = {\n aggregatedMarketValue: 0,\n protocols: {},\n };\n }\n\n const chainData = groupedDeFiPositions[chain];\n\n if (!chainData.protocols[protocolId]) {\n chainData.protocols[protocolId] = {\n protocolDetails: {\n name: protocolDisplayName,\n iconUrl,\n },\n aggregatedMarketValue: 0,\n positionTypes: {},\n };\n }\n\n const protocolData = chainData.protocols[protocolId];\n\n let positionTypeData = protocolData.positionTypes[positionType];\n if (!positionTypeData) {\n positionTypeData = {\n aggregatedMarketValue: 0,\n positions: [],\n };\n protocolData.positionTypes[positionType] = positionTypeData;\n }\n\n for (const protocolToken of position.tokens) {\n const token = processToken(protocolToken) as ProtocolTokenWithMarketValue;\n\n // If groupPositions is true, we group all positions of the same type\n if (position.metadata?.groupPositions) {\n if (positionTypeData.positions.length === 0) {\n positionTypeData.positions.push([token]);\n } else {\n positionTypeData.positions[0].push(token);\n }\n } else {\n positionTypeData.positions.push([token]);\n }\n\n if (token.marketValue) {\n const multiplier = position.positionType === 'borrow' ? -1 : 1;\n\n positionTypeData.aggregatedMarketValue += token.marketValue;\n protocolData.aggregatedMarketValue += token.marketValue * multiplier;\n chainData.aggregatedMarketValue += token.marketValue * multiplier;\n }\n }\n }\n\n return groupedDeFiPositions;\n}\n\n/**\n *\n * @param tokenBalance - The token balance that is going to be processed\n * @returns The processed token balance\n */\nfunction processToken<T extends Balance>(\n tokenBalance: T,\n): T & {\n marketValue?: number;\n tokens?: UnderlyingWithMarketValue[];\n} {\n if (!tokenBalance.tokens) {\n return {\n ...tokenBalance,\n marketValue: tokenBalance.price\n ? tokenBalance.balance * tokenBalance.price\n : undefined,\n };\n }\n\n const processedTokens = tokenBalance.tokens.map((t) => {\n const { tokens, ...tokenWithoutUnderlyings } = processToken(t);\n\n return tokenWithoutUnderlyings;\n });\n\n const marketValue = processedTokens.reduce(\n (acc, t) =>\n acc === undefined || t.marketValue === undefined\n ? undefined\n : acc + t.marketValue,\n 0 as number | undefined,\n );\n\n return {\n ...tokenBalance,\n marketValue,\n tokens: processedTokens,\n };\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ import type { DefiPositionResponse, PositionType, ProtocolToken, Underlying } from "./fetch-positions.cjs";
3
+ export type GroupedDeFiPositions = {
4
+ aggregatedMarketValue: number;
5
+ protocols: {
6
+ [protocolId: string]: {
7
+ protocolDetails: {
8
+ name: string;
9
+ iconUrl: string;
10
+ };
11
+ aggregatedMarketValue: number;
12
+ positionTypes: {
13
+ [key in PositionType]?: {
14
+ aggregatedMarketValue: number;
15
+ positions: ProtocolTokenWithMarketValue[][];
16
+ };
17
+ };
18
+ };
19
+ };
20
+ };
21
+ export type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {
22
+ marketValue?: number;
23
+ tokens: UnderlyingWithMarketValue[];
24
+ };
25
+ export type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {
26
+ marketValue?: number;
27
+ };
28
+ /**
29
+ *
30
+ * @param defiPositionsResponse - The response from the defi positions API
31
+ * @returns The grouped positions that get assigned to the state
32
+ */
33
+ export declare function groupDeFiPositions(defiPositionsResponse: DefiPositionResponse[]): {
34
+ [key: Hex]: GroupedDeFiPositions;
35
+ };
36
+ //# sourceMappingURL=group-defi-positions.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-defi-positions.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,UAAU,EAEX,8BAA0B;AAE3B,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE;QACT,CAAC,UAAU,EAAE,MAAM,GAAG;YACpB,eAAe,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,OAAO,EAAE,MAAM,CAAA;aAAE,CAAC;YACnD,qBAAqB,EAAE,MAAM,CAAC;YAC9B,aAAa,EAAE;iBACZ,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE;oBACtB,qBAAqB,EAAE,MAAM,CAAC;oBAC9B,SAAS,EAAE,4BAA4B,EAAE,EAAE,CAAC;iBAC7C;aACF,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,yBAAyB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C;IACD,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAAC;CAClC,CAqEA"}
@@ -0,0 +1,36 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ import type { DefiPositionResponse, PositionType, ProtocolToken, Underlying } from "./fetch-positions.mjs";
3
+ export type GroupedDeFiPositions = {
4
+ aggregatedMarketValue: number;
5
+ protocols: {
6
+ [protocolId: string]: {
7
+ protocolDetails: {
8
+ name: string;
9
+ iconUrl: string;
10
+ };
11
+ aggregatedMarketValue: number;
12
+ positionTypes: {
13
+ [key in PositionType]?: {
14
+ aggregatedMarketValue: number;
15
+ positions: ProtocolTokenWithMarketValue[][];
16
+ };
17
+ };
18
+ };
19
+ };
20
+ };
21
+ export type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {
22
+ marketValue?: number;
23
+ tokens: UnderlyingWithMarketValue[];
24
+ };
25
+ export type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {
26
+ marketValue?: number;
27
+ };
28
+ /**
29
+ *
30
+ * @param defiPositionsResponse - The response from the defi positions API
31
+ * @returns The grouped positions that get assigned to the state
32
+ */
33
+ export declare function groupDeFiPositions(defiPositionsResponse: DefiPositionResponse[]): {
34
+ [key: Hex]: GroupedDeFiPositions;
35
+ };
36
+ //# sourceMappingURL=group-defi-positions.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-defi-positions.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,UAAU,EAEX,8BAA0B;AAE3B,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE;QACT,CAAC,UAAU,EAAE,MAAM,GAAG;YACpB,eAAe,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,OAAO,EAAE,MAAM,CAAA;aAAE,CAAC;YACnD,qBAAqB,EAAE,MAAM,CAAC;YAC9B,aAAa,EAAE;iBACZ,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE;oBACtB,qBAAqB,EAAE,MAAM,CAAC;oBAC9B,SAAS,EAAE,4BAA4B,EAAE,EAAE,CAAC;iBAC7C;aACF,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,yBAAyB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C;IACD,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAAC;CAClC,CAqEA"}
@@ -0,0 +1,92 @@
1
+ import { toHex } from "@metamask/controller-utils";
2
+ /**
3
+ *
4
+ * @param defiPositionsResponse - The response from the defi positions API
5
+ * @returns The grouped positions that get assigned to the state
6
+ */
7
+ export function groupDeFiPositions(defiPositionsResponse) {
8
+ const groupedDeFiPositions = {};
9
+ for (const position of defiPositionsResponse) {
10
+ if (!position.success) {
11
+ continue;
12
+ }
13
+ const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } = position;
14
+ const chain = toHex(chainId);
15
+ if (!groupedDeFiPositions[chain]) {
16
+ groupedDeFiPositions[chain] = {
17
+ aggregatedMarketValue: 0,
18
+ protocols: {},
19
+ };
20
+ }
21
+ const chainData = groupedDeFiPositions[chain];
22
+ if (!chainData.protocols[protocolId]) {
23
+ chainData.protocols[protocolId] = {
24
+ protocolDetails: {
25
+ name: protocolDisplayName,
26
+ iconUrl,
27
+ },
28
+ aggregatedMarketValue: 0,
29
+ positionTypes: {},
30
+ };
31
+ }
32
+ const protocolData = chainData.protocols[protocolId];
33
+ let positionTypeData = protocolData.positionTypes[positionType];
34
+ if (!positionTypeData) {
35
+ positionTypeData = {
36
+ aggregatedMarketValue: 0,
37
+ positions: [],
38
+ };
39
+ protocolData.positionTypes[positionType] = positionTypeData;
40
+ }
41
+ for (const protocolToken of position.tokens) {
42
+ const token = processToken(protocolToken);
43
+ // If groupPositions is true, we group all positions of the same type
44
+ if (position.metadata?.groupPositions) {
45
+ if (positionTypeData.positions.length === 0) {
46
+ positionTypeData.positions.push([token]);
47
+ }
48
+ else {
49
+ positionTypeData.positions[0].push(token);
50
+ }
51
+ }
52
+ else {
53
+ positionTypeData.positions.push([token]);
54
+ }
55
+ if (token.marketValue) {
56
+ const multiplier = position.positionType === 'borrow' ? -1 : 1;
57
+ positionTypeData.aggregatedMarketValue += token.marketValue;
58
+ protocolData.aggregatedMarketValue += token.marketValue * multiplier;
59
+ chainData.aggregatedMarketValue += token.marketValue * multiplier;
60
+ }
61
+ }
62
+ }
63
+ return groupedDeFiPositions;
64
+ }
65
+ /**
66
+ *
67
+ * @param tokenBalance - The token balance that is going to be processed
68
+ * @returns The processed token balance
69
+ */
70
+ function processToken(tokenBalance) {
71
+ if (!tokenBalance.tokens) {
72
+ return {
73
+ ...tokenBalance,
74
+ marketValue: tokenBalance.price
75
+ ? tokenBalance.balance * tokenBalance.price
76
+ : undefined,
77
+ };
78
+ }
79
+ const processedTokens = tokenBalance.tokens.map((t) => {
80
+ const { tokens, ...tokenWithoutUnderlyings } = processToken(t);
81
+ return tokenWithoutUnderlyings;
82
+ });
83
+ const marketValue = processedTokens.reduce((acc, t) => acc === undefined || t.marketValue === undefined
84
+ ? undefined
85
+ : acc + t.marketValue, 0);
86
+ return {
87
+ ...tokenBalance,
88
+ marketValue,
89
+ tokens: processedTokens,
90
+ };
91
+ }
92
+ //# sourceMappingURL=group-defi-positions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-defi-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAoCnD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,qBAA6C;IAI7C,MAAM,oBAAoB,GAAyC,EAAE,CAAC;IAEtE,KAAK,MAAM,QAAQ,IAAI,qBAAqB,EAAE;QAC5C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACrB,SAAS;SACV;QAED,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,GACvE,QAAQ,CAAC;QAEX,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAE7B,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE;YAChC,oBAAoB,CAAC,KAAK,CAAC,GAAG;gBAC5B,qBAAqB,EAAE,CAAC;gBACxB,SAAS,EAAE,EAAE;aACd,CAAC;SACH;QAED,MAAM,SAAS,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAE9C,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YACpC,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG;gBAChC,eAAe,EAAE;oBACf,IAAI,EAAE,mBAAmB;oBACzB,OAAO;iBACR;gBACD,qBAAqB,EAAE,CAAC;gBACxB,aAAa,EAAE,E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OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CACnB,YAAe;IAKf,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QACxB,OAAO;YACL,GAAG,YAAY;YACf,WAAW,EAAE,YAAY,CAAC,KAAK;gBAC7B,CAAC,CAAC,YAAY,CAAC,OAAO,GAAG,YAAY,CAAC,KAAK;gBAC3C,CAAC,CAAC,SAAS;SACd,CAAC;KACH;IAED,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACpD,MAAM,EAAE,MAAM,EAAE,GAAG,uBAAuB,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QAE/D,OAAO,uBAAuB,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CACxC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CACT,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAC9C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW,EACzB,CAAuB,CACxB,CAAC;IAEF,OAAO;QACL,GAAG,YAAY;QACf,WAAW;QACX,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n DefiPositionResponse,\n PositionType,\n ProtocolToken,\n Underlying,\n Balance,\n} from './fetch-positions';\n\nexport type GroupedDeFiPositions = {\n aggregatedMarketValue: number;\n protocols: {\n [protocolId: string]: {\n protocolDetails: { name: string; iconUrl: string };\n aggregatedMarketValue: number;\n positionTypes: {\n [key in PositionType]?: {\n aggregatedMarketValue: number;\n positions: ProtocolTokenWithMarketValue[][];\n };\n };\n };\n };\n};\n\nexport type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {\n marketValue?: number;\n tokens: UnderlyingWithMarketValue[];\n};\n\nexport type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {\n marketValue?: number;\n};\n\n/**\n *\n * @param defiPositionsResponse - The response from the defi positions API\n * @returns The grouped positions that get assigned to the state\n */\nexport function groupDeFiPositions(\n defiPositionsResponse: DefiPositionResponse[],\n): {\n [key: Hex]: GroupedDeFiPositions;\n} {\n const groupedDeFiPositions: { [key: Hex]: GroupedDeFiPositions } = {};\n\n for (const position of defiPositionsResponse) {\n if (!position.success) {\n continue;\n }\n\n const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } =\n position;\n\n const chain = toHex(chainId);\n\n if (!groupedDeFiPositions[chain]) {\n groupedDeFiPositions[chain] = {\n aggregatedMarketValue: 0,\n protocols: {},\n };\n }\n\n const chainData = groupedDeFiPositions[chain];\n\n if (!chainData.protocols[protocolId]) {\n chainData.protocols[protocolId] = {\n protocolDetails: {\n name: protocolDisplayName,\n iconUrl,\n },\n aggregatedMarketValue: 0,\n positionTypes: {},\n };\n }\n\n const protocolData = chainData.protocols[protocolId];\n\n let positionTypeData = protocolData.positionTypes[positionType];\n if (!positionTypeData) {\n positionTypeData = {\n aggregatedMarketValue: 0,\n positions: [],\n };\n protocolData.positionTypes[positionType] = positionTypeData;\n }\n\n for (const protocolToken of position.tokens) {\n const token = processToken(protocolToken) as ProtocolTokenWithMarketValue;\n\n // If groupPositions is true, we group all positions of the same type\n if (position.metadata?.groupPositions) {\n if (positionTypeData.positions.length === 0) {\n positionTypeData.positions.push([token]);\n } else {\n positionTypeData.positions[0].push(token);\n }\n } else {\n positionTypeData.positions.push([token]);\n }\n\n if (token.marketValue) {\n const multiplier = position.positionType === 'borrow' ? -1 : 1;\n\n positionTypeData.aggregatedMarketValue += token.marketValue;\n protocolData.aggregatedMarketValue += token.marketValue * multiplier;\n chainData.aggregatedMarketValue += token.marketValue * multiplier;\n }\n }\n }\n\n return groupedDeFiPositions;\n}\n\n/**\n *\n * @param tokenBalance - The token balance that is going to be processed\n * @returns The processed token balance\n */\nfunction processToken<T extends Balance>(\n tokenBalance: T,\n): T & {\n marketValue?: number;\n tokens?: UnderlyingWithMarketValue[];\n} {\n if (!tokenBalance.tokens) {\n return {\n ...tokenBalance,\n marketValue: tokenBalance.price\n ? tokenBalance.balance * tokenBalance.price\n : undefined,\n };\n }\n\n const processedTokens = tokenBalance.tokens.map((t) => {\n const { tokens, ...tokenWithoutUnderlyings } = processToken(t);\n\n return tokenWithoutUnderlyings;\n });\n\n const marketValue = processedTokens.reduce(\n (acc, t) =>\n acc === undefined || t.marketValue === undefined\n ? undefined\n : acc + t.marketValue,\n 0 as number | undefined,\n );\n\n return {\n ...tokenBalance,\n marketValue,\n tokens: processedTokens,\n };\n}\n"]}
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.TokenSearchDiscoveryDataController = exports.getDefaultMultichainAssetsRatesControllerState = exports.MultichainAssetsRatesController = exports.getDefaultMultichainAssetsControllerState = exports.MultichainAssetsController = exports.MultichainBalancesController = exports.Cryptocurrency = exports.RatesController = exports.getNativeTokenAddress = exports.SUPPORTED_CHAIN_IDS = exports.CodefiTokenPricesServiceV2 = exports.getKeyByValue = exports.fetchTokenContractExchangeRates = exports.getFormattedIpfsUrl = exports.formatIconUrlWithProxy = exports.isTokenDetectionSupportedForNetwork = exports.TokensController = exports.TokenRatesController = exports.getDefaultTokenRatesControllerState = exports.TokenListController = exports.TokenDetectionController = exports.TokenBalancesController = exports.NftDetectionController = exports.NftController = exports.getDefaultNftControllerState = exports.AssetsContractController = exports.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID = exports.AccountTrackerController = void 0;
17
+ exports.DeFiPositionsController = exports.TokenSearchDiscoveryDataController = exports.getDefaultMultichainAssetsRatesControllerState = exports.MultichainAssetsRatesController = exports.getDefaultMultichainAssetsControllerState = exports.MultichainAssetsController = exports.MultichainBalancesController = exports.Cryptocurrency = exports.RatesController = exports.getNativeTokenAddress = exports.SUPPORTED_CHAIN_IDS = exports.CodefiTokenPricesServiceV2 = exports.getKeyByValue = exports.fetchTokenContractExchangeRates = exports.getFormattedIpfsUrl = exports.formatIconUrlWithProxy = exports.isTokenDetectionSupportedForNetwork = exports.TokensController = exports.TokenRatesController = exports.getDefaultTokenRatesControllerState = exports.TokenListController = exports.TokenDetectionController = exports.TokenBalancesController = exports.NftDetectionController = exports.NftController = exports.getDefaultNftControllerState = exports.AssetsContractController = exports.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID = exports.AccountTrackerController = void 0;
18
18
  var AccountTrackerController_1 = require("./AccountTrackerController.cjs");
19
19
  Object.defineProperty(exports, "AccountTrackerController", { enumerable: true, get: function () { return AccountTrackerController_1.AccountTrackerController; } });
20
20
  var AssetsContractController_1 = require("./AssetsContractController.cjs");
@@ -60,4 +60,6 @@ Object.defineProperty(exports, "MultichainAssetsRatesController", { enumerable:
60
60
  Object.defineProperty(exports, "getDefaultMultichainAssetsRatesControllerState", { enumerable: true, get: function () { return MultichainAssetsRatesController_1.getDefaultMultichainAssetsRatesControllerState; } });
61
61
  var TokenSearchDiscoveryDataController_1 = require("./TokenSearchDiscoveryDataController/index.cjs");
62
62
  Object.defineProperty(exports, "TokenSearchDiscoveryDataController", { enumerable: true, get: function () { return TokenSearchDiscoveryDataController_1.TokenSearchDiscoveryDataController; } });
63
+ var DeFiPositionsController_1 = require("./DeFiPositionsController/DeFiPositionsController.cjs");
64
+ Object.defineProperty(exports, "DeFiPositionsController", { enumerable: true, get: function () { return DeFiPositionsController_1.DeFiPositionsController; } });
63
65
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AASA,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AAuBjC,2EAGoC;AAFlC,mJAAA,uCAAuC,OAAA;AACvC,oIAAA,wBAAwB,OAAA;AAE1B,+DAAyC;AAYzC,qDAA8E;AAArE,6HAAA,4BAA4B,OAAA;AAAE,8GAAA,aAAa,OAAA;AAwBpD,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAS/B,yEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAQhC,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AAWjC,iEAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAa5B,mEAGgC;AAF9B,2IAAA,mCAAmC,OAAA;AACnC,4HAAA,oBAAoB,OAAA;AAWtB,2DAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,+CAMsB;AALpB,iIAAA,mCAAmC,OAAA;AACnC,oHAAA,sBAAsB,OAAA;AACtB,iHAAA,mBAAmB,OAAA;AACnB,6HAAA,+BAA+B,OAAA;AAC/B,2GAAA,aAAa,OAAA;AAEf,yEAIgC;AAH9B,kIAAA,0BAA0B,OAAA;AAC1B,2HAAA,mBAAmB,OAAA;AACnB,6HAAA,qBAAqB,OAAA;AAEvB,+DAAoE;AAA3D,kHAAA,eAAe,OAAA;AAAE,iHAAA,cAAc,OAAA;AAWxC,yFAA8E;AAArE,4IAAA,4BAA4B,OAAA;AAUrC,qFAGsC;AAFpC,wIAAA,0BAA0B,OAAA;AAC1B,uJAAA,yCAAyC,OAAA;AAY3C,+FAG2C;AAFzC,kJAAA,+BAA+B,OAAA;AAC/B,iKAAA,8CAA8C,OAAA;AAWhD,qGAA0F;AAAjF,wJAAA,kCAAkC,OAAA","sourcesContent":["export type {\n AccountInformation,\n AccountTrackerControllerMessenger,\n AccountTrackerControllerState,\n AccountTrackerControllerActions,\n AccountTrackerControllerGetStateAction,\n AccountTrackerControllerStateChangeEvent,\n AccountTrackerControllerEvents,\n} from './AccountTrackerController';\nexport { AccountTrackerController } from './AccountTrackerController';\nexport type {\n AssetsContractControllerActions,\n AssetsContractControllerEvents,\n AssetsContractControllerGetERC20StandardAction,\n AssetsContractControllerGetERC721StandardAction,\n AssetsContractControllerGetERC1155StandardAction,\n AssetsContractControllerGetERC20BalanceOfAction,\n AssetsContractControllerGetERC20TokenDecimalsAction,\n AssetsContractControllerGetERC20TokenNameAction,\n AssetsContractControllerGetERC721NftTokenIdAction,\n AssetsContractControllerGetERC721TokenURIAction,\n AssetsContractControllerGetERC721AssetNameAction,\n AssetsContractControllerGetERC721AssetSymbolAction,\n AssetsContractControllerGetERC721OwnerOfAction,\n AssetsContractControllerGetERC1155TokenURIAction,\n AssetsContractControllerGetERC1155BalanceOfAction,\n AssetsContractControllerTransferSingleERC1155Action,\n AssetsContractControllerGetTokenStandardAndDetailsAction,\n AssetsContractControllerGetBalancesInSingleCallAction,\n AssetsContractControllerMessenger,\n BalanceMap,\n} from './AssetsContractController';\nexport {\n SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID,\n AssetsContractController,\n} from './AssetsContractController';\nexport * from './CurrencyRateController';\nexport type {\n NftControllerState,\n NftControllerMessenger,\n NftControllerActions,\n NftControllerGetStateAction,\n NftControllerEvents,\n NftControllerStateChangeEvent,\n Nft,\n NftContract,\n NftMetadata,\n} from './NftController';\nexport { getDefaultNftControllerState, NftController } from './NftController';\nexport type {\n NftDetectionControllerMessenger,\n ApiNft,\n ApiNftContract,\n ApiNftLastSale,\n ApiNftCreator,\n ReservoirResponse,\n TokensResponse,\n BlockaidResultType,\n Blockaid,\n Market,\n TokenResponse,\n TopBid,\n LastSale,\n FeeBreakdown,\n Attributes,\n Collection,\n Royalties,\n Ownership,\n FloorAsk,\n Price,\n Metadata,\n} from './NftDetectionController';\nexport { NftDetectionController } from './NftDetectionController';\nexport type {\n TokenBalancesControllerMessenger,\n TokenBalancesControllerActions,\n TokenBalancesControllerGetStateAction,\n TokenBalancesControllerEvents,\n TokenBalancesControllerStateChangeEvent,\n TokenBalancesControllerState,\n} from './TokenBalancesController';\nexport { TokenBalancesController } from './TokenBalancesController';\nexport type {\n TokenDetectionControllerMessenger,\n TokenDetectionControllerActions,\n TokenDetectionControllerGetStateAction,\n TokenDetectionControllerEvents,\n TokenDetectionControllerStateChangeEvent,\n} from './TokenDetectionController';\nexport { TokenDetectionController } from './TokenDetectionController';\nexport type {\n TokenListState,\n TokenListToken,\n TokenListMap,\n TokenListStateChange,\n TokenListControllerEvents,\n GetTokenListState,\n TokenListControllerActions,\n TokenListControllerMessenger,\n} from './TokenListController';\nexport { TokenListController } from './TokenListController';\nexport type {\n ContractExchangeRates,\n ContractMarketData,\n Token,\n TokenRatesControllerActions,\n TokenRatesControllerEvents,\n TokenRatesControllerGetStateAction,\n TokenRatesControllerMessenger,\n TokenRatesControllerState,\n TokenRatesControllerStateChangeEvent,\n MarketDataDetails,\n} from './TokenRatesController';\nexport {\n getDefaultTokenRatesControllerState,\n TokenRatesController,\n} from './TokenRatesController';\nexport type {\n TokensControllerState,\n TokensControllerActions,\n TokensControllerGetStateAction,\n TokensControllerAddDetectedTokensAction,\n TokensControllerEvents,\n TokensControllerStateChangeEvent,\n TokensControllerMessenger,\n} from './TokensController';\nexport { TokensController } from './TokensController';\nexport {\n isTokenDetectionSupportedForNetwork,\n formatIconUrlWithProxy,\n getFormattedIpfsUrl,\n fetchTokenContractExchangeRates,\n getKeyByValue,\n} from './assetsUtil';\nexport {\n CodefiTokenPricesServiceV2,\n SUPPORTED_CHAIN_IDS,\n getNativeTokenAddress,\n} from './token-prices-service';\nexport { RatesController, Cryptocurrency } from './RatesController';\nexport type {\n RatesControllerState,\n RatesControllerEvents,\n RatesControllerActions,\n RatesControllerMessenger,\n RatesControllerGetStateAction,\n RatesControllerStateChangeEvent,\n RatesControllerPollingStartedEvent,\n RatesControllerPollingStoppedEvent,\n} from './RatesController';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n\nexport {\n MultichainAssetsController,\n getDefaultMultichainAssetsControllerState,\n} from './MultichainAssetsController';\n\nexport type {\n MultichainAssetsControllerState,\n MultichainAssetsControllerGetStateAction,\n MultichainAssetsControllerStateChangeEvent,\n MultichainAssetsControllerActions,\n MultichainAssetsControllerEvents,\n MultichainAssetsControllerMessenger,\n} from './MultichainAssetsController';\n\nexport {\n MultichainAssetsRatesController,\n getDefaultMultichainAssetsRatesControllerState,\n} from './MultichainAssetsRatesController';\n\nexport type {\n MultichainAssetsRatesControllerState,\n MultichainAssetsRatesControllerActions,\n MultichainAssetsRatesControllerEvents,\n MultichainAssetsRatesControllerGetStateAction,\n MultichainAssetsRatesControllerStateChange,\n MultichainAssetsRatesControllerMessenger,\n} from './MultichainAssetsRatesController';\nexport { TokenSearchDiscoveryDataController } from './TokenSearchDiscoveryDataController';\nexport type {\n TokenDisplayData,\n TokenSearchDiscoveryDataControllerState,\n TokenSearchDiscoveryDataControllerGetStateAction,\n TokenSearchDiscoveryDataControllerEvents,\n TokenSearchDiscoveryDataControllerStateChangeEvent,\n TokenSearchDiscoveryDataControllerActions,\n TokenSearchDiscoveryDataControllerMessenger,\n} from './TokenSearchDiscoveryDataController';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AASA,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AAuBjC,2EAGoC;AAFlC,mJAAA,uCAAuC,OAAA;AACvC,oIAAA,wBAAwB,OAAA;AAE1B,+DAAyC;AAYzC,qDAA8E;AAArE,6HAAA,4BAA4B,OAAA;AAAE,8GAAA,aAAa,OAAA;AAwBpD,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAS/B,yEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAQhC,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AAWjC,iEAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAa5B,mEAGgC;AAF9B,2IAAA,mCAAmC,OAAA;AACnC,4HAAA,oBAAoB,OAAA;AAWtB,2DAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,+CAMsB;AALpB,iIAAA,mCAAmC,OAAA;AACnC,oHAAA,sBAAsB,OAAA;AACtB,iHAAA,mBAAmB,OAAA;AACnB,6HAAA,+BAA+B,OAAA;AAC/B,2GAAA,aAAa,OAAA;AAEf,yEAIgC;AAH9B,kIAAA,0BAA0B,OAAA;AAC1B,2HAAA,mBAAmB,OAAA;AACnB,6HAAA,qBAAqB,OAAA;AAEvB,+DAAoE;AAA3D,kHAAA,eAAe,OAAA;AAAE,iHAAA,cAAc,OAAA;AAWxC,yFAA8E;AAArE,4IAAA,4BAA4B,OAAA;AAUrC,qFAGsC;AAFpC,wIAAA,0BAA0B,OAAA;AAC1B,uJAAA,yCAAyC,OAAA;AAY3C,+FAG2C;AAFzC,kJAAA,+BAA+B,OAAA;AAC/B,iKAAA,8CAA8C,OAAA;AAWhD,qGAA0F;AAAjF,wJAAA,kCAAkC,OAAA;AAU3C,iGAA4F;AAAnF,kIAAA,uBAAuB,OAAA","sourcesContent":["export type {\n AccountInformation,\n AccountTrackerControllerMessenger,\n AccountTrackerControllerState,\n AccountTrackerControllerActions,\n AccountTrackerControllerGetStateAction,\n AccountTrackerControllerStateChangeEvent,\n AccountTrackerControllerEvents,\n} from './AccountTrackerController';\nexport { AccountTrackerController } from './AccountTrackerController';\nexport type {\n AssetsContractControllerActions,\n AssetsContractControllerEvents,\n AssetsContractControllerGetERC20StandardAction,\n AssetsContractControllerGetERC721StandardAction,\n AssetsContractControllerGetERC1155StandardAction,\n AssetsContractControllerGetERC20BalanceOfAction,\n AssetsContractControllerGetERC20TokenDecimalsAction,\n AssetsContractControllerGetERC20TokenNameAction,\n AssetsContractControllerGetERC721NftTokenIdAction,\n AssetsContractControllerGetERC721TokenURIAction,\n AssetsContractControllerGetERC721AssetNameAction,\n AssetsContractControllerGetERC721AssetSymbolAction,\n AssetsContractControllerGetERC721OwnerOfAction,\n AssetsContractControllerGetERC1155TokenURIAction,\n AssetsContractControllerGetERC1155BalanceOfAction,\n AssetsContractControllerTransferSingleERC1155Action,\n AssetsContractControllerGetTokenStandardAndDetailsAction,\n AssetsContractControllerGetBalancesInSingleCallAction,\n AssetsContractControllerMessenger,\n BalanceMap,\n} from './AssetsContractController';\nexport {\n SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID,\n AssetsContractController,\n} from './AssetsContractController';\nexport * from './CurrencyRateController';\nexport type {\n NftControllerState,\n NftControllerMessenger,\n NftControllerActions,\n NftControllerGetStateAction,\n NftControllerEvents,\n NftControllerStateChangeEvent,\n Nft,\n NftContract,\n NftMetadata,\n} from './NftController';\nexport { getDefaultNftControllerState, NftController } from './NftController';\nexport type {\n NftDetectionControllerMessenger,\n ApiNft,\n ApiNftContract,\n ApiNftLastSale,\n ApiNftCreator,\n ReservoirResponse,\n TokensResponse,\n BlockaidResultType,\n Blockaid,\n Market,\n TokenResponse,\n TopBid,\n LastSale,\n FeeBreakdown,\n Attributes,\n Collection,\n Royalties,\n Ownership,\n FloorAsk,\n Price,\n Metadata,\n} from './NftDetectionController';\nexport { NftDetectionController } from './NftDetectionController';\nexport type {\n TokenBalancesControllerMessenger,\n TokenBalancesControllerActions,\n TokenBalancesControllerGetStateAction,\n TokenBalancesControllerEvents,\n TokenBalancesControllerStateChangeEvent,\n TokenBalancesControllerState,\n} from './TokenBalancesController';\nexport { TokenBalancesController } from './TokenBalancesController';\nexport type {\n TokenDetectionControllerMessenger,\n TokenDetectionControllerActions,\n TokenDetectionControllerGetStateAction,\n TokenDetectionControllerEvents,\n TokenDetectionControllerStateChangeEvent,\n} from './TokenDetectionController';\nexport { TokenDetectionController } from './TokenDetectionController';\nexport type {\n TokenListState,\n TokenListToken,\n TokenListMap,\n TokenListStateChange,\n TokenListControllerEvents,\n GetTokenListState,\n TokenListControllerActions,\n TokenListControllerMessenger,\n} from './TokenListController';\nexport { TokenListController } from './TokenListController';\nexport type {\n ContractExchangeRates,\n ContractMarketData,\n Token,\n TokenRatesControllerActions,\n TokenRatesControllerEvents,\n TokenRatesControllerGetStateAction,\n TokenRatesControllerMessenger,\n TokenRatesControllerState,\n TokenRatesControllerStateChangeEvent,\n MarketDataDetails,\n} from './TokenRatesController';\nexport {\n getDefaultTokenRatesControllerState,\n TokenRatesController,\n} from './TokenRatesController';\nexport type {\n TokensControllerState,\n TokensControllerActions,\n TokensControllerGetStateAction,\n TokensControllerAddDetectedTokensAction,\n TokensControllerEvents,\n TokensControllerStateChangeEvent,\n TokensControllerMessenger,\n} from './TokensController';\nexport { TokensController } from './TokensController';\nexport {\n isTokenDetectionSupportedForNetwork,\n formatIconUrlWithProxy,\n getFormattedIpfsUrl,\n fetchTokenContractExchangeRates,\n getKeyByValue,\n} from './assetsUtil';\nexport {\n CodefiTokenPricesServiceV2,\n SUPPORTED_CHAIN_IDS,\n getNativeTokenAddress,\n} from './token-prices-service';\nexport { RatesController, Cryptocurrency } from './RatesController';\nexport type {\n RatesControllerState,\n RatesControllerEvents,\n RatesControllerActions,\n RatesControllerMessenger,\n RatesControllerGetStateAction,\n RatesControllerStateChangeEvent,\n RatesControllerPollingStartedEvent,\n RatesControllerPollingStoppedEvent,\n} from './RatesController';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n\nexport {\n MultichainAssetsController,\n getDefaultMultichainAssetsControllerState,\n} from './MultichainAssetsController';\n\nexport type {\n MultichainAssetsControllerState,\n MultichainAssetsControllerGetStateAction,\n MultichainAssetsControllerStateChangeEvent,\n MultichainAssetsControllerActions,\n MultichainAssetsControllerEvents,\n MultichainAssetsControllerMessenger,\n} from './MultichainAssetsController';\n\nexport {\n MultichainAssetsRatesController,\n getDefaultMultichainAssetsRatesControllerState,\n} from './MultichainAssetsRatesController';\n\nexport type {\n MultichainAssetsRatesControllerState,\n MultichainAssetsRatesControllerActions,\n MultichainAssetsRatesControllerEvents,\n MultichainAssetsRatesControllerGetStateAction,\n MultichainAssetsRatesControllerStateChange,\n MultichainAssetsRatesControllerMessenger,\n} from './MultichainAssetsRatesController';\nexport { TokenSearchDiscoveryDataController } from './TokenSearchDiscoveryDataController';\nexport type {\n TokenDisplayData,\n TokenSearchDiscoveryDataControllerState,\n TokenSearchDiscoveryDataControllerGetStateAction,\n TokenSearchDiscoveryDataControllerEvents,\n TokenSearchDiscoveryDataControllerStateChangeEvent,\n TokenSearchDiscoveryDataControllerActions,\n TokenSearchDiscoveryDataControllerMessenger,\n} from './TokenSearchDiscoveryDataController';\nexport { DeFiPositionsController } from './DeFiPositionsController/DeFiPositionsController';\nexport type {\n DeFiPositionsControllerState,\n DeFiPositionsControllerActions,\n DeFiPositionsControllerEvents,\n DeFiPositionsControllerGetStateAction,\n DeFiPositionsControllerStateChangeEvent,\n DeFiPositionsControllerMessenger,\n} from './DeFiPositionsController/DeFiPositionsController';\nexport type { GroupedDeFiPositions } from './DeFiPositionsController/group-defi-positions';\n"]}
package/dist/index.d.cts CHANGED
@@ -29,4 +29,7 @@ export { MultichainAssetsRatesController, getDefaultMultichainAssetsRatesControl
29
29
  export type { MultichainAssetsRatesControllerState, MultichainAssetsRatesControllerActions, MultichainAssetsRatesControllerEvents, MultichainAssetsRatesControllerGetStateAction, MultichainAssetsRatesControllerStateChange, MultichainAssetsRatesControllerMessenger, } from "./MultichainAssetsRatesController/index.cjs";
30
30
  export { TokenSearchDiscoveryDataController } from "./TokenSearchDiscoveryDataController/index.cjs";
31
31
  export type { TokenDisplayData, TokenSearchDiscoveryDataControllerState, TokenSearchDiscoveryDataControllerGetStateAction, TokenSearchDiscoveryDataControllerEvents, TokenSearchDiscoveryDataControllerStateChangeEvent, TokenSearchDiscoveryDataControllerActions, TokenSearchDiscoveryDataControllerMessenger, } from "./TokenSearchDiscoveryDataController/index.cjs";
32
+ export { DeFiPositionsController } from "./DeFiPositionsController/DeFiPositionsController.cjs";
33
+ export type { DeFiPositionsControllerState, DeFiPositionsControllerActions, DeFiPositionsControllerEvents, DeFiPositionsControllerGetStateAction, DeFiPositionsControllerStateChangeEvent, DeFiPositionsControllerMessenger, } from "./DeFiPositionsController/DeFiPositionsController.cjs";
34
+ export type { GroupedDeFiPositions } from "./DeFiPositionsController/group-defi-positions.cjs";
32
35
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iCAAiC,EACjC,6BAA6B,EAC7B,+BAA+B,EAC/B,sCAAsC,EACtC,wCAAwC,EACxC,8BAA8B,GAC/B,uCAAmC;AACpC,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,8CAA8C,EAC9C,+CAA+C,EAC/C,gDAAgD,EAChD,+CAA+C,EAC/C,mDAAmD,EACnD,+CAA+C,EAC/C,iDAAiD,EACjD,+CAA+C,EAC/C,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EAC9C,gDAAgD,EAChD,iDAAiD,EACjD,mDAAmD,EACnD,wDAAwD,EACxD,qDAAqD,EACrD,iCAAiC,EACjC,UAAU,GACX,uCAAmC;AACpC,OAAO,EACL,uCAAuC,EACvC,wBAAwB,GACzB,uCAAmC;AACpC,6CAAyC;AACzC,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,6BAA6B,EAC7B,GAAG,EACH,WAAW,EACX,WAAW,GACZ,4BAAwB;AACzB,OAAO,EAAE,4BAA4B,EAAE,aA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AEtC,OAAO,EACL,+BAA+B,EAC/B,8CAA8C,GAC/C,oDAA0C;AAE3C,YAAY,EACV,oCAAoC,EACpC,sCAAsC,EACtC,qCAAqC,EACrC,6CAA6C,EAC7C,0CAA0C,EAC1C,wCAAwC,GACzC,oDAA0C;AAC3C,OAAO,EAAE,kCAAkC,EAAE,uDAA6C;AAC1F,YAAY,EACV,gBAAgB,EAChB,uCAAuC,EACvC,gDAAgD,EAChD,wCAAwC,EACxC,kDAAkD,EAClD,yCAAyC,EACzC,2CAA2C,GAC5C,uDAA6C;AAC9C,OAAO,EAAE,uBAAuB,EAAE,8DAA0D;AAC5F,YAAY,EACV,4BAA4B,EAC5B,8BAA8B,EAC9B,6BAA6B,EAC7B,qCAAqC,EACrC,uCAAuC,EACvC,gCAAgC,GACjC,8DAA0D;AAC3D,YAAY,EAAE,oBAAoB,EAAE,2DAAuD"}
package/dist/index.d.mts CHANGED
@@ -29,4 +29,7 @@ export { MultichainAssetsRatesController, getDefaultMultichainAssetsRatesControl
29
29
  export type { MultichainAssetsRatesControllerState, MultichainAssetsRatesControllerActions, MultichainAssetsRatesControllerEvents, MultichainAssetsRatesControllerGetStateAction, MultichainAssetsRatesControllerStateChange, MultichainAssetsRatesControllerMessenger, } from "./MultichainAssetsRatesController/index.mjs";
30
30
  export { TokenSearchDiscoveryDataController } from "./TokenSearchDiscoveryDataController/index.mjs";
31
31
  export type { TokenDisplayData, TokenSearchDiscoveryDataControllerState, TokenSearchDiscoveryDataControllerGetStateAction, TokenSearchDiscoveryDataControllerEvents, TokenSearchDiscoveryDataControllerStateChangeEvent, TokenSearchDiscoveryDataControllerActions, TokenSearchDiscoveryDataControllerMessenger, } from "./TokenSearchDiscoveryDataController/index.mjs";
32
+ export { DeFiPositionsController } from "./DeFiPositionsController/DeFiPositionsController.mjs";
33
+ export type { DeFiPositionsControllerState, DeFiPositionsControllerActions, DeFiPositionsControllerEvents, DeFiPositionsControllerGetStateAction, DeFiPositionsControllerStateChangeEvent, DeFiPositionsControllerMessenger, } from "./DeFiPositionsController/DeFiPositionsController.mjs";
34
+ export type { GroupedDeFiPositions } from "./DeFiPositionsController/group-defi-positions.mjs";
32
35
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iCAAiC,EACjC,6BAA6B,EAC7B,+BAA+B,EAC/B,sCAAsC,EACtC,wCAAwC,EACxC,8BAA8B,GAC/B,uCAAmC;AACpC,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,8CAA8C,EAC9C,+CAA+C,EAC/C,gDAAgD,EAChD,+CAA+C,EAC/C,mDAAmD,EACnD,+CAA+C,EAC/C,iDAAiD,EACjD,+CAA+C,EAC/C,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EAC9C,gDAAgD,EAChD,iDAAiD,EACjD,mDAAmD,EACnD,wDAAwD,EACxD,qDAAqD,EACrD,iCAAiC,EACjC,UAAU,GACX,uCAAmC;AACpC,OAAO,EACL,uCAAuC,EACvC,wBAAwB,GACzB,uCAAmC;AACpC,6CAAyC;AACzC,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,6BAA6B,EAC7B,GAAG,EACH,WAAW,EACX,WAAW,GACZ,4BAAwB;AACzB,OAAO,EAAE,4BAA4B,EAAE,aAAa,EAAE,4BAAwB;AAC9E,YAAY,EACV,+BAA+B,EAC/B,MAAM,EACN,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,MAAM,EACN,aAAa,EACb,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,KAAK,EACL,QAAQ,GAC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AwC,EACxC,kDAAkD,EAClD,yCAAyC,EACzC,2CAA2C,GAC5C,uDAA6C;AAC9C,OAAO,EAAE,uBAAuB,EAAE,8DAA0D;AAC5F,YAAY,EACV,4BAA4B,EAC5B,8BAA8B,EAC9B,6BAA6B,EAC7B,qCAAqC,EACrC,uCAAuC,EACvC,gCAAgC,GACjC,8DAA0D;AAC3D,YAAY,EAAE,oBAAoB,EAAE,2DAAuD"}
package/dist/index.mjs CHANGED
@@ -15,4 +15,5 @@ export { MultichainBalancesController } from "./MultichainBalancesController/ind
15
15
  export { MultichainAssetsController, getDefaultMultichainAssetsControllerState } from "./MultichainAssetsController/index.mjs";
16
16
  export { MultichainAssetsRatesController, getDefaultMultichainAssetsRatesControllerState } from "./MultichainAssetsRatesController/index.mjs";
17
17
  export { TokenSearchDiscoveryDataController } from "./TokenSearchDiscoveryDataController/index.mjs";
18
+ export { DeFiPositionsController } from "./DeFiPositionsController/DeFiPositionsController.mjs";
18
19
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AAuBtE,OAAO,EACL,uCAAuC,EACvC,wBAAwB,EACzB,uCAAmC;AACpC,6CAAyC;AAYzC,OAAO,EAAE,4BAA4B,EAAE,aAAa,EAAE,4BAAwB;AAwB9E,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AASlE,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AAQpE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AAWtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAa5D,OAAO,EACL,mCAAmC,EACnC,oBAAoB,EACrB,mCAA+B;AAUhC,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,OAAO,EACL,mCAAmC,EACnC,sBAAsB,EACtB,mBAAmB,EACnB,+BAA+B,EAC/B,aAAa,EACd,yBAAqB;AACtB,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,EACtB,yCAA+B;AAChC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,oCAA0B;AAWpE,OAAO,EAAE,4BAA4B,EAAE,iDAAuC;AAU9E,OAAO,EACL,0BAA0B,EAC1B,yCAAyC,EAC1C,+CAAqC;AAWtC,OAAO,EACL,+BAA+B,EAC/B,8CAA8C,EAC/C,oDAA0C;AAU3C,OAAO,EAAE,kCAAkC,EAAE,uDAA6C","sourcesContent":["export type {\n AccountInformation,\n AccountTrackerControllerMessenger,\n AccountTrackerControllerState,\n AccountTrackerControllerActions,\n AccountTrackerControllerGetStateAction,\n AccountTrackerControllerStateChangeEvent,\n AccountTrackerControllerEvents,\n} from './AccountTrackerController';\nexport { AccountTrackerController } from './AccountTrackerController';\nexport type {\n AssetsContractControllerActions,\n AssetsContractControllerEvents,\n AssetsContractControllerGetERC20StandardAction,\n AssetsContractControllerGetERC721StandardAction,\n AssetsContractControllerGetERC1155StandardAction,\n AssetsContractControllerGetERC20BalanceOfAction,\n AssetsContractControllerGetERC20TokenDecimalsAction,\n AssetsContractControllerGetERC20TokenNameAction,\n AssetsContractControllerGetERC721NftTokenIdAction,\n AssetsContractControllerGetERC721TokenURIAction,\n AssetsContractControllerGetERC721AssetNameAction,\n AssetsContractControllerGetERC721AssetSymbolAction,\n AssetsContractControllerGetERC721OwnerOfAction,\n AssetsContractControllerGetERC1155TokenURIAction,\n AssetsContractControllerGetERC1155BalanceOfAction,\n AssetsContractControllerTransferSingleERC1155Action,\n AssetsContractControllerGetTokenStandardAndDetailsAction,\n AssetsContractControllerGetBalancesInSingleCallAction,\n AssetsContractControllerMessenger,\n BalanceMap,\n} from './AssetsContractController';\nexport {\n SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID,\n AssetsContractController,\n} from './AssetsContractController';\nexport * from './CurrencyRateController';\nexport type {\n NftControllerState,\n NftControllerMessenger,\n NftControllerActions,\n NftControllerGetStateAction,\n NftControllerEvents,\n NftControllerStateChangeEvent,\n Nft,\n NftContract,\n NftMetadata,\n} from './NftController';\nexport { getDefaultNftControllerState, NftController } from './NftController';\nexport type {\n NftDetectionControllerMessenger,\n ApiNft,\n ApiNftContract,\n ApiNftLastSale,\n ApiNftCreator,\n ReservoirResponse,\n TokensResponse,\n BlockaidResultType,\n Blockaid,\n Market,\n TokenResponse,\n TopBid,\n LastSale,\n FeeBreakdown,\n Attributes,\n Collection,\n Royalties,\n Ownership,\n FloorAsk,\n Price,\n Metadata,\n} from './NftDetectionController';\nexport { NftDetectionController } from './NftDetectionController';\nexport type {\n TokenBalancesControllerMessenger,\n TokenBalancesControllerActions,\n TokenBalancesControllerGetStateAction,\n TokenBalancesControllerEvents,\n TokenBalancesControllerStateChangeEvent,\n TokenBalancesControllerState,\n} from './TokenBalancesController';\nexport { TokenBalancesController } from './TokenBalancesController';\nexport type {\n TokenDetectionControllerMessenger,\n TokenDetectionControllerActions,\n TokenDetectionControllerGetStateAction,\n TokenDetectionControllerEvents,\n TokenDetectionControllerStateChangeEvent,\n} from './TokenDetectionController';\nexport { TokenDetectionController } from './TokenDetectionController';\nexport type {\n TokenListState,\n TokenListToken,\n TokenListMap,\n TokenListStateChange,\n TokenListControllerEvents,\n GetTokenListState,\n TokenListControllerActions,\n TokenListControllerMessenger,\n} from './TokenListController';\nexport { TokenListController } from './TokenListController';\nexport type {\n ContractExchangeRates,\n ContractMarketData,\n Token,\n TokenRatesControllerActions,\n TokenRatesControllerEvents,\n TokenRatesControllerGetStateAction,\n TokenRatesControllerMessenger,\n TokenRatesControllerState,\n TokenRatesControllerStateChangeEvent,\n MarketDataDetails,\n} from './TokenRatesController';\nexport {\n getDefaultTokenRatesControllerState,\n TokenRatesController,\n} from './TokenRatesController';\nexport type {\n TokensControllerState,\n TokensControllerActions,\n TokensControllerGetStateAction,\n TokensControllerAddDetectedTokensAction,\n TokensControllerEvents,\n TokensControllerStateChangeEvent,\n TokensControllerMessenger,\n} from './TokensController';\nexport { TokensController } from './TokensController';\nexport {\n isTokenDetectionSupportedForNetwork,\n formatIconUrlWithProxy,\n getFormattedIpfsUrl,\n fetchTokenContractExchangeRates,\n getKeyByValue,\n} from './assetsUtil';\nexport {\n CodefiTokenPricesServiceV2,\n SUPPORTED_CHAIN_IDS,\n getNativeTokenAddress,\n} from './token-prices-service';\nexport { RatesController, Cryptocurrency } from './RatesController';\nexport type {\n RatesControllerState,\n RatesControllerEvents,\n RatesControllerActions,\n RatesControllerMessenger,\n RatesControllerGetStateAction,\n RatesControllerStateChangeEvent,\n RatesControllerPollingStartedEvent,\n RatesControllerPollingStoppedEvent,\n} from './RatesController';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n\nexport {\n MultichainAssetsController,\n getDefaultMultichainAssetsControllerState,\n} from './MultichainAssetsController';\n\nexport type {\n MultichainAssetsControllerState,\n MultichainAssetsControllerGetStateAction,\n MultichainAssetsControllerStateChangeEvent,\n MultichainAssetsControllerActions,\n MultichainAssetsControllerEvents,\n MultichainAssetsControllerMessenger,\n} from './MultichainAssetsController';\n\nexport {\n MultichainAssetsRatesController,\n getDefaultMultichainAssetsRatesControllerState,\n} from './MultichainAssetsRatesController';\n\nexport type {\n MultichainAssetsRatesControllerState,\n MultichainAssetsRatesControllerActions,\n MultichainAssetsRatesControllerEvents,\n MultichainAssetsRatesControllerGetStateAction,\n MultichainAssetsRatesControllerStateChange,\n MultichainAssetsRatesControllerMessenger,\n} from './MultichainAssetsRatesController';\nexport { TokenSearchDiscoveryDataController } from './TokenSearchDiscoveryDataController';\nexport type {\n TokenDisplayData,\n TokenSearchDiscoveryDataControllerState,\n TokenSearchDiscoveryDataControllerGetStateAction,\n TokenSearchDiscoveryDataControllerEvents,\n TokenSearchDiscoveryDataControllerStateChangeEvent,\n TokenSearchDiscoveryDataControllerActions,\n TokenSearchDiscoveryDataControllerMessenger,\n} from './TokenSearchDiscoveryDataController';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AAuBtE,OAAO,EACL,uCAAuC,EACvC,wBAAwB,EACzB,uCAAmC;AACpC,6CAAyC;AAYzC,OAAO,EAAE,4BAA4B,EAAE,aAAa,EAAE,4BAAwB;AAwB9E,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AASlE,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AAQpE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AAWtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAa5D,OAAO,EACL,mCAAmC,EACnC,oBAAoB,EACrB,mCAA+B;AAUhC,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,OAAO,EACL,mCAAmC,EACnC,sBAAsB,EACtB,mBAAmB,EACnB,+BAA+B,EAC/B,aAAa,EACd,yBAAqB;AACtB,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,EACtB,yCAA+B;AAChC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,oCAA0B;AAWpE,OAAO,EAAE,4BAA4B,EAAE,iDAAuC;AAU9E,OAAO,EACL,0BAA0B,EAC1B,yCAAyC,EAC1C,+CAAqC;AAWtC,OAAO,EACL,+BAA+B,EAC/B,8CAA8C,EAC/C,oDAA0C;AAU3C,OAAO,EAAE,kCAAkC,EAAE,uDAA6C;AAU1F,OAAO,EAAE,uBAAuB,EAAE,8DAA0D","sourcesContent":["export type {\n AccountInformation,\n AccountTrackerControllerMessenger,\n AccountTrackerControllerState,\n AccountTrackerControllerActions,\n AccountTrackerControllerGetStateAction,\n AccountTrackerControllerStateChangeEvent,\n AccountTrackerControllerEvents,\n} from './AccountTrackerController';\nexport { AccountTrackerController } from './AccountTrackerController';\nexport type {\n AssetsContractControllerActions,\n AssetsContractControllerEvents,\n AssetsContractControllerGetERC20StandardAction,\n AssetsContractControllerGetERC721StandardAction,\n AssetsContractControllerGetERC1155StandardAction,\n AssetsContractControllerGetERC20BalanceOfAction,\n AssetsContractControllerGetERC20TokenDecimalsAction,\n AssetsContractControllerGetERC20TokenNameAction,\n AssetsContractControllerGetERC721NftTokenIdAction,\n AssetsContractControllerGetERC721TokenURIAction,\n AssetsContractControllerGetERC721AssetNameAction,\n AssetsContractControllerGetERC721AssetSymbolAction,\n AssetsContractControllerGetERC721OwnerOfAction,\n AssetsContractControllerGetERC1155TokenURIAction,\n AssetsContractControllerGetERC1155BalanceOfAction,\n AssetsContractControllerTransferSingleERC1155Action,\n AssetsContractControllerGetTokenStandardAndDetailsAction,\n AssetsContractControllerGetBalancesInSingleCallAction,\n AssetsContractControllerMessenger,\n BalanceMap,\n} from './AssetsContractController';\nexport {\n SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID,\n AssetsContractController,\n} from './AssetsContractController';\nexport * from './CurrencyRateController';\nexport type {\n NftControllerState,\n NftControllerMessenger,\n NftControllerActions,\n NftControllerGetStateAction,\n NftControllerEvents,\n NftControllerStateChangeEvent,\n Nft,\n NftContract,\n NftMetadata,\n} from './NftController';\nexport { getDefaultNftControllerState, NftController } from './NftController';\nexport type {\n NftDetectionControllerMessenger,\n ApiNft,\n ApiNftContract,\n ApiNftLastSale,\n ApiNftCreator,\n ReservoirResponse,\n TokensResponse,\n BlockaidResultType,\n Blockaid,\n Market,\n TokenResponse,\n TopBid,\n LastSale,\n FeeBreakdown,\n Attributes,\n Collection,\n Royalties,\n Ownership,\n FloorAsk,\n Price,\n Metadata,\n} from './NftDetectionController';\nexport { NftDetectionController } from './NftDetectionController';\nexport type {\n TokenBalancesControllerMessenger,\n TokenBalancesControllerActions,\n TokenBalancesControllerGetStateAction,\n TokenBalancesControllerEvents,\n TokenBalancesControllerStateChangeEvent,\n TokenBalancesControllerState,\n} from './TokenBalancesController';\nexport { TokenBalancesController } from './TokenBalancesController';\nexport type {\n TokenDetectionControllerMessenger,\n TokenDetectionControllerActions,\n TokenDetectionControllerGetStateAction,\n TokenDetectionControllerEvents,\n TokenDetectionControllerStateChangeEvent,\n} from './TokenDetectionController';\nexport { TokenDetectionController } from './TokenDetectionController';\nexport type {\n TokenListState,\n TokenListToken,\n TokenListMap,\n TokenListStateChange,\n TokenListControllerEvents,\n GetTokenListState,\n TokenListControllerActions,\n TokenListControllerMessenger,\n} from './TokenListController';\nexport { TokenListController } from './TokenListController';\nexport type {\n ContractExchangeRates,\n ContractMarketData,\n Token,\n TokenRatesControllerActions,\n TokenRatesControllerEvents,\n TokenRatesControllerGetStateAction,\n TokenRatesControllerMessenger,\n TokenRatesControllerState,\n TokenRatesControllerStateChangeEvent,\n MarketDataDetails,\n} from './TokenRatesController';\nexport {\n getDefaultTokenRatesControllerState,\n TokenRatesController,\n} from './TokenRatesController';\nexport type {\n TokensControllerState,\n TokensControllerActions,\n TokensControllerGetStateAction,\n TokensControllerAddDetectedTokensAction,\n TokensControllerEvents,\n TokensControllerStateChangeEvent,\n TokensControllerMessenger,\n} from './TokensController';\nexport { TokensController } from './TokensController';\nexport {\n isTokenDetectionSupportedForNetwork,\n formatIconUrlWithProxy,\n getFormattedIpfsUrl,\n fetchTokenContractExchangeRates,\n getKeyByValue,\n} from './assetsUtil';\nexport {\n CodefiTokenPricesServiceV2,\n SUPPORTED_CHAIN_IDS,\n getNativeTokenAddress,\n} from './token-prices-service';\nexport { RatesController, Cryptocurrency } from './RatesController';\nexport type {\n RatesControllerState,\n RatesControllerEvents,\n RatesControllerActions,\n RatesControllerMessenger,\n RatesControllerGetStateAction,\n RatesControllerStateChangeEvent,\n RatesControllerPollingStartedEvent,\n RatesControllerPollingStoppedEvent,\n} from './RatesController';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n\nexport {\n MultichainAssetsController,\n getDefaultMultichainAssetsControllerState,\n} from './MultichainAssetsController';\n\nexport type {\n MultichainAssetsControllerState,\n MultichainAssetsControllerGetStateAction,\n MultichainAssetsControllerStateChangeEvent,\n MultichainAssetsControllerActions,\n MultichainAssetsControllerEvents,\n MultichainAssetsControllerMessenger,\n} from './MultichainAssetsController';\n\nexport {\n MultichainAssetsRatesController,\n getDefaultMultichainAssetsRatesControllerState,\n} from './MultichainAssetsRatesController';\n\nexport type {\n MultichainAssetsRatesControllerState,\n MultichainAssetsRatesControllerActions,\n MultichainAssetsRatesControllerEvents,\n MultichainAssetsRatesControllerGetStateAction,\n MultichainAssetsRatesControllerStateChange,\n MultichainAssetsRatesControllerMessenger,\n} from './MultichainAssetsRatesController';\nexport { TokenSearchDiscoveryDataController } from './TokenSearchDiscoveryDataController';\nexport type {\n TokenDisplayData,\n TokenSearchDiscoveryDataControllerState,\n TokenSearchDiscoveryDataControllerGetStateAction,\n TokenSearchDiscoveryDataControllerEvents,\n TokenSearchDiscoveryDataControllerStateChangeEvent,\n TokenSearchDiscoveryDataControllerActions,\n TokenSearchDiscoveryDataControllerMessenger,\n} from './TokenSearchDiscoveryDataController';\nexport { DeFiPositionsController } from './DeFiPositionsController/DeFiPositionsController';\nexport type {\n DeFiPositionsControllerState,\n DeFiPositionsControllerActions,\n DeFiPositionsControllerEvents,\n DeFiPositionsControllerGetStateAction,\n DeFiPositionsControllerStateChangeEvent,\n DeFiPositionsControllerMessenger,\n} from './DeFiPositionsController/DeFiPositionsController';\nexport type { GroupedDeFiPositions } from './DeFiPositionsController/group-defi-positions';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/assets-controllers",
3
- "version": "56.0.0",
3
+ "version": "57.0.0",
4
4
  "description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -81,7 +81,7 @@
81
81
  "@metamask/approval-controller": "^7.1.3",
82
82
  "@metamask/auto-changelog": "^3.4.4",
83
83
  "@metamask/ethjs-provider-http": "^0.3.0",
84
- "@metamask/keyring-controller": "^21.0.1",
84
+ "@metamask/keyring-controller": "^21.0.3",
85
85
  "@metamask/keyring-internal-api": "^6.0.1",
86
86
  "@metamask/keyring-snap-client": "^4.1.0",
87
87
  "@metamask/network-controller": "^23.2.0",
@@ -90,6 +90,7 @@
90
90
  "@metamask/providers": "^18.1.1",
91
91
  "@metamask/snaps-controllers": "^9.19.0",
92
92
  "@metamask/snaps-sdk": "^6.17.1",
93
+ "@metamask/transaction-controller": "^54.1.0",
93
94
  "@types/jest": "^27.4.1",
94
95
  "@types/lodash": "^4.14.191",
95
96
  "@types/node": "^16.18.54",
@@ -113,6 +114,7 @@
113
114
  "@metamask/preferences-controller": "^17.0.0",
114
115
  "@metamask/providers": "^18.1.0",
115
116
  "@metamask/snaps-controllers": "^9.19.0",
117
+ "@metamask/transaction-controller": "^54.0.0",
116
118
  "webextension-polyfill": "^0.10.0 || ^0.11.0 || ^0.12.0"
117
119
  },
118
120
  "engines": {