Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@exodus/assets

Package Overview
Dependencies
Maintainers
0
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@exodus/assets - npm Package Compare versions

Comparing version 9.1.1 to 9.2.0

48

lib/connect-assets.js

@@ -16,9 +16,13 @@ "use strict";

exports.connectCombinedAssets = connectCombinedAssets;
exports.getListWithTokensLast = void 0;
exports.updateCombinedAsset = updateCombinedAsset;
exports.updateToken = updateToken;
var _minimalisticAssert = _interopRequireDefault(require("minimalistic-assert"));
var _basicUtils = require("@exodus/basic-utils");
var _currency = require("@exodus/currency");
var _asset = require("@exodus/asset");
var _constants = require("./constants");
var _validateAsset = require("./validate-asset");
var _createCombined = require("./create-combined");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const connectProp = (asset, prop, value) => {

@@ -65,3 +69,3 @@ if (asset[prop] === undefined && value !== undefined) asset[prop] = value;

asset.isBuiltIn = !asset.isCustomToken;
if (asset.isCustomToken || ['bcashclaim', 'bgoldclaim', 'bitcoinsvclaim'].includes(asset.name)) {
if (asset.isCustomToken) {
coerceTokenProps(asset, asset.baseAsset);

@@ -101,2 +105,4 @@ }

}
const getListWithTokensLast = assets => Object.values(assets).sort((a, b) => Number(b.baseAssetName === b.name) - Number(a.baseAssetName === a.name));
exports.getListWithTokensLast = getListWithTokensLast;
function coerceAssetProps(asset, baseAsset) {

@@ -122,3 +128,3 @@ return coerceTokenProps(asset, baseAsset);

}));
Object.values(_assets).forEach(asset => defineAssetProps({
getListWithTokensLast(_assets).forEach(asset => defineAssetProps({
assets: _assets,

@@ -150,9 +156,9 @@ asset

baseAssetName,
info = {}
info = Object.create(null)
} = assetDef;
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name);
(0, _validateAsset.assert)(name && !assets[name], `token ${name} already in registry`);
(0, _minimalisticAssert.default)(name && !assets[name], `token ${name} already in registry`);
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(baseAssetName);
(0, _validateAsset.assert)(baseAssetName && assets[baseAssetName], `base asset ${baseAssetName} not found for token ${name}`);
(0, _validateAsset.assert)(name !== baseAssetName, `token ${name} must be distinct from base asset`);
(0, _minimalisticAssert.default)(baseAssetName && assets[baseAssetName], `base asset ${baseAssetName} not found for token ${name}`);
(0, _minimalisticAssert.default)(name !== baseAssetName, `token ${name} must be distinct from base asset`);
const asset = {

@@ -163,3 +169,3 @@ ...assetDef,

};
(0, _validateAsset.validateTokenDef)(asset);
(0, _asset.validateTokenDef)(asset);
defineAssetProps({

@@ -177,5 +183,5 @@ assets,

(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name);
(0, _validateAsset.assert)(name && assets[name], `token ${name} not in the registry`);
(0, _validateAsset.assert)(name !== assets[name].baseAssetName, `token ${name} must be distinct from base asset`);
(0, _validateAsset.assert)(updateableProps, 'expected `updateableProps`');
(0, _minimalisticAssert.default)(name && assets[name], `token ${name} not in the registry`);
(0, _minimalisticAssert.default)(name !== assets[name].baseAssetName, `token ${name} must be distinct from base asset`);
(0, _minimalisticAssert.default)(updateableProps, 'expected `updateableProps`');
const asset = {

@@ -185,3 +191,3 @@ ...assets[name],

};
(0, _validateAsset.validateTokenDef)(asset);
(0, _asset.validateTokenDef)(asset);
assets[name] = asset;

@@ -193,5 +199,5 @@ return asset;

name,
info = {}
info = Object.create(null)
} = baseAssetDef;
(0, _validateAsset.assert)(!assets[name], `asset ${name} already exists`);
(0, _minimalisticAssert.default)(!assets[name], `asset ${name} already exists`);
const asset = {

@@ -202,3 +208,3 @@ ...baseAssetDef,

};
(0, _validateAsset.validateBaseAssetDef)(asset);
(0, _asset.validateBaseAssetDef)(asset);
try {

@@ -222,5 +228,5 @@ assets[name] = asset;

(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name);
(0, _validateAsset.assert)(name && !assets[name], `combined asset ${name} already in registry`);
(0, _minimalisticAssert.default)(name && !assets[name], `combined asset ${name} already in registry`);
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(baseAssetName);
(0, _validateAsset.assert)(baseAssetName && name === baseAssetName, `combined asset ${name} invalid`);
(0, _minimalisticAssert.default)(baseAssetName && name === baseAssetName, `combined asset ${name} invalid`);
const asset = (0, _createCombined.createCombined)(assetDef, assets);

@@ -242,3 +248,3 @@ try {

newMemberAsset
} = {}) {
} = Object.create(null)) {
const {

@@ -248,7 +254,7 @@ name,

} = combinedAsset;
(0, _validateAsset.assert)(isCombined, `asset ${name} must be a combined asset`);
(0, _minimalisticAssert.default)(isCombined, `asset ${name} must be a combined asset`);
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name);
(0, _validateAsset.assert)(assets[name], `combined asset ${name} does not exist`);
(0, _validateAsset.assert)(assets[newMemberAsset.name], `asset ${newMemberAsset.name} does not exist`);
(0, _validateAsset.assert)(!newMemberAsset.isCombined, `asset ${newMemberAsset.name} must not be a combined asset`);
(0, _minimalisticAssert.default)(assets[name], `combined asset ${name} does not exist`);
(0, _minimalisticAssert.default)(assets[newMemberAsset.name], `asset ${newMemberAsset.name} does not exist`);
(0, _minimalisticAssert.default)(!newMemberAsset.isCombined, `asset ${newMemberAsset.name} must not be a combined asset`);
const assetDef = (0, _basicUtils.omit)(combinedAsset, ['baseAsset', 'feeAsset', 'combinedAssets']);

@@ -255,0 +261,0 @@ assetDef.combinedAssetNames.push(newMemberAsset.name);

@@ -7,3 +7,3 @@ "use strict";

exports.createCombined = createCombined;
var _lodash = require("lodash");
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
var _minimalisticAssert = _interopRequireDefault(require("minimalistic-assert"));

@@ -15,4 +15,4 @@ var _currency = require("@exodus/currency");

return !assetDef[key] && primaryAssetDef[key] ? {
[key]: (0, _lodash.cloneDeep)(primaryAssetDef[key])
} : {};
[key]: (0, _cloneDeep2.default)(primaryAssetDef[key])
} : Object.create(null);
};

@@ -30,7 +30,7 @@ function createCombined(assetDef, assets) {

(0, _minimalisticAssert.default)(name && ticker && displayName && displayTicker && assetType && units && combinedAssetNames, `mandatory filed missing for combined asset ${JSON.stringify(assetDef)}`);
const cloned = (0, _lodash.cloneDeep)(assetDef);
const cloned = (0, _cloneDeep2.default)(assetDef);
return {
...cloned,
baseAssetName: name,
blockExplorer: {},
blockExplorer: Object.create(null),
currency: _currency.UnitType.create(units),

@@ -37,0 +37,0 @@ displayNetworkName: cloned.displayNetworkName || displayName,

@@ -105,3 +105,3 @@ "use strict";

get: function () {
return _validateAsset.validateBaseAssetDef;
return _asset.validateBaseAssetDef;
}

@@ -118,3 +118,3 @@ });

get: function () {
return _validateAsset.validateCombinedAssetDef;
return _asset.validateCombinedAssetDef;
}

@@ -131,3 +131,3 @@ });

