abstractionkit 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"SafeAccountV0_2_0.d.ts","sourceRoot":"","sources":["../../../src/account/Safe/SafeAccountV0_2_0.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EACN,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EACN,4BAA4B,EAC5B,iBAAiB,EACjB,kCAAkC,EAGlC,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,qBAAa,iBAAkB,SAAQ,YAAY;IAClD,MAAM,CAAC,QAAQ,CAAC,0BAA0B,gDACI;IAC9C,MAAM,CAAC,QAAQ,CAAC,gCAAgC,gDACF;IAC9C,MAAM,CAAC,QAAQ,CAAC,yBAAyB,gDACK;IAC9C,MAAM,CAAC,QAAQ,CAAC,8BAA8B,gDACA;IAC9C,MAAM,CAAC,QAAQ,CAAC,kCAAkC,gDACJ;IAE9C,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAC66B;IACl9B,MAAM,CAAC,QAAQ,CAAC,2BAA2B,EAAE,MAAM,CAAgB;IACnE,MAAM,CAAC,QAAQ,CAAC,2BAA2B,EAAE,MAAM,EAAE,CASnD;IAEF,MAAM,CAAC,QAAQ,CAAC,kCAAkC,mEACe;IACjE,MAAM,CAAC,QAAQ,CAAC,wBAAwB,EAAE,MAAM,EAAE,CAKhD;IAEF,MAAM,CAAC,QAAQ,CAAC,0BAA0B;;;;;MAgBxC;IAEF,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,OAAO,CAAC,QAAQ,CAAgB;gBAG/B,cAAc,EAAE,MAAM,EACtB,qBAAqB,GAAE,MAA2D,EAClF,iBAAiB,GAAE,MAAqD;WAiB3D,oBAAoB,CACjC,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,iBAAsB,GAC/B,iBAAiB;WAcN,oBAAoB,CACjC,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,iBAAsB,GAC/B,MAAM;WAcK,+BAA+B,CAC5C,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,iBAAsB,GAC/B,CAAC,MAAM,EAAE,MAAM,CAAC;IAkDnB,OAAO,CAAC,MAAM,CAAC,yBAAyB;WAqD1B,cAAc,CAC3B,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,MAAU,EACrB,OAAO,GAAE,MAAW,EACpB,gBAAgB,GAAE,MAAoD,EACtE,kBAAkB,GAAE,kBAA6C,EACjE,qBAAqB,GAAE,MAA2D,EAClF,mBAAmB,GAAE,MAAyD,GAC5E,MAAM;WAsCK,kBAAkB,CAC/B,mBAAmB,EAAE,MAAM,EAC3B,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,EAC1B,gBAAgB,EAAE,MAAM,GACtB,MAAM;WA4BK,sCAAsC,CACnD,eAAe,EAAE,eAAe,GAC9B,MAAM;WAgBK,sCAAsC,CACnD,gBAAgB,EAAE,eAAe,EAAE,EACnC,wBAAwB,GAAE,MAA6D,GACrF,MAAM;WA2BK,qBAAqB,CAClC,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,EACpB,kCAAkC,GAAE,kCAAyF,GAC3H,MAAM;WAcK,qBAAqB,CAClC,QAAQ,EAAE,MAAM,GACd,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IA6C5B,sCAAsC,CAC5C,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,wBAAwB,GAAE,MAA6D,GACrF,MAAM;WAcK,4CAA4C,CACzD,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,wBAAwB,GAAE,MAA6D,GACrF,MAAM;IAyEI,wBAAwB,CACpC,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,gBAAgB,EACrC,eAAe,GAAE,MAAU,GACzB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IA6CvB,mBAAmB,CAC/B,YAAY,EAAE,eAAe,EAAE,EAC/B,WAAW,CAAC,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,GAAE,4BAAiC,GACzC,OAAO,CAAC,aAAa,CAAC;IAgNlB,iBAAiB,CACvB,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,MAAM,EACf,UAAU,GAAE,MAAW,EACvB,UAAU,GAAE,MAAW,GACrB,MAAM;WAkEK,8CAA8C,CAC3D,gBAAgB,EAAE,MAAM,EAAE,EAC1B,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,GAAE,MAAW,EACvB,UAAU,GAAE,MAAW,GACrB,MAAM;WAmCK,mDAAmD,CAChE,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,MAAW,EACvB,UAAU,GAAE,MAAW,GACrB,MAAM;IAoBI,iBAAiB,CAC7B,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,yBAAyB,CAAC;CAarC"}
1
+ {"version":3,"file":"SafeAccountV0_2_0.d.ts","sourceRoot":"","sources":["../../../src/account/Safe/SafeAccountV0_2_0.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EACN,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EACN,4BAA4B,EAC5B,iBAAiB,EACjB,kCAAkC,EAGlC,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,qBAAa,iBAAkB,SAAQ,YAAY;IAClD,MAAM,CAAC,QAAQ,CAAC,0BAA0B,gDACI;IAC9C,MAAM,CAAC,QAAQ,CAAC,gCAAgC,gDACF;IAC9C,MAAM,CAAC,QAAQ,CAAC,yBAAyB,gDACK;IAC9C,MAAM,CAAC,QAAQ,CAAC,8BAA8B,gDACA;IAC9C,MAAM,CAAC,QAAQ,CAAC,kCAAkC,gDACJ;IAE9C,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAC66B;IACl9B,MAAM,CAAC,QAAQ,CAAC,2BAA2B,EAAE,MAAM,CAAgB;IACnE,MAAM,CAAC,QAAQ,CAAC,2BAA2B,EAAE,MAAM,EAAE,CASnD;IAEF,MAAM,CAAC,QAAQ,CAAC,kCAAkC,mEACe;IACjE,MAAM,CAAC,QAAQ,CAAC,wBAAwB,EAAE,MAAM,EAAE,CAKhD;IAEF,MAAM,CAAC,QAAQ,CAAC,0BAA0B;;;;;MAgBxC;IAEF,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,OAAO,CAAC,QAAQ,CAAgB;gBAG/B,cAAc,EAAE,MAAM,EACtB,qBAAqB,GAAE,MAA2D,EAClF,iBAAiB,GAAE,MAAqD;WAiB3D,oBAAoB,CACjC,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,iBAAsB,GAC/B,iBAAiB;WAcN,oBAAoB,CACjC,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,iBAAsB,GAC/B,MAAM;WAcK,+BAA+B,CAC5C,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,iBAAsB,GAC/B,CAAC,MAAM,EAAE,MAAM,CAAC;IAkDnB,OAAO,CAAC,MAAM,CAAC,yBAAyB;WAqD1B,cAAc,CAC3B,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,GAAE,MAAU,EACrB,OAAO,GAAE,MAAW,EACpB,gBAAgB,GAAE,MAAoD,EACtE,kBAAkB,GAAE,kBAA6C,EACjE,qBAAqB,GAAE,MAA2D,EAClF,mBAAmB,GAAE,MAAyD,GAC5E,MAAM;WAsCK,kBAAkB,CAC/B,mBAAmB,EAAE,MAAM,EAC3B,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,EAC1B,gBAAgB,EAAE,MAAM,GACtB,MAAM;WA4BK,sCAAsC,CACnD,eAAe,EAAE,eAAe,GAC9B,MAAM;WAgBK,sCAAsC,CACnD,gBAAgB,EAAE,eAAe,EAAE,EACnC,wBAAwB,GAAE,MAA6D,GACrF,MAAM;WA2BK,qBAAqB,CAClC,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,EACpB,kCAAkC,GAAE,kCAAyF,GAC3H,MAAM;WAcK,qBAAqB,CAClC,QAAQ,EAAE,MAAM,GACd,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IA6C5B,sCAAsC,CAC5C,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,wBAAwB,GAAE,MAA6D,GACrF,MAAM;WAcK,4CAA4C,CACzD,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,wBAAwB,GAAE,MAA6D,GACrF,MAAM;IAyEI,wBAAwB,CACpC,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,gBAAgB,EACrC,eAAe,GAAE,MAAU,GACzB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IA8CvB,mBAAmB,CAC/B,YAAY,EAAE,eAAe,EAAE,EAC/B,WAAW,CAAC,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,GAAE,4BAAiC,GACzC,OAAO,CAAC,aAAa,CAAC;IAgNlB,iBAAiB,CACvB,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,MAAM,EACf,UAAU,GAAE,MAAW,EACvB,UAAU,GAAE,MAAW,GACrB,MAAM;WAkEK,8CAA8C,CAC3D,gBAAgB,EAAE,MAAM,EAAE,EAC1B,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,GAAE,MAAW,EACvB,UAAU,GAAE,MAAW,GACrB,MAAM;WAmCK,mDAAmD,CAChE,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,MAAW,EACvB,UAAU,GAAE,MAAW,GACrB,MAAM;IAoBI,iBAAiB,CAC7B,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,yBAAyB,CAAC;CAarC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
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 c(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(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,f(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"},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 c(t,e),t}(/*#__PURE__*/l(Error));function h(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 v("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=h(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=h(e);throw new v("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 v(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 G(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var E,D="0x0000000000000000000000000000000000000000",b={sender:D,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"},x=/*#__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}(),S=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return c(t,e),t}(x);function R(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 O(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}exports.SafeModuleExecutorFunctionSelector=void 0,(E=exports.SafeModuleExecutorFunctionSelector||(exports.SafeModuleExecutorFunctionSelector={})).executeUserOpWithErrorString="0x541d63c8",E.executeUserOp="0x7bb37428";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(O(function(){return Promise.resolve(y(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=h(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(O(function(){return Promise.resolve(y(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=h(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(O(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=h(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(O(function(){return Promise.resolve(y(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=h(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(O(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=h(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(O(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=h(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 _(e,t,r){if(!e.s){if(r instanceof L){if(!r.s)return void(r.o=_.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(_.bind(null,e,t),_.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{_(n,1,a(this.v))}catch(e){_(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?_(n,1,t?t(i):i):r?_(n,1,r(i)):_(n,2,i)}catch(e){_(n,2,e)}},n},e}();function T(e){return e instanceof L&&1&e.s}var U=/*#__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(T(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!T(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!T(o)){n=2;break}}}var s=new L,c=_.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(f):o.then(l)).then(void 0,c),s;function f(n){a=n;do{if(t&&(o=t())&&o.then&&!T(o))return void o.then(l).then(void 0,c);if(!(i=e())||T(i)&&!i.v)return void _(s,1,a);if(i.then)return void i.then(u).then(void 0,c);T(a=r())&&(a=a.v)}while(!a||!a.then);a.then(f).then(void 0,c)}function u(e){e?(a=r())&&a.then?a.then(f).then(void 0,c):f(a):_(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,c):u(i):_(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}(),w=/*#__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}c(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.createAccountAddress=function(e,t){return void 0===t&&(t={}),r.createAccountAddressAndInitCode(e,t)[0]},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 c=null!=(n=t.threshold)?n:1,f=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 S;null!=t.safeAccountFactoryAddress&&(p=new S(t.safeAccountFactoryAddress));var v=r.createInitializerCallData(e,c,l,d);return[this.createProxyAddress(v,f,p.address,u),p.getFactoryGeneratorFunctionCallData([u,v,f])]},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,D,0,D])},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 S),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 c=r.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,c,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]),c=e.keccak256(e.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+e.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,c]).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"],[R(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])},r.decodeAccountCallData=function(t){if(t.startsWith(exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString)||t.startsWith(exports.SafeModuleExecutorFunctionSelector.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 "+exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString+" or "+exports.SafeModuleExecutorFunctionSelector.executeUserOp,{context:{callData:t}})};var i=r.prototype;return i.prependTokenPaymasterApproveToCallData=function(e,t,n,i,a){return void 0===a&&(a=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS),r.prependTokenPaymasterApproveToCallDataStatic(e,t,n,i,a)},r.prependTokenPaymasterApproveToCallDataStatic=function(t,n,i,a,o){void 0===o&&(o=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=r.decodeAccountCallData(t),c=s[0],f=s[1],u=s[2],l=s[3],d="";d="string"!=typeof u?(new TextDecoder).decode(u):u;var p=R([{to:n,value:0n,data:P(g("approve(address,uint256)"),["address","uint256"],[i,a]),operation:exports.Operation.Call}]),v="",h="0x8d80ff0a";if(d.startsWith(h)){var m=function(t){return e.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+t.slice(10))[0]}(d);v=m+p.slice(2)}else v=R([{to:c,value:f,data:u,operation:l}])+p.slice(2);var y=P(h,["bytes"],[v]);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 F(t),s=e.maxFeePerGas,c=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(t){return e.maxFeePerGas=s,e.maxPriorityFeePerGas=c,[BigInt(t.preVerificationGas),BigInt(t.verificationGasLimit)+20000n*BigInt(n),BigInt(t.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(t,i,a,o){void 0===o&&(o={});try{var c=function(c){var l;function d(e){var t,r,n,i;function c(e){var t,r,n,i,a,s;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 l.preVerificationGas=null!=(t=o.preVerificationGas)?t:d*BigInt(Math.floor(((null!=(r=o.preVerificationGasPercentageMultiplier)?r:0)+100)/100)),l.verificationGasLimit=null!=(n=o.verificationGasLimit)?n:A*BigInt(Math.floor(((null!=(i=o.verificationGasLimitPercentageMultiplier)?i:0)+100)/100)),l.callGasLimit=null!=(a=o.callGasLimit)?a:P*BigInt(Math.floor(((null!=(s=o.callGasLimitPercentageMultiplier)?s:0)+100)/100)),l}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");m=null!=(t=o.maxFeePerGas)?t:m*BigInt(Math.floor(((null!=(r=o.maxFeePerGasPercentageMultiplier)?r:0)+100)/100)),y=null!=(n=o.maxPriorityFeePerGas)?n:y*BigInt(Math.floor(((null!=(i=o.maxPriorityFeePerGasPercentageMultiplier)?i:0)+100)/100));var l=s({},b,{sender:f.accountAddress,nonce:u,initCode:p,callData:h,maxFeePerGas:m,maxPriorityFeePerGas:y}),d=b.preVerificationGas,A=b.verificationGasLimit,P=b.callGasLimit,g=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return function(){if(null!=a){l.callGasLimit=0n,l.verificationGasLimit=0n,l.preVerificationGas=0n;var e=l.maxFeePerGas,t=l.maxPriorityFeePerGas;return l.maxFeePerGas=0n,l.maxPriorityFeePerGas=0n,Promise.resolve(f.estimateUserOperationGas(l,a,o.state_override_set,o.numberOfSigners)).then(function(r){d=r[0],A=r[1],P=r[2],l.maxFeePerGas=e,l.maxPriorityFeePerGas=t})}throw new v("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return g&&g.then?g.then(c):c()}var p=null!=(l=o.initCode)?l:f.initCode;if((null==p||u>0n)&&(p="0x"),u<0n)throw RangeError("nonce can't be negative");var h="0x";h=null==o.callData?1==t.length?r.createAccountCallDataSingleTransaction(t[0]):r.createAccountCallDataBatchTransactions(t):o.callData;var m=b.maxFeePerGas,y=b.maxPriorityFeePerGas,A=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return function(){if(null!=i)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){0n==(m=e[0])&&(m=1n),0n==(y=e[1])&&(y=1n)});throw new v("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden")}()}();return A&&A.then?A.then(d):d()},f=this;if(t.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return function(){if(null!=i)return Promise.resolve(m(i,f.entrypointAddress,f.accountAddress)).then(function(e){u=e});throw new v("BAD_DATA","providerRpc cant't be null if nonce is not overriden")}();u=o.nonce}();return Promise.resolve(l&&l.then?l.then(c):c())}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,c={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},f={chainId:i,verifyingContract:this.safe4337ModuleAddress},u=[],l=[],p=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=p()).done;){var v=new e.Wallet(s.value),h=v.signingKey.sign(e.TypedDataEncoder.hash(f,r.EIP712_SAFE_OPERATION_TYPE,c)).serialized;u.push(v.address),l.push(h)}return r.formatEip712SignaturesToUseroperationSignature(u,l,a,o)},r.formatEip712SignaturesToUseroperationSignature=function(e,t,n,i){if(void 0===n&&(n=0n),void 0===i&&(i=0n),e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");var a=new Map;e.forEach(function(e,r){a.set(e.toLocaleLowerCase(),t[r])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return r.formatEip712SingleSignatureToUseroperationSignature(s,n,i)},r.formatEip712SingleSignatureToUseroperationSignature=function(t,r,n){if(void 0===r&&(r=0n),void 0===n&&(n=0n),r<0n)throw RangeError("validAfter can't be negative");if(n<0n)throw RangeError("validUntil can't be negative");return e.solidityPacked(["uint48","uint48","bytes"],[r,n,t])},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 U(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}w.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",w.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",w.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",w.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",w.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",w.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",w.initializerFunctionSelector="0xb63e800d",w.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],w.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString,w.executorFunctionInputAbi=["address","uint256","bytes","uint8"],w.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}c(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=h(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(y(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens.map(function(e){return{symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)}}),paymasterMetadata:e.paymasterMetadata}})},function(e){var t=h(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(y(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=h(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.toLowerCase()===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={}),void 0===n&&(n={});try{var i=function(){return I(function(){function i(t){var i,f,u,l,d,p;if("bigint"==typeof n.preVerificationGas&&n.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof n.verificationGasLimit&&n.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof n.callGasLimit&&n.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return e.preVerificationGas=null!=(i=n.preVerificationGas)?i:o*BigInt((null!=(f=n.preVerificationGasPercentageMultiplier)?f:0)+100)/100n,e.verificationGasLimit=null!=(u=n.verificationGasLimit)?u:s*BigInt((null!=(l=n.verificationGasLimitPercentageMultiplier)?l:0)+100)/100n,e.callGasLimit=null!=(d=n.callGasLimit)?d:c*BigInt((null!=(p=n.callGasLimitPercentageMultiplier)?p:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n,Promise.resolve(y(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,c={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=c.paymasterAndData,e.callGasLimit=null!=(r=c.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=c.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=c.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=c.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=c.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})}e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var o=e.preVerificationGas,s=e.verificationGasLimit,c=e.callGasLimit,f=function(){if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit)return function(){if(null!=t){var r=new F(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;var i=e.maxFeePerGas,f=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(r.estimateUserOperationGas(e,a.entrypointAddress,n.state_override_set)).then(function(t){o<t.preVerificationGas&&(o=t.preVerificationGas),s<t.verificationGasLimit&&(s=t.verificationGasLimit),c<t.callGasLimit&&(c=t.callGasLimit),e.maxFeePerGas=i,e.maxPriorityFeePerGas=f})}throw new v("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return f&&f.then?f.then(i):i()},function(e){var t=h(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){void 0===r&&(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 c=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=c,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=h(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,function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t})}})});var i=G(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=h(e);throw new v("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),M={__proto__:null,SmartAccount:a,SafeAccountV0_2_0:w,SendUseroperationResponse:U,SmartAccountFactory:x,SafeAccountFactory:S,Bundler:F,CandidePaymaster:C,createUserOperationHash:A,createCallData:P,getFunctionSelector:g,fetchAccountNonce:m,calculateUserOperationMaxGasCost:G,get SafeModuleExecutorFunctionSelector(){return exports.SafeModuleExecutorFunctionSelector},get Operation(){return exports.Operation},ZeroAddress:D,UserOperationDummyValues:b};exports.Bundler=F,exports.CandidePaymaster=C,exports.SafeAccountFactory=S,exports.SafeAccountV0_2_0=w,exports.SendUseroperationResponse=U,exports.SmartAccount=a,exports.SmartAccountFactory=x,exports.UserOperationDummyValues=b,exports.ZeroAddress=D,exports.abstractionkit=M,exports.calculateUserOperationMaxGasCost=G,exports.createCallData=P,exports.createUserOperationHash=A,exports.fetchAccountNonce=m,exports.getFunctionSelector=g;
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 c(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(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,f(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"},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 c(t,e),t}(/*#__PURE__*/l(Error));function h(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 v("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=h(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=h(e);throw new v("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 v(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 G(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var E,D="0x0000000000000000000000000000000000000000",b={sender:D,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"},x=/*#__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}(),S=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return c(t,e),t}(x);function R(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 O(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}exports.SafeModuleExecutorFunctionSelector=void 0,(E=exports.SafeModuleExecutorFunctionSelector||(exports.SafeModuleExecutorFunctionSelector={})).executeUserOpWithErrorString="0x541d63c8",E.executeUserOp="0x7bb37428";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(O(function(){return Promise.resolve(y(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=h(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(O(function(){return Promise.resolve(y(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=h(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(O(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=h(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(O(function(){return Promise.resolve(y(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=h(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(O(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=h(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(O(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=h(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 _(e,t,r){if(!e.s){if(r instanceof L){if(!r.s)return void(r.o=_.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(_.bind(null,e,t),_.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{_(n,1,a(this.v))}catch(e){_(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?_(n,1,t?t(i):i):r?_(n,1,r(i)):_(n,2,i)}catch(e){_(n,2,e)}},n},e}();function T(e){return e instanceof L&&1&e.s}var U=/*#__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(T(i)&&(i=i.v),!i)return a;if(i.then){n=0;break}var a=r();if(a&&a.then){if(!T(a)){n=1;break}a=a.s}if(t){var o=t();if(o&&o.then&&!T(o)){n=2;break}}}var s=new L,c=_.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(f):o.then(l)).then(void 0,c),s;function f(n){a=n;do{if(t&&(o=t())&&o.then&&!T(o))return void o.then(l).then(void 0,c);if(!(i=e())||T(i)&&!i.v)return void _(s,1,a);if(i.then)return void i.then(u).then(void 0,c);T(a=r())&&(a=a.v)}while(!a||!a.then);a.then(f).then(void 0,c)}function u(e){e?(a=r())&&a.then?a.then(f).then(void 0,c):f(a):_(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,c):u(i):_(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}(),w=/*#__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}c(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.createAccountAddress=function(e,t){return void 0===t&&(t={}),r.createAccountAddressAndInitCode(e,t)[0]},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 c=null!=(n=t.threshold)?n:1,f=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 S;null!=t.safeAccountFactoryAddress&&(p=new S(t.safeAccountFactoryAddress));var v=r.createInitializerCallData(e,c,l,d);return[this.createProxyAddress(v,f,p.address,u),p.getFactoryGeneratorFunctionCallData([u,v,f])]},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,D,0,D])},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 S),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 c=r.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,c,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]),c=e.keccak256(e.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+e.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,c]).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"],[R(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])},r.decodeAccountCallData=function(t){if(t.startsWith(exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString)||t.startsWith(exports.SafeModuleExecutorFunctionSelector.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 "+exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString+" or "+exports.SafeModuleExecutorFunctionSelector.executeUserOp,{context:{callData:t}})};var i=r.prototype;return i.prependTokenPaymasterApproveToCallData=function(e,t,n,i,a){return void 0===a&&(a=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS),r.prependTokenPaymasterApproveToCallDataStatic(e,t,n,i,a)},r.prependTokenPaymasterApproveToCallDataStatic=function(t,n,i,a,o){void 0===o&&(o=r.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=r.decodeAccountCallData(t),c=s[0],f=s[1],u=s[2],l=s[3],d="";d="string"!=typeof u?(new TextDecoder).decode(u):u;var p=R([{to:n,value:0n,data:P(g("approve(address,uint256)"),["address","uint256"],[i,a]),operation:exports.Operation.Call}]),v="",h="0x8d80ff0a";if(d.startsWith(h)){var m=function(t){return e.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+t.slice(10))[0]}(d);v=m+p.slice(2)}else v=R([{to:c,value:f,data:u,operation:l}])+p.slice(2);var y=P(h,["bytes"],[v]);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 F(t),s=e.maxFeePerGas,c=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(t){return e.maxFeePerGas=s,e.maxPriorityFeePerGas=c,[BigInt(t.preVerificationGas),BigInt(t.verificationGasLimit)+30000n*BigInt(n),BigInt(t.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(t,i,a,o){void 0===o&&(o={});try{var c=function(c){var l;function d(e){var t,r,n,i;function c(e){var t,r,n,i,a,s;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 l.preVerificationGas=null!=(t=o.preVerificationGas)?t:d*BigInt(Math.floor(((null!=(r=o.preVerificationGasPercentageMultiplier)?r:0)+100)/100)),l.verificationGasLimit=null!=(n=o.verificationGasLimit)?n:A*BigInt(Math.floor(((null!=(i=o.verificationGasLimitPercentageMultiplier)?i:0)+100)/100)),l.callGasLimit=null!=(a=o.callGasLimit)?a:P*BigInt(Math.floor(((null!=(s=o.callGasLimitPercentageMultiplier)?s:0)+100)/100)),l}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");m=null!=(t=o.maxFeePerGas)?t:m*BigInt(Math.floor(((null!=(r=o.maxFeePerGasPercentageMultiplier)?r:0)+100)/100)),y=null!=(n=o.maxPriorityFeePerGas)?n:y*BigInt(Math.floor(((null!=(i=o.maxPriorityFeePerGasPercentageMultiplier)?i:0)+100)/100));var l=s({},b,{sender:f.accountAddress,nonce:u,initCode:p,callData:h,maxFeePerGas:m,maxPriorityFeePerGas:y}),d=b.preVerificationGas,A=b.verificationGasLimit,P=b.callGasLimit,g=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return function(){if(null!=a){l.callGasLimit=0n,l.verificationGasLimit=0n,l.preVerificationGas=0n;var e=l.maxFeePerGas,t=l.maxPriorityFeePerGas;return l.maxFeePerGas=0n,l.maxPriorityFeePerGas=0n,Promise.resolve(f.estimateUserOperationGas(l,a,o.state_override_set,o.numberOfSigners)).then(function(r){d=r[0],A=r[1],P=r[2],l.maxFeePerGas=e,l.maxPriorityFeePerGas=t})}throw new v("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return g&&g.then?g.then(c):c()}var p=null!=(l=o.initCode)?l:f.initCode;if((null==p||u>0n)&&(p="0x"),u<0n)throw RangeError("nonce can't be negative");var h="0x";h=null==o.callData?1==t.length?r.createAccountCallDataSingleTransaction(t[0]):r.createAccountCallDataBatchTransactions(t):o.callData;var m=b.maxFeePerGas,y=b.maxPriorityFeePerGas,A=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return function(){if(null!=i)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){0n==(m=e[0])&&(m=1n),0n==(y=e[1])&&(y=1n)});throw new v("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden")}()}();return A&&A.then?A.then(d):d()},f=this;if(t.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return function(){if(null!=i)return Promise.resolve(m(i,f.entrypointAddress,f.accountAddress)).then(function(e){u=e});throw new v("BAD_DATA","providerRpc cant't be null if nonce is not overriden")}();u=o.nonce}();return Promise.resolve(l&&l.then?l.then(c):c())}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,c={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},f={chainId:i,verifyingContract:this.safe4337ModuleAddress},u=[],l=[],p=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=p()).done;){var v=new e.Wallet(s.value),h=v.signingKey.sign(e.TypedDataEncoder.hash(f,r.EIP712_SAFE_OPERATION_TYPE,c)).serialized;u.push(v.address),l.push(h)}return r.formatEip712SignaturesToUseroperationSignature(u,l,a,o)},r.formatEip712SignaturesToUseroperationSignature=function(e,t,n,i){if(void 0===n&&(n=0n),void 0===i&&(i=0n),e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");var a=new Map;e.forEach(function(e,r){a.set(e.toLocaleLowerCase(),t[r])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return r.formatEip712SingleSignatureToUseroperationSignature(s,n,i)},r.formatEip712SingleSignatureToUseroperationSignature=function(t,r,n){if(void 0===r&&(r=0n),void 0===n&&(n=0n),r<0n)throw RangeError("validAfter can't be negative");if(n<0n)throw RangeError("validUntil can't be negative");return e.solidityPacked(["uint48","uint48","bytes"],[r,n,t])},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 U(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}w.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",w.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",w.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",w.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",w.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",w.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",w.initializerFunctionSelector="0xb63e800d",w.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],w.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=exports.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString,w.executorFunctionInputAbi=["address","uint256","bytes","uint8"],w.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}c(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=h(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(y(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens.map(function(e){return{symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)}}),paymasterMetadata:e.paymasterMetadata}})},function(e){var t=h(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(y(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=h(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.toLowerCase()===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={}),void 0===n&&(n={});try{var i=function(){return I(function(){function i(t){var i,f,u,l,d,p;if("bigint"==typeof n.preVerificationGas&&n.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof n.verificationGasLimit&&n.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof n.callGasLimit&&n.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return e.preVerificationGas=null!=(i=n.preVerificationGas)?i:o*BigInt((null!=(f=n.preVerificationGasPercentageMultiplier)?f:0)+100)/100n,e.verificationGasLimit=null!=(u=n.verificationGasLimit)?u:s*BigInt((null!=(l=n.verificationGasLimitPercentageMultiplier)?l:0)+100)/100n,e.callGasLimit=null!=(d=n.callGasLimit)?d:c*BigInt((null!=(p=n.callGasLimitPercentageMultiplier)?p:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n,Promise.resolve(y(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,c={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=c.paymasterAndData,e.callGasLimit=null!=(r=c.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=c.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=c.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=c.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=c.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})}e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var o=e.preVerificationGas,s=e.verificationGasLimit,c=e.callGasLimit,f=function(){if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit)return function(){if(null!=t){var r=new F(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;var i=e.maxFeePerGas,f=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(r.estimateUserOperationGas(e,a.entrypointAddress,n.state_override_set)).then(function(t){o<t.preVerificationGas&&(o=t.preVerificationGas),s<t.verificationGasLimit&&(s=t.verificationGasLimit),c<t.callGasLimit&&(c=t.callGasLimit),e.maxFeePerGas=i,e.maxPriorityFeePerGas=f})}throw new v("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return f&&f.then?f.then(i):i()},function(e){var t=h(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){void 0===r&&(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 c=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=c,Promise.resolve(a.createPaymasterUserOperation(t,n,{token:r},i))})})},function(e){var t=h(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,function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t})}})});var i=G(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=h(e);throw new v("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),M={__proto__:null,SmartAccount:a,SafeAccountV0_2_0:w,SendUseroperationResponse:U,SmartAccountFactory:x,SafeAccountFactory:S,Bundler:F,CandidePaymaster:C,createUserOperationHash:A,createCallData:P,getFunctionSelector:g,fetchAccountNonce:m,calculateUserOperationMaxGasCost:G,get SafeModuleExecutorFunctionSelector(){return exports.SafeModuleExecutorFunctionSelector},get Operation(){return exports.Operation},ZeroAddress:D,UserOperationDummyValues:b};exports.Bundler=F,exports.CandidePaymaster=C,exports.SafeAccountFactory=S,exports.SafeAccountV0_2_0=w,exports.SendUseroperationResponse=U,exports.SmartAccount=a,exports.SmartAccountFactory=x,exports.UserOperationDummyValues=b,exports.ZeroAddress=D,exports.abstractionkit=M,exports.calculateUserOperationMaxGasCost=G,exports.createCallData=P,exports.createUserOperationHash=A,exports.fetchAccountNonce=m,exports.getFunctionSelector=g;
package/dist/index.m.js CHANGED
@@ -1 +1 @@
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 v(){return v=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},v.apply(this,arguments)}function m(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,y(e,t)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},h(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,h(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}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 g={"-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"},G=/*#__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 m(t,e),t}(/*#__PURE__*/A(Error));function E(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 D=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(b(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new G("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=E(e);throw new G("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=E(e);throw new G("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},b=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 G(n in g?g[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 _(e,r,n){return e+t.defaultAbiCoder().encode(r,n).slice(2)}function S(e){return r(e).slice(0,10)}function L(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:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"},O=/*#__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}(),U=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return m(t,e),t}(O);function w(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(b(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new G("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=E(e);throw new G("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(b(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=E(e);throw new G("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(b(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(b(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=E(e);throw new G("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(b(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=E(e);throw new G("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(b(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=v({},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 v({},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=E(t);throw new G("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(b(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?v({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=E(t);throw new G("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 N(e){return e instanceof M&&1&e.s}var V=/*#__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 G("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 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&&!N(o))return void o.then(l).then(void 0,f);if(!(i=e())||N(i)&&!i.v)return void B(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):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}(),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}m(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.createAccountAddress=function(e,t){return void 0===t&&(t={}),i.createAccountAddressAndInitCode(e,t)[0]},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 U;null!=t.safeAccountFactoryAddress&&(p=new U(t.safeAccountFactoryAddress));var v=i.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(v,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,v,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 U),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"],[w(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])},i.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 G("BAD_DATA","Invalid calldata, should start with "+T.executeUserOpWithErrorString+" or "+T.executeUserOp,{context:{callData:e}})};var c=i.prototype;return c.prependTokenPaymasterApproveToCallData=function(e,t,r,n,a){return void 0===a&&(a=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS),i.prependTokenPaymasterApproveToCallDataStatic(e,t,r,n,a)},i.prependTokenPaymasterApproveToCallDataStatic=function(e,r,n,a,o){void 0===o&&(o=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=i.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 v=w([{to:r,value:0n,data:_(S("approve(address,uint256)"),["address","uint256"],[n,a]),operation:u.Call}]),m="",h="0x8d80ff0a";if(p.startsWith(h)){var y=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);m=y+v.slice(2)}else m=w([{to:f,value:c,data:l,operation:d}])+v.slice(2);var A=_(h,["bytes"],[m]);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),s=e.maxFeePerGas,f=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(t){return e.maxFeePerGas=s,e.maxPriorityFeePerGas=f,[BigInt(t.preVerificationGas),BigInt(t.verificationGasLimit)+20000n*BigInt(n),BigInt(t.callGasLimit)]})}catch(e){return Promise.reject(e)}},c.createUserOperation=function(e,t,r,a){void 0===a&&(a={});try{var o=function(o){var c;function u(e){var t,n,i,o;function c(e){var t,r,n,i,o,s;if("bigint"==typeof a.preVerificationGas&&a.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof a.verificationGasLimit&&a.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof a.callGasLimit&&a.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return u.preVerificationGas=null!=(t=a.preVerificationGas)?t:l*BigInt(Math.floor(((null!=(r=a.preVerificationGasPercentageMultiplier)?r:0)+100)/100)),u.verificationGasLimit=null!=(n=a.verificationGasLimit)?n:y*BigInt(Math.floor(((null!=(i=a.verificationGasLimitPercentageMultiplier)?i:0)+100)/100)),u.callGasLimit=null!=(o=a.callGasLimit)?o:A*BigInt(Math.floor(((null!=(s=a.callGasLimitPercentageMultiplier)?s:0)+100)/100)),u}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");m=null!=(t=a.maxFeePerGas)?t:m*BigInt(Math.floor(((null!=(n=a.maxFeePerGasPercentageMultiplier)?n:0)+100)/100)),h=null!=(i=a.maxPriorityFeePerGas)?i:h*BigInt(Math.floor(((null!=(o=a.maxPriorityFeePerGasPercentageMultiplier)?o:0)+100)/100));var u=v({},F,{sender:s.accountAddress,nonce:f,initCode:d,callData:p,maxFeePerGas:m,maxPriorityFeePerGas:h}),l=F.preVerificationGas,y=F.verificationGasLimit,A=F.callGasLimit,P=function(){if(null==a.preVerificationGas||null==a.verificationGasLimit||null==a.callGasLimit)return function(){if(null!=r){u.callGasLimit=0n,u.verificationGasLimit=0n,u.preVerificationGas=0n;var e=u.maxFeePerGas,t=u.maxPriorityFeePerGas;return u.maxFeePerGas=0n,u.maxPriorityFeePerGas=0n,Promise.resolve(s.estimateUserOperationGas(u,r,a.state_override_set,a.numberOfSigners)).then(function(r){l=r[0],y=r[1],A=r[2],u.maxFeePerGas=e,u.maxPriorityFeePerGas=t})}throw new G("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return P&&P.then?P.then(c):c()}var d=null!=(c=a.initCode)?c:s.initCode;if((null==d||f>0n)&&(d="0x"),f<0n)throw RangeError("nonce can't be negative");var p="0x";p=null==a.callData?1==e.length?i.createAccountCallDataSingleTransaction(e[0]):i.createAccountCallDataBatchTransactions(e):a.callData;var m=F.maxFeePerGas,h=F.maxPriorityFeePerGas,y=function(){if(null==a.maxFeePerGas||null==a.maxPriorityFeePerGas)return function(){if(null!=t)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){0n==(m=e[0])&&(m=1n),0n==(h=e[1])&&(h=1n)});throw new G("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden")}()}();return y&&y.then?y.then(u):u()},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 function(){if(null!=t)return Promise.resolve(D(t,s.entrypointAddress,s.accountAddress)).then(function(e){f=e});throw new G("BAD_DATA","providerRpc cant't be null if nonce is not overriden")}();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={chainId:r,verifyingContract:this.safe4337ModuleAddress},l=[],d=[],p=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 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))){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=p()).done;){var v=new s(o.value),m=v.signingKey.sign(f.hash(u,i.EIP712_SAFE_OPERATION_TYPE,c)).serialized;l.push(v.address),d.push(m)}return i.formatEip712SignaturesToUseroperationSignature(l,d,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");var a=new Map;e.forEach(function(e,r){a.set(e.toLocaleLowerCase(),t[r])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return i.formatEip712SingleSignatureToUseroperationSignature(s,r,n)},i.formatEip712SingleSignatureToUseroperationSignature=function(e,t,r){if(void 0===t&&(t=0n),void 0===r&&(r=0n),t<0n)throw RangeError("validAfter can't be negative");if(r<0n)throw RangeError("validUntil can't be negative");return a(["uint48","uint48","bytes"],[t,r,e])},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 V(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},i}(d);function j(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}m(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(j(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=E(e);throw new G("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?j(function(){return Promise.resolve(b(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens.map(function(e){return{symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)}}),paymasterMetadata:e.paymasterMetadata}})},function(e){var t=E(e);throw new G("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?j(function(){return Promise.resolve(b(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=E(e);throw new G("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.toLowerCase()===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={}),void 0===n&&(n={});try{var i=function(){return j(function(){function i(t){var i,c,u,l,d,p;if("bigint"==typeof n.preVerificationGas&&n.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof n.verificationGasLimit&&n.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof n.callGasLimit&&n.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return e.preVerificationGas=null!=(i=n.preVerificationGas)?i:o*BigInt((null!=(c=n.preVerificationGasPercentageMultiplier)?c:0)+100)/100n,e.verificationGasLimit=null!=(u=n.verificationGasLimit)?u:s*BigInt((null!=(l=n.verificationGasLimitPercentageMultiplier)?l:0)+100)/100n,e.callGasLimit=null!=(d=n.callGasLimit)?d:f*BigInt((null!=(p=n.callGasLimitPercentageMultiplier)?p:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n,Promise.resolve(b(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})}e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var o=e.preVerificationGas,s=e.verificationGasLimit,f=e.callGasLimit,c=function(){if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit)return function(){if(null!=t){var r=new C(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;var i=e.maxFeePerGas,c=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(r.estimateUserOperationGas(e,a.entrypointAddress,n.state_override_set)).then(function(t){o<t.preVerificationGas&&(o=t.preVerificationGas),s<t.verificationGasLimit&&(s=t.verificationGasLimit),f<t.callGasLimit&&(f=t.callGasLimit),e.maxFeePerGas=i,e.maxPriorityFeePerGas=c})}throw new G("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return c&&c.then?c.then(i):i()},function(e){var t=E(e);throw new G("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){void 0===r&&(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(j(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=E(e);throw new G("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(j(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new G("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e,function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t})}})});var i=L(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=E(e);throw new G("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),Y={__proto__:null,SmartAccount:d,SafeAccountV0_2_0:k,SendUseroperationResponse:V,SmartAccountFactory:O,SafeAccountFactory:U,Bundler:C,CandidePaymaster:z,createUserOperationHash:R,createCallData:_,getFunctionSelector:S,fetchAccountNonce:D,calculateUserOperationMaxGasCost:L,get SafeModuleExecutorFunctionSelector(){return T},get Operation(){return u},ZeroAddress:x,UserOperationDummyValues:F};export{C as Bundler,z as CandidePaymaster,u as Operation,U as SafeAccountFactory,k as SafeAccountV0_2_0,T as SafeModuleExecutorFunctionSelector,V as SendUseroperationResponse,d as SmartAccount,O as SmartAccountFactory,F as UserOperationDummyValues,x as ZeroAddress,Y as abstractionkit,L as calculateUserOperationMaxGasCost,_ as createCallData,R as createUserOperationHash,D as fetchAccountNonce,S as getFunctionSelector};
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 v(){return v=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},v.apply(this,arguments)}function m(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,y(e,t)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},h(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,h(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}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 g={"-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"},G=/*#__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 m(t,e),t}(/*#__PURE__*/A(Error));function E(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 D=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(b(e,"eth_call",i)).then(function(e){if("string"!=typeof e)throw new G("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(e)});try{return BigInt(e)}catch(e){var t=E(e);throw new G("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=E(e);throw new G("BAD_DATA","getNonce failed",{cause:t})}))}catch(e){return Promise.reject(e)}},b=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 G(n in g?g[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 _(e,r,n){return e+t.defaultAbiCoder().encode(r,n).slice(2)}function S(e){return r(e).slice(0,10)}function L(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:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"},O=/*#__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}(),U=/*#__PURE__*/function(e){function t(t){return void 0===t&&(t="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"),e.call(this,t,"0x1688f0b9",["address","bytes","uint256"])||this}return m(t,e),t}(O);function w(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(b(e.rpcUrl,"eth_chainId",[])).then(function(e){if("string"==typeof e)return e;throw new G("BAD_DATA","bundler eth_chainId rpc call failed")})},function(e){var t=E(e);throw new G("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(b(e.rpcUrl,"eth_supportedEntryPoints",[]))},function(e){var t=E(e);throw new G("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(b(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(b(n.rpcUrl,"eth_estimateUserOperationGas",[e,t,r])).then(function(e){a=e});return o&&o.then?o.then(i):i()},function(e){var t=E(e);throw new G("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(b(r.rpcUrl,"eth_sendUserOperation",[e,t]))},function(e){var t=E(e);throw new G("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(b(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=v({},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 v({},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=E(t);throw new G("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(b(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?v({},e,{blockNumber:null==e.blockNumber?null:BigInt(e.blockNumber)}):null})},function(t){var r=E(t);throw new G("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 N(e){return e instanceof M&&1&e.s}var V=/*#__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 G("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 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&&!N(o))return void o.then(l).then(void 0,f);if(!(i=e())||N(i)&&!i.v)return void B(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):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}(),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}m(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.createAccountAddress=function(e,t){return void 0===t&&(t={}),i.createAccountAddressAndInitCode(e,t)[0]},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 U;null!=t.safeAccountFactoryAddress&&(p=new U(t.safeAccountFactoryAddress));var v=i.createInitializerCallData(e,f,l,d);return[this.createProxyAddress(v,c,p.address,u),p.getFactoryGeneratorFunctionCallData([u,v,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 U),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"],[w(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])},i.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 G("BAD_DATA","Invalid calldata, should start with "+T.executeUserOpWithErrorString+" or "+T.executeUserOp,{context:{callData:e}})};var c=i.prototype;return c.prependTokenPaymasterApproveToCallData=function(e,t,r,n,a){return void 0===a&&(a=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS),i.prependTokenPaymasterApproveToCallDataStatic(e,t,r,n,a)},i.prependTokenPaymasterApproveToCallDataStatic=function(e,r,n,a,o){void 0===o&&(o=i.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var s=i.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 v=w([{to:r,value:0n,data:_(S("approve(address,uint256)"),["address","uint256"],[n,a]),operation:u.Call}]),m="",h="0x8d80ff0a";if(p.startsWith(h)){var y=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);m=y+v.slice(2)}else m=w([{to:f,value:c,data:l,operation:d}])+v.slice(2);var A=_(h,["bytes"],[m]);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),s=e.maxFeePerGas,f=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(t){return e.maxFeePerGas=s,e.maxPriorityFeePerGas=f,[BigInt(t.preVerificationGas),BigInt(t.verificationGasLimit)+30000n*BigInt(n),BigInt(t.callGasLimit)]})}catch(e){return Promise.reject(e)}},c.createUserOperation=function(e,t,r,a){void 0===a&&(a={});try{var o=function(o){var c;function u(e){var t,n,i,o;function c(e){var t,r,n,i,o,s;if("bigint"==typeof a.preVerificationGas&&a.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof a.verificationGasLimit&&a.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof a.callGasLimit&&a.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return u.preVerificationGas=null!=(t=a.preVerificationGas)?t:l*BigInt(Math.floor(((null!=(r=a.preVerificationGasPercentageMultiplier)?r:0)+100)/100)),u.verificationGasLimit=null!=(n=a.verificationGasLimit)?n:y*BigInt(Math.floor(((null!=(i=a.verificationGasLimitPercentageMultiplier)?i:0)+100)/100)),u.callGasLimit=null!=(o=a.callGasLimit)?o:A*BigInt(Math.floor(((null!=(s=a.callGasLimitPercentageMultiplier)?s:0)+100)/100)),u}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");m=null!=(t=a.maxFeePerGas)?t:m*BigInt(Math.floor(((null!=(n=a.maxFeePerGasPercentageMultiplier)?n:0)+100)/100)),h=null!=(i=a.maxPriorityFeePerGas)?i:h*BigInt(Math.floor(((null!=(o=a.maxPriorityFeePerGasPercentageMultiplier)?o:0)+100)/100));var u=v({},F,{sender:s.accountAddress,nonce:f,initCode:d,callData:p,maxFeePerGas:m,maxPriorityFeePerGas:h}),l=F.preVerificationGas,y=F.verificationGasLimit,A=F.callGasLimit,P=function(){if(null==a.preVerificationGas||null==a.verificationGasLimit||null==a.callGasLimit)return function(){if(null!=r){u.callGasLimit=0n,u.verificationGasLimit=0n,u.preVerificationGas=0n;var e=u.maxFeePerGas,t=u.maxPriorityFeePerGas;return u.maxFeePerGas=0n,u.maxPriorityFeePerGas=0n,Promise.resolve(s.estimateUserOperationGas(u,r,a.state_override_set,a.numberOfSigners)).then(function(r){l=r[0],y=r[1],A=r[2],u.maxFeePerGas=e,u.maxPriorityFeePerGas=t})}throw new G("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return P&&P.then?P.then(c):c()}var d=null!=(c=a.initCode)?c:s.initCode;if((null==d||f>0n)&&(d="0x"),f<0n)throw RangeError("nonce can't be negative");var p="0x";p=null==a.callData?1==e.length?i.createAccountCallDataSingleTransaction(e[0]):i.createAccountCallDataBatchTransactions(e):a.callData;var m=F.maxFeePerGas,h=F.maxPriorityFeePerGas,y=function(){if(null==a.maxFeePerGas||null==a.maxPriorityFeePerGas)return function(){if(null!=t)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){0n==(m=e[0])&&(m=1n),0n==(h=e[1])&&(h=1n)});throw new G("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden")}()}();return y&&y.then?y.then(u):u()},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 function(){if(null!=t)return Promise.resolve(D(t,s.entrypointAddress,s.accountAddress)).then(function(e){f=e});throw new G("BAD_DATA","providerRpc cant't be null if nonce is not overriden")}();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={chainId:r,verifyingContract:this.safe4337ModuleAddress},l=[],d=[],p=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 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))){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=p()).done;){var v=new s(o.value),m=v.signingKey.sign(f.hash(u,i.EIP712_SAFE_OPERATION_TYPE,c)).serialized;l.push(v.address),d.push(m)}return i.formatEip712SignaturesToUseroperationSignature(l,d,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");var a=new Map;e.forEach(function(e,r){a.set(e.toLocaleLowerCase(),t[r])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return i.formatEip712SingleSignatureToUseroperationSignature(s,r,n)},i.formatEip712SingleSignatureToUseroperationSignature=function(e,t,r){if(void 0===t&&(t=0n),void 0===r&&(r=0n),t<0n)throw RangeError("validAfter can't be negative");if(r<0n)throw RangeError("validUntil can't be negative");return a(["uint48","uint48","bytes"],[t,r,e])},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 V(e,n,r.entrypointAddress)})}catch(e){return Promise.reject(e)}},i}(d);function j(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}m(t,e);var r=t.prototype;return r.initialize=function(){try{var e=this;return Promise.resolve(j(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=E(e);throw new G("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?j(function(){return Promise.resolve(b(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens.map(function(e){return{symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)}}),paymasterMetadata:e.paymasterMetadata}})},function(e){var t=E(e);throw new G("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?j(function(){return Promise.resolve(b(e.rpcUrl,"pm_supportedEntryPoint",[]))},function(e){var t=E(e);throw new G("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.toLowerCase()===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={}),void 0===n&&(n={});try{var i=function(){return j(function(){function i(t){var i,c,u,l,d,p;if("bigint"==typeof n.preVerificationGas&&n.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof n.verificationGasLimit&&n.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof n.callGasLimit&&n.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return e.preVerificationGas=null!=(i=n.preVerificationGas)?i:o*BigInt((null!=(c=n.preVerificationGasPercentageMultiplier)?c:0)+100)/100n,e.verificationGasLimit=null!=(u=n.verificationGasLimit)?u:s*BigInt((null!=(l=n.verificationGasLimitPercentageMultiplier)?l:0)+100)/100n,e.callGasLimit=null!=(d=n.callGasLimit)?d:f*BigInt((null!=(p=n.callGasLimitPercentageMultiplier)?p:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n,Promise.resolve(b(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})}e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var o=e.preVerificationGas,s=e.verificationGasLimit,f=e.callGasLimit,c=function(){if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit)return function(){if(null!=t){var r=new C(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;var i=e.maxFeePerGas,c=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(r.estimateUserOperationGas(e,a.entrypointAddress,n.state_override_set)).then(function(t){o<t.preVerificationGas&&(o=t.preVerificationGas),s<t.verificationGasLimit&&(s=t.verificationGasLimit),f<t.callGasLimit&&(f=t.callGasLimit),e.maxFeePerGas=i,e.maxPriorityFeePerGas=c})}throw new G("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return c&&c.then?c.then(i):i()},function(e){var t=E(e);throw new G("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){void 0===r&&(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(j(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=E(e);throw new G("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}))}catch(e){return Promise.reject(e)}},r.calculateUserOperationErc20TokenMaxGasCost=function(e,t){try{var r=this;return Promise.resolve(j(function(){return Promise.resolve(r.getSupportedERC20TokenData(t)).then(function(n){if(null==n)return Promise.resolve(r.getSupportedERC20TokensAndPaymasterMetadata()).then(function(e){throw new G("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(e,function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t})}})});var i=L(e);return n.exchangeRate*i/BigInt(Math.pow(10,18))})},function(e){var t=E(e);throw new G("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}))}catch(e){return Promise.reject(e)}},t}(function(){}),Y={__proto__:null,SmartAccount:d,SafeAccountV0_2_0:k,SendUseroperationResponse:V,SmartAccountFactory:O,SafeAccountFactory:U,Bundler:C,CandidePaymaster:z,createUserOperationHash:R,createCallData:_,getFunctionSelector:S,fetchAccountNonce:D,calculateUserOperationMaxGasCost:L,get SafeModuleExecutorFunctionSelector(){return T},get Operation(){return u},ZeroAddress:x,UserOperationDummyValues:F};export{C as Bundler,z as CandidePaymaster,u as Operation,U as SafeAccountFactory,k as SafeAccountV0_2_0,T as SafeModuleExecutorFunctionSelector,V as SendUseroperationResponse,d as SmartAccount,O as SmartAccountFactory,F as UserOperationDummyValues,x as ZeroAddress,Y as abstractionkit,L as calculateUserOperationMaxGasCost,_ as createCallData,R as createUserOperationHash,D as fetchAccountNonce,S as getFunctionSelector};
@@ -1 +1 @@
1
- import{keccak256 as e,AbiCoder as t,id as a,JsonRpcProvider as i,getBytes as r,solidityPacked as n,solidityPackedKeccak256 as s,Wallet as o,TypedDataEncoder as c}from"ethers";import*as f from"isomorphic-unfetch";class l{constructor(e){this.accountAddress=void 0,this.accountAddress=e}}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(e[i]=a[i])}return e},d.apply(this,arguments)}var u,p;l.proxyByteCode=void 0,l.initializerFunctionSelector=void 0,l.initializerFunctionInputAbi=void 0,l.executorFunctionSelector=void 0,l.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"}(p||(p={}));const 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"};class m extends Error{constructor(e,t,a={}){const{cause:i,errno:r,context:n}=a;super(t,{cause:i}),this.code=void 0,this.context=void 0,this.errno=void 0,this.name=this.constructor.name,this.code=e,this.errno=r,this.context=n}}function y(e){if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error(`This value was thrown as is, not through an Error: ${t}`)}function A(a,i,r){const n=e(function(a){const i=[a.sender,a.nonce,e(a.initCode),e(a.callData),a.callGasLimit,a.verificationGasLimit,a.preVerificationGas,a.maxFeePerGas,a.maxPriorityFeePerGas,e(a.paymasterAndData)];return t.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],i)}(a)),s=t.defaultAbiCoder().encode(["bytes32","address","uint256"],[n,i,r]);return e(s)}function g(e,a,i){return e+t.defaultAbiCoder().encode(a,i).slice(2)}async function G(e,t,a){const i=f.default||f,r={method:"POST",body:JSON.stringify({method:t,params:a,id:(new Date).getTime(),jsonrpc:"2.0"},(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t),redirect:"follow"},n=await i(e,r),s=await n.json();if("result"in s)return s.result;{const t=s.error,a=String(t.code);throw new m(a in h?h[a]:"UNKNOWN_ERROR",t.message,{errno:t.code,context:{url:e,requestOptions:JSON.stringify(r)}})}}function E(e){return a(e).slice(0,10)}async function D(e,t,a,i=0){const r=[{from:"0x0000000000000000000000000000000000000000",to:t,data:g(E("getNonce(address,uint192)"),["address","uint192"],[a,i])},"latest"];try{const t=await G(e,"eth_call",r);if("string"!=typeof t)throw new m("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(t)});try{return BigInt(t)}catch(e){const t=y(e);throw new m("BAD_DATA","getNonce returned ill formed data",{cause:t})}}catch(e){const t=y(e);throw new m("BAD_DATA","getNonce failed",{cause:t})}}function P(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}const R="0x0000000000000000000000000000000000000000",w={sender:R,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"};class b{constructor(e,t,a){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=a}getFactoryGeneratorFunctionCallData(e){const t=g(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)}}class v extends b{constructor(e="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"){super(e,"0x1688f0b9",["address","bytes","uint256"])}}var L;function x(e){return"0x"+e.map(e=>function(e){var t;const a=null!=(t=e.operation)?t:u.Call,i=r(e.data);return n(["uint8","address","uint256","uint256","bytes"],[a,e.to,e.value,i.length,i]).slice(2)}(e)).join("")}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(L||(L={}));class T{constructor(e){this.rpcUrl=void 0,this.rpcUrl=e}async chainId(){try{const e=await G(this.rpcUrl,"eth_chainId",[]);if("string"==typeof e)return e;throw new m("BAD_DATA","bundler eth_chainId rpc call failed")}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}}async supportedEntryPoints(){try{return await G(this.rpcUrl,"eth_supportedEntryPoints",[])}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}}async estimateUserOperationGas(e,t,a){try{let i={};i=void 0===a?await G(this.rpcUrl,"eth_estimateUserOperationGas",[e,t]):await G(this.rpcUrl,"eth_estimateUserOperationGas",[e,t,a]);const r=i;return{callGasLimit:BigInt(r.callGasLimit),preVerificationGas:BigInt(r.preVerificationGas),verificationGasLimit:BigInt(r.verificationGasLimit)}}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}}async sendUserOperation(e,t){try{return await G(this.rpcUrl,"eth_sendUserOperation",[e,t])}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}}async getUserOperationReceipt(e){try{const t=await G(this.rpcUrl,"eth_getUserOperationReceipt",[e]);if(null!=t){const e=d({},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 d({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:e})}return null}catch(t){const a=y(t);throw new m("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:a,context:{useroperationhash:e}})}}async getUserOperationByHash(e){try{const t=await G(this.rpcUrl,"eth_getUserOperationByHash",[e]);return null!=t?d({},t,{blockNumber:null==t.blockNumber?null:BigInt(t.blockNumber)}):null}catch(t){const a=y(t);throw new m("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:a,context:{useroperationhash:e}})}}}class F{constructor(e,t,a){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=a}delay(e){return new Promise(t=>setTimeout(t,e))}async included(e=180,t=2){if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");let a=0;for(;a<=e;){await this.delay(1e3*t);const e=await this.bundler.getUserOperationReceipt(this.userOperationHash);if(null!=e)return e;a++}throw new m("TIMEOUT","can't find useroperation",{context:this.userOperationHash})}}class S extends l{constructor(e,t=S.DEFAULT_SAFE_4337_MODULE_ADDRESS,a=S.DEFAULT_ENTRYPOINT_ADDRESS){super(e),this.entrypointAddress=void 0,this.safe4337ModuleAddress=void 0,this.initCode=void 0,this.entrypointAddress=a,this.safe4337ModuleAddress=t,this.initCode=null}static initializeNewAccount(e,t={}){const[a,i]=S.createAccountAddressAndInitCode(e,t),r=new S(a);return r.initCode=i,r}static createAccountAddress(e,t={}){const[a]=S.createAccountAddressAndInitCode(e,t);return a}static createAccountAddressAndInitCode(e,t={}){var a,i,r,n,s;if(e.length<1)throw RangeError("There should be at least one owner");const o=null!=(a=t.threshold)?a:1,c=null!=(i=t.c2Nonce)?i:0n,f=null!=(r=t.singletonAddress)?r:S.DEFAULT_SINGLETON_ADDRESS,l=null!=(n=t.safe4337ModuleAddress)?n:S.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:S.DEFAULT_ADD_MODULE_LIB_ADDRESS;let u=new v;null!=t.safeAccountFactoryAddress&&(u=new v(t.safeAccountFactoryAddress));const p=S.createInitializerCallData(e,o,l,d);return[this.createProxyAddress(p,c,u.address,f),u.getFactoryGeneratorFunctionCallData([f,p,c])]}static createInitializerCallData(e,t,a=S.DEFAULT_SAFE_4337_MODULE_ADDRESS,i=S.DEFAULT_ADD_MODULE_LIB_ADDRESS){if(e.length<1)throw RangeError("There should be at least one owner");if(t<1)throw RangeError("threshold should be at least one");if(t>e.length)throw RangeError("threshold can't be larger than number of owners");const r=g("0x8d0dc49f",["address[]"],[[a]]);return g(S.initializerFunctionSelector,S.initializerFunctionInputAbi,[e,t,i,r,a,R,0,R])}static createInitCode(e,t=1,a=0n,i=S.DEFAULT_SINGLETON_ADDRESS,r=new v,n=S.DEFAULT_SAFE_4337_MODULE_ADDRESS,s=S.DEFAULT_ADD_MODULE_LIB_ADDRESS){if(e.length<1)throw RangeError("There should be at least one owner");if(t<1)throw RangeError("threshold should be at least one");if(t>e.length)throw RangeError("threshold can't be larger than number of owners");if(a<0n)throw RangeError("c2Nonce can't be negative");const o=S.createInitializerCallData(e,t,n,s);return r.getFactoryGeneratorFunctionCallData([i,o,a])}static createProxyAddress(a,i,r,o){if(i<0n)throw RangeError("c2Nonce can't be negative");const c=t.defaultAbiCoder(),f=e(n(["bytes32","uint256"],[e(a),i])),l=c.encode(["uint256"],[o]),d=e(n(["bytes","bytes"],[this.proxyByteCode,l]));return"0x"+s(["bytes1","address","bytes32","bytes32"],["0xff",r,f,d]).slice(-40)}static createAccountCallDataSingleTransaction(e){var t,a,i;const r=null!=(t=e.value)?t:0,n=null!=(a=e.data)?a:"0x",s=null!=(i=e.operation)?i:u.Call;return S.createAccountCallData(e.to,r,n,s)}static createAccountCallDataBatchTransactions(e,t=S.DEFAULT_MULTISEND_CONTRACT_ADDRESS){if(e.length<1)throw RangeError("There should be at least one metaTransaction");const a=g("0x8d80ff0a",["bytes"],[x(e)]);return S.createAccountCallData(t,0n,a,u.Delegate)}static createAccountCallData(e,t,a,i,r=S.DEFAULT_EXECUTOR_FUCNTION_SELECTOR){return g(r,S.executorFunctionInputAbi,[e,t,a,i])}static decodeAccountCallData(e){if(e.startsWith(L.executeUserOpWithErrorString)||e.startsWith(L.executeUserOp)){const a=t.defaultAbiCoder(),i="0x"+e.slice(10),r=a.decode(["address","uint256","bytes","uint8"],i);return[r[0],BigInt(r[1]),r[2],Number(r[3])]}throw new m("BAD_DATA","Invalid calldata, should start with "+L.executeUserOpWithErrorString+" or "+L.executeUserOp,{context:{callData:e}})}prependTokenPaymasterApproveToCallData(e,t,a,i,r=S.DEFAULT_MULTISEND_CONTRACT_ADDRESS){return S.prependTokenPaymasterApproveToCallDataStatic(e,t,a,i,r)}static prependTokenPaymasterApproveToCallDataStatic(e,a,i,r,n=S.DEFAULT_MULTISEND_CONTRACT_ADDRESS){const[s,o,c,f]=S.decodeAccountCallData(e);let l="";l="string"!=typeof c?(new TextDecoder).decode(c):c;const d=x([{to:a,value:0n,data:g(E("approve(address,uint256)"),["address","uint256"],[i,r]),operation:u.Call}]);let p="";const h="0x8d80ff0a";if(l.startsWith(h)){const e=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(l);p=e+d.slice(2)}else p=x([{to:s,value:o,data:c,operation:f}])+d.slice(2);const m=g(h,["bytes"],[p]);return S.createAccountCallData(n,0n,m,u.Delegate)}async estimateUserOperationGas(e,t,a,i=1){if(i<1n)throw RangeError("numberOfSigners can't be less than 1");let r="";for(let e=0;e<i;e++)r+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+r;const n=new T(t),s=e.maxFeePerGas,o=e.maxPriorityFeePerGas;e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n;const c=await n.estimateUserOperationGas(e,this.entrypointAddress,a);return e.maxFeePerGas=s,e.maxPriorityFeePerGas=o,[BigInt(c.preVerificationGas),BigInt(c.verificationGasLimit)+20000n*BigInt(i),BigInt(c.callGasLimit)]}async createUserOperation(e,t,a,r={}){var n,s,o,c,f,l,u,h,y,A,g;if(e.length<1)throw RangeError("There should be at least one transaction");let G=0n;if(null==r.nonce){if(null==t)throw new m("BAD_DATA","providerRpc cant't be null if nonce is not overriden");G=await D(t,this.entrypointAddress,this.accountAddress)}else G=r.nonce;let E=null!=(n=r.initCode)?n:this.initCode;if((null==E||G>0n)&&(E="0x"),G<0n)throw RangeError("nonce can't be negative");let P="0x";P=null==r.callData?1==e.length?S.createAccountCallDataSingleTransaction(e[0]):S.createAccountCallDataBatchTransactions(e):r.callData;let R=w.maxFeePerGas,b=w.maxPriorityFeePerGas;if(null==r.maxFeePerGas||null==r.maxPriorityFeePerGas){if(null==t)throw new m("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden");[R,b]=await async function(e,t=p.Medium){const a=new i(e),r=await a.getFeeData();return[BigInt(Math.ceil(Number(r.maxFeePerGas)*t)),BigInt(Math.ceil(Number(r.maxPriorityFeePerGas)*t))]}(t),0n==R&&(R=1n),0n==b&&(b=1n)}if("bigint"==typeof r.maxFeePerGas&&r.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof r.maxPriorityFeePerGas&&r.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");R=null!=(s=r.maxFeePerGas)?s:R*BigInt(Math.floor(((null!=(o=r.maxFeePerGasPercentageMultiplier)?o:0)+100)/100)),b=null!=(c=r.maxPriorityFeePerGas)?c:b*BigInt(Math.floor(((null!=(f=r.maxPriorityFeePerGasPercentageMultiplier)?f:0)+100)/100));const v=d({},w,{sender:this.accountAddress,nonce:G,initCode:E,callData:P,maxFeePerGas:R,maxPriorityFeePerGas:b});let L=w.preVerificationGas,x=w.verificationGasLimit,T=w.callGasLimit;if(null==r.preVerificationGas||null==r.verificationGasLimit||null==r.callGasLimit){if(null==a)throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{v.callGasLimit=0n,v.verificationGasLimit=0n,v.preVerificationGas=0n;const e=v.maxFeePerGas,t=v.maxPriorityFeePerGas;v.maxFeePerGas=0n,v.maxPriorityFeePerGas=0n,[L,x,T]=await this.estimateUserOperationGas(v,a,r.state_override_set,r.numberOfSigners),v.maxFeePerGas=e,v.maxPriorityFeePerGas=t}}if("bigint"==typeof r.preVerificationGas&&r.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof r.verificationGasLimit&&r.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof r.callGasLimit&&r.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return v.preVerificationGas=null!=(l=r.preVerificationGas)?l:L*BigInt(Math.floor(((null!=(u=r.preVerificationGasPercentageMultiplier)?u:0)+100)/100)),v.verificationGasLimit=null!=(h=r.verificationGasLimit)?h:x*BigInt(Math.floor(((null!=(y=r.verificationGasLimitPercentageMultiplier)?y:0)+100)/100)),v.callGasLimit=null!=(A=r.callGasLimit)?A:T*BigInt(Math.floor(((null!=(g=r.callGasLimitPercentageMultiplier)?g:0)+100)/100)),v}signUserOperation(e,t,a,i=0n,r=0n){if(t.length<1)throw RangeError("There should be at least one privateKey");if(a<0n)throw RangeError("chainId can't be negative");if(i<0n)throw RangeError("validAfter can't be negative");if(r<0n)throw RangeError("validUntil can't be negative");const n={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:i,validUntil:r,entryPoint:this.entrypointAddress},s={chainId:a,verifyingContract:this.safe4337ModuleAddress},f=[],l=[];for(const e of t){const t=new o(e),a=t.signingKey.sign(c.hash(s,S.EIP712_SAFE_OPERATION_TYPE,n)).serialized;f.push(t.address),l.push(a)}return S.formatEip712SignaturesToUseroperationSignature(f,l,i,r)}static formatEip712SignaturesToUseroperationSignature(e,t,a=0n,i=0n){if(e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");const r=new Map;e.forEach((e,a)=>{r.set(e.toLocaleLowerCase(),t[a])});const n=new Map(Array.from(r).sort()),s="0x"+Array.from(n.values()).reduce((e,t)=>e+t.slice(2),"");return S.formatEip712SingleSignatureToUseroperationSignature(s,a,i)}static formatEip712SingleSignatureToUseroperationSignature(e,t=0n,a=0n){if(t<0n)throw RangeError("validAfter can't be negative");if(a<0n)throw RangeError("validUntil can't be negative");return n(["uint48","uint48","bytes"],[t,a,e])}async sendUserOperation(e,t){const a=new T(t),i=await a.sendUserOperation(e,this.entrypointAddress);return new F(i,a,this.entrypointAddress)}}S.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",S.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",S.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",S.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",S.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",S.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",S.initializerFunctionSelector="0xb63e800d",S.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],S.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=L.executeUserOpWithErrorString,S.executorFunctionInputAbi=["address","uint256","bytes","uint8"],S.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"}]};class _{}class U extends _{constructor(e){super(),this.rpcUrl=void 0,this.entrypointAddress=void 0,this.supportedTokens=void 0,this.paymasterMetadata=void 0,this.rpcUrl=e}async initialize(){try{this.entrypointAddress=await this.getSupportedEntrypoint();const e=await this.getSupportedERC20TokensAndPaymasterMetadata();return this.supportedTokens=e.tokens,this.paymasterMetadata=e.paymasterMetadata,null}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}}async getPaymasterMetaData(){return null==this.paymasterMetadata&&await this.initialize(),this.paymasterMetadata}async getSupportedERC20TokensAndPaymasterMetadata(){if(null!=this.supportedTokens&&null!=this.paymasterMetadata)return{tokens:this.supportedTokens,paymasterMetadata:this.paymasterMetadata};try{const e=await G(this.rpcUrl,"pm_supportedERC20Tokens",[]);return{tokens:e.tokens.map(e=>({symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)})),paymasterMetadata:e.paymasterMetadata}}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}}async getSupportedEntrypoint(){if(null!=this.entrypointAddress)return this.entrypointAddress;try{return await G(this.rpcUrl,"pm_supportedEntryPoint",[])}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}}async isSupportedERC20Token(e){return null!=this.entrypointAddress&&null!=this.supportedTokens&&null!=this.paymasterMetadata||await this.initialize(),!!this.supportedTokens.find(t=>t.address.toLowerCase()===e.toLowerCase())}async getSupportedERC20TokenData(e){null!=this.entrypointAddress&&null!=this.supportedTokens&&null!=this.paymasterMetadata||await this.initialize();const t=this.supportedTokens.find(t=>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}async createPaymasterUserOperation(e,t,a={},i={}){null!=this.entrypointAddress&&null!=this.supportedTokens&&null!=this.paymasterMetadata||await this.initialize();try{var r,n,s,o,c,f,l,d,u,p,h;e.paymasterAndData=this.paymasterMetadata.dummyPaymasterAndData;let y=e.preVerificationGas,A=e.verificationGasLimit,g=e.callGasLimit;if(null==i.preVerificationGas||null==i.verificationGasLimit||null==i.callGasLimit){if(null==t)throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{const a=new T(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;const r=e.maxFeePerGas,n=e.maxPriorityFeePerGas;e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n;const s=await a.estimateUserOperationGas(e,this.entrypointAddress,i.state_override_set);y<s.preVerificationGas&&(y=s.preVerificationGas),A<s.verificationGasLimit&&(A=s.verificationGasLimit),g<s.callGasLimit&&(g=s.callGasLimit),e.maxFeePerGas=r,e.maxPriorityFeePerGas=n}}if("bigint"==typeof i.preVerificationGas&&i.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof i.verificationGasLimit&&i.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof i.callGasLimit&&i.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");e.preVerificationGas=null!=(r=i.preVerificationGas)?r:y*BigInt((null!=(n=i.preVerificationGasPercentageMultiplier)?n:0)+100)/100n,e.verificationGasLimit=null!=(s=i.verificationGasLimit)?s:A*BigInt((null!=(o=i.verificationGasLimitPercentageMultiplier)?o:0)+100)/100n,e.callGasLimit=null!=(c=i.callGasLimit)?c:g*BigInt((null!=(f=i.callGasLimitPercentageMultiplier)?f:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n;const E=await G(this.rpcUrl,"pm_sponsorUserOperation",[e,this.entrypointAddress,a]),D={paymasterAndData:E.paymasterAndData,callGasLimit:null==E.callGasLimit?void 0:BigInt(E.callGasLimit),preVerificationGas:null==E.preVerificationGas?void 0:BigInt(E.preVerificationGas),verificationGasLimit:null==E.verificationGasLimit?void 0:BigInt(E.verificationGasLimit),maxFeePerGas:null==E.maxFeePerGas?void 0:BigInt(E.maxFeePerGas),maxPriorityFeePerGas:null==E.maxPriorityFeePerGas?void 0:BigInt(E.maxPriorityFeePerGas)};return e.paymasterAndData=D.paymasterAndData,e.callGasLimit=null!=(l=D.callGasLimit)?l:e.callGasLimit,e.preVerificationGas=null!=(d=D.preVerificationGas)?d:e.preVerificationGas,e.verificationGasLimit=null!=(u=D.verificationGasLimit)?u:e.verificationGasLimit,e.maxFeePerGas=null!=(p=D.maxFeePerGas)?p:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(h=D.maxPriorityFeePerGas)?h:e.maxPriorityFeePerGas,e}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})}}async createSponsorPaymasterUserOperation(e,t,a={}){return await this.createPaymasterUserOperation(e,t,{},a)}async createTokenPaymasterUserOperation(e,t,a,i,r={}){try{const n=2n*await this.calculateUserOperationErc20TokenMaxGasCost(t,a);let s=await this.getPaymasterMetaData();const o=e.prependTokenPaymasterApproveToCallData(t.callData,a,s.address,n);return t.callData=o,await this.createPaymasterUserOperation(t,i,{token:a},r)}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}}async calculateUserOperationErc20TokenMaxGasCost(e,t){try{const a=await this.getSupportedERC20TokenData(t);if(null==a)throw new m("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(await this.getSupportedERC20TokensAndPaymasterMetadata(),(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t)}});{const t=P(e);return a.exchangeRate*t/BigInt(10**18)}}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}}}var O={__proto__:null,SmartAccount:l,SafeAccountV0_2_0:S,SendUseroperationResponse:F,SmartAccountFactory:b,SafeAccountFactory:v,Bundler:T,CandidePaymaster:U,createUserOperationHash:A,createCallData:g,getFunctionSelector:E,fetchAccountNonce:D,calculateUserOperationMaxGasCost:P,get SafeModuleExecutorFunctionSelector(){return L},get Operation(){return u},ZeroAddress:R,UserOperationDummyValues:w};export{T as Bundler,U as CandidePaymaster,u as Operation,v as SafeAccountFactory,S as SafeAccountV0_2_0,L as SafeModuleExecutorFunctionSelector,F as SendUseroperationResponse,l as SmartAccount,b as SmartAccountFactory,w as UserOperationDummyValues,R as ZeroAddress,O as abstractionkit,P as calculateUserOperationMaxGasCost,g as createCallData,A as createUserOperationHash,D as fetchAccountNonce,E as getFunctionSelector};
1
+ import{keccak256 as e,AbiCoder as t,id as a,JsonRpcProvider as i,getBytes as r,solidityPacked as n,solidityPackedKeccak256 as s,Wallet as o,TypedDataEncoder as c}from"ethers";import*as f from"isomorphic-unfetch";class l{constructor(e){this.accountAddress=void 0,this.accountAddress=e}}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(e[i]=a[i])}return e},d.apply(this,arguments)}var u,p;l.proxyByteCode=void 0,l.initializerFunctionSelector=void 0,l.initializerFunctionInputAbi=void 0,l.executorFunctionSelector=void 0,l.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"}(p||(p={}));const 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"};class m extends Error{constructor(e,t,a={}){const{cause:i,errno:r,context:n}=a;super(t,{cause:i}),this.code=void 0,this.context=void 0,this.errno=void 0,this.name=this.constructor.name,this.code=e,this.errno=r,this.context=n}}function y(e){if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch(e){}return new Error(`This value was thrown as is, not through an Error: ${t}`)}function A(a,i,r){const n=e(function(a){const i=[a.sender,a.nonce,e(a.initCode),e(a.callData),a.callGasLimit,a.verificationGasLimit,a.preVerificationGas,a.maxFeePerGas,a.maxPriorityFeePerGas,e(a.paymasterAndData)];return t.defaultAbiCoder().encode(["address","uint256","bytes32","bytes32","uint256","uint256","uint256","uint256","uint256","bytes32"],i)}(a)),s=t.defaultAbiCoder().encode(["bytes32","address","uint256"],[n,i,r]);return e(s)}function g(e,a,i){return e+t.defaultAbiCoder().encode(a,i).slice(2)}async function G(e,t,a){const i=f.default||f,r={method:"POST",body:JSON.stringify({method:t,params:a,id:(new Date).getTime(),jsonrpc:"2.0"},(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t),redirect:"follow"},n=await i(e,r),s=await n.json();if("result"in s)return s.result;{const t=s.error,a=String(t.code);throw new m(a in h?h[a]:"UNKNOWN_ERROR",t.message,{errno:t.code,context:{url:e,requestOptions:JSON.stringify(r)}})}}function E(e){return a(e).slice(0,10)}async function D(e,t,a,i=0){const r=[{from:"0x0000000000000000000000000000000000000000",to:t,data:g(E("getNonce(address,uint192)"),["address","uint192"],[a,i])},"latest"];try{const t=await G(e,"eth_call",r);if("string"!=typeof t)throw new m("BAD_DATA","getNonce returned ill formed data",{context:JSON.stringify(t)});try{return BigInt(t)}catch(e){const t=y(e);throw new m("BAD_DATA","getNonce returned ill formed data",{cause:t})}}catch(e){const t=y(e);throw new m("BAD_DATA","getNonce failed",{cause:t})}}function P(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}const R="0x0000000000000000000000000000000000000000",w={sender:R,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"};class b{constructor(e,t,a){this.address=void 0,this.generatorFunctionSelector=void 0,this.generatorFunctionInputAbi=void 0,this.address=e,this.generatorFunctionSelector=t,this.generatorFunctionInputAbi=a}getFactoryGeneratorFunctionCallData(e){const t=g(this.generatorFunctionSelector,this.generatorFunctionInputAbi,e);return this.address+t.slice(2)}}class v extends b{constructor(e="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"){super(e,"0x1688f0b9",["address","bytes","uint256"])}}var L;function x(e){return"0x"+e.map(e=>function(e){var t;const a=null!=(t=e.operation)?t:u.Call,i=r(e.data);return n(["uint8","address","uint256","uint256","bytes"],[a,e.to,e.value,i.length,i]).slice(2)}(e)).join("")}!function(e){e.executeUserOpWithErrorString="0x541d63c8",e.executeUserOp="0x7bb37428"}(L||(L={}));class T{constructor(e){this.rpcUrl=void 0,this.rpcUrl=e}async chainId(){try{const e=await G(this.rpcUrl,"eth_chainId",[]);if("string"==typeof e)return e;throw new m("BAD_DATA","bundler eth_chainId rpc call failed")}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_chainId rpc call failed",{cause:t})}}async supportedEntryPoints(){try{return await G(this.rpcUrl,"eth_supportedEntryPoints",[])}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_supportedEntryPoints rpc call failed",{cause:t})}}async estimateUserOperationGas(e,t,a){try{let i={};i=void 0===a?await G(this.rpcUrl,"eth_estimateUserOperationGas",[e,t]):await G(this.rpcUrl,"eth_estimateUserOperationGas",[e,t,a]);const r=i;return{callGasLimit:BigInt(r.callGasLimit),preVerificationGas:BigInt(r.preVerificationGas),verificationGasLimit:BigInt(r.verificationGasLimit)}}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_estimateUserOperationGas rpc call failed",{cause:t})}}async sendUserOperation(e,t){try{return await G(this.rpcUrl,"eth_sendUserOperation",[e,t])}catch(e){const t=y(e);throw new m("BUNDLER_ERROR","bundler eth_sendUserOperation rpc call failed",{cause:t})}}async getUserOperationReceipt(e){try{const t=await G(this.rpcUrl,"eth_getUserOperationReceipt",[e]);if(null!=t){const e=d({},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 d({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt:e})}return null}catch(t){const a=y(t);throw new m("BUNDLER_ERROR","bundler eth_getUserOperationReceipt rpc call failed",{cause:a,context:{useroperationhash:e}})}}async getUserOperationByHash(e){try{const t=await G(this.rpcUrl,"eth_getUserOperationByHash",[e]);return null!=t?d({},t,{blockNumber:null==t.blockNumber?null:BigInt(t.blockNumber)}):null}catch(t){const a=y(t);throw new m("BUNDLER_ERROR","bundler eth_getUserOperationByHash rpc call failed",{cause:a,context:{useroperationhash:e}})}}}class F{constructor(e,t,a){this.userOperationHash=void 0,this.bundler=void 0,this.entrypointAddress=void 0,this.bundler=t,this.userOperationHash=e,this.entrypointAddress=a}delay(e){return new Promise(t=>setTimeout(t,e))}async included(e=180,t=2){if(e<=0||t<=0)throw RangeError("timeoutInSeconds and requestIntervalInSeconds should be bigger than zero");if(e<t)throw RangeError("timeoutInSeconds can't be less than requestIntervalInSeconds");let a=0;for(;a<=e;){await this.delay(1e3*t);const e=await this.bundler.getUserOperationReceipt(this.userOperationHash);if(null!=e)return e;a++}throw new m("TIMEOUT","can't find useroperation",{context:this.userOperationHash})}}class S extends l{constructor(e,t=S.DEFAULT_SAFE_4337_MODULE_ADDRESS,a=S.DEFAULT_ENTRYPOINT_ADDRESS){super(e),this.entrypointAddress=void 0,this.safe4337ModuleAddress=void 0,this.initCode=void 0,this.entrypointAddress=a,this.safe4337ModuleAddress=t,this.initCode=null}static initializeNewAccount(e,t={}){const[a,i]=S.createAccountAddressAndInitCode(e,t),r=new S(a);return r.initCode=i,r}static createAccountAddress(e,t={}){const[a]=S.createAccountAddressAndInitCode(e,t);return a}static createAccountAddressAndInitCode(e,t={}){var a,i,r,n,s;if(e.length<1)throw RangeError("There should be at least one owner");const o=null!=(a=t.threshold)?a:1,c=null!=(i=t.c2Nonce)?i:0n,f=null!=(r=t.singletonAddress)?r:S.DEFAULT_SINGLETON_ADDRESS,l=null!=(n=t.safe4337ModuleAddress)?n:S.DEFAULT_SAFE_4337_MODULE_ADDRESS,d=null!=(s=t.addModuleLibAddress)?s:S.DEFAULT_ADD_MODULE_LIB_ADDRESS;let u=new v;null!=t.safeAccountFactoryAddress&&(u=new v(t.safeAccountFactoryAddress));const p=S.createInitializerCallData(e,o,l,d);return[this.createProxyAddress(p,c,u.address,f),u.getFactoryGeneratorFunctionCallData([f,p,c])]}static createInitializerCallData(e,t,a=S.DEFAULT_SAFE_4337_MODULE_ADDRESS,i=S.DEFAULT_ADD_MODULE_LIB_ADDRESS){if(e.length<1)throw RangeError("There should be at least one owner");if(t<1)throw RangeError("threshold should be at least one");if(t>e.length)throw RangeError("threshold can't be larger than number of owners");const r=g("0x8d0dc49f",["address[]"],[[a]]);return g(S.initializerFunctionSelector,S.initializerFunctionInputAbi,[e,t,i,r,a,R,0,R])}static createInitCode(e,t=1,a=0n,i=S.DEFAULT_SINGLETON_ADDRESS,r=new v,n=S.DEFAULT_SAFE_4337_MODULE_ADDRESS,s=S.DEFAULT_ADD_MODULE_LIB_ADDRESS){if(e.length<1)throw RangeError("There should be at least one owner");if(t<1)throw RangeError("threshold should be at least one");if(t>e.length)throw RangeError("threshold can't be larger than number of owners");if(a<0n)throw RangeError("c2Nonce can't be negative");const o=S.createInitializerCallData(e,t,n,s);return r.getFactoryGeneratorFunctionCallData([i,o,a])}static createProxyAddress(a,i,r,o){if(i<0n)throw RangeError("c2Nonce can't be negative");const c=t.defaultAbiCoder(),f=e(n(["bytes32","uint256"],[e(a),i])),l=c.encode(["uint256"],[o]),d=e(n(["bytes","bytes"],[this.proxyByteCode,l]));return"0x"+s(["bytes1","address","bytes32","bytes32"],["0xff",r,f,d]).slice(-40)}static createAccountCallDataSingleTransaction(e){var t,a,i;const r=null!=(t=e.value)?t:0,n=null!=(a=e.data)?a:"0x",s=null!=(i=e.operation)?i:u.Call;return S.createAccountCallData(e.to,r,n,s)}static createAccountCallDataBatchTransactions(e,t=S.DEFAULT_MULTISEND_CONTRACT_ADDRESS){if(e.length<1)throw RangeError("There should be at least one metaTransaction");const a=g("0x8d80ff0a",["bytes"],[x(e)]);return S.createAccountCallData(t,0n,a,u.Delegate)}static createAccountCallData(e,t,a,i,r=S.DEFAULT_EXECUTOR_FUCNTION_SELECTOR){return g(r,S.executorFunctionInputAbi,[e,t,a,i])}static decodeAccountCallData(e){if(e.startsWith(L.executeUserOpWithErrorString)||e.startsWith(L.executeUserOp)){const a=t.defaultAbiCoder(),i="0x"+e.slice(10),r=a.decode(["address","uint256","bytes","uint8"],i);return[r[0],BigInt(r[1]),r[2],Number(r[3])]}throw new m("BAD_DATA","Invalid calldata, should start with "+L.executeUserOpWithErrorString+" or "+L.executeUserOp,{context:{callData:e}})}prependTokenPaymasterApproveToCallData(e,t,a,i,r=S.DEFAULT_MULTISEND_CONTRACT_ADDRESS){return S.prependTokenPaymasterApproveToCallDataStatic(e,t,a,i,r)}static prependTokenPaymasterApproveToCallDataStatic(e,a,i,r,n=S.DEFAULT_MULTISEND_CONTRACT_ADDRESS){const[s,o,c,f]=S.decodeAccountCallData(e);let l="";l="string"!=typeof c?(new TextDecoder).decode(c):c;const d=x([{to:a,value:0n,data:g(E("approve(address,uint256)"),["address","uint256"],[i,r]),operation:u.Call}]);let p="";const h="0x8d80ff0a";if(l.startsWith(h)){const e=function(e){return t.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(l);p=e+d.slice(2)}else p=x([{to:s,value:o,data:c,operation:f}])+d.slice(2);const m=g(h,["bytes"],[p]);return S.createAccountCallData(n,0n,m,u.Delegate)}async estimateUserOperationGas(e,t,a,i=1){if(i<1n)throw RangeError("numberOfSigners can't be less than 1");let r="";for(let e=0;e<i;e++)r+="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";e.signature="0xffffffffffffffffffffffff"+r;const n=new T(t),s=e.maxFeePerGas,o=e.maxPriorityFeePerGas;e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n;const c=await n.estimateUserOperationGas(e,this.entrypointAddress,a);return e.maxFeePerGas=s,e.maxPriorityFeePerGas=o,[BigInt(c.preVerificationGas),BigInt(c.verificationGasLimit)+30000n*BigInt(i),BigInt(c.callGasLimit)]}async createUserOperation(e,t,a,r={}){var n,s,o,c,f,l,u,h,y,A,g;if(e.length<1)throw RangeError("There should be at least one transaction");let G=0n;if(null==r.nonce){if(null==t)throw new m("BAD_DATA","providerRpc cant't be null if nonce is not overriden");G=await D(t,this.entrypointAddress,this.accountAddress)}else G=r.nonce;let E=null!=(n=r.initCode)?n:this.initCode;if((null==E||G>0n)&&(E="0x"),G<0n)throw RangeError("nonce can't be negative");let P="0x";P=null==r.callData?1==e.length?S.createAccountCallDataSingleTransaction(e[0]):S.createAccountCallDataBatchTransactions(e):r.callData;let R=w.maxFeePerGas,b=w.maxPriorityFeePerGas;if(null==r.maxFeePerGas||null==r.maxPriorityFeePerGas){if(null==t)throw new m("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden");[R,b]=await async function(e,t=p.Medium){const a=new i(e),r=await a.getFeeData();return[BigInt(Math.ceil(Number(r.maxFeePerGas)*t)),BigInt(Math.ceil(Number(r.maxPriorityFeePerGas)*t))]}(t),0n==R&&(R=1n),0n==b&&(b=1n)}if("bigint"==typeof r.maxFeePerGas&&r.maxFeePerGas<0n)throw RangeError("maxFeePerGas overrid can't be negative");if("bigint"==typeof r.maxPriorityFeePerGas&&r.maxPriorityFeePerGas<0n)throw RangeError("maxPriorityFeePerGas overrid can't be negative");R=null!=(s=r.maxFeePerGas)?s:R*BigInt(Math.floor(((null!=(o=r.maxFeePerGasPercentageMultiplier)?o:0)+100)/100)),b=null!=(c=r.maxPriorityFeePerGas)?c:b*BigInt(Math.floor(((null!=(f=r.maxPriorityFeePerGasPercentageMultiplier)?f:0)+100)/100));const v=d({},w,{sender:this.accountAddress,nonce:G,initCode:E,callData:P,maxFeePerGas:R,maxPriorityFeePerGas:b});let L=w.preVerificationGas,x=w.verificationGasLimit,T=w.callGasLimit;if(null==r.preVerificationGas||null==r.verificationGasLimit||null==r.callGasLimit){if(null==a)throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{v.callGasLimit=0n,v.verificationGasLimit=0n,v.preVerificationGas=0n;const e=v.maxFeePerGas,t=v.maxPriorityFeePerGas;v.maxFeePerGas=0n,v.maxPriorityFeePerGas=0n,[L,x,T]=await this.estimateUserOperationGas(v,a,r.state_override_set,r.numberOfSigners),v.maxFeePerGas=e,v.maxPriorityFeePerGas=t}}if("bigint"==typeof r.preVerificationGas&&r.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof r.verificationGasLimit&&r.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof r.callGasLimit&&r.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return v.preVerificationGas=null!=(l=r.preVerificationGas)?l:L*BigInt(Math.floor(((null!=(u=r.preVerificationGasPercentageMultiplier)?u:0)+100)/100)),v.verificationGasLimit=null!=(h=r.verificationGasLimit)?h:x*BigInt(Math.floor(((null!=(y=r.verificationGasLimitPercentageMultiplier)?y:0)+100)/100)),v.callGasLimit=null!=(A=r.callGasLimit)?A:T*BigInt(Math.floor(((null!=(g=r.callGasLimitPercentageMultiplier)?g:0)+100)/100)),v}signUserOperation(e,t,a,i=0n,r=0n){if(t.length<1)throw RangeError("There should be at least one privateKey");if(a<0n)throw RangeError("chainId can't be negative");if(i<0n)throw RangeError("validAfter can't be negative");if(r<0n)throw RangeError("validUntil can't be negative");const n={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:i,validUntil:r,entryPoint:this.entrypointAddress},s={chainId:a,verifyingContract:this.safe4337ModuleAddress},f=[],l=[];for(const e of t){const t=new o(e),a=t.signingKey.sign(c.hash(s,S.EIP712_SAFE_OPERATION_TYPE,n)).serialized;f.push(t.address),l.push(a)}return S.formatEip712SignaturesToUseroperationSignature(f,l,i,r)}static formatEip712SignaturesToUseroperationSignature(e,t,a=0n,i=0n){if(e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");const r=new Map;e.forEach((e,a)=>{r.set(e.toLocaleLowerCase(),t[a])});const n=new Map(Array.from(r).sort()),s="0x"+Array.from(n.values()).reduce((e,t)=>e+t.slice(2),"");return S.formatEip712SingleSignatureToUseroperationSignature(s,a,i)}static formatEip712SingleSignatureToUseroperationSignature(e,t=0n,a=0n){if(t<0n)throw RangeError("validAfter can't be negative");if(a<0n)throw RangeError("validUntil can't be negative");return n(["uint48","uint48","bytes"],[t,a,e])}async sendUserOperation(e,t){const a=new T(t),i=await a.sendUserOperation(e,this.entrypointAddress);return new F(i,a,this.entrypointAddress)}}S.DEFAULT_ENTRYPOINT_ADDRESS="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",S.DEFAULT_SAFE_4337_MODULE_ADDRESS="0xa581c4A4DB7175302464fF3C06380BC3270b4037",S.DEFAULT_SINGLETON_ADDRESS="0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",S.DEFAULT_ADD_MODULE_LIB_ADDRESS="0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",S.DEFAULT_MULTISEND_CONTRACT_ADDRESS="0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",S.proxyByteCode="0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564",S.initializerFunctionSelector="0xb63e800d",S.initializerFunctionInputAbi=["address[]","uint256","address","bytes","address","address","uint256","address"],S.DEFAULT_EXECUTOR_FUCNTION_SELECTOR=L.executeUserOpWithErrorString,S.executorFunctionInputAbi=["address","uint256","bytes","uint8"],S.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"}]};class _{}class U extends _{constructor(e){super(),this.rpcUrl=void 0,this.entrypointAddress=void 0,this.supportedTokens=void 0,this.paymasterMetadata=void 0,this.rpcUrl=e}async initialize(){try{this.entrypointAddress=await this.getSupportedEntrypoint();const e=await this.getSupportedERC20TokensAndPaymasterMetadata();return this.supportedTokens=e.tokens,this.paymasterMetadata=e.paymasterMetadata,null}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","failed initializing the paymaster",{cause:t})}}async getPaymasterMetaData(){return null==this.paymasterMetadata&&await this.initialize(),this.paymasterMetadata}async getSupportedERC20TokensAndPaymasterMetadata(){if(null!=this.supportedTokens&&null!=this.paymasterMetadata)return{tokens:this.supportedTokens,paymasterMetadata:this.paymasterMetadata};try{const e=await G(this.rpcUrl,"pm_supportedERC20Tokens",[]);return{tokens:e.tokens.map(e=>({symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)})),paymasterMetadata:e.paymasterMetadata}}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","getSupportedERC20TokensAndPaymasterMetadata failed",{cause:t})}}async getSupportedEntrypoint(){if(null!=this.entrypointAddress)return this.entrypointAddress;try{return await G(this.rpcUrl,"pm_supportedEntryPoint",[])}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","getSupportedEntrypoint failed",{cause:t})}}async isSupportedERC20Token(e){return null!=this.entrypointAddress&&null!=this.supportedTokens&&null!=this.paymasterMetadata||await this.initialize(),!!this.supportedTokens.find(t=>t.address.toLowerCase()===e.toLowerCase())}async getSupportedERC20TokenData(e){null!=this.entrypointAddress&&null!=this.supportedTokens&&null!=this.paymasterMetadata||await this.initialize();const t=this.supportedTokens.find(t=>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}async createPaymasterUserOperation(e,t,a={},i={}){null!=this.entrypointAddress&&null!=this.supportedTokens&&null!=this.paymasterMetadata||await this.initialize();try{var r,n,s,o,c,f,l,d,u,p,h;e.paymasterAndData=this.paymasterMetadata.dummyPaymasterAndData;let y=e.preVerificationGas,A=e.verificationGasLimit,g=e.callGasLimit;if(null==i.preVerificationGas||null==i.verificationGasLimit||null==i.callGasLimit){if(null==t)throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden");{const a=new T(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;const r=e.maxFeePerGas,n=e.maxPriorityFeePerGas;e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n;const s=await a.estimateUserOperationGas(e,this.entrypointAddress,i.state_override_set);y<s.preVerificationGas&&(y=s.preVerificationGas),A<s.verificationGasLimit&&(A=s.verificationGasLimit),g<s.callGasLimit&&(g=s.callGasLimit),e.maxFeePerGas=r,e.maxPriorityFeePerGas=n}}if("bigint"==typeof i.preVerificationGas&&i.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof i.verificationGasLimit&&i.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof i.callGasLimit&&i.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");e.preVerificationGas=null!=(r=i.preVerificationGas)?r:y*BigInt((null!=(n=i.preVerificationGasPercentageMultiplier)?n:0)+100)/100n,e.verificationGasLimit=null!=(s=i.verificationGasLimit)?s:A*BigInt((null!=(o=i.verificationGasLimitPercentageMultiplier)?o:0)+100)/100n,e.callGasLimit=null!=(c=i.callGasLimit)?c:g*BigInt((null!=(f=i.callGasLimitPercentageMultiplier)?f:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n;const E=await G(this.rpcUrl,"pm_sponsorUserOperation",[e,this.entrypointAddress,a]),D={paymasterAndData:E.paymasterAndData,callGasLimit:null==E.callGasLimit?void 0:BigInt(E.callGasLimit),preVerificationGas:null==E.preVerificationGas?void 0:BigInt(E.preVerificationGas),verificationGasLimit:null==E.verificationGasLimit?void 0:BigInt(E.verificationGasLimit),maxFeePerGas:null==E.maxFeePerGas?void 0:BigInt(E.maxFeePerGas),maxPriorityFeePerGas:null==E.maxPriorityFeePerGas?void 0:BigInt(E.maxPriorityFeePerGas)};return e.paymasterAndData=D.paymasterAndData,e.callGasLimit=null!=(l=D.callGasLimit)?l:e.callGasLimit,e.preVerificationGas=null!=(d=D.preVerificationGas)?d:e.preVerificationGas,e.verificationGasLimit=null!=(u=D.verificationGasLimit)?u:e.verificationGasLimit,e.maxFeePerGas=null!=(p=D.maxFeePerGas)?p:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(h=D.maxPriorityFeePerGas)?h:e.maxPriorityFeePerGas,e}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","pm_sponsorUserOperation failed",{cause:t})}}async createSponsorPaymasterUserOperation(e,t,a={}){return await this.createPaymasterUserOperation(e,t,{},a)}async createTokenPaymasterUserOperation(e,t,a,i,r={}){try{const n=2n*await this.calculateUserOperationErc20TokenMaxGasCost(t,a);let s=await this.getPaymasterMetaData();const o=e.prependTokenPaymasterApproveToCallData(t.callData,a,s.address,n);return t.callData=o,await this.createPaymasterUserOperation(t,i,{token:a},r)}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","createTokenPaymasterUserOperation failed",{cause:t})}}async calculateUserOperationErc20TokenMaxGasCost(e,t){try{const a=await this.getSupportedERC20TokenData(t);if(null==a)throw new m("PAYMASTER_ERROR",t+" token is not supported by the paymaster.",{context:{supportedERC20TokensAndPaymasterMetadata:JSON.stringify(await this.getSupportedERC20TokensAndPaymasterMetadata(),(e,t)=>"bigint"==typeof t?"0x"+t.toString(16):t)}});{const t=P(e);return a.exchangeRate*t/BigInt(10**18)}}catch(e){const t=y(e);throw new m("PAYMASTER_ERROR","calculateUserOperationErc20TokenMaxGasCost failed",{cause:t})}}}var O={__proto__:null,SmartAccount:l,SafeAccountV0_2_0:S,SendUseroperationResponse:F,SmartAccountFactory:b,SafeAccountFactory:v,Bundler:T,CandidePaymaster:U,createUserOperationHash:A,createCallData:g,getFunctionSelector:E,fetchAccountNonce:D,calculateUserOperationMaxGasCost:P,get SafeModuleExecutorFunctionSelector(){return L},get Operation(){return u},ZeroAddress:R,UserOperationDummyValues:w};export{T as Bundler,U as CandidePaymaster,u as Operation,v as SafeAccountFactory,S as SafeAccountV0_2_0,L as SafeModuleExecutorFunctionSelector,F as SendUseroperationResponse,l as SmartAccount,b as SmartAccountFactory,w as UserOperationDummyValues,R as ZeroAddress,O as abstractionkit,P as calculateUserOperationMaxGasCost,g as createCallData,A as createUserOperationHash,D as fetchAccountNonce,E as getFunctionSelector};
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
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 c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function f(){return f=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},f.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(c())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 v(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 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"},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:G(E("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(P(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)}},P=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 h?h[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(i)}})})})}catch(e){return Promise.reject(e)}};function g(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 G(e,r,n){return e+t.AbiCoder.defaultAbiCoder().encode(r,n).slice(2)}function E(e){return t.id(e).slice(0,10)}function b(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var D,S="0x0000000000000000000000000000000000000000",R={sender:S,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"},O=/*#__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 u(t,e),t}(O);function F(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 _(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}e.SafeModuleExecutorFunctionSelector=void 0,(D=e.SafeModuleExecutorFunctionSelector||(e.SafeModuleExecutorFunctionSelector={})).executeUserOpWithErrorString="0x541d63c8",D.executeUserOp="0x7bb37428";var L=/*#__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(P(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(_(function(){return Promise.resolve(P(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(_(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(P(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(P(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(_(function(){return Promise.resolve(P(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(_(function(){return Promise.resolve(P(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=f({},t.receipt,{blockNumber:BigInt(t.receipt.blockNumber),cumulativeGasUsed:BigInt(t.receipt.cumulativeGasUsed),gasUsed:BigInt(t.receipt.gasUsed),transactionIndex:BigInt(t.receipt.transactionIndex),effectiveGasPrice:null==t.receipt.effectiveGasPrice?void 0:BigInt(t.receipt.effectiveGasPrice),logs:JSON.stringify(t.receipt.logs)});return f({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt: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(_(function(){return Promise.resolve(P(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?f({},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 T(e,t,r){if(!e.s){if(r instanceof U){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 U=/*#__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 U&&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(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 U,c=T.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(f):o.then(l)).then(void 0,c),s;function f(n){a=n;do{if(t&&(o=t())&&o.then&&!w(o))return void o.then(l).then(void 0,c);if(!(i=e())||w(i)&&!i.v)return void T(s,1,a);if(i.then)return void i.then(u).then(void 0,c);w(a=r())&&(a=a.v)}while(!a||!a.then);a.then(f).then(void 0,c)}function u(e){e?(a=r())&&a.then?a.then(f).then(void 0,c):f(a):T(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,c):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(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.createAccountAddress=function(e,t){return void 0===t&&(t={}),n.createAccountAddressAndInitCode(e,t)[0]},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 c=null!=(r=t.threshold)?r:1,f=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 x;null!=t.safeAccountFactoryAddress&&(p=new x(t.safeAccountFactoryAddress));var v=n.createInitializerCallData(e,c,l,d);return[this.createProxyAddress(v,f,p.address,u),p.getFactoryGeneratorFunctionCallData([u,v,f])]},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=G("0x8d0dc49f",["address[]"],[[r]]);return G(n.initializerFunctionSelector,n.initializerFunctionInputAbi,[e,t,i,a,r,S,0,S])},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 x),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 c=n.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,c,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]),c=t.keccak256(t.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+t.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,c]).slice(-40)},n.createAccountCallDataSingleTransaction=function(t){var r,i,a,o=null!=(r=t.value)?r:0,s=null!=(i=t.data)?i:"0x",c=null!=(a=t.operation)?a:e.Operation.Call;return n.createAccountCallData(t.to,o,s,c)},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=G("0x8d80ff0a",["bytes"],[F(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),G(a,n.executorFunctionInputAbi,[e,t,r,i])},n.decodeAccountCallData=function(r){if(r.startsWith(e.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString)||r.startsWith(e.SafeModuleExecutorFunctionSelector.executeUserOp)){var n=t.AbiCoder.defaultAbiCoder(),i="0x"+r.slice(10),a=n.decode(["address","uint256","bytes","uint8"],i);return[a[0],BigInt(a[1]),a[2],Number(a[3])]}throw new m("BAD_DATA","Invalid calldata, should start with "+e.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString+" or "+e.SafeModuleExecutorFunctionSelector.executeUserOp,{context:{callData:r}})};var i=n.prototype;return i.prependTokenPaymasterApproveToCallData=function(e,t,r,i,a){return void 0===a&&(a=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS),n.prependTokenPaymasterApproveToCallDataStatic(e,t,r,i,a)},n.prependTokenPaymasterApproveToCallDataStatic=function(r,i,a,o,s){void 0===s&&(s=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var c=n.decodeAccountCallData(r),f=c[0],u=c[1],l=c[2],d=c[3],p="";p="string"!=typeof l?(new TextDecoder).decode(l):l;var v=F([{to:i,value:0n,data:G(E("approve(address,uint256)"),["address","uint256"],[a,o]),operation:e.Operation.Call}]),h="",m="0x8d80ff0a";if(p.startsWith(m)){var y=function(e){return t.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);h=y+v.slice(2)}else h=F([{to:f,value:u,data:l,operation:d}])+v.slice(2);var A=G(m,["bytes"],[h]);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 L(t),s=e.maxFeePerGas,c=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(t){return e.maxFeePerGas=s,e.maxPriorityFeePerGas=c,[BigInt(t.preVerificationGas),BigInt(t.verificationGasLimit)+20000n*BigInt(n),BigInt(t.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(e,r,i,o){void 0===o&&(o={});try{var s=function(s){var l;function d(e){var t,r,n,a;function s(e){var t,r,n,i,a,s;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 l.preVerificationGas=null!=(t=o.preVerificationGas)?t:d*BigInt(Math.floor(((null!=(r=o.preVerificationGasPercentageMultiplier)?r:0)+100)/100)),l.verificationGasLimit=null!=(n=o.verificationGasLimit)?n:A*BigInt(Math.floor(((null!=(i=o.verificationGasLimitPercentageMultiplier)?i:0)+100)/100)),l.callGasLimit=null!=(a=o.callGasLimit)?a:P*BigInt(Math.floor(((null!=(s=o.callGasLimitPercentageMultiplier)?s:0)+100)/100)),l}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!=(t=o.maxFeePerGas)?t:h*BigInt(Math.floor(((null!=(r=o.maxFeePerGasPercentageMultiplier)?r:0)+100)/100)),y=null!=(n=o.maxPriorityFeePerGas)?n:y*BigInt(Math.floor(((null!=(a=o.maxPriorityFeePerGasPercentageMultiplier)?a:0)+100)/100));var l=f({},R,{sender:c.accountAddress,nonce:u,initCode:p,callData:v,maxFeePerGas:h,maxPriorityFeePerGas:y}),d=R.preVerificationGas,A=R.verificationGasLimit,P=R.callGasLimit,g=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return function(){if(null!=i){l.callGasLimit=0n,l.verificationGasLimit=0n,l.preVerificationGas=0n;var e=l.maxFeePerGas,t=l.maxPriorityFeePerGas;return l.maxFeePerGas=0n,l.maxPriorityFeePerGas=0n,Promise.resolve(c.estimateUserOperationGas(l,i,o.state_override_set,o.numberOfSigners)).then(function(r){d=r[0],A=r[1],P=r[2],l.maxFeePerGas=e,l.maxPriorityFeePerGas=t})}throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return g&&g.then?g.then(s):s()}var p=null!=(l=o.initCode)?l:c.initCode;if((null==p||u>0n)&&(p="0x"),u<0n)throw RangeError("nonce can't be negative");var v="0x";v=null==o.callData?1==e.length?n.createAccountCallDataSingleTransaction(e[0]):n.createAccountCallDataBatchTransactions(e):o.callData;var h=R.maxFeePerGas,y=R.maxPriorityFeePerGas,A=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return function(){if(null!=r)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){0n==(h=e[0])&&(h=1n),0n==(y=e[1])&&(y=1n)});throw new m("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden")}()}();return A&&A.then?A.then(d):d()},c=this;if(e.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return function(){if(null!=r)return Promise.resolve(A(r,c.entrypointAddress,c.accountAddress)).then(function(e){u=e});throw new m("BAD_DATA","providerRpc cant't be null if nonce is not overriden")}();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,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:a,validUntil:o,entryPoint:this.entrypointAddress},f={chainId:i,verifyingContract:this.safe4337ModuleAddress},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 v(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)?v(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=d()).done;){var p=new t.Wallet(s.value),h=p.signingKey.sign(t.TypedDataEncoder.hash(f,n.EIP712_SAFE_OPERATION_TYPE,c)).serialized;u.push(p.address),l.push(h)}return n.formatEip712SignaturesToUseroperationSignature(u,l,a,o)},n.formatEip712SignaturesToUseroperationSignature=function(e,t,r,i){if(void 0===r&&(r=0n),void 0===i&&(i=0n),e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");var a=new Map;e.forEach(function(e,r){a.set(e.toLocaleLowerCase(),t[r])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return n.formatEip712SingleSignatureToUseroperationSignature(s,r,i)},n.formatEip712SingleSignatureToUseroperationSignature=function(e,r,n){if(void 0===r&&(r=0n),void 0===n&&(n=0n),r<0n)throw RangeError("validAfter can't be negative");if(n<0n)throw RangeError("validUntil can't be negative");return t.solidityPacked(["uint48","uint48","bytes"],[r,n,e])},i.sendUserOperation=function(e,t){try{var r=this,n=new L(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=e.SafeModuleExecutorFunctionSelector.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(P(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens.map(function(e){return{symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)}}),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(P(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.toLowerCase()===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={}),void 0===n&&(n={});try{var i=function(){return M(function(){function i(t){var i,f,u,l,d,p;if("bigint"==typeof n.preVerificationGas&&n.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof n.verificationGasLimit&&n.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof n.callGasLimit&&n.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return e.preVerificationGas=null!=(i=n.preVerificationGas)?i:o*BigInt((null!=(f=n.preVerificationGasPercentageMultiplier)?f:0)+100)/100n,e.verificationGasLimit=null!=(u=n.verificationGasLimit)?u:s*BigInt((null!=(l=n.verificationGasLimitPercentageMultiplier)?l:0)+100)/100n,e.callGasLimit=null!=(d=n.callGasLimit)?d:c*BigInt((null!=(p=n.callGasLimitPercentageMultiplier)?p:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n,Promise.resolve(P(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,c={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=c.paymasterAndData,e.callGasLimit=null!=(r=c.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=c.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=c.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=c.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=c.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})}e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var o=e.preVerificationGas,s=e.verificationGasLimit,c=e.callGasLimit,f=function(){if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit)return function(){if(null!=t){var r=new L(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;var i=e.maxFeePerGas,f=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(r.estimateUserOperationGas(e,a.entrypointAddress,n.state_override_set)).then(function(t){o<t.preVerificationGas&&(o=t.preVerificationGas),s<t.verificationGasLimit&&(s=t.verificationGasLimit),c<t.callGasLimit&&(c=t.callGasLimit),e.maxFeePerGas=i,e.maxPriorityFeePerGas=f})}throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return f&&f.then?f.then(i):i()},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){void 0===r&&(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 c=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=c,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,function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t})}})});var i=b(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:O,SafeAccountFactory:x,Bundler:L,CandidePaymaster:B,createUserOperationHash:g,createCallData:G,getFunctionSelector:E,fetchAccountNonce:A,calculateUserOperationMaxGasCost:b,get SafeModuleExecutorFunctionSelector(){return e.SafeModuleExecutorFunctionSelector},get Operation(){return e.Operation},ZeroAddress:S,UserOperationDummyValues:R};e.Bundler=L,e.CandidePaymaster=B,e.SafeAccountFactory=x,e.SafeAccountV0_2_0=C,e.SendUseroperationResponse=I,e.SmartAccount=s,e.SmartAccountFactory=O,e.UserOperationDummyValues=R,e.ZeroAddress=S,e.abstractionkit=N,e.calculateUserOperationMaxGasCost=b,e.createCallData=G,e.createUserOperationHash=g,e.fetchAccountNonce=A,e.getFunctionSelector=E});
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 c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function f(){return f=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},f.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(c())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 v(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 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"},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:G(E("getNonce(address,uint192)"),["address","uint192"],[r,n])},"latest"];return Promise.resolve(function(t,r){try{var n=Promise.resolve(P(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)}},P=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 h?h[n]:"UNKNOWN_ERROR",r.message,{errno:r.code,context:{url:e,requestOptions:JSON.stringify(i)}})})})}catch(e){return Promise.reject(e)}};function g(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 G(e,r,n){return e+t.AbiCoder.defaultAbiCoder().encode(r,n).slice(2)}function E(e){return t.id(e).slice(0,10)}function b(e){return(e.callGasLimit+e.verificationGasLimit*("0x"==e.paymasterAndData||null==e.paymasterAndData?3n:0n)+e.preVerificationGas)*e.maxFeePerGas}var D,S="0x0000000000000000000000000000000000000000",R={sender:S,nonce:0n,initCode:"0x",callData:"0x",callGasLimit:0n,verificationGasLimit:0n,preVerificationGas:0n,maxFeePerGas:0n,maxPriorityFeePerGas:0n,paymasterAndData:"0x",signature:"0x"},O=/*#__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 u(t,e),t}(O);function F(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 _(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}e.SafeModuleExecutorFunctionSelector=void 0,(D=e.SafeModuleExecutorFunctionSelector||(e.SafeModuleExecutorFunctionSelector={})).executeUserOpWithErrorString="0x541d63c8",D.executeUserOp="0x7bb37428";var L=/*#__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(P(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(_(function(){return Promise.resolve(P(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(_(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(P(n.rpcUrl,"eth_estimateUserOperationGas",[e,t])).then(function(e){a=e}):Promise.resolve(P(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(_(function(){return Promise.resolve(P(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(_(function(){return Promise.resolve(P(t.rpcUrl,"eth_getUserOperationReceipt",[e])).then(function(e){var t=e;if(null!=t){var r=f({},t.receipt,{blockNumber:BigInt(t.receipt.blockNumber),cumulativeGasUsed:BigInt(t.receipt.cumulativeGasUsed),gasUsed:BigInt(t.receipt.gasUsed),transactionIndex:BigInt(t.receipt.transactionIndex),effectiveGasPrice:null==t.receipt.effectiveGasPrice?void 0:BigInt(t.receipt.effectiveGasPrice),logs:JSON.stringify(t.receipt.logs)});return f({},t,{nonce:BigInt(t.nonce),actualGasCost:BigInt(t.actualGasCost),actualGasUsed:BigInt(t.actualGasUsed),logs:JSON.stringify(t.logs),receipt: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(_(function(){return Promise.resolve(P(t.rpcUrl,"eth_getUserOperationByHash",[e])).then(function(e){return null!=e?f({},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 T(e,t,r){if(!e.s){if(r instanceof U){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 U=/*#__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 U&&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(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 U,c=T.bind(null,s,2);return(0===n?i.then(u):1===n?a.then(f):o.then(l)).then(void 0,c),s;function f(n){a=n;do{if(t&&(o=t())&&o.then&&!w(o))return void o.then(l).then(void 0,c);if(!(i=e())||w(i)&&!i.v)return void T(s,1,a);if(i.then)return void i.then(u).then(void 0,c);w(a=r())&&(a=a.v)}while(!a||!a.then);a.then(f).then(void 0,c)}function u(e){e?(a=r())&&a.then?a.then(f).then(void 0,c):f(a):T(s,1,a)}function l(){(i=e())?i.then?i.then(u).then(void 0,c):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(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.createAccountAddress=function(e,t){return void 0===t&&(t={}),n.createAccountAddressAndInitCode(e,t)[0]},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 c=null!=(r=t.threshold)?r:1,f=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 x;null!=t.safeAccountFactoryAddress&&(p=new x(t.safeAccountFactoryAddress));var v=n.createInitializerCallData(e,c,l,d);return[this.createProxyAddress(v,f,p.address,u),p.getFactoryGeneratorFunctionCallData([u,v,f])]},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=G("0x8d0dc49f",["address[]"],[[r]]);return G(n.initializerFunctionSelector,n.initializerFunctionInputAbi,[e,t,i,a,r,S,0,S])},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 x),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 c=n.createInitializerCallData(e,t,o,s);return a.getFactoryGeneratorFunctionCallData([i,c,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]),c=t.keccak256(t.solidityPacked(["bytes","bytes"],[this.proxyByteCode,s]));return"0x"+t.solidityPackedKeccak256(["bytes1","address","bytes32","bytes32"],["0xff",n,o,c]).slice(-40)},n.createAccountCallDataSingleTransaction=function(t){var r,i,a,o=null!=(r=t.value)?r:0,s=null!=(i=t.data)?i:"0x",c=null!=(a=t.operation)?a:e.Operation.Call;return n.createAccountCallData(t.to,o,s,c)},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=G("0x8d80ff0a",["bytes"],[F(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),G(a,n.executorFunctionInputAbi,[e,t,r,i])},n.decodeAccountCallData=function(r){if(r.startsWith(e.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString)||r.startsWith(e.SafeModuleExecutorFunctionSelector.executeUserOp)){var n=t.AbiCoder.defaultAbiCoder(),i="0x"+r.slice(10),a=n.decode(["address","uint256","bytes","uint8"],i);return[a[0],BigInt(a[1]),a[2],Number(a[3])]}throw new m("BAD_DATA","Invalid calldata, should start with "+e.SafeModuleExecutorFunctionSelector.executeUserOpWithErrorString+" or "+e.SafeModuleExecutorFunctionSelector.executeUserOp,{context:{callData:r}})};var i=n.prototype;return i.prependTokenPaymasterApproveToCallData=function(e,t,r,i,a){return void 0===a&&(a=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS),n.prependTokenPaymasterApproveToCallDataStatic(e,t,r,i,a)},n.prependTokenPaymasterApproveToCallDataStatic=function(r,i,a,o,s){void 0===s&&(s=n.DEFAULT_MULTISEND_CONTRACT_ADDRESS);var c=n.decodeAccountCallData(r),f=c[0],u=c[1],l=c[2],d=c[3],p="";p="string"!=typeof l?(new TextDecoder).decode(l):l;var v=F([{to:i,value:0n,data:G(E("approve(address,uint256)"),["address","uint256"],[a,o]),operation:e.Operation.Call}]),h="",m="0x8d80ff0a";if(p.startsWith(m)){var y=function(e){return t.AbiCoder.defaultAbiCoder().decode(["bytes"],"0x"+e.slice(10))[0]}(p);h=y+v.slice(2)}else h=F([{to:f,value:u,data:l,operation:d}])+v.slice(2);var A=G(m,["bytes"],[h]);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 L(t),s=e.maxFeePerGas,c=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(o.estimateUserOperationGas(e,this.entrypointAddress,r)).then(function(t){return e.maxFeePerGas=s,e.maxPriorityFeePerGas=c,[BigInt(t.preVerificationGas),BigInt(t.verificationGasLimit)+30000n*BigInt(n),BigInt(t.callGasLimit)]})}catch(e){return Promise.reject(e)}},i.createUserOperation=function(e,r,i,o){void 0===o&&(o={});try{var s=function(s){var l;function d(e){var t,r,n,a;function s(e){var t,r,n,i,a,s;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 l.preVerificationGas=null!=(t=o.preVerificationGas)?t:d*BigInt(Math.floor(((null!=(r=o.preVerificationGasPercentageMultiplier)?r:0)+100)/100)),l.verificationGasLimit=null!=(n=o.verificationGasLimit)?n:A*BigInt(Math.floor(((null!=(i=o.verificationGasLimitPercentageMultiplier)?i:0)+100)/100)),l.callGasLimit=null!=(a=o.callGasLimit)?a:P*BigInt(Math.floor(((null!=(s=o.callGasLimitPercentageMultiplier)?s:0)+100)/100)),l}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!=(t=o.maxFeePerGas)?t:h*BigInt(Math.floor(((null!=(r=o.maxFeePerGasPercentageMultiplier)?r:0)+100)/100)),y=null!=(n=o.maxPriorityFeePerGas)?n:y*BigInt(Math.floor(((null!=(a=o.maxPriorityFeePerGasPercentageMultiplier)?a:0)+100)/100));var l=f({},R,{sender:c.accountAddress,nonce:u,initCode:p,callData:v,maxFeePerGas:h,maxPriorityFeePerGas:y}),d=R.preVerificationGas,A=R.verificationGasLimit,P=R.callGasLimit,g=function(){if(null==o.preVerificationGas||null==o.verificationGasLimit||null==o.callGasLimit)return function(){if(null!=i){l.callGasLimit=0n,l.verificationGasLimit=0n,l.preVerificationGas=0n;var e=l.maxFeePerGas,t=l.maxPriorityFeePerGas;return l.maxFeePerGas=0n,l.maxPriorityFeePerGas=0n,Promise.resolve(c.estimateUserOperationGas(l,i,o.state_override_set,o.numberOfSigners)).then(function(r){d=r[0],A=r[1],P=r[2],l.maxFeePerGas=e,l.maxPriorityFeePerGas=t})}throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return g&&g.then?g.then(s):s()}var p=null!=(l=o.initCode)?l:c.initCode;if((null==p||u>0n)&&(p="0x"),u<0n)throw RangeError("nonce can't be negative");var v="0x";v=null==o.callData?1==e.length?n.createAccountCallDataSingleTransaction(e[0]):n.createAccountCallDataBatchTransactions(e):o.callData;var h=R.maxFeePerGas,y=R.maxPriorityFeePerGas,A=function(){if(null==o.maxFeePerGas||null==o.maxPriorityFeePerGas)return function(){if(null!=r)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){0n==(h=e[0])&&(h=1n),0n==(y=e[1])&&(y=1n)});throw new m("BAD_DATA","providerRpc cant't be null if maxFeePerGas and maxPriorityFeePerGas are not overriden")}()}();return A&&A.then?A.then(d):d()},c=this;if(e.length<1)throw RangeError("There should be at least one transaction");var u=0n,l=function(){if(null==o.nonce)return function(){if(null!=r)return Promise.resolve(A(r,c.entrypointAddress,c.accountAddress)).then(function(e){u=e});throw new m("BAD_DATA","providerRpc cant't be null if nonce is not overriden")}();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,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:a,validUntil:o,entryPoint:this.entrypointAddress},f={chainId:i,verifyingContract:this.safe4337ModuleAddress},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 v(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)?v(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=d()).done;){var p=new t.Wallet(s.value),h=p.signingKey.sign(t.TypedDataEncoder.hash(f,n.EIP712_SAFE_OPERATION_TYPE,c)).serialized;u.push(p.address),l.push(h)}return n.formatEip712SignaturesToUseroperationSignature(u,l,a,o)},n.formatEip712SignaturesToUseroperationSignature=function(e,t,r,i){if(void 0===r&&(r=0n),void 0===i&&(i=0n),e.length!=t.length)throw RangeError("signersAddresses and signatures arrays should be the same length");var a=new Map;e.forEach(function(e,r){a.set(e.toLocaleLowerCase(),t[r])});var o=new Map(Array.from(a).sort()),s="0x"+Array.from(o.values()).reduce(function(e,t){return e+t.slice(2)},"");return n.formatEip712SingleSignatureToUseroperationSignature(s,r,i)},n.formatEip712SingleSignatureToUseroperationSignature=function(e,r,n){if(void 0===r&&(r=0n),void 0===n&&(n=0n),r<0n)throw RangeError("validAfter can't be negative");if(n<0n)throw RangeError("validUntil can't be negative");return t.solidityPacked(["uint48","uint48","bytes"],[r,n,e])},i.sendUserOperation=function(e,t){try{var r=this,n=new L(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=e.SafeModuleExecutorFunctionSelector.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(P(e.rpcUrl,"pm_supportedERC20Tokens",[])).then(function(e){return{tokens:e.tokens.map(function(e){return{symbol:e.symbol,address:e.address,decimal:Number(e.decimal),fee:BigInt(e.fee),exchangeRate:BigInt(e.exchangeRate)}}),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(P(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.toLowerCase()===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={}),void 0===n&&(n={});try{var i=function(){return M(function(){function i(t){var i,f,u,l,d,p;if("bigint"==typeof n.preVerificationGas&&n.preVerificationGas<0n)throw RangeError("preVerificationGas overrid can't be negative");if("bigint"==typeof n.verificationGasLimit&&n.verificationGasLimit<0n)throw RangeError("verificationGasLimit overrid can't be negative");if("bigint"==typeof n.callGasLimit&&n.callGasLimit<0n)throw RangeError("callGasLimit overrid can't be negative");return e.preVerificationGas=null!=(i=n.preVerificationGas)?i:o*BigInt((null!=(f=n.preVerificationGasPercentageMultiplier)?f:0)+100)/100n,e.verificationGasLimit=null!=(u=n.verificationGasLimit)?u:s*BigInt((null!=(l=n.verificationGasLimitPercentageMultiplier)?l:0)+100)/100n,e.callGasLimit=null!=(d=n.callGasLimit)?d:c*BigInt((null!=(p=n.callGasLimitPercentageMultiplier)?p:0)+100)/100n,e.preVerificationGas=e.preVerificationGas+100n,e.verificationGasLimit=e.verificationGasLimit+10000n,Promise.resolve(P(a.rpcUrl,"pm_sponsorUserOperation",[e,a.entrypointAddress,r])).then(function(t){var r,n,i,a,o,s=t,c={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=c.paymasterAndData,e.callGasLimit=null!=(r=c.callGasLimit)?r:e.callGasLimit,e.preVerificationGas=null!=(n=c.preVerificationGas)?n:e.preVerificationGas,e.verificationGasLimit=null!=(i=c.verificationGasLimit)?i:e.verificationGasLimit,e.maxFeePerGas=null!=(a=c.maxFeePerGas)?a:e.maxFeePerGas,e.maxPriorityFeePerGas=null!=(o=c.maxPriorityFeePerGas)?o:e.maxPriorityFeePerGas,e})}e.paymasterAndData=a.paymasterMetadata.dummyPaymasterAndData;var o=e.preVerificationGas,s=e.verificationGasLimit,c=e.callGasLimit,f=function(){if(null==n.preVerificationGas||null==n.verificationGasLimit||null==n.callGasLimit)return function(){if(null!=t){var r=new L(t);e.callGasLimit=0n,e.verificationGasLimit=0n,e.preVerificationGas=0n;var i=e.maxFeePerGas,f=e.maxPriorityFeePerGas;return e.maxFeePerGas=0n,e.maxPriorityFeePerGas=0n,Promise.resolve(r.estimateUserOperationGas(e,a.entrypointAddress,n.state_override_set)).then(function(t){o<t.preVerificationGas&&(o=t.preVerificationGas),s<t.verificationGasLimit&&(s=t.verificationGasLimit),c<t.callGasLimit&&(c=t.callGasLimit),e.maxFeePerGas=i,e.maxPriorityFeePerGas=f})}throw new m("BAD_DATA","bundlerRpc cant't be null if preVerificationGas,verificationGasLimit and callGasLimit are not overriden")}()}();return f&&f.then?f.then(i):i()},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){void 0===r&&(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 c=e.prependTokenPaymasterApproveToCallData(t.callData,r,o.address,s);return t.callData=c,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,function(e,t){return"bigint"==typeof t?"0x"+t.toString(16):t})}})});var i=b(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:O,SafeAccountFactory:x,Bundler:L,CandidePaymaster:B,createUserOperationHash:g,createCallData:G,getFunctionSelector:E,fetchAccountNonce:A,calculateUserOperationMaxGasCost:b,get SafeModuleExecutorFunctionSelector(){return e.SafeModuleExecutorFunctionSelector},get Operation(){return e.Operation},ZeroAddress:S,UserOperationDummyValues:R};e.Bundler=L,e.CandidePaymaster=B,e.SafeAccountFactory=x,e.SafeAccountV0_2_0=C,e.SendUseroperationResponse=I,e.SmartAccount=s,e.SmartAccountFactory=O,e.UserOperationDummyValues=R,e.ZeroAddress=S,e.abstractionkit=N,e.calculateUserOperationMaxGasCost=b,e.createCallData=G,e.createUserOperationHash=g,e.fetchAccountNonce=A,e.getFunctionSelector=E});
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Candidelabs",
5
5
  "url": "https://candide.dev"
6
6
  },
7
- "version": "0.1.9",
7
+ "version": "0.1.10",
8
8
  "description": "Account Abstraction 4337 SDK by Candidelabs",
9
9
  "main": "dist/index.js",
10
10
  "module": "dist/index.m.js",