@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.
Files changed (90) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/dist/CurrencyRateController.cjs +3 -3
  3. package/dist/CurrencyRateController.cjs.map +1 -1
  4. package/dist/CurrencyRateController.d.cts.map +1 -1
  5. package/dist/CurrencyRateController.d.mts.map +1 -1
  6. package/dist/CurrencyRateController.mjs +3 -3
  7. package/dist/CurrencyRateController.mjs.map +1 -1
  8. package/dist/TokenBalancesController.cjs +48 -10
  9. package/dist/TokenBalancesController.cjs.map +1 -1
  10. package/dist/TokenBalancesController.d.cts +2 -1
  11. package/dist/TokenBalancesController.d.cts.map +1 -1
  12. package/dist/TokenBalancesController.d.mts +2 -1
  13. package/dist/TokenBalancesController.d.mts.map +1 -1
  14. package/dist/TokenBalancesController.mjs +49 -11
  15. package/dist/TokenBalancesController.mjs.map +1 -1
  16. package/dist/TokenDetectionController.cjs +12 -7
  17. package/dist/TokenDetectionController.cjs.map +1 -1
  18. package/dist/TokenDetectionController.d.cts +2 -1
  19. package/dist/TokenDetectionController.d.cts.map +1 -1
  20. package/dist/TokenDetectionController.d.mts +2 -1
  21. package/dist/TokenDetectionController.d.mts.map +1 -1
  22. package/dist/TokenDetectionController.mjs +12 -7
  23. package/dist/TokenDetectionController.mjs.map +1 -1
  24. package/dist/TokenRatesController.cjs +82 -278
  25. package/dist/TokenRatesController.cjs.map +1 -1
  26. package/dist/TokenRatesController.d.cts +9 -35
  27. package/dist/TokenRatesController.d.cts.map +1 -1
  28. package/dist/TokenRatesController.d.mts +9 -35
  29. package/dist/TokenRatesController.d.mts.map +1 -1
  30. package/dist/TokenRatesController.mjs +83 -279
  31. package/dist/TokenRatesController.mjs.map +1 -1
  32. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +2 -3
  33. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
  34. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
  35. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
  36. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs +2 -3
  37. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
  38. package/dist/TokenSearchDiscoveryDataController/types.cjs.map +1 -1
  39. package/dist/TokenSearchDiscoveryDataController/types.d.cts +2 -2
  40. package/dist/TokenSearchDiscoveryDataController/types.d.cts.map +1 -1
  41. package/dist/TokenSearchDiscoveryDataController/types.d.mts +2 -2
  42. package/dist/TokenSearchDiscoveryDataController/types.d.mts.map +1 -1
  43. package/dist/TokenSearchDiscoveryDataController/types.mjs.map +1 -1
  44. package/dist/assetsUtil.cjs +11 -5
  45. package/dist/assetsUtil.cjs.map +1 -1
  46. package/dist/assetsUtil.d.cts +2 -2
  47. package/dist/assetsUtil.d.cts.map +1 -1
  48. package/dist/assetsUtil.d.mts +2 -2
  49. package/dist/assetsUtil.d.mts.map +1 -1
  50. package/dist/assetsUtil.mjs +11 -5
  51. package/dist/assetsUtil.mjs.map +1 -1
  52. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +8 -8
  53. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -1
  54. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts +2 -1
  55. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts.map +1 -1
  56. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts +2 -1
  57. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts.map +1 -1
  58. package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs +8 -8
  59. package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -1
  60. package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs +18 -8
  61. package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs.map +1 -1
  62. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts +4 -2
  63. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts.map +1 -1
  64. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts +4 -2
  65. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts.map +1 -1
  66. package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs +18 -8
  67. package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs.map +1 -1
  68. package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
  69. package/dist/token-prices-service/abstract-token-prices-service.d.cts +17 -43
  70. package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
  71. package/dist/token-prices-service/abstract-token-prices-service.d.mts +17 -43
  72. package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
  73. package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
  74. package/dist/token-prices-service/codefi-v2.cjs +177 -109
  75. package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
  76. package/dist/token-prices-service/codefi-v2.d.cts +47 -10
  77. package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
  78. package/dist/token-prices-service/codefi-v2.d.mts +47 -10
  79. package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
  80. package/dist/token-prices-service/codefi-v2.mjs +177 -109
  81. package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
  82. package/dist/token-service.cjs +6 -4
  83. package/dist/token-service.cjs.map +1 -1
  84. package/dist/token-service.d.cts +3 -1
  85. package/dist/token-service.d.cts.map +1 -1
  86. package/dist/token-service.d.mts +3 -1
  87. package/dist/token-service.d.mts.map +1 -1
  88. package/dist/token-service.mjs +6 -4
  89. package/dist/token-service.mjs.map +1 -1
  90. package/package.json +14 -24
