UNPKG

@ixily/activ

Version:

Alpha Capture Trade Idea Verification. Blockchain ownership proven trade ideas and strategies.

1,461 lines (1,306 loc) 1.3 MB
/******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 1834: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.LIT_ACTIONS_ETH_ADDRESS = void 0; exports.LIT_ACTIONS_ETH_ADDRESS = { ALPACA_V2: '0x1e07793aF5a9A4eD3F006Bfa90e916C7b1f0e1B9', BINANCE_V2: '0x62555428470948d1861D91701b6C54f53501076a', COINMARKETCAP_V2: '0xabeB4EEaFa61dd7600E1091BbAc363903355455e', CRYPTOCOMPARE_V2: '0xf7c5c7a2Beb1669638F238Ef40cE5C8d41d67D3B', IEX_V2: '0x26EF08558d4a9c2963825c0dbD924d545515d555', IG_V2: '0xe24698d197107cFF37E991e471655Cb3be05Ed8E', TRADESTATION_V2: '0x574e11FF32cb17fC8bD14B9C91a699e44a57525C', }; //# sourceMappingURL=lit-actions-eth-address.js.map /***/ }), /***/ 3095: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.PRICING_PROVIDER = void 0; exports.PRICING_PROVIDER = [ 'Binance', 'CryptoCompare', 'IEX', 'IG Group', 'Alpaca', 'Tradestation', 'CoinMarketCap', ]; //# sourceMappingURL=pricing-providers.js.map /***/ }), /***/ 4407: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", ({ value: true })); __exportStar(__webpack_require__(1834), exports); __exportStar(__webpack_require__(3095), exports); //# sourceMappingURL=index.js.map /***/ }), /***/ 1449: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.CONTRACT_TOOLS = exports.CONTRACT_INTERFACES = exports.CONTRACT_CONSTANTS = void 0; exports.CONTRACT_CONSTANTS = __importStar(__webpack_require__(4407)); exports.CONTRACT_INTERFACES = __importStar(__webpack_require__(2114)); exports.CONTRACT_TOOLS = __importStar(__webpack_require__(6557)); //# sourceMappingURL=index.js.map /***/ }), /***/ 9638: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=hashed-signed-message.i.js.map /***/ }), /***/ 1052: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=pricing-provider.i.js.map /***/ }), /***/ 2165: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=provider-request.i.js.map /***/ }), /***/ 7217: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=rule-valid-result.i.js.map /***/ }), /***/ 1625: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=strategy-state.i.js.map /***/ }), /***/ 8595: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-access.i.js.map /***/ }), /***/ 5406: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-content.i.js.map /***/ }), /***/ 2219: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-creator.i.js.map /***/ }), /***/ 5138: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-idea.i.js.map /***/ }), /***/ 6570: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-image.i.js.map /***/ }), /***/ 5451: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-kind.i.js.map /***/ }), /***/ 7906: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-pricing-credentials.i.js.map /***/ }), /***/ 2753: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-pricing.i.js.map /***/ }), /***/ 9413: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-strategy-summary-calc.i.js.map /***/ }), /***/ 712: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea-strategy.i.js.map /***/ }), /***/ 4366: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=trade-idea.i.js.map /***/ }), /***/ 8110: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=valid-price.i.js.map /***/ }), /***/ 2114: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", ({ value: true })); __exportStar(__webpack_require__(9638), exports); __exportStar(__webpack_require__(1052), exports); __exportStar(__webpack_require__(2165), exports); __exportStar(__webpack_require__(7217), exports); __exportStar(__webpack_require__(1625), exports); __exportStar(__webpack_require__(8595), exports); __exportStar(__webpack_require__(5406), exports); __exportStar(__webpack_require__(2219), exports); __exportStar(__webpack_require__(5138), exports); __exportStar(__webpack_require__(6570), exports); __exportStar(__webpack_require__(5451), exports); __exportStar(__webpack_require__(7906), exports); __exportStar(__webpack_require__(2753), exports); __exportStar(__webpack_require__(9413), exports); __exportStar(__webpack_require__(712), exports); __exportStar(__webpack_require__(4366), exports); __exportStar(__webpack_require__(8110), exports); __exportStar(__webpack_require__(9489), exports); __exportStar(__webpack_require__(9724), exports); __exportStar(__webpack_require__(2724), exports); __exportStar(__webpack_require__(5261), exports); __exportStar(__webpack_require__(6660), exports); __exportStar(__webpack_require__(3572), exports); __exportStar(__webpack_require__(7350), exports); __exportStar(__webpack_require__(7887), exports); //# sourceMappingURL=index.js.map /***/ }), /***/ 9489: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=adjust-idea-request.i.js.map /***/ }), /***/ 9724: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=close-idea-request.i.js.map /***/ }), /***/ 2724: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=create-idea-content-request.i.js.map /***/ }), /***/ 5261: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=create-idea-creator-request.i.js.map /***/ }), /***/ 6660: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=create-idea-idea-request.i.js.map /***/ }), /***/ 3572: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=create-idea-request.i.js.map /***/ }), /***/ 7350: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=create-idea-strategy-request.i.js.map /***/ }), /***/ 7887: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); //# sourceMappingURL=update-idea-request.i.js.map /***/ }), /***/ 2199: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.deterministicEvenlyMixedArray = exports.hashJsonStringPreSign = exports.deterministicStringify = void 0; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THIS CODE MUST MATCH LIT ACTIONS CODE CAUTION WHEN EDITING, YOU MUST REPLACE THE LIT ACTIONS CODE IF DO SO. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ // Deterministic JSON const jsonStringify = JSON.stringify; const isArray = Array.isArray || function (x) { return {}.toString.call(x) === '[object Array]'; }; const objectKeys = Object.keys || function (obj) { var has = Object.prototype.hasOwnProperty || function () { return true; }; var keys = []; for (var key in obj) { if (has.call(obj, key)) { keys.push(key); } } return keys; }; const deterministicStringify = function (obj, opts) { if (!opts) { opts = {}; } if (typeof opts === 'function') { opts = { cmp: opts }; } var space = opts.space || ''; if (typeof space === 'number') { space = Array(space + 1).join(' '); } var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false; var replacer = opts.replacer || function (key, value) { return value; }; var cmpOpt = opts.cmp; var cmp = cmpOpt && function (node) { return function (a, b) { return cmpOpt({ key: a, value: node[a] }, { key: b, value: node[b] }); }; }; var seen = []; return (function stringify(parent, key, node, level) { var indent = space ? '\n' + new Array(level + 1).join(space) : ''; var colonSeparator = space ? ': ' : ':'; if (node && node.toJSON && typeof node.toJSON === 'function') { node = node.toJSON(); } node = replacer.call(parent, key, node); if (node === undefined) { return; } if (typeof node !== 'object' || node === null) { return jsonStringify(node); } if (isArray(node)) { var out = []; for (var i = 0; i < node.length; i++) { var item = stringify(node, i, node[i], level + 1) || jsonStringify(null); out.push(indent + space + item); } return '[' + out.join(',') + indent + ']'; } if (seen.indexOf(node) !== -1) { if (cycles) { return jsonStringify('__cycle__'); } throw new TypeError('Converting circular structure to JSON'); } else { seen.push(node); } var keys = objectKeys(node).sort(cmp && cmp(node)); var out = []; for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = stringify(node, key, node[key], level + 1); if (!value) { continue; } var keyValue = jsonStringify(key) + colonSeparator + value; out.push(indent + space + keyValue); } seen.splice(seen.indexOf(node), 1); return '{' + out.join(',') + indent + '}'; })({ '': obj }, '', obj, 0); }; exports.deterministicStringify = deterministicStringify; /** * Returns a hash code from a string * Pre signing hash applicable to json strings objects */ const hashJsonStringPreSign = (str) => { let hash = 0; for (let i = 0, len = str.length; i < len; i++) { let chr = str.charCodeAt(i); hash = (hash << 5) - hash + chr; hash |= 0; // Convert to 32bit integer } const strPreHash = '' + hash; return strPreHash; }; exports.hashJsonStringPreSign = hashJsonStringPreSign; /** * * Receives an amount of arrays with some length each * and returns an evenly mixed array with all the elements of the input arrays * with no repetition or missing element in a deterministic way */ const deterministicEvenlyMixedArray = (arrs) => { const resultEvenlyArray = []; const arrsLength = arrs.length; const arrsLengths = arrs.map((arr) => arr.length); const maxArrLength = Math.max(...arrsLengths); for (let i = 0; i < maxArrLength; i++) { for (let j = 0; j < arrsLength; j++) { const arr = arrs[j]; const element = arr[i]; if (element !== undefined) { resultEvenlyArray.push(element); } } } return resultEvenlyArray; }; exports.deterministicEvenlyMixedArray = deterministicEvenlyMixedArray; //# sourceMappingURL=deterministic.tools.js.map /***/ }), /***/ 8937: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.validatePricingSignature = void 0; const CryptoJS = __importStar(__webpack_require__(1396)); const ethers_1 = __webpack_require__(5146); const __1 = __webpack_require__(6557); const __2 = __webpack_require__(1449); const MAXIMUM_TIMESTAMP_DISTANCE = 400; // 200 ms const MAXIMUM_PRICE_DISTANCE = 0.04; // 4% const splitSignature = (signature) => { const r = signature.slice(0, 66); const s = '0x' + signature.slice(66, 130); const v = parseInt(signature.slice(130, 132), 16); return { r, s, v }; }; /* * Uses crypto-js to decrypt the price part * response is the encrypted price part as string * key is the key part as string * cryptography used function PBKDF2 with SHA-256 * response is concatenation of, in order: salt, iv and ciphertext. */ const decryptPricePart = (response, password) => { const encrypted = CryptoJS.enc.Base64.parse(response); const salt_len = 16; const iv_len = 16; const salt = CryptoJS.lib.WordArray.create(encrypted.words.slice(0, salt_len / 4)); const iv = CryptoJS.lib.WordArray.create(encrypted.words.slice(0 + salt_len / 4, (salt_len + iv_len) / 4)); const key = CryptoJS.PBKDF2(password, salt, { keySize: 256 / 32, iterations: 10000, hasher: CryptoJS.algo.SHA256, }); const decrypted = CryptoJS.AES.decrypt(CryptoJS.lib.WordArray.create(encrypted.words.slice((salt_len + iv_len) / 4)).toString(CryptoJS.enc.Base64), key, { iv: iv }); return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8)); }; const testForInvalidNoFetchNodes = (priceParts, keys) => { for (const pricePartIndex in priceParts) { const pricePart = priceParts[pricePartIndex]; // validate the skipped parts if (pricePart.noFetch === true) { const skipped = pricePart; if (skipped.ckWd === undefined) { throw new Error('TradeIdeaPricingValidationError: noFetch ckWd undefined'); } else { if (skipped.ckWd !== keys[pricePartIndex][0]) { throw new Error('TradeIdeaPricingValidationError: noFetch ckWd does not match'); } } } } }; const testForDealtErrors = (priceParts) => { let listOfKnownErrors = []; let atLeastOneUnknownError = undefined; for (const pricePartIndex in priceParts) { const pricePart = priceParts[pricePartIndex]; // validate the skipped parts if (pricePart.fetchError === true) { const err = pricePart; if (err.unknownError !== undefined) { atLeastOneUnknownError = err.unknownError; } else { if (err.knownError === undefined) { throw new Error('TradeIdeaPricingValidationError: fetchError knownError undefined when not expected'); } if (listOfKnownErrors.find((one) => one === err.knownError) === undefined) { listOfKnownErrors.push(err.knownError); } } } } if (atLeastOneUnknownError !== undefined) { const pricingError = { fetchError: true, unknownError: atLeastOneUnknownError, }; return pricingError; } else { if (listOfKnownErrors.length === 0) { return undefined; } else if (listOfKnownErrors.length === 1) { const pricingError = { fetchError: true, knownError: listOfKnownErrors[0], }; return pricingError; } else { const pricingError = { fetchError: true, unknownError: listOfKnownErrors.join(', '), }; return pricingError; } } }; const restorePricePartsFromKeys = (responses, keys) => { const priceParts = []; for (let i = 0; i < responses.length; i++) { const response = responses[i]; const key = keys[i]; const pricePart = decryptPricePart(response, key[1]); // log.dev('pricePart') // log.dev(pricePart) priceParts.push(pricePart); } return priceParts; }; const getValidPriceFromPartsAndKeys = (priceParts, keys) => { // console.log('priceParts') // console.log(priceParts) // console.log('keys') // console.log(keys) testForInvalidNoFetchNodes(priceParts, keys); const pricingError = testForDealtErrors(priceParts); // console.log('pricingError') // console.log(pricingError) if (pricingError !== undefined) { return pricingError; } let provider; // required let symbol; // required let company; const globalPrices = []; // required let globalPrice = 0; // required let asks = undefined; let ask = undefined; let bids = undefined; let bid = undefined; const timestamps = []; // required let timestamp = 0; // required let fromProxy = undefined; for (const pricePartIndex in priceParts) { const pricePart = priceParts[pricePartIndex]; if (!(pricePart.noFetch === true)) { const _price = pricePart; // validate provider if (_price.provider === undefined) { throw new Error('TradeIdeaPricingValidationError: provider undefined'); } if (typeof _price.provider !== 'string') { throw new Error('TradeIdeaPricingValidationError: provider not string'); } if (provider === undefined) { provider = _price.provider; } else { if (provider !== _price.provider) { throw new Error('TradeIdeaPricingValidationError: provider does not match'); } } // validate symbol if (_price.symbol === undefined) { throw new Error('TradeIdeaPricingValidationError: symbol undefined'); } if (typeof _price.symbol !== 'string') { throw new Error('TradeIdeaPricingValidationError: symbol not string'); } if (symbol === undefined) { symbol = _price.symbol; } else { if (symbol !== _price.symbol) { throw new Error('TradeIdeaPricingValidationError: symbol does not match'); } } // validate company if (_price.company !== undefined) { if (typeof _price.company !== 'string') { throw new Error('TradeIdeaPricingValidationError: company not string'); } if (company === undefined) { company = _price.company; } else { if (company !== _price.company) { throw new Error('TradeIdeaPricingValidationError: company does not match'); } } } else { if (company !== undefined) { throw new Error('TradeIdeaPricingValidationError: company does not match'); } } // validate globalPrice if (_price.globalPrice === undefined) { throw new Error('TradeIdeaPricingValidationError: globalPrice undefined'); } if (typeof _price.globalPrice !== 'number') { throw new Error('TradeIdeaPricingValidationError: globalPrice not number'); } globalPrices.push(_price.globalPrice); // validate ask if (_price.ask !== undefined) { if (typeof _price.ask !== 'number') { throw new Error('TradeIdeaPricingValidationError: ask not number'); } if (asks === undefined) { asks = []; } asks.push(_price.ask); } // validate bid if (_price.bid !== undefined) { if (typeof _price.bid !== 'number') { throw new Error('TradeIdeaPricingValidationError: bid not number'); } if (bids === undefined) { bids = []; } bids.push(_price.bid); } // validate timestamp if (_price.timestamp === undefined) { throw new Error('TradeIdeaPricingValidationError: timestamp undefined'); } if (typeof _price.timestamp !== 'number') { throw new Error('TradeIdeaPricingValidationError: timestamp not number'); } timestamps.push(_price.timestamp); // validate origin if (_price.fromProxy !== undefined) { if (fromProxy === undefined) { fromProxy = _price.fromProxy; } else { if (fromProxy !== _price.fromProxy) { throw new Error('TradeIdeaPricingValidationError: fromProxy does not match'); } } } } } // calculate globalPrice // console.log('globalPrices') // console.log(globalPrices) let maxDecimalsGlobalPrice = 0; for (const _globalPrice of globalPrices) { const preDecimals = _globalPrice.toString().split('.'); const decimals = preDecimals.length > 1 ? preDecimals[1].length : 0; if (decimals > maxDecimalsGlobalPrice) { maxDecimalsGlobalPrice = decimals; } globalPrice += _globalPrice; } globalPrice = globalPrice / globalPrices.length; // restore globalPrice to its maximum decimals globalPrice = parseFloat(globalPrice.toFixed(maxDecimalsGlobalPrice)); // console.log('globalPrice') // console.log(globalPrice) // validate that globalPrices are not too far apart in a distance of constant // MAXIMUM_PRICE_DISTANCE, in percentage difference from average for (const _globalPrice of globalPrices) { const difference = Math.abs(_globalPrice - globalPrice); const percentageDifference = difference / globalPrice; if (percentageDifference > MAXIMUM_PRICE_DISTANCE) { throw new Error('TradeIdeaPricingValidationError: globalPrice too far apart'); } } // calculate average timestamp for (const _timestamp of timestamps) { timestamp += _timestamp; } timestamp = Math.floor(timestamp / timestamps.length); // validate that timestamps are not too far apart in a distance of constant // MAXIMUM_TIMESTAMP_DISTANCE, in milliseconds for (const _timestamp of timestamps) { if (Math.abs(_timestamp - timestamp) > MAXIMUM_TIMESTAMP_DISTANCE) { throw new Error('TradeIdeaPricingValidationError: timestamp too far apart'); } } // if applicable, calculate average ask and bid if (asks !== undefined) { ask = 0; let maxDecimalsAsk = 0; for (const _ask of asks) { const preDecimals = _ask.toString().split('.'); const decimals = preDecimals.length > 1 ? preDecimals[1].length : 0; if (decimals > maxDecimalsAsk) { maxDecimalsAsk = decimals; } ask += _ask; } ask = ask / asks.length; ask = parseFloat(ask.toFixed(maxDecimalsAsk)); // validate that ask prices are not too far apart in a distance of constant // MAXIMUM_PRICE_DISTANCE, in percentage difference from average for (const _ask of asks) { const difference = Math.abs(_ask - ask); const percentageDifference = difference / ask; if (percentageDifference > MAXIMUM_PRICE_DISTANCE) { throw new Error('TradeIdeaPricingValidationError: ask too far apart'); } } } if (bids !== undefined) { bid = 0; let maxDecimalsBid = 0; for (const _bid of bids) { const preDecimals = _bid.toString().split('.'); const decimals = preDecimals.length > 1 ? preDecimals[1].length : 0; if (decimals > maxDecimalsBid) { maxDecimalsBid = decimals; } bid += _bid; } bid = bid / bids.length; bid = parseFloat(bid.toFixed(maxDecimalsBid)); // validate that bid prices are not too far apart in a distance of constant // MAXIMUM_PRICE_DISTANCE, in percentage difference from average for (const _bid of bids) { const difference = Math.abs(_bid - bid); const percentageDifference = difference / bid; if (percentageDifference > MAXIMUM_PRICE_DISTANCE) { throw new Error('TradeIdeaPricingValidationError: bid too far apart'); } } } if (provider === undefined) { throw new Error('TradeIdeaPricingValidationError: provider undefined'); } if (symbol === undefined) { throw new Error('TradeIdeaPricingValidationError: symbol undefined'); } if (timestamp === 0) { throw new Error('TradeIdeaPricingValidationError: timestamp undefined'); } if (globalPrice === 0) { throw new Error('TradeIdeaPricingValidationError: globalPrice undefined'); } return { provider: provider, symbol: symbol, company, globalPrice, ask, bid, fromProxy, timestamp, }; }; const hashString = (valueStr) => { return ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.toUtf8Bytes(valueStr)); }; const getHashedMessage = (originalMessage) => { const hashedMessage = hashString(originalMessage); return { originalMessage, hashedMessage, }; }; const validateHashedSignedMessage = async (hashedSignedMessage, expectedAddress) => { const probeHashed = getHashedMessage(hashedSignedMessage.originalMessage); if (probeHashed.originalMessage !== hashedSignedMessage.originalMessage) { throw new Error('The hashed message does not match original message'); } const signerAddr = await ethers_1.ethers.utils.verifyMessage(hashedSignedMessage.hashedMessage, hashedSignedMessage.signature); if (expectedAddress !== undefined) { if (signerAddr !== expectedAddress) { throw new Error(`Signature address mismatch. Expected ${expectedAddress}, got ${signerAddr}`); } } return signerAddr; }; const checkIfPriceSignedResponseIsValid = async (pricingDetails, cachedStrategyState, mockValidation = false) => { if (mockValidation) { return { valid: true, price: pricingDetails, }; } const hashedMessage = getHashedMessage((0, __1.deterministicStringify)(pricingDetails.response)); // log.dev('pricingDetails.signature.signature:') // log.dev(pricingDetails.signature.signature) const signature = pricingDetails.signature.signature; const splitedSignature = splitSignature(signature); const hashedSignedMessage = { ...hashedMessage, signature, ...splitedSignature, }; if (pricingDetails.price === undefined) { return { valid: false, price: pricingDetails, }; } let expectedAddress = undefined; if (pricingDetails.price.provider === 'Binance') { expectedAddress = __2.CONTRACT_CONSTANTS.LIT_ACTIONS_ETH_ADDRESS.BINANCE_V2; } else if (pricingDetails.price.provider === 'IEX') { expectedAddress = __2.CONTRACT_CONSTANTS.LIT_ACTIONS_ETH_ADDRESS.IEX_V2; } else if (pricingDetails.price.provider === 'IG Group') { expectedAddress = __2.CONTRACT_CONSTANTS.LIT_ACTIONS_ETH_ADDRESS.IG_V2; } else if (pricingDetails.price.provider === 'Alpaca') { expectedAddress = __2.CONTRACT_CONSTANTS.LIT_ACTIONS_ETH_ADDRESS.ALPACA_V2; } else if (pricingDetails.price.provider === 'Tradestation') { expectedAddress = __2.CONTRACT_CONSTANTS.LIT_ACTIONS_ETH_ADDRESS.TRADESTATION_V2; } else if (pricingDetails.price.provider === 'CoinMarketCap') { expectedAddress = __2.CONTRACT_CONSTANTS.LIT_ACTIONS_ETH_ADDRESS.COINMARKETCAP_V2; } else if (pricingDetails.price.provider === 'CryptoCompare') { expectedAddress = __2.CONTRACT_CONSTANTS.LIT_ACTIONS_ETH_ADDRESS.CRYPTOCOMPARE_V2; } else { throw new Error('TradeIdeaPricingValidationError: Invalid pricing provider'); } const verification = await validateHashedSignedMessage(hashedSignedMessage); // console.log('verification:', verification) // we let off while not debugged if (verification !== expectedAddress) { return { valid: false, price: pricingDetails, }; } else { return { valid: true, price: pricingDetails, }; } }; const validatePricingSignature = async (ideaIdea, cachedStrategyState, mockValidation = false) => { const pricingDetails = ideaIdea.priceInfo; // console.log('pricingDetails:') // console.log(pricingDetails) if (mockValidation) { let priceIn; try { priceIn = JSON.parse(pricingDetails.response[0]); } catch (e) { priceIn = { globalPrice: 1, provider: 'Binance', symbol: 'BTCUSDT', timestamp: 1, }; } return { valid: true, price: { ...pricingDetails, priceParts: pricingDetails.response, price: priceIn, }, }; } if (ideaIdea.priceInfo === undefined) { // console.log('TradeIdeaPricingValidationError: priceInfo undefined') return { valid: false, price: pricingDetails, }; } // First we restore the price parts from key parts let priceParts = []; try { priceParts = restorePricePartsFromKeys(pricingDetails.response, pricingDetails.keys); } catch (e) { // console.log('Error Validating Prices:') // console.log(e) return { valid: false, price: pricingDetails, }; } if ((0, __1.deterministicStringify)(priceParts) !== (0, __1.deterministicStringify)(pricingDetails.priceParts)) { // console.log('TradeIdeaPricingValidationError: priceParts do not match') return { valid: false, price: pricingDetails, }; } // Now we validate the got prices and reduce to one price let price; try { price = getValidPriceFromPartsAndKeys(pricingDetails.priceParts, pricingDetails.keys); } catch (e) { // console.log('Error Validating Prices:') // console.log(e) return { valid: false, price: pricingDetails, }; } if (price.fetchError === true) { return { valid: false, price: pricingDetails, }; } // console.log('price:') // console.log(price) // console.log('pricingDetails.price:') // console.log(pricingDetails.price) if ((0, __1.deterministicStringify)(price) !== (0, __1.deterministicStringify)(pricingDetails.price)) { // console.log('TradeIdeaPricingValidationError: price do not match') return { valid: false, price: pricingDetails, }; } // console.log('price') // console.log(price) // console.log('pricingDetails') // console.log(pricingDetails.price) // For last, we validate the original responseArray signature return checkIfPriceSignedResponseIsValid(pricingDetails, cachedStrategyState, mockValidation); }; exports.validatePricingSignature = validatePricingSignature; //# sourceMappingURL=pricing-validation.tools.js.map /***/ }), /***/ 4989: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getAllStillNotClosedLatestIdeas = exports.getOnlyLastStageOfEachIdea = exports.getCreatorLatestData = exports.getLastIdea = exports.getExistingCloseNftByTicker = exports.getExistingAdjustNftByTicker = exports.getExistingOpenNftByTicker = exports.getFirstStageOfIdeaByKey = exports.getLastStageOfIdeaByKey = exports.getAllIdeasByKey = exports.getAllIdeas = exports.getEncryptedIdeasByKey = exports.getEncryptedIdeas = exports.getValidatedIdeasByKey = exports.getValidatedIdeas = exports.sanitizeIdeas = exports.filterDuplicatedIdeas = exports.filterNullifiedIdeas = exports.orderByNftId = void 0; // order by nftId. if nftId is undefined, put it at the end const orderByNftId = (ideas) => { const orderedIdeas = ideas.sort((a, b) => { if (a.nftId === undefined && b.nftId === undefined) return 0; if (a.nftId === undefined) return 1; if (b.nftId === undefined) return -1; return a.nftId - b.nftId; }); return orderedIdeas; }; exports.orderByNftId = orderByNftId; const filterNullifiedIdeas = (ideas) => { const filteredIdeas = ideas.filter((idea) => idea.nullified === undefined); return filteredIdeas; }; exports.filterNullifiedIdeas = filterNullifiedIdeas; const filterDuplicatedIdeas = (ideas) => { const alreadySeenNftIds = new Set(); const filteredIdeas = []; for (const idea of ideas) { if (idea.nftId === undefined) continue; if (alreadySeenNftIds.has(idea.nftId)) continue; alreadySeenNftIds.add(idea.nftId); filteredIdeas.push(idea); } return filteredIdeas; }; exports.filterDuplicatedIdeas = filterDuplicatedIdeas; const sanitizeIdeas = (ideas) => { return (0, exports.orderByNftId)((0, exports.filterDuplicatedIdeas)((0, exports.filterNullifiedIdeas)(ideas))); }; exports.sanitizeIdeas = sanitizeIdeas; const getValidatedIdeas = (cachedStrategyState) => { let validatedIdeas = []; const check = cachedStrategyState?.validatedIdeaKeys; if (check) { for (const validatedIdeaKey of cachedStrategyState.validatedIdeaKeys.values()) { const validatedIdeaSet = (0, exports.getValidatedIdeasByKey)(validatedIdeaKey, cachedStrategyState); validatedIdeas = [...validatedIdeas, ...validatedIdeaSet]; } } return (0, exports.sanitizeIdeas)(validatedIdeas); }; exports.getValidatedIdeas = getValidatedIdeas; const getValidatedIdeasByKey = (ideaKey, cachedStrategyState) => { const validatedIdeas = []; const check = cachedStrategyState?.validatedIdeasByKey; if (check) { const validatedIdeasNftIds = cachedStrategyState.validatedIdeasByKey.get(ideaKey) || []; for (const validatedIdeaNftId of validatedIdeasNftIds) { const validatedIdea = cachedStrategyState.ideas.get(validatedIdeaNftId); validatedIdeas.push(validatedIdea); } } return (0, exports.sanitizeIdeas)(validatedIdeas); }; exports.getValidatedIdeasByKey = getValidatedIdeasByKey; const getEncryptedIdeas = (cachedStrategyState) => { const encryptedIdeas = []; const check = cachedStrategyState?.encryptedIdeas; if (check) { const encryptedIdeasNftIds = cachedStrategyState.encryptedIdeas.values(); for (const encryptedIdeaNftId of encryptedIdeasNftIds) { const encryptedIdea = cachedStrategyState.ideas.get(encryptedIdeaNftId); encryptedIdeas.push(encryptedIdea); } } return (0, exports.sanitizeIdeas)(encryptedIdeas); }; exports.getEncryptedIdeas = getEncryptedIdeas; const getEncryptedIdeasByKey = (ideaKey, cachedStrategyState) => { const encryptedIdeas = []; const check = cachedStrategyState?.encryptedIdeasByKey; if (check) { const encryptedIdeasNftIds = cachedStrategyState.encryptedIdeasByKey.get(ideaKey) || []; for (const encryptedIdeaNftId of encryptedIdeasNftIds) { const encryptedIdea = cachedStrategyState.ideas.get(encryptedIdeaNftId); encryptedIdeas.push(encryptedIdea); } } return (0, exports.sanitizeIdeas)(encryptedIdeas); }; exports.getEncryptedIdeasByKey = getEncryptedIdeasByKey; const getAllIdeas = (cachedStrategyState) => { const allIdeas = [ ...(0, exports.getValidatedIdeas)(cachedStrategyState), ...(0, exports.getEncryptedIdeas)(cachedStrategyState), ]; return (0, exports.sanitizeIdeas)(allIdeas); }; exports.getAllIdeas = getAllIdeas; const getAllIdeasByKey = (ideaKey, cachedStrategyState) => { const allIdeas = [ ...(0, exports.getValidatedIdeasByKey)(ideaKey, cachedStrategyState), ...(0, exports.getEncryptedIdeasByKey)(ideaKey, cachedStrategyState), ]; return (0, exports.sanitizeIdeas)(allIdeas); }; exports.getAllIdeasByKey = getAllIdeasByKey; const getLastStageOfIdeaByKey = (ideaKey, cachedStrategyState) => { const lastStageOfIdea = (0, exports.getAllIdeasByKey)(ideaKey, cachedStrategyState).pop(); return lastStageOfIdea; }; exports.getLastStageOfIdeaByKey = getLastStageOfIdeaByKey; const getFirstStageOfIdeaByKey = (ideaKey, cachedStrategyState) => { const firstStageOfIdea = (0, exports.getAllIdeasByKey)(ideaKey, cachedStrategyState).shift(); return firstStageOfIdea; }; exports.getFirstStageOfIdeaByKey = getFirstStageOfIdeaByKey; const getExistingOpenNftByTicker = (ticker, cachedStrategyState) => { const valids = (0, exports.getAllIdeas)(cachedStrategyState); const tickersMapOpenNftId = new Map(); for (const valid of valids) { if (valid.idea === undefined) continue; const idea = valid.idea; if (idea.kind === 'open') { tickersMapOpenNftId.set(idea.asset.ticker, valid.nftId); } else if (idea.kind === 'close') { tickersMapOpenNftId.delete(idea.asset.ticker); } } if (tickersMapOpenNftId.has(ticker)) { return cachedStrategyState.ideas.get(tickersMapOpenNftId.get(ticker)); } else { return undefined; } }; exports.getExistingOpenNftByTicker = getExistingOpenNftByTicker; const getExistingAdjustNftByTicker = (ticker, cachedStrategyState) => { const valids = (0, exports.getAllIdeas)(cachedStrategyState); let lookingForNftId = undefined; const tickersMapOpenNftId = new Map(); for (const valid of valids) { if (valid.idea === undefined) continue; const idea = valid.idea; if (idea.kind === 'open') { tickersMapOpenNftId.set(idea.asset.ticker, valid.nftId); } else if (idea.kind === 'adjust') { lookingForNftId = valid.nftId; } else if (idea.kind === 'close') { tickersMapOpenNftId.delete(idea.asset.ticker); lookingForNftId = undefined; } } if (tickersMapOpenNftId.has(ticker) && lookingForNftId !== undefined) { return cachedStrategyState.ideas.get(lookingForNftId); } else { return undefined; } }; exports.getExistingAdjustNftByTicker = getExistingAdjustNftByTicker; const getExistingCloseNftByTicker = (ticker, cachedStrategyState) => { const valids = (0, exports.getAllIdeas)(cachedStrategyState); let lookingForNftId = undefined; const tickersMapOpenNftId = new Map(); for (const valid of valids) { if (valid.idea === undefined) continue; const idea = valid.idea; if (idea.kind === 'open') { lookingForNftId = undefined; tickersMapOpenNftId.set(idea.asset.ticker, valid.nftId); } else if (idea.kind === 'adjust') { } else if (idea.kind === 'close') { lookingForNftId = valid.nftId; tickersMapOpenNftId.delete(idea.asset.ticker); } } if (!tickersMapOpenNftId.has(ticker) && lookingForNftId !== undefined) { return cachedStrategyState.ideas.get(lookingForNftId); } else { return undefined; } }; exports.getExistingCloseNftByTicker = getExistingCloseNftByTicker; const getLastIdea = (cachedStrategyState) => { return cachedStrategyState.ideas.get(cachedStrategyState.lastNftId); }; exports.getLastIdea = getLastIdea; const getCreatorLatestData = (cachedStrategyState) => { const lastIdea = (0, exports.getLastIdea)(cachedStrategyState); const creator = lastIdea.creator; return creator; }; exports.getCreatorLatestData = getCreatorLatestData; const getOnlyLastStageOfEachIdea = (cachedStrategyState) => { const allOrderedIdeas = (0, exports.getAllIdeas)(cachedStrategyState); const allLatestIdeas = new Map(); for (const idea of allOrderedIdeas) { allLatestIdeas.set(idea.content.ideaKey, idea); } const latestStages = Array.from(allLatestIdeas.values()); // now order it again const orderedLatestStages = latestStages.sort((a, b) => { if (a.nftId === undefined && b.nftId === undefined) return 0; if (a.nftId === undefined) return 1; if (b.nftId === undefined) return -1; return a.nftId - b.nftId; }); return orderedLatestStages; }; exports.getOnlyLastStageOfEachIdea = getOnlyLastStageOfEachIdea; const getAllStillNotClosedLatestIdeas = (cachedStrategyState) => { const allLatestStages = (0, exports.getOnlyLastStageOfEachIdea)(cachedStrategyState); return allLatestStages.filter((ones) => { if (typeof ones.idea === 'string') { return true; } else { const idea = ones.idea; if (idea.kind === 'close') { return false; } else { return true; } } }); }; exports.getAllStillNotClosedLatestIdeas = getAllStillNotClosedLatestIdeas; //# sourceMappingURL=query-chain.tools.js.map /***/ }), /***/ 6557: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.queryChain = void 0; __exportStar(__webpack_require__(2199), exports); __exportStar(__webpack_require__(8937), exports); exports.queryChain = __importStar(__webpack_require__(4989)); //# sourceMappingURL=index.js.map /***/ }), /***/ 3836: /***/ (function(module) { "use strict"; (function(root) { function checkInt(value) { return (parseInt(value) === value); } function checkInts(arrayish) { if (!checkInt(arrayish.length)) { return false; } for (var i = 0; i < arrayish.length; i++) { if (!checkInt(arrayish[i]) || arrayish[i] < 0 || arrayish[i] > 255) { return false; } } return true; } function coerceArray(arg, copy) { // ArrayBuffer view if (arg.buffer && ArrayBuffer.isView(arg) && arg.name === 'Uint8Array') { if (copy) { if (arg.slice) { arg = arg.slice(); } else { arg = Array.prototype.slice.call(arg); } } return arg; } // It's an array; check it is a valid representation of a byte if (Array.isArray(arg)) { if (!checkInts(arg)) { throw new Error('Array contains invalid value: ' + arg); } return new Uint8Array(arg); } // Something else, but behaves like an array (maybe a Buffer? Arguments?) if (checkInt(arg.length) && checkInts(arg)) { return new Uint8Array(arg); } throw new Error('unsupport