UNPKG

@mimicry/kaleidoscope

Version:

Kaleidoscope is an NPM package that conveniently aggregates responses from multiple NFT data providers.

3 lines (2 loc) 38.9 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,r,n,o,a,i=require("decimal.js"),c=(t=require("got"))&&"object"==typeof t&&"default"in t?t.default:t,s=require("candlestick-convert");function u(){u=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function h(t,e,r,o){var a=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new _(o||[]);return n(a,"_invoke",{value:C(t,r,i)}),a}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=h;var l={};function f(){}function d(){}function m(){}var v={};s(v,a,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(M([])));g&&g!==e&&r.call(g,a)&&(v=g);var w=m.prototype=f.prototype=Object.create(v);function b(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var o;n(this,"_invoke",{value:function(n,a){function i(){return new e((function(o,i){!function n(o,a,i,c){var s=p(t[o],t,a);if("throw"!==s.type){var u=s.arg,h=u.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(h).then((function(t){u.value=t,i(u)}),(function(t){return n("throw",t,i,c)}))}c(s.arg)}(n,a,o,i)}))}return o=o?o.then(i,i):i()}})}function C(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=k(i,r);if(c){if(c===l)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=p(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===l)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}function k(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,k(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),l;var o=p(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,l;var a=o.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function M(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:A}}function A(){return{value:void 0,done:!0}}return d.prototype=m,n(w,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:d,configurable:!0}),d.displayName=s(m,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,s(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},b(x.prototype),s(x.prototype,i,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new x(h(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},b(w),s(w,c,"Generator"),s(w,a,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=M,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(N),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:M(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function h(t,e,r,n,o,a,i){try{var c=t[a](i),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function p(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){h(a,n,o,i,c,"next",t)}function c(t){h(a,n,o,i,c,"throw",t)}i(void 0)}))}}function l(){return(l=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function f(t,e){var r,n;t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r=t,n=e,(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(r,n)}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function m(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return d(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e=exports.Chain||(exports.Chain={})).ETHEREUM="ethereum",e.POLYGON="polygon",e.SOLANA="solana",e.BSC="bsc",e.ARBITRUM="arbitrum",e.OPTIMISM="optimism",e.KLAYTN="klaytn",e.AVALANCHE="avalanche",(r=exports.CurrencySymbol||(exports.CurrencySymbol={})).ETH="ETH",r.USD="USD",r.MATIC="MATIC",r.SOL="SOL",r.BNB="BNB",r.KLAY="KLAY",r.AVAX="AVAX",(n=exports.ConsensusFilter||(exports.ConsensusFilter={})).MAD="mad",n.NONE="none",(o=exports.ConsensusMethod||(exports.ConsensusMethod={})).MEDIAN="median",o.RANDOM="random",o.MEAN="mean",(a=exports.Timeframe||(exports.Timeframe={})).FIVE_MIN="5m",a.FIFTEEN_MIN="15m",a.THIRTY_MIN="30m",a.ONE_HOUR="1h",a.ONE_DAY="1d",a.ONE_WEEK="1w";var v=function(){function t(t){if(this._verbose=!1,t.verbose&&(this._verbose=Boolean(t.verbose)),!t.dataProviders)throw new Error("No providers specified.")}var e=t.prototype;return e.getName=function(){return this.constructor.name},e.runFactory=function(){var t=p(u().mark((function t(e,r,n,o){var a,i,c,s,h,p;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=[],i=[],t.t0=u().keys(e);case 3:if((t.t1=t.t0()).done){t.next=19;break}return c=e[t.t1.value],t.prev=6,t.next=9,c[r].apply(c,n);case 9:a.push(s=t.sent),i.push({source:c.getName(),value:s.amount}),t.next=17;break;case 14:t.prev=14,t.t2=t.catch(6);case 17:t.next=3;break;case 19:if(0!==a.length){t.next=21;break}throw new Error("No valid values returned from providers.");case 21:return p={method:r,timestamp:(new Date).toISOString()},1===a.length?(p.data=h=a[0],p.source=i[0].source):(h=this.applyConsensusMechanism(a,o),p.currencyInfo=h.currencyInfo,p.data=h.amount,p.sources=i),t.abrupt("return",this._verbose?p:h);case 24:case"end":return t.stop()}}),t,this,[[6,14]])})));return function(e,r,n,o){return t.apply(this,arguments)}}(),e.addDataProvider=function(t,e){throw new Error("Method not implemented: addDataProvider()")},e.applyConsensusMechanism=function(t,e){void 0===e&&(e={filter:exports.ConsensusFilter.NONE,method:exports.ConsensusMethod.MEDIAN});var r=this._applyConsensusFilter(t,e.filter);return this._applyConsensusMethod(r,e.method)},e.getBlockchain=function(t){throw new Error("Method not implemented: addDataProvider()")},e.getCorrectProviders=function(t,e){var r,n=t;return e&&((r={})[e]=t[e],n=r),n},e.initProviders=function(t){for(var e=0,r=Object.entries(t);e<r.length;e++){var n=r[e];this.addDataProvider(n[0],String(n[1]))}},e._applyConsensusFilter=function(t,e){switch(e){case void 0:case exports.ConsensusFilter.NONE:return t;case exports.ConsensusFilter.MAD:return function(t){if(0===t.length)return t;var e=t.reduce((function(t,e){return t.plus(e.amount.decimal)}),new i.Decimal(0)).dividedBy(t.length),r=t.map((function(t){return t.amount.decimal.minus(e).absoluteValue()})),n=r.reduce((function(t,e){return t.plus(e)}),new i.Decimal(0)).dividedBy(r.length),o=e.minus(n),a=e.plus(n);return t.filter((function(t){return t.amount.decimal.greaterThanOrEqualTo(o)&&t.amount.decimal.lessThanOrEqualTo(a)}))}(t);default:throw new Error(e+" is not a valid consensus filter.")}},e._applyConsensusMethod=function(t,e){switch(e){case void 0:case exports.ConsensusMethod.MEDIAN:return function(t){if(0===t.length)throw new Error("Cannot calculate median of empty array");if(1===t.length)return t[0];for(var e,r=t[0].currencyInfo,n=m(t);!(e=n()).done;)if(e.value.currencyInfo.symbol!==r.symbol)throw new Error("All Values must be in the same currency to calculate median.");t.sort((function(t,e){return t.amount.decimal.comparedTo(e.amount.decimal)}));var o=Math.floor(t.length/2);if(t.length%2==0){var a=i.Decimal.div(i.Decimal.add(t[o-1].amount.decimal,t[o].amount.decimal),2);return{currencyInfo:t[o].currencyInfo,amount:{atomic:BigInt(a.times(Math.pow(10,t[o].currencyInfo.decimals)).toFixed(0)),decimal:a}}}return t[o]}(t);case exports.ConsensusMethod.MEAN:return function(t){if(0===t.length)throw new Error("Cannot calculate mean of empty array");if(1===t.length)return t[0];for(var e,r=t[0].currencyInfo,n=m(t);!(e=n()).done;)if(e.value.currencyInfo.symbol!==r.symbol)throw new Error("All values must be in the same currency to calculate mean");for(var o,a=new i.Decimal(0),c=m(t);!(o=c()).done;)a=a.plus(o.value.amount.decimal);var s=a.dividedBy(t.length);return{currencyInfo:r,amount:{atomic:BigInt(s.times(new i.Decimal(10).pow(r.decimals)).toFixed(0)),decimal:s}}}(t);case exports.ConsensusMethod.RANDOM:return function(t){if(0===t.length)throw new Error("Cannot select a random Value from an empty array");return t[Math.floor(Math.random()*t.length)]}(t);default:throw new Error(e+" is not a valid consensus method.")}},t}(),y=function(){function t(t,e){this._config={key:"string"==typeof t?t:t.apiKey,host:e}}var e=t.prototype;return e.gotJson=function(){var t=p(u().mark((function t(e,r){var n;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=l({},r,{retry:{limit:5,backoffLimit:1e4,calculateDelay:function(t){return t.computedValue/4}}}),t.next=4,c(e,n).json();case 4:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),e.getApiHost=function(){return this._config.host},e.getApiKey=function(){return this._config.key},e.getBlockchain=function(t){throw new Error("Method not implemented: getBlockchain()")},e.getCurrencyInfoFromChain=function(t){switch(t){case void 0:case exports.Chain.ARBITRUM:case exports.Chain.OPTIMISM:case exports.Chain.ETHEREUM:return this.getCurrencyInfoFromSymbol(exports.CurrencySymbol.ETH);case exports.Chain.POLYGON:return this.getCurrencyInfoFromSymbol(exports.CurrencySymbol.MATIC);case exports.Chain.SOLANA:return this.getCurrencyInfoFromSymbol(exports.CurrencySymbol.SOL);case exports.Chain.BSC:return this.getCurrencyInfoFromSymbol(exports.CurrencySymbol.BNB);default:throw new Error(t+" is not a valid chain.")}},e.getCurrencyInfoFromSymbol=function(t){switch(t){case void 0:case exports.CurrencySymbol.ETH:return{symbol:exports.CurrencySymbol.ETH,name:"Ethereum",decimals:18};case exports.CurrencySymbol.MATIC:return{symbol:exports.CurrencySymbol.MATIC,name:"Matic",decimals:18};case exports.CurrencySymbol.BNB:return{symbol:exports.CurrencySymbol.BNB,name:"Binance Coin",decimals:18};case exports.CurrencySymbol.SOL:return{symbol:exports.CurrencySymbol.SOL,name:"Solana",decimals:9};case exports.CurrencySymbol.USD:return{symbol:exports.CurrencySymbol.USD,name:"United States Dollar",decimals:8};default:throw new Error(t+" is not a valid CurrencySymbol.")}},e.getName=function(){return this.constructor.name},t}();function g(t,e){return function(t,e){return{currencyInfo:e,amount:{atomic:t,decimal:new i.Decimal(Number(t)/Math.pow(10,e.decimals))}}}(function(t,e){return BigInt(t*Math.pow(10,e.decimals))}(t,e),e)}function w(t){switch(t){case void 0:case exports.Chain.ETHEREUM:return"https://etherscan.io";case exports.Chain.POLYGON:return"https://polygonscan.com";case exports.Chain.SOLANA:return"https://explorer.solana.com";case exports.Chain.BSC:return"https://bscscan.com";case exports.Chain.ARBITRUM:return"https://arbiscan.io";case exports.Chain.OPTIMISM:return"https://optimistic.etherscan.io";default:throw new Error("Cannot find blockchain explorer using unknown chain: "+t)}}var b=function(t){function e(e){return t.call(this,e,"https://api.coingecko.com/api/v3/")||this}f(e,t);var r=e.prototype;return r.getFloor=function(){var t=p(u().mark((function t(e){var r,n,o,a,i;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=r+"nfts/"+n+"/contract/"+e.address,t.next=5,this.gotJson(o);case 5:return a=t.sent,i=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",g(Number(a.floor_price.native_currency),i));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getFloorChart=function(){var t=p(u().mark((function t(e,r){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),r.getHistoricSales=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMarketCap=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMetadata=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=r+"nfts/"+n+"/contract/"+e.address,t.next=5,this.gotJson(o);case 5:return a=t.sent,i=this.getCurrencyInfoFromChain(e.chain),c={contract:e,symbol:a.symbol,name:a.name,description:a.description,collectionSize:Number(a.total_supply),ownerCount:Number(a.number_of_unique_addresses),images:{thumbnail:a.image.small},urls:{explorer:w(e.chain)+"/address/"+e.address,website:a.links.homepage,discord:a.links.discord,twitter:a.links.twitter},stats:{currencyInfo:i,floor:{h24:g(Number(a.floor_price.native_currency),i).amount,h24Change:g(Number(a.floor_price_24h_percentage_change.native_currency),i).amount.decimal},volume:{h24:g(Number(a.volume_24h.native_currency),i).amount,h24Change:g(Number(a.volume_24h_percentage_change.native_currency),i).amount.decimal}}},t.abrupt("return",c);case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getBlockchain=function(t){switch(t){case void 0:case exports.Chain.ETHEREUM:return"ethereum";case exports.Chain.BSC:return"binance-smart-chain";case exports.Chain.POLYGON:return"polygon-pos";case exports.Chain.ARBITRUM:return"arbitrum-one";case exports.Chain.SOLANA:throw new Error("Solana is supported by CoinGecko, but not yet implemented.");case exports.Chain.OPTIMISM:return"optimistic-ethereum";case exports.Chain.AVALANCHE:return"avalanche";case exports.Chain.KLAYTN:return"klay-token";default:throw new Error(t+" is not supported by "+this.getName()+".")}},r.getName=function(){return"CoinGecko"},e}(y);function x(t){if(0===t.length)throw new Error("No ticks provided.");t.sort((function(t,e){return t[0]-e[0]}));var e=t[0][1];return t.map((function(t){var r=t[0],n=e,o=t[1],a=Math.max(n,o),i=Math.min(n,o);return e=o,{time:r,open:n,high:a,low:i,close:o,volume:0}}))}var C=function(t){function e(e){return t.call(this,e,"https://pro-api.coingecko.com/api/v3/")||this}f(e,t);var r=e.prototype;return r.getFloorChart=function(){var t=p(u().mark((function t(e,r){var n,o,a,i,c,h,p,l,f,d,m;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this._getTimeParams(r),o=n[0],a=n[1],i=this.getApiHost(),c=this.getBlockchain(e.chain),h=i+"nfts/"+c+"/contract/"+e.address+"/market_chart",p={searchParams:{days:o},headers:{Accept:"application/json","x-cg-pro-api-key":this.getApiKey()}},t.next=7,this.gotJson(h,p);case 7:return f=x((l=t.sent).floor_price_native),d=300,"max"===o&&(f=this._injectVolumeIntoIOCHLV(f,l.h24_volume_native),d=86400),f=s.batchCandleJSON(f,d,a),m=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",{currencyInfo:m,iochlv:f});case 15:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r._getTimeParams=function(t){switch(t){case exports.Timeframe.FIVE_MIN:return[14,300];case exports.Timeframe.FIFTEEN_MIN:case exports.Timeframe.THIRTY_MIN:return[14,900];case exports.Timeframe.ONE_HOUR:return[14,3600];case void 0:case exports.Timeframe.ONE_DAY:return["max",86400];case exports.Timeframe.ONE_WEEK:return["max",604800];default:throw new Error("Invalid timeframe.")}},r._injectVolumeIntoIOCHLV=function(t,e){var r=new Map(e.map((function(t){return[t[0],t[1]]})));return t.map((function(t){return l({},t,{volume:r.get(t.time)||0})}))},r.getFloor=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=r+"nfts/"+n+"/contract/"+e.address,a={headers:{Accept:"application/json","x-cg-pro-api-key":this.getApiKey()}},t.next=6,this.gotJson(o,a);case 6:return i=t.sent,c=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",g(Number(i.floor_price.native_currency),c));case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getHistoricSales=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMarketCap=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMetadata=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c,s;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=r+"nfts/"+n+"/contract/"+e.address,a={headers:{Accept:"application/json","x-cg-pro-api-key":this.getApiKey()}},t.next=6,this.gotJson(o,a);case 6:return i=t.sent,c=this.getCurrencyInfoFromChain(e.chain),s={contract:e,symbol:i.symbol,name:i.name,description:i.description,collectionSize:Number(i.total_supply),ownerCount:Number(i.number_of_unique_addresses),images:{thumbnail:i.image.small},urls:{explorer:w(e.chain)+"/address/"+e.address,website:i.links.homepage,discord:i.links.discord,twitter:i.links.twitter},stats:{currencyInfo:c,floor:{h24:g(Number(i.floor_price.native_currency),c).amount,h24Change:g(Number(i.floor_price_24h_percentage_change.native_currency),c).amount.decimal},volume:{h24:g(Number(i.volume_24h.native_currency),c).amount,h24Change:g(Number(i.volume_24h_percentage_change.native_currency),c).amount.decimal}}},t.abrupt("return",s);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getBlockchain=function(t){switch(t){case void 0:case exports.Chain.ETHEREUM:return"ethereum";case exports.Chain.BSC:return"binance-smart-chain";case exports.Chain.POLYGON:return"polygon-pos";case exports.Chain.ARBITRUM:return"arbitrum-one";case exports.Chain.SOLANA:throw new Error("Solana is supported by CoinGecko, but not yet implemented.");case exports.Chain.OPTIMISM:return"optimistic-ethereum";case exports.Chain.AVALANCHE:return"avalanche";case exports.Chain.KLAYTN:return"klay-token";default:throw new Error(t+" is not supported by "+this.getName()+".")}},r.getName=function(){return"CoinGecko Pro"},e}(y),k=function(t){function e(e){return t.call(this,e,"https://api.diadata.org/v1/")||this}f(e,t);var r=e.prototype;return r.getFloor=function(){var t=p(u().mark((function t(e){var r,n,o,a,i;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=r+"NFTFloor/"+n+"/"+e.address,t.next=5,this.gotJson(o);case 5:return a=t.sent,i=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",g(Number(a.Floor_Price),i));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getFloorChart=function(){var t=p(u().mark((function t(e,r){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),r.getHistoricSales=function(){var t=p(u().mark((function t(e,r,n){var o,a,c,s,h,p,l,f,d,v;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=this.getApiHost(),a=this.getBlockchain(e.chain),c=o+"NFTTradesCollection/"+a+"/"+e.address,s={searchParams:{starttime:r,endtime:n}},h=this.getCurrencyInfoFromChain(e.chain),t.next=7,this.gotJson(c,s);case 7:for(p=[],l=m(t.sent);!(f=l()).done;)v={timestamp:(d=f.value).Timestamp,blockNumber:Number(d.BlockNumber),tokenId:String(d.NFTid),price:(u=Number(d.Price),y=h,{atomic:BigInt(u*Math.pow(10,y.decimals)),decimal:new i.Decimal(u)}),buyer:d.ToAddress,seller:d.FromAddress,transactionHash:d.TxHash,exchange:d.Exchange,bundleSale:Boolean(d.BundleSale)},p.push(v);return t.abrupt("return",{contract:e,currencyInfo:h,numSales:p.length,sales:p});case 11:case"end":return t.stop()}var u,y}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getMarketCap=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMetadata=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getBlockchain=function(t){switch(t){case void 0:case exports.Chain.ETHEREUM:return"Ethereum";default:throw new Error(t+" is not supported by "+this.getName()+".")}},r.getName=function(){return"DIA"},e}(y),E=function(t){function e(e){return t.call(this,e,"https://api.nftbank.run/v1/")||this}f(e,t);var r=e.prototype;return r.getFloor=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=r+"collection/"+e.address+"/floor",a={searchParams:{networkId:n},headers:{Accept:"application/json","x-api-key":this.getApiKey()}},t.next=6,this.gotJson(o,a);case 6:return i=t.sent,c=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",g(Number(i.data.floor.eth),c));case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getFloorChart=function(){var t=p(u().mark((function t(e,r){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),r.getHistoricSales=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMarketCap=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMetadata=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getBlockchain=function(t){switch(t){case void 0:case exports.Chain.ETHEREUM:return"ethereum";default:throw new Error(t+" is not supported by "+this.getName()+".")}},r.getName=function(){return"NFTBank"},e}(y),N=function(t){function e(e){return t.call(this,e,"https://data-api.nftgo.io/")||this}f(e,t);var r=e.prototype;return r.getFloor=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=""+r+n+"/v1/collection/"+e.address+"/metrics",a={headers:{Accept:"application/json","X-API-KEY":this.getApiKey()}},t.next=6,this.gotJson(o,a);case 6:return i=t.sent,c=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",g(Number(i.floor_price.value),c));case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getFloorChart=function(){var t=p(u().mark((function t(e,r){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),r.getHistoricSales=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMarketCap=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getApiHost(),n=this.getBlockchain(e.chain),o=""+r+n+"/v1/collection/"+e.address+"/metrics",a={headers:{Accept:"application/json","X-API-KEY":this.getApiKey()}},t.next=6,this.gotJson(o,a);case 6:return i=t.sent,c=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",g(Number(i.market_cap_eth),c));case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getMetadata=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getBlockchain=function(t){switch(t){case void 0:case exports.Chain.ETHEREUM:return"eth";default:throw new Error(t+" is not supported by "+this.getName()+".")}},r.getName=function(){return"NFTGo"},e}(y),_=function(t){function e(e){return t.call(this,e,"https://api.reservoir.tools/")||this}f(e,t);var r=e.prototype;return r.getFloor=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c,s,h;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getHost(e.chain),n=r+"stats/v2/",o={searchParams:{collection:e.address},headers:{Accept:"application/json","x-api-key":this.getApiKey()}},t.next=5,this.gotJson(n,o);case 5:return a=t.sent,i=Number(a.stats.market.floorAsk.price.amount.decimal),c=Number(a.stats.market.topBid.price.amount.decimal),s=(i+c)/2,h=this.getCurrencyInfoFromChain(e.chain),t.abrupt("return",g(s,h));case 11:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getFloorChart=function(){var t=p(u().mark((function t(e,r){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),r.getHistoricSales=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMarketCap=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented.");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getMetadata=function(){var t=p(u().mark((function t(e){var r,n,o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getHost(e.chain),n=r+"collections/v5",o={searchParams:{id:e.address},headers:{Accept:"application/json","x-api-key":this.getApiKey()}},t.next=5,this.gotJson(n,o);case 5:return a=t.sent.collections[0],i=this.getCurrencyInfoFromChain(e.chain),c={contract:e,name:a.name,description:a.description,createdAt:a.createdAt,openseaVerificationStatus:"verified"===a.openseaVerificationStatus,openseaSlug:a.slug,collectionSize:Number(a.tokenCount),onSaleCount:Number(a.onSaleCount),ownerCount:Number(a.ownerCount),contractType:a.contractKind,images:{thumbnail:a.image,banner:a.banner,samples:a.sampleImages},urls:{explorer:w(e.chain)+"/address/"+e.address,website:a.externalUrl,discord:a.discordUrl,twitter:"https://twitter.com/"+a.twitterUsername},stats:{currencyInfo:i,floor:{h24:g(Number(a.floorSale["1day"]),i).amount,h24Change:g(Number(a.floorSaleChange["1day"]),i).amount.decimal,d7:g(Number(a.floorSale["7day"]),i).amount,d7Change:g(Number(a.floorSaleChange["7day"]),i).amount.decimal,d30:g(Number(a.floorSale["30day"]),i).amount,d30Change:g(Number(a.floorSaleChange["30day"]),i).amount.decimal},volume:{h24:g(Number(a.volume["1day"]),i).amount,h24Change:g(Number(a.volumeChange["1day"]),i).amount.decimal,d7:g(Number(a.volume["7day"]),i).amount,d7Change:g(Number(a.volumeChange["7day"]),i).amount.decimal,d30:g(Number(a.volume["30day"]),i).amount,d30Change:g(Number(a.volumeChange["30day"]),i).amount.decimal}}},t.abrupt("return",c);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getHost=function(t){switch(t){case void 0:case exports.Chain.ETHEREUM:return this.getApiHost();case exports.Chain.POLYGON:return"https://api-polygon.reservoir.tools/";case exports.Chain.BSC:return"https://api-bsc.reservoir.tools/";case exports.Chain.ARBITRUM:return"https://api-arbitrum.reservoir.tools/";case exports.Chain.OPTIMISM:return"https://api-optimism.reservoir.tools/";default:throw new Error(t+" is not supported by "+this.getName()+".")}},r.getName=function(){return"Reservoir"},e}(y),M=function(t){function e(e){var r;return(r=t.call(this,e)||this)._dataProviders={},r.initProviders(e.dataProviders.nfts),r}f(e,t);var r=e.prototype;return r.addDataProvider=function(t,e){switch(t){case"dia":this._dataProviders[t]=new k(e);break;case"nftBank":this._dataProviders[t]=new E(e);break;case"reservoir":this._dataProviders[t]=new _(e);break;case"coinGecko":this._dataProviders[t]=new b(e);break;case"coinGeckoPro":this._dataProviders[t]=new C(e);break;case"nftGo":this._dataProviders[t]=new N(e);break;default:throw new Error(t+" is not a valid NftCollectionDataProvider.")}},r.getFloors=function(){var t=p(u().mark((function t(e,r,n){var o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=[],a=m(e);case 2:if((i=a()).done){t.next=10;break}return c=i.value,t.next=6,this.getFloor(c,r,n);case 6:o.push(t.sent);case 8:t.next=2;break;case 10:return t.abrupt("return",o);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getFloor=function(){var t=p(u().mark((function t(e,r,n){var o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=this.getCorrectProviders(this._dataProviders,n),t.abrupt("return",this.runFactory(o,"getFloor",[e],r));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getFloorChart=function(){var t=p(u().mark((function t(e,r,n){var o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=this.getCorrectProviders(this._dataProviders,r),t.abrupt("return",this.runFactory(o,"getFloorChart",[e,n]));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getHistoricSales=function(){var t=p(u().mark((function t(e,r,n,o){var a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=this.getCorrectProviders(this._dataProviders,r),t.abrupt("return",this.runFactory(a,"getHistoricSales",[e,n,o]));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n,o){return t.apply(this,arguments)}}(),r.getMarketCap=function(){var t=p(u().mark((function t(e,r){var n;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.getCorrectProviders(this._dataProviders,r),t.abrupt("return",this.runFactory(n,"getMarketCap",[e]));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.getMetadata=function(){var t=p(u().mark((function t(e,r){var n;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.getCorrectProviders(this._dataProviders,r),t.abrupt("return",this.runFactory(n,"getMetadata",[e]));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e}(v),A=function(t){function e(e){return t.call(this,e,"https://api.coingecko.com/api/v3/")||this}f(e,t);var r=e.prototype;return r.getPrice=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented: getPrice()");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getName=function(){return"CoinGecko"},e}(y),I=function(t){function e(e){return t.call(this,e,"https://api.diadata.org/v1/")||this}f(e,t);var r=e.prototype;return r.getPrice=function(){var t=p(u().mark((function t(e){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Method not implemented: getPrice()");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),r.getName=function(){return"Dia"},e}(y),S=function(t){function e(e){var r;return(r=t.call(this,e)||this)._dataProviders={},r.initProviders(e.dataProviders.fungibleTokens),r}f(e,t);var r=e.prototype;return r.addDataProvider=function(t,e){switch(t){case"dia":this._dataProviders[t]=new I(e);break;case"coinGecko":this._dataProviders[t]=new A(e);break;default:throw new Error(t+" is not a valid FungibleDataProvider.")}},r.getPrices=function(){var t=p(u().mark((function t(e,r,n){var o,a,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=[],a=m(e);case 2:if((i=a()).done){t.next=10;break}return c=i.value,t.next=6,this.getPrice(c,r,n);case 6:o.push(t.sent);case 8:t.next=2;break;case 10:return t.abrupt("return",o);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),r.getPrice=function(){var t=p(u().mark((function t(e,r,n){var o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=this.getCorrectProviders(this._dataProviders,n),t.abrupt("return",this.runFactory(o,"getPrice",e,r));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),e}(v);exports.Kaleidoscope=function(t){if(!t.dataProviders)throw new Error("No data providers specified in config");this.nftCollection=new M(t.dataProviders.nfts?t:{dataProviders:{nfts:{dia:!0,coinGecko:!0}}}),this.fungibleToken=new S(t.dataProviders.fungibleTokens?t:{dataProviders:{fungibleTokens:{dia:!0,coinGecko:!0}}})}; //# sourceMappingURL=kaleidoscope.cjs.production.min.js.map