@metamask-previews/money-account-api-data-service 1.0.0-preview-d2ea3cc → 1.0.0-preview-acac4ba67

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 CHANGED
@@ -7,6 +7,11 @@ 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
+ - Add optional `fresh` option to `fetchPositions` that cancels in-flight reads, invalidates the client cache, and fetches with `Cache-Control: no-cache` without writing through TanStack — so a rejected freshness read cannot seed the steady-state cache. Asks the Money API to skip its Nest response cache when the server honors the header ([#10422](https://github.com/MetaMask/core/pull/10422))
13
+ - Accept optional additive `musd_balance_updated_at` on the positions `balance` summary ([#10422](https://github.com/MetaMask/core/pull/10422))
14
+
10
15
  ### Changed
11
16
 
12
17
  - Bump `@metamask/utils` from `^11.12.0` to `^12.0.0` ([#10192](https://github.com/MetaMask/core/pull/10192))
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { MoneyAccountApiDataService } from './money-account-api-data-service.js';
2
- export type { MoneyAccountApiDataServiceActions, MoneyAccountApiDataServiceEvents, MoneyAccountApiDataServiceMessenger, MoneyAccountApiDataServiceOptions, MoneyAccountApiDataServiceTraceCallback, MoneyAccountApiDataServiceTraceRequest, } from './money-account-api-data-service.js';
2
+ export type { MoneyAccountApiDataServiceActions, MoneyAccountApiDataServiceEvents, MoneyAccountApiDataServiceMessenger, MoneyAccountApiDataServiceOptions, MoneyAccountApiDataServiceTraceCallback, MoneyAccountApiDataServiceTraceRequest, MoneyAccountApiDataServiceInvalidateQueriesAction, } from './money-account-api-data-service.js';
3
3
  export type { MoneyAccountApiDataServiceFetchPositionsAction, MoneyAccountApiDataServiceFetchInterestAction, MoneyAccountApiDataServiceFetchHistoryAction, MoneyAccountApiDataServiceFetchRateHistoryAction, } from './money-account-api-data-service-method-action-types.js';
4
4
  export type { PositionResponse, PositionBalance, InterestResponse, HistoryResponse, RateHistoryResponse, VaultPosition, CashFlowEntry, RateHistoryEntry, DataFreshness, CashFlowType, CashFlowSource, } from './response.types.js';
5
- export type { InterestWindow, InterestOptions, HistoryOptions, RateHistoryOptions, } from './types.js';
5
+ export type { InterestWindow, InterestOptions, FetchPositionsOptions, HistoryOptions, RateHistoryOptions, } from './types.js';
6
6
  export { Env } from './constants.js';
7
7
  export { MoneyAccountApiResponseValidationError } from './errors.js';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,YAAY,EACV,iCAAiC,EACjC,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,uCAAuC,EACvC,sCAAsC,GACvC,MAAM,qCAAqC,CAAC;AAC7C,YAAY,EACV,8CAA8C,EAC9C,6CAA6C,EAC7C,4CAA4C,EAC5C,gDAAgD,GACjD,MAAM,yDAAyD,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,GACf,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,cAAc,EACd,eAAe,EACf,cAAc,EACd,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,sCAAsC,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,YAAY,EACV,iCAAiC,EACjC,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,uCAAuC,EACvC,sCAAsC,EACtC,iDAAiD,GAClD,MAAM,qCAAqC,CAAC;AAC7C,YAAY,EACV,8CAA8C,EAC9C,6CAA6C,EAC7C,4CAA4C,EAC5C,gDAAgD,GACjD,MAAM,yDAAyD,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,GACf,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,sCAAsC,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAkCjF,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,sCAAsC,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { MoneyAccountApiDataService } from './money-account-api-data-service.js';\nexport type {\n MoneyAccountApiDataServiceActions,\n MoneyAccountApiDataServiceEvents,\n MoneyAccountApiDataServiceMessenger,\n MoneyAccountApiDataServiceOptions,\n MoneyAccountApiDataServiceTraceCallback,\n MoneyAccountApiDataServiceTraceRequest,\n} from './money-account-api-data-service.js';\nexport type {\n MoneyAccountApiDataServiceFetchPositionsAction,\n MoneyAccountApiDataServiceFetchInterestAction,\n MoneyAccountApiDataServiceFetchHistoryAction,\n MoneyAccountApiDataServiceFetchRateHistoryAction,\n} from './money-account-api-data-service-method-action-types.js';\nexport type {\n PositionResponse,\n PositionBalance,\n InterestResponse,\n HistoryResponse,\n RateHistoryResponse,\n VaultPosition,\n CashFlowEntry,\n RateHistoryEntry,\n DataFreshness,\n CashFlowType,\n CashFlowSource,\n} from './response.types.js';\nexport type {\n InterestWindow,\n InterestOptions,\n HistoryOptions,\n RateHistoryOptions,\n} from './types.js';\nexport { Env } from './constants.js';\nexport { MoneyAccountApiResponseValidationError } from './errors.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAoCjF,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,sCAAsC,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { MoneyAccountApiDataService } from './money-account-api-data-service.js';\nexport type {\n MoneyAccountApiDataServiceActions,\n MoneyAccountApiDataServiceEvents,\n MoneyAccountApiDataServiceMessenger,\n MoneyAccountApiDataServiceOptions,\n MoneyAccountApiDataServiceTraceCallback,\n MoneyAccountApiDataServiceTraceRequest,\n MoneyAccountApiDataServiceInvalidateQueriesAction,\n} from './money-account-api-data-service.js';\nexport type {\n MoneyAccountApiDataServiceFetchPositionsAction,\n MoneyAccountApiDataServiceFetchInterestAction,\n MoneyAccountApiDataServiceFetchHistoryAction,\n MoneyAccountApiDataServiceFetchRateHistoryAction,\n} from './money-account-api-data-service-method-action-types.js';\nexport type {\n PositionResponse,\n PositionBalance,\n InterestResponse,\n HistoryResponse,\n RateHistoryResponse,\n VaultPosition,\n CashFlowEntry,\n RateHistoryEntry,\n DataFreshness,\n CashFlowType,\n CashFlowSource,\n} from './response.types.js';\nexport type {\n InterestWindow,\n InterestOptions,\n FetchPositionsOptions,\n HistoryOptions,\n RateHistoryOptions,\n} from './types.js';\nexport { Env } from './constants.js';\nexport { MoneyAccountApiResponseValidationError } from './errors.js';\n"]}
@@ -7,6 +7,13 @@ import type { MoneyAccountApiDataService } from './money-account-api-data-servic
7
7
  * Fetches the current vault positions for a given user address.
8
8
  *
9
9
  * @param address - The user's Ethereum address.
10
+ * @param options - Optional fetch options.
11
+ * @param options.fresh - When true, cancels in-flight reads, invalidates the
12
+ * client cache, and fetches with `Cache-Control: no-cache` **without**
13
+ * writing through TanStack — so a caller that later rejects the body
14
+ * (e.g. `minBlock` freshness) cannot leave a warm pre-tx entry for the
15
+ * next steady-state poll. Asks the Money API to skip its Nest response
16
+ * cache when that server honors the header.
10
17
  * @returns The position response containing vault positions and an optional
11
18
  * `balance` summary (`null` when the API balance path is unavailable).
12
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"money-account-api-data-service-method-action-types.d.ts","sourceRoot":"","sources":["../src/money-account-api-data-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAEtF;;;;;;GAMG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,0BAA0B,CAAC,gBAAgB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,0BAA0B,CAAC,eAAe,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAC/C,8CAA8C,GAC9C,6CAA6C,GAC7C,4CAA4C,GAC5C,gDAAgD,CAAC"}
1
+ {"version":3,"file":"money-account-api-data-service-method-action-types.d.ts","sourceRoot":"","sources":["../src/money-account-api-data-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAEtF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,0BAA0B,CAAC,gBAAgB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,0BAA0B,CAAC,eAAe,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAC/C,8CAA8C,GAC9C,6CAA6C,GAC7C,4CAA4C,GAC5C,gDAAgD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"money-account-api-data-service-method-action-types.js","sourceRoot":"","sources":["../src/money-account-api-data-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MoneyAccountApiDataService } from './money-account-api-data-service.js';\n\n/**\n * Fetches the current vault positions for a given user address.\n *\n * @param address - The user's Ethereum address.\n * @returns The position response containing vault positions and an optional\n * `balance` summary (`null` when the API balance path is unavailable).\n */\nexport type MoneyAccountApiDataServiceFetchPositionsAction = {\n type: `MoneyAccountApiDataService:fetchPositions`;\n handler: MoneyAccountApiDataService['fetchPositions'];\n};\n\n/**\n * Fetches the interest earned for a given address and vault over a\n * specified time window.\n *\n * @param address - The user's Ethereum address.\n * @param options - Options specifying vault, window, and optional chain ID.\n * @returns The interest response.\n */\nexport type MoneyAccountApiDataServiceFetchInterestAction = {\n type: `MoneyAccountApiDataService:fetchInterest`;\n handler: MoneyAccountApiDataService['fetchInterest'];\n};\n\n/**\n * Fetches cursor-paginated cash-flow history for a given address.\n * Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.\n *\n * When paginating, consumers must re-pass the same filter options\n * (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page\n * request. This ensures the query key matches the original infinite query\n * and that the HTTP request includes the correct filters.\n *\n * @param address - The user's Ethereum address.\n * @param options - Optional filtering and pagination options.\n * @returns The history response containing cash-flow entries for the requested page.\n */\nexport type MoneyAccountApiDataServiceFetchHistoryAction = {\n type: `MoneyAccountApiDataService:fetchHistory`;\n handler: MoneyAccountApiDataService['fetchHistory'];\n};\n\n/**\n * Fetches the exchange-rate time series for a given vault.\n *\n * @param vaultAddress - The vault's Ethereum address.\n * @param options - Optional range and chain ID filters.\n * @returns The rate history response.\n */\nexport type MoneyAccountApiDataServiceFetchRateHistoryAction = {\n type: `MoneyAccountApiDataService:fetchRateHistory`;\n handler: MoneyAccountApiDataService['fetchRateHistory'];\n};\n\n/**\n * Union of all MoneyAccountApiDataService action types.\n */\nexport type MoneyAccountApiDataServiceMethodActions =\n | MoneyAccountApiDataServiceFetchPositionsAction\n | MoneyAccountApiDataServiceFetchInterestAction\n | MoneyAccountApiDataServiceFetchHistoryAction\n | MoneyAccountApiDataServiceFetchRateHistoryAction;\n"]}
1
+ {"version":3,"file":"money-account-api-data-service-method-action-types.js","sourceRoot":"","sources":["../src/money-account-api-data-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MoneyAccountApiDataService } from './money-account-api-data-service.js';\n\n/**\n * Fetches the current vault positions for a given user address.\n *\n * @param address - The user's Ethereum address.\n * @param options - Optional fetch options.\n * @param options.fresh - When true, cancels in-flight reads, invalidates the\n * client cache, and fetches with `Cache-Control: no-cache` **without**\n * writing through TanStack — so a caller that later rejects the body\n * (e.g. `minBlock` freshness) cannot leave a warm pre-tx entry for the\n * next steady-state poll. Asks the Money API to skip its Nest response\n * cache when that server honors the header.\n * @returns The position response containing vault positions and an optional\n * `balance` summary (`null` when the API balance path is unavailable).\n */\nexport type MoneyAccountApiDataServiceFetchPositionsAction = {\n type: `MoneyAccountApiDataService:fetchPositions`;\n handler: MoneyAccountApiDataService['fetchPositions'];\n};\n\n/**\n * Fetches the interest earned for a given address and vault over a\n * specified time window.\n *\n * @param address - The user's Ethereum address.\n * @param options - Options specifying vault, window, and optional chain ID.\n * @returns The interest response.\n */\nexport type MoneyAccountApiDataServiceFetchInterestAction = {\n type: `MoneyAccountApiDataService:fetchInterest`;\n handler: MoneyAccountApiDataService['fetchInterest'];\n};\n\n/**\n * Fetches cursor-paginated cash-flow history for a given address.\n * Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.\n *\n * When paginating, consumers must re-pass the same filter options\n * (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page\n * request. This ensures the query key matches the original infinite query\n * and that the HTTP request includes the correct filters.\n *\n * @param address - The user's Ethereum address.\n * @param options - Optional filtering and pagination options.\n * @returns The history response containing cash-flow entries for the requested page.\n */\nexport type MoneyAccountApiDataServiceFetchHistoryAction = {\n type: `MoneyAccountApiDataService:fetchHistory`;\n handler: MoneyAccountApiDataService['fetchHistory'];\n};\n\n/**\n * Fetches the exchange-rate time series for a given vault.\n *\n * @param vaultAddress - The vault's Ethereum address.\n * @param options - Optional range and chain ID filters.\n * @returns The rate history response.\n */\nexport type MoneyAccountApiDataServiceFetchRateHistoryAction = {\n type: `MoneyAccountApiDataService:fetchRateHistory`;\n handler: MoneyAccountApiDataService['fetchRateHistory'];\n};\n\n/**\n * Union of all MoneyAccountApiDataService action types.\n */\nexport type MoneyAccountApiDataServiceMethodActions =\n | MoneyAccountApiDataServiceFetchPositionsAction\n | MoneyAccountApiDataServiceFetchInterestAction\n | MoneyAccountApiDataServiceFetchHistoryAction\n | MoneyAccountApiDataServiceFetchRateHistoryAction;\n"]}
@@ -6,7 +6,7 @@ import type { QueryClientConfig } from '@tanstack/query-core';
6
6
  import { Env } from './constants.js';
7
7
  import type { MoneyAccountApiDataServiceMethodActions } from './money-account-api-data-service-method-action-types.js';
8
8
  import type { HistoryResponse, InterestResponse, PositionResponse, RateHistoryResponse } from './response.types.js';
9
- import type { HistoryOptions, InterestOptions, RateHistoryOptions } from './types.js';
9
+ import type { HistoryOptions, InterestOptions, RateHistoryOptions, FetchPositionsOptions } from './types.js';
10
10
  /**
11
11
  * The name of the {@link MoneyAccountApiDataService}, used to namespace the
12
12
  * service's actions and events.
@@ -92,10 +92,17 @@ export declare class MoneyAccountApiDataService extends BaseDataService<typeof s
92
92
  * Fetches the current vault positions for a given user address.
93
93
  *
94
94
  * @param address - The user's Ethereum address.
95
+ * @param options - Optional fetch options.
96
+ * @param options.fresh - When true, cancels in-flight reads, invalidates the
97
+ * client cache, and fetches with `Cache-Control: no-cache` **without**
98
+ * writing through TanStack — so a caller that later rejects the body
99
+ * (e.g. `minBlock` freshness) cannot leave a warm pre-tx entry for the
100
+ * next steady-state poll. Asks the Money API to skip its Nest response
101
+ * cache when that server honors the header.
95
102
  * @returns The position response containing vault positions and an optional
96
103
  * `balance` summary (`null` when the API balance path is unavailable).
97
104
  */
98
- fetchPositions(address: string): Promise<PositionResponse>;
105
+ fetchPositions(address: string, options?: FetchPositionsOptions): Promise<PositionResponse>;
99
106
  /**
100
107
  * Fetches the interest earned for a given address and vault over a
101
108
  * specified time window.
@@ -1 +1 @@
1
- {"version":3,"file":"money-account-api-data-service.d.ts","sourceRoot":"","sources":["../src/money-account-api-data-service.ts"],"names":[],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AClB,KAAK,GACN,EAAE,iCAAiC,EAgCnC;IAuBD;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAyC/D;IAED;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAuD3B;IAED;;;;;;;;;;;;OAYG;IACG,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,eAAe,CAAC,CAqE1B;IAED;;;;;;OAMG;IACG,gBAAgB,CACpB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CA2D9B;CAkDF"}
1
+ {"version":3,"file":"money-account-api-data-service.d.ts","sourceRoot":"","sources":["../src/money-account-api-data-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EACV,0BAA0B,EAC1B,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAEL,GAAG,EAGJ,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,yDAAyD,CAAC;AACvH,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,YA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,mDAAmD,CAAC;AAExD;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,mCAAmC,GAAG,SAAS,CACzD,OAAO,WAAW,EAClB,iCAAiC,GAAG,cAAc,EAClD,gCAAgC,GAAG,aAAa,CACjD,CAAC;AAIF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,SAAS,EAAE,mCAAmC,CAAC;IAC/C,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,KAAK,CAAC,EAAE,uCAAuC,CAAC;CACjD,CAAC;AAEF;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,eAAe,CAC7D,OAAO,WAAW,EAClB,mCAAmC,CACpC;;IAKC;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,GAAa,EACb,iBAAsB,EACtB,aAAkB,EAClB,KAAK,GACN,EAAE,iCAAiC,EAgCnC;IAuBD;;;;;;;;;;;;;OAaG;IACG,cAAc,CAClB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,gBAAgB,CAAC,CAyB3B;IAoDD;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAuD3B;IAED;;;;;;;;;;;;OAYG;IACG,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,eAAe,CAAC,CAqE1B;IAED;;;;;;OAMG;IACG,gBAAgB,CACpB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CA2D9B;CAkDF"}
@@ -87,35 +87,72 @@ export class MoneyAccountApiDataService extends BaseDataService {
87
87
  * Fetches the current vault positions for a given user address.
88
88
  *
89
89
  * @param address - The user's Ethereum address.
90
+ * @param options - Optional fetch options.
91
+ * @param options.fresh - When true, cancels in-flight reads, invalidates the
92
+ * client cache, and fetches with `Cache-Control: no-cache` **without**
93
+ * writing through TanStack — so a caller that later rejects the body
94
+ * (e.g. `minBlock` freshness) cannot leave a warm pre-tx entry for the
95
+ * next steady-state poll. Asks the Money API to skip its Nest response
96
+ * cache when that server honors the header.
90
97
  * @returns The position response containing vault positions and an optional
91
98
  * `balance` summary (`null` when the API balance path is unavailable).
92
99
  */
93
- async fetchPositions(address) {
94
- const url = new URL(`/v1/positions/${address.toLowerCase()}`, this.#baseUrl);
100
+ async fetchPositions(address, options) {
101
+ const normalizedAddress = address.toLowerCase();
102
+ const fresh = options?.fresh === true;
103
+ const queryKey = [
104
+ `${this.name}:fetchPositions`,
105
+ normalizedAddress,
106
+ ];
107
+ if (fresh) {
108
+ // Cancel any in-flight non-fresh fetch so it cannot win the shared
109
+ // queryKey and re-seed a response that omitted Cache-Control: no-cache.
110
+ await this.cancelQueries({ queryKey: [...queryKey] });
111
+ await this.invalidateQueries({ queryKey: [...queryKey] });
112
+ // Bypass fetchQuery: a minBlock-rejected body must not become the
113
+ // steady-state cache entry with a fresh dataUpdatedAt.
114
+ return await this.#fetchPositionsFromNetwork(normalizedAddress, true);
115
+ }
95
116
  return this.fetchQuery({
96
- queryKey: [`${this.name}:fetchPositions`, address.toLowerCase()],
117
+ queryKey: [...queryKey],
97
118
  staleTime: DEFAULT_STALE_TIME_MS,
98
119
  queryFn: async () => {
99
- return this.#traceNetworkRequest({
100
- name: TRACES.POSITIONS_API,
101
- data: { operation: 'fetchPositions' },
102
- }, async () => {
103
- const response = await fetch(url, {
104
- headers: await this.#getRequestHeaders(),
105
- });
106
- if (!response.ok) {
107
- throw new HttpError(response.status, `Money Account API positions request failed with status '${response.status}'`);
108
- }
109
- const json = await response.json();
110
- const [error, validated] = validate(json, PositionResponseStruct);
111
- if (error) {
112
- throw new MoneyAccountApiResponseValidationError(`Malformed response from positions endpoint: ${error.message}`);
113
- }
114
- return validated;
115
- });
120
+ return this.#fetchPositionsFromNetwork(normalizedAddress, false);
116
121
  },
117
122
  });
118
123
  }
124
+ /**
125
+ * Performs the HTTP GET for `/v1/positions/:address`.
126
+ *
127
+ * @param normalizedAddress - Lowercased account address.
128
+ * @param fresh - When true, send `Cache-Control: no-cache`.
129
+ * @returns Validated positions response.
130
+ */
131
+ async #fetchPositionsFromNetwork(normalizedAddress, fresh) {
132
+ const url = new URL(`/v1/positions/${normalizedAddress}`, this.#baseUrl);
133
+ return this.#traceNetworkRequest({
134
+ name: TRACES.POSITIONS_API,
135
+ data: {
136
+ operation: 'fetchPositions',
137
+ ...(fresh ? { fresh: true } : {}),
138
+ },
139
+ }, async () => {
140
+ const headers = {
141
+ ...(await this.#getRequestHeaders()),
142
+ ...(fresh ? { 'Cache-Control': 'no-cache' } : {}),
143
+ };
144
+ const response = await fetch(url, { headers });
145
+ if (!response.ok) {
146
+ throw new HttpError(response.status, `Money Account API positions request failed with status '${response.status}'`);
147
+ }
148
+ const json = await response.json();
149
+ const [error, validated] = validate(json, PositionResponseStruct);
150
+ if (error) {
151
+ throw new MoneyAccountApiResponseValidationError(`Malformed response from positions endpoint: ${error.message}`);
152
+ }
153
+ return validated;
154
+ });
155
+ }
119
156
  /**
120
157
  * Fetches the interest earned for a given address and vault over a
121
158
  * specified time window.
@@ -1 +1 @@
1
- {"version":3,"file":"money-account-api-data-service.js","sourceRoot":"","sources":["../src/money-account-api-data-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAM9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD,OAAO,EACL,qBAAqB,EACrB,GAAG,EACH,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB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,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACpC;aACF,CAAC;YACF,MAAM,YAAY,GAAG,CAAC,UAAmB,EAAQ,EAAE;gBACjD,WAAW,CAAC,sBAAsB,EAAE;oBAClC,SAAS,EAAE,OAAO,CAAC,IAAI;oBACvB,UAAU;iBACX,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,IAAI,CAAC;gBACH,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAC/D,YAAY,CACb,CAAC;YACJ,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACpB,YAAY,CAAC,UAAU,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type {\n CreateServicePolicyOptions,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\nimport { handleWhen, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport { validate } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport {\n DEFAULT_STALE_TIME_MS,\n Env,\n MONEY_ACCOUNT_API_URL_MAP,\n RATE_HISTORY_STALE_TIME_MS,\n} from './constants.js';\nimport { MoneyAccountApiResponseValidationError } from './errors.js';\nimport { projectLogger, createModuleLogger } from './logger.js';\nimport type { MoneyAccountApiDataServiceMethodActions } from './money-account-api-data-service-method-action-types.js';\nimport type {\n HistoryResponse,\n InterestResponse,\n PositionResponse,\n RateHistoryResponse,\n} from './response.types.js';\nimport {\n HistoryResponseStruct,\n InterestResponseStruct,\n PositionResponseStruct,\n RateHistoryResponseStruct,\n} from './structs.js';\nimport type {\n HistoryOptions,\n InterestOptions,\n RateHistoryOptions,\n} from './types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link MoneyAccountApiDataService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'MoneyAccountApiDataService';\n\nconst log = createModuleLogger(projectLogger, serviceName);\nconst traceLogger = createModuleLogger(projectLogger, 'trace');\n\nexport const TRACES = {\n POSITIONS_API: 'Money Account API Fetch Positions',\n INTEREST_API: 'Money Account API Fetch Interest',\n HISTORY_API: 'Money Account API Fetch History',\n RATE_HISTORY_API: 'Money Account API Fetch Rate History',\n} as const;\n\nexport type MoneyAccountApiDataServiceTraceName =\n (typeof TRACES)[keyof typeof TRACES];\n\nexport type MoneyAccountApiDataServiceTraceRequest = Omit<\n TraceRequest,\n 'name'\n> & {\n name: MoneyAccountApiDataServiceTraceName;\n startTime?: number;\n};\n\nexport type MoneyAccountApiDataServiceTraceCallback = <ReturnType>(\n request: MoneyAccountApiDataServiceTraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchPositions',\n 'fetchInterest',\n 'fetchHistory',\n 'fetchRateHistory',\n] as const;\n\n/**\n * Invalidates cached queries for {@link MoneyAccountApiDataService}.\n */\nexport type MoneyAccountApiDataServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link MoneyAccountApiDataService} exposes to other consumers.\n */\nexport type MoneyAccountApiDataServiceActions =\n | MoneyAccountApiDataServiceMethodActions\n | MoneyAccountApiDataServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link MoneyAccountApiDataService} calls.\n */\ntype AuthenticationControllerGetBearerTokenAction = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\ntype AllowedActions = AuthenticationControllerGetBearerTokenAction;\n\n/**\n * Published when {@link MoneyAccountApiDataService}'s cache is updated.\n */\nexport type MoneyAccountApiDataServiceCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link MoneyAccountApiDataService}'s cache is\n * updated.\n */\nexport type MoneyAccountApiDataServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link MoneyAccountApiDataService} exposes to other consumers.\n */\nexport type MoneyAccountApiDataServiceEvents =\n | MoneyAccountApiDataServiceCacheUpdatedEvent\n | MoneyAccountApiDataServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link MoneyAccountApiDataService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link MoneyAccountApiDataService}.\n */\nexport type MoneyAccountApiDataServiceMessenger = Messenger<\n typeof serviceName,\n MoneyAccountApiDataServiceActions | AllowedActions,\n MoneyAccountApiDataServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\nexport type MoneyAccountApiDataServiceOptions = {\n messenger: MoneyAccountApiDataServiceMessenger;\n env?: Env;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n trace?: MoneyAccountApiDataServiceTraceCallback;\n};\n\n/**\n * Data service responsible for fetching positions, interest, cash-flow\n * history, and vault rate history from the Money Account APY Tracking API.\n */\nexport class MoneyAccountApiDataService extends BaseDataService<\n typeof serviceName,\n MoneyAccountApiDataServiceMessenger\n> {\n readonly #baseUrl: string;\n\n readonly #trace: MoneyAccountApiDataServiceTraceCallback;\n\n /**\n * Constructs a new MoneyAccountApiDataService.\n *\n * @param options - The constructor arguments.\n * @param options.messenger - The messenger suited for this service.\n * @param options.env - The target environment. Defaults to production.\n * @param options.queryClientConfig - Configuration for the underlying\n * TanStack Query client.\n * @param options.policyOptions - Options to pass to `createServicePolicy`.\n * @param options.trace - Optional callback to trace network requests.\n */\n constructor({\n messenger,\n env = Env.PRD,\n queryClientConfig = {},\n policyOptions = {},\n trace,\n }: MoneyAccountApiDataServiceOptions) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions: {\n retryFilterPolicy: handleWhen(\n (error) =>\n !(error instanceof MoneyAccountApiResponseValidationError) &&\n !(error instanceof HttpError && error.httpStatus === 403),\n ),\n ...policyOptions,\n },\n });\n\n this.#baseUrl = MONEY_ACCOUNT_API_URL_MAP[env];\n\n this.#trace =\n trace ??\n (async <Result>(\n _request: MoneyAccountApiDataServiceTraceRequest,\n fn?: (context?: TraceContext) => Result,\n ): Promise<Result> => {\n return await Promise.resolve(fn?.() as Result);\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n log('Initialized', { env, baseUrl: this.#baseUrl });\n }\n\n /**\n * Builds best-effort authentication headers for a Money Account API request.\n *\n * Requests proceed without authentication when the wallet is locked, the\n * user is signed out, or the token is otherwise unavailable. The API edge\n * rate limiter falls back to IP-based limiting when the header is omitted.\n *\n * @returns The Authorization header when a profile token is available.\n */\n async #getRequestHeaders(): Promise<Record<string, string>> {\n try {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return token ? { Authorization: `Bearer ${token}` } : {};\n } catch (error: unknown) {\n log('Auth token unavailable, proceeding unauthenticated', error);\n return {};\n }\n }\n\n /**\n * Fetches the current vault positions for a given user address.\n *\n * @param address - The user's Ethereum address.\n * @returns The position response containing vault positions and an optional\n * `balance` summary (`null` when the API balance path is unavailable).\n */\n async fetchPositions(address: string): Promise<PositionResponse> {\n const url = new URL(\n `/v1/positions/${address.toLowerCase()}`,\n this.#baseUrl,\n );\n\n return this.fetchQuery({\n queryKey: [`${this.name}:fetchPositions`, address.toLowerCase()],\n staleTime: DEFAULT_STALE_TIME_MS,\n queryFn: async () => {\n return this.#traceNetworkRequest(\n {\n name: TRACES.POSITIONS_API,\n data: { operation: 'fetchPositions' },\n },\n async () => {\n const response = await fetch(url, {\n headers: await this.#getRequestHeaders(),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API positions request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(json, PositionResponseStruct);\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from positions endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as PositionResponse;\n },\n );\n },\n });\n }\n\n /**\n * Fetches the interest earned for a given address and vault over a\n * specified time window.\n *\n * @param address - The user's Ethereum address.\n * @param options - Options specifying vault, window, and optional chain ID.\n * @returns The interest response.\n */\n async fetchInterest(\n address: string,\n options: InterestOptions,\n ): Promise<InterestResponse> {\n const url = new URL(\n `/v1/positions/${address.toLowerCase()}/interest`,\n this.#baseUrl,\n );\n url.searchParams.append(\n 'vault_address',\n options.vaultAddress.toLowerCase(),\n );\n url.searchParams.append('window', options.window);\n if (options.chainId !== undefined) {\n url.searchParams.append('chain_id', String(options.chainId));\n }\n\n return this.fetchQuery({\n queryKey: [\n `${this.name}:fetchInterest`,\n address.toLowerCase(),\n options.vaultAddress.toLowerCase(),\n options.window,\n ...(options.chainId === undefined ? [] : [options.chainId]),\n ],\n staleTime: DEFAULT_STALE_TIME_MS,\n queryFn: async () => {\n return this.#traceNetworkRequest(\n {\n name: TRACES.INTEREST_API,\n data: { operation: 'fetchInterest' },\n },\n async () => {\n const response = await fetch(url, {\n headers: await this.#getRequestHeaders(),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API interest request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(json, InterestResponseStruct);\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from interest endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as InterestResponse;\n },\n );\n },\n });\n }\n\n /**\n * Fetches cursor-paginated cash-flow history for a given address.\n * Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.\n *\n * When paginating, consumers must re-pass the same filter options\n * (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page\n * request. This ensures the query key matches the original infinite query\n * and that the HTTP request includes the correct filters.\n *\n * @param address - The user's Ethereum address.\n * @param options - Optional filtering and pagination options.\n * @returns The history response containing cash-flow entries for the requested page.\n */\n async fetchHistory(\n address: string,\n options?: HistoryOptions,\n ): Promise<HistoryResponse> {\n const normalizedAddress = address.toLowerCase();\n const normalizedVault = options?.vaultAddress?.toLowerCase() ?? null;\n\n return this.fetchInfiniteQuery<HistoryResponse>(\n {\n queryKey: [\n `${this.name}:fetchHistory`,\n normalizedAddress,\n normalizedVault,\n options?.chainId ?? null,\n options?.limit ?? null,\n ],\n initialPageParam: null,\n getNextPageParam: (result) => result.next_cursor,\n staleTime: DEFAULT_STALE_TIME_MS,\n queryFn: async (context) => {\n const cursor = context.pageParam as string | null | undefined;\n\n const url = new URL(\n `/v1/positions/${normalizedAddress}/history`,\n this.#baseUrl,\n );\n if (normalizedVault) {\n url.searchParams.append('vault_address', normalizedVault);\n }\n if (options?.chainId !== undefined) {\n url.searchParams.append('chain_id', String(options.chainId));\n }\n if (cursor) {\n url.searchParams.append('cursor', cursor);\n }\n if (options?.limit !== undefined) {\n url.searchParams.append('limit', String(options.limit));\n }\n\n return this.#traceNetworkRequest(\n {\n name: TRACES.HISTORY_API,\n data: { operation: 'fetchHistory' },\n },\n async () => {\n const response = await fetch(url, {\n headers: await this.#getRequestHeaders(),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API history request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(json, HistoryResponseStruct);\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from history endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as HistoryResponse;\n },\n );\n },\n },\n options?.cursor ?? undefined,\n );\n }\n\n /**\n * Fetches the exchange-rate time series for a given vault.\n *\n * @param vaultAddress - The vault's Ethereum address.\n * @param options - Optional range and chain ID filters.\n * @returns The rate history response.\n */\n async fetchRateHistory(\n vaultAddress: string,\n options?: RateHistoryOptions,\n ): Promise<RateHistoryResponse> {\n const url = new URL(\n `/v1/vaults/${vaultAddress.toLowerCase()}/rate-history`,\n this.#baseUrl,\n );\n if (options?.chainId !== undefined) {\n url.searchParams.append('chain_id', String(options.chainId));\n }\n if (options?.from) {\n url.searchParams.append('from', options.from);\n }\n if (options?.to) {\n url.searchParams.append('to', options.to);\n }\n\n return this.fetchQuery({\n queryKey: [\n `${this.name}:fetchRateHistory`,\n vaultAddress.toLowerCase(),\n ...(options?.chainId === undefined ? [null] : [options.chainId]),\n ...(options?.from ? [options.from] : [null]),\n ...(options?.to ? [options.to] : [null]),\n ],\n staleTime: RATE_HISTORY_STALE_TIME_MS,\n queryFn: async () => {\n return this.#traceNetworkRequest(\n {\n name: TRACES.RATE_HISTORY_API,\n data: { operation: 'fetchRateHistory' },\n },\n async () => {\n const response = await fetch(url, {\n headers: await this.#getRequestHeaders(),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API rate-history request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(\n json,\n RateHistoryResponseStruct,\n );\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from rate-history endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as RateHistoryResponse;\n },\n );\n },\n });\n }\n\n /**\n * Runs a network request and emits a best-effort backdated trace.\n *\n * @param request - Trace metadata for the network request.\n * @param fn - Network request to execute.\n * @returns The network request result.\n */\n async #traceNetworkRequest<Result>(\n request: MoneyAccountApiDataServiceTraceRequest,\n fn: () => Promise<Result>,\n ): Promise<Result> {\n const startTime = Date.now();\n let success = false;\n let errorName: string | undefined;\n\n try {\n const result = await fn();\n success = true;\n return result;\n } catch (error) {\n errorName = error instanceof Error ? error.name : typeof error;\n throw error;\n } finally {\n const traceRequest = {\n ...request,\n startTime,\n data: {\n ...request.data,\n success,\n ...(errorName ? { errorName } : {}),\n },\n };\n const onTraceError = (traceError: unknown): void => {\n traceLogger('Failed to emit trace', {\n traceName: request.name,\n traceError,\n });\n };\n\n try {\n Promise.resolve(this.#trace(traceRequest, () => undefined)).catch(\n onTraceError,\n );\n } catch (traceError) {\n onTraceError(traceError);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"money-account-api-data-service.js","sourceRoot":"","sources":["../src/money-account-api-data-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAM9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD,OAAO,EACL,qBAAqB,EACrB,GAAG,EACH,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,sCAAsC,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQhE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAQtB,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAExD,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAC3D,MAAM,WAAW,GAAG,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,aAAa,EAAE,mCAAmC;IAClD,YAAY,EAAE,kCAAkC;IAChD,WAAW,EAAE,iCAAiC;IAC9C,gBAAgB,EAAE,sCAAsC;CAChD,CAAC;AAkBX,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,gBAAgB;IAChB,eAAe;IACf,cAAc;IACd,kBAAkB;CAC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AY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC;YAC/D,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,MAAM,YAAY,GAAG;gBACnB,GAAG,OAAO;gBACV,SAAS;gBACT,IAAI,EAAE;oBACJ,GAAG,OAAO,CAAC,IAAI;oBACf,OAAO;oBACP,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACpC;aACF,CAAC;YACF,MAAM,YAAY,GAAG,CAAC,UAAmB,EAAQ,EAAE;gBACjD,WAAW,CAAC,sBAAsB,EAAE;oBAClC,SAAS,EAAE,OAAO,CAAC,IAAI;oBACvB,UAAU;iBACX,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,IAAI,CAAC;gBACH,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAC/D,YAAY,CACb,CAAC;YACJ,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACpB,YAAY,CAAC,UAAU,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type {\n CreateServicePolicyOptions,\n TraceContext,\n TraceRequest,\n} from '@metamask/controller-utils';\nimport { handleWhen, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport { validate } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport {\n DEFAULT_STALE_TIME_MS,\n Env,\n MONEY_ACCOUNT_API_URL_MAP,\n RATE_HISTORY_STALE_TIME_MS,\n} from './constants.js';\nimport { MoneyAccountApiResponseValidationError } from './errors.js';\nimport { projectLogger, createModuleLogger } from './logger.js';\nimport type { MoneyAccountApiDataServiceMethodActions } from './money-account-api-data-service-method-action-types.js';\nimport type {\n HistoryResponse,\n InterestResponse,\n PositionResponse,\n RateHistoryResponse,\n} from './response.types.js';\nimport {\n HistoryResponseStruct,\n InterestResponseStruct,\n PositionResponseStruct,\n RateHistoryResponseStruct,\n} from './structs.js';\nimport type {\n HistoryOptions,\n InterestOptions,\n RateHistoryOptions,\n FetchPositionsOptions,\n} from './types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link MoneyAccountApiDataService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'MoneyAccountApiDataService';\n\nconst log = createModuleLogger(projectLogger, serviceName);\nconst traceLogger = createModuleLogger(projectLogger, 'trace');\n\nexport const TRACES = {\n POSITIONS_API: 'Money Account API Fetch Positions',\n INTEREST_API: 'Money Account API Fetch Interest',\n HISTORY_API: 'Money Account API Fetch History',\n RATE_HISTORY_API: 'Money Account API Fetch Rate History',\n} as const;\n\nexport type MoneyAccountApiDataServiceTraceName =\n (typeof TRACES)[keyof typeof TRACES];\n\nexport type MoneyAccountApiDataServiceTraceRequest = Omit<\n TraceRequest,\n 'name'\n> & {\n name: MoneyAccountApiDataServiceTraceName;\n startTime?: number;\n};\n\nexport type MoneyAccountApiDataServiceTraceCallback = <ReturnType>(\n request: MoneyAccountApiDataServiceTraceRequest,\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchPositions',\n 'fetchInterest',\n 'fetchHistory',\n 'fetchRateHistory',\n] as const;\n\n/**\n * Invalidates cached queries for {@link MoneyAccountApiDataService}.\n */\nexport type MoneyAccountApiDataServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link MoneyAccountApiDataService} exposes to other consumers.\n */\nexport type MoneyAccountApiDataServiceActions =\n | MoneyAccountApiDataServiceMethodActions\n | MoneyAccountApiDataServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link MoneyAccountApiDataService} calls.\n */\ntype AuthenticationControllerGetBearerTokenAction = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\ntype AllowedActions = AuthenticationControllerGetBearerTokenAction;\n\n/**\n * Published when {@link MoneyAccountApiDataService}'s cache is updated.\n */\nexport type MoneyAccountApiDataServiceCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link MoneyAccountApiDataService}'s cache is\n * updated.\n */\nexport type MoneyAccountApiDataServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link MoneyAccountApiDataService} exposes to other consumers.\n */\nexport type MoneyAccountApiDataServiceEvents =\n | MoneyAccountApiDataServiceCacheUpdatedEvent\n | MoneyAccountApiDataServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link MoneyAccountApiDataService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link MoneyAccountApiDataService}.\n */\nexport type MoneyAccountApiDataServiceMessenger = Messenger<\n typeof serviceName,\n MoneyAccountApiDataServiceActions | AllowedActions,\n MoneyAccountApiDataServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\nexport type MoneyAccountApiDataServiceOptions = {\n messenger: MoneyAccountApiDataServiceMessenger;\n env?: Env;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n trace?: MoneyAccountApiDataServiceTraceCallback;\n};\n\n/**\n * Data service responsible for fetching positions, interest, cash-flow\n * history, and vault rate history from the Money Account APY Tracking API.\n */\nexport class MoneyAccountApiDataService extends BaseDataService<\n typeof serviceName,\n MoneyAccountApiDataServiceMessenger\n> {\n readonly #baseUrl: string;\n\n readonly #trace: MoneyAccountApiDataServiceTraceCallback;\n\n /**\n * Constructs a new MoneyAccountApiDataService.\n *\n * @param options - The constructor arguments.\n * @param options.messenger - The messenger suited for this service.\n * @param options.env - The target environment. Defaults to production.\n * @param options.queryClientConfig - Configuration for the underlying\n * TanStack Query client.\n * @param options.policyOptions - Options to pass to `createServicePolicy`.\n * @param options.trace - Optional callback to trace network requests.\n */\n constructor({\n messenger,\n env = Env.PRD,\n queryClientConfig = {},\n policyOptions = {},\n trace,\n }: MoneyAccountApiDataServiceOptions) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions: {\n retryFilterPolicy: handleWhen(\n (error) =>\n !(error instanceof MoneyAccountApiResponseValidationError) &&\n !(error instanceof HttpError && error.httpStatus === 403),\n ),\n ...policyOptions,\n },\n });\n\n this.#baseUrl = MONEY_ACCOUNT_API_URL_MAP[env];\n\n this.#trace =\n trace ??\n (async <Result>(\n _request: MoneyAccountApiDataServiceTraceRequest,\n fn?: (context?: TraceContext) => Result,\n ): Promise<Result> => {\n return await Promise.resolve(fn?.() as Result);\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n log('Initialized', { env, baseUrl: this.#baseUrl });\n }\n\n /**\n * Builds best-effort authentication headers for a Money Account API request.\n *\n * Requests proceed without authentication when the wallet is locked, the\n * user is signed out, or the token is otherwise unavailable. The API edge\n * rate limiter falls back to IP-based limiting when the header is omitted.\n *\n * @returns The Authorization header when a profile token is available.\n */\n async #getRequestHeaders(): Promise<Record<string, string>> {\n try {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return token ? { Authorization: `Bearer ${token}` } : {};\n } catch (error: unknown) {\n log('Auth token unavailable, proceeding unauthenticated', error);\n return {};\n }\n }\n\n /**\n * Fetches the current vault positions for a given user address.\n *\n * @param address - The user's Ethereum address.\n * @param options - Optional fetch options.\n * @param options.fresh - When true, cancels in-flight reads, invalidates the\n * client cache, and fetches with `Cache-Control: no-cache` **without**\n * writing through TanStack — so a caller that later rejects the body\n * (e.g. `minBlock` freshness) cannot leave a warm pre-tx entry for the\n * next steady-state poll. Asks the Money API to skip its Nest response\n * cache when that server honors the header.\n * @returns The position response containing vault positions and an optional\n * `balance` summary (`null` when the API balance path is unavailable).\n */\n async fetchPositions(\n address: string,\n options?: FetchPositionsOptions,\n ): Promise<PositionResponse> {\n const normalizedAddress = address.toLowerCase();\n const fresh = options?.fresh === true;\n const queryKey = [\n `${this.name}:fetchPositions`,\n normalizedAddress,\n ] as const;\n\n if (fresh) {\n // Cancel any in-flight non-fresh fetch so it cannot win the shared\n // queryKey and re-seed a response that omitted Cache-Control: no-cache.\n await this.cancelQueries({ queryKey: [...queryKey] });\n await this.invalidateQueries({ queryKey: [...queryKey] });\n // Bypass fetchQuery: a minBlock-rejected body must not become the\n // steady-state cache entry with a fresh dataUpdatedAt.\n return await this.#fetchPositionsFromNetwork(normalizedAddress, true);\n }\n\n return this.fetchQuery({\n queryKey: [...queryKey],\n staleTime: DEFAULT_STALE_TIME_MS,\n queryFn: async () => {\n return this.#fetchPositionsFromNetwork(normalizedAddress, false);\n },\n });\n }\n\n /**\n * Performs the HTTP GET for `/v1/positions/:address`.\n *\n * @param normalizedAddress - Lowercased account address.\n * @param fresh - When true, send `Cache-Control: no-cache`.\n * @returns Validated positions response.\n */\n async #fetchPositionsFromNetwork(\n normalizedAddress: string,\n fresh: boolean,\n ): Promise<PositionResponse> {\n const url = new URL(`/v1/positions/${normalizedAddress}`, this.#baseUrl);\n\n return this.#traceNetworkRequest(\n {\n name: TRACES.POSITIONS_API,\n data: {\n operation: 'fetchPositions',\n ...(fresh ? { fresh: true } : {}),\n },\n },\n async () => {\n const headers = {\n ...(await this.#getRequestHeaders()),\n ...(fresh ? { 'Cache-Control': 'no-cache' } : {}),\n };\n\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API positions request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(json, PositionResponseStruct);\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from positions endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as PositionResponse;\n },\n );\n }\n\n /**\n * Fetches the interest earned for a given address and vault over a\n * specified time window.\n *\n * @param address - The user's Ethereum address.\n * @param options - Options specifying vault, window, and optional chain ID.\n * @returns The interest response.\n */\n async fetchInterest(\n address: string,\n options: InterestOptions,\n ): Promise<InterestResponse> {\n const url = new URL(\n `/v1/positions/${address.toLowerCase()}/interest`,\n this.#baseUrl,\n );\n url.searchParams.append(\n 'vault_address',\n options.vaultAddress.toLowerCase(),\n );\n url.searchParams.append('window', options.window);\n if (options.chainId !== undefined) {\n url.searchParams.append('chain_id', String(options.chainId));\n }\n\n return this.fetchQuery({\n queryKey: [\n `${this.name}:fetchInterest`,\n address.toLowerCase(),\n options.vaultAddress.toLowerCase(),\n options.window,\n ...(options.chainId === undefined ? [] : [options.chainId]),\n ],\n staleTime: DEFAULT_STALE_TIME_MS,\n queryFn: async () => {\n return this.#traceNetworkRequest(\n {\n name: TRACES.INTEREST_API,\n data: { operation: 'fetchInterest' },\n },\n async () => {\n const response = await fetch(url, {\n headers: await this.#getRequestHeaders(),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API interest request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(json, InterestResponseStruct);\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from interest endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as InterestResponse;\n },\n );\n },\n });\n }\n\n /**\n * Fetches cursor-paginated cash-flow history for a given address.\n * Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.\n *\n * When paginating, consumers must re-pass the same filter options\n * (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page\n * request. This ensures the query key matches the original infinite query\n * and that the HTTP request includes the correct filters.\n *\n * @param address - The user's Ethereum address.\n * @param options - Optional filtering and pagination options.\n * @returns The history response containing cash-flow entries for the requested page.\n */\n async fetchHistory(\n address: string,\n options?: HistoryOptions,\n ): Promise<HistoryResponse> {\n const normalizedAddress = address.toLowerCase();\n const normalizedVault = options?.vaultAddress?.toLowerCase() ?? null;\n\n return this.fetchInfiniteQuery<HistoryResponse>(\n {\n queryKey: [\n `${this.name}:fetchHistory`,\n normalizedAddress,\n normalizedVault,\n options?.chainId ?? null,\n options?.limit ?? null,\n ],\n initialPageParam: null,\n getNextPageParam: (result) => result.next_cursor,\n staleTime: DEFAULT_STALE_TIME_MS,\n queryFn: async (context) => {\n const cursor = context.pageParam as string | null | undefined;\n\n const url = new URL(\n `/v1/positions/${normalizedAddress}/history`,\n this.#baseUrl,\n );\n if (normalizedVault) {\n url.searchParams.append('vault_address', normalizedVault);\n }\n if (options?.chainId !== undefined) {\n url.searchParams.append('chain_id', String(options.chainId));\n }\n if (cursor) {\n url.searchParams.append('cursor', cursor);\n }\n if (options?.limit !== undefined) {\n url.searchParams.append('limit', String(options.limit));\n }\n\n return this.#traceNetworkRequest(\n {\n name: TRACES.HISTORY_API,\n data: { operation: 'fetchHistory' },\n },\n async () => {\n const response = await fetch(url, {\n headers: await this.#getRequestHeaders(),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API history request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(json, HistoryResponseStruct);\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from history endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as HistoryResponse;\n },\n );\n },\n },\n options?.cursor ?? undefined,\n );\n }\n\n /**\n * Fetches the exchange-rate time series for a given vault.\n *\n * @param vaultAddress - The vault's Ethereum address.\n * @param options - Optional range and chain ID filters.\n * @returns The rate history response.\n */\n async fetchRateHistory(\n vaultAddress: string,\n options?: RateHistoryOptions,\n ): Promise<RateHistoryResponse> {\n const url = new URL(\n `/v1/vaults/${vaultAddress.toLowerCase()}/rate-history`,\n this.#baseUrl,\n );\n if (options?.chainId !== undefined) {\n url.searchParams.append('chain_id', String(options.chainId));\n }\n if (options?.from) {\n url.searchParams.append('from', options.from);\n }\n if (options?.to) {\n url.searchParams.append('to', options.to);\n }\n\n return this.fetchQuery({\n queryKey: [\n `${this.name}:fetchRateHistory`,\n vaultAddress.toLowerCase(),\n ...(options?.chainId === undefined ? [null] : [options.chainId]),\n ...(options?.from ? [options.from] : [null]),\n ...(options?.to ? [options.to] : [null]),\n ],\n staleTime: RATE_HISTORY_STALE_TIME_MS,\n queryFn: async () => {\n return this.#traceNetworkRequest(\n {\n name: TRACES.RATE_HISTORY_API,\n data: { operation: 'fetchRateHistory' },\n },\n async () => {\n const response = await fetch(url, {\n headers: await this.#getRequestHeaders(),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Money Account API rate-history request failed with status '${response.status}'`,\n );\n }\n\n const json: Json = await response.json();\n\n const [error, validated] = validate(\n json,\n RateHistoryResponseStruct,\n );\n if (error) {\n throw new MoneyAccountApiResponseValidationError(\n `Malformed response from rate-history endpoint: ${error.message}`,\n );\n }\n\n return validated as unknown as RateHistoryResponse;\n },\n );\n },\n });\n }\n\n /**\n * Runs a network request and emits a best-effort backdated trace.\n *\n * @param request - Trace metadata for the network request.\n * @param fn - Network request to execute.\n * @returns The network request result.\n */\n async #traceNetworkRequest<Result>(\n request: MoneyAccountApiDataServiceTraceRequest,\n fn: () => Promise<Result>,\n ): Promise<Result> {\n const startTime = Date.now();\n let success = false;\n let errorName: string | undefined;\n\n try {\n const result = await fn();\n success = true;\n return result;\n } catch (error) {\n errorName = error instanceof Error ? error.name : typeof error;\n throw error;\n } finally {\n const traceRequest = {\n ...request,\n startTime,\n data: {\n ...request.data,\n success,\n ...(errorName ? { errorName } : {}),\n },\n };\n const onTraceError = (traceError: unknown): void => {\n traceLogger('Failed to emit trace', {\n traceName: request.name,\n traceError,\n });\n };\n\n try {\n Promise.resolve(this.#trace(traceRequest, () => undefined)).catch(\n onTraceError,\n );\n } catch (traceError) {\n onTraceError(traceError);\n }\n }\n }\n}\n"]}
@@ -29,6 +29,8 @@ export type PositionBalance = {
29
29
  musd_balance: string;
30
30
  vmusd_value_in_musd: string;
31
31
  total_balance: string;
32
+ /** ISO-8601 timestamp of the last wallet mUSD observation, when provided. */
33
+ musd_balance_updated_at?: string | null;
32
34
  };
33
35
  /**
34
36
  * Response from `GET /v1/positions/:address`.
@@ -1 +1 @@
1
- {"version":3,"file":"response.types.d.ts","sourceRoot":"","sources":["../src/response.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EAC1B,MAAM,cAAc,CAAC;AAMtB;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,uBAAuB,EAAE,MAAM,CAAC;IAChC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,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AC1B,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"response.types.js","sourceRoot":"","sources":["../src/response.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Infer } from '@metamask/superstruct';\n\nimport type {\n HistoryResponseStruct,\n InterestResponseStruct,\n PositionResponseStruct,\n RateHistoryResponseStruct,\n} from './structs.js';\n\n// All types in this file mirror the external Money Account API's snake_case\n// JSON contract verbatim to maintain 1:1 parity with API responses.\n/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n * Data freshness indicator returned by all business endpoints.\n */\nexport type DataFreshness = 'live' | 'degraded';\n\n/**\n * A single vault position within the positions response.\n */\nexport type VaultPosition = {\n vault_address: string;\n shares_held: string;\n current_rate: string;\n current_value_assets: string;\n current_value_usd: string;\n cost_basis_assets: string;\n cost_basis_usd: string;\n realized_interest_usd: string;\n unrealised_interest_usd: string;\n lifetime_interest_usd: string;\n current_apy: string;\n effective_apy: string;\n};\n\n/**\n * Balance summary on the positions response.\n * `null` when the API's wallet-balance path is disabled or unavailable.\n */\nexport type PositionBalance = {\n musd_balance: string;\n vmusd_value_in_musd: string;\n total_balance: string;\n};\n\n/**\n * Response from `GET /v1/positions/:address`.\n * Derived from {@link PositionResponseStruct} to ensure type/struct parity.\n */\nexport type PositionResponse = Infer<typeof PositionResponseStruct>;\n\n/**\n * Response from `GET /v1/positions/:address/interest`.\n * Derived from {@link InterestResponseStruct} to ensure type/struct parity.\n */\nexport type InterestResponse = Infer<typeof InterestResponseStruct>;\n\n/**\n * Cash-flow type for the history endpoint.\n */\nexport type CashFlowType =\n | 'deposit'\n | 'withdraw'\n | 'transfer_in'\n | 'transfer_out';\n\n/**\n * Cash-flow source label.\n */\nexport type CashFlowSource =\n | 'teller'\n | 'withdraw_queue'\n | 'atomic_queue'\n | 'erc20_transfer'\n | 'cross_chain';\n\n/**\n * A single entry in the cash-flow history.\n */\nexport type CashFlowEntry = {\n type: CashFlowType;\n chain_id: number;\n vault_address: string;\n timestamp: string;\n block_number: number;\n log_index: number;\n tx_hash: string;\n assets_usd: string;\n assets_wei: string;\n shares_wei: string;\n rate: string;\n source: CashFlowSource;\n};\n\n/**\n * Response from `GET /v1/positions/:address/history`.\n * Derived from {@link HistoryResponseStruct} to ensure type/struct parity.\n */\nexport type HistoryResponse = Infer<typeof HistoryResponseStruct>;\n\n/**\n * A single entry in the rate-history time series.\n */\nexport type RateHistoryEntry = {\n timestamp: string;\n block_number: number;\n rate: string;\n tx_hash: string;\n};\n\n/**\n * Response from `GET /v1/vaults/:address/rate-history`.\n * Derived from {@link RateHistoryResponseStruct} to ensure type/struct parity.\n */\nexport type RateHistoryResponse = Infer<typeof RateHistoryResponseStruct>;\n"]}
1
+ {"version":3,"file":"response.types.js","sourceRoot":"","sources":["../src/response.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Infer } from '@metamask/superstruct';\n\nimport type {\n HistoryResponseStruct,\n InterestResponseStruct,\n PositionResponseStruct,\n RateHistoryResponseStruct,\n} from './structs.js';\n\n// All types in this file mirror the external Money Account API's snake_case\n// JSON contract verbatim to maintain 1:1 parity with API responses.\n/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n * Data freshness indicator returned by all business endpoints.\n */\nexport type DataFreshness = 'live' | 'degraded';\n\n/**\n * A single vault position within the positions response.\n */\nexport type VaultPosition = {\n vault_address: string;\n shares_held: string;\n current_rate: string;\n current_value_assets: string;\n current_value_usd: string;\n cost_basis_assets: string;\n cost_basis_usd: string;\n realized_interest_usd: string;\n unrealised_interest_usd: string;\n lifetime_interest_usd: string;\n current_apy: string;\n effective_apy: string;\n};\n\n/**\n * Balance summary on the positions response.\n * `null` when the API's wallet-balance path is disabled or unavailable.\n */\nexport type PositionBalance = {\n musd_balance: string;\n vmusd_value_in_musd: string;\n total_balance: string;\n /** ISO-8601 timestamp of the last wallet mUSD observation, when provided. */\n musd_balance_updated_at?: string | null;\n};\n\n/**\n * Response from `GET /v1/positions/:address`.\n * Derived from {@link PositionResponseStruct} to ensure type/struct parity.\n */\nexport type PositionResponse = Infer<typeof PositionResponseStruct>;\n\n/**\n * Response from `GET /v1/positions/:address/interest`.\n * Derived from {@link InterestResponseStruct} to ensure type/struct parity.\n */\nexport type InterestResponse = Infer<typeof InterestResponseStruct>;\n\n/**\n * Cash-flow type for the history endpoint.\n */\nexport type CashFlowType =\n | 'deposit'\n | 'withdraw'\n | 'transfer_in'\n | 'transfer_out';\n\n/**\n * Cash-flow source label.\n */\nexport type CashFlowSource =\n | 'teller'\n | 'withdraw_queue'\n | 'atomic_queue'\n | 'erc20_transfer'\n | 'cross_chain';\n\n/**\n * A single entry in the cash-flow history.\n */\nexport type CashFlowEntry = {\n type: CashFlowType;\n chain_id: number;\n vault_address: string;\n timestamp: string;\n block_number: number;\n log_index: number;\n tx_hash: string;\n assets_usd: string;\n assets_wei: string;\n shares_wei: string;\n rate: string;\n source: CashFlowSource;\n};\n\n/**\n * Response from `GET /v1/positions/:address/history`.\n * Derived from {@link HistoryResponseStruct} to ensure type/struct parity.\n */\nexport type HistoryResponse = Infer<typeof HistoryResponseStruct>;\n\n/**\n * A single entry in the rate-history time series.\n */\nexport type RateHistoryEntry = {\n timestamp: string;\n block_number: number;\n rate: string;\n tx_hash: string;\n};\n\n/**\n * Response from `GET /v1/vaults/:address/rate-history`.\n * Derived from {@link RateHistoryResponseStruct} to ensure type/struct parity.\n */\nexport type RateHistoryResponse = Infer<typeof RateHistoryResponseStruct>;\n"]}
package/dist/structs.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare const PositionResponseStruct: import("@metamask/superstruct").Str
8
8
  musd_balance: string;
9
9
  vmusd_value_in_musd: string;
10
10
  total_balance: string;
11
+ musd_balance_updated_at?: string | null | undefined;
11
12
  } | null | undefined;
12
13
  positions: {
13
14
  vault_address: string;
@@ -36,10 +37,12 @@ export declare const PositionResponseStruct: import("@metamask/superstruct").Str
36
37
  musd_balance: string;
37
38
  vmusd_value_in_musd: string;
38
39
  total_balance: string;
40
+ musd_balance_updated_at?: string | null | undefined;
39
41
  } | null | undefined, {
40
42
  musd_balance: import("@metamask/superstruct").Struct<string, null>;
41
43
  vmusd_value_in_musd: import("@metamask/superstruct").Struct<string, null>;
42
44
  total_balance: import("@metamask/superstruct").Struct<string, null>;
45
+ musd_balance_updated_at: import("@metamask/superstruct").Struct<string | null | undefined, null>;
43
46
  }>;
44
47
  positions: import("@metamask/superstruct").Struct<{
45
48
  vault_address: string;
@@ -1 +1 @@
1
- {"version":3,"file":"structs.d.ts","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AAsCA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUjC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAajC,CAAC;AAuBH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAShC,CAAC;AASH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUpC,CAAC"}
1
+ {"version":3,"file":"structs.d.ts","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AAwCA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUjC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAajC,CAAC;AAuBH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAShC,CAAC;AASH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUpC,CAAC"}
package/dist/structs.js CHANGED
@@ -22,6 +22,8 @@ const PositionBalanceStruct = object({
22
22
  musd_balance: string(),
23
23
  vmusd_value_in_musd: string(),
24
24
  total_balance: string(),
25
+ // Additive — older API builds omit this field.
26
+ musd_balance_updated_at: optional(nullable(string())),
25
27
  });
26
28
  export const PositionResponseStruct = object({
27
29
  address: string(),
@@ -1 +1 @@
1
- {"version":3,"file":"structs.js","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,GACP,MAAM,uBAAuB,CAAC;AAE/B,MAAM,mBAAmB,GAAG,KAAK,CAAC,CAAC,MAAM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AO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;IAC9C,aAAa,EAAE,MAAM,EAAE;IACvB,QAAQ,EAAE,MAAM,EAAE;IAClB,WAAW,EAAE,MAAM,EAAE;IACrB,SAAS,EAAE,MAAM,EAAE;IACnB,KAAK,EAAE,KAAK,CAAC,sBAAsB,CAAC;IACpC,WAAW,EAAE,MAAM,EAAE;IACrB,eAAe,EAAE,MAAM,EAAE;IACzB,cAAc,EAAE,mBAAmB;IACnC,mBAAmB,EAAE,MAAM,EAAE;CAC9B,CAAC,CAAC","sourcesContent":["import {\n array,\n boolean,\n enums,\n nullable,\n number,\n object,\n optional,\n string,\n} from '@metamask/superstruct';\n\nconst DataFreshnessStruct = enums(['live', 'degraded']);\n\nconst VaultPositionStruct = object({\n vault_address: string(),\n shares_held: string(),\n current_rate: string(),\n current_value_assets: string(),\n current_value_usd: string(),\n cost_basis_assets: string(),\n cost_basis_usd: string(),\n realized_interest_usd: string(),\n unrealised_interest_usd: string(),\n lifetime_interest_usd: string(),\n current_apy: string(),\n effective_apy: string(),\n});\n\n/**\n * Wallet + vault balance summary on the positions response.\n * `null` when the API's wallet-balance path is disabled or unavailable.\n */\nconst PositionBalanceStruct = object({\n musd_balance: string(),\n vmusd_value_in_musd: string(),\n total_balance: string(),\n});\n\nexport const PositionResponseStruct = object({\n address: string(),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n // Optional for backwards compatibility with responses that omit the field;\n // when present, may be `null` if the API balance flag is off.\n balance: optional(nullable(PositionBalanceStruct)),\n positions: array(VaultPositionStruct),\n});\n\nexport const InterestResponseStruct = object({\n address: string(),\n vault_address: string(),\n window: string(),\n window_start: string(),\n window_end: string(),\n interest_earned_assets: string(),\n interest_earned_usd: string(),\n method: string(),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n});\n\nconst CashFlowEntryStruct = object({\n type: enums(['deposit', 'withdraw', 'transfer_in', 'transfer_out']),\n chain_id: number(),\n vault_address: string(),\n timestamp: string(),\n block_number: number(),\n log_index: number(),\n tx_hash: string(),\n assets_usd: string(),\n assets_wei: string(),\n shares_wei: string(),\n rate: string(),\n source: enums([\n 'teller',\n 'withdraw_queue',\n 'atomic_queue',\n 'erc20_transfer',\n 'cross_chain',\n ]),\n});\n\nexport const HistoryResponseStruct = object({\n address: string(),\n cash_flows: array(CashFlowEntryStruct),\n next_cursor: nullable(string()),\n has_more: boolean(),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n});\n\nconst RateHistoryEntryStruct = object({\n timestamp: string(),\n block_number: number(),\n rate: string(),\n tx_hash: string(),\n});\n\nexport const RateHistoryResponseStruct = object({\n vault_address: string(),\n chain_id: number(),\n range_start: string(),\n range_end: string(),\n rates: array(RateHistoryEntryStruct),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n});\n"]}
1
+ {"version":3,"file":"structs.js","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,GACP,MAAM,uBAAuB,CAAC;AAE/B,MAAM,mBAAmB,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AAExD,MAAM,mBAAmB,GAAG,MAAM,CAAC;IACjC,aAAa,EAAE,MAAM,EAAE;IACvB,WAAW,EAAE,MAAM,EAAE;IACrB,YAAY,EAAE,MAAM,EAAE;IACtB,oBAAoB,EAAE,MAAM,EAAE;IAC9B,iBAAiB,EAAE,MAAM,EAAE;IAC3B,iBAAiB,EAAE,MAAM,EAAE;IAC3B,cAAc,EAAE,MAAM,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E,MAAM,EAAE;IACnB,KAAK,EAAE,KAAK,CAAC,sBAAsB,CAAC;IACpC,WAAW,EAAE,MAAM,EAAE;IACrB,eAAe,EAAE,MAAM,EAAE;IACzB,cAAc,EAAE,mBAAmB;IACnC,mBAAmB,EAAE,MAAM,EAAE;CAC9B,CAAC,CAAC","sourcesContent":["import {\n array,\n boolean,\n enums,\n nullable,\n number,\n object,\n optional,\n string,\n} from '@metamask/superstruct';\n\nconst DataFreshnessStruct = enums(['live', 'degraded']);\n\nconst VaultPositionStruct = object({\n vault_address: string(),\n shares_held: string(),\n current_rate: string(),\n current_value_assets: string(),\n current_value_usd: string(),\n cost_basis_assets: string(),\n cost_basis_usd: string(),\n realized_interest_usd: string(),\n unrealised_interest_usd: string(),\n lifetime_interest_usd: string(),\n current_apy: string(),\n effective_apy: string(),\n});\n\n/**\n * Wallet + vault balance summary on the positions response.\n * `null` when the API's wallet-balance path is disabled or unavailable.\n */\nconst PositionBalanceStruct = object({\n musd_balance: string(),\n vmusd_value_in_musd: string(),\n total_balance: string(),\n // Additive — older API builds omit this field.\n musd_balance_updated_at: optional(nullable(string())),\n});\n\nexport const PositionResponseStruct = object({\n address: string(),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n // Optional for backwards compatibility with responses that omit the field;\n // when present, may be `null` if the API balance flag is off.\n balance: optional(nullable(PositionBalanceStruct)),\n positions: array(VaultPositionStruct),\n});\n\nexport const InterestResponseStruct = object({\n address: string(),\n vault_address: string(),\n window: string(),\n window_start: string(),\n window_end: string(),\n interest_earned_assets: string(),\n interest_earned_usd: string(),\n method: string(),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n});\n\nconst CashFlowEntryStruct = object({\n type: enums(['deposit', 'withdraw', 'transfer_in', 'transfer_out']),\n chain_id: number(),\n vault_address: string(),\n timestamp: string(),\n block_number: number(),\n log_index: number(),\n tx_hash: string(),\n assets_usd: string(),\n assets_wei: string(),\n shares_wei: string(),\n rate: string(),\n source: enums([\n 'teller',\n 'withdraw_queue',\n 'atomic_queue',\n 'erc20_transfer',\n 'cross_chain',\n ]),\n});\n\nexport const HistoryResponseStruct = object({\n address: string(),\n cash_flows: array(CashFlowEntryStruct),\n next_cursor: nullable(string()),\n has_more: boolean(),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n});\n\nconst RateHistoryEntryStruct = object({\n timestamp: string(),\n block_number: number(),\n rate: string(),\n tx_hash: string(),\n});\n\nexport const RateHistoryResponseStruct = object({\n vault_address: string(),\n chain_id: number(),\n range_start: string(),\n range_end: string(),\n rates: array(RateHistoryEntryStruct),\n as_of_block: number(),\n as_of_timestamp: string(),\n data_freshness: DataFreshnessStruct,\n indexer_lag_seconds: number(),\n});\n"]}
package/dist/types.d.ts CHANGED
@@ -10,6 +10,18 @@ export type InterestOptions = {
10
10
  window: InterestWindow;
11
11
  chainId?: number;
12
12
  };
13
+ /**
14
+ * Options for the `fetchPositions` method.
15
+ */
16
+ export type FetchPositionsOptions = {
17
+ /**
18
+ * When true, bypass the client TanStack cache and send
19
+ * `Cache-Control: no-cache` so the Money API also skips its Nest
20
+ * response cache and refreshes the wallet mUSD balance on demand.
21
+ * Intended for post-transaction read-your-writes refreshes.
22
+ */
23
+ fresh?: boolean;
24
+ };
13
25
  /**
14
26
  * Options for the `fetchHistory` method.
15
27
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,iBAAiB,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,iBAAiB,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Valid time-window values for the interest endpoint.\n */\nexport type InterestWindow = '24h' | '7d' | '30d' | 'ytd' | 'since_inception';\n\n/**\n * Options for the `fetchInterest` method.\n */\nexport type InterestOptions = {\n vaultAddress: string;\n window: InterestWindow;\n chainId?: number;\n};\n\n/**\n * Options for the `fetchHistory` method.\n */\nexport type HistoryOptions = {\n vaultAddress?: string;\n chainId?: number;\n cursor?: string;\n limit?: number;\n};\n\n/**\n * Options for the `fetchRateHistory` method.\n */\nexport type RateHistoryOptions = {\n chainId?: number;\n from?: string;\n to?: string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Valid time-window values for the interest endpoint.\n */\nexport type InterestWindow = '24h' | '7d' | '30d' | 'ytd' | 'since_inception';\n\n/**\n * Options for the `fetchInterest` method.\n */\nexport type InterestOptions = {\n vaultAddress: string;\n window: InterestWindow;\n chainId?: number;\n};\n\n/**\n * Options for the `fetchPositions` method.\n */\nexport type FetchPositionsOptions = {\n /**\n * When true, bypass the client TanStack cache and send\n * `Cache-Control: no-cache` so the Money API also skips its Nest\n * response cache and refreshes the wallet mUSD balance on demand.\n * Intended for post-transaction read-your-writes refreshes.\n */\n fresh?: boolean;\n};\n\n/**\n * Options for the `fetchHistory` method.\n */\nexport type HistoryOptions = {\n vaultAddress?: string;\n chainId?: number;\n cursor?: string;\n limit?: number;\n};\n\n/**\n * Options for the `fetchRateHistory` method.\n */\nexport type RateHistoryOptions = {\n chainId?: number;\n from?: string;\n to?: string;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/money-account-api-data-service",
3
- "version": "1.0.0-preview-d2ea3cc",
3
+ "version": "1.0.0-preview-acac4ba67",
4
4
  "description": "Data service for fetching Money account positions, interest, cash-flow history, and vault rate history from the Money Account API",
5
5
  "keywords": [
6
6
  "Ethereum",