dev3-sdk
Version:
SDK for interacting with the 0xDev3 platform.
12 lines (8 loc) • 411 kB
JavaScript
'use strict';
var polycodeChainlinkFeeds = require('polycode-chainlink-feeds');
var dkg_js = require('dkg.js');
var c0 = require('axios');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var dkg_js__default = /*#__PURE__*/_interopDefault(dkg_js);
var c0__default = /*#__PURE__*/_interopDefault(c0);
var Bd=Object.defineProperty,Pm=Object.defineProperties;var vm=Object.getOwnPropertyDescriptors;var Td=Object.getOwnPropertySymbols,Sm=Object.getPrototypeOf,Nm=Object.prototype.hasOwnProperty,Im=Object.prototype.propertyIsEnumerable,Tm=Reflect.get;var a0=(n,e,t)=>e in n?Bd(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Mo=(n,e)=>{for(var t in e||(e={}))Nm.call(e,t)&&a0(n,t,e[t]);if(Td)for(var t of Td(e))Im.call(e,t)&&a0(n,t,e[t]);return n},Go=(n,e)=>Pm(n,vm(e));var Od=(n,e)=>{for(var t in e)Bd(n,t,{get:e[t],enumerable:!0});};var g=(n,e,t)=>(a0(n,typeof e!="symbol"?e+"":e,t),t),o0=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var u=(n,e,t)=>(o0(n,e,"read from private field"),t?t.call(n):e.get(n)),b=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t);},p=(n,e,t,r)=>(o0(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),Zr=(n,e,t,r)=>({set _(s){p(n,e,s,t);},get _(){return u(n,e,r)}}),P=(n,e,t)=>(o0(n,e,"access private method"),t),Se=(n,e,t)=>Tm(Sm(n),t,e);var l=(n,e,t)=>new Promise((r,s)=>{var i=c=>{try{o(t.next(c));}catch(f){s(f);}},a=c=>{try{o(t.throw(c));}catch(f){s(f);}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,a);o((t=t.apply(n,e)).next());});var wu=class extends Error{constructor(e,t){super(`${e}: ${t}`);}},Ee=class extends Error{constructor(e){super(e);}};var Au=class{constructor(e,t,r,s){this._initializeResponseInterceptor=()=>{this.instance.interceptors.response.use(this._handleResponse,this._handleError),this.protectedInstance.interceptors.response.use(this._handleResponse,this._handleError),this.identityServiceInstance.interceptors.response.use(this._handleResponse,this._handleError);};this._handleResponse=({data:e})=>e;this._handleError=e=>{var t,r,s,i;if(e instanceof c0.AxiosError){let a=(r=(t=e.response)==null?void 0:t.data)==null?void 0:r.error_code,o=(i=(s=e.response)==null?void 0:s.data)==null?void 0:i.message;if(a!==void 0&&o!==void 0)return Promise.reject(new wu(a,o))}return Promise.reject(e)};this.instance=c0__default.default.create({baseURL:e}),this.protectedInstance=c0__default.default.create({baseURL:e,headers:{"X-API-KEY":r}}),this.identityServiceInstance=c0__default.default.create({baseURL:t}),this.projectId=s,this.apiKey=r,this._initializeResponseInterceptor();}};var O=class extends Au{constructor(e,t,r,s){super(e,t,r,s);}static init(e,t,r,s){this.classInstance||(this.classInstance=new O(e,t,r,s));}static instance(){if(this.classInstance===void 0)throw new Ee("API module not initialized.");return this.classInstance}createWalletAuthorizationRequest(e){return l(this,null,function*(){return yield this.protectedInstance.post("wallet-authorization",e)})}fetchProject(){return l(this,null,function*(){return yield this.protectedInstance.get("projects/by-api-key")})}fetchWalletAuthorizationRequestById(e){return l(this,null,function*(){return yield this.instance.get(`wallet-authorization/${e}`)})}fetchWalletAuthorizationRequests(){return l(this,null,function*(){return yield this.instance.get(`wallet-authorization/by-project/${this.projectId}`)})}createContractDeploymentRequest(e){return l(this,null,function*(){return yield this.protectedInstance.post("deploy",e)})}fetchContractDeploymentRequestById(e){return l(this,null,function*(){return yield this.instance.get(`deploy/${e}`)})}fetchContractDeploymentRequestByAlias(e){return l(this,null,function*(){return yield this.instance.get(`deploy/by-project/${this.projectId}/by-alias/${e}`)})}fetchContractDeploymentRequests(e,t,r,s){return l(this,null,function*(){return yield this.protectedInstance.get(`deploy/by-project/${this.projectId}`,{params:{contractIds:e.join(","),contracTags:r.join(","),contractImplements:s.join(","),deployedOnly:t}})})}deleteContractDeploymentRequestById(e){return l(this,null,function*(){return this.protectedInstance.delete(`deploy/${e}`)})}createFunctionCallRequest(e){return l(this,null,function*(){return yield this.protectedInstance.post("function-call",e)})}fetchFunctionCallRequestById(e){return l(this,null,function*(){return yield this.instance.get(`function-call/${e}`)})}fetchFunctionCallRequests(e,t){return l(this,null,function*(){let r=new Map;return e&&r.set("deployedContractId",e),t&&r.set("contractAddress",t),(yield this.instance.get(`function-call/by-project/${this.projectId}`,{params:r})).requests})}readContract(e){return l(this,null,function*(){return yield this.protectedInstance.post("readonly-function-call",e)})}attachTxHashForFunctionCall(e){return l(this,null,function*(){return yield this.instance.put(`function-call/${e.action_id}`,{tx_hash:e.tx_hash,caller_address:e.caller_address})})}fetchDeployableContracts(e){return l(this,null,function*(){return yield this.instance.get("deployable-contracts",{params:{tags:e.tags.join(","),implements:e.implements.join(","),projectId:this.projectId}})})}fetchDeployableContractById(e){return l(this,null,function*(){return yield this.instance.get(`deployable-contracts/${e}`)})}getPayload(e){return l(this,null,function*(){let t=e==null?void 0:e.address;return t?this.identityServiceInstance.post("authorize",{address:t}):this.identityServiceInstance.post("authorize/by-message")})}getJwt(e){return l(this,null,function*(){return this.identityServiceInstance.post("authorize/jwt",e)})}getJwtByMessage(e){return l(this,null,function*(){return this.identityServiceInstance.post("authorize/jwt/by-message",e)})}createAddressBookEntry(e,t){return l(this,null,function*(){return this.instance.post("address-book",e,{headers:{Authorization:`Bearer ${t.access_token}`}})})}updateAddressBookEntry(e,t){return l(this,null,function*(){return this.instance.patch(`address-book/${e.id}`,{alias:e.alias,address:e.address,phone_number:e.phone_number,email:e.email},{headers:{Authorization:`Bearer ${t.access_token}`}})})}deleteAddressBookEntry(e,t){return l(this,null,function*(){return this.instance.delete(`address-book/${e.id}`,{headers:{Authorization:`Bearer ${t.access_token}`}})})}fetchAddressBookEntryByAlias(e,t){return l(this,null,function*(){return this.instance.get(`address-book/by-alias/${e.alias}`,{headers:{Authorization:`Bearer ${t.access_token}`}})})}fetchAddressBookEntries(e,t){return l(this,null,function*(){return this.instance.get(`address-book/by-wallet-address/${e}`,{headers:{Authorization:`Bearer ${t.access_token}`}})})}createAssetSendRequest(e){return l(this,null,function*(){return this.protectedInstance.post("send",e)})}fetchAssetSendRequest(e){return l(this,null,function*(){return this.instance.get(`send/${e}`)})}fetchAllAssetSendRequests(){return l(this,null,function*(){return this.instance.get(`send/by-project/${this.projectId}`)})}fetchAssetSendRequestsBySender(e){return l(this,null,function*(){return this.instance.get(`send/by-sender/${e}`)})}fetchAssetSendRequestsByRecipient(e){return l(this,null,function*(){return this.instance.get(`send/by-recipient/${e}`)})}createContractArbitraryCallRequest(e){return l(this,null,function*(){return yield this.protectedInstance.post("arbitrary-call",e)})}estimateArbitraryCallGasCost(e){return l(this,null,function*(){return yield this.protectedInstance.post("gas/estimate/arbitrary-call",e)})}getGasPrice(){return l(this,null,function*(){return yield this.protectedInstance.get("gas/price")})}fetchContractArbitraryCallRequestById(e){return l(this,null,function*(){return yield this.instance.get(`arbitrary-call/${e}`)})}fetchContractArbitraryCallRequests(e,t){return l(this,null,function*(){let r=new Map;return e&&r.set("deployedContractId",e),t&&r.set("contractAddress",t),(yield this.instance.get(`arbitrary-call/by-project/${this.projectId}`,{params:r})).requests})}};var Ls=class{constructor(){this.deployableContracts=new Map;}static instance(){return this.classInstance||(this.classInstance=new Ls),this.classInstance}getManifest(e){return l(this,null,function*(){yield this.lazyInit();let t=this.deployableContracts.get(e);if(!t)throw new Ee(`DeployableContractsService:: Fatal error. No contract found with id ${e}`);return t})}lazyInit(){return l(this,null,function*(){if(this.deployableContracts.size===0){let e=yield O.instance().fetchDeployableContracts({tags:[],implements:[]});this.deployableContracts=e.deployable_contracts.reduce((t,r)=>(t.set(r.id,r),t),this.deployableContracts);}})}};var xt=class{static instance(){return xt._instance||(xt._instance=new xt),xt._instance}encodeConstructorInputs(e,t){if(e.length===0)return [];let s=this.getConstructorDecoratorFromManifest(t,e.length).inputs;return this.encodeInputsImpl(e,s)}encodeInputs(e,t,r){if(t.length===0)return [];let i=this.getFunctionDecoratorFromManifest(e,r).inputs;return this.encodeInputsImpl(t,i)}encodeOutputTypes(e,t){let s=this.getFunctionDecoratorFromManifest(e,t).outputs;return this.encodeOutputTypesImpl(s)}encodeInputsImpl(e,t){return t?t.map((r,s)=>{let i=r.solidity_type,a=this.encodeInputValue(e[s],r,i);return {type:i,value:a}}):[]}encodeOutputTypesImpl(e){return e?e.map(t=>{if(t.solidity_type.startsWith("tuple")){let r=this.encodeOutputTypesImpl(t.parameters);return {type:t.solidity_type,elems:r}}else return t.solidity_type}):[]}encodeInputValue(e,t,r){if(r.endsWith("]")){let s=r.substring(0,r.lastIndexOf("["));return (e!=null?e:[]).map(i=>this.encodeInputValue(i,t,s))}else if(r.startsWith("tuple")){let s=t.parameters;if(!s)throw new Ee(`Expected tuple definition but nothing found for decorator ${t.name} and function ${t.solidity_name}`);return (e!=null?e:[]).map((i,a)=>({type:s[a].solidity_type,value:this.encodeInputValue(i,s[a],s[a].solidity_type)}))}else {if(r==="bool")return !!e;if(r.startsWith("bytes"))return (e!=null?e:[]).map(s=>String(s));if(r.startsWith("uint")||r.startsWith("int")||r.startsWith("byte")||r.startsWith("address")||r.startsWith("string"))return String(e);throw new Ee(`Could not parse solidity type: ${r} for function ${t.name}`)}}getConstructorDecoratorFromManifest(e,t){let r=e.constructors.find(s=>s.inputs.length===t);if(!r)throw new Ee(`Can't deploy contract. Constructor with ${t} param(s) not found in contract descriptor.`);return r}getFunctionDecoratorFromManifest(e,t){let r=t.functions.find(s=>s.solidity_name===e);if(!r)throw new Ee(`Can't call execute on a contract . Function ${e} not found in contract descriptor.`);return r}};var Xr=class{constructor(e){this.defaultCaller="0x0000000000000000000000000000000000000000";this.defaultEthAmount="0";this.deploymentRequest=e;}buildAction(e,t,r){return l(this,null,function*(){var o;let s=yield Ls.instance().getManifest(this.deploymentRequest.contract_id),i=xt.instance().encodeInputs(e,t,s),a=yield O.instance().createFunctionCallRequest({deployed_contract_id:this.deploymentRequest.id,function_name:e,function_params:i,eth_amount:(o=r==null?void 0:r.ethAmount)!=null?o:this.defaultEthAmount,arbitrary_data:r==null?void 0:r.arbitraryData,screen_config:r==null?void 0:r.screenConfig,caller_address:r==null?void 0:r.callerAddress,redirect_url:r==null?void 0:r.redirectUrl});return new mt(a)})}read(e,t){return l(this,null,function*(){if(this.deploymentRequest.status!=="SUCCESS")return Promise.reject(new Ee(`Can't read state on a contract with deployment status: ${this.deploymentRequest.status}`));let r=yield Ls.instance().getManifest(this.deploymentRequest.contract_id),s=xt.instance().encodeInputs(e,t,r),i=xt.instance().encodeOutputTypes(e,r);return yield O.instance().readContract({deployed_contract_id:this.deploymentRequest.id,function_name:e,function_params:s,output_params:i,caller_address:this.defaultCaller})})}};var le={};Od(le,{AbiCoder:()=>Gt,AbstractProvider:()=>jt,AbstractSigner:()=>Jt,AlchemyProvider:()=>Er,AnkrProvider:()=>Gr,BaseContract:()=>kn,BaseWallet:()=>Un,Block:()=>di,BrowserProvider:()=>iu,CloudflareProvider:()=>Ni,ConstructorFragment:()=>nt,Contract:()=>ft,ContractEventPayload:()=>hi,ContractFactory:()=>mi,ContractTransactionReceipt:()=>Ya,ContractTransactionResponse:()=>Rn,ContractUnknownEventPayload:()=>os,EnsPlugin:()=>_r,EnsResolver:()=>Pn,ErrorDescription:()=>Wa,ErrorFragment:()=>ke,EtherSymbol:()=>z0,EtherscanPlugin:()=>Ii,EtherscanProvider:()=>Ti,EventFragment:()=>Ke,EventLog:()=>En,EventPayload:()=>rn,FallbackFragment:()=>ut,FallbackProvider:()=>_i,FeeData:()=>is,FeeDataNetworkPlugin:()=>Dc,FetchCancelSignal:()=>oa,FetchRequest:()=>ce,FetchResponse:()=>sr,FetchUrlFeeDataNetworkPlugin:()=>ls,FixedNumber:()=>qn,Fragment:()=>kt,FunctionFragment:()=>je,GasCostPlugin:()=>Ur,HDNodeVoidWallet:()=>Qr,HDNodeWallet:()=>Wr,Indexed:()=>fi,InfuraProvider:()=>kr,InfuraWebSocketProvider:()=>Eo,Interface:()=>wn,IpcSocketProvider:()=>id,JsonRpcApiProvider:()=>As,JsonRpcProvider:()=>Pe,JsonRpcSigner:()=>ws,LangEn:()=>Ze,Log:()=>Pt,LogDescription:()=>ja,MaxInt256:()=>H0,MaxUint256:()=>G0,MessagePrefix:()=>pc,MinInt256:()=>q0,Mnemonic:()=>Tt,MulticoinProviderPlugin:()=>Xa,N:()=>L0,NamedFragment:()=>yn,Network:()=>X,NetworkPlugin:()=>St,NonceManager:()=>su,ParamType:()=>Ae,PocketProvider:()=>vs,QuickNodeProvider:()=>qr,Result:()=>ln,Signature:()=>_e,SigningKey:()=>De,SocketBlockSubscriber:()=>wo,SocketEventSubscriber:()=>Co,SocketPendingSubscriber:()=>Ao,SocketProvider:()=>Fi,SocketSubscriber:()=>ks,StructFragment:()=>Mt,Transaction:()=>Rt,TransactionDescription:()=>Ja,TransactionReceipt:()=>Cn,TransactionResponse:()=>Or,Typed:()=>ae,TypedDataEncoder:()=>Dt,UndecodedEventLog:()=>as,UnmanagedSubscriber:()=>Ar,Utf8ErrorFuncs:()=>Ru,VoidSigner:()=>Ri,Wallet:()=>_o,WebSocketProvider:()=>On,WeiPerEther:()=>M0,Wordlist:()=>Li,WordlistOwl:()=>_n,WordlistOwlA:()=>xu,ZeroAddress:()=>Xn,ZeroHash:()=>wa,accessListify:()=>Me,assert:()=>w,assertArgument:()=>h,assertArgumentCount:()=>Gs,assertNormalize:()=>qs,assertPrivate:()=>Fe,checkResultErrors:()=>Fu,computeAddress:()=>gr,computeHmac:()=>wt,concat:()=>q,copyRequest:()=>Fr,dataLength:()=>it,dataSlice:()=>J,decodeBase58:()=>Ho,decodeBase64:()=>zo,decodeBytes32String:()=>gf,decodeRlp:()=>$s,decryptCrowdsaleJson:()=>Fo,decryptKeystoreJson:()=>fu,decryptKeystoreJsonSync:()=>lu,defaultPath:()=>Bo,defineProperties:()=>I,dnsEncode:()=>Rc,encodeBase58:()=>Vs,encodeBase64:()=>Vo,encodeBytes32String:()=>mf,encodeRlp:()=>Sr,encryptKeystoreJson:()=>Ki,encryptKeystoreJsonSync:()=>Vi,ensNormalize:()=>dl,formatEther:()=>w0,formatUnits:()=>Su,fromTwos:()=>en,getAccountPath:()=>yd,getAddress:()=>M,getBigInt:()=>T,getBytes:()=>S,getBytesCopy:()=>he,getCreate2Address:()=>j0,getCreateAddress:()=>oi,getDefaultProvider:()=>sd,getIcapAddress:()=>K0,getIndexedAccountPath:()=>wd,getNumber:()=>D,getUint:()=>zs,hashMessage:()=>Ma,hexlify:()=>v,id:()=>Le,isAddress:()=>W0,isAddressable:()=>ka,isBytesLike:()=>Hs,isCallException:()=>Ln,isCrowdsaleJson:()=>Oo,isError:()=>ge,isHexString:()=>K,isKeystoreJson:()=>To,isValidName:()=>sf,keccak256:()=>V,lock:()=>yp,makeError:()=>re,mask:()=>gt,namehash:()=>es,parseEther:()=>A0,parseUnits:()=>Nu,pbkdf2:()=>et,randomBytes:()=>Ve,recoverAddress:()=>pn,resolveAddress:()=>me,resolveProperties:()=>oe,ripemd160:()=>lr,scrypt:()=>fr,scryptSync:()=>dr,sha256:()=>Ie,sha512:()=>ni,showThrottleMessage:()=>st,solidityPacked:()=>kc,solidityPackedKeccak256:()=>uf,solidityPackedSha256:()=>lf,stripZerosLeft:()=>u0,toBeArray:()=>xe,toBeHex:()=>Te,toBigInt:()=>Ot,toNumber:()=>qo,toQuantity:()=>at,toTwos:()=>tn,toUtf8Bytes:()=>te,toUtf8CodePoints:()=>d0,toUtf8String:()=>ot,uuidV4:()=>ec,verifyMessage:()=>cf,verifyTypedData:()=>hf,version:()=>Xi,wordlists:()=>Cd,zeroPadBytes:()=>$r,zeroPadValue:()=>Ne});var Xi="6.7.1";function Om(n,e,t){let r=e.split("|").map(i=>i.trim());for(let i=0;i<r.length;i++)switch(e){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof n===e)return}let s=new Error(`invalid value for type ${e}`);throw s.code="INVALID_ARGUMENT",s.argument=`value.${t}`,s.value=n,s}function oe(n){return l(this,null,function*(){let e=Object.keys(n);return (yield Promise.all(e.map(r=>Promise.resolve(n[r])))).reduce((r,s,i)=>(r[e[i]]=s,r),{})})}function I(n,e,t){for(let r in e){let s=e[r],i=t?t[r]:null;i&&Om(s,i,r),Object.defineProperty(n,r,{enumerable:!0,value:s,writable:!1});}}function $i(n){if(n==null)return "null";if(Array.isArray(n))return "[ "+n.map($i).join(", ")+" ]";if(n instanceof Uint8Array){let e="0123456789abcdef",t="0x";for(let r=0;r<n.length;r++)t+=e[n[r]>>4],t+=e[n[r]&15];return t}if(typeof n=="object"&&typeof n.toJSON=="function")return $i(n.toJSON());switch(typeof n){case"boolean":case"symbol":return n.toString();case"bigint":return BigInt(n).toString();case"number":return n.toString();case"string":return JSON.stringify(n);case"object":{let e=Object.keys(n);return e.sort(),"{ "+e.map(t=>`${$i(t)}: ${$i(n[t])}`).join(", ")+" }"}}return "[ COULD NOT SERIALIZE ]"}function ge(n,e){return n&&n.code===e}function Ln(n){return ge(n,"CALL_EXCEPTION")}function re(n,e,t){{let s=[];if(t){if("message"in t||"code"in t||"name"in t)throw new Error(`value will overwrite populated values: ${$i(t)}`);for(let i in t){let a=t[i];s.push(i+"="+$i(a));}}s.push(`code=${e}`),s.push(`version=${Xi}`),s.length&&(n+=" ("+s.join(", ")+")");}let r;switch(e){case"INVALID_ARGUMENT":r=new TypeError(n);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":r=new RangeError(n);break;default:r=new Error(n);}return I(r,{code:e}),t&&Object.assign(r,t),r}function w(n,e,t,r){if(!n)throw re(e,t,r)}function h(n,e,t,r){w(n,e,"INVALID_ARGUMENT",{argument:t,value:r});}function Gs(n,e,t){t==null&&(t=""),t&&(t=": "+t),w(n>=e,"missing arguemnt"+t,"MISSING_ARGUMENT",{count:n,expectedCount:e}),w(n<=e,"too many arguemnts"+t,"UNEXPECTED_ARGUMENT",{count:n,expectedCount:e});}var Fm=["NFD","NFC","NFKD","NFKC"].reduce((n,e)=>{try{if("test".normalize(e)!=="test")throw new Error("bad");if(e==="NFD"){let t=String.fromCharCode(233).normalize("NFD"),r=String.fromCharCode(101,769);if(t!==r)throw new Error("broken")}n.push(e);}catch(t){}return n},[]);function qs(n){w(Fm.indexOf(n)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:n}});}function Fe(n,e,t){if(t==null&&(t=""),n!==e){let r=t,s="new";t&&(r+=".",s+=" "+t),w(!1,`private constructor; use ${r}from* methods`,"UNSUPPORTED_OPERATION",{operation:s});}}function Ud(n,e,t){if(n instanceof Uint8Array)return t?new Uint8Array(n):n;if(typeof n=="string"&&n.match(/^0x([0-9a-f][0-9a-f])*$/i)){let r=new Uint8Array((n.length-2)/2),s=2;for(let i=0;i<r.length;i++)r[i]=parseInt(n.substring(s,s+2),16),s+=2;return r}h(!1,"invalid BytesLike value",e||"value",n);}function S(n,e){return Ud(n,e,!1)}function he(n,e){return Ud(n,e,!0)}function K(n,e){return !(typeof n!="string"||!n.match(/^0x[0-9A-Fa-f]*$/)||typeof e=="number"&&n.length!==2+2*e||e===!0&&n.length%2!==0)}function Hs(n){return K(n,!0)||n instanceof Uint8Array}var Fd="0123456789abcdef";function v(n){let e=S(n),t="0x";for(let r=0;r<e.length;r++){let s=e[r];t+=Fd[(s&240)>>4]+Fd[s&15];}return t}function q(n){return "0x"+n.map(e=>v(e).substring(2)).join("")}function it(n){return K(n,!0)?(n.length-2)/2:S(n).length}function J(n,e,t){let r=S(n);return t!=null&&t>r.length&&w(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:t}),v(r.slice(e==null?0:e,t==null?r.length:t))}function u0(n){let e=v(n).substring(2);for(;e.startsWith("00");)e=e.substring(2);return "0x"+e}function _d(n,e,t){let r=S(n);w(e>=r.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(r),length:e,offset:e+1});let s=new Uint8Array(e);return s.fill(0),t?s.set(r,e-r.length):s.set(r,0),v(s)}function Ne(n,e){return _d(n,e,!0)}function $r(n,e){return _d(n,e,!1)}var Cu=BigInt(0),tr=BigInt(1),ea=9007199254740991;function en(n,e){let t=zs(n,"value"),r=BigInt(D(e,"width"));if(w(t>>r===Cu,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:n}),t>>r-tr){let s=(tr<<r)-tr;return -((~t&s)+tr)}return t}function tn(n,e){let t=T(n,"value"),r=BigInt(D(e,"width")),s=tr<<r-tr;if(t<Cu){t=-t,w(t<=s,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:n});let i=(tr<<r)-tr;return (~t&i)+tr}else w(t<s,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:n});return t}function gt(n,e){let t=zs(n,"value"),r=BigInt(D(e,"bits"));return t&(tr<<r)-tr}function T(n,e){switch(typeof n){case"bigint":return n;case"number":return h(Number.isInteger(n),"underflow",e||"value",n),h(n>=-ea&&n<=ea,"overflow",e||"value",n),BigInt(n);case"string":try{if(n==="")throw new Error("empty string");return n[0]==="-"&&n[1]!=="-"?-BigInt(n.substring(1)):BigInt(n)}catch(t){h(!1,`invalid BigNumberish string: ${t.message}`,e||"value",n);}}h(!1,"invalid BigNumberish value",e||"value",n);}function zs(n,e){let t=T(n,e);return w(t>=Cu,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:n}),t}var Dd="0123456789abcdef";function Ot(n){if(n instanceof Uint8Array){let e="0x0";for(let t of n)e+=Dd[t>>4],e+=Dd[t&15];return BigInt(e)}return T(n)}function D(n,e){switch(typeof n){case"bigint":return h(n>=-ea&&n<=ea,"overflow",e||"value",n),Number(n);case"number":return h(Number.isInteger(n),"underflow",e||"value",n),h(n>=-ea&&n<=ea,"overflow",e||"value",n),n;case"string":try{if(n==="")throw new Error("empty string");return D(BigInt(n),e)}catch(t){h(!1,`invalid numeric string: ${t.message}`,e||"value",n);}}h(!1,"invalid numeric value",e||"value",n);}function qo(n){return D(Ot(n))}function Te(n,e){let r=zs(n,"value").toString(16);if(e==null)r.length%2&&(r="0"+r);else {let s=D(e,"width");for(w(s*2>=r.length,`value exceeds width (${s} bits)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:n});r.length<s*2;)r="0"+r;}return "0x"+r}function xe(n){let e=zs(n,"value");if(e===Cu)return new Uint8Array([]);let t=e.toString(16);t.length%2&&(t="0"+t);let r=new Uint8Array(t.length/2);for(let s=0;s<r.length;s++){let i=s*2;r[s]=parseInt(t.substring(i,i+2),16);}return r}function at(n){let e=v(Hs(n)?n:xe(n)).substring(2);for(;e.startsWith("0");)e=e.substring(1);return e===""&&(e="0"),"0x"+e}var l0="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Eu=null;function Um(n){if(Eu==null){Eu={};for(let t=0;t<l0.length;t++)Eu[l0[t]]=BigInt(t);}let e=Eu[n];return h(e!=null,"invalid base58 value","letter",n),e}var _m=BigInt(0),f0=BigInt(58);function Vs(n){let e=Ot(S(n)),t="";for(;e;)t=l0[Number(e%f0)]+t,e/=f0;return t}function Ho(n){let e=_m;for(let t=0;t<n.length;t++)e*=f0,e+=Um(n[t]);return e}function zo(n){n=atob(n);let e=new Uint8Array(n.length);for(let t=0;t<n.length;t++)e[t]=n.charCodeAt(t);return S(e)}function Vo(n){let e=S(n),t="";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return btoa(t)}var ta,rn=class{constructor(e,t,r){g(this,"filter");g(this,"emitter");b(this,ta,void 0);p(this,ta,t),I(this,{emitter:e,filter:r});}removeListener(){return l(this,null,function*(){u(this,ta)!=null&&(yield this.emitter.off(this.filter,u(this,ta)));})}};ta=new WeakMap;function Dm(n,e,t,r,s){h(!1,`invalid codepoint at offset ${e}; ${n}`,"bytes",t);}function Ld(n,e,t,r,s){if(n==="BAD_PREFIX"||n==="UNEXPECTED_CONTINUE"){let i=0;for(let a=e+1;a<t.length&&t[a]>>6===2;a++)i++;return i}return n==="OVERRUN"?t.length-e-1:0}function Lm(n,e,t,r,s){return n==="OVERLONG"?(h(typeof s=="number","invalid bad code point for replacement","badCodepoint",s),r.push(s),0):(r.push(65533),Ld(n,e,t))}var Ru=Object.freeze({error:Dm,ignore:Ld,replace:Lm});function Md(n,e){e==null&&(e=Ru.error);let t=S(n,"bytes"),r=[],s=0;for(;s<t.length;){let i=t[s++];if(!(i>>7)){r.push(i);continue}let a=null,o=null;if((i&224)===192)a=1,o=127;else if((i&240)===224)a=2,o=2047;else if((i&248)===240)a=3,o=65535;else {(i&192)===128?s+=e("UNEXPECTED_CONTINUE",s-1,t,r):s+=e("BAD_PREFIX",s-1,t,r);continue}if(s-1+a>=t.length){s+=e("OVERRUN",s-1,t,r);continue}let c=i&(1<<8-a-1)-1;for(let f=0;f<a;f++){let d=t[s];if((d&192)!=128){s+=e("MISSING_CONTINUE",s,t,r),c=null;break}c=c<<6|d&63,s++;}if(c!==null){if(c>1114111){s+=e("OUT_OF_RANGE",s-1-a,t,r,c);continue}if(c>=55296&&c<=57343){s+=e("UTF16_SURROGATE",s-1-a,t,r,c);continue}if(c<=o){s+=e("OVERLONG",s-1-a,t,r,c);continue}r.push(c);}}return r}function te(n,e){e!=null&&(qs(e),n=n.normalize(e));let t=[];for(let r=0;r<n.length;r++){let s=n.charCodeAt(r);if(s<128)t.push(s);else if(s<2048)t.push(s>>6|192),t.push(s&63|128);else if((s&64512)==55296){r++;let i=n.charCodeAt(r);h(r<n.length&&(i&64512)===56320,"invalid surrogate pair","str",n);let a=65536+((s&1023)<<10)+(i&1023);t.push(a>>18|240),t.push(a>>12&63|128),t.push(a>>6&63|128),t.push(a&63|128);}else t.push(s>>12|224),t.push(s>>6&63|128),t.push(s&63|128);}return new Uint8Array(t)}function Mm(n){return n.map(e=>e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10&1023)+55296,(e&1023)+56320))).join("")}function ot(n,e){return Mm(Md(n,e))}function d0(n,e){return Md(te(n,e))}function Gd(n,e){return l(this,null,function*(){let t=n.url.split(":")[0].toLowerCase();w(t==="http"||t==="https",`unsupported protocol ${t}`,"UNSUPPORTED_OPERATION",{info:{protocol:t},operation:"request"}),w(t==="https"||!n.credentials||n.allowInsecureAuthentication,"insecure authorized connections unsupported","UNSUPPORTED_OPERATION",{operation:"request"});let r;if(e){let f=new AbortController;r=f.signal,e.addListener(()=>{f.abort();});}let s={method:n.method,headers:new Headers(Array.from(n)),body:n.body||void 0,signal:r},i=yield fetch(n.url,s),a={};i.headers.forEach((f,d)=>{a[d.toLowerCase()]=f;});let o=yield i.arrayBuffer(),c=o==null?null:new Uint8Array(o);return {statusCode:i.status,statusMessage:i.statusText,headers:a,body:c}})}var Gm=12,qm=250,qd=Gd,Hm=new RegExp("^data:([^;:]*)?(;base64)?,(.*)$","i"),zm=new RegExp("^ipfs://(ipfs/)?(.*)$","i"),h0=!1;function zd(n,e){return l(this,null,function*(){try{let t=n.match(Hm);if(!t)throw new Error("invalid data");return new sr(200,"OK",{"content-type":t[1]||"text/plain"},t[2]?zo(t[3]):Vm(t[3]))}catch(t){return new sr(599,"BAD REQUEST (invalid data: URI)",{},null,new ce(n))}})}function Vd(n){function e(t,r){return l(this,null,function*(){try{let s=t.match(zm);if(!s)throw new Error("invalid link");return new ce(`${n}${s[2]}`)}catch(s){return new sr(599,"BAD REQUEST (invalid IPFS URI)",{},null,new ce(t))}})}return e}var ku={data:zd,ipfs:Vd("https://gateway.ipfs.io/ipfs/")},Kd=new WeakMap,Ks,Mn,oa=class{constructor(e){b(this,Ks,void 0);b(this,Mn,void 0);p(this,Ks,[]),p(this,Mn,!1),Kd.set(e,()=>{if(!u(this,Mn)){p(this,Mn,!0);for(let t of u(this,Ks))setTimeout(()=>{t();},0);p(this,Ks,[]);}});}addListener(e){w(!u(this,Mn),"singal already cancelled","UNSUPPORTED_OPERATION",{operation:"fetchCancelSignal.addCancelListener"}),u(this,Ks).push(e);}get cancelled(){return u(this,Mn)}checkSignal(){w(!this.cancelled,"cancelled","CANCELLED",{});}};Ks=new WeakMap,Mn=new WeakMap;function Pu(n){if(n==null)throw new Error("missing signal; should not happen");return n.checkSignal(),n}var ra,na,rr,nn,sa,ia,Be,bt,sn,js,Js,Ws,vr,an,Qs,Ko,vu=class{constructor(e){b(this,Qs);b(this,ra,void 0);b(this,na,void 0);b(this,rr,void 0);b(this,nn,void 0);b(this,sa,void 0);b(this,ia,void 0);b(this,Be,void 0);b(this,bt,void 0);b(this,sn,void 0);b(this,js,void 0);b(this,Js,void 0);b(this,Ws,void 0);b(this,vr,void 0);b(this,an,void 0);p(this,ia,String(e)),p(this,ra,!1),p(this,na,!0),p(this,rr,{}),p(this,nn,""),p(this,sa,3e5),p(this,an,{slotInterval:qm,maxAttempts:Gm});}get url(){return u(this,ia)}set url(e){p(this,ia,String(e));}get body(){return u(this,Be)==null?null:new Uint8Array(u(this,Be))}set body(e){if(e==null)p(this,Be,void 0),p(this,bt,void 0);else if(typeof e=="string")p(this,Be,te(e)),p(this,bt,"text/plain");else if(e instanceof Uint8Array)p(this,Be,e),p(this,bt,"application/octet-stream");else if(typeof e=="object")p(this,Be,te(JSON.stringify(e))),p(this,bt,"application/json");else throw new Error("invalid body")}hasBody(){return u(this,Be)!=null}get method(){return u(this,nn)?u(this,nn):this.hasBody()?"POST":"GET"}set method(e){e==null&&(e=""),p(this,nn,String(e).toUpperCase());}get headers(){let e=Object.assign({},u(this,rr));return u(this,sn)&&(e.authorization=`Basic ${Vo(te(u(this,sn)))}`),this.allowGzip&&(e["accept-encoding"]="gzip"),e["content-type"]==null&&u(this,bt)&&(e["content-type"]=u(this,bt)),this.body&&(e["content-length"]=String(this.body.length)),e}getHeader(e){return this.headers[e.toLowerCase()]}setHeader(e,t){u(this,rr)[String(e).toLowerCase()]=String(t);}clearHeaders(){p(this,rr,{});}[Symbol.iterator](){let e=this.headers,t=Object.keys(e),r=0;return {next:()=>{if(r<t.length){let s=t[r++];return {value:[s,e[s]],done:!1}}return {value:void 0,done:!0}}}}get credentials(){return u(this,sn)||null}setCredentials(e,t){h(!e.match(/:/),"invalid basic authentication username","username","[REDACTED]"),p(this,sn,`${e}:${t}`);}get allowGzip(){return u(this,na)}set allowGzip(e){p(this,na,!!e);}get allowInsecureAuthentication(){return !!u(this,ra)}set allowInsecureAuthentication(e){p(this,ra,!!e);}get timeout(){return u(this,sa)}set timeout(e){h(e>=0,"timeout must be non-zero","timeout",e),p(this,sa,e);}get preflightFunc(){return u(this,js)||null}set preflightFunc(e){p(this,js,e);}get processFunc(){return u(this,Js)||null}set processFunc(e){p(this,Js,e);}get retryFunc(){return u(this,Ws)||null}set retryFunc(e){p(this,Ws,e);}toString(){return `<FetchRequest method=${JSON.stringify(this.method)} url=${JSON.stringify(this.url)} headers=${JSON.stringify(this.headers)} body=${u(this,Be)?v(u(this,Be)):"null"}>`}setThrottleParams(e){e.slotInterval!=null&&(u(this,an).slotInterval=e.slotInterval),e.maxAttempts!=null&&(u(this,an).maxAttempts=e.maxAttempts);}send(){return w(u(this,vr)==null,"request already sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.send"}),p(this,vr,new oa(this)),P(this,Qs,Ko).call(this,0,Hd()+this.timeout,0,this,new sr(0,"",{},null,this))}cancel(){w(u(this,vr)!=null,"request has not been sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.cancel"});let e=Kd.get(this);if(!e)throw new Error("missing signal; should not happen");e();}redirect(e){let t=this.url.split(":")[0].toLowerCase(),r=e.split(":")[0].toLowerCase();w(this.method==="GET"&&(t!=="https"||r!=="http")&&e.match(/^https?:/),"unsupported redirect","UNSUPPORTED_OPERATION",{operation:`redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(e)})`});let s=new vu(e);return s.method="GET",s.allowGzip=this.allowGzip,s.timeout=this.timeout,p(s,rr,Object.assign({},u(this,rr))),u(this,Be)&&p(s,Be,new Uint8Array(u(this,Be))),p(s,bt,u(this,bt)),s}clone(){let e=new vu(this.url);return p(e,nn,u(this,nn)),u(this,Be)&&p(e,Be,u(this,Be)),p(e,bt,u(this,bt)),p(e,rr,Object.assign({},u(this,rr))),p(e,sn,u(this,sn)),this.allowGzip&&(e.allowGzip=!0),e.timeout=this.timeout,this.allowInsecureAuthentication&&(e.allowInsecureAuthentication=!0),p(e,js,u(this,js)),p(e,Js,u(this,Js)),p(e,Ws,u(this,Ws)),e}static lockConfig(){h0=!0;}static getGateway(e){return ku[e.toLowerCase()]||null}static registerGateway(e,t){if(e=e.toLowerCase(),e==="http"||e==="https")throw new Error(`cannot intercept ${e}; use registerGetUrl`);if(h0)throw new Error("gateways locked");ku[e]=t;}static registerGetUrl(e){if(h0)throw new Error("gateways locked");qd=e;}static createDataGateway(){return zd}static createIpfsGatewayFunc(e){return Vd(e)}},ce=vu;ra=new WeakMap,na=new WeakMap,rr=new WeakMap,nn=new WeakMap,sa=new WeakMap,ia=new WeakMap,Be=new WeakMap,bt=new WeakMap,sn=new WeakMap,js=new WeakMap,Js=new WeakMap,Ws=new WeakMap,vr=new WeakMap,an=new WeakMap,Qs=new WeakSet,Ko=function(e,t,r,s,i){return l(this,null,function*(){var d,x,m;if(e>=u(this,an).maxAttempts)return i.makeServerError("exceeded maximum retry limit");w(Hd()<=t,"timeout","TIMEOUT",{operation:"request.send",reason:"timeout",request:s}),r>0&&(yield Km(r));let a=this.clone(),o=(a.url.split(":")[0]||"").toLowerCase();if(o in ku){let y=yield ku[o](a.url,Pu(u(s,vr)));if(y instanceof sr){let k=y;if(this.processFunc){Pu(u(s,vr));try{k=yield this.processFunc(a,k);}catch(N){(N.throttle==null||typeof N.stall!="number")&&k.makeServerError("error in post-processing function",N).assertOk();}}return k}a=y;}this.preflightFunc&&(a=yield this.preflightFunc(a));let c=yield qd(a,Pu(u(s,vr))),f=new sr(c.statusCode,c.statusMessage,c.headers,c.body,s);if(f.statusCode===301||f.statusCode===302){try{let y=f.headers.location||"";return P(d=a.redirect(y),Qs,Ko).call(d,e+1,t,0,s,f)}catch(y){}return f}else if(f.statusCode===429&&(this.retryFunc==null||(yield this.retryFunc(a,f,e)))){let y=f.headers["retry-after"],k=u(this,an).slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return typeof y=="string"&&y.match(/^[1-9][0-9]*$/)&&(k=parseInt(y)),P(x=a.clone(),Qs,Ko).call(x,e+1,t,k,s,f)}if(this.processFunc){Pu(u(s,vr));try{f=yield this.processFunc(a,f);}catch(y){(y.throttle==null||typeof y.stall!="number")&&f.makeServerError("error in post-processing function",y).assertOk();let k=u(this,an).slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return y.stall>=0&&(k=y.stall),P(m=a.clone(),Qs,Ko).call(m,e+1,t,k,s,f)}}return f})};var jo,Jo,Wo,nr,aa,Ys,p0=class{constructor(e,t,r,s,i){b(this,jo,void 0);b(this,Jo,void 0);b(this,Wo,void 0);b(this,nr,void 0);b(this,aa,void 0);b(this,Ys,void 0);p(this,jo,e),p(this,Jo,t),p(this,Wo,Object.keys(r).reduce((a,o)=>(a[o.toLowerCase()]=String(r[o]),a),{})),p(this,nr,s==null?null:new Uint8Array(s)),p(this,aa,i||null),p(this,Ys,{message:""});}toString(){return `<FetchResponse status=${this.statusCode} body=${u(this,nr)?v(u(this,nr)):"null"}>`}get statusCode(){return u(this,jo)}get statusMessage(){return u(this,Jo)}get headers(){return Object.assign({},u(this,Wo))}get body(){return u(this,nr)==null?null:new Uint8Array(u(this,nr))}get bodyText(){try{return u(this,nr)==null?"":ot(u(this,nr))}catch(e){w(!1,"response body is not valid UTF-8 data","UNSUPPORTED_OPERATION",{operation:"bodyText",info:{response:this}});}}get bodyJson(){try{return JSON.parse(this.bodyText)}catch(e){w(!1,"response body is not valid JSON","UNSUPPORTED_OPERATION",{operation:"bodyJson",info:{response:this}});}}[Symbol.iterator](){let e=this.headers,t=Object.keys(e),r=0;return {next:()=>{if(r<t.length){let s=t[r++];return {value:[s,e[s]],done:!1}}return {value:void 0,done:!0}}}}makeServerError(e,t){let r;e?r=`CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${e})`:(e=`${this.statusCode} ${this.statusMessage}`,r=`CLIENT ESCALATED SERVER ERROR (${e})`);let s=new p0(599,r,this.headers,this.body,u(this,aa)||void 0);return p(s,Ys,{message:e,error:t}),s}throwThrottleError(e,t){t==null?t=-1:h(Number.isInteger(t)&&t>=0,"invalid stall timeout","stall",t);let r=new Error(e||"throttling requests");throw I(r,{stall:t,throttle:!0}),r}getHeader(e){return this.headers[e.toLowerCase()]}hasBody(){return u(this,nr)!=null}get request(){return u(this,aa)}ok(){return u(this,Ys).message===""&&this.statusCode>=200&&this.statusCode<300}assertOk(){if(this.ok())return;let{message:e,error:t}=u(this,Ys);e===""&&(e=`server response ${this.statusCode} ${this.statusMessage}`),w(!1,e,"SERVER_ERROR",{request:this.request||"unknown request",response:this,error:t});}},sr=p0;jo=new WeakMap,Jo=new WeakMap,Wo=new WeakMap,nr=new WeakMap,aa=new WeakMap,Ys=new WeakMap;function Hd(){return new Date().getTime()}function Vm(n){return te(n.replace(/%([0-9a-f][0-9a-f])/gi,(e,t)=>String.fromCharCode(parseInt(t,16))))}function Km(n){return new Promise(e=>setTimeout(e,n))}var jm=BigInt(-1),ir=BigInt(0),ua=BigInt(1),Jm=BigInt(5),ca={},la="0000";for(;la.length<80;)la+=la;function Zs(n){let e=la;for(;e.length<n;)e+=e;return BigInt("1"+e.substring(0,n))}function Qo(n,e,t){let r=BigInt(e.width);if(e.signed){let s=ua<<r-ua;w(t==null||n>=-s&&n<s,"overflow","NUMERIC_FAULT",{operation:t,fault:"overflow",value:n}),n>ir?n=en(gt(n,r),r):n=-en(gt(-n,r),r);}else {let s=ua<<r;w(t==null||n>=0&&n<s,"overflow","NUMERIC_FAULT",{operation:t,fault:"overflow",value:n}),n=(n%s+s)%s&s-ua;}return n}function x0(n){typeof n=="number"&&(n=`fixed128x${n}`);let e=!0,t=128,r=18;if(typeof n=="string"){if(n!=="fixed")if(n==="ufixed")e=!1;else {let i=n.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);h(i,"invalid fixed format","format",n),e=i[1]!=="u",t=parseInt(i[2]),r=parseInt(i[3]);}}else if(n){let i=n,a=(o,c,f)=>i[o]==null?f:(h(typeof i[o]===c,"invalid fixed format ("+o+" not "+c+")","format."+o,i[o]),i[o]);e=a("signed","boolean",e),t=a("width","number",t),r=a("decimals","number",r);}h(t%8===0,"invalid FixedNumber width (not byte aligned)","format.width",t),h(r<=80,"invalid FixedNumber decimals (too large)","format.decimals",r);let s=(e?"":"u")+"fixed"+String(t)+"x"+String(r);return {signed:e,width:t,decimals:r,name:s}}function Wm(n,e){let t="";n<ir&&(t="-",n*=jm);let r=n.toString();if(e===0)return t+r;for(;r.length<=e;)r=la+r;let s=r.length-e;for(r=r.substring(0,s)+"."+r.substring(s);r[0]==="0"&&r[1]!==".";)r=r.substring(1);for(;r[r.length-1]==="0"&&r[r.length-2]!==".";)r=r.substring(0,r.length-1);return t+r}var ar,se,$e,cn,Xs,or,on,Yo,m0,Zo,g0,Xo,b0,$o,y0,Gn=class{constructor(e,t,r){b(this,cn);b(this,or);b(this,Yo);b(this,Zo);b(this,Xo);b(this,$o);g(this,"format");b(this,ar,void 0);b(this,se,void 0);b(this,$e,void 0);g(this,"_value");Fe(e,ca,"FixedNumber"),p(this,se,t),p(this,ar,r);let s=Wm(t,r.decimals);I(this,{format:r.name,_value:s}),p(this,$e,Zs(r.decimals));}get signed(){return u(this,ar).signed}get width(){return u(this,ar).width}get decimals(){return u(this,ar).decimals}get value(){return u(this,se)}addUnsafe(e){return P(this,Yo,m0).call(this,e)}add(e){return P(this,Yo,m0).call(this,e,"add")}subUnsafe(e){return P(this,Zo,g0).call(this,e)}sub(e){return P(this,Zo,g0).call(this,e,"sub")}mulUnsafe(e){return P(this,Xo,b0).call(this,e)}mul(e){return P(this,Xo,b0).call(this,e,"mul")}mulSignal(e){P(this,cn,Xs).call(this,e);let t=u(this,se)*u(e,se);return w(t%u(this,$e)===ir,"precision lost during signalling mul","NUMERIC_FAULT",{operation:"mulSignal",fault:"underflow",value:this}),P(this,or,on).call(this,t/u(this,$e),"mulSignal")}divUnsafe(e){return P(this,$o,y0).call(this,e)}div(e){return P(this,$o,y0).call(this,e,"div")}divSignal(e){w(u(e,se)!==ir,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),P(this,cn,Xs).call(this,e);let t=u(this,se)*u(this,$e);return w(t%u(e,se)===ir,"precision lost during signalling div","NUMERIC_FAULT",{operation:"divSignal",fault:"underflow",value:this}),P(this,or,on).call(this,t/u(e,se),"divSignal")}cmp(e){let t=this.value,r=e.value,s=this.decimals-e.decimals;return s>0?r*=Zs(s):s<0&&(t*=Zs(-s)),t<r?-1:t>r?1:0}eq(e){return this.cmp(e)===0}lt(e){return this.cmp(e)<0}lte(e){return this.cmp(e)<=0}gt(e){return this.cmp(e)>0}gte(e){return this.cmp(e)>=0}floor(){let e=u(this,se);return u(this,se)<ir&&(e-=u(this,$e)-ua),e=u(this,se)/u(this,$e)*u(this,$e),P(this,or,on).call(this,e,"floor")}ceiling(){let e=u(this,se);return u(this,se)>ir&&(e+=u(this,$e)-ua),e=u(this,se)/u(this,$e)*u(this,$e),P(this,or,on).call(this,e,"ceiling")}round(e){if(e==null&&(e=0),e>=this.decimals)return this;let t=this.decimals-e,r=Jm*Zs(t-1),s=this.value+r,i=Zs(t);return s=s/i*i,Qo(s,u(this,ar),"round"),new Gn(ca,s,u(this,ar))}isZero(){return u(this,se)===ir}isNegative(){return u(this,se)<ir}toString(){return this._value}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(e){return Gn.fromString(this.toString(),e)}static fromValue(e,t,r){let s=t==null?0:D(t),i=x0(r),a=T(e,"value"),o=s-i.decimals;if(o>0){let c=Zs(o);w(a%c===ir,"value loses precision for format","NUMERIC_FAULT",{operation:"fromValue",fault:"underflow",value:e}),a/=c;}else o<0&&(a*=Zs(-o));return Qo(a,i,"fromValue"),new Gn(ca,a,i)}static fromString(e,t){let r=e.match(/^(-?)([0-9]*)\.?([0-9]*)$/);h(r&&r[2].length+r[3].length>0,"invalid FixedNumber string value","value",e);let s=x0(t),i=r[2]||"0",a=r[3]||"";for(;a.length<s.decimals;)a+=la;w(a.substring(s.decimals).match(/^0*$/),"too many decimals for format","NUMERIC_FAULT",{operation:"fromString",fault:"underflow",value:e}),a=a.substring(0,s.decimals);let o=BigInt(r[1]+i+a);return Qo(o,s,"fromString"),new Gn(ca,o,s)}static fromBytes(e,t){let r=Ot(S(e,"value")),s=x0(t);return s.signed&&(r=en(r,s.width)),Qo(r,s,"fromBytes"),new Gn(ca,r,s)}},qn=Gn;ar=new WeakMap,se=new WeakMap,$e=new WeakMap,cn=new WeakSet,Xs=function(e){h(this.format===e.format,"incompatible format; use fixedNumber.toFormat","other",e);},or=new WeakSet,on=function(e,t){return e=Qo(e,u(this,ar),t),new Gn(ca,e,u(this,ar))},Yo=new WeakSet,m0=function(e,t){return P(this,cn,Xs).call(this,e),P(this,or,on).call(this,u(this,se)+u(e,se),t)},Zo=new WeakSet,g0=function(e,t){return P(this,cn,Xs).call(this,e),P(this,or,on).call(this,u(this,se)-u(e,se),t)},Xo=new WeakSet,b0=function(e,t){return P(this,cn,Xs).call(this,e),P(this,or,on).call(this,u(this,se)*u(e,se)/u(this,$e),t)},$o=new WeakSet,y0=function(e,t){return w(u(e,se)!==ir,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),P(this,cn,Xs).call(this,e),P(this,or,on).call(this,u(this,se)*u(this,$e)/u(e,se),t)};function Qm(n){let e=n.toString(16);for(;e.length<2;)e="0"+e;return "0x"+e}function jd(n,e,t){let r=0;for(let s=0;s<t;s++)r=r*256+n[e+s];return r}function Jd(n,e,t,r){let s=[];for(;t<e+1+r;){let i=Wd(n,t);s.push(i.result),t+=i.consumed,w(t<=e+1+r,"child data too short","BUFFER_OVERRUN",{buffer:n,length:r,offset:e});}return {consumed:1+r,result:s}}function Wd(n,e){w(n.length!==0,"data too short","BUFFER_OVERRUN",{buffer:n,length:0,offset:1});let t=r=>{w(r<=n.length,"data short segment too short","BUFFER_OVERRUN",{buffer:n,length:n.length,offset:r});};if(n[e]>=248){let r=n[e]-247;t(e+1+r);let s=jd(n,e+1,r);return t(e+1+r+s),Jd(n,e,e+1+r,r+s)}else if(n[e]>=192){let r=n[e]-192;return t(e+1+r),Jd(n,e,e+1,r)}else if(n[e]>=184){let r=n[e]-183;t(e+1+r);let s=jd(n,e+1,r);t(e+1+r+s);let i=v(n.slice(e+1+r,e+1+r+s));return {consumed:1+r+s,result:i}}else if(n[e]>=128){let r=n[e]-128;t(e+1+r);let s=v(n.slice(e+1,e+1+r));return {consumed:1+r,result:s}}return {consumed:1,result:Qm(n[e])}}function $s(n){let e=S(n,"data"),t=Wd(e,0);return h(t.consumed===e.length,"unexpected junk after rlp payload","data",n),t.result}function Qd(n){let e=[];for(;n;)e.unshift(n&255),n>>=8;return e}function Zd(n){if(Array.isArray(n)){let r=[];if(n.forEach(function(i){r=r.concat(Zd(i));}),r.length<=55)return r.unshift(192+r.length),r;let s=Qd(r.length);return s.unshift(247+s.length),s.concat(r)}let e=Array.prototype.slice.call(S(n,"object"));if(e.length===1&&e[0]<=127)return e;if(e.length<=55)return e.unshift(128+e.length),e;let t=Qd(e.length);return t.unshift(183+t.length),t.concat(e)}var Yd="0123456789abcdef";function Sr(n){let e="0x";for(let t of Zd(n))e+=Yd[t>>4],e+=Yd[t&15];return e}var Xd=["wei","kwei","mwei","gwei","szabo","finney","ether"];function Su(n,e){let t=18;if(typeof e=="string"){let r=Xd.indexOf(e);h(r>=0,"invalid unit","unit",e),t=3*r;}else e!=null&&(t=D(e,"unit"));return qn.fromValue(n,t,{decimals:t,width:512}).toString()}function Nu(n,e){h(typeof n=="string","value must be a string","value",n);let t=18;if(typeof e=="string"){let r=Xd.indexOf(e);h(r>=0,"invalid unit","unit",e),t=3*r;}else e!=null&&(t=D(e,"unit"));return qn.fromString(n,{decimals:t,width:512}).value}function w0(n){return Su(n,18)}function A0(n){return Nu(n,18)}function ec(n){let e=S(n,"randomBytes");e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=v(e);return [t.substring(2,10),t.substring(10,14),t.substring(14,18),t.substring(18,22),t.substring(22,34)].join("-")}var Ue=32,C0=new Uint8Array(Ue),Ym=["then"],Iu={};function tc(n,e){let t=new Error(`deferred error during ABI decoding triggered accessing ${n}`);throw t.error=e,t}var Hn,rc=class extends Array{constructor(...t){let r=t[0],s=t[1],i=(t[2]||[]).slice(),a=!0;r!==Iu&&(s=t,i=[],a=!1);super(s.length);b(this,Hn,void 0);s.forEach((c,f)=>{this[f]=c;});let o=i.reduce((c,f)=>(typeof f=="string"&&c.set(f,(c.get(f)||0)+1),c),new Map);if(p(this,Hn,Object.freeze(s.map((c,f)=>{let d=i[f];return d!=null&&o.get(d)===1?d:null}))),!!a)return Object.freeze(this),new Proxy(this,{get:(c,f,d)=>{if(typeof f=="string"){if(f.match(/^[0-9]+$/)){let m=D(f,"%index");if(m<0||m>=this.length)throw new RangeError("out of result range");let y=c[m];return y instanceof Error&&tc(`index ${m}`,y),y}if(Ym.indexOf(f)>=0)return Reflect.get(c,f,d);let x=c[f];if(x instanceof Function)return function(...m){return x.apply(this===d?c:this,m)};if(!(f in c))return c.getValue.apply(this===d?c:this,[f])}return Reflect.get(c,f,d)}})}toArray(){let t=[];return this.forEach((r,s)=>{r instanceof Error&&tc(`index ${s}`,r),t.push(r);}),t}toObject(){return u(this,Hn).reduce((t,r,s)=>(w(r!=null,"value at index ${ index } unnamed","UNSUPPORTED_OPERATION",{operation:"toObject()"}),r in t||(t[r]=this.getValue(r)),t),{})}slice(t,r){t==null&&(t=0),t<0&&(t+=this.length,t<0&&(t=0)),r==null&&(r=this.length),r<0&&(r+=this.length,r<0&&(r=0)),r>this.length&&(r=this.length);let s=[],i=[];for(let a=t;a<r;a++)s.push(this[a]),i.push(u(this,Hn)[a]);return new rc(Iu,s,i)}filter(t,r){let s=[],i=[];for(let a=0;a<this.length;a++){let o=this[a];o instanceof Error&&tc(`index ${a}`,o),t.call(r,o,a,this)&&(s.push(o),i.push(u(this,Hn)[a]));}return new rc(Iu,s,i)}map(t,r){let s=[];for(let i=0;i<this.length;i++){let a=this[i];a instanceof Error&&tc(`index ${i}`,a),s.push(t.call(r,a,i,this));}return s}getValue(t){let r=u(this,Hn).indexOf(t);if(r===-1)return;let s=this[r];return s instanceof Error&&tc(`property ${JSON.stringify(t)}`,s.error),s}static fromItems(t,r){return new rc(Iu,t,r)}},ln=rc;Hn=new WeakMap;function Fu(n){let e=[],t=function(r,s){if(Array.isArray(s))for(let i in s){let a=r.slice();a.push(i);try{t(a,s[i]);}catch(o){e.push({path:a,error:o});}}};return t([],n),e}function $d(n){let e=xe(n);return w(e.length<=Ue,"value out-of-bounds","BUFFER_OVERRUN",{buffer:e,length:Ue,offset:e.length}),e.length!==Ue&&(e=he(q([C0.slice(e.length%Ue),e]))),e}var Re=class{constructor(e,t,r,s){g(this,"name");g(this,"type");g(this,"localName");g(this,"dynamic");I(this,{name:e,type:t,localName:r,dynamic:s},{name:"string",type:"string",localName:"string",dynamic:"boolean"});}_throwError(e,t){h(!1,e,this.localName,t);}},un,ei,fa,Tu,ti=class{constructor(){b(this,fa);b(this,un,void 0);b(this,ei,void 0);p(this,un,[]),p(this,ei,0);}get data(){return q(u(this,un))}get length(){return u(this,ei)}appendWriter(e){return P(this,fa,Tu).call(this,he(e.data))}writeBytes(e){let t=he(e),r=t.length%Ue;return r&&(t=he(q([t,C0.slice(r)]))),P(this,fa,Tu).call(this,t)}writeValue(e){return P(this,fa,Tu).call(this,$d(e))}writeUpdatableValue(){let e=u(this,un).length;return u(this,un).push(C0),p(this,ei,u(this,ei)+Ue),t=>{u(this,un)[e]=$d(t);}}};un=new WeakMap,ei=new WeakMap,fa=new WeakSet,Tu=function(e){return u(this,un).push(e),p(this,ei,u(this,ei)+e.length),e.length};var yt,Ft,Ou,eh,E0=class{constructor(e,t){b(this,Ou);g(this,"allowLoose");b(this,yt,void 0);b(this,Ft,void 0);I(this,{allowLoose:!!t}),p(this,yt,he(e)),p(this,Ft,0);}get data(){return v(u(this,yt))}get dataLength(){return u(this,yt).length}get consumed(){return u(this,Ft)}get bytes(){return new Uint8Array(u(this,yt))}subReader(e){return new E0(u(this,yt).slice(u(this,Ft)+e),this.allowLoose)}readBytes(e,t){let r=P(this,Ou,eh).call(this,0,e,!!t);return p(this,Ft,u(this,Ft)+r.length),r.slice(0,e)}readValue(){return Ot(this.readBytes(Ue))}readIndex(){return qo(this.readBytes(Ue))}},Bu=E0;yt=new WeakMap,Ft=new WeakMap,Ou=new WeakSet,eh=function(e,t,r){let s=Math.ceil(t/Ue)*Ue;return u(this,Ft)+s>u(this,yt).length&&(this.allowLoose&&r&&u(this,Ft)+t<=u(this,yt).length?s=t:w(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:he(u(this,yt)),length:u(this,yt).length,offset:u(this,Ft)+s})),u(this,yt).slice(u(this,Ft),u(this,Ft)+s)};function R0(n){if(!Number.isSafeInteger(n)||n<0)throw new Error(`Wrong positive integer: ${n}`)}function Zm(n){if(typeof n!="boolean")throw new Error(`Expected boolean, not ${n}`)}function th(n,...e){if(!(n instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(n.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${n.length}`)}function Xm(n){if(typeof n!="function"||typeof n.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");R0(n.outputLen),R0(n.blockLen);}function $m(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function eg(n,e){th(n);let t=e.outputLen;if(n.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var tg={number:R0,bool:Zm,bytes:th,hash:Xm,exists:$m,output:eg},ie=tg;var da=n=>new Uint32Array(n.buffer,n.byteOffset,Math.floor(n.byteLength/4)),ha=n=>new DataView(n.buffer,n.byteOffset,n.byteLength),cr=(n,e)=>n<<32-e|n>>>e,ng=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!ng)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));var sg=()=>l(void 0,null,function*(){});function Uu(n,e,t){return l(this,null,function*(){let r=Date.now();for(let s=0;s<n;s++){t(s);let i=Date.now()-r;i>=0&&i<e||(yield sg(),r+=i);}})}function ig(n){if(typeof n!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof n}`);return new TextEncoder().encode(n)}function ur(n){if(typeof n=="string"&&(n=ig(n)),!(n instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof n})`);return n}var fn=class{clone(){return this._cloneInto()}},ag=n=>Object.prototype.toString.call(n)==="[object Object]"&&n.constructor===Object;function _u(n,e){if(e!==void 0&&(typeof e!="object"||!ag(e)))throw new TypeError("Options should be object or undefined");return Object.assign(n,e)}function Nr(n){let e=r=>n().update(ur(r)).digest(),