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