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