bringid 0.5.1-beta-rc.3 → 0.5.2-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,7 +13,7 @@ npm install bringid
13
13
  ```ts
14
14
  import { BringID } from "bringid";
15
15
 
16
- const bringid = new BringID({ appId: "1" });
16
+ const bringid = new BringID({ appId: "0x..." });
17
17
 
18
18
  // Get a reputation score (0-100) — works immediately
19
19
  const { score } = await bringid.getAddressScore("0x...");
@@ -45,13 +45,13 @@ const { verified, score } = await bringid.verifyProofs({ proofs, provider });
45
45
 
46
46
  ### 1. Create the SDK instance
47
47
 
48
- Create a shared instance to use across your app. The `appId` parameter is required.
48
+ Create a shared instance to use across your app. The `appId` parameter is required. Please, use https://manager.bringid.org/ to create appId for your application
49
49
 
50
50
  ```ts
51
51
  // lib/bringid.ts
52
52
  import { BringID } from "bringid";
53
53
 
54
- export const bringid = new BringID({ appId: "1" });
54
+ export const bringid = new BringID({ appId: "0x..." });
55
55
  ```
56
56
 
57
57
  ### 2. Add the Modal Provider
@@ -117,10 +117,10 @@ Creates a new SDK instance. The `appId` is required.
117
117
  import { BringID } from "bringid";
118
118
 
119
119
  // Production mode (default)
120
- const bringid = new BringID({ appId: "1" });
120
+ const bringid = new BringID({ appId: "0x..." });
121
121
 
122
122
  // Development mode
123
- const bringid = new BringID({ appId: "1", mode: "dev" });
123
+ const bringid = new BringID({ appId: "0x...", mode: "dev" });
124
124
  ```
125
125
 
126
126
  **Options:**
@@ -163,7 +163,7 @@ const { verified, score } = await bringid.verifyProofs({
163
163
  proofs,
164
164
  provider,
165
165
  context: 1,
166
- contract: "0x..."
166
+ contract: "0x...",
167
167
  });
168
168
  ```
169
169
 
@@ -244,9 +244,9 @@ import { BringIDModal } from "bringid/react";
244
244
  customTitles={{
245
245
  pointsTitle: "Humanity Points",
246
246
  pointsShortTitle: "HP",
247
- scoreTitle: "Score"
247
+ scoreTitle: "Score",
248
248
  }}
249
- />
249
+ />;
250
250
  ```
251
251
 
252
252
  **Props:**
@@ -266,7 +266,7 @@ import { BringIDModal } from "bringid/react";
266
266
  Set `mode: "dev"` on the BringID instance. The mode is automatically passed to the modal via postMessage — no need to set it on `BringIDModal`.
267
267
 
268
268
  ```ts
269
- const bringid = new BringID({ appId: "1", mode: "dev" });
269
+ const bringid = new BringID({ appId: "0x...", mode: "dev" });
270
270
  ```
271
271
 
