@metamask-previews/assets-controllers 45.1.0-preview-a0b32c13 → 45.1.1-preview-9e30e90a

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 (74) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/AccountTrackerController.d.cts +4 -4
  3. package/dist/AccountTrackerController.d.mts +4 -4
  4. package/dist/CurrencyRateController.d.cts +4 -4
  5. package/dist/CurrencyRateController.d.mts +4 -4
  6. package/dist/MultichainBalancesController/BalancesTracker.cjs +117 -0
  7. package/dist/MultichainBalancesController/BalancesTracker.cjs.map +1 -0
  8. package/dist/MultichainBalancesController/BalancesTracker.d.cts +54 -0
  9. package/dist/MultichainBalancesController/BalancesTracker.d.cts.map +1 -0
  10. package/dist/MultichainBalancesController/BalancesTracker.d.mts +54 -0
  11. package/dist/MultichainBalancesController/BalancesTracker.d.mts.map +1 -0
  12. package/dist/MultichainBalancesController/BalancesTracker.mjs +113 -0
  13. package/dist/MultichainBalancesController/BalancesTracker.mjs.map +1 -0
  14. package/dist/MultichainBalancesController/MultichainBalancesController.cjs +203 -0
  15. package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +1 -0
  16. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts +89 -0
  17. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +1 -0
  18. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts +89 -0
  19. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +1 -0
  20. package/dist/MultichainBalancesController/MultichainBalancesController.mjs +201 -0
  21. package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +1 -0
  22. package/dist/MultichainBalancesController/Poller.cjs +44 -0
  23. package/dist/MultichainBalancesController/Poller.cjs.map +1 -0
  24. package/dist/MultichainBalancesController/Poller.d.cts +7 -0
  25. package/dist/MultichainBalancesController/Poller.d.cts.map +1 -0
  26. package/dist/MultichainBalancesController/Poller.d.mts +7 -0
  27. package/dist/MultichainBalancesController/Poller.d.mts.map +1 -0
  28. package/dist/MultichainBalancesController/Poller.mjs +40 -0
  29. package/dist/MultichainBalancesController/Poller.mjs.map +1 -0
  30. package/dist/MultichainBalancesController/constants.cjs +45 -0
  31. package/dist/MultichainBalancesController/constants.cjs.map +1 -0
  32. package/dist/MultichainBalancesController/constants.d.cts +29 -0
  33. package/dist/MultichainBalancesController/constants.d.cts.map +1 -0
  34. package/dist/MultichainBalancesController/constants.d.mts +29 -0
  35. package/dist/MultichainBalancesController/constants.d.mts.map +1 -0
  36. package/dist/MultichainBalancesController/constants.mjs +43 -0
  37. package/dist/MultichainBalancesController/constants.mjs.map +1 -0
  38. package/dist/MultichainBalancesController/index.cjs +13 -0
  39. package/dist/MultichainBalancesController/index.cjs.map +1 -0
  40. package/dist/MultichainBalancesController/index.d.cts +5 -0
  41. package/dist/MultichainBalancesController/index.d.cts.map +1 -0
  42. package/dist/MultichainBalancesController/index.d.mts +5 -0
  43. package/dist/MultichainBalancesController/index.d.mts.map +1 -0
  44. package/dist/MultichainBalancesController/index.mjs +4 -0
  45. package/dist/MultichainBalancesController/index.mjs.map +1 -0
  46. package/dist/MultichainBalancesController/utils.cjs +60 -0
  47. package/dist/MultichainBalancesController/utils.cjs.map +1 -0
  48. package/dist/MultichainBalancesController/utils.d.cts +29 -0
  49. package/dist/MultichainBalancesController/utils.d.cts.map +1 -0
  50. package/dist/MultichainBalancesController/utils.d.mts +29 -0
  51. package/dist/MultichainBalancesController/utils.d.mts.map +1 -0
  52. package/dist/MultichainBalancesController/utils.mjs +55 -0
  53. package/dist/MultichainBalancesController/utils.mjs.map +1 -0
  54. package/dist/Standards/ERC20Standard.mjs +2 -4
  55. package/dist/Standards/ERC20Standard.mjs.map +1 -1
  56. package/dist/TokenBalancesController.d.cts +4 -4
  57. package/dist/TokenBalancesController.d.mts +4 -4
  58. package/dist/TokenDetectionController.d.cts +4 -4
  59. package/dist/TokenDetectionController.d.mts +4 -4
  60. package/dist/TokenListController.d.cts +4 -4
  61. package/dist/TokenListController.d.mts +4 -4
  62. package/dist/TokenRatesController.d.cts +4 -4
  63. package/dist/TokenRatesController.d.mts +4 -4
  64. package/dist/index.cjs +9 -1
  65. package/dist/index.cjs.map +1 -1
  66. package/dist/index.d.cts +2 -0
  67. package/dist/index.d.cts.map +1 -1
  68. package/dist/index.d.mts +2 -0
  69. package/dist/index.d.mts.map +1 -1
  70. package/dist/index.mjs +3 -0
  71. package/dist/index.mjs.map +1 -1
  72. package/dist/token-prices-service/codefi-v2.mjs +1 -2
  73. package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
  74. package/package.json +18 -9
