UNPKG

abstractionkit

Version:

Account Abstraction 4337 SDK by Candidelabs

1 lines 109 kB
var e=require("isomorphic-unfetch"),t=require("ethers");function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var n=/*#__PURE__*/r(e),a=function(e){this.accountAddress=void 0,this.accountAddress=e};function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return i(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},s.apply(null,arguments)}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function c(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function f(e){var t="function"==typeof Map?new Map:void 0;return f=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(l())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var a=new(e.bind.apply(e,n));return r&&d(a,r.prototype),a}(e,arguments,u(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},f(e)}a.proxyByteCode=void 0,a.initializerFunctionSelector=void 0,a.initializerFunctionInputAbi=void 0,a.executorFunctionSelector=void 0,a.executorFunctionInputAbi=void 0;var h,p,v,m="0x0000000000000000000000000000000000000000",A="0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",y="0x0000000071727De22E5E9d8BAf0edAc6f37da032",g="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",E={sender:m,nonce:0n,callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,signature:"0x"},S={SafeOp:[{type:"address",name:"safe"},{type:"uint256",name:"nonce"},{type:"bytes",name:"initCode"},{type:"bytes",name:"callData"},{type:"uint256",name:"callGasLimit"},{type:"uint256",name:"verificationGasLimit"},{type:"uint256",name:"preVerificationGas"},{type:"uint256",name:"maxFeePerGas"},{type:"uint256",name:"maxPriorityFeePerGas"},{type:"bytes",name:"paymasterAndData"},{type:"uint48",name:"validAfter"},{type:"uint48",name:"validUntil"},{type:"address",name:"entryPoint"}]},P={SafeOp:[{type:"address",name:"safe"},{type:"uint256",name:"nonce"},{type:"bytes",name:"initCode"},{type:"bytes",name:"callData"},{type:"uint128",name:"verificationGasLimit"},{type:"uint128",name:"callGasLimit"},{type:"uint256",name:"preVerificationGas"},{type:"uint128",name:"maxPriorityFeePerGas"},{type:"uint128",name:"maxFeePerGas"},{type:"bytes",name:"paymasterAndData"},{type:"uint48",name:"validAfter"},{type:"uint48",name:"validUntil"},{type:"address",name:"entryPoint"}]},b="0x0000000000000000000000000000000000000100";exports.Operation=void 0,(h=exports.Operation||(exports.Operation={}))[h.Call=0]="Call",h[h.Delegate=1]="Delegate",exports.GasOption=void 0,(p=exports.GasOption||(exports.GasOption={}))[p.Slow=1]="Slow",p[p.Medium=1.2]="Medium",p[p.Fast=1.5]="Fast",exports.PolygonChain=void 0,(v=exports.PolygonChain||(exports.PolygonChain={})).Mainnet="v2",v.ZkMainnet="zkevm",v.Amoy="amoy",v.Cardona="cardona";var D={"-32602":"INVALID_FIELDS","-32500":"SIMULATE_VALIDATION","-32501":"SIMULATE_PAYMASTER_VALIDATION","-32502":"OPCODE_VALIDATION","-32503":"EXPIRE_SHORTLY","-32504":"REPUTATION","-32505":"INSUFFICIENT_STAKE","-32506":"UNSUPPORTED_SIGNATURE_AGGREGATOR","-32507":"INVALID_SIGNATURE","-32601":"INVALID_USEROPERATION_HASH","-32521":"EXECUTION_REVERTED"},_=/*#__PURE__*/function(e){function t(t,r,n){var a;void 0===n&&(n={});var i=n.errno,o=n.context;return(a=e.call(this,r,{cause:n.cause})||this).code=void 0,a.context=void 0,a.errno=void 0,a.name=a.constructor.name,a.code=t,a.errno=i,a.context=o,a}return c(t,e),t.prototype.stringify=function(){return JSON.stringify(this,["name","code","message","cause","errno","context"])},t}(/*#__PURE__*/f(Error));function x(e){if(e instanceof Error)return e;var t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error("This value was thrown as is, not through an Error: "+t)}function T(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var F=function(e,t,r){try{var n,a,i=function(e){return[n,a]};void 0===r&&(r=exports.GasOption.Medium);var o=null!=t?Promise.resolve(U(t,r)).then(function(e){n=e[0],a=e[1]}):function(){if(null!=e)return Promise.resolve(w(e,r)).then(function(e){n=e[0],a=e[1]});throw new _("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden")}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}},R=function(e,t,r){try{var n=[t,r];return Promise.resolve(T(function(){return Promise.resolve(I(e,"eth_getCode",n)).then(function(e){if("string"!=typeof e)throw new _("BAD_DATA","eth_getCode returned ill formed data",{context:JSON.stringify(e)});try{return e}catch(e){var t=x(e);throw new _("BAD_DATA","eth_getCode returned ill formed data",{cause:t})}})},function(e){var t=x(e);throw new _("BAD_DATA","eth_getCode failed",{cause:t})}))}catch(e){return Promise.reject(e)}},G=function(e,t,r,n){try{var a;return a=null==n?[t,r]:[t,r,n],Promise.resolve(T(function(){return Promise.resolve(I(e,"eth_call",a)).then(function(e){if("string"!=typeof e)throw new _("BAD_DATA","eth_call returned ill formed data",{context:JSON.stringify(e)});try{return e}catch(e){var t=x(e);throw new _("BAD_DATA","eth_call returned ill formed data",{cause:t})}})},function(e){var t=x(e);throw new _("BAD_DATA","eth_call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},L=function(e,r,n){try{var a={from:"0x0000000000000000000000000000000000000000",to:n,data:B("0x5287ce12",["address"],[r])};return Promise.resolve(T(function(){return Promise.resolve(G(e,a,"latest")).then(function(e){var r=t.AbiCoder.defaultAbiCoder().decode(["uint256","bool","uint112","uint32","uint48"],e);if(5!==r.length)throw new _("BAD_DATA","getDepositInfo returned ill formed data",{context:JSON.stringify(r)});try{return{deposit:BigInt(r[0]),staked:Boolean(r[1]),stake:BigInt(r[2]),unstakeDelaySec:BigInt(r[3]),withdrawTime:BigInt(r[4])}}catch(e){var n=x(e);throw new _("BAD_DATA","getDepositInfo returned ill formed data",{cause:n})}})},function(e){var t=x(e);throw new _("BAD_DATA","getDepositInfo failed",{cause:t})}))}catch(e){return Promise.reject(e)}},C=function(e,t,r){return Promise.resolve(L(e,t,r)).then(function(e){return e.deposit})},U=function(e,t){try{void 0===t&&(t=exports.GasOption.Medium);var r="https://gasstation.polygon.technology/"+e;return Promise.resolve(T(function(){return Promise.resolve(fetch(r)).then(function(e){return Promise.resolve(e.json()).then(function(e){var r;r=t==exports.GasOption.Slow?e.safeLow:t==exports.GasOption.Medium?e.standard:e.fast;var n=BigInt(Math.ceil(1e9*Number(r.maxFee))),a=BigInt(Math.ceil(1e9*Number(r.maxPriorityFee)));return 0n==n&&(n=1n),0n==a&&(a=1n),[n,a]})})},function(e){var t=x(e);throw new _("BAD_DATA","fetching gas prices from "+r+" failed.",{cause:t})}))}catch(e){return Promise.reject(e)}},w=function(e,r){try{return void 0===r&&(r=exports.GasOption.Medium),Promise.resolve(T(function(){var n=new t.JsonRpcProvider(e);return Promise.resolve(n.getFeeData()).then(function(e){var t,n;return null!=e.maxFeePerGas&&null!=e.maxPriorityFeePerGas?(t=BigInt(Math.ceil(Number(e.maxFeePerGas)*r)),n=BigInt(Math.ceil(Number(e.maxPriorityFeePerGas)*r))):n=t=null!=e.gasPrice?BigInt(Math.ceil(Number(e.gasPrice)*r)):BigInt(Math.ceil(1e9*r)),0n==t&&(t=1n),0n==n&&(n=1n),[t,n]})},function(e){var t=x(e);throw new _("BAD_DATA","fetching gas prices from node failed.",{cause:t})}))}catch(e){return Promise.reject(e)}},O=function(e,t,r,n){void 0===n&&(n=0);try{var a=[{from:"0x0000000000000000000000000000000000000000",to:t,data:B(V("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(T(function(){return Promise.resolve(I(e,"eth_call",a)).then(function(e){if("string"!=typeof e)throw new _("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=x(e);throw new _("BAD_DATA","getNonce returned ill formed data",{cause:t})}})},function(e){var t=x(e);throw new _("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},I=function(e,t,r,a,i){void 0===a&&(a={"Content-Type":"application/json"}),void 0===i&&(i="params");try{var o,s=n.default||n,u={method:"POST",headers:a,body:JSON.stringify(((o={method:t})[i]=r,o.id=(new Date).getTime(),o.jsonrpc="2.0",o),function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t}),redirect:"follow"};return Promise.resolve(s(e,u)).then(function(t){return Promise.resolve(t.json()).then(function(t){if("result"in t)return t.result;if("simulation_results"in t)return t.simulation_results;var r=t.error,n=String(r.code);throw new _(n in D?D[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(u)}})})})}catch(e){return Promise.reject(e)}};function M(e,r,n){var a,i,o=t.AbiCoder.defaultAbiCoder();if(r.toLowerCase()==g.toLowerCase()){a=t.keccak256(function(e){var r=[e.sender,e.nonce,t.keccak256(e.initCode),t.keccak256(e.callData),e.callGasLimit,e.verificationGasLimit,e.preVerificationGas,e.maxFeePerGas,e.maxPriorityFeePerGas,t.keccak256(e.paymasterAndData)];return t.AbiCoder.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],r)}(e));var s=o.encode(["bytes32","address","uint256"],[a,r,n]);i=t.keccak256(s)}else if(r.toLowerCase()==y.toLowerCase()){a=t.keccak256(function(e){var r=t.AbiCoder.defaultAbiCoder(),n="0x";null!=e.factory&&(n=e.factory,null!=e.factoryData&&(n+=e.factoryData.slice(2)));var a="0x"+r.encode(["uint128"],[e.verificationGasLimit]).slice(34)+r.encode(["uint128"],[e.callGasLimit]).slice(34),i="0x"+r.encode(["uint128"],[e.maxPriorityFeePerGas]).slice(34)+r.encode(["uint128"],[e.maxFeePerGas]).slice(34),o="0x";null!=e.paymaster&&(o=e.paymaster,null!=e.paymasterVerificationGasLimit&&(o+=r.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(o+=r.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(o+=e.paymasterData.slice(2)));var s=[e.sender,e.nonce,t.keccak256(n),t.keccak256(e.callData),a,e.preVerificationGas,i,t.keccak256(o)];return r.encode(["address","uint256","bytes32","bytes32","bytes32","uint256","bytes32","bytes32"],s)}(e));var u=o.encode(["bytes32","address","uint256"],[a,r,n]);i=t.keccak256(u)}else{a=t.keccak256(function(e){var r=t.AbiCoder.defaultAbiCoder(),n="0x";if(null!=e.factory){var a=e.eip7702Auth;n=null!=a&&null!=a.address?a.address:e.factory,null!=e.factoryData&&(n+=e.factoryData.slice(2))}var i="0x"+r.encode(["uint128"],[e.verificationGasLimit]).slice(34)+r.encode(["uint128"],[e.callGasLimit]).slice(34),o="0x"+r.encode(["uint128"],[e.maxPriorityFeePerGas]).slice(34)+r.encode(["uint128"],[e.maxFeePerGas]).slice(34),s="0x";null!=e.paymaster&&(s=e.paymaster,null!=e.paymasterVerificationGasLimit&&(s+=r.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(s+=r.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(s+=e.paymasterData.slice(2)));var u=["0x29a0bca4af4be3421398da00295e58e6d7de38cb492214754cb6a47507dd6f8e",e.sender,e.nonce,t.keccak256(n),t.keccak256(e.callData),i,e.preVerificationGas,o,t.keccak256(s)];return r.encode(["bytes32","address","uint256","bytes32","bytes32","bytes32","uint256","bytes32","bytes32"],u)}(e));var c=function(e){var r=t.AbiCoder.defaultAbiCoder().encode(["(bytes32,bytes32,bytes32,uint256,address)"],[["0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f","0x364da28a5c92bcc87fe97c8813a6c6b8a3a049b0ea0a328fcb0b4f0e00337586","0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6",e,A]]);return t.keccak256(r)}(n);i=t.keccak256("0x1901"+c.slice(2)+a.slice(2))}return i}function B(e,r,n){return e+t.AbiCoder.defaultAbiCoder().encode(r,n).slice(2)}function V(e){return t.id(e).slice(0,10)}function N(e){var t,r;return"initCode"in e?(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas:(e.verificationGasLimit+e.callGasLimit+(null!=(t=e.paymasterVerificationGasLimit)?t:0n)+(null!=(r=e.paymasterPostOpGasLimit)?r:0n)+e.preVerificationGas)*e.maxFeePerGas}var k="0x04";function W(e,r,n,a,i,o,s,u){if(e>=Math.pow(2,64))throw RangeError("Invalide chainId.");if(r>=Math.pow(2,64))throw RangeError("Invalide nonce.");if(42!=i.length)throw RangeError("Invalide destination.");var c=[X(r),X(n),X(a),i,X(o),s,X(e),X(0n),X(0n)],l=t.keccak256(t.encodeRlp(c)),d=new t.Wallet(u).signingKey.sign(l);return c=[X(r),X(n),X(a),i,X(o),s,X(BigInt(d.yParity+2*Number(e)+35)),t.getBytes(d.r),t.getBytes(d.s)],t.encodeRlp(c)}function j(e,t,r,n){var a=z(H(e,t,r),n);return{chainId:q(e),address:t,nonce:q(r),yParity:q(BigInt(a.yParity)),r:q(a.r),s:q(a.s)}}function H(e,r,n){var a=[X(e),r,X(n)],i=t.encodeRlp(a);return t.keccak256("0x05"+i.slice(2))}function z(e,r){var n=new t.Wallet(r).signingKey.sign(e);return{yParity:n.yParity,r:BigInt(n.r),s:BigInt(n.s)}}function Y(e,r,n,a,i,o,s,u,c,l,d){var f=J(e,r,n,a,i,o,s,u,c,l),h=K(e,r,n,a,i,o,s,u,c,l),p=z(f,d),v=h.concat([X(BigInt(p.yParity)),X(p.r),X(p.s)]),m=t.encodeRlp(v);return k+m.slice(2)}function J(e,r,n,a,i,o,s,u,c,l){var d=K(e,r,n,a,i,o,s,u,c,l);return t.keccak256(k+t.encodeRlp(d).slice(2))}function K(e,r,n,a,i,s,u,c,l,d){if(e>=Math.pow(2,64))throw RangeError("Invalide chainId.");if(r>=Math.pow(2,64))throw RangeError("Invalide nonce.");if(42!=s.length)throw RangeError("Invalide destination.");var f=function(e){for(var t,r=[],n=o(e);!(t=n()).done;){var a=t.value;if(42!=a.address.length)throw RangeError("Invalide authorization list address: "+a);var i=[X(a.chainId),a.address,X(a.nonce),X(BigInt(a.yParity)),X(a.r),X(a.s)];r.push(i)}return r}(d),h=function(e){for(var r,n=[],a=o(e);!(r=a()).done;){var i=r.value,s=i[0],u=i[1];if(42!=s.length)throw RangeError("Invalide access list address: "+s);for(var c,l=[],d=o(u);!(c=d()).done;){var f=c.value;if(66!=f.length)throw RangeError("Invalide access list storage: "+f);l.push(t.getBytes(f))}n.push([t.getBytes(s),l])}return n}(l);return[X(e),X(r),X(n),X(a),X(i),s,X(u),c,h,f]}function X(e){return t.getBytes(t.toBeArray(e))}function q(e){var t=e.toString(16);return t.length%2?"0x0"+t:"0x"+t}function Z(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var $=/*#__PURE__*/function(){function e(e){this.rpcUrl=void 0,this.rpcUrl=e}var t=e.prototype;return t.chainId=function(){try{var e=this;return Promise.resolve(Z(function(){return Promise.resolve(I(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new _("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=x(e);throw new _("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.supportedEntryPoints=function(){try{var e=this;return Promise.resolve(Z(function(){return Promise.resolve(I(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=x(e);throw new _("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.estimateUserOperationGas=function(e,t,r){try{var n=this;return Promise.resolve(Z(function(){function a(){var e=i;return{callGasLimit:BigInt(e.callGasLimit),preVerificationGas:BigInt(e.preVerificationGas),verificationGasLimit:BigInt(e.verificationGasLimit)}}var i={},o=void 0===r?Promise.resolve(I(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){i=e}):Promise.resolve(I(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){i=e});return o&&o.then?o.then(a):a()},function(e){var t=x(e);throw new _("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.sendUserOperation=function(e,t){try{var r=this;return Promise.resolve(Z(function(){return Promise.resolve(I(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=x(e);throw new _("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.getUserOperationReceipt=function(e){try{var t=this;return Promise.resolve(Z(function(){return Promise.resolve(I(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=s({},t.receipt,{blockNumber:BigInt(t.receipt.blockNumber),cumulativeGasUsed:BigInt(t.receipt.cumulativeGasUsed),gasUsed:BigInt(t.receipt.gasUsed),transactionIndex:BigInt(t.receipt.transactionIndex),effectiveGasPrice:null==t.receipt.effectiveGasPrice?void 0:BigInt(t.receipt.effectiveGasPrice),logs:JSON.stringify(t.receipt.logs)});return s({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:r})}return null})},function(t){var r=x(t);throw new _("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},t.getUserOperationByHash=function(e){try{var t=this;return Promise.resolve(Z(function(){return Promise.resolve(I(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?s({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=x(t);throw new _("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},e}();function Q(e,t,r){if(!e.s){if(r instanceof ee){if(!r.s)return void(r.o=Q.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Q.bind(null,e,t),Q.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var ee=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,a=this.s;if(a){var i=1&a?t:r;if(i){try{Q(n,1,i(this.v))}catch(e){Q(n,2,e)}return n}return this}return this.o=function(e){try{var a=e.v;1&e.s?Q(n,1,t?t(a):a):r?Q(n,1,r(a)):Q(n,2,a)}catch(e){Q(n,2,e)}},n},e}();function te(e){return e instanceof ee&&1&e.s}var re=/*#__PURE__*/function(){function e(e,t,r){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=r}var t=e.prototype;return t.delay=function(e){return new Promise(function(t){return setTimeout(t,e)})},t.included=function(e,t){void 0===e&&(e=180),void 0===t&&(t=2);try{var r,n=function(e){if(r)return e;throw new _("TIMEOUT","can't find useroperation",{context:a.userOperationHash})},a=this;if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");var i=0,o=function(e,t,r){for(var n;;){var a=e();if(te(a)&&(a=a.v),!a)return i;if(a.then){n=0;break}var i=r();if(i&&i.then){if(!te(i)){n=1;break}i=i.s}}var o=new ee,s=Q.bind(null,o,2);return(0===n?a.then(c):1===n?i.then(u):(void 0).then(function(){(a=e())?a.then?a.then(c).then(void 0,s):c(a):Q(o,1,i)})).then(void 0,s),o;function u(t){i=t;do{if(!(a=e())||te(a)&&!a.v)return void Q(o,1,i);if(a.then)return void a.then(c).then(void 0,s);te(i=r())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,s)}function c(e){e?(i=r())&&i.then?i.then(u).then(void 0,s):u(i):Q(o,1,i)}}(function(){return!r&&i<=e},0,function(){return Promise.resolve(a.delay(1e3*t)).then(function(){return Promise.resolve(a.bundler.getUserOperationReceipt(a.userOperationHash)).then(function(e){if(null!=e)return r=1,e;i++})})});return Promise.resolve(o&&o.then?o.then(n):n(o))}catch(e){return Promise.reject(e)}},e}(),ne=/*#__PURE__*/function(e){function r(t,n){var a,i;return void 0===n&&(n={}),(i=e.call(this,t)||this).entrypointAddress=void 0,i.entrypointAddress=null!=(a=n.entrypointAddress)?a:r.DEFAULT_ENTRYPOINT_ADDRESS,i}c(r,e),r.createAccountCallData=function(e,t,n){return B(r.executorFunctionSelector,r.executorFunctionInputAbi,[e,t,n])},r.createAccountCallDataSingleTransaction=function(e){var t,n,a=null!=(t=e.value)?t:0,i=null!=(n=e.data)?n:"0x";return r.createAccountCallData(e.to,a,i)},r.createAccountCallDataBatchTransactions=function(e){var t=[e.map(function(e){return[e.to,e.value,e.data]})];return B(r.batchExecutorFunctionSelector,r.batchExecutorFunctionInputAbi,t)};var n=r.prototype;return n.createUserOperation=function(e,t,n,a){void 0===a&&(a={});try{var i=function(t){var i,c,f,h,p,y;function g(e){var t,r,n,i,o,s;if("bigint"==typeof a.preVerificationGas&&a.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof a.verificationGasLimit&&a.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof a.callGasLimit&&a.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return p.preVerificationGas=null!=(t=a.preVerificationGas)?t:T*BigInt(Math.floor(((null!=(r=a.preVerificationGasPercentageMultiplier)?r:0)+100)/100)),p.verificationGasLimit=null!=(n=a.verificationGasLimit)?n:F*BigInt(Math.floor(((null!=(i=a.verificationGasLimitPercentageMultiplier)?i:0)+100)/100)),p.callGasLimit=null!=(o=a.callGasLimit)?o:R*BigInt(Math.floor(((null!=(s=a.callGasLimitPercentageMultiplier)?s:0)+100)/100)),p}if(l=null!=(i=a.maxFeePerGas)?i:l*BigInt(Math.floor(((null!=(c=a.maxFeePerGasPercentageMultiplier)?c:0)+100)/100)),d=null!=(f=a.maxPriorityFeePerGas)?f:d*BigInt(Math.floor(((null!=(h=a.maxPriorityFeePerGasPercentageMultiplier)?h:0)+100)/100)),null==u)throw RangeError("failed to determine nonce");if(u<0n)throw RangeError("nonce can't be negative");if(y=null==a.callData?1==e.length?r.createAccountCallDataSingleTransaction(e[0]):r.createAccountCallDataBatchTransactions(e):a.callData,null!=a.eip7702Auth){var S,P,b,D=null!=(S=a.eip7702Auth.yParity)?S:"0x0";if("0x0"!=D&&"0x00"!=D&&"0x1"!=D&&"0x01"!=D)throw new _("BAD_DATA","invalide yParity value for eoaDelegatorSignature. must be '0x0' or '0x1'");var x={chainId:q(v),address:m,nonce:q(A),yParity:D,r:null!=(P=a.eip7702Auth.r)?P:"0x4277ba564d2c138823415df0ec8e8f97f30825056d54ec5128a8b29ec2dd81b2",s:null!=(b=a.eip7702Auth.s)?b:"0x1075a1bec7f59848cca899ece93075199cd2aabceb0654b9ae00b881a30044cd"};p=s({},E,{sender:o.accountAddress,nonce:u,callData:y,maxFeePerGas:l,maxPriorityFeePerGas:d,factory:"0x7702",factoryData:null,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null,eip7702Auth:x})}else p=s({},E,{sender:o.accountAddress,nonce:u,callData:y,maxFeePerGas:l,maxPriorityFeePerGas:d,factory:null,factoryData:null,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null,eip7702Auth:null});var T=E.preVerificationGas,F=E.verificationGasLimit,R=E.callGasLimit,G=function(){if(null==a.preVerificationGas||null==a.verificationGasLimit||null==a.callGasLimit)return function(){if(null!=n){var e;p.callGasLimit=0n,p.verificationGasLimit=0n,p.preVerificationGas=0n;var t,i=p.maxFeePerGas,u=p.maxPriorityFeePerGas;return p.maxFeePerGas=0n,p.maxPriorityFeePerGas=0n,t=s({},p),p.signature=null!=(e=a.dummySignature)?e:r.dummySignature,Promise.resolve(o.estimateUserOperationGas(t,n,{stateOverrideSet:a.state_override_set})).then(function(e){T=e[0],F=e[1],R=e[2],F+=55000n,p.maxFeePerGas=i,p.maxPriorityFeePerGas=u})}throw new _("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return G&&G.then?G.then(g):g()},o=this;if(e.length<1)throw RangeError("There should be at least one transaction");var u=null,c=null;if(null==a.nonce){if(null==t)throw new _("BAD_DATA","providerRpc cant't be null if nonce is not overriden");c=O(t,o.entrypointAddress,o.accountAddress)}else u=a.nonce;if("bigint"==typeof a.maxFeePerGas&&a.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof a.maxPriorityFeePerGas&&a.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");var l=E.maxFeePerGas,d=E.maxPriorityFeePerGas,f=null;null!=a.maxFeePerGas&&null!=a.maxPriorityFeePerGas||(f=F(t,a.polygonGasStation,a.gasLevel));var h,p,v=null,m=null,A=null;null!=a.eip7702Auth&&(v=a.eip7702Auth.chainId,m=null!=(h=a.eip7702Auth.address)?h:r.DEFAULT_DELEGATEE_ADDRESS,A=null!=(p=a.eip7702Auth.nonce)?p:null);var y=function(){if(null!=a.eip7702Auth&&null==A){var e;if(null==t)throw new _("BAD_DATA","providerRpc cant't be null if eoaDelegatorNonce is not overriden");e=I(t,"eth_getTransactionCount",[o.accountAddress,"latest"]);var r=function(){if(null!=f&&null!=c)return Promise.resolve(Promise.all([e,c,f]).then(function(e){A=BigInt(e[0]),u=e[1];var t=e[2];l=t[0],d=t[1]})).then(function(){});var t=function(){if(null!=f)return Promise.resolve(Promise.all([e,f]).then(function(e){A=BigInt(e[0]);var t=e[1];l=t[0],d=t[1]})).then(function(){});var t=function(){if(null!=c)return Promise.resolve(Promise.all([e,f]).then(function(e){A=BigInt(e[0]),u=e[1]})).then(function(){});var t=BigInt;return Promise.resolve(e).then(function(e){A=t(e)})}();return t&&t.then?t.then(function(){}):void 0}();return t&&t.then?t.then(function(){}):void 0}();if(r&&r.then)return r.then(function(){})}else{var n=function(){if(null!=f&&null!=c)return Promise.resolve(Promise.all([c,f]).then(function(e){u=e[0];var t=e[1];l=t[0],d=t[1]})).then(function(){});var e=function(){if(null!=f)return Promise.resolve(f).then(function(e){l=e[0],d=e[1]});var e=function(){if(null!=c)return Promise.resolve(c).then(function(e){u=e})}();return e&&e.then?e.then(function(){}):void 0}();return e&&e.then?e.then(function(){}):void 0}();if(n&&n.then)return n.then(function(){})}}();return Promise.resolve(y&&y.then?y.then(i):i())}catch(e){return Promise.reject(e)}},n.estimateUserOperationGas=function(e,t,n){void 0===n&&(n={});try{var a;e.signature=null!=(a=n.dummySignature)?a:r.dummySignature;var i=new $(t),o=e.maxFeePerGas,s=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(i.estimateUserOperationGas(e,this.entrypointAddress,n.stateOverrideSet)).then(function(t){return e.maxFeePerGas=o,e.maxPriorityFeePerGas=s,[BigInt(t.preVerificationGas),BigInt(t.verificationGasLimit),BigInt(t.callGasLimit)]})}catch(e){return Promise.reject(e)}},n.signUserOperation=function(e,r,n){var a=M(e,this.entrypointAddress,n);return new t.Wallet(r).signingKey.sign(a).serialized},n.sendUserOperation=function(e,t){try{var r=this,n=new $(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new re(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},n.prependTokenPaymasterApproveToCallData=function(e,t,n,a){return r.prependTokenPaymasterApproveToCallDataStatic(e,t,n,a)},r.prependTokenPaymasterApproveToCallDataStatic=function(e,n,a,i){var o,s={to:n,value:0n,data:B(V("approve(address,uint256)"),["address","uint256"],[a,i])},u=t.AbiCoder.defaultAbiCoder();if(e.startsWith(r.batchExecutorFunctionSelector))o=u.decode(r.batchExecutorFunctionInputAbi,"0x"+e.slice(10))[0].map(function(e){return{to:e[0],value:BigInt(e[1]),data:"string"!=typeof e[2]?(new TextDecoder).decode(e[2]):e[2]}});else{if(!e.startsWith(r.executorFunctionSelector))throw new _("BAD_DATA","Invalid calldata, should start with "+r.batchExecutorFunctionSelector+" or "+r.executorFunctionSelector,{context:{callData:e}});var c=u.decode(r.executorFunctionInputAbi,"0x"+e.slice(10));o=[{to:c[0],value:BigInt(c[1]),data:"string"!=typeof c[2]?(new TextDecoder).decode(c[2]):c[2]}]}return o.unshift(s),r.createAccountCallDataBatchTransactions(o)},r}(a);ne.DEFAULT_DELEGATEE_ADDRESS="0xe6Cae83BdE06E4c305530e199D7217f42808555B",ne.DEFAULT_ENTRYPOINT_ADDRESS=A,ne.executorFunctionSelector="0xb61d27f6",ne.executorFunctionInputAbi=["address","uint256","bytes"],ne.batchExecutorFunctionSelector="0x34fcd5be",ne.batchExecutorFunctionInputAbi=["(address,uint256,bytes)[]"],ne.dummySignature="0xd2614025fc173b86704caf37b2fb447f7618101a0d31f5f304c777024cef38a060a29ee43fcf0c46f9107d4f670b8a85c2c017a1fe9e4af891f24f0be6ba5d671c";var ae,ie=function(e,t,r,n){try{var a="https://api.tenderly.co/api/v1/account/"+e+"/project/"+t+"/simulate-bundle",i=n.map(function(e){var t,r,n,a={network_id:e.chainId.toString(),save:null==(t=e.save)||t,save_if_fails:null==(r=e.saveIfFails)||r,from:e.from,to:e.to,input:e.data,simulation_type:null!=(n=e.simulationType)?n:"quick"};return null!=e.blockNumber&&(a.block_number=e.blockNumber),null!=e.gas&&(a.gas=e.gas),null!=e.gasPrice&&(a.gas_price=e.gasPrice),null!=e.value&&(a.value=e.value),null!=e.stateOverride&&(a.state_objects=e.stateOverride),null!=e.transactionIndex&&(a.transaction_index=e.transactionIndex),null!=e.estimateGas&&(a.estimate_gas=e.estimateGas),null!=e.generateAccessList&&(a.generate_access_list=e.generateAccessList),null!=e.accessList&&(a.access_list=e.accessList),a});return Promise.resolve(I(a,"tenderly_simulateBundle",i,{Accept:"application/json","Content-Type":"application/json","X-Access-Key":r},"simulations"))}catch(e){return Promise.reject(e)}},oe=function(e,t,r,n,a,i,o,s,u,c){void 0===s&&(s=null),void 0===u&&(u=null),void 0===c&&(c=null);try{var l,d=[],f=a.toLowerCase();if("0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"==f)l="0x7fc98430eaedbb6070b35b39d798725049088348";else if("0x0000000071727de22e5e9d8baf0edac6f37da032"==f)l="0xefc2c1444ebcc4db75e7613d20c6a62ff67a167c";else{if("0x4337084d9e255ff0702461cf8895ce9e3b5ff108"!=f)throw RangeError("Invalid entrypoint: "+a);l="0x449ed7c3e6fee6a97311d4b55475df59c44add33"}if(null==s&&null!=u||null!=s&&null==u)throw RangeError("Invalid factory and factoryData");return null!=s&&null!=u&&d.push({chainId:n,blockNumber:c,from:l,to:s,data:u}),d.push({chainId:n,blockNumber:c,from:a,to:i,data:o}),Promise.resolve(ie(e,t,r,d))}catch(e){return Promise.reject(e)}},se=function(e,t,r,n,a,i,o,s,u,c){return void 0===s&&(s=null),void 0===u&&(u=null),void 0===c&&(c=null),Promise.resolve(oe(e,t,r,n,a,i,o,s,u,c)).then(function(n){var a=n.map(function(e){return e.simulation.id});a.map(function(n){return de(e,t,r,n)});var i=a.map(function(e){return"https://dashboard.tenderly.co/shared/simulation/"+e});if(1==i.length)return{simulation:n,callDataSimulationShareLink:i[0]};if(2==i.length)return{simulation:n,accountDeploymentSimulationShareLink:i[0],callDataSimulationShareLink:i[1]};throw new _("BAD_DATA","invalid number of simulations retuned",{context:JSON.stringify(n,function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t})})})},ue=function(e,t,r,n,a,i,o){void 0===o&&(o=null);try{var s=null,u=null;return"initCode"in i?i.initCode.length>2&&(s=i.initCode.slice(0,22),u=i.initCode.slice(22)):(s=i.factory,u=i.factoryData),Promise.resolve(oe(e,t,r,n,a,i.sender,i.callData,s,u,o))}catch(e){return Promise.reject(e)}},ce=function(e,r,n,a,i,o,s){void 0===s&&(s=null);try{var u=i.toLowerCase(),c=null,l=t.AbiCoder.defaultAbiCoder();if("initCode"in o&&"0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"==u)c="0x1fad948c"+l.encode(["(address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[]","address"],[[[o.sender,o.nonce,o.initCode,o.callData,o.callGasLimit,o.verificationGasLimit,o.preVerificationGas,o.maxFeePerGas,o.maxPriorityFeePerGas,o.paymasterAndData,o.signature]],"0x1000000000000000000000000000000000000000"]).slice(2);else{var d="0x";null!=o.factory&&(d=o.factory,null!=o.factoryData&&(d+=o.factoryData.slice(2)));var f="0x"+l.encode(["uint128"],[o.verificationGasLimit]).slice(34)+l.encode(["uint128"],[o.callGasLimit]).slice(34),h="0x"+l.encode(["uint128"],[o.maxPriorityFeePerGas]).slice(34)+l.encode(["uint128"],[o.maxFeePerGas]).slice(34),p="0x";null!=o.paymaster&&(p=o.paymaster,null!=o.paymasterVerificationGasLimit&&(p+=l.encode(["uint128"],[o.paymasterVerificationGasLimit]).slice(34)),null!=o.paymasterPostOpGasLimit&&(p+=l.encode(["uint128"],[o.paymasterPostOpGasLimit]).slice(34)),null!=o.paymasterData&&(p+=o.paymasterData.slice(2)));var v=l.encode(["(address,uint256,bytes,bytes,bytes32,uint256,bytes32,bytes,bytes)[]","address"],[[[o.sender,o.nonce,d,o.callData,f,o.preVerificationGas,h,p,o.signature]],"0x1000000000000000000000000000000000000000"]);if("0x0000000071727de22e5e9d8baf0edac6f37da032"!=u&&"0x4337084d9e255ff0702461cf8895ce9e3b5ff108"!=u)throw RangeError("Invalid entrypoint.");c="0x765e827f"+v.slice(2)}return Promise.resolve(ie(e,r,n,[{chainId:a,blockNumber:s,from:"0x1000000000000000000000000000000000000000",to:i,data:c}])).then(function(e){return e[0]})}catch(e){return Promise.reject(e)}},le=function(e,t,r,n,a,i,o){return void 0===o&&(o=null),Promise.resolve(ce(e,t,r,n,a,i,o)).then(function(n){return Promise.resolve(de(e,t,r,n.simulation.id)).then(function(){return{simulation:n,simulationShareLink:"https://dashboard.tenderly.co/shared/simulation/"+n.simulation.id}})})},de=function(e,t,r,a){try{return Promise.resolve((n.default||n)("https://api.tenderly.co/api/v1/account/"+e+"/project/"+t+"/simulations/"+a+"/share",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Access-Key":r},redirect:"follow"})).then(function(n){var i=n.status;if(204!=i)throw new _("BAD_DATA","tenderly share simulation failed.",{context:{tenderlyAccountSlug:e,tenderlyProjectSlug:t,tenderlyAccessKey:r,tenderlySimulationId:a,status:i}})})}catch(e){return Promise.reject(e)}};exports.SafeModuleExecutorFunctionSelector=void 0,(ae=exports.SafeModuleExecutorFunctionSelector||(exports.SafeModuleExecutorFunctionSelector={})).executeUserOpWithErrorString="0x541d63c8",ae.executeUserOp="0x7bb37428";var fe={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x47003599ffa7e9198f321afa774e34a12a959844efd6363b88896e9c24ed33cf4e1be876ef123a3c4467e7d451511434039539699f2baa2f44955fa3d1c1c6d81c",isContractSignature:!1},he={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e06c92f0ac5c4ef9e74721c23d80a9fc12f259ca84afb160f0890483539b9e6080d824c0e6c795157ad5d1ee5eff1ceeb3031009a595f9360919b83dd411c5a78d0000000000000000000000000000000000000000000000000000000000000025a24f744b28d73f066bf3203d145765a7bc735e6328168c8b03e476da3ad0d8fe0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e226f726967696e223a2268747470733a2f2f736166652e676c6f62616c220000",isContractSignature:!0};function pe(e){return"0x"+e.map(function(e){return a=null!=(n=(r=e).operation)?n:exports.Operation.Call,i=t.getBytes(r.data),t.solidityPacked(["uint8","address","uint256","uint256","bytes"],[a,r.to,r.value,i.length,i]).slice(2);var r,n,a,i}).join("")}var ve=/*#__PURE__*/function(){function e(e,t,r){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=r}return e.prototype.getFactoryGeneratorFunctionCallData=function(e){return B(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e)},e}(),me=/*#__PURE__*/function(e){function t(r){return void 0===r&&(r=t.DEFAULT_FACTORY_ADDRESS),e.call(this,r,"0x1688f0b9",["address","bytes","uint256"])||this}return c(t,e),t}(ve);function Ae(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}me.DEFAULT_FACTORY_ADDRESS="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67";var ye=/*#__PURE__*/function(e){function r(r,n,a,i){var o;if(void 0===i&&(i={}),(o=e.call(this,r)||this).isInitWebAuthn=void 0,o.x=null,o.y=null,o.entrypointAddress=void 0,o.safe4337ModuleAddress=void 0,o.factoryAddress=void 0,o.factoryData=void 0,o.onChainIdentifier=void 0,o.entrypointAddress=a,o.safe4337ModuleAddress=n,o.factoryAddress=null,o.factoryData=null,o.isInitWebAuthn=!1,null!=i.onChainIdentifierParams&&null!=i.onChainIdentifier)throw RangeError("can't override both onChainIdentifier and onChainIdentifierParams");if(null!=i.onChainIdentifierParams)o.onChainIdentifier=function(e,r,n,a){void 0===r&&(r="Web"),void 0===n&&(n="abstractionkit"),void 0===a&&(a="0.2.21");var i=t.keccak256("0x"+Buffer.from(e,"utf8").toString("hex")).slice(-20),o=t.keccak256("0x"+Buffer.from(r,"utf8").toString("hex")).slice(-3),s=t.keccak256("0x"+Buffer.from(n,"utf8").toString("hex")).slice(-3),u=t.keccak256("0x"+Buffer.from(a,"utf8").toString("hex")).slice(-3);return"5afe00"+Buffer.from(i,"utf8").toString("hex")+Buffer.from(o,"utf8").toString("hex")+Buffer.from(s,"utf8").toString("hex")+Buffer.from(u,"utf8").toString("hex")}(i.onChainIdentifierParams.project,i.onChainIdentifierParams.platform,i.onChainIdentifierParams.tool,i.onChainIdentifierParams.toolVersion);else if(null!=i.onChainIdentifier){var s=i.onChainIdentifier;if(s.startsWith("0x")&&(s=s.slice(2)),64!=s.length)throw RangeError("onChainIdentifier length must be 64.");o.onChainIdentifier=s}else o.onChainIdentifier=null;return o}c(r,e),r.createProxyAddress=function(e,n){var a,i,o;void 0===n&&(n={});var s=null!=(a=n.c2Nonce)?a:0n;if(s<0n)throw RangeError("c2Nonce can't be negative");var u=null!=(i=n.safeFactoryAddress)?i:me.DEFAULT_FACTORY_ADDRESS,c=null!=(o=n.singletonInitHash)?o:r.DEFAULT_SAFE_SINGLETON.singletonInitHash,l=t.keccak256(t.solidityPacked(["bytes32","uint256"],[t.keccak256(e),s])),d=t.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",u,l,c]).slice(-40);return t.getAddress("0x"+d)},r.createAccountCallDataSingleTransaction=function(e,t){var n,a,i,o;void 0===t&&(t={});var s=null!=(n=e.value)?n:0,u=null!=(a=e.data)?a:"0x",c=null!=(i=e.operation)?i:exports.Operation.Call,l=null!=(o=t.safeModuleExecutorFunctionSelector)?o:r.DEFAULT_EXECUTOR_FUCNTION_SELECTOR;return r.createAccountCallData(e.to,s,u,c,{safeModuleExecutorFunctionSelector:l})},r.createAccountCallDataBatchTransactions=function(e,t){var n,a;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one metaTransaction");var i=null!=(n=t.safeModuleExecutorFunctionSelector)?n:r.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,o=null!=(a=t.multisendContractAddress)?a:r.DEFAULT_MULTISEND_CONTRACT_ADDRESS,s=B("0x8d80ff0a",["bytes"],[pe(e)]);return r.createAccountCallData(o,0n,s,exports.Operation.Delegate,{safeModuleExecutorFunctionSelector:i})},r.createAccountCallData=function(e,t,n,a,i){var o;return void 0===i&&(i={}),B(null!=(o=i.safeModuleExecutorFunctionSelector)?o:r.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,r.executorFunctionInputAbi,[e,t,n,a])},r.decodeAccountCallData=function(e){var r=null;if(e.startsWith(exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString)?r=exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString:e.startsWith(exports.SafeModuleExecutorFunctionSelector.executeUserOp)&&(r=exports.SafeModuleExecutorFunctionSelector.executeUserOp),null!=r){var n,a=t.AbiCoder.defaultAbiCoder(),i="0x"+e.slice(10),o=a.decode(["address","uint256","bytes","uint8"],i);return n="string"!=typeof o[2]?(new TextDecoder).decode(o[2]):o[2],[{to:o[0],value:BigInt(o[1]),data:n,operation:Number(o[3])},r]}throw new _("BAD_DATA","Invalid calldata, should start with "+exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString+" or "+exports.SafeModuleExecutorFunctionSelector.executeUserOp,{context:{callData:e}})},r.prependTokenPaymasterApproveToCallDataStatic=function(e,n,a,i,o){var s;void 0===o&&(o={});var u=null!=(s=o.multisendContractAddress)?s:r.DEFAULT_MULTISEND_CONTRACT_ADDRESS,c=r.decodeAccountCallData(e),l=c[0],d=c[1],f=pe([{to:n,value:0n,data:B(V("approve(address,uint256)"),["address","uint256"],[a,i]),operation:exports.Operation.Call}]),h="",p="0x8d80ff0a";if(l.data.startsWith(p)){var v=function(e){return t.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(l.data);h=v+f.slice(2)}else h=pe([l])+f.slice(2);var m=B(p,["bytes"],[h]);return r.createAccountCallData(u,0n,m,exports.Operation.Delegate,{safeModuleExecutorFunctionSelector:d})},r.formatEip712SignaturesToUseroperationSignature=function(e,t,n){var a,i;if(void 0===n&&(n={}),e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");var o=null!=(a=n.validAfter)?a:0n,s=null!=(i=n.validUntil)?i:0n,u=new Map;e.forEach(function(e,r){u.set(e.toLocaleLowerCase(),t[r])});var c=new Map(Array.from(u).sort()),l="0x"+Array.from(c.values()).reduce(function(e,t){return e+t.slice(2)},"");return r.formatEip712SingleSignatureToUseroperationSignature(l,{validAfter:o,validUntil:s})},r.getUserOperationEip712Hash=function(e,t,n){return void 0===n&&(n={}),"initCode"in e?r.getUserOperationEip712Hash_V6(e,t,n):r.getUserOperationEip712Hash_V7(e,t,n)},r.getUserOperationEip712Data=function(e,t,n){if("initCode"in e){var a=r.getUserOperationEip712Data_V6(e,t,n);return{domain:a.domain,types:a.types,messageValue:a.messageValue}}var i=r.getUserOperationEip712Data_V7(e,t,n);return{domain:i.domain,types:i.types,messageValue:i.messageValue}},r.getUserOperationEip712Data_V6=function(e,t,r){var n,a,i,o;void 0===r&&(r={});var s=null!=(n=r.validAfter)?n:0n,u=null!=(a=r.validUntil)?a:0n,c=null!=(i=r.entrypointAddress)?i:g,l=null!=(o=r.safe4337ModuleAddress)?o:"0xa581c4A4DB7175302464fF3C06380BC3270b4037",d={safe:e.sender,nonce:e.nonce,initCode:e.initCode,callData:e.callData,callGasLimit:e.callGasLimit,verificationGasLimit:e.verificationGasLimit,preVerificationGas:e.preVerificationGas,maxFeePerGas:e.maxFeePerGas,maxPriorityFeePerGas:e.maxPriorityFeePerGas,paymasterAndData:e.paymasterAndData,validAfter:s,validUntil:u,entryPoint:c};return{domain:{chainId:Number(t),verifyingContract:l},types:S,messageValue:d}},r.getUserOperationEip712Hash_V6=function(e,n,a){void 0===a&&(a={});var i=r.getUserOperationEip712Data_V6(e,n,a);return t.TypedDataEncoder.hash(i.domain,i.types,i.messageValue)},r.getUserOperationEip712Data_V7=function(e,r,n){var a,i,o,s;void 0===n&&(n={});var u=null!=(a=n.validAfter)?a:0n,c=null!=(i=n.validUntil)?i:0n,l=null!=(o=n.entrypointAddress)?o:y,d=null!=(s=n.safe4337ModuleAddress)?s:"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",f=t.AbiCoder.defaultAbiCoder(),h="0x";null!=e.factory&&(h=e.factory,null!=e.factoryData&&(h+=e.factoryData.slice(2)));var p="0x";null!=e.paymaster&&(p=e.paymaster,null!=e.paymasterVerificationGasLimit&&(p+=f.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(p+=f.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(p+=e.paymasterData.slice(2)));var v={safe:e.sender,nonce:e.nonce,initCode:h,callData:e.callData,verificationGasLimit:e.verificationGasLimit,callGasLimit:e.callGasLimit,preVerificationGas:e.preVerificationGas,maxPriorityFeePerGas:e.maxPriorityFeePerGas,maxFeePerGas:e.maxFeePerGas,paymasterAndData:p,validAfter:u,validUntil:c,entryPoint:l};return{domain:{chainId:Number(r),verifyingContract:d},types:P,messageValue:v}},r.getUserOperationEip712Hash_V7=function(e,n,a){void 0===a&&(a={});var i=r.getUserOperationEip712Data_V7(e,n,a);return t.TypedDataEncoder.hash(i.domain,i.types,i.messageValue)},r.formatEip712SingleSignatureToUseroperationSignature=function(e,r){var n,a;void 0===r&&(r={});var i=null!=(n=r.validAfter)?n:0n,o=null!=(a=r.validUntil)?a:0n;if(i<0n)throw RangeError("validAfter can't be negative");if(o<0n)throw RangeError("validUntil can't be negative");return t.solidityPacked(["uint48","uint48","bytes"],[i,o,e])};var n=r.prototype;return n.sendUserOperation=function(e,t){try{var r=this,n=new $(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new re(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},r.createAccountAddressAndFactoryAddressAndData=function(e,t,n,a){var i,o,s,u,c,l,d,f;if(e.length<1)throw RangeError("There should be at least one owner");var h,p=r.createBaseInitializerCallData(e,null!=(i=t.threshold)?i:1,n,a,null!=(o=t.multisendContractAddress)?o:r.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(s=t.webAuthnSharedSigner)?s:r.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(u=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?u:r.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(c=t.eip7212WebAuthnContractVerifierForSharedSigner)?c:r.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);h=null!=t.safeAccountFactoryAddress?new me(t.safeAccountFactoryAddress):new me;var v=null!=(l=t.safeAccountSingleton)?l:r.DEFAULT_SAFE_SINGLETON,m=this.createProxyAddress(p,{c2Nonce:null!=(d=t.c2Nonce)?d:0n,safeFactoryAddress:h.address,singletonInitHash:v.singletonInitHash}),A=[v.singletonAddress,p,null!=(f=t.c2Nonce)?f:0n],y=h.getFactoryGeneratorFunctionCallData(A);return[m,h.address,y]},r.createBaseInitializerCallData=function(e,t,n,a,i,s,u,c){if(void 0===i&&(i=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS),void 0===s&&(s=r.DEFAULT_WEB_AUTHN_SHARED_SIGNER),void 0===u&&(u=r.DEFAULT_WEB_AUTHN_PRECOMPILE),void 0===c&&(c=r.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER),e.length<1)throw RangeError("There should be at least one owner");if(t<1)throw RangeError("threshold should be at least one");if(t>e.length)throw RangeError("threshold can't be larger than number of owners");for(var l,d,f=B("0x8d0dc49f",["address[]"],[[n]]),h=!1,p=[],v=o(e);!(d=v()).done;){var A=d.value;"string"!=typeof A?h=!0:p.push(A)}if(h){var y={to:a,value:0n,data:f,operation:exports.Operation.Delegate},g=[];g.push(y);for(var E,S=[],P=0,b=o(e);!(E=b()).done;){var D=E.value;if("string"!=typeof D){if(P>0)throw RangeError("Only one WebAuthn owner can be set during initialization");var _={to:s,value:0n,data:B("0x0dd9692f",["uint256","uint256","uint176"],[D.x,D.y,"0x"+u.slice(-4)+c.slice(2)]),operation:exports.Operation.Delegate};g.push(_),S.push(s),P++}else S.push(D)}l=[S,t,i,B("0x8d80ff0a",["bytes"],[pe(g)]),n,m,0,m]}else l=[p,t,a,f,n,m,0,m];return B(r.initializerFunctionSelector,r.initializerFunctionInputAbi,l)},r.createFactoryAddressAndData=function(e,t,n,a){var i,o,s,u,c,l,d,f;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one owner");var h=null!=(i=t.threshold)?i:1,p=null!=(o=t.c2Nonce)?o:0;if(h<1)throw RangeError("threshold should be at least one");if(h>e.length)throw RangeError("threshold can't be larger than number of owners");if(p<0n)throw RangeError("c2Nonce can't be negative");var v,m=r.createBaseInitializerCallData(e,null!=(s=t.threshold)?s:1,n,a,null!=(u=t.multisendContractAddress)?u:r.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(c=t.webAuthnSharedSigner)?c:r.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(l=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?l:r.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(d=t.eip7212WebAuthnContractVerifierForSharedSigner)?d:r.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);v=null!=t.safeAccountFactoryAddress?new me(t.safeAccountFactoryAddress):new me;var A=null!=(f=t.safeAccountSingleton)?f:r.DEFAULT_SAFE_SINGLETON,y=v.getFactoryGeneratorFunctionCallData([A.singletonAddress,m,p]);return[v.address,y]},n.prependTokenPaymasterApproveToCallData=function(e,t,n,a,i){var o;void 0===i&&(i={});var s=null!=(o=i.multisendContractAddress)?o:r.DEFAULT_MULTISEND_CONTRACT_ADDRESS;return r.prependTokenPaymasterApproveToCallDataStatic(e,t,n,a,{multisendContractAddress:s})},n.estimateUserOperationGas=function(e,t,n){void 0===n&&(n={});try{var a=0xffffffffffffn,i=0xffffffffffffn;if(null!=n.dummySignerSignaturePairs){if(null!=n.expectedSigners)throw RangeError("Can't use both dummySignerSignaturePairs and expectedSigners overrides.");if(n.dummySignerSignaturePairs.length<1)throw RangeError("Number of dummy signers signature pairs can't be less than 1");e.signature=r.formatSignaturesToUseroperationSignature(n.dummySignerSignaturePairs,{validAfter:a,validUntil:i})}else if(null!=n.expectedSigners){var o,s=r.createDummySignerSignaturePairForExpectedSigners(n.expectedSigners,{isInit:null!=(o="initCode"in e?e.initCode:e.factory)&&"0x"!=o,webAuthnSharedSigner:n.webAuthnSharedSigner,eip7212WebAuthnPrecompileVerifier:n.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:n.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:n.webAuthnSignerFactory,webAuthnSignerSingleton:n.webAuthnSignerSingleton,validAfter:a,validUntil:i});e.signature=r.formatSignaturesToUseroperationSignature(s,{validAfter:a,validUntil:i})}else e.signature.length<3&&(e.signature=r.formatSignaturesToUseroperationSignature([fe],{validAfter:a,validUntil:i}));var u=new $(t),c=e.maxFeePerGas,l=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(u.estimateUserOperationGas(e,this.entrypointAddress,n.stateOverrideSet)).then(function(t){return e.maxFeePerGas=c,e.maxPriorityFeePerGas=l,[BigInt(t.preVerificationGas),null!=n.dummySign