272
272
  > **Note:** Production mode is enabled by default. Only use `dev` mode during development.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.BringSDK=e():t.BringSDK=e()}(this,(function(){return function(){"use strict";var t={d:function(e,n){for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function i(t,e,n){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}t.r(e),t.d(e,{BringID:function(){return pi}});var s=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"GET",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return fetch(t,{method:e,body:"GET"===e||"OPTIONS"===e?void 0:JSON.stringify(i),headers:r({},n)}).then((async t=>{if(!t.ok){const e=await t.json();throw new Error(e.error)}return t.json()}))},o=t=>s("".concat("https://api.bringid.org","/v1/score/address/").concat(t),"GET",{Authorization:"Bearer ".concat("zpka_52e44068bb9745f2be776b343e96cdab_1a60a93b"),"content-type":"application/json"});const a=[{internalType:"uint256",name:"credentialGroupId",type:"uint256"},{internalType:"uint256",name:"appId",type:"uint256"},{components:[{internalType:"uint256",name:"merkleTreeDepth",type:"uint256"},{internalType:"uint256",name:"merkleTreeRoot",type:"uint256"},{internalType:"uint256",name:"nullifier",type:"uint256"},{internalType:"uint256",name:"message",type:"uint256"},{internalType:"uint256",name:"scope",type:"uint256"},{internalType:"uint256[8]",name:"points",type:"uint256[8]"}],internalType:"struct ISemaphore.SemaphoreProof",name:"semaphoreProof",type:"tuple"}];var c=[{inputs:[{internalType:"uint256",name:"appId",type:"uint256"},{internalType:"uint256",name:"context_",type:"uint256"},{components:a,internalType:"struct ICredentialRegistry.CredentialProof",name:"proof_",type:"tuple"}],name:"verifyProof",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"appId",type:"uint256"},{internalType:"uint256",name:"context_",type:"uint256"},{components:a,internalType:"struct ICredentialRegistry.CredentialProof[]",name:"proofs_",type:"tuple[]"}],name:"verifyProofs",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"appId",type:"uint256"},{internalType:"uint256",name:"context_",type:"uint256"},{components:a,internalType:"struct ICredentialRegistry.CredentialProof[]",name:"proofs_",type:"tuple[]"}],name:"getScore",outputs:[{internalType:"uint256",name:"_score",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"appId",type:"uint256"}],name:"apps",outputs:[{internalType:"enum ICredentialRegistry.AppStatus",name:"status",type:"uint8"},{internalType:"uint256",name:"recoveryTimelock",type:"uint256"},{internalType:"address",name:"admin",type:"address"},{internalType:"address",name:"scorer",type:"address"}],stateMutability:"view",type:"function"}],u=[{inputs:[{internalType:"uint256",name:"",type:"uint256"}],name:"getScore",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],name:"getScores",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"}];function l(t,e,n){const r=e.split("|").map((t=>t.trim()));for(let n=0;n<r.length;n++)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 ".concat(e));throw i.code="INVALID_ARGUMENT",i.argument="value.".concat(n),i.value=t,i}async function h(t){const e=Object.keys(t);return(await Promise.all(e.map((e=>Promise.resolve(t[e]))))).reduce(((t,n,r)=>(t[e[r]]=n,t)),{})}function f(t,e,n){for(let r in e){let i=e[r];const s=n?n[r]:null;s&&l(i,s,r),Object.defineProperty(t,r,{enumerable:!0,value:i,writable:!1})}}function p(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=>p(t,e))).join(", ")+" ]";if(t instanceof Uint8Array){const e="0123456789abcdef";let n="0x";for(let r=0;r<t.length;r++)n+=e[t[r]>>4],n+=e[15&t[r]];return n}if("object"==typeof t&&"function"==typeof t.toJSON)return p(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 n=Object.keys(t);return n.sort(),"{ "+n.map((n=>"".concat(p(n,e),": ").concat(p(t[n],e)))).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function d(t,e){return t&&t.code===e}function g(t){return d(t,"CALL_EXCEPTION")}function y(t,e,n){let r,i=t;{const r=[];if(n){if("message"in n||"code"in n||"name"in n)throw new Error("value will overwrite populated values: ".concat(p(n)));for(const t in n){if("shortMessage"===t)continue;const e=n[t];r.push(t+"="+p(e))}}r.push("code=".concat(e)),r.push("version=".concat("6.16.0")),r.length&&(t+=" ("+r.join(", ")+")")}switch(e){case"INVALID_ARGUMENT":r=new TypeError(t);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":r=new RangeError(t);break;default:r=new Error(t)}return f(r,{code:e}),n&&Object.assign(r,n),null==r.shortMessage&&f(r,{shortMessage:i}),r}function m(t,e,n,r){if(!t)throw y(e,n,r)}function b(t,e,n,r){m(t,e,"INVALID_ARGUMENT",{argument:n,value:r})}function v(t,e,n){null==n&&(n=""),n&&(n=": "+n),m(t>=e,"missing argument"+n,"MISSING_ARGUMENT",{count:t,expectedCount:e}),m(t<=e,"too many arguments"+n,"UNEXPECTED_ARGUMENT",{count:t,expectedCount:e})}const w=["NFD","NFC","NFKD","NFKC"].reduce(((t,e)=>{try{if("test"!=="test".normalize(e))throw new Error("bad");if("NFD"===e){if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken")}t.push(e)}catch(t){}return t}),[]);function E(t,e,n){if(null==n&&(n=""),t!==e){let t=n,e="new";n&&(t+=".",e+=" "+n),m(!1,"private constructor; use ".concat(t,"from* methods"),"UNSUPPORTED_OPERATION",{operation:e})}}function O(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var P=0;function N(t){return"__private_"+P+++"_"+t}const T={};function k(t,e){let n=!1;return e<0&&(n=!0,e*=-1),new _(T,"".concat(n?"":"u","int").concat(e),t,{signed:n,width:e})}function x(t,e){return new _(T,"bytes".concat(e||""),t,{size:e})}const R=Symbol.for("_ethers_typed");var A=N("options");class _{constructor(t,e,n,r){this.type=void 0,this.value=void 0,Object.defineProperty(this,A,{writable:!0,value:void 0}),this._typedSymbol=void 0,null==r&&(r=null),E(T,t,"Typed"),f(this,{_typedSymbol:R,type:e,value:n}),O(this,A)[A]=r,this.format()}format(){if("array"===this.type)throw new Error("");if("dynamicArray"===this.type)throw new Error("");return"tuple"===this.type?"tuple(".concat(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 O(this,A)[A]}get arrayLength(){if("array"!==this.type)throw TypeError("not an array");return!0===O(this,A)[A]?-1:!1===O(this,A)[A]?this.value.length:null}static from(t,e){return new _(T,t,e)}static uint8(t){return k(t,8)}static uint16(t){return k(t,16)}static uint24(t){return k(t,24)}static uint32(t){return k(t,32)}static uint40(t){return k(t,40)}static uint48(t){return k(t,48)}static uint56(t){return k(t,56)}static uint64(t){return k(t,64)}static uint72(t){return k(t,72)}static uint80(t){return k(t,80)}static uint88(t){return k(t,88)}static uint96(t){return k(t,96)}static uint104(t){return k(t,104)}static uint112(t){return k(t,112)}static uint120(t){return k(t,120)}static uint128(t){return k(t,128)}static uint136(t){return k(t,136)}static uint144(t){return k(t,144)}static uint152(t){return k(t,152)}static uint160(t){return k(t,160)}static uint168(t){return k(t,168)}static uint176(t){return k(t,176)}static uint184(t){return k(t,184)}static uint192(t){return k(t,192)}static uint200(t){return k(t,200)}static uint208(t){return k(t,208)}static uint216(t){return k(t,216)}static uint224(t){return k(t,224)}static uint232(t){return k(t,232)}static uint240(t){return k(t,240)}static uint248(t){return k(t,248)}static uint256(t){return k(t,256)}static uint(t){return k(t,256)}static int8(t){return k(t,-8)}static int16(t){return k(t,-16)}static int24(t){return k(t,-24)}static int32(t){return k(t,-32)}static int40(t){return k(t,-40)}static int48(t){return k(t,-48)}static int56(t){return k(t,-56)}static int64(t){return k(t,-64)}static int72(t){return k(t,-72)}static int80(t){return k(t,-80)}static int88(t){return k(t,-88)}static int96(t){return k(t,-96)}static int104(t){return k(t,-104)}static int112(t){return k(t,-112)}static int120(t){return k(t,-120)}static int128(t){return k(t,-128)}static int136(t){return k(t,-136)}static int144(t){return k(t,-144)}static int152(t){return k(t,-152)}static int160(t){return k(t,-160)}static int168(t){return k(t,-168)}static int176(t){return k(t,-176)}static int184(t){return k(t,-184)}static int192(t){return k(t,-192)}static int200(t){return k(t,-200)}static int208(t){return k(t,-208)}static int216(t){return k(t,-216)}static int224(t){return k(t,-224)}static int232(t){return k(t,-232)}static int240(t){return k(t,-240)}static int248(t){return k(t,-248)}static int256(t){return k(t,-256)}static int(t){return k(t,-256)}static bytes1(t){return x(t,1)}static bytes2(t){return x(t,2)}static bytes3(t){return x(t,3)}static bytes4(t){return x(t,4)}static bytes5(t){return x(t,5)}static bytes6(t){return x(t,6)}static bytes7(t){return x(t,7)}static bytes8(t){return x(t,8)}static bytes9(t){return x(t,9)}static bytes10(t){return x(t,10)}static bytes11(t){return x(t,11)}static bytes12(t){return x(t,12)}static bytes13(t){return x(t,13)}static bytes14(t){return x(t,14)}static bytes15(t){return x(t,15)}static bytes16(t){return x(t,16)}static bytes17(t){return x(t,17)}static bytes18(t){return x(t,18)}static bytes19(t){return x(t,19)}static bytes20(t){return x(t,20)}static bytes21(t){return x(t,21)}static bytes22(t){return x(t,22)}static bytes23(t){return x(t,23)}static bytes24(t){return x(t,24)}static bytes25(t){return x(t,25)}static bytes26(t){return x(t,26)}static bytes27(t){return x(t,27)}static bytes28(t){return x(t,28)}static bytes29(t){return x(t,29)}static bytes30(t){return x(t,30)}static bytes31(t){return x(t,31)}static bytes32(t){return x(t,32)}static address(t){return new _(T,"address",t)}static bool(t){return new _(T,"bool",!!t)}static bytes(t){return new _(T,"bytes",t)}static string(t){return new _(T,"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 _(T,"overrides",Object.assign({},t))}static isTyped(t){return t&&"object"==typeof t&&"_typedSymbol"in t&&t._typedSymbol===R}static dereference(t,e){if(_.isTyped(t)){if(t.type!==e)throw new Error("invalid type: expecetd ".concat(e,", got ").concat(t.type));return t.value}return t}}function I(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("Wrong positive integer: ".concat(t))}function j(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];if(n.length>0&&!n.includes(t.length))throw new Error("Expected Uint8Array of length ".concat(n,", not of length=").concat(t.length))}function U(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}const S=BigInt(2**32-1),F=BigInt(32);function C(t){return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?{h:Number(t&S),l:Number(t>>F&S)}:{h:0|Number(t>>F&S),l:0|Number(t&S)}}function L(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:s,l:o}=C(t[i],e);[n[i],r[i]]=[s,o]}return[n,r]}if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");function B(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got ".concat(typeof t));return new Uint8Array((new TextEncoder).encode(t))}(t)),!(t instanceof Uint8Array))throw new Error("expected Uint8Array, got ".concat(typeof t));return t}class D{clone(){return this._cloneInto()}}const[M,G,V]=[[],[],[]],H=BigInt(0),z=BigInt(1),J=BigInt(2),K=BigInt(7),W=BigInt(256),q=BigInt(113);for(let t=0,e=z,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],M.push(2*(5*r+n)),G.push((t+1)*(t+2)/2%64);let i=H;for(let t=0;t<7;t++)e=(e<<z^(e>>K)*q)%W,e&J&&(i^=z<<(z<<BigInt(t))-z);V.push(i)}const[$,X]=L(V,!0),Y=(t,e,n)=>n>32?((t,e,n)=>e<<n-32|t>>>64-n)(t,e,n):((t,e,n)=>t<<n|e>>>32-n)(t,e,n),Z=(t,e,n)=>n>32?((t,e,n)=>t<<n-32|e>>>64-n)(t,e,n):((t,e,n)=>e<<n|t>>>32-n)(t,e,n);class Q extends D{constructor(t,e,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:24;if(super(),this.blockLen=t,this.suffix=e,this.outputLen=n,this.enableXOF=r,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,I(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var s;this.state=new Uint8Array(200),this.state32=(s=this.state,new Uint32Array(s.buffer,s.byteOffset,Math.floor(s.byteLength/4)))}keccak(){!function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:24;const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let e=0;e<10;e++)n[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const r=(e+8)%10,i=(e+2)%10,s=n[i],o=n[i+1],a=Y(s,o,1)^n[r],c=Z(s,o,1)^n[r+1];for(let n=0;n<50;n+=10)t[e+n]^=a,t[e+n+1]^=c}let e=t[2],i=t[3];for(let n=0;n<24;n++){const r=G[n],s=Y(e,i,r),o=Z(e,i,r),a=M[n];e=t[a],i=t[a+1],t[a]=s,t[a+1]=o}for(let e=0;e<50;e+=10){for(let r=0;r<10;r++)n[r]=t[e+r];for(let r=0;r<10;r++)t[e+r]^=~n[(r+2)%10]&n[(r+4)%10]}t[0]^=$[r],t[1]^=X[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){U(this);const{blockLen:e,state:n}=this,r=(t=B(t)).length;for(let i=0;i<r;){const s=Math.min(e-this.pos,r-i);for(let e=0;e<s;e++)n[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:n,blockLen:r}=this;t[n]^=e,128&e&&n===r-1&&this.keccak(),t[r-1]^=128,this.keccak()}writeInto(t){U(this,!1),j(t),this.finish();const e=this.state,{blockLen:n}=this;for(let r=0,i=t.length;r<i;){this.posOut>=n&&this.keccak();const s=Math.min(n-this.posOut,i-r);t.set(e.subarray(this.posOut,this.posOut+s),r),this.posOut+=s,r+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return I(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(function(t,e){j(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least ".concat(n))}(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:n,outputLen:r,rounds:i,enableXOF:s}=this;return t||(t=new Q(e,n,r,s,i)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=i,t.suffix=n,t.outputLen=r,t.enableXOF=s,t.destroyed=this.destroyed,t}}const tt=((t,e,n)=>function(t){const e=e=>t().update(B(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}((()=>new Q(e,t,n))))(1,136,32);function et(t,e,n){if(t instanceof Uint8Array)return n?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 n=2;for(let r=0;r<e.length;r++)e[r]=parseInt(t.substring(n,n+2),16),n+=2;return e}b(!1,"invalid BytesLike value",e||"value",t)}function nt(t,e){return et(t,e,!1)}function rt(t,e){return et(t,e,!0)}function it(t,e){return!("string"!=typeof t||!t.match(/^0x[0-9A-Fa-f]*$/)||"number"==typeof e&&t.length!==2+2*e||!0===e&&t.length%2!=0)}const st="0123456789abcdef";function ot(t){const e=nt(t);let n="0x";for(let t=0;t<e.length;t++){const r=e[t];n+=st[(240&r)>>4]+st[15&r]}return n}function at(t){return"0x"+t.map((t=>ot(t).substring(2))).join("")}function ct(t,e,n){const r=nt(t);return null!=n&&n>r.length&&m(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:n}),ot(r.slice(null==e?0:e,null==n?r.length:n))}function ut(t,e,n){const r=nt(t);m(e>=r.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(r),length:e,offset:e+1});const i=new Uint8Array(e);return i.fill(0),n?i.set(r,e-r.length):i.set(r,0),ot(i)}let lt=!1;const ht=function(t){return tt(t)};let ft=ht;function pt(t){const e=nt(t,"data");return ot(ft(e))}function dt(t,e,n,r,i){if("BAD_PREFIX"===t||"UNEXPECTED_CONTINUE"===t){let t=0;for(let r=e+1;r<n.length&&n[r]>>6==2;r++)t++;return t}return"OVERRUN"===t?n.length-e-1:0}pt._=ht,pt.lock=function(){lt=!0},pt.register=function(t){if(lt)throw new TypeError("keccak256 is locked");ft=t},Object.freeze(pt);const gt=Object.freeze({error:function(t,e,n,r,i){b(!1,"invalid codepoint at offset ".concat(e,"; ").concat(t),"bytes",n)},ignore:dt,replace:function(t,e,n,r,i){return"OVERLONG"===t?(b("number"==typeof i,"invalid bad code point for replacement","badCodepoint",i),r.push(i),0):(r.push(65533),dt(t,e,n))}});function yt(t,e){b("string"==typeof t,"invalid string value","str",t),null!=e&&(function(t){m(w.indexOf(t)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:t}})}(e),t=t.normalize(e));let n=[];for(let e=0;e<t.length;e++){const r=t.charCodeAt(e);if(r<128)n.push(r);else if(r<2048)n.push(r>>6|192),n.push(63&r|128);else if(55296==(64512&r)){e++;const i=t.charCodeAt(e);b(e<t.length&&56320==(64512&i),"invalid surrogate pair","str",t);const s=65536+((1023&r)<<10)+(1023&i);n.push(s>>18|240),n.push(s>>12&63|128),n.push(s>>6&63|128),n.push(63&s|128)}else n.push(r>>12|224),n.push(r>>6&63|128),n.push(63&r|128)}return new Uint8Array(n)}function mt(t,e){return function(t,e){null==e&&(e=gt.error);const n=nt(t,"bytes"),r=[];let i=0;for(;i<n.length;){const t=n[i++];if(!(t>>7)){r.push(t);continue}let s=null,o=null;if(192==(224&t))s=1,o=127;else if(224==(240&t))s=2,o=2047;else{if(240!=(248&t)){i+=e(128==(192&t)?"UNEXPECTED_CONTINUE":"BAD_PREFIX",i-1,n,r);continue}s=3,o=65535}if(i-1+s>=n.length){i+=e("OVERRUN",i-1,n,r);continue}let a=t&(1<<8-s-1)-1;for(let t=0;t<s;t++){let t=n[i];if(128!=(192&t)){i+=e("MISSING_CONTINUE",i,n,r),a=null;break}a=a<<6|63&t,i++}null!==a&&(a>1114111?i+=e("OUT_OF_RANGE",i-1-s,n,r,a):a>=55296&&a<=57343?i+=e("UTF16_SURROGATE",i-1-s,n,r,a):a<=o?i+=e("OVERLONG",i-1-s,n,r,a):r.push(a))}return r}(t,e).map((t=>t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10&1023),56320+(1023&t))))).join("")}function bt(t){return pt(yt(t))}const vt=BigInt(0),wt=BigInt(1),Et=9007199254740991;function Ot(t,e){const n=Nt(t,"value"),r=BigInt(xt(e,"bits"));return n&(wt<<r)-wt}function Pt(t,e){switch(typeof t){case"bigint":return t;case"number":return b(Number.isInteger(t),"underflow",e||"value",t),b(t>=-Et&&t<=Et,"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(n){b(!1,"invalid BigNumberish string: ".concat(n.message),e||"value",t)}}b(!1,"invalid BigNumberish value",e||"value",t)}function Nt(t,e){const n=Pt(t,e);return m(n>=vt,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:t}),n}const Tt="0123456789abcdef";function kt(t){if(t instanceof Uint8Array){let e="0x0";for(const n of t)e+=Tt[n>>4],e+=Tt[15&n];return BigInt(e)}return Pt(t)}function xt(t,e){switch(typeof t){case"bigint":return b(t>=-Et&&t<=Et,"overflow",e||"value",t),Number(t);case"number":return b(Number.isInteger(t),"underflow",e||"value",t),b(t>=-Et&&t<=Et,"overflow",e||"value",t),t;case"string":try{if(""===t)throw new Error("empty string");return xt(BigInt(t),e)}catch(n){b(!1,"invalid numeric string: ".concat(n.message),e||"value",t)}}b(!1,"invalid numeric value",e||"value",t)}function Rt(t,e){const n=Nt(t,"value");let r=n.toString(16);if(null==e)r.length%2&&(r="0"+r);else{const i=xt(e,"width");if(0===i&&n===vt)return"0x";for(m(2*i>=r.length,"value exceeds width (".concat(i," bytes)"),"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:t});r.length<2*i;)r="0"+r}return"0x"+r}function At(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var _t=0;function It(t){return"__private_"+_t+++"_"+t}const jt=32,Ut=new Uint8Array(jt),St=["then"],Ft={},Ct=new WeakMap;function Lt(t){return Ct.get(t)}function Bt(t,e){Ct.set(t,e)}function Dt(t,e){const n=new Error("deferred error during ABI decoding triggered accessing ".concat(t));throw n.error=e,n}function Mt(t,e,n){return t.indexOf(null)>=0?e.map(((t,e)=>t instanceof Vt?Mt(Lt(t),t,n):t)):t.reduce(((t,r,i)=>{let s=e.getValue(r);return r in t||(n&&s instanceof Vt&&(s=Mt(Lt(s),s,n)),t[r]=s),t}),{})}var Gt=It("names");class Vt extends Array{constructor(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];const r=e[0];let i=e[1],s=(e[2]||[]).slice(),o=!0;r!==Ft&&(i=e,s=[],o=!1),super(i.length),Object.defineProperty(this,Gt,{writable:!0,value:void 0}),i.forEach(((t,e)=>{this[e]=t}));const a=s.reduce(((t,e)=>("string"==typeof e&&t.set(e,(t.get(e)||0)+1),t)),new Map);if(Bt(this,Object.freeze(i.map(((t,e)=>{const n=s[e];return null!=n&&1===a.get(n)?n:null})))),At(this,Gt)[Gt]=[],null==At(this,Gt)[Gt]&&At(this,Gt)[Gt],!o)return;Object.freeze(this);const c=new Proxy(this,{get:(t,e,n)=>{if("string"==typeof e){if(e.match(/^[0-9]+$/)){const n=xt(e,"%index");if(n<0||n>=this.length)throw new RangeError("out of result range");const r=t[n];return r instanceof Error&&Dt("index ".concat(n),r),r}if(St.indexOf(e)>=0)return Reflect.get(t,e,n);const r=t[e];if(r instanceof Function)return function(){for(var e=arguments.length,i=new Array(e),s=0;s<e;s++)i[s]=arguments[s];return r.apply(this===n?t:this,i)};if(!(e in t))return t.getValue.apply(this===n?t:this,[e])}return Reflect.get(t,e,n)}});return Bt(c,Lt(this)),c}toArray(t){const e=[];return this.forEach(((n,r)=>{n instanceof Error&&Dt("index ".concat(r),n),t&&n instanceof Vt&&(n=n.toArray(t)),e.push(n)})),e}toObject(t){const e=Lt(this);return e.reduce(((n,r,i)=>(m(null!=r,"value at index ".concat(i," unnamed"),"UNSUPPORTED_OPERATION",{operation:"toObject()"}),Mt(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 n=Lt(this),r=[],i=[];for(let s=t;s<e;s++)r.push(this[s]),i.push(n[s]);return new Vt(Ft,r,i)}filter(t,e){const n=Lt(this),r=[],i=[];for(let s=0;s<this.length;s++){const o=this[s];o instanceof Error&&Dt("index ".concat(s),o),t.call(e,o,s,this)&&(r.push(o),i.push(n[s]))}return new Vt(Ft,r,i)}map(t,e){const n=[];for(let r=0;r<this.length;r++){const i=this[r];i instanceof Error&&Dt("index ".concat(r),i),n.push(t.call(e,i,r,this))}return n}getValue(t){const e=Lt(this).indexOf(t);if(-1===e)return;const n=this[e];return n instanceof Error&&Dt("property ".concat(JSON.stringify(t)),n.error),n}static fromItems(t,e){return new Vt(Ft,t,e)}}function Ht(t){let e=function(t,e){const n=Nt(t,"value");if(n===vt){const t=null!=e?xt(e,"width"):0;return new Uint8Array(t)}let r=n.toString(16);if(r.length%2&&(r="0"+r),null!=e){const n=xt(e,"width");for(;r.length<2*n;)r="00"+r;m(2*n===r.length,"value exceeds width (".concat(n," bytes)"),"NUMERIC_FAULT",{operation:"toBeArray",fault:"overflow",value:t})}const i=new Uint8Array(r.length/2);for(let t=0;t<i.length;t++){const e=2*t;i[t]=parseInt(r.substring(e,e+2),16)}return i}(t);return m(e.length<=jt,"value out-of-bounds","BUFFER_OVERRUN",{buffer:e,length:jt,offset:e.length}),e.length!==jt&&(e=rt(at([Ut.slice(e.length%jt),e]))),e}class zt{constructor(t,e,n,r){this.name=void 0,this.type=void 0,this.localName=void 0,this.dynamic=void 0,f(this,{name:t,type:e,localName:n,dynamic:r},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(t,e){b(!1,t,this.localName,e)}}var Jt=It("data"),Kt=It("dataLength"),Wt=It("writeData");class qt{constructor(){Object.defineProperty(this,Wt,{value:$t}),Object.defineProperty(this,Jt,{writable:!0,value:void 0}),Object.defineProperty(this,Kt,{writable:!0,value:void 0}),At(this,Jt)[Jt]=[],At(this,Kt)[Kt]=0}get data(){return at(At(this,Jt)[Jt])}get length(){return At(this,Kt)[Kt]}appendWriter(t){return At(this,Wt)[Wt](rt(t.data))}writeBytes(t){let e=rt(t);const n=e.length%jt;return n&&(e=rt(at([e,Ut.slice(n)]))),At(this,Wt)[Wt](e)}writeValue(t){return At(this,Wt)[Wt](Ht(t))}writeUpdatableValue(){const t=At(this,Jt)[Jt].length;return At(this,Jt)[Jt].push(Ut),At(this,Kt)[Kt]+=jt,e=>{At(this,Jt)[Jt][t]=Ht(e)}}}function $t(t){return At(this,Jt)[Jt].push(t),At(this,Kt)[Kt]+=t.length,t.length}var Xt=It("data"),Yt=It("offset"),Zt=It("bytesRead"),Qt=It("parent"),te=It("maxInflation"),ee=It("incrementBytesRead"),ne=It("peekBytes");class re{constructor(t,e,n){Object.defineProperty(this,ne,{value:se}),Object.defineProperty(this,ee,{value:ie}),this.allowLoose=void 0,Object.defineProperty(this,Xt,{writable:!0,value:void 0}),Object.defineProperty(this,Yt,{writable:!0,value:void 0}),Object.defineProperty(this,Zt,{writable:!0,value:void 0}),Object.defineProperty(this,Qt,{writable:!0,value:void 0}),Object.defineProperty(this,te,{writable:!0,value:void 0}),f(this,{allowLoose:!!e}),At(this,Xt)[Xt]=rt(t),At(this,Zt)[Zt]=0,At(this,Qt)[Qt]=null,At(this,te)[te]=null!=n?n:1024,At(this,Yt)[Yt]=0}get data(){return ot(At(this,Xt)[Xt])}get dataLength(){return At(this,Xt)[Xt].length}get consumed(){return At(this,Yt)[Yt]}get bytes(){return new Uint8Array(At(this,Xt)[Xt])}subReader(t){const e=new re(At(this,Xt)[Xt].slice(At(this,Yt)[Yt]+t),this.allowLoose,At(this,te)[te]);return At(e,Qt)[Qt]=this,e}readBytes(t,e){let n=At(this,ne)[ne](0,t,!!e);return At(this,ee)[ee](t),At(this,Yt)[Yt]+=n.length,n.slice(0,t)}readValue(){return kt(this.readBytes(jt))}readIndex(){return xt(kt(this.readBytes(jt)))}}function ie(t){if(At(this,Qt)[Qt])return At(At(this,Qt)[Qt],ee)[ee](t);At(this,Zt)[Zt]+=t,m(At(this,te)[te]<1||At(this,Zt)[Zt]<=At(this,te)[te]*this.dataLength,"compressed ABI data exceeds inflation ratio of ".concat(At(this,te)[te]," ( see: https://github.com/ethers-io/ethers.js/issues/4537 )"),"BUFFER_OVERRUN",{buffer:rt(At(this,Xt)[Xt]),offset:At(this,Yt)[Yt],length:t,info:{bytesRead:At(this,Zt)[Zt],dataLength:this.dataLength}})}function se(t,e,n){let r=Math.ceil(e/jt)*jt;return At(this,Yt)[Yt]+r>At(this,Xt)[Xt].length&&(this.allowLoose&&n&&At(this,Yt)[Yt]+e<=At(this,Xt)[Xt].length?r=e:m(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:rt(At(this,Xt)[Xt]),length:At(this,Xt)[Xt].length,offset:At(this,Yt)[Yt]+r})),At(this,Xt)[Xt].slice(At(this,Yt)[Yt],At(this,Yt)[Yt]+r)}const oe=BigInt(0),ae=BigInt(36);function ce(t){const e=(t=t.toLowerCase()).substring(2).split(""),n=new Uint8Array(40);for(let t=0;t<40;t++)n[t]=e[t].charCodeAt(0);const r=nt(pt(n));for(let t=0;t<40;t+=2)r[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&r[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const ue={};for(let t=0;t<10;t++)ue[String(t)]=String(t);for(let t=0;t<26;t++)ue[String.fromCharCode(65+t)]=String(10+t);const le=function(){const t={};for(let e=0;e<36;e++)t["0123456789abcdefghijklmnopqrstuvwxyz"[e]]=BigInt(e);return t}();function he(t){if(b("string"==typeof t,"invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/)){t.startsWith("0x")||(t="0x"+t);const e=ce(t);return b(!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}$/)){b(t.substring(2,4)===function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map((t=>ue[t])).join("");for(;e.length>=15;){let t=e.substring(0,15);e=parseInt(t,10)%97+e.substring(t.length)}let n=String(98-parseInt(e,10)%97);for(;n.length<2;)n="0"+n;return n}(t),"bad icap checksum","address",t);let e=function(t){t=t.toLowerCase();let e=oe;for(let n=0;n<t.length;n++)e=e*ae+le[t[n]];return e}(t.substring(4)).toString(16);for(;e.length<40;)e="0"+e;return ce("0x"+e)}b(!1,"invalid address","address",t)}class fe extends zt{constructor(t){super("address","address",t,!1)}defaultValue(){return"0x0000000000000000000000000000000000000000"}encode(t,e){let n=_.dereference(e,"string");try{n=he(n)}catch(t){return this._throwError(t.message,e)}return t.writeValue(n)}decode(t){return he(Rt(t.readValue(),20))}}class pe extends zt{constructor(t){super(t.name,t.type,"_",t.dynamic),this.coder=void 0,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 de(t,e,n){let r=[];if(Array.isArray(n))r=n;else if(n&&"object"==typeof n){let t={};r=e.map((e=>{const r=e.localName;return m(r,"cannot encode object for signature with missing names","INVALID_ARGUMENT",{argument:"values",info:{coder:e},value:n}),m(!t[r],"cannot encode object for signature with duplicate names","INVALID_ARGUMENT",{argument:"values",info:{coder:e},value:n}),t[r]=!0,n[r]}))}else b(!1,"invalid tuple value","tuple",n);b(e.length===r.length,"types/value length mismatch","tuple",n);let i=new qt,s=new qt,o=[];e.forEach(((t,e)=>{let n=r[e];if(t.dynamic){let e=s.length;t.encode(s,n);let r=i.writeUpdatableValue();o.push((t=>{r(t+e)}))}else t.encode(i,n)})),o.forEach((t=>{t(i.length)}));let a=t.appendWriter(i);return a+=t.appendWriter(s),a}function ge(t,e){let n=[],r=[],i=t.subReader(0);return e.forEach((e=>{let s=null;if(e.dynamic){let n=t.readIndex(),r=i.subReader(n);try{s=e.decode(r)}catch(t){if(d(t,"BUFFER_OVERRUN"))throw t;s=t,s.baseType=e.name,s.name=e.localName,s.type=e.type}}else try{s=e.decode(t)}catch(t){if(d(t,"BUFFER_OVERRUN"))throw t;s=t,s.baseType=e.name,s.name=e.localName,s.type=e.type}if(null==s)throw new Error("investigate");n.push(s),r.push(e.localName||null)})),Vt.fromItems(n,r)}class ye extends zt{constructor(t,e,n){super("array",t.type+"["+(e>=0?e:"")+"]",n,-1===e||t.dynamic),this.coder=void 0,this.length=void 0,f(this,{coder:t,length:e})}defaultValue(){const t=this.coder.defaultValue(),e=[];for(let n=0;n<this.length;n++)e.push(t);return e}encode(t,e){const n=_.dereference(e,"array");Array.isArray(n)||this._throwError("expected array value",n);let r=this.length;-1===r&&(r=n.length,t.writeValue(n.length)),v(n.length,r,"coder array"+(this.localName?" "+this.localName:""));let i=[];for(let t=0;t<n.length;t++)i.push(this.coder);return de(t,i,n)}decode(t){let e=this.length;-1===e&&(e=t.readIndex(),m(e*jt<=t.dataLength,"insufficient data length","BUFFER_OVERRUN",{buffer:t.bytes,offset:e*jt,length:t.dataLength}));let n=[];for(let t=0;t<e;t++)n.push(new pe(this.coder));return ge(t,n)}}class me extends zt{constructor(t){super("bool","bool",t,!1)}defaultValue(){return!1}encode(t,e){const n=_.dereference(e,"bool");return t.writeValue(n?1:0)}decode(t){return!!t.readValue()}}class be extends zt{constructor(t,e){super(t,t,e,!0)}defaultValue(){return"0x"}encode(t,e){e=rt(e);let n=t.writeValue(e.length);return n+=t.writeBytes(e),n}decode(t){return t.readBytes(t.readIndex(),!0)}}class ve extends be{constructor(t){super("bytes",t)}decode(t){return ot(super.decode(t))}}class we extends zt{constructor(t,e){let n="bytes"+String(t);super(n,n,e,!1),this.size=void 0,f(this,{size:t},{size:"number"})}defaultValue(){return"0x0000000000000000000000000000000000000000000000000000000000000000".substring(0,2+2*this.size)}encode(t,e){let n=rt(_.dereference(e,this.type));return n.length!==this.size&&this._throwError("incorrect data length",e),t.writeBytes(n)}decode(t){return ot(t.readBytes(this.size))}}const Ee=new Uint8Array([]);class Oe extends zt{constructor(t){super("null","",t,!1)}defaultValue(){return null}encode(t,e){return null!=e&&this._throwError("not null",e),t.writeBytes(Ee)}decode(t){return t.readBytes(0),null}}const Pe=BigInt(0),Ne=BigInt(1),Te=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");class ke extends zt{constructor(t,e,n){const r=(e?"int":"uint")+8*t;super(r,r,n,!1),this.size=void 0,this.signed=void 0,f(this,{size:t,signed:e},{size:"number",signed:"boolean"})}defaultValue(){return 0}encode(t,e){let n=Pt(_.dereference(e,this.type)),r=Ot(Te,256);if(this.signed){let t=Ot(r,8*this.size-1);(n>t||n<-(t+Ne))&&this._throwError("value out-of-bounds",e),n=function(t){let e=Pt(t,"value");const n=BigInt(xt(256,"width")),r=wt<<n-wt;return e<vt?(e=-e,m(e<=r,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:t}),(~e&(wt<<n)-wt)+wt):(m(e<r,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:t}),e)}(n)}else(n<Pe||n>Ot(r,8*this.size))&&this._throwError("value out-of-bounds",e);return t.writeValue(n)}decode(t){let e=Ot(t.readValue(),8*this.size);return this.signed&&(e=function(t,e){const n=Nt(t,"value"),r=BigInt(xt(e,"width"));return m(n>>r===vt,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:t}),n>>r-wt?-((~n&(wt<<r)-wt)+wt):n}(e,8*this.size)),e}}class xe extends be{constructor(t){super("string",t)}defaultValue(){return""}encode(t,e){return super.encode(t,yt(_.dereference(e,"string")))}decode(t){return mt(super.decode(t))}}class Re extends zt{constructor(t,e){let n=!1;const r=[];t.forEach((t=>{t.dynamic&&(n=!0),r.push(t.type)})),super("tuple","tuple("+r.join(",")+")",e,n),this.coders=void 0,f(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 n=e.localName;return n&&(t[n]||(t[n]=0),t[n]++),t}),{});return this.coders.forEach(((n,r)=>{let i=n.localName;i&&1===e[i]&&("length"===i&&(i="_length"),null==t[i]&&(t[i]=t[r]))})),Object.freeze(t)}encode(t,e){const n=_.dereference(e,"tuple");return de(t,this.coders,n)}decode(t){return ge(t,this.coders)}}var Ae;function _e(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Ie=0;function je(t){return"__private_"+Ie+++"_"+t}function Ue(t){const e=new Set;return t.forEach((t=>e.add(t))),Object.freeze(e)}const Se=Ue("external public payable override".split(" ")),Fe="constant external internal payable private public pure view override",Ce=Ue(Fe.split(" ")),Le="constructor error event fallback function receive struct",Be=Ue(Le.split(" ")),De="calldata memory storage payable indexed",Me=Ue(De.split(" ")),Ge=Ue([Le,De,"tuple returns",Fe].join(" ").split(" ")),Ve={"(":"OPEN_PAREN",")":"CLOSE_PAREN","[":"OPEN_BRACKET","]":"CLOSE_BRACKET",",":"COMMA","@":"AT"},He=new RegExp("^(\\s*)"),ze=new RegExp("^([0-9]+)"),Je=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)"),Ke=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$"),We=new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$");var qe=je("offset"),$e=je("tokens"),Xe=je("subTokenString");class Ye{get offset(){return _e(this,qe)[qe]}get length(){return _e(this,$e)[$e].length-_e(this,qe)[qe]}constructor(t){Object.defineProperty(this,Xe,{value:Ze}),Object.defineProperty(this,qe,{writable:!0,value:void 0}),Object.defineProperty(this,$e,{writable:!0,value:void 0}),_e(this,qe)[qe]=0,_e(this,$e)[$e]=t.slice()}clone(){return new Ye(_e(this,$e)[$e])}reset(){_e(this,qe)[qe]=0}popKeyword(t){const e=this.peek();if("KEYWORD"!==e.type||!t.has(e.text))throw new Error("expected keyword ".concat(e.text));return this.pop().text}popType(t){if(this.peek().type!==t){const e=this.peek();throw new Error("expected ".concat(t,"; got ").concat(e.type," ").concat(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=_e(this,Xe)[Xe](_e(this,qe)[qe]+1,t.match+1);return _e(this,qe)[qe]=t.match+1,e}popParams(){const t=this.peek();if("OPEN_PAREN"!==t.type)throw new Error("bad start");const e=[];for(;_e(this,qe)[qe]<t.match-1;){const t=this.peek().linkNext;e.push(_e(this,Xe)[Xe](_e(this,qe)[qe]+1,t)),_e(this,qe)[qe]=t}return _e(this,qe)[qe]=t.match+1,e}peek(){if(_e(this,qe)[qe]>=_e(this,$e)[$e].length)throw new Error("out-of-bounds");return _e(this,$e)[$e][_e(this,qe)[qe]]}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 _e(this,qe)[qe]++,t}toString(){const t=[];for(let e=_e(this,qe)[qe];e<_e(this,$e)[$e].length;e++){const n=_e(this,$e)[$e][e];t.push("".concat(n.type,":").concat(n.text))}return"<TokenString ".concat(t.join(" "),">")}}function Ze(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return new Ae(_e(this,$e)[$e].slice(t,e).map((e=>Object.freeze(Object.assign({},e,{match:e.match-t,linkBack:e.linkBack-t,linkNext:e.linkNext-t})))))}function Qe(t){const e=[],n=e=>{const n=s<t.length?JSON.stringify(t[s]):"$EOI";throw new Error("invalid token ".concat(n," at ").concat(s,": ").concat(e))};let r=[],i=[],s=0;for(;s<t.length;){let o=t.substring(s),a=o.match(He);a&&(s+=a[1].length,o=t.substring(s));const c={depth:r.length,linkBack:-1,linkNext:-1,match:-1,type:"",text:"",offset:s,value:-1};e.push(c);let u=Ve[o[0]]||"";if(u){if(c.type=u,c.text=o[0],s++,"OPEN_PAREN"===u)r.push(e.length-1),i.push(e.length-1);else if("CLOSE_PAREN"==u)0===r.length&&n("no matching open bracket"),c.match=r.pop(),e[c.match].match=e.length-1,c.depth--,c.linkBack=i.pop(),e[c.linkBack].linkNext=e.length-1;else if("COMMA"===u)c.linkBack=i.pop(),e[c.linkBack].linkNext=e.length-1,i.push(e.length-1);else if("OPEN_BRACKET"===u)c.type="BRACKET";else if("CLOSE_BRACKET"===u){let t=e.pop().text;if(e.length>0&&"NUMBER"===e[e.length-1].type){const n=e.pop().text;t=n+t,e[e.length-1].value=xt(n)}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=o.match(Je),a){if(c.text=a[1],s+=c.text.length,Ge.has(c.text)){c.type="KEYWORD";continue}if(c.text.match(We)){c.type="TYPE";continue}c.type="ID"}else{if(a=o.match(ze),!a)throw new Error("unexpected token ".concat(JSON.stringify(o[0])," at position ").concat(s));c.text=a[1],c.type="NUMBER",s+=c.text.length}}return new Ye(e.map((t=>Object.freeze(t))))}function tn(t,e){let n=[];for(const r in e.keys())t.has(r)&&n.push(r);if(n.length>1)throw new Error("conflicting types: ".concat(n.join(", ")))}function en(t,e){if(e.peekKeyword(Be)){const n=e.pop().text;if(n!==t)throw new Error("expected ".concat(t,", got ").concat(n))}return e.popType("ID")}function nn(t,e){const n=new Set;for(;;){const r=t.peekType("KEYWORD");if(null==r||e&&!e.has(r))break;if(t.pop(),n.has(r))throw new Error("duplicate keywords: ".concat(JSON.stringify(r)));n.add(r)}return Object.freeze(n)}function rn(t){let e=nn(t,Ce);return tn(e,Ue("constant payable nonpayable".split(" "))),tn(e,Ue("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 sn(t,e){return t.popParams().map((t=>wn.from(t,e)))}function on(t){if(t.peekType("AT")){if(t.pop(),t.peekType("NUMBER"))return Pt(t.pop().text);throw new Error("invalid gas")}return null}function an(t){if(t.length)throw new Error("unexpected tokens at offset ".concat(t.offset,": ").concat(t.toString()))}Ae=Ye;const cn=new RegExp(/^(.*)\[([0-9]*)\]$/);function un(t){const e=t.match(We);if(b(e,"invalid type","type",t),"uint"===t)return"uint256";if("int"===t)return"int256";if(e[2]){const n=parseInt(e[2]);b(0!==n&&n<=32,"invalid bytes length","type",t)}else if(e[3]){const n=parseInt(e[3]);b(0!==n&&n<=256&&n%8==0,"invalid numeric width","type",t)}return t}const ln={},hn=Symbol.for("_ethers_internal"),fn="_ParamTypeInternal",pn="_ErrorInternal",dn="_EventInternal",gn="_ConstructorInternal",yn="_FallbackInternal",mn="_FunctionInternal",bn="_StructInternal";var vn=je("walkAsync");class wn{constructor(t,e,n,r,i,s,o,a){if(Object.defineProperty(this,vn,{value:En}),this.name=void 0,this.type=void 0,this.baseType=void 0,this.indexed=void 0,this.components=void 0,this.arrayLength=void 0,this.arrayChildren=void 0,E(t,ln,"ParamType"),Object.defineProperty(this,hn,{value:fn}),s&&(s=Object.freeze(s.slice())),"array"===r){if(null==o||null==a)throw new Error("")}else if(null!=o||null!=a)throw new Error("");if("tuple"===r){if(null==s)throw new Error("")}else if(null!=s)throw new Error("");f(this,{name:e,type:n,baseType:r,indexed:i,components:s,arrayLength:o,arrayChildren:a})}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+="[".concat(this.arrayLength<0?"":String(this.arrayLength),"]"),JSON.stringify(t)}const n={type:"tuple"===this.baseType?"tuple":this.type,name:e};return"boolean"==typeof this.indexed&&(n.indexed=this.indexed),this.isTuple()&&(n.components=this.components.map((e=>JSON.parse(e.format(t))))),JSON.stringify(n)}let e="";return this.isArray()?(e+=this.arrayChildren.format(t),e+="[".concat(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 n=this;return t.map((t=>n.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 n=this;return t.map(((t,r)=>n.components[r].walk(t,e)))}return e(this.type,t)}async walkAsync(t,e){const n=[],r=[t];return _e(this,vn)[vn](n,t,e,(t=>{r[0]=t})),n.length&&await Promise.all(n),r[0]}static from(t,e){if(wn.isParamType(t))return t;if("string"==typeof t)try{return wn.from(Qe(t),e)}catch(e){b(!1,"invalid param type","obj",t)}else if(t instanceof Ye){let n="",r="",i=null;nn(t,Ue(["tuple"])).has("tuple")||t.peekType("OPEN_PAREN")?(r="tuple",i=t.popParams().map((t=>wn.from(t))),n="tuple(".concat(i.map((t=>t.format())).join(","),")")):(n=un(t.popType("TYPE")),r=n);let s=null,o=null;for(;t.length&&t.peekType("BRACKET");){const e=t.pop();s=new wn(ln,"",n,r,null,i,o,s),o=e.value,n+=e.text,r="array",i=null}let a=null;if(nn(t,Me).has("indexed")){if(!e)throw new Error("");a=!0}const c=t.peekType("ID")?t.pop().text:"";if(t.length)throw new Error("leftover tokens");return new wn(ln,c,n,r,a,i,o,s)}const n=t.name;b(!n||"string"==typeof n&&n.match(Ke),"invalid name","obj.name",n);let r=t.indexed;null!=r&&(b(e,"parameter cannot be indexed","obj.indexed",t.indexed),r=!!r);let i=t.type,s=i.match(cn);if(s){const e=parseInt(s[2]||"-1"),o=wn.from({type:s[1],components:t.components});return new wn(ln,n||"",i,"array",r,null,e,o)}if("tuple"===i||i.startsWith("tuple(")||i.startsWith("(")){const e=null!=t.components?t.components.map((t=>wn.from(t))):null;return new wn(ln,n||"",i,"tuple",r,e,null,null)}return i=un(t.type),new wn(ln,n||"",i,i,r,null,null,null)}static isParamType(t){return t&&t[hn]===fn}}function En(t,e,n,r){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,s=e.slice();return s.forEach(((e,r)=>{_e(i,vn)[vn](t,e,n,(t=>{s[r]=t}))})),void r(s)}if(this.isTuple()){const i=this.components;let s;if(Array.isArray(e))s=e.slice();else{if(null==e||"object"!=typeof e)throw new Error("invalid tuple value");s=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 ".concat(t.name));return e[t.name]}))}if(s.length!==this.components.length)throw new Error("array is wrong length");return s.forEach(((e,r)=>{_e(i[r],vn)[vn](t,e,n,(t=>{s[r]=t}))})),void r(s)}const i=n(this.type,e);i.then?t.push(async function(){r(await i)}()):r(i)}class On{constructor(t,e,n){this.type=void 0,this.inputs=void 0,E(t,ln,"Fragment"),f(this,{type:e,inputs:n=Object.freeze(n.slice())})}static from(t){if("string"==typeof t){try{On.from(JSON.parse(t))}catch(t){}return On.from(Qe(t))}if(t instanceof Ye)switch(t.peekKeyword(Be)){case"constructor":return xn.from(t);case"error":return Tn.from(t);case"event":return kn.from(t);case"fallback":case"receive":return Rn.from(t);case"function":return An.from(t);case"struct":return _n.from(t)}else if("object"==typeof t){switch(t.type){case"constructor":return xn.from(t);case"error":return Tn.from(t);case"event":return kn.from(t);case"fallback":case"receive":return Rn.from(t);case"function":return An.from(t);case"struct":return _n.from(t)}m(!1,"unsupported type: ".concat(t.type),"UNSUPPORTED_OPERATION",{operation:"Fragment.from"})}b(!1,"unsupported frgament object","obj",t)}static isConstructor(t){return xn.isFragment(t)}static isError(t){return Tn.isFragment(t)}static isEvent(t){return kn.isFragment(t)}static isFunction(t){return An.isFragment(t)}static isStruct(t){return _n.isFragment(t)}}class Pn extends On{constructor(t,e,n,r){super(t,e,r),this.name=void 0,b("string"==typeof n&&n.match(Ke),"invalid identifier","name",n),r=Object.freeze(r.slice()),f(this,{name:n})}}function Nn(t,e){return"("+e.map((e=>e.format(t))).join("full"===t?", ":",")+")"}class Tn extends Pn{constructor(t,e,n){super(t,"error",e,n),Object.defineProperty(this,hn,{value:pn})}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+Nn(t,this.inputs)),e.join(" ")}static from(t){if(Tn.isFragment(t))return t;if("string"==typeof t)return Tn.from(Qe(t));if(t instanceof Ye){const e=en("error",t),n=sn(t);return an(t),new Tn(ln,e,n)}return new Tn(ln,t.name,t.inputs?t.inputs.map(wn.from):[])}static isFragment(t){return t&&t[hn]===pn}}class kn extends Pn{constructor(t,e,n,r){super(t,"event",e,n),this.anonymous=void 0,Object.defineProperty(this,hn,{value:dn}),f(this,{anonymous:r})}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+Nn(t,this.inputs)),"sighash"!==t&&this.anonymous&&e.push("anonymous"),e.join(" ")}static getTopicHash(t,e){return e=(e||[]).map((t=>wn.from(t))),new kn(ln,t,e,!1).topicHash}static from(t){if(kn.isFragment(t))return t;if("string"==typeof t)try{return kn.from(Qe(t))}catch(e){b(!1,"invalid event fragment","obj",t)}else if(t instanceof Ye){const e=en("event",t),n=sn(t,!0),r=!!nn(t,Ue(["anonymous"])).has("anonymous");return an(t),new kn(ln,e,n,r)}return new kn(ln,t.name,t.inputs?t.inputs.map((t=>wn.from(t,!0))):[],!!t.anonymous)}static isFragment(t){return t&&t[hn]===dn}}class xn extends On{constructor(t,e,n,r,i){super(t,e,n),this.payable=void 0,this.gas=void 0,Object.defineProperty(this,hn,{value:gn}),f(this,{payable:r,gas:i})}format(t){if(m(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".concat(Nn(t,this.inputs))];return this.payable&&e.push("payable"),null!=this.gas&&e.push("@".concat(this.gas.toString())),e.join(" ")}static from(t){if(xn.isFragment(t))return t;if("string"==typeof t)try{return xn.from(Qe(t))}catch(e){b(!1,"invalid constuctor fragment","obj",t)}else if(t instanceof Ye){nn(t,Ue(["constructor"]));const e=sn(t),n=!!nn(t,Se).has("payable"),r=on(t);return an(t),new xn(ln,"constructor",e,n,r)}return new xn(ln,"constructor",t.inputs?t.inputs.map(wn.from):[],!!t.payable,null!=t.gas?t.gas:null)}static isFragment(t){return t&&t[hn]===gn}}class Rn extends On{constructor(t,e,n){super(t,"fallback",e),this.payable=void 0,Object.defineProperty(this,hn,{value:yn}),f(this,{payable:n})}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"".concat(e,"()").concat(this.payable?" payable":"")}static from(t){if(Rn.isFragment(t))return t;if("string"==typeof t)try{return Rn.from(Qe(t))}catch(e){b(!1,"invalid fallback fragment","obj",t)}else if(t instanceof Ye){const e=t.toString();if(b(t.peekKeyword(Ue(["fallback","receive"])),"type must be fallback or receive","obj",e),"receive"===t.popKeyword(Ue(["fallback","receive"]))){const e=sn(t);return b(0===e.length,"receive cannot have arguments","obj.inputs",e),nn(t,Ue(["payable"])),an(t),new Rn(ln,[],!0)}let n=sn(t);n.length?b(1===n.length&&"bytes"===n[0].type,"invalid fallback inputs","obj.inputs",n.map((t=>t.format("minimal"))).join(", ")):n=[wn.from("bytes")];const r=rn(t);if(b("nonpayable"===r||"payable"===r,"fallback cannot be constants","obj.stateMutability",r),nn(t,Ue(["returns"])).has("returns")){const e=sn(t);b(1===e.length&&"bytes"===e[0].type,"invalid fallback outputs","obj.outputs",e.map((t=>t.format("minimal"))).join(", "))}return an(t),new Rn(ln,n,"payable"===r)}if("receive"===t.type)return new Rn(ln,[],!0);if("fallback"===t.type){const e=[wn.from("bytes")],n="payable"===t.stateMutability;return new Rn(ln,e,n)}b(!1,"invalid fallback description","obj",t)}static isFragment(t){return t&&t[hn]===yn}}class An extends Pn{constructor(t,e,n,r,i,s){super(t,"function",e,r),this.constant=void 0,this.outputs=void 0,this.stateMutability=void 0,this.payable=void 0,this.gas=void 0,Object.defineProperty(this,hn,{value:mn}),f(this,{constant:"view"===n||"pure"===n,gas:s,outputs:i=Object.freeze(i.slice()),payable:"payable"===n,stateMutability:n})}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+Nn(t,this.inputs)),"sighash"!==t&&("nonpayable"!==this.stateMutability&&e.push(this.stateMutability),this.outputs&&this.outputs.length&&(e.push("returns"),e.push(Nn(t,this.outputs))),null!=this.gas&&e.push("@".concat(this.gas.toString()))),e.join(" ")}static getSelector(t,e){return e=(e||[]).map((t=>wn.from(t))),new An(ln,t,"view",e,[],null).selector}static from(t){if(An.isFragment(t))return t;if("string"==typeof t)try{return An.from(Qe(t))}catch(e){b(!1,"invalid function fragment","obj",t)}else if(t instanceof Ye){const e=en("function",t),n=sn(t),r=rn(t);let i=[];nn(t,Ue(["returns"])).has("returns")&&(i=sn(t));const s=on(t);return an(t),new An(ln,e,r,n,i,s)}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 An(ln,t.name,e,t.inputs?t.inputs.map(wn.from):[],t.outputs?t.outputs.map(wn.from):[],null!=t.gas?t.gas:null)}static isFragment(t){return t&&t[hn]===mn}}class _n extends Pn{constructor(t,e,n){super(t,"struct",e,n),Object.defineProperty(this,hn,{value:bn})}format(){throw new Error("@TODO")}static from(t){if("string"==typeof t)try{return _n.from(Qe(t))}catch(e){b(!1,"invalid struct fragment","obj",t)}else if(t instanceof Ye){const e=en("struct",t),n=sn(t);return an(t),new _n(ln,e,n)}return new _n(ln,t.name,t.inputs?t.inputs.map(wn.from):[])}static isFragment(t){return t&&t[hn]===bn}}function In(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var jn=0;function Un(t){return"__private_"+jn+++"_"+t}const Sn=new Map;Sn.set(0,"GENERIC_PANIC"),Sn.set(1,"ASSERT_FALSE"),Sn.set(17,"OVERFLOW"),Sn.set(18,"DIVIDE_BY_ZERO"),Sn.set(33,"ENUM_RANGE_ERROR"),Sn.set(34,"BAD_STORAGE_DATA"),Sn.set(49,"STACK_UNDERFLOW"),Sn.set(50,"ARRAY_RANGE_ERROR"),Sn.set(65,"OUT_OF_MEMORY"),Sn.set(81,"UNINITIALIZED_FUNCTION_CALL");const Fn=new RegExp(/^bytes([0-9]*)$/),Cn=new RegExp(/^(u?int)([0-9]*)$/);let Ln=null,Bn=1024;var Dn=Un("getCoder");class Mn{constructor(){Object.defineProperty(this,Dn,{value:Gn})}getDefaultValue(t){const e=t.map((t=>In(this,Dn)[Dn](wn.from(t))));return new Re(e,"_").defaultValue()}encode(t,e){v(e.length,t.length,"types/values length mismatch");const n=t.map((t=>In(this,Dn)[Dn](wn.from(t)))),r=new Re(n,"_"),i=new qt;return r.encode(i,e),i.data}decode(t,e,n){const r=t.map((t=>In(this,Dn)[Dn](wn.from(t))));return new Re(r,"_").decode(new re(e,n,Bn))}static _setDefaultMaxInflation(t){b("number"==typeof t&&Number.isInteger(t),"invalid defaultMaxInflation factor","value",t),Bn=t}static defaultAbiCoder(){return null==Ln&&(Ln=new Mn),Ln}static getBuiltinCallException(t,e,n){return function(t,e,n,r){let i="missing revert data",s=null,o=null;if(n){i="execution reverted";const t=nt(n);if(n=ot(n),0===t.length)i+=" (no data present; likely require(false) occurred",s="require(false)";else if(t.length%32!=4)i+=" (could not decode reason; invalid data length)";else if("0x08c379a0"===ot(t.slice(0,4)))try{s=r.decode(["string"],t.slice(4))[0],o={signature:"Error(string)",name:"Error",args:[s]},i+=": ".concat(JSON.stringify(s))}catch(t){i+=" (could not decode reason; invalid string data)"}else if("0x4e487b71"===ot(t.slice(0,4)))try{const e=Number(r.decode(["uint256"],t.slice(4))[0]);o={signature:"Panic(uint256)",name:"Panic",args:[e]},s="Panic due to ".concat(Sn.get(e)||"UNKNOWN","(").concat(e,")"),i+=": ".concat(s)}catch(t){i+=" (could not decode panic code)"}else i+=" (unknown custom error)"}const a={to:e.to?he(e.to):null,data:e.data||"0x"};return e.from&&(a.from=he(e.from)),y(i,"CALL_EXCEPTION",{action:t,data:n,reason:s,transaction:a,invocation:null,revert:o})}(t,e,n,Mn.defaultAbiCoder())}}function Gn(t){if(t.isArray())return new ye(In(this,Dn)[Dn](t.arrayChildren),t.arrayLength,t.name);if(t.isTuple())return new Re(t.components.map((t=>In(this,Dn)[Dn](t))),t.name);switch(t.baseType){case"address":return new fe(t.name);case"bool":return new me(t.name);case"string":return new xe(t.name);case"bytes":return new ve(t.name);case"":return new Oe(t.name)}let e=t.type.match(Cn);if(e){let n=parseInt(e[2]||"256");return b(0!==n&&n<=256&&n%8==0,"invalid "+e[1]+" bit length","param",t),new ke(n/8,"int"===e[1],t.name)}if(e=t.type.match(Fn),e){let n=parseInt(e[1]);return b(0!==n&&n<=32,"invalid bytes length","param",t),new we(n,t.name)}b(!1,"invalid type","type",t.type)}function Vn(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Hn=0;function zn(t){return"__private_"+Hn+++"_"+t}class Jn{constructor(t,e,n){this.fragment=void 0,this.name=void 0,this.signature=void 0,this.topic=void 0,this.args=void 0;const r=t.name,i=t.format();f(this,{fragment:t,name:r,signature:i,topic:e,args:n})}}class Kn{constructor(t,e,n,r){this.fragment=void 0,this.name=void 0,this.args=void 0,this.signature=void 0,this.selector=void 0,this.value=void 0;const i=t.name,s=t.format();f(this,{fragment:t,name:i,args:n,signature:s,selector:e,value:r})}}class Wn{constructor(t,e,n){this.fragment=void 0,this.name=void 0,this.args=void 0,this.signature=void 0,this.selector=void 0;const r=t.name,i=t.format();f(this,{fragment:t,name:r,args:n,signature:i,selector:e})}}class qn{static isIndexed(t){return!(!t||!t._isIndexed)}constructor(t){this.hash=void 0,this._isIndexed=void 0,f(this,{hash:t,_isIndexed:!0})}}const $n={0:"generic panic",1:"assert(false)",17:"arithmetic overflow",18:"division or modulo by zero",33:"enum overflow",34:"invalid encoded storage byte array accessed",49:"out-of-bounds array access; popping on an empty array",50:"out-of-bounds access of an array or bytesN",65:"out of memory",81:"uninitialized function"},Xn={"0x08c379a0":{signature:"Error(string)",name:"Error",inputs:["string"],reason:t=>"reverted with reason string ".concat(JSON.stringify(t))},"0x4e487b71":{signature:"Panic(uint256)",name:"Panic",inputs:["uint256"],reason:t=>{let e="unknown panic code";return t>=0&&t<=255&&$n[t.toString()]&&(e=$n[t.toString()]),"reverted with panic code 0x".concat(t.toString(16)," (").concat(e,")")}}};var Yn=zn("errors"),Zn=zn("events"),Qn=zn("functions"),tr=zn("abiCoder"),er=zn("getFunction"),nr=zn("getEvent");class rr{constructor(t){Object.defineProperty(this,nr,{value:sr}),Object.defineProperty(this,er,{value:ir}),this.fragments=void 0,this.deploy=void 0,this.fallback=void 0,this.receive=void 0,Object.defineProperty(this,Yn,{writable:!0,value:void 0}),Object.defineProperty(this,Zn,{writable:!0,value:void 0}),Object.defineProperty(this,Qn,{writable:!0,value:void 0}),Object.defineProperty(this,tr,{writable:!0,value:void 0});let e=[];e="string"==typeof t?JSON.parse(t):t,Vn(this,Qn)[Qn]=new Map,Vn(this,Yn)[Yn]=new Map,Vn(this,Zn)[Zn]=new Map;const n=[];for(const t of e)try{n.push(On.from(t))}catch(e){console.log("[Warning] Invalid Fragment ".concat(JSON.stringify(t),":"),e.message)}f(this,{fragments:Object.freeze(n)});let r=null,i=!1;Vn(this,tr)[tr]=this.getAbiCoder(),this.fragments.forEach(((t,e)=>{let n;switch(t.type){case"constructor":return this.deploy?void console.log("duplicate definition - constructor"):void f(this,{deploy:t});case"fallback":return void(0===t.inputs.length?i=!0:(b(!r||t.payable!==r.payable,"conflicting fallback fragments","fragments[".concat(e,"]"),t),r=t,i=r.payable));case"function":n=Vn(this,Qn)[Qn];break;case"event":n=Vn(this,Zn)[Zn];break;case"error":n=Vn(this,Yn)[Yn];break;default:return}const s=t.format();n.has(s)||n.set(s,t)})),this.deploy||f(this,{deploy:xn.from("constructor()")}),f(this,{fallback:r,receive:i})}format(t){const e=t?"minimal":"full";return this.fragments.map((t=>t.format(e)))}formatJson(){const t=this.fragments.map((t=>t.format("json")));return JSON.stringify(t.map((t=>JSON.parse(t))))}getAbiCoder(){return Mn.defaultAbiCoder()}getFunctionName(t){const e=Vn(this,er)[er](t,null,!1);return b(e,"no matching function","key",t),e.name}hasFunction(t){return!!Vn(this,er)[er](t,null,!1)}getFunction(t,e){return Vn(this,er)[er](t,e||null,!0)}forEachFunction(t){const e=Array.from(Vn(this,Qn)[Qn].keys());e.sort(((t,e)=>t.localeCompare(e)));for(let n=0;n<e.length;n++){const r=e[n];t(Vn(this,Qn)[Qn].get(r),n)}}getEventName(t){const e=Vn(this,nr)[nr](t,null,!1);return b(e,"no matching event","key",t),e.name}hasEvent(t){return!!Vn(this,nr)[nr](t,null,!1)}getEvent(t,e){return Vn(this,nr)[nr](t,e||null,!0)}forEachEvent(t){const e=Array.from(Vn(this,Zn)[Zn].keys());e.sort(((t,e)=>t.localeCompare(e)));for(let n=0;n<e.length;n++){const r=e[n];t(Vn(this,Zn)[Zn].get(r),n)}}getError(t,e){if(it(t)){const e=t.toLowerCase();if(Xn[e])return Tn.from(Xn[e].signature);for(const t of Vn(this,Yn)[Yn].values())if(e===t.selector)return t;return null}if(-1===t.indexOf("(")){const e=[];for(const[n,r]of Vn(this,Yn)[Yn])n.split("(")[0]===t&&e.push(r);if(0===e.length)return"Error"===t?Tn.from("error Error(string)"):"Panic"===t?Tn.from("error Panic(uint256)"):null;if(e.length>1){const n=e.map((t=>JSON.stringify(t.format()))).join(", ");b(!1,"ambiguous error description (i.e. ".concat(n,")"),"name",t)}return e[0]}if("Error(string)"===(t=Tn.from(t).format()))return Tn.from("error Error(string)");if("Panic(uint256)"===t)return Tn.from("error Panic(uint256)");return Vn(this,Yn)[Yn].get(t)||null}forEachError(t){const e=Array.from(Vn(this,Yn)[Yn].keys());e.sort(((t,e)=>t.localeCompare(e)));for(let n=0;n<e.length;n++){const r=e[n];t(Vn(this,Yn)[Yn].get(r),n)}}_decodeParams(t,e){return Vn(this,tr)[tr].decode(t,e)}_encodeParams(t,e){return Vn(this,tr)[tr].encode(t,e)}encodeDeploy(t){return this._encodeParams(this.deploy.inputs,t||[])}decodeErrorResult(t,e){if("string"==typeof t){const e=this.getError(t);b(e,"unknown error","fragment",t),t=e}return b(ct(e,0,4)===t.selector,"data signature does not match error ".concat(t.name,"."),"data",e),this._decodeParams(t.inputs,ct(e,4))}encodeErrorResult(t,e){if("string"==typeof t){const e=this.getError(t);b(e,"unknown error","fragment",t),t=e}return at([t.selector,this._encodeParams(t.inputs,e||[])])}decodeFunctionData(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}return b(ct(e,0,4)===t.selector,"data signature does not match function ".concat(t.name,"."),"data",e),this._decodeParams(t.inputs,ct(e,4))}encodeFunctionData(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}return at([t.selector,this._encodeParams(t.inputs,e||[])])}decodeFunctionResult(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}let n="invalid length for result data";const r=rt(e);if(r.length%32==0)try{return Vn(this,tr)[tr].decode(t.outputs,r)}catch(t){n="could not decode result data"}m(!1,n,"BAD_DATA",{value:ot(r),info:{method:t.name,signature:t.format()}})}makeError(t,e){const n=nt(t,"data"),r=Mn.getBuiltinCallException("call",e,n);if(r.message.startsWith("execution reverted (unknown custom error)")){const t=ot(n.slice(0,4)),e=this.getError(t);if(e)try{const t=Vn(this,tr)[tr].decode(e.inputs,n.slice(4));r.revert={name:e.name,signature:e.format(),args:t},r.reason=r.revert.signature,r.message="execution reverted: ".concat(r.reason)}catch(t){r.message="execution reverted (coult not decode custom error)"}}const i=this.parseTransaction(e);return i&&(r.invocation={method:i.name,signature:i.signature,args:i.args}),r}encodeFunctionResult(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}return ot(Vn(this,tr)[tr].encode(t.outputs,e||[]))}encodeFilterTopics(t,e){if("string"==typeof t){const e=this.getEvent(t);b(e,"unknown event","eventFragment",t),t=e}m(e.length<=t.inputs.length,"too many arguments for ".concat(t.format()),"UNEXPECTED_ARGUMENT",{count:e.length,expectedCount:t.inputs.length});const n=[];t.anonymous||n.push(t.topicHash);const r=(t,e)=>"string"===t.type?bt(e):"bytes"===t.type?pt(ot(e)):("bool"===t.type&&"boolean"==typeof e?e=e?"0x01":"0x00":t.type.match(/^u?int/)?e=Rt(e):t.type.match(/^bytes/)?e=ut(e,32,!1):"address"===t.type&&Vn(this,tr)[tr].encode(["address"],[e]),ut(ot(e),32,!0));for(e.forEach(((e,i)=>{const s=t.inputs[i];s.indexed?null==e?n.push(null):"array"===s.baseType||"tuple"===s.baseType?b(!1,"filtering with tuples or arrays not supported","contract."+s.name,e):Array.isArray(e)?n.push(e.map((t=>r(s,t)))):n.push(r(s,e)):b(null==e,"cannot filter non-indexed parameters; must be null","contract."+s.name,e)}));n.length&&null===n[n.length-1];)n.pop();return n}encodeEventLog(t,e){if("string"==typeof t){const e=this.getEvent(t);b(e,"unknown event","eventFragment",t),t=e}const n=[],r=[],i=[];return t.anonymous||n.push(t.topicHash),b(e.length===t.inputs.length,"event arguments/values mismatch","values",e),t.inputs.forEach(((t,s)=>{const o=e[s];if(t.indexed)if("string"===t.type)n.push(bt(o));else if("bytes"===t.type)n.push(pt(o));else{if("tuple"===t.baseType||"array"===t.baseType)throw new Error("not implemented");n.push(Vn(this,tr)[tr].encode([t.type],[o]))}else r.push(t),i.push(o)})),{data:Vn(this,tr)[tr].encode(r,i),topics:n}}decodeEventLog(t,e,n){if("string"==typeof t){const e=this.getEvent(t);b(e,"unknown event","eventFragment",t),t=e}if(null!=n&&!t.anonymous){const e=t.topicHash;b(it(n[0],32)&&n[0].toLowerCase()===e,"fragment/topic mismatch","topics[0]",n[0]),n=n.slice(1)}const r=[],i=[],s=[];t.inputs.forEach(((t,e)=>{t.indexed?"string"===t.type||"bytes"===t.type||"tuple"===t.baseType||"array"===t.baseType?(r.push(wn.from({type:"bytes32",name:t.name})),s.push(!0)):(r.push(t),s.push(!1)):(i.push(t),s.push(!1))}));const o=null!=n?Vn(this,tr)[tr].decode(r,at(n)):null,a=Vn(this,tr)[tr].decode(i,e,!0),c=[],u=[];let l=0,h=0;return t.inputs.forEach(((t,e)=>{let n=null;if(t.indexed)if(null==o)n=new qn(null);else if(s[e])n=new qn(o[h++]);else try{n=o[h++]}catch(t){n=t}else try{n=a[l++]}catch(t){n=t}c.push(n),u.push(t.name||null)})),Vt.fromItems(c,u)}parseTransaction(t){const e=nt(t.data,"tx.data"),n=Pt(null!=t.value?t.value:0,"tx.value"),r=this.getFunction(ot(e.slice(0,4)));if(!r)return null;const i=Vn(this,tr)[tr].decode(r.inputs,e.slice(4));return new Kn(r,r.selector,i,n)}parseCallResult(t){throw new Error("@TODO")}parseLog(t){const e=this.getEvent(t.topics[0]);return!e||e.anonymous?null:new Jn(e,e.topicHash,this.decodeEventLog(e,t.data,t.topics))}parseError(t){const e=ot(t),n=this.getError(ct(e,0,4));if(!n)return null;const r=Vn(this,tr)[tr].decode(n.inputs,ct(e,4));return new Wn(n,n.selector,r)}static from(t){return t instanceof rr?t:"string"==typeof t?new rr(JSON.parse(t)):"function"==typeof t.formatJson?new rr(t.formatJson()):"function"==typeof t.format?new rr(t.format("json")):new rr(t)}}function ir(t,e,n){if(it(t)){const e=t.toLowerCase();for(const t of Vn(this,Qn)[Qn].values())if(e===t.selector)return t;return null}if(-1===t.indexOf("(")){const r=[];for(const[e,n]of Vn(this,Qn)[Qn])e.split("(")[0]===t&&r.push(n);if(e){const t=e.length>0?e[e.length-1]:null;let n=e.length,i=!0;_.isTyped(t)&&"overrides"===t.type&&(i=!1,n--);for(let t=r.length-1;t>=0;t--){const e=r[t].inputs.length;e===n||i&&e===n-1||r.splice(t,1)}for(let t=r.length-1;t>=0;t--){const n=r[t].inputs;for(let i=0;i<e.length;i++)if(_.isTyped(e[i])){if(i>=n.length){if("overrides"===e[i].type)continue;r.splice(t,1);break}if(e[i].type!==n[i].baseType){r.splice(t,1);break}}}}if(1===r.length&&e&&e.length!==r[0].inputs.length){const t=e[e.length-1];(null==t||Array.isArray(t)||"object"!=typeof t)&&r.splice(0,1)}if(0===r.length)return null;if(r.length>1&&n){const e=r.map((t=>JSON.stringify(t.format()))).join(", ");b(!1,"ambiguous function description (i.e. matches ".concat(e,")"),"key",t)}return r[0]}return Vn(this,Qn)[Qn].get(An.from(t).format())||null}function sr(t,e,n){if(it(t)){const e=t.toLowerCase();for(const t of Vn(this,Zn)[Zn].values())if(e===t.topicHash)return t;return null}if(-1===t.indexOf("(")){const r=[];for(const[e,n]of Vn(this,Zn)[Zn])e.split("(")[0]===t&&r.push(n);if(e){for(let t=r.length-1;t>=0;t--)r[t].inputs.length<e.length&&r.splice(t,1);for(let t=r.length-1;t>=0;t--){const n=r[t].inputs;for(let i=0;i<e.length;i++)if(_.isTyped(e[i])&&e[i].type!==n[i].baseType){r.splice(t,1);break}}}if(0===r.length)return null;if(r.length>1&&n){const e=r.map((t=>JSON.stringify(t.format()))).join(", ");b(!1,"ambiguous event description (i.e. matches ".concat(e,")"),"key",t)}return r[0]}return Vn(this,Zn)[Zn].get(kn.from(t).format())||null}function or(t){return t&&"function"==typeof t.getAddress}async function ar(t,e){const n=await e;return null!=n&&"0x0000000000000000000000000000000000000000"!==n||(m("string"!=typeof t,"unconfigured name","UNCONFIGURED_NAME",{value:t}),b(!1,"invalid AddressLike value; did not resolve to a value address","target",t)),he(n)}function cr(t,e){return"string"==typeof t?t.match(/^0x[0-9a-f]{40}$/i)?he(t):(m(null!=e,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),ar(t,e.resolveName(t))):or(t)?ar(t,t.getAddress()):t&&"function"==typeof t.then?ar(t,t):void b(!1,"unsupported addressable value","target",t)}function ur(t,e){return{address:he(t),storageKeys:e.map(((t,e)=>(b(it(t,32),"invalid slot","storageKeys[".concat(e,"]"),t),t.toLowerCase())))}}function lr(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var hr=0;function fr(t){return"__private_"+hr+++"_"+t}const pr=BigInt(0);function dr(t){return null==t?null:t.toString()}Symbol.iterator;class gr{constructor(t,e){this.provider=void 0,this.transactionHash=void 0,this.blockHash=void 0,this.blockNumber=void 0,this.removed=void 0,this.address=void 0,this.data=void 0,this.topics=void 0,this.index=void 0,this.transactionIndex=void 0,this.provider=e;const n=Object.freeze(t.topics.slice());f(this,{transactionHash:t.transactionHash,blockHash:t.blockHash,blockNumber:t.blockNumber,removed:t.removed,address:t.address,data:t.data,topics:n,index:t.index,transactionIndex:t.transactionIndex})}toJSON(){const{address:t,blockHash:e,blockNumber:n,data:r,index:i,removed:s,topics:o,transactionHash:a,transactionIndex:c}=this;return{_type:"log",address:t,blockHash:e,blockNumber:n,data:r,index:i,removed:s,topics:o,transactionHash:a,transactionIndex:c}}async getBlock(){const t=await this.provider.getBlock(this.blockHash);return m(!!t,"failed to find transaction","UNKNOWN_ERROR",{}),t}async getTransaction(){const t=await this.provider.getTransaction(this.transactionHash);return m(!!t,"failed to find transaction","UNKNOWN_ERROR",{}),t}async getTransactionReceipt(){const t=await this.provider.getTransactionReceipt(this.transactionHash);return m(!!t,"failed to find transaction receipt","UNKNOWN_ERROR",{}),t}removedEvent(){return{orphan:"drop-log",log:{transactionHash:(t=this).transactionHash,blockHash:t.blockHash,blockNumber:t.blockNumber,address:t.address,data:t.data,topics:Object.freeze(t.topics.slice()),index:t.index}};var t}}var yr=fr("logs");class mr{constructor(t,e){this.provider=void 0,this.to=void 0,this.from=void 0,this.contractAddress=void 0,this.hash=void 0,this.index=void 0,this.blockHash=void 0,this.blockNumber=void 0,this.logsBloom=void 0,this.gasUsed=void 0,this.blobGasUsed=void 0,this.cumulativeGasUsed=void 0,this.gasPrice=void 0,this.blobGasPrice=void 0,this.type=void 0,this.status=void 0,this.root=void 0,Object.defineProperty(this,yr,{writable:!0,value:void 0}),lr(this,yr)[yr]=Object.freeze(t.logs.map((t=>new gr(t,e))));let n=pr;null!=t.effectiveGasPrice?n=t.effectiveGasPrice:null!=t.gasPrice&&(n=t.gasPrice),f(this,{provider:e,to:t.to,from:t.from,contractAddress:t.contractAddress,hash:t.hash,index:t.index,blockHash:t.blockHash,blockNumber:t.blockNumber,logsBloom:t.logsBloom,gasUsed:t.gasUsed,cumulativeGasUsed:t.cumulativeGasUsed,blobGasUsed:t.blobGasUsed,gasPrice:n,blobGasPrice:t.blobGasPrice,type:t.type,status:t.status,root:t.root})}get logs(){return lr(this,yr)[yr]}toJSON(){const{to:t,from:e,contractAddress:n,hash:r,index:i,blockHash:s,blockNumber:o,logsBloom:a,logs:c,status:u,root:l}=this;return{_type:"TransactionReceipt",blockHash:s,blockNumber:o,contractAddress:n,cumulativeGasUsed:dr(this.cumulativeGasUsed),from:e,gasPrice:dr(this.gasPrice),blobGasUsed:dr(this.blobGasUsed),blobGasPrice:dr(this.blobGasPrice),gasUsed:dr(this.gasUsed),hash:r,index:i,logs:c,logsBloom:a,root:l,status:u,to:t}}get length(){return this.logs.length}[Symbol.iterator](){let t=0;return{next:()=>t<this.length?{value:this.logs[t++],done:!1}:{value:void 0,done:!0}}}get fee(){return this.gasUsed*this.gasPrice}async getBlock(){const t=await this.provider.getBlock(this.blockHash);if(null==t)throw new Error("TODO");return t}async getTransaction(){const t=await this.provider.getTransaction(this.hash);if(null==t)throw new Error("TODO");return t}async getResult(){return await this.provider.getTransactionResult(this.hash)}async confirmations(){return await this.provider.getBlockNumber()-this.blockNumber+1}removedEvent(){return Er(this)}reorderedEvent(t){return m(!t||t.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),wr(this,t)}}var br=fr("startBlock");class vr{constructor(t,e){this.provider=void 0,this.blockNumber=void 0,this.blockHash=void 0,this.index=void 0,this.hash=void 0,this.type=void 0,this.to=void 0,this.from=void 0,this.nonce=void 0,this.gasLimit=void 0,this.gasPrice=void 0,this.maxPriorityFeePerGas=void 0,this.maxFeePerGas=void 0,this.maxFeePerBlobGas=void 0,this.data=void 0,this.value=void 0,this.chainId=void 0,this.signature=void 0,this.accessList=void 0,this.blobVersionedHashes=void 0,this.authorizationList=void 0,Object.defineProperty(this,br,{writable:!0,value:void 0}),this.provider=e,this.blockNumber=null!=t.blockNumber?t.blockNumber:null,this.blockHash=null!=t.blockHash?t.blockHash:null,this.hash=t.hash,this.index=t.index,this.type=t.type,this.from=t.from,this.to=t.to||null,this.gasLimit=t.gasLimit,this.nonce=t.nonce,this.data=t.data,this.value=t.value,this.gasPrice=t.gasPrice,this.maxPriorityFeePerGas=null!=t.maxPriorityFeePerGas?t.maxPriorityFeePerGas:null,this.maxFeePerGas=null!=t.maxFeePerGas?t.maxFeePerGas:null,this.maxFeePerBlobGas=null!=t.maxFeePerBlobGas?t.maxFeePerBlobGas:null,this.chainId=t.chainId,this.signature=t.signature,this.accessList=null!=t.accessList?t.accessList:null,this.blobVersionedHashes=null!=t.blobVersionedHashes?t.blobVersionedHashes:null,this.authorizationList=null!=t.authorizationList?t.authorizationList:null,lr(this,br)[br]=-1}toJSON(){const{blockNumber:t,blockHash:e,index:n,hash:r,type:i,to:s,from:o,nonce:a,data:c,signature:u,accessList:l,blobVersionedHashes:h}=this;return{_type:"TransactionResponse",accessList:l,blockNumber:t,blockHash:e,blobVersionedHashes:h,chainId:dr(this.chainId),data:c,from:o,gasLimit:dr(this.gasLimit),gasPrice:dr(this.gasPrice),hash:r,maxFeePerGas:dr(this.maxFeePerGas),maxPriorityFeePerGas:dr(this.maxPriorityFeePerGas),maxFeePerBlobGas:dr(this.maxFeePerBlobGas),nonce:a,signature:u,to:s,index:n,type:i,value:dr(this.value)}}async getBlock(){let t=this.blockNumber;if(null==t){const e=await this.getTransaction();e&&(t=e.blockNumber)}if(null==t)return null;const e=this.provider.getBlock(t);if(null==e)throw new Error("TODO");return e}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(null==this.blockNumber){const{tx:t,blockNumber:e}=await h({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});return null==t||null==t.blockNumber?0:e-t.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(t,e){const n=null==t?1:t,r=null==e?0:e;let i=lr(this,br)[br],s=-1,o=-1===i;const a=async()=>{if(o)return null;const{blockNumber:t,nonce:e}=await h({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(e<this.nonce)return void(i=t);if(o)return null;const r=await this.getTransaction();if(!r||null==r.blockNumber)for(-1===s&&(s=i-3,s<lr(this,br)[br]&&(s=lr(this,br)[br]));s<=t;){if(o)return null;const e=await this.provider.getBlock(s,!0);if(null==e)return;for(const t of e)if(t===this.hash)return;for(let r=0;r<e.length;r++){const s=await e.getTransaction(r);if(s.from===this.from&&s.nonce===this.nonce){if(o)return null;const e=await this.provider.getTransactionReceipt(s.hash);if(null==e)return;if(t-e.blockNumber+1<n)return;let r="replaced";s.data===this.data&&s.to===this.to&&s.value===this.value?r="repriced":"0x"===s.data&&s.from===s.to&&s.value===pr&&(r="cancelled"),m(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:"replaced"===r||"cancelled"===r,reason:r,replacement:s.replaceableTransaction(i),hash:s.hash,receipt:e})}}s++}},c=t=>{if(null==t||0!==t.status)return t;m(!1,"transaction execution reverted","CALL_EXCEPTION",{action:"sendTransaction",data:null,reason:null,invocation:null,revert:null,transaction:{to:t.to,from:t.from,data:""},receipt:t})},u=await this.provider.getTransactionReceipt(this.hash);if(0===n)return c(u);if(u){if(1===n||await u.confirmations()>=n)return c(u)}else if(await a(),0===n)return null;const l=new Promise(((t,e)=>{const s=[],u=()=>{s.forEach((t=>t()))};if(s.push((()=>{o=!0})),r>0){const t=setTimeout((()=>{u(),e(y("wait for transaction timeout","TIMEOUT"))}),r);s.push((()=>{clearTimeout(t)}))}const l=async r=>{if(await r.confirmations()>=n){u();try{t(c(r))}catch(t){e(t)}}};if(s.push((()=>{this.provider.off(this.hash,l)})),this.provider.on(this.hash,l),i>=0){const t=async()=>{try{await a()}catch(t){if(d(t,"TRANSACTION_REPLACED"))return u(),void e(t)}o||this.provider.once("block",t)};s.push((()=>{this.provider.off("block",t)})),this.provider.once("block",t)}}));return await l}isMined(){return null!=this.blockHash}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}removedEvent(){return m(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),Er(this)}reorderedEvent(t){return m(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),m(!t||t.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),wr(this,t)}replaceableTransaction(t){b(Number.isInteger(t)&&t>=0,"invalid startBlock","startBlock",t);const e=new vr(this,this.provider);return lr(e,br)[br]=t,e}}function wr(t,e){return{orphan:"reorder-transaction",tx:t,other:e}}function Er(t){return{orphan:"drop-transaction",tx:t}}function Or(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Pr=0;function Nr(t){return"__private_"+Pr+++"_"+t}var Tr=Nr("listener");class kr{constructor(t,e,n){this.filter=void 0,this.emitter=void 0,Object.defineProperty(this,Tr,{writable:!0,value:void 0}),Or(this,Tr)[Tr]=e,f(this,{emitter:t,filter:n})}async removeListener(){null!=Or(this,Tr)[Tr]&&await this.emitter.off(this.filter,Or(this,Tr)[Tr])}}function xr(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Rr=0;function Ar(t){return"__private_"+Rr+++"_"+t}class _r extends gr{constructor(t,e,n){super(t,t.provider),this.interface=void 0,this.fragment=void 0,this.args=void 0,f(this,{args:e.decodeEventLog(n,t.data,t.topics),fragment:n,interface:e})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}class Ir extends gr{constructor(t,e){super(t,t.provider),this.error=void 0,f(this,{error:e})}}var jr=Ar("iface");class Ur extends mr{constructor(t,e,n){super(n,e),Object.defineProperty(this,jr,{writable:!0,value:void 0}),xr(this,jr)[jr]=t}get logs(){return super.logs.map((t=>{const e=t.topics.length?xr(this,jr)[jr].getEvent(t.topics[0]):null;if(e)try{return new _r(t,xr(this,jr)[jr],e)}catch(e){return new Ir(t,e)}return t}))}}var Sr=Ar("iface");class Fr extends vr{constructor(t,e,n){super(n,e),Object.defineProperty(this,Sr,{writable:!0,value:void 0}),xr(this,Sr)[Sr]=t}async wait(t,e){const n=await super.wait(t,e);return null==n?null:new Ur(xr(this,Sr)[Sr],this.provider,n)}}class Cr extends kr{constructor(t,e,n,r){super(t,e,n),this.log=void 0,f(this,{log:r})}async getBlock(){return await this.log.getBlock()}async getTransaction(){return await this.log.getTransaction()}async getTransactionReceipt(){return await this.log.getTransactionReceipt()}}class Lr extends Cr{constructor(t,e,n,r,i){super(t,e,n,new _r(i,t.interface,r)),f(this,{args:t.interface.decodeEventLog(r,this.log.data,this.log.topics),fragment:r})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}function Br(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Dr=0;function Mr(t){return"__private_"+Dr+++"_"+t}const Gr=BigInt(0);function Vr(t){return t&&"function"==typeof t.call}function Hr(t){return t&&"function"==typeof t.estimateGas}function zr(t){return t&&"function"==typeof t.resolveName}function Jr(t){return t&&"function"==typeof t.sendTransaction}function Kr(t){if(null!=t){if(zr(t))return t;if(t.provider)return t.provider}}var Wr=Mr("filter");class qr{constructor(t,e,n){if(Object.defineProperty(this,Wr,{writable:!0,value:void 0}),this.fragment=void 0,f(this,{fragment:e}),e.inputs.length<n.length)throw new Error("too many arguments");const r=$r(t.runner,"resolveName"),i=zr(r)?r:null;Br(this,Wr)[Wr]=async function(){const r=await Promise.all(e.inputs.map(((t,e)=>null==n[e]?null:t.walkAsync(n[e],((t,e)=>"address"===t?Array.isArray(e)?Promise.all(e.map((t=>cr(t,i)))):cr(e,i):e)))));return t.interface.encodeFilterTopics(e,r)}()}getTopicFilter(){return Br(this,Wr)[Wr]}}function $r(t,e){return null==t?null:"function"==typeof t[e]?t:t.provider&&"function"==typeof t.provider[e]?t.provider:null}function Xr(t){return null==t?null:t.provider||null}async function Yr(t,e){const n=_.dereference(t,"overrides");b("object"==typeof n,"invalid overrides parameter","overrides",t);const r=function(t){const e={};t.to&&(e.to=t.to),t.from&&(e.from=t.from),t.data&&(e.data=ot(t.data));const n="chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);for(const r of n)r in t&&null!=t[r]&&(e[r]=Pt(t[r],"request.".concat(r)));const r="type,nonce".split(/,/);for(const n of r)n in t&&null!=t[n]&&(e[n]=xt(t[n],"request.".concat(n)));return t.accessList&&(e.accessList=function(t){if(Array.isArray(t))return t.map(((e,n)=>Array.isArray(e)?(b(2===e.length,"invalid slot set","value[".concat(n,"]"),e),ur(e[0],e[1])):(b(null!=e&&"object"==typeof e,"invalid address-slot set","value",t),ur(e.address,e.storageKeys))));b(null!=t&&"object"==typeof t,"invalid access list","value",t);const e=Object.keys(t).map((e=>{const n=t[e].reduce(((t,e)=>(t[e]=!0,t)),{});return ur(e,Object.keys(n).sort())}));return e.sort(((t,e)=>t.address.localeCompare(e.address))),e}(t.accessList)),t.authorizationList&&(e.authorizationList=t.authorizationList.slice()),"blockTag"in t&&(e.blockTag=t.blockTag),"enableCcipRead"in t&&(e.enableCcipRead=!!t.enableCcipRead),"customData"in t&&(e.customData=t.customData),"blobVersionedHashes"in t&&t.blobVersionedHashes&&(e.blobVersionedHashes=t.blobVersionedHashes.slice()),"kzg"in t&&(e.kzg=t.kzg),"blobWrapperVersion"in t&&(e.blobWrapperVersion=t.blobWrapperVersion),"blobs"in t&&t.blobs&&(e.blobs=t.blobs.map((t=>{return it(e=t,!0)||e instanceof Uint8Array?ot(t):Object.assign({},t);var e}))),e}(n);return b(null==r.to||(e||[]).indexOf("to")>=0,"cannot override to","overrides.to",r.to),b(null==r.data||(e||[]).indexOf("data")>=0,"cannot override data","overrides.data",r.data),r.from&&(r.from=r.from),r}function Zr(t){const e=async function(e){const n=await Yr(e,["data"]);n.to=await t.getAddress(),n.from&&(n.from=await cr(n.from,Kr(t.runner)));const r=t.interface,i=Pt(n.value||Gr,"overrides.value")===Gr,s="0x"===(n.data||"0x");return!r.fallback||r.fallback.payable||!r.receive||s||i||b(!1,"cannot send data to receive or send value to non-payable fallback","overrides",e),b(r.fallback||s,"cannot send data to receive-only contract","overrides.data",n.data),b(r.receive||r.fallback&&r.fallback.payable||i,"cannot send value to non-payable fallback","overrides.value",n.value),b(r.fallback||s,"cannot send data to receive-only contract","overrides.data",n.data),n},n=async function(n){const r=t.runner;m(Jr(r),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const i=await r.sendTransaction(await e(n)),s=Xr(t.runner);return new Fr(t.interface,s,i)},r=async t=>await n(t);return f(r,{_contract:t,estimateGas:async function(n){const r=$r(t.runner,"estimateGas");return m(Hr(r),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await r.estimateGas(await e(n))},populateTransaction:e,send:n,staticCall:async function(n){const r=$r(t.runner,"call");m(Vr(r),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const i=await e(n);try{return await r.call(i)}catch(e){if(g(e)&&e.data)throw t.interface.makeError(e.data,i);throw e}}}),r}const Qr=Symbol.for("_ethersInternal_contract"),ti=new WeakMap;function ei(t){return ti.get(t[Qr])}async function ni(t,e){let n,r=null;if(Array.isArray(e)){const r=function(e){if(it(e,32))return e;const n=t.interface.getEvent(e);return b(n,"unknown fragment","name",e),n.topicHash};n=e.map((t=>null==t?null:Array.isArray(t)?t.map(r):r(t)))}else"*"===e?n=[null]:"string"==typeof e?it(e,32)?n=[e]:(r=t.interface.getEvent(e),b(r,"unknown fragment","event",e),n=[r.topicHash]):(i=e)&&"object"==typeof i&&"getTopicFilter"in i&&"function"==typeof i.getTopicFilter&&i.fragment?n=await e.getTopicFilter():"fragment"in e?(r=e.fragment,n=[r.topicHash]):b(!1,"unknown event name","event",e);var i;return n=n.map((t=>{if(null==t)return null;if(Array.isArray(t)){const e=Array.from(new Set(t.map((t=>t.toLowerCase()))).values());return 1===e.length?e[0]:(e.sort(),e)}return t.toLowerCase()})),{fragment:r,tag:n.map((t=>null==t?"null":Array.isArray(t)?t.join("|"):t)).join("&"),topics:n}}async function ri(t,e){const{subs:n}=ei(t);return n.get((await ni(t,e)).tag)||null}async function ii(t,e,n){const r=Xr(t.runner);m(r,"contract runner does not support subscribing","UNSUPPORTED_OPERATION",{operation:e});const{fragment:i,tag:s,topics:o}=await ni(t,n),{addr:a,subs:c}=ei(t);let u=c.get(s);if(!u){const e={address:a||t,topics:o},l=e=>{let r=i;if(null==r)try{r=t.interface.getEvent(e.topics[0])}catch(t){}if(r){const s=r,o=i?t.interface.decodeEventLog(i,e.data,e.topics):[];oi(t,n,o,(r=>new Lr(t,r,n,s,e)))}else oi(t,n,[],(r=>new Cr(t,r,n,e)))};let h=[];u={tag:s,listeners:[],start:()=>{h.length||h.push(r.on(e,l))},stop:async()=>{if(0==h.length)return;let t=h;h=[],await Promise.all(t),r.off(e,l)}},c.set(s,u)}return u}let si=Promise.resolve();async function oi(t,e,n,r){try{await si}catch(t){}const i=async function(t,e,n,r){await si;const i=await ri(t,e);if(!i)return!1;const s=i.listeners.length;return i.listeners=i.listeners.filter((e=>{let{listener:i,once:s}=e;const o=Array.from(n);r&&o.push(r(s?null:i));try{i.call(t,...o)}catch(t){}return!s})),0===i.listeners.length&&(i.stop(),ei(t).subs.delete(i.tag)),s>0}(t,e,n,r);return si=i,await i}const ai=["then"];class ci{constructor(t,e,n,r){this.target=void 0,this.interface=void 0,this.runner=void 0,this.filters=void 0,this[Qr]=void 0,this.fallback=void 0,b("string"==typeof t||or(t),"invalid value for Contract target","target",t),null==n&&(n=null);const i=rr.from(e);let s;f(this,{target:t,runner:n,interface:i}),Object.defineProperty(this,Qr,{value:{}});let o=null,a=null;if(r){const t=Xr(n);a=new Fr(this.interface,t,r)}let c=new Map;if("string"==typeof t)if(it(t))o=t,s=Promise.resolve(t);else{const e=$r(n,"resolveName");if(!zr(e))throw y("contract runner does not support name resolution","UNSUPPORTED_OPERATION",{operation:"resolveName"});s=e.resolveName(t).then((e=>{if(null==e)throw y("an ENS name used for a contract target must be correctly configured","UNCONFIGURED_NAME",{value:t});return ei(this).addr=e,e}))}else s=t.getAddress().then((t=>{if(null==t)throw new Error("TODO");return ei(this).addr=t,t}));var u;u={addrPromise:s,addr:o,deployTx:a,subs:c},ti.set(this[Qr],u);const l=new Proxy({},{get:(t,e,n)=>{if("symbol"==typeof e||ai.indexOf(e)>=0)return Reflect.get(t,e,n);try{return this.getEvent(e)}catch(t){if(!d(t,"INVALID_ARGUMENT")||"key"!==t.argument)throw t}},has:(t,e)=>ai.indexOf(e)>=0?Reflect.has(t,e):Reflect.has(t,e)||this.interface.hasEvent(String(e))});return f(this,{filters:l}),f(this,{fallback:i.receive||i.fallback?Zr(this):null}),new Proxy(this,{get:(t,e,n)=>{if("symbol"==typeof e||e in t||ai.indexOf(e)>=0)return Reflect.get(t,e,n);try{return t.getFunction(e)}catch(t){if(!d(t,"INVALID_ARGUMENT")||"key"!==t.argument)throw t}},has:(t,e)=>"symbol"==typeof e||e in t||ai.indexOf(e)>=0?Reflect.has(t,e):t.interface.hasFunction(e)})}connect(t){return new ci(this.target,this.interface,t)}attach(t){return new ci(t,this.interface,this.runner)}async getAddress(){return await ei(this).addrPromise}async getDeployedCode(){const t=Xr(this.runner);m(t,"runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"getDeployedCode"});const e=await t.getCode(await this.getAddress());return"0x"===e?null:e}async waitForDeployment(){const t=this.deploymentTransaction();if(t)return await t.wait(),this;if(null!=await this.getDeployedCode())return this;const e=Xr(this.runner);return m(null!=e,"contract runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"waitForDeployment"}),new Promise(((t,n)=>{const r=async()=>{try{if(null!=await this.getDeployedCode())return t(this);e.once("block",r)}catch(t){n(t)}};r()}))}deploymentTransaction(){return ei(this).deployTx}getFunction(t){return"string"!=typeof t&&(t=t.format()),function(t,e){const n=function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];const s=t.interface.getFunction(e,r);return m(s,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e,args:r}}),s},r=async function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];const s=n(...r);let o={};if(s.inputs.length+1===r.length&&(o=await Yr(r.pop()),o.from&&(o.from=await cr(o.from,Kr(t.runner)))),s.inputs.length!==r.length)throw new Error("internal error: fragment inputs doesn't match arguments; should not happen");const a=await async function(t,e,n){const r=$r(t,"resolveName"),i=zr(r)?r:null;return await Promise.all(e.map(((t,e)=>t.walkAsync(n[e],((t,e)=>(e=_.dereference(e,t),"address"===t?cr(e,i):e))))))}(t.runner,s.inputs,r);return Object.assign({},o,await h({to:t.getAddress(),data:t.interface.encodeFunctionData(s,a)}))},i=async function(){const t=await o(...arguments);return 1===t.length?t[0]:t},s=async function(){const e=t.runner;m(Jr(e),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const n=await e.sendTransaction(await r(...arguments)),i=Xr(t.runner);return new Fr(t.interface,i,n)},o=async function(){const e=$r(t.runner,"call");m(Vr(e),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const i=await r(...arguments);let s="0x";try{s=await e.call(i)}catch(e){if(g(e)&&e.data)throw t.interface.makeError(e.data,i);throw e}const o=n(...arguments);return t.interface.decodeFunctionResult(o,s)},a=async function(){return n(...arguments).constant?await i(...arguments):await s(...arguments)};return f(a,{name:t.interface.getFunctionName(e),_contract:t,_key:e,getFragment:n,estimateGas:async function(){const e=$r(t.runner,"estimateGas");return m(Hr(e),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await e.estimateGas(await r(...arguments))},populateTransaction:r,send:s,staticCall:i,staticCallResult:o}),Object.defineProperty(a,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=t.interface.getFunction(e);return m(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e}}),n}}),a}(this,t)}getEvent(t){return"string"!=typeof t&&(t=t.format()),function(t,e){const n=function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];const s=t.interface.getEvent(e,r);return m(s,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e,args:r}}),s},r=function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return new qr(t,n(...r),r)};return f(r,{name:t.interface.getEventName(e),_contract:t,_key:e,getFragment:n}),Object.defineProperty(r,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=t.interface.getEvent(e);return m(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e}}),n}}),r}(this,t)}async queryTransaction(t){throw new Error("@TODO")}async queryFilter(t,e,n){null==e&&(e=0),null==n&&(n="latest");const{addr:r,addrPromise:i}=ei(this),s=r||await i,{fragment:o,topics:a}=await ni(this,t),c={address:s,topics:a,fromBlock:e,toBlock:n},u=Xr(this.runner);return m(u,"contract runner does not have a provider","UNSUPPORTED_OPERATION",{operation:"queryFilter"}),(await u.getLogs(c)).map((t=>{let e=o;if(null==e)try{e=this.interface.getEvent(t.topics[0])}catch(t){}if(e)try{return new _r(t,this.interface,e)}catch(e){return new Ir(t,e)}return new gr(t,u)}))}async on(t,e){const n=await ii(this,"on",t);return n.listeners.push({listener:e,once:!1}),n.start(),this}async once(t,e){const n=await ii(this,"once",t);return n.listeners.push({listener:e,once:!0}),n.start(),this}async emit(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return await oi(this,t,n,null)}async listenerCount(t){if(t){const e=await ri(this,t);return e?e.listeners.length:0}const{subs:e}=ei(this);let n=0;for(const{listeners:t}of e.values())n+=t.length;return n}async listeners(t){if(t){const e=await ri(this,t);return e?e.listeners.map((t=>{let{listener:e}=t;return e})):[]}const{subs:e}=ei(this);let n=[];for(const{listeners:t}of e.values())n=n.concat(t.map((t=>{let{listener:e}=t;return e})));return n}async off(t,e){const n=await ri(this,t);if(!n)return this;if(e){const t=n.listeners.map((t=>{let{listener:e}=t;return e})).indexOf(e);t>=0&&n.listeners.splice(t,1)}return null!=e&&0!==n.listeners.length||(n.stop(),ei(this).subs.delete(n.tag)),this}async removeAllListeners(t){if(t){const e=await ri(this,t);if(!e)return this;e.stop(),ei(this).subs.delete(e.tag)}else{const{subs:t}=ei(this);for(const{tag:e,stop:n}of t.values())n(),t.delete(e)}return this}async addListener(t,e){return await this.on(t,e)}async removeListener(t,e){return await this.off(t,e)}static buildClass(t){return class extends ci{constructor(e){super(e,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null)}}}static from(t,e,n){return null==n&&(n=null),new this(t,e,n)}}class ui extends(function(){return ci}()){}function li(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function hi(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?li(Object(n),!0).forEach((function(e){fi(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):li(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function fi(t,e,n){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var pi=class{constructor(t){var e=this;this.dialogWindowOrigin="",this.isDestroyed=!1,this.appId=void 0,this.mode="production",this.pendingRequest=null,this.getMode=()=>this.mode,this.setMode=t=>{this.mode=t},this.getAppId=()=>this.appId,this.setAppId=t=>{this.appId=t},this.destroy=()=>{this.isDestroyed||(this.isDestroyed=!0,"undefined"!=typeof window&&window.removeEventListener("message",this.handleMessage),this.rejectPendingRequest("DESTROYED"))},this.handleMessage=t=>{if(t.origin!==this.dialogWindowOrigin)return;const e=t.data;if("CLOSE_MODAL"!==e.type){if("PROOFS_RESPONSE"===e.type&&this.pendingRequest){const{resolve:t,reject:n}=this.pendingRequest;this.pendingRequest=null,e.error?n(e.error):t(e.payload)}}else this.rejectPendingRequest("REJECTED")},this.verifyHumanity=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=await e.sendRequest("PROOFS_REQUEST",hi(hi({minPoints:0,context:0},t),{},{mode:e.mode,appId:e.appId}));return console.log("[BringID] verifyHumanity completed successfully"),n},this.getAddressScore=async t=>{if(!t)throw new Error("`address` argument is required to get address score");try{const{score:e,message:n,signature:r}=await o(t);return console.log("[BringID] getAddressScore completed successfully"),{score:e,message:n,signature:r}}catch(t){throw console.error("[BringID] getAddressScore failed:",t),t}},this.verifyProofs=async t=>{let{proofs:e,provider:n,context:r,contract:i}=t;const o={verified:!1,score:{total:0,groups:[]}},a=await async function(t){try{const e="dev"===t?"dev-configs-staging":"configs",n=await s("https://raw.githubusercontent.com/BringID/configs/main/".concat(e,".json")),r={REGISTRY:n.REGISTRY,CHAIN_ID:n.CHAIN_ID};return console.log("[BringID] Registry config fetched successfully:",r),r}catch(t){return console.error("[BringID] Failed to fetch registry config:",t),null}}(this.mode);if(!a)throw new Error("configs cannot be fetched");const l=e.map((t=>({credentialGroupId:t.credential_group_id,appId:t.app_id,semaphoreProof:{merkleTreeDepth:t.semaphore_proof.merkle_tree_depth,merkleTreeRoot:t.semaphore_proof.merkle_tree_root,nullifier:t.semaphore_proof.nullifier,message:t.semaphore_proof.message,scope:t.semaphore_proof.scope,points:t.semaphore_proof.points}}))),h=new ui(a.REGISTRY,c,n);try{const t=await h.apps(this.appId);console.log("[BringID] app data:",t);const s=null!=r?r:0,a=null!=i?i:"0x0000000000000000000000000000000000000000";if(!await h.verifyProofs.staticCall(this.appId,s,l,{from:a}))return o;const c=t.scorer,f=new ui(c,u,n),p=e.map((t=>t.credential_group_id)),d=await f.getScores(p),g=e.map(((t,e)=>({credential_group_id:t.credential_group_id,score:Number(d[e])}))),y=g.reduce(((t,e)=>t+e.score),0);return console.log("[BringID] verifyProofs completed successfully"),{verified:!0,score:{total:y,groups:g}}}catch(t){return console.error("[BringID] verifyProofs failed:",t),o}},this.appId=t.appId,"undefined"!=typeof window&&(window.addEventListener("message",this.handleMessage),this.dialogWindowOrigin=window.location.origin),t.mode&&(this.mode=t.mode)}sendMessageToDialog(t){window.postMessage(t,this.dialogWindowOrigin)}sendRequest(t,e){return this.rejectPendingRequest("REJECTED"),new Promise(((n,r)=>{this.pendingRequest={resolve:n,reject:r},this.sendMessageToDialog({type:t,payload:e})}))}rejectPendingRequest(t){this.pendingRequest&&(this.pendingRequest.reject(t),this.pendingRequest=null)}};return e}()}));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.BringSDK=e():t.BringSDK=e()}(this,(function(){return function(){"use strict";var t={d:function(e,n){for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function i(t,e,n){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}t.r(e),t.d(e,{BringID:function(){return pi}});var s=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"GET",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return fetch(t,{method:e,body:"GET"===e||"OPTIONS"===e?void 0:JSON.stringify(i),headers:r({},n)}).then((async t=>{if(!t.ok){const e=await t.json();throw new Error(e.error)}return t.json()}))},o=t=>s("".concat("https://api.bringid.org","/v1/score/address/").concat(t),"GET",{Authorization:"Bearer ".concat("zpka_52e44068bb9745f2be776b343e96cdab_1a60a93b"),"content-type":"application/json"});const a=[{internalType:"uint256",name:"credentialGroupId",type:"uint256"},{internalType:"uint256",name:"appId",type:"uint256"},{components:[{internalType:"uint256",name:"merkleTreeDepth",type:"uint256"},{internalType:"uint256",name:"merkleTreeRoot",type:"uint256"},{internalType:"uint256",name:"nullifier",type:"uint256"},{internalType:"uint256",name:"message",type:"uint256"},{internalType:"uint256",name:"scope",type:"uint256"},{internalType:"uint256[8]",name:"points",type:"uint256[8]"}],internalType:"struct ISemaphore.SemaphoreProof",name:"semaphoreProof",type:"tuple"}];var c=[{inputs:[{internalType:"uint256",name:"appId",type:"uint256"},{internalType:"uint256",name:"context_",type:"uint256"},{components:a,internalType:"struct ICredentialRegistry.CredentialProof",name:"proof_",type:"tuple"}],name:"verifyProof",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"appId",type:"uint256"},{internalType:"uint256",name:"context_",type:"uint256"},{components:a,internalType:"struct ICredentialRegistry.CredentialProof[]",name:"proofs_",type:"tuple[]"}],name:"verifyProofs",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"appId",type:"uint256"},{internalType:"uint256",name:"context_",type:"uint256"},{components:a,internalType:"struct ICredentialRegistry.CredentialProof[]",name:"proofs_",type:"tuple[]"}],name:"getScore",outputs:[{internalType:"uint256",name:"_score",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"appId",type:"uint256"}],name:"apps",outputs:[{internalType:"enum ICredentialRegistry.AppStatus",name:"status",type:"uint8"},{internalType:"uint256",name:"recoveryTimelock",type:"uint256"},{internalType:"address",name:"admin",type:"address"},{internalType:"address",name:"scorer",type:"address"}],stateMutability:"view",type:"function"}],u=[{inputs:[{internalType:"uint256",name:"",type:"uint256"}],name:"getScore",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],name:"getScores",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"}];function l(t,e,n){const r=e.split("|").map((t=>t.trim()));for(let n=0;n<r.length;n++)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 ".concat(e));throw i.code="INVALID_ARGUMENT",i.argument="value.".concat(n),i.value=t,i}async function h(t){const e=Object.keys(t);return(await Promise.all(e.map((e=>Promise.resolve(t[e]))))).reduce(((t,n,r)=>(t[e[r]]=n,t)),{})}function f(t,e,n){for(let r in e){let i=e[r];const s=n?n[r]:null;s&&l(i,s,r),Object.defineProperty(t,r,{enumerable:!0,value:i,writable:!1})}}function p(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=>p(t,e))).join(", ")+" ]";if(t instanceof Uint8Array){const e="0123456789abcdef";let n="0x";for(let r=0;r<t.length;r++)n+=e[t[r]>>4],n+=e[15&t[r]];return n}if("object"==typeof t&&"function"==typeof t.toJSON)return p(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 n=Object.keys(t);return n.sort(),"{ "+n.map((n=>"".concat(p(n,e),": ").concat(p(t[n],e)))).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function d(t,e){return t&&t.code===e}function g(t){return d(t,"CALL_EXCEPTION")}function y(t,e,n){let r,i=t;{const r=[];if(n){if("message"in n||"code"in n||"name"in n)throw new Error("value will overwrite populated values: ".concat(p(n)));for(const t in n){if("shortMessage"===t)continue;const e=n[t];r.push(t+"="+p(e))}}r.push("code=".concat(e)),r.push("version=".concat("6.16.0")),r.length&&(t+=" ("+r.join(", ")+")")}switch(e){case"INVALID_ARGUMENT":r=new TypeError(t);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":r=new RangeError(t);break;default:r=new Error(t)}return f(r,{code:e}),n&&Object.assign(r,n),null==r.shortMessage&&f(r,{shortMessage:i}),r}function m(t,e,n,r){if(!t)throw y(e,n,r)}function b(t,e,n,r){m(t,e,"INVALID_ARGUMENT",{argument:n,value:r})}function v(t,e,n){null==n&&(n=""),n&&(n=": "+n),m(t>=e,"missing argument"+n,"MISSING_ARGUMENT",{count:t,expectedCount:e}),m(t<=e,"too many arguments"+n,"UNEXPECTED_ARGUMENT",{count:t,expectedCount:e})}const w=["NFD","NFC","NFKD","NFKC"].reduce(((t,e)=>{try{if("test"!=="test".normalize(e))throw new Error("bad");if("NFD"===e){if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken")}t.push(e)}catch(t){}return t}),[]);function E(t,e,n){if(null==n&&(n=""),t!==e){let t=n,e="new";n&&(t+=".",e+=" "+n),m(!1,"private constructor; use ".concat(t,"from* methods"),"UNSUPPORTED_OPERATION",{operation:e})}}function O(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var P=0;function N(t){return"__private_"+P+++"_"+t}const T={};function k(t,e){let n=!1;return e<0&&(n=!0,e*=-1),new _(T,"".concat(n?"":"u","int").concat(e),t,{signed:n,width:e})}function x(t,e){return new _(T,"bytes".concat(e||""),t,{size:e})}const R=Symbol.for("_ethers_typed");var A=N("options");class _{constructor(t,e,n,r){this.type=void 0,this.value=void 0,Object.defineProperty(this,A,{writable:!0,value:void 0}),this._typedSymbol=void 0,null==r&&(r=null),E(T,t,"Typed"),f(this,{_typedSymbol:R,type:e,value:n}),O(this,A)[A]=r,this.format()}format(){if("array"===this.type)throw new Error("");if("dynamicArray"===this.type)throw new Error("");return"tuple"===this.type?"tuple(".concat(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 O(this,A)[A]}get arrayLength(){if("array"!==this.type)throw TypeError("not an array");return!0===O(this,A)[A]?-1:!1===O(this,A)[A]?this.value.length:null}static from(t,e){return new _(T,t,e)}static uint8(t){return k(t,8)}static uint16(t){return k(t,16)}static uint24(t){return k(t,24)}static uint32(t){return k(t,32)}static uint40(t){return k(t,40)}static uint48(t){return k(t,48)}static uint56(t){return k(t,56)}static uint64(t){return k(t,64)}static uint72(t){return k(t,72)}static uint80(t){return k(t,80)}static uint88(t){return k(t,88)}static uint96(t){return k(t,96)}static uint104(t){return k(t,104)}static uint112(t){return k(t,112)}static uint120(t){return k(t,120)}static uint128(t){return k(t,128)}static uint136(t){return k(t,136)}static uint144(t){return k(t,144)}static uint152(t){return k(t,152)}static uint160(t){return k(t,160)}static uint168(t){return k(t,168)}static uint176(t){return k(t,176)}static uint184(t){return k(t,184)}static uint192(t){return k(t,192)}static uint200(t){return k(t,200)}static uint208(t){return k(t,208)}static uint216(t){return k(t,216)}static uint224(t){return k(t,224)}static uint232(t){return k(t,232)}static uint240(t){return k(t,240)}static uint248(t){return k(t,248)}static uint256(t){return k(t,256)}static uint(t){return k(t,256)}static int8(t){return k(t,-8)}static int16(t){return k(t,-16)}static int24(t){return k(t,-24)}static int32(t){return k(t,-32)}static int40(t){return k(t,-40)}static int48(t){return k(t,-48)}static int56(t){return k(t,-56)}static int64(t){return k(t,-64)}static int72(t){return k(t,-72)}static int80(t){return k(t,-80)}static int88(t){return k(t,-88)}static int96(t){return k(t,-96)}static int104(t){return k(t,-104)}static int112(t){return k(t,-112)}static int120(t){return k(t,-120)}static int128(t){return k(t,-128)}static int136(t){return k(t,-136)}static int144(t){return k(t,-144)}static int152(t){return k(t,-152)}static int160(t){return k(t,-160)}static int168(t){return k(t,-168)}static int176(t){return k(t,-176)}static int184(t){return k(t,-184)}static int192(t){return k(t,-192)}static int200(t){return k(t,-200)}static int208(t){return k(t,-208)}static int216(t){return k(t,-216)}static int224(t){return k(t,-224)}static int232(t){return k(t,-232)}static int240(t){return k(t,-240)}static int248(t){return k(t,-248)}static int256(t){return k(t,-256)}static int(t){return k(t,-256)}static bytes1(t){return x(t,1)}static bytes2(t){return x(t,2)}static bytes3(t){return x(t,3)}static bytes4(t){return x(t,4)}static bytes5(t){return x(t,5)}static bytes6(t){return x(t,6)}static bytes7(t){return x(t,7)}static bytes8(t){return x(t,8)}static bytes9(t){return x(t,9)}static bytes10(t){return x(t,10)}static bytes11(t){return x(t,11)}static bytes12(t){return x(t,12)}static bytes13(t){return x(t,13)}static bytes14(t){return x(t,14)}static bytes15(t){return x(t,15)}static bytes16(t){return x(t,16)}static bytes17(t){return x(t,17)}static bytes18(t){return x(t,18)}static bytes19(t){return x(t,19)}static bytes20(t){return x(t,20)}static bytes21(t){return x(t,21)}static bytes22(t){return x(t,22)}static bytes23(t){return x(t,23)}static bytes24(t){return x(t,24)}static bytes25(t){return x(t,25)}static bytes26(t){return x(t,26)}static bytes27(t){return x(t,27)}static bytes28(t){return x(t,28)}static bytes29(t){return x(t,29)}static bytes30(t){return x(t,30)}static bytes31(t){return x(t,31)}static bytes32(t){return x(t,32)}static address(t){return new _(T,"address",t)}static bool(t){return new _(T,"bool",!!t)}static bytes(t){return new _(T,"bytes",t)}static string(t){return new _(T,"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 _(T,"overrides",Object.assign({},t))}static isTyped(t){return t&&"object"==typeof t&&"_typedSymbol"in t&&t._typedSymbol===R}static dereference(t,e){if(_.isTyped(t)){if(t.type!==e)throw new Error("invalid type: expecetd ".concat(e,", got ").concat(t.type));return t.value}return t}}function I(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("Wrong positive integer: ".concat(t))}function j(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];if(n.length>0&&!n.includes(t.length))throw new Error("Expected Uint8Array of length ".concat(n,", not of length=").concat(t.length))}function U(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}const S=BigInt(2**32-1),F=BigInt(32);function C(t){return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?{h:Number(t&S),l:Number(t>>F&S)}:{h:0|Number(t>>F&S),l:0|Number(t&S)}}function L(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:s,l:o}=C(t[i],e);[n[i],r[i]]=[s,o]}return[n,r]}if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");function B(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got ".concat(typeof t));return new Uint8Array((new TextEncoder).encode(t))}(t)),!(t instanceof Uint8Array))throw new Error("expected Uint8Array, got ".concat(typeof t));return t}class D{clone(){return this._cloneInto()}}const[M,G,V]=[[],[],[]],H=BigInt(0),z=BigInt(1),J=BigInt(2),K=BigInt(7),W=BigInt(256),q=BigInt(113);for(let t=0,e=z,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],M.push(2*(5*r+n)),G.push((t+1)*(t+2)/2%64);let i=H;for(let t=0;t<7;t++)e=(e<<z^(e>>K)*q)%W,e&J&&(i^=z<<(z<<BigInt(t))-z);V.push(i)}const[$,X]=L(V,!0),Y=(t,e,n)=>n>32?((t,e,n)=>e<<n-32|t>>>64-n)(t,e,n):((t,e,n)=>t<<n|e>>>32-n)(t,e,n),Z=(t,e,n)=>n>32?((t,e,n)=>t<<n-32|e>>>64-n)(t,e,n):((t,e,n)=>e<<n|t>>>32-n)(t,e,n);class Q extends D{constructor(t,e,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:24;if(super(),this.blockLen=t,this.suffix=e,this.outputLen=n,this.enableXOF=r,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,I(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var s;this.state=new Uint8Array(200),this.state32=(s=this.state,new Uint32Array(s.buffer,s.byteOffset,Math.floor(s.byteLength/4)))}keccak(){!function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:24;const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let e=0;e<10;e++)n[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const r=(e+8)%10,i=(e+2)%10,s=n[i],o=n[i+1],a=Y(s,o,1)^n[r],c=Z(s,o,1)^n[r+1];for(let n=0;n<50;n+=10)t[e+n]^=a,t[e+n+1]^=c}let e=t[2],i=t[3];for(let n=0;n<24;n++){const r=G[n],s=Y(e,i,r),o=Z(e,i,r),a=M[n];e=t[a],i=t[a+1],t[a]=s,t[a+1]=o}for(let e=0;e<50;e+=10){for(let r=0;r<10;r++)n[r]=t[e+r];for(let r=0;r<10;r++)t[e+r]^=~n[(r+2)%10]&n[(r+4)%10]}t[0]^=$[r],t[1]^=X[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){U(this);const{blockLen:e,state:n}=this,r=(t=B(t)).length;for(let i=0;i<r;){const s=Math.min(e-this.pos,r-i);for(let e=0;e<s;e++)n[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:n,blockLen:r}=this;t[n]^=e,128&e&&n===r-1&&this.keccak(),t[r-1]^=128,this.keccak()}writeInto(t){U(this,!1),j(t),this.finish();const e=this.state,{blockLen:n}=this;for(let r=0,i=t.length;r<i;){this.posOut>=n&&this.keccak();const s=Math.min(n-this.posOut,i-r);t.set(e.subarray(this.posOut,this.posOut+s),r),this.posOut+=s,r+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return I(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(function(t,e){j(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least ".concat(n))}(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:n,outputLen:r,rounds:i,enableXOF:s}=this;return t||(t=new Q(e,n,r,s,i)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=i,t.suffix=n,t.outputLen=r,t.enableXOF=s,t.destroyed=this.destroyed,t}}const tt=((t,e,n)=>function(t){const e=e=>t().update(B(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}((()=>new Q(e,t,n))))(1,136,32);function et(t,e,n){if(t instanceof Uint8Array)return n?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 n=2;for(let r=0;r<e.length;r++)e[r]=parseInt(t.substring(n,n+2),16),n+=2;return e}b(!1,"invalid BytesLike value",e||"value",t)}function nt(t,e){return et(t,e,!1)}function rt(t,e){return et(t,e,!0)}function it(t,e){return!("string"!=typeof t||!t.match(/^0x[0-9A-Fa-f]*$/)||"number"==typeof e&&t.length!==2+2*e||!0===e&&t.length%2!=0)}const st="0123456789abcdef";function ot(t){const e=nt(t);let n="0x";for(let t=0;t<e.length;t++){const r=e[t];n+=st[(240&r)>>4]+st[15&r]}return n}function at(t){return"0x"+t.map((t=>ot(t).substring(2))).join("")}function ct(t,e,n){const r=nt(t);return null!=n&&n>r.length&&m(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:n}),ot(r.slice(null==e?0:e,null==n?r.length:n))}function ut(t,e,n){const r=nt(t);m(e>=r.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(r),length:e,offset:e+1});const i=new Uint8Array(e);return i.fill(0),n?i.set(r,e-r.length):i.set(r,0),ot(i)}let lt=!1;const ht=function(t){return tt(t)};let ft=ht;function pt(t){const e=nt(t,"data");return ot(ft(e))}function dt(t,e,n,r,i){if("BAD_PREFIX"===t||"UNEXPECTED_CONTINUE"===t){let t=0;for(let r=e+1;r<n.length&&n[r]>>6==2;r++)t++;return t}return"OVERRUN"===t?n.length-e-1:0}pt._=ht,pt.lock=function(){lt=!0},pt.register=function(t){if(lt)throw new TypeError("keccak256 is locked");ft=t},Object.freeze(pt);const gt=Object.freeze({error:function(t,e,n,r,i){b(!1,"invalid codepoint at offset ".concat(e,"; ").concat(t),"bytes",n)},ignore:dt,replace:function(t,e,n,r,i){return"OVERLONG"===t?(b("number"==typeof i,"invalid bad code point for replacement","badCodepoint",i),r.push(i),0):(r.push(65533),dt(t,e,n))}});function yt(t,e){b("string"==typeof t,"invalid string value","str",t),null!=e&&(function(t){m(w.indexOf(t)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:t}})}(e),t=t.normalize(e));let n=[];for(let e=0;e<t.length;e++){const r=t.charCodeAt(e);if(r<128)n.push(r);else if(r<2048)n.push(r>>6|192),n.push(63&r|128);else if(55296==(64512&r)){e++;const i=t.charCodeAt(e);b(e<t.length&&56320==(64512&i),"invalid surrogate pair","str",t);const s=65536+((1023&r)<<10)+(1023&i);n.push(s>>18|240),n.push(s>>12&63|128),n.push(s>>6&63|128),n.push(63&s|128)}else n.push(r>>12|224),n.push(r>>6&63|128),n.push(63&r|128)}return new Uint8Array(n)}function mt(t,e){return function(t,e){null==e&&(e=gt.error);const n=nt(t,"bytes"),r=[];let i=0;for(;i<n.length;){const t=n[i++];if(!(t>>7)){r.push(t);continue}let s=null,o=null;if(192==(224&t))s=1,o=127;else if(224==(240&t))s=2,o=2047;else{if(240!=(248&t)){i+=e(128==(192&t)?"UNEXPECTED_CONTINUE":"BAD_PREFIX",i-1,n,r);continue}s=3,o=65535}if(i-1+s>=n.length){i+=e("OVERRUN",i-1,n,r);continue}let a=t&(1<<8-s-1)-1;for(let t=0;t<s;t++){let t=n[i];if(128!=(192&t)){i+=e("MISSING_CONTINUE",i,n,r),a=null;break}a=a<<6|63&t,i++}null!==a&&(a>1114111?i+=e("OUT_OF_RANGE",i-1-s,n,r,a):a>=55296&&a<=57343?i+=e("UTF16_SURROGATE",i-1-s,n,r,a):a<=o?i+=e("OVERLONG",i-1-s,n,r,a):r.push(a))}return r}(t,e).map((t=>t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10&1023),56320+(1023&t))))).join("")}function bt(t){return pt(yt(t))}const vt=BigInt(0),wt=BigInt(1),Et=9007199254740991;function Ot(t,e){const n=Nt(t,"value"),r=BigInt(xt(e,"bits"));return n&(wt<<r)-wt}function Pt(t,e){switch(typeof t){case"bigint":return t;case"number":return b(Number.isInteger(t),"underflow",e||"value",t),b(t>=-Et&&t<=Et,"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(n){b(!1,"invalid BigNumberish string: ".concat(n.message),e||"value",t)}}b(!1,"invalid BigNumberish value",e||"value",t)}function Nt(t,e){const n=Pt(t,e);return m(n>=vt,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:t}),n}const Tt="0123456789abcdef";function kt(t){if(t instanceof Uint8Array){let e="0x0";for(const n of t)e+=Tt[n>>4],e+=Tt[15&n];return BigInt(e)}return Pt(t)}function xt(t,e){switch(typeof t){case"bigint":return b(t>=-Et&&t<=Et,"overflow",e||"value",t),Number(t);case"number":return b(Number.isInteger(t),"underflow",e||"value",t),b(t>=-Et&&t<=Et,"overflow",e||"value",t),t;case"string":try{if(""===t)throw new Error("empty string");return xt(BigInt(t),e)}catch(n){b(!1,"invalid numeric string: ".concat(n.message),e||"value",t)}}b(!1,"invalid numeric value",e||"value",t)}function Rt(t,e){const n=Nt(t,"value");let r=n.toString(16);if(null==e)r.length%2&&(r="0"+r);else{const i=xt(e,"width");if(0===i&&n===vt)return"0x";for(m(2*i>=r.length,"value exceeds width (".concat(i," bytes)"),"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:t});r.length<2*i;)r="0"+r}return"0x"+r}function At(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var _t=0;function It(t){return"__private_"+_t+++"_"+t}const jt=32,Ut=new Uint8Array(jt),St=["then"],Ft={},Ct=new WeakMap;function Lt(t){return Ct.get(t)}function Bt(t,e){Ct.set(t,e)}function Dt(t,e){const n=new Error("deferred error during ABI decoding triggered accessing ".concat(t));throw n.error=e,n}function Mt(t,e,n){return t.indexOf(null)>=0?e.map(((t,e)=>t instanceof Vt?Mt(Lt(t),t,n):t)):t.reduce(((t,r,i)=>{let s=e.getValue(r);return r in t||(n&&s instanceof Vt&&(s=Mt(Lt(s),s,n)),t[r]=s),t}),{})}var Gt=It("names");class Vt extends Array{constructor(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];const r=e[0];let i=e[1],s=(e[2]||[]).slice(),o=!0;r!==Ft&&(i=e,s=[],o=!1),super(i.length),Object.defineProperty(this,Gt,{writable:!0,value:void 0}),i.forEach(((t,e)=>{this[e]=t}));const a=s.reduce(((t,e)=>("string"==typeof e&&t.set(e,(t.get(e)||0)+1),t)),new Map);if(Bt(this,Object.freeze(i.map(((t,e)=>{const n=s[e];return null!=n&&1===a.get(n)?n:null})))),At(this,Gt)[Gt]=[],null==At(this,Gt)[Gt]&&At(this,Gt)[Gt],!o)return;Object.freeze(this);const c=new Proxy(this,{get:(t,e,n)=>{if("string"==typeof e){if(e.match(/^[0-9]+$/)){const n=xt(e,"%index");if(n<0||n>=this.length)throw new RangeError("out of result range");const r=t[n];return r instanceof Error&&Dt("index ".concat(n),r),r}if(St.indexOf(e)>=0)return Reflect.get(t,e,n);const r=t[e];if(r instanceof Function)return function(){for(var e=arguments.length,i=new Array(e),s=0;s<e;s++)i[s]=arguments[s];return r.apply(this===n?t:this,i)};if(!(e in t))return t.getValue.apply(this===n?t:this,[e])}return Reflect.get(t,e,n)}});return Bt(c,Lt(this)),c}toArray(t){const e=[];return this.forEach(((n,r)=>{n instanceof Error&&Dt("index ".concat(r),n),t&&n instanceof Vt&&(n=n.toArray(t)),e.push(n)})),e}toObject(t){const e=Lt(this);return e.reduce(((n,r,i)=>(m(null!=r,"value at index ".concat(i," unnamed"),"UNSUPPORTED_OPERATION",{operation:"toObject()"}),Mt(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 n=Lt(this),r=[],i=[];for(let s=t;s<e;s++)r.push(this[s]),i.push(n[s]);return new Vt(Ft,r,i)}filter(t,e){const n=Lt(this),r=[],i=[];for(let s=0;s<this.length;s++){const o=this[s];o instanceof Error&&Dt("index ".concat(s),o),t.call(e,o,s,this)&&(r.push(o),i.push(n[s]))}return new Vt(Ft,r,i)}map(t,e){const n=[];for(let r=0;r<this.length;r++){const i=this[r];i instanceof Error&&Dt("index ".concat(r),i),n.push(t.call(e,i,r,this))}return n}getValue(t){const e=Lt(this).indexOf(t);if(-1===e)return;const n=this[e];return n instanceof Error&&Dt("property ".concat(JSON.stringify(t)),n.error),n}static fromItems(t,e){return new Vt(Ft,t,e)}}function Ht(t){let e=function(t,e){const n=Nt(t,"value");if(n===vt){const t=null!=e?xt(e,"width"):0;return new Uint8Array(t)}let r=n.toString(16);if(r.length%2&&(r="0"+r),null!=e){const n=xt(e,"width");for(;r.length<2*n;)r="00"+r;m(2*n===r.length,"value exceeds width (".concat(n," bytes)"),"NUMERIC_FAULT",{operation:"toBeArray",fault:"overflow",value:t})}const i=new Uint8Array(r.length/2);for(let t=0;t<i.length;t++){const e=2*t;i[t]=parseInt(r.substring(e,e+2),16)}return i}(t);return m(e.length<=jt,"value out-of-bounds","BUFFER_OVERRUN",{buffer:e,length:jt,offset:e.length}),e.length!==jt&&(e=rt(at([Ut.slice(e.length%jt),e]))),e}class zt{constructor(t,e,n,r){this.name=void 0,this.type=void 0,this.localName=void 0,this.dynamic=void 0,f(this,{name:t,type:e,localName:n,dynamic:r},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(t,e){b(!1,t,this.localName,e)}}var Jt=It("data"),Kt=It("dataLength"),Wt=It("writeData");class qt{constructor(){Object.defineProperty(this,Wt,{value:$t}),Object.defineProperty(this,Jt,{writable:!0,value:void 0}),Object.defineProperty(this,Kt,{writable:!0,value:void 0}),At(this,Jt)[Jt]=[],At(this,Kt)[Kt]=0}get data(){return at(At(this,Jt)[Jt])}get length(){return At(this,Kt)[Kt]}appendWriter(t){return At(this,Wt)[Wt](rt(t.data))}writeBytes(t){let e=rt(t);const n=e.length%jt;return n&&(e=rt(at([e,Ut.slice(n)]))),At(this,Wt)[Wt](e)}writeValue(t){return At(this,Wt)[Wt](Ht(t))}writeUpdatableValue(){const t=At(this,Jt)[Jt].length;return At(this,Jt)[Jt].push(Ut),At(this,Kt)[Kt]+=jt,e=>{At(this,Jt)[Jt][t]=Ht(e)}}}function $t(t){return At(this,Jt)[Jt].push(t),At(this,Kt)[Kt]+=t.length,t.length}var Xt=It("data"),Yt=It("offset"),Zt=It("bytesRead"),Qt=It("parent"),te=It("maxInflation"),ee=It("incrementBytesRead"),ne=It("peekBytes");class re{constructor(t,e,n){Object.defineProperty(this,ne,{value:se}),Object.defineProperty(this,ee,{value:ie}),this.allowLoose=void 0,Object.defineProperty(this,Xt,{writable:!0,value:void 0}),Object.defineProperty(this,Yt,{writable:!0,value:void 0}),Object.defineProperty(this,Zt,{writable:!0,value:void 0}),Object.defineProperty(this,Qt,{writable:!0,value:void 0}),Object.defineProperty(this,te,{writable:!0,value:void 0}),f(this,{allowLoose:!!e}),At(this,Xt)[Xt]=rt(t),At(this,Zt)[Zt]=0,At(this,Qt)[Qt]=null,At(this,te)[te]=null!=n?n:1024,At(this,Yt)[Yt]=0}get data(){return ot(At(this,Xt)[Xt])}get dataLength(){return At(this,Xt)[Xt].length}get consumed(){return At(this,Yt)[Yt]}get bytes(){return new Uint8Array(At(this,Xt)[Xt])}subReader(t){const e=new re(At(this,Xt)[Xt].slice(At(this,Yt)[Yt]+t),this.allowLoose,At(this,te)[te]);return At(e,Qt)[Qt]=this,e}readBytes(t,e){let n=At(this,ne)[ne](0,t,!!e);return At(this,ee)[ee](t),At(this,Yt)[Yt]+=n.length,n.slice(0,t)}readValue(){return kt(this.readBytes(jt))}readIndex(){return xt(kt(this.readBytes(jt)))}}function ie(t){if(At(this,Qt)[Qt])return At(At(this,Qt)[Qt],ee)[ee](t);At(this,Zt)[Zt]+=t,m(At(this,te)[te]<1||At(this,Zt)[Zt]<=At(this,te)[te]*this.dataLength,"compressed ABI data exceeds inflation ratio of ".concat(At(this,te)[te]," ( see: https://github.com/ethers-io/ethers.js/issues/4537 )"),"BUFFER_OVERRUN",{buffer:rt(At(this,Xt)[Xt]),offset:At(this,Yt)[Yt],length:t,info:{bytesRead:At(this,Zt)[Zt],dataLength:this.dataLength}})}function se(t,e,n){let r=Math.ceil(e/jt)*jt;return At(this,Yt)[Yt]+r>At(this,Xt)[Xt].length&&(this.allowLoose&&n&&At(this,Yt)[Yt]+e<=At(this,Xt)[Xt].length?r=e:m(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:rt(At(this,Xt)[Xt]),length:At(this,Xt)[Xt].length,offset:At(this,Yt)[Yt]+r})),At(this,Xt)[Xt].slice(At(this,Yt)[Yt],At(this,Yt)[Yt]+r)}const oe=BigInt(0),ae=BigInt(36);function ce(t){const e=(t=t.toLowerCase()).substring(2).split(""),n=new Uint8Array(40);for(let t=0;t<40;t++)n[t]=e[t].charCodeAt(0);const r=nt(pt(n));for(let t=0;t<40;t+=2)r[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&r[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const ue={};for(let t=0;t<10;t++)ue[String(t)]=String(t);for(let t=0;t<26;t++)ue[String.fromCharCode(65+t)]=String(10+t);const le=function(){const t={};for(let e=0;e<36;e++)t["0123456789abcdefghijklmnopqrstuvwxyz"[e]]=BigInt(e);return t}();function he(t){if(b("string"==typeof t,"invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/)){t.startsWith("0x")||(t="0x"+t);const e=ce(t);return b(!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}$/)){b(t.substring(2,4)===function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map((t=>ue[t])).join("");for(;e.length>=15;){let t=e.substring(0,15);e=parseInt(t,10)%97+e.substring(t.length)}let n=String(98-parseInt(e,10)%97);for(;n.length<2;)n="0"+n;return n}(t),"bad icap checksum","address",t);let e=function(t){t=t.toLowerCase();let e=oe;for(let n=0;n<t.length;n++)e=e*ae+le[t[n]];return e}(t.substring(4)).toString(16);for(;e.length<40;)e="0"+e;return ce("0x"+e)}b(!1,"invalid address","address",t)}class fe extends zt{constructor(t){super("address","address",t,!1)}defaultValue(){return"0x0000000000000000000000000000000000000000"}encode(t,e){let n=_.dereference(e,"string");try{n=he(n)}catch(t){return this._throwError(t.message,e)}return t.writeValue(n)}decode(t){return he(Rt(t.readValue(),20))}}class pe extends zt{constructor(t){super(t.name,t.type,"_",t.dynamic),this.coder=void 0,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 de(t,e,n){let r=[];if(Array.isArray(n))r=n;else if(n&&"object"==typeof n){let t={};r=e.map((e=>{const r=e.localName;return m(r,"cannot encode object for signature with missing names","INVALID_ARGUMENT",{argument:"values",info:{coder:e},value:n}),m(!t[r],"cannot encode object for signature with duplicate names","INVALID_ARGUMENT",{argument:"values",info:{coder:e},value:n}),t[r]=!0,n[r]}))}else b(!1,"invalid tuple value","tuple",n);b(e.length===r.length,"types/value length mismatch","tuple",n);let i=new qt,s=new qt,o=[];e.forEach(((t,e)=>{let n=r[e];if(t.dynamic){let e=s.length;t.encode(s,n);let r=i.writeUpdatableValue();o.push((t=>{r(t+e)}))}else t.encode(i,n)})),o.forEach((t=>{t(i.length)}));let a=t.appendWriter(i);return a+=t.appendWriter(s),a}function ge(t,e){let n=[],r=[],i=t.subReader(0);return e.forEach((e=>{let s=null;if(e.dynamic){let n=t.readIndex(),r=i.subReader(n);try{s=e.decode(r)}catch(t){if(d(t,"BUFFER_OVERRUN"))throw t;s=t,s.baseType=e.name,s.name=e.localName,s.type=e.type}}else try{s=e.decode(t)}catch(t){if(d(t,"BUFFER_OVERRUN"))throw t;s=t,s.baseType=e.name,s.name=e.localName,s.type=e.type}if(null==s)throw new Error("investigate");n.push(s),r.push(e.localName||null)})),Vt.fromItems(n,r)}class ye extends zt{constructor(t,e,n){super("array",t.type+"["+(e>=0?e:"")+"]",n,-1===e||t.dynamic),this.coder=void 0,this.length=void 0,f(this,{coder:t,length:e})}defaultValue(){const t=this.coder.defaultValue(),e=[];for(let n=0;n<this.length;n++)e.push(t);return e}encode(t,e){const n=_.dereference(e,"array");Array.isArray(n)||this._throwError("expected array value",n);let r=this.length;-1===r&&(r=n.length,t.writeValue(n.length)),v(n.length,r,"coder array"+(this.localName?" "+this.localName:""));let i=[];for(let t=0;t<n.length;t++)i.push(this.coder);return de(t,i,n)}decode(t){let e=this.length;-1===e&&(e=t.readIndex(),m(e*jt<=t.dataLength,"insufficient data length","BUFFER_OVERRUN",{buffer:t.bytes,offset:e*jt,length:t.dataLength}));let n=[];for(let t=0;t<e;t++)n.push(new pe(this.coder));return ge(t,n)}}class me extends zt{constructor(t){super("bool","bool",t,!1)}defaultValue(){return!1}encode(t,e){const n=_.dereference(e,"bool");return t.writeValue(n?1:0)}decode(t){return!!t.readValue()}}class be extends zt{constructor(t,e){super(t,t,e,!0)}defaultValue(){return"0x"}encode(t,e){e=rt(e);let n=t.writeValue(e.length);return n+=t.writeBytes(e),n}decode(t){return t.readBytes(t.readIndex(),!0)}}class ve extends be{constructor(t){super("bytes",t)}decode(t){return ot(super.decode(t))}}class we extends zt{constructor(t,e){let n="bytes"+String(t);super(n,n,e,!1),this.size=void 0,f(this,{size:t},{size:"number"})}defaultValue(){return"0x0000000000000000000000000000000000000000000000000000000000000000".substring(0,2+2*this.size)}encode(t,e){let n=rt(_.dereference(e,this.type));return n.length!==this.size&&this._throwError("incorrect data length",e),t.writeBytes(n)}decode(t){return ot(t.readBytes(this.size))}}const Ee=new Uint8Array([]);class Oe extends zt{constructor(t){super("null","",t,!1)}defaultValue(){return null}encode(t,e){return null!=e&&this._throwError("not null",e),t.writeBytes(Ee)}decode(t){return t.readBytes(0),null}}const Pe=BigInt(0),Ne=BigInt(1),Te=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");class ke extends zt{constructor(t,e,n){const r=(e?"int":"uint")+8*t;super(r,r,n,!1),this.size=void 0,this.signed=void 0,f(this,{size:t,signed:e},{size:"number",signed:"boolean"})}defaultValue(){return 0}encode(t,e){let n=Pt(_.dereference(e,this.type)),r=Ot(Te,256);if(this.signed){let t=Ot(r,8*this.size-1);(n>t||n<-(t+Ne))&&this._throwError("value out-of-bounds",e),n=function(t){let e=Pt(t,"value");const n=BigInt(xt(256,"width")),r=wt<<n-wt;return e<vt?(e=-e,m(e<=r,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:t}),(~e&(wt<<n)-wt)+wt):(m(e<r,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:t}),e)}(n)}else(n<Pe||n>Ot(r,8*this.size))&&this._throwError("value out-of-bounds",e);return t.writeValue(n)}decode(t){let e=Ot(t.readValue(),8*this.size);return this.signed&&(e=function(t,e){const n=Nt(t,"value"),r=BigInt(xt(e,"width"));return m(n>>r===vt,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:t}),n>>r-wt?-((~n&(wt<<r)-wt)+wt):n}(e,8*this.size)),e}}class xe extends be{constructor(t){super("string",t)}defaultValue(){return""}encode(t,e){return super.encode(t,yt(_.dereference(e,"string")))}decode(t){return mt(super.decode(t))}}class Re extends zt{constructor(t,e){let n=!1;const r=[];t.forEach((t=>{t.dynamic&&(n=!0),r.push(t.type)})),super("tuple","tuple("+r.join(",")+")",e,n),this.coders=void 0,f(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 n=e.localName;return n&&(t[n]||(t[n]=0),t[n]++),t}),{});return this.coders.forEach(((n,r)=>{let i=n.localName;i&&1===e[i]&&("length"===i&&(i="_length"),null==t[i]&&(t[i]=t[r]))})),Object.freeze(t)}encode(t,e){const n=_.dereference(e,"tuple");return de(t,this.coders,n)}decode(t){return ge(t,this.coders)}}var Ae;function _e(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Ie=0;function je(t){return"__private_"+Ie+++"_"+t}function Ue(t){const e=new Set;return t.forEach((t=>e.add(t))),Object.freeze(e)}const Se=Ue("external public payable override".split(" ")),Fe="constant external internal payable private public pure view override",Ce=Ue(Fe.split(" ")),Le="constructor error event fallback function receive struct",Be=Ue(Le.split(" ")),De="calldata memory storage payable indexed",Me=Ue(De.split(" ")),Ge=Ue([Le,De,"tuple returns",Fe].join(" ").split(" ")),Ve={"(":"OPEN_PAREN",")":"CLOSE_PAREN","[":"OPEN_BRACKET","]":"CLOSE_BRACKET",",":"COMMA","@":"AT"},He=new RegExp("^(\\s*)"),ze=new RegExp("^([0-9]+)"),Je=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)"),Ke=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$"),We=new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$");var qe=je("offset"),$e=je("tokens"),Xe=je("subTokenString");class Ye{get offset(){return _e(this,qe)[qe]}get length(){return _e(this,$e)[$e].length-_e(this,qe)[qe]}constructor(t){Object.defineProperty(this,Xe,{value:Ze}),Object.defineProperty(this,qe,{writable:!0,value:void 0}),Object.defineProperty(this,$e,{writable:!0,value:void 0}),_e(this,qe)[qe]=0,_e(this,$e)[$e]=t.slice()}clone(){return new Ye(_e(this,$e)[$e])}reset(){_e(this,qe)[qe]=0}popKeyword(t){const e=this.peek();if("KEYWORD"!==e.type||!t.has(e.text))throw new Error("expected keyword ".concat(e.text));return this.pop().text}popType(t){if(this.peek().type!==t){const e=this.peek();throw new Error("expected ".concat(t,"; got ").concat(e.type," ").concat(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=_e(this,Xe)[Xe](_e(this,qe)[qe]+1,t.match+1);return _e(this,qe)[qe]=t.match+1,e}popParams(){const t=this.peek();if("OPEN_PAREN"!==t.type)throw new Error("bad start");const e=[];for(;_e(this,qe)[qe]<t.match-1;){const t=this.peek().linkNext;e.push(_e(this,Xe)[Xe](_e(this,qe)[qe]+1,t)),_e(this,qe)[qe]=t}return _e(this,qe)[qe]=t.match+1,e}peek(){if(_e(this,qe)[qe]>=_e(this,$e)[$e].length)throw new Error("out-of-bounds");return _e(this,$e)[$e][_e(this,qe)[qe]]}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 _e(this,qe)[qe]++,t}toString(){const t=[];for(let e=_e(this,qe)[qe];e<_e(this,$e)[$e].length;e++){const n=_e(this,$e)[$e][e];t.push("".concat(n.type,":").concat(n.text))}return"<TokenString ".concat(t.join(" "),">")}}function Ze(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return new Ae(_e(this,$e)[$e].slice(t,e).map((e=>Object.freeze(Object.assign({},e,{match:e.match-t,linkBack:e.linkBack-t,linkNext:e.linkNext-t})))))}function Qe(t){const e=[],n=e=>{const n=s<t.length?JSON.stringify(t[s]):"$EOI";throw new Error("invalid token ".concat(n," at ").concat(s,": ").concat(e))};let r=[],i=[],s=0;for(;s<t.length;){let o=t.substring(s),a=o.match(He);a&&(s+=a[1].length,o=t.substring(s));const c={depth:r.length,linkBack:-1,linkNext:-1,match:-1,type:"",text:"",offset:s,value:-1};e.push(c);let u=Ve[o[0]]||"";if(u){if(c.type=u,c.text=o[0],s++,"OPEN_PAREN"===u)r.push(e.length-1),i.push(e.length-1);else if("CLOSE_PAREN"==u)0===r.length&&n("no matching open bracket"),c.match=r.pop(),e[c.match].match=e.length-1,c.depth--,c.linkBack=i.pop(),e[c.linkBack].linkNext=e.length-1;else if("COMMA"===u)c.linkBack=i.pop(),e[c.linkBack].linkNext=e.length-1,i.push(e.length-1);else if("OPEN_BRACKET"===u)c.type="BRACKET";else if("CLOSE_BRACKET"===u){let t=e.pop().text;if(e.length>0&&"NUMBER"===e[e.length-1].type){const n=e.pop().text;t=n+t,e[e.length-1].value=xt(n)}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=o.match(Je),a){if(c.text=a[1],s+=c.text.length,Ge.has(c.text)){c.type="KEYWORD";continue}if(c.text.match(We)){c.type="TYPE";continue}c.type="ID"}else{if(a=o.match(ze),!a)throw new Error("unexpected token ".concat(JSON.stringify(o[0])," at position ").concat(s));c.text=a[1],c.type="NUMBER",s+=c.text.length}}return new Ye(e.map((t=>Object.freeze(t))))}function tn(t,e){let n=[];for(const r in e.keys())t.has(r)&&n.push(r);if(n.length>1)throw new Error("conflicting types: ".concat(n.join(", ")))}function en(t,e){if(e.peekKeyword(Be)){const n=e.pop().text;if(n!==t)throw new Error("expected ".concat(t,", got ").concat(n))}return e.popType("ID")}function nn(t,e){const n=new Set;for(;;){const r=t.peekType("KEYWORD");if(null==r||e&&!e.has(r))break;if(t.pop(),n.has(r))throw new Error("duplicate keywords: ".concat(JSON.stringify(r)));n.add(r)}return Object.freeze(n)}function rn(t){let e=nn(t,Ce);return tn(e,Ue("constant payable nonpayable".split(" "))),tn(e,Ue("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 sn(t,e){return t.popParams().map((t=>wn.from(t,e)))}function on(t){if(t.peekType("AT")){if(t.pop(),t.peekType("NUMBER"))return Pt(t.pop().text);throw new Error("invalid gas")}return null}function an(t){if(t.length)throw new Error("unexpected tokens at offset ".concat(t.offset,": ").concat(t.toString()))}Ae=Ye;const cn=new RegExp(/^(.*)\[([0-9]*)\]$/);function un(t){const e=t.match(We);if(b(e,"invalid type","type",t),"uint"===t)return"uint256";if("int"===t)return"int256";if(e[2]){const n=parseInt(e[2]);b(0!==n&&n<=32,"invalid bytes length","type",t)}else if(e[3]){const n=parseInt(e[3]);b(0!==n&&n<=256&&n%8==0,"invalid numeric width","type",t)}return t}const ln={},hn=Symbol.for("_ethers_internal"),fn="_ParamTypeInternal",pn="_ErrorInternal",dn="_EventInternal",gn="_ConstructorInternal",yn="_FallbackInternal",mn="_FunctionInternal",bn="_StructInternal";var vn=je("walkAsync");class wn{constructor(t,e,n,r,i,s,o,a){if(Object.defineProperty(this,vn,{value:En}),this.name=void 0,this.type=void 0,this.baseType=void 0,this.indexed=void 0,this.components=void 0,this.arrayLength=void 0,this.arrayChildren=void 0,E(t,ln,"ParamType"),Object.defineProperty(this,hn,{value:fn}),s&&(s=Object.freeze(s.slice())),"array"===r){if(null==o||null==a)throw new Error("")}else if(null!=o||null!=a)throw new Error("");if("tuple"===r){if(null==s)throw new Error("")}else if(null!=s)throw new Error("");f(this,{name:e,type:n,baseType:r,indexed:i,components:s,arrayLength:o,arrayChildren:a})}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+="[".concat(this.arrayLength<0?"":String(this.arrayLength),"]"),JSON.stringify(t)}const n={type:"tuple"===this.baseType?"tuple":this.type,name:e};return"boolean"==typeof this.indexed&&(n.indexed=this.indexed),this.isTuple()&&(n.components=this.components.map((e=>JSON.parse(e.format(t))))),JSON.stringify(n)}let e="";return this.isArray()?(e+=this.arrayChildren.format(t),e+="[".concat(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 n=this;return t.map((t=>n.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 n=this;return t.map(((t,r)=>n.components[r].walk(t,e)))}return e(this.type,t)}async walkAsync(t,e){const n=[],r=[t];return _e(this,vn)[vn](n,t,e,(t=>{r[0]=t})),n.length&&await Promise.all(n),r[0]}static from(t,e){if(wn.isParamType(t))return t;if("string"==typeof t)try{return wn.from(Qe(t),e)}catch(e){b(!1,"invalid param type","obj",t)}else if(t instanceof Ye){let n="",r="",i=null;nn(t,Ue(["tuple"])).has("tuple")||t.peekType("OPEN_PAREN")?(r="tuple",i=t.popParams().map((t=>wn.from(t))),n="tuple(".concat(i.map((t=>t.format())).join(","),")")):(n=un(t.popType("TYPE")),r=n);let s=null,o=null;for(;t.length&&t.peekType("BRACKET");){const e=t.pop();s=new wn(ln,"",n,r,null,i,o,s),o=e.value,n+=e.text,r="array",i=null}let a=null;if(nn(t,Me).has("indexed")){if(!e)throw new Error("");a=!0}const c=t.peekType("ID")?t.pop().text:"";if(t.length)throw new Error("leftover tokens");return new wn(ln,c,n,r,a,i,o,s)}const n=t.name;b(!n||"string"==typeof n&&n.match(Ke),"invalid name","obj.name",n);let r=t.indexed;null!=r&&(b(e,"parameter cannot be indexed","obj.indexed",t.indexed),r=!!r);let i=t.type,s=i.match(cn);if(s){const e=parseInt(s[2]||"-1"),o=wn.from({type:s[1],components:t.components});return new wn(ln,n||"",i,"array",r,null,e,o)}if("tuple"===i||i.startsWith("tuple(")||i.startsWith("(")){const e=null!=t.components?t.components.map((t=>wn.from(t))):null;return new wn(ln,n||"",i,"tuple",r,e,null,null)}return i=un(t.type),new wn(ln,n||"",i,i,r,null,null,null)}static isParamType(t){return t&&t[hn]===fn}}function En(t,e,n,r){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,s=e.slice();return s.forEach(((e,r)=>{_e(i,vn)[vn](t,e,n,(t=>{s[r]=t}))})),void r(s)}if(this.isTuple()){const i=this.components;let s;if(Array.isArray(e))s=e.slice();else{if(null==e||"object"!=typeof e)throw new Error("invalid tuple value");s=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 ".concat(t.name));return e[t.name]}))}if(s.length!==this.components.length)throw new Error("array is wrong length");return s.forEach(((e,r)=>{_e(i[r],vn)[vn](t,e,n,(t=>{s[r]=t}))})),void r(s)}const i=n(this.type,e);i.then?t.push(async function(){r(await i)}()):r(i)}class On{constructor(t,e,n){this.type=void 0,this.inputs=void 0,E(t,ln,"Fragment"),f(this,{type:e,inputs:n=Object.freeze(n.slice())})}static from(t){if("string"==typeof t){try{On.from(JSON.parse(t))}catch(t){}return On.from(Qe(t))}if(t instanceof Ye)switch(t.peekKeyword(Be)){case"constructor":return xn.from(t);case"error":return Tn.from(t);case"event":return kn.from(t);case"fallback":case"receive":return Rn.from(t);case"function":return An.from(t);case"struct":return _n.from(t)}else if("object"==typeof t){switch(t.type){case"constructor":return xn.from(t);case"error":return Tn.from(t);case"event":return kn.from(t);case"fallback":case"receive":return Rn.from(t);case"function":return An.from(t);case"struct":return _n.from(t)}m(!1,"unsupported type: ".concat(t.type),"UNSUPPORTED_OPERATION",{operation:"Fragment.from"})}b(!1,"unsupported frgament object","obj",t)}static isConstructor(t){return xn.isFragment(t)}static isError(t){return Tn.isFragment(t)}static isEvent(t){return kn.isFragment(t)}static isFunction(t){return An.isFragment(t)}static isStruct(t){return _n.isFragment(t)}}class Pn extends On{constructor(t,e,n,r){super(t,e,r),this.name=void 0,b("string"==typeof n&&n.match(Ke),"invalid identifier","name",n),r=Object.freeze(r.slice()),f(this,{name:n})}}function Nn(t,e){return"("+e.map((e=>e.format(t))).join("full"===t?", ":",")+")"}class Tn extends Pn{constructor(t,e,n){super(t,"error",e,n),Object.defineProperty(this,hn,{value:pn})}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+Nn(t,this.inputs)),e.join(" ")}static from(t){if(Tn.isFragment(t))return t;if("string"==typeof t)return Tn.from(Qe(t));if(t instanceof Ye){const e=en("error",t),n=sn(t);return an(t),new Tn(ln,e,n)}return new Tn(ln,t.name,t.inputs?t.inputs.map(wn.from):[])}static isFragment(t){return t&&t[hn]===pn}}class kn extends Pn{constructor(t,e,n,r){super(t,"event",e,n),this.anonymous=void 0,Object.defineProperty(this,hn,{value:dn}),f(this,{anonymous:r})}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+Nn(t,this.inputs)),"sighash"!==t&&this.anonymous&&e.push("anonymous"),e.join(" ")}static getTopicHash(t,e){return e=(e||[]).map((t=>wn.from(t))),new kn(ln,t,e,!1).topicHash}static from(t){if(kn.isFragment(t))return t;if("string"==typeof t)try{return kn.from(Qe(t))}catch(e){b(!1,"invalid event fragment","obj",t)}else if(t instanceof Ye){const e=en("event",t),n=sn(t,!0),r=!!nn(t,Ue(["anonymous"])).has("anonymous");return an(t),new kn(ln,e,n,r)}return new kn(ln,t.name,t.inputs?t.inputs.map((t=>wn.from(t,!0))):[],!!t.anonymous)}static isFragment(t){return t&&t[hn]===dn}}class xn extends On{constructor(t,e,n,r,i){super(t,e,n),this.payable=void 0,this.gas=void 0,Object.defineProperty(this,hn,{value:gn}),f(this,{payable:r,gas:i})}format(t){if(m(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".concat(Nn(t,this.inputs))];return this.payable&&e.push("payable"),null!=this.gas&&e.push("@".concat(this.gas.toString())),e.join(" ")}static from(t){if(xn.isFragment(t))return t;if("string"==typeof t)try{return xn.from(Qe(t))}catch(e){b(!1,"invalid constuctor fragment","obj",t)}else if(t instanceof Ye){nn(t,Ue(["constructor"]));const e=sn(t),n=!!nn(t,Se).has("payable"),r=on(t);return an(t),new xn(ln,"constructor",e,n,r)}return new xn(ln,"constructor",t.inputs?t.inputs.map(wn.from):[],!!t.payable,null!=t.gas?t.gas:null)}static isFragment(t){return t&&t[hn]===gn}}class Rn extends On{constructor(t,e,n){super(t,"fallback",e),this.payable=void 0,Object.defineProperty(this,hn,{value:yn}),f(this,{payable:n})}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"".concat(e,"()").concat(this.payable?" payable":"")}static from(t){if(Rn.isFragment(t))return t;if("string"==typeof t)try{return Rn.from(Qe(t))}catch(e){b(!1,"invalid fallback fragment","obj",t)}else if(t instanceof Ye){const e=t.toString();if(b(t.peekKeyword(Ue(["fallback","receive"])),"type must be fallback or receive","obj",e),"receive"===t.popKeyword(Ue(["fallback","receive"]))){const e=sn(t);return b(0===e.length,"receive cannot have arguments","obj.inputs",e),nn(t,Ue(["payable"])),an(t),new Rn(ln,[],!0)}let n=sn(t);n.length?b(1===n.length&&"bytes"===n[0].type,"invalid fallback inputs","obj.inputs",n.map((t=>t.format("minimal"))).join(", ")):n=[wn.from("bytes")];const r=rn(t);if(b("nonpayable"===r||"payable"===r,"fallback cannot be constants","obj.stateMutability",r),nn(t,Ue(["returns"])).has("returns")){const e=sn(t);b(1===e.length&&"bytes"===e[0].type,"invalid fallback outputs","obj.outputs",e.map((t=>t.format("minimal"))).join(", "))}return an(t),new Rn(ln,n,"payable"===r)}if("receive"===t.type)return new Rn(ln,[],!0);if("fallback"===t.type){const e=[wn.from("bytes")],n="payable"===t.stateMutability;return new Rn(ln,e,n)}b(!1,"invalid fallback description","obj",t)}static isFragment(t){return t&&t[hn]===yn}}class An extends Pn{constructor(t,e,n,r,i,s){super(t,"function",e,r),this.constant=void 0,this.outputs=void 0,this.stateMutability=void 0,this.payable=void 0,this.gas=void 0,Object.defineProperty(this,hn,{value:mn}),f(this,{constant:"view"===n||"pure"===n,gas:s,outputs:i=Object.freeze(i.slice()),payable:"payable"===n,stateMutability:n})}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+Nn(t,this.inputs)),"sighash"!==t&&("nonpayable"!==this.stateMutability&&e.push(this.stateMutability),this.outputs&&this.outputs.length&&(e.push("returns"),e.push(Nn(t,this.outputs))),null!=this.gas&&e.push("@".concat(this.gas.toString()))),e.join(" ")}static getSelector(t,e){return e=(e||[]).map((t=>wn.from(t))),new An(ln,t,"view",e,[],null).selector}static from(t){if(An.isFragment(t))return t;if("string"==typeof t)try{return An.from(Qe(t))}catch(e){b(!1,"invalid function fragment","obj",t)}else if(t instanceof Ye){const e=en("function",t),n=sn(t),r=rn(t);let i=[];nn(t,Ue(["returns"])).has("returns")&&(i=sn(t));const s=on(t);return an(t),new An(ln,e,r,n,i,s)}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 An(ln,t.name,e,t.inputs?t.inputs.map(wn.from):[],t.outputs?t.outputs.map(wn.from):[],null!=t.gas?t.gas:null)}static isFragment(t){return t&&t[hn]===mn}}class _n extends Pn{constructor(t,e,n){super(t,"struct",e,n),Object.defineProperty(this,hn,{value:bn})}format(){throw new Error("@TODO")}static from(t){if("string"==typeof t)try{return _n.from(Qe(t))}catch(e){b(!1,"invalid struct fragment","obj",t)}else if(t instanceof Ye){const e=en("struct",t),n=sn(t);return an(t),new _n(ln,e,n)}return new _n(ln,t.name,t.inputs?t.inputs.map(wn.from):[])}static isFragment(t){return t&&t[hn]===bn}}function In(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var jn=0;function Un(t){return"__private_"+jn+++"_"+t}const Sn=new Map;Sn.set(0,"GENERIC_PANIC"),Sn.set(1,"ASSERT_FALSE"),Sn.set(17,"OVERFLOW"),Sn.set(18,"DIVIDE_BY_ZERO"),Sn.set(33,"ENUM_RANGE_ERROR"),Sn.set(34,"BAD_STORAGE_DATA"),Sn.set(49,"STACK_UNDERFLOW"),Sn.set(50,"ARRAY_RANGE_ERROR"),Sn.set(65,"OUT_OF_MEMORY"),Sn.set(81,"UNINITIALIZED_FUNCTION_CALL");const Fn=new RegExp(/^bytes([0-9]*)$/),Cn=new RegExp(/^(u?int)([0-9]*)$/);let Ln=null,Bn=1024;var Dn=Un("getCoder");class Mn{constructor(){Object.defineProperty(this,Dn,{value:Gn})}getDefaultValue(t){const e=t.map((t=>In(this,Dn)[Dn](wn.from(t))));return new Re(e,"_").defaultValue()}encode(t,e){v(e.length,t.length,"types/values length mismatch");const n=t.map((t=>In(this,Dn)[Dn](wn.from(t)))),r=new Re(n,"_"),i=new qt;return r.encode(i,e),i.data}decode(t,e,n){const r=t.map((t=>In(this,Dn)[Dn](wn.from(t))));return new Re(r,"_").decode(new re(e,n,Bn))}static _setDefaultMaxInflation(t){b("number"==typeof t&&Number.isInteger(t),"invalid defaultMaxInflation factor","value",t),Bn=t}static defaultAbiCoder(){return null==Ln&&(Ln=new Mn),Ln}static getBuiltinCallException(t,e,n){return function(t,e,n,r){let i="missing revert data",s=null,o=null;if(n){i="execution reverted";const t=nt(n);if(n=ot(n),0===t.length)i+=" (no data present; likely require(false) occurred",s="require(false)";else if(t.length%32!=4)i+=" (could not decode reason; invalid data length)";else if("0x08c379a0"===ot(t.slice(0,4)))try{s=r.decode(["string"],t.slice(4))[0],o={signature:"Error(string)",name:"Error",args:[s]},i+=": ".concat(JSON.stringify(s))}catch(t){i+=" (could not decode reason; invalid string data)"}else if("0x4e487b71"===ot(t.slice(0,4)))try{const e=Number(r.decode(["uint256"],t.slice(4))[0]);o={signature:"Panic(uint256)",name:"Panic",args:[e]},s="Panic due to ".concat(Sn.get(e)||"UNKNOWN","(").concat(e,")"),i+=": ".concat(s)}catch(t){i+=" (could not decode panic code)"}else i+=" (unknown custom error)"}const a={to:e.to?he(e.to):null,data:e.data||"0x"};return e.from&&(a.from=he(e.from)),y(i,"CALL_EXCEPTION",{action:t,data:n,reason:s,transaction:a,invocation:null,revert:o})}(t,e,n,Mn.defaultAbiCoder())}}function Gn(t){if(t.isArray())return new ye(In(this,Dn)[Dn](t.arrayChildren),t.arrayLength,t.name);if(t.isTuple())return new Re(t.components.map((t=>In(this,Dn)[Dn](t))),t.name);switch(t.baseType){case"address":return new fe(t.name);case"bool":return new me(t.name);case"string":return new xe(t.name);case"bytes":return new ve(t.name);case"":return new Oe(t.name)}let e=t.type.match(Cn);if(e){let n=parseInt(e[2]||"256");return b(0!==n&&n<=256&&n%8==0,"invalid "+e[1]+" bit length","param",t),new ke(n/8,"int"===e[1],t.name)}if(e=t.type.match(Fn),e){let n=parseInt(e[1]);return b(0!==n&&n<=32,"invalid bytes length","param",t),new we(n,t.name)}b(!1,"invalid type","type",t.type)}function Vn(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Hn=0;function zn(t){return"__private_"+Hn+++"_"+t}class Jn{constructor(t,e,n){this.fragment=void 0,this.name=void 0,this.signature=void 0,this.topic=void 0,this.args=void 0;const r=t.name,i=t.format();f(this,{fragment:t,name:r,signature:i,topic:e,args:n})}}class Kn{constructor(t,e,n,r){this.fragment=void 0,this.name=void 0,this.args=void 0,this.signature=void 0,this.selector=void 0,this.value=void 0;const i=t.name,s=t.format();f(this,{fragment:t,name:i,args:n,signature:s,selector:e,value:r})}}class Wn{constructor(t,e,n){this.fragment=void 0,this.name=void 0,this.args=void 0,this.signature=void 0,this.selector=void 0;const r=t.name,i=t.format();f(this,{fragment:t,name:r,args:n,signature:i,selector:e})}}class qn{static isIndexed(t){return!(!t||!t._isIndexed)}constructor(t){this.hash=void 0,this._isIndexed=void 0,f(this,{hash:t,_isIndexed:!0})}}const $n={0:"generic panic",1:"assert(false)",17:"arithmetic overflow",18:"division or modulo by zero",33:"enum overflow",34:"invalid encoded storage byte array accessed",49:"out-of-bounds array access; popping on an empty array",50:"out-of-bounds access of an array or bytesN",65:"out of memory",81:"uninitialized function"},Xn={"0x08c379a0":{signature:"Error(string)",name:"Error",inputs:["string"],reason:t=>"reverted with reason string ".concat(JSON.stringify(t))},"0x4e487b71":{signature:"Panic(uint256)",name:"Panic",inputs:["uint256"],reason:t=>{let e="unknown panic code";return t>=0&&t<=255&&$n[t.toString()]&&(e=$n[t.toString()]),"reverted with panic code 0x".concat(t.toString(16)," (").concat(e,")")}}};var Yn=zn("errors"),Zn=zn("events"),Qn=zn("functions"),tr=zn("abiCoder"),er=zn("getFunction"),nr=zn("getEvent");class rr{constructor(t){Object.defineProperty(this,nr,{value:sr}),Object.defineProperty(this,er,{value:ir}),this.fragments=void 0,this.deploy=void 0,this.fallback=void 0,this.receive=void 0,Object.defineProperty(this,Yn,{writable:!0,value:void 0}),Object.defineProperty(this,Zn,{writable:!0,value:void 0}),Object.defineProperty(this,Qn,{writable:!0,value:void 0}),Object.defineProperty(this,tr,{writable:!0,value:void 0});let e=[];e="string"==typeof t?JSON.parse(t):t,Vn(this,Qn)[Qn]=new Map,Vn(this,Yn)[Yn]=new Map,Vn(this,Zn)[Zn]=new Map;const n=[];for(const t of e)try{n.push(On.from(t))}catch(e){console.log("[Warning] Invalid Fragment ".concat(JSON.stringify(t),":"),e.message)}f(this,{fragments:Object.freeze(n)});let r=null,i=!1;Vn(this,tr)[tr]=this.getAbiCoder(),this.fragments.forEach(((t,e)=>{let n;switch(t.type){case"constructor":return this.deploy?void console.log("duplicate definition - constructor"):void f(this,{deploy:t});case"fallback":return void(0===t.inputs.length?i=!0:(b(!r||t.payable!==r.payable,"conflicting fallback fragments","fragments[".concat(e,"]"),t),r=t,i=r.payable));case"function":n=Vn(this,Qn)[Qn];break;case"event":n=Vn(this,Zn)[Zn];break;case"error":n=Vn(this,Yn)[Yn];break;default:return}const s=t.format();n.has(s)||n.set(s,t)})),this.deploy||f(this,{deploy:xn.from("constructor()")}),f(this,{fallback:r,receive:i})}format(t){const e=t?"minimal":"full";return this.fragments.map((t=>t.format(e)))}formatJson(){const t=this.fragments.map((t=>t.format("json")));return JSON.stringify(t.map((t=>JSON.parse(t))))}getAbiCoder(){return Mn.defaultAbiCoder()}getFunctionName(t){const e=Vn(this,er)[er](t,null,!1);return b(e,"no matching function","key",t),e.name}hasFunction(t){return!!Vn(this,er)[er](t,null,!1)}getFunction(t,e){return Vn(this,er)[er](t,e||null,!0)}forEachFunction(t){const e=Array.from(Vn(this,Qn)[Qn].keys());e.sort(((t,e)=>t.localeCompare(e)));for(let n=0;n<e.length;n++){const r=e[n];t(Vn(this,Qn)[Qn].get(r),n)}}getEventName(t){const e=Vn(this,nr)[nr](t,null,!1);return b(e,"no matching event","key",t),e.name}hasEvent(t){return!!Vn(this,nr)[nr](t,null,!1)}getEvent(t,e){return Vn(this,nr)[nr](t,e||null,!0)}forEachEvent(t){const e=Array.from(Vn(this,Zn)[Zn].keys());e.sort(((t,e)=>t.localeCompare(e)));for(let n=0;n<e.length;n++){const r=e[n];t(Vn(this,Zn)[Zn].get(r),n)}}getError(t,e){if(it(t)){const e=t.toLowerCase();if(Xn[e])return Tn.from(Xn[e].signature);for(const t of Vn(this,Yn)[Yn].values())if(e===t.selector)return t;return null}if(-1===t.indexOf("(")){const e=[];for(const[n,r]of Vn(this,Yn)[Yn])n.split("(")[0]===t&&e.push(r);if(0===e.length)return"Error"===t?Tn.from("error Error(string)"):"Panic"===t?Tn.from("error Panic(uint256)"):null;if(e.length>1){const n=e.map((t=>JSON.stringify(t.format()))).join(", ");b(!1,"ambiguous error description (i.e. ".concat(n,")"),"name",t)}return e[0]}if("Error(string)"===(t=Tn.from(t).format()))return Tn.from("error Error(string)");if("Panic(uint256)"===t)return Tn.from("error Panic(uint256)");return Vn(this,Yn)[Yn].get(t)||null}forEachError(t){const e=Array.from(Vn(this,Yn)[Yn].keys());e.sort(((t,e)=>t.localeCompare(e)));for(let n=0;n<e.length;n++){const r=e[n];t(Vn(this,Yn)[Yn].get(r),n)}}_decodeParams(t,e){return Vn(this,tr)[tr].decode(t,e)}_encodeParams(t,e){return Vn(this,tr)[tr].encode(t,e)}encodeDeploy(t){return this._encodeParams(this.deploy.inputs,t||[])}decodeErrorResult(t,e){if("string"==typeof t){const e=this.getError(t);b(e,"unknown error","fragment",t),t=e}return b(ct(e,0,4)===t.selector,"data signature does not match error ".concat(t.name,"."),"data",e),this._decodeParams(t.inputs,ct(e,4))}encodeErrorResult(t,e){if("string"==typeof t){const e=this.getError(t);b(e,"unknown error","fragment",t),t=e}return at([t.selector,this._encodeParams(t.inputs,e||[])])}decodeFunctionData(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}return b(ct(e,0,4)===t.selector,"data signature does not match function ".concat(t.name,"."),"data",e),this._decodeParams(t.inputs,ct(e,4))}encodeFunctionData(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}return at([t.selector,this._encodeParams(t.inputs,e||[])])}decodeFunctionResult(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}let n="invalid length for result data";const r=rt(e);if(r.length%32==0)try{return Vn(this,tr)[tr].decode(t.outputs,r)}catch(t){n="could not decode result data"}m(!1,n,"BAD_DATA",{value:ot(r),info:{method:t.name,signature:t.format()}})}makeError(t,e){const n=nt(t,"data"),r=Mn.getBuiltinCallException("call",e,n);if(r.message.startsWith("execution reverted (unknown custom error)")){const t=ot(n.slice(0,4)),e=this.getError(t);if(e)try{const t=Vn(this,tr)[tr].decode(e.inputs,n.slice(4));r.revert={name:e.name,signature:e.format(),args:t},r.reason=r.revert.signature,r.message="execution reverted: ".concat(r.reason)}catch(t){r.message="execution reverted (coult not decode custom error)"}}const i=this.parseTransaction(e);return i&&(r.invocation={method:i.name,signature:i.signature,args:i.args}),r}encodeFunctionResult(t,e){if("string"==typeof t){const e=this.getFunction(t);b(e,"unknown function","fragment",t),t=e}return ot(Vn(this,tr)[tr].encode(t.outputs,e||[]))}encodeFilterTopics(t,e){if("string"==typeof t){const e=this.getEvent(t);b(e,"unknown event","eventFragment",t),t=e}m(e.length<=t.inputs.length,"too many arguments for ".concat(t.format()),"UNEXPECTED_ARGUMENT",{count:e.length,expectedCount:t.inputs.length});const n=[];t.anonymous||n.push(t.topicHash);const r=(t,e)=>"string"===t.type?bt(e):"bytes"===t.type?pt(ot(e)):("bool"===t.type&&"boolean"==typeof e?e=e?"0x01":"0x00":t.type.match(/^u?int/)?e=Rt(e):t.type.match(/^bytes/)?e=ut(e,32,!1):"address"===t.type&&Vn(this,tr)[tr].encode(["address"],[e]),ut(ot(e),32,!0));for(e.forEach(((e,i)=>{const s=t.inputs[i];s.indexed?null==e?n.push(null):"array"===s.baseType||"tuple"===s.baseType?b(!1,"filtering with tuples or arrays not supported","contract."+s.name,e):Array.isArray(e)?n.push(e.map((t=>r(s,t)))):n.push(r(s,e)):b(null==e,"cannot filter non-indexed parameters; must be null","contract."+s.name,e)}));n.length&&null===n[n.length-1];)n.pop();return n}encodeEventLog(t,e){if("string"==typeof t){const e=this.getEvent(t);b(e,"unknown event","eventFragment",t),t=e}const n=[],r=[],i=[];return t.anonymous||n.push(t.topicHash),b(e.length===t.inputs.length,"event arguments/values mismatch","values",e),t.inputs.forEach(((t,s)=>{const o=e[s];if(t.indexed)if("string"===t.type)n.push(bt(o));else if("bytes"===t.type)n.push(pt(o));else{if("tuple"===t.baseType||"array"===t.baseType)throw new Error("not implemented");n.push(Vn(this,tr)[tr].encode([t.type],[o]))}else r.push(t),i.push(o)})),{data:Vn(this,tr)[tr].encode(r,i),topics:n}}decodeEventLog(t,e,n){if("string"==typeof t){const e=this.getEvent(t);b(e,"unknown event","eventFragment",t),t=e}if(null!=n&&!t.anonymous){const e=t.topicHash;b(it(n[0],32)&&n[0].toLowerCase()===e,"fragment/topic mismatch","topics[0]",n[0]),n=n.slice(1)}const r=[],i=[],s=[];t.inputs.forEach(((t,e)=>{t.indexed?"string"===t.type||"bytes"===t.type||"tuple"===t.baseType||"array"===t.baseType?(r.push(wn.from({type:"bytes32",name:t.name})),s.push(!0)):(r.push(t),s.push(!1)):(i.push(t),s.push(!1))}));const o=null!=n?Vn(this,tr)[tr].decode(r,at(n)):null,a=Vn(this,tr)[tr].decode(i,e,!0),c=[],u=[];let l=0,h=0;return t.inputs.forEach(((t,e)=>{let n=null;if(t.indexed)if(null==o)n=new qn(null);else if(s[e])n=new qn(o[h++]);else try{n=o[h++]}catch(t){n=t}else try{n=a[l++]}catch(t){n=t}c.push(n),u.push(t.name||null)})),Vt.fromItems(c,u)}parseTransaction(t){const e=nt(t.data,"tx.data"),n=Pt(null!=t.value?t.value:0,"tx.value"),r=this.getFunction(ot(e.slice(0,4)));if(!r)return null;const i=Vn(this,tr)[tr].decode(r.inputs,e.slice(4));return new Kn(r,r.selector,i,n)}parseCallResult(t){throw new Error("@TODO")}parseLog(t){const e=this.getEvent(t.topics[0]);return!e||e.anonymous?null:new Jn(e,e.topicHash,this.decodeEventLog(e,t.data,t.topics))}parseError(t){const e=ot(t),n=this.getError(ct(e,0,4));if(!n)return null;const r=Vn(this,tr)[tr].decode(n.inputs,ct(e,4));return new Wn(n,n.selector,r)}static from(t){return t instanceof rr?t:"string"==typeof t?new rr(JSON.parse(t)):"function"==typeof t.formatJson?new rr(t.formatJson()):"function"==typeof t.format?new rr(t.format("json")):new rr(t)}}function ir(t,e,n){if(it(t)){const e=t.toLowerCase();for(const t of Vn(this,Qn)[Qn].values())if(e===t.selector)return t;return null}if(-1===t.indexOf("(")){const r=[];for(const[e,n]of Vn(this,Qn)[Qn])e.split("(")[0]===t&&r.push(n);if(e){const t=e.length>0?e[e.length-1]:null;let n=e.length,i=!0;_.isTyped(t)&&"overrides"===t.type&&(i=!1,n--);for(let t=r.length-1;t>=0;t--){const e=r[t].inputs.length;e===n||i&&e===n-1||r.splice(t,1)}for(let t=r.length-1;t>=0;t--){const n=r[t].inputs;for(let i=0;i<e.length;i++)if(_.isTyped(e[i])){if(i>=n.length){if("overrides"===e[i].type)continue;r.splice(t,1);break}if(e[i].type!==n[i].baseType){r.splice(t,1);break}}}}if(1===r.length&&e&&e.length!==r[0].inputs.length){const t=e[e.length-1];(null==t||Array.isArray(t)||"object"!=typeof t)&&r.splice(0,1)}if(0===r.length)return null;if(r.length>1&&n){const e=r.map((t=>JSON.stringify(t.format()))).join(", ");b(!1,"ambiguous function description (i.e. matches ".concat(e,")"),"key",t)}return r[0]}return Vn(this,Qn)[Qn].get(An.from(t).format())||null}function sr(t,e,n){if(it(t)){const e=t.toLowerCase();for(const t of Vn(this,Zn)[Zn].values())if(e===t.topicHash)return t;return null}if(-1===t.indexOf("(")){const r=[];for(const[e,n]of Vn(this,Zn)[Zn])e.split("(")[0]===t&&r.push(n);if(e){for(let t=r.length-1;t>=0;t--)r[t].inputs.length<e.length&&r.splice(t,1);for(let t=r.length-1;t>=0;t--){const n=r[t].inputs;for(let i=0;i<e.length;i++)if(_.isTyped(e[i])&&e[i].type!==n[i].baseType){r.splice(t,1);break}}}if(0===r.length)return null;if(r.length>1&&n){const e=r.map((t=>JSON.stringify(t.format()))).join(", ");b(!1,"ambiguous event description (i.e. matches ".concat(e,")"),"key",t)}return r[0]}return Vn(this,Zn)[Zn].get(kn.from(t).format())||null}function or(t){return t&&"function"==typeof t.getAddress}async function ar(t,e){const n=await e;return null!=n&&"0x0000000000000000000000000000000000000000"!==n||(m("string"!=typeof t,"unconfigured name","UNCONFIGURED_NAME",{value:t}),b(!1,"invalid AddressLike value; did not resolve to a value address","target",t)),he(n)}function cr(t,e){return"string"==typeof t?t.match(/^0x[0-9a-f]{40}$/i)?he(t):(m(null!=e,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),ar(t,e.resolveName(t))):or(t)?ar(t,t.getAddress()):t&&"function"==typeof t.then?ar(t,t):void b(!1,"unsupported addressable value","target",t)}function ur(t,e){return{address:he(t),storageKeys:e.map(((t,e)=>(b(it(t,32),"invalid slot","storageKeys[".concat(e,"]"),t),t.toLowerCase())))}}function lr(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var hr=0;function fr(t){return"__private_"+hr+++"_"+t}const pr=BigInt(0);function dr(t){return null==t?null:t.toString()}Symbol.iterator;class gr{constructor(t,e){this.provider=void 0,this.transactionHash=void 0,this.blockHash=void 0,this.blockNumber=void 0,this.removed=void 0,this.address=void 0,this.data=void 0,this.topics=void 0,this.index=void 0,this.transactionIndex=void 0,this.provider=e;const n=Object.freeze(t.topics.slice());f(this,{transactionHash:t.transactionHash,blockHash:t.blockHash,blockNumber:t.blockNumber,removed:t.removed,address:t.address,data:t.data,topics:n,index:t.index,transactionIndex:t.transactionIndex})}toJSON(){const{address:t,blockHash:e,blockNumber:n,data:r,index:i,removed:s,topics:o,transactionHash:a,transactionIndex:c}=this;return{_type:"log",address:t,blockHash:e,blockNumber:n,data:r,index:i,removed:s,topics:o,transactionHash:a,transactionIndex:c}}async getBlock(){const t=await this.provider.getBlock(this.blockHash);return m(!!t,"failed to find transaction","UNKNOWN_ERROR",{}),t}async getTransaction(){const t=await this.provider.getTransaction(this.transactionHash);return m(!!t,"failed to find transaction","UNKNOWN_ERROR",{}),t}async getTransactionReceipt(){const t=await this.provider.getTransactionReceipt(this.transactionHash);return m(!!t,"failed to find transaction receipt","UNKNOWN_ERROR",{}),t}removedEvent(){return{orphan:"drop-log",log:{transactionHash:(t=this).transactionHash,blockHash:t.blockHash,blockNumber:t.blockNumber,address:t.address,data:t.data,topics:Object.freeze(t.topics.slice()),index:t.index}};var t}}var yr=fr("logs");class mr{constructor(t,e){this.provider=void 0,this.to=void 0,this.from=void 0,this.contractAddress=void 0,this.hash=void 0,this.index=void 0,this.blockHash=void 0,this.blockNumber=void 0,this.logsBloom=void 0,this.gasUsed=void 0,this.blobGasUsed=void 0,this.cumulativeGasUsed=void 0,this.gasPrice=void 0,this.blobGasPrice=void 0,this.type=void 0,this.status=void 0,this.root=void 0,Object.defineProperty(this,yr,{writable:!0,value:void 0}),lr(this,yr)[yr]=Object.freeze(t.logs.map((t=>new gr(t,e))));let n=pr;null!=t.effectiveGasPrice?n=t.effectiveGasPrice:null!=t.gasPrice&&(n=t.gasPrice),f(this,{provider:e,to:t.to,from:t.from,contractAddress:t.contractAddress,hash:t.hash,index:t.index,blockHash:t.blockHash,blockNumber:t.blockNumber,logsBloom:t.logsBloom,gasUsed:t.gasUsed,cumulativeGasUsed:t.cumulativeGasUsed,blobGasUsed:t.blobGasUsed,gasPrice:n,blobGasPrice:t.blobGasPrice,type:t.type,status:t.status,root:t.root})}get logs(){return lr(this,yr)[yr]}toJSON(){const{to:t,from:e,contractAddress:n,hash:r,index:i,blockHash:s,blockNumber:o,logsBloom:a,logs:c,status:u,root:l}=this;return{_type:"TransactionReceipt",blockHash:s,blockNumber:o,contractAddress:n,cumulativeGasUsed:dr(this.cumulativeGasUsed),from:e,gasPrice:dr(this.gasPrice),blobGasUsed:dr(this.blobGasUsed),blobGasPrice:dr(this.blobGasPrice),gasUsed:dr(this.gasUsed),hash:r,index:i,logs:c,logsBloom:a,root:l,status:u,to:t}}get length(){return this.logs.length}[Symbol.iterator](){let t=0;return{next:()=>t<this.length?{value:this.logs[t++],done:!1}:{value:void 0,done:!0}}}get fee(){return this.gasUsed*this.gasPrice}async getBlock(){const t=await this.provider.getBlock(this.blockHash);if(null==t)throw new Error("TODO");return t}async getTransaction(){const t=await this.provider.getTransaction(this.hash);if(null==t)throw new Error("TODO");return t}async getResult(){return await this.provider.getTransactionResult(this.hash)}async confirmations(){return await this.provider.getBlockNumber()-this.blockNumber+1}removedEvent(){return Er(this)}reorderedEvent(t){return m(!t||t.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),wr(this,t)}}var br=fr("startBlock");class vr{constructor(t,e){this.provider=void 0,this.blockNumber=void 0,this.blockHash=void 0,this.index=void 0,this.hash=void 0,this.type=void 0,this.to=void 0,this.from=void 0,this.nonce=void 0,this.gasLimit=void 0,this.gasPrice=void 0,this.maxPriorityFeePerGas=void 0,this.maxFeePerGas=void 0,this.maxFeePerBlobGas=void 0,this.data=void 0,this.value=void 0,this.chainId=void 0,this.signature=void 0,this.accessList=void 0,this.blobVersionedHashes=void 0,this.authorizationList=void 0,Object.defineProperty(this,br,{writable:!0,value:void 0}),this.provider=e,this.blockNumber=null!=t.blockNumber?t.blockNumber:null,this.blockHash=null!=t.blockHash?t.blockHash:null,this.hash=t.hash,this.index=t.index,this.type=t.type,this.from=t.from,this.to=t.to||null,this.gasLimit=t.gasLimit,this.nonce=t.nonce,this.data=t.data,this.value=t.value,this.gasPrice=t.gasPrice,this.maxPriorityFeePerGas=null!=t.maxPriorityFeePerGas?t.maxPriorityFeePerGas:null,this.maxFeePerGas=null!=t.maxFeePerGas?t.maxFeePerGas:null,this.maxFeePerBlobGas=null!=t.maxFeePerBlobGas?t.maxFeePerBlobGas:null,this.chainId=t.chainId,this.signature=t.signature,this.accessList=null!=t.accessList?t.accessList:null,this.blobVersionedHashes=null!=t.blobVersionedHashes?t.blobVersionedHashes:null,this.authorizationList=null!=t.authorizationList?t.authorizationList:null,lr(this,br)[br]=-1}toJSON(){const{blockNumber:t,blockHash:e,index:n,hash:r,type:i,to:s,from:o,nonce:a,data:c,signature:u,accessList:l,blobVersionedHashes:h}=this;return{_type:"TransactionResponse",accessList:l,blockNumber:t,blockHash:e,blobVersionedHashes:h,chainId:dr(this.chainId),data:c,from:o,gasLimit:dr(this.gasLimit),gasPrice:dr(this.gasPrice),hash:r,maxFeePerGas:dr(this.maxFeePerGas),maxPriorityFeePerGas:dr(this.maxPriorityFeePerGas),maxFeePerBlobGas:dr(this.maxFeePerBlobGas),nonce:a,signature:u,to:s,index:n,type:i,value:dr(this.value)}}async getBlock(){let t=this.blockNumber;if(null==t){const e=await this.getTransaction();e&&(t=e.blockNumber)}if(null==t)return null;const e=this.provider.getBlock(t);if(null==e)throw new Error("TODO");return e}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(null==this.blockNumber){const{tx:t,blockNumber:e}=await h({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});return null==t||null==t.blockNumber?0:e-t.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(t,e){const n=null==t?1:t,r=null==e?0:e;let i=lr(this,br)[br],s=-1,o=-1===i;const a=async()=>{if(o)return null;const{blockNumber:t,nonce:e}=await h({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(e<this.nonce)return void(i=t);if(o)return null;const r=await this.getTransaction();if(!r||null==r.blockNumber)for(-1===s&&(s=i-3,s<lr(this,br)[br]&&(s=lr(this,br)[br]));s<=t;){if(o)return null;const e=await this.provider.getBlock(s,!0);if(null==e)return;for(const t of e)if(t===this.hash)return;for(let r=0;r<e.length;r++){const s=await e.getTransaction(r);if(s.from===this.from&&s.nonce===this.nonce){if(o)return null;const e=await this.provider.getTransactionReceipt(s.hash);if(null==e)return;if(t-e.blockNumber+1<n)return;let r="replaced";s.data===this.data&&s.to===this.to&&s.value===this.value?r="repriced":"0x"===s.data&&s.from===s.to&&s.value===pr&&(r="cancelled"),m(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:"replaced"===r||"cancelled"===r,reason:r,replacement:s.replaceableTransaction(i),hash:s.hash,receipt:e})}}s++}},c=t=>{if(null==t||0!==t.status)return t;m(!1,"transaction execution reverted","CALL_EXCEPTION",{action:"sendTransaction",data:null,reason:null,invocation:null,revert:null,transaction:{to:t.to,from:t.from,data:""},receipt:t})},u=await this.provider.getTransactionReceipt(this.hash);if(0===n)return c(u);if(u){if(1===n||await u.confirmations()>=n)return c(u)}else if(await a(),0===n)return null;const l=new Promise(((t,e)=>{const s=[],u=()=>{s.forEach((t=>t()))};if(s.push((()=>{o=!0})),r>0){const t=setTimeout((()=>{u(),e(y("wait for transaction timeout","TIMEOUT"))}),r);s.push((()=>{clearTimeout(t)}))}const l=async r=>{if(await r.confirmations()>=n){u();try{t(c(r))}catch(t){e(t)}}};if(s.push((()=>{this.provider.off(this.hash,l)})),this.provider.on(this.hash,l),i>=0){const t=async()=>{try{await a()}catch(t){if(d(t,"TRANSACTION_REPLACED"))return u(),void e(t)}o||this.provider.once("block",t)};s.push((()=>{this.provider.off("block",t)})),this.provider.once("block",t)}}));return await l}isMined(){return null!=this.blockHash}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}removedEvent(){return m(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),Er(this)}reorderedEvent(t){return m(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),m(!t||t.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),wr(this,t)}replaceableTransaction(t){b(Number.isInteger(t)&&t>=0,"invalid startBlock","startBlock",t);const e=new vr(this,this.provider);return lr(e,br)[br]=t,e}}function wr(t,e){return{orphan:"reorder-transaction",tx:t,other:e}}function Er(t){return{orphan:"drop-transaction",tx:t}}function Or(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Pr=0;function Nr(t){return"__private_"+Pr+++"_"+t}var Tr=Nr("listener");class kr{constructor(t,e,n){this.filter=void 0,this.emitter=void 0,Object.defineProperty(this,Tr,{writable:!0,value:void 0}),Or(this,Tr)[Tr]=e,f(this,{emitter:t,filter:n})}async removeListener(){null!=Or(this,Tr)[Tr]&&await this.emitter.off(this.filter,Or(this,Tr)[Tr])}}function xr(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Rr=0;function Ar(t){return"__private_"+Rr+++"_"+t}class _r extends gr{constructor(t,e,n){super(t,t.provider),this.interface=void 0,this.fragment=void 0,this.args=void 0,f(this,{args:e.decodeEventLog(n,t.data,t.topics),fragment:n,interface:e})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}class Ir extends gr{constructor(t,e){super(t,t.provider),this.error=void 0,f(this,{error:e})}}var jr=Ar("iface");class Ur extends mr{constructor(t,e,n){super(n,e),Object.defineProperty(this,jr,{writable:!0,value:void 0}),xr(this,jr)[jr]=t}get logs(){return super.logs.map((t=>{const e=t.topics.length?xr(this,jr)[jr].getEvent(t.topics[0]):null;if(e)try{return new _r(t,xr(this,jr)[jr],e)}catch(e){return new Ir(t,e)}return t}))}}var Sr=Ar("iface");class Fr extends vr{constructor(t,e,n){super(n,e),Object.defineProperty(this,Sr,{writable:!0,value:void 0}),xr(this,Sr)[Sr]=t}async wait(t,e){const n=await super.wait(t,e);return null==n?null:new Ur(xr(this,Sr)[Sr],this.provider,n)}}class Cr extends kr{constructor(t,e,n,r){super(t,e,n),this.log=void 0,f(this,{log:r})}async getBlock(){return await this.log.getBlock()}async getTransaction(){return await this.log.getTransaction()}async getTransactionReceipt(){return await this.log.getTransactionReceipt()}}class Lr extends Cr{constructor(t,e,n,r,i){super(t,e,n,new _r(i,t.interface,r)),f(this,{args:t.interface.decodeEventLog(r,this.log.data,this.log.topics),fragment:r})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}function Br(t,e){if(!{}.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var Dr=0;function Mr(t){return"__private_"+Dr+++"_"+t}const Gr=BigInt(0);function Vr(t){return t&&"function"==typeof t.call}function Hr(t){return t&&"function"==typeof t.estimateGas}function zr(t){return t&&"function"==typeof t.resolveName}function Jr(t){return t&&"function"==typeof t.sendTransaction}function Kr(t){if(null!=t){if(zr(t))return t;if(t.provider)return t.provider}}var Wr=Mr("filter");class qr{constructor(t,e,n){if(Object.defineProperty(this,Wr,{writable:!0,value:void 0}),this.fragment=void 0,f(this,{fragment:e}),e.inputs.length<n.length)throw new Error("too many arguments");const r=$r(t.runner,"resolveName"),i=zr(r)?r:null;Br(this,Wr)[Wr]=async function(){const r=await Promise.all(e.inputs.map(((t,e)=>null==n[e]?null:t.walkAsync(n[e],((t,e)=>"address"===t?Array.isArray(e)?Promise.all(e.map((t=>cr(t,i)))):cr(e,i):e)))));return t.interface.encodeFilterTopics(e,r)}()}getTopicFilter(){return Br(this,Wr)[Wr]}}function $r(t,e){return null==t?null:"function"==typeof t[e]?t:t.provider&&"function"==typeof t.provider[e]?t.provider:null}function Xr(t){return null==t?null:t.provider||null}async function Yr(t,e){const n=_.dereference(t,"overrides");b("object"==typeof n,"invalid overrides parameter","overrides",t);const r=function(t){const e={};t.to&&(e.to=t.to),t.from&&(e.from=t.from),t.data&&(e.data=ot(t.data));const n="chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);for(const r of n)r in t&&null!=t[r]&&(e[r]=Pt(t[r],"request.".concat(r)));const r="type,nonce".split(/,/);for(const n of r)n in t&&null!=t[n]&&(e[n]=xt(t[n],"request.".concat(n)));return t.accessList&&(e.accessList=function(t){if(Array.isArray(t))return t.map(((e,n)=>Array.isArray(e)?(b(2===e.length,"invalid slot set","value[".concat(n,"]"),e),ur(e[0],e[1])):(b(null!=e&&"object"==typeof e,"invalid address-slot set","value",t),ur(e.address,e.storageKeys))));b(null!=t&&"object"==typeof t,"invalid access list","value",t);const e=Object.keys(t).map((e=>{const n=t[e].reduce(((t,e)=>(t[e]=!0,t)),{});return ur(e,Object.keys(n).sort())}));return e.sort(((t,e)=>t.address.localeCompare(e.address))),e}(t.accessList)),t.authorizationList&&(e.authorizationList=t.authorizationList.slice()),"blockTag"in t&&(e.blockTag=t.blockTag),"enableCcipRead"in t&&(e.enableCcipRead=!!t.enableCcipRead),"customData"in t&&(e.customData=t.customData),"blobVersionedHashes"in t&&t.blobVersionedHashes&&(e.blobVersionedHashes=t.blobVersionedHashes.slice()),"kzg"in t&&(e.kzg=t.kzg),"blobWrapperVersion"in t&&(e.blobWrapperVersion=t.blobWrapperVersion),"blobs"in t&&t.blobs&&(e.blobs=t.blobs.map((t=>{return it(e=t,!0)||e instanceof Uint8Array?ot(t):Object.assign({},t);var e}))),e}(n);return b(null==r.to||(e||[]).indexOf("to")>=0,"cannot override to","overrides.to",r.to),b(null==r.data||(e||[]).indexOf("data")>=0,"cannot override data","overrides.data",r.data),r.from&&(r.from=r.from),r}function Zr(t){const e=async function(e){const n=await Yr(e,["data"]);n.to=await t.getAddress(),n.from&&(n.from=await cr(n.from,Kr(t.runner)));const r=t.interface,i=Pt(n.value||Gr,"overrides.value")===Gr,s="0x"===(n.data||"0x");return!r.fallback||r.fallback.payable||!r.receive||s||i||b(!1,"cannot send data to receive or send value to non-payable fallback","overrides",e),b(r.fallback||s,"cannot send data to receive-only contract","overrides.data",n.data),b(r.receive||r.fallback&&r.fallback.payable||i,"cannot send value to non-payable fallback","overrides.value",n.value),b(r.fallback||s,"cannot send data to receive-only contract","overrides.data",n.data),n},n=async function(n){const r=t.runner;m(Jr(r),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const i=await r.sendTransaction(await e(n)),s=Xr(t.runner);return new Fr(t.interface,s,i)},r=async t=>await n(t);return f(r,{_contract:t,estimateGas:async function(n){const r=$r(t.runner,"estimateGas");return m(Hr(r),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await r.estimateGas(await e(n))},populateTransaction:e,send:n,staticCall:async function(n){const r=$r(t.runner,"call");m(Vr(r),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const i=await e(n);try{return await r.call(i)}catch(e){if(g(e)&&e.data)throw t.interface.makeError(e.data,i);throw e}}}),r}const Qr=Symbol.for("_ethersInternal_contract"),ti=new WeakMap;function ei(t){return ti.get(t[Qr])}async function ni(t,e){let n,r=null;if(Array.isArray(e)){const r=function(e){if(it(e,32))return e;const n=t.interface.getEvent(e);return b(n,"unknown fragment","name",e),n.topicHash};n=e.map((t=>null==t?null:Array.isArray(t)?t.map(r):r(t)))}else"*"===e?n=[null]:"string"==typeof e?it(e,32)?n=[e]:(r=t.interface.getEvent(e),b(r,"unknown fragment","event",e),n=[r.topicHash]):(i=e)&&"object"==typeof i&&"getTopicFilter"in i&&"function"==typeof i.getTopicFilter&&i.fragment?n=await e.getTopicFilter():"fragment"in e?(r=e.fragment,n=[r.topicHash]):b(!1,"unknown event name","event",e);var i;return n=n.map((t=>{if(null==t)return null;if(Array.isArray(t)){const e=Array.from(new Set(t.map((t=>t.toLowerCase()))).values());return 1===e.length?e[0]:(e.sort(),e)}return t.toLowerCase()})),{fragment:r,tag:n.map((t=>null==t?"null":Array.isArray(t)?t.join("|"):t)).join("&"),topics:n}}async function ri(t,e){const{subs:n}=ei(t);return n.get((await ni(t,e)).tag)||null}async function ii(t,e,n){const r=Xr(t.runner);m(r,"contract runner does not support subscribing","UNSUPPORTED_OPERATION",{operation:e});const{fragment:i,tag:s,topics:o}=await ni(t,n),{addr:a,subs:c}=ei(t);let u=c.get(s);if(!u){const e={address:a||t,topics:o},l=e=>{let r=i;if(null==r)try{r=t.interface.getEvent(e.topics[0])}catch(t){}if(r){const s=r,o=i?t.interface.decodeEventLog(i,e.data,e.topics):[];oi(t,n,o,(r=>new Lr(t,r,n,s,e)))}else oi(t,n,[],(r=>new Cr(t,r,n,e)))};let h=[];u={tag:s,listeners:[],start:()=>{h.length||h.push(r.on(e,l))},stop:async()=>{if(0==h.length)return;let t=h;h=[],await Promise.all(t),r.off(e,l)}},c.set(s,u)}return u}let si=Promise.resolve();async function oi(t,e,n,r){try{await si}catch(t){}const i=async function(t,e,n,r){await si;const i=await ri(t,e);if(!i)return!1;const s=i.listeners.length;return i.listeners=i.listeners.filter((e=>{let{listener:i,once:s}=e;const o=Array.from(n);r&&o.push(r(s?null:i));try{i.call(t,...o)}catch(t){}return!s})),0===i.listeners.length&&(i.stop(),ei(t).subs.delete(i.tag)),s>0}(t,e,n,r);return si=i,await i}const ai=["then"];class ci{constructor(t,e,n,r){this.target=void 0,this.interface=void 0,this.runner=void 0,this.filters=void 0,this[Qr]=void 0,this.fallback=void 0,b("string"==typeof t||or(t),"invalid value for Contract target","target",t),null==n&&(n=null);const i=rr.from(e);let s;f(this,{target:t,runner:n,interface:i}),Object.defineProperty(this,Qr,{value:{}});let o=null,a=null;if(r){const t=Xr(n);a=new Fr(this.interface,t,r)}let c=new Map;if("string"==typeof t)if(it(t))o=t,s=Promise.resolve(t);else{const e=$r(n,"resolveName");if(!zr(e))throw y("contract runner does not support name resolution","UNSUPPORTED_OPERATION",{operation:"resolveName"});s=e.resolveName(t).then((e=>{if(null==e)throw y("an ENS name used for a contract target must be correctly configured","UNCONFIGURED_NAME",{value:t});return ei(this).addr=e,e}))}else s=t.getAddress().then((t=>{if(null==t)throw new Error("TODO");return ei(this).addr=t,t}));var u;u={addrPromise:s,addr:o,deployTx:a,subs:c},ti.set(this[Qr],u);const l=new Proxy({},{get:(t,e,n)=>{if("symbol"==typeof e||ai.indexOf(e)>=0)return Reflect.get(t,e,n);try{return this.getEvent(e)}catch(t){if(!d(t,"INVALID_ARGUMENT")||"key"!==t.argument)throw t}},has:(t,e)=>ai.indexOf(e)>=0?Reflect.has(t,e):Reflect.has(t,e)||this.interface.hasEvent(String(e))});return f(this,{filters:l}),f(this,{fallback:i.receive||i.fallback?Zr(this):null}),new Proxy(this,{get:(t,e,n)=>{if("symbol"==typeof e||e in t||ai.indexOf(e)>=0)return Reflect.get(t,e,n);try{return t.getFunction(e)}catch(t){if(!d(t,"INVALID_ARGUMENT")||"key"!==t.argument)throw t}},has:(t,e)=>"symbol"==typeof e||e in t||ai.indexOf(e)>=0?Reflect.has(t,e):t.interface.hasFunction(e)})}connect(t){return new ci(this.target,this.interface,t)}attach(t){return new ci(t,this.interface,this.runner)}async getAddress(){return await ei(this).addrPromise}async getDeployedCode(){const t=Xr(this.runner);m(t,"runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"getDeployedCode"});const e=await t.getCode(await this.getAddress());return"0x"===e?null:e}async waitForDeployment(){const t=this.deploymentTransaction();if(t)return await t.wait(),this;if(null!=await this.getDeployedCode())return this;const e=Xr(this.runner);return m(null!=e,"contract runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"waitForDeployment"}),new Promise(((t,n)=>{const r=async()=>{try{if(null!=await this.getDeployedCode())return t(this);e.once("block",r)}catch(t){n(t)}};r()}))}deploymentTransaction(){return ei(this).deployTx}getFunction(t){return"string"!=typeof t&&(t=t.format()),function(t,e){const n=function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];const s=t.interface.getFunction(e,r);return m(s,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e,args:r}}),s},r=async function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];const s=n(...r);let o={};if(s.inputs.length+1===r.length&&(o=await Yr(r.pop()),o.from&&(o.from=await cr(o.from,Kr(t.runner)))),s.inputs.length!==r.length)throw new Error("internal error: fragment inputs doesn't match arguments; should not happen");const a=await async function(t,e,n){const r=$r(t,"resolveName"),i=zr(r)?r:null;return await Promise.all(e.map(((t,e)=>t.walkAsync(n[e],((t,e)=>(e=_.dereference(e,t),"address"===t?cr(e,i):e))))))}(t.runner,s.inputs,r);return Object.assign({},o,await h({to:t.getAddress(),data:t.interface.encodeFunctionData(s,a)}))},i=async function(){const t=await o(...arguments);return 1===t.length?t[0]:t},s=async function(){const e=t.runner;m(Jr(e),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const n=await e.sendTransaction(await r(...arguments)),i=Xr(t.runner);return new Fr(t.interface,i,n)},o=async function(){const e=$r(t.runner,"call");m(Vr(e),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const i=await r(...arguments);let s="0x";try{s=await e.call(i)}catch(e){if(g(e)&&e.data)throw t.interface.makeError(e.data,i);throw e}const o=n(...arguments);return t.interface.decodeFunctionResult(o,s)},a=async function(){return n(...arguments).constant?await i(...arguments):await s(...arguments)};return f(a,{name:t.interface.getFunctionName(e),_contract:t,_key:e,getFragment:n,estimateGas:async function(){const e=$r(t.runner,"estimateGas");return m(Hr(e),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await e.estimateGas(await r(...arguments))},populateTransaction:r,send:s,staticCall:i,staticCallResult:o}),Object.defineProperty(a,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=t.interface.getFunction(e);return m(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e}}),n}}),a}(this,t)}getEvent(t){return"string"!=typeof t&&(t=t.format()),function(t,e){const n=function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];const s=t.interface.getEvent(e,r);return m(s,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e,args:r}}),s},r=function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return new qr(t,n(...r),r)};return f(r,{name:t.interface.getEventName(e),_contract:t,_key:e,getFragment:n}),Object.defineProperty(r,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=t.interface.getEvent(e);return m(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:e}}),n}}),r}(this,t)}async queryTransaction(t){throw new Error("@TODO")}async queryFilter(t,e,n){null==e&&(e=0),null==n&&(n="latest");const{addr:r,addrPromise:i}=ei(this),s=r||await i,{fragment:o,topics:a}=await ni(this,t),c={address:s,topics:a,fromBlock:e,toBlock:n},u=Xr(this.runner);return m(u,"contract runner does not have a provider","UNSUPPORTED_OPERATION",{operation:"queryFilter"}),(await u.getLogs(c)).map((t=>{let e=o;if(null==e)try{e=this.interface.getEvent(t.topics[0])}catch(t){}if(e)try{return new _r(t,this.interface,e)}catch(e){return new Ir(t,e)}return new gr(t,u)}))}async on(t,e){const n=await ii(this,"on",t);return n.listeners.push({listener:e,once:!1}),n.start(),this}async once(t,e){const n=await ii(this,"once",t);return n.listeners.push({listener:e,once:!0}),n.start(),this}async emit(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return await oi(this,t,n,null)}async listenerCount(t){if(t){const e=await ri(this,t);return e?e.listeners.length:0}const{subs:e}=ei(this);let n=0;for(const{listeners:t}of e.values())n+=t.length;return n}async listeners(t){if(t){const e=await ri(this,t);return e?e.listeners.map((t=>{let{listener:e}=t;return e})):[]}const{subs:e}=ei(this);let n=[];for(const{listeners:t}of e.values())n=n.concat(t.map((t=>{let{listener:e}=t;return e})));return n}async off(t,e){const n=await ri(this,t);if(!n)return this;if(e){const t=n.listeners.map((t=>{let{listener:e}=t;return e})).indexOf(e);t>=0&&n.listeners.splice(t,1)}return null!=e&&0!==n.listeners.length||(n.stop(),ei(this).subs.delete(n.tag)),this}async removeAllListeners(t){if(t){const e=await ri(this,t);if(!e)return this;e.stop(),ei(this).subs.delete(e.tag)}else{const{subs:t}=ei(this);for(const{tag:e,stop:n}of t.values())n(),t.delete(e)}return this}async addListener(t,e){return await this.on(t,e)}async removeListener(t,e){return await this.off(t,e)}static buildClass(t){return class extends ci{constructor(e){super(e,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null)}}}static from(t,e,n){return null==n&&(n=null),new this(t,e,n)}}class ui extends(function(){return ci}()){}function li(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function hi(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?li(Object(n),!0).forEach((function(e){fi(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):li(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function fi(t,e,n){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var pi=class{constructor(t){var e=this;this.dialogWindowOrigin="",this.isDestroyed=!1,this.appId=void 0,this.mode="production",this.pendingRequest=null,this.getMode=()=>this.mode,this.setMode=t=>{this.mode=t},this.getAppId=()=>this.appId,this.setAppId=t=>{this.appId=t},this.destroy=()=>{this.isDestroyed||(this.isDestroyed=!0,"undefined"!=typeof window&&window.removeEventListener("message",this.handleMessage),this.rejectPendingRequest("DESTROYED"))},this.handleMessage=t=>{if(t.origin!==this.dialogWindowOrigin)return;const e=t.data;if("CLOSE_MODAL"!==e.type){if("PROOFS_RESPONSE"===e.type&&this.pendingRequest){const{resolve:t,reject:n}=this.pendingRequest;this.pendingRequest=null,e.error?n(e.error):t(e.payload)}}else this.rejectPendingRequest("REJECTED")},this.verifyHumanity=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=await e.sendRequest("PROOFS_REQUEST",hi(hi({minPoints:0,context:0},t),{},{mode:e.mode,appId:e.appId}));return console.log("[BringID] verifyHumanity completed successfully"),n},this.getAddressScore=async t=>{if(!t)throw new Error("`address` argument is required to get address score");try{const{score:e,message:n,signature:r}=await o(t);return console.log("[BringID] getAddressScore completed successfully"),{score:e,message:n,signature:r}}catch(t){throw console.error("[BringID] getAddressScore failed:",t),t}},this.verifyProofs=async t=>{let{proofs:e,provider:n,context:r,contract:i}=t;const o={verified:!1,score:{total:0,groups:[]}},a=await async function(t){try{const e="dev"===t?"dev-configs":"configs",n=await s("https://raw.githubusercontent.com/BringID/configs/main/".concat(e,".json")),r={REGISTRY:n.REGISTRY,CHAIN_ID:n.CHAIN_ID};return console.log("[BringID] Registry config fetched successfully:",r),r}catch(t){return console.error("[BringID] Failed to fetch registry config:",t),null}}(this.mode);if(!a)throw new Error("configs cannot be fetched");const l=e.map((t=>({credentialGroupId:t.credential_group_id,appId:t.app_id,semaphoreProof:{merkleTreeDepth:t.semaphore_proof.merkle_tree_depth,merkleTreeRoot:t.semaphore_proof.merkle_tree_root,nullifier:t.semaphore_proof.nullifier,message:t.semaphore_proof.message,scope:t.semaphore_proof.scope,points:t.semaphore_proof.points}}))),h=new ui(a.REGISTRY,c,n);try{const t=await h.apps(this.appId);console.log("[BringID] app data:",t);const s=null!=r?r:0,a=null!=i?i:"0x0000000000000000000000000000000000000000";if(!await h.verifyProofs.staticCall(this.appId,s,l,{from:a}))return o;const c=t.scorer,f=new ui(c,u,n),p=e.map((t=>t.credential_group_id)),d=await f.getScores(p),g=e.map(((t,e)=>({credential_group_id:t.credential_group_id,score:Number(d[e])}))),y=g.reduce(((t,e)=>t+e.score),0);return console.log("[BringID] verifyProofs completed successfully"),{verified:!0,score:{total:y,groups:g}}}catch(t){return console.error("[BringID] verifyProofs failed:",t),o}},this.appId=t.appId,"undefined"!=typeof window&&(window.addEventListener("message",this.handleMessage),this.dialogWindowOrigin=window.location.origin),t.mode&&(this.mode=t.mode)}sendMessageToDialog(t){window.postMessage(t,this.dialogWindowOrigin)}sendRequest(t,e){return this.rejectPendingRequest("REJECTED"),new Promise(((n,r)=>{this.pendingRequest={resolve:n,reject:r},this.sendMessageToDialog({type:t,payload:e})}))}rejectPendingRequest(t){this.pendingRequest&&(this.pendingRequest.reject(t),this.pendingRequest=null)}};return e}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bringid",
3
- "version": "0.5.1-beta-rc.3",
3
+ "version": "0.5.2-beta",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [