-
Notifications
You must be signed in to change notification settings - Fork 0
/
8197.c98f5316d900e675db95.js
1 lines (1 loc) · 74.9 KB
/
8197.c98f5316d900e675db95.js
1
"use strict";(self.webpackChunktimeless_frontend=self.webpackChunktimeless_frontend||[]).push([[8197],{98197:(Ct,_e,N)=>{N.r(_e),N.d(_e,{AlchemyProvider:()=>ye,AlchemyWebSocketProvider:()=>Ge,BaseProvider:()=>Q,CloudflareProvider:()=>We,EtherscanProvider:()=>ne,FallbackProvider:()=>le,Formatter:()=>f,InfuraProvider:()=>ke,InfuraWebSocketProvider:()=>Qe,IpcProvider:()=>Xe,JsonRpcBatchProvider:()=>Ot,JsonRpcProvider:()=>I,JsonRpcSigner:()=>q,NodesmithProvider:()=>Ye,PocketProvider:()=>tt,Provider:()=>H.zt,Resolver:()=>ge,StaticJsonRpcProvider:()=>He,UrlJsonRpcProvider:()=>A,Web3Provider:()=>ae,WebSocketProvider:()=>ee,getDefaultProvider:()=>St,getNetwork:()=>ue.H,isCommunityResourcable:()=>xe,isCommunityResource:()=>de,showThrottleMessage:()=>X});var H=N(11527),ue=N(35473),Re=N(53744),b=N(2024),g=N(61488),it=N(45052),K=N(21),d=N(92275),Pe=N(15614),C=N(8822),x=N(51838),ot=N(29901),Te=N.n(ot),h=N(53898);const R="providers/5.5.0";var he=N(2885),st=N(51528),Z=N(32701);const U=new h.Logger(R);class f{constructor(){U.checkNew(new.target,f),this.formats=this.getDefaultFormats()}getDefaultFormats(){const e={},t=this.address.bind(this),r=this.bigNumber.bind(this),n=this.blockTag.bind(this),i=this.data.bind(this),o=this.hash.bind(this),c=this.hex.bind(this),l=this.number.bind(this),a=this.type.bind(this);return e.transaction={hash:o,type:a,accessList:f.allowNull(this.accessList.bind(this),null),blockHash:f.allowNull(o,null),blockNumber:f.allowNull(l,null),transactionIndex:f.allowNull(l,null),confirmations:f.allowNull(l,null),from:t,gasPrice:f.allowNull(r),maxPriorityFeePerGas:f.allowNull(r),maxFeePerGas:f.allowNull(r),gasLimit:r,to:f.allowNull(t,null),value:r,nonce:l,data:i,r:f.allowNull(this.uint256),s:f.allowNull(this.uint256),v:f.allowNull(l),creates:f.allowNull(t,null),raw:f.allowNull(i)},e.transactionRequest={from:f.allowNull(t),nonce:f.allowNull(l),gasLimit:f.allowNull(r),gasPrice:f.allowNull(r),maxPriorityFeePerGas:f.allowNull(r),maxFeePerGas:f.allowNull(r),to:f.allowNull(t),value:f.allowNull(r),data:f.allowNull(m=>this.data(m,!0)),type:f.allowNull(l),accessList:f.allowNull(this.accessList.bind(this),null)},e.receiptLog={transactionIndex:l,blockNumber:l,transactionHash:o,address:t,topics:f.arrayOf(o),data:i,logIndex:l,blockHash:o},e.receipt={to:f.allowNull(this.address,null),from:f.allowNull(this.address,null),contractAddress:f.allowNull(t,null),transactionIndex:l,root:f.allowNull(c),gasUsed:r,logsBloom:f.allowNull(i),blockHash:o,transactionHash:o,logs:f.arrayOf(this.receiptLog.bind(this)),blockNumber:l,confirmations:f.allowNull(l,null),cumulativeGasUsed:r,effectiveGasPrice:f.allowNull(r),status:f.allowNull(l),type:a},e.block={hash:o,parentHash:o,number:l,timestamp:l,nonce:f.allowNull(c),difficulty:this.difficulty.bind(this),gasLimit:r,gasUsed:r,miner:t,extraData:i,transactions:f.allowNull(f.arrayOf(o)),baseFeePerGas:f.allowNull(r)},e.blockWithTransactions=(0,d.shallowCopy)(e.block),e.blockWithTransactions.transactions=f.allowNull(f.arrayOf(this.transactionResponse.bind(this))),e.filter={fromBlock:f.allowNull(n,void 0),toBlock:f.allowNull(n,void 0),blockHash:f.allowNull(o,void 0),address:f.allowNull(t,void 0),topics:f.allowNull(this.topics.bind(this),void 0)},e.filterLog={blockNumber:f.allowNull(l),blockHash:f.allowNull(o),transactionIndex:l,removed:f.allowNull(this.boolean.bind(this)),address:t,data:f.allowFalsish(i,"0x"),topics:f.arrayOf(o),transactionHash:o,logIndex:l},e}accessList(e){return(0,Z.accessListify)(e||[])}number(e){return"0x"===e?0:b.O$.from(e).toNumber()}type(e){return"0x"===e||null==e?0:b.O$.from(e).toNumber()}bigNumber(e){return b.O$.from(e)}boolean(e){if("boolean"==typeof e)return e;if("string"==typeof e){if("true"===(e=e.toLowerCase()))return!0;if("false"===e)return!1}throw new Error("invalid boolean - "+e)}hex(e,t){return"string"==typeof e&&(!t&&"0x"!==e.substring(0,2)&&(e="0x"+e),(0,g.isHexString)(e))?e.toLowerCase():U.throwArgumentError("invalid hash","value",e)}data(e,t){const r=this.hex(e,t);if(r.length%2!=0)throw new Error("invalid data; odd-length - "+e);return r}address(e){return(0,he.getAddress)(e)}callAddress(e){if(!(0,g.isHexString)(e,32))return null;const t=(0,he.getAddress)((0,g.hexDataSlice)(e,12));return t===st.d?null:t}contractAddress(e){return(0,he.getContractAddress)(e)}blockTag(e){if(null==e)return"latest";if("earliest"===e)return"0x0";if("latest"===e||"pending"===e)return e;if("number"==typeof e||(0,g.isHexString)(e))return(0,g.hexValue)(e);throw new Error("invalid blockTag")}hash(e,t){const r=this.hex(e,t);return 32!==(0,g.hexDataLength)(r)?U.throwArgumentError("invalid hash","value",e):r}difficulty(e){if(null==e)return null;const t=b.O$.from(e);try{return t.toNumber()}catch{}return null}uint256(e){if(!(0,g.isHexString)(e))throw new Error("invalid uint256");return(0,g.hexZeroPad)(e,32)}_block(e,t){null!=e.author&&null==e.miner&&(e.miner=e.author);const r=null!=e._difficulty?e._difficulty:e.difficulty,n=f.check(t,e);return n._difficulty=null==r?null:b.O$.from(r),n}block(e){return this._block(e,this.formats.block)}blockWithTransactions(e){return this._block(e,this.formats.blockWithTransactions)}transactionRequest(e){return f.check(this.formats.transactionRequest,e)}transactionResponse(e){null!=e.gas&&null==e.gasLimit&&(e.gasLimit=e.gas),e.to&&b.O$.from(e.to).isZero()&&(e.to="0x0000000000000000000000000000000000000000"),null!=e.input&&null==e.data&&(e.data=e.input),null==e.to&&null==e.creates&&(e.creates=this.contractAddress(e)),(1===e.type||2===e.type)&&null==e.accessList&&(e.accessList=[]);const t=f.check(this.formats.transaction,e);if(null!=e.chainId){let r=e.chainId;(0,g.isHexString)(r)&&(r=b.O$.from(r).toNumber()),t.chainId=r}else{let r=e.networkId;null==r&&null==t.v&&(r=e.chainId),(0,g.isHexString)(r)&&(r=b.O$.from(r).toNumber()),"number"!=typeof r&&null!=t.v&&(r=(t.v-35)/2,r<0&&(r=0),r=parseInt(r)),"number"!=typeof r&&(r=0),t.chainId=r}return t.blockHash&&"x"===t.blockHash.replace(/0/g,"")&&(t.blockHash=null),t}transaction(e){return(0,Z.parse)(e)}receiptLog(e){return f.check(this.formats.receiptLog,e)}receipt(e){const t=f.check(this.formats.receipt,e);if(null!=t.root)if(t.root.length<=4){const r=b.O$.from(t.root).toNumber();0===r||1===r?(null!=t.status&&t.status!==r&&U.throwArgumentError("alt-root-status/status mismatch","value",{root:t.root,status:t.status}),t.status=r,delete t.root):U.throwArgumentError("invalid alt-root-status","value.root",t.root)}else 66!==t.root.length&&U.throwArgumentError("invalid root hash","value.root",t.root);return null!=t.status&&(t.byzantium=!0),t}topics(e){return Array.isArray(e)?e.map(t=>this.topics(t)):null!=e?this.hash(e,!0):null}filter(e){return f.check(this.formats.filter,e)}filterLog(e){return f.check(this.formats.filterLog,e)}static check(e,t){const r={};for(const n in e)try{const i=e[n](t[n]);void 0!==i&&(r[n]=i)}catch(i){throw i.checkKey=n,i.checkValue=t[n],i}return r}static allowNull(e,t){return function(r){return null==r?t:e(r)}}static allowFalsish(e,t){return function(r){return r?e(r):t}}static arrayOf(e){return function(t){if(!Array.isArray(t))throw new Error("not an array");const r=[];return t.forEach(function(n){r.push(e(n))}),r}}}function xe(s){return s&&"function"==typeof s.isCommunityResource}function de(s){return xe(s)&&s.isCommunityResource()}let Oe=!1;function X(){Oe||(Oe=!0,console.log("========= NOTICE ========="),console.log("Request-Rate Exceeded (this message will not be repeated)"),console.log(""),console.log("The default API keys for each service are provided as a highly-throttled,"),console.log("community resource for low-traffic projects and early prototyping."),console.log(""),console.log("While your application will continue to function, we highly recommended"),console.log("signing up for your own API keys to improve performance, increase your"),console.log("request rate/limit and enable other perks, such as metrics and advanced APIs."),console.log(""),console.log("For more details: https://docs.ethers.io/api-keys/"),console.log("=========================="))}var w=function(s,e,t,r){return new(t||(t=Promise))(function(i,o){function c(u){try{a(r.next(u))}catch(m){o(m)}}function l(u){try{a(r.throw(u))}catch(m){o(m)}}function a(u){u.done?i(u.value):function(i){return i instanceof t?i:new t(function(o){o(i)})}(u.value).then(c,l)}a((r=r.apply(s,e||[])).next())})};const y=new h.Logger(R);function Ie(s){return null==s?"null":(32!==(0,g.hexDataLength)(s)&&y.throwArgumentError("invalid topic","topic",s),s.toLowerCase())}function Le(s){for(s=s.slice();s.length>0&&null==s[s.length-1];)s.pop();return s.map(e=>{if(Array.isArray(e)){const t={};e.forEach(n=>{t[Ie(n)]=!0});const r=Object.keys(t);return r.sort(),r.join("|")}return Ie(e)}).join("&")}function D(s){if("string"==typeof s){if(s=s.toLowerCase(),32===(0,g.hexDataLength)(s))return"tx:"+s;if(-1===s.indexOf(":"))return s}else{if(Array.isArray(s))return"filter:*:"+Le(s);if(H.Sg.isForkEvent(s))throw y.warn("not implemented"),new Error("not implemented");if(s&&"object"==typeof s)return"filter:"+(s.address||"*")+":"+Le(s.topics||[])}throw new Error("invalid event - "+s)}function $(){return(new Date).getTime()}function Ae(s){return new Promise(e=>{setTimeout(e,s)})}const ct=["block","network","pending","poll"];class at{constructor(e,t,r){(0,d.defineReadOnly)(this,"tag",e),(0,d.defineReadOnly)(this,"listener",t),(0,d.defineReadOnly)(this,"once",r)}get event(){switch(this.type){case"tx":return this.hash;case"filter":return this.filter}return this.tag}get type(){return this.tag.split(":")[0]}get hash(){const e=this.tag.split(":");return"tx"!==e[0]?null:e[1]}get filter(){const e=this.tag.split(":");if("filter"!==e[0])return null;const t=e[1],r=""===(s=e[2])?[]:s.split(/&/g).map(e=>{if(""===e)return[];const t=e.split("|").map(r=>"null"===r?null:r);return 1===t.length?t[0]:t}),n={};var s;return r.length>0&&(n.topics=r),t&&"*"!==t&&(n.address=t),n}pollable(){return this.tag.indexOf(":")>=0||ct.indexOf(this.tag)>=0}}const ut={0:{symbol:"btc",p2pkh:0,p2sh:5,prefix:"bc"},2:{symbol:"ltc",p2pkh:48,p2sh:50,prefix:"ltc"},3:{symbol:"doge",p2pkh:30,p2sh:22},60:{symbol:"eth",ilk:"eth"},61:{symbol:"etc",ilk:"eth"},700:{symbol:"xdai",ilk:"eth"}};function fe(s){return(0,g.hexZeroPad)(b.O$.from(s).toHexString(),32)}function Se(s){return Re.Base58.encode((0,g.concat)([s,(0,g.hexDataSlice)((0,Pe.JQ)((0,Pe.JQ)(s)),0,4)]))}const Be=[new RegExp("^(https)://(.*)$","i"),new RegExp("^(data):(.*)$","i"),new RegExp("^(ipfs)://(.*)$","i"),new RegExp("^eip155:[0-9]+/(erc[0-9]+):(.*)$","i")];function ht(s){try{return(0,C.ZN)(Ce(s))}catch{}return null}function Ce(s){if("0x"===s)return null;const e=b.O$.from((0,g.hexDataSlice)(s,0,32)).toNumber(),t=b.O$.from((0,g.hexDataSlice)(s,e,e+32)).toNumber();return(0,g.hexDataSlice)(s,e+32,e+32+t)}class ge{constructor(e,t,r,n){(0,d.defineReadOnly)(this,"provider",e),(0,d.defineReadOnly)(this,"name",r),(0,d.defineReadOnly)(this,"address",e.formatter.address(t)),(0,d.defineReadOnly)(this,"_resolvedAddress",n)}_fetchBytes(e,t){return w(this,void 0,void 0,function*(){const r={to:this.address,data:(0,g.hexConcat)([e,(0,K.VM)(this.name),t||"0x"])};try{return Ce(yield this.provider.call(r))}catch(n){return null}})}_getAddress(e,t){const r=ut[String(e)];if(null==r&&y.throwError(`unsupported coin type: ${e}`,h.Logger.errors.UNSUPPORTED_OPERATION,{operation:`getAddress(${e})`}),"eth"===r.ilk)return this.provider.formatter.address(t);const n=(0,g.arrayify)(t);if(null!=r.p2pkh){const i=t.match(/^0x76a9([0-9a-f][0-9a-f])([0-9a-f]*)88ac$/);if(i){const o=parseInt(i[1],16);if(i[2].length===2*o&&o>=1&&o<=75)return Se((0,g.concat)([[r.p2pkh],"0x"+i[2]]))}}if(null!=r.p2sh){const i=t.match(/^0xa9([0-9a-f][0-9a-f])([0-9a-f]*)87$/);if(i){const o=parseInt(i[1],16);if(i[2].length===2*o&&o>=1&&o<=75)return Se((0,g.concat)([[r.p2sh],"0x"+i[2]]))}}if(null!=r.prefix){const i=n[1];let o=n[0];if(0===o?20!==i&&32!==i&&(o=-1):o=-1,o>=0&&n.length===2+i&&i>=1&&i<=75){const c=Te().toWords(n.slice(2));return c.unshift(o),Te().encode(r.prefix,c)}}return null}getAddress(e){return w(this,void 0,void 0,function*(){if(null==e&&(e=60),60===e)try{const n={to:this.address,data:"0x3b3b57de"+(0,K.VM)(this.name).substring(2)},i=yield this.provider.call(n);return"0x"===i||i===it.R?null:this.provider.formatter.callAddress(i)}catch(n){if(n.code===h.Logger.errors.CALL_EXCEPTION)return null;throw n}const t=yield this._fetchBytes("0xf1cb7e06",fe(e));if(null==t||"0x"===t)return null;const r=this._getAddress(e,t);return null==r&&y.throwError("invalid or unsupported coin data",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:`getAddress(${e})`,coinType:e,data:t}),r})}getAvatar(){return w(this,void 0,void 0,function*(){const e=[];try{const t=yield this.getText("avatar");if(null==t)return null;for(let r=0;r<Be.length;r++){const n=t.match(Be[r]);if(null!=n)switch(n[1]){case"https":return e.push({type:"url",content:t}),{linkage:e,url:t};case"data":return e.push({type:"data",content:t}),{linkage:e,url:t};case"ipfs":return e.push({type:"ipfs",content:t}),{linkage:e,url:`https://gateway.ipfs.io/ipfs/${t.substring(7)}`};case"erc721":case"erc1155":{const i="erc721"===n[1]?"0xc87b56dd":"0x0e89341c";e.push({type:n[1],content:t});const o=this._resolvedAddress||(yield this.getAddress()),c=(n[2]||"").split("/");if(2!==c.length)return null;const l=yield this.provider.formatter.address(c[0]),a=(0,g.hexZeroPad)(b.O$.from(c[1]).toHexString(),32);if("erc721"===n[1]){const p=this.provider.formatter.callAddress(yield this.provider.call({to:l,data:(0,g.hexConcat)(["0x6352211e",a])}));if(o!==p)return null;e.push({type:"owner",content:p})}else if("erc1155"===n[1]){const p=b.O$.from(yield this.provider.call({to:l,data:(0,g.hexConcat)(["0x00fdd58e",(0,g.hexZeroPad)(o,32),a])}));if(p.isZero())return null;e.push({type:"balance",content:p.toString()})}const u={to:this.provider.formatter.address(c[0]),data:(0,g.hexConcat)([i,a])};let m=ht(yield this.provider.call(u));if(null==m)return null;e.push({type:"metadata-url",content:m}),"erc1155"===n[1]&&(m=m.replace("{id}",a.substring(2)));const k=yield(0,x.fetchJson)(m);return k&&"string"==typeof k.image&&k.image.match(/^https:\/\//i)?(e.push({type:"metadata",content:JSON.stringify(k)}),e.push({type:"url",content:k.image}),{linkage:e,url:k.image}):null}}}}catch{}return null})}getContentHash(){return w(this,void 0,void 0,function*(){const e=yield this._fetchBytes("0xbc1c58d1");if(null==e||"0x"===e)return null;const t=e.match(/^0xe3010170(([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f]*))$/);if(t){const n=parseInt(t[3],16);if(t[4].length===2*n)return"ipfs://"+Re.Base58.encode("0x"+t[1])}const r=e.match(/^0xe40101fa011b20([0-9a-f]*)$/);return r&&64===r[1].length?"bzz://"+r[1]:y.throwError("invalid or unsupported content hash data",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"getContentHash()",data:e})})}getText(e){return w(this,void 0,void 0,function*(){let t=(0,C.Y0)(e);t=(0,g.concat)([fe(64),fe(t.length),t]),t.length%32!=0&&(t=(0,g.concat)([t,(0,g.hexZeroPad)("0x",32-e.length%32)]));const r=yield this._fetchBytes("0x59d1d43c",(0,g.hexlify)(t));return null==r||"0x"===r?null:(0,C.ZN)(r)})}}let pe=null,dt=1;class Q extends H.zt{constructor(e){if(y.checkNew(new.target,H.zt),super(),this._events=[],this._emitted={block:-2},this.formatter=new.target.getFormatter(),(0,d.defineReadOnly)(this,"anyNetwork","any"===e),this.anyNetwork&&(e=this.detectNetwork()),e instanceof Promise)this._networkPromise=e,e.catch(t=>{}),this._ready().catch(t=>{});else{const t=(0,d.getStatic)(new.target,"getNetwork")(e);t?((0,d.defineReadOnly)(this,"_network",t),this.emit("network",t,null)):y.throwArgumentError("invalid network","network",e)}this._maxInternalBlockNumber=-1024,this._lastBlockNumber=-2,this._pollingInterval=4e3,this._fastQueryDate=0}_ready(){return w(this,void 0,void 0,function*(){if(null==this._network){let e=null;if(this._networkPromise)try{e=yield this._networkPromise}catch{}null==e&&(e=yield this.detectNetwork()),e||y.throwError("no network detected",h.Logger.errors.UNKNOWN_ERROR,{}),null==this._network&&(this.anyNetwork?this._network=e:(0,d.defineReadOnly)(this,"_network",e),this.emit("network",e,null))}return this._network})}get ready(){return(0,x.poll)(()=>this._ready().then(e=>e,e=>{if(e.code!==h.Logger.errors.NETWORK_ERROR||"noNetwork"!==e.event)throw e}))}static getFormatter(){return null==pe&&(pe=new f),pe}static getNetwork(e){return(0,ue.H)(e??"homestead")}_getInternalBlockNumber(e){return w(this,void 0,void 0,function*(){if(yield this._ready(),e>0)for(;this._internalBlockNumber;){const n=this._internalBlockNumber;try{const i=yield n;if($()-i.respTime<=e)return i.blockNumber;break}catch{if(this._internalBlockNumber===n)break}}const t=$(),r=(0,d.resolveProperties)({blockNumber:this.perform("getBlockNumber",{}),networkError:this.getNetwork().then(n=>null,n=>n)}).then(({blockNumber:n,networkError:i})=>{if(i)throw this._internalBlockNumber===r&&(this._internalBlockNumber=null),i;const o=$();return(n=b.O$.from(n).toNumber())<this._maxInternalBlockNumber&&(n=this._maxInternalBlockNumber),this._maxInternalBlockNumber=n,this._setFastBlockNumber(n),{blockNumber:n,reqTime:t,respTime:o}});return this._internalBlockNumber=r,r.catch(n=>{this._internalBlockNumber===r&&(this._internalBlockNumber=null)}),(yield r).blockNumber})}poll(){return w(this,void 0,void 0,function*(){const e=dt++,t=[];let r=null;try{r=yield this._getInternalBlockNumber(100+this.pollingInterval/2)}catch(n){return void this.emit("error",n)}if(this._setFastBlockNumber(r),this.emit("poll",e,r),r!==this._lastBlockNumber){if(-2===this._emitted.block&&(this._emitted.block=r-1),Math.abs(this._emitted.block-r)>1e3)y.warn(`network block skew detected; skipping block events (emitted=${this._emitted.block} blockNumber${r})`),this.emit("error",y.makeError("network block skew detected",h.Logger.errors.NETWORK_ERROR,{blockNumber:r,event:"blockSkew",previousBlockNumber:this._emitted.block})),this.emit("block",r);else for(let n=this._emitted.block+1;n<=r;n++)this.emit("block",n);this._emitted.block!==r&&(this._emitted.block=r,Object.keys(this._emitted).forEach(n=>{if("block"===n)return;const i=this._emitted[n];"pending"!==i&&r-i>12&&delete this._emitted[n]})),-2===this._lastBlockNumber&&(this._lastBlockNumber=r-1),this._events.forEach(n=>{switch(n.type){case"tx":{const i=n.hash;let o=this.getTransactionReceipt(i).then(c=>(!c||null==c.blockNumber||(this._emitted["t:"+i]=c.blockNumber,this.emit(i,c)),null)).catch(c=>{this.emit("error",c)});t.push(o);break}case"filter":{const i=n.filter;i.fromBlock=this._lastBlockNumber+1,i.toBlock=r;const o=this.getLogs(i).then(c=>{0!==c.length&&c.forEach(l=>{this._emitted["b:"+l.blockHash]=l.blockNumber,this._emitted["t:"+l.transactionHash]=l.blockNumber,this.emit(i,l)})}).catch(c=>{this.emit("error",c)});t.push(o);break}}}),this._lastBlockNumber=r,Promise.all(t).then(()=>{this.emit("didPoll",e)}).catch(n=>{this.emit("error",n)})}else this.emit("didPoll",e)})}resetEventsBlock(e){this._lastBlockNumber=e-1,this.polling&&this.poll()}get network(){return this._network}detectNetwork(){return w(this,void 0,void 0,function*(){return y.throwError("provider does not support network detection",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"provider.detectNetwork"})})}getNetwork(){return w(this,void 0,void 0,function*(){const e=yield this._ready(),t=yield this.detectNetwork();if(e.chainId!==t.chainId){if(this.anyNetwork)return this._network=t,this._lastBlockNumber=-2,this._fastBlockNumber=null,this._fastBlockNumberPromise=null,this._fastQueryDate=0,this._emitted.block=-2,this._maxInternalBlockNumber=-1024,this._internalBlockNumber=null,this.emit("network",t,e),yield Ae(0),this._network;const r=y.makeError("underlying network changed",h.Logger.errors.NETWORK_ERROR,{event:"changed",network:e,detectedNetwork:t});throw this.emit("error",r),r}return e})}get blockNumber(){return this._getInternalBlockNumber(100+this.pollingInterval/2).then(e=>{this._setFastBlockNumber(e)},e=>{}),null!=this._fastBlockNumber?this._fastBlockNumber:-1}get polling(){return null!=this._poller}set polling(e){e&&!this._poller?(this._poller=setInterval(()=>{this.poll()},this.pollingInterval),this._bootstrapPoll||(this._bootstrapPoll=setTimeout(()=>{this.poll(),this._bootstrapPoll=setTimeout(()=>{this._poller||this.poll(),this._bootstrapPoll=null},this.pollingInterval)},0))):!e&&this._poller&&(clearInterval(this._poller),this._poller=null)}get pollingInterval(){return this._pollingInterval}set pollingInterval(e){if("number"!=typeof e||e<=0||parseInt(String(e))!=e)throw new Error("invalid polling interval");this._pollingInterval=e,this._poller&&(clearInterval(this._poller),this._poller=setInterval(()=>{this.poll()},this._pollingInterval))}_getFastBlockNumber(){const e=$();return e-this._fastQueryDate>2*this._pollingInterval&&(this._fastQueryDate=e,this._fastBlockNumberPromise=this.getBlockNumber().then(t=>((null==this._fastBlockNumber||t>this._fastBlockNumber)&&(this._fastBlockNumber=t),this._fastBlockNumber))),this._fastBlockNumberPromise}_setFastBlockNumber(e){null!=this._fastBlockNumber&&e<this._fastBlockNumber||(this._fastQueryDate=$(),(null==this._fastBlockNumber||e>this._fastBlockNumber)&&(this._fastBlockNumber=e,this._fastBlockNumberPromise=Promise.resolve(e)))}waitForTransaction(e,t,r){return w(this,void 0,void 0,function*(){return this._waitForTransaction(e,t??1,r||0,null)})}_waitForTransaction(e,t,r,n){return w(this,void 0,void 0,function*(){const i=yield this.getTransactionReceipt(e);return(i?i.confirmations:0)>=t?i:new Promise((o,c)=>{const l=[];let a=!1;const u=function(){return!!a||(a=!0,l.forEach(k=>{k()}),!1)},m=k=>{k.confirmations<t||u()||o(k)};if(this.on(e,m),l.push(()=>{this.removeListener(e,m)}),n){let k=n.startBlock,p=null;const v=_=>w(this,void 0,void 0,function*(){a||(yield Ae(1e3),this.getTransactionCount(n.from).then(V=>w(this,void 0,void 0,function*(){if(!a){if(V<=n.nonce)k=_;else{{const P=yield this.getTransaction(e);if(P&&null!=P.blockNumber)return}for(null==p&&(p=k-3,p<n.startBlock&&(p=n.startBlock));p<=_;){if(a)return;const P=yield this.getBlockWithTransactions(p);for(let Ee=0;Ee<P.transactions.length;Ee++){const T=P.transactions[Ee];if(T.hash===e)return;if(T.from===n.from&&T.nonce===n.nonce){if(a)return;const Bt=yield this.waitForTransaction(T.hash,t);if(u())return;let z="replaced";return T.data===n.data&&T.to===n.to&&T.value.eq(n.value)?z="repriced":"0x"===T.data&&T.from===T.to&&T.value.isZero()&&(z="cancelled"),void c(y.makeError("transaction was replaced",h.Logger.errors.TRANSACTION_REPLACED,{cancelled:"replaced"===z||"cancelled"===z,reason:z,replacement:this._wrapTransaction(T),hash:e,receipt:Bt}))}}p++}}a||this.once("block",v)}}),V=>{a||this.once("block",v)}))});if(a)return;this.once("block",v),l.push(()=>{this.removeListener("block",v)})}if("number"==typeof r&&r>0){const k=setTimeout(()=>{u()||c(y.makeError("timeout exceeded",h.Logger.errors.TIMEOUT,{timeout:r}))},r);k.unref&&k.unref(),l.push(()=>{clearTimeout(k)})}})})}getBlockNumber(){return w(this,void 0,void 0,function*(){return this._getInternalBlockNumber(0)})}getGasPrice(){return w(this,void 0,void 0,function*(){yield this.getNetwork();const e=yield this.perform("getGasPrice",{});try{return b.O$.from(e)}catch(t){return y.throwError("bad result from backend",h.Logger.errors.SERVER_ERROR,{method:"getGasPrice",result:e,error:t})}})}getBalance(e,t){return w(this,void 0,void 0,function*(){yield this.getNetwork();const r=yield(0,d.resolveProperties)({address:this._getAddress(e),blockTag:this._getBlockTag(t)}),n=yield this.perform("getBalance",r);try{return b.O$.from(n)}catch(i){return y.throwError("bad result from backend",h.Logger.errors.SERVER_ERROR,{method:"getBalance",params:r,result:n,error:i})}})}getTransactionCount(e,t){return w(this,void 0,void 0,function*(){yield this.getNetwork();const r=yield(0,d.resolveProperties)({address:this._getAddress(e),blockTag:this._getBlockTag(t)}),n=yield this.perform("getTransactionCount",r);try{return b.O$.from(n).toNumber()}catch(i){return y.throwError("bad result from backend",h.Logger.errors.SERVER_ERROR,{method:"getTransactionCount",params:r,result:n,error:i})}})}getCode(e,t){return w(this,void 0,void 0,function*(){yield this.getNetwork();const r=yield(0,d.resolveProperties)({address:this._getAddress(e),blockTag:this._getBlockTag(t)}),n=yield this.perform("getCode",r);try{return(0,g.hexlify)(n)}catch(i){return y.throwError("bad result from backend",h.Logger.errors.SERVER_ERROR,{method:"getCode",params:r,result:n,error:i})}})}getStorageAt(e,t,r){return w(this,void 0,void 0,function*(){yield this.getNetwork();const n=yield(0,d.resolveProperties)({address:this._getAddress(e),blockTag:this._getBlockTag(r),position:Promise.resolve(t).then(o=>(0,g.hexValue)(o))}),i=yield this.perform("getStorageAt",n);try{return(0,g.hexlify)(i)}catch(o){return y.throwError("bad result from backend",h.Logger.errors.SERVER_ERROR,{method:"getStorageAt",params:n,result:i,error:o})}})}_wrapTransaction(e,t,r){if(null!=t&&32!==(0,g.hexDataLength)(t))throw new Error("invalid response - sendTransaction");const n=e;return null!=t&&e.hash!==t&&y.throwError("Transaction hash mismatch from Provider.sendTransaction.",h.Logger.errors.UNKNOWN_ERROR,{expectedHash:e.hash,returnedHash:t}),n.wait=(i,o)=>w(this,void 0,void 0,function*(){let c;null==i&&(i=1),null==o&&(o=0),0!==i&&null!=r&&(c={data:e.data,from:e.from,nonce:e.nonce,to:e.to,value:e.value,startBlock:r});const l=yield this._waitForTransaction(e.hash,i,o,c);return null==l&&0===i?null:(this._emitted["t:"+e.hash]=l.blockNumber,0===l.status&&y.throwError("transaction failed",h.Logger.errors.CALL_EXCEPTION,{transactionHash:e.hash,transaction:e,receipt:l}),l)}),n}sendTransaction(e){return w(this,void 0,void 0,function*(){yield this.getNetwork();const t=yield Promise.resolve(e).then(i=>(0,g.hexlify)(i)),r=this.formatter.transaction(e);null==r.confirmations&&(r.confirmations=0);const n=yield this._getInternalBlockNumber(100+2*this.pollingInterval);try{const i=yield this.perform("sendTransaction",{signedTransaction:t});return this._wrapTransaction(r,i,n)}catch(i){throw i.transaction=r,i.transactionHash=r.hash,i}})}_getTransactionRequest(e){return w(this,void 0,void 0,function*(){const t=yield e,r={};return["from","to"].forEach(n=>{null!=t[n]&&(r[n]=Promise.resolve(t[n]).then(i=>i?this._getAddress(i):null))}),["gasLimit","gasPrice","maxFeePerGas","maxPriorityFeePerGas","value"].forEach(n=>{null!=t[n]&&(r[n]=Promise.resolve(t[n]).then(i=>i?b.O$.from(i):null))}),["type"].forEach(n=>{null!=t[n]&&(r[n]=Promise.resolve(t[n]).then(i=>i??null))}),t.accessList&&(r.accessList=this.formatter.accessList(t.accessList)),["data"].forEach(n=>{null!=t[n]&&(r[n]=Promise.resolve(t[n]).then(i=>i?(0,g.hexlify)(i):null))}),this.formatter.transactionRequest(yield(0,d.resolveProperties)(r))})}_getFilter(e){return w(this,void 0,void 0,function*(){e=yield e;const t={};return null!=e.address&&(t.address=this._getAddress(e.address)),["blockHash","topics"].forEach(r=>{null!=e[r]&&(t[r]=e[r])}),["fromBlock","toBlock"].forEach(r=>{null!=e[r]&&(t[r]=this._getBlockTag(e[r]))}),this.formatter.filter(yield(0,d.resolveProperties)(t))})}call(e,t){return w(this,void 0,void 0,function*(){yield this.getNetwork();const r=yield(0,d.resolveProperties)({transaction:this._getTransactionRequest(e),blockTag:this._getBlockTag(t)}),n=yield this.perform("call",r);try{return(0,g.hexlify)(n)}catch(i){return y.throwError("bad result from backend",h.Logger.errors.SERVER_ERROR,{method:"call",params:r,result:n,error:i})}})}estimateGas(e){return w(this,void 0,void 0,function*(){yield this.getNetwork();const t=yield(0,d.resolveProperties)({transaction:this._getTransactionRequest(e)}),r=yield this.perform("estimateGas",t);try{return b.O$.from(r)}catch(n){return y.throwError("bad result from backend",h.Logger.errors.SERVER_ERROR,{method:"estimateGas",params:t,result:r,error:n})}})}_getAddress(e){return w(this,void 0,void 0,function*(){"string"!=typeof(e=yield e)&&y.throwArgumentError("invalid address or ENS name","name",e);const t=yield this.resolveName(e);return null==t&&y.throwError("ENS name not configured",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:`resolveName(${JSON.stringify(e)})`}),t})}_getBlock(e,t){return w(this,void 0,void 0,function*(){yield this.getNetwork(),e=yield e;let r=-128;const n={includeTransactions:!!t};if((0,g.isHexString)(e,32))n.blockHash=e;else try{n.blockTag=yield this._getBlockTag(e),(0,g.isHexString)(n.blockTag)&&(r=parseInt(n.blockTag.substring(2),16))}catch{y.throwArgumentError("invalid block hash or block tag","blockHashOrBlockTag",e)}return(0,x.poll)(()=>w(this,void 0,void 0,function*(){const i=yield this.perform("getBlock",n);if(null==i)return null!=n.blockHash&&null==this._emitted["b:"+n.blockHash]||null!=n.blockTag&&r>this._emitted.block?null:void 0;if(t){let o=null;for(let l=0;l<i.transactions.length;l++){const a=i.transactions[l];if(null==a.blockNumber)a.confirmations=0;else if(null==a.confirmations){null==o&&(o=yield this._getInternalBlockNumber(100+2*this.pollingInterval));let u=o-a.blockNumber+1;u<=0&&(u=1),a.confirmations=u}}const c=this.formatter.blockWithTransactions(i);return c.transactions=c.transactions.map(l=>this._wrapTransaction(l)),c}return this.formatter.block(i)}),{oncePoll:this})})}getBlock(e){return this._getBlock(e,!1)}getBlockWithTransactions(e){return this._getBlock(e,!0)}getTransaction(e){return w(this,void 0,void 0,function*(){yield this.getNetwork(),e=yield e;const t={transactionHash:this.formatter.hash(e,!0)};return(0,x.poll)(()=>w(this,void 0,void 0,function*(){const r=yield this.perform("getTransaction",t);if(null==r)return null==this._emitted["t:"+e]?null:void 0;const n=this.formatter.transactionResponse(r);if(null==n.blockNumber)n.confirmations=0;else if(null==n.confirmations){let o=(yield this._getInternalBlockNumber(100+2*this.pollingInterval))-n.blockNumber+1;o<=0&&(o=1),n.confirmations=o}return this._wrapTransaction(n)}),{oncePoll:this})})}getTransactionReceipt(e){return w(this,void 0,void 0,function*(){yield this.getNetwork(),e=yield e;const t={transactionHash:this.formatter.hash(e,!0)};return(0,x.poll)(()=>w(this,void 0,void 0,function*(){const r=yield this.perform("getTransactionReceipt",t);if(null==r)return null==this._emitted["t:"+e]?null:void 0;if(null==r.blockHash)return;const n=this.formatter.receipt(r);if(null==n.blockNumber)n.confirmations=0;else if(null==n.confirmations){let o=(yield this._getInternalBlockNumber(100+2*this.pollingInterval))-n.blockNumber+1;o<=0&&(o=1),n.confirmations=o}return n}),{oncePoll:this})})}getLogs(e){return w(this,void 0,void 0,function*(){yield this.getNetwork();const t=yield(0,d.resolveProperties)({filter:this._getFilter(e)}),r=yield this.perform("getLogs",t);return r.forEach(n=>{null==n.removed&&(n.removed=!1)}),f.arrayOf(this.formatter.filterLog.bind(this.formatter))(r)})}getEtherPrice(){return w(this,void 0,void 0,function*(){return yield this.getNetwork(),this.perform("getEtherPrice",{})})}_getBlockTag(e){return w(this,void 0,void 0,function*(){if("number"==typeof(e=yield e)&&e<0){e%1&&y.throwArgumentError("invalid BlockTag","blockTag",e);let t=yield this._getInternalBlockNumber(100+2*this.pollingInterval);return t+=e,t<0&&(t=0),this.formatter.blockTag(t)}return this.formatter.blockTag(e)})}getResolver(e){return w(this,void 0,void 0,function*(){try{const t=yield this._getResolver(e);return null==t?null:new ge(this,t,e)}catch(t){return null}})}_getResolver(e){return w(this,void 0,void 0,function*(){const t=yield this.getNetwork();t.ensAddress||y.throwError("network does not support ENS",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"ENS",network:t.name});const r={to:t.ensAddress,data:"0x0178b8bf"+(0,K.VM)(e).substring(2)};try{return this.formatter.callAddress(yield this.call(r))}catch(n){if(n.code===h.Logger.errors.CALL_EXCEPTION)return null;throw n}})}resolveName(e){return w(this,void 0,void 0,function*(){e=yield e;try{return Promise.resolve(this.formatter.address(e))}catch(r){if((0,g.isHexString)(e))throw r}"string"!=typeof e&&y.throwArgumentError("invalid ENS name","name",e);const t=yield this.getResolver(e);return t?yield t.getAddress():null})}lookupAddress(e){return w(this,void 0,void 0,function*(){e=yield e;const t=(e=this.formatter.address(e)).substring(2).toLowerCase()+".addr.reverse",r=yield this._getResolver(t);if(!r)return null;let n=(0,g.arrayify)(yield this.call({to:r,data:"0x691f3431"+(0,K.VM)(t).substring(2)}));if(n.length<32||!b.O$.from(n.slice(0,32)).eq(32)||(n=n.slice(32),n.length<32))return null;const i=b.O$.from(n.slice(0,32)).toNumber();if(n=n.slice(32),i>n.length)return null;const o=(0,C.ZN)(n.slice(0,i));return(yield this.resolveName(o))!=e?null:o})}getAvatar(e){return w(this,void 0,void 0,function*(){let t=null;if((0,g.isHexString)(e)){const n=this.formatter.address(e),i=n.substring(2).toLowerCase()+".addr.reverse",o=yield this._getResolver(i);if(!o)return null;t=new ge(this,o,"_",n)}else t=yield this.getResolver(e);const r=yield t.getAvatar();return null==r?null:r.url})}perform(e,t){return y.throwError(e+" not implemented",h.Logger.errors.NOT_IMPLEMENTED,{operation:e})}_startEvent(e){this.polling=this._events.filter(t=>t.pollable()).length>0}_stopEvent(e){this.polling=this._events.filter(t=>t.pollable()).length>0}_addEventListener(e,t,r){const n=new at(D(e),t,r);return this._events.push(n),this._startEvent(n),this}on(e,t){return this._addEventListener(e,t,!1)}once(e,t){return this._addEventListener(e,t,!0)}emit(e,...t){let r=!1,n=[],i=D(e);return this._events=this._events.filter(o=>o.tag!==i||(setTimeout(()=>{o.listener.apply(this,t)},0),r=!0,!o.once||(n.push(o),!1))),n.forEach(o=>{this._stopEvent(o)}),r}listenerCount(e){if(!e)return this._events.length;let t=D(e);return this._events.filter(r=>r.tag===t).length}listeners(e){if(null==e)return this._events.map(r=>r.listener);let t=D(e);return this._events.filter(r=>r.tag===t).map(r=>r.listener)}off(e,t){if(null==t)return this.removeAllListeners(e);const r=[];let n=!1,i=D(e);return this._events=this._events.filter(o=>!(o.tag===i&&o.listener==t&&!n&&(n=!0,r.push(o),1))),r.forEach(o=>{this._stopEvent(o)}),this}removeAllListeners(e){let t=[];if(null==e)t=this._events,this._events=[];else{const r=D(e);this._events=this._events.filter(n=>n.tag!==r||(t.push(n),!1))}return t.forEach(r=>{this._stopEvent(r)}),this}}var ft=N(11221),Ue=N(72072),O=function(s,e,t,r){return new(t||(t=Promise))(function(i,o){function c(u){try{a(r.next(u))}catch(m){o(m)}}function l(u){try{a(r.throw(u))}catch(m){o(m)}}function a(u){u.done?i(u.value):function(i){return i instanceof t?i:new t(function(o){o(i)})}(u.value).then(c,l)}a((r=r.apply(s,e||[])).next())})};const E=new h.Logger(R),gt=["call","estimateGas"];function De(s,e,t){if("call"===s&&e.code===h.Logger.errors.SERVER_ERROR){const i=e.error;if(i&&i.message.match("reverted")&&(0,g.isHexString)(i.data))return i.data;E.throwError("missing revert data in call exception",h.Logger.errors.CALL_EXCEPTION,{error:e,data:"0x"})}let r=e.message;e.code===h.Logger.errors.SERVER_ERROR&&e.error&&"string"==typeof e.error.message?r=e.error.message:"string"==typeof e.body?r=e.body:"string"==typeof e.responseText&&(r=e.responseText),r=(r||"").toLowerCase();const n=t.transaction||t.signedTransaction;throw r.match(/insufficient funds|base fee exceeds gas limit/)&&E.throwError("insufficient funds for intrinsic transaction cost",h.Logger.errors.INSUFFICIENT_FUNDS,{error:e,method:s,transaction:n}),r.match(/nonce too low/)&&E.throwError("nonce has already been used",h.Logger.errors.NONCE_EXPIRED,{error:e,method:s,transaction:n}),r.match(/replacement transaction underpriced/)&&E.throwError("replacement fee too low",h.Logger.errors.REPLACEMENT_UNDERPRICED,{error:e,method:s,transaction:n}),r.match(/only replay-protected/)&&E.throwError("legacy pre-eip-155 transactions not supported",h.Logger.errors.UNSUPPORTED_OPERATION,{error:e,method:s,transaction:n}),gt.indexOf(s)>=0&&r.match(/gas required exceeds allowance|always failing transaction|execution reverted/)&&E.throwError("cannot estimate gas; transaction may fail or may require manual gas limit",h.Logger.errors.UNPREDICTABLE_GAS_LIMIT,{error:e,method:s,transaction:n}),e}function je(s){return new Promise(function(e){setTimeout(e,s)})}function pt(s){if(s.error){const e=new Error(s.error.message);throw e.code=s.error.code,e.data=s.error.data,e}return s.result}function G(s){return s&&s.toLowerCase()}const me={};class q extends ft.Signer{constructor(e,t,r){if(E.checkNew(new.target,q),super(),e!==me)throw new Error("do not call the JsonRpcSigner constructor directly; use provider.getSigner");(0,d.defineReadOnly)(this,"provider",t),null==r&&(r=0),"string"==typeof r?((0,d.defineReadOnly)(this,"_address",this.provider.formatter.address(r)),(0,d.defineReadOnly)(this,"_index",null)):"number"==typeof r?((0,d.defineReadOnly)(this,"_index",r),(0,d.defineReadOnly)(this,"_address",null)):E.throwArgumentError("invalid address or index","addressOrIndex",r)}connect(e){return E.throwError("cannot alter JSON-RPC Signer connection",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"connect"})}connectUnchecked(){return new mt(me,this.provider,this._address||this._index)}getAddress(){return this._address?Promise.resolve(this._address):this.provider.send("eth_accounts",[]).then(e=>(e.length<=this._index&&E.throwError("unknown account #"+this._index,h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"getAddress"}),this.provider.formatter.address(e[this._index])))}sendUncheckedTransaction(e){e=(0,d.shallowCopy)(e);const t=this.getAddress().then(r=>(r&&(r=r.toLowerCase()),r));if(null==e.gasLimit){const r=(0,d.shallowCopy)(e);r.from=t,e.gasLimit=this.provider.estimateGas(r)}return null!=e.to&&(e.to=Promise.resolve(e.to).then(r=>O(this,void 0,void 0,function*(){if(null==r)return null;const n=yield this.provider.resolveName(r);return null==n&&E.throwArgumentError("provided ENS name resolves to null","tx.to",r),n}))),(0,d.resolveProperties)({tx:(0,d.resolveProperties)(e),sender:t}).then(({tx:r,sender:n})=>{null!=r.from?r.from.toLowerCase()!==n&&E.throwArgumentError("from address mismatch","transaction",e):r.from=n;const i=this.provider.constructor.hexlifyTransaction(r,{from:!0});return this.provider.send("eth_sendTransaction",[i]).then(o=>o,o=>De("sendTransaction",o,i))})}signTransaction(e){return E.throwError("signing transactions is unsupported",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"signTransaction"})}sendTransaction(e){return O(this,void 0,void 0,function*(){const t=yield this.provider._getInternalBlockNumber(100+2*this.provider.pollingInterval),r=yield this.sendUncheckedTransaction(e);try{return yield(0,x.poll)(()=>O(this,void 0,void 0,function*(){const n=yield this.provider.getTransaction(r);if(null!==n)return this.provider._wrapTransaction(n,r,t)}),{oncePoll:this.provider})}catch(n){throw n.transactionHash=r,n}})}signMessage(e){return O(this,void 0,void 0,function*(){const t="string"==typeof e?(0,C.Y0)(e):e,r=yield this.getAddress();return yield this.provider.send("personal_sign",[(0,g.hexlify)(t),r.toLowerCase()])})}_legacySignMessage(e){return O(this,void 0,void 0,function*(){const t="string"==typeof e?(0,C.Y0)(e):e,r=yield this.getAddress();return yield this.provider.send("eth_sign",[r.toLowerCase(),(0,g.hexlify)(t)])})}_signTypedData(e,t,r){return O(this,void 0,void 0,function*(){const n=yield Ue.E.resolveNames(e,t,r,o=>this.provider.resolveName(o)),i=yield this.getAddress();return yield this.provider.send("eth_signTypedData_v4",[i.toLowerCase(),JSON.stringify(Ue.E.getPayload(n.domain,t,n.value))])})}unlock(e){return O(this,void 0,void 0,function*(){const t=this.provider,r=yield this.getAddress();return t.send("personal_unlockAccount",[r.toLowerCase(),e,null])})}}class mt extends q{sendTransaction(e){return this.sendUncheckedTransaction(e).then(t=>({hash:t,nonce:null,gasLimit:null,gasPrice:null,data:null,value:null,chainId:null,confirmations:0,from:null,wait:r=>this.provider.waitForTransaction(t,r)}))}}const wt={chainId:!0,data:!0,gasLimit:!0,gasPrice:!0,nonce:!0,to:!0,value:!0,type:!0,accessList:!0,maxFeePerGas:!0,maxPriorityFeePerGas:!0};class I extends Q{constructor(e,t){E.checkNew(new.target,I);let r=t;null==r&&(r=new Promise((n,i)=>{setTimeout(()=>{this.detectNetwork().then(o=>{n(o)},o=>{i(o)})},0)})),super(r),e||(e=(0,d.getStatic)(this.constructor,"defaultUrl")()),(0,d.defineReadOnly)(this,"connection",Object.freeze("string"==typeof e?{url:e}:(0,d.shallowCopy)(e))),this._nextId=42}get _cache(){return null==this._eventLoopCache&&(this._eventLoopCache={}),this._eventLoopCache}static defaultUrl(){return"http://localhost:8545"}detectNetwork(){return this._cache.detectNetwork||(this._cache.detectNetwork=this._uncachedDetectNetwork(),setTimeout(()=>{this._cache.detectNetwork=null},0)),this._cache.detectNetwork}_uncachedDetectNetwork(){return O(this,void 0,void 0,function*(){yield je(0);let e=null;try{e=yield this.send("eth_chainId",[])}catch{try{e=yield this.send("net_version",[])}catch{}}if(null!=e){const t=(0,d.getStatic)(this.constructor,"getNetwork");try{return t(b.O$.from(e).toNumber())}catch(r){return E.throwError("could not detect network",h.Logger.errors.NETWORK_ERROR,{chainId:e,event:"invalidNetwork",serverError:r})}}return E.throwError("could not detect network",h.Logger.errors.NETWORK_ERROR,{event:"noNetwork"})})}getSigner(e){return new q(me,this,e)}getUncheckedSigner(e){return this.getSigner(e).connectUnchecked()}listAccounts(){return this.send("eth_accounts",[]).then(e=>e.map(t=>this.formatter.address(t)))}send(e,t){const r={method:e,params:t,id:this._nextId++,jsonrpc:"2.0"};this.emit("debug",{action:"request",request:(0,d.deepCopy)(r),provider:this});const n=["eth_chainId","eth_blockNumber"].indexOf(e)>=0;if(n&&this._cache[e])return this._cache[e];const i=(0,x.fetchJson)(this.connection,JSON.stringify(r),pt).then(o=>(this.emit("debug",{action:"response",request:r,response:o,provider:this}),o),o=>{throw this.emit("debug",{action:"response",error:o,request:r,provider:this}),o});return n&&(this._cache[e]=i,setTimeout(()=>{this._cache[e]=null},0)),i}prepareRequest(e,t){switch(e){case"getBlockNumber":return["eth_blockNumber",[]];case"getGasPrice":return["eth_gasPrice",[]];case"getBalance":return["eth_getBalance",[G(t.address),t.blockTag]];case"getTransactionCount":return["eth_getTransactionCount",[G(t.address),t.blockTag]];case"getCode":return["eth_getCode",[G(t.address),t.blockTag]];case"getStorageAt":return["eth_getStorageAt",[G(t.address),t.position,t.blockTag]];case"sendTransaction":return["eth_sendRawTransaction",[t.signedTransaction]];case"getBlock":return t.blockTag?["eth_getBlockByNumber",[t.blockTag,!!t.includeTransactions]]:t.blockHash?["eth_getBlockByHash",[t.blockHash,!!t.includeTransactions]]:null;case"getTransaction":return["eth_getTransactionByHash",[t.transactionHash]];case"getTransactionReceipt":return["eth_getTransactionReceipt",[t.transactionHash]];case"call":return["eth_call",[(0,d.getStatic)(this.constructor,"hexlifyTransaction")(t.transaction,{from:!0}),t.blockTag]];case"estimateGas":return["eth_estimateGas",[(0,d.getStatic)(this.constructor,"hexlifyTransaction")(t.transaction,{from:!0})]];case"getLogs":return t.filter&&null!=t.filter.address&&(t.filter.address=G(t.filter.address)),["eth_getLogs",[t.filter]]}return null}perform(e,t){return O(this,void 0,void 0,function*(){if("call"===e||"estimateGas"===e){const n=t.transaction;if(n&&null!=n.type&&b.O$.from(n.type).isZero()&&null==n.maxFeePerGas&&null==n.maxPriorityFeePerGas){const i=yield this.getFeeData();null==i.maxFeePerGas&&null==i.maxPriorityFeePerGas&&((t=(0,d.shallowCopy)(t)).transaction=(0,d.shallowCopy)(n),delete t.transaction.type)}}const r=this.prepareRequest(e,t);null==r&&E.throwError(e+" not implemented",h.Logger.errors.NOT_IMPLEMENTED,{operation:e});try{return yield this.send(r[0],r[1])}catch(n){return De(e,n,t)}})}_startEvent(e){"pending"===e.tag&&this._startPending(),super._startEvent(e)}_startPending(){if(null!=this._pendingFilter)return;const e=this,t=this.send("eth_newPendingTransactionFilter",[]);this._pendingFilter=t,t.then(function(r){return function n(){e.send("eth_getFilterChanges",[r]).then(function(i){if(e._pendingFilter!=t)return null;let o=Promise.resolve();return i.forEach(function(c){e._emitted["t:"+c.toLowerCase()]="pending",o=o.then(function(){return e.getTransaction(c).then(function(l){return e.emit("pending",l),null})})}),o.then(function(){return je(1e3)})}).then(function(){if(e._pendingFilter==t)return setTimeout(function(){n()},0),null;e.send("eth_uninstallFilter",[r])}).catch(i=>{})}(),r}).catch(r=>{})}_stopEvent(e){"pending"===e.tag&&0===this.listenerCount("pending")&&(this._pendingFilter=null),super._stopEvent(e)}static hexlifyTransaction(e,t){const r=(0,d.shallowCopy)(wt);if(t)for(const i in t)t[i]&&(r[i]=!0);(0,d.checkProperties)(e,r);const n={};return["gasLimit","gasPrice","type","maxFeePerGas","maxPriorityFeePerGas","nonce","value"].forEach(function(i){if(null==e[i])return;const o=(0,g.hexValue)(e[i]);"gasLimit"===i&&(i="gas"),n[i]=o}),["from","to","data"].forEach(function(i){null!=e[i]&&(n[i]=(0,g.hexlify)(e[i]))}),e.accessList&&(n.accessList=(0,Z.accessListify)(e.accessList)),n}}let W=null;try{if(W=WebSocket,null==W)throw new Error("inject please")}catch{const e=new h.Logger(R);W=function(){e.throwError("WebSockets not supported in this environment",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"new WebSocket()"})}}var we=function(s,e,t,r){return new(t||(t=Promise))(function(i,o){function c(u){try{a(r.next(u))}catch(m){o(m)}}function l(u){try{a(r.throw(u))}catch(m){o(m)}}function a(u){u.done?i(u.value):function(i){return i instanceof t?i:new t(function(o){o(i)})}(u.value).then(c,l)}a((r=r.apply(s,e||[])).next())})};const Y=new h.Logger(R);let yt=1;class ee extends I{constructor(e,t){"any"===t&&Y.throwError("WebSocketProvider does not support 'any' network yet",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"network:any"}),super(e,t),this._pollingInterval=-1,this._wsReady=!1,(0,d.defineReadOnly)(this,"_websocket",new W(this.connection.url)),(0,d.defineReadOnly)(this,"_requests",{}),(0,d.defineReadOnly)(this,"_subs",{}),(0,d.defineReadOnly)(this,"_subIds",{}),(0,d.defineReadOnly)(this,"_detectNetwork",super.detectNetwork()),this._websocket.onopen=()=>{this._wsReady=!0,Object.keys(this._requests).forEach(n=>{this._websocket.send(this._requests[n].payload)})},this._websocket.onmessage=n=>{const i=n.data,o=JSON.parse(i);if(null!=o.id){const c=String(o.id),l=this._requests[c];if(delete this._requests[c],void 0!==o.result)l.callback(null,o.result),this.emit("debug",{action:"response",request:JSON.parse(l.payload),response:o.result,provider:this});else{let a=null;o.error?(a=new Error(o.error.message||"unknown error"),(0,d.defineReadOnly)(a,"code",o.error.code||null),(0,d.defineReadOnly)(a,"response",i)):a=new Error("unknown error"),l.callback(a,void 0),this.emit("debug",{action:"response",error:a,request:JSON.parse(l.payload),provider:this})}}else if("eth_subscription"===o.method){const c=this._subs[o.params.subscription];c&&c.processFunc(o.params.result)}else console.warn("this should not happen")};const r=setInterval(()=>{this.emit("poll")},1e3);r.unref&&r.unref()}detectNetwork(){return this._detectNetwork}get pollingInterval(){return 0}resetEventsBlock(e){Y.throwError("cannot reset events block on WebSocketProvider",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"resetEventBlock"})}set pollingInterval(e){Y.throwError("cannot set polling interval on WebSocketProvider",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"setPollingInterval"})}poll(){return we(this,void 0,void 0,function*(){return null})}set polling(e){!e||Y.throwError("cannot set polling on WebSocketProvider",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"setPolling"})}send(e,t){const r=yt++;return new Promise((n,i)=>{const c=JSON.stringify({method:e,params:t,id:r,jsonrpc:"2.0"});this.emit("debug",{action:"request",request:JSON.parse(c),provider:this}),this._requests[String(r)]={callback:function(l,a){return l?i(l):n(a)},payload:c},this._wsReady&&this._websocket.send(c)})}static defaultUrl(){return"ws://localhost:8546"}_subscribe(e,t,r){return we(this,void 0,void 0,function*(){let n=this._subIds[e];null==n&&(n=Promise.all(t).then(o=>this.send("eth_subscribe",o)),this._subIds[e]=n);const i=yield n;this._subs[i]={tag:e,processFunc:r}})}_startEvent(e){switch(e.type){case"block":this._subscribe("block",["newHeads"],t=>{const r=b.O$.from(t.number).toNumber();this._emitted.block=r,this.emit("block",r)});break;case"pending":this._subscribe("pending",["newPendingTransactions"],t=>{this.emit("pending",t)});break;case"filter":this._subscribe(e.tag,["logs",this._getFilter(e.filter)],t=>{null==t.removed&&(t.removed=!1),this.emit(e.filter,this.formatter.filterLog(t))});break;case"tx":{const t=r=>{const n=r.hash;this.getTransactionReceipt(n).then(i=>{!i||this.emit(n,i)})};t(e),this._subscribe("tx",["newHeads"],r=>{this._events.filter(n=>"tx"===n.type).forEach(t)});break}case"debug":case"poll":case"willPoll":case"didPoll":case"error":break;default:console.log("unhandled:",e)}}_stopEvent(e){let t=e.tag;if("tx"===e.type){if(this._events.filter(n=>"tx"===n.type).length)return;t="tx"}else if(this.listenerCount(e.event))return;const r=this._subIds[t];!r||(delete this._subIds[t],r.then(n=>{!this._subs[n]||(delete this._subs[n],this.send("eth_unsubscribe",[n]))}))}destroy(){return we(this,void 0,void 0,function*(){this._websocket.readyState===W.CONNECTING&&(yield new Promise(e=>{this._websocket.onopen=function(){e(!0)},this._websocket.onerror=function(){e(!1)}})),this._websocket.close(1e3)})}}const J=new h.Logger(R);class He extends I{detectNetwork(){const e=Object.create(null,{detectNetwork:{get:()=>super.detectNetwork}});return function(s,e,t,r){return new(t||(t=Promise))(function(i,o){function c(u){try{a(r.next(u))}catch(m){o(m)}}function l(u){try{a(r.throw(u))}catch(m){o(m)}}function a(u){u.done?i(u.value):function(i){return i instanceof t?i:new t(function(o){o(i)})}(u.value).then(c,l)}a((r=r.apply(s,e||[])).next())})}(this,void 0,void 0,function*(){let t=this.network;return null==t&&(t=yield e.detectNetwork.call(this),t||J.throwError("no network detected",h.Logger.errors.UNKNOWN_ERROR,{}),null==this._network&&((0,d.defineReadOnly)(this,"_network",t),this.emit("network",t,null))),t})}}class A extends He{constructor(e,t){J.checkAbstract(new.target,A),e=(0,d.getStatic)(new.target,"getNetwork")(e),t=(0,d.getStatic)(new.target,"getApiKey")(t),super((0,d.getStatic)(new.target,"getUrl")(e,t),e),"string"==typeof t?(0,d.defineReadOnly)(this,"apiKey",t):null!=t&&Object.keys(t).forEach(n=>{(0,d.defineReadOnly)(this,n,t[n])})}_startPending(){J.warn("WARNING: API provider does not support pending filters")}isCommunityResource(){return!1}getSigner(e){return J.throwError("API provider does not support signing",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"getSigner"})}listAccounts(){return Promise.resolve([])}static getApiKey(e){return e}static getUrl(e,t){return J.throwError("not implemented; sub-classes must override getUrl",h.Logger.errors.NOT_IMPLEMENTED,{operation:"getUrl"})}}const $e=new h.Logger(R),te="_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC";class Ge extends ee{constructor(e,t){const r=new ye(e,t);super(r.connection.url.replace(/^http/i,"ws").replace(".alchemyapi.",".ws.alchemyapi."),r.network),(0,d.defineReadOnly)(this,"apiKey",r.apiKey)}isCommunityResource(){return this.apiKey===te}}class ye extends A{static getWebSocketProvider(e,t){return new Ge(e,t)}static getApiKey(e){return null==e?te:(e&&"string"!=typeof e&&$e.throwArgumentError("invalid apiKey","apiKey",e),e)}static getUrl(e,t){let r=null;switch(e.name){case"homestead":r="eth-mainnet.alchemyapi.io/v2/";break;case"ropsten":r="eth-ropsten.alchemyapi.io/v2/";break;case"rinkeby":r="eth-rinkeby.alchemyapi.io/v2/";break;case"goerli":r="eth-goerli.alchemyapi.io/v2/";break;case"kovan":r="eth-kovan.alchemyapi.io/v2/";break;case"matic":r="polygon-mainnet.g.alchemy.com/v2/";break;case"maticmum":r="polygon-mumbai.g.alchemy.com/v2/";break;default:$e.throwArgumentError("unsupported network","network",arguments[0])}return{allowGzip:!0,url:"https://"+r+t,throttleCallback:(n,i)=>(t===te&&X(),Promise.resolve(!0))}}isCommunityResource(){return this.apiKey===te}}const qe=new h.Logger(R);class We extends A{static getApiKey(e){return null!=e&&qe.throwArgumentError("apiKey not supported for cloudflare","apiKey",e),null}static getUrl(e,t){let r=null;return"homestead"===e.name?r="https://cloudflare-eth.com/":qe.throwArgumentError("unsupported network","network",arguments[0]),r}perform(e,t){const r=Object.create(null,{perform:{get:()=>super.perform}});return function(s,e,t,r){return new(t||(t=Promise))(function(i,o){function c(u){try{a(r.next(u))}catch(m){o(m)}}function l(u){try{a(r.throw(u))}catch(m){o(m)}}function a(u){u.done?i(u.value):function(i){return i instanceof t?i:new t(function(o){o(i)})}(u.value).then(c,l)}a((r=r.apply(s,e||[])).next())})}(this,void 0,void 0,function*(){return"getBlockNumber"===e?(yield r.perform.call(this,"getBlock",{blockTag:"latest"})).number:r.perform.call(this,e,t)})}}var re=function(s,e,t,r){return new(t||(t=Promise))(function(i,o){function c(u){try{a(r.next(u))}catch(m){o(m)}}function l(u){try{a(r.throw(u))}catch(m){o(m)}}function a(u){u.done?i(u.value):function(i){return i instanceof t?i:new t(function(o){o(i)})}(u.value).then(c,l)}a((r=r.apply(s,e||[])).next())})};const L=new h.Logger(R);function Je(s){const e={};for(let t in s){if(null==s[t])continue;let r=s[t];"type"===t&&0===r||(r={type:!0,gasLimit:!0,gasPrice:!0,maxFeePerGs:!0,maxPriorityFeePerGas:!0,nonce:!0,value:!0}[t]?(0,g.hexValue)((0,g.hexlify)(r)):"accessList"===t?"["+(0,Z.accessListify)(r).map(n=>`{address:"${n.address}",storageKeys:["${n.storageKeys.join('","')}"]}`).join(",")+"]":(0,g.hexlify)(r),e[t]=r)}return e}function vt(s){if(0==s.status&&("No records found"===s.message||"No transactions found"===s.message))return s.result;if(1!=s.status||"OK"!=s.message){const e=new Error("invalid response");throw e.result=JSON.stringify(s),(s.result||"").toLowerCase().indexOf("rate limit")>=0&&(e.throttleRetry=!0),e}return s.result}function Me(s){if(s&&0==s.status&&"NOTOK"==s.message&&(s.result||"").toLowerCase().indexOf("rate limit")>=0){const e=new Error("throttled response");throw e.result=JSON.stringify(s),e.throttleRetry=!0,e}if("2.0"!=s.jsonrpc){const e=new Error("invalid response");throw e.result=JSON.stringify(s),e}if(s.error){const e=new Error(s.error.message||"unknown error");throw s.error.code&&(e.code=s.error.code),s.error.data&&(e.data=s.error.data),e}return s.result}function Fe(s){if("pending"===s)throw new Error("pending not supported");return"latest"===s?s:parseInt(s.substring(2),16)}const Ve="9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB";function be(s,e,t){if("call"===s&&e.code===h.Logger.errors.SERVER_ERROR){const n=e.error;if(n&&(n.message.match(/reverted/i)||n.message.match(/VM execution error/i))){let i=n.data;if(i&&(i="0x"+i.replace(/^.*0x/i,"")),(0,g.isHexString)(i))return i;L.throwError("missing revert data in call exception",h.Logger.errors.CALL_EXCEPTION,{error:e,data:"0x"})}}let r=e.message;throw e.code===h.Logger.errors.SERVER_ERROR&&(e.error&&"string"==typeof e.error.message?r=e.error.message:"string"==typeof e.body?r=e.body:"string"==typeof e.responseText&&(r=e.responseText)),r=(r||"").toLowerCase(),r.match(/insufficient funds/)&&L.throwError("insufficient funds for intrinsic transaction cost",h.Logger.errors.INSUFFICIENT_FUNDS,{error:e,method:s,transaction:t}),r.match(/same hash was already imported|transaction nonce is too low|nonce too low/)&&L.throwError("nonce has already been used",h.Logger.errors.NONCE_EXPIRED,{error:e,method:s,transaction:t}),r.match(/another transaction with same nonce/)&&L.throwError("replacement fee too low",h.Logger.errors.REPLACEMENT_UNDERPRICED,{error:e,method:s,transaction:t}),r.match(/execution failed due to an exception|execution reverted/)&&L.throwError("cannot estimate gas; transaction may fail or may require manual gas limit",h.Logger.errors.UNPREDICTABLE_GAS_LIMIT,{error:e,method:s,transaction:t}),e}class ne extends Q{constructor(e,t){L.checkNew(new.target,ne),super(e),(0,d.defineReadOnly)(this,"baseUrl",this.getBaseUrl()),(0,d.defineReadOnly)(this,"apiKey",t||Ve)}getBaseUrl(){switch(this.network?this.network.name:"invalid"){case"homestead":return"https://api.etherscan.io";case"ropsten":return"https://api-ropsten.etherscan.io";case"rinkeby":return"https://api-rinkeby.etherscan.io";case"kovan":return"https://api-kovan.etherscan.io";case"goerli":return"https://api-goerli.etherscan.io"}return L.throwArgumentError("unsupported network","network",name)}getUrl(e,t){const r=Object.keys(t).reduce((i,o)=>{const c=t[o];return null!=c&&(i+=`&${o}=${c}`),i},"");return`${this.baseUrl}/api?module=${e}${r}${this.apiKey?`&apikey=${this.apiKey}`:""}`}getPostUrl(){return`${this.baseUrl}/api`}getPostData(e,t){return t.module=e,t.apikey=this.apiKey,t}fetch(e,t,r){return re(this,void 0,void 0,function*(){const n=r?this.getPostUrl():this.getUrl(e,t),i=r?this.getPostData(e,t):null,o="proxy"===e?Me:vt;this.emit("debug",{action:"request",request:n,provider:this});const c={url:n,throttleSlotInterval:1e3,throttleCallback:(u,m)=>(this.isCommunityResource()&&X(),Promise.resolve(!0))};let l=null;i&&(c.headers={"content-type":"application/x-www-form-urlencoded; charset=UTF-8"},l=Object.keys(i).map(u=>`${u}=${i[u]}`).join("&"));const a=yield(0,x.fetchJson)(c,l,o||Me);return this.emit("debug",{action:"response",request:n,response:(0,d.deepCopy)(a),provider:this}),a})}detectNetwork(){return re(this,void 0,void 0,function*(){return this.network})}perform(e,t){const r=Object.create(null,{perform:{get:()=>super.perform}});return re(this,void 0,void 0,function*(){switch(e){case"getBlockNumber":return this.fetch("proxy",{action:"eth_blockNumber"});case"getGasPrice":return this.fetch("proxy",{action:"eth_gasPrice"});case"getBalance":return this.fetch("account",{action:"balance",address:t.address,tag:t.blockTag});case"getTransactionCount":return this.fetch("proxy",{action:"eth_getTransactionCount",address:t.address,tag:t.blockTag});case"getCode":return this.fetch("proxy",{action:"eth_getCode",address:t.address,tag:t.blockTag});case"getStorageAt":return this.fetch("proxy",{action:"eth_getStorageAt",address:t.address,position:t.position,tag:t.blockTag});case"sendTransaction":return this.fetch("proxy",{action:"eth_sendRawTransaction",hex:t.signedTransaction},!0).catch(n=>be("sendTransaction",n,t.signedTransaction));case"getBlock":if(t.blockTag)return this.fetch("proxy",{action:"eth_getBlockByNumber",tag:t.blockTag,boolean:t.includeTransactions?"true":"false"});throw new Error("getBlock by blockHash not implemented");case"getTransaction":return this.fetch("proxy",{action:"eth_getTransactionByHash",txhash:t.transactionHash});case"getTransactionReceipt":return this.fetch("proxy",{action:"eth_getTransactionReceipt",txhash:t.transactionHash});case"call":{if("latest"!==t.blockTag)throw new Error("EtherscanProvider does not support blockTag for call");const n=Je(t.transaction);n.module="proxy",n.action="eth_call";try{return yield this.fetch("proxy",n,!0)}catch(i){return be("call",i,t.transaction)}}case"estimateGas":{const n=Je(t.transaction);n.module="proxy",n.action="eth_estimateGas";try{return yield this.fetch("proxy",n,!0)}catch(i){return be("estimateGas",i,t.transaction)}}case"getLogs":{const n={action:"getLogs"};if(t.filter.fromBlock&&(n.fromBlock=Fe(t.filter.fromBlock)),t.filter.toBlock&&(n.toBlock=Fe(t.filter.toBlock)),t.filter.address&&(n.address=t.filter.address),t.filter.topics&&t.filter.topics.length>0&&(t.filter.topics.length>1&&L.throwError("unsupported topic count",h.Logger.errors.UNSUPPORTED_OPERATION,{topics:t.filter.topics}),1===t.filter.topics.length)){const c=t.filter.topics[0];("string"!=typeof c||66!==c.length)&&L.throwError("unsupported topic format",h.Logger.errors.UNSUPPORTED_OPERATION,{topic0:c}),n.topic0=c}const i=yield this.fetch("logs",n);let o={};for(let c=0;c<i.length;c++){const l=i[c];if(null==l.blockHash){if(null==o[l.blockNumber]){const a=yield this.getBlock(l.blockNumber);a&&(o[l.blockNumber]=a.hash)}l.blockHash=o[l.blockNumber]}}return i}case"getEtherPrice":return"homestead"!==this.network.name?0:parseFloat((yield this.fetch("stats",{action:"ethprice"})).ethusd)}return r.perform.call(this,e,t)})}getHistory(e,t,r){return re(this,void 0,void 0,function*(){const n={action:"txlist",address:yield this.resolveName(e),startblock:t??0,endblock:r??99999999,sort:"asc"};return(yield this.fetch("account",n)).map(o=>{["contractAddress","to"].forEach(function(l){""==o[l]&&delete o[l]}),null==o.creates&&null!=o.contractAddress&&(o.creates=o.contractAddress);const c=this.formatter.transactionResponse(o);return o.timeStamp&&(c.timestamp=parseInt(o.timeStamp)),c})})}isCommunityResource(){return this.apiKey===Ve}}var Nt=N(34820),ie=function(s,e,t,r){return new(t||(t=Promise))(function(i,o){function c(u){try{a(r.next(u))}catch(m){o(m)}}function l(u){try{a(r.throw(u))}catch(m){o(m)}}function a(u){u.done?i(u.value):function(i){return i instanceof t?i:new t(function(o){o(i)})}(u.value).then(c,l)}a((r=r.apply(s,e||[])).next())})};const S=new h.Logger(R);function oe(){return(new Date).getTime()}function ze(s){let e=null;for(let t=0;t<s.length;t++){const r=s[t];if(null==r)return null;e?e.name===r.name&&e.chainId===r.chainId&&(e.ensAddress===r.ensAddress||null==e.ensAddress&&null==r.ensAddress)||S.throwArgumentError("provider mismatch","networks",s):e=r}return e}function Ke(s,e){s=s.slice().sort();const t=Math.floor(s.length/2);if(s.length%2)return s[t];const r=s[t-1],n=s[t];return null!=e&&Math.abs(r-n)>e?null:(r+n)/2}function j(s){if(null===s)return"null";if("number"==typeof s||"boolean"==typeof s)return JSON.stringify(s);if("string"==typeof s)return s;if(b.O$.isBigNumber(s))return s.toString();if(Array.isArray(s))return JSON.stringify(s.map(e=>j(e)));if("object"==typeof s){const e=Object.keys(s);return e.sort(),"{"+e.map(t=>{let r=s[t];return r="function"==typeof r?"[function]":j(r),JSON.stringify(t)+":"+r}).join(",")+"}"}throw new Error("unknown value type: "+typeof s)}let Et=1;function Ze(s){let e=null,t=null,r=new Promise(o=>{e=function(){t&&(clearTimeout(t),t=null),o()},t=setTimeout(e,s)});return{cancel:e,getPromise:function(){return r},wait:o=>(r=r.then(o),r)}}const _t=[h.Logger.errors.CALL_EXCEPTION,h.Logger.errors.INSUFFICIENT_FUNDS,h.Logger.errors.NONCE_EXPIRED,h.Logger.errors.REPLACEMENT_UNDERPRICED,h.Logger.errors.UNPREDICTABLE_GAS_LIMIT],Rt=["address","args","errorArgs","errorSignature","method","transaction"];function se(s,e){const t={weight:s.weight};return Object.defineProperty(t,"provider",{get:()=>s.provider}),s.start&&(t.start=s.start),e&&(t.duration=e-s.start),s.done&&(s.error?t.error=s.error:t.result=s.result||null),t}function M(s,e){return ie(this,void 0,void 0,function*(){const t=s.provider;return null!=t.blockNumber&&t.blockNumber>=e||-1===e?t:(0,x.poll)(()=>new Promise((r,n)=>{setTimeout(function(){return r(t.blockNumber>=e?t:s.cancelled?null:void 0)},0)}),{oncePoll:t})})}function xt(s,e,t,r){return ie(this,void 0,void 0,function*(){let n=s.provider;switch(t){case"getBlockNumber":case"getGasPrice":return n[t]();case"getEtherPrice":if(n.getEtherPrice)return n.getEtherPrice();break;case"getBalance":case"getTransactionCount":case"getCode":return r.blockTag&&(0,g.isHexString)(r.blockTag)&&(n=yield M(s,e)),n[t](r.address,r.blockTag||"latest");case"getStorageAt":return r.blockTag&&(0,g.isHexString)(r.blockTag)&&(n=yield M(s,e)),n.getStorageAt(r.address,r.position,r.blockTag||"latest");case"getBlock":return r.blockTag&&(0,g.isHexString)(r.blockTag)&&(n=yield M(s,e)),n[r.includeTransactions?"getBlockWithTransactions":"getBlock"](r.blockTag||r.blockHash);case"call":case"estimateGas":return r.blockTag&&(0,g.isHexString)(r.blockTag)&&(n=yield M(s,e)),n[t](r.transaction);case"getTransaction":case"getTransactionReceipt":return n[t](r.transactionHash);case"getLogs":{let i=r.filter;return(i.fromBlock&&(0,g.isHexString)(i.fromBlock)||i.toBlock&&(0,g.isHexString)(i.toBlock))&&(n=yield M(s,e)),n.getLogs(i)}}return S.throwError("unknown method error",h.Logger.errors.UNKNOWN_ERROR,{method:t,params:r})})}class le extends Q{constructor(e,t){S.checkNew(new.target,le),0===e.length&&S.throwArgumentError("missing providers","providers",e);const r=e.map((o,c)=>{if(H.zt.isProvider(o)){const u=de(o)?2e3:750;return Object.freeze({provider:o,weight:1,stallTimeout:u,priority:1})}const l=(0,d.shallowCopy)(o);null==l.priority&&(l.priority=1),null==l.stallTimeout&&(l.stallTimeout=de(o)?2e3:750),null==l.weight&&(l.weight=1);const a=l.weight;return(a%1||a>512||a<1)&&S.throwArgumentError("invalid weight; must be integer in [1, 512]",`providers[${c}].weight`,a),Object.freeze(l)}),n=r.reduce((o,c)=>o+c.weight,0);null==t?t=n/2:t>n&&S.throwArgumentError("quorum will always fail; larger than total weight","quorum",t);let i=ze(r.map(o=>o.provider.network));null==i&&(i=new Promise((o,c)=>{setTimeout(()=>{this.detectNetwork().then(o,c)},0)})),super(i),(0,d.defineReadOnly)(this,"providerConfigs",Object.freeze(r)),(0,d.defineReadOnly)(this,"quorum",t),this._highestBlockNumber=-1}detectNetwork(){return ie(this,void 0,void 0,function*(){return ze(yield Promise.all(this.providerConfigs.map(t=>t.provider.getNetwork())))})}perform(e,t){return ie(this,void 0,void 0,function*(){if("sendTransaction"===e){const l=yield Promise.all(this.providerConfigs.map(a=>a.provider.sendTransaction(t.signedTransaction).then(u=>u.hash,u=>u)));for(let a=0;a<l.length;a++){const u=l[a];if("string"==typeof u)return u}throw l[0]}-1===this._highestBlockNumber&&"getBlockNumber"!==e&&(yield this.getBlockNumber());const r=function(s,e,t){let r=j;switch(e){case"getBlockNumber":return function(n){const i=n.map(c=>c.result);let o=Ke(n.map(c=>c.result),2);if(null!=o)return o=Math.ceil(o),i.indexOf(o+1)>=0&&o++,o>=s._highestBlockNumber&&(s._highestBlockNumber=o),s._highestBlockNumber};case"getGasPrice":return function(n){const i=n.map(o=>o.result);return i.sort(),i[Math.floor(i.length/2)]};case"getEtherPrice":return function(n){return Ke(n.map(i=>i.result))};case"getBalance":case"getTransactionCount":case"getCode":case"getStorageAt":case"call":case"estimateGas":case"getLogs":break;case"getTransaction":case"getTransactionReceipt":r=function(n){return null==n?null:((n=(0,d.shallowCopy)(n)).confirmations=-1,j(n))};break;case"getBlock":r=t.includeTransactions?function(n){return null==n?null:((n=(0,d.shallowCopy)(n)).transactions=n.transactions.map(i=>((i=(0,d.shallowCopy)(i)).confirmations=-1,i)),j(n))}:function(n){return null==n?null:j(n)};break;default:throw new Error("unknown method: "+e)}return function(s,e){return function(t){const r={};t.forEach(i=>{const o=s(i.result);r[o]||(r[o]={count:0,result:i.result}),r[o].count++});const n=Object.keys(r);for(let i=0;i<n.length;i++){const o=r[n[i]];if(o.count>=e)return o.result}}}(r,s.quorum)}(this,e,t),n=(0,Nt.y)(this.providerConfigs.map(d.shallowCopy));n.sort((l,a)=>l.priority-a.priority);const i=this._highestBlockNumber;let o=0,c=!0;for(;;){const l=oe();let a=n.filter(p=>p.runner&&l-p.start<p.stallTimeout).reduce((p,v)=>p+v.weight,0);for(;a<this.quorum&&o<n.length;){const p=n[o++],v=Et++;p.start=oe(),p.staller=Ze(p.stallTimeout),p.staller.wait(()=>{p.staller=null}),p.runner=xt(p,i,e,t).then(_=>{p.done=!0,p.result=_,this.listenerCount("debug")&&this.emit("debug",{action:"request",rid:v,backend:se(p,oe()),request:{method:e,params:(0,d.deepCopy)(t)},provider:this})},_=>{p.done=!0,p.error=_,this.listenerCount("debug")&&this.emit("debug",{action:"request",rid:v,backend:se(p,oe()),request:{method:e,params:(0,d.deepCopy)(t)},provider:this})}),this.listenerCount("debug")&&this.emit("debug",{action:"request",rid:v,backend:se(p,null),request:{method:e,params:(0,d.deepCopy)(t)},provider:this}),a+=p.weight}const u=[];n.forEach(p=>{p.done||!p.runner||(u.push(p.runner),p.staller&&u.push(p.staller.getPromise()))}),u.length&&(yield Promise.race(u));const m=n.filter(p=>p.done&&null==p.error);if(m.length>=this.quorum){const p=r(m);if(void 0!==p)return n.forEach(v=>{v.staller&&v.staller.cancel(),v.cancelled=!0}),p;c||(yield Ze(100).getPromise()),c=!1}const k=n.reduce((p,v)=>{if(!v.done||null==v.error)return p;const _=v.error.code;return _t.indexOf(_)>=0&&(p[_]||(p[_]={error:v.error,weight:0}),p[_].weight+=v.weight),p},{});if(Object.keys(k).forEach(p=>{const v=k[p];if(v.weight<this.quorum)return;n.forEach(P=>{P.staller&&P.staller.cancel(),P.cancelled=!0});const _=v.error,V={};Rt.forEach(P=>{null!=_[P]&&(V[P]=_[P])}),S.throwError(_.reason||_.message,p,V)}),0===n.filter(p=>!p.done).length)break}return n.forEach(l=>{l.staller&&l.staller.cancel(),l.cancelled=!0}),S.throwError("failed to meet quorum",h.Logger.errors.SERVER_ERROR,{method:e,params:t,results:n.map(l=>se(l)),provider:this})})}}const Xe=null,ce=new h.Logger(R),F="84842078b09946638c03157f83405213";class Qe extends ee{constructor(e,t){const r=new ke(e,t),n=r.connection;n.password&&ce.throwError("INFURA WebSocket project secrets unsupported",h.Logger.errors.UNSUPPORTED_OPERATION,{operation:"InfuraProvider.getWebSocketProvider()"}),super(n.url.replace(/^http/i,"ws").replace("/v3/","/ws/v3/"),e),(0,d.defineReadOnly)(this,"apiKey",r.projectId),(0,d.defineReadOnly)(this,"projectId",r.projectId),(0,d.defineReadOnly)(this,"projectSecret",r.projectSecret)}isCommunityResource(){return this.projectId===F}}class ke extends A{static getWebSocketProvider(e,t){return new Qe(e,t)}static getApiKey(e){const t={apiKey:F,projectId:F,projectSecret:null};return null==e||("string"==typeof e?t.projectId=e:null!=e.projectSecret?(ce.assertArgument("string"==typeof e.projectId,"projectSecret requires a projectId","projectId",e.projectId),ce.assertArgument("string"==typeof e.projectSecret,"invalid projectSecret","projectSecret","[REDACTED]"),t.projectId=e.projectId,t.projectSecret=e.projectSecret):e.projectId&&(t.projectId=e.projectId),t.apiKey=t.projectId),t}static getUrl(e,t){let r=null;switch(e?e.name:"unknown"){case"homestead":r="mainnet.infura.io";break;case"ropsten":r="ropsten.infura.io";break;case"rinkeby":r="rinkeby.infura.io";break;case"kovan":r="kovan.infura.io";break;case"goerli":r="goerli.infura.io";break;case"matic":r="polygon-mainnet.infura.io";break;case"maticmum":r="polygon-mumbai.infura.io";break;default:ce.throwError("unsupported network",h.Logger.errors.INVALID_ARGUMENT,{argument:"network",value:e})}const n={allowGzip:!0,url:"https://"+r+"/v3/"+t.projectId,throttleCallback:(i,o)=>(t.projectId===F&&X(),Promise.resolve(!0))};return null!=t.projectSecret&&(n.user="",n.password=t.projectSecret),n}isCommunityResource(){return this.projectId===F}}class Ot extends I{send(e,t){const r={method:e,params:t,id:this._nextId++,jsonrpc:"2.0"};null==this._pendingBatch&&(this._pendingBatch=[]);const n={request:r,resolve:null,reject:null},i=new Promise((o,c)=>{n.resolve=o,n.reject=c});return this._pendingBatch.push(n),this._pendingBatchAggregator||(this._pendingBatchAggregator=setTimeout(()=>{const o=this._pendingBatch;this._pendingBatch=null,this._pendingBatchAggregator=null;const c=o.map(l=>l.request);return this.emit("debug",{action:"requestBatch",request:(0,d.deepCopy)(c),provider:this}),(0,x.fetchJson)(this.connection,JSON.stringify(c)).then(l=>{this.emit("debug",{action:"response",request:c,response:l,provider:this}),o.forEach((a,u)=>{const m=l[u];if(m.error){const k=new Error(m.error.message);k.code=m.error.code,k.data=m.error.data,a.reject(k)}else a.resolve(m.result)})},l=>{this.emit("debug",{action:"response",error:l,request:c,provider:this}),o.forEach(a=>{a.reject(l)})})},10)),i}}const ve=new h.Logger(R);class Ye extends A{static getApiKey(e){return e&&"string"!=typeof e&&ve.throwArgumentError("invalid apiKey","apiKey",e),e||"ETHERS_JS_SHARED"}static getUrl(e,t){ve.warn("NodeSmith will be discontinued on 2019-12-20; please migrate to another platform.");let r=null;switch(e.name){case"homestead":r="https://ethereum.api.nodesmith.io/v1/mainnet/jsonrpc";break;case"ropsten":r="https://ethereum.api.nodesmith.io/v1/ropsten/jsonrpc";break;case"rinkeby":r="https://ethereum.api.nodesmith.io/v1/rinkeby/jsonrpc";break;case"goerli":r="https://ethereum.api.nodesmith.io/v1/goerli/jsonrpc";break;case"kovan":r="https://ethereum.api.nodesmith.io/v1/kovan/jsonrpc";break;default:ve.throwArgumentError("unsupported network","network",arguments[0])}return r+"?apiKey="+t}}const B=new h.Logger(R),et={homestead:"6004bcd10040261633ade990",ropsten:"6004bd4d0040261633ade991",rinkeby:"6004bda20040261633ade994",goerli:"6004bd860040261633ade992"};class tt extends A{constructor(e,t){if(null==t){const r=(0,d.getStatic)(new.target,"getNetwork")(e);if(r){const n=et[r.name];n&&(t={applicationId:n,loadBalancer:!0})}null==t&&B.throwError("unsupported network",h.Logger.errors.INVALID_ARGUMENT,{argument:"network",value:e})}super(e,t)}static getApiKey(e){null==e&&B.throwArgumentError("PocketProvider.getApiKey does not support null apiKey","apiKey",e);const t={applicationId:null,loadBalancer:!1,applicationSecretKey:null};return"string"==typeof e?t.applicationId=e:null!=e.applicationSecretKey?(B.assertArgument("string"==typeof e.applicationId,"applicationSecretKey requires an applicationId","applicationId",e.applicationId),B.assertArgument("string"==typeof e.applicationSecretKey,"invalid applicationSecretKey","applicationSecretKey","[REDACTED]"),t.applicationId=e.applicationId,t.applicationSecretKey=e.applicationSecretKey,t.loadBalancer=!!e.loadBalancer):e.applicationId?(B.assertArgument("string"==typeof e.applicationId,"apiKey.applicationId must be a string","apiKey.applicationId",e.applicationId),t.applicationId=e.applicationId,t.loadBalancer=!!e.loadBalancer):B.throwArgumentError("unsupported PocketProvider apiKey","apiKey",e),t}static getUrl(e,t){let r=null;switch(e?e.name:"unknown"){case"homestead":r="eth-mainnet.gateway.pokt.network";break;case"ropsten":r="eth-ropsten.gateway.pokt.network";break;case"rinkeby":r="eth-rinkeby.gateway.pokt.network";break;case"goerli":r="eth-goerli.gateway.pokt.network";break;default:B.throwError("unsupported network",h.Logger.errors.INVALID_ARGUMENT,{argument:"network",value:e})}let n=null;n=t.loadBalancer?`https://${r}/v1/lb/${t.applicationId}`:`https://${r}/v1/${t.applicationId}`;const i={url:n,headers:{}};return null!=t.applicationSecretKey&&(i.user="",i.password=t.applicationSecretKey),i}isCommunityResource(){return this.applicationId===et[this.network.name]}}const Ne=new h.Logger(R);let Lt=1;function rt(s,e){const t="Web3LegacyFetcher";return function(r,n){const i={method:r,params:n,id:Lt++,jsonrpc:"2.0"};return new Promise((o,c)=>{this.emit("debug",{action:"request",fetcher:t,request:(0,d.deepCopy)(i),provider:this}),e(i,(l,a)=>{if(l)return this.emit("debug",{action:"response",fetcher:t,error:l,request:i,provider:this}),c(l);if(this.emit("debug",{action:"response",fetcher:t,request:i,response:a,provider:this}),a.error){const u=new Error(a.error.message);return u.code=a.error.code,u.data=a.error.data,c(u)}o(a.result)})})}}class ae extends I{constructor(e,t){Ne.checkNew(new.target,ae),null==e&&Ne.throwArgumentError("missing provider","provider",e);let r=null,n=null,i=null;var s;"function"==typeof e?(r="unknown:",n=e):(r=e.host||e.path||"",!r&&e.isMetaMask&&(r="metamask"),i=e,e.request?(""===r&&(r="eip-1193:"),s=e,n=function(e,t){null==t&&(t=[]);const r={method:e,params:t};return this.emit("debug",{action:"request",fetcher:"Eip1193Fetcher",request:(0,d.deepCopy)(r),provider:this}),s.request(r).then(n=>(this.emit("debug",{action:"response",fetcher:"Eip1193Fetcher",request:r,response:n,provider:this}),n),n=>{throw this.emit("debug",{action:"response",fetcher:"Eip1193Fetcher",request:r,error:n,provider:this}),n})}):e.sendAsync?n=rt(0,e.sendAsync.bind(e)):e.send?n=rt(0,e.send.bind(e)):Ne.throwArgumentError("unsupported provider","provider",e),r||(r="unknown:")),super(r,t),(0,d.defineReadOnly)(this,"jsonRpcFetchFunc",n),(0,d.defineReadOnly)(this,"provider",i)}send(e,t){return this.jsonRpcFetchFunc(e,t)}}const nt=new h.Logger(R);function St(s,e){if(null==s&&(s="homestead"),"string"==typeof s){const r=s.match(/^(ws|http)s?:/i);if(r)switch(r[1]){case"http":return new I(s);case"ws":return new ee(s);default:nt.throwArgumentError("unsupported URL scheme","network",s)}}const t=(0,ue.H)(s);return(!t||!t._defaultProvider)&&nt.throwError("unsupported getDefaultProvider network",h.Logger.errors.NETWORK_ERROR,{operation:"getDefaultProvider",network:s}),t._defaultProvider({FallbackProvider:le,AlchemyProvider:ye,CloudflareProvider:We,EtherscanProvider:ne,InfuraProvider:ke,JsonRpcProvider:I,NodesmithProvider:Ye,PocketProvider:tt,Web3Provider:ae,IpcProvider:Xe},e)}}}]);