@metamask-previews/earn-controller 4.0.0-preview-b31794c → 4.0.0-preview-a8644e5b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - **BREAKING:** Added mandatory parameter `selectedNetworkClientId` to `EarnController` constructor ([#6153](https://github.com/MetaMask/core/pull/6153))
13
+ - **BREAKING:** Added mandatory `chainId` parameter to `executeLendingTokenApprove`, `executeLendingWithdraw`, `executeLendingDeposit`, `getLendingMarketDailyApysAndAverages` and `getLendingPositionHistory` methods ([#6153](https://github.com/MetaMask/core/pull/6153))
14
+ - **BREAKING:** Changed `refreshPooledStakingVaultDailyApys` to accept an options object with `chainId`, `days`, and `order` properties, where `chainId` is a new option, instead of separate parameters `days` and `order` ([#6153](https://github.com/MetaMask/core/pull/6153))
15
+ - Added optional `chainId` parameter to `refreshPooledStakingVaultApyAverages`, `refreshPooledStakingVaultMetadata` and `refreshPooledStakes` (defaults to Ethereum) ([#6153](https://github.com/MetaMask/core/pull/6153))
16
+
17
+ ### Changed
18
+
19
+ - **BREAKING:** Removed usages of `NetworkController:getState` for GNS removal. Added optional `chainId` parameter to `refreshPooledStakingVaultApyAverages`, `refreshPooledStakingVaultDailyApys`, `refreshPooledStakingVaultMetadata` and `refreshPooledStakes`. ([#6153](https://github.com/MetaMask/core/pull/6153))
20
+ - **BREAKING:** `EarnController` messenger must now allow `NetworkController:networkDidChange` and must not allow `NetworkController:getState` and `NetworkController:stateChange` ([#6153](https://github.com/MetaMask/core/pull/6153))
21
+ - `refreshPooledStakingData` now refreshes for all supported chains, not just global chain ([#6153](https://github.com/MetaMask/core/pull/6153))
22
+
10
23
  ## [4.0.0]
11
24
 
12
25
  ### Changed
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
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
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _EarnController_instances, _EarnController_earnSDK, _EarnController_selectedNetworkClientId, _EarnController_earnApiService, _EarnController_addTransactionFn, _EarnController_supportedPooledStakingChains, _EarnController_env, _EarnController_initializeSDK, _EarnController_getCurrentAccount, _EarnController_getCurrentChainId, _EarnController_getActivePooledStakingChainId;
13
+ var _EarnController_instances, _EarnController_earnSDK, _EarnController_selectedNetworkClientId, _EarnController_earnApiService, _EarnController_addTransactionFn, _EarnController_supportedPooledStakingChains, _EarnController_env, _EarnController_initializeSDK, _EarnController_getCurrentAccount;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.EarnController = exports.getDefaultEarnControllerState = exports.DEFAULT_POOLED_STAKING_CHAIN_STATE = exports.DEFAULT_POOLED_STAKING_VAULT_APY_AVERAGES = exports.DEFAULT_LENDING_POSITION = exports.DEFAULT_LENDING_MARKET = exports.controllerName = void 0;
16
16
  const providers_1 = require("@ethersproject/providers");
@@ -18,7 +18,6 @@ const base_controller_1 = require("@metamask/base-controller");
18
18
  const controller_utils_1 = require("@metamask/controller-utils");
19
19
  const stake_sdk_1 = require("@metamask/stake-sdk");
20
20
  const transaction_controller_1 = require("@metamask/transaction-controller");
21
- const constants_1 = require("./constants.cjs");
22
21
  exports.controllerName = 'EarnController';
23
22
  const stakingTransactionTypes = new Set([
24
23
  transaction_controller_1.TransactionType.stakingDeposit,
@@ -132,7 +131,7 @@ exports.getDefaultEarnControllerState = getDefaultEarnControllerState;
132
131
  * EarnController manages DeFi earning opportunities across different protocols and chains.
133
132
  */
134
133
  class EarnController extends base_controller_1.BaseController {
135
- constructor({ messenger, state = {}, addTransactionFn, env = stake_sdk_1.EarnEnvironments.PROD, }) {
134
+ constructor({ messenger, state = {}, addTransactionFn, selectedNetworkClientId, env = stake_sdk_1.EarnEnvironments.PROD, }) {
136
135
  super({
137
136
  name: exports.controllerName,
138
137
  metadata: earnControllerMetadata,
@@ -154,30 +153,24 @@ class EarnController extends base_controller_1.BaseController {
154
153
  // temporary array of supported chains
155
154
  // TODO: remove this once we export a supported chains list from the sdk
156
155
  // from sdk or api to get lending and pooled staking chains
157
- __classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [
158
- transaction_controller_1.CHAIN_IDS.MAINNET,
159
- constants_1.HOODI_TESTNET_CHAIN_ID_HEX,
160
- ], "f");
156
+ __classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [stake_sdk_1.ChainId.ETHEREUM, stake_sdk_1.ChainId.HOODI], "f");
161
157
  __classPrivateFieldSet(this, _EarnController_addTransactionFn, addTransactionFn, "f");
162
- __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this).catch(console.error);
158
+ __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, selectedNetworkClientId, "f");
159
+ __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, selectedNetworkClientId).catch(console.error);
163
160
  this.refreshPooledStakingData().catch(console.error);
164
161
  this.refreshLendingData().catch(console.error);
165
- const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
166
- __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, selectedNetworkClientId, "f");
167
162
  // Listen for network changes
168
- this.messagingSystem.subscribe('NetworkController:stateChange', (networkControllerState) => {
169
- if (networkControllerState.selectedNetworkClientId !==
170
- __classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f")) {
171
- __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, networkControllerState.selectedNetworkClientId).catch(console.error);
172
- this.refreshPooledStakingVaultMetadata().catch(console.error);
173
- this.refreshPooledStakingVaultDailyApys().catch(console.error);
174
- this.refreshPooledStakingVaultApyAverages().catch(console.error);
175
- this.refreshPooledStakes().catch(console.error);
176
- // refresh lending data for all chains
177
- this.refreshLendingMarkets().catch(console.error);
178
- this.refreshLendingPositions().catch(console.error);
179
- }
163
+ this.messagingSystem.subscribe('NetworkController:networkDidChange', (networkControllerState) => {
180
164
  __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, networkControllerState.selectedNetworkClientId, "f");
165
+ __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, __classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f")).catch(console.error);
166
+ // refresh pooled staking data
167
+ this.refreshPooledStakingVaultMetadata().catch(console.error);
168
+ this.refreshPooledStakingVaultDailyApys().catch(console.error);
169
+ this.refreshPooledStakingVaultApyAverages().catch(console.error);
170
+ this.refreshPooledStakes().catch(console.error);
171
+ // refresh lending data for all chains
172
+ this.refreshLendingMarkets().catch(console.error);
173
+ this.refreshLendingPositions().catch(console.error);
181
174
  });
182
175
  // Listen for account changes
183
176
  this.messagingSystem.subscribe('AccountsController:selectedAccountChange', (account) => {
@@ -222,18 +215,22 @@ class EarnController extends base_controller_1.BaseController {
222
215
  * @param options - Optional arguments
223
216
  * @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
224
217
  * @param [options.address] - The address to refresh pooled stakes for (optional).
218
+ * @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
225
219
  * @returns A promise that resolves when the stakes data has been updated
226
220
  */
227
- async refreshPooledStakes({ resetCache = false, address, } = {}) {
221
+ async refreshPooledStakes({ resetCache = false, address, chainId = stake_sdk_1.ChainId.ETHEREUM, } = {}) {
228
222
  const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
229
223
  if (!addressToUse) {
230
224
  return;
231
225
  }
232
- const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
233
- const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse], chainId, resetCache);
226
+ const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
227
+ ? chainId
228
+ : stake_sdk_1.ChainId.ETHEREUM;
229
+ const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse], chainIdToUse, resetCache);
234
230
  this.update((state) => {
235
- const chainState = state.pooled_staking[chainId] ?? exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
236
- state.pooled_staking[chainId] = {
231
+ const chainState = state.pooled_staking[chainIdToUse] ??
232
+ exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
233
+ state.pooled_staking[chainIdToUse] = {
237
234
  ...chainState,
238
235
  pooledStakes: accounts[0],
239
236
  exchangeRate,
@@ -268,14 +265,18 @@ class EarnController extends base_controller_1.BaseController {
268
265
  * Updates the vault metadata in the controller state including APY, capacity,
269
266
  * fee percentage, total assets, and vault address.
270
267
  *
268
+ * @param [chainId] - The chain id to refresh pooled staking vault metadata for (optional).
271
269
  * @returns A promise that resolves when the vault metadata has been updated
272
270
  */
273
- async refreshPooledStakingVaultMetadata() {
274
- const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
275
- const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(chainId);
271
+ async refreshPooledStakingVaultMetadata(chainId = stake_sdk_1.ChainId.ETHEREUM) {
272
+ const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
273
+ ? chainId
274
+ : stake_sdk_1.ChainId.ETHEREUM;
275
+ const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(chainIdToUse);
276
276
  this.update((state) => {
277
- const chainState = state.pooled_staking[chainId] ?? exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
278
- state.pooled_staking[chainId] = {
277
+ const chainState = state.pooled_staking[chainIdToUse] ??
278
+ exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
279
+ state.pooled_staking[chainIdToUse] = {
279
280
  ...chainState,
280
281
  vaultMetadata,
281
282
  };
@@ -285,16 +286,21 @@ class EarnController extends base_controller_1.BaseController {
285
286
  * Refreshes pooled staking vault daily apys for the current chain.
286
287
  * Updates the pooled staking vault daily apys controller state.
287
288
  *
288
- * @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
289
- * @param order - The order in which to fetch pooled staking vault daily apys. Descending order fetches the latest N days (latest working backwards). Ascending order fetches the oldest N days (oldest working forwards) (defaults to 'desc').
289
+ * @param [options] - The options for refreshing pooled staking vault daily apys.
290
+ * @param [options.chainId] - The chain id to refresh pooled staking vault daily apys for (defaults to Ethereum).
291
+ * @param [options.days] - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
292
+ * @param [options.order] - The order in which to fetch pooled staking vault daily apys. Descending order fetches the latest N days (latest working backwards). Ascending order fetches the oldest N days (oldest working forwards) (defaults to 'desc').
290
293
  * @returns A promise that resolves when the pooled staking vault daily apys have been updated.
291
294
  */
292
- async refreshPooledStakingVaultDailyApys(days = 365, order = 'desc') {
293
- const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
294
- const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainId, days, order);
295
+ async refreshPooledStakingVaultDailyApys({ chainId = stake_sdk_1.ChainId.ETHEREUM, days = 365, order = 'desc', } = {}) {
296
+ const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
297
+ ? chainId
298
+ : stake_sdk_1.ChainId.ETHEREUM;
299
+ const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainIdToUse, days, order);
295
300
  this.update((state) => {
296
- const chainState = state.pooled_staking[chainId] ?? exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
297
- state.pooled_staking[chainId] = {
301
+ const chainState = state.pooled_staking[chainIdToUse] ??
302
+ exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
303
+ state.pooled_staking[chainIdToUse] = {
298
304
  ...chainState,
299
305
  vaultDailyApys,
300
306
  };
@@ -304,14 +310,18 @@ class EarnController extends base_controller_1.BaseController {
304
310
  * Refreshes pooled staking vault apy averages for the current chain.
305
311
  * Updates the pooled staking vault apy averages controller state.
306
312
  *
313
+ * @param [chainId] - The chain id to refresh pooled staking vault apy averages for (optional).
307
314
  * @returns A promise that resolves when the pooled staking vault apy averages have been updated.
308
315
  */
309
- async refreshPooledStakingVaultApyAverages() {
310
- const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
311
- const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainId);
316
+ async refreshPooledStakingVaultApyAverages(chainId = stake_sdk_1.ChainId.ETHEREUM) {
317
+ const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
318
+ ? chainId
319
+ : stake_sdk_1.ChainId.ETHEREUM;
320
+ const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainIdToUse);
312
321
  this.update((state) => {
313
- const chainState = state.pooled_staking[chainId] ?? exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
314
- state.pooled_staking[chainId] = {
322
+ const chainState = state.pooled_staking[chainIdToUse] ??
323
+ exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
324
+ state.pooled_staking[chainIdToUse] = {
315
325
  ...chainState,
316
326
  vaultApyAverages,
317
327
  };
@@ -330,23 +340,26 @@ class EarnController extends base_controller_1.BaseController {
330
340
  */
331
341
  async refreshPooledStakingData({ resetCache, address, } = {}) {
332
342
  const errors = [];
333
- await Promise.all([
334
- this.refreshPooledStakes({ resetCache, address }).catch((error) => {
335
- errors.push(error);
336
- }),
337
- this.refreshEarnEligibility({ address }).catch((error) => {
338
- errors.push(error);
339
- }),
340
- this.refreshPooledStakingVaultMetadata().catch((error) => {
341
- errors.push(error);
342
- }),
343
- this.refreshPooledStakingVaultDailyApys().catch((error) => {
344
- errors.push(error);
345
- }),
346
- this.refreshPooledStakingVaultApyAverages().catch((error) => {
347
- errors.push(error);
348
- }),
349
- ]);
343
+ // Refresh earn eligibility once since it's not chain-specific
344
+ await this.refreshEarnEligibility({ address }).catch((error) => {
345
+ errors.push(error);
346
+ });
347
+ for (const chainId of __classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f")) {
348
+ await Promise.all([
349
+ this.refreshPooledStakes({ resetCache, address, chainId }).catch((error) => {
350
+ errors.push(error);
351
+ }),
352
+ this.refreshPooledStakingVaultMetadata(chainId).catch((error) => {
353
+ errors.push(error);
354
+ }),
355
+ this.refreshPooledStakingVaultDailyApys({ chainId }).catch((error) => {
356
+ errors.push(error);
357
+ }),
358
+ this.refreshPooledStakingVaultApyAverages(chainId).catch((error) => {
359
+ errors.push(error);
360
+ }),
361
+ ]);
362
+ }
350
363
  if (errors.length > 0) {
351
364
  throw new Error(`Failed to refresh some staking data: ${errors
352
365
  .map((e) => e.message)
@@ -447,7 +460,7 @@ class EarnController extends base_controller_1.BaseController {
447
460
  *
448
461
  * @param options - Optional arguments
449
462
  * @param [options.address] - The address to get lending position history for (optional).
450
- * @param [options.chainId] - The chain id to get lending position history for (optional).
463
+ * @param options.chainId - The chain id to get lending position history for.
451
464
  * @param [options.positionId] - The position id to get lending position history for.
452
465
  * @param [options.marketId] - The market id to get lending position history for.
453
466
  * @param [options.marketAddress] - The market address to get lending position history for.
@@ -457,34 +470,33 @@ class EarnController extends base_controller_1.BaseController {
457
470
  */
458
471
  getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days = 730, }) {
459
472
  const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
460
- const chainIdToUse = chainId ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
461
- if (!addressToUse || !(0, stake_sdk_1.isSupportedLendingChain)(chainIdToUse)) {
473
+ if (!addressToUse || !(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
462
474
  return [];
463
475
  }
464
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainIdToUse, protocol, marketId, marketAddress, positionId, days);
476
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainId, protocol, marketId, marketAddress, positionId, days);
465
477
  }
466
478
  /**
467
479
  * Gets the lending market daily apys and averages for the current chain.
468
480
  *
469
481
  * @param options - Optional arguments
470
- * @param [options.chainId] - The chain id to get lending market daily apys and averages for (optional).
482
+ * @param options.chainId - The chain id to get lending market daily apys and averages for.
471
483
  * @param [options.protocol] - The protocol to get lending market daily apys and averages for.
472
484
  * @param [options.marketId] - The market id to get lending market daily apys and averages for.
473
485
  * @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
474
486
  * @returns A promise that resolves when the lending market daily apys and averages have been updated
475
487
  */
476
488
  getLendingMarketDailyApysAndAverages({ chainId, protocol, marketId, days = 365, }) {
477
- const chainIdToUse = chainId ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
478
- if (!(0, stake_sdk_1.isSupportedLendingChain)(chainIdToUse)) {
489
+ if (!(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
479
490
  return undefined;
480
491
  }
481
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainIdToUse, protocol, marketId, days);
492
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainId, protocol, marketId, days);
482
493
  }
483
494
  /**
484
495
  * Executes a lending deposit transaction.
485
496
  *
486
497
  * @param options - The options for the lending deposit transaction.
487
498
  * @param options.amount - The amount to deposit.
499
+ * @param options.chainId - The chain ID for the lending deposit transaction.
488
500
  * @param options.protocol - The protocol of the lending market.
489
501
  * @param options.underlyingTokenAddress - The address of the underlying token.
490
502
  * @param options.gasOptions - The gas options for the transaction.
@@ -493,7 +505,7 @@ class EarnController extends base_controller_1.BaseController {
493
505
  * @param options.txOptions - The transaction options for the transaction.
494
506
  * @returns A promise that resolves to the transaction hash.
495
507
  */
496
- async executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
508
+ async executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
497
509
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
498
510
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeDepositTransactionData(amount, address, gasOptions);
499
511
  if (!transactionData) {
@@ -508,7 +520,7 @@ class EarnController extends base_controller_1.BaseController {
508
520
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
509
521
  ...transactionData,
510
522
  value: transactionData.value.toString(),
511
- chainId: (0, controller_utils_1.toHex)(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
523
+ chainId: (0, controller_utils_1.toHex)(chainId),
512
524
  gasLimit,
513
525
  }, {
514
526
  ...txOptions,
@@ -521,6 +533,7 @@ class EarnController extends base_controller_1.BaseController {
521
533
  *
522
534
  * @param options - The options for the lending withdraw transaction.
523
535
  * @param options.amount - The amount to withdraw.
536
+ * @param options.chainId - The chain ID for the lending withdraw transaction.
524
537
  * @param options.protocol - The protocol of the lending market.
525
538
  * @param options.underlyingTokenAddress - The address of the underlying token.
526
539
  * @param options.gasOptions - The gas options for the transaction.
@@ -529,7 +542,7 @@ class EarnController extends base_controller_1.BaseController {
529
542
  * @param options.txOptions - The transaction options for the transaction.
530
543
  * @returns A promise that resolves to the transaction hash.
531
544
  */
532
- async executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
545
+ async executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
533
546
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
534
547
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeWithdrawTransactionData(amount, address, gasOptions);
535
548
  if (!transactionData) {
@@ -544,7 +557,7 @@ class EarnController extends base_controller_1.BaseController {
544
557
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
545
558
  ...transactionData,
546
559
  value: transactionData.value.toString(),
547
- chainId: (0, controller_utils_1.toHex)(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
560
+ chainId: (0, controller_utils_1.toHex)(chainId),
548
561
  gasLimit,
549
562
  }, {
550
563
  ...txOptions,
@@ -557,6 +570,7 @@ class EarnController extends base_controller_1.BaseController {
557
570
  *
558
571
  * @param options - The options for the lending token approve transaction.
559
572
  * @param options.amount - The amount to approve.
573
+ * @param options.chainId - The chain ID for the lending token approve transaction.
560
574
  * @param options.protocol - The protocol of the lending market.
561
575
  * @param options.underlyingTokenAddress - The address of the underlying token.
562
576
  * @param options.gasOptions - The gas options for the transaction.
@@ -565,7 +579,7 @@ class EarnController extends base_controller_1.BaseController {
565
579
  * @param options.txOptions - The transaction options for the transaction.
566
580
  * @returns A promise that resolves to the transaction hash.
567
581
  */
568
- async executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }) {
582
+ async executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }) {
569
583
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
570
584
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeUnderlyingTokenApproveTransactionData(amount, address, gasOptions);
571
585
  if (!transactionData) {
@@ -580,7 +594,7 @@ class EarnController extends base_controller_1.BaseController {
580
594
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
581
595
  ...transactionData,
582
596
  value: transactionData.value.toString(),
583
- chainId: (0, controller_utils_1.toHex)(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
597
+ chainId: (0, controller_utils_1.toHex)(chainId),
584
598
  gasLimit,
585
599
  }, {
586
600
  ...txOptions,
@@ -630,13 +644,10 @@ _EarnController_earnSDK = new WeakMap(), _EarnController_selectedNetworkClientId
630
644
  /**
631
645
  * Initializes the Earn SDK.
632
646
  *
633
- * @param networkClientId - The network client id to initialize the Earn SDK for (optional).
647
+ * @param networkClientId - The network client id to initialize the Earn SDK for.
634
648
  */
635
649
  async function _EarnController_initializeSDK(networkClientId) {
636
- const { selectedNetworkClientId } = networkClientId
637
- ? { selectedNetworkClientId: networkClientId }
638
- : this.messagingSystem.call('NetworkController:getState');
639
- const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
650
+ const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
640
651
  if (!networkClient?.provider) {
641
652
  __classPrivateFieldSet(this, _EarnController_earnSDK, null, "f");
642
653
  return;
@@ -661,19 +672,5 @@ async function _EarnController_initializeSDK(networkClientId) {
661
672
  }
662
673
  }, _EarnController_getCurrentAccount = function _EarnController_getCurrentAccount() {
663
674
  return this.messagingSystem.call('AccountsController:getSelectedAccount');
664
- }, _EarnController_getCurrentChainId = function _EarnController_getCurrentChainId(networkClientId) {
665
- const networkClientIdToUse = networkClientId ??
666
- this.messagingSystem.call('NetworkController:getState')
667
- .selectedNetworkClientId;
668
- const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientIdToUse);
669
- return (0, controller_utils_1.convertHexToDecimal)(chainId);
670
- }, _EarnController_getActivePooledStakingChainId = function _EarnController_getActivePooledStakingChainId() {
671
- const activeChainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
672
- if (!activeChainId ||
673
- !__classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f").includes((0, controller_utils_1.toHex)(activeChainId))) {
674
- // Fallback to Ethereum Mainnet if chainId is not supported.
675
- return (0, controller_utils_1.convertHexToDecimal)(transaction_controller_1.CHAIN_IDS.MAINNET);
676
- }
677
- return activeChainId;
678
675
  };
679
676
  //# sourceMappingURL=EarnController.cjs.map