@metamask-previews/earn-controller 4.0.0-preview-e0bc4b4b → 4.0.0-preview-b8fffa99

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.
@@ -1,10 +1,10 @@
1
1
  import type { AccountsControllerGetSelectedAccountAction, AccountsControllerSelectedAccountChangeEvent } from "@metamask/accounts-controller";
2
2
  import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
3
3
  import { BaseController } from "@metamask/base-controller";
4
- import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
4
+ import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
5
5
  import { type LendingMarket, type PooledStake, type VaultData, type VaultDailyApy, type VaultApyAverages, type LendingPosition, type GasLimitParams, type HistoricLendingMarketApys, EarnEnvironments } from "@metamask/stake-sdk";
6
6
  import { type TransactionController, type TransactionControllerTransactionConfirmedEvent } from "@metamask/transaction-controller";
7
- import type { RefreshEarnEligibilityOptions, RefreshLendingEligibilityOptions, RefreshLendingPositionsOptions, RefreshPooledStakesOptions, RefreshPooledStakingDataOptions, RefreshPooledStakingVaultDailyApysOptions } from "./types.mjs";
7
+ import type { RefreshEarnEligibilityOptions, RefreshLendingEligibilityOptions, RefreshLendingPositionsOptions, RefreshPooledStakesOptions, RefreshPooledStakingDataOptions } from "./types.mjs";
8
8
  export declare const controllerName = "EarnController";
9
9
  export type PooledStakingState = {
10
10
  [chainId: number]: {
@@ -77,7 +77,7 @@ export type EarnControllerActions = EarnControllerGetStateAction;
77
77
  /**
78
78
  * All actions that EarnController calls internally.
79
79
  */
80
- export type AllowedActions = NetworkControllerGetNetworkClientByIdAction | AccountsControllerGetSelectedAccountAction;
80
+ export type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | AccountsControllerGetSelectedAccountAction;
81
81
  /**
82
82
  * The event that EarnController publishes when updating state.
83
83
  */
@@ -89,7 +89,7 @@ export type EarnControllerEvents = EarnControllerStateChangeEvent;
89
89
  /**
90
90
  * All events that EarnController subscribes to internally.
91
91
  */
92
- export type AllowedEvents = AccountsControllerSelectedAccountChangeEvent | TransactionControllerTransactionConfirmedEvent | NetworkControllerStateChangeEvent;
92
+ export type AllowedEvents = AccountsControllerSelectedAccountChangeEvent | NetworkControllerStateChangeEvent | TransactionControllerTransactionConfirmedEvent;
93
93
  /**
94
94
  * The messenger which is restricted to actions and events accessed by
95
95
  * EarnController.
@@ -100,11 +100,10 @@ export type EarnControllerMessenger = RestrictedMessenger<typeof controllerName,
100
100
  */
101
101
  export declare class EarnController extends BaseController<typeof controllerName, EarnControllerState, EarnControllerMessenger> {
102
102
  #private;
103
- constructor({ messenger, state, addTransactionFn, selectedNetworkClientId, env, }: {
103
+ constructor({ messenger, state, addTransactionFn, env, }: {
104
104
  messenger: EarnControllerMessenger;
105
105
  state?: Partial<EarnControllerState>;
106
106
  addTransactionFn: typeof TransactionController.prototype.addTransaction;
107
- selectedNetworkClientId: string;
108
107
  env?: EarnEnvironments;
109
108
  });
110
109
  /**
@@ -115,10 +114,9 @@ export declare class EarnController extends BaseController<typeof controllerName
115
114
  * @param options - Optional arguments
116
115
  * @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
117
116
  * @param [options.address] - The address to refresh pooled stakes for (optional).
118
- * @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
119
117
  * @returns A promise that resolves when the stakes data has been updated
120
118
  */
121
- refreshPooledStakes({ resetCache, address, chainId, }?: RefreshPooledStakesOptions): Promise<void>;
119
+ refreshPooledStakes({ resetCache, address, }?: RefreshPooledStakesOptions): Promise<void>;
122
120
  /**
123
121
  * Refreshes the earn eligibility status for the current account.
124
122
  * Updates the eligibility status in the controller state based on the location and address blocklist for compliance.
@@ -135,29 +133,25 @@ export declare class EarnController extends BaseController<typeof controllerName
135
133
  * Updates the vault metadata in the controller state including APY, capacity,
136
134
  * fee percentage, total assets, and vault address.
137
135
  *
138
- * @param [chainId] - The chain id to refresh pooled staking vault metadata for (optional).
139
136
  * @returns A promise that resolves when the vault metadata has been updated
140
137
  */
141
- refreshPooledStakingVaultMetadata(chainId?: number): Promise<void>;
138
+ refreshPooledStakingVaultMetadata(): Promise<void>;
142
139
  /**
143
140
  * Refreshes pooled staking vault daily apys for the current chain.
144
141
  * Updates the pooled staking vault daily apys controller state.
145
142
  *
146
- * @param [options] - The options for refreshing pooled staking vault daily apys.
147
- * @param [options.chainId] - The chain id to refresh pooled staking vault daily apys for (defaults to Ethereum).
148
- * @param [options.days] - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
149
- * @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').
143
+ * @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
144
+ * @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').
150
145
  * @returns A promise that resolves when the pooled staking vault daily apys have been updated.
151
146
  */
152
- refreshPooledStakingVaultDailyApys({ chainId, days, order, }?: RefreshPooledStakingVaultDailyApysOptions): Promise<void>;
147
+ refreshPooledStakingVaultDailyApys(days?: number, order?: 'asc' | 'desc'): Promise<void>;
153
148
  /**
154
149
  * Refreshes pooled staking vault apy averages for the current chain.
155
150
  * Updates the pooled staking vault apy averages controller state.
156
151
  *
157
- * @param [chainId] - The chain id to refresh pooled staking vault apy averages for (optional).
158
152
  * @returns A promise that resolves when the pooled staking vault apy averages have been updated.
159
153
  */
160
- refreshPooledStakingVaultApyAverages(chainId?: number): Promise<void>;
154
+ refreshPooledStakingVaultApyAverages(): Promise<void>;
161
155
  /**
162
156
  * Refreshes all pooled staking related data including stakes, eligibility, and vault data.
163
157
  * This method allows partial success, meaning some data may update while other requests fail.
@@ -209,7 +203,7 @@ export declare class EarnController extends BaseController<typeof controllerName
209
203
  *
210
204
  * @param options - Optional arguments
211
205
  * @param [options.address] - The address to get lending position history for (optional).
212
- * @param options.chainId - The chain id to get lending position history for.
206
+ * @param [options.chainId] - The chain id to get lending position history for (optional).
213
207
  * @param [options.positionId] - The position id to get lending position history for.
214
208
  * @param [options.marketId] - The market id to get lending position history for.
215
209
  * @param [options.marketAddress] - The market address to get lending position history for.
@@ -219,7 +213,7 @@ export declare class EarnController extends BaseController<typeof controllerName
219
213
  */
220
214
  getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days, }: {
221
215
  address?: string;
222
- chainId: number;
216
+ chainId?: number;
223
217
  positionId: string;
224
218
  marketId: string;
225
219
  marketAddress: string;
@@ -230,14 +224,14 @@ export declare class EarnController extends BaseController<typeof controllerName
230
224
  * Gets the lending market daily apys and averages for the current chain.
231
225
  *
232
226
  * @param options - Optional arguments
233
- * @param options.chainId - The chain id to get lending market daily apys and averages for.
227
+ * @param [options.chainId] - The chain id to get lending market daily apys and averages for (optional).
234
228
  * @param [options.protocol] - The protocol to get lending market daily apys and averages for.
235
229
  * @param [options.marketId] - The market id to get lending market daily apys and averages for.
236
230
  * @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
237
231
  * @returns A promise that resolves when the lending market daily apys and averages have been updated
238
232
  */
239
233
  getLendingMarketDailyApysAndAverages({ chainId, protocol, marketId, days, }: {
240
- chainId: number;
234
+ chainId?: number;
241
235
  protocol: string;
242
236
  marketId: string;
243
237
  days?: number;
@@ -247,7 +241,6 @@ export declare class EarnController extends BaseController<typeof controllerName
247
241
  *
248
242
  * @param options - The options for the lending deposit transaction.
249
243
  * @param options.amount - The amount to deposit.
250
- * @param options.chainId - The chain ID for the lending deposit transaction.
251
244
  * @param options.protocol - The protocol of the lending market.
252
245
  * @param options.underlyingTokenAddress - The address of the underlying token.
253
246
  * @param options.gasOptions - The gas options for the transaction.
@@ -256,9 +249,8 @@ export declare class EarnController extends BaseController<typeof controllerName
256
249
  * @param options.txOptions - The transaction options for the transaction.
257
250
  * @returns A promise that resolves to the transaction hash.
258
251
  */
259
- executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
252
+ executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
260
253
  amount: string;
261
- chainId: string;
262
254
  protocol: LendingMarket['protocol'];
263
255
  underlyingTokenAddress: string;
264
256
  gasOptions: {
@@ -272,7 +264,6 @@ export declare class EarnController extends BaseController<typeof controllerName
272
264
  *
273
265
  * @param options - The options for the lending withdraw transaction.
274
266
  * @param options.amount - The amount to withdraw.
275
- * @param options.chainId - The chain ID for the lending withdraw transaction.
276
267
  * @param options.protocol - The protocol of the lending market.
277
268
  * @param options.underlyingTokenAddress - The address of the underlying token.
278
269
  * @param options.gasOptions - The gas options for the transaction.
@@ -281,9 +272,8 @@ export declare class EarnController extends BaseController<typeof controllerName
281
272
  * @param options.txOptions - The transaction options for the transaction.
282
273
  * @returns A promise that resolves to the transaction hash.
283
274
  */
284
- executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
275
+ executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
285
276
  amount: string;
286
- chainId: string;
287
277
  protocol: LendingMarket['protocol'];
288
278
  underlyingTokenAddress: string;
289
279
  gasOptions: {
@@ -297,7 +287,6 @@ export declare class EarnController extends BaseController<typeof controllerName
297
287
  *
298
288
  * @param options - The options for the lending token approve transaction.
299
289
  * @param options.amount - The amount to approve.
300
- * @param options.chainId - The chain ID for the lending token approve transaction.
301
290
  * @param options.protocol - The protocol of the lending market.
302
291
  * @param options.underlyingTokenAddress - The address of the underlying token.
303
292
  * @param options.gasOptions - The gas options for the transaction.
@@ -306,10 +295,9 @@ export declare class EarnController extends BaseController<typeof controllerName
306
295
  * @param options.txOptions - The transaction options for the transaction.
307
296
  * @returns A promise that resolves to the transaction hash.
308
297
  */
309
- executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }: {
298
+ executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }: {
310
299
  protocol: LendingMarket['protocol'];
311
300
  amount: string;
312
- chainId: string;
313
301
  underlyingTokenAddress: string;
314
302
  gasOptions: {
315
303
  gasLimit?: GasLimitParams;
@@ -1 +1 @@
1
- {"version":3,"file":"EarnController.d.mts","sourceRoot":"","sources":["../src/EarnController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0CAA0C,EAC1C,4CAA4C,EAC7C,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EACV,2CAA2C,EAC3C,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,WAAW,EAEhB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,gBAAgB,EAGjB,4BAA4B;AAC7B,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,8CAA8C,EACpD,yCAAyC;AAE1C,OAAO,KAAK,EACV,6BAA6B,EAC7B,gCAAgC,EAChC,8BAA8B,EAC9B,0BAA0B,EAC1B,+BAA+B,EAC/B,yCAAyC,EAC1C,oBAAgB;AAEjB,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,CAAC,OAAO,EAAE,MAAM,GAAG;QACjB,YAAY,EAAE,WAAW,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,SAAS,CAAC;QACzB,cAAc,EAAE,aAAa,EAAE,CAAC;QAChC,gBAAgB,EAAE,gBAAgB,CAAC;KACpC,CAAC;IAC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BAAsB,EAAE,MAAM,CAAC;QAC/B,UAAU,EAAE;YACV,QAAQ,CAAC,EAAE,cAAc,CAAC;YAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;SACvB,CAAC;QACF,SAAS,EAAE,UAAU,CACnB,OAAO,qBAAqB,CAAC,SAAS,CAAC,cAAc,CACtD,CAAC,CAAC,CAAC,CAAC;KACN;IAuCD;;;;;;OAMG;IACG,wBAAwB,CAC5B,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,sBAAsB,EAAE,MAAM;IAYhC;;;;;;OAMG;IACG,0BAA0B,CAC9B,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,sBAAsB,EAAE,MAAM;IAYhC;;;;;;OAMG;IACG,yBAAyB,CAC7B,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,sBAAsB,EAAE,MAAM;CAWjC"}
@@ -9,12 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
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
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _EarnController_instances, _EarnController_earnSDK, _EarnController_selectedNetworkClientId, _EarnController_earnApiService, _EarnController_addTransactionFn, _EarnController_supportedPooledStakingChains, _EarnController_env, _EarnController_initializeSDK, _EarnController_getCurrentAccount;
12
+ var _EarnController_instances, _EarnController_earnSDK, _EarnController_selectedNetworkClientId, _EarnController_earnApiService, _EarnController_addTransactionFn, _EarnController_supportedPooledStakingChains, _EarnController_env, _EarnController_initializeSDK, _EarnController_getCurrentAccount, _EarnController_getCurrentChainId, _EarnController_getActivePooledStakingChainId;
13
13
  import { Web3Provider } from "@ethersproject/providers";
14
14
  import { BaseController } from "@metamask/base-controller";
15
15
  import { convertHexToDecimal, toHex } from "@metamask/controller-utils";
16
- import { EarnSdk, EarnApiService, isSupportedLendingChain, EarnEnvironments, ChainId, isSupportedPooledStakingChain } from "@metamask/stake-sdk";
17
- import { TransactionType } from "@metamask/transaction-controller";
16
+ import { EarnSdk, EarnApiService, isSupportedLendingChain, EarnEnvironments } from "@metamask/stake-sdk";
17
+ import { TransactionType, CHAIN_IDS } from "@metamask/transaction-controller";
18
+ import { HOODI_TESTNET_CHAIN_ID_HEX } from "./constants.mjs";
18
19
  export const controllerName = 'EarnController';
19
20
  const stakingTransactionTypes = new Set([
20
21
  TransactionType.stakingDeposit,
@@ -127,7 +128,7 @@ export function getDefaultEarnControllerState() {
127
128
  * EarnController manages DeFi earning opportunities across different protocols and chains.
128
129
  */
129
130
  export class EarnController extends BaseController {
130
- constructor({ messenger, state = {}, addTransactionFn, selectedNetworkClientId, env = EarnEnvironments.PROD, }) {
131
+ constructor({ messenger, state = {}, addTransactionFn, env = EarnEnvironments.PROD, }) {
131
132
  super({
132
133
  name: controllerName,
133
134
  metadata: earnControllerMetadata,
@@ -149,12 +150,16 @@ export class EarnController extends BaseController {
149
150
  // temporary array of supported chains
150
151
  // TODO: remove this once we export a supported chains list from the sdk
151
152
  // from sdk or api to get lending and pooled staking chains
152
- __classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [ChainId.ETHEREUM, ChainId.HOODI], "f");
153
+ __classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [
154
+ CHAIN_IDS.MAINNET,
155
+ HOODI_TESTNET_CHAIN_ID_HEX,
156
+ ], "f");
153
157
  __classPrivateFieldSet(this, _EarnController_addTransactionFn, addTransactionFn, "f");
154
- __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, selectedNetworkClientId, "f");
155
- __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, selectedNetworkClientId).catch(console.error);
158
+ __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this).catch(console.error);
156
159
  this.refreshPooledStakingData().catch(console.error);
157
160
  this.refreshLendingData().catch(console.error);
161
+ const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
162
+ __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, selectedNetworkClientId, "f");
158
163
  // Listen for network changes
159
164
  this.messagingSystem.subscribe('NetworkController:stateChange', (networkControllerState) => {
160
165
  if (networkControllerState.selectedNetworkClientId !==
@@ -213,22 +218,18 @@ export class EarnController extends BaseController {
213
218
  * @param options - Optional arguments
214
219
  * @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
215
220
  * @param [options.address] - The address to refresh pooled stakes for (optional).
216
- * @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
217
221
  * @returns A promise that resolves when the stakes data has been updated
218
222
  */
219
- async refreshPooledStakes({ resetCache = false, address, chainId = ChainId.ETHEREUM, } = {}) {
223
+ async refreshPooledStakes({ resetCache = false, address, } = {}) {
220
224
  const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
221
225
  if (!addressToUse) {
222
226
  return;
223
227
  }
224
- const chainIdToUse = isSupportedPooledStakingChain(chainId)
225
- ? chainId
226
- : ChainId.ETHEREUM;
227
- const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse], chainIdToUse, resetCache);
228
+ const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
229
+ const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse], chainId, resetCache);
228
230
  this.update((state) => {
229
- const chainState = state.pooled_staking[chainIdToUse] ??
230
- DEFAULT_POOLED_STAKING_CHAIN_STATE;
231
- state.pooled_staking[chainIdToUse] = {
231
+ const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
232
+ state.pooled_staking[chainId] = {
232
233
  ...chainState,
233
234
  pooledStakes: accounts[0],
234
235
  exchangeRate,
@@ -263,18 +264,14 @@ export class EarnController extends BaseController {
263
264
  * Updates the vault metadata in the controller state including APY, capacity,
264
265
  * fee percentage, total assets, and vault address.
265
266
  *
266
- * @param [chainId] - The chain id to refresh pooled staking vault metadata for (optional).
267
267
  * @returns A promise that resolves when the vault metadata has been updated
268
268
  */
269
- async refreshPooledStakingVaultMetadata(chainId = ChainId.ETHEREUM) {
270
- const chainIdToUse = isSupportedPooledStakingChain(chainId)
271
- ? chainId
272
- : ChainId.ETHEREUM;
273
- const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(chainIdToUse);
269
+ async refreshPooledStakingVaultMetadata() {
270
+ const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
271
+ const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(chainId);
274
272
  this.update((state) => {
275
- const chainState = state.pooled_staking[chainIdToUse] ??
276
- DEFAULT_POOLED_STAKING_CHAIN_STATE;
277
- state.pooled_staking[chainIdToUse] = {
273
+ const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
274
+ state.pooled_staking[chainId] = {
278
275
  ...chainState,
279
276
  vaultMetadata,
280
277
  };
@@ -284,21 +281,16 @@ export class EarnController extends BaseController {
284
281
  * Refreshes pooled staking vault daily apys for the current chain.
285
282
  * Updates the pooled staking vault daily apys controller state.
286
283
  *
287
- * @param [options] - The options for refreshing pooled staking vault daily apys.
288
- * @param [options.chainId] - The chain id to refresh pooled staking vault daily apys for (defaults to Ethereum).
289
- * @param [options.days] - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
290
- * @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').
284
+ * @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
285
+ * @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').
291
286
  * @returns A promise that resolves when the pooled staking vault daily apys have been updated.
292
287
  */
293
- async refreshPooledStakingVaultDailyApys({ chainId = ChainId.ETHEREUM, days = 365, order = 'desc', } = {}) {
294
- const chainIdToUse = isSupportedPooledStakingChain(chainId)
295
- ? chainId
296
- : ChainId.ETHEREUM;
297
- const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainIdToUse, days, order);
288
+ async refreshPooledStakingVaultDailyApys(days = 365, order = 'desc') {
289
+ const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
290
+ const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainId, days, order);
298
291
  this.update((state) => {
299
- const chainState = state.pooled_staking[chainIdToUse] ??
300
- DEFAULT_POOLED_STAKING_CHAIN_STATE;
301
- state.pooled_staking[chainIdToUse] = {
292
+ const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
293
+ state.pooled_staking[chainId] = {
302
294
  ...chainState,
303
295
  vaultDailyApys,
304
296
  };
@@ -308,18 +300,14 @@ export class EarnController extends BaseController {
308
300
  * Refreshes pooled staking vault apy averages for the current chain.
309
301
  * Updates the pooled staking vault apy averages controller state.
310
302
  *
311
- * @param [chainId] - The chain id to refresh pooled staking vault apy averages for (optional).
312
303
  * @returns A promise that resolves when the pooled staking vault apy averages have been updated.
313
304
  */
314
- async refreshPooledStakingVaultApyAverages(chainId = ChainId.ETHEREUM) {
315
- const chainIdToUse = isSupportedPooledStakingChain(chainId)
316
- ? chainId
317
- : ChainId.ETHEREUM;
318
- const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainIdToUse);
305
+ async refreshPooledStakingVaultApyAverages() {
306
+ const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
307
+ const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainId);
319
308
  this.update((state) => {
320
- const chainState = state.pooled_staking[chainIdToUse] ??
321
- DEFAULT_POOLED_STAKING_CHAIN_STATE;
322
- state.pooled_staking[chainIdToUse] = {
309
+ const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
310
+ state.pooled_staking[chainId] = {
323
311
  ...chainState,
324
312
  vaultApyAverages,
325
313
  };
@@ -338,25 +326,23 @@ export class EarnController extends BaseController {
338
326
  */
339
327
  async refreshPooledStakingData({ resetCache, address, } = {}) {
340
328
  const errors = [];
341
- for (const chainId of __classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f")) {
342
- await Promise.all([
343
- this.refreshPooledStakes({ resetCache, address, chainId }).catch((error) => {
344
- errors.push(error);
345
- }),
346
- this.refreshEarnEligibility({ address }).catch((error) => {
347
- errors.push(error);
348
- }),
349
- this.refreshPooledStakingVaultMetadata(chainId).catch((error) => {
350
- errors.push(error);
351
- }),
352
- this.refreshPooledStakingVaultDailyApys({ chainId }).catch((error) => {
353
- errors.push(error);
354
- }),
355
- this.refreshPooledStakingVaultApyAverages(chainId).catch((error) => {
356
- errors.push(error);
357
- }),
358
- ]);
359
- }
329
+ await Promise.all([
330
+ this.refreshPooledStakes({ resetCache, address }).catch((error) => {
331
+ errors.push(error);
332
+ }),
333
+ this.refreshEarnEligibility({ address }).catch((error) => {
334
+ errors.push(error);
335
+ }),
336
+ this.refreshPooledStakingVaultMetadata().catch((error) => {
337
+ errors.push(error);
338
+ }),
339
+ this.refreshPooledStakingVaultDailyApys().catch((error) => {
340
+ errors.push(error);
341
+ }),
342
+ this.refreshPooledStakingVaultApyAverages().catch((error) => {
343
+ errors.push(error);
344
+ }),
345
+ ]);
360
346
  if (errors.length > 0) {
361
347
  throw new Error(`Failed to refresh some staking data: ${errors
362
348
  .map((e) => e.message)
@@ -457,7 +443,7 @@ export class EarnController extends BaseController {
457
443
  *
458
444
  * @param options - Optional arguments
459
445
  * @param [options.address] - The address to get lending position history for (optional).
460
- * @param options.chainId - The chain id to get lending position history for.
446
+ * @param [options.chainId] - The chain id to get lending position history for (optional).
461
447
  * @param [options.positionId] - The position id to get lending position history for.
462
448
  * @param [options.marketId] - The market id to get lending position history for.
463
449
  * @param [options.marketAddress] - The market address to get lending position history for.
@@ -467,33 +453,34 @@ export class EarnController extends BaseController {
467
453
  */
468
454
  getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days = 730, }) {
469
455
  const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
470
- if (!addressToUse || !isSupportedLendingChain(chainId)) {
456
+ const chainIdToUse = chainId ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
457
+ if (!addressToUse || !isSupportedLendingChain(chainIdToUse)) {
471
458
  return [];
472
459
  }
473
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainId, protocol, marketId, marketAddress, positionId, days);
460
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainIdToUse, protocol, marketId, marketAddress, positionId, days);
474
461
  }
475
462
  /**
476
463
  * Gets the lending market daily apys and averages for the current chain.
477
464
  *
478
465
  * @param options - Optional arguments
479
- * @param options.chainId - The chain id to get lending market daily apys and averages for.
466
+ * @param [options.chainId] - The chain id to get lending market daily apys and averages for (optional).
480
467
  * @param [options.protocol] - The protocol to get lending market daily apys and averages for.
481
468
  * @param [options.marketId] - The market id to get lending market daily apys and averages for.
482
469
  * @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
483
470
  * @returns A promise that resolves when the lending market daily apys and averages have been updated
484
471
  */
485
472
  getLendingMarketDailyApysAndAverages({ chainId, protocol, marketId, days = 365, }) {
486
- if (!isSupportedLendingChain(chainId)) {
473
+ const chainIdToUse = chainId ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
474
+ if (!isSupportedLendingChain(chainIdToUse)) {
487
475
  return undefined;
488
476
  }
489
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainId, protocol, marketId, days);
477
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainIdToUse, protocol, marketId, days);
490
478
  }
491
479
  /**
492
480
  * Executes a lending deposit transaction.
493
481
  *
494
482
  * @param options - The options for the lending deposit transaction.
495
483
  * @param options.amount - The amount to deposit.
496
- * @param options.chainId - The chain ID for the lending deposit transaction.
497
484
  * @param options.protocol - The protocol of the lending market.
498
485
  * @param options.underlyingTokenAddress - The address of the underlying token.
499
486
  * @param options.gasOptions - The gas options for the transaction.
@@ -502,7 +489,7 @@ export class EarnController extends BaseController {
502
489
  * @param options.txOptions - The transaction options for the transaction.
503
490
  * @returns A promise that resolves to the transaction hash.
504
491
  */
505
- async executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
492
+ async executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
506
493
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
507
494
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeDepositTransactionData(amount, address, gasOptions);
508
495
  if (!transactionData) {
@@ -517,7 +504,7 @@ export class EarnController extends BaseController {
517
504
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
518
505
  ...transactionData,
519
506
  value: transactionData.value.toString(),
520
- chainId: toHex(chainId),
507
+ chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
521
508
  gasLimit,
522
509
  }, {
523
510
  ...txOptions,
@@ -530,7 +517,6 @@ export class EarnController extends BaseController {
530
517
  *
531
518
  * @param options - The options for the lending withdraw transaction.
532
519
  * @param options.amount - The amount to withdraw.
533
- * @param options.chainId - The chain ID for the lending withdraw transaction.
534
520
  * @param options.protocol - The protocol of the lending market.
535
521
  * @param options.underlyingTokenAddress - The address of the underlying token.
536
522
  * @param options.gasOptions - The gas options for the transaction.
@@ -539,7 +525,7 @@ export class EarnController extends BaseController {
539
525
  * @param options.txOptions - The transaction options for the transaction.
540
526
  * @returns A promise that resolves to the transaction hash.
541
527
  */
542
- async executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
528
+ async executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
543
529
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
544
530
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeWithdrawTransactionData(amount, address, gasOptions);
545
531
  if (!transactionData) {
@@ -554,7 +540,7 @@ export class EarnController extends BaseController {
554
540
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
555
541
  ...transactionData,
556
542
  value: transactionData.value.toString(),
557
- chainId: toHex(chainId),
543
+ chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
558
544
  gasLimit,
559
545
  }, {
560
546
  ...txOptions,
@@ -567,7 +553,6 @@ export class EarnController extends BaseController {
567
553
  *
568
554
  * @param options - The options for the lending token approve transaction.
569
555
  * @param options.amount - The amount to approve.
570
- * @param options.chainId - The chain ID for the lending token approve transaction.
571
556
  * @param options.protocol - The protocol of the lending market.
572
557
  * @param options.underlyingTokenAddress - The address of the underlying token.
573
558
  * @param options.gasOptions - The gas options for the transaction.
@@ -576,7 +561,7 @@ export class EarnController extends BaseController {
576
561
  * @param options.txOptions - The transaction options for the transaction.
577
562
  * @returns A promise that resolves to the transaction hash.
578
563
  */
579
- async executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }) {
564
+ async executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }) {
580
565
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
581
566
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeUnderlyingTokenApproveTransactionData(amount, address, gasOptions);
582
567
  if (!transactionData) {
@@ -591,7 +576,7 @@ export class EarnController extends BaseController {
591
576
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
592
577
  ...transactionData,
593
578
  value: transactionData.value.toString(),
594
- chainId: toHex(chainId),
579
+ chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
595
580
  gasLimit,
596
581
  }, {
597
582
  ...txOptions,
@@ -640,10 +625,13 @@ _EarnController_earnSDK = new WeakMap(), _EarnController_selectedNetworkClientId
640
625
  /**
641
626
  * Initializes the Earn SDK.
642
627
  *
643
- * @param networkClientId - The network client id to initialize the Earn SDK for.
628
+ * @param networkClientId - The network client id to initialize the Earn SDK for (optional).
644
629
  */
645
630
  async function _EarnController_initializeSDK(networkClientId) {
646
- const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
631
+ const { selectedNetworkClientId } = networkClientId
632
+ ? { selectedNetworkClientId: networkClientId }
633
+ : this.messagingSystem.call('NetworkController:getState');
634
+ const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
647
635
  if (!networkClient?.provider) {
648
636
  __classPrivateFieldSet(this, _EarnController_earnSDK, null, "f");
649
637
  return;
@@ -668,5 +656,19 @@ async function _EarnController_initializeSDK(networkClientId) {
668
656
  }
669
657
  }, _EarnController_getCurrentAccount = function _EarnController_getCurrentAccount() {
670
658
  return this.messagingSystem.call('AccountsController:getSelectedAccount');
659
+ }, _EarnController_getCurrentChainId = function _EarnController_getCurrentChainId(networkClientId) {
660
+ const networkClientIdToUse = networkClientId ??
661
+ this.messagingSystem.call('NetworkController:getState')
662
+ .selectedNetworkClientId;
663
+ const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientIdToUse);
664
+ return convertHexToDecimal(chainId);
665
+ }, _EarnController_getActivePooledStakingChainId = function _EarnController_getActivePooledStakingChainId() {
666
+ const activeChainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
667
+ if (!activeChainId ||
668
+ !__classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f").includes(toHex(activeChainId))) {
669
+ // Fallback to Ethereum Mainnet if chainId is not supported.
670
+ return convertHexToDecimal(CHAIN_IDS.MAINNET);
671
+ }
672
+ return activeChainId;
671
673
  };
672
674
  //# sourceMappingURL=EarnController.mjs.map