@metamask-previews/earn-controller 3.0.0-preview-31e2b13a → 3.0.0-preview-d05158e7

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,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Changed
11
+
12
+ - **BREAKING:** Removed usages of `NetworkController:getState` for GNS removal. Added mandatory `chainId` parameter to `executeLendingTokenApprove`, `executeLendingWithdraw`, `executeLendingDeposit`, `getLendingMarketDailyApysAndAverages` and `getLendingPositionHistory` methods. Added mandatory `selectedNetworkClientId` parameter to constructor. Added optional `chainId` parameter to `refreshPooledStakingVaultApyAverages`, `refreshPooledStakingVaultDailyApys`, `refreshPooledStakingVaultMetadata` and `refreshPooledStakes`. ([#6153](https://github.com/MetaMask/core/pull/6153))
13
+
10
14
  ## [3.0.0]
11
15
 
12
16
  ### 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,29 +153,23 @@ 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) => {
164
+ __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, networkControllerState.selectedNetworkClientId).catch(console.error);
165
+ // refresh pooled staking data
166
+ this.refreshPooledStakingVaultMetadata().catch(console.error);
167
+ this.refreshPooledStakingVaultDailyApys().catch(console.error);
168
+ this.refreshPooledStakingVaultApyAverages().catch(console.error);
169
+ this.refreshPooledStakes().catch(console.error);
170
+ // refresh lending data for all chains
171
+ this.refreshLendingMarkets().catch(console.error);
172
+ this.refreshLendingPositions().catch(console.error);
180
173
  __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, networkControllerState.selectedNetworkClientId, "f");
181
174
  });
182
175
  // Listen for account changes
@@ -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,20 @@ 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
  *
289
+ * @param chainId - The chain id to refresh pooled staking vault daily apys for (optional).
288
290
  * @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
289
291
  * @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').
290
292
  * @returns A promise that resolves when the pooled staking vault daily apys have been updated.
