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