@metamask/earn-controller 2.0.0 → 3.0.0
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 +19 -1
- package/dist/EarnController.cjs +73 -64
- package/dist/EarnController.cjs.map +1 -1
- package/dist/EarnController.d.cts +10 -12
- package/dist/EarnController.d.cts.map +1 -1
- package/dist/EarnController.d.mts +10 -12
- package/dist/EarnController.d.mts.map +1 -1
- package/dist/EarnController.mjs +75 -66
- 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 +1 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -4,7 +4,7 @@ import { BaseController } from "@metamask/base-controller";
|
|
|
4
4
|
import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
5
5
|
import { type LendingMarket, type PooledStake, type VaultData, type VaultDailyApy, type VaultApyAverages, type LendingPosition, type GasLimitParams, type HistoricLendingMarketApys, EarnEnvironments } from "@metamask/stake-sdk";
|
|
6
6
|
import { type TransactionController, type TransactionControllerTransactionConfirmedEvent } from "@metamask/transaction-controller";
|
|
7
|
-
import type { RefreshLendingEligibilityOptions, RefreshLendingPositionsOptions, RefreshPooledStakesOptions, RefreshPooledStakingDataOptions
|
|
7
|
+
import type { RefreshEarnEligibilityOptions, RefreshLendingEligibilityOptions, RefreshLendingPositionsOptions, RefreshPooledStakesOptions, RefreshPooledStakingDataOptions } from "./types.cjs";
|
|
8
8
|
export declare const controllerName = "EarnController";
|
|
9
9
|
export type PooledStakingState = {
|
|
10
10
|
[chainId: number]: {
|
|
@@ -114,46 +114,44 @@ export declare class EarnController extends BaseController<typeof controllerName
|
|
|
114
114
|
* @param options - Optional arguments
|
|
115
115
|
* @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
|
|
116
116
|
* @param [options.address] - The address to refresh pooled stakes for (optional).
|
|
117
|
-
* @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
|
|
118
117
|
* @returns A promise that resolves when the stakes data has been updated
|
|
119
118
|
*/
|
|
120
|
-
refreshPooledStakes({ resetCache, address,
|
|
119
|
+
refreshPooledStakes({ resetCache, address, }?: RefreshPooledStakesOptions): Promise<void>;
|
|
121
120
|
/**
|
|
122
|
-
* Refreshes the
|
|
121
|
+
* Refreshes the earn eligibility status for the current account.
|
|
123
122
|
* Updates the eligibility status in the controller state based on the location and address blocklist for compliance.
|
|
124
123
|
*
|
|
124
|
+
* Note: Pooled-staking and Lending used the same result since there isn't a need to split these up right now.
|
|
125
|
+
*
|
|
125
126
|
* @param options - Optional arguments
|
|
126
|
-
* @param [options.address] - Address to refresh
|
|
127
|
+
* @param [options.address] - Address to refresh earn eligibility for (optional).
|
|
127
128
|
* @returns A promise that resolves when the eligibility status has been updated
|
|
128
129
|
*/
|
|
129
|
-
|
|
130
|
+
refreshEarnEligibility({ address, }?: RefreshEarnEligibilityOptions): Promise<void>;
|
|
130
131
|
/**
|
|
131
132
|
* Refreshes pooled staking vault metadata for the current chain.
|
|
132
133
|
* Updates the vault metadata in the controller state including APY, capacity,
|
|
133
134
|
* fee percentage, total assets, and vault address.
|
|
134
135
|
*
|
|
135
|
-
* @param chainId - The chain id to refresh pooled staking vault metadata for (optional).
|
|
136
136
|
* @returns A promise that resolves when the vault metadata has been updated
|
|
137
137
|
*/
|
|
138
|
-
refreshPooledStakingVaultMetadata(
|
|
138
|
+
refreshPooledStakingVaultMetadata(): Promise<void>;
|
|
139
139
|
/**
|
|
140
140
|
* Refreshes pooled staking vault daily apys for the current chain.
|
|
141
141
|
* Updates the pooled staking vault daily apys controller state.
|
|
142
142
|
*
|
|
143
|
-
* @param chainId - The chain id to refresh pooled staking vault daily apys for (optional).
|
|
144
143
|
* @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
|
|
145
144
|
* @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').
|
|
146
145
|
* @returns A promise that resolves when the pooled staking vault daily apys have been updated.
|
|
147
146
|
*/
|
|
148
|
-
refreshPooledStakingVaultDailyApys(
|
|
147
|
+
refreshPooledStakingVaultDailyApys(days?: number, order?: 'asc' | 'desc'): Promise<void>;
|
|
149
148
|
/**
|
|
150
149
|
* Refreshes pooled staking vault apy averages for the current chain.
|
|
151
150
|
* Updates the pooled staking vault apy averages controller state.
|
|
152
151
|
*
|
|
153
|
-
* @param chainId - The chain id to refresh pooled staking vault apy averages for (optional).
|
|
154
152
|
* @returns A promise that resolves when the pooled staking vault apy averages have been updated.
|
|
155
153
|
*/
|
|
156
|
-
refreshPooledStakingVaultApyAverages(
|
|
154
|
+
refreshPooledStakingVaultApyAverages(): Promise<void>;
|
|
157
155
|
/**
|
|
158
156
|
* Refreshes all pooled staking related data including stakes, eligibility, and vault data.
|
|
159
157
|
* This method allows partial success, meaning some data may update while other requests fail.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EarnController.d.cts","sourceRoot":"","sources":["../src/EarnController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0CAA0C,EAC1C,4CAA4C,EAC7C,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAC/B,iCAAiC,EAClC,qCAAqC;A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Aa,CAAC,UAAU,CAAC,EACnC,sBAAsB,EAAE,MAAM;CAWjC"}
|
|
@@ -4,7 +4,7 @@ import { BaseController } from "@metamask/base-controller";
|
|
|
4
4
|
import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
5
5
|
import { type LendingMarket, type PooledStake, type VaultData, type VaultDailyApy, type VaultApyAverages, type LendingPosition, type GasLimitParams, type HistoricLendingMarketApys, EarnEnvironments } from "@metamask/stake-sdk";
|
|
6
6
|
import { type TransactionController, type TransactionControllerTransactionConfirmedEvent } from "@metamask/transaction-controller";
|
|
7
|
-
import type { RefreshLendingEligibilityOptions, RefreshLendingPositionsOptions, RefreshPooledStakesOptions, RefreshPooledStakingDataOptions
|
|
7
|
+
import type { RefreshEarnEligibilityOptions, RefreshLendingEligibilityOptions, RefreshLendingPositionsOptions, RefreshPooledStakesOptions, RefreshPooledStakingDataOptions } from "./types.mjs";
|
|
8
8
|
export declare const controllerName = "EarnController";
|
|
9
9
|
export type PooledStakingState = {
|
|
10
10
|
[chainId: number]: {
|
|
@@ -114,46 +114,44 @@ export declare class EarnController extends BaseController<typeof controllerName
|
|
|
114
114
|
* @param options - Optional arguments
|
|
115
115
|
* @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
|
|
116
116
|
* @param [options.address] - The address to refresh pooled stakes for (optional).
|
|
117
|
-
* @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
|
|
118
117
|
* @returns A promise that resolves when the stakes data has been updated
|
|
119
118
|
*/
|
|
120
|
-
refreshPooledStakes({ resetCache, address,
|
|
119
|
+
refreshPooledStakes({ resetCache, address, }?: RefreshPooledStakesOptions): Promise<void>;
|
|
121
120
|
/**
|
|
122
|
-
* Refreshes the
|
|
121
|
+
* Refreshes the earn eligibility status for the current account.
|
|
123
122
|
* Updates the eligibility status in the controller state based on the location and address blocklist for compliance.
|
|
124
123
|
*
|
|
124
|
+
* Note: Pooled-staking and Lending used the same result since there isn't a need to split these up right now.
|
|
125
|
+
*
|
|
125
126
|
* @param options - Optional arguments
|
|
126
|
-
* @param [options.address] - Address to refresh
|
|
127
|
+
* @param [options.address] - Address to refresh earn eligibility for (optional).
|
|
127
128
|
* @returns A promise that resolves when the eligibility status has been updated
|
|
128
129
|
*/
|
|
129
|
-
|
|
130
|
+
refreshEarnEligibility({ address, }?: RefreshEarnEligibilityOptions): Promise<void>;
|
|
130
131
|
/**
|
|
131
132
|
* Refreshes pooled staking vault metadata for the current chain.
|
|
132
133
|
* Updates the vault metadata in the controller state including APY, capacity,
|
|
133
134
|
* fee percentage, total assets, and vault address.
|
|
134
135
|
*
|
|
135
|
-
* @param chainId - The chain id to refresh pooled staking vault metadata for (optional).
|
|
136
136
|
* @returns A promise that resolves when the vault metadata has been updated
|
|
137
137
|
*/
|
|
138
|
-
refreshPooledStakingVaultMetadata(
|
|
138
|
+
refreshPooledStakingVaultMetadata(): Promise<void>;
|
|
139
139
|
/**
|
|
140
140
|
* Refreshes pooled staking vault daily apys for the current chain.
|
|
141
141
|
* Updates the pooled staking vault daily apys controller state.
|
|
142
142
|
*
|
|
143
|
-
* @param chainId - The chain id to refresh pooled staking vault daily apys for (optional).
|
|
144
143
|
* @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
|
|
145
144
|
* @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').
|
|
146
145
|
* @returns A promise that resolves when the pooled staking vault daily apys have been updated.
|
|
147
146
|
*/
|
|
148
|
-
refreshPooledStakingVaultDailyApys(
|
|
147
|
+
refreshPooledStakingVaultDailyApys(days?: number, order?: 'asc' | 'desc'): Promise<void>;
|
|
149
148
|
/**
|
|
150
149
|
* Refreshes pooled staking vault apy averages for the current chain.
|
|
151
150
|
* Updates the pooled staking vault apy averages controller state.
|
|
152
151
|
*
|
|
153
|
-
* @param chainId - The chain id to refresh pooled staking vault apy averages for (optional).
|
|
154
152
|
* @returns A promise that resolves when the pooled staking vault apy averages have been updated.
|
|
155
153
|
*/
|
|
156
|
-
refreshPooledStakingVaultApyAverages(
|
|
154
|
+
refreshPooledStakingVaultApyAverages(): Promise<void>;
|
|
157
155
|
/**
|
|
158
156
|
* Refreshes all pooled staking related data including stakes, eligibility, and vault data.
|
|
159
157
|
* This method allows partial success, meaning some data may update while other requests fail.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EarnController.d.mts","sourceRoot":"","sources":["../src/EarnController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0CAA0C,EAC1C,4CAA4C,EAC7C,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAC/B,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"EarnController.d.mts","sourceRoot":"","sources":["../src/EarnController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0CAA0C,EAC1C,4CAA4C,EAC7C,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAC/B,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,WAAW,EAEhB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,gBAAgB,EACjB,4BAA4B;AAC7B,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,8CAA8C,EAEpD,yCAAyC;AAI1C,OAAO,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ACtB,UAAU,EACV,SAAS,GACV,EAAE;QACD,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;QACpC,MAAM,EAAE,MAAM,CAAC;QACf,sBAAsB,EAAE,MAAM,CAAC;QAC/B,UAAU,EAAE;YACV,QAAQ,CAAC,EAAE,cAAc,CAAC;YAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;SACvB,CAAC;QACF,SAAS,EAAE,UAAU,CACnB,OAAO,qBAAqB,CAAC,SAAS,CAAC,cAAc,CACtD,CAAC,CAAC,CAAC,CAAC;KACN;IAuCD;;;;;;OAMG;IACG,wBAAwB,CAC5B,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,sBAAsB,EAAE,MAAM;IAYhC;;;;;;OAMG;IACG,0BAA0B,CAC9B,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,sBAAsB,EAAE,MAAM;IAYhC;;;;;;OAMG;IACG,yBAAyB,CAC7B,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,sBAAsB,EAAE,MAAM;CAWjC"}
|
package/dist/EarnController.mjs
CHANGED
|
@@ -9,12 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _EarnController_instances, _EarnController_earnSDK, _EarnController_selectedNetworkClientId, _EarnController_earnApiService, _EarnController_addTransactionFn, _EarnController_supportedPooledStakingChains, _EarnController_env, _EarnController_initializeSDK, _EarnController_getCurrentAccount, _EarnController_getCurrentChainId;
|
|
12
|
+
var _EarnController_instances, _EarnController_earnSDK, _EarnController_selectedNetworkClientId, _EarnController_earnApiService, _EarnController_addTransactionFn, _EarnController_supportedPooledStakingChains, _EarnController_env, _EarnController_initializeSDK, _EarnController_getCurrentAccount, _EarnController_getCurrentChainId, _EarnController_getActivePooledStakingChainId;
|
|
13
13
|
import { Web3Provider } from "@ethersproject/providers";
|
|
14
14
|
import { BaseController } from "@metamask/base-controller";
|
|
15
15
|
import { convertHexToDecimal, toHex } from "@metamask/controller-utils";
|
|
16
|
-
import { EarnSdk, EarnApiService,
|
|
17
|
-
import { TransactionType } from "@metamask/transaction-controller";
|
|
16
|
+
import { EarnSdk, EarnApiService, isSupportedLendingChain, EarnEnvironments } from "@metamask/stake-sdk";
|
|
17
|
+
import { TransactionType, CHAIN_IDS } from "@metamask/transaction-controller";
|
|
18
|
+
import { HOODI_TESTNET_CHAIN_ID_HEX } from "./constants.mjs";
|
|
18
19
|
export const controllerName = 'EarnController';
|
|
19
20
|
const stakingTransactionTypes = new Set([
|
|
20
21
|
TransactionType.stakingDeposit,
|
|
@@ -149,7 +150,10 @@ export class EarnController extends BaseController {
|
|
|
149
150
|
// temporary array of supported chains
|
|
150
151
|
// TODO: remove this once we export a supported chains list from the sdk
|
|
151
152
|
// from sdk or api to get lending and pooled staking chains
|
|
152
|
-
__classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [
|
|
153
|
+
__classPrivateFieldSet(this, _EarnController_supportedPooledStakingChains, [
|
|
154
|
+
CHAIN_IDS.MAINNET,
|
|
155
|
+
HOODI_TESTNET_CHAIN_ID_HEX,
|
|
156
|
+
], "f");
|
|
153
157
|
__classPrivateFieldSet(this, _EarnController_addTransactionFn, addTransactionFn, "f");
|
|
154
158
|
__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this).catch(console.error);
|
|
155
159
|
this.refreshPooledStakingData().catch(console.error);
|
|
@@ -160,15 +164,11 @@ export class EarnController extends BaseController {
|
|
|
160
164
|
this.messagingSystem.subscribe('NetworkController:stateChange', (networkControllerState) => {
|
|
161
165
|
if (networkControllerState.selectedNetworkClientId !==
|
|
162
166
|
__classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f")) {
|
|
163
|
-
const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this, networkControllerState.selectedNetworkClientId);
|
|
164
167
|
__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_initializeSDK).call(this, networkControllerState.selectedNetworkClientId).catch(console.error);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.refreshPooledStakingVaultApyAverages(chainId).catch(console.error);
|
|
170
|
-
this.refreshPooledStakes({ chainId }).catch(console.error);
|
|
171
|
-
}
|
|
168
|
+
this.refreshPooledStakingVaultMetadata().catch(console.error);
|
|
169
|
+
this.refreshPooledStakingVaultDailyApys().catch(console.error);
|
|
170
|
+
this.refreshPooledStakingVaultApyAverages().catch(console.error);
|
|
171
|
+
this.refreshPooledStakes().catch(console.error);
|
|
172
172
|
// refresh lending data for all chains
|
|
173
173
|
this.refreshLendingMarkets().catch(console.error);
|
|
174
174
|
this.refreshLendingPositions().catch(console.error);
|
|
@@ -185,7 +185,7 @@ export class EarnController extends BaseController {
|
|
|
185
185
|
*/
|
|
186
186
|
// TODO: temp solution, this will refresh lending eligibility also
|
|
187
187
|
// we could have a more general check, as what is happening is a compliance address check
|
|
188
|
-
this.
|
|
188
|
+
this.refreshEarnEligibility({ address }).catch(console.error);
|
|
189
189
|
this.refreshPooledStakes({ address }).catch(console.error);
|
|
190
190
|
this.refreshLendingPositions({ address }).catch(console.error);
|
|
191
191
|
});
|
|
@@ -218,20 +218,18 @@ export class EarnController extends BaseController {
|
|
|
218
218
|
* @param options - Optional arguments
|
|
219
219
|
* @param [options.resetCache] - Control whether the BE cache should be invalidated (optional).
|
|
220
220
|
* @param [options.address] - The address to refresh pooled stakes for (optional).
|
|
221
|
-
* @param [options.chainId] - The chain id to refresh pooled stakes for (optional).
|
|
222
221
|
* @returns A promise that resolves when the stakes data has been updated
|
|
223
222
|
*/
|
|
224
|
-
async refreshPooledStakes({ resetCache = false, address,
|
|
223
|
+
async refreshPooledStakes({ resetCache = false, address, } = {}) {
|
|
225
224
|
const addressToUse = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
|
226
225
|
if (!addressToUse) {
|
|
227
226
|
return;
|
|
228
227
|
}
|
|
229
|
-
const
|
|
230
|
-
const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse],
|
|
228
|
+
const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
|
|
229
|
+
const { accounts, exchangeRate } = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getPooledStakes([addressToUse], chainId, resetCache);
|
|
231
230
|
this.update((state) => {
|
|
232
|
-
const chainState = state.pooled_staking[
|
|
233
|
-
|
|
234
|
-
state.pooled_staking[chainIdToUse] = {
|
|
231
|
+
const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
|
232
|
+
state.pooled_staking[chainId] = {
|
|
235
233
|
...chainState,
|
|
236
234
|
pooledStakes: accounts[0],
|
|
237
235
|
exchangeRate,
|
|
@@ -239,14 +237,16 @@ export class EarnController extends BaseController {
|
|
|
239
237
|
});
|
|
240
238
|
}
|
|
241
239
|
/**
|
|
242
|
-
* Refreshes the
|
|
240
|
+
* Refreshes the earn eligibility status for the current account.
|
|
243
241
|
* Updates the eligibility status in the controller state based on the location and address blocklist for compliance.
|
|
244
242
|
*
|
|
243
|
+
* Note: Pooled-staking and Lending used the same result since there isn't a need to split these up right now.
|
|
244
|
+
*
|
|
245
245
|
* @param options - Optional arguments
|
|
246
|
-
* @param [options.address] - Address to refresh
|
|
246
|
+
* @param [options.address] - Address to refresh earn eligibility for (optional).
|
|
247
247
|
* @returns A promise that resolves when the eligibility status has been updated
|
|
248
248
|
*/
|
|
249
|
-
async
|
|
249
|
+
async refreshEarnEligibility({ address, } = {}) {
|
|
250
250
|
const addressToCheck = address ?? __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentAccount).call(this)?.address;
|
|
251
251
|
if (!addressToCheck) {
|
|
252
252
|
return;
|
|
@@ -264,16 +264,14 @@ export class EarnController extends BaseController {
|
|
|
264
264
|
* Updates the vault metadata in the controller state including APY, capacity,
|
|
265
265
|
* fee percentage, total assets, and vault address.
|
|
266
266
|
*
|
|
267
|
-
* @param chainId - The chain id to refresh pooled staking vault metadata for (optional).
|
|
268
267
|
* @returns A promise that resolves when the vault metadata has been updated
|
|
269
268
|
*/
|
|
270
|
-
async refreshPooledStakingVaultMetadata(
|
|
271
|
-
const
|
|
272
|
-
const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(
|
|
269
|
+
async refreshPooledStakingVaultMetadata() {
|
|
270
|
+
const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
|
|
271
|
+
const vaultMetadata = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultData(chainId);
|
|
273
272
|
this.update((state) => {
|
|
274
|
-
const chainState = state.pooled_staking[
|
|
275
|
-
|
|
276
|
-
state.pooled_staking[chainIdToUse] = {
|
|
273
|
+
const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
|
274
|
+
state.pooled_staking[chainId] = {
|
|
277
275
|
...chainState,
|
|
278
276
|
vaultMetadata,
|
|
279
277
|
};
|
|
@@ -283,18 +281,16 @@ export class EarnController extends BaseController {
|
|
|
283
281
|
* Refreshes pooled staking vault daily apys for the current chain.
|
|
284
282
|
* Updates the pooled staking vault daily apys controller state.
|
|
285
283
|
*
|
|
286
|
-
* @param chainId - The chain id to refresh pooled staking vault daily apys for (optional).
|
|
287
284
|
* @param days - The number of days to fetch pooled staking vault daily apys for (defaults to 365).
|
|
288
285
|
* @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').
|
|
289
286
|
* @returns A promise that resolves when the pooled staking vault daily apys have been updated.
|
|
290
287
|
*/
|
|
291
|
-
async refreshPooledStakingVaultDailyApys(
|
|
292
|
-
const
|
|
293
|
-
const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(
|
|
288
|
+
async refreshPooledStakingVaultDailyApys(days = 365, order = 'desc') {
|
|
289
|
+
const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
|
|
290
|
+
const vaultDailyApys = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultDailyApys(chainId, days, order);
|
|
294
291
|
this.update((state) => {
|
|
295
|
-
const chainState = state.pooled_staking[
|
|
296
|
-
|
|
297
|
-
state.pooled_staking[chainIdToUse] = {
|
|
292
|
+
const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
|
293
|
+
state.pooled_staking[chainId] = {
|
|
298
294
|
...chainState,
|
|
299
295
|
vaultDailyApys,
|
|
300
296
|
};
|
|
@@ -304,16 +300,14 @@ export class EarnController extends BaseController {
|
|
|
304
300
|
* Refreshes pooled staking vault apy averages for the current chain.
|
|
305
301
|
* Updates the pooled staking vault apy averages controller state.
|
|
306
302
|
*
|
|
307
|
-
* @param chainId - The chain id to refresh pooled staking vault apy averages for (optional).
|
|
308
303
|
* @returns A promise that resolves when the pooled staking vault apy averages have been updated.
|
|
309
304
|
*/
|
|
310
|
-
async refreshPooledStakingVaultApyAverages(
|
|
311
|
-
const
|
|
312
|
-
const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(
|
|
305
|
+
async refreshPooledStakingVaultApyAverages() {
|
|
306
|
+
const chainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getActivePooledStakingChainId).call(this);
|
|
307
|
+
const vaultApyAverages = await __classPrivateFieldGet(this, _EarnController_earnApiService, "f").pooledStaking.getVaultApyAverages(chainId);
|
|
313
308
|
this.update((state) => {
|
|
314
|
-
const chainState = state.pooled_staking[
|
|
315
|
-
|
|
316
|
-
state.pooled_staking[chainIdToUse] = {
|
|
309
|
+
const chainState = state.pooled_staking[chainId] ?? DEFAULT_POOLED_STAKING_CHAIN_STATE;
|
|
310
|
+
state.pooled_staking[chainId] = {
|
|
317
311
|
...chainState,
|
|
318
312
|
vaultApyAverages,
|
|
319
313
|
};
|
|
@@ -332,25 +326,23 @@ export class EarnController extends BaseController {
|
|
|
332
326
|
*/
|
|
333
327
|
async refreshPooledStakingData({ resetCache, address, } = {}) {
|
|
334
328
|
const errors = [];
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
]);
|
|
353
|
-
}
|
|
329
|
+
await Promise.all([
|
|
330
|
+
this.refreshPooledStakes({ resetCache, address }).catch((error) => {
|
|
331
|
+
errors.push(error);
|
|
332
|
+
}),
|
|
333
|
+
this.refreshEarnEligibility({ address }).catch((error) => {
|
|
334
|
+
errors.push(error);
|
|
335
|
+
}),
|
|
336
|
+
this.refreshPooledStakingVaultMetadata().catch((error) => {
|
|
337
|
+
errors.push(error);
|
|
338
|
+
}),
|
|
339
|
+
this.refreshPooledStakingVaultDailyApys().catch((error) => {
|
|
340
|
+
errors.push(error);
|
|
341
|
+
}),
|
|
342
|
+
this.refreshPooledStakingVaultApyAverages().catch((error) => {
|
|
343
|
+
errors.push(error);
|
|
344
|
+
}),
|
|
345
|
+
]);
|
|
354
346
|
if (errors.length > 0) {
|
|
355
347
|
throw new Error(`Failed to refresh some staking data: ${errors
|
|
356
348
|
.map((e) => e.message)
|
|
@@ -506,11 +498,14 @@ export class EarnController extends BaseController {
|
|
|
506
498
|
if (!__classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f")) {
|
|
507
499
|
throw new Error('Selected network client id not found');
|
|
508
500
|
}
|
|
501
|
+
const gasLimit = !transactionData.gasLimit
|
|
502
|
+
? undefined
|
|
503
|
+
: toHex(transactionData.gasLimit);
|
|
509
504
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
|
510
505
|
...transactionData,
|
|
511
506
|
value: transactionData.value.toString(),
|
|
512
507
|
chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
|
|
513
|
-
gasLimit
|
|
508
|
+
gasLimit,
|
|
514
509
|
}, {
|
|
515
510
|
...txOptions,
|
|
516
511
|
networkClientId: __classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f"),
|
|
@@ -539,11 +534,14 @@ export class EarnController extends BaseController {
|
|
|
539
534
|
if (!__classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f")) {
|
|
540
535
|
throw new Error('Selected network client id not found');
|
|
541
536
|
}
|
|
537
|
+
const gasLimit = !transactionData.gasLimit
|
|
538
|
+
? undefined
|
|
539
|
+
: toHex(transactionData.gasLimit);
|
|
542
540
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
|
543
541
|
...transactionData,
|
|
544
542
|
value: transactionData.value.toString(),
|
|
545
543
|
chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
|
|
546
|
-
gasLimit
|
|
544
|
+
gasLimit,
|
|
547
545
|
}, {
|
|
548
546
|
...txOptions,
|
|
549
547
|
networkClientId: __classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f"),
|
|
@@ -572,11 +570,14 @@ export class EarnController extends BaseController {
|
|
|
572
570
|
if (!__classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f")) {
|
|
573
571
|
throw new Error('Selected network client id not found');
|
|
574
572
|
}
|
|
573
|
+
const gasLimit = !transactionData.gasLimit
|
|
574
|
+
? undefined
|
|
575
|
+
: toHex(transactionData.gasLimit);
|
|
575
576
|
const txHash = await __classPrivateFieldGet(this, _EarnController_addTransactionFn, "f").call(this, {
|
|
576
577
|
...transactionData,
|
|
577
578
|
value: transactionData.value.toString(),
|
|
578
579
|
chainId: toHex(__classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this)),
|
|
579
|
-
gasLimit
|
|
580
|
+
gasLimit,
|
|
580
581
|
}, {
|
|
581
582
|
...txOptions,
|
|
582
583
|
networkClientId: __classPrivateFieldGet(this, _EarnController_selectedNetworkClientId, "f"),
|
|
@@ -661,5 +662,13 @@ async function _EarnController_initializeSDK(networkClientId) {
|
|
|
661
662
|
.selectedNetworkClientId;
|
|
662
663
|
const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientIdToUse);
|
|
663
664
|
return convertHexToDecimal(chainId);
|
|
665
|
+
}, _EarnController_getActivePooledStakingChainId = function _EarnController_getActivePooledStakingChainId() {
|
|
666
|
+
const activeChainId = __classPrivateFieldGet(this, _EarnController_instances, "m", _EarnController_getCurrentChainId).call(this);
|
|
667
|
+
if (!activeChainId ||
|
|
668
|
+
!__classPrivateFieldGet(this, _EarnController_supportedPooledStakingChains, "f").includes(toHex(activeChainId))) {
|
|
669
|
+
// Fallback to Ethereum Mainnet if chainId is not supported.
|
|
670
|
+
return convertHexToDecimal(CHAIN_IDS.MAINNET);
|
|
671
|
+
}
|
|
672
|
+
return activeChainId;
|
|
664
673
|
};
|
|
665
674
|
//# sourceMappingURL=EarnController.mjs.map
|