UNPKG

@vechain/connex

Version:

Standard interface to connect DApp with VeChain and user

2 lines 198 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Connex=e()}(this,function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r,n={};var i=function(){if(r)return n;r=1,Object.defineProperty(n,"__esModule",{value:!0}),n.optional=function(e){return(r,n)=>(void 0!==r&&t(r,e,n),"")},n.nullable=function(e){return(r,n)=>(null!==r&&t(r,e,n),"")},n.Validator=class Validator{constructor(t){this.scheme=t}test(e,r){return t(e,this.scheme,r)}};class ValidationError extends Error{constructor(t,e){super(e?`${e}: ${t}`:t),this.rawMessage=t,this.context=e}}function t(e,r,n){if(Array.isArray(r)){if(!Array.isArray(e))throw new ValidationError("expected array",n||"");e.forEach((e,i)=>t(e,r[0],n?`${n}.#${i}`:`#${i}`))}else if(r instanceof Function){const t=r(e,n);if(t)throw new ValidationError(t,n||"")}else{if(!(e instanceof Object))throw new ValidationError("expected object",n||"");for(const i in r)r.hasOwnProperty(i)&&t(e[i],r[i],n?`${n}.${i}`:i)}return e}return n.ValidationError=ValidationError,ValidationError.prototype.name="ValidationError",n.validate=t,n}();function o(t,e,r){const n=e.split("|").map(t=>t.trim());for(let r=0;r<n.length;r++)switch(e){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof t===e)return}const i=new Error(`invalid value for type ${e}`);throw i.code="INVALID_ARGUMENT",i.argument=`value.${r}`,i.value=t,i}function s(t,e,r){for(let n in e){let i=e[n];const s=r?r[n]:null;s&&o(i,s,n),Object.defineProperty(t,n,{enumerable:!0,value:i,writable:!1})}}function a(t,e){if(null==t)return"null";if(null==e&&(e=new Set),"object"==typeof t){if(e.has(t))return"[Circular]";e.add(t)}if(Array.isArray(t))return"[ "+t.map(t=>a(t,e)).join(", ")+" ]";if(t instanceof Uint8Array){const e="0123456789abcdef";let r="0x";for(let n=0;n<t.length;n++)r+=e[t[n]>>4],r+=e[15&t[n]];return r}if("object"==typeof t&&"function"==typeof t.toJSON)return a(t.toJSON(),e);switch(typeof t){case"boolean":case"number":case"symbol":return t.toString();case"bigint":return BigInt(t).toString();case"string":return JSON.stringify(t);case"object":{const r=Object.keys(t);return r.sort(),"{ "+r.map(r=>`${a(r,e)}: ${a(t[r],e)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function u(t,e){return t&&t.code===e}function c(t,e,r){let n,i=t;{const n=[];if(r){if("message"in r||"code"in r||"name"in r)throw new Error(`value will overwrite populated values: ${a(r)}`);for(const t in r){if("shortMessage"===t)continue;const e=r[t];n.push(t+"="+a(e))}}n.push(`code=${e}`),n.push("version=6.16.0"),n.length&&(t+=" ("+n.join(", ")+")")}switch(e){case"INVALID_ARGUMENT":n=new TypeError(t);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":n=new RangeError(t);break;default:n=new Error(t)}return s(n,{code:e}),r&&Object.assign(n,r),null==n.shortMessage&&s(n,{shortMessage:i}),n}function l(t,e,r,n){if(!t)throw c(e,r,n)}function h(t,e,r,n){l(t,e,"INVALID_ARGUMENT",{argument:r,value:n})}function f(t,e,r){null==r&&(r=""),r&&(r=": "+r),l(t>=e,"missing argument"+r,"MISSING_ARGUMENT",{count:t,expectedCount:e}),l(t<=e,"too many arguments"+r,"UNEXPECTED_ARGUMENT",{count:t,expectedCount:e})}function p(t,e,r){if(null==r&&(r=""),t!==e){let t=r,e="new";r&&(t+=".",e+=" "+r),l(!1,`private constructor; use ${t}from* methods`,"UNSUPPORTED_OPERATION",{operation:e})}}function d(t,e,r){if(t instanceof Uint8Array)return r?new Uint8Array(t):t;if("string"==typeof t&&t.length%2==0&&t.match(/^0x[0-9a-f]*$/i)){const e=new Uint8Array((t.length-2)/2);let r=2;for(let n=0;n<e.length;n++)e[n]=parseInt(t.substring(r,r+2),16),r+=2;return e}h(!1,"invalid BytesLike value",e||"value",t)}function g(t,e){return d(t,e,!1)}function y(t,e){return d(t,e,!0)}["NFD","NFC","NFKD","NFKC"].reduce((t,e)=>{try{if("test"!=="test".normalize(e))throw new Error("bad");if("NFD"===e){const t=String.fromCharCode(233).normalize("NFD");if(t!==String.fromCharCode(101,769))throw new Error("broken")}t.push(e)}catch(t){}return t},[]);const m="0123456789abcdef";function b(t){const e=g(t);let r="0x";for(let t=0;t<e.length;t++){const n=e[t];r+=m[(240&n)>>4]+m[15&n]}return r}function w(t){return"0x"+t.map(t=>b(t).substring(2)).join("")}const v=BigInt(0),E=BigInt(1),x=9007199254740991;function O(t,e){const r=R(t,"value"),n=BigInt(T(e,"bits"));return r&(E<<n)-E}function A(t,e){switch(typeof t){case"bigint":return t;case"number":return h(Number.isInteger(t),"underflow",e||"value",t),h(t>=-x&&t<=x,"overflow",e||"value",t),BigInt(t);case"string":try{if(""===t)throw new Error("empty string");return"-"===t[0]&&"-"!==t[1]?-BigInt(t.substring(1)):BigInt(t)}catch(r){h(!1,`invalid BigNumberish string: ${r.message}`,e||"value",t)}}h(!1,"invalid BigNumberish value",e||"value",t)}function R(t,e){const r=A(t,e);return l(r>=v,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:t}),r}const S="0123456789abcdef";function k(t){if(t instanceof Uint8Array){let e="0x0";for(const r of t)e+=S[r>>4],e+=S[15&r];return BigInt(e)}return A(t)}function T(t,e){switch(typeof t){case"bigint":return h(t>=-x&&t<=x,"overflow",e||"value",t),Number(t);case"number":return h(Number.isInteger(t),"underflow",e||"value",t),h(t>=-x&&t<=x,"overflow",e||"value",t),t;case"string":try{if(""===t)throw new Error("empty string");return T(BigInt(t),e)}catch(r){h(!1,`invalid numeric string: ${r.message}`,e||"value",t)}}h(!1,"invalid numeric value",e||"value",t)}function C(t,e,r,n,i){if("BAD_PREFIX"===t||"UNEXPECTED_CONTINUE"===t){let t=0;for(let n=e+1;n<r.length&&r[n]>>6==2;n++)t++;return t}return"OVERRUN"===t?r.length-e-1:0}const N=Object.freeze({error:function(t,e,r,n,i){h(!1,`invalid codepoint at offset ${e}; ${t}`,"bytes",r)},ignore:C,replace:function(t,e,r,n,i){return"OVERLONG"===t?(h("number"==typeof i,"invalid bad code point for replacement","badCodepoint",i),n.push(i),0):(n.push(65533),C(t,e,r))}});function B(t,e){h("string"==typeof t,"invalid string value","str",t);let r=[];for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(n<128)r.push(n);else if(n<2048)r.push(n>>6|192),r.push(63&n|128);else if(55296==(64512&n)){e++;const i=t.charCodeAt(e);h(e<t.length&&56320==(64512&i),"invalid surrogate pair","str",t);const o=65536+((1023&n)<<10)+(1023&i);r.push(o>>18|240),r.push(o>>12&63|128),r.push(o>>6&63|128),r.push(63&o|128)}else r.push(n>>12|224),r.push(n>>6&63|128),r.push(63&n|128)}return new Uint8Array(r)}function U(t,e){return r=function(t,e){null==e&&(e=N.error);const r=g(t,"bytes"),n=[];let i=0;for(;i<r.length;){const t=r[i++];if(!(t>>7)){n.push(t);continue}let o=null,s=null;if(192==(224&t))o=1,s=127;else if(224==(240&t))o=2,s=2047;else{if(240!=(248&t)){i+=e(128==(192&t)?"UNEXPECTED_CONTINUE":"BAD_PREFIX",i-1,r,n);continue}o=3,s=65535}if(i-1+o>=r.length){i+=e("OVERRUN",i-1,r,n);continue}let a=t&(1<<8-o-1)-1;for(let t=0;t<o;t++){let t=r[i];if(128!=(192&t)){i+=e("MISSING_CONTINUE",i,r,n),a=null;break}a=a<<6|63&t,i++}null!==a&&(a>1114111?i+=e("OUT_OF_RANGE",i-1-o,r,n,a):a>=55296&&a<=57343?i+=e("UTF16_SURROGATE",i-1-o,r,n,a):a<=s?i+=e("OVERLONG",i-1-o,r,n,a):n.push(a))}return n}(t,e),r.map(t=>t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10&1023),56320+(1023&t)))).join("");var r}const F=32,P=new Uint8Array(F),I=["then"],j={},L=new WeakMap;function _(t){return L.get(t)}function D(t,e){L.set(t,e)}function $(t,e){const r=new Error(`deferred error during ABI decoding triggered accessing ${t}`);throw r.error=e,r}function M(t,e,r){return t.indexOf(null)>=0?e.map((t,e)=>t instanceof Result?M(_(t),t,r):t):t.reduce((t,n,i)=>{let o=e.getValue(n);return n in t||(r&&o instanceof Result&&(o=M(_(o),o,r)),t[n]=o),t},{})}class Result extends Array{#t;constructor(...t){const e=t[0];let r=t[1],n=(t[2]||[]).slice(),i=!0;e!==j&&(r=t,n=[],i=!1),super(r.length),r.forEach((t,e)=>{this[e]=t});const o=n.reduce((t,e)=>("string"==typeof e&&t.set(e,(t.get(e)||0)+1),t),new Map);if(D(this,Object.freeze(r.map((t,e)=>{const r=n[e];return null!=r&&1===o.get(r)?r:null}))),this.#t=[],null==this.#t&&this.#t,!i)return;Object.freeze(this);const s=new Proxy(this,{get:(t,e,r)=>{if("string"==typeof e){if(e.match(/^[0-9]+$/)){const r=T(e,"%index");if(r<0||r>=this.length)throw new RangeError("out of result range");const n=t[r];return n instanceof Error&&$(`index ${r}`,n),n}if(I.indexOf(e)>=0)return Reflect.get(t,e,r);const n=t[e];if(n instanceof Function)return function(...e){return n.apply(this===r?t:this,e)};if(!(e in t))return t.getValue.apply(this===r?t:this,[e])}return Reflect.get(t,e,r)}});return D(s,_(this)),s}toArray(t){const e=[];return this.forEach((r,n)=>{r instanceof Error&&$(`index ${n}`,r),t&&r instanceof Result&&(r=r.toArray(t)),e.push(r)}),e}toObject(t){const e=_(this);return e.reduce((r,n,i)=>(l(null!=n,`value at index ${i} unnamed`,"UNSUPPORTED_OPERATION",{operation:"toObject()"}),M(e,this,t)),{})}slice(t,e){null==t&&(t=0),t<0&&(t+=this.length)<0&&(t=0),null==e&&(e=this.length),e<0&&(e+=this.length)<0&&(e=0),e>this.length&&(e=this.length);const r=_(this),n=[],i=[];for(let o=t;o<e;o++)n.push(this[o]),i.push(r[o]);return new Result(j,n,i)}filter(t,e){const r=_(this),n=[],i=[];for(let o=0;o<this.length;o++){const s=this[o];s instanceof Error&&$(`index ${o}`,s),t.call(e,s,o,this)&&(n.push(s),i.push(r[o]))}return new Result(j,n,i)}map(t,e){const r=[];for(let n=0;n<this.length;n++){const i=this[n];i instanceof Error&&$(`index ${n}`,i),r.push(t.call(e,i,n,this))}return r}getValue(t){const e=_(this).indexOf(t);if(-1===e)return;const r=this[e];return r instanceof Error&&$(`property ${JSON.stringify(t)}`,r.error),r}static fromItems(t,e){return new Result(j,t,e)}}function V(t){let e=function(t){const e=R(t,"value");if(e===v)return new Uint8Array(0);let r=e.toString(16);r.length%2&&(r="0"+r);const n=new Uint8Array(r.length/2);for(let t=0;t<n.length;t++){const e=2*t;n[t]=parseInt(r.substring(e,e+2),16)}return n}(t);return l(e.length<=F,"value out-of-bounds","BUFFER_OVERRUN",{buffer:e,length:F,offset:e.length}),e.length!==F&&(e=y(w([P.slice(e.length%F),e]))),e}class Coder{name;type;localName;dynamic;constructor(t,e,r,n){s(this,{name:t,type:e,localName:r,dynamic:n},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(t,e){h(!1,t,this.localName,e)}}class Writer{#e;#r;constructor(){this.#e=[],this.#r=0}get data(){return w(this.#e)}get length(){return this.#r}#n(t){return this.#e.push(t),this.#r+=t.length,t.length}appendWriter(t){return this.#n(y(t.data))}writeBytes(t){let e=y(t);const r=e.length%F;return r&&(e=y(w([e,P.slice(r)]))),this.#n(e)}writeValue(t){return this.#n(V(t))}writeUpdatableValue(){const t=this.#e.length;return this.#e.push(P),this.#r+=F,e=>{this.#e[t]=V(e)}}}class Reader{allowLoose;#e;#i;#o;#s;#a;constructor(t,e,r){s(this,{allowLoose:!!e}),this.#e=y(t),this.#o=0,this.#s=null,this.#a=null!=r?r:1024,this.#i=0}get data(){return b(this.#e)}get dataLength(){return this.#e.length}get consumed(){return this.#i}get bytes(){return new Uint8Array(this.#e)}#u(t){if(this.#s)return this.#s.#u(t);this.#o+=t,l(this.#a<1||this.#o<=this.#a*this.dataLength,`compressed ABI data exceeds inflation ratio of ${this.#a} ( see: https://github.com/ethers-io/ethers.js/issues/4537 )`,"BUFFER_OVERRUN",{buffer:y(this.#e),offset:this.#i,length:t,info:{bytesRead:this.#o,dataLength:this.dataLength}})}#c(t,e,r){let n=Math.ceil(e/F)*F;return this.#i+n>this.#e.length&&(this.allowLoose&&r&&this.#i+e<=this.#e.length?n=e:l(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:y(this.#e),length:this.#e.length,offset:this.#i+n})),this.#e.slice(this.#i,this.#i+n)}subReader(t){const e=new Reader(this.#e.slice(this.#i+t),this.allowLoose,this.#a);return e.#s=this,e}readBytes(t,e){let r=this.#c(0,t,!!e);return this.#u(t),this.#i+=r.length,r.slice(0,t)}readValue(){return k(this.readBytes(F))}readIndex(){return T(k(this.readBytes(F)))}}function z(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function q(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function H(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function G(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),!(t instanceof Uint8Array))throw new Error("expected Uint8Array, got "+typeof t);return t}class Hash{clone(){return this._cloneInto()}}const W=BigInt(2**32-1),J=BigInt(32);function K(t,e=!1){return e?{h:Number(t&W),l:Number(t>>J&W)}:{h:0|Number(t>>J&W),l:0|Number(t&W)}}function X(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:o,l:s}=K(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}const[Y,Z,Q]=[[],[],[]],tt=BigInt(0),et=BigInt(1),rt=BigInt(2),nt=BigInt(7),it=BigInt(256),ot=BigInt(113);for(let t=0,e=et,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Y.push(2*(5*n+r)),Z.push((t+1)*(t+2)/2%64);let i=tt;for(let t=0;t<7;t++)e=(e<<et^(e>>nt)*ot)%it,e&rt&&(i^=et<<(et<<BigInt(t))-et);Q.push(i)}const[st,at]=X(Q,!0),ut=(t,e,r)=>r>32?((t,e,r)=>e<<r-32|t>>>64-r)(t,e,r):((t,e,r)=>t<<r|e>>>32-r)(t,e,r),ct=(t,e,r)=>r>32?((t,e,r)=>t<<r-32|e>>>64-r)(t,e,r):((t,e,r)=>e<<r|t>>>32-r)(t,e,r);class Keccak extends Hash{constructor(t,e,r,n=!1,i=24){if(super(),this.blockLen=t,this.suffix=e,this.outputLen=r,this.enableXOF=n,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,z(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}keccak(){!function(t,e=24){const r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let e=0;e<10;e++)r[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const n=(e+8)%10,i=(e+2)%10,o=r[i],s=r[i+1],a=ut(o,s,1)^r[n],u=ct(o,s,1)^r[n+1];for(let r=0;r<50;r+=10)t[e+r]^=a,t[e+r+1]^=u}let e=t[2],i=t[3];for(let r=0;r<24;r++){const n=Z[r],o=ut(e,i,n),s=ct(e,i,n),a=Y[r];e=t[a],i=t[a+1],t[a]=o,t[a+1]=s}for(let e=0;e<50;e+=10){for(let n=0;n<10;n++)r[n]=t[e+n];for(let n=0;n<10;n++)t[e+n]^=~r[(n+2)%10]&r[(n+4)%10]}t[0]^=st[n],t[1]^=at[n]}r.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){H(this);const{blockLen:e,state:r}=this,n=(t=G(t)).length;for(let i=0;i<n;){const o=Math.min(e-this.pos,n-i);for(let e=0;e<o;e++)r[this.pos++]^=t[i++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:e,pos:r,blockLen:n}=this;t[r]^=e,128&e&&r===n-1&&this.keccak(),t[n-1]^=128,this.keccak()}writeInto(t){H(this,!1),q(t),this.finish();const e=this.state,{blockLen:r}=this;for(let n=0,i=t.length;n<i;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,i-n);t.set(e.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return z(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(function(t,e){q(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)} /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:e,suffix:r,outputLen:n,rounds:i,enableXOF:o}=this;return t||(t=new Keccak(e,r,n,o,i)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=i,t.suffix=r,t.outputLen=n,t.enableXOF=o,t.destroyed=this.destroyed,t}}const lt=((t,e,r)=>function(t){const e=e=>t().update(G(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}(()=>new Keccak(e,t,r)))(1,136,32);let ht=!1;const ft=function(t){return lt(t)};let pt=ft;function dt(t){const e=g(t,"data");return b(pt(e))}dt._=ft,dt.lock=function(){ht=!0},dt.register=function(t){if(ht)throw new TypeError("keccak256 is locked");pt=t},Object.freeze(dt);const gt=BigInt(0),yt=BigInt(36);function mt(t){const e=(t=t.toLowerCase()).substring(2).split(""),r=new Uint8Array(40);for(let t=0;t<40;t++)r[t]=e[t].charCodeAt(0);const n=g(dt(r));for(let t=0;t<40;t+=2)n[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&n[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const bt={};for(let t=0;t<10;t++)bt[String(t)]=String(t);for(let t=0;t<26;t++)bt[String.fromCharCode(65+t)]=String(10+t);const wt=function(){const t={};for(let e=0;e<36;e++){t["0123456789abcdefghijklmnopqrstuvwxyz"[e]]=BigInt(e)}return t}();function vt(t){if(h("string"==typeof t,"invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/)){t.startsWith("0x")||(t="0x"+t);const e=mt(t);return h(!t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||e===t,"bad address checksum","address",t),e}if(t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){h(t.substring(2,4)===function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map(t=>bt[t]).join("");for(;e.length>=15;){let t=e.substring(0,15);e=parseInt(t,10)%97+e.substring(t.length)}let r=String(98-parseInt(e,10)%97);for(;r.length<2;)r="0"+r;return r}(t),"bad icap checksum","address",t);let e=function(t){t=t.toLowerCase();let e=gt;for(let r=0;r<t.length;r++)e=e*yt+wt[t[r]];return e}(t.substring(4)).toString(16);for(;e.length<40;)e="0"+e;return mt("0x"+e)}h(!1,"invalid address","address",t)}const Et={};function xt(t,e){let r=!1;return e<0&&(r=!0,e*=-1),new Typed(Et,`${r?"":"u"}int${e}`,t,{signed:r,width:e})}function Ot(t,e){return new Typed(Et,`bytes${e||""}`,t,{size:e})}const At=Symbol.for("_ethers_typed");class Typed{type;value;#l;_typedSymbol;constructor(t,e,r,n){null==n&&(n=null),p(Et,t,"Typed"),s(this,{_typedSymbol:At,type:e,value:r}),this.#l=n,this.format()}format(){if("array"===this.type)throw new Error("");if("dynamicArray"===this.type)throw new Error("");return"tuple"===this.type?`tuple(${this.value.map(t=>t.format()).join(",")})`:this.type}defaultValue(){return 0}minValue(){return 0}maxValue(){return 0}isBigInt(){return!!this.type.match(/^u?int[0-9]+$/)}isData(){return this.type.startsWith("bytes")}isString(){return"string"===this.type}get tupleName(){if("tuple"!==this.type)throw TypeError("not a tuple");return this.#l}get arrayLength(){if("array"!==this.type)throw TypeError("not an array");return!0===this.#l?-1:!1===this.#l?this.value.length:null}static from(t,e){return new Typed(Et,t,e)}static uint8(t){return xt(t,8)}static uint16(t){return xt(t,16)}static uint24(t){return xt(t,24)}static uint32(t){return xt(t,32)}static uint40(t){return xt(t,40)}static uint48(t){return xt(t,48)}static uint56(t){return xt(t,56)}static uint64(t){return xt(t,64)}static uint72(t){return xt(t,72)}static uint80(t){return xt(t,80)}static uint88(t){return xt(t,88)}static uint96(t){return xt(t,96)}static uint104(t){return xt(t,104)}static uint112(t){return xt(t,112)}static uint120(t){return xt(t,120)}static uint128(t){return xt(t,128)}static uint136(t){return xt(t,136)}static uint144(t){return xt(t,144)}static uint152(t){return xt(t,152)}static uint160(t){return xt(t,160)}static uint168(t){return xt(t,168)}static uint176(t){return xt(t,176)}static uint184(t){return xt(t,184)}static uint192(t){return xt(t,192)}static uint200(t){return xt(t,200)}static uint208(t){return xt(t,208)}static uint216(t){return xt(t,216)}static uint224(t){return xt(t,224)}static uint232(t){return xt(t,232)}static uint240(t){return xt(t,240)}static uint248(t){return xt(t,248)}static uint256(t){return xt(t,256)}static uint(t){return xt(t,256)}static int8(t){return xt(t,-8)}static int16(t){return xt(t,-16)}static int24(t){return xt(t,-24)}static int32(t){return xt(t,-32)}static int40(t){return xt(t,-40)}static int48(t){return xt(t,-48)}static int56(t){return xt(t,-56)}static int64(t){return xt(t,-64)}static int72(t){return xt(t,-72)}static int80(t){return xt(t,-80)}static int88(t){return xt(t,-88)}static int96(t){return xt(t,-96)}static int104(t){return xt(t,-104)}static int112(t){return xt(t,-112)}static int120(t){return xt(t,-120)}static int128(t){return xt(t,-128)}static int136(t){return xt(t,-136)}static int144(t){return xt(t,-144)}static int152(t){return xt(t,-152)}static int160(t){return xt(t,-160)}static int168(t){return xt(t,-168)}static int176(t){return xt(t,-176)}static int184(t){return xt(t,-184)}static int192(t){return xt(t,-192)}static int200(t){return xt(t,-200)}static int208(t){return xt(t,-208)}static int216(t){return xt(t,-216)}static int224(t){return xt(t,-224)}static int232(t){return xt(t,-232)}static int240(t){return xt(t,-240)}static int248(t){return xt(t,-248)}static int256(t){return xt(t,-256)}static int(t){return xt(t,-256)}static bytes1(t){return Ot(t,1)}static bytes2(t){return Ot(t,2)}static bytes3(t){return Ot(t,3)}static bytes4(t){return Ot(t,4)}static bytes5(t){return Ot(t,5)}static bytes6(t){return Ot(t,6)}static bytes7(t){return Ot(t,7)}static bytes8(t){return Ot(t,8)}static bytes9(t){return Ot(t,9)}static bytes10(t){return Ot(t,10)}static bytes11(t){return Ot(t,11)}static bytes12(t){return Ot(t,12)}static bytes13(t){return Ot(t,13)}static bytes14(t){return Ot(t,14)}static bytes15(t){return Ot(t,15)}static bytes16(t){return Ot(t,16)}static bytes17(t){return Ot(t,17)}static bytes18(t){return Ot(t,18)}static bytes19(t){return Ot(t,19)}static bytes20(t){return Ot(t,20)}static bytes21(t){return Ot(t,21)}static bytes22(t){return Ot(t,22)}static bytes23(t){return Ot(t,23)}static bytes24(t){return Ot(t,24)}static bytes25(t){return Ot(t,25)}static bytes26(t){return Ot(t,26)}static bytes27(t){return Ot(t,27)}static bytes28(t){return Ot(t,28)}static bytes29(t){return Ot(t,29)}static bytes30(t){return Ot(t,30)}static bytes31(t){return Ot(t,31)}static bytes32(t){return Ot(t,32)}static address(t){return new Typed(Et,"address",t)}static bool(t){return new Typed(Et,"bool",!!t)}static bytes(t){return new Typed(Et,"bytes",t)}static string(t){return new Typed(Et,"string",t)}static array(t,e){throw new Error("not implemented yet")}static tuple(t,e){throw new Error("not implemented yet")}static overrides(t){return new Typed(Et,"overrides",Object.assign({},t))}static isTyped(t){return t&&"object"==typeof t&&"_typedSymbol"in t&&t._typedSymbol===At}static dereference(t,e){if(Typed.isTyped(t)){if(t.type!==e)throw new Error(`invalid type: expecetd ${e}, got ${t.type}`);return t.value}return t}}class AddressCoder extends Coder{constructor(t){super("address","address",t,!1)}defaultValue(){return"0x0000000000000000000000000000000000000000"}encode(t,e){let r=Typed.dereference(e,"string");try{r=vt(r)}catch(t){return this._throwError(t.message,e)}return t.writeValue(r)}decode(t){return vt(function(t,e){const r=R(t,"value");let n=r.toString(16);{const i=T(e,"width");if(0===i&&r===v)return"0x";for(l(2*i>=n.length,`value exceeds width (${i} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:t});n.length<2*i;)n="0"+n}return"0x"+n}(t.readValue(),20))}}class AnonymousCoder extends Coder{coder;constructor(t){super(t.name,t.type,"_",t.dynamic),this.coder=t}defaultValue(){return this.coder.defaultValue()}encode(t,e){return this.coder.encode(t,e)}decode(t){return this.coder.decode(t)}}function Rt(t,e,r){let n=[];if(Array.isArray(r))n=r;else if(r&&"object"==typeof r){let t={};n=e.map(e=>{const n=e.localName;return l(n,"cannot encode object for signature with missing names","INVALID_ARGUMENT",{argument:"values",info:{coder:e},value:r}),l(!t[n],"cannot encode object for signature with duplicate names","INVALID_ARGUMENT",{argument:"values",info:{coder:e},value:r}),t[n]=!0,r[n]})}else h(!1,"invalid tuple value","tuple",r);h(e.length===n.length,"types/value length mismatch","tuple",r);let i=new Writer,o=new Writer,s=[];e.forEach((t,e)=>{let r=n[e];if(t.dynamic){let e=o.length;t.encode(o,r);let n=i.writeUpdatableValue();s.push(t=>{n(t+e)})}else t.encode(i,r)}),s.forEach(t=>{t(i.length)});let a=t.appendWriter(i);return a+=t.appendWriter(o),a}function St(t,e){let r=[],n=[],i=t.subReader(0);return e.forEach(e=>{let o=null;if(e.dynamic){let r=t.readIndex(),n=i.subReader(r);try{o=e.decode(n)}catch(t){if(u(t,"BUFFER_OVERRUN"))throw t;o=t,o.baseType=e.name,o.name=e.localName,o.type=e.type}}else try{o=e.decode(t)}catch(t){if(u(t,"BUFFER_OVERRUN"))throw t;o=t,o.baseType=e.name,o.name=e.localName,o.type=e.type}if(null==o)throw new Error("investigate");r.push(o),n.push(e.localName||null)}),Result.fromItems(r,n)}class ArrayCoder extends Coder{coder;length;constructor(t,e,r){super("array",t.type+"["+(e>=0?e:"")+"]",r,-1===e||t.dynamic),s(this,{coder:t,length:e})}defaultValue(){const t=this.coder.defaultValue(),e=[];for(let r=0;r<this.length;r++)e.push(t);return e}encode(t,e){const r=Typed.dereference(e,"array");Array.isArray(r)||this._throwError("expected array value",r);let n=this.length;-1===n&&(n=r.length,t.writeValue(r.length)),f(r.length,n,"coder array"+(this.localName?" "+this.localName:""));let i=[];for(let t=0;t<r.length;t++)i.push(this.coder);return Rt(t,i,r)}decode(t){let e=this.length;-1===e&&(e=t.readIndex(),l(e*F<=t.dataLength,"insufficient data length","BUFFER_OVERRUN",{buffer:t.bytes,offset:e*F,length:t.dataLength}));let r=[];for(let t=0;t<e;t++)r.push(new AnonymousCoder(this.coder));return St(t,r)}}class BooleanCoder extends Coder{constructor(t){super("bool","bool",t,!1)}defaultValue(){return!1}encode(t,e){const r=Typed.dereference(e,"bool");return t.writeValue(r?1:0)}decode(t){return!!t.readValue()}}class DynamicBytesCoder extends Coder{constructor(t,e){super(t,t,e,!0)}defaultValue(){return"0x"}encode(t,e){e=y(e);let r=t.writeValue(e.length);return r+=t.writeBytes(e),r}decode(t){return t.readBytes(t.readIndex(),!0)}}class BytesCoder extends DynamicBytesCoder{constructor(t){super("bytes",t)}decode(t){return b(super.decode(t))}}class FixedBytesCoder extends Coder{size;constructor(t,e){let r="bytes"+String(t);super(r,r,e,!1),s(this,{size:t},{size:"number"})}defaultValue(){return"0x0000000000000000000000000000000000000000000000000000000000000000".substring(0,2+2*this.size)}encode(t,e){let r=y(Typed.dereference(e,this.type));return r.length!==this.size&&this._throwError("incorrect data length",e),t.writeBytes(r)}decode(t){return b(t.readBytes(this.size))}}const kt=new Uint8Array([]);class NullCoder extends Coder{constructor(t){super("null","",t,!1)}defaultValue(){return null}encode(t,e){return null!=e&&this._throwError("not null",e),t.writeBytes(kt)}decode(t){return t.readBytes(0),null}}const Tt=BigInt(0),Ct=BigInt(1),Nt=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");class NumberCoder extends Coder{size;signed;constructor(t,e,r){const n=(e?"int":"uint")+8*t;super(n,n,r,!1),s(this,{size:t,signed:e},{size:"number",signed:"boolean"})}defaultValue(){return 0}encode(t,e){let r=A(Typed.dereference(e,this.type)),n=O(Nt,256);if(this.signed){let t=O(n,8*this.size-1);(r>t||r<-(t+Ct))&&this._throwError("value out-of-bounds",e),r=function(t,e){let r=A(t,"value");const n=BigInt(T(e,"width")),i=E<<n-E;if(r<v)return r=-r,l(r<=i,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:t}),(~r&(E<<n)-E)+E;return l(r<i,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:t}),r}(r,256)}else(r<Tt||r>O(n,8*this.size))&&this._throwError("value out-of-bounds",e);return t.writeValue(r)}decode(t){let e=O(t.readValue(),8*this.size);return this.signed&&(e=function(t,e){const r=R(t,"value"),n=BigInt(T(e,"width"));if(l(r>>n===v,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:t}),r>>n-E)return-((~r&(E<<n)-E)+E);return r}(e,8*this.size)),e}}class StringCoder extends DynamicBytesCoder{constructor(t){super("string",t)}defaultValue(){return""}encode(t,e){return super.encode(t,B(Typed.dereference(e,"string")))}decode(t){return U(super.decode(t))}}class TupleCoder extends Coder{coders;constructor(t,e){let r=!1;const n=[];t.forEach(t=>{t.dynamic&&(r=!0),n.push(t.type)});super("tuple","tuple("+n.join(",")+")",e,r),s(this,{coders:Object.freeze(t.slice())})}defaultValue(){const t=[];this.coders.forEach(e=>{t.push(e.defaultValue())});const e=this.coders.reduce((t,e)=>{const r=e.localName;return r&&(t[r]||(t[r]=0),t[r]++),t},{});return this.coders.forEach((r,n)=>{let i=r.localName;i&&1===e[i]&&("length"===i&&(i="_length"),null==t[i]&&(t[i]=t[n]))}),Object.freeze(t)}encode(t,e){const r=Typed.dereference(e,"tuple");return Rt(t,this.coders,r)}decode(t){return St(t,this.coders)}}function Bt(t){return dt(B(t))}function Ut(t){const e=new Set;return t.forEach(t=>e.add(t)),Object.freeze(e)}const Ft=Ut("external public payable override".split(" ")),Pt="constant external internal payable private public pure view override",It=Ut(Pt.split(" ")),jt="constructor error event fallback function receive struct",Lt=Ut(jt.split(" ")),_t="calldata memory storage payable indexed",Dt=Ut(_t.split(" ")),$t=Ut([jt,_t,"tuple returns",Pt].join(" ").split(" ")),Mt={"(":"OPEN_PAREN",")":"CLOSE_PAREN","[":"OPEN_BRACKET","]":"CLOSE_BRACKET",",":"COMMA","@":"AT"},Vt=new RegExp("^(\\s*)"),zt=new RegExp("^([0-9]+)"),qt=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)"),Ht=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$"),Gt=new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$");class TokenString{#i;#h;get offset(){return this.#i}get length(){return this.#h.length-this.#i}constructor(t){this.#i=0,this.#h=t.slice()}clone(){return new TokenString(this.#h)}reset(){this.#i=0}#f(t=0,e=0){return new TokenString(this.#h.slice(t,e).map(e=>Object.freeze(Object.assign({},e,{match:e.match-t,linkBack:e.linkBack-t,linkNext:e.linkNext-t}))))}popKeyword(t){const e=this.peek();if("KEYWORD"!==e.type||!t.has(e.text))throw new Error(`expected keyword ${e.text}`);return this.pop().text}popType(t){if(this.peek().type!==t){const e=this.peek();throw new Error(`expected ${t}; got ${e.type} ${JSON.stringify(e.text)}`)}return this.pop().text}popParen(){const t=this.peek();if("OPEN_PAREN"!==t.type)throw new Error("bad start");const e=this.#f(this.#i+1,t.match+1);return this.#i=t.match+1,e}popParams(){const t=this.peek();if("OPEN_PAREN"!==t.type)throw new Error("bad start");const e=[];for(;this.#i<t.match-1;){const t=this.peek().linkNext;e.push(this.#f(this.#i+1,t)),this.#i=t}return this.#i=t.match+1,e}peek(){if(this.#i>=this.#h.length)throw new Error("out-of-bounds");return this.#h[this.#i]}peekKeyword(t){const e=this.peekType("KEYWORD");return null!=e&&t.has(e)?e:null}peekType(t){if(0===this.length)return null;const e=this.peek();return e.type===t?e.text:null}pop(){const t=this.peek();return this.#i++,t}toString(){const t=[];for(let e=this.#i;e<this.#h.length;e++){const r=this.#h[e];t.push(`${r.type}:${r.text}`)}return`<TokenString ${t.join(" ")}>`}}function Wt(t){const e=[],r=e=>{const r=o<t.length?JSON.stringify(t[o]):"$EOI";throw new Error(`invalid token ${r} at ${o}: ${e}`)};let n=[],i=[],o=0;for(;o<t.length;){let s=t.substring(o),a=s.match(Vt);a&&(o+=a[1].length,s=t.substring(o));const u={depth:n.length,linkBack:-1,linkNext:-1,match:-1,type:"",text:"",offset:o,value:-1};e.push(u);let c=Mt[s[0]]||"";if(c){if(u.type=c,u.text=s[0],o++,"OPEN_PAREN"===c)n.push(e.length-1),i.push(e.length-1);else if("CLOSE_PAREN"==c)0===n.length&&r("no matching open bracket"),u.match=n.pop(),e[u.match].match=e.length-1,u.depth--,u.linkBack=i.pop(),e[u.linkBack].linkNext=e.length-1;else if("COMMA"===c)u.linkBack=i.pop(),e[u.linkBack].linkNext=e.length-1,i.push(e.length-1);else if("OPEN_BRACKET"===c)u.type="BRACKET";else if("CLOSE_BRACKET"===c){let t=e.pop().text;if(e.length>0&&"NUMBER"===e[e.length-1].type){const r=e.pop().text;t=r+t,e[e.length-1].value=T(r)}if(0===e.length||"BRACKET"!==e[e.length-1].type)throw new Error("missing opening bracket");e[e.length-1].text+=t}}else if(a=s.match(qt),a){if(u.text=a[1],o+=u.text.length,$t.has(u.text)){u.type="KEYWORD";continue}if(u.text.match(Gt)){u.type="TYPE";continue}u.type="ID"}else{if(a=s.match(zt),!a)throw new Error(`unexpected token ${JSON.stringify(s[0])} at position ${o}`);u.text=a[1],u.type="NUMBER",o+=u.text.length}}return new TokenString(e.map(t=>Object.freeze(t)))}function Jt(t,e){let r=[];for(const n in e.keys())t.has(n)&&r.push(n);if(r.length>1)throw new Error(`conflicting types: ${r.join(", ")}`)}function Kt(t,e){if(e.peekKeyword(Lt)){const r=e.pop().text;if(r!==t)throw new Error(`expected ${t}, got ${r}`)}return e.popType("ID")}function Xt(t,e){const r=new Set;for(;;){const n=t.peekType("KEYWORD");if(null==n||e&&!e.has(n))break;if(t.pop(),r.has(n))throw new Error(`duplicate keywords: ${JSON.stringify(n)}`);r.add(n)}return Object.freeze(r)}function Yt(t){let e=Xt(t,It);return Jt(e,Ut("constant payable nonpayable".split(" "))),Jt(e,Ut("pure view payable nonpayable".split(" "))),e.has("view")?"view":e.has("pure")?"pure":e.has("payable")?"payable":e.has("nonpayable")?"nonpayable":e.has("constant")?"view":"nonpayable"}function Zt(t,e){return t.popParams().map(t=>ParamType.from(t,e))}function Qt(t){if(t.peekType("AT")){if(t.pop(),t.peekType("NUMBER"))return A(t.pop().text);throw new Error("invalid gas")}return null}function te(t){if(t.length)throw new Error(`unexpected tokens at offset ${t.offset}: ${t.toString()}`)}const ee=new RegExp(/^(.*)\[([0-9]*)\]$/);function re(t){const e=t.match(Gt);if(h(e,"invalid type","type",t),"uint"===t)return"uint256";if("int"===t)return"int256";if(e[2]){const r=parseInt(e[2]);h(0!==r&&r<=32,"invalid bytes length","type",t)}else if(e[3]){const r=parseInt(e[3]);h(0!==r&&r<=256&&r%8==0,"invalid numeric width","type",t)}return t}const ne={},ie=Symbol.for("_ethers_internal"),oe="_ParamTypeInternal",se="_ErrorInternal",ae="_EventInternal",ue="_ConstructorInternal",ce="_FallbackInternal",le="_FunctionInternal",he="_StructInternal";class ParamType{name;type;baseType;indexed;components;arrayLength;arrayChildren;constructor(t,e,r,n,i,o,a,u){if(p(t,ne,"ParamType"),Object.defineProperty(this,ie,{value:oe}),o&&(o=Object.freeze(o.slice())),"array"===n){if(null==a||null==u)throw new Error("")}else if(null!=a||null!=u)throw new Error("");if("tuple"===n){if(null==o)throw new Error("")}else if(null!=o)throw new Error("");s(this,{name:e,type:r,baseType:n,indexed:i,components:o,arrayLength:a,arrayChildren:u})}format(t){if(null==t&&(t="sighash"),"json"===t){const e=this.name||"";if(this.isArray()){const t=JSON.parse(this.arrayChildren.format("json"));return t.name=e,t.type+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`,JSON.stringify(t)}const r={type:"tuple"===this.baseType?"tuple":this.type,name:e};return"boolean"==typeof this.indexed&&(r.indexed=this.indexed),this.isTuple()&&(r.components=this.components.map(e=>JSON.parse(e.format(t)))),JSON.stringify(r)}let e="";return this.isArray()?(e+=this.arrayChildren.format(t),e+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`):this.isTuple()?e+="("+this.components.map(e=>e.format(t)).join("full"===t?", ":",")+")":e+=this.type,"sighash"!==t&&(!0===this.indexed&&(e+=" indexed"),"full"===t&&this.name&&(e+=" "+this.name)),e}isArray(){return"array"===this.baseType}isTuple(){return"tuple"===this.baseType}isIndexable(){return null!=this.indexed}walk(t,e){if(this.isArray()){if(!Array.isArray(t))throw new Error("invalid array value");if(-1!==this.arrayLength&&t.length!==this.arrayLength)throw new Error("array is wrong length");const r=this;return t.map(t=>r.arrayChildren.walk(t,e))}if(this.isTuple()){if(!Array.isArray(t))throw new Error("invalid tuple value");if(t.length!==this.components.length)throw new Error("array is wrong length");const r=this;return t.map((t,n)=>r.components[n].walk(t,e))}return e(this.type,t)}#p(t,e,r,n){if(this.isArray()){if(!Array.isArray(e))throw new Error("invalid array value");if(-1!==this.arrayLength&&e.length!==this.arrayLength)throw new Error("array is wrong length");const i=this.arrayChildren,o=e.slice();return o.forEach((e,n)=>{i.#p(t,e,r,t=>{o[n]=t})}),void n(o)}if(this.isTuple()){const i=this.components;let o;if(Array.isArray(e))o=e.slice();else{if(null==e||"object"!=typeof e)throw new Error("invalid tuple value");o=i.map(t=>{if(!t.name)throw new Error("cannot use object value with unnamed components");if(!(t.name in e))throw new Error(`missing value for component ${t.name}`);return e[t.name]})}if(o.length!==this.components.length)throw new Error("array is wrong length");return o.forEach((e,n)=>{i[n].#p(t,e,r,t=>{o[n]=t})}),void n(o)}const i=r(this.type,e);i.then?t.push(async function(){n(await i)}()):n(i)}async walkAsync(t,e){const r=[],n=[t];return this.#p(r,t,e,t=>{n[0]=t}),r.length&&await Promise.all(r),n[0]}static from(t,e){if(ParamType.isParamType(t))return t;if("string"==typeof t)try{return ParamType.from(Wt(t),e)}catch(e){h(!1,"invalid param type","obj",t)}else if(t instanceof TokenString){let r="",n="",i=null;Xt(t,Ut(["tuple"])).has("tuple")||t.peekType("OPEN_PAREN")?(n="tuple",i=t.popParams().map(t=>ParamType.from(t)),r=`tuple(${i.map(t=>t.format()).join(",")})`):(r=re(t.popType("TYPE")),n=r);let o=null,s=null;for(;t.length&&t.peekType("BRACKET");){const e=t.pop();o=new ParamType(ne,"",r,n,null,i,s,o),s=e.value,r+=e.text,n="array",i=null}let a=null;if(Xt(t,Dt).has("indexed")){if(!e)throw new Error("");a=!0}const u=t.peekType("ID")?t.pop().text:"";if(t.length)throw new Error("leftover tokens");return new ParamType(ne,u,r,n,a,i,s,o)}const r=t.name;h(!r||"string"==typeof r&&r.match(Ht),"invalid name","obj.name",r);let n=t.indexed;null!=n&&(h(e,"parameter cannot be indexed","obj.indexed",t.indexed),n=!!n);let i=t.type,o=i.match(ee);if(o){const e=parseInt(o[2]||"-1"),s=ParamType.from({type:o[1],components:t.components});return new ParamType(ne,r||"",i,"array",n,null,e,s)}if("tuple"===i||i.startsWith("tuple(")||i.startsWith("(")){const e=null!=t.components?t.components.map(t=>ParamType.from(t)):null;return new ParamType(ne,r||"",i,"tuple",n,e,null,null)}return i=re(t.type),new ParamType(ne,r||"",i,i,n,null,null,null)}static isParamType(t){return t&&t[ie]===oe}}class Fragment{type;inputs;constructor(t,e,r){p(t,ne,"Fragment"),s(this,{type:e,inputs:r=Object.freeze(r.slice())})}static from(t){if("string"==typeof t){try{Fragment.from(JSON.parse(t))}catch(t){}return Fragment.from(Wt(t))}if(t instanceof TokenString){switch(t.peekKeyword(Lt)){case"constructor":return ConstructorFragment.from(t);case"error":return ErrorFragment.from(t);case"event":return EventFragment.from(t);case"fallback":case"receive":return FallbackFragment.from(t);case"function":return FunctionFragment.from(t);case"struct":return StructFragment.from(t)}}else if("object"==typeof t){switch(t.type){case"constructor":return ConstructorFragment.from(t);case"error":return ErrorFragment.from(t);case"event":return EventFragment.from(t);case"fallback":case"receive":return FallbackFragment.from(t);case"function":return FunctionFragment.from(t);case"struct":return StructFragment.from(t)}l(!1,`unsupported type: ${t.type}`,"UNSUPPORTED_OPERATION",{operation:"Fragment.from"})}h(!1,"unsupported frgament object","obj",t)}static isConstructor(t){return ConstructorFragment.isFragment(t)}static isError(t){return ErrorFragment.isFragment(t)}static isEvent(t){return EventFragment.isFragment(t)}static isFunction(t){return FunctionFragment.isFragment(t)}static isStruct(t){return StructFragment.isFragment(t)}}class NamedFragment extends Fragment{name;constructor(t,e,r,n){super(t,e,n),h("string"==typeof r&&r.match(Ht),"invalid identifier","name",r),n=Object.freeze(n.slice()),s(this,{name:r})}}function fe(t,e){return"("+e.map(e=>e.format(t)).join("full"===t?", ":",")+")"}class ErrorFragment extends NamedFragment{constructor(t,e,r){super(t,"error",e,r),Object.defineProperty(this,ie,{value:se})}get selector(){return Bt(this.format("sighash")).substring(0,10)}format(t){if(null==t&&(t="sighash"),"json"===t)return JSON.stringify({type:"error",name:this.name,inputs:this.inputs.map(e=>JSON.parse(e.format(t)))});const e=[];return"sighash"!==t&&e.push("error"),e.push(this.name+fe(t,this.inputs)),e.join(" ")}static from(t){if(ErrorFragment.isFragment(t))return t;if("string"==typeof t)return ErrorFragment.from(Wt(t));if(t instanceof TokenString){const e=Kt("error",t),r=Zt(t);return te(t),new ErrorFragment(ne,e,r)}return new ErrorFragment(ne,t.name,t.inputs?t.inputs.map(ParamType.from):[])}static isFragment(t){return t&&t[ie]===se}}class EventFragment extends NamedFragment{anonymous;constructor(t,e,r,n){super(t,"event",e,r),Object.defineProperty(this,ie,{value:ae}),s(this,{anonymous:n})}get topicHash(){return Bt(this.format("sighash"))}format(t){if(null==t&&(t="sighash"),"json"===t)return JSON.stringify({type:"event",anonymous:this.anonymous,name:this.name,inputs:this.inputs.map(e=>JSON.parse(e.format(t)))});const e=[];return"sighash"!==t&&e.push("event"),e.push(this.name+fe(t,this.inputs)),"sighash"!==t&&this.anonymous&&e.push("anonymous"),e.join(" ")}static getTopicHash(t,e){e=(e||[]).map(t=>ParamType.from(t));return new EventFragment(ne,t,e,!1).topicHash}static from(t){if(EventFragment.isFragment(t))return t;if("string"==typeof t)try{return EventFragment.from(Wt(t))}catch(e){h(!1,"invalid event fragment","obj",t)}else if(t instanceof TokenString){const e=Kt("event",t),r=Zt(t,!0),n=!!Xt(t,Ut(["anonymous"])).has("anonymous");return te(t),new EventFragment(ne,e,r,n)}return new EventFragment(ne,t.name,t.inputs?t.inputs.map(t=>ParamType.from(t,!0)):[],!!t.anonymous)}static isFragment(t){return t&&t[ie]===ae}}class ConstructorFragment extends Fragment{payable;gas;constructor(t,e,r,n,i){super(t,e,r),Object.defineProperty(this,ie,{value:ue}),s(this,{payable:n,gas:i})}format(t){if(l(null!=t&&"sighash"!==t,"cannot format a constructor for sighash","UNSUPPORTED_OPERATION",{operation:"format(sighash)"}),"json"===t)return JSON.stringify({type:"constructor",stateMutability:this.payable?"payable":"undefined",payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(e=>JSON.parse(e.format(t)))});const e=[`constructor${fe(t,this.inputs)}`];return this.payable&&e.push("payable"),null!=this.gas&&e.push(`@${this.gas.toString()}`),e.join(" ")}static from(t){if(ConstructorFragment.isFragment(t))return t;if("string"==typeof t)try{return ConstructorFragment.from(Wt(t))}catch(e){h(!1,"invalid constuctor fragment","obj",t)}else if(t instanceof TokenString){Xt(t,Ut(["constructor"]));const e=Zt(t),r=!!Xt(t,Ft).has("payable"),n=Qt(t);return te(t),new ConstructorFragment(ne,"constructor",e,r,n)}return new ConstructorFragment(ne,"constructor",t.inputs?t.inputs.map(ParamType.from):[],!!t.payable,null!=t.gas?t.gas:null)}static isFragment(t){return t&&t[ie]===ue}}class FallbackFragment extends Fragment{payable;constructor(t,e,r){super(t,"fallback",e),Object.defineProperty(this,ie,{value:ce}),s(this,{payable:r})}format(t){const e=0===this.inputs.length?"receive":"fallback";if("json"===t){const t=this.payable?"payable":"nonpayable";return JSON.stringify({type:e,stateMutability:t})}return`${e}()${this.payable?" payable":""}`}static from(t){if(FallbackFragment.isFragment(t))return t;if("string"==typeof t)try{return FallbackFragment.from(Wt(t))}catch(e){h(!1,"invalid fallback fragment","obj",t)}else if(t instanceof TokenString){const e=t.toString();h(t.peekKeyword(Ut(["fallback","receive"])),"type must be fallback or receive","obj",e);if("receive"===t.popKeyword(Ut(["fallback","receive"]))){const e=Zt(t);return h(0===e.length,"receive cannot have arguments","obj.inputs",e),Xt(t,Ut(["payable"])),te(t),new FallbackFragment(ne,[],!0)}let r=Zt(t);r.length?h(1===r.length&&"bytes"===r[0].type,"invalid fallback inputs","obj.inputs",r.map(t=>t.format("minimal")).join(", ")):r=[ParamType.from("bytes")];const n=Yt(t);if(h("nonpayable"===n||"payable"===n,"fallback cannot be constants","obj.stateMutability",n),Xt(t,Ut(["returns"])).has("returns")){const e=Zt(t);h(1===e.length&&"bytes"===e[0].type,"invalid fallback outputs","obj.outputs",e.map(t=>t.format("minimal")).join(", "))}return te(t),new FallbackFragment(ne,r,"payable"===n)}if("receive"===t.type)return new FallbackFragment(ne,[],!0);if("fallback"===t.type){const e=[ParamType.from("bytes")],r="payable"===t.stateMutability;return new FallbackFragment(ne,e,r)}h(!1,"invalid fallback description","obj",t)}static isFragment(t){return t&&t[ie]===ce}}class FunctionFragment extends NamedFragment{constant;outputs;stateMutability;payable;gas;constructor(t,e,r,n,i,o){super(t,"function",e,n),Object.defineProperty(this,ie,{value:le});s(this,{constant:"view"===r||"pure"===r,gas:o,outputs:i=Object.freeze(i.slice()),payable:"payable"===r,stateMutability:r})}get selector(){return Bt(this.format("sighash")).substring(0,10)}format(t){if(null==t&&(t="sighash"),"json"===t)return JSON.stringify({type:"function",name:this.name,constant:this.constant,stateMutability:"nonpayable"!==this.stateMutability?this.stateMutability:void 0,payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(e=>JSON.parse(e.format(t))),outputs:this.outputs.map(e=>JSON.parse(e.format(t)))});const e=[];return"sighash"!==t&&e.push("function"),e.push(this.name+fe(t,this.inputs)),"sighash"!==t&&("nonpayable"!==this.stateMutability&&e.push(this.stateMutability),this.outputs&&this.outputs.length&&(e.push("returns"),e.push(fe(t,this.outputs))),null!=this.gas&&e.push(`@${this.gas.toString()}`)),e.join(" ")}static getSelector(t,e){e=(e||[]).map(t=>ParamType.from(t));return new FunctionFragment(ne,t,"view",e,[],null).selector}static from(t){if(FunctionFragment.isFragment(t))return t;if("string"==typeof t)try{return FunctionFragment.from(Wt(t))}catch(e){h(!1,"invalid function fragment","obj",t)}else if(t instanceof TokenString){const e=Kt("function",t),r=Zt(t),n=Yt(t);let i=[];Xt(t,Ut(["returns"])).has("returns")&&(i=Zt(t));const o=Qt(t);return te(t),new FunctionFragment(ne,e,n,r,i,o)}let e=t.stateMutability;return null==e&&(e="payable","boolean"==typeof t.constant?(e="view",t.constant||(e="payable","boolean"!=typeof t.payable||t.payable||(e="nonpayable"))):"boolean"!=typeof t.payable||t.payable||(e="nonpayable")),new FunctionFragment(ne,t.name,e,t.inputs?t.inputs.map(ParamType.from):[],t.outputs?t.outputs.map(ParamType.from):[],null!=t.gas?t.gas:null)}static isFragment(t){return t&&t[ie]===le}}class StructFragment extends NamedFragment{constructor(t,e,r){super(t,"struct",e,r),Object.defineProperty(this,ie,{value:he})}format(){throw new Error("@TODO")}static from(t){if("string"==typeof t)try{return StructFragment.from(Wt(t))}catch(e){h(!1,"invalid struct fragment","obj",t)}else if(t instanceof TokenString){const e=Kt("struct",t),r=Zt(t);return te(t),new StructFragment(ne,e,r)}return new StructFragment(ne,t.name,t.inputs?t.inputs.map(ParamType.from):[])}static isFragment(t){return t&&t[ie]===he}}const pe=new Map;pe.set(0,"GENERIC_PANIC"),pe.set(1,"ASSERT_FALSE"),pe.set(17,"OVERFLOW"),pe.set(18,"DIVIDE_BY_ZERO"),pe.set(33,"ENUM_RANGE_ERROR"),pe.set(34,"BAD_STORAGE_DATA"),pe.set(49,"STACK_UNDERFLOW"),pe.set(50,"ARRAY_RANGE_ERROR"),pe.set(65,"OUT_OF_MEMORY"),pe.set(81,"UNINITIALIZED_FUNCTION_CALL");const de=new RegExp(/^bytes([0-9]*)$/),ge=new RegExp(/^(u?int)([0-9]*)$/);let ye=null,me=1024;class AbiCoder{#d(t){if(t.isArray())return new ArrayCoder(this.#d(t.arrayChildren),t.arrayLength,t.name);if(t.isTuple())return new TupleCoder(t.components.map(t=>this.#d(t)),t.name);switch(t.baseType){case"address":return new AddressCoder(t.name);case"bool":return new BooleanCoder(t.name);case"string":return new StringCoder(t.name);case"bytes":return new BytesCoder(t.name);case"":return new NullCoder(t.name)}let e=t.type.match(ge);if(e){let r=parseInt(e[2]||"256");return h(0!==r&&r<=256&&r%8==0,"invalid "+e[1]+" bit length","param",t),new NumberCoder(r/8,"int"===e[1],t.name)}if(e=t.type.match(de),e){let r=parseInt(e[1]);return h(0!==r&&r<=32,"invalid bytes length","param",t),new FixedBytesCoder(r,t.name)}h(!1,"invalid type","type",t.type)}getDefaultValue(t){const e=t.map(t=>this.#d(ParamType.from(t)));return new TupleCoder(e,"_").defaultValue()}encode(t,e){f(e.length,t.length,"types/values length mismatch");const r=t.map(t=>this.#d(ParamType.from(t))),n=new TupleCoder(r,"_"),i=new Writer;return n.encode(i,e),i.data}decode(t,e,r){const n=t.map(t=>this.#d(ParamType.from(t)));return new TupleCoder(n,"_").decode(new Reader(e,r,me))}static _setDefaultMaxInflation(t){h("number"==typeof t&&Number.isInteger(t),"invalid defaultMaxInflation factor","value",t),me=t}static defaultAbiCoder(){return null==ye&&(ye=new AbiCoder),ye}static getBuiltinCallException(t,e,r){return function(t,e,r,n){let i="missing revert data",o=null,s=null;if(r){i="execution reverted";const t=g(r);if(r=b(r),0===t.length)i+=" (no data present; likely require(false) occurred",o="require(false)";else if(t.length%32!=4)i+=" (could not decode reason; invalid data length)";else if("0x08c379a0"===b(t.slice(0,4)))try{o=n.decode(["string"],t.slice(4))[0],s={signature:"Error(string)",name:"Error",args:[o]},i+=`: ${JSON.stringify(o)}`}catch(t){i+=" (could not decode reason; invalid string data)"}else if("0x4e487b71"===b(t.slice(0,4)))try{const e=Number(n.decode(["uint256"],t.slice(4))[0]);s={signature:"Panic(uint256)",name:"Panic",args:[e]},o=`Panic due to ${pe.get(e)||"UNKNOWN"}(${e})`,i+=`: ${o}`}catch(t){i+=" (could not decode panic code)"}else i+=" (unknown custom error)"}const a={to:e.to?vt(e.to):null,data:e.data||"0x"};return e.from&&(a.from=vt(e.from)),c(i,"CALL_EXCEPTION",{action:t,data:r,reason:o,transaction:a,invoc