get: function () {
return _validateAsset.validateTokenDef;
return _asset.validateTokenDef;
}

@@ -137,2 +137,3 @@ });

var _validateAsset = require("./validate-asset");
var _asset = require("@exodus/asset");
var _constants = require("./constants");

@@ -139,0 +140,0 @@ var _createCombined = require("./create-combined");

@@ -6,17 +6,13 @@ "use strict";

});
exports.assert = assert;
exports.assertNotAnObjectPrototypeProperty = void 0;
exports.validateAsset = validateAsset;
exports.validateBaseAsset = validateBaseAsset;
exports.validateBaseAssetDef = validateBaseAssetDef;
exports.validateCombinedAsset = validateCombinedAsset;
exports.validateCombinedAssetDef = validateCombinedAssetDef;
exports.validateToken = validateToken;
exports.validateTokenDef = validateTokenDef;
var _lodash = require("lodash");
const assetNameRe = /^[\d_a-z]+$/;
const tickerRe = /^\w+$/;
function assert(condition, message) {
if (!condition) throw new Error(message);
}
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
var _isString2 = _interopRequireDefault(require("lodash/isString"));
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
var _minimalisticAssert = _interopRequireDefault(require("minimalistic-assert"));
var _asset = require("@exodus/asset");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function validateAsset(asset) {

@@ -26,59 +22,25 @@ asset.baseAssetName && asset.name !== asset.baseAssetName ? validateToken(asset) : asset.isCombined === true ? validateCombinedAsset(asset) : validateBaseAsset(asset);

function _validateCommon(asset) {
assert((0, _lodash.isObject)(asset.baseAsset), `base asset missing for ${asset.name}`);
assert((0, _lodash.isObject)(asset.feeAsset), `fee asset missing for ${asset.name}`);
assert((0, _lodash.isObject)(asset.currency), `currency missing for ${asset.name}`);
assert(asset.properTicker && (0, _lodash.isString)(asset.properTicker), `properTicker asset missing for ${asset.name}`);
assert(asset.displayNetworkName && (0, _lodash.isString)(asset.displayNetworkName), `displayNetworkName missing for ${asset.name}`);
assert(asset.displayNetworkTicker && (0, _lodash.isString)(asset.displayNetworkTicker), `displayNetworkTicker missing for ${asset.name}`);
(0, _minimalisticAssert.default)((0, _isObject2.default)(asset.baseAsset), `base asset missing for ${asset.name}`);
(0, _minimalisticAssert.default)((0, _isObject2.default)(asset.feeAsset), `fee asset missing for ${asset.name}`);
(0, _minimalisticAssert.default)((0, _isObject2.default)(asset.currency), `currency missing for ${asset.name}`);
(0, _minimalisticAssert.default)(asset.properTicker && (0, _isString2.default)(asset.properTicker), `properTicker asset missing for ${asset.name}`);
(0, _minimalisticAssert.default)(asset.displayNetworkName && (0, _isString2.default)(asset.displayNetworkName), `displayNetworkName missing for ${asset.name}`);
(0, _minimalisticAssert.default)(asset.displayNetworkTicker && (0, _isString2.default)(asset.displayNetworkTicker), `displayNetworkTicker missing for ${asset.name}`);
}
function validateToken(asset) {
validateTokenDef(asset);
(0, _asset.validateTokenDef)(asset);
_validateCommon(asset);
}
function validateBaseAsset(asset) {
validateBaseAssetDef(asset);
(0, _asset.validateBaseAssetDef)(asset);
_validateCommon(asset);
}
function validateCombinedAsset(asset) {
validateCombinedAssetDef(asset);
(0, _asset.validateCombinedAssetDef)(asset);
_validateCommon(asset);
assert((0, _lodash.isArray)(asset.combinedAssets), `combined assets missing for ${asset.name}`);
(0, _minimalisticAssert.default)((0, _isArray2.default)(asset.combinedAssets), `combined assets missing for ${asset.name}`);
}
function _validateCommonDef(asset) {
const {
name,
properName,
ticker,
units,
assetType,
info
} = asset;
assert(name && (0, _lodash.isString)(name) && name.match(assetNameRe), 'asset name required');
assert(properName && (0, _lodash.isString)(properName), `asset proper (display) name required for ${name}`);
assert(ticker && (0, _lodash.isString)(ticker) && ticker.match(tickerRe), `ticker name required for ${name}`);
assert((0, _lodash.isObject)(units) && !(0, _lodash.isEmpty)(units), `units required for ${name}`);
assert(assetType && (0, _lodash.isString)(assetType), `asset type required for ${name}`);
assert((0, _lodash.isFunction)(asset.toString), `isString required for ${name}`);
assert(asset.toString() === name, `isString must return ${name}`);
assert((0, _lodash.isObject)(info), `info missing for ${name}`);
}
function validateBaseAssetDef(asset) {
_validateCommonDef(asset);
assert(!asset.baseAssetName || asset.name === asset.baseAssetName, `base asset name ${asset.baseAssetName} is not valid for ${asset.name}`);
assert(!asset.isCombined, `combined asset is not supported for base asset ${asset.name}`);
assert(asset.blockExplorer, `block explorer missing for ${asset.name}`);
}
function validateTokenDef(asset) {
_validateCommonDef(asset);
assert(asset.baseAssetName && asset.name !== asset.baseAssetName, `base asset name ${asset.baseAssetName} is not valid for token ${asset.name}`);
assert(!asset.isCombined, `combined asset is not supported for token ${asset.name}`);
}
function validateCombinedAssetDef(asset) {
_validateCommonDef(asset);
assert(asset.isCombined, `isCombined missing for ${asset.name}`);
assert((0, _lodash.isArray)(asset.combinedAssetNames) && asset.combinedAssetNames.length > 0, `at least one combined asset name expected for ${asset.name}`);
}
const assertNotAnObjectPrototypeProperty = name => {
assert(!{}[name], `property ${name} conflicts with object prototype`);
(0, _minimalisticAssert.default)(!{}[name], `property ${name} conflicts with object prototype`);
};
exports.assertNotAnObjectPrototypeProperty = assertNotAnObjectPrototypeProperty;
{
"name": "@exodus/assets",
"version": "9.1.1",
"version": "9.2.0",
"description": "Exodus assets",

@@ -13,2 +13,3 @@ "main": "lib/index.js",

"dependencies": {
"@exodus/asset": "^1.1.0",
"@exodus/basic-utils": "^2.1.1",

@@ -21,4 +22,3 @@ "@exodus/currency": "^2.2.0",

"@exodus/assets-base": "^8.1.14",
"@exodus/combined-assets-meta": "^1.2.9",
"jest": "^29.3.1"
"@exodus/combined-assets-meta": "^2.0.0"
},

@@ -28,4 +28,4 @@ "scripts": {

"build:clean": "rm -rf lib",
"test": "jest",
"lint": "eslint . --ignore-path ../../.gitignore",
"test": "run -T jest",
"lint": "run -T eslint . --ignore-path ../../.gitignore",
"lint:fix": "yarn lint --fix"

@@ -40,3 +40,3 @@ },

},
"gitHead": "78106c5f1be546353342771fdfcb1a9b997ac828"
"gitHead": "5eb05bdbf231470db1eea375b1b0a2469cc774ab"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc