UNPKG

@samudai_xyz/web3-sdk

Version:

## All in one web3 integrations for Samudai

1 lines 7.87 kB
"use strict";(this.webpackChunkexampleTypescriptPackage=this.webpackChunkexampleTypescriptPackage||[]).push([[214],{60214:(e,r,t)=>{t.r(r),t.d(r,{AlchemyProvider:()=>_});var o=t(46797),n=t(82169),s=t(79861),i=t(58341);t(34359);let c=!1,a=!1;const E={debug:1,default:2,info:2,warning:3,error:4,off:5};let l=E.default,h=null;const u=function(){try{const e=[];if(["NFD","NFC","NFKD","NFKC"].forEach((r=>{try{if("test"!=="test".normalize(r))throw new Error("bad normalize")}catch(t){e.push(r)}})),e.length)throw new Error("missing "+e.join(", "));if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken implementation")}catch(e){return e.message}return null}();var N,R;!function(e){e.DEBUG="DEBUG",e.INFO="INFO",e.WARNING="WARNING",e.ERROR="ERROR",e.OFF="OFF"}(N||(N={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.NOT_IMPLEMENTED="NOT_IMPLEMENTED",e.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",e.NETWORK_ERROR="NETWORK_ERROR",e.SERVER_ERROR="SERVER_ERROR",e.TIMEOUT="TIMEOUT",e.BUFFER_OVERRUN="BUFFER_OVERRUN",e.NUMERIC_FAULT="NUMERIC_FAULT",e.MISSING_NEW="MISSING_NEW",e.INVALID_ARGUMENT="INVALID_ARGUMENT",e.MISSING_ARGUMENT="MISSING_ARGUMENT",e.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",e.CALL_EXCEPTION="CALL_EXCEPTION",e.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",e.NONCE_EXPIRED="NONCE_EXPIRED",e.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",e.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",e.TRANSACTION_REPLACED="TRANSACTION_REPLACED",e.ACTION_REJECTED="ACTION_REJECTED"}(R||(R={}));const p="0123456789abcdef";class g{constructor(e){Object.defineProperty(this,"version",{enumerable:!0,value:e,writable:!1})}_log(e,r){const t=e.toLowerCase();null==E[t]&&this.throwArgumentError("invalid log level name","logLevel",e),l>E[t]||console.log.apply(console,r)}debug(...e){this._log(g.levels.DEBUG,e)}info(...e){this._log(g.levels.INFO,e)}warn(...e){this._log(g.levels.WARNING,e)}makeError(e,r,t){if(a)return this.makeError("censored error",r,{});r||(r=g.errors.UNKNOWN_ERROR),t||(t={});const o=[];Object.keys(t).forEach((e=>{const r=t[e];try{if(r instanceof Uint8Array){let t="";for(let e=0;e<r.length;e++)t+=p[r[e]>>4],t+=p[15&r[e]];o.push(e+"=Uint8Array(0x"+t+")")}else o.push(e+"="+JSON.stringify(r))}catch(r){o.push(e+"="+JSON.stringify(t[e].toString()))}})),o.push(`code=${r}`),o.push(`version=${this.version}`);const n=e;let s="";switch(r){case R.NUMERIC_FAULT:{s="NUMERIC_FAULT";const r=e;switch(r){case"overflow":case"underflow":case"division-by-zero":s+="-"+r;break;case"negative-power":case"negative-width":s+="-unsupported";break;case"unbound-bitwise-result":s+="-unbound-result"}break}case R.CALL_EXCEPTION:case R.INSUFFICIENT_FUNDS:case R.MISSING_NEW:case R.NONCE_EXPIRED:case R.REPLACEMENT_UNDERPRICED:case R.TRANSACTION_REPLACED:case R.UNPREDICTABLE_GAS_LIMIT:s=r}s&&(e+=" [ See: https://links.ethers.org/v5-errors-"+s+" ]"),o.length&&(e+=" ("+o.join(", ")+")");const i=new Error(e);return i.reason=n,i.code=r,Object.keys(t).forEach((function(e){i[e]=t[e]})),i}throwError(e,r,t){throw this.makeError(e,r,t)}throwArgumentError(e,r,t){return this.throwError(e,g.errors.INVALID_ARGUMENT,{argument:r,value:t})}assert(e,r,t,o){e||this.throwError(r,t,o)}assertArgument(e,r,t,o){e||this.throwArgumentError(r,t,o)}checkNormalize(e){u&&this.throwError("platform missing String.prototype.normalize",g.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:u})}checkSafeUint53(e,r){"number"==typeof e&&(null==r&&(r="value not safe"),(e<0||e>=9007199254740991)&&this.throwError(r,g.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:e}),e%1&&this.throwError(r,g.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:e}))}checkArgumentCount(e,r,t){t=t?": "+t:"",e<r&&this.throwError("missing argument"+t,g.errors.MISSING_ARGUMENT,{count:e,expectedCount:r}),e>r&&this.throwError("too many arguments"+t,g.errors.UNEXPECTED_ARGUMENT,{count:e,expectedCount:r})}checkNew(e,r){e!==Object&&null!=e||this.throwError("missing new",g.errors.MISSING_NEW,{name:r.name})}checkAbstract(e,r){e===r?this.throwError("cannot instantiate abstract class "+JSON.stringify(r.name)+" directly; use a sub-class",g.errors.UNSUPPORTED_OPERATION,{name:e.name,operation:"new"}):e!==Object&&null!=e||this.throwError("missing new",g.errors.MISSING_NEW,{name:r.name})}static globalLogger(){return h||(h=new g("logger/5.7.0")),h}static setCensorship(e,r){if(!e&&r&&this.globalLogger().throwError("cannot permanently disable censorship",g.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),c){if(!e)return;this.globalLogger().throwError("error censorship permanent",g.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}a=!!e,c=!!r}static setLogLevel(e){const r=E[e.toLowerCase()];null!=r?l=r:g.globalLogger().warn("invalid log level - "+e)}static from(e){return new g(e)}}g.errors=R,g.levels=N;const I=new g("properties/5.7.0");function f(e,r,t){Object.defineProperty(e,r,{enumerable:!0,value:t,writable:!1})}const d={bigint:!0,boolean:!0,function:!0,number:!0,string:!0};function m(e){if(null==e||d[typeof e])return!0;if(Array.isArray(e)||"object"==typeof e){if(!Object.isFrozen(e))return!1;const r=Object.keys(e);for(let t=0;t<r.length;t++){let o=null;try{o=e[r[t]]}catch(e){continue}if(!m(o))return!1}return!0}return I.throwArgumentError("Cannot deepCopy "+typeof e,"object",e)}function A(e){if(m(e))return e;if(Array.isArray(e))return Object.freeze(e.map((e=>w(e))));if("object"==typeof e){const r={};for(const t in e){const o=e[t];void 0!==o&&f(r,t,w(o))}return r}return I.throwArgumentError("Cannot deepCopy "+typeof e,"object",e)}function w(e){return A(e)}class _ extends n.r{constructor(e){const r=_.getApiKey(e.apiKey),t=_.getAlchemyNetwork(e.network),n=_.getAlchemyConnectionInfo(t,r,"http");void 0!==e.url&&(n.url=e.url),n.throttleLimit=e.maxRetries,super(n,o.E[t]),this.apiKey=e.apiKey,this.maxRetries=e.maxRetries}static getApiKey(e){if(null==e)return o.D;if(e&&"string"!=typeof e)throw new Error(`Invalid apiKey '${e}' provided. apiKey must be a string.`);return e}static getNetwork(e){return"string"==typeof e&&e in o.C?o.C[e]:(0,s.H)(e)}static getAlchemyNetwork(e){if(void 0===e)return o.a;if("number"==typeof e)throw new Error(`Invalid network '${e}' provided. Network must be a string.`);if(!Object.values(o.N).includes(e))throw new Error(`Invalid network '${e}' provided. Network must be one of: ${Object.values(o.N).join(", ")}.`);return e}static getAlchemyConnectionInfo(e,r,t){const n="http"===t?(0,o.g)(e,r):(0,o.b)(e,r);return{headers:o.I?{"Alchemy-Ethers-Sdk-Version":o.V}:{"Alchemy-Ethers-Sdk-Version":o.V,"Accept-Encoding":"gzip"},allowGzip:!0,url:n}}detectNetwork(){const e=Object.create(null,{detectNetwork:{get:()=>super.detectNetwork}});return(0,o._)(this,void 0,void 0,(function*(){let r=this.network;if(null==r&&(r=yield e.detectNetwork.call(this),!r))throw new Error("No network detected");return r}))}_startPending(){(0,o.l)("WARNING: Alchemy Provider does not support pending filters")}isCommunityResource(){return this.apiKey===o.D}send(e,r){return this._send(e,r,"send")}_send(e,r,t){const o={method:e,params:r,id:this._nextId++,jsonrpc:"2.0"};this.emit("debug",{action:"request",request:w(o),provider:this});const n=["eth_chainId","eth_blockNumber"].indexOf(e)>=0;if(n&&this._cache[e])return this._cache[e];Object.assign({},this.connection).headers["Alchemy-Ethers-Sdk-Method"]=t;const s=(0,i.fetchJson)(this.connection,JSON.stringify(o),O).then((e=>(this.emit("debug",{action:"response",request:o,response:e,provider:this}),e)),(e=>{throw this.emit("debug",{action:"response",error:e,request:o,provider:this}),e}));return n&&(this._cache[e]=s,setTimeout((()=>{this._cache[e]=null}),0)),s}}function O(e){if(e.error){const r=new Error(e.error.message);throw r.code=e.error.code,r.data=e.error.data,r}return e.result}}}]);