@@ -1 +1 @@
1
- {"version":3,"file":"multi-chain-accounts.cjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-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ChC,QAAgC;IAEhC,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,EAAE;QAClC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;KACpC,CAAC,CAAC;IACH,MAAM,QAAQ,GAAwB,MAAM,IAAA,8BAAW,EAAC,GAAG,EAAE;QAC3D,OAAO,EAAE;YACP,0BAA0B,EAAE,YAAY,QAAQ,EAAE;SACnD;KACF,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAdD,0DAcC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,yBAAyB,CAC7C,OAAyE,EACzE,QAAgC;IAEhC,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,QAAQ,GAAwB,MAAM,IAAA,8BAAW,EAAC,GAAG,EAAE;QAC3D,OAAO,EAAE;YACP,0BAA0B,EAAE,YAAY,QAAQ,EAAE;SACnD;KACF,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAfD,8DAeC","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 * @returns a Balances Response\n */\nexport async function fetchMultiChainBalances(\n address: string,\n options: { networks?: number[] },\n platform: 'extension' | 'mobile',\n) {\n const url = getBalancesUrl(address, {\n networks: options?.networks?.join(),\n });\n const response: GetBalancesResponse = await handleFetch(url, {\n headers: {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n },\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 * @returns a Balances Response\n */\nexport async function fetchMultiChainBalancesV4(\n options: { accountAddresses?: CaipAccountAddress[]; networks?: number[] },\n platform: 'extension' | 'mobile',\n) {\n const url = getBalancesUrlV4({\n accountAddresses: options?.accountAddresses?.join(),\n networks: options?.networks?.join(),\n });\n\n const response: GetBalancesResponse = await handleFetch(url, {\n headers: {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n },\n });\n return response;\n}\n"]}
1
+ {"version":3,"file":"multi-chain-accounts.cjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/multi-chain-accounts.ts"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C,EAChC,QAAiB;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,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;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EAChC,QAAQ,EAAE,WAAW,GAAG,QAAQ,gCAWjC;AAED;;;;;;;;GAQG;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,gCAajC"}
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,OA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AAE,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 +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,CAAC,WAAW,CAAC;AAC9B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAe,EACf,OAAgC,EAChC,QAAgC;IAEhC,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,EAAE;QAClC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;KACpC,CAAC,CAAC;IACH,MAAM,QAAQ,GAAwB,MAAM,WAAW,CAAC,GAAG,EAAE;QAC3D,OAAO,EAAE;YACP,0BAA0B,EAAE,YAAY,QAAQ,EAAE;SACnD;KACF,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,OAAyE,EACzE,QAAgC;IAEhC,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,QAAQ,GAAwB,MAAM,WAAW,CAAC,GAAG,EAAE;QAC3D,OAAO,EAAE;YACP,0BAA0B,EAAE,YAAY,QAAQ,EAAE;SACnD;KACF,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 * @returns a Balances Response\n */\nexport async function fetchMultiChainBalances(\n address: string,\n options: { networks?: number[] },\n platform: 'extension' | 'mobile',\n) {\n const url = getBalancesUrl(address, {\n networks: options?.networks?.join(),\n });\n const response: GetBalancesResponse = await handleFetch(url, {\n headers: {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n },\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 * @returns a Balances Response\n */\nexport async function fetchMultiChainBalancesV4(\n options: { accountAddresses?: CaipAccountAddress[]; networks?: number[] },\n platform: 'extension' | 'mobile',\n) {\n const url = getBalancesUrlV4({\n accountAddresses: options?.accountAddresses?.join(),\n networks: options?.networks?.join(),\n });\n\n const response: GetBalancesResponse = await handleFetch(url, {\n headers: {\n 'x-metamask-clientproduct': `metamask-${platform}`,\n },\n });\n return response;\n}\n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,CAAC,WAAW,CAAC;AAC9B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAe,EACf,OAAgC,EAChC,QAAgC,EAChC,QAAiB;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\n/**\n * Represents the price of a token in a currency.\n */\nexport type TokenPrice<TokenAddress extends Hex, Currency extends string> = {\n tokenAddress: TokenAddress;\n currency: Currency;\n allTimeHigh: number;\n allTimeLow: number;\n circulatingSupply: number;\n dilutedMarketCap: number;\n high1d: number;\n low1d: number;\n marketCap: number;\n marketCapPercentChange1d: number;\n price: number;\n priceChange1d: number;\n pricePercentChange1d: number;\n pricePercentChange1h: number;\n pricePercentChange1y: number;\n pricePercentChange7d: number;\n pricePercentChange14d: number;\n pricePercentChange30d: number;\n pricePercentChange200d: number;\n totalVolume: number;\n};\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 token address to its price.\n */\nexport type TokenPricesByTokenAddress<\n TokenAddress extends Hex,\n Currency extends string,\n> = {\n [A in TokenAddress]: TokenPrice<A, Currency>;\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\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 TokenAddress - A type union of all token addresses. The reason this\n * type parameter exists is so that we can guarantee that same addresses that\n * `fetchTokenPrices` receives are the same addresses that shown up in the\n * return value.\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 TokenAddress 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.chainId - An EIP-155 chain ID.\n * @param args.tokenAddresses - Addresses for tokens that live on the chain.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n fetchTokenPrices({\n chainId,\n tokenAddresses,\n currency,\n }: {\n chainId: ChainId;\n tokenAddresses: TokenAddress[];\n currency: Currency;\n }): Promise<Partial<TokenPricesByTokenAddress<TokenAddress, 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
+ {"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, TokenAddress extends Hex = Hex, Currency extends string = string> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
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.chainId - An EIP-155 chain ID.
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({ chainId, tokenAddresses, currency, }: {
75
- chainId: ChainId;
76
- tokenAddresses: TokenAddress[];
49
+ fetchTokenPrices({ assets, currency, }: {
50
+ assets: EvmAssetAddressWithChain<ChainId>[];
77
51
  currency: Currency;
78
- }): Promise<Partial<TokenPricesByTokenAddress<TokenAddress, Currency>>>;
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,GAAG,EAAE,wBAAwB;AAE3C;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,YAAY,SAAS,GAAG,EAAE,QAAQ,SAAS,MAAM,IAAI;IAC1E,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,wBAAwB,EAAE,MAAM,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;I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ExE;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EACjB,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,EAAE;QACD,YAAY,EAAE,QAAQ,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;QACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;KAC5B,GAAG,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/C;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC;IAE/D;;;;;;OAMG;IACH,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,QAAQ,CAAC;CACpE,CAAC"}
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,C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ils";
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.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, TokenAddress extends Hex = Hex, Currency extends string = string> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
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.chainId - An EIP-155 chain ID.
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({ chainId, tokenAddresses, currency, }: {
75
- chainId: ChainId;
76
- tokenAddresses: TokenAddress[];
49
+ fetchTokenPrices({ assets, currency, }: {
50
+ assets: EvmAssetAddressWithChain<ChainId>[];
77
51
  currency: Currency;
78
- }): Promise<Partial<TokenPricesByTokenAddress<TokenAddress, Currency>>>;
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,GAAG,EAAE,wBAAwB;AAE3C;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,YAAY,SAAS,GAAG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CACpC,OAAO,SAAS,GAAG,GAAG,GAAG,EACzB,YAAY,SAAS,GAAG,GAAG,GAAG,EAC9B,QAAQ,SAAS,MAAM,GAAG,MAAM,IAC9B,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,CAAC,CAAC,GAAG;IAC3D;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EACf,OAAO,EACP,cAAc,EACd,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,cAAc,EAAE,YAAY,EAAE,CAAC;QAC/B,QAAQ,EAAE,QAAQ,CAAC;KACpB,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAExE;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EACjB,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,EAAE;QACD,YAAY,EAAE,QAAQ,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;QACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;KAC5B,GAAG,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/C;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC;IAE/D;;;;;;OAMG;IACH,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,QAAQ,CAAC;CACpE,CAAC"}
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;I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,EACZ,cAAc,EACd,gBAAgB,GACjB,EAAE;QACD,YAAY,EAAE,QAAQ,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;QACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;KAC5B,GAAG,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/C;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC;IAE/D;;;;;;OAMG;IACH,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,QAAQ,CAAC;CACpE,CAAC"}
@@ -1 +1 @@
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 { Hex } from '@metamask/utils';\n\n/**\n * Represents the price of a token in a currency.\n */\nexport type TokenPrice<TokenAddress extends Hex, Currency extends string> = {\n tokenAddress: TokenAddress;\n currency: Currency;\n allTimeHigh: number;\n allTimeLow: number;\n circulatingSupply: number;\n dilutedMarketCap: number;\n high1d: number;\n low1d: number;\n marketCap: number;\n marketCapPercentChange1d: number;\n price: number;\n priceChange1d: number;\n pricePercentChange1d: number;\n pricePercentChange1h: number;\n pricePercentChange1y: number;\n pricePercentChange7d: number;\n pricePercentChange14d: number;\n pricePercentChange30d: number;\n pricePercentChange200d: number;\n totalVolume: number;\n};\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 token address to its price.\n */\nexport type TokenPricesByTokenAddress<\n TokenAddress extends Hex,\n Currency extends string,\n> = {\n [A in TokenAddress]: TokenPrice<A, Currency>;\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\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 TokenAddress - A type union of all token addresses. The reason this\n * type parameter exists is so that we can guarantee that same addresses that\n * `fetchTokenPrices` receives are the same addresses that shown up in the\n * return value.\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 TokenAddress 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.chainId - An EIP-155 chain ID.\n * @param args.tokenAddresses - Addresses for tokens that live on the chain.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n fetchTokenPrices({\n chainId,\n tokenAddresses,\n currency,\n }: {\n chainId: ChainId;\n tokenAddresses: TokenAddress[];\n currency: Currency;\n }): Promise<Partial<TokenPricesByTokenAddress<TokenAddress, 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
+ {"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"]}