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