@metamask/assets-controllers 90.0.0 → 92.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -1
- package/dist/CurrencyRateController.cjs +3 -3
- package/dist/CurrencyRateController.cjs.map +1 -1
- package/dist/CurrencyRateController.d.cts.map +1 -1
- package/dist/CurrencyRateController.d.mts.map +1 -1
- package/dist/CurrencyRateController.mjs +3 -3
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +48 -10
- package/dist/TokenBalancesController.cjs.map +1 -1
- package/dist/TokenBalancesController.d.cts +2 -1
- package/dist/TokenBalancesController.d.cts.map +1 -1
- package/dist/TokenBalancesController.d.mts +2 -1
- package/dist/TokenBalancesController.d.mts.map +1 -1
- package/dist/TokenBalancesController.mjs +49 -11
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +12 -7
- package/dist/TokenDetectionController.cjs.map +1 -1
- package/dist/TokenDetectionController.d.cts +2 -1
- package/dist/TokenDetectionController.d.cts.map +1 -1
- package/dist/TokenDetectionController.d.mts +2 -1
- package/dist/TokenDetectionController.d.mts.map +1 -1
- package/dist/TokenDetectionController.mjs +12 -7
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +82 -278
- package/dist/TokenRatesController.cjs.map +1 -1
- package/dist/TokenRatesController.d.cts +9 -35
- package/dist/TokenRatesController.d.cts.map +1 -1
- package/dist/TokenRatesController.d.mts +9 -35
- package/dist/TokenRatesController.d.mts.map +1 -1
- package/dist/TokenRatesController.mjs +83 -279
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +2 -3
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs +2 -3
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.cts +2 -2
- package/dist/TokenSearchDiscoveryDataController/types.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.mts +2 -2
- package/dist/TokenSearchDiscoveryDataController/types.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.mjs.map +1 -1
- package/dist/assetsUtil.cjs +11 -5
- package/dist/assetsUtil.cjs.map +1 -1
- package/dist/assetsUtil.d.cts +2 -2
- package/dist/assetsUtil.d.cts.map +1 -1
- package/dist/assetsUtil.d.mts +2 -2
- package/dist/assetsUtil.d.mts.map +1 -1
- package/dist/assetsUtil.mjs +11 -5
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +8 -8
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts +2 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts +2 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs +8 -8
- package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs +18 -8
- package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts +4 -2
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts +4 -2
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs +18 -8
- package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.cts +17 -43
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.mts +17 -43
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +177 -109
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.cts +47 -10
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.mts +47 -10
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
- package/dist/token-prices-service/codefi-v2.mjs +177 -109
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/dist/token-service.cjs +6 -4
- package/dist/token-service.cjs.map +1 -1
- package/dist/token-service.d.cts +3 -1
- package/dist/token-service.d.cts.map +1 -1
- package/dist/token-service.d.mts +3 -1
- package/dist/token-service.d.mts.map +1 -1
- package/dist/token-service.mjs +6 -4
- package/dist/token-service.mjs.map +1 -1
- package/package.json +14 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-chain-accounts.cjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-accounts.ts"],"names":[],"mappings":";;;AAAA,iEAAyD;AAU5C,QAAA,0BAA0B,GAAG,qCAAqC,CAAC;AAEhF,MAAM,cAAc,GAAG,CACrB,OAAe,EACf,WAAoC,EACpC,EAAE;IACF,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB,GAAG,kCAA0B,gBAAgB,OAAO,WAA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AAQ,EAAE;KACnD,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,aAAa,GAAG,UAAU,QAAQ,EAAE,CAAC;IAC/C,CAAC;IAED,MAAM,QAAQ,GAAwB,MAAM,IAAA,8BAAW,EAAC,GAAG,EAAE;QAC3D,OAAO;KACR,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAtBD,0DAsBC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,yBAAyB,CAC7C,OAAyE,EACzE,QAAgC,EAChC,QAAiB;IAEjB,MAAM,GAAG,GAAG,gBAAgB,CAAC;QAC3B,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE;QACnD,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;KACpC,CAAC,CAAC;IAEH,MAAM,OAAO,GAA2B;QACtC,0BAA0B,EAAE,YAAY,QAAQ,EAAE;KACnD,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,aAAa,GAAG,UAAU,QAAQ,EAAE,CAAC;IAC/C,CAAC;IAED,MAAM,QAAQ,GAAwB,MAAM,IAAA,8BAAW,EAAC,GAAG,EAAE;QAC3D,OAAO;KACR,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAtBD,8DAsBC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { CaipAccountAddress } from '@metamask/utils';\n\nimport type {\n GetBalancesQueryParams,\n GetBalancesQueryParamsV4,\n GetBalancesResponse,\n GetSupportedNetworksResponse,\n} from './types';\n\nexport const MULTICHAIN_ACCOUNTS_DOMAIN = 'https://accounts.api.cx.metamask.io';\n\nconst getBalancesUrl = (\n address: string,\n queryParams?: GetBalancesQueryParams,\n) => {\n const url = new URL(\n `${MULTICHAIN_ACCOUNTS_DOMAIN}/v2/accounts/${address}/balances`,\n );\n\n if (queryParams?.networks !== undefined) {\n url.searchParams.append('networks', queryParams.networks);\n }\n\n return url;\n};\n\nconst getBalancesUrlV4 = (queryParams?: GetBalancesQueryParamsV4) => {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_DOMAIN}/v4/multiaccount/balances`);\n\n if (queryParams?.networks !== undefined) {\n url.searchParams.append('networks', queryParams.networks);\n }\n\n if (queryParams?.accountAddresses !== undefined) {\n url.searchParams.append('accountAddresses', queryParams.accountAddresses);\n }\n\n return url;\n};\n\n/**\n * Fetches Supported Networks.\n *\n * @returns supported networks (decimal)\n */\nexport async function fetchSupportedNetworks(): Promise<number[]> {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_DOMAIN}/v1/supportedNetworks`);\n const response: GetSupportedNetworksResponse = await handleFetch(url);\n return response.fullSupport;\n}\n\n/**\n * Fetches Balances for multiple networks.\n *\n * @param address - address to fetch balances from\n * @param options - params to pass down for a more refined search\n * @param options.networks - the networks (in decimal) that you want to filter by\n * @param platform - indicates whether the platform is extension or mobile\n * @param jwtToken - JWT token for authentication\n * @returns a Balances Response\n */\nexport async function fetchMultiChainBalances(\n address: string,\n options: { networks?: number[] },\n platform: 'extension' | 'mobile',\n jwtToken?: string,\n) {\n const url = getBalancesUrl(address, {\n networks: options?.networks?.join(),\n });\n\n const headers: Record<string, string> = {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n };\n\n if (jwtToken) {\n headers.Authorization = `Bearer ${jwtToken}`;\n }\n\n const response: GetBalancesResponse = await handleFetch(url, {\n headers,\n });\n return response;\n}\n\n/**\n * Fetches Balances for multiple networks.\n *\n * @param options - params to pass down for a more refined search\n * @param options.accountAddresses - the account addresses that you want to filter by\n * @param options.networks - the networks (in decimal) that you want to filter by\n * @param platform - indicates whether the platform is extension or mobile\n * @param jwtToken - JWT token for authentication\n * @returns a Balances Response\n */\nexport async function fetchMultiChainBalancesV4(\n options: { accountAddresses?: CaipAccountAddress[]; networks?: number[] },\n platform: 'extension' | 'mobile',\n jwtToken?: string,\n) {\n const url = getBalancesUrlV4({\n accountAddresses: options?.accountAddresses?.join(),\n networks: options?.networks?.join(),\n });\n\n const headers: Record<string, string> = {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n };\n\n if (jwtToken) {\n headers.Authorization = `Bearer ${jwtToken}`;\n }\n\n const response: GetBalancesResponse = await handleFetch(url, {\n headers,\n });\n return response;\n}\n"]}
|
|
@@ -14,11 +14,12 @@ export declare function fetchSupportedNetworks(): Promise<number[]>;
|
|
|
14
14
|
* @param options - params to pass down for a more refined search
|
|
15
15
|
* @param options.networks - the networks (in decimal) that you want to filter by
|
|
16
16
|
* @param platform - indicates whether the platform is extension or mobile
|
|
17
|
+
* @param jwtToken - JWT token for authentication
|
|
17
18
|
* @returns a Balances Response
|
|
18
19
|
*/
|
|
19
20
|
export declare function fetchMultiChainBalances(address: string, options: {
|
|
20
21
|
networks?: number[];
|
|
21
|
-
}, platform: 'extension' | 'mobile'): Promise<GetBalancesResponse>;
|
|
22
|
+
}, platform: 'extension' | 'mobile', jwtToken?: string): Promise<GetBalancesResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* Fetches Balances for multiple networks.
|
|
24
25
|
*
|
|
@@ -26,10 +27,11 @@ export declare function fetchMultiChainBalances(address: string, options: {
|
|
|
26
27
|
* @param options.accountAddresses - the account addresses that you want to filter by
|
|
27
28
|
* @param options.networks - the networks (in decimal) that you want to filter by
|
|
28
29
|
* @param platform - indicates whether the platform is extension or mobile
|
|
30
|
+
* @param jwtToken - JWT token for authentication
|
|
29
31
|
* @returns a Balances Response
|
|
30
32
|
*/
|
|
31
33
|
export declare function fetchMultiChainBalancesV4(options: {
|
|
32
34
|
accountAddresses?: CaipAccountAddress[];
|
|
33
35
|
networks?: number[];
|
|
34
|
-
}, platform: 'extension' | 'mobile'): Promise<GetBalancesResponse>;
|
|
36
|
+
}, platform: 'extension' | 'mobile', jwtToken?: string): Promise<GetBalancesResponse>;
|
|
35
37
|
//# sourceMappingURL=multi-chain-accounts.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-chain-accounts.d.cts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAE1D,OAAO,KAAK,EAGV,mBAAmB,EAEpB,oBAAgB;AAEjB,eAAO,MAAM,0BAA0B,wCAAwC,CAAC;AA+BhF;;;;GAIG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAIhE;AAED
|
|
1
|
+
{"version":3,"file":"multi-chain-accounts.d.cts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAE1D,OAAO,KAAK,EAGV,mBAAmB,EAEpB,oBAAgB;AAEjB,eAAO,MAAM,0BAA0B,wCAAwC,CAAC;AA+BhF;;;;GAIG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAIhE;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EAChC,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,QAAQ,CAAC,EAAE,MAAM,gCAkBlB;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE;IAAE,gBAAgB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EACzE,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,QAAQ,CAAC,EAAE,MAAM,gCAmBlB"}
|
|
@@ -14,11 +14,12 @@ export declare function fetchSupportedNetworks(): Promise<number[]>;
|
|
|
14
14
|
* @param options - params to pass down for a more refined search
|
|
15
15
|
* @param options.networks - the networks (in decimal) that you want to filter by
|
|
16
16
|
* @param platform - indicates whether the platform is extension or mobile
|
|
17
|
+
* @param jwtToken - JWT token for authentication
|
|
17
18
|
* @returns a Balances Response
|
|
18
19
|
*/
|
|
19
20
|
export declare function fetchMultiChainBalances(address: string, options: {
|
|
20
21
|
networks?: number[];
|
|
21
|
-
}, platform: 'extension' | 'mobile'): Promise<GetBalancesResponse>;
|
|
22
|
+
}, platform: 'extension' | 'mobile', jwtToken?: string): Promise<GetBalancesResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* Fetches Balances for multiple networks.
|
|
24
25
|
*
|
|
@@ -26,10 +27,11 @@ export declare function fetchMultiChainBalances(address: string, options: {
|
|
|
26
27
|
* @param options.accountAddresses - the account addresses that you want to filter by
|
|
27
28
|
* @param options.networks - the networks (in decimal) that you want to filter by
|
|
28
29
|
* @param platform - indicates whether the platform is extension or mobile
|
|
30
|
+
* @param jwtToken - JWT token for authentication
|
|
29
31
|
* @returns a Balances Response
|
|
30
32
|
*/
|
|
31
33
|
export declare function fetchMultiChainBalancesV4(options: {
|
|
32
34
|
accountAddresses?: CaipAccountAddress[];
|
|
33
35
|
networks?: number[];
|
|
34
|
-
}, platform: 'extension' | 'mobile'): Promise<GetBalancesResponse>;
|
|
36
|
+
}, platform: 'extension' | 'mobile', jwtToken?: string): Promise<GetBalancesResponse>;
|
|
35
37
|
//# sourceMappingURL=multi-chain-accounts.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-chain-accounts.d.mts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAE1D,OAAO,KAAK,EAGV,mBAAmB,EAEpB,oBAAgB;AAEjB,eAAO,MAAM,0BAA0B,wCAAwC,CAAC;AA+BhF;;;;GAIG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAIhE;AAED
|
|
1
|
+
{"version":3,"file":"multi-chain-accounts.d.mts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAE1D,OAAO,KAAK,EAGV,mBAAmB,EAEpB,oBAAgB;AAEjB,eAAO,MAAM,0BAA0B,wCAAwC,CAAC;AA+BhF;;;;GAIG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAIhE;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EAChC,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,QAAQ,CAAC,EAAE,MAAM,gCAkBlB;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE;IAAE,gBAAgB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EACzE,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,QAAQ,CAAC,EAAE,MAAM,gCAmBlB"}
|
|
@@ -34,16 +34,21 @@ export async function fetchSupportedNetworks() {
|
|
|
34
34
|
* @param options - params to pass down for a more refined search
|
|
35
35
|
* @param options.networks - the networks (in decimal) that you want to filter by
|
|
36
36
|
* @param platform - indicates whether the platform is extension or mobile
|
|
37
|
+
* @param jwtToken - JWT token for authentication
|
|
37
38
|
* @returns a Balances Response
|
|
38
39
|
*/
|
|
39
|
-
export async function fetchMultiChainBalances(address, options, platform) {
|
|
40
|
+
export async function fetchMultiChainBalances(address, options, platform, jwtToken) {
|
|
40
41
|
const url = getBalancesUrl(address, {
|
|
41
42
|
networks: options?.networks?.join(),
|
|
42
43
|
});
|
|
44
|
+
const headers = {
|
|
45
|
+
'x-metamask-clientproduct': `metamask-${platform}`,
|
|
46
|
+
};
|
|
47
|
+
if (jwtToken) {
|
|
48
|
+
headers.Authorization = `Bearer ${jwtToken}`;
|
|
49
|
+
}
|
|
43
50
|
const response = await handleFetch(url, {
|
|
44
|
-
headers
|
|
45
|
-
'x-metamask-clientproduct': `metamask-${platform}`,
|
|
46
|
-
},
|
|
51
|
+
headers,
|
|
47
52
|
});
|
|
48
53
|
return response;
|
|
49
54
|
}
|
|
@@ -54,17 +59,22 @@ export async function fetchMultiChainBalances(address, options, platform) {
|
|
|
54
59
|
* @param options.accountAddresses - the account addresses that you want to filter by
|
|
55
60
|
* @param options.networks - the networks (in decimal) that you want to filter by
|
|
56
61
|
* @param platform - indicates whether the platform is extension or mobile
|
|
62
|
+
* @param jwtToken - JWT token for authentication
|
|
57
63
|
* @returns a Balances Response
|
|
58
64
|
*/
|
|
59
|
-
export async function fetchMultiChainBalancesV4(options, platform) {
|
|
65
|
+
export async function fetchMultiChainBalancesV4(options, platform, jwtToken) {
|
|
60
66
|
const url = getBalancesUrlV4({
|
|
61
67
|
accountAddresses: options?.accountAddresses?.join(),
|
|
62
68
|
networks: options?.networks?.join(),
|
|
63
69
|
});
|
|
70
|
+
const headers = {
|
|
71
|
+
'x-metamask-clientproduct': `metamask-${platform}`,
|
|
72
|
+
};
|
|
73
|
+
if (jwtToken) {
|
|
74
|
+
headers.Authorization = `Bearer ${jwtToken}`;
|
|
75
|
+
}
|
|
64
76
|
const response = await handleFetch(url, {
|
|
65
|
-
headers
|
|
66
|
-
'x-metamask-clientproduct': `metamask-${platform}`,
|
|
67
|
-
},
|
|
77
|
+
headers,
|
|
68
78
|
});
|
|
69
79
|
return response;
|
|
70
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-chain-accounts.mjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAUzD,MAAM,CAAC,MAAM,0BAA0B,GAAG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B;IAEjB,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,EAAE;QAClC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;KACpC,CAAC,CAAC;IAEH,MAAM,OAAO,GAA2B;QACtC,0BAA0B,EAAE,YAAY,QAAQ,EAAE;KACnD,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,aAAa,GAAG,UAAU,QAAQ,EAAE,CAAC;IAC/C,CAAC;IAED,MAAM,QAAQ,GAAwB,MAAM,WAAW,CAAC,GAAG,EAAE;QAC3D,OAAO;KACR,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,OAAyE,EACzE,QAAgC,EAChC,QAAiB;IAEjB,MAAM,GAAG,GAAG,gBAAgB,CAAC;QAC3B,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE;QACnD,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;KACpC,CAAC,CAAC;IAEH,MAAM,OAAO,GAA2B;QACtC,0BAA0B,EAAE,YAAY,QAAQ,EAAE;KACnD,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,aAAa,GAAG,UAAU,QAAQ,EAAE,CAAC;IAC/C,CAAC;IAED,MAAM,QAAQ,GAAwB,MAAM,WAAW,CAAC,GAAG,EAAE;QAC3D,OAAO;KACR,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { CaipAccountAddress } from '@metamask/utils';\n\nimport type {\n GetBalancesQueryParams,\n GetBalancesQueryParamsV4,\n GetBalancesResponse,\n GetSupportedNetworksResponse,\n} from './types';\n\nexport const MULTICHAIN_ACCOUNTS_DOMAIN = 'https://accounts.api.cx.metamask.io';\n\nconst getBalancesUrl = (\n address: string,\n queryParams?: GetBalancesQueryParams,\n) => {\n const url = new URL(\n `${MULTICHAIN_ACCOUNTS_DOMAIN}/v2/accounts/${address}/balances`,\n );\n\n if (queryParams?.networks !== undefined) {\n url.searchParams.append('networks', queryParams.networks);\n }\n\n return url;\n};\n\nconst getBalancesUrlV4 = (queryParams?: GetBalancesQueryParamsV4) => {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_DOMAIN}/v4/multiaccount/balances`);\n\n if (queryParams?.networks !== undefined) {\n url.searchParams.append('networks', queryParams.networks);\n }\n\n if (queryParams?.accountAddresses !== undefined) {\n url.searchParams.append('accountAddresses', queryParams.accountAddresses);\n }\n\n return url;\n};\n\n/**\n * Fetches Supported Networks.\n *\n * @returns supported networks (decimal)\n */\nexport async function fetchSupportedNetworks(): Promise<number[]> {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_DOMAIN}/v1/supportedNetworks`);\n const response: GetSupportedNetworksResponse = await handleFetch(url);\n return response.fullSupport;\n}\n\n/**\n * Fetches Balances for multiple networks.\n *\n * @param address - address to fetch balances from\n * @param options - params to pass down for a more refined search\n * @param options.networks - the networks (in decimal) that you want to filter by\n * @param platform - indicates whether the platform is extension or mobile\n * @param jwtToken - JWT token for authentication\n * @returns a Balances Response\n */\nexport async function fetchMultiChainBalances(\n address: string,\n options: { networks?: number[] },\n platform: 'extension' | 'mobile',\n jwtToken?: string,\n) {\n const url = getBalancesUrl(address, {\n networks: options?.networks?.join(),\n });\n\n const headers: Record<string, string> = {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n };\n\n if (jwtToken) {\n headers.Authorization = `Bearer ${jwtToken}`;\n }\n\n const response: GetBalancesResponse = await handleFetch(url, {\n headers,\n });\n return response;\n}\n\n/**\n * Fetches Balances for multiple networks.\n *\n * @param options - params to pass down for a more refined search\n * @param options.accountAddresses - the account addresses that you want to filter by\n * @param options.networks - the networks (in decimal) that you want to filter by\n * @param platform - indicates whether the platform is extension or mobile\n * @param jwtToken - JWT token for authentication\n * @returns a Balances Response\n */\nexport async function fetchMultiChainBalancesV4(\n options: { accountAddresses?: CaipAccountAddress[]; networks?: number[] },\n platform: 'extension' | 'mobile',\n jwtToken?: string,\n) {\n const url = getBalancesUrlV4({\n accountAddresses: options?.accountAddresses?.join(),\n networks: options?.networks?.join(),\n });\n\n const headers: Record<string, string> = {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n };\n\n if (jwtToken) {\n headers.Authorization = `Bearer ${jwtToken}`;\n }\n\n const response: GetBalancesResponse = await handleFetch(url, {\n headers,\n });\n return response;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-token-prices-service.cjs","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\
|
|
1
|
+
{"version":3,"file":"abstract-token-prices-service.cjs","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\n\nimport type { MarketDataDetails } from '../TokenRatesController';\n\n/**\n * Represents an exchange rate.\n */\nexport type ExchangeRate = {\n name: string;\n ticker: string;\n value: number;\n currencyType: string;\n usd?: number;\n};\n\n/**\n * A map of currency to its exchange rate.\n */\nexport type ExchangeRatesByCurrency<Currency extends string> = {\n [C in Currency]: ExchangeRate;\n};\n\nexport type EvmAssetAddressWithChain<ChainId extends Hex = Hex> = {\n tokenAddress: Hex;\n chainId: ChainId;\n};\n\nexport type EvmAssetWithId<ChainId extends Hex = Hex> =\n EvmAssetAddressWithChain<ChainId> & {\n assetId: CaipAssetType;\n };\n\nexport type EvmAssetWithMarketData<\n ChainId extends Hex = Hex,\n Currency extends string = string,\n> = EvmAssetAddressWithChain<ChainId> &\n MarketDataDetails & { currency: Currency };\n\n/**\n * An ideal token prices service. All implementations must confirm to this\n * interface.\n *\n * @template ChainId - A type union of valid arguments for the `chainId`\n * argument to `fetchTokenPrices`.\n * @template Currency - A type union of valid arguments for the `currency`\n * argument to `fetchTokenPrices`.\n */\nexport type AbstractTokenPricesService<\n ChainId extends Hex = Hex,\n Currency extends string = string,\n> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {\n /**\n * Retrieves prices in the given currency for the tokens identified by the\n * given addresses which are expected to live on the given chain.\n *\n * @param args - The arguments to this function.\n * @param args.assets - The assets to get prices for.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n fetchTokenPrices({\n assets,\n currency,\n }: {\n assets: EvmAssetAddressWithChain<ChainId>[];\n currency: Currency;\n }): Promise<EvmAssetWithMarketData<ChainId, Currency>[]>;\n\n /**\n * Retrieves exchange rates in the given currency.\n *\n * @param args - The arguments to this function.\n * @param args.baseCurrency - The desired currency of the token prices.\n * @param args.includeUsdRate - Whether to include the USD rate in the response.\n * @param args.cryptocurrencies - The cryptocurrencies to get exchange rates for.\n * @returns The exchange rates in the requested base currency.\n */\n fetchExchangeRates({\n baseCurrency,\n includeUsdRate,\n cryptocurrencies,\n }: {\n baseCurrency: Currency;\n includeUsdRate: boolean;\n cryptocurrencies: string[];\n }): Promise<ExchangeRatesByCurrency<Currency>>;\n\n /**\n * Type guard for whether the API can return token prices for the given chain\n * ID.\n *\n * @param chainId - The chain ID to check.\n * @returns True if the API supports the chain ID, false otherwise.\n */\n validateChainIdSupported(chainId: unknown): chainId is ChainId;\n\n /**\n * Type guard for whether the API can return token prices in the given\n * currency.\n *\n * @param currency - The currency to check.\n * @returns True if the API supports the currency, false otherwise.\n */\n validateCurrencySupported(currency: unknown): currency is Currency;\n};\n"]}
|
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
import type { ServicePolicy } from "@metamask/controller-utils";
|
|
2
|
-
import type { Hex } from "@metamask/utils";
|
|
3
|
-
|
|
4
|
-
* Represents the price of a token in a currency.
|
|
5
|
-
*/
|
|
6
|
-
export type TokenPrice<TokenAddress extends Hex, Currency extends string> = {
|
|
7
|
-
tokenAddress: TokenAddress;
|
|
8
|
-
currency: Currency;
|
|
9
|
-
allTimeHigh: number;
|
|
10
|
-
allTimeLow: number;
|
|
11
|
-
circulatingSupply: number;
|
|
12
|
-
dilutedMarketCap: number;
|
|
13
|
-
high1d: number;
|
|
14
|
-
low1d: number;
|
|
15
|
-
marketCap: number;
|
|
16
|
-
marketCapPercentChange1d: number;
|
|
17
|
-
price: number;
|
|
18
|
-
priceChange1d: number;
|
|
19
|
-
pricePercentChange1d: number;
|
|
20
|
-
pricePercentChange1h: number;
|
|
21
|
-
pricePercentChange1y: number;
|
|
22
|
-
pricePercentChange7d: number;
|
|
23
|
-
pricePercentChange14d: number;
|
|
24
|
-
pricePercentChange30d: number;
|
|
25
|
-
pricePercentChange200d: number;
|
|
26
|
-
totalVolume: number;
|
|
27
|
-
};
|
|
2
|
+
import type { CaipAssetType, Hex } from "@metamask/utils";
|
|
3
|
+
import type { MarketDataDetails } from "../TokenRatesController.cjs";
|
|
28
4
|
/**
|
|
29
5
|
* Represents an exchange rate.
|
|
30
6
|
*/
|
|
@@ -35,47 +11,45 @@ export type ExchangeRate = {
|
|
|
35
11
|
currencyType: string;
|
|
36
12
|
usd?: number;
|
|
37
13
|
};
|
|
38
|
-
/**
|
|
39
|
-
* A map of token address to its price.
|
|
40
|
-
*/
|
|
41
|
-
export type TokenPricesByTokenAddress<TokenAddress extends Hex, Currency extends string> = {
|
|
42
|
-
[A in TokenAddress]: TokenPrice<A, Currency>;
|
|
43
|
-
};
|
|
44
14
|
/**
|
|
45
15
|
* A map of currency to its exchange rate.
|
|
46
16
|
*/
|
|
47
17
|
export type ExchangeRatesByCurrency<Currency extends string> = {
|
|
48
18
|
[C in Currency]: ExchangeRate;
|
|
49
19
|
};
|
|
20
|
+
export type EvmAssetAddressWithChain<ChainId extends Hex = Hex> = {
|
|
21
|
+
tokenAddress: Hex;
|
|
22
|
+
chainId: ChainId;
|
|
23
|
+
};
|
|
24
|
+
export type EvmAssetWithId<ChainId extends Hex = Hex> = EvmAssetAddressWithChain<ChainId> & {
|
|
25
|
+
assetId: CaipAssetType;
|
|
26
|
+
};
|
|
27
|
+
export type EvmAssetWithMarketData<ChainId extends Hex = Hex, Currency extends string = string> = EvmAssetAddressWithChain<ChainId> & MarketDataDetails & {
|
|
28
|
+
currency: Currency;
|
|
29
|
+
};
|
|
50
30
|
/**
|
|
51
31
|
* An ideal token prices service. All implementations must confirm to this
|
|
52
32
|
* interface.
|
|
53
33
|
*
|
|
54
34
|
* @template ChainId - A type union of valid arguments for the `chainId`
|
|
55
35
|
* argument to `fetchTokenPrices`.
|
|
56
|
-
* @template TokenAddress - A type union of all token addresses. The reason this
|
|
57
|
-
* type parameter exists is so that we can guarantee that same addresses that
|
|
58
|
-
* `fetchTokenPrices` receives are the same addresses that shown up in the
|
|
59
|
-
* return value.
|
|
60
36
|
* @template Currency - A type union of valid arguments for the `currency`
|
|
61
37
|
* argument to `fetchTokenPrices`.
|
|
62
38
|
*/
|
|
63
|
-
export type AbstractTokenPricesService<ChainId extends Hex = Hex,
|
|
39
|
+
export type AbstractTokenPricesService<ChainId extends Hex = Hex, Currency extends string = string> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
|
|
64
40
|
/**
|
|
65
41
|
* Retrieves prices in the given currency for the tokens identified by the
|
|
66
42
|
* given addresses which are expected to live on the given chain.
|
|
67
43
|
*
|
|
68
44
|
* @param args - The arguments to this function.
|
|
69
|
-
* @param args.
|
|
70
|
-
* @param args.tokenAddresses - Addresses for tokens that live on the chain.
|
|
45
|
+
* @param args.assets - The assets to get prices for.
|
|
71
46
|
* @param args.currency - The desired currency of the token prices.
|
|
72
47
|
* @returns The prices for the requested tokens.
|
|
73
48
|
*/
|
|
74
|
-
fetchTokenPrices({
|
|
75
|
-
|
|
76
|
-
tokenAddresses: TokenAddress[];
|
|
49
|
+
fetchTokenPrices({ assets, currency, }: {
|
|
50
|
+
assets: EvmAssetAddressWithChain<ChainId>[];
|
|
77
51
|
currency: Currency;
|
|
78
|
-
}): Promise<
|
|
52
|
+
}): Promise<EvmAssetWithMarketData<ChainId, Currency>[]>;
|
|
79
53
|
/**
|
|
80
54
|
* Retrieves exchange rates in the given currency.
|
|
81
55
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-token-prices-service.d.cts","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"abstract-token-prices-service.d.cts","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAgC;AAEjE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,CAAC,QAAQ,SAAS,MAAM,IAAI;KAC5D,CAAC,IAAI,QAAQ,GAAG,YAAY;CAC9B,CAAC;AAEF,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,GAAG,GAAG,GAAG,IAAI;IAChE,YAAY,EAAE,GAAG,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,GAAG,GAAG,GAAG,IAClD,wBAAwB,CAAC,OAAO,CAAC,GAAG;IAClC,OA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
|
-
|
|
4
|
-
* Represents the price of a token in a currency.
|
|
5
|
-
*/
|
|
6
|
-
export type TokenPrice<TokenAddress extends Hex, Currency extends string> = {
|
|
7
|
-
tokenAddress: TokenAddress;
|
|
8
|
-
currency: Currency;
|
|
9
|
-
allTimeHigh: number;
|
|
10
|
-
allTimeLow: number;
|
|
11
|
-
circulatingSupply: number;
|
|
12
|
-
dilutedMarketCap: number;
|
|
13
|
-
high1d: number;
|
|
14
|
-
low1d: number;
|
|
15
|
-
marketCap: number;
|
|
16
|
-
marketCapPercentChange1d: number;
|
|
17
|
-
price: number;
|
|
18
|
-
priceChange1d: number;
|
|
19
|
-
pricePercentChange1d: number;
|
|
20
|
-
pricePercentChange1h: number;
|
|
21
|
-
pricePercentChange1y: number;
|
|
22
|
-
pricePercentChange7d: number;
|
|
23
|
-
pricePercentChange14d: number;
|
|
24
|
-
pricePercentChange30d: number;
|
|
25
|
-
pricePercentChange200d: number;
|
|
26
|
-
totalVolume: number;
|
|
27
|
-
};
|
|
2
|
+
import type { CaipAssetType, Hex } from "@metamask/utils";
|
|
3
|
+
import type { MarketDataDetails } from "../TokenRatesController.mjs";
|
|
28
4
|
/**
|
|
29
5
|
* Represents an exchange rate.
|
|
30
6
|
*/
|
|
@@ -35,47 +11,45 @@ export type ExchangeRate = {
|
|
|
35
11
|
currencyType: string;
|
|
36
12
|
usd?: number;
|
|
37
13
|
};
|
|
38
|
-
/**
|
|
39
|
-
* A map of token address to its price.
|
|
40
|
-
*/
|
|
41
|
-
export type TokenPricesByTokenAddress<TokenAddress extends Hex, Currency extends string> = {
|
|
42
|
-
[A in TokenAddress]: TokenPrice<A, Currency>;
|
|
43
|
-
};
|
|
44
14
|
/**
|
|
45
15
|
* A map of currency to its exchange rate.
|
|
46
16
|
*/
|
|
47
17
|
export type ExchangeRatesByCurrency<Currency extends string> = {
|
|
48
18
|
[C in Currency]: ExchangeRate;
|
|
49
19
|
};
|
|
20
|
+
export type EvmAssetAddressWithChain<ChainId extends Hex = Hex> = {
|
|
21
|
+
tokenAddress: Hex;
|
|
22
|
+
chainId: ChainId;
|
|
23
|
+
};
|
|
24
|
+
export type EvmAssetWithId<ChainId extends Hex = Hex> = EvmAssetAddressWithChain<ChainId> & {
|
|
25
|
+
assetId: CaipAssetType;
|
|
26
|
+
};
|
|
27
|
+
export type EvmAssetWithMarketData<ChainId extends Hex = Hex, Currency extends string = string> = EvmAssetAddressWithChain<ChainId> & MarketDataDetails & {
|
|
28
|
+
currency: Currency;
|
|
29
|
+
};
|
|
50
30
|
/**
|
|
51
31
|
* An ideal token prices service. All implementations must confirm to this
|
|
52
32
|
* interface.
|
|
53
33
|
*
|
|
54
34
|
* @template ChainId - A type union of valid arguments for the `chainId`
|
|
55
35
|
* argument to `fetchTokenPrices`.
|
|
56
|
-
* @template TokenAddress - A type union of all token addresses. The reason this
|
|
57
|
-
* type parameter exists is so that we can guarantee that same addresses that
|
|
58
|
-
* `fetchTokenPrices` receives are the same addresses that shown up in the
|
|
59
|
-
* return value.
|
|
60
36
|
* @template Currency - A type union of valid arguments for the `currency`
|
|
61
37
|
* argument to `fetchTokenPrices`.
|
|
62
38
|
*/
|
|
63
|
-
export type AbstractTokenPricesService<ChainId extends Hex = Hex,
|
|
39
|
+
export type AbstractTokenPricesService<ChainId extends Hex = Hex, Currency extends string = string> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
|
|
64
40
|
/**
|
|
65
41
|
* Retrieves prices in the given currency for the tokens identified by the
|
|
66
42
|
* given addresses which are expected to live on the given chain.
|
|
67
43
|
*
|
|
68
44
|
* @param args - The arguments to this function.
|
|
69
|
-
* @param args.
|
|
70
|
-
* @param args.tokenAddresses - Addresses for tokens that live on the chain.
|
|
45
|
+
* @param args.assets - The assets to get prices for.
|
|
71
46
|
* @param args.currency - The desired currency of the token prices.
|
|
72
47
|
* @returns The prices for the requested tokens.
|
|
73
48
|
*/
|
|
74
|
-
fetchTokenPrices({
|
|
75
|
-
|
|
76
|
-
tokenAddresses: TokenAddress[];
|
|
49
|
+
fetchTokenPrices({ assets, currency, }: {
|
|
50
|
+
assets: EvmAssetAddressWithChain<ChainId>[];
|
|
77
51
|
currency: Currency;
|
|
78
|
-
}): Promise<
|
|
52
|
+
}): Promise<EvmAssetWithMarketData<ChainId, Currency>[]>;
|
|
79
53
|
/**
|
|
80
54
|
* Retrieves exchange rates in the given currency.
|
|
81
55
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-token-prices-service.d.mts","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"abstract-token-prices-service.d.mts","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAgC;AAEjE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,CAAC,QAAQ,SAAS,MAAM,IAAI;KAC5D,CAAC,IAAI,QAAQ,GAAG,YAAY;CAC9B,CAAC;AAEF,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,GAAG,GAAG,GAAG,IAAI;IAChE,YAAY,EAAE,GAAG,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,GAAG,GAAG,GAAG,IAClD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ceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\
|
|
1
|
+
{"version":3,"file":"abstract-token-prices-service.mjs","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\n\nimport type { MarketDataDetails } from '../TokenRatesController';\n\n/**\n * Represents an exchange rate.\n */\nexport type ExchangeRate = {\n name: string;\n ticker: string;\n value: number;\n currencyType: string;\n usd?: number;\n};\n\n/**\n * A map of currency to its exchange rate.\n */\nexport type ExchangeRatesByCurrency<Currency extends string> = {\n [C in Currency]: ExchangeRate;\n};\n\nexport type EvmAssetAddressWithChain<ChainId extends Hex = Hex> = {\n tokenAddress: Hex;\n chainId: ChainId;\n};\n\nexport type EvmAssetWithId<ChainId extends Hex = Hex> =\n EvmAssetAddressWithChain<ChainId> & {\n assetId: CaipAssetType;\n };\n\nexport type EvmAssetWithMarketData<\n ChainId extends Hex = Hex,\n Currency extends string = string,\n> = EvmAssetAddressWithChain<ChainId> &\n MarketDataDetails & { currency: Currency };\n\n/**\n * An ideal token prices service. All implementations must confirm to this\n * interface.\n *\n * @template ChainId - A type union of valid arguments for the `chainId`\n * argument to `fetchTokenPrices`.\n * @template Currency - A type union of valid arguments for the `currency`\n * argument to `fetchTokenPrices`.\n */\nexport type AbstractTokenPricesService<\n ChainId extends Hex = Hex,\n Currency extends string = string,\n> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {\n /**\n * Retrieves prices in the given currency for the tokens identified by the\n * given addresses which are expected to live on the given chain.\n *\n * @param args - The arguments to this function.\n * @param args.assets - The assets to get prices for.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n fetchTokenPrices({\n assets,\n currency,\n }: {\n assets: EvmAssetAddressWithChain<ChainId>[];\n currency: Currency;\n }): Promise<EvmAssetWithMarketData<ChainId, Currency>[]>;\n\n /**\n * Retrieves exchange rates in the given currency.\n *\n * @param args - The arguments to this function.\n * @param args.baseCurrency - The desired currency of the token prices.\n * @param args.includeUsdRate - Whether to include the USD rate in the response.\n * @param args.cryptocurrencies - The cryptocurrencies to get exchange rates for.\n * @returns The exchange rates in the requested base currency.\n */\n fetchExchangeRates({\n baseCurrency,\n includeUsdRate,\n cryptocurrencies,\n }: {\n baseCurrency: Currency;\n includeUsdRate: boolean;\n cryptocurrencies: string[];\n }): Promise<ExchangeRatesByCurrency<Currency>>;\n\n /**\n * Type guard for whether the API can return token prices for the given chain\n * ID.\n *\n * @param chainId - The chain ID to check.\n * @returns True if the API supports the chain ID, false otherwise.\n */\n validateChainIdSupported(chainId: unknown): chainId is ChainId;\n\n /**\n * Type guard for whether the API can return token prices in the given\n * currency.\n *\n * @param currency - The currency to check.\n * @returns True if the API supports the currency, false otherwise.\n */\n validateCurrencySupported(currency: unknown): currency is Currency;\n};\n"]}
|