UNPKG

sevm

Version:

A Symbolic Ethereum Virtual Machine (EVM) bytecode decompiler & analyzer library & CLI

1 lines 69.3 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("sevm",[],e):"object"==typeof exports?exports.sevm=e():t.sevm=e()}(self,(()=>{return t={788:(t,e,s)=>{const a=s(326),n=t=>Object.fromEntries(Object.entries(t).map((([t,e])=>[t,e?.map((({name:t})=>t))??[]])));a.Contract.prototype.patch=async function(t={}){const e=Object.keys,s=t=>"0x"+t,a=[...e(this.functions),...e(this.reverts)].map(s).join(","),r=e(this.events).map(s).join(",");if(!t.function||!t.event){const e=`https://api.openchain.xyz/signature-database/v1/lookup?function=${a}&event=${r}`,s=await fetch(e);if(!s.ok)throw new Error(`Failed to fetch signatures from api.openchain.xyz, url: ${e}`);const{result:o}=await s.json();t.function=n(o.function),t.event=n(o.event)}for(let[e,s]of Object.entries(this.functions))e="0x"+e,e in t.function&&(s.label=t.function[e][0]);for(let[e,s]of Object.entries(this.events))e="0x"+e,e in t.event&&(s.sig=t.event[e][0]);for(let[e,s]of Object.entries(this.reverts))e="0x"+e,e in t.function&&(s.sig=t.function[e][0]);return this},t.exports=a},90:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hexlify=e.arrayify=void 0,e.arrayify=function(t){if(t instanceof Uint8Array)return t;if("string"!=typeof t)return new Uint8Array(t);if(t.length%2!=0)throw new Error(`Unable to decode, input should have even length, but got length '${t.length}'`);const e="0x"===t.slice(0,2).toLowerCase()?2:0,s=new Uint8Array((t.length-e)/2);for(let a=e,n=0;a<t.length;a+=2,n++){const e=t.slice(a,a+2),r=Number("0x"+e);if(!(r>=0))throw new Error(`Unable to decode, invalid hex byte '${e}' found at position '${a+1}'`);s[n]=r}return s},e.hexlify=function(t){return t.reduce(((t,e)=>t+e.toString(16).padStart(2,"0")),"")}},69:function(t,e){"use strict";var s,a=this&&this.__classPrivateFieldSet||function(t,e,s,a,n){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?n.call(t,s):n?n.value=s:e.set(t,s),s},n=this&&this.__classPrivateFieldGet||function(t,e,s,a){if("a"===s&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?a:"a"===s?a.call(t):a?a.value:e.get(t)};function r(t){return l.includes(t)}function o(t){switch(t){case"uint":return"uint256";case"int":return"int256";case"fixed":return"fixed128x18";case"ufixed":return"ufixed128x18";default:return t}}Object.defineProperty(e,"__esModule",{value:!0}),e.fnsig=e.sighash=e.parseSig=e.isElemType=void 0,e.isElemType=r;const i=[...Array(32).keys()].map((t=>8*(t+1))),c=[...Array(32).keys()].map((t=>t+1)),l=["address","address payable","bool","uint",...i.map((t=>`uint${t}`)),"int",...i.map((t=>`int${t}`)),"bytes",...c.map((t=>`bytes${t}`)),"string","function"];class u{constructor(t){this.input=t,this.ID_REGEX=/^\w+\b/,this.position=0}next(){for(;" "===this.input[this.position];)this.position++;const t=this.position,e=this.input.slice(t).match(this.ID_REGEX);if(e)return this.position+=e[0].length,[t,r(e[0])?"TYPE":Number.isNaN(Number(e[0]))?"ID":"LIT",e[0]];switch(this.input[t]){case"(":case")":case",":case"[":case"]":return this.position++,[t,"OP",this.input[t]]}return[t,null,null]}*[Symbol.iterator](){for(let[t,e,s]=this.next();null!==s;[t,e,s]=this.next())yield[t+1,e,s]}}class h{constructor(t){this.sig=t,s.set(this,[]),a(this,s,[...new u(t)],"f")}peek(){if(0===n(this,s,"f").length)throw new Error("Reached end of input.");return n(this,s,"f")[0]}next(){if(0===n(this,s,"f").length)throw new Error("Reached end of input.");return n(this,s,"f").shift()}consume(t){const[,,e]=this.next();if(e!==t)throw new Error(`Expected '${t}' but got '${e}'`)}}function d(t){if(void 0!==t.arrayType){const e=null===t.arrayLength?"":t.arrayLength;return`${d(t.arrayType)}[${e}]`}return"tuple"===t.type?`(${t.components.map(d).join(",")})`:t.type}s=new WeakMap,e.parseSig=function(t){const e=new h(t);let[s,a,n]=e.next();if("function"===n&&([s,a,n]=e.next()),"ID"!==a)throw new Error(`Expected function name, found '${n}':${s}`);const i=[];e.consume("(");let[,,c]=e.peek();for(;")"!==c;)i.push(l()),[,,c]=e.peek(),","===c&&e.consume(",");return e.consume(")"),{name:n,inputs:i};function l(){const t=u(),[,s,a]=e.peek();return"ID"!==s?{...t}:(e.consume(a),{...t,name:a})}function u(){const t=function(){let[t,,s]=e.peek();if("("===s){const t=[];let a;for(e.consume("("),[,,s]=e.peek();")"!==s;)a=u(),t.push(a),[,,s]=e.peek(),","===s&&e.consume(",");return e.consume(")"),{type:"tuple",components:t}}if(r(s))return e.next(),{type:o(s)};throw new Error(`Invalid type ${s}: ${t}`)}(),s=[];let[,,a]=e.peek();for(;"["===a;){e.consume("[");const[,t,n]=e.peek();"LIT"===t?(e.consume(n),e.consume("]"),s.push(Number(n))):(s.push(null),e.consume("]")),[,,a]=e.peek()}return s.reduce(((e,a,n)=>({type:`${t.type}${s.slice(0,n+1).map((t=>`[${null===t?"":t}]`)).join("")}`,arrayType:e,arrayLength:a})),t)}},e.sighash=function(t){return`${t.name}(${t.inputs.map(d).join(",")})`},e.fnsig=function(t){return`${t.name}(${t.inputs.map(((t,e)=>`${d(t)} ${t.name??"_arg"+e}`)).join(", ")})`}},773:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Sar=e.Shr=e.Shl=e.Byte=e.Not=e.Xor=e.Or=e.And=e.IsZero=e.Eq=e.Gt=e.Lt=e.Exp=e.Mod=e.Div=e.Sub=e.Mul=e.Add=void 0;const a=s(224);class n extends a.Tag{constructor(t,e){super(Math.max(t.depth,e.depth)+1,t.count+e.count+1),this.left=t,this.right=e}}const r=t=>(t%a.MOD_256+a.MOD_256)%a.MOD_256;class o extends n{constructor(){super(...arguments),this.tag="Add"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(r(t.val+e.val)):t.isZero()?e:e.isZero()?t:new o(t,e)}}e.Add=o;class i extends n{constructor(){super(...arguments),this.tag="Mul"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(r(t.val*e.val)):t.isZero()||e.isZero()?new a.Val(0n):new i(t,e)}}e.Mul=i;class c extends n{constructor(){super(...arguments),this.tag="Sub"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(r(t.val-e.val)):e.isZero()?t:new c(t,e)}}e.Sub=c;class l extends n{constructor(){super(...arguments),this.tag="Div"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?0n===e.val?new l(t,e):new a.Val(t.val/e.val):e.isVal()&&1n===e.val?t:new l(t,e)}}e.Div=l;class u extends n{constructor(){super(...arguments),this.tag="Mod"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()&&0n!==e.val?new a.Val(t.val%e.val):new u(t,e)}}e.Mod=u;class h extends n{constructor(){super(...arguments),this.tag="Exp"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()&&e.val>=0?new a.Val(t.val**e.val):new h(t,e)}}e.Exp=h;class d extends a.Tag{constructor(t,e,s=!1){super(Math.max(t.depth,e.depth)+1,t.count+e.count+1),this.left=t,this.right=e,this.equal=s}}class p extends a.Tag{constructor(t){super(t.depth+1,t.count+1),this.value=t}}class f extends a.Tag{constructor(t,e){super(Math.max(t.depth,e.depth)+1,t.count+e.count+1),this.value=t,this.shift=e}}class v extends d{constructor(){super(...arguments),this.tag="Lt"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(t.val<e.val?1n:0n):new v(t,e)}}e.Lt=v;class g extends d{constructor(){super(...arguments),this.tag="Gt"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(t.val>e.val?1n:0n):new g(t,e)}}e.Gt=g;class m extends n{constructor(){super(...arguments),this.tag="Eq"}eval(){return new m(this.left.eval(),this.right.eval())}}e.Eq=m;class b extends a.Tag{constructor(t){super(t.depth+1,t.count+1),this.value=t,this.tag="IsZero"}eval(){const t=this.value.eval();return t.isVal()?0n===t.val?new a.Val(1n):new a.Val(0n):"Lt"===t.tag?new g(t.left,t.right,!t.equal):"Gt"===t.tag?new v(t.left,t.right,!t.equal):"IsZero"===t.tag?t.value:new b(t)}}e.IsZero=b;class w extends n{constructor(){super(...arguments),this.tag="And"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(t.val&e.val):t.isVal()&&/^[f]+$/.test(t.val.toString(16))?e:e.isVal()&&/^[f]+$/.test(e.val.toString(16))?t:t.isVal()&&"And"===e.tag&&e.left.isVal()&&t.val===e.left.val?e.right:new w(t,e)}}e.And=w;class y extends n{constructor(){super(...arguments),this.tag="Or"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(t.val|e.val):new y(t,e)}}e.Or=y;class $ extends n{constructor(){super(...arguments),this.tag="Xor"}eval(){const t=this.left.eval(),e=this.right.eval();return t.isVal()&&e.isVal()?new a.Val(t.val^e.val):new $(t,e)}}e.Xor=$;class S extends p{constructor(){super(...arguments),this.tag="Not"}eval(){const t=this.value.eval();return t.isVal()?new a.Val(r(~t.val)):new S(t)}}e.Not=S;class E extends a.Tag{constructor(t,e){super(Math.max(t.depth,e.depth)+1,t.count+e.count+1),this.pos=t,this.data=e,this.tag="Byte"}eval(){const t=this.pos.eval(),e=this.data.eval();return e.isVal()&&t.isVal()?new a.Val(e.val>>t.val&1n):new E(t,e)}}e.Byte=E;class x extends f{constructor(){super(...arguments),this.tag="Shl"}eval(){const t=this.value.eval(),e=this.shift.eval();return t.isVal()&&e.isVal()?new a.Val(t.val<<e.val):new x(t,e)}}e.Shl=x;class k extends f{constructor(){super(...arguments),this.tag="Shr"}eval(){const t=this.value.eval(),e=this.shift.eval();return t.isVal()&&e.isVal()?new a.Val(t.val>>e.val):new k(t,e)}}e.Shr=k;class V extends f{constructor(){super(...arguments),this.tag="Sar"}eval(){const t=this.value.eval(),e=this.shift.eval();return t.isVal()&&e.isVal()?new a.Val(t.val>>e.val):new V(t,e)}}e.Sar=V},865:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SigCase=e.Sig=e.JumpDest=e.Jumpi=e.Jump=e.Branch=void 0;const a=s(224);class n{constructor(t,e){this.pc=t,this.state=e}static make(t,e){return new n(t,e.clone())}}e.Branch=n,e.Jump=class{constructor(t,e,s){this.offset=t,this.destBranch=e,this.pushStateId=s,this.name="Jump"}eval(){return this}next(){return[this.destBranch]}};class r{constructor(t,e,s,a,n){this.cond=t,this.offset=e,this.fallBranch=s,this.destBranch=a,this.pushStateId=n,this.name="Jumpi",this.evalCond=t.eval()}eval(){return new r(this.cond.eval(),this.offset,this.fallBranch,this.destBranch,this.pushStateId)}next(){return this.evalCond.isVal()?0n===this.evalCond.val?[this.fallBranch]:[this.destBranch]:[this.destBranch,this.fallBranch]}}e.Jumpi=r,e.JumpDest=class{constructor(t){this.fallBranch=t,this.name="JumpDest"}eval(){return this}next(){return[this.fallBranch]}};class o extends a.Tag{constructor(t,e=!0){super(0,1),this.selector=t,this.positive=e,this.tag="Sig"}eval(){return this}}e.Sig=o,e.SigCase=class{constructor(t,e,s){this.condition=t,this.offset=e,this.fallBranch=s,this.name="SigCase"}eval(){return this}next(){return[this.fallBranch]}}},224:function(t,e,s){"use strict";var a,n=this&&this.__createBinding||(Object.create?function(t,e,s,a){void 0===a&&(a=s);var n=Object.getOwnPropertyDescriptor(e,s);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[s]}}),Object.defineProperty(t,a,n)}:function(t,e,s,a){void 0===a&&(a=s),t[a]=e[s]}),r=this&&this.__exportStar||function(t,e){for(var s in t)"default"===s||Object.prototype.hasOwnProperty.call(e,s)||n(e,t,s)},o=this&&this.__classPrivateFieldGet||function(t,e,s,a){if("a"===s&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?a:"a"===s?a.call(t):a?a.value:e.get(t)},i=this&&this.__classPrivateFieldSet||function(t,e,s,a,n){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?n.call(t,s):n?n.value=s:e.set(t,s),s};Object.defineProperty(e,"__esModule",{value:!0}),e.mem=e.inline0=e.reduce=e.Locali=e.Local=e.Val=e.MOD_256=e.Tag=e.Require=e.CallSite=e.If=e.Throw=e.evalE=e.isInst=e.isExpr=void 0,e.isExpr=t=>null!==t&&"object"==typeof t&&"tag"in t,e.isInst=t=>null!==t&&"object"==typeof t&&"name"in t,e.evalE=t=>t.eval(),e.Throw=class{constructor(t,e){this.reason=t,this.opcode=e,this.name="Throw"}eval(){return this}};class c{constructor(t,e,s){this.condition=t,this.trueBlock=e,this.falseBlock=s,this.name="If"}eval(){return new c(this.condition.eval(),this.trueBlock?d(this.trueBlock):void 0,this.falseBlock?d(this.falseBlock):void 0)}}e.If=c,e.CallSite=class{constructor(t){this.selector=t,this.name="CallSite"}eval(){return this}};class l{constructor(t,e,s){this.condition=t,this.selector=e,this.args=s,this.name="Require"}eval(){return new l(this.condition.eval(),this.selector,this.args.map(e.evalE))}}e.Require=l;class u{constructor(t,e){this.depth=t,this.count=e}isVal(){return"Val"===this.tag}isZero(){return this.isVal()&&0n===this.val}isJumpDest(){return this.isVal()&&null!==this.jumpDest}children(){return Object.values(this).filter((t=>t instanceof u))}unwrap(){return this}}e.Tag=u,e.MOD_256=1n<<0x100n;class h extends u{constructor(t,s){if(t<0||t>=e.MOD_256)throw new Error(`Val is a not a valid unsigned 256-word: ${t}`);super(0,1),this.val=t,this.pushStateId=s,this.tag="Val",this.jumpDest=null}eval(){return new h(this.val)}}function d(t){return t?.flatMap((t=>["Local","MStore"].includes(t.name)?[]:t.eval()))}e.Val=h,e.Local=class extends u{constructor(t,e){super(e.depth+1,e.count+1),this.index=t,this.value=e,this.tag="Local",this.nrefs=0,a.set(this,void 0)}eval(){return void 0===o(this,a,"f")&&i(this,a,this.value.eval(),"f"),o(this,a,"f")}unwrap(){return this.value}},a=new WeakMap,e.Locali=class{constructor(t){this.local=t,this.name="Local"}eval(){return this}},e.reduce=d,e.inline0=function(t){const e=new WeakSet,s=[];for(const n of t.reverse()){if("MStore"===n.name)a(n.location),a(n.data);else if("Local"===n.name&&e.has(n.local))continue;s.unshift(n)}return s;function a(t){e.add(t),t.children().forEach(a)}},e.mem=function(t){const e=[];for(const a of t.reverse())"MStore"===a.name&&(s(a.location),s(a.data)),e.unshift(a);return e;function s(t){"Local"===t.tag&&t.nrefs--,t.children().forEach(s)}},r(s(773),e),r(s(865),e),r(s(418),e),r(s(8),e),r(s(872),e),r(s(939),e),r(s(350),e)},418:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Log=void 0;const a=s(224);class n{constructor(t,e,s,a,n){this.event=t,this.offset=e,this.size=s,this.topics=a,this.args=n,this.name="Log"}get eventName(){if(void 0!==this.event&&void 0!==this.event.sig)return this.event.sig.split("(")[0]}eval(){return new n(this.event,this.offset.eval(),this.size.eval(),this.topics.map(a.evalE),this.args?.map(a.evalE))}}e.Log=n},8:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MStore=e.MLoad=void 0;const a=s(224);class n extends a.Tag{constructor(t,e){super(Math.max(t.depth,e?.depth??0)+1,t.count+(e?.count??0)+1),this.location=t,this.value=e,this.tag="MLoad"}eval(){return this.value?this.value.eval():new n(this.location.eval())}}e.MLoad=n;class r{constructor(t,e){this.location=t,this.data=e,this.name="MStore"}eval(){return new r(this.location.eval(),this.data.eval())}}e.MStore=r},872:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CallDataLoad=e.CallValue=e.DataCopy=e.Fn=e.FNS=e.Props=e.Prop=void 0;const a=s(224);class n extends a.Tag{constructor(t,e){super(0,1),this.symbol=t,this.type=e,this.tag="Prop"}eval(){return this}}e.Prop=n;const r=t=>[t[0],new n(t[0],t[1])],o=(t,e)=>t.map((([t,s])=>[`${e}.${t}`,s]));e.Props=Object.assign(Object.fromEntries([["address(this)","address"],["codesize()","uint"],["returndatasize()","uint"],["address(this).balance","uint"],["gasleft()","uint"]].map(r)),Object.fromEntries(o([["basefee","uint"],["coinbase","address payable"],["timestamp","uint"],["number","uint"],["difficulty","uint"],["gaslimit","uint"],["chainid","uint"],["prevrandao","uint"]],"block").map(r)),Object.fromEntries(o([["sender","address"],["data.length","uint"]],"msg").map(r)),Object.fromEntries(o([["origin","address"],["gasprice","uint"]],"tx").map(r))),e.FNS={BALANCE:[t=>`${t}.balance`,"uint256",49],EXTCODESIZE:[t=>`address(${t}).code.length`,"uint256",59],EXTCODEHASH:[t=>`keccak256(address(${t}).code)`,"bytes32",63],BLOCKHASH:[t=>`blockhash(${t})`,"bytes32",64]};class i extends a.Tag{constructor(t,s){super(s.depth+1,s.count+1),this.mnemonic=t,this.value=s,this.tag="Fn",this.type=e.FNS[t][1]}eval(){return new i(this.mnemonic,this.value.eval())}}e.Fn=i;class c extends a.Tag{constructor(t,e,s,a,n){super(Math.max(e.depth,s.depth,a?.depth??0)+1,e.count+s.count+(a?.count??0)+1),this.kind=t,this.offset=e,this.size=s,this.address=a,this.bytecode=n,this.tag="DataCopy"}eval(){return this}}e.DataCopy=c;class l extends a.Tag{constructor(){super(0,1),this.tag="CallValue"}eval(){return this}}e.CallValue=l;class u extends a.Tag{constructor(t){super(t.depth+1,t.count+1),this.location=t,this.tag="CallDataLoad"}eval(){return new u(this.location.eval())}}e.CallDataLoad=u},939:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SLoad=e.MappingLoad=e.SStore=e.MappingStore=e.Variable=void 0;const a=s(224);e.Variable=class{constructor(t,e,s){this.label=t,this.types=e,this.index=s}};class n{constructor(t,e,s,a,n,r){this.slot=t,this.mappings=e,this.location=s,this.items=a,this.data=n,this.structlocation=r,this.name="MappingStore";const o=s;o in e||(e[o]={name:void 0,structs:[],keys:[],values:[]}),e[o].keys.push(a),void 0===r&&e[o].values.push(n)}eval(){return new n(this.slot,this.mappings,this.location,this.items,this.data.eval(),this.structlocation)}}e.MappingStore=n;class r{constructor(t,e,s){this.slot=t,this.data=e,this.variable=s,this.name="SStore"}eval(){const t=this.data.eval();if(void 0!==this.variable){const e=this.variable.types.indexOf(this.data);if(-1===e)throw new Error("error in eval sstore");this.variable.types[e]=t}return new r(this.slot.eval(),t,this.variable)}}e.SStore=r;class o extends a.Tag{constructor(t,e,s,a,n){super(Math.max(t.depth,...a.map((t=>t.depth)))+1,t.count+a.reduce(((t,e)=>t+e.count),0)+1),this.slot=t,this.mappings=e,this.location=s,this.items=a,this.structlocation=n,this.tag="MappingLoad",s in e||(e[s]={name:void 0,structs:[],keys:[],values:[]}),e[s].keys.push(a)}eval(){return this}}e.MappingLoad=o;class i extends a.Tag{constructor(t,e){super(t.depth+1,t.count+1),this.slot=t,this.variable=e,this.tag="SLoad"}eval(){return new i(this.slot.eval(),this.variable)}}e.SLoad=i},350:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SelfDestruct=e.Invalid=e.Revert=e.Return=e.Stop=e.DelegateCall=e.StaticCall=e.Create2=e.CallCode=e.ReturnData=e.Call=e.Create=e.Sha3=void 0;const a=s(224);function n(...t){return[Math.max(...t.map((t=>t.depth)))+1,(t?.reduce(((t,e)=>t+e.count),0)??0)+1]}class r extends a.Tag{constructor(t,e,s){super(...n(t,e,...s??[])),this.offset=t,this.size=e,this.args=s,this.tag="Sha3"}eval(){return new r(this.offset.eval(),this.size.eval(),this.args?.map(a.evalE))}children(){return[...super.children(),...this.args??[]]}}e.Sha3=r;class o extends a.Tag{constructor(t,e,s,a=null){super(...n(t,e,s)),this.value=t,this.offset=e,this.size=s,this.bytecode=a,this.tag="Create",this.type="address"}eval(){return new o(this.value.eval(),this.offset.eval(),this.size.eval(),this.bytecode)}}e.Create=o;class i extends a.Tag{constructor(t,e,s,a,r,o,i){super(...n(t,e,s,a,r,o,i)),this.gas=t,this.address=e,this.value=s,this.argsStart=a,this.argsLen=r,this.retStart=o,this.retLen=i,this.tag="Call",this.throwOnFail=!1}eval(){return this}}e.Call=i;class c extends a.Tag{constructor(t,e){super(...n(t,e)),this.retOffset=t,this.retSize=e,this.tag="ReturnData",this.type="bytes",this.wrapped=!1}eval(){return this}}e.ReturnData=c;class l extends a.Tag{constructor(t,e,s,a,r,o,i){super(...n(t,e,s,a,r,o,i)),this.gas=t,this.address=e,this.value=s,this.memoryStart=a,this.memoryLength=r,this.outputStart=o,this.outputLength=i,this.tag="CallCode"}eval(){return this}}e.CallCode=l;class u extends a.Tag{constructor(t,e,s){super(...n(t,e,s)),this.offset=t,this.size=e,this.value=s,this.tag="Create2"}eval(){return this}}e.Create2=u;class h extends a.Tag{constructor(t,e,s,a,r,o){super(...n(t,e,s,a,r,o)),this.gas=t,this.address=e,this.memoryStart=s,this.memoryLength=a,this.outputStart=r,this.outputLength=o,this.tag="StaticCall"}eval(){return this}}e.StaticCall=h;class d extends a.Tag{constructor(t,e,s,a,r,o){super(...n(t,e,s,a,r,o)),this.gas=t,this.address=e,this.memoryStart=s,this.memoryLength=a,this.outputStart=r,this.outputLength=o,this.tag="DelegateCall"}eval(){return this}}e.DelegateCall=d,e.Stop=class{constructor(){this.name="Stop"}eval(){return this}};class p{constructor(t,e,s){this.offset=t,this.size=e,this.args=s,this.name="Return"}eval(){return new p(this.offset.eval(),this.size.eval(),this.args?.map(a.evalE))}}e.Return=p;class f{constructor(t,e,s,a,n){this.offset=t,this.size=e,this.selector=s,this.sig=a,this.args=n,this.name="Revert"}eval(){return new f(this.offset.eval(),this.size.eval(),this.selector,this.sig,this.args?.map(a.evalE))}static isRequireOrAssert(t){return void 0===t||t===f.ERROR||t===f.PANIC}isRequireOrAssert(){return f.isRequireOrAssert(this.selector)}}e.Revert=f,f.ERROR="08c379a0",f.PANIC="4e487b71",e.Invalid=class{constructor(t){this.opcode=t,this.name="Invalid"}eval(){return this}},e.SelfDestruct=class{constructor(t){this.address=t,this.name="SelfDestruct"}eval(){return this}}},755:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={ERC165:{selectors:["01ffc9a7"],topics:[],functions:{"01ffc9a7":"function supportsInterface(bytes4 interfaceID) view returns (bool)"},events:{}},ERC173:{selectors:["8da5cb5b","01ffc9a7","f2fde38b"],topics:["8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0"],functions:{"8da5cb5b":"function owner() view returns (address)","01ffc9a7":"function supportsInterface(bytes4 interfaceID) view returns (bool)",f2fde38b:"function transferOwnership(address _newOwner)"},events:{"8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0":"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)"}},ERC20:{selectors:["dd62ed3e","095ea7b3","70a08231","18160ddd","a9059cbb","23b872dd"],topics:["8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925","ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],functions:{dd62ed3e:"function allowance(address _owner, address _spender) view returns (uint256 remaining)","095ea7b3":"function approve(address _spender, uint256 _value) returns (bool success)","70a08231":"function balanceOf(address _owner) view returns (uint256 balance)","18160ddd":"function totalSupply() view returns (uint256)",a9059cbb:"function transfer(address _to, uint256 _value) returns (bool success)","23b872dd":"function transferFrom(address _from, address _to, uint256 _value) returns (bool success)"},events:{"8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925":"event Approval(address indexed _owner, address indexed _spender, uint256 _value)",ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef:"event Transfer(address indexed _from, address indexed _to, uint256 _value)"}},ERC20Metadata:{selectors:["dd62ed3e","095ea7b3","70a08231","313ce567","06fdde03","95d89b41","18160ddd","a9059cbb","23b872dd"],topics:["8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925","ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],functions:{dd62ed3e:"function allowance(address _owner, address _spender) view returns (uint256 remaining)","095ea7b3":"function approve(address _spender, uint256 _value) returns (bool success)","70a08231":"function balanceOf(address _owner) view returns (uint256 balance)","313ce567":"function decimals() view returns (uint8)","06fdde03":"function name() view returns (string)","95d89b41":"function symbol() view returns (string)","18160ddd":"function totalSupply() view returns (uint256)",a9059cbb:"function transfer(address _to, uint256 _value) returns (bool success)","23b872dd":"function transferFrom(address _from, address _to, uint256 _value) returns (bool success)"},events:{"8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925":"event Approval(address indexed _owner, address indexed _spender, uint256 _value)",ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef:"event Transfer(address indexed _from, address indexed _to, uint256 _value)"}},ERC721:{selectors:["095ea7b3","70a08231","081812fc","e985e9c5","6352211e","42842e0e","b88d4fde","a22cb465","01ffc9a7","23b872dd"],topics:["8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925","17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31","ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],functions:{"095ea7b3":"function approve(address _approved, uint256 _tokenId) payable","70a08231":"function balanceOf(address _owner) view returns (uint256)","081812fc":"function getApproved(uint256 _tokenId) view returns (address)",e985e9c5:"function isApprovedForAll(address _owner, address _operator) view returns (bool)","6352211e":"function ownerOf(uint256 _tokenId) view returns (address)","42842e0e":"function safeTransferFrom(address _from, address _to, uint256 _tokenId) payable",b88d4fde:"function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) payable",a22cb465:"function setApprovalForAll(address _operator, bool _approved)","01ffc9a7":"function supportsInterface(bytes4 interfaceID) view returns (bool)","23b872dd":"function transferFrom(address _from, address _to, uint256 _tokenId) payable"},events:{"8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925":"event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)","17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31":"event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)",ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef:"event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)"}}}},42:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.EVM=void 0;const a=s(90),n=s(224),r=s(360),o=s(554);class i{constructor(t,e){this.step=e,this.blocks=new Map,this.errors=[],this._ids={_count:0,push(t){void 0===t.id&&(t.id=this._count++)}},this.bytecode=(0,a.arrayify)(t)}static new(t){return new i(t,new o.Shanghai)}chunks(){let t=0;const e=[],s=[...this.blocks.keys()];s.sort(((t,e)=>t-e));for(const a of s){const s=this.blocks.get(a);t!==a&&e.push({pcbegin:t,pcend:a,content:this.bytecode.subarray(t,a)}),t=s.pcend;const n=s.opcodes.map((({opcode:t})=>t));e.push({pcbegin:a,pcend:s.pcend,content:n,states:s.states})}return t!==this.bytecode.length&&e.push({pcbegin:t,pcend:this.bytecode.length,content:this.bytecode.subarray(t)}),e}start(){const t=new r.State;this.run(0,t);for(const[,t]of this.step.functionBranches)this.run(t.pc,t.state);return t}run(t,e){const s=[new n.Branch(t,e)];for(;s.length>0;){const t=s.shift(),e=this.blocks.get(t.pc);if(void 0!==e&&e.states.length>10)continue;this.exec(t.pc,t.state);const a=t.state.last;for(const t of a.next?a.next():[])s.unshift(t)}}exec(t,e){if(this._ids.push(e),e.halted)throw new Error(`State at ${t} must be non-halted to be \`exec\``);const s=[];let a;for(a of this.step.decode(this.bytecode,t)){const[,t,i]=this.step[a.opcode],c={opcode:a};s.push(c);try{e.halted||(this.step[i](e,a,this),c.stack=e.stack.clone())}catch(t){if(!(t instanceof r.ExecError))throw t;const s=new n.Throw(t.message,a);e.halt(s),this.errors.push({err:s,state:e})}if(!t&&this.bytecode[a.nextpc]===o.JUMPDEST){const t=n.Branch.make(a.nextpc,e);e.halted||e.halt(new n.JumpDest(t));break}if(t){if(!e.halted)throw Error("asfdasdf 12123");break}}if(void 0===a)throw new Error(`Executing block at ${t} cannot be empty`);if(!e.halted)throw new Error(`State must be halted after executing block at ${t}..${a.pc}`);const i=this.blocks.get(t);void 0===i?this.blocks.set(t,{pcend:a.nextpc,opcodes:s,states:[e]}):i.states.push(e)}opcodes(){if(0===this.blocks.size)throw new Error("`blocks` is empty, call `start`, `run` or `exec` first");return[...this.blocks.values()].flatMap((t=>t.opcodes.map((t=>t.opcode))))}gc(t){const e=this.blocks.get(t.pc);if(void 0!==e)for(const s of e.states)if(c(t.state,s))return s}}function c({stack:t},{stack:e}){const s=(t,e)=>!(t.isVal()&&t.pushStateId&&e.isVal()&&e.pushStateId&&t.val!==e.val);if(t.values.length!==e.values.length)return!1;for(let a=0;a<t.values.length;a++)if(!s(t.values[a],e.values[a]))return!1;return!0}e.EVM=i},326:function(t,e,s){"use strict";var a=this&&this.__createBinding||(Object.create?function(t,e,s,a){void 0===a&&(a=s);var n=Object.getOwnPropertyDescriptor(e,s);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[s]}}),Object.defineProperty(t,a,n)}:function(t,e,s,a){void 0===a&&(a=s),t[a]=e[s]}),n=this&&this.__exportStar||function(t,e){for(var s in t)"default"===s||Object.prototype.hasOwnProperty.call(e,s)||a(e,t,s)},r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.reduce0=e.build=e.PublicFunction=e.isRevertBlock=e.Contract=e.ERCIds=void 0;const o=s(224),i=s(773),c=s(939),l=s(90),u=r(s(755)),h=s(42),d=s(452),p=s(360),f=s(554);e.ERCIds=Object.keys(u.default);class v{constructor(t,e=new f.Shanghai){this.events={},this.variables=new Map,this.mappings={},this.functionBranches=new Map,this.reverts={},this.functions={},this.bytecode=(0,l.arrayify)(t);const s=new h.EVM(this.bytecode,e),a=new p.State;s.run(0,a),this.main=b(a),this.payable=!w(this.main,!0);for(const[t,e]of s.step.functionBranches)s.run(e.pc,e.state),this.functions[t]=new m(this,b(e.state),t);this.events=s.step.events,this.variables=s.step.variables,this.mappings=s.step.mappings,this.functionBranches=s.step.functionBranches,this.reverts=s.step.reverts,this.metadata=(0,d.splitMetadataHash)(this.bytecode).metadata,this.errors=s.errors,this.blocks=s.blocks,this.chunks=()=>s.chunks(),this.opcodes=()=>s.opcodes()}reduce(){const t=Object.create(v.prototype),e=Object.assign(t,this);e.main=(0,o.reduce)(this.main),e.payable=!w(e.main),e.functions={};for(const[t,s]of Object.entries(this.functions)){const a=new m(e,(0,o.reduce)(s.stmts),t,s.payable);a.label=s.label,e.functions[t]=a}return e}getFunctions(){return Object.values(this.functions).flatMap((t=>void 0===t.label?[]:[t.label]))}getEvents(){return Object.values(this.events).flatMap((t=>void 0===t.sig?[]:[t.sig]))}isERC(t,e=!0){return u.default[t].selectors.every((t=>this.functionBranches.has(t)))&&(!e||u.default[t].topics.every((t=>t in this.events)))}}function g(t){return t.length>=1&&t.slice(0,-1).every((t=>"Local"===t.name||"MStore"===t.name))&&"Revert"===t.at(-1).name&&t.at(-1).isRequireOrAssert()}e.Contract=v,e.isRevertBlock=g;class m{constructor(t,e,s,a){this.contract=t,this.stmts=e,this.selector=s,this._label=void 0,this.returns=[],this.visibility="public",void 0===a?w(this.stmts)?this.payable=!1:t.payable?this.payable=!0:this.payable=!1:this.payable=a,this.constant=1===this.stmts.length&&"Return"===this.stmts[0].name;const n=[];m.findReturns(e,n),n.length>0&&n.every((t=>t.length===n[0].length&&t.map((t=>t.type)).join("")===n[0].map((t=>t.type)).join("")))?n[0].forEach((t=>{t.isVal()?this.returns.push("uint256"):t.type?this.returns.push(t.type):this.returns.push("unknown")})):n.length>0&&this.returns.push("<unknown>")}get label(){return this._label}set label(t){if(this._label=t,void 0!==t){const e=t.split("(")[0];if(this.isGetter()){const t=this.stmts.at(-1).args[0].slot.val,s=this.contract.variables.get(t);void 0!==s?s.label=e:this.contract.variables.set(t,new c.Variable(e,[],this.contract.variables.size+1))}if(this.isMappingGetter()){const t=this.stmts.at(-1).args[0].location;this.contract.mappings[t].name=e}const s=t.replace(e,"").slice(1,-1).split(",");(s.length>1||1===s.length&&""!==s[0])&&this.stmts.forEach((t=>m.patchCallDataLoad(t,s)))}}isGetter(){const t=this.stmts.at(-1);return this.stmts.length>=1&&this.stmts.slice(0,-1).every((t=>"Local"===t.name||"MStore"===t.name||"Require"===t.name))&&"Return"===t.name&&void 0!==t.args&&1===t.args.length&&"SLoad"===t.args[0].tag&&t.args[0].slot.isVal()}isMappingGetter(){const t=this.stmts.find((t=>"Local"!==t.name&&"MStore"!==t.name&&"Require"!==t.name));return void 0!==t&&this.stmts.at(-1)===t&&"Return"===t.name&&void 0!==t.args&&t.args.every((t=>"MappingLoad"===t.tag))}static findReturns(t,e){for(const s of t)"Return"===s.name&&s.args&&s.args.length>0?e.push(s.args):"If"===s.name&&[s.trueBlock,s.falseBlock].forEach((t=>{void 0!==t&&m.findReturns(t,e)}))}static patchCallDataLoad(t,e,s=new Set){if(null!==t&&!s.has(t)){s.add(t);for(const a in t)if("mappings"!==a&&Object.prototype.hasOwnProperty.call(t,a)){const n=t[a];if(n&&"CallDataLoad"===n.tag&&n.location.isVal()){const t=Number((n.location.val-4n)/32n);n.type=e[t]}"object"!=typeof n||n instanceof c.Variable||n instanceof o.Throw||m.patchCallDataLoad(n,e,s)}}}}function b(t){const e=new WeakSet,s=function t(s){if(e.has(s))return[];e.add(s);const a=s.last;if(void 0===a)return[];for(let t=0;t<s.stmts.length;t++);switch(a.name){case"Jumpi":{if(a.evalCond.isVal())return 0n===a.evalCond.val?[...s.stmts.slice(0,-1),...t(a.fallBranch.state)]:[...s.stmts.slice(0,-1),...t(a.destBranch.state)];const e=t(a.destBranch.state),n=t(a.fallBranch.state);return[...s.stmts.slice(0,-1),...g(n)?[new o.Require(a.cond,n.at(-1).selector,n.at(-1).args??[]),...e]:[new o.If(new i.IsZero(a.cond),n),...e]]}case"SigCase":{const e=t(a.fallBranch.state);return[...s.stmts.slice(0,-1),new o.If(a.condition,[new o.CallSite(a.condition.selector)],e)]}case"Jump":return[...s.stmts.slice(0,-1),...t(a.destBranch.state)];case"JumpDest":return[...s.stmts.slice(0,-1),...t(a.fallBranch.state)];default:return s.stmts}}(t);return s}function w(t,e=!1){const s=(t=e&&t[0]instanceof o.MStore?t.slice(1):t).find((t=>"Local"!==t.name));return s instanceof o.Require&&(t=>"IsZero"===t.condition.tag&&"CallValue"===t.condition.value.tag)(s.eval())}e.PublicFunction=m,e.build=b,e.reduce0=function(t){const e=[];for(const s of t)("Local"!==s.name||s.local.nrefs>0)&&e.push(s);return e},n(s(69),e),n(s(42),e),n(s(452),e),n(s(989),e),n(s(360),e),n(s(554),e),n(s(693),e)},452:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.splitMetadataHash=e.Metadata=void 0;const a=s(90);class n{constructor(){this.protocol="",this.hash="",this.solc=""}get url(){return`${this.protocol}://${this.hash}`}get minor(){const t=/^0\.(\d+)\./.exec(this.solc)?.[1];return t?parseInt(t):void 0}}e.Metadata=n,e.splitMetadataHash=function(t){const e=(0,a.arrayify)(t);if(e.length<=2)return{bytecode:e,metadata:void 0};const s=(e.at(-2)<<8)+e.at(-1),r=new Uint8Array(e.subarray(e.length-2-s,e.length-2));if(r.length!==s)return{bytecode:e,metadata:void 0};let o;try{o=function(t){const e=Math.pow(2,-24),s=Math.pow(2,32),a=new DataView(t);let n=0;function r(t,e){return n+=e,t}function o(e){return r(new Uint8Array(t,n,e),e)}const i=()=>r(a.getUint8(n),1),c=()=>r(a.getUint16(n),2),l=()=>r(a.getUint32(n),4);function u(){return 255===a.getUint8(n)&&(n+=1,!0)}function h(t){if(t<24)return t;if(24===t)return i();if(25===t)return c();if(26===t)return l();if(27===t)return l()*s+l();if(31===t)return-1;throw"Invalid length encoding"}function d(t){const e=i();if(255===e)return-1;const s=h(31&e);if(s<0||e>>5!==t)throw"Invalid indefinite length element";return s}function p(t,e){for(let s=0;s<e;++s){let s=i();128&s&&(s<224?(s=(31&s)<<6|63&i(),e-=1):s<240?(s=(15&s)<<12|(63&i())<<6|63&i(),e-=2):(s=(15&s)<<18|(63&i())<<12|(63&i())<<6|63&i(),e-=3)),s<65536?t.push(s):(s-=65536,t.push(55296|s>>10),t.push(56320|1023&s))}}const f=function t(){const s=i(),l=s>>5,f=31&s;let v,g;if(7===l)switch(f){case 25:return function(){const t=new ArrayBuffer(4),s=new DataView(t),a=c(),n=32768&a;let r=31744&a;const o=1023&a;if(31744===r)r=261120;else if(0!==r)r+=114688;else if(0!==o)return o*e;return s.setUint32(0,n<<16|r<<13|o<<13),s.getFloat32(0)}();case 26:return r(a.getFloat32(n),4);case 27:return r(a.getFloat64(n),8)}if(g=h(f),g<0&&(l<2||6<l))throw"Invalid length";switch(l){case 0:return g;case 1:return-1-g;case 2:if(g<0){const t=[];let e=0;for(;(g=d(l))>=0;)e+=g,t.push(o(g));const s=new Uint8Array(e);let a=0;for(v=0;v<t.length;++v)s.set(t[v],a),a+=t[v].length;return s}return o(g);case 3:const e=[];if(g<0)for(;(g=d(l))>=0;)p(e,g);else p(e,g);return String.fromCharCode.apply(null,e);case 4:let s;if(g<0)for(s=[];!u();)s.push(t());else for(s=new Array(g),v=0;v<g;++v)s[v]=t();return s;case 5:const a={};for(v=0;v<g||g<0&&!u();++v)a[t()]=t();return a;case 6:return t();case 7:switch(g){case 20:return!1;case 21:return!0;case 22:return null;default:return}default:throw new Error("Unrecognized major type")}}();if(n!==t.byteLength)throw"Remaining bytes";return f}(r.buffer)}catch{return{bytecode:e,metadata:void 0}}if(null===o||"object"!=typeof o)return{bytecode:e,metadata:void 0};const i=new n;return"ipfs"in o&&o.ipfs instanceof Uint8Array?(i.protocol="ipfs",i.hash=function(t){const e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",s=Array(256).fill(-1);for(let t=0;t<e.length;++t)s[e.charCodeAt(t)]=t;const a=[];for(const n of t){let t=n;for(let n=0;n<a.length;++n){const r=(s[a[n]]<<8)+t;a[n]=e.charCodeAt(r%58),t=r/58|0}for(;t;)a.push(e.charCodeAt(t%58)),t=t/58|0}for(const e of t){if(e)break;a.push("1".charCodeAt(0))}return a.reverse(),String.fromCharCode(...a)}(o.ipfs),delete o.ipfs):"bzzr0"in o&&o.bzzr0 instanceof Uint8Array?(i.protocol="bzzr0",i.hash=(0,a.hexlify)(o.bzzr0),delete o.bzzr0):"bzzr1"in o&&o.bzzr1 instanceof Uint8Array&&(i.protocol="bzzr1",i.hash=(0,a.hexlify)(o.bzzr1),delete o.bzzr1),"solc"in o&&o.solc instanceof Uint8Array&&(i.solc=o.solc.join("."),delete o.solc),{bytecode:e.subarray(0,e.length-2-s),metadata:Object.assign(i,o)}}},989:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.solMappings=e.solStructs=e.solVars=e.solEvents=e.solStmts=e.sol=void 0;const a=s(326),n=s(69),r=s(224),o=s(872);function i(t,...e){const s=[t[0]];return e.forEach(((e,a)=>{const n=(0,r.isExpr)(e)?h(e):(0,r.isInst)(e)?v(e):`${e}`;s.push(n,t[a+1])})),s.join("")}e.sol=i;const c={Add:["+",11],Mul:["*",12],Sub:["-",11],Div:["/",12],Mod:["%",12],Exp:["**",14],Lt:["<",9],Gt:[">",9],Eq:["==",8],And:["&",4],Or:["|",3],Xor:["^",6],Not:["not",14],Byte:["byte",10],Shl:["<<",10],Shr:[">>>",10],Sar:[">>",10]},l=t=>{const e=t.tag;return e in c?c[e][1]:16};function u(t,e){return l(t)<l(e)?i`(${t})`:i`${t}`}function h(t){switch(t.tag){case"Val":return`${t.isJumpDest()?"[J]":""}0x${t.val.toString(16)}`;case"Local":return t.nrefs>0?`local${t.index}`:t.count>=1e3?`/*expression too big to decompile: ${t.count} AST nodes*/local${t.index}`:i`${t.value}`;case"Add":case"Mul":case"Sub":case"Div":case"Mod":case"Exp":case"Eq":case"And":case"Or":case"Xor":return`${u(t.left,t)} ${c[t.tag][0]} ${u(t.right,t)}`;case"Lt":case"Gt":return`${u(t.left,t)} ${c[t.tag][0]}${t.equal?"=":""} ${u(t.right,t)}`;case"IsZero":return"Eq"===t.value.tag?u(t.value.left,t)+" != "+u(t.value.right,t):u(t.value,t)+" == 0";case"Not":return`~${u(t.value,t)}`;case"Byte":return`(${u(t.data,t)} >> ${u(t.pos,t)}) & 1`;case"Shl":case"Shr":case"Sar":return`${u(t.value,t)} ${c[t.tag][0]} ${u(t.shift,t)}`;case"Sig":return`msg.sig == ${t.selector}`;case"CallValue":return"msg.value";case"CallDataLoad":{const e=t.location;return e.isVal()&&0n===e.val?"msg.data":e.isVal()&&(e.val-4n)%32n===0n?"_arg"+(e.val-4n)/32n:i`msg.data[${e}]`}case"Prop":return t.symbol;case"Fn":return o.FNS[t.mnemonic][0](h(t.value));case"DataCopy":switch(t.kind){case"calldatacopy":return i`msg.data[${t.offset}:(${t.offset}+${t.size})]`;case"codecopy":return i`this.code[${t.offset}:(${t.offset}+${t.size})]`;case"extcodecopy":return i`address(${t.address}).code[${t.offset}:(${t.offset}+${t.size})]`;case"returndatacopy":return i`output[${t.offset}:(${t.offset}+${t.size})]`}case"MLoad":return i`memory[${t.location}]`;case"Sha3":return void 0===t.args?i`keccak256(memory[${t.offset}:(${t.offset}+${t.size})])`:`keccak256(${t.args.map(h).join(", ")})`;case"Create":return i`new Contract(memory[${t.offset}..${t.offset}+${t.size}]).value(${t.value}).address`;case"Call":return t.argsLen.isZero()&&t.retLen.isZero()?"Mul"===t.gas.tag&&t.gas.left.isZero()&&t.gas.right.isVal()&&2300n===t.gas.right.val?t.throwOnFail?i`address(${t.address}).transfer(${t.value})`:i`address(${t.address}).send(${t.value})`:i`address(${t.address}).call.gas(${t.gas}).value(${t.value})`:i`call(${t.gas},${t.address},${t.value},${t.argsStart},${t.argsLen},${t.retStart},${t.retLen})`;case"ReturnData":return i`output:ReturnData:${t.retOffset}:${t.retSize}`;case"CallCode":return i`callcode(${t.gas},${t.address},${t.value},${t.memoryStart},${t.memoryLength},${t.outputStart},${t.outputLength})`;case"Create2":return i`new Contract(memory[${t.offset}:(${t.offset}+${t.size})]).value(${t.value}).address`;case"StaticCall":return i`staticcall(${t.gas},${t.address},${t.memoryStart},${t.memoryLength},${t.outputStart},${t.outputLength})`;case"DelegateCall":return i`delegatecall(${t.gas},${t.address},${t.memoryStart},${t.memoryLength},${t.outputStart},${t.outputLength})`;case"SLoad":if(void 0!==t.variable){return t.variable.label||`var_${t.variable.index}`}return i`storage[${t.slot}]`;case"MappingLoad":{let e=`mapping${t.location+1}`;const s=t.mappings[t.location].name;return t.location in t.mappings&&s&&(e=s),t.structlocation?e+t.items.map((t=>i`[${t}]`)).join("")+"["+t.structlocation.toString()+"]":e+t.items.map((t=>"["+h(t)+"]")).join("")}}}function d(t){return 3===t?.length&&t.every((t=>t.isVal()))}function p(t){let e="";for(let s=0;s<t.length&&"00"!==t.slice(s,s+2);s+=2)e+=String.fromCharCode(parseInt(t.substring(s,s+2),16));return e}function f({args:t},e){return t=t?.map(r.evalE),e===r.Revert.ERROR&&d(t)&&32n===t[0].val?`"${p(t[2].val.toString(16))}"`:void 0}function v(t){switch(t.name){case"If":return i`(${t.condition})`;case"CallSite":return i`$${t.selector}();`;case"Require":{const e=t.selector===r.Revert.PANIC?"assert":"require",s=void 0===t.selector||t.selector===r.Revert.PANIC?t.args:[new r.Val(BigInt("0x"+t.selector)),...t.args],a=f(t,r.Revert.ERROR);return void 0!==a?i`${e}(${t.condition}, ${a});`:`${e}(${[t.condition,...s].map(h).join(", ")});`}default:return function(t){switch(t.name){case"Local":return i`${t.local.value.type} local${t.local.index} = ${t.local.value}; // #refs ${t.local.nrefs}`;case"MStore":return i`memory[${t.location}] = ${t.data};`;case"Stop":return"return;";case"Return":return void 0===t.args?i`return memory[${t.offset}:(${t.offset}+${t.size})];`:0===t.args.length?"return;":d(t.args)&&32n===t.args[0].val?`return '${p(t.args[2].val.toString(16))}';`:1===t.args.length?i`return ${t.args[0]};`:`return (${t.args.map(h).join(", ")});`;case"Revert":{const e=void 0!==t.selector?f(t,t.selector):void 0;return void 0!==e?`revert(${e});`:void 0===t.args?i`revert(memory[${t.offset}:(${t.offset}+${t.size})]);`:void 0!==t.selector?`revert ${function(t){if(void 0!==t)try{return(0,n.parseSig)(t).name}catch{return t}}(t.sig?.sig)??t.selector}(${t.args.map(h).join(", ")});`:`revert(${t.args.map(h).join(", ")});`}case"SelfDestruct":return i`selfdestruct(${t.address});`;case"Invalid":return`revert('Invalid instruction (0x${t.opcode.toString(16)})');`;case"Log":return t.eventName?`emit ${t.eventName}(${[...t.topics.slice(1),...t.args??[]].map(h).join(", ")});`:"log("+(void 0===t.args?[...t.topics,i`memory[${t.offset}:${t.size} ]`].join(", ")+"ii":[...t.topics,...t.args].map(h).join(", "))+");";case"Jump":return i`goto :${t.offset} branch:${t.destBranch.pc}`;case"Jumpi":return i`when ${t.cond} goto ${t.destBranch.pc} or fall ${t.fallBranch.pc}`;case"JumpDest":return`fall: ${t.fallBranch.pc}:`;case"SigCase":return i`case when ${t.condition} goto ${t.offset} or fall ${t.fallBranch.pc}`;case"SStore":{const e=t.slot.eval(),s=t=>"SLoad"===t.tag&&h(t.slot.eval())===h(e);let a=i`storage[${e}]`;e.isVal()&&void 0!==t.variable&&(a=t.variable.label||`var_${t.variable.index}`);const n=t.data.eval();return"Add"===n.tag&&s(n.left)?i`${a} += ${n.right};`:"Add"===n.tag&&s(n.right)?i`${a} += ${n.left};`:"Sub"===n.tag&&s(n.left)?i`${a} -= ${n.right};`:i`${a} = ${t.data};`}case"MappingStore":{let e=`mapping${t.location+1}`;return t.location in t.mappings&&t.mappings[t.location].name&&(e=t.mappings[t.location].name),"Add"===t.data.tag&&"MappingLoad"===t.data.right.tag&&t.data.right.location===t.location?e+t.items.map((t=>"["+h(t)+"]")).join("")+" += "+h(t.data.left)+";":"Add"===t.data.tag&&"MappingLoad"===t.data.left.tag&&t.data.left.location===t.location?e+t.items.map((t=>i`[${t}]`)).join("")+" += "+h(t.data.right)+";":"Sub"===t.data.tag&&"MappingLoad"===t.data.left.tag&&t.data.left.location===t.location?e+t.items.map((t=>i`[${t}]`)).join("")+" -= "+h(t.data.right)+";":e+t.items.map((t=>i`[${t}]`)).join("")+" = "+h(t.data)+";"}case"Throw":return`throw('${t.reason}');`}}(t)}}function g(t,e=0){let s="";for(const a of t)if(a instanceof r.If){const t=v(a);s+=" ".repeat(e)+"if "+t+" {\n",s+=g(a.trueBlock,e+4),a.falseBlock&&(s+=" ".repeat(e)+"} else {\n",s+=g(a.falseBlock,e+4)),s+=" ".repeat(e)+"}\n"}else{if("Local"===a.name&&a.local.nrefs<=0)continue;if("MStore"===a.name)continue;s+=" ".repeat(e)+v(a)+"\n"}return s}function m(t,e=0){let s="";for(const[a,n]of Object.entries(t)){if(s+=" ".repeat(e)+"event ",void 0===n.sig)s+=a;else{const t=n.sig.split("(")[0],e=n.sig.replace(t,"").substring(1).slice(0,-1);e?(s+=t+"(",s+=e.split(",").map(((t,e)=>e<n.indexedCount?`${t} indexed _arg${e}`:`${t} _arg${e}`)).join(", "),s+=")"):s+=n.sig}s+=";\n"}return s}function b(t){let e="";return[...t.entries()].forEach((([t,s],a)=>{const n=s.types.map((t=>t.isVal()?"uint256":t.type??"")).filter((t=>""!==t.trim()));0===n.length&&n.push("unknown");const r=s.label?` public ${s.label}`:` var${a+1}__${s.index}`;e+=` ${[...new Set(n)].join("|")+r}; // Slot #${t}\n`})),e}function w(t){let e="";return Object.keys(t).filter((e=>t[e].structs.length>0)).forEach((s=>{const a=t[s];e+=`struct ${a.name}Struct {\n`,a.structs.forEach((t=>{e+=` ${t.toString()};\n`})),e+="}\n\n"})),e}function y(t){let e="";return Object.keys(t).forEach(((a,n)=>{const r=t[a],o=r.name?`public ${r.name}`:`mapping${n+1}`;e+=` ${s(r)} ${o};\n`})),e;function s(t){const e=[],a=[];let n=!1;return t.keys.filter((t=>t.length>0)).forEach((r=>{const o=r[0];r.length>0&&o.type&&!e.includes(o.type)&&e.push(o.type),r.length>1&&!n?(n=!0,a.push(s({name:t.name,structs:t.structs,keys:t.keys.map((t=>t.slice(1))),values:t.values}))):1!==r.length||n||t.values.forEach((t=>{t.type&&!a.includes(t.type)&&a.push(t.type)}))})),0===e.length&&e.push("unknown"),t.structs.length>0&&0===a.length?a.push(`${t.name}Struct`):0===a.length&&a.push("unknown"),"mapping ("+e.join("|")+" => "+a.join("|")+")"}}function $(t,e=" "){let s=e+"function "+(void 0!==t.label?(0,n.fnsig)((0,n.parseSig)(t.label)):`${t.selector}(/*no signature*/)`)+" "+t.visibility;return t.constant&&(s+=" view"),t.payable&&(s+=" payable"),t.returns.length>0&&(s+=` returns (${t.returns.join(", ")})`),s+=" {\n",s+=g(t.stmts,8),s+=e+"}\n\n",s}e.solStmts=g,e.solEvents=m,e.solVars=b,e.solStructs=w,e.solMappings=y,a.Contract.prototype.solidify=function(t={}){const{license:e="UNLICENSED",pragma:s=!0,contractName:a="Contract"}=t;let n="";e&&(n+=`// SPDX-License-Identifier: ${e}\n`),s&&this.metadata&&(n+=`// Metadata ${this.metadata.url}\n`,n+=`pragma solidity ${this.metadata.solc};\n`,n+="\n"),n+=`contract ${a} {\n\n`;const o=t=>""===t?"":t+"\n";n+=o(m(this.events,4)),n+=w(this.mappings),n+=o(y(this.mappings)),n+=o(b(this.variables)),n+=o(function(t){let e="";for(const[s,a]of Object.entries(t))r.Revert.isRequireOrAssert(s)||(void 0===a.sig?e+=` // error ${s}\n`:e+=` error ${a.sig}; // ${s}\n`);return e}(this.reverts));const i=this.metadata?.minor>=6?"fallback":"function";n+=" ".repeat(4)+`${i}() external payable {\n`,n+=g(this.main,8),n+=" ".repeat(4)+"}\n\n";for(const[,t]of Object.entries(this.functions))n+=$(t);return n+="}\n",n},r.Tag.prototype.sol=function(){return h(this)}},360:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ExecError=e.State=e.Stack=void 0;class s{constructor(){this.values=[]}get top(){return this.values[0]}push(t){if(this.values.length>=1024)throw new n("Stack too deep");this.values.unshift(t)}pop(){if(0===this.values.length)throw new n("POP with empty stack");return this.values.shift()}swap(t){if(t<1||t>16)throw new n("Unsupported position for swap operation");if(!(t in this.values))throw new n("Position not found for swap operation,");const e=this.values[0],s=this.values[t];this.values[0]=s,this.values[t]=e}clone(){const t=new s;return t.values.push(...this.values),t}}e.Stack=s;class a{constructor(t=new s,e={},a=0){this.stack=t,this.memory=e,this.nlocals=a,this._halted=!1,this.stmts=[]}get halted(){return this._halted}get last(){return this.stmts.at(-1)}halt(t){if(this._halted)throw new n("State already halted");this.stmts.push(t),this._halted=!0}clone(){return new a(this.stack.clone(),{...this.memory},this.nlocals)}}e.State=a;class n extends Error{}e.ExecError=n},554:function(t,e,s){"use strict";var a=this&&this.__createBinding||(Object.create?function(t,e,s,a){void 0===a&&(a=s);var n=Object.getOwn