abstractionkit
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -17,2 +17,8 @@ import { SmartAccount } from "../SmartAccount"; | ||
static readonly executorFunctionInputAbi: string[]; | ||
static readonly EIP712_SAFE_OPERATION_TYPE: { | ||
SafeOp: { | ||
type: string; | ||
name: string; | ||
}[]; | ||
}; | ||
readonly entrypointAddress: string; | ||
@@ -35,5 +41,5 @@ readonly safe4337ModuleAddress: string; | ||
signUserOperation(useroperation: UserOperation, privateKeys: string[], chainId: bigint, validAfter?: bigint, validUntil?: bigint): string; | ||
static formatEip712SignaturesToUseroperationSignature(signatures: string[], validAfter?: bigint, validUntil?: bigint): string; | ||
static formatEip712SignaturesToUseroperationSignature(signersAddresses: string[], signatures: string[], validAfter?: bigint, validUntil?: bigint): string; | ||
sendUserOperation(userOperation: UserOperation, bundlerRpc: string): Promise<SendUseroperationResponse>; | ||
} | ||
//# sourceMappingURL=SafeAccountV0_2_0.d.ts.map |
@@ -11,2 +11,7 @@ import type { StateOverrideSet } from "../../types"; | ||
maxPriorityFeePerGas?: bigint; | ||
callGasLimitPercentageMultiplier?: number; | ||
verificationGasLimitPercentageMultiplier?: number; | ||
preVerificationGasPercentageMultiplier?: number; | ||
maxFeePerGasPercentageMultiplier?: number; | ||
maxPriorityFeePerGasPercentageMultiplier?: number; | ||
numberOfSigners?: number; | ||
@@ -13,0 +18,0 @@ state_override_set?: StateOverrideSet; |
@@ -1,1 +0,1 @@ | ||
var e=require("ethers");function t(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var r,n,i=/*#__PURE__*/t(require("isomorphic-unfetch")),a=function(e){this.accountAddress=void 0,this.accountAddress=e};function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},s.apply(this,arguments)}function f(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function l(e){var t="function"==typeof Map?new Map:void 0;return l=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(o())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&u(i,r.prototype),i}(e,arguments,c(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,e)},l(e)}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function p(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}a.proxyByteCode=void 0,a.initializerFunctionSelector=void 0,a.initializerFunctionInputAbi=void 0,a.executorFunctionSelector=void 0,a.executorFunctionInputAbi=void 0,exports.Operation=void 0,(r=exports.Operation||(exports.Operation={}))[r.Call=0]="Call",r[r.Delegate=1]="Delegate",function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(n||(n={}));var h={"-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"},v=/*#__PURE__*/function(e){function t(t,r,n){var i;void 0===n&&(n={});var a=n.errno,o=n.context;return(i=e.call(this,r,{cause:n.cause})||this).code=void 0,i.context=void 0,i.errno=void 0,i.name=i.constructor.name,i.code=t,i.errno=a,i.context=o,i}return f(t,e),t}(/*#__PURE__*/l(Error));function m(e){if(e instanceof Error)return e;var t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error("This value was thrown as is, not through an Error: "+t)}var y=function(e,t,r,n){void 0===n&&(n=0);try{var i=[{from:"0x0000000000000000000000000000000000000000",to:t,data:g(E("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(A(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new v("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=m(e);throw new v("BAD_DATA","getNonce returned ill formed data",{cause:t})}})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=m(e);throw new v("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},A=function(e,t,r){try{var n=i.default||i,a={method:"POST",body:JSON.stringify({method:t,params:r,id:(new Date).getTime(),jsonrpc:"2.0"},function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t}),redirect:"follow"};return Promise.resolve(n(e,a)).then(function(t){return Promise.resolve(t.json()).then(function(t){if("result"in t)return t.result;var r=t.error,n=String(r.code);throw new v(n in h?h[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(a)}})})})}catch(e){return Promise.reject(e)}};function P(t,r,n){var i=e.keccak256(function(t){var r=[t.sender,t.nonce,e.keccak256(t.initCode),e.keccak256(t.callData),t.callGasLimit,t.verificationGasLimit,t.preVerificationGas,t.maxFeePerGas,t.maxPriorityFeePerGas,e.keccak256(t.paymasterAndData)];return e.AbiCoder.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],r)}(t)),a=e.AbiCoder.defaultAbiCoder().encode(["bytes32","address","uint256"],[i,r,n]);return e.keccak256(a)}function g(t,r,n){return t+e.AbiCoder.defaultAbiCoder().encode(r,n).slice(2)}function E(t){return e.id(t).slice(0,10)}function D(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var b,O="0x0000000000000000000000000000000000000000",G={sender:O,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0xffffffn,verificationGasLimit:0xffffffn,preVerificationGas:0xffffffn,maxFeePerGas:0xffffffn,maxPriorityFeePerGas:0xfffffffn,paymasterAndData:"0x",signature:"0x"},R=/*#__PURE__*/function(){function e(e,t,r){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=r}return e.prototype.getFactoryGeneratorFunctionCallData=function(e){var t=g(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)},e}(),x=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return f(t,e),t}(R);function S(t){return"0x"+t.map(function(t){return i=null!=(n=(r=t).operation)?n:exports.Operation.Call,a=e.getBytes(r.data),e.solidityPacked(["uint8","address","uint256","uint256","bytes"],[i,r.to,r.value,a.length,a]).slice(2);var r,n,i,a}).join("")}function _(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(b||(b={}));var U=/*#__PURE__*/function(){function e(e){this.rpcUrl=void 0,this.rpcUrl=e}var t=e.prototype;return t.chainId=function(){try{var e=this;return Promise.resolve(_(function(){return Promise.resolve(A(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new v("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=m(e);throw new v("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.supportedEntryPoints=function(){try{var e=this;return Promise.resolve(_(function(){return Promise.resolve(A(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=m(e);throw new v("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.estimateUserOperationGas=function(e,t,r){try{var n=this;return Promise.resolve(_(function(){function i(){var e=a;return{callGasLimit:BigInt(e.callGasLimit),preVerificationGas:BigInt(e.preVerificationGas),verificationGasLimit:BigInt(e.verificationGasLimit)}}var a={},o=void 0===r?Promise.resolve(A(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(A(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=m(e);throw new v("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.sendUserOperation=function(e,t){try{var r=this;return Promise.resolve(_(function(){return Promise.resolve(A(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=m(e);throw new v("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.getUserOperationReceipt=function(e){try{var t=this;return Promise.resolve(_(function(){return Promise.resolve(A(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=s({},t.receipt,{blockNumber:BigInt(t.receipt.blockNumber),cumulativeGasUsed:BigInt(t.receipt.cumulativeGasUsed),gasUsed:BigInt(t.receipt.gasUsed),transactionIndex:BigInt(t.receipt.transactionIndex),effectiveGasPrice:null==t.receipt.effectiveGasPrice?void 0:BigInt(t.receipt.effectiveGasPrice),logs:JSON.stringify(t.receipt.logs)});return s({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:r})}return null})},function(t){var r=m(t);throw new v("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},t.getUserOperationByHash=function(e){try{var t=this;return Promise.resolve(_(function(){return Promise.resolve(A(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?s({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=m(t);throw new v("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},e}();function T(e,t,r){if(!e.s){if(r instanceof F){if(!r.s)return void(r.o=T.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(T.bind(null,e,t),T.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var F=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var a=1&i?t:r;if(a){try{T(n,1,a(this.v))}catch(e){T(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?T(n,1,t?t(i):i):r?T(n,1,r(i)):T(n,2,i)}catch(e){T(n,2,e)}},n},e}();function w(e){return e instanceof F&&1&e.s}var L=/*#__PURE__*/function(){function e(e,t,r){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=r}var t=e.prototype;return t.delay=function(e){return new Promise(function(t){return setTimeout(t,e)})},t.included=function(e,t){void 0===e&&(e=180),void 0===t&&(t=2);try{var r,n=function(e){if(r)return e;throw new v("TIMEOUT","can't find useroperation",{context:i.userOperationHash})},i=this;if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");var a=0,o=function(e,t,r){for(var n;;){var i=e();if(w(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!w(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!w(o)){n=2;break}}}var s=new F,f=T.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(c):o.then(l)).then(void 0,f),s;function c(n){a=n;do{if(t&&(o=t())&&o.then&&!w(o))return void o.then(l).then(void 0,f);if(!(i=e())||w(i)&&!i.v)return void T(s,1,a);if(i.then)return void i.then(u).then(void 0,f);w(a=r())&&(a=a.v)}while(!a||!a.then);a.then(c).then(void 0,f)}function u(e){e?(a=r())&&a.then?a.then(c).then(void 0,f):c(a):T(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,f):u(i):T(s,1,a)}}(function(){return!r&&a<=e},void 0,function(){return Promise.resolve(i.delay(1e3*t)).then(function(){return Promise.resolve(i.bundler.getUserOperationReceipt(i.userOperationHash)).then(function(e){if(null!=e)return r=1,e;a++})})});return Promise.resolve(o&&o.then?o.then(n):n(o))}catch(e){return Promise.reject(e)}},e}(),C=/*#__PURE__*/function(t){function r(e,n,i){var a;return void 0===n&&(n=r.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=r.DEFAULT_ENTRYPOINT_ADDRESS),(a=t.call(this,e)||this).entrypointAddress=void 0,a.safe4337ModuleAddress=void 0,a.initCode=void 0,a.entrypointAddress=i,a.safe4337ModuleAddress=n,a.initCode=null,a}f(r,t),r.initializeNewAccount=function(e,t){void 0===t&&(t={});var n=r.createAccountAddressAndInitCode(e,t),i=n[1],a=new r(n[0]);return a.initCode=i,a},r.createAccountAddressAndInitCode=function(e,t){var n,i,a,o,s;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one owner");var f=null!=(n=t.threshold)?n:1,c=null!=(i=t.c2Nonce)?i:0n,u=null!=(a=t.singletonAddress)?a:r.DEFAULT_SINGLETON_ADDRESS,l=null!=(o=t.safe4337ModuleAddress)?o:r.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:r.DEFAULT_ADD_MODULE_LIB_ADDRESS,p=new x;null!=t.safeAccountFactoryAddress&&(p=new x(t.safeAccountFactoryAddress));var h=r.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(h,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,h,c])]},r.createInitializerCallData=function(e,t,n,i){if(void 0===n&&(n=r.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=r.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");var a=g("0x8d0dc49f",["address[]"],[[n]]);return g(r.initializerFunctionSelector,r.initializerFunctionInputAbi,[e,t,i,a,n,O,0,O])},r.createInitCode=function(e,t,n,i,a,o,s){if(void 0===t&&(t=1),void 0===n&&(n=0n),void 0===i&&(i=r.DEFAULT_SINGLETON_ADDRESS),void 0===a&&(a=new x),void 0===o&&(o=r.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===s&&(s=r.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");if(n<0n)throw RangeError("c2Nonce can't be negative");var f=r.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,f,n])},r.createProxyAddress=function(t,r,n,i){if(r<0n)throw RangeError("c2Nonce can't be negative");var a=e.AbiCoder.defaultAbiCoder(),o=e.keccak256(e.solidityPacked(["bytes32","uint256"],[e.keccak256(t),r])),s=a.encode(["uint256"],[i]),f=e.keccak256(e.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+e.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,f]).slice(-40)},r.createAccountCallDataSingleTransaction=function(e){var t,n,i,a=null!=(t=e.value)?t:0,o=null!=(n=e.data)?n:"0x",s=null!=(i=e.operation)?i:exports.Operation.Call;return r.createAccountCallData(e.to,a,o,s)},r.createAccountCallDataBatchTransactions=function(e,t){if(void 0===t&&(t=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS),e.length<1)throw RangeError("There should be at least one metaTransaction");var n=g("0x8d80ff0a",["bytes"],[S(e)]);return r.createAccountCallData(t,0n,n,exports.Operation.Delegate)},r.createAccountCallData=function(e,t,n,i,a){return void 0===a&&(a=r.DEFAULT_EXECUTOR_FUCNTION_SELECTOR),g(a,r.executorFunctionInputAbi,[e,t,n,i])};var i=r.prototype;return i.decodeAccountCallData=function(t){if(t.startsWith(b.executeUserOpWithErrorString)||t.startsWith(b.executeUserOp)){var r=e.AbiCoder.defaultAbiCoder(),n="0x"+t.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);return[i[0],BigInt(i[1]),i[2],Number(i[3])]}throw new v("BAD_DATA","Invalid calldata, should start with "+b.executeUserOpWithErrorString+" or "+b.executeUserOp,{context:{callData:t}})},i.prependTokenPaymasterApproveToCallData=function(t,n,i,a,o){void 0===o&&(o=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=this.decodeAccountCallData(t),f=s[0],c=s[1],u=s[2],l=s[3],d="";d="string"!=typeof u?(new TextDecoder).decode(u):u;var p=S([{to:n,value:0n,data:g(E("approve(address,uint256)"),["address","uint256"],[i,a]),operation:exports.Operation.Call}]),h="",v="0x8d80ff0a";if(d.startsWith(v)){var m=function(t){return e.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+t.slice(10))[0]}(d);h=m+p.slice(2)}else h=S([{to:f,value:c,data:u,operation:l}])+p.slice(2);var y=g(v,["bytes"],[h]);return r.createAccountCallData(o,0n,y,exports.Operation.Delegate)},i.estimateUserOperationGas=function(e,t,r,n){void 0===n&&(n=1);try{if(n<1n)throw RangeError("numberOfSigners can't be less than 1");for(var i="",a=0;a<n;a++)i+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+i;var o=new U(t);return Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(e){return[BigInt(e.preVerificationGas),BigInt(e.verificationGasLimit)+5000n*BigInt(n),BigInt(e.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(t,i,a,o){void 0===o&&(o={});try{var f=function(){var f;function l(){var e,t;function r(){var e,t,r;if("bigint"==typeof o.preVerificationGas&&o.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof o.verificationGasLimit&&o.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof o.callGasLimit&&o.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return n.preVerificationGas=null!=(e=o.preVerificationGas)?e:i,n.verificationGasLimit=null!=(t=o.verificationGasLimit)?t:f,n.callGasLimit=null!=(r=o.callGasLimit)?r:l,n}if("bigint"==typeof o.maxFeePerGas&&o.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof o.maxPriorityFeePerGas&&o.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");h=null!=(e=o.maxFeePerGas)?e:h,v=null!=(t=o.maxPriorityFeePerGas)?t:v;var n=s({},G,{sender:c.accountAddress,nonce:u,initCode:d,callData:p,maxFeePerGas:h,maxPriorityFeePerGas:v}),i=G.preVerificationGas,f=G.verificationGasLimit,l=G.callGasLimit,m=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return Promise.resolve(c.estimateUserOperationGas(n,a,o.state_override_set,o.numberOfSigners)).then(function(e){i=e[0],f=e[1],l=e[2]})}();return m&&m.then?m.then(r):r()}var d=null!=(f=o.initCode)?f:c.initCode;if((null==d||u>0n)&&(d="0x"),u<0n)throw RangeError("nonce can't be negative");var p="0x";p=null==o.callData?1==t.length?r.createAccountCallDataSingleTransaction(t[0]):r.createAccountCallDataBatchTransactions(t):o.callData;var h=G.maxFeePerGas,v=G.maxPriorityFeePerGas,m=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return Promise.resolve(function(t,r){try{void 0===r&&(r=n.Medium);var i=new e.JsonRpcProvider(t);return Promise.resolve(i.getFeeData()).then(function(e){return[BigInt(Math.ceil(Number(e.maxFeePerGas)*r)),BigInt(Math.ceil(Number(e.maxPriorityFeePerGas)*r))]})}catch(e){return Promise.reject(e)}}(i)).then(function(e){h=e[0],v=e[1]})}();return m&&m.then?m.then(l):l()},c=this;if(t.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return Promise.resolve(y(i,c.entrypointAddress,c.accountAddress)).then(function(e){u=e});u=o.nonce}();return Promise.resolve(l&&l.then?l.then(f):f())}catch(e){return Promise.reject(e)}},i.signUserOperation=function(t,n,i,a,o){if(void 0===a&&(a=0n),void 0===o&&(o=0n),n.length<1)throw RangeError("There should be at least one privateKey");if(i<0n)throw RangeError("chainId can't be negative");if(a<0n)throw RangeError("validAfter can't be negative");if(o<0n)throw RangeError("validUntil can't be negative");for(var s,f={safe:t.sender,nonce:t.nonce,initCode:t.initCode,callData:t.callData,callGasLimit:t.callGasLimit,verificationGasLimit:t.verificationGasLimit,preVerificationGas:t.preVerificationGas,maxFeePerGas:t.maxFeePerGas,maxPriorityFeePerGas:t.maxPriorityFeePerGas,paymasterAndData:t.paymasterAndData,validAfter:a,validUntil:o,entryPoint:this.entrypointAddress},c={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"}]},u=new Map,l=p(n);!(s=l()).done;){var d=new e.Wallet(s.value);u.set(d.address,d)}for(var h,v=[],m=p(Array.from(u.keys()).sort());!(h=m()).done;){var y=u.get(h.value).signingKey.sign(e.TypedDataEncoder.hash({chainId:i,verifyingContract:this.safe4337ModuleAddress},c,f)).serialized;v.push(y.slice(2))}return r.formatEip712SignaturesToUseroperationSignature(v,a,o)},r.formatEip712SignaturesToUseroperationSignature=function(t,r,n){void 0===r&&(r=0n),void 0===n&&(n=0n);var i="0x"+t.join("");return e.solidityPacked(["uint48","uint48","bytes"],[r,n,i])},i.sendUserOperation=function(e,t){try{var r=this,n=new U(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new L(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},r}(a);function I(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}C.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",C.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",C.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",C.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",C.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",C.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",C.initializerFunctionSelector="0xb63e800d",C.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],C.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=b.executeUserOpWithErrorString,C.executorFunctionInputAbi=["address","uint256","bytes","uint8"];var N=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this)||this).rpcUrl=void 0,r.entrypointAddress=void 0,r.supportedTokens=void 0,r.paymasterMetadata=void 0,r.rpcUrl=t,r}f(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(I(function(){return Promise.resolve(e.getSupportedEntrypoint()).then(function(t){return e.entrypointAddress=t,Promise.resolve(e.getSupportedERC20TokensAndPaymasterMetadata()).then(function(t){return e.supportedTokens=t.tokens,e.paymasterMetadata=t.paymasterMetadata,null})})},function(e){var t=m(e);throw new v("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}))}catch(e){return Promise.reject(e)}},r.getPaymasterMetaData=function(){try{var e=function(){return t.paymasterMetadata},t=this,r=function(){if(null==t.paymasterMetadata)return Promise.resolve(t.initialize()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokensAndPaymasterMetadata=function(){try{var e=this;return Promise.resolve(null==e.supportedTokens||null==e.paymasterMetadata?I(function(){return Promise.resolve(A(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens,paymasterMetadata:e.paymasterMetadata}})},function(e){var t=m(e);throw new v("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}):{tokens:e.supportedTokens,paymasterMetadata:e.paymasterMetadata})}catch(e){return Promise.reject(e)}},r.getSupportedEntrypoint=function(){try{var e=this;return Promise.resolve(null==e.entrypointAddress?I(function(){return Promise.resolve(A(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=m(e);throw new v("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}):e.entrypointAddress)}catch(e){return Promise.reject(e)}},r.isSupportedERC20Token=function(e){try{var t=function(){return!!r.supportedTokens.find(function(t){return t.address===e.toLowerCase()})},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokenData=function(e){try{var t=function(){var t=r.supportedTokens.find(function(t){return t.address.toLowerCase()===e.toLowerCase()});return t?{symbol:t.symbol,address:t.address,decimal:Number(t.decimal),fee:BigInt(t.fee),exchangeRate:BigInt(t.exchangeRate)}:null},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.createPaymasterUserOperation=function(e,t,r,n){void 0===r&&(r={});try{var i=function(){return I(function(){e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var i=new U(t);return Promise.resolve(i.estimateUserOperationGas(e,a.entrypointAddress,n)).then(function(t){return e.preVerificationGas=t.preVerificationGas,e.verificationGasLimit=t.verificationGasLimit+10000n,e.callGasLimit=t.callGasLimit,Promise.resolve(A(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,f={paymasterAndData:s.paymasterAndData,callGasLimit:null==s.callGasLimit?void 0:BigInt(s.callGasLimit),preVerificationGas:null==s.preVerificationGas?void 0:BigInt(s.preVerificationGas),verificationGasLimit:null==s.verificationGasLimit?void 0:BigInt(s.verificationGasLimit),maxFeePerGas:null==s.maxFeePerGas?void 0:BigInt(s.maxFeePerGas),maxPriorityFeePerGas:null==s.maxPriorityFeePerGas?void 0:BigInt(s.maxPriorityFeePerGas)};return e.paymasterAndData=f.paymasterAndData,e.callGasLimit=null!=(r=f.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=f.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=f.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=f.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=f.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})})},function(e){var t=m(e);throw new v("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})})},a=this,o=function(){if(null==a.entrypointAddress||null==a.supportedTokens||null==a.paymasterMetadata)return Promise.resolve(a.initialize()).then(function(){})}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}},r.createSponsorPaymasterUserOperation=function(e,t,r){try{return Promise.resolve(this.createPaymasterUserOperation(e,t,{},r))}catch(e){return Promise.reject(e)}},r.createTokenPaymasterUserOperation=function(e,t,r,n,i){void 0===i&&(i={});try{var a=this;return Promise.resolve(I(function(){return Promise.resolve(a.calculateUserOperationErc20TokenMaxGasCost(t,r)).then(function(o){var s=2n*o;return Promise.resolve(a.getPaymasterMetaData()).then(function(o){var f=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=f,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=m(e);throw new v("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(I(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new v("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e)}})});var i=D(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=m(e);throw new v("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),B={__proto__:null,SmartAccount:a,SafeAccountV0_2_0:C,SendUseroperationResponse:L,SmartAccountFactory:R,SafeAccountFactory:x,Bundler:U,CandidePaymaster:N,createUserOperationHash:P,createCallData:g,getFunctionSelector:E,fetchAccountNonce:y,calculateUserOperationMaxGasCost:D,get Operation(){return exports.Operation}};exports.Bundler=U,exports.CandidePaymaster=N,exports.SafeAccountFactory=x,exports.SafeAccountV0_2_0=C,exports.SendUseroperationResponse=L,exports.SmartAccount=a,exports.SmartAccountFactory=R,exports.abstractionkit=B,exports.calculateUserOperationMaxGasCost=D,exports.createCallData=g,exports.createUserOperationHash=P,exports.fetchAccountNonce=y,exports.getFunctionSelector=E; | ||
var e=require("ethers");function t(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var r,n,i=/*#__PURE__*/t(require("isomorphic-unfetch")),a=function(e){this.accountAddress=void 0,this.accountAddress=e};function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},s.apply(this,arguments)}function f(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function l(e){var t="function"==typeof Map?new Map:void 0;return l=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(o())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&u(i,r.prototype),i}(e,arguments,c(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,e)},l(e)}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}a.proxyByteCode=void 0,a.initializerFunctionSelector=void 0,a.initializerFunctionInputAbi=void 0,a.executorFunctionSelector=void 0,a.executorFunctionInputAbi=void 0,exports.Operation=void 0,(r=exports.Operation||(exports.Operation={}))[r.Call=0]="Call",r[r.Delegate=1]="Delegate",function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(n||(n={}));var p={"-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"},h=/*#__PURE__*/function(e){function t(t,r,n){var i;void 0===n&&(n={});var a=n.errno,o=n.context;return(i=e.call(this,r,{cause:n.cause})||this).code=void 0,i.context=void 0,i.errno=void 0,i.name=i.constructor.name,i.code=t,i.errno=a,i.context=o,i}return f(t,e),t}(/*#__PURE__*/l(Error));function v(e){if(e instanceof Error)return e;var t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error("This value was thrown as is, not through an Error: "+t)}var m=function(e,t,r,n){void 0===n&&(n=0);try{var i=[{from:"0x0000000000000000000000000000000000000000",to:t,data:P(g("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(y(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new h("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=v(e);throw new h("BAD_DATA","getNonce returned ill formed data",{cause:t})}})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=v(e);throw new h("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},y=function(e,t,r){try{var n=i.default||i,a={method:"POST",body:JSON.stringify({method:t,params:r,id:(new Date).getTime(),jsonrpc:"2.0"},function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t}),redirect:"follow"};return Promise.resolve(n(e,a)).then(function(t){return Promise.resolve(t.json()).then(function(t){if("result"in t)return t.result;var r=t.error,n=String(r.code);throw new h(n in p?p[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(a)}})})})}catch(e){return Promise.reject(e)}};function A(t,r,n){var i=e.keccak256(function(t){var r=[t.sender,t.nonce,e.keccak256(t.initCode),e.keccak256(t.callData),t.callGasLimit,t.verificationGasLimit,t.preVerificationGas,t.maxFeePerGas,t.maxPriorityFeePerGas,e.keccak256(t.paymasterAndData)];return e.AbiCoder.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],r)}(t)),a=e.AbiCoder.defaultAbiCoder().encode(["bytes32","address","uint256"],[i,r,n]);return e.keccak256(a)}function P(t,r,n){return t+e.AbiCoder.defaultAbiCoder().encode(r,n).slice(2)}function g(t){return e.id(t).slice(0,10)}function E(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var D,b="0x0000000000000000000000000000000000000000",O={sender:b,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0xffffffn,verificationGasLimit:0xffffffn,preVerificationGas:0xffffffn,maxFeePerGas:0xffffffn,maxPriorityFeePerGas:0xfffffffn,paymasterAndData:"0x",signature:"0x"},G=/*#__PURE__*/function(){function e(e,t,r){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=r}return e.prototype.getFactoryGeneratorFunctionCallData=function(e){var t=P(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)},e}(),R=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return f(t,e),t}(G);function x(t){return"0x"+t.map(function(t){return i=null!=(n=(r=t).operation)?n:exports.Operation.Call,a=e.getBytes(r.data),e.solidityPacked(["uint8","address","uint256","uint256","bytes"],[i,r.to,r.value,a.length,a]).slice(2);var r,n,i,a}).join("")}function _(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(D||(D={}));var S=/*#__PURE__*/function(){function e(e){this.rpcUrl=void 0,this.rpcUrl=e}var t=e.prototype;return t.chainId=function(){try{var e=this;return Promise.resolve(_(function(){return Promise.resolve(y(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new h("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=v(e);throw new h("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.supportedEntryPoints=function(){try{var e=this;return Promise.resolve(_(function(){return Promise.resolve(y(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=v(e);throw new h("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.estimateUserOperationGas=function(e,t,r){try{var n=this;return Promise.resolve(_(function(){function i(){var e=a;return{callGasLimit:BigInt(e.callGasLimit),preVerificationGas:BigInt(e.preVerificationGas),verificationGasLimit:BigInt(e.verificationGasLimit)}}var a={},o=void 0===r?Promise.resolve(y(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(y(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=v(e);throw new h("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.sendUserOperation=function(e,t){try{var r=this;return Promise.resolve(_(function(){return Promise.resolve(y(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=v(e);throw new h("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.getUserOperationReceipt=function(e){try{var t=this;return Promise.resolve(_(function(){return Promise.resolve(y(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=s({},t.receipt,{blockNumber:BigInt(t.receipt.blockNumber),cumulativeGasUsed:BigInt(t.receipt.cumulativeGasUsed),gasUsed:BigInt(t.receipt.gasUsed),transactionIndex:BigInt(t.receipt.transactionIndex),effectiveGasPrice:null==t.receipt.effectiveGasPrice?void 0:BigInt(t.receipt.effectiveGasPrice),logs:JSON.stringify(t.receipt.logs)});return s({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:r})}return null})},function(t){var r=v(t);throw new h("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},t.getUserOperationByHash=function(e){try{var t=this;return Promise.resolve(_(function(){return Promise.resolve(y(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?s({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=v(t);throw new h("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},e}();function U(e,t,r){if(!e.s){if(r instanceof T){if(!r.s)return void(r.o=U.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(U.bind(null,e,t),U.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var T=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var a=1&i?t:r;if(a){try{U(n,1,a(this.v))}catch(e){U(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?U(n,1,t?t(i):i):r?U(n,1,r(i)):U(n,2,i)}catch(e){U(n,2,e)}},n},e}();function F(e){return e instanceof T&&1&e.s}var w=/*#__PURE__*/function(){function e(e,t,r){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=r}var t=e.prototype;return t.delay=function(e){return new Promise(function(t){return setTimeout(t,e)})},t.included=function(e,t){void 0===e&&(e=180),void 0===t&&(t=2);try{var r,n=function(e){if(r)return e;throw new h("TIMEOUT","can't find useroperation",{context:i.userOperationHash})},i=this;if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");var a=0,o=function(e,t,r){for(var n;;){var i=e();if(F(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!F(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!F(o)){n=2;break}}}var s=new T,f=U.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(c):o.then(l)).then(void 0,f),s;function c(n){a=n;do{if(t&&(o=t())&&o.then&&!F(o))return void o.then(l).then(void 0,f);if(!(i=e())||F(i)&&!i.v)return void U(s,1,a);if(i.then)return void i.then(u).then(void 0,f);F(a=r())&&(a=a.v)}while(!a||!a.then);a.then(c).then(void 0,f)}function u(e){e?(a=r())&&a.then?a.then(c).then(void 0,f):c(a):U(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,f):u(i):U(s,1,a)}}(function(){return!r&&a<=e},void 0,function(){return Promise.resolve(i.delay(1e3*t)).then(function(){return Promise.resolve(i.bundler.getUserOperationReceipt(i.userOperationHash)).then(function(e){if(null!=e)return r=1,e;a++})})});return Promise.resolve(o&&o.then?o.then(n):n(o))}catch(e){return Promise.reject(e)}},e}(),L=/*#__PURE__*/function(t){function r(e,n,i){var a;return void 0===n&&(n=r.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=r.DEFAULT_ENTRYPOINT_ADDRESS),(a=t.call(this,e)||this).entrypointAddress=void 0,a.safe4337ModuleAddress=void 0,a.initCode=void 0,a.entrypointAddress=i,a.safe4337ModuleAddress=n,a.initCode=null,a}f(r,t),r.initializeNewAccount=function(e,t){void 0===t&&(t={});var n=r.createAccountAddressAndInitCode(e,t),i=n[1],a=new r(n[0]);return a.initCode=i,a},r.createAccountAddressAndInitCode=function(e,t){var n,i,a,o,s;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one owner");var f=null!=(n=t.threshold)?n:1,c=null!=(i=t.c2Nonce)?i:0n,u=null!=(a=t.singletonAddress)?a:r.DEFAULT_SINGLETON_ADDRESS,l=null!=(o=t.safe4337ModuleAddress)?o:r.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:r.DEFAULT_ADD_MODULE_LIB_ADDRESS,p=new R;null!=t.safeAccountFactoryAddress&&(p=new R(t.safeAccountFactoryAddress));var h=r.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(h,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,h,c])]},r.createInitializerCallData=function(e,t,n,i){if(void 0===n&&(n=r.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=r.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");var a=P("0x8d0dc49f",["address[]"],[[n]]);return P(r.initializerFunctionSelector,r.initializerFunctionInputAbi,[e,t,i,a,n,b,0,b])},r.createInitCode=function(e,t,n,i,a,o,s){if(void 0===t&&(t=1),void 0===n&&(n=0n),void 0===i&&(i=r.DEFAULT_SINGLETON_ADDRESS),void 0===a&&(a=new R),void 0===o&&(o=r.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===s&&(s=r.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");if(n<0n)throw RangeError("c2Nonce can't be negative");var f=r.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,f,n])},r.createProxyAddress=function(t,r,n,i){if(r<0n)throw RangeError("c2Nonce can't be negative");var a=e.AbiCoder.defaultAbiCoder(),o=e.keccak256(e.solidityPacked(["bytes32","uint256"],[e.keccak256(t),r])),s=a.encode(["uint256"],[i]),f=e.keccak256(e.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+e.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,f]).slice(-40)},r.createAccountCallDataSingleTransaction=function(e){var t,n,i,a=null!=(t=e.value)?t:0,o=null!=(n=e.data)?n:"0x",s=null!=(i=e.operation)?i:exports.Operation.Call;return r.createAccountCallData(e.to,a,o,s)},r.createAccountCallDataBatchTransactions=function(e,t){if(void 0===t&&(t=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS),e.length<1)throw RangeError("There should be at least one metaTransaction");var n=P("0x8d80ff0a",["bytes"],[x(e)]);return r.createAccountCallData(t,0n,n,exports.Operation.Delegate)},r.createAccountCallData=function(e,t,n,i,a){return void 0===a&&(a=r.DEFAULT_EXECUTOR_FUCNTION_SELECTOR),P(a,r.executorFunctionInputAbi,[e,t,n,i])};var i=r.prototype;return i.decodeAccountCallData=function(t){if(t.startsWith(D.executeUserOpWithErrorString)||t.startsWith(D.executeUserOp)){var r=e.AbiCoder.defaultAbiCoder(),n="0x"+t.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);return[i[0],BigInt(i[1]),i[2],Number(i[3])]}throw new h("BAD_DATA","Invalid calldata, should start with "+D.executeUserOpWithErrorString+" or "+D.executeUserOp,{context:{callData:t}})},i.prependTokenPaymasterApproveToCallData=function(t,n,i,a,o){void 0===o&&(o=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=this.decodeAccountCallData(t),f=s[0],c=s[1],u=s[2],l=s[3],d="";d="string"!=typeof u?(new TextDecoder).decode(u):u;var p=x([{to:n,value:0n,data:P(g("approve(address,uint256)"),["address","uint256"],[i,a]),operation:exports.Operation.Call}]),h="",v="0x8d80ff0a";if(d.startsWith(v)){var m=function(t){return e.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+t.slice(10))[0]}(d);h=m+p.slice(2)}else h=x([{to:f,value:c,data:u,operation:l}])+p.slice(2);var y=P(v,["bytes"],[h]);return r.createAccountCallData(o,0n,y,exports.Operation.Delegate)},i.estimateUserOperationGas=function(e,t,r,n){void 0===n&&(n=1);try{if(n<1n)throw RangeError("numberOfSigners can't be less than 1");for(var i="",a=0;a<n;a++)i+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+i;var o=new S(t);return Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(e){return[BigInt(e.preVerificationGas),BigInt(e.verificationGasLimit)+5000n*BigInt(n),BigInt(e.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(t,i,a,o){void 0===o&&(o={});try{var f=function(){var f;function l(){var e,t,r,n;function i(){var e,t,r,n,i,a;if("bigint"==typeof o.preVerificationGas&&o.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof o.verificationGasLimit&&o.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof o.callGasLimit&&o.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return f.preVerificationGas=null!=(e=o.preVerificationGas)?e:l*BigInt(Math.floor(((null!=(t=o.preVerificationGasPercentageMultiplier)?t:0)+100)/100)),f.verificationGasLimit=null!=(r=o.verificationGasLimit)?r:m*BigInt(Math.floor(((null!=(n=o.verificationGasLimitPercentageMultiplier)?n:0)+100)/100)),f.callGasLimit=null!=(i=o.callGasLimit)?i:y*BigInt(Math.floor(((null!=(a=o.callGasLimitPercentageMultiplier)?a:0)+100)/100)),f}if("bigint"==typeof o.maxFeePerGas&&o.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof o.maxPriorityFeePerGas&&o.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");h=null!=(e=o.maxFeePerGas)?e:h*BigInt(Math.floor(((null!=(t=o.maxFeePerGasPercentageMultiplier)?t:0)+100)/100)),v=null!=(r=o.maxPriorityFeePerGas)?r:v*BigInt(Math.floor(((null!=(n=o.maxPriorityFeePerGasPercentageMultiplier)?n:0)+100)/100));var f=s({},O,{sender:c.accountAddress,nonce:u,initCode:d,callData:p,maxFeePerGas:h,maxPriorityFeePerGas:v}),l=O.preVerificationGas,m=O.verificationGasLimit,y=O.callGasLimit,A=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return Promise.resolve(c.estimateUserOperationGas(f,a,o.state_override_set,o.numberOfSigners)).then(function(e){l=e[0],m=e[1],y=e[2]})}();return A&&A.then?A.then(i):i()}var d=null!=(f=o.initCode)?f:c.initCode;if((null==d||u>0n)&&(d="0x"),u<0n)throw RangeError("nonce can't be negative");var p="0x";p=null==o.callData?1==t.length?r.createAccountCallDataSingleTransaction(t[0]):r.createAccountCallDataBatchTransactions(t):o.callData;var h=O.maxFeePerGas,v=O.maxPriorityFeePerGas,m=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return Promise.resolve(function(t,r){try{void 0===r&&(r=n.Medium);var i=new e.JsonRpcProvider(t);return Promise.resolve(i.getFeeData()).then(function(e){return[BigInt(Math.ceil(Number(e.maxFeePerGas)*r)),BigInt(Math.ceil(Number(e.maxPriorityFeePerGas)*r))]})}catch(e){return Promise.reject(e)}}(i)).then(function(e){h=e[0],v=e[1]})}();return m&&m.then?m.then(l):l()},c=this;if(t.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return Promise.resolve(m(i,c.entrypointAddress,c.accountAddress)).then(function(e){u=e});u=o.nonce}();return Promise.resolve(l&&l.then?l.then(f):f())}catch(e){return Promise.reject(e)}},i.signUserOperation=function(t,n,i,a,o){if(void 0===a&&(a=0n),void 0===o&&(o=0n),n.length<1)throw RangeError("There should be at least one privateKey");if(i<0n)throw RangeError("chainId can't be negative");if(a<0n)throw RangeError("validAfter can't be negative");if(o<0n)throw RangeError("validUntil can't be negative");for(var s,f={safe:t.sender,nonce:t.nonce,initCode:t.initCode,callData:t.callData,callGasLimit:t.callGasLimit,verificationGasLimit:t.verificationGasLimit,preVerificationGas:t.preVerificationGas,maxFeePerGas:t.maxFeePerGas,maxPriorityFeePerGas:t.maxPriorityFeePerGas,paymasterAndData:t.paymasterAndData,validAfter:a,validUntil:o,entryPoint:this.entrypointAddress},c=[],u=[],l=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(n);!(s=l()).done;){var p=new e.Wallet(s.value),h=p.signingKey.sign(e.TypedDataEncoder.hash({chainId:i,verifyingContract:this.safe4337ModuleAddress},r.EIP712_SAFE_OPERATION_TYPE,f)).serialized;c.push(p.address),u.push(h)}return r.formatEip712SignaturesToUseroperationSignature(c,u,a,o)},r.formatEip712SignaturesToUseroperationSignature=function(t,r,n,i){if(void 0===n&&(n=0n),void 0===i&&(i=0n),t.length!=r.length)throw RangeError("signersAddresses and signatures arrays should be the same length");if(n<0n)throw RangeError("validAfter can't be negative");if(i<0n)throw RangeError("validUntil can't be negative");var a=new Map;t.forEach(function(e,t){a.set(e.toLocaleLowerCase(),r[t])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return e.solidityPacked(["uint48","uint48","bytes"],[n,i,s])},i.sendUserOperation=function(e,t){try{var r=this,n=new S(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new w(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},r}(a);function I(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}L.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",L.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",L.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",L.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",L.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",L.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",L.initializerFunctionSelector="0xb63e800d",L.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],L.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=D.executeUserOpWithErrorString,L.executorFunctionInputAbi=["address","uint256","bytes","uint8"],L.EIP712_SAFE_OPERATION_TYPE={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"}]};var C=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this)||this).rpcUrl=void 0,r.entrypointAddress=void 0,r.supportedTokens=void 0,r.paymasterMetadata=void 0,r.rpcUrl=t,r}f(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(I(function(){return Promise.resolve(e.getSupportedEntrypoint()).then(function(t){return e.entrypointAddress=t,Promise.resolve(e.getSupportedERC20TokensAndPaymasterMetadata()).then(function(t){return e.supportedTokens=t.tokens,e.paymasterMetadata=t.paymasterMetadata,null})})},function(e){var t=v(e);throw new h("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}))}catch(e){return Promise.reject(e)}},r.getPaymasterMetaData=function(){try{var e=function(){return t.paymasterMetadata},t=this,r=function(){if(null==t.paymasterMetadata)return Promise.resolve(t.initialize()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokensAndPaymasterMetadata=function(){try{var e=this;return Promise.resolve(null==e.supportedTokens||null==e.paymasterMetadata?I(function(){return Promise.resolve(y(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens,paymasterMetadata:e.paymasterMetadata}})},function(e){var t=v(e);throw new h("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}):{tokens:e.supportedTokens,paymasterMetadata:e.paymasterMetadata})}catch(e){return Promise.reject(e)}},r.getSupportedEntrypoint=function(){try{var e=this;return Promise.resolve(null==e.entrypointAddress?I(function(){return Promise.resolve(y(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=v(e);throw new h("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}):e.entrypointAddress)}catch(e){return Promise.reject(e)}},r.isSupportedERC20Token=function(e){try{var t=function(){return!!r.supportedTokens.find(function(t){return t.address===e.toLowerCase()})},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokenData=function(e){try{var t=function(){var t=r.supportedTokens.find(function(t){return t.address.toLowerCase()===e.toLowerCase()});return t?{symbol:t.symbol,address:t.address,decimal:Number(t.decimal),fee:BigInt(t.fee),exchangeRate:BigInt(t.exchangeRate)}:null},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.createPaymasterUserOperation=function(e,t,r,n){void 0===r&&(r={});try{var i=function(){return I(function(){e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var i=new S(t);return Promise.resolve(i.estimateUserOperationGas(e,a.entrypointAddress,n)).then(function(t){return e.preVerificationGas=t.preVerificationGas+100n,e.verificationGasLimit=t.verificationGasLimit+10000n,e.callGasLimit=t.callGasLimit,Promise.resolve(y(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,f={paymasterAndData:s.paymasterAndData,callGasLimit:null==s.callGasLimit?void 0:BigInt(s.callGasLimit),preVerificationGas:null==s.preVerificationGas?void 0:BigInt(s.preVerificationGas),verificationGasLimit:null==s.verificationGasLimit?void 0:BigInt(s.verificationGasLimit),maxFeePerGas:null==s.maxFeePerGas?void 0:BigInt(s.maxFeePerGas),maxPriorityFeePerGas:null==s.maxPriorityFeePerGas?void 0:BigInt(s.maxPriorityFeePerGas)};return e.paymasterAndData=f.paymasterAndData,e.callGasLimit=null!=(r=f.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=f.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=f.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=f.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=f.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})})},function(e){var t=v(e);throw new h("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})})},a=this,o=function(){if(null==a.entrypointAddress||null==a.supportedTokens||null==a.paymasterMetadata)return Promise.resolve(a.initialize()).then(function(){})}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}},r.createSponsorPaymasterUserOperation=function(e,t,r){try{return Promise.resolve(this.createPaymasterUserOperation(e,t,{},r))}catch(e){return Promise.reject(e)}},r.createTokenPaymasterUserOperation=function(e,t,r,n,i){void 0===i&&(i={});try{var a=this;return Promise.resolve(I(function(){return Promise.resolve(a.calculateUserOperationErc20TokenMaxGasCost(t,r)).then(function(o){var s=2n*o;return Promise.resolve(a.getPaymasterMetaData()).then(function(o){var f=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=f,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=v(e);throw new h("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(I(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new h("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e)}})});var i=E(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=v(e);throw new h("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),M={__proto__:null,SmartAccount:a,SafeAccountV0_2_0:L,SendUseroperationResponse:w,SmartAccountFactory:G,SafeAccountFactory:R,Bundler:S,CandidePaymaster:C,createUserOperationHash:A,createCallData:P,getFunctionSelector:g,fetchAccountNonce:m,calculateUserOperationMaxGasCost:E,get Operation(){return exports.Operation}};exports.Bundler=S,exports.CandidePaymaster=C,exports.SafeAccountFactory=R,exports.SafeAccountV0_2_0=L,exports.SendUseroperationResponse=w,exports.SmartAccount=a,exports.SmartAccountFactory=G,exports.abstractionkit=M,exports.calculateUserOperationMaxGasCost=E,exports.createCallData=P,exports.createUserOperationHash=A,exports.fetchAccountNonce=m,exports.getFunctionSelector=g; |
@@ -1,1 +0,1 @@ | ||
import{keccak256 as e,AbiCoder as t,id as r,JsonRpcProvider as n,getBytes as i,solidityPacked as a,solidityPackedKeccak256 as o,Wallet as s,TypedDataEncoder as f}from"ethers";import*as c from"isomorphic-unfetch";var u,l,d=function(e){this.accountAddress=void 0,this.accountAddress=e};function p(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(p=function(){return!!e})()}function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},h.apply(this,arguments)}function v(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,y(e,t)}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function A(e){var t="function"==typeof Map?new Map:void 0;return A=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(p())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&y(i,r.prototype),i}(e,arguments,m(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)},A(e)}function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function g(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return P(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?P(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}d.proxyByteCode=void 0,d.initializerFunctionSelector=void 0,d.initializerFunctionInputAbi=void 0,d.executorFunctionSelector=void 0,d.executorFunctionInputAbi=void 0,function(e){e[e.Call=0]="Call",e[e.Delegate=1]="Delegate"}(u||(u={})),function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(l||(l={}));var E={"-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"},D=/*#__PURE__*/function(e){function t(t,r,n){var i;void 0===n&&(n={});var a=n.errno,o=n.context;return(i=e.call(this,r,{cause:n.cause})||this).code=void 0,i.context=void 0,i.errno=void 0,i.name=i.constructor.name,i.code=t,i.errno=a,i.context=o,i}return v(t,e),t}(/*#__PURE__*/A(Error));function b(e){if(e instanceof Error)return e;var t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error("This value was thrown as is, not through an Error: "+t)}var G=function(e,t,r,n){void 0===n&&(n=0);try{var i=[{from:"0x0000000000000000000000000000000000000000",to:t,data:_(S("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(R(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new D("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=b(e);throw new D("BAD_DATA","getNonce returned ill formed data",{cause:t})}})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=b(e);throw new D("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},R=function(e,t,r){try{var n=c.default||c,i={method:"POST",body:JSON.stringify({method:t,params:r,id:(new Date).getTime(),jsonrpc:"2.0"},function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t}),redirect:"follow"};return Promise.resolve(n(e,i)).then(function(t){return Promise.resolve(t.json()).then(function(t){if("result"in t)return t.result;var r=t.error,n=String(r.code);throw new D(n in E?E[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(i)}})})})}catch(e){return Promise.reject(e)}};function O(r,n,i){var a=e(function(r){var n=[r.sender,r.nonce,e(r.initCode),e(r.callData),r.callGasLimit,r.verificationGasLimit,r.preVerificationGas,r.maxFeePerGas,r.maxPriorityFeePerGas,e(r.paymasterAndData)];return t.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],n)}(r)),o=t.defaultAbiCoder().encode(["bytes32","address","uint256"],[a,n,i]);return e(o)}function _(e,r,n){return e+t.defaultAbiCoder().encode(r,n).slice(2)}function S(e){return r(e).slice(0,10)}function U(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var T,x="0x0000000000000000000000000000000000000000",F={sender:x,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0xffffffn,verificationGasLimit:0xffffffn,preVerificationGas:0xffffffn,maxFeePerGas:0xffffffn,maxPriorityFeePerGas:0xfffffffn,paymasterAndData:"0x",signature:"0x"},w=/*#__PURE__*/function(){function e(e,t,r){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=r}return e.prototype.getFactoryGeneratorFunctionCallData=function(e){var t=_(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)},e}(),L=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return v(t,e),t}(w);function I(e){return"0x"+e.map(function(e){return n=null!=(r=(t=e).operation)?r:u.Call,o=i(t.data),a(["uint8","address","uint256","uint256","bytes"],[n,t.to,t.value,o.length,o]).slice(2);var t,r,n,o}).join("")}function C(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(T||(T={}));var N=/*#__PURE__*/function(){function e(e){this.rpcUrl=void 0,this.rpcUrl=e}var t=e.prototype;return t.chainId=function(){try{var e=this;return Promise.resolve(C(function(){return Promise.resolve(R(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new D("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=b(e);throw new D("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.supportedEntryPoints=function(){try{var e=this;return Promise.resolve(C(function(){return Promise.resolve(R(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=b(e);throw new D("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.estimateUserOperationGas=function(e,t,r){try{var n=this;return Promise.resolve(C(function(){function i(){var e=a;return{callGasLimit:BigInt(e.callGasLimit),preVerificationGas:BigInt(e.preVerificationGas),verificationGasLimit:BigInt(e.verificationGasLimit)}}var a={},o=void 0===r?Promise.resolve(R(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(R(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=b(e);throw new D("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.sendUserOperation=function(e,t){try{var r=this;return Promise.resolve(C(function(){return Promise.resolve(R(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=b(e);throw new D("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.getUserOperationReceipt=function(e){try{var t=this;return Promise.resolve(C(function(){return Promise.resolve(R(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=h({},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 h({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:r})}return null})},function(t){var r=b(t);throw new D("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},t.getUserOperationByHash=function(e){try{var t=this;return Promise.resolve(C(function(){return Promise.resolve(R(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?h({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=b(t);throw new D("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},e}();function B(e,t,r){if(!e.s){if(r instanceof M){if(!r.s)return void(r.o=B.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(B.bind(null,e,t),B.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var M=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var a=1&i?t:r;if(a){try{B(n,1,a(this.v))}catch(e){B(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?B(n,1,t?t(i):i):r?B(n,1,r(i)):B(n,2,i)}catch(e){B(n,2,e)}},n},e}();function j(e){return e instanceof M&&1&e.s}var k=/*#__PURE__*/function(){function e(e,t,r){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=r}var t=e.prototype;return t.delay=function(e){return new Promise(function(t){return setTimeout(t,e)})},t.included=function(e,t){void 0===e&&(e=180),void 0===t&&(t=2);try{var r,n=function(e){if(r)return e;throw new D("TIMEOUT","can't find useroperation",{context:i.userOperationHash})},i=this;if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");var a=0,o=function(e,t,r){for(var n;;){var i=e();if(j(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!j(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!j(o)){n=2;break}}}var s=new M,f=B.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(c):o.then(l)).then(void 0,f),s;function c(n){a=n;do{if(t&&(o=t())&&o.then&&!j(o))return void o.then(l).then(void 0,f);if(!(i=e())||j(i)&&!i.v)return void B(s,1,a);if(i.then)return void i.then(u).then(void 0,f);j(a=r())&&(a=a.v)}while(!a||!a.then);a.then(c).then(void 0,f)}function u(e){e?(a=r())&&a.then?a.then(c).then(void 0,f):c(a):B(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,f):u(i):B(s,1,a)}}(function(){return!r&&a<=e},void 0,function(){return Promise.resolve(i.delay(1e3*t)).then(function(){return Promise.resolve(i.bundler.getUserOperationReceipt(i.userOperationHash)).then(function(e){if(null!=e)return r=1,e;a++})})});return Promise.resolve(o&&o.then?o.then(n):n(o))}catch(e){return Promise.reject(e)}},e}(),V=/*#__PURE__*/function(r){function i(e,t,n){var a;return void 0===t&&(t=i.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===n&&(n=i.DEFAULT_ENTRYPOINT_ADDRESS),(a=r.call(this,e)||this).entrypointAddress=void 0,a.safe4337ModuleAddress=void 0,a.initCode=void 0,a.entrypointAddress=n,a.safe4337ModuleAddress=t,a.initCode=null,a}v(i,r),i.initializeNewAccount=function(e,t){void 0===t&&(t={});var r=i.createAccountAddressAndInitCode(e,t),n=r[1],a=new i(r[0]);return a.initCode=n,a},i.createAccountAddressAndInitCode=function(e,t){var r,n,a,o,s;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one owner");var f=null!=(r=t.threshold)?r:1,c=null!=(n=t.c2Nonce)?n:0n,u=null!=(a=t.singletonAddress)?a:i.DEFAULT_SINGLETON_ADDRESS,l=null!=(o=t.safe4337ModuleAddress)?o:i.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:i.DEFAULT_ADD_MODULE_LIB_ADDRESS,p=new L;null!=t.safeAccountFactoryAddress&&(p=new L(t.safeAccountFactoryAddress));var h=i.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(h,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,h,c])]},i.createInitializerCallData=function(e,t,r,n){if(void 0===r&&(r=i.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===n&&(n=i.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");var a=_("0x8d0dc49f",["address[]"],[[r]]);return _(i.initializerFunctionSelector,i.initializerFunctionInputAbi,[e,t,n,a,r,x,0,x])},i.createInitCode=function(e,t,r,n,a,o,s){if(void 0===t&&(t=1),void 0===r&&(r=0n),void 0===n&&(n=i.DEFAULT_SINGLETON_ADDRESS),void 0===a&&(a=new L),void 0===o&&(o=i.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===s&&(s=i.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");if(r<0n)throw RangeError("c2Nonce can't be negative");var f=i.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([n,f,r])},i.createProxyAddress=function(r,n,i,s){if(n<0n)throw RangeError("c2Nonce can't be negative");var f=t.defaultAbiCoder(),c=e(a(["bytes32","uint256"],[e(r),n])),u=f.encode(["uint256"],[s]),l=e(a(["bytes","bytes"],[this.proxyByteCode,u]));return"0x"+o(["bytes1","address","bytes32","bytes32"],["0xff",i,c,l]).slice(-40)},i.createAccountCallDataSingleTransaction=function(e){var t,r,n,a=null!=(t=e.value)?t:0,o=null!=(r=e.data)?r:"0x",s=null!=(n=e.operation)?n:u.Call;return i.createAccountCallData(e.to,a,o,s)},i.createAccountCallDataBatchTransactions=function(e,t){if(void 0===t&&(t=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS),e.length<1)throw RangeError("There should be at least one metaTransaction");var r=_("0x8d80ff0a",["bytes"],[I(e)]);return i.createAccountCallData(t,0n,r,u.Delegate)},i.createAccountCallData=function(e,t,r,n,a){return void 0===a&&(a=i.DEFAULT_EXECUTOR_FUCNTION_SELECTOR),_(a,i.executorFunctionInputAbi,[e,t,r,n])};var c=i.prototype;return c.decodeAccountCallData=function(e){if(e.startsWith(T.executeUserOpWithErrorString)||e.startsWith(T.executeUserOp)){var r=t.defaultAbiCoder(),n="0x"+e.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);return[i[0],BigInt(i[1]),i[2],Number(i[3])]}throw new D("BAD_DATA","Invalid calldata, should start with "+T.executeUserOpWithErrorString+" or "+T.executeUserOp,{context:{callData:e}})},c.prependTokenPaymasterApproveToCallData=function(e,r,n,a,o){void 0===o&&(o=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=this.decodeAccountCallData(e),f=s[0],c=s[1],l=s[2],d=s[3],p="";p="string"!=typeof l?(new TextDecoder).decode(l):l;var h=I([{to:r,value:0n,data:_(S("approve(address,uint256)"),["address","uint256"],[n,a]),operation:u.Call}]),v="",m="0x8d80ff0a";if(p.startsWith(m)){var y=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);v=y+h.slice(2)}else v=I([{to:f,value:c,data:l,operation:d}])+h.slice(2);var A=_(m,["bytes"],[v]);return i.createAccountCallData(o,0n,A,u.Delegate)},c.estimateUserOperationGas=function(e,t,r,n){void 0===n&&(n=1);try{if(n<1n)throw RangeError("numberOfSigners can't be less than 1");for(var i="",a=0;a<n;a++)i+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+i;var o=new N(t);return Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(e){return[BigInt(e.preVerificationGas),BigInt(e.verificationGasLimit)+5000n*BigInt(n),BigInt(e.callGasLimit)]})}catch(e){return Promise.reject(e)}},c.createUserOperation=function(e,t,r,a){void 0===a&&(a={});try{var o=function(){var o;function c(){var e,t;function n(){var e,t,r;if("bigint"==typeof a.preVerificationGas&&a.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof a.verificationGasLimit&&a.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof a.callGasLimit&&a.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return i.preVerificationGas=null!=(e=a.preVerificationGas)?e:o,i.verificationGasLimit=null!=(t=a.verificationGasLimit)?t:c,i.callGasLimit=null!=(r=a.callGasLimit)?r:l,i}if("bigint"==typeof a.maxFeePerGas&&a.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof a.maxPriorityFeePerGas&&a.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");p=null!=(e=a.maxFeePerGas)?e:p,v=null!=(t=a.maxPriorityFeePerGas)?t:v;var i=h({},F,{sender:s.accountAddress,nonce:f,initCode:u,callData:d,maxFeePerGas:p,maxPriorityFeePerGas:v}),o=F.preVerificationGas,c=F.verificationGasLimit,l=F.callGasLimit,m=function(){if(null==a.preVerificationGas||null==a.verificationGasLimit||null==a.callGasLimit)return Promise.resolve(s.estimateUserOperationGas(i,r,a.state_override_set,a.numberOfSigners)).then(function(e){o=e[0],c=e[1],l=e[2]})}();return m&&m.then?m.then(n):n()}var u=null!=(o=a.initCode)?o:s.initCode;if((null==u||f>0n)&&(u="0x"),f<0n)throw RangeError("nonce can't be negative");var d="0x";d=null==a.callData?1==e.length?i.createAccountCallDataSingleTransaction(e[0]):i.createAccountCallDataBatchTransactions(e):a.callData;var p=F.maxFeePerGas,v=F.maxPriorityFeePerGas,m=function(){if(null==a.maxFeePerGas||null==a.maxPriorityFeePerGas)return Promise.resolve(function(e,t){try{void 0===t&&(t=l.Medium);var r=new n(e);return Promise.resolve(r.getFeeData()).then(function(e){return[BigInt(Math.ceil(Number(e.maxFeePerGas)*t)),BigInt(Math.ceil(Number(e.maxPriorityFeePerGas)*t))]})}catch(e){return Promise.reject(e)}}(t)).then(function(e){p=e[0],v=e[1]})}();return m&&m.then?m.then(c):c()},s=this;if(e.length<1)throw RangeError("There should be at least one transaction");var f=0n,c=function(){if(null==a.nonce)return Promise.resolve(G(t,s.entrypointAddress,s.accountAddress)).then(function(e){f=e});f=a.nonce}();return Promise.resolve(c&&c.then?c.then(o):o())}catch(e){return Promise.reject(e)}},c.signUserOperation=function(e,t,r,n,a){if(void 0===n&&(n=0n),void 0===a&&(a=0n),t.length<1)throw RangeError("There should be at least one privateKey");if(r<0n)throw RangeError("chainId can't be negative");if(n<0n)throw RangeError("validAfter can't be negative");if(a<0n)throw RangeError("validUntil can't be negative");for(var o,c={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:n,validUntil:a,entryPoint:this.entrypointAddress},u={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"}]},l=new Map,d=g(t);!(o=d()).done;){var p=new s(o.value);l.set(p.address,p)}for(var h,v=[],m=g(Array.from(l.keys()).sort());!(h=m()).done;){var y=l.get(h.value).signingKey.sign(f.hash({chainId:r,verifyingContract:this.safe4337ModuleAddress},u,c)).serialized;v.push(y.slice(2))}return i.formatEip712SignaturesToUseroperationSignature(v,n,a)},i.formatEip712SignaturesToUseroperationSignature=function(e,t,r){void 0===t&&(t=0n),void 0===r&&(r=0n);var n="0x"+e.join("");return a(["uint48","uint48","bytes"],[t,r,n])},c.sendUserOperation=function(e,t){try{var r=this,n=new N(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new k(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},i}(d);function z(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}V.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",V.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",V.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",V.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",V.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",V.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",V.initializerFunctionSelector="0xb63e800d",V.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],V.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=T.executeUserOpWithErrorString,V.executorFunctionInputAbi=["address","uint256","bytes","uint8"];var H=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this)||this).rpcUrl=void 0,r.entrypointAddress=void 0,r.supportedTokens=void 0,r.paymasterMetadata=void 0,r.rpcUrl=t,r}v(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(z(function(){return Promise.resolve(e.getSupportedEntrypoint()).then(function(t){return e.entrypointAddress=t,Promise.resolve(e.getSupportedERC20TokensAndPaymasterMetadata()).then(function(t){return e.supportedTokens=t.tokens,e.paymasterMetadata=t.paymasterMetadata,null})})},function(e){var t=b(e);throw new D("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}))}catch(e){return Promise.reject(e)}},r.getPaymasterMetaData=function(){try{var e=function(){return t.paymasterMetadata},t=this,r=function(){if(null==t.paymasterMetadata)return Promise.resolve(t.initialize()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokensAndPaymasterMetadata=function(){try{var e=this;return Promise.resolve(null==e.supportedTokens||null==e.paymasterMetadata?z(function(){return Promise.resolve(R(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens,paymasterMetadata:e.paymasterMetadata}})},function(e){var t=b(e);throw new D("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}):{tokens:e.supportedTokens,paymasterMetadata:e.paymasterMetadata})}catch(e){return Promise.reject(e)}},r.getSupportedEntrypoint=function(){try{var e=this;return Promise.resolve(null==e.entrypointAddress?z(function(){return Promise.resolve(R(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=b(e);throw new D("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}):e.entrypointAddress)}catch(e){return Promise.reject(e)}},r.isSupportedERC20Token=function(e){try{var t=function(){return!!r.supportedTokens.find(function(t){return t.address===e.toLowerCase()})},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokenData=function(e){try{var t=function(){var t=r.supportedTokens.find(function(t){return t.address.toLowerCase()===e.toLowerCase()});return t?{symbol:t.symbol,address:t.address,decimal:Number(t.decimal),fee:BigInt(t.fee),exchangeRate:BigInt(t.exchangeRate)}:null},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.createPaymasterUserOperation=function(e,t,r,n){void 0===r&&(r={});try{var i=function(){return z(function(){e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var i=new N(t);return Promise.resolve(i.estimateUserOperationGas(e,a.entrypointAddress,n)).then(function(t){return e.preVerificationGas=t.preVerificationGas,e.verificationGasLimit=t.verificationGasLimit+10000n,e.callGasLimit=t.callGasLimit,Promise.resolve(R(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,f={paymasterAndData:s.paymasterAndData,callGasLimit:null==s.callGasLimit?void 0:BigInt(s.callGasLimit),preVerificationGas:null==s.preVerificationGas?void 0:BigInt(s.preVerificationGas),verificationGasLimit:null==s.verificationGasLimit?void 0:BigInt(s.verificationGasLimit),maxFeePerGas:null==s.maxFeePerGas?void 0:BigInt(s.maxFeePerGas),maxPriorityFeePerGas:null==s.maxPriorityFeePerGas?void 0:BigInt(s.maxPriorityFeePerGas)};return e.paymasterAndData=f.paymasterAndData,e.callGasLimit=null!=(r=f.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=f.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=f.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=f.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=f.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})})},function(e){var t=b(e);throw new D("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})})},a=this,o=function(){if(null==a.entrypointAddress||null==a.supportedTokens||null==a.paymasterMetadata)return Promise.resolve(a.initialize()).then(function(){})}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}},r.createSponsorPaymasterUserOperation=function(e,t,r){try{return Promise.resolve(this.createPaymasterUserOperation(e,t,{},r))}catch(e){return Promise.reject(e)}},r.createTokenPaymasterUserOperation=function(e,t,r,n,i){void 0===i&&(i={});try{var a=this;return Promise.resolve(z(function(){return Promise.resolve(a.calculateUserOperationErc20TokenMaxGasCost(t,r)).then(function(o){var s=2n*o;return Promise.resolve(a.getPaymasterMetaData()).then(function(o){var f=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=f,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=b(e);throw new D("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(z(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new D("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e)}})});var i=U(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=b(e);throw new D("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),Y={__proto__:null,SmartAccount:d,SafeAccountV0_2_0:V,SendUseroperationResponse:k,SmartAccountFactory:w,SafeAccountFactory:L,Bundler:N,CandidePaymaster:H,createUserOperationHash:O,createCallData:_,getFunctionSelector:S,fetchAccountNonce:G,calculateUserOperationMaxGasCost:U,get Operation(){return u}};export{N as Bundler,H as CandidePaymaster,u as Operation,L as SafeAccountFactory,V as SafeAccountV0_2_0,k as SendUseroperationResponse,d as SmartAccount,w as SmartAccountFactory,Y as abstractionkit,U as calculateUserOperationMaxGasCost,_ as createCallData,O as createUserOperationHash,G as fetchAccountNonce,S as getFunctionSelector}; | ||
import{keccak256 as e,AbiCoder as t,id as r,JsonRpcProvider as n,getBytes as i,solidityPacked as a,solidityPackedKeccak256 as o,Wallet as s,TypedDataEncoder as f}from"ethers";import*as c from"isomorphic-unfetch";var u,l,d=function(e){this.accountAddress=void 0,this.accountAddress=e};function p(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(p=function(){return!!e})()}function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},h.apply(this,arguments)}function v(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,y(e,t)}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function A(e){var t="function"==typeof Map?new Map:void 0;return A=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(p())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&y(i,r.prototype),i}(e,arguments,m(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)},A(e)}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}d.proxyByteCode=void 0,d.initializerFunctionSelector=void 0,d.initializerFunctionInputAbi=void 0,d.executorFunctionSelector=void 0,d.executorFunctionInputAbi=void 0,function(e){e[e.Call=0]="Call",e[e.Delegate=1]="Delegate"}(u||(u={})),function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(l||(l={}));var P={"-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"},E=/*#__PURE__*/function(e){function t(t,r,n){var i;void 0===n&&(n={});var a=n.errno,o=n.context;return(i=e.call(this,r,{cause:n.cause})||this).code=void 0,i.context=void 0,i.errno=void 0,i.name=i.constructor.name,i.code=t,i.errno=a,i.context=o,i}return v(t,e),t}(/*#__PURE__*/A(Error));function D(e){if(e instanceof Error)return e;var t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error("This value was thrown as is, not through an Error: "+t)}var b=function(e,t,r,n){void 0===n&&(n=0);try{var i=[{from:"0x0000000000000000000000000000000000000000",to:t,data:O(_("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(G(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new E("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=D(e);throw new E("BAD_DATA","getNonce returned ill formed data",{cause:t})}})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=D(e);throw new E("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},G=function(e,t,r){try{var n=c.default||c,i={method:"POST",body:JSON.stringify({method:t,params:r,id:(new Date).getTime(),jsonrpc:"2.0"},function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t}),redirect:"follow"};return Promise.resolve(n(e,i)).then(function(t){return Promise.resolve(t.json()).then(function(t){if("result"in t)return t.result;var r=t.error,n=String(r.code);throw new E(n in P?P[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(i)}})})})}catch(e){return Promise.reject(e)}};function R(r,n,i){var a=e(function(r){var n=[r.sender,r.nonce,e(r.initCode),e(r.callData),r.callGasLimit,r.verificationGasLimit,r.preVerificationGas,r.maxFeePerGas,r.maxPriorityFeePerGas,e(r.paymasterAndData)];return t.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],n)}(r)),o=t.defaultAbiCoder().encode(["bytes32","address","uint256"],[a,n,i]);return e(o)}function O(e,r,n){return e+t.defaultAbiCoder().encode(r,n).slice(2)}function _(e){return r(e).slice(0,10)}function S(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var T,U="0x0000000000000000000000000000000000000000",x={sender:U,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0xffffffn,verificationGasLimit:0xffffffn,preVerificationGas:0xffffffn,maxFeePerGas:0xffffffn,maxPriorityFeePerGas:0xfffffffn,paymasterAndData:"0x",signature:"0x"},F=/*#__PURE__*/function(){function e(e,t,r){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=r}return e.prototype.getFactoryGeneratorFunctionCallData=function(e){var t=O(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)},e}(),w=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return v(t,e),t}(F);function L(e){return"0x"+e.map(function(e){return n=null!=(r=(t=e).operation)?r:u.Call,o=i(t.data),a(["uint8","address","uint256","uint256","bytes"],[n,t.to,t.value,o.length,o]).slice(2);var t,r,n,o}).join("")}function I(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(T||(T={}));var C=/*#__PURE__*/function(){function e(e){this.rpcUrl=void 0,this.rpcUrl=e}var t=e.prototype;return t.chainId=function(){try{var e=this;return Promise.resolve(I(function(){return Promise.resolve(G(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new E("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=D(e);throw new E("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.supportedEntryPoints=function(){try{var e=this;return Promise.resolve(I(function(){return Promise.resolve(G(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=D(e);throw new E("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.estimateUserOperationGas=function(e,t,r){try{var n=this;return Promise.resolve(I(function(){function i(){var e=a;return{callGasLimit:BigInt(e.callGasLimit),preVerificationGas:BigInt(e.preVerificationGas),verificationGasLimit:BigInt(e.verificationGasLimit)}}var a={},o=void 0===r?Promise.resolve(G(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(G(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=D(e);throw new E("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.sendUserOperation=function(e,t){try{var r=this;return Promise.resolve(I(function(){return Promise.resolve(G(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=D(e);throw new E("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.getUserOperationReceipt=function(e){try{var t=this;return Promise.resolve(I(function(){return Promise.resolve(G(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=h({},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 h({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:r})}return null})},function(t){var r=D(t);throw new E("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},t.getUserOperationByHash=function(e){try{var t=this;return Promise.resolve(I(function(){return Promise.resolve(G(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?h({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=D(t);throw new E("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},e}();function M(e,t,r){if(!e.s){if(r instanceof B){if(!r.s)return void(r.o=M.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(M.bind(null,e,t),M.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var B=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var a=1&i?t:r;if(a){try{M(n,1,a(this.v))}catch(e){M(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?M(n,1,t?t(i):i):r?M(n,1,r(i)):M(n,2,i)}catch(e){M(n,2,e)}},n},e}();function N(e){return e instanceof B&&1&e.s}var j=/*#__PURE__*/function(){function e(e,t,r){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=r}var t=e.prototype;return t.delay=function(e){return new Promise(function(t){return setTimeout(t,e)})},t.included=function(e,t){void 0===e&&(e=180),void 0===t&&(t=2);try{var r,n=function(e){if(r)return e;throw new E("TIMEOUT","can't find useroperation",{context:i.userOperationHash})},i=this;if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");var a=0,o=function(e,t,r){for(var n;;){var i=e();if(N(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!N(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!N(o)){n=2;break}}}var s=new B,f=M.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(c):o.then(l)).then(void 0,f),s;function c(n){a=n;do{if(t&&(o=t())&&o.then&&!N(o))return void o.then(l).then(void 0,f);if(!(i=e())||N(i)&&!i.v)return void M(s,1,a);if(i.then)return void i.then(u).then(void 0,f);N(a=r())&&(a=a.v)}while(!a||!a.then);a.then(c).then(void 0,f)}function u(e){e?(a=r())&&a.then?a.then(c).then(void 0,f):c(a):M(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,f):u(i):M(s,1,a)}}(function(){return!r&&a<=e},void 0,function(){return Promise.resolve(i.delay(1e3*t)).then(function(){return Promise.resolve(i.bundler.getUserOperationReceipt(i.userOperationHash)).then(function(e){if(null!=e)return r=1,e;a++})})});return Promise.resolve(o&&o.then?o.then(n):n(o))}catch(e){return Promise.reject(e)}},e}(),k=/*#__PURE__*/function(r){function i(e,t,n){var a;return void 0===t&&(t=i.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===n&&(n=i.DEFAULT_ENTRYPOINT_ADDRESS),(a=r.call(this,e)||this).entrypointAddress=void 0,a.safe4337ModuleAddress=void 0,a.initCode=void 0,a.entrypointAddress=n,a.safe4337ModuleAddress=t,a.initCode=null,a}v(i,r),i.initializeNewAccount=function(e,t){void 0===t&&(t={});var r=i.createAccountAddressAndInitCode(e,t),n=r[1],a=new i(r[0]);return a.initCode=n,a},i.createAccountAddressAndInitCode=function(e,t){var r,n,a,o,s;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one owner");var f=null!=(r=t.threshold)?r:1,c=null!=(n=t.c2Nonce)?n:0n,u=null!=(a=t.singletonAddress)?a:i.DEFAULT_SINGLETON_ADDRESS,l=null!=(o=t.safe4337ModuleAddress)?o:i.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:i.DEFAULT_ADD_MODULE_LIB_ADDRESS,p=new w;null!=t.safeAccountFactoryAddress&&(p=new w(t.safeAccountFactoryAddress));var h=i.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(h,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,h,c])]},i.createInitializerCallData=function(e,t,r,n){if(void 0===r&&(r=i.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===n&&(n=i.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");var a=O("0x8d0dc49f",["address[]"],[[r]]);return O(i.initializerFunctionSelector,i.initializerFunctionInputAbi,[e,t,n,a,r,U,0,U])},i.createInitCode=function(e,t,r,n,a,o,s){if(void 0===t&&(t=1),void 0===r&&(r=0n),void 0===n&&(n=i.DEFAULT_SINGLETON_ADDRESS),void 0===a&&(a=new w),void 0===o&&(o=i.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===s&&(s=i.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");if(r<0n)throw RangeError("c2Nonce can't be negative");var f=i.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([n,f,r])},i.createProxyAddress=function(r,n,i,s){if(n<0n)throw RangeError("c2Nonce can't be negative");var f=t.defaultAbiCoder(),c=e(a(["bytes32","uint256"],[e(r),n])),u=f.encode(["uint256"],[s]),l=e(a(["bytes","bytes"],[this.proxyByteCode,u]));return"0x"+o(["bytes1","address","bytes32","bytes32"],["0xff",i,c,l]).slice(-40)},i.createAccountCallDataSingleTransaction=function(e){var t,r,n,a=null!=(t=e.value)?t:0,o=null!=(r=e.data)?r:"0x",s=null!=(n=e.operation)?n:u.Call;return i.createAccountCallData(e.to,a,o,s)},i.createAccountCallDataBatchTransactions=function(e,t){if(void 0===t&&(t=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS),e.length<1)throw RangeError("There should be at least one metaTransaction");var r=O("0x8d80ff0a",["bytes"],[L(e)]);return i.createAccountCallData(t,0n,r,u.Delegate)},i.createAccountCallData=function(e,t,r,n,a){return void 0===a&&(a=i.DEFAULT_EXECUTOR_FUCNTION_SELECTOR),O(a,i.executorFunctionInputAbi,[e,t,r,n])};var c=i.prototype;return c.decodeAccountCallData=function(e){if(e.startsWith(T.executeUserOpWithErrorString)||e.startsWith(T.executeUserOp)){var r=t.defaultAbiCoder(),n="0x"+e.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);return[i[0],BigInt(i[1]),i[2],Number(i[3])]}throw new E("BAD_DATA","Invalid calldata, should start with "+T.executeUserOpWithErrorString+" or "+T.executeUserOp,{context:{callData:e}})},c.prependTokenPaymasterApproveToCallData=function(e,r,n,a,o){void 0===o&&(o=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=this.decodeAccountCallData(e),f=s[0],c=s[1],l=s[2],d=s[3],p="";p="string"!=typeof l?(new TextDecoder).decode(l):l;var h=L([{to:r,value:0n,data:O(_("approve(address,uint256)"),["address","uint256"],[n,a]),operation:u.Call}]),v="",m="0x8d80ff0a";if(p.startsWith(m)){var y=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);v=y+h.slice(2)}else v=L([{to:f,value:c,data:l,operation:d}])+h.slice(2);var A=O(m,["bytes"],[v]);return i.createAccountCallData(o,0n,A,u.Delegate)},c.estimateUserOperationGas=function(e,t,r,n){void 0===n&&(n=1);try{if(n<1n)throw RangeError("numberOfSigners can't be less than 1");for(var i="",a=0;a<n;a++)i+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+i;var o=new C(t);return Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(e){return[BigInt(e.preVerificationGas),BigInt(e.verificationGasLimit)+5000n*BigInt(n),BigInt(e.callGasLimit)]})}catch(e){return Promise.reject(e)}},c.createUserOperation=function(e,t,r,a){void 0===a&&(a={});try{var o=function(){var o;function c(){var e,t,n,i;function o(){var e,t,r,n,i,o;if("bigint"==typeof a.preVerificationGas&&a.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof a.verificationGasLimit&&a.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof a.callGasLimit&&a.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return c.preVerificationGas=null!=(e=a.preVerificationGas)?e:l*BigInt(Math.floor(((null!=(t=a.preVerificationGasPercentageMultiplier)?t:0)+100)/100)),c.verificationGasLimit=null!=(r=a.verificationGasLimit)?r:m*BigInt(Math.floor(((null!=(n=a.verificationGasLimitPercentageMultiplier)?n:0)+100)/100)),c.callGasLimit=null!=(i=a.callGasLimit)?i:y*BigInt(Math.floor(((null!=(o=a.callGasLimitPercentageMultiplier)?o:0)+100)/100)),c}if("bigint"==typeof a.maxFeePerGas&&a.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof a.maxPriorityFeePerGas&&a.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");p=null!=(e=a.maxFeePerGas)?e:p*BigInt(Math.floor(((null!=(t=a.maxFeePerGasPercentageMultiplier)?t:0)+100)/100)),v=null!=(n=a.maxPriorityFeePerGas)?n:v*BigInt(Math.floor(((null!=(i=a.maxPriorityFeePerGasPercentageMultiplier)?i:0)+100)/100));var c=h({},x,{sender:s.accountAddress,nonce:f,initCode:u,callData:d,maxFeePerGas:p,maxPriorityFeePerGas:v}),l=x.preVerificationGas,m=x.verificationGasLimit,y=x.callGasLimit,A=function(){if(null==a.preVerificationGas||null==a.verificationGasLimit||null==a.callGasLimit)return Promise.resolve(s.estimateUserOperationGas(c,r,a.state_override_set,a.numberOfSigners)).then(function(e){l=e[0],m=e[1],y=e[2]})}();return A&&A.then?A.then(o):o()}var u=null!=(o=a.initCode)?o:s.initCode;if((null==u||f>0n)&&(u="0x"),f<0n)throw RangeError("nonce can't be negative");var d="0x";d=null==a.callData?1==e.length?i.createAccountCallDataSingleTransaction(e[0]):i.createAccountCallDataBatchTransactions(e):a.callData;var p=x.maxFeePerGas,v=x.maxPriorityFeePerGas,m=function(){if(null==a.maxFeePerGas||null==a.maxPriorityFeePerGas)return Promise.resolve(function(e,t){try{void 0===t&&(t=l.Medium);var r=new n(e);return Promise.resolve(r.getFeeData()).then(function(e){return[BigInt(Math.ceil(Number(e.maxFeePerGas)*t)),BigInt(Math.ceil(Number(e.maxPriorityFeePerGas)*t))]})}catch(e){return Promise.reject(e)}}(t)).then(function(e){p=e[0],v=e[1]})}();return m&&m.then?m.then(c):c()},s=this;if(e.length<1)throw RangeError("There should be at least one transaction");var f=0n,c=function(){if(null==a.nonce)return Promise.resolve(b(t,s.entrypointAddress,s.accountAddress)).then(function(e){f=e});f=a.nonce}();return Promise.resolve(c&&c.then?c.then(o):o())}catch(e){return Promise.reject(e)}},c.signUserOperation=function(e,t,r,n,a){if(void 0===n&&(n=0n),void 0===a&&(a=0n),t.length<1)throw RangeError("There should be at least one privateKey");if(r<0n)throw RangeError("chainId can't be negative");if(n<0n)throw RangeError("validAfter can't be negative");if(a<0n)throw RangeError("validUntil can't be negative");for(var o,c={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:n,validUntil:a,entryPoint:this.entrypointAddress},u=[],l=[],d=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return g(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t);!(o=d()).done;){var p=new s(o.value),h=p.signingKey.sign(f.hash({chainId:r,verifyingContract:this.safe4337ModuleAddress},i.EIP712_SAFE_OPERATION_TYPE,c)).serialized;u.push(p.address),l.push(h)}return i.formatEip712SignaturesToUseroperationSignature(u,l,n,a)},i.formatEip712SignaturesToUseroperationSignature=function(e,t,r,n){if(void 0===r&&(r=0n),void 0===n&&(n=0n),e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");if(r<0n)throw RangeError("validAfter can't be negative");if(n<0n)throw RangeError("validUntil can't be negative");var i=new Map;e.forEach(function(e,r){i.set(e.toLocaleLowerCase(),t[r])});var o=new Map(Array.from(i).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return a(["uint48","uint48","bytes"],[r,n,s])},c.sendUserOperation=function(e,t){try{var r=this,n=new C(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new j(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},i}(d);function V(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}k.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",k.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",k.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",k.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",k.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",k.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",k.initializerFunctionSelector="0xb63e800d",k.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],k.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=T.executeUserOpWithErrorString,k.executorFunctionInputAbi=["address","uint256","bytes","uint8"],k.EIP712_SAFE_OPERATION_TYPE={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"}]};var z=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this)||this).rpcUrl=void 0,r.entrypointAddress=void 0,r.supportedTokens=void 0,r.paymasterMetadata=void 0,r.rpcUrl=t,r}v(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(V(function(){return Promise.resolve(e.getSupportedEntrypoint()).then(function(t){return e.entrypointAddress=t,Promise.resolve(e.getSupportedERC20TokensAndPaymasterMetadata()).then(function(t){return e.supportedTokens=t.tokens,e.paymasterMetadata=t.paymasterMetadata,null})})},function(e){var t=D(e);throw new E("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}))}catch(e){return Promise.reject(e)}},r.getPaymasterMetaData=function(){try{var e=function(){return t.paymasterMetadata},t=this,r=function(){if(null==t.paymasterMetadata)return Promise.resolve(t.initialize()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokensAndPaymasterMetadata=function(){try{var e=this;return Promise.resolve(null==e.supportedTokens||null==e.paymasterMetadata?V(function(){return Promise.resolve(G(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens,paymasterMetadata:e.paymasterMetadata}})},function(e){var t=D(e);throw new E("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}):{tokens:e.supportedTokens,paymasterMetadata:e.paymasterMetadata})}catch(e){return Promise.reject(e)}},r.getSupportedEntrypoint=function(){try{var e=this;return Promise.resolve(null==e.entrypointAddress?V(function(){return Promise.resolve(G(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=D(e);throw new E("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}):e.entrypointAddress)}catch(e){return Promise.reject(e)}},r.isSupportedERC20Token=function(e){try{var t=function(){return!!r.supportedTokens.find(function(t){return t.address===e.toLowerCase()})},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokenData=function(e){try{var t=function(){var t=r.supportedTokens.find(function(t){return t.address.toLowerCase()===e.toLowerCase()});return t?{symbol:t.symbol,address:t.address,decimal:Number(t.decimal),fee:BigInt(t.fee),exchangeRate:BigInt(t.exchangeRate)}:null},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.createPaymasterUserOperation=function(e,t,r,n){void 0===r&&(r={});try{var i=function(){return V(function(){e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var i=new C(t);return Promise.resolve(i.estimateUserOperationGas(e,a.entrypointAddress,n)).then(function(t){return e.preVerificationGas=t.preVerificationGas+100n,e.verificationGasLimit=t.verificationGasLimit+10000n,e.callGasLimit=t.callGasLimit,Promise.resolve(G(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,f={paymasterAndData:s.paymasterAndData,callGasLimit:null==s.callGasLimit?void 0:BigInt(s.callGasLimit),preVerificationGas:null==s.preVerificationGas?void 0:BigInt(s.preVerificationGas),verificationGasLimit:null==s.verificationGasLimit?void 0:BigInt(s.verificationGasLimit),maxFeePerGas:null==s.maxFeePerGas?void 0:BigInt(s.maxFeePerGas),maxPriorityFeePerGas:null==s.maxPriorityFeePerGas?void 0:BigInt(s.maxPriorityFeePerGas)};return e.paymasterAndData=f.paymasterAndData,e.callGasLimit=null!=(r=f.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=f.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=f.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=f.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=f.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})})},function(e){var t=D(e);throw new E("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})})},a=this,o=function(){if(null==a.entrypointAddress||null==a.supportedTokens||null==a.paymasterMetadata)return Promise.resolve(a.initialize()).then(function(){})}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}},r.createSponsorPaymasterUserOperation=function(e,t,r){try{return Promise.resolve(this.createPaymasterUserOperation(e,t,{},r))}catch(e){return Promise.reject(e)}},r.createTokenPaymasterUserOperation=function(e,t,r,n,i){void 0===i&&(i={});try{var a=this;return Promise.resolve(V(function(){return Promise.resolve(a.calculateUserOperationErc20TokenMaxGasCost(t,r)).then(function(o){var s=2n*o;return Promise.resolve(a.getPaymasterMetaData()).then(function(o){var f=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=f,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=D(e);throw new E("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(V(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new E("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e)}})});var i=S(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=D(e);throw new E("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),Y={__proto__:null,SmartAccount:d,SafeAccountV0_2_0:k,SendUseroperationResponse:j,SmartAccountFactory:F,SafeAccountFactory:w,Bundler:C,CandidePaymaster:z,createUserOperationHash:R,createCallData:O,getFunctionSelector:_,fetchAccountNonce:b,calculateUserOperationMaxGasCost:S,get Operation(){return u}};export{C as Bundler,z as CandidePaymaster,u as Operation,w as SafeAccountFactory,k as SafeAccountV0_2_0,j as SendUseroperationResponse,d as SmartAccount,F as SmartAccountFactory,Y as abstractionkit,S as calculateUserOperationMaxGasCost,O as createCallData,R as createUserOperationHash,b as fetchAccountNonce,_ as getFunctionSelector}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ethers"),require("isomorphic-unfetch")):"function"==typeof define&&define.amd?define(["exports","ethers","isomorphic-unfetch"],t):t((e||self).abstractionkit={},e.ethers,e.isomorphicUnfetch)}(this,function(e,t,r){function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var i,a,o=/*#__PURE__*/n(r),s=function(e){this.accountAddress=void 0,this.accountAddress=e};function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(f=function(){return!!e})()}function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c.apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function p(e){var t="function"==typeof Map?new Map:void 0;return p=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(f())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&d(i,r.prototype),i}(e,arguments,l(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},p(e)}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function v(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return h(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}s.proxyByteCode=void 0,s.initializerFunctionSelector=void 0,s.initializerFunctionInputAbi=void 0,s.executorFunctionSelector=void 0,s.executorFunctionInputAbi=void 0,e.Operation=void 0,(i=e.Operation||(e.Operation={}))[i.Call=0]="Call",i[i.Delegate=1]="Delegate",function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(a||(a={}));var m={"-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"},y=/*#__PURE__*/function(e){function t(t,r,n){var i;void 0===n&&(n={});var a=n.errno,o=n.context;return(i=e.call(this,r,{cause:n.cause})||this).code=void 0,i.context=void 0,i.errno=void 0,i.name=i.constructor.name,i.code=t,i.errno=a,i.context=o,i}return u(t,e),t}(/*#__PURE__*/p(Error));function A(e){if(e instanceof Error)return e;var t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error("This value was thrown as is, not through an Error: "+t)}var P=function(e,t,r,n){void 0===n&&(n=0);try{var i=[{from:"0x0000000000000000000000000000000000000000",to:t,data:b(D("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(g(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new y("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=A(e);throw new y("BAD_DATA","getNonce returned ill formed data",{cause:t})}})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=A(e);throw new y("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},g=function(e,t,r){try{var n=o.default||o,i={method:"POST",body:JSON.stringify({method:t,params:r,id:(new Date).getTime(),jsonrpc:"2.0"},function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t}),redirect:"follow"};return Promise.resolve(n(e,i)).then(function(t){return Promise.resolve(t.json()).then(function(t){if("result"in t)return t.result;var r=t.error,n=String(r.code);throw new y(n in m?m[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(i)}})})})}catch(e){return Promise.reject(e)}};function E(e,r,n){var i=t.keccak256(function(e){var r=[e.sender,e.nonce,t.keccak256(e.initCode),t.keccak256(e.callData),e.callGasLimit,e.verificationGasLimit,e.preVerificationGas,e.maxFeePerGas,e.maxPriorityFeePerGas,t.keccak256(e.paymasterAndData)];return t.AbiCoder.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],r)}(e)),a=t.AbiCoder.defaultAbiCoder().encode(["bytes32","address","uint256"],[i,r,n]);return t.keccak256(a)}function b(e,r,n){return e+t.AbiCoder.defaultAbiCoder().encode(r,n).slice(2)}function D(e){return t.id(e).slice(0,10)}function O(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var G,R="0x0000000000000000000000000000000000000000",S={sender:R,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0xffffffn,verificationGasLimit:0xffffffn,preVerificationGas:0xffffffn,maxFeePerGas:0xffffffn,maxPriorityFeePerGas:0xfffffffn,paymasterAndData:"0x",signature:"0x"},_=/*#__PURE__*/function(){function e(e,t,r){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=r}return e.prototype.getFactoryGeneratorFunctionCallData=function(e){var t=b(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)},e}(),U=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return u(t,e),t}(_);function T(r){return"0x"+r.map(function(r){return a=null!=(i=(n=r).operation)?i:e.Operation.Call,o=t.getBytes(n.data),t.solidityPacked(["uint8","address","uint256","uint256","bytes"],[a,n.to,n.value,o.length,o]).slice(2);var n,i,a,o}).join("")}function x(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(G||(G={}));var F=/*#__PURE__*/function(){function e(e){this.rpcUrl=void 0,this.rpcUrl=e}var t=e.prototype;return t.chainId=function(){try{var e=this;return Promise.resolve(x(function(){return Promise.resolve(g(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new y("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=A(e);throw new y("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.supportedEntryPoints=function(){try{var e=this;return Promise.resolve(x(function(){return Promise.resolve(g(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=A(e);throw new y("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.estimateUserOperationGas=function(e,t,r){try{var n=this;return Promise.resolve(x(function(){function i(){var e=a;return{callGasLimit:BigInt(e.callGasLimit),preVerificationGas:BigInt(e.preVerificationGas),verificationGasLimit:BigInt(e.verificationGasLimit)}}var a={},o=void 0===r?Promise.resolve(g(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(g(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=A(e);throw new y("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.sendUserOperation=function(e,t){try{var r=this;return Promise.resolve(x(function(){return Promise.resolve(g(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=A(e);throw new y("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.getUserOperationReceipt=function(e){try{var t=this;return Promise.resolve(x(function(){return Promise.resolve(g(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=c({},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 c({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:r})}return null})},function(t){var r=A(t);throw new y("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},t.getUserOperationByHash=function(e){try{var t=this;return Promise.resolve(x(function(){return Promise.resolve(g(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?c({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=A(t);throw new y("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},e}();function w(e,t,r){if(!e.s){if(r instanceof L){if(!r.s)return void(r.o=w.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(w.bind(null,e,t),w.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var L=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var a=1&i?t:r;if(a){try{w(n,1,a(this.v))}catch(e){w(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?w(n,1,t?t(i):i):r?w(n,1,r(i)):w(n,2,i)}catch(e){w(n,2,e)}},n},e}();function C(e){return e instanceof L&&1&e.s}var I=/*#__PURE__*/function(){function e(e,t,r){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=r}var t=e.prototype;return t.delay=function(e){return new Promise(function(t){return setTimeout(t,e)})},t.included=function(e,t){void 0===e&&(e=180),void 0===t&&(t=2);try{var r,n=function(e){if(r)return e;throw new y("TIMEOUT","can't find useroperation",{context:i.userOperationHash})},i=this;if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");var a=0,o=function(e,t,r){for(var n;;){var i=e();if(C(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!C(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!C(o)){n=2;break}}}var s=new L,f=w.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(c):o.then(l)).then(void 0,f),s;function c(n){a=n;do{if(t&&(o=t())&&o.then&&!C(o))return void o.then(l).then(void 0,f);if(!(i=e())||C(i)&&!i.v)return void w(s,1,a);if(i.then)return void i.then(u).then(void 0,f);C(a=r())&&(a=a.v)}while(!a||!a.then);a.then(c).then(void 0,f)}function u(e){e?(a=r())&&a.then?a.then(c).then(void 0,f):c(a):w(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,f):u(i):w(s,1,a)}}(function(){return!r&&a<=e},void 0,function(){return Promise.resolve(i.delay(1e3*t)).then(function(){return Promise.resolve(i.bundler.getUserOperationReceipt(i.userOperationHash)).then(function(e){if(null!=e)return r=1,e;a++})})});return Promise.resolve(o&&o.then?o.then(n):n(o))}catch(e){return Promise.reject(e)}},e}(),N=/*#__PURE__*/function(r){function n(e,t,i){var a;return void 0===t&&(t=n.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=n.DEFAULT_ENTRYPOINT_ADDRESS),(a=r.call(this,e)||this).entrypointAddress=void 0,a.safe4337ModuleAddress=void 0,a.initCode=void 0,a.entrypointAddress=i,a.safe4337ModuleAddress=t,a.initCode=null,a}u(n,r),n.initializeNewAccount=function(e,t){void 0===t&&(t={});var r=n.createAccountAddressAndInitCode(e,t),i=r[1],a=new n(r[0]);return a.initCode=i,a},n.createAccountAddressAndInitCode=function(e,t){var r,i,a,o,s;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one owner");var f=null!=(r=t.threshold)?r:1,c=null!=(i=t.c2Nonce)?i:0n,u=null!=(a=t.singletonAddress)?a:n.DEFAULT_SINGLETON_ADDRESS,l=null!=(o=t.safe4337ModuleAddress)?o:n.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:n.DEFAULT_ADD_MODULE_LIB_ADDRESS,p=new U;null!=t.safeAccountFactoryAddress&&(p=new U(t.safeAccountFactoryAddress));var h=n.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(h,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,h,c])]},n.createInitializerCallData=function(e,t,r,i){if(void 0===r&&(r=n.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=n.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");var a=b("0x8d0dc49f",["address[]"],[[r]]);return b(n.initializerFunctionSelector,n.initializerFunctionInputAbi,[e,t,i,a,r,R,0,R])},n.createInitCode=function(e,t,r,i,a,o,s){if(void 0===t&&(t=1),void 0===r&&(r=0n),void 0===i&&(i=n.DEFAULT_SINGLETON_ADDRESS),void 0===a&&(a=new U),void 0===o&&(o=n.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===s&&(s=n.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");if(r<0n)throw RangeError("c2Nonce can't be negative");var f=n.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,f,r])},n.createProxyAddress=function(e,r,n,i){if(r<0n)throw RangeError("c2Nonce can't be negative");var a=t.AbiCoder.defaultAbiCoder(),o=t.keccak256(t.solidityPacked(["bytes32","uint256"],[t.keccak256(e),r])),s=a.encode(["uint256"],[i]),f=t.keccak256(t.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+t.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,f]).slice(-40)},n.createAccountCallDataSingleTransaction=function(t){var r,i,a,o=null!=(r=t.value)?r:0,s=null!=(i=t.data)?i:"0x",f=null!=(a=t.operation)?a:e.Operation.Call;return n.createAccountCallData(t.to,o,s,f)},n.createAccountCallDataBatchTransactions=function(t,r){if(void 0===r&&(r=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS),t.length<1)throw RangeError("There should be at least one metaTransaction");var i=b("0x8d80ff0a",["bytes"],[T(t)]);return n.createAccountCallData(r,0n,i,e.Operation.Delegate)},n.createAccountCallData=function(e,t,r,i,a){return void 0===a&&(a=n.DEFAULT_EXECUTOR_FUCNTION_SELECTOR),b(a,n.executorFunctionInputAbi,[e,t,r,i])};var i=n.prototype;return i.decodeAccountCallData=function(e){if(e.startsWith(G.executeUserOpWithErrorString)||e.startsWith(G.executeUserOp)){var r=t.AbiCoder.defaultAbiCoder(),n="0x"+e.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);return[i[0],BigInt(i[1]),i[2],Number(i[3])]}throw new y("BAD_DATA","Invalid calldata, should start with "+G.executeUserOpWithErrorString+" or "+G.executeUserOp,{context:{callData:e}})},i.prependTokenPaymasterApproveToCallData=function(r,i,a,o,s){void 0===s&&(s=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var f=this.decodeAccountCallData(r),c=f[0],u=f[1],l=f[2],d=f[3],p="";p="string"!=typeof l?(new TextDecoder).decode(l):l;var h=T([{to:i,value:0n,data:b(D("approve(address,uint256)"),["address","uint256"],[a,o]),operation:e.Operation.Call}]),v="",m="0x8d80ff0a";if(p.startsWith(m)){var y=function(e){return t.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);v=y+h.slice(2)}else v=T([{to:c,value:u,data:l,operation:d}])+h.slice(2);var A=b(m,["bytes"],[v]);return n.createAccountCallData(s,0n,A,e.Operation.Delegate)},i.estimateUserOperationGas=function(e,t,r,n){void 0===n&&(n=1);try{if(n<1n)throw RangeError("numberOfSigners can't be less than 1");for(var i="",a=0;a<n;a++)i+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+i;var o=new F(t);return Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(e){return[BigInt(e.preVerificationGas),BigInt(e.verificationGasLimit)+5000n*BigInt(n),BigInt(e.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(e,r,i,o){void 0===o&&(o={});try{var s=function(){var s;function l(){var e,t;function r(){var e,t,r;if("bigint"==typeof o.preVerificationGas&&o.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof o.verificationGasLimit&&o.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof o.callGasLimit&&o.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return n.preVerificationGas=null!=(e=o.preVerificationGas)?e:a,n.verificationGasLimit=null!=(t=o.verificationGasLimit)?t:s,n.callGasLimit=null!=(r=o.callGasLimit)?r:l,n}if("bigint"==typeof o.maxFeePerGas&&o.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof o.maxPriorityFeePerGas&&o.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");h=null!=(e=o.maxFeePerGas)?e:h,v=null!=(t=o.maxPriorityFeePerGas)?t:v;var n=c({},S,{sender:f.accountAddress,nonce:u,initCode:d,callData:p,maxFeePerGas:h,maxPriorityFeePerGas:v}),a=S.preVerificationGas,s=S.verificationGasLimit,l=S.callGasLimit,m=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return Promise.resolve(f.estimateUserOperationGas(n,i,o.state_override_set,o.numberOfSigners)).then(function(e){a=e[0],s=e[1],l=e[2]})}();return m&&m.then?m.then(r):r()}var d=null!=(s=o.initCode)?s:f.initCode;if((null==d||u>0n)&&(d="0x"),u<0n)throw RangeError("nonce can't be negative");var p="0x";p=null==o.callData?1==e.length?n.createAccountCallDataSingleTransaction(e[0]):n.createAccountCallDataBatchTransactions(e):o.callData;var h=S.maxFeePerGas,v=S.maxPriorityFeePerGas,m=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return Promise.resolve(function(e,r){try{void 0===r&&(r=a.Medium);var n=new t.JsonRpcProvider(e);return Promise.resolve(n.getFeeData()).then(function(e){return[BigInt(Math.ceil(Number(e.maxFeePerGas)*r)),BigInt(Math.ceil(Number(e.maxPriorityFeePerGas)*r))]})}catch(e){return Promise.reject(e)}}(r)).then(function(e){h=e[0],v=e[1]})}();return m&&m.then?m.then(l):l()},f=this;if(e.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return Promise.resolve(P(r,f.entrypointAddress,f.accountAddress)).then(function(e){u=e});u=o.nonce}();return Promise.resolve(l&&l.then?l.then(s):s())}catch(e){return Promise.reject(e)}},i.signUserOperation=function(e,r,i,a,o){if(void 0===a&&(a=0n),void 0===o&&(o=0n),r.length<1)throw RangeError("There should be at least one privateKey");if(i<0n)throw RangeError("chainId can't be negative");if(a<0n)throw RangeError("validAfter can't be negative");if(o<0n)throw RangeError("validUntil can't be negative");for(var s,f={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:a,validUntil:o,entryPoint:this.entrypointAddress},c={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"}]},u=new Map,l=v(r);!(s=l()).done;){var d=new t.Wallet(s.value);u.set(d.address,d)}for(var p,h=[],m=v(Array.from(u.keys()).sort());!(p=m()).done;){var y=u.get(p.value).signingKey.sign(t.TypedDataEncoder.hash({chainId:i,verifyingContract:this.safe4337ModuleAddress},c,f)).serialized;h.push(y.slice(2))}return n.formatEip712SignaturesToUseroperationSignature(h,a,o)},n.formatEip712SignaturesToUseroperationSignature=function(e,r,n){void 0===r&&(r=0n),void 0===n&&(n=0n);var i="0x"+e.join("");return t.solidityPacked(["uint48","uint48","bytes"],[r,n,i])},i.sendUserOperation=function(e,t){try{var r=this,n=new F(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new I(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},n}(s);function B(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}N.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",N.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",N.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",N.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",N.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",N.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",N.initializerFunctionSelector="0xb63e800d",N.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],N.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=G.executeUserOpWithErrorString,N.executorFunctionInputAbi=["address","uint256","bytes","uint8"];var k=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this)||this).rpcUrl=void 0,r.entrypointAddress=void 0,r.supportedTokens=void 0,r.paymasterMetadata=void 0,r.rpcUrl=t,r}u(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(B(function(){return Promise.resolve(e.getSupportedEntrypoint()).then(function(t){return e.entrypointAddress=t,Promise.resolve(e.getSupportedERC20TokensAndPaymasterMetadata()).then(function(t){return e.supportedTokens=t.tokens,e.paymasterMetadata=t.paymasterMetadata,null})})},function(e){var t=A(e);throw new y("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}))}catch(e){return Promise.reject(e)}},r.getPaymasterMetaData=function(){try{var e=function(){return t.paymasterMetadata},t=this,r=function(){if(null==t.paymasterMetadata)return Promise.resolve(t.initialize()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokensAndPaymasterMetadata=function(){try{var e=this;return Promise.resolve(null==e.supportedTokens||null==e.paymasterMetadata?B(function(){return Promise.resolve(g(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens,paymasterMetadata:e.paymasterMetadata}})},function(e){var t=A(e);throw new y("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}):{tokens:e.supportedTokens,paymasterMetadata:e.paymasterMetadata})}catch(e){return Promise.reject(e)}},r.getSupportedEntrypoint=function(){try{var e=this;return Promise.resolve(null==e.entrypointAddress?B(function(){return Promise.resolve(g(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=A(e);throw new y("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}):e.entrypointAddress)}catch(e){return Promise.reject(e)}},r.isSupportedERC20Token=function(e){try{var t=function(){return!!r.supportedTokens.find(function(t){return t.address===e.toLowerCase()})},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokenData=function(e){try{var t=function(){var t=r.supportedTokens.find(function(t){return t.address.toLowerCase()===e.toLowerCase()});return t?{symbol:t.symbol,address:t.address,decimal:Number(t.decimal),fee:BigInt(t.fee),exchangeRate:BigInt(t.exchangeRate)}:null},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.createPaymasterUserOperation=function(e,t,r,n){void 0===r&&(r={});try{var i=function(){return B(function(){e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var i=new F(t);return Promise.resolve(i.estimateUserOperationGas(e,a.entrypointAddress,n)).then(function(t){return e.preVerificationGas=t.preVerificationGas,e.verificationGasLimit=t.verificationGasLimit+10000n,e.callGasLimit=t.callGasLimit,Promise.resolve(g(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,f={paymasterAndData:s.paymasterAndData,callGasLimit:null==s.callGasLimit?void 0:BigInt(s.callGasLimit),preVerificationGas:null==s.preVerificationGas?void 0:BigInt(s.preVerificationGas),verificationGasLimit:null==s.verificationGasLimit?void 0:BigInt(s.verificationGasLimit),maxFeePerGas:null==s.maxFeePerGas?void 0:BigInt(s.maxFeePerGas),maxPriorityFeePerGas:null==s.maxPriorityFeePerGas?void 0:BigInt(s.maxPriorityFeePerGas)};return e.paymasterAndData=f.paymasterAndData,e.callGasLimit=null!=(r=f.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=f.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=f.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=f.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=f.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})})},function(e){var t=A(e);throw new y("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})})},a=this,o=function(){if(null==a.entrypointAddress||null==a.supportedTokens||null==a.paymasterMetadata)return Promise.resolve(a.initialize()).then(function(){})}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}},r.createSponsorPaymasterUserOperation=function(e,t,r){try{return Promise.resolve(this.createPaymasterUserOperation(e,t,{},r))}catch(e){return Promise.reject(e)}},r.createTokenPaymasterUserOperation=function(e,t,r,n,i){void 0===i&&(i={});try{var a=this;return Promise.resolve(B(function(){return Promise.resolve(a.calculateUserOperationErc20TokenMaxGasCost(t,r)).then(function(o){var s=2n*o;return Promise.resolve(a.getPaymasterMetaData()).then(function(o){var f=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=f,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=A(e);throw new y("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(B(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new y("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e)}})});var i=O(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=A(e);throw new y("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),M={__proto__:null,SmartAccount:s,SafeAccountV0_2_0:N,SendUseroperationResponse:I,SmartAccountFactory:_,SafeAccountFactory:U,Bundler:F,CandidePaymaster:k,createUserOperationHash:E,createCallData:b,getFunctionSelector:D,fetchAccountNonce:P,calculateUserOperationMaxGasCost:O,get Operation(){return e.Operation}};e.Bundler=F,e.CandidePaymaster=k,e.SafeAccountFactory=U,e.SafeAccountV0_2_0=N,e.SendUseroperationResponse=I,e.SmartAccount=s,e.SmartAccountFactory=_,e.abstractionkit=M,e.calculateUserOperationMaxGasCost=O,e.createCallData=b,e.createUserOperationHash=E,e.fetchAccountNonce=P,e.getFunctionSelector=D}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ethers"),require("isomorphic-unfetch")):"function"==typeof define&&define.amd?define(["exports","ethers","isomorphic-unfetch"],t):t((e||self).abstractionkit={},e.ethers,e.isomorphicUnfetch)}(this,function(e,t,r){function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var i,a,o=/*#__PURE__*/n(r),s=function(e){this.accountAddress=void 0,this.accountAddress=e};function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(f=function(){return!!e})()}function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c.apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function p(e){var t="function"==typeof Map?new Map:void 0;return p=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(f())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&d(i,r.prototype),i}(e,arguments,l(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},p(e)}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}s.proxyByteCode=void 0,s.initializerFunctionSelector=void 0,s.initializerFunctionInputAbi=void 0,s.executorFunctionSelector=void 0,s.executorFunctionInputAbi=void 0,e.Operation=void 0,(i=e.Operation||(e.Operation={}))[i.Call=0]="Call",i[i.Delegate=1]="Delegate",function(e){e[e.Slow=1]="Slow",e[e.Medium=1.2]="Medium",e[e.Fast=1.5]="Fast"}(a||(a={}));var v={"-32602":"INVALID_FIELDS","-32500":"SIMULATE_VALIDATION","-32501":"SIMULATE_PAYMASTER_VALIDATION","-32502":"OPCODE_VALIDATION","-32503":"EXPIRE_SHORTLY","-32504":"REPUTATION","-32505":"INSUFFICIENT_STAKE","-32506":"UNSUPPORTED_SIGNATURE_AGGREGATOR","-32507":"INVALID_SIGNATURE","-32601":"INVALID_USEROPERATION_HASH","-32521":"EXECUTION_REVERTED"},m=/*#__PURE__*/function(e){function t(t,r,n){var i;void 0===n&&(n={});var a=n.errno,o=n.context;return(i=e.call(this,r,{cause:n.cause})||this).code=void 0,i.context=void 0,i.errno=void 0,i.name=i.constructor.name,i.code=t,i.errno=a,i.context=o,i}return u(t,e),t}(/*#__PURE__*/p(Error));function y(e){if(e instanceof Error)return e;var t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error("This value was thrown as is, not through an Error: "+t)}var A=function(e,t,r,n){void 0===n&&(n=0);try{var i=[{from:"0x0000000000000000000000000000000000000000",to:t,data:E(b("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(g(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new m("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=y(e);throw new m("BAD_DATA","getNonce returned ill formed data",{cause:t})}})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=y(e);throw new m("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},g=function(e,t,r){try{var n=o.default||o,i={method:"POST",body:JSON.stringify({method:t,params:r,id:(new Date).getTime(),jsonrpc:"2.0"},function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t}),redirect:"follow"};return Promise.resolve(n(e,i)).then(function(t){return Promise.resolve(t.json()).then(function(t){if("result"in t)return t.result;var r=t.error,n=String(r.code);throw new m(n in v?v[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(i)}})})})}catch(e){return Promise.reject(e)}};function P(e,r,n){var i=t.keccak256(function(e){var r=[e.sender,e.nonce,t.keccak256(e.initCode),t.keccak256(e.callData),e.callGasLimit,e.verificationGasLimit,e.preVerificationGas,e.maxFeePerGas,e.maxPriorityFeePerGas,t.keccak256(e.paymasterAndData)];return t.AbiCoder.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],r)}(e)),a=t.AbiCoder.defaultAbiCoder().encode(["bytes32","address","uint256"],[i,r,n]);return t.keccak256(a)}function E(e,r,n){return e+t.AbiCoder.defaultAbiCoder().encode(r,n).slice(2)}function b(e){return t.id(e).slice(0,10)}function D(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var O,G="0x0000000000000000000000000000000000000000",R={sender:G,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0xffffffn,verificationGasLimit:0xffffffn,preVerificationGas:0xffffffn,maxFeePerGas:0xffffffn,maxPriorityFeePerGas:0xfffffffn,paymasterAndData:"0x",signature:"0x"},_=/*#__PURE__*/function(){function e(e,t,r){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=r}return e.prototype.getFactoryGeneratorFunctionCallData=function(e){var t=E(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)},e}(),S=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return u(t,e),t}(_);function U(r){return"0x"+r.map(function(r){return a=null!=(i=(n=r).operation)?i:e.Operation.Call,o=t.getBytes(n.data),t.solidityPacked(["uint8","address","uint256","uint256","bytes"],[a,n.to,n.value,o.length,o]).slice(2);var n,i,a,o}).join("")}function T(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(O||(O={}));var x=/*#__PURE__*/function(){function e(e){this.rpcUrl=void 0,this.rpcUrl=e}var t=e.prototype;return t.chainId=function(){try{var e=this;return Promise.resolve(T(function(){return Promise.resolve(g(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new m("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=y(e);throw new m("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.supportedEntryPoints=function(){try{var e=this;return Promise.resolve(T(function(){return Promise.resolve(g(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=y(e);throw new m("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.estimateUserOperationGas=function(e,t,r){try{var n=this;return Promise.resolve(T(function(){function i(){var e=a;return{callGasLimit:BigInt(e.callGasLimit),preVerificationGas:BigInt(e.preVerificationGas),verificationGasLimit:BigInt(e.verificationGasLimit)}}var a={},o=void 0===r?Promise.resolve(g(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(g(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=y(e);throw new m("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.sendUserOperation=function(e,t){try{var r=this;return Promise.resolve(T(function(){return Promise.resolve(g(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=y(e);throw new m("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t.getUserOperationReceipt=function(e){try{var t=this;return Promise.resolve(T(function(){return Promise.resolve(g(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=c({},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 c({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:r})}return null})},function(t){var r=y(t);throw new m("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},t.getUserOperationByHash=function(e){try{var t=this;return Promise.resolve(T(function(){return Promise.resolve(g(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?c({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=y(t);throw new m("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:r,context:{useroperationhash:e}})}))}catch(e){return Promise.reject(e)}},e}();function F(e,t,r){if(!e.s){if(r instanceof w){if(!r.s)return void(r.o=F.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(F.bind(null,e,t),F.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var w=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var a=1&i?t:r;if(a){try{F(n,1,a(this.v))}catch(e){F(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?F(n,1,t?t(i):i):r?F(n,1,r(i)):F(n,2,i)}catch(e){F(n,2,e)}},n},e}();function L(e){return e instanceof w&&1&e.s}var I=/*#__PURE__*/function(){function e(e,t,r){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=r}var t=e.prototype;return t.delay=function(e){return new Promise(function(t){return setTimeout(t,e)})},t.included=function(e,t){void 0===e&&(e=180),void 0===t&&(t=2);try{var r,n=function(e){if(r)return e;throw new m("TIMEOUT","can't find useroperation",{context:i.userOperationHash})},i=this;if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");var a=0,o=function(e,t,r){for(var n;;){var i=e();if(L(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!L(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!L(o)){n=2;break}}}var s=new w,f=F.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(c):o.then(l)).then(void 0,f),s;function c(n){a=n;do{if(t&&(o=t())&&o.then&&!L(o))return void o.then(l).then(void 0,f);if(!(i=e())||L(i)&&!i.v)return void F(s,1,a);if(i.then)return void i.then(u).then(void 0,f);L(a=r())&&(a=a.v)}while(!a||!a.then);a.then(c).then(void 0,f)}function u(e){e?(a=r())&&a.then?a.then(c).then(void 0,f):c(a):F(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,f):u(i):F(s,1,a)}}(function(){return!r&&a<=e},void 0,function(){return Promise.resolve(i.delay(1e3*t)).then(function(){return Promise.resolve(i.bundler.getUserOperationReceipt(i.userOperationHash)).then(function(e){if(null!=e)return r=1,e;a++})})});return Promise.resolve(o&&o.then?o.then(n):n(o))}catch(e){return Promise.reject(e)}},e}(),C=/*#__PURE__*/function(r){function n(e,t,i){var a;return void 0===t&&(t=n.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=n.DEFAULT_ENTRYPOINT_ADDRESS),(a=r.call(this,e)||this).entrypointAddress=void 0,a.safe4337ModuleAddress=void 0,a.initCode=void 0,a.entrypointAddress=i,a.safe4337ModuleAddress=t,a.initCode=null,a}u(n,r),n.initializeNewAccount=function(e,t){void 0===t&&(t={});var r=n.createAccountAddressAndInitCode(e,t),i=r[1],a=new n(r[0]);return a.initCode=i,a},n.createAccountAddressAndInitCode=function(e,t){var r,i,a,o,s;if(void 0===t&&(t={}),e.length<1)throw RangeError("There should be at least one owner");var f=null!=(r=t.threshold)?r:1,c=null!=(i=t.c2Nonce)?i:0n,u=null!=(a=t.singletonAddress)?a:n.DEFAULT_SINGLETON_ADDRESS,l=null!=(o=t.safe4337ModuleAddress)?o:n.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:n.DEFAULT_ADD_MODULE_LIB_ADDRESS,p=new S;null!=t.safeAccountFactoryAddress&&(p=new S(t.safeAccountFactoryAddress));var h=n.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(h,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,h,c])]},n.createInitializerCallData=function(e,t,r,i){if(void 0===r&&(r=n.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===i&&(i=n.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");var a=E("0x8d0dc49f",["address[]"],[[r]]);return E(n.initializerFunctionSelector,n.initializerFunctionInputAbi,[e,t,i,a,r,G,0,G])},n.createInitCode=function(e,t,r,i,a,o,s){if(void 0===t&&(t=1),void 0===r&&(r=0n),void 0===i&&(i=n.DEFAULT_SINGLETON_ADDRESS),void 0===a&&(a=new S),void 0===o&&(o=n.DEFAULT_SAFE_4337_MODULE_ADDRESS),void 0===s&&(s=n.DEFAULT_ADD_MODULE_LIB_ADDRESS),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");if(r<0n)throw RangeError("c2Nonce can't be negative");var f=n.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,f,r])},n.createProxyAddress=function(e,r,n,i){if(r<0n)throw RangeError("c2Nonce can't be negative");var a=t.AbiCoder.defaultAbiCoder(),o=t.keccak256(t.solidityPacked(["bytes32","uint256"],[t.keccak256(e),r])),s=a.encode(["uint256"],[i]),f=t.keccak256(t.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+t.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,f]).slice(-40)},n.createAccountCallDataSingleTransaction=function(t){var r,i,a,o=null!=(r=t.value)?r:0,s=null!=(i=t.data)?i:"0x",f=null!=(a=t.operation)?a:e.Operation.Call;return n.createAccountCallData(t.to,o,s,f)},n.createAccountCallDataBatchTransactions=function(t,r){if(void 0===r&&(r=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS),t.length<1)throw RangeError("There should be at least one metaTransaction");var i=E("0x8d80ff0a",["bytes"],[U(t)]);return n.createAccountCallData(r,0n,i,e.Operation.Delegate)},n.createAccountCallData=function(e,t,r,i,a){return void 0===a&&(a=n.DEFAULT_EXECUTOR_FUCNTION_SELECTOR),E(a,n.executorFunctionInputAbi,[e,t,r,i])};var i=n.prototype;return i.decodeAccountCallData=function(e){if(e.startsWith(O.executeUserOpWithErrorString)||e.startsWith(O.executeUserOp)){var r=t.AbiCoder.defaultAbiCoder(),n="0x"+e.slice(10),i=r.decode(["address","uint256","bytes","uint8"],n);return[i[0],BigInt(i[1]),i[2],Number(i[3])]}throw new m("BAD_DATA","Invalid calldata, should start with "+O.executeUserOpWithErrorString+" or "+O.executeUserOp,{context:{callData:e}})},i.prependTokenPaymasterApproveToCallData=function(r,i,a,o,s){void 0===s&&(s=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var f=this.decodeAccountCallData(r),c=f[0],u=f[1],l=f[2],d=f[3],p="";p="string"!=typeof l?(new TextDecoder).decode(l):l;var h=U([{to:i,value:0n,data:E(b("approve(address,uint256)"),["address","uint256"],[a,o]),operation:e.Operation.Call}]),v="",m="0x8d80ff0a";if(p.startsWith(m)){var y=function(e){return t.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);v=y+h.slice(2)}else v=U([{to:c,value:u,data:l,operation:d}])+h.slice(2);var A=E(m,["bytes"],[v]);return n.createAccountCallData(s,0n,A,e.Operation.Delegate)},i.estimateUserOperationGas=function(e,t,r,n){void 0===n&&(n=1);try{if(n<1n)throw RangeError("numberOfSigners can't be less than 1");for(var i="",a=0;a<n;a++)i+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+i;var o=new x(t);return Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(e){return[BigInt(e.preVerificationGas),BigInt(e.verificationGasLimit)+5000n*BigInt(n),BigInt(e.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(e,r,i,o){void 0===o&&(o={});try{var s=function(){var s;function l(){var e,t,r,n;function a(){var e,t,r,n,i,a;if("bigint"==typeof o.preVerificationGas&&o.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof o.verificationGasLimit&&o.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof o.callGasLimit&&o.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return s.preVerificationGas=null!=(e=o.preVerificationGas)?e:l*BigInt(Math.floor(((null!=(t=o.preVerificationGasPercentageMultiplier)?t:0)+100)/100)),s.verificationGasLimit=null!=(r=o.verificationGasLimit)?r:m*BigInt(Math.floor(((null!=(n=o.verificationGasLimitPercentageMultiplier)?n:0)+100)/100)),s.callGasLimit=null!=(i=o.callGasLimit)?i:y*BigInt(Math.floor(((null!=(a=o.callGasLimitPercentageMultiplier)?a:0)+100)/100)),s}if("bigint"==typeof o.maxFeePerGas&&o.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof o.maxPriorityFeePerGas&&o.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");h=null!=(e=o.maxFeePerGas)?e:h*BigInt(Math.floor(((null!=(t=o.maxFeePerGasPercentageMultiplier)?t:0)+100)/100)),v=null!=(r=o.maxPriorityFeePerGas)?r:v*BigInt(Math.floor(((null!=(n=o.maxPriorityFeePerGasPercentageMultiplier)?n:0)+100)/100));var s=c({},R,{sender:f.accountAddress,nonce:u,initCode:d,callData:p,maxFeePerGas:h,maxPriorityFeePerGas:v}),l=R.preVerificationGas,m=R.verificationGasLimit,y=R.callGasLimit,A=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return Promise.resolve(f.estimateUserOperationGas(s,i,o.state_override_set,o.numberOfSigners)).then(function(e){l=e[0],m=e[1],y=e[2]})}();return A&&A.then?A.then(a):a()}var d=null!=(s=o.initCode)?s:f.initCode;if((null==d||u>0n)&&(d="0x"),u<0n)throw RangeError("nonce can't be negative");var p="0x";p=null==o.callData?1==e.length?n.createAccountCallDataSingleTransaction(e[0]):n.createAccountCallDataBatchTransactions(e):o.callData;var h=R.maxFeePerGas,v=R.maxPriorityFeePerGas,m=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return Promise.resolve(function(e,r){try{void 0===r&&(r=a.Medium);var n=new t.JsonRpcProvider(e);return Promise.resolve(n.getFeeData()).then(function(e){return[BigInt(Math.ceil(Number(e.maxFeePerGas)*r)),BigInt(Math.ceil(Number(e.maxPriorityFeePerGas)*r))]})}catch(e){return Promise.reject(e)}}(r)).then(function(e){h=e[0],v=e[1]})}();return m&&m.then?m.then(l):l()},f=this;if(e.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return Promise.resolve(A(r,f.entrypointAddress,f.accountAddress)).then(function(e){u=e});u=o.nonce}();return Promise.resolve(l&&l.then?l.then(s):s())}catch(e){return Promise.reject(e)}},i.signUserOperation=function(e,r,i,a,o){if(void 0===a&&(a=0n),void 0===o&&(o=0n),r.length<1)throw RangeError("There should be at least one privateKey");if(i<0n)throw RangeError("chainId can't be negative");if(a<0n)throw RangeError("validAfter can't be negative");if(o<0n)throw RangeError("validUntil can't be negative");for(var s,f={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:a,validUntil:o,entryPoint:this.entrypointAddress},c=[],u=[],l=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return h(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(s=l()).done;){var d=new t.Wallet(s.value),p=d.signingKey.sign(t.TypedDataEncoder.hash({chainId:i,verifyingContract:this.safe4337ModuleAddress},n.EIP712_SAFE_OPERATION_TYPE,f)).serialized;c.push(d.address),u.push(p)}return n.formatEip712SignaturesToUseroperationSignature(c,u,a,o)},n.formatEip712SignaturesToUseroperationSignature=function(e,r,n,i){if(void 0===n&&(n=0n),void 0===i&&(i=0n),e.length!=r.length)throw RangeError("signersAddresses and signatures arrays should be the same length");if(n<0n)throw RangeError("validAfter can't be negative");if(i<0n)throw RangeError("validUntil can't be negative");var a=new Map;e.forEach(function(e,t){a.set(e.toLocaleLowerCase(),r[t])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return t.solidityPacked(["uint48","uint48","bytes"],[n,i,s])},i.sendUserOperation=function(e,t){try{var r=this,n=new x(t);return Promise.resolve(n.sendUserOperation(e,r.entrypointAddress)).then(function(e){return new I(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},n}(s);function M(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}C.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",C.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",C.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",C.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",C.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",C.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",C.initializerFunctionSelector="0xb63e800d",C.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],C.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=O.executeUserOpWithErrorString,C.executorFunctionInputAbi=["address","uint256","bytes","uint8"],C.EIP712_SAFE_OPERATION_TYPE={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"}]};var B=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this)||this).rpcUrl=void 0,r.entrypointAddress=void 0,r.supportedTokens=void 0,r.paymasterMetadata=void 0,r.rpcUrl=t,r}u(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(M(function(){return Promise.resolve(e.getSupportedEntrypoint()).then(function(t){return e.entrypointAddress=t,Promise.resolve(e.getSupportedERC20TokensAndPaymasterMetadata()).then(function(t){return e.supportedTokens=t.tokens,e.paymasterMetadata=t.paymasterMetadata,null})})},function(e){var t=y(e);throw new m("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}))}catch(e){return Promise.reject(e)}},r.getPaymasterMetaData=function(){try{var e=function(){return t.paymasterMetadata},t=this,r=function(){if(null==t.paymasterMetadata)return Promise.resolve(t.initialize()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokensAndPaymasterMetadata=function(){try{var e=this;return Promise.resolve(null==e.supportedTokens||null==e.paymasterMetadata?M(function(){return Promise.resolve(g(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens,paymasterMetadata:e.paymasterMetadata}})},function(e){var t=y(e);throw new m("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}):{tokens:e.supportedTokens,paymasterMetadata:e.paymasterMetadata})}catch(e){return Promise.reject(e)}},r.getSupportedEntrypoint=function(){try{var e=this;return Promise.resolve(null==e.entrypointAddress?M(function(){return Promise.resolve(g(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=y(e);throw new m("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}):e.entrypointAddress)}catch(e){return Promise.reject(e)}},r.isSupportedERC20Token=function(e){try{var t=function(){return!!r.supportedTokens.find(function(t){return t.address===e.toLowerCase()})},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.getSupportedERC20TokenData=function(e){try{var t=function(){var t=r.supportedTokens.find(function(t){return t.address.toLowerCase()===e.toLowerCase()});return t?{symbol:t.symbol,address:t.address,decimal:Number(t.decimal),fee:BigInt(t.fee),exchangeRate:BigInt(t.exchangeRate)}:null},r=this,n=function(){if(null==r.entrypointAddress||null==r.supportedTokens||null==r.paymasterMetadata)return Promise.resolve(r.initialize()).then(function(){})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},r.createPaymasterUserOperation=function(e,t,r,n){void 0===r&&(r={});try{var i=function(){return M(function(){e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var i=new x(t);return Promise.resolve(i.estimateUserOperationGas(e,a.entrypointAddress,n)).then(function(t){return e.preVerificationGas=t.preVerificationGas+100n,e.verificationGasLimit=t.verificationGasLimit+10000n,e.callGasLimit=t.callGasLimit,Promise.resolve(g(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,f={paymasterAndData:s.paymasterAndData,callGasLimit:null==s.callGasLimit?void 0:BigInt(s.callGasLimit),preVerificationGas:null==s.preVerificationGas?void 0:BigInt(s.preVerificationGas),verificationGasLimit:null==s.verificationGasLimit?void 0:BigInt(s.verificationGasLimit),maxFeePerGas:null==s.maxFeePerGas?void 0:BigInt(s.maxFeePerGas),maxPriorityFeePerGas:null==s.maxPriorityFeePerGas?void 0:BigInt(s.maxPriorityFeePerGas)};return e.paymasterAndData=f.paymasterAndData,e.callGasLimit=null!=(r=f.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=f.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=f.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=f.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=f.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})})},function(e){var t=y(e);throw new m("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})})},a=this,o=function(){if(null==a.entrypointAddress||null==a.supportedTokens||null==a.paymasterMetadata)return Promise.resolve(a.initialize()).then(function(){})}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}},r.createSponsorPaymasterUserOperation=function(e,t,r){try{return Promise.resolve(this.createPaymasterUserOperation(e,t,{},r))}catch(e){return Promise.reject(e)}},r.createTokenPaymasterUserOperation=function(e,t,r,n,i){void 0===i&&(i={});try{var a=this;return Promise.resolve(M(function(){return Promise.resolve(a.calculateUserOperationErc20TokenMaxGasCost(t,r)).then(function(o){var s=2n*o;return Promise.resolve(a.getPaymasterMetaData()).then(function(o){var f=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=f,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=y(e);throw new m("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(M(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new m("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e)}})});var i=D(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=y(e);throw new m("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),N={__proto__:null,SmartAccount:s,SafeAccountV0_2_0:C,SendUseroperationResponse:I,SmartAccountFactory:_,SafeAccountFactory:S,Bundler:x,CandidePaymaster:B,createUserOperationHash:P,createCallData:E,getFunctionSelector:b,fetchAccountNonce:A,calculateUserOperationMaxGasCost:D,get Operation(){return e.Operation}};e.Bundler=x,e.CandidePaymaster=B,e.SafeAccountFactory=S,e.SafeAccountV0_2_0=C,e.SendUseroperationResponse=I,e.SmartAccount=s,e.SmartAccountFactory=_,e.abstractionkit=N,e.calculateUserOperationMaxGasCost=D,e.createCallData=E,e.createUserOperationHash=P,e.fetchAccountNonce=A,e.getFunctionSelector=b}); |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Account Abstraction 4337 SDK by Candidelabs", | ||
@@ -10,0 +10,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
152452
755