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