UNPKG

abstractionkit

Version:

Account Abstraction 4337 SDK by Candidelabs

1 lines 68.7 kB
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("0xeb37abe