@metamask-previews/earn-controller 0.14.0-preview-d9a49231 → 0.14.0-preview-4ef4efd7

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA4B;AAGzD,OAAO,KAAK,EACV,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EAC1B,6BAAyB;AAE1B,eAAO,MAAM,oBAAoB,UAAW,mBAAmB,oBACxC,CAAC;AAExB,eAAO,MAAM,sBAAsB,UAAW,mBAAmB,oEACxC,CAAC;AAE1B,eAAO,MAAM,8BAA8B,YAAa,MAAM;;;;;;;;;;;;2BANlB,mBAAmB;;;;;;;;CAS5D,CAAC;AAEJ,eAAO,MAAM,mCAAmC;;;;;;;;;;;;2BAXJ,mBAAmB;;;;;;;;CAuB9D,CAAC;AAEF,eAAO,MAAM,mCAAmC,aACpC,MAAM,MACZ,MAAM;;;;;;;;;;;;;;;;;;;;;;;;+BA3BgC,mBAAmB;;;;;;;;;;;;;;;;CAgC5D,CAAC;AAEJ,eAAO,MAAM,6BAA6B;;;;;;;;;;;;2BAlCE,mBAAmB;;;;;;;;CA8C9D,CAAC;AAEF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;2BA7CC,mBAAmB;;;;;;;;;;;;+BAHrB,mBAAmB;;;;;;;;;;;;;;;;CA4D9D,CAAC;AAEF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;+BA3DE,mBAAmB;;;;;;;;;;;;mCAHrB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;CA6E9D,CAAC;AAEF,eAAO,MAAM,+CAA+C;;;;;;;;;;;;;;;;;;;;;;;;+BA5Ed,mBAAmB;;;;;;;;;;;;mCAHrB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CA7JwB,mBAAmB;;;;;;;;;;;;+CAHrB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;uBAAnB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;CAsK5D,CAAC;AAEJ,eAAO,MAAM,kDAAkD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uCArKjB,mBAAmB;;;;;;;;;;;;2CAHrB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;mBAAnB,mBAAmB;;;;;;;;;;;;;;;;CAsL5D,CAAC;AAEJ,eAAO,MAAM,4CAA4C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uCArLX,mBAAmB;;;;;;;;;;;;2CAHrB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;mBAAnB,mBAAmB;;;;;;;;;;;;;;;;CAuM9D,CAAC;AAEF,eAAO,MAAM,uBAAuB,UAAW,mBAAmB,YACxC,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { createSelector } from "reselect";
2
+ export const selectLendingMarkets = (state) => state.lending.markets;
3
+ export const selectLendingPositions = (state) => state.lending.positions;
4
+ export const selectLendingMarketsForChainId = (chainId) => createSelector(selectLendingMarkets, (markets) => markets.filter((market) => market.chainId === chainId));
5
+ export const selectLendingMarketsByProtocolAndId = createSelector(selectLendingMarkets, (markets) => {
6
+ return markets.reduce((acc, market) => {
7
+ acc[market.protocol] = acc[market.protocol] || {};
8
+ acc[market.protocol][market.id] = market;
9
+ return acc;
10
+ }, {});
11
+ });
12
+ export const selectLendingMarketForProtocolAndId = (protocol, id) => createSelector(selectLendingMarketsByProtocolAndId, (marketsByProtocolAndId) => marketsByProtocolAndId?.[protocol]?.[id]);
13
+ export const selectLendingMarketsByChainId = createSelector(selectLendingMarkets, (markets) => {
14
+ return markets.reduce((acc, market) => {
15
+ acc[market.chainId] = acc[market.chainId] || [];
16
+ acc[market.chainId].push(market);
17
+ return acc;
18
+ }, {});
19
+ });
20
+ export const selectLendingPositionsWithMarket = createSelector(selectLendingPositions, selectLendingMarketsByProtocolAndId, (positions, marketsByProtocolAndId) => {
21
+ return positions.map((position) => {
22
+ return {
23
+ ...position,
24
+ market: marketsByProtocolAndId?.[position.protocol]?.[position.marketId],
25
+ };
26
+ });
27
+ });
28
+ export const selectLendingPositionsByChainId = createSelector(selectLendingPositionsWithMarket, (positionsWithMarket) => {
29
+ return positionsWithMarket.reduce((acc, position) => {
30
+ const chainId = position.market?.chainId;
31
+ if (chainId) {
32
+ acc[chainId] = acc[chainId] || [];
33
+ acc[chainId].push(position);
34
+ }
35
+ return acc;
36
+ }, {});
37
+ });
38
+ export const selectLendingPositionsByProtocolChainIdMarketId = createSelector(selectLendingPositionsWithMarket, (positionsWithMarket) => positionsWithMarket.reduce((acc, position) => {
39
+ var _a, _b, _c;
40
+ acc[_a = position.protocol] ?? (acc[_a] = {});
41
+ (_b = acc[position.protocol])[_c = position.chainId] ?? (_b[_c] = {});
42
+ acc[position.protocol][position.chainId][position.marketId] = position;
43
+ return acc;
44
+ }, {}));
45
+ export const selectLendingMarketsWithPosition = createSelector(selectLendingPositionsByProtocolChainIdMarketId, selectLendingMarkets, (positionsByProtocolChainIdMarketId, lendingMarkets) => lendingMarkets.map((market) => {
46
+ const position = positionsByProtocolChainIdMarketId?.[market.protocol]?.[market.chainId]?.[market.id];
47
+ return {
48
+ ...market,
49
+ position: position || null,
50
+ };
51
+ }));
52
+ export const selectLendingMarketsByTokenAddress = createSelector(selectLendingMarketsWithPosition, (marketsWithPosition) => {
53
+ return marketsWithPosition.reduce((acc, market) => {
54
+ if (market.underlying?.address) {
55
+ acc[market.underlying.address] = acc[market.underlying.address] || [];
56
+ acc[market.underlying.address].push(market);
57
+ }
58
+ return acc;
59
+ }, {});
60
+ });
61
+ export const selectLendingPositionsByProtocol = createSelector(selectLendingPositionsWithMarket, (positionsWithMarket) => {
62
+ return positionsWithMarket.reduce((acc, position) => {
63
+ acc[position.protocol] = acc[position.protocol] || [];
64
+ acc[position.protocol].push(position);
65
+ return acc;
66
+ }, {});
67
+ });
68
+ export const selectLendingMarketByProtocolAndTokenAddress = createSelector(selectLendingMarketsWithPosition, (marketsWithPosition) => {
69
+ return marketsWithPosition.reduce((acc, market) => {
70
+ if (market.underlying?.address) {
71
+ acc[market.protocol] = acc[market.protocol] || {};
72
+ acc[market.protocol][market.underlying.address] = market;
73
+ }
74
+ return acc;
75
+ }, {});
76
+ });
77
+ export const selectLendingMarketForProtocolAndTokenAddress = (protocol, tokenAddress) => createSelector(selectLendingMarketByProtocolAndTokenAddress, (marketsByProtocolAndTokenAddress) => marketsByProtocolAndTokenAddress?.[protocol]?.[tokenAddress]);
78
+ export const selectLendingMarketsByChainIdAndOutputTokenAddress = createSelector(selectLendingMarketsWithPosition, (marketsWithPosition) => marketsWithPosition.reduce((acc, market) => {
79
+ if (market.outputToken?.address) {
80
+ acc[market.chainId] = acc?.[market.chainId] || {};
81
+ acc[market.chainId][market.outputToken.address] =
82
+ acc?.[market.chainId]?.[market.outputToken.address] || [];
83
+ acc[market.chainId][market.outputToken.address].push(market);
84
+ }
85
+ return acc;
86
+ }, {}));
87
+ export const selectLendingMarketsByChainIdAndTokenAddress = createSelector(selectLendingMarketsWithPosition, (marketsWithPosition) => marketsWithPosition.reduce((acc, market) => {
88
+ if (market.underlying?.address) {
89
+ acc[market.chainId] = acc?.[market.chainId] || {};
90
+ acc[market.chainId][market.underlying.address] =
91
+ acc?.[market.chainId]?.[market.underlying.address] || [];
92
+ acc[market.chainId][market.underlying.address].push(market);
93
+ }
94
+ return acc;
95
+ }, {}));
96
+ export const selectIsLendingEligible = (state) => state.lending.isEligible;
97
+ //# sourceMappingURL=selectors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAQ1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAA0B,EAAE,EAAE,CACjE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;AAExB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAA0B,EAAE,EAAE,CACnE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;AAE1B,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,OAAe,EAAE,EAAE,CAChE,cAAc,CAAC,oBAAoB,EAAE,CAAC,OAAO,EAAE,EAAE,CAC/C,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,KAAK,OAAO,CAAC,CACvD,CAAC;AAEJ,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAC/D,oBAAoB,EACpB,CAAC,OAAO,EAAE,EAAE;IACV,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACd,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClD,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;QACzC,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAmD,CACpD,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,QAAgB,EAChB,EAAU,EACV,EAAE,CACF,cAAc,CACZ,mCAAmC,EACnC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OAAO,EAAE;QAC9B,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAClD,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;YAC5C,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC3D,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KAC7D;IACD,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAiE,CAClE,CACJ,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAA0B,EAAE,EAAE,CACpE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC","sourcesContent":["import type { LendingMarket } from '@metamask/stake-sdk';\nimport { createSelector } from 'reselect';\n\nimport type {\n EarnControllerState,\n LendingMarketWithPosition,\n LendingPositionWithMarket,\n} from './EarnController';\n\nexport const selectLendingMarkets = (state: EarnControllerState) =>\n state.lending.markets;\n\nexport const selectLendingPositions = (state: EarnControllerState) =>\n state.lending.positions;\n\nexport const selectLendingMarketsForChainId = (chainId: number) =>\n createSelector(selectLendingMarkets, (markets) =>\n markets.filter((market) => market.chainId === chainId),\n );\n\nexport const selectLendingMarketsByProtocolAndId = createSelector(\n selectLendingMarkets,\n (markets) => {\n return markets.reduce(\n (acc, market) => {\n acc[market.protocol] = acc[market.protocol] || {};\n acc[market.protocol][market.id] = market;\n return acc;\n },\n {} as Record<string, Record<string, LendingMarket>>,\n );\n },\n);\n\nexport const selectLendingMarketForProtocolAndId = (\n protocol: string,\n id: string,\n) =>\n createSelector(\n selectLendingMarketsByProtocolAndId,\n (marketsByProtocolAndId) => marketsByProtocolAndId?.[protocol]?.[id],\n );\n\nexport const selectLendingMarketsByChainId = createSelector(\n selectLendingMarkets,\n (markets) => {\n return markets.reduce(\n (acc, market) => {\n acc[market.chainId] = acc[market.chainId] || [];\n acc[market.chainId].push(market);\n return acc;\n },\n {} as Record<number, LendingMarket[]>,\n );\n },\n);\n\nexport const selectLendingPositionsWithMarket = createSelector(\n selectLendingPositions,\n selectLendingMarketsByProtocolAndId,\n (positions, marketsByProtocolAndId): LendingPositionWithMarket[] => {\n return positions.map((position) => {\n return {\n ...position,\n market:\n marketsByProtocolAndId?.[position.protocol]?.[position.marketId],\n };\n });\n },\n);\n\nexport const selectLendingPositionsByChainId = createSelector(\n selectLendingPositionsWithMarket,\n (positionsWithMarket) => {\n return positionsWithMarket.reduce(\n (acc, position) => {\n const chainId = position.market?.chainId;\n if (chainId) {\n acc[chainId] = acc[chainId] || [];\n acc[chainId].push(position);\n }\n return acc;\n },\n {} as Record<number, LendingPositionWithMarket[]>,\n );\n },\n);\n\nexport const selectLendingPositionsByProtocolChainIdMarketId = createSelector(\n selectLendingPositionsWithMarket,\n (positionsWithMarket) =>\n positionsWithMarket.reduce(\n (acc, position) => {\n acc[position.protocol] ??= {};\n acc[position.protocol][position.chainId] ??= {};\n acc[position.protocol][position.chainId][position.marketId] = position;\n return acc;\n },\n {} as Record<\n string,\n Record<string, Record<string, LendingPositionWithMarket>>\n >,\n ),\n);\n\nexport const selectLendingMarketsWithPosition = createSelector(\n selectLendingPositionsByProtocolChainIdMarketId,\n selectLendingMarkets,\n (positionsByProtocolChainIdMarketId, lendingMarkets) =>\n lendingMarkets.map((market) => {\n const position =\n positionsByProtocolChainIdMarketId?.[market.protocol]?.[\n market.chainId\n ]?.[market.id];\n return {\n ...market,\n position: position || null,\n };\n }),\n);\n\nexport const selectLendingMarketsByTokenAddress = createSelector(\n selectLendingMarketsWithPosition,\n (marketsWithPosition) => {\n return marketsWithPosition.reduce(\n (acc, market) => {\n if (market.underlying?.address) {\n acc[market.underlying.address] = acc[market.underlying.address] || [];\n acc[market.underlying.address].push(market);\n }\n return acc;\n },\n {} as Record<string, LendingMarketWithPosition[]>,\n );\n },\n);\n\nexport const selectLendingPositionsByProtocol = createSelector(\n selectLendingPositionsWithMarket,\n (positionsWithMarket) => {\n return positionsWithMarket.reduce(\n (acc, position) => {\n acc[position.protocol] = acc[position.protocol] || [];\n acc[position.protocol].push(position);\n return acc;\n },\n {} as Record<string, LendingPositionWithMarket[]>,\n );\n },\n);\n\nexport const selectLendingMarketByProtocolAndTokenAddress = createSelector(\n selectLendingMarketsWithPosition,\n (marketsWithPosition) => {\n return marketsWithPosition.reduce(\n (acc, market) => {\n if (market.underlying?.address) {\n acc[market.protocol] = acc[market.protocol] || {};\n acc[market.protocol][market.underlying.address] = market;\n }\n return acc;\n },\n {} as Record<string, Record<string, LendingMarketWithPosition>>,\n );\n },\n);\n\nexport const selectLendingMarketForProtocolAndTokenAddress = (\n protocol: string,\n tokenAddress: string,\n) =>\n createSelector(\n selectLendingMarketByProtocolAndTokenAddress,\n (marketsByProtocolAndTokenAddress) =>\n marketsByProtocolAndTokenAddress?.[protocol]?.[tokenAddress],\n );\n\nexport const selectLendingMarketsByChainIdAndOutputTokenAddress =\n createSelector(selectLendingMarketsWithPosition, (marketsWithPosition) =>\n marketsWithPosition.reduce(\n (acc, market) => {\n if (market.outputToken?.address) {\n acc[market.chainId] = acc?.[market.chainId] || {};\n acc[market.chainId][market.outputToken.address] =\n acc?.[market.chainId]?.[market.outputToken.address] || [];\n acc[market.chainId][market.outputToken.address].push(market);\n }\n return acc;\n },\n {} as Record<string, Record<string, LendingMarketWithPosition[]>>,\n ),\n );\n\nexport const selectLendingMarketsByChainIdAndTokenAddress = createSelector(\n selectLendingMarketsWithPosition,\n (marketsWithPosition) =>\n marketsWithPosition.reduce(\n (acc, market) => {\n if (market.underlying?.address) {\n acc[market.chainId] = acc?.[market.chainId] || {};\n acc[market.chainId][market.underlying.address] =\n acc?.[market.chainId]?.[market.underlying.address] || [];\n acc[market.chainId][market.underlying.address].push(market);\n }\n return acc;\n },\n {} as Record<string, Record<string, LendingMarketWithPosition[]>>,\n ),\n);\n\nexport const selectIsLendingEligible = (state: EarnControllerState) =>\n state.lending.isEligible;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type RefreshStakingEligibilityOptions = {\n address?: string;\n};\n\nexport type RefreshPooledStakesOptions = {\n resetCache?: boolean;\n address?: string;\n};\n\nexport type RefreshPooledStakingDataOptions = {\n resetCache?: boolean;\n address?: string;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type RefreshStakingEligibilityOptions = {\n address?: string;\n};\n\nexport type RefreshPooledStakesOptions = {\n resetCache?: boolean;\n address?: string;\n chainId?: number;\n};\n\nexport type RefreshPooledStakingDataOptions = {\n resetCache?: boolean;\n address?: string;\n chainId?: number;\n};\n\nexport type RefreshLendingPositionsOptions = {\n address?: string;\n};\n\nexport type RefreshLendingEligibilityOptions = {\n address?: string;\n};\n"]}
package/dist/types.d.cts CHANGED
@@ -4,9 +4,17 @@ export type RefreshStakingEligibilityOptions = {
4
4
  export type RefreshPooledStakesOptions = {
5
5
  resetCache?: boolean;
6
6
  address?: string;
7
+ chainId?: number;
7
8
  };
8
9
  export type RefreshPooledStakingDataOptions = {
9
10
  resetCache?: boolean;
10
11
  address?: string;
12
+ chainId?: number;
13
+ };
14
+ export type RefreshLendingPositionsOptions = {
15
+ address?: string;
16
+ };
17
+ export type RefreshLendingEligibilityOptions = {
18
+ address?: string;
11
19
  };
12
20
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
package/dist/types.d.mts CHANGED
@@ -4,9 +4,17 @@ export type RefreshStakingEligibilityOptions = {
4
4
  export type RefreshPooledStakesOptions = {
5
5
  resetCache?: boolean;
6
6
  address?: string;
7
+ chainId?: number;
7
8
  };
8
9
  export type RefreshPooledStakingDataOptions = {
9
10
  resetCache?: boolean;
10
11
  address?: string;
12
+ chainId?: number;
13
+ };
14
+ export type RefreshLendingPositionsOptions = {
15
+ address?: string;
16
+ };
17
+ export type RefreshLendingEligibilityOptions = {
18
+ address?: string;
11
19
  };
12
20
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type RefreshStakingEligibilityOptions = {\n address?: string;\n};\n\nexport type RefreshPooledStakesOptions = {\n resetCache?: boolean;\n address?: string;\n};\n\nexport type RefreshPooledStakingDataOptions = {\n resetCache?: boolean;\n address?: string;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type RefreshStakingEligibilityOptions = {\n address?: string;\n};\n\nexport type RefreshPooledStakesOptions = {\n resetCache?: boolean;\n address?: string;\n chainId?: number;\n};\n\nexport type RefreshPooledStakingDataOptions = {\n resetCache?: boolean;\n address?: string;\n chainId?: number;\n};\n\nexport type RefreshLendingPositionsOptions = {\n address?: string;\n};\n\nexport type RefreshLendingEligibilityOptions = {\n address?: string;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/earn-controller",
3
- "version": "0.14.0-preview-d9a49231",
3
+ "version": "0.14.0-preview-4ef4efd7",
4
4
  "description": "Manages state for earning features and coordinates interactions between staking services, SDK integrations, and other controllers to enable users to participate in various earning opportunities",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -47,16 +47,18 @@
47
47
  "since-latest-release": "../../scripts/since-latest-release.sh"
48
48
  },
49
49
  "dependencies": {
50
+ "@ethersproject/bignumber": "^5.7.0",
50
51
  "@ethersproject/providers": "^5.7.0",
51
52
  "@metamask/base-controller": "^8.0.1",
52
53
  "@metamask/controller-utils": "^11.9.0",
53
- "@metamask/stake-sdk": "^1.0.0"
54
+ "@metamask/stake-sdk": "3.2.0",
55
+ "reselect": "^5.1.1"
54
56
  },
55
57
  "devDependencies": {
56
58
  "@metamask/accounts-controller": "^29.0.0",
57
59
  "@metamask/auto-changelog": "^3.4.4",
58
- "@metamask/network-controller": "^23.5.0",
59
- "@metamask/transaction-controller": "^56.2.0",
60
+ "@metamask/network-controller": "^23.5.1",
61
+ "@metamask/transaction-controller": "^56.3.0",
60
62
  "@types/jest": "^27.4.1",
61
63
  "deepmerge": "^4.2.2",
62
64
  "jest": "^27.5.1",