@metamask-previews/earn-controller 4.0.0-preview-a0e6b482 → 4.0.0-preview-defa214d
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 +90 -94
- 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 +92 -96
- 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 allow `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
|
+
|
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,30 +153,24 @@ 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
|
-
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
|
-
}
|
163
|
+
this.messagingSystem.subscribe('NetworkController:networkDidChange', (networkControllerState) => {
|
180
164
|
__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);
|
181
174
|
});
|
182
175
|
// Listen for account changes
|
183
176
|
this.messagingSystem.subscribe('AccountsController:selectedAccountChange', (account) => {
|
@@ -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,21 @@ 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
|
*
|
288
|
-
* @param
|
289
|
-
* @param
|
289
|
+
* @param [options] - The options for refreshing pooled staking vault daily apys.
|
290
|
+
* @param [options.chainId] - The chain id to refresh pooled staking vault daily apys for (defaults to Ethereum).
|
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').
|
290
293
|
* @returns A promise that resolves when the pooled staking vault daily apys have been updated.
|
291
294
|
*/
|
292
|
-
async refreshPooledStakingVaultDailyApys(days = 365, order = 'desc') {
|
293
|
-
const
|
294
|
-
|
295
|
+
async refreshPooledStakingVaultDailyApys({ chainId = stake_sdk_1.ChainId.ETHEREUM, days = 365, order = 'desc', } = {}) {
|
296
|
+
const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
|
297
|
+
? chainId
|
298
|
+
: stake_sdk_1.ChainId.ETHEREUM;
|
299
|
+
const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainIdToUse, days, order);
|
295
300
|
this.update((state) => {
|
296
|
-
const chainState = state.pooled_staking[
|
297
|
-
|
301
|
+
const chainState = state.pooled_staking[chainIdToUse] ??
|
302
|
+
exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
303
|
+
state.pooled_staking[chainIdToUse] = {
|
298
304
|
...chainState,
|
299
305
|
vaultDailyApys,
|
300
306
|
};
|
@@ -304,14 +310,18 @@ class EarnController extends base_controller_1.BaseController {
|
|
304
310
|
* Refreshes pooled staking vault apy averages for the current chain.
|
305
311
|
* Updates the pooled staking vault apy averages controller state.
|
306
312
|
*
|
313
|
+
* @param [chainId] - The chain id to refresh pooled staking vault apy averages for (optional).
|
307
314
|
* @returns A promise that resolves when the pooled staking vault apy averages have been updated.
|
308
315
|
*/
|
309
|
-
async refreshPooledStakingVaultApyAverages() {
|
310
|
-
const
|
311
|
-
|
316
|
+
async refreshPooledStakingVaultApyAverages(chainId = stake_sdk_1.ChainId.ETHEREUM) {
|
317
|
+
const chainIdToUse = (0, stake_sdk_1.isSupportedPooledStakingChain)(chainId)
|
318
|
+
? chainId
|
319
|
+
: stake_sdk_1.ChainId.ETHEREUM;
|
320
|
+
const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainIdToUse);
|
312
321
|
this.update((state) => {
|
313
|
-
const chainState = state.pooled_staking[
|
314
|
-
|
322
|
+
const chainState = state.pooled_staking[chainIdToUse] ??
|
323
|
+
exports.DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
324
|
+
state.pooled_staking[chainIdToUse] = {
|
315
325
|
...chainState,
|
316
326
|
vaultApyAverages,
|
317
327
|
};
|
@@ -330,23 +340,25 @@ class EarnController extends base_controller_1.BaseController {
|
|
330
340
|
*/
|
331
341
|
async refreshPooledStakingData({ resetCache, address, } = {}) {
|
332
342
|
const errors = [];
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
343
|
+
for (const chainId of __classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f")) {
|
344
|
+
await Promise.all([
|
345
|
+
this.refreshPooledStakes({ resetCache, address, chainId }).catch((error) => {
|
346
|
+
errors.push(error);
|
347
|
+
}),
|
348
|
+
this.refreshEarnEligibility({ address }).catch((error) => {
|
349
|
+
errors.push(error);
|
350
|
+
}),
|
351
|
+
this.refreshPooledStakingVaultMetadata(chainId).catch((error) => {
|
352
|
+
errors.push(error);
|
353
|
+
}),
|
354
|
+
this.refreshPooledStakingVaultDailyApys({ chainId }).catch((error) => {
|
355
|
+
errors.push(error);
|
356
|
+
}),
|
357
|
+
this.refreshPooledStakingVaultApyAverages(chainId).catch((error) => {
|
358
|
+
errors.push(error);
|
359
|
+
}),
|
360
|
+
]);
|
361
|
+
}
|
350
362
|
if (errors.length > 0) {
|
351
363
|
throw new Error(`Failed to refresh some staking data: ${errors
|
352
364
|
.map((e) => e.message)
|
@@ -447,7 +459,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
447
459
|
*
|
448
460
|
* @param options - Optional arguments
|
449
461
|
* @param [options.address] - The address to get lending position history for (optional).
|
450
|
-
* @param
|
462
|
+
* @param options.chainId - The chain id to get lending position history for.
|
451
463
|
* @param [options.positionId] - The position id to get lending position history for.
|
452
464
|
* @param [options.marketId] - The market id to get lending position history for.
|
453
465
|
* @param [options.marketAddress] - The market address to get lending position history for.
|
@@ -457,34 +469,33 @@ class EarnController extends base_controller_1.BaseController {
|
|
457
469
|
*/
|
458
470
|
getLendingPositionHistory({ address, chainId, positionId, marketId, marketAddress, protocol, days = 730, }) {
|
459
471
|
const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
460
|
-
|
461
|
-
if (!addressToUse || !(0, stake_sdk_1.isSupportedLendingChain)(chainIdToUse)) {
|
472
|
+
if (!addressToUse || !(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
|
462
473
|
return [];
|
463
474
|
}
|
464
|
-
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse,
|
475
|
+
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getPositionHistory(addressToUse, chainId, protocol, marketId, marketAddress, positionId, days);
|
465
476
|
}
|
466
477
|
/**
|
467
478
|
* Gets the lending market daily apys and averages for the current chain.
|
468
479
|
*
|
469
480
|
* @param options - Optional arguments
|
470
|
-
* @param
|
481
|
+
* @param options.chainId - The chain id to get lending market daily apys and averages for.
|
471
482
|
* @param [options.protocol] - The protocol to get lending market daily apys and averages for.
|
472
483
|
* @param [options.marketId] - The market id to get lending market daily apys and averages for.
|
473
484
|
* @param [options.days] - The number of days to get lending market daily apys and averages for (optional).
|
474
485
|
* @returns A promise that resolves when the lending market daily apys and averages have been updated
|
475
486
|
*/
|
476
487
|
getLendingMarketDailyApysAndAverages({ chainId, protocol, marketId, days = 365, }) {
|
477
|
-
|
478
|
-
if (!(0, stake_sdk_1.isSupportedLendingChain)(chainIdToUse)) {
|
488
|
+
if (!(0, stake_sdk_1.isSupportedLendingChain)(chainId)) {
|
479
489
|
return undefined;
|
480
490
|
}
|
481
|
-
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(
|
491
|
+
return __classPrivateFieldGet(this, _EarnController_earnApiService, "f").lending.getHistoricMarketApys(chainId, protocol, marketId, days);
|
482
492
|
}
|
483
493
|
/**
|
484
494
|
* Executes a lending deposit transaction.
|
485
495
|
*
|
486
496
|
* @param options - The options for the lending deposit transaction.
|
487
497
|
* @param options.amount - The amount to deposit.
|
498
|
+
* @param options.chainId - The chain ID for the lending deposit transaction.
|
488
499
|
* @param options.protocol - The protocol of the lending market.
|
489
500
|
* @param options.underlyingTokenAddress - The address of the underlying token.
|
490
501
|
* @param options.gasOptions - The gas options for the transaction.
|
@@ -493,7 +504,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
493
504
|
* @param options.txOptions - The transaction options for the transaction.
|
494
505
|
* @returns A promise that resolves to the transaction hash.
|
495
506
|
*/
|
496
|
-
async executeLendingDeposit({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
507
|
+
async executeLendingDeposit({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
497
508
|
const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
498
509
|
const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeDepositTransactionData(amount, address, gasOptions);
|
499
510
|
if (!transactionData) {
|
@@ -508,7 +519,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
508
519
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
509
520
|
...transactionData,
|
510
521
|
value: transactionData.value.toString(),
|
511
|
-
chainId: (0, controller_utils_1.toHex)(
|
522
|
+
chainId: (0, controller_utils_1.toHex)(chainId),
|
512
523
|
gasLimit,
|
513
524
|
}, {
|
514
525
|
...txOptions,
|
@@ -521,6 +532,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
521
532
|
*
|
522
533
|
* @param options - The options for the lending withdraw transaction.
|
523
534
|
* @param options.amount - The amount to withdraw.
|
535
|
+
* @param options.chainId - The chain ID for the lending withdraw transaction.
|
524
536
|
* @param options.protocol - The protocol of the lending market.
|
525
537
|
* @param options.underlyingTokenAddress - The address of the underlying token.
|
526
538
|
* @param options.gasOptions - The gas options for the transaction.
|
@@ -529,7 +541,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
529
541
|
* @param options.txOptions - The transaction options for the transaction.
|
530
542
|
* @returns A promise that resolves to the transaction hash.
|
531
543
|
*/
|
532
|
-
async executeLendingWithdraw({ amount, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
544
|
+
async executeLendingWithdraw({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }) {
|
533
545
|
const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
534
546
|
const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeWithdrawTransactionData(amount, address, gasOptions);
|
535
547
|
if (!transactionData) {
|
@@ -544,7 +556,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
544
556
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
545
557
|
...transactionData,
|
546
558
|
value: transactionData.value.toString(),
|
547
|
-
chainId: (0, controller_utils_1.toHex)(
|
559
|
+
chainId: (0, controller_utils_1.toHex)(chainId),
|
548
560
|
gasLimit,
|
549
561
|
}, {
|
550
562
|
...txOptions,
|
@@ -557,6 +569,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
557
569
|
*
|
558
570
|
* @param options - The options for the lending token approve transaction.
|
559
571
|
* @param options.amount - The amount to approve.
|
572
|
+
* @param options.chainId - The chain ID for the lending token approve transaction.
|
560
573
|
* @param options.protocol - The protocol of the lending market.
|
561
574
|
* @param options.underlyingTokenAddress - The address of the underlying token.
|
562
575
|
* @param options.gasOptions - The gas options for the transaction.
|
@@ -565,7 +578,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
565
578
|
* @param options.txOptions - The transaction options for the transaction.
|
566
579
|
* @returns A promise that resolves to the transaction hash.
|
567
580
|
*/
|
568
|
-
async executeLendingTokenApprove({ protocol, amount, underlyingTokenAddress, gasOptions, txOptions, }) {
|
581
|
+
async executeLendingTokenApprove({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }) {
|
569
582
|
const address = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
570
583
|
const transactionData = await __classPrivateFieldGet(this, _EarnController_earnSDK, "f")?.contracts?.lending?.[protocol]?.[underlyingTokenAddress]?.encodeUnderlyingTokenApproveTransactionData(amount, address, gasOptions);
|
571
584
|
if (!transactionData) {
|
@@ -580,7 +593,7 @@ class EarnController extends base_controller_1.BaseController {
|
|
580
593
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
581
594
|
...transactionData,
|
582
595
|
value: transactionData.value.toString(),
|
583
|
-
chainId: (0, controller_utils_1.toHex)(
|
596
|
+
chainId: (0, controller_utils_1.toHex)(chainId),
|
584
597
|
gasLimit,
|
585
598
|
}, {
|
586
599
|
...txOptions,
|
@@ -630,13 +643,10 @@ _EarnController_earnSDK = new WeakMap(), _EarnController_selectedNetworkClientId
|
|
630
643
|
/**
|
631
644
|
* Initializes the Earn SDK.
|
632
645
|
*
|
633
|
-
* @param networkClientId - The network client id to initialize the Earn SDK for
|
646
|
+
* @param networkClientId - The network client id to initialize the Earn SDK for.
|
634
647
|
*/
|
635
648
|
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);
|
649
|
+
const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
|
640
650
|
if (!networkClient?.provider) {
|
641
651
|
__classPrivateFieldSet(this, _EarnController_earnSDK, null, "f");
|
642
652
|
return;
|
@@ -661,19 +671,5 @@ async function _EarnController_initializeSDK(networkClientId) {
|
|
661
671
|
}
|
662
672
|
}, _EarnController_getCurrentAccount = function _EarnController_getCurrentAccount() {
|
663
673
|
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
674
|
};
|
679
675
|
//# sourceMappingURL=EarnController.cjs.map
|