@metamask-previews/earn-controller 3.0.0-preview-91d59c3 → 3.0.0-preview-243e64f7

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,7 +1,7 @@
1
1
  import type { AccountsControllerGetSelectedAccountAction, AccountsControllerSelectedAccountChangeEvent } from "@metamask/accounts-controller";
2
- import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
2
+ import type { ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
3
3
  import { BaseController } from "@metamask/base-controller";
4
- import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
4
+ import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetSelectedNetworkClientAction, NetworkControllerNetworkDidChangeEvent, 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
7
  import type { RefreshEarnEligibilityOptions, RefreshLendingEligibilityOptions, RefreshLendingPositionsOptions, RefreshPooledStakesOptions, RefreshPooledStakingDataOptions } from "./types.mjs";
@@ -66,18 +66,10 @@ export declare const DEFAULT_POOLED_STAKING_CHAIN_STATE: {
66
66
  * @returns The default EarnController state.
67
67
  */
68
68
  export declare function getDefaultEarnControllerState(): EarnControllerState;
69
- /**
70
- * The action which can be used to retrieve the state of the EarnController.
71
- */
72
- export type EarnControllerGetStateAction = ControllerGetStateAction<typeof controllerName, EarnControllerState>;
73
- /**
74
- * All actions that EarnController registers, to be called externally.
75
- */
76
- export type EarnControllerActions = EarnControllerGetStateAction;
77
69
  /**
78
70
  * All actions that EarnController calls internally.
79
71
  */
80
- export type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | AccountsControllerGetSelectedAccountAction;
72
+ export type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetSelectedNetworkClientAction | AccountsControllerGetSelectedAccountAction;
81
73
  /**
82
74
  * The event that EarnController publishes when updating state.
83
75
  */
@@ -89,21 +81,22 @@ export type EarnControllerEvents = EarnControllerStateChangeEvent;
89
81
  /**
90
82
  * All events that EarnController subscribes to internally.
91
83
  */
92
- export type AllowedEvents = AccountsControllerSelectedAccountChangeEvent | NetworkControllerStateChangeEvent | TransactionControllerTransactionConfirmedEvent;
84
+ export type AllowedEvents = AccountsControllerSelectedAccountChangeEvent | NetworkControllerStateChangeEvent | TransactionControllerTransactionConfirmedEvent | NetworkControllerNetworkDidChangeEvent;
93
85
  /**
94
86
  * The messenger which is restricted to actions and events accessed by
95
87
  * EarnController.
96
88
  */
97
- export type EarnControllerMessenger = RestrictedMessenger<typeof controllerName, EarnControllerActions | AllowedActions, EarnControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
89
+ export type EarnControllerMessenger = RestrictedMessenger<typeof controllerName, AllowedActions, EarnControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
98
90
  /**
99
91
  * EarnController manages DeFi earning opportunities across different protocols and chains.
100
92
  */
101
93
  export declare class EarnController extends BaseController<typeof controllerName, EarnControllerState, EarnControllerMessenger> {
102
94
  #private;
103
- constructor({ messenger, state, addTransactionFn, env, }: {
95
+ constructor({ messenger, state, addTransactionFn, selectedNetworkClientId, env, }: {
104
96
  messenger: EarnControllerMessenger;
105
97
  state?: Partial<EarnControllerState>;
106
98
  addTransactionFn: typeof TransactionController.prototype.addTransaction;
99
+ selectedNetworkClientId: string;
107
100
  env?: EarnEnvironments;
108
101
  });
109
102
  /**
@@ -114,9 +107,10 @@ export declare class EarnController extends BaseController<typeof controllerName
114
107
  * @param options - Optional arguments
115
108
  * @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
116
109
  * @param [options.address] - The address to refresh pooled stakes for (optional).
110
+ * @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
117
111
  * @returns A promise that resolves when the stakes data has been updated
118
112
  */
119
- refreshPooledStakes({ resetCache, address, }?: RefreshPooledStakesOptions): Promise<void>;
113
+ refreshPooledStakes({ resetCache, address, chainId, }?: RefreshPooledStakesOptions): Promise<void>;
120
114
  /**
121
115
  * Refreshes the earn eligibility status for the current account.
122
116
  * Updates the eligibility status in the controller state based on the location and address blocklist for compliance.
@@ -133,25 +127,28 @@ export declare class EarnController extends BaseController<typeof controllerName
133
127
  * Updates the vault metadata in the controller state including APY, capacity,
134
128
  * fee percentage, total assets, and vault address.
135
129
  *
130
+ * @param chainId - The chain id to refresh pooled staking vault metadata for (optional).
136
131
  * @returns A promise that resolves when the vault metadata has been updated
137
132
  */
138
- refreshPooledStakingVaultMetadata(): Promise<void>;
133
+ refreshPooledStakingVaultMetadata(chainId?: number): Promise<void>;
139
134
  /**
140
135
  * Refreshes pooled staking vault daily apys for the current chain.
141
136
  * Updates the pooled staking vault daily apys controller state.
142
137
  *
138
+ * @param chainId - The chain id to refresh pooled staking vault daily apys for (optional).
143
139
  * @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
144
140
  * @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').
145
141
  * @returns A promise that resolves when the pooled staking vault daily apys have been updated.
146
142
  */
147
- refreshPooledStakingVaultDailyApys(days?: number, order?: 'asc' | 'desc'): Promise<void>;
143
+ refreshPooledStakingVaultDailyApys(chainId?: number, days?: number, order?: 'asc' | 'desc'): Promise<void>;
148
144
  /**
149
145
  * Refreshes pooled staking vault apy averages for the current chain.
150
146
  * Updates the pooled staking vault apy averages controller state.
151
147
  *
148
+ * @param chainId - The chain id to refresh pooled staking vault apy averages for (optional).
152
149
  * @returns A promise that resolves when the pooled staking vault apy averages have been updated.
153
150
  */
154
- refreshPooledStakingVaultApyAverages(): Promise<void>;
151
+ refreshPooledStakingVaultApyAverages(chainId?: number): Promise<void>;
155
152
  /**
156
153
  * Refreshes all pooled staking related data including stakes, eligibility, and vault data.
157
154
  * This method allows partial success, meaning some data may update while other requests fail.
@@ -203,7 +200,7 @@ export declare class EarnController extends BaseController<typeof controllerName
203
200
  *
204
201
  * @param options - Optional arguments
205
202
  * @param [options.address] - The address to get lending position history for (optional).
206
- * @param [options.chainId] - The chain id to get lending position history for (optional).
203
+ * @param [options.chainId] - The chain id to get lending position history for.
207
204
  * @param [options.positionId] - The position id to get lending position history for.
208
205
  * @param [options.marketId] - The market id to get lending position history for.
209
206
  * @param [options.marketAddress] - The market address to get lending position history for.
@@ -213,7 +210,7 @@ export declare class EarnController extends BaseController<typeof controllerName
213
210
  */
214
211
  getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days, }: {
215
212
  address?: string;
216
- chainId?: number;
213
+ chainId: number;
217
214
  positionId: string;
218
215
  marketId: string;
219
216
  marketAddress: string;
@@ -224,14 +221,14 @@ export declare class EarnController extends BaseController<typeof controllerName
224
221
  * Gets the lending market daily apys and averages for the current chain.
225
222
  *
226
223
  * @param options - Optional arguments
227
- * @param [options.chainId] - The chain id to get lending market daily apys and averages for (optional).
224
+ * @param [options.chainId] - The chain id to get lending market daily apys and averages for.
228
225
  * @param [options.protocol] - The protocol to get lending market daily apys and averages for.
229
226
  * @param [options.marketId] - The market id to get lending market daily apys and averages for.
230
227
  * @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
231
228
  * @returns A promise that resolves when the lending market daily apys and averages have been updated
232
229
  */
233
230
  getLendingMarketDailyApysAndAverages({ chainId, protocol, marketId, days, }: {
234
- chainId?: number;
231
+ chainId: number;
235
232
  protocol: string;
236
233
  marketId: string;
237
234
  days?: number;
@@ -241,6 +238,7 @@ export declare class EarnController extends BaseController<typeof controllerName
241
238
  *
242
239
  * @param options - The options for the lending deposit transaction.
243
240
  * @param options.amount - The amount to deposit.
241
+ * @param options.chainId - The chain ID for the lending deposit transaction.
244
242
  * @param options.protocol - The protocol of the lending market.
245
243
  * @param options.underlyingTokenAddress - The address of the underlying token.
246
244
  * @param options.gasOptions - The gas options for the transaction.
@@ -249,8 +247,9 @@ export declare class EarnController extends BaseController<typeof controllerName
249
247
  * @param options.txOptions - The transaction options for the transaction.
250
248
  * @returns A promise that resolves to the transaction hash.
251
249
  */
252
- executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
250
+ executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
253
251
  amount: string;
252
+ chainId: string;
254
253
  protocol: LendingMarket['protocol'];
255
254
  underlyingTokenAddress: string;
256
255
  gasOptions: {
@@ -264,6 +263,7 @@ export declare class EarnController extends BaseController<typeof controllerName
264
263
  *
265
264
  * @param options - The options for the lending withdraw transaction.
266
265
  * @param options.amount - The amount to withdraw.
266
+ * @param options.chainId - The chain ID for the lending withdraw transaction.
267
267
  * @param options.protocol - The protocol of the lending market.
268
268
  * @param options.underlyingTokenAddress - The address of the underlying token.
269
269
  * @param options.gasOptions - The gas options for the transaction.
@@ -272,8 +272,9 @@ export declare class EarnController extends BaseController<typeof controllerName
272
272
  * @param options.txOptions - The transaction options for the transaction.
273
273
  * @returns A promise that resolves to the transaction hash.
274
274
  */
275
- executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
275
+ executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
276
276
  amount: string;
277
+ chainId: string;
277
278
  protocol: LendingMarket['protocol'];
278
279
  underlyingTokenAddress: string;
279
280
  gasOptions: {
@@ -287,6 +288,7 @@ export declare class EarnController extends BaseController<typeof controllerName
287
288
  *
288
289
  * @param options - The options for the lending token approve transaction.
289
290
  * @param options.amount - The amount to approve.
291
+ * @param options.chainId - The chain ID for the lending token approve transaction.
290
292
  * @param options.protocol - The protocol of the lending market.
291
293
  * @param options.underlyingTokenAddress - The address of the underlying token.
292
294
  * @param options.gasOptions - The gas options for the transaction.
@@ -295,9 +297,10 @@ export declare class EarnController extends BaseController<typeof controllerName
295
297
  * @param options.txOptions - The transaction options for the transaction.
296
298
  * @returns A promise that resolves to the transaction hash.
297
299
  */
298
- executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }: {
300
+ executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }: {
299
301
  protocol: LendingMarket['protocol'];
300
302
  amount: string;
303
+ chainId: string;
301
304
  underlyingTokenAddress: string;
302
305
  gasOptions: {
303
306
  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,+BAA+B,EAC/B,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,EACjB,4BAA4B;AAC7B,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,8CAA8C,EAEpD,yCAAyC;AAI1C,OAAO,KAAK,EACV,6BAA6B,EAC7B,gCAAgC,EAChC,8BAA8B,EAC9B,0BAA0B,EAC1B,+BAA+B,EAChC,oBAAgB;AAEjB,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,MAAM,MAAM,kBAAkB,GAAG;IAC/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AAU,CAAC,CAAC;QACpC,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,sBAAsB,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,13 +9,12 @@ 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, _EarnController_getCurrentChainId, _EarnController_getActivePooledStakingChainId;
12
+ var _EarnController_instances, _EarnController_earnSDK, _EarnController_selectedNetworkClientId, _EarnController_earnApiService, _EarnController_addTransactionFn, _EarnController_supportedPooledStakingChains, _EarnController_env, _EarnController_initializeSDK, _EarnController_getCurrentAccount;
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 } from "@metamask/stake-sdk";
17
- import { TransactionType, CHAIN_IDS } from "@metamask/transaction-controller";
18
- import { HOODI_TESTNET_CHAIN_ID_HEX } from "./constants.mjs";
16
+ import { EarnSdk, EarnApiService, isSupportedLendingChain, EarnEnvironments, ChainId, isSupportedPooledStakingChain } from "@metamask/stake-sdk";
17
+ import { TransactionType } from "@metamask/transaction-controller";
19
18
  export const controllerName = 'EarnController';
20
19
  const stakingTransactionTypes = new Set([
21
20
  TransactionType.stakingDeposit,
@@ -128,7 +127,7 @@ export function getDefaultEarnControllerState() {
128
127
  * EarnController manages DeFi earning opportunities across different protocols and chains.
129
128
  */
130
129
  export class EarnController extends BaseController {
131
- constructor({ messenger, state = {}, addTransactionFn, env = EarnEnvironments.PROD, }) {
130
+ constructor({ messenger, state = {}, addTransactionFn, selectedNetworkClientId, env = EarnEnvironments.PROD, }) {
132
131
  super({
133
132
  name: controllerName,
134
133
  metadata: earnControllerMetadata,
@@ -150,29 +149,23 @@ export class EarnController extends BaseController {
150
149
  // temporary array of supported chains
151
150
  // TODO: remove this once we export a supported chains list from the sdk
152
151
  // from sdk or api to get lending and pooled staking chains
153
- __classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [
154
- CHAIN_IDS.MAINNET,
155
- HOODI_TESTNET_CHAIN_ID_HEX,
156
- ], "f");
152
+ __classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [ChainId.ETHEREUM, ChainId.HOODI], "f");
157
153
  __classPrivateFieldSet(this, _EarnController_addTransactionFn, addTransactionFn, "f");
158
- __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this).catch(console.error);
154
+ __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, selectedNetworkClientId, "f");
155
+ __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, selectedNetworkClientId).catch(console.error);
159
156
  this.refreshPooledStakingData().catch(console.error);
160
157
  this.refreshLendingData().catch(console.error);
161
- const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
162
- __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, selectedNetworkClientId, "f");
163
158
  // Listen for network changes
164
- this.messagingSystem.subscribe('NetworkController:stateChange', (networkControllerState) => {
165
- if (networkControllerState.selectedNetworkClientId !==
166
- __classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f")) {
167
- __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, networkControllerState.selectedNetworkClientId).catch(console.error);
168
- this.refreshPooledStakingVaultMetadata().catch(console.error);
169
- this.refreshPooledStakingVaultDailyApys().catch(console.error);
170
- this.refreshPooledStakingVaultApyAverages().catch(console.error);
171
- this.refreshPooledStakes().catch(console.error);
172
- // refresh lending data for all chains
173
- this.refreshLendingMarkets().catch(console.error);
174
- this.refreshLendingPositions().catch(console.error);
175
- }
159
+ this.messagingSystem.subscribe('NetworkController:networkDidChange', (networkControllerState) => {
160
+ __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, networkControllerState.selectedNetworkClientId).catch(console.error);
161
+ // refresh pooled staking data
162
+ this.refreshPooledStakingVaultMetadata().catch(console.error);
163
+ this.refreshPooledStakingVaultDailyApys().catch(console.error);
164
+ this.refreshPooledStakingVaultApyAverages().catch(console.error);
165
+ this.refreshPooledStakes().catch(console.error);
166
+ // refresh lending data for all chains
167
+ this.refreshLendingMarkets().catch(console.error);
168
+ this.refreshLendingPositions().catch(console.error);
176
169
  __classPrivateFieldSet(this, _EarnController_selectedNetworkClientId, networkControllerState.selectedNetworkClientId, "f");
177
170
  });
178
171
  // Listen for account changes
@@ -218,18 +211,22 @@ export class EarnController extends BaseController {
218
211
  * @param options - Optional arguments
219
212
  * @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
220
213
  * @param [options.address] - The address to refresh pooled stakes for (optional).
214
+ * @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
221
215
  * @returns A promise that resolves when the stakes data has been updated
222
216
  */
223
- async refreshPooledStakes({ resetCache = false, address, } = {}) {
217
+ async refreshPooledStakes({ resetCache = false, address, chainId = ChainId.ETHEREUM, } = {}) {
224
218
  const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
225
219
  if (!addressToUse) {
226
220
  return;
227
221
  }
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);
222
+ const chainIdToUse = isSupportedPooledStakingChain(chainId)
223
+ ? chainId
224
+ : ChainId.ETHEREUM;
225
+ const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse], chainIdToUse, resetCache);
230
226
  this.update((state) => {
231
- const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
232
- state.pooled_staking[chainId] = {
227
+ const chainState = state.pooled_staking[chainIdToUse] ??
228
+ DEFAULT_POOLED_STAKING_CHAIN_STATE;
229
+ state.pooled_staking[chainIdToUse] = {
233
230
  ...chainState,
234
231
  pooledStakes: accounts[0],
235
232
  exchangeRate,
@@ -264,14 +261,18 @@ export class EarnController extends BaseController {
264
261
  * Updates the vault metadata in the controller state including APY, capacity,
265
262
  * fee percentage, total assets, and vault address.
266
263
  *
264
+ * @param chainId - The chain id to refresh pooled staking vault metadata for (optional).
267
265
  * @returns A promise that resolves when the vault metadata has been updated
268
266
  */
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);
267
+ async refreshPooledStakingVaultMetadata(chainId = ChainId.ETHEREUM) {
268
+ const chainIdToUse = isSupportedPooledStakingChain(chainId)
269
+ ? chainId
270
+ : ChainId.ETHEREUM;
271
+ const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(chainIdToUse);
272
272
  this.update((state) => {
273
- const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
274
- state.pooled_staking[chainId] = {
273
+ const chainState = state.pooled_staking[chainIdToUse] ??
274
+ DEFAULT_POOLED_STAKING_CHAIN_STATE;
275
+ state.pooled_staking[chainIdToUse] = {
275
276
  ...chainState,
276
277
  vaultMetadata,
277
278
  };
@@ -281,16 +282,20 @@ export class EarnController extends BaseController {
281
282
  * Refreshes pooled staking vault daily apys for the current chain.
282
283
  * Updates the pooled staking vault daily apys controller state.
283
284
  *
285
+ * @param chainId - The chain id to refresh pooled staking vault daily apys for (optional).
284
286
  * @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
285
287
  * @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').
286
288
  * @returns A promise that resolves when the pooled staking vault daily apys have been updated.
287
289
  */
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);
290
+ async refreshPooledStakingVaultDailyApys(chainId = ChainId.ETHEREUM, days = 365, order = 'desc') {
291
+ const chainIdToUse = isSupportedPooledStakingChain(chainId)
292
+ ? chainId
293
+ : ChainId.ETHEREUM;
294
+ const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainIdToUse, days, order);
291
295
  this.update((state) => {
292
- const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
293
- state.pooled_staking[chainId] = {
296
+ const chainState = state.pooled_staking[chainIdToUse] ??
297
+ DEFAULT_POOLED_STAKING_CHAIN_STATE;
298
+ state.pooled_staking[chainIdToUse] = {
294
299
  ...chainState,
295
300
  vaultDailyApys,
296
301
  };
@@ -300,14 +305,18 @@ export class EarnController extends BaseController {
300
305
  * Refreshes pooled staking vault apy averages for the current chain.
301
306
  * Updates the pooled staking vault apy averages controller state.
302
307
  *
308
+ * @param chainId - The chain id to refresh pooled staking vault apy averages for (optional).
303
309
  * @returns A promise that resolves when the pooled staking vault apy averages have been updated.
304
310
  */
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);
311
+ async refreshPooledStakingVaultApyAverages(chainId = ChainId.ETHEREUM) {
312
+ const chainIdToUse = isSupportedPooledStakingChain(chainId)
313
+ ? chainId
314
+ : ChainId.ETHEREUM;
315
+ const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainIdToUse);
308
316
  this.update((state) => {
309
- const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
310
- state.pooled_staking[chainId] = {
317
+ const chainState = state.pooled_staking[chainIdToUse] ??
318
+ DEFAULT_POOLED_STAKING_CHAIN_STATE;
319
+ state.pooled_staking[chainIdToUse] = {
311
320
  ...chainState,
312
321
  vaultApyAverages,
313
322
  };
@@ -326,23 +335,25 @@ export class EarnController extends BaseController {
326
335
  */
327
336
  async refreshPooledStakingData({ resetCache, address, } = {}) {
328
337
  const errors = [];
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
- ]);
338
+ for (const chainId of __classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f")) {
339
+ await Promise.all([
340
+ this.refreshPooledStakes({ resetCache, address, chainId }).catch((error) => {
341
+ errors.push(error);
342
+ }),
343
+ this.refreshEarnEligibility({ address }).catch((error) => {
344
+ errors.push(error);
345
+ }),
346
+ this.refreshPooledStakingVaultMetadata(chainId).catch((error) => {
347
+ errors.push(error);
348
+ }),
349
+ this.refreshPooledStakingVaultDailyApys(chainId).catch((error) => {
350
+ errors.push(error);
351
+ }),
352
+ this.refreshPooledStakingVaultApyAverages(chainId).catch((error) => {
353
+ errors.push(error);
354
+ }),
355
+ ]);
356
+ }
346
357
  if (errors.length > 0) {
347
358
  throw new Error(`Failed to refresh some staking data: ${errors
348
359
  .map((e) => e.message)
@@ -443,7 +454,7 @@ export class EarnController extends BaseController {
443
454
  *
444
455
  * @param options - Optional arguments
445
456
  * @param [options.address] - The address to get lending position history for (optional).
446
- * @param [options.chainId] - The chain id to get lending position history for (optional).
457
+ * @param [options.chainId] - The chain id to get lending position history for.
447
458
  * @param [options.positionId] - The position id to get lending position history for.
448
459
  * @param [options.marketId] - The market id to get lending position history for.
449
460
  * @param [options.marketAddress] - The market address to get lending position history for.
@@ -453,34 +464,33 @@ export class EarnController extends BaseController {
453
464
  */
454
465
  getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days = 730, }) {
455
466
  const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
456
- const chainIdToUse = chainId ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
457
- if (!addressToUse || !isSupportedLendingChain(chainIdToUse)) {
467
+ if (!addressToUse || !isSupportedLendingChain(chainId)) {
458
468
  return [];
459
469
  }
460
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainIdToUse, protocol, marketId, marketAddress, positionId, days);
470
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainId, protocol, marketId, marketAddress, positionId, days);
461
471
  }
462
472
  /**
463
473
  * Gets the lending market daily apys and averages for the current chain.
464
474
  *
465
475
  * @param options - Optional arguments
466
- * @param [options.chainId] - The chain id to get lending market daily apys and averages for (optional).
476
+ * @param [options.chainId] - The chain id to get lending market daily apys and averages for.
467
477
  * @param [options.protocol] - The protocol to get lending market daily apys and averages for.
468
478
  * @param [options.marketId] - The market id to get lending market daily apys and averages for.
469
479
  * @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
470
480
  * @returns A promise that resolves when the lending market daily apys and averages have been updated
471
481
  */
472
482
  getLendingMarketDailyApysAndAverages({ chainId, protocol, marketId, days = 365, }) {
473
- const chainIdToUse = chainId ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
474
- if (!isSupportedLendingChain(chainIdToUse)) {
483
+ if (!isSupportedLendingChain(chainId)) {
475
484
  return undefined;
476
485
  }
477
- return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainIdToUse, protocol, marketId, days);
486
+ return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainId, protocol, marketId, days);
478
487
  }
479
488
  /**
480
489
  * Executes a lending deposit transaction.
481
490
  *
482
491
  * @param options - The options for the lending deposit transaction.
483
492
  * @param options.amount - The amount to deposit.
493
+ * @param options.chainId - The chain ID for the lending deposit transaction.
484
494
  * @param options.protocol - The protocol of the lending market.
485
495
  * @param options.underlyingTokenAddress - The address of the underlying token.
486
496
  * @param options.gasOptions - The gas options for the transaction.
@@ -489,7 +499,7 @@ export class EarnController extends BaseController {
489
499
  * @param options.txOptions - The transaction options for the transaction.
490
500
  * @returns A promise that resolves to the transaction hash.
491
501
  */
492
- async executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
502
+ async executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
493
503
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
494
504
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeDepositTransactionData(amount, address, gasOptions);
495
505
  if (!transactionData) {
@@ -504,7 +514,7 @@ export class EarnController extends BaseController {
504
514
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
505
515
  ...transactionData,
506
516
  value: transactionData.value.toString(),
507
- chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
517
+ chainId: toHex(chainId),
508
518
  gasLimit,
509
519
  }, {
510
520
  ...txOptions,
@@ -517,6 +527,7 @@ export class EarnController extends BaseController {
517
527
  *
518
528
  * @param options - The options for the lending withdraw transaction.
519
529
  * @param options.amount - The amount to withdraw.
530
+ * @param options.chainId - The chain ID for the lending withdraw transaction.
520
531
  * @param options.protocol - The protocol of the lending market.
521
532
  * @param options.underlyingTokenAddress - The address of the underlying token.
522
533
  * @param options.gasOptions - The gas options for the transaction.
@@ -525,7 +536,7 @@ export class EarnController extends BaseController {
525
536
  * @param options.txOptions - The transaction options for the transaction.
526
537
  * @returns A promise that resolves to the transaction hash.
527
538
  */
528
- async executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
539
+ async executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
529
540
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
530
541
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeWithdrawTransactionData(amount, address, gasOptions);
531
542
  if (!transactionData) {
@@ -540,7 +551,7 @@ export class EarnController extends BaseController {
540
551
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
541
552
  ...transactionData,
542
553
  value: transactionData.value.toString(),
543
- chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
554
+ chainId: toHex(chainId),
544
555
  gasLimit,
545
556
  }, {
546
557
  ...txOptions,
@@ -553,6 +564,7 @@ export class EarnController extends BaseController {
553
564
  *
554
565
  * @param options - The options for the lending token approve transaction.
555
566
  * @param options.amount - The amount to approve.
567
+ * @param options.chainId - The chain ID for the lending token approve transaction.
556
568
  * @param options.protocol - The protocol of the lending market.
557
569
  * @param options.underlyingTokenAddress - The address of the underlying token.
558
570
  * @param options.gasOptions - The gas options for the transaction.
@@ -561,7 +573,7 @@ export class EarnController extends BaseController {
561
573
  * @param options.txOptions - The transaction options for the transaction.
562
574
  * @returns A promise that resolves to the transaction hash.
563
575
  */
564
- async executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }) {
576
+ async executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }) {
565
577
  const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
566
578
  const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeUnderlyingTokenApproveTransactionData(amount, address, gasOptions);
567
579
  if (!transactionData) {
@@ -576,7 +588,7 @@ export class EarnController extends BaseController {
576
588
  const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
577
589
  ...transactionData,
578
590
  value: transactionData.value.toString(),
579
- chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
591
+ chainId: toHex(chainId),
580
592
  gasLimit,
581
593
  }, {
582
594
  ...txOptions,
@@ -625,13 +637,10 @@ _EarnController_earnSDK = new WeakMap(), _EarnController_selectedNetworkClientId
625
637
  /**
626
638
  * Initializes the Earn SDK.
627
639
  *
628
- * @param networkClientId - The network client id to initialize the Earn SDK for (optional).
640
+ * @param networkClientId - The network client id to initialize the Earn SDK for.
629
641
  */
630
642
  async function _EarnController_initializeSDK(networkClientId) {
631
- const { selectedNetworkClientId } = networkClientId
632
- ? { selectedNetworkClientId: networkClientId }
633
- : this.messagingSystem.call('NetworkController:getState');
634
- const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
643
+ const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
635
644
  if (!networkClient?.provider) {
636
645
  __classPrivateFieldSet(this, _EarnController_earnSDK, null, "f");
637
646
  return;
@@ -656,19 +665,5 @@ async function _EarnController_initializeSDK(networkClientId) {
656
665
  }
657
666
  }, _EarnController_getCurrentAccount = function _EarnController_getCurrentAccount() {
658
667
  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;
673
668
  };
674
669
  //# sourceMappingURL=EarnController.mjs.map