@metamask/money-account-api-data-service 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/LICENSE.APACHE2 +201 -0
- package/LICENSE.MIT +21 -0
- package/README.md +26 -0
- package/dist/constants.cjs +31 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +23 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +23 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +28 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/errors.cjs +16 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +8 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +8 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +12 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +10 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +4 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/money-account-api-data-service-method-action-types.cjs +7 -0
- package/dist/money-account-api-data-service-method-action-types.cjs.map +1 -0
- package/dist/money-account-api-data-service-method-action-types.d.cts +60 -0
- package/dist/money-account-api-data-service-method-action-types.d.cts.map +1 -0
- package/dist/money-account-api-data-service-method-action-types.d.mts +60 -0
- package/dist/money-account-api-data-service-method-action-types.d.mts.map +1 -0
- package/dist/money-account-api-data-service-method-action-types.mjs +6 -0
- package/dist/money-account-api-data-service-method-action-types.mjs.map +1 -0
- package/dist/money-account-api-data-service.cjs +228 -0
- package/dist/money-account-api-data-service.cjs.map +1 -0
- package/dist/money-account-api-data-service.d.cts +112 -0
- package/dist/money-account-api-data-service.d.cts.map +1 -0
- package/dist/money-account-api-data-service.d.mts +112 -0
- package/dist/money-account-api-data-service.d.mts.map +1 -0
- package/dist/money-account-api-data-service.mjs +224 -0
- package/dist/money-account-api-data-service.mjs.map +1 -0
- package/dist/response.types.cjs +3 -0
- package/dist/response.types.cjs.map +1 -0
- package/dist/response.types.d.cts +78 -0
- package/dist/response.types.d.cts.map +1 -0
- package/dist/response.types.d.mts +78 -0
- package/dist/response.types.d.mts.map +1 -0
- package/dist/response.types.mjs +2 -0
- package/dist/response.types.mjs.map +1 -0
- package/dist/structs.cjs +89 -0
- package/dist/structs.cjs.map +1 -0
- package/dist/structs.d.cts +230 -0
- package/dist/structs.d.cts.map +1 -0
- package/dist/structs.d.mts +230 -0
- package/dist/structs.d.mts.map +1 -0
- package/dist/structs.mjs +86 -0
- package/dist/structs.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +30 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +30 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { MoneyAccountApiDataService } from "./money-account-api-data-service.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the current vault positions for a given user address.
|
|
8
|
+
*
|
|
9
|
+
* @param address - The user's Ethereum address.
|
|
10
|
+
* @returns The position response containing vault positions.
|
|
11
|
+
*/
|
|
12
|
+
export type MoneyAccountApiDataServiceFetchPositionsAction = {
|
|
13
|
+
type: `MoneyAccountApiDataService:fetchPositions`;
|
|
14
|
+
handler: MoneyAccountApiDataService['fetchPositions'];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Fetches the interest earned for a given address and vault over a
|
|
18
|
+
* specified time window.
|
|
19
|
+
*
|
|
20
|
+
* @param address - The user's Ethereum address.
|
|
21
|
+
* @param options - Options specifying vault, window, and optional chain ID.
|
|
22
|
+
* @returns The interest response.
|
|
23
|
+
*/
|
|
24
|
+
export type MoneyAccountApiDataServiceFetchInterestAction = {
|
|
25
|
+
type: `MoneyAccountApiDataService:fetchInterest`;
|
|
26
|
+
handler: MoneyAccountApiDataService['fetchInterest'];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Fetches cursor-paginated cash-flow history for a given address.
|
|
30
|
+
* Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.
|
|
31
|
+
*
|
|
32
|
+
* When paginating, consumers must re-pass the same filter options
|
|
33
|
+
* (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page
|
|
34
|
+
* request. This ensures the query key matches the original infinite query
|
|
35
|
+
* and that the HTTP request includes the correct filters.
|
|
36
|
+
*
|
|
37
|
+
* @param address - The user's Ethereum address.
|
|
38
|
+
* @param options - Optional filtering and pagination options.
|
|
39
|
+
* @returns The history response containing cash-flow entries for the requested page.
|
|
40
|
+
*/
|
|
41
|
+
export type MoneyAccountApiDataServiceFetchHistoryAction = {
|
|
42
|
+
type: `MoneyAccountApiDataService:fetchHistory`;
|
|
43
|
+
handler: MoneyAccountApiDataService['fetchHistory'];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Fetches the exchange-rate time series for a given vault.
|
|
47
|
+
*
|
|
48
|
+
* @param vaultAddress - The vault's Ethereum address.
|
|
49
|
+
* @param options - Optional range and chain ID filters.
|
|
50
|
+
* @returns The rate history response.
|
|
51
|
+
*/
|
|
52
|
+
export type MoneyAccountApiDataServiceFetchRateHistoryAction = {
|
|
53
|
+
type: `MoneyAccountApiDataService:fetchRateHistory`;
|
|
54
|
+
handler: MoneyAccountApiDataService['fetchRateHistory'];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Union of all MoneyAccountApiDataService action types.
|
|
58
|
+
*/
|
|
59
|
+
export type MoneyAccountApiDataServiceMethodActions = MoneyAccountApiDataServiceFetchPositionsAction | MoneyAccountApiDataServiceFetchInterestAction | MoneyAccountApiDataServiceFetchHistoryAction | MoneyAccountApiDataServiceFetchRateHistoryAction;
|
|
60
|
+
//# sourceMappingURL=money-account-api-data-service-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-api-data-service-method-action-types.d.cts","sourceRoot":"","sources":["../src/money-account-api-data-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,6CAAyC;AAEnF;;;;;GAKG;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"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { MoneyAccountApiDataService } from "./money-account-api-data-service.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the current vault positions for a given user address.
|
|
8
|
+
*
|
|
9
|
+
* @param address - The user's Ethereum address.
|
|
10
|
+
* @returns The position response containing vault positions.
|
|
11
|
+
*/
|
|
12
|
+
export type MoneyAccountApiDataServiceFetchPositionsAction = {
|
|
13
|
+
type: `MoneyAccountApiDataService:fetchPositions`;
|
|
14
|
+
handler: MoneyAccountApiDataService['fetchPositions'];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Fetches the interest earned for a given address and vault over a
|
|
18
|
+
* specified time window.
|
|
19
|
+
*
|
|
20
|
+
* @param address - The user's Ethereum address.
|
|
21
|
+
* @param options - Options specifying vault, window, and optional chain ID.
|
|
22
|
+
* @returns The interest response.
|
|
23
|
+
*/
|
|
24
|
+
export type MoneyAccountApiDataServiceFetchInterestAction = {
|
|
25
|
+
type: `MoneyAccountApiDataService:fetchInterest`;
|
|
26
|
+
handler: MoneyAccountApiDataService['fetchInterest'];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Fetches cursor-paginated cash-flow history for a given address.
|
|
30
|
+
* Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.
|
|
31
|
+
*
|
|
32
|
+
* When paginating, consumers must re-pass the same filter options
|
|
33
|
+
* (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page
|
|
34
|
+
* request. This ensures the query key matches the original infinite query
|
|
35
|
+
* and that the HTTP request includes the correct filters.
|
|
36
|
+
*
|
|
37
|
+
* @param address - The user's Ethereum address.
|
|
38
|
+
* @param options - Optional filtering and pagination options.
|
|
39
|
+
* @returns The history response containing cash-flow entries for the requested page.
|
|
40
|
+
*/
|
|
41
|
+
export type MoneyAccountApiDataServiceFetchHistoryAction = {
|
|
42
|
+
type: `MoneyAccountApiDataService:fetchHistory`;
|
|
43
|
+
handler: MoneyAccountApiDataService['fetchHistory'];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Fetches the exchange-rate time series for a given vault.
|
|
47
|
+
*
|
|
48
|
+
* @param vaultAddress - The vault's Ethereum address.
|
|
49
|
+
* @param options - Optional range and chain ID filters.
|
|
50
|
+
* @returns The rate history response.
|
|
51
|
+
*/
|
|
52
|
+
export type MoneyAccountApiDataServiceFetchRateHistoryAction = {
|
|
53
|
+
type: `MoneyAccountApiDataService:fetchRateHistory`;
|
|
54
|
+
handler: MoneyAccountApiDataService['fetchRateHistory'];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Union of all MoneyAccountApiDataService action types.
|
|
58
|
+
*/
|
|
59
|
+
export type MoneyAccountApiDataServiceMethodActions = MoneyAccountApiDataServiceFetchPositionsAction | MoneyAccountApiDataServiceFetchInterestAction | MoneyAccountApiDataServiceFetchHistoryAction | MoneyAccountApiDataServiceFetchRateHistoryAction;
|
|
60
|
+
//# sourceMappingURL=money-account-api-data-service-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-api-data-service-method-action-types.d.mts","sourceRoot":"","sources":["../src/money-account-api-data-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,6CAAyC;AAEnF;;;;;GAKG;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-api-data-service-method-action-types.mjs","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';\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.\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"]}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MoneyAccountApiDataService_baseUrl;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MoneyAccountApiDataService = exports.serviceName = void 0;
|
|
16
|
+
const base_data_service_1 = require("@metamask/base-data-service");
|
|
17
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
19
|
+
const constants_1 = require("./constants.cjs");
|
|
20
|
+
const errors_1 = require("./errors.cjs");
|
|
21
|
+
const logger_1 = require("./logger.cjs");
|
|
22
|
+
const structs_1 = require("./structs.cjs");
|
|
23
|
+
// === GENERAL ===
|
|
24
|
+
/**
|
|
25
|
+
* The name of the {@link MoneyAccountApiDataService}, used to namespace the
|
|
26
|
+
* service's actions and events.
|
|
27
|
+
*/
|
|
28
|
+
exports.serviceName = 'MoneyAccountApiDataService';
|
|
29
|
+
const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, exports.serviceName);
|
|
30
|
+
// === MESSENGER ===
|
|
31
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
32
|
+
'fetchPositions',
|
|
33
|
+
'fetchInterest',
|
|
34
|
+
'fetchHistory',
|
|
35
|
+
'fetchRateHistory',
|
|
36
|
+
];
|
|
37
|
+
// === SERVICE DEFINITION ===
|
|
38
|
+
/**
|
|
39
|
+
* Data service responsible for fetching positions, interest, cash-flow
|
|
40
|
+
* history, and vault rate history from the Money Account APY Tracking API.
|
|
41
|
+
*/
|
|
42
|
+
class MoneyAccountApiDataService extends base_data_service_1.BaseDataService {
|
|
43
|
+
/**
|
|
44
|
+
* Constructs a new MoneyAccountApiDataService.
|
|
45
|
+
*
|
|
46
|
+
* @param args - The constructor arguments.
|
|
47
|
+
* @param args.messenger - The messenger suited for this service.
|
|
48
|
+
* @param args.env - The target environment. Defaults to production.
|
|
49
|
+
* @param args.queryClientConfig - Configuration for the underlying TanStack
|
|
50
|
+
* Query client.
|
|
51
|
+
* @param args.policyOptions - Options to pass to `createServicePolicy`.
|
|
52
|
+
*/
|
|
53
|
+
constructor({ messenger, env = constants_1.Env.PRD, queryClientConfig = {}, policyOptions = {}, }) {
|
|
54
|
+
super({
|
|
55
|
+
name: exports.serviceName,
|
|
56
|
+
messenger,
|
|
57
|
+
queryClientConfig,
|
|
58
|
+
policyOptions: {
|
|
59
|
+
retryFilterPolicy: (0, controller_utils_1.handleWhen)((error) => !(error instanceof errors_1.MoneyAccountApiResponseValidationError)),
|
|
60
|
+
...policyOptions,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
_MoneyAccountApiDataService_baseUrl.set(this, void 0);
|
|
64
|
+
__classPrivateFieldSet(this, _MoneyAccountApiDataService_baseUrl, constants_1.MONEY_ACCOUNT_API_URL_MAP[env], "f");
|
|
65
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
66
|
+
log('Initialized', { env, baseUrl: __classPrivateFieldGet(this, _MoneyAccountApiDataService_baseUrl, "f") });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Fetches the current vault positions for a given user address.
|
|
70
|
+
*
|
|
71
|
+
* @param address - The user's Ethereum address.
|
|
72
|
+
* @returns The position response containing vault positions.
|
|
73
|
+
*/
|
|
74
|
+
async fetchPositions(address) {
|
|
75
|
+
const url = new URL(`/v1/positions/${address.toLowerCase()}`, __classPrivateFieldGet(this, _MoneyAccountApiDataService_baseUrl, "f"));
|
|
76
|
+
return this.fetchQuery({
|
|
77
|
+
queryKey: [`${this.name}:fetchPositions`, address.toLowerCase()],
|
|
78
|
+
staleTime: constants_1.DEFAULT_STALE_TIME_MS,
|
|
79
|
+
queryFn: async () => {
|
|
80
|
+
const response = await fetch(url);
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
throw new controller_utils_1.HttpError(response.status, `Money Account API positions request failed with status '${response.status}'`);
|
|
83
|
+
}
|
|
84
|
+
const json = await response.json();
|
|
85
|
+
const [error, validated] = (0, superstruct_1.validate)(json, structs_1.PositionResponseStruct);
|
|
86
|
+
if (error) {
|
|
87
|
+
throw new errors_1.MoneyAccountApiResponseValidationError(`Malformed response from positions endpoint: ${error.message}`);
|
|
88
|
+
}
|
|
89
|
+
return validated;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Fetches the interest earned for a given address and vault over a
|
|
95
|
+
* specified time window.
|
|
96
|
+
*
|
|
97
|
+
* @param address - The user's Ethereum address.
|
|
98
|
+
* @param options - Options specifying vault, window, and optional chain ID.
|
|
99
|
+
* @returns The interest response.
|
|
100
|
+
*/
|
|
101
|
+
async fetchInterest(address, options) {
|
|
102
|
+
const url = new URL(`/v1/positions/${address.toLowerCase()}/interest`, __classPrivateFieldGet(this, _MoneyAccountApiDataService_baseUrl, "f"));
|
|
103
|
+
url.searchParams.append('vault_address', options.vaultAddress.toLowerCase());
|
|
104
|
+
url.searchParams.append('window', options.window);
|
|
105
|
+
if (options.chainId !== undefined) {
|
|
106
|
+
url.searchParams.append('chain_id', String(options.chainId));
|
|
107
|
+
}
|
|
108
|
+
return this.fetchQuery({
|
|
109
|
+
queryKey: [
|
|
110
|
+
`${this.name}:fetchInterest`,
|
|
111
|
+
address.toLowerCase(),
|
|
112
|
+
options.vaultAddress.toLowerCase(),
|
|
113
|
+
options.window,
|
|
114
|
+
...(options.chainId === undefined ? [] : [options.chainId]),
|
|
115
|
+
],
|
|
116
|
+
staleTime: constants_1.DEFAULT_STALE_TIME_MS,
|
|
117
|
+
queryFn: async () => {
|
|
118
|
+
const response = await fetch(url);
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
throw new controller_utils_1.HttpError(response.status, `Money Account API interest request failed with status '${response.status}'`);
|
|
121
|
+
}
|
|
122
|
+
const json = await response.json();
|
|
123
|
+
const [error, validated] = (0, superstruct_1.validate)(json, structs_1.InterestResponseStruct);
|
|
124
|
+
if (error) {
|
|
125
|
+
throw new errors_1.MoneyAccountApiResponseValidationError(`Malformed response from interest endpoint: ${error.message}`);
|
|
126
|
+
}
|
|
127
|
+
return validated;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Fetches cursor-paginated cash-flow history for a given address.
|
|
133
|
+
* Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.
|
|
134
|
+
*
|
|
135
|
+
* When paginating, consumers must re-pass the same filter options
|
|
136
|
+
* (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page
|
|
137
|
+
* request. This ensures the query key matches the original infinite query
|
|
138
|
+
* and that the HTTP request includes the correct filters.
|
|
139
|
+
*
|
|
140
|
+
* @param address - The user's Ethereum address.
|
|
141
|
+
* @param options - Optional filtering and pagination options.
|
|
142
|
+
* @returns The history response containing cash-flow entries for the requested page.
|
|
143
|
+
*/
|
|
144
|
+
async fetchHistory(address, options) {
|
|
145
|
+
const normalizedAddress = address.toLowerCase();
|
|
146
|
+
const normalizedVault = options?.vaultAddress?.toLowerCase() ?? null;
|
|
147
|
+
return this.fetchInfiniteQuery({
|
|
148
|
+
queryKey: [
|
|
149
|
+
`${this.name}:fetchHistory`,
|
|
150
|
+
normalizedAddress,
|
|
151
|
+
normalizedVault,
|
|
152
|
+
options?.chainId ?? null,
|
|
153
|
+
options?.limit ?? null,
|
|
154
|
+
],
|
|
155
|
+
staleTime: constants_1.DEFAULT_STALE_TIME_MS,
|
|
156
|
+
queryFn: async (context) => {
|
|
157
|
+
const cursor = context.pageParam;
|
|
158
|
+
const url = new URL(`/v1/positions/${normalizedAddress}/history`, __classPrivateFieldGet(this, _MoneyAccountApiDataService_baseUrl, "f"));
|
|
159
|
+
if (normalizedVault) {
|
|
160
|
+
url.searchParams.append('vault_address', normalizedVault);
|
|
161
|
+
}
|
|
162
|
+
if (options?.chainId !== undefined) {
|
|
163
|
+
url.searchParams.append('chain_id', String(options.chainId));
|
|
164
|
+
}
|
|
165
|
+
if (cursor) {
|
|
166
|
+
url.searchParams.append('cursor', cursor);
|
|
167
|
+
}
|
|
168
|
+
if (options?.limit !== undefined) {
|
|
169
|
+
url.searchParams.append('limit', String(options.limit));
|
|
170
|
+
}
|
|
171
|
+
const response = await fetch(url);
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
throw new controller_utils_1.HttpError(response.status, `Money Account API history request failed with status '${response.status}'`);
|
|
174
|
+
}
|
|
175
|
+
const json = await response.json();
|
|
176
|
+
const [error, validated] = (0, superstruct_1.validate)(json, structs_1.HistoryResponseStruct);
|
|
177
|
+
if (error) {
|
|
178
|
+
throw new errors_1.MoneyAccountApiResponseValidationError(`Malformed response from history endpoint: ${error.message}`);
|
|
179
|
+
}
|
|
180
|
+
return validated;
|
|
181
|
+
},
|
|
182
|
+
}, options?.cursor ?? undefined);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Fetches the exchange-rate time series for a given vault.
|
|
186
|
+
*
|
|
187
|
+
* @param vaultAddress - The vault's Ethereum address.
|
|
188
|
+
* @param options - Optional range and chain ID filters.
|
|
189
|
+
* @returns The rate history response.
|
|
190
|
+
*/
|
|
191
|
+
async fetchRateHistory(vaultAddress, options) {
|
|
192
|
+
const url = new URL(`/v1/vaults/${vaultAddress.toLowerCase()}/rate-history`, __classPrivateFieldGet(this, _MoneyAccountApiDataService_baseUrl, "f"));
|
|
193
|
+
if (options?.chainId !== undefined) {
|
|
194
|
+
url.searchParams.append('chain_id', String(options.chainId));
|
|
195
|
+
}
|
|
196
|
+
if (options?.from) {
|
|
197
|
+
url.searchParams.append('from', options.from);
|
|
198
|
+
}
|
|
199
|
+
if (options?.to) {
|
|
200
|
+
url.searchParams.append('to', options.to);
|
|
201
|
+
}
|
|
202
|
+
return this.fetchQuery({
|
|
203
|
+
queryKey: [
|
|
204
|
+
`${this.name}:fetchRateHistory`,
|
|
205
|
+
vaultAddress.toLowerCase(),
|
|
206
|
+
...(options?.chainId === undefined ? [null] : [options.chainId]),
|
|
207
|
+
...(options?.from ? [options.from] : [null]),
|
|
208
|
+
...(options?.to ? [options.to] : [null]),
|
|
209
|
+
],
|
|
210
|
+
staleTime: constants_1.RATE_HISTORY_STALE_TIME_MS,
|
|
211
|
+
queryFn: async () => {
|
|
212
|
+
const response = await fetch(url);
|
|
213
|
+
if (!response.ok) {
|
|
214
|
+
throw new controller_utils_1.HttpError(response.status, `Money Account API rate-history request failed with status '${response.status}'`);
|
|
215
|
+
}
|
|
216
|
+
const json = await response.json();
|
|
217
|
+
const [error, validated] = (0, superstruct_1.validate)(json, structs_1.RateHistoryResponseStruct);
|
|
218
|
+
if (error) {
|
|
219
|
+
throw new errors_1.MoneyAccountApiResponseValidationError(`Malformed response from rate-history endpoint: ${error.message}`);
|
|
220
|
+
}
|
|
221
|
+
return validated;
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.MoneyAccountApiDataService = MoneyAccountApiDataService;
|
|
227
|
+
_MoneyAccountApiDataService_baseUrl = new WeakMap();
|
|
228
|
+
//# sourceMappingURL=money-account-api-data-service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-api-data-service.cjs","sourceRoot":"","sources":["../src/money-account-api-data-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mEAA8D;AAE9D,iEAAmE;AAEnE,uDAAiD;AAIjD,+CAKqB;AACrB,yCAAkE;AAClE,yCAA6D;AAQ7D,2CAKmB;AAOnB,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,4BAA4B,CAAC;AAExD,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,mBAAW,CAAC,CAAC;AAE3D,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,gBAAgB;IAChB,eAAe;IACf,cAAc;IACd,kBAAkB;CACV,CAAC;AAwDX,6BAA6B;AAE7B;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,mCAG/C;IAGC;;;;;;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QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;gBAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,4BAAS,CACjB,QAAQ,CAAC,MAAM,EACf,8DAA8D,QAAQ,CAAC,MAAM,GAAG,CACjF,CAAC;gBACJ,CAAC;gBAED,MAAM,IAAI,GAAS,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAEzC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,IAAA,sBAAQ,EAAC,IAAI,EAAE,mCAAyB,CAAC,CAAC;gBACrE,IAAI,KAAK,EAAE,CAAC;oBACV,MAAM,IAAI,+CAAsC,CAC9C,kDAAkD,KAAK,CAAC,OAAO,EAAE,CAClE,CAAC;gBACJ,CAAC;gBAED,OAAO,SAA2C,CAAC;YACrD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAtRD,gEAsRC","sourcesContent":["import type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } 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';\nimport { MoneyAccountApiResponseValidationError } from './errors';\nimport { projectLogger, createModuleLogger } from './logger';\nimport type { MoneyAccountApiDataServiceMethodActions } from './money-account-api-data-service-method-action-types';\nimport type {\n HistoryResponse,\n InterestResponse,\n PositionResponse,\n RateHistoryResponse,\n} from './response.types';\nimport {\n HistoryResponseStruct,\n InterestResponseStruct,\n PositionResponseStruct,\n RateHistoryResponseStruct,\n} from './structs';\nimport type {\n HistoryOptions,\n InterestOptions,\n RateHistoryOptions,\n} from './types';\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);\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 AllowedActions = never;\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\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 /**\n * Constructs a new MoneyAccountApiDataService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.env - The target environment. Defaults to production.\n * @param args.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\n * @param args.policyOptions - Options to pass to `createServicePolicy`.\n */\n constructor({\n messenger,\n env = Env.PRD,\n queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: MoneyAccountApiDataServiceMessenger;\n env?: Env;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions: {\n retryFilterPolicy: handleWhen(\n (error) => !(error instanceof MoneyAccountApiResponseValidationError),\n ),\n ...policyOptions,\n },\n });\n\n this.#baseUrl = MONEY_ACCOUNT_API_URL_MAP[env];\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n log('Initialized', { env, baseUrl: this.#baseUrl });\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.\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 const response = await fetch(url);\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 const response = await fetch(url);\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 * 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(\n {\n queryKey: [\n `${this.name}:fetchHistory`,\n normalizedAddress,\n normalizedVault,\n options?.chainId ?? null,\n options?.limit ?? null,\n ],\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 const response = await fetch(url);\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 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 const response = await fetch(url);\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(json, RateHistoryResponseStruct);\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"]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from "@metamask/base-data-service";
|
|
2
|
+
import { BaseDataService } from "@metamask/base-data-service";
|
|
3
|
+
import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
|
|
4
|
+
import type { Messenger } from "@metamask/messenger";
|
|
5
|
+
import type { QueryClientConfig } from "@tanstack/query-core";
|
|
6
|
+
import { Env } from "./constants.cjs";
|
|
7
|
+
import type { MoneyAccountApiDataServiceMethodActions } from "./money-account-api-data-service-method-action-types.cjs";
|
|
8
|
+
import type { HistoryResponse, InterestResponse, PositionResponse, RateHistoryResponse } from "./response.types.cjs";
|
|
9
|
+
import type { HistoryOptions, InterestOptions, RateHistoryOptions } from "./types.cjs";
|
|
10
|
+
/**
|
|
11
|
+
* The name of the {@link MoneyAccountApiDataService}, used to namespace the
|
|
12
|
+
* service's actions and events.
|
|
13
|
+
*/
|
|
14
|
+
export declare const serviceName = "MoneyAccountApiDataService";
|
|
15
|
+
/**
|
|
16
|
+
* Invalidates cached queries for {@link MoneyAccountApiDataService}.
|
|
17
|
+
*/
|
|
18
|
+
export type MoneyAccountApiDataServiceInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
|
|
19
|
+
/**
|
|
20
|
+
* Actions that {@link MoneyAccountApiDataService} exposes to other consumers.
|
|
21
|
+
*/
|
|
22
|
+
export type MoneyAccountApiDataServiceActions = MoneyAccountApiDataServiceMethodActions | MoneyAccountApiDataServiceInvalidateQueriesAction;
|
|
23
|
+
/**
|
|
24
|
+
* Actions from other messengers that {@link MoneyAccountApiDataService} calls.
|
|
25
|
+
*/
|
|
26
|
+
type AllowedActions = never;
|
|
27
|
+
/**
|
|
28
|
+
* Published when {@link MoneyAccountApiDataService}'s cache is updated.
|
|
29
|
+
*/
|
|
30
|
+
export type MoneyAccountApiDataServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<typeof serviceName>;
|
|
31
|
+
/**
|
|
32
|
+
* Published when a key within {@link MoneyAccountApiDataService}'s cache is
|
|
33
|
+
* updated.
|
|
34
|
+
*/
|
|
35
|
+
export type MoneyAccountApiDataServiceGranularCacheUpdatedEvent = DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
|
|
36
|
+
/**
|
|
37
|
+
* Events that {@link MoneyAccountApiDataService} exposes to other consumers.
|
|
38
|
+
*/
|
|
39
|
+
export type MoneyAccountApiDataServiceEvents = MoneyAccountApiDataServiceCacheUpdatedEvent | MoneyAccountApiDataServiceGranularCacheUpdatedEvent;
|
|
40
|
+
/**
|
|
41
|
+
* Events from other messengers that {@link MoneyAccountApiDataService}
|
|
42
|
+
* subscribes to.
|
|
43
|
+
*/
|
|
44
|
+
type AllowedEvents = never;
|
|
45
|
+
/**
|
|
46
|
+
* The messenger which is restricted to actions and events accessed by
|
|
47
|
+
* {@link MoneyAccountApiDataService}.
|
|
48
|
+
*/
|
|
49
|
+
export type MoneyAccountApiDataServiceMessenger = Messenger<typeof serviceName, MoneyAccountApiDataServiceActions | AllowedActions, MoneyAccountApiDataServiceEvents | AllowedEvents>;
|
|
50
|
+
/**
|
|
51
|
+
* Data service responsible for fetching positions, interest, cash-flow
|
|
52
|
+
* history, and vault rate history from the Money Account APY Tracking API.
|
|
53
|
+
*/
|
|
54
|
+
export declare class MoneyAccountApiDataService extends BaseDataService<typeof serviceName, MoneyAccountApiDataServiceMessenger> {
|
|
55
|
+
#private;
|
|
56
|
+
/**
|
|
57
|
+
* Constructs a new MoneyAccountApiDataService.
|
|
58
|
+
*
|
|
59
|
+
* @param args - The constructor arguments.
|
|
60
|
+
* @param args.messenger - The messenger suited for this service.
|
|
61
|
+
* @param args.env - The target environment. Defaults to production.
|
|
62
|
+
* @param args.queryClientConfig - Configuration for the underlying TanStack
|
|
63
|
+
* Query client.
|
|
64
|
+
* @param args.policyOptions - Options to pass to `createServicePolicy`.
|
|
65
|
+
*/
|
|
66
|
+
constructor({ messenger, env, queryClientConfig, policyOptions, }: {
|
|
67
|
+
messenger: MoneyAccountApiDataServiceMessenger;
|
|
68
|
+
env?: Env;
|
|
69
|
+
queryClientConfig?: QueryClientConfig;
|
|
70
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Fetches the current vault positions for a given user address.
|
|
74
|
+
*
|
|
75
|
+
* @param address - The user's Ethereum address.
|
|
76
|
+
* @returns The position response containing vault positions.
|
|
77
|
+
*/
|
|
78
|
+
fetchPositions(address: string): Promise<PositionResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Fetches the interest earned for a given address and vault over a
|
|
81
|
+
* specified time window.
|
|
82
|
+
*
|
|
83
|
+
* @param address - The user's Ethereum address.
|
|
84
|
+
* @param options - Options specifying vault, window, and optional chain ID.
|
|
85
|
+
* @returns The interest response.
|
|
86
|
+
*/
|
|
87
|
+
fetchInterest(address: string, options: InterestOptions): Promise<InterestResponse>;
|
|
88
|
+
/**
|
|
89
|
+
* Fetches cursor-paginated cash-flow history for a given address.
|
|
90
|
+
* Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.
|
|
91
|
+
*
|
|
92
|
+
* When paginating, consumers must re-pass the same filter options
|
|
93
|
+
* (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page
|
|
94
|
+
* request. This ensures the query key matches the original infinite query
|
|
95
|
+
* and that the HTTP request includes the correct filters.
|
|
96
|
+
*
|
|
97
|
+
* @param address - The user's Ethereum address.
|
|
98
|
+
* @param options - Optional filtering and pagination options.
|
|
99
|
+
* @returns The history response containing cash-flow entries for the requested page.
|
|
100
|
+
*/
|
|
101
|
+
fetchHistory(address: string, options?: HistoryOptions): Promise<HistoryResponse>;
|
|
102
|
+
/**
|
|
103
|
+
* Fetches the exchange-rate time series for a given vault.
|
|
104
|
+
*
|
|
105
|
+
* @param vaultAddress - The vault's Ethereum address.
|
|
106
|
+
* @param options - Optional range and chain ID filters.
|
|
107
|
+
* @returns The rate history response.
|
|
108
|
+
*/
|
|
109
|
+
fetchRateHistory(vaultAddress: string, options?: RateHistoryOptions): Promise<RateHistoryResponse>;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=money-account-api-data-service.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-api-data-service.d.cts","sourceRoot":"","sources":["../src/money-account-api-data-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B;AAE9D,OAAO,EAEL,GAAG,EAGJ,wBAAoB;AAGrB,OAAO,KAAK,EAAE,uCAAuC,EAAE,iEAA6D;AACpH,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACpB,6BAAyB;AAO1B,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,kBAAkB,EACnB,oBAAgB;AAIjB;;;GAGG;AACH,eAAO,MAAM,WAAW,+BAA+B,CAAC;AAaxD;;GAEG;AACH,MAAM,MA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ACvB,OAAO,CAAC,eAAe,CAAC;IA2D3B;;;;;;OAMG;IACG,gBAAgB,CACpB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;CA+ChC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from "@metamask/base-data-service";
|
|
2
|
+
import { BaseDataService } from "@metamask/base-data-service";
|
|
3
|
+
import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
|
|
4
|
+
import type { Messenger } from "@metamask/messenger";
|
|
5
|
+
import type { QueryClientConfig } from "@tanstack/query-core";
|
|
6
|
+
import { Env } from "./constants.mjs";
|
|
7
|
+
import type { MoneyAccountApiDataServiceMethodActions } from "./money-account-api-data-service-method-action-types.mjs";
|
|
8
|
+
import type { HistoryResponse, InterestResponse, PositionResponse, RateHistoryResponse } from "./response.types.mjs";
|
|
9
|
+
import type { HistoryOptions, InterestOptions, RateHistoryOptions } from "./types.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* The name of the {@link MoneyAccountApiDataService}, used to namespace the
|
|
12
|
+
* service's actions and events.
|
|
13
|
+
*/
|
|
14
|
+
export declare const serviceName = "MoneyAccountApiDataService";
|
|
15
|
+
/**
|
|
16
|
+
* Invalidates cached queries for {@link MoneyAccountApiDataService}.
|
|
17
|
+
*/
|
|
18
|
+
export type MoneyAccountApiDataServiceInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
|
|
19
|
+
/**
|
|
20
|
+
* Actions that {@link MoneyAccountApiDataService} exposes to other consumers.
|
|
21
|
+
*/
|
|
22
|
+
export type MoneyAccountApiDataServiceActions = MoneyAccountApiDataServiceMethodActions | MoneyAccountApiDataServiceInvalidateQueriesAction;
|
|
23
|
+
/**
|
|
24
|
+
* Actions from other messengers that {@link MoneyAccountApiDataService} calls.
|
|
25
|
+
*/
|
|
26
|
+
type AllowedActions = never;
|
|
27
|
+
/**
|
|
28
|
+
* Published when {@link MoneyAccountApiDataService}'s cache is updated.
|
|
29
|
+
*/
|
|
30
|
+
export type MoneyAccountApiDataServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<typeof serviceName>;
|
|
31
|
+
/**
|
|
32
|
+
* Published when a key within {@link MoneyAccountApiDataService}'s cache is
|
|
33
|
+
* updated.
|
|
34
|
+
*/
|
|
35
|
+
export type MoneyAccountApiDataServiceGranularCacheUpdatedEvent = DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
|
|
36
|
+
/**
|
|
37
|
+
* Events that {@link MoneyAccountApiDataService} exposes to other consumers.
|
|
38
|
+
*/
|
|
39
|
+
export type MoneyAccountApiDataServiceEvents = MoneyAccountApiDataServiceCacheUpdatedEvent | MoneyAccountApiDataServiceGranularCacheUpdatedEvent;
|
|
40
|
+
/**
|
|
41
|
+
* Events from other messengers that {@link MoneyAccountApiDataService}
|
|
42
|
+
* subscribes to.
|
|
43
|
+
*/
|
|
44
|
+
type AllowedEvents = never;
|
|
45
|
+
/**
|
|
46
|
+
* The messenger which is restricted to actions and events accessed by
|
|
47
|
+
* {@link MoneyAccountApiDataService}.
|
|
48
|
+
*/
|
|
49
|
+
export type MoneyAccountApiDataServiceMessenger = Messenger<typeof serviceName, MoneyAccountApiDataServiceActions | AllowedActions, MoneyAccountApiDataServiceEvents | AllowedEvents>;
|
|
50
|
+
/**
|
|
51
|
+
* Data service responsible for fetching positions, interest, cash-flow
|
|
52
|
+
* history, and vault rate history from the Money Account APY Tracking API.
|
|
53
|
+
*/
|
|
54
|
+
export declare class MoneyAccountApiDataService extends BaseDataService<typeof serviceName, MoneyAccountApiDataServiceMessenger> {
|
|
55
|
+
#private;
|
|
56
|
+
/**
|
|
57
|
+
* Constructs a new MoneyAccountApiDataService.
|
|
58
|
+
*
|
|
59
|
+
* @param args - The constructor arguments.
|
|
60
|
+
* @param args.messenger - The messenger suited for this service.
|
|
61
|
+
* @param args.env - The target environment. Defaults to production.
|
|
62
|
+
* @param args.queryClientConfig - Configuration for the underlying TanStack
|
|
63
|
+
* Query client.
|
|
64
|
+
* @param args.policyOptions - Options to pass to `createServicePolicy`.
|
|
65
|
+
*/
|
|
66
|
+
constructor({ messenger, env, queryClientConfig, policyOptions, }: {
|
|
67
|
+
messenger: MoneyAccountApiDataServiceMessenger;
|
|
68
|
+
env?: Env;
|
|
69
|
+
queryClientConfig?: QueryClientConfig;
|
|
70
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Fetches the current vault positions for a given user address.
|
|
74
|
+
*
|
|
75
|
+
* @param address - The user's Ethereum address.
|
|
76
|
+
* @returns The position response containing vault positions.
|
|
77
|
+
*/
|
|
78
|
+
fetchPositions(address: string): Promise<PositionResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Fetches the interest earned for a given address and vault over a
|
|
81
|
+
* specified time window.
|
|
82
|
+
*
|
|
83
|
+
* @param address - The user's Ethereum address.
|
|
84
|
+
* @param options - Options specifying vault, window, and optional chain ID.
|
|
85
|
+
* @returns The interest response.
|
|
86
|
+
*/
|
|
87
|
+
fetchInterest(address: string, options: InterestOptions): Promise<InterestResponse>;
|
|
88
|
+
/**
|
|
89
|
+
* Fetches cursor-paginated cash-flow history for a given address.
|
|
90
|
+
* Uses `fetchInfiniteQuery` for proper TanStack Query pagination semantics.
|
|
91
|
+
*
|
|
92
|
+
* When paginating, consumers must re-pass the same filter options
|
|
93
|
+
* (`vaultAddress`, `chainId`, `limit`) alongside `cursor` on every page
|
|
94
|
+
* request. This ensures the query key matches the original infinite query
|
|
95
|
+
* and that the HTTP request includes the correct filters.
|
|
96
|
+
*
|
|
97
|
+
* @param address - The user's Ethereum address.
|
|
98
|
+
* @param options - Optional filtering and pagination options.
|
|
99
|
+
* @returns The history response containing cash-flow entries for the requested page.
|
|
100
|
+
*/
|
|
101
|
+
fetchHistory(address: string, options?: HistoryOptions): Promise<HistoryResponse>;
|
|
102
|
+
/**
|
|
103
|
+
* Fetches the exchange-rate time series for a given vault.
|
|
104
|
+
*
|
|
105
|
+
* @param vaultAddress - The vault's Ethereum address.
|
|
106
|
+
* @param options - Optional range and chain ID filters.
|
|
107
|
+
* @returns The rate history response.
|
|
108
|
+
*/
|
|
109
|
+
fetchRateHistory(vaultAddress: string, options?: RateHistoryOptions): Promise<RateHistoryResponse>;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=money-account-api-data-service.d.mts.map
|