@metamask-previews/earn-controller 4.0.0-preview-fed19434 → 4.0.0-preview-e0bc4b4b
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 +13 -0
- package/dist/EarnController.cjs +80 -82
- package/dist/EarnController.cjs.map +1 -1
- package/dist/EarnController.d.cts +30 -18
- package/dist/EarnController.d.cts.map +1 -1
- package/dist/EarnController.d.mts +30 -18
- package/dist/EarnController.d.mts.map +1 -1
- package/dist/EarnController.mjs +82 -84
- package/dist/EarnController.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +5 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +5 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/constants.cjs +0 -6
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -3
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -3
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs +0 -3
- package/dist/constants.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -7,6 +7,19 @@ 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:** Changed `refreshPooledStakingVaultDailyApys` to accept an options object with `chainId`, `days`, and `order` properties, where `chainId` is a new option, instead of separate parameters `days` and `order` ([#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 not allow `NetworkController:getState` ([#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
|
+
|
10
23
|
## [4.0.0]
|
11
24
|
|
12
25
|
### 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;
|
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,16 +153,12 @@ 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
163
|
this.messagingSystem.subscribe('NetworkController:stateChange', (networkControllerState) => {
|
169
164
|
if (networkControllerState.selectedNetworkClientId !==
|
@@ -222,18 +217,22 @@ class EarnController extends base_controller_1.BaseController {
|
|
222
217
|
* @param options - Optional arguments
|
223
218
|
* @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
|
224
219
|
* @param [options.address] - The address to refresh pooled stakes for (optional).
|
220
|
+
* @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
|
225
221
|
* @returns A promise that resolves when the stakes data has been updated
|
226
222
|
*/
|
227
|
-
async refreshPooledStakes({ resetCache = false, address, } = {}) {
|
223
|
+
async refreshPooledStakes({ resetCache = false, address, chainId = stake_sdk_1.ChainId.ETHEREUM, } = {}) {
|
228
224
|
const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
229
225
|
if (!addressToUse) {
|
230
226
|
return;
|
231
227
|
}
|
232
|
-
const
|
233
|
-
|
228
|
+
const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
|
229
|
+
? chainId
|
230
|
+
: stake_sdk_1.ChainId.ETHEREUM;
|
231
|
+
const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse], chainIdToUse, resetCache);
|
234
232
|
this.update((state) => {
|
235
|
-
const chainState = state.pooled_staking[
|
236
|
-
|
233
|
+
const chainState = state.pooled_staking[chainIdToUse] ??
|
234
|
+
exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
235
|
+
state.pooled_staking[chainIdToUse] = {
|
237
236
|
...chainState,
|
238
237
|
pooledStakes: accounts[0],
|
239
238
|
exchangeRate,
|
@@ -268,14 +267,18 @@ class EarnController extends base_controller_1.BaseController {
|
|
268
267
|
* Updates the vault metadata in the controller state including APY, capacity,
|
269
268
|
* fee percentage, total assets, and vault address.
|
270
269
|
*
|
270
|
+
* @param [chainId] - The chain id to refresh pooled staking vault metadata for (optional).
|
271
271
|
* @returns A promise that resolves when the vault metadata has been updated
|
272
272
|
*/
|
273
|
-
async refreshPooledStakingVaultMetadata() {
|
274
|
-
const
|
275
|
-
|
273
|
+
async refreshPooledStakingVaultMetadata(chainId = stake_sdk_1.ChainId.ETHEREUM) {
|
274
|
+
const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
|
275
|
+
? chainId
|
276
|
+
: stake_sdk_1.ChainId.ETHEREUM;
|
277
|
+
const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(chainIdToUse);
|
276
278
|
this.update((state) => {
|
277
|
-
const chainState = state.pooled_staking[
|
278
|
-
|
279
|
+
const chainState = state.pooled_staking[chainIdToUse] ??
|
280
|
+
exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
281
|
+
state.pooled_staking[chainIdToUse] = {
|
279
282
|
...chainState,
|
280
283
|
vaultMetadata,
|
281
284
|
};
|
@@ -285,16 +288,21 @@ class EarnController extends base_controller_1.BaseController {
|
|
285
288
|
* Refreshes pooled staking vault daily apys for the current chain.
|
286
289
|
* Updates the pooled staking vault daily apys controller state.
|
287
290
|
*
|
288
|
-
* @param
|
289
|
-
* @param
|
291
|
+
* @param [options] - The options for refreshing pooled staking vault daily apys.
|
292
|
+
* @param [options.chainId] - The chain id to refresh pooled staking vault daily apys for (defaults to Ethereum).
|
293
|
+
* @param [options.days] - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
|
294
|
+
* @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').
|
290
295
|
* @returns A promise that resolves when the pooled staking vault daily apys have been updated.
|
291
296
|
*/
|
292
|
-
async refreshPooledStakingVaultDailyApys(days = 365, order = 'desc') {
|
293
|
-
const
|
294
|
-
|
297
|
+
async refreshPooledStakingVaultDailyApys({ chainId = stake_sdk_1.ChainId.ETHEREUM, days = 365, order = 'desc', } = {}) {
|
298
|
+
const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
|
299
|
+
? chainId
|
300
|
+
: stake_sdk_1.ChainId.ETHEREUM;
|
301
|
+
const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainIdToUse, days, order);
|
295
302
|
this.update((state) => {
|
296
|
-
const chainState = state.pooled_staking[
|
297
|
-
|
303
|
+
const chainState = state.pooled_staking[chainIdToUse] ??
|
304
|
+
exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
305
|
+
state.pooled_staking[chainIdToUse] = {
|
298
306
|
...chainState,
|
299
307
|
vaultDailyApys,
|
300
308
|
};
|
@@ -304,14 +312,18 @@ class EarnController extends base_controller_1.BaseController {
|
|
304
312
|
* Refreshes pooled staking vault apy averages for the current chain.
|
305
313
|
* Updates the pooled staking vault apy averages controller state.
|
306
314
|
*
|
315
|
+
* @param [chainId] - The chain id to refresh pooled staking vault apy averages for (optional).
|
307
316
|
* @returns A promise that resolves when the pooled staking vault apy averages have been updated.
|
308
317
|
*/
|
309
|
-
async refreshPooledStakingVaultApyAverages() {
|
310
|
-
const
|
311
|
-
|
318
|
+
async refreshPooledStakingVaultApyAverages(chainId = stake_sdk_1.ChainId.ETHEREUM) {
|
319
|
+
const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
|
320
|
+
? chainId
|
321
|
+
: stake_sdk_1.ChainId.ETHEREUM;
|
322
|
+
const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainIdToUse);
|
312
323
|
this.update((state) => {
|
313
|
-
const chainState = state.pooled_staking[
|
314
|
-
|
324
|
+
const chainState = state.pooled_staking[chainIdToUse] ??
|
325
|
+
exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
326
|
+
state.pooled_staking[chainIdToUse] = {
|
315
327
|
...chainState,
|
316
328
|
vaultApyAverages,
|
317
329
|
};
|
@@ -330,23 +342,25 @@ class EarnController extends base_controller_1.BaseController {
|
|
330
342
|
*/
|
331
343
|
async refreshPooledStakingData({ resetCache, address, } = {}) {
|
332
344
|
const errors = [];
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
345
|
+
for (const chainId of __classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f")) {
|
346
|
+
await Promise.all([
|
347
|
+
this.refreshPooledStakes({ resetCache, address, chainId }).catch((error) => {
|
348
|
+
errors.push(error);
|
349
|
+
}),
|
350
|
+
this.refreshEarnEligibility({ address }).catch((error) => {
|
351
|
+
errors.push(error);
|
352
|
+
}),
|
353
|
+
this.refreshPooledStakingVaultMetadata(chainId).catch((error) => {
|
354
|
+
errors.push(error);
|
355
|
+
}),
|
356
|
+
this.refreshPooledStakingVaultDailyApys({ chainId }).catch((error) => {
|
357
|
+
errors.push(error);
|
358
|
+
}),
|
359
|
+
this.refreshPooledStakingVaultApyAverages(chainId).catch((error) => {
|
360
|
+
errors.push(error);
|
361
|
+
}),
|
362
|
+
]);
|
363
|
+
}
|
350
364
|
if (errors.length > 0) {
|
351
365
|
throw new Error(`Failed to refresh some staking data: ${errors
|
352
366
|
.map((e) => e.message)
|
@@ -447,7 +461,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
447
461
|
*
|
448
462
|
* @param options - Optional arguments
|
449
463
|
* @param [options.address] - The address to get lending position history for (optional).
|
450
|
-
* @param
|
464
|
+
* @param options.chainId - The chain id to get lending position history for.
|
451
465
|
* @param [options.positionId] - The position id to get lending position history for.
|
452
466
|
* @param [options.marketId] - The market id to get lending position history for.
|
453
467
|
* @param [options.marketAddress] - The market address to get lending position history for.
|
@@ -457,34 +471,33 @@ class EarnController extends base_controller_1.BaseController {
|
|
457
471
|
*/
|
458
472
|
getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days = 730, }) {
|
459
473
|
const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
460
|
-
|
461
|
-
if (!addressToUse || !(0, stake_sdk_1.isSupportedLendingChain)(chainIdToUse)) {
|
474
|
+
if (!addressToUse || !(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
|
462
475
|
return [];
|
463
476
|
}
|
464
|
-
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse,
|
477
|
+
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainId, protocol, marketId, marketAddress, positionId, days);
|
465
478
|
}
|
466
479
|
/**
|
467
480
|
* Gets the lending market daily apys and averages for the current chain.
|
468
481
|
*
|
469
482
|
* @param options - Optional arguments
|
470
|
-
* @param
|
483
|
+
* @param options.chainId - The chain id to get lending market daily apys and averages for.
|
471
484
|
* @param [options.protocol] - The protocol to get lending market daily apys and averages for.
|
472
485
|
* @param [options.marketId] - The market id to get lending market daily apys and averages for.
|
473
486
|
* @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
|
474
487
|
* @returns A promise that resolves when the lending market daily apys and averages have been updated
|
475
488
|
*/
|
476
489
|
getLendingMarketDailyApysAndAverages({ chainId, protocol, marketId, days = 365, }) {
|
477
|
-
|
478
|
-
if (!(0, stake_sdk_1.isSupportedLendingChain)(chainIdToUse)) {
|
490
|
+
if (!(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
|
479
491
|
return undefined;
|
480
492
|
}
|
481
|
-
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(
|
493
|
+
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainId, protocol, marketId, days);
|
482
494
|
}
|
483
495
|
/**
|
484
496
|
* Executes a lending deposit transaction.
|
485
497
|
*
|
486
498
|
* @param options - The options for the lending deposit transaction.
|
487
499
|
* @param options.amount - The amount to deposit.
|
500
|
+
* @param options.chainId - The chain ID for the lending deposit transaction.
|
488
501
|
* @param options.protocol - The protocol of the lending market.
|
489
502
|
* @param options.underlyingTokenAddress - The address of the underlying token.
|
490
503
|
* @param options.gasOptions - The gas options for the transaction.
|
@@ -493,7 +506,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
493
506
|
* @param options.txOptions - The transaction options for the transaction.
|
494
507
|
* @returns A promise that resolves to the transaction hash.
|
495
508
|
*/
|
496
|
-
async executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
509
|
+
async executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
497
510
|
const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
498
511
|
const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeDepositTransactionData(amount, address, gasOptions);
|
499
512
|
if (!transactionData) {
|
@@ -508,7 +521,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
508
521
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
509
522
|
...transactionData,
|
510
523
|
value: transactionData.value.toString(),
|
511
|
-
chainId: (0, controller_utils_1.toHex)(
|
524
|
+
chainId: (0, controller_utils_1.toHex)(chainId),
|
512
525
|
gasLimit,
|
513
526
|
}, {
|
514
527
|
...txOptions,
|
@@ -521,6 +534,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
521
534
|
*
|
522
535
|
* @param options - The options for the lending withdraw transaction.
|
523
536
|
* @param options.amount - The amount to withdraw.
|
537
|
+
* @param options.chainId - The chain ID for the lending withdraw transaction.
|
524
538
|
* @param options.protocol - The protocol of the lending market.
|
525
539
|
* @param options.underlyingTokenAddress - The address of the underlying token.
|
526
540
|
* @param options.gasOptions - The gas options for the transaction.
|
@@ -529,7 +543,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
529
543
|
* @param options.txOptions - The transaction options for the transaction.
|
530
544
|
* @returns A promise that resolves to the transaction hash.
|
531
545
|
*/
|
532
|
-
async executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
546
|
+
async executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
533
547
|
const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
534
548
|
const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeWithdrawTransactionData(amount, address, gasOptions);
|
535
549
|
if (!transactionData) {
|
@@ -544,7 +558,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
544
558
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
545
559
|
...transactionData,
|
546
560
|
value: transactionData.value.toString(),
|
547
|
-
chainId: (0, controller_utils_1.toHex)(
|
561
|
+
chainId: (0, controller_utils_1.toHex)(chainId),
|
548
562
|
gasLimit,
|
549
563
|
}, {
|
550
564
|
...txOptions,
|
@@ -557,6 +571,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
557
571
|
*
|
558
572
|
* @param options - The options for the lending token approve transaction.
|
559
573
|
* @param options.amount - The amount to approve.
|
574
|
+
* @param options.chainId - The chain ID for the lending token approve transaction.
|
560
575
|
* @param options.protocol - The protocol of the lending market.
|
561
576
|
* @param options.underlyingTokenAddress - The address of the underlying token.
|
562
577
|
* @param options.gasOptions - The gas options for the transaction.
|
@@ -565,7 +580,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
565
580
|
* @param options.txOptions - The transaction options for the transaction.
|
566
581
|
* @returns A promise that resolves to the transaction hash.
|
567
582
|
*/
|
568
|
-
async executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }) {
|
583
|
+
async executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }) {
|
569
584
|
const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
570
585
|
const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeUnderlyingTokenApproveTransactionData(amount, address, gasOptions);
|
571
586
|
if (!transactionData) {
|
@@ -580,7 +595,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
580
595
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
581
596
|
...transactionData,
|
582
597
|
value: transactionData.value.toString(),
|
583
|
-
chainId: (0, controller_utils_1.toHex)(
|
598
|
+
chainId: (0, controller_utils_1.toHex)(chainId),
|
584
599
|
gasLimit,
|
585
600
|
}, {
|
586
601
|
...txOptions,
|
@@ -630,13 +645,10 @@ _EarnController_earnSDK = new WeakMap(), _EarnController_selectedNetworkClientId
|
|
630
645
|
/**
|
631
646
|
* Initializes the Earn SDK.
|
632
647
|
*
|
633
|
-
* @param networkClientId - The network client id to initialize the Earn SDK for
|
648
|
+
* @param networkClientId - The network client id to initialize the Earn SDK for.
|
634
649
|
*/
|
635
650
|
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);
|
651
|
+
const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
|
640
652
|
if (!networkClient?.provider) {
|
641
653
|
__classPrivateFieldSet(this, _EarnController_earnSDK, null, "f");
|
642
654
|
return;
|
@@ -661,19 +673,5 @@ async function _EarnController_initializeSDK(networkClientId) {
|
|
661
673
|
}
|
662
674
|
}, _EarnController_getCurrentAccount = function _EarnController_getCurrentAccount() {
|
663
675
|
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
676
|
};
|
679
677
|
//# sourceMappingURL=EarnController.cjs.map
|