Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OpenSea V1 -> V2 patch #8155

Merged
merged 7 commits into from
Dec 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge release/7.12.4-2
bergeron committed Dec 19, 2023
commit c1b80d16a89e2322d66c8566f1feeb075f1dfbe7
927 changes: 670 additions & 257 deletions patches/@metamask+assets-controllers+7.0.0.patch
Original file line number Diff line number Diff line change
@@ -110,46 +110,11 @@ index 332c87d..b634fde 100644
/**
* Enumerate assets assigned to an owner.
*
diff --git a/node_modules/@metamask/assets-controllers/dist/NftController.d.ts b/node_modules/@metamask/assets-controllers/dist/NftController.d.ts
index a71d8f0..0353e90 100644
--- a/node_modules/@metamask/assets-controllers/dist/NftController.d.ts
+++ b/node_modules/@metamask/assets-controllers/dist/NftController.d.ts
@@ -140,7 +140,10 @@ export interface NftState extends BaseState {
*/
export declare class NftController extends BaseController<NftConfig, NftState> {
private mutex;
- private getNftApi;
+ getNftApi({ contractAddress, tokenId, }: {
+ contractAddress: string;
+ tokenId: string;
+ }): string;
private getNftContractInformationApi;
/**
* Helper method to update nested state for allNfts and allNftContracts.
diff --git a/node_modules/@metamask/assets-controllers/dist/NftController.js b/node_modules/@metamask/assets-controllers/dist/NftController.js
index 6a14075..fc7842e 100644
index 6a14075..c2662fb 100644
--- a/node_modules/@metamask/assets-controllers/dist/NftController.js
+++ b/node_modules/@metamask/assets-controllers/dist/NftController.js
@@ -9,13 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.NftController = void 0;
+exports.NftController = exports.OpenSeaV2ChainIds = void 0;
const events_1 = require("events");
const ethereumjs_util_1 = require("ethereumjs-util");
const async_mutex_1 = require("async-mutex");
const base_controller_1 = require("@metamask/base-controller");
const controller_utils_1 = require("@metamask/controller-utils");
const assetsUtil_1 = require("./assetsUtil");
+var OpenSeaV2ChainIds;
+(function (OpenSeaV2ChainIds) {
+ OpenSeaV2ChainIds["ethereum"] = "ethereum";
+})(OpenSeaV2ChainIds = exports.OpenSeaV2ChainIds || (exports.OpenSeaV2ChainIds = {}));
const ALL_NFTS_STATE_KEY = 'allNfts';
const ALL_NFTS_CONTRACTS_STATE_KEY = 'allNftContracts';
/**
@@ -55,8 +59,9 @@ class NftController extends base_controller_1.BaseController {
@@ -55,8 +55,9 @@ class NftController extends base_controller_1.BaseController {
selectedAddress: '',
chainId: '',
ipfsGateway: controller_utils_1.IPFS_DEFAULT_GATEWAY_URL,
@@ -160,7 +125,7 @@ index 6a14075..fc7842e 100644
};
this.defaultState = {
allNftContracts: {},
@@ -71,23 +76,22 @@ class NftController extends base_controller_1.BaseController {
@@ -71,23 +72,19 @@ class NftController extends base_controller_1.BaseController {
this.getERC1155BalanceOf = getERC1155BalanceOf;
this.getERC1155TokenURI = getERC1155TokenURI;
this.onNftAdded = onNftAdded;
@@ -178,29 +143,25 @@ index 6a14075..fc7842e 100644
- return useProxy
- ? `${controller_utils_1.OPENSEA_PROXY_URL}/asset/${contractAddress}/${tokenId}`
- : `${controller_utils_1.OPENSEA_API_URL}/asset/${contractAddress}/${tokenId}`;
+ getNftApi({ contractAddress, tokenId, }) {
+ return `${controller_utils_1.OPENSEA_PROXY_URL}/chain/${OpenSeaV2ChainIds.ethereum}/contract/${contractAddress}/nfts/${tokenId}`;
+ getNftApi({ contractAddress, tokenId }) {
+ return `${controller_utils_1.OPENSEA_PROXY_URL}/asset/${contractAddress}/${tokenId}`;
}
- getNftContractInformationApi({ contractAddress, useProxy, }) {
- return useProxy
- ? `${controller_utils_1.OPENSEA_PROXY_URL}/asset_contract/${contractAddress}`
- : `${controller_utils_1.OPENSEA_API_URL}/asset_contract/${contractAddress}`;
+ getNftContractInformationApi({ contractAddress, }) {
+ return `${controller_utils_1.OPENSEA_PROXY_URL}/chain/${OpenSeaV2ChainIds.ethereum}/contract/${contractAddress}`;
+ }
+ getNftCollectionInformationApi({ collectionSlug, }) {
+ return `${controller_utils_1.OPENSEA_PROXY_URL}/collections/${collectionSlug}`;
+ getNftContractInformationApi({ contractAddress }) {
+ return `${controller_utils_1.OPENSEA_PROXY_URL}/asset_contract/${contractAddress}`;
}
/**
* Helper method to update nested state for allNfts and allNftContracts.
@@ -119,31 +123,17 @@ class NftController extends base_controller_1.BaseController {
@@ -119,29 +116,15 @@ class NftController extends base_controller_1.BaseController {
*/
getNftInformationFromApi(contractAddress, tokenId) {
return __awaiter(this, void 0, void 0, function* () {
+ try{
// Attempt to fetch the data with the proxy
- let nftInformation = yield (0, controller_utils_1.fetchWithErrorHandling)({
+ const nftInformation = yield (0, controller_utils_1.fetchWithErrorHandling)({
let nftInformation = yield (0, controller_utils_1.fetchWithErrorHandling)({
url: this.getNftApi({
contractAddress,
tokenId,
@@ -224,19 +185,9 @@ index 6a14075..fc7842e 100644
- }
+
// if we were still unable to fetch the data we return out the default/null of `NftMetadata`
- if (!nftInformation) {
+ if (!(nftInformation === null || nftInformation === void 0 ? void 0 : nftInformation.nft)) {
if (!nftInformation) {
return {
name: null,
description: null,
@@ -153,12 +143,21 @@ class NftController extends base_controller_1.BaseController {
}
// if we've reached this point, we have successfully fetched some data for nftInformation
// now we reconfigure the data to conform to the `NftMetadata` type for storage.
- const { num_sales, background_color, image_url, image_preview_url, image_thumbnail_url, image_original_url, animation_url, animation_original_url, name, description, external_link, creator, last_sale, asset_contract: { schema_name }, } = nftInformation;
+ const { num_sales, background_color, image_url, image_preview_url, image_thumbnail_url, image_original_url, animation_url, animation_original_url, name, description, external_link, creator, last_sale, asset_contract: { schema_name }, } = (0, assetsUtil_1.mapOpenSeaDetailedNftV2ToV1)(nftInformation.nft);;
/* istanbul ignore next */
const nftMetadata = Object.assign({}, { name: name || null }, { description: description || null }, { image: image_url || null }, creator && { creator }, num_sales && { numberOfSales: num_sales }, background_color && { backgroundColor: background_color }, image_preview_url && { imagePreview: image_preview_url }, image_thumbnail_url && { imageThumbnail: image_thumbnail_url }, image_original_url && { imageOriginal: image_original_url }, animation_url && { animation: animation_url }, animation_original_url && {
@@ -159,6 +142,15 @@ class NftController extends base_controller_1.BaseController {
animationOriginal: animation_original_url,
}, external_link && { externalLink: external_link }, last_sale && { lastSale: last_sale }, schema_name && { standard: schema_name });
return nftMetadata;
@@ -252,7 +203,7 @@ index 6a14075..fc7842e 100644
});
}
/**
@@ -170,13 +169,49 @@ class NftController extends base_controller_1.BaseController {
@@ -170,13 +162,49 @@ class NftController extends base_controller_1.BaseController {
*/
getNftInformationFromTokenURI(contractAddress, tokenId) {
return __awaiter(this, void 0, void 0, function* () {
@@ -305,15 +256,15 @@ index 6a14075..fc7842e 100644
try {
const object = yield (0, controller_utils_1.handleFetch)(tokenURI);
// TODO: Check image_url existence. This is not part of EIP721 nor EIP1155
@@ -189,6 +224,7 @@ class NftController extends base_controller_1.BaseController {
@@ -189,6 +217,7 @@ class NftController extends base_controller_1.BaseController {
description: object.description,
standard,
favorite: false,
+ tokenURI
};
}
catch (_a) {
@@ -198,6 +234,8 @@ class NftController extends base_controller_1.BaseController {
@@ -198,6 +227,8 @@ class NftController extends base_controller_1.BaseController {
description: null,
standard: standard || null,
favorite: false,
@@ -322,7 +273,7 @@ index 6a14075..fc7842e 100644
};
}
});
@@ -255,12 +293,25 @@ class NftController extends base_controller_1.BaseController {
@@ -255,12 +286,25 @@ class NftController extends base_controller_1.BaseController {
return yield this.getNftInformationFromTokenURI(contractAddress, tokenId);
}));
let openSeaMetadata;
@@ -350,7 +301,7 @@ index 6a14075..fc7842e 100644
});
}
/**
@@ -272,33 +323,20 @@ class NftController extends base_controller_1.BaseController {
@@ -272,34 +316,15 @@ class NftController extends base_controller_1.BaseController {
getNftContractInformationFromApi(contractAddress) {
return __awaiter(this, void 0, void 0, function* () {
/* istanbul ignore if */
@@ -361,37 +312,32 @@ index 6a14075..fc7842e 100644
- useProxy: true,
}),
});
- // if we successfully fetched return the fetched data immediately
+ // If we successfully fetched the contract
// if we successfully fetched return the fetched data immediately
if (apiNftContractObject) {
- return apiNftContractObject;
- }
return apiNftContractObject;
}
- // if we were unsuccessful in fetching from the API and an OpenSea API key is present
- // attempt to refetch directly against the OpenSea API and if successful return the data immediately
- if (this.openSeaApiKey) {
- apiNftContractObject = yield (0, controller_utils_1.fetchWithErrorHandling)({
- url: this.getNftContractInformationApi({
- contractAddress,
- useProxy: false,
+ // Then fetch some additional details from the collection
+ const collection = yield (0, controller_utils_1.fetchWithErrorHandling)({
+ url: this.getNftCollectionInformationApi({
+ collectionSlug: apiNftContractObject.collection,
}),
- }),
- options: {
- headers: { 'X-API-KEY': this.openSeaApiKey },
- },
- // catch 403 errors (in case API key is down we don't want to blow up)
- errorCodesToCatch: [403],
});
- });
- if (apiNftContractObject) {
- return apiNftContractObject;
- }
+ return (0, assetsUtil_1.mapOpenSeaContractV2ToV1)(apiNftContractObject, collection);
}
- }
// If we've reached this point we were unable to fetch data from either the proxy or opensea so we return
// the default/null of ApiNftContract
@@ -347,7 +385,7 @@ class NftController extends base_controller_1.BaseController {
return {
@@ -347,7 +372,7 @@ class NftController extends base_controller_1.BaseController {
return yield this.getNftContractInformationFromContract(contractAddress);
}));
let openSeaContractData;
@@ -400,100 +346,20 @@ index 6a14075..fc7842e 100644
openSeaContractData = yield (0, controller_utils_1.safelyExecute)(() => __awaiter(this, void 0, void 0, function* () {
return yield this.getNftContractInformationFromApi(contractAddress);
}));
@@ -428,6 +466,7 @@ class NftController extends base_controller_1.BaseController {
@@ -428,6 +453,7 @@ class NftController extends base_controller_1.BaseController {
tokenId: tokenId.toString(),
standard: nftMetadata.standard,
source: detection ? 'detected' : 'custom',
+ tokenURI: nftMetadata.tokenURI
});
}
return newNfts;
diff --git a/node_modules/@metamask/assets-controllers/dist/NftDetectionController.d.ts b/node_modules/@metamask/assets-controllers/dist/NftDetectionController.d.ts
index 20d65ab..c26f596 100644
--- a/node_modules/@metamask/assets-controllers/dist/NftDetectionController.d.ts
+++ b/node_modules/@metamask/assets-controllers/dist/NftDetectionController.d.ts
@@ -127,6 +127,7 @@ export declare class NftDetectionController extends BaseController<NftDetectionC
name: string;
private getOpenSeaApiKey;
private addNft;
+ private getNftApi;
private getNftState;
/**
* Creates an NftDetectionController instance.
@@ -137,16 +138,18 @@ export declare class NftDetectionController extends BaseController<NftDetectionC
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
* @param options.getOpenSeaApiKey - Gets the OpenSea API key, if one is set.
* @param options.addNft - Add an NFT.
+ * @param options.getNftApi - Gets the URL to fetch an NFT from OpenSea.
* @param options.getNftState - Gets the current state of the Assets controller.
* @param config - Initial options used to configure this controller.
* @param state - Initial state to set on this controller.
*/
- constructor({ onPreferencesStateChange, onNetworkStateChange, getOpenSeaApiKey, addNft, getNftState, }: {
+ constructor({ onPreferencesStateChange, onNetworkStateChange, getOpenSeaApiKey, addNft, getNftApi, getNftState, }: {
onNftsStateChange: (listener: (nftsState: NftState) => void) => void;
onPreferencesStateChange: (listener: (preferencesState: PreferencesState) => void) => void;
onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void;
getOpenSeaApiKey: () => string | undefined;
addNft: NftController['addNft'];
+ getNftApi: NftController['getNftApi'];
getNftState: () => NftState;
}, config?: Partial<NftDetectionConfig>, state?: Partial<BaseState>);
/**
diff --git a/node_modules/@metamask/assets-controllers/dist/NftDetectionController.js b/node_modules/@metamask/assets-controllers/dist/NftDetectionController.js
index 1f234ca..cfa84bf 100644
index 1f234ca..ef2b7e7 100644
--- a/node_modules/@metamask/assets-controllers/dist/NftDetectionController.js
+++ b/node_modules/@metamask/assets-controllers/dist/NftDetectionController.js
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.NftDetectionController = void 0;
const base_controller_1 = require("@metamask/base-controller");
const controller_utils_1 = require("@metamask/controller-utils");
+const assetsUtil_1 = require("./assetsUtil");
+const NftController_1 = require("./NftController");
const DEFAULT_INTERVAL = 180000;
/**
* Controller that passively polls on a set interval for NFT auto detection
@@ -26,11 +28,12 @@ class NftDetectionController extends base_controller_1.BaseController {
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
* @param options.getOpenSeaApiKey - Gets the OpenSea API key, if one is set.
* @param options.addNft - Add an NFT.
+ * @param options.getNftApi - Gets the URL to fetch an NFT from OpenSea.
* @param options.getNftState - Gets the current state of the Assets controller.
* @param config - Initial options used to configure this controller.
* @param state - Initial state to set on this controller.
*/
- constructor({ onPreferencesStateChange, onNetworkStateChange, getOpenSeaApiKey, addNft, getNftState, }, config, state) {
+ constructor({ onPreferencesStateChange, onNetworkStateChange, getOpenSeaApiKey, addNft, getNftApi, getNftState, }, config, state) {
super(config, state);
/**
* Name of this controller used during composition
@@ -74,47 +77,40 @@ class NftDetectionController extends base_controller_1.BaseController {
});
this.getOpenSeaApiKey = getOpenSeaApiKey;
this.addNft = addNft;
+ this.getNftApi = getNftApi;
}
- getOwnerNftApi({ address, offset, useProxy, }) {
- return useProxy
- ? `${controller_utils_1.OPENSEA_PROXY_URL}/assets?owner=${address}&offset=${offset}&limit=50`
- : `${controller_utils_1.OPENSEA_API_URL}/assets?owner=${address}&offset=${offset}&limit=50`;
+ getOwnerNftApi({ address, next, }) {
+ return `${controller_utils_1.OPENSEA_PROXY_URL}/chain/${NftController_1.OpenSeaV2ChainIds.ethereum}/account/${address}/nfts?limit=200&next=${next !== null && next !== void 0 ? next : ''}`;
}
getOwnerNfts(address) {
- var _a;
return __awaiter(this, void 0, void 0, function* () {
let nftApiResponse;
let nfts = [];
- const openSeaApiKey = this.getOpenSeaApiKey();
- let offset = 0;
- let pagingFinish = false;
- /* istanbul ignore if */
+ let next;
do {
nftApiResponse = yield (0, controller_utils_1.fetchWithErrorHandling)({
- url: this.getOwnerNftApi({ address, offset, useProxy: true }),
+ url: this.getOwnerNftApi({ address, next }),
@@ -94,19 +94,6 @@ class NftDetectionController extends base_controller_1.BaseController {
url: this.getOwnerNftApi({ address, offset, useProxy: true }),
timeout: 15000,
});
- if (openSeaApiKey && !nftApiResponse) {
@@ -512,30 +378,6 @@ index 1f234ca..cfa84bf 100644
if (!nftApiResponse) {
return nfts;
}
- ((_a = nftApiResponse === null || nftApiResponse === void 0 ? void 0 : nftApiResponse.assets) === null || _a === void 0 ? void 0 : _a.length) !== 0
- ? (nfts = [...nfts, ...nftApiResponse.assets])
- : (pagingFinish = true);
- offset += 50;
- } while (!pagingFinish);
+ const newNfts = yield Promise.all(nftApiResponse.nfts.map((nftV2) => __awaiter(this, void 0, void 0, function* () {
+ var _a, _b;
+ const nftV1 = (0, assetsUtil_1.mapOpenSeaNftV2ToV1)(nftV2);
+ // If the image hasn't been processed into OpenSea's CDN, the image_url will be null.
+ // Try fetching the NFT individually, which returns the original image url from metadata if available.
+ if (!nftV1.image_url && nftV2.metadata_url) {
+ const nftDetails = yield (0, controller_utils_1.safelyExecute)(() => (0, controller_utils_1.timeoutFetch)(this.getNftApi({
+ contractAddress: nftV2.contract,
+ tokenId: nftV2.identifier,
+ }), undefined, 1000).then((r) => r.json()));
+ nftV1.image_original_url = (_b = (_a = nftDetails === null || nftDetails === void 0 ? void 0 : nftDetails.nft) === null || _a === void 0 ? void 0 : _a.image_url) !== null && _b !== void 0 ? _b : null;
+ }
+ return nftV1;
+ })));
+ nfts = [...nfts, ...newNfts];
+ } while ((next = nftApiResponse.next));
return nfts;
});
}
diff --git a/node_modules/@metamask/assets-controllers/dist/Standards/ERC20Standard.js b/node_modules/@metamask/assets-controllers/dist/Standards/ERC20Standard.js
index 9ddbc28..b9f309a 100644
--- a/node_modules/@metamask/assets-controllers/dist/Standards/ERC20Standard.js
@@ -841,7 +683,7 @@ index 8bb7c20..d0dfdee 100644
//# sourceMappingURL=TokenRatesController.d.ts.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js b/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js
index e3f81e9..c8cb97d 100644
index e3f81e9..8f6a719 100644
--- a/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js
+++ b/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js
@@ -8,37 +8,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
@@ -1683,7 +1525,7 @@ index 1b69903..d45fe80 100644
/**
* Check if token detection is enabled for certain networks.
diff --git a/node_modules/@metamask/assets-controllers/dist/assetsUtil.js b/node_modules/@metamask/assets-controllers/dist/assetsUtil.js
index 4b54e82..f03a880 100644
index 4b54e82..4cb845e 100644
--- a/node_modules/@metamask/assets-controllers/dist/assetsUtil.js
+++ b/node_modules/@metamask/assets-controllers/dist/assetsUtil.js
@@ -120,6 +120,7 @@ var SupportedTokenDetectionNetworks;
@@ -1694,85 +1536,656 @@ index 4b54e82..f03a880 100644
})(SupportedTokenDetectionNetworks = exports.SupportedTokenDetectionNetworks || (exports.SupportedTokenDetectionNetworks = {}));
/**
* Check if token detection is enabled for certain networks.
@@ -225,4 +226,80 @@ function ethersBigNumberToBN(bigNumber) {
@@ -225,4 +226,50 @@ function ethersBigNumberToBN(bigNumber) {
return new ethereumjs_util_1.BN((0, ethereumjs_util_1.stripHexPrefix)(bigNumber.toHexString()), 'hex');
}
exports.ethersBigNumberToBN = ethersBigNumberToBN;
+/**
+ * Maps an OpenSea V2 NFT to the V1 schema.
+ * @param nft - The V2 NFT to map.
+ * @returns The NFT in the V1 schema.
+ * Partitions a list of values into groups that are at most `batchSize` in
+ * length.
+ *
+ * @param values - The list of values.
+ * @param args - The remaining arguments.
+ * @param args.batchSize - The desired maximum number of values per batch.
+ * @returns The list of batches.
+ */
+function mapOpenSeaNftV2ToV1(nft) {
+ return {
+ token_id: nft.identifier,
+ num_sales: null,
+ background_color: null,
+ image_url: nft.image_url,
+ image_preview_url: null,
+ image_thumbnail_url: null,
+ image_original_url: null,
+ animation_url: null,
+ animation_original_url: null,
+ name: nft.name,
+ description: nft.description,
+ external_link: null,
+ asset_contract: {
+ address: nft.contract,
+ asset_contract_type: null,
+ created_date: null,
+ schema_name: nft.token_standard.toUpperCase(),
+ symbol: null,
+ total_supply: null,
+ description: nft.description,
+ external_link: null,
+ collection: {
+ name: nft.collection,
+ image_url: null,
+ },
+ },
+ creator: {
+ user: { username: '' },
+ profile_img_url: '',
+ address: '',
+ },
+ last_sale: null,
+ };
+function divideIntoBatches(values, { batchSize }) {
+ const batches = [];
+ for (let i = 0; i < values.length; i += batchSize) {
+ batches.push(values.slice(i, i + batchSize));
+ }
+ return batches;
+}
+exports.mapOpenSeaNftV2ToV1 = mapOpenSeaNftV2ToV1;
+exports.divideIntoBatches = divideIntoBatches;
+/**
+ * Maps an OpenSea V2 detailed NFT to the V1 schema.
+ * @param nft - The V2 detailed NFT to map.
+ * @returns The NFT in the V1 schema.
+ * Constructs an object from processing batches of the given values
+ * sequentially.
+ *
+ * @param args - The arguments to this function.
+ * @param args.values - A list of values to iterate over.
+ * @param args.batchSize - The maximum number of values in each batch.
+ * @param args.eachBatch - A function to call for each batch. This function is
+ * similar to the function that `Array.prototype.reduce` takes, in that it
+ * receives the object that is being built, each batch in the list of batches
+ * and the index, and should return an updated version of the object.
+ * @param args.initialResult - The initial value of the final data structure,
+ * i.e., the value that will be fed into the first call of `eachBatch`.
+ * @returns The built object.
+ */
+function mapOpenSeaDetailedNftV2ToV1(nft) {
+ const mapped = mapOpenSeaNftV2ToV1(nft);
+ return Object.assign(Object.assign({}, mapped), { animation_url: nft.animation_url, creator: Object.assign(Object.assign({}, mapped.creator), { address: nft.creator }) });
+function reduceInBatchesSerially({ values, batchSize, eachBatch, initialResult, }) {
+ return __awaiter(this, void 0, void 0, function* () {
+ const batches = divideIntoBatches(values, { batchSize });
+ let workingResult = initialResult;
+ for (const [index, batch] of batches.entries()) {
+ workingResult = yield eachBatch(workingResult, batch, index);
+ }
+ // There's no way around this — we have to assume that in the end, the result
+ // matches the intended type.
+ const finalResult = workingResult;
+ return finalResult;
+ });
+}
+exports.mapOpenSeaDetailedNftV2ToV1 = mapOpenSeaDetailedNftV2ToV1;
+exports.reduceInBatchesSerially = reduceInBatchesSerially;
//# sourceMappingURL=assetsUtil.js.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/index.d.ts b/node_modules/@metamask/assets-controllers/dist/index.d.ts
index 9526321..5f08fce 100644
--- a/node_modules/@metamask/assets-controllers/dist/index.d.ts
+++ b/node_modules/@metamask/assets-controllers/dist/index.d.ts
@@ -9,4 +9,5 @@ export * from './TokenListController';
export * from './TokenRatesController';
export * from './TokensController';
export { isTokenDetectionSupportedForNetwork, formatIconUrlWithProxy, getFormattedIpfsUrl, } from './assetsUtil';
+export { CodefiTokenPricesServiceV2 } from './token-prices-service';
//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/index.js b/node_modules/@metamask/assets-controllers/dist/index.js
index d4d8682..96d7224 100644
--- a/node_modules/@metamask/assets-controllers/dist/index.js
+++ b/node_modules/@metamask/assets-controllers/dist/index.js
@@ -29,4 +29,6 @@ var assetsUtil_1 = require("./assetsUtil");
Object.defineProperty(exports, "isTokenDetectionSupportedForNetwork", { enumerable: true, get: function () { return assetsUtil_1.isTokenDetectionSupportedForNetwork; } });
Object.defineProperty(exports, "formatIconUrlWithProxy", { enumerable: true, get: function () { return assetsUtil_1.formatIconUrlWithProxy; } });
Object.defineProperty(exports, "getFormattedIpfsUrl", { enumerable: true, get: function () { return assetsUtil_1.getFormattedIpfsUrl; } });
+var token_prices_service_1 = require("./token-prices-service");
+Object.defineProperty(exports, "CodefiTokenPricesServiceV2", { enumerable: true, get: function () { return token_prices_service_1.CodefiTokenPricesServiceV2; } });
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/index.js.map b/node_modules/@metamask/assets-controllers/dist/index.js.map
index ea0eaab..e528b48 100644
--- a/node_modules/@metamask/assets-controllers/dist/index.js.map
+++ b/node_modules/@metamask/assets-controllers/dist/index.js.map
@@ -1 +1 @@
-{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,6DAA2C;AAC3C,2DAAyC;AACzC,kDAAgC;AAChC,2DAAyC;AACzC,4DAA0C;AAC1C,6DAA2C;AAC3C,wDAAsC;AACtC,yDAAuC;AACvC,qDAAmC;AACnC,2CAIsB;AAHpB,iIAAA,mCAAmC,OAAA;AACnC,oHAAA,sBAAsB,OAAA;AACtB,iHAAA,mBAAmB,OAAA","sourcesContent":["export * from './AccountTrackerController';\nexport * from './AssetsContractController';\nexport * from './CurrencyRateController';\nexport * from './NftController';\nexport * from './NftDetectionController';\nexport * from './TokenBalancesController';\nexport * from './TokenDetectionController';\nexport * from './TokenListController';\nexport * from './TokenRatesController';\nexport * from './TokensController';\nexport {\n isTokenDetectionSupportedForNetwork,\n formatIconUrlWithProxy,\n getFormattedIpfsUrl,\n} from './assetsUtil';\n"]}
\ No newline at end of file
+{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,6DAA2C;AAC3C,2DAAyC;AACzC,kDAAgC;AAChC,2DAAyC;AACzC,4DAA0C;AAC1C,6DAA2C;AAC3C,wDAAsC;AACtC,yDAAuC;AACvC,qDAAmC;AACnC,2CAIsB;AAHpB,iIAAA,mCAAmC,OAAA;AACnC,oHAAA,sBAAsB,OAAA;AACtB,iHAAA,mBAAmB,OAAA","sourcesContent":["export * from './AccountTrackerController';\nexport * from './AssetsContractController';\nexport * from './CurrencyRateController';\nexport * from './NftController';\nexport * from './NftDetectionController';\nexport * from './TokenBalancesController';\nexport * from './TokenDetectionController';\nexport * from './TokenListController';\nexport * from './TokenRatesController';\nexport * from './TokensController';\nexport {\n isTokenDetectionSupportedForNetwork,\n formatIconUrlWithProxy,\n getFormattedIpfsUrl,\n} from './assetsUtil';\nexport { CodefiTokenPricesServiceV2 } from './token-prices-service';\n"]}
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts
new file mode 100644
index 0000000..7d4d0eb
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts
@@ -0,0 +1,62 @@
+import type { Hex } from '@metamask/utils';
+/**
+ * Maps an OpenSea V2 contract to the V1 schema.
+ * @param contract - The v2 contract data.
+ * @param collection - The v2 collection data.
+ * @returns The contract in the v1 schema.
+ * Represents the price of a token in a currency.
+ */
+function mapOpenSeaContractV2ToV1(contract, collection) {
+ var _a, _b, _c;
+ return {
+ address: contract.address,
+ asset_contract_type: null,
+ created_date: null,
+ schema_name: contract.contract_standard.toUpperCase(),
+ symbol: null,
+ total_supply: contract.supply.toString(),
+ description: (_a = collection === null || collection === void 0 ? void 0 : collection.description) !== null && _a !== void 0 ? _a : null,
+ external_link: (_b = collection === null || collection === void 0 ? void 0 : collection.project_url) !== null && _b !== void 0 ? _b : null,
+ collection: {
+ name: (_c = collection === null || collection === void 0 ? void 0 : collection.name) !== null && _c !== void 0 ? _c : contract.name,
+ image_url: collection === null || collection === void 0 ? void 0 : collection.image_url,
+ },
+ };
+export declare type TokenPrice<TokenAddress extends Hex, Currency extends string> = {
+ tokenAddress: TokenAddress;
+ value: number;
+ currency: Currency;
+};
+/**
+ * A map of token address to its price.
+ */
+export declare type TokenPricesByTokenAddress<TokenAddress extends Hex, Currency extends string> = {
+ [A in TokenAddress]: TokenPrice<A, Currency>;
+};
+/**
+ * An ideal token prices service. All implementations must confirm to this
+ * interface.
+ *
+ * @template ChainId - A type union of valid arguments for the `chainId`
+ * argument to `fetchTokenPrices`.
+ * @template TokenAddress - A type union of all token addresses. The reason this
+ * type parameter exists is so that we can guarantee that same addresses that
+ * `fetchTokenPrices` receives are the same addresses that shown up in the
+ * return value.
+ * @template Currency - A type union of valid arguments for the `currency`
+ * argument to `fetchTokenPrices`.
+ */
+export declare type AbstractTokenPricesService<ChainId extends Hex = Hex, TokenAddress extends Hex = Hex, Currency extends string = string> = {
+ /**
+ * Retrieves prices in the given currency for the tokens identified by the
+ * given addresses which are expected to live on the given chain.
+ *
+ * @param args - The arguments to this function.
+ * @param args.chainId - An EIP-155 chain ID.
+ * @param args.tokenAddresses - Addresses for tokens that live on the chain.
+ * @param args.currency - The desired currency of the token prices.
+ * @returns The prices for the requested tokens.
+ */
+ fetchTokenPrices({ chainId, tokenAddresses, currency, }: {
+ chainId: ChainId;
+ tokenAddresses: TokenAddress[];
+ currency: Currency;
+ }): Promise<TokenPricesByTokenAddress<TokenAddress, Currency>>;
+ /**
+ * Type guard for whether the API can return token prices for the given chain
+ * ID.
+ *
+ * @param chainId - The chain ID to check.
+ * @returns True if the API supports the chain ID, false otherwise.
+ */
+ validateChainIdSupported(chainId: unknown): chainId is ChainId;
+ /**
+ * Type guard for whether the API can return token prices in the given
+ * currency.
+ *
+ * @param currency - The currency to check.
+ * @returns True if the API supports the currency, false otherwise.
+ */
+ validateCurrencySupported(currency: unknown): currency is Currency;
+};
+//# sourceMappingURL=abstract-token-prices-service.d.ts.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts.map b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts.map
new file mode 100644
index 0000000..4d99cdf
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"abstract-token-prices-service.d.ts","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;GAEG;AACH,oBAAY,UAAU,CAAC,YAAY,SAAS,GAAG,EAAE,QAAQ,SAAS,MAAM,IAAI;IAC1E,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,oBAAY,yBAAyB,CACnC,YAAY,SAAS,GAAG,EACxB,QAAQ,SAAS,MAAM,IACrB;KACD,CAAC,IAAI,YAAY,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,oBAAY,0BAA0B,CACpC,OAAO,SAAS,GAAG,GAAG,GAAG,EACzB,YAAY,SAAS,GAAG,GAAG,GAAG,EAC9B,QAAQ,SAAS,MAAM,GAAG,MAAM,IAC9B;IACF;;;;;;;;;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,yBAAyB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE/D;;;;;;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"}
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.js b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.js
new file mode 100644
index 0000000..6b79d8f
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.js
@@ -0,0 +1,3 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+//# sourceMappingURL=abstract-token-prices-service.js.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.js.map b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.js.map
new file mode 100644
index 0000000..178484b
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"abstract-token-prices-service.js","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import 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 value: number;\n currency: Currency;\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 * 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> = {\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<TokenPricesByTokenAddress<TokenAddress, 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"]}
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts
new file mode 100644
index 0000000..dbae7a1
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts
@@ -0,0 +1,80 @@
+import type { Hex } from '@metamask/utils';
+import type { AbstractTokenPricesService, TokenPricesByTokenAddress } from './abstract-token-prices-service';
+/**
+ * The list of currencies that can be supplied as the `vsCurrency` parameter to
+ * the `/spot-prices` endpoint, in lowercase form.
+ */
+export declare const SUPPORTED_CURRENCIES: readonly ["btc", "eth", "ltc", "bch", "bnb", "eos", "xrp", "xlm", "link", "dot", "yfi", "usd", "aed", "ars", "aud", "bdt", "bhd", "bmd", "brl", "cad", "chf", "clp", "cny", "czk", "dkk", "eur", "gbp", "hkd", "huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php", "pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar", "xdr", "xag", "xau", "bits", "sats"];
+/**
+ * A currency that can be supplied as the `vsCurrency` parameter to
+ * the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.
+ */
+declare type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number] | Uppercase<(typeof SUPPORTED_CURRENCIES)[number]>;
+/**
+ * The list of chain IDs that can be supplied in the URL for the `/spot-prices`
+ * endpoint, but in hexadecimal form (for consistency with how we represent
+ * chain IDs in other places).
+ */
+export declare const SUPPORTED_CHAIN_IDS: readonly ["0x1", "0xa", "0x19", "0x38", "0x39", "0x42", "0x46", "0x52", "0x58", "0x64", "0x6a", "0x7a", "0x80", "0x89", "0xfa", "0x120", "0x141", "0x144", "0x169", "0x440", "0x504", "0x505", "0x2105", "0x2107", "0x2710", "0xa4b1", "0xa4ec", "0xa516", "0xa86a", "0x518af", "0x4e454152", "0x63564c40"];
+/**
+ * A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,
+ * but in hexadecimal form (for consistency with how we represent chain IDs in
+ * other places).
+ */
+declare type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
+/**
+ * This version of the token prices service uses V2 of the Codefi Price API to
+ * fetch token prices.
+ */
+export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency> {
+ #private;
+ /**
+ * Construct a Codefi Token Price Service.
+ *
+ * @param options - Constructor options
+ * @param options.retries - Number of retry attempts for each token price update.
+ * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures
+ * allowed before breaking the circuit and pausing further updates.
+ * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks
+ * from too many consecutive failures.
+ */
+ constructor({ retries, maximumConsecutiveFailures, circuitBreakDuration, }?: {
+ retries?: number;
+ maximumConsecutiveFailures?: number;
+ circuitBreakDuration?: number;
+ });
+ /**
+ * Retrieves prices in the given currency for the tokens identified by the
+ * given addresses which are expected to live on the given chain.
+ *
+ * @param args - The arguments to function.
+ * @param args.chainId - An EIP-155 chain ID.
+ * @param args.tokenAddresses - Addresses for tokens that live on the chain.
+ * @param args.currency - The desired currency of the token prices.
+ * @returns The prices for the requested tokens.
+ */
+ fetchTokenPrices({ chainId, tokenAddresses, currency, }: {
+ chainId: SupportedChainId;
+ tokenAddresses: Hex[];
+ currency: SupportedCurrency;
+ }): Promise<TokenPricesByTokenAddress<Hex, SupportedCurrency>>;
+ /**
+ * Type guard for whether the API can return token prices for the given chain
+ * ID.
+ *
+ * @param chainId - The chain ID to check.
+ * @returns True if the API supports the chain ID, false otherwise.
+ */
+ validateChainIdSupported(chainId: unknown): chainId is SupportedChainId;
+ /**
+ * Type guard for whether the API can return token prices in the given
+ * currency.
+ *
+ * @param currency - The currency to check. If a string, can be either
+ * lowercase or uppercase.
+ * @returns True if the API supports the currency, false otherwise.
+ */
+ validateCurrencySupported(currency: unknown): currency is SupportedCurrency;
+}
+exports.mapOpenSeaContractV2ToV1 = mapOpenSeaContractV2ToV1;
//# sourceMappingURL=assetsUtil.js.map
+export {};
+//# sourceMappingURL=codefi-v2.d.ts.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts.map b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts.map
new file mode 100644
index 0000000..c8c9c66
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"codefi-v2.d.ts","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAY3C,OAAO,KAAK,EACV,0BAA0B,EAE1B,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AAUzC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,ybA2HvB,CAAC;AAEX;;;GAGG;AACH,aAAK,iBAAiB,GAClB,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,GACrC,SAAS,CAAC,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,6SAkEtB,CAAC;AAEX;;;;GAIG;AACH,aAAK,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAY7D;;;GAGG;AACH,qBAAa,0BACX,YACE,0BAA0B,CAAC,gBAAgB,EAAE,GAAG,EAAE,iBAAiB,CAAC;;IAItE;;;;;;;;;OASG;gBACS,EACV,OAAqC,EACrC,0BAAyE,EACzE,oBAAqC,GACtC,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC1B;IAcN;;;;;;;;;OASG;IACG,gBAAgB,CAAC,EACrB,OAAO,EACP,cAAc,EACd,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,gBAAgB,CAAC;QAC1B,cAAc,EAAE,GAAG,EAAE,CAAC;QACtB,QAAQ,EAAE,iBAAiB,CAAC;KAC7B,GAAG,OAAO,CAAC,yBAAyB,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;IAiD9D;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,gBAAgB;IAKvE;;;;;;;OAOG;IACH,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,iBAAiB;CAO5E"}
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js
new file mode 100644
index 0000000..0bbe39a
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js
@@ -0,0 +1,325 @@
+"use strict";
+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
+ if (kind === "m") throw new TypeError("Private method is not writable");
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
+};
+var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
+};
+var _CodefiTokenPricesServiceV2_tokenPricePolicy;
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.CodefiTokenPricesServiceV2 = exports.SUPPORTED_CHAIN_IDS = exports.SUPPORTED_CURRENCIES = void 0;
+const controller_utils_1 = require("@metamask/controller-utils");
+const utils_1 = require("@metamask/utils");
+const cockatiel_1 = require("cockatiel");
+/**
+ * The list of currencies that can be supplied as the `vsCurrency` parameter to
+ * the `/spot-prices` endpoint, in lowercase form.
+ */
+exports.SUPPORTED_CURRENCIES = [
+ // Bitcoin
+ 'btc',
+ // Ether
+ 'eth',
+ // Litecoin
+ 'ltc',
+ // Bitcoin Cash
+ 'bch',
+ // Binance Coin
+ 'bnb',
+ // EOS
+ 'eos',
+ // XRP
+ 'xrp',
+ // Lumens
+ 'xlm',
+ // Chainlink
+ 'link',
+ // Polkadot
+ 'dot',
+ // Yearn.finance
+ 'yfi',
+ // US Dollar
+ 'usd',
+ // United Arab Emirates Dirham
+ 'aed',
+ // Argentine Peso
+ 'ars',
+ // Australian Dollar
+ 'aud',
+ // Bangladeshi Taka
+ 'bdt',
+ // Bahraini Dinar
+ 'bhd',
+ // Bermudian Dollar
+ 'bmd',
+ // Brazil Real
+ 'brl',
+ // Canadian Dollar
+ 'cad',
+ // Swiss Franc
+ 'chf',
+ // Chilean Peso
+ 'clp',
+ // Chinese Yuan
+ 'cny',
+ // Czech Koruna
+ 'czk',
+ // Danish Krone
+ 'dkk',
+ // Euro
+ 'eur',
+ // British Pound Sterling
+ 'gbp',
+ // Hong Kong Dollar
+ 'hkd',
+ // Hungarian Forint
+ 'huf',
+ // Indonesian Rupiah
+ 'idr',
+ // Israeli New Shekel
+ 'ils',
+ // Indian Rupee
+ 'inr',
+ // Japanese Yen
+ 'jpy',
+ // South Korean Won
+ 'krw',
+ // Kuwaiti Dinar
+ 'kwd',
+ // Sri Lankan Rupee
+ 'lkr',
+ // Burmese Kyat
+ 'mmk',
+ // Mexican Peso
+ 'mxn',
+ // Malaysian Ringgit
+ 'myr',
+ // Nigerian Naira
+ 'ngn',
+ // Norwegian Krone
+ 'nok',
+ // New Zealand Dollar
+ 'nzd',
+ // Philippine Peso
+ 'php',
+ // Pakistani Rupee
+ 'pkr',
+ // Polish Zloty
+ 'pln',
+ // Russian Ruble
+ 'rub',
+ // Saudi Riyal
+ 'sar',
+ // Swedish Krona
+ 'sek',
+ // Singapore Dollar
+ 'sgd',
+ // Thai Baht
+ 'thb',
+ // Turkish Lira
+ 'try',
+ // New Taiwan Dollar
+ 'twd',
+ // Ukrainian hryvnia
+ 'uah',
+ // Venezuelan bolívar fuerte
+ 'vef',
+ // Vietnamese đồng
+ 'vnd',
+ // South African Rand
+ 'zar',
+ // IMF Special Drawing Rights
+ 'xdr',
+ // Silver - Troy Ounce
+ 'xag',
+ // Gold - Troy Ounce
+ 'xau',
+ // Bits
+ 'bits',
+ // Satoshi
+ 'sats',
+];
+/**
+ * The list of chain IDs that can be supplied in the URL for the `/spot-prices`
+ * endpoint, but in decimal form (for consistency with how we represent
+ * chain IDs in other places).
+ */
+exports.SUPPORTED_CHAIN_IDS = [
+ // Ethereum Mainnet
+ '1',
+ // OP Mainnet
+ '10',
+ // Cronos Mainnet
+ '25',
+ // BNB Smart Chain Mainnet
+ '56',
+ // Syscoin Mainnet
+ '57',
+ // OKXChain Mainnet
+ '66',
+ // Hoo Smart Chain
+ '70',
+ // Meter Mainnet
+ '82',
+ // TomoChain
+ '88',
+ // Gnosis
+ '100',
+ // Velas EVM Mainnet
+ '106',
+ // Fuse Mainnet
+ '122',
+ // Huobi ECO Chain Mainnet
+ '128',
+ // Polygon Mainnet
+ '137',
+ // Fantom Opera
+ '250',
+ // Boba Network
+ '288',
+ // KCC Mainnet
+ '321',
+ // zkSync Era Mainnet
+ '328',
+ // Theta Mainnet
+ '361',
+ // Metis Andromeda Mainnet
+ '1088',
+ // Moonbeam
+ '1284',
+ // Moonriver
+ '1285',
+ // Base
+ '8453',
+ // Shiden
+ '336',
+ // Smart Bitcoin Cash
+ '10000',
+ // Arbitrum One
+ '42161',
+ // Celo Mainnet
+ '42220',
+ // Oasis Emerald
+ '42294',
+ // Avalanche C-Chain
+ '43114',
+ // Polis Mainnet
+ '535824',
+ // Aurora Mainnet
+ '1313161554',
+ // Harmony Mainnet Shard 0
+ '1666600000',
+];
+/**
+ * All requests to V2 of the Price API start with this.
+ */
+const BASE_URL = 'https://price-api.metafi.codefi.network/v2';
+const DEFAULT_TOKEN_PRICE_RETRIES = 3;
+// Each update attempt will result (1 + retries) calls if the server is down
+const DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;
+/**
+ * This version of the token prices service uses V2 of the Codefi Price API to
+ * fetch token prices.
+ */
+class CodefiTokenPricesServiceV2 {
+ /**
+ * Construct a Codefi Token Price Service.
+ *
+ * @param options - Constructor options
+ * @param options.retries - Number of retry attempts for each token price update.
+ * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures
+ * allowed before breaking the circuit and pausing further updates.
+ * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks
+ * from too many consecutive failures.
+ */
+ constructor({ retries = DEFAULT_TOKEN_PRICE_RETRIES, maximumConsecutiveFailures = DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = 30 * 60 * 1000, } = {}) {
+ _CodefiTokenPricesServiceV2_tokenPricePolicy.set(this, void 0);
+ // Construct a policy that will retry each update, and halt further updates
+ // for a certain period after too many consecutive failures.
+ const retryPolicy = (0, cockatiel_1.retry)(cockatiel_1.handleAll, {
+ maxAttempts: retries,
+ backoff: new cockatiel_1.ExponentialBackoff(),
+ });
+ const circuitBreakerPolicy = (0, cockatiel_1.circuitBreaker)(cockatiel_1.handleAll, {
+ halfOpenAfter: circuitBreakDuration,
+ breaker: new cockatiel_1.ConsecutiveBreaker(maximumConsecutiveFailures),
+ });
+ __classPrivateFieldSet(this, _CodefiTokenPricesServiceV2_tokenPricePolicy, (0, cockatiel_1.wrap)(retryPolicy, circuitBreakerPolicy), "f");
+ }
+ /**
+ * Retrieves prices in the given currency for the tokens identified by the
+ * given addresses which are expected to live on the given chain.
+ *
+ * @param args - The arguments to function.
+ * @param args.chainId - An EIP-155 chain ID.
+ * @param args.tokenAddresses - Addresses for tokens that live on the chain.
+ * @param args.currency - The desired currency of the token prices.
+ * @returns The prices for the requested tokens.
+ */
+ fetchTokenPrices({ chainId, tokenAddresses, currency, }) {
+ return __awaiter(this, void 0, void 0, function* () {
+ const url = new URL(`${BASE_URL}/chains/${chainId}/spot-prices`);
+ url.searchParams.append('tokenAddresses', tokenAddresses.join(','));
+ url.searchParams.append('vsCurrency', currency);
+ const pricesByCurrencyByTokenAddress = yield __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_tokenPricePolicy, "f").execute(() => (0, controller_utils_1.handleFetch)(url));
+ return tokenAddresses.reduce((obj, tokenAddress) => {
+ var _a;
+ // The Price API lowercases both currency and token addresses, so we have
+ // to keep track of them and make sure we return the original versions.
+ const lowercasedTokenAddress = tokenAddress.toLowerCase();
+ const lowercasedCurrency = currency.toLowerCase();
+ const price = (_a = pricesByCurrencyByTokenAddress[lowercasedTokenAddress]) === null || _a === void 0 ? void 0 : _a[lowercasedCurrency];
+ if (!price) {
+ throw new Error(`Could not find price for "${tokenAddress}" in "${currency}"`);
+ }
+ const tokenPrice = {
+ tokenAddress,
+ value: price,
+ currency,
+ };
+ return Object.assign(Object.assign({}, obj), { [tokenAddress]: tokenPrice });
+ }, {});
+ });
+ }
+ /**
+ * Type guard for whether the API can return token prices for the given chain
+ * ID.
+ *
+ * @param chainId - The chain ID to check.
+ * @returns True if the API supports the chain ID, false otherwise.
+ */
+ validateChainIdSupported(chainId) {
+ const supportedChainIds = exports.SUPPORTED_CHAIN_IDS;
+ return typeof chainId === 'string' && supportedChainIds.includes(chainId);
+ }
+ /**
+ * Type guard for whether the API can return token prices in the given
+ * currency.
+ *
+ * @param currency - The currency to check. If a string, can be either
+ * lowercase or uppercase.
+ * @returns True if the API supports the currency, false otherwise.
+ */
+ validateCurrencySupported(currency) {
+ const supportedCurrencies = exports.SUPPORTED_CURRENCIES;
+ return (typeof currency === 'string' &&
+ supportedCurrencies.includes(currency.toLowerCase()));
+ }
+}
+exports.CodefiTokenPricesServiceV2 = CodefiTokenPricesServiceV2;
+_CodefiTokenPricesServiceV2_tokenPricePolicy = new WeakMap();
+//# sourceMappingURL=codefi-v2.js.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js.map b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js.map
new file mode 100644
index 0000000..02039c6
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"codefi-v2.js","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":"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","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { hexToNumber } from '@metamask/utils';\nimport {\n circuitBreaker,\n ConsecutiveBreaker,\n ExponentialBackoff,\n handleAll,\n type IPolicy,\n retry,\n wrap,\n} from 'cockatiel';\n\nimport type {\n AbstractTokenPricesService,\n TokenPrice,\n TokenPricesByTokenAddress,\n} from './abstract-token-prices-service';\n\n/**\n * The shape of the data that the /spot-prices endpoint returns.\n */\ntype SpotPricesEndpointData<\n TokenAddress extends Hex,\n Currency extends string,\n> = Record<TokenAddress, Record<Currency, number>>;\n\n/**\n * The list of currencies that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint, in lowercase form.\n */\nexport const SUPPORTED_CURRENCIES = [\n // Bitcoin\n 'btc',\n // Ether\n 'eth',\n // Litecoin\n 'ltc',\n // Bitcoin Cash\n 'bch',\n // Binance Coin\n 'bnb',\n // EOS\n 'eos',\n // XRP\n 'xrp',\n // Lumens\n 'xlm',\n // Chainlink\n 'link',\n // Polkadot\n 'dot',\n // Yearn.finance\n 'yfi',\n // US Dollar\n 'usd',\n // United Arab Emirates Dirham\n 'aed',\n // Argentine Peso\n 'ars',\n // Australian Dollar\n 'aud',\n // Bangladeshi Taka\n 'bdt',\n // Bahraini Dinar\n 'bhd',\n // Bermudian Dollar\n 'bmd',\n // Brazil Real\n 'brl',\n // Canadian Dollar\n 'cad',\n // Swiss Franc\n 'chf',\n // Chilean Peso\n 'clp',\n // Chinese Yuan\n 'cny',\n // Czech Koruna\n 'czk',\n // Danish Krone\n 'dkk',\n // Euro\n 'eur',\n // British Pound Sterling\n 'gbp',\n // Hong Kong Dollar\n 'hkd',\n // Hungarian Forint\n 'huf',\n // Indonesian Rupiah\n 'idr',\n // Israeli New Shekel\n 'ils',\n // Indian Rupee\n 'inr',\n // Japanese Yen\n 'jpy',\n // South Korean Won\n 'krw',\n // Kuwaiti Dinar\n 'kwd',\n // Sri Lankan Rupee\n 'lkr',\n // Burmese Kyat\n 'mmk',\n // Mexican Peso\n 'mxn',\n // Malaysian Ringgit\n 'myr',\n // Nigerian Naira\n 'ngn',\n // Norwegian Krone\n 'nok',\n // New Zealand Dollar\n 'nzd',\n // Philippine Peso\n 'php',\n // Pakistani Rupee\n 'pkr',\n // Polish Zloty\n 'pln',\n // Russian Ruble\n 'rub',\n // Saudi Riyal\n 'sar',\n // Swedish Krona\n 'sek',\n // Singapore Dollar\n 'sgd',\n // Thai Baht\n 'thb',\n // Turkish Lira\n 'try',\n // New Taiwan Dollar\n 'twd',\n // Ukrainian hryvnia\n 'uah',\n // Venezuelan bolívar fuerte\n 'vef',\n // Vietnamese đồng\n 'vnd',\n // South African Rand\n 'zar',\n // IMF Special Drawing Rights\n 'xdr',\n // Silver - Troy Ounce\n 'xag',\n // Gold - Troy Ounce\n 'xau',\n // Bits\n 'bits',\n // Satoshi\n 'sats',\n] as const;\n\n/**\n * A currency that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.\n */\ntype SupportedCurrency =\n | (typeof SUPPORTED_CURRENCIES)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES)[number]>;\n\n/**\n * The list of chain IDs that can be supplied in the URL for the `/spot-prices`\n * endpoint, but in hexadecimal form (for consistency with how we represent\n * chain IDs in other places).\n */\nexport const SUPPORTED_CHAIN_IDS = [\n // Ethereum Mainnet\n '0x1',\n // OP Mainnet\n '0xa',\n // Cronos Mainnet\n '0x19',\n // BNB Smart Chain Mainnet\n '0x38',\n // Syscoin Mainnet\n '0x39',\n // OKXChain Mainnet\n '0x42',\n // Hoo Smart Chain\n '0x46',\n // Meter Mainnet\n '0x52',\n // TomoChain\n '0x58',\n // Gnosis\n '0x64',\n // Velas EVM Mainnet\n '0x6a',\n // Fuse Mainnet\n '0x7a',\n // Huobi ECO Chain Mainnet\n '0x80',\n // Polygon Mainnet\n '0x89',\n // Fantom Opera\n '0xfa',\n // Boba Network\n '0x120',\n // KCC Mainnet\n '0x141',\n // zkSync Era Mainnet\n '0x144',\n // Theta Mainnet\n '0x169',\n // Metis Andromeda Mainnet\n '0x440',\n // Moonbeam\n '0x504',\n // Moonriver\n '0x505',\n // Base\n '0x2105',\n // Shiden\n // NOTE: This is the wrong chain ID, this should be 0x150\n '0x2107',\n // Smart Bitcoin Cash\n '0x2710',\n // Arbitrum One\n '0xa4b1',\n // Celo Mainnet\n '0xa4ec',\n // Oasis Emerald\n '0xa516',\n // Avalanche C-Chain\n '0xa86a',\n // Polis Mainnet\n '0x518af',\n // Aurora Mainnet\n '0x4e454152',\n // Harmony Mainnet Shard 0\n '0x63564c40',\n] as const;\n\n/**\n * A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,\n * but in hexadecimal form (for consistency with how we represent chain IDs in\n * other places).\n */\ntype SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];\n\n/**\n * All requests to V2 of the Price API start with this.\n */\nconst BASE_URL = 'https://price-api.metafi.codefi.network/v2';\n\nconst DEFAULT_TOKEN_PRICE_RETRIES = 3;\n// Each update attempt will result (1 + retries) calls if the server is down\nconst DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES =\n (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;\n\n/**\n * This version of the token prices service uses V2 of the Codefi Price API to\n * fetch token prices.\n */\nexport class CodefiTokenPricesServiceV2\n implements\n AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency>\n{\n #tokenPricePolicy: IPolicy;\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param options - Constructor options\n * @param options.retries - Number of retry attempts for each token price update.\n * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures\n * allowed before breaking the circuit and pausing further updates.\n * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks\n * from too many consecutive failures.\n */\n constructor({\n retries = DEFAULT_TOKEN_PRICE_RETRIES,\n maximumConsecutiveFailures = DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = 30 * 60 * 1000,\n }: {\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n } = {}) {\n // Construct a policy that will retry each update, and halt further updates\n // for a certain period after too many consecutive failures.\n const retryPolicy = retry(handleAll, {\n maxAttempts: retries,\n backoff: new ExponentialBackoff(),\n });\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maximumConsecutiveFailures),\n });\n this.#tokenPricePolicy = wrap(retryPolicy, circuitBreakerPolicy);\n }\n\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 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 async fetchTokenPrices({\n chainId,\n tokenAddresses,\n currency,\n }: {\n chainId: SupportedChainId;\n tokenAddresses: Hex[];\n currency: SupportedCurrency;\n }): Promise<TokenPricesByTokenAddress<Hex, SupportedCurrency>> {\n const chainIdAsNumber = hexToNumber(chainId);\n\n const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);\n url.searchParams.append('tokenAddresses', tokenAddresses.join(','));\n url.searchParams.append('vsCurrency', currency);\n\n const pricesByCurrencyByTokenAddress: SpotPricesEndpointData<\n Lowercase<Hex>,\n Lowercase<SupportedCurrency>\n > = await this.#tokenPricePolicy.execute(() => handleFetch(url));\n\n return tokenAddresses.reduce(\n (\n obj: Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>,\n tokenAddress,\n ) => {\n // The Price API lowercases both currency and token addresses, so we have\n // to keep track of them and make sure we return the original versions.\n const lowercasedTokenAddress =\n tokenAddress.toLowerCase() as Lowercase<Hex>;\n const lowercasedCurrency =\n currency.toLowerCase() as Lowercase<SupportedCurrency>;\n\n const price =\n pricesByCurrencyByTokenAddress[lowercasedTokenAddress]?.[\n lowercasedCurrency\n ];\n\n if (!price) {\n throw new Error(\n `Could not find price for \"${tokenAddress}\" in \"${currency}\"`,\n );\n }\n\n const tokenPrice: TokenPrice<Hex, SupportedCurrency> = {\n tokenAddress,\n value: price,\n currency,\n };\n return {\n ...obj,\n [tokenAddress]: tokenPrice,\n };\n },\n {},\n ) as TokenPricesByTokenAddress<Hex, SupportedCurrency>;\n }\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 SupportedChainId {\n const supportedChainIds: readonly string[] = SUPPORTED_CHAIN_IDS;\n return typeof chainId === 'string' && supportedChainIds.includes(chainId);\n }\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. If a string, can be either\n * lowercase or uppercase.\n * @returns True if the API supports the currency, false otherwise.\n */\n validateCurrencySupported(currency: unknown): currency is SupportedCurrency {\n const supportedCurrencies: readonly string[] = SUPPORTED_CURRENCIES;\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n}\n"]}
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.d.ts b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.d.ts
new file mode 100644
index 0000000..785225a
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.d.ts
@@ -0,0 +1,3 @@
+export type { AbstractTokenPricesService } from './abstract-token-prices-service';
+export { CodefiTokenPricesServiceV2 } from './codefi-v2';
+//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.d.ts.map b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.d.ts.map
new file mode 100644
index 0000000..48c1a1c
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/token-prices-service/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC"}
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.js b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.js
new file mode 100644
index 0000000..5d52474
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.js
@@ -0,0 +1,6 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.CodefiTokenPricesServiceV2 = void 0;
+var codefi_v2_1 = require("./codefi-v2");
+Object.defineProperty(exports, "CodefiTokenPricesServiceV2", { enumerable: true, get: function () { return codefi_v2_1.CodefiTokenPricesServiceV2; } });
+//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.js.map b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.js.map
new file mode 100644
index 0000000..2692b27
--- /dev/null
+++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/index.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/token-prices-service/index.ts"],"names":[],"mappings":";;;AACA,yCAAyD;AAAhD,uHAAA,0BAA0B,OAAA","sourcesContent":["export type { AbstractTokenPricesService } from './abstract-token-prices-service';\nexport { CodefiTokenPricesServiceV2 } from './codefi-v2';\n"]}
\ No newline at end of file
You are viewing a condensed version of this merge commit. You can view the full changes here.