abstractionkit 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.modern.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{keccak256 as e,AbiCoder as t,id as a,JsonRpcProvider as r,getBytes as n,solidityPacked as i,solidityPackedKeccak256 as s,getAddress as o,TypedDataEncoder as l,Wallet as c,ethers as d}from"ethers";import*as u from"isomorphic-unfetch";class A{constructor(e){this.accountAddress=void 0,this.accountAddress=e}}function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e},f.apply(this,arguments)}A.proxyByteCode=void 0,A.initializerFunctionSelector=void 0,A.initializerFunctionInputAbi=void 0,A.executorFunctionSelector=void 0,A.executorFunctionInputAbi=void 0;const p="0x0000000000000000000000000000000000000000",h="0x0000000071727De22E5E9d8BAf0edAc6f37da032",E="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",g={sender:p,nonce:0n,callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,signature:"0x"},m={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"}]},y={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"}]},S="0x0000000000000000000000000000000000000100";var D,_,b;!function(e){e[e.Call=0]="Call",e[e.Delegate=1]="Delegate"}(D||(D={})),function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(_||(_={})),function(e){e.Mainnet="v2",e.ZkMainnet="zkevm",e.Amoy="amoy",e.Cardona="cardona"}(b||(b={}));const T={"-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 F extends Error{constructor(e,t,a={}){const{cause:r,errno:n,context:i}=a;super(t,{cause:r}),this.code=void 0,this.context=void 0,this.errno=void 0,this.name=this.constructor.name,this.code=e,this.errno=n,this.context=i}stringify(){return JSON.stringify(this,["name","code","message","cause","errno","context"])}}function w(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 U(a,r,n){let i;i=e("initCode"in a?function(a){const r=[a.sender,a.nonce,e(a.initCode),e(a.callData),a.callGasLimit,a.verificationGasLimit,a.preVerificationGas,a.maxFeePerGas,a.maxPriorityFeePerGas,e(a.paymasterAndData)];return t.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],r)}(a):function(a){const r=t.defaultAbiCoder();let n="0x";null!=a.factory&&(n=a.factory,null!=a.factoryData&&(n+=a.factoryData.slice(2)));const i="0x"+r.encode(["uint128"],[a.verificationGasLimit]).slice(34)+r.encode(["uint128"],[a.callGasLimit]).slice(34),s="0x"+r.encode(["uint128"],[a.maxPriorityFeePerGas]).slice(34)+r.encode(["uint128"],[a.maxFeePerGas]).slice(34);let o="0x";null!=a.paymaster&&(o=a.paymaster,null!=a.paymasterVerificationGasLimit&&(o+=r.encode(["uint128"],[a.paymasterVerificationGasLimit]).slice(34)),null!=a.paymasterPostOpGasLimit&&(o+=r.encode(["uint128"],[a.paymasterPostOpGasLimit]).slice(34)),null!=a.paymasterData&&(o+=a.paymasterData.slice(2)));const l=[a.sender,a.nonce,e(n),e(a.callData),i,a.preVerificationGas,s,e(o)];return r.encode(["address","uint256","bytes32","bytes32","bytes32","uint256","bytes32","bytes32"],l)}(a));const s=t.defaultAbiCoder().encode(["bytes32","address","uint256"],[i,r,n]);return e(s)}function R(e,a,r){return e+t.defaultAbiCoder().encode(a,r).slice(2)}async function v(e,t,a){const r=u.default||u,n={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:t,params:a,id:(new Date).getTime(),jsonrpc:"2.0"},(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t),redirect:"follow"},i=await r(e,n),s=await i.json();if("result"in s)return s.result;{const t=s.error,a=String(t.code);throw new F(a in T?T[a]:"UNKNOWN_ERROR",t.message,{errno:t.code,context:{url:e,requestOptions:JSON.stringify(n)}})}}function L(e){return a(e).slice(0,10)}async function x(e,t,a,r=0){const n=[{from:"0x0000000000000000000000000000000000000000",to:t,data:R(L("getNonce(address,uint192)"),["address","uint192"],[a,r])},"latest"];try{const t=await v(e,"eth_call",n);if("string"!=typeof t)throw new F("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(t)});try{return BigInt(t)}catch(e){const t=w(e);throw new F("BAD_DATA","getNonce returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","getNonce failed",{cause:t})}}async function P(e,t=_.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=w(e);throw new F("BAD_DATA","fetching gas prices from node failed.",{cause:t})}}function G(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 C(e,t,a){return(await O(e,t,a)).deposit}async function O(e,a,r){const n={from:"0x0000000000000000000000000000000000000000",to:r,data:R("0x5287ce12",["address"],[a])};try{const a=await I(e,n,"latest"),r=t.defaultAbiCoder().decode(["uint256","bool","uint112","uint32","uint48"],a);if(5!==r.length)throw new F("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){const t=w(e);throw new F("BAD_DATA","getDepositInfo returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","getDepositInfo failed",{cause:t})}}async function I(e,t,a,r){let n=[];n=null==r?[t,a]:[t,a,r];try{const t=await v(e,"eth_call",n);if("string"!=typeof t)throw new F("BAD_DATA","eth_call returned ill formed data",{context:JSON.stringify(t)});try{return t}catch(e){const t=w(e);throw new F("BAD_DATA","eth_call returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","eth_call failed",{cause:t})}}async function M(e,t,a){const r=[t,a];try{const t=await v(e,"eth_getCode",r);if("string"!=typeof t)throw new F("BAD_DATA","eth_getCode returned ill formed data",{context:JSON.stringify(t)});try{return t}catch(e){const t=w(e);throw new F("BAD_DATA","eth_getCode returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","eth_getCode failed",{cause:t})}}var N;!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(N||(N={}));const V={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x47003599ffa7e9198f321afa774e34a12a959844efd6363b88896e9c24ed33cf4e1be876ef123a3c4467e7d451511434039539699f2baa2f44955fa3d1c1c6d81c",isContractSignature:!1},B={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e06c92f0ac5c4ef9e74721c23d80a9fc12f259ca84afb160f0890483539b9e6080d824c0e6c795157ad5d1ee5eff1ceeb3031009a595f9360919b83dd411c5a78d0000000000000000000000000000000000000000000000000000000000000025a24f744b28d73f066bf3203d145765a7bc735e6328168c8b03e476da3ad0d8fe0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e226f726967696e223a2268747470733a2f2f736166652e676c6f62616c220000",isContractSignature:!0};function W(e){return"0x"+e.map(e=>function(e){var t;const a=null!=(t=e.operation)?t:D.Call,r=n(e.data);return i(["uint8","address","uint256","uint256","bytes"],[a,e.to,e.value,r.length,r]).slice(2)}(e)).join("")}class H{constructor(e){this.rpcUrl=void 0,this.rpcUrl=e}async chainId(){try{const e=await v(this.rpcUrl,"eth_chainId",[]);if("string"==typeof e)return e;throw new F("BAD_DATA","bundler eth_chainId rpc call failed")}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}}async supportedEntryPoints(){try{return await v(this.rpcUrl,"eth_supportedEntryPoints",[])}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}}async estimateUserOperationGas(e,t,a){try{let r={};r=void 0===a?await v(this.rpcUrl,"eth_estimateUserOperationGas",[e,t]):await v(this.rpcUrl,"eth_estimateUserOperationGas",[e,t,a]);const n=r;return{callGasLimit:BigInt(n.callGasLimit),preVerificationGas:BigInt(n.preVerificationGas),verificationGasLimit:BigInt(n.verificationGasLimit)}}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}}async sendUserOperation(e,t){try{return await v(this.rpcUrl,"eth_sendUserOperation",[e,t])}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}}async getUserOperationReceipt(e){try{const t=await v(this.rpcUrl,"eth_getUserOperationReceipt",[e]);if(null!=t){const e=f({},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 f({},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=w(t);throw new F("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:a,context:{useroperationhash:e}})}}async getUserOperationByHash(e){try{const t=await v(this.rpcUrl,"eth_getUserOperationByHash",[e]);return null!=t?f({},t,{blockNumber:null==t.blockNumber?null:BigInt(t.blockNumber)}):null}catch(t){const a=w(t);throw new F("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:a,context:{useroperationhash:e}})}}}class k{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 F("TIMEOUT","can't find useroperation",{context:this.userOperationHash})}}class z{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 R(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e)}}class Y extends z{constructor(e=Y.DEFAULT_FACTORY_ADDRESS){super(e,"0x1688f0b9",["address","bytes","uint256"])}}Y.DEFAULT_FACTORY_ADDRESS="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67";class J extends A{constructor(e,t,a){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.entrypointAddress=a,this.safe4337ModuleAddress=t,this.factoryAddress=null,this.factoryData=null,this.isInitWebAuthn=!1}static createProxyAddress(t,a={}){var r,n,l;const c=null!=(r=a.c2Nonce)?r:0n;if(c<0n)throw RangeError("c2Nonce can't be negative");const d=null!=(n=a.safeFactoryAddress)?n:Y.DEFAULT_FACTORY_ADDRESS,u=null!=(l=a.singletonInitHash)?l:J.DEFAULT_SAFE_SINGLETON.singletonInitHash,A=e(i(["bytes32","uint256"],[e(t),c])),f=s(["bytes1","address","bytes32","bytes32"],["0xff",d,A,u]).slice(-40);return o("0x"+f)}static createAccountCallDataSingleTransaction(e,t={}){var a,r,n,i;const s=null!=(a=e.value)?a:0,o=null!=(r=e.data)?r:"0x",l=null!=(n=e.operation)?n:D.Call,c=null!=(i=t.safeModuleExecutorFunctionSelector)?i:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR;return J.createAccountCallData(e.to,s,o,l,{safeModuleExecutorFunctionSelector:c})}static createAccountCallDataBatchTransactions(e,t={}){var a,r;if(e.length<1)throw RangeError("There should be at least one metaTransaction");const n=null!=(a=t.safeModuleExecutorFunctionSelector)?a:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,i=null!=(r=t.multisendContractAddress)?r:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,s=R("0x8d80ff0a",["bytes"],[W(e)]);return J.createAccountCallData(i,0n,s,D.Delegate,{safeModuleExecutorFunctionSelector:n})}static createAccountCallData(e,t,a,r,n={}){var i;return R(null!=(i=n.safeModuleExecutorFunctionSelector)?i:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,J.executorFunctionInputAbi,[e,t,a,r])}static decodeAccountCallData(e){let a=null;if(e.startsWith(N.executeUserOpWithErrorString)?a=N.executeUserOpWithErrorString:e.startsWith(N.executeUserOp)&&(a=N.executeUserOp),null!=a){const r=t.defaultAbiCoder(),n="0x"+e.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);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 F("BAD_DATA","Invalid calldata, should start with "+N.executeUserOpWithErrorString+" or "+N.executeUserOp,{context:{callData:e}})}static prependTokenPaymasterApproveToCallDataStatic(e,a,r,n,i={}){var s;const o=null!=(s=i.multisendContractAddress)?s:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,[l,c]=J.decodeAccountCallData(e),d=W([{to:a,value:0n,data:R(L("approve(address,uint256)"),["address","uint256"],[r,n]),operation:D.Call}]);let u="";const A="0x8d80ff0a";if(l.data.startsWith(A)){const e=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(l.data);u=e+d.slice(2)}else u=W([l])+d.slice(2);const f=R(A,["bytes"],[u]);return J.createAccountCallData(o,0n,f,D.Delegate,{safeModuleExecutorFunctionSelector:c})}static formatEip712SignaturesToUseroperationSignature(e,t,a={}){var r,n;if(e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");const i=null!=(r=a.validAfter)?r:0n,s=null!=(n=a.validUntil)?n: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 J.formatEip712SingleSignatureToUseroperationSignature(c,{validAfter:i,validUntil:s})}static getUserOperationEip712Hash(e,t,a={}){return"initCode"in e?J.getUserOperationEip712Hash_V6(e,t,a):J.getUserOperationEip712Hash_V7(e,t,a)}static getUserOperationEip712Data(e,t,a){if("initCode"in e){const r=J.getUserOperationEip712Data_V6(e,t,a);return{domain:r.domain,types:r.types,messageValue:r.messageValue}}{const r=J.getUserOperationEip712Data_V7(e,t,a);return{domain:r.domain,types:r.types,messageValue:r.messageValue}}}static getUserOperationEip712Data_V6(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n: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:m,messageValue:u}}static getUserOperationEip712Hash_V6(e,t,a={}){const r=J.getUserOperationEip712Data_V6(e,t,a);return l.hash(r.domain,r.types,r.messageValue)}static getUserOperationEip712Data_V7(e,a,r={}){var n,i,s,o;const l=null!=(n=r.validAfter)?n:0n,c=null!=(i=r.validUntil)?i:0n,d=null!=(s=r.entrypointAddress)?s:h,u=null!=(o=r.safe4337ModuleAddress)?o:"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",A=t.defaultAbiCoder();let f="0x";null!=e.factory&&(f=e.factory,null!=e.factoryData&&(f+=e.factoryData.slice(2)));let p="0x";null!=e.paymaster&&(p=e.paymaster,null!=e.paymasterVerificationGasLimit&&(p+=A.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(p+=A.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(p+=e.paymasterData.slice(2)));const E={safe:e.sender,nonce:e.nonce,initCode:f,callData:e.callData,verificationGasLimit:e.verificationGasLimit,callGasLimit:e.callGasLimit,preVerificationGas:e.preVerificationGas,maxPriorityFeePerGas:e.maxPriorityFeePerGas,maxFeePerGas:e.maxFeePerGas,paymasterAndData:p,validAfter:l,validUntil:c,entryPoint:d};return{domain:{chainId:Number(a),verifyingContract:u},types:y,messageValue:E}}static getUserOperationEip712Hash_V7(e,t,a={}){const r=J.getUserOperationEip712Data_V7(e,t,a);return l.hash(r.domain,r.types,r.messageValue)}static formatEip712SingleSignatureToUseroperationSignature(e,t={}){var a,r;const n=null!=(a=t.validAfter)?a:0n,s=null!=(r=t.validUntil)?r:0n;if(n<0n)throw RangeError("validAfter can't be negative");if(s<0n)throw RangeError("validUntil can't be negative");return i(["uint48","uint48","bytes"],[n,s,e])}async sendUserOperation(e,t){const a=new H(t),r=await a.sendUserOperation(e,this.entrypointAddress);return new k(r,a,this.entrypointAddress)}static createAccountAddressAndFactoryAddressAndData(e,t,a,r){var n,i,s,o,l,c,d,u;if(e.length<1)throw RangeError("There should be at least one owner");const A=J.createBaseInitializerCallData(e,null!=(n=t.threshold)?n:1,a,r,null!=(i=t.multisendContractAddress)?i:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(s=t.webAuthnSharedSigner)?s:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(o=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?o:J.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(l=t.eip7212WebAuthnContractVerifierForSharedSigner)?l:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);let f;f=null!=t.safeAccountFactoryAddress?new Y(t.safeAccountFactoryAddress):new Y;const p=null!=(c=t.safeAccountSingleton)?c:J.DEFAULT_SAFE_SINGLETON,h=this.createProxyAddress(A,{c2Nonce:null!=(d=t.c2Nonce)?d:0n,safeFactoryAddress:f.address,singletonInitHash:p.singletonInitHash}),E=[p.singletonAddress,A,null!=(u=t.c2Nonce)?u:0n],g=f.getFactoryGeneratorFunctionCallData(E);return[h,f.address,g]}static createBaseInitializerCallData(e,t,a,r,n=J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,i=J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,s=J.DEFAULT_WEB_AUTHN_PRECOMPILE,o=J.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=R("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:r,value:0n,data:l,operation:D.Delegate});const u=[];let A=0;for(const t of e)if("string"!=typeof t){if(A>0)throw RangeError("Only one WebAuthn owner can be set during initialization");const e=R("0x0dd9692f",["uint256","uint256","uint176"],[t.x,t.y,"0x"+s.slice(-4)+o.slice(2)]);d.push({to:i,value:0n,data:e,operation:D.Delegate}),u.push(i),A++}else u.push(t);c=[u,t,n,R("0x8d80ff0a",["bytes"],[W(d)]),a,p,0,p]}else c=[u,t,r,l,a,p,0,p];return R(J.initializerFunctionSelector,J.initializerFunctionInputAbi,c)}static createFactoryAddressAndData(e,t={},a,r){var n,i,s,o,l,c,d,u;if(e.length<1)throw RangeError("There should be at least one owner");const A=null!=(n=t.threshold)?n:1,f=null!=(i=t.c2Nonce)?i:0;if(A<1)throw RangeError("threshold should be at least one");if(A>e.length)throw RangeError("threshold can't be larger than number of owners");if(f<0n)throw RangeError("c2Nonce can't be negative");const p=J.createBaseInitializerCallData(e,null!=(s=t.threshold)?s:1,a,r,null!=(o=t.multisendContractAddress)?o:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(l=t.webAuthnSharedSigner)?l:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(c=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?c:J.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(d=t.eip7212WebAuthnContractVerifierForSharedSigner)?d:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);let h;h=null!=t.safeAccountFactoryAddress?new Y(t.safeAccountFactoryAddress):new Y;const E=null!=(u=t.safeAccountSingleton)?u:J.DEFAULT_SAFE_SINGLETON,g=h.getFactoryGeneratorFunctionCallData([E.singletonAddress,p,f]);return[h.address,g]}prependTokenPaymasterApproveToCallData(e,t,a,r,n={}){var i;const s=null!=(i=n.multisendContractAddress)?i:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS;return J.prependTokenPaymasterApproveToCallDataStatic(e,t,a,r,{multisendContractAddress:s})}async estimateUserOperationGas(e,t,a={}){const r=0xffffffffffffn,n=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=J.formatSignaturesToUseroperationSignature(a.dummySignerSignaturePairs,{validAfter:r,validUntil:n})}else if(null!=a.expectedSigners){let t;t="initCode"in e?e.initCode:e.factory;const i=J.createDummySignerSignaturePairForExpectedSigners(a.expectedSigners,{isInit:null!=t&&"0x"!=t,webAuthnSharedSigner:a.webAuthnSharedSigner,eip7212WebAuthnPrecompileVerifier:a.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:a.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:a.webAuthnSignerFactory,webAuthnSignerSingleton:a.webAuthnSignerSingleton,validAfter:r,validUntil:n});e.signature=J.formatSignaturesToUseroperationSignature(i,{validAfter:r,validUntil:n})}else e.signature.length<3&&(e.signature=J.formatSignaturesToUseroperationSignature([V],{validAfter:r,validUntil:n}));const i=new H(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,r,n={}){var i,s,o,l,c,d,u,A,p,h,E,m,y,S,D,_,b;if(e.length<1)throw RangeError("There should be at least one transaction");const T=null!=(i=n.webAuthnSharedSigner)?i:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,w=null!=(s=n.safeModuleExecutorFunctionSelector)?s:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,U=null!=(o=n.multisendContractAddress)?o:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS;let v=null,L=null;if(null==n.nonce){if(null==a)throw new F("BAD_DATA","providerRpc cant't be null if nonce is not overriden");L=x(a,this.entrypointAddress,this.accountAddress)}else v=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 P=g.maxFeePerGas,G=g.maxPriorityFeePerGas,C=null;null!=n.maxFeePerGas&&null!=n.maxPriorityFeePerGas||(C=J.handlefetchGasPrice(a,n.polygonGasStation,n.gasLevel)),null!=C&&null!=L?await Promise.all([L,C]).then(e=>{v=e[0],[P,G]=e[1]}):null!=C?[P,G]=await C:null!=L&&(v=await L),P=null!=(l=n.maxFeePerGas)?l:P*BigInt(Math.floor(((null!=(c=n.maxFeePerGasPercentageMultiplier)?c:0)+100)/100)),G=null!=(d=n.maxPriorityFeePerGas)?d:G*BigInt(Math.floor(((null!=(u=n.maxPriorityFeePerGasPercentageMultiplier)?u:0)+100)/100));const O=null!=(A=n.eip7212WebAuthnPrecompileVerifier)?A:J.DEFAULT_WEB_AUTHN_PRECOMPILE,I=null!=(p=n.eip7212WebAuthnContractVerifier)?p:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,M=null!=(h=n.webAuthnSignerFactory)?h:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,N=null!=(E=n.webAuthnSignerSingleton)?E:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;let B=this.factoryAddress,W=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,W=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=J.createDeployWebAuthnVerifierMetaTransaction(this.x,this.y,{eip7212WebAuthnPrecompileVerifier:O,eip7212WebAuthnContractVerifier:I,webAuthnSignerFactory:M}),a=R("0xe318b52b",["address","address","address"],["0x0000000000000000000000000000000000000001",T,J.createWebAuthnSignerVerifierAddress(this.x,this.y,{eip7212WebAuthnPrecompileVerifier:O,eip7212WebAuthnContractVerifier:I,webAuthnSignerFactory:M,webAuthnSignerSingleton:N})]);e=[t,{to:this.accountAddress,value:0n,data:a}].concat(e)}let H="0x";H=null==n.callData?1==e.length?J.createAccountCallDataSingleTransaction(e[0],{safeModuleExecutorFunctionSelector:w}):J.createAccountCallDataBatchTransactions(e,{safeModuleExecutorFunctionSelector:w,multisendContractAddress:U}):n.callData;const k=f({},g,{sender:this.accountAddress,nonce:v,callData:H,maxFeePerGas:P,maxPriorityFeePerGas:G});let z=g.preVerificationGas,Y=g.verificationGasLimit,X=g.callGasLimit;if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit){if(null==r)throw new F("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{k.callGasLimit=0n,k.verificationGasLimit=0n,k.preVerificationGas=0n;const e=k.maxFeePerGas,a=k.maxPriorityFeePerGas;let i;if(k.maxFeePerGas=0n,k.maxPriorityFeePerGas=0n,t){let e="0x";null!=B&&(e=B,null!=W&&(e+=W.slice(2))),i=f({},k,{initCode:e,paymasterAndData:"0x"})}else i=f({},k,{factory:B,factoryData:W,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null});const s=0xffffffffffffn,o=0xffffffffffffn;let l;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 dummySignerSignaturePairs can't be less than 1");l=n.dummySignerSignaturePairs}else l=null==n.expectedSigners?[V]:J.createDummySignerSignaturePairForExpectedSigners(n.expectedSigners,{isInit:null!=B&&"0x"!=B,webAuthnSharedSigner:T,eip7212WebAuthnPrecompileVerifier:O,eip7212WebAuthnContractVerifier:I,webAuthnSignerFactory:M,webAuthnSignerSingleton:N,validAfter:s,validUntil:o});k.signature=J.formatSignaturesToUseroperationSignature(l,{validAfter:s,validUntil:o,webAuthnSharedSigner:T}),[z,Y,X]=await this.estimateUserOperationGas(i,r,{stateOverrideSet:n.state_override_set}),Y+=55000n*BigInt(l.length),k.maxFeePerGas=e,k.maxPriorityFeePerGas=a}}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 k.preVerificationGas=null!=(m=n.preVerificationGas)?m:z*BigInt(Math.floor(((null!=(y=n.preVerificationGasPercentageMultiplier)?y:0)+100)/100)),k.verificationGasLimit=null!=(S=n.verificationGasLimit)?S:Y*BigInt(Math.floor(((null!=(D=n.verificationGasLimitPercentageMultiplier)?D:0)+100)/100)),k.callGasLimit=null!=(_=n.callGasLimit)?_:X*BigInt(Math.floor(((null!=(b=n.callGasLimitPercentageMultiplier)?b:0)+100)/100)),[k,B,W]}static async handlefetchGasPrice(e,t,a=_.Medium){let r,n;if(null!=t)[r,n]=await async function(e,t=_.Medium){const a="https://gasstation.polygon.technology/"+e;try{const e=await fetch(a),r=await e.json();let n;n=t==_.Slow?r.safeLow:t==_.Medium?r.standard:r.fast;let i=BigInt(Math.ceil(1e9*Number(n.maxFee))),s=BigInt(Math.ceil(1e9*Number(n.maxPriorityFee)));return 0n==i&&(i=1n),0n==s&&(s=1n),[i,s]}catch(e){const t=w(e);throw new F("BAD_DATA","fetching gas prices from "+a+" failed.",{cause:t})}}(t,a);else{if(null==e)throw new F("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden");[r,n]=await P(e,a)}return[r,n]}signUserOperation(e,t,a,r={}){var n,i;const s=null!=(n=r.validAfter)?n:0n,o=null!=(i=r.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(s<0n)throw RangeError("validAfter can't be negative");if(o<0n)throw RangeError("validUntil can't be negative");const l=J.getUserOperationEip712Hash(e,a,{validAfter:s,validUntil:o,entrypointAddress:this.entrypointAddress,safe4337ModuleAddress:this.safe4337ModuleAddress}),d=[],u=[];for(const e of t){const t=new c(e),a=t.signingKey.sign(l).serialized;d.push(t.address),u.push(a)}return J.formatEip712SignaturesToUseroperationSignature(d,u,{validAfter:s,validUntil:o})}static createWebAuthnSignerVerifierAddress(t,a,r={}){var n,o,l,c;const d=null!=(n=r.eip7212WebAuthnPrecompileVerifier)?n:J.DEFAULT_WEB_AUTHN_PRECOMPILE,u=null!=(o=r.eip7212WebAuthnContractVerifier)?o:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,A=null!=(l=r.webAuthnSignerFactory)?l:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,f=null!=(c=r.webAuthnSignerSingleton)?c:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;if(42!=d.length||d.slice(0,38)!=p.slice(0,38))throw RangeError("Invalide precompile address. It should have the format 0x000000000000000000000000000000000000____");const h=e(i(["bytes","uint256","uint256","uint256","uint256"],[J.DEFAULT_WEB_AUTHN_SIGNER_PROXY_CREATION_CODE,f,t,a,"0x"+d.slice(-4)+u.slice(2)]));return"0x"+s(["bytes1","address","bytes32","bytes32"],["0xff",A,"0x0000000000000000000000000000000000000000000000000000000000000000",h]).slice(-40)}static formatSignaturesToUseroperationSignature(e,t={}){var a,r;const n=null!=(a=t.validAfter)?a:0n,s=null!=(r=t.validUntil)?r:0n,o=this.buildSignaturesFromSingerSignaturePairs(e,t);return i(["uint48","uint48","bytes"],[n,s,o])}static getSignerLowerCaseAddress(e,t={}){if("string"==typeof e)return e.toLowerCase();{var a,r,n,i;const s=null!=(a=t.eip7212WebAuthnPrecompileVerifier)?a:J.DEFAULT_WEB_AUTHN_PRECOMPILE,o=null!=(r=t.eip7212WebAuthnContractVerifier)?r:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,l=null!=(n=t.webAuthnSignerFactory)?n:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,c=null!=(i=t.webAuthnSignerSingleton)?i:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;return J.createWebAuthnSignerVerifierAddress(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:s,eip7212WebAuthnContractVerifier:o,webAuthnSignerFactory:l,webAuthnSignerSingleton:c}).toLowerCase()}}static sortSignatures(e,t={}){e.sort((e,a)=>J.getSignerLowerCaseAddress(e.signer,t).localeCompare(J.getSignerLowerCaseAddress(a.signer,t)))}static buildSignaturesFromSingerSignaturePairs(e,t={}){J.sortSignatures(e,t);const a=65*e.length,{segments:r}=e.reduce(({segments:e,offset:r},{signer:n,signature:i,isContractSignature:s})=>{if(s=s||"string"!=typeof n){if("string"!=typeof n){if(null==t.isInit)throw RangeError("Must define isInit parameter when using WebAuthn");if(t.isInit){var o;n=null!=(o=t.webAuthnSharedSigner)?o:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER}else{var l,c,u,A;const e=null!=(l=t.eip7212WebAuthnPrecompileVerifier)?l:J.DEFAULT_WEB_AUTHN_PRECOMPILE,a=null!=(c=t.eip7212WebAuthnContractVerifier)?c:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,r=null!=(u=t.webAuthnSignerFactory)?u:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,i=null!=(A=t.webAuthnSignerSingleton)?A:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;n=J.createWebAuthnSignerVerifierAddress(n.x,n.y,{eip7212WebAuthnPrecompileVerifier:e,eip7212WebAuthnContractVerifier:a,webAuthnSignerFactory:r,webAuthnSignerSingleton:i})}}return{segments:[...e,d.solidityPacked(["uint256","uint256","uint8"],[n,a+r,0])],offset:r+32+d.dataLength(i)}}return{segments:[...e,d.solidityPacked(["bytes"],[i])],offset:r}},{segments:[],offset:0});return d.concat([...r,...e.map(({signer:e,signature:t,isContractSignature:a})=>(a=a||"string"!=typeof e)?d.solidityPacked(["uint256","bytes"],[d.dataLength(t),t]):"0x")])}static createWebAuthnSignature(e){return d.AbiCoder.defaultAbiCoder().encode(["bytes","bytes","uint256[2]"],[new Uint8Array(e.authenticatorData),e.clientDataFields,e.rs])}async createSwapOwnerMetaTransactions(e,t,a,r={}){let n,i,s=null;"string"!=typeof t?(n=J.createWebAuthnSignerVerifierAddress(t.x,t.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory,webAuthnSignerSingleton:r.webAuthnSignerSingleton}),(await M(e,n,"latest")).length<3&&(s=J.createDeployWebAuthnVerifierMetaTransaction(t.x,t.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory}))):n=t,i="string"!=typeof a?J.createWebAuthnSignerVerifierAddress(a.x,a.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory,webAuthnSignerSingleton:r.webAuthnSignerSingleton}):a;let o=r.prevOwner;if(null==o){const t=await this.getOwners(e),a=t.indexOf(i);if(-1==a)throw RangeError("oldOwner is not a current owner.");if(0==a)o="0x0000000000000000000000000000000000000001";else{if(!(a>0))throw RangeError("Invalid owner index");o=t[a-1]}}const l=this.createStandardSwapOwnerMetaTransaction(n,i,o);return null==s?[l]:[s,l]}async createRemoveOwnerMetaTransaction(e,t,a,r={}){let n;n="string"!=typeof t?J.createWebAuthnSignerVerifierAddress(t.x,t.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory,webAuthnSignerSingleton:r.webAuthnSignerSingleton}):t;let i=r.prevOwner;if(null==i){const t=await this.getOwners(e),a=t.indexOf(n);if(-1==a)throw RangeError("ownerToDelete is not a current owner.");if(0==a)i="0x0000000000000000000000000000000000000001";else{if(!(a>0))throw RangeError("Invalid owner index");i=t[a-1]}}return this.createStandardRemoveOwnerMetaTransaction(n,a,i)}async createAddOwnerWithThresholdMetaTransactions(e,t,a={}){let r,n=null;if("string"!=typeof e){if(r=J.createWebAuthnSignerVerifierAddress(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:a.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:a.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:a.webAuthnSignerFactory,webAuthnSignerSingleton:a.webAuthnSignerSingleton}),null==a.nodeRpcUrl)throw RangeError("overrides.nodeRpcUrl can't be null if adding a webauthn owner");(await M(a.nodeRpcUrl,r,"latest")).length<3&&(n=J.createDeployWebAuthnVerifierMetaTransaction(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:a.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:a.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:a.webAuthnSignerFactory}))}else r=e;const i=this.createStandardAddOwnerWithThresholdMetaTransaction(r,t);return null==n?[i]:[n,i]}createStandardAddOwnerWithThresholdMetaTransaction(e,t){const a=R("0x0d582f13",["address","uint256"],[e,t]);return{to:this.accountAddress,data:a,value:0n}}createStandardSwapOwnerMetaTransaction(e,t,a){const r=R("0xe318b52b",["address","address","address"],[a,t,e]);return{to:this.accountAddress,data:r,value:0n}}createStandardRemoveOwnerMetaTransaction(e,t,a){const r=R("0xf8dc5dd9",["address","address","uint256"],[a,e,t]);return{to:this.accountAddress,data:r,value:0n}}static createDeployWebAuthnVerifierMetaTransaction(e,t,a={}){var r,n,i;const s=null!=(r=a.eip7212WebAuthnPrecompileVerifier)?r:J.DEFAULT_WEB_AUTHN_PRECOMPILE,o=null!=(n=a.eip7212WebAuthnContractVerifier)?n:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER;return{to:null!=(i=a.webAuthnSignerFactory)?i:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,value:0n,data:R("0x0d2f0489",["uint256","uint256","uint176"],[e,t,"0x"+s.slice(-4)+o.slice(2)])}}async getOwners(e){const a=R(L("getOwners()"),[],[]),r={to:this.accountAddress,data:a},n=await I(e,r,"latest");return t.defaultAbiCoder().decode(["address[]"],n)[0]}async getModules(e,a={}){try{let r=a.start;null==r&&(r="0x0000000000000000000000000000000000000001");let n=a.pageSize;null==n&&(n=10n);const i=R("0xcc2f8452",["address","uint256"],[r,n]),s={to:this.accountAddress,data:i},o=await I(e,s,"latest");if("0x"==o)throw new F("BAD_DATA","getModules retuned an empty result, the target account is probably not deployed yet.");const l=t.defaultAbiCoder().decode(["address[]","address"],o);return[l[0],l[1]]}catch(e){const t=w(e);throw new F("BAD_DATA","getModules failed",{cause:t})}}async isModuleEnabled(e,a){const r=R(L("isModuleEnabled(address)"),["address"],[a]),n={to:this.accountAddress,data:r},i=await I(e,n,"latest");return t.defaultAbiCoder().decode(["bool"],i)[0]}static createDummySignerSignaturePairForExpectedSigners(e,t={}){const a=[...e],r=[];for(let e of a){let a;if("string"==typeof e)a=V;else{if(null==t.isInit)throw RangeError("Must define isInit parameter when using WebAuthn");if(a=B,t.isInit){var n;const e=null!=(n=t.webAuthnSharedSigner)?n:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER;a.signer=e}else{var i,s,o,l;const r=null!=(i=t.eip7212WebAuthnPrecompileVerifier)?i:J.DEFAULT_WEB_AUTHN_PRECOMPILE,n=null!=(s=t.eip7212WebAuthnContractVerifier)?s:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,c=null!=(o=t.webAuthnSignerFactory)?o:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,d=null!=(l=t.webAuthnSignerSingleton)?l:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;a.signer=J.createWebAuthnSignerVerifierAddress(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:r,eip7212WebAuthnContractVerifier:n,webAuthnSignerFactory:c,webAuthnSignerSingleton:d})}}r.push(a)}return r}static async verifyWebAuthnSignatureForMessageHash(e,a,r,n,i={}){var s,o,l;if(66!=r.length||"0x"!=r.slice(0,2))throw RangeError("Invalide messageHash ,must be a 0x prefixed keccak256 hash.");const c=null!=(s=i.eip7212WebAuthnPrecompileVerifier)?s:J.DEFAULT_WEB_AUTHN_PRECOMPILE,d=null!=(o=i.eip7212WebAuthnContractVerifier)?o:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,u=null!=(l=i.webAuthnSignerSingleton)?l:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;if(42!=c.length||c.slice(0,38)!=p.slice(0,38))throw RangeError("Invalide precompile address. It should have the format 0x000000000000000000000000000000000000____");const A="0x1111111111111111111111111111111111111111",f={to:A,data:R("0x1626ba7e",["bytes32","bytes"],[r,n])},h=J.createSafeWebAuthnSignerProxyDeployedByteCode(a,c,d,u),E=await I(e,f,"latest",{[A]:{code:h}});return t.defaultAbiCoder().decode(["bool"],E)[0]}static createSafeWebAuthnSignerProxyDeployedByteCode(e,a,r,n){const i=t.defaultAbiCoder(),s=i.encode(["uint256"],[e.x]),o=i.encode(["uint256"],[e.y]);return"0x608060408190527f"+i.encode(["uint176"],["0x"+a.slice(-4)+r.slice(2)]).slice(2)+"3660b681018290527f"+o.slice(2)+"60a082018190527f"+s.slice(2)+"8285018190527f000000000000000000000000"+n.slice(2)+"9490939192600082376000806056360183885af490503d6000803e8060c3573d6000fd5b503d6000f3fea2646970667358221220ddd9bb059ba7a6497d560ca97aadf4dbf0476f578378554a50d41c6bb654beae64736f6c63430008180033"}static createEnableModuleMetaTransaction(e,t){return{to:t,data:R("0x610b5925",["address"],[e]),value:0n}}async createDisableModuleMetaTransaction(e,t,a,r={}){try{let n=r.prevModuleAddress;if(null==n){const[a,i]=await this.getModules(e,{start:r.modulesStart,pageSize:r.modulesPageSize}),s=a.indexOf(t);if(-1==s)throw RangeError("moduleToDisable "+t+" is not an enabled module.");if(0==s)n="0x0000000000000000000000000000000000000001";else{if(!(s>0))throw RangeError("Invalid module index for "+t);n=a[s-1]}}return J.createStandardDisableModuleMetaTransaction(t,n,a)}catch(e){const t=w(e);throw new F("BAD_DATA","createDisableModuleMetaTransaction failed",{cause:t})}}static createStandardDisableModuleMetaTransaction(e,t,a){return{to:a,data:R("0xe009cfde",["address","address"],[t,e]),value:0n}}}J.DEFAULT_SAFE_SINGLETON={singletonAddress:"0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",singletonInitHash:"0xe298282cefe913ab5d282047161268a8222e4bd4ed106300c547894bbefd31ee"},J.DEFAULT_WEB_AUTHN_SHARED_SIGNER="0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON="0x270D7E4a57E6322f336261f3EaE2BADe72E68d72",J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY="0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf",J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER="0x445a0683e494ea0c5AF3E83c5159fBE47Cf9e765",J.DEFAULT_WEB_AUTHN_PRECOMPILE="0x0000000000000000000000000000000000000000",J.DEFAULT_WEB_AUTHN_SIGNER_PROXY_CREATION_CODE="0x61010060405234801561001157600080fd5b506040516101ee3803806101ee83398101604081905261003091610058565b6001600160a01b0390931660805260a09190915260c0526001600160b01b031660e0526100bc565b6000806000806080858703121561006e57600080fd5b84516001600160a01b038116811461008557600080fd5b60208601516040870151606088015192965090945092506001600160b01b03811681146100b157600080fd5b939692955090935050565b60805160a05160c05160e05160ff6100ef60003960006008015260006031015260006059015260006080015260ff6000f3fe608060408190527f00000000000000000000000000000000000000000000000000000000000000003660b681018290527f000000000000000000000000000000000000000000000000000000000000000060a082018190527f00000000000000000000000000000000000000000000000000000000000000008285018190527f00000000000000000000000000000000000000000000000000000000000000009490939192600082376000806056360183885af490503d6000803e8060c3573d6000fd5b503d6000f3fea2646970667358221220ddd9bb059ba7a6497d560ca97aadf4dbf0476f578378554a50d41c6bb654beae64736f6c63430008180033",J.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",J.initializerFunctionSelector="0xb63e800d",J.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=N.executeUserOpWithErrorString,J.executorFunctionInputAbi=["address","uint256","bytes","uint8"];class X{constructor(e){this.moduleAddress=void 0,this.moduleAddress=e}createEnableModuleMetaTransaction(e){return J.createEnableModuleMetaTransaction(this.moduleAddress,e)}}var j;!function(e){e.After3Minutes="0x949d01d424bE050D09C16025dd007CB59b3A8c66",e.After3Days="0x38275826E1933303E508433dD5f289315Da2541c",e.After7Days="0x088f6cfD8BB1dDb1BB069CCb3fc1A98927D233f2",e.After14Days="0x9BacD92F4687Db306D7ded5d4513a51EA05df25b"}(j||(j={}));class q extends X{constructor(e=q.DEFAULT_SOCIAL_RECOVERY_ADDRESS){super(e)}createConfirmRecoveryMetaTransaction(e,t,a,r){const n=R("0x064e2d0e",["address","address[]","uint256","bool"],[e,t,a,r]);return{to:this.moduleAddress,data:n,value:0n}}createMultiConfirmRecoveryMetaTransaction(e,t,a,r,n){const i=R("0x0728e1e7",["address","address[]","uint256","(address,bytes)","bool"],[e,t,a,r.map(e=>[e.signer,e.signature]),n]);return{to:this.moduleAddress,data:i,value:0n}}createExecuteRecoveryMetaTransaction(e,t,a){const r=R("0xb1f85f69",["address","address[]","uint256"],[e,t,a]);return{to:this.moduleAddress,data:r,value:0n}}createFinalizeRecoveryMetaTransaction(e){const t=R("0x315a7af3",["address"],[e]);return{to:this.moduleAddress,data:t,value:0n}}createCancelRecoveryMetaTransaction(){return{to:this.moduleAddress,data:"0x0ba234d6",value:0n}}createAddGuardianWithThresholdMetaTransaction(e,t){const a=R("0xbe0e54d7",["address","uint256"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}async createRevokeGuardianWithThresholdMetaTransaction(e,t,a,r,n={}){let i=n.prevGuardianAddress;if(null==i){const r=await this.getGuardians(e,t),n=r.indexOf(a);if(-1==n)throw RangeError(a+" is not a current guardian for account : "+t);if(0==n)i="0x0000000000000000000000000000000000000001";else{if(!(n>0))throw RangeError("Invalid guardian index");i=r[n-1]}}return this.createStandardRevokeGuardianWithThresholdMetaTransaction(i,a,r)}createStandardRevokeGuardianWithThresholdMetaTransaction(e,t,a){const r=R("0x936f7d86",["address","address","uint256"],[e,t,a]);return{to:this.moduleAddress,data:r,value:0n}}createChangeThresholdMetaTransaction(e){const t=R("0x694e80c3",["uint256"],[e]);return{to:this.moduleAddress,data:t,value:0n}}async getRecoveryHash(e,t,a,r,n){const i=R("0x5f19df08",["address","address[]","uint256","uint256"],[t,a,r,n]);return I(e,{to:this.moduleAddress,data:i},"latest")}async getRecoveryRequest(e,a){const r=R("0x4f9a28b9",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["uint256","uint256","uint64","address[]"],i);return{guardiansApprovalCount:BigInt(s[0]),newThreshold:BigInt(s[1]),executeAfter:BigInt(s[2]),newOwners:s[3]}}async getRecoveryApprovals(e,a,r,n){const i=R("0x6c6595ca",["address","address[]","uint256"],[a,r,n]),s={to:this.moduleAddress,data:i},o=await I(e,s,"latest"),l=t.defaultAbiCoder().decode(["uint256"],o);return BigInt(l[0])}async hasGuardianApproved(e,a,r,n,i){const s=R("0x37d82c36",["address","address","address[]","uint256"],[a,r,n,i]),o={to:this.moduleAddress,data:s},l=await I(e,o,"latest"),c=t.defaultAbiCoder().decode(["bool"],l);return Boolean(c[0])}async isGuardian(e,a,r){const n=R("0xd4ee9734",["address","address"],[a,r]),i={to:this.moduleAddress,data:n},s=await I(e,i,"latest"),o=t.defaultAbiCoder().decode(["bool"],s);return Boolean(o[0])}async guardiansCount(e,a){const r=R("0xc026e7ee",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["uint256"],i);return BigInt(s[0])}async threshold(e,a){const r=R("0xc86ec2bf",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["uint256"],i);return BigInt(s[0])}async getGuardians(e,a){const r=R("0xf18858ab",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest");return t.defaultAbiCoder().decode(["address[]"],i)[0]}async nonce(e,a){const r=R("0x70ae92d2",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["uint256"],i);return BigInt(s[0])}}q.DEFAULT_SOCIAL_RECOVERY_ADDRESS=j.After3Days;class K extends X{constructor(e=K.DEFAULT_ALLOWANCE_MODULE_ADDRESS){super(e)}createOneTimeAllowanceMetaTransaction(e,t,a,r){return this.createBaseSetAllowanceMetaTransaction(e,t,a,0n,r)}createRecurringAllowanceMetaTransaction(e,t,a,r,n){return this.createBaseSetAllowanceMetaTransaction(e,t,a,r,n)}createBaseSetAllowanceMetaTransaction(e,t,a,r,n){const i=R("0xbeaeb388",["address","address","uint96","uint16","uint32"],[e,t,a,r,n]);return{to:this.moduleAddress,data:i,value:0n}}createRenewAllowanceMetaTransaction(e,t){const a=R("0xc19bf50e",["address","address"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}createDeleteAllowanceMetaTransaction(e,t){const a=R("0x885133e3",["address","address"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}createAllowanceTransferMetaTransaction(e,t,a,r,n,i={}){var s;let o="0x0000000000000000000000000000000000000000",l=0n;if(null!=i.paymentToken){if(o=i.paymentToken,null==i.paymentAmount)throw RangeError("must specify paymentAmount if paymentToken is set");l=i.paymentAmount}let c=null!=(s=i.delegateSignature)?s:"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001";return this.createBaseExecuteAllowanceTransferMetaTransaction(e,t,a,r,o,l,n,c)}createBaseExecuteAllowanceTransferMetaTransaction(e,t,a,r,n,i,s,o){const l=R("0x4515641a",["address","address","address","uint96","address","uint96","address","bytes"],[e,t,a,r,n,i,s,o]);return{to:this.moduleAddress,data:l,value:0n}}createAddDelegateMetaTransaction(e){const t=R("0xe71bdf41",["address"],[e]);return{to:this.moduleAddress,data:t,value:0n}}createRemoveDelegateMetaTransaction(e,t){const a=R("0xdd43a79f",["address","bool"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}async getTokens(e,a,r){const n=R("0x8d0e8e1d",["address","address"],[a,r]),i={to:this.moduleAddress,data:n},s=await I(e,i,"latest");return t.defaultAbiCoder().decode(["address[]"],s)[0]}async getTokensAllowance(e,a,r,n){const i=R("0x94b31fbd",["address","address","address"],[a,r,n]),s={to:this.moduleAddress,data:i},o=await I(e,s,"latest"),l=t.defaultAbiCoder().decode(["uint256[5]"],o)[0];return{amount:BigInt(l[0]),spent:BigInt(l[1]),resetTimeMin:BigInt(l[2]),lastResetMin:BigInt(l[3]),nonce:BigInt(l[4])}}async getDelegates(e,t,a={}){var r;let n=null!=(r=a.start)?r:0n;if(null!=a.maxNumberOfResults)return(await this.baseGetDelegates(e,t,n,a.maxNumberOfResults)).results;const i=20n,s=[];for(;;){const a=await this.baseGetDelegates(e,t,n,i);if(s.push.apply(s,a.results),0n==a.next)break;n=a.next}return s}async baseGetDelegates(e,a,r,n){const i=R("0xeb37abe0",["address","uint48","uint8"],[a,r,n]),s={to:this.moduleAddress,data:i},o=await I(e,s,"latest"),l=t.defaultAbiCoder().decode(["address[]","uint48"],o);return{results:l[0],next:BigInt(l[1])}}}K.DEFAULT_ALLOWANCE_MODULE_ADDRESS="0xAA46724893dedD72658219405185Fb0Fc91e091C";class Z extends J{constructor(e,t={}){var a,r;super(e,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.entrypointAddress)?r:Z.DEFAULT_ENTRYPOINT_ADDRESS)}static createAccountAddress(e,t={}){var a,r;const[n,,]=J.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return n}static initializeNewAccount(e,t={}){var a,r;let n=!1,i=0n,s=0n;for(const t of e)if("string"!=typeof t){if(n)throw RangeError("Only one Webauthn signer is allowed during initialization");if(0!=e.indexOf(t))throw RangeError("Webauthn owner has to be the first owner for an init transaction.");n=!0,i=t.x,s=t.y}const[o,l,c]=Z.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS),d=new Z(o,{safe4337ModuleAddress:t.safe4337ModuleAddress,entrypointAddress:t.entrypointAddress});return d.factoryAddress=l,d.factoryData=c,n&&(d.isInitWebAuthn=!0,d.x=i,d.y=s),d}static getUserOperationEip712Hash(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:Z.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Hash(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static getUserOperationEip712Data(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:Z.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Data(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static createAccountAddressAndInitCode(e,t={}){var a,r;const[n,i,s]=J.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return[n,i+s.slice(2)]}static createInitializerCallData(e,t,a={}){var r,n;const i=null!=(r=a.safe4337ModuleAddress)?r:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,s=null!=(n=a.safeModuleSetupddress)?n:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS;return J.createBaseInitializerCallData(e,t,i,s,a.multisendContractAddress,a.webAuthnSharedSigner,a.eip7212WebAuthnPrecompileVerifierForSharedSigner,a.eip7212WebAuthnContractVerifierForSharedSigner)}static createInitCode(e,t={}){var a,r;const[n,i]=J.createFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return n+i.slice(2)}async createUserOperation(e,t,a,r={}){const[n,i,s]=await this.createBaseUserOperationAndFactoryAddressAndFactoryData(e,!0,t,a,r);let o="0x";if(null==r.initCode){if(null!=i){let e="0x";null!=s&&(e=s),o=i+e.slice(2)}}else o=r.initCode;return f({},n,{initCode:o,paymasterAndData:"0x"})}async createMigrateToV07ModuleMetaTransactions(e,t={}){var a,r;const n=null!=(a=t.safeV06ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,i=null!=(r=t.safeV07ModuleAddress)?r:"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",s=await this.createDisableModuleMetaTransaction(e,n,this.accountAddress,{prevModuleAddress:t.safeV06ModuleAddress,modulesPageSize:t.pageSize,modulesStart:t.modulesStart}),o=J.createEnableModuleMetaTransaction(i,this.accountAddress),l=R("0xf08a0323",["address"],[i]);return[s,o,{to:this.accountAddress,value:0n,data:l}]}}Z.DEFAULT_ENTRYPOINT_ADDRESS=E,Z.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb";class $ extends J{constructor(e,t={}){var a,r;super(e,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.entrypointAddress)?r:$.DEFAULT_ENTRYPOINT_ADDRESS)}static createAccountAddress(e,t={}){var a,r;const[n,,]=J.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return n}static initializeNewAccount(e,t={}){var a,r;let n=!1,i=0n,s=0n;for(const t of e)if("string"!=typeof t){if(n)throw RangeError("Only one Webauthn signer is allowed during initialization");if(0!=e.indexOf(t))throw RangeError("Webauthn owner has to be the first owner for an init transaction.");n=!0,i=t.x,s=t.y}const[o,l,c]=$.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS),d=new $(o,{safe4337ModuleAddress:t.safe4337ModuleAddress,entrypointAddress:t.entrypointAddress});return d.factoryAddress=l,d.factoryData=c,n&&(d.isInitWebAuthn=!0,d.x=i,d.y=s),d}static getUserOperationEip712Hash(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:$.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:$.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Hash(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static getUserOperationEip712Data(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:$.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:$.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Data(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static createInitializerCallData(e,t,a={}){var r,n;const i=null!=(r=a.safe4337ModuleAddress)?r:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,s=null!=(n=a.safeModuleSetupddress)?n:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS;return J.createBaseInitializerCallData(e,t,i,s,a.multisendContractAddress,a.webAuthnSharedSigner,a.eip7212WebAuthnPrecompileVerifierForSharedSigner,a.eip7212WebAuthnContractVerifierForSharedSigner)}static createFactoryAddressAndData(e,t={}){var a,r;return J.createFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS)}async createUserOperation(e,t,a,r={}){const[n,i,s]=await this.createBaseUserOperationAndFactoryAddressAndFactoryData(e,!1,t,a,r);return f({},n,{factory:i,factoryData:s,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null})}}$.DEFAULT_ENTRYPOINT_ADDRESS=h,$.DEFAULT_SAFE_4337_MODULE_ADDRESS="0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS="0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47";class Q{}class ee extends Q{constructor(e){super(),this.rpcUrl=void 0,this.version=void 0,this.entrypointDataV7=void 0,this.entrypointDataV6=void 0,this.isInitilized=!1,this.rpcUrl=e}async initialize(){try{const e=await v(this.rpcUrl,"pm_clientVersion",[]);if(e.startsWith("Candide/v3"))this.version="v3";else if(e.startsWith("Candide/v2"))this.version="v2";else{if(!e.startsWith("Candide/v1"))throw RangeError("Invalide paymaster version received from paymaster rpc");this.version="v1"}const t=await this.getSupportedEntrypointsLive();if(t.some(e=>e.toLowerCase()===h.toLowerCase())){const e=await this.getSupportedERC20TokensAndPaymasterMetadata(h);this.entrypointDataV7=null!=e?e:null}if(t.some(e=>e.toLowerCase()===E.toLowerCase())){const e=await this.getSupportedERC20TokensAndPaymasterMetadata(E);this.entrypointDataV6=null!=e?e:null}if(null==this.entrypointDataV7&&null==this.entrypointDataV6)throw RangeError("Invalide data received during initilization.");return this.isInitilized=!0,null}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}}async getSupportedERC20TokensAndPaymasterMetadata(e){if(this.isInitilized){var t,a;if(e==h)return null!=(t=this.entrypointDataV7)?t:null;if(e==E)return null!=(a=this.entrypointDataV6)?a:null}else try{let t;if(t="v3"==this.version?await v(this.rpcUrl,"pm_supportedERC20Tokens",[e]):await v(this.rpcUrl,"pm_supportedERC20Tokens",[]),e==h)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals)})),paymasterMetadata:t.paymasterMetadata};if(e==E)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals)})),paymasterMetadata:t.paymasterMetadata};throw RangeError("unsupported entrypoint.")}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}return null}async getSupportedEntrypointsLive(){try{return"v3"==this.version?await v(this.rpcUrl,"pm_supportedEntryPoints",[]):[await v(this.rpcUrl,"pm_supportedEntryPoint",[])]}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}}async getSupportedEntrypoints(){this.isInitilized||await this.initialize();const e=[];return null!=this.entrypointDataV7&&e.push(h),null!=this.entrypointDataV6&&e.push(E),e}async getPaymasterMetaData(e){if(this.isInitilized||await this.initialize(),e==h&&null!=this.entrypointDataV7)return this.entrypointDataV7.paymasterMetadata;if(e==E&&null!=this.entrypointDataV6)return this.entrypointDataV6.paymasterMetadata;throw RangeError("unsupported entrypoint.")}async isSupportedERC20Token(e,t=h){return!!this.getSupportedERC20TokenData(e,t)}async getSupportedERC20TokenData(e,t=h){let a;if(this.isInitilized||await this.initialize(),t==h&&null!=this.entrypointDataV7)a=this.entrypointDataV7.tokens;else{if(t!=E||null==this.entrypointDataV6)throw RangeError("unsupported entrypoint.");a=this.entrypointDataV6.tokens}const r=a.find(t=>t.address.toLowerCase()===e.toLowerCase());return r?{name:r.name,symbol:r.symbol,address:r.address,decimals:Number(r.decimals)}:null}async createPaymasterUserOperation(e,t,a,r){null==a&&(a={});let n=r;null==n&&(n={});const i=f({},e);let s;this.isInitilized||await this.initialize();try{var o,l,c,d,u;let e;if("initCode"in i){if(null==this.entrypointDataV6)throw RangeError("useroperation v0.06 is not supported");e=E,i.paymasterAndData=this.entrypointDataV6.paymasterMetadata.dummyPaymasterAndData}else{if(null==this.entrypointDataV7)throw RangeError("useroperation v0.07 is not supported");e=h;const t=this.entrypointDataV7.paymasterMetadata.dummyPaymasterAndData;i.paymaster=t.paymaster,i.paymasterVerificationGasLimit=t.paymasterVerificationGasLimit,i.paymasterPostOpGasLimit=t.paymasterPostOpGasLimit,i.paymasterData=t.paymasterData}if("v1"==this.version||"v2"==this.version||"token"in a&&null!=a.token){var A,p,g,m,y,S;let a=i.preVerificationGas,r=i.verificationGasLimit,s=i.callGasLimit;if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit){if(null==t)throw new F("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{const o=new H(t);i.callGasLimit=0n,i.verificationGasLimit=0n,i.preVerificationGas=0n;const l=i.maxFeePerGas,c=i.maxPriorityFeePerGas;i.maxFeePerGas=0n,i.maxPriorityFeePerGas=0n;const d=await o.estimateUserOperationGas(i,e,n.state_override_set);a<d.preVerificationGas&&(a=d.preVerificationGas),r<d.verificationGasLimit&&(r=d.verificationGasLimit),s<d.callGasLimit&&(s=d.callGasLimit),i.maxFeePerGas=l,i.maxPriorityFeePerGas=c}}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");i.preVerificationGas=null!=(A=n.preVerificationGas)?A:a*BigInt((null!=(p=n.preVerificationGasPercentageMultiplier)?p:0)+100)/100n,i.verificationGasLimit=null!=(g=n.verificationGasLimit)?g:r*BigInt((null!=(m=n.verificationGasLimitPercentageMultiplier)?m:0)+100)/100n,i.callGasLimit=null!=(y=n.callGasLimit)?y:s*BigInt((null!=(S=n.callGasLimitPercentageMultiplier)?S:0)+100)/100n,i.preVerificationGas=i.preVerificationGas+100n,i.verificationGasLimit=i.verificationGasLimit+10000n}else if(null!=n.preVerificationGas||null!=n.verificationGasLimit||null!=n.callGasLimit||null!=n.preVerificationGasPercentageMultiplier||null!=n.verificationGasLimitPercentageMultiplier||null!=n.callGasLimitPercentageMultiplier)throw RangeError("you can't use any gas overrides for sponsor paymaster v3, as it will estimate gas and override any provided values.");const r=await v(this.rpcUrl,"pm_sponsorUserOperation",[i,e,a]),f=r,D={callGasLimit:null==f.callGasLimit?void 0:BigInt(f.callGasLimit),preVerificationGas:null==f.preVerificationGas?void 0:BigInt(f.preVerificationGas),verificationGasLimit:null==f.verificationGasLimit?void 0:BigInt(f.verificationGasLimit),maxFeePerGas:null==f.maxFeePerGas?void 0:BigInt(f.maxFeePerGas),maxPriorityFeePerGas:null==f.maxPriorityFeePerGas?void 0:BigInt(f.maxPriorityFeePerGas),sponsorMetadata:null==f.sponsorMetadata?void 0:f.sponsorMetadata};if(i.callGasLimit=null!=(o=D.callGasLimit)?o:i.callGasLimit,i.preVerificationGas=null!=(l=D.preVerificationGas)?l:i.preVerificationGas,i.verificationGasLimit=null!=(c=D.verificationGasLimit)?c:i.verificationGasLimit,i.maxFeePerGas=null!=(d=D.maxFeePerGas)?d:i.maxFeePerGas,i.maxPriorityFeePerGas=null!=(u=D.maxPriorityFeePerGas)?u:i.maxPriorityFeePerGas,s=D.sponsorMetadata,"initCode"in i)i.paymasterAndData=r.paymasterAndData;else{const e=r;i.paymaster=e.paymaster,i.paymasterVerificationGasLimit=BigInt(e.paymasterVerificationGasLimit),i.paymasterPostOpGasLimit=BigInt(e.paymasterPostOpGasLimit),i.paymasterData=e.paymasterData}return[i,s]}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})}}async createSponsorPaymasterUserOperation(e,t,a){const r={};return a&&a.trim().length>0&&(r.sponsorshipPolicyId=a),await this.createPaymasterUserOperation(e,t,r)}async createTokenPaymasterUserOperation(e,t,a,r,n={}){const i=n;try{let n;this.isInitilized||await this.initialize(),n="initCode"in t?E:h;const s=2n*await this.calculateUserOperationErc20TokenMaxGasCost(t,a),o=await this.getPaymasterMetaData(n);if(null==o)throw RangeError("unsupported entrypoint.");const l=e.prependTokenPaymasterApproveToCallData(t.callData,a,o.address,s);if(t.callData=l,"initCode"in t){const[e]=await this.createPaymasterUserOperation(t,r,{token:a},i);return e}{const[e]=await this.createPaymasterUserOperation(t,r,{token:a},i);return e}}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}}async calculateUserOperationErc20TokenMaxGasCost(e,t){try{let a;return this.isInitilized||await this.initialize(),a="initCode"in e?E:h,await this.fetchTokenPaymasterExchangeRate(t,a)*G(e)/BigInt(10**18)}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}}async fetchTokenPaymasterExchangeRate(e,t=h){try{let a;this.isInitilized||await this.initialize(),a="v3"==this.version?await v(this.rpcUrl,"pm_supportedERC20Tokens",[t]):await v(this.rpcUrl,"pm_supportedERC20Tokens",[]);const r=a.tokens.map(e=>({address:e.address,exchangeRate:e.exchangeRate})),n=r.find(t=>t.address.toLowerCase()===e.toLowerCase());if(n)return BigInt(n.exchangeRate);throw new F("PAYMASTER_ERROR",e+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadataV7:JSON.stringify(this.entrypointDataV7,(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t),supportedERC20TokensAndPaymasterMetadataV6:JSON.stringify(this.entrypointDataV6,(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t)}})}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","fetchTokenPaymasterExchangeRate failed",{cause:t})}}async fetchSupportedERC20TokensAndPaymasterMetadata(e=h){try{let t;if(this.isInitilized||await this.initialize(),t="v3"==this.version?await v(this.rpcUrl,"pm_supportedERC20Tokens",[e]):await v(this.rpcUrl,"pm_supportedERC20Tokens",[]),e==h)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals),exchangeRate:BigInt(e.exchangeRate)})),paymasterMetadata:t.paymasterMetadata};if(e==E)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals),exchangeRate:BigInt(e.exchangeRate)})),paymasterMetadata:t.paymasterMetadata};throw RangeError("unsupported entrypoint.")}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","fetchSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}}}var te={__proto__:null,SmartAccount:A,SocialRecoveryModule:q,get SocialRecoveryModuleGracePeriodSelector(){return j},AllowanceModule:K,SafeAccountV0_2_0:Z,SafeAccountV0_3_0:$,SendUseroperationResponse:k,SmartAccountFactory:z,SafeAccountFactory:Y,Bundler:H,CandidePaymaster:ee,createUserOperationHash:U,createCallData:R,getFunctionSelector:L,fetchAccountNonce:x,calculateUserOperationMaxGasCost:G,sendJsonRpcRequest:v,fetchGasPrice:P,getDepositInfo:O,getBalanceOf:C,get SafeModuleExecutorFunctionSelector(){return N},EOADummySignerSignaturePair:V,WebauthnDummySignerSignaturePair:B,get Operation(){return D},get GasOption(){return _},get PolygonChain(){return b},ZeroAddress:p,BaseUserOperationDummyValues:g,EIP712_SAFE_OPERATION_V7_TYPE:y,EIP712_SAFE_OPERATION_V6_TYPE:m,DEFAULT_SECP256R1_PRECOMPILE_ADDRESS:S,AbstractionKitError:F};export{F as AbstractionKitError,K as AllowanceModule,g as BaseUserOperationDummyValues,H as Bundler,ee as CandidePaymaster,S as DEFAULT_SECP256R1_PRECOMPILE_ADDRESS,m as EIP712_SAFE_OPERATION_V6_TYPE,y as EIP712_SAFE_OPERATION_V7_TYPE,V as EOADummySignerSignaturePair,_ as GasOption,D as Operation,b as PolygonChain,Y as SafeAccountFactory,Z as SafeAccountV0_2_0,$ as SafeAccountV0_3_0,N as SafeModuleExecutorFunctionSelector,k as SendUseroperationResponse,A as SmartAccount,z as SmartAccountFactory,q as SocialRecoveryModule,j as SocialRecoveryModuleGracePeriodSelector,B as WebauthnDummySignerSignaturePair,p as ZeroAddress,te as abstractionkit,G as calculateUserOperationMaxGasCost,R as createCallData,U as createUserOperationHash,x as fetchAccountNonce,P as fetchGasPrice,C as getBalanceOf,O as getDepositInfo,L as getFunctionSelector,v as sendJsonRpcRequest};
|
|
1
|
+
import{keccak256 as e,AbiCoder as t,id as a,JsonRpcProvider as r,getBytes as n,solidityPacked as i,solidityPackedKeccak256 as s,getAddress as o,TypedDataEncoder as l,Wallet as c,ethers as d}from"ethers";import*as u from"isomorphic-unfetch";class A{constructor(e){this.accountAddress=void 0,this.accountAddress=e}}function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e},f.apply(this,arguments)}A.proxyByteCode=void 0,A.initializerFunctionSelector=void 0,A.initializerFunctionInputAbi=void 0,A.executorFunctionSelector=void 0,A.executorFunctionInputAbi=void 0;const p="0x0000000000000000000000000000000000000000",h="0x0000000071727De22E5E9d8BAf0edAc6f37da032",E="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",g={sender:p,nonce:0n,callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,signature:"0x"},m={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"}]},y={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"}]},S="0x0000000000000000000000000000000000000100";var D,_,b;!function(e){e[e.Call=0]="Call",e[e.Delegate=1]="Delegate"}(D||(D={})),function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(_||(_={})),function(e){e.Mainnet="v2",e.ZkMainnet="zkevm",e.Amoy="amoy",e.Cardona="cardona"}(b||(b={}));const T={"-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 F extends Error{constructor(e,t,a={}){const{cause:r,errno:n,context:i}=a;super(t,{cause:r}),this.code=void 0,this.context=void 0,this.errno=void 0,this.name=this.constructor.name,this.code=e,this.errno=n,this.context=i}stringify(){return JSON.stringify(this,["name","code","message","cause","errno","context"])}}function w(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 U(a,r,n){let i;i=e("initCode"in a?function(a){const r=[a.sender,a.nonce,e(a.initCode),e(a.callData),a.callGasLimit,a.verificationGasLimit,a.preVerificationGas,a.maxFeePerGas,a.maxPriorityFeePerGas,e(a.paymasterAndData)];return t.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],r)}(a):function(a){const r=t.defaultAbiCoder();let n="0x";null!=a.factory&&(n=a.factory,null!=a.factoryData&&(n+=a.factoryData.slice(2)));const i="0x"+r.encode(["uint128"],[a.verificationGasLimit]).slice(34)+r.encode(["uint128"],[a.callGasLimit]).slice(34),s="0x"+r.encode(["uint128"],[a.maxPriorityFeePerGas]).slice(34)+r.encode(["uint128"],[a.maxFeePerGas]).slice(34);let o="0x";null!=a.paymaster&&(o=a.paymaster,null!=a.paymasterVerificationGasLimit&&(o+=r.encode(["uint128"],[a.paymasterVerificationGasLimit]).slice(34)),null!=a.paymasterPostOpGasLimit&&(o+=r.encode(["uint128"],[a.paymasterPostOpGasLimit]).slice(34)),null!=a.paymasterData&&(o+=a.paymasterData.slice(2)));const l=[a.sender,a.nonce,e(n),e(a.callData),i,a.preVerificationGas,s,e(o)];return r.encode(["address","uint256","bytes32","bytes32","bytes32","uint256","bytes32","bytes32"],l)}(a));const s=t.defaultAbiCoder().encode(["bytes32","address","uint256"],[i,r,n]);return e(s)}function R(e,a,r){return e+t.defaultAbiCoder().encode(a,r).slice(2)}async function v(e,t,a){const r=u.default||u,n={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:t,params:a,id:(new Date).getTime(),jsonrpc:"2.0"},(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t),redirect:"follow"},i=await r(e,n),s=await i.json();if("result"in s)return s.result;{const t=s.error,a=String(t.code);throw new F(a in T?T[a]:"UNKNOWN_ERROR",t.message,{errno:t.code,context:{url:e,requestOptions:JSON.stringify(n)}})}}function L(e){return a(e).slice(0,10)}async function x(e,t,a,r=0){const n=[{from:"0x0000000000000000000000000000000000000000",to:t,data:R(L("getNonce(address,uint192)"),["address","uint192"],[a,r])},"latest"];try{const t=await v(e,"eth_call",n);if("string"!=typeof t)throw new F("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(t)});try{return BigInt(t)}catch(e){const t=w(e);throw new F("BAD_DATA","getNonce returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","getNonce failed",{cause:t})}}async function P(e,t=_.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=w(e);throw new F("BAD_DATA","fetching gas prices from node failed.",{cause:t})}}function G(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 C(e,t,a){return(await O(e,t,a)).deposit}async function O(e,a,r){const n={from:"0x0000000000000000000000000000000000000000",to:r,data:R("0x5287ce12",["address"],[a])};try{const a=await I(e,n,"latest"),r=t.defaultAbiCoder().decode(["uint256","bool","uint112","uint32","uint48"],a);if(5!==r.length)throw new F("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){const t=w(e);throw new F("BAD_DATA","getDepositInfo returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","getDepositInfo failed",{cause:t})}}async function I(e,t,a,r){let n=[];n=null==r?[t,a]:[t,a,r];try{const t=await v(e,"eth_call",n);if("string"!=typeof t)throw new F("BAD_DATA","eth_call returned ill formed data",{context:JSON.stringify(t)});try{return t}catch(e){const t=w(e);throw new F("BAD_DATA","eth_call returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","eth_call failed",{cause:t})}}async function M(e,t,a){const r=[t,a];try{const t=await v(e,"eth_getCode",r);if("string"!=typeof t)throw new F("BAD_DATA","eth_getCode returned ill formed data",{context:JSON.stringify(t)});try{return t}catch(e){const t=w(e);throw new F("BAD_DATA","eth_getCode returned ill formed data",{cause:t})}}catch(e){const t=w(e);throw new F("BAD_DATA","eth_getCode failed",{cause:t})}}var N;!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(N||(N={}));const V={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x47003599ffa7e9198f321afa774e34a12a959844efd6363b88896e9c24ed33cf4e1be876ef123a3c4467e7d451511434039539699f2baa2f44955fa3d1c1c6d81c",isContractSignature:!1},B={signer:"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",signature:"0x000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e06c92f0ac5c4ef9e74721c23d80a9fc12f259ca84afb160f0890483539b9e6080d824c0e6c795157ad5d1ee5eff1ceeb3031009a595f9360919b83dd411c5a78d0000000000000000000000000000000000000000000000000000000000000025a24f744b28d73f066bf3203d145765a7bc735e6328168c8b03e476da3ad0d8fe0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e226f726967696e223a2268747470733a2f2f736166652e676c6f62616c220000",isContractSignature:!0};function W(e){return"0x"+e.map(e=>function(e){var t;const a=null!=(t=e.operation)?t:D.Call,r=n(e.data);return i(["uint8","address","uint256","uint256","bytes"],[a,e.to,e.value,r.length,r]).slice(2)}(e)).join("")}class H{constructor(e){this.rpcUrl=void 0,this.rpcUrl=e}async chainId(){try{const e=await v(this.rpcUrl,"eth_chainId",[]);if("string"==typeof e)return e;throw new F("BAD_DATA","bundler eth_chainId rpc call failed")}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}}async supportedEntryPoints(){try{return await v(this.rpcUrl,"eth_supportedEntryPoints",[])}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}}async estimateUserOperationGas(e,t,a){try{let r={};r=void 0===a?await v(this.rpcUrl,"eth_estimateUserOperationGas",[e,t]):await v(this.rpcUrl,"eth_estimateUserOperationGas",[e,t,a]);const n=r;return{callGasLimit:BigInt(n.callGasLimit),preVerificationGas:BigInt(n.preVerificationGas),verificationGasLimit:BigInt(n.verificationGasLimit)}}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}}async sendUserOperation(e,t){try{return await v(this.rpcUrl,"eth_sendUserOperation",[e,t])}catch(e){const t=w(e);throw new F("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}}async getUserOperationReceipt(e){try{const t=await v(this.rpcUrl,"eth_getUserOperationReceipt",[e]);if(null!=t){const e=f({},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 f({},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=w(t);throw new F("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:a,context:{useroperationhash:e}})}}async getUserOperationByHash(e){try{const t=await v(this.rpcUrl,"eth_getUserOperationByHash",[e]);return null!=t?f({},t,{blockNumber:null==t.blockNumber?null:BigInt(t.blockNumber)}):null}catch(t){const a=w(t);throw new F("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:a,context:{useroperationhash:e}})}}}class k{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 F("TIMEOUT","can't find useroperation",{context:this.userOperationHash})}}class z{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 R(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e)}}class Y extends z{constructor(e=Y.DEFAULT_FACTORY_ADDRESS){super(e,"0x1688f0b9",["address","bytes","uint256"])}}Y.DEFAULT_FACTORY_ADDRESS="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67";class J extends A{constructor(e,t,a){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.entrypointAddress=a,this.safe4337ModuleAddress=t,this.factoryAddress=null,this.factoryData=null,this.isInitWebAuthn=!1}static createProxyAddress(t,a={}){var r,n,l;const c=null!=(r=a.c2Nonce)?r:0n;if(c<0n)throw RangeError("c2Nonce can't be negative");const d=null!=(n=a.safeFactoryAddress)?n:Y.DEFAULT_FACTORY_ADDRESS,u=null!=(l=a.singletonInitHash)?l:J.DEFAULT_SAFE_SINGLETON.singletonInitHash,A=e(i(["bytes32","uint256"],[e(t),c])),f=s(["bytes1","address","bytes32","bytes32"],["0xff",d,A,u]).slice(-40);return o("0x"+f)}static createAccountCallDataSingleTransaction(e,t={}){var a,r,n,i;const s=null!=(a=e.value)?a:0,o=null!=(r=e.data)?r:"0x",l=null!=(n=e.operation)?n:D.Call,c=null!=(i=t.safeModuleExecutorFunctionSelector)?i:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR;return J.createAccountCallData(e.to,s,o,l,{safeModuleExecutorFunctionSelector:c})}static createAccountCallDataBatchTransactions(e,t={}){var a,r;if(e.length<1)throw RangeError("There should be at least one metaTransaction");const n=null!=(a=t.safeModuleExecutorFunctionSelector)?a:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,i=null!=(r=t.multisendContractAddress)?r:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,s=R("0x8d80ff0a",["bytes"],[W(e)]);return J.createAccountCallData(i,0n,s,D.Delegate,{safeModuleExecutorFunctionSelector:n})}static createAccountCallData(e,t,a,r,n={}){var i;return R(null!=(i=n.safeModuleExecutorFunctionSelector)?i:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,J.executorFunctionInputAbi,[e,t,a,r])}static decodeAccountCallData(e){let a=null;if(e.startsWith(N.executeUserOpWithErrorString)?a=N.executeUserOpWithErrorString:e.startsWith(N.executeUserOp)&&(a=N.executeUserOp),null!=a){const r=t.defaultAbiCoder(),n="0x"+e.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);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 F("BAD_DATA","Invalid calldata, should start with "+N.executeUserOpWithErrorString+" or "+N.executeUserOp,{context:{callData:e}})}static prependTokenPaymasterApproveToCallDataStatic(e,a,r,n,i={}){var s;const o=null!=(s=i.multisendContractAddress)?s:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,[l,c]=J.decodeAccountCallData(e),d=W([{to:a,value:0n,data:R(L("approve(address,uint256)"),["address","uint256"],[r,n]),operation:D.Call}]);let u="";const A="0x8d80ff0a";if(l.data.startsWith(A)){const e=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(l.data);u=e+d.slice(2)}else u=W([l])+d.slice(2);const f=R(A,["bytes"],[u]);return J.createAccountCallData(o,0n,f,D.Delegate,{safeModuleExecutorFunctionSelector:c})}static formatEip712SignaturesToUseroperationSignature(e,t,a={}){var r,n;if(e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");const i=null!=(r=a.validAfter)?r:0n,s=null!=(n=a.validUntil)?n: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 J.formatEip712SingleSignatureToUseroperationSignature(c,{validAfter:i,validUntil:s})}static getUserOperationEip712Hash(e,t,a={}){return"initCode"in e?J.getUserOperationEip712Hash_V6(e,t,a):J.getUserOperationEip712Hash_V7(e,t,a)}static getUserOperationEip712Data(e,t,a){if("initCode"in e){const r=J.getUserOperationEip712Data_V6(e,t,a);return{domain:r.domain,types:r.types,messageValue:r.messageValue}}{const r=J.getUserOperationEip712Data_V7(e,t,a);return{domain:r.domain,types:r.types,messageValue:r.messageValue}}}static getUserOperationEip712Data_V6(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n: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:m,messageValue:u}}static getUserOperationEip712Hash_V6(e,t,a={}){const r=J.getUserOperationEip712Data_V6(e,t,a);return l.hash(r.domain,r.types,r.messageValue)}static getUserOperationEip712Data_V7(e,a,r={}){var n,i,s,o;const l=null!=(n=r.validAfter)?n:0n,c=null!=(i=r.validUntil)?i:0n,d=null!=(s=r.entrypointAddress)?s:h,u=null!=(o=r.safe4337ModuleAddress)?o:"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",A=t.defaultAbiCoder();let f="0x";null!=e.factory&&(f=e.factory,null!=e.factoryData&&(f+=e.factoryData.slice(2)));let p="0x";null!=e.paymaster&&(p=e.paymaster,null!=e.paymasterVerificationGasLimit&&(p+=A.encode(["uint128"],[e.paymasterVerificationGasLimit]).slice(34)),null!=e.paymasterPostOpGasLimit&&(p+=A.encode(["uint128"],[e.paymasterPostOpGasLimit]).slice(34)),null!=e.paymasterData&&(p+=e.paymasterData.slice(2)));const E={safe:e.sender,nonce:e.nonce,initCode:f,callData:e.callData,verificationGasLimit:e.verificationGasLimit,callGasLimit:e.callGasLimit,preVerificationGas:e.preVerificationGas,maxPriorityFeePerGas:e.maxPriorityFeePerGas,maxFeePerGas:e.maxFeePerGas,paymasterAndData:p,validAfter:l,validUntil:c,entryPoint:d};return{domain:{chainId:Number(a),verifyingContract:u},types:y,messageValue:E}}static getUserOperationEip712Hash_V7(e,t,a={}){const r=J.getUserOperationEip712Data_V7(e,t,a);return l.hash(r.domain,r.types,r.messageValue)}static formatEip712SingleSignatureToUseroperationSignature(e,t={}){var a,r;const n=null!=(a=t.validAfter)?a:0n,s=null!=(r=t.validUntil)?r:0n;if(n<0n)throw RangeError("validAfter can't be negative");if(s<0n)throw RangeError("validUntil can't be negative");return i(["uint48","uint48","bytes"],[n,s,e])}async sendUserOperation(e,t){const a=new H(t),r=await a.sendUserOperation(e,this.entrypointAddress);return new k(r,a,this.entrypointAddress)}static createAccountAddressAndFactoryAddressAndData(e,t,a,r){var n,i,s,o,l,c,d,u;if(e.length<1)throw RangeError("There should be at least one owner");const A=J.createBaseInitializerCallData(e,null!=(n=t.threshold)?n:1,a,r,null!=(i=t.multisendContractAddress)?i:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(s=t.webAuthnSharedSigner)?s:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(o=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?o:J.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(l=t.eip7212WebAuthnContractVerifierForSharedSigner)?l:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);let f;f=null!=t.safeAccountFactoryAddress?new Y(t.safeAccountFactoryAddress):new Y;const p=null!=(c=t.safeAccountSingleton)?c:J.DEFAULT_SAFE_SINGLETON,h=this.createProxyAddress(A,{c2Nonce:null!=(d=t.c2Nonce)?d:0n,safeFactoryAddress:f.address,singletonInitHash:p.singletonInitHash}),E=[p.singletonAddress,A,null!=(u=t.c2Nonce)?u:0n],g=f.getFactoryGeneratorFunctionCallData(E);return[h,f.address,g]}static createBaseInitializerCallData(e,t,a,r,n=J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,i=J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,s=J.DEFAULT_WEB_AUTHN_PRECOMPILE,o=J.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=R("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:r,value:0n,data:l,operation:D.Delegate});const u=[];let A=0;for(const t of e)if("string"!=typeof t){if(A>0)throw RangeError("Only one WebAuthn owner can be set during initialization");const e=R("0x0dd9692f",["uint256","uint256","uint176"],[t.x,t.y,"0x"+s.slice(-4)+o.slice(2)]);d.push({to:i,value:0n,data:e,operation:D.Delegate}),u.push(i),A++}else u.push(t);c=[u,t,n,R("0x8d80ff0a",["bytes"],[W(d)]),a,p,0,p]}else c=[u,t,r,l,a,p,0,p];return R(J.initializerFunctionSelector,J.initializerFunctionInputAbi,c)}static createFactoryAddressAndData(e,t={},a,r){var n,i,s,o,l,c,d,u;if(e.length<1)throw RangeError("There should be at least one owner");const A=null!=(n=t.threshold)?n:1,f=null!=(i=t.c2Nonce)?i:0;if(A<1)throw RangeError("threshold should be at least one");if(A>e.length)throw RangeError("threshold can't be larger than number of owners");if(f<0n)throw RangeError("c2Nonce can't be negative");const p=J.createBaseInitializerCallData(e,null!=(s=t.threshold)?s:1,a,r,null!=(o=t.multisendContractAddress)?o:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS,null!=(l=t.webAuthnSharedSigner)?l:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,null!=(c=t.eip7212WebAuthnPrecompileVerifierForSharedSigner)?c:J.DEFAULT_WEB_AUTHN_PRECOMPILE,null!=(d=t.eip7212WebAuthnContractVerifierForSharedSigner)?d:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER);let h;h=null!=t.safeAccountFactoryAddress?new Y(t.safeAccountFactoryAddress):new Y;const E=null!=(u=t.safeAccountSingleton)?u:J.DEFAULT_SAFE_SINGLETON,g=h.getFactoryGeneratorFunctionCallData([E.singletonAddress,p,f]);return[h.address,g]}prependTokenPaymasterApproveToCallData(e,t,a,r,n={}){var i;const s=null!=(i=n.multisendContractAddress)?i:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS;return J.prependTokenPaymasterApproveToCallDataStatic(e,t,a,r,{multisendContractAddress:s})}async estimateUserOperationGas(e,t,a={}){const r=0xffffffffffffn,n=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=J.formatSignaturesToUseroperationSignature(a.dummySignerSignaturePairs,{validAfter:r,validUntil:n})}else if(null!=a.expectedSigners){let t;t="initCode"in e?e.initCode:e.factory;const i=J.createDummySignerSignaturePairForExpectedSigners(a.expectedSigners,{isInit:null!=t&&"0x"!=t,webAuthnSharedSigner:a.webAuthnSharedSigner,eip7212WebAuthnPrecompileVerifier:a.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:a.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:a.webAuthnSignerFactory,webAuthnSignerSingleton:a.webAuthnSignerSingleton,validAfter:r,validUntil:n});e.signature=J.formatSignaturesToUseroperationSignature(i,{validAfter:r,validUntil:n})}else e.signature.length<3&&(e.signature=J.formatSignaturesToUseroperationSignature([V],{validAfter:r,validUntil:n}));const i=new H(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,r,n={}){var i,s,o,l,c,d,u,A,p,h,E,m,y,S,D,_,b;if(e.length<1)throw RangeError("There should be at least one transaction");const T=null!=(i=n.webAuthnSharedSigner)?i:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER,w=null!=(s=n.safeModuleExecutorFunctionSelector)?s:J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR,U=null!=(o=n.multisendContractAddress)?o:J.DEFAULT_MULTISEND_CONTRACT_ADDRESS;let v=null,L=null;if(null==n.nonce){if(null==a)throw new F("BAD_DATA","providerRpc cant't be null if nonce is not overriden");L=x(a,this.entrypointAddress,this.accountAddress)}else v=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 P=g.maxFeePerGas,G=g.maxPriorityFeePerGas,C=null;null!=n.maxFeePerGas&&null!=n.maxPriorityFeePerGas||(C=J.handlefetchGasPrice(a,n.polygonGasStation,n.gasLevel)),null!=C&&null!=L?await Promise.all([L,C]).then(e=>{v=e[0],[P,G]=e[1]}):null!=C?[P,G]=await C:null!=L&&(v=await L),P=null!=(l=n.maxFeePerGas)?l:P*BigInt(Math.floor(((null!=(c=n.maxFeePerGasPercentageMultiplier)?c:0)+100)/100)),G=null!=(d=n.maxPriorityFeePerGas)?d:G*BigInt(Math.floor(((null!=(u=n.maxPriorityFeePerGasPercentageMultiplier)?u:0)+100)/100));const O=null!=(A=n.eip7212WebAuthnPrecompileVerifier)?A:J.DEFAULT_WEB_AUTHN_PRECOMPILE,I=null!=(p=n.eip7212WebAuthnContractVerifier)?p:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,M=null!=(h=n.webAuthnSignerFactory)?h:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,N=null!=(E=n.webAuthnSignerSingleton)?E:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;let B=this.factoryAddress,W=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,W=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=J.createDeployWebAuthnVerifierMetaTransaction(this.x,this.y,{eip7212WebAuthnPrecompileVerifier:O,eip7212WebAuthnContractVerifier:I,webAuthnSignerFactory:M}),a=R("0xe318b52b",["address","address","address"],["0x0000000000000000000000000000000000000001",T,J.createWebAuthnSignerVerifierAddress(this.x,this.y,{eip7212WebAuthnPrecompileVerifier:O,eip7212WebAuthnContractVerifier:I,webAuthnSignerFactory:M,webAuthnSignerSingleton:N})]);e=[t,{to:this.accountAddress,value:0n,data:a}].concat(e)}let H="0x";H=null==n.callData?1==e.length?J.createAccountCallDataSingleTransaction(e[0],{safeModuleExecutorFunctionSelector:w}):J.createAccountCallDataBatchTransactions(e,{safeModuleExecutorFunctionSelector:w,multisendContractAddress:U}):n.callData;const k=f({},g,{sender:this.accountAddress,nonce:v,callData:H,maxFeePerGas:P,maxPriorityFeePerGas:G});let z=g.preVerificationGas,Y=g.verificationGasLimit,X=g.callGasLimit;if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit){if(null==r)throw new F("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{k.callGasLimit=0n,k.verificationGasLimit=0n,k.preVerificationGas=0n;const e=k.maxFeePerGas,a=k.maxPriorityFeePerGas;let i;if(k.maxFeePerGas=0n,k.maxPriorityFeePerGas=0n,t){let e="0x";null!=B&&(e=B,null!=W&&(e+=W.slice(2))),i=f({},k,{initCode:e,paymasterAndData:"0x"})}else i=f({},k,{factory:B,factoryData:W,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null});const s=0xffffffffffffn,o=0xffffffffffffn;let l;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 dummySignerSignaturePairs can't be less than 1");l=n.dummySignerSignaturePairs}else l=null==n.expectedSigners?[V]:J.createDummySignerSignaturePairForExpectedSigners(n.expectedSigners,{isInit:null!=B&&"0x"!=B,webAuthnSharedSigner:T,eip7212WebAuthnPrecompileVerifier:O,eip7212WebAuthnContractVerifier:I,webAuthnSignerFactory:M,webAuthnSignerSingleton:N,validAfter:s,validUntil:o});k.signature=J.formatSignaturesToUseroperationSignature(l,{validAfter:s,validUntil:o,webAuthnSharedSigner:T}),[z,Y,X]=await this.estimateUserOperationGas(i,r,{stateOverrideSet:n.state_override_set}),Y+=55000n*BigInt(l.length),k.maxFeePerGas=e,k.maxPriorityFeePerGas=a}}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 k.preVerificationGas=null!=(m=n.preVerificationGas)?m:z*BigInt(Math.floor(((null!=(y=n.preVerificationGasPercentageMultiplier)?y:0)+100)/100)),k.verificationGasLimit=null!=(S=n.verificationGasLimit)?S:Y*BigInt(Math.floor(((null!=(D=n.verificationGasLimitPercentageMultiplier)?D:0)+100)/100)),k.callGasLimit=null!=(_=n.callGasLimit)?_:X*BigInt(Math.floor(((null!=(b=n.callGasLimitPercentageMultiplier)?b:0)+100)/100)),[k,B,W]}static async handlefetchGasPrice(e,t,a=_.Medium){let r,n;if(null!=t)[r,n]=await async function(e,t=_.Medium){const a="https://gasstation.polygon.technology/"+e;try{const e=await fetch(a),r=await e.json();let n;n=t==_.Slow?r.safeLow:t==_.Medium?r.standard:r.fast;let i=BigInt(Math.ceil(1e9*Number(n.maxFee))),s=BigInt(Math.ceil(1e9*Number(n.maxPriorityFee)));return 0n==i&&(i=1n),0n==s&&(s=1n),[i,s]}catch(e){const t=w(e);throw new F("BAD_DATA","fetching gas prices from "+a+" failed.",{cause:t})}}(t,a);else{if(null==e)throw new F("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden");[r,n]=await P(e,a)}return[r,n]}signUserOperation(e,t,a,r={}){var n,i;const s=null!=(n=r.validAfter)?n:0n,o=null!=(i=r.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(s<0n)throw RangeError("validAfter can't be negative");if(o<0n)throw RangeError("validUntil can't be negative");const l=J.getUserOperationEip712Hash(e,a,{validAfter:s,validUntil:o,entrypointAddress:this.entrypointAddress,safe4337ModuleAddress:this.safe4337ModuleAddress}),d=[],u=[];for(const e of t){const t=new c(e),a=t.signingKey.sign(l).serialized;d.push(t.address),u.push(a)}return J.formatEip712SignaturesToUseroperationSignature(d,u,{validAfter:s,validUntil:o})}static createWebAuthnSignerVerifierAddress(t,a,r={}){var n,o,l,c;const d=null!=(n=r.eip7212WebAuthnPrecompileVerifier)?n:J.DEFAULT_WEB_AUTHN_PRECOMPILE,u=null!=(o=r.eip7212WebAuthnContractVerifier)?o:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,A=null!=(l=r.webAuthnSignerFactory)?l:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,f=null!=(c=r.webAuthnSignerSingleton)?c:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;if(42!=d.length||d.slice(0,38)!=p.slice(0,38))throw RangeError("Invalide precompile address. It should have the format 0x000000000000000000000000000000000000____");const h=e(i(["bytes","uint256","uint256","uint256","uint256"],[J.DEFAULT_WEB_AUTHN_SIGNER_PROXY_CREATION_CODE,f,t,a,"0x"+d.slice(-4)+u.slice(2)]));return"0x"+s(["bytes1","address","bytes32","bytes32"],["0xff",A,"0x0000000000000000000000000000000000000000000000000000000000000000",h]).slice(-40)}static formatSignaturesToUseroperationSignature(e,t={}){var a,r;const n=null!=(a=t.validAfter)?a:0n,s=null!=(r=t.validUntil)?r:0n,o=this.buildSignaturesFromSingerSignaturePairs(e,t);return i(["uint48","uint48","bytes"],[n,s,o])}static getSignerLowerCaseAddress(e,t={}){if("string"==typeof e)return e.toLowerCase();{var a,r,n,i;const s=null!=(a=t.eip7212WebAuthnPrecompileVerifier)?a:J.DEFAULT_WEB_AUTHN_PRECOMPILE,o=null!=(r=t.eip7212WebAuthnContractVerifier)?r:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,l=null!=(n=t.webAuthnSignerFactory)?n:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,c=null!=(i=t.webAuthnSignerSingleton)?i:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;return J.createWebAuthnSignerVerifierAddress(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:s,eip7212WebAuthnContractVerifier:o,webAuthnSignerFactory:l,webAuthnSignerSingleton:c}).toLowerCase()}}static sortSignatures(e,t={}){e.sort((e,a)=>J.getSignerLowerCaseAddress(e.signer,t).localeCompare(J.getSignerLowerCaseAddress(a.signer,t)))}static buildSignaturesFromSingerSignaturePairs(e,t={}){J.sortSignatures(e,t);const a=65*e.length,{segments:r}=e.reduce(({segments:e,offset:r},{signer:n,signature:i,isContractSignature:s})=>{if(s=s||"string"!=typeof n){if("string"!=typeof n){if(null==t.isInit)throw RangeError("Must define isInit parameter when using WebAuthn");if(t.isInit){var o;n=null!=(o=t.webAuthnSharedSigner)?o:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER}else{var l,c,u,A;const e=null!=(l=t.eip7212WebAuthnPrecompileVerifier)?l:J.DEFAULT_WEB_AUTHN_PRECOMPILE,a=null!=(c=t.eip7212WebAuthnContractVerifier)?c:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,r=null!=(u=t.webAuthnSignerFactory)?u:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,i=null!=(A=t.webAuthnSignerSingleton)?A:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;n=J.createWebAuthnSignerVerifierAddress(n.x,n.y,{eip7212WebAuthnPrecompileVerifier:e,eip7212WebAuthnContractVerifier:a,webAuthnSignerFactory:r,webAuthnSignerSingleton:i})}}return{segments:[...e,d.solidityPacked(["uint256","uint256","uint8"],[n,a+r,0])],offset:r+32+d.dataLength(i)}}return{segments:[...e,d.solidityPacked(["bytes"],[i])],offset:r}},{segments:[],offset:0});return d.concat([...r,...e.map(({signer:e,signature:t,isContractSignature:a})=>(a=a||"string"!=typeof e)?d.solidityPacked(["uint256","bytes"],[d.dataLength(t),t]):"0x")])}static createWebAuthnSignature(e){return d.AbiCoder.defaultAbiCoder().encode(["bytes","bytes","uint256[2]"],[new Uint8Array(e.authenticatorData),e.clientDataFields,e.rs])}async createSwapOwnerMetaTransactions(e,t,a,r={}){let n,i,s=null;"string"!=typeof t?(n=J.createWebAuthnSignerVerifierAddress(t.x,t.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory,webAuthnSignerSingleton:r.webAuthnSignerSingleton}),(await M(e,n,"latest")).length<3&&(s=J.createDeployWebAuthnVerifierMetaTransaction(t.x,t.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory}))):n=t,i="string"!=typeof a?J.createWebAuthnSignerVerifierAddress(a.x,a.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory,webAuthnSignerSingleton:r.webAuthnSignerSingleton}):a;let o=r.prevOwner;if(null==o){const t=await this.getOwners(e),a=t.indexOf(i);if(-1==a)throw RangeError("oldOwner is not a current owner.");if(0==a)o="0x0000000000000000000000000000000000000001";else{if(!(a>0))throw RangeError("Invalid owner index");o=t[a-1]}}const l=this.createStandardSwapOwnerMetaTransaction(n,i,o);return null==s?[l]:[s,l]}async createRemoveOwnerMetaTransaction(e,t,a,r={}){let n;n="string"!=typeof t?J.createWebAuthnSignerVerifierAddress(t.x,t.y,{eip7212WebAuthnPrecompileVerifier:r.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:r.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:r.webAuthnSignerFactory,webAuthnSignerSingleton:r.webAuthnSignerSingleton}):t;let i=r.prevOwner;if(null==i){const t=await this.getOwners(e),a=t.indexOf(n);if(-1==a)throw RangeError("ownerToDelete is not a current owner.");if(0==a)i="0x0000000000000000000000000000000000000001";else{if(!(a>0))throw RangeError("Invalid owner index");i=t[a-1]}}return this.createStandardRemoveOwnerMetaTransaction(n,a,i)}async createAddOwnerWithThresholdMetaTransactions(e,t,a={}){let r,n=null;if("string"!=typeof e){if(r=J.createWebAuthnSignerVerifierAddress(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:a.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:a.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:a.webAuthnSignerFactory,webAuthnSignerSingleton:a.webAuthnSignerSingleton}),null==a.nodeRpcUrl)throw RangeError("overrides.nodeRpcUrl can't be null if adding a webauthn owner");(await M(a.nodeRpcUrl,r,"latest")).length<3&&(n=J.createDeployWebAuthnVerifierMetaTransaction(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:a.eip7212WebAuthnPrecompileVerifier,eip7212WebAuthnContractVerifier:a.eip7212WebAuthnContractVerifier,webAuthnSignerFactory:a.webAuthnSignerFactory}))}else r=e;const i=this.createStandardAddOwnerWithThresholdMetaTransaction(r,t);return null==n?[i]:[n,i]}createStandardAddOwnerWithThresholdMetaTransaction(e,t){const a=R("0x0d582f13",["address","uint256"],[e,t]);return{to:this.accountAddress,data:a,value:0n}}createStandardSwapOwnerMetaTransaction(e,t,a){const r=R("0xe318b52b",["address","address","address"],[a,t,e]);return{to:this.accountAddress,data:r,value:0n}}createStandardRemoveOwnerMetaTransaction(e,t,a){const r=R("0xf8dc5dd9",["address","address","uint256"],[a,e,t]);return{to:this.accountAddress,data:r,value:0n}}static createDeployWebAuthnVerifierMetaTransaction(e,t,a={}){var r,n,i;const s=null!=(r=a.eip7212WebAuthnPrecompileVerifier)?r:J.DEFAULT_WEB_AUTHN_PRECOMPILE,o=null!=(n=a.eip7212WebAuthnContractVerifier)?n:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER;return{to:null!=(i=a.webAuthnSignerFactory)?i:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,value:0n,data:R("0x0d2f0489",["uint256","uint256","uint176"],[e,t,"0x"+s.slice(-4)+o.slice(2)])}}async getOwners(e){const a=R(L("getOwners()"),[],[]),r={to:this.accountAddress,data:a},n=await I(e,r,"latest");return t.defaultAbiCoder().decode(["address[]"],n)[0]}async getModules(e,a={}){try{let r=a.start;null==r&&(r="0x0000000000000000000000000000000000000001");let n=a.pageSize;null==n&&(n=10n);const i=R("0xcc2f8452",["address","uint256"],[r,n]),s={to:this.accountAddress,data:i},o=await I(e,s,"latest");if("0x"==o)throw new F("BAD_DATA","getModules retuned an empty result, the target account is probably not deployed yet.");const l=t.defaultAbiCoder().decode(["address[]","address"],o);return[l[0],l[1]]}catch(e){const t=w(e);throw new F("BAD_DATA","getModules failed",{cause:t})}}async isModuleEnabled(e,a){const r=R(L("isModuleEnabled(address)"),["address"],[a]),n={to:this.accountAddress,data:r},i=await I(e,n,"latest");return t.defaultAbiCoder().decode(["bool"],i)[0]}static createDummySignerSignaturePairForExpectedSigners(e,t={}){const a=[...e],r=[];for(let e of a){let a;if("string"==typeof e)a=V;else{if(null==t.isInit)throw RangeError("Must define isInit parameter when using WebAuthn");if(a=B,t.isInit){var n;const e=null!=(n=t.webAuthnSharedSigner)?n:J.DEFAULT_WEB_AUTHN_SHARED_SIGNER;a.signer=e}else{var i,s,o,l;const r=null!=(i=t.eip7212WebAuthnPrecompileVerifier)?i:J.DEFAULT_WEB_AUTHN_PRECOMPILE,n=null!=(s=t.eip7212WebAuthnContractVerifier)?s:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,c=null!=(o=t.webAuthnSignerFactory)?o:J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,d=null!=(l=t.webAuthnSignerSingleton)?l:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;a.signer=J.createWebAuthnSignerVerifierAddress(e.x,e.y,{eip7212WebAuthnPrecompileVerifier:r,eip7212WebAuthnContractVerifier:n,webAuthnSignerFactory:c,webAuthnSignerSingleton:d})}}r.push(a)}return r}static async verifyWebAuthnSignatureForMessageHash(e,a,r,n,i={}){var s,o,l;if(66!=r.length||"0x"!=r.slice(0,2))throw RangeError("Invalide messageHash ,must be a 0x prefixed keccak256 hash.");const c=null!=(s=i.eip7212WebAuthnPrecompileVerifier)?s:J.DEFAULT_WEB_AUTHN_PRECOMPILE,d=null!=(o=i.eip7212WebAuthnContractVerifier)?o:J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER,u=null!=(l=i.webAuthnSignerSingleton)?l:J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON;if(42!=c.length||c.slice(0,38)!=p.slice(0,38))throw RangeError("Invalide precompile address. It should have the format 0x000000000000000000000000000000000000____");const A="0x1111111111111111111111111111111111111111",f={to:A,data:R("0x1626ba7e",["bytes32","bytes"],[r,n])},h=J.createSafeWebAuthnSignerProxyDeployedByteCode(a,c,d,u),E=await I(e,f,"latest",{[A]:{code:h}});return t.defaultAbiCoder().decode(["bool"],E)[0]}static createSafeWebAuthnSignerProxyDeployedByteCode(e,a,r,n){const i=t.defaultAbiCoder(),s=i.encode(["uint256"],[e.x]),o=i.encode(["uint256"],[e.y]);return"0x608060408190527f"+i.encode(["uint176"],["0x"+a.slice(-4)+r.slice(2)]).slice(2)+"3660b681018290527f"+o.slice(2)+"60a082018190527f"+s.slice(2)+"8285018190527f000000000000000000000000"+n.slice(2)+"9490939192600082376000806056360183885af490503d6000803e8060c3573d6000fd5b503d6000f3fea2646970667358221220ddd9bb059ba7a6497d560ca97aadf4dbf0476f578378554a50d41c6bb654beae64736f6c63430008180033"}static createEnableModuleMetaTransaction(e,t){return{to:t,data:R("0x610b5925",["address"],[e]),value:0n}}async createDisableModuleMetaTransaction(e,t,a,r={}){try{let n=r.prevModuleAddress;if(null==n){const[a,i]=await this.getModules(e,{start:r.modulesStart,pageSize:r.modulesPageSize}),s=a.indexOf(t);if(-1==s)throw RangeError("moduleToDisable "+t+" is not an enabled module.");if(0==s)n="0x0000000000000000000000000000000000000001";else{if(!(s>0))throw RangeError("Invalid module index for "+t);n=a[s-1]}}return J.createStandardDisableModuleMetaTransaction(t,n,a)}catch(e){const t=w(e);throw new F("BAD_DATA","createDisableModuleMetaTransaction failed",{cause:t})}}static createStandardDisableModuleMetaTransaction(e,t,a){return{to:a,data:R("0xe009cfde",["address","address"],[t,e]),value:0n}}}J.DEFAULT_SAFE_SINGLETON={singletonAddress:"0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",singletonInitHash:"0xe298282cefe913ab5d282047161268a8222e4bd4ed106300c547894bbefd31ee"},J.DEFAULT_WEB_AUTHN_SHARED_SIGNER="0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9",J.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON="0x270D7E4a57E6322f336261f3EaE2BADe72E68d72",J.DEFAULT_WEB_AUTHN_SIGNER_FACTORY="0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf",J.DEFAULT_WEB_AUTHN_FCLP256_VERIFIER="0x445a0683e494ea0c5AF3E83c5159fBE47Cf9e765",J.DEFAULT_WEB_AUTHN_PRECOMPILE="0x0000000000000000000000000000000000000000",J.DEFAULT_WEB_AUTHN_SIGNER_PROXY_CREATION_CODE="0x61010060405234801561001157600080fd5b506040516101ee3803806101ee83398101604081905261003091610058565b6001600160a01b0390931660805260a09190915260c0526001600160b01b031660e0526100bc565b6000806000806080858703121561006e57600080fd5b84516001600160a01b038116811461008557600080fd5b60208601516040870151606088015192965090945092506001600160b01b03811681146100b157600080fd5b939692955090935050565b60805160a05160c05160e05160ff6100ef60003960006008015260006031015260006059015260006080015260ff6000f3fe608060408190527f00000000000000000000000000000000000000000000000000000000000000003660b681018290527f000000000000000000000000000000000000000000000000000000000000000060a082018190527f00000000000000000000000000000000000000000000000000000000000000008285018190527f00000000000000000000000000000000000000000000000000000000000000009490939192600082376000806056360183885af490503d6000803e8060c3573d6000fd5b503d6000f3fea2646970667358221220ddd9bb059ba7a6497d560ca97aadf4dbf0476f578378554a50d41c6bb654beae64736f6c63430008180033",J.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",J.initializerFunctionSelector="0xb63e800d",J.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],J.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=N.executeUserOpWithErrorString,J.executorFunctionInputAbi=["address","uint256","bytes","uint8"];class X{constructor(e){this.moduleAddress=void 0,this.moduleAddress=e}createEnableModuleMetaTransaction(e){return J.createEnableModuleMetaTransaction(this.moduleAddress,e)}}var j;!function(e){e.After3Minutes="0x949d01d424bE050D09C16025dd007CB59b3A8c66",e.After3Days="0x38275826E1933303E508433dD5f289315Da2541c",e.After7Days="0x088f6cfD8BB1dDb1BB069CCb3fc1A98927D233f2",e.After14Days="0x9BacD92F4687Db306D7ded5d4513a51EA05df25b"}(j||(j={}));class q extends X{constructor(e=q.DEFAULT_SOCIAL_RECOVERY_ADDRESS){super(e)}createConfirmRecoveryMetaTransaction(e,t,a,r){const n=R("0x064e2d0e",["address","address[]","uint256","bool"],[e,t,a,r]);return{to:this.moduleAddress,data:n,value:0n}}createMultiConfirmRecoveryMetaTransaction(e,t,a,r,n){const i=R("0x0728e1e7",["address","address[]","uint256","(address,bytes)","bool"],[e,t,a,r.map(e=>[e.signer,e.signature]),n]);return{to:this.moduleAddress,data:i,value:0n}}createExecuteRecoveryMetaTransaction(e,t,a){const r=R("0xb1f85f69",["address","address[]","uint256"],[e,t,a]);return{to:this.moduleAddress,data:r,value:0n}}createFinalizeRecoveryMetaTransaction(e){const t=R("0x315a7af3",["address"],[e]);return{to:this.moduleAddress,data:t,value:0n}}createCancelRecoveryMetaTransaction(){return{to:this.moduleAddress,data:"0x0ba234d6",value:0n}}createAddGuardianWithThresholdMetaTransaction(e,t){const a=R("0xbe0e54d7",["address","uint256"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}async createRevokeGuardianWithThresholdMetaTransaction(e,t,a,r,n={}){let i=n.prevGuardianAddress;if(null==i){const r=await this.getGuardians(e,t),n=r.indexOf(a);if(-1==n)throw RangeError(a+" is not a current guardian for account : "+t);if(0==n)i="0x0000000000000000000000000000000000000001";else{if(!(n>0))throw RangeError("Invalid guardian index");i=r[n-1]}}return this.createStandardRevokeGuardianWithThresholdMetaTransaction(i,a,r)}createStandardRevokeGuardianWithThresholdMetaTransaction(e,t,a){const r=R("0x936f7d86",["address","address","uint256"],[e,t,a]);return{to:this.moduleAddress,data:r,value:0n}}createChangeThresholdMetaTransaction(e){const t=R("0x694e80c3",["uint256"],[e]);return{to:this.moduleAddress,data:t,value:0n}}async getRecoveryHash(e,t,a,r,n){const i=R("0x5f19df08",["address","address[]","uint256","uint256"],[t,a,r,n]);return I(e,{to:this.moduleAddress,data:i},"latest")}async getRecoveryRequest(e,a){const r=R("0x4f9a28b9",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["(uint256,uint256,uint64,address[])"],i);return{guardiansApprovalCount:BigInt(s[0][0]),newThreshold:BigInt(s[0][1]),executeAfter:BigInt(s[0][2]),newOwners:s[0][3]}}async getRecoveryApprovals(e,a,r,n){const i=R("0x6c6595ca",["address","address[]","uint256"],[a,r,n]),s={to:this.moduleAddress,data:i},o=await I(e,s,"latest"),l=t.defaultAbiCoder().decode(["uint256"],o);return BigInt(l[0])}async hasGuardianApproved(e,a,r,n,i){const s=R("0x37d82c36",["address","address","address[]","uint256"],[a,r,n,i]),o={to:this.moduleAddress,data:s},l=await I(e,o,"latest"),c=t.defaultAbiCoder().decode(["bool"],l);return Boolean(c[0])}async isGuardian(e,a,r){const n=R("0xd4ee9734",["address","address"],[a,r]),i={to:this.moduleAddress,data:n},s=await I(e,i,"latest"),o=t.defaultAbiCoder().decode(["bool"],s);return Boolean(o[0])}async guardiansCount(e,a){const r=R("0xc026e7ee",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["uint256"],i);return BigInt(s[0])}async threshold(e,a){const r=R("0xc86ec2bf",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["uint256"],i);return BigInt(s[0])}async getGuardians(e,a){const r=R("0xf18858ab",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest");return t.defaultAbiCoder().decode(["address[]"],i)[0]}async nonce(e,a){const r=R("0x70ae92d2",["address"],[a]),n={to:this.moduleAddress,data:r},i=await I(e,n,"latest"),s=t.defaultAbiCoder().decode(["uint256"],i);return BigInt(s[0])}}q.DEFAULT_SOCIAL_RECOVERY_ADDRESS=j.After3Days;class K extends X{constructor(e=K.DEFAULT_ALLOWANCE_MODULE_ADDRESS){super(e)}createOneTimeAllowanceMetaTransaction(e,t,a,r){return this.createBaseSetAllowanceMetaTransaction(e,t,a,0n,r)}createRecurringAllowanceMetaTransaction(e,t,a,r,n){return this.createBaseSetAllowanceMetaTransaction(e,t,a,r,n)}createBaseSetAllowanceMetaTransaction(e,t,a,r,n){const i=R("0xbeaeb388",["address","address","uint96","uint16","uint32"],[e,t,a,r,n]);return{to:this.moduleAddress,data:i,value:0n}}createRenewAllowanceMetaTransaction(e,t){const a=R("0xc19bf50e",["address","address"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}createDeleteAllowanceMetaTransaction(e,t){const a=R("0x885133e3",["address","address"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}createAllowanceTransferMetaTransaction(e,t,a,r,n,i={}){var s;let o="0x0000000000000000000000000000000000000000",l=0n;if(null!=i.paymentToken){if(o=i.paymentToken,null==i.paymentAmount)throw RangeError("must specify paymentAmount if paymentToken is set");l=i.paymentAmount}let c=null!=(s=i.delegateSignature)?s:"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001";return this.createBaseExecuteAllowanceTransferMetaTransaction(e,t,a,r,o,l,n,c)}createBaseExecuteAllowanceTransferMetaTransaction(e,t,a,r,n,i,s,o){const l=R("0x4515641a",["address","address","address","uint96","address","uint96","address","bytes"],[e,t,a,r,n,i,s,o]);return{to:this.moduleAddress,data:l,value:0n}}createAddDelegateMetaTransaction(e){const t=R("0xe71bdf41",["address"],[e]);return{to:this.moduleAddress,data:t,value:0n}}createRemoveDelegateMetaTransaction(e,t){const a=R("0xdd43a79f",["address","bool"],[e,t]);return{to:this.moduleAddress,data:a,value:0n}}async getTokens(e,a,r){const n=R("0x8d0e8e1d",["address","address"],[a,r]),i={to:this.moduleAddress,data:n},s=await I(e,i,"latest");return t.defaultAbiCoder().decode(["address[]"],s)[0]}async getTokensAllowance(e,a,r,n){const i=R("0x94b31fbd",["address","address","address"],[a,r,n]),s={to:this.moduleAddress,data:i},o=await I(e,s,"latest"),l=t.defaultAbiCoder().decode(["uint256[5]"],o)[0];return{amount:BigInt(l[0]),spent:BigInt(l[1]),resetTimeMin:BigInt(l[2]),lastResetMin:BigInt(l[3]),nonce:BigInt(l[4])}}async getDelegates(e,t,a={}){var r;let n=null!=(r=a.start)?r:0n;if(null!=a.maxNumberOfResults)return(await this.baseGetDelegates(e,t,n,a.maxNumberOfResults)).results;const i=20n,s=[];for(;;){const a=await this.baseGetDelegates(e,t,n,i);if(s.push.apply(s,a.results),0n==a.next)break;n=a.next}return s}async baseGetDelegates(e,a,r,n){const i=R("0xeb37abe0",["address","uint48","uint8"],[a,r,n]),s={to:this.moduleAddress,data:i},o=await I(e,s,"latest"),l=t.defaultAbiCoder().decode(["address[]","uint48"],o);return{results:l[0],next:BigInt(l[1])}}}K.DEFAULT_ALLOWANCE_MODULE_ADDRESS="0xAA46724893dedD72658219405185Fb0Fc91e091C";class Z extends J{constructor(e,t={}){var a,r;super(e,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.entrypointAddress)?r:Z.DEFAULT_ENTRYPOINT_ADDRESS)}static createAccountAddress(e,t={}){var a,r;const[n,,]=J.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return n}static initializeNewAccount(e,t={}){var a,r;let n=!1,i=0n,s=0n;for(const t of e)if("string"!=typeof t){if(n)throw RangeError("Only one Webauthn signer is allowed during initialization");if(0!=e.indexOf(t))throw RangeError("Webauthn owner has to be the first owner for an init transaction.");n=!0,i=t.x,s=t.y}const[o,l,c]=Z.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS),d=new Z(o,{safe4337ModuleAddress:t.safe4337ModuleAddress,entrypointAddress:t.entrypointAddress});return d.factoryAddress=l,d.factoryData=c,n&&(d.isInitWebAuthn=!0,d.x=i,d.y=s),d}static getUserOperationEip712Hash(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:Z.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Hash(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static getUserOperationEip712Data(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:Z.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Data(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static createInitializerCallData(e,t,a={}){var r,n;const i=null!=(r=a.safe4337ModuleAddress)?r:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,s=null!=(n=a.safeModuleSetupddress)?n:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS;return J.createBaseInitializerCallData(e,t,i,s,a.multisendContractAddress,a.webAuthnSharedSigner,a.eip7212WebAuthnPrecompileVerifierForSharedSigner,a.eip7212WebAuthnContractVerifierForSharedSigner)}static createFactoryAddressAndData(e,t={}){var a,r;return J.createFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS)}async createUserOperation(e,t,a,r={}){const[n,i,s]=await this.createBaseUserOperationAndFactoryAddressAndFactoryData(e,!1,t,a,r);return f({},n,{factory:i,factoryData:s,paymaster:null,paymasterVerificationGasLimit:null,paymasterPostOpGasLimit:null,paymasterData:null})}}Z.DEFAULT_ENTRYPOINT_ADDRESS=h,Z.DEFAULT_SAFE_4337_MODULE_ADDRESS="0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",Z.DEFAULT_SAFE_MODULE_SETUP_ADDRESS="0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47";class $ extends J{constructor(e,t={}){var a,r;super(e,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.entrypointAddress)?r:$.DEFAULT_ENTRYPOINT_ADDRESS)}static createAccountAddress(e,t={}){var a,r;const[n,,]=J.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return n}static initializeNewAccount(e,t={}){var a,r;let n=!1,i=0n,s=0n;for(const t of e)if("string"!=typeof t){if(n)throw RangeError("Only one Webauthn signer is allowed during initialization");if(0!=e.indexOf(t))throw RangeError("Webauthn owner has to be the first owner for an init transaction.");n=!0,i=t.x,s=t.y}const[o,l,c]=$.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS),d=new $(o,{safe4337ModuleAddress:t.safe4337ModuleAddress,entrypointAddress:t.entrypointAddress});return d.factoryAddress=l,d.factoryData=c,n&&(d.isInitWebAuthn=!0,d.x=i,d.y=s),d}static getUserOperationEip712Hash(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:$.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:$.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Hash(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static getUserOperationEip712Data(e,t,a={}){var r,n,i,s;const o=null!=(r=a.validAfter)?r:0n,l=null!=(n=a.validUntil)?n:0n,c=null!=(i=a.entrypointAddress)?i:$.DEFAULT_ENTRYPOINT_ADDRESS,d=null!=(s=a.safe4337ModuleAddress)?s:$.DEFAULT_SAFE_4337_MODULE_ADDRESS;return J.getUserOperationEip712Data(e,t,{validAfter:o,validUntil:l,entrypointAddress:c,safe4337ModuleAddress:d})}static createAccountAddressAndInitCode(e,t={}){var a,r;const[n,i,s]=J.createAccountAddressAndFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return[n,i+s.slice(2)]}static createInitializerCallData(e,t,a={}){var r,n;const i=null!=(r=a.safe4337ModuleAddress)?r:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,s=null!=(n=a.safeModuleSetupddress)?n:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS;return J.createBaseInitializerCallData(e,t,i,s,a.multisendContractAddress,a.webAuthnSharedSigner,a.eip7212WebAuthnPrecompileVerifierForSharedSigner,a.eip7212WebAuthnContractVerifierForSharedSigner)}static createInitCode(e,t={}){var a,r;const[n,i]=J.createFactoryAddressAndData(e,t,null!=(a=t.safe4337ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,null!=(r=t.safeModuleSetupddress)?r:$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS);return n+i.slice(2)}async createUserOperation(e,t,a,r={}){const[n,i,s]=await this.createBaseUserOperationAndFactoryAddressAndFactoryData(e,!0,t,a,r);let o="0x";if(null==r.initCode){if(null!=i){let e="0x";null!=s&&(e=s),o=i+e.slice(2)}}else o=r.initCode;return f({},n,{initCode:o,paymasterAndData:"0x"})}async createMigrateToSafeAccountV0_3_0MetaTransactions(e,t={}){var a,r;const n=null!=(a=t.safeV06ModuleAddress)?a:$.DEFAULT_SAFE_4337_MODULE_ADDRESS,i=null!=(r=t.safeV07ModuleAddress)?r:Z.DEFAULT_SAFE_4337_MODULE_ADDRESS,s=await this.createDisableModuleMetaTransaction(e,n,this.accountAddress,{prevModuleAddress:t.safeV06ModuleAddress,modulesPageSize:t.pageSize,modulesStart:t.modulesStart}),o=J.createEnableModuleMetaTransaction(i,this.accountAddress),l=R("0xf08a0323",["address"],[i]);return[s,o,{to:this.accountAddress,value:0n,data:l}]}}$.DEFAULT_ENTRYPOINT_ADDRESS=E,$.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",$.DEFAULT_SAFE_MODULE_SETUP_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb";class Q{}class ee extends Q{constructor(e){super(),this.rpcUrl=void 0,this.version=void 0,this.entrypointDataV7=void 0,this.entrypointDataV6=void 0,this.isInitilized=!1,this.rpcUrl=e}async initialize(){try{const e=await v(this.rpcUrl,"pm_clientVersion",[]);if(e.startsWith("Candide/v3"))this.version="v3";else if(e.startsWith("Candide/v2"))this.version="v2";else{if(!e.startsWith("Candide/v1"))throw RangeError("Invalide paymaster version received from paymaster rpc");this.version="v1"}const t=await this.getSupportedEntrypointsLive();if(t.some(e=>e.toLowerCase()===h.toLowerCase())){const e=await this.getSupportedERC20TokensAndPaymasterMetadata(h);this.entrypointDataV7=null!=e?e:null}if(t.some(e=>e.toLowerCase()===E.toLowerCase())){const e=await this.getSupportedERC20TokensAndPaymasterMetadata(E);this.entrypointDataV6=null!=e?e:null}if(null==this.entrypointDataV7&&null==this.entrypointDataV6)throw RangeError("Invalide data received during initilization.");return this.isInitilized=!0,null}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}}async getSupportedERC20TokensAndPaymasterMetadata(e){if(this.isInitilized){var t,a;if(e==h)return null!=(t=this.entrypointDataV7)?t:null;if(e==E)return null!=(a=this.entrypointDataV6)?a:null}else try{let t;if(t="v3"==this.version?await v(this.rpcUrl,"pm_supportedERC20Tokens",[e]):await v(this.rpcUrl,"pm_supportedERC20Tokens",[]),e==h)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals)})),paymasterMetadata:t.paymasterMetadata};if(e==E)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals)})),paymasterMetadata:t.paymasterMetadata};throw RangeError("unsupported entrypoint.")}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}return null}async getSupportedEntrypointsLive(){try{return"v3"==this.version?await v(this.rpcUrl,"pm_supportedEntryPoints",[]):[await v(this.rpcUrl,"pm_supportedEntryPoint",[])]}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}}async getSupportedEntrypoints(){this.isInitilized||await this.initialize();const e=[];return null!=this.entrypointDataV7&&e.push(h),null!=this.entrypointDataV6&&e.push(E),e}async getPaymasterMetaData(e){if(this.isInitilized||await this.initialize(),e==h&&null!=this.entrypointDataV7)return this.entrypointDataV7.paymasterMetadata;if(e==E&&null!=this.entrypointDataV6)return this.entrypointDataV6.paymasterMetadata;throw RangeError("unsupported entrypoint.")}async isSupportedERC20Token(e,t=h){return!!this.getSupportedERC20TokenData(e,t)}async getSupportedERC20TokenData(e,t=h){let a;if(this.isInitilized||await this.initialize(),t==h&&null!=this.entrypointDataV7)a=this.entrypointDataV7.tokens;else{if(t!=E||null==this.entrypointDataV6)throw RangeError("unsupported entrypoint.");a=this.entrypointDataV6.tokens}const r=a.find(t=>t.address.toLowerCase()===e.toLowerCase());return r?{name:r.name,symbol:r.symbol,address:r.address,decimals:Number(r.decimals)}:null}async createPaymasterUserOperation(e,t,a,r){null==a&&(a={});let n=r;null==n&&(n={});const i=f({},e);let s;this.isInitilized||await this.initialize();try{var o,l,c,d,u;let e;if("initCode"in i){if(null==this.entrypointDataV6)throw RangeError("useroperation v0.06 is not supported");e=E,i.paymasterAndData=this.entrypointDataV6.paymasterMetadata.dummyPaymasterAndData}else{if(null==this.entrypointDataV7)throw RangeError("useroperation v0.07 is not supported");e=h;const t=this.entrypointDataV7.paymasterMetadata.dummyPaymasterAndData;i.paymaster=t.paymaster,i.paymasterVerificationGasLimit=t.paymasterVerificationGasLimit,i.paymasterPostOpGasLimit=t.paymasterPostOpGasLimit,i.paymasterData=t.paymasterData}if("v1"==this.version||"v2"==this.version||"token"in a&&null!=a.token){var A,p,g,m,y,S;let a=i.preVerificationGas,r=i.verificationGasLimit,s=i.callGasLimit;if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit){if(null==t)throw new F("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{const o=new H(t);i.callGasLimit=0n,i.verificationGasLimit=0n,i.preVerificationGas=0n;const l=i.maxFeePerGas,c=i.maxPriorityFeePerGas;i.maxFeePerGas=0n,i.maxPriorityFeePerGas=0n;const d=await o.estimateUserOperationGas(i,e,n.state_override_set);a<d.preVerificationGas&&(a=d.preVerificationGas),r<d.verificationGasLimit&&(r=d.verificationGasLimit),s<d.callGasLimit&&(s=d.callGasLimit),i.maxFeePerGas=l,i.maxPriorityFeePerGas=c}}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");i.preVerificationGas=null!=(A=n.preVerificationGas)?A:a*BigInt((null!=(p=n.preVerificationGasPercentageMultiplier)?p:0)+100)/100n,i.verificationGasLimit=null!=(g=n.verificationGasLimit)?g:r*BigInt((null!=(m=n.verificationGasLimitPercentageMultiplier)?m:0)+100)/100n,i.callGasLimit=null!=(y=n.callGasLimit)?y:s*BigInt((null!=(S=n.callGasLimitPercentageMultiplier)?S:0)+100)/100n,i.preVerificationGas=i.preVerificationGas+100n,i.verificationGasLimit=i.verificationGasLimit+10000n}else if(null!=n.preVerificationGas||null!=n.verificationGasLimit||null!=n.callGasLimit||null!=n.preVerificationGasPercentageMultiplier||null!=n.verificationGasLimitPercentageMultiplier||null!=n.callGasLimitPercentageMultiplier)throw RangeError("you can't use any gas overrides for sponsor paymaster v3, as it will estimate gas and override any provided values.");const r=await v(this.rpcUrl,"pm_sponsorUserOperation",[i,e,a]),f=r,D={callGasLimit:null==f.callGasLimit?void 0:BigInt(f.callGasLimit),preVerificationGas:null==f.preVerificationGas?void 0:BigInt(f.preVerificationGas),verificationGasLimit:null==f.verificationGasLimit?void 0:BigInt(f.verificationGasLimit),maxFeePerGas:null==f.maxFeePerGas?void 0:BigInt(f.maxFeePerGas),maxPriorityFeePerGas:null==f.maxPriorityFeePerGas?void 0:BigInt(f.maxPriorityFeePerGas),sponsorMetadata:null==f.sponsorMetadata?void 0:f.sponsorMetadata};if(i.callGasLimit=null!=(o=D.callGasLimit)?o:i.callGasLimit,i.preVerificationGas=null!=(l=D.preVerificationGas)?l:i.preVerificationGas,i.verificationGasLimit=null!=(c=D.verificationGasLimit)?c:i.verificationGasLimit,i.maxFeePerGas=null!=(d=D.maxFeePerGas)?d:i.maxFeePerGas,i.maxPriorityFeePerGas=null!=(u=D.maxPriorityFeePerGas)?u:i.maxPriorityFeePerGas,s=D.sponsorMetadata,"initCode"in i)i.paymasterAndData=r.paymasterAndData;else{const e=r;i.paymaster=e.paymaster,i.paymasterVerificationGasLimit=BigInt(e.paymasterVerificationGasLimit),i.paymasterPostOpGasLimit=BigInt(e.paymasterPostOpGasLimit),i.paymasterData=e.paymasterData}return[i,s]}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})}}async createSponsorPaymasterUserOperation(e,t,a){const r={};return a&&a.trim().length>0&&(r.sponsorshipPolicyId=a),await this.createPaymasterUserOperation(e,t,r)}async createTokenPaymasterUserOperation(e,t,a,r,n={}){const i=n;try{let n;this.isInitilized||await this.initialize(),n="initCode"in t?E:h;const s=2n*await this.calculateUserOperationErc20TokenMaxGasCost(t,a),o=await this.getPaymasterMetaData(n);if(null==o)throw RangeError("unsupported entrypoint.");const l=e.prependTokenPaymasterApproveToCallData(t.callData,a,o.address,s);if(t.callData=l,"initCode"in t){const[e]=await this.createPaymasterUserOperation(t,r,{token:a},i);return e}{const[e]=await this.createPaymasterUserOperation(t,r,{token:a},i);return e}}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}}async calculateUserOperationErc20TokenMaxGasCost(e,t){try{let a;return this.isInitilized||await this.initialize(),a="initCode"in e?E:h,await this.fetchTokenPaymasterExchangeRate(t,a)*G(e)/BigInt(10**18)}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}}async fetchTokenPaymasterExchangeRate(e,t=h){try{let a;this.isInitilized||await this.initialize(),a="v3"==this.version?await v(this.rpcUrl,"pm_supportedERC20Tokens",[t]):await v(this.rpcUrl,"pm_supportedERC20Tokens",[]);const r=a.tokens.map(e=>({address:e.address,exchangeRate:e.exchangeRate})),n=r.find(t=>t.address.toLowerCase()===e.toLowerCase());if(n)return BigInt(n.exchangeRate);throw new F("PAYMASTER_ERROR",e+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadataV7:JSON.stringify(this.entrypointDataV7,(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t),supportedERC20TokensAndPaymasterMetadataV6:JSON.stringify(this.entrypointDataV6,(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t)}})}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","fetchTokenPaymasterExchangeRate failed",{cause:t})}}async fetchSupportedERC20TokensAndPaymasterMetadata(e=h){try{let t;if(this.isInitilized||await this.initialize(),t="v3"==this.version?await v(this.rpcUrl,"pm_supportedERC20Tokens",[e]):await v(this.rpcUrl,"pm_supportedERC20Tokens",[]),e==h)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals),exchangeRate:BigInt(e.exchangeRate)})),paymasterMetadata:t.paymasterMetadata};if(e==E)return{tokens:t.tokens.map(e=>({name:e.name,symbol:e.symbol,address:e.address,decimals:Number(e.decimals),exchangeRate:BigInt(e.exchangeRate)})),paymasterMetadata:t.paymasterMetadata};throw RangeError("unsupported entrypoint.")}catch(e){const t=w(e);throw new F("PAYMASTER_ERROR","fetchSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}}}var te={__proto__:null,SmartAccount:A,SocialRecoveryModule:q,get SocialRecoveryModuleGracePeriodSelector(){return j},AllowanceModule:K,SafeAccountV0_2_0:$,SafeAccountV0_3_0:Z,SendUseroperationResponse:k,SmartAccountFactory:z,SafeAccountFactory:Y,Bundler:H,CandidePaymaster:ee,createUserOperationHash:U,createCallData:R,getFunctionSelector:L,fetchAccountNonce:x,calculateUserOperationMaxGasCost:G,sendJsonRpcRequest:v,fetchGasPrice:P,getDepositInfo:O,getBalanceOf:C,get SafeModuleExecutorFunctionSelector(){return N},EOADummySignerSignaturePair:V,WebauthnDummySignerSignaturePair:B,get Operation(){return D},get GasOption(){return _},get PolygonChain(){return b},ZeroAddress:p,BaseUserOperationDummyValues:g,EIP712_SAFE_OPERATION_V7_TYPE:y,EIP712_SAFE_OPERATION_V6_TYPE:m,DEFAULT_SECP256R1_PRECOMPILE_ADDRESS:S,AbstractionKitError:F};export{F as AbstractionKitError,K as AllowanceModule,g as BaseUserOperationDummyValues,H as Bundler,ee as CandidePaymaster,S as DEFAULT_SECP256R1_PRECOMPILE_ADDRESS,m as EIP712_SAFE_OPERATION_V6_TYPE,y as EIP712_SAFE_OPERATION_V7_TYPE,V as EOADummySignerSignaturePair,_ as GasOption,D as Operation,b as PolygonChain,Y as SafeAccountFactory,$ as SafeAccountV0_2_0,Z as SafeAccountV0_3_0,N as SafeModuleExecutorFunctionSelector,k as SendUseroperationResponse,A as SmartAccount,z as SmartAccountFactory,q as SocialRecoveryModule,j as SocialRecoveryModuleGracePeriodSelector,B as WebauthnDummySignerSignaturePair,p as ZeroAddress,te as abstractionkit,G as calculateUserOperationMaxGasCost,R as createCallData,U as createUserOperationHash,x as fetchAccountNonce,P as fetchGasPrice,C as getBalanceOf,O as getDepositInfo,L as getFunctionSelector,v as sendJsonRpcRequest};
|