package/CHANGELOG.md CHANGED
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [45.1.1]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/controller-utils` from `^11.3.0` to `^11.4.4` ([#5012](https://github.com/MetaMask/core/pull/5012))
15
+ - Bump `@metamask/polling-controller` from `^12.0.1` to `^12.0.2` ([#5012](https://github.com/MetaMask/core/pull/5012))
16
+
17
+ ### Fixed
18
+
19
+ - Make implicit peer dependencies explicit ([#4974](https://github.com/MetaMask/core/pull/4974))
20
+ - Add the following packages as peer dependencies of this package to satisfy peer dependency requirements from other dependencies:
21
+ - `@metamask/providers` `^18.1.0` (required by `@metamask/keyring-api`)
22
+ - `webextension-polyfill` `^0.10.0 || ^0.11.0 || ^0.12.0` (required by `@metamask/providers`)
23
+ - These dependencies really should be present in projects that consume this package (e.g. MetaMask clients), and this change ensures that they now are.
24
+ - Furthermore, we are assuming that clients already use these dependencies, since otherwise it would be impossible to consume this package in its entirety or even create a working build. Hence, the addition of these peer dependencies is really a formality and should not be breaking.
25
+ - Fix `TokensController.ignoreTokens` so that if a network is provided, `allIgnoredTokens`, `allTokens`, and `allDetectedTokens` for that network no longer get corrupted with tokens from the globally selected network ([#4967](https://github.com/MetaMask/core/pull/4967))
26
+ - Correct ESM-compatible build so that imports of the following packages that re-export other modules via `export *` are no longer corrupted: ([#5011](https://github.com/MetaMask/core/pull/5011))
27
+ - `@metamask/abi-utils`
28
+ - `@metamask/contract-metadata`
29
+ - `@metamask/eth-query`
30
+ - `@ethereumjs/util`
31
+ - `bn.js`
32
+ - `cockatiel`
33
+ - `lodash`
34
+ - `single-call-balance-checker-abi`
35
+
10
36
  ## [45.1.0]
11
37
 
12
38
  ### Added
@@ -1265,7 +1291,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1265
1291
 
1266
1292
  - Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
1267
1293
 
1268
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@45.1.0...HEAD
1294
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@45.1.1...HEAD
1295
+ [45.1.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@45.1.0...@metamask/assets-controllers@45.1.1
1269
1296
  [45.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@45.0.0...@metamask/assets-controllers@45.1.0
1270
1297
  [45.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@44.1.0...@metamask/assets-controllers@45.0.0
1271
1298
  [44.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@44.0.1...@metamask/assets-controllers@44.1.0
@@ -65,14 +65,14 @@ type AccountTrackerPollingInput = {
65
65
  networkClientId: NetworkClientId;
66
66
  };
67
67
  declare const AccountTrackerController_base: (abstract new (...args: any[]) => {
68
- readonly "__#787811@#intervalIds": Record<string, NodeJS.Timeout>;
69
- "__#787811@#intervalLength": number | undefined;
68
+ readonly "__#11@#intervalIds": Record<string, NodeJS.Timeout>;
69
+ "__#11@#intervalLength": number | undefined;
70
70
  setIntervalLength(intervalLength: number): void;
71
71
  getIntervalLength(): number | undefined;
72
72
  _startPolling(input: AccountTrackerPollingInput): void;
73
73
  _stopPollingByPollingTokenSetId(key: string): void;
74
- readonly "__#787803@#pollingTokenSets": Map<string, Set<string>>;
75
- "__#787803@#callbacks": Map<string, Set<(input: AccountTrackerPollingInput) => void>>;
74
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
75
+ "__#3@#callbacks": Map<string, Set<(input: AccountTrackerPollingInput) => void>>;
76
76
  _executePoll(input: AccountTrackerPollingInput): Promise<void>;
77
77
  startPolling(input: AccountTrackerPollingInput): string;
78
78
  stopAllPolling(): void;
@@ -65,14 +65,14 @@ type AccountTrackerPollingInput = {
65
65
  networkClientId: NetworkClientId;
66
66
  };
67
67
  declare const AccountTrackerController_base: (abstract new (...args: any[]) => {
68
- readonly "__#787811@#intervalIds": Record<string, NodeJS.Timeout>;
69
- "__#787811@#intervalLength": number | undefined;
68
+ readonly "__#11@#intervalIds": Record<string, NodeJS.Timeout>;
69
+ "__#11@#intervalLength": number | undefined;
70
70
  setIntervalLength(intervalLength: number): void;
71
71
  getIntervalLength(): number | undefined;
72
72
  _startPolling(input: AccountTrackerPollingInput): void;
73
73
  _stopPollingByPollingTokenSetId(key: string): void;
74
- readonly "__#787803@#pollingTokenSets": Map<string, Set<string>>;
75
- "__#787803@#callbacks": Map<string, Set<(input: AccountTrackerPollingInput) => void>>;
74
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
75
+ "__#3@#callbacks": Map<string, Set<(input: AccountTrackerPollingInput) => void>>;
76
76
  _executePoll(input: AccountTrackerPollingInput): Promise<void>;
77
77
  startPolling(input: AccountTrackerPollingInput): string;
78
78
  stopAllPolling(): void;
@@ -29,14 +29,14 @@ type CurrencyRatePollingInput = {
29
29
  nativeCurrencies: string[];
30
30
  };
31
31
  declare const CurrencyRateController_base: (abstract new (...args: any[]) => {
32
- readonly "__#787811@#intervalIds": Record<string, NodeJS.Timeout>;
33
- "__#787811@#intervalLength": number | undefined;
32
+ readonly "__#11@#intervalIds": Record<string, NodeJS.Timeout>;
33
+ "__#11@#intervalLength": number | undefined;
34
34
  setIntervalLength(intervalLength: number): void;
35
35
  getIntervalLength(): number | undefined;
36
36
  _startPolling(input: CurrencyRatePollingInput): void;
37
37
  _stopPollingByPollingTokenSetId(key: string): void;
38
- readonly "__#787803@#pollingTokenSets": Map<string, Set<string>>;
39
- "__#787803@#callbacks": Map<string, Set<(input: CurrencyRatePollingInput) => void>>;
38
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
39
+ "__#3@#callbacks": Map<string, Set<(input: CurrencyRatePollingInput) => void>>;
40
40
  _executePoll(input: CurrencyRatePollingInput): Promise<void>;
41
41
  startPolling(input: CurrencyRatePollingInput): string;
42
42
  stopAllPolling(): void;
@@ -29,14 +29,14 @@ type CurrencyRatePollingInput = {
29
29
  nativeCurrencies: string[];
30
30
  };
31
31
  declare const CurrencyRateController_base: (abstract new (...args: any[]) => {
32
- readonly "__#787811@#intervalIds": Record<string, NodeJS.Timeout>;
33
- "__#787811@#intervalLength": number | undefined;
32
+ readonly "__#11@#intervalIds": Record<string, NodeJS.Timeout>;
33
+ "__#11@#intervalLength": number | undefined;
34
34
  setIntervalLength(intervalLength: number): void;
35
35
  getIntervalLength(): number | undefined;
36
36
  _startPolling(input: CurrencyRatePollingInput): void;
37
37
  _stopPollingByPollingTokenSetId(key: string): void;
38
- readonly "__#787803@#pollingTokenSets": Map<string, Set<string>>;
39
- "__#787803@#callbacks": Map<string, Set<(input: CurrencyRatePollingInput) => void>>;
38
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
39
+ "__#3@#callbacks": Map<string, Set<(input: CurrencyRatePollingInput) => void>>;
40
40
  _executePoll(input: CurrencyRatePollingInput): Promise<void>;
41
41
  startPolling(input: CurrencyRatePollingInput): string;
42
42
  stopAllPolling(): void;
@@ -0,0 +1,117 @@
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 _BalancesTracker_poller, _BalancesTracker_updateBalance, _BalancesTracker_balances;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BalancesTracker = void 0;
16
+ const Poller_1 = require("./Poller.cjs");
17
+ const BALANCES_TRACKING_INTERVAL = 30 * 1000; // Every 30s in milliseconds.
18
+ class BalancesTracker {
19
+ constructor(updateBalanceCallback) {
20
+ _BalancesTracker_poller.set(this, void 0);
21
+ _BalancesTracker_updateBalance.set(this, void 0);
22
+ _BalancesTracker_balances.set(this, {});
23
+ __classPrivateFieldSet(this, _BalancesTracker_updateBalance, updateBalanceCallback, "f");
24
+ __classPrivateFieldSet(this, _BalancesTracker_poller, new Poller_1.Poller(this.updateBalances, BALANCES_TRACKING_INTERVAL), "f");
25
+ }
26
+ /**
27
+ * Starts the tracking process.
28
+ */
29
+ start() {
30
+ __classPrivateFieldGet(this, _BalancesTracker_poller, "f").start();
31
+ }
32
+ /**
33
+ * Stops the tracking process.
34
+ */
35
+ stop() {
36
+ __classPrivateFieldGet(this, _BalancesTracker_poller, "f").stop();
37
+ }
38
+ /**
39
+ * Checks if an account ID is being tracked.
40
+ *
41
+ * @param accountId - The account ID.
42
+ * @returns True if the account is being tracker, false otherwise.
43
+ */
44
+ isTracked(accountId) {
45
+ return accountId in __classPrivateFieldGet(this, _BalancesTracker_balances, "f");
46
+ }
47
+ /**
48
+ * Asserts that an account ID is being tracked.
49
+ *
50
+ * @param accountId - The account ID.
51
+ * @throws If the account ID is not being tracked.
52
+ */
53
+ assertBeingTracked(accountId) {
54
+ if (!this.isTracked(accountId)) {
55
+ throw new Error(`Account is not being tracked: ${accountId}`);
56
+ }
57
+ }
58
+ /**
59
+ * Starts tracking a new account ID. This method has no effect on already tracked
60
+ * accounts.
61
+ *
62
+ * @param accountId - The account ID.
63
+ * @param blockTime - The block time (used when refreshing the account balances).
64
+ */
65
+ track(accountId, blockTime) {
66
+ // Do not overwrite current info if already being tracked!
67
+ if (!this.isTracked(accountId)) {
68
+ __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId] = {
69
+ lastUpdated: 0,
70
+ blockTime,
71
+ };
72
+ }
73
+ }
74
+ /**
75
+ * Stops tracking a tracked account ID.
76
+ *
77
+ * @param accountId - The account ID.
78
+ * @throws If the account ID is not being tracked.
79
+ */
80
+ untrack(accountId) {
81
+ this.assertBeingTracked(accountId);
82
+ delete __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
83
+ }
84
+ /**
85
+ * Update the balances for a tracked account ID.
86
+ *
87
+ * @param accountId - The account ID.
88
+ * @throws If the account ID is not being tracked.
89
+ */
90
+ async updateBalance(accountId) {
91
+ this.assertBeingTracked(accountId);
92
+ // We check if the balance is outdated (by comparing to the block time associated
93
+ // with this kind of account).
94
+ //
95
+ // This might not be super accurate, but we could probably compute this differently
96
+ // and try to sync with the "real block time"!
97
+ const info = __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
98
+ const isOutdated = Date.now() - info.lastUpdated >= info.blockTime;
99
+ const hasNoBalanceYet = info.lastUpdated === 0;
100
+ if (hasNoBalanceYet || isOutdated) {
101
+ await __classPrivateFieldGet(this, _BalancesTracker_updateBalance, "f").call(this, accountId);
102
+ __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId].lastUpdated = Date.now();
103
+ }
104
+ }
105
+ /**
106
+ * Update the balances of all tracked accounts (only if the balances
107
+ * is considered outdated).
108
+ */
109
+ async updateBalances() {
110
+ await Promise.allSettled(Object.keys(__classPrivateFieldGet(this, _BalancesTracker_balances, "f")).map(async (accountId) => {
111
+ await this.updateBalance(accountId);
112
+ }));
113
+ }
114
+ }
115
+ exports.BalancesTracker = BalancesTracker;
116
+ _BalancesTracker_poller = new WeakMap(), _BalancesTracker_updateBalance = new WeakMap(), _BalancesTracker_balances = new WeakMap();
117
+ //# sourceMappingURL=BalancesTracker.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalancesTracker.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAkC;AAOlC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,6BAA6B;AAE3E,MAAa,eAAe;IAO1B,YAAY,qBAA2D;QANvE,0CAAgB;QAEhB,iDAAqD;QAErD,oCAAyC,EAAE,EAAC;QAG1C,uBAAA,IAAI,kCAAkB,qBAAqB,MAAA,CAAC;QAE5C,uBAAA,IAAI,2BAAW,IAAI,eAAM,CAAC,IAAI,CAAC,cAAc,EAAE,0BAA0B,CAAC,MAAA,CAAC;IAC7E,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,+BAAQ,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI;QACF,uBAAA,IAAI,+BAAQ,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,SAAiB;QACzB,OAAO,SAAS,IAAI,uBAAA,IAAI,iCAAU,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,SAAiB;QAClC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,EAAE,CAA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MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AA/GD,0CA+GC","sourcesContent":["import { Poller } from './Poller';\n\ntype BalanceInfo = {\n lastUpdated: number;\n blockTime: number;\n};\n\nconst BALANCES_TRACKING_INTERVAL = 30 * 1000; // Every 30s in milliseconds.\n\nexport class BalancesTracker {\n #poller: Poller;\n\n #updateBalance: (accountId: string) => Promise<void>;\n\n #balances: Record<string, BalanceInfo> = {};\n\n constructor(updateBalanceCallback: (accountId: string) => Promise<void>) {\n this.#updateBalance = updateBalanceCallback;\n\n this.#poller = new Poller(this.updateBalances, BALANCES_TRACKING_INTERVAL);\n }\n\n /**\n * Starts the tracking process.\n */\n start(): void {\n this.#poller.start();\n }\n\n /**\n * Stops the tracking process.\n */\n stop(): void {\n this.#poller.stop();\n }\n\n /**\n * Checks if an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @returns True if the account is being tracker, false otherwise.\n */\n isTracked(accountId: string) {\n return accountId in this.#balances;\n }\n\n /**\n * Asserts that an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n assertBeingTracked(accountId: string) {\n if (!this.isTracked(accountId)) {\n throw new Error(`Account is not being tracked: ${accountId}`);\n }\n }\n\n /**\n * Starts tracking a new account ID. This method has no effect on already tracked\n * accounts.\n *\n * @param accountId - The account ID.\n * @param blockTime - The block time (used when refreshing the account balances).\n */\n track(accountId: string, blockTime: number) {\n // Do not overwrite current info if already being tracked!\n if (!this.isTracked(accountId)) {\n this.#balances[accountId] = {\n lastUpdated: 0,\n blockTime,\n };\n }\n }\n\n /**\n * Stops tracking a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n untrack(accountId: string) {\n this.assertBeingTracked(accountId);\n delete this.#balances[accountId];\n }\n\n /**\n * Update the balances for a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n async updateBalance(accountId: string) {\n this.assertBeingTracked(accountId);\n\n // We check if the balance is outdated (by comparing to the block time associated\n // with this kind of account).\n //\n // This might not be super accurate, but we could probably compute this differently\n // and try to sync with the \"real block time\"!\n const info = this.#balances[accountId];\n const isOutdated = Date.now() - info.lastUpdated >= info.blockTime;\n const hasNoBalanceYet = info.lastUpdated === 0;\n if (hasNoBalanceYet || isOutdated) {\n await this.#updateBalance(accountId);\n this.#balances[accountId].lastUpdated = Date.now();\n }\n }\n\n /**\n * Update the balances of all tracked accounts (only if the balances\n * is considered outdated).\n */\n async updateBalances() {\n await Promise.allSettled(\n Object.keys(this.#balances).map(async (accountId) => {\n await this.updateBalance(accountId);\n }),\n );\n }\n}\n"]}
@@ -0,0 +1,54 @@
1
+ export declare class BalancesTracker {
2
+ #private;
3
+ constructor(updateBalanceCallback: (accountId: string) => Promise<void>);
4
+ /**
5
+ * Starts the tracking process.
6
+ */
7
+ start(): void;
8
+ /**
9
+ * Stops the tracking process.
10
+ */
11
+ stop(): void;
12
+ /**
13
+ * Checks if an account ID is being tracked.
14
+ *
15
+ * @param accountId - The account ID.
16
+ * @returns True if the account is being tracker, false otherwise.
17
+ */
18
+ isTracked(accountId: string): boolean;
19
+ /**
20
+ * Asserts that an account ID is being tracked.
21
+ *
22
+ * @param accountId - The account ID.
23
+ * @throws If the account ID is not being tracked.
24
+ */
25
+ assertBeingTracked(accountId: string): void;
26
+ /**
27
+ * Starts tracking a new account ID. This method has no effect on already tracked
28
+ * accounts.
29
+ *
30
+ * @param accountId - The account ID.
31
+ * @param blockTime - The block time (used when refreshing the account balances).
32
+ */
33
+ track(accountId: string, blockTime: number): void;
34
+ /**
35
+ * Stops tracking a tracked account ID.
36
+ *
37
+ * @param accountId - The account ID.
38
+ * @throws If the account ID is not being tracked.
39
+ */
40
+ untrack(accountId: string): void;
41
+ /**
42
+ * Update the balances for a tracked account ID.
43
+ *
44
+ * @param accountId - The account ID.
45
+ * @throws If the account ID is not being tracked.
46
+ */
47
+ updateBalance(accountId: string): Promise<void>;
48
+ /**
49
+ * Update the balances of all tracked accounts (only if the balances
50
+ * is considered outdated).
51
+ */
52
+ updateBalances(): Promise<void>;
53
+ }
54
+ //# sourceMappingURL=BalancesTracker.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalancesTracker.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":"AASA,qBAAa,eAAe;;gBAOd,qBAAqB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IAMvE;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM;IAI3B;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM;IAMpC;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAU1C;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM;IAKzB;;;;;OAKG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM;IAiBrC;;;OAGG;IACG,cAAc;CAOrB"}
@@ -0,0 +1,54 @@
1
+ export declare class BalancesTracker {
2
+ #private;
3
+ constructor(updateBalanceCallback: (accountId: string) => Promise<void>);
4
+ /**
5
+ * Starts the tracking process.
6
+ */
7
+ start(): void;
8
+ /**
9
+ * Stops the tracking process.
10
+ */
11
+ stop(): void;
12
+ /**
13
+ * Checks if an account ID is being tracked.
14
+ *
15
+ * @param accountId - The account ID.
16
+ * @returns True if the account is being tracker, false otherwise.
17
+ */
18
+ isTracked(accountId: string): boolean;
19
+ /**
20
+ * Asserts that an account ID is being tracked.
21
+ *
22
+ * @param accountId - The account ID.
23
+ * @throws If the account ID is not being tracked.
24
+ */
25
+ assertBeingTracked(accountId: string): void;
26
+ /**
27
+ * Starts tracking a new account ID. This method has no effect on already tracked
28
+ * accounts.
29
+ *
30
+ * @param accountId - The account ID.
31
+ * @param blockTime - The block time (used when refreshing the account balances).
32
+ */
33
+ track(accountId: string, blockTime: number): void;
34
+ /**
35
+ * Stops tracking a tracked account ID.
36
+ *
37
+ * @param accountId - The account ID.
38
+ * @throws If the account ID is not being tracked.
39
+ */
40
+ untrack(accountId: string): void;
41
+ /**
42
+ * Update the balances for a tracked account ID.
43
+ *
44
+ * @param accountId - The account ID.
45
+ * @throws If the account ID is not being tracked.
46
+ */
47
+ updateBalance(accountId: string): Promise<void>;
48
+ /**
49
+ * Update the balances of all tracked accounts (only if the balances
50
+ * is considered outdated).
51
+ */
52
+ updateBalances(): Promise<void>;
53
+ }
54
+ //# sourceMappingURL=BalancesTracker.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalancesTracker.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":"AASA,qBAAa,eAAe;;gBAOd,qBAAqB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IAMvE;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM;IAI3B;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM;IAMpC;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAU1C;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM;IAKzB;;;;;OAKG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM;IAiBrC;;;OAGG;IACG,cAAc;CAOrB"}
@@ -0,0 +1,113 @@
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 _BalancesTracker_poller, _BalancesTracker_updateBalance, _BalancesTracker_balances;
13
+ import { Poller } from "./Poller.mjs";
14
+ const BALANCES_TRACKING_INTERVAL = 30 * 1000; // Every 30s in milliseconds.
15
+ export class BalancesTracker {
16
+ constructor(updateBalanceCallback) {
17
+ _BalancesTracker_poller.set(this, void 0);
18
+ _BalancesTracker_updateBalance.set(this, void 0);
19
+ _BalancesTracker_balances.set(this, {});
20
+ __classPrivateFieldSet(this, _BalancesTracker_updateBalance, updateBalanceCallback, "f");
21
+ __classPrivateFieldSet(this, _BalancesTracker_poller, new Poller(this.updateBalances, BALANCES_TRACKING_INTERVAL), "f");
22
+ }
23
+ /**
24
+ * Starts the tracking process.
25
+ */
26
+ start() {
27
+ __classPrivateFieldGet(this, _BalancesTracker_poller, "f").start();
28
+ }
29
+ /**
30
+ * Stops the tracking process.
31
+ */
32
+ stop() {
33
+ __classPrivateFieldGet(this, _BalancesTracker_poller, "f").stop();
34
+ }
35
+ /**
36
+ * Checks if an account ID is being tracked.
37
+ *
38
+ * @param accountId - The account ID.
39
+ * @returns True if the account is being tracker, false otherwise.
40
+ */
41
+ isTracked(accountId) {
42
+ return accountId in __classPrivateFieldGet(this, _BalancesTracker_balances, "f");
43
+ }
44
+ /**
45
+ * Asserts that an account ID is being tracked.
46
+ *
47
+ * @param accountId - The account ID.
48
+ * @throws If the account ID is not being tracked.
49
+ */
50
+ assertBeingTracked(accountId) {
51
+ if (!this.isTracked(accountId)) {
52
+ throw new Error(`Account is not being tracked: ${accountId}`);
53
+ }
54
+ }
55
+ /**
56
+ * Starts tracking a new account ID. This method has no effect on already tracked
57
+ * accounts.
58
+ *
59
+ * @param accountId - The account ID.
60
+ * @param blockTime - The block time (used when refreshing the account balances).
61
+ */
62
+ track(accountId, blockTime) {
63
+ // Do not overwrite current info if already being tracked!
64
+ if (!this.isTracked(accountId)) {
65
+ __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId] = {
66
+ lastUpdated: 0,
67
+ blockTime,
68
+ };
69
+ }
70
+ }
71
+ /**
72
+ * Stops tracking a tracked account ID.
73
+ *
74
+ * @param accountId - The account ID.
75
+ * @throws If the account ID is not being tracked.
76
+ */
77
+ untrack(accountId) {
78
+ this.assertBeingTracked(accountId);
79
+ delete __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
80
+ }
81
+ /**
82
+ * Update the balances for a tracked account ID.
83
+ *
84
+ * @param accountId - The account ID.
85
+ * @throws If the account ID is not being tracked.
86
+ */
87
+ async updateBalance(accountId) {
88
+ this.assertBeingTracked(accountId);
89
+ // We check if the balance is outdated (by comparing to the block time associated
90
+ // with this kind of account).
91
+ //
92
+ // This might not be super accurate, but we could probably compute this differently
93
+ // and try to sync with the "real block time"!
94
+ const info = __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
95
+ const isOutdated = Date.now() - info.lastUpdated >= info.blockTime;
96
+ const hasNoBalanceYet = info.lastUpdated === 0;
97
+ if (hasNoBalanceYet || isOutdated) {
98
+ await __classPrivateFieldGet(this, _BalancesTracker_updateBalance, "f").call(this, accountId);
99
+ __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId].lastUpdated = Date.now();
100
+ }
101
+ }
102
+ /**
103
+ * Update the balances of all tracked accounts (only if the balances
104
+ * is considered outdated).
105
+ */
106
+ async updateBalances() {
107
+ await Promise.allSettled(Object.keys(__classPrivateFieldGet(this, _BalancesTracker_balances, "f")).map(async (accountId) => {
108
+ await this.updateBalance(accountId);
109
+ }));
110
+ }
111
+ }
112
+ _BalancesTracker_poller = new WeakMap(), _BalancesTracker_updateBalance = new WeakMap(), _BalancesTracker_balances = new WeakMap();
113
+ //# sourceMappingURL=BalancesTracker.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalancesTracker.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,qBAAiB;AAOlC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,6BAA6B;AAE3E,MAAM,OAAO,eAAe;IAO1B,YAAY,qBAA2D;QANvE,0CAAgB;QAEhB,iDAAqD;QAErD,oCAAyC,EAAE,EAAC;QAG1C,uBAAA,IAAI,kCAAkB,qBAAqB,MAAA,CAAC;QAE5C,uBAAA,IAAI,2BAAW,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,0BAA0B,CAAC,MAAA,CAAC;IAC7E,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,+BAAQ,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI;QACF,uBAAA,IAAI,+BAAQ,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,SAAiB;QACzB,OAAO,SAAS,IAAI,uBAAA,IAAI,iCAAU,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,SAAiB;QAClC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;SAC/D;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAiB,EAAE,SAAiB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J,CAAC;CACF","sourcesContent":["import { Poller } from './Poller';\n\ntype BalanceInfo = {\n lastUpdated: number;\n blockTime: number;\n};\n\nconst BALANCES_TRACKING_INTERVAL = 30 * 1000; // Every 30s in milliseconds.\n\nexport class BalancesTracker {\n #poller: Poller;\n\n #updateBalance: (accountId: string) => Promise<void>;\n\n #balances: Record<string, BalanceInfo> = {};\n\n constructor(updateBalanceCallback: (accountId: string) => Promise<void>) {\n this.#updateBalance = updateBalanceCallback;\n\n this.#poller = new Poller(this.updateBalances, BALANCES_TRACKING_INTERVAL);\n }\n\n /**\n * Starts the tracking process.\n */\n start(): void {\n this.#poller.start();\n }\n\n /**\n * Stops the tracking process.\n */\n stop(): void {\n this.#poller.stop();\n }\n\n /**\n * Checks if an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @returns True if the account is being tracker, false otherwise.\n */\n isTracked(accountId: string) {\n return accountId in this.#balances;\n }\n\n /**\n * Asserts that an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n assertBeingTracked(accountId: string) {\n if (!this.isTracked(accountId)) {\n throw new Error(`Account is not being tracked: ${accountId}`);\n }\n }\n\n /**\n * Starts tracking a new account ID. This method has no effect on already tracked\n * accounts.\n *\n * @param accountId - The account ID.\n * @param blockTime - The block time (used when refreshing the account balances).\n */\n track(accountId: string, blockTime: number) {\n // Do not overwrite current info if already being tracked!\n if (!this.isTracked(accountId)) {\n this.#balances[accountId] = {\n lastUpdated: 0,\n blockTime,\n };\n }\n }\n\n /**\n * Stops tracking a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n untrack(accountId: string) {\n this.assertBeingTracked(accountId);\n delete this.#balances[accountId];\n }\n\n /**\n * Update the balances for a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n async updateBalance(accountId: string) {\n this.assertBeingTracked(accountId);\n\n // We check if the balance is outdated (by comparing to the block time associated\n // with this kind of account).\n //\n // This might not be super accurate, but we could probably compute this differently\n // and try to sync with the \"real block time\"!\n const info = this.#balances[accountId];\n const isOutdated = Date.now() - info.lastUpdated >= info.blockTime;\n const hasNoBalanceYet = info.lastUpdated === 0;\n if (hasNoBalanceYet || isOutdated) {\n await this.#updateBalance(accountId);\n this.#balances[accountId].lastUpdated = Date.now();\n }\n }\n\n /**\n * Update the balances of all tracked accounts (only if the balances\n * is considered outdated).\n */\n async updateBalances() {\n await Promise.allSettled(\n Object.keys(this.#balances).map(async (accountId) => {\n await this.updateBalance(accountId);\n }),\n );\n }\n}\n"]}