291
293
  */
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);
294
+ async refreshPooledStakingVaultDailyApys(chainId = stake_sdk_1.ChainId.ETHEREUM, days = 365, order = 'desc') {
295
+ const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
296
+ ? chainId
297
+ : stake_sdk_1.ChainId.ETHEREUM;
298
+ const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainIdToUse, days, order);
295
299
  this.update((state) => {
296
- const chainState = state.pooled_staking[chainId] ?? exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
297
- state.pooled_staking[chainId] = {
300
+ const chainState = state.pooled_staking[chainIdToUse] ??
301
+ exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
302
+ state.pooled_staking[chainIdToUse] = {
298
303
  ...chainState,
299
304
  vaultDailyApys,
300
305
  };
@@ -304,14 +309,18 @@ class EarnController extends base_controller_1.BaseController {
304
309
  * Refreshes pooled staking vault apy averages for the current chain.
305
310
  * Updates the pooled staking vault apy averages controller state.
306
311
  *
312
+ * @param chainId - The chain id to refresh pooled staking vault apy averages for (optional).
307
313
  * @returns A promise that resolves when the pooled staking vault apy averages have been updated.
308
314
  */
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);
315
+ async refreshPooledStakingVaultApyAverages(chainId = stake_sdk_1.ChainId.ETHEREUM) {
316
+ const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
317
+ ? chainId
318
+ : stake_sdk_1.ChainId.ETHEREUM;
319
+ const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainIdToUse);
312
320
  this.update((state) => {
313
- const chainState = state.pooled_staking[chainId] ?? exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
314
- state.pooled_staking[chainId] = {
321
+ const chainState = state.pooled_staking[chainIdToUse] ??
322
+ exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
323
+ state.pooled_staking[chainIdToUse] = {
315
324
  ...chainState,
316
325
  vaultApyAverages,
317
326
  };
@@ -330,23 +339,25 @@ class EarnController extends base_controller_1.BaseController {
330
339
  */
331
340
  async refreshPooledStakingData({ resetCache, address, } = {}) {
332
341
  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
- ]);
342
+ for (const chainId of __classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f")) {
343
+ await Promise.all([
344
+ this.refreshPooledStakes({ resetCache, address, chainId }).catch((error) => {
345
+ errors.push(error);
346
+ }),
347
+ this.refreshEarnEligibility({ address }).catch((error) => {
348
+ errors.push(error);
349
+ }),
350
+ this.refreshPooledStakingVaultMetadata(chainId).catch((error) => {
351
+ errors.push(error);
352
+ }),
353
+ this.refreshPooledStakingVaultDailyApys(chainId).catch((error) => {
354
+ errors.push(error);
355
+ }),
356
+ this.refreshPooledStakingVaultApyAverages(chainId).catch((error) => {
357
+ errors.push(error);
358
+ }),
359
+ ]);
360
+ }
350
361
  if (errors.length > 0) {
351
362
  throw new Error(`Failed to refresh some staking data: ${errors
352
363
  .map((e) => e.message)
@@ -447,7 +458,7 @@ class EarnController extends base_controller_1.BaseController {
447
458
  *
448
459
  * @param options - Optional arguments
449
460
  * @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).
461
+ * @param [options.chainId] - The chain id to get lending position history for.
451
462
  * @param [options.positionId] - The position id to get lending position history for.
452
463
  * @param [options.marketId] - The market id to get lending position history for.
453
464
  * @param [options.marketAddress] - The market address to get lending position history for.
@@ -457,34 +468,33 @@ class EarnController extends base_controller_1.BaseController {
457
468
  */
458
469
  getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days = 730, }) {
459
470
  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)) {
471
+ if (!addressToUse || !(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
462
472
  return [];
463
473
  }
464
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainIdToUse, protocol, marketId, marketAddress, positionId, days);
474
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainId, protocol, marketId, marketAddress, positionId, days);
465
475
  }
466
476
  /**
467
477
  * Gets the lending market daily apys and averages for the current chain.
468
478
  *
469
479
  * @param options - Optional arguments
470
- * @param [options.chainId] - The chain id to get lending market daily apys and averages for (optional).
480
+ * @param [options.chainId] - The chain id to get lending market daily apys and averages for.
471
481
  * @param [options.protocol] - The protocol to get lending market daily apys and averages for.
472
482
  * @param [options.marketId] - The market id to get lending market daily apys and averages for.
473
483
  * @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
474
484
  * @returns A promise that resolves when the lending market daily apys and averages have been updated
475
485
  */
476
486
  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)) {
487
+ if (!(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
479
488
  return undefined;
480
489
  }
481
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainIdToUse, protocol, marketId, days);
490
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainId, protocol, marketId, days);
482
491
  }
483
492
  /**
484
493
  * Executes a lending deposit transaction.
485
494
  *
486
495
  * @param options - The options for the lending deposit transaction.
487
496
  * @param options.amount - The amount to deposit.
497
+ * @param options.chainId - The chain ID for the lending deposit transaction.
488
498
  * @param options.protocol - The protocol of the lending market.
489
499
  * @param options.underlyingTokenAddress - The address of the underlying token.
490
500
  * @param options.gasOptions - The gas options for the transaction.
@@ -493,7 +503,7 @@ class EarnController extends base_controller_1.BaseController {
493
503
  * @param options.txOptions - The transaction options for the transaction.
494
504
  * @returns A promise that resolves to the transaction hash.
495
505
  */
496
- async executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
506
+ async executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
497
507
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
498
508
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeDepositTransactionData(amount, address, gasOptions);
499
509
  if (!transactionData) {
@@ -508,7 +518,7 @@ class EarnController extends base_controller_1.BaseController {
508
518
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
509
519
  ...transactionData,
510
520
  value: transactionData.value.toString(),
511
- chainId: (0, controller_utils_1.toHex)(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
521
+ chainId: (0, controller_utils_1.toHex)(chainId),
512
522
  gasLimit,
513
523
  }, {
514
524
  ...txOptions,
@@ -521,6 +531,7 @@ class EarnController extends base_controller_1.BaseController {
521
531
  *
522
532
  * @param options - The options for the lending withdraw transaction.
523
533
  * @param options.amount - The amount to withdraw.
534
+ * @param options.chainId - The chain ID for the lending withdraw transaction.
524
535
  * @param options.protocol - The protocol of the lending market.
525
536
  * @param options.underlyingTokenAddress - The address of the underlying token.
526
537
  * @param options.gasOptions - The gas options for the transaction.
@@ -529,7 +540,7 @@ class EarnController extends base_controller_1.BaseController {
529
540
  * @param options.txOptions - The transaction options for the transaction.
530
541
  * @returns A promise that resolves to the transaction hash.
531
542
  */
532
- async executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
543
+ async executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
533
544
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
534
545
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeWithdrawTransactionData(amount, address, gasOptions);
535
546
  if (!transactionData) {
@@ -544,7 +555,7 @@ class EarnController extends base_controller_1.BaseController {
544
555
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
545
556
  ...transactionData,
546
557
  value: transactionData.value.toString(),
547
- chainId: (0, controller_utils_1.toHex)(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
558
+ chainId: (0, controller_utils_1.toHex)(chainId),
548
559
  gasLimit,
549
560
  }, {
550
561
  ...txOptions,
@@ -557,6 +568,7 @@ class EarnController extends base_controller_1.BaseController {
557
568
  *
558
569
  * @param options - The options for the lending token approve transaction.
559
570
  * @param options.amount - The amount to approve.
571
+ * @param options.chainId - The chain ID for the lending token approve transaction.
560
572
  * @param options.protocol - The protocol of the lending market.
561
573
  * @param options.underlyingTokenAddress - The address of the underlying token.
562
574
  * @param options.gasOptions - The gas options for the transaction.
@@ -565,7 +577,7 @@ class EarnController extends base_controller_1.BaseController {
565
577
  * @param options.txOptions - The transaction options for the transaction.
566
578
  * @returns A promise that resolves to the transaction hash.
567
579
  */
568
- async executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }) {
580
+ async executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }) {
569
581
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
570
582
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeUnderlyingTokenApproveTransactionData(amount, address, gasOptions);
571
583
  if (!transactionData) {
@@ -580,7 +592,7 @@ class EarnController extends base_controller_1.BaseController {
580
592
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
581
593
  ...transactionData,
582
594
  value: transactionData.value.toString(),
583
- chainId: (0, controller_utils_1.toHex)(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
595
+ chainId: (0, controller_utils_1.toHex)(chainId),
584
596
  gasLimit,
585
597
  }, {
586
598
  ...txOptions,
@@ -630,13 +642,10 @@ _EarnController_earnSDK = new WeakMap(), _EarnController_selectedNetworkClientId
630
642
  /**
631
643
  * Initializes the Earn SDK.
632
644
  *
633
- * @param networkClientId - The network client id to initialize the Earn SDK for (optional).
645
+ * @param networkClientId - The network client id to initialize the Earn SDK for.
634
646
  */
635
647
  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);
648
+ const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
640
649
  if (!networkClient?.provider) {
641
650
  __classPrivateFieldSet(this, _EarnController_earnSDK, null, "f");
642
651
  return;
@@ -661,19 +670,5 @@ async function _EarnController_initializeSDK(networkClientId) {
661
670
  }
662
671
  }, _EarnController_getCurrentAccount = function _EarnController_getCurrentAccount() {
663
672
  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
673
  };
679
674
  //# sourceMappingURL=EarnController.cjs.map