UNPKG

abstractionkit

Version:

Account Abstraction 4337 SDK by Candidelabs

1 lines 89.7 kB
import*as e from"isomorphic-unfetch";import{AbiCoder as t,keccak256 as a,id as n,JsonRpcProvider as r,encodeRlp as i,Wallet as s,getBytes as o,toBeArray as l,solidityPacked as c,solidityPackedKeccak256 as d,getAddress as u,TypedDataEncoder as f,ethers as h}from"ethers";class A{constructor(e){this.accountAddress=void 0,this.accountAddress=e}}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)({}).hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},p.apply(null,arguments)}A.proxyByteCode=void 0,A.initializerFunctionSelector=void 0,A.initializerFunctionInputAbi=void 0,A.executorFunctionSelector=void 0,A.executorFunctionInputAbi=void 0;const m="0x0000000000000000000000000000000000000000",y="0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",g="0x0000000071727De22E5E9d8BAf0edAc6f37da032",E="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",D={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"}]},b={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"}]},_="0x0000000000000000000000000000000000000100";var T,w,F;!function(e){e[e.Call=0]="Call",e[e.Delegate=1]="Delegate"}(T||(T={})),function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(w||(w={})),function(e){e.Mainnet="v2",e.ZkMainnet="zkevm",e.Amoy="amoy",e.Cardona="cardona"}(F||(F={}));const v={"-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"};class x extends Error{constructor(e,t,a={}){const{cause:n,errno:r,context:i}=a;super(t,{cause:n}),this.code=void 0,this.context=void 0,this.errno=void 0,this.name=this.constructor.name,this.code=e,this.errno=r,this.context=i}stringify(){return JSON.stringify(this,["name","code","message","cause","errno","context"])}}function R(e){if(e instanceof Error)return e;let 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 P(e,n,r){let i;const s=t.defaultAbiCoder();let o;if(n.toLowerCase()==E.toLowerCase()){i=a(function(e){const n=[e.sender,e.nonce,a(e.initCode),a(e.callData),e.callGasLimit,e.verificationGasLimit,e.preVerificationGas,e.maxFeePerGas,e.maxPriorityFeePerGas,a(e.paymasterAndData)];return t.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],n)}(e));const l=s.encode(["bytes32","address","uint256"],[i,n,r]);o=a(l)}else if(n.toLowerCase()==g.toLowerCase()){i=a(function(e){const n=t.defaultAbiCoder();let r="0x";null!=e.factory&&(r=e.factory,null!=e.factoryData&&(r+=e.factoryData.slice(2)));const i="0x"+n.encode(["uint128"],[e.verificationGasLimit]).slice(34)+n.encode(["uint128"],[e.callGasLimit]).slice(34),s="0x"+n.encode(["uint128"],[e.maxPriorityFeePerGas]).slice(34)+n.encode(["uint128"],[e.maxFeePerGas]).slice(34);let o="0x";null!=e.paymaster&&(o=e.paymaster,null!=e.paymasterVerificationGasLimit&&(o+=n.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(o+=n.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(o+=e.paymasterData.slice(2)));const l=[e.sender,e.nonce,a(r),a(e.callData),i,e.preVerificationGas,s,a(o)];return n.encode(["address","uint256","bytes32","bytes32","bytes32","uint256","bytes32","bytes32"],l)}(e));const l=s.encode(["bytes32","address","uint256"],[i,n,r]);o=a(l)}else{i=a(function(e){const n=t.defaultAbiCoder();let r="0x";if(null!=e.factory){const t=e.eip7702Auth;r=null!=t&&null!=t.address?t.address:e.factory,null!=e.factoryData&&(r+=e.factoryData.slice(2))}const i="0x"+n.encode(["uint128"],[e.verificationGasLimit]).slice(34)+n.encode(["uint128"],[e.callGasLimit]).slice(34),s="0x"+n.encode(["uint128"],[e.maxPriorityFeePerGas]).slice(34)+n.encode(["uint128"],[e.maxFeePerGas]).slice(34);let o="0x";null!=e.paymaster&&(o=e.paymaster,null!=e.paymasterVerificationGasLimit&&(o+=n.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(o+=n.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(o+=e.paymasterData.slice(2)));const l=["0x29a0bca4af4be3421398da00295e58e6d7de38cb492214754cb6a47507dd6f8e",e.sender,e.nonce,a(r),a(e.callData),i,e.preVerificationGas,s,a(o)];return n.encode(["bytes32","address","uint256","bytes32","bytes32","bytes32","uint256","bytes32","bytes32"],l)}(e));const n=function(e){const n=t.defaultAbiCoder().encode(["(bytes32,bytes32,bytes32,uint256,address)"],[["0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f","0x364da28a5c92bcc87fe97c8813a6c6b8a3a049b0ea0a328fcb0b4f0e00337586","0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6",e,y]]);return a(n)}(r);o=a("0x1901"+n.slice(2)+i.slice(2))}return o}function L(e,a,n){return e+t.defaultAbiCoder().encode(a,n).slice(2)}async function G(t,a,n,r={"Content-Type":"application/json"},i="params"){const s=e.default||e,o={method:"POST",headers:r,body:JSON.stringify({method:a,[i]:n,id:(new Date).getTime(),jsonrpc:"2.0"},(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t),redirect:"follow"},l=await s(t,o),c=await l.json();if("result"in c)return c.result;if("simulation_results"in c)return c.simulation_results;{const e=c.error,a=String(e.code);throw new x(a in v?v[a]:"UNKNOWN_ERROR",e.message,{errno:e.code,context:{url:t,requestOptions:JSON.stringify(o)}})}}function U(e){return n(e).slice(0,10)}async function C(e,t,a,n=0){const r=[{from:"0x0000000000000000000000000000000000000000",to:t,data:L(U("getNonce(address,uint192)"),["address","uint192"],[a,n])},"latest"];try{const t=await G(e,"eth_call",r);if("string"!=typeof t)throw new x("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(t)});try{return BigInt(t)}catch(e){const t=R(e);throw new x("BAD_DATA","getNonce returned ill formed data",{cause:t})}}catch(e){const t=R(e);throw new x("BAD_DATA","getNonce failed",{cause:t})}}async function I(e,t=w.Medium){try{const a=new r(e),n=await a.getFeeData();let i,s;return null!=n.maxFeePerGas&&null!=n.maxPriorityFeePerGas?(i=BigInt(Math.ceil(Number(n.maxFeePerGas)*t)),s=BigInt(Math.ceil(Number(n.maxPriorityFeePerGas)*t))):null!=n.gasPrice?(i=BigInt(Math.ceil(Number(n.gasPrice)*t)),s=i):(i=BigInt(Math.ceil(1e9*t)),s=i),0n==i&&(i=1n),0n==s&&(s=1n),[i,s]}catch(e){const t=R(e);throw new x("BAD_DATA","fetching gas prices from node failed.",{cause:t})}}function O(e){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!=(a=e.paymasterPostOpGasLimit)?a:0n)+e.preVerificationGas)*e.maxFeePerGas;var t,a}async function M(e,t,a){return(await V(e,t,a)).deposit}async function V(e,a,n){const r={from:"0x0000000000000000000000000000000000000000",to:n,data:L("0x5287ce12",["address"],[a])};try{const a=await B(e,r,"latest"),n=t.defaultAbiCoder().decode(["uint256","bool","uint112","uint32","uint48"],a);if(5!==n.length)throw new x("BAD_DATA","getDepositInfo returned ill formed data",{context:JSON.stringify(n)});try{return{deposit:BigInt(n[0]),staked:Boolean(n[1]),stake:BigInt(n[2]),unstakeDelaySec:BigInt(n[3]),withdrawTime:BigInt(n[4])}}catch(e){const t=R(e);throw new x("BAD_DATA","getDepositInfo returned ill formed data",{cause:t})}}catch(e){const t=R(e);throw new x("BAD_DATA","getDepositInfo failed",{cause:t})}}async function B(e,t,a,n){let r=[];r=null==n?[t,a]:[t,a,n];try{const t=await G(e,"eth_call",r);if("string"!=typeof t)throw new x("BAD_DATA","eth_call returned ill formed data",{context:JSON.stringify(t)});try{return t}catch(e){const t=R(e);throw new x("BAD_DATA","eth_call returned ill formed data",{cause:t})}}catch(e){const t=R(e);throw new x("BAD_DATA","eth_call failed",{cause:t})}}async function N(e,t,a){const n=[t,a];try{const t=await G(e,"eth_getCode",n);if("string"!=typeof t)throw new x("BAD_DATA","eth_getCode returned ill formed data",{context:JSON.stringify(t)});try{return t}catch(e){const t=R(e);throw new x("BAD_DATA","eth_getCode returned ill formed data",{cause:t})}}catch(e){const t=R(e);throw new x("BAD_DATA","eth_getCode failed",{cause:t})}}async function W(e,t,a=w.Medium){let n,r;if(null!=t)[n,r]=await async function(e,t=w.Medium){const a="https://gasstation.polygon.technology/"+e;try{const e=await fetch(a),n=await e.json();let r;r=t==w.Slow?n.safeLow:t==w.Medium?n.standard:n.fast;let i=BigInt(Math.ceil(1e9*Number(r.maxFee))),s=BigInt(Math.ceil(1e9*Number(r.maxPriorityFee)));return 0n==i&&(i=1n),0n==s&&(s=1n),[i,s]}catch(e){const t=R(e);throw new x("BAD_DATA","fetching gas prices from "+a+" failed.",{cause:t})}}(t,a);else{if(null==e)throw new x("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden");[n,r]=await I(e,a)}return[n,r]}const k="0x04";function H(e,t,n,r,l,c,d,u){if(e>=2**64)throw RangeError("Invalide chainId.");if(t>=2**64)throw RangeError("Invalide nonce.");if(42!=l.length)throw RangeError("Invalide destination.");let f=[q(t),q(n),q(r),l,q(c),d,q(e),q(0n),q(0n)];const h=a(i(f)),A=new s(u).signingKey.sign(h);return f=[q(t),q(n),q(r),l,q(c),d,q(BigInt(A.yParity+2*Number(e)+35)),o(A.r),o(A.s)],i(f)}function z(e,t,a,n){const r=j(Y(e,t,a),n);return{chainId:$(e),address:t,nonce:$(a),yParity:$(BigInt(r.yParity)),r:$(r.r),s:$(r.s)}}function Y(e,t,n){const r=[q(e),t,q(n)],s=i(r);return a("0x05"+s.slice(2))}function j(e,t){const a=new s(t).signingKey.sign(e);return{yParity:a.yParity,r:BigInt(a.r),s:BigInt(a.s)}}function J(e,t,a,n,r,s,o,l,c,d,u){const f=K(e,t,a,n,r,s,o,l,c,d),h=X(e,t,a,n,r,s,o,l,c,d),A=j(f,u),p=h.concat([q(BigInt(A.yParity)),q(A.r),q(A.s)]),m=i(p);return k+m.slice(2)}function K(e,t,n,r,s,o,l,c,d,u){const f=X(e,t,n,r,s,o,l,c,d,u);return a(k+i(f).slice(2))}function X(e,t,a,n,r,i,s,l,c,d){if(e>=2**64)throw RangeError("Invalide chainId.");if(t>=2**64)throw RangeError("Invalide nonce.");if(42!=i.length)throw RangeError("Invalide destination.");const u=function(e){let t=[];for(const a of e){if(42!=a.address.length)throw RangeError("Invalide authorization list address: "+a);const e=[q(a.chainId),a.address,q(a.nonce),q(BigInt(a.yParity)),q(a.r),q(a.s)];t.push(e)}return t}(d),f=function(e){let t=[];for(const[a,n]of e){if(42!=a.length)throw RangeError("Invalide access list address: "+a);let e=[];for(const t of n){if(66!=t.length)throw RangeError("Invalide access list storage: "+t);e.push(o(t))}t.push([o(a),e])}return t}(c);return[q(e),q(t),q(a),q(n),q(r),i,q(s),l,f,u]}function q(e){return o(l(e))}function $(e){let t=e.toString(16);return t.length%2?"0x0"+t:"0x"+t}class Z{constructor(e){this.rpcUrl=void 0,this.rpcUrl=e}async chainId(){try{const e=await G(this.rpcUrl,"eth_chainId",[]);if("string"==typeof e)return e;throw new x("BAD_DATA","bundler eth_chainId rpc call failed")}catch(e){const t=R(e);throw new x("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}}async supportedEntryPoints(){try{return await G(this.rpcUrl,"eth_supportedEntryPoints",[])}catch(e){const t=R(e);throw new x("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}}async estimateUserOperationGas(e,t,a){try{let n={};n=void 0===a?await G(this.rpcUrl,"eth_estimateUserOperationGas",[e,t]):await G(this.rpcUrl,"eth_estimateUserOperationGas",[e,t,a]);const r=n;return{callGasLimit:BigInt(r.callGasLimit),preVerificationGas:BigInt(r.preVerificationGas),verificationGasLimit:BigInt(r.verificationGasLimit)}}catch(e){const t=R(e);throw new x("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}}async sendUserOperation(e,t){try{return await G(this.rpcUrl,"eth_sendUserOperation",[e,t])}catch(e){const t=R(e);throw new x("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}}async getUserOperationReceipt(e){try{const t=await G(this.rpcUrl,"eth_getUserOperationReceipt",[e]);if(null!=t){const e=p({},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 p({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:e})}return null}catch(t){const a=R(t);throw new x("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:a,context:{useroperationhash:e}})}}async getUserOperationByHash(e){try{const t=await G(this.rpcUrl,"eth_getUserOperationByHash",[e]);return null!=t?p({},t,{blockNumber:null==t.blockNumber?null:BigInt(t.blockNumber)}):null}catch(t){const a=R(t);throw new x("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:a,context:{useroperationhash:e}})}}}class Q{constructor(e,t,a){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=a}delay(e){return new Promise(t=>setTimeout(t,e))}async included(e=180,t=2){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");let a=0;for(;a<=e;){await this.delay(1e3*t);const e=await this.bundler.getUserOperationReceipt(this.userOperationHash);if(null!=e)return e;a++}throw new x("TIMEOUT","can't find useroperation",{context:this.userOperationHash})}}class ee extends A{constructor(e,t={}){var a;super(e),this.entrypointAddress=void 0,this.entrypointAddress=null!=(a=t.entrypointAddress)?a:ee.DEFAULT_ENTRYPOINT_ADDRESS}static createAccountCallData(e,t,a){return L(ee.executorFunctionSelector,ee.executorFunctionInputAbi,[e,t,a])}static createAccountCallDataSingleTransaction(e){var t,a;const n=null!=(t=e.value)?t:0,r=null!=(a=e.data)?a:"0x";return ee.createAccountCallData(e.to,n,r)}static createAccountCallDataBatchTransactions(e){const t=[e.map(e=>[e.to,e.value,e.data])];return L(ee.batchExecutorFunctionSelector,ee.batchExecutorFunctionInputAbi,t)}async createUserOperation(e,t,a,n={}){var r,i,s,o,l,c,d,u,f,h;if(e.length<1)throw RangeError("There should be at least one transaction");let A=null,m=null;if(null==n.nonce){if(null==t)throw new x("BAD_DATA","providerRpc cant't be null if nonce is not overriden");m=C(t,this.entrypointAddress,this.accountAddress)}else A=n.nonce;if("bigint"==typeof n.maxFeePerGas&&n.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof n.maxPriorityFeePerGas&&n.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");let y=D.maxFeePerGas,g=D.maxPriorityFeePerGas,E=null;null!=n.maxFeePerGas&&null!=n.maxPriorityFeePerGas||(E=W(t,n.polygonGasStation,n.gasLevel));let S=null,b=null,_=null;var T,w;if(null!=n.eip7702Auth&&(S=n.eip7702Auth.chainId,b=null!=(T=n.eip7702Auth.address)?T:ee.DEFAULT_DELEGATEE_ADDRESS,_=null!=(w=n.eip7702Auth.nonce)?w:null),null!=n.eip7702Auth&&null==_){let e;if(null==t)throw new x("BAD_DATA","providerRpc cant't be null if eoaDelegatorNonce is not overriden");e=G(t,"eth_getTransactionCount",[this.accountAddress,"latest"]),null!=E&&null!=m?await Promise.all([e,m,E]).then(e=>{_=BigInt(e[0]),A=e[1],[y,g]=e[2]}):null!=E?await Promise.all([e,E]).then(e=>{_=BigInt(e[0]),[y,g]=e[1]}):null!=m?await Promise.all([e,E]).then(e=>{_=BigInt(e[0]),A=e[1]}):_=BigInt(await e)}else null!=E&&null!=m?await Promise.all([m,E]).then(e=>{A=e[0],[y,g]=e[1]}):null!=E?[y,g]=await E:null!=m&&(A=await m);if(y=null!=(r=n.maxFeePerGas)?r:y*BigInt(Math.floor(((null!=(i=n.maxFeePerGasPercentageMultiplier)?i:0)+100)/100)),g=null!=(s=n.maxPriorityFeePerGas)?s:g*BigInt(Math.floor(((null!=(o=n.maxPriorityFeePerGasPercentageMultiplier)?o:0)+100)/100)),null==A)throw RangeError("failed to determine nonce");if(A<0n)throw RangeError("nonce can't be negative");let F,v="0x";if(v=null==n.callData?1==e.length?ee.createAccountCallDataSingleTransaction(e[0]):ee.createAccountCallDataBatchTransactions(e):n.callData,null!=n.eip7702Auth){var R,P,L;const e=null!=(R=n.eip7702Auth.yParity)?R:"0x0";if("0x0"!=e&&"0x00"!=e&&"0x1"!=e&&"0x01"!=e)throw new x("BAD_DATA","invalide yParity value for eoaDelegatorSignature. must be '0x0' or '0x1'");const t={chainId:$(S),address:b,nonce:$(_),yParity:e,r:null!=(P=n.eip7702Auth.r)?P:"0x4277ba564d2c138823415df0ec8e8f97f30825056d54ec5128a8b29ec2dd81b2",s:null!=(L=n.eip7702Auth.s)?L:"0x1075a1bec7f59848cca899ece93075199cd2aabceb0654b9ae00b881a30044cd"};F=p({},D,{sender:this.accountAddress,nonce:A,callData:v,maxFeePerGas:y,maxPriorityFeePerGas:g,factory:"0x7702",factoryData:null,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null,eip7702Auth:t})}else F=p({},D,{sender:this.accountAddress,nonce:A,callData:v,maxFeePerGas:y,maxPriorityFeePerGas:g,factory:null,factoryData:null,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null,eip7702Auth:null});let U=D.preVerificationGas,I=D.verificationGasLimit,O=D.callGasLimit;if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit){if(null==a)throw new x("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{var M;F.callGasLimit=0n,F.verificationGasLimit=0n,F.preVerificationGas=0n;const e=F.maxFeePerGas,t=F.maxPriorityFeePerGas;let r;F.maxFeePerGas=0n,F.maxPriorityFeePerGas=0n,r=p({},F),F.signature=null!=(M=n.dummySignature)?M:ee.dummySignature,[U,I,O]=await this.estimateUserOperationGas(r,a,{stateOverrideSet:n.state_override_set}),I+=55000n,F.maxFeePerGas=e,F.maxPriorityFeePerGas=t}}if("bigint"==typeof n.preVerificationGas&&n.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof n.verificationGasLimit&&n.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof n.callGasLimit&&n.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return F.preVerificationGas=null!=(l=n.preVerificationGas)?l:U*BigInt(Math.floor(((null!=(c=n.preVerificationGasPercentageMultiplier)?c:0)+100)/100)),F.verificationGasLimit=null!=(d=n.verificationGasLimit)?d:I*BigInt(Math.floor(((null!=(u=n.verificationGasLimitPercentageMultiplier)?u:0)+100)/100)),F.callGasLimit=null!=(f=n.callGasLimit)?f:O*BigInt(Math.floor(((null!=(h=n.callGasLimitPercentageMultiplier)?h:0)+100)/100)),F}async estimateUserOperationGas(e,t,a={}){var n;e.signature=null!=(n=a.dummySignature)?n:ee.dummySignature;const r=new Z(t),i=e.maxFeePerGas,s=e.maxPriorityFeePerGas;e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n;const o=await r.estimateUserOperationGas(e,this.entrypointAddress,a.stateOverrideSet);return e.maxFeePerGas=i,e.maxPriorityFeePerGas=s,[BigInt(o.preVerificationGas),BigInt(o.verificationGasLimit),BigInt(o.callGasLimit)]}signUserOperation(e,t,a){const n=P(e,this.entrypointAddress,a);return new s(t).signingKey.sign(n).serialized}async sendUserOperation(e,t){const a=new Z(t),n=await a.sendUserOperation(e,this.entrypointAddress);return new Q(n,a,this.entrypointAddress)}prependTokenPaymasterApproveToCallData(e,t,a,n){return ee.prependTokenPaymasterApproveToCallDataStatic(e,t,a,n)}static prependTokenPaymasterApproveToCallDataStatic(e,a,n,r){const i={to:a,value:0n,data:L(U("approve(address,uint256)"),["address","uint256"],[n,r])},s=t.defaultAbiCoder();let o;if(e.startsWith(ee.batchExecutorFunctionSelector))o=s.decode(ee.batchExecutorFunctionInputAbi,"0x"+e.slice(10))[0].map(e=>({to:e[0],value:BigInt(e[1]),data:"string"!=typeof e[2]?(new TextDecoder).decode(e[2]):e[2]}));else{if(!e.startsWith(ee.executorFunctionSelector))throw new x("BAD_DATA","Invalid calldata, should start with "+ee.batchExecutorFunctionSelector+" or "+ee.executorFunctionSelector,{context:{callData:e}});{const t=s.decode(ee.executorFunctionInputAbi,"0x"+e.slice(10));o=[{to:t[0],value:BigInt(t[1]),data:"string"!=typeof t[2]?(new TextDecoder).decode(t[2]):t[2]}]}}return o.unshift(i),ee.createAccountCallDataBatchTransactions(o)}}async function te(t,a,n,r){const i="https://api.tenderly.co/api/v1/account/"+t+"/project/"+a+"/simulations/"+r+"/share",s=e.default||e,o={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Access-Key":n},redirect:"follow"},l=(await s(i,o)).status;if(204!=l)throw new x("BAD_DATA","tenderly share simulation failed.",{context:{tenderlyAccountSlug:t,tenderlyProjectSlug:a,tenderlyAccessKey:n,tenderlySimulationId:r,status:l}})}async function ae(e,t,a,n,r,i,s=null){const o=await ne(e,t,a,n,r,i,s);return await te(e,t,a,o.simulation.id),{simulation:o,simulationShareLink:"https://dashboard.tenderly.co/shared/simulation/"+o.simulation.id}}async function ne(e,a,n,r,i,s,o=null){const l=i.toLowerCase();let c=null;const d=t.defaultAbiCoder();if("initCode"in s&&"0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"==l)c="0x1fad948c"+d.encode(["(address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[]","address"],[[[s.sender,s.nonce,s.initCode,s.callData,s.callGasLimit,s.verificationGasLimit,s.preVerificationGas,s.maxFeePerGas,s.maxPriorityFeePerGas,s.paymasterAndData,s.signature]],"0x1000000000000000000000000000000000000000"]).slice(2);else{let e="0x";null!=s.factory&&(e=s.factory,null!=s.factoryData&&(e+=s.factoryData.slice(2)));const t="0x"+d.encode(["uint128"],[s.verificationGasLimit]).slice(34)+d.encode(["uint128"],[s.callGasLimit]).slice(34),a="0x"+d.encode(["uint128"],[s.maxPriorityFeePerGas]).slice(34)+d.encode(["uint128"],[s.maxFeePerGas]).slice(34);let n="0x";null!=s.paymaster&&(n=s.paymaster,null!=s.paymasterVerificationGasLimit&&(n+=d.encode(["uint128"],[s.paymasterVerificationGasLimit]).slice(34)),null!=s.paymasterPostOpGasLimit&&(n+=d.encode(["uint128"],[s.paymasterPostOpGasLimit]).slice(34)),null!=s.paymasterData&&(n+=s.paymasterData.slice(2)));const r=d.encode(["(address,uint256,bytes,bytes,bytes32,uint256,bytes32,bytes,bytes)[]","address"],[[[s.sender,s.nonce,e,s.callData,t,s.preVerificationGas,a,n,s.signature]],"0x1000000000000000000000000000000000000000"]);if("0x0000000071727de22e5e9d8baf0edac6f37da032"!=l&&"0x4337084d9e255ff0702461cf8895ce9e3b5ff108"!=l)throw RangeError("Invalid entrypoint.");c="0x765e827f"+r.slice(2)}return(await oe(e,a,n,[{chainId:r,blockNumber:o,from:"0x1000000000000000000000000000000000000000",to:i,data:c}]))[0]}async function re(e,t,a,n,r,i,s=null){let o=null,l=null;return"initCode"in i?i.initCode.length>2&&(o=i.initCode.slice(0,22),l=i.initCode.slice(22)):(o=i.factory,l=i.factoryData),await se(e,t,a,n,r,i.sender,i.callData,o,l,s)}async function ie(e,t,a,n,r,i,s,o=null,l=null,c=null){const d=await se(e,t,a,n,r,i,s,o,l,c),u=d.map(e=>e.simulation.id);u.map(n=>te(e,t,a,n));const f=u.map(e=>"https://dashboard.tenderly.co/shared/simulation/"+e);if(1==f.length)return{simulation:d,callDataSimulationShareLink:f[0]};if(2==f.length)return{simulation:d,accountDeploymentSimulationShareLink:f[0],callDataSimulationShareLink:f[1]};throw new x("BAD_DATA","invalid number of simulations retuned",{context:JSON.stringify(d,(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t)})}async function se(e,t,a,n,r,i,s,o=null,l=null,c=null){const d=[],u=r.toLowerCase();let f;if("0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"==u)f="0x7fc98430eaedbb6070b35b39d798725049088348";else if("0x0000000071727de22e5e9d8baf0edac6f37da032"==u)f="0xefc2c1444ebcc4db75e7613d20c6a62ff67a167c";else{if("0x4337084d9e255ff0702461cf8895ce9e3b5ff108"!=u)throw RangeError(`Invalid entrypoint: ${r}`);f="0x449ed7c3e6fee6a97311d4b55475df59c44add33"}if(null==o&&null!=l||null!=o&&null==l)throw RangeError("Invalid factory and factoryData");return null!=o&&null!=l&&d.push({chainId:n,blockNumber:c,from:f,to:o,data:l}),d.push({chainId:n,blockNumber:c,from:r,to:i,data:s}),await oe(e,t,a,d)}async function oe(e,t,a,n){const r="https://api.tenderly.co/api/v1/account/"+e+"/project/"+t+"/simulate-bundle",i=n.map(e=>{var t,a,n;const r={network_id:e.chainId.toString(),save:null==(t=e.save)||t,save_if_fails:null==(a=e.saveIfFails)||a,from:e.from,to:e.to,input:e.data,simulation_type:null!=(n=e.simulationType)?n:"quick"};return null!=e.blockNumber&&(r.block_number=e.blockNumber),null!=e.gas&&(r.gas=e.gas),null!=e.gasPrice&&(r.gas_price=e.gasPrice),null!=e.value&&(r.value=e.value),null!=e.stateOverride&&(r.state_objects=e.stateOverride),null!=e.transactionIndex&&(r.transaction_index=e.transactionIndex),null!=e.estimateGas&&(r.estimate_gas=e.estimateGas),null!=e.generateAccessList&&(r.generate_access_list=e.generateAccessList),null!=e.accessList&&(r.access_list=e.accessList),r}),s={Accept:"application/json","Content-Type":"application/json","X-Access-Key":a};return await G(r,"tenderly_simulateBundle",i,s,"simulations")}var le;ee.DEFAULT_DELEGATEE_ADDRESS="0xe6Cae83BdE06E4c305530e199D7217f42808555B",ee.DEFAULT_ENTRYPOINT_ADDRESS=y,ee.executorFunctionSelector="0xb61d27f6",ee.executorFunctionInputAbi=["address","uint256","bytes"],ee.batchExecutorFunctionSelector="0x34fcd5be",ee.batchExecutorFunctionInputAbi=["(address,uint256,bytes)[]"],ee.dummySignature="0xd2614025fc173b86704caf37b2fb447f7618101a0d31f5f304c777024cef38a060a29ee43fcf0c46f9107d4f670b8a85c2c017a1fe9e4af891f24f0be6ba5d671c",function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(le||(le={}));const ce={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x47003599ffa7e9198f321afa774e34a12a959844efd6363b88896e9c24ed33cf4e1be876ef123a3c4467e7d451511434039539699f2baa2f44955fa3d1c1c6d81c",isContractSignature:!1},de={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e06c92f0ac5c4ef9e74721c23d80a9fc12f259ca84afb160f0890483539b9e6080d824c0e6c795157ad5d1ee5eff1ceeb3031009a595f9360919b83dd411c5a78d0000000000000000000000000000000000000000000000000000000000000025a24f744b28d73f066bf3203d145765a7bc735e6328168c8b03e476da3ad0d8fe0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e226f726967696e223a2268747470733a2f2f736166652e676c6f62616c220000",isContractSignature:!0};function ue(e){return"0x"+e.map(e=>function(e){var t;const a=null!=(t=e.operation)?t:T.Call,n=o(e.data);return c(["uint8","address","uint256","uint256","bytes"],[a,e.to,e.value,n.length,n]).slice(2)}(e)).join("")}class fe{constructor(e,t,a){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=a}getFactoryGeneratorFunctionCallData(e){return L(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e)}}class he extends fe{constructor(e=he.DEFAULT_FACTORY_ADDRESS){super(e,"0x1688f0b9",["address","bytes","uint256"])}}he.DEFAULT_FACTORY_ADDRESS="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67";class Ae extends A{constructor(e,t,n,r={}){if(super(e),this.isInitWebAuthn=void 0,this.x=null,this.y=null,this.entrypointAddress=void 0,this.safe4337ModuleAddress=void 0,this.factoryAddress=void 0,this.factoryData=void 0,this.onChainIdentifier=void 0,this.entrypointAddress=n,this.safe4337ModuleAddress=t,this.factoryAddress=null,this.factoryData=null,this.isInitWebAuthn=!1,null!=r.onChainIdentifierParams&&null!=r.onChainIdentifier)throw RangeError("can't override both onChainIdentifier and onChainIdentifierParams");if(null!=r.onChainIdentifierParams)this.onChainIdentifier=function(e,t="Web",n="abstractionkit",r="0.2.21"){const i=a("0x"+Buffer.from(e,"utf8").toString("hex")).slice(-20),s=a("0x"+Buffer.from(t,"utf8").toString("hex")).slice(-3),o=a("0x"+Buffer.from(n,"utf8").toString("hex")).slice(-3),l=a("0x"+Buffer.from(r,"utf8").toString("hex")).slice(-3);return`5afe00${Buffer.from(i,"utf8").toString("hex")}${Buffer.from(s,"utf8").toString("hex")}${Buffer.from(o,"utf8").toString("hex")}${Buffer.from(l,"utf8").toString("hex")}`}(r.onChainIdentifierParams.project,r.onChainIdentifierParams.platform,r.onChainIdentifierParams.tool,r.onChainIdentifierParams.toolVersion);else if(null!=r.onChainIdentifier){let e=r.onChainIdentifier;if(e.startsWith("0x")&&(e=e.slice(2)),64!=e.length)throw RangeError("onChainIdentifier length must be 64.");this.onChainIdentifier=e}else this.onChainIdentifier=null}static createProxyAddress(e,t={}){var n,r,i;const s=null!=(n=t.c2Nonce)?n:0n;if(s<0n)throw RangeError("c2Nonce can't be negative");const o=null!=(r=t.safeFactoryAddress)?r:he.DEFAULT_FACTORY_ADDRESS,l=null!=(i=t.singletonInitHash)?i:Ae.DEFAULT_SAFE_SINGLETON.singletonInitHash,f=a(c(["bytes32","uint256"],[a(e),s])),h=d(["bytes1","address","bytes32","bytes32"],["0xff",o,f,l]).slice(-40);return u("0x"+h)}static createAccountCallDataSingleTransaction(e,t={}){var a,n,r,i;const s=null!=(a=e.value)?a:0,o=null!=(n=e.data)?n:"0x",l=null!=(r=e.operation)?r:T.Call,c=null!=(i=t.safeModuleExecutorFunctionSelector)?i:Ae.DEFAULT_EXECUTOR_FUCNTION_SELECTOR;return Ae.createAccountCallData(e.to,s,o,l,{safeModuleExecutorFunctionSelector:c})}static createAccountCallDataBatchTransactions(e,t={}){var a,n;if(e.length<1)throw RangeError("There should be at least one metaTransaction");const r=null!=(a=t.safeModuleExecutorFunctionSelector)?a:Ae.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,i=null!=(n=t.multisendContractAddress)?n:Ae.DEFAULT_MULTISEND_CONTRACT_ADDRESS,s=L("0x8d80ff0a",["bytes"],[ue(e)]);return Ae.createAccountCallData(i,0n,s,T.Delegate,{safeModuleExecutorFunctionSelector:r})}static createAccountCallData(e,t,a,n,r={}){var i;return L(null!=(i=r.safeModuleExecutorFunctionSelector)?i:Ae.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,Ae.executorFunctionInputAbi,[e,t,a,n])}static decodeAccountCallData(e){let a=null;if(e.startsWith(le.executeUserOpWithErrorString)?a=le.executeUserOpWithErrorString:e.startsWith(le.executeUserOp)&&(a=le.executeUserOp),null!=a){const n=t.defaultAbiCoder(),r="0x"+e.slice(10),i=n.decode(["address","uint256","bytes","uint8"],r);let s;return s="string"!=typeof i[2]?(new TextDecoder).decode(i[2]):i[2],[{to:i[0],value:BigInt(i[1]),data:s,operation:Number(i[3])},a]}throw new x("BAD_DATA","Invalid calldata, should start with "+le.executeUserOpWithErrorString+" or "+le.executeUserOp,{context:{callData:e}})}static prependTokenPaymasterApproveToCallDataStatic(e,a,n,r,i={}){var s;const o=null!=(s=i.multisendContractAddress)?s:Ae.DEFAULT_MULTISEND_CONTRACT_ADDRESS,[l,c]=Ae.decodeAccountCallData(e),d=ue([{to:a,value:0n,data:L(U("approve(address,uint256)"),["address","uint256"],[n,r]),operation:T.Call}]);let u="";const f="0x8d80ff0a";if(l.data.startsWith(f)){const e=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(l.data);u=e+d.slice(2)}else u=ue([l])+d.slice(2);const h=L(f,["bytes"],[u]);return Ae.createAccountCallData(o,0n,h,T.Delegate,{safeModuleExecutorFunctionSelector:c})}static formatEip712SignaturesToUseroperationSignature(e,t,a={}){var n,r;if(e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");const i=null!=(n=a.validAfter)?n:0n,s=null!=(r=a.validUntil)?r:0n,o=new Map;e.forEach((e,a)=>{o.set(e.toLocaleLowerCase(),t[a])});const l=new Map(Array.from(o).sort()),c="0x"+Array.from(l.values()).reduce((e,t)=>e+t.slice(2),"");return Ae.formatEip712SingleSignatureToUseroperationSignature(c,{validAfter:i,validUntil:s})}static getUserOperationEip712Hash(e,t,a={}){return"initCode"in e?Ae.getUserOperationEip712Hash_V6(e,t,a):Ae.getUserOperationEip712Hash_V7(e,t,a)}static getUserOperationEip712Data(e,t,a){if("initCode"in e){const n=Ae.getUserOperationEip712Data_V6(e,t,a);return{domain:n.domain,types:n.types,messageValue:n.messageValue}}{const n=Ae.getUserOperationEip712Data_V7(e,t,a);return{domain:n.domain,types:n.types,messageValue:n.messageValue}}}static getUserOperationEip712Data_V6(e,t,a={}){var n,r,i,s;const o=null!=(n=a.validAfter)?n:0n,l=null!=(r=a.validUntil)?r:0n,c=null!=(i=a.entrypointAddress)?i:E,d=null!=(s=a.safe4337ModuleAddress)?s:"0xa581c4A4DB7175302464fF3C06380BC3270b4037",u={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:o,validUntil:l,entryPoint:c};return{domain:{chainId:Number(t),verifyingContract:d},types:S,messageValue:u}}static getUserOperationEip712Hash_V6(e,t,a={}){const n=Ae.getUserOperationEip712Data_V6(e,t,a);return f.hash(n.domain,n.types,n.messageValue)}static getUserOperationEip712Data_V7(e,a,n={}){var r,i,s,o;const l=null!=(r=n.validAfter)?r:0n,c=null!=(i=n.validUntil)?i:0n,d=null!=(s=n.entrypointAddress)?s:g,u=null!=(o=n.safe4337ModuleAddress)?o:"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",f=t.defaultAbiCoder();let h="0x";null!=e.factory&&(h=e.factory,null!=e.factoryData&&(h+=e.factoryData.slice(2)));let A="0x";null!=e.paymaster&&(A=e.paymaster,null!=e.paymasterVerificationGasLimit&&(A+=f.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(A+=f.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(A+=e.paymasterData.slice(2)));const p={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:A,validAfter:l,validUntil:c,entryPoint:d};return{domain:{chainId:Number(a),verifyingContract:u},types:b,messageValue:p}}static getUserOperationEip712Hash_V7(e,t,a={}){const n=Ae.getUserOperationEip712Data_V7(e,t,a);return f.hash(n.domain,n.types,n.messageValue)}static formatEip712SingleSignatureToUseroperationSignature(e,t={}){var a,n;const r=null!=(a=t.validAfter)?a:0n,i=null!=(n=t.validUntil)?n:0n;if(r<0n)throw RangeError("validAfter can't be negative");if(i<0n)throw RangeError("validUntil can't be negative");return c(["uint48","uint48","bytes"],[r,i,e])}async sendUserOperation(e,t){const a=new Z(t),n=await a.sendUserOperation(e,this.entrypointAddress);return new Q(n,a,this.entrypointAddress)}static createAccountAddressAndFactoryAddressAndData(e,t,a,n){var r,i,s,o,l,c,d,u;if(e.length<1)throw RangeError("There should be at least one owner");const f=Ae.createBaseInitializerCallData(e,null!=(r=t.threshold)?r:1,a,n,null!=(i=t.multisendContractAddress)?i:Ae.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(s=t.webAuthnSharedSigner)?s:Ae.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(o=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?o:Ae.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(l=t.eip7212WebAuthnContractVerifierForSharedSigner)?l:Ae.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);let h;h=null!=t.safeAccountFactoryAddress?new he(t.safeAccountFactoryAddress):new he;const A=null!=(c=t.safeAccountSingleton)?c:Ae.DEFAULT_SAFE_SINGLETON,p=this.createProxyAddress(f,{c2Nonce:null!=(d=t.c2Nonce)?d:0n,safeFactoryAddress:h.address,singletonInitHash:A.singletonInitHash}),m=[A.singletonAddress,f,null!=(u=t.c2Nonce)?u:0n],y=h.getFactoryGeneratorFunctionCallData(m);return[p,h.address,y]}static createBaseInitializerCallData(e,t,a,n,r=Ae.DEFAULT_MULTISEND_CONTRACT_ADDRESS,i=Ae.DEFAULT_WEB_AUTHN_SHARED_SIGNER,s=Ae.DEFAULT_WEB_AUTHN_PRECOMPILE,o=Ae.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER){if(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");const l=L("0x8d0dc49f",["address[]"],[[a]]);let c,d=!1;const u=[];for(const t of e)"string"!=typeof t?d=!0:u.push(t);if(d){const d=[];d.push({to:n,value:0n,data:l,operation:T.Delegate});const u=[];let f=0;for(const t of e)if("string"!=typeof t){if(f>0)throw RangeError("Only one WebAuthn owner can be set during initialization");const e=L("0x0dd9692f",["uint256","uint256","uint176"],[t.x,t.y,"0x"+s.slice(-4)+o.slice(2)]);d.push({to:i,value:0n,data:e,operation:T.Delegate}),u.push(i),f++}else u.push(t);c=[u,t,r,L("0x8d80ff0a",["bytes"],[ue(d)]),a,m,0,m]}else c=[u,t,n,l,a,m,0,m];return L(Ae.initializerFunctionSelector,Ae.initializerFunctionInputAbi,c)}static createFactoryAddressAndData(e,t={},a,n){var r,i,s,o,l,c,d,u;if(e.length<1)throw RangeError("There should be at least one owner");const f=null!=(r=t.threshold)?r:1,h=null!=(i=t.c2Nonce)?i:0;if(f<1)throw RangeError("threshold should be at least one");if(f>e.length)throw RangeError("threshold can't be larger than number of owners");if(h<0n)throw RangeError("c2Nonce can't be negative");const A=Ae.createBaseInitializerCallData(e,null!=(s=t.threshold)?s:1,a,n,null!=(o=t.multisendContractAddress)?o:Ae.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(l=t.webAuthnSharedSigner)?l:Ae.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(c=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?c:Ae.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(d=t.eip7212WebAuthnContractVerifierForSharedSigner)?d:Ae.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);let p;p=null!=t.safeAccountFactoryAddress?new he(t.safeAccountFactoryAddress):new he;const m=null!=(u=t.safeAccountSingleton)?u:Ae.DEFAULT_SAFE_SINGLETON,y=p.getFactoryGeneratorFunctionCallData([m.singletonAddress,A,h]);return[p.address,y]}prependTokenPaymasterApproveToCallData(e,t,a,n,r={}){var i;const s=null!=(i=r.multisendContractAddress)?i:Ae.DEFAULT_MULTISEND_CONTRACT_ADDRESS;return Ae.prependTokenPaymasterApproveToCallDataStatic(e,t,a,n,{multisendContractAddress:s})}async estimateUserOperationGas(e,t,a={}){const n=0xffffffffffffn,r=0xffffffffffffn;if(null!=a.dummySignerSignaturePairs){if(null!=a.expectedSigners)throw RangeError("Can't use both dummySignerSignaturePairs and expectedSigners overrides.");if(a.dummySignerSignaturePairs.length<1)throw RangeError("Number of dummy signers signature pairs can't be less than 1");e.signature=Ae.formatSignaturesToUseroperationSignature(a.dummySignerSignaturePairs,{validAfter:n,validUntil:r})}else if(null!=a.expectedSigners){let t;t="initCode"in e?e.initCode:e.factory;const i=Ae.createDummySignerSignaturePairForExpectedSigners(a.expectedSigners,{isInit:null!=t&&"0x"!=t,webAuthnSharedSigner:a.webAuthnSharedSigner,eip7212WebAuthnPrecompileVerifier:a.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:a.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:a.webAuthnSignerFactory,webAuthnSignerSingleton:a.webAuthnSignerSingleton,validAfter:n,validUntil:r});e.signature=Ae.formatSignaturesToUseroperationSignature(i,{validAfter:n,validUntil:r})}else e.signature.length<3&&(e.signature=Ae.formatSignaturesToUseroperationSignature([ce],{validAfter:n,validUntil:r}));const i=new Z(t),s=e.maxFeePerGas,o=e.maxPriorityFeePerGas;e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n;const l=await i.estimateUserOperationGas(e,this.entrypointAddress,a.stateOverrideSet);e.maxFeePerGas=s,e.maxPriorityFeePerGas=o;const c=BigInt(l.preVerificationGas);let d;return d=null!=a.dummySignerSignaturePairs?BigInt(l.verificationGasLimit)+55000n*BigInt(a.dummySignerSignaturePairs.length):BigInt(l.verificationGasLimit),[c,d,BigInt(l.callGasLimit)]}async createBaseUserOperationAndFactoryAddressAndFactoryData(e,t,a,n,r={}){var i,s,o,l,c,d,u,f,h,A,m,y,g,E,S,b,_;if(e.length<1)throw RangeError("There should be at least one transaction");const T=null!=(i=r.webAuthnSharedSigner)?i:Ae.DEFAULT_WEB_AUTHN_SHARED_SIGNER,w=null!=(s=r.safeModuleExecutorFunctionSelector)?s:Ae.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,F=null!=(o=r.multisendContractAddress)?o:Ae.DEFAULT_MULTISEND_CONTRACT_ADDRESS;let v=null,R=null;if(null==r.nonce){if(null==a)throw new x("BAD_DATA","providerRpc cant't be null if nonce is not overriden");R=C(a,this.entrypointAddress,this.accountAddress)}else v=r.nonce;if("bigint"==typeof r.maxFeePerGas&&r.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof r.maxPriorityFeePerGas&&r.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");let P=D.maxFeePerGas,G=D.maxPriorityFeePerGas,U=null;null!=r.maxFeePerGas&&null!=r.maxPriorityFeePerGas||(U=W(a,r.polygonGasStation,r.gasLevel)),null!=U&&null!=R?await Promise.all([R,U]).then(e=>{v=e[0],[P,G]=e[1]}):null!=U?[P,G]=await U:null!=R&&(v=await R),P=null!=(l=r.maxFeePerGas)?l:P*BigInt(Math.floor(((null!=(c=r.maxFeePerGasPercentageMultiplier)?c:0)+100)/100)),G=null!=(d=r.maxPriorityFeePerGas)?d:G*BigInt(Math.floor(((null!=(u=r.maxPriorityFeePerGasPercentageMultiplier)?u:0)+100)/100));const I=null!=(f=r.eip7212WebAuthnPrecompileVerifier)?f:Ae.DEFAULT_WEB_AUTHN_PRECOMPILE,O=null!=(h=r.eip7212WebAuthnContractVerifier)?h:Ae.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,M=null!=(A=r.webAuthnSignerFactory)?A:Ae.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,V=null!=(m=r.webAuthnSignerSingleton)?m:Ae.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;let B=this.factoryAddress,N=this.factoryData;if(null==v)throw RangeError("failed to determine nonce");if(v<0n)throw RangeError("nonce can't be negative");if(v>0n)B=null,N=null;else if(this.isInitWebAuthn){if(null==this.x||null==this.y)throw RangeError("Invalide account initialization with Webauthnn signer.Webauthnn signer publickey can be null!!");const t=Ae.createDeployWebAuthnVerifierMetaTransaction(this.x,this.y,{eip7212WebAuthnPrecompileVerifier:I,eip7212WebAuthnContractVerifier:O,webAuthnSignerFactory:M}),a=L("0xe318b52b",["address","address","address"],["0x0000000000000000000000000000000000000001",T,Ae.createWebAuthnSignerVerifierAddress(this.x,this.y,{eip7212WebAuthnPrecompileVerifier:I,eip7212WebAuthnContractVerifier:O,webAuthnSignerFactory:M,webAuthnSignerSingleton:V})]);e=[t,{to:this.accountAddress,value:0n,data:a}].concat(e)}let k="0x";k=null==r.callData?1==e.length?Ae.createAccountCallDataSingleTransaction(e[0],{safeModuleExecutorFunctionSelector:w}):Ae.createAccountCallDataBatchTransactions(e,{safeModuleExecutorFunctionSelector:w,multisendContractAddress:F}):r.callData,null!=this.onChainIdentifier&&(k+=this.onChainIdentifier);const H=p({},D,{sender:this.accountAddress,nonce:v,callData:k,maxFeePerGas:P,maxPriorityFeePerGas:G});let z=D.preVerificationGas,Y=D.verificationGasLimit,j=D.callGasLimit;if(null==r.preVerificationGas||null==r.verificationGasLimit||null==r.callGasLimit){if(null==n)throw new x("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{H.callGasLimit=0n,H.verificationGasLimit=0n,H.preVerificationGas=0n;const e=H.maxFeePerGas,a=H.maxPriorityFeePerGas;let i;if(H.maxFeePerGas=0n,H.maxPriorityFeePerGas=0n,t){let e="0x";null!=B&&(e=B,null!=N&&(e+=N.slice(2))),i=p({},H,{initCode:e,paymasterAndData:"0x"})}else i=p({},H,{factory:B,factoryData:N,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null});const s=0xffffffffffffn,o=0xffffffffffffn;let l;if(null!=r.dummySignerSignaturePairs){if(null!=r.expectedSigners)throw RangeError("Can't use both dummySignerSignaturePairs and expectedSigners overrides.");if(r.dummySignerSignaturePairs.length<1)throw RangeError("Number of dummySignerSignaturePairs can't be less than 1");l=r.dummySignerSignaturePairs}else l=null==r.expectedSigners?[ce]:Ae.createDummySignerSignaturePairForExpectedSigners(r.expectedSigners,{isInit:null!=B&&"0x"!=B,webAuthnSharedSigner:T,eip7212WebAuthnPrecompileVerifier:I,eip7212WebAuthnContractVerifier:O,webAuthnSignerFactory:M,webAuthnSignerSingleton:V,validAfter:s,validUntil:o});H.signature=Ae.formatSignaturesToUseroperationSignature(l,{validAfter:s,validUntil:o,webAuthnSharedSigner:T}),[z,Y,j]=await this.estimateUserOperationGas(i,n,{stateOverrideSet:r.state_override_set}),Y+=55000n*BigInt(l.length),H.maxFeePerGas=e,H.maxPriorityFeePerGas=a}}if("bigint"==typeof r.preVerificationGas&&r.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof r.verificationGasLimit&&r.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof r.callGasLimit&&r.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return H.preVerificationGas=null!=(y=r.preVerificationGas)?y:z*BigInt(Math.floor(((null!=(g=r.preVerificationGasPercentageMultiplier)?g:0)+100)/100)),H.verificationGasLimit=null!=(E=r.verificationGasLimit)?E:Y*BigInt(Math.floor(((null!=(S=r.verificationGasLimitPercentageMultiplier)?S:0)+100)/100)),H.callGasLimit=null!=(b=r.callGasLimit)?b:j*BigInt(Math.floor(((null!=(_=r.callGasLimitPercentageMultiplier)?_:0)+100)/100)),[H,B,N]}signUserOperation(e,t,a,n={}){var r,i;const o=null!=(r=n.validAfter)?r:0n,l=null!=(i=n.validUntil)?i:0n;if(t.length<1)throw RangeError("There should be at least one privateKey");if(a<0n)throw RangeError("chainId can't be negative");if(o<0n)throw RangeError("validAfter can't be negative");if(l<0n)throw RangeError("validUntil can't be negative");const c=Ae.getUserOperationEip712Hash(e,a,{validAfter:o,validUntil:l,entrypointAddress:this.entrypointAddress,safe4337ModuleAddress:this.safe4337ModuleAddress}),d=[],u=[];for(const e of t){const t=new s(e),a=t.signingKey.sign(c).serialized;d.push(t.address),u.push(a)}return Ae.formatEip712SignaturesToUseroperationSignature(d,u,{validAfter:o,validUntil:l})}static createWebAuthnSignerVerifierAddress(e,t,n={}){var r,i,s,o;const l=null!=(r=n.eip7212WebAuthnPrecompileVerifier)?r:Ae.DEFAULT_WEB_AUTHN_PRECOMPILE,u=null!=(i=n.eip7212WebAuthnContractVerifier)?i:Ae.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,f=null!=(s=n.webAuthnSignerFactory)?s:Ae.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,h=null!=(o=n.webAuthnSignerSingleton)?o:Ae.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;if(42!=l.length||l.slice(0,38)!=m.slice(0,38))throw RangeError("Invalide precompile address. It should have the format 0x000000000000000000000000000000000000____");const A=a(c(["bytes","uint256","uint256","uint256","uint256"],[Ae.DEFAULT_WEB_AUTHN_SIGNER_PROXY_CREATION_CODE,h,e,t,"0x"+l.slice(-4)+u.slice(2)]));return"0x"+d(["bytes1","address","bytes32","bytes32"],["0xff",f,"0x0000000000000000000000000000000000000000000000000000000000000000",A]).slice(-40)}static formatSignaturesToUseroperationSignature(e,t={}){var a,n;const r=null!=(a=t.validAfter)?a:0n,i=null!=(n=t.validUntil)?n:0n,s=this.buildSignaturesFromSingerSignaturePairs(e,t);return c(["uint48","uint48","bytes"],[r,i,s])}static getSignerLowerCaseAddress(e,t={}){if("string"==typeof e)return e.toLowerCase();{var a,n,r,i;const s=null!=(a=t.eip7212WebAuthnPrecompileVerifier)?a:Ae.DEFAULT_WEB_AUTHN_PRECOMPILE,o=null!=(n=t.eip7212WebAuthnContractVerifier)?n:Ae.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,l=null!=(r=t.webAuthnSignerFactory)?r:Ae.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,c=null!=(i=t.webAuthnSignerSingleton)?i:Ae.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;return Ae.createWebAuthnSignerVerifierAddress(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:s,eip7212WebAuthnContractVerifier:o,webAuthnSignerFactory:l,webAuthnSignerSingleton:c}).toLowerCase()}}static sortSignatures(e,t={}){e.sort((e,a)=>Ae.getSignerLowerCaseAddress(e.signer,t).localeCompare(Ae.getSignerLowerCaseAddress(a.signer,t)))}static buildSignaturesFromSingerSignaturePairs(e,t={}){Ae.sortSignatures(e,t);const a=65*e.length,{segments:n}=e.reduce(({segments:e,offset:n},{signer:r,signature:i,isContractSignature:s})=>{if(s=s||"string"!=typeof r){if("string"!=typeof r){if(null==t.isInit)throw RangeError("Must define isInit parameter when using WebAuthn");if(t.isInit){var o;r=null!=(o=t.webAuthnSharedSigner)?o:Ae.DEFAULT_WEB_AUTHN_SHARED_SIGNER}else{var l,c,d,u;const e=null!=(l=t.eip7212WebAuthnPrecompileVerifier)?l:Ae.DEFAULT_WEB_AUTHN_PRECOMPILE,a=null!=(c=t.eip7212WebAuthnContractVerifier)?c:Ae.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,n=null!=(d=t.webAuthnSignerFactory)?d:Ae.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,i=null!=(u=t.webAuthnSignerSingleton)?u:Ae.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;r=Ae.createWebAuthnSignerVerifierAddress(r.x,r.y,{eip7212WebAuthnPrecompileVerifier:e,eip7212WebAuthnContractVerifier:a,webAuthnSignerFactory:n,webAuthnSignerSingleton:i})}}return{segments:[...e,h.solidityPacked(["uint256","uint256","uint8"],[r,a+n,0])],offset:n+32+h.dataLength(i)}}return{segments:[...e,h.solidityPacked(["bytes"],[i])],offset:n}},{segments:[],offset:0});return h.concat([...n,...e.map(({signer:e,signature:t,isContractSignature:a})=>(a=a||"string"!=typeof e)?h.solidityPacked(["uint256","bytes"],[h.dataLength(t),t]):"0x")])}static createWebAuthnSignature(e){return h.AbiCoder.defaultAbiCoder().encode(["bytes","bytes","uint256[2]"],[new Uint8Array(e.authent